ReactOS  0.4.15-dev-4570-g4f8bbd1
send.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Intel PRO/1000 Driver
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later.html)
4  * PURPOSE: Sending packets
5  * COPYRIGHT: Copyright 2018 Mark Jansen <mark.jansen@reactos.org>
6  * Copyright 2019 Victor Perevertkin <victor.perevertkin@reactos.org>
7  */
8 
9 #include "nic.h"
10 
11 #include <debug.h>
12 
13 static
16  _In_ PE1000_ADAPTER Adapter,
19 {
20  volatile PE1000_TRANSMIT_DESCRIPTOR TransmitDescriptor;
21 
22  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
23 
24  TransmitDescriptor = Adapter->TransmitDescriptors + Adapter->CurrentTxDesc;
25  TransmitDescriptor->Address = PhysicalAddress.QuadPart;
26  TransmitDescriptor->Length = Length;
27  TransmitDescriptor->ChecksumOffset = 0;
28  TransmitDescriptor->Command = E1000_TDESC_CMD_RS | E1000_TDESC_CMD_IFCS |
30  TransmitDescriptor->Status = 0;
31  TransmitDescriptor->ChecksumStartField = 0;
32  TransmitDescriptor->Special = 0;
33 
34  Adapter->CurrentTxDesc = (Adapter->CurrentTxDesc + 1) % NUM_TRANSMIT_DESCRIPTORS;
35 
36  E1000WriteUlong(Adapter, E1000_REG_TDT, Adapter->CurrentTxDesc);
37 
38  if (Adapter->CurrentTxDesc == Adapter->LastTxDesc)
39  {
40  NDIS_DbgPrint(MID_TRACE, ("All TX descriptors are full now\n"));
41  Adapter->TxFull = TRUE;
42  }
43 
44  return NDIS_STATUS_SUCCESS;
45 }
46 
48 NTAPI
50  _In_ NDIS_HANDLE MiniportAdapterContext,
52  _In_ UINT Flags)
53 {
54  PE1000_ADAPTER Adapter = (PE1000_ADAPTER)MiniportAdapterContext;
55  PSCATTER_GATHER_LIST sgList;
56  ULONG TransmitLength;
57  PHYSICAL_ADDRESS TransmitBuffer;
59 
61 
62  ASSERT(sgList != NULL);
63  ASSERT(sgList->NumberOfElements == 1);
64  ASSERT((sgList->Elements[0].Address.LowPart & 3) == 0);
65  ASSERT(sgList->Elements[0].Length <= MAXIMUM_FRAME_SIZE);
66 
67  if (Adapter->TxFull)
68  {
69  NDIS_DbgPrint(MIN_TRACE, ("All TX descriptors are full\n"));
70  return NDIS_STATUS_RESOURCES;
71  }
72 
73  TransmitLength = sgList->Elements[0].Length;
74  TransmitBuffer = sgList->Elements[0].Address;
75  Adapter->TransmitPackets[Adapter->CurrentTxDesc] = Packet;
76 
77  Status = NICTransmitPacket(Adapter, TransmitBuffer, TransmitLength);
79  {
80  NDIS_DbgPrint(MIN_TRACE, ("Transmit packet failed\n"));
81  return Status;
82  }
83 
84  return NDIS_STATUS_PENDING;
85 }
#define MID_TRACE
Definition: debug.h:15
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
#define E1000_TDESC_CMD_IDE
Definition: e1000hw.h:79
#define TRUE
Definition: types.h:120
#define E1000_TDESC_CMD_RS
Definition: e1000hw.h:80
FORCEINLINE VOID E1000WriteUlong(_In_ PE1000_ADAPTER Adapter, _In_ ULONG Address, _In_ ULONG Value)
Definition: nic.h:219
struct _E1000_ADAPTER * PE1000_ADAPTER
#define NUM_TRANSMIT_DESCRIPTORS
Definition: e1000hw.h:108
int NDIS_STATUS
Definition: ntddndis.h:475
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define _In_
Definition: ms_sal.h:308
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ASSERT(a)
Definition: mode.c:44
#define E1000_TDESC_CMD_EOP
Definition: e1000hw.h:82
BOOLEAN TxFull
Definition: nic.h:81
#define E1000_TDESC_CMD_IFCS
Definition: e1000hw.h:81
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
ULONG CurrentTxDesc
Definition: nic.h:79
PNDIS_PACKET TransmitPackets[NUM_TRANSMIT_DESCRIPTORS]
Definition: nic.h:77
#define E1000_REG_TDT
Definition: e1000hw.h:141
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
NDIS_STATUS NTAPI MiniportSend(_In_ NDIS_HANDLE MiniportAdapterContext, _In_ PNDIS_PACKET Packet, _In_ UINT Flags)
Definition: send.c:49
struct _SCATTER_GATHER_LIST * PSCATTER_GATHER_LIST
Definition: iotypes.h:2204
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14
static NDIS_STATUS NICTransmitPacket(_In_ PE1000_ADAPTER Adapter, _In_ PHYSICAL_ADDRESS PhysicalAddress, _In_ ULONG Length)
Definition: send.c:15
#define MAXIMUM_FRAME_SIZE
Definition: nic.h:19
#define NDIS_PER_PACKET_INFO_FROM_PACKET(Packet, InfoType)
Definition: ndis.h:1351
LONGLONG QuadPart
Definition: typedefs.h:114