aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/dummy.c
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2017-12-01 18:09:02 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2017-12-02 18:27:58 -0500
commitc33616109a63aa64235108fb7f3b60cb2117ef3b (patch)
tree2d7bbfe3daa1af1ae3b45ce6901e651e19624c57 /drivers/net/dummy.c
parent79579220566cd33fe3b15ce8249c57e10251b258 (diff)
net: dummy: remove fake SR-IOV functionality
netdevsim driver seems like a better place for fake SR-IOV functionality. Remove the code previously added to dummy. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Acked-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'drivers/net/dummy.c')
-rw-r--r--drivers/net/dummy.c215
1 files changed, 1 insertions, 214 deletions
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 58483af80bdb..30b1c8512049 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -42,48 +42,7 @@
42#define DRV_NAME "dummy" 42#define DRV_NAME "dummy"
43#define DRV_VERSION "1.0" 43#define DRV_VERSION "1.0"
44 44
45#undef pr_fmt
46#define pr_fmt(fmt) DRV_NAME ": " fmt
47
48static int numdummies = 1; 45static int numdummies = 1;
49static int num_vfs;
50
51struct vf_data_storage {
52 u8 vf_mac[ETH_ALEN];
53 u16 pf_vlan; /* When set, guest VLAN config not allowed. */
54 u16 pf_qos;
55 __be16 vlan_proto;
56 u16 min_tx_rate;
57 u16 max_tx_rate;
58 u8 spoofchk_enabled;
59 bool rss_query_enabled;
60 u8 trusted;
61 int link_state;
62};
63
64struct dummy_priv {
65 struct vf_data_storage *vfinfo;
66};
67
68static int dummy_num_vf(struct device *dev)
69{
70 return num_vfs;
71}
72
73static struct bus_type dummy_bus = {
74 .name = "dummy",
75 .num_vf = dummy_num_vf,
76};
77
78static void release_dummy_parent(struct device *dev)
79{
80}
81
82static struct device dummy_parent = {
83 .init_name = "dummy",
84 .bus = &dummy_bus,
85 .release = release_dummy_parent,
86};
87 46
88/* fake multicast ability */ 47/* fake multicast ability */
89static void set_multicast_list(struct net_device *dev) 48static void set_multicast_list(struct net_device *dev)
@@ -133,25 +92,10 @@ static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev)
133 92
134static int dummy_dev_init(struct net_device *dev) 93static int dummy_dev_init(struct net_device *dev)
135{ 94{
136 struct dummy_priv *priv = netdev_priv(dev);
137
138 dev->dstats = netdev_alloc_pcpu_stats(struct pcpu_dstats); 95 dev->dstats = netdev_alloc_pcpu_stats(struct pcpu_dstats);
139 if (!dev->dstats) 96 if (!dev->dstats)
140 return -ENOMEM; 97 return -ENOMEM;
141 98
142 priv->vfinfo = NULL;
143
144 if (!num_vfs)
145 return 0;
146
147 dev->dev.parent = &dummy_parent;
148 priv->vfinfo = kcalloc(num_vfs, sizeof(struct vf_data_storage),
149 GFP_KERNEL);
150 if (!priv->vfinfo) {
151 free_percpu(dev->dstats);
152 return -ENOMEM;
153 }
154
155 return 0; 99 return 0;
156} 100}
157 101
@@ -169,117 +113,6 @@ static int dummy_change_carrier(struct net_device *dev, bool new_carrier)
169 return 0; 113 return 0;
170} 114}
171 115
172static int dummy_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
173{
174 struct dummy_priv *priv = netdev_priv(dev);
175
176 if (!is_valid_ether_addr(mac) || (vf >= num_vfs))
177 return -EINVAL;
178
179 memcpy(priv->vfinfo[vf].vf_mac, mac, ETH_ALEN);
180
181 return 0;
182}
183
184static int dummy_set_vf_vlan(struct net_device *dev, int vf,
185 u16 vlan, u8 qos, __be16 vlan_proto)
186{
187 struct dummy_priv *priv = netdev_priv(dev);
188
189 if ((vf >= num_vfs) || (vlan > 4095) || (qos > 7))
190 return -EINVAL;
191
192 priv->vfinfo[vf].pf_vlan = vlan;
193 priv->vfinfo[vf].pf_qos = qos;
194 priv->vfinfo[vf].vlan_proto = vlan_proto;
195
196 return 0;
197}
198
199static int dummy_set_vf_rate(struct net_device *dev, int vf, int min, int max)
200{
201 struct dummy_priv *priv = netdev_priv(dev);
202
203 if (vf >= num_vfs)
204 return -EINVAL;
205
206 priv->vfinfo[vf].min_tx_rate = min;
207 priv->vfinfo[vf].max_tx_rate = max;
208
209 return 0;
210}
211
212static int dummy_set_vf_spoofchk(struct net_device *dev, int vf, bool val)
213{
214 struct dummy_priv *priv = netdev_priv(dev);
215
216 if (vf >= num_vfs)
217 return -EINVAL;
218
219 priv->vfinfo[vf].spoofchk_enabled = val;
220
221 return 0;
222}
223
224static int dummy_set_vf_rss_query_en(struct net_device *dev, int vf, bool val)
225{
226 struct dummy_priv *priv = netdev_priv(dev);
227
228 if (vf >= num_vfs)
229 return -EINVAL;
230
231 priv->vfinfo[vf].rss_query_enabled = val;
232
233 return 0;
234}
235
236static int dummy_set_vf_trust(struct net_device *dev, int vf, bool val)
237{
238 struct dummy_priv *priv = netdev_priv(dev);
239
240 if (vf >= num_vfs)
241 return -EINVAL;
242
243 priv->vfinfo[vf].trusted = val;
244
245 return 0;
246}
247
248static int dummy_get_vf_config(struct net_device *dev,
249 int vf, struct ifla_vf_info *ivi)
250{
251 struct dummy_priv *priv = netdev_priv(dev);
252
253 if (vf >= num_vfs)
254 return -EINVAL;
255
256 ivi->vf = vf;
257 memcpy(&ivi->mac, priv->vfinfo[vf].vf_mac, ETH_ALEN);
258 ivi->vlan = priv->vfinfo[vf].pf_vlan;
259 ivi->qos = priv->vfinfo[vf].pf_qos;
260 ivi->spoofchk = priv->vfinfo[vf].spoofchk_enabled;
261 ivi->linkstate = priv->vfinfo[vf].link_state;
262 ivi->min_tx_rate = priv->vfinfo[vf].min_tx_rate;
263 ivi->max_tx_rate = priv->vfinfo[vf].max_tx_rate;
264 ivi->rss_query_en = priv->vfinfo[vf].rss_query_enabled;
265 ivi->trusted = priv->vfinfo[vf].trusted;
266 ivi->vlan_proto = priv->vfinfo[vf].vlan_proto;
267
268 return 0;
269}
270
271static int dummy_set_vf_link_state(struct net_device *dev, int vf, int state)
272{
273 struct dummy_priv *priv = netdev_priv(dev);
274
275 if (vf >= num_vfs)
276 return -EINVAL;
277
278 priv->vfinfo[vf].link_state = state;
279
280 return 0;
281}
282
283static const struct net_device_ops dummy_netdev_ops = { 116static const struct net_device_ops dummy_netdev_ops = {
284 .ndo_init = dummy_dev_init, 117 .ndo_init = dummy_dev_init,
285 .ndo_uninit = dummy_dev_uninit, 118 .ndo_uninit = dummy_dev_uninit,
@@ -289,14 +122,6 @@ static const struct net_device_ops dummy_netdev_ops = {
289 .ndo_set_mac_address = eth_mac_addr, 122 .ndo_set_mac_address = eth_mac_addr,
290 .ndo_get_stats64 = dummy_get_stats64, 123 .ndo_get_stats64 = dummy_get_stats64,
291 .ndo_change_carrier = dummy_change_carrier, 124 .ndo_change_carrier = dummy_change_carrier,
292 .ndo_set_vf_mac = dummy_set_vf_mac,
293 .ndo_set_vf_vlan = dummy_set_vf_vlan,
294 .ndo_set_vf_rate = dummy_set_vf_rate,
295 .ndo_set_vf_spoofchk = dummy_set_vf_spoofchk,
296 .ndo_set_vf_trust = dummy_set_vf_trust,
297 .ndo_get_vf_config = dummy_get_vf_config,
298 .ndo_set_vf_link_state = dummy_set_vf_link_state,
299 .ndo_set_vf_rss_query_en = dummy_set_vf_rss_query_en,
300}; 125};
301 126
302static void dummy_get_drvinfo(struct net_device *dev, 127static void dummy_get_drvinfo(struct net_device *dev,
@@ -323,13 +148,6 @@ static const struct ethtool_ops dummy_ethtool_ops = {
323 .get_ts_info = dummy_get_ts_info, 148 .get_ts_info = dummy_get_ts_info,
324}; 149};
325 150
326static void dummy_free_netdev(struct net_device *dev)
327{
328 struct dummy_priv *priv = netdev_priv(dev);
329
330 kfree(priv->vfinfo);
331}
332
333static void dummy_setup(struct net_device *dev) 151static void dummy_setup(struct net_device *dev)
334{ 152{
335 ether_setup(dev); 153 ether_setup(dev);
@@ -338,7 +156,6 @@ static void dummy_setup(struct net_device *dev)
338 dev->netdev_ops = &dummy_netdev_ops; 156 dev->netdev_ops = &dummy_netdev_ops;
339 dev->ethtool_ops = &dummy_ethtool_ops; 157 dev->ethtool_ops = &dummy_ethtool_ops;
340 dev->needs_free_netdev = true; 158 dev->needs_free_netdev = true;
341 dev->priv_destructor = dummy_free_netdev;
342 159
343 /* Fill in device structure with ethernet-generic values. */ 160 /* Fill in device structure with ethernet-generic values. */
344 dev->flags |= IFF_NOARP; 161 dev->flags |= IFF_NOARP;
@@ -370,7 +187,6 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[],
370 187
371static struct rtnl_link_ops dummy_link_ops __read_mostly = { 188static struct rtnl_link_ops dummy_link_ops __read_mostly = {
372 .kind = DRV_NAME, 189 .kind = DRV_NAME,
373 .priv_size = sizeof(struct dummy_priv),
374 .setup = dummy_setup, 190 .setup = dummy_setup,
375 .validate = dummy_validate, 191 .validate = dummy_validate,
376}; 192};
@@ -379,16 +195,12 @@ static struct rtnl_link_ops dummy_link_ops __read_mostly = {
379module_param(numdummies, int, 0); 195module_param(numdummies, int, 0);
380MODULE_PARM_DESC(numdummies, "Number of dummy pseudo devices"); 196MODULE_PARM_DESC(numdummies, "Number of dummy pseudo devices");
381 197
382module_param(num_vfs, int, 0);
383MODULE_PARM_DESC(num_vfs, "Number of dummy VFs per dummy device");
384
385static int __init dummy_init_one(void) 198static int __init dummy_init_one(void)
386{ 199{
387 struct net_device *dev_dummy; 200 struct net_device *dev_dummy;
388 int err; 201 int err;
389 202
390 dev_dummy = alloc_netdev(sizeof(struct dummy_priv), 203 dev_dummy = alloc_netdev(0, "dummy%d", NET_NAME_ENUM, dummy_setup);
391 "dummy%d", NET_NAME_ENUM, dummy_setup);
392 if (!dev_dummy) 204 if (!dev_dummy)
393 return -ENOMEM; 205 return -ENOMEM;
394 206
@@ -407,21 +219,6 @@ static int __init dummy_init_module(void)
407{ 219{
408 int i, err = 0; 220 int i, err = 0;
409 221
410 if (num_vfs) {
411 err = bus_register(&dummy_bus);
412 if (err < 0) {
413 pr_err("registering dummy bus failed\n");
414 return err;
415 }
416
417 err = device_register(&dummy_parent);
418 if (err < 0) {
419 pr_err("registering dummy parent device failed\n");
420 bus_unregister(&dummy_bus);
421 return err;
422 }
423 }
424
425 rtnl_lock(); 222 rtnl_lock();
426 err = __rtnl_link_register(&dummy_link_ops); 223 err = __rtnl_link_register(&dummy_link_ops);
427 if (err < 0) 224 if (err < 0)
@@ -437,22 +234,12 @@ static int __init dummy_init_module(void)
437out: 234out:
438 rtnl_unlock(); 235 rtnl_unlock();
439 236
440 if (err && num_vfs) {
441 device_unregister(&dummy_parent);
442 bus_unregister(&dummy_bus);
443 }
444
445 return err; 237 return err;
446} 238}
447 239
448static void __exit dummy_cleanup_module(void) 240static void __exit dummy_cleanup_module(void)
449{ 241{
450 rtnl_link_unregister(&dummy_link_ops); 242 rtnl_link_unregister(&dummy_link_ops);
451
452 if (num_vfs) {
453 device_unregister(&dummy_parent);
454 bus_unregister(&dummy_bus);
455 }
456} 243}
457 244
458module_init(dummy_init_module); 245module_init(dummy_init_module);