VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / char / ipmi / ipmi_msghandler.c
index c1e4abf..83ae6f5 100644 (file)
@@ -46,7 +46,7 @@
 #include <linux/init.h>
 #include <linux/proc_fs.h>
 
-#define IPMI_MSGHANDLER_VERSION "v31"
+#define IPMI_MSGHANDLER_VERSION "v32"
 
 struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
 static int ipmi_init_msghandler(void);
@@ -123,6 +123,12 @@ struct ipmi_channel
        unsigned char protocol;
 };
 
+struct ipmi_proc_entry
+{
+       char                   *name;
+       struct ipmi_proc_entry *next;
+};
+
 #define IPMI_IPMB_NUM_SEQ      64
 #define IPMI_MAX_CHANNELS       8
 struct ipmi_smi
@@ -149,6 +155,11 @@ struct ipmi_smi
        struct ipmi_smi_handlers *handlers;
        void                     *send_info;
 
+       /* A list of proc entries for this interface.  This does not
+          need a lock, only one thread creates it and only one thread
+          destroys it. */
+       struct ipmi_proc_entry *proc_entries;
+
        /* 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
@@ -896,7 +907,7 @@ ipmb_checksum(unsigned char *data, int size)
 }
 
 static inline void format_ipmb_msg(struct ipmi_smi_msg   *smi_msg,
-                                  struct ipmi_msg       *msg,
+                                  struct kernel_ipmi_msg *msg,
                                   struct ipmi_ipmb_addr *ipmb_addr,
                                   long                  msgid,
                                   unsigned char         ipmb_seq,
@@ -938,7 +949,7 @@ static inline void format_ipmb_msg(struct ipmi_smi_msg   *smi_msg,
 }
 
 static inline void format_lan_msg(struct ipmi_smi_msg   *smi_msg,
-                                 struct ipmi_msg       *msg,
+                                 struct kernel_ipmi_msg *msg,
                                  struct ipmi_lan_addr  *lan_addr,
                                  long                  msgid,
                                  unsigned char         ipmb_seq,
@@ -982,7 +993,7 @@ static inline int i_ipmi_request(ipmi_user_t          user,
                                 ipmi_smi_t           intf,
                                 struct ipmi_addr     *addr,
                                 long                 msgid,
-                                struct ipmi_msg      *msg,
+                                struct kernel_ipmi_msg *msg,
                                 void                 *user_msg_data,
                                 void                 *supplied_smi,
                                 struct ipmi_recv_msg *supplied_recv,
@@ -1324,7 +1335,7 @@ static inline int i_ipmi_request(ipmi_user_t          user,
                goto out_err;
        }
 
-#if DEBUG_MSGING
+#ifdef DEBUG_MSGING
        {
                int m;
                for (m=0; m<smi_msg->data_size; m++)
@@ -1345,7 +1356,7 @@ static inline int i_ipmi_request(ipmi_user_t          user,
 int ipmi_request(ipmi_user_t      user,
                 struct ipmi_addr *addr,
                 long             msgid,
-                struct ipmi_msg  *msg,
+                struct kernel_ipmi_msg  *msg,
                 void             *user_msg_data,
                 int              priority)
 {
@@ -1365,7 +1376,7 @@ int ipmi_request(ipmi_user_t      user,
 int ipmi_request_settime(ipmi_user_t      user,
                         struct ipmi_addr *addr,
                         long             msgid,
-                        struct ipmi_msg  *msg,
+                        struct kernel_ipmi_msg  *msg,
                         void             *user_msg_data,
                         int              priority,
                         int              retries,
@@ -1388,7 +1399,7 @@ int ipmi_request_settime(ipmi_user_t      user,
 int ipmi_request_supply_msgs(ipmi_user_t          user,
                             struct ipmi_addr     *addr,
                             long                 msgid,
-                            struct ipmi_msg      *msg,
+                            struct kernel_ipmi_msg *msg,
                             void                 *user_msg_data,
                             void                 *supplied_smi,
                             struct ipmi_recv_msg *supplied_recv,
@@ -1411,7 +1422,7 @@ int ipmi_request_supply_msgs(ipmi_user_t          user,
 int ipmi_request_with_source(ipmi_user_t      user,
                             struct ipmi_addr *addr,
                             long             msgid,
-                            struct ipmi_msg  *msg,
+                            struct kernel_ipmi_msg  *msg,
                             void             *user_msg_data,
                             int              priority,
                             unsigned char    source_address,
@@ -1515,18 +1526,36 @@ int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
                            read_proc_t *read_proc, write_proc_t *write_proc,
                            void *data, struct module *owner)
 {
-       struct proc_dir_entry *file;
-       int                   rv = 0;
+       struct proc_dir_entry  *file;
+       int                    rv = 0;
+       struct ipmi_proc_entry *entry;
+
+       /* Create a list element. */
+       entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+       if (!entry)
+               return -ENOMEM;
+       entry->name = kmalloc(strlen(name)+1, GFP_KERNEL);
+       if (!entry->name) {
+               kfree(entry);
+               return -ENOMEM;
+       }
+       strcpy(entry->name, name);
 
        file = create_proc_entry(name, 0, smi->proc_dir);
-       if (!file)
+       if (!file) {
+               kfree(entry->name);
+               kfree(entry);
                rv = -ENOMEM;
-       else {
+       else {
                file->nlink = 1;
                file->data = data;
                file->read_proc = read_proc;
                file->write_proc = write_proc;
                file->owner = owner;
+
+               /* Stick it on the list. */
+               entry->next = smi->proc_entries;
+               smi->proc_entries = entry;
        }
 
        return rv;
@@ -1562,10 +1591,25 @@ static int add_proc_entries(ipmi_smi_t smi, int num)
        return rv;
 }
 
+static void remove_proc_entries(ipmi_smi_t smi)
+{
+       struct ipmi_proc_entry *entry;
+
+       while (smi->proc_entries) {
+               entry = smi->proc_entries;
+               smi->proc_entries = entry->next;
+
+               remove_proc_entry(entry->name, smi->proc_dir);
+               kfree(entry->name);
+               kfree(entry);
+       }
+       remove_proc_entry(smi->proc_dir_name, proc_ipmi_root);
+}
+
 static int
 send_channel_info_cmd(ipmi_smi_t intf, int chan)
 {
-       struct ipmi_msg                   msg;
+       struct kernel_ipmi_msg            msg;
        unsigned char                     data[1];
        struct ipmi_system_interface_addr si;
 
@@ -1604,6 +1648,22 @@ channel_handler(ipmi_smi_t intf, struct ipmi_smi_msg *msg)
                /* It's the one we want */
                if (msg->rsp[2] != 0) {
                        /* Got an error from the channel, just go on. */
+
+                       if (msg->rsp[2] == 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->channels[0].medium
+                                       = IPMI_CHANNEL_MEDIUM_IPMB;
+                               intf->channels[0].protocol
+                                       = IPMI_CHANNEL_PROTOCOL_IPMB;
+                               rv = -ENOSYS;
+
+                               intf->curr_channel = IPMI_MAX_CHANNELS;
+                               wake_up(&intf->waitq);
+                               goto out;
+                       }
                        goto next_channel;
                }
                if (msg->rsp_size < 6) {
@@ -1627,10 +1687,20 @@ channel_handler(ipmi_smi_t intf, struct ipmi_smi_msg *msg)
                        wake_up(&intf->waitq);
 
                        printk(KERN_WARNING "ipmi_msghandler: Error sending"
-                              "channel information: 0x%x\n",
+                              "channel information: %d\n",
                               rv);
                }
        }
+ out:
+       return;
+}
+
+void ipmi_poll_interface(ipmi_user_t user)
+{
+       ipmi_smi_t intf = user->intf;
+
+       if (intf->handlers->poll)
+               intf->handlers->poll(intf->send_info);
 }
 
 int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
@@ -1749,8 +1819,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
 
        if (rv) {
                if (new_intf->proc_dir)
-                       remove_proc_entry(new_intf->proc_dir_name,
-                                         proc_ipmi_root);
+                       remove_proc_entries(new_intf);
                kfree(new_intf);
        }
 
@@ -1806,8 +1875,7 @@ int ipmi_unregister_smi(ipmi_smi_t intf)
        {
                for (i=0; i<MAX_IPMI_INTERFACES; i++) {
                        if (ipmi_interfaces[i] == intf) {
-                               remove_proc_entry(intf->proc_dir_name,
-                                                 proc_ipmi_root);
+                               remove_proc_entries(intf);
                                spin_lock_irqsave(&interfaces_lock, flags);
                                ipmi_interfaces[i] = NULL;
                                clean_up_interface_data(intf);
@@ -1965,7 +2033,7 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t          intf,
                msg->data[10] = ipmb_checksum(&(msg->data[6]), 4);
                msg->data_size = 11;
 
-#if DEBUG_MSGING
+#ifdef DEBUG_MSGING
        {
                int m;
                printk("Invalid command:");
@@ -2356,7 +2424,7 @@ static int handle_new_recv_msg(ipmi_smi_t          intf,
        int requeue;
        int chan;
 
-#if DEBUG_MSGING
+#ifdef DEBUG_MSGING
        int m;
        printk("Recv:");
        for (m=0; m<msg->rsp_size; m++)
@@ -2571,7 +2639,7 @@ send_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg,
           MC, which don't get resent. */
        intf->handlers->sender(intf->send_info, smi_msg, 0);
 
-#if DEBUG_MSGING
+#ifdef DEBUG_MSGING
        {
                int m;
                printk("Resend: ");
@@ -2805,7 +2873,7 @@ static void device_id_fetcher(ipmi_smi_t intf, struct ipmi_smi_msg *msg)
 
 static void send_panic_events(char *str)
 {
-       struct ipmi_msg                   msg;
+       struct kernel_ipmi_msg            msg;
        ipmi_smi_t                        intf;
        unsigned char                     data[16];
        int                               i;
@@ -3030,7 +3098,7 @@ static struct notifier_block panic_block = {
        200   /* priority: INT_MAX >= x >= 0 */
 };
 
-static __init int ipmi_init_msghandler(void)
+static int ipmi_init_msghandler(void)
 {
        int i;
 
@@ -3044,7 +3112,7 @@ static __init int ipmi_init_msghandler(void)
                ipmi_interfaces[i] = NULL;
        }
 
-       proc_ipmi_root = proc_mkdir("ipmi", 0);
+       proc_ipmi_root = proc_mkdir("ipmi", NULL);
        if (!proc_ipmi_root) {
            printk("Unable to create IPMI proc dir");
            return -ENOMEM;
@@ -3065,6 +3133,12 @@ static __init int ipmi_init_msghandler(void)
        return 0;
 }
 
+static __init int ipmi_init_msghandler_mod(void)
+{
+       ipmi_init_msghandler();
+       return 0;
+}
+
 static __exit void cleanup_ipmi(void)
 {
        int count;
@@ -3101,7 +3175,7 @@ static __exit void cleanup_ipmi(void)
 }
 module_exit(cleanup_ipmi);
 
-module_init(ipmi_init_msghandler);
+module_init(ipmi_init_msghandler_mod);
 MODULE_LICENSE("GPL");
 
 EXPORT_SYMBOL(ipmi_alloc_recv_msg);
@@ -3112,6 +3186,7 @@ EXPORT_SYMBOL(ipmi_request);
 EXPORT_SYMBOL(ipmi_request_settime);
 EXPORT_SYMBOL(ipmi_request_supply_msgs);
 EXPORT_SYMBOL(ipmi_request_with_source);
+EXPORT_SYMBOL(ipmi_poll_interface);
 EXPORT_SYMBOL(ipmi_register_smi);
 EXPORT_SYMBOL(ipmi_unregister_smi);
 EXPORT_SYMBOL(ipmi_register_for_cmd);