net/smc: Introduce a specific sysctl for TEST_LINK time
[linux-2.6-block.git] / net / smc / smc_sysctl.c
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_llc.h"
20 #include "smc_sysctl.h"
21
22 static struct ctl_table smc_table[] = {
23         {
24                 .procname       = "autocorking_size",
25                 .data           = &init_net.smc.sysctl_autocorking_size,
26                 .maxlen         = sizeof(unsigned int),
27                 .mode           = 0644,
28                 .proc_handler   = proc_douintvec,
29         },
30         {
31                 .procname       = "smcr_buf_type",
32                 .data           = &init_net.smc.sysctl_smcr_buf_type,
33                 .maxlen         = sizeof(unsigned int),
34                 .mode           = 0644,
35                 .proc_handler   = proc_douintvec_minmax,
36                 .extra1         = SYSCTL_ZERO,
37                 .extra2         = SYSCTL_TWO,
38         },
39         {
40                 .procname       = "smcr_testlink_time",
41                 .data           = &init_net.smc.sysctl_smcr_testlink_time,
42                 .maxlen         = sizeof(int),
43                 .mode           = 0644,
44                 .proc_handler   = proc_dointvec_jiffies,
45         },
46         {  }
47 };
48
49 int __net_init smc_sysctl_net_init(struct net *net)
50 {
51         struct ctl_table *table;
52
53         table = smc_table;
54         if (!net_eq(net, &init_net)) {
55                 int i;
56
57                 table = kmemdup(table, sizeof(smc_table), GFP_KERNEL);
58                 if (!table)
59                         goto err_alloc;
60
61                 for (i = 0; i < ARRAY_SIZE(smc_table) - 1; i++)
62                         table[i].data += (void *)net - (void *)&init_net;
63         }
64
65         net->smc.smc_hdr = register_net_sysctl(net, "net/smc", table);
66         if (!net->smc.smc_hdr)
67                 goto err_reg;
68
69         net->smc.sysctl_autocorking_size = SMC_AUTOCORKING_DEFAULT_SIZE;
70         net->smc.sysctl_smcr_buf_type = SMCR_PHYS_CONT_BUFS;
71         net->smc.sysctl_smcr_testlink_time = SMC_LLC_TESTLINK_DEFAULT_TIME;
72
73         return 0;
74
75 err_reg:
76         if (!net_eq(net, &init_net))
77                 kfree(table);
78 err_alloc:
79         return -ENOMEM;
80 }
81
82 void __net_exit smc_sysctl_net_exit(struct net *net)
83 {
84         struct ctl_table *table;
85
86         table = net->smc.smc_hdr->ctl_table_arg;
87         unregister_net_sysctl_table(net->smc.smc_hdr);
88         if (!net_eq(net, &init_net))
89                 kfree(table);
90 }