aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/ipmi/ipmi_msghandler.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/ipmi/ipmi_msghandler.c')
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c336
1 files changed, 199 insertions, 137 deletions
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index e16c13fe698d..463351d4f942 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -47,7 +47,8 @@
47#include <linux/proc_fs.h> 47#include <linux/proc_fs.h>
48 48
49#define PFX "IPMI message handler: " 49#define PFX "IPMI message handler: "
50#define IPMI_MSGHANDLER_VERSION "v33" 50
51#define IPMI_DRIVER_VERSION "36.0"
51 52
52static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); 53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
53static int ipmi_init_msghandler(void); 54static int ipmi_init_msghandler(void);
@@ -116,7 +117,7 @@ struct seq_table
116 do { \ 117 do { \
117 seq = ((msgid >> 26) & 0x3f); \ 118 seq = ((msgid >> 26) & 0x3f); \
118 seqid = (msgid & 0x3fffff); \ 119 seqid = (msgid & 0x3fffff); \
119 } while(0) 120 } while (0)
120 121
121#define NEXT_SEQID(seqid) (((seqid) + 1) & 0x3fffff) 122#define NEXT_SEQID(seqid) (((seqid) + 1) & 0x3fffff)
122 123
@@ -124,6 +125,14 @@ struct ipmi_channel
124{ 125{
125 unsigned char medium; 126 unsigned char medium;
126 unsigned char protocol; 127 unsigned char protocol;
128
129 /* My slave address. This is initialized to IPMI_BMC_SLAVE_ADDR,
130 but may be changed by the user. */
131 unsigned char address;
132
133 /* My LUN. This should generally stay the SMS LUN, but just in
134 case... */
135 unsigned char lun;
127}; 136};
128 137
129#ifdef CONFIG_PROC_FS 138#ifdef CONFIG_PROC_FS
@@ -135,7 +144,7 @@ struct ipmi_proc_entry
135#endif 144#endif
136 145
137#define IPMI_IPMB_NUM_SEQ 64 146#define IPMI_IPMB_NUM_SEQ 64
138#define IPMI_MAX_CHANNELS 8 147#define IPMI_MAX_CHANNELS 16
139struct ipmi_smi 148struct ipmi_smi
140{ 149{
141 /* What interface number are we? */ 150 /* What interface number are we? */
@@ -193,20 +202,6 @@ struct ipmi_smi
193 struct list_head waiting_events; 202 struct list_head waiting_events;
194 unsigned int waiting_events_count; /* How many events in queue? */ 203 unsigned int waiting_events_count; /* How many events in queue? */
195 204
196 /* This will be non-null if someone registers to receive all
197 IPMI commands (this is for interface emulation). There
198 may not be any things in the cmd_rcvrs list above when
199 this is registered. */
200 ipmi_user_t all_cmd_rcvr;
201
202 /* My slave address. This is initialized to IPMI_BMC_SLAVE_ADDR,
203 but may be changed by the user. */
204 unsigned char my_address;
205
206 /* My LUN. This should generally stay the SMS LUN, but just in
207 case... */
208 unsigned char my_lun;
209
210 /* The event receiver for my BMC, only really used at panic 205 /* The event receiver for my BMC, only really used at panic
211 shutdown as a place to store this. */ 206 shutdown as a place to store this. */
212 unsigned char event_receiver; 207 unsigned char event_receiver;
@@ -218,7 +213,7 @@ struct ipmi_smi
218 interface comes in with a NULL user, call this routine with 213 interface comes in with a NULL user, call this routine with
219 it. Note that the message will still be freed by the 214 it. Note that the message will still be freed by the
220 caller. This only works on the system interface. */ 215 caller. This only works on the system interface. */
221 void (*null_user_handler)(ipmi_smi_t intf, struct ipmi_smi_msg *msg); 216 void (*null_user_handler)(ipmi_smi_t intf, struct ipmi_recv_msg *msg);
222 217
223 /* When we are scanning the channels for an SMI, this will 218 /* When we are scanning the channels for an SMI, this will
224 tell which channel we are scanning. */ 219 tell which channel we are scanning. */
@@ -325,7 +320,7 @@ int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
325 down_read(&interfaces_sem); 320 down_read(&interfaces_sem);
326 down_write(&smi_watchers_sem); 321 down_write(&smi_watchers_sem);
327 list_add(&(watcher->link), &smi_watchers); 322 list_add(&(watcher->link), &smi_watchers);
328 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 323 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
329 if (ipmi_interfaces[i] != NULL) { 324 if (ipmi_interfaces[i] != NULL) {
330 watcher->new_smi(i); 325 watcher->new_smi(i);
331 } 326 }
@@ -458,7 +453,27 @@ unsigned int ipmi_addr_length(int addr_type)
458 453
459static void deliver_response(struct ipmi_recv_msg *msg) 454static void deliver_response(struct ipmi_recv_msg *msg)
460{ 455{
461 msg->user->handler->ipmi_recv_hndl(msg, msg->user->handler_data); 456 if (! msg->user) {
457 ipmi_smi_t intf = msg->user_msg_data;
458 unsigned long flags;
459
460 /* Special handling for NULL users. */
461 if (intf->null_user_handler) {
462 intf->null_user_handler(intf, msg);
463 spin_lock_irqsave(&intf->counter_lock, flags);
464 intf->handled_local_responses++;
465 spin_unlock_irqrestore(&intf->counter_lock, flags);
466 } else {
467 /* No handler, so give up. */
468 spin_lock_irqsave(&intf->counter_lock, flags);
469 intf->unhandled_local_responses++;
470 spin_unlock_irqrestore(&intf->counter_lock, flags);
471 }
472 ipmi_free_recv_msg(msg);
473 } else {
474 msg->user->handler->ipmi_recv_hndl(msg,
475 msg->user->handler_data);
476 }
462} 477}
463 478
464/* Find the next sequence number not being used and add the given 479/* Find the next sequence number not being used and add the given
@@ -475,9 +490,9 @@ static int intf_next_seq(ipmi_smi_t intf,
475 int rv = 0; 490 int rv = 0;
476 unsigned int i; 491 unsigned int i;
477 492
478 for (i=intf->curr_seq; 493 for (i = intf->curr_seq;
479 (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq; 494 (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq;
480 i=(i+1)%IPMI_IPMB_NUM_SEQ) 495 i = (i+1)%IPMI_IPMB_NUM_SEQ)
481 { 496 {
482 if (! intf->seq_table[i].inuse) 497 if (! intf->seq_table[i].inuse)
483 break; 498 break;
@@ -712,7 +727,7 @@ static int ipmi_destroy_user_nolock(ipmi_user_t user)
712 727
713 /* Remove the user from the interfaces sequence table. */ 728 /* Remove the user from the interfaces sequence table. */
714 spin_lock_irqsave(&(user->intf->seq_lock), flags); 729 spin_lock_irqsave(&(user->intf->seq_lock), flags);
715 for (i=0; i<IPMI_IPMB_NUM_SEQ; i++) { 730 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
716 if (user->intf->seq_table[i].inuse 731 if (user->intf->seq_table[i].inuse
717 && (user->intf->seq_table[i].recv_msg->user == user)) 732 && (user->intf->seq_table[i].recv_msg->user == user))
718 { 733 {
@@ -766,26 +781,44 @@ void ipmi_get_version(ipmi_user_t user,
766 *minor = user->intf->version_minor; 781 *minor = user->intf->version_minor;
767} 782}
768 783
769void ipmi_set_my_address(ipmi_user_t user, 784int ipmi_set_my_address(ipmi_user_t user,
770 unsigned char address) 785 unsigned int channel,
786 unsigned char address)
771{ 787{
772 user->intf->my_address = address; 788 if (channel >= IPMI_MAX_CHANNELS)
789 return -EINVAL;
790 user->intf->channels[channel].address = address;
791 return 0;
773} 792}
774 793
775unsigned char ipmi_get_my_address(ipmi_user_t user) 794int ipmi_get_my_address(ipmi_user_t user,
795 unsigned int channel,
796 unsigned char *address)
776{ 797{
777 return user->intf->my_address; 798 if (channel >= IPMI_MAX_CHANNELS)
799 return -EINVAL;
800 *address = user->intf->channels[channel].address;
801 return 0;
778} 802}
779 803
780void ipmi_set_my_LUN(ipmi_user_t user, 804int ipmi_set_my_LUN(ipmi_user_t user,
781 unsigned char LUN) 805 unsigned int channel,
806 unsigned char LUN)
782{ 807{
783 user->intf->my_lun = LUN & 0x3; 808 if (channel >= IPMI_MAX_CHANNELS)
809 return -EINVAL;
810 user->intf->channels[channel].lun = LUN & 0x3;
811 return 0;
784} 812}
785 813
786unsigned char ipmi_get_my_LUN(ipmi_user_t user) 814int ipmi_get_my_LUN(ipmi_user_t user,
815 unsigned int channel,
816 unsigned char *address)
787{ 817{
788 return user->intf->my_lun; 818 if (channel >= IPMI_MAX_CHANNELS)
819 return -EINVAL;
820 *address = user->intf->channels[channel].lun;
821 return 0;
789} 822}
790 823
791int ipmi_set_gets_events(ipmi_user_t user, int val) 824int ipmi_set_gets_events(ipmi_user_t user, int val)
@@ -828,11 +861,6 @@ int ipmi_register_for_cmd(ipmi_user_t user,
828 861
829 read_lock(&(user->intf->users_lock)); 862 read_lock(&(user->intf->users_lock));
830 write_lock_irqsave(&(user->intf->cmd_rcvr_lock), flags); 863 write_lock_irqsave(&(user->intf->cmd_rcvr_lock), flags);
831 if (user->intf->all_cmd_rcvr != NULL) {
832 rv = -EBUSY;
833 goto out_unlock;
834 }
835
836 /* Make sure the command/netfn is not already registered. */ 864 /* Make sure the command/netfn is not already registered. */
837 list_for_each_entry(cmp, &(user->intf->cmd_rcvrs), link) { 865 list_for_each_entry(cmp, &(user->intf->cmd_rcvrs), link) {
838 if ((cmp->netfn == netfn) && (cmp->cmd == cmd)) { 866 if ((cmp->netfn == netfn) && (cmp->cmd == cmd)) {
@@ -847,7 +875,7 @@ int ipmi_register_for_cmd(ipmi_user_t user,
847 rcvr->user = user; 875 rcvr->user = user;
848 list_add_tail(&(rcvr->link), &(user->intf->cmd_rcvrs)); 876 list_add_tail(&(rcvr->link), &(user->intf->cmd_rcvrs));
849 } 877 }
850 out_unlock: 878
851 write_unlock_irqrestore(&(user->intf->cmd_rcvr_lock), flags); 879 write_unlock_irqrestore(&(user->intf->cmd_rcvr_lock), flags);
852 read_unlock(&(user->intf->users_lock)); 880 read_unlock(&(user->intf->users_lock));
853 881
@@ -1213,7 +1241,7 @@ static inline int i_ipmi_request(ipmi_user_t user,
1213 unsigned char ipmb_seq; 1241 unsigned char ipmb_seq;
1214 long seqid; 1242 long seqid;
1215 1243
1216 if (addr->channel > IPMI_NUM_CHANNELS) { 1244 if (addr->channel >= IPMI_NUM_CHANNELS) {
1217 spin_lock_irqsave(&intf->counter_lock, flags); 1245 spin_lock_irqsave(&intf->counter_lock, flags);
1218 intf->sent_invalid_commands++; 1246 intf->sent_invalid_commands++;
1219 spin_unlock_irqrestore(&intf->counter_lock, flags); 1247 spin_unlock_irqrestore(&intf->counter_lock, flags);
@@ -1331,7 +1359,7 @@ static inline int i_ipmi_request(ipmi_user_t user,
1331#ifdef DEBUG_MSGING 1359#ifdef DEBUG_MSGING
1332 { 1360 {
1333 int m; 1361 int m;
1334 for (m=0; m<smi_msg->data_size; m++) 1362 for (m = 0; m < smi_msg->data_size; m++)
1335 printk(" %2.2x", smi_msg->data[m]); 1363 printk(" %2.2x", smi_msg->data[m]);
1336 printk("\n"); 1364 printk("\n");
1337 } 1365 }
@@ -1346,6 +1374,18 @@ static inline int i_ipmi_request(ipmi_user_t user,
1346 return rv; 1374 return rv;
1347} 1375}
1348 1376
1377static int check_addr(ipmi_smi_t intf,
1378 struct ipmi_addr *addr,
1379 unsigned char *saddr,
1380 unsigned char *lun)
1381{
1382 if (addr->channel >= IPMI_MAX_CHANNELS)
1383 return -EINVAL;
1384 *lun = intf->channels[addr->channel].lun;
1385 *saddr = intf->channels[addr->channel].address;
1386 return 0;
1387}
1388
1349int ipmi_request_settime(ipmi_user_t user, 1389int ipmi_request_settime(ipmi_user_t user,
1350 struct ipmi_addr *addr, 1390 struct ipmi_addr *addr,
1351 long msgid, 1391 long msgid,
@@ -1355,6 +1395,14 @@ int ipmi_request_settime(ipmi_user_t user,
1355 int retries, 1395 int retries,
1356 unsigned int retry_time_ms) 1396 unsigned int retry_time_ms)
1357{ 1397{
1398 unsigned char saddr, lun;
1399 int rv;
1400
1401 if (! user)
1402 return -EINVAL;
1403 rv = check_addr(user->intf, addr, &saddr, &lun);
1404 if (rv)
1405 return rv;
1358 return i_ipmi_request(user, 1406 return i_ipmi_request(user,
1359 user->intf, 1407 user->intf,
1360 addr, 1408 addr,
@@ -1363,8 +1411,8 @@ int ipmi_request_settime(ipmi_user_t user,
1363 user_msg_data, 1411 user_msg_data,
1364 NULL, NULL, 1412 NULL, NULL,
1365 priority, 1413 priority,
1366 user->intf->my_address, 1414 saddr,
1367 user->intf->my_lun, 1415 lun,
1368 retries, 1416 retries,
1369 retry_time_ms); 1417 retry_time_ms);
1370} 1418}
@@ -1378,6 +1426,14 @@ int ipmi_request_supply_msgs(ipmi_user_t user,
1378 struct ipmi_recv_msg *supplied_recv, 1426 struct ipmi_recv_msg *supplied_recv,
1379 int priority) 1427 int priority)
1380{ 1428{
1429 unsigned char saddr, lun;
1430 int rv;
1431
1432 if (! user)
1433 return -EINVAL;
1434 rv = check_addr(user->intf, addr, &saddr, &lun);
1435 if (rv)
1436 return rv;
1381 return i_ipmi_request(user, 1437 return i_ipmi_request(user,
1382 user->intf, 1438 user->intf,
1383 addr, 1439 addr,
@@ -1387,8 +1443,8 @@ int ipmi_request_supply_msgs(ipmi_user_t user,
1387 supplied_smi, 1443 supplied_smi,
1388 supplied_recv, 1444 supplied_recv,
1389 priority, 1445 priority,
1390 user->intf->my_address, 1446 saddr,
1391 user->intf->my_lun, 1447 lun,
1392 -1, 0); 1448 -1, 0);
1393} 1449}
1394 1450
@@ -1397,8 +1453,15 @@ static int ipmb_file_read_proc(char *page, char **start, off_t off,
1397{ 1453{
1398 char *out = (char *) page; 1454 char *out = (char *) page;
1399 ipmi_smi_t intf = data; 1455 ipmi_smi_t intf = data;
1456 int i;
1457 int rv= 0;
1400 1458
1401 return sprintf(out, "%x\n", intf->my_address); 1459 for (i = 0; i < IPMI_MAX_CHANNELS; i++)
1460 rv += sprintf(out+rv, "%x ", intf->channels[i].address);
1461 out[rv-1] = '\n'; /* Replace the final space with a newline */
1462 out[rv] = '\0';
1463 rv++;
1464 return rv;
1402} 1465}
1403 1466
1404static int version_file_read_proc(char *page, char **start, off_t off, 1467static int version_file_read_proc(char *page, char **start, off_t off,
@@ -1588,29 +1651,30 @@ send_channel_info_cmd(ipmi_smi_t intf, int chan)
1588 (struct ipmi_addr *) &si, 1651 (struct ipmi_addr *) &si,
1589 0, 1652 0,
1590 &msg, 1653 &msg,
1591 NULL, 1654 intf,
1592 NULL, 1655 NULL,
1593 NULL, 1656 NULL,
1594 0, 1657 0,
1595 intf->my_address, 1658 intf->channels[0].address,
1596 intf->my_lun, 1659 intf->channels[0].lun,
1597 -1, 0); 1660 -1, 0);
1598} 1661}
1599 1662
1600static void 1663static void
1601channel_handler(ipmi_smi_t intf, struct ipmi_smi_msg *msg) 1664channel_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
1602{ 1665{
1603 int rv = 0; 1666 int rv = 0;
1604 int chan; 1667 int chan;
1605 1668
1606 if ((msg->rsp[0] == (IPMI_NETFN_APP_RESPONSE << 2)) 1669 if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
1607 && (msg->rsp[1] == IPMI_GET_CHANNEL_INFO_CMD)) 1670 && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE)
1671 && (msg->msg.cmd == IPMI_GET_CHANNEL_INFO_CMD))
1608 { 1672 {
1609 /* It's the one we want */ 1673 /* It's the one we want */
1610 if (msg->rsp[2] != 0) { 1674 if (msg->msg.data[0] != 0) {
1611 /* Got an error from the channel, just go on. */ 1675 /* Got an error from the channel, just go on. */
1612 1676
1613 if (msg->rsp[2] == IPMI_INVALID_COMMAND_ERR) { 1677 if (msg->msg.data[0] == IPMI_INVALID_COMMAND_ERR) {
1614 /* If the MC does not support this 1678 /* If the MC does not support this
1615 command, that is legal. We just 1679 command, that is legal. We just
1616 assume it has one IPMB at channel 1680 assume it has one IPMB at channel
@@ -1627,13 +1691,13 @@ channel_handler(ipmi_smi_t intf, struct ipmi_smi_msg *msg)
1627 } 1691 }
1628 goto next_channel; 1692 goto next_channel;
1629 } 1693 }
1630 if (msg->rsp_size < 6) { 1694 if (msg->msg.data_len < 4) {
1631 /* Message not big enough, just go on. */ 1695 /* Message not big enough, just go on. */
1632 goto next_channel; 1696 goto next_channel;
1633 } 1697 }
1634 chan = intf->curr_channel; 1698 chan = intf->curr_channel;
1635 intf->channels[chan].medium = msg->rsp[4] & 0x7f; 1699 intf->channels[chan].medium = msg->msg.data[2] & 0x7f;
1636 intf->channels[chan].protocol = msg->rsp[5] & 0x1f; 1700 intf->channels[chan].protocol = msg->msg.data[3] & 0x1f;
1637 1701
1638 next_channel: 1702 next_channel:
1639 intf->curr_channel++; 1703 intf->curr_channel++;
@@ -1691,22 +1755,24 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1691 rv = -ENOMEM; 1755 rv = -ENOMEM;
1692 1756
1693 down_write(&interfaces_sem); 1757 down_write(&interfaces_sem);
1694 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 1758 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
1695 if (ipmi_interfaces[i] == NULL) { 1759 if (ipmi_interfaces[i] == NULL) {
1696 new_intf->intf_num = i; 1760 new_intf->intf_num = i;
1697 new_intf->version_major = version_major; 1761 new_intf->version_major = version_major;
1698 new_intf->version_minor = version_minor; 1762 new_intf->version_minor = version_minor;
1699 if (slave_addr == 0) 1763 for (j = 0; j < IPMI_MAX_CHANNELS; j++) {
1700 new_intf->my_address = IPMI_BMC_SLAVE_ADDR; 1764 new_intf->channels[j].address
1701 else 1765 = IPMI_BMC_SLAVE_ADDR;
1702 new_intf->my_address = slave_addr; 1766 new_intf->channels[j].lun = 2;
1703 new_intf->my_lun = 2; /* the SMS LUN. */ 1767 }
1768 if (slave_addr != 0)
1769 new_intf->channels[0].address = slave_addr;
1704 rwlock_init(&(new_intf->users_lock)); 1770 rwlock_init(&(new_intf->users_lock));
1705 INIT_LIST_HEAD(&(new_intf->users)); 1771 INIT_LIST_HEAD(&(new_intf->users));
1706 new_intf->handlers = handlers; 1772 new_intf->handlers = handlers;
1707 new_intf->send_info = send_info; 1773 new_intf->send_info = send_info;
1708 spin_lock_init(&(new_intf->seq_lock)); 1774 spin_lock_init(&(new_intf->seq_lock));
1709 for (j=0; j<IPMI_IPMB_NUM_SEQ; j++) { 1775 for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) {
1710 new_intf->seq_table[j].inuse = 0; 1776 new_intf->seq_table[j].inuse = 0;
1711 new_intf->seq_table[j].seqid = 0; 1777 new_intf->seq_table[j].seqid = 0;
1712 } 1778 }
@@ -1722,7 +1788,6 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1722 rwlock_init(&(new_intf->cmd_rcvr_lock)); 1788 rwlock_init(&(new_intf->cmd_rcvr_lock));
1723 init_waitqueue_head(&new_intf->waitq); 1789 init_waitqueue_head(&new_intf->waitq);
1724 INIT_LIST_HEAD(&(new_intf->cmd_rcvrs)); 1790 INIT_LIST_HEAD(&(new_intf->cmd_rcvrs));
1725 new_intf->all_cmd_rcvr = NULL;
1726 1791
1727 spin_lock_init(&(new_intf->counter_lock)); 1792 spin_lock_init(&(new_intf->counter_lock));
1728 1793
@@ -1814,7 +1879,7 @@ static void clean_up_interface_data(ipmi_smi_t intf)
1814 free_recv_msg_list(&(intf->waiting_events)); 1879 free_recv_msg_list(&(intf->waiting_events));
1815 free_cmd_rcvr_list(&(intf->cmd_rcvrs)); 1880 free_cmd_rcvr_list(&(intf->cmd_rcvrs));
1816 1881
1817 for (i=0; i<IPMI_IPMB_NUM_SEQ; i++) { 1882 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
1818 if ((intf->seq_table[i].inuse) 1883 if ((intf->seq_table[i].inuse)
1819 && (intf->seq_table[i].recv_msg)) 1884 && (intf->seq_table[i].recv_msg))
1820 { 1885 {
@@ -1833,7 +1898,7 @@ int ipmi_unregister_smi(ipmi_smi_t intf)
1833 down_write(&interfaces_sem); 1898 down_write(&interfaces_sem);
1834 if (list_empty(&(intf->users))) 1899 if (list_empty(&(intf->users)))
1835 { 1900 {
1836 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 1901 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
1837 if (ipmi_interfaces[i] == intf) { 1902 if (ipmi_interfaces[i] == intf) {
1838 remove_proc_entries(intf); 1903 remove_proc_entries(intf);
1839 spin_lock_irqsave(&interfaces_lock, flags); 1904 spin_lock_irqsave(&interfaces_lock, flags);
@@ -1960,15 +2025,11 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
1960 2025
1961 read_lock(&(intf->cmd_rcvr_lock)); 2026 read_lock(&(intf->cmd_rcvr_lock));
1962 2027
1963 if (intf->all_cmd_rcvr) { 2028 /* Find the command/netfn. */
1964 user = intf->all_cmd_rcvr; 2029 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) {
1965 } else { 2030 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
1966 /* Find the command/netfn. */ 2031 user = rcvr->user;
1967 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) { 2032 break;
1968 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
1969 user = rcvr->user;
1970 break;
1971 }
1972 } 2033 }
1973 } 2034 }
1974 read_unlock(&(intf->cmd_rcvr_lock)); 2035 read_unlock(&(intf->cmd_rcvr_lock));
@@ -1985,7 +2046,7 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
1985 msg->data[3] = msg->rsp[6]; 2046 msg->data[3] = msg->rsp[6];
1986 msg->data[4] = ((netfn + 1) << 2) | (msg->rsp[7] & 0x3); 2047 msg->data[4] = ((netfn + 1) << 2) | (msg->rsp[7] & 0x3);
1987 msg->data[5] = ipmb_checksum(&(msg->data[3]), 2); 2048 msg->data[5] = ipmb_checksum(&(msg->data[3]), 2);
1988 msg->data[6] = intf->my_address; 2049 msg->data[6] = intf->channels[msg->rsp[3] & 0xf].address;
1989 /* rqseq/lun */ 2050 /* rqseq/lun */
1990 msg->data[7] = (msg->rsp[7] & 0xfc) | (msg->rsp[4] & 0x3); 2051 msg->data[7] = (msg->rsp[7] & 0xfc) | (msg->rsp[4] & 0x3);
1991 msg->data[8] = msg->rsp[8]; /* cmd */ 2052 msg->data[8] = msg->rsp[8]; /* cmd */
@@ -1997,7 +2058,7 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
1997 { 2058 {
1998 int m; 2059 int m;
1999 printk("Invalid command:"); 2060 printk("Invalid command:");
2000 for (m=0; m<msg->data_size; m++) 2061 for (m = 0; m < msg->data_size; m++)
2001 printk(" %2.2x", msg->data[m]); 2062 printk(" %2.2x", msg->data[m]);
2002 printk("\n"); 2063 printk("\n");
2003 } 2064 }
@@ -2145,15 +2206,11 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2145 2206
2146 read_lock(&(intf->cmd_rcvr_lock)); 2207 read_lock(&(intf->cmd_rcvr_lock));
2147 2208
2148 if (intf->all_cmd_rcvr) { 2209 /* Find the command/netfn. */
2149 user = intf->all_cmd_rcvr; 2210 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) {
2150 } else { 2211 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
2151 /* Find the command/netfn. */ 2212 user = rcvr->user;
2152 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) { 2213 break;
2153 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
2154 user = rcvr->user;
2155 break;
2156 }
2157 } 2214 }
2158 } 2215 }
2159 read_unlock(&(intf->cmd_rcvr_lock)); 2216 read_unlock(&(intf->cmd_rcvr_lock));
@@ -2330,6 +2387,14 @@ static int handle_bmc_rsp(ipmi_smi_t intf,
2330 unsigned long flags; 2387 unsigned long flags;
2331 2388
2332 recv_msg = (struct ipmi_recv_msg *) msg->user_data; 2389 recv_msg = (struct ipmi_recv_msg *) msg->user_data;
2390 if (recv_msg == NULL)
2391 {
2392 printk(KERN_WARNING"IPMI message received with no owner. This\n"
2393 "could be because of a malformed message, or\n"
2394 "because of a hardware error. Contact your\n"
2395 "hardware vender for assistance\n");
2396 return 0;
2397 }
2333 2398
2334 /* Make sure the user still exists. */ 2399 /* Make sure the user still exists. */
2335 list_for_each_entry(user, &(intf->users), link) { 2400 list_for_each_entry(user, &(intf->users), link) {
@@ -2340,19 +2405,11 @@ static int handle_bmc_rsp(ipmi_smi_t intf,
2340 } 2405 }
2341 } 2406 }
2342 2407
2343 if (!found) { 2408 if ((! found) && recv_msg->user) {
2344 /* Special handling for NULL users. */ 2409 /* The user for the message went away, so give up. */
2345 if (!recv_msg->user && intf->null_user_handler){ 2410 spin_lock_irqsave(&intf->counter_lock, flags);
2346 intf->null_user_handler(intf, msg); 2411 intf->unhandled_local_responses++;
2347 spin_lock_irqsave(&intf->counter_lock, flags); 2412 spin_unlock_irqrestore(&intf->counter_lock, flags);
2348 intf->handled_local_responses++;
2349 spin_unlock_irqrestore(&intf->counter_lock, flags);
2350 }else{
2351 /* The user for the message went away, so give up. */
2352 spin_lock_irqsave(&intf->counter_lock, flags);
2353 intf->unhandled_local_responses++;
2354 spin_unlock_irqrestore(&intf->counter_lock, flags);
2355 }
2356 ipmi_free_recv_msg(recv_msg); 2413 ipmi_free_recv_msg(recv_msg);
2357 } else { 2414 } else {
2358 struct ipmi_system_interface_addr *smi_addr; 2415 struct ipmi_system_interface_addr *smi_addr;
@@ -2392,7 +2449,7 @@ static int handle_new_recv_msg(ipmi_smi_t intf,
2392#ifdef DEBUG_MSGING 2449#ifdef DEBUG_MSGING
2393 int m; 2450 int m;
2394 printk("Recv:"); 2451 printk("Recv:");
2395 for (m=0; m<msg->rsp_size; m++) 2452 for (m = 0; m < msg->rsp_size; m++)
2396 printk(" %2.2x", msg->rsp[m]); 2453 printk(" %2.2x", msg->rsp[m]);
2397 printk("\n"); 2454 printk("\n");
2398#endif 2455#endif
@@ -2626,7 +2683,7 @@ smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg,
2626 { 2683 {
2627 int m; 2684 int m;
2628 printk("Resend: "); 2685 printk("Resend: ");
2629 for (m=0; m<smi_msg->data_size; m++) 2686 for (m = 0; m < smi_msg->data_size; m++)
2630 printk(" %2.2x", smi_msg->data[m]); 2687 printk(" %2.2x", smi_msg->data[m]);
2631 printk("\n"); 2688 printk("\n");
2632 } 2689 }
@@ -2647,7 +2704,7 @@ ipmi_timeout_handler(long timeout_period)
2647 INIT_LIST_HEAD(&timeouts); 2704 INIT_LIST_HEAD(&timeouts);
2648 2705
2649 spin_lock(&interfaces_lock); 2706 spin_lock(&interfaces_lock);
2650 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 2707 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2651 intf = ipmi_interfaces[i]; 2708 intf = ipmi_interfaces[i];
2652 if (intf == NULL) 2709 if (intf == NULL)
2653 continue; 2710 continue;
@@ -2672,7 +2729,7 @@ ipmi_timeout_handler(long timeout_period)
2672 have timed out, putting them in the timeouts 2729 have timed out, putting them in the timeouts
2673 list. */ 2730 list. */
2674 spin_lock_irqsave(&(intf->seq_lock), flags); 2731 spin_lock_irqsave(&(intf->seq_lock), flags);
2675 for (j=0; j<IPMI_IPMB_NUM_SEQ; j++) { 2732 for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) {
2676 struct seq_table *ent = &(intf->seq_table[j]); 2733 struct seq_table *ent = &(intf->seq_table[j]);
2677 if (!ent->inuse) 2734 if (!ent->inuse)
2678 continue; 2735 continue;
@@ -2712,7 +2769,7 @@ ipmi_timeout_handler(long timeout_period)
2712 spin_unlock(&intf->counter_lock); 2769 spin_unlock(&intf->counter_lock);
2713 smi_msg = smi_from_recv_msg(intf, 2770 smi_msg = smi_from_recv_msg(intf,
2714 ent->recv_msg, j, ent->seqid); 2771 ent->recv_msg, j, ent->seqid);
2715 if(!smi_msg) 2772 if (! smi_msg)
2716 continue; 2773 continue;
2717 2774
2718 spin_unlock_irqrestore(&(intf->seq_lock),flags); 2775 spin_unlock_irqrestore(&(intf->seq_lock),flags);
@@ -2743,7 +2800,7 @@ static void ipmi_request_event(void)
2743 int i; 2800 int i;
2744 2801
2745 spin_lock(&interfaces_lock); 2802 spin_lock(&interfaces_lock);
2746 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 2803 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2747 intf = ipmi_interfaces[i]; 2804 intf = ipmi_interfaces[i];
2748 if (intf == NULL) 2805 if (intf == NULL)
2749 continue; 2806 continue;
@@ -2838,28 +2895,30 @@ static void dummy_recv_done_handler(struct ipmi_recv_msg *msg)
2838} 2895}
2839 2896
2840#ifdef CONFIG_IPMI_PANIC_STRING 2897#ifdef CONFIG_IPMI_PANIC_STRING
2841static void event_receiver_fetcher(ipmi_smi_t intf, struct ipmi_smi_msg *msg) 2898static void event_receiver_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
2842{ 2899{
2843 if ((msg->rsp[0] == (IPMI_NETFN_SENSOR_EVENT_RESPONSE << 2)) 2900 if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
2844 && (msg->rsp[1] == IPMI_GET_EVENT_RECEIVER_CMD) 2901 && (msg->msg.netfn == IPMI_NETFN_SENSOR_EVENT_RESPONSE)
2845 && (msg->rsp[2] == IPMI_CC_NO_ERROR)) 2902 && (msg->msg.cmd == IPMI_GET_EVENT_RECEIVER_CMD)
2903 && (msg->msg.data[0] == IPMI_CC_NO_ERROR))
2846 { 2904 {
2847 /* A get event receiver command, save it. */ 2905 /* A get event receiver command, save it. */
2848 intf->event_receiver = msg->rsp[3]; 2906 intf->event_receiver = msg->msg.data[1];
2849 intf->event_receiver_lun = msg->rsp[4] & 0x3; 2907 intf->event_receiver_lun = msg->msg.data[2] & 0x3;
2850 } 2908 }
2851} 2909}
2852 2910
2853static void device_id_fetcher(ipmi_smi_t intf, struct ipmi_smi_msg *msg) 2911static void device_id_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
2854{ 2912{
2855 if ((msg->rsp[0] == (IPMI_NETFN_APP_RESPONSE << 2)) 2913 if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
2856 && (msg->rsp[1] == IPMI_GET_DEVICE_ID_CMD) 2914 && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE)
2857 && (msg->rsp[2] == IPMI_CC_NO_ERROR)) 2915 && (msg->msg.cmd == IPMI_GET_DEVICE_ID_CMD)
2916 && (msg->msg.data[0] == IPMI_CC_NO_ERROR))
2858 { 2917 {
2859 /* A get device id command, save if we are an event 2918 /* A get device id command, save if we are an event
2860 receiver or generator. */ 2919 receiver or generator. */
2861 intf->local_sel_device = (msg->rsp[8] >> 2) & 1; 2920 intf->local_sel_device = (msg->msg.data[6] >> 2) & 1;
2862 intf->local_event_generator = (msg->rsp[8] >> 5) & 1; 2921 intf->local_event_generator = (msg->msg.data[6] >> 5) & 1;
2863 } 2922 }
2864} 2923}
2865#endif 2924#endif
@@ -2903,7 +2962,7 @@ static void send_panic_events(char *str)
2903 recv_msg.done = dummy_recv_done_handler; 2962 recv_msg.done = dummy_recv_done_handler;
2904 2963
2905 /* For every registered interface, send the event. */ 2964 /* For every registered interface, send the event. */
2906 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 2965 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2907 intf = ipmi_interfaces[i]; 2966 intf = ipmi_interfaces[i];
2908 if (intf == NULL) 2967 if (intf == NULL)
2909 continue; 2968 continue;
@@ -2915,12 +2974,12 @@ static void send_panic_events(char *str)
2915 &addr, 2974 &addr,
2916 0, 2975 0,
2917 &msg, 2976 &msg,
2918 NULL, 2977 intf,
2919 &smi_msg, 2978 &smi_msg,
2920 &recv_msg, 2979 &recv_msg,
2921 0, 2980 0,
2922 intf->my_address, 2981 intf->channels[0].address,
2923 intf->my_lun, 2982 intf->channels[0].lun,
2924 0, 1); /* Don't retry, and don't wait. */ 2983 0, 1); /* Don't retry, and don't wait. */
2925 } 2984 }
2926 2985
@@ -2930,7 +2989,7 @@ static void send_panic_events(char *str)
2930 if (!str) 2989 if (!str)
2931 return; 2990 return;
2932 2991
2933 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 2992 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2934 char *p = str; 2993 char *p = str;
2935 struct ipmi_ipmb_addr *ipmb; 2994 struct ipmi_ipmb_addr *ipmb;
2936 int j; 2995 int j;
@@ -2961,12 +3020,12 @@ static void send_panic_events(char *str)
2961 &addr, 3020 &addr,
2962 0, 3021 0,
2963 &msg, 3022 &msg,
2964 NULL, 3023 intf,
2965 &smi_msg, 3024 &smi_msg,
2966 &recv_msg, 3025 &recv_msg,
2967 0, 3026 0,
2968 intf->my_address, 3027 intf->channels[0].address,
2969 intf->my_lun, 3028 intf->channels[0].lun,
2970 0, 1); /* Don't retry, and don't wait. */ 3029 0, 1); /* Don't retry, and don't wait. */
2971 3030
2972 if (intf->local_event_generator) { 3031 if (intf->local_event_generator) {
@@ -2981,12 +3040,12 @@ static void send_panic_events(char *str)
2981 &addr, 3040 &addr,
2982 0, 3041 0,
2983 &msg, 3042 &msg,
2984 NULL, 3043 intf,
2985 &smi_msg, 3044 &smi_msg,
2986 &recv_msg, 3045 &recv_msg,
2987 0, 3046 0,
2988 intf->my_address, 3047 intf->channels[0].address,
2989 intf->my_lun, 3048 intf->channels[0].lun,
2990 0, 1); /* no retry, and no wait. */ 3049 0, 1); /* no retry, and no wait. */
2991 } 3050 }
2992 intf->null_user_handler = NULL; 3051 intf->null_user_handler = NULL;
@@ -2996,7 +3055,7 @@ static void send_panic_events(char *str)
2996 be zero, and it must not be my address. */ 3055 be zero, and it must not be my address. */
2997 if (((intf->event_receiver & 1) == 0) 3056 if (((intf->event_receiver & 1) == 0)
2998 && (intf->event_receiver != 0) 3057 && (intf->event_receiver != 0)
2999 && (intf->event_receiver != intf->my_address)) 3058 && (intf->event_receiver != intf->channels[0].address))
3000 { 3059 {
3001 /* The event receiver is valid, send an IPMB 3060 /* The event receiver is valid, send an IPMB
3002 message. */ 3061 message. */
@@ -3031,7 +3090,7 @@ static void send_panic_events(char *str)
3031 data[0] = 0; 3090 data[0] = 0;
3032 data[1] = 0; 3091 data[1] = 0;
3033 data[2] = 0xf0; /* OEM event without timestamp. */ 3092 data[2] = 0xf0; /* OEM event without timestamp. */
3034 data[3] = intf->my_address; 3093 data[3] = intf->channels[0].address;
3035 data[4] = j++; /* sequence # */ 3094 data[4] = j++; /* sequence # */
3036 /* Always give 11 bytes, so strncpy will fill 3095 /* Always give 11 bytes, so strncpy will fill
3037 it with zeroes for me. */ 3096 it with zeroes for me. */
@@ -3043,12 +3102,12 @@ static void send_panic_events(char *str)
3043 &addr, 3102 &addr,
3044 0, 3103 0,
3045 &msg, 3104 &msg,
3046 NULL, 3105 intf,
3047 &smi_msg, 3106 &smi_msg,
3048 &recv_msg, 3107 &recv_msg,
3049 0, 3108 0,
3050 intf->my_address, 3109 intf->channels[0].address,
3051 intf->my_lun, 3110 intf->channels[0].lun,
3052 0, 1); /* no retry, and no wait. */ 3111 0, 1); /* no retry, and no wait. */
3053 } 3112 }
3054 } 3113 }
@@ -3070,7 +3129,7 @@ static int panic_event(struct notifier_block *this,
3070 has_paniced = 1; 3129 has_paniced = 1;
3071 3130
3072 /* For every registered interface, set it to run to completion. */ 3131 /* For every registered interface, set it to run to completion. */
3073 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 3132 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
3074 intf = ipmi_interfaces[i]; 3133 intf = ipmi_interfaces[i];
3075 if (intf == NULL) 3134 if (intf == NULL)
3076 continue; 3135 continue;
@@ -3099,9 +3158,9 @@ static int ipmi_init_msghandler(void)
3099 return 0; 3158 return 0;
3100 3159
3101 printk(KERN_INFO "ipmi message handler version " 3160 printk(KERN_INFO "ipmi message handler version "
3102 IPMI_MSGHANDLER_VERSION "\n"); 3161 IPMI_DRIVER_VERSION "\n");
3103 3162
3104 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 3163 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
3105 ipmi_interfaces[i] = NULL; 3164 ipmi_interfaces[i] = NULL;
3106 } 3165 }
3107 3166
@@ -3171,6 +3230,9 @@ module_exit(cleanup_ipmi);
3171 3230
3172module_init(ipmi_init_msghandler_mod); 3231module_init(ipmi_init_msghandler_mod);
3173MODULE_LICENSE("GPL"); 3232MODULE_LICENSE("GPL");
3233MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
3234MODULE_DESCRIPTION("Incoming and outgoing message routing for an IPMI interface.");
3235MODULE_VERSION(IPMI_DRIVER_VERSION);
3174 3236
3175EXPORT_SYMBOL(ipmi_create_user); 3237EXPORT_SYMBOL(ipmi_create_user);
3176EXPORT_SYMBOL(ipmi_destroy_user); 3238EXPORT_SYMBOL(ipmi_destroy_user);