net/ethtool/linkstate.c
Source file repositories/reference/linux-study-clean/net/ethtool/linkstate.c
File Facts
- System
- Linux kernel
- Corpus path
net/ethtool/linkstate.c- Extension
.c- Size
- 5670 bytes
- Lines
- 227
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/phy.hlinux/phylib_stubs.hcommon.hnetlink.h
Detected Declarations
struct linkstate_req_infostruct linkstate_reply_datafunction linkstate_get_sqifunction linkstate_get_sqi_maxfunction linkstate_sqi_critical_errorfunction linkstate_sqi_validfunction linkstate_get_link_ext_statefunction linkstate_prepare_datafunction linkstate_reply_sizefunction linkstate_fill_reply
Annotated Snippet
struct linkstate_req_info {
struct ethnl_req_info base;
};
struct linkstate_reply_data {
struct ethnl_reply_data base;
int link;
int sqi;
int sqi_max;
struct ethtool_link_ext_stats link_stats;
bool link_ext_state_provided;
struct ethtool_link_ext_state_info ethtool_link_ext_state_info;
};
#define LINKSTATE_REPDATA(__reply_base) \
container_of(__reply_base, struct linkstate_reply_data, base)
const struct nla_policy ethnl_linkstate_get_policy[] = {
[ETHTOOL_A_LINKSTATE_HEADER] =
NLA_POLICY_NESTED(ethnl_header_policy_stats),
};
static int linkstate_get_sqi(struct phy_device *phydev)
{
int ret;
if (!phydev)
return -EOPNOTSUPP;
mutex_lock(&phydev->lock);
if (!phydev->drv || !phydev->drv->get_sqi)
ret = -EOPNOTSUPP;
else if (!phydev->link)
ret = -ENETDOWN;
else
ret = phydev->drv->get_sqi(phydev);
mutex_unlock(&phydev->lock);
return ret;
}
static int linkstate_get_sqi_max(struct phy_device *phydev)
{
int ret;
if (!phydev)
return -EOPNOTSUPP;
mutex_lock(&phydev->lock);
if (!phydev->drv || !phydev->drv->get_sqi_max)
ret = -EOPNOTSUPP;
else if (!phydev->link)
ret = -ENETDOWN;
else
ret = phydev->drv->get_sqi_max(phydev);
mutex_unlock(&phydev->lock);
return ret;
};
static bool linkstate_sqi_critical_error(int sqi)
{
return sqi < 0 && sqi != -EOPNOTSUPP && sqi != -ENETDOWN;
}
static bool linkstate_sqi_valid(struct linkstate_reply_data *data)
{
return data->sqi >= 0 && data->sqi_max >= 0 &&
data->sqi <= data->sqi_max;
}
static int linkstate_get_link_ext_state(struct net_device *dev,
struct linkstate_reply_data *data)
{
int err;
if (!dev->ethtool_ops->get_link_ext_state)
return -EOPNOTSUPP;
err = dev->ethtool_ops->get_link_ext_state(dev, &data->ethtool_link_ext_state_info);
if (err)
return err;
data->link_ext_state_provided = true;
return 0;
}
static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
struct ethnl_reply_data *reply_base,
Annotation
- Immediate include surface: `linux/phy.h`, `linux/phylib_stubs.h`, `common.h`, `netlink.h`.
- Detected declarations: `struct linkstate_req_info`, `struct linkstate_reply_data`, `function linkstate_get_sqi`, `function linkstate_get_sqi_max`, `function linkstate_sqi_critical_error`, `function linkstate_sqi_valid`, `function linkstate_get_link_ext_state`, `function linkstate_prepare_data`, `function linkstate_reply_size`, `function linkstate_fill_reply`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- 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.