]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/SnpDxe/Transmit.c
MdeModulePkg: Correct one return status code in SNP Transmit function.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Transmit.c
CommitLineData
a3c5f87a 1/** @file\r
4cda7726 2 Implementation of transmitting a packet.\r
3 \r
c1a19806 4Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials are licensed \r
4cda7726 6and made available under the terms and conditions of the BSD License which \r
7accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php \r
a3c5f87a 9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
a3c5f87a 13**/\r
14\r
15#include "Snp.h"\r
16\r
17\r
18/**\r
f3816027 19 Call UNDI to create the meadia header for the given data buffer.\r
a3c5f87a 20\r
f3816027 21 @param Snp Pointer to SNP driver structure.\r
22 @param MacHeaderPtr Address where the media header will be filled in.\r
23 @param HeaderSize Size of the memory at MacHeaderPtr.\r
24 @param Buffer Data buffer pointer.\r
25 @param BufferSize Size of data in the Buffer\r
26 @param DestAddr Address of the destination mac address buffer.\r
27 @param SrcAddr Address of the source mac address buffer.\r
28 @param ProtocolPtr Address of the protocol type.\r
a3c5f87a 29\r
f3816027 30 @retval EFI_SUCCESS Successfully completed the undi call.\r
31 @retval Other Error return from undi call.\r
a3c5f87a 32\r
33**/\r
a3c5f87a 34EFI_STATUS\r
4cda7726 35PxeFillHeader (\r
36 SNP_DRIVER *Snp,\r
a3c5f87a 37 VOID *MacHeaderPtr,\r
4cda7726 38 UINTN HeaderSize,\r
39 VOID *Buffer,\r
40 UINTN BufferSize,\r
41 EFI_MAC_ADDRESS *DestAddr,\r
42 EFI_MAC_ADDRESS *SrcAddr,\r
a3c5f87a 43 UINT16 *ProtocolPtr\r
44 )\r
45{\r
4cda7726 46 PXE_CPB_FILL_HEADER_FRAGMENTED *Cpb;\r
a3c5f87a 47\r
4cda7726 48 Cpb = Snp->Cpb;\r
49 if (SrcAddr != NULL) {\r
a3c5f87a 50 CopyMem (\r
4cda7726 51 (VOID *) Cpb->SrcAddr,\r
52 (VOID *) SrcAddr,\r
53 Snp->Mode.HwAddressSize\r
a3c5f87a 54 );\r
55 } else {\r
56 CopyMem (\r
4cda7726 57 (VOID *) Cpb->SrcAddr,\r
58 (VOID *) &(Snp->Mode.CurrentAddress),\r
59 Snp->Mode.HwAddressSize\r
a3c5f87a 60 );\r
61 }\r
62\r
63 CopyMem (\r
4cda7726 64 (VOID *) Cpb->DestAddr,\r
65 (VOID *) DestAddr,\r
66 Snp->Mode.HwAddressSize\r
a3c5f87a 67 );\r
68\r
69 //\r
70 // we need to do the byte swapping\r
71 //\r
4cda7726 72 Cpb->Protocol = (UINT16) PXE_SWAP_UINT16 (*ProtocolPtr);\r
a3c5f87a 73\r
4cda7726 74 Cpb->PacketLen = (UINT32) (BufferSize);\r
75 Cpb->MediaHeaderLen = (UINT16) HeaderSize;\r
a3c5f87a 76\r
4cda7726 77 Cpb->FragCnt = 2;\r
78 Cpb->reserved = 0;\r
a3c5f87a 79\r
4cda7726 80 Cpb->FragDesc[0].FragAddr = (UINT64)(UINTN) MacHeaderPtr;\r
81 Cpb->FragDesc[0].FragLen = (UINT32) HeaderSize;\r
82 Cpb->FragDesc[1].FragAddr = (UINT64)(UINTN) Buffer;\r
83 Cpb->FragDesc[1].FragLen = (UINT32) BufferSize;\r
a3c5f87a 84\r
4cda7726 85 Cpb->FragDesc[0].reserved = Cpb->FragDesc[1].reserved = 0;\r
a3c5f87a 86\r
4cda7726 87 Snp->Cdb.OpCode = PXE_OPCODE_FILL_HEADER;\r
88 Snp->Cdb.OpFlags = PXE_OPFLAGS_FILL_HEADER_FRAGMENTED;\r
a3c5f87a 89\r
4cda7726 90 Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED;\r
91 Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED;\r
a3c5f87a 92\r
cd7bfc2c 93 Snp->Cdb.CPBsize = (UINT16) sizeof (PXE_CPB_FILL_HEADER_FRAGMENTED);\r
4cda7726 94 Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb;\r
a3c5f87a 95\r
4cda7726 96 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
97 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
98 Snp->Cdb.IFnum = Snp->IfNum;\r
99 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
a3c5f87a 100\r
101 //\r
102 // Issue UNDI command and check result.\r
103 //\r
9cff2f8d 104 DEBUG ((EFI_D_NET, "\nSnp->undi.fill_header() "));\r
a3c5f87a 105\r
4cda7726 106 (*Snp->IssueUndi32Command) ((UINT64) (UINTN) &Snp->Cdb);\r
a3c5f87a 107\r
4cda7726 108 switch (Snp->Cdb.StatCode) {\r
a3c5f87a 109 case PXE_STATCODE_SUCCESS:\r
110 return EFI_SUCCESS;\r
111\r
112 case PXE_STATCODE_INVALID_PARAMETER:\r
113 DEBUG (\r
114 (EFI_D_ERROR,\r
4cda7726 115 "\nSnp->undi.fill_header() %xh:%xh\n",\r
116 Snp->Cdb.StatFlags,\r
117 Snp->Cdb.StatCode)\r
a3c5f87a 118 );\r
119\r
120 return EFI_INVALID_PARAMETER;\r
121\r
122 default:\r
123 DEBUG (\r
124 (EFI_D_ERROR,\r
4cda7726 125 "\nSnp->undi.fill_header() %xh:%xh\n",\r
126 Snp->Cdb.StatFlags,\r
127 Snp->Cdb.StatCode)\r
a3c5f87a 128 );\r
129\r
130 return EFI_DEVICE_ERROR;\r
131 }\r
132}\r
133\r
134\r
135/**\r
136 This routine calls undi to transmit the given data buffer\r
137\r
4cda7726 138 @param Snp pointer to SNP driver structure\r
139 @param Buffer data buffer pointer\r
140 @param BufferSize Size of data in the Buffer\r
a3c5f87a 141\r
142 @retval EFI_SUCCESS if successfully completed the undi call\r
143 @retval Other error return from undi call.\r
144\r
145**/\r
a3c5f87a 146EFI_STATUS\r
4cda7726 147PxeTransmit (\r
148 SNP_DRIVER *Snp,\r
149 VOID *Buffer,\r
150 UINTN BufferSize\r
a3c5f87a 151 )\r
152{\r
4cda7726 153 PXE_CPB_TRANSMIT *Cpb;\r
a3c5f87a 154 EFI_STATUS Status;\r
155\r
4cda7726 156 Cpb = Snp->Cpb;\r
157 Cpb->FrameAddr = (UINT64) (UINTN) Buffer;\r
158 Cpb->DataLen = (UINT32) BufferSize;\r
a3c5f87a 159\r
4cda7726 160 Cpb->MediaheaderLen = 0;\r
161 Cpb->reserved = 0;\r
a3c5f87a 162\r
4cda7726 163 Snp->Cdb.OpFlags = PXE_OPFLAGS_TRANSMIT_WHOLE;\r
a3c5f87a 164\r
c9325700 165 Snp->Cdb.CPBsize = (UINT16) sizeof (PXE_CPB_TRANSMIT);\r
4cda7726 166 Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb;\r
a3c5f87a 167\r
4cda7726 168 Snp->Cdb.OpCode = PXE_OPCODE_TRANSMIT;\r
169 Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED;\r
170 Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED;\r
a3c5f87a 171\r
4cda7726 172 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
173 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
174 Snp->Cdb.IFnum = Snp->IfNum;\r
175 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
a3c5f87a 176\r
177 //\r
178 // Issue UNDI command and check result.\r
179 //\r
9cff2f8d 180 DEBUG ((EFI_D_NET, "\nSnp->undi.transmit() "));\r
181 DEBUG ((EFI_D_NET, "\nSnp->Cdb.OpCode == %x", Snp->Cdb.OpCode));\r
182 DEBUG ((EFI_D_NET, "\nSnp->Cdb.CPBaddr == %LX", Snp->Cdb.CPBaddr));\r
183 DEBUG ((EFI_D_NET, "\nSnp->Cdb.DBaddr == %LX", Snp->Cdb.DBaddr));\r
184 DEBUG ((EFI_D_NET, "\nCpb->FrameAddr == %LX\n", Cpb->FrameAddr));\r
a3c5f87a 185\r
4cda7726 186 (*Snp->IssueUndi32Command) ((UINT64) (UINTN) &Snp->Cdb);\r
a3c5f87a 187\r
9cff2f8d 188 DEBUG ((EFI_D_NET, "\nexit Snp->undi.transmit() "));\r
189 DEBUG ((EFI_D_NET, "\nSnp->Cdb.StatCode == %r", Snp->Cdb.StatCode));\r
a3c5f87a 190\r
191 //\r
192 // we will unmap the buffers in get_status call, not here\r
193 //\r
4cda7726 194 switch (Snp->Cdb.StatCode) {\r
a3c5f87a 195 case PXE_STATCODE_SUCCESS:\r
196 return EFI_SUCCESS;\r
197\r
c1a19806 198 case PXE_STATCODE_BUFFER_FULL:\r
a3c5f87a 199 case PXE_STATCODE_QUEUE_FULL:\r
200 case PXE_STATCODE_BUSY:\r
201 Status = EFI_NOT_READY;\r
202 break;\r
203\r
204 default:\r
205 Status = EFI_DEVICE_ERROR;\r
206 }\r
207\r
208 DEBUG (\r
209 (EFI_D_ERROR,\r
4cda7726 210 "\nSnp->undi.transmit() %xh:%xh\n",\r
211 Snp->Cdb.StatFlags,\r
212 Snp->Cdb.StatCode)\r
a3c5f87a 213 );\r
214\r
215 return Status;\r
216}\r
217\r
a3c5f87a 218/**\r
4cda7726 219 Places a packet in the transmit queue of a network interface.\r
220 \r
221 This function places the packet specified by Header and Buffer on the transmit\r
222 queue. If HeaderSize is nonzero and HeaderSize is not equal to \r
223 This->Mode->MediaHeaderSize, then EFI_INVALID_PARAMETER will be returned. If \r
224 BufferSize is less than This->Mode->MediaHeaderSize, then EFI_BUFFER_TOO_SMALL\r
225 will be returned. If Buffer is NULL, then EFI_INVALID_PARAMETER will be \r
226 returned. If HeaderSize is nonzero and DestAddr or Protocol is NULL, then\r
227 EFI_INVALID_PARAMETER will be returned. If the transmit engine of the network\r
228 interface is busy, then EFI_NOT_READY will be returned. If this packet can be \r
229 accepted by the transmit engine of the network interface, the packet contents \r
230 specified by Buffer will be placed on the transmit queue of the network \r
231 interface, and EFI_SUCCESS will be returned. GetStatus() can be used to \r
232 determine when the packet has actually been transmitted. The contents of the \r
233 Buffer must not be modified until the packet has actually been transmitted. \r
234 The Transmit() function performs nonblocking I/O. A caller who wants to perform\r
235 blocking I/O, should call Transmit(), and then GetStatus() until the \r
236 transmitted buffer shows up in the recycled transmit buffer.\r
237 If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.\r
238\r
239 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
240 @param HeaderSize The size, in bytes, of the media header to be filled in by the \r
241 Transmit() function. If HeaderSize is nonzero, then it must\r
242 be equal to This->Mode->MediaHeaderSize and the DestAddr and\r
243 Protocol parameters must not be NULL.\r
244 @param BufferSize The size, in bytes, of the entire packet (media header and\r
245 data) to be transmitted through the network interface.\r
246 @param Buffer A pointer to the packet (media header followed by data) to be \r
247 transmitted. This parameter cannot be NULL. If HeaderSize is \r
248 zero, then the media header in Buffer must already be filled\r
249 in by the caller. If HeaderSize is nonzero, then the media \r
250 header will be filled in by the Transmit() function.\r
251 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this \r
252 parameter is ignored. If HeaderSize is nonzero and SrcAddr \r
253 is NULL, then This->Mode->CurrentAddress is used for the \r
254 source HW MAC address.\r
255 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then \r
256 this parameter is ignored.\r
257 @param Protocol The type of header to build. If HeaderSize is zero, then this \r
258 parameter is ignored. See RFC 1700, section "Ether Types," \r
259 for examples.\r
260\r
261 @retval EFI_SUCCESS The packet was placed on the transmit queue.\r
262 @retval EFI_NOT_STARTED The network interface has not been started.\r
263 @retval EFI_NOT_READY The network interface is too busy to accept this\r
264 transmit request.\r
265 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r
266 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported\r
267 value.\r
268 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
269 @retval EFI_UNSUPPORTED This function is not supported by the network interface.\r
a3c5f87a 270\r
271**/\r
272EFI_STATUS\r
273EFIAPI\r
4cda7726 274SnpUndi32Transmit (\r
275 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
276 IN UINTN HeaderSize,\r
277 IN UINTN BufferSize,\r
278 IN VOID *Buffer,\r
279 IN EFI_MAC_ADDRESS *SrcAddr, OPTIONAL\r
280 IN EFI_MAC_ADDRESS *DestAddr, OPTIONAL\r
281 IN UINT16 *Protocol OPTIONAL\r
a3c5f87a 282 )\r
283{\r
4cda7726 284 SNP_DRIVER *Snp;\r
a3c5f87a 285 EFI_STATUS Status;\r
286 EFI_TPL OldTpl;\r
287\r
4cda7726 288 if (This == NULL) {\r
a3c5f87a 289 return EFI_INVALID_PARAMETER;\r
290 }\r
291\r
4cda7726 292 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r
a3c5f87a 293\r
294 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
295\r
4cda7726 296 if (Snp == NULL) {\r
a3c5f87a 297 return EFI_DEVICE_ERROR;\r
298 }\r
299\r
4cda7726 300 switch (Snp->Mode.State) {\r
a3c5f87a 301 case EfiSimpleNetworkInitialized:\r
302 break;\r
303\r
304 case EfiSimpleNetworkStopped:\r
305 Status = EFI_NOT_STARTED;\r
306 goto ON_EXIT;\r
307\r
308 default:\r
309 Status = EFI_DEVICE_ERROR;\r
310 goto ON_EXIT;\r
311 }\r
312\r
4cda7726 313 if (Buffer == NULL) {\r
a3c5f87a 314 Status = EFI_INVALID_PARAMETER;\r
315 goto ON_EXIT;\r
316 }\r
317\r
4cda7726 318 if (BufferSize < Snp->Mode.MediaHeaderSize) {\r
a3c5f87a 319 Status = EFI_BUFFER_TOO_SMALL;\r
320 goto ON_EXIT;\r
321 }\r
322\r
323 //\r
4cda7726 324 // if the HeaderSize is non-zero, we need to fill up the header and for that\r
a3c5f87a 325 // we need the destination address and the protocol\r
326 //\r
4cda7726 327 if (HeaderSize != 0) {\r
328 if (HeaderSize != Snp->Mode.MediaHeaderSize || DestAddr == 0 || Protocol == 0) {\r
a3c5f87a 329 Status = EFI_INVALID_PARAMETER;\r
330 goto ON_EXIT;\r
331 }\r
332\r
4cda7726 333 Status = PxeFillHeader (\r
334 Snp,\r
335 Buffer,\r
336 HeaderSize,\r
337 (UINT8 *) Buffer + HeaderSize,\r
338 BufferSize - HeaderSize,\r
339 DestAddr,\r
340 SrcAddr,\r
341 Protocol\r
a3c5f87a 342 );\r
343\r
344 if (EFI_ERROR (Status)) {\r
345 goto ON_EXIT;\r
346 }\r
347 }\r
348\r
4cda7726 349 Status = PxeTransmit (Snp, Buffer, BufferSize);\r
a3c5f87a 350\r
351ON_EXIT:\r
352 gBS->RestoreTPL (OldTpl);\r
353\r
354 return Status;\r
355}\r