ifa_pack.c (5933B)
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: ifa_pack.c 8 * Purpose: IFA pack and unpack routines for: 9 * - IFA Control messages 10 * 11 * 12 * IFA control messages 13 * 14 * IFA 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 IFA 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/ifa.h> 27 #include <soc/shared/ifa_msg.h> 28 #include <soc/shared/ifa_pack.h> 29 30 /* 31 * IFA Initialization control message packing 32 */ 33 uint8* 34 shr_ifa_msg_ctrl_init_pack(uint8 *buf, shr_ifa_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 * IFA Initialization control message 43 */ 44 uint8* 45 shr_ifa_msg_ctrl_init_unpack(uint8 *buf, shr_ifa_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 IFA collector - pack 54 */ 55 uint8* 56 shr_ifa_msg_ctrl_collector_info_pack(uint8* buf, 57 shr_ifa_msg_ctrl_collector_info_t *msg) 58 { 59 int i; 60 61 _SHR_PACK_U16(buf, msg->encap_length); 62 for (i = 0; i < msg->encap_length; i++) { 63 _SHR_PACK_U8(buf, msg->encap[i]); 64 } 65 66 _SHR_PACK_U32(buf, msg->ip_base_checksum); 67 _SHR_PACK_U32(buf, msg->udp_base_checksum); 68 _SHR_PACK_U32(buf, msg->outer_vlan_tag); 69 _SHR_PACK_U32(buf, msg->inner_vlan_tag); 70 _SHR_PACK_U16(buf, msg->mtu); 71 _SHR_PACK_U16(buf, msg->ip_offset); 72 _SHR_PACK_U16(buf, msg->udp_offset); 73 _SHR_PACK_U16(buf, msg->outer_tpid); 74 _SHR_PACK_U16(buf, msg->inner_tpid); 75 _SHR_PACK_U8(buf, msg->vlan_tag_structure); 76 _SHR_PACK_U8(buf, msg->transport_type); 77 78 return buf; 79 } 80 81 /* 82 * Create IFA collector - unpack 83 */ 84 uint8* 85 shr_ifa_msg_ctrl_collector_info_unpack(uint8* buf, 86 shr_ifa_msg_ctrl_collector_info_t *msg) 87 { 88 int i; 89 90 _SHR_UNPACK_U16(buf, msg->encap_length); 91 for (i = 0; i < msg->encap_length; i++) { 92 _SHR_UNPACK_U8(buf, msg->encap[i]); 93 } 94 95 _SHR_UNPACK_U32(buf, msg->ip_base_checksum); 96 _SHR_UNPACK_U32(buf, msg->udp_base_checksum); 97 _SHR_UNPACK_U32(buf, msg->outer_vlan_tag); 98 _SHR_UNPACK_U32(buf, msg->inner_vlan_tag); 99 _SHR_UNPACK_U16(buf, msg->mtu); 100 _SHR_UNPACK_U16(buf, msg->ip_offset); 101 _SHR_UNPACK_U16(buf, msg->udp_offset); 102 _SHR_UNPACK_U16(buf, msg->outer_tpid); 103 _SHR_UNPACK_U16(buf, msg->inner_tpid); 104 _SHR_UNPACK_U8(buf, msg->vlan_tag_structure); 105 _SHR_UNPACK_U8(buf, msg->transport_type); 106 107 return buf; 108 } 109 110 /* 111 * Create IFA config information - pack 112 */ 113 uint8* 114 shr_ifa_msg_ctrl_config_info_pack(uint8* buf, 115 shr_ifa_msg_ctrl_config_info_t *msg) 116 { 117 int i; 118 119 _SHR_PACK_U32(buf, msg->probemarker_1); 120 _SHR_PACK_U32(buf, msg->probemarker_2); 121 _SHR_PACK_U32(buf, msg->device_id); 122 _SHR_PACK_U16(buf, msg->lb_port_1); 123 _SHR_PACK_U16(buf, msg->lb_port_2); 124 _SHR_PACK_U16(buf, msg->module_id); 125 126 _SHR_PACK_U16(buf, msg->rx_packet_payload_length); 127 _SHR_PACK_U16(buf, msg->max_payload_length); 128 _SHR_PACK_U8(buf, msg->optional_headers); 129 _SHR_PACK_U8(buf, msg->hop_limit); 130 131 _SHR_PACK_U16(buf, msg->int_encap_length); 132 for (i = 0; i < msg->int_encap_length; i++) { 133 _SHR_PACK_U8(buf, msg->int_encap[i]); 134 } 135 136 _SHR_PACK_U16(buf, msg->lb_encap_length); 137 for (i = 0; i < msg->lb_encap_length; i++) { 138 _SHR_PACK_U8(buf, msg->lb_encap[i]); 139 } 140 141 return buf; 142 } 143 144 /* 145 * Create IFA config information - unpack 146 */ 147 uint8* 148 shr_ifa_msg_ctrl_config_info_unpack(uint8* buf, 149 shr_ifa_msg_ctrl_config_info_t *msg) 150 { 151 int i; 152 153 _SHR_UNPACK_U32(buf, msg->probemarker_1); 154 _SHR_UNPACK_U32(buf, msg->probemarker_2); 155 _SHR_UNPACK_U32(buf, msg->device_id); 156 _SHR_UNPACK_U16(buf, msg->lb_port_1); 157 _SHR_UNPACK_U16(buf, msg->lb_port_2); 158 _SHR_UNPACK_U16(buf, msg->module_id); 159 160 _SHR_UNPACK_U16(buf, msg->rx_packet_payload_length); 161 _SHR_UNPACK_U16(buf, msg->max_payload_length); 162 _SHR_UNPACK_U8(buf, msg->optional_headers); 163 _SHR_UNPACK_U8(buf, msg->hop_limit); 164 165 _SHR_UNPACK_U16(buf, msg->int_encap_length); 166 for (i = 0; i < msg->int_encap_length; i++) { 167 _SHR_UNPACK_U8(buf, msg->int_encap[i]); 168 } 169 170 _SHR_UNPACK_U16(buf, msg->lb_encap_length); 171 for (i = 0; i < msg->lb_encap_length; i++) { 172 _SHR_UNPACK_U8(buf, msg->lb_encap[i]); 173 } 174 175 return buf; 176 } 177 178 /* 179 * Create IFA statistics information - pack 180 */ 181 uint8* 182 shr_ifa_msg_ctrl_stat_info_pack(uint8* buf, 183 shr_ifa_msg_ctrl_stat_info_t *msg) 184 { 185 _SHR_PACK_U32(buf, msg->rx_pkt_cnt); 186 _SHR_PACK_U32(buf, msg->tx_pkt_cnt); 187 _SHR_PACK_U32(buf, msg->ifa_no_config_drop); 188 _SHR_PACK_U32(buf, msg->ifa_collector_not_present_drop); 189 _SHR_PACK_U32(buf, msg->ifa_hop_cnt_invalid_drop); 190 _SHR_PACK_U32(buf, msg->ifa_int_hdr_len_invalid_drop); 191 _SHR_PACK_U32(buf, msg->ifa_pkt_size_invalid_drop); 192 return buf; 193 } 194 195 /* 196 * Create IFA statistics information - unpack 197 */ 198 uint8* 199 shr_ifa_msg_ctrl_stat_info_unpack(uint8* buf, 200 shr_ifa_msg_ctrl_stat_info_t *msg) 201 { 202 _SHR_UNPACK_U32(buf, msg->rx_pkt_cnt); 203 _SHR_UNPACK_U32(buf, msg->tx_pkt_cnt); 204 _SHR_UNPACK_U32(buf, msg->ifa_no_config_drop); 205 _SHR_UNPACK_U32(buf, msg->ifa_collector_not_present_drop); 206 _SHR_UNPACK_U32(buf, msg->ifa_hop_cnt_invalid_drop); 207 _SHR_UNPACK_U32(buf, msg->ifa_int_hdr_len_invalid_drop); 208 _SHR_UNPACK_U32(buf, msg->ifa_pkt_size_invalid_drop); 209 return buf; 210 }