Skip to content

Commit bb12588

Browse files
dillowRoland Dreier
authored andcommitted
IB/srp: Implement SRP_CRED_REQ and SRP_AER_REQ
This patch adds support for SRP_CRED_REQ to avoid a lockup by targets that use that mechanism to return credits to the initiator. This prevents a lockup observed in the field where we would never add the credits from the SRP_CRED_REQ to our current count, and would therefore never send another command to the target. Minimal support for SRP_AER_REQ is also added, as these messages can also be used to convey additional credits to the initiator. Based upon extensive debugging and code by Bart Van Assche and a bug report by Chris Worley. Signed-off-by: David Dillow <dillowda@ornl.gov> Signed-off-by: Roland Dreier <rolandd@cisco.com>
1 parent dd5e6e3 commit bb12588

3 files changed

Lines changed: 141 additions & 10 deletions

File tree

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

Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ static void srp_remove_one(struct ib_device *device);
8383
static void srp_recv_completion(struct ib_cq *cq, void *target_ptr);
8484
static void srp_send_completion(struct ib_cq *cq, void *target_ptr);
8585
static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event);
86+
static struct srp_iu *__srp_get_tx_iu(struct srp_target_port *target,
87+
enum srp_iu_type iu_type);
88+
static int __srp_post_send(struct srp_target_port *target,
89+
struct srp_iu *iu, int len);
8690

8791
static struct scsi_transport_template *ib_srp_transport_template;
8892

@@ -896,6 +900,71 @@ static void srp_process_rsp(struct srp_target_port *target, struct srp_rsp *rsp)
896900
spin_unlock_irqrestore(target->scsi_host->host_lock, flags);
897901
}
898902

903+
static int srp_response_common(struct srp_target_port *target, s32 req_delta,
904+
void *rsp, int len)
905+
{
906+
struct ib_device *dev;
907+
unsigned long flags;
908+
struct srp_iu *iu;
909+
int err = 1;
910+
911+
dev = target->srp_host->srp_dev->dev;
912+
913+
spin_lock_irqsave(target->scsi_host->host_lock, flags);
914+
target->req_lim += req_delta;
915+
916+
iu = __srp_get_tx_iu(target, SRP_IU_RSP);
917+
if (!iu) {
918+
shost_printk(KERN_ERR, target->scsi_host, PFX
919+
"no IU available to send response\n");
920+
goto out;
921+
}
922+
923+
ib_dma_sync_single_for_cpu(dev, iu->dma, len, DMA_TO_DEVICE);
924+
memcpy(iu->buf, rsp, len);
925+
ib_dma_sync_single_for_device(dev, iu->dma, len, DMA_TO_DEVICE);
926+
927+
err = __srp_post_send(target, iu, len);
928+
if (err)
929+
shost_printk(KERN_ERR, target->scsi_host, PFX
930+
"unable to post response: %d\n", err);
931+
932+
out:
933+
spin_unlock_irqrestore(target->scsi_host->host_lock, flags);
934+
return err;
935+
}
936+
937+
static void srp_process_cred_req(struct srp_target_port *target,
938+
struct srp_cred_req *req)
939+
{
940+
struct srp_cred_rsp rsp = {
941+
.opcode = SRP_CRED_RSP,
942+
.tag = req->tag,
943+
};
944+
s32 delta = be32_to_cpu(req->req_lim_delta);
945+
946+
if (srp_response_common(target, delta, &rsp, sizeof rsp))
947+
shost_printk(KERN_ERR, target->scsi_host, PFX
948+
"problems processing SRP_CRED_REQ\n");
949+
}
950+
951+
static void srp_process_aer_req(struct srp_target_port *target,
952+
struct srp_aer_req *req)
953+
{
954+
struct srp_aer_rsp rsp = {
955+
.opcode = SRP_AER_RSP,
956+
.tag = req->tag,
957+
};
958+
s32 delta = be32_to_cpu(req->req_lim_delta);
959+
960+
shost_printk(KERN_ERR, target->scsi_host, PFX
961+
"ignoring AER for LUN %llu\n", be64_to_cpu(req->lun));
962+
963+
if (srp_response_common(target, delta, &rsp, sizeof rsp))
964+
shost_printk(KERN_ERR, target->scsi_host, PFX
965+
"problems processing SRP_AER_REQ\n");
966+
}
967+
899968
static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc)
900969
{
901970
struct ib_device *dev;
@@ -923,6 +992,14 @@ static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc)
923992
srp_process_rsp(target, iu->buf);
924993
break;
925994

995+
case SRP_CRED_REQ:
996+
srp_process_cred_req(target, iu->buf);
997+
break;
998+
999+
case SRP_AER_REQ:
1000+
srp_process_aer_req(target, iu->buf);
1001+
break;
1002+
9261003
case SRP_T_LOGOUT:
9271004
/* XXX Handle target logout */
9281005
shost_printk(KERN_WARNING, target->scsi_host,
@@ -985,23 +1062,36 @@ static void srp_send_completion(struct ib_cq *cq, void *target_ptr)
9851062
* Must be called with target->scsi_host->host_lock held to protect
9861063
* req_lim and tx_head. Lock cannot be dropped between call here and
9871064
* call to __srp_post_send().
1065+
*
1066+
* Note:
1067+
* An upper limit for the number of allocated information units for each
1068+
* request type is:
1069+
* - SRP_IU_CMD: SRP_CMD_SQ_SIZE, since the SCSI mid-layer never queues
1070+
* more than Scsi_Host.can_queue requests.
1071+
* - SRP_IU_TSK_MGMT: SRP_TSK_MGMT_SQ_SIZE.
1072+
* - SRP_IU_RSP: 1, since a conforming SRP target never sends more than
1073+
* one unanswered SRP request to an initiator.
9881074
*/
9891075
static struct srp_iu *__srp_get_tx_iu(struct srp_target_port *target,
990-
enum srp_request_type req_type)
1076+
enum srp_iu_type iu_type)
9911077
{
992-
s32 rsv = (req_type == SRP_REQ_TASK_MGMT) ? 0 : SRP_TSK_MGMT_SQ_SIZE;
1078+
s32 rsv = (iu_type == SRP_IU_TSK_MGMT) ? 0 : SRP_TSK_MGMT_SQ_SIZE;
1079+
struct srp_iu *iu;
9931080

9941081
srp_send_completion(target->send_cq, target);
9951082

9961083
if (target->tx_head - target->tx_tail >= SRP_SQ_SIZE)
9971084
return NULL;
9981085

999-
if (target->req_lim <= rsv) {
1086+
/* Initiator responses to target requests do not consume credits */
1087+
if (target->req_lim <= rsv && iu_type != SRP_IU_RSP) {
10001088
++target->zero_req_lim;
10011089
return NULL;
10021090
}
10031091

1004-
return target->tx_ring[target->tx_head & SRP_SQ_MASK];
1092+
iu = target->tx_ring[target->tx_head & SRP_SQ_MASK];
1093+
iu->type = iu_type;
1094+
return iu;
10051095
}
10061096

10071097
/*
@@ -1030,7 +1120,8 @@ static int __srp_post_send(struct srp_target_port *target,
10301120

10311121
if (!ret) {
10321122
++target->tx_head;
1033-
--target->req_lim;
1123+
if (iu->type != SRP_IU_RSP)
1124+
--target->req_lim;
10341125
}
10351126

10361127
return ret;
@@ -1056,7 +1147,7 @@ static int srp_queuecommand(struct scsi_cmnd *scmnd,
10561147
return 0;
10571148
}
10581149

1059-
iu = __srp_get_tx_iu(target, SRP_REQ_NORMAL);
1150+
iu = __srp_get_tx_iu(target, SRP_IU_CMD);
10601151
if (!iu)
10611152
goto err;
10621153

@@ -1363,7 +1454,7 @@ static int srp_send_tsk_mgmt(struct srp_target_port *target,
13631454

13641455
init_completion(&req->done);
13651456

1366-
iu = __srp_get_tx_iu(target, SRP_REQ_TASK_MGMT);
1457+
iu = __srp_get_tx_iu(target, SRP_IU_TSK_MGMT);
13671458
if (!iu)
13681459
goto out;
13691460

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ enum srp_target_state {
8282
SRP_TARGET_REMOVED
8383
};
8484

85-
enum srp_request_type {
86-
SRP_REQ_NORMAL,
87-
SRP_REQ_TASK_MGMT,
85+
enum srp_iu_type {
86+
SRP_IU_CMD,
87+
SRP_IU_TSK_MGMT,
88+
SRP_IU_RSP,
8889
};
8990

9091
struct srp_device {
@@ -171,6 +172,7 @@ struct srp_iu {
171172
void *buf;
172173
size_t size;
173174
enum dma_data_direction direction;
175+
enum srp_iu_type type;
174176
};
175177

176178
#endif /* IB_SRP_H */

‎include/scsi/srp.h‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,42 @@ struct srp_rsp {
239239
u8 data[0];
240240
} __attribute__((packed));
241241

242+
struct srp_cred_req {
243+
u8 opcode;
244+
u8 sol_not;
245+
u8 reserved[2];
246+
__be32 req_lim_delta;
247+
u64 tag;
248+
};
249+
250+
struct srp_cred_rsp {
251+
u8 opcode;
252+
u8 reserved[7];
253+
u64 tag;
254+
};
255+
256+
/*
257+
* The SRP spec defines the fixed portion of the AER_REQ structure to be
258+
* 36 bytes, so it needs to be packed to avoid having it padded to 40 bytes
259+
* on 64-bit architectures.
260+
*/
261+
struct srp_aer_req {
262+
u8 opcode;
263+
u8 sol_not;
264+
u8 reserved[2];
265+
__be32 req_lim_delta;
266+
u64 tag;
267+
u32 reserved2;
268+
__be64 lun;
269+
__be32 sense_data_len;
270+
u32 reserved3;
271+
u8 sense_data[0];
272+
} __attribute__((packed));
273+
274+
struct srp_aer_rsp {
275+
u8 opcode;
276+
u8 reserved[7];
277+
u64 tag;
278+
};
279+
242280
#endif /* SCSI_SRP_H */

0 commit comments

Comments
 (0)