drivers/net/ethernet/chelsio/cxgb4/sge.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/chelsio/cxgb4/sge.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/chelsio/cxgb4/sge.c- Extension
.c- Size
- 150570 bytes
- Lines
- 5206
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/skbuff.hlinux/netdevice.hlinux/etherdevice.hlinux/if_vlan.hlinux/ip.hlinux/dma-mapping.hlinux/jiffies.hlinux/prefetch.hlinux/export.hnet/xfrm.hnet/ipv6.hnet/tcp.hnet/busy_poll.hscsi/fc/fc_fcoe.hcxgb4.ht4_regs.ht4_values.ht4_msg.ht4fw_api.hcxgb4_ptp.hcxgb4_uld.hcxgb4_tc_mqprio.hsched.h
Detected Declarations
struct rx_sw_descfunction fl_mtu_bufsizefunction get_buf_addrfunction is_buf_mappedfunction txq_availfunction fl_capfunction fl_starvingfunction cxgb4_map_skbfunction unmap_skbfunction deferred_unmap_destructorfunction free_tx_descfunction reclaimablefunction reclaim_completed_txfunction cxgb4_reclaim_completed_txfunction get_buf_sizefunction free_rx_bufsfunction unmap_rx_buffunction ring_fl_dbfunction set_rx_sw_descfunction refill_flfunction __refill_flfunction entryfunction sgl_lenfunction flits_to_descfunction is_eth_immfunction calc_tx_flitsfunction cxgb4_write_sglfunction cxgb4_write_partial_sglfunction cxgb_pio_copyfunction cxgb4_ring_tx_dbfunction cxgb4_inline_tx_skbfunction hwcsumfunction eth_txq_stopfunction txq_advancefunction cxgb_fcoe_offloadfunction cxgb_encap_offload_supportedfunction t6_fill_tnl_lsofunction t4_sge_eth_txq_egress_updatefunction cxgb4_validate_skbfunction cxgb4_eth_xmitfunction t4vf_is_eth_immfunction t4vf_calc_tx_flitsfunction cxgb4_vf_eth_xmitfunction cxgb4_reclaim_completed_txfunction eosw_txq_advance_indexfunction cxgb4_eosw_txq_free_descfunction eosw_txq_advancefunction eosw_txq_enqueue
Annotated Snippet
struct rx_sw_desc { /* SW state per Rx descriptor */
struct page *page;
dma_addr_t dma_addr;
};
/*
* Rx buffer sizes for "useskbs" Free List buffers (one ingress packet pe skb
* buffer). We currently only support two sizes for 1500- and 9000-byte MTUs.
* We could easily support more but there doesn't seem to be much need for
* that ...
*/
#define FL_MTU_SMALL 1500
#define FL_MTU_LARGE 9000
static inline unsigned int fl_mtu_bufsize(struct adapter *adapter,
unsigned int mtu)
{
struct sge *s = &adapter->sge;
return ALIGN(s->pktshift + ETH_HLEN + VLAN_HLEN + mtu, s->fl_align);
}
#define FL_MTU_SMALL_BUFSIZE(adapter) fl_mtu_bufsize(adapter, FL_MTU_SMALL)
#define FL_MTU_LARGE_BUFSIZE(adapter) fl_mtu_bufsize(adapter, FL_MTU_LARGE)
/*
* Bits 0..3 of rx_sw_desc.dma_addr have special meaning. The hardware uses
* these to specify the buffer size as an index into the SGE Free List Buffer
* Size register array. We also use bit 4, when the buffer has been unmapped
* for DMA, but this is of course never sent to the hardware and is only used
* to prevent double unmappings. All of the above requires that the Free List
* Buffers which we allocate have the bottom 5 bits free (0) -- i.e. are
* 32-byte or a power of 2 greater in alignment. Since the SGE's minimal
* Free List Buffer alignment is 32 bytes, this works out for us ...
*/
enum {
RX_BUF_FLAGS = 0x1f, /* bottom five bits are special */
RX_BUF_SIZE = 0x0f, /* bottom three bits are for buf sizes */
RX_UNMAPPED_BUF = 0x10, /* buffer is not mapped */
/*
* XXX We shouldn't depend on being able to use these indices.
* XXX Especially when some other Master PF has initialized the
* XXX adapter or we use the Firmware Configuration File. We
* XXX should really search through the Host Buffer Size register
* XXX array for the appropriately sized buffer indices.
*/
RX_SMALL_PG_BUF = 0x0, /* small (PAGE_SIZE) page buffer */
RX_LARGE_PG_BUF = 0x1, /* buffer large (FL_PG_ORDER) page buffer */
RX_SMALL_MTU_BUF = 0x2, /* small MTU buffer */
RX_LARGE_MTU_BUF = 0x3, /* large MTU buffer */
};
static int timer_pkt_quota[] = {1, 1, 2, 3, 4, 5};
#define MIN_NAPI_WORK 1
static inline dma_addr_t get_buf_addr(const struct rx_sw_desc *d)
{
return d->dma_addr & ~(dma_addr_t)RX_BUF_FLAGS;
}
static inline bool is_buf_mapped(const struct rx_sw_desc *d)
{
return !(d->dma_addr & RX_UNMAPPED_BUF);
}
/**
* txq_avail - return the number of available slots in a Tx queue
* @q: the Tx queue
*
* Returns the number of descriptors in a Tx queue available to write new
* packets.
*/
static inline unsigned int txq_avail(const struct sge_txq *q)
{
return q->size - 1 - q->in_use;
}
/**
* fl_cap - return the capacity of a free-buffer list
* @fl: the FL
*
* Returns the capacity of a free-buffer list. The capacity is less than
* the size because one descriptor needs to be left unpopulated, otherwise
* HW will think the FL is empty.
*/
static inline unsigned int fl_cap(const struct sge_fl *fl)
{
return fl->size - 8; /* 1 descriptor = 8 buffers */
Annotation
- Immediate include surface: `linux/skbuff.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/if_vlan.h`, `linux/ip.h`, `linux/dma-mapping.h`, `linux/jiffies.h`, `linux/prefetch.h`.
- Detected declarations: `struct rx_sw_desc`, `function fl_mtu_bufsize`, `function get_buf_addr`, `function is_buf_mapped`, `function txq_avail`, `function fl_cap`, `function fl_starving`, `function cxgb4_map_skb`, `function unmap_skb`, `function deferred_unmap_destructor`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration 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.