[openib-general] Re: [PATCH] mad: add GID/class checking for matching received to sent MADs

Jack Morgenstein jackm at mellanox.co.il
Thu Mar 2 07:49:07 PST 2006


On Wednesday 01 March 2006 20:18, Sean Hefty wrote:
> Can we just remove the if and let the code fall through?
We still need to compare the source (i.e., originator) GIDs if the grh flag is 
set.  This means:  the destination GID of the received packet, and the source 
GID of the sent packet (converting the gid index to a GID).

Patch is below.

- Jack
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

compare MAD GIDs at query-originator side, too,
to handle case where same TID is used for sending with
with different GIDs from same port.

Signed-off-by: Jack Morgenstein <jackm at mellanox.co.il>

Index: src/drivers/infiniband/core/mad.c
===================================================================
--- src.orig/drivers/infiniband/core/mad.c	2006-03-01 10:04:21.818944000 +0200
+++ src/drivers/infiniband/core/mad.c	2006-03-02 17:42:16.441851000 +0200
@@ -35,6 +35,7 @@
  */
 #include <linux/dma-mapping.h>
 
+#include <rdma/ib_cache.h>
 #include "mad_priv.h"
 #include "mad_rmpp.h"
 #include "smi.h"
@@ -1644,40 +1645,51 @@ static inline int rcv_has_same_class(str
 		rwc->recv_buf.mad->mad_hdr.mgmt_class;
 }
 
-static inline int rcv_has_same_gid(struct ib_mad_send_wr_private *wr,
+static inline int rcv_has_same_gid(struct ib_mad_agent_private 
*mad_agent_priv,
+				   struct ib_mad_send_wr_private *wr,
 				   struct ib_mad_recv_wc *rwc )
 {
 	struct ib_ah_attr attr;
 	u8 send_resp, rcv_resp;
+	union ib_gid  sg;
 
 	send_resp = ((struct ib_mad *)(wr->send_buf.mad))->
 		     mad_hdr.method & IB_MGMT_METHOD_RESP;
 	rcv_resp = rwc->recv_buf.mad->mad_hdr.method & IB_MGMT_METHOD_RESP;
 
-	if (!send_resp && rcv_resp)
-		/* is request/response. GID/LIDs are both local (same). */
-		return 1;
-
 	if (send_resp == rcv_resp)
 		/* both requests, or both responses. GIDs different */
 		return 0;
 
 	if (ib_query_ah(wr->send_buf.ah, &attr))
-		/* Assume not equal, to avoid false positives. */
+		/* Assume different, to avoid false positives. */
 		return 0;
 
 	if (!(attr.ah_flags & IB_AH_GRH) && !(rwc->wc->wc_flags & IB_WC_GRH))
 		return attr.dlid == rwc->wc->slid;
 	else if ((attr.ah_flags & IB_AH_GRH) &&
-		 (rwc->wc->wc_flags & IB_WC_GRH))
-		return memcmp(attr.grh.dgid.raw,
-			      rwc->recv_buf.grh->sgid.raw, 16) == 0;
-	else
+		 (rwc->wc->wc_flags & IB_WC_GRH)) {
+		if (send_resp)
+			/* compare remote GIDs */
+			return !memcmp(attr.grh.dgid.raw,
+				       rwc->recv_buf.grh->sgid.raw, 16);
+		else {
+			/* compare local GIDs */
+			if (ib_get_cached_gid(mad_agent_priv->agent.device,
+					      mad_agent_priv->agent.port_num,
+					      attr.grh.sgid_index,
+					      &sg))
+				/* assume different if cannot get GID */
+				return 0;
+			return !memcmp(sg.raw, rwc->recv_buf.grh->dgid.raw, 16);
+		}
+	} else
 		/* one has GID, other does not.  Assume different */
 		return 0;
 }
+
 struct ib_mad_send_wr_private*
-ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv,
+ib_find_send_mad(struct ib_mad_agent_private *mad_agent,
 		 struct ib_mad_recv_wc *mad_recv_wc)
 {
 	struct ib_mad_send_wr_private *mad_send_wr;
@@ -1685,11 +1697,11 @@ ib_find_send_mad(struct ib_mad_agent_pri
 
 	mad = (struct ib_mad *)mad_recv_wc->recv_buf.mad;
 
-	list_for_each_entry(mad_send_wr, &mad_agent_priv->wait_list,
+	list_for_each_entry(mad_send_wr, &mad_agent->wait_list,
 			    agent_list) {
 		if ((mad_send_wr->tid == mad->mad_hdr.tid) &&
 		    rcv_has_same_class(mad_send_wr, mad_recv_wc) &&
-		    rcv_has_same_gid(mad_send_wr, mad_recv_wc))
+		    rcv_has_same_gid(mad_agent, mad_send_wr, mad_recv_wc))
 			return mad_send_wr;
 	}
 
@@ -1697,13 +1709,13 @@ ib_find_send_mad(struct ib_mad_agent_pri
 	 * It's possible to receive the response before we've
 	 * been notified that the send has completed
 	 */
-	list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list,
+	list_for_each_entry(mad_send_wr, &mad_agent->send_list,
 			    agent_list) {
-		if (is_data_mad(mad_agent_priv, mad_send_wr->send_buf.mad) &&
+		if (is_data_mad(mad_agent, mad_send_wr->send_buf.mad) &&
 		    mad_send_wr->tid == mad->mad_hdr.tid &&
 		    mad_send_wr->timeout &&
 		    rcv_has_same_class(mad_send_wr, mad_recv_wc) &&
-		    rcv_has_same_gid(mad_send_wr, mad_recv_wc)) {
+		    rcv_has_same_gid(mad_agent, mad_send_wr, mad_recv_wc)) {
 			/* Verify request has not been canceled */
 			return (mad_send_wr->status == IB_WC_SUCCESS) ?
 				mad_send_wr : NULL;



More information about the general mailing list