[openib-general] [PATCH] ib_smi: Change from smi to agent names for more code clarity

Hal Rosenstock halr at voltaire.com
Wed Oct 13 06:11:20 PDT 2004


ib_smi: Change from smi to agent names for more code clarity

Index: ib_smi_priv.h
===================================================================
--- ib_smi_priv.h       (revision 976)
+++ ib_smi_priv.h       (working copy)
@@ -23,22 +23,22 @@
   Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
 */
 
-#ifndef __IB_SMI_PRIV_H__
-#define __IB_SMI_PRIV_H__
+#ifndef __IB_AGENT_PRIV_H__
+#define __IB_AGENT_PRIV_H__
 
 #include <linux/pci.h>
 
-#define SPFX "ib_sma: "
+#define SPFX "ib_agent: "
 
-struct ib_smi_send_wr {
+struct ib_agent_send_wr {
        struct list_head send_list;
-       struct ib_mad *smp;
+       struct ib_mad *mad;
        DECLARE_PCI_UNMAP_ADDR(mapping)
 };
 
-struct ib_smi_port_private {
+struct ib_agent_port_private {
        struct list_head port_list;
-       struct list_head send_posted_smp_list;
+       struct list_head send_posted_list;
        spinlock_t send_list_lock;
        int port_num;
        struct ib_mad_agent *dr_smp_mad_agent; /* DR SM class */
@@ -48,4 +48,4 @@
        u64 wr_id;
 };
 
-#endif /* __IB_SMI_PRIV_H__ */
+#endif /* __IB_AGENT_PRIV_H__ */
Index: ib_smi.c
===================================================================
--- ib_smi.c    (revision 976)
+++ ib_smi.c    (working copy)
@@ -34,8 +34,8 @@
 MODULE_AUTHOR("Hal Rosenstock");
 
 
-static spinlock_t ib_smi_port_list_lock = SPIN_LOCK_UNLOCKED;
-static struct list_head ib_smi_port_list;
+static spinlock_t ib_agent_port_list_lock = SPIN_LOCK_UNLOCKED;
+static struct list_head ib_agent_port_list;
 
 /*
  * Fixup a directed route SMP for sending.  Return 0 if the SMP should
be
@@ -300,12 +300,12 @@
                                              slid, smp, smp_response);
 }
 
-void smp_send(struct ib_mad_agent *mad_agent,
-             struct ib_mad *smp,
+void mad_send(struct ib_mad_agent *mad_agent,
+             struct ib_mad *mad,
              struct ib_mad_recv_wc *mad_recv_wc)
 {
-       struct ib_smi_port_private *entry, *port_priv = NULL;
-       struct ib_smi_send_wr *smi_send_wr;
+       struct ib_agent_port_private *entry, *port_priv = NULL;
+       struct ib_agent_send_wr *agent_send_wr;
        struct ib_sge gather_list;
        struct ib_send_wr send_wr;
        struct ib_send_wr *bad_send_wr;
@@ -314,8 +314,8 @@
        unsigned long flags;
 
        /* Find matching MAD agent */
-       spin_lock_irqsave(&ib_smi_port_list_lock, flags);
-       list_for_each_entry(entry, &ib_smi_port_list, port_list) {
+       spin_lock_irqsave(&ib_agent_port_list_lock, flags);
+       list_for_each_entry(entry, &ib_agent_port_list, port_list) {
                if ((entry->dr_smp_mad_agent == mad_agent) ||
                    (entry->lr_smp_mad_agent == mad_agent) ||
                    (entry->pma_mad_agent == mad_agent)) { 
@@ -323,21 +323,21 @@
                        break;
                }
        }
-       spin_unlock_irqrestore(&ib_smi_port_list_lock, flags);
+       spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
        if (!port_priv) {
-               printk(KERN_ERR SPFX "smp_send: no matching MAD agent
0x%x\n",
+               printk(KERN_ERR SPFX "mad_send: no matching MAD agent
0x%x\n",
                       (unsigned int)mad_agent);
                return;
        }
 
-       smi_send_wr = kmalloc(sizeof(*smi_send_wr), GFP_KERNEL);
-       if (!smi_send_wr)
+       agent_send_wr = kmalloc(sizeof(*agent_send_wr), GFP_KERNEL);
+       if (!agent_send_wr)
                return;
-       smi_send_wr->smp = smp;
+       agent_send_wr->mad = mad;
 
        /* PCI mapping */
        gather_list.addr = pci_map_single(mad_agent->device->dma_device,
-                                         smp,
+                                         mad,
                                          sizeof(struct ib_mad),
                                          PCI_DMA_TODEVICE);
        gather_list.length = sizeof(struct ib_mad);
@@ -361,33 +361,33 @@
        ah = ib_create_ah(mad_agent->qp->pd, &ah_attr);
        if (IS_ERR(ah)) {
                printk(KERN_ERR SPFX "No memory for address handle\n");
-               kfree(smp);
+               kfree(mad);
                return;
        }
                                                                                
 
        send_wr.wr.ud.ah = ah;
-       if (smp->mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT) {
+       if (mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT) {
                send_wr.wr.ud.pkey_index = mad_recv_wc->wc->pkey_index;
                send_wr.wr.ud.remote_qkey = IB_QP1_QKEY;
        } else {
                send_wr.wr.ud.pkey_index = 0; /* Should only matter for
GMPs */
                send_wr.wr.ud.remote_qkey = 0; /* for SMPs */
        }
-       send_wr.wr.ud.mad_hdr = (struct ib_mad_hdr *)smp;
+       send_wr.wr.ud.mad_hdr = (struct ib_mad_hdr *)mad;
        send_wr.wr_id = ++port_priv->wr_id;
 
-       pci_unmap_addr_set(smp, smi_send_wr->mapping, gather_list.addr);
+       pci_unmap_addr_set(mad, agent_send_wr->mapping,
gather_list.addr);
 
        /* Send */
        spin_lock_irqsave(&port_priv->send_list_lock, flags);
        if (ib_post_send_mad(mad_agent, &send_wr, &bad_send_wr)) {
                pci_unmap_single(mad_agent->device->dma_device,
-                                pci_unmap_addr(smp,
smi_send_wr->mapping),
+                                pci_unmap_addr(mad,
agent_send_wr->mapping),
                                 sizeof(struct ib_mad),
                                 PCI_DMA_TODEVICE);
        } else {
-               list_add_tail(&smi_send_wr->send_list,
-                             &port_priv->send_posted_smp_list);
+               list_add_tail(&agent_send_wr->send_list,
+                             &port_priv->send_posted_list);
        }
        spin_unlock_irqrestore(&port_priv->send_list_lock, flags);
        ib_destroy_ah(ah);
@@ -420,7 +420,7 @@
                                kfree(smp_response);
                                return 0;
                        }
-                       smp_send(mad_agent, smp_response, mad_recv_wc);
+                       mad_send(mad_agent, smp_response, mad_recv_wc);
                } else
                        kfree(smp_response);
                return 1;
@@ -449,17 +449,17 @@
        return 1;
 }
 
-static void smi_send_handler(struct ib_mad_agent *mad_agent,
-                            struct ib_mad_send_wc *mad_send_wc)
+static void agent_send_handler(struct ib_mad_agent *mad_agent,
+                              struct ib_mad_send_wc *mad_send_wc)
 {
-       struct ib_smi_port_private      *entry, *port_priv = NULL;
-       struct ib_smi_send_wr           *smi_send_wr;
+       struct ib_agent_port_private    *entry, *port_priv = NULL;
+       struct ib_agent_send_wr         *agent_send_wr;
        struct list_head                *send_wr;
        unsigned long                   flags;
 
        /* Find matching MAD agent */
-       spin_lock_irqsave(&ib_smi_port_list_lock, flags);
-       list_for_each_entry(entry, &ib_smi_port_list, port_list) {
+       spin_lock_irqsave(&ib_agent_port_list_lock, flags);
+       list_for_each_entry(entry, &ib_agent_port_list, port_list) {
                if ((entry->dr_smp_mad_agent == mad_agent) ||
                    (entry->lr_smp_mad_agent == mad_agent) ||
                    (entry->pma_mad_agent == mad_agent)) {
@@ -468,44 +468,46 @@
                }
        }
        /* Hold lock longer !!! */
-       spin_unlock_irqrestore(&ib_smi_port_list_lock, flags);
+       spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
        if (!port_priv) {
-               printk(KERN_ERR SPFX "smi_send_handler: no matching MAD
agent "
+               printk(KERN_ERR SPFX "agent_send_handler: no matching
MAD agent 
"
                       "0x%x\n", (unsigned int)mad_agent);
                return;
        }
 
        /* Completion corresponds to first entry on posted MAD send list
*/
        spin_lock_irqsave(&port_priv->send_list_lock, flags);
-       if (list_empty(&port_priv->send_posted_smp_list)) {
+       if (list_empty(&port_priv->send_posted_list)) {
                spin_unlock_irqrestore(&port_priv->send_list_lock,
flags);
                printk(KERN_ERR SPFX "Send completion WR ID 0x%Lx but
send list 
"
                       "is empty\n", mad_send_wc->wr_id);
                return;
        }
                                                                                
 
-       smi_send_wr = list_entry(&port_priv->send_posted_smp_list,
-                                 struct ib_smi_send_wr,
-                                 send_list);
-       send_wr = smi_send_wr->send_list.next;
-       smi_send_wr = container_of(send_wr, struct ib_smi_send_wr,
send_list);
+       agent_send_wr = list_entry(&port_priv->send_posted_list,
+                                   struct ib_agent_send_wr,
+                                   send_list);
+       send_wr = agent_send_wr->send_list.next;
+       agent_send_wr = container_of(send_wr, struct ib_agent_send_wr,
+                                    send_list);
 
        /* Remove from posted send SMP list */
-        list_del(&smi_send_wr->send_list);
+        list_del(&agent_send_wr->send_list);
         spin_unlock_irqrestore(&port_priv->send_list_lock, flags);
 
        /* Unmap PCI */
        pci_unmap_single(mad_agent->device->dma_device,
-                        pci_unmap_addr(smi_send_wr->smp,
smi_send_wr->mapping),
+                        pci_unmap_addr(agent_send_wr->smp,
+                                       agent_send_wr->mapping),
                         sizeof(struct ib_mad),
                         PCI_DMA_TODEVICE);
 
        /* Release allocated memory */
-       kfree(smi_send_wr->smp);
+       kfree(agent_send_wr->mad);
 }
 
-static void smi_recv_handler(struct ib_mad_agent *mad_agent,
-                            struct ib_mad_recv_wc *mad_recv_wc)
+static void agent_recv_handler(struct ib_mad_agent *mad_agent,
+                              struct ib_mad_recv_wc *mad_recv_wc)
 {
        smi_recv_smp(mad_agent, 
                     (struct ib_smp *)mad_recv_wc->recv_buf->mad,
@@ -515,7 +517,7 @@
        ib_free_recv_mad(mad_recv_wc);
 }
 
-static int ib_smi_port_open(struct ib_device *device, int port_num)
+static int ib_agent_port_open(struct ib_device *device, int port_num)
 {
        int ret;
        u64 iova = 0;
@@ -523,20 +525,20 @@
                .addr = 0,
                .size = (unsigned long) high_memory - PAGE_OFFSET
        };
-       struct ib_smi_port_private *entry, *port_priv = NULL;
+       struct ib_agent_port_private *entry, *port_priv = NULL;
        struct ib_mad_reg_req reg_req;
        unsigned long flags;
 
        /* First, check if port already open for SMI */
-       spin_lock_irqsave(&ib_smi_port_list_lock, flags);
-       list_for_each_entry(entry, &ib_smi_port_list, port_list) {
+       spin_lock_irqsave(&ib_agent_port_list_lock, flags);
+       list_for_each_entry(entry, &ib_agent_port_list, port_list) {
                if (entry->dr_smp_mad_agent->device == device && 
                    entry->port_num == port_num) {
                        port_priv = entry;
                        break;
                }
        }
-       spin_unlock_irqrestore(&ib_smi_port_list_lock, flags);
+       spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
        if (port_priv) {
                printk(KERN_DEBUG SPFX "%s port %d already open\n",
                       device->name, port_num);
@@ -546,7 +548,7 @@
        /* Create new device info */
        port_priv = kmalloc(sizeof *port_priv, GFP_KERNEL);
        if (!port_priv) {
-               printk(KERN_ERR SPFX "No memory for
ib_smi_port_private\n");
+               printk(KERN_ERR SPFX "No memory for
ib_agent_port_private\n");
                ret = -ENOMEM;
                goto error1;
        }
@@ -555,7 +557,7 @@
        port_priv->port_num = port_num;
        port_priv->wr_id = 0;
        spin_lock_init(&port_priv->send_list_lock);
-       INIT_LIST_HEAD(&port_priv->send_posted_smp_list);
+       INIT_LIST_HEAD(&port_priv->send_posted_list);
 
        /* Obtain MAD agent for directed route SM class */
        reg_req.mgmt_class = IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE;
@@ -571,8 +573,8 @@
        port_priv->dr_smp_mad_agent = ib_register_mad_agent(device,
port_num,
                                                            IB_QPT_SMI,
                                                           &reg_req, 0,
-                                                         
&smi_send_handler,
-                                                         
&smi_recv_handler,
+                                                         
&agent_send_handler,
+                                                         
&agent_recv_handler,
                                                            NULL);
        if (IS_ERR(port_priv->dr_smp_mad_agent)) {
                ret = PTR_ERR(port_priv->dr_smp_mad_agent);
@@ -584,8 +586,8 @@
        port_priv->lr_smp_mad_agent = ib_register_mad_agent(device,
port_num,
                                                            IB_QPT_SMI,
                                                           &reg_req, 0,
-                                                         
&smi_send_handler,
-                                                         
&smi_recv_handler,
+                                                         
&agent_send_handler,
+                                                         
&agent_recv_handler,
                                                            NULL);
        if (IS_ERR(port_priv->lr_smp_mad_agent)) {
                ret = PTR_ERR(port_priv->lr_smp_mad_agent);
@@ -599,8 +601,8 @@
         port_priv->pma_mad_agent = ib_register_mad_agent(device,
port_num,
                                                         IB_QPT_GSI,
                                                        &reg_req, 0,
-                                                      
&smi_send_handler,
-                                                      
&smi_recv_handler,
+                                                      
&agent_send_handler,
+                                                      
&agent_recv_handler,
                                                         NULL);
        if (IS_ERR(port_priv->pma_mad_agent)) {
                ret = PTR_ERR(port_priv->pma_mad_agent);
@@ -616,9 +618,9 @@
                goto error5;
        } 
 
-       spin_lock_irqsave(&ib_smi_port_list_lock, flags);
-       list_add_tail(&port_priv->port_list, &ib_smi_port_list);
-       spin_unlock_irqrestore(&ib_smi_port_list_lock, flags);
+       spin_lock_irqsave(&ib_agent_port_list_lock, flags);
+       list_add_tail(&port_priv->port_list, &ib_agent_port_list);
+       spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
 
        return 0;
 
@@ -634,13 +636,13 @@
        return ret;
 }
 
-static int ib_smi_port_close(struct ib_device *device, int port_num)
+static int ib_agent_port_close(struct ib_device *device, int port_num)
 {
-       struct ib_smi_port_private *entry, *port_priv = NULL;
+       struct ib_agent_port_private *entry, *port_priv = NULL;
        unsigned long flags;
 
-       spin_lock_irqsave(&ib_smi_port_list_lock, flags);
-       list_for_each_entry(entry, &ib_smi_port_list, port_list) {
+       spin_lock_irqsave(&ib_agent_port_list_lock, flags);
+       list_for_each_entry(entry, &ib_agent_port_list, port_list) {
                if (entry->dr_smp_mad_agent->device == device && 
                    entry->port_num == port_num) {
                        port_priv = entry;
@@ -650,12 +652,12 @@
 
        if (port_priv == NULL) {
                printk(KERN_ERR SPFX "Port %d not found\n", port_num);
-               spin_unlock_irqrestore(&ib_smi_port_list_lock, flags);
+               spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
                return -ENODEV;
        }
 
        list_del(&port_priv->port_list);
-       spin_unlock_irqrestore(&ib_smi_port_list_lock, flags);
+       spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
 
        ib_dereg_mr(port_priv->mr);
        ib_unregister_mad_agent(port_priv->pma_mad_agent);
@@ -666,7 +668,7 @@
        return 0;
 }
 
-static void ib_smi_init_device(struct ib_device *device)
+static void ib_agent_init_device(struct ib_device *device)
 {
        int ret, num_ports, cur_port, i, ret2;
        struct ib_device_attr device_attr;
@@ -686,7 +688,7 @@
        }
 
        for (i = 0; i < num_ports; i++, cur_port++) {
-               ret = ib_smi_port_open(device, cur_port);
+               ret = ib_agent_port_open(device, cur_port);
                if (ret) {
                        printk(KERN_ERR SPFX "Couldn't open %s port
%d\n",
                               device->name, cur_port);
@@ -699,7 +701,7 @@
 error_device_open:
        while (i > 0) {
                cur_port--;
-               ret2 = ib_smi_port_close(device, 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);
@@ -711,7 +713,7 @@
        return;
 }
                                                                                
 
-static void ib_smi_remove_device(struct ib_device *device)
+static void ib_agent_remove_device(struct ib_device *device)
 {
        int ret, i, num_ports, cur_port, ret2;
        struct ib_device_attr device_attr;
@@ -730,7 +732,7 @@
                cur_port = 1;
        }
        for (i = 0; i < num_ports; i++, cur_port++) {
-               ret2 = ib_smi_port_close(device, 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);
@@ -743,27 +745,27 @@
        return;
 }
 
-static struct ib_client ib_smi_client = {
-        .name = "ib_smi",
-        .add = ib_smi_init_device,
-        .remove = ib_smi_remove_device
+static struct ib_client ib_agent_client = {
+        .name = "ib_agent",
+        .add = ib_agent_init_device,
+        .remove = ib_agent_remove_device
 };
                                                                                 
-static int __init ib_smi_init(void)
+static int __init ib_agent_init(void)
 {
-       INIT_LIST_HEAD(&ib_smi_port_list);
-        if (ib_register_client(&ib_smi_client)) {
-                printk(KERN_ERR SPFX "Couldn't register ib_smi
client\n");
+       INIT_LIST_HEAD(&ib_agent_port_list);
+        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_smi_exit(void)
+static void __exit ib_agent_exit(void)
 {
-       ib_unregister_client(&ib_smi_client);
+       ib_unregister_client(&ib_agent_client);
 }
 
-module_init(ib_smi_init);
-module_exit(ib_smi_exit);
+module_init(ib_agent_init);
+module_exit(ib_agent_exit);

                                     




More information about the general mailing list