From 3091373c488257975050d3fe9afb35e286bff46a Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 7 Jan 2016 17:11:33 -0800 Subject: [PATCH] Thermal thresholds. --- .../any/onlp/src/onlp/module/auto/onlp.yml | 9 +++ .../any/onlp/src/onlp/module/inc/onlp/onlp.x | 1 + .../onlp/src/onlp/module/inc/onlp/thermal.h | 36 +++++++++++ .../any/onlp/src/onlp/module/src/onlp_enums.c | 62 +++++++++++++++++++ 4 files changed, 108 insertions(+) diff --git a/packages/base/any/onlp/src/onlp/module/auto/onlp.yml b/packages/base/any/onlp/src/onlp/module/auto/onlp.yml index 6e39ae96..f264b05b 100644 --- a/packages/base/any/onlp/src/onlp/module/auto/onlp.yml +++ b/packages/base/any/onlp/src/onlp/module/auto/onlp.yml @@ -152,6 +152,12 @@ thermal_caps: &thermal_caps - GET_ERROR_THRESHOLD : (1 << 2) - GET_SHUTDOWN_THRESHOLD : (1 << 3) +# Thermal threshold, in milli-celsius +thermal_threshold: &thermal_threshold +- WARNING_DEFAULT : 45000 +- ERROR_DEFAULT : 55000 +- SHUTDOWN_DEFAULT : 60000 + # LED caps led_caps: &led_caps - ON_OFF : (1 << 0) @@ -232,6 +238,9 @@ definitions: onlp_thermal_caps: tag: thermal members: *thermal_caps + onlp_thermal_threshold: + tag: thermal + members: *thermal_threshold onlp_sfp_control: tag: sfp1 members: diff --git a/packages/base/any/onlp/src/onlp/module/inc/onlp/onlp.x b/packages/base/any/onlp/src/onlp/module/inc/onlp/onlp.x index 82b5f6c8..ebcf42da 100644 --- a/packages/base/any/onlp/src/onlp/module/inc/onlp/onlp.x +++ b/packages/base/any/onlp/src/onlp/module/inc/onlp/onlp.x @@ -56,6 +56,7 @@ ONLP_ENUMERATION_ENTRY(onlp_sfp_control_flag, "") ONLP_ENUMERATION_ENTRY(onlp_status, "") ONLP_ENUMERATION_ENTRY(onlp_thermal_caps, "") ONLP_ENUMERATION_ENTRY(onlp_thermal_status, "") +ONLP_ENUMERATION_ENTRY(onlp_thermal_threshold, "") #undef ONLP_ENUMERATION_ENTRY #endif /* */ diff --git a/packages/base/any/onlp/src/onlp/module/inc/onlp/thermal.h b/packages/base/any/onlp/src/onlp/module/inc/onlp/thermal.h index d1e5c3b1..6f73ab20 100644 --- a/packages/base/any/onlp/src/onlp/module/inc/onlp/thermal.h +++ b/packages/base/any/onlp/src/onlp/module/inc/onlp/thermal.h @@ -43,6 +43,13 @@ typedef enum onlp_thermal_status_e { ONLP_THERMAL_STATUS_PRESENT = (1 << 0), ONLP_THERMAL_STATUS_FAILED = (1 << 1), } onlp_thermal_status_t; + +/** onlp_thermal_threshold */ +typedef enum onlp_thermal_threshold_e { + ONLP_THERMAL_THRESHOLD_WARNING_DEFAULT = 45000, + ONLP_THERMAL_THRESHOLD_ERROR_DEFAULT = 55000, + ONLP_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT = 60000, +} onlp_thermal_threshold_t; /* */ /** @@ -58,6 +65,14 @@ typedef enum onlp_thermal_status_e { ONLP_THERMAL_CAPS_GET_ERROR_THRESHOLD | \ ONLP_THERMAL_CAPS_GET_SHUTDOWN_THRESHOLD ) +/** + * Shortcut for all default thermal threshold value. + */ +#define ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS \ + { ONLP_THERMAL_THRESHOLD_WARNING_DEFAULT, \ + ONLP_THERMAL_THRESHOLD_ERROR_DEFAULT, \ + ONLP_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT } + /** * Thermal sensor information structure. */ @@ -183,6 +198,27 @@ int onlp_thermal_status_valid(onlp_thermal_status_t e); extern aim_map_si_t onlp_thermal_status_map[]; /** onlp_thermal_status_desc_map table. */ extern aim_map_si_t onlp_thermal_status_desc_map[]; + +/** Enum names. */ +const char* onlp_thermal_threshold_name(onlp_thermal_threshold_t e); + +/** Enum values. */ +int onlp_thermal_threshold_value(const char* str, onlp_thermal_threshold_t* e, int substr); + +/** Enum descriptions. */ +const char* onlp_thermal_threshold_desc(onlp_thermal_threshold_t e); + +/** Enum validator. */ +int onlp_thermal_threshold_valid(onlp_thermal_threshold_t e); + +/** validator */ +#define ONLP_THERMAL_THRESHOLD_VALID(_e) \ + (onlp_thermal_threshold_valid((_e))) + +/** onlp_thermal_threshold_map table. */ +extern aim_map_si_t onlp_thermal_threshold_map[]; +/** onlp_thermal_threshold_desc_map table. */ +extern aim_map_si_t onlp_thermal_threshold_desc_map[]; /* */ #endif /* __ONLP_THERMAL_H__ */ diff --git a/packages/base/any/onlp/src/onlp/module/src/onlp_enums.c b/packages/base/any/onlp/src/onlp/module/src/onlp_enums.c index d74b832e..7fd366bf 100644 --- a/packages/base/any/onlp/src/onlp/module/src/onlp_enums.c +++ b/packages/base/any/onlp/src/onlp/module/src/onlp_enums.c @@ -1044,5 +1044,67 @@ onlp_thermal_status_valid(onlp_thermal_status_t e) return aim_map_si_i(NULL, e, onlp_thermal_status_map, 0) ? 1 : 0; } + +aim_map_si_t onlp_thermal_threshold_map[] = +{ + { "WARNING_DEFAULT", ONLP_THERMAL_THRESHOLD_WARNING_DEFAULT }, + { "ERROR_DEFAULT", ONLP_THERMAL_THRESHOLD_ERROR_DEFAULT }, + { "SHUTDOWN_DEFAULT", ONLP_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT }, + { NULL, 0 } +}; + +aim_map_si_t onlp_thermal_threshold_desc_map[] = +{ + { "None", ONLP_THERMAL_THRESHOLD_WARNING_DEFAULT }, + { "None", ONLP_THERMAL_THRESHOLD_ERROR_DEFAULT }, + { "None", ONLP_THERMAL_THRESHOLD_SHUTDOWN_DEFAULT }, + { NULL, 0 } +}; + +const char* +onlp_thermal_threshold_name(onlp_thermal_threshold_t e) +{ + const char* name; + if(aim_map_si_i(&name, e, onlp_thermal_threshold_map, 0)) { + return name; + } + else { + return "-invalid value for enum type 'onlp_thermal_threshold'"; + } +} + +int +onlp_thermal_threshold_value(const char* str, onlp_thermal_threshold_t* e, int substr) +{ + int i; + AIM_REFERENCE(substr); + if(aim_map_si_s(&i, str, onlp_thermal_threshold_map, 0)) { + /* Enum Found */ + *e = i; + return 0; + } + else { + return -1; + } +} + +const char* +onlp_thermal_threshold_desc(onlp_thermal_threshold_t e) +{ + const char* name; + if(aim_map_si_i(&name, e, onlp_thermal_threshold_desc_map, 0)) { + return name; + } + else { + return "-invalid value for enum type 'onlp_thermal_threshold'"; + } +} + +int +onlp_thermal_threshold_valid(onlp_thermal_threshold_t e) +{ + return aim_map_si_i(NULL, e, onlp_thermal_threshold_map, 0) ? 1 : 0; +} + /* */