drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/huawei/hinic/hinic_hw_wq.c- Extension
.c- Size
- 23197 bytes
- Lines
- 905
- 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.
- 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/kernel.hlinux/types.hlinux/pci.hlinux/device.hlinux/dma-mapping.hlinux/slab.hlinux/atomic.hlinux/semaphore.hlinux/errno.hlinux/vmalloc.hlinux/err.hasm/byteorder.hhinic_hw_if.hhinic_hw_wqe.hhinic_hw_wq.hhinic_hw_cmdq.h
Detected Declarations
function Copyrightfunction WQE_PAGE_NUMfunction queue_alloc_pagefunction wqs_allocate_pagefunction wqs_free_pagefunction cmdq_allocate_pagefunction cmdq_free_pagefunction alloc_page_arraysfunction free_page_arraysfunction wqs_next_blockfunction wqs_return_blockfunction init_wqs_blocks_arrfunction hinic_wqs_allocfunction hinic_wqs_freefunction alloc_wqes_shadowfunction free_wqes_shadowfunction free_wq_pagesfunction alloc_wq_pagesfunction hinic_wq_allocatefunction hinic_wq_freefunction hinic_wqs_cmdq_allocfunction hinic_wqs_cmdq_freefunction copy_wqe_to_shadowfunction copy_wqe_from_shadowfunction hinic_return_wqefunction hinic_put_wqefunction wqe_shadowfunction hinic_write_wqe
Annotated Snippet
if (err) {
dev_err(&pdev->dev, "Failed wq page allocation\n");
goto err_wq_allocate_page;
}
}
wqs->free_blocks = devm_kzalloc(&pdev->dev, WQS_FREE_BLOCKS_SIZE(wqs),
GFP_KERNEL);
if (!wqs->free_blocks) {
err = -ENOMEM;
goto err_alloc_blocks;
}
init_wqs_blocks_arr(wqs);
return 0;
err_alloc_blocks:
err_wq_allocate_page:
for (i = 0; i < page_idx; i++)
wqs_free_page(wqs, i);
free_page_arrays(wqs);
return err;
}
/**
* hinic_wqs_free - free Work Queues set
* @wqs: Work Queue Set
**/
void hinic_wqs_free(struct hinic_wqs *wqs)
{
struct hinic_hwif *hwif = wqs->hwif;
struct pci_dev *pdev = hwif->pdev;
int page_idx;
devm_kfree(&pdev->dev, wqs->free_blocks);
for (page_idx = 0; page_idx < wqs->num_pages; page_idx++)
wqs_free_page(wqs, page_idx);
free_page_arrays(wqs);
}
/**
* alloc_wqes_shadow - allocate WQE shadows for WQ
* @wq: WQ to allocate shadows for
*
* Return 0 - Success, negative - Failure
**/
static int alloc_wqes_shadow(struct hinic_wq *wq)
{
struct hinic_hwif *hwif = wq->hwif;
struct pci_dev *pdev = hwif->pdev;
wq->shadow_wqe = devm_kcalloc(&pdev->dev, wq->num_q_pages,
wq->max_wqe_size, GFP_KERNEL);
if (!wq->shadow_wqe)
return -ENOMEM;
wq->shadow_idx = devm_kcalloc(&pdev->dev, wq->num_q_pages,
sizeof(*wq->shadow_idx), GFP_KERNEL);
if (!wq->shadow_idx)
goto err_shadow_idx;
return 0;
err_shadow_idx:
devm_kfree(&pdev->dev, wq->shadow_wqe);
return -ENOMEM;
}
/**
* free_wqes_shadow - free WQE shadows of WQ
* @wq: WQ to free shadows from
**/
static void free_wqes_shadow(struct hinic_wq *wq)
{
struct hinic_hwif *hwif = wq->hwif;
struct pci_dev *pdev = hwif->pdev;
devm_kfree(&pdev->dev, wq->shadow_idx);
devm_kfree(&pdev->dev, wq->shadow_wqe);
}
/**
* free_wq_pages - free pages of WQ
* @hwif: HW interface for releasing dma addresses
* @wq: WQ to free pages from
* @num_q_pages: number pages to free
**/
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/pci.h`, `linux/device.h`, `linux/dma-mapping.h`, `linux/slab.h`, `linux/atomic.h`, `linux/semaphore.h`.
- Detected declarations: `function Copyright`, `function WQE_PAGE_NUM`, `function queue_alloc_page`, `function wqs_allocate_page`, `function wqs_free_page`, `function cmdq_allocate_page`, `function cmdq_free_page`, `function alloc_page_arrays`, `function free_page_arrays`, `function wqs_next_block`.
- 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.
- 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.