[openib-general] [PATCH 3/4] [RFC] Use ib_modify_qp_is_ok in ipath

Roland Dreier rolandd at cisco.com
Fri Feb 10 16:51:58 PST 2006


Convert ipath to use ib_modify_qp_is_ok() instead of its own QP
transition table.  Lightly tested.

PathScale people: please test this out and apply if it's OK.

--- infiniband/hw/ipath/ipath_verbs.c	(revision 5364)
+++ infiniband/hw/ipath/ipath_verbs.c	(working copy)
@@ -1003,213 +1003,6 @@ static void send_complete(unsigned long 
 }
 
 /*
- * This is the QP state transition table.
- * See ipath_modify_qp() for details.
- */
-static const struct {
-	int trans;
-	u32 req_param[IB_QPT_RAW_IPV6];
-	u32 opt_param[IB_QPT_RAW_IPV6];
-} qp_state_table[IB_QPS_ERR + 1][IB_QPS_ERR + 1] = {
-	[IB_QPS_RESET] = {
-		[IB_QPS_RESET] = { .trans = IPATH_TRANS_ANY2RST },
-		[IB_QPS_ERR] = { .trans = IPATH_TRANS_ANY2ERR },
-		[IB_QPS_INIT] = {
-			.trans = IPATH_TRANS_RST2INIT,
-			.req_param = {
-				[IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
-					 IB_QP_QKEY),
-				[IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
-					 IB_QP_QKEY),
-				[IB_QPT_UD] = (IB_QP_PKEY_INDEX |
-					 IB_QP_PORT |
-					 IB_QP_QKEY),
-				[IB_QPT_UC] = (IB_QP_PKEY_INDEX |
-					 IB_QP_PORT |
-					 IB_QP_ACCESS_FLAGS),
-				[IB_QPT_RC] = (IB_QP_PKEY_INDEX |
-					 IB_QP_PORT |
-					 IB_QP_ACCESS_FLAGS),
-			},
-		},
-	},
-	[IB_QPS_INIT] = {
-		[IB_QPS_RESET] = { .trans = IPATH_TRANS_ANY2RST },
-		[IB_QPS_ERR] = { .trans = IPATH_TRANS_ANY2ERR },
-		[IB_QPS_INIT] = {
-			.trans = IPATH_TRANS_INIT2INIT,
-			.opt_param = {
-				[IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
-					 IB_QP_QKEY),
-				[IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
-					 IB_QP_QKEY),
-				[IB_QPT_UD] = (IB_QP_PKEY_INDEX |
-					 IB_QP_PORT |
-					 IB_QP_QKEY),
-				[IB_QPT_UC] = (IB_QP_PKEY_INDEX |
-					 IB_QP_PORT |
-					 IB_QP_ACCESS_FLAGS),
-				[IB_QPT_RC] = (IB_QP_PKEY_INDEX |
-					 IB_QP_PORT |
-					 IB_QP_ACCESS_FLAGS),
-			}
-		},
-		[IB_QPS_RTR] = {
-			.trans = IPATH_TRANS_INIT2RTR,
-			.req_param = {
-				[IB_QPT_UC] = (IB_QP_AV |
-					 IB_QP_PATH_MTU |
-					 IB_QP_DEST_QPN |
-					 IB_QP_RQ_PSN),
-				[IB_QPT_RC] = (IB_QP_AV |
-					 IB_QP_PATH_MTU |
-					 IB_QP_DEST_QPN |
-					 IB_QP_RQ_PSN |
-					 IB_QP_MAX_DEST_RD_ATOMIC |
-					 IB_QP_MIN_RNR_TIMER),
-			},
-			.opt_param = {
-				[IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
-					 IB_QP_QKEY),
-				[IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
-					 IB_QP_QKEY),
-				[IB_QPT_UD] = (IB_QP_PKEY_INDEX |
-					 IB_QP_QKEY),
-				[IB_QPT_UC] = (IB_QP_ALT_PATH |
-					 IB_QP_ACCESS_FLAGS |
-					 IB_QP_PKEY_INDEX),
-				[IB_QPT_RC] = (IB_QP_ALT_PATH |
-					 IB_QP_ACCESS_FLAGS |
-					 IB_QP_PKEY_INDEX),
-			}
-		}
-	},
-	[IB_QPS_RTR] = {
-		[IB_QPS_RESET] = { .trans = IPATH_TRANS_ANY2RST },
-		[IB_QPS_ERR] = { .trans = IPATH_TRANS_ANY2ERR },
-		[IB_QPS_RTS] = {
-			.trans = IPATH_TRANS_RTR2RTS,
-			.req_param = {
-				[IB_QPT_SMI] = IB_QP_SQ_PSN,
-				[IB_QPT_GSI] = IB_QP_SQ_PSN,
-				[IB_QPT_UD] = IB_QP_SQ_PSN,
-				[IB_QPT_UC] = IB_QP_SQ_PSN,
-				[IB_QPT_RC] = (IB_QP_TIMEOUT |
-					 IB_QP_RETRY_CNT |
-					 IB_QP_RNR_RETRY |
-					 IB_QP_SQ_PSN |
-					 IB_QP_MAX_QP_RD_ATOMIC),
-			},
-			.opt_param = {
-				[IB_QPT_SMI] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_GSI] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_UD] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_UC] = (IB_QP_CUR_STATE |
-					 IB_QP_ALT_PATH |
-					 IB_QP_ACCESS_FLAGS |
-					 IB_QP_PKEY_INDEX |
-					 IB_QP_PATH_MIG_STATE),
-				[IB_QPT_RC] = (IB_QP_CUR_STATE |
-					 IB_QP_ALT_PATH |
-					 IB_QP_ACCESS_FLAGS |
-					 IB_QP_PKEY_INDEX |
-					 IB_QP_MIN_RNR_TIMER |
-					 IB_QP_PATH_MIG_STATE),
-			}
-		}
-	},
-	[IB_QPS_RTS] = {
-		[IB_QPS_RESET] = { .trans = IPATH_TRANS_ANY2RST },
-		[IB_QPS_ERR] = { .trans = IPATH_TRANS_ANY2ERR },
-		[IB_QPS_RTS] = {
-			.trans = IPATH_TRANS_RTS2RTS,
-			.opt_param = {
-				[IB_QPT_SMI] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_GSI] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_UD] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_UC] = (IB_QP_ACCESS_FLAGS |
-					 IB_QP_ALT_PATH |
-					 IB_QP_PATH_MIG_STATE),
-				[IB_QPT_RC] = (IB_QP_ACCESS_FLAGS |
-					 IB_QP_ALT_PATH |
-					 IB_QP_PATH_MIG_STATE |
-					 IB_QP_MIN_RNR_TIMER),
-			}
-		},
-		[IB_QPS_SQD] = {
-			.trans = IPATH_TRANS_RTS2SQD,
-		},
-	},
-	[IB_QPS_SQD] = {
-		[IB_QPS_RESET] = { .trans = IPATH_TRANS_ANY2RST },
-		[IB_QPS_ERR] = { .trans = IPATH_TRANS_ANY2ERR },
-		[IB_QPS_RTS] = {
-			.trans = IPATH_TRANS_SQD2RTS,
-			.opt_param = {
-				[IB_QPT_SMI] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_GSI] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_UD] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_UC] = (IB_QP_CUR_STATE |
-					 IB_QP_ALT_PATH |
-					 IB_QP_ACCESS_FLAGS |
-					 IB_QP_PATH_MIG_STATE),
-				[IB_QPT_RC] = (IB_QP_CUR_STATE |
-					 IB_QP_ALT_PATH |
-					 IB_QP_ACCESS_FLAGS |
-					 IB_QP_MIN_RNR_TIMER |
-					 IB_QP_PATH_MIG_STATE),
-			}
-		},
-		[IB_QPS_SQD] = {
-			.trans = IPATH_TRANS_SQD2SQD,
-			.opt_param = {
-				[IB_QPT_SMI] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_GSI] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_UD] = (IB_QP_PKEY_INDEX | IB_QP_QKEY),
-				[IB_QPT_UC] = (IB_QP_AV |
-					 IB_QP_TIMEOUT |
-					 IB_QP_CUR_STATE |
-					 IB_QP_ALT_PATH |
-					 IB_QP_ACCESS_FLAGS |
-					 IB_QP_PKEY_INDEX |
-					 IB_QP_PATH_MIG_STATE),
-				[IB_QPT_RC] = (IB_QP_AV |
-					 IB_QP_TIMEOUT |
-					 IB_QP_RETRY_CNT |
-					 IB_QP_RNR_RETRY |
-					 IB_QP_MAX_QP_RD_ATOMIC |
-					 IB_QP_MAX_DEST_RD_ATOMIC |
-					 IB_QP_CUR_STATE |
-					 IB_QP_ALT_PATH |
-					 IB_QP_ACCESS_FLAGS |
-					 IB_QP_PKEY_INDEX |
-					 IB_QP_MIN_RNR_TIMER |
-					 IB_QP_PATH_MIG_STATE),
-			}
-		}
-	},
-	[IB_QPS_SQE] = {
-		[IB_QPS_RESET] = { .trans = IPATH_TRANS_ANY2RST },
-		[IB_QPS_ERR] = { .trans = IPATH_TRANS_ANY2ERR },
-		[IB_QPS_RTS] = {
-			.trans = IPATH_TRANS_SQERR2RTS,
-			.opt_param = {
-				[IB_QPT_SMI] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_GSI] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_UD] = (IB_QP_CUR_STATE | IB_QP_QKEY),
-				[IB_QPT_UC] = IB_QP_CUR_STATE,
-				[IB_QPT_RC] = (IB_QP_CUR_STATE |
-					 IB_QP_MIN_RNR_TIMER),
-			}
-		}
-	},
-	[IB_QPS_ERR] = {
-		[IB_QPS_RESET] = { .trans = IPATH_TRANS_ANY2RST },
-		[IB_QPS_ERR] = { .trans = IPATH_TRANS_ANY2ERR }
-	}
-};
-
-/*
  * Initialize the QP state to the reset state.
  */
 static void ipath_reset_qp(struct ipath_qp *qp)
@@ -1340,55 +1133,30 @@ static int ipath_modify_qp(struct ib_qp 
 {
 	struct ipath_qp *qp = to_iqp(ibqp);
 	enum ib_qp_state cur_state, new_state;
-	u32 req_param, opt_param;
 	unsigned long flags;
 
-	if (attr_mask & IB_QP_CUR_STATE) {
-		cur_state = attr->cur_qp_state;
-		if (cur_state != IB_QPS_RTR &&
-		    cur_state != IB_QPS_RTS &&
-		    cur_state != IB_QPS_SQD && cur_state != IB_QPS_SQE)
-			return -EINVAL;
-		spin_lock_irqsave(&qp->r_rq.lock, flags);
-		spin_lock(&qp->s_lock);
-	} else {
-		spin_lock_irqsave(&qp->r_rq.lock, flags);
-		spin_lock(&qp->s_lock);
-		cur_state = qp->state;
-	}
+	spin_lock_irqsave(&qp->r_rq.lock, flags);
+	spin_lock(&qp->s_lock);
 
-	if (attr_mask & IB_QP_STATE) {
-		new_state = attr->qp_state;
-		if (new_state < 0 || new_state > IB_QPS_ERR)
-			goto inval;
-	} else
-		new_state = cur_state;
+	cur_state = attr_mask & IB_QP_CUR_STATE ? attr->cur_qp_state : qp->state;
+	new_state = attr_mask & IB_QP_STATE     ? attr->qp_state     : cur_state;
 
-	switch (qp_state_table[cur_state][new_state].trans) {
-	case IPATH_TRANS_INVALID:
+	if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type, attr_mask))
 		goto inval;
 
-	case IPATH_TRANS_ANY2RST:
+	switch (new_state) {
+	case IB_QPS_RESET:
 		ipath_reset_qp(qp);
 		break;
 
-	case IPATH_TRANS_ANY2ERR:
+	case IB_QPS_ERR:
 		ipath_error_qp(qp);
 		break;
 
+	default:
+		break;
 	}
 
-	req_param =
-	    qp_state_table[cur_state][new_state].req_param[qp->ibqp.qp_type];
-	opt_param =
-	    qp_state_table[cur_state][new_state].opt_param[qp->ibqp.qp_type];
-
-	if ((req_param & attr_mask) != req_param)
-		goto inval;
-
-	if (attr_mask & ~(req_param | opt_param | IB_QP_STATE))
-		goto inval;
-
 	if (attr_mask & IB_QP_PKEY_INDEX) {
 		struct ipath_ibdev *dev = to_idev(ibqp->device);
 



More information about the general mailing list