net/dsa/tag_brcm.c

Source file repositories/reference/linux-study-clean/net/dsa/tag_brcm.c

File Facts

System
Linux kernel
Corpus path
net/dsa/tag_brcm.c
Extension
.c
Size
11906 bytes
Lines
419
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: implementation source
Status
source implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0+
/*
 * Broadcom tag support
 *
 * Copyright (C) 2014 Broadcom Corporation
 */

#include <linux/dsa/brcm.h>
#include <linux/etherdevice.h>
#include <linux/if_vlan.h>
#include <linux/list.h>
#include <linux/slab.h>

#include "tag.h"

#define BRCM_NAME		"brcm"
#define BRCM_LEGACY_NAME	"brcm-legacy"
#define BRCM_LEGACY_FCS_NAME	"brcm-legacy-fcs"
#define BRCM_PREPEND_NAME	"brcm-prepend"

/* Legacy Broadcom tag (6 bytes) */
#define BRCM_LEG_TAG_LEN	6

/* Type fields */
/* 1st byte in the tag */
#define BRCM_LEG_TYPE_HI	0x88
/* 2nd byte in the tag */
#define BRCM_LEG_TYPE_LO	0x74

/* Tag fields */
/* 3rd byte in the tag */
#define BRCM_LEG_UNICAST	(0 << 5)
#define BRCM_LEG_MULTICAST	(1 << 5)
#define BRCM_LEG_EGRESS		(2 << 5)
#define BRCM_LEG_INGRESS	(3 << 5)
#define BRCM_LEG_LEN_HI(x)	(((x) >> 8) & 0x7)

/* 4th byte in the tag */
#define BRCM_LEG_LEN_LO(x)	((x) & 0xff)

/* 6th byte in the tag */
#define BRCM_LEG_PORT_ID	(0xf)

/* Newer Broadcom tag (4 bytes) */
#define BRCM_TAG_LEN	4

/* Tag is constructed and deconstructed using byte by byte access
 * because the tag is placed after the MAC Source Address, which does
 * not make it 4-bytes aligned, so this might cause unaligned accesses
 * on most systems where this is used.
 */

/* Ingress and egress opcodes */
#define BRCM_OPCODE_SHIFT	5
#define BRCM_OPCODE_MASK	0x7

/* Ingress fields */
/* 1st byte in the tag */
#define BRCM_IG_TC_SHIFT	2
#define BRCM_IG_TC_MASK		0x7
/* 2nd byte in the tag */
#define BRCM_IG_TE_MASK		0x3
#define BRCM_IG_TS_SHIFT	7
/* 3rd byte in the tag */
#define BRCM_IG_DSTMAP2_MASK	1
#define BRCM_IG_DSTMAP1_MASK	0xff

/* Egress fields */

/* 2nd byte in the tag */
#define BRCM_EG_CID_MASK	0xff

/* 3rd byte in the tag */
#define BRCM_EG_RC_MASK		0xff
#define  BRCM_EG_RC_RSVD	(3 << 6)
#define  BRCM_EG_RC_EXCEPTION	(1 << 5)
#define  BRCM_EG_RC_PROT_SNOOP	(1 << 4)
#define  BRCM_EG_RC_PROT_TERM	(1 << 3)
#define  BRCM_EG_RC_SWITCH	(1 << 2)
#define  BRCM_EG_RC_MAC_LEARN	(1 << 1)
#define  BRCM_EG_RC_MIRROR	(1 << 0)
#define BRCM_EG_TC_SHIFT	5
#define BRCM_EG_TC_MASK		0x7
#define BRCM_EG_PID_MASK	0x1f

#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) || \
	IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND)

static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,
					struct net_device *dev,

Annotation

Implementation Notes