1 // SPDX-License-Identifier: GPL-2.0
3 * Shared Memory Communications over RDMA (SMC-R) and RoCE
5 * smc_sysctl.c: sysctl interface to SMC subsystem.
7 * Copyright (c) 2022, Alibaba Inc.
9 * Author: Tony Lu <tonylu@linux.alibaba.com>
13 #include <linux/init.h>
14 #include <linux/sysctl.h>
15 #include <net/net_namespace.h>
20 #include "smc_sysctl.h"
22 static int min_sndbuf = SMC_BUF_MIN_SIZE;
23 static int min_rcvbuf = SMC_BUF_MIN_SIZE;
24 static int max_sndbuf = INT_MAX / 2;
25 static int max_rcvbuf = INT_MAX / 2;
26 static const int net_smc_wmem_init = (64 * 1024);
27 static const int net_smc_rmem_init = (64 * 1024);
29 static struct ctl_table smc_table[] = {
31 .procname = "autocorking_size",
32 .data = &init_net.smc.sysctl_autocorking_size,
33 .maxlen = sizeof(unsigned int),
35 .proc_handler = proc_douintvec,
38 .procname = "smcr_buf_type",
39 .data = &init_net.smc.sysctl_smcr_buf_type,
40 .maxlen = sizeof(unsigned int),
42 .proc_handler = proc_douintvec_minmax,
43 .extra1 = SYSCTL_ZERO,
47 .procname = "smcr_testlink_time",
48 .data = &init_net.smc.sysctl_smcr_testlink_time,
49 .maxlen = sizeof(int),
51 .proc_handler = proc_dointvec_jiffies,
55 .data = &init_net.smc.sysctl_wmem,
56 .maxlen = sizeof(int),
58 .proc_handler = proc_dointvec_minmax,
59 .extra1 = &min_sndbuf,
60 .extra2 = &max_sndbuf,
64 .data = &init_net.smc.sysctl_rmem,
65 .maxlen = sizeof(int),
67 .proc_handler = proc_dointvec_minmax,
68 .extra1 = &min_rcvbuf,
69 .extra2 = &max_rcvbuf,
74 int __net_init smc_sysctl_net_init(struct net *net)
76 struct ctl_table *table;
79 if (!net_eq(net, &init_net)) {
82 table = kmemdup(table, sizeof(smc_table), GFP_KERNEL);
86 for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++)
87 table[i].data += (void *)net - (void *)&init_net;
90 net->smc.smc_hdr = register_net_sysctl(net, "net/smc", table);
91 if (!net->smc.smc_hdr)
94 net->smc.sysctl_autocorking_size = SMC_AUTOCORKING_DEFAULT_SIZE;
95 net->smc.sysctl_smcr_buf_type = SMCR_PHYS_CONT_BUFS;
96 net->smc.sysctl_smcr_testlink_time = SMC_LLC_TESTLINK_DEFAULT_TIME;
97 WRITE_ONCE(net->smc.sysctl_wmem, net_smc_wmem_init);
98 WRITE_ONCE(net->smc.sysctl_rmem, net_smc_rmem_init);
103 if (!net_eq(net, &init_net))
109 void __net_exit smc_sysctl_net_exit(struct net *net)
111 struct ctl_table *table;
113 table = net->smc.smc_hdr->ctl_table_arg;
114 unregister_net_sysctl_table(net->smc.smc_hdr);
115 if (!net_eq(net, &init_net))