pack_pbmp.c (2280B)
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: pack_pbmp.c 8 * Purpose: BCM API Type Packers - port bitmaps 9 */ 10 11 #include <bcm/types.h> 12 #include <shared/pbmp.h> 13 #include <bcm_int/rpc/pack.h> 14 15 /* 16 * Two different mechanisms for packing bcm_pbmp_t structures are provided. 17 * 18 * If BCM_RPC_PBMP_64 is not defined then rpc version 3 is in use and port 19 * bitmaps are packed as: 20 * <uint8 nword><uint32 word[0]>...<uint32 word[nword-1]> 21 * This packing method handles bcm implementations compiled with differing 22 * lengths of port bitmaps and is potentially more efficient in packing size 23 * (zero value trailing words are not packed) 24 * 25 * If BCM_RPC_PBMP_64 is defined, then rpc version 2 is in use and 26 * port bitmaps are packed as: 27 * <uint32 word[0]><uint32 word[1]> 28 * The second packing method is limited to 64 bit port bitmaps but is 29 * backwards compatible with sdk-5.3 and sdk-5.4 releases. 30 */ 31 32 #ifndef BCM_RPC_PBMP_64 33 34 uint8 * 35 _bcm_pack_pbmp(uint8 *buf, bcm_pbmp_t *var) 36 { 37 uint8 nwords; 38 int i; 39 40 /* back up over zero values words */ 41 for (i = _SHR_PBMP_WORD_MAX-1; i >= 0; i--) { 42 if (_SHR_PBMP_WORD_GET(*var, i) != 0) { 43 break; 44 } 45 } 46 nwords = i+1; 47 BCM_PACK_U8(buf, nwords); 48 for (i = 0; i < nwords; i++) { 49 BCM_PACK_U32(buf, _SHR_PBMP_WORD_GET(*var, i)); 50 } 51 return buf; 52 } 53 54 uint8 * 55 _bcm_unpack_pbmp(uint8 *buf, bcm_pbmp_t *var) 56 { 57 uint8 nwords; 58 uint32 pword; 59 int i; 60 61 BCM_UNPACK_U8(buf, nwords); 62 for (i = 0; i < nwords; i++) { 63 BCM_UNPACK_U32(buf, pword); 64 if (i < _SHR_PBMP_WORD_MAX) { 65 _SHR_PBMP_WORD_SET(*var, i, pword); 66 } 67 } 68 /* clear any remaining words */ 69 for (i = nwords; i < _SHR_PBMP_WORD_MAX; i++) { 70 _SHR_PBMP_WORD_SET(*var, i, 0); 71 } 72 return buf; 73 } 74 75 #else /* BCM_RPC_PBMP_64 */ 76 77 uint8 * 78 _bcm_pack_pbmp(uint8 *buf, bcm_pbmp_t *var) 79 { 80 BCM_PACK_U32(buf, var->pbits[0]); 81 BCM_PACK_U32(buf, var->pbits[1]); 82 return buf; 83 } 84 85 uint8 * 86 _bcm_unpack_pbmp(uint8 *buf, bcm_pbmp_t *var) 87 { 88 BCM_UNPACK_U32(buf, var->pbits[0]); 89 BCM_UNPACK_U32(buf, var->pbits[1]); 90 return buf; 91 } 92 93 #endif /* BCM_RPC_PBMP_64 */