[openib-general] [PATCH] ib_smi: Add port number into receive SMI checking

Hal Rosenstock halr at voltaire.com
Wed Oct 13 07:38:05 PDT 2004


ib_smi: Add port number into receive SMI checking

Index: ib_smi.c
===================================================================
--- ib_smi.c    (revision 981)
+++ ib_smi.c    (working copy)
@@ -148,7 +148,8 @@
  * dropped.
  */
 static int smi_handle_dr_smp_recv(struct ib_mad_agent *mad_agent,
-                                 struct ib_smp *smp)
+                                 struct ib_smp *smp,
+                                 int phys_port_cnt)
 {
        u8 hop_ptr, hop_cnt;
 
@@ -168,8 +169,7 @@
 
                        smp->return_path[hop_ptr] = mad_agent->port_num;
                        /* smp->hop_ptr updated when sending */
-                       return 1; /*(smp->initial_path[hop_ptr+1] <=
-                               mad_agent->device->phys_port_cnt); */
+                       return (smp->initial_path[hop_ptr+1] <=
phys_port_cnt);
                }
 
                /* C14-9:3 -- We're at the end of the DR segment of path
*/
@@ -201,8 +201,7 @@
                                return 0;
 
                        /* smp->hop_ptr updated when sending */
-                       return 1; /*(smp->return_path[hop_ptr-1] <=
-                               mad_agent->device->phys_port_cnt); */
+                       return (smp->return_path[hop_ptr-1] <=
phys_port_cnt);
                }
 
                /* C14-13:3 -- We're at the end of the DR segment of
path */
@@ -227,12 +226,13 @@
  * the spec.  Return 0 if the SMP should be dropped.
  */
 static int smi_handle_smp_recv(struct ib_mad_agent *mad_agent,
-                              struct ib_smp *smp)
+                              struct ib_smp *smp,
+                              int phys_port_cnt)
 {
        switch (smp->mgmt_class)
        {
        case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
-               return smi_handle_dr_smp_recv(mad_agent, smp);
+               return smi_handle_dr_smp_recv(mad_agent, smp,
phys_port_cnt);
        default:        /* LR SM or PerfMgmt classes */
                return 1;
        }
@@ -396,7 +396,8 @@
 int smi_send_smp(struct ib_mad_agent *mad_agent,
                 struct ib_smp *smp,
                 struct ib_mad_recv_wc *mad_recv_wc,
-                u16 slid)
+                u16 slid,
+                int phys_port_cnt)
 {
        struct ib_mad *smp_response;
        int ret;
@@ -415,7 +416,8 @@
                                        smp_response, slid);
                if (ret & IB_MAD_RESULT_SUCCESS) {
                        if (!smi_handle_smp_recv(mad_agent,
-                                                (struct ib_smp
*)smp_response))
 {
+                                                (struct ib_smp
*)smp_response,
+                                                phys_port_cnt)) {
                                /* SMI failed receive */
                                kfree(smp_response);
                                return 0;
@@ -432,16 +434,17 @@
 
 int smi_recv_smp(struct ib_mad_agent *mad_agent,
                 struct ib_smp *smp,
-                struct ib_mad_recv_wc *mad_recv_wc)
+                struct ib_mad_recv_wc *mad_recv_wc,
+                int phys_port_cnt)
 {
-       if (!smi_handle_smp_recv(mad_agent, smp)) {
+       if (!smi_handle_smp_recv(mad_agent, smp, phys_port_cnt)) {
                /* SMI failed receive */
                return 0;
        }
 
        if (smi_check_forward_smp(mad_agent, smp)) {
                smi_send_smp(mad_agent, smp, mad_recv_wc,
-                            mad_recv_wc->wc->slid);
+                            mad_recv_wc->wc->slid, phys_port_cnt);
                return 0;
        }
 
@@ -509,16 +512,36 @@
 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,
-                    mad_recv_wc);
+       struct ib_agent_port_private *entry, *port_priv = NULL;
+       unsigned long flags;
 
+       /* Find matching MAD agent */
+       spin_lock_irqsave(&ib_agent_port_list_lock, flags);
+       list_for_each_entry(entry, &ib_agent_port_list, port_list) {
+               if ((entry->dr_smp_agent == mad_agent) ||
+                   (entry->lr_smp_agent == mad_agent) ||
+                   (entry->perf_mgmt_agent == mad_agent)) {
+                       port_priv = entry;
+                       break;
+               }
+       }
+       spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
+       if (!port_priv) {
+               printk(KERN_ERR SPFX "agent_recv_handler: no matching
MAD agent 
0x%x\n",
+                      (unsigned int)mad_agent);
+
+       } else {
+               smi_recv_smp(mad_agent, 
+                            (struct ib_smp
*)mad_recv_wc->recv_buf->mad,
+                            mad_recv_wc, port_priv->phys_port_cnt);
+       }
+
        /* Free received MAD */
        ib_free_recv_mad(mad_recv_wc);
 }
 
 static int ib_agent_port_open(struct ib_device *device, int port_num,
-                             int num_ports)
+                             int phys_port_cnt)
 {
        int ret;
        u64 iova = 0;
@@ -556,7 +579,7 @@
 
        memset(port_priv, 0, sizeof *port_priv);
        port_priv->port_num = port_num;
-       port_priv->phys_port_cnt = num_ports;
+       port_priv->phys_port_cnt = phys_port_cnt;
        port_priv->wr_id = 0;
        spin_lock_init(&port_priv->send_list_lock);
        INIT_LIST_HEAD(&port_priv->send_posted_list);





More information about the general mailing list