~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ethtool/rss.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 
  3 #include "netlink.h"
  4 #include "common.h"
  5 
  6 struct rss_req_info {
  7         struct ethnl_req_info           base;
  8         u32                             rss_context;
  9 };
 10 
 11 struct rss_reply_data {
 12         struct ethnl_reply_data         base;
 13         u32                             indir_size;
 14         u32                             hkey_size;
 15         u32                             hfunc;
 16         u32                             input_xfrm;
 17         u32                             *indir_table;
 18         u8                              *hkey;
 19 };
 20 
 21 #define RSS_REQINFO(__req_base) \
 22         container_of(__req_base, struct rss_req_info, base)
 23 
 24 #define RSS_REPDATA(__reply_base) \
 25         container_of(__reply_base, struct rss_reply_data, base)
 26 
 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 },
 30 };
 31 
 32 static int
 33 rss_parse_request(struct ethnl_req_info *req_info, struct nlattr **tb,
 34                   struct netlink_ext_ack *extack)
 35 {
 36         struct rss_req_info *request = RSS_REQINFO(req_info);
 37 
 38         if (tb[ETHTOOL_A_RSS_CONTEXT])
 39                 request->rss_context = nla_get_u32(tb[ETHTOOL_A_RSS_CONTEXT]);
 40 
 41         return 0;
 42 }
 43 
 44 static int
 45 rss_prepare_data(const struct ethnl_req_info *req_base,
 46                  struct ethnl_reply_data *reply_base,
 47                  const struct genl_info *info)
 48 {
 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;
 55         u8 *rss_config;
 56         int ret;
 57 
 58         ops = dev->ethtool_ops;
 59         if (!ops->get_rxfh)
 60                 return -EOPNOTSUPP;
 61 
 62         /* Some drivers don't handle rss_context */
 63         if (request->rss_context && !ops->cap_rss_ctx_supported)
 64                 return -EOPNOTSUPP;
 65 
 66         ret = ethnl_ops_begin(dev);
 67         if (ret < 0)
 68                 return ret;
 69 
 70         data->indir_size = 0;
 71         data->hkey_size = 0;
 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);
 76 
 77         indir_bytes = data->indir_size * sizeof(u32);
 78         total_size = indir_bytes + data->hkey_size;
 79         rss_config = kzalloc(total_size, GFP_KERNEL);
 80         if (!rss_config) {
 81                 ret = -ENOMEM;
 82                 goto out_ops;
 83         }
 84 
 85         if (data->indir_size)
 86                 data->indir_table = (u32 *)rss_config;
 87         if (data->hkey_size)
 88                 data->hkey = rss_config + indir_bytes;
 89 
 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;
 95 
 96         ret = ops->get_rxfh(dev, &rxfh);
 97         if (ret)
 98                 goto out_ops;
 99 
100         data->hfunc = rxfh.hfunc;
101         data->input_xfrm = rxfh.input_xfrm;
102 out_ops:
103         ethnl_ops_complete(dev);
104         return ret;
105 }
106 
107 static int
108 rss_reply_size(const struct ethnl_req_info *req_base,
109                const struct ethnl_reply_data *reply_base)
110 {
111         const struct rss_reply_data *data = RSS_REPDATA(reply_base);
112         int len;
113 
114         len = nla_total_size(sizeof(u32)) +     /* _RSS_CONTEXT */
115               nla_total_size(sizeof(u32)) +     /* _RSS_HFUNC */
116               nla_total_size(sizeof(u32)) +     /* _RSS_INPUT_XFRM */
117               nla_total_size(sizeof(u32) * data->indir_size) + /* _RSS_INDIR */
118               nla_total_size(data->hkey_size);  /* _RSS_HKEY */
119 
120         return len;
121 }
122 
123 static int
124 rss_fill_reply(struct sk_buff *skb, const struct ethnl_req_info *req_base,
125                const struct ethnl_reply_data *reply_base)
126 {
127         const struct rss_reply_data *data = RSS_REPDATA(reply_base);
128         struct rss_req_info *request = RSS_REQINFO(req_base);
129 
130         if (request->rss_context &&
131             nla_put_u32(skb, ETHTOOL_A_RSS_CONTEXT, request->rss_context))
132                 return -EMSGSIZE;
133 
134         if ((data->hfunc &&
135              nla_put_u32(skb, ETHTOOL_A_RSS_HFUNC, data->hfunc)) ||
136             (data->input_xfrm &&
137              nla_put_u32(skb, ETHTOOL_A_RSS_INPUT_XFRM, data->input_xfrm)) ||
138             (data->indir_size &&
139              nla_put(skb, ETHTOOL_A_RSS_INDIR,
140                      sizeof(u32) * data->indir_size, data->indir_table)) ||
141             (data->hkey_size &&
142              nla_put(skb, ETHTOOL_A_RSS_HKEY, data->hkey_size, data->hkey)))
143                 return -EMSGSIZE;
144 
145         return 0;
146 }
147 
148 static void rss_cleanup_data(struct ethnl_reply_data *reply_base)
149 {
150         const struct rss_reply_data *data = RSS_REPDATA(reply_base);
151 
152         kfree(data->indir_table);
153 }
154 
155 const struct ethnl_request_ops ethnl_rss_request_ops = {
156         .request_cmd            = ETHTOOL_MSG_RSS_GET,
157         .reply_cmd              = ETHTOOL_MSG_RSS_GET_REPLY,
158         .hdr_attr               = ETHTOOL_A_RSS_HEADER,
159         .req_info_size          = sizeof(struct rss_req_info),
160         .reply_data_size        = sizeof(struct rss_reply_data),
161 
162         .parse_request          = rss_parse_request,
163         .prepare_data           = rss_prepare_data,
164         .reply_size             = rss_reply_size,
165         .fill_reply             = rss_fill_reply,
166         .cleanup_data           = rss_cleanup_data,
167 };
168 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php