openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

st_pack.c (9686B)


      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:        st_pack.c
      8  * Purpose:     ST pack and unpack routines for:
      9  *              - ST Control messages
     10  *
     11  *
     12  * ST control messages
     13  *
     14  * ST 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 ST 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/st.h>
     27 #include <soc/shared/st_msg.h>
     28 #include <soc/shared/st_pack.h>
     29 
     30 /*
     31  * ST Initialization control message - pack
     32  */
     33 uint8*
     34 shr_st_msg_ctrl_init_pack(uint8 *buf, shr_st_msg_ctrl_init_t *msg)
     35 {
     36     _SHR_PACK_U32(buf, msg->flags);
     37     _SHR_PACK_U32(buf, msg->init_time_u);
     38     _SHR_PACK_U32(buf, msg->init_time_l);
     39     _SHR_PACK_U16(buf, msg->max_export_pkt_length);
     40     _SHR_PACK_U16(buf, msg->num_instances);
     41     _SHR_PACK_U16(buf, msg->num_collectors);
     42 
     43     return buf;
     44 }
     45 
     46 /*
     47  * ST Initialization control message - unpack
     48  */
     49 uint8*
     50 shr_st_msg_ctrl_init_unpack(uint8 *buf, shr_st_msg_ctrl_init_t *msg)
     51 {
     52     _SHR_UNPACK_U32(buf, msg->flags);
     53     _SHR_UNPACK_U32(buf, msg->init_time_u);
     54     _SHR_UNPACK_U32(buf, msg->init_time_l);
     55     _SHR_UNPACK_U16(buf, msg->max_export_pkt_length);
     56     _SHR_UNPACK_U16(buf, msg->num_instances);
     57     _SHR_UNPACK_U16(buf, msg->num_collectors);
     58 
     59     return buf;
     60 }
     61 
     62 /*
     63  * ST system ID message - pack
     64  */
     65 uint8*
     66 shr_st_msg_system_id_pack(uint8 *buf, shr_st_msg_system_id_t *msg)
     67 {
     68     int i;
     69 
     70     _SHR_PACK_U16(buf, msg->system_id_length);
     71     for (i = 0; i < msg->system_id_length; i++) {
     72         _SHR_PACK_U8(buf, msg->system_id[i]);
     73     }
     74 
     75     return buf;
     76 }
     77 
     78 /*
     79  * ST system ID message - unpack
     80  */
     81 uint8*
     82 shr_st_msg_system_id_unpack(uint8 *buf, shr_st_msg_system_id_t *msg)
     83 {
     84     int i;
     85 
     86     _SHR_UNPACK_U16(buf, msg->system_id_length);
     87     for (i = 0; i < msg->system_id_length; i++) {
     88         _SHR_UNPACK_U8(buf, msg->system_id[i]);
     89     }
     90 
     91     return buf;
     92 }
     93 
     94 /*
     95  * ST Ports add message - pack
     96  */
     97 uint8*
     98 shr_st_msg_ctrl_ports_add_pack(uint8 *buf, shr_st_msg_ctrl_ports_add_t *msg)
     99 {
    100     int i;
    101 
    102     _SHR_PACK_U16(buf, msg->num_ports);
    103     for (i = 0; i < msg->num_ports; i++) {
    104         _SHR_PACK_U16(buf, msg->lports[i]);
    105         _SHR_PACK_U16(buf, msg->pports[i]);
    106         _SHR_PACK_U16(buf, msg->mports[i]);
    107     }
    108 
    109     return buf;
    110 }
    111 
    112 /*
    113  * ST Ports add message - unpack
    114  */
    115 uint8*
    116 shr_st_msg_ctrl_ports_add_unpack(uint8 *buf, shr_st_msg_ctrl_ports_add_t *msg)
    117 {
    118     int i;
    119 
    120     _SHR_UNPACK_U16(buf, msg->num_ports);
    121 
    122     for (i = 0; i < msg->num_ports; i++) {
    123         _SHR_UNPACK_U16(buf, msg->lports[i]);
    124         _SHR_UNPACK_U16(buf, msg->pports[i]);
    125         _SHR_UNPACK_U16(buf, msg->mports[i]);
    126     }
    127 
    128     return buf;
    129 }
    130 
    131 
    132 /*
    133  * ST Ports get message - pack
    134  */
    135 uint8*
    136 shr_st_msg_ctrl_ports_get_pack(uint8 *buf, shr_st_msg_ctrl_ports_get_t *msg)
    137 {
    138     int i;
    139 
    140     _SHR_PACK_U16(buf, msg->num_ports);
    141     for (i = 0; i < msg->num_ports; i++) {
    142         _SHR_PACK_U16(buf, msg->lports[i]);
    143     }
    144 
    145     return buf;
    146 }
    147 
    148 /*
    149  * ST Ports get message - unpack
    150  */
    151 uint8*
    152 shr_st_msg_ctrl_ports_get_unpack(uint8 *buf, shr_st_msg_ctrl_ports_get_t *msg)
    153 {
    154     int i;
    155 
    156     _SHR_UNPACK_U16(buf, msg->num_ports);
    157 
    158     for (i = 0; i < msg->num_ports; i++) {
    159         _SHR_UNPACK_U16(buf, msg->lports[i]);
    160     }
    161 
    162     return buf;
    163 }
    164 
    165 /*
    166  * ST Ports delete message - pack
    167  */
    168 uint8*
    169 shr_st_msg_ctrl_ports_delete_pack(uint8 *buf, shr_st_msg_ctrl_ports_delete_t *msg)
    170 {
    171     int i;
    172 
    173     _SHR_PACK_U16(buf, msg->num_ports);
    174     for (i = 0; i < msg->num_ports; i++) {
    175         _SHR_PACK_U16(buf, msg->lports[i]);
    176     }
    177 
    178     return buf;
    179 }
    180 
    181 /*
    182  * ST Ports delete message - unpack
    183  */
    184 uint8*
    185 shr_st_msg_ctrl_ports_delete_unpack(uint8 *buf, shr_st_msg_ctrl_ports_delete_t *msg)
    186 {
    187     int i;
    188 
    189     _SHR_UNPACK_U16(buf, msg->num_ports);
    190 
    191     for (i = 0; i < msg->num_ports; i++) {
    192         _SHR_UNPACK_U16(buf, msg->lports[i]);
    193     }
    194 
    195     return buf;
    196 }
    197 
    198 /*
    199  * ST Instance create - pack
    200  */
    201 uint8*
    202 shr_st_msg_ctrl_instance_create_pack(uint8 *buf, shr_st_msg_ctrl_instance_create_t *msg)
    203 {
    204     int i, j;
    205 
    206     _SHR_PACK_U16(buf, msg->instance_id);
    207     _SHR_PACK_U32(buf, msg->component_id);
    208 
    209     _SHR_PACK_U16(buf, msg->num_ports);
    210     for (i = 0; i < msg->num_ports; i++) {
    211         _SHR_PACK_U16(buf, msg->lports[i]);
    212         _SHR_PACK_U32(buf, msg->stat_types[i]);
    213 
    214         _SHR_PACK_U16(buf, msg->if_name_lengths[i]);
    215         for (j = 0; j < msg->if_name_lengths[i]; j++) {
    216             _SHR_PACK_U8(buf, msg->if_names[i][j]);
    217         }
    218     }
    219 
    220     return buf;
    221 }
    222 
    223 /*
    224  * ST Instance create - unpack
    225  */
    226 uint8*
    227 shr_st_msg_ctrl_instance_create_unpack(uint8 *buf, shr_st_msg_ctrl_instance_create_t *msg)
    228 {
    229     int i, j;
    230 
    231     _SHR_UNPACK_U16(buf, msg->instance_id);
    232     _SHR_UNPACK_U32(buf, msg->component_id);
    233 
    234     _SHR_UNPACK_U16(buf, msg->num_ports);
    235     for (i = 0; i < msg->num_ports; i++) {
    236         _SHR_UNPACK_U16(buf, msg->lports[i]);
    237         _SHR_UNPACK_U32(buf, msg->stat_types[i]);
    238 
    239         _SHR_UNPACK_U16(buf, msg->if_name_lengths[i]);
    240         for (j = 0; j < msg->if_name_lengths[i]; j++) {
    241             _SHR_UNPACK_U8(buf, msg->if_names[i][j]);
    242         }
    243     }
    244 
    245     return buf;
    246 }
    247 
    248 /*
    249  * ST Instance get - pack
    250  */
    251 uint8*
    252 shr_st_msg_ctrl_instance_get_pack(uint8 *buf, shr_st_msg_ctrl_instance_get_t *msg)
    253 {
    254     int i, j;
    255 
    256     _SHR_PACK_U32(buf, msg->component_id);
    257     _SHR_PACK_U16(buf, msg->collector_id);
    258 
    259     _SHR_PACK_U16(buf, msg->num_ports);
    260     for (i = 0; i < msg->num_ports; i++) {
    261         _SHR_PACK_U16(buf, msg->lports[i]);
    262         _SHR_PACK_U32(buf, msg->stat_types[i]);
    263 
    264         _SHR_PACK_U16(buf, msg->if_name_lengths[i]);
    265         for (j = 0; j < msg->if_name_lengths[i]; j++) {
    266             _SHR_PACK_U8(buf, msg->if_names[i][j]);
    267         }
    268     }
    269 
    270     return buf;
    271 }
    272 
    273 /*
    274  * ST Instance get - unpack
    275  */
    276 uint8*
    277 shr_st_msg_ctrl_instance_get_unpack(uint8 *buf, shr_st_msg_ctrl_instance_get_t *msg)
    278 {
    279     int i, j;
    280 
    281     _SHR_UNPACK_U32(buf, msg->component_id);
    282     _SHR_UNPACK_U16(buf, msg->collector_id);
    283 
    284     _SHR_UNPACK_U16(buf, msg->num_ports);
    285     for (i = 0; i < msg->num_ports; i++) {
    286         _SHR_UNPACK_U16(buf, msg->lports[i]);
    287         _SHR_UNPACK_U32(buf, msg->stat_types[i]);
    288 
    289         _SHR_UNPACK_U16(buf, msg->if_name_lengths[i]);
    290         for (j = 0; j < msg->if_name_lengths[i]; j++) {
    291             _SHR_UNPACK_U8(buf, msg->if_names[i][j]);
    292         }
    293     }
    294 
    295     return buf;
    296 }
    297 
    298 /*
    299  * Create PB collector - pack
    300  */
    301 uint8*
    302 shr_st_msg_ctrl_collector_create_pack(uint8* buf, shr_st_msg_ctrl_collector_create_t *msg)
    303 {
    304     int i;
    305 
    306     _SHR_PACK_U16(buf, msg->id);
    307     _SHR_PACK_U32(buf, msg->flags);
    308     _SHR_PACK_U16(buf, msg->encap_length);
    309 
    310     for (i = 0; i < msg->encap_length; i++) {
    311         _SHR_PACK_U8(buf, msg->encap[i]);
    312     }
    313 
    314     _SHR_PACK_U16(buf, msg->mtu);
    315     _SHR_PACK_U32(buf, msg->ip_base_checksum);
    316     _SHR_PACK_U32(buf, msg->udp_base_checksum);
    317     _SHR_PACK_U16(buf, msg->ip_offset);
    318     _SHR_PACK_U16(buf, msg->udp_offset);
    319     _SHR_PACK_U16(buf, msg->num_port_in_pkt);
    320 
    321     return buf;
    322 }
    323 
    324 /*
    325  * Create PB collector - unpack
    326  */
    327 uint8*
    328 shr_st_msg_ctrl_collector_create_unpack(uint8* buf, shr_st_msg_ctrl_collector_create_t *msg)
    329 {
    330     int i;
    331 
    332     _SHR_UNPACK_U16(buf, msg->id);
    333     _SHR_UNPACK_U32(buf, msg->flags);
    334     _SHR_UNPACK_U16(buf, msg->encap_length);
    335 
    336     for (i = 0; i < msg->encap_length; i++) {
    337         _SHR_UNPACK_U8(buf, msg->encap[i]);
    338     }
    339 
    340     _SHR_UNPACK_U16(buf, msg->mtu);
    341     _SHR_UNPACK_U32(buf, msg->ip_base_checksum);
    342     _SHR_UNPACK_U32(buf, msg->udp_base_checksum);
    343     _SHR_UNPACK_U16(buf, msg->ip_offset);
    344     _SHR_UNPACK_U16(buf, msg->udp_offset);
    345     _SHR_UNPACK_U16(buf, msg->num_port_in_pkt);
    346 
    347     return buf;
    348 }
    349 
    350 /*
    351  * Instance collector attach - pack
    352  */
    353 uint8*
    354 shr_st_msg_ctrl_instance_collector_attach_pack(uint8* buf,
    355                                                shr_st_msg_ctrl_instance_collector_attach_t *msg)
    356 {
    357     _SHR_PACK_U16(buf, msg->instance_id);
    358     _SHR_PACK_U16(buf, msg->collector_id);
    359     _SHR_PACK_U32(buf, msg->export_interval_usecs);
    360 
    361     return buf;
    362 }
    363 
    364 /*
    365  * Instance collector attach - unpack
    366  */
    367 uint8*
    368 shr_st_msg_ctrl_instance_collector_attach_unpack(uint8* buf,
    369                                                  shr_st_msg_ctrl_instance_collector_attach_t *msg)
    370 {
    371     _SHR_UNPACK_U16(buf, msg->instance_id);
    372     _SHR_UNPACK_U16(buf, msg->collector_id);
    373     _SHR_UNPACK_U32(buf, msg->export_interval_usecs);
    374 
    375     return buf;
    376 }
    377 
    378 /*
    379  * Instance export statistics - pack
    380  */
    381 uint8*
    382 shr_st_msg_instance_export_stats_pack(uint8 *buf,
    383                                       shr_st_msg_instance_export_stats_t *msg)
    384 {
    385     _SHR_PACK_U16(buf, msg->instance_id);
    386     _SHR_PACK_U16(buf, msg->collector_id);
    387 
    388     _SHR_PACK_U32(buf, msg->tx_pkts_hi);
    389     _SHR_PACK_U32(buf, msg->tx_pkts_lo);
    390 
    391     _SHR_PACK_U32(buf, msg->tx_pkt_fails_hi);
    392     _SHR_PACK_U32(buf, msg->tx_pkt_fails_lo);
    393 
    394     return buf;
    395 }
    396 
    397 /*
    398  * Instance export statistics - unpack
    399  */
    400 uint8*
    401 shr_st_msg_instance_export_stats_unpack(uint8 *buf,
    402                                         shr_st_msg_instance_export_stats_t *msg)
    403 {
    404     _SHR_UNPACK_U16(buf, msg->instance_id);
    405     _SHR_UNPACK_U16(buf, msg->collector_id);
    406 
    407     _SHR_UNPACK_U32(buf, msg->tx_pkts_hi);
    408     _SHR_UNPACK_U32(buf, msg->tx_pkts_lo);
    409 
    410     _SHR_UNPACK_U32(buf, msg->tx_pkt_fails_hi);
    411     _SHR_UNPACK_U32(buf, msg->tx_pkt_fails_lo);
    412 
    413     return buf;
    414 }