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.

Dependency Surface

Detected Declarations

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

Implementation Notes