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

ifa.c (47942B)


      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  * IFA - In-band Flow Analyzer Monitoring Embedded Application APP interface
      8  * Purpose: API to configure IFA embedded app interface.
      9  */
     10 
     11 #if defined(INCLUDE_IFA)
     12 
     13 #include <shared/bsl.h>
     14 #include <soc/defs.h>
     15 #include <soc/drv.h>
     16 #include <soc/uc.h>
     17 #include <soc/loopback.h>
     18 #include <shared/alloc.h>
     19 #include <soc/shared/ifa.h>
     20 #include <soc/shared/ifa_msg.h>
     21 #include <soc/shared/ifa_pack.h>
     22 #include <soc/shared/shr_pkt.h>
     23 
     24 #include <bcm/types.h>
     25 #include <bcm/error.h>
     26 #include <bcm/ifa.h>
     27 
     28 #include <bcm_int/esw/ifa.h>
     29 #include <bcm_int/esw/xgs5.h>
     30 #include <bcm_int/common/rx.h>
     31 #include <bcm_int/esw_dispatch.h>
     32 #include <bcm_int/esw/ifa_feature.h>
     33 #include <bcm_int/esw/ifa_sdk_pack.h>
     34 #include <bcm_int/esw/ifa_sdk_msg.h>
     35 
     36 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
     37 #include <soc/flexport/trident3/trident3_flexport_defines.h>
     38 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
     39 
     40 /*Global to hold the ifa firmware version for feature compatibility check */
     41 uint32 ifa_firmware_version = 0;
     42 
     43 /* List of ifa collector info*/
     44 bcm_ifa_collector_info_t ifa_collector_info[BCM_MAX_NUM_UNITS];
     45 
     46 /* List of ifa collector info*/
     47 bcm_ifa_config_info_t ifa_config_info[BCM_MAX_NUM_UNITS];
     48 
     49 /*
     50  * Function:
     51  *      _bcm_xgs5_ifa_convert_uc_error
     52  * Purpose:
     53  *      Converts uController error code to corresponding BCM error code.
     54  * Parameters:
     55  *      uc_rv  - (IN) uController error code to convert.
     56  * Returns:
     57  *      BCM_E_XXX   - BCM error code.
     58  * Notes:
     59  */
     60 STATIC int
     61 _bcm_xgs5_ifa_convert_uc_error(uint32 uc_rv)
     62 {
     63     int rv = BCM_E_NONE;
     64 
     65     switch(uc_rv) {
     66     case SHR_IFA_UC_E_NONE:
     67         rv = BCM_E_NONE;
     68         break;
     69     case SHR_IFA_UC_E_INTERNAL:
     70         rv = BCM_E_INTERNAL;
     71         break;
     72     case SHR_IFA_UC_E_MEMORY:
     73         rv = BCM_E_MEMORY;
     74         break;
     75     case SHR_IFA_UC_E_UNIT:
     76         rv = BCM_E_UNIT;
     77         break;
     78     case SHR_IFA_UC_E_PARAM:
     79         rv = BCM_E_PARAM;
     80         break;
     81     case SHR_IFA_UC_E_EMPTY:
     82         rv = BCM_E_EMPTY;
     83         break;
     84     case SHR_IFA_UC_E_FULL:
     85         rv = BCM_E_FULL;
     86         break;
     87     case SHR_IFA_UC_E_NOT_FOUND:
     88         rv = BCM_E_NOT_FOUND;
     89         break;
     90     case SHR_IFA_UC_E_EXISTS:
     91         rv = BCM_E_EXISTS;
     92         break;
     93     case SHR_IFA_UC_E_TIMEOUT:
     94         rv = BCM_E_TIMEOUT;
     95         break;
     96     case SHR_IFA_UC_E_BUSY:
     97         rv = BCM_E_BUSY;
     98         break;
     99     case SHR_IFA_UC_E_FAIL:
    100         rv = BCM_E_FAIL;
    101         break;
    102     case SHR_IFA_UC_E_DISABLED:
    103         rv = BCM_E_DISABLED;
    104         break;
    105     case SHR_IFA_UC_E_BADID:
    106         rv = BCM_E_BADID;
    107         break;
    108     case SHR_IFA_UC_E_RESOURCE:
    109         rv = BCM_E_RESOURCE;
    110         break;
    111     case SHR_IFA_UC_E_CONFIG:
    112         rv = BCM_E_CONFIG;
    113         break;
    114     case SHR_IFA_UC_E_UNAVAIL:
    115         rv = BCM_E_UNAVAIL;
    116         break;
    117     case SHR_IFA_UC_E_INIT:
    118         rv = BCM_E_INIT;
    119         break;
    120     case SHR_IFA_UC_E_PORT:
    121         rv = BCM_E_PORT;
    122         break;
    123     default:
    124         rv = BCM_E_INTERNAL;
    125         break;
    126     }
    127 
    128     return rv;
    129 }
    130 
    131 /*
    132  * Functions:
    133  *      _bcm_xgs5_ifa_<header>_get
    134  * Purpose:
    135  *      The following set of _get() functions builds a given header for
    136  *      a given collector.
    137  * Parameters:
    138  *      collector_info -  (IN) Pointer to Collector information structure.
    139  *      <... other IN args ...>
    140  *      <header>  - (OUT) Returns header.
    141  * Returns:
    142  *      BCM_E_XXX
    143  * Notes:
    144  */
    145 STATIC int
    146 _bcm_xgs5_ifa_int_header_get(int unit,
    147                              bcm_ifa_config_info_t *config_info,
    148                              shr_int_header_t *int_h)
    149 {
    150     /* Set INT */
    151     sal_memset(int_h, 0, sizeof(*int_h));
    152     int_h->probemarker1     = config_info->probemarker_1;
    153     int_h->probemarker2     = config_info->probemarker_2;
    154     int_h->maximumlength    = config_info->max_payload_length;
    155     int_h->hoplimit         = config_info->hop_limit;
    156 
    157     /* INT Header below fields fixed in case of IFA eapps */
    158     int_h->ver                  = 1;
    159     int_h->type                 = 1;
    160     int_h->flags                = 0;
    161     int_h->requestvector        = 0xFFFFFFFF;
    162     int_h->hopcount             = 0;
    163     int_h->currentlength        = 0;
    164 
    165     /* INT header sequence number update by R5 */
    166     int_h->senderhandle         = 0;
    167     int_h->seqnumber            = 0;
    168 
    169     return BCM_E_NONE;
    170 }
    171 
    172 STATIC int
    173 _bcm_xgs5_ifa_lb_header_get(
    174                             bcm_ifa_config_info_t *config_info,
    175                             shr_lb_header_t *lb)
    176 {
    177     /* LB Header below fields fixed in case of IFA eapps */
    178     sal_memset(lb, 0, sizeof(*lb));
    179     lb->start               = 0xFB;
    180     lb->common_hdr1         = 1;
    181     lb->source_type         = 1;
    182     lb->visibility          = 1;
    183     lb->pkt_profile         = 3;
    184 
    185     /* LB header other fields are update by R5 */
    186     return BCM_E_NONE;
    187 }
    188 
    189 
    190 STATIC int
    191 _bcm_xgs5_ifa_udp_header_get(
    192                              bcm_ifa_collector_info_t *collector_info,
    193                              shr_udp_header_t *udp)
    194 {
    195     /* Set UDP */
    196     sal_memset(udp, 0, sizeof(*udp));
    197     udp->src = collector_info->udp.src_port;
    198     udp->dst = collector_info->udp.dst_port;
    199     /* Do not set UDP length since this will be filled by
    200      * EAPP.
    201      */
    202     udp->length = 0;
    203     udp->sum = 0;    /* Calculated later */
    204 
    205     return BCM_E_NONE;
    206 }
    207 
    208 STATIC int
    209 _bcm_xgs5_ifa_ipv6_header_get(uint8 protocol,
    210         uint32 f_label, uint8 t_class, uint8 hop_limit,
    211         bcm_ip6_t src_ip_addr, bcm_ip6_t dst_ip_addr,
    212         shr_ipv6_header_t *ip)
    213 {
    214     sal_memset(ip, 0, sizeof(*ip));
    215     ip->version  = SHR_IPV6_VERSION;
    216     ip->next_header = protocol;
    217     ip->t_class = t_class;
    218     ip->hop_limit = hop_limit;
    219     ip->f_label = f_label;
    220     /* Dont fill in length since length will be calculated by
    221      * EAPP.
    222      */
    223     ip->p_length   = 0;
    224 
    225     /* Destination and Source IP address */
    226     sal_memcpy(ip->src, src_ip_addr, sizeof(bcm_ip6_t));
    227     sal_memcpy(ip->dst, dst_ip_addr, sizeof(bcm_ip6_t));
    228 
    229     return BCM_E_NONE;
    230 }
    231 
    232 STATIC int
    233 _bcm_xgs5_ifa_ipv4_header_get(uint8 protocol,
    234         uint8 tos, uint8 ttl,
    235         bcm_ip_t src_ip_addr, bcm_ip_t dst_ip_addr,
    236         shr_ipv4_header_t *ip)
    237 {
    238     uint8 buffer[SHR_IPV4_HEADER_LENGTH];
    239 
    240     sal_memset(ip, 0, sizeof(*ip));
    241     ip->version  = SHR_IPV4_VERSION;
    242     ip->h_length = SHR_IPV4_HEADER_LENGTH_WORDS;
    243     ip->dscp     = tos;
    244     ip->ecn      = 0;
    245     /* Dont fill in length since length will be calculated by
    246      * EAPP.
    247      */
    248     ip->length   = 0;
    249     ip->id       = 0;
    250     ip->flags    = 0;
    251     ip->f_offset = 0;
    252     ip->ttl      = ttl;
    253     ip->protocol = protocol;
    254     ip->sum      = 0;
    255     ip->src      = src_ip_addr;
    256     ip->dst      = dst_ip_addr;
    257 
    258     /* Calculate IP header checksum */
    259     shr_ipv4_header_pack(buffer, ip);
    260     ip->sum = 0;
    261 
    262     return BCM_E_NONE;
    263 }
    264 
    265 STATIC int
    266 _bcm_xgs5_ifa_ip6_headers_get(bcm_ifa_collector_info_t *collector_info,
    267                               uint16 *etype,
    268                               shr_ipv6_header_t *ipv6)
    269 {
    270     int ip_protocol;
    271 
    272     ip_protocol = SHR_IP_PROTOCOL_UDP;
    273     *etype = SHR_L2_ETYPE_IPV6;
    274 
    275     BCM_IF_ERROR_RETURN
    276         (_bcm_xgs5_ifa_ipv6_header_get(ip_protocol,
    277                                        collector_info->ipv6.flow_label,
    278                                        collector_info->ipv6.traffic_class,
    279                                        collector_info->ipv6.hop_limit,
    280                                        collector_info->ipv6.src_ip,
    281                                        collector_info->ipv6.dst_ip,
    282                                        ipv6));
    283 
    284     return BCM_E_NONE;
    285 }
    286 
    287 
    288 STATIC int
    289 _bcm_xgs5_ifa_ip4_headers_get(bcm_ifa_collector_info_t *collector_info,
    290         uint16 *etype,
    291         shr_ipv4_header_t *ipv4)
    292 {
    293     int ip_protocol;
    294 
    295     ip_protocol = SHR_IP_PROTOCOL_UDP;
    296     *etype = SHR_L2_ETYPE_IPV4;
    297 
    298     BCM_IF_ERROR_RETURN
    299         (_bcm_xgs5_ifa_ipv4_header_get(ip_protocol,
    300                                        collector_info->ipv4.dscp,
    301                                        collector_info->ipv4.ttl,
    302                                        collector_info->ipv4.src_ip,
    303                                        collector_info->ipv4.dst_ip,
    304                                        ipv4));
    305 
    306     return BCM_E_NONE;
    307 }
    308 
    309 STATIC int
    310 _bcm_xgs5_ifa_l2_header_get(bcm_ifa_collector_info_t *collector_info,
    311         uint16 etype, shr_l2_header_t *l2)
    312 {
    313     sal_memset(l2, 0, sizeof(*l2));
    314 
    315     /* Destination and Source MAC */
    316     sal_memcpy(l2->dst_mac, collector_info->eth.dst_mac, SHR_MAC_ADDR_LENGTH);
    317     sal_memcpy(l2->src_mac, collector_info->eth.src_mac, SHR_MAC_ADDR_LENGTH);
    318 
    319     /*
    320      * VLAN Tag(s)
    321      */
    322     if (collector_info->eth.vlan_tag_structure == BCM_IFA_COLLECTOR_ETH_HDR_UNTAGGED) {
    323         /* Set to 0 to indicate untagged */
    324         l2->outer_vlan_tag.tpid = 0;
    325         l2->inner_vlan_tag.tpid = 0;
    326     } else {
    327         /* Fill outer vlan */
    328         if ((collector_info->eth.vlan_tag_structure == BCM_IFA_COLLECTOR_ETH_HDR_SINGLE_TAGGED) ||
    329             (collector_info->eth.vlan_tag_structure == BCM_IFA_COLLECTOR_ETH_HDR_DOUBLE_TAGGED))
    330         {
    331             l2->outer_vlan_tag.tpid     = collector_info->eth.outer_tpid;
    332             l2->outer_vlan_tag.tci.prio = BCM_VLAN_CTRL_PRIO(collector_info->eth.outer_vlan_tag);
    333             l2->outer_vlan_tag.tci.cfi  = BCM_VLAN_CTRL_CFI(collector_info->eth.outer_vlan_tag);
    334             l2->outer_vlan_tag.tci.vid  = BCM_VLAN_CTRL_ID(collector_info->eth.outer_vlan_tag);
    335         } else {
    336             return BCM_E_PARAM;
    337         }
    338         /* Fill inner vlan if double tagged */
    339         if (collector_info->eth.vlan_tag_structure == BCM_IFA_COLLECTOR_ETH_HDR_DOUBLE_TAGGED) {
    340             l2->inner_vlan_tag.tpid     = collector_info->eth.inner_tpid;
    341             l2->inner_vlan_tag.tci.prio = BCM_VLAN_CTRL_PRIO(collector_info->eth.inner_vlan_tag);
    342             l2->inner_vlan_tag.tci.cfi  = BCM_VLAN_CTRL_CFI(collector_info->eth.inner_vlan_tag);
    343             l2->inner_vlan_tag.tci.vid  = BCM_VLAN_CTRL_ID(collector_info->eth.inner_vlan_tag);
    344         } else {
    345             l2->inner_vlan_tag.tpid = 0;  /* Set to 0 to indicate not inner tagged */
    346         }
    347     }
    348 
    349     /* Ether Type */
    350     l2->etype = etype;
    351 
    352     return BCM_E_NONE;
    353 }
    354 
    355 /*
    356  * Function:
    357  *      _bcm_xgs5_ifa_eapp_collector_encap_build_pack
    358  * Purpose:
    359  *      Builds and packs the IFA export packet
    360  *      encapsulation for a given collector
    361  * Parameters:
    362  *      collector_info  - (IN) Pointer to collector info structure.
    363  *      collector_set_msg - (OUT) Message which contains the encapsulation.
    364  * Returns:
    365  *      BCM_E_XXX
    366  * Notes:
    367  *      The returning encapsulation includes only all the
    368  *      encapsulation headers and does not include control packet.
    369  */
    370 STATIC int
    371 _bcm_xgs5_ifa_eapp_collector_encap_build_pack(
    372         bcm_ifa_collector_info_t *collector_info,
    373         shr_ifa_msg_ctrl_collector_info_t *collector_set_msg)
    374 {
    375     uint8               *buffer  = collector_set_msg->encap;
    376     uint8               *cur_ptr;
    377     uint16              etype = 0;
    378     shr_udp_header_t    udp;
    379     shr_ipv4_header_t   ipv4;
    380     shr_ipv6_header_t   ipv6;
    381     shr_l2_header_t     l2;
    382     uint16              ip_offset = 0;
    383     uint16              udp_offset = 0;
    384 
    385     sal_memset(&udp, 0, sizeof(udp));
    386     sal_memset(&ipv4, 0, sizeof(ipv4));
    387     sal_memset(&l2, 0, sizeof(l2));
    388 
    389     /*
    390      * Get necessary headers/labels information.
    391      *
    392      * Following order is important since some headers/labels
    393      * may depend on previous header/label information.
    394      */
    395     if ((collector_info->transport_type == bcmIfaCollectorTransportTypeIpv4Udp) ||
    396         (collector_info->transport_type == bcmIfaCollectorTransportTypeIpv6Udp)) {
    397         BCM_IF_ERROR_RETURN
    398             (_bcm_xgs5_ifa_udp_header_get(collector_info, &udp));
    399     }
    400 
    401     if (collector_info->transport_type == bcmIfaCollectorTransportTypeIpv4Udp) {
    402         BCM_IF_ERROR_RETURN
    403             (_bcm_xgs5_ifa_ip4_headers_get(collector_info,
    404                                            &etype,
    405                                            &ipv4));
    406     }
    407 
    408     if (collector_info->transport_type == bcmIfaCollectorTransportTypeIpv6Udp) {
    409         BCM_IF_ERROR_RETURN
    410             (_bcm_xgs5_ifa_ip6_headers_get(collector_info,
    411                                           &etype,
    412                                           &ipv6));
    413     }
    414 
    415     /* Always build L2 Header */
    416     BCM_IF_ERROR_RETURN
    417         (_bcm_xgs5_ifa_l2_header_get(collector_info, etype, &l2));
    418 
    419     /*
    420      * Pack header/labels into given buffer (network packet format).
    421      *
    422      * Following packing order must be followed to correctly
    423      * build the packet encapsulation.
    424      */
    425     cur_ptr = buffer;
    426 
    427     /* L2 Header is always present */
    428     cur_ptr = shr_l2_header_pack(cur_ptr, &l2);
    429 
    430     if (collector_info->transport_type == bcmIfaCollectorTransportTypeIpv6Udp) {
    431         /*
    432          * IP offset
    433          */
    434         ip_offset = cur_ptr - buffer;
    435         cur_ptr = shr_ipv6_header_pack(cur_ptr, &ipv6);
    436     }
    437 
    438     if (collector_info->transport_type == bcmIfaCollectorTransportTypeIpv4Udp) {
    439         /*
    440          * IP offset
    441          */
    442         ip_offset = cur_ptr - buffer;
    443         cur_ptr = shr_ipv4_header_pack(cur_ptr, &ipv4);
    444     }
    445 
    446     if ((collector_info->transport_type == bcmIfaCollectorTransportTypeIpv4Udp) ||
    447         (collector_info->transport_type == bcmIfaCollectorTransportTypeIpv6Udp)) {
    448         /*
    449          * UDP offset
    450          */
    451         udp_offset = cur_ptr - buffer;
    452         cur_ptr = shr_udp_header_pack(cur_ptr, &udp);
    453     }
    454 
    455 
    456     /* Set IFA export pkt encapsulation length */
    457     collector_set_msg->encap_length = cur_ptr - buffer;
    458 
    459     /* Set IFA export pkt IP base offset */
    460     collector_set_msg->ip_offset = ip_offset;
    461 
    462     /* Set IFA export pkt IP Base checksum */
    463     collector_set_msg->ip_base_checksum =
    464         shr_initial_chksum_get(SHR_IPV4_HEADER_LENGTH, buffer + ip_offset);
    465 
    466     /* Set IFA export pkt UDP Base checksum */
    467     if (collector_info->transport_type == bcmIfaCollectorTransportTypeIpv4Udp) {
    468         collector_set_msg->udp_base_checksum =
    469             shr_udp_initial_checksum_get(0, &ipv4, NULL, NULL, &udp);
    470     }
    471 
    472     if (collector_info->transport_type == bcmIfaCollectorTransportTypeIpv6Udp) {
    473         collector_set_msg->udp_base_checksum =
    474             shr_udp_initial_checksum_get(1, NULL, &ipv6, NULL, &udp);
    475     }
    476 
    477     /* Set IFA export pkt UDP base offset */
    478     collector_set_msg->udp_offset = udp_offset;
    479     collector_set_msg->mtu        = collector_info->mtu;
    480 
    481     collector_set_msg->transport_type        = collector_info->transport_type;
    482     collector_set_msg->outer_vlan_tag        = collector_info->eth.outer_vlan_tag;
    483     collector_set_msg->inner_vlan_tag        = collector_info->eth.inner_vlan_tag;
    484     collector_set_msg->outer_tpid            = collector_info->eth.outer_tpid;
    485     collector_set_msg->inner_tpid            = collector_info->eth.inner_tpid;
    486     collector_set_msg->vlan_tag_structure    = collector_info->eth.vlan_tag_structure;
    487 
    488     return BCM_E_NONE;
    489 }
    490 
    491 /*
    492  * Function:
    493  *      _bcm_xgs5_ifa_eapp_loopback_port_set
    494  * Purpose:
    495  *      Builds and packs Device Id INT header
    496  * Parameters:
    497  *      config_info     - (IN) Device Id
    498  * Returns:
    499  *      BCM_E_XXX
    500  * Notes:
    501  *      The returning encapsulation includes only INT headers
    502  */
    503 STATIC int
    504 _bcm_xgs5_ifa_eapp_loopback_port_set(int unit, bcm_port_t lb_port)
    505 {
    506     int rv = BCM_E_NONE;
    507 #if defined(INCLUDE_L3)
    508     int     mod_id, pp_port, tgid, id;
    509     bcm_gport_t gport;
    510     int pipe_num;
    511     int loopback_port;
    512     source_trunk_map_modbase_entry_t modbase_entry;
    513     int i, lb_idx;
    514     uint32 src_ent[SOC_MAX_MEM_FIELD_WORDS];
    515     uint32 lb_src_ent[SOC_MAX_MEM_FIELD_WORDS];
    516     int lport_index = 0;
    517     int lb_lport_index = 0;
    518 
    519     BCM_IF_ERROR_RETURN(bcm_esw_port_gport_get(unit, lb_port, &gport));
    520     BCM_IF_ERROR_RETURN(_bcm_esw_gport_resolve(unit, gport, &mod_id, &pp_port,
    521                                                &tgid, &id));
    522 
    523     /*
    524      * Program the SOURCE_TRUNK_MAP with packet
    525      * processing port
    526      */
    527     SOC_IF_ERROR_RETURN(
    528         soc_port_pipe_get(unit, pp_port, &pipe_num));
    529     loopback_port = soc_loopback_lbport_num_get(unit, pipe_num);
    530     if (loopback_port == -1) {
    531         return BCM_E_PARAM;
    532     }
    533     sal_memset(src_ent, 0, sizeof(src_ent));
    534     sal_memset(lb_src_ent, 0, sizeof(lb_src_ent));
    535     BCM_IF_ERROR_RETURN
    536         (soc_mem_read(unit, ING_DEVICE_PORTm, MEM_BLOCK_ANY, pp_port,
    537          src_ent));
    538     lport_index =
    539         soc_mem_field32_get(unit, ING_DEVICE_PORTm, src_ent, LPORT_PROFILE_IDXf);
    540 
    541     BCM_IF_ERROR_RETURN
    542         (soc_mem_read(unit, ING_DEVICE_PORTm, MEM_BLOCK_ANY, loopback_port,
    543          lb_src_ent));
    544     lb_lport_index=
    545         soc_mem_field32_get(unit, ING_DEVICE_PORTm, lb_src_ent, LPORT_PROFILE_IDXf);
    546 
    547     BCM_IF_ERROR_RETURN
    548             (soc_mem_read(unit, SOURCE_TRUNK_MAP_MODBASEm, MEM_BLOCK_ANY,
    549                 mod_id, &modbase_entry));
    550 
    551     i = soc_mem_field32_get(unit, SOURCE_TRUNK_MAP_MODBASEm,
    552                     &modbase_entry, BASEf) + pp_port;
    553     lb_idx = soc_mem_field32_get(unit, SOURCE_TRUNK_MAP_MODBASEm,
    554                     &modbase_entry, BASEf) + loopback_port;
    555 
    556     BCM_IF_ERROR_RETURN
    557         (soc_mem_field32_modify(unit, SOURCE_TRUNK_MAP_TABLEm,
    558                                 i, PP_PORT_NUMf, pp_port));
    559     BCM_IF_ERROR_RETURN
    560         (soc_mem_field32_modify(unit, SOURCE_TRUNK_MAP_TABLEm,
    561                                 i, LPORT_PROFILE_IDXf, lport_index));
    562     BCM_IF_ERROR_RETURN
    563         (soc_mem_field32_modify(unit, SOURCE_TRUNK_MAP_TABLEm,
    564                                 lb_idx, PP_PORT_NUMf, loopback_port));
    565     BCM_IF_ERROR_RETURN
    566         (soc_mem_field32_modify(unit, SOURCE_TRUNK_MAP_TABLEm,
    567                                 lb_idx, LPORT_PROFILE_IDXf, lb_lport_index));
    568     return rv;
    569 #else
    570     return rv;
    571 #endif
    572 }
    573 
    574 /*
    575  * Function:
    576  *      _bcm_xgs5_ifa_eapp_int_encap_build_pack
    577  * Purpose:
    578  *      Builds and packs the IFA INT header
    579  * Parameters:
    580  *      config_info     - (IN) Pointer to config info structure.
    581  *      config_info_msg - (OUT) Message which contains the int header encapsulation.
    582  * Returns:
    583  *      BCM_E_XXX
    584  * Notes:
    585  *      The returning encapsulation includes only INT headers
    586  */
    587 STATIC int
    588 _bcm_xgs5_ifa_eapp_int_encap_build_pack(int unit,
    589         bcm_ifa_config_info_t *config_info,
    590         ifa_sdk_msg_ctrl_config_info_t *config_info_msg)
    591 {
    592     uint8               *buffer  = config_info_msg->int_encap;
    593     uint8               *cur_ptr;
    594     shr_int_header_t    int_h;
    595 
    596     sal_memset(&int_h, 0, sizeof(int_h));
    597     BCM_IF_ERROR_RETURN
    598         (_bcm_xgs5_ifa_int_header_get(unit, config_info, &int_h));
    599 
    600     /*
    601      * Pack header into given buffer (network packet format).
    602      */
    603     cur_ptr = buffer;
    604 
    605     /* INT Header is always present */
    606     cur_ptr = shr_int_header_pack(cur_ptr, &int_h);
    607 
    608     /* Set IFA export pkt encapsulation length */
    609     config_info_msg->int_encap_length = cur_ptr - buffer;
    610 
    611     if (config_info_msg->int_encap_length != SHR_INT_HEADER_LENGTH) {
    612         LOG_DEBUG(BSL_LS_BCM_IFA, (BSL_META_U(unit,
    613                         "IFA(unit %d) Info: update INT header"), unit));
    614         return (BCM_E_INIT);
    615     }
    616 
    617     return BCM_E_NONE;
    618 }
    619 
    620 /*
    621  * Function:
    622  *      _bcm_xgs5_ifa_eapp_lb_encap_build_pack
    623  * Purpose:
    624  *      Builds and packs the IFA LB Header
    625  * Parameters:
    626  *      config_info     - (IN) Pointer to config info structure.
    627  *      config_info_msg - (OUT) Message which contains the int header encapsulation.
    628  * Returns:
    629  *      BCM_E_XXX
    630  * Notes:
    631  *      The returning encapsulation includes only INT headers
    632  */
    633 STATIC int
    634 _bcm_xgs5_ifa_eapp_lb_encap_build_pack(int unit,
    635         bcm_ifa_config_info_t *config_info,
    636         ifa_sdk_msg_ctrl_config_info_t *config_info_msg)
    637 {
    638     uint8               *buffer  = config_info_msg->lb_encap;
    639     uint8               *cur_ptr;
    640     shr_lb_header_t     lb;
    641 
    642     sal_memset(&lb, 0, sizeof(lb));
    643     BCM_IF_ERROR_RETURN
    644         (_bcm_xgs5_ifa_lb_header_get(config_info, &lb));
    645 
    646     /*
    647      * Pack header into given buffer (network packet format).
    648      */
    649     cur_ptr = buffer;
    650 
    651     /* LoopBack Header is always present */
    652     cur_ptr = shr_lb_header_pack(cur_ptr, &lb);
    653 
    654     /* Set IFA export pkt encapsulation length */
    655     config_info_msg->lb_encap_length = cur_ptr - buffer;
    656 
    657     if (config_info_msg->lb_encap_length != SHR_LB_HEADER_LENGTH) {
    658         LOG_DEBUG(BSL_LS_BCM_IFA, (BSL_META_U(unit,
    659                         "IFA(unit %d) Info: update LB header"), unit));
    660         return (BCM_E_INIT);
    661     }
    662 
    663     return BCM_E_NONE;
    664 }
    665 
    666 STATIC int
    667 _bcm_xgs5_ifa_msg_send_receive(int unit, uint8 s_subclass,
    668                                uint16 s_len, uint32 s_data,
    669                                uint8 r_subclass, uint16 *r_len,
    670                                sal_usecs_t timeout)
    671 {
    672     int rv;
    673     mos_msg_data_t send, reply;
    674     uint32 uc_rv;
    675     _bcm_int_ifa_info_t *ifa_info = IFA_INFO_GET(unit);
    676     uint8 *dma_buffer;
    677     int dma_buffer_len;
    678 
    679 
    680     dma_buffer = ifa_info->dma_buffer;
    681     dma_buffer_len = ifa_info->dma_buffer_len;
    682 
    683     sal_memset(&send, 0, sizeof(send));
    684     sal_memset(&reply, 0, sizeof(reply));
    685     send.s.mclass = MOS_MSG_CLASS_IFA;
    686     send.s.subclass = s_subclass;
    687     send.s.len = bcm_htons(s_len);
    688 
    689     /*
    690      * Set 'data' to DMA buffer address if a DMA operation is
    691      * required for send or receive.
    692      */
    693     if (MOS_MSG_DMA_MSG(s_subclass) ||
    694             MOS_MSG_DMA_MSG(r_subclass)) {
    695         send.s.data = bcm_htonl(soc_cm_l2p(unit, dma_buffer));
    696     } else {
    697         send.s.data = bcm_htonl(s_data);
    698     }
    699 
    700     /* Flush DMA memory */
    701     if (MOS_MSG_DMA_MSG(s_subclass)) {
    702         soc_cm_sflush(unit, dma_buffer, s_len);
    703     }
    704 
    705     /* Invalidate DMA memory to read */
    706     if (MOS_MSG_DMA_MSG(r_subclass)) {
    707         soc_cm_sinval(unit, dma_buffer, dma_buffer_len);
    708     }
    709 
    710     rv = soc_cmic_uc_msg_send_receive(unit, ifa_info->uc_num,
    711                                       &send, &reply,
    712                                       timeout);
    713     if (rv != SOC_E_NONE){
    714         return BCM_E_INTERNAL;
    715     }
    716 
    717     /* Convert IFA uController error code to BCM */
    718     uc_rv  = bcm_ntohl(reply.s.data);
    719     rv     = _bcm_xgs5_ifa_convert_uc_error(uc_rv);
    720 
    721     *r_len = bcm_ntohs(reply.s.len);
    722 
    723     /*Check reply class and subclass*/
    724     if((rv == SOC_E_NONE) && ((reply.s.mclass != MOS_MSG_CLASS_IFA) ||
    725        (reply.s.subclass != r_subclass)))
    726     {
    727         return BCM_E_INTERNAL;
    728     }
    729     return rv;
    730 }
    731 
    732 int _bcm_xgs5_ifa_eapp_send_ctrl_init_msg (int unit)
    733 {
    734     shr_ifa_msg_ctrl_init_t ctrl_init_msg;
    735     uint8 *buffer_req = NULL, *buffer_ptr = NULL;
    736     uint16 buffer_len = 0, reply_len = 0;
    737     _bcm_int_ifa_info_t *ifa_info = IFA_INFO_GET(unit);
    738 
    739     sal_memset(&ctrl_init_msg, 0, sizeof(ctrl_init_msg));
    740     ctrl_init_msg.rx_channel = BCM_IFA_EAPP_RX_CHANNEL;
    741     ctrl_init_msg.tx_channel = BCM_IFA_EAPP_TX_CHANNEL;
    742 
    743     buffer_req      = ifa_info->dma_buffer;
    744     buffer_ptr      = shr_ifa_msg_ctrl_init_pack(buffer_req, &ctrl_init_msg);
    745     buffer_len      = buffer_ptr - buffer_req;
    746 
    747     BCM_IF_ERROR_RETURN(_bcm_xgs5_ifa_msg_send_receive(unit, MOS_MSG_SUBCLASS_IFA_INIT,
    748                 buffer_len, 0,
    749                 MOS_MSG_SUBCLASS_IFA_INIT_REPLY, &reply_len,
    750                 SHR_IFA_MAX_UC_MSG_TIMEOUT));
    751     return BCM_E_NONE;
    752 }
    753 
    754 /******************************************************
    755  *                                                     *
    756  *           IFA EMBEDDED APP APIs                     *
    757  */
    758 
    759 int bcm_xgs5_ifa_eapp_init(int unit)
    760 {
    761     _bcm_int_ifa_info_t *ifa_info = IFA_INFO_GET(unit);
    762     int rv = BCM_E_NONE;
    763     int uc = 0;
    764     int status;
    765     bcm_ifa_collector_info_t *collector_info_node = (&(ifa_collector_info[unit]));
    766     bcm_ifa_config_info_t *config_info_node = (&(ifa_config_info[unit]));
    767 
    768     /* Init the app */
    769     /*
    770      * Start IFA application in BTE (Broadcom Task Engine) uController,
    771      * if not already running (warm boot).
    772      * Determine which uController is running IFA  by choosing the first
    773      * uC that returns successfully.
    774      */
    775     for (uc = 0; uc < CMICM_NUM_UCS; uc++) {
    776         rv = soc_uc_status(unit, uc, &status);
    777         if ((rv == SOC_E_NONE) && (status != 0)) {
    778             rv = soc_cmic_uc_appl_init(unit, uc, MOS_MSG_CLASS_IFA,
    779                                        SHR_IFA_MAX_UC_MSG_TIMEOUT,
    780                                        IFA_SDK_VERSION,
    781                                        IFA_UC_MIN_VERSION,
    782                                        NULL, NULL);
    783             if (SOC_E_NONE == rv) {
    784                 /* IFA started successfully */
    785                 break;
    786             }
    787         }
    788     }
    789 
    790     if (uc >= CMICM_NUM_UCS) {
    791         /* Could not find or start IFA appl */
    792         LOG_WARN(BSL_LS_BCM_IFA,
    793                  (BSL_META_U(unit,
    794                              "uKernel IFA application not available\n")));
    795         return BCM_E_NONE;
    796     }
    797     ifa_info->uc_num             = uc;
    798 
    799     /* Detach if already initialized */
    800     if (!soc_feature(unit, soc_feature_ifa)) {
    801         BCM_IF_ERROR_RETURN(bcm_xgs5_ifa_eapp_detach(unit));
    802         return BCM_E_INIT;
    803     }
    804 
    805     if (!SOC_WARM_BOOT(unit)) {
    806         /* Send the init config to UKERNEL */
    807         rv = _bcm_xgs5_ifa_eapp_send_ctrl_init_msg(unit);
    808         if (BCM_FAILURE(rv)) {
    809             BCM_IF_ERROR_RETURN(bcm_xgs5_ifa_eapp_detach(unit));
    810             return rv;
    811         }
    812         sal_memset(collector_info_node, 0, sizeof(bcm_ifa_collector_info_t));
    813         sal_memset(config_info_node, 0, sizeof(bcm_ifa_config_info_t));
    814     } else {
    815         /* Get the Collector info */
    816         rv = bcm_xgs5_ifa_eapp_collector_info_get_msg(unit, collector_info_node);
    817         if (BCM_FAILURE(rv)) {
    818             return rv;
    819         }
    820 
    821         /* Get the Config info */
    822         rv = bcm_xgs5_ifa_eapp_config_info_get_msg(unit, config_info_node);
    823         if (BCM_FAILURE(rv)) {
    824             return rv;
    825         }
    826     }
    827 
    828     ifa_info->status = 1;
    829     return BCM_E_NONE;
    830 }
    831 
    832 int bcm_xgs5_ifa_eapp_detach(int unit)
    833 {
    834     _bcm_int_ifa_info_t *ifa_info = IFA_INFO_GET(unit);
    835     int                          rv = BCM_E_NONE;
    836     int                          status = 0;
    837     uint16                       reply_len = 0;
    838 
    839     if (!SOC_WARM_BOOT(unit)) {
    840         /* Un Init the app */
    841         SOC_IF_ERROR_RETURN(soc_uc_status(unit, ifa_info->uc_num, &status));
    842         if (status) {
    843             rv = _bcm_xgs5_ifa_msg_send_receive(unit,
    844                     MOS_MSG_SUBCLASS_IFA_SHUTDOWN,
    845                     0, 0,
    846                     MOS_MSG_SUBCLASS_IFA_SHUTDOWN_REPLY,
    847                     &reply_len,
    848                     SHR_IFA_MAX_UC_MSG_TIMEOUT);
    849             if (BCM_SUCCESS(rv) && (reply_len != 0)) {
    850                 return BCM_E_INTERNAL;
    851             }
    852         }
    853     }
    854 
    855     /*
    856      * Free DMA buffer
    857  */
    858     if (ifa_info->dma_buffer != NULL) {
    859         soc_cm_sfree(unit, ifa_info->dma_buffer);
    860     }
    861     ifa_info->status = 0;
    862 
    863     return BCM_E_NONE;
    864 }
    865 
    866 /*
    867  * Function:
    868  *     bcm_xgs5_ifa_collector_set
    869  * Purpose:
    870  *     Set a collector information.
    871  * Parameters:
    872  *     unit          - (IN) BCM device number
    873  *     collector_info - (IN) Collector informatin.
    874  * Returns:
    875  *     BCM_E_XXX
    876  */
    877 int
    878 bcm_xgs5_ifa_collector_set(int unit,
    879                            bcm_ifa_collector_info_t *collector_info)
    880 {
    881     bcm_ifa_collector_info_t *collector_info_node = (&(ifa_collector_info[unit]));
    882 
    883     if (collector_info_node->mtu != 0) {
    884         LOG_ERROR(BSL_LS_BCM_IFA, (BSL_META_U(unit,
    885                   "IFA(unit %d) Info: already exists \n"), unit));
    886         return BCM_E_EXISTS;
    887     }
    888 
    889     sal_memcpy(collector_info_node, collector_info,
    890                sizeof(bcm_ifa_collector_info_t));
    891 
    892     LOG_DEBUG(BSL_LS_BCM_IFA, (BSL_META_U(unit,
    893                     "IFA(unit %d) Info: %s \n"), unit, __FUNCTION__));
    894     return (BCM_E_NONE);
    895 }
    896 
    897 /*
    898  * Function:
    899  *     bcm_xgs5_ifa_collector_modify
    900  * Purpose:
    901  *     Set a collector information.
    902  * Parameters:
    903  *     unit          - (IN) BCM device number
    904  *     collector_info - (IN) Collector informatin.
    905  * Returns:
    906  *     BCM_E_XXX
    907  */
    908 int
    909 bcm_xgs5_ifa_collector_modify(int unit,
    910                               bcm_ifa_collector_info_t *collector_info)
    911 {
    912     bcm_ifa_collector_info_t *collector_info_node = (&(ifa_collector_info[unit]));
    913 
    914     if (collector_info_node->mtu == 0) {
    915         LOG_DEBUG(BSL_LS_BCM_IFA, (BSL_META_U(unit,
    916                   "IFA(unit %d) Info: collector does not exist"), unit));
    917         return (BCM_E_NOT_FOUND);
    918     }
    919 
    920     sal_memcpy(collector_info_node, collector_info,
    921                sizeof(bcm_ifa_collector_info_t));
    922     return (BCM_E_NONE);
    923 }
    924 
    925 /*
    926  * Function:
    927  *     bcm_xgs5_ifa_collector_get
    928  * Purpose:
    929  *     Set a collector information.
    930  * Parameters:
    931  *     unit          - (IN) BCM device number
    932  *     collector_info - (OUT) Collector informatin.
    933  * Returns:
    934  *     BCM_E_XXX
    935  */
    936 int
    937 bcm_xgs5_ifa_collector_get(int unit,
    938                            bcm_ifa_collector_info_t *collector_info)
    939 {
    940     bcm_ifa_collector_info_t *collector_info_node = (&(ifa_collector_info[unit]));
    941 
    942     if (collector_info_node->mtu == 0) {
    943         LOG_DEBUG(BSL_LS_BCM_IFA, (BSL_META_U(unit,
    944                   "IFA(unit %d) Info: collector does not exist"), unit));
    945         return (BCM_E_NOT_FOUND);
    946     }
    947 
    948     sal_memcpy(collector_info, (&(ifa_collector_info[unit])),
    949                sizeof(bcm_ifa_collector_info_t));
    950     return (BCM_E_NONE);
    951 }
    952 
    953 int bcm_xgs5_ifa_eapp_collector_set_msg(int unit,
    954                                         bcm_ifa_collector_info_t *collector_info)
    955 {
    956     shr_ifa_msg_ctrl_collector_info_t collector_set_msg;
    957     _bcm_int_ifa_info_t *ifa_info = IFA_INFO_GET(unit);
    958     uint8 *buffer_req = NULL, *buffer_ptr = NULL;
    959     uint16 buffer_len = 0, reply_len = 0;
    960     int rv = BCM_E_NONE;
    961 
    962     sal_memset(&collector_set_msg, 0, sizeof(collector_set_msg));
    963     if (collector_info->mtu) {
    964         rv = _bcm_xgs5_ifa_eapp_collector_encap_build_pack(
    965                                                            collector_info,
    966                                                            &collector_set_msg);
    967         if (BCM_FAILURE(rv)) {
    968             return rv;
    969         }
    970 
    971         /* Check if there is space to insert at least the headers  */
    972         if ((collector_set_msg.encap_length + BCM_IFA_L2_CRC_LENGTH) >
    973             collector_set_msg.mtu) {
    974             LOG_ERROR(BSL_LS_BCM_IFA, (BSL_META_U(unit,
    975                             "IFA(unit %d) Info: collector MTU \n"), unit));
    976             return BCM_E_PARAM;
    977         }
    978     } else {
    979         bcm_ifa_collector_info_t *collector_info_node = (&(ifa_collector_info[unit]));
    980         sal_memset(collector_info_node, 0, sizeof(bcm_ifa_collector_info_t));
    981     }
    982 
    983     buffer_req      = ifa_info->dma_buffer;
    984     buffer_ptr      = shr_ifa_msg_ctrl_collector_info_pack(buffer_req, &collector_set_msg);
    985     buffer_len      = buffer_ptr - buffer_req;
    986 
    987     BCM_IF_ERROR_RETURN(_bcm_xgs5_ifa_msg_send_receive(unit, MOS_MSG_SUBCLASS_IFA_COLLECTOR_SET,
    988                                                        buffer_len, 0,
    989                                                        MOS_MSG_SUBCLASS_IFA_COLLECTOR_SET_REPLY,
    990                                                        &reply_len,
    991                                                        SHR_IFA_MAX_UC_MSG_TIMEOUT));
    992     return BCM_E_NONE;
    993 }
    994 
    995 /*
    996  * Function:
    997  *     bcm_xgs5_ifa_config_set
    998  * Purpose:
    999  *     Set a configuration information.
   1000  * Parameters:
   1001  *     unit          - (IN) BCM device number
   1002  *     config_info   - (IN) Configuration informatin.
   1003  * Returns:
   1004  *     BCM_E_XXX
   1005  */
   1006 int
   1007 bcm_xgs5_ifa_config_set(int unit,
   1008                         bcm_ifa_config_info_t *config_info)
   1009 {
   1010     bcm_ifa_config_info_t *config_info_node = (&(ifa_config_info[unit]));
   1011 
   1012     if (config_info_node->max_payload_length != 0) {
   1013         LOG_ERROR(BSL_LS_BCM_IFA, (BSL_META_U(unit,
   1014                   "IFA(unit %d) Info: already exists \n"), unit));
   1015         return BCM_E_EXISTS;
   1016     }
   1017 
   1018     sal_memcpy(config_info_node, config_info,
   1019                sizeof(bcm_ifa_config_info_t));
   1020 
   1021     LOG_DEBUG(BSL_LS_BCM_IFA, (BSL_META_U(unit,
   1022                     "IFA(unit %d) Info: %s \n"), unit, __FUNCTION__));
   1023     return (BCM_E_NONE);
   1024 }
   1025 
   1026 /*
   1027  * Function:
   1028  *     bcm_xgs5_ifa_config_modify
   1029  * Purpose:
   1030  *     Modify a configuration information.
   1031  * Parameters:
   1032  *     unit          - (IN) BCM device number
   1033  *     config_info   - (IN) Configuration informatin.
   1034  * Returns:
   1035  *     BCM_E_XXX
   1036  */
   1037 int
   1038 bcm_xgs5_ifa_config_modify(int unit,
   1039                            bcm_ifa_config_info_t *config_info)
   1040 {
   1041     bcm_ifa_config_info_t *config_info_node = (&(ifa_config_info[unit]));
   1042 
   1043     if (config_info_node->max_payload_length == 0) {
   1044         LOG_DEBUG(BSL_LS_BCM_IFA, (BSL_META_U(unit,
   1045                   "IFA(unit %d) Info: configuration does not exist"), unit));
   1046         return (BCM_E_NOT_FOUND);
   1047     }
   1048 
   1049     sal_memcpy(config_info_node, config_info,
   1050                sizeof(bcm_ifa_config_info_t));
   1051     return (BCM_E_NONE);
   1052 }
   1053 
   1054 /*
   1055  * Function:
   1056  *     bcm_xgs5_ifa_config_get
   1057  * Purpose:
   1058  *     Get a configuration information.
   1059  * Parameters:
   1060  *     unit          - (IN) BCM device number
   1061  *     config_info   - (OUT) Configuration informatin.
   1062  * Returns:
   1063  *     BCM_E_XXX
   1064  */
   1065 int
   1066 bcm_xgs5_ifa_config_get(int unit,
   1067                         bcm_ifa_config_info_t *config_info)
   1068 {
   1069     bcm_ifa_config_info_t *config_info_node = (&(ifa_config_info[unit]));
   1070 
   1071     if (config_info_node->max_payload_length == 0) {
   1072         LOG_DEBUG(BSL_LS_BCM_IFA, (BSL_META_U(unit,
   1073                   "IFA(unit %d) Info: configuration does not exist"), unit));
   1074         return (BCM_E_NOT_FOUND);
   1075     }
   1076 
   1077     sal_memcpy(config_info, (&(ifa_config_info[unit])),
   1078                sizeof(bcm_ifa_config_info_t));
   1079     return (BCM_E_NONE);
   1080 }
   1081 
   1082 int bcm_xgs5_ifa_eapp_config_info_msg(int unit,
   1083                                       bcm_ifa_config_info_t *config_info)
   1084 {
   1085     ifa_sdk_msg_ctrl_config_info_t config_info_msg;
   1086     _bcm_int_ifa_info_t *ifa_info = IFA_INFO_GET(unit);
   1087     uint8 *buffer_req = NULL, *buffer_ptr = NULL;
   1088     uint16 buffer_len = 0, reply_len = 0;
   1089     int rv = BCM_E_NONE;
   1090 
   1091     sal_memset(&config_info_msg, 0, sizeof(config_info_msg));
   1092     if (config_info->max_payload_length) {
   1093         bcm_port_t start_port = 1;
   1094         bcm_port_t last_port = 1;
   1095 
   1096         config_info_msg.probemarker_1       = config_info->probemarker_1;
   1097         config_info_msg.probemarker_2       = config_info->probemarker_2;
   1098         config_info_msg.device_id           = config_info->device_id;
   1099 
   1100 #if defined(BCM_TRIDENT3_SUPPORT)
   1101         if (SOC_IS_TRIDENT3(unit)) {
   1102             /* CANCUN INT header fields validation */
   1103             if (config_info->lb_port_1 < 66) {
   1104                 config_info_msg.lb_port_1       = config_info->lb_port_1;
   1105                 config_info_msg.lb_port_2       = config_info->lb_port_2;
   1106             } else {
   1107                 config_info_msg.lb_port_1       = config_info->lb_port_2;
   1108                 config_info_msg.lb_port_2       = config_info->lb_port_1;
   1109             }
   1110         }
   1111 #endif  /* BCM_TRIDENT3_SUPPORT */
   1112 
   1113 #if defined(BCM_MAVERICK2_SUPPORT)
   1114         if (SOC_IS_MAVERICK2(unit)) {
   1115             if (config_info->lb_port_1 < 63) {
   1116                 config_info_msg.lb_port_1       = config_info->lb_port_1;
   1117             } else {
   1118                 config_info_msg.lb_port_1       = config_info->lb_port_2;
   1119             }
   1120         }
   1121 #endif  /* BCM_MAVERICK2_SUPPORT */
   1122 
   1123         config_info_msg.module_id           = config_info->module_id;
   1124         config_info_msg.hop_limit           = config_info->hop_limit;
   1125         config_info_msg.optional_headers    = config_info->optional_headers;
   1126         config_info_msg.max_payload_length  = config_info->max_payload_length;
   1127         config_info_msg.rx_packet_payload_length   = config_info->rx_packet_payload_length;
   1128         config_info_msg.true_hop_count      = config_info->true_hop_count;
   1129 
   1130         /* SYNC Ingress Device port to Source Trunk Map Table */
   1131 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
   1132         if ((SOC_IS_TRIDENT3(unit)) || (SOC_IS_MAVERICK2(unit))) {
   1133             last_port = TRIDENT3_PHY_PORTS_PER_DEV;
   1134         }
   1135 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
   1136 
   1137         for (;start_port < last_port; ++start_port) {
   1138             rv = _bcm_xgs5_ifa_eapp_loopback_port_set(unit, start_port);
   1139             if (BCM_FAILURE(rv)) {
   1140                 LOG_DEBUG(BSL_LS_BCM_IFA, (BSL_META_U(unit,
   1141                           "IFA(unit %d) Info: start_port: %d not validate port "),
   1142                           unit, start_port));
   1143             }
   1144         }
   1145 
   1146         rv = _bcm_xgs5_ifa_eapp_int_encap_build_pack(unit,
   1147                         config_info, &config_info_msg);
   1148         if (BCM_FAILURE(rv)) {
   1149             return rv;
   1150         }
   1151 
   1152         rv = _bcm_xgs5_ifa_eapp_lb_encap_build_pack(unit,
   1153                 config_info, &config_info_msg);
   1154         if (BCM_FAILURE(rv)) {
   1155             return rv;
   1156         }
   1157     } else {
   1158         bcm_ifa_config_info_t *config_info_node = (&(ifa_config_info[unit]));
   1159         sal_memset(config_info_node, 0, sizeof(bcm_ifa_config_info_t));
   1160     }
   1161 
   1162     buffer_req      = ifa_info->dma_buffer;
   1163     buffer_ptr      = ifa_sdk_msg_ctrl_config_info_pack(buffer_req,
   1164                                                         &config_info_msg);
   1165     buffer_len      = buffer_ptr - buffer_req;
   1166 
   1167     BCM_IF_ERROR_RETURN(_bcm_xgs5_ifa_msg_send_receive(unit, MOS_MSG_SUBCLASS_IFA_CONFIG_SET,
   1168                                                        buffer_len, 0,
   1169                                                        MOS_MSG_SUBCLASS_IFA_CONFIG_SET_REPLY,
   1170                                                        &reply_len,
   1171                                                        SHR_IFA_MAX_UC_MSG_TIMEOUT));
   1172     return BCM_E_NONE;
   1173 }
   1174 
   1175 int bcm_xgs5_ifa_eapp_collector_info_get_msg(int unit,
   1176                                              bcm_ifa_collector_info_t *collector_info)
   1177 {
   1178     shr_ifa_msg_ctrl_collector_info_t collector_msg;
   1179     _bcm_int_ifa_info_t *ifa_info = IFA_INFO_GET(unit);
   1180     uint8 *buffer_req = NULL, *buffer_ptr = NULL;
   1181     uint16 buffer_len = 0, reply_len = 0, i;
   1182 
   1183     if (collector_info == NULL) {
   1184         return BCM_E_PARAM;
   1185     }
   1186 
   1187     sal_memset(collector_info, 0, sizeof(bcm_ifa_collector_info_t));
   1188     sal_memset(&collector_msg, 0, sizeof(collector_msg));
   1189 
   1190     BCM_IF_ERROR_RETURN(_bcm_xgs5_ifa_msg_send_receive(unit, MOS_MSG_SUBCLASS_IFA_COLLECTOR_GET,
   1191                                                        buffer_len, 0,
   1192                                                        MOS_MSG_SUBCLASS_IFA_COLLECTOR_GET_REPLY, &reply_len,
   1193                                                        SHR_IFA_MAX_UC_MSG_TIMEOUT));
   1194     buffer_req      = ifa_info->dma_buffer;
   1195     buffer_ptr      = shr_ifa_msg_ctrl_collector_info_unpack(buffer_req, &collector_msg);
   1196     buffer_len      = buffer_ptr - buffer_req;
   1197 
   1198     collector_info->mtu        = collector_msg.mtu;
   1199     /* L2 ETH and VLAN TAG Headers */
   1200     /* Destination and Source MAC */
   1201     for (i = 0; i < SHR_MAC_ADDR_LENGTH; i++) {
   1202         collector_info->eth.dst_mac[i] = (uint8)collector_msg.encap[i];
   1203     }
   1204     for (i = 0; i < SHR_MAC_ADDR_LENGTH; i++) {
   1205         collector_info->eth.src_mac[i] = (uint8)collector_msg.encap[(i + 6)];
   1206     }
   1207 
   1208     collector_info->transport_type          =   collector_msg.transport_type;
   1209     collector_info->eth.outer_vlan_tag      =   collector_msg.outer_vlan_tag;
   1210     collector_info->eth.inner_vlan_tag      =   collector_msg.inner_vlan_tag;
   1211     collector_info->eth.outer_tpid          =   collector_msg.outer_tpid;
   1212     collector_info->eth.inner_tpid          =   collector_msg.inner_tpid;
   1213     collector_info->eth.vlan_tag_structure  =   collector_msg.vlan_tag_structure;
   1214 
   1215     /* L3 IPV6 Header */
   1216     if (collector_info->transport_type == bcmIfaCollectorTransportTypeIpv6Udp) {
   1217         collector_info->ipv6.traffic_class = (uint8)(((collector_msg.encap[collector_msg.ip_offset] & 0x0F) << 4) |
   1218                                                      ((collector_msg.encap[collector_msg.ip_offset + 1] & 0xF0) >> 4));
   1219         collector_info->ipv6.hop_limit  = (uint8)(collector_msg.encap[collector_msg.ip_offset + 7] & 0xFF);
   1220         collector_info->ipv6.flow_label = (uint32)(((collector_msg.encap[collector_msg.ip_offset + 1] & 0x0F) << 16) |
   1221                                                    ((collector_msg.encap[collector_msg.ip_offset + 2] & 0xFF) << 8)  |
   1222                                                    (collector_msg.encap[collector_msg.ip_offset + 3] & 0xFF));
   1223         /* Source and Destination IP */
   1224         for (i = 0; i < 16; i++) {
   1225             collector_info->ipv6.src_ip[i] = (uint8)(collector_msg.encap[(collector_msg.ip_offset + 8 + i)] & 0xFF);
   1226         }
   1227         for (i = 0; i < 16; i++) {
   1228             collector_info->ipv6.dst_ip[i] = (uint8)(collector_msg.encap[(collector_msg.ip_offset + 24 + i)] & 0xFF);
   1229         }
   1230     }
   1231 
   1232     /* L3 IPV4 Header */
   1233     if (collector_info->transport_type == bcmIfaCollectorTransportTypeIpv4Udp) {
   1234         collector_info->ipv4.dscp = (uint8)(collector_msg.encap[collector_msg.ip_offset + 1] & 0xFF);
   1235         collector_info->ipv4.ttl  = (uint8)(collector_msg.encap[collector_msg.ip_offset + 8] & 0xFF);
   1236         /* Source and Destination IP */
   1237         collector_info->ipv4.src_ip = (uint32)(((collector_msg.encap[(collector_msg.ip_offset + 12)] & 0xFF) << 24) |
   1238                                                ((collector_msg.encap[(collector_msg.ip_offset + 13)] & 0xFF) << 16) |
   1239                                                ((collector_msg.encap[(collector_msg.ip_offset + 14)] & 0xFF) << 8) |
   1240                                                ((collector_msg.encap[(collector_msg.ip_offset + 15)] & 0xFF)));
   1241         collector_info->ipv4.dst_ip = (uint32)(((collector_msg.encap[(collector_msg.ip_offset + 16)] & 0xFF) << 24) |
   1242                                                ((collector_msg.encap[(collector_msg.ip_offset + 17)] & 0xFF) << 16) |
   1243                                                ((collector_msg.encap[(collector_msg.ip_offset + 18)] & 0xFF) << 8) |
   1244                                                ((collector_msg.encap[(collector_msg.ip_offset + 19)] & 0xFF)));
   1245     }
   1246 
   1247     /* L4 UDP Header */
   1248     collector_info->udp.src_port    =   (bcm_l4_port_t)(((collector_msg.encap[collector_msg.udp_offset] & 0xFF) << 8) |
   1249                                                         (collector_msg.encap[(collector_msg.udp_offset + 1)] & 0xFF));
   1250     collector_info->udp.dst_port    =   (bcm_l4_port_t)(((collector_msg.encap[(collector_msg.udp_offset + 2)] & 0xFF) << 8) |
   1251                                                         (collector_msg.encap[(collector_msg.udp_offset + 3)] & 0xFF));
   1252     return BCM_E_NONE;
   1253 }
   1254 
   1255 int bcm_xgs5_ifa_eapp_config_info_get_msg(int unit,
   1256                                           bcm_ifa_config_info_t *config_info)
   1257 {
   1258     ifa_sdk_msg_ctrl_config_info_t config_info_msg;
   1259     _bcm_int_ifa_info_t *ifa_info = IFA_INFO_GET(unit);
   1260     uint8 *buffer_req = NULL, *buffer_ptr = NULL;
   1261     uint16 buffer_len = 0, reply_len = 0;
   1262 
   1263     if (config_info == NULL) {
   1264         return BCM_E_PARAM;
   1265     }
   1266 
   1267     sal_memset(config_info, 0, sizeof(bcm_ifa_config_info_t));
   1268     sal_memset(&config_info_msg, 0, sizeof(config_info_msg));
   1269 
   1270     BCM_IF_ERROR_RETURN(_bcm_xgs5_ifa_msg_send_receive(unit, MOS_MSG_SUBCLASS_IFA_CONFIG_GET,
   1271                                                        buffer_len, 0,
   1272                                                        MOS_MSG_SUBCLASS_IFA_CONFIG_GET_REPLY, &reply_len,
   1273                                                        SHR_IFA_MAX_UC_MSG_TIMEOUT));
   1274     buffer_req      = ifa_info->dma_buffer;
   1275     buffer_ptr      = ifa_sdk_msg_ctrl_config_info_unpack(buffer_req,
   1276                                                           &config_info_msg);
   1277     buffer_len      = buffer_ptr - buffer_req;
   1278 
   1279     config_info->probemarker_1       = config_info_msg.probemarker_1;
   1280     config_info->probemarker_2       = config_info_msg.probemarker_2;
   1281     config_info->device_id           = config_info_msg.device_id;
   1282     config_info->module_id           = config_info_msg.module_id;
   1283     config_info->hop_limit           = config_info_msg.hop_limit;
   1284     config_info->optional_headers    = config_info_msg.optional_headers;
   1285     config_info->lb_port_1           = config_info_msg.lb_port_1;
   1286     config_info->lb_port_2           = config_info_msg.lb_port_2;
   1287     config_info->max_payload_length  = config_info_msg.max_payload_length;
   1288     config_info->rx_packet_payload_length   = config_info_msg.rx_packet_payload_length;
   1289     config_info->true_hop_count      = config_info_msg.true_hop_count;
   1290 
   1291     return BCM_E_NONE;
   1292 }
   1293 
   1294 int bcm_xgs5_ifa_eapp_stat_info_get_msg(int unit,
   1295         bcm_ifa_stat_info_t *stat_data)
   1296 {
   1297     shr_ifa_msg_ctrl_stat_info_t stat_data_msg;
   1298     _bcm_int_ifa_info_t *ifa_info = IFA_INFO_GET(unit);
   1299     uint8 *buffer_req = NULL, *buffer_ptr = NULL;
   1300     uint16 buffer_len = 0, reply_len = 0;
   1301 
   1302     sal_memset(stat_data, 0, sizeof(bcm_ifa_stat_info_t));
   1303     sal_memset(&stat_data_msg, 0, sizeof(stat_data_msg));
   1304 
   1305     BCM_IF_ERROR_RETURN(_bcm_xgs5_ifa_msg_send_receive(unit, MOS_MSG_SUBCLASS_IFA_STAT_GET,
   1306                                                        buffer_len, 0,
   1307                                                        MOS_MSG_SUBCLASS_IFA_STAT_GET_REPLY, &reply_len,
   1308                                                        SHR_IFA_MAX_UC_MSG_TIMEOUT));
   1309     buffer_req      = ifa_info->dma_buffer;
   1310     buffer_ptr      = shr_ifa_msg_ctrl_stat_info_unpack(buffer_req, &stat_data_msg);
   1311     buffer_len      = buffer_ptr - buffer_req;
   1312 
   1313     stat_data->rx_pkt_cnt                       = stat_data_msg.rx_pkt_cnt;
   1314     stat_data->tx_pkt_cnt                       = stat_data_msg.tx_pkt_cnt;
   1315     stat_data->ifa_no_config_drop               = stat_data_msg.ifa_no_config_drop;
   1316     stat_data->ifa_collector_not_present_drop   = stat_data_msg.ifa_collector_not_present_drop;
   1317     stat_data->ifa_hop_cnt_invalid_drop         = stat_data_msg.ifa_hop_cnt_invalid_drop;
   1318     stat_data->ifa_int_hdr_len_invalid_drop     = stat_data_msg.ifa_int_hdr_len_invalid_drop;
   1319     stat_data->ifa_pkt_size_invalid_drop        = stat_data_msg.ifa_pkt_size_invalid_drop;
   1320 
   1321     return BCM_E_NONE;
   1322 }
   1323 
   1324 int bcm_xgs5_ifa_eapp_stat_info_set_msg(int unit,
   1325         bcm_ifa_stat_info_t *stat_data)
   1326 {
   1327     shr_ifa_msg_ctrl_stat_info_t stat_data_msg;
   1328     _bcm_int_ifa_info_t *ifa_info = IFA_INFO_GET(unit);
   1329     uint8 *buffer_req = NULL, *buffer_ptr = NULL;
   1330     uint16 buffer_len = 0, reply_len = 0;
   1331 
   1332     sal_memset(&stat_data_msg, 0, sizeof(stat_data_msg));
   1333     stat_data_msg.rx_pkt_cnt                       = stat_data->rx_pkt_cnt;
   1334     stat_data_msg.tx_pkt_cnt                       = stat_data->tx_pkt_cnt;
   1335     stat_data_msg.ifa_no_config_drop               = stat_data->ifa_no_config_drop;
   1336     stat_data_msg.ifa_collector_not_present_drop   = stat_data->ifa_collector_not_present_drop;
   1337     stat_data_msg.ifa_hop_cnt_invalid_drop         = stat_data->ifa_hop_cnt_invalid_drop;
   1338     stat_data_msg.ifa_int_hdr_len_invalid_drop     = stat_data->ifa_int_hdr_len_invalid_drop;
   1339     stat_data_msg.ifa_pkt_size_invalid_drop        = stat_data->ifa_pkt_size_invalid_drop;
   1340 
   1341     buffer_req      = ifa_info->dma_buffer;
   1342     buffer_ptr      = shr_ifa_msg_ctrl_stat_info_pack(buffer_req, &stat_data_msg);
   1343     buffer_len      = buffer_ptr - buffer_req;
   1344 
   1345     BCM_IF_ERROR_RETURN(_bcm_xgs5_ifa_msg_send_receive(unit, MOS_MSG_SUBCLASS_IFA_STAT_SET,
   1346                                                        buffer_len, 0,
   1347                                                        MOS_MSG_SUBCLASS_IFA_STAT_SET_REPLY, &reply_len,
   1348                                                        SHR_IFA_MAX_UC_MSG_TIMEOUT));
   1349     return BCM_E_NONE;
   1350 }
   1351 #else
   1352 typedef int bcm_make_iso_compilers_happy;
   1353 #endif /* INCLUDE_IFA */