net/ethtool/common.c
Source file repositories/reference/linux-study-clean/net/ethtool/common.c
File Facts
- System
- Linux kernel
- Corpus path
net/ethtool/common.c- Extension
.c- Size
- 47211 bytes
- Lines
- 1403
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/ethtool_netlink.hlinux/net_tstamp.hlinux/phy.hlinux/rtnetlink.hlinux/ptp_clock_kernel.hlinux/phy_link_topology.hnet/netdev_queues.hcommon.hnetlink.h../core/dev.h
Detected Declarations
function convert_legacy_settings_to_link_ksettingsfunction __ethtool_get_linkfunction ethtool_get_rx_ring_countfunction ethtool_get_rxnfc_rule_countfunction ethtool_get_rss_ctx_max_channelfunction ethtool_get_max_rxnfc_channelfunction ethtool_get_max_rss_ctx_channelfunction ethtool_get_max_rxfh_channelfunction ethtool_check_max_channelfunction ethtool_check_rss_ctx_busyfunction ethtool_rxfh_ctx_allocfunction ethtool_rxfh_config_is_symfunction ethtool_check_opsfunction ethtool_ringparam_get_cfgfunction ethtool_init_tsinfofunction ethtool_net_get_ts_info_by_phcfunction ethtool_phy_get_ts_info_by_phcfunction xa_for_eachfunction ethtool_get_ts_info_by_phcfunction __ethtool_get_ts_infofunction net_support_hwtstamp_qualifierfunction ethtool_get_phc_vclocksfunction ethtool_get_ts_info_by_layerfunction ethtool_set_ethtool_phy_opsfunction ethtool_params_from_link_modefunction ethtool_forced_speed_maps_initfunction ethtool_rxfh_context_lostfunction netif_is_rxfh_configuredfunction ethtool_rxfh_indir_lostfunction ethtool_rxfh_is_periodicfunction ethtool_rxfh_can_resizefunction ethtool_rxfh_resizefunction ethtool_rxfh_indir_can_resizefunction ethtool_rxfh_indir_can_resizefunction ethtool_rxfh_ctxs_can_resizefunction ethtool_rxfh_ctxs_can_resizefunction ethtool_str_to_mediumexport link_mode_paramsexport ethtool_get_phc_vclocksexport ethtool_get_ts_info_by_layerexport ethtool_set_ethtool_phy_opsexport ethtool_params_from_link_modeexport ethtool_forced_speed_maps_initexport ethtool_rxfh_context_lostexport netif_is_rxfh_configuredexport ethtool_rxfh_indir_lostexport ethtool_rxfh_indir_can_resizeexport ethtool_rxfh_indir_resize
Annotated Snippet
if (rule_info.flow_type & FLOW_RSS) {
struct ethtool_rxfh_context *ctx;
ctx = xa_load(&dev->ethtool->rss_ctx,
rule_info.rss_context);
ring += ethtool_get_rss_ctx_max_channel(ctx);
}
max_ring = max_t(u64, max_ring, ring);
}
}
kvfree(info);
*max = max_ring;
return 0;
err_free_info:
kvfree(info);
return err;
}
/* Max offset across all of a device's RSS contexts */
static u32 ethtool_get_max_rss_ctx_channel(struct net_device *dev)
{
struct ethtool_rxfh_context *ctx;
unsigned long context;
u32 max_ring = 0;
mutex_lock(&dev->ethtool->rss_lock);
xa_for_each(&dev->ethtool->rss_ctx, context, ctx)
max_ring = max(max_ring, ethtool_get_rss_ctx_max_channel(ctx));
mutex_unlock(&dev->ethtool->rss_lock);
return max_ring;
}
static u32 ethtool_get_max_rxfh_channel(struct net_device *dev)
{
struct ethtool_rxfh_param rxfh = {};
u32 dev_size, current_max = 0;
int ret;
/* While we do track whether RSS context has an indirection
* table explicitly set by the user, no driver looks at that bit.
* Assume drivers won't auto-regenerate the additional tables,
* to be safe.
*/
current_max = ethtool_get_max_rss_ctx_channel(dev);
if (!netif_is_rxfh_configured(dev))
return current_max;
if (!dev->ethtool_ops->get_rxfh_indir_size ||
!dev->ethtool_ops->get_rxfh)
return current_max;
dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
if (dev_size == 0)
return current_max;
rxfh.indir = kzalloc_objs(rxfh.indir[0], dev_size, GFP_USER);
if (!rxfh.indir)
return U32_MAX;
mutex_lock(&dev->ethtool->rss_lock);
ret = dev->ethtool_ops->get_rxfh(dev, &rxfh);
mutex_unlock(&dev->ethtool->rss_lock);
if (ret) {
current_max = U32_MAX;
goto out_free;
}
while (dev_size--)
current_max = max(current_max, rxfh.indir[dev_size]);
out_free:
kfree(rxfh.indir);
return current_max;
}
int ethtool_check_max_channel(struct net_device *dev,
struct ethtool_channels channels,
struct genl_info *info)
{
u64 max_rxnfc_in_use;
u32 max_rxfh_in_use;
int max_mp_in_use;
/* ensure the new Rx count fits within the configured Rx flow
* indirection table/rxnfc settings
*/
if (ethtool_get_max_rxnfc_channel(dev, &max_rxnfc_in_use))
Annotation
- Immediate include surface: `linux/ethtool_netlink.h`, `linux/net_tstamp.h`, `linux/phy.h`, `linux/rtnetlink.h`, `linux/ptp_clock_kernel.h`, `linux/phy_link_topology.h`, `net/netdev_queues.h`, `common.h`.
- Detected declarations: `function convert_legacy_settings_to_link_ksettings`, `function __ethtool_get_link`, `function ethtool_get_rx_ring_count`, `function ethtool_get_rxnfc_rule_count`, `function ethtool_get_rss_ctx_max_channel`, `function ethtool_get_max_rxnfc_channel`, `function ethtool_get_max_rss_ctx_channel`, `function ethtool_get_max_rxfh_channel`, `function ethtool_check_max_channel`, `function ethtool_check_rss_ctx_busy`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration 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.