cputrans.h (12399B)
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: cputrans.h 8 * Purpose: General defines for CPU to CPU communication 9 */ 10 11 #ifndef _CPUTRANS_CPUTRANS_H_ 12 #define _CPUTRANS_CPUTRANS_H_ 13 14 #include <sdk_config.h> 15 #include <bcm/pkt.h> 16 #include <bcm/rx.h> 17 18 #include <appl/cpudb/cpudb.h> 19 20 /* Default values for cputrans_rx_pkt_setup */ 21 22 #ifndef CPUTRANS_RX_BLK_CNTS_DEFAULT 23 #define CPUTRANS_RX_BLK_CNTS_DEFAULT {20, 20, 20, 10, 0, 0, 0, 10} 24 #endif 25 #ifndef CPUTRANS_RX_LIST_COUNT_DEFAULT 26 #define CPUTRANS_RX_LIST_COUNT_DEFAULT 8 27 #endif 28 29 /* Default packet pool size */ 30 #ifndef CPUTRANS_PKT_POOL_SIZE_DEFAULT 31 #define CPUTRANS_PKT_POOL_SIZE_DEFAULT 128 32 #endif 33 34 /* Here's a sample TX reserve setup 35 #define CPUTRANS_TX_RESERVE_DEFAULT {50, 50, 50, 50, 25, 25, 10, 0} 36 */ 37 38 #ifndef CPUTRANS_TX_RESERVE_DEFAULT 39 #define CPUTRANS_TX_RESERVE_DEFAULT {0 } 40 #endif 41 42 /* 43 * Transmit flags: 44 * CPUTRANS_NO_HEADER_ALLOC Packet buffer already has header space; 45 * default is to use locally maintained 46 * buffers for headers. 47 * CPUTRANS_BCAST Broadcast to all CPUs; currently 48 * implies BET and next hop; default is to 49 * use dest_key or other addressing means 50 * CPUTRANS_LOOPBACK Only examined if BCAST is set; In this 51 * case, will also send the packet up the 52 * local stack; default is to only send 53 * out to remote CPUs 54 * CPUTRANS_NO_L2_UPDATE For nh_tx: Do not update the L2 55 * header of the packet; default is to 56 * update the L2 header with the NH dest 57 * mac and the local CPU. Packets that 58 * are received by next_hop and then 59 * retransmitted have this flag set. 60 * CPUTRANS_NO_ACK Override client flags and send a 61 * packet without an ACK. The flag is 62 * conveyed in the packet headers. 63 * CPUTRANS_NEXT_HOP Override client flags and send a 64 * packet using the next hop transport. 65 * CPUTRANS_CRC_REGEN Regenerate CRC. 66 * CPUTRANS_IMMEDIATE_ACK Send ACK immediately. If flag is not 67 * set, ACK is sent asynchronously; 68 * packet handling and transmit of the 69 * ACK can happen in any order. 70 * CPUTRANS_COS_OVERRIDE Use the cos priority bits for cos queue 71 * packet transmit. 72 * COS value should be set with macro 73 * CPUTRANS_COS_SET. 74 * CPUTRANS_INT_PRIO_OVERRIDE Use the internal priority bits for packet 75 * transmit. Internal priority value should 76 * be set with macro CPUTRANS_INT_PRIO_SET. 77 */ 78 79 #define CPUTRANS_COS_SHIFT 0 80 #define CPUTRANS_COS_MASK (0x7 << CPUTRANS_COS_SHIFT) 81 #define CPUTRANS_COS_OVERRIDE 0x00000080 82 #define CPUTRANS_INT_PRIO_SHIFT 8 83 #define CPUTRANS_INT_PRIO_MASK (0x7 << CPUTRANS_INT_PRIO_SHIFT) 84 #define CPUTRANS_INT_PRIO_OVERRIDE 0x00008000 85 86 #define CPUTRANS_NO_HEADER_ALLOC 0x00010000 87 #define CPUTRANS_BCAST 0x00020000 /* Implies BET and next hop */ 88 #define CPUTRANS_LOOPBACK 0x00040000 89 #define CPUTRANS_NO_L2_UPDATE 0x00080000 90 #define CPUTRANS_NO_ACK 0x00100000 91 #define CPUTRANS_NEXT_HOP 0x00200000 92 #define CPUTRANS_CRC_REGEN 0x00400000 93 #define CPUTRANS_IMMEDIATE_ACK 0x00800000 94 95 #define CPUTRANS_INT_PRIO_VALID CPUTRANS_INT_PRIO_OVERRIDE 96 97 #define CPUTRANS_COS_SET(flags, val) \ 98 ((flags) = ((flags) & (~CPUTRANS_COS_MASK)) | \ 99 (((val) << CPUTRANS_COS_SHIFT) & CPUTRANS_COS_MASK) | \ 100 CPUTRANS_COS_OVERRIDE) 101 102 #define CPUTRANS_COS_GET(flags) \ 103 (((flags) & CPUTRANS_COS_MASK) >> CPUTRANS_COS_SHIFT) 104 105 #define CPUTRANS_INT_PRIO_SET(flags, val) \ 106 ((flags) = ((flags) & (~CPUTRANS_INT_PRIO_MASK)) | \ 107 (((val) << CPUTRANS_INT_PRIO_SHIFT) & CPUTRANS_INT_PRIO_MASK) | \ 108 CPUTRANS_INT_PRIO_OVERRIDE) 109 110 #define CPUTRANS_INT_PRIO_GET(flags) \ 111 (((flags) & CPUTRANS_INT_PRIO_MASK) >> CPUTRANS_INT_PRIO_SHIFT) 112 113 114 /* Next hop used explicitly or with BET BCAST */ 115 #define CPUTRANS_IS_NEXT_HOP(ct_flags) \ 116 ((ct_flags) & (CPUTRANS_BCAST | CPUTRANS_NEXT_HOP)) 117 118 /* 119 * These defines indicate the data layout. Most importantly, they 120 * indicate to the application where in a raw packet the payload 121 * starts. By default, applications do not allocate space for 122 * the header, but can indicate they have by setting the NO_HEADER_ALLOC 123 * flag above. 124 * 125 * The SNAP header is common for all packet types: 126 * src/dest MAC, VLAN, type/len, SNAP HDR, local type indicator, 127 * client indicator, reserved 16 bits. 128 */ 129 #define CPUTRANS_L2_SNAP_OFS 0 /* Just for consistency */ 130 131 #define CPUTRANS_L2_SNAP_BYTES \ 132 (2 * sizeof(bcm_mac_t) + /* S/D MACs */ \ 133 sizeof(uint32) + /* VLAN */ \ 134 sizeof(uint16) + /* Type/Len */ \ 135 sizeof(bcm_mac_t) + sizeof(uint16) + /* SNAP */ \ 136 sizeof(uint16) + /* TR_TYPE (Local SNAP type) */ \ 137 sizeof(uint16) + /* TR_MULT (Client multiplex */ \ 138 sizeof(uint16)) /* TR_R (Transport reserved */ 139 140 141 /* 142 * CPU Transport Header, part 1. 143 * See cputrans.txt for more info about these 144 * CPUTRANS_DMAC_OFS 0 145 * CPUTRANS_SMAC_OFS 6 146 * CPUTRANS_VTAG_OFS 12 147 * CPUTRANS_LEN_OFS 16 148 * CPUTRANS_SNAP_OFS 18 149 * CPUTRANS_SNAP_TYPE_OFS 26 150 * CPUTRANS_SNAP_BYTES 8 151 * 152 * Three local words (part of CPU Trans, part 1): 153 * CPUTRANS_TR_TYPE_OFS 28 What transport is using this? 154 * CPUTRANS_TR_MULT_OFS 30 Multiplexor for apps using transport 155 * CPUTRANS_TR_RSVD_OFS 32 2 bytes reserved for transport 156 * 157 * Next hop transmit stores the TX unit/port in the header. 158 * CPUTRANS_NH_UNIT_OFS 32 159 * CPUTRANS_NH_PORT_OFS 33 160 */ 161 162 #define CPUTRANS_DMAC_OFS CPUTRANS_L2_SNAP_OFS 163 #define CPUTRANS_SMAC_OFS (CPUTRANS_DMAC_OFS + sizeof(bcm_mac_t)) 164 #define CPUTRANS_VTAG_OFS (CPUTRANS_SMAC_OFS + sizeof(bcm_mac_t)) 165 #define CPUTRANS_LEN_OFS (CPUTRANS_VTAG_OFS + sizeof(uint32)) 166 #define CPUTRANS_SNAP_OFS (CPUTRANS_LEN_OFS + sizeof(uint16)) 167 #define CPUTRANS_SNAP_TYPE_OFS (CPUTRANS_SNAP_OFS + sizeof(bcm_mac_t)) 168 #define CPUTRANS_SNAP_BYTES (sizeof(bcm_mac_t) + sizeof(uint16)) 169 170 #define CPUTRANS_TR_TYPE_OFS (CPUTRANS_SNAP_OFS + CPUTRANS_SNAP_BYTES) 171 #define CPUTRANS_TR_MULT_OFS (CPUTRANS_TR_TYPE_OFS + sizeof(uint16)) 172 #define CPUTRANS_TR_RSVD_OFS (CPUTRANS_TR_MULT_OFS + sizeof(uint16)) 173 174 #define CPUTRANS_NH_UNIT_OFS CPUTRANS_TR_RSVD_OFS 175 #define CPUTRANS_NH_PORT_OFS (CPUTRANS_NH_UNIT_OFS + 1) 176 177 /* 178 * Space is left for next hop header always: 179 * NH dest mac, NH src mac, seq number, port (client) 180 */ 181 182 #define CPUTRANS_NEXT_HOP_OFS CPUTRANS_L2_SNAP_BYTES 183 184 185 /* Offsets for (original) source CPU key and NEXT_HOP seq no */ 186 #define CPUTRANS_DEST_KEY_OFS CPUTRANS_NEXT_HOP_OFS 187 #define CPUTRANS_SRC_KEY_OFS (CPUTRANS_DEST_KEY_OFS + sizeof(cpudb_key_t)) 188 #define CPUTRANS_NH_SEQ_NUM_OFS (CPUTRANS_SRC_KEY_OFS + sizeof(cpudb_key_t)) 189 #define CPUTRANS_NH_MPLX_NUM_OFS (CPUTRANS_NH_SEQ_NUM_OFS + sizeof(uint16)) 190 191 #define CPUTRANS_NEXT_HOP_BYTES \ 192 (2 * CPUDB_KEY_BYTES + /* D/S keys */ \ 193 sizeof(uint16) + /* Sequence num */ \ 194 sizeof(uint32)) /* Client multiplexing value */ 195 196 /* 197 * The ATP/BET header: 198 * Client ID, Flags, Sequence number, Segment count, 199 * Length, Opcode, Priority 200 */ 201 202 #define CPUTRANS_ATP_OFS \ 203 (CPUTRANS_L2_SNAP_BYTES + CPUTRANS_NEXT_HOP_BYTES) 204 205 #define CPUTRANS_ATP_BYTES \ 206 (sizeof(uint8) + /* Version */ \ 207 sizeof(uint8) + /* Reserved */ \ 208 sizeof(uint16) + /* Client ID */ \ 209 sizeof(uint32) + /* Flags */ \ 210 sizeof(uint16) + /* Sequence Number */ \ 211 sizeof(uint16) + /* Total Payload */ \ 212 sizeof(uint16) + /* Payload Offset */ \ 213 sizeof(uint8) + /* Total Segments */ \ 214 sizeof(uint8) + /* Segment Number */ \ 215 sizeof(uint8) + /* Opcode */ \ 216 sizeof(uint8)) /* Cos */ 217 218 /* 219 * How deep into the packet before the data starts. 220 * This is also an overhead counter for extra space at start 221 * of packet for all transports. 222 */ 223 224 #define CPUTRANS_HEADER_BYTES \ 225 (CPUTRANS_L2_SNAP_BYTES + \ 226 CPUTRANS_NEXT_HOP_BYTES + \ 227 CPUTRANS_ATP_BYTES) 228 229 #define CPUTRANS_DATA_OFS CPUTRANS_HEADER_BYTES 230 231 /* 232 * cputrans_error_count counts errors that may cause or may indicate 233 * internal corruption. 234 */ 235 236 extern volatile int cputrans_error_count; 237 extern int cputrans_error_count_get(int clear); 238 239 extern int cputrans_tx_pkt_setup(int pkt_pool_size, 240 bcm_trans_ptr_t *trans_ptr); 241 extern void cputrans_tx_pkt_cleanup(void); 242 extern bcm_pkt_t *cputrans_tx_pkt_alloc(uint8 *pkt_buf, int len, uint32 flags); 243 extern int cputrans_tx_setup_done(void); 244 extern bcm_pkt_t *cputrans_tx_pkt_list_alloc(uint8 *pkt_buf, 245 int len, 246 int seg_len, 247 uint32 ct_flags, 248 int *num_segs); 249 extern void cputrans_tx_pkt_list_free(bcm_pkt_t *pkt); 250 251 extern int cputrans_tx_alloc_limit_set(int cos, int reserve); 252 extern int cputrans_tx_alloc_limit_get(int cos, int *reserve); 253 254 #define cputrans_tx_pkt_free(_pkt) cputrans_tx_pkt_list_free(_pkt) 255 256 257 extern void cputrans_rx_pkt_cleanup(void); 258 extern int cputrans_rx_pkt_setup(int list_count, int *blk_cnts); 259 extern int cputrans_rx_setup_done(void); 260 extern bcm_pkt_t *cputrans_rx_pkt_alloc(int num_blks); 261 extern void cputrans_rx_pkt_free(bcm_pkt_t *pkt); 262 263 extern int cputrans_trans_count(void); 264 extern int cputrans_trans_add(bcm_trans_ptr_t *trans); 265 extern int cputrans_trans_remove(bcm_trans_ptr_t *trans); 266 extern int cputrans_rx_register(const char *name, 267 bcm_rx_cb_f callback, 268 uint8 priority, 269 void *cookie, 270 uint32 flags); 271 extern int cputrans_rx_unit_register(int unit, 272 const char *name, 273 bcm_rx_cb_f callback, 274 uint8 priority, 275 void *cookie, 276 uint32 flags); 277 extern int cputrans_rx_bmp_register(uint32 unit_bmp, 278 const char *name, 279 bcm_rx_cb_f callback, 280 uint8 priority, 281 void *cookie, 282 uint32 flags); 283 extern int cputrans_rx_unregister(bcm_rx_cb_f callback, 284 uint8 priority); 285 extern int cputrans_rx_unit_unregister(int unit, 286 bcm_rx_cb_f callback, 287 uint8 priority); 288 extern int cputrans_rx_bmp_unregister(uint32 unit_bmp, 289 bcm_rx_cb_f callback, 290 uint8 priority); 291 292 #endif /* _CPUTRANS_CPUTRANS_H_ */