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.
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;
25 static struct ctl_table smc_table[] = {
27 .procname = "autocorking_size",
28 .data = &init_net.smc.sysctl_autocorking_size,
29 .maxlen = sizeof(unsigned int),
31 .proc_handler = proc_douintvec,
34 .procname = "smcr_buf_type",
35 .data = &init_net.smc.sysctl_smcr_buf_type,
36 .maxlen = sizeof(unsigned int),
38 .proc_handler = proc_douintvec_minmax,
39 .extra1 = SYSCTL_ZERO,
43 .procname = "smcr_testlink_time",
44 .data = &init_net.smc.sysctl_smcr_testlink_time,
45 .maxlen = sizeof(int),
47 .proc_handler = proc_dointvec_jiffies,
51 .data = &init_net.smc.sysctl_wmem,
52 .maxlen = sizeof(int),
54 .proc_handler = proc_dointvec_minmax,
55 .extra1 = &min_sndbuf,
59 .data = &init_net.smc.sysctl_rmem,
60 .maxlen = sizeof(int),
62 .proc_handler = proc_dointvec_minmax,
63 .extra1 = &min_rcvbuf,
68 int __net_init smc_sysctl_net_init(struct net *net)
70 struct ctl_table *table;
73 if (!net_eq(net, &init_net)) {
76 table = kmemdup(table, sizeof(smc_table), GFP_KERNEL);
80 for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++)
81 table[i].data += (void *)net - (void *)&init_net;
84 net->smc.smc_hdr = register_net_sysctl(net, "net/smc", table);
85 if (!net->smc.smc_hdr)
88 net->smc.sysctl_autocorking_size = SMC_AUTOCORKING_DEFAULT_SIZE;
89 net->smc.sysctl_smcr_buf_type = SMCR_PHYS_CONT_BUFS;
90 net->smc.sysctl_smcr_testlink_time = SMC_LLC_TESTLINK_DEFAULT_TIME;
91 WRITE_ONCE(net->smc.sysctl_wmem, READ_ONCE(net->ipv4.sysctl_tcp_wmem[1]));
92 WRITE_ONCE(net->smc.sysctl_rmem, READ_ONCE(net->ipv4.sysctl_tcp_rmem[1]));
97 if (!net_eq(net, &init_net))
103 void __net_exit smc_sysctl_net_exit(struct net *net)
105 struct ctl_table *table;
107 table = net->smc.smc_hdr->ctl_table_arg;
108 unregister_net_sysctl_table(net->smc.smc_hdr);
109 if (!net_eq(net, &init_net))