Skip to content

Commit fcce2fd

Browse files
committed
Merge branch 'mlx4-dynamic-tc-tx-queues'
Tariq Toukan says: ==================== mlx4_en dynamic TC tx queues This patchset from Inbar aligns the number of TX queues to the actual need, according to the TC configuration. Series generated against net-next commit: 2ee87db Merge branch 'nfp-get_phys_port_name-for-representors-and-SR-IOV-reorder' ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents cddbb79 + ec327f7 commit fcce2fd

File tree

7 files changed

+79
-26
lines changed

7 files changed

+79
-26
lines changed

drivers/net/ethernet/mellanox/mlx4/en_dcb_nl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static u8 mlx4_en_dcbnl_set_state(struct net_device *dev, u8 state)
238238
priv->flags &= ~MLX4_EN_FLAG_DCB_ENABLED;
239239
}
240240

241-
if (mlx4_en_setup_tc(dev, num_tcs))
241+
if (mlx4_en_alloc_tx_queue_per_tc(dev, num_tcs))
242242
return 1;
243243

244244
return 0;
@@ -303,7 +303,7 @@ static int mlx4_en_ets_validate(struct mlx4_en_priv *priv, struct ieee_ets *ets)
303303
int has_ets_tc = 0;
304304

305305
for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
306-
if (ets->prio_tc[i] >= MLX4_EN_NUM_UP) {
306+
if (ets->prio_tc[i] >= MLX4_EN_NUM_UP_HIGH) {
307307
en_err(priv, "Bad priority in UP <=> TC mapping. TC: %d, UP: %d\n",
308308
i, ets->prio_tc[i]);
309309
return -EINVAL;
@@ -472,7 +472,7 @@ static u8 mlx4_en_dcbnl_setdcbx(struct net_device *dev, u8 mode)
472472
goto err;
473473
if (mlx4_en_dcbnl_ieee_setpfc(dev, &pfc))
474474
goto err;
475-
if (mlx4_en_setup_tc(dev, 0))
475+
if (mlx4_en_alloc_tx_queue_per_tc(dev, 0))
476476
goto err;
477477
}
478478

drivers/net/ethernet/mellanox/mlx4/en_ethtool.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,8 @@ static void mlx4_en_get_channels(struct net_device *dev,
17501750
channel->max_tx = MLX4_EN_MAX_TX_RING_P_UP;
17511751

17521752
channel->rx_count = priv->rx_ring_num;
1753-
channel->tx_count = priv->tx_ring_num[TX] / MLX4_EN_NUM_UP;
1753+
channel->tx_count = priv->tx_ring_num[TX] /
1754+
priv->prof->num_up;
17541755
}
17551756

17561757
static int mlx4_en_set_channels(struct net_device *dev,
@@ -1763,6 +1764,7 @@ static int mlx4_en_set_channels(struct net_device *dev,
17631764
int port_up = 0;
17641765
int xdp_count;
17651766
int err = 0;
1767+
u8 up;
17661768

17671769
if (!channel->tx_count || !channel->rx_count)
17681770
return -EINVAL;
@@ -1773,18 +1775,19 @@ static int mlx4_en_set_channels(struct net_device *dev,
17731775

17741776
mutex_lock(&mdev->state_lock);
17751777
xdp_count = priv->tx_ring_num[TX_XDP] ? channel->rx_count : 0;
1776-
if (channel->tx_count * MLX4_EN_NUM_UP + xdp_count > MAX_TX_RINGS) {
1778+
if (channel->tx_count * priv->prof->num_up + xdp_count >
1779+
MAX_TX_RINGS) {
17771780
err = -EINVAL;
17781781
en_err(priv,
17791782
"Total number of TX and XDP rings (%d) exceeds the maximum supported (%d)\n",
1780-
channel->tx_count * MLX4_EN_NUM_UP + xdp_count,
1783+
channel->tx_count * priv->prof->num_up + xdp_count,
17811784
MAX_TX_RINGS);
17821785
goto out;
17831786
}
17841787

17851788
memcpy(&new_prof, priv->prof, sizeof(struct mlx4_en_port_profile));
17861789
new_prof.num_tx_rings_p_up = channel->tx_count;
1787-
new_prof.tx_ring_num[TX] = channel->tx_count * MLX4_EN_NUM_UP;
1790+
new_prof.tx_ring_num[TX] = channel->tx_count * priv->prof->num_up;
17881791
new_prof.tx_ring_num[TX_XDP] = xdp_count;
17891792
new_prof.rx_ring_num = channel->rx_count;
17901793

@@ -1799,11 +1802,11 @@ static int mlx4_en_set_channels(struct net_device *dev,
17991802

18001803
mlx4_en_safe_replace_resources(priv, tmp);
18011804

1802-
netif_set_real_num_tx_queues(dev, priv->tx_ring_num[TX]);
18031805
netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
18041806

1805-
if (netdev_get_num_tc(dev))
1806-
mlx4_en_setup_tc(dev, MLX4_EN_NUM_UP);
1807+
up = (priv->prof->num_up == MLX4_EN_NUM_UP_LOW) ?
1808+
0 : priv->prof->num_up;
1809+
mlx4_en_setup_tc(dev, up);
18071810

18081811
en_warn(priv, "Using %d TX rings\n", priv->tx_ring_num[TX]);
18091812
en_warn(priv, "Using %d RX rings\n", priv->rx_ring_num);

drivers/net/ethernet/mellanox/mlx4/en_main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ static int mlx4_en_get_profile(struct mlx4_en_dev *mdev)
169169
params->prof[i].tx_ppp = pfctx;
170170
params->prof[i].tx_ring_size = MLX4_EN_DEF_TX_RING_SIZE;
171171
params->prof[i].rx_ring_size = MLX4_EN_DEF_RX_RING_SIZE;
172+
params->prof[i].num_up = MLX4_EN_NUM_UP_LOW;
173+
params->prof[i].num_tx_rings_p_up = params->num_tx_rings_p_up;
172174
params->prof[i].tx_ring_num[TX] = params->num_tx_rings_p_up *
173-
MLX4_EN_NUM_UP;
175+
params->prof[i].num_up;
174176
params->prof[i].rss_rings = 0;
175177
params->prof[i].inline_thold = inline_thold;
176178
}

drivers/net/ethernet/mellanox/mlx4/en_netdev.c

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ int mlx4_en_setup_tc(struct net_device *dev, u8 up)
6060
int i;
6161
unsigned int offset = 0;
6262

63-
if (up && up != MLX4_EN_NUM_UP)
63+
if (up && up != MLX4_EN_NUM_UP_HIGH)
6464
return -EINVAL;
6565

6666
netdev_set_num_tc(dev, up);
67-
67+
netif_set_real_num_tx_queues(dev, priv->tx_ring_num[TX]);
6868
/* Partition Tx queues evenly amongst UP's */
6969
for (i = 0; i < up; i++) {
7070
netdev_set_tc_queue(dev, i, priv->num_tx_rings_p_up, offset);
@@ -86,16 +86,63 @@ int mlx4_en_setup_tc(struct net_device *dev, u8 up)
8686
return 0;
8787
}
8888

89+
int mlx4_en_alloc_tx_queue_per_tc(struct net_device *dev, u8 tc)
90+
{
91+
struct mlx4_en_priv *priv = netdev_priv(dev);
92+
struct mlx4_en_dev *mdev = priv->mdev;
93+
struct mlx4_en_port_profile new_prof;
94+
struct mlx4_en_priv *tmp;
95+
int port_up = 0;
96+
int err = 0;
97+
98+
tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
99+
if (!tmp)
100+
return -ENOMEM;
101+
102+
mutex_lock(&mdev->state_lock);
103+
memcpy(&new_prof, priv->prof, sizeof(struct mlx4_en_port_profile));
104+
new_prof.num_up = (tc == 0) ? MLX4_EN_NUM_UP_LOW :
105+
MLX4_EN_NUM_UP_HIGH;
106+
new_prof.tx_ring_num[TX] = new_prof.num_tx_rings_p_up *
107+
new_prof.num_up;
108+
err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof, true);
109+
if (err)
110+
goto out;
111+
112+
if (priv->port_up) {
113+
port_up = 1;
114+
mlx4_en_stop_port(dev, 1);
115+
}
116+
117+
mlx4_en_safe_replace_resources(priv, tmp);
118+
if (port_up) {
119+
err = mlx4_en_start_port(dev);
120+
if (err) {
121+
en_err(priv, "Failed starting port for setup TC\n");
122+
goto out;
123+
}
124+
}
125+
126+
err = mlx4_en_setup_tc(dev, tc);
127+
out:
128+
mutex_unlock(&mdev->state_lock);
129+
kfree(tmp);
130+
return err;
131+
}
132+
89133
static int __mlx4_en_setup_tc(struct net_device *dev, u32 handle,
90134
u32 chain_index, __be16 proto,
91135
struct tc_to_netdev *tc)
92136
{
93137
if (tc->type != TC_SETUP_MQPRIO)
94138
return -EINVAL;
95139

140+
if (tc->mqprio->num_tc && tc->mqprio->num_tc != MLX4_EN_NUM_UP_HIGH)
141+
return -EINVAL;
142+
96143
tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
97144

98-
return mlx4_en_setup_tc(dev, tc->mqprio->num_tc);
145+
return mlx4_en_alloc_tx_queue_per_tc(dev, tc->mqprio->num_tc);
99146
}
100147

101148
#ifdef CONFIG_RFS_ACCEL
@@ -2144,7 +2191,7 @@ static int mlx4_en_copy_priv(struct mlx4_en_priv *dst,
21442191

21452192
memcpy(&dst->hwtstamp_config, &prof->hwtstamp_config,
21462193
sizeof(dst->hwtstamp_config));
2147-
dst->num_tx_rings_p_up = src->mdev->profile.num_tx_rings_p_up;
2194+
dst->num_tx_rings_p_up = prof->num_tx_rings_p_up;
21482195
dst->rx_ring_num = prof->rx_ring_num;
21492196
dst->flags = prof->flags;
21502197
dst->mdev = src->mdev;
@@ -2197,6 +2244,7 @@ static void mlx4_en_update_priv(struct mlx4_en_priv *dst,
21972244
dst->tx_ring[t] = src->tx_ring[t];
21982245
dst->tx_cq[t] = src->tx_cq[t];
21992246
}
2247+
dst->num_tx_rings_p_up = src->num_tx_rings_p_up;
22002248
dst->rx_ring_num = src->rx_ring_num;
22012249
memcpy(dst->prof, src->prof, sizeof(struct mlx4_en_port_profile));
22022250
}
@@ -2780,7 +2828,7 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog)
27802828
if (priv->tx_ring_num[TX] + xdp_ring_num > MAX_TX_RINGS) {
27812829
tx_changed = 1;
27822830
new_prof.tx_ring_num[TX] =
2783-
MAX_TX_RINGS - ALIGN(xdp_ring_num, MLX4_EN_NUM_UP);
2831+
MAX_TX_RINGS - ALIGN(xdp_ring_num, priv->prof->num_up);
27842832
en_warn(priv, "Reducing the number of TX rings, to not exceed the max total rings number.\n");
27852833
}
27862834

@@ -3271,7 +3319,7 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
32713319
priv->flags |= MLX4_EN_DCB_ENABLED;
32723320
priv->cee_config.pfc_state = false;
32733321

3274-
for (i = 0; i < MLX4_EN_NUM_UP; i++)
3322+
for (i = 0; i < MLX4_EN_NUM_UP_HIGH; i++)
32753323
priv->cee_config.dcb_pfc[i] = pfc_disabled;
32763324

32773325
if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETS_CFG) {

drivers/net/ethernet/mellanox/mlx4/en_resources.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ void mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
6363
context->local_qpn = cpu_to_be32(qpn);
6464
context->pri_path.ackto = 1 & 0x07;
6565
context->pri_path.sched_queue = 0x83 | (priv->port - 1) << 6;
66-
if (user_prio >= 0) {
66+
/* force user priority per tx ring */
67+
if (user_prio >= 0 && priv->prof->num_up == MLX4_EN_NUM_UP_HIGH) {
6768
context->pri_path.sched_queue |= user_prio << 3;
6869
context->pri_path.feup = MLX4_FEUP_FORCE_ETH_UP;
6970
}

drivers/net/ethernet/mellanox/mlx4/en_tx.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -691,15 +691,11 @@ u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,
691691
{
692692
struct mlx4_en_priv *priv = netdev_priv(dev);
693693
u16 rings_p_up = priv->num_tx_rings_p_up;
694-
u8 up = 0;
695694

696695
if (netdev_get_num_tc(dev))
697696
return skb_tx_hash(dev, skb);
698697

699-
if (skb_vlan_tag_present(skb))
700-
up = skb_vlan_tag_get(skb) >> VLAN_PRIO_SHIFT;
701-
702-
return fallback(dev, skb) % rings_p_up + up * rings_p_up;
698+
return fallback(dev, skb) % rings_p_up;
703699
}
704700

705701
static void mlx4_bf_copy(void __iomem *dst, const void *src,

drivers/net/ethernet/mellanox/mlx4/mlx4_en.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@
115115
#define MLX4_EN_SMALL_PKT_SIZE 64
116116
#define MLX4_EN_MIN_TX_RING_P_UP 1
117117
#define MLX4_EN_MAX_TX_RING_P_UP 32
118-
#define MLX4_EN_NUM_UP 8
118+
#define MLX4_EN_NUM_UP_LOW 1
119+
#define MLX4_EN_NUM_UP_HIGH 8
119120
#define MLX4_EN_DEF_RX_RING_SIZE 1024
120121
#define MLX4_EN_DEF_TX_RING_SIZE MLX4_EN_DEF_RX_RING_SIZE
121122
#define MAX_TX_RINGS (MLX4_EN_MAX_TX_RING_P_UP * \
122-
MLX4_EN_NUM_UP)
123+
MLX4_EN_NUM_UP_HIGH)
123124

124125
#define MLX4_EN_DEFAULT_TX_WORK 256
125126

@@ -386,6 +387,7 @@ struct mlx4_en_port_profile {
386387
u8 rx_ppp;
387388
u8 tx_pause;
388389
u8 tx_ppp;
390+
u8 num_up;
389391
int rss_rings;
390392
int inline_thold;
391393
struct hwtstamp_config hwtstamp_config;
@@ -485,7 +487,7 @@ enum dcb_pfc_type {
485487

486488
struct mlx4_en_cee_config {
487489
bool pfc_state;
488-
enum dcb_pfc_type dcb_pfc[MLX4_EN_NUM_UP];
490+
enum dcb_pfc_type dcb_pfc[MLX4_EN_NUM_UP_HIGH];
489491
};
490492
#endif
491493

@@ -761,6 +763,7 @@ extern const struct dcbnl_rtnl_ops mlx4_en_dcbnl_pfc_ops;
761763
#endif
762764

763765
int mlx4_en_setup_tc(struct net_device *dev, u8 up);
766+
int mlx4_en_alloc_tx_queue_per_tc(struct net_device *dev, u8 tc);
764767

765768
#ifdef CONFIG_RFS_ACCEL
766769
void mlx4_en_cleanup_filters(struct mlx4_en_priv *priv);

0 commit comments

Comments
 (0)