Skip to content

Commit be27b89

Browse files
xiaoleiwang123456kuba-moo
authored andcommitted
net: stmmac: replace priv->speed with the portTransmitRate from the tc-cbs parameters
The current cbs parameter depends on speed after uplinking, which is not needed and will report a configuration error if the port is not initially connected. The UAPI exposed by tc-cbs requires userspace to recalculate the send slope anyway, because the formula depends on port_transmit_rate (see man tc-cbs), which is not an invariant from tc's perspective. Therefore, we use offload->sendslope and offload->idleslope to derive the original port_transmit_rate from the CBS formula. Fixes: 1f705bc ("net: stmmac: Add support for CBS QDISC") Signed-off-by: Xiaolei Wang <[email protected]> Reviewed-by: Wojciech Drewek <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 1b9f756 commit be27b89

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ static int tc_setup_cbs(struct stmmac_priv *priv,
343343
struct tc_cbs_qopt_offload *qopt)
344344
{
345345
u32 tx_queues_count = priv->plat->tx_queues_to_use;
346+
s64 port_transmit_rate_kbps;
346347
u32 queue = qopt->queue;
347-
u32 ptr, speed_div;
348348
u32 mode_to_use;
349349
u64 value;
350+
u32 ptr;
350351
int ret;
351352

352353
/* Queue 0 is not AVB capable */
@@ -355,30 +356,26 @@ static int tc_setup_cbs(struct stmmac_priv *priv,
355356
if (!priv->dma_cap.av)
356357
return -EOPNOTSUPP;
357358

359+
port_transmit_rate_kbps = qopt->idleslope - qopt->sendslope;
360+
358361
/* Port Transmit Rate and Speed Divider */
359-
switch (priv->speed) {
362+
switch (div_s64(port_transmit_rate_kbps, 1000)) {
360363
case SPEED_10000:
361-
ptr = 32;
362-
speed_div = 10000000;
363-
break;
364364
case SPEED_5000:
365365
ptr = 32;
366-
speed_div = 5000000;
367366
break;
368367
case SPEED_2500:
369-
ptr = 8;
370-
speed_div = 2500000;
371-
break;
372368
case SPEED_1000:
373369
ptr = 8;
374-
speed_div = 1000000;
375370
break;
376371
case SPEED_100:
377372
ptr = 4;
378-
speed_div = 100000;
379373
break;
380374
default:
381-
return -EOPNOTSUPP;
375+
netdev_err(priv->dev,
376+
"Invalid portTransmitRate %lld (idleSlope - sendSlope)\n",
377+
port_transmit_rate_kbps);
378+
return -EINVAL;
382379
}
383380

384381
mode_to_use = priv->plat->tx_queues_cfg[queue].mode_to_use;
@@ -398,10 +395,10 @@ static int tc_setup_cbs(struct stmmac_priv *priv,
398395
}
399396

400397
/* Final adjustments for HW */
401-
value = div_s64(qopt->idleslope * 1024ll * ptr, speed_div);
398+
value = div_s64(qopt->idleslope * 1024ll * ptr, port_transmit_rate_kbps);
402399
priv->plat->tx_queues_cfg[queue].idle_slope = value & GENMASK(31, 0);
403400

404-
value = div_s64(-qopt->sendslope * 1024ll * ptr, speed_div);
401+
value = div_s64(-qopt->sendslope * 1024ll * ptr, port_transmit_rate_kbps);
405402
priv->plat->tx_queues_cfg[queue].send_slope = value & GENMASK(31, 0);
406403

407404
value = qopt->hicredit * 1024ll * 8;

0 commit comments

Comments
 (0)