compat_6511.c (14154B)
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 * RPC Compatibility with <=sdk-6.5.11 routines 8 */ 9 10 #ifdef BCM_RPC_SUPPORT 11 12 #include <shared/alloc.h> 13 #include <bcm/error.h> 14 #include <bcm/cosq.h> 15 #include <bcm/mirror.h> 16 #include <bcm_int/compat/compat_6511.h> 17 18 /* 19 * Function: 20 * bcm_compat6511in_cosq_pfc_class_mapping_t 21 * Purpose: 22 * Convert the bcm_cosq_pfc_class_mapping_t datatype from <=6.5.11 to 23 * SDK 6.5.12+ 24 * Parameters: 25 * from - (IN) The <=6.5.11 version of the datatype 26 * to - (OUT) The SDK 6.5.12+ version of the datatype 27 * Returns: 28 * Nothing 29 */ 30 STATIC void 31 bcm_compat6511in_cosq_pfc_class_mapping_t(bcm_compat6511_cosq_pfc_class_mapping_t *from, 32 bcm_cosq_pfc_class_mapping_t *to) 33 { 34 int index = 0; 35 bcm_cosq_pfc_class_mapping_t_init(to); 36 to->class_id = from->class_id; 37 for (index = 0; index < BCM_COMPAT6511_COSQ_PFC_GPORT_COUNT; index++) { 38 to->gport_list[index] = from->gport_list[index]; 39 } 40 } 41 42 /* 43 * Function: 44 * bcm_compat6511out_cosq_pfc_class_mapping_t 45 * Purpose: 46 * Convert bcm_cosq_pfc_class_mapping_t datatype from 6.5.12+ to 47 * <=6.5.11 48 * Parameters: 49 * from - (IN) The SDK 6.5.12+ version of the datatype 50 * to - (OUT) The <=6.5.11 version of the datatype 51 * Returns: 52 * Nothing 53 */ 54 55 STATIC void 56 bcm_compat6511out_cosq_pfc_class_mapping_t(bcm_cosq_pfc_class_mapping_t *from, 57 bcm_compat6511_cosq_pfc_class_mapping_t *to) 58 { 59 int index = 0; 60 to->class_id = from->class_id; 61 for (index = 0; index < BCM_COMPAT6511_COSQ_PFC_GPORT_COUNT; index++) { 62 to->gport_list[index] = from->gport_list[index]; 63 } 64 } 65 66 /* 67 * Function: bcm_compat6511_cosq_pfc_class_mapping_set 68 * 69 * Purpose: 70 * Compatibility function for RPC call to bcm_cosq_pfc_class_mapping_set. 71 * 72 * Parameters: 73 * unit - (IN) BCM device number. 74 * port - (IN) Port number. 75 * array_count - (IN) Number of mappings in mapping_array. 76 * mapping_array - (IN/OUT) Array of PFC class mappings with old format 77 * 78 * Returns: 79 * BCM_E_XXX 80 */ 81 int 82 bcm_compat6511_cosq_pfc_class_mapping_set(int unit, bcm_gport_t port, int array_count, 83 bcm_compat6511_cosq_pfc_class_mapping_t *mapping_array) 84 { 85 int rv; 86 bcm_cosq_pfc_class_mapping_t *new_mapping_array; 87 int index; 88 89 if (mapping_array == NULL) { 90 return BCM_E_PARAM; 91 } 92 /* Create from heap to avoid the stack to bloat */ 93 new_mapping_array = (bcm_cosq_pfc_class_mapping_t*) 94 sal_alloc(array_count * sizeof(bcm_cosq_pfc_class_mapping_t), "new_mapping_array"); 95 if (NULL == new_mapping_array) { 96 return BCM_E_MEMORY; 97 } 98 99 for(index = 0; index < array_count; index++) { 100 /* Transform the mapping from the old format to new one */ 101 bcm_compat6511in_cosq_pfc_class_mapping_t( &mapping_array[index], 102 &new_mapping_array[index]); 103 } 104 /* Call the BCM API with new format */ 105 rv = bcm_cosq_pfc_class_mapping_set(unit, port, array_count, new_mapping_array); 106 107 for (index = 0; index < array_count; index++) { 108 /* Transform the mapping from the new format to old one */ 109 bcm_compat6511out_cosq_pfc_class_mapping_t(&new_mapping_array[index], 110 &mapping_array[index]); 111 } 112 113 /* Deallocate memory*/ 114 sal_free(new_mapping_array); 115 116 return rv; 117 } 118 119 120 /* 121 * Function: bcm_compat6511_cosq_pfc_class_mapping_get 122 * 123 * Purpose: 124 * Compatibility function for RPC call to bcm_cosq_pfc_class_mapping_set. 125 * 126 * Parameters: 127 * unit - (IN) BCM device number. 128 * port - (IN) Port number. 129 * array_max - (IN) Number of mappings allocated in mapping_array. 130 * mapping_array - (IN/OUT) Array of PFC class mappings with old format. 131 * array_count - (OUT) Number of mappings returned. 132 * 133 * Returns: 134 * BCM_E_XXX 135 */ 136 int 137 bcm_compat6511_cosq_pfc_class_mapping_get(int unit, bcm_gport_t port, int array_max, 138 bcm_compat6511_cosq_pfc_class_mapping_t *mapping_array, int *array_count) 139 { 140 int rv; 141 int index; 142 bcm_cosq_pfc_class_mapping_t *new_mapping_array = NULL; 143 144 if ((mapping_array == NULL) && (array_max > 0)) { 145 return BCM_E_PARAM; 146 } 147 148 if (array_max > 0) { 149 /* Create from heap to avoid the stack to bloat */ 150 new_mapping_array = (bcm_cosq_pfc_class_mapping_t*) 151 sal_alloc(array_max * sizeof(bcm_cosq_pfc_class_mapping_t), "new_mapping_array"); 152 if (NULL == new_mapping_array) { 153 return BCM_E_MEMORY; 154 } 155 156 for(index = 0; index < array_max; index++) { 157 /* Transform the mapping from the old format to new one */ 158 bcm_compat6511in_cosq_pfc_class_mapping_t(&mapping_array[index], 159 &new_mapping_array[index]); 160 } 161 /* Call the BCM API with new format */ 162 rv = bcm_cosq_pfc_class_mapping_get(unit, port, array_max, new_mapping_array, array_count); 163 } else { 164 /* Call the BCM API with new format */ 165 rv = bcm_cosq_pfc_class_mapping_get(unit, port, array_max, NULL, array_count); 166 } 167 168 if (array_max > 0) { 169 /* Transform the mapping from the new format to old one */ 170 for(index = 0; index < array_max; index++) { 171 bcm_compat6511out_cosq_pfc_class_mapping_t(&new_mapping_array[index], 172 &mapping_array[index]); 173 } 174 /* Deallocate memory*/ 175 sal_free(new_mapping_array); 176 } 177 178 return rv; 179 } 180 181 /* 182 * Function: 183 * _bcm_compat6511in_mirror_destination_t 184 * Purpose: 185 * Convert the bcm_mirror_destination_t datatype from <=6.5.11 to 186 * SDK 6.5.12+ 187 * Parameters: 188 * from - (IN) The <=6.5.11 version of the datatype 189 * to - (OUT) The SDK 6.5.12+ version of the datatype 190 * Returns: 191 * Nothing 192 */ 193 STATIC void 194 _bcm_compat6511in_mirror_destination_t(bcm_compat6511_mirror_destination_t 195 *from, 196 bcm_mirror_destination_t *to) 197 { 198 bcm_mirror_destination_t_init(to); 199 to->mirror_dest_id = from->mirror_dest_id; 200 to->flags = from->flags; 201 to->gport = from->gport; 202 to->version = from->version; 203 to->tos = from->tos; 204 to->ttl = from->ttl; 205 to->src_addr = from->src_addr; 206 to->dst_addr = from->dst_addr; 207 sal_memcpy(to->src6_addr, from->src6_addr, 16); 208 sal_memcpy(to->dst6_addr, from->dst6_addr, 16); 209 to->flow_label = from->flow_label; 210 sal_memcpy(to->src_mac, from->src_mac, 6); 211 sal_memcpy(to->dst_mac, from->dst_mac, 6); 212 to->tpid = from->tpid; 213 to->vlan_id = from->vlan_id; 214 to->trill_src_name = from->trill_src_name; 215 to->trill_dst_name = from->trill_dst_name; 216 to->trill_hopcount = from->trill_hopcount; 217 to->niv_src_vif = from->niv_src_vif; 218 to->niv_dst_vif = from->niv_dst_vif; 219 to->niv_flags = from->niv_flags; 220 to->gre_protocol = from->gre_protocol; 221 to->policer_id = from->policer_id; 222 to->stat_id = from->stat_id; 223 to->stat_id2 = from->stat_id2; 224 to->encap_id = from->encap_id; 225 to->tunnel_id = from->tunnel_id; 226 to->span_id = from->span_id; 227 to->pkt_prio = from->pkt_prio; 228 to->sample_rate_dividend = from->sample_rate_dividend; 229 to->sample_rate_divisor = from->sample_rate_divisor; 230 to->int_pri = from->int_pri; 231 to->etag_src_vid = from->etag_src_vid; 232 to->etag_dst_vid = from->etag_dst_vid; 233 to->udp_src_port = from->udp_src_port; 234 to->udp_dst_port = from->udp_dst_port; 235 to->egress_sample_rate_dividend = from->egress_sample_rate_dividend; 236 to->egress_sample_rate_divisor = from->egress_sample_rate_divisor; 237 to->recycle_context = from->recycle_context; 238 to->packet_copy_size = from->packet_copy_size; 239 to->egress_packet_copy_size = from->egress_packet_copy_size; 240 to->packet_control_updates = from->packet_control_updates; 241 to->rtag = from->rtag; 242 to->df = from->df; 243 to->truncate = from->truncate; 244 to->template_id = from->template_id; 245 to->observation_domain = from->observation_domain; 246 to->is_recycle_strict_priority = from->is_recycle_strict_priority; 247 } 248 249 /* 250 * Function: 251 * _bcm_compat6511out_mirror_destination_t 252 * Purpose: 253 * Convert the bcm_mirror_destination_t datatype from 6.5.12+ to 254 * <=6.5.11 255 * Parameters: 256 * from - (IN) The SDK 6.5.12+ version of the datatype 257 * to - (OUT) The <=6.5.11 version of the datatype 258 * Returns: 259 * Nothing 260 */ 261 STATIC void 262 _bcm_compat6511out_mirror_destination_t(bcm_mirror_destination_t *from, 263 bcm_compat6511_mirror_destination_t *to) 264 { 265 to->mirror_dest_id = from->mirror_dest_id; 266 to->flags = from->flags; 267 to->gport = from->gport; 268 to->version = from->version; 269 to->tos = from->tos; 270 to->ttl = from->ttl; 271 to->src_addr = from->src_addr; 272 to->dst_addr = from->dst_addr; 273 sal_memcpy(to->src6_addr, from->src6_addr, 16); 274 sal_memcpy(to->dst6_addr, from->dst6_addr, 16); 275 to->flow_label = from->flow_label; 276 sal_memcpy(to->src_mac, from->src_mac, 6); 277 sal_memcpy(to->dst_mac, from->dst_mac, 6); 278 to->tpid = from->tpid; 279 to->vlan_id = from->vlan_id; 280 to->trill_src_name = from->trill_src_name; 281 to->trill_dst_name = from->trill_dst_name; 282 to->trill_hopcount = from->trill_hopcount; 283 to->niv_src_vif = from->niv_src_vif; 284 to->niv_dst_vif = from->niv_dst_vif; 285 to->niv_flags = from->niv_flags; 286 to->gre_protocol = from->gre_protocol; 287 to->policer_id = from->policer_id; 288 to->stat_id = from->stat_id; 289 to->stat_id2 = from->stat_id2; 290 to->encap_id = from->encap_id; 291 to->tunnel_id = from->tunnel_id; 292 to->span_id = from->span_id; 293 to->pkt_prio = from->pkt_prio; 294 to->sample_rate_dividend = from->sample_rate_dividend; 295 to->sample_rate_divisor = from->sample_rate_divisor; 296 to->int_pri = from->int_pri; 297 to->etag_src_vid = from->etag_src_vid; 298 to->etag_dst_vid = from->etag_dst_vid; 299 to->udp_src_port = from->udp_src_port; 300 to->udp_dst_port = from->udp_dst_port; 301 to->egress_sample_rate_dividend = from->egress_sample_rate_dividend; 302 to->egress_sample_rate_divisor = from->egress_sample_rate_divisor; 303 to->recycle_context = from->recycle_context; 304 to->packet_copy_size = from->packet_copy_size; 305 to->egress_packet_copy_size = from->egress_packet_copy_size; 306 to->packet_control_updates = from->packet_control_updates; 307 to->rtag = from->rtag; 308 to->df = from->df; 309 to->truncate = from->truncate; 310 to->template_id = from->template_id; 311 to->observation_domain = from->observation_domain; 312 to->is_recycle_strict_priority = from->is_recycle_strict_priority; 313 } 314 315 /* 316 * Function: bcm_compat6511_mirror_destination_create 317 * 318 * Purpose: 319 * Compatibility function for RPC call to bcm_mirror_destination_create 320 * 321 * Parameters: 322 * unit - (IN) BCM device number. 323 * mirror_dest - (IN/OUT) Mirrored destination and encapsulation. 324 * 325 * Returns: 326 * BCM_E_XXX 327 */ 328 int 329 bcm_compat6511_mirror_destination_create(int unit, 330 bcm_compat6511_mirror_destination_t 331 *mirror_dest) 332 { 333 int rv; 334 bcm_mirror_destination_t *new_mirror_dest = NULL; 335 336 if (NULL != mirror_dest) { 337 /* Create from heap to avoid the stack to bloat */ 338 new_mirror_dest = (bcm_mirror_destination_t *) 339 sal_alloc(sizeof(bcm_mirror_destination_t), "New Mirror Dst Entry"); 340 if (NULL == new_mirror_dest) { 341 return BCM_E_MEMORY; 342 } 343 344 /* Transform the entry from the old format to new one */ 345 _bcm_compat6511in_mirror_destination_t(mirror_dest, 346 new_mirror_dest); 347 } 348 349 /* Call the BCM API with new format */ 350 rv = bcm_mirror_destination_create(unit, new_mirror_dest); 351 352 if (NULL != new_mirror_dest) { 353 /* Transform the entry from the new format to old one */ 354 _bcm_compat6511out_mirror_destination_t(new_mirror_dest, 355 mirror_dest); 356 357 /* Deallocate memory */ 358 sal_free(new_mirror_dest); 359 } 360 361 return rv; 362 } 363 364 /* 365 * Function: bcm_compat6511_mirror_destination_get 366 * 367 * Purpose: 368 * Compatibility function for RPC call to bcm_mirror_destination_get 369 * 370 * Parameters: 371 * unit - (IN) BCM device number. 372 * mirror_dest_id - (IN) Mirrored destination ID. 373 * mirror_dest - (IN/OUT) Matching Mirrored destination descriptor. 374 * 375 * Returns: 376 * BCM_E_XXX 377 */ 378 int 379 bcm_compat6511_mirror_destination_get(int unit, bcm_gport_t mirror_dest_id, 380 bcm_compat6511_mirror_destination_t 381 *mirror_dest) 382 { 383 int rv; 384 bcm_mirror_destination_t *new_mirror_dest = NULL; 385 386 if (NULL != mirror_dest) { 387 /* Create from heap to avoid the stack to bloat */ 388 new_mirror_dest = (bcm_mirror_destination_t *) 389 sal_alloc(sizeof(bcm_mirror_destination_t), "New Mirror Dst Entry"); 390 if (NULL == new_mirror_dest) { 391 return BCM_E_MEMORY; 392 } 393 394 /* Transform the entry from the old format to new one */ 395 _bcm_compat6511in_mirror_destination_t(mirror_dest, 396 new_mirror_dest); 397 } 398 399 /* Call the BCM API with new format */ 400 rv = bcm_mirror_destination_get(unit, mirror_dest_id, new_mirror_dest); 401 402 if (NULL != new_mirror_dest) { 403 /* Transform the entry from the new format to old one */ 404 _bcm_compat6511out_mirror_destination_t(new_mirror_dest, 405 mirror_dest); 406 407 /* Deallocate memory */ 408 sal_free(new_mirror_dest); 409 } 410 411 return rv; 412 } 413 #endif /* BCM_RPC_SUPPORT */