Bartosz Golaszewski | cb8a14b | 2020-05-23 15:27:08 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * This file contains all networking devres helpers. |
| 4 | */ |
| 5 | |
| 6 | #include <linux/device.h> |
| 7 | #include <linux/etherdevice.h> |
| 8 | #include <linux/netdevice.h> |
| 9 | |
Bartosz Golaszewski | f75063a | 2020-05-23 15:27:09 +0200 | [diff] [blame^] | 10 | struct net_device_devres { |
| 11 | struct net_device *ndev; |
| 12 | }; |
| 13 | |
| 14 | static void devm_free_netdev(struct device *dev, void *this) |
Bartosz Golaszewski | cb8a14b | 2020-05-23 15:27:08 +0200 | [diff] [blame] | 15 | { |
Bartosz Golaszewski | f75063a | 2020-05-23 15:27:09 +0200 | [diff] [blame^] | 16 | struct net_device_devres *res = this; |
| 17 | |
| 18 | free_netdev(res->ndev); |
Bartosz Golaszewski | cb8a14b | 2020-05-23 15:27:08 +0200 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv, |
| 22 | unsigned int txqs, unsigned int rxqs) |
| 23 | { |
Bartosz Golaszewski | f75063a | 2020-05-23 15:27:09 +0200 | [diff] [blame^] | 24 | struct net_device_devres *dr; |
Bartosz Golaszewski | cb8a14b | 2020-05-23 15:27:08 +0200 | [diff] [blame] | 25 | |
| 26 | dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL); |
| 27 | if (!dr) |
| 28 | return NULL; |
| 29 | |
Bartosz Golaszewski | f75063a | 2020-05-23 15:27:09 +0200 | [diff] [blame^] | 30 | dr->ndev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs); |
| 31 | if (!dr->ndev) { |
Bartosz Golaszewski | cb8a14b | 2020-05-23 15:27:08 +0200 | [diff] [blame] | 32 | devres_free(dr); |
| 33 | return NULL; |
| 34 | } |
| 35 | |
Bartosz Golaszewski | cb8a14b | 2020-05-23 15:27:08 +0200 | [diff] [blame] | 36 | devres_add(dev, dr); |
| 37 | |
Bartosz Golaszewski | f75063a | 2020-05-23 15:27:09 +0200 | [diff] [blame^] | 38 | return dr->ndev; |
Bartosz Golaszewski | cb8a14b | 2020-05-23 15:27:08 +0200 | [diff] [blame] | 39 | } |
| 40 | EXPORT_SYMBOL(devm_alloc_etherdev_mqs); |