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

ixgbevf: Add zero_base handler to network statistics

This patch removes the need to keep a zero_base variable in the adapter
structure. Now we just use two different macros to set the non-zero and
zero base. This adds to readability and shortens some of the structure
initialization under 80 columns. The gathering of status for ethtool was
slightly modified to again better fit into 80 columns and become a bit
more readable.

Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
Signed-off-by: Don Skidmore <donald.c.skidmore@intel.com>
Tested-by: Phil Schmitt <phillip.j.schmitt@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>

authored by

Don Skidmore and committed by
Jeff Kirsher
44bd741e 3b5dca26

+45 -34
+45 -33
drivers/net/ethernet/intel/ixgbevf/ethtool.c
··· 45 45 46 46 struct ixgbe_stats { 47 47 char stat_string[ETH_GSTRING_LEN]; 48 - int sizeof_stat; 49 - int stat_offset; 50 - int base_stat_offset; 51 - int saved_reset_offset; 48 + struct { 49 + int sizeof_stat; 50 + int stat_offset; 51 + int base_stat_offset; 52 + int saved_reset_offset; 53 + }; 52 54 }; 53 55 54 - #define IXGBEVF_STAT(m, b, r) sizeof(((struct ixgbevf_adapter *)0)->m), \ 55 - offsetof(struct ixgbevf_adapter, m), \ 56 - offsetof(struct ixgbevf_adapter, b), \ 57 - offsetof(struct ixgbevf_adapter, r) 56 + #define IXGBEVF_STAT(m, b, r) { \ 57 + .sizeof_stat = FIELD_SIZEOF(struct ixgbevf_adapter, m), \ 58 + .stat_offset = offsetof(struct ixgbevf_adapter, m), \ 59 + .base_stat_offset = offsetof(struct ixgbevf_adapter, b), \ 60 + .saved_reset_offset = offsetof(struct ixgbevf_adapter, r) \ 61 + } 62 + 63 + #define IXGBEVF_ZSTAT(m) { \ 64 + .sizeof_stat = FIELD_SIZEOF(struct ixgbevf_adapter, m), \ 65 + .stat_offset = offsetof(struct ixgbevf_adapter, m), \ 66 + .base_stat_offset = -1, \ 67 + .saved_reset_offset = -1 \ 68 + } 58 69 59 70 static const struct ixgbe_stats ixgbe_gstrings_stats[] = { 60 71 {"rx_packets", IXGBEVF_STAT(stats.vfgprc, stats.base_vfgprc, ··· 76 65 stats.saved_reset_vfgorc)}, 77 66 {"tx_bytes", IXGBEVF_STAT(stats.vfgotc, stats.base_vfgotc, 78 67 stats.saved_reset_vfgotc)}, 79 - {"tx_busy", IXGBEVF_STAT(tx_busy, zero_base, zero_base)}, 68 + {"tx_busy", IXGBEVF_ZSTAT(tx_busy)}, 80 69 {"multicast", IXGBEVF_STAT(stats.vfmprc, stats.base_vfmprc, 81 70 stats.saved_reset_vfmprc)}, 82 - {"rx_csum_offload_good", IXGBEVF_STAT(hw_csum_rx_good, zero_base, 83 - zero_base)}, 84 - {"rx_csum_offload_errors", IXGBEVF_STAT(hw_csum_rx_error, zero_base, 85 - zero_base)}, 86 - {"tx_csum_offload_ctxt", IXGBEVF_STAT(hw_csum_tx_good, zero_base, 87 - zero_base)}, 71 + {"rx_csum_offload_good", IXGBEVF_ZSTAT(hw_csum_rx_good)}, 72 + {"rx_csum_offload_errors", IXGBEVF_ZSTAT(hw_csum_rx_error)}, 73 + {"tx_csum_offload_ctxt", IXGBEVF_ZSTAT(hw_csum_tx_good)}, 88 74 #ifdef BP_EXTENDED_STATS 89 - {"rx_bp_poll_yield", IXGBEVF_STAT(bp_rx_yields, zero_base, zero_base)}, 90 - {"rx_bp_cleaned", IXGBEVF_STAT(bp_rx_cleaned, zero_base, zero_base)}, 91 - {"rx_bp_misses", IXGBEVF_STAT(bp_rx_missed, zero_base, zero_base)}, 92 - {"tx_bp_napi_yield", IXGBEVF_STAT(bp_tx_yields, zero_base, zero_base)}, 93 - {"tx_bp_cleaned", IXGBEVF_STAT(bp_tx_cleaned, zero_base, zero_base)}, 94 - {"tx_bp_misses", IXGBEVF_STAT(bp_tx_missed, zero_base, zero_base)}, 75 + {"rx_bp_poll_yield", IXGBEVF_ZSTAT(bp_rx_yields)}, 76 + {"rx_bp_cleaned", IXGBEVF_ZSTAT(bp_rx_cleaned)}, 77 + {"rx_bp_misses", IXGBEVF_ZSTAT(bp_rx_missed)}, 78 + {"tx_bp_napi_yield", IXGBEVF_ZSTAT(bp_tx_yields)}, 79 + {"tx_bp_cleaned", IXGBEVF_ZSTAT(bp_tx_cleaned)}, 80 + {"tx_bp_misses", IXGBEVF_ZSTAT(bp_tx_missed)}, 95 81 #endif 96 82 }; 97 83 ··· 406 398 struct ethtool_stats *stats, u64 *data) 407 399 { 408 400 struct ixgbevf_adapter *adapter = netdev_priv(netdev); 401 + char *base = (char *) adapter; 409 402 int i; 410 403 #ifdef BP_EXTENDED_STATS 411 404 u64 rx_yields = 0, rx_cleaned = 0, rx_missed = 0, ··· 435 426 436 427 ixgbevf_update_stats(adapter); 437 428 for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { 438 - char *p = (char *)adapter + 439 - ixgbe_gstrings_stats[i].stat_offset; 440 - char *b = (char *)adapter + 441 - ixgbe_gstrings_stats[i].base_stat_offset; 442 - char *r = (char *)adapter + 443 - ixgbe_gstrings_stats[i].saved_reset_offset; 444 - data[i] = ((ixgbe_gstrings_stats[i].sizeof_stat == 445 - sizeof(u64)) ? *(u64 *)p : *(u32 *)p) - 446 - ((ixgbe_gstrings_stats[i].sizeof_stat == 447 - sizeof(u64)) ? *(u64 *)b : *(u32 *)b) + 448 - ((ixgbe_gstrings_stats[i].sizeof_stat == 449 - sizeof(u64)) ? *(u64 *)r : *(u32 *)r); 429 + char *p = base + ixgbe_gstrings_stats[i].stat_offset; 430 + char *b = base + ixgbe_gstrings_stats[i].base_stat_offset; 431 + char *r = base + ixgbe_gstrings_stats[i].saved_reset_offset; 432 + 433 + if (ixgbe_gstrings_stats[i].sizeof_stat == sizeof(u64)) { 434 + if (ixgbe_gstrings_stats[i].base_stat_offset >= 0) 435 + data[i] = *(u64 *)p - *(u64 *)b + *(u64 *)r; 436 + else 437 + data[i] = *(u64 *)p; 438 + } else { 439 + if (ixgbe_gstrings_stats[i].base_stat_offset >= 0) 440 + data[i] = *(u32 *)p - *(u32 *)b + *(u32 *)r; 441 + else 442 + data[i] = *(u32 *)p; 443 + } 450 444 } 451 445 } 452 446
-1
drivers/net/ethernet/intel/ixgbevf/ixgbevf.h
··· 361 361 struct ixgbe_hw hw; 362 362 u16 msg_enable; 363 363 struct ixgbevf_hw_stats stats; 364 - u64 zero_base; 365 364 /* Interrupt Throttle Rate */ 366 365 u32 eitr_param; 367 366