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

proc_hdr.c (12021B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        proc_hdr.h
      8  */
      9 
     10 #include <shared/bsl.h>
     11 
     12 #include <assert.h>
     13 #include <sal/core/libc.h>
     14 #include <shared/bsl.h>
     15 
     16 #include <soc/drv.h>
     17 #include <soc/types.h>
     18 #include <soc/proc_hdr.h>
     19 #include <soc/enet.h>
     20 #include <soc/cm.h>
     21 #include <soc/debug.h>
     22 
     23 #if defined(BCM_XGS_SUPPORT) && defined(BCM_CPU_TX_PROC_SUPPORT)
     24 
     25 static char *soc_proc_hdr_field_names[] = {
     26     SOC_PROC_HDR_FIELD_NAMES_INIT
     27 };
     28 
     29 /*
     30  * Function Name:
     31  *         soc_proc_hdr_name_to_field
     32  * Purpose:
     33  *         To convert field name to the field
     34  * Parameters:
     35  *         [IN] unit - unit number
     36  *         [IN] name - ascii name of the field
     37  * Return:
     38  *         Proc HDR Field or invalid code
     39  */
     40 soc_proc_hdr_field_t
     41 soc_proc_hdr_name_to_field(int unit, char *name)
     42 {
     43     soc_proc_hdr_field_t		f;
     44 
     45     assert(COUNTOF(soc_proc_hdr_field_names) - 1 == PH_COUNT);
     46 
     47     COMPILER_REFERENCE(unit);
     48 
     49     for (f = 0; soc_proc_hdr_field_names[f] != NULL; f++) {
     50 	if (sal_strcmp(name, soc_proc_hdr_field_names[f]) == 0) {
     51 	    return f;
     52 	}
     53     }
     54 
     55     return PH_invalid;
     56 }
     57 
     58 /*
     59  * Function Name:
     60  *         soc_proc_hdr_field_to_name
     61  * Purpose:
     62  *         To convert field to field name
     63  * Parameters:
     64  *         [IN] unit - unit number
     65  *         [IN] name - field in the proc hdr
     66  * Return:
     67  *         Field character name or ?? on ERROR
     68  */
     69 char *
     70 soc_proc_hdr_field_to_name(int unit, soc_proc_hdr_field_t field)
     71 {
     72     COMPILER_REFERENCE(unit);
     73 
     74     assert(COUNTOF(soc_proc_hdr_field_names) == PH_COUNT);
     75 
     76     if (field < 0 || field >= PH_COUNT) {
     77 	return "??";
     78     } else {
     79 	return soc_proc_hdr_field_names[field];
     80     }
     81 }
     82 
     83 /*
     84  * Function Name:
     85  *         soc_proc_hdr_field_set
     86  * Purpose:
     87  *         To set the value of a field in the proc header
     88  * Parameters:
     89  *         [IN] unit  - unit number
     90  *         [INOUT] ph    - proc header to be modified
     91  *         [IN] field - field to be modified
     92  *         [IN] val   - value of the field
     93  * Return:
     94  *         None
     95  */
     96 void
     97 soc_proc_hdr_field_set(int unit, soc_proc_hdr_t *ph,
     98                        soc_proc_hdr_field_t field, uint32 val)
     99 {
    100     COMPILER_REFERENCE(unit);
    101 
    102     switch (field) {
    103         case PH_start:
    104             ph->overlay1.start = val;
    105             break;
    106         case PH_input_pri:
    107             ph->overlay1.input_pri = val;
    108             break;
    109         case PH_header_types:
    110             ph->overlay1.header_types_4_1 = ((val >> 1) & 0xf);
    111             ph->overlay1.header_types_0 = (val & 0x1);
    112             break;
    113         case PH_source_type:
    114             ph->overlay1.source_type = val;
    115             break;
    116         case PH_source:
    117             ph->overlay1.source_15_10 = ((val >> 10) & 0x3f);
    118             ph->overlay1.source_9_2 = ((val >> 2) & 0xff);
    119             ph->overlay1.source_1_0 = (val & 0x3);
    120             break;
    121         case PH_visibility_pkt:
    122             ph->overlay1.visibility_pkt = val;
    123             break;
    124         case PH_pkt_profile:
    125             ph->overlay1.pkt_profile = val;
    126             break;
    127         case PH_mcast_lb_idx_valid:
    128             ph->overlay1.mcast_lb_idx_valid = val;
    129             break;
    130         case PH_mcast_lb_idx:
    131             ph->overlay1.mcast_lb_idx_7_2 = ((val >> 2) & 0x3f);
    132             ph->overlay1.mcast_lb_idx_1_0 = (val & 0x3);
    133             break;
    134         case PH_zero:
    135             ph->overlay1.zero = val;
    136             break;
    137         case PH_ecmp_member_id:
    138             ph->overlay1.ecmp_member_id_11_4 = ((val >> 4) & 0xff);
    139             ph->overlay1.ecmp_member_id_3_0 = (val & 0xf);
    140             break;
    141         case PH_dp:
    142             ph->overlay1.dp = val;
    143             break;
    144         case PH_int_pri:
    145             ph->overlay1.int_pri_3_2 = ((val >> 2) & 0x3);
    146             ph->overlay1.int_pri_1_0 = (val & 0x3);
    147             break;
    148         case PH_int_cn:
    149             ph->overlay1.int_cn = val;
    150             break;
    151         case PH_qos_fields_valid:
    152             ph->overlay1.qos_fields_valid = val;
    153             break;
    154         case PH_routed_pkt:
    155             ph->overlay1.routed_pkt = val;
    156             break;
    157         case PH_destination:
    158             ph->overlay1.destination_15_10 = ((val >> 10) & 0x3f);
    159             ph->overlay1.destination_9_2 = ((val >> 2) & 0xff);
    160             ph->overlay1.destination_1_0 = (val & 0x3);
    161             break;
    162         case PH_destination_type:
    163             ph->overlay1.destination_type = val;
    164             break;
    165         case PH_subflow_type:
    166             ph->overlay1.subflow_type = val;
    167             break;
    168         case PH_pp_port:
    169             ph->overlay1.pp_port = val;
    170             break;
    171         default:
    172 	    LOG_WARN(BSL_LS_SOC_COMMON,
    173                     (BSL_META_U(unit,
    174                     "proc_hdr_set: unit %d: Unknown proc hdr field=%d val=0x%x\n"),
    175                     unit, field, val));
    176 	    break;
    177     }
    178 }
    179 
    180 /*
    181  * Function Name:
    182  *         soc_proc_hdr_field_get
    183  * Purpose:
    184  *         To get the value of a field in the proc header
    185  * Parameters:
    186  *         [IN] unit  - unit number
    187  *         [IN] ph    - proc header to be modified
    188  *         [IN] field - field to be modified
    189  * Return:
    190  *         value of the field, if field is not found then Log Warning
    191  */
    192 uint32
    193 soc_proc_hdr_field_get(int unit, soc_proc_hdr_t *ph,
    194                        soc_proc_hdr_field_t field)
    195 {
    196     COMPILER_REFERENCE(unit);
    197 
    198     switch (field) {
    199         case PH_start:
    200             return ph->overlay1.start;
    201         case PH_input_pri:
    202             return ph->overlay1.input_pri;
    203         case PH_header_types:
    204             return ((ph->overlay1.header_types_4_1 << 1) | ph->overlay1.header_types_0);
    205         case PH_source_type:
    206             return ph->overlay1.source_type;
    207         case PH_source:
    208             return ((ph->overlay1.source_15_10 << 10) |
    209                     (ph->overlay1.source_9_2 << 2) |
    210                     (ph->overlay1.source_1_0));
    211         case PH_visibility_pkt:
    212             return ph->overlay1.visibility_pkt;
    213         case PH_pkt_profile:
    214             return ph->overlay1.pkt_profile;
    215         case PH_mcast_lb_idx_valid:
    216             return ph->overlay1.mcast_lb_idx_valid;
    217         case PH_mcast_lb_idx:
    218             return ((ph->overlay1.mcast_lb_idx_7_2 << 2) |
    219                     (ph->overlay1.mcast_lb_idx_1_0));
    220         case PH_zero:
    221             return ph->overlay1.zero;
    222         case PH_ecmp_member_id:
    223             return ((ph->overlay1.ecmp_member_id_11_4 << 4) |
    224                     (ph->overlay1.ecmp_member_id_3_0));
    225         case PH_dp:
    226             return ph->overlay1.dp;
    227         case PH_int_pri:
    228             return ((ph->overlay1.int_pri_3_2 << 2) |
    229                     (ph->overlay1.int_pri_1_0));
    230         case PH_int_cn:
    231             return ph->overlay1.int_cn;
    232         case PH_qos_fields_valid:
    233             return ph->overlay1.qos_fields_valid;
    234         case PH_routed_pkt:
    235             return ph->overlay1.routed_pkt;
    236         case PH_destination:
    237             return ((ph->overlay1.destination_15_10 << 10) |
    238                    (ph->overlay1.destination_9_2 << 2) |
    239                    (ph->overlay1.destination_1_0));
    240         case PH_destination_type:
    241             return ph->overlay1.destination_type;
    242         case PH_subflow_type:
    243             return ph->overlay1.subflow_type;
    244         case PH_pp_port:
    245             return ph->overlay1.pp_port;
    246         default:
    247 	    LOG_WARN(BSL_LS_SOC_COMMON,
    248                     (BSL_META_U(unit,
    249                     "proc_hdr_get: unit %d: Unknown proc hdr field=%d\n"),
    250                     unit, field));
    251 	    return 0;
    252     }
    253 }
    254 
    255 /*
    256  * Function Name:
    257  *         soc_proc_hdr_field_dump
    258  * Purpose:
    259  *         to output the entire proc header in a user friendly format
    260  * Parameters:
    261  *         [IN] unit - unit number
    262  *         [IN] pfx  - character prefix to be appended to the header output.
    263  *         [IN] ph   - proc header to be modified
    264  * Return:
    265  *         None
    266  */
    267 void
    268 soc_proc_hdr_dump(int unit, char *pfx, soc_proc_hdr_t *ph)
    269 {
    270     LOG_CLI((BSL_META_U(unit,
    271                         "%s0x%02x%02x%02x%02x%02x "
    272              "<START=0x%x INPUT_PRI=0x%x HEADER_TYPES=%d SOURCE_TYPE=%d SOURCE=%d VISIBILITY_PKT=%d PKT_PROFILE=%d\n"),
    273              pfx,
    274              ph->overlay0.bytes[0],
    275              ph->overlay0.bytes[1],
    276              ph->overlay0.bytes[2],
    277              ph->overlay0.bytes[3],
    278              ph->overlay0.bytes[4],
    279              soc_proc_hdr_field_get(unit, ph, PH_start),
    280              soc_proc_hdr_field_get(unit, ph, PH_input_pri),
    281              soc_proc_hdr_field_get(unit, ph, PH_header_types),
    282              soc_proc_hdr_field_get(unit, ph, PH_source_type),
    283              soc_proc_hdr_field_get(unit, ph, PH_source),
    284              soc_proc_hdr_field_get(unit, ph, PH_visibility_pkt),
    285              soc_proc_hdr_field_get(unit, ph, PH_pkt_profile)));
    286 
    287     LOG_CLI((BSL_META_U(unit,
    288                         "%s0x%02x%02x%02x "
    289              "<MCAST_LB_IDX_VALID=%d MCAST_LB_IDX=%d ZERO=%d>\n"),
    290              pfx,
    291              ph->overlay0.bytes[5],
    292              ph->overlay0.bytes[6],
    293              ph->overlay0.bytes[7],
    294              soc_proc_hdr_field_get(unit, ph, PH_mcast_lb_idx_valid),
    295              soc_proc_hdr_field_get(unit, ph, PH_mcast_lb_idx),
    296              soc_proc_hdr_field_get(unit, ph, PH_zero)));
    297 
    298     LOG_CLI((BSL_META_U(unit,
    299                         "%s0x%02x%02x%02x%02x "
    300              "<ECMP_MEMBER_ID=%d DP=%d INT_PRI=%d INT_CN=%d QOS_FIELD_VALID=%d ROUTED_PKT=%d>\n"),
    301              pfx,
    302              ph->overlay0.bytes[8],
    303              ph->overlay0.bytes[9],
    304              ph->overlay0.bytes[10],
    305              ph->overlay0.bytes[11],
    306              soc_proc_hdr_field_get(unit, ph, PH_ecmp_member_id),
    307              soc_proc_hdr_field_get(unit, ph, PH_dp),
    308              soc_proc_hdr_field_get(unit, ph, PH_int_pri),
    309              soc_proc_hdr_field_get(unit, ph, PH_int_cn),
    310              soc_proc_hdr_field_get(unit, ph, PH_qos_fields_valid),
    311              soc_proc_hdr_field_get(unit, ph, PH_routed_pkt)));
    312 
    313     LOG_CLI((BSL_META_U(unit,
    314                         "%s0x%02x%02x%02x%02x "
    315              "<DESTINATION=%d DESTINATION_TYPE=%d SUBFLOW_TYPE=%d PP_PORT=%d>\n"),
    316              pfx,
    317              ph->overlay0.bytes[12],
    318              ph->overlay0.bytes[13],
    319              ph->overlay0.bytes[14],
    320              ph->overlay0.bytes[15],
    321              soc_proc_hdr_field_get(unit, ph, PH_destination),
    322              soc_proc_hdr_field_get(unit, ph, PH_destination_type),
    323              soc_proc_hdr_field_get(unit, ph, PH_subflow_type),
    324              soc_proc_hdr_field_get(unit, ph, PH_pp_port)));
    325 }
    326 
    327 /*
    328  * Function:
    329  *     soc_lbport_num_get
    330  * Description:
    331  *      return FIRST loopback port of the chip
    332  * Parameters:
    333  *      unit         device number
    334  * Return:
    335  *      first loopback port on the given device
    336  */
    337 int
    338 soc_lbport_num_get(int unit, uint32 pipe)
    339 {
    340     int port, lb_index = 0, loopback_port_num = -1;
    341 #ifdef BCM_TOMAHAWK3_SUPPORT
    342     uint16 dev_id;
    343     uint8  rev_id;
    344 
    345     soc_cm_get_id(unit, &dev_id, &rev_id);
    346 #endif
    347 
    348     PBMP_LB_ITER(unit, port) {
    349         loopback_port_num = port;
    350 #ifdef BCM_TOMAHAWK3_SUPPORT
    351         /* For 56983 SKU, pipes are not contiguous so when lb port 139 is
    352            reached while iteration, we change the lb_index to 6 since it
    353            belongs to pipe 6
    354         */
    355         if ((port == 139) && (dev_id == BCM56983_DEVICE_ID)) {
    356             lb_index = 6;
    357         }
    358 #endif
    359 
    360         if (pipe == lb_index) {
    361             break;
    362         }
    363         lb_index++;
    364     }
    365 
    366    return loopback_port_num;
    367 }
    368 
    369 /*
    370  * Function:
    371  *     soc_pipe_get
    372  * Description:
    373  *      return the pipe of the chip
    374  * Parameters:
    375  *      unit             device number
    376  *      logical_src_port source port
    377  * Return:
    378  *      pipe number based on logical src port
    379  */
    380 int
    381 soc_pipe_get(int unit, uint32 logical_src_port)
    382 {
    383     soc_info_t  *si;
    384     si = &SOC_INFO(unit);
    385 
    386     return si->port_pipe[logical_src_port];
    387 }
    388 
    389 #endif /* BCM_XGS_SUPPORT && BCM_CPU_TX_PROC_SUPPORT */