openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

kcom.h (15028B)


      1 /*
      2  * Copyright 2017 Broadcom
      3  * 
      4  * This program is free software; you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License, version 2, as
      6  * published by the Free Software Foundation (the "GPL").
      7  * 
      8  * This program is distributed in the hope that it will be useful, but
      9  * WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     11  * General Public License version 2 (GPLv2) for more details.
     12  * 
     13  * You should have received a copy of the GNU General Public License
     14  * version 2 (GPLv2) along with this source code.
     15  */
     16 /*
     17  * $Id: kcom.h,v 1.9 Broadcom SDK $
     18  * $Copyright: (c) 2005 Broadcom Corp.
     19  * All Rights Reserved.$
     20  *
     21  * File:    kcom.h
     22  * Purpose: User/Kernel message definitions
     23  */
     24 
     25 #ifndef _KCOM_H
     26 #define _KCOM_H
     27 
     28 #include <sal/types.h>
     29 
     30 #define KCOM_CHAN_KNET          "KCOM_KNET"
     31 
     32 /*
     33  * Message types
     34  */
     35 #define KCOM_MSG_TYPE_CMD       1  /* Command */
     36 #define KCOM_MSG_TYPE_RSP       2  /* Command response */
     37 #define KCOM_MSG_TYPE_EVT       3  /* Unsolicited event */
     38 
     39 /*
     40  * Message opcodes
     41  */
     42 #define KCOM_M_NONE             0  /* Should not be used */
     43 #define KCOM_M_VERSION          1  /* Protocol version */
     44 #define KCOM_M_STRING           2  /* For debug messages */
     45 #define KCOM_M_HW_RESET         3  /* H/W not ready */
     46 #define KCOM_M_HW_INIT          4  /* H/W initialized */
     47 #define KCOM_M_ETH_HW_CONFIG    5  /* ETH HW config*/
     48 #define KCOM_M_DETACH           6  /* Detach kernel module */
     49 #define KCOM_M_REPROBE          7  /* Reprobe device */
     50 #define KCOM_M_NETIF_CREATE     11 /* Create network interface */
     51 #define KCOM_M_NETIF_DESTROY    12 /* Destroy network interface */
     52 #define KCOM_M_NETIF_LIST       13 /* Get list of network interface IDs */
     53 #define KCOM_M_NETIF_GET        14 /* Get network interface info */
     54 #define KCOM_M_FILTER_CREATE    21 /* Create Rx filter */
     55 #define KCOM_M_FILTER_DESTROY   22 /* Destroy Rx filter */
     56 #define KCOM_M_FILTER_LIST      23 /* Get list of Rx filter IDs */
     57 #define KCOM_M_FILTER_GET       24 /* Get Rx filter info */
     58 #define KCOM_M_DMA_INFO         31 /* Tx/Rx DMA info */
     59 #define KCOM_M_DBGPKT_SET       41 /* Enbale debug packet function */
     60 #define KCOM_M_DBGPKT_GET       42 /* Get debug packet function info */
     61 #define KCOM_M_WB_CLEANUP       51 /* Clean up for warmbooting */
     62 
     63 #define KCOM_VERSION            10 /* Protocol version */
     64 
     65 /*
     66  * Message status codes
     67  */
     68 #define KCOM_E_NONE             0  /* No errors */
     69 #define KCOM_E_PARAM            1  /* Invalid/unsupported parameter */
     70 #define KCOM_E_RESOURCE         2  /* Out of memory or other resource */
     71 #define KCOM_E_NOT_FOUND        3  /* Requested object not found */
     72 
     73 typedef struct kcom_msg_hdr_s {
     74     uint8 type;
     75     uint8 opcode;
     76     uint8 seqno;
     77     uint8 status;
     78     uint8 unit;
     79     uint8 reserved;
     80     uint16 id;
     81 } kcom_msg_hdr_t;
     82 
     83 /*
     84  * Object types
     85  */
     86 
     87 /*
     88  * System network interface
     89  *
     90  * Network interface types:
     91  *
     92  *  KCOM_NETIF_T_VLAN
     93  *  Transmits to this interface will go to ingress PIPE of switch
     94  *  CPU port using specified VLAN ID. Packet will be switched.
     95  *
     96  *  KCOM_NETIF_T_PORT
     97  *  Transmits to this interface will go to unmodified to specified
     98  *  physical switch port. All switching logic is bypassed.
     99  *
    100  *  KCOM_NETIF_T_META
    101  *  Transmits to this interface will be done using raw meta data
    102  *  as DMA descriptors. Currently used for RCPU mode only.
    103  *
    104  * Network interface flags:
    105  *
    106  *  KCOM_NETIF_F_ADD_TAG
    107  *  Add VLAN tag to packets sent directly to physical port.
    108  *
    109  *  KCOM_NETIF_F_RCPU_ENCAP
    110  *  Use RCPU encapsulation for packets that enter and exit this
    111  *  interface.
    112  */
    113 #define KCOM_NETIF_T_VLAN       0
    114 #define KCOM_NETIF_T_PORT       1
    115 #define KCOM_NETIF_T_META       2
    116 
    117 #define KCOM_NETIF_F_ADD_TAG    (1U << 0)
    118 #define KCOM_NETIF_F_RCPU_ENCAP (1U << 1)
    119 /* If a netif has this flag, the packet sent to the netif can't be stripped tag or added tag */
    120 #define KCOM_NETIF_F_KEEP_RX_TAG (1U << 2)
    121 
    122 #define KCOM_NETIF_NAME_MAX     16
    123 
    124 /*
    125  * Max size of Sand System Headers
    126  * For DNX, Module Header(20B) + PTCH(2B) + ITMH(5B)
    127  * For DPP, PTCH(2B) + ITMH(4B)
    128  */
    129 #define KCOM_NETIF_SYSTEM_HEADERS_SIZE_MAX     27
    130 
    131 typedef struct kcom_netif_s {
    132     uint16 id;
    133     uint8 type;
    134     uint8 flags;
    135     uint32 cb_user_data;
    136     uint8 port;
    137     uint8 reserved;
    138     uint16 vlan;
    139     uint16 qnum;
    140     uint8 macaddr[6];
    141     uint8 ptch[2];
    142     uint8 itmh[4];
    143     uint8 system_headers[KCOM_NETIF_SYSTEM_HEADERS_SIZE_MAX];
    144     uint8 system_headers_size;
    145     char name[KCOM_NETIF_NAME_MAX];
    146 } kcom_netif_t;
    147 
    148 /*
    149  * Packet filters
    150  *
    151  * Filters work like software TCAMs where a mask is applied to the
    152  * source data, and the result is then compared to the filter data.
    153  *
    154  * Filters are checked in priority order with the lowest priority
    155  * values being checked first (i.e. 0 is the highest priority).
    156  *
    157  * Filter types:
    158  *
    159  *  KCOM_FILTER_T_RX_PKT
    160  *  Filter data and mask are applied to the Rx DMA control block
    161  *  as well as to the Rx packet contents.
    162  *
    163  * Destination types:
    164  *
    165  *  KCOM_DEST_T_NULL
    166  *  Packet is dropped.
    167  *
    168  *  KCOM_DEST_T_NETIF
    169  *  Packet is sent to network interface with ID <dest_id>.
    170  *
    171  *  KCOM_DEST_T_API
    172  *  Packet is sent to Rx API through queue <dest_id>.
    173  *
    174  *  KCOM_DEST_T_CB
    175  *  Packet destination is obtained from kernel call-back function.
    176  *
    177  * Filter flags:
    178  *
    179  *  KCOM_FILTER_F_ANY_DATA
    180  *  When this flags is set the filter will match any packet on
    181  *  the associated unit.
    182  *
    183  *  KCOM_FILTER_F_STRIP_TAG
    184  *  Strip VLAN tag before packet is sent to destination.
    185  *  This flag only applies to KCOM_DEST_T_NETIF.
    186  *
    187  */
    188 #define KCOM_FILTER_BYTES_MAX   256
    189 #define KCOM_FILTER_WORDS_MAX   BYTES2WORDS(KCOM_FILTER_BYTES_MAX)
    190 
    191 #define KCOM_FILTER_T_RX_PKT    1
    192 
    193 #define KCOM_DEST_T_NULL        0
    194 #define KCOM_DEST_T_NETIF       1
    195 #define KCOM_DEST_T_API         2
    196 #define KCOM_DEST_T_CB          3
    197 
    198 #define KCOM_FILTER_F_ANY_DATA  (1U << 0)
    199 #define KCOM_FILTER_F_STRIP_TAG (1U << 1)
    200 
    201 #define KCOM_FILTER_DESC_MAX    32
    202 
    203 typedef struct kcom_filter_s {
    204     uint16 id;
    205     uint8 type;
    206     uint8 priority;
    207     char desc[KCOM_FILTER_DESC_MAX];
    208     uint32 flags;
    209     uint32 cb_user_data;
    210     uint16 dest_type;
    211     uint16 dest_id;
    212     uint16 dest_proto;
    213     uint16 mirror_type;
    214     uint16 mirror_id;
    215     uint16 mirror_proto;
    216     uint16 oob_data_offset;
    217     uint16 oob_data_size;
    218     uint16 pkt_data_offset;
    219     uint16 pkt_data_size;
    220     union {
    221         uint8 b[KCOM_FILTER_BYTES_MAX];
    222         uint32 w[KCOM_FILTER_WORDS_MAX];
    223     } data;
    224     union {
    225         uint8 b[KCOM_FILTER_BYTES_MAX];
    226         uint32 w[KCOM_FILTER_WORDS_MAX];
    227     } mask;
    228     /** Information to parse Dune system headers */
    229     uint32 ftmh_lb_key_ext_size;
    230     uint32 ftmh_stacking_ext_size;
    231     uint32 pph_base_size;
    232     uint32 pph_lif_ext_size[8];
    233     uint8  udh_enable;
    234     uint32 udh_length_type[4];
    235 } kcom_filter_t;
    236 
    237 /*
    238  * DMA buffer information
    239  *
    240  * Cookie field is reserved use by application (32/64-bit pointer).
    241  *
    242  * For Tx operation the application will submit the start address of
    243  * the Tx DCB chain which is queued for transfer by the kernel module.
    244  * Once DMA is done a DMA event is returned to the application with an
    245  * optional sequence number.
    246  *
    247  * For Rx operation the application will submit the start address of
    248  * the Rx DCB chain which should be use for packet reception by the
    249  * kernel module. Once DMA is done a DMA event is returned to the
    250  * application with an optional sequence number.
    251  *
    252  * Cookie field is reserved use by application (32/64-bit pointer).
    253  *
    254  * Packet info types:
    255  *
    256  *  KCOM_DMA_INFO_T_TX_DCB
    257  *  Data is physical start address of Tx DCB chain.
    258  *
    259  *  KCOM_DMA_INFO_T_RX_DCB
    260  *  Data is physical start address of Rx DCB chain.
    261  *
    262  * Packet info flags:
    263  *
    264  *  KCOM_DMA_INFO_F_TX_DONE
    265  *  This flag is set by the kernel module and means that one or more
    266  *  packets have been sent.
    267  *
    268  *  KCOM_DMA_INFO_F_RX_DONE
    269  *  This flag is set by the kernel module and means that one or more
    270  *  Rx buffers contain valid packet data.
    271  */
    272 #define KCOM_DMA_INFO_T_TX_DCB  1
    273 #define KCOM_DMA_INFO_T_RX_DCB  2
    274 
    275 #define KCOM_DMA_INFO_F_TX_DONE (1U << 0)
    276 #define KCOM_DMA_INFO_F_RX_DONE (1U << 1)
    277 
    278 typedef struct kcom_dma_info_s {
    279     uint8 type;
    280     uint8 cnt;
    281     uint16 size;
    282     uint16 chan;
    283     uint16 flags;
    284     union {
    285         uint64 dcb_start;
    286         struct {
    287             uint32 tx;
    288             uint32 rx;
    289         } seqno;
    290     } data;
    291     union {
    292         void *p;
    293         uint8 b[8];
    294     } cookie;
    295   } kcom_dma_info_t;
    296 
    297 /* Default channel configuration */
    298 #define KCOM_DMA_TX_CHAN        0
    299 #define KCOM_DMA_RX_CHAN        1
    300 
    301 
    302 #define KCOM_ETH_HW_T_RESET     1
    303 #define KCOM_ETH_HW_T_INIT      2
    304 #define KCOM_ETH_HW_T_OTHER     3
    305 
    306 #define KCOM_ETH_HW_C_ALL       0xff
    307 
    308 #define KCOM_ETH_HW_RESET_F_TX              (1U << 0)
    309 #define KCOM_ETH_HW_RESET_F_RX              (1U << 1)
    310 #define KCOM_ETH_HW_RESET_F_TX_RECLAIM      (1U << 2)
    311 #define KCOM_ETH_HW_RESET_F_RX_RECLAIM      (1U << 3)
    312 
    313 #define KCOM_ETH_HW_INIT_F_TX               (1U << 0)
    314 #define KCOM_ETH_HW_INIT_F_RX               (1U << 1)
    315 #define KCOM_ETH_HW_INIT_F_RX_FILL          (1U << 2)
    316 
    317 #define KCOM_ETH_HW_OTHER_F_FIFO_LOOPBACK   (1U << 0)
    318 #define KCOM_ETH_HW_OTHER_F_INTERRUPT       (1U << 1)
    319 
    320 typedef struct kcom_eth_hw_config_s {
    321     uint8 type;
    322     uint8 chan;
    323     uint32 flags;
    324     uint32 value;
    325 } kcom_eth_hw_config_t;
    326 
    327 /*
    328  * Message types
    329  */
    330 
    331 /*
    332  * Request KCOM interface version of kernel module.
    333  */
    334 typedef struct kcom_msg_version_s {
    335     kcom_msg_hdr_t hdr;
    336     uint32 version;
    337     uint32 netif_max;
    338     uint32 filter_max;
    339 } kcom_msg_version_t;
    340 
    341 /*
    342  * Send literal string to/from kernel module.
    343  * Mainly for debugging purposes.
    344  */
    345 #define KCOM_MSG_STRING_MAX     128
    346 
    347 typedef struct kcom_msg_string_s {
    348     kcom_msg_hdr_t hdr;
    349     uint32 len;
    350     char val[KCOM_MSG_STRING_MAX];
    351 } kcom_msg_string_t;
    352 
    353 /*
    354  * Indicate that eth hardware is about to be reset. Active
    355  * DMA operations should be aborted and DMA and interrupts
    356  * should be disabled.
    357  */
    358 /*
    359  * Indicate that eth hardware has been properly initialized
    360  * for DMA operation to commence.
    361  */ 
    362 typedef struct kcom_msg_eth_hw_config_s {
    363     kcom_msg_hdr_t hdr;
    364     kcom_eth_hw_config_t config;
    365 } kcom_msg_eth_hw_config_t;
    366 
    367 /*
    368  * Indicate that switch hardware is about to be reset. Active
    369  * DMA operations should be aborted and DMA and interrupts
    370  * should be disabled.
    371  */
    372 typedef struct kcom_msg_hw_reset_s {
    373     kcom_msg_hdr_t hdr;
    374     uint32 channels;
    375 } kcom_msg_hw_reset_t;
    376 
    377 /*
    378  * Indicate that switch hardware has been properly initialized
    379  * for DMA operation to commence.
    380  */
    381 typedef struct kcom_msg_hw_init_s {
    382     kcom_msg_hdr_t hdr;
    383     uint8 cmic_type;
    384     uint8 dcb_type;
    385     uint8 dcb_size;
    386     uint8 pkt_hdr_size;
    387     uint32 dma_hi;
    388     uint32 cdma_channels;
    389 } kcom_msg_hw_init_t;
    390 
    391 /*
    392  * Release blocked IOCTL threads and clean up as necessary.
    393  */
    394 typedef struct kcom_msg_detach_s {
    395     kcom_msg_hdr_t hdr;
    396     uint32 flags;
    397 } kcom_msg_detach_t;
    398 
    399 /*
    400  * Reprobe switch device.
    401  */
    402 typedef struct kcom_msg_reprobe_s {
    403     kcom_msg_hdr_t hdr;
    404     uint32 flags;
    405 } kcom_msg_reprobe_t;
    406 
    407 /*
    408  * Enable/Disable debugging packet function.
    409  */
    410 typedef struct kcom_msg_dbg_pkt_set_s {
    411     kcom_msg_hdr_t hdr;
    412     int enable;
    413 } kcom_msg_dbg_pkt_set_t;
    414 
    415 /*
    416  * Get debugging packet function info.
    417  */
    418 typedef struct kcom_msg_dbg_pkt_get_s {
    419     kcom_msg_hdr_t hdr;
    420     int value;
    421 } kcom_msg_dbg_pkt_get_t;
    422 
    423 /*
    424  * Clean up warmboot-related resources.
    425  */
    426 typedef struct kcom_msg_wb_cleanup_s {
    427     kcom_msg_hdr_t hdr;
    428     uint32 flags;
    429 } kcom_msg_wb_cleanup_t;
    430 
    431 /*
    432  * Create new system network interface. The network interface will
    433  * be associated with the specified switch unit number.
    434  * The interface id and name will be assigned by the kernel module.
    435  */
    436 typedef struct kcom_msg_netif_create_s {
    437     kcom_msg_hdr_t hdr;
    438     kcom_netif_t netif;
    439 } kcom_msg_netif_create_t;
    440 
    441 /*
    442  * Destroy system network interface.
    443  */
    444 typedef struct kcom_msg_netif_destroy_s {
    445     kcom_msg_hdr_t hdr;
    446 } kcom_msg_netif_destroy_t;
    447 
    448 /*
    449  * Get list of currently defined system network interfaces.
    450  */
    451 #ifndef KCOM_NETIF_MAX
    452 #define KCOM_NETIF_MAX          128
    453 #endif
    454 
    455 typedef struct kcom_msg_netif_list_s {
    456     kcom_msg_hdr_t hdr;
    457     uint32 ifcnt;
    458     uint16 id[KCOM_NETIF_MAX];
    459 } kcom_msg_netif_list_t;
    460 
    461 /*
    462  * Get detailed network interface information.
    463  */
    464 typedef struct kcom_msg_netif_get_s {
    465     kcom_msg_hdr_t hdr;
    466     kcom_netif_t netif;
    467 } kcom_msg_netif_get_t;
    468 
    469 /*
    470  * Create new packet filter.
    471  * The filter id will be assigned by the kernel module.
    472  */
    473 typedef struct kcom_msg_filter_create_s {
    474     kcom_msg_hdr_t hdr;
    475     kcom_filter_t filter;
    476 } kcom_msg_filter_create_t;
    477 
    478 /*
    479  * Destroy packet filter.
    480  */
    481 typedef struct kcom_msg_filter_destroy_s {
    482     kcom_msg_hdr_t hdr;
    483 } kcom_msg_filter_destroy_t;
    484 
    485 /*
    486  * Get list of currently defined packet filters.
    487  */
    488 #ifndef KCOM_FILTER_MAX
    489 #define KCOM_FILTER_MAX         128
    490 #endif
    491 
    492 typedef struct kcom_msg_filter_list_s {
    493     kcom_msg_hdr_t hdr;
    494     uint32 fcnt;
    495     uint16 id[KCOM_FILTER_MAX];
    496 } kcom_msg_filter_list_t;
    497 
    498 /*
    499  * Get detailed packet filter information.
    500  */
    501 typedef struct kcom_msg_filter_get_s {
    502     kcom_msg_hdr_t hdr;
    503     kcom_filter_t filter;
    504 } kcom_msg_filter_get_t;
    505 
    506 /*
    507  * DMA info
    508  */
    509 typedef struct kcom_msg_dma_info_s {
    510     kcom_msg_hdr_t hdr;
    511     kcom_dma_info_t dma_info;
    512 } kcom_msg_dma_info_t;
    513 
    514 /*
    515  * All messages (e.g. for generic receive)
    516  */
    517 typedef union kcom_msg_s {
    518     kcom_msg_hdr_t hdr;
    519     kcom_msg_version_t version;
    520     kcom_msg_string_t string;
    521     kcom_msg_hw_reset_t hw_reset;
    522     kcom_msg_hw_init_t hw_init;
    523     kcom_msg_eth_hw_config_t eth_hw_config;
    524     kcom_msg_detach_t detach;
    525     kcom_msg_reprobe_t reprobe;
    526     kcom_msg_netif_create_t netif_create;
    527     kcom_msg_netif_destroy_t netif_destroy;
    528     kcom_msg_netif_list_t netif_list;
    529     kcom_msg_netif_get_t netif_get;
    530     kcom_msg_filter_create_t filter_create;
    531     kcom_msg_filter_destroy_t filter_destroy;
    532     kcom_msg_filter_list_t filter_list;
    533     kcom_msg_filter_get_t filter_get;
    534     kcom_msg_dma_info_t dma_info;
    535     kcom_msg_dbg_pkt_set_t dbg_pkt_set;
    536     kcom_msg_dbg_pkt_get_t dbg_pkt_get;
    537     kcom_msg_wb_cleanup_t wb_cleanup;
    538 } kcom_msg_t;
    539 
    540 /*
    541  * KCOM communication channel vectors
    542  *
    543  * open
    544  * Open KCOM channel.
    545  *
    546  * close
    547  * Close KCOM channel.
    548  *
    549  * send
    550  * Send KCOM message. If bufsz is non-zero, a synchronous send will be
    551  * performed (if supported) and the function will return the number of
    552  * bytes in the response.
    553  *
    554  * recv
    555  * Receive KCOM message. This function is used t oreceive unsolicited
    556  * messages from the kernel. If synchronous send is not supported, this
    557  * function is also used to retrieve responses to command messages.
    558  */
    559 
    560 typedef struct kcom_chan_s {
    561     void *(*open)(char *name);
    562     int (*close)(void *handle);
    563     int (*send)(void *handle, void *msg, unsigned int len, unsigned int bufsz);
    564     int (*recv)(void *handle, void *msg, unsigned int bufsz);
    565 } kcom_chan_t;
    566 
    567 #endif /* _KCOM_H */