xref: /openbmc/linux/net/smc/smc_netlink.c (revision 3a35093a)
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_netlink.h"
23 
24 #define SMC_CMD_MAX_ATTR 1
25 
26 /* SMC_GENL generic netlink operation definition */
27 static const struct genl_ops smc_gen_nl_ops[] = {
28 	{
29 		.cmd = SMC_NETLINK_GET_SYS_INFO,
30 		/* can be retrieved by unprivileged users */
31 		.dumpit = smc_nl_get_sys_info,
32 	},
33 	{
34 		.cmd = SMC_NETLINK_GET_LGR_SMCR,
35 		/* can be retrieved by unprivileged users */
36 		.dumpit = smcr_nl_get_lgr,
37 	},
38 	{
39 		.cmd = SMC_NETLINK_GET_LINK_SMCR,
40 		/* can be retrieved by unprivileged users */
41 		.dumpit = smcr_nl_get_link,
42 	},
43 	{
44 		.cmd = SMC_NETLINK_GET_LGR_SMCD,
45 		/* can be retrieved by unprivileged users */
46 		.dumpit = smcd_nl_get_lgr,
47 	},
48 	{
49 		.cmd = SMC_NETLINK_GET_DEV_SMCD,
50 		/* can be retrieved by unprivileged users */
51 		.dumpit = smcd_nl_get_device,
52 	},
53 	{
54 		.cmd = SMC_NETLINK_GET_DEV_SMCR,
55 		/* can be retrieved by unprivileged users */
56 		.dumpit = smcr_nl_get_device,
57 	},
58 };
59 
60 static const struct nla_policy smc_gen_nl_policy[2] = {
61 	[SMC_CMD_MAX_ATTR]	= { .type = NLA_REJECT, },
62 };
63 
64 /* SMC_GENL family definition */
65 struct genl_family smc_gen_nl_family __ro_after_init = {
66 	.hdrsize =	0,
67 	.name =		SMC_GENL_FAMILY_NAME,
68 	.version =	SMC_GENL_FAMILY_VERSION,
69 	.maxattr =	SMC_CMD_MAX_ATTR,
70 	.policy =	smc_gen_nl_policy,
71 	.netnsok =	true,
72 	.module =	THIS_MODULE,
73 	.ops =		smc_gen_nl_ops,
74 	.n_ops =	ARRAY_SIZE(smc_gen_nl_ops)
75 };
76 
77 int __init smc_nl_init(void)
78 {
79 	return genl_register_family(&smc_gen_nl_family);
80 }
81 
82 void smc_nl_exit(void)
83 {
84 	genl_unregister_family(&smc_gen_nl_family);
85 }
86