Skip to content

Commit 2d7e339

Browse files
authored
add offload options to task offload API (#87)
1 parent e920feb commit 2d7e339

File tree

7 files changed

+76
-7
lines changed

7 files changed

+76
-7
lines changed

inc/fniotypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,8 @@ typedef enum _FN_OFFLOAD_TYPE {
152152
FnOffloadHardwareCapabilities,
153153
} FN_OFFLOAD_TYPE;
154154

155+
typedef struct _FN_OFFLOAD_OPTIONS {
156+
UINT32 GsoMaxOffloadSize;
157+
} FN_OFFLOAD_OPTIONS;
158+
155159
EXTERN_C_END

inc/fnmpapi.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,23 @@ FnMpOidCompleteRequest(
377377
return FnIoctl(Handle, FNMP_IOCTL_OID_COMPLETE_REQUEST, &In, sizeof(In), NULL, 0, NULL, NULL);
378378
}
379379

380+
FNMPAPI
381+
VOID
382+
FnMpInitializeOffloadOptions(
383+
_Out_ FN_OFFLOAD_OPTIONS *OffloadOptions
384+
)
385+
{
386+
RtlZeroMemory(OffloadOptions, sizeof(*OffloadOptions));
387+
}
388+
380389
FNMPAPI
381390
FNMPAPI_STATUS
382-
FnMpUpdateTaskOffload(
391+
FnMpUpdateTaskOffload2(
383392
_In_ FNMP_HANDLE Handle,
384393
_In_ FN_OFFLOAD_TYPE OffloadType,
385394
_In_opt_ const NDIS_OFFLOAD_PARAMETERS *OffloadParameters,
386-
_In_ UINT32 OffloadParametersLength
395+
_In_ UINT32 OffloadParametersLength,
396+
_In_opt_ FN_OFFLOAD_OPTIONS *OffloadOptions
387397
)
388398
{
389399
MINIPORT_UPDATE_TASK_OFFLOAD_IN In = {0};
@@ -396,13 +406,30 @@ FnMpUpdateTaskOffload(
396406
// configuration from the registry. If the offload parameters are specfied,
397407
// the miniport handles this as if it were set via OID.
398408
//
409+
// The offload options optionally override the NIC's default capabilities.
410+
//
399411

400412
In.OffloadType = OffloadType;
401413
In.OffloadParameters = OffloadParameters;
402414
In.OffloadParametersLength = OffloadParametersLength;
415+
In.OffloadOptions = OffloadOptions;
403416

404417
return
405418
FnIoctl(Handle, FNMP_IOCTL_MINIPORT_UPDATE_TASK_OFFLOAD, &In, sizeof(In), NULL, 0, NULL, NULL);
406419
}
407420

421+
FNMPAPI
422+
FNMPAPI_STATUS
423+
FnMpUpdateTaskOffload(
424+
_In_ FNMP_HANDLE Handle,
425+
_In_ FN_OFFLOAD_TYPE OffloadType,
426+
_In_opt_ const NDIS_OFFLOAD_PARAMETERS *OffloadParameters,
427+
_In_ UINT32 OffloadParametersLength
428+
)
429+
{
430+
return
431+
FnMpUpdateTaskOffload2(
432+
Handle, OffloadType, OffloadParameters, OffloadParametersLength, NULL);
433+
}
434+
408435
EXTERN_C_END

inc/fnmpioctl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ typedef struct _MINIPORT_UPDATE_TASK_OFFLOAD_IN {
101101
FN_OFFLOAD_TYPE OffloadType;
102102
const NDIS_OFFLOAD_PARAMETERS *OffloadParameters;
103103
UINT32 OffloadParametersLength;
104+
const FN_OFFLOAD_OPTIONS *OffloadOptions;
104105
} MINIPORT_UPDATE_TASK_OFFLOAD_IN;
105106

106107
EXTERN_C_END

src/mp/sys/miniport.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ MpOpenConfiguration(
328328
return Status;
329329
}
330330

331+
static
332+
VOID
333+
MpInitializeOffload(
334+
_Inout_ ADAPTER_OFFLOAD *Offload
335+
)
336+
{
337+
Offload->GsoMaxOffloadSize = MAX_GSO_SIZE;
338+
}
339+
331340
static
332341
NDIS_STATUS
333342
MpReadConfiguration(
@@ -345,6 +354,8 @@ MpReadConfiguration(
345354
Adapter->MtuSize = FNMP_DEFAULT_MTU - ETH_HDR_LEN;
346355
Adapter->CurrentLookAhead = 0;
347356
Adapter->CurrentPacketFilter = 0;
357+
MpInitializeOffload(&Adapter->OffloadCapabilities);
358+
MpInitializeOffload(&Adapter->OffloadConfig);
348359

349360
Adapter->RssEnabled = 0;
350361
TRY_READ_INT_CONFIGURATION(ConfigHandle, &RegRSS, &Adapter->RssEnabled);
@@ -452,28 +463,28 @@ MpFillOffload(
452463

453464
if (AdapterOffload->LsoV2IPv4) {
454465
Offload->LsoV2.IPv4.Encapsulation = Encapsulation;
455-
Offload->LsoV2.IPv4.MaxOffLoadSize = MAX_GSO_SIZE;
466+
Offload->LsoV2.IPv4.MaxOffLoadSize = AdapterOffload->GsoMaxOffloadSize;
456467
Offload->LsoV2.IPv4.MinSegmentCount = MIN_GSO_SEG_COUNT;
457468
}
458469

459470
if (AdapterOffload->LsoV2IPv6) {
460471
Offload->LsoV2.IPv6.Encapsulation = Encapsulation;
461-
Offload->LsoV2.IPv6.MaxOffLoadSize = MAX_GSO_SIZE;
472+
Offload->LsoV2.IPv6.MaxOffLoadSize = AdapterOffload->GsoMaxOffloadSize;
462473
Offload->LsoV2.IPv6.MinSegmentCount = MIN_GSO_SEG_COUNT;
463474
Offload->LsoV2.IPv6.IpExtensionHeadersSupported = NDIS_OFFLOAD_SUPPORTED;
464475
Offload->LsoV2.IPv6.TcpOptionsSupported = NDIS_OFFLOAD_SUPPORTED;
465476
}
466477

467478
if (AdapterOffload->UsoIPv4) {
468479
Offload->UdpSegmentation.IPv4.Encapsulation = Encapsulation;
469-
Offload->UdpSegmentation.IPv4.MaxOffLoadSize = MAX_GSO_SIZE;
480+
Offload->UdpSegmentation.IPv4.MaxOffLoadSize = AdapterOffload->GsoMaxOffloadSize;
470481
Offload->UdpSegmentation.IPv4.MinSegmentCount = MIN_GSO_SEG_COUNT;
471482
Offload->UdpSegmentation.IPv4.SubMssFinalSegmentSupported = NDIS_OFFLOAD_SUPPORTED;
472483
}
473484

474485
if (AdapterOffload->UsoIPv6) {
475486
Offload->UdpSegmentation.IPv6.Encapsulation = Encapsulation;
476-
Offload->UdpSegmentation.IPv6.MaxOffLoadSize = MAX_GSO_SIZE;
487+
Offload->UdpSegmentation.IPv6.MaxOffLoadSize = AdapterOffload->GsoMaxOffloadSize;
477488
Offload->UdpSegmentation.IPv6.MinSegmentCount = MIN_GSO_SEG_COUNT;
478489
Offload->UdpSegmentation.IPv6.IpExtensionHeadersSupported = NDIS_OFFLOAD_SUPPORTED;
479490
Offload->UdpSegmentation.IPv6.SubMssFinalSegmentSupported = NDIS_OFFLOAD_SUPPORTED;

src/mp/sys/miniport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct _ADAPTER_OFFLOAD {
5656
UINT32 RscIPv4;
5757
UINT32 RscIPv6;
5858
UINT32 UdpRsc;
59+
UINT32 GsoMaxOffloadSize;
5960
} ADAPTER_OFFLOAD;
6061

6162
typedef struct _ADAPTER_CONTEXT {

src/mp/sys/shared.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,13 @@ SharedIrpUpdateTaskOffload(
150150
ADAPTER_CONTEXT *Adapter = Shared->Adapter;
151151
NDIS_HANDLE ConfigHandle = NULL;
152152
BOUNCE_BUFFER OffloadParameters;
153+
BOUNCE_BUFFER OffloadOptions;
153154
NTSTATUS Status;
154155
NDIS_OFFLOAD Offload;
155156
UINT32 IndicationStatus;
156157

157158
BounceInitialize(&OffloadParameters);
159+
BounceInitialize(&OffloadOptions);
158160

159161
if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(*In)) {
160162
Status = STATUS_BUFFER_TOO_SMALL;
@@ -172,6 +174,28 @@ SharedIrpUpdateTaskOffload(
172174
NDIS_STATUS_TASK_OFFLOAD_CURRENT_CONFIG :
173175
NDIS_STATUS_TASK_OFFLOAD_HARDWARE_CAPABILITIES;
174176

177+
if (In->OffloadOptions != NULL) {
178+
FN_OFFLOAD_OPTIONS *Options;
179+
180+
Status =
181+
BounceBuffer(
182+
&OffloadOptions, Irp->RequestorMode, In->OffloadOptions, sizeof(*Options),
183+
__alignof(FN_OFFLOAD_OPTIONS));
184+
if (!NT_SUCCESS(Status)) {
185+
goto Exit;
186+
}
187+
188+
Options = OffloadOptions.Buffer;
189+
190+
RtlAcquirePushLockExclusive(&Adapter->PushLock);
191+
192+
if (Options->GsoMaxOffloadSize != 0) {
193+
MpGetOffload(Adapter, In->OffloadType)->GsoMaxOffloadSize = Options->GsoMaxOffloadSize;
194+
}
195+
196+
RtlReleasePushLockExclusive(&Adapter->PushLock);
197+
}
198+
175199
if (In->OffloadParametersLength > 0) {
176200
Status =
177201
BounceBuffer(
@@ -211,6 +235,7 @@ SharedIrpUpdateTaskOffload(
211235
NdisCloseConfiguration(ConfigHandle);
212236
}
213237

238+
BounceCleanup(&OffloadOptions);
214239
BounceCleanup(&OffloadParameters);
215240

216241
return Status;

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "major": 0, "minor": 5, "patch": 1 }
1+
{ "major": 0, "minor": 5, "patch": 2 }

0 commit comments

Comments
 (0)