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