Skip to content

Commit dd5e6e3

Browse files
bvanasscheRoland Dreier
authored andcommitted
IB/srp: Preparation for transmit ring response allocation
The transmit ring in ib_srp (srp_target.tx_ring) is currently only used for allocating requests sent by the initiator to the target. This patch prepares using that ring for allocation of both requests and responses. Also, this patch differentiates the uses of SRP_SQ_SIZE, increases the size of the IB send completion queue by one element and reserves one transmit ring slot for SRP_TSK_MGMT requests. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: David Dillow <dillowda@ornl.gov> Signed-off-by: Roland Dreier <rolandd@cisco.com>
1 parent fb50a83 commit dd5e6e3

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

‎drivers/infiniband/ulp/srp/ib_srp.c‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static void srp_free_target_ib(struct srp_target_port *target)
291291

292292
for (i = 0; i < SRP_RQ_SIZE; ++i)
293293
srp_free_iu(target->srp_host, target->rx_ring[i]);
294-
for (i = 0; i < SRP_SQ_SIZE + 1; ++i)
294+
for (i = 0; i < SRP_SQ_SIZE; ++i)
295295
srp_free_iu(target->srp_host, target->tx_ring[i]);
296296
}
297297

@@ -822,7 +822,7 @@ static int srp_post_recv(struct srp_target_port *target)
822822

823823
spin_lock_irqsave(target->scsi_host->host_lock, flags);
824824

825-
next = target->rx_head & (SRP_RQ_SIZE - 1);
825+
next = target->rx_head & SRP_RQ_MASK;
826826
wr.wr_id = next;
827827
iu = target->rx_ring[next];
828828

@@ -989,19 +989,19 @@ static void srp_send_completion(struct ib_cq *cq, void *target_ptr)
989989
static struct srp_iu *__srp_get_tx_iu(struct srp_target_port *target,
990990
enum srp_request_type req_type)
991991
{
992-
s32 min = (req_type == SRP_REQ_TASK_MGMT) ? 1 : 2;
992+
s32 rsv = (req_type == SRP_REQ_TASK_MGMT) ? 0 : SRP_TSK_MGMT_SQ_SIZE;
993993

994994
srp_send_completion(target->send_cq, target);
995995

996996
if (target->tx_head - target->tx_tail >= SRP_SQ_SIZE)
997997
return NULL;
998998

999-
if (target->req_lim < min) {
999+
if (target->req_lim <= rsv) {
10001000
++target->zero_req_lim;
10011001
return NULL;
10021002
}
10031003

1004-
return target->tx_ring[target->tx_head & SRP_SQ_SIZE];
1004+
return target->tx_ring[target->tx_head & SRP_SQ_MASK];
10051005
}
10061006

10071007
/*
@@ -1020,7 +1020,7 @@ static int __srp_post_send(struct srp_target_port *target,
10201020
list.lkey = target->srp_host->srp_dev->mr->lkey;
10211021

10221022
wr.next = NULL;
1023-
wr.wr_id = target->tx_head & SRP_SQ_SIZE;
1023+
wr.wr_id = target->tx_head & SRP_SQ_MASK;
10241024
wr.sg_list = &list;
10251025
wr.num_sge = 1;
10261026
wr.opcode = IB_WR_SEND;
@@ -1121,7 +1121,7 @@ static int srp_alloc_iu_bufs(struct srp_target_port *target)
11211121
goto err;
11221122
}
11231123

1124-
for (i = 0; i < SRP_SQ_SIZE + 1; ++i) {
1124+
for (i = 0; i < SRP_SQ_SIZE; ++i) {
11251125
target->tx_ring[i] = srp_alloc_iu(target->srp_host,
11261126
srp_max_iu_len,
11271127
GFP_KERNEL, DMA_TO_DEVICE);
@@ -1137,7 +1137,7 @@ static int srp_alloc_iu_bufs(struct srp_target_port *target)
11371137
target->rx_ring[i] = NULL;
11381138
}
11391139

1140-
for (i = 0; i < SRP_SQ_SIZE + 1; ++i) {
1140+
for (i = 0; i < SRP_SQ_SIZE; ++i) {
11411141
srp_free_iu(target->srp_host, target->tx_ring[i]);
11421142
target->tx_ring[i] = NULL;
11431143
}
@@ -1626,9 +1626,9 @@ static struct scsi_host_template srp_template = {
16261626
.eh_abort_handler = srp_abort,
16271627
.eh_device_reset_handler = srp_reset_device,
16281628
.eh_host_reset_handler = srp_reset_host,
1629-
.can_queue = SRP_SQ_SIZE,
1629+
.can_queue = SRP_CMD_SQ_SIZE,
16301630
.this_id = -1,
1631-
.cmd_per_lun = SRP_SQ_SIZE,
1631+
.cmd_per_lun = SRP_CMD_SQ_SIZE,
16321632
.use_clustering = ENABLE_CLUSTERING,
16331633
.shost_attrs = srp_host_attrs
16341634
};
@@ -1813,7 +1813,7 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
18131813
printk(KERN_WARNING PFX "bad max cmd_per_lun parameter '%s'\n", p);
18141814
goto out;
18151815
}
1816-
target->scsi_host->cmd_per_lun = min(token, SRP_SQ_SIZE);
1816+
target->scsi_host->cmd_per_lun = min(token, SRP_CMD_SQ_SIZE);
18171817
break;
18181818

18191819
case SRP_OPT_IO_CLASS:
@@ -1891,7 +1891,7 @@ static ssize_t srp_create_target(struct device *dev,
18911891

18921892
INIT_LIST_HEAD(&target->free_reqs);
18931893
INIT_LIST_HEAD(&target->req_queue);
1894-
for (i = 0; i < SRP_SQ_SIZE; ++i) {
1894+
for (i = 0; i < SRP_CMD_SQ_SIZE; ++i) {
18951895
target->req_ring[i].index = i;
18961896
list_add_tail(&target->req_ring[i].list, &target->free_reqs);
18971897
}
@@ -2159,6 +2159,9 @@ static int __init srp_init_module(void)
21592159
{
21602160
int ret;
21612161

2162+
BUILD_BUG_ON_NOT_POWER_OF_2(SRP_SQ_SIZE);
2163+
BUILD_BUG_ON_NOT_POWER_OF_2(SRP_RQ_SIZE);
2164+
21622165
if (srp_sg_tablesize > 255) {
21632166
printk(KERN_WARNING PFX "Clamping srp_sg_tablesize to 255\n");
21642167
srp_sg_tablesize = 255;

‎drivers/infiniband/ulp/srp/ib_srp.h‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ enum {
5959

6060
SRP_RQ_SHIFT = 6,
6161
SRP_RQ_SIZE = 1 << SRP_RQ_SHIFT,
62-
SRP_SQ_SIZE = SRP_RQ_SIZE - 1,
62+
SRP_RQ_MASK = SRP_RQ_SIZE - 1,
63+
64+
SRP_SQ_SIZE = SRP_RQ_SIZE,
65+
SRP_SQ_MASK = SRP_SQ_SIZE - 1,
66+
SRP_RSP_SQ_SIZE = 1,
67+
SRP_REQ_SQ_SIZE = SRP_SQ_SIZE - SRP_RSP_SQ_SIZE,
68+
SRP_TSK_MGMT_SQ_SIZE = 1,
69+
SRP_CMD_SQ_SIZE = SRP_REQ_SQ_SIZE - SRP_TSK_MGMT_SQ_SIZE,
6370

6471
SRP_TAG_TSK_MGMT = 1 << (SRP_RQ_SHIFT + 1),
6572

@@ -144,11 +151,11 @@ struct srp_target_port {
144151

145152
unsigned tx_head;
146153
unsigned tx_tail;
147-
struct srp_iu *tx_ring[SRP_SQ_SIZE + 1];
154+
struct srp_iu *tx_ring[SRP_SQ_SIZE];
148155

149156
struct list_head free_reqs;
150157
struct list_head req_queue;
151-
struct srp_request req_ring[SRP_SQ_SIZE];
158+
struct srp_request req_ring[SRP_CMD_SQ_SIZE];
152159

153160
struct work_struct work;
154161

0 commit comments

Comments
 (0)