drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/hisilicon/hibmcge/hbg_txrx.c- Extension
.c- Size
- 18438 bytes
- Lines
- 718
- 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.
- 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
net/netdev_queues.hhbg_common.hhbg_irq.hhbg_reg.hhbg_txrx.hhbg_trace.h
Detected Declarations
function hbg_dma_mapfunction hbg_dma_unmapfunction hbg_buffer_free_pagefunction hbg_buffer_alloc_pagefunction hbg_init_tx_descfunction hbg_net_start_xmitfunction hbg_buffer_free_skbfunction hbg_buffer_freefunction hbg_napi_tx_recyclefunction hbg_rx_check_l3l4_errorfunction hbg_update_rx_ip_protocol_statsfunction hbg_update_rx_protocol_statsfunction hbg_rx_pkt_checkfunction hbg_rx_fill_one_bufferfunction hbg_rx_fill_buffersfunction hbg_sync_data_from_hwfunction hbg_build_skbfunction hbg_napi_rx_pollfunction hbg_ring_page_pool_destoryfunction hbg_ring_page_pool_initfunction hbg_ring_uninitfunction hbg_ring_initfunction hbg_tx_ring_initfunction hbg_rx_ring_initfunction hbg_txrx_initfunction hbg_txrx_uninit
Annotated Snippet
FIELD_GET(HBG_RX_DESC_W4_DROP_B, desc->word4))) {
priv->stats.rx_desc_drop++;
return false;
}
if (unlikely(FIELD_GET(HBG_RX_DESC_W4_L2_ERR_B, desc->word4))) {
priv->stats.rx_desc_l2_err_cnt++;
return false;
}
if (unlikely(!hbg_rx_check_l3l4_error(priv, desc, skb))) {
priv->stats.rx_desc_l3l4_err_cnt++;
return false;
}
hbg_update_rx_protocol_stats(priv, desc);
return true;
}
static int hbg_rx_fill_one_buffer(struct hbg_priv *priv)
{
struct hbg_ring *ring = &priv->rx_ring;
struct hbg_buffer *buffer;
int ret;
if (hbg_queue_is_full(ring->ntc, ring->ntu, ring) ||
hbg_fifo_is_full(priv, ring->dir))
return 0;
buffer = &ring->queue[ring->ntu];
ret = hbg_buffer_alloc_page(buffer);
if (unlikely(ret))
return ret;
memset(buffer->page_addr, 0, HBG_PACKET_HEAD_SIZE);
dma_sync_single_for_device(&priv->pdev->dev, buffer->page_dma,
HBG_PACKET_HEAD_SIZE, DMA_TO_DEVICE);
hbg_hw_fill_buffer(priv, buffer->page_dma);
hbg_queue_move_next(ntu, ring);
return 0;
}
static int hbg_rx_fill_buffers(struct hbg_priv *priv)
{
u32 remained = hbg_hw_get_fifo_used_num(priv, HBG_DIR_RX);
u32 max_count = priv->dev_specs.rx_fifo_num;
u32 refill_count;
int ret;
if (unlikely(remained >= max_count))
return 0;
refill_count = max_count - remained;
while (refill_count--) {
ret = hbg_rx_fill_one_buffer(priv);
if (unlikely(ret))
break;
}
return ret;
}
static bool hbg_sync_data_from_hw(struct hbg_priv *priv,
struct hbg_buffer *buffer)
{
struct hbg_rx_desc *rx_desc;
dma_sync_single_for_cpu(&priv->pdev->dev, buffer->page_dma,
buffer->page_size, DMA_FROM_DEVICE);
/* make sure HW write desc complete */
dma_rmb();
rx_desc = (struct hbg_rx_desc *)buffer->page_addr;
return FIELD_GET(HBG_RX_DESC_W2_PKT_LEN_M, rx_desc->word2) != 0;
}
static int hbg_build_skb(struct hbg_priv *priv,
struct hbg_buffer *buffer, u32 pkt_len)
{
net_prefetch(buffer->page_addr);
buffer->skb = napi_build_skb(buffer->page_addr, buffer->page_size);
if (unlikely(!buffer->skb))
return -ENOMEM;
skb_mark_for_recycle(buffer->skb);
/* page will be freed together with the skb */
buffer->page = NULL;
Annotation
- Immediate include surface: `net/netdev_queues.h`, `hbg_common.h`, `hbg_irq.h`, `hbg_reg.h`, `hbg_txrx.h`, `hbg_trace.h`.
- Detected declarations: `function hbg_dma_map`, `function hbg_dma_unmap`, `function hbg_buffer_free_page`, `function hbg_buffer_alloc_page`, `function hbg_init_tx_desc`, `function hbg_net_start_xmit`, `function hbg_buffer_free_skb`, `function hbg_buffer_free`, `function hbg_napi_tx_recycle`, `function hbg_rx_check_l3l4_error`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- 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.