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.
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
28 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, write to the Free Software Foundation, Inc.,
32 * 675 Mass Ave, Cambridge, MA 02139, USA.
36 * This file holds the "policy" for the interface to the SMI state
37 * machine. It does the configuration, handles timers and interrupts,
38 * and drives the real SMI state machine.
41 #include <linux/config.h>
42 #include <linux/module.h>
43 #include <linux/moduleparam.h>
44 #include <asm/system.h>
45 #include <linux/sched.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>
55 #ifdef CONFIG_HIGH_RES_TIMERS
56 #include <linux/hrtime.h>
57 # if defined(schedule_next_int)
58 /* Old high-res timer code, do translations. */
59 # define get_arch_cycles(a) quick_update_jiffies_sub(a)
60 # define arch_cycles_per_jiffy cycles_per_jiffies
62 static inline void add_usec_to_timer(struct timer_list
*t
, long v
)
64 t
->sub_expires
+= nsec_to_arch_cycle(v
* 1000);
65 while (t
->sub_expires
>= arch_cycles_per_jiffy
)
68 t
->sub_expires
-= arch_cycles_per_jiffy
;
72 #include <linux/interrupt.h>
73 #include <linux/rcupdate.h>
74 #include <linux/ipmi_smi.h>
76 #include "ipmi_si_sm.h"
77 #include <linux/init.h>
79 #define IPMI_SI_VERSION "v33"
81 /* Measure times between events in the driver. */
84 /* Call every 10 ms. */
85 #define SI_TIMEOUT_TIME_USEC 10000
86 #define SI_USEC_PER_JIFFY (1000000/HZ)
87 #define SI_TIMEOUT_JIFFIES (SI_TIMEOUT_TIME_USEC/SI_USEC_PER_JIFFY)
88 #define SI_SHORT_TIMEOUT_USEC 250 /* .25ms when the SM request a
96 SI_CLEARING_FLAGS_THEN_SET_IRQ
,
98 SI_ENABLE_INTERRUPTS1
,
100 /* FIXME - add watchdog stuff. */
103 /* Some BT-specific defines we need here. */
104 #define IPMI_BT_INTMASK_REG 2
105 #define IPMI_BT_INTMASK_CLEAR_IRQ_BIT 2
106 #define IPMI_BT_INTMASK_ENABLE_IRQ_BIT 1
109 SI_KCS
, SI_SMIC
, SI_BT
115 struct si_sm_data
*si_sm
;
116 struct si_sm_handlers
*handlers
;
117 enum si_type si_type
;
120 struct list_head xmit_msgs
;
121 struct list_head hp_xmit_msgs
;
122 struct ipmi_smi_msg
*curr_msg
;
123 enum si_intf_state si_state
;
125 /* Used to handle the various types of I/O that can occur with
128 int (*io_setup
)(struct smi_info
*info
);
129 void (*io_cleanup
)(struct smi_info
*info
);
130 int (*irq_setup
)(struct smi_info
*info
);
131 void (*irq_cleanup
)(struct smi_info
*info
);
132 unsigned int io_size
;
134 /* Flags from the last GET_MSG_FLAGS command, used when an ATTN
135 is set to hold the flags until we are done handling everything
137 #define RECEIVE_MSG_AVAIL 0x01
138 #define EVENT_MSG_BUFFER_FULL 0x02
139 #define WDT_PRE_TIMEOUT_INT 0x08
140 unsigned char msg_flags
;
142 /* If set to true, this will request events the next time the
143 state machine is idle. */
146 /* If true, run the state machine to completion on every send
147 call. Generally used after a panic to make sure stuff goes
149 int run_to_completion
;
151 /* The I/O port of an SI interface. */
154 /* The space between start addresses of the two ports. For
155 instance, if the first port is 0xca2 and the spacing is 4, then
156 the second port is 0xca6. */
157 unsigned int spacing
;
159 /* zero if no irq; */
162 /* The timer for this si. */
163 struct timer_list si_timer
;
165 /* The time (in jiffies) the last timeout occurred at. */
166 unsigned long last_timeout_jiffies
;
168 /* Used to gracefully stop the timer without race conditions. */
169 volatile int stop_operation
;
170 volatile int timer_stopped
;
172 /* The driver will disable interrupts when it gets into a
173 situation where it cannot handle messages due to lack of
174 memory. Once that situation clears up, it will re-enable
176 int interrupt_disabled
;
178 unsigned char ipmi_si_dev_rev
;
179 unsigned char ipmi_si_fw_rev_major
;
180 unsigned char ipmi_si_fw_rev_minor
;
181 unsigned char ipmi_version_major
;
182 unsigned char ipmi_version_minor
;
184 /* Slave address, could be reported from DMI. */
185 unsigned char slave_addr
;
187 /* Counters and things for the proc filesystem. */
188 spinlock_t count_lock
;
189 unsigned long short_timeouts
;
190 unsigned long long_timeouts
;
191 unsigned long timeout_restarts
;
193 unsigned long interrupts
;
194 unsigned long attentions
;
195 unsigned long flag_fetches
;
196 unsigned long hosed_count
;
197 unsigned long complete_transactions
;
198 unsigned long events
;
199 unsigned long watchdog_pretimeouts
;
200 unsigned long incoming_messages
;
203 static void si_restart_short_timer(struct smi_info
*smi_info
);
205 static void deliver_recv_msg(struct smi_info
*smi_info
,
206 struct ipmi_smi_msg
*msg
)
208 /* Deliver the message to the upper layer with the lock
210 spin_unlock(&(smi_info
->si_lock
));
211 ipmi_smi_msg_received(smi_info
->intf
, msg
);
212 spin_lock(&(smi_info
->si_lock
));
215 static void return_hosed_msg(struct smi_info
*smi_info
)
217 struct ipmi_smi_msg
*msg
= smi_info
->curr_msg
;
219 /* Make it a reponse */
220 msg
->rsp
[0] = msg
->data
[0] | 4;
221 msg
->rsp
[1] = msg
->data
[1];
222 msg
->rsp
[2] = 0xFF; /* Unknown error. */
225 smi_info
->curr_msg
= NULL
;
226 deliver_recv_msg(smi_info
, msg
);
229 static enum si_sm_result
start_next_msg(struct smi_info
*smi_info
)
232 struct list_head
*entry
= NULL
;
237 /* No need to save flags, we aleady have interrupts off and we
238 already hold the SMI lock. */
239 spin_lock(&(smi_info
->msg_lock
));
241 /* Pick the high priority queue first. */
242 if (! list_empty(&(smi_info
->hp_xmit_msgs
))) {
243 entry
= smi_info
->hp_xmit_msgs
.next
;
244 } else if (! list_empty(&(smi_info
->xmit_msgs
))) {
245 entry
= smi_info
->xmit_msgs
.next
;
249 smi_info
->curr_msg
= NULL
;
255 smi_info
->curr_msg
= list_entry(entry
,
260 printk("**Start2: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
262 err
= smi_info
->handlers
->start_transaction(
264 smi_info
->curr_msg
->data
,
265 smi_info
->curr_msg
->data_size
);
267 return_hosed_msg(smi_info
);
270 rv
= SI_SM_CALL_WITHOUT_DELAY
;
272 spin_unlock(&(smi_info
->msg_lock
));
277 static void start_enable_irq(struct smi_info
*smi_info
)
279 unsigned char msg
[2];
281 /* If we are enabling interrupts, we have to tell the
283 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
284 msg
[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD
;
286 smi_info
->handlers
->start_transaction(smi_info
->si_sm
, msg
, 2);
287 smi_info
->si_state
= SI_ENABLE_INTERRUPTS1
;
290 static void start_clear_flags(struct smi_info
*smi_info
)
292 unsigned char msg
[3];
294 /* Make sure the watchdog pre-timeout flag is not set at startup. */
295 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
296 msg
[1] = IPMI_CLEAR_MSG_FLAGS_CMD
;
297 msg
[2] = WDT_PRE_TIMEOUT_INT
;
299 smi_info
->handlers
->start_transaction(smi_info
->si_sm
, msg
, 3);
300 smi_info
->si_state
= SI_CLEARING_FLAGS
;
303 /* When we have a situtaion where we run out of memory and cannot
304 allocate messages, we just leave them in the BMC and run the system
305 polled until we can allocate some memory. Once we have some
306 memory, we will re-enable the interrupt. */
307 static inline void disable_si_irq(struct smi_info
*smi_info
)
309 if ((smi_info
->irq
) && (!smi_info
->interrupt_disabled
)) {
310 disable_irq_nosync(smi_info
->irq
);
311 smi_info
->interrupt_disabled
= 1;
315 static inline void enable_si_irq(struct smi_info
*smi_info
)
317 if ((smi_info
->irq
) && (smi_info
->interrupt_disabled
)) {
318 enable_irq(smi_info
->irq
);
319 smi_info
->interrupt_disabled
= 0;
323 static void handle_flags(struct smi_info
*smi_info
)
325 if (smi_info
->msg_flags
& WDT_PRE_TIMEOUT_INT
) {
326 /* Watchdog pre-timeout */
327 spin_lock(&smi_info
->count_lock
);
328 smi_info
->watchdog_pretimeouts
++;
329 spin_unlock(&smi_info
->count_lock
);
331 start_clear_flags(smi_info
);
332 smi_info
->msg_flags
&= ~WDT_PRE_TIMEOUT_INT
;
333 spin_unlock(&(smi_info
->si_lock
));
334 ipmi_smi_watchdog_pretimeout(smi_info
->intf
);
335 spin_lock(&(smi_info
->si_lock
));
336 } else if (smi_info
->msg_flags
& RECEIVE_MSG_AVAIL
) {
337 /* Messages available. */
338 smi_info
->curr_msg
= ipmi_alloc_smi_msg();
339 if (!smi_info
->curr_msg
) {
340 disable_si_irq(smi_info
);
341 smi_info
->si_state
= SI_NORMAL
;
344 enable_si_irq(smi_info
);
346 smi_info
->curr_msg
->data
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
347 smi_info
->curr_msg
->data
[1] = IPMI_GET_MSG_CMD
;
348 smi_info
->curr_msg
->data_size
= 2;
350 smi_info
->handlers
->start_transaction(
352 smi_info
->curr_msg
->data
,
353 smi_info
->curr_msg
->data_size
);
354 smi_info
->si_state
= SI_GETTING_MESSAGES
;
355 } else if (smi_info
->msg_flags
& EVENT_MSG_BUFFER_FULL
) {
356 /* Events available. */
357 smi_info
->curr_msg
= ipmi_alloc_smi_msg();
358 if (!smi_info
->curr_msg
) {
359 disable_si_irq(smi_info
);
360 smi_info
->si_state
= SI_NORMAL
;
363 enable_si_irq(smi_info
);
365 smi_info
->curr_msg
->data
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
366 smi_info
->curr_msg
->data
[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD
;
367 smi_info
->curr_msg
->data_size
= 2;
369 smi_info
->handlers
->start_transaction(
371 smi_info
->curr_msg
->data
,
372 smi_info
->curr_msg
->data_size
);
373 smi_info
->si_state
= SI_GETTING_EVENTS
;
375 smi_info
->si_state
= SI_NORMAL
;
379 static void handle_transaction_done(struct smi_info
*smi_info
)
381 struct ipmi_smi_msg
*msg
;
386 printk("**Done: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
388 switch (smi_info
->si_state
) {
390 if (!smi_info
->curr_msg
)
393 smi_info
->curr_msg
->rsp_size
394 = smi_info
->handlers
->get_result(
396 smi_info
->curr_msg
->rsp
,
397 IPMI_MAX_MSG_LENGTH
);
399 /* Do this here becase deliver_recv_msg() releases the
400 lock, and a new message can be put in during the
401 time the lock is released. */
402 msg
= smi_info
->curr_msg
;
403 smi_info
->curr_msg
= NULL
;
404 deliver_recv_msg(smi_info
, msg
);
407 case SI_GETTING_FLAGS
:
409 unsigned char msg
[4];
412 /* We got the flags from the SMI, now handle them. */
413 len
= smi_info
->handlers
->get_result(smi_info
->si_sm
, msg
, 4);
415 /* Error fetching flags, just give up for
417 smi_info
->si_state
= SI_NORMAL
;
418 } else if (len
< 4) {
419 /* Hmm, no flags. That's technically illegal, but
420 don't use uninitialized data. */
421 smi_info
->si_state
= SI_NORMAL
;
423 smi_info
->msg_flags
= msg
[3];
424 handle_flags(smi_info
);
429 case SI_CLEARING_FLAGS
:
430 case SI_CLEARING_FLAGS_THEN_SET_IRQ
:
432 unsigned char msg
[3];
434 /* We cleared the flags. */
435 smi_info
->handlers
->get_result(smi_info
->si_sm
, msg
, 3);
437 /* Error clearing flags */
439 "ipmi_si: Error clearing flags: %2.2x\n",
442 if (smi_info
->si_state
== SI_CLEARING_FLAGS_THEN_SET_IRQ
)
443 start_enable_irq(smi_info
);
445 smi_info
->si_state
= SI_NORMAL
;
449 case SI_GETTING_EVENTS
:
451 smi_info
->curr_msg
->rsp_size
452 = smi_info
->handlers
->get_result(
454 smi_info
->curr_msg
->rsp
,
455 IPMI_MAX_MSG_LENGTH
);
457 /* Do this here becase deliver_recv_msg() releases the
458 lock, and a new message can be put in during the
459 time the lock is released. */
460 msg
= smi_info
->curr_msg
;
461 smi_info
->curr_msg
= NULL
;
462 if (msg
->rsp
[2] != 0) {
463 /* Error getting event, probably done. */
466 /* Take off the event flag. */
467 smi_info
->msg_flags
&= ~EVENT_MSG_BUFFER_FULL
;
468 handle_flags(smi_info
);
470 spin_lock(&smi_info
->count_lock
);
472 spin_unlock(&smi_info
->count_lock
);
474 /* Do this before we deliver the message
475 because delivering the message releases the
476 lock and something else can mess with the
478 handle_flags(smi_info
);
480 deliver_recv_msg(smi_info
, msg
);
485 case SI_GETTING_MESSAGES
:
487 smi_info
->curr_msg
->rsp_size
488 = smi_info
->handlers
->get_result(
490 smi_info
->curr_msg
->rsp
,
491 IPMI_MAX_MSG_LENGTH
);
493 /* Do this here becase deliver_recv_msg() releases the
494 lock, and a new message can be put in during the
495 time the lock is released. */
496 msg
= smi_info
->curr_msg
;
497 smi_info
->curr_msg
= NULL
;
498 if (msg
->rsp
[2] != 0) {
499 /* Error getting event, probably done. */
502 /* Take off the msg flag. */
503 smi_info
->msg_flags
&= ~RECEIVE_MSG_AVAIL
;
504 handle_flags(smi_info
);
506 spin_lock(&smi_info
->count_lock
);
507 smi_info
->incoming_messages
++;
508 spin_unlock(&smi_info
->count_lock
);
510 /* Do this before we deliver the message
511 because delivering the message releases the
512 lock and something else can mess with the
514 handle_flags(smi_info
);
516 deliver_recv_msg(smi_info
, msg
);
521 case SI_ENABLE_INTERRUPTS1
:
523 unsigned char msg
[4];
525 /* We got the flags from the SMI, now handle them. */
526 smi_info
->handlers
->get_result(smi_info
->si_sm
, msg
, 4);
529 "ipmi_si: Could not enable interrupts"
530 ", failed get, using polled mode.\n");
531 smi_info
->si_state
= SI_NORMAL
;
533 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
534 msg
[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD
;
535 msg
[2] = msg
[3] | 1; /* enable msg queue int */
536 smi_info
->handlers
->start_transaction(
537 smi_info
->si_sm
, msg
, 3);
538 smi_info
->si_state
= SI_ENABLE_INTERRUPTS2
;
543 case SI_ENABLE_INTERRUPTS2
:
545 unsigned char msg
[4];
547 /* We got the flags from the SMI, now handle them. */
548 smi_info
->handlers
->get_result(smi_info
->si_sm
, msg
, 4);
551 "ipmi_si: Could not enable interrupts"
552 ", failed set, using polled mode.\n");
554 smi_info
->si_state
= SI_NORMAL
;
560 /* Called on timeouts and events. Timeouts should pass the elapsed
561 time, interrupts should pass in zero. */
562 static enum si_sm_result
smi_event_handler(struct smi_info
*smi_info
,
565 enum si_sm_result si_sm_result
;
568 /* There used to be a loop here that waited a little while
569 (around 25us) before giving up. That turned out to be
570 pointless, the minimum delays I was seeing were in the 300us
571 range, which is far too long to wait in an interrupt. So
572 we just run until the state machine tells us something
573 happened or it needs a delay. */
574 si_sm_result
= smi_info
->handlers
->event(smi_info
->si_sm
, time
);
576 while (si_sm_result
== SI_SM_CALL_WITHOUT_DELAY
)
578 si_sm_result
= smi_info
->handlers
->event(smi_info
->si_sm
, 0);
581 if (si_sm_result
== SI_SM_TRANSACTION_COMPLETE
)
583 spin_lock(&smi_info
->count_lock
);
584 smi_info
->complete_transactions
++;
585 spin_unlock(&smi_info
->count_lock
);
587 handle_transaction_done(smi_info
);
588 si_sm_result
= smi_info
->handlers
->event(smi_info
->si_sm
, 0);
590 else if (si_sm_result
== SI_SM_HOSED
)
592 spin_lock(&smi_info
->count_lock
);
593 smi_info
->hosed_count
++;
594 spin_unlock(&smi_info
->count_lock
);
596 /* Do the before return_hosed_msg, because that
597 releases the lock. */
598 smi_info
->si_state
= SI_NORMAL
;
599 if (smi_info
->curr_msg
!= NULL
) {
600 /* If we were handling a user message, format
601 a response to send to the upper layer to
602 tell it about the error. */
603 return_hosed_msg(smi_info
);
605 si_sm_result
= smi_info
->handlers
->event(smi_info
->si_sm
, 0);
608 /* We prefer handling attn over new messages. */
609 if (si_sm_result
== SI_SM_ATTN
)
611 unsigned char msg
[2];
613 spin_lock(&smi_info
->count_lock
);
614 smi_info
->attentions
++;
615 spin_unlock(&smi_info
->count_lock
);
617 /* Got a attn, send down a get message flags to see
618 what's causing it. It would be better to handle
619 this in the upper layer, but due to the way
620 interrupts work with the SMI, that's not really
622 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
623 msg
[1] = IPMI_GET_MSG_FLAGS_CMD
;
625 smi_info
->handlers
->start_transaction(
626 smi_info
->si_sm
, msg
, 2);
627 smi_info
->si_state
= SI_GETTING_FLAGS
;
631 /* If we are currently idle, try to start the next message. */
632 if (si_sm_result
== SI_SM_IDLE
) {
633 spin_lock(&smi_info
->count_lock
);
635 spin_unlock(&smi_info
->count_lock
);
637 si_sm_result
= start_next_msg(smi_info
);
638 if (si_sm_result
!= SI_SM_IDLE
)
642 if ((si_sm_result
== SI_SM_IDLE
)
643 && (atomic_read(&smi_info
->req_events
)))
645 /* We are idle and the upper layer requested that I fetch
647 unsigned char msg
[2];
649 spin_lock(&smi_info
->count_lock
);
650 smi_info
->flag_fetches
++;
651 spin_unlock(&smi_info
->count_lock
);
653 atomic_set(&smi_info
->req_events
, 0);
654 msg
[0] = (IPMI_NETFN_APP_REQUEST
<< 2);
655 msg
[1] = IPMI_GET_MSG_FLAGS_CMD
;
657 smi_info
->handlers
->start_transaction(
658 smi_info
->si_sm
, msg
, 2);
659 smi_info
->si_state
= SI_GETTING_FLAGS
;
666 static void sender(void *send_info
,
667 struct ipmi_smi_msg
*msg
,
670 struct smi_info
*smi_info
= send_info
;
671 enum si_sm_result result
;
677 spin_lock_irqsave(&(smi_info
->msg_lock
), flags
);
680 printk("**Enqueue: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
683 if (smi_info
->run_to_completion
) {
684 /* If we are running to completion, then throw it in
685 the list and run transactions until everything is
686 clear. Priority doesn't matter here. */
687 list_add_tail(&(msg
->link
), &(smi_info
->xmit_msgs
));
689 /* We have to release the msg lock and claim the smi
690 lock in this case, because of race conditions. */
691 spin_unlock_irqrestore(&(smi_info
->msg_lock
), flags
);
693 spin_lock_irqsave(&(smi_info
->si_lock
), flags
);
694 result
= smi_event_handler(smi_info
, 0);
695 while (result
!= SI_SM_IDLE
) {
696 udelay(SI_SHORT_TIMEOUT_USEC
);
697 result
= smi_event_handler(smi_info
,
698 SI_SHORT_TIMEOUT_USEC
);
700 spin_unlock_irqrestore(&(smi_info
->si_lock
), flags
);
704 list_add_tail(&(msg
->link
), &(smi_info
->hp_xmit_msgs
));
706 list_add_tail(&(msg
->link
), &(smi_info
->xmit_msgs
));
709 spin_unlock_irqrestore(&(smi_info
->msg_lock
), flags
);
711 spin_lock_irqsave(&(smi_info
->si_lock
), flags
);
712 if ((smi_info
->si_state
== SI_NORMAL
)
713 && (smi_info
->curr_msg
== NULL
))
715 start_next_msg(smi_info
);
716 si_restart_short_timer(smi_info
);
718 spin_unlock_irqrestore(&(smi_info
->si_lock
), flags
);
721 static void set_run_to_completion(void *send_info
, int i_run_to_completion
)
723 struct smi_info
*smi_info
= send_info
;
724 enum si_sm_result result
;
727 spin_lock_irqsave(&(smi_info
->si_lock
), flags
);
729 smi_info
->run_to_completion
= i_run_to_completion
;
730 if (i_run_to_completion
) {
731 result
= smi_event_handler(smi_info
, 0);
732 while (result
!= SI_SM_IDLE
) {
733 udelay(SI_SHORT_TIMEOUT_USEC
);
734 result
= smi_event_handler(smi_info
,
735 SI_SHORT_TIMEOUT_USEC
);
739 spin_unlock_irqrestore(&(smi_info
->si_lock
), flags
);
742 static void poll(void *send_info
)
744 struct smi_info
*smi_info
= send_info
;
746 smi_event_handler(smi_info
, 0);
749 static void request_events(void *send_info
)
751 struct smi_info
*smi_info
= send_info
;
753 atomic_set(&smi_info
->req_events
, 1);
756 static int initialized
= 0;
758 /* Must be called with interrupts off and with the si_lock held. */
759 static void si_restart_short_timer(struct smi_info
*smi_info
)
761 #if defined(CONFIG_HIGH_RES_TIMERS)
763 unsigned long jiffies_now
;
765 if (del_timer(&(smi_info
->si_timer
))) {
766 /* If we don't delete the timer, then it will go off
767 immediately, anyway. So we only process if we
768 actually delete the timer. */
770 /* We already have irqsave on, so no need for it
772 read_lock(&xtime_lock
);
773 jiffies_now
= jiffies
;
774 smi_info
->si_timer
.expires
= jiffies_now
;
775 smi_info
->si_timer
.sub_expires
= get_arch_cycles(jiffies_now
);
777 add_usec_to_timer(&smi_info
->si_timer
, SI_SHORT_TIMEOUT_USEC
);
779 add_timer(&(smi_info
->si_timer
));
780 spin_lock_irqsave(&smi_info
->count_lock
, flags
);
781 smi_info
->timeout_restarts
++;
782 spin_unlock_irqrestore(&smi_info
->count_lock
, flags
);
787 static void smi_timeout(unsigned long data
)
789 struct smi_info
*smi_info
= (struct smi_info
*) data
;
790 enum si_sm_result smi_result
;
792 unsigned long jiffies_now
;
793 unsigned long time_diff
;
798 if (smi_info
->stop_operation
) {
799 smi_info
->timer_stopped
= 1;
803 spin_lock_irqsave(&(smi_info
->si_lock
), flags
);
806 printk("**Timer: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
808 jiffies_now
= jiffies
;
809 time_diff
= ((jiffies_now
- smi_info
->last_timeout_jiffies
)
810 * SI_USEC_PER_JIFFY
);
811 smi_result
= smi_event_handler(smi_info
, time_diff
);
813 spin_unlock_irqrestore(&(smi_info
->si_lock
), flags
);
815 smi_info
->last_timeout_jiffies
= jiffies_now
;
817 if ((smi_info
->irq
) && (! smi_info
->interrupt_disabled
)) {
818 /* Running with interrupts, only do long timeouts. */
819 smi_info
->si_timer
.expires
= jiffies
+ SI_TIMEOUT_JIFFIES
;
820 spin_lock_irqsave(&smi_info
->count_lock
, flags
);
821 smi_info
->long_timeouts
++;
822 spin_unlock_irqrestore(&smi_info
->count_lock
, flags
);
826 /* If the state machine asks for a short delay, then shorten
827 the timer timeout. */
828 if (smi_result
== SI_SM_CALL_WITH_DELAY
) {
829 spin_lock_irqsave(&smi_info
->count_lock
, flags
);
830 smi_info
->short_timeouts
++;
831 spin_unlock_irqrestore(&smi_info
->count_lock
, flags
);
832 #if defined(CONFIG_HIGH_RES_TIMERS)
833 read_lock(&xtime_lock
);
834 smi_info
->si_timer
.expires
= jiffies
;
835 smi_info
->si_timer
.sub_expires
836 = get_arch_cycles(smi_info
->si_timer
.expires
);
837 read_unlock(&xtime_lock
);
838 add_usec_to_timer(&smi_info
->si_timer
, SI_SHORT_TIMEOUT_USEC
);
840 smi_info
->si_timer
.expires
= jiffies
+ 1;
843 spin_lock_irqsave(&smi_info
->count_lock
, flags
);
844 smi_info
->long_timeouts
++;
845 spin_unlock_irqrestore(&smi_info
->count_lock
, flags
);
846 smi_info
->si_timer
.expires
= jiffies
+ SI_TIMEOUT_JIFFIES
;
847 #if defined(CONFIG_HIGH_RES_TIMERS)
848 smi_info
->si_timer
.sub_expires
= 0;
853 add_timer(&(smi_info
->si_timer
));
856 static irqreturn_t
si_irq_handler(int irq
, void *data
, struct pt_regs
*regs
)
858 struct smi_info
*smi_info
= data
;
864 spin_lock_irqsave(&(smi_info
->si_lock
), flags
);
866 spin_lock(&smi_info
->count_lock
);
867 smi_info
->interrupts
++;
868 spin_unlock(&smi_info
->count_lock
);
870 if (smi_info
->stop_operation
)
875 printk("**Interrupt: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
877 smi_event_handler(smi_info
, 0);
879 spin_unlock_irqrestore(&(smi_info
->si_lock
), flags
);
883 static irqreturn_t
si_bt_irq_handler(int irq
, void *data
, struct pt_regs
*regs
)
885 struct smi_info
*smi_info
= data
;
886 /* We need to clear the IRQ flag for the BT interface. */
887 smi_info
->io
.outputb(&smi_info
->io
, IPMI_BT_INTMASK_REG
,
888 IPMI_BT_INTMASK_CLEAR_IRQ_BIT
889 | IPMI_BT_INTMASK_ENABLE_IRQ_BIT
);
890 return si_irq_handler(irq
, data
, regs
);
894 static struct ipmi_smi_handlers handlers
=
896 .owner
= THIS_MODULE
,
898 .request_events
= request_events
,
899 .set_run_to_completion
= set_run_to_completion
,
903 /* There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
904 a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS */
906 #define SI_MAX_PARMS 4
907 #define SI_MAX_DRIVERS ((SI_MAX_PARMS * 2) + 2)
908 static struct smi_info
*smi_infos
[SI_MAX_DRIVERS
] =
909 { NULL
, NULL
, NULL
, NULL
};
911 #define DEVICE_NAME "ipmi_si"
913 #define DEFAULT_KCS_IO_PORT 0xca2
914 #define DEFAULT_SMIC_IO_PORT 0xca9
915 #define DEFAULT_BT_IO_PORT 0xe4
916 #define DEFAULT_REGSPACING 1
918 static int si_trydefaults
= 1;
919 static char *si_type
[SI_MAX_PARMS
];
920 #define MAX_SI_TYPE_STR 30
921 static char si_type_str
[MAX_SI_TYPE_STR
];
922 static unsigned long addrs
[SI_MAX_PARMS
];
923 static int num_addrs
;
924 static unsigned int ports
[SI_MAX_PARMS
];
925 static int num_ports
;
926 static int irqs
[SI_MAX_PARMS
];
928 static int regspacings
[SI_MAX_PARMS
];
929 static int num_regspacings
= 0;
930 static int regsizes
[SI_MAX_PARMS
];
931 static int num_regsizes
= 0;
932 static int regshifts
[SI_MAX_PARMS
];
933 static int num_regshifts
= 0;
934 static int slave_addrs
[SI_MAX_PARMS
];
935 static int num_slave_addrs
= 0;
938 module_param_named(trydefaults
, si_trydefaults
, bool, 0);
939 MODULE_PARM_DESC(trydefaults
, "Setting this to 'false' will disable the"
940 " default scan of the KCS and SMIC interface at the standard"
942 module_param_string(type
, si_type_str
, MAX_SI_TYPE_STR
, 0);
943 MODULE_PARM_DESC(type
, "Defines the type of each interface, each"
944 " interface separated by commas. The types are 'kcs',"
945 " 'smic', and 'bt'. For example si_type=kcs,bt will set"
946 " the first interface to kcs and the second to bt");
947 module_param_array(addrs
, long, &num_addrs
, 0);
948 MODULE_PARM_DESC(addrs
, "Sets the memory address of each interface, the"
949 " addresses separated by commas. Only use if an interface"
950 " is in memory. Otherwise, set it to zero or leave"
952 module_param_array(ports
, int, &num_ports
, 0);
953 MODULE_PARM_DESC(ports
, "Sets the port address of each interface, the"
954 " addresses separated by commas. Only use if an interface"
955 " is a port. Otherwise, set it to zero or leave"
957 module_param_array(irqs
, int, &num_irqs
, 0);
958 MODULE_PARM_DESC(irqs
, "Sets the interrupt of each interface, the"
959 " addresses separated by commas. Only use if an interface"
960 " has an interrupt. Otherwise, set it to zero or leave"
962 module_param_array(regspacings
, int, &num_regspacings
, 0);
963 MODULE_PARM_DESC(regspacings
, "The number of bytes between the start address"
964 " and each successive register used by the interface. For"
965 " instance, if the start address is 0xca2 and the spacing"
966 " is 2, then the second address is at 0xca4. Defaults"
968 module_param_array(regsizes
, int, &num_regsizes
, 0);
969 MODULE_PARM_DESC(regsizes
, "The size of the specific IPMI register in bytes."
970 " This should generally be 1, 2, 4, or 8 for an 8-bit,"
971 " 16-bit, 32-bit, or 64-bit register. Use this if you"
972 " the 8-bit IPMI register has to be read from a larger"
974 module_param_array(regshifts
, int, &num_regshifts
, 0);
975 MODULE_PARM_DESC(regshifts
, "The amount to shift the data read from the."
976 " IPMI register, in bits. For instance, if the data"
977 " is read from a 32-bit word and the IPMI data is in"
978 " bit 8-15, then the shift would be 8");
979 module_param_array(slave_addrs
, int, &num_slave_addrs
, 0);
980 MODULE_PARM_DESC(slave_addrs
, "Set the default IPMB slave address for"
981 " the controller. Normally this is 0x20, but can be"
982 " overridden by this parm. This is an array indexed"
983 " by interface number.");
986 #define IPMI_MEM_ADDR_SPACE 1
987 #define IPMI_IO_ADDR_SPACE 2
989 #if defined(CONFIG_ACPI_INTERPRETER) || defined(CONFIG_X86) || defined(CONFIG_PCI)
990 static int is_new_interface(int intf
, u8 addr_space
, unsigned long base_addr
)
994 for (i
= 0; i
< SI_MAX_PARMS
; ++i
) {
995 /* Don't check our address. */
998 if (si_type
[i
] != NULL
) {
999 if ((addr_space
== IPMI_MEM_ADDR_SPACE
&&
1000 base_addr
== addrs
[i
]) ||
1001 (addr_space
== IPMI_IO_ADDR_SPACE
&&
1002 base_addr
== ports
[i
]))
1013 static int std_irq_setup(struct smi_info
*info
)
1020 if (info
->si_type
== SI_BT
) {
1021 rv
= request_irq(info
->irq
,
1027 /* Enable the interrupt in the BT interface. */
1028 info
->io
.outputb(&info
->io
, IPMI_BT_INTMASK_REG
,
1029 IPMI_BT_INTMASK_ENABLE_IRQ_BIT
);
1031 rv
= request_irq(info
->irq
,
1038 "ipmi_si: %s unable to claim interrupt %d,"
1039 " running polled\n",
1040 DEVICE_NAME
, info
->irq
);
1043 printk(" Using irq %d\n", info
->irq
);
1049 static void std_irq_cleanup(struct smi_info
*info
)
1054 if (info
->si_type
== SI_BT
)
1055 /* Disable the interrupt in the BT interface. */
1056 info
->io
.outputb(&info
->io
, IPMI_BT_INTMASK_REG
, 0);
1057 free_irq(info
->irq
, info
);
1060 static unsigned char port_inb(struct si_sm_io
*io
, unsigned int offset
)
1062 unsigned int *addr
= io
->info
;
1064 return inb((*addr
)+(offset
*io
->regspacing
));
1067 static void port_outb(struct si_sm_io
*io
, unsigned int offset
,
1070 unsigned int *addr
= io
->info
;
1072 outb(b
, (*addr
)+(offset
* io
->regspacing
));
1075 static unsigned char port_inw(struct si_sm_io
*io
, unsigned int offset
)
1077 unsigned int *addr
= io
->info
;
1079 return (inw((*addr
)+(offset
* io
->regspacing
)) >> io
->regshift
) & 0xff;
1082 static void port_outw(struct si_sm_io
*io
, unsigned int offset
,
1085 unsigned int *addr
= io
->info
;
1087 outw(b
<< io
->regshift
, (*addr
)+(offset
* io
->regspacing
));
1090 static unsigned char port_inl(struct si_sm_io
*io
, unsigned int offset
)
1092 unsigned int *addr
= io
->info
;
1094 return (inl((*addr
)+(offset
* io
->regspacing
)) >> io
->regshift
) & 0xff;
1097 static void port_outl(struct si_sm_io
*io
, unsigned int offset
,
1100 unsigned int *addr
= io
->info
;
1102 outl(b
<< io
->regshift
, (*addr
)+(offset
* io
->regspacing
));
1105 static void port_cleanup(struct smi_info
*info
)
1107 unsigned int *addr
= info
->io
.info
;
1110 if (addr
&& (*addr
)) {
1111 mapsize
= ((info
->io_size
* info
->io
.regspacing
)
1112 - (info
->io
.regspacing
- info
->io
.regsize
));
1114 release_region (*addr
, mapsize
);
1119 static int port_setup(struct smi_info
*info
)
1121 unsigned int *addr
= info
->io
.info
;
1124 if (!addr
|| (!*addr
))
1127 info
->io_cleanup
= port_cleanup
;
1129 /* Figure out the actual inb/inw/inl/etc routine to use based
1130 upon the register size. */
1131 switch (info
->io
.regsize
) {
1133 info
->io
.inputb
= port_inb
;
1134 info
->io
.outputb
= port_outb
;
1137 info
->io
.inputb
= port_inw
;
1138 info
->io
.outputb
= port_outw
;
1141 info
->io
.inputb
= port_inl
;
1142 info
->io
.outputb
= port_outl
;
1145 printk("ipmi_si: Invalid register size: %d\n",
1150 /* Calculate the total amount of memory to claim. This is an
1151 * unusual looking calculation, but it avoids claiming any
1152 * more memory than it has to. It will claim everything
1153 * between the first address to the end of the last full
1155 mapsize
= ((info
->io_size
* info
->io
.regspacing
)
1156 - (info
->io
.regspacing
- info
->io
.regsize
));
1158 if (request_region(*addr
, mapsize
, DEVICE_NAME
) == NULL
)
1163 static int try_init_port(int intf_num
, struct smi_info
**new_info
)
1165 struct smi_info
*info
;
1167 if (!ports
[intf_num
])
1170 if (!is_new_interface(intf_num
, IPMI_IO_ADDR_SPACE
,
1174 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
1176 printk(KERN_ERR
"ipmi_si: Could not allocate SI data (1)\n");
1179 memset(info
, 0, sizeof(*info
));
1181 info
->io_setup
= port_setup
;
1182 info
->io
.info
= &(ports
[intf_num
]);
1183 info
->io
.addr
= NULL
;
1184 info
->io
.regspacing
= regspacings
[intf_num
];
1185 if (!info
->io
.regspacing
)
1186 info
->io
.regspacing
= DEFAULT_REGSPACING
;
1187 info
->io
.regsize
= regsizes
[intf_num
];
1188 if (!info
->io
.regsize
)
1189 info
->io
.regsize
= DEFAULT_REGSPACING
;
1190 info
->io
.regshift
= regshifts
[intf_num
];
1192 info
->irq_setup
= NULL
;
1195 if (si_type
[intf_num
] == NULL
)
1196 si_type
[intf_num
] = "kcs";
1198 printk("ipmi_si: Trying \"%s\" at I/O port 0x%x\n",
1199 si_type
[intf_num
], ports
[intf_num
]);
1203 static unsigned char mem_inb(struct si_sm_io
*io
, unsigned int offset
)
1205 return readb((io
->addr
)+(offset
* io
->regspacing
));
1208 static void mem_outb(struct si_sm_io
*io
, unsigned int offset
,
1211 writeb(b
, (io
->addr
)+(offset
* io
->regspacing
));
1214 static unsigned char mem_inw(struct si_sm_io
*io
, unsigned int offset
)
1216 return (readw((io
->addr
)+(offset
* io
->regspacing
)) >> io
->regshift
)
1220 static void mem_outw(struct si_sm_io
*io
, unsigned int offset
,
1223 writeb(b
<< io
->regshift
, (io
->addr
)+(offset
* io
->regspacing
));
1226 static unsigned char mem_inl(struct si_sm_io
*io
, unsigned int offset
)
1228 return (readl((io
->addr
)+(offset
* io
->regspacing
)) >> io
->regshift
)
1232 static void mem_outl(struct si_sm_io
*io
, unsigned int offset
,
1235 writel(b
<< io
->regshift
, (io
->addr
)+(offset
* io
->regspacing
));
1239 static unsigned char mem_inq(struct si_sm_io
*io
, unsigned int offset
)
1241 return (readq((io
->addr
)+(offset
* io
->regspacing
)) >> io
->regshift
)
1245 static void mem_outq(struct si_sm_io
*io
, unsigned int offset
,
1248 writeq(b
<< io
->regshift
, (io
->addr
)+(offset
* io
->regspacing
));
1252 static void mem_cleanup(struct smi_info
*info
)
1254 unsigned long *addr
= info
->io
.info
;
1257 if (info
->io
.addr
) {
1258 iounmap(info
->io
.addr
);
1260 mapsize
= ((info
->io_size
* info
->io
.regspacing
)
1261 - (info
->io
.regspacing
- info
->io
.regsize
));
1263 release_mem_region(*addr
, mapsize
);
1268 static int mem_setup(struct smi_info
*info
)
1270 unsigned long *addr
= info
->io
.info
;
1273 if (!addr
|| (!*addr
))
1276 info
->io_cleanup
= mem_cleanup
;
1278 /* Figure out the actual readb/readw/readl/etc routine to use based
1279 upon the register size. */
1280 switch (info
->io
.regsize
) {
1282 info
->io
.inputb
= mem_inb
;
1283 info
->io
.outputb
= mem_outb
;
1286 info
->io
.inputb
= mem_inw
;
1287 info
->io
.outputb
= mem_outw
;
1290 info
->io
.inputb
= mem_inl
;
1291 info
->io
.outputb
= mem_outl
;
1295 info
->io
.inputb
= mem_inq
;
1296 info
->io
.outputb
= mem_outq
;
1300 printk("ipmi_si: Invalid register size: %d\n",
1305 /* Calculate the total amount of memory to claim. This is an
1306 * unusual looking calculation, but it avoids claiming any
1307 * more memory than it has to. It will claim everything
1308 * between the first address to the end of the last full
1310 mapsize
= ((info
->io_size
* info
->io
.regspacing
)
1311 - (info
->io
.regspacing
- info
->io
.regsize
));
1313 if (request_mem_region(*addr
, mapsize
, DEVICE_NAME
) == NULL
)
1316 info
->io
.addr
= ioremap(*addr
, mapsize
);
1317 if (info
->io
.addr
== NULL
) {
1318 release_mem_region(*addr
, mapsize
);
1324 static int try_init_mem(int intf_num
, struct smi_info
**new_info
)
1326 struct smi_info
*info
;
1328 if (!addrs
[intf_num
])
1331 if (!is_new_interface(intf_num
, IPMI_MEM_ADDR_SPACE
,
1335 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
1337 printk(KERN_ERR
"ipmi_si: Could not allocate SI data (2)\n");
1340 memset(info
, 0, sizeof(*info
));
1342 info
->io_setup
= mem_setup
;
1343 info
->io
.info
= &addrs
[intf_num
];
1344 info
->io
.addr
= NULL
;
1345 info
->io
.regspacing
= regspacings
[intf_num
];
1346 if (!info
->io
.regspacing
)
1347 info
->io
.regspacing
= DEFAULT_REGSPACING
;
1348 info
->io
.regsize
= regsizes
[intf_num
];
1349 if (!info
->io
.regsize
)
1350 info
->io
.regsize
= DEFAULT_REGSPACING
;
1351 info
->io
.regshift
= regshifts
[intf_num
];
1353 info
->irq_setup
= NULL
;
1356 if (si_type
[intf_num
] == NULL
)
1357 si_type
[intf_num
] = "kcs";
1359 printk("ipmi_si: Trying \"%s\" at memory address 0x%lx\n",
1360 si_type
[intf_num
], addrs
[intf_num
]);
1365 #ifdef CONFIG_ACPI_INTERPRETER
1367 #include <linux/acpi.h>
1369 /* Once we get an ACPI failure, we don't try any more, because we go
1370 through the tables sequentially. Once we don't find a table, there
1372 static int acpi_failure
= 0;
1374 /* For GPE-type interrupts. */
1375 static u32
ipmi_acpi_gpe(void *context
)
1377 struct smi_info
*smi_info
= context
;
1378 unsigned long flags
;
1383 spin_lock_irqsave(&(smi_info
->si_lock
), flags
);
1385 spin_lock(&smi_info
->count_lock
);
1386 smi_info
->interrupts
++;
1387 spin_unlock(&smi_info
->count_lock
);
1389 if (smi_info
->stop_operation
)
1393 do_gettimeofday(&t
);
1394 printk("**ACPI_GPE: %d.%9.9d\n", t
.tv_sec
, t
.tv_usec
);
1396 smi_event_handler(smi_info
, 0);
1398 spin_unlock_irqrestore(&(smi_info
->si_lock
), flags
);
1400 return ACPI_INTERRUPT_HANDLED
;
1403 static int acpi_gpe_irq_setup(struct smi_info
*info
)
1410 /* FIXME - is level triggered right? */
1411 status
= acpi_install_gpe_handler(NULL
,
1413 ACPI_GPE_LEVEL_TRIGGERED
,
1416 if (status
!= AE_OK
) {
1418 "ipmi_si: %s unable to claim ACPI GPE %d,"
1419 " running polled\n",
1420 DEVICE_NAME
, info
->irq
);
1424 printk(" Using ACPI GPE %d\n", info
->irq
);
1429 static void acpi_gpe_irq_cleanup(struct smi_info
*info
)
1434 acpi_remove_gpe_handler(NULL
, info
->irq
, &ipmi_acpi_gpe
);
1439 * http://h21007.www2.hp.com/dspp/files/unprotected/devresource/Docs/TechPapers/IA64/hpspmi.pdf
1450 s8 CreatorRevision
[4];
1453 s16 SpecificationRevision
;
1456 * Bit 0 - SCI interrupt supported
1457 * Bit 1 - I/O APIC/SAPIC
1461 /* If bit 0 of InterruptType is set, then this is the SCI
1462 interrupt in the GPEx_STS register. */
1467 /* If bit 1 of InterruptType is set, then this is the I/O
1468 APIC/SAPIC interrupt. */
1469 u32 GlobalSystemInterrupt
;
1471 /* The actual register address. */
1472 struct acpi_generic_address addr
;
1476 s8 spmi_id
[1]; /* A '\0' terminated array starts here. */
1479 static int try_init_acpi(int intf_num
, struct smi_info
**new_info
)
1481 struct smi_info
*info
;
1483 struct SPMITable
*spmi
;
1490 status
= acpi_get_firmware_table("SPMI", intf_num
+1,
1491 ACPI_LOGICAL_ADDRESSING
,
1492 (struct acpi_table_header
**) &spmi
);
1493 if (status
!= AE_OK
) {
1498 if (spmi
->IPMIlegacy
!= 1) {
1499 printk(KERN_INFO
"IPMI: Bad SPMI legacy %d\n", spmi
->IPMIlegacy
);
1503 if (spmi
->addr
.address_space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
)
1504 addr_space
= IPMI_MEM_ADDR_SPACE
;
1506 addr_space
= IPMI_IO_ADDR_SPACE
;
1507 if (!is_new_interface(-1, addr_space
, spmi
->addr
.address
))
1510 if (!spmi
->addr
.register_bit_width
) {
1515 /* Figure out the interface type. */
1516 switch (spmi
->InterfaceType
)
1519 si_type
[intf_num
] = "kcs";
1523 si_type
[intf_num
] = "smic";
1527 si_type
[intf_num
] = "bt";
1531 printk(KERN_INFO
"ipmi_si: Unknown ACPI/SPMI SI type %d\n",
1532 spmi
->InterfaceType
);
1536 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
1538 printk(KERN_ERR
"ipmi_si: Could not allocate SI data (3)\n");
1541 memset(info
, 0, sizeof(*info
));
1543 if (spmi
->InterruptType
& 1) {
1544 /* We've got a GPE interrupt. */
1545 info
->irq
= spmi
->GPE
;
1546 info
->irq_setup
= acpi_gpe_irq_setup
;
1547 info
->irq_cleanup
= acpi_gpe_irq_cleanup
;
1548 } else if (spmi
->InterruptType
& 2) {
1549 /* We've got an APIC/SAPIC interrupt. */
1550 info
->irq
= spmi
->GlobalSystemInterrupt
;
1551 info
->irq_setup
= std_irq_setup
;
1552 info
->irq_cleanup
= std_irq_cleanup
;
1554 /* Use the default interrupt setting. */
1556 info
->irq_setup
= NULL
;
1559 if (spmi
->addr
.register_bit_width
) {
1560 /* A (hopefully) properly formed register bit width. */
1561 regspacings
[intf_num
] = spmi
->addr
.register_bit_width
/ 8;
1562 info
->io
.regspacing
= spmi
->addr
.register_bit_width
/ 8;
1564 /* Some broken systems get this wrong and set the value
1565 * to zero. Assume it is the default spacing. If that
1566 * is wrong, too bad, the vendor should fix the tables. */
1567 regspacings
[intf_num
] = DEFAULT_REGSPACING
;
1568 info
->io
.regspacing
= DEFAULT_REGSPACING
;
1570 regsizes
[intf_num
] = regspacings
[intf_num
];
1571 info
->io
.regsize
= regsizes
[intf_num
];
1572 regshifts
[intf_num
] = spmi
->addr
.register_bit_offset
;
1573 info
->io
.regshift
= regshifts
[intf_num
];
1575 if (spmi
->addr
.address_space_id
== ACPI_ADR_SPACE_SYSTEM_MEMORY
) {
1577 info
->io_setup
= mem_setup
;
1578 addrs
[intf_num
] = spmi
->addr
.address
;
1579 info
->io
.info
= &(addrs
[intf_num
]);
1580 } else if (spmi
->addr
.address_space_id
== ACPI_ADR_SPACE_SYSTEM_IO
) {
1582 info
->io_setup
= port_setup
;
1583 ports
[intf_num
] = spmi
->addr
.address
;
1584 info
->io
.info
= &(ports
[intf_num
]);
1587 printk("ipmi_si: Unknown ACPI I/O Address type\n");
1593 printk("ipmi_si: ACPI/SPMI specifies \"%s\" %s SI @ 0x%lx\n",
1594 si_type
[intf_num
], io_type
, (unsigned long) spmi
->addr
.address
);
1600 typedef struct dmi_ipmi_data
1604 unsigned long base_addr
;
1610 static dmi_ipmi_data_t dmi_data
[SI_MAX_DRIVERS
];
1611 static int dmi_data_entries
;
1613 typedef struct dmi_header
1620 static int decode_dmi(dmi_header_t __iomem
*dm
, int intf_num
)
1622 u8 __iomem
*data
= (u8 __iomem
*)dm
;
1623 unsigned long base_addr
;
1625 u8 len
= readb(&dm
->length
);
1626 dmi_ipmi_data_t
*ipmi_data
= dmi_data
+intf_num
;
1628 ipmi_data
->type
= readb(&data
[4]);
1630 memcpy(&base_addr
, data
+8, sizeof(unsigned long));
1632 if (base_addr
& 1) {
1634 base_addr
&= 0xFFFE;
1635 ipmi_data
->addr_space
= IPMI_IO_ADDR_SPACE
;
1639 ipmi_data
->addr_space
= IPMI_MEM_ADDR_SPACE
;
1641 /* If bit 4 of byte 0x10 is set, then the lsb for the address
1643 ipmi_data
->base_addr
= base_addr
| ((readb(&data
[0x10]) & 0x10) >> 4);
1645 ipmi_data
->irq
= readb(&data
[0x11]);
1647 /* The top two bits of byte 0x10 hold the register spacing. */
1648 reg_spacing
= (readb(&data
[0x10]) & 0xC0) >> 6;
1649 switch(reg_spacing
){
1650 case 0x00: /* Byte boundaries */
1651 ipmi_data
->offset
= 1;
1653 case 0x01: /* 32-bit boundaries */
1654 ipmi_data
->offset
= 4;
1656 case 0x02: /* 16-byte boundaries */
1657 ipmi_data
->offset
= 16;
1660 /* Some other interface, just ignore it. */
1665 /* Note that technically, the lower bit of the base
1666 * address should be 1 if the address is I/O and 0 if
1667 * the address is in memory. So many systems get that
1668 * wrong (and all that I have seen are I/O) so we just
1669 * ignore that bit and assume I/O. Systems that use
1670 * memory should use the newer spec, anyway. */
1671 ipmi_data
->base_addr
= base_addr
& 0xfffe;
1672 ipmi_data
->addr_space
= IPMI_IO_ADDR_SPACE
;
1673 ipmi_data
->offset
= 1;
1676 ipmi_data
->slave_addr
= readb(&data
[6]);
1678 if (is_new_interface(-1, ipmi_data
->addr_space
,ipmi_data
->base_addr
)) {
1683 memset(ipmi_data
, 0, sizeof(dmi_ipmi_data_t
));
1688 static int dmi_table(u32 base
, int len
, int num
)
1691 struct dmi_header __iomem
*dm
;
1697 buf
= ioremap(base
, len
);
1703 while(i
<num
&& (data
- buf
) < len
)
1705 dm
=(dmi_header_t __iomem
*)data
;
1707 if((data
-buf
+readb(&dm
->length
)) >= len
)
1710 if (readb(&dm
->type
) == 38) {
1711 if (decode_dmi(dm
, intf_num
) == 0) {
1713 if (intf_num
>= SI_MAX_DRIVERS
)
1718 data
+=readb(&dm
->length
);
1719 while((data
-buf
) < len
&& (readb(data
)||readb(data
+1)))
1729 inline static int dmi_checksum(u8
*buf
)
1739 static int dmi_decode(void)
1744 #ifdef CONFIG_SIMNOW
1750 isa_memcpy_fromio(buf
, fp
, 15);
1751 if(memcmp(buf
, "_DMI_", 5)==0 && dmi_checksum(buf
))
1753 u16 num
=buf
[13]<<8|buf
[12];
1754 u16 len
=buf
[7]<<8|buf
[6];
1755 u32 base
=buf
[11]<<24|buf
[10]<<16|buf
[9]<<8|buf
[8];
1757 if(dmi_table(base
, len
, num
) == 0)
1766 static int try_init_smbios(int intf_num
, struct smi_info
**new_info
)
1768 struct smi_info
*info
;
1769 dmi_ipmi_data_t
*ipmi_data
= dmi_data
+intf_num
;
1772 if (intf_num
>= dmi_data_entries
)
1775 switch(ipmi_data
->type
) {
1776 case 0x01: /* KCS */
1777 si_type
[intf_num
] = "kcs";
1779 case 0x02: /* SMIC */
1780 si_type
[intf_num
] = "smic";
1783 si_type
[intf_num
] = "bt";
1789 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
1791 printk(KERN_ERR
"ipmi_si: Could not allocate SI data (4)\n");
1794 memset(info
, 0, sizeof(*info
));
1796 if (ipmi_data
->addr_space
== 1) {
1798 info
->io_setup
= mem_setup
;
1799 addrs
[intf_num
] = ipmi_data
->base_addr
;
1800 info
->io
.info
= &(addrs
[intf_num
]);
1801 } else if (ipmi_data
->addr_space
== 2) {
1803 info
->io_setup
= port_setup
;
1804 ports
[intf_num
] = ipmi_data
->base_addr
;
1805 info
->io
.info
= &(ports
[intf_num
]);
1808 printk("ipmi_si: Unknown SMBIOS I/O Address type.\n");
1812 regspacings
[intf_num
] = ipmi_data
->offset
;
1813 info
->io
.regspacing
= regspacings
[intf_num
];
1814 if (!info
->io
.regspacing
)
1815 info
->io
.regspacing
= DEFAULT_REGSPACING
;
1816 info
->io
.regsize
= DEFAULT_REGSPACING
;
1817 info
->io
.regshift
= regshifts
[intf_num
];
1819 info
->slave_addr
= ipmi_data
->slave_addr
;
1821 irqs
[intf_num
] = ipmi_data
->irq
;
1825 printk("ipmi_si: Found SMBIOS-specified state machine at %s"
1826 " address 0x%lx, slave address 0x%x\n",
1827 io_type
, (unsigned long)ipmi_data
->base_addr
,
1828 ipmi_data
->slave_addr
);
1831 #endif /* CONFIG_X86 */
1835 #define PCI_ERMC_CLASSCODE 0x0C0700
1836 #define PCI_HP_VENDOR_ID 0x103C
1837 #define PCI_MMC_DEVICE_ID 0x121A
1838 #define PCI_MMC_ADDR_CW 0x10
1840 /* Avoid more than one attempt to probe pci smic. */
1841 static int pci_smic_checked
= 0;
1843 static int find_pci_smic(int intf_num
, struct smi_info
**new_info
)
1845 struct smi_info
*info
;
1847 struct pci_dev
*pci_dev
= NULL
;
1851 if (pci_smic_checked
)
1854 pci_smic_checked
= 1;
1856 if ((pci_dev
= pci_get_device(PCI_HP_VENDOR_ID
, PCI_MMC_DEVICE_ID
,
1859 else if ((pci_dev
= pci_get_class(PCI_ERMC_CLASSCODE
, NULL
)) &&
1860 pci_dev
->subsystem_vendor
== PCI_HP_VENDOR_ID
)
1865 error
= pci_read_config_word(pci_dev
, PCI_MMC_ADDR_CW
, &base_addr
);
1868 pci_dev_put(pci_dev
);
1870 "ipmi_si: pci_read_config_word() failed (%d).\n",
1875 /* Bit 0: 1 specifies programmed I/O, 0 specifies memory mapped I/O */
1876 if (!(base_addr
& 0x0001))
1878 pci_dev_put(pci_dev
);
1880 "ipmi_si: memory mapped I/O not supported for PCI"
1885 base_addr
&= 0xFFFE;
1887 /* Data register starts at base address + 1 in eRMC */
1890 if (!is_new_interface(-1, IPMI_IO_ADDR_SPACE
, base_addr
)) {
1891 pci_dev_put(pci_dev
);
1895 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
1897 pci_dev_put(pci_dev
);
1898 printk(KERN_ERR
"ipmi_si: Could not allocate SI data (5)\n");
1901 memset(info
, 0, sizeof(*info
));
1903 info
->io_setup
= port_setup
;
1904 ports
[intf_num
] = base_addr
;
1905 info
->io
.info
= &(ports
[intf_num
]);
1906 info
->io
.regspacing
= regspacings
[intf_num
];
1907 if (!info
->io
.regspacing
)
1908 info
->io
.regspacing
= DEFAULT_REGSPACING
;
1909 info
->io
.regsize
= DEFAULT_REGSPACING
;
1910 info
->io
.regshift
= regshifts
[intf_num
];
1914 irqs
[intf_num
] = pci_dev
->irq
;
1915 si_type
[intf_num
] = "smic";
1917 printk("ipmi_si: Found PCI SMIC at I/O address 0x%lx\n",
1918 (long unsigned int) base_addr
);
1920 pci_dev_put(pci_dev
);
1923 #endif /* CONFIG_PCI */
1925 static int try_init_plug_and_play(int intf_num
, struct smi_info
**new_info
)
1928 if (find_pci_smic(intf_num
, new_info
)==0)
1931 /* Include other methods here. */
1937 static int try_get_dev_id(struct smi_info
*smi_info
)
1939 unsigned char msg
[2];
1940 unsigned char *resp
;
1941 unsigned long resp_len
;
1942 enum si_sm_result smi_result
;
1945 resp
= kmalloc(IPMI_MAX_MSG_LENGTH
, GFP_KERNEL
);
1949 /* Do a Get Device ID command, since it comes back with some
1951 msg
[0] = IPMI_NETFN_APP_REQUEST
<< 2;
1952 msg
[1] = IPMI_GET_DEVICE_ID_CMD
;
1953 smi_info
->handlers
->start_transaction(smi_info
->si_sm
, msg
, 2);
1955 smi_result
= smi_info
->handlers
->event(smi_info
->si_sm
, 0);
1958 if (smi_result
== SI_SM_CALL_WITH_DELAY
) {
1959 set_current_state(TASK_UNINTERRUPTIBLE
);
1960 schedule_timeout(1);
1961 smi_result
= smi_info
->handlers
->event(
1962 smi_info
->si_sm
, 100);
1964 else if (smi_result
== SI_SM_CALL_WITHOUT_DELAY
)
1966 smi_result
= smi_info
->handlers
->event(
1967 smi_info
->si_sm
, 0);
1972 if (smi_result
== SI_SM_HOSED
) {
1973 /* We couldn't get the state machine to run, so whatever's at
1974 the port is probably not an IPMI SMI interface. */
1979 /* Otherwise, we got some data. */
1980 resp_len
= smi_info
->handlers
->get_result(smi_info
->si_sm
,
1981 resp
, IPMI_MAX_MSG_LENGTH
);
1983 /* That's odd, it should be longer. */
1988 if ((resp
[1] != IPMI_GET_DEVICE_ID_CMD
) || (resp
[2] != 0)) {
1989 /* That's odd, it shouldn't be able to fail. */
1994 /* Record info from the get device id, in case we need it. */
1995 smi_info
->ipmi_si_dev_rev
= resp
[4] & 0xf;
1996 smi_info
->ipmi_si_fw_rev_major
= resp
[5] & 0x7f;
1997 smi_info
->ipmi_si_fw_rev_minor
= resp
[6];
1998 smi_info
->ipmi_version_major
= resp
[7] & 0xf;
1999 smi_info
->ipmi_version_minor
= resp
[7] >> 4;
2006 static int type_file_read_proc(char *page
, char **start
, off_t off
,
2007 int count
, int *eof
, void *data
)
2009 char *out
= (char *) page
;
2010 struct smi_info
*smi
= data
;
2012 switch (smi
->si_type
) {
2014 return sprintf(out
, "kcs\n");
2016 return sprintf(out
, "smic\n");
2018 return sprintf(out
, "bt\n");
2024 static int stat_file_read_proc(char *page
, char **start
, off_t off
,
2025 int count
, int *eof
, void *data
)
2027 char *out
= (char *) page
;
2028 struct smi_info
*smi
= data
;
2030 out
+= sprintf(out
, "interrupts_enabled: %d\n",
2031 smi
->irq
&& !smi
->interrupt_disabled
);
2032 out
+= sprintf(out
, "short_timeouts: %ld\n",
2033 smi
->short_timeouts
);
2034 out
+= sprintf(out
, "long_timeouts: %ld\n",
2035 smi
->long_timeouts
);
2036 out
+= sprintf(out
, "timeout_restarts: %ld\n",
2037 smi
->timeout_restarts
);
2038 out
+= sprintf(out
, "idles: %ld\n",
2040 out
+= sprintf(out
, "interrupts: %ld\n",
2042 out
+= sprintf(out
, "attentions: %ld\n",
2044 out
+= sprintf(out
, "flag_fetches: %ld\n",
2046 out
+= sprintf(out
, "hosed_count: %ld\n",
2048 out
+= sprintf(out
, "complete_transactions: %ld\n",
2049 smi
->complete_transactions
);
2050 out
+= sprintf(out
, "events: %ld\n",
2052 out
+= sprintf(out
, "watchdog_pretimeouts: %ld\n",
2053 smi
->watchdog_pretimeouts
);
2054 out
+= sprintf(out
, "incoming_messages: %ld\n",
2055 smi
->incoming_messages
);
2057 return (out
- ((char *) page
));
2060 /* Returns 0 if initialized, or negative on an error. */
2061 static int init_one_smi(int intf_num
, struct smi_info
**smi
)
2064 struct smi_info
*new_smi
;
2067 rv
= try_init_mem(intf_num
, &new_smi
);
2069 rv
= try_init_port(intf_num
, &new_smi
);
2070 #ifdef CONFIG_ACPI_INTERPRETER
2071 if ((rv
) && (si_trydefaults
)) {
2072 rv
= try_init_acpi(intf_num
, &new_smi
);
2076 if ((rv
) && (si_trydefaults
)) {
2077 rv
= try_init_smbios(intf_num
, &new_smi
);
2080 if ((rv
) && (si_trydefaults
)) {
2081 rv
= try_init_plug_and_play(intf_num
, &new_smi
);
2088 /* So we know not to free it unless we have allocated one. */
2089 new_smi
->intf
= NULL
;
2090 new_smi
->si_sm
= NULL
;
2091 new_smi
->handlers
= NULL
;
2093 if (!new_smi
->irq_setup
) {
2094 new_smi
->irq
= irqs
[intf_num
];
2095 new_smi
->irq_setup
= std_irq_setup
;
2096 new_smi
->irq_cleanup
= std_irq_cleanup
;
2099 /* Default to KCS if no type is specified. */
2100 if (si_type
[intf_num
] == NULL
) {
2102 si_type
[intf_num
] = "kcs";
2109 /* Set up the state machine to use. */
2110 if (strcmp(si_type
[intf_num
], "kcs") == 0) {
2111 new_smi
->handlers
= &kcs_smi_handlers
;
2112 new_smi
->si_type
= SI_KCS
;
2113 } else if (strcmp(si_type
[intf_num
], "smic") == 0) {
2114 new_smi
->handlers
= &smic_smi_handlers
;
2115 new_smi
->si_type
= SI_SMIC
;
2116 } else if (strcmp(si_type
[intf_num
], "bt") == 0) {
2117 new_smi
->handlers
= &bt_smi_handlers
;
2118 new_smi
->si_type
= SI_BT
;
2120 /* No support for anything else yet. */
2125 /* Allocate the state machine's data and initialize it. */
2126 new_smi
->si_sm
= kmalloc(new_smi
->handlers
->size(), GFP_KERNEL
);
2127 if (!new_smi
->si_sm
) {
2128 printk(" Could not allocate state machine memory\n");
2132 new_smi
->io_size
= new_smi
->handlers
->init_data(new_smi
->si_sm
,
2135 /* Now that we know the I/O size, we can set up the I/O. */
2136 rv
= new_smi
->io_setup(new_smi
);
2138 printk(" Could not set up I/O space\n");
2142 spin_lock_init(&(new_smi
->si_lock
));
2143 spin_lock_init(&(new_smi
->msg_lock
));
2144 spin_lock_init(&(new_smi
->count_lock
));
2146 /* Do low-level detection first. */
2147 if (new_smi
->handlers
->detect(new_smi
->si_sm
)) {
2152 /* Attempt a get device id command. If it fails, we probably
2153 don't have a SMI here. */
2154 rv
= try_get_dev_id(new_smi
);
2158 /* Try to claim any interrupts. */
2159 new_smi
->irq_setup(new_smi
);
2161 INIT_LIST_HEAD(&(new_smi
->xmit_msgs
));
2162 INIT_LIST_HEAD(&(new_smi
->hp_xmit_msgs
));
2163 new_smi
->curr_msg
= NULL
;
2164 atomic_set(&new_smi
->req_events
, 0);
2165 new_smi
->run_to_completion
= 0;
2167 new_smi
->interrupt_disabled
= 0;
2168 new_smi
->timer_stopped
= 0;
2169 new_smi
->stop_operation
= 0;
2171 /* Start clearing the flags before we enable interrupts or the
2172 timer to avoid racing with the timer. */
2173 start_clear_flags(new_smi
);
2174 /* IRQ is defined to be set when non-zero. */
2176 new_smi
->si_state
= SI_CLEARING_FLAGS_THEN_SET_IRQ
;
2178 /* The ipmi_register_smi() code does some operations to
2179 determine the channel information, so we must be ready to
2180 handle operations before it is called. This means we have
2181 to stop the timer if we get an error after this point. */
2182 init_timer(&(new_smi
->si_timer
));
2183 new_smi
->si_timer
.data
= (long) new_smi
;
2184 new_smi
->si_timer
.function
= smi_timeout
;
2185 new_smi
->last_timeout_jiffies
= jiffies
;
2186 new_smi
->si_timer
.expires
= jiffies
+ SI_TIMEOUT_JIFFIES
;
2187 add_timer(&(new_smi
->si_timer
));
2189 rv
= ipmi_register_smi(&handlers
,
2191 new_smi
->ipmi_version_major
,
2192 new_smi
->ipmi_version_minor
,
2193 new_smi
->slave_addr
,
2197 "ipmi_si: Unable to register device: error %d\n",
2199 goto out_err_stop_timer
;
2202 rv
= ipmi_smi_add_proc_entry(new_smi
->intf
, "type",
2203 type_file_read_proc
, NULL
,
2204 new_smi
, THIS_MODULE
);
2207 "ipmi_si: Unable to create proc entry: %d\n",
2209 goto out_err_stop_timer
;
2212 rv
= ipmi_smi_add_proc_entry(new_smi
->intf
, "si_stats",
2213 stat_file_read_proc
, NULL
,
2214 new_smi
, THIS_MODULE
);
2217 "ipmi_si: Unable to create proc entry: %d\n",
2219 goto out_err_stop_timer
;
2224 printk(" IPMI %s interface initialized\n", si_type
[intf_num
]);
2229 new_smi
->stop_operation
= 1;
2231 /* Wait for the timer to stop. This avoids problems with race
2232 conditions removing the timer here. */
2233 while (!new_smi
->timer_stopped
) {
2234 set_current_state(TASK_UNINTERRUPTIBLE
);
2235 schedule_timeout(1);
2240 ipmi_unregister_smi(new_smi
->intf
);
2242 new_smi
->irq_cleanup(new_smi
);
2244 /* Wait until we know that we are out of any interrupt
2245 handlers might have been running before we freed the
2247 synchronize_sched();
2249 if (new_smi
->si_sm
) {
2250 if (new_smi
->handlers
)
2251 new_smi
->handlers
->cleanup(new_smi
->si_sm
);
2252 kfree(new_smi
->si_sm
);
2254 new_smi
->io_cleanup(new_smi
);
2259 static __init
int init_ipmi_si(void)
2270 /* Parse out the si_type string into its components. */
2273 for (i
=0; (i
<SI_MAX_PARMS
) && (*str
!= '\0'); i
++) {
2275 str
= strchr(str
, ',');
2285 printk(KERN_INFO
"IPMI System Interface driver version "
2287 if (kcs_smi_handlers
.version
)
2288 printk(", KCS version %s", kcs_smi_handlers
.version
);
2289 if (smic_smi_handlers
.version
)
2290 printk(", SMIC version %s", smic_smi_handlers
.version
);
2291 if (bt_smi_handlers
.version
)
2292 printk(", BT version %s", bt_smi_handlers
.version
);
2299 rv
= init_one_smi(0, &(smi_infos
[pos
]));
2300 if (rv
&& !ports
[0] && si_trydefaults
) {
2301 /* If we are trying defaults and the initial port is
2302 not set, then set it. */
2304 ports
[0] = DEFAULT_KCS_IO_PORT
;
2305 rv
= init_one_smi(0, &(smi_infos
[pos
]));
2307 /* No KCS - try SMIC */
2308 si_type
[0] = "smic";
2309 ports
[0] = DEFAULT_SMIC_IO_PORT
;
2310 rv
= init_one_smi(0, &(smi_infos
[pos
]));
2313 /* No SMIC - try BT */
2315 ports
[0] = DEFAULT_BT_IO_PORT
;
2316 rv
= init_one_smi(0, &(smi_infos
[pos
]));
2322 for (i
=1; i
< SI_MAX_PARMS
; i
++) {
2323 rv
= init_one_smi(i
, &(smi_infos
[pos
]));
2328 if (smi_infos
[0] == NULL
) {
2329 printk("ipmi_si: Unable to find any System Interface(s)\n");
2335 module_init(init_ipmi_si
);
2337 static void __exit
cleanup_one_si(struct smi_info
*to_clean
)
2340 unsigned long flags
;
2345 /* Tell the timer and interrupt handlers that we are shutting
2347 spin_lock_irqsave(&(to_clean
->si_lock
), flags
);
2348 spin_lock(&(to_clean
->msg_lock
));
2350 to_clean
->stop_operation
= 1;
2352 to_clean
->irq_cleanup(to_clean
);
2354 spin_unlock(&(to_clean
->msg_lock
));
2355 spin_unlock_irqrestore(&(to_clean
->si_lock
), flags
);
2357 /* Wait until we know that we are out of any interrupt
2358 handlers might have been running before we freed the
2360 synchronize_sched();
2362 /* Wait for the timer to stop. This avoids problems with race
2363 conditions removing the timer here. */
2364 while (!to_clean
->timer_stopped
) {
2365 set_current_state(TASK_UNINTERRUPTIBLE
);
2366 schedule_timeout(1);
2369 /* Interrupts and timeouts are stopped, now make sure the
2370 interface is in a clean state. */
2371 while ((to_clean
->curr_msg
) || (to_clean
->si_state
!= SI_NORMAL
)) {
2373 set_current_state(TASK_UNINTERRUPTIBLE
);
2374 schedule_timeout(1);
2377 rv
= ipmi_unregister_smi(to_clean
->intf
);
2380 "ipmi_si: Unable to unregister device: errno=%d\n",
2384 to_clean
->handlers
->cleanup(to_clean
->si_sm
);
2386 kfree(to_clean
->si_sm
);
2388 to_clean
->io_cleanup(to_clean
);
2391 static __exit
void cleanup_ipmi_si(void)
2398 for (i
=0; i
<SI_MAX_DRIVERS
; i
++) {
2399 cleanup_one_si(smi_infos
[i
]);
2402 module_exit(cleanup_ipmi_si
);
2404 MODULE_LICENSE("GPL");