Skip to content

Commit e6c2950

Browse files
committed
Merge branch 'eliminate-config_nr_cpus-dependency-in-dpaa-eth-and-enable-compile_test-in-fsl_qbman'
Vladimir Oltean says: ==================== Eliminate CONFIG_NR_CPUS dependency in dpaa-eth and enable COMPILE_TEST in fsl_qbman Breno's previous attempt at enabling COMPILE_TEST for the fsl_qbman driver (now included here as patch 5/5) triggered compilation warnings for large CONFIG_NR_CPUS values: https://lore.kernel.org/all/[email protected]/ Patch 1/5 switches two NR_CPUS arrays in the dpaa-eth driver to dynamic allocation to avoid that warning. There is more NR_CPUS usage in the fsl-qbman driver, but that looks relatively harmless and I couldn't find a good reason to change it. I noticed, while testing, that the driver doesn't actually work properly with high CONFIG_NR_CPUS values, and patch 2/5 addresses that. During code analysis, I have identified two places which treat conditions that can never happen. Patches 3/5 and 4/5 simplify the probing code - dpaa_fq_setup() - just a little bit. Finally we have at 5/5 the patch that triggered all of this. There is an okay from Herbert to take it via netdev, despite it being on soc/qbman: https://lore.kernel.org/all/Zns%[email protected]/ Link to v1: https://lore.kernel.org/netdev/[email protected]/ ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 62fdd17 + 782fe08 commit e6c2950

File tree

4 files changed

+69
-39
lines changed

4 files changed

+69
-39
lines changed

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ static int dpaa_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
371371
void *type_data)
372372
{
373373
struct dpaa_priv *priv = netdev_priv(net_dev);
374+
int num_txqs_per_tc = dpaa_num_txqs_per_tc();
374375
struct tc_mqprio_qopt *mqprio = type_data;
375376
u8 num_tc;
376377
int i;
@@ -398,12 +399,12 @@ static int dpaa_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
398399
netdev_set_num_tc(net_dev, num_tc);
399400

400401
for (i = 0; i < num_tc; i++)
401-
netdev_set_tc_queue(net_dev, i, DPAA_TC_TXQ_NUM,
402-
i * DPAA_TC_TXQ_NUM);
402+
netdev_set_tc_queue(net_dev, i, num_txqs_per_tc,
403+
i * num_txqs_per_tc);
403404

404405
out:
405406
priv->num_tc = num_tc ? : 1;
406-
netif_set_real_num_tx_queues(net_dev, priv->num_tc * DPAA_TC_TXQ_NUM);
407+
netif_set_real_num_tx_queues(net_dev, priv->num_tc * num_txqs_per_tc);
407408
return 0;
408409
}
409410

@@ -649,7 +650,7 @@ static inline void dpaa_assign_wq(struct dpaa_fq *fq, int idx)
649650
fq->wq = 6;
650651
break;
651652
case FQ_TYPE_TX:
652-
switch (idx / DPAA_TC_TXQ_NUM) {
653+
switch (idx / dpaa_num_txqs_per_tc()) {
653654
case 0:
654655
/* Low priority (best effort) */
655656
fq->wq = 6;
@@ -667,8 +668,8 @@ static inline void dpaa_assign_wq(struct dpaa_fq *fq, int idx)
667668
fq->wq = 0;
668669
break;
669670
default:
670-
WARN(1, "Too many TX FQs: more than %d!\n",
671-
DPAA_ETH_TXQ_NUM);
671+
WARN(1, "Too many TX FQs: more than %zu!\n",
672+
dpaa_max_num_txqs());
672673
}
673674
break;
674675
default:
@@ -740,7 +741,8 @@ static int dpaa_alloc_all_fqs(struct device *dev, struct list_head *list,
740741

741742
port_fqs->rx_pcdq = &dpaa_fq[0];
742743

743-
if (!dpaa_fq_alloc(dev, 0, DPAA_ETH_TXQ_NUM, list, FQ_TYPE_TX_CONF_MQ))
744+
if (!dpaa_fq_alloc(dev, 0, dpaa_max_num_txqs(), list,
745+
FQ_TYPE_TX_CONF_MQ))
744746
goto fq_alloc_failed;
745747

746748
dpaa_fq = dpaa_fq_alloc(dev, 0, 1, list, FQ_TYPE_TX_ERROR);
@@ -755,7 +757,7 @@ static int dpaa_alloc_all_fqs(struct device *dev, struct list_head *list,
755757

756758
port_fqs->tx_defq = &dpaa_fq[0];
757759

758-
if (!dpaa_fq_alloc(dev, 0, DPAA_ETH_TXQ_NUM, list, FQ_TYPE_TX))
760+
if (!dpaa_fq_alloc(dev, 0, dpaa_max_num_txqs(), list, FQ_TYPE_TX))
759761
goto fq_alloc_failed;
760762

761763
return 0;
@@ -931,14 +933,18 @@ static inline void dpaa_setup_egress(const struct dpaa_priv *priv,
931933
}
932934
}
933935

934-
static void dpaa_fq_setup(struct dpaa_priv *priv,
935-
const struct dpaa_fq_cbs *fq_cbs,
936-
struct fman_port *tx_port)
936+
static int dpaa_fq_setup(struct dpaa_priv *priv,
937+
const struct dpaa_fq_cbs *fq_cbs,
938+
struct fman_port *tx_port)
937939
{
938940
int egress_cnt = 0, conf_cnt = 0, num_portals = 0, portal_cnt = 0, cpu;
939941
const cpumask_t *affine_cpus = qman_affine_cpus();
940-
u16 channels[NR_CPUS];
941942
struct dpaa_fq *fq;
943+
u16 *channels;
944+
945+
channels = kcalloc(num_possible_cpus(), sizeof(u16), GFP_KERNEL);
946+
if (!channels)
947+
return -ENOMEM;
942948

943949
for_each_cpu_and(cpu, affine_cpus, cpu_online_mask)
944950
channels[num_portals++] = qman_affine_channel(cpu);
@@ -965,11 +971,7 @@ static void dpaa_fq_setup(struct dpaa_priv *priv,
965971
case FQ_TYPE_TX:
966972
dpaa_setup_egress(priv, fq, tx_port,
967973
&fq_cbs->egress_ern);
968-
/* If we have more Tx queues than the number of cores,
969-
* just ignore the extra ones.
970-
*/
971-
if (egress_cnt < DPAA_ETH_TXQ_NUM)
972-
priv->egress_fqs[egress_cnt++] = &fq->fq_base;
974+
priv->egress_fqs[egress_cnt++] = &fq->fq_base;
973975
break;
974976
case FQ_TYPE_TX_CONF_MQ:
975977
priv->conf_fqs[conf_cnt++] = &fq->fq_base;
@@ -987,24 +989,17 @@ static void dpaa_fq_setup(struct dpaa_priv *priv,
987989
}
988990
}
989991

990-
/* Make sure all CPUs receive a corresponding Tx queue. */
991-
while (egress_cnt < DPAA_ETH_TXQ_NUM) {
992-
list_for_each_entry(fq, &priv->dpaa_fq_list, list) {
993-
if (fq->fq_type != FQ_TYPE_TX)
994-
continue;
995-
priv->egress_fqs[egress_cnt++] = &fq->fq_base;
996-
if (egress_cnt == DPAA_ETH_TXQ_NUM)
997-
break;
998-
}
999-
}
992+
kfree(channels);
993+
994+
return 0;
1000995
}
1001996

1002997
static inline int dpaa_tx_fq_to_id(const struct dpaa_priv *priv,
1003998
struct qman_fq *tx_fq)
1004999
{
10051000
int i;
10061001

1007-
for (i = 0; i < DPAA_ETH_TXQ_NUM; i++)
1002+
for (i = 0; i < dpaa_max_num_txqs(); i++)
10081003
if (priv->egress_fqs[i] == tx_fq)
10091004
return i;
10101005

@@ -3324,7 +3319,7 @@ static int dpaa_eth_probe(struct platform_device *pdev)
33243319
/* Allocate this early, so we can store relevant information in
33253320
* the private area
33263321
*/
3327-
net_dev = alloc_etherdev_mq(sizeof(*priv), DPAA_ETH_TXQ_NUM);
3322+
net_dev = alloc_etherdev_mq(sizeof(*priv), dpaa_max_num_txqs());
33283323
if (!net_dev) {
33293324
dev_err(dev, "alloc_etherdev_mq() failed\n");
33303325
return -ENOMEM;
@@ -3339,6 +3334,22 @@ static int dpaa_eth_probe(struct platform_device *pdev)
33393334

33403335
priv->msg_enable = netif_msg_init(debug, DPAA_MSG_DEFAULT);
33413336

3337+
priv->egress_fqs = devm_kcalloc(dev, dpaa_max_num_txqs(),
3338+
sizeof(*priv->egress_fqs),
3339+
GFP_KERNEL);
3340+
if (!priv->egress_fqs) {
3341+
err = -ENOMEM;
3342+
goto free_netdev;
3343+
}
3344+
3345+
priv->conf_fqs = devm_kcalloc(dev, dpaa_max_num_txqs(),
3346+
sizeof(*priv->conf_fqs),
3347+
GFP_KERNEL);
3348+
if (!priv->conf_fqs) {
3349+
err = -ENOMEM;
3350+
goto free_netdev;
3351+
}
3352+
33423353
mac_dev = dpaa_mac_dev_get(pdev);
33433354
if (IS_ERR(mac_dev)) {
33443355
netdev_err(net_dev, "dpaa_mac_dev_get() failed\n");
@@ -3416,7 +3427,9 @@ static int dpaa_eth_probe(struct platform_device *pdev)
34163427
*/
34173428
dpaa_eth_add_channel(priv->channel, &pdev->dev);
34183429

3419-
dpaa_fq_setup(priv, &dpaa_fq_cbs, priv->mac_dev->port[TX]);
3430+
err = dpaa_fq_setup(priv, &dpaa_fq_cbs, priv->mac_dev->port[TX]);
3431+
if (err)
3432+
goto free_dpaa_bps;
34203433

34213434
/* Create a congestion group for this netdev, with
34223435
* dynamically-allocated CGR ID.
@@ -3462,7 +3475,8 @@ static int dpaa_eth_probe(struct platform_device *pdev)
34623475
}
34633476

34643477
priv->num_tc = 1;
3465-
netif_set_real_num_tx_queues(net_dev, priv->num_tc * DPAA_TC_TXQ_NUM);
3478+
netif_set_real_num_tx_queues(net_dev,
3479+
priv->num_tc * dpaa_num_txqs_per_tc());
34663480

34673481
/* Initialize NAPI */
34683482
err = dpaa_napi_add(net_dev);

drivers/net/ethernet/freescale/dpaa/dpaa_eth.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818

1919
/* Number of prioritised traffic classes */
2020
#define DPAA_TC_NUM 4
21-
/* Number of Tx queues per traffic class */
22-
#define DPAA_TC_TXQ_NUM NR_CPUS
23-
/* Total number of Tx queues */
24-
#define DPAA_ETH_TXQ_NUM (DPAA_TC_NUM * DPAA_TC_TXQ_NUM)
2521

2622
/* More detailed FQ types - used for fine-grained WQ assignments */
2723
enum dpaa_fq_type {
@@ -142,8 +138,8 @@ struct dpaa_priv {
142138
struct mac_device *mac_dev;
143139
struct device *rx_dma_dev;
144140
struct device *tx_dma_dev;
145-
struct qman_fq *egress_fqs[DPAA_ETH_TXQ_NUM];
146-
struct qman_fq *conf_fqs[DPAA_ETH_TXQ_NUM];
141+
struct qman_fq **egress_fqs;
142+
struct qman_fq **conf_fqs;
147143

148144
u16 channel;
149145
struct list_head dpaa_fq_list;
@@ -185,4 +181,16 @@ extern const struct ethtool_ops dpaa_ethtool_ops;
185181
/* from dpaa_eth_sysfs.c */
186182
void dpaa_eth_sysfs_remove(struct device *dev);
187183
void dpaa_eth_sysfs_init(struct device *dev);
184+
185+
static inline size_t dpaa_num_txqs_per_tc(void)
186+
{
187+
return num_possible_cpus();
188+
}
189+
190+
/* Total number of Tx queues */
191+
static inline size_t dpaa_max_num_txqs(void)
192+
{
193+
return DPAA_TC_NUM * dpaa_num_txqs_per_tc();
194+
}
195+
188196
#endif /* __DPAA_H */

drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,16 @@ static int dpaa_set_coalesce(struct net_device *dev,
457457
struct netlink_ext_ack *extack)
458458
{
459459
const cpumask_t *cpus = qman_affine_cpus();
460-
bool needs_revert[NR_CPUS] = {false};
461460
struct qman_portal *portal;
462461
u32 period, prev_period;
463462
u8 thresh, prev_thresh;
463+
bool *needs_revert;
464464
int cpu, res;
465465

466+
needs_revert = kcalloc(num_possible_cpus(), sizeof(bool), GFP_KERNEL);
467+
if (!needs_revert)
468+
return -ENOMEM;
469+
466470
period = c->rx_coalesce_usecs;
467471
thresh = c->rx_max_coalesced_frames;
468472

@@ -485,6 +489,8 @@ static int dpaa_set_coalesce(struct net_device *dev,
485489
needs_revert[cpu] = true;
486490
}
487491

492+
kfree(needs_revert);
493+
488494
return 0;
489495

490496
revert_values:
@@ -498,6 +504,8 @@ static int dpaa_set_coalesce(struct net_device *dev,
498504
qman_dqrr_set_ithresh(portal, prev_thresh);
499505
}
500506

507+
kfree(needs_revert);
508+
501509
return res;
502510
}
503511

drivers/soc/fsl/qbman/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
menuconfig FSL_DPAA
33
bool "QorIQ DPAA1 framework support"
4-
depends on ((FSL_SOC_BOOKE || ARCH_LAYERSCAPE) && ARCH_DMA_ADDR_T_64BIT)
4+
depends on ((FSL_SOC_BOOKE || ARCH_LAYERSCAPE || COMPILE_TEST) && ARCH_DMA_ADDR_T_64BIT)
55
select GENERIC_ALLOCATOR
66
help
77
The Freescale Data Path Acceleration Architecture (DPAA) is a set of

0 commit comments

Comments
 (0)