[PATCH v6 net-next 0/5] use bulk reads for ocelot statistics

From: Colin Foster
Date: Wed Feb 09 2022 - 23:15:45 EST


Ocelot loops over memory regions to gather stats on different ports.
These regions are mostly continuous, and are ordered. This patch set
uses that information to break the stats reads into regions that can get
read in bulk.

The motiviation is for general cleanup, but also for SPI. Performing two
back-to-back reads on a SPI bus require toggling the CS line, holding,
re-toggling the CS line, sending 3 address bytes, sending N padding
bytes, then actually performing the read. Bulk reads could reduce almost
all of that overhead, but require that the reads are performed via
regmap_bulk_read.

Verified with eth0 hooked up to the CPU port:
# ethtool -S eth0 | grep -v ": 0"
NIC statistics:
Good Rx Frames: 8352
Rx Octets: 10972241
Good Tx Frames: 1674
Tx Octets: 146253
Rx + Tx 65-127 Octet Frames: 2565
Rx + Tx 128-255 Octet Frames: 93
Rx + Tx 256-511 Octet Frames: 158
Rx + Tx 512-1023 Octet Frames: 271
Rx + Tx 1024-Up Octet Frames: 6939
Net Octets: 11118494
Rx DMA chan 0: head_enqueue: 1
Rx DMA chan 0: tail_enqueue: 8479
Rx DMA chan 0: busy_dequeue: 7614
Rx DMA chan 0: good_dequeue: 8352
Tx DMA chan 0: head_enqueue: 1335
Tx DMA chan 0: tail_enqueue: 339
Tx DMA chan 0: misqueued: 339
Tx DMA chan 0: empty_dequeue: 1335
Tx DMA chan 0: good_dequeue: 1674
p00_rx_octets: 146253
p00_rx_unicast: 1674
p00_rx_frames_65_to_127_octets: 1666
p00_rx_frames_128_to_255_octets: 7
p00_rx_frames_over_1526_octets: 1
p00_tx_octets: 10972241
p00_tx_unicast: 8352
p00_tx_frames_65_to_127_octets: 899
p00_tx_frames_128_255_octets: 86
p00_tx_frames_256_511_octets: 158
p00_tx_frames_512_1023_octets: 271
p00_tx_frames_1024_1526_octets: 222
p00_tx_frames_over_1526_octets: 6716
p00_tx_green_prio_0: 8352


And with swp2 connected to swp3 with STP enabled:
# ethtool -S swp2 | grep -v ": 0"
NIC statistics:
tx_packets: 397
tx_bytes: 20634
rx_packets: 1
rx_bytes: 46
rx_octets: 64
rx_multicast: 1
rx_frames_below_65_octets: 1
rx_classified_drops: 1
tx_octets: 46586
tx_multicast: 404
tx_broadcast: 303
tx_frames_below_65_octets: 397
tx_frames_65_to_127_octets: 306
tx_frames_128_255_octets: 4
tx_green_prio_0: 311
tx_green_prio_7: 396
# ethtool -S swp3 | grep -v ": 0"
NIC statistics:
tx_packets: 1
tx_bytes: 52
rx_packets: 711
rx_bytes: 34050
rx_octets: 46848
rx_multicast: 406
rx_broadcast: 305
rx_frames_below_65_octets: 399
rx_frames_65_to_127_octets: 308
rx_frames_128_to_255_octets: 4
rx_classified_drops: 398
rx_green_prio_0: 313
tx_octets: 64
tx_multicast: 1
tx_frames_below_65_octets: 1
tx_green_prio_7: 1


v1 > v2: reword commit messages
v2 > v3: correctly mark this for net-next when sending
v3 > v4: calloc array instead of zalloc per review
v4 > v5:
Apply CR suggestions for whitespace
Fix calloc / zalloc mixup
Properly destroy workqueues
Add third commit to split long macros
v5 > v6:
Fix functionality - v5 was improperly tested
Add bugfix for ethtool mutex lock
Remove unnecessary ethtool stats reads


Colin Foster (5):
net: mscc: ocelot: fix mutex lock error during ethtool stats read
net: mscc: ocelot: remove unnecessary stat reading from ethtool
net: ocelot: align macros for consistency
net: mscc: ocelot: add ability to perform bulk reads
net: mscc: ocelot: use bulk reads for stats

drivers/net/ethernet/mscc/ocelot.c | 97 +++++++++++++++++++++------
drivers/net/ethernet/mscc/ocelot_io.c | 13 ++++
include/soc/mscc/ocelot.h | 57 +++++++++++-----
3 files changed, 132 insertions(+), 35 deletions(-)

--
2.25.1