drivers/net/ethernet/ti/icssg/icssg_switchdev.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/ti/icssg/icssg_switchdev.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/ti/icssg/icssg_switchdev.c
Extension
.c
Size
12361 bytes
Lines
478
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 prueth_switchdev_event_work {
	struct work_struct work;
	struct switchdev_notifier_fdb_info fdb_info;
	struct prueth_emac *emac;
	unsigned long event;
};

static int prueth_switchdev_stp_state_set(struct prueth_emac *emac,
					  u8 state)
{
	enum icssg_port_state_cmd emac_state;
	int ret = 0;

	switch (state) {
	case BR_STATE_FORWARDING:
		emac_state = ICSSG_EMAC_PORT_FORWARD;
		break;
	case BR_STATE_DISABLED:
		emac_state = ICSSG_EMAC_PORT_DISABLE;
		break;
	case BR_STATE_LISTENING:
	case BR_STATE_BLOCKING:
		emac_state = ICSSG_EMAC_PORT_BLOCK;
		break;
	default:
		return -EOPNOTSUPP;
	}

	icssg_set_port_state(emac, emac_state);
	netdev_dbg(emac->ndev, "STP state: %u\n", emac_state);

	return ret;
}

static int prueth_switchdev_attr_br_flags_set(struct prueth_emac *emac,
					      struct net_device *orig_dev,
					      struct switchdev_brport_flags brport_flags)
{
	enum icssg_port_state_cmd emac_state;

	if (brport_flags.mask & BR_MCAST_FLOOD)
		emac_state = ICSSG_EMAC_PORT_MC_FLOODING_ENABLE;
	else
		emac_state = ICSSG_EMAC_PORT_MC_FLOODING_DISABLE;

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

	icssg_set_port_state(emac, emac_state);

	return 0;
}

static int prueth_switchdev_attr_br_flags_pre_set(struct net_device *netdev,
						  struct switchdev_brport_flags brport_flags)
{
	if (brport_flags.mask & ~(BR_LEARNING | BR_MCAST_FLOOD))
		return -EINVAL;

	return 0;
}

static int prueth_switchdev_attr_set(struct net_device *ndev, const void *ctx,
				     const struct switchdev_attr *attr,
				     struct netlink_ext_ack *extack)
{
	struct prueth_emac *emac = netdev_priv(ndev);
	int ret;

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

	switch (attr->id) {
	case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
		ret = prueth_switchdev_attr_br_flags_pre_set(ndev,
							     attr->u.brport_flags);
		break;
	case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
		ret = prueth_switchdev_stp_state_set(emac,
						     attr->u.stp_state);
		netdev_dbg(ndev, "stp state: %u\n", attr->u.stp_state);
		break;
	case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
		ret = prueth_switchdev_attr_br_flags_set(emac, attr->orig_dev,
							 attr->u.brport_flags);
		break;
	default:
		ret = -EOPNOTSUPP;
		break;
	}

Annotation

Implementation Notes