tx.c (8087B)
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: tx.c 8 * Purpose: 9 * Requires: 10 * 11 * Notes on internals: 12 * The basic tx function is bcm_tx. In this case, a chain 13 * corresponds to a single packet. The done chain interrupt (dv done) 14 * is used to indicate the end of packet for async transmission. 15 * 16 * Arrays may be transmitted using bcm_tx_array; similarly, linked lists 17 * can be transmitted with bcm_tx_list. In both cases, the 18 * tx_dv_info_t structure is associated with the DV. Currently, 19 * only one call back is supported for a chain of packets. It 20 * wouldn't be too difficult to have a per packet callback using 21 * the packet's call back member. 22 */ 23 24 /* We need to call top-level APIs on other units */ 25 #include <assert.h> 26 #include <bcm_int/common/tx.h> 27 #ifdef BCM_TRIDENT3_SUPPORT 28 #include <bcm_int/esw/trident3.h> 29 #endif 30 #include <soc/drv.h> 31 /* 32 * Function: 33 * bcm_tx_pkt_setup 34 * Purpose: 35 * Default packet setup routine for transmit 36 * Parameters: 37 * unit - Unit on which being transmitted 38 * tx_pkt - Packet to update 39 * Returns: 40 * BCM_E_XXX 41 * Notes: 42 * tx_pkt->tx_pbmp should be set before calling this function 43 * Currently, the main thing this does is force the HG header 44 * on Hercules. 45 */ 46 47 int 48 bcm_esw_tx_pkt_setup(int unit, bcm_pkt_t *tx_pkt) 49 { 50 return bcm_common_tx_pkt_setup(unit, tx_pkt); 51 } 52 53 /* 54 * Function: 55 * bcm_tx_init 56 * Purpose: 57 * Initialize BCM TX API 58 * Parameters: 59 * unit - transmission unit 60 * Returns: 61 * BCM_E_XXX 62 * Notes: 63 * Currently, this just allocates shared memory space for the 64 * CRC append memory. This memory is zero and used by all packets 65 * that require CRC append (allocate). 66 * 67 * This pointer is only allocated once. If allocation fails, 68 * BCM_E_MEMORY is returned. 69 */ 70 71 int 72 bcm_esw_tx_init(int unit) 73 { 74 return bcm_common_tx_init(unit); 75 } 76 77 78 /* 79 * Function: 80 * bcm_tx 81 * Purpose: 82 * Wrapper for _bcm_tx to work around a lack of XGS3 support for 83 * transmitting to a bitmap. 84 * Parameters: 85 * unit - transmission unit 86 * pkt - The tx packet structure 87 * cookie - Callback cookie when tx done 88 * Returns: 89 * BCM_E_XXX 90 * Notes: 91 * XGS3 devices cannot dispatch packets to multiple ports. To emulate this 92 * functionality, bcm_tx iterates over the requested bitmaps. The callback, 93 * if applicable, shall be called only once. 94 */ 95 96 int 97 bcm_esw_tx(int unit, bcm_pkt_t *pkt, void *cookie) 98 { 99 int rv; 100 101 #ifdef BCM_TRIUMPH3_SUPPORT 102 bcm_port_t port_iter; 103 bcm_pbmp_t lock_pbmp; 104 105 extern void _bcm_esw_ibod_recovery_port_lock(int unit, bcm_port_t port); 106 extern void _bcm_esw_ibod_recovery_port_unlock(int unit, bcm_port_t port); 107 /* to avoid any change in tx_pbmp leaving the port in locked state */ 108 BCM_PBMP_ASSIGN(lock_pbmp, pkt->tx_pbmp); 109 110 /* Hold the ibod recovery port group lock */ 111 if (SOC_IS_TRIUMPH3(unit)) { 112 BCM_PBMP_ITER(lock_pbmp, port_iter) { 113 _bcm_esw_ibod_recovery_port_lock(unit, port_iter); 114 } 115 } 116 #endif 117 rv = bcm_common_tx(unit, pkt, cookie); 118 #ifdef BCM_TRIUMPH3_SUPPORT 119 /* Release the ibod recovery port group lock */ 120 if (SOC_IS_TRIUMPH3(unit)) { 121 BCM_PBMP_ITER(lock_pbmp, port_iter) { 122 _bcm_esw_ibod_recovery_port_unlock(unit, port_iter); 123 } 124 } 125 #endif 126 return rv; 127 } 128 129 /* 130 * Function: 131 * bcm_tx_array 132 * Purpose: 133 * Transmit an array of packets 134 * Parameters: 135 * unit - transmission unit 136 * pkt - array of pointers to packets to transmit 137 * count - Number of packets in list 138 * all_done_cb - Callback function (if non-NULL) when all pkts tx'd 139 * cookie - Callback cookie. 140 * Returns: 141 * BCM_E_XXX 142 * Notes: 143 * If all_done_cb is non-NULL, the packets are sent asynchronously 144 * (the routine returns before all the pkts are sent) 145 * 146 * The "packet callback" will be set according to the value 147 * in each packet's "call_back" member, so that must be initialized 148 * for all packets in the chain. 149 * 150 * If any packet requires a callback, the packet-done callback is 151 * enabled for all packets in the chain. 152 * 153 * This routine does not support tunnelling to a remote CPU for 154 * forwarding. 155 * 156 * CURRENTLY: The TX parameters, src mod, src port, PFM 157 * and internal priority, are determined by the first packet in 158 * the array. This may change to break the array into subchains 159 * when differences are detected. 160 */ 161 162 int 163 bcm_esw_tx_array(int unit, bcm_pkt_t **pkt, int count, bcm_pkt_cb_f all_done_cb, 164 void *cookie) 165 { 166 #ifdef BCM_TRIDENT3_SUPPORT 167 if (SOC_IS_TRIDENT3X(unit) && soc_feature(unit, soc_feature_higig_over_ethernet)) { 168 return bcm_td3_tx_hgoe_array(unit, pkt, count, all_done_cb, cookie); 169 } 170 #endif 171 return bcm_common_tx_array(unit, pkt, count, all_done_cb, cookie); 172 } 173 174 /* 175 * Function: 176 * bcm_tx_list 177 * Purpose: 178 * Transmit a linked list of packets 179 * Parameters: 180 * unit - transmission unit 181 * pkt - Pointer to linked list of packets 182 * all_done_cb - Callback function (if non-NULL) when all pkts tx'd 183 * cookie - Callback cookie. 184 * Returns: 185 * BCM_E_XXX 186 * Notes: 187 * If callback is non-NULL, the packets are sent asynchronously 188 * (the routine returns before all the pkts are sent) 189 * 190 * The "packet callback" will be set according to the value 191 * in each packet's "call_back" member, so that must be initialized 192 * for all packets in the chain. 193 * 194 * The "next" member of the packet is used for the linked list. 195 * CAREFUL: The internal _next member is not used for this. 196 * 197 * This routine does not support tunnelling to a remote CPU for 198 * forwarding. 199 * 200 * The TX parameters, src mod, src port, PFM and internal priority, 201 * are currently determined by the first packet in the list. 202 */ 203 204 int 205 bcm_esw_tx_list(int unit, bcm_pkt_t *pkt, bcm_pkt_cb_f all_done_cb, void *cookie) 206 { 207 #ifdef BCM_TRIDENT3_SUPPORT 208 if (SOC_IS_TRIDENT3X(unit) 209 && soc_feature(unit, soc_feature_higig_over_ethernet)) { 210 return bcm_td3_tx_hgoe_list(unit, pkt, all_done_cb, cookie); 211 } 212 #endif 213 return bcm_common_tx_list(unit, pkt, all_done_cb, cookie); 214 } 215 216 217 /**************************************************************** 218 * 219 * Map a destination MAC address to port bitmaps. Uses 220 * the dest_mac passed as a parameter. Sets the 221 * bitmaps in the pkt structure. 222 */ 223 224 /* 225 * Function: 226 * bcm_tx_pkt_l2_map 227 * Purpose: 228 * Resolve the packet's L2 destination and update the necessary 229 * fields of the packet. 230 * Parameters: 231 * unit - Transmit unit 232 * pkt - Pointer to pkt being transmitted 233 * dest_mac - use for L2 lookup 234 * vid - use for L2 lookup 235 * Returns: 236 * BCM_E_XXX 237 * Notes: 238 * Deprecated, not implemented. 239 */ 240 241 int 242 bcm_esw_tx_pkt_l2_map(int unit, bcm_pkt_t *pkt, bcm_mac_t dest_mac, int vid) 243 { 244 return bcm_common_tx_pkt_l2_map(unit, pkt, dest_mac, vid); 245 } 246 247 248 /**************************************************************** 249 * 250 * TX DV info dump routine. 251 */ 252 253 #if defined(BROADCOM_DEBUG) 254 /* 255 * Function: 256 * bcm_tx_show 257 * Purpose: 258 * Display info about tx state 259 * Parameters: 260 * unit - ignored 261 * Returns: 262 * None 263 * Notes: 264 */ 265 266 int 267 bcm_esw_tx_show(int unit) 268 { 269 return bcm_common_tx_show(unit); 270 } 271 272 /* 273 * Function: 274 * bcm_tx_dv_dump 275 * Purpose: 276 * Display info about a DV that is setup for TX. 277 * Parameters: 278 * unit - transmission unit 279 * dv - The DV to show info about 280 * Returns: 281 * None 282 * Notes: 283 * Mainly, dumps the tx_dv_info_t structure; then calls soc_dma_dump_dv 284 */ 285 286 int 287 bcm_esw_tx_dv_dump(int unit, void *dv_p) 288 { 289 return bcm_common_tx_dv_dump(unit, dv_p); 290 } 291 292 #endif /* BROADCOM_DEBUG */ 293