drivers/net/ethernet/ti/cpsw_switchdev.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/ti/cpsw_switchdev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/ti/cpsw_switchdev.c- Extension
.c- Size
- 13760 bytes
- Lines
- 545
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/etherdevice.hlinux/if_bridge.hlinux/netdevice.hlinux/workqueue.hnet/switchdev.hcpsw.hcpsw_ale.hcpsw_priv.hcpsw_switchdev.h
Detected Declarations
struct cpsw_switchdev_event_workfunction cpsw_port_stp_state_setfunction cpsw_port_attr_br_flags_setfunction cpsw_port_attr_br_flags_pre_setfunction cpsw_port_attr_setfunction cpsw_get_pvidfunction cpsw_set_pvidfunction cpsw_port_vlan_addfunction cpsw_port_vlan_delfunction cpsw_port_vlans_addfunction cpsw_port_mdb_addfunction cpsw_port_mdb_delfunction cpsw_port_obj_addfunction cpsw_port_obj_delfunction cpsw_fdb_offload_notifyfunction cpsw_switchdev_event_workfunction cpsw_switchdev_eventfunction cpsw_switchdev_blocking_eventfunction cpsw_switchdev_register_notifiersfunction cpsw_switchdev_unregister_notifiers
Annotated Snippet
struct cpsw_switchdev_event_work {
struct work_struct work;
struct switchdev_notifier_fdb_info fdb_info;
struct cpsw_priv *priv;
unsigned long event;
};
static int cpsw_port_stp_state_set(struct cpsw_priv *priv, u8 state)
{
struct cpsw_common *cpsw = priv->cpsw;
u8 cpsw_state;
int ret = 0;
switch (state) {
case BR_STATE_FORWARDING:
cpsw_state = ALE_PORT_STATE_FORWARD;
break;
case BR_STATE_LEARNING:
cpsw_state = ALE_PORT_STATE_LEARN;
break;
case BR_STATE_DISABLED:
cpsw_state = ALE_PORT_STATE_DISABLE;
break;
case BR_STATE_LISTENING:
case BR_STATE_BLOCKING:
cpsw_state = ALE_PORT_STATE_BLOCK;
break;
default:
return -EOPNOTSUPP;
}
ret = cpsw_ale_control_set(cpsw->ale, priv->emac_port,
ALE_PORT_STATE, cpsw_state);
dev_dbg(priv->dev, "ale state: %u\n", cpsw_state);
return ret;
}
static int cpsw_port_attr_br_flags_set(struct cpsw_priv *priv,
struct net_device *orig_dev,
struct switchdev_brport_flags flags)
{
struct cpsw_common *cpsw = priv->cpsw;
if (flags.mask & BR_MCAST_FLOOD) {
bool unreg_mcast_add = false;
if (flags.val & BR_MCAST_FLOOD)
unreg_mcast_add = true;
dev_dbg(priv->dev, "BR_MCAST_FLOOD: %d port %u\n",
unreg_mcast_add, priv->emac_port);
cpsw_ale_set_unreg_mcast(cpsw->ale, BIT(priv->emac_port),
unreg_mcast_add);
}
return 0;
}
static int cpsw_port_attr_br_flags_pre_set(struct net_device *netdev,
struct switchdev_brport_flags flags)
{
if (flags.mask & ~(BR_LEARNING | BR_MCAST_FLOOD))
return -EINVAL;
return 0;
}
static int cpsw_port_attr_set(struct net_device *ndev, const void *ctx,
const struct switchdev_attr *attr,
struct netlink_ext_ack *extack)
{
struct cpsw_priv *priv = netdev_priv(ndev);
int ret;
dev_dbg(priv->dev, "attr: id %u port: %u\n", attr->id, priv->emac_port);
switch (attr->id) {
case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
ret = cpsw_port_attr_br_flags_pre_set(ndev,
attr->u.brport_flags);
break;
case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
ret = cpsw_port_stp_state_set(priv, attr->u.stp_state);
dev_dbg(priv->dev, "stp state: %u\n", attr->u.stp_state);
break;
case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
ret = cpsw_port_attr_br_flags_set(priv, attr->orig_dev,
attr->u.brport_flags);
Annotation
- Immediate include surface: `linux/etherdevice.h`, `linux/if_bridge.h`, `linux/netdevice.h`, `linux/workqueue.h`, `net/switchdev.h`, `cpsw.h`, `cpsw_ale.h`, `cpsw_priv.h`.
- Detected declarations: `struct cpsw_switchdev_event_work`, `function cpsw_port_stp_state_set`, `function cpsw_port_attr_br_flags_set`, `function cpsw_port_attr_br_flags_pre_set`, `function cpsw_port_attr_set`, `function cpsw_get_pvid`, `function cpsw_set_pvid`, `function cpsw_port_vlan_add`, `function cpsw_port_vlan_del`, `function cpsw_port_vlans_add`.
- Atlas domain: Driver Families / drivers/net.
- 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.