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

subport.h (31592B)


      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  * This file contains subport definitions internal to the BCM library.
      8  */
      9 
     10 #include <sal/core/sync.h>
     11 #include <bcm/subport.h>
     12 #include <soc/scache.h>
     13 
     14 #ifndef _BCM_INT_ESW_SUBPORT_H_
     15 #define _BCM_INT_ESW_SUBPORT_H_
     16 
     17 /** Raghu Start change */
     18 
     19 /*****************************************
     20 * Subport CoE common section - start
     21  */
     22 
     23 /* The common data structures between KT2 and TD2+ Subport-CoE 
     24    implementation */
     25 
     26 /* SUBPORT GPORT CoE subtype shift & mask definitions */
     27 
     28 /* Subport CoE Common defines */
     29 
     30 #define _BCM_COE_PORT_TYPE_ETHERNET         0
     31 #define _BCM_COE_PORT_TYPE_CASCADED         4
     32 #define _BCM_COE_PORT_TYPE_CASCADED_LINKPHY 0
     33 #define _BCM_COE_PORT_TYPE_CASCADED_SUBTAG  1
     34 
     35 /* Subport group type defs */
     36 #define _BCM_SUBPORT_COE_TYPE_ETHERNET              0
     37 #define _BCM_SUBPORT_COE_TYPE_CASCADED              1
     38 
     39 /* Subport type defs */
     40 #define _BCM_SUBPORT_COE_TYPE_LINKPHY               2
     41 #define _BCM_SUBPORT_COE_TYPE_SUBTAG                3
     42 #define _BCM_SUBPORT_COE_TYPE_GENERAL               1
     43 
     44 /*
     45 * LinkPHY/SubTag Subport group gport format 
     46 * bit 31-26 -- gport type (subport group)
     47 * bit 25-24 -- subport group type (cascaded)
     48 * bit 19-18 -- subport subtype (linkphy / subtag / general)
     49 * bit 17    -- subport group is trunk indicator
     50 * bit 16-9  -- subport group port number/trunk group id
     51 * bit 8-0   -- subport group index
     52 */
     53 #define _BCM_SUBPORT_COE_GROUP_TYPE_MASK      0x3
     54 #define _BCM_SUBPORT_COE_GROUP_TYPE_SHIFT     24
     55 #define _BCM_SUBPORT_COE_GROUP_SUBTYPE_MASK   0x3
     56 #define _BCM_SUBPORT_COE_GROUP_SUBTYPE_SHIFT  18
     57 #define _BCM_SUBPORT_COE_GROUP_PORT_MASK      0xFF
     58 #define _BCM_SUBPORT_COE_GROUP_PORT_SHIFT     9
     59 #define _BCM_SUBPORT_COE_GROUP_SPGID_MASK     0x1FF
     60 #define _BCM_SUBPORT_COE_GROUP_SPGID_SHIFT    0
     61 
     62 /*
     63 * LinkPHY/SubTag Subport port gport format 
     64 * bit 31-26  -- gport type (subport port)
     65 * bit 25-24  -- subport port type (LinkPHY / SubTag/ General)
     66 * bit 23-15  -- zero
     67 * bit 14-07  -- subport module index(range 0 to 255) 
     68 * bit 06-00  -- subport port index  (range 0 to 127) 
     69 */
     70 
     71 #define _BCM_SUBPORT_COE_PORT_TYPE_MASK         0x3
     72 #define _BCM_SUBPORT_COE_PORT_TYPE_SHIFT        24
     73 #define _BCM_SUBPORT_COE_PORT_ZERO_BITS_MASK    0x1FF
     74 #define _BCM_SUBPORT_COE_PORT_ZERO_BITS_SHIFT   15
     75 #define _BCM_SUBPORT_COE_PORT_MODULE_MASK       0xFF
     76 #define _BCM_SUBPORT_COE_PORT_MODULE_SHIFT      7
     77 #define _BCM_SUBPORT_COE_PORT_PORT_MASK         0x7F
     78 #define _BCM_SUBPORT_COE_PORT_PORT_SHIFT        0
     79 
     80 #define _BCM_SUBPORT_COE_PORT_VALUE_MASK        0x7FFF
     81 
     82 #define BCM_SUBPORT_COE_DEFAULT_ETHERTYPE       0x8874
     83 
     84 /* Check if gport is LinkPHY subport_group */
     85 #define _BCM_COE_GPORT_IS_LINKPHY_SUBPORT_GROUP(_subport_group)    \
     86         ((((_subport_group >> _BCM_SUBPORT_COE_GROUP_SUBTYPE_SHIFT) & \
     87             _BCM_SUBPORT_COE_GROUP_SUBTYPE_MASK) ==    \
     88             _BCM_SUBPORT_COE_TYPE_LINKPHY) && \
     89          (((_subport_group >> _BCM_SUBPORT_COE_GROUP_TYPE_SHIFT) & \
     90             _BCM_SUBPORT_COE_GROUP_TYPE_MASK) ==    \
     91             _BCM_SUBPORT_COE_TYPE_CASCADED))
     92 
     93 
     94 /* Check if gport is SubTag subport_group */
     95 #define _BCM_COE_GPORT_IS_SUBTAG_SUBPORT_GROUP(_subport_group)    \
     96         ((((_subport_group >> _BCM_SUBPORT_COE_GROUP_SUBTYPE_SHIFT) & \
     97             _BCM_SUBPORT_COE_GROUP_SUBTYPE_MASK) ==    \
     98             _BCM_SUBPORT_COE_TYPE_SUBTAG) && \
     99          (((_subport_group >> _BCM_SUBPORT_COE_GROUP_TYPE_SHIFT) & \
    100             _BCM_SUBPORT_COE_GROUP_TYPE_MASK) ==    \
    101             _BCM_SUBPORT_COE_TYPE_CASCADED))
    102 
    103 
    104 /* Check if gport is general subport_group */
    105 #define _BCM_COE_GPORT_IS_GENERAL_SUBPORT_GROUP(_subport_group)    \
    106     ((((_subport_group >> _BCM_SUBPORT_COE_GROUP_SUBTYPE_SHIFT) & \
    107        _BCM_SUBPORT_COE_GROUP_SUBTYPE_MASK) ==    \
    108       _BCM_SUBPORT_COE_TYPE_GENERAL) && \
    109      (((_subport_group >> _BCM_SUBPORT_COE_GROUP_TYPE_SHIFT) & \
    110        _BCM_SUBPORT_COE_GROUP_TYPE_MASK) ==    \
    111       _BCM_SUBPORT_COE_TYPE_CASCADED))
    112 
    113 /* Set the subport port gport  type */
    114 #define _BCM_SUBPORT_COE_PORT_TYPE_SET(_subport_port, _type)  \
    115     (_subport_port |= ((_type & _BCM_SUBPORT_COE_PORT_TYPE_MASK) \
    116           << _BCM_SUBPORT_COE_PORT_TYPE_SHIFT))
    117 
    118 
    119 /* Get port number/trunk id associated with subport_group gport */
    120 #define _BCM_SUBPORT_COE_GROUP_PORT_GET(_subport_group) \
    121         ((_subport_group >> _BCM_SUBPORT_COE_GROUP_PORT_SHIFT) & \
    122             _BCM_SUBPORT_COE_GROUP_PORT_MASK)
    123 
    124 /* Get group id associated with subport_group gport */
    125 #define _BCM_SUBPORT_COE_GROUP_ID_GET(_subport_group) \
    126         (((_subport_group) >> _BCM_SUBPORT_COE_GROUP_SPGID_SHIFT) & \
    127             _BCM_SUBPORT_COE_GROUP_SPGID_MASK)
    128 
    129 #define _BCM_SUBPORT_COE_GROUP_TYPE_CASCADED_SET(_subport_group) \
    130     ((_subport_group) |= ((_BCM_SUBPORT_COE_TYPE_CASCADED & \
    131                           _BCM_SUBPORT_COE_GROUP_TYPE_MASK) \
    132                               << _BCM_SUBPORT_COE_GROUP_TYPE_SHIFT))
    133  
    134 /*
    135  * Subtended port Function Vector Driver
    136  */
    137 typedef struct bcm_esw_subport_drv_s {
    138     /*
    139      * Subport APIs
    140      */
    141 
    142     /* Initial subport module handlers */
    143 
    144     /* Initalize enhanced subport module */
    145     int (*subport_init)(int unit);
    146     /* Create Subport group */
    147     int (*subport_group_create)(int unit, bcm_subport_group_config_t *config,
    148              bcm_gport_t *group);
    149     /* Delete Subport group */
    150     int (*subport_group_get)(int unit, bcm_gport_t group,
    151              bcm_subport_group_config_t *config);
    152     /* Traverse Subport group */
    153     int (*subport_group_traverse)(int unit, bcm_gport_t subport_group,
    154                           bcm_subport_port_traverse_cb cb, void *user_data);
    155     /* Destroy Subport group */
    156     int (*subport_group_destroy)(int unit, bcm_gport_t group);
    157     /* Set LinkPhy config */
    158     int (*subport_linkphy_config_set)(int unit, bcm_gport_t port,
    159            bcm_subport_group_linkphy_config_t *linkphy_config);
    160     /* Get LinkPhy config */
    161     int (*subport_linkphy_config_get)(int unit, bcm_gport_t port,
    162            bcm_subport_group_linkphy_config_t *linkphy_config);   
    163 
    164     /* Subport port add */
    165     int (*subport_port_add)(int unit, bcm_subport_config_t *config, 
    166                             bcm_gport_t *port); 
    167     /* Subport port get */
    168     int (*subport_port_get)(int unit, bcm_gport_t port, 
    169                             bcm_subport_config_t *config);
    170     /* Subport port traverse */
    171     int (*subport_port_traverse)(int unit, 
    172                                  bcm_subport_port_traverse_cb cb, 
    173                                  void *user_data);
    174     /* Subport port stat set */
    175     int (*subport_port_stat_set)(int unit, bcm_gport_t port, 
    176                                  int stream_id,
    177                                  bcm_subport_stat_t stat_type, uint64 val);
    178     /* Subport port stat get */
    179     int (*subport_port_stat_get)(int unit, bcm_gport_t port, int stream_id,
    180                                  bcm_subport_stat_t stat_type, uint64 *val);
    181     /* Subport port delete */
    182     int (*subport_port_delete)(int unit, bcm_gport_t port);
    183     /* Subport module cleanup */
    184     int (*subport_cleanup)(int unit);
    185 
    186     /* CoE module handlers */
    187 
    188     /* Init CoE subport module handlers */
    189     int (*coe_init)(int unit);
    190     /* Create Subport group */
    191     int (*coe_group_create)(int unit, bcm_subport_group_config_t *config,
    192 			 bcm_gport_t *group);
    193     /* Delete Subport group */
    194     int (*coe_group_get)(int unit, bcm_gport_t group,
    195              bcm_subport_group_config_t *config);
    196     /* Traverse Subport group */
    197     int (*coe_group_traverse)(int unit, bcm_gport_t subport_group,
    198                               bcm_subport_port_traverse_cb cb, 
    199                               void *user_data);
    200     /* Destroy Subport group */
    201     int (*coe_group_destroy)(int unit, bcm_gport_t group);
    202     /* Set LinkPhy config */
    203     int (*coe_group_linkphy_config_set)(int unit, bcm_gport_t port,
    204           bcm_subport_group_linkphy_config_t *linkphy_config);
    205     /* Get LinkPhy config */
    206     int (*coe_group_linkphy_config_get)(int unit, bcm_gport_t port,
    207          bcm_subport_group_linkphy_config_t *linkphy_config); 
    208 
    209     /* Subport port add */
    210     int (*coe_port_add)(int unit, bcm_subport_config_t *config, 
    211                         bcm_gport_t *port);
    212     /* Subport port get */
    213     int (*coe_port_get)(int unit, bcm_gport_t port, 
    214                         bcm_subport_config_t *config);
    215     /* Subport port traverse */
    216     int (*coe_port_traverse)(int unit, bcm_subport_port_traverse_cb cb, 
    217                              void *user_data);
    218     /* Subport port stat set */
    219     int (*coe_port_stat_set)(int unit, bcm_gport_t port, int stream_id,
    220                          bcm_subport_stat_t stat_type, uint64 val);
    221     /* Subport port stat get */
    222     int (*coe_port_stat_get)(int unit, bcm_gport_t port, int stream_id,
    223                          bcm_subport_stat_t stat_type, uint64 *val);
    224     /* Subport port delete */
    225     int (*coe_port_delete)(int unit, bcm_gport_t port);
    226     /* Subport module cleanup */
    227     int (*coe_cleanup)(int unit);
    228     /* subport_linkphy_rx_error_register */
    229     int (*subport_linkphy_rx_error_register) (int unit,
    230             bcm_subport_linkphy_rx_errors_t errors,
    231             bcm_subport_linkphy_rx_error_reg_info_t *reg_info,
    232             void *user_data);
    233     /* subport_linkphy_rx_error_unregister */
    234     int (*subport_linkphy_rx_error_unregister) (int unit,
    235             bcm_subport_linkphy_rx_errors_t errors);
    236     /* subport_gport mod-port get */
    237     int (*subport_gport_modport_get) (int unit,
    238             bcm_gport_t subport_gport, bcm_module_t *module,
    239            bcm_port_t *port);
    240  
    241 } bcm_esw_subport_drv_t;
    242 
    243 extern bcm_esw_subport_drv_t      *bcm_esw_subport_drv[BCM_MAX_NUM_UNITS];
    244 
    245 #define BCM_ESW_SUBPORT_DRV(_u)   (bcm_esw_subport_drv[(_u)])
    246 
    247 extern int bcmi_subport_common_init(int unit, bcm_esw_subport_drv_t *drv);
    248 
    249 /*
    250  * Bitmap of subport group id
    251  * Each Subport group created has unique group id
    252  * across all ports in the device irrespective of
    253  * group type LinkPHY/SubTag
    254  */
    255 extern SHR_BITDCL *_bcm_subport_group_bitmap[BCM_MAX_NUM_UNITS];
    256 
    257 /* Count of all subport groups created */
    258 extern int _bcm_subport_group_count[BCM_MAX_NUM_UNITS];
    259 
    260 /* Count subport port per subport group*/
    261 extern int *(_bcm_subport_group_subport_port_count[BCM_MAX_NUM_UNITS]);
    262 
    263 
    264 /*********************************
    265 * Subport common  section - end
    266  */
    267 
    268 /*****************************************
    269 * General purpose subport section - start
    270  */
    271 
    272 /* Bitmap of general subport group id */
    273 extern SHR_BITDCL *_bcm_general_subport_group_bitmap[BCM_MAX_NUM_UNITS];
    274 
    275 /* Count of all general subport groups created */
    276 extern int _bcm_general_subport_group_count[BCM_MAX_NUM_UNITS];
    277 
    278 /* general subport port info structure */
    279 typedef struct {
    280     /* Subport group gort attached to */
    281     bcm_gport_t  group;
    282     int          valid;
    283 } _bcm_general_subport_port_info_t;
    284 
    285 extern _bcm_general_subport_port_info_t
    286         *(_bcm_general_subport_port_info[BCM_MAX_NUM_UNITS]);
    287 
    288 /*****************************************
    289 * General purpose subport section - end
    290  */
    291 
    292 /*********************************
    293 * SubTag subport section - start
    294  */
    295 
    296 /* Bitmap of SubTag subport group id */
    297 extern SHR_BITDCL *_bcm_subtag_group_bitmap[BCM_MAX_NUM_UNITS];
    298 
    299 /* Count of all SubTag subport groups created */
    300 extern int _bcm_subtag_subport_group_count[BCM_MAX_NUM_UNITS];
    301 
    302 extern SHR_BITDCL *_bcm_subtag_vlan_id_bitmap
    303                    [BCM_MAX_NUM_UNITS][SOC_MAX_NUM_PORTS];
    304 
    305 /* SubTag subport port info structure */
    306 typedef struct {
    307     /* Subport group gort attached to */
    308     bcm_gport_t  group;
    309     /* VLAN ID */
    310     bcm_vlan_t   vlan;
    311     int          valid;
    312     int          subtag_tcam_hw_idx;
    313     int          modport_subport_idx;
    314     /* Subport-Port, represented as GPORT_SUBPORT */
    315     bcm_gport_t  subport_port;
    316     /* Associated subport, represented as GPORT_MODPORT */
    317     bcm_gport_t  subport_modport;
    318     int          phb_valid;
    319     int          priority;
    320     int          color;
    321     int          nh_index;
    322 } _bcm_subtag_subport_port_info_t;
    323 
    324 extern _bcm_subtag_subport_port_info_t
    325            *(_bcm_subtag_subport_port_info[BCM_MAX_NUM_UNITS]);
    326 
    327 /*********************************
    328 * SubTag subport section - end
    329  */
    330 
    331 
    332 /****  Misc section start */
    333 
    334 extern sal_mutex_t _bcm_subport_mutex[BCM_MAX_NUM_UNITS];
    335 
    336 #define _BCM_SUBPORT_COE_LOCK(unit) \
    337     sal_mutex_take(_bcm_subport_mutex[unit], sal_mutex_FOREVER);
    338 
    339 #define _BCM_SUBPORT_COE_UNLOCK(unit) \
    340     sal_mutex_give(_bcm_subport_mutex[unit]);
    341 
    342 
    343 #define _BCM_SUBPORT_COE_CHECK_INIT(_unit_) \
    344         if (!_bcm_subport_group_bitmap[_unit_]) \
    345             return BCM_E_INIT
    346 
    347 /****  Misc section end */
    348 
    349 
    350 /** Common defines for CoE implementation - start */
    351 
    352 /*
    353  * Subport group usage bitmap operations
    354  */
    355 #define _BCM_SUBPORT_COE_GROUP_USED_GET(_u_, _group_) \
    356                 SHR_BITGET(_bcm_subport_group_bitmap[_u_], (_group_))
    357 
    358 #define _BCM_SUBPORT_COE_GROUP_USED_SET(_u_, _group_) \
    359                 SHR_BITSET(_bcm_subport_group_bitmap[_u_], (_group_))
    360 
    361 #define _BCM_SUBPORT_COE_GROUP_USED_CLR(_u_, _group_) \
    362                 SHR_BITCLR(_bcm_subport_group_bitmap[_u_], (_group_))
    363 
    364 /*
    365  * General subport group usage bitmap operations
    366  */
    367 #define _BCM_GENERAL_SUBPORT_GROUP_USED_GET(_u_, _group_) \
    368     SHR_BITGET(_bcm_general_subport_group_bitmap[_u_], (_group_))
    369 
    370 #define _BCM_GENERAL_SUBPORT_GROUP_USED_SET(_u_, _group_) \
    371     SHR_BITSET(_bcm_general_subport_group_bitmap[_u_], (_group_))
    372 
    373 #define _BCM_GENERAL_SUBPORT_GROUP_USED_CLR(_u_, _group_) \
    374     SHR_BITCLR(_bcm_general_subport_group_bitmap[_u_], (_group_))
    375 
    376 /*
    377  * SubTag subport group usage bitmap operations
    378  */
    379 #define _BCM_SUBPORT_COE_SUBTAG_GROUP_USED_GET(_u_, _group_) \
    380             SHR_BITGET(_bcm_subtag_group_bitmap[_u_], (_group_))
    381 
    382 #define _BCM_SUBPORT_COE_SUBTAG_GROUP_USED_SET(_u_, _group_) \
    383             SHR_BITSET(_bcm_subtag_group_bitmap[_u_], (_group_))
    384 
    385 #define _BCM_SUBPORT_COE_SUBTAG_GROUP_USED_CLR(_u_, _group_) \
    386             SHR_BITCLR(_bcm_subtag_group_bitmap[_u_], (_group_))
    387 
    388 /* Katana2 SubTag VLAN id usage bitmap for given port*/
    389 #define _BCM_COE_SUBTAG_VLAN_ID_USED_GET(_u_, _p, _vlan_id_) \
    390             SHR_BITGET(_bcm_subtag_vlan_id_bitmap[_u_][_p], (_vlan_id_))
    391 
    392 #define _BCM_COE_SUBTAG_VLAN_ID_USED_SET(_u_, _p, _vlan_id_) \
    393             SHR_BITSET(_bcm_subtag_vlan_id_bitmap[_u_][_p], (_vlan_id_))
    394 
    395 #define _BCM_COE_SUBTAG_VLAN_ID_USED_CLR(_u_, _p, _vlan_id_) \
    396             SHR_BITCLR(_bcm_subtag_vlan_id_bitmap[_u_][_p], (_vlan_id_))
    397 
    398 
    399 /* Set the SubTag subport group gport */
    400 
    401 /* The encoding is like this, based on the flags used:
    402     GPORT-TYPE-SUBPORT, SUBTYPE-SUBPORT, PHYSICAL-PORT, GroupId
    403  */
    404 
    405 #define _BCM_SUBPORT_COE_SUBTAG_GROUP_SET(_subport_group, \
    406                                           _port, _gid) \
    407             (BCM_GPORT_SUBPORT_GROUP_SET((_subport_group), \
    408                         (((_BCM_SUBPORT_COE_TYPE_SUBTAG & \
    409                           _BCM_SUBPORT_COE_GROUP_SUBTYPE_MASK) \
    410                               << _BCM_SUBPORT_COE_GROUP_SUBTYPE_SHIFT) | \
    411                          ((_port & _BCM_SUBPORT_COE_GROUP_PORT_MASK) \
    412                               << _BCM_SUBPORT_COE_GROUP_PORT_SHIFT) | \
    413                          ((_gid & _BCM_SUBPORT_COE_GROUP_SPGID_MASK) \
    414                               << _BCM_SUBPORT_COE_GROUP_SPGID_SHIFT))))
    415 
    416 /* Set the LinkPHY subport group gport */
    417 
    418 /* The encoding is like this, based on the flags used:
    419     GPORT-TYPE-SUBPORT, SUBTYPE-LINKPHY, PHYSICAL-PORT, GroupId
    420  */
    421 #define _BCM_COE_LINKPHY_SUBPORT_GROUP_SET(_subport_group, \
    422                                            _port, _gid) \
    423     (BCM_GPORT_SUBPORT_GROUP_SET((_subport_group), \
    424                         (((_BCM_SUBPORT_COE_TYPE_LINKPHY & \
    425                           _BCM_SUBPORT_COE_GROUP_SUBTYPE_MASK) \
    426                               << _BCM_SUBPORT_COE_GROUP_SUBTYPE_SHIFT) | \
    427                          ((_port & _BCM_SUBPORT_COE_GROUP_PORT_MASK) \
    428                               << _BCM_SUBPORT_COE_GROUP_PORT_SHIFT) | \
    429                          ((_gid & _BCM_SUBPORT_COE_GROUP_SPGID_MASK) \
    430                               << _BCM_SUBPORT_COE_GROUP_SPGID_SHIFT))))
    431 
    432 /* Set the general group gport */
    433 
    434 /* The encoding is like this, based on the flags used:
    435    GPORT-TYPE-SUBPORT, SUBTYPE-GENERAL, PHYSICAL-PORT, GroupId
    436  */
    437 #define _BCM_GENERAL_SUBPORT_GROUP_SET(_subport_group, \
    438                                        _port, _gid) \
    439     (BCM_GPORT_SUBPORT_GROUP_SET((_subport_group), \
    440                              (((_BCM_SUBPORT_COE_TYPE_GENERAL & \
    441                                 _BCM_SUBPORT_COE_GROUP_SUBTYPE_MASK) \
    442                                << _BCM_SUBPORT_COE_GROUP_SUBTYPE_SHIFT) | \
    443                               ((_port & _BCM_SUBPORT_COE_GROUP_PORT_MASK) \
    444                                << _BCM_SUBPORT_COE_GROUP_PORT_SHIFT) | \
    445                               ((_gid & _BCM_SUBPORT_COE_GROUP_SPGID_MASK) \
    446                                << _BCM_SUBPORT_COE_GROUP_SPGID_SHIFT))))
    447 
    448 /** Common defines for CoE implementation - end */
    449 
    450 
    451 #ifdef BCM_HGPROXY_COE_SUPPORT
    452 
    453 #define _BCM_SUBPORT_COE_SUBTAG_PORT_INFO_VALID_GET(unit, tcam_hw_id) \
    454     (_bcm_subtag_subport_port_info[unit][tcam_hw_id].valid)
    455 
    456 #define _BCM_SUBPORT_COE_SUBTAG_PORT_INFO_GROUP_GET(unit, tcam_hw_id) \
    457     (_bcm_subtag_subport_port_info[unit][tcam_hw_id].group)
    458 
    459 #define _BCM_SUBPORT_COE_SUBTAG_PORT_INFO_VLAN_GET(unit, tcam_hw_id) \
    460     (_bcm_subtag_subport_port_info[unit][tcam_hw_id].vlan)
    461 
    462 #define _BCM_SUBPORT_COE_SUBTAG_PORT_INFO_TCAM_HW_ID_GET(unit, tcam_hw_id) \
    463     (_bcm_subtag_subport_port_info[unit][tcam_hw_id].subtag_tcam_hw_idx)
    464 
    465 #define _BCM_SUBPORT_COE_SUBTAG_PORT_INFO_SUBPORT_MODPORT_GET(unit, tcam_hw_id) \
    466     (_bcm_subtag_subport_port_info[unit][tcam_hw_id].subport_modport)
    467 
    468 #define _BCM_SUBPORT_COE_SUBTAG_PORT_INFO_MODPORT_IDX_GET(unit, tcam_hw_id) \
    469     (_bcm_subtag_subport_port_info[unit][tcam_hw_id].modport_subport_idx)
    470 
    471 #define _BCM_SUBPORT_COE_SUBTAG_PORT_INFO_SET(unit, tcam_hw_id, tcam_hw_mem_idx, \
    472         sp_group, vlan_id, subport_port_val, subport_modport_val, phbValid, \
    473         pri, col, is_valid, modport_subport_idx_val) \
    474 { \
    475     _bcm_subtag_subport_port_info[unit][tcam_hw_id].group = sp_group; \
    476     _bcm_subtag_subport_port_info[unit][tcam_hw_id].vlan = vlan_id; \
    477     _bcm_subtag_subport_port_info[unit] \
    478                                  [tcam_hw_id].subtag_tcam_hw_idx = \
    479                                  tcam_hw_mem_idx; \
    480     _bcm_subtag_subport_port_info[unit][tcam_hw_id].subport_port = \
    481                                 subport_port_val; \
    482     _bcm_subtag_subport_port_info[unit][tcam_hw_id].subport_modport = \
    483                                 subport_modport_val; \
    484     _bcm_subtag_subport_port_info[unit][tcam_hw_id].phb_valid = phbValid; \
    485     _bcm_subtag_subport_port_info[unit][tcam_hw_id].priority = pri; \
    486     _bcm_subtag_subport_port_info[unit][tcam_hw_id].color = col; \
    487     _bcm_subtag_subport_port_info[unit][tcam_hw_id].valid = is_valid; \
    488     _bcm_subtag_subport_port_info[unit][tcam_hw_id].modport_subport_idx = \
    489                                 modport_subport_idx_val; \
    490 }
    491 
    492 /* Set the subport port gport mod,port id */
    493 #define _BCM_SUBPORT_COE_PORT_ID_SET(_subport_port, mod, port)  \
    494     (BCM_GPORT_SUBPORT_PORT_SET((_subport_port), \
    495         ((mod & _BCM_SUBPORT_COE_PORT_MODULE_MASK) \
    496              << _BCM_SUBPORT_COE_PORT_MODULE_SHIFT) | \
    497         ((port & _BCM_SUBPORT_COE_PORT_PORT_MASK) \
    498              << _BCM_SUBPORT_COE_PORT_PORT_SHIFT)))
    499 
    500 /* Get the subport port gport mod id */
    501 #define _BCM_SUBPORT_COE_PORT_ID_MOD_GET(_subport_port)  \
    502         ((_subport_port >> _BCM_SUBPORT_COE_PORT_MODULE_SHIFT) & \
    503                  _BCM_SUBPORT_COE_PORT_MODULE_MASK)
    504 
    505 /* Get the subport port gport port id */
    506 #define _BCM_SUBPORT_COE_PORT_ID_PORT_GET(_subport_port)  \
    507         ((_subport_port >> _BCM_SUBPORT_COE_PORT_PORT_SHIFT) & \
    508                  _BCM_SUBPORT_COE_PORT_PORT_MASK)   
    509 
    510 /* Get the subport port gport mod id */
    511 #define _BCM_SUBPORT_COE_PORT_ID_GET(_subport_port)  \
    512         ((_subport_port & (_BCM_SUBPORT_COE_PORT_VALUE_MASK)))
    513 
    514 /* Check if gport is SubTag subport_port */
    515 #define _BCM_COE_GPORT_IS_SUBTAG_SUBPORT_PORT(_unit, _subport_port)    \
    516         (((((_subport_port) >> _BCM_SUBPORT_COE_PORT_TYPE_SHIFT) & \
    517                         _BCM_SUBPORT_COE_PORT_TYPE_MASK) == \
    518                         _BCM_SUBPORT_COE_TYPE_SUBTAG) && \
    519          ((((_subport_port) >> _BCM_SUBPORT_COE_PORT_ZERO_BITS_SHIFT) & \
    520                         _BCM_SUBPORT_COE_PORT_ZERO_BITS_MASK) == 0))
    521 
    522 /* Traverse all valid hgproxy SubTag subport ports */
    523 #define BCM_HGPROXY_SUBTAG_COE_PORT_ITER(i, gport)                          \
    524     if (soc_feature(unit, soc_feature_hgproxy_subtag_coe) &&                \
    525         (_bcm_subtag_subport_port_info[unit] != NULL))                      \
    526         for (i = 0; i < SOC_INFO(unit).max_subport_coe_ports; i++)          \
    527             if((_bcm_subtag_subport_port_info[unit][i].valid) &&            \
    528                 (gport =                                                    \
    529                     _bcm_subtag_subport_port_info[unit][i].subport_port))
    530 
    531 /* Get the subport port gport mod id */
    532 #define _BCM_SUBPORT_COE_PORT_GLP_GET(_subport_port)  \
    533    (_BCM_SUBPORT_COE_PORT_ID_MOD_GET(_subport_port) << 8 ) |  \
    534    (_BCM_SUBPORT_COE_PORT_ID_PORT_GET(_subport_port))
    535 
    536 #endif /* BCM_HGPROXY_COE_SUPPORT */
    537 
    538 
    539 #ifdef BCM_APACHE_SUPPORT
    540 
    541 #define _BCM_APACHE_SUBPORT_COE_GROUP_MAX     (256)
    542 #define _BCM_APACHE_SUBPORT_COE_PORT_MAX      (256)
    543 #define _BCM_APACHE_MAX_SUBPORT_COE_PER_PORT  (80)
    544 
    545 #endif /* BCM_APACHE_SUPPORT */
    546 
    547 /** End change */
    548 
    549 #ifdef BCM_KATANA2_SUPPORT
    550 
    551 /* Subport Common defines */
    552 #define _BCM_KT2_PORT_TYPE_ETHERNET         _BCM_COE_PORT_TYPE_ETHERNET
    553 #define _BCM_KT2_PORT_TYPE_CASCADED         _BCM_COE_PORT_TYPE_CASCADED
    554 #define _BCM_KT2_PORT_TYPE_CASCADED_LINKPHY _BCM_COE_PORT_TYPE_CASCADED_LINKPHY
    555 #define _BCM_KT2_PORT_TYPE_CASCADED_SUBTAG  _BCM_COE_PORT_TYPE_CASCADED_SUBTAG
    556 
    557 #define _BCM_KT2_GPORT_IS_LINKPHY_OR_SUBTAG_SUBPORT_GPORT(_unit, _gport) \
    558     (BCM_GPORT_IS_SUBPORT_PORT(_gport) && \
    559         ((soc_feature(_unit, soc_feature_linkphy_coe) && \
    560         _BCM_KT2_GPORT_IS_LINKPHY_SUBPORT_PORT (_unit, _gport)) || \
    561         (soc_feature(_unit, soc_feature_subtag_coe) && \
    562          _BCM_KT2_GPORT_IS_SUBTAG_SUBPORT_PORT (_unit, _gport)) || \
    563         (soc_feature(_unit, soc_feature_general_cascade) && \
    564          _BCM_KT2_GPORT_IS_GENERAL_SUBPORT_PORT (_unit, _gport))))
    565 
    566 /* LinkPHY subport specific defines */
    567 #define _BCM_KT2_LINKPHY_STREAMS_MAX                1024
    568 #define _BCM_KT2_LINKPHY_PER_PORT_STREAMS_MAX       128
    569 #define _BCM_KT2_LINKPHY_PER_BLK_STREAMS_MAX        128
    570 /* 
    571  * Maximum number of streams supported are 2 per
    572  * subport where each subport port can support 4 
    573  * Stream Ids in the range Id, Id + 3.
    574  */ 
    575 #define _BCM_KT2_LINKPHY_MAX_STREAM_IDS_PER_PORT    4
    576 
    577 #define _BCM_SB2_MAX_LINKPHY_PORTS                  4
    578 #define _BCM_SB2_MAX_INT_STREAMS_PER_LINKPHY_PORT   8
    579 #define _BCM_SB2_MAX_EXT_STREAMS_PER_LINKPHY_PORT   32
    580 
    581 #define _BCM_ML_MAX_LINKPHY_PORTS                  4
    582 #define _BCM_ML_MAX_INT_STREAMS_PER_LINKPHY_PORT   6
    583 #define _BCM_ML_MAX_EXT_STREAMS_PER_LINKPHY_PORT   24
    584 #define _BCM_ML_LINKPHY_PER_BLK_STREAMS_MAX       24
    585 
    586 /*
    587 * Katana2:
    588 * There are two tables in TXLP Block in MXQ8 and MXQ9 blocks 
    589 * 1. TXLP_PORT_ADDR_MAP_TABLE - This is programmed when the 
    590 * port is in Non-linkPhy Mode. The start_addr and the end_addr
    591 * are set based on the speed of the port.
    592 * 2. TXLP_STREAM_ADDR_MAP_TABLE - This is programmed when the 
    593 * port is in LinkPhy mode. The startaddr and end_addr are 
    594 * programmed per stream.
    595 * The buffer allocation done as part of the above should be unique
    596 * There are 3423 lines of buffer, reserving the first 0x5f lines
    597 * of buffer for the ports which are in Non-LinkPhy mode.
    598 * When LinkPhy is enabled on a port, the start_addr and end_addr
    599 * for the port in TXLP_PORT_ADDR_MAP_TABLE is set to 0. And the 
    600 * buffer allocated to the port previously is unused. Since the port
    601 * is in LinkPhy mode the start_addr and end_addr in 
    602 * TXLP_STREAM_ADDR_MAP_TABLE is programmed with buffer space 
    603 * leaving buffer space from 0x0 to 0x5f as reserve for Non-linkPhy
    604 * Ports.
    605 */
    606 #define _BCM_KT2_LINKPHY_STREAM_ID_FLUSH_TIMEOUT    20000
    607 
    608 /*
    609 * Katana2 LinkPHY/SubTag subport feature supports
    610 * 1.creation of multiple logical subport groups per port.
    611 *        Port/trunk_id and group id are stored in subport group gport.
    612 * 2.attachment of multiple subport ports to a subport group
    613 *       A subport port is represented by
    614 *       a. (port, external stream id array)] for LinkPHY subport
    615 *       b. (port, VLAN) for SubTag subport
    616 *       Group id and subport_port id are stored in subport port gport.
    617 */
    618 
    619 #define _BCM_KT2_SUBPORT_TYPE_ETHERNET               _BCM_SUBPORT_COE_TYPE_ETHERNET
    620 #define _BCM_KT2_SUBPORT_TYPE_CASCADED               _BCM_SUBPORT_COE_TYPE_CASCADED
    621 #define _BCM_KT2_SUBPORT_TYPE_LINKPHY                _BCM_SUBPORT_COE_TYPE_LINKPHY
    622 #define _BCM_KT2_SUBPORT_TYPE_SUBTAG                 _BCM_SUBPORT_COE_TYPE_SUBTAG
    623 #define _BCM_KT2_SUBPORT_TYPE_GENERAL                _BCM_SUBPORT_COE_TYPE_GENERAL
    624 
    625 /*
    626 * LinkPHY/SubTag Subport group gport format 
    627 * bit 31-26 -- gport type (subport group)
    628 * bit 25-24  -- subport group type (cascaded)
    629 * bit 18-17 -- subport subtype (linkphy / subtag / general)
    630 * bit 17    -- subport group is trunk indicator
    631 * bit 16-9  -- subport group port number/trunk group id
    632 * bit 8 -0  -- subport group index
    633 */
    634 #define _BCM_KT2_SUBPORT_GROUP_TYPE_MASK \
    635             _BCM_SUBPORT_COE_GROUP_TYPE_MASK
    636 #define _BCM_KT2_SUBPORT_GROUP_TYPE_SHIFT \
    637             _BCM_SUBPORT_COE_GROUP_TYPE_SHIFT
    638 #define _BCM_KT2_SUBPORT_GROUP_SUBTYPE_MASK \
    639             _BCM_SUBPORT_COE_GROUP_SUBTYPE_MASK
    640 #define _BCM_KT2_SUBPORT_GROUP_SUBTYPE_SHIFT \
    641             _BCM_SUBPORT_COE_GROUP_SUBTYPE_SHIFT
    642 #define _BCM_KT2_SUBPORT_GROUP_PORT_MASK \
    643             _BCM_SUBPORT_COE_GROUP_PORT_MASK
    644 #define _BCM_KT2_SUBPORT_GROUP_PORT_SHIFT \
    645             _BCM_SUBPORT_COE_GROUP_PORT_SHIFT
    646 #define _BCM_KT2_SUBPORT_GROUP_SPGID_MASK \
    647             _BCM_SUBPORT_COE_GROUP_SPGID_MASK
    648 #define _BCM_KT2_SUBPORT_GROUP_SPGID_SHIFT \
    649             _BCM_SUBPORT_COE_GROUP_SPGID_SHIFT
    650 /*
    651 * LinkPHY/SubTag Subport port gport format 
    652 * bit 31-26  -- gport type (subport port)
    653 * bit 25-24  -- subport port type (LinkPHY / SubTag/ General)
    654 * bit 23-08  -- zero
    655 * bit 07-00  -- subport port index  (range 42 to 169)
    656 */
    657 
    658 #define _BCM_KT2_SUBPORT_PORT_TYPE_MASK           0x3
    659 #define _BCM_KT2_SUBPORT_PORT_TYPE_SHIFT          24
    660 #define _BCM_KT2_SUBPORT_PORT_ZERO_BITS_MASK      0xFFFF
    661 #define _BCM_KT2_SUBPORT_PORT_ZERO_BITS_SHIFT     8
    662 #define _BCM_KT2_SUBPORT_PORT_PP_PORT_MASK        0xFF
    663 #define _BCM_KT2_SUBPORT_PORT_PP_PORT_SHIFT       0
    664 
    665 /* Check if gport is LinkPHY subport_group */
    666 #define _BCM_KT2_GPORT_IS_LINKPHY_SUBPORT_GROUP(_subport_group)    \
    667             _BCM_COE_GPORT_IS_LINKPHY_SUBPORT_GROUP(_subport_group)
    668 
    669 /* Check if gport is SubTag subport_group */
    670 #define _BCM_KT2_GPORT_IS_SUBTAG_SUBPORT_GROUP(_subport_group)    \
    671             _BCM_COE_GPORT_IS_SUBTAG_SUBPORT_GROUP(_subport_group)
    672 
    673 /* Check if gport is general subport_group */
    674 #define _BCM_KT2_GPORT_IS_GENERAL_SUBPORT_GROUP(_subport_group)    \
    675             _BCM_COE_GPORT_IS_GENERAL_SUBPORT_GROUP(_subport_group)
    676 
    677 /* Set the subport port gport  type*/
    678 #define _BCM_KT2_SUBPORT_PORT_TYPE_SET(_subport_port, _type)  \
    679              _BCM_SUBPORT_COE_PORT_TYPE_SET(_subport_port, _type)
    680 
    681 /* Set the subport port gport  pp_port id*/
    682 #define _BCM_KT2_SUBPORT_PORT_ID_SET(_subport_port, _pp_port)  \
    683     (BCM_GPORT_SUBPORT_PORT_SET((_subport_port), \
    684         ((_pp_port & _BCM_KT2_SUBPORT_PORT_PP_PORT_MASK) \
    685              << _BCM_KT2_SUBPORT_PORT_PP_PORT_SHIFT)))
    686 
    687 /* Get the subport port gport pp_port id */
    688 #define _BCM_KT2_SUBPORT_PORT_ID_GET(_subport_port)   \
    689     (((_subport_port) >> _BCM_KT2_SUBPORT_PORT_PP_PORT_SHIFT) & \
    690                          _BCM_KT2_SUBPORT_PORT_PP_PORT_MASK)
    691 
    692 
    693 /* Check if gport is LinkPHY subport_port */
    694 #define _BCM_KT2_GPORT_IS_LINKPHY_SUBPORT_PORT(_unit, _subport_port)    \
    695         (((((_subport_port) >> _BCM_KT2_SUBPORT_PORT_TYPE_SHIFT) & \
    696                         _BCM_KT2_SUBPORT_PORT_TYPE_MASK) == \
    697                         _BCM_KT2_SUBPORT_TYPE_LINKPHY) && \
    698          ((((_subport_port) >> _BCM_KT2_SUBPORT_PORT_ZERO_BITS_SHIFT) & \
    699                         _BCM_KT2_SUBPORT_PORT_ZERO_BITS_MASK) == 0) && \
    700         (BCM_PBMP_MEMBER(SOC_INFO(_unit).linkphy_pp_port_pbm, \
    701             (((_subport_port) >> _BCM_KT2_SUBPORT_PORT_PP_PORT_SHIFT) & \
    702                         _BCM_KT2_SUBPORT_PORT_PP_PORT_MASK))))
    703 
    704 /* Check if gport is SubTag subport_port */
    705 #define _BCM_KT2_GPORT_IS_SUBTAG_SUBPORT_PORT(_unit, _subport_port)    \
    706         (((((_subport_port) >> _BCM_KT2_SUBPORT_PORT_TYPE_SHIFT) & \
    707                         _BCM_KT2_SUBPORT_PORT_TYPE_MASK) == \
    708                         _BCM_KT2_SUBPORT_TYPE_SUBTAG) && \
    709          ((((_subport_port) >> _BCM_KT2_SUBPORT_PORT_ZERO_BITS_SHIFT) & \
    710                         _BCM_KT2_SUBPORT_PORT_ZERO_BITS_MASK) == 0) && \
    711         (BCM_PBMP_MEMBER(SOC_INFO(_unit).subtag_pp_port_pbm, \
    712             (((_subport_port) >> _BCM_KT2_SUBPORT_PORT_PP_PORT_SHIFT) & \
    713                         _BCM_KT2_SUBPORT_PORT_PP_PORT_MASK))))
    714 
    715 /* Check if gport is General subport_port */
    716 #define _BCM_KT2_GPORT_IS_GENERAL_SUBPORT_PORT(_unit, _subport_port)    \
    717     (((((_subport_port) >> _BCM_KT2_SUBPORT_PORT_TYPE_SHIFT) & \
    718                     _BCM_KT2_SUBPORT_PORT_TYPE_MASK) == \
    719                     _BCM_KT2_SUBPORT_TYPE_GENERAL) && \
    720      ((((_subport_port) >> _BCM_KT2_SUBPORT_PORT_ZERO_BITS_SHIFT) & \
    721                     _BCM_KT2_SUBPORT_PORT_ZERO_BITS_MASK) == 0) && \
    722      (BCM_PBMP_MEMBER(SOC_INFO(_unit).general_pp_port_pbm, \
    723                       (((_subport_port) >> _BCM_KT2_SUBPORT_PORT_PP_PORT_SHIFT) & \
    724                        _BCM_KT2_SUBPORT_PORT_PP_PORT_MASK))))
    725 
    726 
    727 typedef struct {
    728     bcm_port_t port;
    729     int        port_type;
    730     bcm_vlan_t subtag;
    731     int        num_streams;
    732     uint16     dev_int_stream_id[BCM_SUBPORT_CONFIG_MAX_STREAMS];
    733 } _bcm_kt2_subport_info_t;
    734 
    735 #endif /* BCM_KATANA2_SUPPORT */
    736 
    737 #ifdef BCM_WARM_BOOT_SUPPORT
    738 #define BCM_SUBPORT_WB_VERSION_1_0          SOC_SCACHE_VERSION(1,0)
    739 #define BCM_SUBPORT_WB_VERSION_1_1          SOC_SCACHE_VERSION(1,1)
    740 #define BCM_SUBPORT_WB_DEFAULT_VERSION      BCM_SUBPORT_WB_VERSION_1_1
    741 
    742 extern int _bcm_esw_subport_sync(int unit);
    743 #endif /* BCM_WARM_BOOT_SUPPORT */
    744 
    745 #ifdef BCM_WARM_BOOT_SUPPORT_SW_DUMP
    746 extern void _bcm_tr_subport_sw_dump(int unit);
    747 extern void _bcm_tr2_subport_sw_dump(int unit);
    748 extern void _bcm_kt2_subport_sw_dump(int unit);
    749 
    750 #endif /* BCM_WARM_BOOT_SUPPORT_SW_DUMP */
    751 
    752 extern int
    753 _bcm_subport_physical_port_get(int unit, int pp_port,
    754                               int *local_port);
    755 
    756 extern int
    757 _bcmi_linkphy_subport_stream_dfc_update(int unit,
    758                                         bcm_subport_config_t *config,
    759                                         int pp_port_index,
    760                                         int ext_stream_id,
    761                                         int enable);
    762 
    763 extern int
    764 _bcmi_linkphy_subport_stream_flush(int unit,
    765                                    bcm_subport_config_t *config,
    766                                    int pp_port_index,
    767                                    int ext_stream_id);
    768 
    769 #endif /* !_BCM_INT_ESW_SUBPORT_H_ */