Skip to content

Commit b54054c

Browse files
chuckleveramschuma-ntap
authored andcommitted
xprtrdma: Clean up device capability detection
Clean up: Move device capability detection into memreg-specific source files. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Tested-by: Steve Wise <swise@opengridcomputing.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent a473018 commit b54054c

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

net/sunrpc/xprtrdma/fmr_ops.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ enum {
3434
IB_ACCESS_REMOTE_READ,
3535
};
3636

37+
bool
38+
fmr_is_supported(struct rpcrdma_ia *ia)
39+
{
40+
if (!ia->ri_device->alloc_fmr) {
41+
pr_info("rpcrdma: 'fmr' mode is not supported by device %s\n",
42+
ia->ri_device->name);
43+
return false;
44+
}
45+
return true;
46+
}
47+
3748
static int
3849
__fmr_init(struct rpcrdma_mw *mw, struct ib_pd *pd)
3950
{

net/sunrpc/xprtrdma/frwr_ops.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@
7373
# define RPCDBG_FACILITY RPCDBG_TRANS
7474
#endif
7575

76+
bool
77+
frwr_is_supported(struct rpcrdma_ia *ia)
78+
{
79+
struct ib_device_attr *attrs = &ia->ri_device->attrs;
80+
81+
if (!(attrs->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS))
82+
goto out_not_supported;
83+
if (attrs->max_fast_reg_page_list_len == 0)
84+
goto out_not_supported;
85+
return true;
86+
87+
out_not_supported:
88+
pr_info("rpcrdma: 'frwr' mode is not supported by device %s\n",
89+
ia->ri_device->name);
90+
return false;
91+
}
92+
7693
static int
7794
__frwr_init(struct rpcrdma_mw *r, struct ib_pd *pd, unsigned int depth)
7895
{

net/sunrpc/xprtrdma/verbs.c

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -389,44 +389,29 @@ rpcrdma_ia_open(struct rpcrdma_xprt *xprt, struct sockaddr *addr, int memreg)
389389
ia->ri_pd = ib_alloc_pd(ia->ri_device);
390390
if (IS_ERR(ia->ri_pd)) {
391391
rc = PTR_ERR(ia->ri_pd);
392-
dprintk("RPC: %s: ib_alloc_pd() failed %i\n",
393-
__func__, rc);
392+
pr_err("rpcrdma: ib_alloc_pd() returned %d\n", rc);
394393
goto out2;
395394
}
396395

397-
if (memreg == RPCRDMA_FRMR) {
398-
if (!(ia->ri_device->attrs.device_cap_flags &
399-
IB_DEVICE_MEM_MGT_EXTENSIONS) ||
400-
(ia->ri_device->attrs.max_fast_reg_page_list_len == 0)) {
401-
dprintk("RPC: %s: FRMR registration "
402-
"not supported by HCA\n", __func__);
403-
memreg = RPCRDMA_MTHCAFMR;
404-
}
405-
}
406-
if (memreg == RPCRDMA_MTHCAFMR) {
407-
if (!ia->ri_device->alloc_fmr) {
408-
dprintk("RPC: %s: MTHCAFMR registration "
409-
"not supported by HCA\n", __func__);
410-
rc = -EINVAL;
411-
goto out3;
412-
}
413-
}
414-
415396
switch (memreg) {
416397
case RPCRDMA_FRMR:
417-
ia->ri_ops = &rpcrdma_frwr_memreg_ops;
418-
break;
398+
if (frwr_is_supported(ia)) {
399+
ia->ri_ops = &rpcrdma_frwr_memreg_ops;
400+
break;
401+
}
402+
/*FALLTHROUGH*/
419403
case RPCRDMA_MTHCAFMR:
420-
ia->ri_ops = &rpcrdma_fmr_memreg_ops;
421-
break;
404+
if (fmr_is_supported(ia)) {
405+
ia->ri_ops = &rpcrdma_fmr_memreg_ops;
406+
break;
407+
}
408+
/*FALLTHROUGH*/
422409
default:
423-
printk(KERN_ERR "RPC: Unsupported memory "
424-
"registration mode: %d\n", memreg);
425-
rc = -ENOMEM;
410+
pr_err("rpcrdma: Unsupported memory registration mode: %d\n",
411+
memreg);
412+
rc = -EINVAL;
426413
goto out3;
427414
}
428-
dprintk("RPC: %s: memory registration strategy is '%s'\n",
429-
__func__, ia->ri_ops->ro_displayname);
430415

431416
return 0;
432417

net/sunrpc/xprtrdma/xprt_rdma.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ extern int xprt_rdma_pad_optimize;
446446
*/
447447
int rpcrdma_ia_open(struct rpcrdma_xprt *, struct sockaddr *, int);
448448
void rpcrdma_ia_close(struct rpcrdma_ia *);
449+
bool frwr_is_supported(struct rpcrdma_ia *);
450+
bool fmr_is_supported(struct rpcrdma_ia *);
449451

450452
/*
451453
* Endpoint calls - xprtrdma/verbs.c

0 commit comments

Comments
 (0)