drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/huawei/hinic/hinic_hw_cmdq.c- Extension
.c- Size
- 26034 bytes
- Lines
- 964
- Domain
- Driver Families
- Bucket
- drivers/net
- 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/kernel.hlinux/types.hlinux/errno.hlinux/pci.hlinux/device.hlinux/slab.hlinux/vmalloc.hlinux/spinlock.hlinux/sizes.hlinux/atomic.hlinux/log2.hlinux/io.hlinux/completion.hlinux/err.hasm/byteorder.hasm/barrier.hhinic_common.hhinic_hw_if.hhinic_hw_eqs.hhinic_hw_mgmt.hhinic_hw_wqe.hhinic_hw_wq.hhinic_hw_cmdq.hhinic_hw_io.hhinic_hw_dev.h
Detected Declarations
enum completion_formatenum data_formatenum bufdesc_lenenum ctrl_sect_lenenum cmdq_scmd_typeenum cmdq_cmd_typeenum completion_requestfunction hinic_alloc_cmdq_buffunction hinic_free_cmdq_buffunction cmdq_wqe_size_from_bdlenfunction cmdq_set_sge_completionfunction cmdq_prepare_wqe_ctrlfunction cmdq_set_lcmd_bufdescfunction cmdq_set_direct_wqe_datafunction cmdq_set_lcmd_wqefunction cmdq_set_direct_wqefunction cmdq_wqe_fillfunction cmdq_fill_dbfunction cmdq_set_dbfunction cmdq_sync_cmd_direct_respfunction cmdq_set_arm_bitfunction cmdq_params_validfunction hinic_cmdq_direct_respfunction hinic_set_arm_bitfunction clear_wqe_complete_bitfunction cmdq_arm_ceq_handlerfunction cmdq_update_errcodefunction cmdq_sync_cmd_handlerfunction cmdq_cmd_ceq_handlerfunction cmdq_ceq_handlerfunction cmdq_init_queue_ctxtfunction init_cmdqfunction free_cmdqfunction init_cmdqs_ctxtfunction hinic_set_cmdq_depthfunction hinic_init_cmdqsfunction hinic_free_cmdqs
Annotated Snippet
msecs_to_jiffies(CMDQ_TIMEOUT))) {
spin_lock_bh(&cmdq->cmdq_lock);
if (cmdq->errcode[curr_prod_idx] == &errcode)
cmdq->errcode[curr_prod_idx] = NULL;
if (cmdq->done[curr_prod_idx] == &done)
cmdq->done[curr_prod_idx] = NULL;
spin_unlock_bh(&cmdq->cmdq_lock);
hinic_dump_ceq_info(cmdq->hwdev);
return -ETIMEDOUT;
}
smp_rmb(); /* read error code after completion */
if (resp) {
struct hinic_cmdq_wqe_lcmd *wqe_lcmd = &curr_cmdq_wqe->wqe_lcmd;
*resp = cpu_to_be64(wqe_lcmd->completion.direct_resp);
}
if (errcode != 0)
return -EFAULT;
return 0;
}
static int cmdq_set_arm_bit(struct hinic_cmdq *cmdq, void *buf_in,
u16 in_size)
{
struct hinic_cmdq_wqe *curr_cmdq_wqe, cmdq_wqe;
u16 curr_prod_idx, next_prod_idx;
struct hinic_wq *wq = cmdq->wq;
struct hinic_hw_wqe *hw_wqe;
int wrapped, num_wqebbs;
/* Keep doorbell index correct */
spin_lock(&cmdq->cmdq_lock);
/* WQE_SIZE = WQEBB_SIZE, we will get the wq element and not shadow*/
hw_wqe = hinic_get_wqe(wq, WQE_SCMD_SIZE, &curr_prod_idx);
if (IS_ERR(hw_wqe)) {
spin_unlock(&cmdq->cmdq_lock);
return -EBUSY;
}
curr_cmdq_wqe = &hw_wqe->cmdq_wqe;
wrapped = cmdq->wrapped;
num_wqebbs = ALIGN(WQE_SCMD_SIZE, wq->wqebb_size) / wq->wqebb_size;
next_prod_idx = curr_prod_idx + num_wqebbs;
if (next_prod_idx >= wq->q_depth) {
cmdq->wrapped = !cmdq->wrapped;
next_prod_idx -= wq->q_depth;
}
cmdq_set_direct_wqe(&cmdq_wqe, CMDQ_CMD_SYNC_DIRECT_RESP, buf_in,
in_size, NULL, wrapped, HINIC_CMD_ACK_TYPE_CMDQ,
HINIC_MOD_COMM, CMDQ_SET_ARM_CMD, curr_prod_idx);
/* The data that is written to HW should be in Big Endian Format */
hinic_cpu_to_be32(&cmdq_wqe, WQE_SCMD_SIZE);
/* cmdq wqe is not shadow, therefore wqe will be written to wq */
cmdq_wqe_fill(curr_cmdq_wqe, &cmdq_wqe);
cmdq_set_db(cmdq, HINIC_CMDQ_SYNC, next_prod_idx);
spin_unlock(&cmdq->cmdq_lock);
return 0;
}
static int cmdq_params_valid(struct hinic_cmdq_buf *buf_in)
{
if (buf_in->size > HINIC_CMDQ_MAX_DATA_SIZE)
return -EINVAL;
return 0;
}
/**
* hinic_cmdq_direct_resp - send command with direct data as resp
* @cmdqs: the cmdqs
* @mod: module on the card that will handle the command
* @cmd: the command
* @buf_in: the buffer for the command
* @resp: the response to return
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/errno.h`, `linux/pci.h`, `linux/device.h`, `linux/slab.h`, `linux/vmalloc.h`, `linux/spinlock.h`.
- Detected declarations: `enum completion_format`, `enum data_format`, `enum bufdesc_len`, `enum ctrl_sect_len`, `enum cmdq_scmd_type`, `enum cmdq_cmd_type`, `enum completion_request`, `function hinic_alloc_cmdq_buf`, `function hinic_free_cmdq_buf`, `function cmdq_wqe_size_from_bdlen`.
- Atlas domain: Driver Families / drivers/net.
- 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.