[openib-general] [RFC] [PATCH] mad.c: Add support for switch SMI

Hal Rosenstock halr at voltaire.com
Sat Feb 11 08:39:35 PST 2006


mad.c: Add support for switch SMI

This is a first cut of adding in switch SMI support. I have tested this
with HCAs to make sure I didn't break anything but I have no way of
testing this with a switch. The biggest unknown to me is whether the SMI
itself (smi.c) is correct for switches. It was written from the IB spec.

In order to support this on a switch, there are 2 things that are needed
from the driver:

1. On the receive side, the physical port number that a DR SMP was
received on must be filled into the ib_wc.

2. On the send side, the driver must support the optional query_ah verb
in order to obtain the send side port number (actual switch external
port on which to send the DR SMP).

I'm interested in feedback on the latter point (is there a better way ?)
and any testing experience/feedback with this.

Signed-off-by: Hal Rosenstock <halr at voltaire.com>

Index: mad.c
===================================================================
--- mad.c	(revision 5369)
+++ mad.c	(working copy)
@@ -661,9 +661,27 @@ static int handle_outgoing_dr_smp(struct
 	struct ib_mad_port_private *port_priv;
 	struct ib_mad_agent_private *recv_mad_agent = NULL;
 	struct ib_device *device = mad_agent_priv->agent.device;
-	u8 port_num = mad_agent_priv->agent.port_num;
+	u8 port_num;
 	struct ib_wc mad_wc;
 	struct ib_send_wr *send_wr = &mad_send_wr->send_wr;
+	struct ib_ah_attr ah_attr;
+
+	if (device->node_type != RDMA_NODE_IB_SWITCH)
+		port_num = mad_agent_priv->agent.port_num;
+	else {
+		/* For a switch, port number is obtained from AH attribute */
+		if (!device->query_ah) {
+			ret = -ENOTSUPP;
+			printk(KERN_ERR PFX "Query AH not supported\n");
+			goto out;
+		}
+		ret = ib_query_ah(mad_send_wr->send_wr.wr.ud.ah, &ah_attr);
+		if (ret) {
+			printk(KERN_ERR PFX "Query AH failed\n");
+			goto out;
+		}
+		port_num = ah_attr.port_num;
+	}
 
 	/*
 	 * Directed route handling starts if the initial LID routed part of
@@ -1631,6 +1649,7 @@ static void ib_mad_recv_done_handler(str
 	struct ib_mad_private *recv, *response;
 	struct ib_mad_list_head *mad_list;
 	struct ib_mad_agent_private *mad_agent;
+	int port_num;
 
 	response = kmem_cache_alloc(ib_mad_cache, GFP_KERNEL);
 	if (!response)
@@ -1666,16 +1685,20 @@ static void ib_mad_recv_done_handler(str
 
 	if (recv->mad.mad.mad_hdr.mgmt_class ==
 	    IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
+		if (port_priv->device->node_type != RDMA_NODE_IB_SWITCH)
+			port_num = port_priv->port_num;
+		else
+			port_num = wc->port_num;
 		if (!smi_handle_dr_smp_recv(&recv->mad.smp,
 					    port_priv->device->node_type,
-					    port_priv->port_num,
+					    port_num,
 					    port_priv->device->phys_port_cnt))
 			goto out;
 		if (!smi_check_forward_dr_smp(&recv->mad.smp))
 			goto local;
 		if (!smi_handle_dr_smp_send(&recv->mad.smp,
 					    port_priv->device->node_type,
-					    port_priv->port_num))
+					    port_num))
 			goto out;
 		if (!smi_check_local_smp(&recv->mad.smp, port_priv->device))
 			goto out;






More information about the general mailing list