int_pack.c (4184B)
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: int_pack.c 8 * Purpose: INT pack and unpack routines for: 9 * - INT Control messages 10 * 11 * 12 * INT control messages 13 * 14 * INT 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 INT 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 <shared/pack.h> 26 #include <soc/shared/int.h> 27 #include <soc/shared/int_msg.h> 28 #include <soc/shared/int_pack.h> 29 30 /* 31 * INT TURNAROUND Initialization control message packing 32 */ 33 uint8* 34 shr_int_turnaround_msg_ctrl_init_pack(uint8 *buf, shr_int_turnaround_msg_ctrl_init_t *msg) 35 { 36 _SHR_PACK_U32(buf, msg->rx_channel); 37 _SHR_PACK_U32(buf, msg->tx_channel); 38 return buf; 39 } 40 41 /* 42 * INT TURNAROUND Initialization control message 43 */ 44 uint8* 45 shr_int_turnaround_msg_ctrl_init_unpack(uint8 *buf, shr_int_turnaround_msg_ctrl_init_t *msg) 46 { 47 _SHR_UNPACK_U32(buf, msg->rx_channel); 48 _SHR_UNPACK_U32(buf, msg->tx_channel); 49 return buf; 50 } 51 52 /* 53 * Create INT TURNAROUND config information - pack 54 */ 55 uint8* 56 shr_int_turnaround_msg_ctrl_config_pack(uint8* buf, 57 shr_int_turnaround_msg_ctrl_config_t *msg) 58 { 59 int i; 60 61 for (i = 0; i < SHR_MAC_ADDR_LENGTH; i++) { 62 _SHR_PACK_U8(buf, msg->src_mac[i]); 63 } 64 65 _SHR_PACK_U16(buf, msg->lb_encap_length); 66 for (i = 0; i < msg->lb_encap_length; i++) { 67 _SHR_PACK_U8(buf, msg->lb_encap[i]); 68 } 69 70 return buf; 71 } 72 73 /* 74 * Create INT TURNAROUND config information - unpack 75 */ 76 uint8* 77 shr_int_turnaround_msg_ctrl_config_unpack(uint8* buf, 78 shr_int_turnaround_msg_ctrl_config_t *msg) 79 { 80 int i; 81 82 for (i = 0; i < SHR_MAC_ADDR_LENGTH; i++) { 83 _SHR_UNPACK_U8(buf, msg->src_mac[i]); 84 } 85 86 _SHR_UNPACK_U16(buf, msg->lb_encap_length); 87 for (i = 0; i < msg->lb_encap_length; i++) { 88 _SHR_UNPACK_U8(buf, msg->lb_encap[i]); 89 } 90 return buf; 91 } 92 93 /* 94 * Create INT TURNAROUND statistics information - pack 95 */ 96 uint8* 97 shr_int_turnaround_msg_ctrl_stat_pack(uint8* buf, 98 shr_int_turnaround_msg_ctrl_stat_t *msg) 99 { 100 _SHR_PACK_U32(buf, msg->rx_pkt_cnt_hi); 101 _SHR_PACK_U32(buf, msg->rx_pkt_cnt_lo); 102 103 _SHR_PACK_U32(buf, msg->tx_pkt_cnt_hi); 104 _SHR_PACK_U32(buf, msg->tx_pkt_cnt_lo); 105 106 _SHR_PACK_U32(buf, msg->drop_pkt_cnt_hi); 107 _SHR_PACK_U32(buf, msg->drop_pkt_cnt_lo); 108 109 _SHR_PACK_U32(buf, msg->int_init_config_drop_hi); 110 _SHR_PACK_U32(buf, msg->int_init_config_drop_lo); 111 112 _SHR_PACK_U32(buf, msg->int_hop_cnt_invalid_drop_hi); 113 _SHR_PACK_U32(buf, msg->int_hop_cnt_invalid_drop_lo); 114 115 _SHR_PACK_U32(buf, msg->int_hdr_len_invalid_drop_hi); 116 _SHR_PACK_U32(buf, msg->int_hdr_len_invalid_drop_lo); 117 118 _SHR_PACK_U32(buf, msg->int_pkt_size_invalid_drop_hi); 119 _SHR_PACK_U32(buf, msg->int_pkt_size_invalid_drop_lo); 120 121 return buf; 122 } 123 124 /* 125 * Create INT TURNAROUND statistics information - unpack 126 */ 127 uint8* 128 shr_int_turnaround_msg_ctrl_stat_unpack(uint8* buf, 129 shr_int_turnaround_msg_ctrl_stat_t *msg) 130 { 131 _SHR_UNPACK_U32(buf, msg->rx_pkt_cnt_hi); 132 _SHR_UNPACK_U32(buf, msg->rx_pkt_cnt_lo); 133 134 _SHR_UNPACK_U32(buf, msg->tx_pkt_cnt_hi); 135 _SHR_UNPACK_U32(buf, msg->tx_pkt_cnt_lo); 136 137 _SHR_UNPACK_U32(buf, msg->drop_pkt_cnt_hi); 138 _SHR_UNPACK_U32(buf, msg->drop_pkt_cnt_lo); 139 140 _SHR_UNPACK_U32(buf, msg->int_init_config_drop_hi); 141 _SHR_UNPACK_U32(buf, msg->int_init_config_drop_lo); 142 143 _SHR_UNPACK_U32(buf, msg->int_hop_cnt_invalid_drop_hi); 144 _SHR_UNPACK_U32(buf, msg->int_hop_cnt_invalid_drop_lo); 145 146 _SHR_UNPACK_U32(buf, msg->int_hdr_len_invalid_drop_hi); 147 _SHR_UNPACK_U32(buf, msg->int_hdr_len_invalid_drop_lo); 148 149 _SHR_UNPACK_U32(buf, msg->int_pkt_size_invalid_drop_hi); 150 _SHR_UNPACK_U32(buf, msg->int_pkt_size_invalid_drop_lo); 151 152 return buf; 153 }