net/ethtool/pse-pd.c

Source file repositories/reference/linux-study-clean/net/ethtool/pse-pd.c

File Facts

System
Linux kernel
Corpus path
net/ethtool/pse-pd.c
Extension
.c
Size
10310 bytes
Lines
384
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct pse_req_info {
	struct ethnl_req_info base;
};

struct pse_reply_data {
	struct ethnl_reply_data	base;
	struct ethtool_pse_control_status status;
};

#define PSE_REPDATA(__reply_base) \
	container_of(__reply_base, struct pse_reply_data, base)

/* PSE_GET */

const struct nla_policy ethnl_pse_get_policy[ETHTOOL_A_PSE_HEADER + 1] = {
	[ETHTOOL_A_PSE_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy_phy),
};

static int pse_get_pse_attributes(struct phy_device *phydev,
				  struct netlink_ext_ack *extack,
				  struct pse_reply_data *data)
{
	if (!phydev) {
		NL_SET_ERR_MSG(extack, "No PHY found");
		return -EOPNOTSUPP;
	}

	if (!phydev->psec) {
		NL_SET_ERR_MSG(extack, "No PSE is attached");
		return -EOPNOTSUPP;
	}

	memset(&data->status, 0, sizeof(data->status));

	return pse_ethtool_get_status(phydev->psec, extack, &data->status);
}

static int pse_prepare_data(const struct ethnl_req_info *req_base,
			    struct ethnl_reply_data *reply_base,
			    const struct genl_info *info)
{
	struct pse_reply_data *data = PSE_REPDATA(reply_base);
	struct net_device *dev = reply_base->dev;
	struct nlattr **tb = info->attrs;
	struct phy_device *phydev;
	int ret;

	phydev = ethnl_req_get_phydev(req_base, tb, ETHTOOL_A_PSE_HEADER,
				      info->extack);
	if (IS_ERR(phydev))
		return PTR_ERR(phydev);

	ret = ethnl_ops_begin(dev);
	if (ret < 0)
		return ret;

	ret = pse_get_pse_attributes(phydev, info->extack, data);

	ethnl_ops_complete(dev);

	return ret;
}

static int pse_reply_size(const struct ethnl_req_info *req_base,
			  const struct ethnl_reply_data *reply_base)
{
	const struct pse_reply_data *data = PSE_REPDATA(reply_base);
	const struct ethtool_pse_control_status *st = &data->status;
	int len = 0;

	if (st->pw_d_id)
		len += nla_total_size(sizeof(u32)); /* _PSE_PW_D_ID */
	if (st->podl_admin_state > 0)
		len += nla_total_size(sizeof(u32)); /* _PODL_PSE_ADMIN_STATE */
	if (st->podl_pw_status > 0)
		len += nla_total_size(sizeof(u32)); /* _PODL_PSE_PW_D_STATUS */
	if (st->c33_admin_state > 0)
		len += nla_total_size(sizeof(u32)); /* _C33_PSE_ADMIN_STATE */
	if (st->c33_pw_status > 0)
		len += nla_total_size(sizeof(u32)); /* _C33_PSE_PW_D_STATUS */
	if (st->c33_pw_class > 0)
		len += nla_total_size(sizeof(u32)); /* _C33_PSE_PW_CLASS */
	if (st->c33_actual_pw > 0)
		len += nla_total_size(sizeof(u32)); /* _C33_PSE_ACTUAL_PW */
	if (st->c33_ext_state_info.c33_pse_ext_state > 0) {
		len += nla_total_size(sizeof(u32)); /* _C33_PSE_EXT_STATE */
		if (st->c33_ext_state_info.__c33_pse_ext_substate > 0)
			/* _C33_PSE_EXT_SUBSTATE */
			len += nla_total_size(sizeof(u32));
	}

Annotation

Implementation Notes