4 * The interface to the IPMI driver for SMBus access to a SMBus
5 * compliant device. Called SSIF by the IPMI spec.
7 * Author: Intel Corporation
8 * Todd Davis <todd.c.davis@intel.com>
10 * Rewritten by Corey Minyard <minyard@acm.org> to support the
11 * non-blocking I2C interface, add support for multi-part
12 * transactions, add PEC support, and general clenaup.
14 * Copyright 2003 Intel Corporation
15 * Copyright 2005 MontaVista Software
17 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the
19 * Free Software Foundation; either version 2 of the License, or (at your
20 * option) any later version.
24 * This file holds the "policy" for the interface to the SSIF state
25 * machine. It does the configuration, handles timers and interrupts,
26 * and drives the real SSIF state machine.
30 * TODO: Figure out how to use SMB alerts. This will require a new
31 * interface into the I2C driver, I believe.
34 #include <linux/version.h>
35 #if defined(MODVERSIONS)
36 #include <linux/modversions.h>
39 #include <linux/module.h>
40 #include <linux/moduleparam.h>
41 #include <linux/sched.h>
42 #include <linux/seq_file.h>
43 #include <linux/timer.h>
44 #include <linux/delay.h>
45 #include <linux/errno.h>
46 #include <linux/spinlock.h>
47 #include <linux/slab.h>
48 #include <linux/list.h>
49 #include <linux/i2c.h>
50 #include <linux/ipmi_smi.h>
51 #include <linux/init.h>
52 #include <linux/dmi.h>
53 #include <linux/kthread.h>
54 #include <linux/acpi.h>
55 #include <linux/ctype.h>
57 #define PFX "ipmi_ssif: "
58 #define DEVICE_NAME "ipmi_ssif"
60 #define IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_CMD 0x57
62 #define SSIF_IPMI_REQUEST 2
63 #define SSIF_IPMI_MULTI_PART_REQUEST_START 6
64 #define SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE 7
65 #define SSIF_IPMI_RESPONSE 3
66 #define SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE 9
68 /* ssif_debug is a bit-field
69 * SSIF_DEBUG_MSG - commands and their responses
70 * SSIF_DEBUG_STATES - message states
71 * SSIF_DEBUG_TIMING - Measure times between events in the driver
73 #define SSIF_DEBUG_TIMING 4
74 #define SSIF_DEBUG_STATE 2
75 #define SSIF_DEBUG_MSG 1
76 #define SSIF_NODEBUG 0
77 #define SSIF_DEFAULT_DEBUG (SSIF_NODEBUG)
82 #define SSIF_MSG_USEC 20000 /* 20ms between message tries. */
83 #define SSIF_MSG_PART_USEC 5000 /* 5ms for a message part */
85 /* How many times to we retry sending/receiving the message. */
86 #define SSIF_SEND_RETRIES 5
87 #define SSIF_RECV_RETRIES 250
89 #define SSIF_MSG_MSEC (SSIF_MSG_USEC / 1000)
90 #define SSIF_MSG_JIFFIES ((SSIF_MSG_USEC * 1000) / TICK_NSEC)
91 #define SSIF_MSG_PART_JIFFIES ((SSIF_MSG_PART_USEC * 1000) / TICK_NSEC)
93 enum ssif_intf_state {
98 SSIF_GETTING_MESSAGES,
99 /* FIXME - add watchdog stuff. */
102 #define SSIF_IDLE(ssif) ((ssif)->ssif_state == SSIF_NORMAL \
103 && (ssif)->curr_msg == NULL)
106 * Indexes into stats[] in ssif_info below.
108 enum ssif_stat_indexes {
109 /* Number of total messages sent. */
110 SSIF_STAT_sent_messages = 0,
113 * Number of message parts sent. Messages may be broken into
114 * parts if they are long.
116 SSIF_STAT_sent_messages_parts,
119 * Number of time a message was retried.
121 SSIF_STAT_send_retries,
124 * Number of times the send of a message failed.
126 SSIF_STAT_send_errors,
129 * Number of message responses received.
131 SSIF_STAT_received_messages,
134 * Number of message fragments received.
136 SSIF_STAT_received_message_parts,
139 * Number of times the receive of a message was retried.
141 SSIF_STAT_receive_retries,
144 * Number of errors receiving messages.
146 SSIF_STAT_receive_errors,
149 * Number of times a flag fetch was requested.
151 SSIF_STAT_flag_fetches,
154 * Number of times the hardware didn't follow the state machine.
159 * Number of received events.
163 /* Number of asyncronous messages received. */
164 SSIF_STAT_incoming_messages,
166 /* Number of watchdog pretimeouts. */
167 SSIF_STAT_watchdog_pretimeouts,
169 /* Always add statistics before this value, it must be last. */
173 struct ssif_addr_info {
175 struct i2c_board_info binfo;
179 enum ipmi_addr_src addr_src;
180 union ipmi_smi_info_union addr_info;
182 struct mutex clients_mutex;
183 struct list_head clients;
185 struct list_head link;
190 typedef void (*ssif_i2c_done)(struct ssif_info *ssif_info, int result,
191 unsigned char *data, unsigned int len);
197 struct ipmi_smi_msg *waiting_msg;
198 struct ipmi_smi_msg *curr_msg;
199 enum ssif_intf_state ssif_state;
200 unsigned long ssif_debug;
202 struct ipmi_smi_handlers handlers;
204 enum ipmi_addr_src addr_source; /* ACPI, PCI, SMBIOS, hardcode, etc. */
205 union ipmi_smi_info_union addr_info;
208 * Flags from the last GET_MSG_FLAGS command, used when an ATTN
209 * is set to hold the flags until we are done handling everything
212 #define RECEIVE_MSG_AVAIL 0x01
213 #define EVENT_MSG_BUFFER_FULL 0x02
214 #define WDT_PRE_TIMEOUT_INT 0x08
215 unsigned char msg_flags;
217 bool has_event_buffer;
220 * If set to true, this will request events the next time the
221 * state machine is idle.
226 * If set to true, this will request flags the next time the
227 * state machine is idle.
232 * Used to perform timer operations when run-to-completion
233 * mode is on. This is a countdown timer.
237 /* Used for sending/receiving data. +1 for the length. */
238 unsigned char data[IPMI_MAX_MSG_LENGTH + 1];
239 unsigned int data_len;
241 /* Temp receive buffer, gets copied into data. */
242 unsigned char recv[I2C_SMBUS_BLOCK_MAX];
244 struct i2c_client *client;
245 ssif_i2c_done done_handler;
247 /* Thread interface handling */
248 struct task_struct *thread;
249 struct completion wake_thread;
253 unsigned char *i2c_data;
254 unsigned int i2c_size;
256 /* From the device id response. */
257 struct ipmi_device_id device_id;
259 struct timer_list retry_timer;
262 /* Info from SSIF cmd */
263 unsigned char max_xmit_msg_size;
264 unsigned char max_recv_msg_size;
265 unsigned int multi_support;
268 #define SSIF_NO_MULTI 0
269 #define SSIF_MULTI_2_PART 1
270 #define SSIF_MULTI_n_PART 2
271 unsigned char *multi_data;
272 unsigned int multi_len;
273 unsigned int multi_pos;
275 atomic_t stats[SSIF_NUM_STATS];
278 #define ssif_inc_stat(ssif, stat) \
279 atomic_inc(&(ssif)->stats[SSIF_STAT_ ## stat])
280 #define ssif_get_stat(ssif, stat) \
281 ((unsigned int) atomic_read(&(ssif)->stats[SSIF_STAT_ ## stat]))
283 static bool initialized;
285 static atomic_t next_intf = ATOMIC_INIT(0);
287 static void return_hosed_msg(struct ssif_info *ssif_info,
288 struct ipmi_smi_msg *msg);
289 static void start_next_msg(struct ssif_info *ssif_info, unsigned long *flags);
290 static int start_send(struct ssif_info *ssif_info,
294 static unsigned long *ipmi_ssif_lock_cond(struct ssif_info *ssif_info,
295 unsigned long *flags)
297 spin_lock_irqsave(&ssif_info->lock, *flags);
301 static void ipmi_ssif_unlock_cond(struct ssif_info *ssif_info,
302 unsigned long *flags)
304 spin_unlock_irqrestore(&ssif_info->lock, *flags);
307 static void deliver_recv_msg(struct ssif_info *ssif_info,
308 struct ipmi_smi_msg *msg)
310 ipmi_smi_t intf = ssif_info->intf;
313 ipmi_free_smi_msg(msg);
314 } else if (msg->rsp_size < 0) {
315 return_hosed_msg(ssif_info, msg);
317 "Malformed message in deliver_recv_msg: rsp_size = %d\n",
320 ipmi_smi_msg_received(intf, msg);
324 static void return_hosed_msg(struct ssif_info *ssif_info,
325 struct ipmi_smi_msg *msg)
327 ssif_inc_stat(ssif_info, hosed);
329 /* Make it a response */
330 msg->rsp[0] = msg->data[0] | 4;
331 msg->rsp[1] = msg->data[1];
332 msg->rsp[2] = 0xFF; /* Unknown error. */
335 deliver_recv_msg(ssif_info, msg);
339 * Must be called with the message lock held. This will release the
340 * message lock. Note that the caller will check SSIF_IDLE and start a
341 * new operation, so there is no need to check for new messages to
344 static void start_clear_flags(struct ssif_info *ssif_info, unsigned long *flags)
346 unsigned char msg[3];
348 ssif_info->msg_flags &= ~WDT_PRE_TIMEOUT_INT;
349 ssif_info->ssif_state = SSIF_CLEARING_FLAGS;
350 ipmi_ssif_unlock_cond(ssif_info, flags);
352 /* Make sure the watchdog pre-timeout flag is not set at startup. */
353 msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
354 msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD;
355 msg[2] = WDT_PRE_TIMEOUT_INT;
357 if (start_send(ssif_info, msg, 3) != 0) {
358 /* Error, just go to normal state. */
359 ssif_info->ssif_state = SSIF_NORMAL;
363 static void start_flag_fetch(struct ssif_info *ssif_info, unsigned long *flags)
367 ssif_info->req_flags = false;
368 ssif_info->ssif_state = SSIF_GETTING_FLAGS;
369 ipmi_ssif_unlock_cond(ssif_info, flags);
371 mb[0] = (IPMI_NETFN_APP_REQUEST << 2);
372 mb[1] = IPMI_GET_MSG_FLAGS_CMD;
373 if (start_send(ssif_info, mb, 2) != 0)
374 ssif_info->ssif_state = SSIF_NORMAL;
377 static void check_start_send(struct ssif_info *ssif_info, unsigned long *flags,
378 struct ipmi_smi_msg *msg)
380 if (start_send(ssif_info, msg->data, msg->data_size) != 0) {
381 unsigned long oflags;
383 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
384 ssif_info->curr_msg = NULL;
385 ssif_info->ssif_state = SSIF_NORMAL;
386 ipmi_ssif_unlock_cond(ssif_info, flags);
387 ipmi_free_smi_msg(msg);
391 static void start_event_fetch(struct ssif_info *ssif_info, unsigned long *flags)
393 struct ipmi_smi_msg *msg;
395 ssif_info->req_events = false;
397 msg = ipmi_alloc_smi_msg();
399 ssif_info->ssif_state = SSIF_NORMAL;
403 ssif_info->curr_msg = msg;
404 ssif_info->ssif_state = SSIF_GETTING_EVENTS;
405 ipmi_ssif_unlock_cond(ssif_info, flags);
407 msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
408 msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD;
411 check_start_send(ssif_info, flags, msg);
414 static void start_recv_msg_fetch(struct ssif_info *ssif_info,
415 unsigned long *flags)
417 struct ipmi_smi_msg *msg;
419 msg = ipmi_alloc_smi_msg();
421 ssif_info->ssif_state = SSIF_NORMAL;
425 ssif_info->curr_msg = msg;
426 ssif_info->ssif_state = SSIF_GETTING_MESSAGES;
427 ipmi_ssif_unlock_cond(ssif_info, flags);
429 msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
430 msg->data[1] = IPMI_GET_MSG_CMD;
433 check_start_send(ssif_info, flags, msg);
437 * Must be called with the message lock held. This will release the
438 * message lock. Note that the caller will check SSIF_IDLE and start a
439 * new operation, so there is no need to check for new messages to
442 static void handle_flags(struct ssif_info *ssif_info, unsigned long *flags)
444 if (ssif_info->msg_flags & WDT_PRE_TIMEOUT_INT) {
445 ipmi_smi_t intf = ssif_info->intf;
446 /* Watchdog pre-timeout */
447 ssif_inc_stat(ssif_info, watchdog_pretimeouts);
448 start_clear_flags(ssif_info, flags);
450 ipmi_smi_watchdog_pretimeout(intf);
451 } else if (ssif_info->msg_flags & RECEIVE_MSG_AVAIL)
452 /* Messages available. */
453 start_recv_msg_fetch(ssif_info, flags);
454 else if (ssif_info->msg_flags & EVENT_MSG_BUFFER_FULL)
455 /* Events available. */
456 start_event_fetch(ssif_info, flags);
458 ssif_info->ssif_state = SSIF_NORMAL;
459 ipmi_ssif_unlock_cond(ssif_info, flags);
463 static int ipmi_ssif_thread(void *data)
465 struct ssif_info *ssif_info = data;
467 while (!kthread_should_stop()) {
470 /* Wait for something to do */
471 result = wait_for_completion_interruptible(
472 &ssif_info->wake_thread);
473 if (ssif_info->stopping)
475 if (result == -ERESTARTSYS)
477 init_completion(&ssif_info->wake_thread);
479 if (ssif_info->i2c_read_write == I2C_SMBUS_WRITE) {
480 result = i2c_smbus_write_block_data(
481 ssif_info->client, SSIF_IPMI_REQUEST,
482 ssif_info->i2c_data[0],
483 ssif_info->i2c_data + 1);
484 ssif_info->done_handler(ssif_info, result, NULL, 0);
486 result = i2c_smbus_read_block_data(
487 ssif_info->client, SSIF_IPMI_RESPONSE,
488 ssif_info->i2c_data);
490 ssif_info->done_handler(ssif_info, result,
493 ssif_info->done_handler(ssif_info, 0,
502 static int ssif_i2c_send(struct ssif_info *ssif_info,
503 ssif_i2c_done handler,
504 int read_write, int command,
505 unsigned char *data, unsigned int size)
507 ssif_info->done_handler = handler;
509 ssif_info->i2c_read_write = read_write;
510 ssif_info->i2c_command = command;
511 ssif_info->i2c_data = data;
512 ssif_info->i2c_size = size;
513 complete(&ssif_info->wake_thread);
518 static void msg_done_handler(struct ssif_info *ssif_info, int result,
519 unsigned char *data, unsigned int len);
521 static void retry_timeout(unsigned long data)
523 struct ssif_info *ssif_info = (void *) data;
526 if (ssif_info->stopping)
529 ssif_info->rtc_us_timer = 0;
531 rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
533 ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
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");
539 msg_done_handler(ssif_info, -EIO, NULL, 0);
543 static int start_resend(struct ssif_info *ssif_info);
545 static void msg_done_handler(struct ssif_info *ssif_info, int result,
546 unsigned char *data, unsigned int len)
548 struct ipmi_smi_msg *msg;
549 unsigned long oflags, *flags;
553 * We are single-threaded here, so no need for a lock until we
554 * start messing with driver states or the queues.
558 ssif_info->retries_left--;
559 if (ssif_info->retries_left > 0) {
560 ssif_inc_stat(ssif_info, receive_retries);
562 mod_timer(&ssif_info->retry_timer,
563 jiffies + SSIF_MSG_JIFFIES);
564 ssif_info->rtc_us_timer = SSIF_MSG_USEC;
568 ssif_inc_stat(ssif_info, receive_errors);
570 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
571 pr_info("Error in msg_done_handler: %d\n", result);
576 if ((len > 1) && (ssif_info->multi_pos == 0)
577 && (data[0] == 0x00) && (data[1] == 0x01)) {
578 /* Start of multi-part read. Start the next transaction. */
581 ssif_inc_stat(ssif_info, received_message_parts);
583 /* Remove the multi-part read marker. */
584 for (i = 0; i < (len-2); i++)
585 ssif_info->data[i] = data[i+2];
587 ssif_info->multi_len = len;
588 ssif_info->multi_pos = 1;
590 rv = ssif_i2c_send(ssif_info, msg_done_handler, I2C_SMBUS_READ,
591 SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE,
592 ssif_info->recv, I2C_SMBUS_BLOCK_DATA);
594 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
595 pr_info("Error from i2c_non_blocking_op(1)\n");
600 } else if (ssif_info->multi_pos) {
601 /* Middle of multi-part read. Start the next transaction. */
603 unsigned char blocknum;
607 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
608 pr_info(PFX "Middle message with no data\n");
613 blocknum = data[ssif_info->multi_len];
615 if (ssif_info->multi_len+len-1 > IPMI_MAX_MSG_LENGTH) {
616 /* Received message too big, abort the operation. */
618 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
619 pr_info("Received message too big\n");
624 /* Remove the blocknum from the data. */
625 for (i = 0; i < (len-1); i++)
626 ssif_info->data[i+ssif_info->multi_len] = data[i+1];
628 ssif_info->multi_len += len;
629 if (blocknum == 0xff) {
631 len = ssif_info->multi_len;
632 data = ssif_info->data;
633 } else if ((blocknum+1) != ssif_info->multi_pos) {
635 * Out of sequence block, just abort. Block
636 * numbers start at zero for the second block,
637 * but multi_pos starts at one, so the +1.
641 ssif_inc_stat(ssif_info, received_message_parts);
643 ssif_info->multi_pos++;
645 rv = ssif_i2c_send(ssif_info, msg_done_handler,
647 SSIF_IPMI_MULTI_PART_RESPONSE_MIDDLE,
649 I2C_SMBUS_BLOCK_DATA);
651 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
653 "Error from i2c_non_blocking_op(2)\n");
662 ssif_inc_stat(ssif_info, receive_errors);
664 ssif_inc_stat(ssif_info, received_messages);
665 ssif_inc_stat(ssif_info, received_message_parts);
670 if (ssif_info->ssif_debug & SSIF_DEBUG_STATE)
671 pr_info(PFX "DONE 1: state = %d, result=%d.\n",
672 ssif_info->ssif_state, result);
674 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
675 msg = ssif_info->curr_msg;
678 if (msg->rsp_size > IPMI_MAX_MSG_LENGTH)
679 msg->rsp_size = IPMI_MAX_MSG_LENGTH;
680 memcpy(msg->rsp, data, msg->rsp_size);
681 ssif_info->curr_msg = NULL;
684 switch (ssif_info->ssif_state) {
686 ipmi_ssif_unlock_cond(ssif_info, flags);
691 return_hosed_msg(ssif_info, msg);
693 deliver_recv_msg(ssif_info, msg);
696 case SSIF_GETTING_FLAGS:
697 /* We got the flags from the SSIF, now handle them. */
698 if ((result < 0) || (len < 4) || (data[2] != 0)) {
700 * Error fetching flags, or invalid length,
701 * just give up for now.
703 ssif_info->ssif_state = SSIF_NORMAL;
704 ipmi_ssif_unlock_cond(ssif_info, flags);
705 pr_warn(PFX "Error getting flags: %d %d, %x\n",
706 result, len, data[2]);
707 } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
708 || data[1] != IPMI_GET_MSG_FLAGS_CMD) {
709 pr_warn(PFX "Invalid response getting flags: %x %x\n",
712 ssif_inc_stat(ssif_info, flag_fetches);
713 ssif_info->msg_flags = data[3];
714 handle_flags(ssif_info, flags);
718 case SSIF_CLEARING_FLAGS:
719 /* We cleared the flags. */
720 if ((result < 0) || (len < 3) || (data[2] != 0)) {
721 /* Error clearing flags */
722 pr_warn(PFX "Error clearing flags: %d %d, %x\n",
723 result, len, data[2]);
724 } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
725 || data[1] != IPMI_CLEAR_MSG_FLAGS_CMD) {
726 pr_warn(PFX "Invalid response clearing flags: %x %x\n",
729 ssif_info->ssif_state = SSIF_NORMAL;
730 ipmi_ssif_unlock_cond(ssif_info, flags);
733 case SSIF_GETTING_EVENTS:
734 if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) {
735 /* Error getting event, probably done. */
738 /* Take off the event flag. */
739 ssif_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL;
740 handle_flags(ssif_info, flags);
741 } else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
742 || msg->rsp[1] != IPMI_READ_EVENT_MSG_BUFFER_CMD) {
743 pr_warn(PFX "Invalid response getting events: %x %x\n",
744 msg->rsp[0], msg->rsp[1]);
746 /* Take off the event flag. */
747 ssif_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL;
748 handle_flags(ssif_info, flags);
750 handle_flags(ssif_info, flags);
751 ssif_inc_stat(ssif_info, events);
752 deliver_recv_msg(ssif_info, msg);
756 case SSIF_GETTING_MESSAGES:
757 if ((result < 0) || (len < 3) || (msg->rsp[2] != 0)) {
758 /* Error getting event, probably done. */
761 /* Take off the msg flag. */
762 ssif_info->msg_flags &= ~RECEIVE_MSG_AVAIL;
763 handle_flags(ssif_info, flags);
764 } else if (msg->rsp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2
765 || msg->rsp[1] != IPMI_GET_MSG_CMD) {
766 pr_warn(PFX "Invalid response clearing flags: %x %x\n",
767 msg->rsp[0], msg->rsp[1]);
770 /* Take off the msg flag. */
771 ssif_info->msg_flags &= ~RECEIVE_MSG_AVAIL;
772 handle_flags(ssif_info, flags);
774 ssif_inc_stat(ssif_info, incoming_messages);
775 handle_flags(ssif_info, flags);
776 deliver_recv_msg(ssif_info, msg);
781 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
782 if (SSIF_IDLE(ssif_info) && !ssif_info->stopping) {
783 if (ssif_info->req_events)
784 start_event_fetch(ssif_info, flags);
785 else if (ssif_info->req_flags)
786 start_flag_fetch(ssif_info, flags);
788 start_next_msg(ssif_info, flags);
790 ipmi_ssif_unlock_cond(ssif_info, flags);
792 if (ssif_info->ssif_debug & SSIF_DEBUG_STATE)
793 pr_info(PFX "DONE 2: state = %d.\n", ssif_info->ssif_state);
796 static void msg_written_handler(struct ssif_info *ssif_info, int result,
797 unsigned char *data, unsigned int len)
801 /* We are single-threaded here, so no need for a lock. */
803 ssif_info->retries_left--;
804 if (ssif_info->retries_left > 0) {
805 if (!start_resend(ssif_info)) {
806 ssif_inc_stat(ssif_info, send_retries);
809 /* request failed, just return the error. */
810 ssif_inc_stat(ssif_info, send_errors);
812 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
814 "Out of retries in msg_written_handler\n");
815 msg_done_handler(ssif_info, -EIO, NULL, 0);
819 ssif_inc_stat(ssif_info, send_errors);
822 * Got an error on transmit, let the done routine
825 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
826 pr_info("Error in msg_written_handler: %d\n", result);
828 msg_done_handler(ssif_info, result, NULL, 0);
832 if (ssif_info->multi_data) {
833 /* In the middle of a multi-data write. */
836 ssif_inc_stat(ssif_info, sent_messages_parts);
838 left = ssif_info->multi_len - ssif_info->multi_pos;
842 ssif_info->multi_data[ssif_info->multi_pos] = left;
843 ssif_info->multi_pos += left;
846 * Write is finished. Note that we must end
847 * with a write of less than 32 bytes to
848 * complete the transaction, even if it is
851 ssif_info->multi_data = NULL;
853 rv = ssif_i2c_send(ssif_info, msg_written_handler,
855 SSIF_IPMI_MULTI_PART_REQUEST_MIDDLE,
856 ssif_info->multi_data + ssif_info->multi_pos,
857 I2C_SMBUS_BLOCK_DATA);
859 /* request failed, just return the error. */
860 ssif_inc_stat(ssif_info, send_errors);
862 if (ssif_info->ssif_debug & SSIF_DEBUG_MSG)
863 pr_info("Error from i2c_non_blocking_op(3)\n");
864 msg_done_handler(ssif_info, -EIO, NULL, 0);
867 ssif_inc_stat(ssif_info, sent_messages);
868 ssif_inc_stat(ssif_info, sent_messages_parts);
870 /* Wait a jiffie then request the next message */
871 ssif_info->retries_left = SSIF_RECV_RETRIES;
872 ssif_info->rtc_us_timer = SSIF_MSG_PART_USEC;
873 mod_timer(&ssif_info->retry_timer,
874 jiffies + SSIF_MSG_PART_JIFFIES);
879 static int start_resend(struct ssif_info *ssif_info)
884 if (ssif_info->data_len > 32) {
885 command = SSIF_IPMI_MULTI_PART_REQUEST_START;
886 ssif_info->multi_data = ssif_info->data;
887 ssif_info->multi_len = ssif_info->data_len;
889 * Subtle thing, this is 32, not 33, because we will
890 * overwrite the thing at position 32 (which was just
891 * transmitted) with the new length.
893 ssif_info->multi_pos = 32;
894 ssif_info->data[0] = 32;
896 ssif_info->multi_data = NULL;
897 command = SSIF_IPMI_REQUEST;
898 ssif_info->data[0] = ssif_info->data_len;
901 rv = ssif_i2c_send(ssif_info, msg_written_handler, I2C_SMBUS_WRITE,
902 command, ssif_info->data, I2C_SMBUS_BLOCK_DATA);
903 if (rv && (ssif_info->ssif_debug & SSIF_DEBUG_MSG))
904 pr_info("Error from i2c_non_blocking_op(4)\n");
908 static int start_send(struct ssif_info *ssif_info,
912 if (len > IPMI_MAX_MSG_LENGTH)
914 if (len > ssif_info->max_xmit_msg_size)
917 ssif_info->retries_left = SSIF_SEND_RETRIES;
918 memcpy(ssif_info->data+1, data, len);
919 ssif_info->data_len = len;
920 return start_resend(ssif_info);
923 /* Must be called with the message lock held. */
924 static void start_next_msg(struct ssif_info *ssif_info, unsigned long *flags)
926 struct ipmi_smi_msg *msg;
927 unsigned long oflags;
930 if (!SSIF_IDLE(ssif_info)) {
931 ipmi_ssif_unlock_cond(ssif_info, flags);
935 if (!ssif_info->waiting_msg) {
936 ssif_info->curr_msg = NULL;
937 ipmi_ssif_unlock_cond(ssif_info, flags);
941 ssif_info->curr_msg = ssif_info->waiting_msg;
942 ssif_info->waiting_msg = NULL;
943 ipmi_ssif_unlock_cond(ssif_info, flags);
944 rv = start_send(ssif_info,
945 ssif_info->curr_msg->data,
946 ssif_info->curr_msg->data_size);
948 msg = ssif_info->curr_msg;
949 ssif_info->curr_msg = NULL;
950 return_hosed_msg(ssif_info, msg);
951 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
957 static void sender(void *send_info,
958 struct ipmi_smi_msg *msg)
960 struct ssif_info *ssif_info = (struct ssif_info *) send_info;
961 unsigned long oflags, *flags;
963 BUG_ON(ssif_info->waiting_msg);
964 ssif_info->waiting_msg = msg;
966 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
967 start_next_msg(ssif_info, flags);
969 if (ssif_info->ssif_debug & SSIF_DEBUG_TIMING) {
973 pr_info("**Enqueue %02x %02x: %ld.%6.6ld\n",
974 msg->data[0], msg->data[1],
975 (long) t.tv_sec, (long) t.tv_usec);
979 static int get_smi_info(void *send_info, struct ipmi_smi_info *data)
981 struct ssif_info *ssif_info = send_info;
983 data->addr_src = ssif_info->addr_source;
984 data->dev = &ssif_info->client->dev;
985 data->addr_info = ssif_info->addr_info;
986 get_device(data->dev);
992 * Instead of having our own timer to periodically check the message
993 * flags, we let the message handler drive us.
995 static void request_events(void *send_info)
997 struct ssif_info *ssif_info = (struct ssif_info *) send_info;
998 unsigned long oflags, *flags;
1000 if (!ssif_info->has_event_buffer)
1003 flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
1005 * Request flags first, not events, because the lower layer
1006 * doesn't have a way to send an attention. But make sure
1007 * event checking still happens.
1009 ssif_info->req_events = true;
1010 if (SSIF_IDLE(ssif_info))
1011 start_flag_fetch(ssif_info, flags);
1013 ssif_info->req_flags = true;
1014 ipmi_ssif_unlock_cond(ssif_info, flags);
1018 static int inc_usecount(void *send_info)
1020 struct ssif_info *ssif_info = send_info;
1022 if (!i2c_get_adapter(ssif_info->client->adapter->nr))
1025 i2c_use_client(ssif_info->client);
1029 static void dec_usecount(void *send_info)
1031 struct ssif_info *ssif_info = send_info;
1033 i2c_release_client(ssif_info->client);
1034 i2c_put_adapter(ssif_info->client->adapter);
1037 static int ssif_start_processing(void *send_info,
1040 struct ssif_info *ssif_info = send_info;
1042 ssif_info->intf = intf;
1047 #define MAX_SSIF_BMCS 4
1049 static unsigned short addr[MAX_SSIF_BMCS];
1050 static int num_addrs;
1051 module_param_array(addr, ushort, &num_addrs, 0);
1052 MODULE_PARM_DESC(addr, "The addresses to scan for IPMI BMCs on the SSIFs.");
1054 static char *adapter_name[MAX_SSIF_BMCS];
1055 static int num_adapter_names;
1056 module_param_array(adapter_name, charp, &num_adapter_names, 0);
1057 MODULE_PARM_DESC(adapter_name, "The string name of the I2C device that has the BMC. By default all devices are scanned.");
1059 static int slave_addrs[MAX_SSIF_BMCS];
1060 static int num_slave_addrs;
1061 module_param_array(slave_addrs, int, &num_slave_addrs, 0);
1062 MODULE_PARM_DESC(slave_addrs,
1063 "The default IPMB slave address for the controller.");
1066 * Bit 0 enables message debugging, bit 1 enables state debugging, and
1067 * bit 2 enables timing debugging. This is an array indexed by
1070 static int dbg[MAX_SSIF_BMCS];
1072 module_param_array(dbg, int, &num_dbg, 0);
1073 MODULE_PARM_DESC(dbg, "Turn on debugging.");
1075 static bool ssif_dbg_probe;
1076 module_param_named(dbg_probe, ssif_dbg_probe, bool, 0);
1077 MODULE_PARM_DESC(dbg_probe, "Enable debugging of probing of adapters.");
1079 static int use_thread;
1080 module_param(use_thread, int, 0);
1081 MODULE_PARM_DESC(use_thread, "Use the thread interface.");
1083 static bool ssif_tryacpi = 1;
1084 module_param_named(tryacpi, ssif_tryacpi, bool, 0);
1085 MODULE_PARM_DESC(tryacpi, "Setting this to zero will disable the default scan of the interfaces identified via ACPI");
1087 static bool ssif_trydmi = 1;
1088 module_param_named(trydmi, ssif_trydmi, bool, 0);
1089 MODULE_PARM_DESC(trydmi, "Setting this to zero will disable the default scan of the interfaces identified via DMI (SMBIOS)");
1091 static DEFINE_MUTEX(ssif_infos_mutex);
1092 static LIST_HEAD(ssif_infos);
1094 static int ssif_remove(struct i2c_client *client)
1096 struct ssif_info *ssif_info = i2c_get_clientdata(client);
1103 * After this point, we won't deliver anything asychronously
1104 * to the message handler. We can unregister ourself.
1106 rv = ipmi_unregister_smi(ssif_info->intf);
1108 pr_err(PFX "Unable to unregister device: errno=%d\n", rv);
1111 ssif_info->intf = NULL;
1113 /* make sure the driver is not looking for flags any more. */
1114 while (ssif_info->ssif_state != SSIF_NORMAL)
1115 schedule_timeout(1);
1117 ssif_info->stopping = true;
1118 del_timer_sync(&ssif_info->retry_timer);
1119 if (ssif_info->thread) {
1120 complete(&ssif_info->wake_thread);
1121 kthread_stop(ssif_info->thread);
1125 * No message can be outstanding now, we have removed the
1126 * upper layer and it permitted us to do so.
1132 static int do_cmd(struct i2c_client *client, int len, unsigned char *msg,
1133 int *resp_len, unsigned char *resp)
1138 retry_cnt = SSIF_SEND_RETRIES;
1140 ret = i2c_smbus_write_block_data(client, SSIF_IPMI_REQUEST, len, msg);
1149 retry_cnt = SSIF_RECV_RETRIES;
1150 while (retry_cnt > 0) {
1151 ret = i2c_smbus_read_block_data(client, SSIF_IPMI_RESPONSE,
1155 msleep(SSIF_MSG_MSEC);
1162 /* Validate that the response is correct. */
1164 (resp[0] != (msg[0] | (1 << 2))) ||
1165 (resp[1] != msg[1]))
1176 static int ssif_detect(struct i2c_client *client, struct i2c_board_info *info)
1178 unsigned char *resp;
1179 unsigned char msg[3];
1183 resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
1187 /* Do a Get Device ID command, since it is required. */
1188 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
1189 msg[1] = IPMI_GET_DEVICE_ID_CMD;
1190 rv = do_cmd(client, 2, msg, &len, resp);
1194 strlcpy(info->type, DEVICE_NAME, I2C_NAME_SIZE);
1199 static int smi_type_proc_show(struct seq_file *m, void *v)
1201 seq_puts(m, "ssif\n");
1203 return seq_has_overflowed(m);
1206 static int smi_type_proc_open(struct inode *inode, struct file *file)
1208 return single_open(file, smi_type_proc_show, inode->i_private);
1211 static const struct file_operations smi_type_proc_ops = {
1212 .open = smi_type_proc_open,
1214 .llseek = seq_lseek,
1215 .release = single_release,
1218 static int smi_stats_proc_show(struct seq_file *m, void *v)
1220 struct ssif_info *ssif_info = m->private;
1222 seq_printf(m, "sent_messages: %u\n",
1223 ssif_get_stat(ssif_info, sent_messages));
1224 seq_printf(m, "sent_messages_parts: %u\n",
1225 ssif_get_stat(ssif_info, sent_messages_parts));
1226 seq_printf(m, "send_retries: %u\n",
1227 ssif_get_stat(ssif_info, send_retries));
1228 seq_printf(m, "send_errors: %u\n",
1229 ssif_get_stat(ssif_info, send_errors));
1230 seq_printf(m, "received_messages: %u\n",
1231 ssif_get_stat(ssif_info, received_messages));
1232 seq_printf(m, "received_message_parts: %u\n",
1233 ssif_get_stat(ssif_info, received_message_parts));
1234 seq_printf(m, "receive_retries: %u\n",
1235 ssif_get_stat(ssif_info, receive_retries));
1236 seq_printf(m, "receive_errors: %u\n",
1237 ssif_get_stat(ssif_info, receive_errors));
1238 seq_printf(m, "flag_fetches: %u\n",
1239 ssif_get_stat(ssif_info, flag_fetches));
1240 seq_printf(m, "hosed: %u\n",
1241 ssif_get_stat(ssif_info, hosed));
1242 seq_printf(m, "events: %u\n",
1243 ssif_get_stat(ssif_info, events));
1244 seq_printf(m, "watchdog_pretimeouts: %u\n",
1245 ssif_get_stat(ssif_info, watchdog_pretimeouts));
1249 static int smi_stats_proc_open(struct inode *inode, struct file *file)
1251 return single_open(file, smi_stats_proc_show, PDE_DATA(inode));
1254 static const struct file_operations smi_stats_proc_ops = {
1255 .open = smi_stats_proc_open,
1257 .llseek = seq_lseek,
1258 .release = single_release,
1261 static struct ssif_addr_info *ssif_info_find(unsigned short addr,
1263 bool match_null_name)
1265 struct ssif_addr_info *info, *found = NULL;
1268 list_for_each_entry(info, &ssif_infos, link) {
1269 if (info->binfo.addr == addr) {
1270 if (info->adapter_name || adapter_name) {
1271 if (!info->adapter_name != !adapter_name) {
1272 /* One is NULL and one is not */
1275 if (strcmp(info->adapter_name, adapter_name))
1276 /* Names to not match */
1284 if (!found && match_null_name) {
1285 /* Try to get an exact match first, then try with a NULL name */
1286 adapter_name = NULL;
1287 match_null_name = false;
1294 static bool check_acpi(struct ssif_info *ssif_info, struct device *dev)
1297 acpi_handle acpi_handle;
1299 acpi_handle = ACPI_HANDLE(dev);
1301 ssif_info->addr_source = SI_ACPI;
1302 ssif_info->addr_info.acpi_info.acpi_handle = acpi_handle;
1309 static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
1311 unsigned char msg[3];
1312 unsigned char *resp;
1313 struct ssif_info *ssif_info;
1318 struct ssif_addr_info *addr_info = NULL;
1321 resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
1325 ssif_info = kzalloc(sizeof(*ssif_info), GFP_KERNEL);
1331 if (!check_acpi(ssif_info, &client->dev)) {
1332 addr_info = ssif_info_find(client->addr, client->adapter->name,
1335 /* Must have come in through sysfs. */
1336 ssif_info->addr_source = SI_HOTMOD;
1338 ssif_info->addr_source = addr_info->addr_src;
1339 ssif_info->ssif_debug = addr_info->debug;
1340 ssif_info->addr_info = addr_info->addr_info;
1341 slave_addr = addr_info->slave_addr;
1345 pr_info(PFX "Trying %s-specified SSIF interface at i2c address 0x%x, adapter %s, slave address 0x%x\n",
1346 ipmi_addr_src_to_str(ssif_info->addr_source),
1347 client->addr, client->adapter->name, slave_addr);
1350 * Do a Get Device ID command, since it comes back with some
1353 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
1354 msg[1] = IPMI_GET_DEVICE_ID_CMD;
1355 rv = do_cmd(client, 2, msg, &len, resp);
1359 rv = ipmi_demangle_device_id(resp, len, &ssif_info->device_id);
1363 ssif_info->client = client;
1364 i2c_set_clientdata(client, ssif_info);
1366 /* Now check for system interface capabilities */
1367 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
1368 msg[1] = IPMI_GET_SYSTEM_INTERFACE_CAPABILITIES_CMD;
1369 msg[2] = 0; /* SSIF */
1370 rv = do_cmd(client, 3, msg, &len, resp);
1371 if (!rv && (len >= 3) && (resp[2] == 0)) {
1374 pr_info(PFX "SSIF info too short: %d\n", len);
1378 /* Got a good SSIF response, handle it. */
1379 ssif_info->max_xmit_msg_size = resp[5];
1380 ssif_info->max_recv_msg_size = resp[6];
1381 ssif_info->multi_support = (resp[4] >> 6) & 0x3;
1382 ssif_info->supports_pec = (resp[4] >> 3) & 0x1;
1384 /* Sanitize the data */
1385 switch (ssif_info->multi_support) {
1387 if (ssif_info->max_xmit_msg_size > 32)
1388 ssif_info->max_xmit_msg_size = 32;
1389 if (ssif_info->max_recv_msg_size > 32)
1390 ssif_info->max_recv_msg_size = 32;
1393 case SSIF_MULTI_2_PART:
1394 if (ssif_info->max_xmit_msg_size > 64)
1395 ssif_info->max_xmit_msg_size = 64;
1396 if (ssif_info->max_recv_msg_size > 62)
1397 ssif_info->max_recv_msg_size = 62;
1400 case SSIF_MULTI_n_PART:
1404 /* Data is not sane, just give up. */
1409 /* Assume no multi-part or PEC support */
1410 pr_info(PFX "Error fetching SSIF: %d %d %2.2x, your system probably doesn't support this command so using defaults\n",
1413 ssif_info->max_xmit_msg_size = 32;
1414 ssif_info->max_recv_msg_size = 32;
1415 ssif_info->multi_support = SSIF_NO_MULTI;
1416 ssif_info->supports_pec = 0;
1419 /* Make sure the NMI timeout is cleared. */
1420 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
1421 msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD;
1422 msg[2] = WDT_PRE_TIMEOUT_INT;
1423 rv = do_cmd(client, 3, msg, &len, resp);
1424 if (rv || (len < 3) || (resp[2] != 0))
1425 pr_warn(PFX "Unable to clear message flags: %d %d %2.2x\n",
1428 /* Attempt to enable the event buffer. */
1429 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
1430 msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD;
1431 rv = do_cmd(client, 2, msg, &len, resp);
1432 if (rv || (len < 4) || (resp[2] != 0)) {
1433 pr_warn(PFX "Error getting global enables: %d %d %2.2x\n",
1435 rv = 0; /* Not fatal */
1439 if (resp[3] & IPMI_BMC_EVT_MSG_BUFF) {
1440 ssif_info->has_event_buffer = true;
1441 /* buffer is already enabled, nothing to do. */
1445 msg[0] = IPMI_NETFN_APP_REQUEST << 2;
1446 msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
1447 msg[2] = resp[3] | IPMI_BMC_EVT_MSG_BUFF;
1448 rv = do_cmd(client, 3, msg, &len, resp);
1449 if (rv || (len < 2)) {
1450 pr_warn(PFX "Error getting global enables: %d %d %2.2x\n",
1452 rv = 0; /* Not fatal */
1457 /* A successful return means the event buffer is supported. */
1458 ssif_info->has_event_buffer = true;
1461 ssif_info->intf_num = atomic_inc_return(&next_intf);
1463 if (ssif_dbg_probe) {
1464 pr_info("ssif_probe: i2c_probe found device at i2c address %x\n",
1468 spin_lock_init(&ssif_info->lock);
1469 ssif_info->ssif_state = SSIF_NORMAL;
1470 init_timer(&ssif_info->retry_timer);
1471 ssif_info->retry_timer.data = (unsigned long) ssif_info;
1472 ssif_info->retry_timer.function = retry_timeout;
1474 for (i = 0; i < SSIF_NUM_STATS; i++)
1475 atomic_set(&ssif_info->stats[i], 0);
1477 if (ssif_info->supports_pec)
1478 ssif_info->client->flags |= I2C_CLIENT_PEC;
1480 ssif_info->handlers.owner = THIS_MODULE;
1481 ssif_info->handlers.start_processing = ssif_start_processing;
1482 ssif_info->handlers.get_smi_info = get_smi_info;
1483 ssif_info->handlers.sender = sender;
1484 ssif_info->handlers.request_events = request_events;
1485 ssif_info->handlers.inc_usecount = inc_usecount;
1486 ssif_info->handlers.dec_usecount = dec_usecount;
1489 unsigned int thread_num;
1491 thread_num = ((ssif_info->client->adapter->nr << 8) |
1492 ssif_info->client->addr);
1493 init_completion(&ssif_info->wake_thread);
1494 ssif_info->thread = kthread_run(ipmi_ssif_thread, ssif_info,
1495 "kssif%4.4x", thread_num);
1496 if (IS_ERR(ssif_info->thread)) {
1497 rv = PTR_ERR(ssif_info->thread);
1498 dev_notice(&ssif_info->client->dev,
1499 "Could not start kernel thread: error %d\n",
1505 rv = ipmi_register_smi(&ssif_info->handlers,
1507 &ssif_info->device_id,
1508 &ssif_info->client->dev,
1511 pr_err(PFX "Unable to register device: error %d\n", rv);
1515 rv = ipmi_smi_add_proc_entry(ssif_info->intf, "type",
1519 pr_err(PFX "Unable to create proc entry: %d\n", rv);
1523 rv = ipmi_smi_add_proc_entry(ssif_info->intf, "ssif_stats",
1524 &smi_stats_proc_ops,
1527 pr_err(PFX "Unable to create proc entry: %d\n", rv);
1538 ipmi_unregister_smi(ssif_info->intf);
1542 static int ssif_adapter_handler(struct device *adev, void *opaque)
1544 struct ssif_addr_info *addr_info = opaque;
1546 if (adev->type != &i2c_adapter_type)
1549 i2c_new_device(to_i2c_adapter(adev), &addr_info->binfo);
1551 if (!addr_info->adapter_name)
1552 return 1; /* Only try the first I2C adapter by default. */
1556 static int new_ssif_client(int addr, char *adapter_name,
1557 int debug, int slave_addr,
1558 enum ipmi_addr_src addr_src)
1560 struct ssif_addr_info *addr_info;
1563 mutex_lock(&ssif_infos_mutex);
1564 if (ssif_info_find(addr, adapter_name, false)) {
1569 addr_info = kzalloc(sizeof(*addr_info), GFP_KERNEL);
1576 addr_info->adapter_name = kstrdup(adapter_name, GFP_KERNEL);
1577 if (!addr_info->adapter_name) {
1584 strncpy(addr_info->binfo.type, DEVICE_NAME,
1585 sizeof(addr_info->binfo.type));
1586 addr_info->binfo.addr = addr;
1587 addr_info->binfo.platform_data = addr_info;
1588 addr_info->debug = debug;
1589 addr_info->slave_addr = slave_addr;
1590 addr_info->addr_src = addr_src;
1592 list_add_tail(&addr_info->link, &ssif_infos);
1595 i2c_for_each_dev(addr_info, ssif_adapter_handler);
1596 /* Otherwise address list will get it */
1599 mutex_unlock(&ssif_infos_mutex);
1603 static void free_ssif_clients(void)
1605 struct ssif_addr_info *info, *tmp;
1607 mutex_lock(&ssif_infos_mutex);
1608 list_for_each_entry_safe(info, tmp, &ssif_infos, link) {
1609 list_del(&info->link);
1610 kfree(info->adapter_name);
1613 mutex_unlock(&ssif_infos_mutex);
1616 static unsigned short *ssif_address_list(void)
1618 struct ssif_addr_info *info;
1619 unsigned int count = 0, i;
1620 unsigned short *address_list;
1622 list_for_each_entry(info, &ssif_infos, link)
1625 address_list = kzalloc(sizeof(*address_list) * (count + 1), GFP_KERNEL);
1630 list_for_each_entry(info, &ssif_infos, link) {
1631 unsigned short addr = info->binfo.addr;
1634 for (j = 0; j < i; j++) {
1635 if (address_list[j] == addr)
1638 address_list[i] = addr;
1642 address_list[i] = I2C_CLIENT_END;
1644 return address_list;
1648 static struct acpi_device_id ssif_acpi_match[] = {
1652 MODULE_DEVICE_TABLE(acpi, ssif_acpi_match);
1655 * Once we get an ACPI failure, we don't try any more, because we go
1656 * through the tables sequentially. Once we don't find a table, there
1659 static int acpi_failure;
1662 * Defined in the IPMI 2.0 spec.
1673 s8 CreatorRevision[4];
1676 s16 SpecificationRevision;
1679 * Bit 0 - SCI interrupt supported
1680 * Bit 1 - I/O APIC/SAPIC
1685 * If bit 0 of InterruptType is set, then this is the SCI
1686 * interrupt in the GPEx_STS register.
1693 * If bit 1 of InterruptType is set, then this is the I/O
1694 * APIC/SAPIC interrupt.
1696 u32 GlobalSystemInterrupt;
1698 /* The actual register address. */
1699 struct acpi_generic_address addr;
1703 s8 spmi_id[1]; /* A '\0' terminated array starts here. */
1706 static int try_init_spmi(struct SPMITable *spmi)
1708 unsigned short myaddr;
1710 if (num_addrs >= MAX_SSIF_BMCS)
1713 if (spmi->IPMIlegacy != 1) {
1714 pr_warn("IPMI: Bad SPMI legacy: %d\n", spmi->IPMIlegacy);
1718 if (spmi->InterfaceType != 4)
1721 if (spmi->addr.space_id != ACPI_ADR_SPACE_SMBUS) {
1722 pr_warn(PFX "Invalid ACPI SSIF I/O Address type: %d\n",
1723 spmi->addr.space_id);
1727 myaddr = spmi->addr.address >> 1;
1729 return new_ssif_client(myaddr, NULL, 0, 0, SI_SPMI);
1732 static void spmi_find_bmc(void)
1735 struct SPMITable *spmi;
1744 for (i = 0; ; i++) {
1745 status = acpi_get_table(ACPI_SIG_SPMI, i+1,
1746 (struct acpi_table_header **)&spmi);
1747 if (status != AE_OK)
1750 try_init_spmi(spmi);
1754 static void spmi_find_bmc(void) { }
1758 static int decode_dmi(const struct dmi_device *dmi_dev)
1760 struct dmi_header *dm = dmi_dev->device_data;
1761 u8 *data = (u8 *) dm;
1762 u8 len = dm->length;
1763 unsigned short myaddr;
1766 if (num_addrs >= MAX_SSIF_BMCS)
1772 if (data[0x04] != 4) /* Not SSIF */
1775 if ((data[8] >> 1) == 0) {
1777 * Some broken systems put the I2C address in
1778 * the slave address field. We try to
1779 * accommodate them here.
1781 myaddr = data[6] >> 1;
1784 myaddr = data[8] >> 1;
1785 slave_addr = data[6];
1788 return new_ssif_client(myaddr, NULL, 0, 0, SI_SMBIOS);
1791 static void dmi_iterator(void)
1793 const struct dmi_device *dev = NULL;
1795 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev)))
1799 static void dmi_iterator(void) { }
1802 static const struct i2c_device_id ssif_id[] = {
1806 MODULE_DEVICE_TABLE(i2c, ssif_id);
1808 static struct i2c_driver ssif_i2c_driver = {
1809 .class = I2C_CLASS_HWMON,
1811 .owner = THIS_MODULE,
1814 .probe = ssif_probe,
1815 .remove = ssif_remove,
1816 .id_table = ssif_id,
1817 .detect = ssif_detect
1820 static int init_ipmi_ssif(void)
1828 pr_info("IPMI SSIF Interface driver\n");
1830 /* build list for i2c from addr list */
1831 for (i = 0; i < num_addrs; i++) {
1832 rv = new_ssif_client(addr[i], adapter_name[i],
1833 dbg[i], slave_addrs[i],
1837 "Couldn't add hardcoded device at addr 0x%x\n",
1842 ssif_i2c_driver.driver.acpi_match_table =
1843 ACPI_PTR(ssif_acpi_match);
1849 ssif_i2c_driver.address_list = ssif_address_list();
1851 rv = i2c_add_driver(&ssif_i2c_driver);
1857 module_init(init_ipmi_ssif);
1859 static void cleanup_ipmi_ssif(void)
1864 initialized = false;
1866 i2c_del_driver(&ssif_i2c_driver);
1868 free_ssif_clients();
1870 module_exit(cleanup_ipmi_ssif);
1872 MODULE_AUTHOR("Todd C Davis <todd.c.davis@intel.com>, Corey Minyard <minyard@acm.org>");
1873 MODULE_DESCRIPTION("IPMI driver for management controllers on a SMBus");
1874 MODULE_LICENSE("GPL");