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

bfd_sdk_pack.c (8676B)


      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:        bfd_sdk_pack.c
      6  * Purpose:     BFD unpack routines for:
      7  *              - BFD Control messages
      8  */
      9 #if defined(INCLUDE_BFD)
     10 
     11 #include <bcm_int/esw/bfd_sdk_pack.h>
     12 
     13 uint8 *
     14 bfd_sdk_msg_ctrl_init_pack(uint8 *buf, bfd_sdk_msg_ctrl_init_t *msg)
     15 {
     16     _SHR_PACK_U32(buf, msg->num_sessions);
     17     _SHR_PACK_U32(buf, msg->encap_size);
     18     _SHR_PACK_U32(buf, msg->num_auth_sha1_keys);
     19     _SHR_PACK_U32(buf, msg->num_auth_sp_keys);
     20     _SHR_PACK_U32(buf, msg->rx_channel);
     21     if (BFD_UC_FEATURE_CHECK(BFD_FEATURE_INIT_CONFIG_FLAGS)) {
     22         _SHR_PACK_U32(buf, msg->config_flags);
     23     }
     24 
     25     return buf;
     26 }
     27 
     28 uint8 *
     29 bfd_sdk_msg_ctrl_stat_reply_unpack(uint8 *buf, bfd_sdk_msg_ctrl_stat_reply_t *msg,
     30                                    uint8 stat64bit)
     31 {
     32     _SHR_UNPACK_U32(buf, msg->sess_id);
     33     _SHR_UNPACK_U32(buf, msg->packets_in);
     34     _SHR_UNPACK_U32(buf, msg->packets_out);
     35     _SHR_UNPACK_U32(buf, msg->packets_drop);
     36     _SHR_UNPACK_U32(buf, msg->packets_auth_drop);
     37     if (stat64bit && BFD_UC_FEATURE_CHECK(BFD_FEATURE_64BIT_STAT)) {
     38         _SHR_UNPACK_U32(buf, msg->packets_in_hi);
     39         _SHR_UNPACK_U32(buf, msg->packets_out_hi);
     40         _SHR_UNPACK_U32(buf, msg->packets_drop_hi);
     41         _SHR_UNPACK_U32(buf, msg->packets_auth_drop_hi);
     42     }
     43     if (BFD_UC_FEATURE_CHECK(BFD_FEATURE_ECHO_REPLY_PACKETS)) {
     44         _SHR_UNPACK_U32(buf, msg->packets_echo_reply);
     45         _SHR_UNPACK_U32(buf, msg->packets_echo_reply_hi);
     46     }
     47     return buf;
     48 }
     49 
     50 
     51 uint8 *
     52 bfd_sdk_msg_ctrl_stat_req_pack(uint8 *buf,
     53                                bfd_sdk_msg_ctrl_stat_req_t *msg)
     54 {
     55     _SHR_PACK_U32(buf, msg->sess_id);
     56     _SHR_PACK_U32(buf, msg->options);
     57 
     58     return buf;
     59 }
     60 
     61 uint8 *
     62 bfd_sdk_version_exchange_msg_unpack(uint8 *buf, bfd_sdk_version_exchange_msg_t *msg)
     63 {
     64     _SHR_UNPACK_U32(buf, msg->version);
     65     return buf;
     66 }
     67 
     68 uint8 *
     69 bfd_sdk_version_exchange_msg_pack(uint8 *buf, bfd_sdk_version_exchange_msg_t *msg)
     70 {
     71     _SHR_PACK_U32(buf, msg->version);
     72     return buf;
     73 }
     74 
     75 uint8 *
     76 bfd_sdk_msg_ctrl_sess_set_pack(uint8 *buf,
     77                                bfd_sdk_msg_ctrl_sess_set_t *msg)
     78 {
     79     uint16 i;
     80 
     81     _SHR_PACK_U32(buf, msg->sess_id);
     82     _SHR_PACK_U32(buf, msg->flags);
     83     _SHR_PACK_U8(buf, msg->passive);
     84     _SHR_PACK_U8(buf, msg->local_demand);
     85     _SHR_PACK_U8(buf, msg->local_diag);
     86     _SHR_PACK_U8(buf, msg->local_detect_mult);
     87     _SHR_PACK_U32(buf, msg->local_discriminator);
     88     _SHR_PACK_U32(buf, msg->remote_discriminator);
     89     _SHR_PACK_U32(buf, msg->local_min_tx);
     90     _SHR_PACK_U32(buf, msg->local_min_rx);
     91     _SHR_PACK_U32(buf, msg->local_min_echo_rx);
     92     _SHR_PACK_U8(buf, msg->auth_type);
     93     _SHR_PACK_U32(buf, msg->auth_key);
     94     _SHR_PACK_U32(buf, msg->xmt_auth_seq);
     95     _SHR_PACK_U8(buf, msg->encap_type);
     96     _SHR_PACK_U32(buf, msg->encap_length);
     97     for (i = 0; i < SHR_BFD_MAX_ENCAP_LENGTH; i++) {
     98         _SHR_PACK_U8(buf, msg->encap_data[i]);
     99     }
    100     _SHR_PACK_U16(buf, msg->lkey_etype);
    101     _SHR_PACK_U16(buf, msg->lkey_offset);
    102     _SHR_PACK_U16(buf, msg->lkey_length);
    103     _SHR_PACK_U32(buf, msg->mep_id_length);
    104     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
    105         _SHR_PACK_U8(buf, msg->mep_id[i]);
    106     }
    107     for (i = 0; i < SHR_BFD_MPLS_LABEL_LENGTH; i++) {
    108         _SHR_PACK_U8(buf, msg->mpls_label[i]);
    109     }
    110     _SHR_PACK_U32(buf, msg->tx_port);
    111     _SHR_PACK_U32(buf, msg->tx_cos);
    112     _SHR_PACK_U32(buf, msg->tx_pri);
    113     _SHR_PACK_U32(buf, msg->tx_qnum);
    114     if (BFD_UC_FEATURE_CHECK(BFD_FEATURE_ECHO_MODE)) {
    115         _SHR_PACK_U8(buf, msg->local_echo);
    116     }
    117     if (BFD_UC_FEATURE_CHECK(BFD_FEATURE_REMOTE_MEP_ID)) {
    118         _SHR_PACK_U32(buf, msg->remote_mep_id_length);
    119         for (i = 0; i < msg->remote_mep_id_length; i++) {
    120              _SHR_PACK_U8(buf, msg->remote_mep_id[i]);
    121         }
    122     }
    123     if(BFD_UC_FEATURE_CHECK(BFD_FEATURE_RX_PKT_VLAN_ID)) {
    124         _SHR_PACK_U16(buf, msg->rx_pkt_vlan_id);
    125     }
    126     return buf;
    127 }
    128 
    129 uint8 *
    130 bfd_sdk_msg_ctrl_sess_get_unpack(uint8 *buf,
    131                                  bfd_sdk_msg_ctrl_sess_get_t *msg)
    132 {
    133     uint16 i;
    134 
    135     _SHR_UNPACK_U32(buf, msg->sess_id);
    136     _SHR_UNPACK_U8(buf, msg->enable);
    137     _SHR_UNPACK_U8(buf, msg->passive);
    138     if (BFD_UC_FEATURE_CHECK(BFD_FEATURE_POLL_BIT)) {
    139         _SHR_UNPACK_U8(buf, msg->poll);
    140     }
    141     _SHR_UNPACK_U8(buf, msg->local_demand);
    142     _SHR_UNPACK_U8(buf, msg->remote_demand);
    143     _SHR_UNPACK_U8(buf, msg->local_diag);
    144     _SHR_UNPACK_U8(buf, msg->remote_diag);
    145     _SHR_UNPACK_U8(buf, msg->local_sess_state);
    146     _SHR_UNPACK_U8(buf, msg->remote_sess_state);
    147     _SHR_UNPACK_U8(buf, msg->local_detect_mult);
    148     _SHR_UNPACK_U8(buf, msg->remote_detect_mult);
    149     _SHR_UNPACK_U32(buf, msg->local_discriminator);
    150     _SHR_UNPACK_U32(buf, msg->remote_discriminator);
    151     _SHR_UNPACK_U32(buf, msg->local_min_tx);
    152     _SHR_UNPACK_U32(buf, msg->remote_min_tx);
    153     _SHR_UNPACK_U32(buf, msg->local_min_rx);
    154     _SHR_UNPACK_U32(buf, msg->remote_min_rx);
    155     _SHR_UNPACK_U32(buf, msg->local_min_echo_rx);
    156     _SHR_UNPACK_U32(buf, msg->remote_min_echo_rx);
    157     _SHR_UNPACK_U8(buf, msg->auth_type);
    158     _SHR_UNPACK_U32(buf, msg->auth_key);
    159     _SHR_UNPACK_U32(buf, msg->xmt_auth_seq);
    160     _SHR_UNPACK_U32(buf, msg->rcv_auth_seq);
    161     _SHR_UNPACK_U8(buf, msg->encap_type);
    162     _SHR_UNPACK_U32(buf, msg->encap_length);
    163     for (i = 0; i < SHR_BFD_MAX_ENCAP_LENGTH; i++) {
    164         _SHR_UNPACK_U8(buf, msg->encap_data[i]);
    165     }
    166     _SHR_UNPACK_U16(buf, msg->lkey_etype);
    167     _SHR_UNPACK_U16(buf, msg->lkey_offset);
    168     _SHR_UNPACK_U16(buf, msg->lkey_length);
    169     _SHR_UNPACK_U32(buf, msg->mep_id_length);
    170     for (i = 0; i < _SHR_BFD_ENDPOINT_MAX_MEP_ID_LENGTH; i++) {
    171         _SHR_UNPACK_U8(buf, msg->mep_id[i]);
    172     }
    173     for (i = 0; i < SHR_BFD_MPLS_LABEL_LENGTH; i++) {
    174         _SHR_UNPACK_U8(buf, msg->mpls_label[i]);
    175     }
    176     _SHR_UNPACK_U32(buf, msg->tx_port);
    177     _SHR_UNPACK_U32(buf, msg->tx_cos);
    178     _SHR_UNPACK_U32(buf, msg->tx_pri);
    179     _SHR_UNPACK_U32(buf, msg->tx_qnum);
    180     if (BFD_UC_FEATURE_CHECK(BFD_FEATURE_ECHO_MODE)) {
    181         _SHR_UNPACK_U8(buf, msg->local_echo);
    182     }
    183     if (BFD_UC_FEATURE_CHECK(BFD_FEATURE_REMOTE_MEP_ID)) {
    184         _SHR_UNPACK_U32(buf, msg->remote_mep_id_length);
    185         for (i = 0; i < msg->remote_mep_id_length; i++) {
    186              _SHR_UNPACK_U8(buf, msg->remote_mep_id[i]);
    187         }
    188         _SHR_UNPACK_U32(buf, msg->mis_conn_mep_id_length);
    189         for (i = 0; i < msg->mis_conn_mep_id_length; i++) {
    190              _SHR_UNPACK_U8(buf, msg->mis_conn_mep_id[i]);
    191         }
    192     }
    193 
    194     if(BFD_UC_FEATURE_CHECK(BFD_FEATURE_RX_PKT_VLAN_ID)) {
    195         _SHR_UNPACK_U16(buf, msg->rx_pkt_vlan_id);
    196     }
    197 
    198     return buf;
    199 }
    200 
    201 uint8 *
    202 bfd_sdk_msg_ctrl_discard_stat_get_unpack(uint8 *buf,
    203                                          bfd_sdk_msg_ctrl_discard_stat_get_t *msg)
    204 {
    205     _SHR_UNPACK_U32(buf, msg->bfd_ver_err);
    206     _SHR_UNPACK_U32(buf, msg->bfd_len_err);
    207     _SHR_UNPACK_U32(buf, msg->bfd_detect_mult);
    208     _SHR_UNPACK_U32(buf, msg->bfd_my_disc);
    209     _SHR_UNPACK_U32(buf, msg->bfd_p_f_bit);
    210     _SHR_UNPACK_U32(buf, msg->bfd_m_bit);
    211     _SHR_UNPACK_U32(buf, msg->bfd_auth_type_mismatch);
    212     _SHR_UNPACK_U32(buf, msg->bfd_auth_simple_err);
    213     _SHR_UNPACK_U32(buf, msg->bfd_auth_m_sha1_err);
    214     _SHR_UNPACK_U32(buf, msg->bfd_sess_mismatch);
    215 
    216     return buf;
    217 }
    218 
    219 #if defined(BCM_TOMAHAWK_SUPPORT)
    220 uint8 *
    221 bfd_sdk_msg_port_txqueue_map_pack(uint8 *buf,
    222                                   bfd_sdk_msg_port_txqueue_map_t *msg) {
    223     int i = 0;
    224 
    225     _SHR_PACK_U16(buf, msg->max_num_port);
    226     for (i = 0; i <= msg->max_num_port; i++) {
    227         _SHR_PACK_U16(buf, msg->tx_queue[i]);
    228     }
    229 
    230     return buf;
    231 }
    232 #endif
    233 
    234 uint8* bfd_sdk_msg_ctrl_trace_log_enable_unpack(uint8 *buf,
    235                                               bfd_sdk_msg_ctrl_trace_log_enable_t *msg)
    236 {
    237     _SHR_UNPACK_U32(buf, msg->addr_hi);
    238     _SHR_UNPACK_U32(buf, msg->addr_lo);
    239 
    240     return buf;
    241 }
    242 
    243 #if defined(BCM_TRIDENT3_SUPPORT)
    244 uint8 *
    245 bfd_sdk_msg_match_id_map_pack(uint8 *buf,
    246                               bfd_sdk_msg_match_id_map_t *msg) {
    247     int i = 0;
    248 
    249     _SHR_PACK_U32(buf, msg->match_id_types);
    250     _SHR_PACK_U32(buf, msg->match_id_length);
    251     for (i = 0; i <= msg->match_id_types; i++) {
    252         _SHR_PACK_U32(buf, msg->match_id_fields[i].offset);
    253         _SHR_PACK_U32(buf, msg->match_id_fields[i].width);
    254         _SHR_PACK_U32(buf, msg->match_id_fields[i].value);
    255     }
    256 
    257     return buf;
    258 }
    259 #endif
    260 
    261 #else /* INCLUDE_BFD */
    262 int bcm_xgs5_bfd_not_empty;
    263 #endif  /* INCLUDE_BFD */