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 (14496B)


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