drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_rxtx.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_rxtx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_rxtx.c- Extension
.c- Size
- 10147 bytes
- Lines
- 365
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/aead.hnet/xfrm.hnet/esp.hipsec.hipsec_rxtx.hen.hesw/ipsec_fs.h
Detected Declarations
function mlx5e_ipsec_remove_trailerfunction mlx5e_ipsec_set_swpfunction mlx5e_ipsec_set_iv_esnfunction mlx5e_ipsec_set_ivfunction mlx5e_ipsec_handle_tx_wqefunction mlx5e_ipsec_set_statefunction mlx5e_ipsec_tx_build_esegfunction mlx5e_ipsec_handle_tx_skbfunction mlx5e_ipsec_offload_handle_rx_skbfunction mlx5_esw_ipsec_rx_make_metadata
Annotated Snippet
switch (xo->inner_ipproto) {
case IPPROTO_UDP:
eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L4_UDP;
fallthrough;
case IPPROTO_TCP:
/* IP | ESP | IP | [TCP | UDP] */
eseg->swp_inner_l4_offset = skb_inner_transport_offset(skb) / 2;
break;
default:
break;
}
return;
}
/* Transport mode */
if (mode != XFRM_MODE_TRANSPORT)
return;
if (!xo->inner_ipproto) {
switch (xo->proto) {
case IPPROTO_UDP:
eseg->swp_flags |= MLX5_ETH_WQE_SWP_OUTER_L4_UDP;
fallthrough;
case IPPROTO_TCP:
/* IP | ESP | TCP */
eseg->swp_outer_l4_offset = skb_inner_transport_offset(skb) / 2;
break;
default:
break;
}
} else {
/* Tunnel(VXLAN TCP/UDP) over Transport Mode */
switch (xo->inner_ipproto) {
case IPPROTO_UDP:
eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L4_UDP;
fallthrough;
case IPPROTO_TCP:
eseg->swp_inner_l3_offset = skb_inner_network_offset(skb) / 2;
eseg->swp_inner_l4_offset =
(skb->csum_start + skb->head - skb->data) / 2;
if (inner_ip_hdr(skb)->version == 6)
eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L3_IPV6;
break;
default:
break;
}
}
}
void mlx5e_ipsec_set_iv_esn(struct sk_buff *skb, struct xfrm_state *x,
struct xfrm_offload *xo)
{
struct xfrm_replay_state_esn *replay_esn = x->replay_esn;
__u32 oseq = replay_esn->oseq;
int iv_offset;
__be64 seqno;
u32 seq_hi;
if (unlikely(skb_is_gso(skb) && oseq < MLX5E_IPSEC_ESN_SCOPE_MID &&
MLX5E_IPSEC_ESN_SCOPE_MID < (oseq - skb_shinfo(skb)->gso_segs))) {
seq_hi = xo->seq.hi - 1;
} else {
seq_hi = xo->seq.hi;
}
/* Place the SN in the IV field */
seqno = cpu_to_be64(xo->seq.low + ((u64)seq_hi << 32));
iv_offset = skb_transport_offset(skb) + sizeof(struct ip_esp_hdr);
skb_store_bits(skb, iv_offset, &seqno, 8);
}
void mlx5e_ipsec_set_iv(struct sk_buff *skb, struct xfrm_state *x,
struct xfrm_offload *xo)
{
int iv_offset;
__be64 seqno;
/* Place the SN in the IV field */
seqno = cpu_to_be64(xo->seq.low + ((u64)xo->seq.hi << 32));
iv_offset = skb_transport_offset(skb) + sizeof(struct ip_esp_hdr);
skb_store_bits(skb, iv_offset, &seqno, 8);
}
void mlx5e_ipsec_handle_tx_wqe(struct mlx5e_tx_wqe *wqe,
struct mlx5e_accel_tx_ipsec_state *ipsec_st,
struct mlx5_wqe_inline_seg *inlseg)
{
inlseg->byte_count = cpu_to_be32(ipsec_st->tailen | MLX5_INLINE_SEG);
esp_output_fill_trailer((u8 *)inlseg->data, 0, ipsec_st->plen, ipsec_st->xo->proto);
Annotation
- Immediate include surface: `crypto/aead.h`, `net/xfrm.h`, `net/esp.h`, `ipsec.h`, `ipsec_rxtx.h`, `en.h`, `esw/ipsec_fs.h`.
- Detected declarations: `function mlx5e_ipsec_remove_trailer`, `function mlx5e_ipsec_set_swp`, `function mlx5e_ipsec_set_iv_esn`, `function mlx5e_ipsec_set_iv`, `function mlx5e_ipsec_handle_tx_wqe`, `function mlx5e_ipsec_set_state`, `function mlx5e_ipsec_tx_build_eseg`, `function mlx5e_ipsec_handle_tx_skb`, `function mlx5e_ipsec_offload_handle_rx_skb`, `function mlx5_esw_ipsec_rx_make_metadata`.
- 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.
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.