forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/char/ipmi/ipmi_ssif.c
....@@ -22,10 +22,8 @@
2222 * and drives the real SSIF state machine.
2323 */
2424
25
-/*
26
- * TODO: Figure out how to use SMB alerts. This will require a new
27
- * interface into the I2C driver, I believe.
28
- */
25
+#define pr_fmt(fmt) "ipmi_ssif: " fmt
26
+#define dev_fmt(fmt) "ipmi_ssif: " fmt
2927
3028 #if defined(MODVERSIONS)
3129 #include <linux/modversions.h>
....@@ -49,10 +47,8 @@
4947 #include <linux/acpi.h>
5048 #include <linux/ctype.h>
5149 #include <linux/time64.h>
52
-#include "ipmi_si_sm.h"
5350 #include "ipmi_dmi.h"
5451
55
-#define PFX "ipmi_ssif: "
5652 #define DEVICE_NAME "ipmi_ssif"
5753
5854 #define IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_CMD 0x57
....@@ -60,6 +56,7 @@
6056 #define SSIF_IPMI_REQUEST 2
6157 #define SSIF_IPMI_MULTI_PART_REQUEST_START 6
6258 #define SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE 7
59
+#define SSIF_IPMI_MULTI_PART_REQUEST_END 8
6360 #define SSIF_IPMI_RESPONSE 3
6461 #define SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE 9
6562
....@@ -77,7 +74,8 @@
7774 /*
7875 * Timer values
7976 */
80
-#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). */
8179 #define SSIF_MSG_PART_USEC 5000 /* 5ms for a message part */
8280
8381 /* How many times to we retry sending/receiving the message. */
....@@ -85,11 +83,19 @@
8583 #define SSIF_RECV_RETRIES 250
8684
8785 #define SSIF_MSG_MSEC (SSIF_MSG_USEC / 1000)
86
+#define SSIF_REQ_RETRY_MSEC (SSIF_REQ_RETRY_USEC / 1000)
8887 #define SSIF_MSG_JIFFIES ((SSIF_MSG_USEC * 1000) / TICK_NSEC)
88
+#define SSIF_REQ_RETRY_JIFFIES ((SSIF_REQ_RETRY_USEC * 1000) / TICK_NSEC)
8989 #define SSIF_MSG_PART_JIFFIES ((SSIF_MSG_PART_USEC * 1000) / TICK_NSEC)
9090
91
+/*
92
+ * Timeout for the watch, only used for get flag timer.
93
+ */
94
+#define SSIF_WATCH_MSG_TIMEOUT msecs_to_jiffies(10)
95
+#define SSIF_WATCH_WATCHDOG_TIMEOUT msecs_to_jiffies(250)
96
+
9197 enum ssif_intf_state {
92
- SSIF_NORMAL,
98
+ SSIF_IDLE,
9399 SSIF_GETTING_FLAGS,
94100 SSIF_GETTING_EVENTS,
95101 SSIF_CLEARING_FLAGS,
....@@ -97,8 +103,8 @@
97103 /* FIXME - add watchdog stuff. */
98104 };
99105
100
-#define SSIF_IDLE(ssif) ((ssif)->ssif_state == SSIF_NORMAL \
101
- && (ssif)->curr_msg == NULL)
106
+#define IS_SSIF_IDLE(ssif) ((ssif)->ssif_state == SSIF_IDLE \
107
+ && (ssif)->curr_msg == NULL)
102108
103109 /*
104110 * Indexes into stats[] in ssif_info below.
....@@ -181,8 +187,6 @@
181187 struct device *dev;
182188 struct i2c_client *client;
183189
184
- struct i2c_client *added_client;
185
-
186190 struct mutex clients_mutex;
187191 struct list_head clients;
188192
....@@ -228,6 +232,9 @@
228232 bool got_alert;
229233 bool waiting_alert;
230234
235
+ /* Used to inform the timeout that it should do a resend. */
236
+ bool do_resend;
237
+
231238 /*
232239 * If set to true, this will request events the next time the
233240 * state machine is idle.
....@@ -268,9 +275,13 @@
268275 struct timer_list retry_timer;
269276 int retries_left;
270277
278
+ long watch_timeout; /* Timeout for flags check, 0 if off. */
279
+ struct timer_list watch_timer; /* Flag fetch timer. */
280
+
271281 /* Info from SSIF cmd */
272282 unsigned char max_xmit_msg_size;
273283 unsigned char max_recv_msg_size;
284
+ bool cmd8_works; /* See test_multipart_messages() for details. */
274285 unsigned int multi_support;
275286 int supports_pec;
276287
....@@ -290,6 +301,7 @@
290301 ((unsigned int) atomic_read(&(ssif)->stats[SSIF_STAT_ ## stat]))
291302
292303 static bool initialized;
304
+static bool platform_registered;
293305
294306 static void return_hosed_msg(struct ssif_info *ssif_info,
295307 struct ipmi_smi_msg *msg);
....@@ -300,6 +312,7 @@
300312
301313 static unsigned long *ipmi_ssif_lock_cond(struct ssif_info *ssif_info,
302314 unsigned long *flags)
315
+ __acquires(&ssif_info->lock)
303316 {
304317 spin_lock_irqsave(&ssif_info->lock, *flags);
305318 return flags;
....@@ -307,6 +320,7 @@
307320
308321 static void ipmi_ssif_unlock_cond(struct ssif_info *ssif_info,
309322 unsigned long *flags)
323
+ __releases(&ssif_info->lock)
310324 {
311325 spin_unlock_irqrestore(&ssif_info->lock, *flags);
312326 }
....@@ -316,9 +330,9 @@
316330 {
317331 if (msg->rsp_size < 0) {
318332 return_hosed_msg(ssif_info, msg);
319
- pr_err(PFX
320
- "Malformed message in deliver_recv_msg: rsp_size = %d\n",
321
- msg->rsp_size);
333
+ dev_err(&ssif_info->client->dev,
334
+ "%s: Malformed message: rsp_size = %d\n",
335
+ __func__, msg->rsp_size);
322336 } else {
323337 ipmi_smi_msg_received(ssif_info->intf, msg);
324338 }
....@@ -340,9 +354,9 @@
340354
341355 /*
342356 * Must be called with the message lock held. This will release the
343
- * message lock. Note that the caller will check SSIF_IDLE and start a
344
- * new operation, so there is no need to check for new messages to
345
- * 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.
346360 */
347361 static void start_clear_flags(struct ssif_info *ssif_info, unsigned long *flags)
348362 {
....@@ -359,7 +373,7 @@
359373
360374 if (start_send(ssif_info, msg, 3) != 0) {
361375 /* Error, just go to normal state. */
362
- ssif_info->ssif_state = SSIF_NORMAL;
376
+ ssif_info->ssif_state = SSIF_IDLE;
363377 }
364378 }
365379
....@@ -374,7 +388,7 @@
374388 mb[0] = (IPMI_NETFN_APP_REQUEST << 2);
375389 mb[1] = IPMI_GET_MSG_FLAGS_CMD;
376390 if (start_send(ssif_info, mb, 2) != 0)
377
- ssif_info->ssif_state = SSIF_NORMAL;
391
+ ssif_info->ssif_state = SSIF_IDLE;
378392 }
379393
380394 static void check_start_send(struct ssif_info *ssif_info, unsigned long *flags,
....@@ -385,7 +399,7 @@
385399
386400 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
387401 ssif_info->curr_msg = NULL;
388
- ssif_info->ssif_state = SSIF_NORMAL;
402
+ ssif_info->ssif_state = SSIF_IDLE;
389403 ipmi_ssif_unlock_cond(ssif_info, flags);
390404 ipmi_free_smi_msg(msg);
391405 }
....@@ -399,7 +413,7 @@
399413
400414 msg = ipmi_alloc_smi_msg();
401415 if (!msg) {
402
- ssif_info->ssif_state = SSIF_NORMAL;
416
+ ssif_info->ssif_state = SSIF_IDLE;
403417 ipmi_ssif_unlock_cond(ssif_info, flags);
404418 return;
405419 }
....@@ -422,7 +436,7 @@
422436
423437 msg = ipmi_alloc_smi_msg();
424438 if (!msg) {
425
- ssif_info->ssif_state = SSIF_NORMAL;
439
+ ssif_info->ssif_state = SSIF_IDLE;
426440 ipmi_ssif_unlock_cond(ssif_info, flags);
427441 return;
428442 }
....@@ -440,9 +454,9 @@
440454
441455 /*
442456 * Must be called with the message lock held. This will release the
443
- * message lock. Note that the caller will check SSIF_IDLE and start a
444
- * new operation, so there is no need to check for new messages to
445
- * 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.
446460 */
447461 static void handle_flags(struct ssif_info *ssif_info, unsigned long *flags)
448462 {
....@@ -458,7 +472,7 @@
458472 /* Events available. */
459473 start_event_fetch(ssif_info, flags);
460474 else {
461
- ssif_info->ssif_state = SSIF_NORMAL;
475
+ ssif_info->ssif_state = SSIF_IDLE;
462476 ipmi_ssif_unlock_cond(ssif_info, flags);
463477 }
464478 }
....@@ -502,7 +516,7 @@
502516 return 0;
503517 }
504518
505
-static int ssif_i2c_send(struct ssif_info *ssif_info,
519
+static void ssif_i2c_send(struct ssif_info *ssif_info,
506520 ssif_i2c_done handler,
507521 int read_write, int command,
508522 unsigned char *data, unsigned int size)
....@@ -514,7 +528,6 @@
514528 ssif_info->i2c_data = data;
515529 ssif_info->i2c_size = size;
516530 complete(&ssif_info->wake_thread);
517
- return 0;
518531 }
519532
520533
....@@ -523,41 +536,60 @@
523536
524537 static void start_get(struct ssif_info *ssif_info)
525538 {
526
- int rv;
527
-
528539 ssif_info->rtc_us_timer = 0;
529540 ssif_info->multi_pos = 0;
530541
531
- rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
532
- SSIF_IPMI_RESPONSE,
533
- ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
534
- if (rv < 0) {
535
- /* request failed, just return the error. */
536
- if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
537
- pr_info("Error from i2c_non_blocking_op(5)\n");
538
-
539
- msg_done_handler(ssif_info, -EIO, NULL, 0);
540
- }
542
+ ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
543
+ SSIF_IPMI_RESPONSE,
544
+ ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
541545 }
546
+
547
+static void start_resend(struct ssif_info *ssif_info);
542548
543549 static void retry_timeout(struct timer_list *t)
544550 {
545551 struct ssif_info *ssif_info = from_timer(ssif_info, t, retry_timer);
546552 unsigned long oflags, *flags;
547
- bool waiting;
553
+ bool waiting, resend;
548554
549555 if (ssif_info->stopping)
550556 return;
551557
552558 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
559
+ resend = ssif_info->do_resend;
560
+ ssif_info->do_resend = false;
553561 waiting = ssif_info->waiting_alert;
554562 ssif_info->waiting_alert = false;
555563 ipmi_ssif_unlock_cond(ssif_info, flags);
556564
557565 if (waiting)
558566 start_get(ssif_info);
567
+ if (resend) {
568
+ start_resend(ssif_info);
569
+ ssif_inc_stat(ssif_info, send_retries);
570
+ }
559571 }
560572
573
+static void watch_timeout(struct timer_list *t)
574
+{
575
+ struct ssif_info *ssif_info = from_timer(ssif_info, t, watch_timer);
576
+ unsigned long oflags, *flags;
577
+
578
+ if (ssif_info->stopping)
579
+ return;
580
+
581
+ flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
582
+ if (ssif_info->watch_timeout) {
583
+ mod_timer(&ssif_info->watch_timer,
584
+ jiffies + ssif_info->watch_timeout);
585
+ if (IS_SSIF_IDLE(ssif_info)) {
586
+ start_flag_fetch(ssif_info, flags); /* Releases lock */
587
+ return;
588
+ }
589
+ ssif_info->req_flags = true;
590
+ }
591
+ ipmi_ssif_unlock_cond(ssif_info, flags);
592
+}
561593
562594 static void ssif_alert(struct i2c_client *client, enum i2c_alert_protocol type,
563595 unsigned int data)
....@@ -584,14 +616,11 @@
584616 start_get(ssif_info);
585617 }
586618
587
-static int start_resend(struct ssif_info *ssif_info);
588
-
589619 static void msg_done_handler(struct ssif_info *ssif_info, int result,
590620 unsigned char *data, unsigned int len)
591621 {
592622 struct ipmi_smi_msg *msg;
593623 unsigned long oflags, *flags;
594
- int rv;
595624
596625 /*
597626 * We are single-threaded here, so no need for a lock until we
....@@ -616,7 +645,8 @@
616645 ssif_inc_stat(ssif_info, receive_errors);
617646
618647 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
619
- pr_info("Error in msg_done_handler: %d\n", result);
648
+ dev_dbg(&ssif_info->client->dev,
649
+ "%s: Error %d\n", __func__, result);
620650 len = 0;
621651 goto continue_op;
622652 }
....@@ -636,16 +666,10 @@
636666 ssif_info->multi_len = len;
637667 ssif_info->multi_pos = 1;
638668
639
- rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
640
- SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE,
641
- ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
642
- if (rv < 0) {
643
- if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
644
- pr_info("Error from i2c_non_blocking_op(1)\n");
645
-
646
- result = -EIO;
647
- } else
648
- 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;
649673 } else if (ssif_info->multi_pos) {
650674 /* Middle of multi-part read. Start the next transaction. */
651675 int i;
....@@ -654,7 +678,8 @@
654678 if (len == 0) {
655679 result = -EIO;
656680 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
657
- pr_info(PFX "Middle message with no data\n");
681
+ dev_dbg(&ssif_info->client->dev,
682
+ "Middle message with no data\n");
658683
659684 goto continue_op;
660685 }
....@@ -667,7 +692,8 @@
667692 /* All blocks but the last must have 31 data bytes. */
668693 result = -EIO;
669694 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
670
- pr_info("Received middle message <31\n");
695
+ dev_dbg(&ssif_info->client->dev,
696
+ "Received middle message <31\n");
671697
672698 goto continue_op;
673699 }
....@@ -676,7 +702,8 @@
676702 /* Received message too big, abort the operation. */
677703 result = -E2BIG;
678704 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
679
- pr_info("Received message too big\n");
705
+ dev_dbg(&ssif_info->client->dev,
706
+ "Received message too big\n");
680707
681708 goto continue_op;
682709 }
....@@ -704,19 +731,12 @@
704731
705732 ssif_info->multi_pos++;
706733
707
- rv = ssif_i2c_send(ssif_info, msg_done_handler,
708
- I2C_SMBUS_READ,
709
- SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE,
710
- ssif_info->recv,
711
- I2C_SMBUS_BLOCK_DATA);
712
- if (rv < 0) {
713
- if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
714
- pr_info(PFX
715
- "Error from ssif_i2c_send\n");
716
-
717
- result = -EIO;
718
- } else
719
- 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;
720740 }
721741 }
722742
....@@ -729,7 +749,8 @@
729749 }
730750
731751 if (ssif_info->ssif_debug & SSIF_DEBUG_STATE)
732
- pr_info(PFX "DONE 1: state = %d, result=%d.\n",
752
+ dev_dbg(&ssif_info->client->dev,
753
+ "DONE 1: state = %d, result=%d\n",
733754 ssif_info->ssif_state, result);
734755
735756 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
....@@ -747,7 +768,7 @@
747768 }
748769
749770 switch (ssif_info->ssif_state) {
750
- case SSIF_NORMAL:
771
+ case SSIF_IDLE:
751772 ipmi_ssif_unlock_cond(ssif_info, flags);
752773 if (!msg)
753774 break;
....@@ -765,19 +786,21 @@
765786 * Error fetching flags, or invalid length,
766787 * just give up for now.
767788 */
768
- ssif_info->ssif_state = SSIF_NORMAL;
789
+ ssif_info->ssif_state = SSIF_IDLE;
769790 ipmi_ssif_unlock_cond(ssif_info, flags);
770
- pr_warn(PFX "Error getting flags: %d %d, %x\n",
771
- result, len, (len >= 3) ? data[2] : 0);
791
+ dev_warn(&ssif_info->client->dev,
792
+ "Error getting flags: %d %d, %x\n",
793
+ result, len, (len >= 3) ? data[2] : 0);
772794 } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
773795 || data[1] != IPMI_GET_MSG_FLAGS_CMD) {
774796 /*
775
- * Don't abort here, maybe it was a queued
776
- * response to a previous command.
797
+ * Recv error response, give up.
777798 */
799
+ ssif_info->ssif_state = SSIF_IDLE;
778800 ipmi_ssif_unlock_cond(ssif_info, flags);
779
- pr_warn(PFX "Invalid response getting flags: %x %x\n",
780
- data[0], data[1]);
801
+ dev_warn(&ssif_info->client->dev,
802
+ "Invalid response getting flags: %x %x\n",
803
+ data[0], data[1]);
781804 } else {
782805 ssif_inc_stat(ssif_info, flag_fetches);
783806 ssif_info->msg_flags = data[3];
....@@ -789,18 +812,28 @@
789812 /* We cleared the flags. */
790813 if ((result < 0) || (len < 3) || (data[2] != 0)) {
791814 /* Error clearing flags */
792
- pr_warn(PFX "Error clearing flags: %d %d, %x\n",
793
- result, len, (len >= 3) ? data[2] : 0);
815
+ dev_warn(&ssif_info->client->dev,
816
+ "Error clearing flags: %d %d, %x\n",
817
+ result, len, (len >= 3) ? data[2] : 0);
794818 } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
795819 || data[1] != IPMI_CLEAR_MSG_FLAGS_CMD) {
796
- pr_warn(PFX "Invalid response clearing flags: %x %x\n",
797
- data[0], data[1]);
820
+ dev_warn(&ssif_info->client->dev,
821
+ "Invalid response clearing flags: %x %x\n",
822
+ data[0], data[1]);
798823 }
799
- ssif_info->ssif_state = SSIF_NORMAL;
824
+ ssif_info->ssif_state = SSIF_IDLE;
800825 ipmi_ssif_unlock_cond(ssif_info, flags);
801826 break;
802827
803828 case SSIF_GETTING_EVENTS:
829
+ if (!msg) {
830
+ /* Should never happen, but just in case. */
831
+ dev_warn(&ssif_info->client->dev,
832
+ "No message set while getting events\n");
833
+ ipmi_ssif_unlock_cond(ssif_info, flags);
834
+ break;
835
+ }
836
+
804837 if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) {
805838 /* Error getting event, probably done. */
806839 msg->done(msg);
....@@ -810,8 +843,9 @@
810843 handle_flags(ssif_info, flags);
811844 } else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
812845 || msg->rsp[1] != IPMI_READ_EVENT_MSG_BUFFER_CMD) {
813
- pr_warn(PFX "Invalid response getting events: %x %x\n",
814
- msg->rsp[0], msg->rsp[1]);
846
+ dev_warn(&ssif_info->client->dev,
847
+ "Invalid response getting events: %x %x\n",
848
+ msg->rsp[0], msg->rsp[1]);
815849 msg->done(msg);
816850 /* Take off the event flag. */
817851 ssif_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL;
....@@ -824,6 +858,14 @@
824858 break;
825859
826860 case SSIF_GETTING_MESSAGES:
861
+ if (!msg) {
862
+ /* Should never happen, but just in case. */
863
+ dev_warn(&ssif_info->client->dev,
864
+ "No message set while getting messages\n");
865
+ ipmi_ssif_unlock_cond(ssif_info, flags);
866
+ break;
867
+ }
868
+
827869 if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) {
828870 /* Error getting event, probably done. */
829871 msg->done(msg);
....@@ -833,8 +875,9 @@
833875 handle_flags(ssif_info, flags);
834876 } else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
835877 || msg->rsp[1] != IPMI_GET_MSG_CMD) {
836
- pr_warn(PFX "Invalid response clearing flags: %x %x\n",
837
- msg->rsp[0], msg->rsp[1]);
878
+ dev_warn(&ssif_info->client->dev,
879
+ "Invalid response clearing flags: %x %x\n",
880
+ msg->rsp[0], msg->rsp[1]);
838881 msg->done(msg);
839882
840883 /* Take off the msg flag. */
....@@ -846,10 +889,17 @@
846889 deliver_recv_msg(ssif_info, msg);
847890 }
848891 break;
892
+
893
+ default:
894
+ /* Should never happen, but just in case. */
895
+ dev_warn(&ssif_info->client->dev,
896
+ "Invalid state in message done handling: %d\n",
897
+ ssif_info->ssif_state);
898
+ ipmi_ssif_unlock_cond(ssif_info, flags);
849899 }
850900
851901 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
852
- if (SSIF_IDLE(ssif_info) && !ssif_info->stopping) {
902
+ if (IS_SSIF_IDLE(ssif_info) && !ssif_info->stopping) {
853903 if (ssif_info->req_events)
854904 start_event_fetch(ssif_info, flags);
855905 else if (ssif_info->req_flags)
....@@ -860,42 +910,34 @@
860910 ipmi_ssif_unlock_cond(ssif_info, flags);
861911
862912 if (ssif_info->ssif_debug & SSIF_DEBUG_STATE)
863
- pr_info(PFX "DONE 2: state = %d.\n", ssif_info->ssif_state);
913
+ dev_dbg(&ssif_info->client->dev,
914
+ "DONE 2: state = %d.\n", ssif_info->ssif_state);
864915 }
865916
866917 static void msg_written_handler(struct ssif_info *ssif_info, int result,
867918 unsigned char *data, unsigned int len)
868919 {
869
- int rv;
870
-
871920 /* We are single-threaded here, so no need for a lock. */
872921 if (result < 0) {
873922 ssif_info->retries_left--;
874923 if (ssif_info->retries_left > 0) {
875
- if (!start_resend(ssif_info)) {
876
- ssif_inc_stat(ssif_info, send_retries);
877
- return;
878
- }
879
- /* request failed, just return the error. */
880
- ssif_inc_stat(ssif_info, send_errors);
881
-
882
- if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
883
- pr_info(PFX
884
- "Out of retries in msg_written_handler\n");
885
- 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);
886931 return;
887932 }
888933
889934 ssif_inc_stat(ssif_info, send_errors);
890935
891
- /*
892
- * Got an error on transmit, let the done routine
893
- * handle it.
894
- */
895936 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
896
- pr_info("Error in msg_written_handler: %d\n", result);
937
+ dev_dbg(&ssif_info->client->dev,
938
+ "%s: Out of retries\n", __func__);
897939
898
- msg_done_handler(ssif_info, result, NULL, 0);
940
+ msg_done_handler(ssif_info, -EIO, NULL, 0);
899941 return;
900942 }
901943
....@@ -905,40 +947,33 @@
905947 * in the SSIF_MULTI_n_PART case in the probe function
906948 * for details on the intricacies of this.
907949 */
908
- int left;
950
+ int left, to_write;
909951 unsigned char *data_to_send;
952
+ unsigned char cmd;
910953
911954 ssif_inc_stat(ssif_info, sent_messages_parts);
912955
913956 left = ssif_info->multi_len - ssif_info->multi_pos;
914
- if (left > 32)
915
- left = 32;
957
+ to_write = left;
958
+ if (to_write > 32)
959
+ to_write = 32;
916960 /* Length byte. */
917
- ssif_info->multi_data[ssif_info->multi_pos] = left;
961
+ ssif_info->multi_data[ssif_info->multi_pos] = to_write;
918962 data_to_send = ssif_info->multi_data + ssif_info->multi_pos;
919
- ssif_info->multi_pos += left;
920
- if (left < 32)
921
- /*
922
- * Write is finished. Note that we must end
923
- * with a write of less than 32 bytes to
924
- * complete the transaction, even if it is
925
- * zero bytes.
926
- */
963
+ ssif_info->multi_pos += to_write;
964
+ cmd = SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE;
965
+ if (ssif_info->cmd8_works) {
966
+ if (left == to_write) {
967
+ cmd = SSIF_IPMI_MULTI_PART_REQUEST_END;
968
+ ssif_info->multi_data = NULL;
969
+ }
970
+ } else if (to_write < 32) {
927971 ssif_info->multi_data = NULL;
928
-
929
- rv = ssif_i2c_send(ssif_info, msg_written_handler,
930
- I2C_SMBUS_WRITE,
931
- SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE,
932
- data_to_send,
933
- I2C_SMBUS_BLOCK_DATA);
934
- if (rv < 0) {
935
- /* request failed, just return the error. */
936
- ssif_inc_stat(ssif_info, send_errors);
937
-
938
- if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
939
- pr_info("Error from i2c_non_blocking_op(3)\n");
940
- msg_done_handler(ssif_info, -EIO, NULL, 0);
941972 }
973
+
974
+ ssif_i2c_send(ssif_info, msg_written_handler,
975
+ I2C_SMBUS_WRITE, cmd,
976
+ data_to_send, I2C_SMBUS_BLOCK_DATA);
942977 } else {
943978 /* Ready to request the result. */
944979 unsigned long oflags, *flags;
....@@ -965,9 +1000,8 @@
9651000 }
9661001 }
9671002
968
-static int start_resend(struct ssif_info *ssif_info)
1003
+static void start_resend(struct ssif_info *ssif_info)
9691004 {
970
- int rv;
9711005 int command;
9721006
9731007 ssif_info->got_alert = false;
....@@ -989,11 +1023,8 @@
9891023 ssif_info->data[0] = ssif_info->data_len;
9901024 }
9911025
992
- rv = ssif_i2c_send(ssif_info, msg_written_handler, I2C_SMBUS_WRITE,
993
- command, ssif_info->data, I2C_SMBUS_BLOCK_DATA);
994
- if (rv && (ssif_info->ssif_debug & SSIF_DEBUG_MSG))
995
- pr_info("Error from i2c_non_blocking_op(4)\n");
996
- return rv;
1026
+ ssif_i2c_send(ssif_info, msg_written_handler, I2C_SMBUS_WRITE,
1027
+ command, ssif_info->data, I2C_SMBUS_BLOCK_DATA);
9971028 }
9981029
9991030 static int start_send(struct ssif_info *ssif_info,
....@@ -1008,7 +1039,8 @@
10081039 ssif_info->retries_left = SSIF_SEND_RETRIES;
10091040 memcpy(ssif_info->data + 1, data, len);
10101041 ssif_info->data_len = len;
1011
- return start_resend(ssif_info);
1042
+ start_resend(ssif_info);
1043
+ return 0;
10121044 }
10131045
10141046 /* Must be called with the message lock held. */
....@@ -1018,7 +1050,7 @@
10181050 unsigned long oflags;
10191051
10201052 restart:
1021
- if (!SSIF_IDLE(ssif_info)) {
1053
+ if (!IS_SSIF_IDLE(ssif_info)) {
10221054 ipmi_ssif_unlock_cond(ssif_info, flags);
10231055 return;
10241056 }
....@@ -1061,9 +1093,10 @@
10611093 struct timespec64 t;
10621094
10631095 ktime_get_real_ts64(&t);
1064
- pr_info("**Enqueue %02x %02x: %lld.%6.6ld\n",
1065
- msg->data[0], msg->data[1],
1066
- (long long) t.tv_sec, (long) t.tv_nsec / NSEC_PER_USEC);
1096
+ dev_dbg(&ssif_info->client->dev,
1097
+ "**Enqueue %02x %02x: %lld.%6.6ld\n",
1098
+ msg->data[0], msg->data[1],
1099
+ (long long)t.tv_sec, (long)t.tv_nsec / NSEC_PER_USEC);
10671100 }
10681101 }
10691102
....@@ -1080,8 +1113,7 @@
10801113 }
10811114
10821115 /*
1083
- * Instead of having our own timer to periodically check the message
1084
- * flags, we let the message handler drive us.
1116
+ * Upper layer wants us to request events.
10851117 */
10861118 static void request_events(void *send_info)
10871119 {
....@@ -1092,18 +1124,33 @@
10921124 return;
10931125
10941126 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
1095
- /*
1096
- * Request flags first, not events, because the lower layer
1097
- * doesn't have a way to send an attention. But make sure
1098
- * event checking still happens.
1099
- */
11001127 ssif_info->req_events = true;
1101
- if (SSIF_IDLE(ssif_info))
1102
- start_flag_fetch(ssif_info, flags);
1103
- else {
1104
- ssif_info->req_flags = true;
1105
- ipmi_ssif_unlock_cond(ssif_info, flags);
1128
+ ipmi_ssif_unlock_cond(ssif_info, flags);
1129
+}
1130
+
1131
+/*
1132
+ * Upper layer is changing the flag saying whether we need to request
1133
+ * flags periodically or not.
1134
+ */
1135
+static void ssif_set_need_watch(void *send_info, unsigned int watch_mask)
1136
+{
1137
+ struct ssif_info *ssif_info = (struct ssif_info *) send_info;
1138
+ unsigned long oflags, *flags;
1139
+ long timeout = 0;
1140
+
1141
+ if (watch_mask & IPMI_WATCH_MASK_CHECK_MESSAGES)
1142
+ timeout = SSIF_WATCH_MSG_TIMEOUT;
1143
+ else if (watch_mask)
1144
+ timeout = SSIF_WATCH_WATCHDOG_TIMEOUT;
1145
+
1146
+ flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
1147
+ if (timeout != ssif_info->watch_timeout) {
1148
+ ssif_info->watch_timeout = timeout;
1149
+ if (ssif_info->watch_timeout)
1150
+ mod_timer(&ssif_info->watch_timer,
1151
+ jiffies + ssif_info->watch_timeout);
11061152 }
1153
+ ipmi_ssif_unlock_cond(ssif_info, flags);
11071154 }
11081155
11091156 static int ssif_start_processing(void *send_info,
....@@ -1226,10 +1273,11 @@
12261273 dev_set_drvdata(&ssif_info->client->dev, NULL);
12271274
12281275 /* make sure the driver is not looking for flags any more. */
1229
- while (ssif_info->ssif_state != SSIF_NORMAL)
1276
+ while (ssif_info->ssif_state != SSIF_IDLE)
12301277 schedule_timeout(1);
12311278
12321279 ssif_info->stopping = true;
1280
+ del_timer_sync(&ssif_info->watch_timer);
12331281 del_timer_sync(&ssif_info->retry_timer);
12341282 if (ssif_info->thread) {
12351283 complete(&ssif_info->wake_thread);
....@@ -1263,24 +1311,10 @@
12631311 return 0;
12641312 }
12651313
1266
-static int do_cmd(struct i2c_client *client, int len, unsigned char *msg,
1267
- int *resp_len, unsigned char *resp)
1314
+static int read_response(struct i2c_client *client, unsigned char *resp)
12681315 {
1269
- int retry_cnt;
1270
- int ret;
1316
+ int ret = -ENODEV, retry_cnt = SSIF_RECV_RETRIES;
12711317
1272
- retry_cnt = SSIF_SEND_RETRIES;
1273
- retry1:
1274
- ret = i2c_smbus_write_block_data(client, SSIF_IPMI_REQUEST, len, msg);
1275
- if (ret) {
1276
- retry_cnt--;
1277
- if (retry_cnt > 0)
1278
- goto retry1;
1279
- return -ENODEV;
1280
- }
1281
-
1282
- ret = -ENODEV;
1283
- retry_cnt = SSIF_RECV_RETRIES;
12841318 while (retry_cnt > 0) {
12851319 ret = i2c_smbus_read_block_data(client, SSIF_IPMI_RESPONSE,
12861320 resp);
....@@ -1292,13 +1326,37 @@
12921326 break;
12931327 }
12941328
1329
+ return ret;
1330
+}
1331
+
1332
+static int do_cmd(struct i2c_client *client, int len, unsigned char *msg,
1333
+ int *resp_len, unsigned char *resp)
1334
+{
1335
+ int retry_cnt;
1336
+ int ret;
1337
+
1338
+ retry_cnt = SSIF_SEND_RETRIES;
1339
+ retry1:
1340
+ ret = i2c_smbus_write_block_data(client, SSIF_IPMI_REQUEST, len, msg);
1341
+ if (ret) {
1342
+ retry_cnt--;
1343
+ if (retry_cnt > 0) {
1344
+ msleep(SSIF_REQ_RETRY_MSEC);
1345
+ goto retry1;
1346
+ }
1347
+ return -ENODEV;
1348
+ }
1349
+
1350
+ ret = read_response(client, resp);
12951351 if (ret > 0) {
12961352 /* Validate that the response is correct. */
12971353 if (ret < 3 ||
12981354 (resp[0] != (msg[0] | (1 << 2))) ||
12991355 (resp[1] != msg[1]))
13001356 ret = -EINVAL;
1301
- else {
1357
+ else if (ret > IPMI_MAX_MSG_LENGTH) {
1358
+ ret = -E2BIG;
1359
+ } else {
13021360 *resp_len = ret;
13031361 ret = 0;
13041362 }
....@@ -1356,6 +1414,10 @@
13561414 restart:
13571415 list_for_each_entry(info, &ssif_infos, link) {
13581416 if (info->binfo.addr == addr) {
1417
+ if (info->addr_src == SI_SMBIOS && !info->adapter_name)
1418
+ info->adapter_name = kstrdup(adapter_name,
1419
+ GFP_KERNEL);
1420
+
13591421 if (info->adapter_name || adapter_name) {
13601422 if (!info->adapter_name != !adapter_name) {
13611423 /* One is NULL and one is not */
....@@ -1391,6 +1453,7 @@
13911453 if (acpi_handle) {
13921454 ssif_info->addr_source = SI_ACPI;
13931455 ssif_info->addr_info.acpi_info.acpi_handle = acpi_handle;
1456
+ request_module("acpi_ipmi");
13941457 return true;
13951458 }
13961459 #endif
....@@ -1410,11 +1473,187 @@
14101473 return slave_addr;
14111474 }
14121475
1476
+static int start_multipart_test(struct i2c_client *client,
1477
+ unsigned char *msg, bool do_middle)
1478
+{
1479
+ int retry_cnt = SSIF_SEND_RETRIES, ret;
1480
+
1481
+retry_write:
1482
+ ret = i2c_smbus_write_block_data(client,
1483
+ SSIF_IPMI_MULTI_PART_REQUEST_START,
1484
+ 32, msg);
1485
+ if (ret) {
1486
+ retry_cnt--;
1487
+ if (retry_cnt > 0) {
1488
+ msleep(SSIF_REQ_RETRY_MSEC);
1489
+ goto retry_write;
1490
+ }
1491
+ 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");
1492
+ return ret;
1493
+ }
1494
+
1495
+ if (!do_middle)
1496
+ return 0;
1497
+
1498
+ ret = i2c_smbus_write_block_data(client,
1499
+ SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE,
1500
+ 32, msg + 32);
1501
+ if (ret) {
1502
+ dev_err(&client->dev, "Could not write multi-part middle, though the BMC said it could handle it. Just limit sends to one part.\n");
1503
+ return ret;
1504
+ }
1505
+
1506
+ return 0;
1507
+}
1508
+
1509
+static void test_multipart_messages(struct i2c_client *client,
1510
+ struct ssif_info *ssif_info,
1511
+ unsigned char *resp)
1512
+{
1513
+ unsigned char msg[65];
1514
+ int ret;
1515
+ bool do_middle;
1516
+
1517
+ if (ssif_info->max_xmit_msg_size <= 32)
1518
+ return;
1519
+
1520
+ do_middle = ssif_info->max_xmit_msg_size > 63;
1521
+
1522
+ memset(msg, 0, sizeof(msg));
1523
+ msg[0] = IPMI_NETFN_APP_REQUEST << 2;
1524
+ msg[1] = IPMI_GET_DEVICE_ID_CMD;
1525
+
1526
+ /*
1527
+ * The specification is all messed up dealing with sending
1528
+ * multi-part messages. Per what the specification says, it
1529
+ * is impossible to send a message that is a multiple of 32
1530
+ * bytes, except for 32 itself. It talks about a "start"
1531
+ * transaction (cmd=6) that must be 32 bytes, "middle"
1532
+ * transaction (cmd=7) that must be 32 bytes, and an "end"
1533
+ * transaction. The "end" transaction is shown as cmd=7 in
1534
+ * the text, but if that's the case there is no way to
1535
+ * differentiate between a middle and end part except the
1536
+ * length being less than 32. But there is a table at the far
1537
+ * end of the section (that I had never noticed until someone
1538
+ * pointed it out to me) that mentions it as cmd=8.
1539
+ *
1540
+ * After some thought, I think the example is wrong and the
1541
+ * end transaction should be cmd=8. But some systems don't
1542
+ * implement cmd=8, they use a zero-length end transaction,
1543
+ * even though that violates the SMBus specification.
1544
+ *
1545
+ * So, to work around this, this code tests if cmd=8 works.
1546
+ * If it does, then we use that. If not, it tests zero-
1547
+ * byte end transactions. If that works, good. If not,
1548
+ * we only allow 63-byte transactions max.
1549
+ */
1550
+
1551
+ ret = start_multipart_test(client, msg, do_middle);
1552
+ if (ret)
1553
+ goto out_no_multi_part;
1554
+
1555
+ ret = i2c_smbus_write_block_data(client,
1556
+ SSIF_IPMI_MULTI_PART_REQUEST_END,
1557
+ 1, msg + 64);
1558
+
1559
+ if (!ret)
1560
+ ret = read_response(client, resp);
1561
+
1562
+ if (ret > 0) {
1563
+ /* End transactions work, we are good. */
1564
+ ssif_info->cmd8_works = true;
1565
+ return;
1566
+ }
1567
+
1568
+ ret = start_multipart_test(client, msg, do_middle);
1569
+ if (ret) {
1570
+ dev_err(&client->dev, "Second multipart test failed.\n");
1571
+ goto out_no_multi_part;
1572
+ }
1573
+
1574
+ ret = i2c_smbus_write_block_data(client,
1575
+ SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE,
1576
+ 0, msg + 64);
1577
+ if (!ret)
1578
+ ret = read_response(client, resp);
1579
+ if (ret > 0)
1580
+ /* Zero-size end parts work, use those. */
1581
+ return;
1582
+
1583
+ /* Limit to 63 bytes and use a short middle command to mark the end. */
1584
+ if (ssif_info->max_xmit_msg_size > 63)
1585
+ ssif_info->max_xmit_msg_size = 63;
1586
+ return;
1587
+
1588
+out_no_multi_part:
1589
+ ssif_info->max_xmit_msg_size = 32;
1590
+ return;
1591
+}
1592
+
14131593 /*
14141594 * Global enables we care about.
14151595 */
14161596 #define GLOBAL_ENABLES_MASK (IPMI_BMC_EVT_MSG_BUFF | IPMI_BMC_RCV_MSG_INTR | \
14171597 IPMI_BMC_EVT_MSG_INTR)
1598
+
1599
+static void ssif_remove_dup(struct i2c_client *client)
1600
+{
1601
+ struct ssif_info *ssif_info = i2c_get_clientdata(client);
1602
+
1603
+ ipmi_unregister_smi(ssif_info->intf);
1604
+ kfree(ssif_info);
1605
+}
1606
+
1607
+static int ssif_add_infos(struct i2c_client *client)
1608
+{
1609
+ struct ssif_addr_info *info;
1610
+
1611
+ info = kzalloc(sizeof(*info), GFP_KERNEL);
1612
+ if (!info)
1613
+ return -ENOMEM;
1614
+ info->addr_src = SI_ACPI;
1615
+ info->client = client;
1616
+ info->adapter_name = kstrdup(client->adapter->name, GFP_KERNEL);
1617
+ if (!info->adapter_name) {
1618
+ kfree(info);
1619
+ return -ENOMEM;
1620
+ }
1621
+
1622
+ info->binfo.addr = client->addr;
1623
+ list_add_tail(&info->link, &ssif_infos);
1624
+ return 0;
1625
+}
1626
+
1627
+/*
1628
+ * Prefer ACPI over SMBIOS, if both are available.
1629
+ * So if we get an ACPI interface and have already registered a SMBIOS
1630
+ * interface at the same address, remove the SMBIOS and add the ACPI one.
1631
+ */
1632
+static int ssif_check_and_remove(struct i2c_client *client,
1633
+ struct ssif_info *ssif_info)
1634
+{
1635
+ struct ssif_addr_info *info;
1636
+
1637
+ list_for_each_entry(info, &ssif_infos, link) {
1638
+ if (!info->client)
1639
+ return 0;
1640
+ if (!strcmp(info->adapter_name, client->adapter->name) &&
1641
+ info->binfo.addr == client->addr) {
1642
+ if (info->addr_src == SI_ACPI)
1643
+ return -EEXIST;
1644
+
1645
+ if (ssif_info->addr_source == SI_ACPI &&
1646
+ info->addr_src == SI_SMBIOS) {
1647
+ dev_info(&client->dev,
1648
+ "Removing %s-specified SSIF interface in favor of ACPI\n",
1649
+ ipmi_addr_src_to_str(info->addr_src));
1650
+ ssif_remove_dup(info->client);
1651
+ return 0;
1652
+ }
1653
+ }
1654
+ }
1655
+ return 0;
1656
+}
14181657
14191658 static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
14201659 {
....@@ -1427,13 +1666,17 @@
14271666 u8 slave_addr = 0;
14281667 struct ssif_addr_info *addr_info = NULL;
14291668
1669
+ mutex_lock(&ssif_infos_mutex);
14301670 resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
1431
- if (!resp)
1671
+ if (!resp) {
1672
+ mutex_unlock(&ssif_infos_mutex);
14321673 return -ENOMEM;
1674
+ }
14331675
14341676 ssif_info = kzalloc(sizeof(*ssif_info), GFP_KERNEL);
14351677 if (!ssif_info) {
14361678 kfree(resp);
1679
+ mutex_unlock(&ssif_infos_mutex);
14371680 return -ENOMEM;
14381681 }
14391682
....@@ -1452,14 +1695,28 @@
14521695 }
14531696 }
14541697
1455
- slave_addr = find_slave_address(client, slave_addr);
1456
-
1457
- pr_info(PFX "Trying %s-specified SSIF interface at i2c address 0x%x, adapter %s, slave address 0x%x\n",
1458
- ipmi_addr_src_to_str(ssif_info->addr_source),
1459
- client->addr, client->adapter->name, slave_addr);
1460
-
14611698 ssif_info->client = client;
14621699 i2c_set_clientdata(client, ssif_info);
1700
+
1701
+ rv = ssif_check_and_remove(client, ssif_info);
1702
+ /* If rv is 0 and addr source is not SI_ACPI, continue probing */
1703
+ if (!rv && ssif_info->addr_source == SI_ACPI) {
1704
+ rv = ssif_add_infos(client);
1705
+ if (rv) {
1706
+ dev_err(&client->dev, "Out of memory!, exiting ..\n");
1707
+ goto out;
1708
+ }
1709
+ } else if (rv) {
1710
+ dev_err(&client->dev, "Not probing, Interface already present\n");
1711
+ goto out;
1712
+ }
1713
+
1714
+ slave_addr = find_slave_address(client, slave_addr);
1715
+
1716
+ dev_info(&client->dev,
1717
+ "Trying %s-specified SSIF interface at i2c address 0x%x, adapter %s, slave address 0x%x\n",
1718
+ ipmi_addr_src_to_str(ssif_info->addr_source),
1719
+ client->addr, client->adapter->name, slave_addr);
14631720
14641721 /* Now check for system interface capabilities */
14651722 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
....@@ -1469,7 +1726,8 @@
14691726 if (!rv && (len >= 3) && (resp[2] == 0)) {
14701727 if (len < 7) {
14711728 if (ssif_dbg_probe)
1472
- pr_info(PFX "SSIF info too short: %d\n", len);
1729
+ dev_dbg(&ssif_info->client->dev,
1730
+ "SSIF info too short: %d\n", len);
14731731 goto no_support;
14741732 }
14751733
....@@ -1496,26 +1754,7 @@
14961754 break;
14971755
14981756 case SSIF_MULTI_n_PART:
1499
- /*
1500
- * The specification is rather confusing at
1501
- * this point, but I think I understand what
1502
- * is meant. At least I have a workable
1503
- * solution. With multi-part messages, you
1504
- * cannot send a message that is a multiple of
1505
- * 32-bytes in length, because the start and
1506
- * middle messages are 32-bytes and the end
1507
- * message must be at least one byte. You
1508
- * can't fudge on an extra byte, that would
1509
- * screw up things like fru data writes. So
1510
- * we limit the length to 63 bytes. That way
1511
- * a 32-byte message gets sent as a single
1512
- * part. A larger message will be a 32-byte
1513
- * start and the next message is always going
1514
- * to be 1-31 bytes in length. Not ideal, but
1515
- * it should work.
1516
- */
1517
- if (ssif_info->max_xmit_msg_size > 63)
1518
- ssif_info->max_xmit_msg_size = 63;
1757
+ /* We take whatever size given, but do some testing. */
15191758 break;
15201759
15211760 default:
....@@ -1525,8 +1764,9 @@
15251764 } else {
15261765 no_support:
15271766 /* Assume no multi-part or PEC support */
1528
- pr_info(PFX "Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n",
1529
- rv, len, resp[2]);
1767
+ dev_info(&ssif_info->client->dev,
1768
+ "Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n",
1769
+ rv, len, resp[2]);
15301770
15311771 ssif_info->max_xmit_msg_size = 32;
15321772 ssif_info->max_recv_msg_size = 32;
....@@ -1534,22 +1774,26 @@
15341774 ssif_info->supports_pec = 0;
15351775 }
15361776
1777
+ test_multipart_messages(client, ssif_info, resp);
1778
+
15371779 /* Make sure the NMI timeout is cleared. */
15381780 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
15391781 msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD;
15401782 msg[2] = WDT_PRE_TIMEOUT_INT;
15411783 rv = do_cmd(client, 3, msg, &len, resp);
15421784 if (rv || (len < 3) || (resp[2] != 0))
1543
- pr_warn(PFX "Unable to clear message flags: %d %d %2.2x\n",
1544
- rv, len, resp[2]);
1785
+ dev_warn(&ssif_info->client->dev,
1786
+ "Unable to clear message flags: %d %d %2.2x\n",
1787
+ rv, len, resp[2]);
15451788
15461789 /* Attempt to enable the event buffer. */
15471790 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
15481791 msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD;
15491792 rv = do_cmd(client, 2, msg, &len, resp);
15501793 if (rv || (len < 4) || (resp[2] != 0)) {
1551
- pr_warn(PFX "Error getting global enables: %d %d %2.2x\n",
1552
- rv, len, resp[2]);
1794
+ dev_warn(&ssif_info->client->dev,
1795
+ "Error getting global enables: %d %d %2.2x\n",
1796
+ rv, len, resp[2]);
15531797 rv = 0; /* Not fatal */
15541798 goto found;
15551799 }
....@@ -1567,8 +1811,9 @@
15671811 msg[2] = ssif_info->global_enables | IPMI_BMC_EVT_MSG_BUFF;
15681812 rv = do_cmd(client, 3, msg, &len, resp);
15691813 if (rv || (len < 2)) {
1570
- pr_warn(PFX "Error setting global enables: %d %d %2.2x\n",
1571
- rv, len, resp[2]);
1814
+ dev_warn(&ssif_info->client->dev,
1815
+ "Error setting global enables: %d %d %2.2x\n",
1816
+ rv, len, resp[2]);
15721817 rv = 0; /* Not fatal */
15731818 goto found;
15741819 }
....@@ -1588,8 +1833,9 @@
15881833 msg[2] = ssif_info->global_enables | IPMI_BMC_RCV_MSG_INTR;
15891834 rv = do_cmd(client, 3, msg, &len, resp);
15901835 if (rv || (len < 2)) {
1591
- pr_warn(PFX "Error setting global enables: %d %d %2.2x\n",
1592
- rv, len, resp[2]);
1836
+ dev_warn(&ssif_info->client->dev,
1837
+ "Error setting global enables: %d %d %2.2x\n",
1838
+ rv, len, resp[2]);
15931839 rv = 0; /* Not fatal */
15941840 goto found;
15951841 }
....@@ -1602,13 +1848,15 @@
16021848
16031849 found:
16041850 if (ssif_dbg_probe) {
1605
- pr_info("ssif_probe: i2c_probe found device at i2c address %x\n",
1606
- client->addr);
1851
+ dev_dbg(&ssif_info->client->dev,
1852
+ "%s: i2c_probe found device at i2c address %x\n",
1853
+ __func__, client->addr);
16071854 }
16081855
16091856 spin_lock_init(&ssif_info->lock);
1610
- ssif_info->ssif_state = SSIF_NORMAL;
1857
+ ssif_info->ssif_state = SSIF_IDLE;
16111858 timer_setup(&ssif_info->retry_timer, retry_timeout, 0);
1859
+ timer_setup(&ssif_info->watch_timer, watch_timeout, 0);
16121860
16131861 for (i = 0; i < SSIF_NUM_STATS; i++)
16141862 atomic_set(&ssif_info->stats[i], 0);
....@@ -1622,6 +1870,7 @@
16221870 ssif_info->handlers.get_smi_info = get_smi_info;
16231871 ssif_info->handlers.sender = sender;
16241872 ssif_info->handlers.request_events = request_events;
1873
+ ssif_info->handlers.set_need_watch = ssif_set_need_watch;
16251874
16261875 {
16271876 unsigned int thread_num;
....@@ -1655,8 +1904,9 @@
16551904 ssif_info,
16561905 &ssif_info->client->dev,
16571906 slave_addr);
1658
- if (rv) {
1659
- pr_err(PFX "Unable to register device: error %d\n", rv);
1907
+ if (rv) {
1908
+ dev_err(&ssif_info->client->dev,
1909
+ "Unable to register device: error %d\n", rv);
16601910 goto out_remove_attr;
16611911 }
16621912
....@@ -1665,31 +1915,19 @@
16651915 if (addr_info)
16661916 addr_info->client = NULL;
16671917
1668
- dev_err(&client->dev, "Unable to start IPMI SSIF: %d\n", rv);
1918
+ dev_err(&ssif_info->client->dev,
1919
+ "Unable to start IPMI SSIF: %d\n", rv);
1920
+ i2c_set_clientdata(client, NULL);
16691921 kfree(ssif_info);
16701922 }
16711923 kfree(resp);
1924
+ mutex_unlock(&ssif_infos_mutex);
16721925 return rv;
16731926
16741927 out_remove_attr:
16751928 device_remove_group(&ssif_info->client->dev, &ipmi_ssif_dev_attr_group);
16761929 dev_set_drvdata(&ssif_info->client->dev, NULL);
16771930 goto out;
1678
-}
1679
-
1680
-static int ssif_adapter_handler(struct device *adev, void *opaque)
1681
-{
1682
- struct ssif_addr_info *addr_info = opaque;
1683
-
1684
- if (adev->type != &i2c_adapter_type)
1685
- return 0;
1686
-
1687
- addr_info->added_client = i2c_new_device(to_i2c_adapter(adev),
1688
- &addr_info->binfo);
1689
-
1690
- if (!addr_info->adapter_name)
1691
- return 1; /* Only try the first I2C adapter by default. */
1692
- return 0;
16931931 }
16941932
16951933 static int new_ssif_client(int addr, char *adapter_name,
....@@ -1735,9 +1973,7 @@
17351973
17361974 list_add_tail(&addr_info->link, &ssif_infos);
17371975
1738
- if (initialized)
1739
- i2c_for_each_dev(addr_info, ssif_adapter_handler);
1740
- /* Otherwise address list will get it */
1976
+ /* Address list will get it */
17411977
17421978 out_unlock:
17431979 mutex_unlock(&ssif_infos_mutex);
....@@ -1760,7 +1996,7 @@
17601996 static unsigned short *ssif_address_list(void)
17611997 {
17621998 struct ssif_addr_info *info;
1763
- unsigned int count = 0, i;
1999
+ unsigned int count = 0, i = 0;
17642000 unsigned short *address_list;
17652001
17662002 list_for_each_entry(info, &ssif_infos, link)
....@@ -1771,18 +2007,17 @@
17712007 if (!address_list)
17722008 return NULL;
17732009
1774
- i = 0;
17752010 list_for_each_entry(info, &ssif_infos, link) {
17762011 unsigned short addr = info->binfo.addr;
17772012 int j;
17782013
17792014 for (j = 0; j < i; j++) {
17802015 if (address_list[j] == addr)
1781
- goto skip_addr;
2016
+ /* Found a dup. */
2017
+ break;
17822018 }
1783
- address_list[i] = addr;
1784
-skip_addr:
1785
- i++;
2019
+ if (j == i) /* Didn't find it in the list. */
2020
+ address_list[i++] = addr;
17862021 }
17872022 address_list[i] = I2C_CLIENT_END;
17882023
....@@ -1809,13 +2044,13 @@
18092044
18102045 rv = device_property_read_u16(&pdev->dev, "i2c-addr", &i2c_addr);
18112046 if (rv) {
1812
- dev_warn(&pdev->dev, PFX "No i2c-addr property\n");
2047
+ dev_warn(&pdev->dev, "No i2c-addr property\n");
18132048 return -ENODEV;
18142049 }
18152050
18162051 rv = device_property_read_u8(&pdev->dev, "slave-addr", &slave_addr);
18172052 if (rv)
1818
- dev_warn(&pdev->dev, "device has no slave-addr property");
2053
+ slave_addr = 0x20;
18192054
18202055 return new_ssif_client(i2c_addr, NULL, 0,
18212056 slave_addr, SI_SMBIOS, &pdev->dev);
....@@ -1858,13 +2093,16 @@
18582093 return 0;
18592094
18602095 mutex_lock(&ssif_infos_mutex);
1861
- i2c_unregister_device(addr_info->added_client);
1862
-
18632096 list_del(&addr_info->link);
18642097 kfree(addr_info);
18652098 mutex_unlock(&ssif_infos_mutex);
18662099 return 0;
18672100 }
2101
+
2102
+static const struct platform_device_id ssif_plat_ids[] = {
2103
+ { "dmi-ipmi-ssif", 0 },
2104
+ { }
2105
+};
18682106
18692107 static struct platform_driver ipmi_driver = {
18702108 .driver = {
....@@ -1872,6 +2110,7 @@
18722110 },
18732111 .probe = ssif_platform_probe,
18742112 .remove = ssif_platform_remove,
2113
+ .id_table = ssif_plat_ids
18752114 };
18762115
18772116 static int init_ipmi_ssif(void)
....@@ -1890,8 +2129,7 @@
18902129 dbg[i], slave_addrs[i],
18912130 SI_HARDCODED, NULL);
18922131 if (rv)
1893
- pr_err(PFX
1894
- "Couldn't add hardcoded device at addr 0x%x\n",
2132
+ pr_err("Couldn't add hardcoded device at addr 0x%x\n",
18952133 addr[i]);
18962134 }
18972135
....@@ -1902,7 +2140,9 @@
19022140 if (ssif_trydmi) {
19032141 rv = platform_driver_register(&ipmi_driver);
19042142 if (rv)
1905
- pr_err(PFX "Unable to register driver: %d\n", rv);
2143
+ pr_err("Unable to register driver: %d\n", rv);
2144
+ else
2145
+ platform_registered = true;
19062146 }
19072147
19082148 ssif_i2c_driver.address_list = ssif_address_list();
....@@ -1924,7 +2164,10 @@
19242164
19252165 i2c_del_driver(&ssif_i2c_driver);
19262166
1927
- platform_driver_unregister(&ipmi_driver);
2167
+ kfree(ssif_i2c_driver.address_list);
2168
+
2169
+ if (ssif_trydmi && platform_registered)
2170
+ platform_driver_unregister(&ipmi_driver);
19282171
19292172 free_ssif_clients();
19302173 }