xref: /linux/net/core/netdev_config.c (revision 37a93dd5c49b5fda807fd204edf2547c3493319c)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include <linux/netdevice.h>
4 #include <net/netdev_queues.h>
5 #include <net/netdev_rx_queue.h>
6 
7 #include "dev.h"
8 
9 static int netdev_nop_validate_qcfg(struct net_device *dev,
10 				    struct netdev_queue_config *qcfg,
11 				    struct netlink_ext_ack *extack)
12 {
13 	return 0;
14 }
15 
16 static int __netdev_queue_config(struct net_device *dev, int rxq_idx,
17 				 struct netdev_queue_config *qcfg,
18 				 struct netlink_ext_ack *extack,
19 				 bool validate)
20 {
21 	int (*validate_cb)(struct net_device *dev,
22 			   struct netdev_queue_config *qcfg,
23 			   struct netlink_ext_ack *extack);
24 	struct pp_memory_provider_params *mpp;
25 	int err;
26 
27 	validate_cb = netdev_nop_validate_qcfg;
28 	if (validate && dev->queue_mgmt_ops->ndo_validate_qcfg)
29 		validate_cb = dev->queue_mgmt_ops->ndo_validate_qcfg;
30 
31 	memset(qcfg, 0, sizeof(*qcfg));
32 
33 	/* Get defaults from the driver, in case user config not set */
34 	if (dev->queue_mgmt_ops->ndo_default_qcfg)
35 		dev->queue_mgmt_ops->ndo_default_qcfg(dev, qcfg);
36 	err = validate_cb(dev, qcfg, extack);
37 	if (err)
38 		return err;
39 
40 	/* Apply MP overrides */
41 	mpp = &__netif_get_rx_queue(dev, rxq_idx)->mp_params;
42 	if (mpp->rx_page_size)
43 		qcfg->rx_page_size = mpp->rx_page_size;
44 	err = validate_cb(dev, qcfg, extack);
45 	if (err)
46 		return err;
47 
48 	return 0;
49 }
50 
51 /**
52  * netdev_queue_config() - get configuration for a given queue
53  * @dev:      net_device instance
54  * @rxq_idx:  index of the queue of interest
55  * @qcfg: queue configuration struct (output)
56  *
57  * Render the configuration for a given queue. This helper should be used
58  * by drivers which support queue configuration to retrieve config for
59  * a particular queue.
60  *
61  * @qcfg is an output parameter and is always fully initialized by this
62  * function. Some values may not be set by the user, drivers may either
63  * deal with the "unset" values in @qcfg, or provide the callback
64  * to populate defaults in queue_management_ops.
65  */
66 void netdev_queue_config(struct net_device *dev, int rxq_idx,
67 			 struct netdev_queue_config *qcfg)
68 {
69 	__netdev_queue_config(dev, rxq_idx, qcfg, NULL, false);
70 }
71 EXPORT_SYMBOL(netdev_queue_config);
72 
73 int netdev_queue_config_validate(struct net_device *dev, int rxq_idx,
74 				 struct netdev_queue_config *qcfg,
75 				 struct netlink_ext_ack *extack)
76 {
77 	return __netdev_queue_config(dev, rxq_idx, qcfg, extack, true);
78 }
79