drivers/net/ethernet/marvell/prestera/prestera_router.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/marvell/prestera/prestera_router.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/marvell/prestera/prestera_router.c- Extension
.c- Size
- 43120 bytes
- Lines
- 1646
- 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.
- 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/kernel.hlinux/types.hlinux/inetdevice.hnet/inet_dscp.hnet/switchdev.hlinux/rhashtable.hnet/nexthop.hnet/arp.hlinux/if_vlan.hlinux/if_macvlan.hnet/netevent.hprestera.hprestera_router_hw.h
Detected Declarations
struct prestera_kern_neigh_cache_keystruct prestera_kern_neigh_cachestruct prestera_kern_fib_cache_keystruct prestera_kern_fib_cachestruct prestera_kern_neigh_cache_headstruct prestera_fib_event_workstruct prestera_netevent_workfunction prestera_fix_tb_idfunction prestera_util_fen_info2fib_cache_keyfunction prestera_util_nhc2nc_keyfunction prestera_util_nc_key2nh_keyfunction prestera_util_nhc_eq_n_cache_keyfunction prestera_util_neigh2nc_keyfunction __prestera_fi_is_directfunction prestera_fi_is_directfunction prestera_fi_is_nhfunction __prestera_fi6_is_directfunction prestera_fi6_is_directfunction prestera_fi6_is_nhfunction prestera_fib_info_is_directfunction prestera_fib_info_is_nhfunction prestera_util_kern_get_routefunction __prestera_util_kern_n_is_reachable_v4function prestera_util_kern_n_is_reachablefunction prestera_util_kern_set_neigh_offloadfunction prestera_util_kern_set_nh_offloadfunction prestera_kern_fib_info_nhcfunction list_for_each_entryfunction prestera_kern_fib_info_nhsfunction prestera_kern_fib_info_typefunction prestera_fib_node_util_is_neighbourfunction prestera_dev_if_typefunction prestera_neigh_iface_initfunction prestera_kern_neigh_cache_findfunction __prestera_kern_neigh_cache_destructfunction __prestera_kern_neigh_cache_destroyfunction __prestera_kern_neigh_cache_createfunction prestera_kern_neigh_cache_getfunction prestera_kern_neigh_cache_putfunction prestera_kern_fib_cache_findfunction __prestera_kern_fib_cache_destructfunction prestera_kern_fib_cache_destroyfunction __prestera_kern_fib_cache_create_nhsfunction prestera_kern_fib_cache_createfunction __prestera_k_arb_fib_nh_offload_setfunction __prestera_k_arb_n_offload_setfunction __prestera_k_arb_fib_lpm_offload_setfunction __prestera_k_arb_n_lpm_set
Annotated Snippet
struct prestera_kern_neigh_cache_key {
struct prestera_ip_addr addr;
struct net_device *dev;
};
struct prestera_kern_neigh_cache {
struct prestera_kern_neigh_cache_key key;
struct rhash_head ht_node;
struct list_head kern_fib_cache_list;
/* Hold prepared nh_neigh info if is in_kernel */
struct prestera_neigh_info nh_neigh_info;
/* Indicate if neighbour is reachable by direct route */
bool reachable;
/* Lock cache if neigh is present in kernel */
bool in_kernel;
};
struct prestera_kern_fib_cache_key {
struct prestera_ip_addr addr;
u32 prefix_len;
u32 kern_tb_id; /* tb_id from kernel (not fixed) */
};
/* Subscribing on neighbours in kernel */
struct prestera_kern_fib_cache {
struct prestera_kern_fib_cache_key key;
struct {
struct prestera_fib_key fib_key;
enum prestera_fib_type fib_type;
struct prestera_nexthop_group_key nh_grp_key;
} lpm_info; /* hold prepared lpm info */
/* Indicate if route is not overlapped by another table */
struct rhash_head ht_node; /* node of prestera_router */
struct prestera_kern_neigh_cache_head {
struct prestera_kern_fib_cache *this;
struct list_head head;
struct prestera_kern_neigh_cache *n_cache;
} kern_neigh_cache_head[PRESTERA_NHGR_SIZE_MAX];
union {
struct fib_notifier_info info; /* point to any of 4/6 */
struct fib_entry_notifier_info fen4_info;
};
bool reachable;
};
static const struct rhashtable_params __prestera_kern_neigh_cache_ht_params = {
.key_offset = offsetof(struct prestera_kern_neigh_cache, key),
.head_offset = offsetof(struct prestera_kern_neigh_cache, ht_node),
.key_len = sizeof(struct prestera_kern_neigh_cache_key),
.automatic_shrinking = true,
};
static const struct rhashtable_params __prestera_kern_fib_cache_ht_params = {
.key_offset = offsetof(struct prestera_kern_fib_cache, key),
.head_offset = offsetof(struct prestera_kern_fib_cache, ht_node),
.key_len = sizeof(struct prestera_kern_fib_cache_key),
.automatic_shrinking = true,
};
/* This util to be used, to convert kernel rules for default vr in hw_vr */
static u32 prestera_fix_tb_id(u32 tb_id)
{
if (tb_id == RT_TABLE_UNSPEC ||
tb_id == RT_TABLE_LOCAL ||
tb_id == RT_TABLE_DEFAULT)
tb_id = RT_TABLE_MAIN;
return tb_id;
}
static void
prestera_util_fen_info2fib_cache_key(struct fib_notifier_info *info,
struct prestera_kern_fib_cache_key *key)
{
struct fib_entry_notifier_info *fen_info =
container_of(info, struct fib_entry_notifier_info, info);
memset(key, 0, sizeof(*key));
key->addr.v = PRESTERA_IPV4;
key->addr.u.ipv4 = cpu_to_be32(fen_info->dst);
key->prefix_len = fen_info->dst_len;
key->kern_tb_id = fen_info->tb_id;
}
static int prestera_util_nhc2nc_key(struct prestera_switch *sw,
struct fib_nh_common *nhc,
struct prestera_kern_neigh_cache_key *nk)
{
memset(nk, 0, sizeof(*nk));
if (nhc->nhc_gw_family == AF_INET) {
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/inetdevice.h`, `net/inet_dscp.h`, `net/switchdev.h`, `linux/rhashtable.h`, `net/nexthop.h`, `net/arp.h`.
- Detected declarations: `struct prestera_kern_neigh_cache_key`, `struct prestera_kern_neigh_cache`, `struct prestera_kern_fib_cache_key`, `struct prestera_kern_fib_cache`, `struct prestera_kern_neigh_cache_head`, `struct prestera_fib_event_work`, `struct prestera_netevent_work`, `function prestera_fix_tb_id`, `function prestera_util_fen_info2fib_cache_key`, `function prestera_util_nhc2nc_key`.
- 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.
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.