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
12 Call UNDI to create the meadia header for the given data buffer.
14 @param Snp Pointer to SNP driver structure.
15 @param MacHeaderPtr Address where the media header will be filled in.
16 @param HeaderSize Size of the memory at MacHeaderPtr.
17 @param Buffer Data buffer pointer.
18 @param BufferSize Size of data in the Buffer
19 @param DestAddr Address of the destination mac address buffer.
20 @param SrcAddr Address of the source mac address buffer.
21 @param ProtocolPtr Address of the protocol type.
23 @retval EFI_SUCCESS Successfully completed the undi call.
24 @retval Other Error return from undi call.
34 EFI_MAC_ADDRESS
*DestAddr
,
35 EFI_MAC_ADDRESS
*SrcAddr
,
39 PXE_CPB_FILL_HEADER_FRAGMENTED
*Cpb
;
42 if (SrcAddr
!= NULL
) {
46 Snp
->Mode
.HwAddressSize
51 (VOID
*)&(Snp
->Mode
.CurrentAddress
),
52 Snp
->Mode
.HwAddressSize
57 (VOID
*)Cpb
->DestAddr
,
59 Snp
->Mode
.HwAddressSize
63 // we need to do the byte swapping
65 Cpb
->Protocol
= (UINT16
)PXE_SWAP_UINT16 (*ProtocolPtr
);
67 Cpb
->PacketLen
= (UINT32
)(BufferSize
);
68 Cpb
->MediaHeaderLen
= (UINT16
)HeaderSize
;
73 Cpb
->FragDesc
[0].FragAddr
= (UINT64
)(UINTN
)MacHeaderPtr
;
74 Cpb
->FragDesc
[0].FragLen
= (UINT32
)HeaderSize
;
75 Cpb
->FragDesc
[1].FragAddr
= (UINT64
)(UINTN
)Buffer
;
76 Cpb
->FragDesc
[1].FragLen
= (UINT32
)BufferSize
;
78 Cpb
->FragDesc
[0].reserved
= Cpb
->FragDesc
[1].reserved
= 0;
80 Snp
->Cdb
.OpCode
= PXE_OPCODE_FILL_HEADER
;
81 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_FILL_HEADER_FRAGMENTED
;
83 Snp
->Cdb
.DBsize
= PXE_DBSIZE_NOT_USED
;
84 Snp
->Cdb
.DBaddr
= PXE_DBADDR_NOT_USED
;
86 Snp
->Cdb
.CPBsize
= (UINT16
)sizeof (PXE_CPB_FILL_HEADER_FRAGMENTED
);
87 Snp
->Cdb
.CPBaddr
= (UINT64
)(UINTN
)Cpb
;
89 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
90 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
91 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
92 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
95 // Issue UNDI command and check result.
97 DEBUG ((DEBUG_NET
, "\nSnp->undi.fill_header() "));
99 (*Snp
->IssueUndi32Command
)((UINT64
)(UINTN
)&Snp
->Cdb
);
101 switch (Snp
->Cdb
.StatCode
) {
102 case PXE_STATCODE_SUCCESS
:
105 case PXE_STATCODE_INVALID_PARAMETER
:
108 "\nSnp->undi.fill_header() %xh:%xh\n",
113 return EFI_INVALID_PARAMETER
;
118 "\nSnp->undi.fill_header() %xh:%xh\n",
123 return EFI_DEVICE_ERROR
;
128 This routine calls undi to transmit the given data buffer
130 @param Snp pointer to SNP driver structure
131 @param Buffer data buffer pointer
132 @param BufferSize Size of data in the Buffer
134 @retval EFI_SUCCESS if successfully completed the undi call
135 @retval Other error return from undi call.
145 PXE_CPB_TRANSMIT
*Cpb
;
149 Cpb
->FrameAddr
= (UINT64
)(UINTN
)Buffer
;
150 Cpb
->DataLen
= (UINT32
)BufferSize
;
152 Cpb
->MediaheaderLen
= 0;
155 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_TRANSMIT_WHOLE
;
157 Snp
->Cdb
.CPBsize
= (UINT16
)sizeof (PXE_CPB_TRANSMIT
);
158 Snp
->Cdb
.CPBaddr
= (UINT64
)(UINTN
)Cpb
;
160 Snp
->Cdb
.OpCode
= PXE_OPCODE_TRANSMIT
;
161 Snp
->Cdb
.DBsize
= PXE_DBSIZE_NOT_USED
;
162 Snp
->Cdb
.DBaddr
= PXE_DBADDR_NOT_USED
;
164 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
165 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
166 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
167 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
170 // Issue UNDI command and check result.
172 DEBUG ((DEBUG_NET
, "\nSnp->undi.transmit() "));
173 DEBUG ((DEBUG_NET
, "\nSnp->Cdb.OpCode == %x", Snp
->Cdb
.OpCode
));
174 DEBUG ((DEBUG_NET
, "\nSnp->Cdb.CPBaddr == %LX", Snp
->Cdb
.CPBaddr
));
175 DEBUG ((DEBUG_NET
, "\nSnp->Cdb.DBaddr == %LX", Snp
->Cdb
.DBaddr
));
176 DEBUG ((DEBUG_NET
, "\nCpb->FrameAddr == %LX\n", Cpb
->FrameAddr
));
178 (*Snp
->IssueUndi32Command
)((UINT64
)(UINTN
)&Snp
->Cdb
);
180 DEBUG ((DEBUG_NET
, "\nexit Snp->undi.transmit() "));
183 // we will unmap the buffers in get_status call, not here
185 switch (Snp
->Cdb
.StatCode
) {
186 case PXE_STATCODE_SUCCESS
:
189 case PXE_STATCODE_BUFFER_FULL
:
190 case PXE_STATCODE_QUEUE_FULL
:
191 case PXE_STATCODE_BUSY
:
192 Status
= EFI_NOT_READY
;
195 "\nSnp->undi.transmit() %xh:%xh\n",
204 "\nSnp->undi.transmit() %xh:%xh\n",
208 Status
= EFI_DEVICE_ERROR
;
215 Places a packet in the transmit queue of a network interface.
217 This function places the packet specified by Header and Buffer on the transmit
218 queue. If HeaderSize is nonzero and HeaderSize is not equal to
219 This->Mode->MediaHeaderSize, then EFI_INVALID_PARAMETER will be returned. If
220 BufferSize is less than This->Mode->MediaHeaderSize, then EFI_BUFFER_TOO_SMALL
221 will be returned. If Buffer is NULL, then EFI_INVALID_PARAMETER will be
222 returned. If HeaderSize is nonzero and DestAddr or Protocol is NULL, then
223 EFI_INVALID_PARAMETER will be returned. If the transmit engine of the network
224 interface is busy, then EFI_NOT_READY will be returned. If this packet can be
225 accepted by the transmit engine of the network interface, the packet contents
226 specified by Buffer will be placed on the transmit queue of the network
227 interface, and EFI_SUCCESS will be returned. GetStatus() can be used to
228 determine when the packet has actually been transmitted. The contents of the
229 Buffer must not be modified until the packet has actually been transmitted.
230 The Transmit() function performs nonblocking I/O. A caller who wants to perform
231 blocking I/O, should call Transmit(), and then GetStatus() until the
232 transmitted buffer shows up in the recycled transmit buffer.
233 If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
235 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
236 @param HeaderSize The size, in bytes, of the media header to be filled in by the
237 Transmit() function. If HeaderSize is nonzero, then it must
238 be equal to This->Mode->MediaHeaderSize and the DestAddr and
239 Protocol parameters must not be NULL.
240 @param BufferSize The size, in bytes, of the entire packet (media header and
241 data) to be transmitted through the network interface.
242 @param Buffer A pointer to the packet (media header followed by data) to be
243 transmitted. This parameter cannot be NULL. If HeaderSize is
244 zero, then the media header in Buffer must already be filled
245 in by the caller. If HeaderSize is nonzero, then the media
246 header will be filled in by the Transmit() function.
247 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this
248 parameter is ignored. If HeaderSize is nonzero and SrcAddr
249 is NULL, then This->Mode->CurrentAddress is used for the
250 source HW MAC address.
251 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then
252 this parameter is ignored.
253 @param Protocol The type of header to build. If HeaderSize is zero, then this
254 parameter is ignored. See RFC 1700, section "Ether Types,"
257 @retval EFI_SUCCESS The packet was placed on the transmit queue.
258 @retval EFI_NOT_STARTED The network interface has not been started.
259 @retval EFI_NOT_READY The network interface is too busy to accept this
261 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
262 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported
264 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
265 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
271 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
275 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
276 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
277 IN UINT16
*Protocol OPTIONAL
285 return EFI_INVALID_PARAMETER
;
288 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
290 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
293 return EFI_DEVICE_ERROR
;
296 switch (Snp
->Mode
.State
) {
297 case EfiSimpleNetworkInitialized
:
300 case EfiSimpleNetworkStopped
:
301 Status
= EFI_NOT_STARTED
;
305 Status
= EFI_DEVICE_ERROR
;
309 if (Buffer
== NULL
) {
310 Status
= EFI_INVALID_PARAMETER
;
314 if (BufferSize
< Snp
->Mode
.MediaHeaderSize
) {
315 Status
= EFI_BUFFER_TOO_SMALL
;
320 // if the HeaderSize is non-zero, we need to fill up the header and for that
321 // we need the destination address and the protocol
323 if (HeaderSize
!= 0) {
324 if ((HeaderSize
!= Snp
->Mode
.MediaHeaderSize
) || (DestAddr
== 0) || (Protocol
== 0)) {
325 Status
= EFI_INVALID_PARAMETER
;
329 Status
= PxeFillHeader (
333 (UINT8
*)Buffer
+ HeaderSize
,
334 BufferSize
- HeaderSize
,
340 if (EFI_ERROR (Status
)) {
345 Status
= PxeTransmit (Snp
, Buffer
, BufferSize
);
348 gBS
->RestoreTPL (OldTpl
);