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

fcoe.c (30631B)


      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:        fcoe.c
      8  * Purpose:     ESW FCOE functions
      9  */
     10 #include <soc/drv.h>
     11 #include <soc/l3x.h>
     12 
     13 #include <bcm/stat.h>
     14 #include <bcm_int/esw/fcoe.h>
     15 #include <bcm/l3.h>
     16 #include <bcm_int/esw/l3.h>
     17 
     18 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
     19 #include <bcm_int/esw/trident2.h>
     20 #endif /* BCM_TRIDENT2_SUPPORT */
     21 
     22 /* Flag to check initialized status */
     23 STATIC int fcoe_initialized[BCM_MAX_NUM_UNITS];
     24 
     25 /* FCOE module lock */
     26 STATIC sal_mutex_t fcoe_mutex[BCM_MAX_NUM_UNITS] = {NULL};
     27 
     28 #define FCOE_INIT_CHECK(unit)                             \
     29     do {                                                  \
     30         if ((unit < 0) || (unit >= BCM_MAX_NUM_UNITS)) {  \
     31             return BCM_E_UNIT;                            \
     32         }                                                 \
     33         if (!fcoe_initialized[unit]) {                    \
     34             return BCM_E_INIT;                            \
     35         }                                                 \
     36     } while (0)
     37 
     38 #define FCOE_LOCK(unit) \
     39         sal_mutex_take(fcoe_mutex[unit], sal_mutex_FOREVER);
     40 
     41 #define FCOE_UNLOCK(unit) \
     42         sal_mutex_give(fcoe_mutex[unit]);
     43 
     44 /*
     45  * Function:    _bcm_esw_fcoe_free_resources
     46  * Purpose:     Free FCOE resources
     47  * Parameters:  unit - SOC unit number
     48  * Returns:     Nothing
     49  */
     50 STATIC void
     51 _bcm_esw_fcoe_free_resources(int unit)
     52 {
     53     if (fcoe_mutex[unit]) {
     54         sal_mutex_destroy(fcoe_mutex[unit]);
     55         fcoe_mutex[unit] = NULL;
     56     }
     57 }
     58 
     59 /* De-initialize FCOE module */
     60 int
     61 bcm_esw_fcoe_cleanup(int unit)
     62 {
     63     if (soc_feature(unit, soc_feature_fcoe)) {
     64 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
     65         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
     66             BCM_IF_ERROR_RETURN(bcm_td2_fcoe_cleanup(unit));
     67         }
     68 #endif /* BCM_TRIDENT2_SUPPORT */
     69 
     70         _bcm_esw_fcoe_free_resources(unit);
     71 
     72         fcoe_initialized[unit] = FALSE;
     73 
     74         return BCM_E_NONE;
     75     }
     76 
     77     return BCM_E_UNAVAIL;
     78 }
     79 
     80 /* Initialize FCOE module */
     81 int
     82 bcm_esw_fcoe_init(int unit)
     83 {
     84     if (soc_feature(unit, soc_feature_fcoe)) {
     85         if (fcoe_initialized[unit]) {
     86             BCM_IF_ERROR_RETURN(bcm_esw_fcoe_cleanup(unit));
     87         }
     88 
     89 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
     90         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
     91             BCM_IF_ERROR_RETURN(bcm_td2_fcoe_init(unit));
     92         }
     93 #endif /* BCM_TRIDENT2_SUPPORT */
     94 
     95         if (fcoe_mutex[unit] == NULL) {
     96             fcoe_mutex[unit] = sal_mutex_create("fcoe mutex");
     97             if (fcoe_mutex[unit] == NULL) {
     98                 bcm_esw_fcoe_cleanup(unit);
     99                 return BCM_E_MEMORY;
    100             }
    101         }
    102 
    103         fcoe_initialized[unit] = TRUE;
    104 
    105         return BCM_E_NONE;
    106     }
    107 
    108     return BCM_E_UNAVAIL;
    109 }
    110 
    111 #ifdef BCM_WARM_BOOT_SUPPORT
    112 
    113 int
    114 _bcm_esw_fcoe_sync(int unit)
    115 {
    116 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    117     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    118         FCOE_INIT_CHECK(unit);
    119         return _bcm_td2_fcoe_sync(unit);
    120     }
    121 #endif
    122     return BCM_E_UNAVAIL;
    123 }
    124 
    125 #endif
    126 
    127 /* enable/disable FCOE without clearing any FCOE table */
    128 int
    129 bcm_esw_fcoe_enable_set(int unit)
    130 {
    131     /* temporary return value */
    132     return BCM_E_UNAVAIL;
    133 }
    134 
    135 /* Add an entry into the FCOE routing table */
    136 int
    137 bcm_esw_fcoe_route_add(int unit,  bcm_fcoe_route_t *route)
    138 {
    139 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    140     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    141         FCOE_INIT_CHECK(unit);
    142         return bcm_td2_fcoe_route_add(unit, route);
    143     }
    144 #endif
    145     return BCM_E_UNAVAIL;
    146 }
    147 
    148 /* Delete an nport_id entry from the FCOE routing table */
    149 int
    150 bcm_esw_fcoe_route_delete(int unit,  bcm_fcoe_route_t *route)
    151 {
    152 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    153     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    154         FCOE_INIT_CHECK(unit);
    155         return bcm_td2_fcoe_route_delete(unit, route);
    156     }
    157 #endif
    158     return BCM_E_UNAVAIL;
    159 }
    160 
    161 /* Delete FCOE entries based on Masked Domain prefix (network) */
    162 int
    163 bcm_esw_fcoe_route_delete_by_prefix(int unit, bcm_fcoe_route_t *route)
    164 {
    165 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    166     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    167         FCOE_INIT_CHECK(unit);
    168         return bcm_td2_fcoe_route_delete_by_prefix(unit, route);
    169     }
    170 #endif
    171     return BCM_E_UNAVAIL;
    172 }
    173 
    174 /* Delete FCOE entries that do/don't match a specified L3 interface */
    175 int
    176 bcm_esw_fcoe_route_delete_by_interface(int unit,  bcm_fcoe_route_t *route)
    177 {
    178 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    179     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    180         FCOE_INIT_CHECK(unit);
    181         return bcm_td2_fcoe_route_delete_by_interface(unit, route);
    182     }
    183 #endif
    184     return BCM_E_UNAVAIL;
    185 }
    186 
    187 /* Deletes all FCOE routing table entries */
    188 int
    189 bcm_esw_fcoe_route_delete_all(int unit)
    190 {
    191 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    192     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    193         FCOE_INIT_CHECK(unit);
    194         return bcm_td2_fcoe_route_delete_all(unit);
    195     }
    196 #endif
    197     return BCM_E_UNAVAIL;
    198 }
    199 
    200 /* Look up an FCOE routing table entry based on nport id */
    201 int
    202 bcm_esw_fcoe_route_find(int unit,  bcm_fcoe_route_t *route)
    203 {
    204 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    205     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    206         FCOE_INIT_CHECK(unit);
    207         return bcm_td2_fcoe_route_find(unit, route);
    208     }
    209 #endif
    210     return BCM_E_UNAVAIL;
    211 }
    212 
    213 /* Allocate and configure a VSAN */
    214 int 
    215 bcm_esw_fcoe_vsan_create (int unit, uint32 options, bcm_fcoe_vsan_t *vsan,
    216                           bcm_fcoe_vsan_id_t *vsan_id)
    217 {
    218 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    219     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    220         FCOE_INIT_CHECK(unit);
    221         return bcm_td2_fcoe_vsan_create(unit, options, vsan, vsan_id);
    222     }
    223 #endif
    224     return BCM_E_UNAVAIL;
    225 }
    226 
    227 /* Destroy a VSAN */
    228 int 
    229 bcm_esw_fcoe_vsan_destroy (int unit,  bcm_fcoe_vsan_id_t vsan_id)
    230 {
    231 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    232     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    233         FCOE_INIT_CHECK(unit);
    234         return bcm_td2_fcoe_vsan_destroy(unit, vsan_id);
    235     }
    236 #endif
    237     return BCM_E_UNAVAIL;
    238 }
    239 
    240 /* Destroy all VSANs */
    241 int 
    242 bcm_esw_fcoe_vsan_destroy_all (int unit)
    243 {
    244 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    245     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    246         FCOE_INIT_CHECK(unit);
    247         return bcm_td2_fcoe_vsan_destroy_all(unit);
    248     }
    249 #endif
    250     return BCM_E_UNAVAIL;
    251 }
    252 
    253 /* Get VSAN controls */
    254 int 
    255 bcm_esw_fcoe_control_vsan_get (int unit,  
    256                                bcm_fcoe_vsan_id_t vsan_id, 
    257                                bcm_fcoe_vsan_control_t type, 
    258                                int *arg)
    259 {
    260 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    261     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    262         FCOE_INIT_CHECK(unit);
    263         return bcm_td2_fcoe_control_vsan_get(unit, vsan_id, type, arg);
    264     }
    265 #endif
    266     return BCM_E_UNAVAIL;
    267 }
    268 
    269 /* Set VSAN controls */
    270 int 
    271 bcm_esw_fcoe_control_vsan_set (int unit, 
    272                                bcm_fcoe_vsan_id_t vsan_id, 
    273                                bcm_fcoe_vsan_control_t type, 
    274                                int arg)
    275 {
    276 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    277     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    278         FCOE_INIT_CHECK(unit);
    279         return bcm_td2_fcoe_control_vsan_set(unit, vsan_id, type, arg);
    280     }
    281 #endif
    282     return BCM_E_UNAVAIL;
    283 }
    284 
    285 /* Get VSAN properties associated with a VSAN ID */
    286 int 
    287 bcm_esw_fcoe_vsan_get (int unit, bcm_fcoe_vsan_id_t vsan_id, 
    288                        bcm_fcoe_vsan_t *vsan)
    289 {
    290 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    291     if (soc_feature(unit, soc_feature_fcoe)) {
    292         FCOE_INIT_CHECK(unit);
    293         return bcm_td2_fcoe_vsan_get(unit, vsan_id, vsan);
    294     }
    295 #endif
    296     return BCM_E_UNAVAIL;
    297 }
    298 
    299 /* Update VSAN properties associated with a VSAN ID */
    300 int 
    301 bcm_esw_fcoe_vsan_set (int unit, bcm_fcoe_vsan_id_t vsan_id, 
    302                        bcm_fcoe_vsan_t *vsan)
    303 {
    304 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    305     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    306         FCOE_INIT_CHECK(unit);
    307         return bcm_td2_fcoe_vsan_set(unit, vsan_id, vsan);
    308     }
    309 #endif
    310     return BCM_E_UNAVAIL;
    311 }
    312 
    313 /*
    314  * Purpose:
    315  *      Add FCoE zoning entry
    316  * Parameters:
    317  *      unit       - Device unit number
    318  *      zone       - zone entry
    319  * Returns:
    320  *      BCM_E_NONE - Success.
    321  *      BCM_E_XXX
    322  */
    323 int
    324 bcm_esw_fcoe_zone_add(int unit, bcm_fcoe_zone_entry_t *zone)
    325 {
    326 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    327     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    328         FCOE_INIT_CHECK(unit);
    329 
    330         return bcm_td2_fcoe_zone_add(unit, zone);
    331     }
    332 #endif
    333     return BCM_E_UNAVAIL;
    334 }
    335 
    336 /*
    337  * Purpose:
    338  *      Delete Zone check entry
    339  * Parameters:
    340  *      unit       - Device unit number
    341  *      zone       - zone entry to be deleted
    342  * Returns:
    343  *      BCM_E_NONE - Success.
    344  *      BCM_E_XXX
    345  */
    346 int
    347 bcm_esw_fcoe_zone_delete(int unit, bcm_fcoe_zone_entry_t *zone)
    348 {
    349 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    350     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    351         FCOE_INIT_CHECK(unit);
    352 
    353         return bcm_td2_fcoe_zone_delete(unit, zone);
    354     }
    355 #endif
    356     return BCM_E_UNAVAIL;
    357 }
    358 
    359 /*
    360  * Description:
    361  *      Delete all zone check entries
    362  * Parameters:
    363  *     unit             - device number
    364  * Return:
    365  *     BCM_E_XXX
    366  */
    367 int
    368 bcm_esw_fcoe_zone_delete_all(int unit)
    369 {
    370 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    371     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    372         FCOE_INIT_CHECK(unit);
    373 
    374         return bcm_td2_fcoe_zone_delete_all(unit);
    375     }
    376 #endif
    377     return BCM_E_UNAVAIL;
    378 }
    379 
    380 /*
    381  * Description:
    382  *      Delete all zone check entries matching VSAN ID
    383  * Parameters:
    384  *      unit       - device number
    385  *      zone       - zone entry with VSAN ID to be deleted
    386  * Return:
    387  *      BCM_E_XXX
    388  */
    389 int
    390 bcm_esw_fcoe_zone_delete_by_vsan(int unit, bcm_fcoe_zone_entry_t *zone)
    391 {
    392 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    393     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    394         FCOE_INIT_CHECK(unit);
    395 
    396         return bcm_td2_fcoe_zone_delete_by_vsan(unit, zone);
    397     }
    398 #endif
    399     return BCM_E_UNAVAIL;
    400 }
    401 
    402 /*
    403  * Description:
    404  *      Delete all zone check entries matching Source ID
    405  * Parameters:
    406  *      unit       - device number
    407  *      zone       - zone entry with S_ID to be deleted
    408  * Return:
    409  *      BCM_E_XXX
    410  */
    411 int
    412 bcm_esw_fcoe_zone_delete_by_sid(int unit, bcm_fcoe_zone_entry_t *zone)
    413 {
    414 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    415     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    416         FCOE_INIT_CHECK(unit);
    417 
    418         return bcm_td2_fcoe_zone_delete_by_sid(unit, zone);
    419     }
    420 #endif
    421     return BCM_E_UNAVAIL;
    422 }
    423 
    424 /*
    425  * Description:
    426  *      Delete all zone check entries matching Destination ID
    427  * Parameters:
    428  *      unit       - device number
    429  *      zone       - zone entry with D_ID to be deleted
    430  * Return:
    431  *      BCM_E_XXX
    432  */
    433 int
    434 bcm_esw_fcoe_zone_delete_by_did(int unit, bcm_fcoe_zone_entry_t *zone)
    435 {
    436 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    437     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    438         FCOE_INIT_CHECK(unit);
    439 
    440         return bcm_td2_fcoe_zone_delete_by_did(unit, zone);
    441     }
    442 #endif
    443     return BCM_E_UNAVAIL;
    444 }
    445 
    446 /*
    447  * Description:
    448  *      Retrieve Zone info
    449  * Parameters:
    450  *      unit       - device number
    451  *      zone       - zone entry
    452  * Return:
    453  *      BCM_E_XXX
    454  */
    455 int
    456 bcm_esw_fcoe_zone_get(int unit, bcm_fcoe_zone_entry_t *zone)
    457 {
    458 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    459     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    460         FCOE_INIT_CHECK(unit);
    461 
    462         return bcm_td2_fcoe_zone_get(unit, zone);
    463     }
    464 #endif
    465     return BCM_E_UNAVAIL;
    466 }
    467 
    468 
    469 /* Allocate flex counter and assign counter index/offset for
    470  * FCOE VSAN ID
    471  */
    472 int 
    473 bcm_esw_fcoe_vsan_stat_attach (int                 unit,
    474                                bcm_fcoe_vsan_id_t  vsan,
    475                                uint32              stat_counter_id)
    476 {
    477     int rv = BCM_E_UNAVAIL;
    478 
    479     if (soc_feature(unit, soc_feature_advanced_flex_counter)) {
    480 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    481         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    482             FCOE_INIT_CHECK(unit);
    483 
    484             L3_LOCK(unit);
    485             rv = bcm_td2_fcoe_vsan_stat_attach(unit, vsan, stat_counter_id);
    486             L3_UNLOCK(unit);
    487         }
    488 #endif
    489     }
    490     return rv;
    491 }
    492 
    493 /* Detach flex counter for FCOE VSAN ID  */
    494 int 
    495 bcm_esw_fcoe_vsan_stat_detach (int unit, bcm_fcoe_vsan_id_t  vsan)
    496 {
    497     int rv = BCM_E_UNAVAIL;
    498 
    499     if (soc_feature(unit, soc_feature_advanced_flex_counter)) {
    500 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    501         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    502             FCOE_INIT_CHECK(unit);
    503 
    504             L3_LOCK(unit);
    505             rv = bcm_td2_fcoe_vsan_stat_detach(unit, vsan);
    506             L3_UNLOCK(unit);
    507         }
    508 #endif
    509     }
    510     return rv;
    511 }
    512 
    513 /* Get flex counter for FCOE VSAN ID */                          
    514 int 
    515 _bcm_esw_fcoe_vsan_stat_counter_get (int                  unit, 
    516                                      int                  sync_mode, 
    517                                      bcm_fcoe_vsan_id_t   vsan,
    518                                      bcm_fcoe_vsan_stat_t stat, 
    519                                      uint32               num_entries, 
    520                                      uint32               *counter_indexes, 
    521                                      bcm_stat_value_t     *counter_values)
    522 {
    523     int rv = BCM_E_UNAVAIL;
    524 
    525     if (soc_feature(unit, soc_feature_advanced_flex_counter)) {
    526 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    527         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    528             FCOE_INIT_CHECK(unit);
    529 
    530             L3_LOCK(unit);
    531             rv = bcm_td2_fcoe_vsan_stat_counter_get(unit, sync_mode, vsan, 
    532                                                     stat, num_entries,
    533                                                     counter_indexes, 
    534                                                     counter_values);
    535             L3_UNLOCK(unit);
    536         }
    537 #endif
    538     }
    539     return rv;
    540 }
    541 
    542 /* Get flex counter for FCOE VSAN ID */                          
    543 int 
    544 bcm_esw_fcoe_vsan_stat_counter_get (int                  unit, 
    545                                     bcm_fcoe_vsan_id_t   vsan,
    546                                     bcm_fcoe_vsan_stat_t stat, 
    547                                     uint32               num_entries, 
    548                                     uint32               *counter_indexes, 
    549                                     bcm_stat_value_t     *counter_values)
    550 {
    551     int rv = BCM_E_UNAVAIL;
    552     
    553     rv = _bcm_esw_fcoe_vsan_stat_counter_get(unit, 0, vsan, stat, num_entries,
    554                                              counter_indexes, counter_values);
    555     return rv;
    556 }
    557 
    558 /* Get flex counter for FCOE VSAN ID */                          
    559 int 
    560 bcm_esw_fcoe_vsan_stat_counter_sync_get (int                  unit, 
    561                                          bcm_fcoe_vsan_id_t   vsan,
    562                                          bcm_fcoe_vsan_stat_t stat, 
    563                                          uint32               num_entries, 
    564                                          uint32               *counter_indexes, 
    565                                          bcm_stat_value_t     *counter_values)
    566 {
    567     int rv = BCM_E_UNAVAIL;
    568     
    569     rv = _bcm_esw_fcoe_vsan_stat_counter_get(unit, 1, vsan, stat, num_entries,
    570                                              counter_indexes, counter_values);
    571     return rv;
    572 }
    573 
    574 /* Set flex counter for FCOE VSAN ID */                               
    575 int 
    576 bcm_esw_fcoe_vsan_stat_counter_set (int                  unit, 
    577                                     bcm_fcoe_vsan_id_t   vsan,
    578                                     bcm_fcoe_vsan_stat_t stat, 
    579                                     uint32               num_entries, 
    580                                     uint32               *counter_indexes, 
    581                                     bcm_stat_value_t     *counter_values)
    582 {
    583     int rv = BCM_E_UNAVAIL;
    584 
    585     if (soc_feature(unit, soc_feature_advanced_flex_counter)) {
    586 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    587         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    588             FCOE_INIT_CHECK(unit);
    589 
    590             L3_LOCK(unit);
    591             rv = bcm_td2_fcoe_vsan_stat_counter_set(unit, vsan, stat, num_entries,
    592                                                     counter_indexes, 
    593                                                     counter_values);
    594             L3_UNLOCK(unit);
    595         }
    596 #endif
    597     }
    598     return rv;
    599 }
    600 
    601 /* Get stat counter ID for FCOE VSAN ID */                               
    602 int 
    603 bcm_esw_fcoe_vsan_stat_id_get (int                  unit,
    604                                bcm_fcoe_vsan_id_t   vsan,
    605                                bcm_fcoe_vsan_stat_t stat, 
    606                                uint32               *stat_counter_id)
    607 {
    608     int rv = BCM_E_UNAVAIL;
    609 
    610     if (soc_feature(unit, soc_feature_advanced_flex_counter)) {
    611 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    612         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    613             FCOE_INIT_CHECK(unit);
    614 
    615             L3_LOCK(unit);
    616             rv = bcm_td2_fcoe_vsan_stat_id_get(unit, vsan, stat, 
    617                                                stat_counter_id);
    618             L3_UNLOCK(unit);
    619         }
    620 #endif
    621     }
    622     return rv;
    623 }
    624                                
    625 
    626 /* Allocate flex counter and assign counter index/offset for  
    627  * FCOE Route
    628  */
    629 int 
    630 bcm_esw_fcoe_route_stat_attach (int                 unit,
    631                                 bcm_fcoe_route_t    *route,
    632                                 uint32              stat_counter_id)
    633 {
    634     int rv = BCM_E_UNAVAIL;
    635 
    636     if (soc_feature(unit, soc_feature_advanced_flex_counter)) {
    637 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    638         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    639             FCOE_INIT_CHECK(unit);
    640 
    641             L3_LOCK(unit);
    642             rv = bcm_td2_fcoe_route_stat_attach(unit, route, stat_counter_id);
    643             L3_UNLOCK(unit);
    644         }
    645 #endif
    646     }
    647     return rv;
    648 }
    649 
    650 /* Detach flex counter for FCOE Route */                                
    651 int 
    652 bcm_esw_fcoe_route_stat_detach (int unit, bcm_fcoe_route_t *route)
    653 {
    654     int rv = BCM_E_UNAVAIL;
    655 
    656     if (soc_feature(unit, soc_feature_advanced_flex_counter)) {
    657 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    658         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    659             FCOE_INIT_CHECK(unit);
    660 
    661             L3_LOCK(unit);
    662             rv = bcm_td2_fcoe_route_stat_detach(unit, route);
    663             L3_UNLOCK(unit);
    664         }
    665 #endif
    666     }
    667     return rv;
    668 }
    669 
    670 /* Get flex counter for FCOE Route */                                
    671 int 
    672 _bcm_esw_fcoe_route_stat_counter_get (int                   unit, 
    673                                       int                   sync_mode, 
    674                                       bcm_fcoe_route_t      *route,
    675                                       bcm_fcoe_route_stat_t stat, 
    676                                       uint32                num_entries, 
    677                                       uint32                *counter_indexes, 
    678                                       bcm_stat_value_t      *counter_values)
    679 {
    680     int rv = BCM_E_UNAVAIL;
    681 
    682     if (soc_feature(unit, soc_feature_advanced_flex_counter)) {
    683 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    684         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    685             FCOE_INIT_CHECK(unit);
    686 
    687             L3_LOCK(unit);
    688             rv = bcm_td2_fcoe_route_stat_counter_get(unit, 0, route, stat, 
    689                                                      num_entries,
    690                                                      counter_indexes, 
    691                                                      counter_values);
    692             L3_UNLOCK(unit);
    693         }
    694 #endif
    695     }
    696     return rv;
    697 }
    698 
    699 /* Get flex counter for FCOE Route */                                
    700 int 
    701 bcm_esw_fcoe_route_stat_counter_get (int                   unit, 
    702                                      bcm_fcoe_route_t      *route,
    703                                      bcm_fcoe_route_stat_t stat, 
    704                                      uint32                num_entries, 
    705                                      uint32                *counter_indexes, 
    706                                      bcm_stat_value_t      *counter_values)
    707 {
    708     int rv = BCM_E_UNAVAIL;
    709     
    710     rv = _bcm_esw_fcoe_route_stat_counter_get(unit, 0, route, stat, num_entries,
    711                                               counter_indexes, counter_values);
    712     return rv;
    713 }
    714 
    715 /* Get flex counter for FCOE Route */                                
    716 int 
    717 bcm_esw_fcoe_route_stat_counter_sync_get (int                   unit, 
    718                                           bcm_fcoe_route_t      *route,
    719                                           bcm_fcoe_route_stat_t stat, 
    720                                           uint32                num_entries, 
    721                                           uint32               *counter_indexes, 
    722                                           bcm_stat_value_t      *counter_values)
    723 {
    724     int rv = BCM_E_UNAVAIL;
    725     
    726     rv = _bcm_esw_fcoe_route_stat_counter_get(unit, 1, route, stat, num_entries,
    727                                              counter_indexes, counter_values);
    728     return rv;
    729 }
    730 
    731 /* Set flex counter for FCOE Route */
    732 int 
    733 bcm_esw_fcoe_route_stat_counter_set (int                   unit, 
    734                                      bcm_fcoe_route_t      *route,
    735                                      bcm_fcoe_route_stat_t stat, 
    736                                      uint32                num_entries, 
    737                                      uint32                *counter_indexes, 
    738                                      bcm_stat_value_t      *counter_values)
    739 {
    740     int rv = BCM_E_UNAVAIL;
    741 
    742     if (soc_feature(unit, soc_feature_advanced_flex_counter)) {
    743 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    744         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    745             FCOE_INIT_CHECK(unit);
    746 
    747             L3_LOCK(unit);
    748             rv = bcm_td2_fcoe_route_stat_counter_set(unit, route, stat, num_entries,
    749                                                      counter_indexes, 
    750                                                      counter_values);
    751             L3_UNLOCK(unit);
    752         }
    753 #endif
    754     }
    755     return rv;
    756 }
    757        
    758 /* Get stat counter ID for FCOE Route */       
    759 int 
    760 bcm_esw_fcoe_route_stat_id_get (int                   unit,
    761                                 bcm_fcoe_route_t      *route,
    762                                 bcm_fcoe_route_stat_t stat, 
    763                                 uint32                *stat_counter_id)
    764 {
    765     int rv = BCM_E_UNAVAIL;
    766 
    767     if (soc_feature(unit, soc_feature_advanced_flex_counter)) {
    768 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    769         if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    770             FCOE_INIT_CHECK(unit);
    771 
    772             L3_LOCK(unit);
    773             rv = bcm_td2_fcoe_route_stat_id_get(unit, route, stat, stat_counter_id);
    774             L3_UNLOCK(unit);
    775         }
    776 #endif
    777     }
    778     return rv;
    779 }
    780 
    781 /*
    782  * Description:
    783  *      Set FC header type
    784  * Parameters:
    785  *      unit       - (IN) device number
    786  *      flags      - (IN) BCM_FCOE_FC_HEADER_TYPE_INGRESS/EGRESS
    787  *      r_ctl      - (IN) [0-255] value of r_ctl to modify
    788  *      hdr_type   - (IN) Header type to force this value of r_ctl to use
    789  * Return:
    790  *      BCM_E_XXX
    791  */
    792  int
    793  bcm_esw_fcoe_fc_header_type_set(int unit, uint32 flags, uint8 r_ctl, 
    794                                  bcm_fcoe_fc_header_type_t hdr_type)
    795 {
    796 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    797     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    798         FCOE_INIT_CHECK(unit);
    799 
    800         return bcm_td2_fcoe_fc_header_type_set(unit, flags, r_ctl, hdr_type);
    801     }
    802 #endif
    803     return BCM_E_UNAVAIL;
    804 }
    805 
    806 /*
    807  * Description:
    808  *      Retrieve FC header type
    809  * Parameters:
    810  *      unit       - (IN) device number
    811  *      flags      - (IN) BCM_FCOE_FC_HEADER_TYPE_INGRESS/EGRESS
    812  *      r_ctl      - (IN) [0-255] value of r_ctl to retrieve
    813  *      hdr_type   - (OUT) Header type that this value of r_ctl is forced to
    814  * Return:
    815  *      BCM_E_XXX
    816  */
    817  int
    818  bcm_esw_fcoe_fc_header_type_get(int unit, uint32 flags, uint8 r_ctl, 
    819                                  bcm_fcoe_fc_header_type_t *hdr_type)
    820 {
    821 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    822     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    823         FCOE_INIT_CHECK(unit);
    824 
    825         return bcm_td2_fcoe_fc_header_type_get(unit, flags, r_ctl, hdr_type);
    826     }
    827 #endif
    828     return BCM_E_UNAVAIL;
    829 }
    830 
    831 /* Set parameters for FCOE L3 interface */
    832 int
    833 bcm_esw_fcoe_intf_config_set(int unit, uint32 flags, bcm_if_t intf, 
    834                              bcm_fcoe_intf_config_t *cfg)
    835 {
    836 #if (defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)) && defined(INCLUDE_L3)
    837     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    838         FCOE_INIT_CHECK(unit);
    839         return bcm_td2_fcoe_intf_config_set(unit, flags, intf, cfg);
    840     }
    841 #endif
    842 
    843     return BCM_E_UNAVAIL;
    844 }
    845 
    846 /* Get parameters for FCOE L3 interface */
    847 int
    848 bcm_esw_fcoe_intf_config_get(int unit, uint32 flags, bcm_if_t intf, 
    849                              bcm_fcoe_intf_config_t *cfg)
    850 {
    851 #if (defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)) && defined(INCLUDE_L3)
    852     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    853         FCOE_INIT_CHECK(unit);
    854         return bcm_td2_fcoe_intf_config_get(unit, flags, intf, cfg);
    855     }
    856 #endif
    857 
    858     return BCM_E_UNAVAIL;
    859 }
    860 
    861 /*
    862  * Description:
    863  *      Add VSAN translate action
    864  * Parameters:
    865  *      unit       - (IN) device number
    866  *      key        - (IN) translation key configuration
    867  *      action     - (IN) translate action
    868  * Return:
    869  *      BCM_E_XXX
    870  */
    871 int 
    872 bcm_esw_fcoe_vsan_translate_action_add (
    873                                     int unit, 
    874                                     bcm_fcoe_vsan_translate_key_config_t *key, 
    875                                     bcm_fcoe_vsan_action_set_t *action)
    876 {
    877 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    878     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    879         FCOE_INIT_CHECK(unit);
    880 
    881         return bcm_td2_fcoe_vsan_translate_action_add(unit, key, action);
    882     }
    883 #endif
    884     return BCM_E_UNAVAIL;
    885 }
    886 
    887 /*
    888  * Description:
    889  *      Delete VSAN translate action
    890  * Parameters:
    891  *      unit       - (IN) device number
    892  *      key        - (IN) translation key configuration
    893  * Return:
    894  *      BCM_E_XXX
    895  */
    896 int 
    897 bcm_esw_fcoe_vsan_translate_action_delete (
    898                                     int unit, 
    899                                     bcm_fcoe_vsan_translate_key_config_t *key) 
    900 {
    901 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    902     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    903         FCOE_INIT_CHECK(unit);
    904 
    905         return bcm_td2_fcoe_vsan_translate_action_delete(unit, key);
    906     }
    907 #endif
    908     return BCM_E_UNAVAIL;
    909 }
    910 
    911 #ifdef BCM_WARM_BOOT_SUPPORT_SW_DUMP
    912 void 
    913 _bcm_esw_fcoe_sw_dump(int unit)
    914 {
    915 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    916     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    917         _bcm_td2_fcoe_sw_dump(unit);
    918     }
    919 #endif
    920 }
    921 #endif /* BCM_WARM_BOOT_SUPPORT_SW_DUMP */
    922 
    923 /*
    924  * Description:
    925  *      Traverse zone entries and call callback function
    926  * Parameters:
    927  *      unit       - (IN) device number
    928  *      flags      - (IN) 
    929  *      trav_fn    - (IN) user callback function
    930  *      user_data  - (IN) user data for callback function(optional)
    931  * Return:
    932  *      BCM_E_XXX
    933  */
    934 int
    935 bcm_esw_fcoe_zone_traverse (int unit,
    936                             uint32 flags,
    937                             bcm_fcoe_zone_traverse_cb trav_fn,
    938                             void *user_data)
    939 {
    940 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    941     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    942         FCOE_INIT_CHECK(unit);
    943 
    944         return bcm_td2_fcoe_zone_traverse(unit, flags, trav_fn, user_data);
    945     }
    946 #endif
    947     return BCM_E_UNAVAIL;
    948 }
    949 
    950 /*
    951  * Description:
    952  *      Traverse vsan entries and call callback function 
    953  * Parameters:
    954  *      unit       - (IN) device number
    955  *      flags      - (IN) 
    956  *      trav_fn    - (IN) user callback function
    957  *      user_data  - (IN) user data for callback function(optional)
    958  * Return:
    959  *      BCM_E_XXX
    960  */
    961 int
    962 bcm_esw_fcoe_vsan_traverse (int unit,
    963                             uint32 flags,
    964                             bcm_fcoe_vsan_traverse_cb trav_fn, 
    965                             void *user_data)
    966 {
    967 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    968     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    969         FCOE_INIT_CHECK(unit);
    970 
    971         return bcm_td2_fcoe_vsan_traverse(unit, flags, trav_fn, user_data);
    972     }
    973 #endif
    974     return BCM_E_UNAVAIL;
    975 }
    976 
    977 /*
    978  * Description:
    979  *      Traverse route entries and call callback function
    980  * Parameters:
    981  *      unit       - (IN) device number
    982  *      flags      - (IN) route types (BCM_FCOE_HOST_ROUTE, 
    983  *                        BCM_FCOE_SOURCE_ROUTE, BCM_FCOE_DOMAIN_ROUTE),
    984  *                        can have all 3 types in the flags.
    985  *      trav_fn    - (IN) user callback function
    986  *      user_data  - (IN) user data for callback function(optional)
    987  * Return:
    988  *      BCM_E_XXX
    989  */
    990 int
    991 bcm_esw_fcoe_route_traverse (int unit,
    992                              uint32 flags,
    993                              bcm_fcoe_route_traverse_cb trav_fn,
    994                              void *user_data)
    995 {
    996 #if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT3_SUPPORT)
    997     if (SOC_IS_TRIDENT2X(unit) || SOC_IS_TRIDENT3X(unit)) {
    998         FCOE_INIT_CHECK(unit);
    999 
   1000         return bcm_td2_fcoe_route_traverse(unit, flags, trav_fn, user_data);
   1001     }
   1002 #endif
   1003     return BCM_E_UNAVAIL;
   1004 }
   1005 
   1006