1 /* 2 * PROJECT: ReactOS DC21x4 Driver 3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) 4 * PURPOSE: Utility header file 5 * COPYRIGHT: Copyright 2023 Dmitry Borisov <di.sean@protonmail.com> 6 */ 7 8 #pragma once 9 10 #include <pshpack1.h> 11 typedef struct _ETH_HEADER 12 { 13 UCHAR Destination[ETH_LENGTH_OF_ADDRESS]; 14 UCHAR Source[ETH_LENGTH_OF_ADDRESS]; 15 USHORT PayloadType; 16 } ETH_HEADER, *PETH_HEADER; 17 #include <poppack.h> 18 19 #define ETH_IS_LOCALLY_ADMINISTERED(Address) \ 20 ((BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x02))) 21 22 #define ETH_IS_EMPTY(Address) \ 23 ((BOOLEAN)((((PUCHAR)(Address))[0] | ((PUCHAR)(Address))[1] | ((PUCHAR)(Address))[2] | \ 24 ((PUCHAR)(Address))[3] | ((PUCHAR)(Address))[4] | ((PUCHAR)(Address))[5]) == 0)) 25 26 #if defined(_M_IX86) || defined(_M_AMD64) 27 /* Strict memory model, does not reorder Write-Write operations */ 28 #define DC_WRITE_BARRIER() KeMemoryBarrierWithoutFence() 29 #else 30 #define DC_WRITE_BARRIER() KeMemoryBarrier() 31 #endif 32 33 #if defined(_MSC_VER) 34 /* 35 * Merge with PAGE, we don't need a new pageable section. For a small amount of data, 36 * there is additional size overhead if the actual data size is smaller than section alignment. 37 * GCC doesn't seem to appreciate this idea. 38 */ 39 #define DC_PG_DATA DATA_SEG("PAGE") 40 #else 41 #define DC_PG_DATA 42 #endif 43 44 /* Access to unaligned memory */ 45 FORCEINLINE 46 USHORT 47 DcRetrieveWord( 48 _In_ const VOID* Data) 49 { 50 #if defined(_M_IX86) || defined(_M_AMD64) 51 /* Supported by ISA */ 52 return *(const UNALIGNED USHORT*)Data; 53 #else 54 USHORT Result; 55 56 NdisMoveMemory(&Result, Data, sizeof(Result)); 57 return Result; 58 #endif 59 } 60 61 #if DBG 62 #define DcPopEntryList PopEntryList 63 #else 64 /* 65 * This is an optimized version of the PopEntryList() function. 66 * We assume that the next entry has already been checked for nullability 67 * so we don't need to. 68 */ 69 FORCEINLINE 70 PSINGLE_LIST_ENTRY 71 DcPopEntryList( 72 _Inout_ PSINGLE_LIST_ENTRY ListHead) 73 { 74 PSINGLE_LIST_ENTRY FirstEntry; 75 76 FirstEntry = ListHead->Next; 77 78 ASSERT(FirstEntry); 79 80 ListHead->Next = FirstEntry->Next; 81 82 return FirstEntry; 83 } 84 #endif 85