Guvenc Gulce | e8372d9 | 2020-12-01 20:20:43 +0100 | [diff] [blame] | 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" |
Guvenc Gulce | aaf9552 | 2020-12-01 20:20:48 +0100 | [diff] [blame] | 20 | #include "smc_ism.h" |
Guvenc Gulce | a3db10e | 2020-12-01 20:20:49 +0100 | [diff] [blame] | 21 | #include "smc_ib.h" |
Karsten Graul | fa08666 | 2021-09-14 10:35:05 +0200 | [diff] [blame] | 22 | #include "smc_clc.h" |
Guvenc Gulce | 8c40602 | 2021-06-16 16:52:56 +0200 | [diff] [blame] | 23 | #include "smc_stats.h" |
Guvenc Gulce | e8372d9 | 2020-12-01 20:20:43 +0100 | [diff] [blame] | 24 | #include "smc_netlink.h" |
| 25 | |
Karsten Graul | fa08666 | 2021-09-14 10:35:05 +0200 | [diff] [blame] | 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 | }; |
Guvenc Gulce | e8372d9 | 2020-12-01 20:20:43 +0100 | [diff] [blame] | 33 | |
Karsten Graul | fa08666 | 2021-09-14 10:35:05 +0200 | [diff] [blame] | 34 | #define SMC_CMD_MAX_ATTR 1 |
Guvenc Gulce | e8372d9 | 2020-12-01 20:20:43 +0100 | [diff] [blame] | 35 | /* SMC_GENL generic netlink operation definition */ |
| 36 | static const struct genl_ops smc_gen_nl_ops[] = { |
Guvenc Gulce | 099b990 | 2020-12-01 20:20:44 +0100 | [diff] [blame] | 37 | { |
| 38 | .cmd = SMC_NETLINK_GET_SYS_INFO, |
| 39 | /* can be retrieved by unprivileged users */ |
| 40 | .dumpit = smc_nl_get_sys_info, |
| 41 | }, |
Guvenc Gulce | e9b8c84 | 2020-12-01 20:20:45 +0100 | [diff] [blame] | 42 | { |
| 43 | .cmd = SMC_NETLINK_GET_LGR_SMCR, |
| 44 | /* can be retrieved by unprivileged users */ |
| 45 | .dumpit = smcr_nl_get_lgr, |
| 46 | }, |
Guvenc Gulce | 5a7e09d | 2020-12-01 20:20:46 +0100 | [diff] [blame] | 47 | { |
| 48 | .cmd = SMC_NETLINK_GET_LINK_SMCR, |
| 49 | /* can be retrieved by unprivileged users */ |
| 50 | .dumpit = smcr_nl_get_link, |
| 51 | }, |
Guvenc Gulce | 8f9dde4 | 2020-12-01 20:20:47 +0100 | [diff] [blame] | 52 | { |
| 53 | .cmd = SMC_NETLINK_GET_LGR_SMCD, |
| 54 | /* can be retrieved by unprivileged users */ |
| 55 | .dumpit = smcd_nl_get_lgr, |
| 56 | }, |
Guvenc Gulce | aaf9552 | 2020-12-01 20:20:48 +0100 | [diff] [blame] | 57 | { |
| 58 | .cmd = SMC_NETLINK_GET_DEV_SMCD, |
| 59 | /* can be retrieved by unprivileged users */ |
| 60 | .dumpit = smcd_nl_get_device, |
| 61 | }, |
Guvenc Gulce | a3db10e | 2020-12-01 20:20:49 +0100 | [diff] [blame] | 62 | { |
| 63 | .cmd = SMC_NETLINK_GET_DEV_SMCR, |
| 64 | /* can be retrieved by unprivileged users */ |
| 65 | .dumpit = smcr_nl_get_device, |
| 66 | }, |
Guvenc Gulce | 8c40602 | 2021-06-16 16:52:56 +0200 | [diff] [blame] | 67 | { |
| 68 | .cmd = SMC_NETLINK_GET_STATS, |
| 69 | /* can be retrieved by unprivileged users */ |
| 70 | .dumpit = smc_nl_get_stats, |
| 71 | }, |
Guvenc Gulce | f0dd7bf | 2021-06-16 16:52:57 +0200 | [diff] [blame] | 72 | { |
| 73 | .cmd = SMC_NETLINK_GET_FBACK_STATS, |
| 74 | /* can be retrieved by unprivileged users */ |
| 75 | .dumpit = smc_nl_get_fback_stats, |
| 76 | }, |
Karsten Graul | fa08666 | 2021-09-14 10:35:05 +0200 | [diff] [blame] | 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 | }, |
Karsten Graul | 3c57214 | 2021-09-14 10:35:07 +0200 | [diff] [blame] | 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 | }, |
Guvenc Gulce | e8372d9 | 2020-12-01 20:20:43 +0100 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | static const struct nla_policy smc_gen_nl_policy[2] = { |
| 117 | [SMC_CMD_MAX_ATTR] = { .type = NLA_REJECT, }, |
| 118 | }; |
| 119 | |
| 120 | /* SMC_GENL family definition */ |
| 121 | struct 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 | |
| 133 | int __init smc_nl_init(void) |
| 134 | { |
| 135 | return genl_register_family(&smc_gen_nl_family); |
| 136 | } |
| 137 | |
| 138 | void smc_nl_exit(void) |
| 139 | { |
| 140 | genl_unregister_family(&smc_gen_nl_family); |
| 141 | } |