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