From 5484d6dfc4dd30b28fa3527fbae293427aba1835 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 25 Jun 2011 19:13:50 +0000 Subject: [PATCH] ib_srpt: Eliminate the magic constant SRPT_DEF_SG_PER_WQE git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@3626 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/src/ib_srpt.c | 11 +++++++---- srpt/src/ib_srpt.h | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 523a9f898..50970ca6a 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -2008,7 +2008,9 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch) qp_init->sq_sig_type = IB_SIGNAL_REQ_WR; qp_init->qp_type = IB_QPT_RC; qp_init->cap.max_send_wr = srpt_sq_size; - qp_init->cap.max_send_sge = SRPT_DEF_SG_PER_WQE; + ch->max_sge = sdev->dev_attr.max_sge - 2; + BUG_ON(ch->max_sge <= 2); + qp_init->cap.max_send_sge = ch->max_sge; ch->qp = ib_create_qp(sdev->pd, qp_init); if (IS_ERR(ch->qp)) { @@ -2684,10 +2686,12 @@ static int srpt_map_sg_to_ib_sge(struct srpt_rdma_ch *ch, u32 dma_len; int count, nrdma; int i, j, k; + int max_sge; BUG_ON(!ch); BUG_ON(!ioctx); BUG_ON(!scmnd); + max_sge = ch->max_sge; dir = scst_cmd_get_data_direction(scmnd); BUG_ON(dir == SCST_DATA_NONE); /* @@ -2715,8 +2719,7 @@ static int srpt_map_sg_to_ib_sge(struct srpt_rdma_ch *ch, if (ioctx->rdma_ius && ioctx->n_rdma_ius) nrdma = ioctx->n_rdma_ius; else { - nrdma = (count + SRPT_DEF_SG_PER_WQE - 1) / SRPT_DEF_SG_PER_WQE - + ioctx->n_rbuf; + nrdma = (count + max_sge - 1) / max_sge + ioctx->n_rbuf; ioctx->rdma_ius = kzalloc(nrdma * sizeof *riu, scst_cmd_atomic(scmnd) @@ -2771,7 +2774,7 @@ static int srpt_map_sg_to_ib_sge(struct srpt_rdma_ch *ch, ++riu->sge_cnt; - if (rsize > 0 && riu->sge_cnt == SRPT_DEF_SG_PER_WQE) { + if (rsize > 0 && riu->sge_cnt == max_sge) { ++ioctx->n_rdma; riu->sge = kmalloc(riu->sge_cnt * sizeof *riu->sge, diff --git a/srpt/src/ib_srpt.h b/srpt/src/ib_srpt.h index 194a63001..5774120ba 100644 --- a/srpt/src/ib_srpt.h +++ b/srpt/src/ib_srpt.h @@ -108,7 +108,6 @@ enum { SRP_LOGIN_RSP_MULTICHAN_MAINTAINED = 0x2, SRPT_DEF_SG_TABLESIZE = 128, - SRPT_DEF_SG_PER_WQE = 16, MIN_SRPT_SQ_SIZE = 16, DEF_SRPT_SQ_SIZE = 4096, @@ -208,7 +207,7 @@ struct srpt_tsk_mgmt { /** * struct srpt_send_ioctx - SRPT send I/O context. - * @ioctx: See above. + * @ioctx: See above. * @ch: Channel pointer. * @rdma_ius: Array with information about the RDMA mapping. * @rbufs: Pointer to SRP data buffer array. @@ -275,6 +274,7 @@ enum rdma_ch_state { * @qp: IB queue pair used for communicating over this channel. * @cq: IB completion queue for this channel. * @rq_size: IB receive queue size. + * @max_sge: Maximum length of RDMA scatter list. * @sq_wr_avail: number of work requests available in the send queue. * @sport: pointer to the information of the HCA port used by this * channel. @@ -304,6 +304,7 @@ struct srpt_rdma_ch { struct ib_qp *qp; struct ib_cq *cq; int rq_size; + int max_sge; int sq_wr_avail; struct srpt_port *sport; u8 i_port_id[16];