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" |
Guvenc Gulce | 8c40602 | 2021-06-16 16:52:56 +0200 | [diff] [blame] | 22 | #include "smc_stats.h" |
Guvenc Gulce | e8372d9 | 2020-12-01 20:20:43 +0100 | [diff] [blame] | 23 | #include "smc_netlink.h" |
| 24 | |
| 25 | #define SMC_CMD_MAX_ATTR 1 |
| 26 | |
| 27 | /* SMC_GENL generic netlink operation definition */ |
| 28 | static const struct genl_ops smc_gen_nl_ops[] = { |
Guvenc Gulce | 099b990 | 2020-12-01 20:20:44 +0100 | [diff] [blame] | 29 | { |
| 30 | .cmd = SMC_NETLINK_GET_SYS_INFO, |
| 31 | /* can be retrieved by unprivileged users */ |
| 32 | .dumpit = smc_nl_get_sys_info, |
| 33 | }, |
Guvenc Gulce | e9b8c84 | 2020-12-01 20:20:45 +0100 | [diff] [blame] | 34 | { |
| 35 | .cmd = SMC_NETLINK_GET_LGR_SMCR, |
| 36 | /* can be retrieved by unprivileged users */ |
| 37 | .dumpit = smcr_nl_get_lgr, |
| 38 | }, |
Guvenc Gulce | 5a7e09d | 2020-12-01 20:20:46 +0100 | [diff] [blame] | 39 | { |
| 40 | .cmd = SMC_NETLINK_GET_LINK_SMCR, |
| 41 | /* can be retrieved by unprivileged users */ |
| 42 | .dumpit = smcr_nl_get_link, |
| 43 | }, |
Guvenc Gulce | 8f9dde4 | 2020-12-01 20:20:47 +0100 | [diff] [blame] | 44 | { |
| 45 | .cmd = SMC_NETLINK_GET_LGR_SMCD, |
| 46 | /* can be retrieved by unprivileged users */ |
| 47 | .dumpit = smcd_nl_get_lgr, |
| 48 | }, |
Guvenc Gulce | aaf9552 | 2020-12-01 20:20:48 +0100 | [diff] [blame] | 49 | { |
| 50 | .cmd = SMC_NETLINK_GET_DEV_SMCD, |
| 51 | /* can be retrieved by unprivileged users */ |
| 52 | .dumpit = smcd_nl_get_device, |
| 53 | }, |
Guvenc Gulce | a3db10e | 2020-12-01 20:20:49 +0100 | [diff] [blame] | 54 | { |
| 55 | .cmd = SMC_NETLINK_GET_DEV_SMCR, |
| 56 | /* can be retrieved by unprivileged users */ |
| 57 | .dumpit = smcr_nl_get_device, |
| 58 | }, |
Guvenc Gulce | 8c40602 | 2021-06-16 16:52:56 +0200 | [diff] [blame] | 59 | { |
| 60 | .cmd = SMC_NETLINK_GET_STATS, |
| 61 | /* can be retrieved by unprivileged users */ |
| 62 | .dumpit = smc_nl_get_stats, |
| 63 | }, |
Guvenc Gulce | f0dd7bf | 2021-06-16 16:52:57 +0200 | [diff] [blame] | 64 | { |
| 65 | .cmd = SMC_NETLINK_GET_FBACK_STATS, |
| 66 | /* can be retrieved by unprivileged users */ |
| 67 | .dumpit = smc_nl_get_fback_stats, |
| 68 | }, |
Guvenc Gulce | e8372d9 | 2020-12-01 20:20:43 +0100 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | static const struct nla_policy smc_gen_nl_policy[2] = { |
| 72 | [SMC_CMD_MAX_ATTR] = { .type = NLA_REJECT, }, |
| 73 | }; |
| 74 | |
| 75 | /* SMC_GENL family definition */ |
| 76 | struct genl_family smc_gen_nl_family __ro_after_init = { |
| 77 | .hdrsize = 0, |
| 78 | .name = SMC_GENL_FAMILY_NAME, |
| 79 | .version = SMC_GENL_FAMILY_VERSION, |
| 80 | .maxattr = SMC_CMD_MAX_ATTR, |
| 81 | .policy = smc_gen_nl_policy, |
| 82 | .netnsok = true, |
| 83 | .module = THIS_MODULE, |
| 84 | .ops = smc_gen_nl_ops, |
| 85 | .n_ops = ARRAY_SIZE(smc_gen_nl_ops) |
| 86 | }; |
| 87 | |
| 88 | int __init smc_nl_init(void) |
| 89 | { |
| 90 | return genl_register_family(&smc_gen_nl_family); |
| 91 | } |
| 92 | |
| 93 | void smc_nl_exit(void) |
| 94 | { |
| 95 | genl_unregister_family(&smc_gen_nl_family); |
| 96 | } |