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

mpls_lm_dm_pack.c (12196B)


      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:        mpls_lm_dm_pack.c
      8  * Purpose:     MPLS_LM_DM pack and unpack routines for:
      9  *              - MPLS_LM_DM Control messages
     10  *              - Network Packet headers (PDUs)
     11  *
     12  *
     13  * MPLS_LM_DM control messages
     14  *
     15  * MPLS_LM_DM messages between the Host CPU and uController are sent
     16  * using the uc_message module which allows short messages
     17  * to be passed (see include/soc/shared/mos_msg_common.h)
     18  *
     19  * Additional information for a given message (a long message) is passed
     20  * using DMA.  The MPLS_LM_DM control message types defines the format
     21  * for these long messages.
     22  *
     23  * This file is shared between SDK and uKernel.
     24  */
     25 
     26 #include <shared/pack.h>
     27 #include <soc/shared/mpls_lm_dm_msg.h>
     28 #include <soc/shared/mpls_lm_dm_pkt.h>
     29 #include <soc/shared/mpls_lm_dm_pack.h>
     30 
     31 
     32 /***********************************************************
     33  * MPLS_LM_DM Control Message Pack/Unpack
     34  *
     35  * Functions:
     36  *      shr_mpls_lm_dm_msg_ctrl_<type>_pack/unpack
     37  * Purpose:
     38  *      The following set of routines pack/unpack specified
     39  *      MPLS_LM_DM control message into/from a given buffer
     40  * Parameters:
     41  *   _pack()
     42  *      buffer  - (OUT) Buffer where to pack message.
     43  *      msg     - (IN)  MPLS_LM_DM control message to pack.
     44  *   _unpack()
     45  *      buffer  - (IN)  Buffer with message to unpack.
     46  *      msg     - (OUT) Returns MPLS_LM_DM control message.
     47  * Returns:
     48  *      Pointer to next position in buffer.
     49  * Notes:
     50  *      Assumes pointers are valid and contain enough memory space.
     51  */
     52 uint8 *
     53 shr_mpls_lm_dm_msg_ctrl_init_pack(uint8 *buf, shr_mpls_lm_dm_msg_ctrl_init_t *msg)
     54 {
     55     _SHR_PACK_U32(buf, msg->num_sessions);
     56     _SHR_PACK_U32(buf, msg->rx_channel);
     57     return buf;
     58 }
     59 
     60 uint8 *
     61 shr_mpls_lm_dm_msg_ctrl_init_unpack(uint8 *buf, shr_mpls_lm_dm_msg_ctrl_init_t *msg)
     62 {
     63     _SHR_UNPACK_U32(buf, msg->num_sessions);
     64     _SHR_UNPACK_U32(buf, msg->rx_channel);
     65     return buf;
     66 }
     67 
     68 uint8 *
     69 shr_mpls_lm_dm_msg_ctrl_loss_add_pack(uint8 *buf,
     70                                  shr_mpls_lm_dm_msg_ctrl_loss_add_t *msg)
     71 {
     72     int i;
     73     
     74     _SHR_PACK_U32(buf, msg->flags);
     75     _SHR_PACK_U32(buf, msg->sess_id);
     76     _SHR_PACK_U32(buf, msg->period);
     77     _SHR_PACK_U32(buf, msg->int_pri);
     78     _SHR_PACK_U8 (buf, msg->pkt_pri);
     79 
     80     _SHR_PACK_U16(buf, msg->l2_encap_length);
     81     for (i=0; i<msg->l2_encap_length; i++) {
     82         _SHR_PACK_U8 (buf, msg->l2_encap_data[i]);
     83     }
     84     for (i=0; i<MPLS_LM_DM_OLP_HDR_LEN; i++) {
     85         _SHR_PACK_U8 (buf, msg->olp_encap_data[i]);
     86     }
     87 
     88     _SHR_PACK_U8 (buf, msg->ctr_size);
     89     for (i=0; i<msg->ctr_size; i++) {
     90         _SHR_PACK_U32(buf, msg->ctr_base_id[i]);
     91         _SHR_PACK_U8 (buf, msg->ctr_offset[i]);
     92         _SHR_PACK_U8 (buf, msg->ctr_action[i]);
     93     }
     94     if (msg->flags & SHR_MPLS_LM_DM_BYTE_COUNT_FLAG) {
     95         for (i=0; i<msg->ctr_size; i++) {
     96             _SHR_PACK_U8 (buf, msg->ctr_byte_offset[i]);
     97         }
     98     }
     99     return buf;
    100 }
    101 
    102 uint8 *
    103 shr_mpls_lm_dm_msg_ctrl_loss_add_unpack(uint8 *buf,
    104                                  shr_mpls_lm_dm_msg_ctrl_loss_add_t *msg)
    105 {
    106     int i;
    107     
    108     _SHR_UNPACK_U32(buf, msg->flags);
    109     _SHR_UNPACK_U32(buf, msg->sess_id);
    110     _SHR_UNPACK_U32(buf, msg->period);
    111     _SHR_UNPACK_U32(buf, msg->int_pri);
    112     _SHR_UNPACK_U8 (buf, msg->pkt_pri);
    113 
    114     _SHR_UNPACK_U16(buf, msg->l2_encap_length);
    115     for (i=0; i<msg->l2_encap_length; i++) {
    116         _SHR_UNPACK_U8 (buf, msg->l2_encap_data[i]);
    117     }
    118     for (i=0; i<(MPLS_LM_DM_OLP_HDR_LEN); i++) {
    119         _SHR_UNPACK_U8 (buf, msg->olp_encap_data[i]);
    120     }
    121 
    122     _SHR_UNPACK_U8 (buf, msg->ctr_size);
    123     for (i=0; i<msg->ctr_size; i++) {
    124         _SHR_UNPACK_U32(buf, msg->ctr_base_id[i]);
    125         _SHR_UNPACK_U8 (buf, msg->ctr_offset[i]);
    126         _SHR_UNPACK_U8 (buf, msg->ctr_action[i]);
    127     }
    128     if (msg->flags & SHR_MPLS_LM_DM_BYTE_COUNT_FLAG) {
    129         for (i=0; i<msg->ctr_size; i++) {
    130             _SHR_UNPACK_U8 (buf, msg->ctr_byte_offset[i]);
    131         }
    132     }
    133     return buf;
    134 }
    135 
    136 uint8 *
    137 shr_mpls_lm_dm_msg_ctrl_loss_delete_pack(uint8 *buf,
    138                                  shr_mpls_lm_dm_msg_ctrl_loss_delete_t *msg)
    139 {
    140     _SHR_PACK_U32(buf, msg->sess_id);
    141 
    142     return buf;
    143 }
    144 
    145 uint8 *
    146 shr_mpls_lm_dm_msg_ctrl_loss_delete_unpack(uint8 *buf,
    147                                  shr_mpls_lm_dm_msg_ctrl_loss_delete_t *msg)
    148 {
    149     _SHR_UNPACK_U32(buf, msg->sess_id);
    150 
    151     return buf;
    152 }
    153 
    154 uint8 *
    155 shr_mpls_lm_dm_msg_ctrl_loss_get_pack(uint8 *buf,
    156                                  shr_mpls_lm_dm_msg_ctrl_loss_get_t *msg)
    157 {
    158     _SHR_PACK_U32(buf, msg->flags);
    159     _SHR_PACK_U32(buf, msg->sess_id);
    160     return buf;
    161 }
    162 
    163 uint8 *
    164 shr_mpls_lm_dm_msg_ctrl_loss_get_unpack(uint8 *buf,
    165                                  shr_mpls_lm_dm_msg_ctrl_loss_get_t *msg)
    166 {
    167     _SHR_UNPACK_U32(buf, msg->flags);
    168     _SHR_UNPACK_U32(buf, msg->sess_id);
    169     return buf;
    170 }
    171 
    172 uint8 *
    173 shr_mpls_lm_dm_msg_ctrl_loss_data_pack(uint8 *buf,
    174                                  shr_mpls_lm_dm_msg_ctrl_loss_data_t *msg)
    175 {
    176     int i;
    177 
    178     _SHR_PACK_U32(buf, msg->flags);
    179     _SHR_PACK_U32(buf, msg->sess_id);
    180     _SHR_PACK_U32(buf, msg->period);
    181     _SHR_PACK_U32(buf, msg->loss_threshold);
    182     _SHR_PACK_U32(buf, msg->loss_nearend);
    183     _SHR_PACK_U32(buf, msg->loss_farend);
    184     _SHR_PACK_U32(buf, msg->tx_nearend);
    185     _SHR_PACK_U32(buf, msg->rx_nearend);
    186     _SHR_PACK_U32(buf, msg->tx_farend);
    187     _SHR_PACK_U32(buf, msg->rx_farend);
    188     _SHR_PACK_U32(buf, msg->rx_oam_packets);
    189     _SHR_PACK_U32(buf, msg->tx_oam_packets);
    190     _SHR_PACK_U32(buf, msg->int_pri);
    191     _SHR_PACK_U8 (buf, msg->pkt_pri);
    192 
    193     _SHR_PACK_U8 (buf, msg->ctr_size);
    194     for (i=0; i<msg->ctr_size; i++) {
    195         _SHR_PACK_U32(buf, msg->ctr_base_id[i]);
    196         _SHR_PACK_U8 (buf, msg->ctr_offset[i]);
    197         _SHR_PACK_U8 (buf, msg->ctr_action[i]);
    198     }
    199     if (msg->flags & SHR_MPLS_LM_DM_BYTE_COUNT_FLAG) {
    200         for (i=0; i<msg->ctr_size; i++) {
    201             _SHR_PACK_U8 (buf, msg->ctr_byte_offset[i]);
    202         }
    203 
    204         if (msg->flags & SHR_MPLS_LM_DM_64_BIT_FLAG) {
    205             _SHR_PACK_U32(buf, msg->loss_nearend_upper);
    206             _SHR_PACK_U32(buf, msg->loss_farend_upper);
    207             _SHR_PACK_U32(buf, msg->tx_nearend_upper);
    208             _SHR_PACK_U32(buf, msg->rx_nearend_upper);
    209             _SHR_PACK_U32(buf, msg->tx_farend_upper);
    210             _SHR_PACK_U32(buf, msg->rx_farend_upper);
    211         }
    212     }
    213 
    214     return buf;
    215 }
    216 
    217 uint8 *
    218 shr_mpls_lm_dm_msg_ctrl_loss_data_unpack(uint8 *buf,
    219                                  shr_mpls_lm_dm_msg_ctrl_loss_data_t *msg)
    220 {
    221     int i;
    222 
    223     _SHR_UNPACK_U32(buf, msg->flags);
    224     _SHR_UNPACK_U32(buf, msg->sess_id);
    225     _SHR_UNPACK_U32(buf, msg->period);
    226     _SHR_UNPACK_U32(buf, msg->loss_threshold);
    227     _SHR_UNPACK_U32(buf, msg->loss_nearend);
    228     _SHR_UNPACK_U32(buf, msg->loss_farend);
    229     _SHR_UNPACK_U32(buf, msg->tx_nearend);
    230     _SHR_UNPACK_U32(buf, msg->rx_nearend);
    231     _SHR_UNPACK_U32(buf, msg->tx_farend);
    232     _SHR_UNPACK_U32(buf, msg->rx_farend);
    233     _SHR_UNPACK_U32(buf, msg->rx_oam_packets);
    234     _SHR_UNPACK_U32(buf, msg->tx_oam_packets);
    235     _SHR_UNPACK_U32(buf, msg->int_pri);
    236     _SHR_UNPACK_U8 (buf, msg->pkt_pri);
    237 
    238     _SHR_UNPACK_U8 (buf, msg->ctr_size);
    239     for (i=0; i<msg->ctr_size; i++) {
    240         _SHR_UNPACK_U32(buf, msg->ctr_base_id[i]);
    241         _SHR_UNPACK_U8 (buf, msg->ctr_offset[i]);
    242         _SHR_UNPACK_U8 (buf, msg->ctr_action[i]);
    243     }
    244     if (msg->flags & SHR_MPLS_LM_DM_BYTE_COUNT_FLAG) {
    245         for (i=0; i<msg->ctr_size; i++) {
    246             _SHR_UNPACK_U8 (buf, msg->ctr_byte_offset[i]);
    247         }
    248 
    249         if (msg->flags & SHR_MPLS_LM_DM_64_BIT_FLAG) {
    250             _SHR_UNPACK_U32(buf, msg->loss_nearend_upper);
    251             _SHR_UNPACK_U32(buf, msg->loss_farend_upper);
    252             _SHR_UNPACK_U32(buf, msg->tx_nearend_upper);
    253             _SHR_UNPACK_U32(buf, msg->rx_nearend_upper);
    254             _SHR_UNPACK_U32(buf, msg->tx_farend_upper);
    255             _SHR_UNPACK_U32(buf, msg->rx_farend_upper);
    256         }
    257     }
    258 
    259     return buf;
    260 }
    261 
    262 uint8 *
    263 shr_mpls_lm_dm_msg_ctrl_delay_add_pack(uint8 *buf,
    264                                  shr_mpls_lm_dm_msg_ctrl_delay_add_t *msg)
    265 {
    266     int i;
    267 
    268     _SHR_PACK_U32(buf, msg->flags);
    269     _SHR_PACK_U32(buf, msg->sess_id);
    270     _SHR_PACK_U32(buf, msg->period);
    271     _SHR_PACK_U32(buf, msg->int_pri);
    272     _SHR_PACK_U8 (buf, msg->pkt_pri);
    273     _SHR_PACK_U8 (buf, msg->dm_format);
    274 
    275     _SHR_PACK_U16(buf, msg->l2_encap_length);
    276     for (i=0; i<msg->l2_encap_length; i++) {
    277         _SHR_PACK_U8 (buf, msg->l2_encap_data[i]);
    278     }
    279     for (i=0; i<MPLS_LM_DM_OLP_HDR_LEN; i++) {
    280         _SHR_PACK_U8 (buf, msg->olp_encap_data[i]);
    281     }
    282     return buf;
    283 }
    284 
    285 uint8 *
    286 shr_mpls_lm_dm_msg_ctrl_delay_add_unpack(uint8 *buf,
    287                                  shr_mpls_lm_dm_msg_ctrl_delay_add_t *msg)
    288 {
    289     int i;
    290     _SHR_UNPACK_U32(buf, msg->flags);
    291     _SHR_UNPACK_U32(buf, msg->sess_id);
    292     _SHR_UNPACK_U32(buf, msg->period);
    293     _SHR_UNPACK_U32(buf, msg->int_pri);
    294     _SHR_UNPACK_U8 (buf, msg->pkt_pri);
    295     _SHR_UNPACK_U8 (buf, msg->dm_format);
    296 
    297     _SHR_UNPACK_U16(buf, msg->l2_encap_length);
    298     for (i=0; i<msg->l2_encap_length; i++) {
    299         _SHR_UNPACK_U8 (buf, msg->l2_encap_data[i]);
    300     }
    301     for (i=0; i<(MPLS_LM_DM_OLP_HDR_LEN); i++) {
    302         _SHR_UNPACK_U8 (buf, msg->olp_encap_data[i]);
    303     }
    304     return buf;
    305 }
    306 
    307 uint8 *
    308 shr_mpls_lm_dm_msg_ctrl_delay_delete_pack(uint8 *buf,
    309                                  shr_mpls_lm_dm_msg_ctrl_delay_delete_t *msg)
    310 {
    311     _SHR_PACK_U32(buf, msg->sess_id);
    312 
    313     return buf;
    314 }
    315 
    316 uint8 *
    317 shr_mpls_lm_dm_msg_ctrl_delay_delete_unpack(uint8 *buf,
    318                                  shr_mpls_lm_dm_msg_ctrl_delay_delete_t *msg)
    319 {
    320     _SHR_UNPACK_U32(buf, msg->sess_id);
    321 
    322     return buf;
    323 }
    324 
    325 uint8 *
    326 shr_mpls_lm_dm_msg_ctrl_delay_get_pack(uint8 *buf,
    327                                  shr_mpls_lm_dm_msg_ctrl_delay_get_t *msg)
    328 {
    329 
    330     _SHR_PACK_U32(buf, msg->flags);
    331     _SHR_PACK_U32(buf, msg->sess_id);
    332     return buf;
    333 }
    334 
    335 uint8 *
    336 shr_mpls_lm_dm_msg_ctrl_delay_get_unpack(uint8 *buf,
    337                                  shr_mpls_lm_dm_msg_ctrl_delay_get_t *msg)
    338 {
    339 
    340     _SHR_UNPACK_U32(buf, msg->flags);
    341     _SHR_UNPACK_U32(buf, msg->sess_id);
    342     return buf;
    343 }
    344 
    345 uint8 *
    346 shr_mpls_lm_dm_msg_ctrl_delay_data_pack(uint8 *buf,
    347                                  shr_mpls_lm_dm_msg_ctrl_delay_data_t *msg)
    348 {
    349 
    350     _SHR_PACK_U32(buf, msg->flags);
    351     _SHR_PACK_U32(buf, msg->sess_id);
    352     _SHR_PACK_U32(buf, msg->period);
    353     _SHR_PACK_U32(buf, msg->delay_seconds);
    354     _SHR_PACK_U32(buf, msg->delay_nanoseconds);
    355     _SHR_PACK_U32(buf, msg->txf_seconds);
    356     _SHR_PACK_U32(buf, msg->txf_nanoseconds);
    357     _SHR_PACK_U32(buf, msg->rxf_seconds);
    358     _SHR_PACK_U32(buf, msg->rxf_nanoseconds);
    359     _SHR_PACK_U32(buf, msg->txb_seconds);
    360     _SHR_PACK_U32(buf, msg->txb_nanoseconds);
    361     _SHR_PACK_U32(buf, msg->rxb_seconds);
    362     _SHR_PACK_U32(buf, msg->rxb_nanoseconds);
    363     _SHR_PACK_U32(buf, msg->rx_oam_packets);
    364     _SHR_PACK_U32(buf, msg->tx_oam_packets);
    365     _SHR_PACK_U32(buf, msg->int_pri);
    366     _SHR_PACK_U8 (buf, msg->pkt_pri);
    367     _SHR_PACK_U8 (buf, msg->dm_format);
    368 
    369     return buf;
    370 }
    371 
    372 uint8 *
    373 shr_mpls_lm_dm_msg_ctrl_delay_data_unpack(uint8 *buf,
    374                                  shr_mpls_lm_dm_msg_ctrl_delay_data_t *msg)
    375 {
    376 
    377     _SHR_UNPACK_U32(buf, msg->flags);
    378     _SHR_UNPACK_U32(buf, msg->sess_id);
    379     _SHR_UNPACK_U32(buf, msg->period);
    380     _SHR_UNPACK_U32(buf, msg->delay_seconds);
    381     _SHR_UNPACK_U32(buf, msg->delay_nanoseconds);
    382     _SHR_UNPACK_U32(buf, msg->txf_seconds);
    383     _SHR_UNPACK_U32(buf, msg->txf_nanoseconds);
    384     _SHR_UNPACK_U32(buf, msg->rxf_seconds);
    385     _SHR_UNPACK_U32(buf, msg->rxf_nanoseconds);
    386     _SHR_UNPACK_U32(buf, msg->txb_seconds);
    387     _SHR_UNPACK_U32(buf, msg->txb_nanoseconds);
    388     _SHR_UNPACK_U32(buf, msg->rxb_seconds);
    389     _SHR_UNPACK_U32(buf, msg->rxb_nanoseconds);
    390     _SHR_UNPACK_U32(buf, msg->rx_oam_packets);
    391     _SHR_UNPACK_U32(buf, msg->tx_oam_packets);
    392     _SHR_UNPACK_U32(buf, msg->int_pri);
    393     _SHR_UNPACK_U8 (buf, msg->pkt_pri);
    394     _SHR_UNPACK_U8 (buf, msg->dm_format);
    395 
    396     return buf;
    397 }