cxgb4_write_sgl(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… cxgb4_write_sgl β€” a Kernel API Manual moment ✨

okay so real talk, this is a page from the Kernel API Manual and honestly? it's giving "small function, big responsibility" πŸ’– like it's just one line of C in the synopsis but bestie it is doing the most under the hood. no cap. let's get into it πŸŽ€


🌸 NAME 🌸

cxgb4_write_sgl β€” bestie's whole job is to populate a scatter/gather list for a packet ✨ that's it, that's the vibe, that's the mission πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

void cxgb4_write_sgl (const struct sk_buff *skb , struct sge_txq *q ,
struct ulptx_sgl *sgl , u64 *end , unsigned int start , const dma_addr_t
*addr );

like look at that signature. six arguments. it's serving very much "trust me, I know what I'm doing" energy 😭🫢


πŸ’œ ARGUMENTS πŸ’œ

one bullet per bestie, no skipping, we do not skip here 🌈

  • skb β€” the literal packet πŸ‘‘ the main character of this whole situation fr fr
  • q β€” the Tx queue we are writing into πŸŽ€ that's where the goods are going
  • sgl β€” the starting location for writing the SGL 🌸 like, where the pen first touches the paper, iykyk
  • end β€” points right after the end of the SGL πŸ¦‹ so like, the finish line, but the finish line + 1
  • start β€” a start offset into the skb main-body data to include in the SGL ✨ the "we're jumping in at this byte" era
  • addr β€” the list of bus addresses for the SGL elements πŸ’– every element gets its address, we keep receipts

πŸ”₯ DESCRIPTION πŸ”₯

so basically β€” generates a gather list for the buffers that make up a packet 🧚 okay but here's the part where you actually have to pay attention, bestie, because there are ✨rules✨:

the caller must provide adequate space for the SGL that will be written πŸ‘ˆ not optional. not a suggestion. it's giving "you better have made room" πŸ’€

the SGL includes all of the packet's page fragments and the data in its main body β€” except for the first start bytes 🌸 like we're skipping the first start bytes of the main body, no takebacks.

and now the fussy bits, because this function is highkey picky:

  • sgl must be 16-byte aligned 🎯 not "roughly", not "close enough" β€” 16-byte aligned. periodt.
  • it also must be within a Tx descriptor with available space πŸ‘‘ so vibe check your descriptor first, bestie 🫢
  • end points right after the end of the SGL β€” but ⚠️ it does not account for any potential wrap around, i.e., end > sgl πŸ’…
ngl that last one is important: end is a "right after the end" pointer, and it straight up does not account for any potential wrap around β€” the page literally spells out end > sgl so like… hold that thought 😭✨

🌟 SEE ALSO 🌟

okay so the source is this kernel file right here: ./drivers/net/ethernet/chelsio/cxgb4/sge.c πŸŽ€ and the extended universe of cross-references is huge, like a whole friend group, so buckle up bestie πŸ¦‹:

txq_avail(9), fl_cap(9), fl_starving(9), deferred_unmap_destructor(9), free_tx_desc(9), reclaim_completed_tx(9), cxgb4_reclaim_completed_tx(9), free_rx_bufs(9), unmap_rx_buf(9), refill_fl(9), alloc_ring(9), sgl_len(9), flits_to_desc(9), is_eth_imm(9), calc_tx_flits(9), cxgb4_ring_tx_db(9), cxgb4_inline_tx_skb(9), t4_sge_eth_txq_egress_update(9), cxgb4_eth_xmit(9), t4vf_is_eth_imm(9), t4vf_calc_tx_flits(9), cxgb4_vf_eth_xmit(9), reclaim_completed_tx_imm(9), cxgb4_ethofld_send_flowc(9), is_imm(9), ctrlq_check_stop(9), ctrl_xmit(9), restart_ctrlq(9), t4_mgmt_tx(9), is_ofld_imm(9), calc_tx_flits_ofld(9), txq_stop_maperr(9), ofldtxq_stop(9), service_ofldq(9), ofld_xmit(9), restart_ofldq(9), skb_txq(9), is_ctrl_pkt(9), t4_ofld_send(9), cxgb4_ofld_send(9), ofld_xmit_direct(9), t4_crypto_send(9), cxgb4_crypto_send(9), cxgb4_pktgl_to_skb(9), t4_pktgl_free(9), cxgb4_sgetim_to_hwtstamp(9), t4_systim_to_hwstamp(9), t4_rx_hststamp(9), t4_tx_hststamp(9), t4_tx_completion_handler(9), t4_ethrx_handler(9), restore_rx_bufs(9), is_new_response(9), rspq_next(9), process_responses(9), napi_rx_handler(9), t4_intr_handler(9), bar2_address(9), t4_sge_alloc_eth_txq(9), t4_free_sge_resources(9), t4_sge_stop(9), t4_sge_init_soft(9), t4_sge_init(9) πŸ’–βœ¨


and that's the whole page, bestie 🫢 go forth, align your SGL to 16 bytes, and slay πŸ’…

✨ cute little sign-off: this iconic page comes from the source ./drivers/net/ethernet/chelsio... and it's dated October 2026, filed under cxgb4_write_sgl(9) πŸŽ€ mwah πŸ’‹
πŸ“¦ where this page comes from