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

udf_common.h (10781B)


      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 #ifndef __BCM_INT_UDF_COMMON_H__
      9 #define __BCM_INT_UDF_COMMON_H__
     10 
     11 #include <bcm/types.h>
     12 #include <soc/drv.h>
     13 #include <soc/error.h>
     14 #include <soc/scache.h>
     15 #include <bcm/module.h>
     16 #include <bcm_int/esw/switch.h>
     17 
     18 /*
     19  * Macro:
     20  *     _BCM_UDF_LOCK
     21  * Purpose:
     22  *     Take the UDF control mutex lock.
     23  */
     24 #define _BCM_UDF_LOCK(unit) \
     25     sal_mutex_take(SOC_CONTROL(unit)->udf_lock, sal_mutex_FOREVER)
     26 
     27 /*
     28  * Macro:
     29  *     _BCM_UDF_UNLOCK
     30  * Purpose:
     31  *     Give the UDF control mutex lock.
     32  */
     33 #define _BCM_UDF_UNLOCK(unit) \
     34     sal_mutex_give(SOC_CONTROL(unit)->udf_lock);
     35 
     36 
     37 /* Generic memory allocation routine. */
     38 #define _BCM_UDF_ALLOC(_ptr_,_size_of_,_descr_)               \
     39        do {                                                   \
     40            if (NULL == (_ptr_)) {                             \
     41               (_ptr_) = sal_alloc((_size_of_), (_descr_));    \
     42            }                                                  \
     43            if((_ptr_) != NULL) {                              \
     44                uint32 _size_ = _size_of_;                     \
     45                sal_memset((_ptr_), 0, (_size_));              \
     46                LOG_DEBUG(BSL_LS_BCM_UDF, (BSL_META_U(unit,    \
     47                "UDF Mem Alloc: Addr:%p bytes:%u '%s'\n\r"),   \
     48                                   _ptr_, _size_, _descr_));   \
     49            }  else {                                          \
     50                LOG_ERROR(BSL_LS_BCM_UDF, (BSL_META_U(unit,    \
     51                "UDF Mem Alloc failure: %s\n\r"), (_descr_))); \
     52            }                                                  \
     53        } while (0)
     54 
     55 #define _BCM_UDF_FREE(_ptr_)                                 \
     56        do {                                                  \
     57            if (NULL != (_ptr_)) {                            \
     58               LOG_DEBUG(BSL_LS_BCM_UDF, (BSL_META_U(unit,    \
     59               "UDF Mem Free: Addr:%p\n\r"), _ptr_));         \
     60               sal_free((_ptr_));                             \
     61               _ptr_ = NULL;                                  \
     62            } else {                                          \
     63               LOG_ERROR(BSL_LS_BCM_UDF, (BSL_META_U(unit,    \
     64               "UDF Error: Freeing NULL Ptr.\n\r")));         \
     65            }                                                 \
     66        } while (0)
     67 
     68 
     69 
     70 /********************** Linked-List Macros ***********************/
     71 /* Double Linked-list node add */
     72 #define _UDF_DLL_NODE_ADD(_u_, _new_, _head_)           \
     73     do {                                                \
     74           if (_new_ != NULL) {                          \
     75              /* Add new node at the tail of the head */ \
     76              if (NULL == _head_) {                      \
     77                 /* Adding first node */                 \
     78                 _head_ = _new_;                         \
     79              } else {                                   \
     80                 _head_->next = _new_;                   \
     81                 (_new_)->prev = _head_;                 \
     82                 _head_ = _new_;                         \
     83              }                                          \
     84           }                                             \
     85     } while (0)
     86 
     87 /* Double Linked-list node delete */
     88 #define _UDF_DLL_NODE_DEL(_u_, _del_, _head_, _temp_)        \
     89     do {                                                     \
     90           _temp_ = _head_;                                   \
     91           if ((_del_ != NULL) && (_head_ != NULL)) {         \
     92              while(_temp_ != NULL) {                         \
     93                 if (_del_ == _temp_) {                       \
     94                    if ((void *)_temp_->prev != NULL) {       \
     95                       _temp_->prev->next = _del_->next;      \
     96                    }                                         \
     97                    if ((void *)_temp_->next != NULL) {       \
     98                       _temp_->next->prev = _del_->prev;      \
     99                    }                                         \
    100                    if (_head_ == _temp_) {                   \
    101                       _head_ = _temp_->prev;                 \
    102                    }                                         \
    103                    break;                                    \
    104                 }                                            \
    105                 _temp_ = _temp_->prev;                       \
    106              }                                               \
    107           }                                                  \
    108     } while (0)
    109 
    110 /* Double Linked-list node Get */
    111 #define _UDF_DLL_NODE_GET(_u_, _id_, _head_, _temp_, _node_) \
    112      do {                                                \
    113          _node_ = NULL;                                  \
    114          (_temp_) = _head_;                              \
    115          while ((_temp_) != NULL) {                      \
    116             if (_temp_->udf_id == _id_) {                \
    117                _node_ = _temp_;                          \
    118                break;                                    \
    119             }                                            \
    120             _temp_ = _temp_->prev;                       \
    121          }                                               \
    122      } while(0)
    123 /*****************************************************************/
    124 
    125 /* Offset Chunk Granularity */
    126 #define _BCM_UDF_OFFSET_GRAN2 2
    127 
    128 /* Max number of UDF Chunks Supported */
    129 #define _BCM_UDF_OFFSET_CHUNKS16 16
    130 
    131 
    132 /*
    133  * Typedef:
    134  *     _bcm_udf_funct_t
    135  * Purpose:
    136  *     Function pointers to device specific Field functions
    137  */
    138 typedef struct _bcm_udf_funct_s {
    139     int(*udf_init)(int);                             /* Initialization function */
    140     int(*udf_detach)(int);                           /* detach function */
    141     int(*udf_chunk_create)(                          /* UDF Chunk create */
    142                            int,
    143                            bcm_udf_alloc_hints_t *,
    144                            bcm_udf_chunk_info_t *,
    145                            bcm_udf_id_t *);
    146     int(*udf_destroy)(int, bcm_udf_id_t);            /* UDF destroy */
    147     int(*udf_chunk_info_get)(                        /* UDF Chunk get */
    148                            int,
    149                            bcm_udf_id_t,
    150                            bcm_udf_chunk_info_t *);
    151     int(*udf_flow_based_chunk_arrange_set) (
    152                            int unit,
    153                            bcm_udf_tunnel_term_flow_type_t flow_type,
    154                            uint32 chunk_bmap);
    155     int(*udf_flow_based_chunk_arrange_get) (
    156                            int unit,
    157                            bcm_udf_tunnel_term_flow_type_t flow_type,
    158                            uint32 *chunk_bmap);
    159     int(*udf_abstr_pkt_format_obj_list_get)(         /* UDF Pkt Format Object Get */
    160                            int,
    161                            bcm_udf_abstract_pkt_format_t,
    162                            int,
    163                            bcm_udf_id_t *,
    164                            int *);
    165     int(*udf_abstr_pkt_format_info_get)(             /* UDF Pkt Format Info Get */
    166                            int,
    167                            bcm_udf_abstract_pkt_format_t,
    168                            bcm_udf_abstract_pkt_format_info_t *);
    169     int(*udf_wb_sync)(int);                          /* UDF WB Sync */
    170     int(*udf_range_checker_chunk_info_get)(          /* UDF Range checker chunk info get */
    171                            int,
    172                            uint8 *,
    173                            uint32 *);
    174     void(*udf_sw_dump)(int);                          /* UDF SW Dump */
    175     void(*udf_sw_mem_dump)(int unit, soc_mem_t, int);      /* UDF SW Memory Dump */
    176 } _bcm_udf_funct_t;
    177 
    178 /*
    179  * Typedef:
    180  *     _bcm_udf_control_t
    181  * Purpose:
    182  *     UDF control structure to manage and interact with
    183  *     device specific driver functions.
    184  */
    185 typedef struct _bcm_udf_control_s {
    186     uint8              flags;           /* Module specific flags */
    187     uint8              gran;            /* UDF granularity */
    188     uint8              num_chunks;      /* Max number of chunks supported. */
    189     uint16             max_udfs;        /* Maximum number of UDF objects - For WB purpose. */
    190     uint16             min_obj_id;      /* Minimum Object ID */
    191     uint16             max_obj_id;      /* Maximum Object ID */
    192     uint16             parse_limit;     /* Maximum parse offset limit in bytes */
    193     uint16             udf_id_running;  /* UDF ID running trackers */
    194     _bcm_udf_funct_t   functions;       /* Device specific functions. */
    195 } _bcm_udf_control_t;
    196 
    197 
    198 /*
    199  * Initialize for UDF control structure for MAX supported units.
    200  */
    201 extern _bcm_udf_control_t *_udf_control[BCM_MAX_NUM_UNITS];
    202 
    203 #define UDF_CONTROL(_u_) _udf_control[(_u_)]
    204 
    205 #define _BCM_UDF_INIT_CHECK(_u_) \
    206     do {                                       \
    207         if (UDF_CONTROL(_u_) == NULL) {        \
    208             return BCM_E_INIT;                 \
    209         }                                      \
    210     } while(0)
    211 
    212 #define _BCM_UDF_OFFSET_GRAN(_u_)  UDF_CONTROL(_u_)->gran
    213 
    214 #define _BCM_UDF_ID_MIN(_u_)   UDF_CONTROL(_u_)->min_obj_id
    215 #define _BCM_UDF_ID_MAX(_u_)   UDF_CONTROL(_u_)->max_obj_id
    216 
    217 #define _BCM_UDF_ID_VALIDATE(_u_, _id_)               \
    218     do {                                              \
    219         if ((_id_ < _BCM_UDF_ID_MIN(_u_)) ||          \
    220             (_id_ > _BCM_UDF_ID_MAX(_u_))) {          \
    221             return BCM_E_PARAM;                       \
    222         }                                             \
    223     } while(0)
    224 
    225 #define _BCM_UDF_OBJ_ID_RUNNING(_u_)                  \
    226     (UDF_CONTROL(_u_)->udf_id_running +=              \
    227     (UDF_CONTROL(_u_)->udf_id_running > _BCM_UDF_ID_MAX(_u_) ? 0 : 1))
    228 
    229 #define BCM_IF_NULL_RETURN_PARAM(_p_) \
    230     do {                                                    \
    231         if ((_p_) == NULL) {                                \
    232             return BCM_E_PARAM;                             \
    233         }                                                   \
    234     } while(0)
    235 
    236 #define BCM_IF_ERROR_GOTO_CLEANUP(_rv_) \
    237     do {                                                    \
    238         if (BCM_FAILURE(_rv_)) {                            \
    239             goto cleanup;                                   \
    240         }                                                   \
    241     } while (0)
    242 
    243 
    244 /* Granularity supported. */
    245 #define _BCM_UDF_CTRL_OFFSET_GRAN(_u_)  UDF_CONTROL(_u_)->gran
    246 
    247 /* Max number of chunks supported. */
    248 #define _BCM_UDF_CTRL_MAX_UDF_CHUNKS(_u_)  UDF_CONTROL(_u_)->num_chunks
    249 
    250 extern int
    251 _bcm_udf_common_init(int unit);
    252 extern int
    253 _bcm_udf_common_detach(int unit);
    254 #endif /* __BCM_INT_UDF_COMMON_H__ */