Skip to content

Commit

Permalink
Add AF_XDP transmit checksum offload (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfriesen authored Dec 17, 2024
1 parent a7b0716 commit 16ca3c0
Show file tree
Hide file tree
Showing 27 changed files with 1,581 additions and 279 deletions.
9 changes: 9 additions & 0 deletions docs/api/driver-txqueueconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,13 @@ BOOLEAN
XdpTxQueueIsOutOfOrderCompletionEnabled(
_In_ XDP_TX_QUEUE_CONFIG_ACTIVATE TxQueueConfig
);

//
// Returns whether checksum offload is enabled.
//
BOOLEAN
XdpTxQueueIsChecksumOffloadEnabled(
_In_ XDP_TX_QUEUE_CONFIG_ACTIVATE TxQueueConfig
);

```
42 changes: 19 additions & 23 deletions published/external/afxdp_experimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
extern "C" {
#endif

#include <xdp/framechecksum.h>
#include <xdp/framelayout.h>

//
// XSK_SOCKOPT_POLL_MODE
//
Expand Down Expand Up @@ -52,51 +55,44 @@ typedef enum _XSK_POLL_MODE {
// XSK_SOCKOPT_TX_FRAME_LAYOUT_EXTENSION
//
// Supports: get
// Optval type: XDP_EXTENSION
// Optval type: UINT16
// Description: Gets the XDP_FRAME_LAYOUT descriptor extension for the TX frame
// ring. This requires the socket is bound, the TX ring size is
// set, and at least one socket option has enabled the frame layout
// extension.
// extension. The returned value is the offset of the
// XDP_FRAME_LAYOUT structure from the start of each TX descriptor.
//
#define XSK_SOCKOPT_TX_FRAME_LAYOUT_EXTENSION 1001

//
// XSK_SOCKOPT_TX_FRAME_CHECKSUM_EXTENSION
//
// Supports: get
// Optval type: XDP_EXTENSION
// Optval type: UINT16
// Description: Gets the XDP_FRAME_CHECKSUM descriptor extension for the TX
// frame ring. This requires the socket is bound, the TX ring size
// is set, and at least one socket option has enabled the frame
// layout extension.
// is set, and at least one socket option has enabled the checksum
// extension. The returned value is the offset of the
// XDP_FRAME_CHECKSUM structure from the start of each TX descriptor.
//
#define XSK_SOCKOPT_TX_FRAME_CHECKSUM_EXTENSION 1002

//
// XSK_SOCKOPT_OFFLOAD_UDP_CHECKSUM_TX
// XSK_SOCKOPT_TX_OFFLOAD_CHECKSUM
//
// Supports: set
// Optval type: BOOLEAN
// Description: Sets whether UDP checksum transmit offload is enabled. This
// Optval type: UINT32
// Description: Sets whether checksum transmit offload is enabled. This
// option requires the socket is bound and the TX frame ring size
// is not set. This option enables the XDP_FRAME_LAYOUT and
// XDP_FRAME_CHECKSUM extensions on the TX frame ring.
// If the socket is bound to a queue that has already been
// activated by another socket without enabling checksum offload,
// then enabling the offload on another socket is currently not
// supported. Disabling the offload after is has been enabled is
// also currently not supported.
//
#define XSK_SOCKOPT_OFFLOAD_UDP_CHECKSUM_TX 1003

//
// XSK_SOCKOPT_OFFLOAD_UDP_CHECKSUM_TX_CAPABILITIES
//
// Supports: get
// Optval type: XSK_OFFLOAD_UDP_CHECKSUM_TX_CAPABILITIES
// Description: Returns the UDP checksum transmit offload capabilities. This
// option requires the socket is bound.
//
#define XSK_SOCKOPT_OFFLOAD_UDP_CHECKSUM_TX_CAPABILITIES 1004

typedef struct _XSK_OFFLOAD_UDP_CHECKSUM_TX_CAPABILITIES {
BOOLEAN Supported;
} XSK_OFFLOAD_UDP_CHECKSUM_TX_CAPABILITIES;
#define XSK_SOCKOPT_TX_OFFLOAD_CHECKSUM 1003

#ifdef __cplusplus
} // extern "C"
Expand Down
16 changes: 16 additions & 0 deletions published/external/xdp/details/txqueueconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ typedef struct _XDP_TX_QUEUE_CONFIG_ACTIVATE_DISPATCH {
XDP_TX_QUEUE_ACTIVATE_IS_ENABLED *IsTxCompletionContextEnabled;
XDP_TX_QUEUE_ACTIVATE_IS_ENABLED *IsFragmentationEnabled;
XDP_TX_QUEUE_ACTIVATE_IS_ENABLED *IsOutOfOrderCompletionEnabled;
XDP_TX_QUEUE_ACTIVATE_IS_ENABLED *IsChecksumOffloadEnabled;
} XDP_TX_QUEUE_CONFIG_ACTIVATE_DISPATCH;

#define XDP_TX_QUEUE_CONFIG_ACTIVATE_DISPATCH_REVISION_1 1
Expand Down Expand Up @@ -236,4 +237,19 @@ XDPEXPORT(XdpTxQueueIsOutOfOrderCompletionEnabled)(
return Details->Dispatch->IsOutOfOrderCompletionEnabled(TxQueueConfig);
}

inline
BOOLEAN
XDPEXPORT(XdpTxQueueIsChecksumOffloadEnabled)(
_In_ XDP_TX_QUEUE_CONFIG_ACTIVATE TxQueueConfig
)
{
XDP_TX_QUEUE_CONFIG_ACTIVATE_DETAILS *Details = (XDP_TX_QUEUE_CONFIG_ACTIVATE_DETAILS *)TxQueueConfig;
if (Details->Dispatch->Header.Revision == XDP_TX_QUEUE_CONFIG_ACTIVATE_DISPATCH_REVISION_1 &&
Details->Dispatch->Header.Size >= RTL_SIZEOF_THROUGH_FIELD(XDP_TX_QUEUE_CONFIG_ACTIVATE_DISPATCH, IsChecksumOffloadEnabled)) {
return Details->Dispatch->IsChecksumOffloadEnabled(TxQueueConfig);
} else {
return FALSE;
}
}

EXTERN_C_END
41 changes: 41 additions & 0 deletions published/external/xdp/framechecksum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//

#pragma once

EXTERN_C_START

#pragma warning(push)
#pragma warning(default:4820) // warn if the compiler inserted padding
#pragma warning(disable:4201) // nonstandard extension used: nameless struct/union
#pragma warning(disable:4214) // nonstandard extension used: bit field types other than int

typedef enum _XDP_FRAME_TX_CHECKSUM_ACTION {
XdpFrameTxChecksumActionPassthrough = 0,
XdpFrameTxChecksumActionRequired = 1,
} XDP_FRAME_TX_CHECKSUM_ACTION;

typedef enum _XDP_FRAME_RX_CHECKSUM_EVALUATION {
XdpFrameRxChecksumEvaluationNotChecked = 0,
XdpFrameRxChecksumEvaluationSucceeded = 1,
XdpFrameRxChecksumEvaluationFailed = 2,
XdpFrameRxChecksumEvaluationInvalid = 3,
} XDP_FRAME_RX_CHECKSUM_EVALUATION;

typedef struct _XDP_FRAME_CHECKSUM {
// One of XDP_FRAME_TX_CHECKSUM_ACTION or XDP_FRAME_RX_CHECKSUM_EVALUATION
UINT8 Layer3 : 2;

// One of XDP_FRAME_TX_CHECKSUM_ACTION or XDP_FRAME_RX_CHECKSUM_EVALUATION
UINT8 Layer4 : 2;

UINT8 Reserved : 4;
} XDP_FRAME_CHECKSUM;

C_ASSERT(sizeof(XDP_FRAME_CHECKSUM) == 1);

#pragma warning(pop)

EXTERN_C_END
27 changes: 27 additions & 0 deletions published/external/xdp/framechecksumextension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//

#pragma once

EXTERN_C_START

#include <xdp/framechecksum.h>

#define XDP_FRAME_EXTENSION_CHECKSUM_NAME L"ms_frame_checksum"
#define XDP_FRAME_EXTENSION_CHECKSUM_VERSION_1 1U

#include <xdp/extension.h>

inline
XDP_FRAME_CHECKSUM *
XdpGetChecksumExtension(
_In_ XDP_FRAME *Frame,
_In_ XDP_EXTENSION *Extension
)
{
return (XDP_FRAME_CHECKSUM *)XdpGetExtensionData(Frame, Extension);
}

EXTERN_C_END
62 changes: 62 additions & 0 deletions published/external/xdp/framelayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//

#pragma once

EXTERN_C_START

#pragma warning(push)
#pragma warning(default:4820) // warn if the compiler inserted padding
#pragma warning(disable:4201) // nonstandard extension used: nameless struct/union
#pragma warning(disable:4214) // nonstandard extension used: bit field types other than int

typedef enum _XDP_FRAME_LAYER2_TYPE {
XdpFrameLayer2TypeUnspecified,
XdpFrameLayer2TypeNull,
XdpFrameLayer2TypeEthernet,
} XDP_FRAME_LAYER2_TYPE;

typedef enum _XDP_FRAME_LAYER3_TYPE {
XdpFrameLayer3TypeUnspecified,
XdpFrameLayer3TypeIPv4UnspecifiedOptions,
XdpFrameLayer3TypeIPv4WithOptions,
XdpFrameLayer3TypeIPv4NoOptions,
XdpFrameLayer3TypeIPv6UnspecifiedExtensions,
XdpFrameLayer3TypeIPv6WithExtensions,
XdpFrameLayer3TypeIPv6NoExtensions,
} XDP_FRAME_LAYER3_TYPE;

typedef enum _XDP_FRAME_LAYER4_TYPE {
XdpFrameLayer4TypeUnspecified,
XdpFrameLayer4TypeTcp,
XdpFrameLayer4TypeUdp,
XdpFrameLayer4TypeIPFragment,
XdpFrameLayer4TypeIPNotFragment,
} XDP_FRAME_LAYER4_TYPE;

#include <pshpack1.h>
typedef struct _XDP_FRAME_LAYOUT {
UINT16 Layer2HeaderLength : 7;
UINT16 Layer3HeaderLength : 9;
UINT8 Layer4HeaderLength : 8;

// One of the XDP_FRAME_LAYER2_TYPE values
UINT8 Layer2Type : 4;

// One of the XDP_FRAME_LAYER3_TYPE values
UINT8 Layer3Type : 4;

// One of the XDP_FRAME_LAYER4_TYPE values
UINT8 Layer4Type : 4;

UINT8 Reserved0 : 4;
} XDP_FRAME_LAYOUT;
#include <poppack.h>

C_ASSERT(sizeof(XDP_FRAME_LAYOUT) == 5);

#pragma warning(pop)

EXTERN_C_END
27 changes: 27 additions & 0 deletions published/external/xdp/framelayoutextension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//

#pragma once

EXTERN_C_START

#include <xdp/framelayout.h>

#define XDP_FRAME_EXTENSION_LAYOUT_NAME L"ms_frame_layout"
#define XDP_FRAME_EXTENSION_LAYOUT_VERSION_1 1U

#include <xdp/extension.h>

inline
XDP_FRAME_LAYOUT *
XdpGetLayoutExtension(
_In_ XDP_FRAME *Frame,
_In_ XDP_EXTENSION *Extension
)
{
return (XDP_FRAME_LAYOUT *)XdpGetExtensionData(Frame, Extension);
}

EXTERN_C_END
82 changes: 0 additions & 82 deletions published/external/xdp/offload.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,86 +13,6 @@ EXTERN_C_START
// significant changes.
//

#pragma warning(push)
#pragma warning(default:4820) // warn if the compiler inserted padding
#pragma warning(disable:4201) // nonstandard extension used: nameless struct/union
#pragma warning(disable:4214) // nonstandard extension used: bit field types other than int

typedef enum _XDP_FRAME_LAYER2_TYPE {
XdpFrameLayer2TypeUnspecified,
XdpFrameLayer2TypeNull,
XdpFrameLayer2TypeEthernet,
} XDP_FRAME_LAYER2_TYPE;

typedef enum _XDP_FRAME_LAYER3_TYPE {
XdpFrameLayer3TypeUnspecified,
XdpFrameLayer3TypeIPv4UnspecifiedOptions,
XdpFrameLayer3TypeIPv4WithOptions,
XdpFrameLayer3TypeIPv4NoOptions,
XdpFrameLayer3TypeIPv6UnspecifiedExtensions,
XdpFrameLayer3TypeIPv6WithExtensions,
XdpFrameLayer3TypeIPv6NoExtensions,
} XDP_FRAME_LAYER3_TYPE;

typedef enum _XDP_FRAME_LAYER4_TYPE {
XdpFrameLayer4TypeUnspecified,
XdpFrameLayer4TypeTcp,
XdpFrameLayer4TypeUdp,
XdpFrameLayer4TypeIPFragment,
XdpFrameLayer4TypeIPNotFragment,
} XDP_FRAME_LAYER4_TYPE;

#include <pshpack1.h>
typedef struct _XDP_FRAME_LAYOUT {
UINT16 Layer2HeaderLength : 7;
UINT16 Layer3HeaderLength : 9;
UINT8 Layer4HeaderLength : 8;

// One of the XDP_FRAME_LAYER2_TYPE values
UINT8 Layer2Type : 4;

// One of the XDP_FRAME_LAYER3_TYPE values
UINT8 Layer3Type : 4;

// One of the XDP_FRAME_LAYER4_TYPE values
UINT8 Layer4Type : 4;

UINT8 Reserved0 : 4;
} XDP_FRAME_LAYOUT;
#include <poppack.h>

C_ASSERT(sizeof(XDP_FRAME_LAYOUT) == 5);

#pragma warning(pop)

typedef enum _XDP_FRAME_TX_CHECKSUM_ACTION {
XdpFrameTxChecksumActionPassthrough = 0,
XdpFrameTxChecksumActionRequired = 1,
} XDP_FRAME_TX_CHECKSUM_ACTION;

typedef enum _XDP_FRAME_RX_CHECKSUM_EVALUATION {
XdpFrameRxChecksumEvaluationNotChecked = 0,
XdpFrameRxChecksumEvaluationSucceeded = 1,
XdpFrameRxChecksumEvaluationFailed = 2,
XdpFrameRxChecksumEvaluationInvalid = 3,
} XDP_FRAME_RX_CHECKSUM_EVALUATION;

#pragma warning(push)
#pragma warning(default:4820) // warn if the compiler inserted padding

typedef struct _XDP_FRAME_CHECKSUM {
// One of XDP_FRAME_TX_CHECKSUM_ACTION or XDP_FRAME_RX_CHECKSUM_EVALUATION
UINT8 Layer3 : 2;

// One of XDP_FRAME_TX_CHECKSUM_ACTION or XDP_FRAME_RX_CHECKSUM_EVALUATION
UINT8 Layer4 : 2;

UINT8 Reserved : 4;
} XDP_FRAME_CHECKSUM;

C_ASSERT(sizeof(XDP_FRAME_CHECKSUM) == 1);

#pragma warning(pop)

#pragma warning(push)
#pragma warning(default:4820) // warn if the compiler inserted padding
Expand Down Expand Up @@ -143,8 +63,6 @@ typedef struct _XDP_FRAME_GRO_TIMESTAMP {

C_ASSERT(sizeof(XDP_FRAME_GRO_TIMESTAMP) == 4);

#pragma warning(pop)

typedef struct _XDP_FRAME_TIMESTAMP {
UINT64 Timestamp;
} XDP_FRAME_TIMESTAMP;
Expand Down
6 changes: 6 additions & 0 deletions published/external/xdp/txqueueconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct _XDP_TX_CAPABILITIES {
UINT32 MaximumFrameSize;
UINT8 MaximumFragments;
BOOLEAN OutOfOrderCompletionEnabled;
BOOLEAN ChecksumOffload;
} XDP_TX_CAPABILITIES;


Expand Down Expand Up @@ -172,6 +173,11 @@ XdpTxQueueIsOutOfOrderCompletionEnabled(
_In_ XDP_TX_QUEUE_CONFIG_ACTIVATE TxQueueConfig
);

BOOLEAN
XdpTxQueueIsChecksumOffloadEnabled(
_In_ XDP_TX_QUEUE_CONFIG_ACTIVATE TxQueueConfig
);

#include <xdp/details/txqueueconfig.h>

EXTERN_C_END
Loading

0 comments on commit 16ca3c0

Please sign in to comment.