xref: /linux/net/smc/smc_netlink.c (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *  Shared Memory Communications over RDMA (SMC-R) and RoCE
4  *
5  *  Generic netlink support functions to interact with SMC module
6  *
7  *  Copyright IBM Corp. 2020
8  *
9  *  Author(s):	Guvenc Gulce <guvenc@linux.ibm.com>
10  */
11 
12 #include <linux/module.h>
13 #include <linux/list.h>
14 #include <linux/ctype.h>
15 #include <linux/mutex.h>
16 #include <linux/if.h>
17 #include <linux/smc.h>
18 
19 #include "smc_core.h"
20 #include "smc_ism.h"
21 #include "smc_ib.h"
22 #include "smc_clc.h"
23 #include "smc_stats.h"
24 #include "smc_netlink.h"
25 
26 const struct nla_policy
27 smc_gen_ueid_policy[SMC_NLA_EID_TABLE_MAX + 1] = {
28 	[SMC_NLA_EID_TABLE_UNSPEC]	= { .type = NLA_UNSPEC },
29 	[SMC_NLA_EID_TABLE_ENTRY]	= { .type = NLA_STRING,
30 					    .len = SMC_MAX_EID_LEN,
31 					  },
32 };
33 
34 #define SMC_CMD_MAX_ATTR 1
35 /* SMC_GENL generic netlink operation definition */
36 static const struct genl_ops smc_gen_nl_ops[] = {
37 	{
38 		.cmd = SMC_NETLINK_GET_SYS_INFO,
39 		/* can be retrieved by unprivileged users */
40 		.dumpit = smc_nl_get_sys_info,
41 	},
42 	{
43 		.cmd = SMC_NETLINK_GET_LGR_SMCR,
44 		/* can be retrieved by unprivileged users */
45 		.dumpit = smcr_nl_get_lgr,
46 	},
47 	{
48 		.cmd = SMC_NETLINK_GET_LINK_SMCR,
49 		/* can be retrieved by unprivileged users */
50 		.dumpit = smcr_nl_get_link,
51 	},
52 	{
53 		.cmd = SMC_NETLINK_GET_LGR_SMCD,
54 		/* can be retrieved by unprivileged users */
55 		.dumpit = smcd_nl_get_lgr,
56 	},
57 	{
58 		.cmd = SMC_NETLINK_GET_DEV_SMCD,
59 		/* can be retrieved by unprivileged users */
60 		.dumpit = smcd_nl_get_device,
61 	},
62 	{
63 		.cmd = SMC_NETLINK_GET_DEV_SMCR,
64 		/* can be retrieved by unprivileged users */
65 		.dumpit = smcr_nl_get_device,
66 	},
67 	{
68 		.cmd = SMC_NETLINK_GET_STATS,
69 		/* can be retrieved by unprivileged users */
70 		.dumpit = smc_nl_get_stats,
71 	},
72 	{
73 		.cmd = SMC_NETLINK_GET_FBACK_STATS,
74 		/* can be retrieved by unprivileged users */
75 		.dumpit = smc_nl_get_fback_stats,
76 	},
77 	{
78 		.cmd = SMC_NETLINK_DUMP_UEID,
79 		/* can be retrieved by unprivileged users */
80 		.dumpit = smc_nl_dump_ueid,
81 	},
82 	{
83 		.cmd = SMC_NETLINK_ADD_UEID,
84 		.flags = GENL_ADMIN_PERM,
85 		.doit = smc_nl_add_ueid,
86 		.policy = smc_gen_ueid_policy,
87 	},
88 	{
89 		.cmd = SMC_NETLINK_REMOVE_UEID,
90 		.flags = GENL_ADMIN_PERM,
91 		.doit = smc_nl_remove_ueid,
92 		.policy = smc_gen_ueid_policy,
93 	},
94 	{
95 		.cmd = SMC_NETLINK_FLUSH_UEID,
96 		.flags = GENL_ADMIN_PERM,
97 		.doit = smc_nl_flush_ueid,
98 	},
99 	{
100 		.cmd = SMC_NETLINK_DUMP_SEID,
101 		/* can be retrieved by unprivileged users */
102 		.dumpit = smc_nl_dump_seid,
103 	},
104 	{
105 		.cmd = SMC_NETLINK_ENABLE_SEID,
106 		.flags = GENL_ADMIN_PERM,
107 		.doit = smc_nl_enable_seid,
108 	},
109 	{
110 		.cmd = SMC_NETLINK_DISABLE_SEID,
111 		.flags = GENL_ADMIN_PERM,
112 		.doit = smc_nl_disable_seid,
113 	},
114 	{
115 		.cmd = SMC_NETLINK_DUMP_HS_LIMITATION,
116 		/* can be retrieved by unprivileged users */
117 		.dumpit = smc_nl_dump_hs_limitation,
118 	},
119 	{
120 		.cmd = SMC_NETLINK_ENABLE_HS_LIMITATION,
121 		.flags = GENL_ADMIN_PERM,
122 		.doit = smc_nl_enable_hs_limitation,
123 	},
124 	{
125 		.cmd = SMC_NETLINK_DISABLE_HS_LIMITATION,
126 		.flags = GENL_ADMIN_PERM,
127 		.doit = smc_nl_disable_hs_limitation,
128 	},
129 };
130 
131 static const struct nla_policy smc_gen_nl_policy[2] = {
132 	[SMC_CMD_MAX_ATTR]	= { .type = NLA_REJECT, },
133 };
134 
135 /* SMC_GENL family definition */
136 struct genl_family smc_gen_nl_family __ro_after_init = {
137 	.hdrsize =	0,
138 	.name =		SMC_GENL_FAMILY_NAME,
139 	.version =	SMC_GENL_FAMILY_VERSION,
140 	.maxattr =	SMC_CMD_MAX_ATTR,
141 	.policy =	smc_gen_nl_policy,
142 	.netnsok =	true,
143 	.module =	THIS_MODULE,
144 	.ops =		smc_gen_nl_ops,
145 	.n_ops =	ARRAY_SIZE(smc_gen_nl_ops)
146 };
147 
148 int __init smc_nl_init(void)
149 {
150 	return genl_register_family(&smc_gen_nl_family);
151 }
152 
153 void smc_nl_exit(void)
154 {
155 	genl_unregister_family(&smc_gen_nl_family);
156 }
157