From: Andrew Morton commit 40112ae7504745799e75ef418057f0d2cb745050 Author: Corey Minyard Date: Tue Apr 21 12:24:03 2009 -0700 ipmi: test for event buffer before using The IPMI driver would attempt to use the event buffer even if that didn't exist on the BMC. This patch modified the IPMI driver to check for the event buffer's existence before trying to use it. Signed-off-by: Corey Minyard Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Andrew Morton --- drivers/char/ipmi/ipmi_si_intf.c | 148 +++++------------------------ include/linux/ipmi_msgdefs.h | 6 - 2 files changed, 29 insertions(+), 125 deletions(-) diff -puN drivers/char/ipmi/ipmi_si_intf.c~revert-3 drivers/char/ipmi/ipmi_si_intf.c --- a/drivers/char/ipmi/ipmi_si_intf.c~revert-3 +++ a/drivers/char/ipmi/ipmi_si_intf.c @@ -82,6 +82,12 @@ #define SI_SHORT_TIMEOUT_USEC 250 /* .25ms when the SM request a short timeout */ +/* Bit for BMC global enables. */ +#define IPMI_BMC_RCV_MSG_INTR 0x01 +#define IPMI_BMC_EVT_MSG_INTR 0x02 +#define IPMI_BMC_EVT_MSG_BUFF 0x04 +#define IPMI_BMC_SYS_LOG 0x08 + enum si_intf_state { SI_NORMAL, SI_GETTING_FLAGS, @@ -214,9 +220,6 @@ struct smi_info { OEM2_DATA_AVAIL) unsigned char msg_flags; - /* Does the BMC have an event buffer? */ - char has_event_buffer; - /* * If set to true, this will request events the next time the * state machine is idle. @@ -965,8 +968,7 @@ static void request_events(void *send_in { struct smi_info *smi_info = send_info; - if (atomic_read(&smi_info->stop_operation) || - !smi_info->has_event_buffer) + if (atomic_read(&smi_info->stop_operation)) return; atomic_set(&smi_info->req_events, 1); @@ -2405,38 +2407,13 @@ static struct of_platform_driver ipmi_of }; #endif /* CONFIG_PPC_OF */ -static int wait_for_msg_done(struct smi_info *smi_info) -{ - enum si_sm_result smi_result; - - smi_result = smi_info->handlers->event(smi_info->si_sm, 0); - for (;;) { - if (smi_result == SI_SM_CALL_WITH_DELAY || - smi_result == SI_SM_CALL_WITH_TICK_DELAY) { - schedule_timeout_uninterruptible(1); - smi_result = smi_info->handlers->event( - smi_info->si_sm, 100); - } else if (smi_result == SI_SM_CALL_WITHOUT_DELAY) { - smi_result = smi_info->handlers->event( - smi_info->si_sm, 0); - } else - break; - } - if (smi_result == SI_SM_HOSED) - /* - * We couldn't get the state machine to run, so whatever's at - * the port is probably not an IPMI SMI interface. - */ - return -ENODEV; - - return 0; -} static int try_get_dev_id(struct smi_info *smi_info) { unsigned char msg[2]; unsigned char *resp; unsigned long resp_len; + enum si_sm_result smi_result; int rv = 0; resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); @@ -2451,98 +2428,35 @@ static int try_get_dev_id(struct smi_inf msg[1] = IPMI_GET_DEVICE_ID_CMD; smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); - rv = wait_for_msg_done(smi_info); - if (rv) - goto out; - - resp_len = smi_info->handlers->get_result(smi_info->si_sm, - resp, IPMI_MAX_MSG_LENGTH); - - /* Check and record info from the get device id, in case we need it. */ - rv = ipmi_demangle_device_id(resp, resp_len, &smi_info->device_id); - - out: - kfree(resp); - return rv; -} - -static int try_enable_event_buffer(struct smi_info *smi_info) -{ - unsigned char msg[3]; - unsigned char *resp; - unsigned long resp_len; - int rv = 0; - - resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); - if (!resp) - return -ENOMEM; - - msg[0] = IPMI_NETFN_APP_REQUEST << 2; - msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; - smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); - - rv = wait_for_msg_done(smi_info); - if (rv) { - printk(KERN_WARNING - "ipmi_si: Error getting response from get global," - " enables command, the event buffer is not" - " enabled.\n"); - goto out; - } - - resp_len = smi_info->handlers->get_result(smi_info->si_sm, - resp, IPMI_MAX_MSG_LENGTH); - - if (resp_len < 4 || - resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || - resp[1] != IPMI_GET_BMC_GLOBAL_ENABLES_CMD || - resp[2] != 0) { - printk(KERN_WARNING - "ipmi_si: Invalid return from get global" - " enables command, cannot enable the event" - " buffer.\n"); - rv = -EINVAL; - goto out; + smi_result = smi_info->handlers->event(smi_info->si_sm, 0); + for (;;) { + if (smi_result == SI_SM_CALL_WITH_DELAY || + smi_result == SI_SM_CALL_WITH_TICK_DELAY) { + schedule_timeout_uninterruptible(1); + smi_result = smi_info->handlers->event( + smi_info->si_sm, 100); + } else if (smi_result == SI_SM_CALL_WITHOUT_DELAY) { + smi_result = smi_info->handlers->event( + smi_info->si_sm, 0); + } else + break; } - - if (resp[3] & IPMI_BMC_EVT_MSG_BUFF) - /* buffer is already enabled, nothing to do. */ - goto out; - - msg[0] = IPMI_NETFN_APP_REQUEST << 2; - msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; - msg[2] = resp[3] | IPMI_BMC_EVT_MSG_BUFF; - smi_info->handlers->start_transaction(smi_info->si_sm, msg, 3); - - rv = wait_for_msg_done(smi_info); - if (rv) { - printk(KERN_WARNING - "ipmi_si: Error getting response from set global," - " enables command, the event buffer is not" - " enabled.\n"); + if (smi_result == SI_SM_HOSED) { + /* + * We couldn't get the state machine to run, so whatever's at + * the port is probably not an IPMI SMI interface. + */ + rv = -ENODEV; goto out; } + /* Otherwise, we got some data. */ resp_len = smi_info->handlers->get_result(smi_info->si_sm, resp, IPMI_MAX_MSG_LENGTH); - if (resp_len < 3 || - resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || - resp[1] != IPMI_SET_BMC_GLOBAL_ENABLES_CMD) { - printk(KERN_WARNING - "ipmi_si: Invalid return from get global," - "enables command, not enable the event" - " buffer.\n"); - rv = -EINVAL; - goto out; - } + /* Check and record info from the get device id, in case we need it. */ + rv = ipmi_demangle_device_id(resp, resp_len, &smi_info->device_id); - if (resp[2] != 0) - /* - * An error when setting the event buffer bit means - * that the event buffer is not supported. - */ - rv = -ENOENT; out: kfree(resp); return rv; @@ -2933,10 +2847,6 @@ static int try_smi_init(struct smi_info new_smi->intf_num = smi_num; smi_num++; - rv = try_enable_event_buffer(new_smi); - if (rv == 0) - new_smi->has_event_buffer = 1; - /* * Start clearing the flags before we enable interrupts or the * timer to avoid racing with the timer. diff -puN include/linux/ipmi_msgdefs.h~revert-3 include/linux/ipmi_msgdefs.h --- a/include/linux/ipmi_msgdefs.h~revert-3 +++ a/include/linux/ipmi_msgdefs.h @@ -58,12 +58,6 @@ #define IPMI_READ_EVENT_MSG_BUFFER_CMD 0x35 #define IPMI_GET_CHANNEL_INFO_CMD 0x42 -/* Bit for BMC global enables. */ -#define IPMI_BMC_RCV_MSG_INTR 0x01 -#define IPMI_BMC_EVT_MSG_INTR 0x02 -#define IPMI_BMC_EVT_MSG_BUFF 0x04 -#define IPMI_BMC_SYS_LOG 0x08 - #define IPMI_NETFN_STORAGE_REQUEST 0x0a #define IPMI_NETFN_STORAGE_RESPONSE 0x0b #define IPMI_ADD_SEL_ENTRY_CMD 0x44 _