Skip to content

Commit c5efb62

Browse files
KAGA-KOKOdledford
authored andcommitted
IB/srpt: Add P_Key support
Process connection requests that use another P_Key than the default correctly. Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 4413834 commit c5efb62

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

drivers/infiniband/ulp/srpt/ib_srpt.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/string.h>
4242
#include <linux/delay.h>
4343
#include <linux/atomic.h>
44+
#include <rdma/ib_cache.h>
4445
#include <scsi/scsi_proto.h>
4546
#include <scsi/scsi_tcq.h>
4647
#include <target/target_core_base.h>
@@ -1057,7 +1058,12 @@ static int srpt_init_ch_qp(struct srpt_rdma_ch *ch, struct ib_qp *qp)
10571058
attr->qp_state = IB_QPS_INIT;
10581059
attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE;
10591060
attr->port_num = ch->sport->port;
1060-
attr->pkey_index = 0;
1061+
1062+
ret = ib_find_cached_pkey(ch->sport->sdev->device, ch->sport->port,
1063+
ch->pkey, &attr->pkey_index);
1064+
if (ret < 0)
1065+
pr_err("Translating pkey %#x failed (%d) - using index 0\n",
1066+
ch->pkey, ret);
10611067

10621068
ret = ib_modify_qp(qp, attr,
10631069
IB_QP_STATE | IB_QP_ACCESS_FLAGS | IB_QP_PORT |
@@ -1994,9 +2000,10 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
19942000

19952001
it_iu_len = be32_to_cpu(req->req_it_iu_len);
19962002

1997-
pr_info("Received SRP_LOGIN_REQ with i_port_id %pI6, t_port_id %pI6 and it_iu_len %d on port %d (guid=%pI6)\n",
2003+
pr_info("Received SRP_LOGIN_REQ with i_port_id %pI6, t_port_id %pI6 and it_iu_len %d on port %d (guid=%pI6); pkey %#04x\n",
19982004
req->initiator_port_id, req->target_port_id, it_iu_len,
1999-
param->port, &sport->gid);
2005+
param->port, &sport->gid,
2006+
be16_to_cpu(param->primary_path->pkey));
20002007

20012008
rsp = kzalloc(sizeof(*rsp), GFP_KERNEL);
20022009
rej = kzalloc(sizeof(*rej), GFP_KERNEL);
@@ -2073,6 +2080,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
20732080

20742081
init_rcu_head(&ch->rcu);
20752082
kref_init(&ch->kref);
2083+
ch->pkey = be16_to_cpu(param->primary_path->pkey);
20762084
ch->zw_cqe.done = srpt_zerolength_write_done;
20772085
INIT_WORK(&ch->release_work, srpt_release_channel_work);
20782086
memcpy(ch->i_port_id, req->initiator_port_id, 16);

drivers/infiniband/ulp/srpt/ib_srpt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ enum rdma_ch_state {
266266
* @cmd_wait_list: List of SCSI commands that arrived before the RTU event. This
267267
* list contains struct srpt_ioctx elements and is protected
268268
* against concurrent modification by the cm_id spinlock.
269+
* @pkey: P_Key of the IB partition for this SRP channel.
269270
* @sess: Session information associated with this SRP channel.
270271
* @sess_name: Session name.
271272
* @ini_guid: Initiator port GUID.
@@ -294,6 +295,7 @@ struct srpt_rdma_ch {
294295
struct srpt_recv_ioctx **ioctx_recv_ring;
295296
struct list_head list;
296297
struct list_head cmd_wait_list;
298+
uint16_t pkey;
297299
struct se_session *sess;
298300
u8 sess_name[36];
299301
u8 ini_guid[24];

0 commit comments

Comments
 (0)