]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Universal/Network/Snp32_64/Dxe/receive.c
Fix capitalization
[mirror_edk2.git] / EdkModulePkg / Universal / Network / Snp32_64 / Dxe / receive.c
CommitLineData
878ddf1f 1/*++\r
2Copyright (c) 2006, Intel Corporation \r
3All rights reserved. This program and the accompanying materials \r
4are licensed and made available under the terms and conditions of the BSD License \r
5which accompanies this distribution. The full text of the license may be found at \r
6http://opensource.org/licenses/bsd-license.php \r
7 \r
8THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
9WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
10\r
11Module name:\r
12 receive.c\r
13\r
14Abstract:\r
15\r
16Revision history:\r
17 2000-Feb-03 M(f)J Genesis.\r
18--*/\r
19\r
20\r
4cbd855e 21#include "Snp.h"\r
878ddf1f 22\r
23EFI_STATUS\r
24pxe_receive (\r
25 SNP_DRIVER *snp,\r
26 VOID *BufferPtr,\r
27 UINTN *BuffSizePtr,\r
28 UINTN *HeaderSizePtr,\r
29 EFI_MAC_ADDRESS *SourceAddrPtr,\r
30 EFI_MAC_ADDRESS *DestinationAddrPtr,\r
31 UINT16 *ProtocolPtr\r
32 )\r
33/*++\r
34\r
35Routine Description:\r
36 this routine calls undi to receive a packet and fills in the data in the\r
37 input pointers!\r
38 \r
39Arguments:\r
40 snp - pointer to snp driver structure\r
41 BufferPtr - pointer to the memory for the received data\r
42 BuffSizePtr - is a pointer to the length of the buffer on entry and contains\r
43 the length of the received data on return\r
44 HeaderSizePtr - pointer to the header portion of the data received.\r
45 SourceAddrPtr - optional parameter, is a pointer to contain the source\r
46 ethernet address on return\r
47 DestinationAddrPtr - optional parameter, is a pointer to contain the destination\r
48 ethernet address on return\r
49 ProtocolPtr - optional parameter, is a pointer to contain the protocol type\r
50 from the ethernet header on return\r
51\r
52\r
53Returns:\r
54\r
55--*/\r
56{\r
57 PXE_CPB_RECEIVE *cpb;\r
58 PXE_DB_RECEIVE *db;\r
59 UINTN buf_size;\r
60 UINT64 TempData;\r
61\r
62 cpb = snp->cpb;\r
63 db = snp->db;\r
64 buf_size = *BuffSizePtr;\r
65 //\r
66 // IMPORTANT NOTE:\r
67 // In case of the older 3.0 UNDI, if the input buffer address is beyond 4GB,\r
68 // DO NOT call the map function on the given buffer, instead use\r
69 // a global buffer. The reason is that UNDI3.0 has some unnecessary check of\r
70 // making sure that all the addresses (whether or not they will be given\r
71 // to the NIC ) supplied to it are below 4GB. It may or may not use\r
72 // the mapped address after all (like in case of CPB and DB)!\r
73 // Instead of using the global buffer whose address is allocated within the\r
74 // 2GB limit if I start mapping the given buffer we lose the data, here is\r
75 // why!!!\r
76 // if our address is > 4GB, the map call creates another buffer below 2GB and\r
77 // copies data to/from the original buffer to the mapped buffer either at\r
78 // map time or unmap time depending on the map direction.\r
79 // UNDI will not complain since we already mapped the buffer to be\r
80 // within the 2GB limit but will not use (I know undi) the mapped address\r
81 // since it does not give the user buffers to the NIC's receive unit,\r
82 // It just copies the received packet into the user buffer using the virtual\r
83 // (CPU) address rather than the mapped (device or physical) address.\r
84 // When the UNDI call returns, if we then unmap the buffer, we will lose\r
85 // the contents because unmap copies the contents of the mapped buffer into\r
86 // the original buffer (since the direction is FROM_DEVICE) !!!\r
87 //\r
88 // this is not a problem in Undi 3.1 because this undi uses it's map callback\r
89 // routine to map a cpu address to device address and it does it only if\r
90 // it is giving the address to the device and unmaps it before using the cpu\r
91 // address!\r
92 //\r
93 TempData = (UINT64) (UINTN) BufferPtr;\r
94 if (snp->IsOldUndi && (TempData >= FOUR_GIGABYTES)) {\r
95 cpb->BufferAddr = (UINT64) (UINTN) snp->receive_buf;\r
96 cpb->BufferLen = (UINT32) (snp->init_info.MediaHeaderLen + snp->init_info.FrameDataLen);\r
97 } else {\r
98 cpb->BufferAddr = (UINT64) (UINTN) BufferPtr;\r
99 cpb->BufferLen = (UINT32) *BuffSizePtr;\r
100 }\r
101\r
102 cpb->reserved = 0;\r
103\r
104 snp->cdb.OpCode = PXE_OPCODE_RECEIVE;\r
105 snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED;\r
106\r
107 snp->cdb.CPBsize = sizeof (PXE_CPB_RECEIVE);\r
108 snp->cdb.CPBaddr = (UINT64) (UINTN) cpb;\r
109\r
110 snp->cdb.DBsize = sizeof (PXE_DB_RECEIVE);\r
111 snp->cdb.DBaddr = (UINT64) (UINTN) db;\r
112\r
113 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
114 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
115 snp->cdb.IFnum = snp->if_num;\r
116 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
117\r
118 //\r
119 // Issue UNDI command and check result.\r
120 //\r
121 DEBUG ((EFI_D_INFO, "\nsnp->undi.receive () "));\r
122\r
123 (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb);\r
124\r
125 switch (snp->cdb.StatCode) {\r
126 case PXE_STATCODE_SUCCESS:\r
127 break;\r
128\r
129 case PXE_STATCODE_NO_DATA:\r
130 DEBUG (\r
131 (EFI_D_INFO,\r
132 "\nsnp->undi.receive () %xh:%xh\n",\r
133 snp->cdb.StatFlags,\r
134 snp->cdb.StatCode)\r
135 );\r
136\r
137 return EFI_NOT_READY;\r
138\r
139 default:\r
140 DEBUG (\r
141 (EFI_D_ERROR,\r
142 "\nsnp->undi.receive() %xh:%xh\n",\r
143 snp->cdb.StatFlags,\r
144 snp->cdb.StatCode)\r
145 );\r
146\r
147 return EFI_DEVICE_ERROR;\r
148 }\r
149\r
150 *BuffSizePtr = db->FrameLen;\r
151\r
152 if (HeaderSizePtr != NULL) {\r
153 *HeaderSizePtr = db->MediaHeaderLen;\r
154 }\r
155\r
156 if (SourceAddrPtr != NULL) {\r
157 CopyMem (SourceAddrPtr, &db->SrcAddr, snp->mode.HwAddressSize);\r
158 }\r
159\r
160 if (DestinationAddrPtr != NULL) {\r
161 CopyMem (DestinationAddrPtr, &db->DestAddr, snp->mode.HwAddressSize);\r
162 }\r
163\r
164 if (ProtocolPtr != NULL) {\r
165 *ProtocolPtr = (UINT16) PXE_SWAP_UINT16 (db->Protocol); /* we need to do the byte swapping */\r
166 }\r
167\r
168 TempData = (UINT64) (UINTN) BufferPtr;\r
169 if (snp->IsOldUndi && (TempData >= FOUR_GIGABYTES)) {\r
170 CopyMem (BufferPtr, snp->receive_buf, snp->init_info.MediaHeaderLen + snp->init_info.FrameDataLen);\r
171 }\r
172\r
173 return (*BuffSizePtr <= buf_size) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL;\r
174}\r
175\r
176EFI_STATUS\r
177EFIAPI\r
178snp_undi32_receive (\r
179 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,\r
180 OUT UINTN *HeaderSizePtr OPTIONAL,\r
181 IN OUT UINTN *BuffSizePtr,\r
182 OUT VOID *BufferPtr,\r
183 OUT EFI_MAC_ADDRESS * SourceAddrPtr OPTIONAL,\r
184 OUT EFI_MAC_ADDRESS * DestinationAddrPtr OPTIONAL,\r
185 OUT UINT16 *ProtocolPtr OPTIONAL\r
186 )\r
187/*++\r
188\r
189Routine Description:\r
190 This is the SNP interface routine for receiving network data.\r
191 This routine basically retrieves snp structure, checks the SNP state and\r
192 calls the pxe_receive routine to actually do the receive!\r
193\r
194Arguments:\r
195 this - context pointer\r
196 HeaderSizePtr - optional parameter and is a pointer to the header portion of\r
197 the data received.\r
198 BuffSizePtr - is a pointer to the length of the buffer on entry and contains\r
199 the length of the received data on return\r
200 BufferPtr - pointer to the memory for the received data\r
201 SourceAddrPtr - optional parameter, is a pointer to contain the source\r
202 ethernet address on return\r
203 DestinationAddrPtr - optional parameter, is a pointer to contain the destination\r
204 ethernet address on return\r
205 ProtocolPtr - optional parameter, is a pointer to contain the protocol type\r
206 from the ethernet header on return\r
207\r
208Returns:\r
209\r
210--*/\r
211{\r
212 SNP_DRIVER *snp;\r
213\r
214 if (this == NULL) {\r
215 return EFI_INVALID_PARAMETER;\r
216 }\r
217\r
218 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\r
219\r
220 if (snp == NULL) {\r
221 return EFI_DEVICE_ERROR;\r
222 }\r
223\r
224 switch (snp->mode.State) {\r
225 case EfiSimpleNetworkInitialized:\r
226 break;\r
227\r
228 case EfiSimpleNetworkStopped:\r
229 return EFI_NOT_STARTED;\r
230\r
231 case EfiSimpleNetworkStarted:\r
232 return EFI_DEVICE_ERROR;\r
233\r
234 default:\r
235 return EFI_DEVICE_ERROR;\r
236 }\r
237\r
238 if ((BuffSizePtr == NULL) || (BufferPtr == NULL)) {\r
239 return EFI_INVALID_PARAMETER;\r
240 }\r
241\r
242 if (!snp->mode.ReceiveFilterSetting) {\r
243 return EFI_DEVICE_ERROR;\r
244 }\r
245\r
246 return pxe_receive (\r
247 snp,\r
248 BufferPtr,\r
249 BuffSizePtr,\r
250 HeaderSizePtr,\r
251 SourceAddrPtr,\r
252 DestinationAddrPtr,\r
253 ProtocolPtr\r
254 );\r
255}\r