Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: cadence: macb: Synchronize standard stats

The new stats calculations add several additional calls to
macb/gem_update_stats() and accesses to bp->hw_stats. These are
protected by a spinlock since commit fa52f15c745c ("net: cadence: macb:
Synchronize stats calculations"), which was applied in parallel. Add
some locking now that the net has been merged into net-next.

Fixes: f6af690a295a ("net: cadence: macb: Report standard stats")
Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
Link: https://patch.msgid.link/20250303231832.1648274-1-sean.anderson@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Sean Anderson and committed by
Jakub Kicinski
b9564ca3 85f66df3

+16
+16
drivers/net/ethernet/cadence/macb_main.c
··· 3253 3253 struct macb *bp = netdev_priv(dev); 3254 3254 struct macb_stats *hwstat = &bp->hw_stats.macb; 3255 3255 3256 + spin_lock_irq(&bp->stats_lock); 3256 3257 macb_update_stats(bp); 3257 3258 pause_stats->tx_pause_frames = hwstat->tx_pause_frames; 3258 3259 pause_stats->rx_pause_frames = hwstat->rx_pause_frames; 3260 + spin_unlock_irq(&bp->stats_lock); 3259 3261 } 3260 3262 3261 3263 static void gem_get_pause_stats(struct net_device *dev, ··· 3266 3264 struct macb *bp = netdev_priv(dev); 3267 3265 struct gem_stats *hwstat = &bp->hw_stats.gem; 3268 3266 3267 + spin_lock_irq(&bp->stats_lock); 3269 3268 gem_update_stats(bp); 3270 3269 pause_stats->tx_pause_frames = hwstat->tx_pause_frames; 3271 3270 pause_stats->rx_pause_frames = hwstat->rx_pause_frames; 3271 + spin_unlock_irq(&bp->stats_lock); 3272 3272 } 3273 3273 3274 3274 static void macb_get_eth_mac_stats(struct net_device *dev, ··· 3279 3275 struct macb *bp = netdev_priv(dev); 3280 3276 struct macb_stats *hwstat = &bp->hw_stats.macb; 3281 3277 3278 + spin_lock_irq(&bp->stats_lock); 3282 3279 macb_update_stats(bp); 3283 3280 mac_stats->FramesTransmittedOK = hwstat->tx_ok; 3284 3281 mac_stats->SingleCollisionFrames = hwstat->tx_single_cols; ··· 3295 3290 mac_stats->FramesLostDueToIntMACRcvError = hwstat->rx_overruns; 3296 3291 mac_stats->InRangeLengthErrors = hwstat->rx_length_mismatch; 3297 3292 mac_stats->FrameTooLongErrors = hwstat->rx_oversize_pkts; 3293 + spin_unlock_irq(&bp->stats_lock); 3298 3294 } 3299 3295 3300 3296 static void gem_get_eth_mac_stats(struct net_device *dev, ··· 3304 3298 struct macb *bp = netdev_priv(dev); 3305 3299 struct gem_stats *hwstat = &bp->hw_stats.gem; 3306 3300 3301 + spin_lock_irq(&bp->stats_lock); 3307 3302 gem_update_stats(bp); 3308 3303 mac_stats->FramesTransmittedOK = hwstat->tx_frames; 3309 3304 mac_stats->SingleCollisionFrames = hwstat->tx_single_collision_frames; ··· 3327 3320 mac_stats->BroadcastFramesReceivedOK = hwstat->rx_broadcast_frames; 3328 3321 mac_stats->InRangeLengthErrors = hwstat->rx_length_field_frame_errors; 3329 3322 mac_stats->FrameTooLongErrors = hwstat->rx_oversize_frames; 3323 + spin_unlock_irq(&bp->stats_lock); 3330 3324 } 3331 3325 3332 3326 /* TODO: Report SQE test errors when added to phy_stats */ ··· 3337 3329 struct macb *bp = netdev_priv(dev); 3338 3330 struct macb_stats *hwstat = &bp->hw_stats.macb; 3339 3331 3332 + spin_lock_irq(&bp->stats_lock); 3340 3333 macb_update_stats(bp); 3341 3334 phy_stats->SymbolErrorDuringCarrier = hwstat->rx_symbol_errors; 3335 + spin_unlock_irq(&bp->stats_lock); 3342 3336 } 3343 3337 3344 3338 static void gem_get_eth_phy_stats(struct net_device *dev, ··· 3349 3339 struct macb *bp = netdev_priv(dev); 3350 3340 struct gem_stats *hwstat = &bp->hw_stats.gem; 3351 3341 3342 + spin_lock_irq(&bp->stats_lock); 3352 3343 gem_update_stats(bp); 3353 3344 phy_stats->SymbolErrorDuringCarrier = hwstat->rx_symbol_errors; 3345 + spin_unlock_irq(&bp->stats_lock); 3354 3346 } 3355 3347 3356 3348 static void macb_get_rmon_stats(struct net_device *dev, ··· 3362 3350 struct macb *bp = netdev_priv(dev); 3363 3351 struct macb_stats *hwstat = &bp->hw_stats.macb; 3364 3352 3353 + spin_lock_irq(&bp->stats_lock); 3365 3354 macb_update_stats(bp); 3366 3355 rmon_stats->undersize_pkts = hwstat->rx_undersize_pkts; 3367 3356 rmon_stats->oversize_pkts = hwstat->rx_oversize_pkts; 3368 3357 rmon_stats->jabbers = hwstat->rx_jabbers; 3358 + spin_unlock_irq(&bp->stats_lock); 3369 3359 } 3370 3360 3371 3361 static const struct ethtool_rmon_hist_range gem_rmon_ranges[] = { ··· 3388 3374 struct macb *bp = netdev_priv(dev); 3389 3375 struct gem_stats *hwstat = &bp->hw_stats.gem; 3390 3376 3377 + spin_lock_irq(&bp->stats_lock); 3391 3378 gem_update_stats(bp); 3392 3379 rmon_stats->undersize_pkts = hwstat->rx_undersized_frames; 3393 3380 rmon_stats->oversize_pkts = hwstat->rx_oversize_frames; ··· 3407 3392 rmon_stats->hist_tx[4] = hwstat->tx_512_1023_byte_frames; 3408 3393 rmon_stats->hist_tx[5] = hwstat->tx_1024_1518_byte_frames; 3409 3394 rmon_stats->hist_tx[6] = hwstat->tx_greater_than_1518_byte_frames; 3395 + spin_unlock_irq(&bp->stats_lock); 3410 3396 *ranges = gem_rmon_ranges; 3411 3397 } 3412 3398