Skip to content

Commit efcb9a4

Browse files
committed
net: add bare bone queue configs
We'll need to pass extra parameters when allocating a queue for memory providers. Define a new structure for queue configurations, and pass it to qapi callbacks. It's empty for now, actual parameters will be added in following patches. Configurations should persist across resets, and for that they're default-initialised on device registration and stored in struct netdev_rx_queue. We also add a new qapi callback for defaulting a given config. It must be implemented if a driver wants to use queue configs and is optional otherwise. Suggested-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
1 parent 92d76cf commit efcb9a4

9 files changed

Lines changed: 66 additions & 16 deletions

File tree

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15911,7 +15911,9 @@ static const struct netdev_stat_ops bnxt_stat_ops = {
1591115911
.get_base_stats = bnxt_get_base_stats,
1591215912
};
1591315913

15914-
static int bnxt_queue_mem_alloc(struct net_device *dev, void *qmem, int idx)
15914+
static int bnxt_queue_mem_alloc(struct net_device *dev,
15915+
struct netdev_queue_config *qcfg,
15916+
void *qmem, int idx)
1591515917
{
1591615918
struct bnxt_rx_ring_info *rxr, *clone;
1591715919
struct bnxt *bp = netdev_priv(dev);
@@ -16077,7 +16079,9 @@ static void bnxt_copy_rx_ring(struct bnxt *bp,
1607716079
dst->rx_agg_bmap = src->rx_agg_bmap;
1607816080
}
1607916081

16080-
static int bnxt_queue_start(struct net_device *dev, void *qmem, int idx)
16082+
static int bnxt_queue_start(struct net_device *dev,
16083+
struct netdev_queue_config *qcfg,
16084+
void *qmem, int idx)
1608116085
{
1608216086
struct bnxt *bp = netdev_priv(dev);
1608316087
struct bnxt_rx_ring_info *rxr, *clone;

drivers/net/ethernet/google/gve/gve_main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,8 +2616,9 @@ static void gve_rx_queue_mem_free(struct net_device *dev, void *per_q_mem)
26162616
gve_rx_free_ring_dqo(priv, gve_per_q_mem, &cfg);
26172617
}
26182618

2619-
static int gve_rx_queue_mem_alloc(struct net_device *dev, void *per_q_mem,
2620-
int idx)
2619+
static int gve_rx_queue_mem_alloc(struct net_device *dev,
2620+
struct netdev_queue_config *qcfg,
2621+
void *per_q_mem, int idx)
26212622
{
26222623
struct gve_priv *priv = netdev_priv(dev);
26232624
struct gve_rx_alloc_rings_cfg cfg = {0};
@@ -2638,7 +2639,9 @@ static int gve_rx_queue_mem_alloc(struct net_device *dev, void *per_q_mem,
26382639
return err;
26392640
}
26402641

2641-
static int gve_rx_queue_start(struct net_device *dev, void *per_q_mem, int idx)
2642+
static int gve_rx_queue_start(struct net_device *dev,
2643+
struct netdev_queue_config *qcfg,
2644+
void *per_q_mem, int idx)
26422645
{
26432646
struct gve_priv *priv = netdev_priv(dev);
26442647
struct gve_rx_ring *gve_per_q_mem;

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5596,8 +5596,9 @@ struct mlx5_qmgmt_data {
55965596
struct mlx5e_channel_param cparam;
55975597
};
55985598

5599-
static int mlx5e_queue_mem_alloc(struct net_device *dev, void *newq,
5600-
int queue_index)
5599+
static int mlx5e_queue_mem_alloc(struct net_device *dev,
5600+
struct netdev_queue_config *qcfg,
5601+
void *newq, int queue_index)
56015602
{
56025603
struct mlx5_qmgmt_data *new = (struct mlx5_qmgmt_data *)newq;
56035604
struct mlx5e_priv *priv = netdev_priv(dev);
@@ -5658,8 +5659,9 @@ static int mlx5e_queue_stop(struct net_device *dev, void *oldq, int queue_index)
56585659
return 0;
56595660
}
56605661

5661-
static int mlx5e_queue_start(struct net_device *dev, void *newq,
5662-
int queue_index)
5662+
static int mlx5e_queue_start(struct net_device *dev,
5663+
struct netdev_queue_config *qcfg,
5664+
void *newq, int queue_index)
56635665
{
56645666
struct mlx5_qmgmt_data *new = (struct mlx5_qmgmt_data *)newq;
56655667
struct mlx5e_priv *priv = netdev_priv(dev);

drivers/net/ethernet/meta/fbnic/fbnic_txrx.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,9 @@ void fbnic_napi_depletion_check(struct net_device *netdev)
28092809
fbnic_wrfl(fbd);
28102810
}
28112811

2812-
static int fbnic_queue_mem_alloc(struct net_device *dev, void *qmem, int idx)
2812+
static int fbnic_queue_mem_alloc(struct net_device *dev,
2813+
struct netdev_queue_config *qcfg,
2814+
void *qmem, int idx)
28132815
{
28142816
struct fbnic_net *fbn = netdev_priv(dev);
28152817
const struct fbnic_q_triad *real;
@@ -2861,7 +2863,9 @@ static void __fbnic_nv_restart(struct fbnic_net *fbn,
28612863
netif_wake_subqueue(fbn->netdev, nv->qt[i].sub0.q_idx);
28622864
}
28632865

2864-
static int fbnic_queue_start(struct net_device *dev, void *qmem, int idx)
2866+
static int fbnic_queue_start(struct net_device *dev,
2867+
struct netdev_queue_config *qcfg,
2868+
void *qmem, int idx)
28652869
{
28662870
struct fbnic_net *fbn = netdev_priv(dev);
28672871
struct fbnic_napi_vector *nv;

drivers/net/netdevsim/netdev.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,9 @@ struct nsim_queue_mem {
758758
};
759759

760760
static int
761-
nsim_queue_mem_alloc(struct net_device *dev, void *per_queue_mem, int idx)
761+
nsim_queue_mem_alloc(struct net_device *dev,
762+
struct netdev_queue_config *qcfg,
763+
void *per_queue_mem, int idx)
762764
{
763765
struct nsim_queue_mem *qmem = per_queue_mem;
764766
struct netdevsim *ns = netdev_priv(dev);
@@ -807,7 +809,8 @@ static void nsim_queue_mem_free(struct net_device *dev, void *per_queue_mem)
807809
}
808810

809811
static int
810-
nsim_queue_start(struct net_device *dev, void *per_queue_mem, int idx)
812+
nsim_queue_start(struct net_device *dev, struct netdev_queue_config *qcfg,
813+
void *per_queue_mem, int idx)
811814
{
812815
struct nsim_queue_mem *qmem = per_queue_mem;
813816
struct netdevsim *ns = netdev_priv(dev);

include/net/netdev_queues.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ struct netdev_config {
1414
u8 hds_config;
1515
};
1616

17+
struct netdev_queue_config {
18+
};
19+
1720
/* See the netdev.yaml spec for definition of each statistic */
1821
struct netdev_queue_stats_rx {
1922
u64 bytes;
@@ -130,23 +133,29 @@ void netdev_stat_queue_sum(struct net_device *netdev,
130133
* @ndo_queue_get_dma_dev: Get dma device for zero-copy operations to be used
131134
* for this queue. Return NULL on error.
132135
*
136+
* @ndo_default_qcfg: Populate queue config struct with defaults. Optional.
137+
*
133138
* Note that @ndo_queue_mem_alloc and @ndo_queue_mem_free may be called while
134139
* the interface is closed. @ndo_queue_start and @ndo_queue_stop will only
135140
* be called for an interface which is open.
136141
*/
137142
struct netdev_queue_mgmt_ops {
138143
size_t ndo_queue_mem_size;
139144
int (*ndo_queue_mem_alloc)(struct net_device *dev,
145+
struct netdev_queue_config *qcfg,
140146
void *per_queue_mem,
141147
int idx);
142148
void (*ndo_queue_mem_free)(struct net_device *dev,
143149
void *per_queue_mem);
144150
int (*ndo_queue_start)(struct net_device *dev,
151+
struct netdev_queue_config *qcfg,
145152
void *per_queue_mem,
146153
int idx);
147154
int (*ndo_queue_stop)(struct net_device *dev,
148155
void *per_queue_mem,
149156
int idx);
157+
void (*ndo_default_qcfg)(struct net_device *dev,
158+
struct netdev_queue_config *qcfg);
150159
struct device * (*ndo_queue_get_dma_dev)(struct net_device *dev,
151160
int idx);
152161
};

include/net/netdev_rx_queue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/sysfs.h>
88
#include <net/xdp.h>
99
#include <net/page_pool/types.h>
10+
#include <net/netdev_queues.h>
1011

1112
/* This structure contains an instance of an RX queue. */
1213
struct netdev_rx_queue {
@@ -27,6 +28,7 @@ struct netdev_rx_queue {
2728
struct xsk_buff_pool *pool;
2829
#endif
2930
struct napi_struct *napi;
31+
struct netdev_queue_config qcfg;
3032
struct pp_memory_provider_params mp_params;
3133
} ____cacheline_aligned_in_smp;
3234

net/core/dev.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11270,6 +11270,21 @@ static void netdev_free_phy_link_topology(struct net_device *dev)
1127011270
}
1127111271
}
1127211272

11273+
static void init_rx_queue_cfgs(struct net_device *dev)
11274+
{
11275+
const struct netdev_queue_mgmt_ops *qops = dev->queue_mgmt_ops;
11276+
struct netdev_rx_queue *rxq;
11277+
int i;
11278+
11279+
if (!qops || !qops->ndo_default_qcfg)
11280+
return;
11281+
11282+
for (i = 0; i < dev->num_rx_queues; i++) {
11283+
rxq = __netif_get_rx_queue(dev, i);
11284+
qops->ndo_default_qcfg(dev, &rxq->qcfg);
11285+
}
11286+
}
11287+
1127311288
/**
1127411289
* register_netdevice() - register a network device
1127511290
* @dev: device to register
@@ -11315,6 +11330,8 @@ int register_netdevice(struct net_device *dev)
1131511330
if (!dev->name_node)
1131611331
goto out;
1131711332

11333+
init_rx_queue_cfgs(dev);
11334+
1131811335
/* Init, if this function is available */
1131911336
if (dev->netdev_ops->ndo_init) {
1132011337
ret = dev->netdev_ops->ndo_init(dev);

net/core/netdev_rx_queue.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq_idx)
2222
{
2323
struct netdev_rx_queue *rxq = __netif_get_rx_queue(dev, rxq_idx);
2424
const struct netdev_queue_mgmt_ops *qops = dev->queue_mgmt_ops;
25+
struct netdev_queue_config qcfg;
2526
void *new_mem, *old_mem;
2627
int err;
2728

@@ -31,6 +32,10 @@ int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq_idx)
3132

3233
netdev_assert_locked(dev);
3334

35+
memset(&qcfg, 0, sizeof(qcfg));
36+
if (qops->ndo_default_qcfg)
37+
qops->ndo_default_qcfg(dev, &qcfg);
38+
3439
new_mem = kvzalloc(qops->ndo_queue_mem_size, GFP_KERNEL);
3540
if (!new_mem)
3641
return -ENOMEM;
@@ -41,7 +46,7 @@ int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq_idx)
4146
goto err_free_new_mem;
4247
}
4348

44-
err = qops->ndo_queue_mem_alloc(dev, new_mem, rxq_idx);
49+
err = qops->ndo_queue_mem_alloc(dev, &qcfg, new_mem, rxq_idx);
4550
if (err)
4651
goto err_free_old_mem;
4752

@@ -54,7 +59,7 @@ int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq_idx)
5459
if (err)
5560
goto err_free_new_queue_mem;
5661

57-
err = qops->ndo_queue_start(dev, new_mem, rxq_idx);
62+
err = qops->ndo_queue_start(dev, &qcfg, new_mem, rxq_idx);
5863
if (err)
5964
goto err_start_queue;
6065
} else {
@@ -66,6 +71,7 @@ int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq_idx)
6671
kvfree(old_mem);
6772
kvfree(new_mem);
6873

74+
rxq->qcfg = qcfg;
6975
return 0;
7076

7177
err_start_queue:
@@ -76,7 +82,7 @@ int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq_idx)
7682
* WARN if we fail to recover the old rx queue, and at least free
7783
* old_mem so we don't also leak that.
7884
*/
79-
if (qops->ndo_queue_start(dev, old_mem, rxq_idx)) {
85+
if (qops->ndo_queue_start(dev, &rxq->qcfg, old_mem, rxq_idx)) {
8086
WARN(1,
8187
"Failed to restart old queue in error path. RX queue %d may be unhealthy.",
8288
rxq_idx);

0 commit comments

Comments
 (0)