34 #include <linux/module.h>
35 #include <linux/errno.h>
36 #include <linux/poll.h>
37 #include <linux/sched.h>
41 #include <linux/slab.h>
42 #include <linux/ipmi.h>
50 #define PFX "IPMI message handler: "
52 #define IPMI_DRIVER_VERSION "39.2"
55 static int ipmi_init_msghandler(
void);
56 static void smi_recv_tasklet(
unsigned long);
66 #define IPMI_MAINTENANCE_MODE_TIMEOUT 30000
68 #define MAX_EVENTS_IN_QUEUE 25
74 #define MAX_MSG_TIMEOUT 60000
144 #define STORE_SEQ_IN_MSGID(seq, seqid) (((seq&0xff)<<26) | (seqid&0x3ffffff))
146 #define GET_SEQ_FROM_MSGID(msgid, seq, seqid) \
148 seq = ((msgid >> 26) & 0x3f); \
149 seqid = (msgid & 0x3fffff); \
152 #define NEXT_SEQID(seqid) (((seqid) + 1) & 0x3fffff)
171 #ifdef CONFIG_PROC_FS
172 struct ipmi_proc_entry {
174 struct ipmi_proc_entry *
next;
303 #define IPMI_IPMB_NUM_SEQ 64
304 #define IPMI_MAX_CHANNELS 16
340 #ifdef CONFIG_PROC_FS
342 struct mutex proc_entry_lock;
343 struct ipmi_proc_entry *proc_entries;
432 #define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev)
455 #define ipmi_inc_stat(intf, stat) \
456 atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
457 #define ipmi_get_stat(intf, stat) \
458 ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
475 static void free_recv_msg_list(
struct list_head *
q)
485 static void free_smi_msg_list(
struct list_head *
q)
491 ipmi_free_smi_msg(msg);
511 INIT_LIST_HEAD(&
list);
512 list_splice_init_rcu(&intf->
cmd_rcvrs, &
list, synchronize_rcu);
525 static void intf_free(
struct kref *ref)
529 clean_up_interface_data(intf);
563 list_add(&watcher->
link, &smi_watchers);
603 call_smi_watchers(
int i,
struct device *
dev)
608 if (try_module_get(w->
owner)) {
610 module_put(w->
owner);
629 return (smi_addr1->
lun == smi_addr2->
lun);
632 if (is_ipmb_addr(addr1) || is_ipmb_bcast_addr(addr1)) {
639 && (ipmb_addr1->
lun == ipmb_addr2->
lun));
642 if (is_lan_addr(addr1)) {
652 && (lan_addr1->
lun == lan_addr2->
lun));
674 if (is_ipmb_addr(addr) || is_ipmb_bcast_addr(addr)) {
680 if (is_lan_addr(addr)) {
732 msg->
msg.data_len = 1;
734 deliver_response(msg);
744 unsigned long timeout,
754 i = (i+1)%IPMI_IPMB_NUM_SEQ) {
774 intf->
curr_seq = (i+1)%IPMI_IPMB_NUM_SEQ;
800 if (seq >= IPMI_IPMB_NUM_SEQ)
807 if ((msg->
addr.channel == channel) && (msg->
msg.cmd == cmd)
808 && (msg->
msg.netfn == netfn)
809 && (ipmi_addr_equal(addr, &(msg->
addr)))) {
815 spin_unlock_irqrestore(&(intf->
seq_lock), flags);
822 static int intf_start_seq_timer(
ipmi_smi_t intf,
839 && (intf->
seq_table[seq].seqid == seqid)) {
844 spin_unlock_irqrestore(&(intf->
seq_lock), flags);
869 && (intf->
seq_table[seq].seqid == seqid)) {
876 spin_unlock_irqrestore(&(intf->
seq_lock), flags);
879 deliver_err_response(msg, err);
911 rv = ipmi_init_msghandler();
928 list_for_each_entry_rcu(intf, &ipmi_interfaces,
link) {
946 if (!try_module_get(intf->
handlers->owner)) {
967 list_add_rcu(&new_user->
link, &intf->
users);
968 spin_unlock_irqrestore(&intf->
seq_lock, flags);
973 kref_put(&intf->
refcount, intf_free);
988 list_for_each_entry_rcu(intf, &ipmi_interfaces,
link) {
1008 static void free_user(
struct kref *ref)
1018 unsigned long flags;
1026 list_del_rcu(&user->
link);
1030 && (intf->
seq_table[i].recv_msg->user == user)) {
1035 spin_unlock_irqrestore(&intf->
seq_lock, flags);
1045 if (rcvr->
user == user) {
1046 list_del_rcu(&rcvr->
link);
1067 kref_put(&intf->
refcount, intf_free);
1069 kref_put(&user->
refcount, free_user);
1076 unsigned char *major,
1077 unsigned char *minor)
1085 unsigned int channel,
1096 unsigned int channel,
1107 unsigned int channel,
1118 unsigned int channel,
1131 unsigned long flags;
1141 static void maintenance_mode_update(
ipmi_smi_t intf)
1143 if (intf->
handlers->set_maintenance_mode)
1144 intf->
handlers->set_maintenance_mode(
1151 unsigned long flags;
1178 maintenance_mode_update(intf);
1189 unsigned long flags;
1194 INIT_LIST_HEAD(&msgs);
1209 list_move_tail(&msg->
link, &msgs);
1218 spin_unlock_irqrestore(&intf->
events_lock, flags);
1223 deliver_response(msg);
1231 spin_unlock_irqrestore(&intf->
events_lock, flags);
1238 unsigned char netfn,
1245 if ((rcvr->
netfn == netfn) && (rcvr->
cmd == cmd)
1246 && (rcvr->
chans & (1 << chan)))
1252 static int is_cmd_rcvr_exclusive(
ipmi_smi_t intf,
1253 unsigned char netfn,
1260 if ((rcvr->
netfn == netfn) && (rcvr->
cmd == cmd)
1261 && (rcvr->
chans & chans))
1268 unsigned char netfn,
1287 if (!is_cmd_rcvr_exclusive(intf, netfn, cmd, chans)) {
1304 unsigned char netfn,
1315 if (((1 << i) & chans) == 0)
1317 rcvr = find_cmd_rcvr(intf, netfn, cmd, i);
1320 if (rcvr->
user == user) {
1322 rcvr->
chans &= ~chans;
1323 if (rcvr->
chans == 0) {
1324 list_del_rcu(&rcvr->
link);
1341 static unsigned char
1342 ipmb_checksum(
unsigned char *
data,
int size)
1344 unsigned char csum = 0;
1346 for (; size > 0; size--, data++)
1352 static inline void format_ipmb_msg(
struct ipmi_smi_msg *smi_msg,
1356 unsigned char ipmb_seq,
1358 unsigned char source_address,
1359 unsigned char source_lun)
1368 smi_msg->
data[3] = 0;
1370 smi_msg->
data[i+4] = (msg->
netfn << 2) | (ipmb_addr->
lun & 0x3);
1371 smi_msg->
data[i+5] = ipmb_checksum(&(smi_msg->
data[i+3]), 2);
1372 smi_msg->
data[i+6] = source_address;
1373 smi_msg->
data[i+7] = (ipmb_seq << 2) | source_lun;
1374 smi_msg->
data[i+8] = msg->
cmd;
1384 = ipmb_checksum(&(smi_msg->
data[i+6]),
1393 smi_msg->
msgid = msgid;
1396 static inline void format_lan_msg(
struct ipmi_smi_msg *smi_msg,
1400 unsigned char ipmb_seq,
1401 unsigned char source_lun)
1409 smi_msg->
data[5] = (msg->
netfn << 2) | (lan_addr->
lun & 0x3);
1410 smi_msg->
data[6] = ipmb_checksum(&(smi_msg->
data[4]), 2);
1412 smi_msg->
data[8] = (ipmb_seq << 2) | source_lun;
1423 = ipmb_checksum(&(smi_msg->
data[7]),
1432 smi_msg->
msgid = msgid;
1446 void *user_msg_data,
1450 unsigned char source_address,
1451 unsigned char source_lun,
1453 unsigned int retry_time_ms)
1458 unsigned long flags;
1463 recv_msg = supplied_recv;
1465 recv_msg = ipmi_alloc_recv_msg();
1466 if (recv_msg ==
NULL)
1475 if (smi_msg ==
NULL) {
1501 if (msg->
netfn & 1) {
1508 if (smi_addr->
lun > 3) {
1514 memcpy(&recv_msg->
addr, smi_addr,
sizeof(*smi_addr));
1539 maintenance_mode_update(intf);
1551 smi_msg->
data[0] = (msg->
netfn << 2) | (smi_addr->
lun & 0x3);
1553 smi_msg->
msgid = msgid;
1559 }
else if (is_ipmb_addr(addr) || is_ipmb_bcast_addr(addr)) {
1561 unsigned char ipmb_seq;
1596 if (retry_time_ms == 0)
1597 retry_time_ms = 1000;
1610 if (ipmb_addr->
lun > 3) {
1616 memcpy(&recv_msg->
addr, ipmb_addr,
sizeof(*ipmb_addr));
1618 if (recv_msg->
msg.netfn & 0x1) {
1624 format_ipmb_msg(smi_msg, msg, ipmb_addr, msgid,
1626 source_address, source_lun);
1642 rv = intf_next_seq(intf,
1654 spin_unlock_irqrestore(&(intf->
seq_lock),
1666 format_ipmb_msg(smi_msg, msg, ipmb_addr,
1668 ipmb_seq, broadcast,
1669 source_address, source_lun);
1688 spin_unlock_irqrestore(&(intf->
seq_lock), flags);
1690 }
else if (is_lan_addr(addr)) {
1692 unsigned char ipmb_seq;
1713 if (retry_time_ms == 0)
1714 retry_time_ms = 1000;
1724 if (lan_addr->
lun > 3) {
1730 memcpy(&recv_msg->
addr, lan_addr,
sizeof(*lan_addr));
1732 if (recv_msg->
msg.netfn & 0x1) {
1738 format_lan_msg(smi_msg, msg, lan_addr, msgid,
1755 rv = intf_next_seq(intf,
1767 spin_unlock_irqrestore(&(intf->
seq_lock),
1779 format_lan_msg(smi_msg, msg, lan_addr,
1781 ipmb_seq, source_lun);
1800 spin_unlock_irqrestore(&(intf->
seq_lock), flags);
1812 for (m = 0; m < smi_msg->
data_size; m++)
1825 ipmi_free_smi_msg(smi_msg);
1832 unsigned char *
saddr,
1846 void *user_msg_data,
1849 unsigned int retry_time_ms)
1856 rv = check_addr(user->
intf, addr, &saddr, &lun);
1859 return i_ipmi_request(user,
1878 void *user_msg_data,
1883 unsigned char saddr = 0, lun = 0;
1888 rv = check_addr(user->
intf, addr, &saddr, &lun);
1891 return i_ipmi_request(user,
1906 #ifdef CONFIG_PROC_FS
1907 static int smi_ipmb_proc_show(
struct seq_file *m,
void *
v)
1920 return single_open(file, smi_ipmb_proc_show, PDE(inode)->data);
1924 .
open = smi_ipmb_proc_open,
1930 static int smi_version_proc_show(
struct seq_file *m,
void *v)
1939 static int smi_version_proc_open(
struct inode *inode,
struct file *file)
1941 return single_open(file, smi_version_proc_show, PDE(inode)->data);
1945 .
open = smi_version_proc_open,
1951 static int smi_stats_proc_show(
struct seq_file *m,
void *v)
1959 seq_printf(m,
"handled_local_responses: %u\n",
1961 seq_printf(m,
"unhandled_local_responses: %u\n",
1965 seq_printf(m,
"sent_ipmb_command_errs: %u\n",
1967 seq_printf(m,
"retransmitted_ipmb_commands: %u\n",
1969 seq_printf(m,
"timed_out_ipmb_commands: %u\n",
1971 seq_printf(m,
"timed_out_ipmb_broadcasts: %u\n",
1975 seq_printf(m,
"handled_ipmb_responses: %u\n",
1977 seq_printf(m,
"invalid_ipmb_responses: %u\n",
1979 seq_printf(m,
"unhandled_ipmb_responses: %u\n",
1985 seq_printf(m,
"retransmitted_lan_commands: %u\n",
1987 seq_printf(m,
"timed_out_lan_commands: %u\n",
1995 seq_printf(m,
"unhandled_lan_responses: %u\n",
2007 seq_printf(m,
"failed rexmit LAN msgs: %u\n",
2009 seq_printf(m,
"failed rexmit IPMB msgs: %u\n",
2014 static int smi_stats_proc_open(
struct inode *inode,
struct file *file)
2016 return single_open(file, smi_stats_proc_show, PDE(inode)->data);
2020 .
open = smi_stats_proc_open,
2032 #ifdef CONFIG_PROC_FS
2034 struct ipmi_proc_entry *
entry;
2045 strcpy(entry->name, name);
2055 entry->next = smi->proc_entries;
2056 smi->proc_entries =
entry;
2065 static int add_proc_entries(
ipmi_smi_t smi,
int num)
2069 #ifdef CONFIG_PROC_FS
2077 &smi_stats_proc_ops,
2087 &smi_version_proc_ops,
2094 static void remove_proc_entries(
ipmi_smi_t smi)
2096 #ifdef CONFIG_PROC_FS
2097 struct ipmi_proc_entry *
entry;
2100 while (smi->proc_entries) {
2101 entry = smi->proc_entries;
2102 smi->proc_entries = entry->next;
2113 static int __find_bmc_guid(
struct device *dev,
void *data)
2115 unsigned char *
id =
data;
2121 unsigned char *
guid)
2137 static int __find_bmc_prod_dev_id(
struct device *dev,
void *data)
2146 static struct bmc_device *ipmi_find_bmc_prod_dev_id(
2169 return snprintf(buf, 10,
"%u\n", bmc->
id.device_id);
2179 (bmc->
id.device_revision & 0x80) >> 7);
2188 bmc->
id.device_revision & 0x0F);
2197 return snprintf(buf, 20,
"%u.%x\n", bmc->
id.firmware_revision_1,
2198 bmc->
id.firmware_revision_2);
2207 return snprintf(buf, 20,
"%u.%u\n",
2218 return snprintf(buf, 10,
"0x%02x\n",
2219 bmc->
id.additional_device_support);
2228 return snprintf(buf, 20,
"0x%6.6x\n", bmc->
id.manufacturer_id);
2237 return snprintf(buf, 10,
"0x%4.4x\n", bmc->
id.product_id);
2246 return snprintf(buf, 21,
"0x%02x 0x%02x 0x%02x 0x%02x\n",
2247 bmc->
id.aux_firmware_revision[3],
2248 bmc->
id.aux_firmware_revision[2],
2249 bmc->
id.aux_firmware_revision[1],
2250 bmc->
id.aux_firmware_revision[0]);
2258 return snprintf(buf, 100,
"%Lx%Lx\n",
2259 (
long long) bmc->
guid[0],
2260 (
long long) bmc->
guid[8]);
2263 static void remove_files(
struct bmc_device *bmc)
2285 if (bmc->
id.aux_firmware_revision_set)
2294 cleanup_bmc_device(
struct kref *ref)
2305 static void ipmi_bmc_unregister(
ipmi_smi_t intf)
2321 kref_put(&bmc->
refcount, cleanup_bmc_device);
2326 static int create_files(
struct bmc_device *bmc)
2412 if (bmc->
id.aux_firmware_revision_set) {
2428 if (bmc->
id.aux_firmware_revision_set)
2459 static int ipmi_bmc_register(
ipmi_smi_t intf,
int ifnum,
2460 const char *sysfs_name)
2475 old_bmc = ipmi_find_bmc_guid(&ipmidriver.
driver, bmc->
guid);
2477 old_bmc = ipmi_find_bmc_prod_dev_id(&ipmidriver.
driver,
2487 intf->
bmc = old_bmc;
2494 "ipmi: interfacing existing BMC (man_id: 0x%6.6x,"
2495 " prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n",
2496 bmc->
id.manufacturer_id,
2501 unsigned char orig_dev_id = bmc->
id.device_id;
2502 int warn_printed = 0;
2505 "ipmi_bmc.%4.4x", bmc->
id.product_id);
2507 while (ipmi_find_bmc_prod_dev_id(&ipmidriver.
driver,
2509 bmc->
id.device_id)) {
2510 if (!warn_printed) {
2512 "This machine has two different BMCs"
2513 " with the same product id and device"
2514 " id. This is an error in the"
2515 " firmware, but incrementing the"
2516 " device id to work around the problem."
2517 " Prod ID = 0x%x, Dev ID = 0x%x\n",
2518 bmc->
id.product_id, bmc->
id.device_id);
2521 bmc->
id.device_id++;
2522 if (bmc->
id.device_id == orig_dev_id) {
2524 "Out of device ids!\n");
2534 " Unable to allocate platform device\n");
2537 bmc->
dev->dev.driver = &ipmidriver.
driver;
2548 " Unable to register bmc device: %d\n",
2557 rv = create_files(bmc);
2567 "prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n",
2568 bmc->
id.manufacturer_id,
2581 "ipmi_msghandler: allocate link to BMC: %d\n",
2592 "ipmi_msghandler: Unable to create bmc symlink: %d\n",
2597 size =
snprintf(dummy, 0,
"ipmi%d", ifnum);
2604 "ipmi_msghandler: allocate link from BMC: %d\n",
2619 " Unable to create symlink to bmc: %d\n",
2627 ipmi_bmc_unregister(intf);
2645 return i_ipmi_request(
NULL,
2668 if (msg->
msg.data[0] != 0) {
2670 intf->
bmc->guid_set = 0;
2674 if (msg->
msg.data_len < 17) {
2675 intf->
bmc->guid_set = 0;
2677 "guid_handler: The GUID response from the BMC was too"
2678 " short, it was %d but should have been 17. Assuming"
2679 " GUID is not available.\n",
2685 intf->
bmc->guid_set = 1;
2695 intf->
bmc->guid_set = 0x2;
2697 rv = send_guid_cmd(intf, 0);
2700 intf->
bmc->guid_set = 0;
2706 send_channel_info_cmd(
ipmi_smi_t intf,
int chan)
2709 unsigned char data[1];
2721 return i_ipmi_request(
NULL,
2745 if (msg->
msg.data[0] != 0) {
2767 if (msg->
msg.data_len < 4) {
2772 intf->
channels[chan].medium = msg->
msg.data[2] & 0x7f;
2773 intf->
channels[chan].protocol = msg->
msg.data[3] & 0x1f;
2788 "Error sending channel information: %d\n",
2801 handle_new_recv_msgs(intf);
2806 ipmi_poll(user->
intf);
2814 const char *sysfs_name,
2828 rv = ipmi_init_msghandler();
2859 if (slave_addr != 0)
2861 INIT_LIST_HEAD(&intf->
users);
2870 #ifdef CONFIG_PROC_FS
2877 (
unsigned long) intf);
2878 atomic_set(&intf->watchdog_pretimeouts_to_deliver, 0);
2880 INIT_LIST_HEAD(&intf->waiting_events);
2881 intf->waiting_events_count = 0;
2884 INIT_LIST_HEAD(&intf->cmd_rcvrs);
2889 intf->proc_dir =
NULL;
2895 link = &ipmi_interfaces;
2896 list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) {
2898 link = &tintf->
link;
2905 list_add_rcu(&intf->link, &ipmi_interfaces);
2907 list_add_tail_rcu(&intf->link, link);
2915 if ((intf->ipmi_version_major > 1)
2916 || ((intf->ipmi_version_major == 1)
2917 && (intf->ipmi_version_minor >= 5))) {
2922 intf->null_user_handler = channel_handler;
2923 intf->curr_channel = 0;
2924 rv = send_channel_info_cmd(intf, 0);
2930 intf->curr_channel >= IPMI_MAX_CHANNELS);
2931 intf->null_user_handler =
NULL;
2940 rv = add_proc_entries(intf, i);
2942 rv = ipmi_bmc_register(intf, i, sysfs_name);
2947 remove_proc_entries(intf);
2948 intf->handlers =
NULL;
2949 list_del_rcu(&intf->link);
2953 kref_put(&intf->refcount, intf_free);
2964 call_smi_watchers(i, intf->si_dev);
2972 static void cleanup_smi_msgs(
ipmi_smi_t intf)
2991 ipmi_bmc_unregister(intf);
2997 list_del_rcu(&intf->
link);
3001 cleanup_smi_msgs(intf);
3003 remove_proc_entries(intf);
3013 kref_put(&intf->
refcount, intf_free);
3018 static int handle_ipmb_get_msg_rsp(
ipmi_smi_t intf,
3034 if (msg->
rsp[2] != 0) {
3042 ipmb_addr.
lun = msg->
rsp[7] & 3;
3048 if (intf_find_seq(intf,
3052 (msg->
rsp[4] >> 2) & (~1),
3071 recv_msg->
msg.netfn = msg->
rsp[4] >> 2;
3076 deliver_response(recv_msg);
3081 static int handle_ipmb_get_msg_cmd(
ipmi_smi_t intf,
3086 unsigned char netfn;
3100 if (msg->
rsp[2] != 0) {
3105 netfn = msg->
rsp[4] >> 2;
3107 chan = msg->
rsp[3] & 0xf;
3110 rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
3126 msg->
data[4] = ((netfn + 1) << 2) | (msg->
rsp[7] & 0x3);
3127 msg->
data[5] = ipmb_checksum(&(msg->
data[3]), 2);
3130 msg->
data[7] = (msg->
rsp[7] & 0xfc) | (msg->
rsp[4] & 0x3);
3133 msg->
data[10] = ipmb_checksum(&(msg->
data[6]), 4);
3139 printk(
"Invalid command:");
3161 recv_msg = ipmi_alloc_recv_msg();
3169 kref_put(&user->
refcount, free_user);
3175 ipmb_addr->
lun = msg->
rsp[7] & 3;
3182 recv_msg->
user = user;
3184 recv_msg->
msgid = msg->
rsp[7] >> 2;
3185 recv_msg->
msg.netfn = msg->
rsp[4] >> 2;
3186 recv_msg->
msg.cmd = msg->
rsp[8];
3197 deliver_response(recv_msg);
3204 static int handle_lan_get_msg_rsp(
ipmi_smi_t intf,
3221 if (msg->
rsp[2] != 0) {
3232 lan_addr.
lun = msg->
rsp[9] & 3;
3238 if (intf_find_seq(intf,
3242 (msg->
rsp[6] >> 2) & (~1),
3261 recv_msg->
msg.netfn = msg->
rsp[6] >> 2;
3266 deliver_response(recv_msg);
3271 static int handle_lan_get_msg_cmd(
ipmi_smi_t intf,
3276 unsigned char netfn;
3289 if (msg->
rsp[2] != 0) {
3294 netfn = msg->
rsp[6] >> 2;
3296 chan = msg->
rsp[3] & 0xf;
3299 rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
3320 recv_msg = ipmi_alloc_recv_msg();
3327 kref_put(&user->
refcount, free_user);
3335 lan_addr->
lun = msg->
rsp[9] & 3;
3343 recv_msg->
user = user;
3345 recv_msg->
msgid = msg->
rsp[9] >> 2;
3346 recv_msg->
msg.netfn = msg->
rsp[6] >> 2;
3347 recv_msg->
msg.cmd = msg->
rsp[10];
3358 deliver_response(recv_msg);
3371 static int handle_oem_get_msg_cmd(
ipmi_smi_t intf,
3376 unsigned char netfn;
3393 if (msg->
rsp[2] != 0) {
3402 netfn = msg->
rsp[0] >> 2;
3404 chan = msg->
rsp[3] & 0xf;
3407 rcvr = find_cmd_rcvr(intf, netfn, cmd, chan);
3429 recv_msg = ipmi_alloc_recv_msg();
3437 kref_put(&user->
refcount, free_user);
3449 smi_addr->
lun = msg->
rsp[0] & 3;
3454 recv_msg->
msg.netfn = msg->
rsp[0] >> 2;
3455 recv_msg->
msg.cmd = msg->
rsp[1];
3466 deliver_response(recv_msg);
3473 static void copy_event_into_recv_msg(
struct ipmi_recv_msg *recv_msg,
3478 recv_msg->
msgid = 0;
3482 smi_addr->
lun = msg->
rsp[0] & 3;
3484 recv_msg->
msg.netfn = msg->
rsp[0] >> 2;
3485 recv_msg->
msg.cmd = msg->
rsp[1];
3491 static int handle_read_event_rsp(
ipmi_smi_t intf,
3498 int deliver_count = 0;
3499 unsigned long flags;
3507 if (msg->
rsp[2] != 0) {
3512 INIT_LIST_HEAD(&msgs);
3523 list_for_each_entry_rcu(user, &intf->
users,
link) {
3524 if (!user->gets_events)
3527 recv_msg = ipmi_alloc_recv_msg();
3546 copy_event_into_recv_msg(recv_msg, msg);
3548 kref_get(&user->refcount);
3553 if (deliver_count) {
3557 deliver_response(recv_msg);
3564 recv_msg = ipmi_alloc_recv_msg();
3575 copy_event_into_recv_msg(recv_msg, msg);
3584 " incoming events\n");
3589 spin_unlock_irqrestore(&(intf->
events_lock), flags);
3603 "IPMI message received with no owner. This\n"
3604 "could be because of a malformed message, or\n"
3605 "because of a hardware error. Contact your\n"
3606 "hardware vender for assistance\n");
3610 user = recv_msg->
user;
3612 if (user && !user->
valid) {
3626 smi_addr->
lun = msg->
rsp[0] & 3;
3627 recv_msg->
msg.netfn = msg->
rsp[0] >> 2;
3628 recv_msg->
msg.cmd = msg->
rsp[1];
3634 deliver_response(recv_msg);
3645 static int handle_one_recv_msg(
ipmi_smi_t intf,
3654 for (m = 0; m < msg->
rsp_size; m++)
3661 " for netfn %x cmd %x, got %d bytes\n",
3665 msg->
rsp[0] = msg->
data[0] | (1 << 2);
3669 }
else if (((msg->
rsp[0] >> 2) != ((msg->
data[0] >> 2) | 1))
3670 || (msg->
rsp[1] != msg->
data[1])) {
3676 " expected netfn %x cmd %x, got netfn %x cmd %x\n",
3677 (msg->
data[0] >> 2) | 1, msg->
data[1],
3678 msg->
rsp[0] >> 2, msg->
rsp[1]);
3681 msg->
rsp[0] = msg->
data[0] | (1 << 2);
3701 chan = msg->
data[2] & 0x0f;
3702 if (chan >= IPMI_MAX_CHANNELS)
3715 recv_msg->
msg.data_len = 1;
3717 deliver_response(recv_msg);
3721 chan = msg->
rsp[3] & 0xf;
3722 if (chan >= IPMI_MAX_CHANNELS) {
3739 switch (intf->
channels[chan].medium) {
3741 if (msg->
rsp[4] & 0x04) {
3746 requeue = handle_ipmb_get_msg_rsp(intf, msg);
3752 requeue = handle_ipmb_get_msg_cmd(intf, msg);
3758 if (msg->
rsp[6] & 0x04) {
3763 requeue = handle_lan_get_msg_rsp(intf, msg);
3769 requeue = handle_lan_get_msg_cmd(intf, msg);
3780 requeue = handle_oem_get_msg_cmd(intf, msg);
3793 requeue = handle_read_event_rsp(intf, msg);
3796 requeue = handle_bmc_rsp(intf, msg);
3806 static void handle_new_recv_msgs(
ipmi_smi_t intf)
3809 unsigned long flags = 0;
3814 if (!run_to_completion)
3820 if (!run_to_completion)
3822 rv = handle_one_recv_msg(intf, smi_msg);
3823 if (!run_to_completion)
3827 ipmi_free_smi_msg(smi_msg);
3828 }
else if (rv < 0) {
3839 if (!run_to_completion)
3850 list_for_each_entry_rcu(user, &intf->
users,
link) {
3851 if (user->
handler->ipmi_watchdog_pretimeout)
3852 user->
handler->ipmi_watchdog_pretimeout(
3859 static void smi_recv_tasklet(
unsigned long val)
3868 unsigned long flags = 0;
3869 int run_to_completion;
3894 int chan = msg->
rsp[3] & 0xf;
3897 if (chan >= IPMI_MAX_CHANNELS)
3899 else if ((intf->
channels[chan].medium
3906 intf_err_seq(intf, msg->
msgid, msg->
rsp[2]);
3909 intf_start_seq_timer(intf, msg->
msgid);
3911 ipmi_free_smi_msg(msg);
3920 if (!run_to_completion)
3923 if (!run_to_completion)
3941 unsigned char seq,
long seqid)
3959 for (m = 0; m < smi_msg->
data_size; m++)
3968 struct list_head *timeouts,
long timeout_period,
3969 int slot,
unsigned long *flags)
3980 ent->
timeout -= timeout_period;
3991 else if (is_lan_addr(&ent->
recv_msg->addr))
4005 smi_msg = smi_from_recv_msg(intf, ent->
recv_msg, slot,
4008 if (is_lan_addr(&ent->
recv_msg->addr))
4010 dropped_rexmit_lan_commands);
4013 dropped_rexmit_ipmb_commands);
4017 spin_unlock_irqrestore(&intf->
seq_lock, *flags);
4028 if (is_lan_addr(&ent->
recv_msg->addr))
4030 retransmitted_lan_commands);
4033 retransmitted_ipmb_commands);
4038 ipmi_free_smi_msg(smi_msg);
4044 static void ipmi_timeout_handler(
long timeout_period)
4049 unsigned long flags;
4053 list_for_each_entry_rcu(intf, &ipmi_interfaces,
link) {
4061 INIT_LIST_HEAD(&timeouts);
4064 check_msg_timeout(intf, &(intf->
seq_table[i]),
4065 &timeouts, timeout_period, i,
4067 spin_unlock_irqrestore(&intf->
seq_lock, flags);
4080 if (intf->auto_maintenance_timeout > 0) {
4088 maintenance_mode_update(intf);
4098 static void ipmi_request_event(
void)
4108 list_for_each_entry_rcu(intf, &ipmi_interfaces,
link) {
4123 #define IPMI_TIMEOUT_TIME 1000
4126 #define IPMI_TIMEOUT_JIFFIES ((IPMI_TIMEOUT_TIME * HZ) / 1000)
4134 #define IPMI_REQUEST_EV_TIME (1000 / (IPMI_TIMEOUT_TIME))
4139 static void ipmi_timeout(
unsigned long data)
4145 if (ticks_to_req_ev == 0) {
4146 ipmi_request_event();
4171 rv->
done = free_smi_msg;
4192 rv->
done = free_recv_msg;
4206 #ifdef CONFIG_IPMI_PANIC_EVENT
4210 static void dummy_smi_done_handler(
struct ipmi_smi_msg *msg)
4215 static void dummy_recv_done_handler(
struct ipmi_recv_msg *msg)
4223 static void ipmi_panic_request_and_wait(
ipmi_smi_t intf,
4231 smi_msg.
done = dummy_smi_done_handler;
4232 recv_msg.
done = dummy_recv_done_handler;
4234 rv = i_ipmi_request(
NULL,
4252 #ifdef CONFIG_IPMI_PANIC_STRING
4281 static void send_panic_events(
char *
str)
4285 unsigned char data[16];
4316 list_for_each_entry_rcu(intf, &ipmi_interfaces,
link) {
4317 if (!intf->handlers)
4321 intf->run_to_completion = 1;
4323 intf->handlers->set_run_to_completion(intf->send_info, 1);
4324 ipmi_panic_request_and_wait(intf, &addr, &msg);
4327 #ifdef CONFIG_IPMI_PANIC_STRING
4336 list_for_each_entry_rcu(intf, &ipmi_interfaces,
link) {
4341 if (intf->intf_num == -1)
4362 intf->local_sel_device = 0;
4363 intf->local_event_generator = 0;
4364 intf->event_receiver = 0;
4371 intf->null_user_handler = device_id_fetcher;
4372 ipmi_panic_request_and_wait(intf, &addr, &msg);
4374 if (intf->local_event_generator) {
4380 intf->null_user_handler = event_receiver_fetcher;
4381 ipmi_panic_request_and_wait(intf, &addr, &msg);
4383 intf->null_user_handler =
NULL;
4390 if (((intf->event_receiver & 1) == 0)
4391 && (intf->event_receiver != 0)
4392 && (intf->event_receiver != intf->channels[0].address)) {
4400 ipmb->
lun = intf->event_receiver_lun;
4402 }
else if (intf->local_sel_device) {
4429 data[3] = intf->channels[0].address;
4438 ipmi_panic_request_and_wait(intf, &addr, &msg);
4445 static int has_panicked;
4448 unsigned long event,
4458 list_for_each_entry_rcu(intf, &ipmi_interfaces,
link) {
4467 #ifdef CONFIG_IPMI_PANIC_EVENT
4468 send_panic_events(ptr);
4475 .notifier_call = panic_event,
4480 static int ipmi_init_msghandler(
void)
4496 #ifdef CONFIG_PROC_FS
4498 if (!proc_ipmi_root) {
4515 static int __init ipmi_init_msghandler_mod(
void)
4517 ipmi_init_msghandler();
4521 static void __exit cleanup_ipmi(
void)
4543 #ifdef CONFIG_PROC_FS