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

init.c (4025B)


      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:        init.c
      8  * Purpose:     device initialization
      9  */
     10 
     11 #include <soc/drv.h>
     12 #include <sal/core/time.h>
     13 #include <sal/core/boot.h>
     14 #include <bcm/init.h>
     15 #include <bcm/port.h>
     16 #include <bcm/link.h>
     17 #include <bcm/stat.h>
     18 #include <bcm/error.h>
     19 #include <board_int/support.h>
     20 
     21 
     22 #define BCM_IF_NOT_UNAVAIL_ERROR_RETURN(x) { \
     23   int _rv = x; \
     24   if (_rv != BCM_E_UNAVAIL) {  BCM_IF_ERROR_RETURN(_rv); } \
     25 } while (0)
     26 
     27 
     28 /*
     29  * Function:
     30  *     board_port_init
     31  * Purpose:
     32  *     Initialize ports on a unit to a known state, and initialize
     33  *     services on the ports
     34  * Parameters:
     35  *     unit - (IN) BCM device number
     36  * Returns:
     37  *     BCM_E_NONE - success
     38  *     BCM_E_XXX - failed
     39  */
     40 
     41 int
     42 board_port_init(int unit)
     43 {
     44     sal_usecs_t usec;
     45     bcm_port_config_t  config;
     46     bcm_port_t port;
     47     int rv;
     48 
     49     usec = soc_property_get(unit, spn_BCM_LINKSCAN_INTERVAL,
     50                             BCM_LINKSCAN_INTERVAL_DEFAULT);
     51     BCM_IF_ERROR_RETURN(bcm_linkscan_enable_set(unit, usec));
     52 
     53     BCM_IF_ERROR_RETURN(bcm_port_config_get(unit, &config));
     54 
     55     BCM_PBMP_ITER(config.port, port) {
     56         int abil;
     57 
     58         rv = bcm_port_stp_set(unit, port, (int)BCM_PORT_STP_FORWARD);
     59         BCM_IF_NOT_UNAVAIL_ERROR_RETURN(rv);
     60         
     61         rv = bcm_port_ability_get(unit, port, (bcm_port_abil_t *)&abil);
     62         if (BCM_SUCCESS(rv)) {
     63             rv = bcm_port_advert_set(unit, port, abil);
     64         }
     65         BCM_IF_NOT_UNAVAIL_ERROR_RETURN(rv);
     66 
     67         rv = bcm_port_autoneg_set(unit, port, TRUE);
     68         BCM_IF_NOT_UNAVAIL_ERROR_RETURN(rv);
     69 
     70         rv = bcm_linkscan_mode_set(unit, port, BCM_LINKSCAN_MODE_SW);
     71         BCM_IF_NOT_UNAVAIL_ERROR_RETURN(rv);
     72 
     73         rv = bcm_stat_clear(unit, port);
     74         BCM_IF_ERROR_RETURN(rv);
     75 
     76         rv = bcm_port_learn_set(unit, port,
     77                                 BCM_PORT_LEARN_ARL | BCM_PORT_LEARN_FWD);
     78         BCM_IF_NOT_UNAVAIL_ERROR_RETURN(rv);
     79     }
     80     return BCM_E_NONE;
     81 }
     82 
     83 /*
     84  * Function:
     85  *     board_port_deinit
     86  * Purpose:
     87  *     Undo port initialization
     88  * Parameters:
     89  *     unit - (IN) BCM device number
     90  * Returns:
     91  *     BCM_E_NONE - success
     92  *     BCM_E_XXX - failed
     93  */
     94 int
     95 board_port_deinit(int unit)
     96 {
     97     return bcm_linkscan_detach(unit);
     98 }
     99 
    100 /*
    101  * Function:
    102  *     board_device_init
    103  * Purpose:
    104  *     Architecture independent device initialization
    105  * Parameters:
    106  *     unit - (IN) BCM device number
    107  * Returns:
    108  *     BCM_E_NONE - success
    109  *     BCM_E_XXX - failed
    110  */
    111 int
    112 board_device_init(int unit)
    113 {
    114     BCM_IF_ERROR_RETURN(board_device_reset(unit));
    115     BCM_IF_ERROR_RETURN(bcm_init(unit));
    116     if ((SAL_BOOT_SIMULATION) && (!SAL_BOOT_BCMSIM)) {
    117         /* When in PCID simulation, initialize all the modules needed
    118            by any of the board drivers that bcm_init() skips. */
    119         BCM_IF_ERROR_RETURN(bcm_trunk_init(unit));
    120     }
    121 
    122     return BCM_E_NONE;
    123 }
    124 
    125 /*
    126  * Function:
    127  *     board_device_deinit
    128  * Purpose:
    129  *     Deinitialize device
    130  * Parameters:
    131  *     unit - (IN) BCM device number
    132  * Returns:
    133  *     BCM_E_NONE - success
    134  *     BCM_E_XXX - failed
    135  */
    136 int
    137 board_device_deinit(int unit)
    138 {
    139     /* nothing for now */
    140     return BCM_E_NONE;
    141     
    142 }
    143 
    144 /*
    145  * Function:
    146  *     board_device_cpu_port_get
    147  * Purpose:
    148  *     Get the first CPU port of a device
    149  * Parameters:
    150  *     unit - (IN) BCM device number
    151  * Returns:
    152  *     BCM_E_NONE - success
    153  *     BCM_E_XXX - failed
    154  */
    155 int
    156 board_device_cpu_port_get(int unit, bcm_gport_t *cpu)
    157 {
    158     bcm_port_config_t port_info;
    159     int port = -1;
    160     int rv = BCM_E_NOT_FOUND;
    161 
    162     if (!cpu) {
    163         return BCM_E_PARAM;
    164     }
    165 
    166     BCM_IF_ERROR_RETURN(bcm_port_config_get(unit, &port_info));
    167     
    168     BCM_PBMP_ITER(port_info.cpu, port) {
    169         break;
    170     }
    171 
    172     if (port >= 0) {
    173         *cpu = BCM_GPORT_DEVPORT(unit, port);
    174         rv = BCM_E_NONE;
    175     }
    176 
    177     return rv;
    178 }