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

pkt.h (73920B)


      1 /*
      2  * 
      3  * 
      4  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5  * 
      6  * Copyright 2007-2020 Broadcom Inc. All rights reserved.
      7  *
      8  */
      9 
     10 #ifndef __BCM_PKT_H__
     11 #define __BCM_PKT_H__
     12 
     13 #include <shared/rx.h>
     14 #include <shared/pkt.h>
     15 #include <bcm/types.h>
     16 #include <bcm/vlan.h>
     17 
     18 /* Default TX and RX DMA channels for the BCM layer. */
     19 #define BCM_TX_CHAN_DFLT        0          
     20 #define BCM_RX_CHAN_DFLT        1          
     21 
     22 /* Minimum packet allocation:  MAC addresses, VLAN tag, CRC. */
     23 #define BCM_PKT_ALLOC_MIN       (12 + 4 + 4) 
     24 
     25 /* 
     26  * IEEE header:  MAC addresses + VLAN tag; does not include type/len
     27  * field.
     28  */
     29 #define BCM_IEEE_HDR_BYTES      (12 + 4)   
     30 
     31 /* 
     32  * The packet structure. The packet layout is as follows:
     33  * 
     34  *   DMAC + SMAC     12 bytes
     35  *   VLAN tag         4 bytes (may be filled in by SW on BCM5670/75)
     36  *   payload          N bytes
     37  *   CRC              4 bytes
     38  *   pad              M bytes
     39  *   SL tag           4 bytes (may be unused)
     40  *   HiGig Header    12 bytes (may be unused)
     41  * 
     42  * The rule is: alloc_len = 12 + 4 + N + 4 + M + 4 + 12 (all of above).
     43  * payload_len (below) is N.
     44  * 
     45  * Note that the payload may grow until M == 0; the CRC moves. The SL and
     46  * HiGig headers will not move.
     47  * 
     48  * The "IEEE packet" is everything from the DMAC through the CRC
     49  * (inclusive), not including SL tag or HiGig header.
     50  * 
     51  * Scatter/gather is used to put the data into the right positions on
     52  * transmit and receive. The SL/HiGig headers are parsed on RX into data
     53  * members in the packet structure. On TX, bcm_tx will send the packet
     54  * according to the unit type. It will not check or affect any fields
     55  * except maybe the CRC. Other routines will be provided to ensure the
     56  * HiGig and SL tags are properly set up from the data in the packet
     57  * structure.
     58  */
     59 typedef struct bcm_pkt_s bcm_pkt_t;
     60 
     61 /* bcm_pkt_cb_f */
     62 typedef void (*bcm_pkt_cb_f)(
     63     int unit, 
     64     bcm_pkt_t *pkt, 
     65     void *cookie);
     66 
     67 /* BCM packet gather block type. */
     68 typedef struct bcm_pkt_blk_s {
     69     uint8 *data; 
     70     int len; 
     71 } bcm_pkt_blk_t;
     72 
     73 /* Set of 'reasons' (see bcmRxReason*) why a packet came to the CPU. */
     74 typedef _shr_rx_reasons_t bcm_rx_reasons_t;
     75 
     76 /* Stacking header packet forwarding options. */
     77 typedef enum bcm_pkt_stk_forward_e {
     78     BCM_PKT_STK_FORWARD_CPU = 0,        /* Stacking header packet forwarding
     79                                            option: to Host CPU. */
     80     BCM_PKT_STK_FORWARD_L2_UNICAST = 1, /* Stacking header packet forwarding
     81                                            option: Unicast L2. */
     82     BCM_PKT_STK_FORWARD_L3_UNICAST = 2, /* Stacking header packet forwarding
     83                                            option: Unicast L3. */
     84     BCM_PKT_STK_FORWARD_L2_MULTICAST = 3, /* Stacking header packet forwarding
     85                                            option: Multicast L2. */
     86     BCM_PKT_STK_FORWARD_L2_MULTICAST_UNKNOWN = 4, /* Stacking header packet forwarding
     87                                            option: Unknown Multicast L2. */
     88     BCM_PKT_STK_FORWARD_L3_MULTICAST = 5, /* Stacking header packet forwarding
     89                                            option: Multicast L3. */
     90     BCM_PKT_STK_FORWARD_L3_MULTICAST_UNKNOWN = 6, /* Stacking header packet forwarding
     91                                            option: Unknown Multicast L3. */
     92     BCM_PKT_STK_FORWARD_L2_UNICAST_UNKNOWN = 7, /* Stacking header packet forwarding
     93                                            option: Unknown Unicast L2. */
     94     BCM_PKT_STK_FORWARD_BROADCAST = 8,  /* Stacking header packet forwarding
     95                                            option: Broadcast. */
     96     BCM_PKT_STK_FORWARD_MPLS = 9,       /* Stacking header packet forwarding
     97                                            option: MPLS. */
     98     BCM_PKT_STK_FORWARD_TRILL = 10,     /* Stacking header packet forwarding
     99                                            option: TRILL. */
    100     BCM_PKT_STK_FORWARD_FCOE = 11,      /* Stacking header packet forwarding
    101                                            option: FCoE. */
    102     BCM_PKT_STK_FORWARD_SNOOP = 12,     /* Stacking header packet forwarding
    103                                            option: Snoop. */
    104     BCM_PKT_STK_FORWARD_TRAFFIC_MANAGEMENT = 13, /* Stacking header packet forwarding
    105                                            option: Traffic Management. */
    106     BCM_PKT_STK_FORWARD_COUNT = 14      /* Must be last. */
    107 } bcm_pkt_stk_forward_t;
    108 
    109 /* Decap Tunnel Types */
    110 typedef enum bcm_rx_decap_tunnel_e {
    111     bcmRxDecapNone = _SHR_RX_DECAP_NONE, /* No tunnel Decap */
    112     bcmRxDecapAccessSVP = _SHR_RX_DECAP_ACCESS_SVP, /* Packet ingress on Access SVP (No
    113                                            decap) */
    114     bcmRxDecapMIM = _SHR_RX_DECAP_MIM,  /* Decap Mac-in-Mac tunnel */
    115     bcmRxDecapL2GRE = _SHR_RX_DECAP_L2GRE, /* Decap L2GRE tunnel */
    116     bcmRxDecapVXLAN = _SHR_RX_DECAP_VXLAN, /* Decap VXLAN tunnel */
    117     bcmRxDecapAMT = _SHR_RX_DECAP_AMT,  /* Decap AMT tunnel */
    118     bcmRxDecapIP = _SHR_RX_DECAP_IP,    /* Decap IP tunnel */
    119     bcmRxDecapTRILL = _SHR_RX_DECAP_TRILL, /* Decap TRILL tunnel */
    120     bcmRxDecapMPLS1LABEL = _SHR_RX_DECAP_MPLS_1LABEL, /* Decap MPLS 1 Label, no Control Word */
    121     bcmRxDecapL2MPLS1LABEL = _SHR_RX_DECAP_L2MPLS_1LABEL, /* Decap MPLS 1 Label, L2 payload, no
    122                                            Control Word */
    123     bcmRxDecapMPLS2LABEL = _SHR_RX_DECAP_MPLS_2LABEL, /* Decap MPLS 2 Label, no Control Word */
    124     bcmRxDecapL2MPLS2LABEL = _SHR_RX_DECAP_L2MPLS_2LABEL, /* Decap MPLS 2 Label, L2 payload, no
    125                                            Control Word */
    126     bcmRxDecapMPLS1LABELCW = _SHR_RX_DECAP_MPLS_1LABELCW, /* Decap MPLS 1 Label, Control Word
    127                                            present */
    128     bcmRxDecapL2MPLS1LABELCW = _SHR_RX_DECAP_L2MPLS_1LABELCW, /* Decap MPLS 1 Label, L2 payload,
    129                                            Control Word present */
    130     bcmRxDecapMPLS2LABELCW = _SHR_RX_DECAP_MPLS_2LABELCW, /* Decap MPLS 2 Label, Control Word
    131                                            present */
    132     bcmRxDecapL2MPLS2LABELCW = _SHR_RX_DECAP_L2MPLS_2LABELCW, /* Decap MPLS 2 Label, L2 payload,
    133                                            Control Word present */
    134     bcmRxDecapL3MPLS1LABEL = _SHR_RX_DECAP_L3MPLS_1LABEL, /* Decap MPLS 1 Label, L3 payload, no
    135                                            Control Word present */
    136     bcmRxDecapL3MPLS2LABEL = _SHR_RX_DECAP_L3MPLS_2LABEL, /* Decap MPLS 2 Label, L3 payload, no
    137                                            Control Word present */
    138     bcmRxDecapL3MPLS1LABELCW = _SHR_RX_DECAP_L3MPLS_1LABELCW, /* Decap MPLS 1 Label, L3 payload,
    139                                            Control Word present */
    140     bcmRxDecapL3MPLS2LABELCW = _SHR_RX_DECAP_L3MPLS_2LABELCW, /* Decap MPLS 2 Label, L3 payload,
    141                                            Control Word present */
    142     bcmRxDecapWTP2AC = _SHR_RX_DECAP_WTP2AC, /* Decap WTP2AC Tunnel */
    143     bcmRxDecapAC2AC = _SHR_RX_DECAP_AC2AC, /* Decap AC2AC Tunnel */
    144     bcmRxDecapMPLS3LABEL = _SHR_RX_DECAP_MPLS_3LABEL, /* Decap MPLS 3 Label, no Control Word
    145                                            present */
    146     bcmRxDecapMPLS3LABELCW = _SHR_RX_DECAP_MPLS_3LABELCW, /* Decap MPLS 3 Label, Control Word
    147                                            present */
    148     bcmRxDecapMPLS3LABELENTROPYLABEL = _SHR_RX_DECAP_MPLS_3LABEL_ENTROPY, /* Decap MPLS 3 Label + entropy, no
    149                                            Control Word */
    150     bcmRxDecapMPLS3LABELENTROPYLABELCW = _SHR_RX_DECAP_MPLS_3LABEL_ENTROPYCW, /* Decap MPLS 3 Label + entropy, Control
    151                                            Word present */
    152     bcmRxDecapCount = _SHR_RX_DECAP_COUNT /* Decap Tunnel Max */
    153 } bcm_rx_decap_tunnel_t;
    154 
    155 /* Packet Headers Decapped after Ingress */
    156 typedef enum bcm_rx_decap_hdr_e {
    157     bcmRxDecapHdrNone = _SHR_RX_DECAP_HDR_NONE, /* No headers Decapped */
    158     bcmRxDecapSystemHdr = _SHR_RX_DECAP_SYSTEM_HDR, /* Decap System Header */
    159     bcmRxDecapOuterL2Hdr = _SHR_RX_DECAP_OUTER_L2_HDR, /* Decap Outer L2 Header */
    160     bcmRxDecapL3L4TunnelHdr = _SHR_RX_DECAP_L3_L4_TUNNEL_HDR, /* Decap Outer L3/L4/TUNNEL Header */
    161     bcmRxDecapInnerL2Hdr = _SHR_RX_DECAP_INNER_L2_HDR, /* Decap Inner L2 Header */
    162     bcmRxDecapInnerL3L4Hdr = _SHR_RX_DECAP_INNER_L3_L4_HDR /* Decap Inner L3 and L4 Header */
    163 } bcm_rx_decap_hdr_t;
    164 
    165 /* OAM DM timestamp options. */
    166 typedef enum bcm_pkt_timestamp_mode_e {
    167     BCM_PKT_TIMESTAMP_MODE_NONE = 0,    /* No Timestamp */
    168     BCM_PKT_TIMESTAMP_MODE_PTP = 1,     /* Timestamp mode - PTP. */
    169     BCM_PKT_TIMESTAMP_MODE_NTP = 2,     /* Timestamp mode - NTP. */
    170     BCM_PKT_TIMESTAMP_MODE_NUM = 3      /* Max value - Not to be used */
    171 } bcm_pkt_timestamp_mode_t;
    172 
    173 /* OAM LM counter options. */
    174 typedef enum bcm_pkt_oam_lm_counter_mode_e {
    175     BCM_PKT_OAM_LM_COUNTER_MODE_NONE = 0, /* No LM counter operation */
    176     BCM_PKT_OAM_LM_COUNTER_MODE_INCREMENT = 1, /* Increment LM counter. */
    177     BCM_PKT_OAM_LM_COUNTER_MODE_SAMPLE = 2, /* Sample LM counter. */
    178     BCM_PKT_OAM_LM_COUNTER_MODE_NUM = 3 /* Max value - Not to be used */
    179 } bcm_pkt_oam_lm_counter_mode_t;
    180 
    181 /* OAM Pkt Type */
    182 typedef enum bcm_pkt_rx_oam_type_e {
    183     bcmPktRxOamTypeNone = 0,            /* Not OAM pkt */
    184     bcmPktRxOamTypeBfdOam = 1,          /* BFD OAM packet */
    185     bcmPktRxOamTypeEthOamCcm = 2,       /* Ethernet OAM Down MEP CCM packet */
    186     bcmPktRxOamTypeEthOamLm = 3,        /* Ethernet OAM Down MEP LM packet */
    187     bcmPktRxOamTypeEthOamDm = 4,        /* Ethernet OAM Down MEP DM packet */
    188     bcmPktRxOamTypeEthOamOther = 5,     /* Ethernet OAM Down MEP other opcode
    189                                            packet */
    190     bcmPktRxOamTypeBhhOamCcm = 6,       /* BHH OAM CCM packet */
    191     bcmPktRxOamTypeBhhOamLm = 7,        /* BHH OAM LM packet */
    192     bcmPktRxOamTypeBhhOamDm = 8,        /* BHH OAM DM packet */
    193     bcmPktRxOamTypeBhhOamOther = 9,     /* BHH OAM other opcode packet */
    194     bcmPktRxOamTypeRfc6374Dlm = 10,     /* MPLS LM/DM  DLM packet */
    195     bcmPktRxOamTypeRfc6374Dm = 11,      /* MPLS LM/DM  DM packet */
    196     bcmPktRxOamTypeRfc6374DlmPlusDm = 12, /* MPLS LM/DM  DLM + DM packet */
    197     bcmPktRxOamTypeRfc6374Ilm = 13,     /* MPLS LM/DM  ILM packet */
    198     bcmPktRxOamTypeRfc6374IlmPlusDm = 14, /* MPLS LM/DM  ILM + DM packet */
    199     bcmPktRxOamTypeSat = 15,            /* Service Activation Test */
    200     bcmPktRxOamTypeOtherAch = 16,       /* OAM packets with other ACH types */
    201     bcmPktRxOamTypeEthOamUpMepCcm = 17, /* Ethernet OAM Up MEP CCM packet */
    202     bcmPktRxOamTypeEthOamUpMepLm = 18,  /* Ethernet OAM Up MEP LM packet */
    203     bcmPktRxOamTypeEthOamUpMepDm = 19,  /* Ethernet OAM Up MEP DM packet */
    204     bcmPktRxOamTypeEthOamUpMepOther = 20, /* Ethernet OAM Up MEP other opcode
    205                                            packet */
    206     bcmPktRxOamTypeUpSat = 21,          /* Up Service Activation Test packet */
    207     bcmPktRxOamTypeCount = 22           /* Max value - Not to be used */
    208 } bcm_pkt_rx_oam_type_t;
    209 
    210 /* OAM counter object ID */
    211 typedef enum bcm_pkt_oam_counter_object_e {
    212     bcmOamCounterObjectNone = 0,        /* Invalid counter object */
    213     bcmOamCounterObjectEndpointId = 1,  /* OAM counter object id */
    214     bcmOamCounterObjectFlexStatId = 2   /* OAM counter flex stats ID */
    215 } bcm_pkt_oam_counter_object_t;
    216 
    217 /* Indicates how the packet was forwarded. */
    218 typedef enum bcm_pkt_forwarding_type_e {
    219     BCM_PKT_L2_FORWARD = 0, /* Ethernet/NIV/HiGig forwarded. */
    220     BCM_PKT_L3UC = 1,       /* L3 UC forwarded. */
    221     BCM_PKT_L2L3 = 2        /* Bridge routed. */
    222 } bcm_pkt_forwarding_type_t;
    223 
    224 /* OAM counter */
    225 typedef struct bcm_pkt_oam_counter_s {
    226     bcm_pkt_oam_counter_object_t counter_object; /* OAM counter object type */
    227     uint32 counter_object_id;           /* Counter Object Id */
    228     uint32 counter_offset;              /* Offset from start of counter group */
    229     bcm_pkt_oam_lm_counter_mode_t counter_mode; /* Counter mode during Tx */
    230     uint32 counter_value_upper;         /* Upper 32 bit of OAM LM Counter in Rx
    231                                            Pkt */
    232     uint32 counter_value_lower;         /* Lower 32 bit of OAM LM Counter in Rx
    233                                            Pkt */
    234     uint32 oam_lm_byte_count_offset;    /* Offset to start byte counting */
    235 } bcm_pkt_oam_counter_t;
    236 
    237 /* OAM counter max object */
    238 #define BCM_PKT_OAM_COUNTER_MAX 3          
    239 
    240 /* Rx path definitions */
    241 #define BCM_RX_PATH_SWITCHED    (1 << 0)   
    242 #define BCM_RX_PATH_COPY_TO_CPU (1 << 1)   
    243 #define BCM_RX_PATH_MIRRORED    (1 << 2)   
    244 
    245 /* DNX internal header stack array size */
    246 #define BCM_PKT_NOF_DNX_HEADERS _SHR_PKT_NOF_DNX_HEADERS 
    247 
    248 /* Pkt DNX types. */
    249 typedef enum bcm_pkt_dnx_type_e {
    250     bcmPktDnxTypeItmh = _SHR_PKT_DNX_TYPE_ITMH, /* ITMH Header. */
    251     bcmPktDnxTypeFtmh = _SHR_PKT_DNX_TYPE_FTMH, /* FMTH Header. */
    252     bcmPktDnxTypeOtsh = _SHR_PKT_DNX_TYPE_OTSH, /* OAM-TS Header (OTSH). */
    253     bcmPktDnxTypeOtmh = _SHR_PKT_DNX_TYPE_OTMH, /* OTMH Header. */
    254     bcmPktDnxTypeInternals = _SHR_PKT_DNX_TYPE_INTERNALS /* Dnx Internal fields. */
    255 } bcm_pkt_dnx_type_t;
    256 
    257 /* itmh dest type. */
    258 typedef enum bcm_pkt_dnx_itmh_dest_type_e {
    259     bcmPktDnxItmhDestTypeMulticast = _SHR_PKT_DNX_ITMH_DEST_TYPE_MULTICAST, /* ITMH destination type is multicast. */
    260     bcmPktDnxItmhDestTypeFlow = _SHR_PKT_DNX_ITMH_DEST_TYPE_FLOW, /* ITMH destination type is flow. */
    261     bcmPktDnxItmhDestTypeIngressShapingFlow = _SHR_PKT_DNX_ITMH_DEST_TYPE_INGRESS_SHAPING_FLOW, /* ITMH destination type is ingress
    262                                            shaping flow. */
    263     bcmPktDnxItmhDestTypeVport = _SHR_PKT_DNX_ITMH_DEST_TYPE_VPORT, /* ITMH destination type is out lif. */
    264     bcmPktDnxItmhDestTypeSystemPort = _SHR_PKT_DNX_ITMH_DEST_TYPE_SYSTEM_PORT /* ITMH destination type is system port. */
    265 } bcm_pkt_dnx_itmh_dest_type_t;
    266 
    267 /* Itmh destination. */
    268 typedef struct bcm_pkt_dnx_itmh_dest_s {
    269     bcm_pkt_dnx_itmh_dest_type_t dest_type; /* Destination type */
    270     bcm_pkt_dnx_itmh_dest_type_t dest_extension_type; /* Destination Extension type */
    271     bcm_gport_t destination;            /* Destination Gport */
    272     bcm_multicast_t multicast_id;       /* Destination multicast */
    273     bcm_gport_t destination_ext;        /* Destination-Extension Gport */
    274 } bcm_pkt_dnx_itmh_dest_t;
    275 
    276 /* Itmh */
    277 typedef struct bcm_pkt_dnx_itmh_s {
    278     uint8 inbound_mirror_disable;   /* If set, disable inbound mirroring
    279                                        (ITMH.IN_MIRR_DISABLE) */
    280     uint32 snoop_cmnd;              /* snoop command (ITMH.SNOOP_CMD) */
    281     uint32 prio;                    /* Traffic Class (ITMH.FWD_TRAFFIC_CLASS) */
    282     bcm_color_t color;              /* Color (aka Drop precedence, ITMH.FWD_DP) */
    283     bcm_pkt_dnx_itmh_dest_t dest;   /* Destination information */
    284 } bcm_pkt_dnx_itmh_t;
    285 
    286 /* ftmh action type. */
    287 typedef enum bcm_pkt_dnx_ftmh_action_type_e {
    288     bcmPktDnxFtmhActionTypeForward = _SHR_PKT_DNX_FTMH_ACTION_TYPE_FORWARD, /* TM action is forward */
    289     bcmPktDnxFtmhActionTypeSnoop = _SHR_PKT_DNX_FTMH_ACTION_TYPE_SNOOP, /* TM action is snoop */
    290     bcmPktDnxFtmhActionTypeInboundMirror = _SHR_PKT_DNX_FTMH_ACTION_TYPE_INBOUND_MIRROR, /* TM action is inbound mirror. */
    291     bcmPktDnxFtmhActionTypeOutboundMirror = _SHR_PKT_DNX_FTMH_ACTION_TYPE_OUTBOUND_MIRROR, /* TM action is outbound mirror. */
    292     bcmPktDnxFtmhActionTypeMirror = _SHR_PKT_DNX_FTMH_ACTION_TYPE_MIRROR, /* TM action is mirror. */
    293     bcmPktDnxFtmhActionTypeStatisticalSampling = _SHR_PKT_DNX_FTMH_ACTION_TYPE_STATISTICAL_SAMPLING /* TM action is statistical sampling. */
    294 } bcm_pkt_dnx_ftmh_action_type_t;
    295 
    296 /* ftmh lb extension. */
    297 typedef struct bcm_pkt_dnx_ftmh_lb_extension_s {
    298     uint8 valid;    /* Set if the extension is present */
    299     uint32 lb_key;  /* Load Balancing Key (FTMH.LB-Key) */
    300 } bcm_pkt_dnx_ftmh_lb_extension_t;
    301 
    302 /* ftmh dest extension. */
    303 typedef struct bcm_pkt_dnx_ftmh_dest_extension_s {
    304     uint8 valid;                /* Set if the extension is present */
    305     bcm_gport_t dst_sysport;    /* Destination System Port
    306                                    (FTMH.Destination-Sys-Port)) */
    307 } bcm_pkt_dnx_ftmh_dest_extension_t;
    308 
    309 /* ftmh stack extension. */
    310 typedef struct bcm_pkt_dnx_ftmh_stack_extension_s {
    311     uint8 valid;                    /* Set if the extension is present */
    312     uint32 stack_route_history_bmp; /* Route bitmap to prevent loops in stacking
    313                                        system
    314                                        (FTMH.Stacking-Route-History-Bitmap) */
    315 } bcm_pkt_dnx_ftmh_stack_extension_t;
    316 
    317 /* ASE type. */
    318 typedef enum bcm_pkt_dnx_ase_type_e {
    319     bcmPktDnxAseTypeNone = 0,           /* Ase type is None */
    320     bcmPktDnxAseTypeTrajectoryTrace = 1, /* Ase type is Trajectory trace */
    321     bcmPktDnxAseTypeErspan = 2,         /* Ase type is ERSPAN */
    322     bcmPktDnxAseTypeSFlow = 3,          /* Ase type is sFlow */
    323     bcmPktDnxAseTypeMirrorOnDrop = 4,   /* Ase type is Mirror-On-Drop */
    324     bcmPktDnxAseTypeInt = 5             /* Ase type is Inband Network Telemetry */
    325 } bcm_pkt_dnx_ase_type_t;
    326 
    327 /* ERSPAN header information */
    328 typedef struct bcm_pkt_dnx_erspan_info_s {
    329     uint8 direction;        /* Direction: 0x0-incoming, 0x1-outgoing */
    330     uint8 truncated_flag;   /* Truncated field in ERSPAN header. 0x1-it means
    331                                the frame copy encapsulated in the ERSPAN packet
    332                                will be truncated; 0x0-not truncated */
    333     uint8 en;               /* The trunk encapsulation type */
    334     uint8 cos;              /* Class of service */
    335     uint16 vlan;            /* Vlan */
    336 } bcm_pkt_dnx_erspan_info_t;
    337 
    338 /* Ase information */
    339 typedef struct bcm_pkt_dnx_ase_info_s {
    340     bcm_pkt_dnx_erspan_info_t erspan_info; /* ERSPAN header information */
    341     uint8 int_profile;                  /* Inband Network Telemetry profile */
    342 } bcm_pkt_dnx_ase_info_t;
    343 
    344 /* ftmh application specific extension. */
    345 typedef struct bcm_pkt_dnx_ftmh_ase_extension_s {
    346     uint8 valid;                        /* Set if the extension is present */
    347     bcm_pkt_dnx_ase_type_t ase_type;    /* Application Specific Extension type */
    348     bcm_pkt_dnx_ase_info_t ase_info;    /* Application Specific Extension
    349                                            information */
    350 } bcm_pkt_dnx_ftmh_ase_extension_t;
    351 
    352 /* ftmh flow_id extension. */
    353 typedef struct bcm_pkt_dnx_ftmh_flow_id_extension_s {
    354     uint8 valid;        /* Set if the extension is present */
    355     uint32 flow_id;     /* Flow-ID */
    356     uint8 flow_profile; /* Flow-Profile */
    357 } bcm_pkt_dnx_ftmh_flow_id_extension_t;
    358 
    359 /* ftmh */
    360 typedef struct bcm_pkt_dnx_ftmh_s {
    361     uint32 packet_size;                 /* Packet size in bytes
    362                                            (FTMH.Packet-Size) */
    363     uint32 prio;                        /* Traffic class (FTMH.Traffic-Class) */
    364     bcm_gport_t src_sysport;            /* Source System port
    365                                            (FTMH.Source-System-Port-Aggr) */
    366     bcm_gport_t dst_port;               /* Destination local port (FTMH.PP_DSP) */
    367     bcm_color_t ftmh_dp;                /* Drop precedence (FTMH.DP) */
    368     bcm_pkt_dnx_ftmh_action_type_t action_type; /* Action type (FTMH.TM-Action-Type) */
    369     uint8 out_mirror_disable;           /* Disable Outbound mirroring
    370                                            (FTMH.Out-Mirror-Disable) */
    371     uint8 is_mc_traffic;                /* Indicate if the traffic is multicast
    372                                            (FTMH.TM-Action-Is-Multicast) */
    373     bcm_multicast_t multicast_id;       /* Multicast ID (FTMH.Multicast-ID).
    374                                            Valid only if is_mc_traffic is set */
    375     bcm_gport_t out_vport;              /* Virtual port (FTMH.Out-LIF). Valid
    376                                            only if is_mc_traffic is unset */
    377     uint32 cni;                         /* Congestion indication (FTMH.CNI) */
    378     bcm_pkt_dnx_ftmh_lb_extension_t lb_ext; /* FTMH Load Balancing Key extension */
    379     bcm_pkt_dnx_ftmh_dest_extension_t dest_ext; /* FTMH Destination System Port
    380                                            Extension */
    381     bcm_pkt_dnx_ftmh_stack_extension_t stack_ext; /* FTMH Stacking extension
    382                                            (Stacking-Route-History-Bitmap) */
    383     bcm_pkt_dnx_ftmh_ase_extension_t ase_ext; /* FTMH Application Specific Extension */
    384     bcm_pkt_dnx_ftmh_flow_id_extension_t flow_id_ext; /* FTMH FLow-ID Extension */
    385 } bcm_pkt_dnx_ftmh_t;
    386 
    387 /* TSH header */
    388 typedef struct bcm_pkt_dnx_tsh_s {
    389     uint8 valid;    /* Set if TSH is present */
    390 } bcm_pkt_dnx_tsh_t;
    391 
    392 /* otsh type */
    393 typedef enum bcm_pkt_dnx_otsh_type_e {
    394     bcmPktDnxOtshTypeOam = _SHR_PKT_DNX_OTSH_TYPE_OAM, /* OAM-TS type is OAM */
    395     bcmPktDnxOtshType1588v2 = _SHR_PKT_DNX_OTSH_TYPE_1588v2, /* OAM-TS type is 1588v2 */
    396     bcmPktDnxOtshTypeReserved = _SHR_PKT_DNX_OTSH_TYPE_RESERVED, /* OAM-TS type is Reserved */
    397     bcmPktDnxOtshTypeLatency = _SHR_PKT_DNX_OTSH_TYPE_LATENCY /* OAM-TS type is packet latency */
    398 } bcm_pkt_dnx_otsh_type_t;
    399 
    400 /* otsh oam sutype */
    401 typedef enum bcm_pkt_dnx_otsh_oam_subtype_e {
    402     bcmPktDnxOtshOamSubtypeNone = _SHR_PKT_DNX_OTSH_OAM_SUBTYPE_NONE, /* None */
    403     bcmPktDnxOtshOamSubtypeLm = _SHR_PKT_DNX_OTSH_OAM_SUBTYPE_LM, /* Loss Measurement (LM) */
    404     bcmPktDnxOtshOamSubtypeDm1588 = _SHR_PKT_DNX_OTSH_OAM_SUBTYPE_DM1588, /* Delay Measurement (DM) - 1588 ToD */
    405     bcmPktDnxOtshOamSubtypeDmNtp = _SHR_PKT_DNX_OTSH_OAM_SUBTYPE_DM_NTP, /* Delay Measurement (DM) - NTP ToD */
    406     bcmPktDnxOtshOamSubtypeOamDefault = _SHR_PKT_DNX_OTSH_OAM_SUBTYPE_OAM_DEFAULT, /* Default OAM type */
    407     bcmPktDnxOtshOamSubtypeLoopback = _SHR_PKT_DNX_OTSH_OAM_SUBTYPE_LOOPBACK, /* Loopback */
    408     bcmPktDnxOtshOamSubtypeEcn = _SHR_PKT_DNX_OTSH_OAM_SUBTYPE_ECN /* ECN */
    409 } bcm_pkt_dnx_otsh_oam_subtype_t;
    410 
    411 /* otsh */
    412 typedef struct bcm_pkt_dnx_otsh_s {
    413     bcm_pkt_dnx_otsh_type_t otsh_type;  /* OAM-TS(Type). */
    414     bcm_pkt_dnx_otsh_oam_subtype_t oam_sub_type; /* OAM-TS(OAM-Sub-Type). Applies only
    415                                            when otsh_type is oam. */
    416     uint32 oam_up_mep;                  /* OAM-TS(MEP-Type). Applies only when
    417                                            otsh_type is oam. */
    418     uint32 tp_cmd;                      /* OAM-TS(TP-Cmd). Applies only when
    419                                            otsh_type is 1588. */
    420     uint8 ts_encap;                     /* OAM-TS(TS-Encaps). Applies only when
    421                                            otsh_type is 1588. */
    422     uint64 oam_ts_data;                 /* OAM-TS(OAM-TS-Data) */
    423     uint32 latency_flow_ID;             /* Latency flow ID generated by the PMF. */
    424     uint32 offset;                      /* OAM-TS(offset). Applies only when
    425                                            otsh_type is oam.. */
    426 } bcm_pkt_dnx_otsh_t;
    427 
    428 /* otmh src sysport extension */
    429 typedef struct bcm_pkt_dnx_otmh_src_sysport_extension_s {
    430     uint8 valid;                /* Set if the extension is present */
    431     bcm_gport_t src_sysport;    /* Source System Port (OTMH.Source-System-Port) */
    432 } bcm_pkt_dnx_otmh_src_sysport_extension_t;
    433 
    434 /* otmh vport extension */
    435 typedef struct bcm_pkt_dnx_otmh_vport_extension_s {
    436     uint8 valid;            /* Set if the extension is present */
    437     bcm_gport_t out_vport;  /* Virtual port (OTMH.Out-LIF/CUD) */
    438 } bcm_pkt_dnx_otmh_vport_extension_t;
    439 
    440 /* otmh */
    441 typedef struct bcm_pkt_dnx_otmh_s {
    442     bcm_pkt_dnx_ftmh_action_type_t action_type; /* Action type (OTMH.TM-Action-Type) */
    443     bcm_color_t ftmh_dp;                /* Drop precedence (OTMH.DP) */
    444     uint8 is_mc_traffic;                /* AIndicate if the traffic is multicast
    445                                            (OTMH.System-Multicast) */
    446     uint32 prio;                        /* Traffic class (OTMH.Traffic-Class) */
    447     bcm_gport_t dst_port;               /* Destination local port
    448                                            (OTMH.Destination-Port) */
    449     bcm_pkt_dnx_otmh_src_sysport_extension_t src_sysport_ext; /* OTMH Source System Port Extension */
    450     bcm_pkt_dnx_otmh_vport_extension_t out_vport_ext; /* OTMH Source System Port Extension */
    451 } bcm_pkt_dnx_otmh_t;
    452 
    453 /* Internals */
    454 typedef struct bcm_pkt_dnx_internal_s {
    455     uint32 forward_domain;  /* VSI for bridging, VRF for routing, VFT for FCoE,
    456                                etc */
    457     uint32 trap_qualifier;  /* Trap Qualifier */
    458     uint32 trap_id;         /* Trap Id */
    459 } bcm_pkt_dnx_internal_t;
    460 
    461 /* UDH header */
    462 typedef struct bcm_pkt_dnx_udh_s {
    463     uint8 size;     /* UDH size: 0/1/2/4 */
    464     uint32 data;    /* UDH data */
    465 } bcm_pkt_dnx_udh_t;
    466 
    467 /* dnx packet */
    468 typedef struct bcm_pkt_dnx_s {
    469     bcm_pkt_dnx_type_t type;            /* DNX Header type */
    470     bcm_pkt_dnx_itmh_t itmh;            /* ITMH Header */
    471     bcm_pkt_dnx_ftmh_t ftmh;            /* FTMH Header */
    472     bcm_pkt_dnx_otsh_t otsh;            /* OAM-TS Header (OTSH) */
    473     bcm_pkt_dnx_otmh_t otmh;            /* OTMH Header */
    474     bcm_pkt_dnx_internal_t internal;    /* Internal Header */
    475 } bcm_pkt_dnx_t;
    476 
    477 /* Initialize a BCM packet structure. */
    478 struct bcm_pkt_s { 
    479     bcm_pkt_blk_t *pkt_data;            /* Pointer to array of data blocks. */
    480     uint8 blk_count;                    /* Number of blocks in data array. */
    481     uint8 unit;                         /* Unit number. */
    482     uint8 cos;                          /* The local COS queue to use. */
    483     uint8 prio_int;                     /* Internal priority of the packet. */
    484     bcm_vlan_t vlan;                    /* 802.1q VID or VSI or VPN. */
    485     uint8 vlan_pri;                     /* Vlan tag priority . */
    486     uint8 vlan_cfi;                     /* Vlan tag CFI bit. */
    487     bcm_vlan_t inner_vlan;              /* Inner VID or VSI or VPN. */
    488     uint8 inner_vlan_pri;               /* Inner vlan tag priority . */
    489     uint8 inner_vlan_cfi;               /* Inner vlan tag CFI bit. */
    490     bcm_color_t color;                  /* Packet color. */
    491     int16 src_port;                     /* Source port used in header/tag. */
    492     bcm_trunk_t src_trunk;              /* Source trunk group ID used in
    493                                            header/tag, -1 if src_port set . */
    494     uint16 src_mod;                     /* Source module ID used in header/tag. */
    495     uint16 dest_port;                   /* Destination port used in header/tag. */
    496     uint16 dest_mod;                    /* Destination module ID used in
    497                                            header/tag. */
    498     uint8 opcode;                       /* BCM_HG_OPCODE_xxx. */
    499     bcm_gport_t dst_gport;              /* Destination virtual port */
    500     bcm_gport_t src_gport;              /* Source virtual port */
    501     bcm_multicast_t multicast_group;    /* Destination multicast group. */
    502     uint32 stk_flags;                   /* Stacking header flags. */
    503     bcm_pkt_stk_forward_t stk_forward;  /* Stacking header forwarding opcode. */
    504     uint32 stk_classification_tag;      /* Stacking header classification tag. */
    505     uint32 stk_pkt_prio;                /* Stacking header new packet priority. */
    506     uint32 stk_dscp;                    /* Stacking header new DSCP. */
    507     uint32 stk_load_balancing_number;   /* Stacking header load balancing
    508                                            number. */
    509     bcm_if_t stk_encap_id;              /* Stacking header encapsulation ID for
    510                                            remote packet replication. */
    511     uint16 pkt_len;                     /* Packet length according to flags. */
    512     uint16 tot_len;                     /* Packet length as transmitted or
    513                                            received. */
    514     bcm_pbmp_t tx_pbmp;                 /* Target ports. */
    515     bcm_pbmp_t tx_upbmp;                /* Untagged target ports. */
    516     bcm_pbmp_t tx_l3pbmp;               /* L3 ports. */
    517     bcm_port_t pkt_trace_src_port;      /* pkt_trace_src_port */
    518     uint8 pfm;                          /* BCM_PORT_PFM_xxx flags. */
    519     uint32 rx_reason;                   /* Opcode from packet. */
    520     bcm_rx_reasons_t rx_reasons;        /* Set of packet "reasons". */
    521     uint32 rx_path;                     /* Rx path of packet. */
    522     uint8 rx_unit;                      /* Local rx unit. */
    523     uint8 rx_port;                      /* Local rx port; not in HG hdr. */
    524     uint8 rx_cpu_cos;                   /* CPU may get pkt on diff cos. */
    525     uint8 rx_untagged;                  /* The packet was untagged on ingress. */
    526     uint32 rx_classification_tag;       /* Classification tag. */
    527     uint32 rx_matched;                  /* Field processor matched rule. */
    528     bcm_if_t rx_l3_intf;                /* L3 egress object interface ID. */
    529     bcm_vlan_action_t rx_outer_tag_action; /* Outer-tag action applied to packet. */
    530     bcm_vlan_action_t rx_inner_tag_action; /* Inner-tag action applied to packet. */
    531     uint32 rx_timestamp;                /* Time stamp of time sync protocol
    532                                            packets. */
    533     uint32 rx_timestamp_upper;          /* Upper 32-bit of 64-bit timestamp of
    534                                            OAM DM. */
    535     uint32 timestamp_flags;             /* Timestamp flags. */
    536     void *cookie;                       /* User data for callback. */
    537     void *cookie2;                      /* Additional user data for callback. */
    538     bcm_pkt_cb_f call_back;             /* Callback function. */
    539     uint32 flags;                       /* BCM_PKT_F_xxx flags. */
    540     void *next;                         /* When linked into lists. */
    541     int8 dma_channel;                   /* DMA channel used; may be -1. */
    542     bcm_pkt_blk_t _pkt_data;            /* For single block packets (internal). */
    543     bcm_pkt_t *_last_pkt;               /* To link to end of linked lists
    544                                            (internal). */
    545     void *_dv;                          /* DV controlling this packet
    546                                            (internal). */
    547     int8 _idx;                          /* Packet's index in the DV for RX
    548                                            (internal). */
    549     bcm_pkt_t *_next;                   /* For BCM layer linked lists
    550                                            (internal). */
    551     void *alloc_ptr;                    /* Pointer for deallocation (internal). */
    552     void *trans_ptr;                    /* Transport pointer associated with
    553                                            packet (internal). */
    554     uint8 _higig[16];                   /* HiGig header value (network byte
    555                                            order). */
    556     uint8 _pb_hdr[12];                  /* Pipe Bypass Header (network byte
    557                                            order). */
    558     uint8 _sltag[4];                    /* SL tag value (network byte order). */
    559     uint8 _vtag[4];                     /* VLAN tag if not in packet (network
    560                                            byte order). */
    561     uint8 _dpp_hdr[10];                 /* DPP header contents */
    562     int _dpp_hdr_type;                  /* DPP header and extensions type */
    563     int flow_id;                        /* Internal flow id. */
    564     uint32 filter_enable;               /* filters to be enabled. */
    565     bcm_pbmp_t _dv_tx_pbmp;             /* Actual pbmp assigned to tx
    566                                            descriptor(internal). */
    567     bcm_pbmp_t _dv_tx_upbmp;            /* Actual upbmp assigned to tx
    568                                            descriptor(internal). */
    569     uint32 flags2;                      /* BCM_PKT_F2_xxx flags. */
    570     uint8 oam_replacement_type;         /* OAM replacement type used in SOBMH
    571                                            header. */
    572     uint8 oam_replacement_offset;       /* OAM replacement offset used in SOBMH
    573                                            header. */
    574     uint16 oam_lm_counter_index;        /* OAM LM counter index used in SOBMH
    575                                            header. */
    576     uint32 rx_trap_data;                /* Additional trap information */
    577     void *_dcb;                         /* Pointer for dcb. */
    578     uint16 oam_lm_counter_index_2;      /* OAM Second LM counter index used in
    579                                            SOBMH header. */
    580     uint16 ma_ptr;                      /* OAM MA Pointer value. For BCM5645x,
    581                                            this corresponds to endpoint group
    582                                            index */
    583     bcm_pkt_timestamp_mode_t timestamp_mode; /* OAM DM timestamp mode */
    584     bcm_pkt_oam_lm_counter_mode_t counter_mode_1; /* OAM LM counter-1 mode */
    585     bcm_pkt_oam_lm_counter_mode_t counter_mode_2; /* OAM LM counter-2 mode */
    586     uint8 timestamp_offset;             /* Offset to place the timestamp in the
    587                                            packet. */
    588     bcm_rx_decap_tunnel_t rx_decap_tunnel; /* Tunnel Decap during packet rx */
    589     bcm_gport_t src_vport;              /* Source VPort (In-LIF) */
    590     bcm_gport_t dst_vport;              /* Destination VPort (Out-LIF) */
    591     uint32 fwd_hdr_offset;              /* Distance (in bytes) to forwarding
    592                                            header from start of packet */
    593     int snoop_cmnd;                     /* Snoop command */
    594     bcm_gport_t stk_dst_gport;          /* Stacking destination port */
    595     uint32 stk_route_tm_domains;        /* Bitmap of the traversed TM domains */
    596     uint32 oam_hdr_offset;              /* Distance (in bytes) to OAM header
    597                                            from start of packet */
    598     uint8 oam_lm_replacement_offset;    /* Replacement offset for LM counter in
    599                                            Bytes */
    600     bcm_pkt_rx_oam_type_t rx_oam_pkt_type; /* OAM Pkt Type. */
    601     bcm_pkt_oam_counter_t oam_counter[BCM_PKT_OAM_COUNTER_MAX]; /* OAM counter array. */
    602     uint32 oam_counter_size;            /* Size of Counter array */
    603     uint8 _olp_hdr[20];                 /* OLP Header (network byte order). */
    604     bcm_pkt_dnx_t dnx_header_stack[BCM_PKT_NOF_DNX_HEADERS]; /* DNX Header stack */
    605     uint8 dnx_header_count;             /* Number of DNX headers */
    606     uint8 _ext_higig[4];                /* Extended HiGig Header (network byte
    607                                            order). */
    608     void *tx_header;                    /* Pointer for Packet tx header
    609                                            (internal). */
    610     uint8 txprocmh_qos_fields_valid;    /* QoS properties to be picked up from
    611                                            packet */
    612     uint8 txprocmh_congestion_int;      /* Congestion priority of the packet. */
    613     uint8 txprocmh_mcast_lb_index_valid; /* If set, use the value from
    614                                            txprocmh_mcast_lb_index */
    615     uint8 txprocmh_mcast_lb_index;      /* Software to select load balancing
    616                                            bitmap */
    617     uint16 txprocmh_ecmp_group_index;   /* Single level ECMP group index */
    618     uint16 txprocmh_ecmp_member_index;  /* ECMP member table index used by a
    619                                            single level ECMP group */
    620     uint16 txprocmh_destination;        /* Destination to be used based on
    621                                            txprocmh_destination_type */
    622     uint8 txprocmh_destination_type;    /* Destination Type/opcode of the packet */
    623     uint16 egress_to_cpu_hdr_size;      /* Size of egress to CPU header in CMIC
    624                                            devices. This header is applicable
    625                                            only in the new generation of CMIC
    626                                            called CMIC-X. */
    627     uint32 match_id[2];                 /* Match ID information. */
    628     uint8 rqe_q_num;                    /* RQE Queue Number */
    629     uint32 forwarding_type;             /* Packet forwarding type */
    630     uint32 forwarding_zone_id;          /* Indicates packet was routed - UC OR
    631                                            MC */
    632     uint8 spid;                         /* Service Pool ID (size 2 bits) */
    633     uint8 spid_override;                /* Indicates SPID to be used from Tx
    634                                            header */
    635     uint32 replication_or_nhi;          /* Replication ID or Next hop index */
    636 };
    637 
    638 /* HiGig opcodes. */
    639 #define BCM_HG_OPCODE_CPU       0x00       /* CPU Frame. */
    640 #define BCM_HG_OPCODE_UC        0x01       /* Unicast Frame. */
    641 #define BCM_HG_OPCODE_BC        0x02       /* Broadcast or DLF frame. */
    642 #define BCM_HG_OPCODE_MC        0x03       /* Multicast Frame. */
    643 #define BCM_HG_OPCODE_IPMC      0x04       /* IP Multicast Frame. */
    644 
    645 /* Generic packet opcodes. */
    646 #define BCM_PKT_OPCODE_CPU      0x00       /* CPU Frame. */
    647 #define BCM_PKT_OPCODE_UC       0x01       /* Unicast Frame. */
    648 #define BCM_PKT_OPCODE_BC       0x02       /* Broadcast or DLF frame. */
    649 #define BCM_PKT_OPCODE_MC       0x03       /* Multicast Frame. */
    650 #define BCM_PKT_OPCODE_IPMC     0x04       /* IP Multicast Frame. */
    651 
    652 /* Packet flags. */
    653 #define BCM_PKT_F_HGHDR             0x1        /* HiGig header is active
    654                                                   (internal). */
    655 #define BCM_PKT_F_SLTAG             0x2        /* SL tag is active. */
    656 #define BCM_PKT_F_NO_VTAG           0x4        /* Packet does not contain VLAN
    657                                                   tag. */
    658 #define BCM_PKT_F_TX_UNTAG          0x8        /* TX packet untagged (internal). */
    659 #define BCM_TX_CRC_FLD              0xf0       /* CRC information */
    660 #define BCM_TX_CRC_ALLOC            0x10       /* Allocate buffer for CRC. */
    661 #define BCM_TX_CRC_REGEN            0x20       /* Regenerate CRC. */
    662 #define BCM_TX_CRC_APPEND           (BCM_TX_CRC_ALLOC + BCM_TX_CRC_REGEN) 
    663 #define BCM_TX_CRC_FORCE_ERROR      0x40       /* Force CRC error. */
    664 #define BCM_TX_NO_PAD               0x100      /* Do not pad runt packets. */
    665 #define BCM_TX_FAST_PATH            0x200      /* Fast path TX. */
    666 #define BCM_TX_PURGE                0x400      /* XGS3 Set PURGE bit in DCB
    667                                                   (internal). */
    668 #define BCM_TX_LINKDOWN_TRANSMIT    0x800      /* Transmit on link down ports */
    669 #define BCM_TX_RELIABLE             0x1000     /* Relay (tunnel) packet
    670                                                   reliably. */
    671 #define BCM_TX_BEST_EFFORT          0x2000     /* Use best effort to relay
    672                                                   packet. */
    673 #define BCM_TX_LOOPBACK             0x4000     /* Loopback is indicated. */
    674 #define BCM_TX_PKT_PROP_ANY         0xf0000    /* All packet property fields. */
    675 #define BCM_TX_SRC_MOD              0x10000    /* Use the src_mod field from
    676                                                   packet. */
    677 #define BCM_TX_SRC_PORT             0x20000    /* Use the src_port field from
    678                                                   packet. */
    679 #define BCM_TX_PRIO_INT             0x40000    /* Use the prio_int field from
    680                                                   packet. */
    681 #define BCM_TX_PFM                  0x80000    /* Use PFM field from packet. */
    682 #define BCM_TX_ETHER                0x100000   /* Fully mapped packet TX. */
    683 #define BCM_TX_HG_READY             0x200000   /* HiGig header in _higig. */
    684 #define BCM_TX_TIME_STAMP_REPORT    0x400000   /* Request transmit time stamp. */
    685 #define BCM_RX_LEARN_DISABLED       0x800000   /* Packet's SA is not learned. */
    686 #define BCM_RX_CRC_STRIP            0x1000000  /* Do not include the CRC in the
    687                                                   length of the packet. */
    688 #define BCM_RX_TUNNELLED            0x2000000  /* Packet was tunnelled. */
    689 #define BCM_RX_MIRRORED             0x4000000  /* Packet was mirrored. */
    690 #define BCM_RX_TRUNCATED            0x8000000  /* Packet was truncated. */
    691 #define BCM_PKT_F_TIMESYNC          0x10000000 /* Packet is for Time Sync
    692                                                   protocol. */
    693 #define BCM_PKT_F_TRUNK             0x20000000 /* Trunk port. */
    694 #define BCM_PKT_F_TEST              0x40000000 /* Set the Test bit. */
    695 #define BCM_PKT_F_ROUTED            0x80000000 /* L3 switched packet. */
    696 #define BCM_TX_EXT_HG_HDR           0x20       /* Extended HiGig Header. */
    697 #define BCM_TX_NO_VISIBILITY_RESUME 0x8000     /* Disable Visibility resume for
    698                                                   DNX. */
    699 
    700 /* Packet flags2. */
    701 #define BCM_PKT_F2_REPLACEMENT_TYPE         0x1        /* OAM replacement type. */
    702 #define BCM_PKT_F2_REPLACEMENT_OFFSET       0x2        /* OAM replacement
    703                                                           offset. */
    704 #define BCM_PKT_F2_LM_COUNTER_INDEX         0x4        /* OAM LM counter index. */
    705 #define BCM_PKT_F2_TIMESTAMP_MODE           0x8        /* OAM DM time stamp type
    706                                                           - see
    707                                                           bcm_pkt_timestamp_mode_t
    708                                                           element, No-op by
    709                                                           default */
    710 #define BCM_PKT_F2_SAMPLE_RDI               0x10       /* OAM - Sample RDI bit. */
    711 #define BCM_PKT_F2_MA_PTR                   0x20       /* OAM - MA Pointer . */
    712 #define BCM_PKT_F2_MEP_TYPE_UPMEP           0x40       /* OAM - MEP type -
    713                                                           UP/DOWN */
    714 #define BCM_PKT_F2_LM_COUNTER_INDEX_2       0x80       /* OAM -Second LM counter
    715                                                           index. */
    716 #define BCM_PKT_F2_COUNTER_MODE_1           0x100      /* OAM - Counter 1 mode -
    717                                                           Use specified counter
    718                                                           actions, no-op by
    719                                                           default */
    720 #define BCM_PKT_F2_COUNTER_MODE_2           0x200      /* OAM - Counter 2 mode -
    721                                                           Use specified counter
    722                                                           actions, no-op by
    723                                                           default */
    724 #define BCM_PKT_F2_SNOOPED                  0x400      /* Packet was snooped */
    725 #define BCM_PKT_F2_UNKNOWN_DEST             0x800      /* packet has unknown
    726                                                           destination */
    727 #define BCM_PKT_F2_RX_PORT                  0x1000     /* indicate that
    728                                                           bcm_pkt_s.rx_port is
    729                                                           used as a source port
    730                                                           for the
    731                                                           masquerade/visibility
    732                                                           feature */
    733 #define BCM_PKT_F2_VISIBILITY_PKT           0x2000     /* indication that this
    734                                                           is a visibility
    735                                                           packet(internal) */
    736 #define BCM_PKT_F2_OAM_TX                   0x4000     /* Indicates OAM Packet
    737                                                           Tx */
    738 #define BCM_PKT_F2_OLP_READY                0x8000     /* Indicates OLP already
    739                                                           constructed in field
    740                                                           _olp_hdr */
    741 #define BCM_PKT_F2_LM_REPLACEMENT_OFFSET    0x10000    /* OAM LM replacement
    742                                                           offset */
    743 #define BCM_PKT_F2_MEP_TYPE_SAT_DOWNMEP     0x20000    /* SAT MEP TYPE - DOWN */
    744 #define BCM_PKT_F2_MEP_TYPE_SAT_UPMEP       0x40000    /* SAT MEP TYPE - UP */
    745 #define BCM_PKT_F2_MC_QUEUE                 0x80000    /* Indicates packet goes
    746                                                           to MC queue */
    747 #define BCM_PKT_F2_CPU_TX_PROC              0x100000   /* Indicates CPU TX PROC
    748                                                           packet */
    749 #define BCM_PKT_F2_CONG_INT                 0x200000   /* use the
    750                                                           txprocmh_congestion_int
    751                                                           field from packet */
    752 #define BCM_PKT_F2_EXT_HG_HDR               0x400000   /* use the extended higig
    753                                                           field from packet */
    754 #define BCM_PKT_F2_TWAMP_OWAMP_TS           0x800000   /* Requires
    755                                                           BROADCOM_PREMIUM
    756                                                           license */
    757 #define BCM_PKT_F2_SPID_OVERRIDE            0x1000000  /* Use SPID from the
    758                                                           packet */
    759 
    760 /* Flags for rx_untagged field in bcm_pkt_t structure. */
    761 #define BCM_PKT_OUTER_UNTAGGED  0x1        /* Packet received without outer vlan
    762                                               tag. */
    763 #define BCM_PKT_INNER_UNTAGGED  0x2        /* Packet received without inner vlan
    764                                               tag. */
    765 
    766 /* TimeSync Packet Flags. */
    767 #define BCM_TX_TIMESYNC_ONE_STEP            0x1        /* One step timestamp. */
    768 #define BCM_TX_TIMESYNC_ONE_STEP_INGRESS_SIGN 0x2        /* Ingress timestamp sign
    769                                                           bit. */
    770 #define BCM_TX_TIMESYNC_ONE_STEP_HDR_START_OFFSET 0x4        /* One step timestamp
    771                                                           header offset. */
    772 #define BCM_TX_TIMESYNC_ONE_STEP_REGEN_UDP_CHKSUM 0x8        /* One step timestamp
    773                                                           header offset. */
    774 #define BCM_TX_TIMESYNC_INGRESS_SIGN        (BCM_TX_TIMESYNC_ONE_STEP_INGRESS_SIGN) /* Ingress timestamp sign
    775                                                           bit. */
    776 #define BCM_TX_TIMESYNC_HDR_START_OFFSET    (BCM_TX_TIMESYNC_ONE_STEP_HDR_START_OFFSET) /* PTP header offset in
    777                                                           packet buffer. */
    778 #define BCM_TX_TIMESYNC_REGEN_UDP_CHKSUM    (BCM_TX_TIMESYNC_ONE_STEP_REGEN_UDP_CHKSUM) /* Regenerate UDP header
    779                                                           checksum of PTP
    780                                                           packet. */
    781 
    782 /* Stacking Packet flags. */
    783 #define BCM_PKT_STK_F_MIRROR                0x1        /* Mirror packet. */
    784 #define BCM_PKT_STK_F_DO_NOT_MODIFY         0x2        /* Do not alter packet on
    785                                                           egress device. */
    786 #define BCM_PKT_STK_F_TRUNK_FAILOVER        0x4        /* Packet is redirected
    787                                                           due to trunk failover. */
    788 #define BCM_PKT_STK_F_SRC_PORT              0x8        /* Source GPORT provided. */
    789 #define BCM_PKT_STK_F_DST_PORT              0x10       /* Destination GPORT
    790                                                           provided. */
    791 #define BCM_PKT_STK_F_DEFERRED_DROP         0x20       /* Drop in egress device. */
    792 #define BCM_PKT_STK_F_DEFERRED_CHANGE_PKT_PRIO 0x40       /* Update packet priority
    793                                                           to stk_pkt_prio in
    794                                                           egress device. */
    795 #define BCM_PKT_STK_F_DEFERRED_CHANGE_DSCP  0x80       /* Update DSCP to
    796                                                           stk_dscp in egress
    797                                                           device. */
    798 #define BCM_PKT_STK_F_CLASSIFICATION_TAG    0x100      /* stk_classification_tag
    799                                                           field is valid. */
    800 #define BCM_PKT_STK_F_VLAN_TRANSLATE_NONE   0x200      /* No VLAN translation
    801                                                           performed. */
    802 #define BCM_PKT_STK_F_VLAN_TRANSLATE_UNCHANGED 0x400      /* VLAN translation did
    803                                                           not change packet. */
    804 #define BCM_PKT_STK_F_VLAN_TRANSLATE_CHANGED 0x800      /* VLAN translation
    805                                                           changed packet. */
    806 #define BCM_PKT_STK_F_DO_NOT_LEARN          0x1000     /* Packet should not be
    807                                                           learned on egress
    808                                                           device. */
    809 #define BCM_PKT_STK_F_PRESERVE_DSCP         0x2000     /* Egress device should
    810                                                           not change DSCP. */
    811 #define BCM_PKT_STK_F_PRESERVE_PKT_PRIO     0x4000     /* Egress device should
    812                                                           not change packet
    813                                                           priority. */
    814 #define BCM_PKT_STK_F_TX_TAG                0x8000     /* The VLAN tag should be
    815                                                           included in the packet
    816                                                           data (internal). */
    817 #define BCM_PKT_STK_F_ENCAP_ID              0x10000    /* The stk_encap_id value
    818                                                           is provided. */
    819 #define BCM_PKT_STK_F_FAILOVER              0x20000    /* Use the protection
    820                                                           nexthop instead of the
    821                                                           default nexthop. */
    822 
    823 /* internal packet trace flags */
    824 #define BCM_PKT_TRACE_LEARN                 0x1        /* learning ensable on
    825                                                           internal trace packet */
    826 #define BCM_PKT_TRACE_NO_IFP                0x2        /* disable ingress field
    827                                                           processor lookup on
    828                                                           internal trace packet */
    829 #define BCM_PKT_TRACE_FORWARD               0x4        /* forward internal trace
    830                                                           packet to egress */
    831 #define BCM_PKT_TRACE_DROP_TO_MMU           0x8        /* Drop trace packet to
    832                                                           MMU else forward to
    833                                                           egress */
    834 #define BCM_PKT_TRACE_DROP_TO_EGR           0x10       /* Drop trace packet to
    835                                                           egress */
    836 #define BCM_PKT_TRACE_RETRIEVE_DATA_ONLY    0x20       /* Get the visibility
    837                                                           data with no manual
    838                                                           visibility packet
    839                                                           inject */
    840 
    841 /* Filter types. */
    842 #define BCM_PKT_FILTER_LAG          0x1        /* LAG filter. */
    843 #define BCM_PKT_FILTER_TAGGED       0x2        /* Tag filter. */
    844 #define BCM_PKT_FILTER_PORT_MASK    0x4        /* Port mask filter. */
    845 #define BCM_PKT_FILTER_STP          0x8        /* STP filter. */
    846 #define BCM_PKT_FILTER_EAP          0x10       /* EAP filter. */
    847 #define BCM_PKT_FILTER_INGRESS_VLAN 0x20       /* Ingress Vlan filter. */
    848 #define BCM_PKT_FILTER_EGRESS_VLAN  0x40       /* Egress Vlan filter. */
    849 #define BCM_PKT_FILTER_SA           0x80       /* Source address filter. */
    850 
    851 /* CPU to CPU tunnel modes. */
    852 typedef enum bcm_cpu_tunnel_mode_e {
    853     BCM_CPU_TUNNEL_NONE = 0,            /* Do not tunnel. */
    854     BCM_CPU_TUNNEL_PACKET_RELIABLE = 1, /* Use reliable transport. */
    855     BCM_CPU_TUNNEL_PACKET_BEST_EFFORT = 2, /* Use best effort transport. */
    856     BCM_CPU_TUNNEL_PACKET = 3           /* Use default mode. */
    857 } bcm_cpu_tunnel_mode_t;
    858 
    859 /* CPU to CPU tunnel flags. */
    860 #define BCM_CPU_TUNNEL_F_UNTAGGED       0x1        /* Untagged packet. */
    861 #define BCM_CPU_TUNNEL_F_L3             0x2        /* L3 packet. */
    862 #define BCM_CPU_TUNNEL_F_PBMP           0x4        /* Use port bitmap, not just
    863                                                       port. */
    864 #define BCM_CPU_TUNNEL_F_RELIABLE       0x8        /* Use reliable transport. */
    865 #define BCM_CPU_TUNNEL_F_BEST_EFFORT    0x10       /* Use best effort transport. */
    866 #define BCM_CPU_TUNNEL_F_ALL_UNTAGGED   0x20       /* Use with port bitmap. */
    867 
    868 /* Backward compatibility. */
    869 #define bcm_tunnel_mode_t       bcm_cpu_tunnel_mode_t 
    870 
    871 /* Backward compatibility. */
    872 #define BCM_TUNNEL_NONE             BCM_CPU_TUNNEL_NONE 
    873 #define BCM_TUNNEL_PACKET_RELIABLE  BCM_CPU_TUNNEL_PACKET_RELIABLE 
    874 #define BCM_TUNNEL_PACKET_NO_ACK    BCM_CPU_TUNNEL_PACKET_BEST_EFFORT 
    875 #define BCM_TUNNEL_PACKET           BCM_CPU_TUNNEL_PACKET 
    876 
    877 /* Backward compatibility. */
    878 #define BCM_TUNNEL_F_UNTAGGED       BCM_CPU_TUNNEL_F_UNTAGGED 
    879 #define BCM_TUNNEL_F_L3             BCM_CPU_TUNNEL_F_L3 
    880 #define BCM_TUNNEL_F_PBMP           BCM_CPU_TUNNEL_F_PBMP 
    881 #define BCM_TUNNEL_F_RELIABLE       BCM_CPU_TUNNEL_F_RELIABLE 
    882 #define BCM_TUNNEL_F_BEST_EFFORT    BCM_CPU_TUNNEL_F_BEST_EFFORT 
    883 #define BCM_TUNNEL_F_ALL_UNTAGGED   BCM_CPU_TUNNEL_F_ALL_UNTAGGED 
    884 
    885 /* Set up a single buffer packet. */
    886 #define BCM_PKT_ONE_BUF_SETUP(pkt, buf, _len)  \
    887     do { \
    888         (pkt)->_pkt_data.data = (buf); \
    889         (pkt)->_pkt_data.len = (_len); \
    890         (pkt)->pkt_data = &(pkt)->_pkt_data; \
    891         (pkt)->blk_count = 1; \
    892     } while (0) 
    893 
    894 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    895 #define BCM_PKT_TX_LEN_SET(pkt, _len)  \
    896     (pkt)->_pkt_data.len = (_len) 
    897 
    898 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    899 #define _BCM_HTONS_CVT_SET(pkt, val, posn)  \
    900     do { \
    901          uint16 _tmp; \
    902          _tmp = bcm_htons(val); \
    903          sal_memcpy((pkt)->_pkt_data.data + (posn), &_tmp, 2); \
    904     } while (0) 
    905 
    906 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    907 #define BCM_PKT_HDR_DMAC_SET(pkt, mac)  \
    908     sal_memcpy((pkt)->_pkt_data.data, (mac), 6) 
    909 
    910 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    911 #define BCM_PKT_HDR_SMAC_SET(pkt, mac)  \
    912     sal_memcpy((pkt)->_pkt_data.data + 6, (mac), 6) 
    913 
    914 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    915 #define BCM_PKT_HDR_TPID_SET(pkt, tpid)  \
    916     _BCM_HTONS_CVT_SET(pkt, tpid, 12) 
    917 
    918 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    919 #define BCM_PKT_HDR_UNTAGGED_LEN_SET(pkt, len)  \
    920     _BCM_HTONS_CVT_SET(pkt, len, 12) 
    921 
    922 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    923 #define BCM_PKT_HDR_VTAG_CONTROL_SET(pkt, vtag)  \
    924     _BCM_HTONS_CVT_SET(pkt, vtag, 14) 
    925 
    926 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    927 #define BCM_PKT_HDR_TAGGED_LEN_SET(pkt, len)  \
    928     _BCM_HTONS_CVT_SET(pkt, len, 16) 
    929 
    930 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    931 #define BCM_PKT_HDR_SNAP_DSAP_SET(pkt, dsap)  \
    932     (pkt)->_pkt_data.data[18] = (dsap) 
    933 
    934 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    935 #define BCM_PKT_HDR_SNAP_SSAP_SET(pkt, ssap)  \
    936     (pkt)->_pkt_data.data[19] = (ssap) 
    937 
    938 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    939 #define BCM_PKT_HDR_SNAP_CONTROL_SET(pkt, ctl)  \
    940     (pkt)->_pkt_data.data[20] = (ctl) 
    941 
    942 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    943 #define BCM_PKT_HDR_SNAP_ORG_SET(pkt, b1, b2, b3)  \
    944      do { \
    945         (pkt)->_pkt_data.data[21] = (b1); \
    946         (pkt)->_pkt_data.data[22] = (b2); \
    947         (pkt)->_pkt_data.data[23] = (b3); \
    948     } while (0) 
    949 
    950 /* Helper macro for single buffer Ethernet packet (not HiGig). */
    951 #define BCM_PKT_HDR_SNAP_ETYPE_SET(pkt, etype)  \
    952     _BCM_HTONS_CVT_SET(pkt, etype, 24) 
    953 
    954 /* Set a single port for a packet for TX. */
    955 #define BCM_PKT_PORT_SET(pkt, _port, _untagged, _l3)  \
    956     do { \
    957         BCM_PBMP_PORT_SET((pkt)->tx_pbmp, _port); \
    958         if ((_untagged) != FALSE) { \
    959             BCM_PBMP_PORT_SET((pkt)->tx_upbmp, _port); \
    960         } else { \
    961             BCM_PBMP_CLEAR((pkt)->tx_upbmp); \
    962         } \
    963         if ((_l3) != FALSE) { \
    964             BCM_PBMP_PORT_SET((pkt)->tx_l3pbmp, _port); \
    965         } else { \
    966             BCM_PBMP_CLEAR((pkt)->tx_l3pbmp); \
    967         } \
    968     } while (0) 
    969 
    970 /* Check if HiGig header is active in the packet. */
    971 #define BCM_PKT_HAS_HGHDR(pkt)  \
    972     (((pkt)->flags & BCM_PKT_F_HGHDR) != 0) 
    973 
    974 /* Check if SL tag is active in the packet. */
    975 #define BCM_PKT_HAS_SLTAG(pkt)  \
    976     (((pkt)->flags & BCM_PKT_F_SLTAG) != 0) 
    977 
    978 /* Check if VLAN tag is not present in packet. */
    979 #define BCM_PKT_NO_VLAN_TAG(pkt)  \
    980     (((pkt)->flags & BCM_PKT_F_NO_VTAG) != 0) 
    981 
    982 /* Do not include CRC in length on RX. */
    983 #define BCM_PKT_RX_CRC_STRIP(pkt)  \
    984     ((pkt)->flags & BCM_RX_CRC_STRIP) 
    985 
    986 /* Strip VLAN tag on RX; do not include in length. */
    987 #define BCM_PKT_RX_VLAN_TAG_STRIP(pkt)  \
    988     BCM_PKT_NO_VLAN_TAG(pkt) 
    989 
    990 #define BCM_TX_PKT_PROP_ANY_TST(pkt)  \
    991     (((pkt)->flags & BCM_TX_PKT_PROP_ANY) != 0) 
    992 
    993 #define BCM_PKT_TX_ETHER(pkt)   \
    994     (((pkt)->flags & BCM_TX_ETHER) != 0) 
    995 
    996 #define BCM_PKT_TX_HG_READY(pkt)  \
    997     (((pkt)->flags & BCM_TX_HG_READY) != 0) 
    998 
    999 /* 
   1000  * Check if fabric mapped, which means that the packet is sent
   1001  * from the CPU through the HiGig ingress pipeline.
   1002  */
   1003 #define BCM_PKT_TX_FABRIC_MAPPED(pkt)  \
   1004             ((((pkt)->flags & BCM_TX_ETHER ) !=0 ) && \
   1005              (((pkt)->flags & (BCM_TX_PKT_PROP_ANY | BCM_TX_HG_READY) ) !=0 )) 
   1006 
   1007 /* Pointer to beginning of IEEE packet. */
   1008 #define BCM_PKT_IEEE(pkt)       \
   1009     ((uint8*)((pkt)->pkt_data[0].data)) 
   1010 
   1011 /* Length of IEEE packet including MAC addresses and CRC. */
   1012 #define BCM_PKT_IEEE_LEN(pkt)   \
   1013     ((pkt)->pkt_len) 
   1014 
   1015 /* Pointer to destination MAC address. */
   1016 #define BCM_PKT_DMAC(pkt)       \
   1017     BCM_PKT_IEEE(pkt) 
   1018 
   1019 /* Pointer to VLAN tag (all 4 bytes). */
   1020 #define BCM_PKT_VLAN_PTR(pkt)   \
   1021    (((pkt)->flags & BCM_PKT_F_NO_VTAG) ? (pkt)->_vtag : \
   1022     ((BCM_PKT_DMAC(pkt) + 2*sizeof(bcm_mac_t)))) 
   1023 
   1024 /* The protocol (eg 0x8100) bytes. */
   1025 #define BCM_PKT_TAG_PROTOCOL(pkt)  \
   1026     ((uint16) ((BCM_PKT_VLAN_PTR(pkt)[0] << 8) | (BCM_PKT_VLAN_PTR(pkt)[1]))) 
   1027 
   1028 /* The VLAN control tag. */
   1029 #define BCM_PKT_VLAN_CONTROL(pkt)  \
   1030     ((uint16) ((BCM_PKT_VLAN_PTR(pkt)[2] << 8) | (BCM_PKT_VLAN_PTR(pkt)[3]))) 
   1031 
   1032 /* The ID from the VLAN control tag. */
   1033 #define BCM_PKT_VLAN_ID(pkt)    \
   1034     BCM_VLAN_CTRL_ID(BCM_PKT_VLAN_CONTROL(pkt)) 
   1035 
   1036 /* The priority from the VLAN control tag. */
   1037 #define BCM_PKT_VLAN_PRI(pkt)   \
   1038     BCM_VLAN_CTRL_PRIO(BCM_PKT_VLAN_CONTROL(pkt)) 
   1039 
   1040 /* The CFI from the VLAN control tag. */
   1041 #define BCM_PKT_VLAN_CFI(pkt)   \
   1042      BCM_VLAN_CTRL_CFI(BCM_PKT_VLAN_CONTROL(pkt)) 
   1043 
   1044 /* Pointer to packet's HiGig header. */
   1045 #define BCM_PKT_HG_HDR(pkt)     \
   1046     ((pkt)->_higig) 
   1047 
   1048 /* Pointer to packet's SL tag. */
   1049 #define BCM_PKT_SL_TAG(pkt)     \
   1050     ((pkt)->_sltag) 
   1051 
   1052 /* Pointer to packet's Pipeline Bypass header. */
   1053 #define BCM_PKT_PB_HDR(pkt)     \
   1054     ((pkt)->_pb_hdr) 
   1055 
   1056 /* Pointer to packet's Extended HiGig header. */
   1057 #define BCM_PKT_EXT_HG_HDR(pkt)  \
   1058     ((pkt)->_ext_higig) 
   1059 
   1060 #define BCM_PKT_NO_VTAG_REQUIRE(pkt)  \
   1061     ((pkt)->flags |= BCM_PKT_F_NO_VTAG) 
   1062 
   1063 #define BCM_PKT_HGHDR_CLR(pkt)  \
   1064     ((pkt)->flags &= (~BCM_PKT_F_HGHDR)) 
   1065 
   1066 #define BCM_PKT_HGHDR_REQUIRE(pkt)  \
   1067     ((pkt)->flags |= BCM_PKT_F_HGHDR) 
   1068 
   1069 #define BCM_PKT_SLTAG_REQUIRE(pkt)  \
   1070     ((pkt)->flags |= BCM_PKT_F_SLTAG) 
   1071 
   1072 /* How many bytes in the data blocks. */
   1073 #define BCM_PKT_BLK_BYTES_CALC(pkt, bytes)  \
   1074     do { \
   1075         int i; \
   1076         (bytes) = 0; \
   1077         for (i = 0; i < (pkt)->blk_count; i++) { \
   1078             (bytes) += (pkt)->pkt_data[i].len; \
   1079         } \
   1080     } while (0) 
   1081 
   1082 /* Packet length calculated based on flags. */
   1083 #define BCM_PKT_TX_LEN(pkt, bytes)  \
   1084     do { \
   1085         BCM_PKT_BLK_BYTES_CALC(pkt, bytes); \
   1086         if (BCM_PKT_HAS_HGHDR(pkt)) (bytes) += 12; \
   1087         if (BCM_PKT_HAS_SLTAG(pkt)) (bytes) += 4; \
   1088         if ((pkt)->flags & BCM_PKT_F_NO_VTAG) (bytes) += 4; \
   1089     } while (0) 
   1090 
   1091 /* Packet length including SL, HiGig, VLAN tags. */
   1092 #define BCM_PKT_RX_TOT_LEN(pkt, bytes)  \
   1093     (bytes) = (pkt)->tot_len 
   1094 
   1095 /* 
   1096  * BCM packet allocation function.
   1097  * 
   1098  * If unit is specified, the flags should be set up according to the unit
   1099  * as best as possible.
   1100  * 
   1101  * If len > 0, then a packet buffer should be allocated and the packet
   1102  * will be setup up for a single data block. If len <= 0, no packet
   1103  * allocation will be made.
   1104  */
   1105 typedef int (*bcm_pkt_alloc_f)(
   1106     int unit, 
   1107     int len, 
   1108     bcm_pkt_t **pkt_buf);
   1109 
   1110 /* BCM packet free function. */
   1111 typedef int (*bcm_pkt_free_f)(
   1112     int unit, 
   1113     bcm_pkt_t *pkt);
   1114 
   1115 /* Map target ports according to VLAN and L2 tables. */
   1116 typedef int (*bcm_pkt_l2_map_f)(
   1117     int unit, 
   1118     bcm_pkt_t *pkt, 
   1119     bcm_mac_t dest_mac, 
   1120     int vid);
   1121 
   1122 /* Initialize and set up a bcm_pkt_t structure. */
   1123 extern int bcm_pkt_clear(
   1124     int unit, 
   1125     bcm_pkt_t *pkt, 
   1126     bcm_pkt_blk_t *blks, 
   1127     int blk_count, 
   1128     uint32 flags, 
   1129     bcm_pkt_t **pkt_buf);
   1130 
   1131 /* Initialize packet flags based on the type of device. */
   1132 extern int bcm_pkt_flags_init(
   1133     int unit, 
   1134     bcm_pkt_t *pkt, 
   1135     uint32 init_flags);
   1136 
   1137 /* Set up the length and flags for a bcm_pkt_t structure. */
   1138 extern int bcm_pkt_flags_len_setup(
   1139     int unit, 
   1140     bcm_pkt_t *pkt, 
   1141     int alloc_bytes, 
   1142     int payload_len, 
   1143     uint32 flags);
   1144 
   1145 /* Copy data into the data blocks of a packet structure. */
   1146 extern int bcm_pkt_memcpy(
   1147     bcm_pkt_t *pkt, 
   1148     int dest_byte, 
   1149     uint8 *src, 
   1150     int len);
   1151 
   1152 /* Calculate a byte offset in the data buffer for a packet. */
   1153 extern int bcm_pkt_byte_index(
   1154     bcm_pkt_t *pkt, 
   1155     int n, 
   1156     int *len, 
   1157     int *blk_idx, 
   1158     uint8 **location);
   1159 
   1160 /* Allocate a packet structure and packet data. */
   1161 extern int bcm_pkt_alloc(
   1162     int unit, 
   1163     int size, 
   1164     uint32 flags, 
   1165     bcm_pkt_t **pkt_buf);
   1166 
   1167 /* Deallocate a packet structure and packet data. */
   1168 extern int bcm_pkt_free(
   1169     int unit, 
   1170     bcm_pkt_t *pkt);
   1171 
   1172 /* Allocate or deallocate an array of packets. */
   1173 extern int bcm_pkt_blk_alloc(
   1174     int unit, 
   1175     int count, 
   1176     int size, 
   1177     uint32 flags, 
   1178     bcm_pkt_t ***packet_array);
   1179 
   1180 /* Allocate or deallocate an array of packets. */
   1181 extern int bcm_pkt_blk_free(
   1182     int unit, 
   1183     bcm_pkt_t **pkt, 
   1184     int count);
   1185 
   1186 /* Allocate or deallocate a packet structure using =bcm_rx_alloc. */
   1187 extern int bcm_pkt_rx_alloc(
   1188     int unit, 
   1189     int len, 
   1190     bcm_pkt_t **pkt_buf);
   1191 
   1192 /* Allocate or deallocate a packet structure using =bcm_rx_alloc. */
   1193 extern int bcm_pkt_rx_free(
   1194     int unit, 
   1195     bcm_pkt_t *pkt);
   1196 
   1197 /* Initialize a BCM packet structure. */
   1198 extern void bcm_pkt_t_init(
   1199     bcm_pkt_t *pkt);
   1200 
   1201 /* Initialize a BCM packet block structure. */
   1202 extern void bcm_pkt_blk_t_init(
   1203     bcm_pkt_blk_t *pkt_blk);
   1204 
   1205 /* Set ECMP group field in the pkt structure */
   1206 extern int bcm_pkt_ecmp_grp_set(
   1207     int unit, 
   1208     bcm_pkt_t *pkt, 
   1209     bcm_if_t ecmp_group_id);
   1210 
   1211 /* Set ECMP member field in the pkt structure */
   1212 extern int bcm_pkt_ecmp_member_set(
   1213     int unit, 
   1214     bcm_pkt_t *pkt, 
   1215     bcm_if_t ecmp_group_id, 
   1216     bcm_if_t ecmp_member_id);
   1217 
   1218 /* Set nexthop field in the pkt structure */
   1219 extern int bcm_pkt_nexthop_set(
   1220     int unit, 
   1221     bcm_pkt_t *pkt, 
   1222     bcm_if_t nexthop_id);
   1223 
   1224 /* Initialize a BCM RX reasons structure. */
   1225 extern void bcm_rx_reasons_t_init(
   1226     bcm_rx_reasons_t *reasons);
   1227 
   1228 /* Packet drop reasons */
   1229 typedef enum bcm_pkt_drop_reason_e {
   1230     bcmPktDropReasonEgressVlanTranslateMiss = 0, /* Packet marked for drop due to egress
   1231                                            vlan translate miss */
   1232     bcmPktDropReasonEgressTunnelSnap = 1, /* SNAP packet dropped becasuse it is
   1233                                            being tunneled */
   1234     bcmPktDropReasonEgressColorSelect = 2, /* If control bcmSwitchColorSelect is
   1235                                            not set to BCM_COLOR_OUTER_CFI and
   1236                                            the CFI of the packet is derived as
   1237                                            1, then packet is dropped */
   1238     bcmPktDropReasonEgressTtlError = 3, /* Packet marked for drop due to TTL
   1239                                            error */
   1240     bcmPktDropReasonEgressVlanFilter = 4, /* Packet marked for drop due to port
   1241                                            not being a member of VLAN. This
   1242                                            happens when VLAN filtering is
   1243                                            enabled by passing
   1244                                            BCM_PORT_VLAN_MEMBER_EGRESS flags to
   1245                                            bcm_port_vlan_member_set API */
   1246     bcmPktDropReasonEgressStgBlocked = 5, /* Packet marked for drop due to
   1247                                            Spanning tree in blocking state */
   1248     bcmPktDropReasonEgressIPMCSameVlanPrune = 6, /* IPMC packet marked for drop due to
   1249                                            bcmSwitchDropReasonIpmcSameVlanPruning
   1250                                            setting */
   1251     bcmPktDropReasonEgressMmuPurge = 7, /* Packet marked for drop due to MMU
   1252                                            purge */
   1253     bcmPktDropReasonEgressMmuAge = 8,   /* Packet marked for drop due to MMU age */
   1254     bcmPktDropReasonEgressBadTdipDrop = 9, /* Packet marked for drop due to bad
   1255                                            tunnel destination IP in case of 6to4
   1256                                            tunnels and ISATAP tunnels - possible
   1257                                            reasons are incorrect prefix for IPv6
   1258                                            DIP,IPv4 DIP/SIP is
   1259                                            BC/Zero/loopback/Class-D, IPv4 SIP =
   1260                                            DIP */
   1261     bcmPktDropReasonEgressProtection = 10, /* Packets dropped because of protection
   1262                                            drop control */
   1263     bcmPktDropReasonEgressUnknownVlan = 11, /* Packet marked for drop due to unknown
   1264                                            VLAN. This happens when
   1265                                            bcmVlanDropUnknown vlan control is
   1266                                            used to set dropping of unknown VLAN
   1267                                            packets */
   1268     bcmPktDropReasonEgressStgDisabled = 12, /* Packet marked for drop due to
   1269                                            Spanning tree in disable state */
   1270     bcmPktDropReasonEgressHiGig2ReservedPPD = 13, /* Packets dropped because of HiGig2
   1271                                            header with reserved ppd going out on
   1272                                            non-hg2 ports */
   1273     bcmPktDropReasonEgressHigigPlusUnknown = 14, /* Unknown HiGigPlus packet incoming
   1274                                            from hg source and dest is non-hg */
   1275     bcmPktDropReasonEgressL2MtuExceeded = 15, /* Packet dropped because of L2 MTU
   1276                                            checks configured on the port
   1277                                            (physical/virtual) */
   1278     bcmPktDropReasonEgressCompositeError = 16, /* Packet marked for drop due to parity
   1279                                            error from memories or ISM lookup
   1280                                            fail */
   1281     bcmPktDropReasonEgressMulticastPruned = 17, /* L3 Multicast packets marked for drop
   1282                                            due to BCM_L3_MULTICAST_L3_DROP or
   1283                                            BCM_L3_MULTICAST_L2_DROP setting in
   1284                                            the multicast APIs */
   1285     bcmPktDropReasonEgressHigigPlusInvalidModuleId = 18, /* Unknown HiGigPlus packet incoming
   1286                                            from non-hg source and dest is hg and
   1287                                            the modid is greater than 31 */
   1288     bcmPktDropReasonEgressFieldAction = 19, /* Packet dropped due to a egress field
   1289                                            action */
   1290     bcmPktDropReasonEgressSplitHorizon = 20, /* Packet marked for drop due to split
   1291                                            horizon check. This is done by
   1292                                            enabling pruning for DVP network
   1293                                            group via
   1294                                            bcm_switch_network_group_config_set
   1295                                            with
   1296                                            BCM_SWITCH_NETWORK_GROUP_EGRESS_PRUNE_ENABLE */
   1297     bcmPktDropReasonEgressSVPRemoval = 21, /* Packet marked for drop due to virtual
   1298                                            port pruning - SVP = DVP and VP based
   1299                                            pruning is enabled
   1300                                            (DISABLE_VP_PRUNING is set to 0 in
   1301                                            Source VP table) */
   1302     bcmPktDropReasonEgressNivSrcKnockout = 22, /* Outgoing packet dropped due to NIV
   1303                                            pruning check */
   1304     bcmPktDropReasonEgressNonUCPrune = 23, /* Non-unicast packet marked for drop
   1305                                            due to drop condition set in egress
   1306                                            next hop via
   1307                                            bcm_mpls/l2gre/vxlan_port_add API
   1308                                            with BCM_MPLS/L2GRE/VXLAN_PORT_DROP
   1309                                            flag */
   1310     bcmPktDropReasonEgressTrillPacket = 24, /* Trill packets being sent on non-trill
   1311                                            ports */
   1312     bcmPktDropReasonEgressPacketTooSmall = 25, /* Packet dropped since it it too small */
   1313     bcmPktDropReasonEgressNonTrillPacket = 26, /* Non-Trill packets being sent on trill
   1314                                            ports */
   1315     bcmPktDropReasonEgressVpLagPruned = 27, /* Packet dropped because of VP lag
   1316                                            pruning checks in the egress */
   1317     bcmPktDropReasonEgressInvalid1588Packet = 28, /* Packet dropped since it is a invalid
   1318                                            1588 packet */
   1319     bcmPktDropReasonEgressInvalidFcoePacket = 29, /* Packet dropped since it is a invalid
   1320                                            FCOE packet */
   1321     bcmPktDropReasonEgressInvalidCnmPacket = 30, /* Packet dropped since it is a invalid
   1322                                            CNM packet */
   1323     bcmPktDropReasonEgressOriginalPacket = 31, /* Packet dropped in egress due to user
   1324                                            configuration */
   1325     bcmPktDropReasonCount = 32          /* Always Last. Not a usable value */
   1326 } bcm_pkt_drop_reason_t;
   1327 
   1328 typedef struct bcm_pkt_drop_reasons_s {
   1329     SHR_BITDCL rbits[_SHR_BITDCLSIZE(bcmPktDropReasonCount)]; 
   1330 } bcm_pkt_drop_reasons_t;
   1331 
   1332 /* 
   1333  * Macro to check if a reason (bcmPktDropReason*) is included in a set of
   1334  * reasons (bcm_pkt_drop_reasons_t).
   1335  * 
   1336  * Returns:
   1337  *   zero     => reason is not included in the set
   1338  *   non-zero => reason is included in the set
   1339  */
   1340 #define BCM_PKT_DROP_REASON_GET(_drop_reasons, _drop_reason)  \
   1341    SHR_BITGET(((_drop_reasons).rbits), (_drop_reason)) 
   1342 
   1343 /* 
   1344  * Macro to add a reason (bcmPktDropReason*) to a set of reasons
   1345  * (bcm_pkt_drop_reasons_t).
   1346  */
   1347 #define BCM_PKT_DROP_REASON_SET(_drop_reasons, _drop_reason)  \
   1348    SHR_BITSET(((_drop_reasons).rbits), (_drop_reason)) 
   1349 
   1350 /* 
   1351  * Macro to add all reasons (bcmPktDropReason*) to a set of reasons
   1352  * (bcm_pkt_drop_reasons_t).
   1353  */
   1354 #define BCM_PKT_DROP_REASON_SET_ALL(_drop_reasons)  \
   1355    SHR_BITSET_RANGE(((_drop_reasons).rbits), 0, bcmPktDropReasonCount) 
   1356 
   1357 /* 
   1358  * Macro to clear a reason (bcmPktDropReason*) from a set of reasons
   1359  * (bcm_pkt_drop_reasons_t).
   1360  */
   1361 #define BCM_PKT_DROP_REASON_CLEAR(_drop_reasons, _drop_reason)  \
   1362    SHR_BITCLR(((_drop_reasons).rbits), (_drop_reason)) 
   1363 
   1364 /* Macro to clear a set of reasons (bcm_pkt_drop_reasons_t). */
   1365 #define BCM_PKT_DROP_REASON_CLEAR_ALL(_drop_reasons)  \
   1366    SHR_BITCLR_RANGE(((_drop_reasons).rbits), 0, bcmPktDropReasonCount) 
   1367 
   1368 /* Macro to check if a set of reasons (bcm_pkt_drop_reasons_t) is empty. */
   1369 #define BCM_PKT_DROP_REASON_IS_NULL(_drop_reasons)  \
   1370    SHR_BITNULL_RANGE(((_drop_reasons).rbits), 0, bcmPktDropReasonCount) 
   1371 
   1372 /* Macro to itterate over a set of reasons (bcm_pkt_drop_reasons_t). */
   1373 #define BCM_PKT_DROP_REASON_ITER(_drop_reasons, _drop_reason)  \
   1374    for(_drop_reason = bcmPktDropReasonEgressVlanTranslateMiss; _drop_reason < (int)bcmPktDropReasonCount; _drop_reason++) if(SHR_BITGET(((_drop_reasons).rbits), (_drop_reason))) 
   1375 
   1376 /* 
   1377  * Macro to count number of active reasons in a set of reasons
   1378  * (bcm_pkt_drop_reasons_t).
   1379  */
   1380 #define BCM_PKT_DROP_REASON_COUNT(_drop_reasons, count)  \
   1381                 SHR_BITCOUNT_RANGE(((_drop_reasons).rbits), count, 0, bcmPktDropReasonCount)
   1382  
   1383 
   1384 /* Macro to compare two sets of reasons (bcm_pkt_drop_reasons_t). */
   1385 #define BCM_PKT_DROP_REASON_EQ(_drop_reasons1, _drop_reasons2)  \
   1386    SHR_BITEQ_RANGE(((_drop_reasons1).rbits), ((_drop_reasons2).rbits), 0, bcmPktDropReasonCount)
   1387  
   1388 
   1389 /* 
   1390  * Macro to negative compare two sets of reasons
   1391  * (bcm_pkt_drop_reasons_t).
   1392  */
   1393 #define BCM_PKT_DROP_REASON_NEQ(_drop_reasons1, _drop_reasons2)  \
   1394                 (!SHR_BITEQ_RANGE(((_drop_reasons1).rbits), ((_drop_reasons2).rbits), 0, bcmPktDropReasonCount))
   1395  
   1396 
   1397 /* 
   1398  * Macro to perform logical AND operation on two sets of reasons
   1399  * (bcm_pkt_drop_reasons_t).
   1400  */
   1401 #define BCM_PKT_DROP_REASON_AND(_drop_reasons1, _drop_reasons2)  \
   1402                 SHR_BITAND_RANGE(((_drop_reasons1).rbits), ((_drop_reasons2).rbits), 0, bcmPktDropReasonCount, ((_drop_reasons1).rbits))
   1403  
   1404 
   1405 /* 
   1406  * Macro to perform logical OR operation on two sets of reasons
   1407  * (bcm_pkt_drop_reasons_t).
   1408  */
   1409 #define BCM_PKT_DROP_REASON_OR(_drop_reasons1, _drop_reasons2)  \
   1410                 SHR_BITOR_RANGE(((_drop_reasons1).rbits), ((_drop_reasons2).rbits), 0, bcmPktDropReasonCount, ((_drop_reasons1).rbits))
   1411  
   1412 
   1413 /* 
   1414  * Macro to remove set of reasons2 (bcm_pkt_drop_reasons_t) from set of
   1415  * reasons1 (bcm_pkt_drop_reasons_t).
   1416  */
   1417 #define BCM_PKT_DROP_REASON_REMOVE(_drop_reasons1, _drop_reasons2)  \
   1418    SHR_BITREMOVE_RANGE(((_drop_reasons1).rbits), ((_drop_reasons2).rbits), 0, bcmPktDropReasonCount, ((_drop_reasons1).rbits)); 
   1419 
   1420 /* Macro to negate two sets of reasons (bcm_pkt_drop_reasons_t). */
   1421 #define BCM_PKT_DROP_REASON_NEGATE(_drop_reasons1, _drop_reasons2)  \
   1422                 SHR_BITNEGATE_RANGE(((_drop_reasons2).rbits), 0, bcmPktDropReasonCount, ((_drop_reasons1).rbits));
   1423  
   1424 
   1425 #endif /* __BCM_PKT_H__ */