drivers/infiniband/hw/mthca/mthca_cmd.c
Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/mthca/mthca_cmd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/infiniband/hw/mthca/mthca_cmd.c- Extension
.c- Size
- 58633 bytes
- Lines
- 1971
- 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/completion.hlinux/pci.hlinux/errno.hlinux/sched.hlinux/module.hlinux/slab.hasm/io.hrdma/ib_mad.hmthca_dev.hmthca_config_reg.hmthca_cmd.hmthca_memfree.h
Detected Declarations
struct mthca_cmd_contextfunction go_bitfunction mthca_cmd_post_dbellfunction mthca_cmd_post_hcrfunction mthca_cmd_postfunction mthca_status_to_errnofunction mthca_cmd_pollfunction mthca_cmd_eventfunction mthca_cmd_waitfunction mthca_cmd_boxfunction mthca_cmdfunction parameterfunction mthca_cmd_initfunction mthca_cmd_cleanupfunction commandsfunction pollingfunction mthca_free_mailboxfunction mthca_SYS_ENfunction mthca_SYS_DISfunction mthca_map_cmdfunction mthca_icm_nextfunction mthca_MAP_FAfunction mthca_UNMAP_FAfunction mthca_RUN_FWfunction mthca_setup_cmd_doorbellsfunction mthca_QUERY_FWfunction mthca_ENABLE_LAMfunction mthca_DISABLE_LAMfunction mthca_QUERY_DDRfunction mthca_QUERY_DEV_LIMfunction get_board_idfunction mthca_QUERY_ADAPTERfunction mthca_INIT_HCAfunction mthca_INIT_IBfunction mthca_CLOSE_IBfunction mthca_CLOSE_HCAfunction mthca_SET_IBfunction mthca_MAP_ICMfunction mthca_MAP_ICM_pagefunction mthca_UNMAP_ICMfunction mthca_MAP_ICM_AUXfunction mthca_UNMAP_ICM_AUXfunction mthca_SET_ICM_SIZEfunction mthca_SW2HW_MPTfunction mthca_HW2SW_MPTfunction mthca_WRITE_MTTfunction mthca_SYNC_TPTfunction mthca_MAP_EQ
Annotated Snippet
struct mthca_cmd_context {
struct completion done;
int result;
int next;
u64 out_param;
u16 token;
u8 status;
};
static int fw_cmd_doorbell = 0;
module_param(fw_cmd_doorbell, int, 0644);
MODULE_PARM_DESC(fw_cmd_doorbell, "post FW commands through doorbell page if nonzero "
"(and supported by FW)");
static inline int go_bit(struct mthca_dev *dev)
{
return readl(dev->hcr + HCR_STATUS_OFFSET) &
swab32(1 << HCR_GO_BIT);
}
static void mthca_cmd_post_dbell(struct mthca_dev *dev,
u64 in_param,
u64 out_param,
u32 in_modifier,
u8 op_modifier,
u16 op,
u16 token)
{
void __iomem *ptr = dev->cmd.dbell_map;
u16 *offs = dev->cmd.dbell_offsets;
__raw_writel((__force u32) cpu_to_be32(in_param >> 32), ptr + offs[0]);
wmb();
__raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), ptr + offs[1]);
wmb();
__raw_writel((__force u32) cpu_to_be32(in_modifier), ptr + offs[2]);
wmb();
__raw_writel((__force u32) cpu_to_be32(out_param >> 32), ptr + offs[3]);
wmb();
__raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), ptr + offs[4]);
wmb();
__raw_writel((__force u32) cpu_to_be32(token << 16), ptr + offs[5]);
wmb();
__raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) |
(1 << HCA_E_BIT) |
(op_modifier << HCR_OPMOD_SHIFT) |
op), ptr + offs[6]);
wmb();
__raw_writel((__force u32) 0, ptr + offs[7]);
wmb();
}
static int mthca_cmd_post_hcr(struct mthca_dev *dev,
u64 in_param,
u64 out_param,
u32 in_modifier,
u8 op_modifier,
u16 op,
u16 token,
int event)
{
if (event) {
unsigned long end = jiffies + GO_BIT_TIMEOUT;
while (go_bit(dev) && time_before(jiffies, end)) {
set_current_state(TASK_RUNNING);
schedule();
}
}
if (go_bit(dev))
return -EAGAIN;
/*
* We use writel (instead of something like memcpy_toio)
* because writes of less than 32 bits to the HCR don't work
* (and some architectures such as ia64 implement memcpy_toio
* in terms of writeb).
*/
__raw_writel((__force u32) cpu_to_be32(in_param >> 32), dev->hcr + 0 * 4);
__raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), dev->hcr + 1 * 4);
__raw_writel((__force u32) cpu_to_be32(in_modifier), dev->hcr + 2 * 4);
__raw_writel((__force u32) cpu_to_be32(out_param >> 32), dev->hcr + 3 * 4);
__raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), dev->hcr + 4 * 4);
__raw_writel((__force u32) cpu_to_be32(token << 16), dev->hcr + 5 * 4);
/* __raw_writel may not order writes. */
wmb();
__raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) |
Annotation
- Immediate include surface: `linux/completion.h`, `linux/pci.h`, `linux/errno.h`, `linux/sched.h`, `linux/module.h`, `linux/slab.h`, `asm/io.h`, `rdma/ib_mad.h`.
- Detected declarations: `struct mthca_cmd_context`, `function go_bit`, `function mthca_cmd_post_dbell`, `function mthca_cmd_post_hcr`, `function mthca_cmd_post`, `function mthca_status_to_errno`, `function mthca_cmd_poll`, `function mthca_cmd_event`, `function mthca_cmd_wait`, `function mthca_cmd_box`.
- 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.