Commit 7c41765d authored by Doug Ledford's avatar Doug Ledford

Merge branches 'hfi1' and 'sge-limit' into k.o/for-4.8-2

parents 0636e9ab e6d66e3e
...@@ -58,19 +58,13 @@ static inline bool rdma_rw_io_needs_mr(struct ib_device *dev, u8 port_num, ...@@ -58,19 +58,13 @@ static inline bool rdma_rw_io_needs_mr(struct ib_device *dev, u8 port_num,
return false; return false;
} }
static inline u32 rdma_rw_max_sge(struct ib_device *dev,
enum dma_data_direction dir)
{
return dir == DMA_TO_DEVICE ?
dev->attrs.max_sge : dev->attrs.max_sge_rd;
}
static inline u32 rdma_rw_fr_page_list_len(struct ib_device *dev) static inline u32 rdma_rw_fr_page_list_len(struct ib_device *dev)
{ {
/* arbitrary limit to avoid allocating gigantic resources */ /* arbitrary limit to avoid allocating gigantic resources */
return min_t(u32, dev->attrs.max_fast_reg_page_list_len, 256); return min_t(u32, dev->attrs.max_fast_reg_page_list_len, 256);
} }
/* Caller must have zero-initialized *reg. */
static int rdma_rw_init_one_mr(struct ib_qp *qp, u8 port_num, static int rdma_rw_init_one_mr(struct ib_qp *qp, u8 port_num,
struct rdma_rw_reg_ctx *reg, struct scatterlist *sg, struct rdma_rw_reg_ctx *reg, struct scatterlist *sg,
u32 sg_cnt, u32 offset) u32 sg_cnt, u32 offset)
...@@ -114,6 +108,7 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp, ...@@ -114,6 +108,7 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
u8 port_num, struct scatterlist *sg, u32 sg_cnt, u32 offset, u8 port_num, struct scatterlist *sg, u32 sg_cnt, u32 offset,
u64 remote_addr, u32 rkey, enum dma_data_direction dir) u64 remote_addr, u32 rkey, enum dma_data_direction dir)
{ {
struct rdma_rw_reg_ctx *prev = NULL;
u32 pages_per_mr = rdma_rw_fr_page_list_len(qp->pd->device); u32 pages_per_mr = rdma_rw_fr_page_list_len(qp->pd->device);
int i, j, ret = 0, count = 0; int i, j, ret = 0, count = 0;
...@@ -125,7 +120,6 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp, ...@@ -125,7 +120,6 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
} }
for (i = 0; i < ctx->nr_ops; i++) { for (i = 0; i < ctx->nr_ops; i++) {
struct rdma_rw_reg_ctx *prev = i ? &ctx->reg[i - 1] : NULL;
struct rdma_rw_reg_ctx *reg = &ctx->reg[i]; struct rdma_rw_reg_ctx *reg = &ctx->reg[i];
u32 nents = min(sg_cnt, pages_per_mr); u32 nents = min(sg_cnt, pages_per_mr);
...@@ -162,9 +156,13 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp, ...@@ -162,9 +156,13 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
sg_cnt -= nents; sg_cnt -= nents;
for (j = 0; j < nents; j++) for (j = 0; j < nents; j++)
sg = sg_next(sg); sg = sg_next(sg);
prev = reg;
offset = 0; offset = 0;
} }
if (prev)
prev->wr.wr.next = NULL;
ctx->type = RDMA_RW_MR; ctx->type = RDMA_RW_MR;
return count; return count;
...@@ -181,7 +179,8 @@ static int rdma_rw_init_map_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp, ...@@ -181,7 +179,8 @@ static int rdma_rw_init_map_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
u64 remote_addr, u32 rkey, enum dma_data_direction dir) u64 remote_addr, u32 rkey, enum dma_data_direction dir)
{ {
struct ib_device *dev = qp->pd->device; struct ib_device *dev = qp->pd->device;
u32 max_sge = rdma_rw_max_sge(dev, dir); u32 max_sge = dir == DMA_TO_DEVICE ? qp->max_write_sge :
qp->max_read_sge;
struct ib_sge *sge; struct ib_sge *sge;
u32 total_len = 0, i, j; u32 total_len = 0, i, j;
...@@ -205,11 +204,10 @@ static int rdma_rw_init_map_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp, ...@@ -205,11 +204,10 @@ static int rdma_rw_init_map_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
rdma_wr->wr.opcode = IB_WR_RDMA_READ; rdma_wr->wr.opcode = IB_WR_RDMA_READ;
rdma_wr->remote_addr = remote_addr + total_len; rdma_wr->remote_addr = remote_addr + total_len;
rdma_wr->rkey = rkey; rdma_wr->rkey = rkey;
rdma_wr->wr.num_sge = nr_sge;
rdma_wr->wr.sg_list = sge; rdma_wr->wr.sg_list = sge;
for (j = 0; j < nr_sge; j++, sg = sg_next(sg)) { for (j = 0; j < nr_sge; j++, sg = sg_next(sg)) {
rdma_wr->wr.num_sge++;
sge->addr = ib_sg_dma_address(dev, sg) + offset; sge->addr = ib_sg_dma_address(dev, sg) + offset;
sge->length = ib_sg_dma_len(dev, sg) - offset; sge->length = ib_sg_dma_len(dev, sg) - offset;
sge->lkey = qp->pd->local_dma_lkey; sge->lkey = qp->pd->local_dma_lkey;
...@@ -220,8 +218,8 @@ static int rdma_rw_init_map_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp, ...@@ -220,8 +218,8 @@ static int rdma_rw_init_map_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
offset = 0; offset = 0;
} }
if (i + 1 < ctx->nr_ops) rdma_wr->wr.next = i + 1 < ctx->nr_ops ?
rdma_wr->wr.next = &ctx->map.wrs[i + 1].wr; &ctx->map.wrs[i + 1].wr : NULL;
} }
ctx->type = RDMA_RW_MULTI_WR; ctx->type = RDMA_RW_MULTI_WR;
......
...@@ -814,6 +814,15 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd, ...@@ -814,6 +814,15 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
} }
} }
/*
* Note: all hw drivers guarantee that max_send_sge is lower than
* the device RDMA WRITE SGE limit but not all hw drivers ensure that
* max_send_sge <= max_sge_rd.
*/
qp->max_write_sge = qp_init_attr->cap.max_send_sge;
qp->max_read_sge = min_t(u32, qp_init_attr->cap.max_send_sge,
device->attrs.max_sge_rd);
return qp; return qp;
} }
EXPORT_SYMBOL(ib_create_qp); EXPORT_SYMBOL(ib_create_qp);
......
...@@ -137,8 +137,6 @@ isert_create_qp(struct isert_conn *isert_conn, ...@@ -137,8 +137,6 @@ isert_create_qp(struct isert_conn *isert_conn,
attr.cap.max_recv_wr = ISERT_QP_MAX_RECV_DTOS + 1; attr.cap.max_recv_wr = ISERT_QP_MAX_RECV_DTOS + 1;
attr.cap.max_rdma_ctxs = ISCSI_DEF_XMIT_CMDS_MAX; attr.cap.max_rdma_ctxs = ISCSI_DEF_XMIT_CMDS_MAX;
attr.cap.max_send_sge = device->ib_device->attrs.max_sge; attr.cap.max_send_sge = device->ib_device->attrs.max_sge;
isert_conn->max_sge = min(device->ib_device->attrs.max_sge,
device->ib_device->attrs.max_sge_rd);
attr.cap.max_recv_sge = 1; attr.cap.max_recv_sge = 1;
attr.sq_sig_type = IB_SIGNAL_REQ_WR; attr.sq_sig_type = IB_SIGNAL_REQ_WR;
attr.qp_type = IB_QPT_RC; attr.qp_type = IB_QPT_RC;
......
...@@ -138,7 +138,6 @@ struct isert_conn { ...@@ -138,7 +138,6 @@ struct isert_conn {
u32 responder_resources; u32 responder_resources;
u32 initiator_depth; u32 initiator_depth;
bool pi_support; bool pi_support;
u32 max_sge;
struct iser_rx_desc *login_req_buf; struct iser_rx_desc *login_req_buf;
char *login_rsp_buf; char *login_rsp_buf;
u64 login_req_dma; u64 login_req_dma;
......
...@@ -1601,6 +1601,7 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch) ...@@ -1601,6 +1601,7 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch)
struct ib_qp_init_attr *qp_init; struct ib_qp_init_attr *qp_init;
struct srpt_port *sport = ch->sport; struct srpt_port *sport = ch->sport;
struct srpt_device *sdev = sport->sdev; struct srpt_device *sdev = sport->sdev;
const struct ib_device_attr *attrs = &sdev->device->attrs;
u32 srp_sq_size = sport->port_attrib.srp_sq_size; u32 srp_sq_size = sport->port_attrib.srp_sq_size;
int ret; int ret;
...@@ -1638,7 +1639,7 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch) ...@@ -1638,7 +1639,7 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch)
*/ */
qp_init->cap.max_send_wr = srp_sq_size / 2; qp_init->cap.max_send_wr = srp_sq_size / 2;
qp_init->cap.max_rdma_ctxs = srp_sq_size / 2; qp_init->cap.max_rdma_ctxs = srp_sq_size / 2;
qp_init->cap.max_send_sge = SRPT_DEF_SG_PER_WQE; qp_init->cap.max_send_sge = min(attrs->max_sge, SRPT_MAX_SG_PER_WQE);
qp_init->port_num = ch->sport->port; qp_init->port_num = ch->sport->port;
ch->qp = ib_create_qp(sdev->pd, qp_init); ch->qp = ib_create_qp(sdev->pd, qp_init);
...@@ -2261,7 +2262,7 @@ static void srpt_queue_response(struct se_cmd *cmd) ...@@ -2261,7 +2262,7 @@ static void srpt_queue_response(struct se_cmd *cmd)
container_of(cmd, struct srpt_send_ioctx, cmd); container_of(cmd, struct srpt_send_ioctx, cmd);
struct srpt_rdma_ch *ch = ioctx->ch; struct srpt_rdma_ch *ch = ioctx->ch;
struct srpt_device *sdev = ch->sport->sdev; struct srpt_device *sdev = ch->sport->sdev;
struct ib_send_wr send_wr, *first_wr = NULL, *bad_wr; struct ib_send_wr send_wr, *first_wr = &send_wr, *bad_wr;
struct ib_sge sge; struct ib_sge sge;
enum srpt_command_state state; enum srpt_command_state state;
unsigned long flags; unsigned long flags;
...@@ -2302,11 +2303,8 @@ static void srpt_queue_response(struct se_cmd *cmd) ...@@ -2302,11 +2303,8 @@ static void srpt_queue_response(struct se_cmd *cmd)
struct srpt_rw_ctx *ctx = &ioctx->rw_ctxs[i]; struct srpt_rw_ctx *ctx = &ioctx->rw_ctxs[i];
first_wr = rdma_rw_ctx_wrs(&ctx->rw, ch->qp, first_wr = rdma_rw_ctx_wrs(&ctx->rw, ch->qp,
ch->sport->port, NULL, ch->sport->port, NULL, first_wr);
first_wr ? first_wr : &send_wr);
} }
} else {
first_wr = &send_wr;
} }
if (state != SRPT_STATE_MGMT) if (state != SRPT_STATE_MGMT)
......
...@@ -106,7 +106,11 @@ enum { ...@@ -106,7 +106,11 @@ enum {
SRP_LOGIN_RSP_MULTICHAN_MAINTAINED = 0x2, SRP_LOGIN_RSP_MULTICHAN_MAINTAINED = 0x2,
SRPT_DEF_SG_TABLESIZE = 128, SRPT_DEF_SG_TABLESIZE = 128,
SRPT_DEF_SG_PER_WQE = 16, /*
* An experimentally determined value that avoids that QP creation
* fails due to "swiotlb buffer is full" on systems using the swiotlb.
*/
SRPT_MAX_SG_PER_WQE = 16,
MIN_SRPT_SQ_SIZE = 16, MIN_SRPT_SQ_SIZE = 16,
DEF_SRPT_SQ_SIZE = 4096, DEF_SRPT_SQ_SIZE = 4096,
......
...@@ -1428,6 +1428,10 @@ struct ib_srq { ...@@ -1428,6 +1428,10 @@ struct ib_srq {
} ext; } ext;
}; };
/*
* @max_write_sge: Maximum SGE elements per RDMA WRITE request.
* @max_read_sge: Maximum SGE elements per RDMA READ request.
*/
struct ib_qp { struct ib_qp {
struct ib_device *device; struct ib_device *device;
struct ib_pd *pd; struct ib_pd *pd;
...@@ -1449,6 +1453,8 @@ struct ib_qp { ...@@ -1449,6 +1453,8 @@ struct ib_qp {
void (*event_handler)(struct ib_event *, void *); void (*event_handler)(struct ib_event *, void *);
void *qp_context; void *qp_context;
u32 qp_num; u32 qp_num;
u32 max_write_sge;
u32 max_read_sge;
enum ib_qp_type qp_type; enum ib_qp_type qp_type;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment