drivers/net/ethernet/microchip/lan966x/lan966x_mdb.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/microchip/lan966x/lan966x_mdb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/microchip/lan966x/lan966x_mdb.c- Extension
.c- Size
- 14933 bytes
- Lines
- 552
- 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.
- 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_pgid_entrystruct lan966x_mdb_entryfunction lan966x_mdb_initfunction lan966x_mdb_purge_mdb_entriesfunction list_for_each_entry_safefunction lan966x_mdb_purge_pgid_entriesfunction list_for_each_entry_safefunction lan966x_mdb_deinitfunction lan966x_mdb_entry_getfunction list_for_each_entryfunction lan966x_mdb_entry_addfunction lan966x_mdb_encode_macfunction lan966x_mdb_ip_addfunction lan966x_mdb_ip_delfunction lan966x_pgid_entry_addfunction lan966x_pgid_entry_getfunction list_for_each_entryfunction lan966x_pgid_entry_delfunction lan966x_mdb_l2_addfunction lan966x_mdb_l2_delfunction lan966x_mdb_classifyfunction lan966x_handle_port_mdb_addfunction lan966x_handle_port_mdb_delfunction lan966x_mdb_ip_cpu_copyfunction lan966x_mdb_l2_cpu_copyfunction lan966x_mdb_write_entriesfunction list_for_each_entryfunction lan966x_mdb_ip_cpu_removefunction lan966x_mdb_l2_cpu_removefunction lan966x_mdb_erase_entriesfunction list_for_each_entryfunction lan966x_mdb_clear_entriesfunction list_for_each_entryfunction lan966x_mdb_restore_entriesfunction list_for_each_entry
Annotated Snippet
struct lan966x_pgid_entry {
struct list_head list;
int index;
refcount_t refcount;
u16 ports;
};
struct lan966x_mdb_entry {
struct list_head list;
unsigned char mac[ETH_ALEN];
u16 vid;
u16 ports;
struct lan966x_pgid_entry *pgid;
u8 cpu_copy;
};
void lan966x_mdb_init(struct lan966x *lan966x)
{
INIT_LIST_HEAD(&lan966x->mdb_entries);
INIT_LIST_HEAD(&lan966x->pgid_entries);
}
static void lan966x_mdb_purge_mdb_entries(struct lan966x *lan966x)
{
struct lan966x_mdb_entry *mdb_entry, *tmp;
list_for_each_entry_safe(mdb_entry, tmp, &lan966x->mdb_entries, list) {
list_del(&mdb_entry->list);
kfree(mdb_entry);
}
}
static void lan966x_mdb_purge_pgid_entries(struct lan966x *lan966x)
{
struct lan966x_pgid_entry *pgid_entry, *tmp;
list_for_each_entry_safe(pgid_entry, tmp, &lan966x->pgid_entries, list) {
list_del(&pgid_entry->list);
kfree(pgid_entry);
}
}
void lan966x_mdb_deinit(struct lan966x *lan966x)
{
lan966x_mdb_purge_mdb_entries(lan966x);
lan966x_mdb_purge_pgid_entries(lan966x);
}
static struct lan966x_mdb_entry *
lan966x_mdb_entry_get(struct lan966x *lan966x,
const unsigned char *mac,
u16 vid)
{
struct lan966x_mdb_entry *mdb_entry;
list_for_each_entry(mdb_entry, &lan966x->mdb_entries, list) {
if (ether_addr_equal(mdb_entry->mac, mac) &&
mdb_entry->vid == vid)
return mdb_entry;
}
return NULL;
}
static struct lan966x_mdb_entry *
lan966x_mdb_entry_add(struct lan966x *lan966x,
const struct switchdev_obj_port_mdb *mdb)
{
struct lan966x_mdb_entry *mdb_entry;
mdb_entry = kzalloc_obj(*mdb_entry);
if (!mdb_entry)
return ERR_PTR(-ENOMEM);
ether_addr_copy(mdb_entry->mac, mdb->addr);
mdb_entry->vid = mdb->vid;
list_add_tail(&mdb_entry->list, &lan966x->mdb_entries);
return mdb_entry;
}
static void lan966x_mdb_encode_mac(unsigned char *mac,
struct lan966x_mdb_entry *mdb_entry,
enum macaccess_entry_type type)
{
ether_addr_copy(mac, mdb_entry->mac);
if (type == ENTRYTYPE_MACV4) {
mac[0] = 0;
Annotation
- Immediate include surface: `net/switchdev.h`, `lan966x_main.h`.
- Detected declarations: `struct lan966x_pgid_entry`, `struct lan966x_mdb_entry`, `function lan966x_mdb_init`, `function lan966x_mdb_purge_mdb_entries`, `function list_for_each_entry_safe`, `function lan966x_mdb_purge_pgid_entries`, `function list_for_each_entry_safe`, `function lan966x_mdb_deinit`, `function lan966x_mdb_entry_get`, `function list_for_each_entry`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
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.