4 * Incoming and outgoing message routing for an IPMI interface.
6 * Author: MontaVista Software, Inc.
7 * Corey Minyard <minyard@mvista.com>
10 * Copyright 2002 MontaVista Software Inc.
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * You should have received a copy of the GNU General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 675 Mass Ave, Cambridge, MA 02139, USA.
34 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/errno.h>
37 #include <asm/system.h>
38 #include <linux/sched.h>
39 #include <linux/poll.h>
40 #include <linux/spinlock.h>
41 #include <linux/rwsem.h>
42 #include <linux/slab.h>
43 #include <linux/ipmi.h>
44 #include <linux/ipmi_smi.h>
45 #include <linux/notifier.h>
46 #include <linux/init.h>
47 #include <linux/proc_fs.h>
49 #define PFX "IPMI message handler: "
51 #define IPMI_DRIVER_VERSION "36.0"
53 static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
54 static int ipmi_init_msghandler(void);
56 static int initialized = 0;
59 struct proc_dir_entry *proc_ipmi_root = NULL;
60 #endif /* CONFIG_PROC_FS */
62 #define MAX_EVENTS_IN_QUEUE 25
64 /* Don't let a message sit in a queue forever, always time it with at lest
65 the max message timer. This is in milliseconds. */
66 #define MAX_MSG_TIMEOUT 60000
70 struct list_head link;
72 /* The upper layer that handles receive messages. */
73 struct ipmi_user_hndl *handler;
76 /* The interface this user is bound to. */
79 /* Does this interface receive IPMI events? */
85 struct list_head link;
94 unsigned int inuse : 1;
95 unsigned int broadcast : 1;
97 unsigned long timeout;
98 unsigned long orig_timeout;
99 unsigned int retries_left;
101 /* To verify on an incoming send message response that this is
102 the message that the response is for, we keep a sequence id
103 and increment it every time we send a message. */
106 /* This is held so we can properly respond to the message on a
107 timeout, and it is used to hold the temporary data for
108 retransmission, too. */
109 struct ipmi_recv_msg *recv_msg;
112 /* Store the information in a msgid (long) to allow us to find a
113 sequence table entry from the msgid. */
114 #define STORE_SEQ_IN_MSGID(seq, seqid) (((seq&0xff)<<26) | (seqid&0x3ffffff))
116 #define GET_SEQ_FROM_MSGID(msgid, seq, seqid) \
118 seq = ((msgid >> 26) & 0x3f); \
119 seqid = (msgid & 0x3fffff); \
122 #define NEXT_SEQID(seqid) (((seqid) + 1) & 0x3fffff)
126 unsigned char medium;
127 unsigned char protocol;
129 /* My slave address. This is initialized to IPMI_BMC_SLAVE_ADDR,
130 but may be changed by the user. */
131 unsigned char address;
133 /* My LUN. This should generally stay the SMS LUN, but just in
138 #ifdef CONFIG_PROC_FS
139 struct ipmi_proc_entry
142 struct ipmi_proc_entry *next;
146 #define IPMI_IPMB_NUM_SEQ 64
147 #define IPMI_MAX_CHANNELS 16
150 /* What interface number are we? */
153 /* The list of upper layers that are using me. We read-lock
154 this when delivering messages to the upper layer to keep
155 the user from going away while we are processing the
156 message. This means that you cannot add or delete a user
157 from the receive callback. */
159 struct list_head users;
161 /* Used for wake ups at startup. */
162 wait_queue_head_t waitq;
164 /* The IPMI version of the BMC on the other end. */
165 unsigned char version_major;
166 unsigned char version_minor;
168 /* This is the lower-layer's sender routine. */
169 struct ipmi_smi_handlers *handlers;
172 #ifdef CONFIG_PROC_FS
173 /* A list of proc entries for this interface. This does not
174 need a lock, only one thread creates it and only one thread
176 spinlock_t proc_entry_lock;
177 struct ipmi_proc_entry *proc_entries;
180 /* A table of sequence numbers for this interface. We use the
181 sequence numbers for IPMB messages that go out of the
182 interface to match them up with their responses. A routine
183 is called periodically to time the items in this list. */
185 struct seq_table seq_table[IPMI_IPMB_NUM_SEQ];
188 /* Messages that were delayed for some reason (out of memory,
189 for instance), will go in here to be processed later in a
190 periodic timer interrupt. */
191 spinlock_t waiting_msgs_lock;
192 struct list_head waiting_msgs;
194 /* The list of command receivers that are registered for commands
195 on this interface. */
196 rwlock_t cmd_rcvr_lock;
197 struct list_head cmd_rcvrs;
199 /* Events that were queues because no one was there to receive
201 spinlock_t events_lock; /* For dealing with event stuff. */
202 struct list_head waiting_events;
203 unsigned int waiting_events_count; /* How many events in queue? */
205 /* This will be non-null if someone registers to receive all
206 IPMI commands (this is for interface emulation). There
207 may not be any things in the cmd_rcvrs list above when
208 this is registered. */
209 ipmi_user_t all_cmd_rcvr;
211 /* The event receiver for my BMC, only really used at panic
212 shutdown as a place to store this. */
213 unsigned char event_receiver;
214 unsigned char event_receiver_lun;
215 unsigned char local_sel_device;
216 unsigned char local_event_generator;
218 /* A cheap hack, if this is non-null and a message to an
219 interface comes in with a NULL user, call this routine with
220 it. Note that the message will still be freed by the
221 caller. This only works on the system interface. */
222 void (*null_user_handler)(ipmi_smi_t intf, struct ipmi_smi_msg *msg);
224 /* When we are scanning the channels for an SMI, this will
225 tell which channel we are scanning. */
228 /* Channel information */
229 struct ipmi_channel channels[IPMI_MAX_CHANNELS];
232 struct proc_dir_entry *proc_dir;
233 char proc_dir_name[10];
235 spinlock_t counter_lock; /* For making counters atomic. */
237 /* Commands we got that were invalid. */
238 unsigned int sent_invalid_commands;
240 /* Commands we sent to the MC. */
241 unsigned int sent_local_commands;
242 /* Responses from the MC that were delivered to a user. */
243 unsigned int handled_local_responses;
244 /* Responses from the MC that were not delivered to a user. */
245 unsigned int unhandled_local_responses;
247 /* Commands we sent out to the IPMB bus. */
248 unsigned int sent_ipmb_commands;
249 /* Commands sent on the IPMB that had errors on the SEND CMD */
250 unsigned int sent_ipmb_command_errs;
251 /* Each retransmit increments this count. */
252 unsigned int retransmitted_ipmb_commands;
253 /* When a message times out (runs out of retransmits) this is
255 unsigned int timed_out_ipmb_commands;
257 /* This is like above, but for broadcasts. Broadcasts are
258 *not* included in the above count (they are expected to
260 unsigned int timed_out_ipmb_broadcasts;
262 /* Responses I have sent to the IPMB bus. */
263 unsigned int sent_ipmb_responses;
265 /* The response was delivered to the user. */
266 unsigned int handled_ipmb_responses;
267 /* The response had invalid data in it. */
268 unsigned int invalid_ipmb_responses;
269 /* The response didn't have anyone waiting for it. */
270 unsigned int unhandled_ipmb_responses;
272 /* Commands we sent out to the IPMB bus. */
273 unsigned int sent_lan_commands;
274 /* Commands sent on the IPMB that had errors on the SEND CMD */
275 unsigned int sent_lan_command_errs;
276 /* Each retransmit increments this count. */
277 unsigned int retransmitted_lan_commands;
278 /* When a message times out (runs out of retransmits) this is
280 unsigned int timed_out_lan_commands;
282 /* Responses I have sent to the IPMB bus. */
283 unsigned int sent_lan_responses;
285 /* The response was delivered to the user. */
286 unsigned int handled_lan_responses;
287 /* The response had invalid data in it. */
288 unsigned int invalid_lan_responses;
289 /* The response didn't have anyone waiting for it. */
290 unsigned int unhandled_lan_responses;
292 /* The command was delivered to the user. */
293 unsigned int handled_commands;
294 /* The command had invalid data in it. */
295 unsigned int invalid_commands;
296 /* The command didn't have anyone waiting for it. */
297 unsigned int unhandled_commands;
299 /* Invalid data in an event. */
300 unsigned int invalid_events;
301 /* Events that were received with the proper format. */
305 #define MAX_IPMI_INTERFACES 4
306 static ipmi_smi_t ipmi_interfaces[MAX_IPMI_INTERFACES];
308 /* Used to keep interfaces from going away while operations are
309 operating on interfaces. Grab read if you are not modifying the
310 interfaces, write if you are. */
311 static DECLARE_RWSEM(interfaces_sem);
313 /* Directly protects the ipmi_interfaces data structure. This is
314 claimed in the timer interrupt. */
315 static DEFINE_SPINLOCK(interfaces_lock);
317 /* List of watchers that want to know when smi's are added and
319 static struct list_head smi_watchers = LIST_HEAD_INIT(smi_watchers);
320 static DECLARE_RWSEM(smi_watchers_sem);
322 int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
326 down_read(&interfaces_sem);
327 down_write(&smi_watchers_sem);
328 list_add(&(watcher->link), &smi_watchers);
329 for (i=0; i<MAX_IPMI_INTERFACES; i++) {
330 if (ipmi_interfaces[i] != NULL) {
334 up_write(&smi_watchers_sem);
335 up_read(&interfaces_sem);
339 int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher)
341 down_write(&smi_watchers_sem);
342 list_del(&(watcher->link));
343 up_write(&smi_watchers_sem);
348 call_smi_watchers(int i)
350 struct ipmi_smi_watcher *w;
352 down_read(&smi_watchers_sem);
353 list_for_each_entry(w, &smi_watchers, link) {
354 if (try_module_get(w->owner)) {
356 module_put(w->owner);
359 up_read(&smi_watchers_sem);
363 ipmi_addr_equal(struct ipmi_addr *addr1, struct ipmi_addr *addr2)
365 if (addr1->addr_type != addr2->addr_type)
368 if (addr1->channel != addr2->channel)
371 if (addr1->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) {
372 struct ipmi_system_interface_addr *smi_addr1
373 = (struct ipmi_system_interface_addr *) addr1;
374 struct ipmi_system_interface_addr *smi_addr2
375 = (struct ipmi_system_interface_addr *) addr2;
376 return (smi_addr1->lun == smi_addr2->lun);
379 if ((addr1->addr_type == IPMI_IPMB_ADDR_TYPE)
380 || (addr1->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE))
382 struct ipmi_ipmb_addr *ipmb_addr1
383 = (struct ipmi_ipmb_addr *) addr1;
384 struct ipmi_ipmb_addr *ipmb_addr2
385 = (struct ipmi_ipmb_addr *) addr2;
387 return ((ipmb_addr1->slave_addr == ipmb_addr2->slave_addr)
388 && (ipmb_addr1->lun == ipmb_addr2->lun));
391 if (addr1->addr_type == IPMI_LAN_ADDR_TYPE) {
392 struct ipmi_lan_addr *lan_addr1
393 = (struct ipmi_lan_addr *) addr1;
394 struct ipmi_lan_addr *lan_addr2
395 = (struct ipmi_lan_addr *) addr2;
397 return ((lan_addr1->remote_SWID == lan_addr2->remote_SWID)
398 && (lan_addr1->local_SWID == lan_addr2->local_SWID)
399 && (lan_addr1->session_handle
400 == lan_addr2->session_handle)
401 && (lan_addr1->lun == lan_addr2->lun));
407 int ipmi_validate_addr(struct ipmi_addr *addr, int len)
409 if (len < sizeof(struct ipmi_system_interface_addr)) {
413 if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) {
414 if (addr->channel != IPMI_BMC_CHANNEL)
419 if ((addr->channel == IPMI_BMC_CHANNEL)
420 || (addr->channel >= IPMI_NUM_CHANNELS)
421 || (addr->channel < 0))
424 if ((addr->addr_type == IPMI_IPMB_ADDR_TYPE)
425 || (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE))
427 if (len < sizeof(struct ipmi_ipmb_addr)) {
433 if (addr->addr_type == IPMI_LAN_ADDR_TYPE) {
434 if (len < sizeof(struct ipmi_lan_addr)) {
443 unsigned int ipmi_addr_length(int addr_type)
445 if (addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
446 return sizeof(struct ipmi_system_interface_addr);
448 if ((addr_type == IPMI_IPMB_ADDR_TYPE)
449 || (addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE))
451 return sizeof(struct ipmi_ipmb_addr);
454 if (addr_type == IPMI_LAN_ADDR_TYPE)
455 return sizeof(struct ipmi_lan_addr);
460 static void deliver_response(struct ipmi_recv_msg *msg)
462 msg->user->handler->ipmi_recv_hndl(msg, msg->user->handler_data);
465 /* Find the next sequence number not being used and add the given
466 message with the given timeout to the sequence table. This must be
467 called with the interface's seq_lock held. */
468 static int intf_next_seq(ipmi_smi_t intf,
469 struct ipmi_recv_msg *recv_msg,
470 unsigned long timeout,
479 for (i=intf->curr_seq;
480 (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq;
481 i=(i+1)%IPMI_IPMB_NUM_SEQ)
483 if (! intf->seq_table[i].inuse)
487 if (! intf->seq_table[i].inuse) {
488 intf->seq_table[i].recv_msg = recv_msg;
490 /* Start with the maximum timeout, when the send response
491 comes in we will start the real timer. */
492 intf->seq_table[i].timeout = MAX_MSG_TIMEOUT;
493 intf->seq_table[i].orig_timeout = timeout;
494 intf->seq_table[i].retries_left = retries;
495 intf->seq_table[i].broadcast = broadcast;
496 intf->seq_table[i].inuse = 1;
497 intf->seq_table[i].seqid = NEXT_SEQID(intf->seq_table[i].seqid);
499 *seqid = intf->seq_table[i].seqid;
500 intf->curr_seq = (i+1)%IPMI_IPMB_NUM_SEQ;
508 /* Return the receive message for the given sequence number and
509 release the sequence number so it can be reused. Some other data
510 is passed in to be sure the message matches up correctly (to help
511 guard against message coming in after their timeout and the
512 sequence number being reused). */
513 static int intf_find_seq(ipmi_smi_t intf,
518 struct ipmi_addr *addr,
519 struct ipmi_recv_msg **recv_msg)
524 if (seq >= IPMI_IPMB_NUM_SEQ)
527 spin_lock_irqsave(&(intf->seq_lock), flags);
528 if (intf->seq_table[seq].inuse) {
529 struct ipmi_recv_msg *msg = intf->seq_table[seq].recv_msg;
531 if ((msg->addr.channel == channel)
532 && (msg->msg.cmd == cmd)
533 && (msg->msg.netfn == netfn)
534 && (ipmi_addr_equal(addr, &(msg->addr))))
537 intf->seq_table[seq].inuse = 0;
541 spin_unlock_irqrestore(&(intf->seq_lock), flags);
547 /* Start the timer for a specific sequence table entry. */
548 static int intf_start_seq_timer(ipmi_smi_t intf,
557 GET_SEQ_FROM_MSGID(msgid, seq, seqid);
559 spin_lock_irqsave(&(intf->seq_lock), flags);
560 /* We do this verification because the user can be deleted
561 while a message is outstanding. */
562 if ((intf->seq_table[seq].inuse)
563 && (intf->seq_table[seq].seqid == seqid))
565 struct seq_table *ent = &(intf->seq_table[seq]);
566 ent->timeout = ent->orig_timeout;
569 spin_unlock_irqrestore(&(intf->seq_lock), flags);
574 /* Got an error for the send message for a specific sequence number. */
575 static int intf_err_seq(ipmi_smi_t intf,
583 struct ipmi_recv_msg *msg = NULL;
586 GET_SEQ_FROM_MSGID(msgid, seq, seqid);
588 spin_lock_irqsave(&(intf->seq_lock), flags);
589 /* We do this verification because the user can be deleted
590 while a message is outstanding. */
591 if ((intf->seq_table[seq].inuse)
592 && (intf->seq_table[seq].seqid == seqid))
594 struct seq_table *ent = &(intf->seq_table[seq]);
600 spin_unlock_irqrestore(&(intf->seq_lock), flags);
603 msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
604 msg->msg_data[0] = err;
605 msg->msg.netfn |= 1; /* Convert to a response. */
606 msg->msg.data_len = 1;
607 msg->msg.data = msg->msg_data;
608 deliver_response(msg);
615 int ipmi_create_user(unsigned int if_num,
616 struct ipmi_user_hndl *handler,
621 ipmi_user_t new_user;
625 /* There is no module usecount here, because it's not
626 required. Since this can only be used by and called from
627 other modules, they will implicitly use this module, and
628 thus this can't be removed unless the other modules are
634 /* Make sure the driver is actually initialized, this handles
635 problems with initialization order. */
637 rv = ipmi_init_msghandler();
641 /* The init code doesn't return an error if it was turned
642 off, but it won't initialize. Check that. */
647 new_user = kmalloc(sizeof(*new_user), GFP_KERNEL);
651 down_read(&interfaces_sem);
652 if ((if_num >= MAX_IPMI_INTERFACES) || ipmi_interfaces[if_num] == NULL)
658 intf = ipmi_interfaces[if_num];
660 new_user->handler = handler;
661 new_user->handler_data = handler_data;
662 new_user->intf = intf;
663 new_user->gets_events = 0;
665 if (!try_module_get(intf->handlers->owner)) {
670 if (intf->handlers->inc_usecount) {
671 rv = intf->handlers->inc_usecount(intf->send_info);
673 module_put(intf->handlers->owner);
678 write_lock_irqsave(&intf->users_lock, flags);
679 list_add_tail(&new_user->link, &intf->users);
680 write_unlock_irqrestore(&intf->users_lock, flags);
689 up_read(&interfaces_sem);
693 static int ipmi_destroy_user_nolock(ipmi_user_t user)
697 struct cmd_rcvr *rcvr, *rcvr2;
701 /* Find the user and delete them from the list. */
702 list_for_each_entry(t_user, &(user->intf->users), link) {
703 if (t_user == user) {
704 list_del(&t_user->link);
714 /* Remove the user from the interfaces sequence table. */
715 spin_lock_irqsave(&(user->intf->seq_lock), flags);
716 for (i=0; i<IPMI_IPMB_NUM_SEQ; i++) {
717 if (user->intf->seq_table[i].inuse
718 && (user->intf->seq_table[i].recv_msg->user == user))
720 user->intf->seq_table[i].inuse = 0;
723 spin_unlock_irqrestore(&(user->intf->seq_lock), flags);
725 /* Remove the user from the command receiver's table. */
726 write_lock_irqsave(&(user->intf->cmd_rcvr_lock), flags);
727 list_for_each_entry_safe(rcvr, rcvr2, &(user->intf->cmd_rcvrs), link) {
728 if (rcvr->user == user) {
729 list_del(&rcvr->link);
733 write_unlock_irqrestore(&(user->intf->cmd_rcvr_lock), flags);
742 int ipmi_destroy_user(ipmi_user_t user)
745 ipmi_smi_t intf = user->intf;
748 down_read(&interfaces_sem);
749 write_lock_irqsave(&intf->users_lock, flags);
750 rv = ipmi_destroy_user_nolock(user);
752 module_put(intf->handlers->owner);
753 if (intf->handlers->dec_usecount)
754 intf->handlers->dec_usecount(intf->send_info);
757 write_unlock_irqrestore(&intf->users_lock, flags);
758 up_read(&interfaces_sem);
762 void ipmi_get_version(ipmi_user_t user,
763 unsigned char *major,
764 unsigned char *minor)
766 *major = user->intf->version_major;
767 *minor = user->intf->version_minor;
770 int ipmi_set_my_address(ipmi_user_t user,
771 unsigned int channel,
772 unsigned char address)
774 if (channel >= IPMI_MAX_CHANNELS)
776 user->intf->channels[channel].address = address;
780 int ipmi_get_my_address(ipmi_user_t user,
781 unsigned int channel,
782 unsigned char *address)
784 if (channel >= IPMI_MAX_CHANNELS)
786 *address = user->intf->channels[channel].address;
790 int ipmi_set_my_LUN(ipmi_user_t user,
791 unsigned int channel,
794 if (channel >= IPMI_MAX_CHANNELS)
796 user->intf->channels[channel].lun = LUN & 0x3;
800 int ipmi_get_my_LUN(ipmi_user_t user,
801 unsigned int channel,
802 unsigned char *address)
804 if (channel >= IPMI_MAX_CHANNELS)
806 *address = user->intf->channels[channel].lun;
810 int ipmi_set_gets_events(ipmi_user_t user, int val)
813 struct ipmi_recv_msg *msg, *msg2;
815 read_lock(&(user->intf->users_lock));
816 spin_lock_irqsave(&(user->intf->events_lock), flags);
817 user->gets_events = val;
820 /* Deliver any queued events. */
821 list_for_each_entry_safe(msg, msg2, &(user->intf->waiting_events), link) {
822 list_del(&msg->link);
824 deliver_response(msg);
828 spin_unlock_irqrestore(&(user->intf->events_lock), flags);
829 read_unlock(&(user->intf->users_lock));
834 int ipmi_register_for_cmd(ipmi_user_t user,
838 struct cmd_rcvr *cmp;
840 struct cmd_rcvr *rcvr;
844 rcvr = kmalloc(sizeof(*rcvr), GFP_KERNEL);
848 read_lock(&(user->intf->users_lock));
849 write_lock_irqsave(&(user->intf->cmd_rcvr_lock), flags);
850 if (user->intf->all_cmd_rcvr != NULL) {
855 /* Make sure the command/netfn is not already registered. */
856 list_for_each_entry(cmp, &(user->intf->cmd_rcvrs), link) {
857 if ((cmp->netfn == netfn) && (cmp->cmd == cmd)) {
867 list_add_tail(&(rcvr->link), &(user->intf->cmd_rcvrs));
870 write_unlock_irqrestore(&(user->intf->cmd_rcvr_lock), flags);
871 read_unlock(&(user->intf->users_lock));
879 int ipmi_unregister_for_cmd(ipmi_user_t user,
884 struct cmd_rcvr *rcvr;
887 read_lock(&(user->intf->users_lock));
888 write_lock_irqsave(&(user->intf->cmd_rcvr_lock), flags);
889 /* Make sure the command/netfn is not already registered. */
890 list_for_each_entry(rcvr, &(user->intf->cmd_rcvrs), link) {
891 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
893 list_del(&rcvr->link);
898 write_unlock_irqrestore(&(user->intf->cmd_rcvr_lock), flags);
899 read_unlock(&(user->intf->users_lock));
904 void ipmi_user_set_run_to_completion(ipmi_user_t user, int val)
906 user->intf->handlers->set_run_to_completion(user->intf->send_info,
911 ipmb_checksum(unsigned char *data, int size)
913 unsigned char csum = 0;
915 for (; size > 0; size--, data++)
921 static inline void format_ipmb_msg(struct ipmi_smi_msg *smi_msg,
922 struct kernel_ipmi_msg *msg,
923 struct ipmi_ipmb_addr *ipmb_addr,
925 unsigned char ipmb_seq,
927 unsigned char source_address,
928 unsigned char source_lun)
932 /* Format the IPMB header data. */
933 smi_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
934 smi_msg->data[1] = IPMI_SEND_MSG_CMD;
935 smi_msg->data[2] = ipmb_addr->channel;
937 smi_msg->data[3] = 0;
938 smi_msg->data[i+3] = ipmb_addr->slave_addr;
939 smi_msg->data[i+4] = (msg->netfn << 2) | (ipmb_addr->lun & 0x3);
940 smi_msg->data[i+5] = ipmb_checksum(&(smi_msg->data[i+3]), 2);
941 smi_msg->data[i+6] = source_address;
942 smi_msg->data[i+7] = (ipmb_seq << 2) | source_lun;
943 smi_msg->data[i+8] = msg->cmd;
945 /* Now tack on the data to the message. */
946 if (msg->data_len > 0)
947 memcpy(&(smi_msg->data[i+9]), msg->data,
949 smi_msg->data_size = msg->data_len + 9;
951 /* Now calculate the checksum and tack it on. */
952 smi_msg->data[i+smi_msg->data_size]
953 = ipmb_checksum(&(smi_msg->data[i+6]),
954 smi_msg->data_size-6);
956 /* Add on the checksum size and the offset from the
958 smi_msg->data_size += 1 + i;
960 smi_msg->msgid = msgid;
963 static inline void format_lan_msg(struct ipmi_smi_msg *smi_msg,
964 struct kernel_ipmi_msg *msg,
965 struct ipmi_lan_addr *lan_addr,
967 unsigned char ipmb_seq,
968 unsigned char source_lun)
970 /* Format the IPMB header data. */
971 smi_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
972 smi_msg->data[1] = IPMI_SEND_MSG_CMD;
973 smi_msg->data[2] = lan_addr->channel;
974 smi_msg->data[3] = lan_addr->session_handle;
975 smi_msg->data[4] = lan_addr->remote_SWID;
976 smi_msg->data[5] = (msg->netfn << 2) | (lan_addr->lun & 0x3);
977 smi_msg->data[6] = ipmb_checksum(&(smi_msg->data[4]), 2);
978 smi_msg->data[7] = lan_addr->local_SWID;
979 smi_msg->data[8] = (ipmb_seq << 2) | source_lun;
980 smi_msg->data[9] = msg->cmd;
982 /* Now tack on the data to the message. */
983 if (msg->data_len > 0)
984 memcpy(&(smi_msg->data[10]), msg->data,
986 smi_msg->data_size = msg->data_len + 10;
988 /* Now calculate the checksum and tack it on. */
989 smi_msg->data[smi_msg->data_size]
990 = ipmb_checksum(&(smi_msg->data[7]),
991 smi_msg->data_size-7);
993 /* Add on the checksum size and the offset from the
995 smi_msg->data_size += 1;
997 smi_msg->msgid = msgid;
1000 /* Separate from ipmi_request so that the user does not have to be
1001 supplied in certain circumstances (mainly at panic time). If
1002 messages are supplied, they will be freed, even if an error
1004 static inline int i_ipmi_request(ipmi_user_t user,
1006 struct ipmi_addr *addr,
1008 struct kernel_ipmi_msg *msg,
1009 void *user_msg_data,
1011 struct ipmi_recv_msg *supplied_recv,
1013 unsigned char source_address,
1014 unsigned char source_lun,
1016 unsigned int retry_time_ms)
1019 struct ipmi_smi_msg *smi_msg;
1020 struct ipmi_recv_msg *recv_msg;
1021 unsigned long flags;
1024 if (supplied_recv) {
1025 recv_msg = supplied_recv;
1027 recv_msg = ipmi_alloc_recv_msg();
1028 if (recv_msg == NULL) {
1032 recv_msg->user_msg_data = user_msg_data;
1035 smi_msg = (struct ipmi_smi_msg *) supplied_smi;
1037 smi_msg = ipmi_alloc_smi_msg();
1038 if (smi_msg == NULL) {
1039 ipmi_free_recv_msg(recv_msg);
1044 recv_msg->user = user;
1045 recv_msg->msgid = msgid;
1046 /* Store the message to send in the receive message so timeout
1047 responses can get the proper response data. */
1048 recv_msg->msg = *msg;
1050 if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) {
1051 struct ipmi_system_interface_addr *smi_addr;
1053 if (msg->netfn & 1) {
1054 /* Responses are not allowed to the SMI. */
1059 smi_addr = (struct ipmi_system_interface_addr *) addr;
1060 if (smi_addr->lun > 3) {
1061 spin_lock_irqsave(&intf->counter_lock, flags);
1062 intf->sent_invalid_commands++;
1063 spin_unlock_irqrestore(&intf->counter_lock, flags);
1068 memcpy(&recv_msg->addr, smi_addr, sizeof(*smi_addr));
1070 if ((msg->netfn == IPMI_NETFN_APP_REQUEST)
1071 && ((msg->cmd == IPMI_SEND_MSG_CMD)
1072 || (msg->cmd == IPMI_GET_MSG_CMD)
1073 || (msg->cmd == IPMI_READ_EVENT_MSG_BUFFER_CMD)))
1075 /* We don't let the user do these, since we manage
1076 the sequence numbers. */
1077 spin_lock_irqsave(&intf->counter_lock, flags);
1078 intf->sent_invalid_commands++;
1079 spin_unlock_irqrestore(&intf->counter_lock, flags);
1084 if ((msg->data_len + 2) > IPMI_MAX_MSG_LENGTH) {
1085 spin_lock_irqsave(&intf->counter_lock, flags);
1086 intf->sent_invalid_commands++;
1087 spin_unlock_irqrestore(&intf->counter_lock, flags);
1092 smi_msg->data[0] = (msg->netfn << 2) | (smi_addr->lun & 0x3);
1093 smi_msg->data[1] = msg->cmd;
1094 smi_msg->msgid = msgid;
1095 smi_msg->user_data = recv_msg;
1096 if (msg->data_len > 0)
1097 memcpy(&(smi_msg->data[2]), msg->data, msg->data_len);
1098 smi_msg->data_size = msg->data_len + 2;
1099 spin_lock_irqsave(&intf->counter_lock, flags);
1100 intf->sent_local_commands++;
1101 spin_unlock_irqrestore(&intf->counter_lock, flags);
1102 } else if ((addr->addr_type == IPMI_IPMB_ADDR_TYPE)
1103 || (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE))
1105 struct ipmi_ipmb_addr *ipmb_addr;
1106 unsigned char ipmb_seq;
1110 if (addr->channel >= IPMI_MAX_CHANNELS) {
1111 spin_lock_irqsave(&intf->counter_lock, flags);
1112 intf->sent_invalid_commands++;
1113 spin_unlock_irqrestore(&intf->counter_lock, flags);
1118 if (intf->channels[addr->channel].medium
1119 != IPMI_CHANNEL_MEDIUM_IPMB)
1121 spin_lock_irqsave(&intf->counter_lock, flags);
1122 intf->sent_invalid_commands++;
1123 spin_unlock_irqrestore(&intf->counter_lock, flags);
1129 if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE)
1130 retries = 0; /* Don't retry broadcasts. */
1134 if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE) {
1135 /* Broadcasts add a zero at the beginning of the
1136 message, but otherwise is the same as an IPMB
1138 addr->addr_type = IPMI_IPMB_ADDR_TYPE;
1143 /* Default to 1 second retries. */
1144 if (retry_time_ms == 0)
1145 retry_time_ms = 1000;
1147 /* 9 for the header and 1 for the checksum, plus
1148 possibly one for the broadcast. */
1149 if ((msg->data_len + 10 + broadcast) > IPMI_MAX_MSG_LENGTH) {
1150 spin_lock_irqsave(&intf->counter_lock, flags);
1151 intf->sent_invalid_commands++;
1152 spin_unlock_irqrestore(&intf->counter_lock, flags);
1157 ipmb_addr = (struct ipmi_ipmb_addr *) addr;
1158 if (ipmb_addr->lun > 3) {
1159 spin_lock_irqsave(&intf->counter_lock, flags);
1160 intf->sent_invalid_commands++;
1161 spin_unlock_irqrestore(&intf->counter_lock, flags);
1166 memcpy(&recv_msg->addr, ipmb_addr, sizeof(*ipmb_addr));
1168 if (recv_msg->msg.netfn & 0x1) {
1169 /* It's a response, so use the user's sequence
1171 spin_lock_irqsave(&intf->counter_lock, flags);
1172 intf->sent_ipmb_responses++;
1173 spin_unlock_irqrestore(&intf->counter_lock, flags);
1174 format_ipmb_msg(smi_msg, msg, ipmb_addr, msgid,
1176 source_address, source_lun);
1178 /* Save the receive message so we can use it
1179 to deliver the response. */
1180 smi_msg->user_data = recv_msg;
1182 /* It's a command, so get a sequence for it. */
1184 spin_lock_irqsave(&(intf->seq_lock), flags);
1186 spin_lock(&intf->counter_lock);
1187 intf->sent_ipmb_commands++;
1188 spin_unlock(&intf->counter_lock);
1190 /* Create a sequence number with a 1 second
1191 timeout and 4 retries. */
1192 rv = intf_next_seq(intf,
1200 /* We have used up all the sequence numbers,
1201 probably, so abort. */
1202 spin_unlock_irqrestore(&(intf->seq_lock),
1207 /* Store the sequence number in the message,
1208 so that when the send message response
1209 comes back we can start the timer. */
1210 format_ipmb_msg(smi_msg, msg, ipmb_addr,
1211 STORE_SEQ_IN_MSGID(ipmb_seq, seqid),
1212 ipmb_seq, broadcast,
1213 source_address, source_lun);
1215 /* Copy the message into the recv message data, so we
1216 can retransmit it later if necessary. */
1217 memcpy(recv_msg->msg_data, smi_msg->data,
1218 smi_msg->data_size);
1219 recv_msg->msg.data = recv_msg->msg_data;
1220 recv_msg->msg.data_len = smi_msg->data_size;
1222 /* We don't unlock until here, because we need
1223 to copy the completed message into the
1224 recv_msg before we release the lock.
1225 Otherwise, race conditions may bite us. I
1226 know that's pretty paranoid, but I prefer
1228 spin_unlock_irqrestore(&(intf->seq_lock), flags);
1230 } else if (addr->addr_type == IPMI_LAN_ADDR_TYPE) {
1231 struct ipmi_lan_addr *lan_addr;
1232 unsigned char ipmb_seq;
1235 if (addr->channel >= IPMI_NUM_CHANNELS) {
1236 spin_lock_irqsave(&intf->counter_lock, flags);
1237 intf->sent_invalid_commands++;
1238 spin_unlock_irqrestore(&intf->counter_lock, flags);
1243 if ((intf->channels[addr->channel].medium
1244 != IPMI_CHANNEL_MEDIUM_8023LAN)
1245 && (intf->channels[addr->channel].medium
1246 != IPMI_CHANNEL_MEDIUM_ASYNC))
1248 spin_lock_irqsave(&intf->counter_lock, flags);
1249 intf->sent_invalid_commands++;
1250 spin_unlock_irqrestore(&intf->counter_lock, flags);
1257 /* Default to 1 second retries. */
1258 if (retry_time_ms == 0)
1259 retry_time_ms = 1000;
1261 /* 11 for the header and 1 for the checksum. */
1262 if ((msg->data_len + 12) > IPMI_MAX_MSG_LENGTH) {
1263 spin_lock_irqsave(&intf->counter_lock, flags);
1264 intf->sent_invalid_commands++;
1265 spin_unlock_irqrestore(&intf->counter_lock, flags);
1270 lan_addr = (struct ipmi_lan_addr *) addr;
1271 if (lan_addr->lun > 3) {
1272 spin_lock_irqsave(&intf->counter_lock, flags);
1273 intf->sent_invalid_commands++;
1274 spin_unlock_irqrestore(&intf->counter_lock, flags);
1279 memcpy(&recv_msg->addr, lan_addr, sizeof(*lan_addr));
1281 if (recv_msg->msg.netfn & 0x1) {
1282 /* It's a response, so use the user's sequence
1284 spin_lock_irqsave(&intf->counter_lock, flags);
1285 intf->sent_lan_responses++;
1286 spin_unlock_irqrestore(&intf->counter_lock, flags);
1287 format_lan_msg(smi_msg, msg, lan_addr, msgid,
1290 /* Save the receive message so we can use it
1291 to deliver the response. */
1292 smi_msg->user_data = recv_msg;
1294 /* It's a command, so get a sequence for it. */
1296 spin_lock_irqsave(&(intf->seq_lock), flags);
1298 spin_lock(&intf->counter_lock);
1299 intf->sent_lan_commands++;
1300 spin_unlock(&intf->counter_lock);
1302 /* Create a sequence number with a 1 second
1303 timeout and 4 retries. */
1304 rv = intf_next_seq(intf,
1312 /* We have used up all the sequence numbers,
1313 probably, so abort. */
1314 spin_unlock_irqrestore(&(intf->seq_lock),
1319 /* Store the sequence number in the message,
1320 so that when the send message response
1321 comes back we can start the timer. */
1322 format_lan_msg(smi_msg, msg, lan_addr,
1323 STORE_SEQ_IN_MSGID(ipmb_seq, seqid),
1324 ipmb_seq, source_lun);
1326 /* Copy the message into the recv message data, so we
1327 can retransmit it later if necessary. */
1328 memcpy(recv_msg->msg_data, smi_msg->data,
1329 smi_msg->data_size);
1330 recv_msg->msg.data = recv_msg->msg_data;
1331 recv_msg->msg.data_len = smi_msg->data_size;
1333 /* We don't unlock until here, because we need
1334 to copy the completed message into the
1335 recv_msg before we release the lock.
1336 Otherwise, race conditions may bite us. I
1337 know that's pretty paranoid, but I prefer
1339 spin_unlock_irqrestore(&(intf->seq_lock), flags);
1342 /* Unknown address type. */
1343 spin_lock_irqsave(&intf->counter_lock, flags);
1344 intf->sent_invalid_commands++;
1345 spin_unlock_irqrestore(&intf->counter_lock, flags);
1353 for (m=0; m<smi_msg->data_size; m++)
1354 printk(" %2.2x", smi_msg->data[m]);
1358 intf->handlers->sender(intf->send_info, smi_msg, priority);
1363 ipmi_free_smi_msg(smi_msg);
1364 ipmi_free_recv_msg(recv_msg);
1368 static int check_addr(ipmi_smi_t intf,
1369 struct ipmi_addr *addr,
1370 unsigned char *saddr,
1373 if (addr->channel >= IPMI_MAX_CHANNELS)
1375 *lun = intf->channels[addr->channel].lun;
1376 *saddr = intf->channels[addr->channel].address;
1380 int ipmi_request_settime(ipmi_user_t user,
1381 struct ipmi_addr *addr,
1383 struct kernel_ipmi_msg *msg,
1384 void *user_msg_data,
1387 unsigned int retry_time_ms)
1389 unsigned char saddr, lun;
1392 rv = check_addr(user->intf, addr, &saddr, &lun);
1395 return i_ipmi_request(user,
1409 int ipmi_request_supply_msgs(ipmi_user_t user,
1410 struct ipmi_addr *addr,
1412 struct kernel_ipmi_msg *msg,
1413 void *user_msg_data,
1415 struct ipmi_recv_msg *supplied_recv,
1418 unsigned char saddr, lun;
1421 rv = check_addr(user->intf, addr, &saddr, &lun);
1424 return i_ipmi_request(user,
1438 static int ipmb_file_read_proc(char *page, char **start, off_t off,
1439 int count, int *eof, void *data)
1441 char *out = (char *) page;
1442 ipmi_smi_t intf = data;
1446 for (i=0; i<IPMI_MAX_CHANNELS; i++)
1447 rv += sprintf(out+rv, "%x ", intf->channels[i].address);
1448 out[rv-1] = '\n'; /* Replace the final space with a newline */
1454 static int version_file_read_proc(char *page, char **start, off_t off,
1455 int count, int *eof, void *data)
1457 char *out = (char *) page;
1458 ipmi_smi_t intf = data;
1460 return sprintf(out, "%d.%d\n",
1461 intf->version_major, intf->version_minor);
1464 static int stat_file_read_proc(char *page, char **start, off_t off,
1465 int count, int *eof, void *data)
1467 char *out = (char *) page;
1468 ipmi_smi_t intf = data;
1470 out += sprintf(out, "sent_invalid_commands: %d\n",
1471 intf->sent_invalid_commands);
1472 out += sprintf(out, "sent_local_commands: %d\n",
1473 intf->sent_local_commands);
1474 out += sprintf(out, "handled_local_responses: %d\n",
1475 intf->handled_local_responses);
1476 out += sprintf(out, "unhandled_local_responses: %d\n",
1477 intf->unhandled_local_responses);
1478 out += sprintf(out, "sent_ipmb_commands: %d\n",
1479 intf->sent_ipmb_commands);
1480 out += sprintf(out, "sent_ipmb_command_errs: %d\n",
1481 intf->sent_ipmb_command_errs);
1482 out += sprintf(out, "retransmitted_ipmb_commands: %d\n",
1483 intf->retransmitted_ipmb_commands);
1484 out += sprintf(out, "timed_out_ipmb_commands: %d\n",
1485 intf->timed_out_ipmb_commands);
1486 out += sprintf(out, "timed_out_ipmb_broadcasts: %d\n",
1487 intf->timed_out_ipmb_broadcasts);
1488 out += sprintf(out, "sent_ipmb_responses: %d\n",
1489 intf->sent_ipmb_responses);
1490 out += sprintf(out, "handled_ipmb_responses: %d\n",
1491 intf->handled_ipmb_responses);
1492 out += sprintf(out, "invalid_ipmb_responses: %d\n",
1493 intf->invalid_ipmb_responses);
1494 out += sprintf(out, "unhandled_ipmb_responses: %d\n",
1495 intf->unhandled_ipmb_responses);
1496 out += sprintf(out, "sent_lan_commands: %d\n",
1497 intf->sent_lan_commands);
1498 out += sprintf(out, "sent_lan_command_errs: %d\n",
1499 intf->sent_lan_command_errs);
1500 out += sprintf(out, "retransmitted_lan_commands: %d\n",
1501 intf->retransmitted_lan_commands);
1502 out += sprintf(out, "timed_out_lan_commands: %d\n",
1503 intf->timed_out_lan_commands);
1504 out += sprintf(out, "sent_lan_responses: %d\n",
1505 intf->sent_lan_responses);
1506 out += sprintf(out, "handled_lan_responses: %d\n",
1507 intf->handled_lan_responses);
1508 out += sprintf(out, "invalid_lan_responses: %d\n",
1509 intf->invalid_lan_responses);
1510 out += sprintf(out, "unhandled_lan_responses: %d\n",
1511 intf->unhandled_lan_responses);
1512 out += sprintf(out, "handled_commands: %d\n",
1513 intf->handled_commands);
1514 out += sprintf(out, "invalid_commands: %d\n",
1515 intf->invalid_commands);
1516 out += sprintf(out, "unhandled_commands: %d\n",
1517 intf->unhandled_commands);
1518 out += sprintf(out, "invalid_events: %d\n",
1519 intf->invalid_events);
1520 out += sprintf(out, "events: %d\n",
1523 return (out - ((char *) page));
1526 int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
1527 read_proc_t *read_proc, write_proc_t *write_proc,
1528 void *data, struct module *owner)
1531 #ifdef CONFIG_PROC_FS
1532 struct proc_dir_entry *file;
1533 struct ipmi_proc_entry *entry;
1535 /* Create a list element. */
1536 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
1539 entry->name = kmalloc(strlen(name)+1, GFP_KERNEL);
1544 strcpy(entry->name, name);
1546 file = create_proc_entry(name, 0, smi->proc_dir);
1554 file->read_proc = read_proc;
1555 file->write_proc = write_proc;
1556 file->owner = owner;
1558 spin_lock(&smi->proc_entry_lock);
1559 /* Stick it on the list. */
1560 entry->next = smi->proc_entries;
1561 smi->proc_entries = entry;
1562 spin_unlock(&smi->proc_entry_lock);
1564 #endif /* CONFIG_PROC_FS */
1569 static int add_proc_entries(ipmi_smi_t smi, int num)
1573 #ifdef CONFIG_PROC_FS
1574 sprintf(smi->proc_dir_name, "%d", num);
1575 smi->proc_dir = proc_mkdir(smi->proc_dir_name, proc_ipmi_root);
1579 smi->proc_dir->owner = THIS_MODULE;
1583 rv = ipmi_smi_add_proc_entry(smi, "stats",
1584 stat_file_read_proc, NULL,
1588 rv = ipmi_smi_add_proc_entry(smi, "ipmb",
1589 ipmb_file_read_proc, NULL,
1593 rv = ipmi_smi_add_proc_entry(smi, "version",
1594 version_file_read_proc, NULL,
1596 #endif /* CONFIG_PROC_FS */
1601 static void remove_proc_entries(ipmi_smi_t smi)
1603 #ifdef CONFIG_PROC_FS
1604 struct ipmi_proc_entry *entry;
1606 spin_lock(&smi->proc_entry_lock);
1607 while (smi->proc_entries) {
1608 entry = smi->proc_entries;
1609 smi->proc_entries = entry->next;
1611 remove_proc_entry(entry->name, smi->proc_dir);
1615 spin_unlock(&smi->proc_entry_lock);
1616 remove_proc_entry(smi->proc_dir_name, proc_ipmi_root);
1617 #endif /* CONFIG_PROC_FS */
1621 send_channel_info_cmd(ipmi_smi_t intf, int chan)
1623 struct kernel_ipmi_msg msg;
1624 unsigned char data[1];
1625 struct ipmi_system_interface_addr si;
1627 si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
1628 si.channel = IPMI_BMC_CHANNEL;
1631 msg.netfn = IPMI_NETFN_APP_REQUEST;
1632 msg.cmd = IPMI_GET_CHANNEL_INFO_CMD;
1636 return i_ipmi_request(NULL,
1638 (struct ipmi_addr *) &si,
1645 intf->channels[0].address,
1646 intf->channels[0].lun,
1651 channel_handler(ipmi_smi_t intf, struct ipmi_smi_msg *msg)
1656 if ((msg->rsp[0] == (IPMI_NETFN_APP_RESPONSE << 2))
1657 && (msg->rsp[1] == IPMI_GET_CHANNEL_INFO_CMD))
1659 /* It's the one we want */
1660 if (msg->rsp[2] != 0) {
1661 /* Got an error from the channel, just go on. */
1663 if (msg->rsp[2] == IPMI_INVALID_COMMAND_ERR) {
1664 /* If the MC does not support this
1665 command, that is legal. We just
1666 assume it has one IPMB at channel
1668 intf->channels[0].medium
1669 = IPMI_CHANNEL_MEDIUM_IPMB;
1670 intf->channels[0].protocol
1671 = IPMI_CHANNEL_PROTOCOL_IPMB;
1674 intf->curr_channel = IPMI_MAX_CHANNELS;
1675 wake_up(&intf->waitq);
1680 if (msg->rsp_size < 6) {
1681 /* Message not big enough, just go on. */
1684 chan = intf->curr_channel;
1685 intf->channels[chan].medium = msg->rsp[4] & 0x7f;
1686 intf->channels[chan].protocol = msg->rsp[5] & 0x1f;
1689 intf->curr_channel++;
1690 if (intf->curr_channel >= IPMI_MAX_CHANNELS)
1691 wake_up(&intf->waitq);
1693 rv = send_channel_info_cmd(intf, intf->curr_channel);
1696 /* Got an error somehow, just give up. */
1697 intf->curr_channel = IPMI_MAX_CHANNELS;
1698 wake_up(&intf->waitq);
1700 printk(KERN_WARNING PFX
1701 "Error sending channel information: %d\n",
1709 int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1711 unsigned char version_major,
1712 unsigned char version_minor,
1713 unsigned char slave_addr,
1718 ipmi_smi_t new_intf;
1719 unsigned long flags;
1722 /* Make sure the driver is actually initialized, this handles
1723 problems with initialization order. */
1725 rv = ipmi_init_msghandler();
1728 /* The init code doesn't return an error if it was turned
1729 off, but it won't initialize. Check that. */
1734 new_intf = kmalloc(sizeof(*new_intf), GFP_KERNEL);
1737 memset(new_intf, 0, sizeof(*new_intf));
1739 new_intf->proc_dir = NULL;
1743 down_write(&interfaces_sem);
1744 for (i=0; i<MAX_IPMI_INTERFACES; i++) {
1745 if (ipmi_interfaces[i] == NULL) {
1746 new_intf->intf_num = i;
1747 new_intf->version_major = version_major;
1748 new_intf->version_minor = version_minor;
1749 for (j=0; j<IPMI_MAX_CHANNELS; j++) {
1750 new_intf->channels[j].address
1751 = IPMI_BMC_SLAVE_ADDR;
1752 new_intf->channels[j].lun = 2;
1754 if (slave_addr != 0)
1755 new_intf->channels[0].address = slave_addr;
1756 rwlock_init(&(new_intf->users_lock));
1757 INIT_LIST_HEAD(&(new_intf->users));
1758 new_intf->handlers = handlers;
1759 new_intf->send_info = send_info;
1760 spin_lock_init(&(new_intf->seq_lock));
1761 for (j=0; j<IPMI_IPMB_NUM_SEQ; j++) {
1762 new_intf->seq_table[j].inuse = 0;
1763 new_intf->seq_table[j].seqid = 0;
1765 new_intf->curr_seq = 0;
1766 #ifdef CONFIG_PROC_FS
1767 spin_lock_init(&(new_intf->proc_entry_lock));
1769 spin_lock_init(&(new_intf->waiting_msgs_lock));
1770 INIT_LIST_HEAD(&(new_intf->waiting_msgs));
1771 spin_lock_init(&(new_intf->events_lock));
1772 INIT_LIST_HEAD(&(new_intf->waiting_events));
1773 new_intf->waiting_events_count = 0;
1774 rwlock_init(&(new_intf->cmd_rcvr_lock));
1775 init_waitqueue_head(&new_intf->waitq);
1776 INIT_LIST_HEAD(&(new_intf->cmd_rcvrs));
1777 new_intf->all_cmd_rcvr = NULL;
1779 spin_lock_init(&(new_intf->counter_lock));
1781 spin_lock_irqsave(&interfaces_lock, flags);
1782 ipmi_interfaces[i] = new_intf;
1783 spin_unlock_irqrestore(&interfaces_lock, flags);
1791 downgrade_write(&interfaces_sem);
1794 rv = add_proc_entries(*intf, i);
1797 if ((version_major > 1)
1798 || ((version_major == 1) && (version_minor >= 5)))
1800 /* Start scanning the channels to see what is
1802 (*intf)->null_user_handler = channel_handler;
1803 (*intf)->curr_channel = 0;
1804 rv = send_channel_info_cmd(*intf, 0);
1808 /* Wait for the channel info to be read. */
1809 up_read(&interfaces_sem);
1810 wait_event((*intf)->waitq,
1811 ((*intf)->curr_channel>=IPMI_MAX_CHANNELS));
1812 down_read(&interfaces_sem);
1814 if (ipmi_interfaces[i] != new_intf)
1815 /* Well, it went away. Just return. */
1818 /* Assume a single IPMB channel at zero. */
1819 (*intf)->channels[0].medium = IPMI_CHANNEL_MEDIUM_IPMB;
1820 (*intf)->channels[0].protocol
1821 = IPMI_CHANNEL_PROTOCOL_IPMB;
1824 /* Call all the watcher interfaces to tell
1825 them that a new interface is available. */
1826 call_smi_watchers(i);
1830 up_read(&interfaces_sem);
1833 if (new_intf->proc_dir)
1834 remove_proc_entries(new_intf);
1841 static void free_recv_msg_list(struct list_head *q)
1843 struct ipmi_recv_msg *msg, *msg2;
1845 list_for_each_entry_safe(msg, msg2, q, link) {
1846 list_del(&msg->link);
1847 ipmi_free_recv_msg(msg);
1851 static void free_cmd_rcvr_list(struct list_head *q)
1853 struct cmd_rcvr *rcvr, *rcvr2;
1855 list_for_each_entry_safe(rcvr, rcvr2, q, link) {
1856 list_del(&rcvr->link);
1861 static void clean_up_interface_data(ipmi_smi_t intf)
1865 free_recv_msg_list(&(intf->waiting_msgs));
1866 free_recv_msg_list(&(intf->waiting_events));
1867 free_cmd_rcvr_list(&(intf->cmd_rcvrs));
1869 for (i=0; i<IPMI_IPMB_NUM_SEQ; i++) {
1870 if ((intf->seq_table[i].inuse)
1871 && (intf->seq_table[i].recv_msg))
1873 ipmi_free_recv_msg(intf->seq_table[i].recv_msg);
1878 int ipmi_unregister_smi(ipmi_smi_t intf)
1882 struct ipmi_smi_watcher *w;
1883 unsigned long flags;
1885 down_write(&interfaces_sem);
1886 if (list_empty(&(intf->users)))
1888 for (i=0; i<MAX_IPMI_INTERFACES; i++) {
1889 if (ipmi_interfaces[i] == intf) {
1890 remove_proc_entries(intf);
1891 spin_lock_irqsave(&interfaces_lock, flags);
1892 ipmi_interfaces[i] = NULL;
1893 clean_up_interface_data(intf);
1894 spin_unlock_irqrestore(&interfaces_lock,flags);
1897 goto out_call_watcher;
1903 up_write(&interfaces_sem);
1908 downgrade_write(&interfaces_sem);
1910 /* Call all the watcher interfaces to tell them that
1911 an interface is gone. */
1912 down_read(&smi_watchers_sem);
1913 list_for_each_entry(w, &smi_watchers, link) {
1916 up_read(&smi_watchers_sem);
1917 up_read(&interfaces_sem);
1921 static int handle_ipmb_get_msg_rsp(ipmi_smi_t intf,
1922 struct ipmi_smi_msg *msg)
1924 struct ipmi_ipmb_addr ipmb_addr;
1925 struct ipmi_recv_msg *recv_msg;
1926 unsigned long flags;
1929 /* This is 11, not 10, because the response must contain a
1930 * completion code. */
1931 if (msg->rsp_size < 11) {
1932 /* Message not big enough, just ignore it. */
1933 spin_lock_irqsave(&intf->counter_lock, flags);
1934 intf->invalid_ipmb_responses++;
1935 spin_unlock_irqrestore(&intf->counter_lock, flags);
1939 if (msg->rsp[2] != 0) {
1940 /* An error getting the response, just ignore it. */
1944 ipmb_addr.addr_type = IPMI_IPMB_ADDR_TYPE;
1945 ipmb_addr.slave_addr = msg->rsp[6];
1946 ipmb_addr.channel = msg->rsp[3] & 0x0f;
1947 ipmb_addr.lun = msg->rsp[7] & 3;
1949 /* It's a response from a remote entity. Look up the sequence
1950 number and handle the response. */
1951 if (intf_find_seq(intf,
1955 (msg->rsp[4] >> 2) & (~1),
1956 (struct ipmi_addr *) &(ipmb_addr),
1959 /* We were unable to find the sequence number,
1960 so just nuke the message. */
1961 spin_lock_irqsave(&intf->counter_lock, flags);
1962 intf->unhandled_ipmb_responses++;
1963 spin_unlock_irqrestore(&intf->counter_lock, flags);
1967 memcpy(recv_msg->msg_data,
1970 /* THe other fields matched, so no need to set them, except
1971 for netfn, which needs to be the response that was
1972 returned, not the request value. */
1973 recv_msg->msg.netfn = msg->rsp[4] >> 2;
1974 recv_msg->msg.data = recv_msg->msg_data;
1975 recv_msg->msg.data_len = msg->rsp_size - 10;
1976 recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
1977 spin_lock_irqsave(&intf->counter_lock, flags);
1978 intf->handled_ipmb_responses++;
1979 spin_unlock_irqrestore(&intf->counter_lock, flags);
1980 deliver_response(recv_msg);
1985 static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
1986 struct ipmi_smi_msg *msg)
1988 struct cmd_rcvr *rcvr;
1990 unsigned char netfn;
1992 ipmi_user_t user = NULL;
1993 struct ipmi_ipmb_addr *ipmb_addr;
1994 struct ipmi_recv_msg *recv_msg;
1995 unsigned long flags;
1997 if (msg->rsp_size < 10) {
1998 /* Message not big enough, just ignore it. */
1999 spin_lock_irqsave(&intf->counter_lock, flags);
2000 intf->invalid_commands++;
2001 spin_unlock_irqrestore(&intf->counter_lock, flags);
2005 if (msg->rsp[2] != 0) {
2006 /* An error getting the response, just ignore it. */
2010 netfn = msg->rsp[4] >> 2;
2013 read_lock(&(intf->cmd_rcvr_lock));
2015 if (intf->all_cmd_rcvr) {
2016 user = intf->all_cmd_rcvr;
2018 /* Find the command/netfn. */
2019 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) {
2020 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
2026 read_unlock(&(intf->cmd_rcvr_lock));
2029 /* We didn't find a user, deliver an error response. */
2030 spin_lock_irqsave(&intf->counter_lock, flags);
2031 intf->unhandled_commands++;
2032 spin_unlock_irqrestore(&intf->counter_lock, flags);
2034 msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
2035 msg->data[1] = IPMI_SEND_MSG_CMD;
2036 msg->data[2] = msg->rsp[3];
2037 msg->data[3] = msg->rsp[6];
2038 msg->data[4] = ((netfn + 1) << 2) | (msg->rsp[7] & 0x3);
2039 msg->data[5] = ipmb_checksum(&(msg->data[3]), 2);
2040 msg->data[6] = intf->channels[msg->rsp[3] & 0xf].address;
2042 msg->data[7] = (msg->rsp[7] & 0xfc) | (msg->rsp[4] & 0x3);
2043 msg->data[8] = msg->rsp[8]; /* cmd */
2044 msg->data[9] = IPMI_INVALID_CMD_COMPLETION_CODE;
2045 msg->data[10] = ipmb_checksum(&(msg->data[6]), 4);
2046 msg->data_size = 11;
2051 printk("Invalid command:");
2052 for (m=0; m<msg->data_size; m++)
2053 printk(" %2.2x", msg->data[m]);
2057 intf->handlers->sender(intf->send_info, msg, 0);
2059 rv = -1; /* We used the message, so return the value that
2060 causes it to not be freed or queued. */
2062 /* Deliver the message to the user. */
2063 spin_lock_irqsave(&intf->counter_lock, flags);
2064 intf->handled_commands++;
2065 spin_unlock_irqrestore(&intf->counter_lock, flags);
2067 recv_msg = ipmi_alloc_recv_msg();
2069 /* We couldn't allocate memory for the
2070 message, so requeue it for handling
2074 /* Extract the source address from the data. */
2075 ipmb_addr = (struct ipmi_ipmb_addr *) &recv_msg->addr;
2076 ipmb_addr->addr_type = IPMI_IPMB_ADDR_TYPE;
2077 ipmb_addr->slave_addr = msg->rsp[6];
2078 ipmb_addr->lun = msg->rsp[7] & 3;
2079 ipmb_addr->channel = msg->rsp[3] & 0xf;
2081 /* Extract the rest of the message information
2082 from the IPMB header.*/
2083 recv_msg->user = user;
2084 recv_msg->recv_type = IPMI_CMD_RECV_TYPE;
2085 recv_msg->msgid = msg->rsp[7] >> 2;
2086 recv_msg->msg.netfn = msg->rsp[4] >> 2;
2087 recv_msg->msg.cmd = msg->rsp[8];
2088 recv_msg->msg.data = recv_msg->msg_data;
2090 /* We chop off 10, not 9 bytes because the checksum
2091 at the end also needs to be removed. */
2092 recv_msg->msg.data_len = msg->rsp_size - 10;
2093 memcpy(recv_msg->msg_data,
2095 msg->rsp_size - 10);
2096 deliver_response(recv_msg);
2103 static int handle_lan_get_msg_rsp(ipmi_smi_t intf,
2104 struct ipmi_smi_msg *msg)
2106 struct ipmi_lan_addr lan_addr;
2107 struct ipmi_recv_msg *recv_msg;
2108 unsigned long flags;
2111 /* This is 13, not 12, because the response must contain a
2112 * completion code. */
2113 if (msg->rsp_size < 13) {
2114 /* Message not big enough, just ignore it. */
2115 spin_lock_irqsave(&intf->counter_lock, flags);
2116 intf->invalid_lan_responses++;
2117 spin_unlock_irqrestore(&intf->counter_lock, flags);
2121 if (msg->rsp[2] != 0) {
2122 /* An error getting the response, just ignore it. */
2126 lan_addr.addr_type = IPMI_LAN_ADDR_TYPE;
2127 lan_addr.session_handle = msg->rsp[4];
2128 lan_addr.remote_SWID = msg->rsp[8];
2129 lan_addr.local_SWID = msg->rsp[5];
2130 lan_addr.channel = msg->rsp[3] & 0x0f;
2131 lan_addr.privilege = msg->rsp[3] >> 4;
2132 lan_addr.lun = msg->rsp[9] & 3;
2134 /* It's a response from a remote entity. Look up the sequence
2135 number and handle the response. */
2136 if (intf_find_seq(intf,
2140 (msg->rsp[6] >> 2) & (~1),
2141 (struct ipmi_addr *) &(lan_addr),
2144 /* We were unable to find the sequence number,
2145 so just nuke the message. */
2146 spin_lock_irqsave(&intf->counter_lock, flags);
2147 intf->unhandled_lan_responses++;
2148 spin_unlock_irqrestore(&intf->counter_lock, flags);
2152 memcpy(recv_msg->msg_data,
2154 msg->rsp_size - 11);
2155 /* The other fields matched, so no need to set them, except
2156 for netfn, which needs to be the response that was
2157 returned, not the request value. */
2158 recv_msg->msg.netfn = msg->rsp[6] >> 2;
2159 recv_msg->msg.data = recv_msg->msg_data;
2160 recv_msg->msg.data_len = msg->rsp_size - 12;
2161 recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
2162 spin_lock_irqsave(&intf->counter_lock, flags);
2163 intf->handled_lan_responses++;
2164 spin_unlock_irqrestore(&intf->counter_lock, flags);
2165 deliver_response(recv_msg);
2170 static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2171 struct ipmi_smi_msg *msg)
2173 struct cmd_rcvr *rcvr;
2175 unsigned char netfn;
2177 ipmi_user_t user = NULL;
2178 struct ipmi_lan_addr *lan_addr;
2179 struct ipmi_recv_msg *recv_msg;
2180 unsigned long flags;
2182 if (msg->rsp_size < 12) {
2183 /* Message not big enough, just ignore it. */
2184 spin_lock_irqsave(&intf->counter_lock, flags);
2185 intf->invalid_commands++;
2186 spin_unlock_irqrestore(&intf->counter_lock, flags);
2190 if (msg->rsp[2] != 0) {
2191 /* An error getting the response, just ignore it. */
2195 netfn = msg->rsp[6] >> 2;
2198 read_lock(&(intf->cmd_rcvr_lock));
2200 if (intf->all_cmd_rcvr) {
2201 user = intf->all_cmd_rcvr;
2203 /* Find the command/netfn. */
2204 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) {
2205 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
2211 read_unlock(&(intf->cmd_rcvr_lock));
2214 /* We didn't find a user, deliver an error response. */
2215 spin_lock_irqsave(&intf->counter_lock, flags);
2216 intf->unhandled_commands++;
2217 spin_unlock_irqrestore(&intf->counter_lock, flags);
2219 rv = 0; /* Don't do anything with these messages, just
2220 allow them to be freed. */
2222 /* Deliver the message to the user. */
2223 spin_lock_irqsave(&intf->counter_lock, flags);
2224 intf->handled_commands++;
2225 spin_unlock_irqrestore(&intf->counter_lock, flags);
2227 recv_msg = ipmi_alloc_recv_msg();
2229 /* We couldn't allocate memory for the
2230 message, so requeue it for handling
2234 /* Extract the source address from the data. */
2235 lan_addr = (struct ipmi_lan_addr *) &recv_msg->addr;
2236 lan_addr->addr_type = IPMI_LAN_ADDR_TYPE;
2237 lan_addr->session_handle = msg->rsp[4];
2238 lan_addr->remote_SWID = msg->rsp[8];
2239 lan_addr->local_SWID = msg->rsp[5];
2240 lan_addr->lun = msg->rsp[9] & 3;
2241 lan_addr->channel = msg->rsp[3] & 0xf;
2242 lan_addr->privilege = msg->rsp[3] >> 4;
2244 /* Extract the rest of the message information
2245 from the IPMB header.*/
2246 recv_msg->user = user;
2247 recv_msg->recv_type = IPMI_CMD_RECV_TYPE;
2248 recv_msg->msgid = msg->rsp[9] >> 2;
2249 recv_msg->msg.netfn = msg->rsp[6] >> 2;
2250 recv_msg->msg.cmd = msg->rsp[10];
2251 recv_msg->msg.data = recv_msg->msg_data;
2253 /* We chop off 12, not 11 bytes because the checksum
2254 at the end also needs to be removed. */
2255 recv_msg->msg.data_len = msg->rsp_size - 12;
2256 memcpy(recv_msg->msg_data,
2258 msg->rsp_size - 12);
2259 deliver_response(recv_msg);
2266 static void copy_event_into_recv_msg(struct ipmi_recv_msg *recv_msg,
2267 struct ipmi_smi_msg *msg)
2269 struct ipmi_system_interface_addr *smi_addr;
2271 recv_msg->msgid = 0;
2272 smi_addr = (struct ipmi_system_interface_addr *) &(recv_msg->addr);
2273 smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
2274 smi_addr->channel = IPMI_BMC_CHANNEL;
2275 smi_addr->lun = msg->rsp[0] & 3;
2276 recv_msg->recv_type = IPMI_ASYNC_EVENT_RECV_TYPE;
2277 recv_msg->msg.netfn = msg->rsp[0] >> 2;
2278 recv_msg->msg.cmd = msg->rsp[1];
2279 memcpy(recv_msg->msg_data, &(msg->rsp[3]), msg->rsp_size - 3);
2280 recv_msg->msg.data = recv_msg->msg_data;
2281 recv_msg->msg.data_len = msg->rsp_size - 3;
2284 /* This will be called with the intf->users_lock read-locked, so no need
2286 static int handle_read_event_rsp(ipmi_smi_t intf,
2287 struct ipmi_smi_msg *msg)
2289 struct ipmi_recv_msg *recv_msg, *recv_msg2;
2290 struct list_head msgs;
2293 int deliver_count = 0;
2294 unsigned long flags;
2296 if (msg->rsp_size < 19) {
2297 /* Message is too small to be an IPMB event. */
2298 spin_lock_irqsave(&intf->counter_lock, flags);
2299 intf->invalid_events++;
2300 spin_unlock_irqrestore(&intf->counter_lock, flags);
2304 if (msg->rsp[2] != 0) {
2305 /* An error getting the event, just ignore it. */
2309 INIT_LIST_HEAD(&msgs);
2311 spin_lock_irqsave(&(intf->events_lock), flags);
2313 spin_lock(&intf->counter_lock);
2315 spin_unlock(&intf->counter_lock);
2317 /* Allocate and fill in one message for every user that is getting
2319 list_for_each_entry(user, &(intf->users), link) {
2320 if (! user->gets_events)
2323 recv_msg = ipmi_alloc_recv_msg();
2325 list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, link) {
2326 list_del(&recv_msg->link);
2327 ipmi_free_recv_msg(recv_msg);
2329 /* We couldn't allocate memory for the
2330 message, so requeue it for handling
2338 copy_event_into_recv_msg(recv_msg, msg);
2339 recv_msg->user = user;
2340 list_add_tail(&(recv_msg->link), &msgs);
2343 if (deliver_count) {
2344 /* Now deliver all the messages. */
2345 list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, link) {
2346 list_del(&recv_msg->link);
2347 deliver_response(recv_msg);
2349 } else if (intf->waiting_events_count < MAX_EVENTS_IN_QUEUE) {
2350 /* No one to receive the message, put it in queue if there's
2351 not already too many things in the queue. */
2352 recv_msg = ipmi_alloc_recv_msg();
2354 /* We couldn't allocate memory for the
2355 message, so requeue it for handling
2361 copy_event_into_recv_msg(recv_msg, msg);
2362 list_add_tail(&(recv_msg->link), &(intf->waiting_events));
2364 /* There's too many things in the queue, discard this
2366 printk(KERN_WARNING PFX "Event queue full, discarding an"
2367 " incoming event\n");
2371 spin_unlock_irqrestore(&(intf->events_lock), flags);
2376 static int handle_bmc_rsp(ipmi_smi_t intf,
2377 struct ipmi_smi_msg *msg)
2379 struct ipmi_recv_msg *recv_msg;
2381 struct ipmi_user *user;
2382 unsigned long flags;
2384 recv_msg = (struct ipmi_recv_msg *) msg->user_data;
2386 /* Make sure the user still exists. */
2387 list_for_each_entry(user, &(intf->users), link) {
2388 if (user == recv_msg->user) {
2389 /* Found it, so we can deliver it */
2396 /* Special handling for NULL users. */
2397 if (!recv_msg->user && intf->null_user_handler){
2398 intf->null_user_handler(intf, msg);
2399 spin_lock_irqsave(&intf->counter_lock, flags);
2400 intf->handled_local_responses++;
2401 spin_unlock_irqrestore(&intf->counter_lock, flags);
2403 /* The user for the message went away, so give up. */
2404 spin_lock_irqsave(&intf->counter_lock, flags);
2405 intf->unhandled_local_responses++;
2406 spin_unlock_irqrestore(&intf->counter_lock, flags);
2408 ipmi_free_recv_msg(recv_msg);
2410 struct ipmi_system_interface_addr *smi_addr;
2412 spin_lock_irqsave(&intf->counter_lock, flags);
2413 intf->handled_local_responses++;
2414 spin_unlock_irqrestore(&intf->counter_lock, flags);
2415 recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
2416 recv_msg->msgid = msg->msgid;
2417 smi_addr = ((struct ipmi_system_interface_addr *)
2419 smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
2420 smi_addr->channel = IPMI_BMC_CHANNEL;
2421 smi_addr->lun = msg->rsp[0] & 3;
2422 recv_msg->msg.netfn = msg->rsp[0] >> 2;
2423 recv_msg->msg.cmd = msg->rsp[1];
2424 memcpy(recv_msg->msg_data,
2427 recv_msg->msg.data = recv_msg->msg_data;
2428 recv_msg->msg.data_len = msg->rsp_size - 2;
2429 deliver_response(recv_msg);
2435 /* Handle a new message. Return 1 if the message should be requeued,
2436 0 if the message should be freed, or -1 if the message should not
2437 be freed or requeued. */
2438 static int handle_new_recv_msg(ipmi_smi_t intf,
2439 struct ipmi_smi_msg *msg)
2447 for (m=0; m<msg->rsp_size; m++)
2448 printk(" %2.2x", msg->rsp[m]);
2451 if (msg->rsp_size < 2) {
2452 /* Message is too small to be correct. */
2453 printk(KERN_WARNING PFX "BMC returned to small a message"
2454 " for netfn %x cmd %x, got %d bytes\n",
2455 (msg->data[0] >> 2) | 1, msg->data[1], msg->rsp_size);
2457 /* Generate an error response for the message. */
2458 msg->rsp[0] = msg->data[0] | (1 << 2);
2459 msg->rsp[1] = msg->data[1];
2460 msg->rsp[2] = IPMI_ERR_UNSPECIFIED;
2462 } else if (((msg->rsp[0] >> 2) != ((msg->data[0] >> 2) | 1))/* Netfn */
2463 || (msg->rsp[1] != msg->data[1])) /* Command */
2465 /* The response is not even marginally correct. */
2466 printk(KERN_WARNING PFX "BMC returned incorrect response,"
2467 " expected netfn %x cmd %x, got netfn %x cmd %x\n",
2468 (msg->data[0] >> 2) | 1, msg->data[1],
2469 msg->rsp[0] >> 2, msg->rsp[1]);
2471 /* Generate an error response for the message. */
2472 msg->rsp[0] = msg->data[0] | (1 << 2);
2473 msg->rsp[1] = msg->data[1];
2474 msg->rsp[2] = IPMI_ERR_UNSPECIFIED;
2478 if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2))
2479 && (msg->rsp[1] == IPMI_SEND_MSG_CMD)
2480 && (msg->user_data != NULL))
2482 /* It's a response to a response we sent. For this we
2483 deliver a send message response to the user. */
2484 struct ipmi_recv_msg *recv_msg = msg->user_data;
2487 if (msg->rsp_size < 2)
2488 /* Message is too small to be correct. */
2491 chan = msg->data[2] & 0x0f;
2492 if (chan >= IPMI_MAX_CHANNELS)
2493 /* Invalid channel number */
2497 recv_msg->recv_type = IPMI_RESPONSE_RESPONSE_TYPE;
2498 recv_msg->msg.data = recv_msg->msg_data;
2499 recv_msg->msg.data_len = 1;
2500 recv_msg->msg_data[0] = msg->rsp[2];
2501 deliver_response(recv_msg);
2503 } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2))
2504 && (msg->rsp[1] == IPMI_GET_MSG_CMD))
2506 /* It's from the receive queue. */
2507 chan = msg->rsp[3] & 0xf;
2508 if (chan >= IPMI_MAX_CHANNELS) {
2509 /* Invalid channel number */
2514 switch (intf->channels[chan].medium) {
2515 case IPMI_CHANNEL_MEDIUM_IPMB:
2516 if (msg->rsp[4] & 0x04) {
2517 /* It's a response, so find the
2518 requesting message and send it up. */
2519 requeue = handle_ipmb_get_msg_rsp(intf, msg);
2521 /* It's a command to the SMS from some other
2522 entity. Handle that. */
2523 requeue = handle_ipmb_get_msg_cmd(intf, msg);
2527 case IPMI_CHANNEL_MEDIUM_8023LAN:
2528 case IPMI_CHANNEL_MEDIUM_ASYNC:
2529 if (msg->rsp[6] & 0x04) {
2530 /* It's a response, so find the
2531 requesting message and send it up. */
2532 requeue = handle_lan_get_msg_rsp(intf, msg);
2534 /* It's a command to the SMS from some other
2535 entity. Handle that. */
2536 requeue = handle_lan_get_msg_cmd(intf, msg);
2541 /* We don't handle the channel type, so just
2542 * free the message. */
2546 } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2))
2547 && (msg->rsp[1] == IPMI_READ_EVENT_MSG_BUFFER_CMD))
2549 /* It's an asyncronous event. */
2550 requeue = handle_read_event_rsp(intf, msg);
2552 /* It's a response from the local BMC. */
2553 requeue = handle_bmc_rsp(intf, msg);
2560 /* Handle a new message from the lower layer. */
2561 void ipmi_smi_msg_received(ipmi_smi_t intf,
2562 struct ipmi_smi_msg *msg)
2564 unsigned long flags;
2568 /* Lock the user lock so the user can't go away while we are
2570 read_lock(&(intf->users_lock));
2572 if ((msg->data_size >= 2)
2573 && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2))
2574 && (msg->data[1] == IPMI_SEND_MSG_CMD)
2575 && (msg->user_data == NULL)) {
2576 /* This is the local response to a command send, start
2577 the timer for these. The user_data will not be
2578 NULL if this is a response send, and we will let
2579 response sends just go through. */
2581 /* Check for errors, if we get certain errors (ones
2582 that mean basically we can try again later), we
2583 ignore them and start the timer. Otherwise we
2584 report the error immediately. */
2585 if ((msg->rsp_size >= 3) && (msg->rsp[2] != 0)
2586 && (msg->rsp[2] != IPMI_NODE_BUSY_ERR)
2587 && (msg->rsp[2] != IPMI_LOST_ARBITRATION_ERR))
2589 int chan = msg->rsp[3] & 0xf;
2591 /* Got an error sending the message, handle it. */
2592 spin_lock_irqsave(&intf->counter_lock, flags);
2593 if (chan >= IPMI_MAX_CHANNELS)
2594 ; /* This shouldn't happen */
2595 else if ((intf->channels[chan].medium
2596 == IPMI_CHANNEL_MEDIUM_8023LAN)
2597 || (intf->channels[chan].medium
2598 == IPMI_CHANNEL_MEDIUM_ASYNC))
2599 intf->sent_lan_command_errs++;
2601 intf->sent_ipmb_command_errs++;
2602 spin_unlock_irqrestore(&intf->counter_lock, flags);
2603 intf_err_seq(intf, msg->msgid, msg->rsp[2]);
2605 /* The message was sent, start the timer. */
2606 intf_start_seq_timer(intf, msg->msgid);
2609 ipmi_free_smi_msg(msg);
2613 /* To preserve message order, if the list is not empty, we
2614 tack this message onto the end of the list. */
2615 spin_lock_irqsave(&(intf->waiting_msgs_lock), flags);
2616 if (!list_empty(&(intf->waiting_msgs))) {
2617 list_add_tail(&(msg->link), &(intf->waiting_msgs));
2618 spin_unlock(&(intf->waiting_msgs_lock));
2621 spin_unlock_irqrestore(&(intf->waiting_msgs_lock), flags);
2623 rv = handle_new_recv_msg(intf, msg);
2625 /* Could not handle the message now, just add it to a
2626 list to handle later. */
2627 spin_lock(&(intf->waiting_msgs_lock));
2628 list_add_tail(&(msg->link), &(intf->waiting_msgs));
2629 spin_unlock(&(intf->waiting_msgs_lock));
2630 } else if (rv == 0) {
2631 ipmi_free_smi_msg(msg);
2635 read_unlock(&(intf->users_lock));
2638 void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf)
2642 read_lock(&(intf->users_lock));
2643 list_for_each_entry(user, &(intf->users), link) {
2644 if (! user->handler->ipmi_watchdog_pretimeout)
2647 user->handler->ipmi_watchdog_pretimeout(user->handler_data);
2649 read_unlock(&(intf->users_lock));
2653 handle_msg_timeout(struct ipmi_recv_msg *msg)
2655 msg->recv_type = IPMI_RESPONSE_RECV_TYPE;
2656 msg->msg_data[0] = IPMI_TIMEOUT_COMPLETION_CODE;
2657 msg->msg.netfn |= 1; /* Convert to a response. */
2658 msg->msg.data_len = 1;
2659 msg->msg.data = msg->msg_data;
2660 deliver_response(msg);
2663 static struct ipmi_smi_msg *
2664 smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg,
2665 unsigned char seq, long seqid)
2667 struct ipmi_smi_msg *smi_msg = ipmi_alloc_smi_msg();
2669 /* If we can't allocate the message, then just return, we
2670 get 4 retries, so this should be ok. */
2673 memcpy(smi_msg->data, recv_msg->msg.data, recv_msg->msg.data_len);
2674 smi_msg->data_size = recv_msg->msg.data_len;
2675 smi_msg->msgid = STORE_SEQ_IN_MSGID(seq, seqid);
2681 for (m=0; m<smi_msg->data_size; m++)
2682 printk(" %2.2x", smi_msg->data[m]);
2690 ipmi_timeout_handler(long timeout_period)
2693 struct list_head timeouts;
2694 struct ipmi_recv_msg *msg, *msg2;
2695 struct ipmi_smi_msg *smi_msg, *smi_msg2;
2696 unsigned long flags;
2699 INIT_LIST_HEAD(&timeouts);
2701 spin_lock(&interfaces_lock);
2702 for (i=0; i<MAX_IPMI_INTERFACES; i++) {
2703 intf = ipmi_interfaces[i];
2707 read_lock(&(intf->users_lock));
2709 /* See if any waiting messages need to be processed. */
2710 spin_lock_irqsave(&(intf->waiting_msgs_lock), flags);
2711 list_for_each_entry_safe(smi_msg, smi_msg2, &(intf->waiting_msgs), link) {
2712 if (! handle_new_recv_msg(intf, smi_msg)) {
2713 list_del(&smi_msg->link);
2714 ipmi_free_smi_msg(smi_msg);
2716 /* To preserve message order, quit if we
2717 can't handle a message. */
2721 spin_unlock_irqrestore(&(intf->waiting_msgs_lock), flags);
2723 /* Go through the seq table and find any messages that
2724 have timed out, putting them in the timeouts
2726 spin_lock_irqsave(&(intf->seq_lock), flags);
2727 for (j=0; j<IPMI_IPMB_NUM_SEQ; j++) {
2728 struct seq_table *ent = &(intf->seq_table[j]);
2732 ent->timeout -= timeout_period;
2733 if (ent->timeout > 0)
2736 if (ent->retries_left == 0) {
2737 /* The message has used all its retries. */
2739 msg = ent->recv_msg;
2740 list_add_tail(&(msg->link), &timeouts);
2741 spin_lock(&intf->counter_lock);
2743 intf->timed_out_ipmb_broadcasts++;
2744 else if (ent->recv_msg->addr.addr_type
2745 == IPMI_LAN_ADDR_TYPE)
2746 intf->timed_out_lan_commands++;
2748 intf->timed_out_ipmb_commands++;
2749 spin_unlock(&intf->counter_lock);
2751 struct ipmi_smi_msg *smi_msg;
2752 /* More retries, send again. */
2754 /* Start with the max timer, set to normal
2755 timer after the message is sent. */
2756 ent->timeout = MAX_MSG_TIMEOUT;
2757 ent->retries_left--;
2758 spin_lock(&intf->counter_lock);
2759 if (ent->recv_msg->addr.addr_type
2760 == IPMI_LAN_ADDR_TYPE)
2761 intf->retransmitted_lan_commands++;
2763 intf->retransmitted_ipmb_commands++;
2764 spin_unlock(&intf->counter_lock);
2765 smi_msg = smi_from_recv_msg(intf,
2766 ent->recv_msg, j, ent->seqid);
2770 spin_unlock_irqrestore(&(intf->seq_lock),flags);
2771 /* Send the new message. We send with a zero
2772 * priority. It timed out, I doubt time is
2773 * that critical now, and high priority
2774 * messages are really only for messages to the
2775 * local MC, which don't get resent. */
2776 intf->handlers->sender(intf->send_info,
2778 spin_lock_irqsave(&(intf->seq_lock), flags);
2781 spin_unlock_irqrestore(&(intf->seq_lock), flags);
2783 list_for_each_entry_safe(msg, msg2, &timeouts, link) {
2784 handle_msg_timeout(msg);
2787 read_unlock(&(intf->users_lock));
2789 spin_unlock(&interfaces_lock);
2792 static void ipmi_request_event(void)
2797 spin_lock(&interfaces_lock);
2798 for (i=0; i<MAX_IPMI_INTERFACES; i++) {
2799 intf = ipmi_interfaces[i];
2803 intf->handlers->request_events(intf->send_info);
2805 spin_unlock(&interfaces_lock);
2808 static struct timer_list ipmi_timer;
2810 /* Call every ~100 ms. */
2811 #define IPMI_TIMEOUT_TIME 100
2813 /* How many jiffies does it take to get to the timeout time. */
2814 #define IPMI_TIMEOUT_JIFFIES ((IPMI_TIMEOUT_TIME * HZ) / 1000)
2816 /* Request events from the queue every second (this is the number of
2817 IPMI_TIMEOUT_TIMES between event requests). Hopefully, in the
2818 future, IPMI will add a way to know immediately if an event is in
2819 the queue and this silliness can go away. */
2820 #define IPMI_REQUEST_EV_TIME (1000 / (IPMI_TIMEOUT_TIME))
2822 static atomic_t stop_operation;
2823 static unsigned int ticks_to_req_ev = IPMI_REQUEST_EV_TIME;
2825 static void ipmi_timeout(unsigned long data)
2827 if (atomic_read(&stop_operation))
2831 if (ticks_to_req_ev == 0) {
2832 ipmi_request_event();
2833 ticks_to_req_ev = IPMI_REQUEST_EV_TIME;
2836 ipmi_timeout_handler(IPMI_TIMEOUT_TIME);
2838 mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES);
2842 static atomic_t smi_msg_inuse_count = ATOMIC_INIT(0);
2843 static atomic_t recv_msg_inuse_count = ATOMIC_INIT(0);
2845 /* FIXME - convert these to slabs. */
2846 static void free_smi_msg(struct ipmi_smi_msg *msg)
2848 atomic_dec(&smi_msg_inuse_count);
2852 struct ipmi_smi_msg *ipmi_alloc_smi_msg(void)
2854 struct ipmi_smi_msg *rv;
2855 rv = kmalloc(sizeof(struct ipmi_smi_msg), GFP_ATOMIC);
2857 rv->done = free_smi_msg;
2858 rv->user_data = NULL;
2859 atomic_inc(&smi_msg_inuse_count);
2864 static void free_recv_msg(struct ipmi_recv_msg *msg)
2866 atomic_dec(&recv_msg_inuse_count);
2870 struct ipmi_recv_msg *ipmi_alloc_recv_msg(void)
2872 struct ipmi_recv_msg *rv;
2874 rv = kmalloc(sizeof(struct ipmi_recv_msg), GFP_ATOMIC);
2876 rv->done = free_recv_msg;
2877 atomic_inc(&recv_msg_inuse_count);
2882 #ifdef CONFIG_IPMI_PANIC_EVENT
2884 static void dummy_smi_done_handler(struct ipmi_smi_msg *msg)
2888 static void dummy_recv_done_handler(struct ipmi_recv_msg *msg)
2892 #ifdef CONFIG_IPMI_PANIC_STRING
2893 static void event_receiver_fetcher(ipmi_smi_t intf, struct ipmi_smi_msg *msg)
2895 if ((msg->rsp[0] == (IPMI_NETFN_SENSOR_EVENT_RESPONSE << 2))
2896 && (msg->rsp[1] == IPMI_GET_EVENT_RECEIVER_CMD)
2897 && (msg->rsp[2] == IPMI_CC_NO_ERROR))
2899 /* A get event receiver command, save it. */
2900 intf->event_receiver = msg->rsp[3];
2901 intf->event_receiver_lun = msg->rsp[4] & 0x3;
2905 static void device_id_fetcher(ipmi_smi_t intf, struct ipmi_smi_msg *msg)
2907 if ((msg->rsp[0] == (IPMI_NETFN_APP_RESPONSE << 2))
2908 && (msg->rsp[1] == IPMI_GET_DEVICE_ID_CMD)
2909 && (msg->rsp[2] == IPMI_CC_NO_ERROR))
2911 /* A get device id command, save if we are an event
2912 receiver or generator. */
2913 intf->local_sel_device = (msg->rsp[8] >> 2) & 1;
2914 intf->local_event_generator = (msg->rsp[8] >> 5) & 1;
2919 static void send_panic_events(char *str)
2921 struct kernel_ipmi_msg msg;
2923 unsigned char data[16];
2925 struct ipmi_system_interface_addr *si;
2926 struct ipmi_addr addr;
2927 struct ipmi_smi_msg smi_msg;
2928 struct ipmi_recv_msg recv_msg;
2930 si = (struct ipmi_system_interface_addr *) &addr;
2931 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
2932 si->channel = IPMI_BMC_CHANNEL;
2935 /* Fill in an event telling that we have failed. */
2936 msg.netfn = 0x04; /* Sensor or Event. */
2937 msg.cmd = 2; /* Platform event command. */
2940 data[0] = 0x21; /* Kernel generator ID, IPMI table 5-4 */
2941 data[1] = 0x03; /* This is for IPMI 1.0. */
2942 data[2] = 0x20; /* OS Critical Stop, IPMI table 36-3 */
2943 data[4] = 0x6f; /* Sensor specific, IPMI table 36-1 */
2944 data[5] = 0xa1; /* Runtime stop OEM bytes 2 & 3. */
2946 /* Put a few breadcrumbs in. Hopefully later we can add more things
2947 to make the panic events more useful. */
2954 smi_msg.done = dummy_smi_done_handler;
2955 recv_msg.done = dummy_recv_done_handler;
2957 /* For every registered interface, send the event. */
2958 for (i=0; i<MAX_IPMI_INTERFACES; i++) {
2959 intf = ipmi_interfaces[i];
2963 /* Send the event announcing the panic. */
2964 intf->handlers->set_run_to_completion(intf->send_info, 1);
2965 i_ipmi_request(NULL,
2974 intf->channels[0].address,
2975 intf->channels[0].lun,
2976 0, 1); /* Don't retry, and don't wait. */
2979 #ifdef CONFIG_IPMI_PANIC_STRING
2980 /* On every interface, dump a bunch of OEM event holding the
2985 for (i=0; i<MAX_IPMI_INTERFACES; i++) {
2987 struct ipmi_ipmb_addr *ipmb;
2990 intf = ipmi_interfaces[i];
2994 /* First job here is to figure out where to send the
2995 OEM events. There's no way in IPMI to send OEM
2996 events using an event send command, so we have to
2997 find the SEL to put them in and stick them in
3000 /* Get capabilities from the get device id. */
3001 intf->local_sel_device = 0;
3002 intf->local_event_generator = 0;
3003 intf->event_receiver = 0;
3005 /* Request the device info from the local MC. */
3006 msg.netfn = IPMI_NETFN_APP_REQUEST;
3007 msg.cmd = IPMI_GET_DEVICE_ID_CMD;
3010 intf->null_user_handler = device_id_fetcher;
3011 i_ipmi_request(NULL,
3020 intf->channels[0].address,
3021 intf->channels[0].lun,
3022 0, 1); /* Don't retry, and don't wait. */
3024 if (intf->local_event_generator) {
3025 /* Request the event receiver from the local MC. */
3026 msg.netfn = IPMI_NETFN_SENSOR_EVENT_REQUEST;
3027 msg.cmd = IPMI_GET_EVENT_RECEIVER_CMD;
3030 intf->null_user_handler = event_receiver_fetcher;
3031 i_ipmi_request(NULL,
3040 intf->channels[0].address,
3041 intf->channels[0].lun,
3042 0, 1); /* no retry, and no wait. */
3044 intf->null_user_handler = NULL;
3046 /* Validate the event receiver. The low bit must not
3047 be 1 (it must be a valid IPMB address), it cannot
3048 be zero, and it must not be my address. */
3049 if (((intf->event_receiver & 1) == 0)
3050 && (intf->event_receiver != 0)
3051 && (intf->event_receiver != intf->channels[0].address))
3053 /* The event receiver is valid, send an IPMB
3055 ipmb = (struct ipmi_ipmb_addr *) &addr;
3056 ipmb->addr_type = IPMI_IPMB_ADDR_TYPE;
3057 ipmb->channel = 0; /* FIXME - is this right? */
3058 ipmb->lun = intf->event_receiver_lun;
3059 ipmb->slave_addr = intf->event_receiver;
3060 } else if (intf->local_sel_device) {
3061 /* The event receiver was not valid (or was
3062 me), but I am an SEL device, just dump it
3064 si = (struct ipmi_system_interface_addr *) &addr;
3065 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
3066 si->channel = IPMI_BMC_CHANNEL;
3069 continue; /* No where to send the event. */
3072 msg.netfn = IPMI_NETFN_STORAGE_REQUEST; /* Storage. */
3073 msg.cmd = IPMI_ADD_SEL_ENTRY_CMD;
3079 int size = strlen(p);
3085 data[2] = 0xf0; /* OEM event without timestamp. */
3086 data[3] = intf->channels[0].address;
3087 data[4] = j++; /* sequence # */
3088 /* Always give 11 bytes, so strncpy will fill
3089 it with zeroes for me. */
3090 strncpy(data+5, p, 11);
3093 i_ipmi_request(NULL,
3102 intf->channels[0].address,
3103 intf->channels[0].lun,
3104 0, 1); /* no retry, and no wait. */
3107 #endif /* CONFIG_IPMI_PANIC_STRING */
3109 #endif /* CONFIG_IPMI_PANIC_EVENT */
3111 static int has_paniced = 0;
3113 static int panic_event(struct notifier_block *this,
3114 unsigned long event,
3124 /* For every registered interface, set it to run to completion. */
3125 for (i=0; i<MAX_IPMI_INTERFACES; i++) {
3126 intf = ipmi_interfaces[i];
3130 intf->handlers->set_run_to_completion(intf->send_info, 1);
3133 #ifdef CONFIG_IPMI_PANIC_EVENT
3134 send_panic_events(ptr);
3140 static struct notifier_block panic_block = {
3141 .notifier_call = panic_event,
3143 .priority = 200 /* priority: INT_MAX >= x >= 0 */
3146 static int ipmi_init_msghandler(void)
3153 printk(KERN_INFO "ipmi message handler version "
3154 IPMI_DRIVER_VERSION "\n");
3156 for (i=0; i<MAX_IPMI_INTERFACES; i++) {
3157 ipmi_interfaces[i] = NULL;
3160 #ifdef CONFIG_PROC_FS
3161 proc_ipmi_root = proc_mkdir("ipmi", NULL);
3162 if (!proc_ipmi_root) {
3163 printk(KERN_ERR PFX "Unable to create IPMI proc dir");
3167 proc_ipmi_root->owner = THIS_MODULE;
3168 #endif /* CONFIG_PROC_FS */
3170 init_timer(&ipmi_timer);
3171 ipmi_timer.data = 0;
3172 ipmi_timer.function = ipmi_timeout;
3173 ipmi_timer.expires = jiffies + IPMI_TIMEOUT_JIFFIES;
3174 add_timer(&ipmi_timer);
3176 notifier_chain_register(&panic_notifier_list, &panic_block);
3183 static __init int ipmi_init_msghandler_mod(void)
3185 ipmi_init_msghandler();
3189 static __exit void cleanup_ipmi(void)
3196 notifier_chain_unregister(&panic_notifier_list, &panic_block);
3198 /* This can't be called if any interfaces exist, so no worry about
3199 shutting down the interfaces. */
3201 /* Tell the timer to stop, then wait for it to stop. This avoids
3202 problems with race conditions removing the timer here. */
3203 atomic_inc(&stop_operation);
3204 del_timer_sync(&ipmi_timer);
3206 #ifdef CONFIG_PROC_FS
3207 remove_proc_entry(proc_ipmi_root->name, &proc_root);
3208 #endif /* CONFIG_PROC_FS */
3212 /* Check for buffer leaks. */
3213 count = atomic_read(&smi_msg_inuse_count);
3215 printk(KERN_WARNING PFX "SMI message count %d at exit\n",
3217 count = atomic_read(&recv_msg_inuse_count);
3219 printk(KERN_WARNING PFX "recv message count %d at exit\n",
3222 module_exit(cleanup_ipmi);
3224 module_init(ipmi_init_msghandler_mod);
3225 MODULE_LICENSE("GPL");
3226 MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
3227 MODULE_DESCRIPTION("Incoming and outgoing message routing for an IPMI interface.");
3228 MODULE_VERSION(IPMI_DRIVER_VERSION);
3230 EXPORT_SYMBOL(ipmi_create_user);
3231 EXPORT_SYMBOL(ipmi_destroy_user);
3232 EXPORT_SYMBOL(ipmi_get_version);
3233 EXPORT_SYMBOL(ipmi_request_settime);
3234 EXPORT_SYMBOL(ipmi_request_supply_msgs);
3235 EXPORT_SYMBOL(ipmi_register_smi);
3236 EXPORT_SYMBOL(ipmi_unregister_smi);
3237 EXPORT_SYMBOL(ipmi_register_for_cmd);
3238 EXPORT_SYMBOL(ipmi_unregister_for_cmd);
3239 EXPORT_SYMBOL(ipmi_smi_msg_received);
3240 EXPORT_SYMBOL(ipmi_smi_watchdog_pretimeout);
3241 EXPORT_SYMBOL(ipmi_alloc_smi_msg);
3242 EXPORT_SYMBOL(ipmi_addr_length);
3243 EXPORT_SYMBOL(ipmi_validate_addr);
3244 EXPORT_SYMBOL(ipmi_set_gets_events);
3245 EXPORT_SYMBOL(ipmi_smi_watcher_register);
3246 EXPORT_SYMBOL(ipmi_smi_watcher_unregister);
3247 EXPORT_SYMBOL(ipmi_set_my_address);
3248 EXPORT_SYMBOL(ipmi_get_my_address);
3249 EXPORT_SYMBOL(ipmi_set_my_LUN);
3250 EXPORT_SYMBOL(ipmi_get_my_LUN);
3251 EXPORT_SYMBOL(ipmi_smi_add_proc_entry);
3252 EXPORT_SYMBOL(proc_ipmi_root);
3253 EXPORT_SYMBOL(ipmi_user_set_run_to_completion);