1462791bbSDust Li // SPDX-License-Identifier: GPL-2.0
2462791bbSDust Li /*
3462791bbSDust Li * Shared Memory Communications over RDMA (SMC-R) and RoCE
4462791bbSDust Li *
5462791bbSDust Li * smc_sysctl.c: sysctl interface to SMC subsystem.
6462791bbSDust Li *
7462791bbSDust Li * Copyright (c) 2022, Alibaba Inc.
8462791bbSDust Li *
9462791bbSDust Li * Author: Tony Lu <tonylu@linux.alibaba.com>
10462791bbSDust Li *
11462791bbSDust Li */
12462791bbSDust Li
13462791bbSDust Li #include <linux/init.h>
14462791bbSDust Li #include <linux/sysctl.h>
15462791bbSDust Li #include <net/net_namespace.h>
16462791bbSDust Li
1712bbb0d1SDust Li #include "smc.h"
184bc5008eSWen Gu #include "smc_core.h"
1977eee325SWen Gu #include "smc_llc.h"
20462791bbSDust Li #include "smc_sysctl.h"
21462791bbSDust Li
220227f058STony Lu static int min_sndbuf = SMC_BUF_MIN_SIZE;
230227f058STony Lu static int min_rcvbuf = SMC_BUF_MIN_SIZE;
24833bac7eSGerd Bayer static int max_sndbuf = INT_MAX / 2;
25833bac7eSGerd Bayer static int max_rcvbuf = INT_MAX / 2;
26833bac7eSGerd Bayer static const int net_smc_wmem_init = (64 * 1024);
27833bac7eSGerd Bayer static const int net_smc_rmem_init = (64 * 1024);
280227f058STony Lu
29462791bbSDust Li static struct ctl_table smc_table[] = {
3012bbb0d1SDust Li {
3112bbb0d1SDust Li .procname = "autocorking_size",
3212bbb0d1SDust Li .data = &init_net.smc.sysctl_autocorking_size,
3312bbb0d1SDust Li .maxlen = sizeof(unsigned int),
3412bbb0d1SDust Li .mode = 0644,
3512bbb0d1SDust Li .proc_handler = proc_douintvec,
3612bbb0d1SDust Li },
374bc5008eSWen Gu {
384bc5008eSWen Gu .procname = "smcr_buf_type",
394bc5008eSWen Gu .data = &init_net.smc.sysctl_smcr_buf_type,
404bc5008eSWen Gu .maxlen = sizeof(unsigned int),
414bc5008eSWen Gu .mode = 0644,
424bc5008eSWen Gu .proc_handler = proc_douintvec_minmax,
434bc5008eSWen Gu .extra1 = SYSCTL_ZERO,
444bc5008eSWen Gu .extra2 = SYSCTL_TWO,
454bc5008eSWen Gu },
4677eee325SWen Gu {
4777eee325SWen Gu .procname = "smcr_testlink_time",
4877eee325SWen Gu .data = &init_net.smc.sysctl_smcr_testlink_time,
4977eee325SWen Gu .maxlen = sizeof(int),
5077eee325SWen Gu .mode = 0644,
5177eee325SWen Gu .proc_handler = proc_dointvec_jiffies,
5277eee325SWen Gu },
530227f058STony Lu {
540227f058STony Lu .procname = "wmem",
550227f058STony Lu .data = &init_net.smc.sysctl_wmem,
560227f058STony Lu .maxlen = sizeof(int),
570227f058STony Lu .mode = 0644,
580227f058STony Lu .proc_handler = proc_dointvec_minmax,
590227f058STony Lu .extra1 = &min_sndbuf,
60833bac7eSGerd Bayer .extra2 = &max_sndbuf,
610227f058STony Lu },
620227f058STony Lu {
630227f058STony Lu .procname = "rmem",
640227f058STony Lu .data = &init_net.smc.sysctl_rmem,
650227f058STony Lu .maxlen = sizeof(int),
660227f058STony Lu .mode = 0644,
670227f058STony Lu .proc_handler = proc_dointvec_minmax,
680227f058STony Lu .extra1 = &min_rcvbuf,
69833bac7eSGerd Bayer .extra2 = &max_rcvbuf,
700227f058STony Lu },
71462791bbSDust Li { }
72462791bbSDust Li };
73462791bbSDust Li
smc_sysctl_net_init(struct net * net)747de8eb0dSDust Li int __net_init smc_sysctl_net_init(struct net *net)
75462791bbSDust Li {
76462791bbSDust Li struct ctl_table *table;
77462791bbSDust Li
78462791bbSDust Li table = smc_table;
79462791bbSDust Li if (!net_eq(net, &init_net)) {
80462791bbSDust Li int i;
81462791bbSDust Li
82462791bbSDust Li table = kmemdup(table, sizeof(smc_table), GFP_KERNEL);
83462791bbSDust Li if (!table)
84462791bbSDust Li goto err_alloc;
85462791bbSDust Li
86462791bbSDust Li for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++)
87462791bbSDust Li table[i].data += (void *)net - (void *)&init_net;
88462791bbSDust Li }
89462791bbSDust Li
90*c899710fSJoel Granados net->smc.smc_hdr = register_net_sysctl_sz(net, "net/smc", table,
91*c899710fSJoel Granados ARRAY_SIZE(smc_table));
92462791bbSDust Li if (!net->smc.smc_hdr)
93462791bbSDust Li goto err_reg;
94462791bbSDust Li
9512bbb0d1SDust Li net->smc.sysctl_autocorking_size = SMC_AUTOCORKING_DEFAULT_SIZE;
964bc5008eSWen Gu net->smc.sysctl_smcr_buf_type = SMCR_PHYS_CONT_BUFS;
9777eee325SWen Gu net->smc.sysctl_smcr_testlink_time = SMC_LLC_TESTLINK_DEFAULT_TIME;
98833bac7eSGerd Bayer WRITE_ONCE(net->smc.sysctl_wmem, net_smc_wmem_init);
99833bac7eSGerd Bayer WRITE_ONCE(net->smc.sysctl_rmem, net_smc_rmem_init);
10012bbb0d1SDust Li
101462791bbSDust Li return 0;
102462791bbSDust Li
103462791bbSDust Li err_reg:
104462791bbSDust Li if (!net_eq(net, &init_net))
105462791bbSDust Li kfree(table);
106462791bbSDust Li err_alloc:
107462791bbSDust Li return -ENOMEM;
108462791bbSDust Li }
109462791bbSDust Li
smc_sysctl_net_exit(struct net * net)1107de8eb0dSDust Li void __net_exit smc_sysctl_net_exit(struct net *net)
111462791bbSDust Li {
1125ae6acf1SEric Dumazet struct ctl_table *table;
1135ae6acf1SEric Dumazet
1145ae6acf1SEric Dumazet table = net->smc.smc_hdr->ctl_table_arg;
115462791bbSDust Li unregister_net_sysctl_table(net->smc.smc_hdr);
1165ae6acf1SEric Dumazet if (!net_eq(net, &init_net))
1175ae6acf1SEric Dumazet kfree(table);
118462791bbSDust Li }
119