drivers/net/ethernet/mscc/ocelot_fdma.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mscc/ocelot_fdma.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mscc/ocelot_fdma.c- Extension
.c- Size
- 22794 bytes
- Lines
- 893
- 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/align.hlinux/bitops.hlinux/dmapool.hlinux/dsa/ocelot.hlinux/netdevice.hlinux/skbuff.hocelot_fdma.hocelot_qs.h
Detected Declarations
function ocelot_fdma_writelfunction ocelot_fdma_readlfunction ocelot_fdma_idx_dmafunction ocelot_fdma_dma_idxfunction ocelot_fdma_idx_nextfunction ocelot_fdma_idx_prevfunction ocelot_fdma_rx_ring_freefunction ocelot_fdma_tx_ring_freefunction ocelot_fdma_tx_ring_emptyfunction ocelot_fdma_activate_chanfunction ocelot_fdma_read_ch_safefunction ocelot_fdma_wait_chan_safefunction ocelot_fdma_dcb_set_datafunction ocelot_fdma_rx_alloc_pagefunction ocelot_fdma_alloc_rx_buffsfunction ocelot_fdma_tx_dcb_set_skbfunction ocelot_fdma_check_stop_rxfunction ocelot_fdma_rx_set_llpfunction ocelot_fdma_rx_restartfunction ocelot_fdma_add_rx_fragfunction ocelot_fdma_reuse_rx_pagefunction ocelot_fdma_receive_skbfunction ocelot_fdma_rx_getfunction ocelot_fdma_wakeup_netdevfunction ocelot_fdma_tx_cleanupfunction ocelot_fdma_napi_pollfunction ocelot_fdma_interruptfunction ocelot_fdma_send_skbfunction ocelot_fdma_prepare_skbfunction ocelot_fdma_inject_framefunction ocelot_fdma_free_rx_ringfunction ocelot_fdma_free_tx_ringfunction ocelot_fdma_rings_allocfunction ocelot_fdma_netdev_initfunction ocelot_fdma_netdev_deinitfunction ocelot_fdma_initfunction ocelot_fdma_startfunction ocelot_fdma_deinit
Annotated Snippet
if (unlikely(!rxb->page)) {
if (unlikely(!ocelot_fdma_rx_alloc_page(ocelot, rxb))) {
dev_err_ratelimited(ocelot->dev,
"Failed to allocate rx\n");
ret = -ENOMEM;
break;
}
}
dcb = &rx_ring->dcbs[idx];
dma_addr = rxb->dma_addr + rxb->page_offset;
ocelot_fdma_dcb_set_data(dcb, dma_addr, OCELOT_FDMA_RXB_SIZE);
idx = ocelot_fdma_idx_next(idx, OCELOT_FDMA_RX_RING_SIZE);
/* Chain the DCB to the next one */
dcb->llp = ocelot_fdma_idx_dma(rx_ring->dcbs_dma, idx);
}
rx_ring->next_to_use = idx;
rx_ring->next_to_alloc = idx;
return ret;
}
static bool ocelot_fdma_tx_dcb_set_skb(struct ocelot *ocelot,
struct ocelot_fdma_tx_buf *tx_buf,
struct ocelot_fdma_dcb *dcb,
struct sk_buff *skb)
{
dma_addr_t mapping;
mapping = dma_map_single(ocelot->dev, skb->data, skb->len,
DMA_TO_DEVICE);
if (unlikely(dma_mapping_error(ocelot->dev, mapping)))
return false;
dma_unmap_addr_set(tx_buf, dma_addr, mapping);
ocelot_fdma_dcb_set_data(dcb, mapping, OCELOT_FDMA_RX_SIZE);
tx_buf->skb = skb;
dcb->stat |= MSCC_FDMA_DCB_STAT_BLOCKL(skb->len);
dcb->stat |= MSCC_FDMA_DCB_STAT_SOF | MSCC_FDMA_DCB_STAT_EOF;
return true;
}
static bool ocelot_fdma_check_stop_rx(struct ocelot *ocelot)
{
u32 llp;
/* Check if the FDMA hits the DCB with LLP == NULL */
llp = ocelot_fdma_readl(ocelot, MSCC_FDMA_DCB_LLP(MSCC_FDMA_XTR_CHAN));
if (unlikely(llp))
return false;
ocelot_fdma_writel(ocelot, MSCC_FDMA_CH_DISABLE,
BIT(MSCC_FDMA_XTR_CHAN));
return true;
}
static void ocelot_fdma_rx_set_llp(struct ocelot_fdma_rx_ring *rx_ring)
{
struct ocelot_fdma_dcb *dcb;
unsigned int idx;
idx = ocelot_fdma_idx_prev(rx_ring->next_to_use,
OCELOT_FDMA_RX_RING_SIZE);
dcb = &rx_ring->dcbs[idx];
dcb->llp = 0;
}
static void ocelot_fdma_rx_restart(struct ocelot *ocelot)
{
struct ocelot_fdma *fdma = ocelot->fdma;
struct ocelot_fdma_rx_ring *rx_ring;
const u8 chan = MSCC_FDMA_XTR_CHAN;
dma_addr_t new_llp, dma_base;
unsigned int idx;
u32 llp_prev;
int ret;
rx_ring = &fdma->rx_ring;
ret = ocelot_fdma_wait_chan_safe(ocelot, chan);
if (ret) {
dev_err_ratelimited(ocelot->dev,
"Unable to stop RX channel\n");
return;
}
Annotation
- Immediate include surface: `linux/align.h`, `linux/bitops.h`, `linux/dmapool.h`, `linux/dsa/ocelot.h`, `linux/netdevice.h`, `linux/skbuff.h`, `ocelot_fdma.h`, `ocelot_qs.h`.
- Detected declarations: `function ocelot_fdma_writel`, `function ocelot_fdma_readl`, `function ocelot_fdma_idx_dma`, `function ocelot_fdma_dma_idx`, `function ocelot_fdma_idx_next`, `function ocelot_fdma_idx_prev`, `function ocelot_fdma_rx_ring_free`, `function ocelot_fdma_tx_ring_free`, `function ocelot_fdma_tx_ring_empty`, `function ocelot_fdma_activate_chan`.
- 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.