From d4b10de4b0736d35819bc44d1d86e9bb1b71a1d5 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 26 Apr 2013 13:36:05 +0800 Subject: [PATCH] Modules/IPStack - Added MAC checksum offload support --- .../Modules/IPStack/include/adapters_api.h | 2 +- KernelLand/Modules/IPStack/link.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/KernelLand/Modules/IPStack/include/adapters_api.h b/KernelLand/Modules/IPStack/include/adapters_api.h index 78729986..60e7eb44 100644 --- a/KernelLand/Modules/IPStack/include/adapters_api.h +++ b/KernelLand/Modules/IPStack/include/adapters_api.h @@ -20,7 +20,7 @@ enum eIPStack_AdapterTypes // Checksum offloading #define ADAPTERFLAG_OFFLOAD_MAC (1 << 0) #define ADAPTERFLAG_OFFLOAD_IP4 (1 << 1) -#define ADAPTERFLAG_OFFLOAD_IP6 (1 << 2) +#define ADAPTERFLAG_OFFLOAD_80211q (1 << 2) #define ADAPTERFLAG_OFFLOAD_TCP (1 << 3) #define ADAPTERFLAG_OFFLOAD_UDP (1 << 4) diff --git a/KernelLand/Modules/IPStack/link.c b/KernelLand/Modules/IPStack/link.c index c4f716f0..d92504b7 100644 --- a/KernelLand/Modules/IPStack/link.c +++ b/KernelLand/Modules/IPStack/link.c @@ -82,23 +82,27 @@ void Link_RegisterType(Uint16 Type, tPacketCallback Callback) void Link_SendPacket(tAdapter *Adapter, Uint16 Type, tMacAddr To, tIPStackBuffer *Buffer) { int length = IPStack_Buffer_GetLength(Buffer); - int ofs = 4 - (length & 3); + int ofs = (4 - (length & 3)) & 3; Uint8 buf[sizeof(tEthernetHeader) + ofs + 4]; + Uint32 *checksum = (void*)(buf + sizeof(tEthernetHeader) + ofs); tEthernetHeader *hdr = (void*)buf; - if( ofs == 4 ) ofs = 0; - Log_Log("Net Link", "Sending %i bytes to %02x:%02x:%02x:%02x:%02x:%02x (Type 0x%x)", length, To.B[0], To.B[1], To.B[2], To.B[3], To.B[4], To.B[5], Type); hdr->Dest = To; memcpy(&hdr->Src, Adapter->HWAddr, 6); // TODO: Remove hard coded 6 hdr->Type = htons(Type); - *(Uint32*)(buf + sizeof(tEthernetHeader) + ofs) = 0; + memset(hdr, 0, ofs+4); // zero padding and checksum - IPStack_Buffer_AppendSubBuffer(Buffer, sizeof(tEthernetHeader), ofs + 4, hdr, NULL, NULL); - - *(Uint32*)(buf + sizeof(tEthernetHeader) + ofs) = htonl( Link_CalculateCRC(Buffer) ); + if( (Adapter->Type->Flags & ADAPTERFLAG_OFFLOAD_MAC) ) + IPStack_Buffer_AppendSubBuffer(Buffer, sizeof(tEthernetHeader), ofs, hdr, NULL, NULL); + else + { + IPStack_Buffer_AppendSubBuffer(Buffer, sizeof(tEthernetHeader), ofs + 4, hdr, NULL, NULL); + *checksum = htonl( Link_CalculateCRC(Buffer) ); + Log_Debug("Net Link", "Non-Offloaded: 0x%x, 0x%x", *checksum, ntohl(*checksum)); + } Log_Log("Net Link", " from %02x:%02x:%02x:%02x:%02x:%02x", hdr->Src.B[0], hdr->Src.B[1], hdr->Src.B[2], -- 2.20.1