drivers/net/ethernet/mellanox/mlxsw/item.h
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxsw/item.h
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlxsw/item.h- Extension
.h- Size
- 17947 bytes
- Lines
- 558
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/string.hlinux/bitops.h
Detected Declarations
struct mlxsw_itemfunction __mlxsw_item_offsetfunction __mlxsw_item_get8function __mlxsw_item_set8function __mlxsw_item_get16function __mlxsw_item_set16function __mlxsw_item_get32function __mlxsw_item_set32function __mlxsw_item_get64function __mlxsw_item_set64function __mlxsw_item_memcpy_fromfunction __mlxsw_item_memcpy_tofunction __mlxsw_item_bit_array_offsetfunction __mlxsw_item_bit_array_getfunction __mlxsw_item_bit_array_set
Annotated Snippet
struct mlxsw_item {
unsigned short offset; /* bytes in container */
short step; /* step in bytes for indexed items */
unsigned short in_step_offset; /* offset within one step */
unsigned char shift; /* shift in bits */
unsigned char element_size; /* size of element in bit array */
bool no_real_shift;
union {
unsigned char bits;
unsigned short bytes;
} size;
const char *name;
};
static inline unsigned int
__mlxsw_item_offset(const struct mlxsw_item *item, unsigned short index,
size_t typesize)
{
BUG_ON(index && !item->step);
if (item->offset % typesize != 0 ||
item->step % typesize != 0 ||
item->in_step_offset % typesize != 0) {
pr_err("mlxsw: item bug (name=%s,offset=%x,step=%x,in_step_offset=%x,typesize=%zx)\n",
item->name, item->offset, item->step,
item->in_step_offset, typesize);
BUG();
}
return ((item->offset + item->step * index + item->in_step_offset) /
typesize);
}
static inline u8 __mlxsw_item_get8(const char *buf,
const struct mlxsw_item *item,
unsigned short index)
{
unsigned int offset = __mlxsw_item_offset(item, index, sizeof(u8));
u8 *b = (u8 *) buf;
u8 tmp;
tmp = b[offset];
tmp >>= item->shift;
tmp &= GENMASK(item->size.bits - 1, 0);
if (item->no_real_shift)
tmp <<= item->shift;
return tmp;
}
static inline void __mlxsw_item_set8(char *buf, const struct mlxsw_item *item,
unsigned short index, u8 val)
{
unsigned int offset = __mlxsw_item_offset(item, index,
sizeof(u8));
u8 *b = (u8 *) buf;
u8 mask = GENMASK(item->size.bits - 1, 0) << item->shift;
u8 tmp;
if (!item->no_real_shift)
val <<= item->shift;
val &= mask;
tmp = b[offset];
tmp &= ~mask;
tmp |= val;
b[offset] = tmp;
}
static inline u16 __mlxsw_item_get16(const char *buf,
const struct mlxsw_item *item,
unsigned short index)
{
unsigned int offset = __mlxsw_item_offset(item, index, sizeof(u16));
__be16 *b = (__be16 *) buf;
u16 tmp;
tmp = be16_to_cpu(b[offset]);
tmp >>= item->shift;
tmp &= GENMASK(item->size.bits - 1, 0);
if (item->no_real_shift)
tmp <<= item->shift;
return tmp;
}
static inline void __mlxsw_item_set16(char *buf, const struct mlxsw_item *item,
unsigned short index, u16 val)
{
unsigned int offset = __mlxsw_item_offset(item, index,
sizeof(u16));
__be16 *b = (__be16 *) buf;
u16 mask = GENMASK(item->size.bits - 1, 0) << item->shift;
u16 tmp;
Annotation
- Immediate include surface: `linux/types.h`, `linux/string.h`, `linux/bitops.h`.
- Detected declarations: `struct mlxsw_item`, `function __mlxsw_item_offset`, `function __mlxsw_item_get8`, `function __mlxsw_item_set8`, `function __mlxsw_item_get16`, `function __mlxsw_item_set16`, `function __mlxsw_item_get32`, `function __mlxsw_item_set32`, `function __mlxsw_item_get64`, `function __mlxsw_item_set64`.
- 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.