1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 2015-2018 Oracle. All rights reserved.
4*4882a593Smuzhiyun * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * This software is available to you under a choice of one of two
7*4882a593Smuzhiyun * licenses. You may choose to be licensed under the terms of the GNU
8*4882a593Smuzhiyun * General Public License (GPL) Version 2, available from the file
9*4882a593Smuzhiyun * COPYING in the main directory of this source tree, or the BSD-type
10*4882a593Smuzhiyun * license below:
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
13*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
14*4882a593Smuzhiyun * are met:
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * Redistributions of source code must retain the above copyright
17*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
18*4882a593Smuzhiyun *
19*4882a593Smuzhiyun * Redistributions in binary form must reproduce the above
20*4882a593Smuzhiyun * copyright notice, this list of conditions and the following
21*4882a593Smuzhiyun * disclaimer in the documentation and/or other materials provided
22*4882a593Smuzhiyun * with the distribution.
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * Neither the name of the Network Appliance, Inc. nor the names of
25*4882a593Smuzhiyun * its contributors may be used to endorse or promote products
26*4882a593Smuzhiyun * derived from this software without specific prior written
27*4882a593Smuzhiyun * permission.
28*4882a593Smuzhiyun *
29*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30*4882a593Smuzhiyun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32*4882a593Smuzhiyun * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33*4882a593Smuzhiyun * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34*4882a593Smuzhiyun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35*4882a593Smuzhiyun * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36*4882a593Smuzhiyun * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37*4882a593Smuzhiyun * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39*4882a593Smuzhiyun * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40*4882a593Smuzhiyun *
41*4882a593Smuzhiyun * Author: Tom Tucker <tom@opengridcomputing.com>
42*4882a593Smuzhiyun */
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun #include <linux/slab.h>
45*4882a593Smuzhiyun #include <linux/fs.h>
46*4882a593Smuzhiyun #include <linux/sysctl.h>
47*4882a593Smuzhiyun #include <linux/workqueue.h>
48*4882a593Smuzhiyun #include <linux/sunrpc/clnt.h>
49*4882a593Smuzhiyun #include <linux/sunrpc/sched.h>
50*4882a593Smuzhiyun #include <linux/sunrpc/svc_rdma.h>
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun #define RPCDBG_FACILITY RPCDBG_SVCXPRT
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun /* RPC/RDMA parameters */
55*4882a593Smuzhiyun unsigned int svcrdma_ord = 16; /* historical default */
56*4882a593Smuzhiyun static unsigned int min_ord = 1;
57*4882a593Smuzhiyun static unsigned int max_ord = 255;
58*4882a593Smuzhiyun unsigned int svcrdma_max_requests = RPCRDMA_MAX_REQUESTS;
59*4882a593Smuzhiyun unsigned int svcrdma_max_bc_requests = RPCRDMA_MAX_BC_REQUESTS;
60*4882a593Smuzhiyun static unsigned int min_max_requests = 4;
61*4882a593Smuzhiyun static unsigned int max_max_requests = 16384;
62*4882a593Smuzhiyun unsigned int svcrdma_max_req_size = RPCRDMA_DEF_INLINE_THRESH;
63*4882a593Smuzhiyun static unsigned int min_max_inline = RPCRDMA_DEF_INLINE_THRESH;
64*4882a593Smuzhiyun static unsigned int max_max_inline = RPCRDMA_MAX_INLINE_THRESH;
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun atomic_t rdma_stat_recv;
67*4882a593Smuzhiyun atomic_t rdma_stat_read;
68*4882a593Smuzhiyun atomic_t rdma_stat_write;
69*4882a593Smuzhiyun atomic_t rdma_stat_sq_starve;
70*4882a593Smuzhiyun atomic_t rdma_stat_rq_starve;
71*4882a593Smuzhiyun atomic_t rdma_stat_rq_poll;
72*4882a593Smuzhiyun atomic_t rdma_stat_rq_prod;
73*4882a593Smuzhiyun atomic_t rdma_stat_sq_poll;
74*4882a593Smuzhiyun atomic_t rdma_stat_sq_prod;
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun /*
77*4882a593Smuzhiyun * This function implements reading and resetting an atomic_t stat
78*4882a593Smuzhiyun * variable through read/write to a proc file. Any write to the file
79*4882a593Smuzhiyun * resets the associated statistic to zero. Any read returns it's
80*4882a593Smuzhiyun * current value.
81*4882a593Smuzhiyun */
read_reset_stat(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)82*4882a593Smuzhiyun static int read_reset_stat(struct ctl_table *table, int write,
83*4882a593Smuzhiyun void *buffer, size_t *lenp, loff_t *ppos)
84*4882a593Smuzhiyun {
85*4882a593Smuzhiyun atomic_t *stat = (atomic_t *)table->data;
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun if (!stat)
88*4882a593Smuzhiyun return -EINVAL;
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun if (write)
91*4882a593Smuzhiyun atomic_set(stat, 0);
92*4882a593Smuzhiyun else {
93*4882a593Smuzhiyun char str_buf[32];
94*4882a593Smuzhiyun int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat));
95*4882a593Smuzhiyun if (len >= 32)
96*4882a593Smuzhiyun return -EFAULT;
97*4882a593Smuzhiyun len = strlen(str_buf);
98*4882a593Smuzhiyun if (*ppos > len) {
99*4882a593Smuzhiyun *lenp = 0;
100*4882a593Smuzhiyun return 0;
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun len -= *ppos;
103*4882a593Smuzhiyun if (len > *lenp)
104*4882a593Smuzhiyun len = *lenp;
105*4882a593Smuzhiyun if (len)
106*4882a593Smuzhiyun memcpy(buffer, str_buf, len);
107*4882a593Smuzhiyun *lenp = len;
108*4882a593Smuzhiyun *ppos += len;
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun return 0;
111*4882a593Smuzhiyun }
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun static struct ctl_table_header *svcrdma_table_header;
114*4882a593Smuzhiyun static struct ctl_table svcrdma_parm_table[] = {
115*4882a593Smuzhiyun {
116*4882a593Smuzhiyun .procname = "max_requests",
117*4882a593Smuzhiyun .data = &svcrdma_max_requests,
118*4882a593Smuzhiyun .maxlen = sizeof(unsigned int),
119*4882a593Smuzhiyun .mode = 0644,
120*4882a593Smuzhiyun .proc_handler = proc_dointvec_minmax,
121*4882a593Smuzhiyun .extra1 = &min_max_requests,
122*4882a593Smuzhiyun .extra2 = &max_max_requests
123*4882a593Smuzhiyun },
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun .procname = "max_req_size",
126*4882a593Smuzhiyun .data = &svcrdma_max_req_size,
127*4882a593Smuzhiyun .maxlen = sizeof(unsigned int),
128*4882a593Smuzhiyun .mode = 0644,
129*4882a593Smuzhiyun .proc_handler = proc_dointvec_minmax,
130*4882a593Smuzhiyun .extra1 = &min_max_inline,
131*4882a593Smuzhiyun .extra2 = &max_max_inline
132*4882a593Smuzhiyun },
133*4882a593Smuzhiyun {
134*4882a593Smuzhiyun .procname = "max_outbound_read_requests",
135*4882a593Smuzhiyun .data = &svcrdma_ord,
136*4882a593Smuzhiyun .maxlen = sizeof(unsigned int),
137*4882a593Smuzhiyun .mode = 0644,
138*4882a593Smuzhiyun .proc_handler = proc_dointvec_minmax,
139*4882a593Smuzhiyun .extra1 = &min_ord,
140*4882a593Smuzhiyun .extra2 = &max_ord,
141*4882a593Smuzhiyun },
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun .procname = "rdma_stat_read",
145*4882a593Smuzhiyun .data = &rdma_stat_read,
146*4882a593Smuzhiyun .maxlen = sizeof(atomic_t),
147*4882a593Smuzhiyun .mode = 0644,
148*4882a593Smuzhiyun .proc_handler = read_reset_stat,
149*4882a593Smuzhiyun },
150*4882a593Smuzhiyun {
151*4882a593Smuzhiyun .procname = "rdma_stat_recv",
152*4882a593Smuzhiyun .data = &rdma_stat_recv,
153*4882a593Smuzhiyun .maxlen = sizeof(atomic_t),
154*4882a593Smuzhiyun .mode = 0644,
155*4882a593Smuzhiyun .proc_handler = read_reset_stat,
156*4882a593Smuzhiyun },
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun .procname = "rdma_stat_write",
159*4882a593Smuzhiyun .data = &rdma_stat_write,
160*4882a593Smuzhiyun .maxlen = sizeof(atomic_t),
161*4882a593Smuzhiyun .mode = 0644,
162*4882a593Smuzhiyun .proc_handler = read_reset_stat,
163*4882a593Smuzhiyun },
164*4882a593Smuzhiyun {
165*4882a593Smuzhiyun .procname = "rdma_stat_sq_starve",
166*4882a593Smuzhiyun .data = &rdma_stat_sq_starve,
167*4882a593Smuzhiyun .maxlen = sizeof(atomic_t),
168*4882a593Smuzhiyun .mode = 0644,
169*4882a593Smuzhiyun .proc_handler = read_reset_stat,
170*4882a593Smuzhiyun },
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun .procname = "rdma_stat_rq_starve",
173*4882a593Smuzhiyun .data = &rdma_stat_rq_starve,
174*4882a593Smuzhiyun .maxlen = sizeof(atomic_t),
175*4882a593Smuzhiyun .mode = 0644,
176*4882a593Smuzhiyun .proc_handler = read_reset_stat,
177*4882a593Smuzhiyun },
178*4882a593Smuzhiyun {
179*4882a593Smuzhiyun .procname = "rdma_stat_rq_poll",
180*4882a593Smuzhiyun .data = &rdma_stat_rq_poll,
181*4882a593Smuzhiyun .maxlen = sizeof(atomic_t),
182*4882a593Smuzhiyun .mode = 0644,
183*4882a593Smuzhiyun .proc_handler = read_reset_stat,
184*4882a593Smuzhiyun },
185*4882a593Smuzhiyun {
186*4882a593Smuzhiyun .procname = "rdma_stat_rq_prod",
187*4882a593Smuzhiyun .data = &rdma_stat_rq_prod,
188*4882a593Smuzhiyun .maxlen = sizeof(atomic_t),
189*4882a593Smuzhiyun .mode = 0644,
190*4882a593Smuzhiyun .proc_handler = read_reset_stat,
191*4882a593Smuzhiyun },
192*4882a593Smuzhiyun {
193*4882a593Smuzhiyun .procname = "rdma_stat_sq_poll",
194*4882a593Smuzhiyun .data = &rdma_stat_sq_poll,
195*4882a593Smuzhiyun .maxlen = sizeof(atomic_t),
196*4882a593Smuzhiyun .mode = 0644,
197*4882a593Smuzhiyun .proc_handler = read_reset_stat,
198*4882a593Smuzhiyun },
199*4882a593Smuzhiyun {
200*4882a593Smuzhiyun .procname = "rdma_stat_sq_prod",
201*4882a593Smuzhiyun .data = &rdma_stat_sq_prod,
202*4882a593Smuzhiyun .maxlen = sizeof(atomic_t),
203*4882a593Smuzhiyun .mode = 0644,
204*4882a593Smuzhiyun .proc_handler = read_reset_stat,
205*4882a593Smuzhiyun },
206*4882a593Smuzhiyun { },
207*4882a593Smuzhiyun };
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun static struct ctl_table svcrdma_table[] = {
210*4882a593Smuzhiyun {
211*4882a593Smuzhiyun .procname = "svc_rdma",
212*4882a593Smuzhiyun .mode = 0555,
213*4882a593Smuzhiyun .child = svcrdma_parm_table
214*4882a593Smuzhiyun },
215*4882a593Smuzhiyun { },
216*4882a593Smuzhiyun };
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun static struct ctl_table svcrdma_root_table[] = {
219*4882a593Smuzhiyun {
220*4882a593Smuzhiyun .procname = "sunrpc",
221*4882a593Smuzhiyun .mode = 0555,
222*4882a593Smuzhiyun .child = svcrdma_table
223*4882a593Smuzhiyun },
224*4882a593Smuzhiyun { },
225*4882a593Smuzhiyun };
226*4882a593Smuzhiyun
svc_rdma_cleanup(void)227*4882a593Smuzhiyun void svc_rdma_cleanup(void)
228*4882a593Smuzhiyun {
229*4882a593Smuzhiyun dprintk("SVCRDMA Module Removed, deregister RPC RDMA transport\n");
230*4882a593Smuzhiyun if (svcrdma_table_header) {
231*4882a593Smuzhiyun unregister_sysctl_table(svcrdma_table_header);
232*4882a593Smuzhiyun svcrdma_table_header = NULL;
233*4882a593Smuzhiyun }
234*4882a593Smuzhiyun svc_unreg_xprt_class(&svc_rdma_class);
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun
svc_rdma_init(void)237*4882a593Smuzhiyun int svc_rdma_init(void)
238*4882a593Smuzhiyun {
239*4882a593Smuzhiyun dprintk("SVCRDMA Module Init, register RPC RDMA transport\n");
240*4882a593Smuzhiyun dprintk("\tsvcrdma_ord : %d\n", svcrdma_ord);
241*4882a593Smuzhiyun dprintk("\tmax_requests : %u\n", svcrdma_max_requests);
242*4882a593Smuzhiyun dprintk("\tmax_bc_requests : %u\n", svcrdma_max_bc_requests);
243*4882a593Smuzhiyun dprintk("\tmax_inline : %d\n", svcrdma_max_req_size);
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun if (!svcrdma_table_header)
246*4882a593Smuzhiyun svcrdma_table_header =
247*4882a593Smuzhiyun register_sysctl_table(svcrdma_root_table);
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun /* Register RDMA with the SVC transport switch */
250*4882a593Smuzhiyun svc_reg_xprt_class(&svc_rdma_class);
251*4882a593Smuzhiyun return 0;
252*4882a593Smuzhiyun }
253