drivers/net/ethernet/microchip/lan966x/lan966x_mac.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/microchip/lan966x/lan966x_mac.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/microchip/lan966x/lan966x_mac.c- Extension
.c- Size
- 16142 bytes
- Lines
- 593
- 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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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
net/switchdev.hlan966x_main.h
Detected Declarations
struct lan966x_mac_entrystruct lan966x_mac_raw_entryfunction lan966x_mac_get_statusfunction lan966x_mac_wait_for_completionfunction lan966x_mac_selectfunction __lan966x_mac_learn_lockedfunction __lan966x_mac_learnfunction lan966x_mdb_encode_macfunction lan966x_mac_learnfunction lan966x_mac_learn_lockedfunction lan966x_mac_forget_lockedfunction lan966x_mac_forgetfunction lan966x_mac_cpu_learnfunction lan966x_mac_cpu_forgetfunction lan966x_mac_set_ageingfunction lan966x_mac_initfunction list_for_each_entryfunction lan966x_mac_lookupfunction lan966x_fdb_call_notifiersfunction lan966x_mac_add_entryfunction lan966x_mac_del_entryfunction lan966x_mac_lag_replace_port_entryfunction lan966x_mac_lag_remove_port_entryfunction lan966x_mac_purge_entriesfunction lan966x_mac_notifiersfunction lan966x_mac_process_raw_entryfunction lan966x_mac_irq_processfunction list_for_each_entry_safefunction lan966x_mac_irq_handler
Annotated Snippet
struct lan966x_mac_entry {
struct list_head list;
unsigned char mac[ETH_ALEN] __aligned(2);
u16 vid;
u16 port_index;
int row;
bool lag;
};
struct lan966x_mac_raw_entry {
u32 mach;
u32 macl;
u32 maca;
bool processed;
};
static int lan966x_mac_get_status(struct lan966x *lan966x)
{
return lan_rd(lan966x, ANA_MACACCESS);
}
static int lan966x_mac_wait_for_completion(struct lan966x *lan966x)
{
u32 val;
return readx_poll_timeout_atomic(lan966x_mac_get_status,
lan966x, val,
(ANA_MACACCESS_MAC_TABLE_CMD_GET(val)) ==
MACACCESS_CMD_IDLE,
TABLE_UPDATE_SLEEP_US,
TABLE_UPDATE_TIMEOUT_US);
}
static void lan966x_mac_select(struct lan966x *lan966x,
const unsigned char mac[ETH_ALEN],
unsigned int vid)
{
u32 macl = 0, mach = 0;
/* Set the MAC address to handle and the vlan associated in a format
* understood by the hardware.
*/
mach |= vid << 16;
mach |= mac[0] << 8;
mach |= mac[1] << 0;
macl |= mac[2] << 24;
macl |= mac[3] << 16;
macl |= mac[4] << 8;
macl |= mac[5] << 0;
lan_wr(macl, lan966x, ANA_MACLDATA);
lan_wr(mach, lan966x, ANA_MACHDATA);
}
static int __lan966x_mac_learn_locked(struct lan966x *lan966x, int pgid,
bool cpu_copy,
const unsigned char mac[ETH_ALEN],
unsigned int vid,
enum macaccess_entry_type type)
{
lockdep_assert_held(&lan966x->mac_lock);
lan966x_mac_select(lan966x, mac, vid);
/* Issue a write command */
lan_wr(ANA_MACACCESS_VALID_SET(1) |
ANA_MACACCESS_CHANGE2SW_SET(0) |
ANA_MACACCESS_MAC_CPU_COPY_SET(cpu_copy) |
ANA_MACACCESS_DEST_IDX_SET(pgid) |
ANA_MACACCESS_ENTRYTYPE_SET(type) |
ANA_MACACCESS_MAC_TABLE_CMD_SET(MACACCESS_CMD_LEARN),
lan966x, ANA_MACACCESS);
return lan966x_mac_wait_for_completion(lan966x);
}
static int __lan966x_mac_learn(struct lan966x *lan966x, int pgid,
bool cpu_copy,
const unsigned char mac[ETH_ALEN],
unsigned int vid,
enum macaccess_entry_type type)
{
int ret;
spin_lock(&lan966x->mac_lock);
ret = __lan966x_mac_learn_locked(lan966x, pgid, cpu_copy, mac, vid, type);
spin_unlock(&lan966x->mac_lock);
return ret;
}
Annotation
- Immediate include surface: `net/switchdev.h`, `lan966x_main.h`.
- Detected declarations: `struct lan966x_mac_entry`, `struct lan966x_mac_raw_entry`, `function lan966x_mac_get_status`, `function lan966x_mac_wait_for_completion`, `function lan966x_mac_select`, `function __lan966x_mac_learn_locked`, `function __lan966x_mac_learn`, `function lan966x_mdb_encode_mac`, `function lan966x_mac_learn`, `function lan966x_mac_learn_locked`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.