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

bhh_sdk_pack.c (13225B)


      1 /* 
      2  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      3  * 
      4  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      5  * File:        bhh_sdk_pack.c
      6  * Purpose:     BHH pack and unpack routines for:
      7  *              - BHH Control messages
      8  */
      9 #if defined(INCLUDE_BHH)
     10 
     11 #include <bcm_int/esw/bhh_sdk_pack.h>
     12 #include <shared/pack.h>
     13 #include <soc/feature.h>
     14 #include <soc/drv.h>
     15 
     16 uint8 *
     17 bhh_sdk_version_exchange_msg_unpack(uint8 *buf, bhh_sdk_version_exchange_msg_t *msg)
     18 {
     19     _SHR_UNPACK_U32(buf, msg->version);
     20     return buf;
     21 }
     22 
     23 uint8 *
     24 bhh_sdk_version_exchange_msg_pack(uint8 *buf, bhh_sdk_version_exchange_msg_t *msg)
     25 {
     26     _SHR_PACK_U32(buf, msg->version);
     27     return buf;
     28 }
     29 
     30 uint8 *
     31 bhh_sdk_msg_ctrl_sess_get_unpack(uint8 *buf,
     32                                  bhh_sdk_msg_ctrl_sess_get_t *msg)
     33 { 
     34     int i;
     35 
     36     _SHR_UNPACK_U32(buf, msg->sess_id);
     37     _SHR_UNPACK_U8(buf, msg->enable);
     38     _SHR_UNPACK_U8(buf, msg->passive);
     39     _SHR_UNPACK_U8(buf, msg->local_demand);
     40     _SHR_UNPACK_U8(buf, msg->remote_demand);
     41     _SHR_UNPACK_U8(buf, msg->local_sess_state);
     42     _SHR_UNPACK_U8(buf, msg->remote_sess_state);
     43     _SHR_UNPACK_U8(buf, msg->mel);
     44     _SHR_UNPACK_U16(buf, msg->mep_id);
     45     for (i = 0; i < SHR_BHH_MEG_ID_LENGTH; i++) {
     46         _SHR_UNPACK_U8(buf, msg->meg_id[i]);
     47     }
     48     _SHR_UNPACK_U32(buf, msg->local_period);
     49     _SHR_UNPACK_U8(buf, msg->encap_type);
     50     _SHR_UNPACK_U32(buf, msg->encap_length);
     51 
     52     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP)) {
     53         for (i = 0; i < msg->encap_length; i++) {
     54             _SHR_UNPACK_U8(buf, msg->encap_data[i]);
     55         }
     56     } else {
     57         for (i = 0; i < SHR_BHH_MAX_ENCAP_LENGTH; i++) {
     58             _SHR_UNPACK_U8(buf, msg->encap_data[i]);
     59         }
     60     }
     61 
     62     _SHR_UNPACK_U32(buf, msg->tx_port);
     63     _SHR_UNPACK_U32(buf, msg->tx_cos);
     64     _SHR_UNPACK_U32(buf, msg->tx_pri);
     65     _SHR_UNPACK_U32(buf, msg->tx_qnum);
     66     if(BHH_UC_FEATURE_CHECK(BHH_WB_SESS_GET)) {
     67         _SHR_UNPACK_U32(buf, msg->mpls_label);
     68         _SHR_UNPACK_U32(buf, msg->if_num);
     69         _SHR_UNPACK_U32(buf, msg->flags);
     70     }
     71     if(BHH_UC_FEATURE_CHECK(BHH_REMOTE_EP_NAME)) {
     72         _SHR_UNPACK_U16(buf, msg->remote_mep_id);
     73     }
     74     if(BHH_UC_FEATURE_CHECK(BHH_FAULTS_GET)) {
     75        _SHR_UNPACK_U32(buf, msg->fault_flags);
     76     }
     77 
     78     if(BHH_UC_FEATURE_CHECK(BHH_PASSIVE_MEP)) {
     79        _SHR_UNPACK_U32(buf, msg->remote_period);
     80     }
     81     if (BHH_UC_FEATURE_CHECK(BHH_PRIORITY_EVENT)) {
     82         _SHR_UNPACK_U8(buf, msg->priority);
     83     }
     84 
     85     return buf;
     86 }
     87 
     88 uint8 *
     89 bhh_sdk_msg_ctrl_loss_get_unpack(uint8 *buf,
     90                                  bhh_sdk_msg_ctrl_loss_get_t *msg)
     91 {
     92     int i;
     93 
     94     _SHR_UNPACK_U32(buf, msg->flags);
     95     _SHR_UNPACK_U32(buf, msg->sess_id);
     96     _SHR_UNPACK_U32(buf, msg->period);
     97     _SHR_UNPACK_U32(buf, msg->loss_threshold);
     98     _SHR_UNPACK_U32(buf, msg->loss_nearend);
     99     _SHR_UNPACK_U32(buf, msg->tx_nearend);
    100     _SHR_UNPACK_U32(buf, msg->rx_nearend);
    101     _SHR_UNPACK_U32(buf, msg->tx_farend);
    102     _SHR_UNPACK_U32(buf, msg->rx_farend);
    103     _SHR_UNPACK_U32(buf, msg->rx_oam_packets);
    104     _SHR_UNPACK_U32(buf, msg->tx_oam_packets);
    105     _SHR_UNPACK_U32(buf, msg->int_pri);
    106     _SHR_UNPACK_U8 (buf, msg->pkt_pri);
    107 
    108     if(BHH_UC_FEATURE_CHECK(BHH_LOSS_GET)) {
    109         _SHR_UNPACK_U32(buf, msg->loss_farend);
    110     }
    111 
    112     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP)) {
    113         _SHR_UNPACK_U16(buf, msg->encap_length);
    114         for (i = 0; i < msg->encap_length; i++) {
    115             _SHR_UNPACK_U8(buf, msg->encap_data[i]);
    116         }
    117     }
    118 
    119     return buf;
    120 }
    121 
    122 uint8 *
    123 bhh_sdk_msg_ctrl_init_pack(uint8 unit, uint8 *buf, bhh_sdk_msg_ctrl_init_t *msg)
    124 {
    125     int i;
    126 
    127     _SHR_PACK_U32(buf, msg->num_sessions);
    128     _SHR_PACK_U32(buf, msg->rx_channel);
    129     _SHR_PACK_U32(buf, msg->node_id);
    130 
    131     for (i = 0;i < SHR_BHH_CARRIER_CODE_LEN;i++) {
    132         _SHR_PACK_U8(buf, msg->carrier_code[i]);
    133     }
    134 
    135     if (soc_feature(unit, soc_feature_oam_pm))  {
    136         if ((SOC_IS_SABER2(unit)) || (SOC_IS_APACHE(unit))) {
    137             if(BHH_UC_FEATURE_CHECK(BHH_PM_MODE)) {
    138                 _SHR_PACK_U32(buf, msg->data_collection_mode);
    139             }
    140         }
    141     }
    142 
    143     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP)) {
    144         _SHR_PACK_U16(buf, msg->max_encap_length);
    145     }
    146 
    147     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP_VALID)) {
    148         _SHR_PACK_U32(buf, msg->flags);
    149     }
    150 
    151     if(BHH_UC_FEATURE_CHECK(BHH_KT2_PM_SUPPORT)) {
    152         _SHR_PACK_U32(buf, msg->data_collection_mode);
    153     }
    154     
    155     return buf;
    156 }
    157 
    158 uint8 *
    159 bhh_sdk_msg_ctrl_rmep_create_pack(uint8 *buf, bhh_sdk_msg_ctrl_rmep_create_t *msg)
    160 {
    161     _SHR_PACK_U32(buf, msg->sess_id);
    162     _SHR_PACK_U32(buf, msg->flags);
    163     _SHR_PACK_U16(buf, msg->remote_mep_id);
    164     _SHR_PACK_U8(buf, msg->enable);
    165 
    166     if(BHH_UC_FEATURE_CHECK(BHH_PASSIVE_MEP)) {
    167         _SHR_PACK_U32(buf, msg->period);
    168     }
    169 
    170     return buf;
    171 }
    172 
    173 uint8 *
    174 bhh_sdk_msg_ctrl_loss_add_pack(uint8 *buf, bhh_sdk_msg_ctrl_loss_add_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->int_pri);
    182     _SHR_PACK_U8 (buf, msg->pkt_pri);
    183 
    184     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP)) {
    185         _SHR_PACK_U16(buf, msg->encap_length);
    186         for (i = 0; i < msg->encap_length; i++) {
    187             _SHR_PACK_U8(buf, msg->encap_data[i]);
    188         }
    189     }
    190 
    191     return buf;
    192 }
    193 
    194 uint8 *
    195 bhh_sdk_msg_ctrl_delay_add_pack(uint8 *buf, bhh_sdk_msg_ctrl_delay_add_t *msg)
    196 {
    197     int i;
    198 
    199     _SHR_PACK_U32(buf, msg->flags);
    200     _SHR_PACK_U32(buf, msg->sess_id);
    201     _SHR_PACK_U32(buf, msg->period);
    202     _SHR_PACK_U32(buf, msg->int_pri);
    203     _SHR_PACK_U8 (buf, msg->pkt_pri);
    204     _SHR_PACK_U8 (buf, msg->dm_format);
    205 
    206     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP)) {
    207         _SHR_PACK_U16(buf, msg->encap_length);
    208         for (i = 0; i < msg->encap_length; i++) {
    209             _SHR_PACK_U8(buf, msg->encap_data[i]);
    210         }
    211     }
    212     if (BHH_UC_FEATURE_CHECK(BHH_DM_DATA_TLV)) {
    213         _SHR_PACK_U16(buf, msg->data_tlv_len);
    214     }
    215     return buf;
    216 }
    217 
    218 uint8 *
    219 bhh_sdk_msg_ctrl_loopback_add_pack(uint8 *buf,
    220                                    bhh_sdk_msg_ctrl_loopback_add_t *msg)
    221 {
    222     int i;
    223 
    224     _SHR_PACK_U32(buf, msg->flags);
    225     _SHR_PACK_U32(buf, msg->sess_id);
    226     _SHR_PACK_U32(buf, msg->period);
    227     _SHR_PACK_U32(buf, msg->ttl);
    228 
    229     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP)) {
    230         _SHR_PACK_U16(buf, msg->encap_length);
    231         for (i = 0; i < msg->encap_length; i++) {
    232             _SHR_PACK_U8(buf, msg->encap_data[i]);
    233         }
    234     }
    235 
    236     if (BHH_UC_FEATURE_CHECK(BHH_PRIORITY_EVENT)) {
    237         _SHR_PACK_U32(buf, msg->int_pri);
    238         _SHR_PACK_U8 (buf, msg->pkt_pri);
    239     }
    240 
    241     return buf;
    242 }
    243 
    244 uint8 *
    245 bhh_sdk_msg_ctrl_sess_set_pack(uint8 *buf,
    246                                bhh_sdk_msg_ctrl_sess_set_t *msg)
    247 {
    248     uint16 i;
    249 
    250     _SHR_PACK_U32(buf, msg->sess_id);
    251     _SHR_PACK_U32(buf, msg->flags);
    252     _SHR_PACK_U8(buf, msg->passive);
    253     _SHR_PACK_U8(buf, msg->mel);
    254     _SHR_PACK_U16(buf, msg->mep_id);
    255     for (i = 0; i < SHR_BHH_MEG_ID_LENGTH; i++) {
    256         _SHR_PACK_U8(buf, msg->meg_id[i]);
    257     }
    258     _SHR_PACK_U32(buf, msg->period);
    259     _SHR_PACK_U8(buf, msg->encap_type);
    260     _SHR_PACK_U32(buf, msg->encap_length);
    261 
    262     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP)) {
    263         for (i = 0; i < msg->encap_length; i++) {
    264             _SHR_PACK_U8(buf, msg->encap_data[i]);
    265         }
    266     } else {
    267         for (i = 0; i < SHR_BHH_MAX_ENCAP_LENGTH; i++) {
    268             _SHR_PACK_U8(buf, msg->encap_data[i]);
    269         }
    270     }
    271 
    272     _SHR_PACK_U32(buf, msg->tx_port);
    273     _SHR_PACK_U32(buf, msg->tx_cos);
    274     _SHR_PACK_U32(buf, msg->tx_pri);
    275     _SHR_PACK_U32(buf, msg->tx_qnum);
    276     _SHR_PACK_U32(buf, msg->mpls_label);
    277     _SHR_PACK_U32(buf, msg->if_num);
    278     _SHR_PACK_U32(buf, msg->lm_counter_index);
    279 
    280     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP)) {
    281         _SHR_PACK_U16(buf, msg->inner_vlan);
    282         _SHR_PACK_U16(buf, msg->outer_vlan);
    283         _SHR_PACK_U8(buf, msg->endpoint_type);
    284         _SHR_PACK_U8(buf, msg->num_session_entries);
    285     }
    286     if (BHH_UC_FEATURE_CHECK(BHH_PRIORITY_EVENT)) {
    287         _SHR_PACK_U8(buf, msg->priority);
    288     }
    289 
    290     if (BHH_UC_FEATURE_CHECK(BHH_TRUNK_SUPPORT)) {
    291         _SHR_PACK_U16(buf, msg->rx_port);
    292         _SHR_PACK_U8(buf, msg->trunk_valid);
    293     }
    294 
    295     return buf;
    296 }
    297 
    298 uint8 *
    299 bhh_sdk_msg_ctrl_session_update_pack(uint8 *buf, bhh_sdk_msg_session_update_t *msg)
    300 {
    301     int i;
    302 
    303     _SHR_PACK_U32(buf, msg->flags);
    304     _SHR_PACK_U32(buf, msg->sess_id);
    305     _SHR_PACK_U8(buf, msg->msg_type);
    306     _SHR_PACK_U8(buf, msg->rdi);
    307 
    308     _SHR_PACK_U16(buf, msg->encap_length);
    309     for (i = 0; i < msg->encap_length; i++) {
    310         _SHR_PACK_U8(buf, msg->encap_data[i]);
    311     }
    312 
    313     return buf;
    314 }
    315 
    316 uint8 *
    317 bhh_sdk_msg_ctrl_delay_get_unpack(uint8 *buf, bhh_sdk_msg_ctrl_delay_get_t *msg)
    318 {
    319     int i;
    320 
    321     _SHR_UNPACK_U32(buf, msg->flags);
    322     _SHR_UNPACK_U32(buf, msg->sess_id);
    323     _SHR_UNPACK_U32(buf, msg->period);
    324     _SHR_UNPACK_U32(buf, msg->delay_seconds);
    325     _SHR_UNPACK_U32(buf, msg->delay_nanoseconds);
    326     _SHR_UNPACK_U32(buf, msg->txf_seconds);
    327     _SHR_UNPACK_U32(buf, msg->txf_nanoseconds);
    328     _SHR_UNPACK_U32(buf, msg->rxf_seconds);
    329     _SHR_UNPACK_U32(buf, msg->rxf_nanoseconds);
    330     _SHR_UNPACK_U32(buf, msg->txb_seconds);
    331     _SHR_UNPACK_U32(buf, msg->txb_nanoseconds);
    332     _SHR_UNPACK_U32(buf, msg->rxb_seconds);
    333     _SHR_UNPACK_U32(buf, msg->rxb_nanoseconds);
    334     _SHR_UNPACK_U32(buf, msg->rx_oam_packets);
    335     _SHR_UNPACK_U32(buf, msg->tx_oam_packets);
    336     _SHR_UNPACK_U32(buf, msg->int_pri);
    337     _SHR_UNPACK_U8 (buf, msg->pkt_pri);
    338     _SHR_UNPACK_U8 (buf, msg->dm_format);
    339 
    340     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP)) {
    341         _SHR_UNPACK_U16(buf, msg->encap_length);
    342         for (i = 0; i < msg->encap_length; i++) {
    343             _SHR_UNPACK_U8(buf, msg->encap_data[i]);
    344         }
    345     }
    346 
    347     if(BHH_UC_FEATURE_CHECK(BHH_DM_DATA_TLV)) {
    348         _SHR_UNPACK_U16(buf, msg->data_tlv_len);
    349     }
    350 
    351     return buf;
    352 }
    353 
    354 uint8 *
    355 bhh_sdk_msg_ctrl_loopback_get_unpack(uint8 *buf,
    356                                      bhh_sdk_msg_ctrl_loopback_get_t *msg)
    357 {
    358     int i;
    359 
    360     _SHR_UNPACK_U32(buf, msg->flags);
    361     _SHR_UNPACK_U32(buf, msg->sess_id);
    362     _SHR_UNPACK_U32(buf, msg->period);
    363     _SHR_UNPACK_U32(buf, msg->ttl);
    364     _SHR_UNPACK_U32(buf, msg->discovery_flags);
    365     _SHR_UNPACK_U32(buf, msg->discovery_id);
    366     _SHR_UNPACK_U32(buf, msg->discovery_ttl);
    367     _SHR_UNPACK_U32(buf, msg->rx_count);
    368     _SHR_UNPACK_U32(buf, msg->tx_count);
    369     _SHR_UNPACK_U32(buf, msg->drop_count);
    370     _SHR_UNPACK_U32(buf, msg->unexpected_response);
    371     _SHR_UNPACK_U32(buf, msg->out_of_sequence);
    372     _SHR_UNPACK_U32(buf, msg->local_mipid_missmatch);
    373     _SHR_UNPACK_U32(buf, msg->remote_mipid_missmatch);
    374     _SHR_UNPACK_U32(buf, msg->invalid_target_mep_tlv);
    375     _SHR_UNPACK_U32(buf, msg->invalid_mep_tlv_subtype);
    376     _SHR_UNPACK_U32(buf, msg->invalid_tlv_offset);
    377 
    378     if(BHH_UC_FEATURE_CHECK(BHH_OLP_ENCAP)) {
    379         _SHR_UNPACK_U16(buf, msg->encap_length);
    380         for (i = 0; i < msg->encap_length; i++) {
    381             _SHR_UNPACK_U8(buf, msg->encap_data[i]);
    382         }
    383     }
    384 
    385     if (BHH_UC_FEATURE_CHECK(BHH_PRIORITY_EVENT)) {
    386         _SHR_UNPACK_U32(buf, msg->int_pri);
    387         _SHR_UNPACK_U8 (buf, msg->pkt_pri);
    388     }
    389 
    390     return buf;
    391 }
    392 
    393 uint8 *
    394 bhh_sdk_msg_ctrl_trunk_map_update_pack(uint8 *buf,
    395                                        bhh_sdk_msg_ctrl_trunk_map_update_t *msg)
    396 {
    397     uint16 i;
    398 
    399     _SHR_PACK_U16(buf, msg->num_ports);
    400     _SHR_PACK_U16(buf, msg->trunk_id);
    401     for (i = 0; i < msg->num_ports; i++) {
    402         _SHR_PACK_U16(buf, msg->port_list[i]);
    403     }
    404 
    405     return buf;
    406 }
    407 
    408 uint8 *
    409 bhh_sdk_msg_ctrl_trunk_map_get_unpack(uint8 *buf,
    410                                       bhh_sdk_msg_ctrl_trunk_map_get_t *msg)
    411 {
    412    uint16 i;
    413 
    414     _SHR_UNPACK_U16(buf, msg->num_ports);
    415     _SHR_UNPACK_U16(buf, msg->trunk_id);
    416     for (i = 0; i < msg->num_ports; i++) {
    417         _SHR_UNPACK_U16(buf, msg->port_list[i]);
    418     }
    419 
    420     return buf;
    421 }
    422 
    423 uint8 *
    424 bhh_sdk_msg_ctrl_csf_add_pack(uint8 *buf, bhh_sdk_msg_ctrl_csf_add_t *msg)
    425 {
    426     uint16 i;
    427 
    428     _SHR_PACK_U16(buf, msg->sess_id);
    429     _SHR_PACK_U32(buf, msg->flags);
    430     _SHR_PACK_U8 (buf, msg->type);
    431     _SHR_PACK_U32(buf, msg->period);
    432     _SHR_PACK_U8 (buf, msg->int_pri);
    433     _SHR_PACK_U8 (buf, msg->pkt_pri);
    434 
    435     _SHR_PACK_U16(buf, msg->encap_length);
    436     for (i = 0; i < msg->encap_length; i++) {
    437         _SHR_PACK_U8(buf, msg->encap_data[i]);
    438     }
    439 
    440     return buf;
    441 }
    442 
    443 uint8 *
    444 bhh_sdk_msg_ctrl_csf_get_unpack(uint8 *buf, bhh_sdk_msg_ctrl_csf_get_t *msg)
    445 {
    446     uint16 i;
    447 
    448     _SHR_UNPACK_U32(buf, msg->flags);
    449     _SHR_UNPACK_U8 (buf, msg->type);
    450     _SHR_UNPACK_U32(buf, msg->period);
    451     _SHR_UNPACK_U8 (buf, msg->int_pri);
    452     _SHR_UNPACK_U8 (buf, msg->pkt_pri);
    453 
    454     _SHR_UNPACK_U16(buf, msg->encap_length);
    455     for (i = 0; i < msg->encap_length; i++) {
    456         _SHR_UNPACK_U8(buf, msg->encap_data[i]);
    457     }
    458 
    459     _SHR_UNPACK_U32(buf, msg->tx_csf_packets);
    460     return buf;
    461 }
    462 
    463 uint8 *
    464 bhh_sdk_msg_ctrl_ach_channel_type_msg_pack(uint8 *buf, uint32 *msg)
    465 {
    466     _SHR_PACK_U32(buf, *msg);
    467     return buf;
    468 }
    469 
    470 #else /* INCLUDE_BHH */
    471 int bcm_xgs5_bfd_not_empty;
    472 #endif  /* INCLUDE_BHH */