Skip to content

Commit 513d564

Browse files
bvanasschedledford
authored andcommitted
RDMA/srp: Rework handling of the maximum information unit length
Move the maximum initiator to target information unit length parameter from struct srp_target_port into struct srp_rdma_ch. This patch does not change any functionality but makes the next patch easier to read. Cc: Sergey Gorenko <[email protected]> Cc: Max Gurtovoy <[email protected]> Cc: Laurence Oberman <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 4f6d498 commit 513d564

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

drivers/infiniband/ulp/srp/ib_srp.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,8 @@ static u8 srp_get_subnet_timeout(struct srp_host *host)
823823
return subnet_timeout;
824824
}
825825

826-
static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
826+
static int srp_send_req(struct srp_rdma_ch *ch, uint32_t max_iu_len,
827+
bool multich)
827828
{
828829
struct srp_target_port *target = ch->target;
829830
struct {
@@ -852,7 +853,7 @@ static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
852853

853854
req->ib_req.opcode = SRP_LOGIN_REQ;
854855
req->ib_req.tag = 0;
855-
req->ib_req.req_it_iu_len = cpu_to_be32(target->max_iu_len);
856+
req->ib_req.req_it_iu_len = cpu_to_be32(max_iu_len);
856857
req->ib_req.req_buf_fmt = cpu_to_be16(SRP_BUF_FORMAT_DIRECT |
857858
SRP_BUF_FORMAT_INDIRECT);
858859
req->ib_req.req_flags = (multich ? SRP_MULTICHAN_MULTI :
@@ -1145,7 +1146,8 @@ static int srp_connected_ch(struct srp_target_port *target)
11451146
return c;
11461147
}
11471148

1148-
static int srp_connect_ch(struct srp_rdma_ch *ch, bool multich)
1149+
static int srp_connect_ch(struct srp_rdma_ch *ch, uint32_t max_iu_len,
1150+
bool multich)
11491151
{
11501152
struct srp_target_port *target = ch->target;
11511153
int ret;
@@ -1158,7 +1160,7 @@ static int srp_connect_ch(struct srp_rdma_ch *ch, bool multich)
11581160

11591161
while (1) {
11601162
init_completion(&ch->done);
1161-
ret = srp_send_req(ch, multich);
1163+
ret = srp_send_req(ch, max_iu_len, multich);
11621164
if (ret)
11631165
goto out;
11641166
ret = wait_for_completion_interruptible(&ch->done);
@@ -1344,6 +1346,16 @@ static void srp_terminate_io(struct srp_rport *rport)
13441346
}
13451347
}
13461348

1349+
/* Calculate maximum initiator to target information unit length. */
1350+
static uint32_t srp_max_it_iu_len(int cmd_sg_cnt)
1351+
{
1352+
uint32_t max_iu_len = sizeof(struct srp_cmd) + SRP_MAX_ADD_CDB_LEN +
1353+
sizeof(struct srp_indirect_buf) +
1354+
cmd_sg_cnt * sizeof(struct srp_direct_buf);
1355+
1356+
return max_iu_len;
1357+
}
1358+
13471359
/*
13481360
* It is up to the caller to ensure that srp_rport_reconnect() calls are
13491361
* serialized and that no concurrent srp_queuecommand(), srp_abort(),
@@ -1357,6 +1369,7 @@ static int srp_rport_reconnect(struct srp_rport *rport)
13571369
{
13581370
struct srp_target_port *target = rport->lld_data;
13591371
struct srp_rdma_ch *ch;
1372+
uint32_t max_iu_len = srp_max_it_iu_len(target->cmd_sg_cnt);
13601373
int i, j, ret = 0;
13611374
bool multich = false;
13621375

@@ -1402,7 +1415,7 @@ static int srp_rport_reconnect(struct srp_rport *rport)
14021415
ch = &target->ch[i];
14031416
if (ret)
14041417
break;
1405-
ret = srp_connect_ch(ch, multich);
1418+
ret = srp_connect_ch(ch, max_iu_len, multich);
14061419
multich = true;
14071420
}
14081421

@@ -2316,7 +2329,7 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
23162329

23172330
req = &ch->req_ring[idx];
23182331
dev = target->srp_host->srp_dev->dev;
2319-
ib_dma_sync_single_for_cpu(dev, iu->dma, target->max_iu_len,
2332+
ib_dma_sync_single_for_cpu(dev, iu->dma, ch->max_it_iu_len,
23202333
DMA_TO_DEVICE);
23212334

23222335
scmnd->host_scribble = (void *) req;
@@ -2353,7 +2366,7 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
23532366
goto err_iu;
23542367
}
23552368

2356-
ib_dma_sync_single_for_device(dev, iu->dma, target->max_iu_len,
2369+
ib_dma_sync_single_for_device(dev, iu->dma, ch->max_it_iu_len,
23572370
DMA_TO_DEVICE);
23582371

23592372
if (srp_post_send(ch, iu, len)) {
@@ -2421,7 +2434,7 @@ static int srp_alloc_iu_bufs(struct srp_rdma_ch *ch)
24212434

24222435
for (i = 0; i < target->queue_size; ++i) {
24232436
ch->tx_ring[i] = srp_alloc_iu(target->srp_host,
2424-
target->max_iu_len,
2437+
ch->max_it_iu_len,
24252438
GFP_KERNEL, DMA_TO_DEVICE);
24262439
if (!ch->tx_ring[i])
24272440
goto err;
@@ -2487,6 +2500,9 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
24872500
if (lrsp->opcode == SRP_LOGIN_RSP) {
24882501
ch->max_ti_iu_len = be32_to_cpu(lrsp->max_ti_iu_len);
24892502
ch->req_lim = be32_to_cpu(lrsp->req_lim_delta);
2503+
ch->max_it_iu_len = srp_max_it_iu_len(target->cmd_sg_cnt);
2504+
WARN_ON_ONCE(ch->max_it_iu_len >
2505+
be32_to_cpu(lrsp->max_it_iu_len));
24902506

24912507
/*
24922508
* Reserve credits for task management so we don't
@@ -3734,6 +3750,7 @@ static ssize_t srp_create_target(struct device *dev,
37343750
int ret, node_idx, node, cpu, i;
37353751
unsigned int max_sectors_per_mr, mr_per_cmd = 0;
37363752
bool multich = false;
3753+
uint32_t max_iu_len;
37373754

37383755
target_host = scsi_host_alloc(&srp_template,
37393756
sizeof (struct srp_target_port));
@@ -3839,10 +3856,7 @@ static ssize_t srp_create_target(struct device *dev,
38393856
target->mr_per_cmd = mr_per_cmd;
38403857
target->indirect_size = target->sg_tablesize *
38413858
sizeof (struct srp_direct_buf);
3842-
target->max_iu_len = sizeof (struct srp_cmd) +
3843-
SRP_MAX_ADD_CDB_LEN +
3844-
sizeof (struct srp_indirect_buf) +
3845-
target->cmd_sg_cnt * sizeof (struct srp_direct_buf);
3859+
max_iu_len = srp_max_it_iu_len(target->cmd_sg_cnt);
38463860

38473861
INIT_WORK(&target->tl_err_work, srp_tl_err_work);
38483862
INIT_WORK(&target->remove_work, srp_remove_work);
@@ -3897,7 +3911,7 @@ static ssize_t srp_create_target(struct device *dev,
38973911
if (ret)
38983912
goto err_disconnect;
38993913

3900-
ret = srp_connect_ch(ch, multich);
3914+
ret = srp_connect_ch(ch, max_iu_len, multich);
39013915
if (ret) {
39023916
char dst[64];
39033917

drivers/infiniband/ulp/srp/ib_srp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ struct srp_request {
132132
/**
133133
* struct srp_rdma_ch
134134
* @comp_vector: Completion vector used by this RDMA channel.
135+
* @max_it_iu_len: Maximum initiator-to-target information unit length.
135136
* @max_ti_iu_len: Maximum target-to-initiator information unit length.
136137
*/
137138
struct srp_rdma_ch {
@@ -149,6 +150,7 @@ struct srp_rdma_ch {
149150
struct ib_fmr_pool *fmr_pool;
150151
struct srp_fr_pool *fr_pool;
151152
};
153+
uint32_t max_it_iu_len;
152154
uint32_t max_ti_iu_len;
153155

154156
/* Everything above this point is used in the hot path of
@@ -197,7 +199,6 @@ struct srp_target_port {
197199
u32 ch_count;
198200
u32 lkey;
199201
enum srp_target_state state;
200-
unsigned int max_iu_len;
201202
unsigned int cmd_sg_cnt;
202203
unsigned int indirect_size;
203204
bool allow_ext_sg;

0 commit comments

Comments
 (0)