drivers/net/ethernet/ti/am65-cpsw-switchdev.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/ti/am65-cpsw-switchdev.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/ti/am65-cpsw-switchdev.c
Extension
.c
Size
14306 bytes
Lines
535
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct am65_cpsw_switchdev_event_work {
	struct work_struct work;
	struct switchdev_notifier_fdb_info fdb_info;
	struct am65_cpsw_port *port;
	unsigned long event;
};

static int am65_cpsw_port_stp_state_set(struct am65_cpsw_port *port, u8 state)
{
	struct am65_cpsw_common *cpsw = port->common;
	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, port->port_id,
				   ALE_PORT_STATE, cpsw_state);
	netdev_dbg(port->ndev, "ale state: %u\n", cpsw_state);

	return ret;
}

static int am65_cpsw_port_attr_br_flags_set(struct am65_cpsw_port *port,
					    struct net_device *orig_dev,
					    struct switchdev_brport_flags flags)
{
	struct am65_cpsw_common *cpsw = port->common;

	if (flags.mask & BR_MCAST_FLOOD) {
		bool unreg_mcast_add = false;

		if (flags.val & BR_MCAST_FLOOD)
			unreg_mcast_add = true;

		netdev_dbg(port->ndev, "BR_MCAST_FLOOD: %d port %u\n",
			   unreg_mcast_add, port->port_id);

		cpsw_ale_set_unreg_mcast(cpsw->ale, BIT(port->port_id),
					 unreg_mcast_add);
	}

	return 0;
}

static int am65_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 am65_cpsw_port_attr_set(struct net_device *ndev, const void *ctx,
				   const struct switchdev_attr *attr,
				   struct netlink_ext_ack *extack)
{
	struct am65_cpsw_port *port = am65_ndev_to_port(ndev);
	int ret;

	netdev_dbg(ndev, "attr: id %u port: %u\n", attr->id, port->port_id);

	switch (attr->id) {
	case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
		ret = am65_cpsw_port_attr_br_flags_pre_set(ndev,
							   attr->u.brport_flags);
		break;
	case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
		ret = am65_cpsw_port_stp_state_set(port, attr->u.stp_state);
		netdev_dbg(ndev, "stp state: %u\n", attr->u.stp_state);
		break;
	case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
		ret = am65_cpsw_port_attr_br_flags_set(port, attr->orig_dev,
						       attr->u.brport_flags);

Annotation

Implementation Notes