4 * The interface to the IPMI driver for the system interfaces (KCS, SMIC,
7 * Author: MontaVista Software, Inc.
8 * Corey Minyard <minyard@mvista.com>
11 * Copyright 2002 MontaVista Software Inc.
12 * Copyright 2006 IBM Corp., Christian Krafft <krafft@de.ibm.com>
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
28 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
29 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * You should have received a copy of the GNU General Public License along
32 * with this program; if not, write to the Free Software Foundation, Inc.,
33 * 675 Mass Ave, Cambridge, MA 02139, USA.
37 * This file holds the "policy" for the interface to the SMI state
38 * machine. It does the configuration, handles timers and interrupts,
39 * and drives the real SMI state machine.
42 #include <linux/module.h>
43 #include <linux/moduleparam.h>
44 #include <linux/sched.h>
45 #include <linux/seq_file.h>
46 #include <linux/timer.h>
47 #include <linux/errno.h>
48 #include <linux/spinlock.h>
49 #include <linux/slab.h>
50 #include <linux/delay.h>
51 #include <linux/list.h>
52 #include <linux/pci.h>
53 #include <linux/ioport.h>
54 #include <linux/notifier.h>
55 #include <linux/mutex.h>
56 #include <linux/kthread.h>
58 #include <linux/interrupt.h>
59 #include <linux/rcupdate.h>
60 #include <linux/ipmi.h>
61 #include <linux/ipmi_smi.h>
63 #include "ipmi_si_sm.h"
64 #include <linux/dmi.h>
65 #include <linux/string.h>
66 #include <linux/ctype.h>
67 #include <linux/pnp.h>
68 #include <linux/of_device.h>
69 #include <linux/of_platform.h>
70 #include <linux/of_address.h>
71 #include <linux/of_irq.h>
74 #include <asm/hardware.h> /* for register_parisc_driver() stuff */
75 #include <asm/parisc-device.h>
78 #define PFX "ipmi_si: "
80 /* Measure times between events in the driver. */
83 /* Call every 10 ms. */
84 #define SI_TIMEOUT_TIME_USEC 10000
85 #define SI_USEC_PER_JIFFY (1000000/HZ)
86 #define SI_TIMEOUT_JIFFIES (SI_TIMEOUT_TIME_USEC/SI_USEC_PER_JIFFY)
87 #define SI_SHORT_TIMEOUT_USEC 250 /* .25ms when the SM request a
95 SI_CLEARING_FLAGS_THEN_SET_IRQ
,
97 SI_ENABLE_INTERRUPTS1
,
98 SI_ENABLE_INTERRUPTS2
,
99 SI_DISABLE_INTERRUPTS1
,
100 SI_DISABLE_INTERRUPTS2
101 /* FIXME - add watchdog stuff. */
104 /* Some BT-specific defines we need here. */
105 #define IPMI_BT_INTMASK_REG 2
106 #define IPMI_BT_INTMASK_CLEAR_IRQ_BIT 2
107 #define IPMI_BT_INTMASK_ENABLE_IRQ_BIT 1
110 SI_KCS
, SI_SMIC
, SI_BT
112 static char *si_to_str
[] = { "kcs", "smic", "bt" };
114 static char *ipmi_addr_src_to_str
[] = { NULL
, "hotmod", "hardcoded", "SPMI",
115 "ACPI", "SMBIOS", "PCI",
116 "device-tree", "default" };
118 #define DEVICE_NAME "ipmi_si"
120 static struct platform_driver ipmi_driver
;
123 * Indexes into stats[] in smi_info below.
125 enum si_stat_indexes
{
127 * Number of times the driver requested a timer while an operation
130 SI_STAT_short_timeouts
= 0,
133 * Number of times the driver requested a timer while nothing was in
136 SI_STAT_long_timeouts
,
138 /* Number of times the interface was idle while being polled. */
141 /* Number of interrupts the driver handled. */
144 /* Number of time the driver got an ATTN from the hardware. */
147 /* Number of times the driver requested flags from the hardware. */
148 SI_STAT_flag_fetches
,
150 /* Number of times the hardware didn't follow the state machine. */
153 /* Number of completed messages. */
154 SI_STAT_complete_transactions
,
156 /* Number of IPMI events received from the hardware. */
159 /* Number of watchdog pretimeouts. */
160 SI_STAT_watchdog_pretimeouts
,
162 /* Number of asynchronous messages received. */
163 SI_STAT_incoming_messages
,
166 /* This *must* remain last, add new values above this. */
173 struct si_sm_data
*si_sm
;
174 struct si_sm_handlers
*handlers
;
175 enum si_type si_type
;
177 struct list_head xmit_msgs
;
178 struct list_head hp_xmit_msgs
;
179 struct ipmi_smi_msg
*curr_msg
;
180 enum si_intf_state si_state
;
183 * Used to handle the various types of I/O that can occur with
187 int (*io_setup
)(struct smi_info
*info
);
188 void (*io_cleanup
)(struct smi_info
*info
);
189 int (*irq_setup
)(struct smi_info
*info
);
190 void (*irq_cleanup
)(struct smi_info
*info
);
191 unsigned int io_size
;
192 enum ipmi_addr_src addr_source
; /* ACPI, PCI, SMBIOS, hardcode, etc. */
193 void (*addr_source_cleanup
)(struct smi_info
*info
);
194 void *addr_source_data
;
197 * Per-OEM handler, called from handle_flags(). Returns 1
198 * when handle_flags() needs to be re-run or 0 indicating it
199 * set si_state itself.
201 int (*oem_data_avail_handler
)(struct smi_info
*smi_info
);
204 * Flags from the last GET_MSG_FLAGS command, used when an ATTN
205 * is set to hold the flags until we are done handling everything
208 #define RECEIVE_MSG_AVAIL 0x01
209 #define EVENT_MSG_BUFFER_FULL 0x02
210 #define WDT_PRE_TIMEOUT_INT 0x08
211 #define OEM0_DATA_AVAIL 0x20
212 #define OEM1_DATA_AVAIL 0x40
213 #define OEM2_DATA_AVAIL 0x80
214 #define OEM_DATA_AVAIL (OEM0_DATA_AVAIL | \
217 unsigned char msg_flags
;
219 /* Does the BMC have an event buffer? */
220 char has_event_buffer
;
223 * If set to true, this will request events the next time the
224 * state machine is idle.
229 * If true, run the state machine to completion on every send
230 * call. Generally used after a panic to make sure stuff goes
233 int run_to_completion
;
235 /* The I/O port of an SI interface. */
239 * The space between start addresses of the two ports. For
240 * instance, if the first port is 0xca2 and the spacing is 4, then
241 * the second port is 0xca6.
243 unsigned int spacing
;
245 /* zero if no irq; */
248 /* The timer for this si. */
249 struct timer_list si_timer
;
251 /* The time (in jiffies) the last timeout occurred at. */
252 unsigned long last_timeout_jiffies
;
254 /* Used to gracefully stop the timer without race conditions. */
255 atomic_t stop_operation
;
258 * The driver will disable interrupts when it gets into a
259 * situation where it cannot handle messages due to lack of
260 * memory. Once that situation clears up, it will re-enable
263 int interrupt_disabled
;
265 /* From the get device id response... */
266 struct ipmi_device_id device_id
;
268 /* Driver model stuff. */
270 struct platform_device
*pdev
;
273 * True if we allocated the device, false if it came from
274 * someplace else (like PCI).
278 /* Slave address, could be reported from DMI. */
279 unsigned char slave_addr
;
281 /* Counters and things for the proc filesystem. */
282 atomic_t stats
[SI_NUM_STATS
];
284 struct task_struct
*thread
;
286 struct list_head link
;
287 union ipmi_smi_info_union addr_info
;
290 #define smi_inc_stat(smi, stat) \
291 atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
292 #define smi_get_stat(smi, stat) \
293 ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
295 #define SI_MAX_PARMS 4
297 static int force_kipmid
[SI_MAX_PARMS
];
298 static int num_force_kipmid
;
300 static int pci_registered
;
303 static int pnp_registered
;
306 static int parisc_registered
;
309 static unsigned int kipmid_max_busy_us
[SI_MAX_PARMS
];
310 static int num_max_busy_us
;
312 static int unload_when_empty
= 1;
314 static int add_smi(struct smi_info
*smi
);
315 static int try_smi_init(struct smi_info
*smi
);
316 static void cleanup_one_si(struct smi_info
*to_clean
);
317 static void cleanup_ipmi_si(void);
319 static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list
);
320 static int register_xaction_notifier(struct notifier_block
*nb
)
322 return atomic_notifier_chain_register(&xaction_notifier_list
, nb
);
325 static void deliver_recv_msg(struct smi_info
*smi_info
,
326 struct ipmi_smi_msg
*msg
)
328 /* Deliver the message to the upper layer. */
329 ipmi_smi_msg_received(smi_info
->intf
, msg
);
332 static void return_hosed_msg(struct smi_info
*smi_info
, int cCode
)
334 struct ipmi_smi_msg
*msg
= smi_info
->curr_msg
;
336 if (cCode
< 0 || cCode
> IPMI_ERR_UNSPECIFIED
)
337 cCode
= IPMI_ERR_UNSPECIFIED
;
338 /* else use it as is */
340 /* Make it a response */
341 msg
->rsp
[0] = msg
->data
[0] | 4;
342 msg
->rsp
[1] = msg
->data
[1];
346 smi_info
->curr_msg
= NULL
;
347 deliver_recv_msg(smi_info
, msg
);
350 static enum si_sm_result
start_next_msg(struct smi_info
*smi_info
)
353 struct list_head
*entry
= NULL
;
358 /* Pick the high priority queue first. */
359 if (!list_empty(&(smi_info
->hp_xmit_msgs
))) {
360 entry
= smi_info
->hp_xmit_msgs
.next
;
361 } else if (!list_empty(&(smi_info
->xmit_msgs
))) {
362 entry
= smi_info
->xmit_msgs
.next
;
366 smi_info
->curr_msg
= NULL
;
372 smi_info
->curr_msg
= list_entry(entry
,
377 printk(KERN_DEBUG
"**Start2: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
379 err
= atomic_notifier_call_chain(&xaction_notifier_list
,
381 if (err
& NOTIFY_STOP_MASK
) {
382 rv
= SI_SM_CALL_WITHOUT_DELAY
;
385 err
= smi_info
->handlers
->start_transaction(
387 smi_info
->curr_msg
->data
,
388 smi_info
->curr_msg
->data_size
);
390 return_hosed_msg(smi_info
, err
);
392 rv
= SI_SM_CALL_WITHOUT_DELAY
;
398 static void start_enable_irq(struct smi_info
*smi_info
)
400 unsigned char msg
[2];
403 * If we are enabling interrupts, we have to tell the
406 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
407 msg
[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD
;
409 smi_info
->handlers
->start_transaction(smi_info
->si_sm
, msg
, 2);
410 smi_info
->si_state
= SI_ENABLE_INTERRUPTS1
;
413 static void start_disable_irq(struct smi_info
*smi_info
)
415 unsigned char msg
[2];
417 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
418 msg
[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD
;
420 smi_info
->handlers
->start_transaction(smi_info
->si_sm
, msg
, 2);
421 smi_info
->si_state
= SI_DISABLE_INTERRUPTS1
;
424 static void start_clear_flags(struct smi_info
*smi_info
)
426 unsigned char msg
[3];
428 /* Make sure the watchdog pre-timeout flag is not set at startup. */
429 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
430 msg
[1] = IPMI_CLEAR_MSG_FLAGS_CMD
;
431 msg
[2] = WDT_PRE_TIMEOUT_INT
;
433 smi_info
->handlers
->start_transaction(smi_info
->si_sm
, msg
, 3);
434 smi_info
->si_state
= SI_CLEARING_FLAGS
;
438 * When we have a situtaion where we run out of memory and cannot
439 * allocate messages, we just leave them in the BMC and run the system
440 * polled until we can allocate some memory. Once we have some
441 * memory, we will re-enable the interrupt.
443 static inline void disable_si_irq(struct smi_info
*smi_info
)
445 if ((smi_info
->irq
) && (!smi_info
->interrupt_disabled
)) {
446 start_disable_irq(smi_info
);
447 smi_info
->interrupt_disabled
= 1;
448 if (!atomic_read(&smi_info
->stop_operation
))
449 mod_timer(&smi_info
->si_timer
,
450 jiffies
+ SI_TIMEOUT_JIFFIES
);
454 static inline void enable_si_irq(struct smi_info
*smi_info
)
456 if ((smi_info
->irq
) && (smi_info
->interrupt_disabled
)) {
457 start_enable_irq(smi_info
);
458 smi_info
->interrupt_disabled
= 0;
462 static void handle_flags(struct smi_info
*smi_info
)
465 if (smi_info
->msg_flags
& WDT_PRE_TIMEOUT_INT
) {
466 /* Watchdog pre-timeout */
467 smi_inc_stat(smi_info
, watchdog_pretimeouts
);
469 start_clear_flags(smi_info
);
470 smi_info
->msg_flags
&= ~WDT_PRE_TIMEOUT_INT
;
471 ipmi_smi_watchdog_pretimeout(smi_info
->intf
);
472 } else if (smi_info
->msg_flags
& RECEIVE_MSG_AVAIL
) {
473 /* Messages available. */
474 smi_info
->curr_msg
= ipmi_alloc_smi_msg();
475 if (!smi_info
->curr_msg
) {
476 disable_si_irq(smi_info
);
477 smi_info
->si_state
= SI_NORMAL
;
480 enable_si_irq(smi_info
);
482 smi_info
->curr_msg
->data
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
483 smi_info
->curr_msg
->data
[1] = IPMI_GET_MSG_CMD
;
484 smi_info
->curr_msg
->data_size
= 2;
486 smi_info
->handlers
->start_transaction(
488 smi_info
->curr_msg
->data
,
489 smi_info
->curr_msg
->data_size
);
490 smi_info
->si_state
= SI_GETTING_MESSAGES
;
491 } else if (smi_info
->msg_flags
& EVENT_MSG_BUFFER_FULL
) {
492 /* Events available. */
493 smi_info
->curr_msg
= ipmi_alloc_smi_msg();
494 if (!smi_info
->curr_msg
) {
495 disable_si_irq(smi_info
);
496 smi_info
->si_state
= SI_NORMAL
;
499 enable_si_irq(smi_info
);
501 smi_info
->curr_msg
->data
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
502 smi_info
->curr_msg
->data
[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD
;
503 smi_info
->curr_msg
->data_size
= 2;
505 smi_info
->handlers
->start_transaction(
507 smi_info
->curr_msg
->data
,
508 smi_info
->curr_msg
->data_size
);
509 smi_info
->si_state
= SI_GETTING_EVENTS
;
510 } else if (smi_info
->msg_flags
& OEM_DATA_AVAIL
&&
511 smi_info
->oem_data_avail_handler
) {
512 if (smi_info
->oem_data_avail_handler(smi_info
))
515 smi_info
->si_state
= SI_NORMAL
;
518 static void handle_transaction_done(struct smi_info
*smi_info
)
520 struct ipmi_smi_msg
*msg
;
525 printk(KERN_DEBUG
"**Done: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
527 switch (smi_info
->si_state
) {
529 if (!smi_info
->curr_msg
)
532 smi_info
->curr_msg
->rsp_size
533 = smi_info
->handlers
->get_result(
535 smi_info
->curr_msg
->rsp
,
536 IPMI_MAX_MSG_LENGTH
);
539 * Do this here becase deliver_recv_msg() releases the
540 * lock, and a new message can be put in during the
541 * time the lock is released.
543 msg
= smi_info
->curr_msg
;
544 smi_info
->curr_msg
= NULL
;
545 deliver_recv_msg(smi_info
, msg
);
548 case SI_GETTING_FLAGS
:
550 unsigned char msg
[4];
553 /* We got the flags from the SMI, now handle them. */
554 len
= smi_info
->handlers
->get_result(smi_info
->si_sm
, msg
, 4);
556 /* Error fetching flags, just give up for now. */
557 smi_info
->si_state
= SI_NORMAL
;
558 } else if (len
< 4) {
560 * Hmm, no flags. That's technically illegal, but
561 * don't use uninitialized data.
563 smi_info
->si_state
= SI_NORMAL
;
565 smi_info
->msg_flags
= msg
[3];
566 handle_flags(smi_info
);
571 case SI_CLEARING_FLAGS
:
572 case SI_CLEARING_FLAGS_THEN_SET_IRQ
:
574 unsigned char msg
[3];
576 /* We cleared the flags. */
577 smi_info
->handlers
->get_result(smi_info
->si_sm
, msg
, 3);
579 /* Error clearing flags */
580 dev_warn(smi_info
->dev
,
581 "Error clearing flags: %2.2x\n", msg
[2]);
583 if (smi_info
->si_state
== SI_CLEARING_FLAGS_THEN_SET_IRQ
)
584 start_enable_irq(smi_info
);
586 smi_info
->si_state
= SI_NORMAL
;
590 case SI_GETTING_EVENTS
:
592 smi_info
->curr_msg
->rsp_size
593 = smi_info
->handlers
->get_result(
595 smi_info
->curr_msg
->rsp
,
596 IPMI_MAX_MSG_LENGTH
);
599 * Do this here becase deliver_recv_msg() releases the
600 * lock, and a new message can be put in during the
601 * time the lock is released.
603 msg
= smi_info
->curr_msg
;
604 smi_info
->curr_msg
= NULL
;
605 if (msg
->rsp
[2] != 0) {
606 /* Error getting event, probably done. */
609 /* Take off the event flag. */
610 smi_info
->msg_flags
&= ~EVENT_MSG_BUFFER_FULL
;
611 handle_flags(smi_info
);
613 smi_inc_stat(smi_info
, events
);
616 * Do this before we deliver the message
617 * because delivering the message releases the
618 * lock and something else can mess with the
621 handle_flags(smi_info
);
623 deliver_recv_msg(smi_info
, msg
);
628 case SI_GETTING_MESSAGES
:
630 smi_info
->curr_msg
->rsp_size
631 = smi_info
->handlers
->get_result(
633 smi_info
->curr_msg
->rsp
,
634 IPMI_MAX_MSG_LENGTH
);
637 * Do this here becase deliver_recv_msg() releases the
638 * lock, and a new message can be put in during the
639 * time the lock is released.
641 msg
= smi_info
->curr_msg
;
642 smi_info
->curr_msg
= NULL
;
643 if (msg
->rsp
[2] != 0) {
644 /* Error getting event, probably done. */
647 /* Take off the msg flag. */
648 smi_info
->msg_flags
&= ~RECEIVE_MSG_AVAIL
;
649 handle_flags(smi_info
);
651 smi_inc_stat(smi_info
, incoming_messages
);
654 * Do this before we deliver the message
655 * because delivering the message releases the
656 * lock and something else can mess with the
659 handle_flags(smi_info
);
661 deliver_recv_msg(smi_info
, msg
);
666 case SI_ENABLE_INTERRUPTS1
:
668 unsigned char msg
[4];
670 /* We got the flags from the SMI, now handle them. */
671 smi_info
->handlers
->get_result(smi_info
->si_sm
, msg
, 4);
673 dev_warn(smi_info
->dev
,
674 "Couldn't get irq info: %x.\n", msg
[2]);
675 dev_warn(smi_info
->dev
,
676 "Maybe ok, but ipmi might run very slowly.\n");
677 smi_info
->si_state
= SI_NORMAL
;
679 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
680 msg
[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD
;
682 IPMI_BMC_RCV_MSG_INTR
|
683 IPMI_BMC_EVT_MSG_INTR
);
684 smi_info
->handlers
->start_transaction(
685 smi_info
->si_sm
, msg
, 3);
686 smi_info
->si_state
= SI_ENABLE_INTERRUPTS2
;
691 case SI_ENABLE_INTERRUPTS2
:
693 unsigned char msg
[4];
695 /* We got the flags from the SMI, now handle them. */
696 smi_info
->handlers
->get_result(smi_info
->si_sm
, msg
, 4);
698 dev_warn(smi_info
->dev
,
699 "Couldn't set irq info: %x.\n", msg
[2]);
700 dev_warn(smi_info
->dev
,
701 "Maybe ok, but ipmi might run very slowly.\n");
703 smi_info
->interrupt_disabled
= 0;
704 smi_info
->si_state
= SI_NORMAL
;
708 case SI_DISABLE_INTERRUPTS1
:
710 unsigned char msg
[4];
712 /* We got the flags from the SMI, now handle them. */
713 smi_info
->handlers
->get_result(smi_info
->si_sm
, msg
, 4);
715 dev_warn(smi_info
->dev
, "Could not disable interrupts"
717 smi_info
->si_state
= SI_NORMAL
;
719 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
720 msg
[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD
;
722 ~(IPMI_BMC_RCV_MSG_INTR
|
723 IPMI_BMC_EVT_MSG_INTR
));
724 smi_info
->handlers
->start_transaction(
725 smi_info
->si_sm
, msg
, 3);
726 smi_info
->si_state
= SI_DISABLE_INTERRUPTS2
;
731 case SI_DISABLE_INTERRUPTS2
:
733 unsigned char msg
[4];
735 /* We got the flags from the SMI, now handle them. */
736 smi_info
->handlers
->get_result(smi_info
->si_sm
, msg
, 4);
738 dev_warn(smi_info
->dev
, "Could not disable interrupts"
741 smi_info
->si_state
= SI_NORMAL
;
748 * Called on timeouts and events. Timeouts should pass the elapsed
749 * time, interrupts should pass in zero. Must be called with
750 * si_lock held and interrupts disabled.
752 static enum si_sm_result
smi_event_handler(struct smi_info
*smi_info
,
755 enum si_sm_result si_sm_result
;
759 * There used to be a loop here that waited a little while
760 * (around 25us) before giving up. That turned out to be
761 * pointless, the minimum delays I was seeing were in the 300us
762 * range, which is far too long to wait in an interrupt. So
763 * we just run until the state machine tells us something
764 * happened or it needs a delay.
766 si_sm_result
= smi_info
->handlers
->event(smi_info
->si_sm
, time
);
768 while (si_sm_result
== SI_SM_CALL_WITHOUT_DELAY
)
769 si_sm_result
= smi_info
->handlers
->event(smi_info
->si_sm
, 0);
771 if (si_sm_result
== SI_SM_TRANSACTION_COMPLETE
) {
772 smi_inc_stat(smi_info
, complete_transactions
);
774 handle_transaction_done(smi_info
);
775 si_sm_result
= smi_info
->handlers
->event(smi_info
->si_sm
, 0);
776 } else if (si_sm_result
== SI_SM_HOSED
) {
777 smi_inc_stat(smi_info
, hosed_count
);
780 * Do the before return_hosed_msg, because that
783 smi_info
->si_state
= SI_NORMAL
;
784 if (smi_info
->curr_msg
!= NULL
) {
786 * If we were handling a user message, format
787 * a response to send to the upper layer to
788 * tell it about the error.
790 return_hosed_msg(smi_info
, IPMI_ERR_UNSPECIFIED
);
792 si_sm_result
= smi_info
->handlers
->event(smi_info
->si_sm
, 0);
796 * We prefer handling attn over new messages. But don't do
797 * this if there is not yet an upper layer to handle anything.
799 if (likely(smi_info
->intf
) && si_sm_result
== SI_SM_ATTN
) {
800 unsigned char msg
[2];
802 smi_inc_stat(smi_info
, attentions
);
805 * Got a attn, send down a get message flags to see
806 * what's causing it. It would be better to handle
807 * this in the upper layer, but due to the way
808 * interrupts work with the SMI, that's not really
811 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
812 msg
[1] = IPMI_GET_MSG_FLAGS_CMD
;
814 smi_info
->handlers
->start_transaction(
815 smi_info
->si_sm
, msg
, 2);
816 smi_info
->si_state
= SI_GETTING_FLAGS
;
820 /* If we are currently idle, try to start the next message. */
821 if (si_sm_result
== SI_SM_IDLE
) {
822 smi_inc_stat(smi_info
, idles
);
824 si_sm_result
= start_next_msg(smi_info
);
825 if (si_sm_result
!= SI_SM_IDLE
)
829 if ((si_sm_result
== SI_SM_IDLE
)
830 && (atomic_read(&smi_info
->req_events
))) {
832 * We are idle and the upper layer requested that I fetch
835 atomic_set(&smi_info
->req_events
, 0);
837 smi_info
->curr_msg
= ipmi_alloc_smi_msg();
838 if (!smi_info
->curr_msg
)
841 smi_info
->curr_msg
->data
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
842 smi_info
->curr_msg
->data
[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD
;
843 smi_info
->curr_msg
->data_size
= 2;
845 smi_info
->handlers
->start_transaction(
847 smi_info
->curr_msg
->data
,
848 smi_info
->curr_msg
->data_size
);
849 smi_info
->si_state
= SI_GETTING_EVENTS
;
856 static void sender(void *send_info
,
857 struct ipmi_smi_msg
*msg
,
860 struct smi_info
*smi_info
= send_info
;
861 enum si_sm_result result
;
867 if (atomic_read(&smi_info
->stop_operation
)) {
868 msg
->rsp
[0] = msg
->data
[0] | 4;
869 msg
->rsp
[1] = msg
->data
[1];
870 msg
->rsp
[2] = IPMI_ERR_UNSPECIFIED
;
872 deliver_recv_msg(smi_info
, msg
);
878 printk("**Enqueue: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
881 if (smi_info
->run_to_completion
) {
883 * If we are running to completion, then throw it in
884 * the list and run transactions until everything is
885 * clear. Priority doesn't matter here.
889 * Run to completion means we are single-threaded, no
892 list_add_tail(&(msg
->link
), &(smi_info
->xmit_msgs
));
894 result
= smi_event_handler(smi_info
, 0);
895 while (result
!= SI_SM_IDLE
) {
896 udelay(SI_SHORT_TIMEOUT_USEC
);
897 result
= smi_event_handler(smi_info
,
898 SI_SHORT_TIMEOUT_USEC
);
903 spin_lock_irqsave(&smi_info
->si_lock
, flags
);
905 list_add_tail(&msg
->link
, &smi_info
->hp_xmit_msgs
);
907 list_add_tail(&msg
->link
, &smi_info
->xmit_msgs
);
909 if (smi_info
->si_state
== SI_NORMAL
&& smi_info
->curr_msg
== NULL
) {
911 * last_timeout_jiffies is updated here to avoid
912 * smi_timeout() handler passing very large time_diff
913 * value to smi_event_handler() that causes
914 * the send command to abort.
916 smi_info
->last_timeout_jiffies
= jiffies
;
918 mod_timer(&smi_info
->si_timer
, jiffies
+ SI_TIMEOUT_JIFFIES
);
920 if (smi_info
->thread
)
921 wake_up_process(smi_info
->thread
);
923 start_next_msg(smi_info
);
924 smi_event_handler(smi_info
, 0);
926 spin_unlock_irqrestore(&smi_info
->si_lock
, flags
);
929 static void set_run_to_completion(void *send_info
, int i_run_to_completion
)
931 struct smi_info
*smi_info
= send_info
;
932 enum si_sm_result result
;
934 smi_info
->run_to_completion
= i_run_to_completion
;
935 if (i_run_to_completion
) {
936 result
= smi_event_handler(smi_info
, 0);
937 while (result
!= SI_SM_IDLE
) {
938 udelay(SI_SHORT_TIMEOUT_USEC
);
939 result
= smi_event_handler(smi_info
,
940 SI_SHORT_TIMEOUT_USEC
);
946 * Use -1 in the nsec value of the busy waiting timespec to tell that
947 * we are spinning in kipmid looking for something and not delaying
950 static inline void ipmi_si_set_not_busy(struct timespec
*ts
)
954 static inline int ipmi_si_is_busy(struct timespec
*ts
)
956 return ts
->tv_nsec
!= -1;
959 static int ipmi_thread_busy_wait(enum si_sm_result smi_result
,
960 const struct smi_info
*smi_info
,
961 struct timespec
*busy_until
)
963 unsigned int max_busy_us
= 0;
965 if (smi_info
->intf_num
< num_max_busy_us
)
966 max_busy_us
= kipmid_max_busy_us
[smi_info
->intf_num
];
967 if (max_busy_us
== 0 || smi_result
!= SI_SM_CALL_WITH_DELAY
)
968 ipmi_si_set_not_busy(busy_until
);
969 else if (!ipmi_si_is_busy(busy_until
)) {
970 getnstimeofday(busy_until
);
971 timespec_add_ns(busy_until
, max_busy_us
*NSEC_PER_USEC
);
974 getnstimeofday(&now
);
975 if (unlikely(timespec_compare(&now
, busy_until
) > 0)) {
976 ipmi_si_set_not_busy(busy_until
);
985 * A busy-waiting loop for speeding up IPMI operation.
987 * Lousy hardware makes this hard. This is only enabled for systems
988 * that are not BT and do not have interrupts. It starts spinning
989 * when an operation is complete or until max_busy tells it to stop
990 * (if that is enabled). See the paragraph on kimid_max_busy_us in
991 * Documentation/IPMI.txt for details.
993 static int ipmi_thread(void *data
)
995 struct smi_info
*smi_info
= data
;
997 enum si_sm_result smi_result
;
998 struct timespec busy_until
;
1000 ipmi_si_set_not_busy(&busy_until
);
1001 set_user_nice(current
, 19);
1002 while (!kthread_should_stop()) {
1005 spin_lock_irqsave(&(smi_info
->si_lock
), flags
);
1006 smi_result
= smi_event_handler(smi_info
, 0);
1007 spin_unlock_irqrestore(&(smi_info
->si_lock
), flags
);
1008 busy_wait
= ipmi_thread_busy_wait(smi_result
, smi_info
,
1010 if (smi_result
== SI_SM_CALL_WITHOUT_DELAY
)
1012 else if (smi_result
== SI_SM_CALL_WITH_DELAY
&& busy_wait
)
1014 else if (smi_result
== SI_SM_IDLE
)
1015 schedule_timeout_interruptible(100);
1017 schedule_timeout_interruptible(1);
1023 static void poll(void *send_info
)
1025 struct smi_info
*smi_info
= send_info
;
1026 unsigned long flags
= 0;
1027 int run_to_completion
= smi_info
->run_to_completion
;
1030 * Make sure there is some delay in the poll loop so we can
1031 * drive time forward and timeout things.
1034 if (!run_to_completion
)
1035 spin_lock_irqsave(&smi_info
->si_lock
, flags
);
1036 smi_event_handler(smi_info
, 10);
1037 if (!run_to_completion
)
1038 spin_unlock_irqrestore(&smi_info
->si_lock
, flags
);
1041 static void request_events(void *send_info
)
1043 struct smi_info
*smi_info
= send_info
;
1045 if (atomic_read(&smi_info
->stop_operation
) ||
1046 !smi_info
->has_event_buffer
)
1049 atomic_set(&smi_info
->req_events
, 1);
1052 static int initialized
;
1054 static void smi_timeout(unsigned long data
)
1056 struct smi_info
*smi_info
= (struct smi_info
*) data
;
1057 enum si_sm_result smi_result
;
1058 unsigned long flags
;
1059 unsigned long jiffies_now
;
1066 spin_lock_irqsave(&(smi_info
->si_lock
), flags
);
1068 do_gettimeofday(&t
);
1069 printk(KERN_DEBUG
"**Timer: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
1071 jiffies_now
= jiffies
;
1072 time_diff
= (((long)jiffies_now
- (long)smi_info
->last_timeout_jiffies
)
1073 * SI_USEC_PER_JIFFY
);
1074 smi_result
= smi_event_handler(smi_info
, time_diff
);
1076 spin_unlock_irqrestore(&(smi_info
->si_lock
), flags
);
1078 smi_info
->last_timeout_jiffies
= jiffies_now
;
1080 if ((smi_info
->irq
) && (!smi_info
->interrupt_disabled
)) {
1081 /* Running with interrupts, only do long timeouts. */
1082 timeout
= jiffies
+ SI_TIMEOUT_JIFFIES
;
1083 smi_inc_stat(smi_info
, long_timeouts
);
1088 * If the state machine asks for a short delay, then shorten
1089 * the timer timeout.
1091 if (smi_result
== SI_SM_CALL_WITH_DELAY
) {
1092 smi_inc_stat(smi_info
, short_timeouts
);
1093 timeout
= jiffies
+ 1;
1095 smi_inc_stat(smi_info
, long_timeouts
);
1096 timeout
= jiffies
+ SI_TIMEOUT_JIFFIES
;
1100 if (smi_result
!= SI_SM_IDLE
)
1101 mod_timer(&(smi_info
->si_timer
), timeout
);
1104 static irqreturn_t
si_irq_handler(int irq
, void *data
)
1106 struct smi_info
*smi_info
= data
;
1107 unsigned long flags
;
1112 spin_lock_irqsave(&(smi_info
->si_lock
), flags
);
1114 smi_inc_stat(smi_info
, interrupts
);
1117 do_gettimeofday(&t
);
1118 printk(KERN_DEBUG
"**Interrupt: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
1120 smi_event_handler(smi_info
, 0);
1121 spin_unlock_irqrestore(&(smi_info
->si_lock
), flags
);
1125 static irqreturn_t
si_bt_irq_handler(int irq
, void *data
)
1127 struct smi_info
*smi_info
= data
;
1128 /* We need to clear the IRQ flag for the BT interface. */
1129 smi_info
->io
.outputb(&smi_info
->io
, IPMI_BT_INTMASK_REG
,
1130 IPMI_BT_INTMASK_CLEAR_IRQ_BIT
1131 | IPMI_BT_INTMASK_ENABLE_IRQ_BIT
);
1132 return si_irq_handler(irq
, data
);
1135 static int smi_start_processing(void *send_info
,
1138 struct smi_info
*new_smi
= send_info
;
1141 new_smi
->intf
= intf
;
1143 /* Try to claim any interrupts. */
1144 if (new_smi
->irq_setup
)
1145 new_smi
->irq_setup(new_smi
);
1147 /* Set up the timer that drives the interface. */
1148 setup_timer(&new_smi
->si_timer
, smi_timeout
, (long)new_smi
);
1149 new_smi
->last_timeout_jiffies
= jiffies
;
1150 mod_timer(&new_smi
->si_timer
, jiffies
+ SI_TIMEOUT_JIFFIES
);
1153 * Check if the user forcefully enabled the daemon.
1155 if (new_smi
->intf_num
< num_force_kipmid
)
1156 enable
= force_kipmid
[new_smi
->intf_num
];
1158 * The BT interface is efficient enough to not need a thread,
1159 * and there is no need for a thread if we have interrupts.
1161 else if ((new_smi
->si_type
!= SI_BT
) && (!new_smi
->irq
))
1165 new_smi
->thread
= kthread_run(ipmi_thread
, new_smi
,
1166 "kipmi%d", new_smi
->intf_num
);
1167 if (IS_ERR(new_smi
->thread
)) {
1168 dev_notice(new_smi
->dev
, "Could not start"
1169 " kernel thread due to error %ld, only using"
1170 " timers to drive the interface\n",
1171 PTR_ERR(new_smi
->thread
));
1172 new_smi
->thread
= NULL
;
1179 static int get_smi_info(void *send_info
, struct ipmi_smi_info
*data
)
1181 struct smi_info
*smi
= send_info
;
1183 data
->addr_src
= smi
->addr_source
;
1184 data
->dev
= smi
->dev
;
1185 data
->addr_info
= smi
->addr_info
;
1186 get_device(smi
->dev
);
1191 static void set_maintenance_mode(void *send_info
, int enable
)
1193 struct smi_info
*smi_info
= send_info
;
1196 atomic_set(&smi_info
->req_events
, 0);
1199 static struct ipmi_smi_handlers handlers
= {
1200 .owner
= THIS_MODULE
,
1201 .start_processing
= smi_start_processing
,
1202 .get_smi_info
= get_smi_info
,
1204 .request_events
= request_events
,
1205 .set_maintenance_mode
= set_maintenance_mode
,
1206 .set_run_to_completion
= set_run_to_completion
,
1211 * There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
1212 * a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS.
1215 static LIST_HEAD(smi_infos
);
1216 static DEFINE_MUTEX(smi_infos_lock
);
1217 static int smi_num
; /* Used to sequence the SMIs */
1219 #define DEFAULT_REGSPACING 1
1220 #define DEFAULT_REGSIZE 1
1223 static bool si_tryacpi
= 1;
1226 static bool si_trydmi
= 1;
1228 static bool si_tryplatform
= 1;
1230 static bool si_trypci
= 1;
1232 static bool si_trydefaults
= 1;
1233 static char *si_type
[SI_MAX_PARMS
];
1234 #define MAX_SI_TYPE_STR 30
1235 static char si_type_str
[MAX_SI_TYPE_STR
];
1236 static unsigned long addrs
[SI_MAX_PARMS
];
1237 static unsigned int num_addrs
;
1238 static unsigned int ports
[SI_MAX_PARMS
];
1239 static unsigned int num_ports
;
1240 static int irqs
[SI_MAX_PARMS
];
1241 static unsigned int num_irqs
;
1242 static int regspacings
[SI_MAX_PARMS
];
1243 static unsigned int num_regspacings
;
1244 static int regsizes
[SI_MAX_PARMS
];
1245 static unsigned int num_regsizes
;
1246 static int regshifts
[SI_MAX_PARMS
];
1247 static unsigned int num_regshifts
;
1248 static int slave_addrs
[SI_MAX_PARMS
]; /* Leaving 0 chooses the default value */
1249 static unsigned int num_slave_addrs
;
1251 #define IPMI_IO_ADDR_SPACE 0
1252 #define IPMI_MEM_ADDR_SPACE 1
1253 static char *addr_space_to_str
[] = { "i/o", "mem" };
1255 static int hotmod_handler(const char *val
, struct kernel_param
*kp
);
1257 module_param_call(hotmod
, hotmod_handler
, NULL
, NULL
, 0200);
1258 MODULE_PARM_DESC(hotmod
, "Add and remove interfaces. See"
1259 " Documentation/IPMI.txt in the kernel sources for the"
1263 module_param_named(tryacpi
, si_tryacpi
, bool, 0);
1264 MODULE_PARM_DESC(tryacpi
, "Setting this to zero will disable the"
1265 " default scan of the interfaces identified via ACPI");
1268 module_param_named(trydmi
, si_trydmi
, bool, 0);
1269 MODULE_PARM_DESC(trydmi
, "Setting this to zero will disable the"
1270 " default scan of the interfaces identified via DMI");
1272 module_param_named(tryplatform
, si_tryplatform
, bool, 0);
1273 MODULE_PARM_DESC(tryacpi
, "Setting this to zero will disable the"
1274 " default scan of the interfaces identified via platform"
1275 " interfaces like openfirmware");
1277 module_param_named(trypci
, si_trypci
, bool, 0);
1278 MODULE_PARM_DESC(tryacpi
, "Setting this to zero will disable the"
1279 " default scan of the interfaces identified via pci");
1281 module_param_named(trydefaults
, si_trydefaults
, bool, 0);
1282 MODULE_PARM_DESC(trydefaults
, "Setting this to 'false' will disable the"
1283 " default scan of the KCS and SMIC interface at the standard"
1285 module_param_string(type
, si_type_str
, MAX_SI_TYPE_STR
, 0);
1286 MODULE_PARM_DESC(type
, "Defines the type of each interface, each"
1287 " interface separated by commas. The types are 'kcs',"
1288 " 'smic', and 'bt'. For example si_type=kcs,bt will set"
1289 " the first interface to kcs and the second to bt");
1290 module_param_array(addrs
, ulong
, &num_addrs
, 0);
1291 MODULE_PARM_DESC(addrs
, "Sets the memory address of each interface, the"
1292 " addresses separated by commas. Only use if an interface"
1293 " is in memory. Otherwise, set it to zero or leave"
1295 module_param_array(ports
, uint
, &num_ports
, 0);
1296 MODULE_PARM_DESC(ports
, "Sets the port address of each interface, the"
1297 " addresses separated by commas. Only use if an interface"
1298 " is a port. Otherwise, set it to zero or leave"
1300 module_param_array(irqs
, int, &num_irqs
, 0);
1301 MODULE_PARM_DESC(irqs
, "Sets the interrupt of each interface, the"
1302 " addresses separated by commas. Only use if an interface"
1303 " has an interrupt. Otherwise, set it to zero or leave"
1305 module_param_array(regspacings
, int, &num_regspacings
, 0);
1306 MODULE_PARM_DESC(regspacings
, "The number of bytes between the start address"
1307 " and each successive register used by the interface. For"
1308 " instance, if the start address is 0xca2 and the spacing"
1309 " is 2, then the second address is at 0xca4. Defaults"
1311 module_param_array(regsizes
, int, &num_regsizes
, 0);
1312 MODULE_PARM_DESC(regsizes
, "The size of the specific IPMI register in bytes."
1313 " This should generally be 1, 2, 4, or 8 for an 8-bit,"
1314 " 16-bit, 32-bit, or 64-bit register. Use this if you"
1315 " the 8-bit IPMI register has to be read from a larger"
1317 module_param_array(regshifts
, int, &num_regshifts
, 0);
1318 MODULE_PARM_DESC(regshifts
, "The amount to shift the data read from the."
1319 " IPMI register, in bits. For instance, if the data"
1320 " is read from a 32-bit word and the IPMI data is in"
1321 " bit 8-15, then the shift would be 8");
1322 module_param_array(slave_addrs
, int, &num_slave_addrs
, 0);
1323 MODULE_PARM_DESC(slave_addrs
, "Set the default IPMB slave address for"
1324 " the controller. Normally this is 0x20, but can be"
1325 " overridden by this parm. This is an array indexed"
1326 " by interface number.");
1327 module_param_array(force_kipmid
, int, &num_force_kipmid
, 0);
1328 MODULE_PARM_DESC(force_kipmid
, "Force the kipmi daemon to be enabled (1) or"
1329 " disabled(0). Normally the IPMI driver auto-detects"
1330 " this, but the value may be overridden by this parm.");
1331 module_param(unload_when_empty
, int, 0);
1332 MODULE_PARM_DESC(unload_when_empty
, "Unload the module if no interfaces are"
1333 " specified or found, default is 1. Setting to 0"
1334 " is useful for hot add of devices using hotmod.");
1335 module_param_array(kipmid_max_busy_us
, uint
, &num_max_busy_us
, 0644);
1336 MODULE_PARM_DESC(kipmid_max_busy_us
,
1337 "Max time (in microseconds) to busy-wait for IPMI data before"
1338 " sleeping. 0 (default) means to wait forever. Set to 100-500"
1339 " if kipmid is using up a lot of CPU time.");
1342 static void std_irq_cleanup(struct smi_info
*info
)
1344 if (info
->si_type
== SI_BT
)
1345 /* Disable the interrupt in the BT interface. */
1346 info
->io
.outputb(&info
->io
, IPMI_BT_INTMASK_REG
, 0);
1347 free_irq(info
->irq
, info
);
1350 static int std_irq_setup(struct smi_info
*info
)
1357 if (info
->si_type
== SI_BT
) {
1358 rv
= request_irq(info
->irq
,
1364 /* Enable the interrupt in the BT interface. */
1365 info
->io
.outputb(&info
->io
, IPMI_BT_INTMASK_REG
,
1366 IPMI_BT_INTMASK_ENABLE_IRQ_BIT
);
1368 rv
= request_irq(info
->irq
,
1374 dev_warn(info
->dev
, "%s unable to claim interrupt %d,"
1375 " running polled\n",
1376 DEVICE_NAME
, info
->irq
);
1379 info
->irq_cleanup
= std_irq_cleanup
;
1380 dev_info(info
->dev
, "Using irq %d\n", info
->irq
);
1386 static unsigned char port_inb(struct si_sm_io
*io
, unsigned int offset
)
1388 unsigned int addr
= io
->addr_data
;
1390 return inb(addr
+ (offset
* io
->regspacing
));
1393 static void port_outb(struct si_sm_io
*io
, unsigned int offset
,
1396 unsigned int addr
= io
->addr_data
;
1398 outb(b
, addr
+ (offset
* io
->regspacing
));
1401 static unsigned char port_inw(struct si_sm_io
*io
, unsigned int offset
)
1403 unsigned int addr
= io
->addr_data
;
1405 return (inw(addr
+ (offset
* io
->regspacing
)) >> io
->regshift
) & 0xff;
1408 static void port_outw(struct si_sm_io
*io
, unsigned int offset
,
1411 unsigned int addr
= io
->addr_data
;
1413 outw(b
<< io
->regshift
, addr
+ (offset
* io
->regspacing
));
1416 static unsigned char port_inl(struct si_sm_io
*io
, unsigned int offset
)
1418 unsigned int addr
= io
->addr_data
;
1420 return (inl(addr
+ (offset
* io
->regspacing
)) >> io
->regshift
) & 0xff;
1423 static void port_outl(struct si_sm_io
*io
, unsigned int offset
,
1426 unsigned int addr
= io
->addr_data
;
1428 outl(b
<< io
->regshift
, addr
+(offset
* io
->regspacing
));
1431 static void port_cleanup(struct smi_info
*info
)
1433 unsigned int addr
= info
->io
.addr_data
;
1437 for (idx
= 0; idx
< info
->io_size
; idx
++)
1438 release_region(addr
+ idx
* info
->io
.regspacing
,
1443 static int port_setup(struct smi_info
*info
)
1445 unsigned int addr
= info
->io
.addr_data
;
1451 info
->io_cleanup
= port_cleanup
;
1454 * Figure out the actual inb/inw/inl/etc routine to use based
1455 * upon the register size.
1457 switch (info
->io
.regsize
) {
1459 info
->io
.inputb
= port_inb
;
1460 info
->io
.outputb
= port_outb
;
1463 info
->io
.inputb
= port_inw
;
1464 info
->io
.outputb
= port_outw
;
1467 info
->io
.inputb
= port_inl
;
1468 info
->io
.outputb
= port_outl
;
1471 dev_warn(info
->dev
, "Invalid register size: %d\n",
1477 * Some BIOSes reserve disjoint I/O regions in their ACPI
1478 * tables. This causes problems when trying to register the
1479 * entire I/O region. Therefore we must register each I/O
1482 for (idx
= 0; idx
< info
->io_size
; idx
++) {
1483 if (request_region(addr
+ idx
* info
->io
.regspacing
,
1484 info
->io
.regsize
, DEVICE_NAME
) == NULL
) {
1485 /* Undo allocations */
1487 release_region(addr
+ idx
* info
->io
.regspacing
,
1496 static unsigned char intf_mem_inb(struct si_sm_io
*io
, unsigned int offset
)
1498 return readb((io
->addr
)+(offset
* io
->regspacing
));
1501 static void intf_mem_outb(struct si_sm_io
*io
, unsigned int offset
,
1504 writeb(b
, (io
->addr
)+(offset
* io
->regspacing
));
1507 static unsigned char intf_mem_inw(struct si_sm_io
*io
, unsigned int offset
)
1509 return (readw((io
->addr
)+(offset
* io
->regspacing
)) >> io
->regshift
)
1513 static void intf_mem_outw(struct si_sm_io
*io
, unsigned int offset
,
1516 writeb(b
<< io
->regshift
, (io
->addr
)+(offset
* io
->regspacing
));
1519 static unsigned char intf_mem_inl(struct si_sm_io
*io
, unsigned int offset
)
1521 return (readl((io
->addr
)+(offset
* io
->regspacing
)) >> io
->regshift
)
1525 static void intf_mem_outl(struct si_sm_io
*io
, unsigned int offset
,
1528 writel(b
<< io
->regshift
, (io
->addr
)+(offset
* io
->regspacing
));
1532 static unsigned char mem_inq(struct si_sm_io
*io
, unsigned int offset
)
1534 return (readq((io
->addr
)+(offset
* io
->regspacing
)) >> io
->regshift
)
1538 static void mem_outq(struct si_sm_io
*io
, unsigned int offset
,
1541 writeq(b
<< io
->regshift
, (io
->addr
)+(offset
* io
->regspacing
));
1545 static void mem_cleanup(struct smi_info
*info
)
1547 unsigned long addr
= info
->io
.addr_data
;
1550 if (info
->io
.addr
) {
1551 iounmap(info
->io
.addr
);
1553 mapsize
= ((info
->io_size
* info
->io
.regspacing
)
1554 - (info
->io
.regspacing
- info
->io
.regsize
));
1556 release_mem_region(addr
, mapsize
);
1560 static int mem_setup(struct smi_info
*info
)
1562 unsigned long addr
= info
->io
.addr_data
;
1568 info
->io_cleanup
= mem_cleanup
;
1571 * Figure out the actual readb/readw/readl/etc routine to use based
1572 * upon the register size.
1574 switch (info
->io
.regsize
) {
1576 info
->io
.inputb
= intf_mem_inb
;
1577 info
->io
.outputb
= intf_mem_outb
;
1580 info
->io
.inputb
= intf_mem_inw
;
1581 info
->io
.outputb
= intf_mem_outw
;
1584 info
->io
.inputb
= intf_mem_inl
;
1585 info
->io
.outputb
= intf_mem_outl
;
1589 info
->io
.inputb
= mem_inq
;
1590 info
->io
.outputb
= mem_outq
;
1594 dev_warn(info
->dev
, "Invalid register size: %d\n",
1600 * Calculate the total amount of memory to claim. This is an
1601 * unusual looking calculation, but it avoids claiming any
1602 * more memory than it has to. It will claim everything
1603 * between the first address to the end of the last full
1606 mapsize
= ((info
->io_size
* info
->io
.regspacing
)
1607 - (info
->io
.regspacing
- info
->io
.regsize
));
1609 if (request_mem_region(addr
, mapsize
, DEVICE_NAME
) == NULL
)
1612 info
->io
.addr
= ioremap(addr
, mapsize
);
1613 if (info
->io
.addr
== NULL
) {
1614 release_mem_region(addr
, mapsize
);
1621 * Parms come in as <op1>[:op2[:op3...]]. ops are:
1622 * add|remove,kcs|bt|smic,mem|i/o,<address>[,<opt1>[,<opt2>[,...]]]
1630 enum hotmod_op
{ HM_ADD
, HM_REMOVE
};
1631 struct hotmod_vals
{
1635 static struct hotmod_vals hotmod_ops
[] = {
1637 { "remove", HM_REMOVE
},
1640 static struct hotmod_vals hotmod_si
[] = {
1642 { "smic", SI_SMIC
},
1646 static struct hotmod_vals hotmod_as
[] = {
1647 { "mem", IPMI_MEM_ADDR_SPACE
},
1648 { "i/o", IPMI_IO_ADDR_SPACE
},
1652 static int parse_str(struct hotmod_vals
*v
, int *val
, char *name
, char **curr
)
1657 s
= strchr(*curr
, ',');
1659 printk(KERN_WARNING PFX
"No hotmod %s given.\n", name
);
1664 for (i
= 0; hotmod_ops
[i
].name
; i
++) {
1665 if (strcmp(*curr
, v
[i
].name
) == 0) {
1672 printk(KERN_WARNING PFX
"Invalid hotmod %s '%s'\n", name
, *curr
);
1676 static int check_hotmod_int_op(const char *curr
, const char *option
,
1677 const char *name
, int *val
)
1681 if (strcmp(curr
, name
) == 0) {
1683 printk(KERN_WARNING PFX
1684 "No option given for '%s'\n",
1688 *val
= simple_strtoul(option
, &n
, 0);
1689 if ((*n
!= '\0') || (*option
== '\0')) {
1690 printk(KERN_WARNING PFX
1691 "Bad option given for '%s'\n",
1700 static struct smi_info
*smi_info_alloc(void)
1702 struct smi_info
*info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
1705 spin_lock_init(&info
->si_lock
);
1709 static int hotmod_handler(const char *val
, struct kernel_param
*kp
)
1711 char *str
= kstrdup(val
, GFP_KERNEL
);
1713 char *next
, *curr
, *s
, *n
, *o
;
1715 enum si_type si_type
;
1725 struct smi_info
*info
;
1730 /* Kill any trailing spaces, as we can get a "\n" from echo. */
1733 while ((ival
>= 0) && isspace(str
[ival
])) {
1738 for (curr
= str
; curr
; curr
= next
) {
1743 ipmb
= 0; /* Choose the default if not specified */
1745 next
= strchr(curr
, ':');
1751 rv
= parse_str(hotmod_ops
, &ival
, "operation", &curr
);
1756 rv
= parse_str(hotmod_si
, &ival
, "interface type", &curr
);
1761 rv
= parse_str(hotmod_as
, &addr_space
, "address space", &curr
);
1765 s
= strchr(curr
, ',');
1770 addr
= simple_strtoul(curr
, &n
, 0);
1771 if ((*n
!= '\0') || (*curr
== '\0')) {
1772 printk(KERN_WARNING PFX
"Invalid hotmod address"
1779 s
= strchr(curr
, ',');
1784 o
= strchr(curr
, '=');
1789 rv
= check_hotmod_int_op(curr
, o
, "rsp", ®spacing
);
1794 rv
= check_hotmod_int_op(curr
, o
, "rsi", ®size
);
1799 rv
= check_hotmod_int_op(curr
, o
, "rsh", ®shift
);
1804 rv
= check_hotmod_int_op(curr
, o
, "irq", &irq
);
1809 rv
= check_hotmod_int_op(curr
, o
, "ipmb", &ipmb
);
1816 printk(KERN_WARNING PFX
1817 "Invalid hotmod option '%s'\n",
1823 info
= smi_info_alloc();
1829 info
->addr_source
= SI_HOTMOD
;
1830 info
->si_type
= si_type
;
1831 info
->io
.addr_data
= addr
;
1832 info
->io
.addr_type
= addr_space
;
1833 if (addr_space
== IPMI_MEM_ADDR_SPACE
)
1834 info
->io_setup
= mem_setup
;
1836 info
->io_setup
= port_setup
;
1838 info
->io
.addr
= NULL
;
1839 info
->io
.regspacing
= regspacing
;
1840 if (!info
->io
.regspacing
)
1841 info
->io
.regspacing
= DEFAULT_REGSPACING
;
1842 info
->io
.regsize
= regsize
;
1843 if (!info
->io
.regsize
)
1844 info
->io
.regsize
= DEFAULT_REGSPACING
;
1845 info
->io
.regshift
= regshift
;
1848 info
->irq_setup
= std_irq_setup
;
1849 info
->slave_addr
= ipmb
;
1856 rv
= try_smi_init(info
);
1858 cleanup_one_si(info
);
1863 struct smi_info
*e
, *tmp_e
;
1865 mutex_lock(&smi_infos_lock
);
1866 list_for_each_entry_safe(e
, tmp_e
, &smi_infos
, link
) {
1867 if (e
->io
.addr_type
!= addr_space
)
1869 if (e
->si_type
!= si_type
)
1871 if (e
->io
.addr_data
== addr
)
1874 mutex_unlock(&smi_infos_lock
);
1883 static int hardcode_find_bmc(void)
1887 struct smi_info
*info
;
1889 for (i
= 0; i
< SI_MAX_PARMS
; i
++) {
1890 if (!ports
[i
] && !addrs
[i
])
1893 info
= smi_info_alloc();
1897 info
->addr_source
= SI_HARDCODED
;
1898 printk(KERN_INFO PFX
"probing via hardcoded address\n");
1900 if (!si_type
[i
] || strcmp(si_type
[i
], "kcs") == 0) {
1901 info
->si_type
= SI_KCS
;
1902 } else if (strcmp(si_type
[i
], "smic") == 0) {
1903 info
->si_type
= SI_SMIC
;
1904 } else if (strcmp(si_type
[i
], "bt") == 0) {
1905 info
->si_type
= SI_BT
;
1907 printk(KERN_WARNING PFX
"Interface type specified "
1908 "for interface %d, was invalid: %s\n",
1916 info
->io_setup
= port_setup
;
1917 info
->io
.addr_data
= ports
[i
];
1918 info
->io
.addr_type
= IPMI_IO_ADDR_SPACE
;
1919 } else if (addrs
[i
]) {
1921 info
->io_setup
= mem_setup
;
1922 info
->io
.addr_data
= addrs
[i
];
1923 info
->io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
1925 printk(KERN_WARNING PFX
"Interface type specified "
1926 "for interface %d, but port and address were "
1927 "not set or set to zero.\n", i
);
1932 info
->io
.addr
= NULL
;
1933 info
->io
.regspacing
= regspacings
[i
];
1934 if (!info
->io
.regspacing
)
1935 info
->io
.regspacing
= DEFAULT_REGSPACING
;
1936 info
->io
.regsize
= regsizes
[i
];
1937 if (!info
->io
.regsize
)
1938 info
->io
.regsize
= DEFAULT_REGSPACING
;
1939 info
->io
.regshift
= regshifts
[i
];
1940 info
->irq
= irqs
[i
];
1942 info
->irq_setup
= std_irq_setup
;
1943 info
->slave_addr
= slave_addrs
[i
];
1945 if (!add_smi(info
)) {
1946 if (try_smi_init(info
))
1947 cleanup_one_si(info
);
1958 #include <linux/acpi.h>
1961 * Once we get an ACPI failure, we don't try any more, because we go
1962 * through the tables sequentially. Once we don't find a table, there
1965 static int acpi_failure
;
1967 /* For GPE-type interrupts. */
1968 static u32
ipmi_acpi_gpe(acpi_handle gpe_device
,
1969 u32 gpe_number
, void *context
)
1971 struct smi_info
*smi_info
= context
;
1972 unsigned long flags
;
1977 spin_lock_irqsave(&(smi_info
->si_lock
), flags
);
1979 smi_inc_stat(smi_info
, interrupts
);
1982 do_gettimeofday(&t
);
1983 printk("**ACPI_GPE: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
1985 smi_event_handler(smi_info
, 0);
1986 spin_unlock_irqrestore(&(smi_info
->si_lock
), flags
);
1988 return ACPI_INTERRUPT_HANDLED
;
1991 static void acpi_gpe_irq_cleanup(struct smi_info
*info
)
1996 acpi_remove_gpe_handler(NULL
, info
->irq
, &ipmi_acpi_gpe
);
1999 static int acpi_gpe_irq_setup(struct smi_info
*info
)
2006 /* FIXME - is level triggered right? */
2007 status
= acpi_install_gpe_handler(NULL
,
2009 ACPI_GPE_LEVEL_TRIGGERED
,
2012 if (status
!= AE_OK
) {
2013 dev_warn(info
->dev
, "%s unable to claim ACPI GPE %d,"
2014 " running polled\n", DEVICE_NAME
, info
->irq
);
2018 info
->irq_cleanup
= acpi_gpe_irq_cleanup
;
2019 dev_info(info
->dev
, "Using ACPI GPE %d\n", info
->irq
);
2026 * http://h21007.www2.hp.com/portal/download/files/unprot/hpspmi.pdf
2037 s8 CreatorRevision
[4];
2040 s16 SpecificationRevision
;
2043 * Bit 0 - SCI interrupt supported
2044 * Bit 1 - I/O APIC/SAPIC
2049 * If bit 0 of InterruptType is set, then this is the SCI
2050 * interrupt in the GPEx_STS register.
2057 * If bit 1 of InterruptType is set, then this is the I/O
2058 * APIC/SAPIC interrupt.
2060 u32 GlobalSystemInterrupt
;
2062 /* The actual register address. */
2063 struct acpi_generic_address addr
;
2067 s8 spmi_id
[1]; /* A '\0' terminated array starts here. */
2070 static int try_init_spmi(struct SPMITable
*spmi
)
2072 struct smi_info
*info
;
2075 if (spmi
->IPMIlegacy
!= 1) {
2076 printk(KERN_INFO PFX
"Bad SPMI legacy %d\n", spmi
->IPMIlegacy
);
2080 info
= smi_info_alloc();
2082 printk(KERN_ERR PFX
"Could not allocate SI data (3)\n");
2086 info
->addr_source
= SI_SPMI
;
2087 printk(KERN_INFO PFX
"probing via SPMI\n");
2089 /* Figure out the interface type. */
2090 switch (spmi
->InterfaceType
) {
2092 info
->si_type
= SI_KCS
;
2095 info
->si_type
= SI_SMIC
;
2098 info
->si_type
= SI_BT
;
2101 printk(KERN_INFO PFX
"Unknown ACPI/SPMI SI type %d\n",
2102 spmi
->InterfaceType
);
2107 if (spmi
->InterruptType
& 1) {
2108 /* We've got a GPE interrupt. */
2109 info
->irq
= spmi
->GPE
;
2110 info
->irq_setup
= acpi_gpe_irq_setup
;
2111 } else if (spmi
->InterruptType
& 2) {
2112 /* We've got an APIC/SAPIC interrupt. */
2113 info
->irq
= spmi
->GlobalSystemInterrupt
;
2114 info
->irq_setup
= std_irq_setup
;
2116 /* Use the default interrupt setting. */
2118 info
->irq_setup
= NULL
;
2121 if (spmi
->addr
.bit_width
) {
2122 /* A (hopefully) properly formed register bit width. */
2123 info
->io
.regspacing
= spmi
->addr
.bit_width
/ 8;
2125 info
->io
.regspacing
= DEFAULT_REGSPACING
;
2127 info
->io
.regsize
= info
->io
.regspacing
;
2128 info
->io
.regshift
= spmi
->addr
.bit_offset
;
2130 if (spmi
->addr
.space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
) {
2131 info
->io_setup
= mem_setup
;
2132 info
->io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
2133 } else if (spmi
->addr
.space_id
== ACPI_ADR_SPACE_SYSTEM_IO
) {
2134 info
->io_setup
= port_setup
;
2135 info
->io
.addr_type
= IPMI_IO_ADDR_SPACE
;
2138 printk(KERN_WARNING PFX
"Unknown ACPI I/O Address type\n");
2141 info
->io
.addr_data
= spmi
->addr
.address
;
2143 pr_info("ipmi_si: SPMI: %s %#lx regsize %d spacing %d irq %d\n",
2144 (info
->io
.addr_type
== IPMI_IO_ADDR_SPACE
) ? "io" : "mem",
2145 info
->io
.addr_data
, info
->io
.regsize
, info
->io
.regspacing
,
2155 static void spmi_find_bmc(void)
2158 struct SPMITable
*spmi
;
2167 for (i
= 0; ; i
++) {
2168 status
= acpi_get_table(ACPI_SIG_SPMI
, i
+1,
2169 (struct acpi_table_header
**)&spmi
);
2170 if (status
!= AE_OK
)
2173 try_init_spmi(spmi
);
2177 static int ipmi_pnp_probe(struct pnp_dev
*dev
,
2178 const struct pnp_device_id
*dev_id
)
2180 struct acpi_device
*acpi_dev
;
2181 struct smi_info
*info
;
2182 struct resource
*res
, *res_second
;
2185 unsigned long long tmp
;
2188 acpi_dev
= pnp_acpi_device(dev
);
2192 info
= smi_info_alloc();
2196 info
->addr_source
= SI_ACPI
;
2197 printk(KERN_INFO PFX
"probing via ACPI\n");
2199 handle
= acpi_dev
->handle
;
2200 info
->addr_info
.acpi_info
.acpi_handle
= handle
;
2202 /* _IFT tells us the interface type: KCS, BT, etc */
2203 status
= acpi_evaluate_integer(handle
, "_IFT", NULL
, &tmp
);
2204 if (ACPI_FAILURE(status
))
2209 info
->si_type
= SI_KCS
;
2212 info
->si_type
= SI_SMIC
;
2215 info
->si_type
= SI_BT
;
2218 dev_info(&dev
->dev
, "unknown IPMI type %lld\n", tmp
);
2222 res
= pnp_get_resource(dev
, IORESOURCE_IO
, 0);
2224 info
->io_setup
= port_setup
;
2225 info
->io
.addr_type
= IPMI_IO_ADDR_SPACE
;
2227 res
= pnp_get_resource(dev
, IORESOURCE_MEM
, 0);
2229 info
->io_setup
= mem_setup
;
2230 info
->io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
2234 dev_err(&dev
->dev
, "no I/O or memory address\n");
2237 info
->io
.addr_data
= res
->start
;
2239 info
->io
.regspacing
= DEFAULT_REGSPACING
;
2240 res_second
= pnp_get_resource(dev
,
2241 (info
->io
.addr_type
== IPMI_IO_ADDR_SPACE
) ?
2242 IORESOURCE_IO
: IORESOURCE_MEM
,
2245 if (res_second
->start
> info
->io
.addr_data
)
2246 info
->io
.regspacing
= res_second
->start
- info
->io
.addr_data
;
2248 info
->io
.regsize
= DEFAULT_REGSPACING
;
2249 info
->io
.regshift
= 0;
2251 /* If _GPE exists, use it; otherwise use standard interrupts */
2252 status
= acpi_evaluate_integer(handle
, "_GPE", NULL
, &tmp
);
2253 if (ACPI_SUCCESS(status
)) {
2255 info
->irq_setup
= acpi_gpe_irq_setup
;
2256 } else if (pnp_irq_valid(dev
, 0)) {
2257 info
->irq
= pnp_irq(dev
, 0);
2258 info
->irq_setup
= std_irq_setup
;
2261 info
->dev
= &dev
->dev
;
2262 pnp_set_drvdata(dev
, info
);
2264 dev_info(info
->dev
, "%pR regsize %d spacing %d irq %d\n",
2265 res
, info
->io
.regsize
, info
->io
.regspacing
,
2279 static void ipmi_pnp_remove(struct pnp_dev
*dev
)
2281 struct smi_info
*info
= pnp_get_drvdata(dev
);
2283 cleanup_one_si(info
);
2286 static const struct pnp_device_id pnp_dev_table
[] = {
2291 static struct pnp_driver ipmi_pnp_driver
= {
2292 .name
= DEVICE_NAME
,
2293 .probe
= ipmi_pnp_probe
,
2294 .remove
= ipmi_pnp_remove
,
2295 .id_table
= pnp_dev_table
,
2298 MODULE_DEVICE_TABLE(pnp
, pnp_dev_table
);
2302 struct dmi_ipmi_data
{
2305 unsigned long base_addr
;
2311 static int decode_dmi(const struct dmi_header
*dm
,
2312 struct dmi_ipmi_data
*dmi
)
2314 const u8
*data
= (const u8
*)dm
;
2315 unsigned long base_addr
;
2317 u8 len
= dm
->length
;
2319 dmi
->type
= data
[4];
2321 memcpy(&base_addr
, data
+8, sizeof(unsigned long));
2323 if (base_addr
& 1) {
2325 base_addr
&= 0xFFFE;
2326 dmi
->addr_space
= IPMI_IO_ADDR_SPACE
;
2329 dmi
->addr_space
= IPMI_MEM_ADDR_SPACE
;
2331 /* If bit 4 of byte 0x10 is set, then the lsb for the address
2333 dmi
->base_addr
= base_addr
| ((data
[0x10] & 0x10) >> 4);
2335 dmi
->irq
= data
[0x11];
2337 /* The top two bits of byte 0x10 hold the register spacing. */
2338 reg_spacing
= (data
[0x10] & 0xC0) >> 6;
2339 switch (reg_spacing
) {
2340 case 0x00: /* Byte boundaries */
2343 case 0x01: /* 32-bit boundaries */
2346 case 0x02: /* 16-byte boundaries */
2350 /* Some other interface, just ignore it. */
2356 * Note that technically, the lower bit of the base
2357 * address should be 1 if the address is I/O and 0 if
2358 * the address is in memory. So many systems get that
2359 * wrong (and all that I have seen are I/O) so we just
2360 * ignore that bit and assume I/O. Systems that use
2361 * memory should use the newer spec, anyway.
2363 dmi
->base_addr
= base_addr
& 0xfffe;
2364 dmi
->addr_space
= IPMI_IO_ADDR_SPACE
;
2368 dmi
->slave_addr
= data
[6];
2373 static void try_init_dmi(struct dmi_ipmi_data
*ipmi_data
)
2375 struct smi_info
*info
;
2377 info
= smi_info_alloc();
2379 printk(KERN_ERR PFX
"Could not allocate SI data\n");
2383 info
->addr_source
= SI_SMBIOS
;
2384 printk(KERN_INFO PFX
"probing via SMBIOS\n");
2386 switch (ipmi_data
->type
) {
2387 case 0x01: /* KCS */
2388 info
->si_type
= SI_KCS
;
2390 case 0x02: /* SMIC */
2391 info
->si_type
= SI_SMIC
;
2394 info
->si_type
= SI_BT
;
2401 switch (ipmi_data
->addr_space
) {
2402 case IPMI_MEM_ADDR_SPACE
:
2403 info
->io_setup
= mem_setup
;
2404 info
->io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
2407 case IPMI_IO_ADDR_SPACE
:
2408 info
->io_setup
= port_setup
;
2409 info
->io
.addr_type
= IPMI_IO_ADDR_SPACE
;
2414 printk(KERN_WARNING PFX
"Unknown SMBIOS I/O Address type: %d\n",
2415 ipmi_data
->addr_space
);
2418 info
->io
.addr_data
= ipmi_data
->base_addr
;
2420 info
->io
.regspacing
= ipmi_data
->offset
;
2421 if (!info
->io
.regspacing
)
2422 info
->io
.regspacing
= DEFAULT_REGSPACING
;
2423 info
->io
.regsize
= DEFAULT_REGSPACING
;
2424 info
->io
.regshift
= 0;
2426 info
->slave_addr
= ipmi_data
->slave_addr
;
2428 info
->irq
= ipmi_data
->irq
;
2430 info
->irq_setup
= std_irq_setup
;
2432 pr_info("ipmi_si: SMBIOS: %s %#lx regsize %d spacing %d irq %d\n",
2433 (info
->io
.addr_type
== IPMI_IO_ADDR_SPACE
) ? "io" : "mem",
2434 info
->io
.addr_data
, info
->io
.regsize
, info
->io
.regspacing
,
2441 static void dmi_find_bmc(void)
2443 const struct dmi_device
*dev
= NULL
;
2444 struct dmi_ipmi_data data
;
2447 while ((dev
= dmi_find_device(DMI_DEV_TYPE_IPMI
, NULL
, dev
))) {
2448 memset(&data
, 0, sizeof(data
));
2449 rv
= decode_dmi((const struct dmi_header
*) dev
->device_data
,
2452 try_init_dmi(&data
);
2455 #endif /* CONFIG_DMI */
2459 #define PCI_ERMC_CLASSCODE 0x0C0700
2460 #define PCI_ERMC_CLASSCODE_MASK 0xffffff00
2461 #define PCI_ERMC_CLASSCODE_TYPE_MASK 0xff
2462 #define PCI_ERMC_CLASSCODE_TYPE_SMIC 0x00
2463 #define PCI_ERMC_CLASSCODE_TYPE_KCS 0x01
2464 #define PCI_ERMC_CLASSCODE_TYPE_BT 0x02
2466 #define PCI_HP_VENDOR_ID 0x103C
2467 #define PCI_MMC_DEVICE_ID 0x121A
2468 #define PCI_MMC_ADDR_CW 0x10
2470 static void ipmi_pci_cleanup(struct smi_info
*info
)
2472 struct pci_dev
*pdev
= info
->addr_source_data
;
2474 pci_disable_device(pdev
);
2477 static int ipmi_pci_probe_regspacing(struct smi_info
*info
)
2479 if (info
->si_type
== SI_KCS
) {
2480 unsigned char status
;
2483 info
->io
.regsize
= DEFAULT_REGSIZE
;
2484 info
->io
.regshift
= 0;
2486 info
->handlers
= &kcs_smi_handlers
;
2488 /* detect 1, 4, 16byte spacing */
2489 for (regspacing
= DEFAULT_REGSPACING
; regspacing
<= 16;) {
2490 info
->io
.regspacing
= regspacing
;
2491 if (info
->io_setup(info
)) {
2493 "Could not setup I/O space\n");
2494 return DEFAULT_REGSPACING
;
2496 /* write invalid cmd */
2497 info
->io
.outputb(&info
->io
, 1, 0x10);
2498 /* read status back */
2499 status
= info
->io
.inputb(&info
->io
, 1);
2500 info
->io_cleanup(info
);
2506 return DEFAULT_REGSPACING
;
2509 static int ipmi_pci_probe(struct pci_dev
*pdev
,
2510 const struct pci_device_id
*ent
)
2513 int class_type
= pdev
->class & PCI_ERMC_CLASSCODE_TYPE_MASK
;
2514 struct smi_info
*info
;
2516 info
= smi_info_alloc();
2520 info
->addr_source
= SI_PCI
;
2521 dev_info(&pdev
->dev
, "probing via PCI");
2523 switch (class_type
) {
2524 case PCI_ERMC_CLASSCODE_TYPE_SMIC
:
2525 info
->si_type
= SI_SMIC
;
2528 case PCI_ERMC_CLASSCODE_TYPE_KCS
:
2529 info
->si_type
= SI_KCS
;
2532 case PCI_ERMC_CLASSCODE_TYPE_BT
:
2533 info
->si_type
= SI_BT
;
2538 dev_info(&pdev
->dev
, "Unknown IPMI type: %d\n", class_type
);
2542 rv
= pci_enable_device(pdev
);
2544 dev_err(&pdev
->dev
, "couldn't enable PCI device\n");
2549 info
->addr_source_cleanup
= ipmi_pci_cleanup
;
2550 info
->addr_source_data
= pdev
;
2552 if (pci_resource_flags(pdev
, 0) & IORESOURCE_IO
) {
2553 info
->io_setup
= port_setup
;
2554 info
->io
.addr_type
= IPMI_IO_ADDR_SPACE
;
2556 info
->io_setup
= mem_setup
;
2557 info
->io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
2559 info
->io
.addr_data
= pci_resource_start(pdev
, 0);
2561 info
->io
.regspacing
= ipmi_pci_probe_regspacing(info
);
2562 info
->io
.regsize
= DEFAULT_REGSIZE
;
2563 info
->io
.regshift
= 0;
2565 info
->irq
= pdev
->irq
;
2567 info
->irq_setup
= std_irq_setup
;
2569 info
->dev
= &pdev
->dev
;
2570 pci_set_drvdata(pdev
, info
);
2572 dev_info(&pdev
->dev
, "%pR regsize %d spacing %d irq %d\n",
2573 &pdev
->resource
[0], info
->io
.regsize
, info
->io
.regspacing
,
2579 pci_disable_device(pdev
);
2585 static void ipmi_pci_remove(struct pci_dev
*pdev
)
2587 struct smi_info
*info
= pci_get_drvdata(pdev
);
2588 cleanup_one_si(info
);
2589 pci_disable_device(pdev
);
2592 static struct pci_device_id ipmi_pci_devices
[] = {
2593 { PCI_DEVICE(PCI_HP_VENDOR_ID
, PCI_MMC_DEVICE_ID
) },
2594 { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE
, PCI_ERMC_CLASSCODE_MASK
) },
2597 MODULE_DEVICE_TABLE(pci
, ipmi_pci_devices
);
2599 static struct pci_driver ipmi_pci_driver
= {
2600 .name
= DEVICE_NAME
,
2601 .id_table
= ipmi_pci_devices
,
2602 .probe
= ipmi_pci_probe
,
2603 .remove
= ipmi_pci_remove
,
2605 #endif /* CONFIG_PCI */
2607 static struct of_device_id ipmi_match
[];
2608 static int ipmi_probe(struct platform_device
*dev
)
2611 const struct of_device_id
*match
;
2612 struct smi_info
*info
;
2613 struct resource resource
;
2614 const __be32
*regsize
, *regspacing
, *regshift
;
2615 struct device_node
*np
= dev
->dev
.of_node
;
2619 dev_info(&dev
->dev
, "probing via device tree\n");
2621 match
= of_match_device(ipmi_match
, &dev
->dev
);
2625 ret
= of_address_to_resource(np
, 0, &resource
);
2627 dev_warn(&dev
->dev
, PFX
"invalid address from OF\n");
2631 regsize
= of_get_property(np
, "reg-size", &proplen
);
2632 if (regsize
&& proplen
!= 4) {
2633 dev_warn(&dev
->dev
, PFX
"invalid regsize from OF\n");
2637 regspacing
= of_get_property(np
, "reg-spacing", &proplen
);
2638 if (regspacing
&& proplen
!= 4) {
2639 dev_warn(&dev
->dev
, PFX
"invalid regspacing from OF\n");
2643 regshift
= of_get_property(np
, "reg-shift", &proplen
);
2644 if (regshift
&& proplen
!= 4) {
2645 dev_warn(&dev
->dev
, PFX
"invalid regshift from OF\n");
2649 info
= smi_info_alloc();
2653 "could not allocate memory for OF probe\n");
2657 info
->si_type
= (enum si_type
) match
->data
;
2658 info
->addr_source
= SI_DEVICETREE
;
2659 info
->irq_setup
= std_irq_setup
;
2661 if (resource
.flags
& IORESOURCE_IO
) {
2662 info
->io_setup
= port_setup
;
2663 info
->io
.addr_type
= IPMI_IO_ADDR_SPACE
;
2665 info
->io_setup
= mem_setup
;
2666 info
->io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
2669 info
->io
.addr_data
= resource
.start
;
2671 info
->io
.regsize
= regsize
? be32_to_cpup(regsize
) : DEFAULT_REGSIZE
;
2672 info
->io
.regspacing
= regspacing
? be32_to_cpup(regspacing
) : DEFAULT_REGSPACING
;
2673 info
->io
.regshift
= regshift
? be32_to_cpup(regshift
) : 0;
2675 info
->irq
= irq_of_parse_and_map(dev
->dev
.of_node
, 0);
2676 info
->dev
= &dev
->dev
;
2678 dev_dbg(&dev
->dev
, "addr 0x%lx regsize %d spacing %d irq %d\n",
2679 info
->io
.addr_data
, info
->io
.regsize
, info
->io
.regspacing
,
2682 dev_set_drvdata(&dev
->dev
, info
);
2684 ret
= add_smi(info
);
2693 static int ipmi_remove(struct platform_device
*dev
)
2696 cleanup_one_si(dev_get_drvdata(&dev
->dev
));
2701 static struct of_device_id ipmi_match
[] =
2703 { .type
= "ipmi", .compatible
= "ipmi-kcs",
2704 .data
= (void *)(unsigned long) SI_KCS
},
2705 { .type
= "ipmi", .compatible
= "ipmi-smic",
2706 .data
= (void *)(unsigned long) SI_SMIC
},
2707 { .type
= "ipmi", .compatible
= "ipmi-bt",
2708 .data
= (void *)(unsigned long) SI_BT
},
2712 static struct platform_driver ipmi_driver
= {
2714 .name
= DEVICE_NAME
,
2715 .owner
= THIS_MODULE
,
2716 .of_match_table
= ipmi_match
,
2718 .probe
= ipmi_probe
,
2719 .remove
= ipmi_remove
,
2722 #ifdef CONFIG_PARISC
2723 static int ipmi_parisc_probe(struct parisc_device
*dev
)
2725 struct smi_info
*info
;
2728 info
= smi_info_alloc();
2732 "could not allocate memory for PARISC probe\n");
2736 info
->si_type
= SI_KCS
;
2737 info
->addr_source
= SI_DEVICETREE
;
2738 info
->io_setup
= mem_setup
;
2739 info
->io
.addr_type
= IPMI_MEM_ADDR_SPACE
;
2740 info
->io
.addr_data
= dev
->hpa
.start
;
2741 info
->io
.regsize
= 1;
2742 info
->io
.regspacing
= 1;
2743 info
->io
.regshift
= 0;
2744 info
->irq
= 0; /* no interrupt */
2745 info
->irq_setup
= NULL
;
2746 info
->dev
= &dev
->dev
;
2748 dev_dbg(&dev
->dev
, "addr 0x%lx\n", info
->io
.addr_data
);
2750 dev_set_drvdata(&dev
->dev
, info
);
2761 static int ipmi_parisc_remove(struct parisc_device
*dev
)
2763 cleanup_one_si(dev_get_drvdata(&dev
->dev
));
2767 static struct parisc_device_id ipmi_parisc_tbl
[] = {
2768 { HPHW_MC
, HVERSION_REV_ANY_ID
, 0x004, 0xC0 },
2772 static struct parisc_driver ipmi_parisc_driver
= {
2774 .id_table
= ipmi_parisc_tbl
,
2775 .probe
= ipmi_parisc_probe
,
2776 .remove
= ipmi_parisc_remove
,
2778 #endif /* CONFIG_PARISC */
2780 static int wait_for_msg_done(struct smi_info
*smi_info
)
2782 enum si_sm_result smi_result
;
2784 smi_result
= smi_info
->handlers
->event(smi_info
->si_sm
, 0);
2786 if (smi_result
== SI_SM_CALL_WITH_DELAY
||
2787 smi_result
== SI_SM_CALL_WITH_TICK_DELAY
) {
2788 schedule_timeout_uninterruptible(1);
2789 smi_result
= smi_info
->handlers
->event(
2790 smi_info
->si_sm
, jiffies_to_usecs(1));
2791 } else if (smi_result
== SI_SM_CALL_WITHOUT_DELAY
) {
2792 smi_result
= smi_info
->handlers
->event(
2793 smi_info
->si_sm
, 0);
2797 if (smi_result
== SI_SM_HOSED
)
2799 * We couldn't get the state machine to run, so whatever's at
2800 * the port is probably not an IPMI SMI interface.
2807 static int try_get_dev_id(struct smi_info
*smi_info
)
2809 unsigned char msg
[2];
2810 unsigned char *resp
;
2811 unsigned long resp_len
;
2814 resp
= kmalloc(IPMI_MAX_MSG_LENGTH
, GFP_KERNEL
);
2819 * Do a Get Device ID command, since it comes back with some
2822 msg
[0] = IPMI_NETFN_APP_REQUEST
<< 2;
2823 msg
[1] = IPMI_GET_DEVICE_ID_CMD
;
2824 smi_info
->handlers
->start_transaction(smi_info
->si_sm
, msg
, 2);
2826 rv
= wait_for_msg_done(smi_info
);
2830 resp_len
= smi_info
->handlers
->get_result(smi_info
->si_sm
,
2831 resp
, IPMI_MAX_MSG_LENGTH
);
2833 /* Check and record info from the get device id, in case we need it. */
2834 rv
= ipmi_demangle_device_id(resp
, resp_len
, &smi_info
->device_id
);
2841 static int try_enable_event_buffer(struct smi_info
*smi_info
)
2843 unsigned char msg
[3];
2844 unsigned char *resp
;
2845 unsigned long resp_len
;
2848 resp
= kmalloc(IPMI_MAX_MSG_LENGTH
, GFP_KERNEL
);
2852 msg
[0] = IPMI_NETFN_APP_REQUEST
<< 2;
2853 msg
[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD
;
2854 smi_info
->handlers
->start_transaction(smi_info
->si_sm
, msg
, 2);
2856 rv
= wait_for_msg_done(smi_info
);
2858 printk(KERN_WARNING PFX
"Error getting response from get"
2859 " global enables command, the event buffer is not"
2864 resp_len
= smi_info
->handlers
->get_result(smi_info
->si_sm
,
2865 resp
, IPMI_MAX_MSG_LENGTH
);
2868 resp
[0] != (IPMI_NETFN_APP_REQUEST
| 1) << 2 ||
2869 resp
[1] != IPMI_GET_BMC_GLOBAL_ENABLES_CMD
||
2871 printk(KERN_WARNING PFX
"Invalid return from get global"
2872 " enables command, cannot enable the event buffer.\n");
2877 if (resp
[3] & IPMI_BMC_EVT_MSG_BUFF
)
2878 /* buffer is already enabled, nothing to do. */
2881 msg
[0] = IPMI_NETFN_APP_REQUEST
<< 2;
2882 msg
[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD
;
2883 msg
[2] = resp
[3] | IPMI_BMC_EVT_MSG_BUFF
;
2884 smi_info
->handlers
->start_transaction(smi_info
->si_sm
, msg
, 3);
2886 rv
= wait_for_msg_done(smi_info
);
2888 printk(KERN_WARNING PFX
"Error getting response from set"
2889 " global, enables command, the event buffer is not"
2894 resp_len
= smi_info
->handlers
->get_result(smi_info
->si_sm
,
2895 resp
, IPMI_MAX_MSG_LENGTH
);
2898 resp
[0] != (IPMI_NETFN_APP_REQUEST
| 1) << 2 ||
2899 resp
[1] != IPMI_SET_BMC_GLOBAL_ENABLES_CMD
) {
2900 printk(KERN_WARNING PFX
"Invalid return from get global,"
2901 "enables command, not enable the event buffer.\n");
2908 * An error when setting the event buffer bit means
2909 * that the event buffer is not supported.
2917 static int smi_type_proc_show(struct seq_file
*m
, void *v
)
2919 struct smi_info
*smi
= m
->private;
2921 return seq_printf(m
, "%s\n", si_to_str
[smi
->si_type
]);
2924 static int smi_type_proc_open(struct inode
*inode
, struct file
*file
)
2926 return single_open(file
, smi_type_proc_show
, PDE_DATA(inode
));
2929 static const struct file_operations smi_type_proc_ops
= {
2930 .open
= smi_type_proc_open
,
2932 .llseek
= seq_lseek
,
2933 .release
= single_release
,
2936 static int smi_si_stats_proc_show(struct seq_file
*m
, void *v
)
2938 struct smi_info
*smi
= m
->private;
2940 seq_printf(m
, "interrupts_enabled: %d\n",
2941 smi
->irq
&& !smi
->interrupt_disabled
);
2942 seq_printf(m
, "short_timeouts: %u\n",
2943 smi_get_stat(smi
, short_timeouts
));
2944 seq_printf(m
, "long_timeouts: %u\n",
2945 smi_get_stat(smi
, long_timeouts
));
2946 seq_printf(m
, "idles: %u\n",
2947 smi_get_stat(smi
, idles
));
2948 seq_printf(m
, "interrupts: %u\n",
2949 smi_get_stat(smi
, interrupts
));
2950 seq_printf(m
, "attentions: %u\n",
2951 smi_get_stat(smi
, attentions
));
2952 seq_printf(m
, "flag_fetches: %u\n",
2953 smi_get_stat(smi
, flag_fetches
));
2954 seq_printf(m
, "hosed_count: %u\n",
2955 smi_get_stat(smi
, hosed_count
));
2956 seq_printf(m
, "complete_transactions: %u\n",
2957 smi_get_stat(smi
, complete_transactions
));
2958 seq_printf(m
, "events: %u\n",
2959 smi_get_stat(smi
, events
));
2960 seq_printf(m
, "watchdog_pretimeouts: %u\n",
2961 smi_get_stat(smi
, watchdog_pretimeouts
));
2962 seq_printf(m
, "incoming_messages: %u\n",
2963 smi_get_stat(smi
, incoming_messages
));
2967 static int smi_si_stats_proc_open(struct inode
*inode
, struct file
*file
)
2969 return single_open(file
, smi_si_stats_proc_show
, PDE_DATA(inode
));
2972 static const struct file_operations smi_si_stats_proc_ops
= {
2973 .open
= smi_si_stats_proc_open
,
2975 .llseek
= seq_lseek
,
2976 .release
= single_release
,
2979 static int smi_params_proc_show(struct seq_file
*m
, void *v
)
2981 struct smi_info
*smi
= m
->private;
2983 return seq_printf(m
,
2984 "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n",
2985 si_to_str
[smi
->si_type
],
2986 addr_space_to_str
[smi
->io
.addr_type
],
2995 static int smi_params_proc_open(struct inode
*inode
, struct file
*file
)
2997 return single_open(file
, smi_params_proc_show
, PDE_DATA(inode
));
3000 static const struct file_operations smi_params_proc_ops
= {
3001 .open
= smi_params_proc_open
,
3003 .llseek
= seq_lseek
,
3004 .release
= single_release
,
3008 * oem_data_avail_to_receive_msg_avail
3009 * @info - smi_info structure with msg_flags set
3011 * Converts flags from OEM_DATA_AVAIL to RECEIVE_MSG_AVAIL
3012 * Returns 1 indicating need to re-run handle_flags().
3014 static int oem_data_avail_to_receive_msg_avail(struct smi_info
*smi_info
)
3016 smi_info
->msg_flags
= ((smi_info
->msg_flags
& ~OEM_DATA_AVAIL
) |
3022 * setup_dell_poweredge_oem_data_handler
3023 * @info - smi_info.device_id must be populated
3025 * Systems that match, but have firmware version < 1.40 may assert
3026 * OEM0_DATA_AVAIL on their own, without being told via Set Flags that
3027 * it's safe to do so. Such systems will de-assert OEM1_DATA_AVAIL
3028 * upon receipt of IPMI_GET_MSG_CMD, so we should treat these flags
3029 * as RECEIVE_MSG_AVAIL instead.
3031 * As Dell has no plans to release IPMI 1.5 firmware that *ever*
3032 * assert the OEM[012] bits, and if it did, the driver would have to
3033 * change to handle that properly, we don't actually check for the
3035 * Device ID = 0x20 BMC on PowerEdge 8G servers
3036 * Device Revision = 0x80
3037 * Firmware Revision1 = 0x01 BMC version 1.40
3038 * Firmware Revision2 = 0x40 BCD encoded
3039 * IPMI Version = 0x51 IPMI 1.5
3040 * Manufacturer ID = A2 02 00 Dell IANA
3042 * Additionally, PowerEdge systems with IPMI < 1.5 may also assert
3043 * OEM0_DATA_AVAIL and needs to be treated as RECEIVE_MSG_AVAIL.
3046 #define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20
3047 #define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80
3048 #define DELL_POWEREDGE_8G_BMC_IPMI_VERSION 0x51
3049 #define DELL_IANA_MFR_ID 0x0002a2
3050 static void setup_dell_poweredge_oem_data_handler(struct smi_info
*smi_info
)
3052 struct ipmi_device_id
*id
= &smi_info
->device_id
;
3053 if (id
->manufacturer_id
== DELL_IANA_MFR_ID
) {
3054 if (id
->device_id
== DELL_POWEREDGE_8G_BMC_DEVICE_ID
&&
3055 id
->device_revision
== DELL_POWEREDGE_8G_BMC_DEVICE_REV
&&
3056 id
->ipmi_version
== DELL_POWEREDGE_8G_BMC_IPMI_VERSION
) {
3057 smi_info
->oem_data_avail_handler
=
3058 oem_data_avail_to_receive_msg_avail
;
3059 } else if (ipmi_version_major(id
) < 1 ||
3060 (ipmi_version_major(id
) == 1 &&
3061 ipmi_version_minor(id
) < 5)) {
3062 smi_info
->oem_data_avail_handler
=
3063 oem_data_avail_to_receive_msg_avail
;
3068 #define CANNOT_RETURN_REQUESTED_LENGTH 0xCA
3069 static void return_hosed_msg_badsize(struct smi_info
*smi_info
)
3071 struct ipmi_smi_msg
*msg
= smi_info
->curr_msg
;
3073 /* Make it a response */
3074 msg
->rsp
[0] = msg
->data
[0] | 4;
3075 msg
->rsp
[1] = msg
->data
[1];
3076 msg
->rsp
[2] = CANNOT_RETURN_REQUESTED_LENGTH
;
3078 smi_info
->curr_msg
= NULL
;
3079 deliver_recv_msg(smi_info
, msg
);
3083 * dell_poweredge_bt_xaction_handler
3084 * @info - smi_info.device_id must be populated
3086 * Dell PowerEdge servers with the BT interface (x6xx and 1750) will
3087 * not respond to a Get SDR command if the length of the data
3088 * requested is exactly 0x3A, which leads to command timeouts and no
3089 * data returned. This intercepts such commands, and causes userspace
3090 * callers to try again with a different-sized buffer, which succeeds.
3093 #define STORAGE_NETFN 0x0A
3094 #define STORAGE_CMD_GET_SDR 0x23
3095 static int dell_poweredge_bt_xaction_handler(struct notifier_block
*self
,
3096 unsigned long unused
,
3099 struct smi_info
*smi_info
= in
;
3100 unsigned char *data
= smi_info
->curr_msg
->data
;
3101 unsigned int size
= smi_info
->curr_msg
->data_size
;
3103 (data
[0]>>2) == STORAGE_NETFN
&&
3104 data
[1] == STORAGE_CMD_GET_SDR
&&
3106 return_hosed_msg_badsize(smi_info
);
3112 static struct notifier_block dell_poweredge_bt_xaction_notifier
= {
3113 .notifier_call
= dell_poweredge_bt_xaction_handler
,
3117 * setup_dell_poweredge_bt_xaction_handler
3118 * @info - smi_info.device_id must be filled in already
3120 * Fills in smi_info.device_id.start_transaction_pre_hook
3121 * when we know what function to use there.
3124 setup_dell_poweredge_bt_xaction_handler(struct smi_info
*smi_info
)
3126 struct ipmi_device_id
*id
= &smi_info
->device_id
;
3127 if (id
->manufacturer_id
== DELL_IANA_MFR_ID
&&
3128 smi_info
->si_type
== SI_BT
)
3129 register_xaction_notifier(&dell_poweredge_bt_xaction_notifier
);
3133 * setup_oem_data_handler
3134 * @info - smi_info.device_id must be filled in already
3136 * Fills in smi_info.device_id.oem_data_available_handler
3137 * when we know what function to use there.
3140 static void setup_oem_data_handler(struct smi_info
*smi_info
)
3142 setup_dell_poweredge_oem_data_handler(smi_info
);
3145 static void setup_xaction_handlers(struct smi_info
*smi_info
)
3147 setup_dell_poweredge_bt_xaction_handler(smi_info
);
3150 static inline void wait_for_timer_and_thread(struct smi_info
*smi_info
)
3152 if (smi_info
->intf
) {
3154 * The timer and thread are only running if the
3155 * interface has been started up and registered.
3157 if (smi_info
->thread
!= NULL
)
3158 kthread_stop(smi_info
->thread
);
3159 del_timer_sync(&smi_info
->si_timer
);
3163 static struct ipmi_default_vals
3169 { .type
= SI_KCS
, .port
= 0xca2 },
3170 { .type
= SI_SMIC
, .port
= 0xca9 },
3171 { .type
= SI_BT
, .port
= 0xe4 },
3175 static void default_find_bmc(void)
3177 struct smi_info
*info
;
3180 for (i
= 0; ; i
++) {
3181 if (!ipmi_defaults
[i
].port
)
3184 if (check_legacy_ioport(ipmi_defaults
[i
].port
))
3187 info
= smi_info_alloc();
3191 info
->addr_source
= SI_DEFAULT
;
3193 info
->si_type
= ipmi_defaults
[i
].type
;
3194 info
->io_setup
= port_setup
;
3195 info
->io
.addr_data
= ipmi_defaults
[i
].port
;
3196 info
->io
.addr_type
= IPMI_IO_ADDR_SPACE
;
3198 info
->io
.addr
= NULL
;
3199 info
->io
.regspacing
= DEFAULT_REGSPACING
;
3200 info
->io
.regsize
= DEFAULT_REGSPACING
;
3201 info
->io
.regshift
= 0;
3203 if (add_smi(info
) == 0) {
3204 if ((try_smi_init(info
)) == 0) {
3206 printk(KERN_INFO PFX
"Found default %s"
3207 " state machine at %s address 0x%lx\n",
3208 si_to_str
[info
->si_type
],
3209 addr_space_to_str
[info
->io
.addr_type
],
3210 info
->io
.addr_data
);
3212 cleanup_one_si(info
);
3219 static int is_new_interface(struct smi_info
*info
)
3223 list_for_each_entry(e
, &smi_infos
, link
) {
3224 if (e
->io
.addr_type
!= info
->io
.addr_type
)
3226 if (e
->io
.addr_data
== info
->io
.addr_data
)
3233 static int add_smi(struct smi_info
*new_smi
)
3237 printk(KERN_INFO PFX
"Adding %s-specified %s state machine",
3238 ipmi_addr_src_to_str
[new_smi
->addr_source
],
3239 si_to_str
[new_smi
->si_type
]);
3240 mutex_lock(&smi_infos_lock
);
3241 if (!is_new_interface(new_smi
)) {
3242 printk(KERN_CONT
" duplicate interface\n");
3247 printk(KERN_CONT
"\n");
3249 /* So we know not to free it unless we have allocated one. */
3250 new_smi
->intf
= NULL
;
3251 new_smi
->si_sm
= NULL
;
3252 new_smi
->handlers
= NULL
;
3254 list_add_tail(&new_smi
->link
, &smi_infos
);
3257 mutex_unlock(&smi_infos_lock
);
3261 static int try_smi_init(struct smi_info
*new_smi
)
3266 printk(KERN_INFO PFX
"Trying %s-specified %s state"
3267 " machine at %s address 0x%lx, slave address 0x%x,"
3269 ipmi_addr_src_to_str
[new_smi
->addr_source
],
3270 si_to_str
[new_smi
->si_type
],
3271 addr_space_to_str
[new_smi
->io
.addr_type
],
3272 new_smi
->io
.addr_data
,
3273 new_smi
->slave_addr
, new_smi
->irq
);
3275 switch (new_smi
->si_type
) {
3277 new_smi
->handlers
= &kcs_smi_handlers
;
3281 new_smi
->handlers
= &smic_smi_handlers
;
3285 new_smi
->handlers
= &bt_smi_handlers
;
3289 /* No support for anything else yet. */
3294 /* Allocate the state machine's data and initialize it. */
3295 new_smi
->si_sm
= kmalloc(new_smi
->handlers
->size(), GFP_KERNEL
);
3296 if (!new_smi
->si_sm
) {
3298 "Could not allocate state machine memory\n");
3302 new_smi
->io_size
= new_smi
->handlers
->init_data(new_smi
->si_sm
,
3305 /* Now that we know the I/O size, we can set up the I/O. */
3306 rv
= new_smi
->io_setup(new_smi
);
3308 printk(KERN_ERR PFX
"Could not set up I/O space\n");
3312 /* Do low-level detection first. */
3313 if (new_smi
->handlers
->detect(new_smi
->si_sm
)) {
3314 if (new_smi
->addr_source
)
3315 printk(KERN_INFO PFX
"Interface detection failed\n");
3321 * Attempt a get device id command. If it fails, we probably
3322 * don't have a BMC here.
3324 rv
= try_get_dev_id(new_smi
);
3326 if (new_smi
->addr_source
)
3327 printk(KERN_INFO PFX
"There appears to be no BMC"
3328 " at this location\n");
3332 setup_oem_data_handler(new_smi
);
3333 setup_xaction_handlers(new_smi
);
3335 INIT_LIST_HEAD(&(new_smi
->xmit_msgs
));
3336 INIT_LIST_HEAD(&(new_smi
->hp_xmit_msgs
));
3337 new_smi
->curr_msg
= NULL
;
3338 atomic_set(&new_smi
->req_events
, 0);
3339 new_smi
->run_to_completion
= 0;
3340 for (i
= 0; i
< SI_NUM_STATS
; i
++)
3341 atomic_set(&new_smi
->stats
[i
], 0);
3343 new_smi
->interrupt_disabled
= 1;
3344 atomic_set(&new_smi
->stop_operation
, 0);
3345 new_smi
->intf_num
= smi_num
;
3348 rv
= try_enable_event_buffer(new_smi
);
3350 new_smi
->has_event_buffer
= 1;
3353 * Start clearing the flags before we enable interrupts or the
3354 * timer to avoid racing with the timer.
3356 start_clear_flags(new_smi
);
3357 /* IRQ is defined to be set when non-zero. */
3359 new_smi
->si_state
= SI_CLEARING_FLAGS_THEN_SET_IRQ
;
3361 if (!new_smi
->dev
) {
3363 * If we don't already have a device from something
3364 * else (like PCI), then register a new one.
3366 new_smi
->pdev
= platform_device_alloc("ipmi_si",
3368 if (!new_smi
->pdev
) {
3370 "Unable to allocate platform device\n");
3373 new_smi
->dev
= &new_smi
->pdev
->dev
;
3374 new_smi
->dev
->driver
= &ipmi_driver
.driver
;
3376 rv
= platform_device_add(new_smi
->pdev
);
3379 "Unable to register system interface device:"
3384 new_smi
->dev_registered
= 1;
3387 rv
= ipmi_register_smi(&handlers
,
3389 &new_smi
->device_id
,
3392 new_smi
->slave_addr
);
3394 dev_err(new_smi
->dev
, "Unable to register device: error %d\n",
3396 goto out_err_stop_timer
;
3399 rv
= ipmi_smi_add_proc_entry(new_smi
->intf
, "type",
3403 dev_err(new_smi
->dev
, "Unable to create proc entry: %d\n", rv
);
3404 goto out_err_stop_timer
;
3407 rv
= ipmi_smi_add_proc_entry(new_smi
->intf
, "si_stats",
3408 &smi_si_stats_proc_ops
,
3411 dev_err(new_smi
->dev
, "Unable to create proc entry: %d\n", rv
);
3412 goto out_err_stop_timer
;
3415 rv
= ipmi_smi_add_proc_entry(new_smi
->intf
, "params",
3416 &smi_params_proc_ops
,
3419 dev_err(new_smi
->dev
, "Unable to create proc entry: %d\n", rv
);
3420 goto out_err_stop_timer
;
3423 dev_info(new_smi
->dev
, "IPMI %s interface initialized\n",
3424 si_to_str
[new_smi
->si_type
]);
3429 atomic_inc(&new_smi
->stop_operation
);
3430 wait_for_timer_and_thread(new_smi
);
3433 new_smi
->interrupt_disabled
= 1;
3435 if (new_smi
->intf
) {
3436 ipmi_unregister_smi(new_smi
->intf
);
3437 new_smi
->intf
= NULL
;
3440 if (new_smi
->irq_cleanup
) {
3441 new_smi
->irq_cleanup(new_smi
);
3442 new_smi
->irq_cleanup
= NULL
;
3446 * Wait until we know that we are out of any interrupt
3447 * handlers might have been running before we freed the
3450 synchronize_sched();
3452 if (new_smi
->si_sm
) {
3453 if (new_smi
->handlers
)
3454 new_smi
->handlers
->cleanup(new_smi
->si_sm
);
3455 kfree(new_smi
->si_sm
);
3456 new_smi
->si_sm
= NULL
;
3458 if (new_smi
->addr_source_cleanup
) {
3459 new_smi
->addr_source_cleanup(new_smi
);
3460 new_smi
->addr_source_cleanup
= NULL
;
3462 if (new_smi
->io_cleanup
) {
3463 new_smi
->io_cleanup(new_smi
);
3464 new_smi
->io_cleanup
= NULL
;
3467 if (new_smi
->dev_registered
) {
3468 platform_device_unregister(new_smi
->pdev
);
3469 new_smi
->dev_registered
= 0;
3475 static int init_ipmi_si(void)
3481 enum ipmi_addr_src type
= SI_INVALID
;
3487 if (si_tryplatform
) {
3488 rv
= platform_driver_register(&ipmi_driver
);
3490 printk(KERN_ERR PFX
"Unable to register "
3491 "driver: %d\n", rv
);
3496 /* Parse out the si_type string into its components. */
3499 for (i
= 0; (i
< SI_MAX_PARMS
) && (*str
!= '\0'); i
++) {
3501 str
= strchr(str
, ',');
3511 printk(KERN_INFO
"IPMI System Interface driver.\n");
3513 /* If the user gave us a device, they presumably want us to use it */
3514 if (!hardcode_find_bmc())
3519 rv
= pci_register_driver(&ipmi_pci_driver
);
3521 printk(KERN_ERR PFX
"Unable to register "
3522 "PCI driver: %d\n", rv
);
3530 pnp_register_driver(&ipmi_pnp_driver
);
3545 #ifdef CONFIG_PARISC
3546 register_parisc_driver(&ipmi_parisc_driver
);
3547 parisc_registered
= 1;
3548 /* poking PC IO addresses will crash machine, don't do it */
3552 /* We prefer devices with interrupts, but in the case of a machine
3553 with multiple BMCs we assume that there will be several instances
3554 of a given type so if we succeed in registering a type then also
3555 try to register everything else of the same type */
3557 mutex_lock(&smi_infos_lock
);
3558 list_for_each_entry(e
, &smi_infos
, link
) {
3559 /* Try to register a device if it has an IRQ and we either
3560 haven't successfully registered a device yet or this
3561 device has the same type as one we successfully registered */
3562 if (e
->irq
&& (!type
|| e
->addr_source
== type
)) {
3563 if (!try_smi_init(e
)) {
3564 type
= e
->addr_source
;
3569 /* type will only have been set if we successfully registered an si */
3571 mutex_unlock(&smi_infos_lock
);
3575 /* Fall back to the preferred device */
3577 list_for_each_entry(e
, &smi_infos
, link
) {
3578 if (!e
->irq
&& (!type
|| e
->addr_source
== type
)) {
3579 if (!try_smi_init(e
)) {
3580 type
= e
->addr_source
;
3584 mutex_unlock(&smi_infos_lock
);
3589 if (si_trydefaults
) {
3590 mutex_lock(&smi_infos_lock
);
3591 if (list_empty(&smi_infos
)) {
3592 /* No BMC was found, try defaults. */
3593 mutex_unlock(&smi_infos_lock
);
3596 mutex_unlock(&smi_infos_lock
);
3599 mutex_lock(&smi_infos_lock
);
3600 if (unload_when_empty
&& list_empty(&smi_infos
)) {
3601 mutex_unlock(&smi_infos_lock
);
3603 printk(KERN_WARNING PFX
3604 "Unable to find any System Interface(s)\n");
3607 mutex_unlock(&smi_infos_lock
);
3611 module_init(init_ipmi_si
);
3613 static void cleanup_one_si(struct smi_info
*to_clean
)
3616 unsigned long flags
;
3621 list_del(&to_clean
->link
);
3623 /* Tell the driver that we are shutting down. */
3624 atomic_inc(&to_clean
->stop_operation
);
3627 * Make sure the timer and thread are stopped and will not run
3630 wait_for_timer_and_thread(to_clean
);
3633 * Timeouts are stopped, now make sure the interrupts are off
3634 * for the device. A little tricky with locks to make sure
3635 * there are no races.
3637 spin_lock_irqsave(&to_clean
->si_lock
, flags
);
3638 while (to_clean
->curr_msg
|| (to_clean
->si_state
!= SI_NORMAL
)) {
3639 spin_unlock_irqrestore(&to_clean
->si_lock
, flags
);
3641 schedule_timeout_uninterruptible(1);
3642 spin_lock_irqsave(&to_clean
->si_lock
, flags
);
3644 disable_si_irq(to_clean
);
3645 spin_unlock_irqrestore(&to_clean
->si_lock
, flags
);
3646 while (to_clean
->curr_msg
|| (to_clean
->si_state
!= SI_NORMAL
)) {
3648 schedule_timeout_uninterruptible(1);
3651 /* Clean up interrupts and make sure that everything is done. */
3652 if (to_clean
->irq_cleanup
)
3653 to_clean
->irq_cleanup(to_clean
);
3654 while (to_clean
->curr_msg
|| (to_clean
->si_state
!= SI_NORMAL
)) {
3656 schedule_timeout_uninterruptible(1);
3660 rv
= ipmi_unregister_smi(to_clean
->intf
);
3663 printk(KERN_ERR PFX
"Unable to unregister device: errno=%d\n",
3667 if (to_clean
->handlers
)
3668 to_clean
->handlers
->cleanup(to_clean
->si_sm
);
3670 kfree(to_clean
->si_sm
);
3672 if (to_clean
->addr_source_cleanup
)
3673 to_clean
->addr_source_cleanup(to_clean
);
3674 if (to_clean
->io_cleanup
)
3675 to_clean
->io_cleanup(to_clean
);
3677 if (to_clean
->dev_registered
)
3678 platform_device_unregister(to_clean
->pdev
);
3683 static void cleanup_ipmi_si(void)
3685 struct smi_info
*e
, *tmp_e
;
3692 pci_unregister_driver(&ipmi_pci_driver
);
3696 pnp_unregister_driver(&ipmi_pnp_driver
);
3698 #ifdef CONFIG_PARISC
3699 if (parisc_registered
)
3700 unregister_parisc_driver(&ipmi_parisc_driver
);
3703 platform_driver_unregister(&ipmi_driver
);
3705 mutex_lock(&smi_infos_lock
);
3706 list_for_each_entry_safe(e
, tmp_e
, &smi_infos
, link
)
3708 mutex_unlock(&smi_infos_lock
);
3710 module_exit(cleanup_ipmi_si
);
3712 MODULE_LICENSE("GPL");
3713 MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
3714 MODULE_DESCRIPTION("Interface to the IPMI driver for the KCS, SMIC, and BT"
3715 " system interfaces.");