blob: f13ab0661ed5ee615e5f3dca2b87e7a5edcd11f4 [file] [log] [blame]
Guvenc Gulcee8372d92020-12-01 20:20:43 +01001// 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"
Guvenc Gulceaaf95522020-12-01 20:20:48 +010020#include "smc_ism.h"
Guvenc Gulcea3db10e2020-12-01 20:20:49 +010021#include "smc_ib.h"
Karsten Graulfa086662021-09-14 10:35:05 +020022#include "smc_clc.h"
Guvenc Gulce8c406022021-06-16 16:52:56 +020023#include "smc_stats.h"
Guvenc Gulcee8372d92020-12-01 20:20:43 +010024#include "smc_netlink.h"
25
Karsten Graulfa086662021-09-14 10:35:05 +020026const struct nla_policy
27smc_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};
Guvenc Gulcee8372d92020-12-01 20:20:43 +010033
Karsten Graulfa086662021-09-14 10:35:05 +020034#define SMC_CMD_MAX_ATTR 1
Guvenc Gulcee8372d92020-12-01 20:20:43 +010035/* SMC_GENL generic netlink operation definition */
36static const struct genl_ops smc_gen_nl_ops[] = {
Guvenc Gulce099b9902020-12-01 20:20:44 +010037 {
38 .cmd = SMC_NETLINK_GET_SYS_INFO,
39 /* can be retrieved by unprivileged users */
40 .dumpit = smc_nl_get_sys_info,
41 },
Guvenc Gulcee9b8c842020-12-01 20:20:45 +010042 {
43 .cmd = SMC_NETLINK_GET_LGR_SMCR,
44 /* can be retrieved by unprivileged users */
45 .dumpit = smcr_nl_get_lgr,
46 },
Guvenc Gulce5a7e09d2020-12-01 20:20:46 +010047 {
48 .cmd = SMC_NETLINK_GET_LINK_SMCR,
49 /* can be retrieved by unprivileged users */
50 .dumpit = smcr_nl_get_link,
51 },
Guvenc Gulce8f9dde42020-12-01 20:20:47 +010052 {
53 .cmd = SMC_NETLINK_GET_LGR_SMCD,
54 /* can be retrieved by unprivileged users */
55 .dumpit = smcd_nl_get_lgr,
56 },
Guvenc Gulceaaf95522020-12-01 20:20:48 +010057 {
58 .cmd = SMC_NETLINK_GET_DEV_SMCD,
59 /* can be retrieved by unprivileged users */
60 .dumpit = smcd_nl_get_device,
61 },
Guvenc Gulcea3db10e2020-12-01 20:20:49 +010062 {
63 .cmd = SMC_NETLINK_GET_DEV_SMCR,
64 /* can be retrieved by unprivileged users */
65 .dumpit = smcr_nl_get_device,
66 },
Guvenc Gulce8c406022021-06-16 16:52:56 +020067 {
68 .cmd = SMC_NETLINK_GET_STATS,
69 /* can be retrieved by unprivileged users */
70 .dumpit = smc_nl_get_stats,
71 },
Guvenc Gulcef0dd7bf2021-06-16 16:52:57 +020072 {
73 .cmd = SMC_NETLINK_GET_FBACK_STATS,
74 /* can be retrieved by unprivileged users */
75 .dumpit = smc_nl_get_fback_stats,
76 },
Karsten Graulfa086662021-09-14 10:35:05 +020077 {
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 },
Karsten Graul3c572142021-09-14 10:35:07 +020099 {
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 },
Guvenc Gulcee8372d92020-12-01 20:20:43 +0100114};
115
116static const struct nla_policy smc_gen_nl_policy[2] = {
117 [SMC_CMD_MAX_ATTR] = { .type = NLA_REJECT, },
118};
119
120/* SMC_GENL family definition */
121struct genl_family smc_gen_nl_family __ro_after_init = {
122 .hdrsize = 0,
123 .name = SMC_GENL_FAMILY_NAME,
124 .version = SMC_GENL_FAMILY_VERSION,
125 .maxattr = SMC_CMD_MAX_ATTR,
126 .policy = smc_gen_nl_policy,
127 .netnsok = true,
128 .module = THIS_MODULE,
129 .ops = smc_gen_nl_ops,
130 .n_ops = ARRAY_SIZE(smc_gen_nl_ops)
131};
132
133int __init smc_nl_init(void)
134{
135 return genl_register_family(&smc_gen_nl_family);
136}
137
138void smc_nl_exit(void)
139{
140 genl_unregister_family(&smc_gen_nl_family);
141}