Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Oracle. All rights reserved. |
| 3 | * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | /* No-op chunk preparation. All client memory is pre-registered. |
| 7 | * Sometimes referred to as ALLPHYSICAL mode. |
| 8 | * |
| 9 | * Physical registration is simple because all client memory is |
| 10 | * pre-registered and never deregistered. This mode is good for |
| 11 | * adapter bring up, but is considered not safe: the server is |
| 12 | * trusted not to abuse its access to client memory not involved |
| 13 | * in RDMA I/O. |
| 14 | */ |
| 15 | |
| 16 | #include "xprt_rdma.h" |
| 17 | |
| 18 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
| 19 | # define RPCDBG_FACILITY RPCDBG_TRANS |
| 20 | #endif |
| 21 | |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 22 | static int |
| 23 | physical_op_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep, |
| 24 | struct rpcrdma_create_data_internal *cdata) |
| 25 | { |
Chuck Lever | d1ed857 | 2015-08-03 13:03:30 -0400 | [diff] [blame] | 26 | struct ib_device_attr *devattr = &ia->ri_devattr; |
| 27 | struct ib_mr *mr; |
| 28 | |
| 29 | /* Obtain an rkey to use for RPC data payloads. |
| 30 | */ |
| 31 | mr = ib_get_dma_mr(ia->ri_pd, |
| 32 | IB_ACCESS_LOCAL_WRITE | |
| 33 | IB_ACCESS_REMOTE_WRITE | |
| 34 | IB_ACCESS_REMOTE_READ); |
| 35 | if (IS_ERR(mr)) { |
| 36 | pr_err("%s: ib_get_dma_mr for failed with %lX\n", |
| 37 | __func__, PTR_ERR(mr)); |
| 38 | return -ENOMEM; |
| 39 | } |
| 40 | ia->ri_dma_mr = mr; |
| 41 | |
| 42 | /* Obtain an lkey to use for regbufs. |
| 43 | */ |
| 44 | if (devattr->device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY) |
| 45 | ia->ri_dma_lkey = ia->ri_device->local_dma_lkey; |
| 46 | else |
| 47 | ia->ri_dma_lkey = ia->ri_dma_mr->lkey; |
| 48 | |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 49 | return 0; |
| 50 | } |
| 51 | |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 52 | /* PHYSICAL memory registration conveys one page per chunk segment. |
| 53 | */ |
| 54 | static size_t |
| 55 | physical_op_maxpages(struct rpcrdma_xprt *r_xprt) |
| 56 | { |
| 57 | return min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS, |
| 58 | rpcrdma_max_segments(r_xprt)); |
| 59 | } |
| 60 | |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 61 | static int |
| 62 | physical_op_init(struct rpcrdma_xprt *r_xprt) |
| 63 | { |
| 64 | return 0; |
| 65 | } |
| 66 | |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 67 | /* The client's physical memory is already exposed for |
| 68 | * remote access via RDMA READ or RDMA WRITE. |
| 69 | */ |
| 70 | static int |
| 71 | physical_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg, |
| 72 | int nsegs, bool writing) |
| 73 | { |
| 74 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
| 75 | |
Chuck Lever | 89e0d112 | 2015-05-26 11:51:56 -0400 | [diff] [blame] | 76 | rpcrdma_map_one(ia->ri_device, seg, rpcrdma_data_dir(writing)); |
Chuck Lever | d1ed857 | 2015-08-03 13:03:30 -0400 | [diff] [blame] | 77 | seg->mr_rkey = ia->ri_dma_mr->rkey; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 78 | seg->mr_base = seg->mr_dma; |
| 79 | seg->mr_nsegs = 1; |
| 80 | return 1; |
| 81 | } |
| 82 | |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 83 | /* Unmap a memory region, but leave it registered. |
| 84 | */ |
| 85 | static int |
| 86 | physical_op_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg) |
| 87 | { |
Chuck Lever | d654788 | 2015-03-30 14:35:44 -0400 | [diff] [blame] | 88 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
| 89 | |
Chuck Lever | 89e0d112 | 2015-05-26 11:51:56 -0400 | [diff] [blame] | 90 | rpcrdma_unmap_one(ia->ri_device, seg); |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 91 | return 1; |
| 92 | } |
| 93 | |
Chuck Lever | 31a701a | 2015-03-30 14:35:07 -0400 | [diff] [blame] | 94 | static void |
Chuck Lever | 4561f34 | 2015-03-30 14:35:17 -0400 | [diff] [blame] | 95 | physical_op_destroy(struct rpcrdma_buffer *buf) |
| 96 | { |
| 97 | } |
| 98 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 99 | const struct rpcrdma_memreg_ops rpcrdma_physical_memreg_ops = { |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 100 | .ro_map = physical_op_map, |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 101 | .ro_unmap = physical_op_unmap, |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 102 | .ro_open = physical_op_open, |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 103 | .ro_maxpages = physical_op_maxpages, |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 104 | .ro_init = physical_op_init, |
Chuck Lever | 4561f34 | 2015-03-30 14:35:17 -0400 | [diff] [blame] | 105 | .ro_destroy = physical_op_destroy, |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 106 | .ro_displayname = "physical", |
| 107 | }; |