xref: /reactos/drivers/network/dd/dc21x4/sendrcv.h (revision 59d8a77d)
1 /*
2  * PROJECT:     ReactOS DC21x4 Driver
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Send and receive definitions
5  * COPYRIGHT:   Copyright 2023 Dmitry Borisov <di.sean@protonmail.com>
6  */
7 
8 #pragma once
9 
10 #define DC_LIST_ENTRY_FROM_PACKET(Packet) \
11     ((PLIST_ENTRY)(&(Packet)->MiniportReservedEx[0]))
12 
13 #define DC_PACKET_FROM_LIST_ENTRY(ListEntry) \
14     (CONTAINING_RECORD(ListEntry, NDIS_PACKET, MiniportReservedEx))
15 
16 #define DC_RCB_FROM_PACKET(Packet) \
17     ((PDC_RCB*)&(Packet)->MiniportReservedEx[0])
18 
19 #define DC_RBD_FROM_PACKET(Packet) \
20     ((PDC_RBD*)&(Packet)->MiniportReservedEx[sizeof(PVOID)])
21 
22 typedef struct _DC_COALESCE_BUFFER
23 {
24     /* Must be the first entry */
25     SINGLE_LIST_ENTRY ListEntry;
26 
27     PVOID VirtualAddress;
28     ULONG PhysicalAddress;
29 } DC_COALESCE_BUFFER, *PDC_COALESCE_BUFFER;
30 
31 typedef struct _DC_TCB
32 {
33     PDC_TBD Tbd;
34     PNDIS_PACKET Packet;
35     PDC_COALESCE_BUFFER Buffer;
36     ULONG SlotsUsed;
37 } DC_TCB, *PDC_TCB;
38 
39 typedef struct _DC_RCB
40 {
41     /* Must be the first entry */
42     SINGLE_LIST_ENTRY ListEntry;
43 
44     ULONG PhysicalAddress;
45     ULONG Flags;
46 #define DC_RCB_FLAG_RECLAIM          0x80000000
47 
48     PNDIS_PACKET Packet;
49     PNDIS_BUFFER NdisBuffer;
50     PVOID VirtualAddress;
51     PVOID VirtualAddressOriginal;
52     NDIS_PHYSICAL_ADDRESS PhysicalAddressOriginal;
53     SINGLE_LIST_ENTRY AllocListEntry;
54 } DC_RCB, *PDC_RCB;
55 
56 FORCEINLINE
57 VOID
DC_RELEASE_TCB(_In_ PDC21X4_ADAPTER Adapter,_In_ PDC_TCB Tcb)58 DC_RELEASE_TCB(
59     _In_ PDC21X4_ADAPTER Adapter,
60     _In_ PDC_TCB Tcb)
61 {
62     if (Tcb->Buffer)
63     {
64         PushEntryList(&Adapter->SendBufferList, &Tcb->Buffer->ListEntry);
65     }
66 
67     ++Adapter->TcbSlots;
68 
69     Adapter->TbdSlots += Tcb->SlotsUsed;
70 }
71 
72 FORCEINLINE
73 PDC_TCB
DC_NEXT_TCB(_In_ PDC21X4_ADAPTER Adapter,_In_ PDC_TCB Tcb)74 DC_NEXT_TCB(
75     _In_ PDC21X4_ADAPTER Adapter,
76     _In_ PDC_TCB Tcb)
77 {
78     if (Tcb++ == Adapter->TailTcb)
79         return Adapter->HeadTcb;
80     else
81         return Tcb;
82 }
83 
84 FORCEINLINE
85 PDC_TBD
DC_NEXT_TBD(_In_ PDC21X4_ADAPTER Adapter,_In_ PDC_TBD Tbd)86 DC_NEXT_TBD(
87     _In_ PDC21X4_ADAPTER Adapter,
88     _In_ PDC_TBD Tbd)
89 {
90     if (Tbd++ == Adapter->TailTbd)
91         return Adapter->HeadTbd;
92     else
93         return Tbd;
94 }
95 
96 FORCEINLINE
97 PDC_RBD
DC_NEXT_RBD(_In_ PDC21X4_ADAPTER Adapter,_In_ PDC_RBD Rbd)98 DC_NEXT_RBD(
99     _In_ PDC21X4_ADAPTER Adapter,
100     _In_ PDC_RBD Rbd)
101 {
102     if (Rbd++ == Adapter->TailRbd)
103         return Adapter->HeadRbd;
104     else
105         return Rbd;
106 }
107 
108 FORCEINLINE
109 PDC_RCB*
DC_GET_RCB_SLOT(_In_ PDC21X4_ADAPTER Adapter,_In_ PDC_RBD Rbd)110 DC_GET_RCB_SLOT(
111     _In_ PDC21X4_ADAPTER Adapter,
112     _In_ PDC_RBD Rbd)
113 {
114     return Adapter->RcbArray + (((ULONG_PTR)(Rbd - Adapter->HeadRbd)));
115 }
116