| .. | .. |
|---|
| 11 | 11 | * Copyright 2002 MontaVista Software Inc. |
|---|
| 12 | 12 | */ |
|---|
| 13 | 13 | |
|---|
| 14 | +#define pr_fmt(fmt) "IPMI Watchdog: " fmt |
|---|
| 15 | + |
|---|
| 14 | 16 | #include <linux/module.h> |
|---|
| 15 | 17 | #include <linux/moduleparam.h> |
|---|
| 16 | 18 | #include <linux/ipmi.h> |
|---|
| .. | .. |
|---|
| 49 | 51 | #include <asm/nmi.h> |
|---|
| 50 | 52 | #define HAVE_DIE_NMI |
|---|
| 51 | 53 | #endif |
|---|
| 52 | | - |
|---|
| 53 | | -#define PFX "IPMI Watchdog: " |
|---|
| 54 | 54 | |
|---|
| 55 | 55 | /* |
|---|
| 56 | 56 | * The IPMI command/response information for the watchdog timer. |
|---|
| .. | .. |
|---|
| 232 | 232 | static int get_param_str(char *buffer, const struct kernel_param *kp) |
|---|
| 233 | 233 | { |
|---|
| 234 | 234 | action_fn fn = (action_fn) kp->arg; |
|---|
| 235 | | - int rv; |
|---|
| 235 | + int rv, len; |
|---|
| 236 | 236 | |
|---|
| 237 | 237 | rv = fn(NULL, buffer); |
|---|
| 238 | 238 | if (rv) |
|---|
| 239 | 239 | return rv; |
|---|
| 240 | | - return strlen(buffer); |
|---|
| 240 | + |
|---|
| 241 | + len = strlen(buffer); |
|---|
| 242 | + buffer[len++] = '\n'; |
|---|
| 243 | + buffer[len] = 0; |
|---|
| 244 | + |
|---|
| 245 | + return len; |
|---|
| 241 | 246 | } |
|---|
| 242 | 247 | |
|---|
| 243 | 248 | |
|---|
| .. | .. |
|---|
| 337 | 342 | static DECLARE_COMPLETION(msg_wait); |
|---|
| 338 | 343 | static void msg_free_smi(struct ipmi_smi_msg *msg) |
|---|
| 339 | 344 | { |
|---|
| 340 | | - if (atomic_dec_and_test(&msg_tofree)) |
|---|
| 341 | | - complete(&msg_wait); |
|---|
| 345 | + if (atomic_dec_and_test(&msg_tofree)) { |
|---|
| 346 | + if (!oops_in_progress) |
|---|
| 347 | + complete(&msg_wait); |
|---|
| 348 | + } |
|---|
| 342 | 349 | } |
|---|
| 343 | 350 | static void msg_free_recv(struct ipmi_recv_msg *msg) |
|---|
| 344 | 351 | { |
|---|
| 345 | | - if (atomic_dec_and_test(&msg_tofree)) |
|---|
| 346 | | - complete(&msg_wait); |
|---|
| 352 | + if (atomic_dec_and_test(&msg_tofree)) { |
|---|
| 353 | + if (!oops_in_progress) |
|---|
| 354 | + complete(&msg_wait); |
|---|
| 355 | + } |
|---|
| 347 | 356 | } |
|---|
| 348 | 357 | static struct ipmi_smi_msg smi_msg = { |
|---|
| 349 | 358 | .done = msg_free_smi |
|---|
| .. | .. |
|---|
| 409 | 418 | recv_msg, |
|---|
| 410 | 419 | 1); |
|---|
| 411 | 420 | if (rv) |
|---|
| 412 | | - pr_warn(PFX "set timeout error: %d\n", rv); |
|---|
| 421 | + pr_warn("set timeout error: %d\n", rv); |
|---|
| 413 | 422 | else if (send_heartbeat_now) |
|---|
| 414 | 423 | *send_heartbeat_now = hbnow; |
|---|
| 415 | 424 | |
|---|
| .. | .. |
|---|
| 429 | 438 | rv = __ipmi_set_timeout(&smi_msg, |
|---|
| 430 | 439 | &recv_msg, |
|---|
| 431 | 440 | &send_heartbeat_now); |
|---|
| 432 | | - if (rv) |
|---|
| 441 | + if (rv) { |
|---|
| 442 | + atomic_set(&msg_tofree, 0); |
|---|
| 433 | 443 | return rv; |
|---|
| 444 | + } |
|---|
| 434 | 445 | |
|---|
| 435 | 446 | wait_for_completion(&msg_wait); |
|---|
| 436 | 447 | |
|---|
| .. | .. |
|---|
| 532 | 543 | &send_heartbeat_now); |
|---|
| 533 | 544 | if (rv) { |
|---|
| 534 | 545 | atomic_sub(1, &panic_done_count); |
|---|
| 535 | | - pr_warn(PFX "Unable to extend the watchdog timeout."); |
|---|
| 546 | + pr_warn("Unable to extend the watchdog timeout\n"); |
|---|
| 536 | 547 | } else { |
|---|
| 537 | 548 | if (send_heartbeat_now) |
|---|
| 538 | 549 | panic_halt_ipmi_heartbeat(); |
|---|
| .. | .. |
|---|
| 575 | 586 | &recv_msg, |
|---|
| 576 | 587 | 1); |
|---|
| 577 | 588 | if (rv) { |
|---|
| 578 | | - pr_warn(PFX "heartbeat send failure: %d\n", rv); |
|---|
| 589 | + atomic_set(&msg_tofree, 0); |
|---|
| 590 | + pr_warn("heartbeat send failure: %d\n", rv); |
|---|
| 579 | 591 | return rv; |
|---|
| 580 | 592 | } |
|---|
| 581 | 593 | |
|---|
| .. | .. |
|---|
| 585 | 597 | if (recv_msg.msg.data[0] == IPMI_WDOG_TIMER_NOT_INIT_RESP) { |
|---|
| 586 | 598 | timeout_retries++; |
|---|
| 587 | 599 | if (timeout_retries > 3) { |
|---|
| 588 | | - pr_err(PFX ": Unable to restore the IPMI watchdog's settings, giving up.\n"); |
|---|
| 600 | + pr_err("Unable to restore the IPMI watchdog's settings, giving up\n"); |
|---|
| 589 | 601 | rv = -EIO; |
|---|
| 590 | 602 | goto out; |
|---|
| 591 | 603 | } |
|---|
| .. | .. |
|---|
| 600 | 612 | */ |
|---|
| 601 | 613 | rv = _ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB); |
|---|
| 602 | 614 | if (rv) { |
|---|
| 603 | | - pr_err(PFX ": Unable to send the command to set the watchdog's settings, giving up.\n"); |
|---|
| 615 | + pr_err("Unable to send the command to set the watchdog's settings, giving up\n"); |
|---|
| 604 | 616 | goto out; |
|---|
| 605 | 617 | } |
|---|
| 606 | 618 | |
|---|
| .. | .. |
|---|
| 839 | 851 | * first heartbeat. |
|---|
| 840 | 852 | */ |
|---|
| 841 | 853 | ipmi_start_timer_on_heartbeat = 1; |
|---|
| 842 | | - return nonseekable_open(ino, filep); |
|---|
| 854 | + return stream_open(ino, filep); |
|---|
| 843 | 855 | |
|---|
| 844 | 856 | default: |
|---|
| 845 | 857 | return (-ENODEV); |
|---|
| .. | .. |
|---|
| 878 | 890 | _ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB); |
|---|
| 879 | 891 | mutex_unlock(&ipmi_watchdog_mutex); |
|---|
| 880 | 892 | } else { |
|---|
| 881 | | - pr_crit(PFX |
|---|
| 882 | | - "Unexpected close, not stopping watchdog!\n"); |
|---|
| 893 | + pr_crit("Unexpected close, not stopping watchdog!\n"); |
|---|
| 883 | 894 | ipmi_heartbeat(); |
|---|
| 884 | 895 | } |
|---|
| 885 | 896 | clear_bit(0, &ipmi_wdog_open); |
|---|
| .. | .. |
|---|
| 896 | 907 | .poll = ipmi_poll, |
|---|
| 897 | 908 | .write = ipmi_write, |
|---|
| 898 | 909 | .unlocked_ioctl = ipmi_unlocked_ioctl, |
|---|
| 910 | + .compat_ioctl = compat_ptr_ioctl, |
|---|
| 899 | 911 | .open = ipmi_open, |
|---|
| 900 | 912 | .release = ipmi_close, |
|---|
| 901 | 913 | .fasync = ipmi_fasync, |
|---|
| .. | .. |
|---|
| 913 | 925 | { |
|---|
| 914 | 926 | if (msg->msg.cmd == IPMI_WDOG_RESET_TIMER && |
|---|
| 915 | 927 | msg->msg.data[0] == IPMI_WDOG_TIMER_NOT_INIT_RESP) |
|---|
| 916 | | - pr_info(PFX "response: The IPMI controller appears to have been reset, will attempt to reinitialize the watchdog timer\n"); |
|---|
| 928 | + pr_info("response: The IPMI controller appears to have been reset, will attempt to reinitialize the watchdog timer\n"); |
|---|
| 917 | 929 | else if (msg->msg.data[0] != 0) |
|---|
| 918 | | - pr_err(PFX "response: Error %x on cmd %x\n", |
|---|
| 930 | + pr_err("response: Error %x on cmd %x\n", |
|---|
| 919 | 931 | msg->msg.data[0], |
|---|
| 920 | 932 | msg->msg.cmd); |
|---|
| 921 | 933 | |
|---|
| .. | .. |
|---|
| 987 | 999 | |
|---|
| 988 | 1000 | rv = ipmi_create_user(ipmi_intf, &ipmi_hndlrs, NULL, &watchdog_user); |
|---|
| 989 | 1001 | if (rv < 0) { |
|---|
| 990 | | - pr_crit(PFX "Unable to register with ipmi\n"); |
|---|
| 1002 | + pr_crit("Unable to register with ipmi\n"); |
|---|
| 991 | 1003 | goto out; |
|---|
| 992 | 1004 | } |
|---|
| 993 | 1005 | |
|---|
| .. | .. |
|---|
| 995 | 1007 | &ipmi_version_major, |
|---|
| 996 | 1008 | &ipmi_version_minor); |
|---|
| 997 | 1009 | if (rv) { |
|---|
| 998 | | - pr_warn(PFX "Unable to get IPMI version, assuming 1.0\n"); |
|---|
| 1010 | + pr_warn("Unable to get IPMI version, assuming 1.0\n"); |
|---|
| 999 | 1011 | ipmi_version_major = 1; |
|---|
| 1000 | 1012 | ipmi_version_minor = 0; |
|---|
| 1001 | 1013 | } |
|---|
| .. | .. |
|---|
| 1004 | 1016 | if (rv < 0) { |
|---|
| 1005 | 1017 | ipmi_destroy_user(watchdog_user); |
|---|
| 1006 | 1018 | watchdog_user = NULL; |
|---|
| 1007 | | - pr_crit(PFX "Unable to register misc device\n"); |
|---|
| 1019 | + pr_crit("Unable to register misc device\n"); |
|---|
| 1008 | 1020 | } |
|---|
| 1009 | 1021 | |
|---|
| 1010 | 1022 | #ifdef HAVE_DIE_NMI |
|---|
| .. | .. |
|---|
| 1026 | 1038 | |
|---|
| 1027 | 1039 | rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_FORCE_HB); |
|---|
| 1028 | 1040 | if (rv) { |
|---|
| 1029 | | - pr_warn(PFX "Error starting timer to test NMI: 0x%x. The NMI pretimeout will likely not work\n", |
|---|
| 1041 | + pr_warn("Error starting timer to test NMI: 0x%x. The NMI pretimeout will likely not work\n", |
|---|
| 1030 | 1042 | rv); |
|---|
| 1031 | 1043 | rv = 0; |
|---|
| 1032 | 1044 | goto out_restore; |
|---|
| .. | .. |
|---|
| 1035 | 1047 | msleep(1500); |
|---|
| 1036 | 1048 | |
|---|
| 1037 | 1049 | if (testing_nmi != 2) { |
|---|
| 1038 | | - pr_warn(PFX "IPMI NMI didn't seem to occur. The NMI pretimeout will likely not work\n"); |
|---|
| 1050 | + pr_warn("IPMI NMI didn't seem to occur. The NMI pretimeout will likely not work\n"); |
|---|
| 1039 | 1051 | } |
|---|
| 1040 | 1052 | out_restore: |
|---|
| 1041 | 1053 | testing_nmi = 0; |
|---|
| .. | .. |
|---|
| 1051 | 1063 | start_now = 0; /* Disable this function after first startup. */ |
|---|
| 1052 | 1064 | ipmi_watchdog_state = action_val; |
|---|
| 1053 | 1065 | ipmi_set_timeout(IPMI_SET_TIMEOUT_FORCE_HB); |
|---|
| 1054 | | - pr_info(PFX "Starting now!\n"); |
|---|
| 1066 | + pr_info("Starting now!\n"); |
|---|
| 1055 | 1067 | } else { |
|---|
| 1056 | 1068 | /* Stop the timer now. */ |
|---|
| 1057 | 1069 | ipmi_watchdog_state = WDOG_TIMEOUT_NONE; |
|---|
| .. | .. |
|---|
| 1088 | 1100 | /* Disconnect from IPMI. */ |
|---|
| 1089 | 1101 | rv = ipmi_destroy_user(loc_user); |
|---|
| 1090 | 1102 | if (rv) |
|---|
| 1091 | | - pr_warn(PFX "error unlinking from IPMI: %d\n", rv); |
|---|
| 1103 | + pr_warn("error unlinking from IPMI: %d\n", rv); |
|---|
| 1092 | 1104 | |
|---|
| 1093 | 1105 | /* If it comes back, restart it properly. */ |
|---|
| 1094 | 1106 | ipmi_start_timer_on_heartbeat = 1; |
|---|
| .. | .. |
|---|
| 1129 | 1141 | the timer. So do so. */ |
|---|
| 1130 | 1142 | atomic_set(&pretimeout_since_last_heartbeat, 1); |
|---|
| 1131 | 1143 | if (atomic_inc_and_test(&preop_panic_excl)) |
|---|
| 1132 | | - nmi_panic(regs, PFX "pre-timeout"); |
|---|
| 1144 | + nmi_panic(regs, "pre-timeout"); |
|---|
| 1133 | 1145 | } |
|---|
| 1134 | 1146 | |
|---|
| 1135 | 1147 | return NMI_HANDLED; |
|---|
| .. | .. |
|---|
| 1261 | 1273 | if (preaction_val == WDOG_PRETIMEOUT_NMI) { |
|---|
| 1262 | 1274 | do_nmi = 1; |
|---|
| 1263 | 1275 | if (preop_val == WDOG_PREOP_GIVE_DATA) { |
|---|
| 1264 | | - pr_warn(PFX "Pretimeout op is to give data but NMI pretimeout is enabled, setting pretimeout op to none\n"); |
|---|
| 1276 | + pr_warn("Pretimeout op is to give data but NMI pretimeout is enabled, setting pretimeout op to none\n"); |
|---|
| 1265 | 1277 | preop_op("preop_none", NULL); |
|---|
| 1266 | 1278 | do_nmi = 0; |
|---|
| 1267 | 1279 | } |
|---|
| .. | .. |
|---|
| 1270 | 1282 | rv = register_nmi_handler(NMI_UNKNOWN, ipmi_nmi, 0, |
|---|
| 1271 | 1283 | "ipmi"); |
|---|
| 1272 | 1284 | if (rv) { |
|---|
| 1273 | | - pr_warn(PFX "Can't register nmi handler\n"); |
|---|
| 1285 | + pr_warn("Can't register nmi handler\n"); |
|---|
| 1274 | 1286 | return; |
|---|
| 1275 | 1287 | } else |
|---|
| 1276 | 1288 | nmi_handler_registered = 1; |
|---|
| .. | .. |
|---|
| 1287 | 1299 | |
|---|
| 1288 | 1300 | if (action_op(action, NULL)) { |
|---|
| 1289 | 1301 | action_op("reset", NULL); |
|---|
| 1290 | | - pr_info(PFX "Unknown action '%s', defaulting to reset\n", |
|---|
| 1291 | | - action); |
|---|
| 1302 | + pr_info("Unknown action '%s', defaulting to reset\n", action); |
|---|
| 1292 | 1303 | } |
|---|
| 1293 | 1304 | |
|---|
| 1294 | 1305 | if (preaction_op(preaction, NULL)) { |
|---|
| 1295 | 1306 | preaction_op("pre_none", NULL); |
|---|
| 1296 | | - pr_info(PFX "Unknown preaction '%s', defaulting to none\n", |
|---|
| 1307 | + pr_info("Unknown preaction '%s', defaulting to none\n", |
|---|
| 1297 | 1308 | preaction); |
|---|
| 1298 | 1309 | } |
|---|
| 1299 | 1310 | |
|---|
| 1300 | 1311 | if (preop_op(preop, NULL)) { |
|---|
| 1301 | 1312 | preop_op("preop_none", NULL); |
|---|
| 1302 | | - pr_info(PFX "Unknown preop '%s', defaulting to none\n", preop); |
|---|
| 1313 | + pr_info("Unknown preop '%s', defaulting to none\n", preop); |
|---|
| 1303 | 1314 | } |
|---|
| 1304 | 1315 | |
|---|
| 1305 | 1316 | check_parms(); |
|---|
| .. | .. |
|---|
| 1313 | 1324 | unregister_nmi_handler(NMI_UNKNOWN, "ipmi"); |
|---|
| 1314 | 1325 | #endif |
|---|
| 1315 | 1326 | unregister_reboot_notifier(&wdog_reboot_notifier); |
|---|
| 1316 | | - pr_warn(PFX "can't register smi watcher\n"); |
|---|
| 1327 | + pr_warn("can't register smi watcher\n"); |
|---|
| 1317 | 1328 | return rv; |
|---|
| 1318 | 1329 | } |
|---|
| 1319 | 1330 | |
|---|
| 1320 | | - pr_info(PFX "driver initialized\n"); |
|---|
| 1331 | + pr_info("driver initialized\n"); |
|---|
| 1321 | 1332 | |
|---|
| 1322 | 1333 | return 0; |
|---|
| 1323 | 1334 | } |
|---|