hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/char/ipmi/ipmi_ssif.c
....@@ -74,7 +74,8 @@
7474 /*
7575 * Timer values
7676 */
77
-#define SSIF_MSG_USEC 20000 /* 20ms between message tries. */
77
+#define SSIF_MSG_USEC 60000 /* 60ms between message tries (T3). */
78
+#define SSIF_REQ_RETRY_USEC 60000 /* 60ms between send retries (T6). */
7879 #define SSIF_MSG_PART_USEC 5000 /* 5ms for a message part */
7980
8081 /* How many times to we retry sending/receiving the message. */
....@@ -82,7 +83,9 @@
8283 #define SSIF_RECV_RETRIES 250
8384
8485 #define SSIF_MSG_MSEC (SSIF_MSG_USEC / 1000)
86
+#define SSIF_REQ_RETRY_MSEC (SSIF_REQ_RETRY_USEC / 1000)
8587 #define SSIF_MSG_JIFFIES ((SSIF_MSG_USEC * 1000) / TICK_NSEC)
88
+#define SSIF_REQ_RETRY_JIFFIES ((SSIF_REQ_RETRY_USEC * 1000) / TICK_NSEC)
8689 #define SSIF_MSG_PART_JIFFIES ((SSIF_MSG_PART_USEC * 1000) / TICK_NSEC)
8790
8891 /*
....@@ -92,7 +95,7 @@
9295 #define SSIF_WATCH_WATCHDOG_TIMEOUT msecs_to_jiffies(250)
9396
9497 enum ssif_intf_state {
95
- SSIF_NORMAL,
98
+ SSIF_IDLE,
9699 SSIF_GETTING_FLAGS,
97100 SSIF_GETTING_EVENTS,
98101 SSIF_CLEARING_FLAGS,
....@@ -100,8 +103,8 @@
100103 /* FIXME - add watchdog stuff. */
101104 };
102105
103
-#define SSIF_IDLE(ssif) ((ssif)->ssif_state == SSIF_NORMAL \
104
- && (ssif)->curr_msg == NULL)
106
+#define IS_SSIF_IDLE(ssif) ((ssif)->ssif_state == SSIF_IDLE \
107
+ && (ssif)->curr_msg == NULL)
105108
106109 /*
107110 * Indexes into stats[] in ssif_info below.
....@@ -229,6 +232,9 @@
229232 bool got_alert;
230233 bool waiting_alert;
231234
235
+ /* Used to inform the timeout that it should do a resend. */
236
+ bool do_resend;
237
+
232238 /*
233239 * If set to true, this will request events the next time the
234240 * state machine is idle.
....@@ -348,9 +354,9 @@
348354
349355 /*
350356 * Must be called with the message lock held. This will release the
351
- * message lock. Note that the caller will check SSIF_IDLE and start a
352
- * new operation, so there is no need to check for new messages to
353
- * start in here.
357
+ * message lock. Note that the caller will check IS_SSIF_IDLE and
358
+ * start a new operation, so there is no need to check for new
359
+ * messages to start in here.
354360 */
355361 static void start_clear_flags(struct ssif_info *ssif_info, unsigned long *flags)
356362 {
....@@ -367,7 +373,7 @@
367373
368374 if (start_send(ssif_info, msg, 3) != 0) {
369375 /* Error, just go to normal state. */
370
- ssif_info->ssif_state = SSIF_NORMAL;
376
+ ssif_info->ssif_state = SSIF_IDLE;
371377 }
372378 }
373379
....@@ -382,7 +388,7 @@
382388 mb[0] = (IPMI_NETFN_APP_REQUEST << 2);
383389 mb[1] = IPMI_GET_MSG_FLAGS_CMD;
384390 if (start_send(ssif_info, mb, 2) != 0)
385
- ssif_info->ssif_state = SSIF_NORMAL;
391
+ ssif_info->ssif_state = SSIF_IDLE;
386392 }
387393
388394 static void check_start_send(struct ssif_info *ssif_info, unsigned long *flags,
....@@ -393,7 +399,7 @@
393399
394400 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
395401 ssif_info->curr_msg = NULL;
396
- ssif_info->ssif_state = SSIF_NORMAL;
402
+ ssif_info->ssif_state = SSIF_IDLE;
397403 ipmi_ssif_unlock_cond(ssif_info, flags);
398404 ipmi_free_smi_msg(msg);
399405 }
....@@ -407,7 +413,7 @@
407413
408414 msg = ipmi_alloc_smi_msg();
409415 if (!msg) {
410
- ssif_info->ssif_state = SSIF_NORMAL;
416
+ ssif_info->ssif_state = SSIF_IDLE;
411417 ipmi_ssif_unlock_cond(ssif_info, flags);
412418 return;
413419 }
....@@ -430,7 +436,7 @@
430436
431437 msg = ipmi_alloc_smi_msg();
432438 if (!msg) {
433
- ssif_info->ssif_state = SSIF_NORMAL;
439
+ ssif_info->ssif_state = SSIF_IDLE;
434440 ipmi_ssif_unlock_cond(ssif_info, flags);
435441 return;
436442 }
....@@ -448,9 +454,9 @@
448454
449455 /*
450456 * Must be called with the message lock held. This will release the
451
- * message lock. Note that the caller will check SSIF_IDLE and start a
452
- * new operation, so there is no need to check for new messages to
453
- * start in here.
457
+ * message lock. Note that the caller will check IS_SSIF_IDLE and
458
+ * start a new operation, so there is no need to check for new
459
+ * messages to start in here.
454460 */
455461 static void handle_flags(struct ssif_info *ssif_info, unsigned long *flags)
456462 {
....@@ -466,7 +472,7 @@
466472 /* Events available. */
467473 start_event_fetch(ssif_info, flags);
468474 else {
469
- ssif_info->ssif_state = SSIF_NORMAL;
475
+ ssif_info->ssif_state = SSIF_IDLE;
470476 ipmi_ssif_unlock_cond(ssif_info, flags);
471477 }
472478 }
....@@ -510,7 +516,7 @@
510516 return 0;
511517 }
512518
513
-static int ssif_i2c_send(struct ssif_info *ssif_info,
519
+static void ssif_i2c_send(struct ssif_info *ssif_info,
514520 ssif_i2c_done handler,
515521 int read_write, int command,
516522 unsigned char *data, unsigned int size)
....@@ -522,7 +528,6 @@
522528 ssif_info->i2c_data = data;
523529 ssif_info->i2c_size = size;
524530 complete(&ssif_info->wake_thread);
525
- return 0;
526531 }
527532
528533
....@@ -531,40 +536,38 @@
531536
532537 static void start_get(struct ssif_info *ssif_info)
533538 {
534
- int rv;
535
-
536539 ssif_info->rtc_us_timer = 0;
537540 ssif_info->multi_pos = 0;
538541
539
- rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
540
- SSIF_IPMI_RESPONSE,
541
- ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
542
- if (rv < 0) {
543
- /* request failed, just return the error. */
544
- if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
545
- dev_dbg(&ssif_info->client->dev,
546
- "Error from i2c_non_blocking_op(5)\n");
547
-
548
- msg_done_handler(ssif_info, -EIO, NULL, 0);
549
- }
542
+ ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
543
+ SSIF_IPMI_RESPONSE,
544
+ ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
550545 }
546
+
547
+static void start_resend(struct ssif_info *ssif_info);
551548
552549 static void retry_timeout(struct timer_list *t)
553550 {
554551 struct ssif_info *ssif_info = from_timer(ssif_info, t, retry_timer);
555552 unsigned long oflags, *flags;
556
- bool waiting;
553
+ bool waiting, resend;
557554
558555 if (ssif_info->stopping)
559556 return;
560557
561558 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
559
+ resend = ssif_info->do_resend;
560
+ ssif_info->do_resend = false;
562561 waiting = ssif_info->waiting_alert;
563562 ssif_info->waiting_alert = false;
564563 ipmi_ssif_unlock_cond(ssif_info, flags);
565564
566565 if (waiting)
567566 start_get(ssif_info);
567
+ if (resend) {
568
+ start_resend(ssif_info);
569
+ ssif_inc_stat(ssif_info, send_retries);
570
+ }
568571 }
569572
570573 static void watch_timeout(struct timer_list *t)
....@@ -579,7 +582,7 @@
579582 if (ssif_info->watch_timeout) {
580583 mod_timer(&ssif_info->watch_timer,
581584 jiffies + ssif_info->watch_timeout);
582
- if (SSIF_IDLE(ssif_info)) {
585
+ if (IS_SSIF_IDLE(ssif_info)) {
583586 start_flag_fetch(ssif_info, flags); /* Releases lock */
584587 return;
585588 }
....@@ -613,14 +616,11 @@
613616 start_get(ssif_info);
614617 }
615618
616
-static int start_resend(struct ssif_info *ssif_info);
617
-
618619 static void msg_done_handler(struct ssif_info *ssif_info, int result,
619620 unsigned char *data, unsigned int len)
620621 {
621622 struct ipmi_smi_msg *msg;
622623 unsigned long oflags, *flags;
623
- int rv;
624624
625625 /*
626626 * We are single-threaded here, so no need for a lock until we
....@@ -666,17 +666,10 @@
666666 ssif_info->multi_len = len;
667667 ssif_info->multi_pos = 1;
668668
669
- rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
670
- SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE,
671
- ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
672
- if (rv < 0) {
673
- if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
674
- dev_dbg(&ssif_info->client->dev,
675
- "Error from i2c_non_blocking_op(1)\n");
676
-
677
- result = -EIO;
678
- } else
679
- return;
669
+ ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
670
+ SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE,
671
+ ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
672
+ return;
680673 } else if (ssif_info->multi_pos) {
681674 /* Middle of multi-part read. Start the next transaction. */
682675 int i;
....@@ -738,19 +731,12 @@
738731
739732 ssif_info->multi_pos++;
740733
741
- rv = ssif_i2c_send(ssif_info, msg_done_handler,
742
- I2C_SMBUS_READ,
743
- SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE,
744
- ssif_info->recv,
745
- I2C_SMBUS_BLOCK_DATA);
746
- if (rv < 0) {
747
- if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
748
- dev_dbg(&ssif_info->client->dev,
749
- "Error from ssif_i2c_send\n");
750
-
751
- result = -EIO;
752
- } else
753
- return;
734
+ ssif_i2c_send(ssif_info, msg_done_handler,
735
+ I2C_SMBUS_READ,
736
+ SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE,
737
+ ssif_info->recv,
738
+ I2C_SMBUS_BLOCK_DATA);
739
+ return;
754740 }
755741 }
756742
....@@ -782,7 +768,7 @@
782768 }
783769
784770 switch (ssif_info->ssif_state) {
785
- case SSIF_NORMAL:
771
+ case SSIF_IDLE:
786772 ipmi_ssif_unlock_cond(ssif_info, flags);
787773 if (!msg)
788774 break;
....@@ -800,7 +786,7 @@
800786 * Error fetching flags, or invalid length,
801787 * just give up for now.
802788 */
803
- ssif_info->ssif_state = SSIF_NORMAL;
789
+ ssif_info->ssif_state = SSIF_IDLE;
804790 ipmi_ssif_unlock_cond(ssif_info, flags);
805791 dev_warn(&ssif_info->client->dev,
806792 "Error getting flags: %d %d, %x\n",
....@@ -808,9 +794,9 @@
808794 } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
809795 || data[1] != IPMI_GET_MSG_FLAGS_CMD) {
810796 /*
811
- * Don't abort here, maybe it was a queued
812
- * response to a previous command.
797
+ * Recv error response, give up.
813798 */
799
+ ssif_info->ssif_state = SSIF_IDLE;
814800 ipmi_ssif_unlock_cond(ssif_info, flags);
815801 dev_warn(&ssif_info->client->dev,
816802 "Invalid response getting flags: %x %x\n",
....@@ -835,7 +821,7 @@
835821 "Invalid response clearing flags: %x %x\n",
836822 data[0], data[1]);
837823 }
838
- ssif_info->ssif_state = SSIF_NORMAL;
824
+ ssif_info->ssif_state = SSIF_IDLE;
839825 ipmi_ssif_unlock_cond(ssif_info, flags);
840826 break;
841827
....@@ -913,7 +899,7 @@
913899 }
914900
915901 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
916
- if (SSIF_IDLE(ssif_info) && !ssif_info->stopping) {
902
+ if (IS_SSIF_IDLE(ssif_info) && !ssif_info->stopping) {
917903 if (ssif_info->req_events)
918904 start_event_fetch(ssif_info, flags);
919905 else if (ssif_info->req_flags)
....@@ -931,37 +917,27 @@
931917 static void msg_written_handler(struct ssif_info *ssif_info, int result,
932918 unsigned char *data, unsigned int len)
933919 {
934
- int rv;
935
-
936920 /* We are single-threaded here, so no need for a lock. */
937921 if (result < 0) {
938922 ssif_info->retries_left--;
939923 if (ssif_info->retries_left > 0) {
940
- if (!start_resend(ssif_info)) {
941
- ssif_inc_stat(ssif_info, send_retries);
942
- return;
943
- }
944
- /* request failed, just return the error. */
945
- ssif_inc_stat(ssif_info, send_errors);
946
-
947
- if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
948
- dev_dbg(&ssif_info->client->dev,
949
- "%s: Out of retries\n", __func__);
950
- msg_done_handler(ssif_info, -EIO, NULL, 0);
924
+ /*
925
+ * Wait the retry timeout time per the spec,
926
+ * then redo the send.
927
+ */
928
+ ssif_info->do_resend = true;
929
+ mod_timer(&ssif_info->retry_timer,
930
+ jiffies + SSIF_REQ_RETRY_JIFFIES);
951931 return;
952932 }
953933
954934 ssif_inc_stat(ssif_info, send_errors);
955935
956
- /*
957
- * Got an error on transmit, let the done routine
958
- * handle it.
959
- */
960936 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
961937 dev_dbg(&ssif_info->client->dev,
962
- "%s: Error %d\n", __func__, result);
938
+ "%s: Out of retries\n", __func__);
963939
964
- msg_done_handler(ssif_info, result, NULL, 0);
940
+ msg_done_handler(ssif_info, -EIO, NULL, 0);
965941 return;
966942 }
967943
....@@ -995,18 +971,9 @@
995971 ssif_info->multi_data = NULL;
996972 }
997973
998
- rv = ssif_i2c_send(ssif_info, msg_written_handler,
999
- I2C_SMBUS_WRITE, cmd,
1000
- data_to_send, I2C_SMBUS_BLOCK_DATA);
1001
- if (rv < 0) {
1002
- /* request failed, just return the error. */
1003
- ssif_inc_stat(ssif_info, send_errors);
1004
-
1005
- if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
1006
- dev_dbg(&ssif_info->client->dev,
1007
- "Error from i2c_non_blocking_op(3)\n");
1008
- msg_done_handler(ssif_info, -EIO, NULL, 0);
1009
- }
974
+ ssif_i2c_send(ssif_info, msg_written_handler,
975
+ I2C_SMBUS_WRITE, cmd,
976
+ data_to_send, I2C_SMBUS_BLOCK_DATA);
1010977 } else {
1011978 /* Ready to request the result. */
1012979 unsigned long oflags, *flags;
....@@ -1033,9 +1000,8 @@
10331000 }
10341001 }
10351002
1036
-static int start_resend(struct ssif_info *ssif_info)
1003
+static void start_resend(struct ssif_info *ssif_info)
10371004 {
1038
- int rv;
10391005 int command;
10401006
10411007 ssif_info->got_alert = false;
....@@ -1057,12 +1023,8 @@
10571023 ssif_info->data[0] = ssif_info->data_len;
10581024 }
10591025
1060
- rv = ssif_i2c_send(ssif_info, msg_written_handler, I2C_SMBUS_WRITE,
1061
- command, ssif_info->data, I2C_SMBUS_BLOCK_DATA);
1062
- if (rv && (ssif_info->ssif_debug & SSIF_DEBUG_MSG))
1063
- dev_dbg(&ssif_info->client->dev,
1064
- "Error from i2c_non_blocking_op(4)\n");
1065
- return rv;
1026
+ ssif_i2c_send(ssif_info, msg_written_handler, I2C_SMBUS_WRITE,
1027
+ command, ssif_info->data, I2C_SMBUS_BLOCK_DATA);
10661028 }
10671029
10681030 static int start_send(struct ssif_info *ssif_info,
....@@ -1077,7 +1039,8 @@
10771039 ssif_info->retries_left = SSIF_SEND_RETRIES;
10781040 memcpy(ssif_info->data + 1, data, len);
10791041 ssif_info->data_len = len;
1080
- return start_resend(ssif_info);
1042
+ start_resend(ssif_info);
1043
+ return 0;
10811044 }
10821045
10831046 /* Must be called with the message lock held. */
....@@ -1087,7 +1050,7 @@
10871050 unsigned long oflags;
10881051
10891052 restart:
1090
- if (!SSIF_IDLE(ssif_info)) {
1053
+ if (!IS_SSIF_IDLE(ssif_info)) {
10911054 ipmi_ssif_unlock_cond(ssif_info, flags);
10921055 return;
10931056 }
....@@ -1310,7 +1273,7 @@
13101273 dev_set_drvdata(&ssif_info->client->dev, NULL);
13111274
13121275 /* make sure the driver is not looking for flags any more. */
1313
- while (ssif_info->ssif_state != SSIF_NORMAL)
1276
+ while (ssif_info->ssif_state != SSIF_IDLE)
13141277 schedule_timeout(1);
13151278
13161279 ssif_info->stopping = true;
....@@ -1377,8 +1340,10 @@
13771340 ret = i2c_smbus_write_block_data(client, SSIF_IPMI_REQUEST, len, msg);
13781341 if (ret) {
13791342 retry_cnt--;
1380
- if (retry_cnt > 0)
1343
+ if (retry_cnt > 0) {
1344
+ msleep(SSIF_REQ_RETRY_MSEC);
13811345 goto retry1;
1346
+ }
13821347 return -ENODEV;
13831348 }
13841349
....@@ -1449,7 +1414,7 @@
14491414 restart:
14501415 list_for_each_entry(info, &ssif_infos, link) {
14511416 if (info->binfo.addr == addr) {
1452
- if (info->addr_src == SI_SMBIOS)
1417
+ if (info->addr_src == SI_SMBIOS && !info->adapter_name)
14531418 info->adapter_name = kstrdup(adapter_name,
14541419 GFP_KERNEL);
14551420
....@@ -1519,8 +1484,10 @@
15191484 32, msg);
15201485 if (ret) {
15211486 retry_cnt--;
1522
- if (retry_cnt > 0)
1487
+ if (retry_cnt > 0) {
1488
+ msleep(SSIF_REQ_RETRY_MSEC);
15231489 goto retry_write;
1490
+ }
15241491 dev_err(&client->dev, "Could not write multi-part start, though the BMC said it could handle it. Just limit sends to one part.\n");
15251492 return ret;
15261493 }
....@@ -1647,6 +1614,11 @@
16471614 info->addr_src = SI_ACPI;
16481615 info->client = client;
16491616 info->adapter_name = kstrdup(client->adapter->name, GFP_KERNEL);
1617
+ if (!info->adapter_name) {
1618
+ kfree(info);
1619
+ return -ENOMEM;
1620
+ }
1621
+
16501622 info->binfo.addr = client->addr;
16511623 list_add_tail(&info->link, &ssif_infos);
16521624 return 0;
....@@ -1882,7 +1854,7 @@
18821854 }
18831855
18841856 spin_lock_init(&ssif_info->lock);
1885
- ssif_info->ssif_state = SSIF_NORMAL;
1857
+ ssif_info->ssif_state = SSIF_IDLE;
18861858 timer_setup(&ssif_info->retry_timer, retry_timeout, 0);
18871859 timer_setup(&ssif_info->watch_timer, watch_timeout, 0);
18881860