net/dsa/tag_sja1105.c
Source file repositories/reference/linux-study-clean/net/dsa/tag_sja1105.c
File Facts
- System
- Linux kernel
- Corpus path
net/dsa/tag_sja1105.c- Extension
.c- Size
- 22622 bytes
- Lines
- 763
- 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.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- 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/if_vlan.hlinux/dsa/sja1105.hlinux/dsa/8021q.hlinux/packing.htag.htag_8021q.h
Detected Declarations
struct sja1105_tagger_privatestruct sja1105_metafunction sja1105_tagger_privatefunction sja1105_is_link_localfunction sja1105_meta_unpackfunction sja1105_is_meta_framefunction sja1105_xmit_tpidfunction sja1105_transfer_metafunction skbfunction nowfunction sja1105_skb_has_tag_8021qfunction sja1110_skb_has_inband_control_extensionfunction sja1105_flow_dissectfunction sja1110_flow_dissectfunction sja1105_disconnectfunction sja1105_connect
Annotated Snippet
struct sja1105_tagger_private {
struct sja1105_tagger_data data; /* Must be first */
/* Protects concurrent access to the meta state machine
* from taggers running on multiple ports on SMP systems
*/
spinlock_t meta_lock;
struct sk_buff *stampable_skb;
struct kthread_worker *xmit_worker;
};
static struct sja1105_tagger_private *
sja1105_tagger_private(struct dsa_switch *ds)
{
return ds->tagger_data;
}
/* Similar to is_link_local_ether_addr(hdr->h_dest) but also covers PTP */
static bool sja1105_is_link_local(const struct sk_buff *skb)
{
const struct ethhdr *hdr = eth_hdr(skb);
u64 dmac = ether_addr_to_u64(hdr->h_dest);
if (ntohs(hdr->h_proto) == ETH_P_SJA1105_META)
return false;
if ((dmac & SJA1105_LINKLOCAL_FILTER_A_MASK) ==
SJA1105_LINKLOCAL_FILTER_A)
return true;
if ((dmac & SJA1105_LINKLOCAL_FILTER_B_MASK) ==
SJA1105_LINKLOCAL_FILTER_B)
return true;
return false;
}
struct sja1105_meta {
u64 tstamp;
u64 dmac_byte_4;
u64 dmac_byte_3;
u64 source_port;
u64 switch_id;
};
static void sja1105_meta_unpack(const struct sk_buff *skb,
struct sja1105_meta *meta)
{
u8 *buf = skb_mac_header(skb) + ETH_HLEN;
/* UM10944.pdf section 4.2.17 AVB Parameters:
* Structure of the meta-data follow-up frame.
* It is in network byte order, so there are no quirks
* while unpacking the meta frame.
*
* Also SJA1105 E/T only populates bits 23:0 of the timestamp
* whereas P/Q/R/S does 32 bits. Since the structure is the
* same and the E/T puts zeroes in the high-order byte, use
* a unified unpacking command for both device series.
*/
packing(buf, &meta->tstamp, 31, 0, 4, UNPACK, 0);
packing(buf + 4, &meta->dmac_byte_3, 7, 0, 1, UNPACK, 0);
packing(buf + 5, &meta->dmac_byte_4, 7, 0, 1, UNPACK, 0);
packing(buf + 6, &meta->source_port, 7, 0, 1, UNPACK, 0);
packing(buf + 7, &meta->switch_id, 7, 0, 1, UNPACK, 0);
}
static bool sja1105_is_meta_frame(const struct sk_buff *skb)
{
const struct ethhdr *hdr = eth_hdr(skb);
u64 smac = ether_addr_to_u64(hdr->h_source);
u64 dmac = ether_addr_to_u64(hdr->h_dest);
if (smac != SJA1105_META_SMAC)
return false;
if (dmac != SJA1105_META_DMAC)
return false;
if (ntohs(hdr->h_proto) != ETH_P_SJA1105_META)
return false;
return true;
}
/* Calls sja1105_port_deferred_xmit in sja1105_main.c */
static struct sk_buff *sja1105_defer_xmit(struct dsa_port *dp,
struct sk_buff *skb)
{
struct sja1105_tagger_data *tagger_data = sja1105_tagger_data(dp->ds);
struct sja1105_tagger_private *priv = sja1105_tagger_private(dp->ds);
void (*xmit_work_fn)(struct kthread_work *work);
struct sja1105_deferred_xmit_work *xmit_work;
struct kthread_worker *xmit_worker;
xmit_work_fn = tagger_data->xmit_work_fn;
xmit_worker = priv->xmit_worker;
Annotation
- Immediate include surface: `linux/if_vlan.h`, `linux/dsa/sja1105.h`, `linux/dsa/8021q.h`, `linux/packing.h`, `tag.h`, `tag_8021q.h`.
- Detected declarations: `struct sja1105_tagger_private`, `struct sja1105_meta`, `function sja1105_tagger_private`, `function sja1105_is_link_local`, `function sja1105_meta_unpack`, `function sja1105_is_meta_frame`, `function sja1105_xmit_tpid`, `function sja1105_transfer_meta`, `function skb`, `function now`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- 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.