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

phymod_ids.c (3500B)


      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:        phymod_ids.c
      8  * Purpose:     These routines and structures are related to
      9  *              figuring out core and phy IDs correlating specific device
     10  */
     11 
     12 #include <soc/drv.h>
     13 
     14 /*
     15  * Function:
     16  *      soc_phymod_default_core_id_get
     17  * Purpose:
     18  *      Return the default PHY core_id and phy_ids for logical port
     19  * Parameters:
     20  *      unit - StrataSwitch unit number
     21  *      port - logical port numer
     22  *      max_phys - max size of phy_ids
     23  *      core_id - (OUT) returned core_id
     24  *      phy_ids - (OUT) returned phy_ids
     25  */
     26 
     27 STATIC int
     28 soc_phymod_default_core_id_get(int unit, int port, uint32 max_cores, uint32 max_phys,
     29                                uint32 *num_cores, uint32 *core_id, uint32 *phy_ids)
     30 {
     31     int num_lanes_in_core = 4; /* This can be ovveride per unit, 
     32                                   in each unit must keep constant */
     33     soc_info_t *si;
     34     int phy_port;  
     35     int phy_ids_index = 0;
     36     int cid, pid;
     37     int in_core_offset;
     38 
     39     si = &SOC_INFO(unit);
     40 
     41     /* Calculate num of cores */
     42     (*num_cores) = (si->port_num_lanes[port] + num_lanes_in_core - 1) / num_lanes_in_core;
     43 
     44     /* Validate array sizes */
     45     if(max_cores < (*num_cores)) {
     46         return SOC_E_INTERNAL;
     47     }
     48 
     49     if(max_phys < (*num_cores) * num_lanes_in_core) {
     50         return SOC_E_INTERNAL;
     51     }
     52 
     53     /* Get first physical port */
     54     if (soc_feature(unit, soc_feature_logical_port_num)) {
     55         phy_port = si->port_l2p_mapping[port];
     56     } else {
     57         phy_port = port;
     58     }
     59     in_core_offset = SOC_PORT_BINDEX(unit, phy_port) % num_lanes_in_core;
     60 
     61     /* Set IDs */
     62     for(cid = 0 ; cid<(*num_cores) ; cid++) {
     63         core_id[cid] = in_core_offset / num_lanes_in_core + cid;
     64 
     65         for(pid=0 ; pid<num_lanes_in_core ; pid++) {
     66             /* core offset * max lanes in core + lane offset */
     67             phy_ids[phy_ids_index] = core_id[cid] * num_lanes_in_core + pid;
     68             phy_ids_index++;
     69         }
     70     }
     71 
     72     return SOC_E_NONE;
     73 }
     74 
     75 /*
     76  * Function:
     77  *      soc_phymod_core_id_get
     78  * Purpose:
     79  *      Return the PHY core_id and phy_ids for logical port
     80  * Parameters:
     81  *      unit - StrataSwitch unit number
     82  *      port - logical port numer
     83  *      max_phys - max size of phy_ids
     84  *      core_id - (OUT) returned core_id
     85  *      phy_ids - (OUT) returned phy_ids
     86  *  
     87  * Note: 
     88  *      The function contains default indexing for core ids and phy ids
     89  *      Assuming there are maximum 4 lanes per core
     90  *      Devices that need other calculation required to implement inside their own indexing
     91  */
     92 int
     93 soc_phymod_core_id_get(int unit, int port, uint32 max_cores, uint32 max_phys,
     94                        uint32 *num_cores, uint32 *core_id, uint32 *phy_ids)
     95 {
     96     return soc_phymod_default_core_id_get(unit, port, max_cores, max_phys,
     97                                           num_cores, core_id, phy_ids);
     98 }
     99 
    100 /*
    101  * Function:
    102  *      soc_phymod_broadcast_id_offset
    103  * Purpose:
    104  *      Return the first broadcast_id.
    105  * Parameters:
    106  *      unit - StrataSwitch unit number
    107  *      broadcast_id_offset - (OUT) first allowed broadcast if
    108  *  
    109  * Note: 
    110  *      The actual broadcast ID will be broadcast_id_offset + phy_id
    111  */
    112 int 
    113 soc_phymod_broadcast_id_offset(int unit, uint32 *broadcast_id_offset)
    114 {
    115     *broadcast_id_offset = 400;
    116 
    117     return SOC_E_NONE;
    118 }