drivers/infiniband/hw/usnic/usnic_vnic.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/usnic/usnic_vnic.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/usnic/usnic_vnic.c- Extension
.c- Size
- 11682 bytes
- Lines
- 476
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- 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/errno.hlinux/pci.husnic_ib.hvnic_resource.husnic_log.husnic_vnic.h
Detected Declarations
struct usnic_vnicfunction _to_vnic_res_typefunction usnic_vnic_dumpfunction usnic_vnic_res_spec_updatefunction usnic_vnic_res_spec_satisfiedfunction usnic_vnic_spec_dumpfunction usnic_vnic_check_roomfunction usnic_vnic_res_cntfunction usnic_vnic_res_free_cntfunction usnic_vnic_get_resourcesfunction usnic_vnic_put_resourcesfunction usnic_vnic_get_indexfunction usnic_vnic_alloc_res_chunkfunction usnic_vnic_free_res_chunkfunction usnic_vnic_discover_resourcesfunction usnic_vnic_release_resourcesfunction usnic_vnic_free
Annotated Snippet
struct usnic_vnic {
struct vnic_dev *vdev;
struct vnic_dev_bar bar[PCI_NUM_RESOURCES];
struct usnic_vnic_res_chunk chunks[USNIC_VNIC_RES_TYPE_MAX];
spinlock_t res_lock;
};
static enum vnic_res_type _to_vnic_res_type(enum usnic_vnic_res_type res_type)
{
#define DEFINE_USNIC_VNIC_RES_AT(usnic_vnic_res_t, vnic_res_type, desc, val) \
vnic_res_type,
#define DEFINE_USNIC_VNIC_RES(usnic_vnic_res_t, vnic_res_type, desc) \
vnic_res_type,
static enum vnic_res_type usnic_vnic_type_2_vnic_type[] = {
USNIC_VNIC_RES_TYPES};
#undef DEFINE_USNIC_VNIC_RES
#undef DEFINE_USNIC_VNIC_RES_AT
if (res_type >= USNIC_VNIC_RES_TYPE_MAX)
return RES_TYPE_MAX;
return usnic_vnic_type_2_vnic_type[res_type];
}
const char *usnic_vnic_res_type_to_str(enum usnic_vnic_res_type res_type)
{
#define DEFINE_USNIC_VNIC_RES_AT(usnic_vnic_res_t, vnic_res_type, desc, val) \
desc,
#define DEFINE_USNIC_VNIC_RES(usnic_vnic_res_t, vnic_res_type, desc) \
desc,
static const char * const usnic_vnic_res_type_desc[] = {
USNIC_VNIC_RES_TYPES};
#undef DEFINE_USNIC_VNIC_RES
#undef DEFINE_USNIC_VNIC_RES_AT
if (res_type >= USNIC_VNIC_RES_TYPE_MAX)
return "unknown";
return usnic_vnic_res_type_desc[res_type];
}
const char *usnic_vnic_pci_name(struct usnic_vnic *vnic)
{
return pci_name(usnic_vnic_get_pdev(vnic));
}
int usnic_vnic_dump(struct usnic_vnic *vnic, char *buf,
int buf_sz,
void *hdr_obj,
int (*printtitle)(void *, char*, int),
int (*printcols)(char *, int),
int (*printrow)(void *, char *, int))
{
struct usnic_vnic_res_chunk *chunk;
struct usnic_vnic_res *res;
struct vnic_dev_bar *bar0;
int i, j, offset;
offset = 0;
bar0 = usnic_vnic_get_bar(vnic, 0);
offset += scnprintf(buf + offset, buf_sz - offset,
"VF:%hu BAR0 bus_addr=%pa vaddr=0x%p size=%ld ",
usnic_vnic_get_index(vnic),
&bar0->bus_addr,
bar0->vaddr, bar0->len);
if (printtitle)
offset += printtitle(hdr_obj, buf + offset, buf_sz - offset);
offset += scnprintf(buf + offset, buf_sz - offset, "\n");
offset += scnprintf(buf + offset, buf_sz - offset,
"|RES\t|CTRL_PIN\t\t|IN_USE\t");
if (printcols)
offset += printcols(buf + offset, buf_sz - offset);
offset += scnprintf(buf + offset, buf_sz - offset, "\n");
spin_lock(&vnic->res_lock);
for (i = 0; i < ARRAY_SIZE(vnic->chunks); i++) {
chunk = &vnic->chunks[i];
for (j = 0; j < chunk->cnt; j++) {
res = chunk->res[j];
offset += scnprintf(buf + offset, buf_sz - offset,
"|%s[%u]\t|0x%p\t|%u\t",
usnic_vnic_res_type_to_str(res->type),
res->vnic_idx, res->ctrl, !!res->owner);
if (printrow) {
offset += printrow(res->owner, buf + offset,
buf_sz - offset);
}
offset += scnprintf(buf + offset, buf_sz - offset,
"\n");
Annotation
- Immediate include surface: `linux/errno.h`, `linux/pci.h`, `usnic_ib.h`, `vnic_resource.h`, `usnic_log.h`, `usnic_vnic.h`.
- Detected declarations: `struct usnic_vnic`, `function _to_vnic_res_type`, `function usnic_vnic_dump`, `function usnic_vnic_res_spec_update`, `function usnic_vnic_res_spec_satisfied`, `function usnic_vnic_spec_dump`, `function usnic_vnic_check_room`, `function usnic_vnic_res_cnt`, `function usnic_vnic_res_free_cnt`, `function usnic_vnic_get_resources`.
- Atlas domain: Driver Families / drivers/infiniband.
- 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.