net/dsa/user.c

Source file repositories/reference/linux-study-clean/net/dsa/user.c

File Facts

System
Linux kernel
Corpus path
net/dsa/user.c
Extension
.c
Size
96809 bytes
Lines
3877
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: operation-table or driver-model contract
Status
pattern 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

static const struct net_device_ops dsa_user_netdev_ops = {
	.ndo_open		= dsa_user_open,
	.ndo_stop		= dsa_user_close,
	.ndo_start_xmit		= dsa_user_xmit,
	.ndo_change_rx_flags	= dsa_user_change_rx_flags,
	.ndo_set_rx_mode	= dsa_user_set_rx_mode,
	.ndo_set_mac_address	= dsa_user_set_mac_address,
	.ndo_fdb_dump		= dsa_user_fdb_dump,
	.ndo_eth_ioctl		= dsa_user_ioctl,
	.ndo_get_iflink		= dsa_user_get_iflink,
#ifdef CONFIG_NET_POLL_CONTROLLER
	.ndo_netpoll_setup	= dsa_user_netpoll_setup,
	.ndo_netpoll_cleanup	= dsa_user_netpoll_cleanup,
	.ndo_poll_controller	= dsa_user_poll_controller,
#endif
	.ndo_setup_tc		= dsa_user_setup_tc,
	.ndo_get_stats64	= dsa_user_get_stats64,
	.ndo_vlan_rx_add_vid	= dsa_user_vlan_rx_add_vid,
	.ndo_vlan_rx_kill_vid	= dsa_user_vlan_rx_kill_vid,
	.ndo_change_mtu		= dsa_user_change_mtu,
	.ndo_fill_forward_path	= dsa_user_fill_forward_path,
	.ndo_hwtstamp_get	= dsa_user_hwtstamp_get,
	.ndo_hwtstamp_set	= dsa_user_hwtstamp_set,
};

static const struct device_type dsa_type = {
	.name	= "dsa",
};

void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up)
{
	const struct dsa_port *dp = dsa_to_port(ds, port);

	if (dp->pl)
		phylink_mac_change(dp->pl, up);
}
EXPORT_SYMBOL_GPL(dsa_port_phylink_mac_change);

static void dsa_user_phylink_fixed_state(struct phylink_config *config,
					 struct phylink_link_state *state)
{
	struct dsa_port *dp = dsa_phylink_to_port(config);
	struct dsa_switch *ds = dp->ds;

	/* No need to check that this operation is valid, the callback would
	 * not be called if it was not.
	 */
	ds->ops->phylink_fixed_state(ds, dp->index, state);
}

/* user device setup *******************************************************/
static int dsa_user_phy_connect(struct net_device *user_dev, int addr,
				u32 flags)
{
	struct dsa_port *dp = dsa_user_to_port(user_dev);
	struct dsa_switch *ds = dp->ds;

	user_dev->phydev = mdiobus_get_phy(ds->user_mii_bus, addr);
	if (!user_dev->phydev) {
		netdev_err(user_dev, "no phy at %d\n", addr);
		return -ENODEV;
	}

	user_dev->phydev->dev_flags |= flags;

	return phylink_connect_phy(dp->pl, user_dev->phydev);
}

static int dsa_user_phy_setup(struct net_device *user_dev)
{
	struct dsa_port *dp = dsa_user_to_port(user_dev);
	struct device_node *port_dn = dp->dn;
	struct dsa_switch *ds = dp->ds;
	u32 phy_flags = 0;
	int ret;

	dp->pl_config.dev = &user_dev->dev;
	dp->pl_config.type = PHYLINK_NETDEV;

	/* The get_fixed_state callback takes precedence over polling the
	 * link GPIO in PHYLINK (see phylink_get_fixed_state).  Only set
	 * this if the switch provides such a callback.
	 */
	if (ds->ops->phylink_fixed_state) {
		dp->pl_config.get_fixed_state = dsa_user_phylink_fixed_state;
		dp->pl_config.poll_fixed_state = true;
	}

	ret = dsa_port_phylink_create(dp);
	if (ret)

Annotation

Implementation Notes