Skip to content

Commit 8fa96e3

Browse files
committed
Merge branch 'systemport-tx-napi-improvements'
Florian Fainelli says: ==================== net: systemport: TX/NAPI improvements This patch series builds up on Doug's latest changes done in BCMGENET to reduce the number of spurious interrupts in NAPI, simplify pointer arithmetic and finally tracking of per TX ring statistics to be SMP friendly. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 12459cb + e9d7af7 commit 8fa96e3

2 files changed

Lines changed: 74 additions & 12 deletions

File tree

‎drivers/net/ethernet/broadcom/bcmsysport.c‎

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ static const struct bcm_sysport_stats bcm_sysport_gstrings_stats[] = {
284284
STAT_MIB_SOFT("alloc_rx_buff_failed", mib.alloc_rx_buff_failed),
285285
STAT_MIB_SOFT("rx_dma_failed", mib.rx_dma_failed),
286286
STAT_MIB_SOFT("tx_dma_failed", mib.tx_dma_failed),
287+
/* Per TX-queue statistics are dynamically appended */
287288
};
288289

289290
#define BCM_SYSPORT_STATS_LEN ARRAY_SIZE(bcm_sysport_gstrings_stats)
@@ -338,7 +339,8 @@ static int bcm_sysport_get_sset_count(struct net_device *dev, int string_set)
338339
continue;
339340
j++;
340341
}
341-
return j;
342+
/* Include per-queue statistics */
343+
return j + dev->num_tx_queues * NUM_SYSPORT_TXQ_STAT;
342344
default:
343345
return -EOPNOTSUPP;
344346
}
@@ -349,6 +351,7 @@ static void bcm_sysport_get_strings(struct net_device *dev,
349351
{
350352
struct bcm_sysport_priv *priv = netdev_priv(dev);
351353
const struct bcm_sysport_stats *s;
354+
char buf[128];
352355
int i, j;
353356

354357
switch (stringset) {
@@ -363,6 +366,18 @@ static void bcm_sysport_get_strings(struct net_device *dev,
363366
ETH_GSTRING_LEN);
364367
j++;
365368
}
369+
370+
for (i = 0; i < dev->num_tx_queues; i++) {
371+
snprintf(buf, sizeof(buf), "txq%d_packets", i);
372+
memcpy(data + j * ETH_GSTRING_LEN, buf,
373+
ETH_GSTRING_LEN);
374+
j++;
375+
376+
snprintf(buf, sizeof(buf), "txq%d_bytes", i);
377+
memcpy(data + j * ETH_GSTRING_LEN, buf,
378+
ETH_GSTRING_LEN);
379+
j++;
380+
}
366381
break;
367382
default:
368383
break;
@@ -418,6 +433,7 @@ static void bcm_sysport_get_stats(struct net_device *dev,
418433
struct ethtool_stats *stats, u64 *data)
419434
{
420435
struct bcm_sysport_priv *priv = netdev_priv(dev);
436+
struct bcm_sysport_tx_ring *ring;
421437
int i, j;
422438

423439
if (netif_running(dev))
@@ -436,6 +452,22 @@ static void bcm_sysport_get_stats(struct net_device *dev,
436452
data[j] = *(unsigned long *)p;
437453
j++;
438454
}
455+
456+
/* For SYSTEMPORT Lite since we have holes in our statistics, j would
457+
* be equal to BCM_SYSPORT_STATS_LEN at the end of the loop, but it
458+
* needs to point to how many total statistics we have minus the
459+
* number of per TX queue statistics
460+
*/
461+
j = bcm_sysport_get_sset_count(dev, ETH_SS_STATS) -
462+
dev->num_tx_queues * NUM_SYSPORT_TXQ_STAT;
463+
464+
for (i = 0; i < dev->num_tx_queues; i++) {
465+
ring = &priv->tx_rings[i];
466+
data[j] = ring->packets;
467+
j++;
468+
data[j] = ring->bytes;
469+
j++;
470+
}
439471
}
440472

441473
static void bcm_sysport_get_wol(struct net_device *dev,
@@ -637,6 +669,9 @@ static unsigned int bcm_sysport_desc_rx(struct bcm_sysport_priv *priv,
637669
u16 len, status;
638670
struct bcm_rsb *rsb;
639671

672+
/* Clear status before servicing to reduce spurious interrupts */
673+
intrl2_0_writel(priv, INTRL2_0_RDMA_MBDONE, INTRL2_CPU_CLEAR);
674+
640675
/* Determine how much we should process since last call, SYSTEMPORT Lite
641676
* groups the producer and consumer indexes into the same 32-bit
642677
* which we access using RDMA_CONS_INDEX
@@ -647,11 +682,7 @@ static unsigned int bcm_sysport_desc_rx(struct bcm_sysport_priv *priv,
647682
p_index = rdma_readl(priv, RDMA_CONS_INDEX);
648683
p_index &= RDMA_PROD_INDEX_MASK;
649684

650-
if (p_index < priv->rx_c_index)
651-
to_process = (RDMA_CONS_INDEX_MASK + 1) -
652-
priv->rx_c_index + p_index;
653-
else
654-
to_process = p_index - priv->rx_c_index;
685+
to_process = (p_index - priv->rx_c_index) & RDMA_CONS_INDEX_MASK;
655686

656687
netif_dbg(priv, rx_status, ndev,
657688
"p_index=%d rx_c_index=%d to_process=%d\n",
@@ -746,26 +777,26 @@ static unsigned int bcm_sysport_desc_rx(struct bcm_sysport_priv *priv,
746777
return processed;
747778
}
748779

749-
static void bcm_sysport_tx_reclaim_one(struct bcm_sysport_priv *priv,
780+
static void bcm_sysport_tx_reclaim_one(struct bcm_sysport_tx_ring *ring,
750781
struct bcm_sysport_cb *cb,
751782
unsigned int *bytes_compl,
752783
unsigned int *pkts_compl)
753784
{
785+
struct bcm_sysport_priv *priv = ring->priv;
754786
struct device *kdev = &priv->pdev->dev;
755-
struct net_device *ndev = priv->netdev;
756787

757788
if (cb->skb) {
758-
ndev->stats.tx_bytes += cb->skb->len;
789+
ring->bytes += cb->skb->len;
759790
*bytes_compl += cb->skb->len;
760791
dma_unmap_single(kdev, dma_unmap_addr(cb, dma_addr),
761792
dma_unmap_len(cb, dma_len),
762793
DMA_TO_DEVICE);
763-
ndev->stats.tx_packets++;
794+
ring->packets++;
764795
(*pkts_compl)++;
765796
bcm_sysport_free_cb(cb);
766797
/* SKB fragment */
767798
} else if (dma_unmap_addr(cb, dma_addr)) {
768-
ndev->stats.tx_bytes += dma_unmap_len(cb, dma_len);
799+
ring->bytes += dma_unmap_len(cb, dma_len);
769800
dma_unmap_page(kdev, dma_unmap_addr(cb, dma_addr),
770801
dma_unmap_len(cb, dma_len), DMA_TO_DEVICE);
771802
dma_unmap_addr_set(cb, dma_addr, 0);
@@ -782,6 +813,13 @@ static unsigned int __bcm_sysport_tx_reclaim(struct bcm_sysport_priv *priv,
782813
struct bcm_sysport_cb *cb;
783814
u32 hw_ind;
784815

816+
/* Clear status before servicing to reduce spurious interrupts */
817+
if (!ring->priv->is_lite)
818+
intrl2_1_writel(ring->priv, BIT(ring->index), INTRL2_CPU_CLEAR);
819+
else
820+
intrl2_0_writel(ring->priv, BIT(ring->index +
821+
INTRL2_0_TDMA_MBDONE_SHIFT), INTRL2_CPU_CLEAR);
822+
785823
/* Compute how many descriptors have been processed since last call */
786824
hw_ind = tdma_readl(priv, TDMA_DESC_RING_PROD_CONS_INDEX(ring->index));
787825
c_index = (hw_ind >> RING_CONS_INDEX_SHIFT) & RING_CONS_INDEX_MASK;
@@ -803,7 +841,7 @@ static unsigned int __bcm_sysport_tx_reclaim(struct bcm_sysport_priv *priv,
803841

804842
while (last_tx_cn-- > 0) {
805843
cb = ring->cbs + last_c_index;
806-
bcm_sysport_tx_reclaim_one(priv, cb, &bytes_compl, &pkts_compl);
844+
bcm_sysport_tx_reclaim_one(ring, cb, &bytes_compl, &pkts_compl);
807845

808846
ring->desc_count++;
809847
last_c_index++;
@@ -1632,6 +1670,24 @@ static int bcm_sysport_change_mac(struct net_device *dev, void *p)
16321670
return 0;
16331671
}
16341672

1673+
static struct net_device_stats *bcm_sysport_get_nstats(struct net_device *dev)
1674+
{
1675+
struct bcm_sysport_priv *priv = netdev_priv(dev);
1676+
unsigned long tx_bytes = 0, tx_packets = 0;
1677+
struct bcm_sysport_tx_ring *ring;
1678+
unsigned int q;
1679+
1680+
for (q = 0; q < dev->num_tx_queues; q++) {
1681+
ring = &priv->tx_rings[q];
1682+
tx_bytes += ring->bytes;
1683+
tx_packets += ring->packets;
1684+
}
1685+
1686+
dev->stats.tx_bytes = tx_bytes;
1687+
dev->stats.tx_packets = tx_packets;
1688+
return &dev->stats;
1689+
}
1690+
16351691
static void bcm_sysport_netif_start(struct net_device *dev)
16361692
{
16371693
struct bcm_sysport_priv *priv = netdev_priv(dev);
@@ -1893,6 +1949,7 @@ static const struct net_device_ops bcm_sysport_netdev_ops = {
18931949
#ifdef CONFIG_NET_POLL_CONTROLLER
18941950
.ndo_poll_controller = bcm_sysport_poll_controller,
18951951
#endif
1952+
.ndo_get_stats = bcm_sysport_get_nstats,
18961953
};
18971954

18981955
#define REV_FMT "v%2x.%02x"

‎drivers/net/ethernet/broadcom/bcmsysport.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,9 @@ enum bcm_sysport_stat_type {
647647
.reg_offset = ofs, \
648648
}
649649

650+
/* TX bytes and packets */
651+
#define NUM_SYSPORT_TXQ_STAT 2
652+
650653
struct bcm_sysport_stats {
651654
char stat_string[ETH_GSTRING_LEN];
652655
int stat_sizeof;
@@ -690,6 +693,8 @@ struct bcm_sysport_tx_ring {
690693
struct bcm_sysport_cb *cbs; /* Transmit control blocks */
691694
struct dma_desc *desc_cpu; /* CPU view of the descriptor */
692695
struct bcm_sysport_priv *priv; /* private context backpointer */
696+
unsigned long packets; /* packets statistics */
697+
unsigned long bytes; /* bytes statistics */
693698
};
694699

695700
/* Driver private structure */

0 commit comments

Comments
 (0)