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

custom.c (3468B)


      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  * Custom API callouts
      8  */
      9 
     10 #include <bcm/types.h>
     11 
     12 #include <bcmx/custom.h>
     13 #include <bcmx/lport.h>
     14 #include <bcmx/bcmx.h>
     15 
     16 #include "bcmx_int.h"
     17 
     18 #define BCMX_CUSTOM_INIT_CHECK    BCMX_READY_CHECK
     19 
     20 #define BCMX_CUSTOM_SET_ERROR_CHECK(_unit, _check, _rv)    \
     21     BCMX_SET_ERROR_CHECK(_unit, _check, _rv)
     22 
     23 #define BCMX_CUSTOM_GET_IS_VALID(_unit, _rv)    \
     24     BCMX_ERROR_IS_VALID(_unit, _rv)
     25 
     26 /*
     27  * Notes:
     28  *     If 'port' is a physical port, apply to device where port resides.
     29  *     If 'port' is a virtual port, apply to all devices.
     30  */
     31 int
     32 bcmx_custom_port_set(bcmx_lport_t port, int type, int len, uint32 *args)
     33 {
     34     int         rv = BCM_E_UNAVAIL, tmp_rv;
     35     int         i, bcm_unit;
     36     bcm_port_t  bcm_port;
     37 
     38     BCMX_CUSTOM_INIT_CHECK;
     39 
     40     BCMX_LPORT_CHECK(port);
     41 
     42     if (BCMX_LPORT_IS_PHYSICAL(port)) {
     43         /*
     44          * Convert to old bcm port format to ensure application
     45          * custom routines continue to work.
     46          */
     47         if (BCM_FAILURE(_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port,
     48                                                 BCMX_DEST_CONVERT_NON_GPORT))) {
     49             return BCM_E_PORT;
     50         }
     51         return bcm_custom_port_set(bcm_unit, bcm_port, type, len, args);
     52     }
     53 
     54     /* Virtual port */
     55     BCMX_UNIT_ITER(bcm_unit, i) {
     56         tmp_rv = bcm_custom_port_set(bcm_unit, port, type, len, args);
     57         BCM_IF_ERROR_RETURN
     58             (BCMX_CUSTOM_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv));
     59     }
     60 
     61     return rv;
     62 }
     63 
     64 int
     65 bcmx_custom_port_get(bcmx_lport_t port, int type, int max_len,
     66                      uint32 *args, int *actual_len)
     67 {
     68     int         rv;
     69     int         i, bcm_unit;
     70     bcm_port_t  bcm_port;
     71 
     72     BCMX_CUSTOM_INIT_CHECK;
     73 
     74     BCMX_LPORT_CHECK(port);
     75 
     76     if (BCMX_LPORT_IS_PHYSICAL(port)) {
     77         /*
     78          * Convert to old bcm port format to ensure application
     79          * custom routines continue to work.
     80          */
     81         if (BCM_FAILURE(_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port,
     82                                                 BCMX_DEST_CONVERT_NON_GPORT))) {
     83             return BCM_E_PORT;
     84         }
     85         return bcm_custom_port_get(bcm_unit, bcm_port, type,
     86                                    max_len, args, actual_len);
     87     }
     88 
     89     /* Virtual port */
     90     BCMX_UNIT_ITER(bcm_unit, i) {
     91         rv = bcm_custom_port_get(bcm_unit, port, type, max_len, args, actual_len);
     92         if (BCMX_CUSTOM_GET_IS_VALID(bcm_unit, rv)) {
     93             return rv;
     94         }
     95     }
     96 
     97     return BCM_E_UNAVAIL;
     98 }
     99 
    100 int
    101 bcmx_custom_unit_set(int type, int len, uint32 *args)
    102 {
    103     int rv = BCM_E_UNAVAIL, tmp_rv;
    104     int i, bcm_unit;
    105 
    106     BCMX_CUSTOM_INIT_CHECK;
    107 
    108     BCMX_UNIT_ITER(bcm_unit, i) {
    109         tmp_rv = bcm_custom_port_set(bcm_unit, -1, type, len, args);
    110         BCM_IF_ERROR_RETURN
    111             (BCMX_CUSTOM_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv));
    112     }
    113 
    114     return rv;
    115 }
    116 
    117 int
    118 bcmx_custom_unit_get(int type, int max_len, uint32 *args, int *actual_len)
    119 {
    120     int rv = BCM_E_UNAVAIL;
    121     int i, bcm_unit;
    122 
    123     BCMX_CUSTOM_INIT_CHECK;
    124 
    125     BCMX_UNIT_ITER(bcm_unit, i) {
    126         rv = bcm_custom_port_get(bcm_unit, -1, type, max_len, args, actual_len);
    127         if (BCMX_CUSTOM_GET_IS_VALID(bcm_unit, rv)) {
    128             return rv;
    129         }
    130     }
    131 
    132     return BCM_E_UNAVAIL;
    133 }