Skip to content

Commit 2739b59

Browse files
Bart Van Asschedledford
authored andcommitted
IB/srpt: Eliminate srpt_find_channel()
In the CM REQ message handler, store the channel pointer in cm_id->context such that the function srpt_find_channel() is no longer needed. Additionally, make the CM event messages more informative. Signed-off-by: Bart Van Assche <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Cc: Sagi Grimberg <[email protected]> Cc: Alex Estrin <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 1e20a2a commit 2739b59

File tree

1 file changed

+29
-65
lines changed

1 file changed

+29
-65
lines changed

drivers/infiniband/ulp/srpt/ib_srpt.c

Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,25 +1890,14 @@ static int srpt_shutdown_session(struct se_session *se_sess)
18901890
* ib_destroy_cm_id(), which locks the cm_id spinlock and hence waits until
18911891
* this function has finished).
18921892
*/
1893-
static void srpt_drain_channel(struct ib_cm_id *cm_id)
1893+
static void srpt_drain_channel(struct srpt_rdma_ch *ch)
18941894
{
1895-
struct srpt_device *sdev;
1896-
struct srpt_rdma_ch *ch;
18971895
int ret;
18981896
bool do_reset = false;
18991897

19001898
WARN_ON_ONCE(irqs_disabled());
19011899

1902-
sdev = cm_id->context;
1903-
BUG_ON(!sdev);
1904-
spin_lock_irq(&sdev->spinlock);
1905-
list_for_each_entry(ch, &sdev->rch_list, list) {
1906-
if (ch->cm_id == cm_id) {
1907-
do_reset = srpt_set_ch_state(ch, CH_DRAINING);
1908-
break;
1909-
}
1910-
}
1911-
spin_unlock_irq(&sdev->spinlock);
1900+
do_reset = srpt_set_ch_state(ch, CH_DRAINING);
19121901

19131902
if (do_reset) {
19141903
if (ch->sess)
@@ -1921,34 +1910,6 @@ static void srpt_drain_channel(struct ib_cm_id *cm_id)
19211910
}
19221911
}
19231912

1924-
/**
1925-
* srpt_find_channel() - Look up an RDMA channel.
1926-
* @cm_id: Pointer to the CM ID of the channel to be looked up.
1927-
*
1928-
* Return NULL if no matching RDMA channel has been found.
1929-
*/
1930-
static struct srpt_rdma_ch *srpt_find_channel(struct srpt_device *sdev,
1931-
struct ib_cm_id *cm_id)
1932-
{
1933-
struct srpt_rdma_ch *ch;
1934-
bool found;
1935-
1936-
WARN_ON_ONCE(irqs_disabled());
1937-
BUG_ON(!sdev);
1938-
1939-
found = false;
1940-
spin_lock_irq(&sdev->spinlock);
1941-
list_for_each_entry(ch, &sdev->rch_list, list) {
1942-
if (ch->cm_id == cm_id) {
1943-
found = true;
1944-
break;
1945-
}
1946-
}
1947-
spin_unlock_irq(&sdev->spinlock);
1948-
1949-
return found ? ch : NULL;
1950-
}
1951-
19521913
/**
19531914
* srpt_release_channel() - Release channel resources.
19541915
*
@@ -2132,6 +2093,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
21322093
memcpy(ch->t_port_id, req->target_port_id, 16);
21332094
ch->sport = &sdev->port[param->port - 1];
21342095
ch->cm_id = cm_id;
2096+
cm_id->context = ch;
21352097
/*
21362098
* Avoid QUEUE_FULL conditions by limiting the number of buffers used
21372099
* for the SRP protocol to the command queue size.
@@ -2285,10 +2247,14 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
22852247
return ret;
22862248
}
22872249

2288-
static void srpt_cm_rej_recv(struct ib_cm_id *cm_id)
2250+
static void srpt_cm_rej_recv(struct srpt_rdma_ch *ch,
2251+
enum ib_cm_rej_reason reason,
2252+
const u8 *private_data,
2253+
u8 private_data_len)
22892254
{
2290-
pr_info("Received IB REJ for cm_id %p.\n", cm_id);
2291-
srpt_drain_channel(cm_id);
2255+
pr_info("Received CM REJ for ch %s-%d; reason %d.\n",
2256+
ch->sess_name, ch->qp->qp_num, reason);
2257+
srpt_drain_channel(ch);
22922258
}
22932259

22942260
/**
@@ -2297,14 +2263,10 @@ static void srpt_cm_rej_recv(struct ib_cm_id *cm_id)
22972263
* An IB_CM_RTU_RECEIVED message indicates that the connection is established
22982264
* and that the recipient may begin transmitting (RTU = ready to use).
22992265
*/
2300-
static void srpt_cm_rtu_recv(struct ib_cm_id *cm_id)
2266+
static void srpt_cm_rtu_recv(struct srpt_rdma_ch *ch)
23012267
{
2302-
struct srpt_rdma_ch *ch;
23032268
int ret;
23042269

2305-
ch = srpt_find_channel(cm_id->context, cm_id);
2306-
BUG_ON(!ch);
2307-
23082270
if (srpt_set_ch_state(ch, CH_LIVE)) {
23092271
struct srpt_recv_ioctx *ioctx, *ioctx_tmp;
23102272

@@ -2323,16 +2285,13 @@ static void srpt_cm_rtu_recv(struct ib_cm_id *cm_id)
23232285
/**
23242286
* srpt_cm_dreq_recv() - Process reception of a DREQ message.
23252287
*/
2326-
static void srpt_cm_dreq_recv(struct ib_cm_id *cm_id)
2288+
static void srpt_cm_dreq_recv(struct srpt_rdma_ch *ch)
23272289
{
2328-
struct srpt_rdma_ch *ch;
23292290
unsigned long flags;
23302291
bool send_drep = false;
23312292

2332-
ch = srpt_find_channel(cm_id->context, cm_id);
2333-
BUG_ON(!ch);
2334-
2335-
pr_debug("cm_id= %p ch->state= %d\n", cm_id, ch->state);
2293+
pr_debug("ch %s-%d state %d\n", ch->sess_name, ch->qp->qp_num,
2294+
ch->state);
23362295

23372296
spin_lock_irqsave(&ch->spinlock, flags);
23382297
switch (ch->state) {
@@ -2369,6 +2328,7 @@ static void srpt_cm_dreq_recv(struct ib_cm_id *cm_id)
23692328
*/
23702329
static int srpt_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
23712330
{
2331+
struct srpt_rdma_ch *ch = cm_id->context;
23722332
int ret;
23732333

23742334
ret = 0;
@@ -2378,27 +2338,31 @@ static int srpt_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
23782338
event->private_data);
23792339
break;
23802340
case IB_CM_REJ_RECEIVED:
2381-
srpt_cm_rej_recv(cm_id);
2341+
srpt_cm_rej_recv(ch, event->param.rej_rcvd.reason,
2342+
event->private_data,
2343+
IB_CM_REJ_PRIVATE_DATA_SIZE);
23822344
break;
23832345
case IB_CM_RTU_RECEIVED:
23842346
case IB_CM_USER_ESTABLISHED:
2385-
srpt_cm_rtu_recv(cm_id);
2347+
srpt_cm_rtu_recv(ch);
23862348
break;
23872349
case IB_CM_DREQ_RECEIVED:
2388-
srpt_cm_dreq_recv(cm_id);
2350+
srpt_cm_dreq_recv(ch);
23892351
break;
23902352
case IB_CM_DREP_RECEIVED:
2391-
pr_info("Received CM DREP message for cm_id %p.\n",
2392-
cm_id);
2393-
srpt_drain_channel(cm_id);
2353+
pr_info("Received CM DREP message for ch %s-%d.\n",
2354+
ch->sess_name, ch->qp->qp_num);
2355+
srpt_drain_channel(ch);
23942356
break;
23952357
case IB_CM_TIMEWAIT_EXIT:
2396-
pr_info("Received CM TimeWait exit for cm_id %p.\n", cm_id);
2397-
srpt_drain_channel(cm_id);
2358+
pr_info("Received CM TimeWait exit for ch %s-%d.\n",
2359+
ch->sess_name, ch->qp->qp_num);
2360+
srpt_drain_channel(ch);
23982361
break;
23992362
case IB_CM_REP_ERROR:
2400-
pr_info("Received CM REP error for cm_id %p.\n", cm_id);
2401-
srpt_drain_channel(cm_id);
2363+
pr_info("Received CM REP error for ch %s-%d.\n", ch->sess_name,
2364+
ch->qp->qp_num);
2365+
srpt_drain_channel(ch);
24022366
break;
24032367
case IB_CM_DREQ_ERROR:
24042368
pr_info("Received CM DREQ ERROR event.\n");

0 commit comments

Comments
 (0)