drivers/net/ethernet/mellanox/mlxsw/spectrum_pgt.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxsw/spectrum_pgt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlxsw/spectrum_pgt.c- Extension
.c- Size
- 7926 bytes
- Lines
- 337
- 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/refcount.hlinux/idr.hspectrum.hreg.h
Detected Declarations
struct mlxsw_sp_pgtstruct mlxsw_sp_pgt_entrystruct mlxsw_sp_pgt_entry_portfunction mlxsw_sp_pgt_mid_allocfunction mlxsw_sp_pgt_mid_freefunction mlxsw_sp_pgt_mid_alloc_rangefunction mlxsw_sp_pgt_mid_free_rangefunction mlxsw_sp_pgt_entry_port_lookupfunction list_for_each_entryfunction mlxsw_sp_pgt_entry_createfunction mlxsw_sp_pgt_entry_destroyfunction mlxsw_sp_pgt_entry_getfunction mlxsw_sp_pgt_entry_putfunction mlxsw_sp_pgt_smid2_port_setfunction mlxsw_sp_pgt_entry_port_writefunction mlxsw_sp_pgt_entry_port_createfunction mlxsw_sp_pgt_entry_port_destroyfunction mlxsw_sp_pgt_entry_port_addfunction mlxsw_sp_pgt_entry_port_delfunction mlxsw_sp_pgt_entry_port_setfunction mlxsw_sp_pgt_initfunction mlxsw_sp_pgt_fini
Annotated Snippet
struct mlxsw_sp_pgt {
struct idr pgt_idr;
u16 end_index; /* Exclusive. */
struct mutex lock; /* Protects PGT. */
bool smpe_index_valid;
};
struct mlxsw_sp_pgt_entry {
struct list_head ports_list;
u16 index;
u16 smpe_index;
};
struct mlxsw_sp_pgt_entry_port {
struct list_head list; /* Member of 'ports_list'. */
u16 local_port;
};
int mlxsw_sp_pgt_mid_alloc(struct mlxsw_sp *mlxsw_sp, u16 *p_mid)
{
int index, err = 0;
mutex_lock(&mlxsw_sp->pgt->lock);
index = idr_alloc(&mlxsw_sp->pgt->pgt_idr, NULL, 0,
mlxsw_sp->pgt->end_index, GFP_KERNEL);
if (index < 0) {
err = index;
goto err_idr_alloc;
}
*p_mid = index;
mutex_unlock(&mlxsw_sp->pgt->lock);
return 0;
err_idr_alloc:
mutex_unlock(&mlxsw_sp->pgt->lock);
return err;
}
void mlxsw_sp_pgt_mid_free(struct mlxsw_sp *mlxsw_sp, u16 mid_base)
{
mutex_lock(&mlxsw_sp->pgt->lock);
WARN_ON(idr_remove(&mlxsw_sp->pgt->pgt_idr, mid_base));
mutex_unlock(&mlxsw_sp->pgt->lock);
}
int mlxsw_sp_pgt_mid_alloc_range(struct mlxsw_sp *mlxsw_sp, u16 *p_mid_base,
u16 count)
{
unsigned int mid_base;
int i, err;
mutex_lock(&mlxsw_sp->pgt->lock);
mid_base = idr_get_cursor(&mlxsw_sp->pgt->pgt_idr);
for (i = 0; i < count; i++) {
err = idr_alloc_cyclic(&mlxsw_sp->pgt->pgt_idr, NULL,
mid_base, mid_base + count, GFP_KERNEL);
if (err < 0)
goto err_idr_alloc_cyclic;
}
mutex_unlock(&mlxsw_sp->pgt->lock);
*p_mid_base = mid_base;
return 0;
err_idr_alloc_cyclic:
for (i--; i >= 0; i--)
idr_remove(&mlxsw_sp->pgt->pgt_idr, mid_base + i);
mutex_unlock(&mlxsw_sp->pgt->lock);
return err;
}
void
mlxsw_sp_pgt_mid_free_range(struct mlxsw_sp *mlxsw_sp, u16 mid_base, u16 count)
{
struct idr *pgt_idr = &mlxsw_sp->pgt->pgt_idr;
int i;
mutex_lock(&mlxsw_sp->pgt->lock);
for (i = 0; i < count; i++)
WARN_ON_ONCE(idr_remove(pgt_idr, mid_base + i));
mutex_unlock(&mlxsw_sp->pgt->lock);
}
static struct mlxsw_sp_pgt_entry_port *
mlxsw_sp_pgt_entry_port_lookup(struct mlxsw_sp_pgt_entry *pgt_entry,
Annotation
- Immediate include surface: `linux/refcount.h`, `linux/idr.h`, `spectrum.h`, `reg.h`.
- Detected declarations: `struct mlxsw_sp_pgt`, `struct mlxsw_sp_pgt_entry`, `struct mlxsw_sp_pgt_entry_port`, `function mlxsw_sp_pgt_mid_alloc`, `function mlxsw_sp_pgt_mid_free`, `function mlxsw_sp_pgt_mid_alloc_range`, `function mlxsw_sp_pgt_mid_free_range`, `function mlxsw_sp_pgt_entry_port_lookup`, `function list_for_each_entry`, `function mlxsw_sp_pgt_entry_create`.
- 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.