fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / char / ipmi / ipmi_si_intf.c
index 02a7dd7..f1afd26 100644 (file)
@@ -38,7 +38,6 @@
  * and drives the real SMI state machine.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <asm/system.h>
 #include <linux/mutex.h>
 #include <linux/kthread.h>
 #include <asm/irq.h>
-#ifdef CONFIG_HIGH_RES_TIMERS
-#include <linux/hrtime.h>
-# if defined(schedule_next_int)
-/* Old high-res timer code, do translations. */
-#  define get_arch_cycles(a) quick_update_jiffies_sub(a)
-#  define arch_cycles_per_jiffy cycles_per_jiffies
-# endif
-static inline void add_usec_to_timer(struct timer_list *t, long v)
-{
-       t->arch_cycle_expires += nsec_to_arch_cycle(v * 1000);
-       while (t->arch_cycle_expires >= arch_cycles_per_jiffy)
-       {
-               t->expires++;
-               t->arch_cycle_expires -= arch_cycles_per_jiffy;
-       }
-}
-#endif
 #include <linux/interrupt.h>
 #include <linux/rcupdate.h>
 #include <linux/ipmi_smi.h>
@@ -79,6 +61,10 @@ static inline void add_usec_to_timer(struct timer_list *t, long v)
 #include "ipmi_si_sm.h"
 #include <linux/init.h>
 #include <linux/dmi.h>
+#include <linux/string.h>
+#include <linux/ctype.h>
+
+#define PFX "ipmi_si: "
 
 /* Measure times between events in the driver. */
 #undef DEBUG_TIMING
@@ -110,7 +96,7 @@ enum si_intf_state {
 enum si_type {
     SI_KCS, SI_SMIC, SI_BT
 };
-static char *si_to_str[] = { "KCS", "SMIC", "BT" };
+static char *si_to_str[] = { "kcs", "smic", "bt" };
 
 #define DEVICE_NAME "ipmi_si"
 
@@ -235,7 +221,15 @@ struct smi_info
        struct list_head link;
 };
 
+#define SI_MAX_PARMS 4
+
+static int force_kipmid[SI_MAX_PARMS];
+static int num_force_kipmid;
+
+static int unload_when_empty = 1;
+
 static int try_smi_init(struct smi_info *smi);
+static void cleanup_one_si(struct smi_info *to_clean);
 
 static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list);
 static int register_xaction_notifier(struct notifier_block * nb)
@@ -243,8 +237,6 @@ static int register_xaction_notifier(struct notifier_block * nb)
        return atomic_notifier_chain_register(&xaction_notifier_list, nb);
 }
 
-static void si_restart_short_timer(struct smi_info *smi_info);
-
 static void deliver_recv_msg(struct smi_info *smi_info,
                             struct ipmi_smi_msg *msg)
 {
@@ -255,14 +247,18 @@ static void deliver_recv_msg(struct smi_info *smi_info,
        spin_lock(&(smi_info->si_lock));
 }
 
-static void return_hosed_msg(struct smi_info *smi_info)
+static void return_hosed_msg(struct smi_info *smi_info, int cCode)
 {
        struct ipmi_smi_msg *msg = smi_info->curr_msg;
 
+       if (cCode < 0 || cCode > IPMI_ERR_UNSPECIFIED)
+               cCode = IPMI_ERR_UNSPECIFIED;
+       /* else use it as is */
+
        /* Make it a reponse */
        msg->rsp[0] = msg->data[0] | 4;
        msg->rsp[1] = msg->data[1];
-       msg->rsp[2] = 0xFF; /* Unknown error. */
+       msg->rsp[2] = cCode;
        msg->rsp_size = 3;
 
        smi_info->curr_msg = NULL;
@@ -313,7 +309,7 @@ static enum si_sm_result start_next_msg(struct smi_info *smi_info)
                        smi_info->curr_msg->data,
                        smi_info->curr_msg->data_size);
                if (err) {
-                       return_hosed_msg(smi_info);
+                       return_hosed_msg(smi_info, err);
                }
 
                rv = SI_SM_CALL_WITHOUT_DELAY;
@@ -422,10 +418,10 @@ static void handle_flags(struct smi_info *smi_info)
                        smi_info->curr_msg->data,
                        smi_info->curr_msg->data_size);
                smi_info->si_state = SI_GETTING_EVENTS;
-       } else if (smi_info->msg_flags & OEM_DATA_AVAIL) {
-               if (smi_info->oem_data_avail_handler)
-                       if (smi_info->oem_data_avail_handler(smi_info))
-                               goto retry;
+       } else if (smi_info->msg_flags & OEM_DATA_AVAIL &&
+                  smi_info->oem_data_avail_handler) {
+               if (smi_info->oem_data_avail_handler(smi_info))
+                       goto retry;
        } else {
                smi_info->si_state = SI_NORMAL;
        }
@@ -655,7 +651,7 @@ static enum si_sm_result smi_event_handler(struct smi_info *smi_info,
                        /* If we were handling a user message, format
                            a response to send to the upper layer to
                            tell it about the error. */
-                       return_hosed_msg(smi_info);
+                       return_hosed_msg(smi_info, IPMI_ERR_UNSPECIFIED);
                }
                si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0);
        }
@@ -699,22 +695,24 @@ static enum si_sm_result smi_event_handler(struct smi_info *smi_info,
        {
                /* We are idle and the upper layer requested that I fetch
                   events, so do so. */
-               unsigned char msg[2];
+               atomic_set(&smi_info->req_events, 0);
 
-               spin_lock(&smi_info->count_lock);
-               smi_info->flag_fetches++;
-               spin_unlock(&smi_info->count_lock);
+               smi_info->curr_msg = ipmi_alloc_smi_msg();
+               if (!smi_info->curr_msg)
+                       goto out;
 
-               atomic_set(&smi_info->req_events, 0);
-               msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
-               msg[1] = IPMI_GET_MSG_FLAGS_CMD;
+               smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
+               smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD;
+               smi_info->curr_msg->data_size = 2;
 
                smi_info->handlers->start_transaction(
-                       smi_info->si_sm, msg, 2);
-               smi_info->si_state = SI_GETTING_FLAGS;
+                       smi_info->si_sm,
+                       smi_info->curr_msg->data,
+                       smi_info->curr_msg->data_size);
+               smi_info->si_state = SI_GETTING_EVENTS;
                goto restart;
        }
-
+ out:
        return si_sm_result;
 }
 
@@ -729,6 +727,15 @@ static void sender(void                *send_info,
        struct timeval    t;
 #endif
 
+       if (atomic_read(&smi_info->stop_operation)) {
+               msg->rsp[0] = msg->data[0] | 4;
+               msg->rsp[1] = msg->data[1];
+               msg->rsp[2] = IPMI_ERR_UNSPECIFIED;
+               msg->rsp_size = 3;
+               deliver_recv_msg(smi_info, msg);
+               return;
+       }
+
        spin_lock_irqsave(&(smi_info->msg_lock), flags);
 #ifdef DEBUG_TIMING
        do_gettimeofday(&t);
@@ -768,7 +775,6 @@ static void sender(void                *send_info,
            && (smi_info->curr_msg == NULL))
        {
                start_next_msg(smi_info);
-               si_restart_short_timer(smi_info);
        }
        spin_unlock_irqrestore(&(smi_info->si_lock), flags);
 }
@@ -809,7 +815,7 @@ static int ipmi_thread(void *data)
                        /* do nothing */
                }
                else if (smi_result == SI_SM_CALL_WITH_DELAY)
-                       udelay(1);
+                       schedule();
                else
                        schedule_timeout_interruptible(1);
        }
@@ -821,48 +827,25 @@ static void poll(void *send_info)
 {
        struct smi_info *smi_info = send_info;
 
-       smi_event_handler(smi_info, 0);
+       /*
+        * Make sure there is some delay in the poll loop so we can
+        * drive time forward and timeout things.
+        */
+       udelay(10);
+       smi_event_handler(smi_info, 10);
 }
 
 static void request_events(void *send_info)
 {
        struct smi_info *smi_info = send_info;
 
+       if (atomic_read(&smi_info->stop_operation))
+               return;
+
        atomic_set(&smi_info->req_events, 1);
 }
 
-static int initialized = 0;
-
-/* Must be called with interrupts off and with the si_lock held. */
-static void si_restart_short_timer(struct smi_info *smi_info)
-{
-#if defined(CONFIG_HIGH_RES_TIMERS)
-       unsigned long flags;
-       unsigned long jiffies_now;
-       unsigned long seq;
-
-       if (del_timer(&(smi_info->si_timer))) {
-               /* If we don't delete the timer, then it will go off
-                  immediately, anyway.  So we only process if we
-                  actually delete the timer. */
-
-               do {
-                       seq = read_seqbegin_irqsave(&xtime_lock, flags);
-                       jiffies_now = jiffies;
-                       smi_info->si_timer.expires = jiffies_now;
-                       smi_info->si_timer.arch_cycle_expires
-                               = get_arch_cycles(jiffies_now);
-               } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
-
-               add_usec_to_timer(&smi_info->si_timer, SI_SHORT_TIMEOUT_USEC);
-
-               add_timer(&(smi_info->si_timer));
-               spin_lock_irqsave(&smi_info->count_lock, flags);
-               smi_info->timeout_restarts++;
-               spin_unlock_irqrestore(&smi_info->count_lock, flags);
-       }
-#endif
-}
+static int initialized;
 
 static void smi_timeout(unsigned long data)
 {
@@ -904,38 +887,22 @@ static void smi_timeout(unsigned long data)
        /* If the state machine asks for a short delay, then shorten
            the timer timeout. */
        if (smi_result == SI_SM_CALL_WITH_DELAY) {
-#if defined(CONFIG_HIGH_RES_TIMERS)
-               unsigned long seq;
-#endif
                spin_lock_irqsave(&smi_info->count_lock, flags);
                smi_info->short_timeouts++;
                spin_unlock_irqrestore(&smi_info->count_lock, flags);
-#if defined(CONFIG_HIGH_RES_TIMERS)
-               do {
-                       seq = read_seqbegin_irqsave(&xtime_lock, flags);
-                       smi_info->si_timer.expires = jiffies;
-                       smi_info->si_timer.arch_cycle_expires
-                               = get_arch_cycles(smi_info->si_timer.expires);
-               } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
-               add_usec_to_timer(&smi_info->si_timer, SI_SHORT_TIMEOUT_USEC);
-#else
                smi_info->si_timer.expires = jiffies + 1;
-#endif
        } else {
                spin_lock_irqsave(&smi_info->count_lock, flags);
                smi_info->long_timeouts++;
                spin_unlock_irqrestore(&smi_info->count_lock, flags);
                smi_info->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES;
-#if defined(CONFIG_HIGH_RES_TIMERS)
-               smi_info->si_timer.arch_cycle_expires = 0;
-#endif
        }
 
  do_add_timer:
        add_timer(&(smi_info->si_timer));
 }
 
-static irqreturn_t si_irq_handler(int irq, void *data, struct pt_regs *regs)
+static irqreturn_t si_irq_handler(int irq, void *data)
 {
        struct smi_info *smi_info = data;
        unsigned long   flags;
@@ -962,20 +929,21 @@ static irqreturn_t si_irq_handler(int irq, void *data, struct pt_regs *regs)
        return IRQ_HANDLED;
 }
 
-static irqreturn_t si_bt_irq_handler(int irq, void *data, struct pt_regs *regs)
+static irqreturn_t si_bt_irq_handler(int irq, void *data)
 {
        struct smi_info *smi_info = data;
        /* We need to clear the IRQ flag for the BT interface. */
        smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG,
                             IPMI_BT_INTMASK_CLEAR_IRQ_BIT
                             | IPMI_BT_INTMASK_ENABLE_IRQ_BIT);
-       return si_irq_handler(irq, data, regs);
+       return si_irq_handler(irq, data);
 }
 
 static int smi_start_processing(void       *send_info,
                                ipmi_smi_t intf)
 {
        struct smi_info *new_smi = send_info;
+       int             enable = 0;
 
        new_smi->intf = intf;
 
@@ -984,7 +952,19 @@ static int smi_start_processing(void       *send_info,
        new_smi->last_timeout_jiffies = jiffies;
        mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES);
 
-       if (new_smi->si_type != SI_BT) {
+       /*
+        * Check if the user forcefully enabled the daemon.
+        */
+       if (new_smi->intf_num < num_force_kipmid)
+               enable = force_kipmid[new_smi->intf_num];
+       /*
+        * The BT interface is efficient enough to not need a thread,
+        * and there is no need for a thread if we have interrupts.
+        */
+       else if ((new_smi->si_type != SI_BT) && (!new_smi->irq))
+               enable = 1;
+
+       if (enable) {
                new_smi->thread = kthread_run(ipmi_thread, new_smi,
                                              "kipmi%d", new_smi->intf_num);
                if (IS_ERR(new_smi->thread)) {
@@ -999,12 +979,21 @@ static int smi_start_processing(void       *send_info,
        return 0;
 }
 
+static void set_maintenance_mode(void *send_info, int enable)
+{
+       struct smi_info   *smi_info = send_info;
+
+       if (!enable)
+               atomic_set(&smi_info->req_events, 0);
+}
+
 static struct ipmi_smi_handlers handlers =
 {
        .owner                  = THIS_MODULE,
        .start_processing       = smi_start_processing,
        .sender                 = sender,
        .request_events         = request_events,
+       .set_maintenance_mode   = set_maintenance_mode,
        .set_run_to_completion  = set_run_to_completion,
        .poll                   = poll,
 };
@@ -1012,7 +1001,6 @@ static struct ipmi_smi_handlers handlers =
 /* There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
    a default IO port, and 1 ACPI/SPMI address.  That sets SI_MAX_DRIVERS */
 
-#define SI_MAX_PARMS 4
 static LIST_HEAD(smi_infos);
 static DEFINE_MUTEX(smi_infos_lock);
 static int smi_num; /* Used to sequence the SMIs */
@@ -1030,14 +1018,24 @@ static int num_ports;
 static int           irqs[SI_MAX_PARMS];
 static int num_irqs;
 static int           regspacings[SI_MAX_PARMS];
-static int num_regspacings = 0;
+static int num_regspacings;
 static int           regsizes[SI_MAX_PARMS];
-static int num_regsizes = 0;
+static int num_regsizes;
 static int           regshifts[SI_MAX_PARMS];
-static int num_regshifts = 0;
+static int num_regshifts;
 static int slave_addrs[SI_MAX_PARMS];
-static int num_slave_addrs = 0;
+static int num_slave_addrs;
 
+#define IPMI_IO_ADDR_SPACE  0
+#define IPMI_MEM_ADDR_SPACE 1
+static char *addr_space_to_str[] = { "i/o", "mem" };
+
+static int hotmod_handler(const char *val, struct kernel_param *kp);
+
+module_param_call(hotmod, hotmod_handler, NULL, NULL, 0200);
+MODULE_PARM_DESC(hotmod, "Add and remove interfaces.  See"
+                " Documentation/IPMI.txt in the kernel sources for the"
+                " gory details.");
 
 module_param_named(trydefaults, si_trydefaults, bool, 0);
 MODULE_PARM_DESC(trydefaults, "Setting this to 'false' will disable the"
@@ -1085,12 +1083,16 @@ MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for"
                 " the controller.  Normally this is 0x20, but can be"
                 " overridden by this parm.  This is an array indexed"
                 " by interface number.");
+module_param_array(force_kipmid, int, &num_force_kipmid, 0);
+MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or"
+                " disabled(0).  Normally the IPMI driver auto-detects"
+                " this, but the value may be overridden by this parm.");
+module_param(unload_when_empty, int, 0);
+MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are"
+                " specified or found, default is 1.  Setting to 0"
+                " is useful for hot add of devices using hotmod.");
 
 
-#define IPMI_IO_ADDR_SPACE  0
-#define IPMI_MEM_ADDR_SPACE 1
-static char *addr_space_to_str[] = { "I/O", "memory" };
-
 static void std_irq_cleanup(struct smi_info *info)
 {
        if (info->si_type == SI_BT)
@@ -1109,7 +1111,7 @@ static int std_irq_setup(struct smi_info *info)
        if (info->si_type == SI_BT) {
                rv = request_irq(info->irq,
                                 si_bt_irq_handler,
-                                SA_INTERRUPT,
+                                IRQF_DISABLED,
                                 DEVICE_NAME,
                                 info);
                if (!rv)
@@ -1119,7 +1121,7 @@ static int std_irq_setup(struct smi_info *info)
        } else
                rv = request_irq(info->irq,
                                 si_irq_handler,
-                                SA_INTERRUPT,
+                                IRQF_DISABLED,
                                 DEVICE_NAME,
                                 info);
        if (rv) {
@@ -1258,7 +1260,7 @@ static void intf_mem_outb(struct si_sm_io *io, unsigned int offset,
 static unsigned char intf_mem_inw(struct si_sm_io *io, unsigned int offset)
 {
        return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift)
-               && 0xff;
+               & 0xff;
 }
 
 static void intf_mem_outw(struct si_sm_io *io, unsigned int offset,
@@ -1270,7 +1272,7 @@ static void intf_mem_outw(struct si_sm_io *io, unsigned int offset,
 static unsigned char intf_mem_inl(struct si_sm_io *io, unsigned int offset)
 {
        return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift)
-               && 0xff;
+               & 0xff;
 }
 
 static void intf_mem_outl(struct si_sm_io *io, unsigned int offset,
@@ -1283,7 +1285,7 @@ static void intf_mem_outl(struct si_sm_io *io, unsigned int offset,
 static unsigned char mem_inq(struct si_sm_io *io, unsigned int offset)
 {
        return (readq((io->addr)+(offset * io->regspacing)) >> io->regshift)
-               && 0xff;
+               & 0xff;
 }
 
 static void mem_outq(struct si_sm_io *io, unsigned int offset,
@@ -1364,6 +1366,250 @@ static int mem_setup(struct smi_info *info)
        return 0;
 }
 
+/*
+ * Parms come in as <op1>[:op2[:op3...]].  ops are:
+ *   add|remove,kcs|bt|smic,mem|i/o,<address>[,<opt1>[,<opt2>[,...]]]
+ * Options are:
+ *   rsp=<regspacing>
+ *   rsi=<regsize>
+ *   rsh=<regshift>
+ *   irq=<irq>
+ *   ipmb=<ipmb addr>
+ */
+enum hotmod_op { HM_ADD, HM_REMOVE };
+struct hotmod_vals {
+       char *name;
+       int  val;
+};
+static struct hotmod_vals hotmod_ops[] = {
+       { "add",        HM_ADD },
+       { "remove",     HM_REMOVE },
+       { NULL }
+};
+static struct hotmod_vals hotmod_si[] = {
+       { "kcs",        SI_KCS },
+       { "smic",       SI_SMIC },
+       { "bt",         SI_BT },
+       { NULL }
+};
+static struct hotmod_vals hotmod_as[] = {
+       { "mem",        IPMI_MEM_ADDR_SPACE },
+       { "i/o",        IPMI_IO_ADDR_SPACE },
+       { NULL }
+};
+
+static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr)
+{
+       char *s;
+       int  i;
+
+       s = strchr(*curr, ',');
+       if (!s) {
+               printk(KERN_WARNING PFX "No hotmod %s given.\n", name);
+               return -EINVAL;
+       }
+       *s = '\0';
+       s++;
+       for (i = 0; hotmod_ops[i].name; i++) {
+               if (strcmp(*curr, v[i].name) == 0) {
+                       *val = v[i].val;
+                       *curr = s;
+                       return 0;
+               }
+       }
+
+       printk(KERN_WARNING PFX "Invalid hotmod %s '%s'\n", name, *curr);
+       return -EINVAL;
+}
+
+static int check_hotmod_int_op(const char *curr, const char *option,
+                              const char *name, int *val)
+{
+       char *n;
+
+       if (strcmp(curr, name) == 0) {
+               if (!option) {
+                       printk(KERN_WARNING PFX
+                              "No option given for '%s'\n",
+                              curr);
+                       return -EINVAL;
+               }
+               *val = simple_strtoul(option, &n, 0);
+               if ((*n != '\0') || (*option == '\0')) {
+                       printk(KERN_WARNING PFX
+                              "Bad option given for '%s'\n",
+                              curr);
+                       return -EINVAL;
+               }
+               return 1;
+       }
+       return 0;
+}
+
+static int hotmod_handler(const char *val, struct kernel_param *kp)
+{
+       char *str = kstrdup(val, GFP_KERNEL);
+       int  rv;
+       char *next, *curr, *s, *n, *o;
+       enum hotmod_op op;
+       enum si_type si_type;
+       int  addr_space;
+       unsigned long addr;
+       int regspacing;
+       int regsize;
+       int regshift;
+       int irq;
+       int ipmb;
+       int ival;
+       int len;
+       struct smi_info *info;
+
+       if (!str)
+               return -ENOMEM;
+
+       /* Kill any trailing spaces, as we can get a "\n" from echo. */
+       len = strlen(str);
+       ival = len - 1;
+       while ((ival >= 0) && isspace(str[ival])) {
+               str[ival] = '\0';
+               ival--;
+       }
+
+       for (curr = str; curr; curr = next) {
+               regspacing = 1;
+               regsize = 1;
+               regshift = 0;
+               irq = 0;
+               ipmb = 0x20;
+
+               next = strchr(curr, ':');
+               if (next) {
+                       *next = '\0';
+                       next++;
+               }
+
+               rv = parse_str(hotmod_ops, &ival, "operation", &curr);
+               if (rv)
+                       break;
+               op = ival;
+
+               rv = parse_str(hotmod_si, &ival, "interface type", &curr);
+               if (rv)
+                       break;
+               si_type = ival;
+
+               rv = parse_str(hotmod_as, &addr_space, "address space", &curr);
+               if (rv)
+                       break;
+
+               s = strchr(curr, ',');
+               if (s) {
+                       *s = '\0';
+                       s++;
+               }
+               addr = simple_strtoul(curr, &n, 0);
+               if ((*n != '\0') || (*curr == '\0')) {
+                       printk(KERN_WARNING PFX "Invalid hotmod address"
+                              " '%s'\n", curr);
+                       break;
+               }
+
+               while (s) {
+                       curr = s;
+                       s = strchr(curr, ',');
+                       if (s) {
+                               *s = '\0';
+                               s++;
+                       }
+                       o = strchr(curr, '=');
+                       if (o) {
+                               *o = '\0';
+                               o++;
+                       }
+                       rv = check_hotmod_int_op(curr, o, "rsp", &regspacing);
+                       if (rv < 0)
+                               goto out;
+                       else if (rv)
+                               continue;
+                       rv = check_hotmod_int_op(curr, o, "rsi", &regsize);
+                       if (rv < 0)
+                               goto out;
+                       else if (rv)
+                               continue;
+                       rv = check_hotmod_int_op(curr, o, "rsh", &regshift);
+                       if (rv < 0)
+                               goto out;
+                       else if (rv)
+                               continue;
+                       rv = check_hotmod_int_op(curr, o, "irq", &irq);
+                       if (rv < 0)
+                               goto out;
+                       else if (rv)
+                               continue;
+                       rv = check_hotmod_int_op(curr, o, "ipmb", &ipmb);
+                       if (rv < 0)
+                               goto out;
+                       else if (rv)
+                               continue;
+
+                       rv = -EINVAL;
+                       printk(KERN_WARNING PFX
+                              "Invalid hotmod option '%s'\n",
+                              curr);
+                       goto out;
+               }
+
+               if (op == HM_ADD) {
+                       info = kzalloc(sizeof(*info), GFP_KERNEL);
+                       if (!info) {
+                               rv = -ENOMEM;
+                               goto out;
+                       }
+
+                       info->addr_source = "hotmod";
+                       info->si_type = si_type;
+                       info->io.addr_data = addr;
+                       info->io.addr_type = addr_space;
+                       if (addr_space == IPMI_MEM_ADDR_SPACE)
+                               info->io_setup = mem_setup;
+                       else
+                               info->io_setup = port_setup;
+
+                       info->io.addr = NULL;
+                       info->io.regspacing = regspacing;
+                       if (!info->io.regspacing)
+                               info->io.regspacing = DEFAULT_REGSPACING;
+                       info->io.regsize = regsize;
+                       if (!info->io.regsize)
+                               info->io.regsize = DEFAULT_REGSPACING;
+                       info->io.regshift = regshift;
+                       info->irq = irq;
+                       if (info->irq)
+                               info->irq_setup = std_irq_setup;
+                       info->slave_addr = ipmb;
+
+                       try_smi_init(info);
+               } else {
+                       /* remove */
+                       struct smi_info *e, *tmp_e;
+
+                       mutex_lock(&smi_infos_lock);
+                       list_for_each_entry_safe(e, tmp_e, &smi_infos, link) {
+                               if (e->io.addr_type != addr_space)
+                                       continue;
+                               if (e->si_type != si_type)
+                                       continue;
+                               if (e->io.addr_data == addr)
+                                       cleanup_one_si(e);
+                       }
+                       mutex_unlock(&smi_infos_lock);
+               }
+       }
+       rv = len;
+ out:
+       kfree(str);
+       return rv;
+}
 
 static __devinit void hardcode_find_bmc(void)
 {
@@ -1438,7 +1684,7 @@ static __devinit void hardcode_find_bmc(void)
 /* Once we get an ACPI failure, we don't try any more, because we go
    through the tables sequentially.  Once we don't find a table, there
    are no more. */
-static int acpi_failure = 0;
+static int acpi_failure;
 
 /* For GPE-type interrupts. */
 static u32 ipmi_acpi_gpe(void *context)
@@ -1549,7 +1795,6 @@ struct SPMITable {
 static __devinit int try_init_acpi(struct SPMITable *spmi)
 {
        struct smi_info  *info;
-       char             *io_type;
        u8               addr_space;
 
        if (spmi->IPMIlegacy != 1) {
@@ -1613,11 +1858,9 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
        info->io.regshift = spmi->addr.register_bit_offset;
 
        if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
-               io_type = "memory";
                info->io_setup = mem_setup;
                info->io.addr_type = IPMI_IO_ADDR_SPACE;
        } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
-               io_type = "I/O";
                info->io_setup = port_setup;
                info->io.addr_type = IPMI_MEM_ADDR_SPACE;
        } else {
@@ -1798,6 +2041,7 @@ static void __devinit dmi_find_bmc(void)
        int                  rv;
 
        while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) {
+               memset(&data, 0, sizeof(data));
                rv = decode_dmi((struct dmi_header *) dev->device_data, &data);
                if (!rv)
                        try_init_dmi(&data);
@@ -1835,7 +2079,7 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
 
        info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (!info)
-               return ENOMEM;
+               return -ENOMEM;
 
        info->addr_source = "PCI";
 
@@ -1856,7 +2100,7 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
                kfree(info);
                printk(KERN_INFO "ipmi_si: %s: Unknown IPMI type: %d\n",
                       pci_name(pdev), class_type);
-               return ENOMEM;
+               return -ENOMEM;
        }
 
        rv = pci_enable_device(pdev);
@@ -1913,7 +2157,7 @@ static int ipmi_pci_resume(struct pci_dev *pdev)
 
 static struct pci_device_id ipmi_pci_devices[] = {
        { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) },
-       { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE) }
+       { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE_MASK) }
 };
 MODULE_DEVICE_TABLE(pci, ipmi_pci_devices);
 
@@ -1998,19 +2242,9 @@ static int try_get_dev_id(struct smi_info *smi_info)
 static int type_file_read_proc(char *page, char **start, off_t off,
                               int count, int *eof, void *data)
 {
-       char            *out = (char *) page;
        struct smi_info *smi = data;
 
-       switch (smi->si_type) {
-           case SI_KCS:
-               return sprintf(out, "kcs\n");
-           case SI_SMIC:
-               return sprintf(out, "smic\n");
-           case SI_BT:
-               return sprintf(out, "bt\n");
-           default:
-               return 0;
-       }
+       return sprintf(page, "%s\n", si_to_str[smi->si_type]);
 }
 
 static int stat_file_read_proc(char *page, char **start, off_t off,
@@ -2046,7 +2280,24 @@ static int stat_file_read_proc(char *page, char **start, off_t off,
        out += sprintf(out, "incoming_messages:     %ld\n",
                       smi->incoming_messages);
 
-       return (out - ((char *) page));
+       return out - page;
+}
+
+static int param_read_proc(char *page, char **start, off_t off,
+                          int count, int *eof, void *data)
+{
+       struct smi_info *smi = data;
+
+       return sprintf(page,
+                      "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n",
+                      si_to_str[smi->si_type],
+                      addr_space_to_str[smi->io.addr_type],
+                      smi->io.addr_data,
+                      smi->io.regspacing,
+                      smi->io.regsize,
+                      smi->io.regshift,
+                      smi->irq,
+                      smi->slave_addr);
 }
 
 /*
@@ -2392,7 +2643,7 @@ static int try_smi_init(struct smi_info *new_smi)
                new_smi->dev = &new_smi->pdev->dev;
                new_smi->dev->driver = &ipmi_driver;
 
-               rv = platform_device_register(new_smi->pdev);
+               rv = platform_device_add(new_smi->pdev);
                if (rv) {
                        printk(KERN_ERR
                               "ipmi_si_intf:"
@@ -2408,6 +2659,7 @@ static int try_smi_init(struct smi_info *new_smi)
                               new_smi,
                               &new_smi->device_id,
                               new_smi->dev,
+                              "bmc",
                               new_smi->slave_addr);
        if (rv) {
                printk(KERN_ERR
@@ -2436,6 +2688,16 @@ static int try_smi_init(struct smi_info *new_smi)
                goto out_err_stop_timer;
        }
 
+       rv = ipmi_smi_add_proc_entry(new_smi->intf, "params",
+                                    param_read_proc, NULL,
+                                    new_smi, THIS_MODULE);
+       if (rv) {
+               printk(KERN_ERR
+                      "ipmi_si: Unable to create proc entry: %d\n",
+                      rv);
+               goto out_err_stop_timer;
+       }
+
        list_add_tail(&new_smi->link, &smi_infos);
 
        mutex_unlock(&smi_infos_lock);
@@ -2524,12 +2786,16 @@ static __devinit int init_ipmi_si(void)
 #endif
 
 #ifdef CONFIG_ACPI
-       if (si_trydefaults)
-               acpi_find_bmc();
+       acpi_find_bmc();
 #endif
 
 #ifdef CONFIG_PCI
-       pci_module_init(&ipmi_pci_driver);
+       rv = pci_register_driver(&ipmi_pci_driver);
+       if (rv){
+               printk(KERN_ERR
+                      "init_ipmi_si: Unable to register PCI driver: %d\n",
+                      rv);
+       }
 #endif
 
        if (si_trydefaults) {
@@ -2544,11 +2810,12 @@ static __devinit int init_ipmi_si(void)
        }
 
        mutex_lock(&smi_infos_lock);
-       if (list_empty(&smi_infos)) {
+       if (unload_when_empty && list_empty(&smi_infos)) {
                mutex_unlock(&smi_infos_lock);
 #ifdef CONFIG_PCI
                pci_unregister_driver(&ipmi_pci_driver);
 #endif
+               driver_unregister(&ipmi_driver);
                printk("ipmi_si: Unable to find any System Interface(s)\n");
                return -ENODEV;
        } else {
@@ -2558,7 +2825,7 @@ static __devinit int init_ipmi_si(void)
 }
 module_init(init_ipmi_si);
 
-static void __devexit cleanup_one_si(struct smi_info *to_clean)
+static void cleanup_one_si(struct smi_info *to_clean)
 {
        int           rv;
        unsigned long flags;