Skip to content

Commit 3aeffc4

Browse files
Hakon-Buggejgunthorpe
authored andcommitted
IB/cma: Introduce rdma_set_min_rnr_timer()
Introduce the ability for kernel ULPs to adjust the minimum RNR Retry timer. The INIT -> RTR transition executed by RDMA CM will be used for this adjustment. This avoids an additional ib_modify_qp() call. rdma_set_min_rnr_timer() must be called before the call to rdma_connect() on the active side and before the call to rdma_accept() on the passive side. The default value of RNR Retry timer is zero, which translates to 655 ms. When the receiver is not ready to accept a send messages, it encodes the RNR Retry timer value in the NAK. The requestor will then wait at least the specified time value before retrying the send. The 5-bit value to be supplied to the rdma_set_min_rnr_timer() is documented in IBTA Table 45: "Encoding for RNR NAK Timer Field". Link: https://lore.kernel.org/r/1617216194-12890-2-git-send-email-haakon.bugge@oracle.com Signed-off-by: Håkon Bugge <haakon.bugge@oracle.com> Acked-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 8166e00 commit 3aeffc4

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎drivers/infiniband/core/cma.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ __rdma_create_id(struct net *net, rdma_cm_event_handler event_handler,
843843
id_priv->id.qp_type = qp_type;
844844
id_priv->tos_set = false;
845845
id_priv->timeout_set = false;
846+
id_priv->min_rnr_timer_set = false;
846847
id_priv->gid_type = IB_GID_TYPE_IB;
847848
spin_lock_init(&id_priv->lock);
848849
mutex_init(&id_priv->qp_mutex);
@@ -1133,6 +1134,9 @@ int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr,
11331134
if ((*qp_attr_mask & IB_QP_TIMEOUT) && id_priv->timeout_set)
11341135
qp_attr->timeout = id_priv->timeout;
11351136

1137+
if ((*qp_attr_mask & IB_QP_MIN_RNR_TIMER) && id_priv->min_rnr_timer_set)
1138+
qp_attr->min_rnr_timer = id_priv->min_rnr_timer;
1139+
11361140
return ret;
11371141
}
11381142
EXPORT_SYMBOL(rdma_init_qp_attr);
@@ -2608,6 +2612,43 @@ int rdma_set_ack_timeout(struct rdma_cm_id *id, u8 timeout)
26082612
}
26092613
EXPORT_SYMBOL(rdma_set_ack_timeout);
26102614

2615+
/**
2616+
* rdma_set_min_rnr_timer() - Set the minimum RNR Retry timer of the
2617+
* QP associated with a connection identifier.
2618+
* @id: Communication identifier to associated with service type.
2619+
* @min_rnr_timer: 5-bit value encoded as Table 45: "Encoding for RNR NAK
2620+
* Timer Field" in the IBTA specification.
2621+
*
2622+
* This function should be called before rdma_connect() on active
2623+
* side, and on passive side before rdma_accept(). The timer value
2624+
* will be associated with the local QP. When it receives a send it is
2625+
* not read to handle, typically if the receive queue is empty, an RNR
2626+
* Retry NAK is returned to the requester with the min_rnr_timer
2627+
* encoded. The requester will then wait at least the time specified
2628+
* in the NAK before retrying. The default is zero, which translates
2629+
* to a minimum RNR Timer value of 655 ms.
2630+
*
2631+
* Return: 0 for success
2632+
*/
2633+
int rdma_set_min_rnr_timer(struct rdma_cm_id *id, u8 min_rnr_timer)
2634+
{
2635+
struct rdma_id_private *id_priv;
2636+
2637+
/* It is a five-bit value */
2638+
if (min_rnr_timer & 0xe0)
2639+
return -EINVAL;
2640+
2641+
if (WARN_ON(id->qp_type != IB_QPT_RC && id->qp_type != IB_QPT_XRC_TGT))
2642+
return -EINVAL;
2643+
2644+
id_priv = container_of(id, struct rdma_id_private, id);
2645+
id_priv->min_rnr_timer = min_rnr_timer;
2646+
id_priv->min_rnr_timer_set = true;
2647+
2648+
return 0;
2649+
}
2650+
EXPORT_SYMBOL(rdma_set_min_rnr_timer);
2651+
26112652
static void cma_query_handler(int status, struct sa_path_rec *path_rec,
26122653
void *context)
26132654
{

‎drivers/infiniband/core/cma_priv.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ struct rdma_id_private {
8686
u8 tos;
8787
u8 tos_set:1;
8888
u8 timeout_set:1;
89+
u8 min_rnr_timer_set:1;
8990
u8 reuseaddr;
9091
u8 afonly;
9192
u8 timeout;
93+
u8 min_rnr_timer;
9294
enum ib_gid_type gid_type;
9395

9496
/*

‎include/rdma/rdma_cm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ int rdma_set_reuseaddr(struct rdma_cm_id *id, int reuse);
331331
int rdma_set_afonly(struct rdma_cm_id *id, int afonly);
332332

333333
int rdma_set_ack_timeout(struct rdma_cm_id *id, u8 timeout);
334+
335+
int rdma_set_min_rnr_timer(struct rdma_cm_id *id, u8 min_rnr_timer);
334336
/**
335337
* rdma_get_service_id - Return the IB service ID for a specified address.
336338
* @id: Communication identifier associated with the address.

0 commit comments

Comments
 (0)