blob: c1b6270262c297f8af8c902c40eec32aa6eae215 [file] [log] [blame]
Tom Tuckeref7fbf52007-12-12 16:13:19 -06001/*
2 * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the BSD-type
8 * license below:
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
21 *
22 * Neither the name of the Network Appliance, Inc. nor the names of
23 * its contributors may be used to endorse or promote products
24 * derived from this software without specific prior written
25 * permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 * Author: Tom Tucker <tom@opengridcomputing.com>
40 */
41#include <linux/module.h>
42#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090043#include <linux/slab.h>
Tom Tuckeref7fbf52007-12-12 16:13:19 -060044#include <linux/fs.h>
45#include <linux/sysctl.h>
Tejun Heoa25e7582010-10-15 17:49:27 +020046#include <linux/workqueue.h>
Tom Tuckeref7fbf52007-12-12 16:13:19 -060047#include <linux/sunrpc/clnt.h>
48#include <linux/sunrpc/sched.h>
49#include <linux/sunrpc/svc_rdma.h>
Tom Tuckercec56c82012-02-15 11:30:00 -060050#include "xprt_rdma.h"
Tom Tuckeref7fbf52007-12-12 16:13:19 -060051
52#define RPCDBG_FACILITY RPCDBG_SVCXPRT
53
54/* RPC/RDMA parameters */
55unsigned int svcrdma_ord = RPCRDMA_ORD;
56static unsigned int min_ord = 1;
57static unsigned int max_ord = 4096;
58unsigned int svcrdma_max_requests = RPCRDMA_MAX_REQUESTS;
59static unsigned int min_max_requests = 4;
60static unsigned int max_max_requests = 16384;
61unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
62static unsigned int min_max_inline = 4096;
63static unsigned int max_max_inline = 65536;
64
65atomic_t rdma_stat_recv;
66atomic_t rdma_stat_read;
67atomic_t rdma_stat_write;
68atomic_t rdma_stat_sq_starve;
69atomic_t rdma_stat_rq_starve;
70atomic_t rdma_stat_rq_poll;
71atomic_t rdma_stat_rq_prod;
72atomic_t rdma_stat_sq_poll;
73atomic_t rdma_stat_sq_prod;
74
Tom Tuckerbf5927d2008-05-28 14:05:54 -050075/* Temporary NFS request map and context caches */
Tom Tuckerab96ddd2008-05-28 13:54:04 -050076struct kmem_cache *svc_rdma_map_cachep;
Tom Tuckerbf5927d2008-05-28 14:05:54 -050077struct kmem_cache *svc_rdma_ctxt_cachep;
Tom Tuckerab96ddd2008-05-28 13:54:04 -050078
Tejun Heoa25e7582010-10-15 17:49:27 +020079struct workqueue_struct *svc_rdma_wq;
80
Tom Tuckeref7fbf52007-12-12 16:13:19 -060081/*
82 * This function implements reading and resetting an atomic_t stat
83 * variable through read/write to a proc file. Any write to the file
84 * resets the associated statistic to zero. Any read returns it's
85 * current value.
86 */
Joe Perchesfe2c6332013-06-11 23:04:25 -070087static int read_reset_stat(struct ctl_table *table, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070088 void __user *buffer, size_t *lenp,
Tom Tuckeref7fbf52007-12-12 16:13:19 -060089 loff_t *ppos)
90{
91 atomic_t *stat = (atomic_t *)table->data;
92
93 if (!stat)
94 return -EINVAL;
95
96 if (write)
97 atomic_set(stat, 0);
98 else {
99 char str_buf[32];
100 char *data;
101 int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat));
102 if (len >= 32)
103 return -EFAULT;
104 len = strlen(str_buf);
105 if (*ppos > len) {
106 *lenp = 0;
107 return 0;
108 }
109 data = &str_buf[*ppos];
110 len -= *ppos;
111 if (len > *lenp)
112 len = *lenp;
113 if (len && copy_to_user(buffer, str_buf, len))
114 return -EFAULT;
115 *lenp = len;
116 *ppos += len;
117 }
118 return 0;
119}
120
121static struct ctl_table_header *svcrdma_table_header;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700122static struct ctl_table svcrdma_parm_table[] = {
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600123 {
124 .procname = "max_requests",
125 .data = &svcrdma_max_requests,
126 .maxlen = sizeof(unsigned int),
127 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800128 .proc_handler = proc_dointvec_minmax,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600129 .extra1 = &min_max_requests,
130 .extra2 = &max_max_requests
131 },
132 {
133 .procname = "max_req_size",
134 .data = &svcrdma_max_req_size,
135 .maxlen = sizeof(unsigned int),
136 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800137 .proc_handler = proc_dointvec_minmax,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600138 .extra1 = &min_max_inline,
139 .extra2 = &max_max_inline
140 },
141 {
142 .procname = "max_outbound_read_requests",
143 .data = &svcrdma_ord,
144 .maxlen = sizeof(unsigned int),
145 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800146 .proc_handler = proc_dointvec_minmax,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600147 .extra1 = &min_ord,
148 .extra2 = &max_ord,
149 },
150
151 {
152 .procname = "rdma_stat_read",
153 .data = &rdma_stat_read,
154 .maxlen = sizeof(atomic_t),
155 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800156 .proc_handler = read_reset_stat,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600157 },
158 {
159 .procname = "rdma_stat_recv",
160 .data = &rdma_stat_recv,
161 .maxlen = sizeof(atomic_t),
162 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800163 .proc_handler = read_reset_stat,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600164 },
165 {
166 .procname = "rdma_stat_write",
167 .data = &rdma_stat_write,
168 .maxlen = sizeof(atomic_t),
169 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800170 .proc_handler = read_reset_stat,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600171 },
172 {
173 .procname = "rdma_stat_sq_starve",
174 .data = &rdma_stat_sq_starve,
175 .maxlen = sizeof(atomic_t),
176 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800177 .proc_handler = read_reset_stat,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600178 },
179 {
180 .procname = "rdma_stat_rq_starve",
181 .data = &rdma_stat_rq_starve,
182 .maxlen = sizeof(atomic_t),
183 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800184 .proc_handler = read_reset_stat,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600185 },
186 {
187 .procname = "rdma_stat_rq_poll",
188 .data = &rdma_stat_rq_poll,
189 .maxlen = sizeof(atomic_t),
190 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800191 .proc_handler = read_reset_stat,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600192 },
193 {
194 .procname = "rdma_stat_rq_prod",
195 .data = &rdma_stat_rq_prod,
196 .maxlen = sizeof(atomic_t),
197 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800198 .proc_handler = read_reset_stat,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600199 },
200 {
201 .procname = "rdma_stat_sq_poll",
202 .data = &rdma_stat_sq_poll,
203 .maxlen = sizeof(atomic_t),
204 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800205 .proc_handler = read_reset_stat,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600206 },
207 {
208 .procname = "rdma_stat_sq_prod",
209 .data = &rdma_stat_sq_prod,
210 .maxlen = sizeof(atomic_t),
211 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800212 .proc_handler = read_reset_stat,
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600213 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800214 { },
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600215};
216
Joe Perchesfe2c6332013-06-11 23:04:25 -0700217static struct ctl_table svcrdma_table[] = {
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600218 {
219 .procname = "svc_rdma",
220 .mode = 0555,
221 .child = svcrdma_parm_table
222 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800223 { },
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600224};
225
Joe Perchesfe2c6332013-06-11 23:04:25 -0700226static struct ctl_table svcrdma_root_table[] = {
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600227 {
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600228 .procname = "sunrpc",
229 .mode = 0555,
230 .child = svcrdma_table
231 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800232 { },
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600233};
234
235void svc_rdma_cleanup(void)
236{
237 dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n");
Tejun Heoa25e7582010-10-15 17:49:27 +0200238 destroy_workqueue(svc_rdma_wq);
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600239 if (svcrdma_table_header) {
240 unregister_sysctl_table(svcrdma_table_header);
241 svcrdma_table_header = NULL;
242 }
243 svc_unreg_xprt_class(&svc_rdma_class);
Tom Tuckerab96ddd2008-05-28 13:54:04 -0500244 kmem_cache_destroy(svc_rdma_map_cachep);
Tom Tuckerbf5927d2008-05-28 14:05:54 -0500245 kmem_cache_destroy(svc_rdma_ctxt_cachep);
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600246}
247
248int svc_rdma_init(void)
249{
250 dprintk("SVCRDMA Module Init, register RPC RDMA transport\n");
251 dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord);
252 dprintk("\tmax_requests : %d\n", svcrdma_max_requests);
253 dprintk("\tsq_depth : %d\n",
254 svcrdma_max_requests * RPCRDMA_SQ_DEPTH_MULT);
255 dprintk("\tmax_inline : %d\n", svcrdma_max_req_size);
Tejun Heoa25e7582010-10-15 17:49:27 +0200256
257 svc_rdma_wq = alloc_workqueue("svc_rdma", 0, 0);
258 if (!svc_rdma_wq)
259 return -ENOMEM;
260
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600261 if (!svcrdma_table_header)
262 svcrdma_table_header =
263 register_sysctl_table(svcrdma_root_table);
264
Tom Tuckerab96ddd2008-05-28 13:54:04 -0500265 /* Create the temporary map cache */
266 svc_rdma_map_cachep = kmem_cache_create("svc_rdma_map_cache",
267 sizeof(struct svc_rdma_req_map),
268 0,
269 SLAB_HWCACHE_ALIGN,
270 NULL);
271 if (!svc_rdma_map_cachep) {
272 printk(KERN_INFO "Could not allocate map cache.\n");
Tom Tuckerbf5927d2008-05-28 14:05:54 -0500273 goto err0;
274 }
275
276 /* Create the temporary context cache */
277 svc_rdma_ctxt_cachep =
278 kmem_cache_create("svc_rdma_ctxt_cache",
279 sizeof(struct svc_rdma_op_ctxt),
280 0,
281 SLAB_HWCACHE_ALIGN,
282 NULL);
283 if (!svc_rdma_ctxt_cachep) {
284 printk(KERN_INFO "Could not allocate WR ctxt cache.\n");
285 goto err1;
Tom Tuckerab96ddd2008-05-28 13:54:04 -0500286 }
287
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600288 /* Register RDMA with the SVC transport switch */
289 svc_reg_xprt_class(&svc_rdma_class);
290 return 0;
Tom Tuckerbf5927d2008-05-28 14:05:54 -0500291 err1:
292 kmem_cache_destroy(svc_rdma_map_cachep);
293 err0:
Tom Tuckerab96ddd2008-05-28 13:54:04 -0500294 unregister_sysctl_table(svcrdma_table_header);
Tejun Heoa25e7582010-10-15 17:49:27 +0200295 destroy_workqueue(svc_rdma_wq);
Tom Tuckerab96ddd2008-05-28 13:54:04 -0500296 return -ENOMEM;
Tom Tuckeref7fbf52007-12-12 16:13:19 -0600297}
298MODULE_AUTHOR("Tom Tucker <tom@opengridcomputing.com>");
299MODULE_DESCRIPTION("SVC RDMA Transport");
300MODULE_LICENSE("Dual BSD/GPL");
301module_init(svc_rdma_init);
302module_exit(svc_rdma_cleanup);