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