mirror of
https://github.com/torvalds/linux.git
synced 2026-04-26 02:22:28 -04:00
ICSSG HW stats on TX side considers 8 preamble bytes as data bytes. Due
to this the tx_bytes of ICSSG interface doesn't match the rx_bytes of the
link partner. There is no public errata available yet.
As a workaround to fix this, decrease tx_bytes by 8 bytes for every tx
frame.
Fixes: c1e10d5dc7 ("net: ti: icssg-prueth: Add ICSSG Stats")
Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
Link: https://lore.kernel.org/r/20231012064626.977466-1-danishanwar@ti.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
67 lines
1.7 KiB
C
67 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Texas Instruments ICSSG Ethernet driver
|
|
*
|
|
* Copyright (C) 2018-2021 Texas Instruments Incorporated - https://www.ti.com/
|
|
*
|
|
*/
|
|
|
|
#include "icssg_prueth.h"
|
|
#include "icssg_stats.h"
|
|
#include <linux/regmap.h>
|
|
|
|
#define ICSSG_TX_PACKET_OFFSET 0xA0
|
|
#define ICSSG_TX_BYTE_OFFSET 0xEC
|
|
|
|
static u32 stats_base[] = { 0x54c, /* Slice 0 stats start */
|
|
0xb18, /* Slice 1 stats start */
|
|
};
|
|
|
|
void emac_update_hardware_stats(struct prueth_emac *emac)
|
|
{
|
|
struct prueth *prueth = emac->prueth;
|
|
int slice = prueth_emac_slice(emac);
|
|
u32 base = stats_base[slice];
|
|
u32 tx_pkt_cnt = 0;
|
|
u32 val;
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(icssg_all_stats); i++) {
|
|
regmap_read(prueth->miig_rt,
|
|
base + icssg_all_stats[i].offset,
|
|
&val);
|
|
regmap_write(prueth->miig_rt,
|
|
base + icssg_all_stats[i].offset,
|
|
val);
|
|
|
|
if (icssg_all_stats[i].offset == ICSSG_TX_PACKET_OFFSET)
|
|
tx_pkt_cnt = val;
|
|
|
|
emac->stats[i] += val;
|
|
if (icssg_all_stats[i].offset == ICSSG_TX_BYTE_OFFSET)
|
|
emac->stats[i] -= tx_pkt_cnt * 8;
|
|
}
|
|
}
|
|
|
|
void emac_stats_work_handler(struct work_struct *work)
|
|
{
|
|
struct prueth_emac *emac = container_of(work, struct prueth_emac,
|
|
stats_work.work);
|
|
emac_update_hardware_stats(emac);
|
|
|
|
queue_delayed_work(system_long_wq, &emac->stats_work,
|
|
msecs_to_jiffies((STATS_TIME_LIMIT_1G_MS * 1000) / emac->speed));
|
|
}
|
|
|
|
int emac_get_stat_by_name(struct prueth_emac *emac, char *stat_name)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(icssg_all_stats); i++) {
|
|
if (!strcmp(icssg_all_stats[i].name, stat_name))
|
|
return emac->stats[icssg_all_stats[i].offset / sizeof(u32)];
|
|
}
|
|
|
|
netdev_err(emac->ndev, "Invalid stats %s\n", stat_name);
|
|
return -EINVAL;
|
|
}
|