1 // SPDX-License-Identifier: GPL-2.0-only
7 struct ethnl_req_info base;
11 struct rss_reply_data {
12 struct ethnl_reply_data base;
21 #define RSS_REQINFO(__req_base) \
22 container_of(__req_base, struct rss_req_info, base)
24 #define RSS_REPDATA(__reply_base) \
25 container_of(__reply_base, struct rss_reply_data, base)
27 const struct nla_policy ethnl_rss_get_policy[] = {
28 [ETHTOOL_A_RSS_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
29 [ETHTOOL_A_RSS_CONTEXT] = { .type = NLA_U32 },
33 rss_parse_request(struct ethnl_req_info *req_info, struct nlattr **tb,
34 struct netlink_ext_ack *extack)
36 struct rss_req_info *request = RSS_REQINFO(req_info);
38 if (tb[ETHTOOL_A_RSS_CONTEXT])
39 request->rss_context = nla_get_u32(tb[ETHTOOL_A_RSS_CONTEXT]);
45 rss_prepare_data(const struct ethnl_req_info *req_base,
46 struct ethnl_reply_data *reply_base,
47 const struct genl_info *info)
49 struct rss_reply_data *data = RSS_REPDATA(reply_base);
50 struct rss_req_info *request = RSS_REQINFO(req_base);
51 struct net_device *dev = reply_base->dev;
52 struct ethtool_rxfh_param rxfh = {};
53 const struct ethtool_ops *ops;
54 u32 total_size, indir_bytes;
58 ops = dev->ethtool_ops;
62 /* Some drivers don't handle rss_context */
63 if (request->rss_context && !ops->cap_rss_ctx_supported)
66 ret = ethnl_ops_begin(dev);
72 if (ops->get_rxfh_indir_size)
73 data->indir_size = ops->get_rxfh_indir_size(dev);
74 if (ops->get_rxfh_key_size)
75 data->hkey_size = ops->get_rxfh_key_size(dev);
77 indir_bytes = data->indir_size * sizeof(u32);
78 total_size = indir_bytes + data->hkey_size;
79 rss_config = kzalloc(total_size, GFP_KERNEL);
86 data->indir_table = (u32 *)rss_config;
88 data->hkey = rss_config + indir_bytes;
90 rxfh.indir_size = data->indir_size;
91 rxfh.indir = data->indir_table;
92 rxfh.key_size = data->hkey_size;
93 rxfh.key = data->hkey;
94 rxfh.rss_context = request->rss_context;
96 ret = ops->get_rxfh(dev, &rxfh);
100 data->hfunc = rxfh.hfunc;
101 data->input_xfrm = rxfh.input_xfrm;
103 ethnl_ops_complete(dev);
108 rss_reply_size(const struct ethnl_req_info *req_base,
109 const struct ethnl_reply_data *reply_base)
111 const struct rss_reply_data *data = RSS_REPDATA(reply_base);
114 len = nla_total_size(sizeof(u32)) + /* _RSS_HFUNC */
115 nla_total_size(sizeof(u32)) + /* _RSS_INPUT_XFRM */
116 nla_total_size(sizeof(u32) * data->indir_size) + /* _RSS_INDIR */
117 nla_total_size(data->hkey_size); /* _RSS_HKEY */
123 rss_fill_reply(struct sk_buff *skb, const struct ethnl_req_info *req_base,
124 const struct ethnl_reply_data *reply_base)
126 const struct rss_reply_data *data = RSS_REPDATA(reply_base);
129 nla_put_u32(skb, ETHTOOL_A_RSS_HFUNC, data->hfunc)) ||
131 nla_put_u32(skb, ETHTOOL_A_RSS_INPUT_XFRM, data->input_xfrm)) ||
133 nla_put(skb, ETHTOOL_A_RSS_INDIR,
134 sizeof(u32) * data->indir_size, data->indir_table)) ||
136 nla_put(skb, ETHTOOL_A_RSS_HKEY, data->hkey_size, data->hkey)))
142 static void rss_cleanup_data(struct ethnl_reply_data *reply_base)
144 const struct rss_reply_data *data = RSS_REPDATA(reply_base);
146 kfree(data->indir_table);
149 const struct ethnl_request_ops ethnl_rss_request_ops = {
150 .request_cmd = ETHTOOL_MSG_RSS_GET,
151 .reply_cmd = ETHTOOL_MSG_RSS_GET_REPLY,
152 .hdr_attr = ETHTOOL_A_RSS_HEADER,
153 .req_info_size = sizeof(struct rss_req_info),
154 .reply_data_size = sizeof(struct rss_reply_data),
156 .parse_request = rss_parse_request,
157 .prepare_data = rss_prepare_data,
158 .reply_size = rss_reply_size,
159 .fill_reply = rss_fill_reply,
160 .cleanup_data = rss_cleanup_data,