.. | .. |
---|
22 | 22 | * and drives the real SSIF state machine. |
---|
23 | 23 | */ |
---|
24 | 24 | |
---|
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 |
---|
29 | 27 | |
---|
30 | 28 | #if defined(MODVERSIONS) |
---|
31 | 29 | #include <linux/modversions.h> |
---|
.. | .. |
---|
49 | 47 | #include <linux/acpi.h> |
---|
50 | 48 | #include <linux/ctype.h> |
---|
51 | 49 | #include <linux/time64.h> |
---|
52 | | -#include "ipmi_si_sm.h" |
---|
53 | 50 | #include "ipmi_dmi.h" |
---|
54 | 51 | |
---|
55 | | -#define PFX "ipmi_ssif: " |
---|
56 | 52 | #define DEVICE_NAME "ipmi_ssif" |
---|
57 | 53 | |
---|
58 | 54 | #define IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_CMD 0x57 |
---|
.. | .. |
---|
60 | 56 | #define SSIF_IPMI_REQUEST 2 |
---|
61 | 57 | #define SSIF_IPMI_MULTI_PART_REQUEST_START 6 |
---|
62 | 58 | #define SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE 7 |
---|
| 59 | +#define SSIF_IPMI_MULTI_PART_REQUEST_END 8 |
---|
63 | 60 | #define SSIF_IPMI_RESPONSE 3 |
---|
64 | 61 | #define SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE 9 |
---|
65 | 62 | |
---|
.. | .. |
---|
87 | 84 | #define SSIF_MSG_MSEC (SSIF_MSG_USEC / 1000) |
---|
88 | 85 | #define SSIF_MSG_JIFFIES ((SSIF_MSG_USEC * 1000) / TICK_NSEC) |
---|
89 | 86 | #define SSIF_MSG_PART_JIFFIES ((SSIF_MSG_PART_USEC * 1000) / TICK_NSEC) |
---|
| 87 | + |
---|
| 88 | +/* |
---|
| 89 | + * Timeout for the watch, only used for get flag timer. |
---|
| 90 | + */ |
---|
| 91 | +#define SSIF_WATCH_MSG_TIMEOUT msecs_to_jiffies(10) |
---|
| 92 | +#define SSIF_WATCH_WATCHDOG_TIMEOUT msecs_to_jiffies(250) |
---|
90 | 93 | |
---|
91 | 94 | enum ssif_intf_state { |
---|
92 | 95 | SSIF_NORMAL, |
---|
.. | .. |
---|
181 | 184 | struct device *dev; |
---|
182 | 185 | struct i2c_client *client; |
---|
183 | 186 | |
---|
184 | | - struct i2c_client *added_client; |
---|
185 | | - |
---|
186 | 187 | struct mutex clients_mutex; |
---|
187 | 188 | struct list_head clients; |
---|
188 | 189 | |
---|
.. | .. |
---|
268 | 269 | struct timer_list retry_timer; |
---|
269 | 270 | int retries_left; |
---|
270 | 271 | |
---|
| 272 | + long watch_timeout; /* Timeout for flags check, 0 if off. */ |
---|
| 273 | + struct timer_list watch_timer; /* Flag fetch timer. */ |
---|
| 274 | + |
---|
271 | 275 | /* Info from SSIF cmd */ |
---|
272 | 276 | unsigned char max_xmit_msg_size; |
---|
273 | 277 | unsigned char max_recv_msg_size; |
---|
| 278 | + bool cmd8_works; /* See test_multipart_messages() for details. */ |
---|
274 | 279 | unsigned int multi_support; |
---|
275 | 280 | int supports_pec; |
---|
276 | 281 | |
---|
.. | .. |
---|
290 | 295 | ((unsigned int) atomic_read(&(ssif)->stats[SSIF_STAT_ ## stat])) |
---|
291 | 296 | |
---|
292 | 297 | static bool initialized; |
---|
| 298 | +static bool platform_registered; |
---|
293 | 299 | |
---|
294 | 300 | static void return_hosed_msg(struct ssif_info *ssif_info, |
---|
295 | 301 | struct ipmi_smi_msg *msg); |
---|
.. | .. |
---|
300 | 306 | |
---|
301 | 307 | static unsigned long *ipmi_ssif_lock_cond(struct ssif_info *ssif_info, |
---|
302 | 308 | unsigned long *flags) |
---|
| 309 | + __acquires(&ssif_info->lock) |
---|
303 | 310 | { |
---|
304 | 311 | spin_lock_irqsave(&ssif_info->lock, *flags); |
---|
305 | 312 | return flags; |
---|
.. | .. |
---|
307 | 314 | |
---|
308 | 315 | static void ipmi_ssif_unlock_cond(struct ssif_info *ssif_info, |
---|
309 | 316 | unsigned long *flags) |
---|
| 317 | + __releases(&ssif_info->lock) |
---|
310 | 318 | { |
---|
311 | 319 | spin_unlock_irqrestore(&ssif_info->lock, *flags); |
---|
312 | 320 | } |
---|
.. | .. |
---|
316 | 324 | { |
---|
317 | 325 | if (msg->rsp_size < 0) { |
---|
318 | 326 | 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); |
---|
| 327 | + dev_err(&ssif_info->client->dev, |
---|
| 328 | + "%s: Malformed message: rsp_size = %d\n", |
---|
| 329 | + __func__, msg->rsp_size); |
---|
322 | 330 | } else { |
---|
323 | 331 | ipmi_smi_msg_received(ssif_info->intf, msg); |
---|
324 | 332 | } |
---|
.. | .. |
---|
534 | 542 | if (rv < 0) { |
---|
535 | 543 | /* request failed, just return the error. */ |
---|
536 | 544 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
---|
537 | | - pr_info("Error from i2c_non_blocking_op(5)\n"); |
---|
| 545 | + dev_dbg(&ssif_info->client->dev, |
---|
| 546 | + "Error from i2c_non_blocking_op(5)\n"); |
---|
538 | 547 | |
---|
539 | 548 | msg_done_handler(ssif_info, -EIO, NULL, 0); |
---|
540 | 549 | } |
---|
.. | .. |
---|
558 | 567 | start_get(ssif_info); |
---|
559 | 568 | } |
---|
560 | 569 | |
---|
| 570 | +static void watch_timeout(struct timer_list *t) |
---|
| 571 | +{ |
---|
| 572 | + struct ssif_info *ssif_info = from_timer(ssif_info, t, watch_timer); |
---|
| 573 | + unsigned long oflags, *flags; |
---|
| 574 | + |
---|
| 575 | + if (ssif_info->stopping) |
---|
| 576 | + return; |
---|
| 577 | + |
---|
| 578 | + flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
---|
| 579 | + if (ssif_info->watch_timeout) { |
---|
| 580 | + mod_timer(&ssif_info->watch_timer, |
---|
| 581 | + jiffies + ssif_info->watch_timeout); |
---|
| 582 | + if (SSIF_IDLE(ssif_info)) { |
---|
| 583 | + start_flag_fetch(ssif_info, flags); /* Releases lock */ |
---|
| 584 | + return; |
---|
| 585 | + } |
---|
| 586 | + ssif_info->req_flags = true; |
---|
| 587 | + } |
---|
| 588 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
---|
| 589 | +} |
---|
561 | 590 | |
---|
562 | 591 | static void ssif_alert(struct i2c_client *client, enum i2c_alert_protocol type, |
---|
563 | 592 | unsigned int data) |
---|
.. | .. |
---|
616 | 645 | ssif_inc_stat(ssif_info, receive_errors); |
---|
617 | 646 | |
---|
618 | 647 | 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); |
---|
620 | 650 | len = 0; |
---|
621 | 651 | goto continue_op; |
---|
622 | 652 | } |
---|
.. | .. |
---|
641 | 671 | ssif_info->recv, I2C_SMBUS_BLOCK_DATA); |
---|
642 | 672 | if (rv < 0) { |
---|
643 | 673 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
---|
644 | | - pr_info("Error from i2c_non_blocking_op(1)\n"); |
---|
| 674 | + dev_dbg(&ssif_info->client->dev, |
---|
| 675 | + "Error from i2c_non_blocking_op(1)\n"); |
---|
645 | 676 | |
---|
646 | 677 | result = -EIO; |
---|
647 | 678 | } else |
---|
.. | .. |
---|
654 | 685 | if (len == 0) { |
---|
655 | 686 | result = -EIO; |
---|
656 | 687 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
---|
657 | | - pr_info(PFX "Middle message with no data\n"); |
---|
| 688 | + dev_dbg(&ssif_info->client->dev, |
---|
| 689 | + "Middle message with no data\n"); |
---|
658 | 690 | |
---|
659 | 691 | goto continue_op; |
---|
660 | 692 | } |
---|
.. | .. |
---|
667 | 699 | /* All blocks but the last must have 31 data bytes. */ |
---|
668 | 700 | result = -EIO; |
---|
669 | 701 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
---|
670 | | - pr_info("Received middle message <31\n"); |
---|
| 702 | + dev_dbg(&ssif_info->client->dev, |
---|
| 703 | + "Received middle message <31\n"); |
---|
671 | 704 | |
---|
672 | 705 | goto continue_op; |
---|
673 | 706 | } |
---|
.. | .. |
---|
676 | 709 | /* Received message too big, abort the operation. */ |
---|
677 | 710 | result = -E2BIG; |
---|
678 | 711 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
---|
679 | | - pr_info("Received message too big\n"); |
---|
| 712 | + dev_dbg(&ssif_info->client->dev, |
---|
| 713 | + "Received message too big\n"); |
---|
680 | 714 | |
---|
681 | 715 | goto continue_op; |
---|
682 | 716 | } |
---|
.. | .. |
---|
711 | 745 | I2C_SMBUS_BLOCK_DATA); |
---|
712 | 746 | if (rv < 0) { |
---|
713 | 747 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
---|
714 | | - pr_info(PFX |
---|
| 748 | + dev_dbg(&ssif_info->client->dev, |
---|
715 | 749 | "Error from ssif_i2c_send\n"); |
---|
716 | 750 | |
---|
717 | 751 | result = -EIO; |
---|
.. | .. |
---|
729 | 763 | } |
---|
730 | 764 | |
---|
731 | 765 | if (ssif_info->ssif_debug & SSIF_DEBUG_STATE) |
---|
732 | | - pr_info(PFX "DONE 1: state = %d, result=%d.\n", |
---|
| 766 | + dev_dbg(&ssif_info->client->dev, |
---|
| 767 | + "DONE 1: state = %d, result=%d\n", |
---|
733 | 768 | ssif_info->ssif_state, result); |
---|
734 | 769 | |
---|
735 | 770 | flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
---|
.. | .. |
---|
767 | 802 | */ |
---|
768 | 803 | ssif_info->ssif_state = SSIF_NORMAL; |
---|
769 | 804 | 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); |
---|
| 805 | + dev_warn(&ssif_info->client->dev, |
---|
| 806 | + "Error getting flags: %d %d, %x\n", |
---|
| 807 | + result, len, (len >= 3) ? data[2] : 0); |
---|
772 | 808 | } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 |
---|
773 | 809 | || data[1] != IPMI_GET_MSG_FLAGS_CMD) { |
---|
774 | 810 | /* |
---|
.. | .. |
---|
776 | 812 | * response to a previous command. |
---|
777 | 813 | */ |
---|
778 | 814 | ipmi_ssif_unlock_cond(ssif_info, flags); |
---|
779 | | - pr_warn(PFX "Invalid response getting flags: %x %x\n", |
---|
780 | | - data[0], data[1]); |
---|
| 815 | + dev_warn(&ssif_info->client->dev, |
---|
| 816 | + "Invalid response getting flags: %x %x\n", |
---|
| 817 | + data[0], data[1]); |
---|
781 | 818 | } else { |
---|
782 | 819 | ssif_inc_stat(ssif_info, flag_fetches); |
---|
783 | 820 | ssif_info->msg_flags = data[3]; |
---|
.. | .. |
---|
789 | 826 | /* We cleared the flags. */ |
---|
790 | 827 | if ((result < 0) || (len < 3) || (data[2] != 0)) { |
---|
791 | 828 | /* Error clearing flags */ |
---|
792 | | - pr_warn(PFX "Error clearing flags: %d %d, %x\n", |
---|
793 | | - result, len, (len >= 3) ? data[2] : 0); |
---|
| 829 | + dev_warn(&ssif_info->client->dev, |
---|
| 830 | + "Error clearing flags: %d %d, %x\n", |
---|
| 831 | + result, len, (len >= 3) ? data[2] : 0); |
---|
794 | 832 | } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 |
---|
795 | 833 | || data[1] != IPMI_CLEAR_MSG_FLAGS_CMD) { |
---|
796 | | - pr_warn(PFX "Invalid response clearing flags: %x %x\n", |
---|
797 | | - data[0], data[1]); |
---|
| 834 | + dev_warn(&ssif_info->client->dev, |
---|
| 835 | + "Invalid response clearing flags: %x %x\n", |
---|
| 836 | + data[0], data[1]); |
---|
798 | 837 | } |
---|
799 | 838 | ssif_info->ssif_state = SSIF_NORMAL; |
---|
800 | 839 | ipmi_ssif_unlock_cond(ssif_info, flags); |
---|
801 | 840 | break; |
---|
802 | 841 | |
---|
803 | 842 | case SSIF_GETTING_EVENTS: |
---|
| 843 | + if (!msg) { |
---|
| 844 | + /* Should never happen, but just in case. */ |
---|
| 845 | + dev_warn(&ssif_info->client->dev, |
---|
| 846 | + "No message set while getting events\n"); |
---|
| 847 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
---|
| 848 | + break; |
---|
| 849 | + } |
---|
| 850 | + |
---|
804 | 851 | if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) { |
---|
805 | 852 | /* Error getting event, probably done. */ |
---|
806 | 853 | msg->done(msg); |
---|
.. | .. |
---|
810 | 857 | handle_flags(ssif_info, flags); |
---|
811 | 858 | } else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 |
---|
812 | 859 | || 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]); |
---|
| 860 | + dev_warn(&ssif_info->client->dev, |
---|
| 861 | + "Invalid response getting events: %x %x\n", |
---|
| 862 | + msg->rsp[0], msg->rsp[1]); |
---|
815 | 863 | msg->done(msg); |
---|
816 | 864 | /* Take off the event flag. */ |
---|
817 | 865 | ssif_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL; |
---|
.. | .. |
---|
824 | 872 | break; |
---|
825 | 873 | |
---|
826 | 874 | case SSIF_GETTING_MESSAGES: |
---|
| 875 | + if (!msg) { |
---|
| 876 | + /* Should never happen, but just in case. */ |
---|
| 877 | + dev_warn(&ssif_info->client->dev, |
---|
| 878 | + "No message set while getting messages\n"); |
---|
| 879 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
---|
| 880 | + break; |
---|
| 881 | + } |
---|
| 882 | + |
---|
827 | 883 | if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) { |
---|
828 | 884 | /* Error getting event, probably done. */ |
---|
829 | 885 | msg->done(msg); |
---|
.. | .. |
---|
833 | 889 | handle_flags(ssif_info, flags); |
---|
834 | 890 | } else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 |
---|
835 | 891 | || 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]); |
---|
| 892 | + dev_warn(&ssif_info->client->dev, |
---|
| 893 | + "Invalid response clearing flags: %x %x\n", |
---|
| 894 | + msg->rsp[0], msg->rsp[1]); |
---|
838 | 895 | msg->done(msg); |
---|
839 | 896 | |
---|
840 | 897 | /* Take off the msg flag. */ |
---|
.. | .. |
---|
846 | 903 | deliver_recv_msg(ssif_info, msg); |
---|
847 | 904 | } |
---|
848 | 905 | break; |
---|
| 906 | + |
---|
| 907 | + default: |
---|
| 908 | + /* Should never happen, but just in case. */ |
---|
| 909 | + dev_warn(&ssif_info->client->dev, |
---|
| 910 | + "Invalid state in message done handling: %d\n", |
---|
| 911 | + ssif_info->ssif_state); |
---|
| 912 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
---|
849 | 913 | } |
---|
850 | 914 | |
---|
851 | 915 | flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
---|
.. | .. |
---|
860 | 924 | ipmi_ssif_unlock_cond(ssif_info, flags); |
---|
861 | 925 | |
---|
862 | 926 | if (ssif_info->ssif_debug & SSIF_DEBUG_STATE) |
---|
863 | | - pr_info(PFX "DONE 2: state = %d.\n", ssif_info->ssif_state); |
---|
| 927 | + dev_dbg(&ssif_info->client->dev, |
---|
| 928 | + "DONE 2: state = %d.\n", ssif_info->ssif_state); |
---|
864 | 929 | } |
---|
865 | 930 | |
---|
866 | 931 | static void msg_written_handler(struct ssif_info *ssif_info, int result, |
---|
.. | .. |
---|
880 | 945 | ssif_inc_stat(ssif_info, send_errors); |
---|
881 | 946 | |
---|
882 | 947 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
---|
883 | | - pr_info(PFX |
---|
884 | | - "Out of retries in msg_written_handler\n"); |
---|
| 948 | + dev_dbg(&ssif_info->client->dev, |
---|
| 949 | + "%s: Out of retries\n", __func__); |
---|
885 | 950 | msg_done_handler(ssif_info, -EIO, NULL, 0); |
---|
886 | 951 | return; |
---|
887 | 952 | } |
---|
.. | .. |
---|
893 | 958 | * handle it. |
---|
894 | 959 | */ |
---|
895 | 960 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
---|
896 | | - pr_info("Error in msg_written_handler: %d\n", result); |
---|
| 961 | + dev_dbg(&ssif_info->client->dev, |
---|
| 962 | + "%s: Error %d\n", __func__, result); |
---|
897 | 963 | |
---|
898 | 964 | msg_done_handler(ssif_info, result, NULL, 0); |
---|
899 | 965 | return; |
---|
.. | .. |
---|
905 | 971 | * in the SSIF_MULTI_n_PART case in the probe function |
---|
906 | 972 | * for details on the intricacies of this. |
---|
907 | 973 | */ |
---|
908 | | - int left; |
---|
| 974 | + int left, to_write; |
---|
909 | 975 | unsigned char *data_to_send; |
---|
| 976 | + unsigned char cmd; |
---|
910 | 977 | |
---|
911 | 978 | ssif_inc_stat(ssif_info, sent_messages_parts); |
---|
912 | 979 | |
---|
913 | 980 | left = ssif_info->multi_len - ssif_info->multi_pos; |
---|
914 | | - if (left > 32) |
---|
915 | | - left = 32; |
---|
| 981 | + to_write = left; |
---|
| 982 | + if (to_write > 32) |
---|
| 983 | + to_write = 32; |
---|
916 | 984 | /* Length byte. */ |
---|
917 | | - ssif_info->multi_data[ssif_info->multi_pos] = left; |
---|
| 985 | + ssif_info->multi_data[ssif_info->multi_pos] = to_write; |
---|
918 | 986 | 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 | | - */ |
---|
| 987 | + ssif_info->multi_pos += to_write; |
---|
| 988 | + cmd = SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE; |
---|
| 989 | + if (ssif_info->cmd8_works) { |
---|
| 990 | + if (left == to_write) { |
---|
| 991 | + cmd = SSIF_IPMI_MULTI_PART_REQUEST_END; |
---|
| 992 | + ssif_info->multi_data = NULL; |
---|
| 993 | + } |
---|
| 994 | + } else if (to_write < 32) { |
---|
927 | 995 | ssif_info->multi_data = NULL; |
---|
| 996 | + } |
---|
928 | 997 | |
---|
929 | 998 | 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); |
---|
| 999 | + I2C_SMBUS_WRITE, cmd, |
---|
| 1000 | + data_to_send, I2C_SMBUS_BLOCK_DATA); |
---|
934 | 1001 | if (rv < 0) { |
---|
935 | 1002 | /* request failed, just return the error. */ |
---|
936 | 1003 | ssif_inc_stat(ssif_info, send_errors); |
---|
937 | 1004 | |
---|
938 | 1005 | if (ssif_info->ssif_debug & SSIF_DEBUG_MSG) |
---|
939 | | - pr_info("Error from i2c_non_blocking_op(3)\n"); |
---|
| 1006 | + dev_dbg(&ssif_info->client->dev, |
---|
| 1007 | + "Error from i2c_non_blocking_op(3)\n"); |
---|
940 | 1008 | msg_done_handler(ssif_info, -EIO, NULL, 0); |
---|
941 | 1009 | } |
---|
942 | 1010 | } else { |
---|
.. | .. |
---|
992 | 1060 | rv = ssif_i2c_send(ssif_info, msg_written_handler, I2C_SMBUS_WRITE, |
---|
993 | 1061 | command, ssif_info->data, I2C_SMBUS_BLOCK_DATA); |
---|
994 | 1062 | if (rv && (ssif_info->ssif_debug & SSIF_DEBUG_MSG)) |
---|
995 | | - pr_info("Error from i2c_non_blocking_op(4)\n"); |
---|
| 1063 | + dev_dbg(&ssif_info->client->dev, |
---|
| 1064 | + "Error from i2c_non_blocking_op(4)\n"); |
---|
996 | 1065 | return rv; |
---|
997 | 1066 | } |
---|
998 | 1067 | |
---|
.. | .. |
---|
1061 | 1130 | struct timespec64 t; |
---|
1062 | 1131 | |
---|
1063 | 1132 | 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); |
---|
| 1133 | + dev_dbg(&ssif_info->client->dev, |
---|
| 1134 | + "**Enqueue %02x %02x: %lld.%6.6ld\n", |
---|
| 1135 | + msg->data[0], msg->data[1], |
---|
| 1136 | + (long long)t.tv_sec, (long)t.tv_nsec / NSEC_PER_USEC); |
---|
1067 | 1137 | } |
---|
1068 | 1138 | } |
---|
1069 | 1139 | |
---|
.. | .. |
---|
1080 | 1150 | } |
---|
1081 | 1151 | |
---|
1082 | 1152 | /* |
---|
1083 | | - * Instead of having our own timer to periodically check the message |
---|
1084 | | - * flags, we let the message handler drive us. |
---|
| 1153 | + * Upper layer wants us to request events. |
---|
1085 | 1154 | */ |
---|
1086 | 1155 | static void request_events(void *send_info) |
---|
1087 | 1156 | { |
---|
.. | .. |
---|
1092 | 1161 | return; |
---|
1093 | 1162 | |
---|
1094 | 1163 | 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 | | - */ |
---|
1100 | 1164 | 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); |
---|
| 1165 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
---|
| 1166 | +} |
---|
| 1167 | + |
---|
| 1168 | +/* |
---|
| 1169 | + * Upper layer is changing the flag saying whether we need to request |
---|
| 1170 | + * flags periodically or not. |
---|
| 1171 | + */ |
---|
| 1172 | +static void ssif_set_need_watch(void *send_info, unsigned int watch_mask) |
---|
| 1173 | +{ |
---|
| 1174 | + struct ssif_info *ssif_info = (struct ssif_info *) send_info; |
---|
| 1175 | + unsigned long oflags, *flags; |
---|
| 1176 | + long timeout = 0; |
---|
| 1177 | + |
---|
| 1178 | + if (watch_mask & IPMI_WATCH_MASK_CHECK_MESSAGES) |
---|
| 1179 | + timeout = SSIF_WATCH_MSG_TIMEOUT; |
---|
| 1180 | + else if (watch_mask) |
---|
| 1181 | + timeout = SSIF_WATCH_WATCHDOG_TIMEOUT; |
---|
| 1182 | + |
---|
| 1183 | + flags = ipmi_ssif_lock_cond(ssif_info, &oflags); |
---|
| 1184 | + if (timeout != ssif_info->watch_timeout) { |
---|
| 1185 | + ssif_info->watch_timeout = timeout; |
---|
| 1186 | + if (ssif_info->watch_timeout) |
---|
| 1187 | + mod_timer(&ssif_info->watch_timer, |
---|
| 1188 | + jiffies + ssif_info->watch_timeout); |
---|
1106 | 1189 | } |
---|
| 1190 | + ipmi_ssif_unlock_cond(ssif_info, flags); |
---|
1107 | 1191 | } |
---|
1108 | 1192 | |
---|
1109 | 1193 | static int ssif_start_processing(void *send_info, |
---|
.. | .. |
---|
1230 | 1314 | schedule_timeout(1); |
---|
1231 | 1315 | |
---|
1232 | 1316 | ssif_info->stopping = true; |
---|
| 1317 | + del_timer_sync(&ssif_info->watch_timer); |
---|
1233 | 1318 | del_timer_sync(&ssif_info->retry_timer); |
---|
1234 | 1319 | if (ssif_info->thread) { |
---|
1235 | 1320 | complete(&ssif_info->wake_thread); |
---|
.. | .. |
---|
1263 | 1348 | return 0; |
---|
1264 | 1349 | } |
---|
1265 | 1350 | |
---|
| 1351 | +static int read_response(struct i2c_client *client, unsigned char *resp) |
---|
| 1352 | +{ |
---|
| 1353 | + int ret = -ENODEV, retry_cnt = SSIF_RECV_RETRIES; |
---|
| 1354 | + |
---|
| 1355 | + while (retry_cnt > 0) { |
---|
| 1356 | + ret = i2c_smbus_read_block_data(client, SSIF_IPMI_RESPONSE, |
---|
| 1357 | + resp); |
---|
| 1358 | + if (ret > 0) |
---|
| 1359 | + break; |
---|
| 1360 | + msleep(SSIF_MSG_MSEC); |
---|
| 1361 | + retry_cnt--; |
---|
| 1362 | + if (retry_cnt <= 0) |
---|
| 1363 | + break; |
---|
| 1364 | + } |
---|
| 1365 | + |
---|
| 1366 | + return ret; |
---|
| 1367 | +} |
---|
| 1368 | + |
---|
1266 | 1369 | static int do_cmd(struct i2c_client *client, int len, unsigned char *msg, |
---|
1267 | 1370 | int *resp_len, unsigned char *resp) |
---|
1268 | 1371 | { |
---|
.. | .. |
---|
1279 | 1382 | return -ENODEV; |
---|
1280 | 1383 | } |
---|
1281 | 1384 | |
---|
1282 | | - ret = -ENODEV; |
---|
1283 | | - retry_cnt = SSIF_RECV_RETRIES; |
---|
1284 | | - while (retry_cnt > 0) { |
---|
1285 | | - ret = i2c_smbus_read_block_data(client, SSIF_IPMI_RESPONSE, |
---|
1286 | | - resp); |
---|
1287 | | - if (ret > 0) |
---|
1288 | | - break; |
---|
1289 | | - msleep(SSIF_MSG_MSEC); |
---|
1290 | | - retry_cnt--; |
---|
1291 | | - if (retry_cnt <= 0) |
---|
1292 | | - break; |
---|
1293 | | - } |
---|
1294 | | - |
---|
| 1385 | + ret = read_response(client, resp); |
---|
1295 | 1386 | if (ret > 0) { |
---|
1296 | 1387 | /* Validate that the response is correct. */ |
---|
1297 | 1388 | if (ret < 3 || |
---|
1298 | 1389 | (resp[0] != (msg[0] | (1 << 2))) || |
---|
1299 | 1390 | (resp[1] != msg[1])) |
---|
1300 | 1391 | ret = -EINVAL; |
---|
1301 | | - else { |
---|
| 1392 | + else if (ret > IPMI_MAX_MSG_LENGTH) { |
---|
| 1393 | + ret = -E2BIG; |
---|
| 1394 | + } else { |
---|
1302 | 1395 | *resp_len = ret; |
---|
1303 | 1396 | ret = 0; |
---|
1304 | 1397 | } |
---|
.. | .. |
---|
1356 | 1449 | restart: |
---|
1357 | 1450 | list_for_each_entry(info, &ssif_infos, link) { |
---|
1358 | 1451 | if (info->binfo.addr == addr) { |
---|
| 1452 | + if (info->addr_src == SI_SMBIOS) |
---|
| 1453 | + info->adapter_name = kstrdup(adapter_name, |
---|
| 1454 | + GFP_KERNEL); |
---|
| 1455 | + |
---|
1359 | 1456 | if (info->adapter_name || adapter_name) { |
---|
1360 | 1457 | if (!info->adapter_name != !adapter_name) { |
---|
1361 | 1458 | /* One is NULL and one is not */ |
---|
.. | .. |
---|
1391 | 1488 | if (acpi_handle) { |
---|
1392 | 1489 | ssif_info->addr_source = SI_ACPI; |
---|
1393 | 1490 | ssif_info->addr_info.acpi_info.acpi_handle = acpi_handle; |
---|
| 1491 | + request_module("acpi_ipmi"); |
---|
1394 | 1492 | return true; |
---|
1395 | 1493 | } |
---|
1396 | 1494 | #endif |
---|
.. | .. |
---|
1410 | 1508 | return slave_addr; |
---|
1411 | 1509 | } |
---|
1412 | 1510 | |
---|
| 1511 | +static int start_multipart_test(struct i2c_client *client, |
---|
| 1512 | + unsigned char *msg, bool do_middle) |
---|
| 1513 | +{ |
---|
| 1514 | + int retry_cnt = SSIF_SEND_RETRIES, ret; |
---|
| 1515 | + |
---|
| 1516 | +retry_write: |
---|
| 1517 | + ret = i2c_smbus_write_block_data(client, |
---|
| 1518 | + SSIF_IPMI_MULTI_PART_REQUEST_START, |
---|
| 1519 | + 32, msg); |
---|
| 1520 | + if (ret) { |
---|
| 1521 | + retry_cnt--; |
---|
| 1522 | + if (retry_cnt > 0) |
---|
| 1523 | + goto retry_write; |
---|
| 1524 | + 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"); |
---|
| 1525 | + return ret; |
---|
| 1526 | + } |
---|
| 1527 | + |
---|
| 1528 | + if (!do_middle) |
---|
| 1529 | + return 0; |
---|
| 1530 | + |
---|
| 1531 | + ret = i2c_smbus_write_block_data(client, |
---|
| 1532 | + SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE, |
---|
| 1533 | + 32, msg + 32); |
---|
| 1534 | + if (ret) { |
---|
| 1535 | + 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"); |
---|
| 1536 | + return ret; |
---|
| 1537 | + } |
---|
| 1538 | + |
---|
| 1539 | + return 0; |
---|
| 1540 | +} |
---|
| 1541 | + |
---|
| 1542 | +static void test_multipart_messages(struct i2c_client *client, |
---|
| 1543 | + struct ssif_info *ssif_info, |
---|
| 1544 | + unsigned char *resp) |
---|
| 1545 | +{ |
---|
| 1546 | + unsigned char msg[65]; |
---|
| 1547 | + int ret; |
---|
| 1548 | + bool do_middle; |
---|
| 1549 | + |
---|
| 1550 | + if (ssif_info->max_xmit_msg_size <= 32) |
---|
| 1551 | + return; |
---|
| 1552 | + |
---|
| 1553 | + do_middle = ssif_info->max_xmit_msg_size > 63; |
---|
| 1554 | + |
---|
| 1555 | + memset(msg, 0, sizeof(msg)); |
---|
| 1556 | + msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
---|
| 1557 | + msg[1] = IPMI_GET_DEVICE_ID_CMD; |
---|
| 1558 | + |
---|
| 1559 | + /* |
---|
| 1560 | + * The specification is all messed up dealing with sending |
---|
| 1561 | + * multi-part messages. Per what the specification says, it |
---|
| 1562 | + * is impossible to send a message that is a multiple of 32 |
---|
| 1563 | + * bytes, except for 32 itself. It talks about a "start" |
---|
| 1564 | + * transaction (cmd=6) that must be 32 bytes, "middle" |
---|
| 1565 | + * transaction (cmd=7) that must be 32 bytes, and an "end" |
---|
| 1566 | + * transaction. The "end" transaction is shown as cmd=7 in |
---|
| 1567 | + * the text, but if that's the case there is no way to |
---|
| 1568 | + * differentiate between a middle and end part except the |
---|
| 1569 | + * length being less than 32. But there is a table at the far |
---|
| 1570 | + * end of the section (that I had never noticed until someone |
---|
| 1571 | + * pointed it out to me) that mentions it as cmd=8. |
---|
| 1572 | + * |
---|
| 1573 | + * After some thought, I think the example is wrong and the |
---|
| 1574 | + * end transaction should be cmd=8. But some systems don't |
---|
| 1575 | + * implement cmd=8, they use a zero-length end transaction, |
---|
| 1576 | + * even though that violates the SMBus specification. |
---|
| 1577 | + * |
---|
| 1578 | + * So, to work around this, this code tests if cmd=8 works. |
---|
| 1579 | + * If it does, then we use that. If not, it tests zero- |
---|
| 1580 | + * byte end transactions. If that works, good. If not, |
---|
| 1581 | + * we only allow 63-byte transactions max. |
---|
| 1582 | + */ |
---|
| 1583 | + |
---|
| 1584 | + ret = start_multipart_test(client, msg, do_middle); |
---|
| 1585 | + if (ret) |
---|
| 1586 | + goto out_no_multi_part; |
---|
| 1587 | + |
---|
| 1588 | + ret = i2c_smbus_write_block_data(client, |
---|
| 1589 | + SSIF_IPMI_MULTI_PART_REQUEST_END, |
---|
| 1590 | + 1, msg + 64); |
---|
| 1591 | + |
---|
| 1592 | + if (!ret) |
---|
| 1593 | + ret = read_response(client, resp); |
---|
| 1594 | + |
---|
| 1595 | + if (ret > 0) { |
---|
| 1596 | + /* End transactions work, we are good. */ |
---|
| 1597 | + ssif_info->cmd8_works = true; |
---|
| 1598 | + return; |
---|
| 1599 | + } |
---|
| 1600 | + |
---|
| 1601 | + ret = start_multipart_test(client, msg, do_middle); |
---|
| 1602 | + if (ret) { |
---|
| 1603 | + dev_err(&client->dev, "Second multipart test failed.\n"); |
---|
| 1604 | + goto out_no_multi_part; |
---|
| 1605 | + } |
---|
| 1606 | + |
---|
| 1607 | + ret = i2c_smbus_write_block_data(client, |
---|
| 1608 | + SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE, |
---|
| 1609 | + 0, msg + 64); |
---|
| 1610 | + if (!ret) |
---|
| 1611 | + ret = read_response(client, resp); |
---|
| 1612 | + if (ret > 0) |
---|
| 1613 | + /* Zero-size end parts work, use those. */ |
---|
| 1614 | + return; |
---|
| 1615 | + |
---|
| 1616 | + /* Limit to 63 bytes and use a short middle command to mark the end. */ |
---|
| 1617 | + if (ssif_info->max_xmit_msg_size > 63) |
---|
| 1618 | + ssif_info->max_xmit_msg_size = 63; |
---|
| 1619 | + return; |
---|
| 1620 | + |
---|
| 1621 | +out_no_multi_part: |
---|
| 1622 | + ssif_info->max_xmit_msg_size = 32; |
---|
| 1623 | + return; |
---|
| 1624 | +} |
---|
| 1625 | + |
---|
1413 | 1626 | /* |
---|
1414 | 1627 | * Global enables we care about. |
---|
1415 | 1628 | */ |
---|
1416 | 1629 | #define GLOBAL_ENABLES_MASK (IPMI_BMC_EVT_MSG_BUFF | IPMI_BMC_RCV_MSG_INTR | \ |
---|
1417 | 1630 | IPMI_BMC_EVT_MSG_INTR) |
---|
| 1631 | + |
---|
| 1632 | +static void ssif_remove_dup(struct i2c_client *client) |
---|
| 1633 | +{ |
---|
| 1634 | + struct ssif_info *ssif_info = i2c_get_clientdata(client); |
---|
| 1635 | + |
---|
| 1636 | + ipmi_unregister_smi(ssif_info->intf); |
---|
| 1637 | + kfree(ssif_info); |
---|
| 1638 | +} |
---|
| 1639 | + |
---|
| 1640 | +static int ssif_add_infos(struct i2c_client *client) |
---|
| 1641 | +{ |
---|
| 1642 | + struct ssif_addr_info *info; |
---|
| 1643 | + |
---|
| 1644 | + info = kzalloc(sizeof(*info), GFP_KERNEL); |
---|
| 1645 | + if (!info) |
---|
| 1646 | + return -ENOMEM; |
---|
| 1647 | + info->addr_src = SI_ACPI; |
---|
| 1648 | + info->client = client; |
---|
| 1649 | + info->adapter_name = kstrdup(client->adapter->name, GFP_KERNEL); |
---|
| 1650 | + info->binfo.addr = client->addr; |
---|
| 1651 | + list_add_tail(&info->link, &ssif_infos); |
---|
| 1652 | + return 0; |
---|
| 1653 | +} |
---|
| 1654 | + |
---|
| 1655 | +/* |
---|
| 1656 | + * Prefer ACPI over SMBIOS, if both are available. |
---|
| 1657 | + * So if we get an ACPI interface and have already registered a SMBIOS |
---|
| 1658 | + * interface at the same address, remove the SMBIOS and add the ACPI one. |
---|
| 1659 | + */ |
---|
| 1660 | +static int ssif_check_and_remove(struct i2c_client *client, |
---|
| 1661 | + struct ssif_info *ssif_info) |
---|
| 1662 | +{ |
---|
| 1663 | + struct ssif_addr_info *info; |
---|
| 1664 | + |
---|
| 1665 | + list_for_each_entry(info, &ssif_infos, link) { |
---|
| 1666 | + if (!info->client) |
---|
| 1667 | + return 0; |
---|
| 1668 | + if (!strcmp(info->adapter_name, client->adapter->name) && |
---|
| 1669 | + info->binfo.addr == client->addr) { |
---|
| 1670 | + if (info->addr_src == SI_ACPI) |
---|
| 1671 | + return -EEXIST; |
---|
| 1672 | + |
---|
| 1673 | + if (ssif_info->addr_source == SI_ACPI && |
---|
| 1674 | + info->addr_src == SI_SMBIOS) { |
---|
| 1675 | + dev_info(&client->dev, |
---|
| 1676 | + "Removing %s-specified SSIF interface in favor of ACPI\n", |
---|
| 1677 | + ipmi_addr_src_to_str(info->addr_src)); |
---|
| 1678 | + ssif_remove_dup(info->client); |
---|
| 1679 | + return 0; |
---|
| 1680 | + } |
---|
| 1681 | + } |
---|
| 1682 | + } |
---|
| 1683 | + return 0; |
---|
| 1684 | +} |
---|
1418 | 1685 | |
---|
1419 | 1686 | static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) |
---|
1420 | 1687 | { |
---|
.. | .. |
---|
1427 | 1694 | u8 slave_addr = 0; |
---|
1428 | 1695 | struct ssif_addr_info *addr_info = NULL; |
---|
1429 | 1696 | |
---|
| 1697 | + mutex_lock(&ssif_infos_mutex); |
---|
1430 | 1698 | resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); |
---|
1431 | | - if (!resp) |
---|
| 1699 | + if (!resp) { |
---|
| 1700 | + mutex_unlock(&ssif_infos_mutex); |
---|
1432 | 1701 | return -ENOMEM; |
---|
| 1702 | + } |
---|
1433 | 1703 | |
---|
1434 | 1704 | ssif_info = kzalloc(sizeof(*ssif_info), GFP_KERNEL); |
---|
1435 | 1705 | if (!ssif_info) { |
---|
1436 | 1706 | kfree(resp); |
---|
| 1707 | + mutex_unlock(&ssif_infos_mutex); |
---|
1437 | 1708 | return -ENOMEM; |
---|
1438 | 1709 | } |
---|
1439 | 1710 | |
---|
.. | .. |
---|
1452 | 1723 | } |
---|
1453 | 1724 | } |
---|
1454 | 1725 | |
---|
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 | | - |
---|
1461 | 1726 | ssif_info->client = client; |
---|
1462 | 1727 | i2c_set_clientdata(client, ssif_info); |
---|
| 1728 | + |
---|
| 1729 | + rv = ssif_check_and_remove(client, ssif_info); |
---|
| 1730 | + /* If rv is 0 and addr source is not SI_ACPI, continue probing */ |
---|
| 1731 | + if (!rv && ssif_info->addr_source == SI_ACPI) { |
---|
| 1732 | + rv = ssif_add_infos(client); |
---|
| 1733 | + if (rv) { |
---|
| 1734 | + dev_err(&client->dev, "Out of memory!, exiting ..\n"); |
---|
| 1735 | + goto out; |
---|
| 1736 | + } |
---|
| 1737 | + } else if (rv) { |
---|
| 1738 | + dev_err(&client->dev, "Not probing, Interface already present\n"); |
---|
| 1739 | + goto out; |
---|
| 1740 | + } |
---|
| 1741 | + |
---|
| 1742 | + slave_addr = find_slave_address(client, slave_addr); |
---|
| 1743 | + |
---|
| 1744 | + dev_info(&client->dev, |
---|
| 1745 | + "Trying %s-specified SSIF interface at i2c address 0x%x, adapter %s, slave address 0x%x\n", |
---|
| 1746 | + ipmi_addr_src_to_str(ssif_info->addr_source), |
---|
| 1747 | + client->addr, client->adapter->name, slave_addr); |
---|
1463 | 1748 | |
---|
1464 | 1749 | /* Now check for system interface capabilities */ |
---|
1465 | 1750 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
---|
.. | .. |
---|
1469 | 1754 | if (!rv && (len >= 3) && (resp[2] == 0)) { |
---|
1470 | 1755 | if (len < 7) { |
---|
1471 | 1756 | if (ssif_dbg_probe) |
---|
1472 | | - pr_info(PFX "SSIF info too short: %d\n", len); |
---|
| 1757 | + dev_dbg(&ssif_info->client->dev, |
---|
| 1758 | + "SSIF info too short: %d\n", len); |
---|
1473 | 1759 | goto no_support; |
---|
1474 | 1760 | } |
---|
1475 | 1761 | |
---|
.. | .. |
---|
1496 | 1782 | break; |
---|
1497 | 1783 | |
---|
1498 | 1784 | 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; |
---|
| 1785 | + /* We take whatever size given, but do some testing. */ |
---|
1519 | 1786 | break; |
---|
1520 | 1787 | |
---|
1521 | 1788 | default: |
---|
.. | .. |
---|
1525 | 1792 | } else { |
---|
1526 | 1793 | no_support: |
---|
1527 | 1794 | /* 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]); |
---|
| 1795 | + dev_info(&ssif_info->client->dev, |
---|
| 1796 | + "Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n", |
---|
| 1797 | + rv, len, resp[2]); |
---|
1530 | 1798 | |
---|
1531 | 1799 | ssif_info->max_xmit_msg_size = 32; |
---|
1532 | 1800 | ssif_info->max_recv_msg_size = 32; |
---|
.. | .. |
---|
1534 | 1802 | ssif_info->supports_pec = 0; |
---|
1535 | 1803 | } |
---|
1536 | 1804 | |
---|
| 1805 | + test_multipart_messages(client, ssif_info, resp); |
---|
| 1806 | + |
---|
1537 | 1807 | /* Make sure the NMI timeout is cleared. */ |
---|
1538 | 1808 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
---|
1539 | 1809 | msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD; |
---|
1540 | 1810 | msg[2] = WDT_PRE_TIMEOUT_INT; |
---|
1541 | 1811 | rv = do_cmd(client, 3, msg, &len, resp); |
---|
1542 | 1812 | 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]); |
---|
| 1813 | + dev_warn(&ssif_info->client->dev, |
---|
| 1814 | + "Unable to clear message flags: %d %d %2.2x\n", |
---|
| 1815 | + rv, len, resp[2]); |
---|
1545 | 1816 | |
---|
1546 | 1817 | /* Attempt to enable the event buffer. */ |
---|
1547 | 1818 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
---|
1548 | 1819 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; |
---|
1549 | 1820 | rv = do_cmd(client, 2, msg, &len, resp); |
---|
1550 | 1821 | 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]); |
---|
| 1822 | + dev_warn(&ssif_info->client->dev, |
---|
| 1823 | + "Error getting global enables: %d %d %2.2x\n", |
---|
| 1824 | + rv, len, resp[2]); |
---|
1553 | 1825 | rv = 0; /* Not fatal */ |
---|
1554 | 1826 | goto found; |
---|
1555 | 1827 | } |
---|
.. | .. |
---|
1567 | 1839 | msg[2] = ssif_info->global_enables | IPMI_BMC_EVT_MSG_BUFF; |
---|
1568 | 1840 | rv = do_cmd(client, 3, msg, &len, resp); |
---|
1569 | 1841 | if (rv || (len < 2)) { |
---|
1570 | | - pr_warn(PFX "Error setting global enables: %d %d %2.2x\n", |
---|
1571 | | - rv, len, resp[2]); |
---|
| 1842 | + dev_warn(&ssif_info->client->dev, |
---|
| 1843 | + "Error setting global enables: %d %d %2.2x\n", |
---|
| 1844 | + rv, len, resp[2]); |
---|
1572 | 1845 | rv = 0; /* Not fatal */ |
---|
1573 | 1846 | goto found; |
---|
1574 | 1847 | } |
---|
.. | .. |
---|
1588 | 1861 | msg[2] = ssif_info->global_enables | IPMI_BMC_RCV_MSG_INTR; |
---|
1589 | 1862 | rv = do_cmd(client, 3, msg, &len, resp); |
---|
1590 | 1863 | if (rv || (len < 2)) { |
---|
1591 | | - pr_warn(PFX "Error setting global enables: %d %d %2.2x\n", |
---|
1592 | | - rv, len, resp[2]); |
---|
| 1864 | + dev_warn(&ssif_info->client->dev, |
---|
| 1865 | + "Error setting global enables: %d %d %2.2x\n", |
---|
| 1866 | + rv, len, resp[2]); |
---|
1593 | 1867 | rv = 0; /* Not fatal */ |
---|
1594 | 1868 | goto found; |
---|
1595 | 1869 | } |
---|
.. | .. |
---|
1602 | 1876 | |
---|
1603 | 1877 | found: |
---|
1604 | 1878 | if (ssif_dbg_probe) { |
---|
1605 | | - pr_info("ssif_probe: i2c_probe found device at i2c address %x\n", |
---|
1606 | | - client->addr); |
---|
| 1879 | + dev_dbg(&ssif_info->client->dev, |
---|
| 1880 | + "%s: i2c_probe found device at i2c address %x\n", |
---|
| 1881 | + __func__, client->addr); |
---|
1607 | 1882 | } |
---|
1608 | 1883 | |
---|
1609 | 1884 | spin_lock_init(&ssif_info->lock); |
---|
1610 | 1885 | ssif_info->ssif_state = SSIF_NORMAL; |
---|
1611 | 1886 | timer_setup(&ssif_info->retry_timer, retry_timeout, 0); |
---|
| 1887 | + timer_setup(&ssif_info->watch_timer, watch_timeout, 0); |
---|
1612 | 1888 | |
---|
1613 | 1889 | for (i = 0; i < SSIF_NUM_STATS; i++) |
---|
1614 | 1890 | atomic_set(&ssif_info->stats[i], 0); |
---|
.. | .. |
---|
1622 | 1898 | ssif_info->handlers.get_smi_info = get_smi_info; |
---|
1623 | 1899 | ssif_info->handlers.sender = sender; |
---|
1624 | 1900 | ssif_info->handlers.request_events = request_events; |
---|
| 1901 | + ssif_info->handlers.set_need_watch = ssif_set_need_watch; |
---|
1625 | 1902 | |
---|
1626 | 1903 | { |
---|
1627 | 1904 | unsigned int thread_num; |
---|
.. | .. |
---|
1655 | 1932 | ssif_info, |
---|
1656 | 1933 | &ssif_info->client->dev, |
---|
1657 | 1934 | slave_addr); |
---|
1658 | | - if (rv) { |
---|
1659 | | - pr_err(PFX "Unable to register device: error %d\n", rv); |
---|
| 1935 | + if (rv) { |
---|
| 1936 | + dev_err(&ssif_info->client->dev, |
---|
| 1937 | + "Unable to register device: error %d\n", rv); |
---|
1660 | 1938 | goto out_remove_attr; |
---|
1661 | 1939 | } |
---|
1662 | 1940 | |
---|
.. | .. |
---|
1665 | 1943 | if (addr_info) |
---|
1666 | 1944 | addr_info->client = NULL; |
---|
1667 | 1945 | |
---|
1668 | | - dev_err(&client->dev, "Unable to start IPMI SSIF: %d\n", rv); |
---|
| 1946 | + dev_err(&ssif_info->client->dev, |
---|
| 1947 | + "Unable to start IPMI SSIF: %d\n", rv); |
---|
| 1948 | + i2c_set_clientdata(client, NULL); |
---|
1669 | 1949 | kfree(ssif_info); |
---|
1670 | 1950 | } |
---|
1671 | 1951 | kfree(resp); |
---|
| 1952 | + mutex_unlock(&ssif_infos_mutex); |
---|
1672 | 1953 | return rv; |
---|
1673 | 1954 | |
---|
1674 | 1955 | out_remove_attr: |
---|
1675 | 1956 | device_remove_group(&ssif_info->client->dev, &ipmi_ssif_dev_attr_group); |
---|
1676 | 1957 | dev_set_drvdata(&ssif_info->client->dev, NULL); |
---|
1677 | 1958 | 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; |
---|
1693 | 1959 | } |
---|
1694 | 1960 | |
---|
1695 | 1961 | static int new_ssif_client(int addr, char *adapter_name, |
---|
.. | .. |
---|
1735 | 2001 | |
---|
1736 | 2002 | list_add_tail(&addr_info->link, &ssif_infos); |
---|
1737 | 2003 | |
---|
1738 | | - if (initialized) |
---|
1739 | | - i2c_for_each_dev(addr_info, ssif_adapter_handler); |
---|
1740 | | - /* Otherwise address list will get it */ |
---|
| 2004 | + /* Address list will get it */ |
---|
1741 | 2005 | |
---|
1742 | 2006 | out_unlock: |
---|
1743 | 2007 | mutex_unlock(&ssif_infos_mutex); |
---|
.. | .. |
---|
1760 | 2024 | static unsigned short *ssif_address_list(void) |
---|
1761 | 2025 | { |
---|
1762 | 2026 | struct ssif_addr_info *info; |
---|
1763 | | - unsigned int count = 0, i; |
---|
| 2027 | + unsigned int count = 0, i = 0; |
---|
1764 | 2028 | unsigned short *address_list; |
---|
1765 | 2029 | |
---|
1766 | 2030 | list_for_each_entry(info, &ssif_infos, link) |
---|
.. | .. |
---|
1771 | 2035 | if (!address_list) |
---|
1772 | 2036 | return NULL; |
---|
1773 | 2037 | |
---|
1774 | | - i = 0; |
---|
1775 | 2038 | list_for_each_entry(info, &ssif_infos, link) { |
---|
1776 | 2039 | unsigned short addr = info->binfo.addr; |
---|
1777 | 2040 | int j; |
---|
1778 | 2041 | |
---|
1779 | 2042 | for (j = 0; j < i; j++) { |
---|
1780 | 2043 | if (address_list[j] == addr) |
---|
1781 | | - goto skip_addr; |
---|
| 2044 | + /* Found a dup. */ |
---|
| 2045 | + break; |
---|
1782 | 2046 | } |
---|
1783 | | - address_list[i] = addr; |
---|
1784 | | -skip_addr: |
---|
1785 | | - i++; |
---|
| 2047 | + if (j == i) /* Didn't find it in the list. */ |
---|
| 2048 | + address_list[i++] = addr; |
---|
1786 | 2049 | } |
---|
1787 | 2050 | address_list[i] = I2C_CLIENT_END; |
---|
1788 | 2051 | |
---|
.. | .. |
---|
1809 | 2072 | |
---|
1810 | 2073 | rv = device_property_read_u16(&pdev->dev, "i2c-addr", &i2c_addr); |
---|
1811 | 2074 | if (rv) { |
---|
1812 | | - dev_warn(&pdev->dev, PFX "No i2c-addr property\n"); |
---|
| 2075 | + dev_warn(&pdev->dev, "No i2c-addr property\n"); |
---|
1813 | 2076 | return -ENODEV; |
---|
1814 | 2077 | } |
---|
1815 | 2078 | |
---|
1816 | 2079 | rv = device_property_read_u8(&pdev->dev, "slave-addr", &slave_addr); |
---|
1817 | 2080 | if (rv) |
---|
1818 | | - dev_warn(&pdev->dev, "device has no slave-addr property"); |
---|
| 2081 | + slave_addr = 0x20; |
---|
1819 | 2082 | |
---|
1820 | 2083 | return new_ssif_client(i2c_addr, NULL, 0, |
---|
1821 | 2084 | slave_addr, SI_SMBIOS, &pdev->dev); |
---|
.. | .. |
---|
1858 | 2121 | return 0; |
---|
1859 | 2122 | |
---|
1860 | 2123 | mutex_lock(&ssif_infos_mutex); |
---|
1861 | | - i2c_unregister_device(addr_info->added_client); |
---|
1862 | | - |
---|
1863 | 2124 | list_del(&addr_info->link); |
---|
1864 | 2125 | kfree(addr_info); |
---|
1865 | 2126 | mutex_unlock(&ssif_infos_mutex); |
---|
1866 | 2127 | return 0; |
---|
1867 | 2128 | } |
---|
| 2129 | + |
---|
| 2130 | +static const struct platform_device_id ssif_plat_ids[] = { |
---|
| 2131 | + { "dmi-ipmi-ssif", 0 }, |
---|
| 2132 | + { } |
---|
| 2133 | +}; |
---|
1868 | 2134 | |
---|
1869 | 2135 | static struct platform_driver ipmi_driver = { |
---|
1870 | 2136 | .driver = { |
---|
.. | .. |
---|
1872 | 2138 | }, |
---|
1873 | 2139 | .probe = ssif_platform_probe, |
---|
1874 | 2140 | .remove = ssif_platform_remove, |
---|
| 2141 | + .id_table = ssif_plat_ids |
---|
1875 | 2142 | }; |
---|
1876 | 2143 | |
---|
1877 | 2144 | static int init_ipmi_ssif(void) |
---|
.. | .. |
---|
1890 | 2157 | dbg[i], slave_addrs[i], |
---|
1891 | 2158 | SI_HARDCODED, NULL); |
---|
1892 | 2159 | if (rv) |
---|
1893 | | - pr_err(PFX |
---|
1894 | | - "Couldn't add hardcoded device at addr 0x%x\n", |
---|
| 2160 | + pr_err("Couldn't add hardcoded device at addr 0x%x\n", |
---|
1895 | 2161 | addr[i]); |
---|
1896 | 2162 | } |
---|
1897 | 2163 | |
---|
.. | .. |
---|
1902 | 2168 | if (ssif_trydmi) { |
---|
1903 | 2169 | rv = platform_driver_register(&ipmi_driver); |
---|
1904 | 2170 | if (rv) |
---|
1905 | | - pr_err(PFX "Unable to register driver: %d\n", rv); |
---|
| 2171 | + pr_err("Unable to register driver: %d\n", rv); |
---|
| 2172 | + else |
---|
| 2173 | + platform_registered = true; |
---|
1906 | 2174 | } |
---|
1907 | 2175 | |
---|
1908 | 2176 | ssif_i2c_driver.address_list = ssif_address_list(); |
---|
.. | .. |
---|
1924 | 2192 | |
---|
1925 | 2193 | i2c_del_driver(&ssif_i2c_driver); |
---|
1926 | 2194 | |
---|
1927 | | - platform_driver_unregister(&ipmi_driver); |
---|
| 2195 | + kfree(ssif_i2c_driver.address_list); |
---|
| 2196 | + |
---|
| 2197 | + if (ssif_trydmi && platform_registered) |
---|
| 2198 | + platform_driver_unregister(&ipmi_driver); |
---|
1928 | 2199 | |
---|
1929 | 2200 | free_ssif_clients(); |
---|
1930 | 2201 | } |
---|