xref: /openbmc/linux/net/smc/smc_sysctl.c (revision 679b4bc2)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *  Shared Memory Communications over RDMA (SMC-R) and RoCE
4  *
5  *  smc_sysctl.c: sysctl interface to SMC subsystem.
6  *
7  *  Copyright (c) 2022, Alibaba Inc.
8  *
9  *  Author: Tony Lu <tonylu@linux.alibaba.com>
10  *
11  */
12 
13 #include <linux/init.h>
14 #include <linux/sysctl.h>
15 #include <net/net_namespace.h>
16 
17 #include "smc.h"
18 #include "smc_core.h"
19 #include "smc_sysctl.h"
20 
21 static struct ctl_table smc_table[] = {
22 	{
23 		.procname       = "autocorking_size",
24 		.data           = &init_net.smc.sysctl_autocorking_size,
25 		.maxlen         = sizeof(unsigned int),
26 		.mode           = 0644,
27 		.proc_handler	= proc_douintvec,
28 	},
29 	{
30 		.procname	= "smcr_buf_type",
31 		.data		= &init_net.smc.sysctl_smcr_buf_type,
32 		.maxlen		= sizeof(unsigned int),
33 		.mode		= 0644,
34 		.proc_handler	= proc_douintvec_minmax,
35 		.extra1		= SYSCTL_ZERO,
36 		.extra2		= SYSCTL_TWO,
37 	},
38 	{  }
39 };
40 
41 int __net_init smc_sysctl_net_init(struct net *net)
42 {
43 	struct ctl_table *table;
44 
45 	table = smc_table;
46 	if (!net_eq(net, &init_net)) {
47 		int i;
48 
49 		table = kmemdup(table, sizeof(smc_table), GFP_KERNEL);
50 		if (!table)
51 			goto err_alloc;
52 
53 		for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++)
54 			table[i].data += (void *)net - (void *)&init_net;
55 	}
56 
57 	net->smc.smc_hdr = register_net_sysctl(net, "net/smc", table);
58 	if (!net->smc.smc_hdr)
59 		goto err_reg;
60 
61 	net->smc.sysctl_autocorking_size = SMC_AUTOCORKING_DEFAULT_SIZE;
62 	net->smc.sysctl_smcr_buf_type = SMCR_PHYS_CONT_BUFS;
63 
64 	return 0;
65 
66 err_reg:
67 	if (!net_eq(net, &init_net))
68 		kfree(table);
69 err_alloc:
70 	return -ENOMEM;
71 }
72 
73 void __net_exit smc_sysctl_net_exit(struct net *net)
74 {
75 	struct ctl_table *table;
76 
77 	table = net->smc.smc_hdr->ctl_table_arg;
78 	unregister_net_sysctl_table(net->smc.smc_hdr);
79 	if (!net_eq(net, &init_net))
80 		kfree(table);
81 }
82