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

shr_template.h (31917B)


      1 /*
      2  * 
      3  *
      4  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5  * 
      6  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      7  *
      8  * File:        shr_template.h
      9  * Purpose:     Internal routines to the BCM library for template
     10  *              gu2 management.
     11  */
     12 
     13 #ifndef _SHR_TEMPLATE_H_
     14 /* { */
     15 #define _SHR_TEMPLATE_H_
     16 
     17 
     18 #include <sal/types.h>
     19 #include <sal/core/alloc.h>
     20 #include <sal/appl/io.h>
     21 
     22 #if (defined(BCM_PETRA_SUPPORT) || defined(BCM_DNX_SUPPORT))
     23 /* { */
     24 #include <shared/swstate/sw_state.h>
     25 
     26 
     27 /*
     28  *  Flags supported by the allocation system for each map set. If any of
     29  *  these are provided as group flags, they are automatically applied to the
     30  *  entire group, whether the individual flags include them or not.
     31  *
     32  *  SHR_TEMPLATE_MANAGE_SET_WITH_ID indicates that the template ID is provided by the
     33  *  caller, and that specific template.  The mapping must fail if the requested
     34  *  template is invalid or already in use.
     35  */
     36 
     37 #define SHR_TEMPLATE_MANAGE_SINGLE_FLAGS     0x00000007
     38 #define SHR_TEMPLATE_MANAGE_SET_WITH_ID      0x00000001
     39 #define SHR_TEMPLATE_MANAGE_IGNORE_DATA      0x00000002
     40 #define SHR_TEMPLATE_MANAGE_IGNORE_NOT_EXIST_OLD_TEMPLATE 0x00000004
     41 
     42 /*
     43  *  This enum defines the supported template management mechanisms.  Each one has some
     44  *  of its own advantages and disadvantages.  See the notes for each one if you
     45  *  need details to choose which might be best for a particular resource template management.
     46  */
     47 typedef enum shr_template_manage_e {   
     48     SHR_TEMPLATE_MANAGE_HASH = 0,
     49     SHR_TEMPLATE_MANAGE_COUNT /* last one indicates how many, not valid item */
     50 } shr_template_manage_t;
     51 
     52 /*
     53  *  This is an index to two callbacks arrays configured during template manager init.
     54  *  The arrays hold callbacks that indicate how a certain data is being set / get                         .
     55  *    from/to a typical buffer. The callback in idx given in EXTRA will be used.
     56  */
     57 typedef int (*shr_template_to_stream_t)(const void *data, void *to_stream, size_t size);
     58 typedef int (*shr_template_from_stream_t)(void *data, const void *from_stream, size_t size);
     59 
     60 typedef int shr_template_manage_hash_compare_extras_t;
     61 
     62 /*
     63  *  That's the max length of types and pools' names. Trying to create a type or a pool
     64  *  with a longer name would return an error.
     65  */
     66 #define SW_STATE_TEMPLATE_NAME_MAX_LENGTH 50
     67 
     68 typedef struct sw_state_template_name_s {
     69     char name[SW_STATE_TEMPLATE_NAME_MAX_LENGTH];
     70 } sw_state_template_name_t;
     71 
     72 
     73 /*
     74  *  This describes how a single resource maps to an underlying pool.
     75  *
     76  *  templatePoolId is the ID of the tepmlate pool on this unit from which this
     77  *  template is drawn.
     78  *
     79  *  name is a string that names this resource.  It is used only for diagnostic
     80  *  purposes.  Internally, the provided name will be copied to the same cell as
     81  *  the structure, so the name array is really variable length.
     82  */
     83 typedef struct _shr_template_type_desc_s {
     84     int templatePoolId;              /* unit specific template pool ID */
     85     int refCount;               /* number of elements allocated currently */
     86     sw_state_template_name_t name;               /* descriptive name (for diagnostics) */
     87 } _shr_template_type_desc_t;
     88 
     89 
     90 /*
     91  *  This describes a single resource pool on a unit.
     92  *
     93  *  templateManagerType is the ID of the reousrce manager that will be used to
     94  *  manage this resource pool on this unit.
     95  *
     96  *  low is the minimum valid element of this resource.
     97  *
     98  *  count is the number of valid elements of this resource.
     99  *
    100  *  extras points to a struct (which will be appended to this during setup of
    101  *  this pool) that provides additional arguments to how the pool needs to be
    102  *  managed.  This is provided because some of the supported allocation
    103  *  managers require more information than just the range of valid IDs.
    104  *
    105  *  name is a string that names this resource.  It is used only for diagnostic
    106  *  purposes.  Internally, the provided name will be copied to the same cell as
    107  *  the structure, so the name array is really variable length.
    108  *
    109  *  Note that the extras struct will be appended to the same memory cell as
    110  *  this struct, after the name, and so the pointer will not need to be freed
    111  *  when this is destroyed.
    112  */
    113 typedef struct _shr_template_pool_desc_s {
    114     shr_template_manage_t templateManagerType; /* which resoource manager to use */
    115     int template_low_id;                /* start template id */
    116     int template_count;                 /* Number of templates*/
    117     int max_entities;                   /* Number of Entities */
    118     size_t data_size;                   /* Data size */
    119     int refCount;                       /* number of types using this pool */
    120     uint32 templateHandle;              /* handle for this resource */
    121     shr_template_manage_hash_compare_extras_t extras; /* additional config per resmgr type */
    122     sw_state_template_name_t name;      /* descriptive name for diagnostics */
    123 } _shr_template_pool_desc_t;
    124                          
    125 /*
    126  *  This structure describes attributes about the unit, and includes lists
    127  *  that are applicable to the unit.  Note that while resource IDs and resource
    128  *  types are unit-specific, the resource managers themselves are globally
    129  *  available to all units.
    130  *
    131  *  resTypeCount indicates how many different resources on this unit are being
    132  *  managed through this system.  It is possible for more than one resource to
    133  *  use the same resource pool, but it is not possible for one resource to use
    134  *  more than one resource pool.
    135  *
    136  *  resPoolCount indicates how many different resource pools are being managed
    137  *  on this unit.
    138  *
    139  *  res points to an array of resource descriptors,  Each descriptor will map a
    140  *  single resource on the unit to its underlying resource pool.
    141  *
    142  *  pool points to an array of resource pool descriptors.  Each of these will
    143  *  describe a single resource pool on the unit and map to the manager that
    144  *  will be used for that particular pool.
    145  */
    146 typedef struct _shr_template_unit_desc_s {
    147     uint16 templateTypeCount;          /* maximum presented resource ID */
    148     uint16 templatePoolCount;          /* maximum resource pool ID */
    149     PARSER_HINT_ARR_PTR _shr_template_type_desc_t **template_param;   /* array of type -> pool map pointers */
    150     PARSER_HINT_ARR_PTR _shr_template_pool_desc_t **pool;  /* array of pool description pointers */
    151 } _shr_template_unit_desc_t;
    152 
    153 /*This is the prototype of call back function used to print the template data based on type */
    154 typedef void (*shr_template_print_func_t)(int unit, const void *);
    155 
    156 /*
    157  *   Function
    158  *      shr_template_init
    159  *   Purpose
    160  *      Initialize the tamplate manager for the unit
    161  *   Parameters
    162  *      (IN) unit          : unit number of the device
    163  *      (IN) num_template_types : number of template types for the unit
    164  *      (IN) num_template_pools : number of template pools for the unit
    165  *   Returns
    166  *      BCM_E_NONE if successful
    167  *      BCM_E_* as appropriate otherwise
    168  *   Notes
    169  *      template types map to template pools, from which the actual elements of
    170  *      the resources are drawn, and more than one type can pull elements from
    171  *      the same pool, so there should always be at least as many types as
    172  *      there are pools.
    173  *
    174  *      The unit will be limited to the number of types and pools specified
    175  *      here, as the descriptor space will be allocated and cleared by this
    176  *      function.  See below for how to configure types and pools.
    177  */
    178 extern int
    179 shr_template_init(int unit,
    180                   int num_template_types,
    181                   int num_template_pools,
    182                   shr_template_to_stream_t *to_stream_cb_arr,
    183                   shr_template_from_stream_t *from_stream_cb_arr,
    184                   int cb_arr_length);
    185 
    186 /*
    187  *   Function
    188  *      shr_template_get
    189  *   Purpose
    190  *      Get number of template pools and types configured for a unit
    191  *   Parameters
    192  *      (IN) unit           : unit number of the device
    193  *      (OUT) num_template_types : where to put number of template types for unit
    194  *      (OUT) num_template_pools : where to put number of template pools for unit
    195  *   Returns
    196  *      BCM_E_NONE if successful
    197  *      BCM_E_* as appropriate otherwise
    198  *   Notes
    199  *      Outbound arguments may be NULL for this call; any NULL outbound
    200  *      argument(s) will simply not be filled in.
    201  */
    202 extern int
    203 shr_template_get(int unit,
    204                  int *num_template_types,
    205                  int *num_template_pools);
    206 
    207 /*
    208  *   Function
    209  *      shr_template_pool_set
    210  *   Purpose
    211  *      Configure a template pool for the unit
    212  *   Parameters
    213  *      (IN) unit    	         : unit number of the device
    214  *      (IN) pool_id 	         : which pool to configure (0..max_template_pools-1)
    215  *      (IN) manager 	         : which manager to use for this pool
    216  *      (IN) template_low_id     : lowest valid template ID in this pool
    217  *      (IN) template_count      : number of valid templates in this pool
    218  *      (IN) max_entities        : the number of maximum referring entities
    219  *      (IN) data_size           : The size of the template data in this pool
    220  *      (IN) data_value          : initial value for all templates
    221  *      (IN) template_init_id    : the initial template for all referring entities
    222  *      (IN) extras   	         : pointer to extra information for the manager type
    223  *      (IN) name                : pointer to string naming the pool
    224  *   Returns
    225  *      BCM_E_NONE if successful
    226  *      BCM_E_* as appropriate otherwise
    227  *   Notes
    228  *      A template pool must be configured before any resources can point to
    229  *      it, and can not be changed after resources point to it.
    230  *
    231  *      The underlying template management information will be created during
    232  *      this call.  If this call is made again for the same template pool, and
    233  *      there are no resources using this pool, the old information will be
    234  *      destroyed and the new will be created in its stead, but if resources
    235  *      are already using this pool, the call will fail.
    236  *
    237  *      Most of the allocation managers require some extra arguments, so the
    238  *      extras argument is likely obligatory.  Each allocation manager has its
    239  *      own addiitonal arguments, for specific behavioural control or
    240  *      optimisation, and the correct extras type must be used accordingly.
    241  *
    242  *      This must be called after init, and before a pool can be used, even
    243  *      before a resource can be assigned to the pool.
    244  *
    245  *      Note that name and extras will be copied internally, and so the memory
    246  *      underlying those can be reused by the caller once this call completes.
    247  *
    248  *      All templates will be initialised to the value specified by data_value,
    249  *      unless it is NULL, in which case the templates values will be zeroed.
    250  *      Templates are not guaranteed to be returned to this value when freed.
    251  *
    252  *      The template with ID specified by template_init_id will be considered
    253  *      allocated with template_init_cnt references.  If this feature is not
    254  *      to be used, set template_init_cnt to zero.
    255  */
    256 extern int
    257 shr_template_pool_set(int unit,
    258                  int pool_id,
    259                  shr_template_manage_t manager,
    260                  int template_low_id,
    261                  int template_count,
    262                  int max_entities,
    263                  uint32 global_max,
    264                  size_t data_size,
    265                  const void *extras,
    266                  const char *name);
    267 
    268 /*
    269  *   Function
    270  *      shr_template_pool_get
    271  *   Purpose
    272  *      Get configuration for a resource pool on a particular unit
    273  *   Parameters
    274  *      (IN) unit             : unit number of the device
    275  *      (IN) pool_id          : which pool to query (0..max_template_pools-1)
    276  *      (OUT) manager         : where to put manager that is used for this pool
    277  *      (OUT) template_low_id : where to put template low ID value for this pool
    278  *      (OUT) template_count  : where to put template count value for this pool
    279  *      (OUT) data_size       : where to put data size
    280  *      (OUT) extras          : where to put pointer to extras for this pool
    281  *      (OUT) name            : where to put pointer to name for this pool
    282  *   Returns
    283  *      BCM_E_NONE if successful
    284  *      BCM_E_* as appropriate otherwise
    285  *   Notes
    286  *      Both extras and name will point to internal data for the pool and MUST
    287  *      NOT BE MODIFIED by the caller.  If the caller wants to change these
    288  *      data, the pool will have to be reconfigured with shr_template_pool_set.  If
    289  *      the caller wants to use the data in a destructive manner, the caller
    290  *      must copy the data to a local buffer first and use that buffer.
    291  *
    292  *      Outbound arguments may be NULL for this call; any NULL outbound
    293  *      argument(s) will simply not be filled in.
    294  *
    295  *      Since data_value, template_init_id, and template_init_count are only used
    296  *      to establish initial condition, they are not tracked afterward and not
    297  *      available via this call.
    298  */
    299 extern int
    300 shr_template_pool_get(int unit,
    301                       int pool_id,
    302                       shr_template_manage_t *manager,
    303                       int *template_low_id,
    304                       int *template_count,
    305                       int *max_entities,
    306                       size_t *data_size,
    307                       shr_template_manage_hash_compare_extras_t *extras,
    308                       sw_state_template_name_t *name);
    309 
    310 /*
    311  *   Function
    312  *      shr_template_pool_unset
    313  *   Purpose
    314  *      Destroy a template pool for the unit
    315  *   Parameters
    316  *      (IN) unit    : unit number of the device
    317  *      (IN) pool_id : which pool to configure (0..max_template_pools-1)
    318  *   Returns
    319  *      BCM_E_NONE if successful
    320  *      BCM_E_* as appropriate otherwise
    321  *   Notes
    322  *      Destroys the resource pool only if there are no types using the pool.
    323  *
    324  *      It will report an error (though the pool will be destroyed) if there
    325  *      appear to be elements in use but no types using the pool.
    326  */
    327 extern int
    328 shr_template_pool_unset(int unit,
    329                    int pool_id);
    330 
    331 
    332 /*
    333  *   Function
    334  *      shr_template_type_set
    335  *   Purpose
    336  *      Configure a template type
    337  *   Parameters
    338  *      (IN) unit          : unit number of the device
    339  *      (IN) template_type : which template to configure (0..max_template_types-1)
    340  *      (IN) pool_id   	   : which pool this resource uses (0..max_template_pools-1)
    341  *      (IN) name          : pointer to string naming the type
    342  *   Returns
    343  *      BCM_E_NONE if successful
    344  *      BCM_E_* as appropriate otherwise
    345  *   Notes
    346  *      More than one resource can use the same pool, but a single resource can
    347  *      only use one pool.
    348  *
    349  *      If this is called after a resource has templates mapped, it will
    350  *      fail.  If it is called before a resource has templates mapped, it
    351  *      will map the resource so it uses the specified pool.
    352  *
    353  *      This must be called after init and after the pool it uses has been
    354  *      configured, and before the associted resource can be used.
    355  *
    356  *      Note that name will be copied internally, and so the underlying memory
    357  *      can be reused by the caller once this call completes.
    358  */
    359 extern int
    360 shr_template_type_set(int unit,
    361                       int template_type,
    362                       int pool_id,
    363                       const char *name);
    364 
    365 /*
    366  *   Function
    367  *      shr_template_type_get
    368  *   Purpose
    369  *      Get information about a template type
    370  *   Parameters
    371  *      (IN) unit          : unit number of the device
    372  *      (IN) template_type : which resource to query (0..max_template_types-1)
    373  *      (OUT) pool_id      : where to put pool ID
    374  *      (OUT) name         : where to put name pointer
    375  *   Returns
    376  *      BCM_E_NONE if successful
    377  *      BCM_E_* as appropriate otherwise
    378  *   Notes
    379  *      Name will point to internal data for the type and MUST NOT BE MODIFIED
    380  *      by the caller.  If the caller wants to change the name, the type will
    381  *      have to be reconfigured with shr_template_type_set.  If the caller wants to
    382  *      use the name in a destructive manner, the caller must copy the name to
    383  *      a local buffer first and use that buffer.
    384  *
    385  *      Outbound arguments may be NULL for this call; any NULL outbound
    386  *      argument(s) will simply not be filled in.
    387  */
    388 extern int
    389 shr_template_type_get(int unit,
    390                       int template_type,
    391                       int *pool_id,
    392                       sw_state_template_name_t *name);
    393 
    394 /*
    395  *   Function
    396  *      shr_template_type_unset
    397  *   Purpose
    398  *      Destroy a template type
    399  *   Parameters
    400  *      (IN) unit      : unit number of the device
    401  *      (IN) res_id    : which template to configure (0..max_template_types-1)
    402  *   Returns
    403  *      BCM_E_NONE if successful
    404  *      BCM_E_* as appropriate otherwise
    405  *   Notes
    406  *      Will not destroy a template type if elements of that template are still
    407  *      in use.
    408  */
    409 extern int
    410 shr_template_type_unset(int unit,
    411                    int res_id);
    412 
    413 /*
    414  *   Function
    415  *      shr_template_detach
    416  *   Purpose
    417  *      Remove all template management for a unit
    418  *   Parameters
    419  *      (IN) unit : unit number of the device
    420  *   Returns
    421  *      BCM_E_NONE if successful
    422  *      BCM_E_* as appropriate otherwise
    423  *   Notes
    424  *      This will destroy all of the template pools, then tear down the rest of
    425  *      the resource management for the unit.
    426  */
    427 extern int
    428 shr_template_detach(int unit);
    429 
    430 /*
    431  *   Function
    432  *      shr_template_allocate
    433  *   Purpose
    434  *      Find a template to assign to the requested data.
    435  *   Parameters
    436  *      (IN) unit     	   : unit number of the device
    437  *      (IN) template_type : which template type to use
    438  *      (IN) flags    	   : flags providing specifics of what/how to set
    439  *      (IN) data          : data to be in the template
    440  *      (OUT) is_allocated : where to put 'first alloc' flag
    441  *      (IN/OUT) template_param  : where to map the resource.
    442  *   Returns
    443  *      BCM_E_NONE if successful
    444  *      BCM_E_* as appropriate otherwise
    445  *   Notes
    446  *      The template_param argument is IN if the WITH_ID flag is specified; it is OUT if
    447  *      the WITH_ID flag is not specified.
    448  *
    449  *      If WITH_ID is set and the specified template is not yet allocated, this
    450  *      will allocate it and set its data to the specified data.
    451  *
    452  *      If WITH_ID is set and the specified template is allocated, this will first
    453  *      verify that the new data are 'equal' to the existing data for the template,
    454  *      and: if so, will increment the reference count for the specified template;
    455  *      if not, will return BCM_E_EXISTS.
    456  *
    457  *      If WITH_ID is clear, this will look for a in-use template whose data are
    458  *      'equal' to the specified data.  If it finds such a template, it will
    459  *      increment that template's reference count and return it.  If it does not
    460  *      find such a template, it marks an available template as in use, sets its
    461  *      reference count to 1, copies the data to the template's data, and returns
    462  *      this template.  If there is no 'equal' or free template, BCM_E_RESOURCE.
    463  *
    464  *      Whether WITH_ID is provided or not, on success the int pointed to by the
    465  *      is_allocated argument will be updated.  It will be set TRUE if the template
    466  *      was free before, and FALSE if the template was already in use.  If the
    467  *      value is TRUE, appropriate resources should be updated by the caller (such
    468  *      as programming the data values to hardware registers).
    469  *
    470  *      It is not valid to specify IGNORE_DATA with this call.
    471  */
    472 extern int
    473 shr_template_allocate(int unit,
    474                       int template_type,
    475                       uint32 flags,
    476                       const void *data,
    477                       int *is_allocated,
    478                       int *template_param);
    479 
    480 /*
    481  *   Function
    482  *      shr_template_free
    483  *   Purpose
    484  *      Release a template (referrer no longer points to it)
    485  *   Parameters
    486  *      (IN) unit     	   : unit number of the device
    487  *      (IN) template_type : which template type to use
    488  *      (IN) template_param: which template to release
    489  *      (OUT) is_last      : is the template last pointed
    490  *   Returns
    491  *      BCM_E_NONE if successful
    492  *      BCM_E_* as appropriate otherwise
    493  *   Notes
    494  *      If the template is not currently in use, BCM_E_NOT_FOUND.
    495  *
    496  *      If the template is currently in use, this decrements the reference count,
    497  *      marking the template as free if the reference count hits zero.
    498  */
    499 extern int
    500 shr_template_free(int unit,
    501                   int template_type,
    502                   int template_param,
    503                   int *is_last);
    504 
    505 
    506 /*
    507  *   Function
    508  *      shr_template_free_group
    509  *   Purpose
    510  *      Release several templates (nof referrers no longer points to it)
    511  *   Parameters
    512  *      (IN) unit          : unit number of the device
    513  *      (IN) template_type : which template type to use
    514  *      (IN) template_param: which template to release
    515  *      (IN) nof_deductions: how many referrers to remove.
    516  *      (OUT) is_last      : is the template last pointed
    517  *   Returns
    518  *      BCM_E_NONE if successful
    519  *      BCM_E_* as appropriate otherwise
    520  *   Notes
    521  *      If the template is not currently in use, BCM_E_NOT_FOUND.
    522  *
    523  *      If the template is currently in use, this decrements the reference count,
    524  *      marking the template as free if the reference count hits zero.
    525  */
    526 extern int
    527 shr_template_free_group(int unit,
    528                   int template_type,
    529                   int template_param,
    530                   int nof_deductions,
    531                   int *is_last);
    532 
    533 /*
    534  *   Function
    535  *      shr_template_exchange
    536  *   Purpose
    537  *      Free a current template and allocate a new one for new data
    538  *   Parameters
    539  *      (IN) unit     	   : unit number of the device
    540  *      (IN) template_type : which template type to use
    541  *      (IN) flags    	   : flags providing specifics of what/how to set
    542  *      (IN) data          : data to be in the template
    543  *      (IN) old_template  : is the old template to free
    544  *      (OUT) is_last      : is the template last pointed
    545  *      (IN/OUT) template_param  : where to map the resource.
    546  *      (OUT) is_allocated : is the new template first pointed
    547  *   Returns
    548  *      BCM_E_NONE if successful
    549  *      BCM_E_NOT_FOUND, BCM_E_EXISTS - See notes.
    550  *      BCM_E_INTERNAL - Internal error.
    551  *      BCM_E_MEMORY - No memory.
    552  *      BCM_E_PARAM - Invalid parameters.
    553  *      BCM_E_* - Other (and also these) errors may be returned from copying the hash key.
    554  *   Notes
    555  *      The template_param argument is IN if the WITH_ID flag is specified; it is OUT if
    556  *      the WITH_ID flag is not specified.
    557  * 
    558  *      Whether WITH_ID is provided or not, if the allocation / update was successful,
    559  *      the template with ID provided in old_template will be freed.  Note this only
    560  *      happens if the selection of a new template succeeds, so the old template
    561  *      should not be reclaimed if this function fails.
    562  *      If old_template wasn't allocated before, and the flag IGNORE_NOT_EXIST_OLD_TEMPLATE
    563  *      is not set, then BCM_E_PARAM will be returned. If the flag is set, then a new refrence
    564  *      will be allocated without deleting the old one.
    565  * 
    566  *      If WITH_ID is set and the template specified in *template_param is not yet allocated,
    567  *      this will allocate it and set its data to the specified data. 
    568  * 
    569  *      If WITH_ID is set but IGNORE_DATA is not, and the specified template in *template_param is
    570  *      allocated, the data of the template will be changed to the new data.
    571  *      However if the data already exists with a different index, then BCM_E_EXISTS
    572  *      is returned (if the user wishes for the same key to be used for two different
    573  *      indices, it is possible to insert the index itself in the data which will
    574  *      automatically differentiate them).
    575  *
    576  *      If WITH_ID and IGNORE_DATA are both set, this will increment the reference
    577  *      count for the specified template.
    578  *      If the template does not exist then BCM_E_NOT_FOUND is returned.
    579  * 
    580  *      If WITH_ID is clear, this will look for a in-use template whose data are
    581  *      'equal' to the specified data.  If it finds such a template, it will
    582  *      increment that template's reference count and return it.  If it does not
    583  *      find such a template, it marks an available template as in use, sets its
    584  *      reference count to 1, copies the data to the template's data, and returns
    585  *      this template.  If there is no 'equal' or free template, BCM_E_RESOURCE.
    586  *
    587  *
    588  *      Whether WITH_ID is provided or not, on success the int pointed to by the
    589  *      is_allocated argument will be updated.  It will be set TRUE if the new
    590  *      template was free before, and FALSE if the new template was already in use.
    591  *      If the value is TRUE, appropriate resources should be updated by the caller
    592  *      (such as programming the data values to hardware registers).
    593  *
    594  *      It is not valid to specify IGNORE_DATA without WITH_ID.
    595  */
    596 extern int
    597 shr_template_exchange(int unit,
    598                       int template_type,
    599                       uint32 flags,
    600                       const void *data,
    601                       int old_template,
    602                       int *is_last,
    603                       int *template_param,
    604                       int *is_allocated);
    605         
    606                       
    607 /*
    608  *   Function
    609  *      shr_template_exchange_test
    610  *   Purpose
    611  *      Tests if it is possible to free a current template and allocate a new one for new data.
    612  *   Parameters
    613  *      (IN) unit     	   : unit number of the device
    614  *      (IN) template_type : which template type to use
    615  *      (IN) flags    	   : flags providing specifics of what/how to set
    616  *      (IN) data          : data to be in the template
    617  *      (IN) old_template  : is the old template to free
    618  *      (OUT) is_last      : is the template last pointed
    619  *      (IN/OUT) template_param  : where to map the resource.
    620  *      (OUT) is_allocated : is the new template first pointed
    621  *   Returns
    622  *      BCM_E_NONE if Test is successful.
    623  *      BCM_E_* as appropriate otherwise
    624  *   Notes
    625  *      This function only tests the the following configuration asked can be set,
    626  *      without space problem.
    627  *      
    628  *      The template_param argument is IN if the WITH_ID flag is specified; it is OUT if
    629  *      the WITH_ID flag is not specified.
    630  *
    631  *      If WITH_ID is set and the specified template is not yet allocated, this
    632  *      will allocate it and set its data to the specified data.
    633  *
    634  *      If WITH_ID is set but IGNORE_DATA is not, and the specified template is
    635  *      allocated, this will first verify that the new data are 'equal' to the
    636  *      existing data for the template, and: if so, will increment the reference
    637  *      count for the specified template; if not, will return BCM_E_EXISTS.
    638  *
    639  *      If WITH_ID and IGNORE_DATA are both set, this will increment the reference
    640  *      count for the specified template.  Note that this mode is intended only to
    641  *      be used as a shortcut for 'freeing' the referring entity while mapping its
    642  *      template back to a 'standard' or 'default' template.
    643  *
    644  *      If WITH_ID is clear, this will look for a in-use template whose data are
    645  *      'equal' to the specified data.  If it finds such a template, it will
    646  *      increment that template's reference count and return it.  If it does not
    647  *      find such a template, it marks an available template as in use, sets its
    648  *      reference count to 1, copies the data to the template's data, and returns
    649  *      this template.  If there is no 'equal' or free template, BCM_E_RESOURCE.
    650  *
    651  *      If the new template is successfully chosen, the template with ID provided
    652  *      in old_template will be freed.  Note this only happens if the selection of
    653  *      a new template succeeds, so the old template should not be reclaimed if
    654  *      this function fails.
    655  *
    656  *      Whether WITH_ID is provided or not, on success the int pointed to by the
    657  *      is_allocated argument will be updated.  It will be set TRUE if the new
    658  *      template was free before, and FALSE if the new template was already in use.
    659  *      If the value is TRUE, appropriate resources should be updated by the caller
    660  *      (such as programming the data values to hardware registers).
    661  *
    662  *      It is not valid to specify IGNORE_DATA without WITH_ID.
    663  */
    664 extern int
    665 shr_template_exchange_test(int unit,
    666                       int template_type,
    667                       uint32 flags,
    668                       const void *data,
    669                       int old_template,
    670                       int *is_last,
    671                       int *template_param,
    672                       int *is_allocated);
    673 
    674 /*
    675  *   Function
    676  *      shr_template_data_get
    677  *   Purpose
    678  *      Get the data from a specific template
    679  *   Parameters
    680  *      (IN) unit          : unit number of the device
    681  *      (IN) template_type : which template type to use
    682  *      (IN) template_param: which template to get
    683  *      (OUT) data         : where to put the template's data
    684  *   Returns
    685  *      BCM_E_NONE if successful
    686  *      BCM_E_NOT_FOUND if the template was not found.
    687  *      BCM_E_* as appropriate otherwise
    688  *   Notes
    689  */
    690 extern int
    691 shr_template_data_get(int unit,
    692                       int template_type,
    693                       int template_param,
    694                       void *data);
    695 
    696 /*
    697  *   Function
    698  *      shr_template_template_get
    699  *   Purpose
    700  *      Get the template from a specific data
    701  *   Parameters
    702  *      (IN) unit          : unit number of the device
    703  *      (IN) template_type : which template type to use
    704  *      (IN) data         : the template's data
    705  *      (OUT) template_param : which template
    706  *   Returns
    707  *      BCM_E_NONE if successful
    708  *      BCM_E_* as appropriate otherwise
    709  *   Notes
    710  */
    711 int
    712 shr_template_template_get(int unit,
    713                       int template_type,
    714                       const void *data,
    715                       int *template_param);
    716 
    717 /*
    718  *   Function
    719  *      shr_template_ref_count_get
    720  *   Purpose
    721  *      Get the reference counter from a specific template id
    722  *   Parameters
    723  *      (IN) unit          : unit number of the device
    724  *      (IN) template_type : which template type to use
    725  *      (IN) template_param: which template to get the reference count
    726  *      (OUT) ref_count    : where to put the template's reference count
    727  *   Returns
    728  *      BCM_E_NONE if successful
    729  *      BCM_E_* as appropriate otherwise
    730  *   Notes
    731  */
    732 extern int
    733 shr_template_ref_count_get(int unit,
    734                       int template_type,
    735                       int template_param,
    736                       uint32 *ref_count);
    737 
    738 
    739 extern int
    740 shr_template_allocate_group(int unit,
    741                       int template_type,
    742                       uint32 flags,
    743                       const void *data,
    744                       int nof_additions,
    745                       int *is_allocated,
    746                       int *template_param);
    747 
    748 /*
    749  *   Function
    750  *      shr_template_clear
    751  *   Purpose
    752  *      Free all templates located in this template_type
    753  *      (without free memory of the template resource)
    754  *   Parameters
    755  *      (IN) unit     	   : unit number of the device
    756  *      (IN) template_type : which template type to use
    757  *   Returns
    758  *      BCM_E_NONE if successful
    759  *      BCM_E_* as appropriate otherwise
    760  *   Notes
    761  */
    762 extern int
    763 shr_template_clear(int unit,
    764                   int template_type);
    765                   
    766 
    767 /*
    768  *   Function
    769  *      shr_template_dump
    770  *   Purpose
    771  *      Diagnostic dump of a unit's resource management information
    772  *   Parameters
    773  *      (IN) unit      : unit number of the device
    774  *   Returns
    775  *      BCM_E_NONE if successful
    776  *      BCM_E_* as appropriate otherwise
    777  */
    778 extern int
    779 shr_template_dump(int unit, int template_type);
    780 /* } */
    781 #endif /* defined(BCM_PETRA_SUPPORT) */
    782 /* } */
    783 #endif /* ndef _SHR_RESMGR_H */