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.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/list.hlinux/etherdevice.hlinux/netdevice.hlinux/phy.hlinux/phy_fixed.hlinux/phylink.hlinux/of_net.hlinux/of_mdio.hlinux/mdio.hnet/rtnetlink.hnet/pkt_cls.hnet/selftests.hnet/tc_act/tc_mirred.hlinux/if_bridge.hlinux/if_hsr.hnet/dcbnl.hlinux/netpoll.hlinux/string.hconduit.hdsa.hnetlink.hport.hswitch.htag.huser.h
Detected Declarations
struct dsa_switchdev_event_workstruct dsa_standalone_event_workstruct dsa_host_vlan_rx_filtering_ctxstruct dsa_user_dump_ctxstruct dsa_hw_portenum dsa_standalone_eventfunction dsa_switch_supports_uc_filteringfunction dsa_switch_supports_mc_filteringfunction dsa_user_standalone_event_workfunction dsa_user_schedule_standalone_workfunction dsa_user_host_vlan_rx_filteringfunction dsa_user_vlan_for_eachfunction list_for_each_entryfunction dsa_user_sync_ucfunction dsa_user_unsync_ucfunction dsa_user_sync_mcfunction dsa_user_unsync_mcfunction dsa_user_sync_hafunction dsa_user_unsync_hafunction dsa_user_phy_readfunction dsa_user_phy_writefunction dsa_user_mii_bus_initfunction dsa_user_get_iflinkfunction dsa_user_host_uc_installfunction dsa_user_host_uc_uninstallfunction dsa_user_openfunction dsa_user_closefunction dsa_user_manage_host_floodfunction dsa_user_change_rx_flagsfunction dsa_user_set_rx_modefunction dsa_user_set_mac_addressfunction dsa_user_port_fdb_do_dumpfunction dsa_user_fdb_dumpfunction dsa_user_ioctlfunction dsa_user_port_attr_setfunction dsa_user_vlan_check_for_8021q_uppersfunction netdev_for_each_upper_dev_rcufunction dsa_user_vlan_addfunction dsa_user_host_vlan_addfunction dsa_user_port_obj_addfunction dsa_user_vlan_delfunction dsa_user_host_vlan_delfunction dsa_user_port_obj_delfunction dsa_user_netpoll_send_skbfunction dsa_skb_tx_timestampfunction dsa_enqueue_skbfunction dsa_user_xmitfunction dsa_user_get_drvinfo
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
- Immediate include surface: `linux/list.h`, `linux/etherdevice.h`, `linux/netdevice.h`, `linux/phy.h`, `linux/phy_fixed.h`, `linux/phylink.h`, `linux/of_net.h`, `linux/of_mdio.h`.
- Detected declarations: `struct dsa_switchdev_event_work`, `struct dsa_standalone_event_work`, `struct dsa_host_vlan_rx_filtering_ctx`, `struct dsa_user_dump_ctx`, `struct dsa_hw_port`, `enum dsa_standalone_event`, `function dsa_switch_supports_uc_filtering`, `function dsa_switch_supports_mc_filtering`, `function dsa_user_standalone_event_work`, `function dsa_user_schedule_standalone_work`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern 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.