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

error.h (5158B)


      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  * This file defines common error codes to be shared between API layers.
      8  *
      9  * Its contents are not used directly by applications; it is used only
     10  * by header files of parent APIs which need to define error codes.
     11  */
     12 
     13 #ifndef _SHR_ERROR_H
     14 #define _SHR_ERROR_H
     15 
     16 typedef enum {
     17     _SHR_E_NONE                 = 0,
     18     _SHR_E_INTERNAL             = -1,
     19     _SHR_E_MEMORY               = -2,
     20     _SHR_E_UNIT                 = -3,
     21     _SHR_E_PARAM                = -4,
     22     _SHR_E_EMPTY                = -5,
     23     _SHR_E_FULL                 = -6,
     24     _SHR_E_NOT_FOUND            = -7,
     25     _SHR_E_EXISTS               = -8,
     26     _SHR_E_TIMEOUT              = -9,
     27     _SHR_E_BUSY                 = -10,
     28     _SHR_E_FAIL                 = -11,
     29     _SHR_E_DISABLED             = -12,
     30     _SHR_E_BADID                = -13,
     31     _SHR_E_RESOURCE             = -14,
     32     _SHR_E_CONFIG               = -15,
     33     _SHR_E_UNAVAIL              = -16,
     34     _SHR_E_INIT                 = -17,
     35     _SHR_E_PORT                 = -18,
     36 
     37     _SHR_E_LIMIT                = -19           /* Must come last */
     38 } _shr_error_t;
     39 
     40 #define _SHR_ERRMSG_INIT        { \
     41         "Ok",                           /* E_NONE */ \
     42         "Internal error",               /* E_INTERNAL */ \
     43         "Out of memory",                /* E_MEMORY */ \
     44         "Invalid unit",                 /* E_UNIT */ \
     45         "Invalid parameter",            /* E_PARAM */ \
     46         "Table empty",                  /* E_EMPTY */ \
     47         "Table full",                   /* E_FULL */ \
     48         "Entry not found",              /* E_NOT_FOUND */ \
     49         "Entry exists",                 /* E_EXISTS */ \
     50         "Operation timed out",          /* E_TIMEOUT */ \
     51         "Operation still running",      /* E_BUSY */ \
     52         "Operation failed",             /* E_FAIL */ \
     53         "Operation disabled",           /* E_DISABLED */ \
     54         "Invalid identifier",           /* E_BADID */ \
     55         "No resources for operation",   /* E_RESOURCE */ \
     56         "Invalid configuration",        /* E_CONFIG */ \
     57         "Feature unavailable",          /* E_UNAVAIL */ \
     58         "Feature not initialized",      /* E_INIT */ \
     59         "Invalid port",                 /* E_PORT */ \
     60         "Unknown error"                 /* E_LIMIT */ \
     61         }
     62 
     63 extern char *_shr_errmsg[];
     64 
     65 #define _SHR_ERRMSG(r)          \
     66         _shr_errmsg[(((int)r) <= 0 && ((int)r) > _SHR_E_LIMIT) ? -(r) : -_SHR_E_LIMIT]
     67 
     68 #define _SHR_E_SUCCESS(rv)              ((rv) >= 0)
     69 #define _SHR_E_FAILURE(rv)              ((rv) < 0)
     70 
     71 /*
     72  * Macro:
     73  *      _SHR_E_IF_ERROR_RETURN
     74  * Purpose:
     75  *      Evaluate _op as an expression, and if an error, return.
     76  * Notes:
     77  *      This macro uses a do-while construct to maintain expected
     78  *      "C" blocking, and evaluates "op" ONLY ONCE so it may be
     79  *      a function call that has side affects.
     80  */
     81 
     82 #ifdef DEBUG_ERR_TRACE
     83 #include "shared/bsl.h"
     84 #define _SHR_ERROR_TRACE(__errcode__)  LOG_ERROR(BSL_LS_SOC_DIAG, \
     85                                                     (BSL_META("ERROR(%d)\n"), __errcode__))
     86 #define _SHR_RETURN(__expr__)  do { int __errcode__ = (__expr__);  if (__errcode__ < 0) _SHR_ERROR_TRACE(__errcode__);  return (__errcode__); } while (0)
     87 #else
     88 #define _SHR_ERROR_TRACE(__errcode__)
     89 #define _SHR_RETURN(__expr__)  return (__expr__)
     90 #endif
     91 
     92 #define _SHR_E_IF_ERROR_RETURN(op) \
     93     do { int __rv__; if ((__rv__ = (op)) < 0) { _SHR_ERROR_TRACE(__rv__);  return(__rv__); } } while(0)
     94 
     95 #define _SHR_E_IF_ERROR_CLEAN_RETURN(op,exop) \
     96     do { int __rv__; if ((__rv__ = (op)) < 0) { _SHR_ERROR_TRACE(__rv__); (exop); return(__rv__); } } while(0)
     97 
     98 #define _SHR_E_IF_ERROR_NOT_UNAVAIL_RETURN(op)                       \
     99     do {                                                                \
    100         int __rv__;                                                     \
    101         if (((__rv__ = (op)) < 0) && (__rv__ != _SHR_E_UNAVAIL)) {      \
    102             return(__rv__);                                             \
    103         }                                                               \
    104     } while(0)
    105 
    106 
    107 typedef enum {
    108     _SHR_SWITCH_EVENT_IO_ERROR      = 1,
    109     _SHR_SWITCH_EVENT_PARITY_ERROR  = 2,
    110     _SHR_SWITCH_EVENT_THREAD_ERROR  = 3,
    111     _SHR_SWITCH_EVENT_ACCESS_ERROR  = 4,
    112     _SHR_SWITCH_EVENT_ASSERT_ERROR  = 5,
    113     _SHR_SWITCH_EVENT_MODID_CHANGE  = 6,
    114     _SHR_SWITCH_EVENT_DOS_ATTACK    = 7,
    115     _SHR_SWITCH_EVENT_STABLE_FULL   = 8,
    116     _SHR_SWITCH_EVENT_STABLE_ERROR   = 9,
    117     _SHR_SWITCH_EVENT_UNCONTROLLED_SHUTDOWN = 10,
    118     _SHR_SWITCH_EVENT_WARM_BOOT_DOWNGRADE = 11,
    119     _SHR_SWITCH_EVENT_TUNE_ERROR = 12,
    120     _SHR_SWITCH_EVENT_DEVICE_INTERRUPT  = 13,
    121     _SHR_SWITCH_EVENT_ALARM = 14,
    122     _SHR_SWITCH_EVENT_MMU_BST_TRIGGER = 15,
    123     _SHR_SWITCH_EVENT_EPON_ALARM = 16,
    124     _SHR_SWITCH_EVENT_RUNT_DETECT = 17,
    125     _SHR_SWITCH_EVENT_AUTONEG_SPEED_ERROR = 18,
    126     _SHR_SWITCH_EVENT_COUNT             /* last, as always */
    127 } _shr_switch_event_t;
    128 
    129 #endif  /* !_SHR_ERROR_H */