Skip to content

Commit a92f4f0

Browse files
bijudasdavem330
authored andcommitted
ravb: Add nc_queue to struct ravb_hw_info
R-Car supports network control queue whereas RZ/G2L does not support it. Add nc_queue to struct ravb_hw_info, so that NC queue is handled only by R-Car. This patch also renames ravb_rcar_dmac_init to ravb_dmac_init_rcar to be consistent with the naming convention used in sh_eth driver. Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2b061b5 commit a92f4f0

File tree

2 files changed

+94
-49
lines changed

2 files changed

+94
-49
lines changed

drivers/net/ethernet/renesas/ravb.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ struct ravb_hw_info {
986986
bool (*receive)(struct net_device *ndev, int *quota, int q);
987987
void (*set_rate)(struct net_device *ndev);
988988
int (*set_feature)(struct net_device *ndev, netdev_features_t features);
989-
void (*dmac_init)(struct net_device *ndev);
989+
int (*dmac_init)(struct net_device *ndev);
990990
void (*emac_init)(struct net_device *ndev);
991991
const char (*gstrings_stats)[ETH_GSTRING_LEN];
992992
size_t gstrings_size;
@@ -1002,6 +1002,7 @@ struct ravb_hw_info {
10021002
unsigned multi_irqs:1; /* AVB-DMAC and E-MAC has multiple irqs */
10031003
unsigned gptp:1; /* AVB-DMAC has gPTP support */
10041004
unsigned ccc_gac:1; /* AVB-DMAC has gPTP support active in config mode */
1005+
unsigned nc_queue:1; /* AVB-DMAC has NC queue */
10051006
};
10061007

10071008
struct ravb_private {

drivers/net/ethernet/renesas/ravb_main.c

Lines changed: 92 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,24 @@ static void ravb_emac_init(struct net_device *ndev)
461461
info->emac_init(ndev);
462462
}
463463

464-
static void ravb_rcar_dmac_init(struct net_device *ndev)
464+
static int ravb_dmac_init_rcar(struct net_device *ndev)
465465
{
466466
struct ravb_private *priv = netdev_priv(ndev);
467467
const struct ravb_hw_info *info = priv->info;
468+
int error;
469+
470+
error = ravb_ring_init(ndev, RAVB_BE);
471+
if (error)
472+
return error;
473+
error = ravb_ring_init(ndev, RAVB_NC);
474+
if (error) {
475+
ravb_ring_free(ndev, RAVB_BE);
476+
return error;
477+
}
478+
479+
/* Descriptor format */
480+
ravb_ring_format(ndev, RAVB_BE);
481+
ravb_ring_format(ndev, RAVB_NC);
468482

469483
/* Set AVB RX */
470484
ravb_write(ndev,
@@ -491,6 +505,8 @@ static void ravb_rcar_dmac_init(struct net_device *ndev)
491505
ravb_write(ndev, RIC2_QFE0 | RIC2_QFE1 | RIC2_RFFE, RIC2);
492506
/* Frame transmitted, timestamp FIFO updated */
493507
ravb_write(ndev, TIC_FTE0 | TIC_FTE1 | TIC_TFUE, TIC);
508+
509+
return 0;
494510
}
495511

496512
/* Device init function for Ethernet AVB */
@@ -505,20 +521,9 @@ static int ravb_dmac_init(struct net_device *ndev)
505521
if (error)
506522
return error;
507523

508-
error = ravb_ring_init(ndev, RAVB_BE);
524+
error = info->dmac_init(ndev);
509525
if (error)
510526
return error;
511-
error = ravb_ring_init(ndev, RAVB_NC);
512-
if (error) {
513-
ravb_ring_free(ndev, RAVB_BE);
514-
return error;
515-
}
516-
517-
/* Descriptor format */
518-
ravb_ring_format(ndev, RAVB_BE);
519-
ravb_ring_format(ndev, RAVB_NC);
520-
521-
info->dmac_init(ndev);
522527

523528
/* Setting the control will start the AVB-DMAC process. */
524529
ravb_modify(ndev, CCC, CCC_OPC, CCC_OPC_OPERATION);
@@ -859,6 +864,7 @@ static irqreturn_t ravb_interrupt(int irq, void *dev_id)
859864
{
860865
struct net_device *ndev = dev_id;
861866
struct ravb_private *priv = netdev_priv(ndev);
867+
const struct ravb_hw_info *info = priv->info;
862868
irqreturn_t result = IRQ_NONE;
863869
u32 iss;
864870

@@ -875,8 +881,13 @@ static irqreturn_t ravb_interrupt(int irq, void *dev_id)
875881
result = IRQ_HANDLED;
876882

877883
/* Network control and best effort queue RX/TX */
878-
for (q = RAVB_NC; q >= RAVB_BE; q--) {
879-
if (ravb_queue_interrupt(ndev, q))
884+
if (info->nc_queue) {
885+
for (q = RAVB_NC; q >= RAVB_BE; q--) {
886+
if (ravb_queue_interrupt(ndev, q))
887+
result = IRQ_HANDLED;
888+
}
889+
} else {
890+
if (ravb_queue_interrupt(ndev, RAVB_BE))
880891
result = IRQ_HANDLED;
881892
}
882893
}
@@ -1000,7 +1011,8 @@ static int ravb_poll(struct napi_struct *napi, int budget)
10001011

10011012
/* Receive error message handling */
10021013
priv->rx_over_errors = priv->stats[RAVB_BE].rx_over_errors;
1003-
priv->rx_over_errors += priv->stats[RAVB_NC].rx_over_errors;
1014+
if (info->nc_queue)
1015+
priv->rx_over_errors += priv->stats[RAVB_NC].rx_over_errors;
10041016
if (priv->rx_over_errors != ndev->stats.rx_over_errors)
10051017
ndev->stats.rx_over_errors = priv->rx_over_errors;
10061018
if (priv->rx_fifo_errors != ndev->stats.rx_fifo_errors)
@@ -1208,11 +1220,14 @@ static void ravb_get_ethtool_stats(struct net_device *ndev,
12081220
struct ethtool_stats *estats, u64 *data)
12091221
{
12101222
struct ravb_private *priv = netdev_priv(ndev);
1223+
const struct ravb_hw_info *info = priv->info;
1224+
int num_rx_q;
12111225
int i = 0;
12121226
int q;
12131227

1228+
num_rx_q = info->nc_queue ? NUM_RX_QUEUE : 1;
12141229
/* Device-specific stats */
1215-
for (q = RAVB_BE; q < NUM_RX_QUEUE; q++) {
1230+
for (q = RAVB_BE; q < num_rx_q; q++) {
12161231
struct net_device_stats *stats = &priv->stats[q];
12171232

12181233
data[i++] = priv->cur_rx[q];
@@ -1287,7 +1302,8 @@ static int ravb_set_ringparam(struct net_device *ndev,
12871302

12881303
/* Free all the skb's in the RX queue and the DMA buffers. */
12891304
ravb_ring_free(ndev, RAVB_BE);
1290-
ravb_ring_free(ndev, RAVB_NC);
1305+
if (info->nc_queue)
1306+
ravb_ring_free(ndev, RAVB_NC);
12911307
}
12921308

12931309
/* Set new parameters */
@@ -1403,7 +1419,8 @@ static int ravb_open(struct net_device *ndev)
14031419
int error;
14041420

14051421
napi_enable(&priv->napi[RAVB_BE]);
1406-
napi_enable(&priv->napi[RAVB_NC]);
1422+
if (info->nc_queue)
1423+
napi_enable(&priv->napi[RAVB_NC]);
14071424

14081425
if (!info->multi_irqs) {
14091426
error = request_irq(ndev->irq, ravb_interrupt, IRQF_SHARED,
@@ -1477,7 +1494,8 @@ static int ravb_open(struct net_device *ndev)
14771494
out_free_irq:
14781495
free_irq(ndev->irq, ndev);
14791496
out_napi_off:
1480-
napi_disable(&priv->napi[RAVB_NC]);
1497+
if (info->nc_queue)
1498+
napi_disable(&priv->napi[RAVB_NC]);
14811499
napi_disable(&priv->napi[RAVB_BE]);
14821500
return error;
14831501
}
@@ -1526,7 +1544,8 @@ static void ravb_tx_timeout_work(struct work_struct *work)
15261544
}
15271545

15281546
ravb_ring_free(ndev, RAVB_BE);
1529-
ravb_ring_free(ndev, RAVB_NC);
1547+
if (info->nc_queue)
1548+
ravb_ring_free(ndev, RAVB_NC);
15301549

15311550
/* Device init */
15321551
error = ravb_dmac_init(ndev);
@@ -1698,28 +1717,38 @@ static struct net_device_stats *ravb_get_stats(struct net_device *ndev)
16981717

16991718
nstats = &ndev->stats;
17001719
stats0 = &priv->stats[RAVB_BE];
1701-
stats1 = &priv->stats[RAVB_NC];
17021720

17031721
if (info->tx_counters) {
17041722
nstats->tx_dropped += ravb_read(ndev, TROCR);
17051723
ravb_write(ndev, 0, TROCR); /* (write clear) */
17061724
}
17071725

1708-
nstats->rx_packets = stats0->rx_packets + stats1->rx_packets;
1709-
nstats->tx_packets = stats0->tx_packets + stats1->tx_packets;
1710-
nstats->rx_bytes = stats0->rx_bytes + stats1->rx_bytes;
1711-
nstats->tx_bytes = stats0->tx_bytes + stats1->tx_bytes;
1712-
nstats->multicast = stats0->multicast + stats1->multicast;
1713-
nstats->rx_errors = stats0->rx_errors + stats1->rx_errors;
1714-
nstats->rx_crc_errors = stats0->rx_crc_errors + stats1->rx_crc_errors;
1715-
nstats->rx_frame_errors =
1716-
stats0->rx_frame_errors + stats1->rx_frame_errors;
1717-
nstats->rx_length_errors =
1718-
stats0->rx_length_errors + stats1->rx_length_errors;
1719-
nstats->rx_missed_errors =
1720-
stats0->rx_missed_errors + stats1->rx_missed_errors;
1721-
nstats->rx_over_errors =
1722-
stats0->rx_over_errors + stats1->rx_over_errors;
1726+
nstats->rx_packets = stats0->rx_packets;
1727+
nstats->tx_packets = stats0->tx_packets;
1728+
nstats->rx_bytes = stats0->rx_bytes;
1729+
nstats->tx_bytes = stats0->tx_bytes;
1730+
nstats->multicast = stats0->multicast;
1731+
nstats->rx_errors = stats0->rx_errors;
1732+
nstats->rx_crc_errors = stats0->rx_crc_errors;
1733+
nstats->rx_frame_errors = stats0->rx_frame_errors;
1734+
nstats->rx_length_errors = stats0->rx_length_errors;
1735+
nstats->rx_missed_errors = stats0->rx_missed_errors;
1736+
nstats->rx_over_errors = stats0->rx_over_errors;
1737+
if (info->nc_queue) {
1738+
stats1 = &priv->stats[RAVB_NC];
1739+
1740+
nstats->rx_packets += stats1->rx_packets;
1741+
nstats->tx_packets += stats1->tx_packets;
1742+
nstats->rx_bytes += stats1->rx_bytes;
1743+
nstats->tx_bytes += stats1->tx_bytes;
1744+
nstats->multicast += stats1->multicast;
1745+
nstats->rx_errors += stats1->rx_errors;
1746+
nstats->rx_crc_errors += stats1->rx_crc_errors;
1747+
nstats->rx_frame_errors += stats1->rx_frame_errors;
1748+
nstats->rx_length_errors += stats1->rx_length_errors;
1749+
nstats->rx_missed_errors += stats1->rx_missed_errors;
1750+
nstats->rx_over_errors += stats1->rx_over_errors;
1751+
}
17231752

17241753
return nstats;
17251754
}
@@ -1784,12 +1813,14 @@ static int ravb_close(struct net_device *ndev)
17841813
}
17851814
free_irq(ndev->irq, ndev);
17861815

1787-
napi_disable(&priv->napi[RAVB_NC]);
1816+
if (info->nc_queue)
1817+
napi_disable(&priv->napi[RAVB_NC]);
17881818
napi_disable(&priv->napi[RAVB_BE]);
17891819

17901820
/* Free all the skb's in the RX queue and the DMA buffers. */
17911821
ravb_ring_free(ndev, RAVB_BE);
1792-
ravb_ring_free(ndev, RAVB_NC);
1822+
if (info->nc_queue)
1823+
ravb_ring_free(ndev, RAVB_NC);
17931824

17941825
return 0;
17951826
}
@@ -2007,7 +2038,7 @@ static const struct ravb_hw_info ravb_gen3_hw_info = {
20072038
.receive = ravb_rcar_rx,
20082039
.set_rate = ravb_set_rate,
20092040
.set_feature = ravb_set_features_rcar,
2010-
.dmac_init = ravb_rcar_dmac_init,
2041+
.dmac_init = ravb_dmac_init_rcar,
20112042
.emac_init = ravb_rcar_emac_init,
20122043
.gstrings_stats = ravb_gstrings_stats,
20132044
.gstrings_size = sizeof(ravb_gstrings_stats),
@@ -2019,6 +2050,7 @@ static const struct ravb_hw_info ravb_gen3_hw_info = {
20192050
.tx_counters = 1,
20202051
.multi_irqs = 1,
20212052
.ccc_gac = 1,
2053+
.nc_queue = 1,
20222054
};
20232055

20242056
static const struct ravb_hw_info ravb_gen2_hw_info = {
@@ -2028,7 +2060,7 @@ static const struct ravb_hw_info ravb_gen2_hw_info = {
20282060
.receive = ravb_rcar_rx,
20292061
.set_rate = ravb_set_rate,
20302062
.set_feature = ravb_set_features_rcar,
2031-
.dmac_init = ravb_rcar_dmac_init,
2063+
.dmac_init = ravb_dmac_init_rcar,
20322064
.emac_init = ravb_rcar_emac_init,
20332065
.gstrings_stats = ravb_gstrings_stats,
20342066
.gstrings_size = sizeof(ravb_gstrings_stats),
@@ -2038,6 +2070,7 @@ static const struct ravb_hw_info ravb_gen2_hw_info = {
20382070
.max_rx_len = RX_BUF_SZ + RAVB_ALIGN - 1,
20392071
.aligned_tx = 1,
20402072
.gptp = 1,
2073+
.nc_queue = 1,
20412074
};
20422075

20432076
static const struct of_device_id ravb_match_table[] = {
@@ -2192,8 +2225,11 @@ static int ravb_probe(struct platform_device *pdev)
21922225
priv->pdev = pdev;
21932226
priv->num_tx_ring[RAVB_BE] = BE_TX_RING_SIZE;
21942227
priv->num_rx_ring[RAVB_BE] = BE_RX_RING_SIZE;
2195-
priv->num_tx_ring[RAVB_NC] = NC_TX_RING_SIZE;
2196-
priv->num_rx_ring[RAVB_NC] = NC_RX_RING_SIZE;
2228+
if (info->nc_queue) {
2229+
priv->num_tx_ring[RAVB_NC] = NC_TX_RING_SIZE;
2230+
priv->num_rx_ring[RAVB_NC] = NC_RX_RING_SIZE;
2231+
}
2232+
21972233
priv->addr = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
21982234
if (IS_ERR(priv->addr)) {
21992235
error = PTR_ERR(priv->addr);
@@ -2323,7 +2359,8 @@ static int ravb_probe(struct platform_device *pdev)
23232359
}
23242360

23252361
netif_napi_add(ndev, &priv->napi[RAVB_BE], ravb_poll, 64);
2326-
netif_napi_add(ndev, &priv->napi[RAVB_NC], ravb_poll, 64);
2362+
if (info->nc_queue)
2363+
netif_napi_add(ndev, &priv->napi[RAVB_NC], ravb_poll, 64);
23272364

23282365
/* Network device register */
23292366
error = register_netdev(ndev);
@@ -2341,7 +2378,9 @@ static int ravb_probe(struct platform_device *pdev)
23412378
return 0;
23422379

23432380
out_napi_del:
2344-
netif_napi_del(&priv->napi[RAVB_NC]);
2381+
if (info->nc_queue)
2382+
netif_napi_del(&priv->napi[RAVB_NC]);
2383+
23452384
netif_napi_del(&priv->napi[RAVB_BE]);
23462385
ravb_mdio_release(priv);
23472386
out_dma_free:
@@ -2380,7 +2419,8 @@ static int ravb_remove(struct platform_device *pdev)
23802419
ravb_write(ndev, CCC_OPC_RESET, CCC);
23812420
pm_runtime_put_sync(&pdev->dev);
23822421
unregister_netdev(ndev);
2383-
netif_napi_del(&priv->napi[RAVB_NC]);
2422+
if (info->nc_queue)
2423+
netif_napi_del(&priv->napi[RAVB_NC]);
23842424
netif_napi_del(&priv->napi[RAVB_BE]);
23852425
ravb_mdio_release(priv);
23862426
pm_runtime_disable(&pdev->dev);
@@ -2394,6 +2434,7 @@ static int ravb_remove(struct platform_device *pdev)
23942434
static int ravb_wol_setup(struct net_device *ndev)
23952435
{
23962436
struct ravb_private *priv = netdev_priv(ndev);
2437+
const struct ravb_hw_info *info = priv->info;
23972438

23982439
/* Disable interrupts by clearing the interrupt masks. */
23992440
ravb_write(ndev, 0, RIC0);
@@ -2402,7 +2443,8 @@ static int ravb_wol_setup(struct net_device *ndev)
24022443

24032444
/* Only allow ECI interrupts */
24042445
synchronize_irq(priv->emac_irq);
2405-
napi_disable(&priv->napi[RAVB_NC]);
2446+
if (info->nc_queue)
2447+
napi_disable(&priv->napi[RAVB_NC]);
24062448
napi_disable(&priv->napi[RAVB_BE]);
24072449
ravb_write(ndev, ECSIPR_MPDIP, ECSIPR);
24082450

@@ -2415,9 +2457,11 @@ static int ravb_wol_setup(struct net_device *ndev)
24152457
static int ravb_wol_restore(struct net_device *ndev)
24162458
{
24172459
struct ravb_private *priv = netdev_priv(ndev);
2460+
const struct ravb_hw_info *info = priv->info;
24182461
int ret;
24192462

2420-
napi_enable(&priv->napi[RAVB_NC]);
2463+
if (info->nc_queue)
2464+
napi_enable(&priv->napi[RAVB_NC]);
24212465
napi_enable(&priv->napi[RAVB_BE]);
24222466

24232467
/* Disable MagicPacket */

0 commit comments

Comments
 (0)