1 // SPDX-License-Identifier: GPL-2.0
3 * Shared Memory Communications over RDMA (SMC-R) and RoCE
5 * Generic netlink support functions to interact with SMC module
7 * Copyright IBM Corp. 2020
9 * Author(s): Guvenc Gulce <guvenc@linux.ibm.com>
12 #include <linux/module.h>
13 #include <linux/list.h>
14 #include <linux/ctype.h>
15 #include <linux/mutex.h>
17 #include <linux/smc.h>
23 #include "smc_stats.h"
24 #include "smc_netlink.h"
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,
34 #define SMC_CMD_MAX_ATTR 1
35 /* SMC_GENL generic netlink operation definition */
36 static const struct genl_ops smc_gen_nl_ops[] = {
38 .cmd = SMC_NETLINK_GET_SYS_INFO,
39 /* can be retrieved by unprivileged users */
40 .dumpit = smc_nl_get_sys_info,
43 .cmd = SMC_NETLINK_GET_LGR_SMCR,
44 /* can be retrieved by unprivileged users */
45 .dumpit = smcr_nl_get_lgr,
48 .cmd = SMC_NETLINK_GET_LINK_SMCR,
49 /* can be retrieved by unprivileged users */
50 .dumpit = smcr_nl_get_link,
53 .cmd = SMC_NETLINK_GET_LGR_SMCD,
54 /* can be retrieved by unprivileged users */
55 .dumpit = smcd_nl_get_lgr,
58 .cmd = SMC_NETLINK_GET_DEV_SMCD,
59 /* can be retrieved by unprivileged users */
60 .dumpit = smcd_nl_get_device,
63 .cmd = SMC_NETLINK_GET_DEV_SMCR,
64 /* can be retrieved by unprivileged users */
65 .dumpit = smcr_nl_get_device,
68 .cmd = SMC_NETLINK_GET_STATS,
69 /* can be retrieved by unprivileged users */
70 .dumpit = smc_nl_get_stats,
73 .cmd = SMC_NETLINK_GET_FBACK_STATS,
74 /* can be retrieved by unprivileged users */
75 .dumpit = smc_nl_get_fback_stats,
78 .cmd = SMC_NETLINK_DUMP_UEID,
79 /* can be retrieved by unprivileged users */
80 .dumpit = smc_nl_dump_ueid,
83 .cmd = SMC_NETLINK_ADD_UEID,
84 .flags = GENL_ADMIN_PERM,
85 .doit = smc_nl_add_ueid,
86 .policy = smc_gen_ueid_policy,
89 .cmd = SMC_NETLINK_REMOVE_UEID,
90 .flags = GENL_ADMIN_PERM,
91 .doit = smc_nl_remove_ueid,
92 .policy = smc_gen_ueid_policy,
95 .cmd = SMC_NETLINK_FLUSH_UEID,
96 .flags = GENL_ADMIN_PERM,
97 .doit = smc_nl_flush_ueid,
100 .cmd = SMC_NETLINK_DUMP_SEID,
101 /* can be retrieved by unprivileged users */
102 .dumpit = smc_nl_dump_seid,
105 .cmd = SMC_NETLINK_ENABLE_SEID,
106 .flags = GENL_ADMIN_PERM,
107 .doit = smc_nl_enable_seid,
110 .cmd = SMC_NETLINK_DISABLE_SEID,
111 .flags = GENL_ADMIN_PERM,
112 .doit = smc_nl_disable_seid,
115 .cmd = SMC_NETLINK_DUMP_HS_LIMITATION,
116 /* can be retrieved by unprivileged users */
117 .dumpit = smc_nl_dump_hs_limitation,
120 .cmd = SMC_NETLINK_ENABLE_HS_LIMITATION,
121 .flags = GENL_ADMIN_PERM,
122 .doit = smc_nl_enable_hs_limitation,
125 .cmd = SMC_NETLINK_DISABLE_HS_LIMITATION,
126 .flags = GENL_ADMIN_PERM,
127 .doit = smc_nl_disable_hs_limitation,
131 static const struct nla_policy smc_gen_nl_policy[2] = {
132 [SMC_CMD_MAX_ATTR] = { .type = NLA_REJECT, },
135 /* SMC_GENL family definition */
136 struct genl_family smc_gen_nl_family __ro_after_init = {
138 .name = SMC_GENL_FAMILY_NAME,
139 .version = SMC_GENL_FAMILY_VERSION,
140 .maxattr = SMC_CMD_MAX_ATTR,
141 .policy = smc_gen_nl_policy,
143 .module = THIS_MODULE,
144 .ops = smc_gen_nl_ops,
145 .n_ops = ARRAY_SIZE(smc_gen_nl_ops),
146 .resv_start_op = SMC_NETLINK_DISABLE_HS_LIMITATION + 1,
149 int __init smc_nl_init(void)
151 return genl_register_family(&smc_gen_nl_family);
154 void smc_nl_exit(void)
156 genl_unregister_family(&smc_gen_nl_family);