forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/drivers/char/ipmi/ipmi_watchdog.c
....@@ -11,6 +11,8 @@
1111 * Copyright 2002 MontaVista Software Inc.
1212 */
1313
14
+#define pr_fmt(fmt) "IPMI Watchdog: " fmt
15
+
1416 #include <linux/module.h>
1517 #include <linux/moduleparam.h>
1618 #include <linux/ipmi.h>
....@@ -49,8 +51,6 @@
4951 #include <asm/nmi.h>
5052 #define HAVE_DIE_NMI
5153 #endif
52
-
53
-#define PFX "IPMI Watchdog: "
5454
5555 /*
5656 * The IPMI command/response information for the watchdog timer.
....@@ -232,12 +232,17 @@
232232 static int get_param_str(char *buffer, const struct kernel_param *kp)
233233 {
234234 action_fn fn = (action_fn) kp->arg;
235
- int rv;
235
+ int rv, len;
236236
237237 rv = fn(NULL, buffer);
238238 if (rv)
239239 return rv;
240
- return strlen(buffer);
240
+
241
+ len = strlen(buffer);
242
+ buffer[len++] = '\n';
243
+ buffer[len] = 0;
244
+
245
+ return len;
241246 }
242247
243248
....@@ -337,13 +342,17 @@
337342 static DECLARE_COMPLETION(msg_wait);
338343 static void msg_free_smi(struct ipmi_smi_msg *msg)
339344 {
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
+ }
342349 }
343350 static void msg_free_recv(struct ipmi_recv_msg *msg)
344351 {
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
+ }
347356 }
348357 static struct ipmi_smi_msg smi_msg = {
349358 .done = msg_free_smi
....@@ -409,7 +418,7 @@
409418 recv_msg,
410419 1);
411420 if (rv)
412
- pr_warn(PFX "set timeout error: %d\n", rv);
421
+ pr_warn("set timeout error: %d\n", rv);
413422 else if (send_heartbeat_now)
414423 *send_heartbeat_now = hbnow;
415424
....@@ -429,8 +438,10 @@
429438 rv = __ipmi_set_timeout(&smi_msg,
430439 &recv_msg,
431440 &send_heartbeat_now);
432
- if (rv)
441
+ if (rv) {
442
+ atomic_set(&msg_tofree, 0);
433443 return rv;
444
+ }
434445
435446 wait_for_completion(&msg_wait);
436447
....@@ -532,7 +543,7 @@
532543 &send_heartbeat_now);
533544 if (rv) {
534545 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");
536547 } else {
537548 if (send_heartbeat_now)
538549 panic_halt_ipmi_heartbeat();
....@@ -575,7 +586,8 @@
575586 &recv_msg,
576587 1);
577588 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);
579591 return rv;
580592 }
581593
....@@ -585,7 +597,7 @@
585597 if (recv_msg.msg.data[0] == IPMI_WDOG_TIMER_NOT_INIT_RESP) {
586598 timeout_retries++;
587599 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");
589601 rv = -EIO;
590602 goto out;
591603 }
....@@ -600,7 +612,7 @@
600612 */
601613 rv = _ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);
602614 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");
604616 goto out;
605617 }
606618
....@@ -839,7 +851,7 @@
839851 * first heartbeat.
840852 */
841853 ipmi_start_timer_on_heartbeat = 1;
842
- return nonseekable_open(ino, filep);
854
+ return stream_open(ino, filep);
843855
844856 default:
845857 return (-ENODEV);
....@@ -878,8 +890,7 @@
878890 _ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);
879891 mutex_unlock(&ipmi_watchdog_mutex);
880892 } else {
881
- pr_crit(PFX
882
- "Unexpected close, not stopping watchdog!\n");
893
+ pr_crit("Unexpected close, not stopping watchdog!\n");
883894 ipmi_heartbeat();
884895 }
885896 clear_bit(0, &ipmi_wdog_open);
....@@ -896,6 +907,7 @@
896907 .poll = ipmi_poll,
897908 .write = ipmi_write,
898909 .unlocked_ioctl = ipmi_unlocked_ioctl,
910
+ .compat_ioctl = compat_ptr_ioctl,
899911 .open = ipmi_open,
900912 .release = ipmi_close,
901913 .fasync = ipmi_fasync,
....@@ -913,9 +925,9 @@
913925 {
914926 if (msg->msg.cmd == IPMI_WDOG_RESET_TIMER &&
915927 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");
917929 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",
919931 msg->msg.data[0],
920932 msg->msg.cmd);
921933
....@@ -987,7 +999,7 @@
987999
9881000 rv = ipmi_create_user(ipmi_intf, &ipmi_hndlrs, NULL, &watchdog_user);
9891001 if (rv < 0) {
990
- pr_crit(PFX "Unable to register with ipmi\n");
1002
+ pr_crit("Unable to register with ipmi\n");
9911003 goto out;
9921004 }
9931005
....@@ -995,7 +1007,7 @@
9951007 &ipmi_version_major,
9961008 &ipmi_version_minor);
9971009 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");
9991011 ipmi_version_major = 1;
10001012 ipmi_version_minor = 0;
10011013 }
....@@ -1004,7 +1016,7 @@
10041016 if (rv < 0) {
10051017 ipmi_destroy_user(watchdog_user);
10061018 watchdog_user = NULL;
1007
- pr_crit(PFX "Unable to register misc device\n");
1019
+ pr_crit("Unable to register misc device\n");
10081020 }
10091021
10101022 #ifdef HAVE_DIE_NMI
....@@ -1026,7 +1038,7 @@
10261038
10271039 rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_FORCE_HB);
10281040 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",
10301042 rv);
10311043 rv = 0;
10321044 goto out_restore;
....@@ -1035,7 +1047,7 @@
10351047 msleep(1500);
10361048
10371049 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");
10391051 }
10401052 out_restore:
10411053 testing_nmi = 0;
....@@ -1051,7 +1063,7 @@
10511063 start_now = 0; /* Disable this function after first startup. */
10521064 ipmi_watchdog_state = action_val;
10531065 ipmi_set_timeout(IPMI_SET_TIMEOUT_FORCE_HB);
1054
- pr_info(PFX "Starting now!\n");
1066
+ pr_info("Starting now!\n");
10551067 } else {
10561068 /* Stop the timer now. */
10571069 ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
....@@ -1088,7 +1100,7 @@
10881100 /* Disconnect from IPMI. */
10891101 rv = ipmi_destroy_user(loc_user);
10901102 if (rv)
1091
- pr_warn(PFX "error unlinking from IPMI: %d\n", rv);
1103
+ pr_warn("error unlinking from IPMI: %d\n", rv);
10921104
10931105 /* If it comes back, restart it properly. */
10941106 ipmi_start_timer_on_heartbeat = 1;
....@@ -1129,7 +1141,7 @@
11291141 the timer. So do so. */
11301142 atomic_set(&pretimeout_since_last_heartbeat, 1);
11311143 if (atomic_inc_and_test(&preop_panic_excl))
1132
- nmi_panic(regs, PFX "pre-timeout");
1144
+ nmi_panic(regs, "pre-timeout");
11331145 }
11341146
11351147 return NMI_HANDLED;
....@@ -1261,7 +1273,7 @@
12611273 if (preaction_val == WDOG_PRETIMEOUT_NMI) {
12621274 do_nmi = 1;
12631275 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");
12651277 preop_op("preop_none", NULL);
12661278 do_nmi = 0;
12671279 }
....@@ -1270,7 +1282,7 @@
12701282 rv = register_nmi_handler(NMI_UNKNOWN, ipmi_nmi, 0,
12711283 "ipmi");
12721284 if (rv) {
1273
- pr_warn(PFX "Can't register nmi handler\n");
1285
+ pr_warn("Can't register nmi handler\n");
12741286 return;
12751287 } else
12761288 nmi_handler_registered = 1;
....@@ -1287,19 +1299,18 @@
12871299
12881300 if (action_op(action, NULL)) {
12891301 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);
12921303 }
12931304
12941305 if (preaction_op(preaction, NULL)) {
12951306 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",
12971308 preaction);
12981309 }
12991310
13001311 if (preop_op(preop, NULL)) {
13011312 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);
13031314 }
13041315
13051316 check_parms();
....@@ -1313,11 +1324,11 @@
13131324 unregister_nmi_handler(NMI_UNKNOWN, "ipmi");
13141325 #endif
13151326 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");
13171328 return rv;
13181329 }
13191330
1320
- pr_info(PFX "driver initialized\n");
1331
+ pr_info("driver initialized\n");
13211332
13221333 return 0;
13231334 }