]>
Commit | Line | Data |
---|---|---|
a3c5f87a | 1 | /** @file\r |
4cda7726 | 2 | Implementation of transmitting a packet.\r |
3 | \r | |
4 | Copyright (c) 2004 - 2007, Intel Corporation. <BR> \r | |
5 | All rights reserved. This program and the accompanying materials are licensed \r | |
6 | and made available under the terms and conditions of the BSD License which \r | |
7 | accompanies this distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php \r | |
a3c5f87a | 9 | \r |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT 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 | 34 | EFI_STATUS\r |
4cda7726 | 35 | PxeFillHeader (\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 |
4cda7726 | 93 | Snp->Cdb.CPBsize = sizeof (PXE_CPB_FILL_HEADER_FRAGMENTED);\r |
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 | |
f3816027 | 104 | DEBUG ((EFI_D_INFO | 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 | 146 | EFI_STATUS\r |
4cda7726 | 147 | PxeTransmit (\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 |
4cda7726 | 165 | Snp->Cdb.CPBsize = sizeof (PXE_CPB_TRANSMIT);\r |
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 | |
f3816027 | 180 | DEBUG ((EFI_D_INFO | EFI_D_NET, "\nSnp->undi.transmit() "));\r |
181 | DEBUG ((EFI_D_INFO | EFI_D_NET, "\nSnp->Cdb.OpCode == %x", Snp->Cdb.OpCode));\r | |
182 | DEBUG ((EFI_D_INFO | EFI_D_NET, "\nSnp->Cdb.CPBaddr == %LX", Snp->Cdb.CPBaddr));\r | |
183 | DEBUG ((EFI_D_INFO | EFI_D_NET, "\nSnp->Cdb.DBaddr == %LX", Snp->Cdb.DBaddr));\r | |
184 | DEBUG ((EFI_D_INFO | 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 |
f3816027 | 188 | DEBUG ((EFI_D_INFO | EFI_D_NET, "\nexit Snp->undi.transmit() "));\r |
189 | DEBUG ((EFI_D_INFO | 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 | |
198 | case PXE_STATCODE_QUEUE_FULL:\r | |
199 | case PXE_STATCODE_BUSY:\r | |
200 | Status = EFI_NOT_READY;\r | |
201 | break;\r | |
202 | \r | |
203 | default:\r | |
204 | Status = EFI_DEVICE_ERROR;\r | |
205 | }\r | |
206 | \r | |
207 | DEBUG (\r | |
208 | (EFI_D_ERROR,\r | |
4cda7726 | 209 | "\nSnp->undi.transmit() %xh:%xh\n",\r |
210 | Snp->Cdb.StatFlags,\r | |
211 | Snp->Cdb.StatCode)\r | |
a3c5f87a | 212 | );\r |
213 | \r | |
214 | return Status;\r | |
215 | }\r | |
216 | \r | |
a3c5f87a | 217 | /**\r |
4cda7726 | 218 | Places a packet in the transmit queue of a network interface.\r |
219 | \r | |
220 | This function places the packet specified by Header and Buffer on the transmit\r | |
221 | queue. If HeaderSize is nonzero and HeaderSize is not equal to \r | |
222 | This->Mode->MediaHeaderSize, then EFI_INVALID_PARAMETER will be returned. If \r | |
223 | BufferSize is less than This->Mode->MediaHeaderSize, then EFI_BUFFER_TOO_SMALL\r | |
224 | will be returned. If Buffer is NULL, then EFI_INVALID_PARAMETER will be \r | |
225 | returned. If HeaderSize is nonzero and DestAddr or Protocol is NULL, then\r | |
226 | EFI_INVALID_PARAMETER will be returned. If the transmit engine of the network\r | |
227 | interface is busy, then EFI_NOT_READY will be returned. If this packet can be \r | |
228 | accepted by the transmit engine of the network interface, the packet contents \r | |
229 | specified by Buffer will be placed on the transmit queue of the network \r | |
230 | interface, and EFI_SUCCESS will be returned. GetStatus() can be used to \r | |
231 | determine when the packet has actually been transmitted. The contents of the \r | |
232 | Buffer must not be modified until the packet has actually been transmitted. \r | |
233 | The Transmit() function performs nonblocking I/O. A caller who wants to perform\r | |
234 | blocking I/O, should call Transmit(), and then GetStatus() until the \r | |
235 | transmitted buffer shows up in the recycled transmit buffer.\r | |
236 | If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.\r | |
237 | \r | |
238 | @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r | |
239 | @param HeaderSize The size, in bytes, of the media header to be filled in by the \r | |
240 | Transmit() function. If HeaderSize is nonzero, then it must\r | |
241 | be equal to This->Mode->MediaHeaderSize and the DestAddr and\r | |
242 | Protocol parameters must not be NULL.\r | |
243 | @param BufferSize The size, in bytes, of the entire packet (media header and\r | |
244 | data) to be transmitted through the network interface.\r | |
245 | @param Buffer A pointer to the packet (media header followed by data) to be \r | |
246 | transmitted. This parameter cannot be NULL. If HeaderSize is \r | |
247 | zero, then the media header in Buffer must already be filled\r | |
248 | in by the caller. If HeaderSize is nonzero, then the media \r | |
249 | header will be filled in by the Transmit() function.\r | |
250 | @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this \r | |
251 | parameter is ignored. If HeaderSize is nonzero and SrcAddr \r | |
252 | is NULL, then This->Mode->CurrentAddress is used for the \r | |
253 | source HW MAC address.\r | |
254 | @param DestAddr The destination HW MAC address. If HeaderSize is zero, then \r | |
255 | this parameter is ignored.\r | |
256 | @param Protocol The type of header to build. If HeaderSize is zero, then this \r | |
257 | parameter is ignored. See RFC 1700, section "Ether Types," \r | |
258 | for examples.\r | |
259 | \r | |
260 | @retval EFI_SUCCESS The packet was placed on the transmit queue.\r | |
261 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
262 | @retval EFI_NOT_READY The network interface is too busy to accept this\r | |
263 | transmit request.\r | |
264 | @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r | |
265 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported\r | |
266 | value.\r | |
267 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r | |
268 | @retval EFI_UNSUPPORTED This function is not supported by the network interface.\r | |
a3c5f87a | 269 | \r |
270 | **/\r | |
271 | EFI_STATUS\r | |
272 | EFIAPI\r | |
4cda7726 | 273 | SnpUndi32Transmit (\r |
274 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
275 | IN UINTN HeaderSize,\r | |
276 | IN UINTN BufferSize,\r | |
277 | IN VOID *Buffer,\r | |
278 | IN EFI_MAC_ADDRESS *SrcAddr, OPTIONAL\r | |
279 | IN EFI_MAC_ADDRESS *DestAddr, OPTIONAL\r | |
280 | IN UINT16 *Protocol OPTIONAL\r | |
a3c5f87a | 281 | )\r |
282 | {\r | |
4cda7726 | 283 | SNP_DRIVER *Snp;\r |
a3c5f87a | 284 | EFI_STATUS Status;\r |
285 | EFI_TPL OldTpl;\r | |
286 | \r | |
4cda7726 | 287 | if (This == NULL) {\r |
a3c5f87a | 288 | return EFI_INVALID_PARAMETER;\r |
289 | }\r | |
290 | \r | |
4cda7726 | 291 | Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r |
a3c5f87a | 292 | \r |
293 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
294 | \r | |
4cda7726 | 295 | if (Snp == NULL) {\r |
a3c5f87a | 296 | return EFI_DEVICE_ERROR;\r |
297 | }\r | |
298 | \r | |
4cda7726 | 299 | switch (Snp->Mode.State) {\r |
a3c5f87a | 300 | case EfiSimpleNetworkInitialized:\r |
301 | break;\r | |
302 | \r | |
303 | case EfiSimpleNetworkStopped:\r | |
304 | Status = EFI_NOT_STARTED;\r | |
305 | goto ON_EXIT;\r | |
306 | \r | |
307 | default:\r | |
308 | Status = EFI_DEVICE_ERROR;\r | |
309 | goto ON_EXIT;\r | |
310 | }\r | |
311 | \r | |
4cda7726 | 312 | if (Buffer == NULL) {\r |
a3c5f87a | 313 | Status = EFI_INVALID_PARAMETER;\r |
314 | goto ON_EXIT;\r | |
315 | }\r | |
316 | \r | |
4cda7726 | 317 | if (BufferSize < Snp->Mode.MediaHeaderSize) {\r |
a3c5f87a | 318 | Status = EFI_BUFFER_TOO_SMALL;\r |
319 | goto ON_EXIT;\r | |
320 | }\r | |
321 | \r | |
322 | //\r | |
4cda7726 | 323 | // if the HeaderSize is non-zero, we need to fill up the header and for that\r |
a3c5f87a | 324 | // we need the destination address and the protocol\r |
325 | //\r | |
4cda7726 | 326 | if (HeaderSize != 0) {\r |
327 | if (HeaderSize != Snp->Mode.MediaHeaderSize || DestAddr == 0 || Protocol == 0) {\r | |
a3c5f87a | 328 | Status = EFI_INVALID_PARAMETER;\r |
329 | goto ON_EXIT;\r | |
330 | }\r | |
331 | \r | |
4cda7726 | 332 | Status = PxeFillHeader (\r |
333 | Snp,\r | |
334 | Buffer,\r | |
335 | HeaderSize,\r | |
336 | (UINT8 *) Buffer + HeaderSize,\r | |
337 | BufferSize - HeaderSize,\r | |
338 | DestAddr,\r | |
339 | SrcAddr,\r | |
340 | Protocol\r | |
a3c5f87a | 341 | );\r |
342 | \r | |
343 | if (EFI_ERROR (Status)) {\r | |
344 | goto ON_EXIT;\r | |
345 | }\r | |
346 | }\r | |
347 | \r | |
4cda7726 | 348 | Status = PxeTransmit (Snp, Buffer, BufferSize);\r |
a3c5f87a | 349 | \r |
350 | ON_EXIT:\r | |
351 | gBS->RestoreTPL (OldTpl);\r | |
352 | \r | |
353 | return Status;\r | |
354 | }\r |