2 Copyright (c) 2004 - 2007, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 2000-Feb-03 M(f)J Genesis.
26 This routine calls undi to create the meadia header for the given data buffer.
28 @param snp pointer to SNP driver structure
29 @param MacHeaderPtr address where the media header will be filled in.
30 @param MacHeaderSize size of the memory at MacHeaderPtr
31 @param BufferPtr data buffer pointer
32 @param BufferLength Size of data in the BufferPtr
33 @param DestinationAddrPtr address of the destination mac address buffer
34 @param SourceAddrPtr address of the source mac address buffer
35 @param ProtocolPtr address of the protocol type
37 @retval EFI_SUCCESS if successfully completed the undi call
38 @retval Other error return from undi call.
49 EFI_MAC_ADDRESS
*DestinationAddrPtr
,
50 EFI_MAC_ADDRESS
*SourceAddrPtr
,
54 PXE_CPB_FILL_HEADER_FRAGMENTED
*cpb
;
56 struct s_v2p
*pkt_v2p
;
62 (VOID
*) cpb
->SrcAddr
,
63 (VOID
*) SourceAddrPtr
,
64 snp
->mode
.HwAddressSize
68 (VOID
*) cpb
->SrcAddr
,
69 (VOID
*) &(snp
->mode
.CurrentAddress
),
70 snp
->mode
.HwAddressSize
75 (VOID
*) cpb
->DestAddr
,
76 (VOID
*) DestinationAddrPtr
,
77 snp
->mode
.HwAddressSize
81 // we need to do the byte swapping
83 cpb
->Protocol
= (UINT16
) PXE_SWAP_UINT16 (*ProtocolPtr
);
85 cpb
->PacketLen
= (UINT32
) (BufferLength
);
86 cpb
->MediaHeaderLen
= (UINT16
) MacHeaderSize
;
91 cpb
->FragDesc
[0].FragAddr
= (UINT64
)(UINTN
) MacHeaderPtr
;
92 cpb
->FragDesc
[0].FragLen
= (UINT32
) MacHeaderSize
;
93 cpb
->FragDesc
[1].FragAddr
= (UINT64
)(UINTN
) BufferPtr
;
94 cpb
->FragDesc
[1].FragLen
= (UINT32
) BufferLength
;
96 cpb
->FragDesc
[0].reserved
= cpb
->FragDesc
[1].reserved
= 0;
99 TempData
= (UINT64
) (UINTN
) MacHeaderPtr
;
100 if (TempData
>= FOUR_GIGABYTES
) {
101 cpb
->FragDesc
[0].FragAddr
= (UINT64
) (UINTN
) snp
->fill_hdr_buf
;
102 cpb
->FragDesc
[0].FragLen
= (UINT32
) snp
->init_info
.MediaHeaderLen
;
105 TempData
= (UINT64
) (UINTN
) (BufferPtr
);
106 if (TempData
>= FOUR_GIGABYTES
) {
108 // Let the device just read this buffer
112 EfiPciIoOperationBusMasterRead
,
116 if (Status
!= EFI_SUCCESS
) {
120 // give the virtual address to UNDI and it will call back on Virt2Phys
121 // to get the mapped address, if it needs it
123 cpb
->FragDesc
[1].FragLen
= (UINT32
) pkt_v2p
->bsize
;
127 snp
->cdb
.OpCode
= PXE_OPCODE_FILL_HEADER
;
128 snp
->cdb
.OpFlags
= PXE_OPFLAGS_FILL_HEADER_FRAGMENTED
;
130 snp
->cdb
.DBsize
= PXE_DBSIZE_NOT_USED
;
131 snp
->cdb
.DBaddr
= PXE_DBADDR_NOT_USED
;
133 snp
->cdb
.CPBsize
= sizeof (PXE_CPB_FILL_HEADER_FRAGMENTED
);
134 snp
->cdb
.CPBaddr
= (UINT64
)(UINTN
) cpb
;
136 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
137 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
138 snp
->cdb
.IFnum
= snp
->if_num
;
139 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
142 // Issue UNDI command and check result.
144 DEBUG ((EFI_D_NET
, "\nsnp->undi.fill_header() "));
146 (*snp
->issue_undi32_command
) ((UINT64
) (UINTN
) &snp
->cdb
);
148 if (snp
->IsOldUndi
) {
149 TempData
= (UINT64
) (UINTN
) (BufferPtr
);
150 if (TempData
>= FOUR_GIGABYTES
) {
154 // if we used the global buffer for header, copy the contents
156 TempData
= (UINT64
) (UINTN
) MacHeaderPtr
;
157 if (TempData
>= FOUR_GIGABYTES
) {
161 snp
->init_info
.MediaHeaderLen
166 switch (snp
->cdb
.StatCode
) {
167 case PXE_STATCODE_SUCCESS
:
170 case PXE_STATCODE_INVALID_PARAMETER
:
173 "\nsnp->undi.fill_header() %xh:%xh\n",
178 return EFI_INVALID_PARAMETER
;
183 "\nsnp->undi.fill_header() %xh:%xh\n",
188 return EFI_DEVICE_ERROR
;
194 This routine calls undi to transmit the given data buffer
196 @param snp pointer to SNP driver structure
197 @param BufferPtr data buffer pointer
198 @param BufferLength Size of data in the BufferPtr
200 @retval EFI_SUCCESS if successfully completed the undi call
201 @retval Other error return from undi call.
212 PXE_CPB_TRANSMIT
*cpb
;
218 cpb
->FrameAddr
= (UINT64
) (UINTN
) BufferPtr
;
219 cpb
->DataLen
= (UINT32
) BufferLength
;
221 TempData
= (UINT64
) (UINTN
) BufferPtr
;
222 if (snp
->IsOldUndi
&& (TempData
>= FOUR_GIGABYTES
)) {
224 // we need to create a mapping now and give it to the undi when it calls
225 // the Virt2Phys on this address.
226 // this is a transmit, just map it for the device to READ
230 EfiPciIoOperationBusMasterRead
,
234 if (Status
!= EFI_SUCCESS
) {
238 cpb
->DataLen
= (UINT32
) v2p
->bsize
;
241 cpb
->MediaheaderLen
= 0;
244 snp
->cdb
.OpFlags
= PXE_OPFLAGS_TRANSMIT_WHOLE
;
246 snp
->cdb
.CPBsize
= sizeof (PXE_CPB_TRANSMIT
);
247 snp
->cdb
.CPBaddr
= (UINT64
)(UINTN
) cpb
;
249 snp
->cdb
.OpCode
= PXE_OPCODE_TRANSMIT
;
250 snp
->cdb
.DBsize
= PXE_DBSIZE_NOT_USED
;
251 snp
->cdb
.DBaddr
= PXE_DBADDR_NOT_USED
;
253 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
254 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
255 snp
->cdb
.IFnum
= snp
->if_num
;
256 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
259 // Issue UNDI command and check result.
261 DEBUG ((EFI_D_NET
, "\nsnp->undi.transmit() "));
262 DEBUG ((EFI_D_NET
, "\nsnp->cdb.OpCode == %x", snp
->cdb
.OpCode
));
263 DEBUG ((EFI_D_NET
, "\nsnp->cdb.CPBaddr == %X", snp
->cdb
.CPBaddr
));
264 DEBUG ((EFI_D_NET
, "\nsnp->cdb.DBaddr == %X", snp
->cdb
.DBaddr
));
265 DEBUG ((EFI_D_NET
, "\ncpb->FrameAddr == %X\n", cpb
->FrameAddr
));
267 (*snp
->issue_undi32_command
) ((UINT64
) (UINTN
) &snp
->cdb
);
269 DEBUG ((EFI_D_NET
, "\nexit snp->undi.transmit() "));
270 DEBUG ((EFI_D_NET
, "\nsnp->cdb.StatCode == %r", snp
->cdb
.StatCode
));
273 // we will unmap the buffers in get_status call, not here
275 switch (snp
->cdb
.StatCode
) {
276 case PXE_STATCODE_SUCCESS
:
279 case PXE_STATCODE_QUEUE_FULL
:
280 case PXE_STATCODE_BUSY
:
281 Status
= EFI_NOT_READY
;
285 Status
= EFI_DEVICE_ERROR
;
290 "\nsnp->undi.transmit() %xh:%xh\n",
300 This is the snp interface routine for transmitting a packet. this routine
301 basically retrieves the snp structure, checks the snp state and calls
302 pxe_fill_header and pxe_transmit calls to complete the transmission.
304 @param this pointer to SNP driver context
305 @param MacHeaderSize size of the memory at MacHeaderPtr
306 @param BufferLength Size of data in the BufferPtr
307 @param BufferPtr data buffer pointer
308 @param SourceAddrPtr address of the source mac address buffer
309 @param DestinationAddrPtr address of the destination mac address buffer
310 @param ProtocolPtr address of the protocol type
312 @retval EFI_SUCCESS if successfully completed the undi call
313 @retval Other error return from undi call.
318 snp_undi32_transmit (
319 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
320 IN UINTN MacHeaderSize
,
321 IN UINTN BufferLength
,
323 IN EFI_MAC_ADDRESS
* SourceAddrPtr OPTIONAL
,
324 IN EFI_MAC_ADDRESS
* DestinationAddrPtr OPTIONAL
,
325 IN UINT16
*ProtocolPtr OPTIONAL
333 return EFI_INVALID_PARAMETER
;
336 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
338 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
341 return EFI_DEVICE_ERROR
;
344 switch (snp
->mode
.State
) {
345 case EfiSimpleNetworkInitialized
:
348 case EfiSimpleNetworkStopped
:
349 Status
= EFI_NOT_STARTED
;
353 Status
= EFI_DEVICE_ERROR
;
357 if (BufferPtr
== NULL
) {
358 Status
= EFI_INVALID_PARAMETER
;
362 if (BufferLength
< snp
->mode
.MediaHeaderSize
) {
363 Status
= EFI_BUFFER_TOO_SMALL
;
368 // if the MacHeaderSize is non-zero, we need to fill up the header and for that
369 // we need the destination address and the protocol
371 if (MacHeaderSize
!= 0) {
372 if (MacHeaderSize
!= snp
->mode
.MediaHeaderSize
|| DestinationAddrPtr
== 0 || ProtocolPtr
== 0) {
373 Status
= EFI_INVALID_PARAMETER
;
377 Status
= pxe_fillheader (
381 (UINT8
*) BufferPtr
+ MacHeaderSize
,
382 BufferLength
- MacHeaderSize
,
388 if (EFI_ERROR (Status
)) {
393 Status
= pxe_transmit (snp
, BufferPtr
, BufferLength
);
396 gBS
->RestoreTPL (OldTpl
);