[openib-general] [PATCH] Combine ib_agent into ib_mad module

Hal Rosenstock
Tue Oct 26 09:55:50 PDT 2004


Combine ib_agent into ib_mad module
The only downside of this currently is that when removing some module
which uses the AL will cause the AL to be removed. Is there a way to
stop a dependency from unloading ?

Index: ib_agent.c
===================================================================
--- ib_agent.c  (revision 1073)
+++ ib_agent.c  (working copy)
@@ -29,12 +29,7 @@
 #include <asm/bug.h>
 
 
-MODULE_LICENSE("Dual BSD/GPL");
-MODULE_DESCRIPTION("kernel IB agents (SMA and PMA)");
-MODULE_AUTHOR("Sean Hefty");
-MODULE_AUTHOR("Hal Rosenstock");
 
-
 static spinlock_t ib_agent_port_list_lock = SPIN_LOCK_UNLOCKED;
 static LIST_HEAD(ib_agent_port_list);
 
@@ -619,7 +614,7 @@
        ib_free_recv_mad(mad_recv_wc);
 }
 
-static int ib_agent_port_open(struct ib_device *device, int port_num,
+int ib_agent_port_open(struct ib_device *device, int port_num,
                              int phys_port_cnt)
 {
        int ret;
@@ -732,7 +727,7 @@
        return ret;
 }
 
-static int ib_agent_port_close(struct ib_device *device, int port_num)
+int ib_agent_port_close(struct ib_device *device, int port_num)
 {
        struct ib_agent_port_private *port_priv;
        unsigned long flags;
@@ -757,103 +752,3 @@
        return 0;
 }
 
-static void ib_agent_init_device(struct ib_device *device)
-{
-       int ret, num_ports, cur_port, i, ret2;
-       struct ib_device_attr device_attr;
-
-       ret = ib_query_device(device, &device_attr);
-       if (ret) {
-               printk(KERN_ERR SPFX "Couldn't query device %s\n", device->name);
-               goto error_device_query;
-       }
-
-       if (device->node_type == IB_NODE_SWITCH) {
-               num_ports = 1;
-               cur_port = 0;
-       } else {
-               num_ports = device_attr.phys_port_cnt;
-               cur_port = 1;
-       }
-
-       for (i = 0; i < num_ports; i++, cur_port++) {
-               ret = ib_agent_port_open(device, cur_port, num_ports);
-               if (ret) {
-                       printk(KERN_ERR SPFX "Couldn't open %s port %d\n",
-                              device->name, cur_port);
-                       goto error_device_open;
-               }
-       }
-
-       goto error_device_query;
-
-error_device_open:
-       while (i > 0) {
-               cur_port--;
-               ret2 = ib_agent_port_close(device, cur_port);
-               if (ret2) {
-                       printk(KERN_ERR SPFX "Couldn't close %s port %d\n",
-                              device->name, cur_port);
-               }
-               i--;
-       }
-
-error_device_query:
-       return;
-}
-                                                                                
-static void ib_agent_remove_device(struct ib_device *device)
-{
-       int ret, i, num_ports, cur_port, ret2;
-       struct ib_device_attr device_attr;
-
-       ret = ib_query_device(device, &device_attr);
-       if (ret) {
-               printk(KERN_ERR SPFX "Couldn't query device %s\n", device->name);
-               goto error_device_query;
-       }
-
-       if (device->node_type == IB_NODE_SWITCH) {
-               num_ports = 1;
-               cur_port = 0;
-       } else {
-               num_ports = device_attr.phys_port_cnt;
-               cur_port = 1;
-       }
-       for (i = 0; i < num_ports; i++, cur_port++) {
-               ret2 = ib_agent_port_close(device, cur_port);
-               if (ret2) {
-                       printk(KERN_ERR SPFX "Couldn't close %s port %d\n",
-                              device->name, cur_port);
-                       if (!ret)
-                               ret = ret2;
-               }
-       }
-                                                                                
-error_device_query:
-       return;
-}
-
-static struct ib_client ib_agent_client = {
-        .name = "ib_agent",
-        .add = ib_agent_init_device,
-        .remove = ib_agent_remove_device
-};
-                                                                                
-static int __init ib_agent_init(void)
-{
-        if (ib_register_client(&ib_agent_client)) {
-                printk(KERN_ERR SPFX "Couldn't register ib_agent
client\n");
-                return -EINVAL;
-        }
-                                                                                
-        return 0;
-}
-                                                                                
-static void __exit ib_agent_exit(void)
-{
-       ib_unregister_client(&ib_agent_client);
-}
-
-module_init(ib_agent_init);
-module_exit(ib_agent_exit);
Index: ib_mad.c
===================================================================
--- ib_mad.c    (revision 1071)
+++ ib_mad.c    (working copy)
@@ -1917,6 +1917,12 @@
        return 0;
 }
 
+
+extern int ib_agent_port_open(struct ib_device *device, int port_num,
+                             int phys_port_cnt);
+extern int ib_agent_port_close(struct ib_device *device, int port_num);
+
+
 static void ib_mad_init_device(struct ib_device *device)
 {
        int ret, num_ports, cur_port, i, ret2;
@@ -1942,6 +1948,12 @@
                               device->name, cur_port);
                        goto error_device_open;
                }
+               ret = ib_agent_port_open(device, cur_port, num_ports);
+               if (ret) {
+                       printk(KERN_ERR PFX "Couldn't open %s port %d for agents\n",
+                              device->name, cur_port);
+                       goto error_device_open;
+               }
        }
 
        goto error_device_query;
@@ -1949,6 +1961,11 @@
 error_device_open:
        while (i > 0) {
                cur_port--;
+               ret2 = ib_agent_port_close(device, cur_port);
+               if (ret2) {
+                       printk(KERN_ERR PFX "Couldn't close %s port %d for agent\n",
+                              device->name, cur_port);
+               }
                ret2 = ib_mad_port_close(device, cur_port);
                if (ret2) {
                        printk(KERN_ERR PFX "Couldn't close %s port %d\n",
@@ -1980,6 +1997,13 @@
                cur_port = 1;
        }
        for (i = 0; i < num_ports; i++, cur_port++) {
+               ret2 = ib_agent_port_close(device, cur_port);
+               if (ret2) {
+                       printk(KERN_ERR PFX "Couldn't close %s port %d for agent\n",
+                              device->name, cur_port);
+                       if (!ret)
+                               ret = ret2;
+               }
                ret2 = ib_mad_port_close(device, cur_port);
                if (ret2) {
                        printk(KERN_ERR PFX "Couldn't close %s port %d\n",
@@ -2022,6 +2046,7 @@
                ret = -EINVAL;
                goto error2;
        }
+
        return 0;
 
 error2:
Index: Makefile
===================================================================
--- Makefile    (revision 1071)
+++ Makefile    (working copy)
@@ -2,10 +2,8 @@
 
 obj-$(CONFIG_INFINIBAND_ACCESS_LAYER) += \
     ib_al.o \
-    ib_agt.o 
+    ib_al_test.o
 
 ib_al-objs := \
-    ib_mad.o
-
-ib_agt-objs := \
+    ib_mad.o \
     ib_agent.o
Index: README
===================================================================
--- README      (revision 1071)
+++ README      (working copy)
@@ -42,7 +42,6 @@
 
 6. You are now ready to run the new access layer as follows:
        /sbin/modprobe ib_mthca
-       /sbin/modprobe ib_al (This can be skipped)
-       /sbin/modprobe ib_agt
+       /sbin/modprobe ib_al
 Note that starting ib_al does not cause ib_mthca to be started.
 





More information about the openib-general mailing list