ulink_pack.c (2098B)
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: ulink_pack.c 8 * Purpose: ULINK pack and unpack routines for: 9 * - ukernel link module 10 * 11 * 12 * ULINK control messages 13 * 14 * ULINK messages between the Host CPU and uController are sent 15 * using the uc_message module which allows short messages 16 * to be passed (see include/soc/shared/mos_msg_common.h) 17 * 18 * Additional information for a given message (a long message) is passed 19 * using DMA. The ULINK control message types defines the format 20 * for these long messages. 21 * 22 * This file is shared between SDK and uKernel. 23 */ 24 25 #include <soc/defs.h> 26 #include <shared/pack.h> 27 #include <soc/shared/ulink_pack.h> 28 29 /********************************************************* 30 * ULINK port bitmap Pack/Unpack 31 * 32 * Functions: 33 * shr_ulink_pbm_pack/unpack 34 * Purpose: 35 * The following set of routines pack/unpack link 36 * bitmap to/from given buffer. 37 * Parameters: 38 * _pack() 39 * buffer - (OUT) Buffer where to pack bitmap. 40 * <header> - (IN) bitmap to pack. 41 * _unpack() 42 * buffer - (IN) Buffer with data to unpack. 43 * <header> - (OUT) Returns unpack header. 44 * Returns: 45 * Pointer to next position in buffer. 46 * Notes: 47 * Assumes pointers are valid and contain enough memory space. 48 */ 49 uint8 * 50 shr_ulink_pbm_unpack(uint8 *bufp, soc_ulink_pbm_msg_t *msg) 51 { 52 int i, word_max; 53 54 _SHR_UNPACK_U8(bufp, msg->flags); 55 _SHR_UNPACK_U8(bufp, msg->words); 56 word_max = (msg->words <= UL_PBMP_WORD_MAX) ? msg->words : UL_PBMP_WORD_MAX; 57 58 for(i = 0; i < word_max; i++) { 59 _SHR_UNPACK_U32(bufp,msg->pbits[i]); 60 } 61 return bufp; 62 } 63 64 uint8 * 65 shr_ulink_pbm_pack(uint8 *bufp, soc_ulink_pbm_msg_t *msg) 66 { 67 int i; 68 _SHR_PACK_U8(bufp, msg->flags); 69 _SHR_PACK_U8(bufp, msg->words); 70 for(i = 0; i < msg->words; i++) { 71 _SHR_PACK_U32(bufp,msg->pbits[i]); 72 } 73 return bufp; 74 } 75