drivers/net/dsa/mv88e6xxx/tcflower.c

Source file repositories/reference/linux-study-clean/drivers/net/dsa/mv88e6xxx/tcflower.c

File Facts

System
Linux kernel
Corpus path
drivers/net/dsa/mv88e6xxx/tcflower.c
Extension
.c
Size
4155 bytes
Lines
168
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

BIT_ULL(FLOW_DISSECTOR_KEY_IPV4_ADDRS))) {
		NL_SET_ERR_MSG_MOD(extack,
				   "Unsupported keys used");
		return -EOPNOTSUPP;
	}

	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
		struct flow_match_control match;

		flow_rule_match_control(rule, &match);
		addr_type = match.key->addr_type;

		if (flow_rule_has_control_flags(match.mask->flags,
						cls->common.extack))
			return -EOPNOTSUPP;
	}
	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
		struct flow_match_basic match;

		flow_rule_match_basic(rule, &match);
		mv88e6xxx_tcam_match_set(key, MV88E6XXX_ETHTYPE_OFFSET,
					 match.key->n_proto,
					 match.mask->n_proto);
		mv88e6xxx_tcam_match_set(key, MV88E6XXX_IP_PROTO_OFFSET,
					 match.key->ip_proto,
					 match.mask->ip_proto);
	}

	if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
		struct flow_match_ipv4_addrs match;

		flow_rule_match_ipv4_addrs(cls->rule, &match);
		mv88e6xxx_tcam_match_set(key, MV88E6XXX_IPV4_SRC_OFFSET,
					 match.key->src,
					 match.mask->src);
		mv88e6xxx_tcam_match_set(key, MV88E6XXX_IPV4_DST_OFFSET,
					 match.key->dst,
					 match.mask->dst);
	}

	return 0;
}

int mv88e6xxx_cls_flower_add(struct dsa_switch *ds, int port,
			     struct flow_cls_offload *cls, bool ingress)
{
	struct flow_rule *rule = flow_cls_offload_flow_rule(cls);
	struct netlink_ext_ack *extack = cls->common.extack;
	struct mv88e6xxx_chip *chip = ds->priv;
	struct mv88e6xxx_tcam_key key = { 0 };
	const struct flow_action_entry *act;
	unsigned long cookie = cls->cookie;
	struct mv88e6xxx_tcam_entry *entry;
	int err, i;

	if (!mv88e6xxx_has_tcam(chip)) {
		NL_SET_ERR_MSG_MOD(extack, "hardware offload not supported");
		return -EOPNOTSUPP;
	}

	err = mv88e6xxx_flower_parse_key(chip, extack, cls, &key);
	if (err)
		return err;

	mv88e6xxx_reg_lock(chip);
	entry = mv88e6xxx_tcam_entry_find(chip, cookie);
	if (entry) {
		err = -EEXIST;
		goto err_unlock;
	}

	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
	if (!entry) {
		err = -ENOMEM;
		goto err_unlock;
	}

	entry->cookie = cookie;
	entry->prio = cls->common.prio;
	entry->key = key;

	flow_action_for_each(i, act, &rule->action) {
		switch (act->id) {
		case FLOW_ACTION_TRAP: {
			int cpu = dsa_upstream_port(ds, port);

			entry->action.dpv_mode = DPV_MODE_REPLACE;
			entry->action.dpv = BIT(cpu);
			break;
		}

Annotation

Implementation Notes