[openib-general] Re: static rate encoding change support

Jack Morgenstein jackm at mellanox.co.il
Sun Apr 2 07:03:04 PDT 2006


On Friday 31 March 2006 22:59, Roland Dreier wrote:
> Since I have nothing better to do, I fixed up the patch myself.
> Here's what I have so far; there are still some cleanups that I need
> to make before I commit this.
>
On Sunday 02 April 2006 11:43, Jack Morgenstein wrote:
>Please note, though, that the patch does not include the mthca changes
>for returning the correct static rate to the ib layer in verb "query qp".
>
> I have a patch for this, too, but had hoped to add it to the larger patch,
> since that was not yet checked in.
>
> Jack

Here is the static rate query-qp patch, to be applied on top of your 
static-rate patch. If possible, I think the two patches (yours and mine) 
should be combined into a single check-in.

- Jack

---
Return proper static rate (for new encoding) in query_qp.

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

Index: src/drivers/infiniband/hw/mthca/mthca_av.c
===================================================================
--- src.orig/drivers/infiniband/hw/mthca/mthca_av.c	2006-04-02 
11:48:53.348045000 +0300
+++ src/drivers/infiniband/hw/mthca/mthca_av.c	2006-04-02 16:59:25.695664000 
+0300
@@ -71,6 +71,37 @@ static inline u8 ib_rate_to_memfree(stru
 	}
 }
 
+enum ib_rate mthca_rate_to_ib(struct mthca_dev *dev, u8 mthca_rate, u8 port)
+{
+	if (!mthca_rate)
+		return mult_to_ib_rate(dev->rate[port - 1]);
+
+	if (mthca_is_memfree(dev)) {
+		switch (mthca_rate) {
+		case MTHCA_RATE_MEMFREE_EIGHTH:
+			return mult_to_ib_rate(dev->rate[port - 1] / 8);
+		case MTHCA_RATE_MEMFREE_QUARTER:
+			return mult_to_ib_rate(dev->rate[port - 1] / 4);
+		case MTHCA_RATE_MEMFREE_HALF:
+			return mult_to_ib_rate(dev->rate[port - 1] / 2);
+		case MTHCA_RATE_MEMFREE_FULL:
+		default:
+			return mult_to_ib_rate(dev->rate[port - 1]);
+		}
+	}
+
+	switch (mthca_rate) {
+	case MTHCA_RATE_TAVOR_1X:
+		return IB_RATE_2_5_GBPS;
+	case MTHCA_RATE_TAVOR_1X_DDR:
+		return IB_RATE_5_GBPS;
+	case MTHCA_RATE_TAVOR_4X:
+		return IB_RATE_10_GBPS;
+	default:
+		return mult_to_ib_rate(dev->rate[port - 1]);
+	}
+}
+
 u8 mthca_get_rate(struct mthca_dev *dev, struct ib_ah_attr *attr, u8 port)
 {
 	if (!attr->static_rate)
Index: src/drivers/infiniband/hw/mthca/mthca_dev.h
===================================================================
--- src.orig/drivers/infiniband/hw/mthca/mthca_dev.h	2006-04-02 
11:48:53.289045000 +0300
+++ src/drivers/infiniband/hw/mthca/mthca_dev.h	2006-04-02 16:09:34.421360000 
+0300
@@ -575,6 +575,7 @@ int mthca_process_mad(struct ib_device *
 		      struct ib_mad *out_mad);
 int mthca_update_rate(struct mthca_dev *dev, u8 port_num);
 u8 mthca_get_rate(struct mthca_dev *dev, struct ib_ah_attr *attr, u8 port);
+enum ib_rate mthca_rate_to_ib(struct mthca_dev *dev, u8 mthca_rate, u8 port);
 int mthca_create_agents(struct mthca_dev *dev);
 void mthca_free_agents(struct mthca_dev *dev);
 
Index: src/drivers/infiniband/hw/mthca/mthca_qp.c
===================================================================
--- src.orig/drivers/infiniband/hw/mthca/mthca_qp.c	2006-04-02 
11:48:53.385044000 +0300
+++ src/drivers/infiniband/hw/mthca/mthca_qp.c	2006-04-02 16:11:36.555940000 
+0300
@@ -393,10 +393,17 @@ static void to_ib_ah_attr(struct mthca_d
 {
 	memset(ib_ah_attr, 0, sizeof *path);
 	ib_ah_attr->port_num 	  = (be32_to_cpu(path->port_pkey) >> 24) & 0x3;
+
+	if (ib_ah_attr->port_num == 0 ||
+	    ib_ah_attr->port_num > dev->limits.num_ports )
+		return;
+
 	ib_ah_attr->dlid     	  = be16_to_cpu(path->rlid);
 	ib_ah_attr->sl       	  = be32_to_cpu(path->sl_tclass_flowlabel) >> 28;
 	ib_ah_attr->src_path_bits = path->g_mylmc & 0x7f;
-	ib_ah_attr->static_rate   = path->static_rate & 0x7;
+	ib_ah_attr->static_rate   = mthca_rate_to_ib(dev,
+						     path->static_rate & 0x7,
+						     ib_ah_attr->port_num);
 	ib_ah_attr->ah_flags      = (path->g_mylmc & (1 << 7)) ? IB_AH_GRH : 0;
 	if (ib_ah_attr->ah_flags) {
 		ib_ah_attr->grh.sgid_index = path->mgid_index & (dev->limits.gid_table_len 
- 1);
@@ -421,6 +428,7 @@ int mthca_query_qp(struct ib_qp *ibqp, s
 	struct mthca_qp_context *context;
 	int mthca_state;
 	u8 status;
+	int i;
 
 	mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
 	if (IS_ERR(mailbox))
@@ -435,10 +443,16 @@ int mthca_query_qp(struct ib_qp *ibqp, s
 		goto out;
 	}
 
+	if (qp->transport == RC || qp->transport == UC)
+		for (i = 1; i < dev->limits.num_ports; ++i)
+			if ((err = mthca_update_rate(dev,i)))
+				goto out;
+
 	qp_param    = mailbox->buf;
 	context     = &qp_param->context;
 	mthca_state = be32_to_cpu(context->flags) >> 28;
 
+	memset(qp_attr, 0, sizeof *qp_attr);
 	qp_attr->qp_state 	     = to_ib_qp_state(mthca_state);
 	qp_attr->cur_qp_state 	     = qp_attr->qp_state;
 	qp_attr->path_mtu 	     = context->mtu_msgmax >> 5;
@@ -456,8 +470,10 @@ int mthca_query_qp(struct ib_qp *ibqp, s
 	qp_attr->cap.max_recv_sge    = qp->rq.max_gs;
 	qp_attr->cap.max_inline_data = qp->max_inline_data;
 
-	to_ib_ah_attr(dev, &qp_attr->ah_attr, &context->pri_path);
-	to_ib_ah_attr(dev, &qp_attr->alt_ah_attr, &context->alt_path);
+	if (qp->transport == RC || qp->transport == UC){
+		to_ib_ah_attr(dev, &qp_attr->ah_attr, &context->pri_path);
+		to_ib_ah_attr(dev, &qp_attr->alt_ah_attr, &context->alt_path);
+	}
 
 	qp_attr->pkey_index     = be32_to_cpu(context->pri_path.port_pkey) & 0x7f;
 	qp_attr->alt_pkey_index = be32_to_cpu(context->alt_path.port_pkey) & 0x7f;
Index: src/drivers/infiniband/include/rdma/ib_verbs.h
===================================================================
--- src.orig/drivers/infiniband/include/rdma/ib_verbs.h	2006-04-02 
11:47:26.155973000 +0300
+++ src/drivers/infiniband/include/rdma/ib_verbs.h	2006-04-02 
12:03:27.156727000 +0300
@@ -366,6 +366,22 @@ static inline int ib_rate_to_mult(enum i
 	}
 }
 
+static inline enum ib_rate mult_to_ib_rate(u8 mult)
+{
+	switch (mult) {
+	case 1:  return IB_RATE_2_5_GBPS;
+	case 2:  return IB_RATE_5_GBPS;
+	case 4:  return IB_RATE_10_GBPS;
+	case 8:  return IB_RATE_20_GBPS;
+	case 12: return IB_RATE_30_GBPS;
+	case 16: return IB_RATE_40_GBPS;
+	case 24: return IB_RATE_60_GBPS;
+	case 32: return IB_RATE_80_GBPS;
+	case 48: return IB_RATE_120_GBPS;
+	default: return IB_RATE_PORT_CURRENT;
+	}
+}
+
 
 struct ib_ah_attr {
 	struct ib_global_route	grh;



More information about the general mailing list