/* Numbers in this enumerator should be mapped to ipmi_panic_event_str */ enum ipmi_panic_event_op {
IPMI_SEND_PANIC_EVENT_NONE,
IPMI_SEND_PANIC_EVENT,
IPMI_SEND_PANIC_EVENT_STRING,
IPMI_SEND_PANIC_EVENT_MAX
};
/* Indices in this array should be mapped to enum ipmi_panic_event_op */ staticconstchar *const ipmi_panic_event_str[] = { "none", "event", "string", NULL };
staticconststruct kernel_param_ops panic_op_ops = {
.set = panic_op_write_handler,
.get = panic_op_read_handler
};
module_param_cb(panic_op, &panic_op_ops, NULL, 0600);
MODULE_PARM_DESC(panic_op, "Sets if the IPMI driver will attempt to store panic information in the event log in the event of a panic. Set to 'none' for no, 'event' for a single event, or 'string' for a generic event and the panic string in IPMI OEM events.");
#define MAX_EVENTS_IN_QUEUE 25
/* Remain in auto-maintenance mode for this amount of time (in ms). */ staticunsignedlong maintenance_mode_timeout_ms = 30000;
module_param(maintenance_mode_timeout_ms, ulong, 0644);
MODULE_PARM_DESC(maintenance_mode_timeout_ms, "The time (milliseconds) after the last maintenance message that the connection stays in maintenance mode.");
/* * Don't let a message sit in a queue forever, always time it with at lest * the max message timer. This is in milliseconds.
*/ #define MAX_MSG_TIMEOUT 60000
/* * Timeout times below are in milliseconds, and are done off a 1 * second timer. So setting the value to 1000 would mean anything * between 0 and 1000ms. So really the only reasonable minimum * setting it 2000ms, which is between 1 and 2 seconds.
*/
/* The default timeout for message retries. */ staticunsignedlong default_retry_ms = 2000;
module_param(default_retry_ms, ulong, 0644);
MODULE_PARM_DESC(default_retry_ms, "The time (milliseconds) between retry sends");
/* The default timeout for maintenance mode message retries. */ staticunsignedlong default_maintenance_retry_ms = 3000;
module_param(default_maintenance_retry_ms, ulong, 0644);
MODULE_PARM_DESC(default_maintenance_retry_ms, "The time (milliseconds) between retry sends in maintenance mode");
/* The default maximum number of retries */ staticunsignedint default_max_retries = 4;
module_param(default_max_retries, uint, 0644);
MODULE_PARM_DESC(default_max_retries, "The time (milliseconds) between retry sends in maintenance mode");
/* The default maximum number of users that may register. */ staticunsignedint max_users = 30;
module_param(max_users, uint, 0644);
MODULE_PARM_DESC(max_users, "The most users that may use the IPMI stack at one time.");
/* The default maximum number of message a user may have outstanding. */ staticunsignedint max_msgs_per_user = 100;
module_param(max_msgs_per_user, uint, 0644);
MODULE_PARM_DESC(max_msgs_per_user, "The most message a user may have outstanding.");
/* Call every ~1000 ms. */ #define IPMI_TIMEOUT_TIME 1000
/* How many jiffies does it take to get to the timeout time. */ #define IPMI_TIMEOUT_JIFFIES ((IPMI_TIMEOUT_TIME * HZ) / 1000)
/* * Request events from the queue every second (this is the number of * IPMI_TIMEOUT_TIMES between event requests). Hopefully, in the * future, IPMI will add a way to know immediately if an event is in * the queue and this silliness can go away.
*/ #define IPMI_REQUEST_EV_TIME (1000 / (IPMI_TIMEOUT_TIME))
/* How long should we cache dynamic device IDs? */ #define IPMI_DYN_DEV_ID_EXPIRY (10 * HZ)
/* * The main "user" data structure.
*/ struct ipmi_user { struct list_head link;
struct kref refcount;
refcount_t destroyed;
/* The upper layer that handles receive messages. */ conststruct ipmi_user_hndl *handler; void *handler_data;
/* The interface this user is bound to. */ struct ipmi_smi *intf;
/* Does this interface receive IPMI events? */ bool gets_events;
/* * This is used to form a linked lised during mass deletion. * Since this is in an RCU list, we cannot use the link above * or change any data until the RCU period completes. So we * use this next variable during mass deletion so we can have * a list and don't have to wait and restart the search on * every individual deletion of a command.
*/ struct cmd_rcvr *next;
};
/* * To verify on an incoming send message response that this is * the message that the response is for, we keep a sequence id * and increment it every time we send a message.
*/ long seqid;
/* * This is held so we can properly respond to the message on a * timeout, and it is used to hold the temporary data for * retransmission, too.
*/ struct ipmi_recv_msg *recv_msg;
};
/* * Store the information in a msgid (long) to allow us to find a * sequence table entry from the msgid.
*/ #define STORE_SEQ_IN_MSGID(seq, seqid) \
((((seq) & 0x3f) << 26) | ((seqid) & 0x3ffffff))
struct ipmi_my_addrinfo { /* * My slave address. This is initialized to IPMI_BMC_SLAVE_ADDR, * but may be changed by the user.
*/ unsignedchar address;
/* * My LUN. This should generally stay the SMS LUN, but just in * case...
*/ unsignedchar lun;
};
/* * Note that the product id, manufacturer id, guid, and device id are * immutable in this structure, so dyn_mutex is not required for * accessing those. If those change on a BMC, a new BMC is allocated.
*/ struct bmc_device { struct platform_device pdev; struct list_head intfs; /* Interfaces on this BMC. */ struct ipmi_device_id id; struct ipmi_device_id fetch_id; int dyn_id_set; unsignedlong dyn_id_expiry; struct mutex dyn_mutex; /* Protects id, intfs, & dyn* */
guid_t guid;
guid_t fetch_guid; int dyn_guid_set; struct kref usecount; struct work_struct remove_work; unsignedchar cc; /* completion code */
}; #define to_bmc_device(x) container_of((x), struct bmc_device, pdev.dev)
/* * Various statistics for IPMI, these index stats[] in the ipmi_smi * structure.
*/ enum ipmi_stat_indexes { /* Commands we got from the user that were invalid. */
IPMI_STAT_sent_invalid_commands = 0,
/* Commands we sent to the MC. */
IPMI_STAT_sent_local_commands,
/* Responses from the MC that were delivered to a user. */
IPMI_STAT_handled_local_responses,
/* Responses from the MC that were not delivered to a user. */
IPMI_STAT_unhandled_local_responses,
/* Commands we sent out to the IPMB bus. */
IPMI_STAT_sent_ipmb_commands,
/* Commands sent on the IPMB that had errors on the SEND CMD */
IPMI_STAT_sent_ipmb_command_errs,
/* Each retransmit increments this count. */
IPMI_STAT_retransmitted_ipmb_commands,
/* * When a message times out (runs out of retransmits) this is * incremented.
*/
IPMI_STAT_timed_out_ipmb_commands,
/* * This is like above, but for broadcasts. Broadcasts are * *not* included in the above count (they are expected to * time out).
*/
IPMI_STAT_timed_out_ipmb_broadcasts,
/* Responses I have sent to the IPMB bus. */
IPMI_STAT_sent_ipmb_responses,
/* The response was delivered to the user. */
IPMI_STAT_handled_ipmb_responses,
/* The response had invalid data in it. */
IPMI_STAT_invalid_ipmb_responses,
/* The response didn't have anyone waiting for it. */
IPMI_STAT_unhandled_ipmb_responses,
/* Commands we sent out to the IPMB bus. */
IPMI_STAT_sent_lan_commands,
/* Commands sent on the IPMB that had errors on the SEND CMD */
IPMI_STAT_sent_lan_command_errs,
/* Each retransmit increments this count. */
IPMI_STAT_retransmitted_lan_commands,
/* * When a message times out (runs out of retransmits) this is * incremented.
*/
IPMI_STAT_timed_out_lan_commands,
/* Responses I have sent to the IPMB bus. */
IPMI_STAT_sent_lan_responses,
/* The response was delivered to the user. */
IPMI_STAT_handled_lan_responses,
/* The response had invalid data in it. */
IPMI_STAT_invalid_lan_responses,
/* The response didn't have anyone waiting for it. */
IPMI_STAT_unhandled_lan_responses,
/* The command was delivered to the user. */
IPMI_STAT_handled_commands,
/* The command had invalid data in it. */
IPMI_STAT_invalid_commands,
/* The command didn't have anyone waiting for it. */
IPMI_STAT_unhandled_commands,
/* Invalid data in an event. */
IPMI_STAT_invalid_events,
/* Events that were received with the proper format. */
IPMI_STAT_events,
/* Retransmissions on IPMB that failed. */
IPMI_STAT_dropped_rexmit_ipmb_commands,
/* Retransmissions on LAN that failed. */
IPMI_STAT_dropped_rexmit_lan_commands,
/* This *must* remain last, add new values above this. */
IPMI_NUM_STATS
};
/* Set when the interface is being unregistered. */ bool in_shutdown;
/* Used for a list of interfaces. */ struct list_head link;
/* * The list of upper layers that are using me.
*/ struct list_head users; struct mutex users_mutex;
atomic_t nr_users; struct device_attribute nr_users_devattr; struct device_attribute nr_msgs_devattr;
/* Used for wake ups at startup. */
wait_queue_head_t waitq;
/* * Prevents the interface from being unregistered when the * interface is used by being looked up through the BMC * structure.
*/ struct mutex bmc_reg_mutex;
/* Driver-model device for the system interface. */ struct device *si_dev;
/* * A table of sequence numbers for this interface. We use the * sequence numbers for IPMB messages that go out of the * interface to match them up with their responses. A routine * is called periodically to time the items in this list.
*/ struct mutex seq_lock; struct seq_table seq_table[IPMI_IPMB_NUM_SEQ]; int curr_seq;
/* * Messages queued for deliver to the user.
*/ struct mutex user_msgs_mutex; struct list_head user_msgs;
/* * Messages queued for processing. If processing fails (out * of memory for instance), They will stay in here to be * processed later in a periodic timer interrupt. The * workqueue is for handling received messages directly from * the handler.
*/
spinlock_t waiting_rcv_msgs_lock; struct list_head waiting_rcv_msgs;
atomic_t watchdog_pretimeouts_to_deliver; struct work_struct smi_work;
/* * The list of command receivers that are registered for commands * on this interface.
*/ struct mutex cmd_rcvrs_mutex; struct list_head cmd_rcvrs;
/* * Events that were queues because no one was there to receive * them.
*/ struct mutex events_mutex; /* For dealing with event stuff. */ struct list_head waiting_events; unsignedint waiting_events_count; /* How many events in queue? */ char event_msg_printed;
/* How many users are waiting for events? */
atomic_t event_waiters; unsignedint ticks_to_req_ev;
spinlock_t watch_lock; /* For dealing with watch stuff below. */
/* How many users are waiting for commands? */ unsignedint command_waiters;
/* How many users are waiting for watchdogs? */ unsignedint watchdog_waiters;
/* How many users are waiting for message responses? */ unsignedint response_waiters;
/* * Tells what the lower layer has last been asked to watch for, * messages and/or watchdogs. Protected by watch_lock.
*/ unsignedint last_watch_mask;
/* * The event receiver for my BMC, only really used at panic * shutdown as a place to store this.
*/ unsignedchar event_receiver; unsignedchar event_receiver_lun; unsignedchar local_sel_device; unsignedchar local_event_generator;
/* For handling of maintenance mode. */ int maintenance_mode; bool maintenance_mode_enable; int auto_maintenance_timeout;
spinlock_t maintenance_mode_lock; /* Used in a timer... */
/* * If we are doing maintenance on something on IPMB, extend * the timeout time to avoid timeouts writing firmware and * such.
*/ int ipmb_maintenance_mode_timeout;
/* * A cheap hack, if this is non-null and a message to an * interface comes in with a NULL user, call this routine with * it. Note that the message will still be freed by the * caller. This only works on the system interface. * * Protected by bmc_reg_mutex.
*/ void (*null_user_handler)(struct ipmi_smi *intf, struct ipmi_recv_msg *msg);
/* * When we are scanning the channels for an SMI, this will * tell which channel we are scanning.
*/ int curr_channel;
/* Channel information */ struct ipmi_channel_set *channel_list; unsignedint curr_working_cset; /* First index into the following. */ struct ipmi_channel_set wchannels[2]; struct ipmi_my_addrinfo addrinfo[IPMI_MAX_CHANNELS]; bool channels_ready;
atomic_t stats[IPMI_NUM_STATS];
/* * run_to_completion duplicate of smb_info, smi_info * and ipmi_serial_info structures. Used to decrease numbers of * parameters passed by "low" level IPMI code.
*/ int run_to_completion;
}; #define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev)
/* * The driver model view of the IPMI messaging driver.
*/ staticstruct platform_driver ipmidriver = {
.driver = {
.name = "ipmi",
.bus = &platform_bus_type
}
}; /* * This mutex keeps us from adding the same BMC twice.
*/ static DEFINE_MUTEX(ipmidriver_mutex);
/* * Wholesale remove all the entries from the list in the * interface. No need for locks, this is single-threaded.
*/
list_for_each_entry_safe(rcvr, rcvr2, &intf->cmd_rcvrs, link)
kfree(rcvr);
for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { if ((intf->seq_table[i].inuse)
&& (intf->seq_table[i].recv_msg))
ipmi_free_recv_msg(intf->seq_table[i].recv_msg);
}
kfree(intf);
}
int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
{ struct ipmi_smi *intf; unsignedint count = 0, i; int *interfaces = NULL; struct device **devices = NULL; int rv = 0;
/* * Make sure the driver is actually initialized, this handles * problems with initialization order.
*/
rv = ipmi_init_msghandler(); if (rv) return rv;
mutex_lock(&smi_watchers_mutex);
list_add(&watcher->link, &smi_watchers);
/* * Build an array of ipmi interfaces and fill it in, and * another array of the devices. We can't call the callback * with ipmi_interfaces_mutex held. smi_watchers_mutex will * keep things in order for the user.
*/
mutex_lock(&ipmi_interfaces_mutex);
list_for_each_entry(intf, &ipmi_interfaces, link)
count++; if (count > 0) {
interfaces = kmalloc_array(count, sizeof(*interfaces),
GFP_KERNEL); if (!interfaces) {
rv = -ENOMEM;
} else {
devices = kmalloc_array(count, sizeof(*devices),
GFP_KERNEL); if (!devices) {
kfree(interfaces);
interfaces = NULL;
rv = -ENOMEM;
}
}
count = 0;
} if (interfaces) {
list_for_each_entry(intf, &ipmi_interfaces, link) { int intf_num = READ_ONCE(intf->intf_num);
if (!msg->user) { /* Special handling for NULL users. */ if (intf->null_user_handler) {
intf->null_user_handler(intf, msg);
} else { /* No handler, so give up. */
rv = -EINVAL;
}
ipmi_free_recv_msg(msg);
} elseif (oops_in_progress) { /* * If we are running in the panic context, calling the * receive handler doesn't much meaning and has a deadlock * risk. At this moment, simply skip it in that case.
*/
ipmi_free_recv_msg(msg);
} else { /* * Deliver it in smi_work. The message will hold a * refcount to the user.
*/
mutex_lock(&intf->user_msgs_mutex);
list_add_tail(&msg->link, &intf->user_msgs);
mutex_unlock(&intf->user_msgs_mutex);
queue_work(system_wq, &intf->smi_work);
}
/* * Find the next sequence number not being used and add the given * message with the given timeout to the sequence table. This must be * called with the interface's seq_lock held.
*/ staticint intf_next_seq(struct ipmi_smi *intf, struct ipmi_recv_msg *recv_msg, unsignedlong timeout, int retries, int broadcast, unsignedchar *seq, long *seqid)
{ int rv = 0; unsignedint i;
if (timeout == 0)
timeout = default_retry_ms; if (retries < 0)
retries = default_max_retries;
for (i = intf->curr_seq; (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq;
i = (i+1)%IPMI_IPMB_NUM_SEQ) { if (!intf->seq_table[i].inuse) break;
}
if (!intf->seq_table[i].inuse) {
intf->seq_table[i].recv_msg = recv_msg;
/* * Start with the maximum timeout, when the send response * comes in we will start the real timer.
*/
intf->seq_table[i].timeout = MAX_MSG_TIMEOUT;
intf->seq_table[i].orig_timeout = timeout;
intf->seq_table[i].retries_left = retries;
intf->seq_table[i].broadcast = broadcast;
intf->seq_table[i].inuse = 1;
intf->seq_table[i].seqid = NEXT_SEQID(intf->seq_table[i].seqid);
*seq = i;
*seqid = intf->seq_table[i].seqid;
intf->curr_seq = (i+1)%IPMI_IPMB_NUM_SEQ;
smi_add_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES);
need_waiter(intf);
} else {
rv = -EAGAIN;
}
return rv;
}
/* * Return the receive message for the given sequence number and * release the sequence number so it can be reused. Some other data * is passed in to be sure the message matches up correctly (to help * guard against message coming in after their timeout and the * sequence number being reused).
*/ staticint intf_find_seq(struct ipmi_smi *intf, unsignedchar seq, short channel, unsignedchar cmd, unsignedchar netfn, struct ipmi_addr *addr, struct ipmi_recv_msg **recv_msg)
{ int rv = -ENODEV;
if (seq >= IPMI_IPMB_NUM_SEQ) return -EINVAL;
mutex_lock(&intf->seq_lock); if (intf->seq_table[seq].inuse) { struct ipmi_recv_msg *msg = intf->seq_table[seq].recv_msg;
/* Start the timer for a specific sequence table entry. */ staticint intf_start_seq_timer(struct ipmi_smi *intf, long msgid)
{ int rv = -ENODEV; unsignedchar seq; unsignedlong seqid;
GET_SEQ_FROM_MSGID(msgid, seq, seqid);
mutex_lock(&intf->seq_lock); /* * We do this verification because the user can be deleted * while a message is outstanding.
*/ if ((intf->seq_table[seq].inuse)
&& (intf->seq_table[seq].seqid == seqid)) { struct seq_table *ent = &intf->seq_table[seq];
ent->timeout = ent->orig_timeout;
rv = 0;
}
mutex_unlock(&intf->seq_lock);
return rv;
}
/* Got an error for the send message for a specific sequence number. */ staticint intf_err_seq(struct ipmi_smi *intf, long msgid, unsignedint err)
{ int rv = -ENODEV; unsignedchar seq; unsignedlong seqid; struct ipmi_recv_msg *msg = NULL;
GET_SEQ_FROM_MSGID(msgid, seq, seqid);
mutex_lock(&intf->seq_lock); /* * We do this verification because the user can be deleted * while a message is outstanding.
*/ if ((intf->seq_table[seq].inuse)
&& (intf->seq_table[seq].seqid == seqid)) { struct seq_table *ent = &intf->seq_table[seq];
/* * There is no module usecount here, because it's not * required. Since this can only be used by and called from * other modules, they will implicitly use this module, and * thus this can't be removed unless the other modules are * removed.
*/
if (handler == NULL) return -EINVAL;
/* * Make sure the driver is actually initialized, this handles * problems with initialization order.
*/
rv = ipmi_init_msghandler(); if (rv) return rv;
mutex_lock(&ipmi_interfaces_mutex);
list_for_each_entry(intf, &ipmi_interfaces, link) { if (intf->intf_num == if_num) goto found;
} /* Not found, return an error */
rv = -EINVAL; goto out_unlock;
found: if (intf->in_shutdown) {
rv = -ENODEV; goto out_unlock;
}
if (handler->ipmi_watchdog_pretimeout) /* User wants pretimeouts, so make sure to watch for them. */
smi_add_watch(intf, IPMI_WATCH_MASK_CHECK_WATCHDOG);
/* Must be called with intf->users_mutex held. */ staticvoid _ipmi_destroy_user(struct ipmi_user *user)
{ struct ipmi_smi *intf = user->intf; int i; struct cmd_rcvr *rcvr; struct cmd_rcvr *rcvrs = NULL; struct ipmi_recv_msg *msg, *msg2;
if (!refcount_dec_if_one(&user->destroyed)) return;
if (user->handler->shutdown)
user->handler->shutdown(user->handler_data);
if (user->handler->ipmi_watchdog_pretimeout)
smi_remove_watch(intf, IPMI_WATCH_MASK_CHECK_WATCHDOG);
if (user->gets_events)
atomic_dec(&intf->event_waiters);
/* Remove the user from the interface's list and sequence table. */
list_del(&user->link);
atomic_dec(&intf->nr_users);
mutex_lock(&intf->seq_lock); for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { if (intf->seq_table[i].inuse
&& (intf->seq_table[i].recv_msg->user == user)) {
intf->seq_table[i].inuse = 0;
smi_remove_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES);
ipmi_free_recv_msg(intf->seq_table[i].recv_msg);
}
}
mutex_unlock(&intf->seq_lock);
/* * Remove the user from the command receiver's table. First * we build a list of everything (not using the standard link, * since other things may be using it till we do * synchronize_rcu()) then free everything in that list.
*/
mutex_lock(&intf->cmd_rcvrs_mutex);
list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link,
lockdep_is_held(&intf->cmd_rcvrs_mutex)) { if (rcvr->user == user) {
list_del_rcu(&rcvr->link);
rcvr->next = rcvrs;
rcvrs = rcvr;
}
}
mutex_unlock(&intf->cmd_rcvrs_mutex); while (rcvrs) {
rcvr = rcvrs;
rcvrs = rcvr->next;
kfree(rcvr);
}
mutex_lock(&intf->cmd_rcvrs_mutex); /* Make sure the command/netfn is not already registered. */ if (!is_cmd_rcvr_exclusive(intf, netfn, cmd, chans)) {
rv = -EBUSY; goto out_unlock;
}
/* Now tack on the data to the message. */ if (msg->data_len > 0)
memcpy(&smi_msg->data[i + 9], msg->data, msg->data_len);
smi_msg->data_size = msg->data_len + 9;
/* Now calculate the checksum and tack it on. */
smi_msg->data[i+smi_msg->data_size]
= ipmb_checksum(&smi_msg->data[i + 6], smi_msg->data_size - 6);
/* * Add on the checksum size and the offset from the * broadcast.
*/
smi_msg->data_size += 1 + i;
/* Now tack on the data to the message. */ if (msg->data_len > 0)
memcpy(&smi_msg->data[10], msg->data, msg->data_len);
smi_msg->data_size = msg->data_len + 10;
/* Now calculate the checksum and tack it on. */
smi_msg->data[smi_msg->data_size]
= ipmb_checksum(&smi_msg->data[7], smi_msg->data_size - 7);
/* * Add on the checksum size and the offset from the * broadcast.
*/
smi_msg->data_size += 1;
if ((msg->netfn == IPMI_NETFN_APP_REQUEST)
&& ((msg->cmd == IPMI_SEND_MSG_CMD)
|| (msg->cmd == IPMI_GET_MSG_CMD)
|| (msg->cmd == IPMI_READ_EVENT_MSG_BUFFER_CMD))) { /* * We don't let the user do these, since we manage * the sequence numbers.
*/
ipmi_inc_stat(intf, sent_invalid_commands); return -EINVAL;
}
if (is_maintenance_mode_cmd(msg)) { unsignedlong flags;
staticint i_ipmi_req_ipmb(struct ipmi_smi *intf, struct ipmi_addr *addr, long msgid, struct kernel_ipmi_msg *msg, struct ipmi_smi_msg *smi_msg, struct ipmi_recv_msg *recv_msg, unsignedchar source_address, unsignedchar source_lun, int retries, unsignedint retry_time_ms)
{ struct ipmi_ipmb_addr *ipmb_addr; unsignedchar ipmb_seq; long seqid; int broadcast = 0; struct ipmi_channel *chans; int rv = 0;
if (addr->channel >= IPMI_MAX_CHANNELS) {
ipmi_inc_stat(intf, sent_invalid_commands); return -EINVAL;
}
chans = READ_ONCE(intf->channel_list)->c;
if (chans[addr->channel].medium != IPMI_CHANNEL_MEDIUM_IPMB) {
ipmi_inc_stat(intf, sent_invalid_commands); return -EINVAL;
}
if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE) { /* * Broadcasts add a zero at the beginning of the * message, but otherwise is the same as an IPMB * address.
*/
addr->addr_type = IPMI_IPMB_ADDR_TYPE;
broadcast = 1;
retries = 0; /* Don't retry broadcasts. */
}
/* * 9 for the header and 1 for the checksum, plus * possibly one for the broadcast.
*/ if ((msg->data_len + 10 + broadcast) > IPMI_MAX_MSG_LENGTH) {
ipmi_inc_stat(intf, sent_invalid_commands); return -EMSGSIZE;
}
if (recv_msg->msg.netfn & 0x1) { /* * It's a response, so use the user's sequence * from msgid.
*/
ipmi_inc_stat(intf, sent_ipmb_responses);
format_ipmb_msg(smi_msg, msg, ipmb_addr, msgid,
msgid, broadcast,
source_address, source_lun);
/* * Save the receive message so we can use it * to deliver the response.
*/
smi_msg->user_data = recv_msg;
} else {
mutex_lock(&intf->seq_lock);
if (is_maintenance_mode_cmd(msg))
intf->ipmb_maintenance_mode_timeout =
maintenance_mode_timeout_ms;
if (intf->ipmb_maintenance_mode_timeout && retry_time_ms == 0) /* Different default in maintenance mode */
retry_time_ms = default_maintenance_retry_ms;
/* * Create a sequence number with a 1 second * timeout and 4 retries.
*/
rv = intf_next_seq(intf,
recv_msg,
retry_time_ms,
retries,
broadcast,
&ipmb_seq,
&seqid); if (rv) /* * We have used up all the sequence numbers, * probably, so abort.
*/ goto out_err;
ipmi_inc_stat(intf, sent_ipmb_commands);
/* * Store the sequence number in the message, * so that when the send message response * comes back we can start the timer.
*/
format_ipmb_msg(smi_msg, msg, ipmb_addr,
STORE_SEQ_IN_MSGID(ipmb_seq, seqid),
ipmb_seq, broadcast,
source_address, source_lun);
/* * Copy the message into the recv message data, so we * can retransmit it later if necessary.
*/
memcpy(recv_msg->msg_data, smi_msg->data,
smi_msg->data_size);
recv_msg->msg.data = recv_msg->msg_data;
recv_msg->msg.data_len = smi_msg->data_size;
/* * We don't unlock until here, because we need * to copy the completed message into the * recv_msg before we release the lock. * Otherwise, race conditions may bite us. I * know that's pretty paranoid, but I prefer * to be correct.
*/
out_err:
mutex_unlock(&intf->seq_lock);
}
/* 11 for the header and 1 for the checksum. */ if ((msg->data_len + 12) > IPMI_MAX_MSG_LENGTH) {
ipmi_inc_stat(intf, sent_invalid_commands); return -EMSGSIZE;
}
if (recv_msg->msg.netfn & 0x1) { /* * It's a response, so use the user's sequence * from msgid.
*/
ipmi_inc_stat(intf, sent_lan_responses);
format_lan_msg(smi_msg, msg, lan_addr, msgid,
msgid, source_lun);
/* * Save the receive message so we can use it * to deliver the response.
*/
smi_msg->user_data = recv_msg;
} else {
mutex_lock(&intf->seq_lock);
/* * Create a sequence number with a 1 second * timeout and 4 retries.
*/
rv = intf_next_seq(intf,
recv_msg,
retry_time_ms,
retries,
0,
&ipmb_seq,
&seqid); if (rv) /* * We have used up all the sequence numbers, * probably, so abort.
*/ goto out_err;
ipmi_inc_stat(intf, sent_lan_commands);
/* * Store the sequence number in the message, * so that when the send message response * comes back we can start the timer.
*/
format_lan_msg(smi_msg, msg, lan_addr,
STORE_SEQ_IN_MSGID(ipmb_seq, seqid),
ipmb_seq, source_lun);
/* * Copy the message into the recv message data, so we * can retransmit it later if necessary.
*/
memcpy(recv_msg->msg_data, smi_msg->data,
smi_msg->data_size);
recv_msg->msg.data = recv_msg->msg_data;
recv_msg->msg.data_len = smi_msg->data_size;
/* * We don't unlock until here, because we need * to copy the completed message into the * recv_msg before we release the lock. * Otherwise, race conditions may bite us. I * know that's pretty paranoid, but I prefer * to be correct.
*/
out_err:
mutex_unlock(&intf->seq_lock);
}
return rv;
}
/* * Separate from ipmi_request so that the user does not have to be * supplied in certain circumstances (mainly at panic time). If * messages are supplied, they will be freed, even if an error * occurs.
*/ staticint i_ipmi_request(struct ipmi_user *user, struct ipmi_smi *intf, struct ipmi_addr *addr, long msgid, struct kernel_ipmi_msg *msg, void *user_msg_data, void *supplied_smi, struct ipmi_recv_msg *supplied_recv, int priority, unsignedchar source_address, unsignedchar source_lun, int retries, unsignedint retry_time_ms)
{ struct ipmi_smi_msg *smi_msg; struct ipmi_recv_msg *recv_msg; int run_to_completion = READ_ONCE(intf->run_to_completion); int rv = 0;
if (supplied_recv) {
recv_msg = supplied_recv;
recv_msg->user = user; if (user) {
atomic_inc(&user->nr_msgs); /* The put happens when the message is freed. */
kref_get(&user->refcount);
}
} else {
recv_msg = ipmi_alloc_recv_msg(user); if (IS_ERR(recv_msg)) return PTR_ERR(recv_msg);
}
recv_msg->user_msg_data = user_msg_data;
if (supplied_smi)
smi_msg = supplied_smi; else {
smi_msg = ipmi_alloc_smi_msg(); if (smi_msg == NULL) { if (!supplied_recv)
ipmi_free_recv_msg(recv_msg); return -ENOMEM;
}
}
if (!run_to_completion)
mutex_lock(&intf->users_mutex); if (intf->in_shutdown) {
rv = -ENODEV; goto out_err;
}
recv_msg->msgid = msgid; /* * Store the message to send in the receive message so timeout * responses can get the proper response data.
*/
recv_msg->msg = *msg;
if (msg->msg.data[0]) {
dev_warn(intf->si_dev, "device id fetch failed: 0x%2.2x\n",
msg->msg.data[0]);
intf->bmc->dyn_id_set = 0; goto out;
}
rv = ipmi_demangle_device_id(msg->msg.netfn, msg->msg.cmd,
msg->msg.data, msg->msg.data_len, &intf->bmc->fetch_id); if (rv) {
dev_warn(intf->si_dev, "device id demangle failed: %d\n", rv); /* record completion code when error */
intf->bmc->cc = msg->msg.data[0];
intf->bmc->dyn_id_set = 0;
} else { /* * Make sure the id data is available before setting * dyn_id_set.
*/
smp_wmb();
intf->bmc->dyn_id_set = 1;
}
out:
wake_up(&intf->waitq);
}
/* * Fetch the device id for the bmc/interface. You must pass in either * bmc or intf, this code will get the other one. If the data has * been recently fetched, this will just use the cached data. Otherwise * it will run a new fetch. * * Except for the first time this is called (in ipmi_add_smi()), * this will always return good data;
*/ staticint __bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc, struct ipmi_device_id *id, bool *guid_set, guid_t *guid, int intf_num)
{ int rv = 0; int prev_dyn_id_set, prev_guid_set; bool intf_set = intf != NULL;
/* If we have a valid and current ID, just return that. */ if (intf->in_bmc_register ||
(bmc->dyn_id_set && time_is_after_jiffies(bmc->dyn_id_expiry))) goto out_noprocessing;
/* * The guid, device id, manufacturer id, and product id should * not change on a BMC. If it does we have to do some dancing.
*/ if (!intf->bmc_registered
|| (!prev_guid_set && bmc->dyn_guid_set)
|| (!prev_dyn_id_set && bmc->dyn_id_set)
|| (prev_guid_set && bmc->dyn_guid_set
&& !guid_equal(&bmc->guid, &bmc->fetch_guid))
|| bmc->id.device_id != bmc->fetch_id.device_id
|| bmc->id.manufacturer_id != bmc->fetch_id.manufacturer_id
|| bmc->id.product_id != bmc->fetch_id.product_id) { struct ipmi_device_id id = bmc->fetch_id; int guid_set = bmc->dyn_guid_set;
guid_t guid;
__ipmi_bmc_unregister(intf); /* Fill in the temporary BMC for good measure. */
intf->bmc->id = id;
intf->bmc->dyn_guid_set = guid_set;
intf->bmc->guid = guid; if (__ipmi_bmc_register(intf, &id, guid_set, &guid, intf_num))
need_waiter(intf); /* Retry later on an error. */ else
__scan_channels(intf, &id);
if (!intf_set) { /* * We weren't given the interface on the * command line, so restart the operation on * the next interface for the BMC.
*/
mutex_unlock(&intf->bmc_reg_mutex);
mutex_lock(&bmc->dyn_mutex); goto retry_bmc_lock;
}
/* We have a new BMC, set it up. */
bmc = intf->bmc;
mutex_lock(&bmc->dyn_mutex); goto out_noprocessing;
} elseif (memcmp(&bmc->fetch_id, &bmc->id, sizeof(bmc->id))) /* Version info changes, scan the channels again. */
__scan_channels(intf, &bmc->fetch_id);
out: if (rv && prev_dyn_id_set) {
rv = 0; /* Ignore failures if we have previous data. */
bmc->dyn_id_set = prev_dyn_id_set;
} if (!rv) {
bmc->id = bmc->fetch_id; if (bmc->dyn_guid_set)
bmc->guid = bmc->fetch_guid; elseif (prev_guid_set) /* * The guid used to be valid and it failed to fetch, * just use the cached value.
*/
bmc->dyn_guid_set = prev_guid_set;
}
out_noprocessing: if (!rv) { if (id)
*id = bmc->id;
if (guid_set)
*guid_set = bmc->dyn_guid_set;
if (guid && bmc->dyn_guid_set)
*guid = bmc->guid;
}
/* * Remove the platform device in a work queue to avoid issues * with removing the device attributes while reading a device * attribute.
*/
queue_work(bmc_remove_work_wq, &bmc->remove_work);
}
/* * Must be called with intf->bmc_reg_mutex held.
*/ staticvoid __ipmi_bmc_unregister(struct ipmi_smi *intf)
{ struct bmc_device *bmc = intf->bmc;
/* * Must be called with intf->bmc_reg_mutex held.
*/ staticint __ipmi_bmc_register(struct ipmi_smi *intf, struct ipmi_device_id *id, bool guid_set, guid_t *guid, int intf_num)
{ int rv; struct bmc_device *bmc; struct bmc_device *old_bmc;
/* * platform_device_register() can cause bmc_reg_mutex to * be claimed because of the is_visible functions of * the attributes. Eliminate possible recursion and * release the lock.
*/
intf->in_bmc_register = true;
mutex_unlock(&intf->bmc_reg_mutex);
/* * Try to find if there is an bmc_device struct * representing the interfaced BMC already
*/
mutex_lock(&ipmidriver_mutex); if (guid_set)
old_bmc = ipmi_find_bmc_guid(&ipmidriver.driver, guid); else
old_bmc = ipmi_find_bmc_prod_dev_id(&ipmidriver.driver,
id->product_id,
id->device_id);
/* * If there is already an bmc_device, free the new one, * otherwise register the new BMC device
*/ if (old_bmc) {
bmc = old_bmc; /* * Note: old_bmc already has usecount incremented by * the BMC find functions.
*/
intf->bmc = old_bmc;
mutex_lock(&bmc->dyn_mutex);
list_add_tail(&intf->bmc_link, &bmc->intfs);
mutex_unlock(&bmc->dyn_mutex);
if ((msg->addr.addr_type != IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
|| (msg->msg.netfn != IPMI_NETFN_APP_RESPONSE)
|| (msg->msg.cmd != IPMI_GET_DEVICE_GUID_CMD)) /* Not for me */ return;
if (msg->msg.data[0] != 0) { /* Error from getting the GUID, the BMC doesn't have one. */
bmc->dyn_guid_set = 0; goto out;
}
if (msg->msg.data_len < UUID_SIZE + 1) {
bmc->dyn_guid_set = 0;
dev_warn(intf->si_dev, "The GUID response from the BMC was too short, it was %d but should have been %d. Assuming GUID is not available.\n",
msg->msg.data_len, UUID_SIZE + 1); goto out;
}
import_guid(&bmc->fetch_guid, msg->msg.data + 1); /* * Make sure the guid data is available before setting * dyn_guid_set.
*/
smp_wmb();
bmc->dyn_guid_set = 1;
out:
wake_up(&intf->waitq);
}
staticvoid
channel_handler(struct ipmi_smi *intf, struct ipmi_recv_msg *msg)
{ int rv = 0; int ch; unsignedint set = intf->curr_working_cset; struct ipmi_channel *chans;
if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
&& (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE)
&& (msg->msg.cmd == IPMI_GET_CHANNEL_INFO_CMD)) { /* It's the one we want */ if (msg->msg.data[0] != 0) { /* Got an error from the channel, just go on. */ if (msg->msg.data[0] == IPMI_INVALID_COMMAND_ERR) { /* * If the MC does not support this * command, that is legal. We just * assume it has one IPMB at channel * zero.
*/
intf->wchannels[set].c[0].medium
= IPMI_CHANNEL_MEDIUM_IPMB;
intf->wchannels[set].c[0].protocol
= IPMI_CHANNEL_PROTOCOL_IPMB;
intf->channel_list = intf->wchannels + set;
intf->channels_ready = true;
wake_up(&intf->waitq); goto out;
} goto next_channel;
} if (msg->msg.data_len < 4) { /* Message not big enough, just go on. */ goto next_channel;
}
ch = intf->curr_channel;
chans = intf->wchannels[set].c;
chans[ch].medium = msg->msg.data[2] & 0x7f;
chans[ch].protocol = msg->msg.data[3] & 0x1f;
if (rv) { /* Got an error somehow, just give up. */
dev_warn(intf->si_dev, "Error sending channel information for channel %d: %d\n",
intf->curr_channel, rv);
/* * Start scanning the channels to see what is * available.
*/
set = !intf->curr_working_cset;
intf->curr_working_cset = set;
memset(&intf->wchannels[set], 0, sizeof(struct ipmi_channel_set));
intf->null_user_handler = channel_handler;
intf->curr_channel = 0;
rv = send_channel_info_cmd(intf, 0); if (rv) {
dev_warn(intf->si_dev, "Error sending channel information for channel 0, %d\n",
rv);
intf->null_user_handler = NULL; return -EIO;
}
/* Wait for the channel info to be read. */
wait_event(intf->waitq, intf->channels_ready);
intf->null_user_handler = NULL;
} else { unsignedint set = intf->curr_working_cset;
/* Assume a single IPMB channel at zero. */
intf->wchannels[set].c[0].medium = IPMI_CHANNEL_MEDIUM_IPMB;
intf->wchannels[set].c[0].protocol = IPMI_CHANNEL_PROTOCOL_IPMB;
intf->channel_list = intf->wchannels + set;
intf->channels_ready = true;
}
return 0;
}
staticvoid ipmi_poll(struct ipmi_smi *intf)
{ if (intf->handlers->poll)
intf->handlers->poll(intf->send_info); /* In case something came in */
handle_new_recv_msgs(intf);
}
if (!intf->in_shutdown)
bmc_get_device_id(intf, NULL, NULL, NULL, NULL);
kref_put(&intf->refcount, intf_free);
}
int ipmi_add_smi(struct module *owner, conststruct ipmi_smi_handlers *handlers, void *send_info, struct device *si_dev, unsignedchar slave_addr)
{ int i, j; int rv; struct ipmi_smi *intf, *tintf; struct list_head *link; struct ipmi_device_id id;
/* * Make sure the driver is actually initialized, this handles * problems with initialization order.
*/
rv = ipmi_init_msghandler(); if (rv) return rv;
intf = kzalloc(sizeof(*intf), GFP_KERNEL); if (!intf) return -ENOMEM;
/* * Grab the watchers mutex so we can deliver the new interface * without races.
*/
mutex_lock(&smi_watchers_mutex);
mutex_lock(&ipmi_interfaces_mutex); /* Look for a hole in the numbers. */
i = 0;
link = &ipmi_interfaces;
list_for_each_entry(tintf, &ipmi_interfaces, link) { if (tintf->intf_num != i) {
link = &tintf->link; break;
}
i++;
} /* Add the new interface in numeric order. */ if (i == 0)
list_add(&intf->link, &ipmi_interfaces); else
list_add_tail(&intf->link, link);
rv = handlers->start_processing(send_info, intf); if (rv) goto out_err;
rv = __bmc_get_device_id(intf, NULL, &id, NULL, NULL, i); if (rv) {
dev_err(si_dev, "Unable to get the device id: %d\n", rv); goto out_err_started;
}
mutex_lock(&intf->bmc_reg_mutex);
rv = __scan_channels(intf, &id);
mutex_unlock(&intf->bmc_reg_mutex); if (rv) goto out_err_bmc_reg;
/* Clear out our transmit queues and hold the messages. */
INIT_LIST_HEAD(&tmplist);
list_splice_tail(&intf->hp_xmit_msgs, &tmplist);
list_splice_tail(&intf->xmit_msgs, &tmplist);
/* Current message first, to preserve order */ while (intf->curr_msg && !list_empty(&intf->waiting_rcv_msgs)) { /* Wait for the message to clear out. */
schedule_timeout(1);
}
/* No need for locks, the interface is down. */
/* * Return errors for all pending messages in queue and in the * tables waiting for remote responses.
*/ while (!list_empty(&tmplist)) {
entry = tmplist.next;
list_del(entry);
msg = list_entry(entry, struct ipmi_smi_msg, link);
deliver_smi_err_response(intf, msg, IPMI_ERR_UNSPECIFIED);
}
for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
ent = &intf->seq_table[i]; if (!ent->inuse) continue;
deliver_err_response(intf, ent->recv_msg, IPMI_ERR_UNSPECIFIED);
}
}
void ipmi_unregister_smi(struct ipmi_smi *intf)
{ struct ipmi_smi_watcher *w; int intf_num;
if (!intf) return;
intf_num = intf->intf_num;
mutex_lock(&ipmi_interfaces_mutex);
cancel_work_sync(&intf->smi_work); /* smi_work() can no longer be in progress after this. */
/* * Call all the watcher interfaces to tell them that * an interface is going away.
*/
mutex_lock(&smi_watchers_mutex);
list_for_each_entry(w, &smi_watchers, link)
w->smi_gone(intf_num);
mutex_unlock(&smi_watchers_mutex);
/* * This is 11, not 10, because the response must contain a * completion code.
*/ if (msg->rsp_size < 11) { /* Message not big enough, just ignore it. */
ipmi_inc_stat(intf, invalid_ipmb_responses); return 0;
}
if (msg->rsp[2] != 0) { /* An error getting the response, just ignore it. */ return 0;
}
/* * It's a response from a remote entity. Look up the sequence * number and handle the response.
*/ if (intf_find_seq(intf,
msg->rsp[7] >> 2,
msg->rsp[3] & 0x0f,
msg->rsp[8],
(msg->rsp[4] >> 2) & (~1),
(struct ipmi_addr *) &ipmb_addr,
&recv_msg)) { /* * We were unable to find the sequence number, * so just nuke the message.
*/
ipmi_inc_stat(intf, unhandled_ipmb_responses); return 0;
}
memcpy(recv_msg->msg_data, &msg->rsp[9], msg->rsp_size - 9); /* * The other fields matched, so no need to set them, except * for netfn, which needs to be the response that was * returned, not the request value.
*/
recv_msg->msg.netfn = msg->rsp[4] >> 2;
recv_msg->msg.data = recv_msg->msg_data;
recv_msg->msg.data_len = msg->rsp_size - 10;
recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; if (deliver_response(intf, recv_msg))
ipmi_inc_stat(intf, unhandled_ipmb_responses); else
ipmi_inc_stat(intf, handled_ipmb_responses);
smi_send(intf, intf->handlers, msg, 0); /* * We used the message, so return the value that * causes it to not be freed or queued.
*/
rv = -1;
} elseif (!IS_ERR(recv_msg)) { /* Extract the source address from the data. */
ipmb_addr = (struct ipmi_ipmb_addr *) &recv_msg->addr;
ipmb_addr->addr_type = IPMI_IPMB_ADDR_TYPE;
ipmb_addr->slave_addr = msg->rsp[6];
ipmb_addr->lun = msg->rsp[7] & 3;
ipmb_addr->channel = msg->rsp[3] & 0xf;
/* * Extract the rest of the message information * from the IPMB header.
*/
recv_msg->recv_type = IPMI_CMD_RECV_TYPE;
recv_msg->msgid = msg->rsp[7] >> 2;
recv_msg->msg.netfn = msg->rsp[4] >> 2;
recv_msg->msg.cmd = msg->rsp[8];
recv_msg->msg.data = recv_msg->msg_data;
/* * We chop off 10, not 9 bytes because the checksum * at the end also needs to be removed.
*/
recv_msg->msg.data_len = msg->rsp_size - 10;
memcpy(recv_msg->msg_data, &msg->rsp[9],
msg->rsp_size - 10); if (deliver_response(intf, recv_msg))
ipmi_inc_stat(intf, unhandled_commands); else
ipmi_inc_stat(intf, handled_commands);
} else { /* * We couldn't allocate memory for the message, so * requeue it for handling later.
*/
rv = 1;
}
rcu_read_lock(); /* We always use channel 0 for direct messages. */
rcvr = find_cmd_rcvr(intf, netfn, cmd, 0); if (rcvr) {
user = rcvr->user;
recv_msg = ipmi_alloc_recv_msg(user);
}
rcu_read_unlock();
if (user == NULL) { /* We didn't find a user, deliver an error response. */
ipmi_inc_stat(intf, unhandled_commands);
smi_send(intf, intf->handlers, msg, 0); /* * We used the message, so return the value that * causes it to not be freed or queued.
*/
rv = -1;
} elseif (!IS_ERR(recv_msg)) { /* Extract the source address from the data. */
daddr = (struct ipmi_ipmb_direct_addr *)&recv_msg->addr;
daddr->addr_type = IPMI_IPMB_DIRECT_ADDR_TYPE;
daddr->channel = 0;
daddr->slave_addr = msg->rsp[1];
daddr->rs_lun = msg->rsp[0] & 3;
daddr->rq_lun = msg->rsp[2] & 3;
/* * Extract the rest of the message information * from the IPMB header.
*/
recv_msg->recv_type = IPMI_CMD_RECV_TYPE;
recv_msg->msgid = (msg->rsp[2] >> 2);
recv_msg->msg.netfn = msg->rsp[0] >> 2;
recv_msg->msg.cmd = msg->rsp[3];
recv_msg->msg.data = recv_msg->msg_data;
recv_msg->msg.data_len = msg->rsp_size - 4;
memcpy(recv_msg->msg_data, msg->rsp + 4,
msg->rsp_size - 4); if (deliver_response(intf, recv_msg))
ipmi_inc_stat(intf, unhandled_commands); else
ipmi_inc_stat(intf, handled_commands);
} else { /* * We couldn't allocate memory for the message, so * requeue it for handling later.
*/
rv = 1;
}
recv_msg = msg->user_data; if (recv_msg == NULL) {
dev_warn(intf->si_dev, "IPMI direct message received with no owner. This could be because of a malformed message, or because of a hardware error. Contact your hardware vendor for assistance.\n"); return 0;
}
/* * This is 13, not 12, because the response must contain a * completion code.
*/ if (msg->rsp_size < 13) { /* Message not big enough, just ignore it. */
ipmi_inc_stat(intf, invalid_lan_responses); return 0;
}
if (msg->rsp[2] != 0) { /* An error getting the response, just ignore it. */ return 0;
}
/* * It's a response from a remote entity. Look up the sequence * number and handle the response.
*/ if (intf_find_seq(intf,
msg->rsp[9] >> 2,
msg->rsp[3] & 0x0f,
msg->rsp[10],
(msg->rsp[6] >> 2) & (~1),
(struct ipmi_addr *) &lan_addr,
&recv_msg)) { /* * We were unable to find the sequence number, * so just nuke the message.
*/
ipmi_inc_stat(intf, unhandled_lan_responses); return 0;
}
memcpy(recv_msg->msg_data, &msg->rsp[11], msg->rsp_size - 11); /* * The other fields matched, so no need to set them, except * for netfn, which needs to be the response that was * returned, not the request value.
*/
recv_msg->msg.netfn = msg->rsp[6] >> 2;
recv_msg->msg.data = recv_msg->msg_data;
recv_msg->msg.data_len = msg->rsp_size - 12;
recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; if (deliver_response(intf, recv_msg))
ipmi_inc_stat(intf, unhandled_lan_responses); else
ipmi_inc_stat(intf, handled_lan_responses);
smi_send(intf, intf->handlers, msg, 0); /* * We used the message, so return the value that * causes it to not be freed or queued.
*/
rv = -1;
} elseif (!IS_ERR(recv_msg)) { /* Extract the source address from the data. */
lan_addr = (struct ipmi_lan_addr *) &recv_msg->addr;
lan_addr->addr_type = IPMI_LAN_ADDR_TYPE;
lan_addr->session_handle = msg->rsp[4];
lan_addr->remote_SWID = msg->rsp[8];
lan_addr->local_SWID = msg->rsp[5];
lan_addr->lun = msg->rsp[9] & 3;
lan_addr->channel = msg->rsp[3] & 0xf;
lan_addr->privilege = msg->rsp[3] >> 4;
/* * Extract the rest of the message information * from the IPMB header.
*/
recv_msg->recv_type = IPMI_CMD_RECV_TYPE;
recv_msg->msgid = msg->rsp[9] >> 2;
recv_msg->msg.netfn = msg->rsp[6] >> 2;
recv_msg->msg.cmd = msg->rsp[10];
recv_msg->msg.data = recv_msg->msg_data;
/* * We chop off 12, not 11 bytes because the checksum * at the end also needs to be removed.
*/
recv_msg->msg.data_len = msg->rsp_size - 12;
memcpy(recv_msg->msg_data, &msg->rsp[11],
msg->rsp_size - 12); if (deliver_response(intf, recv_msg))
ipmi_inc_stat(intf, unhandled_commands); else
ipmi_inc_stat(intf, handled_commands);
} else { /* * We couldn't allocate memory for the message, so * requeue it for handling later.
*/
rv = 1;
}
return rv;
}
/* * This routine will handle "Get Message" command responses with * channels that use an OEM Medium. The message format belongs to * the OEM. See IPMI 2.0 specification, Chapter 6 and * Chapter 22, sections 22.6 and 22.24 for more details.
*/ staticint handle_oem_get_msg_cmd(struct ipmi_smi *intf, struct ipmi_smi_msg *msg)
{ struct cmd_rcvr *rcvr; int rv = 0; unsignedchar netfn; unsignedchar cmd; unsignedchar chan; struct ipmi_user *user = NULL; struct ipmi_system_interface_addr *smi_addr; struct ipmi_recv_msg *recv_msg = NULL;
/* * We expect the OEM SW to perform error checking * so we just do some basic sanity checks
*/ if (msg->rsp_size < 4) { /* Message not big enough, just ignore it. */
ipmi_inc_stat(intf, invalid_commands); return 0;
}
if (msg->rsp[2] != 0) { /* An error getting the response, just ignore it. */ return 0;
}
/* * This is an OEM Message so the OEM needs to know how * handle the message. We do no interpretation.
*/
netfn = msg->rsp[0] >> 2;
cmd = msg->rsp[1];
chan = msg->rsp[3] & 0xf;
rcu_read_lock();
rcvr = find_cmd_rcvr(intf, netfn, cmd, chan); if (rcvr) {
user = rcvr->user;
recv_msg = ipmi_alloc_recv_msg(user);
}
rcu_read_unlock();
if (user == NULL) { /* We didn't find a user, just give up. */
ipmi_inc_stat(intf, unhandled_commands);
/* * Don't do anything with these messages, just allow * them to be freed.
*/
rv = 0;
} elseif (!IS_ERR(recv_msg)) { /* * OEM Messages are expected to be delivered via * the system interface to SMS software. We might * need to visit this again depending on OEM * requirements
*/
smi_addr = ((struct ipmi_system_interface_addr *)
&recv_msg->addr);
smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
smi_addr->channel = IPMI_BMC_CHANNEL;
smi_addr->lun = msg->rsp[0] & 3;
/* * The message starts at byte 4 which follows the * Channel Byte in the "GET MESSAGE" command
*/
recv_msg->msg.data_len = msg->rsp_size - 4;
memcpy(recv_msg->msg_data, &msg->rsp[4],
msg->rsp_size - 4); if (deliver_response(intf, recv_msg))
ipmi_inc_stat(intf, unhandled_commands); else
ipmi_inc_stat(intf, handled_commands);
} else { /* * We couldn't allocate memory for the message, so * requeue it for handling later.
*/
rv = 1;
}
if (msg->rsp_size < 19) { /* Message is too small to be an IPMB event. */
ipmi_inc_stat(intf, invalid_events); return 0;
}
if (msg->rsp[2] != 0) { /* An error getting the event, just ignore it. */ return 0;
}
INIT_LIST_HEAD(&msgs);
mutex_lock(&intf->events_mutex);
ipmi_inc_stat(intf, events);
/* * Allocate and fill in one message for every user that is * getting events.
*/
mutex_lock(&intf->users_mutex);
list_for_each_entry(user, &intf->users, link) { if (!user->gets_events) continue;
recv_msg = ipmi_alloc_recv_msg(user); if (IS_ERR(recv_msg)) {
mutex_unlock(&intf->users_mutex);
list_for_each_entry_safe(recv_msg, recv_msg2, &msgs,
link) {
user = recv_msg->user;
list_del(&recv_msg->link);
ipmi_free_recv_msg(recv_msg);
kref_put(&user->refcount, free_ipmi_user);
} /* * We couldn't allocate memory for the * message, so requeue it for handling * later.
*/
rv = 1; goto out;
}
if (deliver_count) { /* Now deliver all the messages. */
list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, link) {
list_del(&recv_msg->link);
deliver_local_response(intf, recv_msg);
}
} elseif (intf->waiting_events_count < MAX_EVENTS_IN_QUEUE) { /* * No one to receive the message, put it in queue if there's * not already too many things in the queue.
*/
recv_msg = ipmi_alloc_recv_msg(NULL); if (IS_ERR(recv_msg)) { /* * We couldn't allocate memory for the * message, so requeue it for handling * later.
*/
rv = 1; goto out;
}
copy_event_into_recv_msg(recv_msg, msg);
list_add_tail(&recv_msg->link, &intf->waiting_events);
intf->waiting_events_count++;
} elseif (!intf->event_msg_printed) { /* * There's too many things in the queue, discard this * message.
*/
dev_warn(intf->si_dev, "Event queue full, discarding incoming events\n");
intf->event_msg_printed = 1;
}
recv_msg = msg->user_data; if (recv_msg == NULL) {
dev_warn(intf->si_dev, "IPMI SMI message received with no owner. This could be because of a malformed message, or because of a hardware error. Contact your hardware vendor for assistance.\n"); return 0;
}
/* * Handle a received message. Return 1 if the message should be requeued, * 0 if the message should be freed, or -1 if the message should not * be freed or requeued.
*/ staticint handle_one_recv_msg(struct ipmi_smi *intf, struct ipmi_smi_msg *msg)
{ int requeue = 0; int chan; unsignedchar cc; bool is_cmd = !((msg->rsp[0] >> 2) & 1);
if (msg->rsp_size < 2) { /* Message is too small to be correct. */
dev_warn_ratelimited(intf->si_dev, "BMC returned too small a message for netfn %x cmd %x, got %d bytes\n",
(msg->data[0] >> 2) | 1,
msg->data[1], msg->rsp_size);
if (intf->in_shutdown || intf->run_to_completion) goto out;
/* * This is the local response to a command send, start * the timer for these. The user_data will not be * NULL if this is a response send, and we will let * response sends just go through.
*/
/* * Check for errors, if we get certain errors (ones * that mean basically we can try again later), we * ignore them and start the timer. Otherwise we * report the error immediately.
*/ if ((msg->rsp_size >= 3) && (msg->rsp[2] != 0)
&& (msg->rsp[2] != IPMI_NODE_BUSY_ERR)
&& (msg->rsp[2] != IPMI_LOST_ARBITRATION_ERR)
&& (msg->rsp[2] != IPMI_BUS_ERR)
&& (msg->rsp[2] != IPMI_NAK_ON_WRITE_ERR)) { int ch = msg->rsp[3] & 0xf; struct ipmi_channel *chans;
/* Got an error sending the message, handle it. */
chans = READ_ONCE(intf->channel_list)->c; if ((chans[ch].medium == IPMI_CHANNEL_MEDIUM_8023LAN)
|| (chans[ch].medium == IPMI_CHANNEL_MEDIUM_ASYNC))
ipmi_inc_stat(intf, sent_lan_command_errs); else
ipmi_inc_stat(intf, sent_ipmb_command_errs);
intf_err_seq(intf, msg->msgid, msg->rsp[2]);
} else /* The message was sent, start the timer. */
intf_start_seq_timer(intf, msg->msgid);
requeue = 0; goto out;
} elseif (((msg->rsp[0] >> 2) != ((msg->data[0] >> 2) | 1))
|| (msg->rsp[1] != msg->data[1])) { /* * The NetFN and Command in the response is not even * marginally correct.
*/
dev_warn_ratelimited(intf->si_dev, "BMC returned incorrect response, expected netfn %x cmd %x, got netfn %x cmd %x\n",
(msg->data[0] >> 2) | 1, msg->data[1],
msg->rsp[0] >> 2, msg->rsp[1]);
goto return_unspecified;
}
if (msg->type == IPMI_SMI_MSG_TYPE_IPMB_DIRECT) { if ((msg->data[0] >> 2) & 1) { /* It's a response to a sent response. */
chan = 0;
cc = msg->rsp[4]; goto process_response_response;
} if (is_cmd)
requeue = handle_ipmb_direct_rcv_cmd(intf, msg); else
requeue = handle_ipmb_direct_rcv_rsp(intf, msg);
} elseif ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2))
&& (msg->rsp[1] == IPMI_SEND_MSG_CMD)
&& (msg->user_data != NULL)) { /* * It's a response to a response we sent. For this we * deliver a send message response to the user.
*/ struct ipmi_recv_msg *recv_msg;
if (intf->run_to_completion) goto out;
chan = msg->data[2] & 0x0f; if (chan >= IPMI_MAX_CHANNELS) /* Invalid channel number */ goto out;
cc = msg->rsp[2];
/* It's from the receive queue. */
chan = msg->rsp[3] & 0xf; if (chan >= IPMI_MAX_CHANNELS) { /* Invalid channel number */
requeue = 0; goto out;
}
/* * We need to make sure the channels have been initialized. * The channel_handler routine will set the "curr_channel" * equal to or greater than IPMI_MAX_CHANNELS when all the * channels for this interface have been initialized.
*/ if (!intf->channels_ready) {
requeue = 0; /* Throw the message away */ goto out;
}
chans = READ_ONCE(intf->channel_list)->c;
switch (chans[chan].medium) { case IPMI_CHANNEL_MEDIUM_IPMB: if (msg->rsp[4] & 0x04) { /* * It's a response, so find the * requesting message and send it up.
*/
requeue = handle_ipmb_get_msg_rsp(intf, msg);
} else { /* * It's a command to the SMS from some other * entity. Handle that.
*/
requeue = handle_ipmb_get_msg_cmd(intf, msg);
} break;
case IPMI_CHANNEL_MEDIUM_8023LAN: case IPMI_CHANNEL_MEDIUM_ASYNC: if (msg->rsp[6] & 0x04) { /* * It's a response, so find the * requesting message and send it up.
*/
requeue = handle_lan_get_msg_rsp(intf, msg);
} else { /* * It's a command to the SMS from some other * entity. Handle that.
*/
requeue = handle_lan_get_msg_cmd(intf, msg);
} break;
default: /* Check for OEM Channels. Clients had better
register for these commands. */ if ((chans[chan].medium >= IPMI_CHANNEL_MEDIUM_OEM_MIN)
&& (chans[chan].medium
<= IPMI_CHANNEL_MEDIUM_OEM_MAX)) {
requeue = handle_oem_get_msg_cmd(intf, msg);
} else { /* * We don't handle the channel type, so just * free the message.
*/
requeue = 0;
}
}
requeue = handle_read_event_rsp(intf, msg);
} else { /* It's a response from the local BMC. */
requeue = handle_bmc_rsp(intf, msg);
}
out: return requeue;
}
/* * If there are messages in the queue or pretimeouts, handle them.
*/ staticvoid handle_new_recv_msgs(struct ipmi_smi *intf)
{ struct ipmi_smi_msg *smi_msg; unsignedlong flags = 0; int rv; int run_to_completion = READ_ONCE(intf->run_to_completion);
/* See if any waiting messages need to be processed. */ if (!run_to_completion)
spin_lock_irqsave(&intf->waiting_rcv_msgs_lock, flags); while (!list_empty(&intf->waiting_rcv_msgs)) {
smi_msg = list_entry(intf->waiting_rcv_msgs.next, struct ipmi_smi_msg, link);
list_del(&smi_msg->link); if (!run_to_completion)
spin_unlock_irqrestore(&intf->waiting_rcv_msgs_lock,
flags);
rv = handle_one_recv_msg(intf, smi_msg); if (!run_to_completion)
spin_lock_irqsave(&intf->waiting_rcv_msgs_lock, flags); if (rv > 0) { /* * To preserve message order, quit if we * can't handle a message. Add the message * back at the head, this is safe because this * workqueue is the only thing that pulls the * messages.
*/
list_add(&smi_msg->link, &intf->waiting_rcv_msgs); break;
} else { if (rv == 0) /* Message handled */
ipmi_free_smi_msg(smi_msg); /* If rv < 0, fatal error, del but don't free. */
}
} if (!run_to_completion)
spin_unlock_irqrestore(&intf->waiting_rcv_msgs_lock, flags);
}
/* * Start the next message if available. * * Do this here, not in the actual receiver, because we may deadlock * because the lower layer is allowed to hold locks while calling * message delivery.
*/
if (!run_to_completion)
spin_lock_irqsave(&intf->xmit_msgs_lock, flags); if (intf->curr_msg == NULL && !intf->in_shutdown) { struct list_head *entry = NULL;
/* Pick the high priority queue first. */ if (!list_empty(&intf->hp_xmit_msgs))
entry = intf->hp_xmit_msgs.next; elseif (!list_empty(&intf->xmit_msgs))
entry = intf->xmit_msgs.next;
if (entry) {
list_del(entry);
newmsg = list_entry(entry, struct ipmi_smi_msg, link);
intf->curr_msg = newmsg;
}
} if (!run_to_completion)
spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
if (newmsg)
intf->handlers->sender(intf->send_info, newmsg);
handle_new_recv_msgs(intf);
/* Nothing below applies during panic time. */ if (run_to_completion) return;
/* * If the pretimout count is non-zero, decrement one from it and * deliver pretimeouts to all the users.
*/ if (atomic_add_unless(&intf->watchdog_pretimeouts_to_deliver, -1, 0)) { struct ipmi_user *user;
/* * Freeing the message can cause a user to be released, which * can then cause the interface to be freed. Make sure that * doesn't happen until we are ready.
*/
kref_get(&intf->refcount);
if (refcount_read(&user->destroyed) == 0)
ipmi_free_recv_msg(msg); else
user->handler->ipmi_recv_hndl(msg, user->handler_data);
}
mutex_unlock(&intf->user_msgs_mutex);
kref_put(&intf->refcount, intf_free);
}
/* Handle a new message from the lower layer. */ void ipmi_smi_msg_received(struct ipmi_smi *intf, struct ipmi_smi_msg *msg)
{ unsignedlong flags = 0; /* keep us warning-free. */ int run_to_completion = READ_ONCE(intf->run_to_completion);
/* * To preserve message order, we keep a queue and deliver from * a workqueue.
*/ if (!run_to_completion)
spin_lock_irqsave(&intf->waiting_rcv_msgs_lock, flags);
list_add_tail(&msg->link, &intf->waiting_rcv_msgs); if (!run_to_completion)
spin_unlock_irqrestore(&intf->waiting_rcv_msgs_lock,
flags);
if (!run_to_completion)
spin_lock_irqsave(&intf->xmit_msgs_lock, flags); /* * We can get an asynchronous event or receive message in addition * to commands we send.
*/ if (msg == intf->curr_msg)
intf->curr_msg = NULL; if (!run_to_completion)
spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
if (run_to_completion)
smi_work(&intf->smi_work); else
queue_work(system_wq, &intf->smi_work);
}
EXPORT_SYMBOL(ipmi_smi_msg_received);
void ipmi_smi_watchdog_pretimeout(struct ipmi_smi *intf)
{ if (intf->in_shutdown) return;
staticstruct ipmi_smi_msg *
smi_from_recv_msg(struct ipmi_smi *intf, struct ipmi_recv_msg *recv_msg, unsignedchar seq, long seqid)
{ struct ipmi_smi_msg *smi_msg = ipmi_alloc_smi_msg(); if (!smi_msg) /* * If we can't allocate the message, then just return, we * get 4 retries, so this should be ok.
*/ return NULL;
if (ent->retries_left == 0) { /* The message has used all its retries. */
ent->inuse = 0;
smi_remove_watch(intf, IPMI_WATCH_MASK_CHECK_MESSAGES);
msg = ent->recv_msg;
list_add_tail(&msg->link, timeouts); if (ent->broadcast)
ipmi_inc_stat(intf, timed_out_ipmb_broadcasts); elseif (is_lan_addr(&ent->recv_msg->addr))
ipmi_inc_stat(intf, timed_out_lan_commands); else
ipmi_inc_stat(intf, timed_out_ipmb_commands);
} else { struct ipmi_smi_msg *smi_msg; /* More retries, send again. */
*need_timer = true;
/* * Start with the max timer, set to normal timer after * the message is sent.
*/
ent->timeout = MAX_MSG_TIMEOUT;
ent->retries_left--;
smi_msg = smi_from_recv_msg(intf, ent->recv_msg, slot,
ent->seqid); if (!smi_msg) { if (is_lan_addr(&ent->recv_msg->addr))
ipmi_inc_stat(intf,
dropped_rexmit_lan_commands); else
ipmi_inc_stat(intf,
dropped_rexmit_ipmb_commands); return;
}
mutex_unlock(&intf->seq_lock);
/* * Send the new message. We send with a zero * priority. It timed out, I doubt time is that * critical now, and high priority messages are really * only for messages to the local MC, which don't get * resent.
*/ if (intf->handlers) { if (is_lan_addr(&ent->recv_msg->addr))
ipmi_inc_stat(intf,
retransmitted_lan_commands); else
ipmi_inc_stat(intf,
retransmitted_ipmb_commands);
if (!intf->bmc_registered) {
kref_get(&intf->refcount); if (!schedule_work(&intf->bmc_reg_work)) {
kref_put(&intf->refcount, intf_free);
need_timer = true;
}
}
/* * Go through the seq table and find any messages that * have timed out, putting them in the timeouts * list.
*/
INIT_LIST_HEAD(&timeouts);
mutex_lock(&intf->seq_lock); if (intf->ipmb_maintenance_mode_timeout) { if (intf->ipmb_maintenance_mode_timeout <= timeout_period)
intf->ipmb_maintenance_mode_timeout = 0; else
intf->ipmb_maintenance_mode_timeout -= timeout_period;
} for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++)
check_msg_timeout(intf, &intf->seq_table[i],
&timeouts, timeout_period, i,
&need_timer);
mutex_unlock(&intf->seq_lock);
/* * Maintenance mode handling. Check the timeout * optimistically before we claim the lock. It may * mean a timeout gets missed occasionally, but that * only means the timeout gets extended by one period * in that case. No big deal, and it avoids the lock * most of the time.
*/ if (intf->auto_maintenance_timeout > 0) {
spin_lock_irqsave(&intf->maintenance_mode_lock, flags); if (intf->auto_maintenance_timeout > 0) {
intf->auto_maintenance_timeout
-= timeout_period; if (!intf->maintenance_mode
&& (intf->auto_maintenance_timeout <= 0)) {
intf->maintenance_mode_enable = false;
maintenance_mode_update(intf);
}
}
spin_unlock_irqrestore(&intf->maintenance_mode_lock,
flags);
}
queue_work(system_wq, &intf->smi_work);
return need_timer;
}
staticvoid ipmi_request_event(struct ipmi_smi *intf)
{ /* No event requests when in maintenance mode. */ if (intf->maintenance_mode_enable) return;
if (!intf->in_shutdown)
intf->handlers->request_events(intf->send_info);
}
staticstruct timer_list ipmi_timer;
static atomic_t stop_operation;
staticvoid ipmi_timeout_work(struct work_struct *work)
{ if (atomic_read(&stop_operation)) return;
staticvoid ipmi_timeout(struct timer_list *unused)
{ if (atomic_read(&stop_operation)) return;
queue_work(system_wq, &ipmi_timer_work);
}
staticvoid need_waiter(struct ipmi_smi *intf)
{ /* Racy, but worst case we start the timer twice. */ if (!timer_pending(&ipmi_timer))
mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES);
}
staticvoid free_smi_msg(struct ipmi_smi_msg *msg)
{
atomic_dec(&smi_msg_inuse_count); /* Try to keep as much stuff out of the panic path as possible. */ if (!oops_in_progress)
kfree(msg);
}
staticvoid free_recv_msg(struct ipmi_recv_msg *msg)
{
atomic_dec(&recv_msg_inuse_count); /* Try to keep as much stuff out of the panic path as possible. */ if (!oops_in_progress)
kfree(msg);
}
/* Fill in an event telling that we have failed. */
msg.netfn = 0x04; /* Sensor or Event. */
msg.cmd = 2; /* Platform event command. */
msg.data = data;
msg.data_len = 8;
data[0] = 0x41; /* Kernel generator ID, IPMI table 5-4 */
data[1] = 0x03; /* This is for IPMI 1.0. */
data[2] = 0x20; /* OS Critical Stop, IPMI table 36-3 */
data[4] = 0x6f; /* Sensor specific, IPMI table 36-1 */
data[5] = 0xa1; /* Runtime stop OEM bytes 2 & 3. */
/* * Put a few breadcrumbs in. Hopefully later we can add more things * to make the panic events more useful.
*/ if (str) {
data[3] = str[0];
data[6] = str[1];
data[7] = str[2];
}
/* Send the event announcing the panic. */
_ipmi_panic_request_and_wait(intf, &addr, &msg);
/* * On every interface, dump a bunch of OEM event holding the * string.
*/ if (ipmi_send_panic_event != IPMI_SEND_PANIC_EVENT_STRING || !str) return;
/* * intf_num is used as an marker to tell if the * interface is valid. Thus we need a read barrier to * make sure data fetched before checking intf_num * won't be used.
*/
smp_rmb();
/* * First job here is to figure out where to send the * OEM events. There's no way in IPMI to send OEM * events using an event send command, so we have to * find the SEL to put them in and stick them in * there.
*/
/* Get capabilities from the get device id. */
intf->local_sel_device = 0;
intf->local_event_generator = 0;
intf->event_receiver = 0;
/* Request the device info from the local MC. */
msg.netfn = IPMI_NETFN_APP_REQUEST;
msg.cmd = IPMI_GET_DEVICE_ID_CMD;
msg.data = NULL;
msg.data_len = 0;
intf->null_user_handler = device_id_fetcher;
_ipmi_panic_request_and_wait(intf, &addr, &msg);
if (intf->local_event_generator) { /* Request the event receiver from the local MC. */
msg.netfn = IPMI_NETFN_SENSOR_EVENT_REQUEST;
msg.cmd = IPMI_GET_EVENT_RECEIVER_CMD;
msg.data = NULL;
msg.data_len = 0;
intf->null_user_handler = event_receiver_fetcher;
_ipmi_panic_request_and_wait(intf, &addr, &msg);
}
intf->null_user_handler = NULL;
/* * Validate the event receiver. The low bit must not * be 1 (it must be a valid IPMB address), it cannot * be zero, and it must not be my address.
*/ if (((intf->event_receiver & 1) == 0)
&& (intf->event_receiver != 0)
&& (intf->event_receiver != intf->addrinfo[0].address)) { /* * The event receiver is valid, send an IPMB * message.
*/
ipmb = (struct ipmi_ipmb_addr *) &addr;
ipmb->addr_type = IPMI_IPMB_ADDR_TYPE;
ipmb->channel = 0; /* FIXME - is this right? */
ipmb->lun = intf->event_receiver_lun;
ipmb->slave_addr = intf->event_receiver;
} elseif (intf->local_sel_device) { /* * The event receiver was not valid (or was * me), but I am an SEL device, just dump it * in my SEL.
*/
si = (struct ipmi_system_interface_addr *) &addr;
si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
si->channel = IPMI_BMC_CHANNEL;
si->lun = 0;
} else return; /* No where to send the event. */
if (has_panicked) return NOTIFY_DONE;
has_panicked = 1;
/* For every registered interface, set it to run to completion. */
list_for_each_entry(intf, &ipmi_interfaces, link) { if (!intf->handlers || intf->intf_num == -1) /* Interface is not ready. */ continue;
if (!intf->handlers->poll) continue;
/* * If we were interrupted while locking xmit_msgs_lock or * waiting_rcv_msgs_lock, the corresponding list may be * corrupted. In this case, drop items on the list for * the safety.
*/ if (!spin_trylock(&intf->xmit_msgs_lock)) {
INIT_LIST_HEAD(&intf->xmit_msgs);
INIT_LIST_HEAD(&intf->hp_xmit_msgs);
} else
spin_unlock(&intf->xmit_msgs_lock);
if (!spin_trylock(&intf->waiting_rcv_msgs_lock))
INIT_LIST_HEAD(&intf->waiting_rcv_msgs); else
spin_unlock(&intf->waiting_rcv_msgs_lock);
intf->run_to_completion = 1; if (intf->handlers->set_run_to_completion)
intf->handlers->set_run_to_completion(intf->send_info,
1);
list_for_each_entry(user, &intf->users, link) { if (user->handler->ipmi_panic_handler)
user->handler->ipmi_panic_handler(
user->handler_data);
}
send_panic_events(intf, ptr);
}
return NOTIFY_DONE;
}
/* Must be called with ipmi_interfaces_mutex held. */ staticint ipmi_register_driver(void)
{ int rv;
if (drvregistered) return 0;
rv = driver_register(&ipmidriver.driver); if (rv)
pr_err("Could not register IPMI driver\n"); else
drvregistered = true; return rv;
}
/* * This can't be called if any interfaces exist, so no worry * about shutting down the interfaces.
*/
/* * Tell the timer to stop, then wait for it to stop. This * avoids problems with race conditions removing the timer * here.
*/
atomic_set(&stop_operation, 1);
timer_delete_sync(&ipmi_timer);
cancel_work_sync(&ipmi_timer_work);
initialized = false;
/* Check for buffer leaks. */
count = atomic_read(&smi_msg_inuse_count); if (count != 0)
pr_warn("SMI message count %d at exit\n", count);
count = atomic_read(&recv_msg_inuse_count); if (count != 0)
pr_warn("recv message count %d at exit\n", count);
} if (drvregistered)
driver_unregister(&ipmidriver.driver);
}
module_exit(cleanup_ipmi);
module_init(ipmi_init_msghandler_mod);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
MODULE_DESCRIPTION("Incoming and outgoing message routing for an IPMI interface.");
MODULE_VERSION(IPMI_DRIVER_VERSION);
MODULE_SOFTDEP("post: ipmi_devintf");
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.78Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-04-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.