drivers/infiniband/hw/hfi1/file_ops.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/hfi1/file_ops.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/hfi1/file_ops.c- Extension
.c- Size
- 44575 bytes
- Lines
- 1715
- Domain
- Driver Families
- Bucket
- drivers/infiniband
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/poll.hlinux/cdev.hlinux/vmalloc.hlinux/io.hlinux/sched/mm.hlinux/bitmap.hrdma/ib.hhfi.hpio.hdevice.hcommon.htrace.hmmu_rb.huser_sdma.huser_exp_rcv.haspm.h
Detected Declarations
enum mmap_typesfunction is_valid_mmapfunction hfi1_file_openfunction hfi1_file_ioctlfunction hfi1_write_iterfunction mmap_cdbgfunction hfi1_file_mmapfunction Localfunction hfi1_pollfunction hfi1_file_closefunction kvirt_to_physfunction complete_subctxtfunction assign_ctxtfunction match_ctxtfunction EINVALfunction allocate_ctxtfunction deallocate_ctxtfunction init_subctxtsfunction setup_subctxtfunction user_initfunction get_ctxt_infofunction init_user_ctxtfunction setup_base_ctxtfunction get_base_infofunction user_exp_rcv_setupfunction hfi1_user_exp_rcv_clearfunction user_exp_rcv_invalidfunction poll_urgentfunction poll_nextfunction find_ctxtfunction manage_rcvqfunction user_event_ackfunction set_ctxt_pkeyfunction ctxt_resetfunction user_removefunction user_addfunction hfi1_device_createfunction hfi1_device_remove
Annotated Snippet
static const struct file_operations hfi1_file_ops = {
.owner = THIS_MODULE,
.write_iter = hfi1_write_iter,
.open = hfi1_file_open,
.release = hfi1_file_close,
.unlocked_ioctl = hfi1_file_ioctl,
.poll = hfi1_poll,
.mmap = hfi1_file_mmap,
.llseek = noop_llseek,
};
static const struct vm_operations_struct vm_ops = {
.fault = vma_fault,
};
/*
* Types of memories mapped into user processes' space
*/
enum mmap_types {
PIO_BUFS = 1,
PIO_BUFS_SOP,
PIO_CRED,
RCV_HDRQ,
RCV_EGRBUF,
UREGS,
EVENTS,
STATUS,
RTAIL,
SUBCTXT_UREGS,
SUBCTXT_RCV_HDRQ,
SUBCTXT_EGRBUF,
SDMA_COMP
};
/*
* Masks and offsets defining the mmap tokens
*/
#define HFI1_MMAP_OFFSET_MASK 0xfffULL
#define HFI1_MMAP_OFFSET_SHIFT 0
#define HFI1_MMAP_SUBCTXT_MASK 0xfULL
#define HFI1_MMAP_SUBCTXT_SHIFT 12
#define HFI1_MMAP_CTXT_MASK 0xffULL
#define HFI1_MMAP_CTXT_SHIFT 16
#define HFI1_MMAP_TYPE_MASK 0xfULL
#define HFI1_MMAP_TYPE_SHIFT 24
#define HFI1_MMAP_MAGIC_MASK 0xffffffffULL
#define HFI1_MMAP_MAGIC_SHIFT 32
#define HFI1_MMAP_MAGIC 0xdabbad00
#define HFI1_MMAP_TOKEN_SET(field, val) \
(((val) & HFI1_MMAP_##field##_MASK) << HFI1_MMAP_##field##_SHIFT)
#define HFI1_MMAP_TOKEN_GET(field, token) \
(((token) >> HFI1_MMAP_##field##_SHIFT) & HFI1_MMAP_##field##_MASK)
#define HFI1_MMAP_TOKEN(type, ctxt, subctxt, addr) \
(HFI1_MMAP_TOKEN_SET(MAGIC, HFI1_MMAP_MAGIC) | \
HFI1_MMAP_TOKEN_SET(TYPE, type) | \
HFI1_MMAP_TOKEN_SET(CTXT, ctxt) | \
HFI1_MMAP_TOKEN_SET(SUBCTXT, subctxt) | \
HFI1_MMAP_TOKEN_SET(OFFSET, (offset_in_page(addr))))
#define dbg(fmt, ...) \
pr_info(fmt, ##__VA_ARGS__)
static inline int is_valid_mmap(u64 token)
{
return (HFI1_MMAP_TOKEN_GET(MAGIC, token) == HFI1_MMAP_MAGIC);
}
static int hfi1_file_open(struct inode *inode, struct file *fp)
{
struct hfi1_filedata *fd;
struct hfi1_devdata *dd = container_of(inode->i_cdev,
struct hfi1_devdata,
user_cdev);
if (!((dd->flags & HFI1_PRESENT) && dd->kregbase1))
return -EINVAL;
if (!refcount_inc_not_zero(&dd->user_refcount))
return -ENXIO;
/* The real work is performed later in assign_ctxt() */
fd = kzalloc_obj(*fd);
if (!fd || init_srcu_struct(&fd->pq_srcu))
goto nomem;
spin_lock_init(&fd->pq_rcu_lock);
spin_lock_init(&fd->tid_lock);
Annotation
- Immediate include surface: `linux/poll.h`, `linux/cdev.h`, `linux/vmalloc.h`, `linux/io.h`, `linux/sched/mm.h`, `linux/bitmap.h`, `rdma/ib.h`, `hfi.h`.
- Detected declarations: `enum mmap_types`, `function is_valid_mmap`, `function hfi1_file_open`, `function hfi1_file_ioctl`, `function hfi1_write_iter`, `function mmap_cdbg`, `function hfi1_file_mmap`, `function Local`, `function hfi1_poll`, `function hfi1_file_close`.
- Atlas domain: Driver Families / drivers/infiniband.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.