netdev_config.c 2.3 KB

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