net: ethernet: litex: add support for 64 bit stats
[ Upstream commit 18da174d865a87d47d2f33f5b0a322efcf067728 ] Implement 64 bit per cpu stats to fix the overflow of netdev->stats on 32 bit platforms. To simplify the code, we use net core pcpu_sw_netstats infrastructure. One small drawback is some memory overhead because litex uses just one queue, but we allocate the counters per cpu. Signed-off-by: Jisheng Zhang <jszhang@kernel.org> Reviewed-by: Simon Horman <simon.horman@corigine.com> Acked-by: Gabriel Somlo <gsomlo@gmail.com> Link: https://lore.kernel.org/r/20230614162035.300-1-jszhang@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
86f9330a49
commit
0d14264155
@ -78,8 +78,7 @@ static int liteeth_rx(struct net_device *netdev)
|
|||||||
memcpy_fromio(data, priv->rx_base + rx_slot * priv->slot_size, len);
|
memcpy_fromio(data, priv->rx_base + rx_slot * priv->slot_size, len);
|
||||||
skb->protocol = eth_type_trans(skb, netdev);
|
skb->protocol = eth_type_trans(skb, netdev);
|
||||||
|
|
||||||
netdev->stats.rx_packets++;
|
dev_sw_netstats_rx_add(netdev, len);
|
||||||
netdev->stats.rx_bytes += len;
|
|
||||||
|
|
||||||
return netif_rx(skb);
|
return netif_rx(skb);
|
||||||
|
|
||||||
@ -185,8 +184,7 @@ static netdev_tx_t liteeth_start_xmit(struct sk_buff *skb,
|
|||||||
litex_write16(priv->base + LITEETH_READER_LENGTH, skb->len);
|
litex_write16(priv->base + LITEETH_READER_LENGTH, skb->len);
|
||||||
litex_write8(priv->base + LITEETH_READER_START, 1);
|
litex_write8(priv->base + LITEETH_READER_START, 1);
|
||||||
|
|
||||||
netdev->stats.tx_bytes += skb->len;
|
dev_sw_netstats_tx_add(netdev, 1, skb->len);
|
||||||
netdev->stats.tx_packets++;
|
|
||||||
|
|
||||||
priv->tx_slot = (priv->tx_slot + 1) % priv->num_tx_slots;
|
priv->tx_slot = (priv->tx_slot + 1) % priv->num_tx_slots;
|
||||||
dev_kfree_skb_any(skb);
|
dev_kfree_skb_any(skb);
|
||||||
@ -194,9 +192,17 @@ static netdev_tx_t liteeth_start_xmit(struct sk_buff *skb,
|
|||||||
return NETDEV_TX_OK;
|
return NETDEV_TX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
liteeth_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
|
||||||
|
{
|
||||||
|
netdev_stats_to_stats64(stats, &netdev->stats);
|
||||||
|
dev_fetch_sw_netstats(stats, netdev->tstats);
|
||||||
|
}
|
||||||
|
|
||||||
static const struct net_device_ops liteeth_netdev_ops = {
|
static const struct net_device_ops liteeth_netdev_ops = {
|
||||||
.ndo_open = liteeth_open,
|
.ndo_open = liteeth_open,
|
||||||
.ndo_stop = liteeth_stop,
|
.ndo_stop = liteeth_stop,
|
||||||
|
.ndo_get_stats64 = liteeth_get_stats64,
|
||||||
.ndo_start_xmit = liteeth_start_xmit,
|
.ndo_start_xmit = liteeth_start_xmit,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -242,6 +248,11 @@ static int liteeth_probe(struct platform_device *pdev)
|
|||||||
priv->netdev = netdev;
|
priv->netdev = netdev;
|
||||||
priv->dev = &pdev->dev;
|
priv->dev = &pdev->dev;
|
||||||
|
|
||||||
|
netdev->tstats = devm_netdev_alloc_pcpu_stats(&pdev->dev,
|
||||||
|
struct pcpu_sw_netstats);
|
||||||
|
if (!netdev->tstats)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
irq = platform_get_irq(pdev, 0);
|
irq = platform_get_irq(pdev, 0);
|
||||||
if (irq < 0)
|
if (irq < 0)
|
||||||
return irq;
|
return irq;
|
||||||
|
Loading…
Reference in New Issue
Block a user