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 (2415B)


      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 callouts
      8  * Mostly useful for running customized composite apis over remote units.
      9  */
     10 
     11 #include <bcm/types.h>
     12 #include <bcm/error.h>
     13 #include <bcm/custom.h>
     14 
     15 #include <bcm_int/control.h>
     16 
     17 static bcm_custom_cb_t	_custom_unit_func[BCM_UNITS_MAX];
     18 static void 	       *_custom_unit_user_data[BCM_UNITS_MAX];
     19 
     20 int
     21 bcm_common_custom_register(int unit,
     22                            bcm_custom_cb_t func,
     23                            void *user_data)
     24 {
     25     if (unit >= BCM_CONTROL_MAX) {
     26         return BCM_E_UNIT;
     27     }
     28     _custom_unit_func[unit] = func;
     29     _custom_unit_user_data[unit] = user_data;
     30     return BCM_E_NONE;
     31 }
     32 
     33 int
     34 bcm_common_custom_unregister(int unit)
     35 {
     36     return bcm_custom_register(unit, NULL, NULL);
     37 }
     38 
     39 int
     40 bcm_common_custom_port_set(int unit,
     41                            bcm_port_t port,
     42                            int type,
     43                            int len,
     44                            uint32 *args)
     45 {
     46     bcm_custom_cb_t     func;
     47     void *user_data;
     48 
     49     func = NULL;
     50     user_data = NULL;
     51     if (unit >= BCM_CONTROL_MAX) {
     52         return BCM_E_UNIT;
     53     } else {
     54         func = _custom_unit_func[unit];
     55         user_data = _custom_unit_user_data[unit];
     56    }
     57     if (func == NULL) {
     58         return BCM_E_UNAVAIL;
     59     }
     60     return (*func)(unit, port, BCM_CUSTOM_SET, type, len, args, NULL, user_data);
     61 }
     62 
     63 int
     64 bcm_common_custom_port_get(int unit,
     65                            bcm_port_t port,
     66                            int type,
     67                            int max_len,
     68                            uint32 *args,
     69                            int *actual_len)
     70 {
     71     bcm_custom_cb_t     func;
     72     void *user_data;
     73 
     74     func = NULL;
     75     user_data = NULL;
     76     if (unit >= BCM_CONTROL_MAX) {
     77         return BCM_E_UNIT;
     78     } else {
     79         func = _custom_unit_func[unit];
     80         user_data = _custom_unit_user_data[unit];
     81     }
     82     if (func == NULL) {
     83         return BCM_E_UNAVAIL;
     84     }
     85     
     86     if (actual_len) {
     87         /* default actual length is max_len passed in; application
     88            callback can modify to the appropriate value */
     89         *actual_len = max_len;
     90     }
     91     return (*func)(unit, port, BCM_CUSTOM_GET, type,
     92                    max_len, args, actual_len, user_data);
     93 }