2 * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
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
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
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.
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
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.
39 * Author: Tom Tucker <tom@opengridcomputing.com>
41 #include <linux/module.h>
42 #include <linux/init.h>
43 #include <linux/slab.h>
45 #include <linux/sysctl.h>
46 #include <linux/sunrpc/clnt.h>
47 #include <linux/sunrpc/sched.h>
48 #include <linux/sunrpc/svc_rdma.h>
50 #define RPCDBG_FACILITY RPCDBG_SVCXPRT
52 /* RPC/RDMA parameters */
53 unsigned int svcrdma_ord = RPCRDMA_ORD;
54 static unsigned int min_ord = 1;
55 static unsigned int max_ord = 4096;
56 unsigned int svcrdma_max_requests = RPCRDMA_MAX_REQUESTS;
57 static unsigned int min_max_requests = 4;
58 static unsigned int max_max_requests = 16384;
59 unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
60 static unsigned int min_max_inline = 4096;
61 static unsigned int max_max_inline = 65536;
63 atomic_t rdma_stat_recv;
64 atomic_t rdma_stat_read;
65 atomic_t rdma_stat_write;
66 atomic_t rdma_stat_sq_starve;
67 atomic_t rdma_stat_rq_starve;
68 atomic_t rdma_stat_rq_poll;
69 atomic_t rdma_stat_rq_prod;
70 atomic_t rdma_stat_sq_poll;
71 atomic_t rdma_stat_sq_prod;
73 /* Temporary NFS request map and context caches */
74 struct kmem_cache *svc_rdma_map_cachep;
75 struct kmem_cache *svc_rdma_ctxt_cachep;
78 * This function implements reading and resetting an atomic_t stat
79 * variable through read/write to a proc file. Any write to the file
80 * resets the associated statistic to zero. Any read returns it's
83 static int read_reset_stat(ctl_table *table, int write,
84 void __user *buffer, size_t *lenp,
87 atomic_t *stat = (atomic_t *)table->data;
97 int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat));
100 len = strlen(str_buf);
105 data = &str_buf[*ppos];
109 if (len && copy_to_user(buffer, str_buf, len))
117 static struct ctl_table_header *svcrdma_table_header;
118 static ctl_table svcrdma_parm_table[] = {
120 .procname = "max_requests",
121 .data = &svcrdma_max_requests,
122 .maxlen = sizeof(unsigned int),
124 .proc_handler = proc_dointvec_minmax,
125 .extra1 = &min_max_requests,
126 .extra2 = &max_max_requests
129 .procname = "max_req_size",
130 .data = &svcrdma_max_req_size,
131 .maxlen = sizeof(unsigned int),
133 .proc_handler = proc_dointvec_minmax,
134 .extra1 = &min_max_inline,
135 .extra2 = &max_max_inline
138 .procname = "max_outbound_read_requests",
139 .data = &svcrdma_ord,
140 .maxlen = sizeof(unsigned int),
142 .proc_handler = proc_dointvec_minmax,
148 .procname = "rdma_stat_read",
149 .data = &rdma_stat_read,
150 .maxlen = sizeof(atomic_t),
152 .proc_handler = read_reset_stat,
155 .procname = "rdma_stat_recv",
156 .data = &rdma_stat_recv,
157 .maxlen = sizeof(atomic_t),
159 .proc_handler = read_reset_stat,
162 .procname = "rdma_stat_write",
163 .data = &rdma_stat_write,
164 .maxlen = sizeof(atomic_t),
166 .proc_handler = read_reset_stat,
169 .procname = "rdma_stat_sq_starve",
170 .data = &rdma_stat_sq_starve,
171 .maxlen = sizeof(atomic_t),
173 .proc_handler = read_reset_stat,
176 .procname = "rdma_stat_rq_starve",
177 .data = &rdma_stat_rq_starve,
178 .maxlen = sizeof(atomic_t),
180 .proc_handler = read_reset_stat,
183 .procname = "rdma_stat_rq_poll",
184 .data = &rdma_stat_rq_poll,
185 .maxlen = sizeof(atomic_t),
187 .proc_handler = read_reset_stat,
190 .procname = "rdma_stat_rq_prod",
191 .data = &rdma_stat_rq_prod,
192 .maxlen = sizeof(atomic_t),
194 .proc_handler = read_reset_stat,
197 .procname = "rdma_stat_sq_poll",
198 .data = &rdma_stat_sq_poll,
199 .maxlen = sizeof(atomic_t),
201 .proc_handler = read_reset_stat,
204 .procname = "rdma_stat_sq_prod",
205 .data = &rdma_stat_sq_prod,
206 .maxlen = sizeof(atomic_t),
208 .proc_handler = read_reset_stat,
213 static ctl_table svcrdma_table[] = {
215 .procname = "svc_rdma",
217 .child = svcrdma_parm_table
222 static ctl_table svcrdma_root_table[] = {
224 .procname = "sunrpc",
226 .child = svcrdma_table
231 void svc_rdma_cleanup(void)
233 dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n");
234 flush_scheduled_work();
235 if (svcrdma_table_header) {
236 unregister_sysctl_table(svcrdma_table_header);
237 svcrdma_table_header = NULL;
239 svc_unreg_xprt_class(&svc_rdma_class);
240 kmem_cache_destroy(svc_rdma_map_cachep);
241 kmem_cache_destroy(svc_rdma_ctxt_cachep);
244 int svc_rdma_init(void)
246 dprintk("SVCRDMA Module Init, register RPC RDMA transport\n");
247 dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord);
248 dprintk("\tmax_requests : %d\n", svcrdma_max_requests);
249 dprintk("\tsq_depth : %d\n",
250 svcrdma_max_requests * RPCRDMA_SQ_DEPTH_MULT);
251 dprintk("\tmax_inline : %d\n", svcrdma_max_req_size);
252 if (!svcrdma_table_header)
253 svcrdma_table_header =
254 register_sysctl_table(svcrdma_root_table);
256 /* Create the temporary map cache */
257 svc_rdma_map_cachep = kmem_cache_create("svc_rdma_map_cache",
258 sizeof(struct svc_rdma_req_map),
262 if (!svc_rdma_map_cachep) {
263 printk(KERN_INFO "Could not allocate map cache.\n");
267 /* Create the temporary context cache */
268 svc_rdma_ctxt_cachep =
269 kmem_cache_create("svc_rdma_ctxt_cache",
270 sizeof(struct svc_rdma_op_ctxt),
274 if (!svc_rdma_ctxt_cachep) {
275 printk(KERN_INFO "Could not allocate WR ctxt cache.\n");
279 /* Register RDMA with the SVC transport switch */
280 svc_reg_xprt_class(&svc_rdma_class);
283 kmem_cache_destroy(svc_rdma_map_cachep);
285 unregister_sysctl_table(svcrdma_table_header);
288 MODULE_AUTHOR("Tom Tucker <tom@opengridcomputing.com>");
289 MODULE_DESCRIPTION("SVC RDMA Transport");
290 MODULE_LICENSE("Dual BSD/GPL");
291 module_init(svc_rdma_init);
292 module_exit(svc_rdma_cleanup);