utils.h (6412B)
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-2020 Broadcom Inc. All rights reserved. 6 * 7 * File: bcm_sand.h 8 * Purpose: Conversion between BCM and SOC_SAND types, and common macros/function for 9 * handling Dune's code. 10 */ 11 12 #ifndef INCLUDE_DPP_UTILS_H 13 #define INCLUDE_DPP_UTILS_H 14 15 #include <bcm/error.h> 16 #include <bcm/types.h> 17 #include <bcm_int/dpp/cosq.h> 18 #include <bcm_int/dpp/multicast.h> 19 #include <soc/dpp/drv.h> 20 #include <soc/dpp/SAND/Utils/sand_pp_mac.h> 21 #include <soc/dpp/SAND/Management/sand_error_code.h> 22 #include <soc/dpp/TMC/tmc_api_general.h> 23 #include <soc/dpp/TMC/tmc_api_ports.h> 24 #include <soc/dpp/PPD/ppd_api_trap_mgmt.h> 25 #include <soc/dpp/TMC/tmc_api_action_cmd.h> 26 #include <soc/dpp/SAND/Utils/sand_multi_set.h> 27 28 #define BCM_SAND_FAP_ID_TO_BCM_MODID(fap_id) (int)(fap_id) 29 #define BCM_SAND_FAP_PORT_ID_TO_BCM_PORT(fap_port_id) (int)(fap_port_id) 30 31 #define _BCM_DPP_CPU_DEST_PORT (0) 32 33 /* snoop comamnd reserved for no snooping */ 34 /* snoop comamnd reserved for snoop all packet to CPU*/ 35 #define _BCM_DPP_SNOOP_CMD_TO_CPU (1) 36 37 /* size of snooped packet (all packet) */ 38 #define _BCM_DPP_SNOOP_SIZE (SOC_TMC_ACTION_CMD_SIZE_BYTES_ALL_PCKT) 39 40 /* Destination of snooped packet */ 41 #define _BCM_DPP_SNOOP_DEST (_BCM_DPP_CPU_DEST_PORT) 42 43 #define FRAGMENT_SIZE (32) 44 45 46 /* 47 * General Utility Macros 48 */ 49 #define BCM_DPP_UNIT_CHECK(unit) \ 50 do { \ 51 if (((unit) < 0) || ((unit) >= BCM_LOCAL_UNITS_MAX)) { BCM_RETURN_VAL_EXIT(BCM_E_UNIT); } \ 52 } while (0) 53 54 55 #define BCM_DPP_MIN_CHECK(arg, min) \ 56 do { \ 57 if ((arg) < min) { return BCM_E_PARAM; } \ 58 } while (0) 59 60 61 62 /* Convert PBMP to one single port and verify that PBMP is with one member only */ 63 #define DPP_PBMP_TO_SINGLE_PORT_GET(_pbmp, _local_port) \ 64 do { \ 65 int count; \ 66 BCM_PBMP_COUNT(_pbmp, count); \ 67 if (count != 1) { \ 68 return BCM_E_INTERNAL; \ 69 } \ 70 BCM_PBMP_ITER(_pbmp, _local_port) { \ 71 break; \ 72 } \ 73 } while (0) 74 75 /* Convert PBMP to one single port not matter which */ 76 #define DPP_PBMP_SINGLE_PORT_GET(_pbmp, _local_port) \ 77 do { \ 78 int count; \ 79 BCM_PBMP_COUNT(_pbmp, count); \ 80 if (count == 0) { \ 81 return BCM_E_INTERNAL; \ 82 } \ 83 BCM_PBMP_ITER(_pbmp, _local_port) { \ 84 break; \ 85 } \ 86 } while (0) 87 88 /* If a pointer is not null, fill it with value */ 89 #define DPP_IF_NOT_NULL_FILL(_p, _value) \ 90 do { \ 91 if ((_p) != NULL) { \ 92 *(_p) = (_value); \ 93 } \ 94 } while (0); 95 96 /* If a flag is set return TRUE, otherwise return FALSE */ 97 #define DPP_IS_FLAG_SET(_flags, _required_flag) \ 98 (((_flags) & (_required_flag)) ? TRUE : FALSE) 99 100 /* Returns a pointers value if not null, otherwise returns 0 */ 101 #define DPP_VALUE_IF_NOT_NULL(_p) \ 102 ((_p) ? *(_p) : 0) 103 104 #if defined(BCM_SBUSDMA_SUPPORT) || defined(BCM_88650_A0) 105 extern sbusdma_desc_handle_t _soc_port_tx_handles[FRAGMENT_SIZE][3]; 106 #endif 107 extern volatile uint32 _soc_tx_pending[BCM_MAX_NUM_UNITS]; 108 109 typedef enum _bcm_dpp_convert_flag_e{ 110 _BCM_DPP_CONVERT_FLAG_NONE = 0, 111 _BCM_DPP_CONVERT_FLAG_PP_TO_LOCAL, 112 _BCM_DPP_CONVERT_FLAG_TM_TO_LOCAL, 113 _BCM_DPP_CONVERT_FLAG_LOCAL_TO_PP, 114 _BCM_DPP_CONVERT_FLAG_LOCAL_TO_TM 115 } _bcm_dpp_convert_flag_t; 116 117 int 118 pbmp_from_ppd_port_bitmap( 119 int unit, 120 bcm_pbmp_t *pbmp, 121 uint32 *ports, 122 int ports_len); 123 124 int 125 pbmp_to_ppd_port_bitmap( 126 int unit, 127 bcm_pbmp_t *pbmp, 128 uint32 *ports, 129 int ports_len); 130 131 132 133 int 134 pbmp_from_ppd_port_bitmap_convert( 135 int unit, 136 int core_id, 137 uint32 *ports, 138 int ports_len, 139 _bcm_dpp_convert_flag_t flag, 140 bcm_pbmp_t *pbmp 141 ); 142 143 144 145 int 146 pbmp_to_ppd_port_bitmap_convert( 147 int unit, 148 int core_id, 149 bcm_pbmp_t *pbmp, 150 int ports_len, 151 _bcm_dpp_convert_flag_t flag, 152 uint32 *ports 153 ); 154 155 156 int 157 _bcm_petra_mac_to_sand_mac( 158 bcm_mac_t bcm_mac, 159 SOC_SAND_PP_MAC_ADDRESS *soc_ppd_mac); 160 161 int 162 _bcm_petra_mac_from_sand_mac( 163 bcm_mac_t bcm_mac, 164 SOC_SAND_PP_MAC_ADDRESS *soc_ppd_mac); 165 166 int 167 _bcm_petra_utils( 168 bcm_mac_t bcm_mac, 169 SOC_SAND_PP_MAC_ADDRESS *soc_ppd_mac); 170 171 /* 172 * Function 173 * _bcm_petra_pbmp_filter_by_core 174 * Purpose 175 * Returns only ports of the input core. 176 * 177 * Parameters 178 * (IN) core_id : required core 179 * (IN) pbmp : bcm_pbmp_t of local ports 180 * (OUT) core_pbmp : returned pbmp: ports of the core 181 * Returns 182 * BCM_E_NONE - success 183 * BCM_E_* - failure 184 */ 185 186 int 187 _bcm_pbmp_filter_by_core( 188 int unit, 189 int core_id, 190 bcm_pbmp_t pbmp, 191 bcm_pbmp_t *core_pbmp); 192 193 /* 194 * resources definitions 195 */ 196 #define BCM_DPP_MAX_MC_ID(unit) ARAD_MAX_MC_ID(unit) 197 198 #define BCM_DPP_MAX_TRUNK_ID(unit) (SOC_TMC_PORT_LAGS_MAX) 199 200 /* needed to put these somewhere */ 201 extern int bcm_petra_stat_stop(int unit); 202 203 /* Given a uint32 containing flags and a flag(s), sets another uint32 with a different flag(s)*/ 204 #define DPP_TRANSLATE_FLAG(_src, _flag, _target, _target_flag) \ 205 if ((_src) & (_flag)) { \ 206 (_target) |= (_target_flag); \ 207 } 208 209 #define DPP_BMP_IS_SUBSET(_bmp, _potential_subset) \ 210 ((_bmp) == ((_bmp) | (_potential_subset))) 211 212 #define DPP_BMP_IS_SUBSET_AND_NOT_EMPTY(_bmp, _potential_subset) \ 213 (DPP_BMP_IS_SUBSET(_bmp, _potential_subset) && ((_potential_subset) != 0)) 214 215 /* 216 * Function 217 * _bcm_pkt_to_soc_pkt 218 * Purpose 219 * Convers a bcm_pkt to soc_pkt. (Currenttly the packets are identical and copy id done.) 220 * 221 * Parameters 222 * (IN) bcm_pkt : bcm_pkt_t 223 * (OUT) soc_pkt : returned soc_pkt_t 224 * Returns 225 * BCM_E_NONE - success 226 * BCM_E_* - failure 227 */ 228 229 int 230 _bcm_dpp_bcm_pkt_to_soc_pkt( 231 bcm_pkt_t *bcm_pkt, 232 soc_pkt_t *soc_pkt); 233 /* 234 * Function 235 * _bcm_pkt_to_soc_pkt 236 * Purpose 237 * Convers a bcm_pkt to soc_pkt. (Currenttly the packets are identical and copy id done.) 238 * 239 * Parameters 240 * (IN) soc_pkt : soc_pkt_t 241 * (OUT) bcm_pkt : returned pcm_pkt_t 242 * Returns 243 * BCM_E_NONE - success 244 * BCM_E_* - failure 245 */ 246 247 int 248 _bcm_dpp_soc_pkt_to_bcm_pkt( 249 soc_pkt_t *soc_pkt, 250 bcm_pkt_t *bcm_pkt); 251 252 253 #endif /* INCLUDE_DPP_UTILS_H */