|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
| 2 | + |
| 3 | +#include "netlink.h" |
| 4 | +#include "common.h" |
| 5 | +#include "bitset.h" |
| 6 | + |
| 7 | +struct features_req_info { |
| 8 | + struct ethnl_req_info base; |
| 9 | +}; |
| 10 | + |
| 11 | +struct features_reply_data { |
| 12 | + struct ethnl_reply_data base; |
| 13 | + u32 hw[ETHTOOL_DEV_FEATURE_WORDS]; |
| 14 | + u32 wanted[ETHTOOL_DEV_FEATURE_WORDS]; |
| 15 | + u32 active[ETHTOOL_DEV_FEATURE_WORDS]; |
| 16 | + u32 nochange[ETHTOOL_DEV_FEATURE_WORDS]; |
| 17 | + u32 all[ETHTOOL_DEV_FEATURE_WORDS]; |
| 18 | +}; |
| 19 | + |
| 20 | +#define FEATURES_REPDATA(__reply_base) \ |
| 21 | + container_of(__reply_base, struct features_reply_data, base) |
| 22 | + |
| 23 | +static const struct nla_policy |
| 24 | +features_get_policy[ETHTOOL_A_FEATURES_MAX + 1] = { |
| 25 | + [ETHTOOL_A_FEATURES_UNSPEC] = { .type = NLA_REJECT }, |
| 26 | + [ETHTOOL_A_FEATURES_HEADER] = { .type = NLA_NESTED }, |
| 27 | + [ETHTOOL_A_FEATURES_HW] = { .type = NLA_REJECT }, |
| 28 | + [ETHTOOL_A_FEATURES_WANTED] = { .type = NLA_REJECT }, |
| 29 | + [ETHTOOL_A_FEATURES_ACTIVE] = { .type = NLA_REJECT }, |
| 30 | + [ETHTOOL_A_FEATURES_NOCHANGE] = { .type = NLA_REJECT }, |
| 31 | +}; |
| 32 | + |
| 33 | +static void ethnl_features_to_bitmap32(u32 *dest, netdev_features_t src) |
| 34 | +{ |
| 35 | + unsigned int i; |
| 36 | + |
| 37 | + for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; i++) |
| 38 | + dest[i] = src >> (32 * i); |
| 39 | +} |
| 40 | + |
| 41 | +static int features_prepare_data(const struct ethnl_req_info *req_base, |
| 42 | + struct ethnl_reply_data *reply_base, |
| 43 | + struct genl_info *info) |
| 44 | +{ |
| 45 | + struct features_reply_data *data = FEATURES_REPDATA(reply_base); |
| 46 | + struct net_device *dev = reply_base->dev; |
| 47 | + netdev_features_t all_features; |
| 48 | + |
| 49 | + ethnl_features_to_bitmap32(data->hw, dev->hw_features); |
| 50 | + ethnl_features_to_bitmap32(data->wanted, dev->wanted_features); |
| 51 | + ethnl_features_to_bitmap32(data->active, dev->features); |
| 52 | + ethnl_features_to_bitmap32(data->nochange, NETIF_F_NEVER_CHANGE); |
| 53 | + all_features = GENMASK_ULL(NETDEV_FEATURE_COUNT - 1, 0); |
| 54 | + ethnl_features_to_bitmap32(data->all, all_features); |
| 55 | + |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +static int features_reply_size(const struct ethnl_req_info *req_base, |
| 60 | + const struct ethnl_reply_data *reply_base) |
| 61 | +{ |
| 62 | + const struct features_reply_data *data = FEATURES_REPDATA(reply_base); |
| 63 | + bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS; |
| 64 | + unsigned int len = 0; |
| 65 | + int ret; |
| 66 | + |
| 67 | + ret = ethnl_bitset32_size(data->hw, data->all, NETDEV_FEATURE_COUNT, |
| 68 | + netdev_features_strings, compact); |
| 69 | + if (ret < 0) |
| 70 | + return ret; |
| 71 | + len += ret; |
| 72 | + ret = ethnl_bitset32_size(data->wanted, NULL, NETDEV_FEATURE_COUNT, |
| 73 | + netdev_features_strings, compact); |
| 74 | + if (ret < 0) |
| 75 | + return ret; |
| 76 | + len += ret; |
| 77 | + ret = ethnl_bitset32_size(data->active, NULL, NETDEV_FEATURE_COUNT, |
| 78 | + netdev_features_strings, compact); |
| 79 | + if (ret < 0) |
| 80 | + return ret; |
| 81 | + len += ret; |
| 82 | + ret = ethnl_bitset32_size(data->nochange, NULL, NETDEV_FEATURE_COUNT, |
| 83 | + netdev_features_strings, compact); |
| 84 | + if (ret < 0) |
| 85 | + return ret; |
| 86 | + len += ret; |
| 87 | + |
| 88 | + return len; |
| 89 | +} |
| 90 | + |
| 91 | +static int features_fill_reply(struct sk_buff *skb, |
| 92 | + const struct ethnl_req_info *req_base, |
| 93 | + const struct ethnl_reply_data *reply_base) |
| 94 | +{ |
| 95 | + const struct features_reply_data *data = FEATURES_REPDATA(reply_base); |
| 96 | + bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS; |
| 97 | + int ret; |
| 98 | + |
| 99 | + ret = ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_HW, data->hw, |
| 100 | + data->all, NETDEV_FEATURE_COUNT, |
| 101 | + netdev_features_strings, compact); |
| 102 | + if (ret < 0) |
| 103 | + return ret; |
| 104 | + ret = ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_WANTED, data->wanted, |
| 105 | + NULL, NETDEV_FEATURE_COUNT, |
| 106 | + netdev_features_strings, compact); |
| 107 | + if (ret < 0) |
| 108 | + return ret; |
| 109 | + ret = ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_ACTIVE, data->active, |
| 110 | + NULL, NETDEV_FEATURE_COUNT, |
| 111 | + netdev_features_strings, compact); |
| 112 | + if (ret < 0) |
| 113 | + return ret; |
| 114 | + return ethnl_put_bitset32(skb, ETHTOOL_A_FEATURES_NOCHANGE, |
| 115 | + data->nochange, NULL, NETDEV_FEATURE_COUNT, |
| 116 | + netdev_features_strings, compact); |
| 117 | +} |
| 118 | + |
| 119 | +const struct ethnl_request_ops ethnl_features_request_ops = { |
| 120 | + .request_cmd = ETHTOOL_MSG_FEATURES_GET, |
| 121 | + .reply_cmd = ETHTOOL_MSG_FEATURES_GET_REPLY, |
| 122 | + .hdr_attr = ETHTOOL_A_FEATURES_HEADER, |
| 123 | + .max_attr = ETHTOOL_A_FEATURES_MAX, |
| 124 | + .req_info_size = sizeof(struct features_req_info), |
| 125 | + .reply_data_size = sizeof(struct features_reply_data), |
| 126 | + .request_policy = features_get_policy, |
| 127 | + |
| 128 | + .prepare_data = features_prepare_data, |
| 129 | + .reply_size = features_reply_size, |
| 130 | + .fill_reply = features_fill_reply, |
| 131 | +}; |
0 commit comments