drivers/misc/ibmvmc.c
Source file repositories/reference/linux-study-clean/drivers/misc/ibmvmc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/ibmvmc.c- Extension
.c- Size
- 62136 bytes
- Lines
- 2420
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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/module.hlinux/kernel.hlinux/kthread.hlinux/major.hlinux/string.hlinux/fcntl.hlinux/slab.hlinux/poll.hlinux/init.hlinux/fs.hlinux/interrupt.hlinux/spinlock.hlinux/percpu.hlinux/delay.hlinux/uaccess.hlinux/io.hlinux/miscdevice.hlinux/sched/signal.hasm/byteorder.hasm/irq.hasm/vio.hibmvmc.h
Detected Declarations
function h_copy_rdmafunction h_free_crqfunction h_request_vmcfunction ibmvmc_handle_eventfunction ibmvmc_release_crq_queuefunction ibmvmc_reset_crq_queuefunction ibmvmc_send_crqfunction free_dma_bufferfunction ibmvmc_free_hmc_bufferfunction ibmvmc_count_hmc_buffersfunction ibmvmc_return_hmcfunction ibmvmc_send_openfunction ibmvmc_send_closefunction ibmvmc_send_capabilitiesfunction ibmvmc_send_add_buffer_respfunction ibmvmc_send_rem_buffer_respfunction ibmvmc_send_msgfunction ibmvmc_openfunction ibmvmc_closefunction ibmvmc_readfunction ibmvmc_pollfunction ibmvmc_writefunction ibmvmc_setup_hmcfunction ibmvmc_ioctl_sethmcidfunction ibmvmc_ioctl_queryfunction ibmvmc_ioctl_requestvmcfunction ibmvmc_ioctlfunction MTUfunction ibmvmc_rem_bufferfunction ibmvmc_recv_msgfunction ibmvmc_process_capabilitiesfunction ibmvmc_validate_hmc_sessionfunction ibmvmc_resetfunction ibmvmc_reset_taskfunction ibmvmc_process_open_respfunction ibmvmc_process_close_respfunction ibmvmc_crq_processfunction ibmvmc_handle_crq_initfunction ibmvmc_handle_crqfunction ibmvmc_taskfunction ibmvmc_init_crq_queuefunction read_dma_windowfunction ibmvmc_probefunction ibmvmc_removefunction ibmvmc_scrub_module_parmsfunction ibmvmc_module_initfunction ibmvmc_module_exitmodule init ibmvmc_module_init
Annotated Snippet
static const struct file_operations ibmvmc_fops = {
.owner = THIS_MODULE,
.read = ibmvmc_read,
.write = ibmvmc_write,
.poll = ibmvmc_poll,
.unlocked_ioctl = ibmvmc_ioctl,
.open = ibmvmc_open,
.release = ibmvmc_close,
};
/**
* ibmvmc_add_buffer - Add Buffer
*
* @adapter: crq_server_adapter struct
* @crq: ibmvmc_crq_msg struct
*
* This message transfers a buffer from hypervisor ownership to management
* partition ownership. The LIOBA is obtained from the virtual TCE table
* associated with the hypervisor side of the VMC device, and points to a
* buffer of size MTU (as established in the capabilities exchange).
*
* Typical flow for ading buffers:
* 1. A new management application connection is opened by the management
* partition.
* 2. The hypervisor assigns new buffers for the traffic associated with
* that connection.
* 3. The hypervisor sends VMC Add Buffer messages to the management
* partition, informing it of the new buffers.
* 4. The hypervisor sends an HMC protocol message (to the management
* application) notifying it of the new buffers. This informs the
* application that it has buffers available for sending HMC
* commands.
*
* Return:
* 0 - Success
* Non-zero - Failure
*/
static int ibmvmc_add_buffer(struct crq_server_adapter *adapter,
struct ibmvmc_crq_msg *crq)
{
struct ibmvmc_buffer *buffer;
u8 hmc_index;
u8 hmc_session;
u16 buffer_id;
unsigned long flags;
int rc = 0;
if (!crq)
return -1;
hmc_session = crq->hmc_session;
hmc_index = crq->hmc_index;
buffer_id = be16_to_cpu(crq->var2.buffer_id);
if (hmc_index > ibmvmc.max_hmc_index) {
dev_err(adapter->dev, "add_buffer: invalid hmc_index = 0x%x\n",
hmc_index);
ibmvmc_send_add_buffer_resp(adapter, VMC_MSG_INVALID_HMC_INDEX,
hmc_session, hmc_index, buffer_id);
return -1;
}
if (buffer_id >= ibmvmc.max_buffer_pool_size) {
dev_err(adapter->dev, "add_buffer: invalid buffer_id = 0x%x\n",
buffer_id);
ibmvmc_send_add_buffer_resp(adapter, VMC_MSG_INVALID_BUFFER_ID,
hmc_session, hmc_index, buffer_id);
return -1;
}
spin_lock_irqsave(&hmcs[hmc_index].lock, flags);
buffer = &hmcs[hmc_index].buffer[buffer_id];
if (buffer->real_addr_local || buffer->dma_addr_local) {
dev_warn(adapter->dev, "add_buffer: already allocated id = 0x%lx\n",
(unsigned long)buffer_id);
spin_unlock_irqrestore(&hmcs[hmc_index].lock, flags);
ibmvmc_send_add_buffer_resp(adapter, VMC_MSG_INVALID_BUFFER_ID,
hmc_session, hmc_index, buffer_id);
return -1;
}
buffer->real_addr_local = alloc_dma_buffer(to_vio_dev(adapter->dev),
ibmvmc.max_mtu,
&buffer->dma_addr_local);
if (!buffer->real_addr_local) {
dev_err(adapter->dev, "add_buffer: alloc_dma_buffer failed.\n");
spin_unlock_irqrestore(&hmcs[hmc_index].lock, flags);
ibmvmc_send_add_buffer_resp(adapter, VMC_MSG_INTERFACE_FAILURE,
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/kthread.h`, `linux/major.h`, `linux/string.h`, `linux/fcntl.h`, `linux/slab.h`, `linux/poll.h`.
- Detected declarations: `function h_copy_rdma`, `function h_free_crq`, `function h_request_vmc`, `function ibmvmc_handle_event`, `function ibmvmc_release_crq_queue`, `function ibmvmc_reset_crq_queue`, `function ibmvmc_send_crq`, `function free_dma_buffer`, `function ibmvmc_free_hmc_buffer`, `function ibmvmc_count_hmc_buffers`.
- Atlas domain: Driver Families / drivers/misc.
- 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.