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

loopback.c (5307B)


      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  * Utility routines for managing loopback headers
      8  * These are mainly used for debug purposes
      9  */
     10 #include <shared/bsl.h>
     11 #include <assert.h>
     12 #include <sal/core/libc.h>
     13 #include <soc/error.h>
     14 #include <soc/debug.h>
     15 #include <soc/types.h>
     16 #include <soc/drv.h>
     17 #include <soc/pbsmh.h>
     18 #include <soc/cm.h>
     19 #include <soc/dcb.h>
     20 #include <soc/loopback.h>
     21 
     22 #ifdef BCM_XGS3_SWITCH_SUPPORT
     23 static char *soc_loopback_hdr_field_names[] = {
     24         /* NOTE: strings must match soc_loopback_hdr_field_t */
     25         "start",
     26         "input_pri",
     27         "visibility",
     28         "pkt_profile",
     29         "src",
     30         "src_type",
     31         "common_hdr",
     32         "cng",
     33         "tc",
     34         "zero",
     35         NULL
     36 };
     37 
     38 soc_loopback_hdr_field_t
     39 soc_loopback_hdr_name_to_field(int unit, char *name)
     40 {
     41     soc_loopback_hdr_field_t           f;
     42 
     43     assert(COUNTOF(soc_loopback_hdr_field_names) - 1 == LBMH_COUNT);
     44 
     45     COMPILER_REFERENCE(unit);
     46 
     47     for (f = 0; soc_loopback_hdr_field_names[f] != NULL; f++) {
     48         if (sal_strcmp(name, soc_loopback_hdr_field_names[f]) == 0) {
     49             return f;
     50         }
     51     }
     52 
     53     return LBMH_invalid;
     54 }
     55 
     56 char *
     57 soc_loopback_hdr_field_to_name(int unit, soc_loopback_hdr_field_t field)
     58 {
     59     COMPILER_REFERENCE(unit);
     60 
     61     assert(COUNTOF(soc_loopback_hdr_field_names) == LBMH_COUNT);
     62 
     63     if (field < 0 || field >= LBMH_COUNT) {
     64         return "??";
     65     } else {
     66         return soc_loopback_hdr_field_names[field];
     67     }
     68 }
     69 
     70 
     71 void
     72 soc_loopback_hdr_field_set(int unit, soc_loopback_hdr_t *lh,
     73                                   soc_loopback_hdr_field_t field, uint32 val)
     74 {
     75     switch(field) {
     76         case LBMH_start:      lh->start      =  val; break;
     77         case LBMH_input_pri:  lh->input_pri  =  val; break;
     78         case LBMH_common_hdr: 
     79              lh->common_hdr0 = (val >> 1) & 0xf;
     80              lh->common_hdr1 = val & 0x1;
     81              break;
     82         case LBMH_src_type:   lh->source_type=  val; break;
     83         case LBMH_src:        
     84              lh->source0        = ((val >> 10  ) & 0x3f);
     85              lh->source1        = ((val >> 2   ) & 0xff);
     86              lh->source2        =  (val & 0x3);
     87              break;
     88         case LBMH_visibility: lh->visibility =  val; break;
     89         case LBMH_pkt_profile:lh->pkt_profile=  val; break;
     90         case LBMH_pp_port:    lh->pp_port    =  val; break;                    
     91         default:
     92             break;
     93     }
     94     return;
     95 
     96 }
     97 
     98 uint32
     99 soc_loopback_hdr_field_get(int unit,soc_loopback_hdr_t * lh,soc_loopback_hdr_field_t field)
    100 
    101 {
    102     switch(field) {
    103         case LBMH_start:      return lh->start;
    104         case LBMH_input_pri:  return lh->input_pri;
    105         case LBMH_visibility: return lh->visibility;
    106         case LBMH_pkt_profile:return lh->pkt_profile;
    107         case LBMH_pp_port:    return lh->pp_port;
    108         case LBMH_src:
    109             return (((lh->source2) |
    110                     (lh->source1 << 2) | 
    111                     (lh->source0 <<10))) ;
    112         case LBMH_src_type:   return lh->source_type;
    113         case LBMH_common_hdr: 
    114             return ((lh->common_hdr0 << 1) | (lh->common_hdr1 & 0x1));
    115                     
    116         default:
    117                 return 0;
    118     }
    119 }
    120 
    121 
    122 void 
    123 soc_loopback_hdr_dump(int unit, char *pfx, soc_loopback_hdr_t *lh)
    124 {
    125     LOG_CLI((BSL_META_U(unit,
    126              "%s "
    127              "<START=0x%x INPUT_PRI=0x%x HEADER_TYPES=%d>\n"
    128              "%s "
    129              "<SOURCE_TYPE=%d SOURCE=%d VISIBILITY_PKT=%d>\n"
    130              "%s "
    131              "<PKT_PROFILE=%d PACKET_PROCESSING_PORT = 0x%x>\n"),
    132              pfx,
    133              soc_loopback_hdr_field_get(unit, lh, LBMH_start),
    134              soc_loopback_hdr_field_get(unit, lh, LBMH_input_pri),
    135              soc_loopback_hdr_field_get(unit, lh, LBMH_common_hdr),
    136              pfx,
    137              soc_loopback_hdr_field_get(unit, lh, LBMH_src_type),
    138              soc_loopback_hdr_field_get(unit, lh, LBMH_src),
    139              soc_loopback_hdr_field_get(unit, lh, LBMH_visibility),
    140              pfx,
    141              soc_loopback_hdr_field_get(unit, lh, LBMH_pkt_profile),
    142              soc_loopback_hdr_field_get(unit, lh, LBMH_pp_port)));
    143 
    144     return;
    145 }
    146 
    147 
    148 /*
    149  * Function:
    150  *     soc_loopback_lbport_num_get
    151  * Description:
    152  *      return FIRST loopback port of the chip
    153  * Parameters:
    154  *      unit         device number
    155  * Return:
    156  *      first loopbackport on the given device
    157  */
    158 int 
    159 soc_loopback_lbport_num_get(int unit, uint32 pipe) 
    160 {
    161     int port, lb_index=0,loopback_port_num=-1;
    162 #ifdef BCM_TOMAHAWK3_SUPPORT
    163     uint16 dev_id;
    164     uint8  rev_id;
    165 
    166     soc_cm_get_id(unit, &dev_id, &rev_id);
    167 #endif
    168 
    169     PBMP_LB_ITER(unit, port) {
    170         loopback_port_num = port;
    171 #ifdef BCM_TOMAHAWK3_SUPPORT
    172         /* For 56983 SKU, pipes are not contiguous so when lb port 139 is
    173            reached while iteration, we change the lb_index to 6 since it
    174            belongs to pipe 6
    175         */
    176         if ((port == 139) && (dev_id == BCM56983_DEVICE_ID)) {
    177             lb_index = 6;
    178         }
    179 #endif
    180         if (pipe == lb_index) {
    181             break;
    182         }
    183         lb_index++;
    184     }
    185     return loopback_port_num;
    186 
    187 }
    188 #endif /* BCM_XGS3_SWITCH_SUPPORT*/
    189