drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx4/en_ethtool.c- Extension
.c- Size
- 62309 bytes
- Lines
- 2181
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/ethtool.hlinux/netdevice.hlinux/mlx4/driver.hlinux/mlx4/device.hlinux/in.hnet/ip.hlinux/bitmap.hlinux/mii.hmlx4_en.hen_port.h
Detected Declarations
struct bitmap_iteratorstruct ptys2ethtool_configenum ethtool_reportfunction Copyrightfunction mlx4_en_get_drvinfofunction mlx4_en_get_msglevelfunction mlx4_en_set_msglevelfunction mlx4_en_get_wolfunction mlx4_en_set_wolfunction bitmap_iterator_initfunction bitmap_iterator_testfunction bitmap_iterator_incfunction bitmap_iterator_countfunction mlx4_en_get_sset_countfunction mlx4_en_get_ethtool_statsfunction mlx4_en_self_testfunction mlx4_en_get_stringsfunction mlx4_en_autoneg_getfunction ptys2ethtool_update_supported_portfunction ptys_get_active_portfunction mlx4_en_init_ptys2ethtool_mapfunction ptys2ethtool_update_link_modesfunction ethtool2ptys_link_modesfunction speed2ptys_link_modesfunction ethtool_get_ptys_link_ksettingsfunction ethtool_get_default_link_ksettingsfunction mlx4_en_get_link_ksettingsfunction speed_set_ptys_adminfunction mlx4_en_set_link_ksettingsfunction mlx4_en_get_coalescefunction mlx4_en_set_coalescefunction mlx4_en_set_pauseparamfunction mlx4_en_get_pause_statsfunction mlx4_en_get_pauseparamfunction mlx4_en_set_ringparamfunction mlx4_en_get_ringparamfunction mlx4_en_get_rxfh_indir_sizefunction mlx4_en_get_rxfh_key_sizefunction mlx4_en_check_rxfh_funcfunction mlx4_en_get_rxfhfunction mlx4_en_set_rxfhfunction mlx4_en_validate_flowfunction mlx4_en_ethtool_add_mac_rulefunction mlx4_en_ethtool_add_mac_rule_by_ipv4function add_ip_rulefunction add_tcp_udp_rulefunction mlx4_en_ethtool_to_net_trans_rulefunction mlx4_en_flow_replace
Annotated Snippet
struct bitmap_iterator {
unsigned long *stats_bitmap;
unsigned int count;
unsigned int iterator;
bool advance_array; /* if set, force no increments */
};
static inline void bitmap_iterator_init(struct bitmap_iterator *h,
unsigned long *stats_bitmap,
int count)
{
h->iterator = 0;
h->advance_array = !bitmap_empty(stats_bitmap, count);
h->count = h->advance_array ? bitmap_weight(stats_bitmap, count)
: count;
h->stats_bitmap = stats_bitmap;
}
static inline int bitmap_iterator_test(struct bitmap_iterator *h)
{
return !h->advance_array ? 1 : test_bit(h->iterator, h->stats_bitmap);
}
static inline int bitmap_iterator_inc(struct bitmap_iterator *h)
{
return h->iterator++;
}
static inline unsigned int
bitmap_iterator_count(struct bitmap_iterator *h)
{
return h->count;
}
static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
{
struct mlx4_en_priv *priv = netdev_priv(dev);
struct bitmap_iterator it;
bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS);
switch (sset) {
case ETH_SS_STATS:
return bitmap_iterator_count(&it) +
(priv->tx_ring_num[TX] * 2) +
(priv->rx_ring_num * (3 + NUM_XDP_STATS));
case ETH_SS_TEST:
return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.flags
& MLX4_DEV_CAP_FLAG_UC_LOOPBACK) * 2;
case ETH_SS_PRIV_FLAGS:
return ARRAY_SIZE(mlx4_en_priv_flags);
default:
return -EOPNOTSUPP;
}
}
static void mlx4_en_get_ethtool_stats(struct net_device *dev,
struct ethtool_stats *stats, uint64_t *data)
{
struct mlx4_en_priv *priv = netdev_priv(dev);
int index = 0;
int i;
struct bitmap_iterator it;
bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS);
spin_lock_bh(&priv->stats_lock);
mlx4_en_fold_software_stats(dev);
for (i = 0; i < NUM_MAIN_STATS; i++, bitmap_iterator_inc(&it))
if (bitmap_iterator_test(&it))
data[index++] = ((unsigned long *)&dev->stats)[i];
for (i = 0; i < NUM_PORT_STATS; i++, bitmap_iterator_inc(&it))
if (bitmap_iterator_test(&it))
data[index++] = ((unsigned long *)&priv->port_stats)[i];
for (i = 0; i < NUM_PF_STATS; i++, bitmap_iterator_inc(&it))
if (bitmap_iterator_test(&it))
data[index++] =
((unsigned long *)&priv->pf_stats)[i];
for (i = 0; i < NUM_FLOW_PRIORITY_STATS_RX;
i++, bitmap_iterator_inc(&it))
if (bitmap_iterator_test(&it))
data[index++] =
((u64 *)&priv->rx_priority_flowstats)[i];
for (i = 0; i < NUM_FLOW_STATS_RX; i++, bitmap_iterator_inc(&it))
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/ethtool.h`, `linux/netdevice.h`, `linux/mlx4/driver.h`, `linux/mlx4/device.h`, `linux/in.h`, `net/ip.h`, `linux/bitmap.h`.
- Detected declarations: `struct bitmap_iterator`, `struct ptys2ethtool_config`, `enum ethtool_report`, `function Copyright`, `function mlx4_en_get_drvinfo`, `function mlx4_en_get_msglevel`, `function mlx4_en_set_msglevel`, `function mlx4_en_get_wol`, `function mlx4_en_set_wol`, `function bitmap_iterator_init`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.