Skip to content

feat(igc): enable tx checksum offload#694

Merged
ytakano merged 5 commits into
tier4:mainfrom
ytakano:igc_tx_csum_offload
Jun 11, 2026
Merged

feat(igc): enable tx checksum offload#694
ytakano merged 5 commits into
tier4:mainfrom
ytakano:igc_tx_csum_offload

Conversation

@ytakano

@ytakano ytakano commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Add ActiveChecksumContext enum to Tx to track and reuse context descriptors
  • Add igc_tx_ctx_setup() to program the Advanced TX Context Descriptor for IPv4, TCP/IPv4, and UDP/IPv4 checksum offload
  • Update igc_send() to prepend a context descriptor when offload context changes
  • Advertise CSUM_IPv4, CSUM_TCPv4, and CSUM_UDPv4 capabilities
  • Enable TCP checksum offload in if_net and update the capability comment

Related links

How was this PR tested?

Notes for reviewers

ytakano and others added 2 commits June 8, 2026 18:30
- Add ActiveChecksumContext enum to Tx to track and reuse context descriptors
- Add igc_tx_ctx_setup() to program the Advanced TX Context Descriptor for
  IPv4, TCP/IPv4, and UDP/IPv4 checksum offload
- Update igc_send() to prepend a context descriptor when offload context changes
- Advertise CSUM_IPv4, CSUM_TCPv4, and CSUM_UDPv4 capabilities
- Enable TCP checksum offload in if_net and update the capability comment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Yuuki Takano <ytakanoster@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds IPv4/TCPv4/UDPv4 TX checksum offload support for the Intel IGC (I225/I226) driver by introducing advanced TX context descriptors and advertising the corresponding network capabilities so the stack can request hardware checksum insertion.

Changes:

  • Add tracking for the “active” TX checksum context and emit an Advanced TX Context Descriptor when the offload context changes.
  • Advertise CSUM_IPv4, CSUM_TCPv4, and CSUM_UDPv4 capabilities in the IGC driver and enable TCP checksum offload in the network interface capabilities mapping.
  • Extend IGC descriptor definitions/structures to support Advanced Context Descriptors.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
awkernel_lib/src/net/if_net.rs Enables TCP checksum offload reporting to smoltcp when the device advertises CSUM_TCPv4.
awkernel_drivers/src/pcie/intel/igc/igc_defines.rs Adds constants needed to build Advanced TX Context Descriptors for checksum offload.
awkernel_drivers/src/pcie/intel/igc/igc_base.rs Extends the advanced TX descriptor union to include the context descriptor view.
awkernel_drivers/src/pcie/intel/igc.rs Implements context descriptor setup, context reuse tracking, capability advertisement, and send-path changes to prepend context descriptors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread awkernel_drivers/src/pcie/intel/igc.rs Outdated
Comment thread awkernel_drivers/src/pcie/intel/igc.rs
Comment thread awkernel_drivers/src/pcie/intel/igc.rs Outdated
Comment thread awkernel_drivers/src/pcie/intel/igc.rs Outdated
ytakano and others added 2 commits June 10, 2026 06:34
Validated on real I225 hardware (UDP echo + TCP both work, valid on-wire
checksums confirmed via tcpdump on the peer).

- IP header length in the advanced context descriptor was programmed in
  32-bit words instead of bytes (`header_len()` returns IHL). With the wrong
  length the NIC mis-placed the checksums and IP packets never egressed
  correctly; shift IHL left by 2 to get bytes (matches the igb driver).
- Seed the IPv4 pseudo-header checksum into the L4 checksum field before DMA.
  smoltcp leaves it zero when TX checksum is offloaded, so without the seed
  the NIC computed segment-only checksums and every TCP/UDP checksum was wrong
  on the wire. Add `igc_pseudo_cksum()` and write it at the L4 csum offset.
- Restore `active_checksum_context` when `igc_send()` bails out due to
  insufficient descriptors, so the software context cannot desync from what
  the hardware actually saw (addresses the review's state-desync concern).
- Reclaim context descriptors in `igc_txeof()`: they carry no DD writeback,
  so the per-descriptor DD scan would stall at the first one and eventually
  wedge TX once the ring filled. Treat a non-DD descriptor whose successor is
  done as a consumed context descriptor.
- Derive `Copy, Clone` for `ActiveChecksumContext` to support the snapshot.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Factor the L4 checksum seed `(usize, u16)` into a `L4CksumSeed` type alias so
`igc_tx_ctx_setup`'s return type is no longer flagged by clippy::type_complexity.
No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ytakano ytakano marked this pull request as ready for review June 10, 2026 01:40
@ytakano ytakano requested a review from atsushi421 June 10, 2026 02:21
Comment thread awkernel_drivers/src/pcie/intel/igc.rs Outdated
Comment thread awkernel_drivers/src/pcie/intel/igc.rs
Comment thread awkernel_drivers/src/pcie/intel/igc.rs
Comment thread awkernel_drivers/src/pcie/intel/igc.rs Outdated
Comment thread awkernel_drivers/src/pcie/intel/igc.rs
Comment thread awkernel_drivers/src/pcie/intel/igc.rs Outdated
Comment thread awkernel_drivers/src/pcie/intel/igc.rs
Validated on real I225 hardware (UDP echo + TCP, all egress checksums valid).

- igc_txeof: guard the context-descriptor look-ahead against the producer
  index so reclaim can never advance `next_to_clean` at/past `next_avail_desc`
  and corrupt `igc_desc_unused()` accounting.
- igc_send: reserve room for the worst case (ctx + data) with an up-front
  `igc_desc_unused() < 2` check (OpenBSD igc style), removing the fragile
  snapshot/restore of `active_checksum_context` on the bail-out path.
- igc_tx_ctx_setup:
  - fast-path early return when `csum_flags` is empty, skipping header parsing
    on packets that need no offload (e.g. ARP).
  - drop (InvalidPacket) when `extract_headers` fails on an offload-requested
    frame instead of posting an unchecksummed packet (mirrors igb/ixgbe).
  - drop IP fragments: the L4 header is not at the expected offset and hardware
    L4 offload cannot complete a fragmented checksum.
  - account for an inline 802.1Q VLAN tag (18-byte L2 header) when computing
    MACLEN and the pseudo-header seed offset.
- if_net::tx_packet_header_flags: gate TCP/UDP_CSUM_OUT on IPv4 so a non-IPv4
  (e.g. IPv6) TCP/UDP packet is not left with an unfilled checksum.
- Add IgcDriverErr::InvalidPacket.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@atsushi421 atsushi421 self-requested a review June 11, 2026 10:24
@ytakano ytakano merged commit 44b8726 into tier4:main Jun 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants