2 Implementation of transmitting a packet.
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Call UNDI to create the meadia header for the given data buffer.
15 @param Snp Pointer to SNP driver structure.
16 @param MacHeaderPtr Address where the media header will be filled in.
17 @param HeaderSize Size of the memory at MacHeaderPtr.
18 @param Buffer Data buffer pointer.
19 @param BufferSize Size of data in the Buffer
20 @param DestAddr Address of the destination mac address buffer.
21 @param SrcAddr Address of the source mac address buffer.
22 @param ProtocolPtr Address of the protocol type.
24 @retval EFI_SUCCESS Successfully completed the undi call.
25 @retval Other Error return from undi call.
35 EFI_MAC_ADDRESS
*DestAddr
,
36 EFI_MAC_ADDRESS
*SrcAddr
,
40 PXE_CPB_FILL_HEADER_FRAGMENTED
*Cpb
;
43 if (SrcAddr
!= NULL
) {
45 (VOID
*) Cpb
->SrcAddr
,
47 Snp
->Mode
.HwAddressSize
51 (VOID
*) Cpb
->SrcAddr
,
52 (VOID
*) &(Snp
->Mode
.CurrentAddress
),
53 Snp
->Mode
.HwAddressSize
58 (VOID
*) Cpb
->DestAddr
,
60 Snp
->Mode
.HwAddressSize
64 // we need to do the byte swapping
66 Cpb
->Protocol
= (UINT16
) PXE_SWAP_UINT16 (*ProtocolPtr
);
68 Cpb
->PacketLen
= (UINT32
) (BufferSize
);
69 Cpb
->MediaHeaderLen
= (UINT16
) HeaderSize
;
74 Cpb
->FragDesc
[0].FragAddr
= (UINT64
)(UINTN
) MacHeaderPtr
;
75 Cpb
->FragDesc
[0].FragLen
= (UINT32
) HeaderSize
;
76 Cpb
->FragDesc
[1].FragAddr
= (UINT64
)(UINTN
) Buffer
;
77 Cpb
->FragDesc
[1].FragLen
= (UINT32
) BufferSize
;
79 Cpb
->FragDesc
[0].reserved
= Cpb
->FragDesc
[1].reserved
= 0;
81 Snp
->Cdb
.OpCode
= PXE_OPCODE_FILL_HEADER
;
82 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_FILL_HEADER_FRAGMENTED
;
84 Snp
->Cdb
.DBsize
= PXE_DBSIZE_NOT_USED
;
85 Snp
->Cdb
.DBaddr
= PXE_DBADDR_NOT_USED
;
87 Snp
->Cdb
.CPBsize
= (UINT16
) sizeof (PXE_CPB_FILL_HEADER_FRAGMENTED
);
88 Snp
->Cdb
.CPBaddr
= (UINT64
)(UINTN
) Cpb
;
90 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
91 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
92 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
93 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
96 // Issue UNDI command and check result.
98 DEBUG ((EFI_D_NET
, "\nSnp->undi.fill_header() "));
100 (*Snp
->IssueUndi32Command
) ((UINT64
) (UINTN
) &Snp
->Cdb
);
102 switch (Snp
->Cdb
.StatCode
) {
103 case PXE_STATCODE_SUCCESS
:
106 case PXE_STATCODE_INVALID_PARAMETER
:
109 "\nSnp->undi.fill_header() %xh:%xh\n",
114 return EFI_INVALID_PARAMETER
;
119 "\nSnp->undi.fill_header() %xh:%xh\n",
124 return EFI_DEVICE_ERROR
;
130 This routine calls undi to transmit the given data buffer
132 @param Snp pointer to SNP driver structure
133 @param Buffer data buffer pointer
134 @param BufferSize Size of data in the Buffer
136 @retval EFI_SUCCESS if successfully completed the undi call
137 @retval Other error return from undi call.
147 PXE_CPB_TRANSMIT
*Cpb
;
151 Cpb
->FrameAddr
= (UINT64
) (UINTN
) Buffer
;
152 Cpb
->DataLen
= (UINT32
) BufferSize
;
154 Cpb
->MediaheaderLen
= 0;
157 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_TRANSMIT_WHOLE
;
159 Snp
->Cdb
.CPBsize
= (UINT16
) sizeof (PXE_CPB_TRANSMIT
);
160 Snp
->Cdb
.CPBaddr
= (UINT64
)(UINTN
) Cpb
;
162 Snp
->Cdb
.OpCode
= PXE_OPCODE_TRANSMIT
;
163 Snp
->Cdb
.DBsize
= PXE_DBSIZE_NOT_USED
;
164 Snp
->Cdb
.DBaddr
= PXE_DBADDR_NOT_USED
;
166 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
167 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
168 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
169 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
172 // Issue UNDI command and check result.
174 DEBUG ((EFI_D_NET
, "\nSnp->undi.transmit() "));
175 DEBUG ((EFI_D_NET
, "\nSnp->Cdb.OpCode == %x", Snp
->Cdb
.OpCode
));
176 DEBUG ((EFI_D_NET
, "\nSnp->Cdb.CPBaddr == %LX", Snp
->Cdb
.CPBaddr
));
177 DEBUG ((EFI_D_NET
, "\nSnp->Cdb.DBaddr == %LX", Snp
->Cdb
.DBaddr
));
178 DEBUG ((EFI_D_NET
, "\nCpb->FrameAddr == %LX\n", Cpb
->FrameAddr
));
180 (*Snp
->IssueUndi32Command
) ((UINT64
) (UINTN
) &Snp
->Cdb
);
182 DEBUG ((EFI_D_NET
, "\nexit Snp->undi.transmit() "));
185 // we will unmap the buffers in get_status call, not here
187 switch (Snp
->Cdb
.StatCode
) {
188 case PXE_STATCODE_SUCCESS
:
191 case PXE_STATCODE_BUFFER_FULL
:
192 case PXE_STATCODE_QUEUE_FULL
:
193 case PXE_STATCODE_BUSY
:
194 Status
= EFI_NOT_READY
;
197 "\nSnp->undi.transmit() %xh:%xh\n",
206 "\nSnp->undi.transmit() %xh:%xh\n",
210 Status
= EFI_DEVICE_ERROR
;
217 Places a packet in the transmit queue of a network interface.
219 This function places the packet specified by Header and Buffer on the transmit
220 queue. If HeaderSize is nonzero and HeaderSize is not equal to
221 This->Mode->MediaHeaderSize, then EFI_INVALID_PARAMETER will be returned. If
222 BufferSize is less than This->Mode->MediaHeaderSize, then EFI_BUFFER_TOO_SMALL
223 will be returned. If Buffer is NULL, then EFI_INVALID_PARAMETER will be
224 returned. If HeaderSize is nonzero and DestAddr or Protocol is NULL, then
225 EFI_INVALID_PARAMETER will be returned. If the transmit engine of the network
226 interface is busy, then EFI_NOT_READY will be returned. If this packet can be
227 accepted by the transmit engine of the network interface, the packet contents
228 specified by Buffer will be placed on the transmit queue of the network
229 interface, and EFI_SUCCESS will be returned. GetStatus() can be used to
230 determine when the packet has actually been transmitted. The contents of the
231 Buffer must not be modified until the packet has actually been transmitted.
232 The Transmit() function performs nonblocking I/O. A caller who wants to perform
233 blocking I/O, should call Transmit(), and then GetStatus() until the
234 transmitted buffer shows up in the recycled transmit buffer.
235 If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
237 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
238 @param HeaderSize The size, in bytes, of the media header to be filled in by the
239 Transmit() function. If HeaderSize is nonzero, then it must
240 be equal to This->Mode->MediaHeaderSize and the DestAddr and
241 Protocol parameters must not be NULL.
242 @param BufferSize The size, in bytes, of the entire packet (media header and
243 data) to be transmitted through the network interface.
244 @param Buffer A pointer to the packet (media header followed by data) to be
245 transmitted. This parameter cannot be NULL. If HeaderSize is
246 zero, then the media header in Buffer must already be filled
247 in by the caller. If HeaderSize is nonzero, then the media
248 header will be filled in by the Transmit() function.
249 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this
250 parameter is ignored. If HeaderSize is nonzero and SrcAddr
251 is NULL, then This->Mode->CurrentAddress is used for the
252 source HW MAC address.
253 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then
254 this parameter is ignored.
255 @param Protocol The type of header to build. If HeaderSize is zero, then this
256 parameter is ignored. See RFC 1700, section "Ether Types,"
259 @retval EFI_SUCCESS The packet was placed on the transmit queue.
260 @retval EFI_NOT_STARTED The network interface has not been started.
261 @retval EFI_NOT_READY The network interface is too busy to accept this
263 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
264 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported
266 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
267 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
273 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
277 IN EFI_MAC_ADDRESS
*SrcAddr
, OPTIONAL
278 IN EFI_MAC_ADDRESS
*DestAddr
, OPTIONAL
279 IN UINT16
*Protocol OPTIONAL
287 return EFI_INVALID_PARAMETER
;
290 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
292 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
295 return EFI_DEVICE_ERROR
;
298 switch (Snp
->Mode
.State
) {
299 case EfiSimpleNetworkInitialized
:
302 case EfiSimpleNetworkStopped
:
303 Status
= EFI_NOT_STARTED
;
307 Status
= EFI_DEVICE_ERROR
;
311 if (Buffer
== NULL
) {
312 Status
= EFI_INVALID_PARAMETER
;
316 if (BufferSize
< Snp
->Mode
.MediaHeaderSize
) {
317 Status
= EFI_BUFFER_TOO_SMALL
;
322 // if the HeaderSize is non-zero, we need to fill up the header and for that
323 // we need the destination address and the protocol
325 if (HeaderSize
!= 0) {
326 if (HeaderSize
!= Snp
->Mode
.MediaHeaderSize
|| DestAddr
== 0 || Protocol
== 0) {
327 Status
= EFI_INVALID_PARAMETER
;
331 Status
= PxeFillHeader (
335 (UINT8
*) Buffer
+ HeaderSize
,
336 BufferSize
- HeaderSize
,
342 if (EFI_ERROR (Status
)) {
347 Status
= PxeTransmit (Snp
, Buffer
, BufferSize
);
350 gBS
->RestoreTPL (OldTpl
);