kcom.h (15761B)
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 #define KCOM_M_CLOCK_CMD 52 /* Clock Commands */ 63 64 #define KCOM_VERSION 12 /* Protocol version */ 65 66 /* 67 * Message status codes 68 */ 69 #define KCOM_E_NONE 0 /* No errors */ 70 #define KCOM_E_PARAM 1 /* Invalid/unsupported parameter */ 71 #define KCOM_E_RESOURCE 2 /* Out of memory or other resource */ 72 #define KCOM_E_NOT_FOUND 3 /* Requested object not found */ 73 74 typedef struct kcom_msg_hdr_s { 75 uint8 type; 76 uint8 opcode; 77 uint8 seqno; 78 uint8 status; 79 uint8 unit; 80 uint8 reserved; 81 uint16 id; 82 } kcom_msg_hdr_t; 83 84 /* 85 * Object types 86 */ 87 88 /* 89 * System network interface 90 * 91 * Network interface types: 92 * 93 * KCOM_NETIF_T_VLAN 94 * Transmits to this interface will go to ingress PIPE of switch 95 * CPU port using specified VLAN ID. Packet will be switched. 96 * 97 * KCOM_NETIF_T_PORT 98 * Transmits to this interface will go to unmodified to specified 99 * physical switch port. All switching logic is bypassed. 100 * 101 * KCOM_NETIF_T_META 102 * Transmits to this interface will be done using raw meta data 103 * as DMA descriptors. Currently used for RCPU mode only. 104 * 105 * Network interface flags: 106 * 107 * KCOM_NETIF_F_ADD_TAG 108 * Add VLAN tag to packets sent directly to physical port. 109 * 110 * KCOM_NETIF_F_RCPU_ENCAP 111 * Use RCPU encapsulation for packets that enter and exit this 112 * interface. 113 */ 114 #define KCOM_NETIF_T_VLAN 0 115 #define KCOM_NETIF_T_PORT 1 116 #define KCOM_NETIF_T_META 2 117 118 #define KCOM_NETIF_F_ADD_TAG (1U << 0) 119 #define KCOM_NETIF_F_RCPU_ENCAP (1U << 1) 120 /* If a netif has this flag, the packet sent to the netif can't be stripped tag or added tag */ 121 #define KCOM_NETIF_F_KEEP_RX_TAG (1U << 2) 122 123 #define KCOM_NETIF_NAME_MAX 16 124 125 /* 126 * Max size of Sand System Headers 127 * For DNX, Module Header(20B) + PTCH(2B) + ITMH(5B) 128 * For DPP, PTCH(2B) + ITMH(4B) 129 */ 130 #define KCOM_NETIF_SYSTEM_HEADERS_SIZE_MAX 27 131 132 typedef struct kcom_netif_s { 133 uint16 id; 134 uint8 type; 135 uint8 flags; 136 uint32 cb_user_data; 137 uint8 port; 138 uint8 reserved; 139 uint16 vlan; 140 uint16 qnum; 141 uint8 macaddr[6]; 142 uint8 system_headers[KCOM_NETIF_SYSTEM_HEADERS_SIZE_MAX]; 143 uint8 system_headers_size; 144 char name[KCOM_NETIF_NAME_MAX]; 145 uint8 phys_port; 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 /** Mark to match source modid and modport */ 229 uint8 is_src_modport; 230 uint8 spa_unit; 231 } kcom_filter_t; 232 233 /* 234 * DMA buffer information 235 * 236 * Cookie field is reserved use by application (32/64-bit pointer). 237 * 238 * For Tx operation the application will submit the start address of 239 * the Tx DCB chain which is queued for transfer by the kernel module. 240 * Once DMA is done a DMA event is returned to the application with an 241 * optional sequence number. 242 * 243 * For Rx operation the application will submit the start address of 244 * the Rx DCB chain which should be use for packet reception by the 245 * kernel module. Once DMA is done a DMA event is returned to the 246 * application with an optional sequence number. 247 * 248 * Cookie field is reserved use by application (32/64-bit pointer). 249 * 250 * Packet info types: 251 * 252 * KCOM_DMA_INFO_T_TX_DCB 253 * Data is physical start address of Tx DCB chain. 254 * 255 * KCOM_DMA_INFO_T_RX_DCB 256 * Data is physical start address of Rx DCB chain. 257 * 258 * Packet info flags: 259 * 260 * KCOM_DMA_INFO_F_TX_DONE 261 * This flag is set by the kernel module and means that one or more 262 * packets have been sent. 263 * 264 * KCOM_DMA_INFO_F_RX_DONE 265 * This flag is set by the kernel module and means that one or more 266 * Rx buffers contain valid packet data. 267 */ 268 #define KCOM_DMA_INFO_T_TX_DCB 1 269 #define KCOM_DMA_INFO_T_RX_DCB 2 270 271 #define KCOM_DMA_INFO_F_TX_DONE (1U << 0) 272 #define KCOM_DMA_INFO_F_RX_DONE (1U << 1) 273 274 typedef struct kcom_dma_info_s { 275 uint8 type; 276 uint8 cnt; 277 uint16 size; 278 uint16 chan; 279 uint16 flags; 280 union { 281 uint64 dcb_start; 282 struct { 283 uint32 tx; 284 uint32 rx; 285 } seqno; 286 } data; 287 union { 288 void *p; 289 uint8 b[8]; 290 } cookie; 291 } kcom_dma_info_t; 292 293 /* Default channel configuration */ 294 #define KCOM_DMA_TX_CHAN 0 295 #define KCOM_DMA_RX_CHAN 1 296 297 298 #define KCOM_ETH_HW_T_RESET 1 299 #define KCOM_ETH_HW_T_INIT 2 300 #define KCOM_ETH_HW_T_OTHER 3 301 302 #define KCOM_ETH_HW_C_ALL 0xff 303 304 #define KCOM_ETH_HW_RESET_F_TX (1U << 0) 305 #define KCOM_ETH_HW_RESET_F_RX (1U << 1) 306 #define KCOM_ETH_HW_RESET_F_TX_RECLAIM (1U << 2) 307 #define KCOM_ETH_HW_RESET_F_RX_RECLAIM (1U << 3) 308 309 #define KCOM_ETH_HW_INIT_F_TX (1U << 0) 310 #define KCOM_ETH_HW_INIT_F_RX (1U << 1) 311 #define KCOM_ETH_HW_INIT_F_RX_FILL (1U << 2) 312 313 #define KCOM_ETH_HW_OTHER_F_FIFO_LOOPBACK (1U << 0) 314 #define KCOM_ETH_HW_OTHER_F_INTERRUPT (1U << 1) 315 316 typedef struct kcom_eth_hw_config_s { 317 uint8 type; 318 uint8 chan; 319 uint32 flags; 320 uint32 value; 321 } kcom_eth_hw_config_t; 322 323 /* 324 * Message types 325 */ 326 327 /* 328 * Request KCOM interface version of kernel module. 329 */ 330 typedef struct kcom_msg_version_s { 331 kcom_msg_hdr_t hdr; 332 uint32 version; 333 uint32 netif_max; 334 uint32 filter_max; 335 } kcom_msg_version_t; 336 337 /* 338 * Request KCOM interface clock info. 339 */ 340 #define KSYNC_M_HW_INIT 0 341 #define KSYNC_M_HW_DEINIT 1 342 #define KSYNC_M_VERSION 2 343 #define KSYNC_M_HW_TS_DISABLE 3 344 345 typedef struct kcom_clock_info_s { 346 uint8 cmd; 347 int32 data[8]; 348 } kcom_clock_info_t; 349 350 /* 351 * Send literal string to/from kernel module. 352 * Mainly for debugging purposes. 353 */ 354 #define KCOM_MSG_STRING_MAX 128 355 356 typedef struct kcom_msg_string_s { 357 kcom_msg_hdr_t hdr; 358 uint32 len; 359 char val[KCOM_MSG_STRING_MAX]; 360 } kcom_msg_string_t; 361 362 /* 363 * Indicate that eth hardware is about to be reset. Active 364 * DMA operations should be aborted and DMA and interrupts 365 * should be disabled. 366 */ 367 /* 368 * Indicate that eth hardware has been properly initialized 369 * for DMA operation to commence. 370 */ 371 typedef struct kcom_msg_eth_hw_config_s { 372 kcom_msg_hdr_t hdr; 373 kcom_eth_hw_config_t config; 374 } kcom_msg_eth_hw_config_t; 375 376 /* 377 * Indicate that switch hardware is about to be reset. Active 378 * DMA operations should be aborted and DMA and interrupts 379 * should be disabled. 380 */ 381 typedef struct kcom_msg_hw_reset_s { 382 kcom_msg_hdr_t hdr; 383 uint32 channels; 384 } kcom_msg_hw_reset_t; 385 386 /* 387 * Indicate that switch hardware has been properly initialized 388 * for DMA operation to commence. 389 */ 390 typedef struct kcom_msg_hw_init_s { 391 kcom_msg_hdr_t hdr; 392 uint8 cmic_type; 393 uint8 dcb_type; 394 uint8 dcb_size; 395 uint8 pkt_hdr_size; 396 uint32 dma_hi; 397 uint32 cdma_channels; 398 /* 399 * Information to parse Dune system headers 400 */ 401 uint32 ftmh_lb_key_ext_size; 402 uint32 ftmh_stacking_ext_size; 403 uint32 pph_base_size; 404 uint32 pph_lif_ext_size[8]; 405 uint32 udh_length_type[4]; 406 uint32 udh_size; 407 uint32 oamp_punted; 408 uint8 no_skip_udh_check; 409 uint8 system_headers_mode; 410 uint8 udh_enable; 411 } kcom_msg_hw_init_t; 412 413 /* 414 * Release blocked IOCTL threads and clean up as necessary. 415 */ 416 typedef struct kcom_msg_detach_s { 417 kcom_msg_hdr_t hdr; 418 uint32 flags; 419 } kcom_msg_detach_t; 420 421 /* 422 * Reprobe switch device. 423 */ 424 typedef struct kcom_msg_reprobe_s { 425 kcom_msg_hdr_t hdr; 426 uint32 flags; 427 } kcom_msg_reprobe_t; 428 429 /* 430 * Enable/Disable debugging packet function. 431 */ 432 typedef struct kcom_msg_dbg_pkt_set_s { 433 kcom_msg_hdr_t hdr; 434 int enable; 435 } kcom_msg_dbg_pkt_set_t; 436 437 /* 438 * Get debugging packet function info. 439 */ 440 typedef struct kcom_msg_dbg_pkt_get_s { 441 kcom_msg_hdr_t hdr; 442 int value; 443 } kcom_msg_dbg_pkt_get_t; 444 445 /* 446 * Clean up warmboot-related resources. 447 */ 448 typedef struct kcom_msg_wb_cleanup_s { 449 kcom_msg_hdr_t hdr; 450 uint32 flags; 451 } kcom_msg_wb_cleanup_t; 452 453 /* 454 * Create new system network interface. The network interface will 455 * be associated with the specified switch unit number. 456 * The interface id and name will be assigned by the kernel module. 457 */ 458 typedef struct kcom_msg_netif_create_s { 459 kcom_msg_hdr_t hdr; 460 kcom_netif_t netif; 461 } kcom_msg_netif_create_t; 462 463 /* 464 * Destroy system network interface. 465 */ 466 typedef struct kcom_msg_netif_destroy_s { 467 kcom_msg_hdr_t hdr; 468 } kcom_msg_netif_destroy_t; 469 470 /* 471 * Destroy system network interface. 472 */ 473 typedef struct kcom_msg_clock_s{ 474 kcom_msg_hdr_t hdr; 475 kcom_clock_info_t clock_info; 476 } kcom_msg_clock_cmd_t; 477 478 /* 479 * Get list of currently defined system network interfaces. 480 */ 481 #ifndef KCOM_NETIF_MAX 482 #define KCOM_NETIF_MAX 128 483 #endif 484 485 typedef struct kcom_msg_netif_list_s { 486 kcom_msg_hdr_t hdr; 487 uint32 ifcnt; 488 uint16 id[KCOM_NETIF_MAX]; 489 } kcom_msg_netif_list_t; 490 491 /* 492 * Get detailed network interface information. 493 */ 494 typedef struct kcom_msg_netif_get_s { 495 kcom_msg_hdr_t hdr; 496 kcom_netif_t netif; 497 } kcom_msg_netif_get_t; 498 499 /* 500 * Create new packet filter. 501 * The filter id will be assigned by the kernel module. 502 */ 503 typedef struct kcom_msg_filter_create_s { 504 kcom_msg_hdr_t hdr; 505 kcom_filter_t filter; 506 } kcom_msg_filter_create_t; 507 508 /* 509 * Destroy packet filter. 510 */ 511 typedef struct kcom_msg_filter_destroy_s { 512 kcom_msg_hdr_t hdr; 513 } kcom_msg_filter_destroy_t; 514 515 /* 516 * Get list of currently defined packet filters. 517 */ 518 #ifndef KCOM_FILTER_MAX 519 #define KCOM_FILTER_MAX 128 520 #endif 521 522 typedef struct kcom_msg_filter_list_s { 523 kcom_msg_hdr_t hdr; 524 uint32 fcnt; 525 uint16 id[KCOM_FILTER_MAX]; 526 } kcom_msg_filter_list_t; 527 528 /* 529 * Get detailed packet filter information. 530 */ 531 typedef struct kcom_msg_filter_get_s { 532 kcom_msg_hdr_t hdr; 533 kcom_filter_t filter; 534 } kcom_msg_filter_get_t; 535 536 /* 537 * DMA info 538 */ 539 typedef struct kcom_msg_dma_info_s { 540 kcom_msg_hdr_t hdr; 541 kcom_dma_info_t dma_info; 542 } kcom_msg_dma_info_t; 543 544 /* 545 * All messages (e.g. for generic receive) 546 */ 547 typedef union kcom_msg_s { 548 kcom_msg_hdr_t hdr; 549 kcom_msg_version_t version; 550 kcom_msg_string_t string; 551 kcom_msg_hw_reset_t hw_reset; 552 kcom_msg_hw_init_t hw_init; 553 kcom_msg_eth_hw_config_t eth_hw_config; 554 kcom_msg_detach_t detach; 555 kcom_msg_reprobe_t reprobe; 556 kcom_msg_netif_create_t netif_create; 557 kcom_msg_netif_destroy_t netif_destroy; 558 kcom_msg_netif_list_t netif_list; 559 kcom_msg_netif_get_t netif_get; 560 kcom_msg_filter_create_t filter_create; 561 kcom_msg_filter_destroy_t filter_destroy; 562 kcom_msg_filter_list_t filter_list; 563 kcom_msg_filter_get_t filter_get; 564 kcom_msg_dma_info_t dma_info; 565 kcom_msg_dbg_pkt_set_t dbg_pkt_set; 566 kcom_msg_dbg_pkt_get_t dbg_pkt_get; 567 kcom_msg_wb_cleanup_t wb_cleanup; 568 kcom_msg_clock_cmd_t clock_cmd; 569 } kcom_msg_t; 570 571 /* 572 * KCOM communication channel vectors 573 * 574 * open 575 * Open KCOM channel. 576 * 577 * close 578 * Close KCOM channel. 579 * 580 * send 581 * Send KCOM message. If bufsz is non-zero, a synchronous send will be 582 * performed (if supported) and the function will return the number of 583 * bytes in the response. 584 * 585 * recv 586 * Receive KCOM message. This function is used t oreceive unsolicited 587 * messages from the kernel. If synchronous send is not supported, this 588 * function is also used to retrieve responses to command messages. 589 */ 590 591 typedef struct kcom_chan_s { 592 void *(*open)(char *name); 593 int (*close)(void *handle); 594 int (*send)(void *handle, void *msg, unsigned int len, unsigned int bufsz); 595 int (*recv)(void *handle, void *msg, unsigned int bufsz); 596 } kcom_chan_t; 597 598 #endif /* _KCOM_H */