| 1 |
/* Temperature control for NuRAN OC-2G BTS management daemon */ |
| 2 |
|
| 3 |
/* Copyright (C) 2015 by Yves Godin <[email protected]> |
| 4 |
* |
| 5 |
* Based on sysmoBTS: |
| 6 |
* sysmobts_mgr_temp.c |
| 7 |
* (C) 2014 by Holger Hans Peter Freyther |
| 8 |
* |
| 9 |
* All Rights Reserved |
| 10 |
* |
| 11 |
* This program is free software; you can redistribute it and/or modify |
| 12 |
* it under the terms of the GNU Affero General Public License as published by |
| 13 |
* the Free Software Foundation; either version 3 of the License, or |
| 14 |
* (at your option) any later version. |
| 15 |
* |
| 16 |
* This program is distributed in the hope that it will be useful, |
| 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
* GNU Affero General Public License for more details. |
| 20 |
* |
| 21 |
* You should have received a copy of the GNU Affero General Public License |
| 22 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 |
* |
| 24 |
*/ |
| 25 |
#include <inttypes.h> |
| 26 |
#include "misc/oc2gbts_mgr.h" |
| 27 |
#include "misc/oc2gbts_misc.h" |
| 28 |
#include "misc/oc2gbts_temp.h" |
| 29 |
#include "misc/oc2gbts_power.h" |
| 30 |
#include "misc/oc2gbts_led.h" |
| 31 |
#include "misc/oc2gbts_swd.h" |
| 32 |
#include "misc/oc2gbts_bid.h" |
| 33 |
#include "limits.h" |
| 34 |
|
| 35 |
#include <osmo-bts/logging.h> |
| 36 |
|
| 37 |
#include <osmocom/core/timer.h> |
| 38 |
#include <osmocom/core/utils.h> |
| 39 |
#include <osmocom/core/linuxlist.h> |
| 40 |
|
| 41 |
struct oc2gbts_mgr_instance *s_mgr; |
| 42 |
static struct osmo_timer_list sensor_ctrl_timer; |
| 43 |
|
| 44 |
static const struct value_string state_names[] = { |
| 45 |
{ STATE_NORMAL, "NORMAL" }, |
| 46 |
{ STATE_WARNING_HYST, "WARNING (HYST)" }, |
| 47 |
{ STATE_WARNING, "WARNING" }, |
| 48 |
{ STATE_CRITICAL, "CRITICAL" }, |
| 49 |
{ 0, NULL } |
| 50 |
}; |
| 51 |
|
| 52 |
/* private function prototype */ |
| 53 |
static void sensor_ctrl_check(struct oc2gbts_mgr_instance *mgr); |
| 54 |
|
| 55 |
const char *oc2gbts_mgr_sensor_get_state(enum oc2gbts_sensor_state state) |
| 56 |
{ |
| 57 |
return get_value_string(state_names, state); |
| 58 |
} |
| 59 |
|
| 60 |
static int next_state(enum oc2gbts_sensor_state current_state, int critical, int warning) |
| 61 |
{ |
| 62 |
int next_state = -1; |
| 63 |
switch (current_state) { |
| 64 |
case STATE_NORMAL: |
| 65 |
if (critical) |
| 66 |
next_state = STATE_CRITICAL; |
| 67 |
else if (warning) |
| 68 |
next_state = STATE_WARNING; |
| 69 |
break; |
| 70 |
case STATE_WARNING_HYST: |
| 71 |
if (critical) |
| 72 |
next_state = STATE_CRITICAL; |
| 73 |
else if (warning) |
| 74 |
next_state = STATE_WARNING; |
| 75 |
else |
| 76 |
next_state = STATE_NORMAL; |
| 77 |
break; |
| 78 |
case STATE_WARNING: |
| 79 |
if (critical) |
| 80 |
next_state = STATE_CRITICAL; |
| 81 |
else if (!warning) |
| 82 |
next_state = STATE_WARNING_HYST; |
| 83 |
break; |
| 84 |
case STATE_CRITICAL: |
| 85 |
if (!critical && !warning) |
| 86 |
next_state = STATE_WARNING; |
| 87 |
break; |
| 88 |
}; |
| 89 |
|
| 90 |
return next_state; |
| 91 |
} |
| 92 |
|
| 93 |
static void handle_normal_actions(int actions) |
| 94 |
{ |
| 95 |
/* switch on the PA */ |
| 96 |
if (actions & SENSOR_ACT_NORM_PA_ON) { |
| 97 |
if (oc2gbts_power_set(OC2GBTS_POWER_PA, 1) != 0) { |
| 98 |
LOGP(DTEMP, LOGL_ERROR, |
| 99 |
"Failed to switch on the PA\n"); |
| 100 |
} else { |
| 101 |
LOGP(DTEMP, LOGL_INFO, |
| 102 |
"Switched on the PA as normal action.\n"); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
if (actions & SENSOR_ACT_NORM_BTS_SRV_ON) { |
| 107 |
LOGP(DTEMP, LOGL_INFO, |
| 108 |
"Going to switch on the BTS service\n"); |
| 109 |
/* |
| 110 |
* TODO: use/create something like nspawn that serializes |
| 111 |
* and used SIGCHLD/waitpid to pick up the dead processes |
| 112 |
* without invoking shell. |
| 113 |
*/ |
| 114 |
system("/bin/systemctl start osmo-bts.service"); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
static void handle_actions(int actions) |
| 119 |
{ |
| 120 |
/* switch off the PA */ |
| 121 |
if (actions & SENSOR_ACT_PA_OFF) { |
| 122 |
if (oc2gbts_option_get(OC2GBTS_OPTION_PA)) { |
| 123 |
if (oc2gbts_power_set(OC2GBTS_POWER_PA, 0) != 0) { |
| 124 |
LOGP(DTEMP, LOGL_ERROR, |
| 125 |
"Failed to switch off the PA. Stop BTS?\n"); |
| 126 |
} else { |
| 127 |
LOGP(DTEMP, LOGL_NOTICE, |
| 128 |
"Switched off the PA due temperature.\n"); |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
if (actions & SENSOR_ACT_BTS_SRV_OFF) { |
| 134 |
LOGP(DTEMP, LOGL_NOTICE, |
| 135 |
"Going to switch off the BTS service\n"); |
| 136 |
/* |
| 137 |
* TODO: use/create something like nspawn that serializes |
| 138 |
* and used SIGCHLD/waitpid to pick up the dead processes |
| 139 |
* without invoking shell. |
| 140 |
*/ |
| 141 |
system("/bin/systemctl stop osmo-bts.service"); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
void handle_ceased_actions(struct oc2gbts_mgr_instance *mgr) |
| 146 |
{ int i; |
| 147 |
uint32_t cause; |
| 148 |
|
| 149 |
if (!mgr->oc2gbts_ctrl.is_up) |
| 150 |
return; |
| 151 |
|
| 152 |
LOGP(DTEMP, LOGL_DEBUG, "handle_ceased_actions in state %s, warn_flags=0x%x, crit_flags=0x%x\n", |
| 153 |
oc2gbts_mgr_sensor_get_state(mgr->state.state), |
| 154 |
mgr->oc2gbts_ctrl.warn_flags, |
| 155 |
mgr->oc2gbts_ctrl.crit_flags); |
| 156 |
|
| 157 |
for (i = 0; i < 32; i++) { |
| 158 |
cause = 1 << i; |
| 159 |
/* clear warning flag without sending ceased alarm */ |
| 160 |
if (mgr->oc2gbts_ctrl.warn_flags & cause) |
| 161 |
mgr->oc2gbts_ctrl.warn_flags &= ~cause; |
| 162 |
|
| 163 |
/* clear warning flag with sending ceased alarm */ |
| 164 |
if (mgr->oc2gbts_ctrl.crit_flags & cause) { |
| 165 |
/* clear associated flag */ |
| 166 |
mgr->oc2gbts_ctrl.crit_flags &= ~cause; |
| 167 |
/* dispatch ceased alarm */ |
| 168 |
switch (cause) { |
| 169 |
case S_MGR_TEMP_SUPPLY_CRIT_MAX_ALARM: |
| 170 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_SUPPLY_MAX_FAIL, "oc2g-oml-ceased", "Main power supply temperature is too high"); |
| 171 |
break; |
| 172 |
case S_MGR_TEMP_SOC_CRIT_MAX_ALARM: |
| 173 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_SOC_MAX_FAIL, "oc2g-oml-ceased", "SoC temperature is too high"); |
| 174 |
break; |
| 175 |
case S_MGR_TEMP_FPGA_CRIT_MAX_ALARM: |
| 176 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_FPGA_MAX_FAIL, "oc2g-oml-ceased", "FPGA temperature is too high"); |
| 177 |
break; |
| 178 |
case S_MGR_TEMP_RMS_DET_CRIT_MAX_ALARM: |
| 179 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_RMS_DET_MAX_FAIL, "oc2g-oml-ceased", "RMS detector temperature is too high"); |
| 180 |
break; |
| 181 |
case S_MGR_TEMP_OCXO_CRIT_MAX_ALARM: |
| 182 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_OCXO_MAX_FAIL, "oc2g-oml-ceased", "OCXO temperature is too high"); |
| 183 |
break; |
| 184 |
case S_MGR_TEMP_TRX_CRIT_MAX_ALARM: |
| 185 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_TRX_MAX_FAIL, "oc2g-oml-ceased", "TRX temperature is too high"); |
| 186 |
break; |
| 187 |
case S_MGR_TEMP_PA_CRIT_MAX_ALARM: |
| 188 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_PA_MAX_FAIL, "oc2g-oml-ceased", "PA temperature is too high"); |
| 189 |
break; |
| 190 |
case S_MGR_SUPPLY_CRIT_MAX_ALARM: |
| 191 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_SUPPLY_MAX_FAIL, "oc2g-oml-ceased", "Power supply voltage is too high"); |
| 192 |
break; |
| 193 |
case S_MGR_SUPPLY_CRIT_MIN_ALARM: |
| 194 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_SUPPLY_MIN_FAIL, "oc2g-oml-ceased", "Power supply voltage is too low"); |
| 195 |
break; |
| 196 |
case S_MGR_VSWR_CRIT_MAX_ALARM: |
| 197 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_VSWR_MAX_FAIL, "oc2g-oml-ceased", "VSWR is too high"); |
| 198 |
break; |
| 199 |
case S_MGR_PWR_SUPPLY_CRIT_MAX_ALARM: |
| 200 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_PWR_SUPPLY_MAX_FAIL, "oc2g-oml-ceased", "Power supply consumption is too high"); |
| 201 |
break; |
| 202 |
case S_MGR_PWR_PA_CRIT_MAX_ALARM: |
| 203 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_PWR_PA_MAX_FAIL, "oc2g-oml-ceased", "PA power consumption is too high"); |
| 204 |
break; |
| 205 |
default: |
| 206 |
break; |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
return; |
| 211 |
} |
| 212 |
|
| 213 |
void handle_alert_actions(struct oc2gbts_mgr_instance *mgr) |
| 214 |
{ int i; |
| 215 |
uint32_t cause; |
| 216 |
|
| 217 |
if (!mgr->oc2gbts_ctrl.is_up) |
| 218 |
return; |
| 219 |
|
| 220 |
LOGP(DTEMP, LOGL_DEBUG, "handle_alert_actions in state %s, crit_flags=0x%x\n", |
| 221 |
oc2gbts_mgr_sensor_get_state(mgr->state.state), |
| 222 |
mgr->oc2gbts_ctrl.crit_flags); |
| 223 |
|
| 224 |
for (i = 0; i < 32; i++) { |
| 225 |
cause = 1 << i; |
| 226 |
if (mgr->oc2gbts_ctrl.crit_flags & cause) { |
| 227 |
switch(cause) { |
| 228 |
case S_MGR_TEMP_SUPPLY_CRIT_MAX_ALARM: |
| 229 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_SUPPLY_MAX_FAIL, "oc2g-oml-alert", "Main power supply temperature is too high"); |
| 230 |
break; |
| 231 |
case S_MGR_TEMP_SOC_CRIT_MAX_ALARM: |
| 232 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_SOC_MAX_FAIL, "oc2g-oml-alert", "SoC temperature is too high"); |
| 233 |
break; |
| 234 |
case S_MGR_TEMP_FPGA_CRIT_MAX_ALARM: |
| 235 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_FPGA_MAX_FAIL, "oc2g-oml-alert", "FPGA temperature is too high"); |
| 236 |
break; |
| 237 |
case S_MGR_TEMP_RMS_DET_CRIT_MAX_ALARM: |
| 238 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_RMS_DET_MAX_FAIL, "oc2g-oml-alert", "RMS detector temperature is too high"); |
| 239 |
break; |
| 240 |
case S_MGR_TEMP_OCXO_CRIT_MAX_ALARM: |
| 241 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_OCXO_MAX_FAIL, "oc2g-oml-alert", "OCXO temperature is too high"); |
| 242 |
break; |
| 243 |
case S_MGR_TEMP_TRX_CRIT_MAX_ALARM: |
| 244 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_TRX_MAX_FAIL, "oc2g-oml-alert", "TRX temperature is too high"); |
| 245 |
break; |
| 246 |
case S_MGR_TEMP_PA_CRIT_MAX_ALARM: |
| 247 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_TEMP_PA_MAX_FAIL, "oc2g-oml-alert", "PA temperature is too high"); |
| 248 |
break; |
| 249 |
case S_MGR_SUPPLY_CRIT_MAX_ALARM: |
| 250 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_SUPPLY_MAX_FAIL, "oc2g-oml-alert", "Power supply voltage is too high"); |
| 251 |
break; |
| 252 |
case S_MGR_SUPPLY_CRIT_MIN_ALARM: |
| 253 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_SUPPLY_MIN_FAIL, "oc2g-oml-alert", "Power supply voltage is too low"); |
| 254 |
break; |
| 255 |
case S_MGR_VSWR_CRIT_MAX_ALARM: |
| 256 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_VSWR_MAX_FAIL, "oc2g-oml-alert", "VSWR is too high"); |
| 257 |
break; |
| 258 |
case S_MGR_PWR_SUPPLY_CRIT_MAX_ALARM: |
| 259 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_PWR_SUPPLY_MAX_FAIL, "oc2g-oml-alert", "Power supply consumption is too high"); |
| 260 |
break; |
| 261 |
case S_MGR_PWR_PA_CRIT_MAX_ALARM: |
| 262 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_CRIT_PWR_PA_MAX_FAIL, "oc2g-oml-alert", "PA power consumption is too high"); |
| 263 |
break; |
| 264 |
default: |
| 265 |
break; |
| 266 |
} |
| 267 |
} |
| 268 |
} |
| 269 |
return; |
| 270 |
} |
| 271 |
|
| 272 |
void handle_warn_actions(struct oc2gbts_mgr_instance *mgr) |
| 273 |
{ int i; |
| 274 |
uint32_t cause; |
| 275 |
|
| 276 |
if (!mgr->oc2gbts_ctrl.is_up) |
| 277 |
return; |
| 278 |
|
| 279 |
LOGP(DTEMP, LOGL_DEBUG, "handle_warn_actions in state %s, warn_flags=0x%x\n", |
| 280 |
oc2gbts_mgr_sensor_get_state(mgr->state.state), |
| 281 |
mgr->oc2gbts_ctrl.warn_flags); |
| 282 |
|
| 283 |
for (i = 0; i < 32; i++) { |
| 284 |
cause = 1 << i; |
| 285 |
if (mgr->oc2gbts_ctrl.warn_flags & cause) { |
| 286 |
switch(cause) { |
| 287 |
case S_MGR_TEMP_SUPPLY_WARN_MAX_ALARM: |
| 288 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_SUPPLY_HIGH_FAIL, "oc2g-oml-alert", "Main power supply temperature is high"); |
| 289 |
break; |
| 290 |
case S_MGR_TEMP_SUPPLY_WARN_MIN_ALARM: |
| 291 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_SUPPLY_LOW_FAIL, "oc2g-oml-alert", "Main power supply temperature is low"); |
| 292 |
break; |
| 293 |
case S_MGR_TEMP_SOC_WARN_MAX_ALARM: |
| 294 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_SOC_HIGH_FAIL, "oc2g-oml-alert", "SoC temperature is high"); |
| 295 |
break; |
| 296 |
case S_MGR_TEMP_SOC_WARN_MIN_ALARM: |
| 297 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_SOC_LOW_FAIL, "oc2g-oml-alert", "SoC temperature is low"); |
| 298 |
break; |
| 299 |
case S_MGR_TEMP_FPGA_WARN_MAX_ALARM: |
| 300 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_FPGA_HIGH_FAIL, "oc2g-oml-alert", "FPGA temperature is high"); |
| 301 |
break; |
| 302 |
case S_MGR_TEMP_FPGA_WARN_MIN_ALARM: |
| 303 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_FPGA_LOW_FAIL, "oc2g-oml-alert", "FPGA temperature is low"); |
| 304 |
break; |
| 305 |
case S_MGR_TEMP_RMS_DET_WARN_MAX_ALARM: |
| 306 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_RMS_DET_HIGH_FAIL, "oc2g-oml-alert", "RMS detector temperature is high"); |
| 307 |
break; |
| 308 |
case S_MGR_TEMP_RMS_DET_WARN_MIN_ALARM: |
| 309 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_RMS_DET_LOW_FAIL, "oc2g-oml-alert", "RMS detector temperature is low"); |
| 310 |
break; |
| 311 |
case S_MGR_TEMP_OCXO_WARN_MAX_ALARM: |
| 312 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_OCXO_HIGH_FAIL, "oc2g-oml-alert", "OCXO temperature is high"); |
| 313 |
break; |
| 314 |
case S_MGR_TEMP_OCXO_WARN_MIN_ALARM: |
| 315 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_OCXO_LOW_FAIL, "oc2g-oml-alert", "OCXO temperature is low"); |
| 316 |
break; |
| 317 |
case S_MGR_TEMP_TRX_WARN_MAX_ALARM: |
| 318 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_TRX_HIGH_FAIL, "oc2g-oml-alert", "TRX temperature is high"); |
| 319 |
break; |
| 320 |
case S_MGR_TEMP_TRX_WARN_MIN_ALARM: |
| 321 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_TRX_LOW_FAIL, "oc2g-oml-alert", "TRX temperature is low"); |
| 322 |
break; |
| 323 |
case S_MGR_TEMP_PA_WARN_MAX_ALARM: |
| 324 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_PA_HIGH_FAIL, "oc2g-oml-alert", "PA temperature is high"); |
| 325 |
break; |
| 326 |
case S_MGR_TEMP_PA_WARN_MIN_ALARM: |
| 327 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_TEMP_PA_LOW_FAIL, "oc2g-oml-alert", "PA temperature is low"); |
| 328 |
break; |
| 329 |
case S_MGR_SUPPLY_WARN_MAX_ALARM: |
| 330 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_SUPPLY_HIGH_FAIL, "oc2g-oml-alert", "Power supply voltage is high"); |
| 331 |
break; |
| 332 |
case S_MGR_SUPPLY_WARN_MIN_ALARM: |
| 333 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_SUPPLY_LOW_FAIL, "oc2g-oml-alert", "Power supply voltage is low"); |
| 334 |
break; |
| 335 |
case S_MGR_VSWR_WARN_MAX_ALARM: |
| 336 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_VSWR_HIGH_FAIL, "oc2g-oml-alert", "VSWR is high"); |
| 337 |
break; |
| 338 |
case S_MGR_PWR_SUPPLY_WARN_MAX_ALARM: |
| 339 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_PWR_SUPPLY_HIGH_FAIL, "oc2g-oml-alert", "Power supply consumption is high"); |
| 340 |
break; |
| 341 |
case S_MGR_PWR_PA_WARN_MAX_ALARM: |
| 342 |
oc2gbts_mgr_dispatch_alarm(mgr, NM_EVT_CAUSE_WARN_PWR_PA_HIGH_FAIL, "oc2g-oml-alert", "PA power consumption is high"); |
| 343 |
break; |
| 344 |
default: |
| 345 |
break; |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
return; |
| 350 |
} |
| 351 |
|
| 352 |
/** |
| 353 |
* Go back to normal! Depending on the configuration execute the normal |
| 354 |
* actions that could (start to) undo everything we did in the other |
| 355 |
* states. What is still missing is the power increase/decrease depending |
| 356 |
* on the state. E.g. starting from WARNING_HYST we might want to slowly |
| 357 |
* ramp up the output power again. |
| 358 |
*/ |
| 359 |
static void execute_normal_act(struct oc2gbts_mgr_instance *manager) |
| 360 |
{ |
| 361 |
LOGP(DTEMP, LOGL_NOTICE, "System is back to normal state.\n"); |
| 362 |
handle_ceased_actions(manager); |
| 363 |
handle_normal_actions(manager->state.action_norm); |
| 364 |
} |
| 365 |
|
| 366 |
static void execute_warning_act(struct oc2gbts_mgr_instance *manager) |
| 367 |
{ |
| 368 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning state.\n"); |
| 369 |
handle_warn_actions(manager); |
| 370 |
handle_actions(manager->state.action_warn); |
| 371 |
} |
| 372 |
|
| 373 |
/* Preventive timer call-back */ |
| 374 |
static void preventive_timer_cb(void *_data) |
| 375 |
{ |
| 376 |
struct oc2gbts_mgr_instance *mgr = _data; |
| 377 |
|
| 378 |
/* Delete current preventive timer if possible */ |
| 379 |
osmo_timer_del(&mgr->alarms.preventive_timer); |
| 380 |
|
| 381 |
LOGP(DTEMP, LOGL_DEBUG, "Preventive timer expired in %d sec, retry=%d\n", |
| 382 |
mgr->alarms.preventive_duration, |
| 383 |
mgr->alarms.preventive_retry); |
| 384 |
|
| 385 |
/* Turn on PA and clear action flag */ |
| 386 |
if (mgr->state.action_comb & SENSOR_ACT_PA_OFF) { |
| 387 |
mgr->state.action_comb &= ~SENSOR_ACT_PA_OFF; |
| 388 |
|
| 389 |
if (oc2gbts_option_get(OC2GBTS_OPTION_PA)) { |
| 390 |
if (oc2gbts_power_set(OC2GBTS_POWER_PA, 1)) |
| 391 |
LOGP(DTEMP, LOGL_ERROR, "Failed to switch on the PA\n"); |
| 392 |
else |
| 393 |
LOGP(DTEMP, LOGL_DEBUG, "Re-enable PA after preventive timer expired in %d sec\n", |
| 394 |
mgr->alarms.preventive_duration); |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
/* restart check sensor timer */ |
| 399 |
osmo_timer_del(&sensor_ctrl_timer); |
| 400 |
osmo_timer_schedule(&sensor_ctrl_timer, OC2GBTS_SENSOR_TIMER_DURATION, 0); |
| 401 |
|
| 402 |
return; |
| 403 |
|
| 404 |
} |
| 405 |
|
| 406 |
static void execute_preventive_act(struct oc2gbts_mgr_instance *manager) |
| 407 |
{ |
| 408 |
struct oc2gbts_preventive_list *prevent_list, *prevent_list2; |
| 409 |
|
| 410 |
/* update LED pattern */ |
| 411 |
select_led_pattern(manager); |
| 412 |
|
| 413 |
/* do nothing if the preventive action list is empty */ |
| 414 |
if (llist_empty(&manager->alarms.list)) |
| 415 |
return; |
| 416 |
|
| 417 |
llist_for_each_entry_safe(prevent_list, prevent_list2, &manager->alarms.list, list) { |
| 418 |
/* Delete the timer in list and perform action*/ |
| 419 |
if (prevent_list) { |
| 420 |
/* Delete current preventive timer if possible */ |
| 421 |
osmo_timer_del(&manager->alarms.preventive_timer); |
| 422 |
|
| 423 |
/* Start/restart preventive timer */ |
| 424 |
if (prevent_list->param.sleep_sec) { |
| 425 |
manager->alarms.preventive_timer.cb = preventive_timer_cb; |
| 426 |
manager->alarms.preventive_timer.data = manager; |
| 427 |
osmo_timer_schedule(&manager->alarms.preventive_timer, prevent_list->param.sleep_sec, 0); |
| 428 |
|
| 429 |
LOGP(DTEMP, LOGL_DEBUG,"Preventive timer scheduled for %d sec, preventive flags=0x%x\n", |
| 430 |
prevent_list->param.sleep_sec, |
| 431 |
prevent_list->action_flag); |
| 432 |
} |
| 433 |
/* Update active flags */ |
| 434 |
manager->state.action_comb |= prevent_list->action_flag; |
| 435 |
|
| 436 |
/* Turn off PA */ |
| 437 |
if (manager->state.action_comb & SENSOR_ACT_PA_OFF) { |
| 438 |
if (oc2gbts_power_set(OC2GBTS_POWER_PA, 0)) |
| 439 |
LOGP(DTEMP, LOGL_ERROR, "Failed to switch off the PA\n"); |
| 440 |
} |
| 441 |
|
| 442 |
/* Delete this preventive entry */ |
| 443 |
llist_del(&prevent_list->list); |
| 444 |
talloc_free(prevent_list); |
| 445 |
LOGP(DTEMP, LOGL_DEBUG,"Deleted preventive entry from list, entries left=%d\n", |
| 446 |
llist_count(&manager->alarms.list)); |
| 447 |
|
| 448 |
/* stay in last state is preventive active has exceed maximum number of retries */ |
| 449 |
if (manager->alarms.preventive_retry > OC2GBTS_PREVENT_RETRY) |
| 450 |
LOGP(DTEMP, LOGL_NOTICE, "Maximum number of preventive active exceed\n"); |
| 451 |
else |
| 452 |
/* increase retry counter */ |
| 453 |
manager->alarms.preventive_retry++; |
| 454 |
} |
| 455 |
} |
| 456 |
return; |
| 457 |
} |
| 458 |
|
| 459 |
static void execute_critical_act(struct oc2gbts_mgr_instance *manager) |
| 460 |
{ |
| 461 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical warning.\n"); |
| 462 |
handle_alert_actions(manager); |
| 463 |
handle_actions(manager->state.action_crit); |
| 464 |
|
| 465 |
} |
| 466 |
|
| 467 |
static void oc2gbts_mgr_sensor_handle(struct oc2gbts_mgr_instance *manager, |
| 468 |
int critical, int warning) |
| 469 |
{ |
| 470 |
int new_state = next_state(manager->state.state, critical, warning); |
| 471 |
|
| 472 |
/* run preventive action if it is possible */ |
| 473 |
execute_preventive_act(manager); |
| 474 |
|
| 475 |
/* Nothing changed */ |
| 476 |
if (new_state < 0) |
| 477 |
return; |
| 478 |
LOGP(DTEMP, LOGL_INFO, "Moving from state %s to %s.\n", |
| 479 |
get_value_string(state_names, manager->state.state), |
| 480 |
get_value_string(state_names, new_state)); |
| 481 |
manager->state.state = new_state; |
| 482 |
switch (manager->state.state) { |
| 483 |
case STATE_NORMAL: |
| 484 |
execute_normal_act(manager); |
| 485 |
/* reset alarms */ |
| 486 |
manager->alarms.temp_high = 0; |
| 487 |
manager->alarms.temp_max = 0; |
| 488 |
manager->alarms.vswr_high = 0; |
| 489 |
manager->alarms.vswr_max = 0; |
| 490 |
manager->alarms.supply_low = 0; |
| 491 |
manager->alarms.supply_min = 0; |
| 492 |
manager->alarms.supply_pwr_high = 0; |
| 493 |
manager->alarms.supply_pwr_max = 0; |
| 494 |
manager->alarms.pa_pwr_max = 0; |
| 495 |
manager->alarms.pa_pwr_high = 0; |
| 496 |
manager->state.action_comb = 0; |
| 497 |
manager->alarms.preventive_retry = 0; |
| 498 |
/* update LED pattern */ |
| 499 |
select_led_pattern(manager); |
| 500 |
break; |
| 501 |
case STATE_WARNING_HYST: |
| 502 |
/* do nothing? Maybe start to increase transmit power? */ |
| 503 |
break; |
| 504 |
case STATE_WARNING: |
| 505 |
execute_warning_act(manager); |
| 506 |
/* update LED pattern */ |
| 507 |
select_led_pattern(manager); |
| 508 |
break; |
| 509 |
case STATE_CRITICAL: |
| 510 |
execute_critical_act(manager); |
| 511 |
/* update LED pattern */ |
| 512 |
select_led_pattern(manager); |
| 513 |
break; |
| 514 |
}; |
| 515 |
} |
| 516 |
|
| 517 |
static void schedule_preventive_action(struct oc2gbts_mgr_instance *mgr, int action, int duration) |
| 518 |
{ |
| 519 |
struct oc2gbts_preventive_list *prevent_list; |
| 520 |
|
| 521 |
/* add to pending list */ |
| 522 |
prevent_list = talloc_zero(tall_mgr_ctx, struct oc2gbts_preventive_list); |
| 523 |
if (prevent_list) { |
| 524 |
prevent_list->action_flag = action; |
| 525 |
prevent_list->param.sleep_sec = duration; |
| 526 |
prevent_list->param.sleep_usec = 0; |
| 527 |
llist_add_tail(&prevent_list->list, &mgr->alarms.list); |
| 528 |
LOGP(DTEMP, LOGL_DEBUG,"Added preventive action to list, duration=%d sec, total entries=%d\n", |
| 529 |
prevent_list->param.sleep_sec, |
| 530 |
llist_count(&mgr->alarms.list)); |
| 531 |
} |
| 532 |
return; |
| 533 |
} |
| 534 |
|
| 535 |
static void sensor_ctrl_check(struct oc2gbts_mgr_instance *mgr) |
| 536 |
{ |
| 537 |
int rc; |
| 538 |
int temp, volt, vswr, power = 0; |
| 539 |
int warn_thresh_passed = 0; |
| 540 |
int crit_thresh_passed = 0; |
| 541 |
int action = 0; |
| 542 |
|
| 543 |
LOGP(DTEMP, LOGL_INFO, "Going to check the temperature.\n"); |
| 544 |
|
| 545 |
/* Read the current supply temperature */ |
| 546 |
rc = oc2gbts_temp_get(OC2GBTS_TEMP_SUPPLY, &temp); |
| 547 |
if (rc < 0) { |
| 548 |
LOGP(DTEMP, LOGL_NOTICE, |
| 549 |
"Failed to read the supply temperature. rc=%d\n", rc); |
| 550 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 551 |
} else { |
| 552 |
temp = temp / 1000; |
| 553 |
if (temp > mgr->temp.supply_temp_limit.thresh_warn_max) { |
| 554 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because supply temperature is over %d\n", mgr->temp.supply_temp_limit.thresh_warn_max); |
| 555 |
warn_thresh_passed = 1; |
| 556 |
mgr->alarms.temp_high = 1; |
| 557 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_SUPPLY_WARN_MAX_ALARM; |
| 558 |
/* add to pending list */ |
| 559 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 560 |
} |
| 561 |
if (temp < mgr->temp.supply_temp_limit.thresh_warn_min){ |
| 562 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because supply temperature is under %d\n", mgr->temp.supply_temp_limit.thresh_warn_min); |
| 563 |
warn_thresh_passed = 1; |
| 564 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_SUPPLY_WARN_MIN_ALARM; |
| 565 |
} |
| 566 |
if (temp > mgr->temp.supply_temp_limit.thresh_crit_max) { |
| 567 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because supply temperature is over %d\n", mgr->temp.supply_temp_limit.thresh_crit_max); |
| 568 |
crit_thresh_passed = 1; |
| 569 |
mgr->alarms.temp_max = 1; |
| 570 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_TEMP_SUPPLY_CRIT_MAX_ALARM; |
| 571 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_TEMP_SUPPLY_WARN_MAX_ALARM; |
| 572 |
action = SENSOR_ACT_PA_OFF; |
| 573 |
/* add to pending list */ |
| 574 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 575 |
} |
| 576 |
LOGP(DTEMP, LOGL_INFO, "Supply temperature is: %d\n", temp); |
| 577 |
} |
| 578 |
|
| 579 |
/* Read the current SoC temperature */ |
| 580 |
rc = oc2gbts_temp_get(OC2GBTS_TEMP_SOC, &temp); |
| 581 |
if (rc < 0) { |
| 582 |
LOGP(DTEMP, LOGL_NOTICE, |
| 583 |
"Failed to read the SoC temperature. rc=%d\n", rc); |
| 584 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 585 |
} else { |
| 586 |
temp = temp / 1000; |
| 587 |
if (temp > mgr->temp.soc_temp_limit.thresh_warn_max) { |
| 588 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because SoC temperature is over %d\n", mgr->temp.soc_temp_limit.thresh_warn_max); |
| 589 |
warn_thresh_passed = 1; |
| 590 |
mgr->alarms.temp_high = 1; |
| 591 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_SOC_WARN_MAX_ALARM; |
| 592 |
/* add to pending list */ |
| 593 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 594 |
} |
| 595 |
if (temp < mgr->temp.soc_temp_limit.thresh_warn_min){ |
| 596 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because SoC temperature is under %d\n", mgr->temp.soc_temp_limit.thresh_warn_min); |
| 597 |
warn_thresh_passed = 1; |
| 598 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_SOC_WARN_MIN_ALARM; |
| 599 |
} |
| 600 |
if (temp > mgr->temp.soc_temp_limit.thresh_crit_max) { |
| 601 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because SoC temperature is over %d\n", mgr->temp.soc_temp_limit.thresh_crit_max); |
| 602 |
crit_thresh_passed = 1; |
| 603 |
mgr->alarms.temp_max = 1; |
| 604 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_TEMP_SOC_CRIT_MAX_ALARM; |
| 605 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_TEMP_SOC_WARN_MAX_ALARM; |
| 606 |
action = SENSOR_ACT_PA_OFF; |
| 607 |
/* add to pending list */ |
| 608 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 609 |
} |
| 610 |
LOGP(DTEMP, LOGL_INFO, "SoC temperature is: %d\n", temp); |
| 611 |
} |
| 612 |
|
| 613 |
/* Read the current fpga temperature */ |
| 614 |
rc = oc2gbts_temp_get(OC2GBTS_TEMP_FPGA, &temp); |
| 615 |
if (rc < 0) { |
| 616 |
LOGP(DTEMP, LOGL_NOTICE, |
| 617 |
"Failed to read the fpga temperature. rc=%d\n", rc); |
| 618 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 619 |
} else { |
| 620 |
temp = temp / 1000; |
| 621 |
if (temp > mgr->temp.fpga_temp_limit.thresh_warn_max) { |
| 622 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because fpga temperature is over %d\n", mgr->temp.fpga_temp_limit.thresh_warn_max); |
| 623 |
warn_thresh_passed = 1; |
| 624 |
mgr->alarms.temp_high = 1; |
| 625 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_FPGA_WARN_MAX_ALARM; |
| 626 |
/* add to pending list */ |
| 627 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 628 |
} |
| 629 |
if (temp < mgr->temp.fpga_temp_limit.thresh_warn_min) { |
| 630 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because fpga temperature is under %d\n", mgr->temp.fpga_temp_limit.thresh_warn_min); |
| 631 |
warn_thresh_passed = 1; |
| 632 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_FPGA_WARN_MIN_ALARM; |
| 633 |
} |
| 634 |
if (temp > mgr->temp.fpga_temp_limit.thresh_crit_max) { |
| 635 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because fpga temperature is over %d\n", mgr->temp.fpga_temp_limit.thresh_crit_max); |
| 636 |
crit_thresh_passed = 1; |
| 637 |
mgr->alarms.temp_max = 1; |
| 638 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_TEMP_FPGA_CRIT_MAX_ALARM; |
| 639 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_TEMP_FPGA_WARN_MAX_ALARM; |
| 640 |
action = SENSOR_ACT_PA_OFF; |
| 641 |
/* add to pending list */ |
| 642 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 643 |
} |
| 644 |
LOGP(DTEMP, LOGL_INFO, "FPGA temperature is: %d\n", temp); |
| 645 |
} |
| 646 |
|
| 647 |
if (oc2gbts_option_get(OC2GBTS_OPTION_RMS_FWD) || oc2gbts_option_get(OC2GBTS_OPTION_RMS_REFL)) { |
| 648 |
/* Read the current RMS detector temperature */ |
| 649 |
rc = oc2gbts_temp_get(OC2GBTS_TEMP_RMSDET, &temp); |
| 650 |
if (rc < 0) { |
| 651 |
LOGP(DTEMP, LOGL_NOTICE, |
| 652 |
"Failed to read the RMS detector temperature. rc=%d\n", rc); |
| 653 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 654 |
} else { |
| 655 |
temp = temp / 1000; |
| 656 |
if (temp > mgr->temp.rmsdet_temp_limit.thresh_warn_max) { |
| 657 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because RMS detector temperature is over %d\n", mgr->temp.rmsdet_temp_limit.thresh_warn_max); |
| 658 |
warn_thresh_passed = 1; |
| 659 |
mgr->alarms.temp_high = 1; |
| 660 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_RMS_DET_WARN_MAX_ALARM; |
| 661 |
/* add to pending list */ |
| 662 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 663 |
} |
| 664 |
if (temp < mgr->temp.rmsdet_temp_limit.thresh_warn_min) { |
| 665 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because RMS detector temperature is under %d\n", mgr->temp.rmsdet_temp_limit.thresh_warn_min); |
| 666 |
warn_thresh_passed = 1; |
| 667 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_RMS_DET_WARN_MIN_ALARM; |
| 668 |
} |
| 669 |
if (temp > mgr->temp.rmsdet_temp_limit.thresh_crit_max) { |
| 670 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because RMS detector temperature is over %d\n", mgr->temp.rmsdet_temp_limit.thresh_crit_max); |
| 671 |
crit_thresh_passed = 1; |
| 672 |
mgr->alarms.temp_max = 1; |
| 673 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_TEMP_RMS_DET_CRIT_MAX_ALARM; |
| 674 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_TEMP_RMS_DET_WARN_MAX_ALARM; |
| 675 |
action = SENSOR_ACT_PA_OFF; |
| 676 |
/* add to pending list */ |
| 677 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 678 |
} |
| 679 |
LOGP(DTEMP, LOGL_INFO, "RMS detector temperature is: %d\n", temp); |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
/* Read the current OCXO temperature */ |
| 684 |
rc = oc2gbts_temp_get(OC2GBTS_TEMP_OCXO, &temp); |
| 685 |
if (rc < 0) { |
| 686 |
LOGP(DTEMP, LOGL_NOTICE, |
| 687 |
"Failed to read the OCXO temperature. rc=%d\n", rc); |
| 688 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 689 |
} else { |
| 690 |
temp = temp / 1000; |
| 691 |
if (temp > mgr->temp.ocxo_temp_limit.thresh_warn_max) { |
| 692 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because OCXO temperature is over %d\n", mgr->temp.ocxo_temp_limit.thresh_warn_max); |
| 693 |
warn_thresh_passed = 1; |
| 694 |
mgr->alarms.temp_high = 1; |
| 695 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_OCXO_WARN_MAX_ALARM; |
| 696 |
/* add to pending list */ |
| 697 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 698 |
} |
| 699 |
if (temp < mgr->temp.ocxo_temp_limit.thresh_warn_min) { |
| 700 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because OCXO temperature is under %d\n", mgr->temp.ocxo_temp_limit.thresh_warn_min); |
| 701 |
warn_thresh_passed = 1; |
| 702 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_OCXO_WARN_MIN_ALARM; |
| 703 |
} |
| 704 |
if (temp > mgr->temp.ocxo_temp_limit.thresh_crit_max) { |
| 705 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because OCXO temperature is over %d\n", mgr->temp.ocxo_temp_limit.thresh_crit_max); |
| 706 |
crit_thresh_passed = 1; |
| 707 |
mgr->alarms.temp_max = 1; |
| 708 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_TEMP_OCXO_CRIT_MAX_ALARM; |
| 709 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_TEMP_OCXO_WARN_MAX_ALARM; |
| 710 |
action = SENSOR_ACT_PA_OFF; |
| 711 |
/* add to pending list */ |
| 712 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 713 |
} |
| 714 |
LOGP(DTEMP, LOGL_INFO, "OCXO temperature is: %d\n", temp); |
| 715 |
} |
| 716 |
|
| 717 |
/* Read the current TX temperature */ |
| 718 |
rc = oc2gbts_temp_get(OC2GBTS_TEMP_TX, &temp); |
| 719 |
if (rc < 0) { |
| 720 |
LOGP(DTEMP, LOGL_NOTICE, |
| 721 |
"Failed to read the TX temperature. rc=%d\n", rc); |
| 722 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 723 |
} else { |
| 724 |
temp = temp / 1000; |
| 725 |
if (temp > mgr->temp.tx_temp_limit.thresh_warn_max) { |
| 726 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because TX temperature is over %d\n", mgr->temp.tx_temp_limit.thresh_warn_max); |
| 727 |
warn_thresh_passed = 1; |
| 728 |
mgr->alarms.temp_high = 1; |
| 729 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_TRX_WARN_MAX_ALARM; |
| 730 |
/* add to pending list */ |
| 731 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 732 |
} |
| 733 |
if (temp < mgr->temp.tx_temp_limit.thresh_warn_min) { |
| 734 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because TX temperature is under %d\n", mgr->temp.tx_temp_limit.thresh_warn_min); |
| 735 |
warn_thresh_passed = 1; |
| 736 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_TRX_WARN_MIN_ALARM; |
| 737 |
} |
| 738 |
if (temp > mgr->temp.tx_temp_limit.thresh_crit_max) { |
| 739 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because TX temperature is over %d\n", mgr->temp.tx_temp_limit.thresh_crit_max); |
| 740 |
crit_thresh_passed = 1; |
| 741 |
mgr->alarms.temp_max = 1; |
| 742 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_TEMP_TRX_CRIT_MAX_ALARM; |
| 743 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_TEMP_TRX_WARN_MAX_ALARM; |
| 744 |
action = SENSOR_ACT_PA_OFF; |
| 745 |
/* add to pending list */ |
| 746 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 747 |
} |
| 748 |
LOGP(DTEMP, LOGL_INFO, "TX temperature is: %d\n", temp); |
| 749 |
} |
| 750 |
|
| 751 |
if (oc2gbts_option_get(OC2GBTS_OPTION_PA_TEMP)) { |
| 752 |
/* Read the current PA temperature */ |
| 753 |
rc = oc2gbts_temp_get(OC2GBTS_TEMP_PA, &temp); |
| 754 |
if (rc < 0) { |
| 755 |
LOGP(DTEMP, LOGL_NOTICE, |
| 756 |
"Failed to read the PA temperature. rc=%d\n", rc); |
| 757 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 758 |
} else { |
| 759 |
temp = temp / 1000; |
| 760 |
if (temp > mgr->temp.pa_temp_limit.thresh_warn_max) { |
| 761 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because PA temperature because is over %d\n", mgr->temp.pa_temp_limit.thresh_warn_max); |
| 762 |
warn_thresh_passed = 1; |
| 763 |
mgr->alarms.temp_high = 1; |
| 764 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_PA_WARN_MAX_ALARM; |
| 765 |
action = SENSOR_ACT_PA_OFF; |
| 766 |
/* add to pending list */ |
| 767 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 768 |
} |
| 769 |
if (temp < mgr->temp.pa_temp_limit.thresh_warn_min) { |
| 770 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because PA temperature because is under %d\n", mgr->temp.pa_temp_limit.thresh_warn_min); |
| 771 |
warn_thresh_passed = 1; |
| 772 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_TEMP_PA_WARN_MIN_ALARM; |
| 773 |
} |
| 774 |
if (temp > mgr->temp.pa_temp_limit.thresh_crit_max) { |
| 775 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because PA temperature because is over %d\n", mgr->temp.pa_temp_limit.thresh_crit_max); |
| 776 |
crit_thresh_passed = 1; |
| 777 |
mgr->alarms.temp_max = 1; |
| 778 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_TEMP_PA_CRIT_MAX_ALARM; |
| 779 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_TEMP_PA_WARN_MAX_ALARM; |
| 780 |
action = SENSOR_ACT_PA_OFF; |
| 781 |
/* add to pending list */ |
| 782 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 783 |
} |
| 784 |
LOGP(DTEMP, LOGL_INFO, "PA temperature is: %d\n", temp); |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
/* Read the current main supply voltage */ |
| 789 |
if (oc2gbts_power_get(OC2GBTS_POWER_SUPPLY)) { |
| 790 |
rc = oc2gbts_power_sensor_get(OC2GBTS_POWER_SUPPLY, OC2GBTS_POWER_VOLTAGE, &volt); |
| 791 |
if (rc < 0) { |
| 792 |
LOGP(DTEMP, LOGL_NOTICE, |
| 793 |
"Failed to read the main supply voltage. rc=%d\n", rc); |
| 794 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 795 |
} else { |
| 796 |
if (volt > mgr->volt.supply_volt_limit.thresh_warn_max) { |
| 797 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because supply voltage is over %d\n", mgr->volt.supply_volt_limit.thresh_warn_max); |
| 798 |
warn_thresh_passed = 1; |
| 799 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_SUPPLY_WARN_MAX_ALARM; |
| 800 |
} |
| 801 |
if (volt < mgr->volt.supply_volt_limit.thresh_warn_min) { |
| 802 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because supply voltage is under %d\n", mgr->volt.supply_volt_limit.thresh_warn_min); |
| 803 |
warn_thresh_passed = 1; |
| 804 |
mgr->alarms.supply_low = 1; |
| 805 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_SUPPLY_WARN_MIN_ALARM; |
| 806 |
} |
| 807 |
if (volt > mgr->volt.supply_volt_limit.thresh_crit_max) { |
| 808 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because supply voltage is over %d\n", mgr->volt.supply_volt_limit.thresh_crit_max); |
| 809 |
crit_thresh_passed = 1; |
| 810 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_SUPPLY_CRIT_MAX_ALARM; |
| 811 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_SUPPLY_WARN_MAX_ALARM; |
| 812 |
} |
| 813 |
|
| 814 |
if (volt < mgr->volt.supply_volt_limit.thresh_crit_min) { |
| 815 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because supply voltage is under %d\n", mgr->volt.supply_volt_limit.thresh_crit_min); |
| 816 |
crit_thresh_passed = 1; |
| 817 |
mgr->alarms.supply_min = 1; |
| 818 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_SUPPLY_CRIT_MIN_ALARM; |
| 819 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_SUPPLY_WARN_MIN_ALARM; |
| 820 |
action = SENSOR_ACT_PA_OFF; |
| 821 |
/* add to pending list */ |
| 822 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_NONE); |
| 823 |
} |
| 824 |
LOGP(DTEMP, LOGL_INFO, "Main supply voltage is: %d\n", volt); |
| 825 |
} |
| 826 |
} |
| 827 |
|
| 828 |
/* Read the main supply power consumption */ |
| 829 |
if (oc2gbts_power_get(OC2GBTS_POWER_SUPPLY)) { |
| 830 |
rc = oc2gbts_power_sensor_get(OC2GBTS_POWER_SUPPLY, OC2GBTS_POWER_POWER, &power); |
| 831 |
if (rc < 0) { |
| 832 |
LOGP(DTEMP, LOGL_NOTICE, |
| 833 |
"Failed to read the power supply current. rc=%d\n", rc); |
| 834 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 835 |
} else { |
| 836 |
power /= 1000000; |
| 837 |
if (power > mgr->pwr.supply_pwr_limit.thresh_warn_max) { |
| 838 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because main supply power consumption is over %d\n", mgr->pwr.supply_pwr_limit.thresh_warn_max); |
| 839 |
warn_thresh_passed = 1; |
| 840 |
mgr->alarms.supply_pwr_high = 1; |
| 841 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_PWR_SUPPLY_WARN_MAX_ALARM; |
| 842 |
} |
| 843 |
if (power > mgr->pwr.supply_pwr_limit.thresh_crit_max) { |
| 844 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because main supply power consumption is over %d\n", mgr->pwr.supply_pwr_limit.thresh_crit_max); |
| 845 |
crit_thresh_passed = 1; |
| 846 |
|
| 847 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_PWR_SUPPLY_CRIT_MAX_ALARM; |
| 848 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_PWR_SUPPLY_WARN_MAX_ALARM; |
| 849 |
|
| 850 |
if (oc2gbts_power_get(OC2GBTS_POWER_PA)) { |
| 851 |
mgr->alarms.supply_pwr_max = 1; |
| 852 |
/* schedule to turn off PA */ |
| 853 |
action = SENSOR_ACT_PA_OFF; |
| 854 |
/* repeat same alarm to BSC */ |
| 855 |
handle_alert_actions(mgr); |
| 856 |
} |
| 857 |
/* add to pending list */ |
| 858 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_SHORT_DURATION); |
| 859 |
} |
| 860 |
LOGP(DTEMP, LOGL_INFO, "Main supply current power consumption is: %d\n", power); |
| 861 |
} |
| 862 |
} else { |
| 863 |
/* keep last state */ |
| 864 |
if (mgr->oc2gbts_ctrl.crit_flags & S_MGR_PWR_SUPPLY_CRIT_MAX_ALARM) { |
| 865 |
warn_thresh_passed = 1; |
| 866 |
crit_thresh_passed = 1; |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
if (oc2gbts_option_get(OC2GBTS_OPTION_PA)) { |
| 871 |
/* Read the current PA power consumption */ |
| 872 |
if (oc2gbts_power_get(OC2GBTS_POWER_PA)) { |
| 873 |
rc = oc2gbts_power_sensor_get(OC2GBTS_POWER_PA, OC2GBTS_POWER_POWER, &power); |
| 874 |
if (rc < 0) { |
| 875 |
LOGP(DTEMP, LOGL_NOTICE, |
| 876 |
"Failed to read the PA power. rc=%d\n", rc); |
| 877 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 878 |
} else { |
| 879 |
power /= 1000000; |
| 880 |
if (power > mgr->pwr.pa_pwr_limit.thresh_warn_max) { |
| 881 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because PA power consumption is over %d\n", mgr->pwr.pa_pwr_limit.thresh_warn_max); |
| 882 |
warn_thresh_passed = 1; |
| 883 |
mgr->alarms.pa_pwr_high = 1; |
| 884 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_PWR_PA_WARN_MAX_ALARM; |
| 885 |
} |
| 886 |
if (power > mgr->pwr.pa_pwr_limit.thresh_crit_max) { |
| 887 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because PA power consumption is over %d\n", mgr->pwr.pa_pwr_limit.thresh_crit_max); |
| 888 |
crit_thresh_passed = 1; |
| 889 |
mgr->alarms.pa_pwr_max = 1; |
| 890 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_PWR_PA_CRIT_MAX_ALARM; |
| 891 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_PWR_PA_WARN_MAX_ALARM; |
| 892 |
action = SENSOR_ACT_PA_OFF; |
| 893 |
/* add to pending list */ |
| 894 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_SHORT_DURATION); |
| 895 |
} |
| 896 |
LOGP(DTEMP, LOGL_INFO, "PA power consumption is: %d\n", power); |
| 897 |
} |
| 898 |
} else { |
| 899 |
/* keep last state */ |
| 900 |
if (mgr->oc2gbts_ctrl.crit_flags & S_MGR_PWR_PA_CRIT_MAX_ALARM) { |
| 901 |
warn_thresh_passed = 1; |
| 902 |
crit_thresh_passed = 1; |
| 903 |
} |
| 904 |
} |
| 905 |
} |
| 906 |
|
| 907 |
if (oc2gbts_option_get(OC2GBTS_OPTION_PA) && |
| 908 |
oc2gbts_option_get(OC2GBTS_OPTION_RMS_FWD) && |
| 909 |
oc2gbts_option_get(OC2GBTS_OPTION_RMS_REFL)) { |
| 910 |
/* Read the current VSWR of powered ON PA*/ |
| 911 |
if (oc2gbts_power_get(OC2GBTS_POWER_PA)) { |
| 912 |
rc = oc2gbts_vswr_get(OC2GBTS_VSWR, &vswr); |
| 913 |
if (rc < 0) { |
| 914 |
LOGP(DTEMP, LOGL_NOTICE, |
| 915 |
"Failed to read the VSWR. rc=%d\n", rc); |
| 916 |
warn_thresh_passed = crit_thresh_passed = 1; |
| 917 |
} else { |
| 918 |
if ((vswr > mgr->vswr.vswr_limit.thresh_warn_max) && (mgr->vswr.last_vswr > mgr->vswr.vswr_limit.thresh_warn_max)) { |
| 919 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached warning because VSWR is over %d\n", mgr->vswr.vswr_limit.thresh_warn_max); |
| 920 |
warn_thresh_passed = 1; |
| 921 |
mgr->alarms.vswr_high = 1; |
| 922 |
mgr->oc2gbts_ctrl.warn_flags |= S_MGR_VSWR_WARN_MAX_ALARM; |
| 923 |
} |
| 924 |
if ((vswr > mgr->vswr.vswr_limit.thresh_crit_max) && (mgr->vswr.last_vswr > mgr->vswr.vswr_limit.thresh_crit_max)) { |
| 925 |
LOGP(DTEMP, LOGL_NOTICE, "System has reached critical because VSWR is over %d\n", mgr->vswr.vswr_limit.thresh_crit_max); |
| 926 |
crit_thresh_passed = 1; |
| 927 |
mgr->alarms.vswr_max = 1; |
| 928 |
mgr->oc2gbts_ctrl.crit_flags |= S_MGR_VSWR_CRIT_MAX_ALARM; |
| 929 |
mgr->oc2gbts_ctrl.warn_flags &= ~S_MGR_VSWR_WARN_MAX_ALARM; |
| 930 |
action = SENSOR_ACT_PA_OFF; |
| 931 |
/* add to pending list */ |
| 932 |
schedule_preventive_action(mgr, action, OC2GBTS_PREVENT_TIMER_DURATION); |
| 933 |
} |
| 934 |
LOGP(DTEMP, LOGL_INFO, "VSWR is: current = %d, last = %d\n", vswr, mgr->vswr.last_vswr); |
| 935 |
|
| 936 |
/* update last VSWR */ |
| 937 |
mgr->vswr.last_vswr = vswr; |
| 938 |
} |
| 939 |
} else { |
| 940 |
/* keep last state */ |
| 941 |
if (mgr->oc2gbts_ctrl.crit_flags & S_MGR_VSWR_CRIT_MAX_ALARM) { |
| 942 |
warn_thresh_passed = 1; |
| 943 |
crit_thresh_passed = 1; |
| 944 |
} |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
select_led_pattern(mgr); |
| 949 |
oc2gbts_mgr_sensor_handle(mgr, crit_thresh_passed, warn_thresh_passed); |
| 950 |
} |
| 951 |
|
| 952 |
static void sensor_ctrl_check_cb(void *_data) |
| 953 |
{ |
| 954 |
struct oc2gbts_mgr_instance *mgr = _data; |
| 955 |
sensor_ctrl_check(mgr); |
| 956 |
/* Check every minute? XXX make it configurable! */ |
| 957 |
osmo_timer_schedule(&sensor_ctrl_timer, OC2GBTS_SENSOR_TIMER_DURATION, 0); |
| 958 |
LOGP(DTEMP, LOGL_DEBUG,"Check sensors timer expired\n"); |
| 959 |
/* TODO: do we want to notify if some sensors could not be read? */ |
| 960 |
oc2gbts_swd_event(mgr, SWD_CHECK_TEMP_SENSOR); |
| 961 |
} |
| 962 |
|
| 963 |
int oc2gbts_mgr_sensor_init(struct oc2gbts_mgr_instance *mgr) |
| 964 |
{ |
| 965 |
int rc = 0; |
| 966 |
|
| 967 |
/* always enable PA GPIO for OC-2G */ |
| 968 |
if (!oc2gbts_power_get(OC2GBTS_POWER_PA)) { |
| 969 |
rc = oc2gbts_power_set(OC2GBTS_POWER_PA, 1); |
| 970 |
if (!rc) |
| 971 |
LOGP(DTEMP, LOGL_ERROR, "Failed to set GPIO for internal PA\n"); |
| 972 |
} |
| 973 |
|
| 974 |
s_mgr = mgr; |
| 975 |
sensor_ctrl_timer.cb = sensor_ctrl_check_cb; |
| 976 |
sensor_ctrl_timer.data = s_mgr; |
| 977 |
sensor_ctrl_check_cb(s_mgr); |
| 978 |
return rc; |
| 979 |
} |
| 980 |
|