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

dport.c (5642B)


      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 
      8 #include <shared/bsl.h>
      9 
     10 #include <sal/core/libc.h>
     11 
     12 #include <soc/drv.h>
     13 #include <soc/debug.h>
     14 #include <soc/error.h>
     15 #include <soc/dport.h>
     16 
     17 int
     18 soc_dport_to_port(int unit, soc_port_t dport)
     19 {
     20     if ((SOC_DPORT_MAP_FLAGS(unit) & SOC_DPORT_MAP_F_ENABLE) == 0) {
     21         if (SOC_PORT_VALID(unit, dport)) {
     22             return dport;
     23         }
     24         return -1;
     25     }
     26 
     27     if (dport >= 0 && dport < COUNTOF(SOC_DPORT_MAP(unit))) {
     28         return SOC_DPORT_MAP(unit)[dport];
     29     }
     30 
     31     return -1;
     32 }
     33 
     34 int
     35 soc_dport_from_port(int unit, soc_port_t port)
     36 {
     37     if ((SOC_DPORT_MAP_FLAGS(unit) & SOC_DPORT_MAP_F_ENABLE) == 0) {
     38         if (SOC_PORT_VALID(unit, port)) {
     39             return port;
     40         }
     41         return -1;
     42     }
     43 
     44     if (port >= 0 && port < COUNTOF(SOC_DPORT_RMAP(unit))) {
     45         return SOC_DPORT_RMAP(unit)[port];
     46     }
     47 
     48     return -1;
     49 }
     50 
     51 int
     52 soc_dport_from_dport_idx(int unit, soc_port_t dport, int idx)
     53 {
     54     if ((SOC_DPORT_MAP_FLAGS(unit) & SOC_DPORT_MAP_F_ENABLE) == 0 ||
     55         (SOC_DPORT_MAP_FLAGS(unit) & SOC_DPORT_MAP_F_INDEXED)) {
     56         return idx;
     57     }
     58     return dport;
     59 }
     60 
     61 int
     62 soc_dport_map_port(int unit, soc_port_t dport, soc_port_t port)
     63 {
     64     int idx;
     65 
     66     /* Check for valid ports */
     67     if (dport < 0 || dport >= SOC_DPORT_MAX ||
     68         port < 0 || port >= SOC_PBMP_PORT_MAX) {
     69         LOG_WARN(BSL_LS_SOC_COMMON,
     70                  (BSL_META_U(unit,
     71                              "soc_dport_map_port: Invalid port mapping %d -> %d\n"),
     72                   dport, port));
     73         return -1;
     74     }
     75 
     76     /* Silently discard invalid ports */
     77     if (!SOC_PORT_VALID(unit, port)) {
     78         return 0;
     79     }
     80 
     81     /* Remove previous mapping if any */
     82     for (idx = 0; idx < COUNTOF(SOC_DPORT_MAP(unit)); idx++) {
     83         if (SOC_DPORT_MAP(unit)[idx] == port) {
     84             SOC_DPORT_MAP(unit)[idx] = -1;
     85         }
     86     }
     87 
     88     /* Update port map */
     89     SOC_DPORT_MAP(unit)[dport] = port;
     90 
     91     return 0;
     92 }
     93 
     94 int
     95 soc_dport_map_update(int unit)
     96 {
     97     int idx, port, dport;
     98     soc_info_t *si = &SOC_INFO(unit);
     99 
    100     for (idx = 0; idx < COUNTOF(SOC_DPORT_RMAP(unit)); idx++) {
    101         SOC_DPORT_RMAP(unit)[idx] = -1;
    102     }
    103 
    104     for (idx = 0; idx < COUNTOF(SOC_DPORT_MAP(unit)); idx++) {
    105         port = SOC_DPORT_MAP(unit)[idx];
    106         if (port >= 0) {
    107             SOC_DPORT_RMAP(unit)[port] = idx;
    108         }
    109     }
    110 
    111     idx = 0;
    112     /* coverity[overrun-local : FALSE] */
    113     SOC_DPORT_PBMP_ITER(unit, PBMP_FE_ALL(unit), dport, port) {
    114         sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    115                      "fe%d", soc_dport_from_dport_idx(unit, dport, idx++));
    116     }
    117     idx = 0;
    118     /* coverity[overrun-local : FALSE] */
    119     SOC_DPORT_PBMP_ITER(unit, PBMP_XE_ALL(unit), dport, port) {
    120         sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    121                      "xe%d", soc_dport_from_dport_idx(unit, dport, idx++));
    122     }
    123     idx = 0;
    124     /* coverity[overrun-local : FALSE] */
    125     SOC_DPORT_PBMP_ITER(unit, PBMP_CE_ALL(unit), dport, port) {
    126         sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    127                      "ce%d", soc_dport_from_dport_idx(unit, dport, idx++));
    128     }
    129     idx = 0;
    130     /* coverity[overrun-local : FALSE] */
    131     SOC_DPORT_PBMP_ITER(unit, PBMP_CDE_ALL(unit), dport, port) {
    132         sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    133                      "cd%d", soc_dport_from_dport_idx(unit, dport, idx++));
    134     }
    135     idx = 0;
    136     /* coverity[overrun-local : FALSE] */
    137     SOC_DPORT_PBMP_ITER(unit, PBMP_HG_ALL(unit), dport, port) {
    138         sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    139                      "hg%d", soc_dport_from_dport_idx(unit, dport, idx++));
    140     }
    141     idx = 0;
    142     /* coverity[overrun-local : FALSE] */
    143     SOC_DPORT_PBMP_ITER(unit, PBMP_GE_ALL(unit), dport, port) {
    144         sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    145                      "ge%d", soc_dport_from_dport_idx(unit, dport, idx++));
    146     }
    147     if (soc_feature(unit, soc_feature_dport_update_hl)) {
    148         idx = 0;
    149         /* coverity[overrun-local : FALSE] */
    150         SOC_DPORT_PBMP_ITER(unit, PBMP_HL_ALL(unit), dport, port) {
    151             sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    152                          "hl%d", soc_dport_from_dport_idx(unit, dport, idx++));
    153         }
    154     }
    155     idx = 0;
    156     /* coverity[overrun-local : FALSE] */
    157     SOC_DPORT_PBMP_ITER(unit, PBMP_AXP_ALL(unit), dport, port) {
    158         sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    159                      "axp%d", soc_dport_from_dport_idx(unit, dport, idx++));
    160     }
    161     idx = 0;
    162     /* coverity[overrun-local : FALSE] */
    163     SOC_DPORT_PBMP_ITER(unit, PBMP_INTP_ALL(unit), dport, port) {
    164         sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    165                      "intp%d", soc_dport_from_dport_idx(unit, dport, idx++));
    166     }
    167     idx = 0;
    168     /* coverity[overrun-local : FALSE] */
    169     SOC_DPORT_PBMP_ITER(unit, PBMP_CPRI_ALL(unit), dport, port) {
    170         sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    171                      "roe%d", soc_dport_from_dport_idx(unit, dport, idx++));
    172     }
    173     /* coverity[overrun-local : FALSE] */
    174     SOC_DPORT_PBMP_ITER(unit, PBMP_RSVD4_ALL(unit), dport, port) {
    175         sal_snprintf(si->port_name[port], sizeof(si->port_name[port]),
    176                      "roe%d", soc_dport_from_dport_idx(unit, dport, idx++));
    177     }
    178 
    179     return 0;
    180 }