blob: b97b0c5a82164ef129470401878584474e7634b9 [file] [log] [blame]
Bartosz Golaszewskicb8a14b2020-05-23 15:27:08 +02001// 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 Golaszewskif75063a2020-05-23 15:27:09 +020010struct net_device_devres {
11 struct net_device *ndev;
12};
13
14static void devm_free_netdev(struct device *dev, void *this)
Bartosz Golaszewskicb8a14b2020-05-23 15:27:08 +020015{
Bartosz Golaszewskif75063a2020-05-23 15:27:09 +020016 struct net_device_devres *res = this;
17
18 free_netdev(res->ndev);
Bartosz Golaszewskicb8a14b2020-05-23 15:27:08 +020019}
20
21struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
22 unsigned int txqs, unsigned int rxqs)
23{
Bartosz Golaszewskif75063a2020-05-23 15:27:09 +020024 struct net_device_devres *dr;
Bartosz Golaszewskicb8a14b2020-05-23 15:27:08 +020025
26 dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
27 if (!dr)
28 return NULL;
29
Bartosz Golaszewskif75063a2020-05-23 15:27:09 +020030 dr->ndev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
31 if (!dr->ndev) {
Bartosz Golaszewskicb8a14b2020-05-23 15:27:08 +020032 devres_free(dr);
33 return NULL;
34 }
35
Bartosz Golaszewskicb8a14b2020-05-23 15:27:08 +020036 devres_add(dev, dr);
37
Bartosz Golaszewskif75063a2020-05-23 15:27:09 +020038 return dr->ndev;
Bartosz Golaszewskicb8a14b2020-05-23 15:27:08 +020039}
40EXPORT_SYMBOL(devm_alloc_etherdev_mqs);