]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/MnpDxe/MnpMain.c
Change the file headers and some function comments.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpMain.c
CommitLineData
8a67d61d 1/** @file\r
c57273b0 2 Implementation of Managed Network Protocol public services.\r
8a67d61d 3\r
c57273b0 4Copyright (c) 2005 - 2007, Intel Corporation. <BR>\r
8a67d61d 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
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
8a67d61d 13**/\r
c57273b0 14#include "MnpImpl.h"\r
8a67d61d 15#include <Library/BaseMemoryLib.h>\r
16#include <Library/BaseLib.h>\r
17\r
8a67d61d 18\r
19\r
20/**\r
b6c4ecad 21 Returns the operational parameters for the current MNP child driver. May also\r
22 support returning the underlying SNP driver mode data. \r
23 \r
24 The GetModeData() function is used to read the current mode data (operational\r
25 parameters) from the MNP or the underlying SNP. \r
26\r
27 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
28 @param MnpConfigData Pointer to storage for MNP operational parameters. Type\r
29 EFI_MANAGED_NETWORK_CONFIG_DATA is defined in "Related\r
30 Definitions" below.\r
31 @param SnpModeData Pointer to storage for SNP operational parameters. This\r
32 feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE\r
33 is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.\r
34 \r
35 @retval EFI_SUCCESS The operation completed successfully.\r
36 @retval EFI_INVALID_PARAMETER This is NULL.\r
37 @retval EFI_UNSUPPORTED The requested feature is unsupported in this\r
38 MNP implementation.\r
39 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
40 configured. The default values are returned in\r
41 MnpConfigData if it is not NULL.\r
42 @retval Other The mode data could not be read.\r
8a67d61d 43\r
44**/\r
45EFI_STATUS\r
46EFIAPI\r
47MnpGetModeData (\r
48 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
b6c4ecad 49 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData, OPTIONAL\r
50 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r
8a67d61d 51 )\r
52{\r
53 MNP_INSTANCE_DATA *Instance;\r
54 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
55 EFI_TPL OldTpl;\r
56 EFI_STATUS Status;\r
57\r
58 if (This == NULL) {\r
59\r
60 return EFI_INVALID_PARAMETER;\r
61 }\r
62\r
63 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
64\r
e48e37fc 65 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 66\r
67 if (MnpConfigData != NULL) {\r
68 //\r
69 // Copy the instance configuration data.\r
70 //\r
687a2e5f 71 CopyMem (MnpConfigData, &Instance->ConfigData, sizeof (*MnpConfigData));\r
8a67d61d 72 }\r
73\r
74 if (SnpModeData != NULL) {\r
75 //\r
76 // Copy the underlayer Snp mode data.\r
77 //\r
78 Snp = Instance->MnpServiceData->Snp;\r
687a2e5f 79 CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));\r
8a67d61d 80 }\r
81\r
82 if (!Instance->Configured) {\r
83 Status = EFI_NOT_STARTED;\r
84 } else {\r
85 Status = EFI_SUCCESS;\r
86 }\r
87\r
e48e37fc 88 gBS->RestoreTPL (OldTpl);\r
8a67d61d 89\r
90 return Status;\r
91}\r
92\r
93\r
94/**\r
b6c4ecad 95 Sets or clears the operational parameters for the MNP child driver. \r
96 \r
97 The Configure() function is used to set, change, or reset the operational \r
98 parameters for the MNP child driver instance. Until the operational parameters\r
99 have been set, no network traffic can be sent or received by this MNP child\r
100 driver instance. Once the operational parameters have been reset, no more\r
101 traffic can be sent or received until the operational parameters have been set\r
102 again.\r
103 Each MNP child driver instance can be started and stopped independently of\r
104 each other by setting or resetting their receive filter settings with the\r
105 Configure() function.\r
106 After any successful call to Configure(), the MNP child driver instance is\r
107 started. The internal periodic timer (if supported) is enabled. Data can be\r
108 transmitted and may be received if the receive filters have also been enabled.\r
109 Note: If multiple MNP child driver instances will receive the same packet\r
110 because of overlapping receive filter settings, then the first MNP child\r
111 driver instance will receive the original packet and additional instances will\r
112 receive copies of the original packet.\r
113 Note: Warning: Receive filter settings that overlap will consume extra\r
114 processor and/or DMA resources and degrade system and network performance.\r
115\r
116 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
117 @param MnpConfigData Pointer to configuration data that will be assigned\r
118 to the MNP child driver instance. If NULL, the MNP\r
119 child driver instance is reset to startup defaults\r
120 and all pending transmit and receive requests are\r
121 flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is\r
122 defined in\r
123 EFI_MANAGED_NETWORK_PROTOCOL.GetModeData().\r
8a67d61d 124\r
125 @retval EFI_SUCCESS The operation completed successfully.\r
b6c4ecad 126 @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r
127 TRUE:\r
128 * This is NULL.\r
129 * MnpConfigData.ProtocolTypeFilter is not\r
130 valid.\r
131 The operational data for the MNP child driver\r
132 instance is unchanged.\r
133 @retval EFI_OUT_OF_RESOURCES Required system resources (usually memory)\r
134 could not be allocated.\r
135 The MNP child driver instance has been reset to\r
136 startup defaults.\r
137 @retval EFI_UNSUPPORTED The requested feature is unsupported in\r
138 this [MNP] implementation. The operational data\r
139 for the MNP child driver instance is unchanged.\r
140 @retval EFI_DEVICE_ERROR An unexpected network or system error\r
141 occurred. The MNP child driver instance has\r
142 been reset to startup defaults.\r
8a67d61d 143 @retval Other The MNP child driver instance has been reset to\r
144 startup defaults.\r
145\r
146**/\r
147EFI_STATUS\r
148EFIAPI\r
149MnpConfigure (\r
150 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
151 IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL\r
152 )\r
153{\r
154 MNP_INSTANCE_DATA *Instance;\r
155 EFI_TPL OldTpl;\r
156 EFI_STATUS Status;\r
157\r
158 if ((This == NULL) ||\r
159 ((MnpConfigData != NULL) &&\r
160 (MnpConfigData->ProtocolTypeFilter > 0) &&\r
161 (MnpConfigData->ProtocolTypeFilter <= 1500))) {\r
162\r
163 return EFI_INVALID_PARAMETER;\r
164 }\r
165\r
166 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
167\r
e48e37fc 168 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 169\r
170 if ((MnpConfigData == NULL) && (!Instance->Configured)) {\r
171 //\r
172 // If the instance is not configured and a reset is requested, just return.\r
173 //\r
174 Status = EFI_SUCCESS;\r
175 goto ON_EXIT;\r
176 }\r
177\r
178 //\r
179 // Configure the instance.\r
180 //\r
181 Status = MnpConfigureInstance (Instance, MnpConfigData);\r
182\r
183ON_EXIT:\r
e48e37fc 184 gBS->RestoreTPL (OldTpl);\r
8a67d61d 185\r
186 return Status;\r
187}\r
188\r
189\r
190/**\r
b6c4ecad 191 Translates an IP multicast address to a hardware (MAC) multicast address. This \r
192 function may be unsupported in some MNP implementations. \r
193 \r
194 The McastIpToMac() function translates an IP multicast address to a hardware\r
195 (MAC) multicast address. This function may be implemented by calling the\r
196 underlying EFI_SIMPLE_NETWORK.MCastIpToMac() function, which may also be\r
197 unsupported in some MNP implementations.\r
198\r
199 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
200 @param Ipv6Flag Set to TRUE to if IpAddress is an IPv6 multicast address.\r
201 Set to FALSE if IpAddress is an IPv4 multicast address.\r
202 @param IpAddress Pointer to the multicast IP address (in network byte order)\r
203 to convert.\r
204 @param MacAddress Pointer to the resulting multicast MAC address. \r
205\r
206 @retval EFI_SUCCESS The operation completed successfully.\r
207 @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:\r
208 * This is NULL.\r
209 * IpAddress is NULL.\r
210 * IpAddress is not a valid multicast IP\r
211 address.\r
212 * MacAddress is NULL.\r
213 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
214 configured.\r
215 @retval EFI_UNSUPPORTED The requested feature is unsupported in this\r
216 MNP implementation.\r
217 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
218 @retval Other The address could not be converted.\r
8a67d61d 219**/\r
220EFI_STATUS\r
221EFIAPI\r
222MnpMcastIpToMac (\r
223 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
224 IN BOOLEAN Ipv6Flag,\r
225 IN EFI_IP_ADDRESS *IpAddress,\r
226 OUT EFI_MAC_ADDRESS *MacAddress\r
227 )\r
228{\r
229 EFI_STATUS Status;\r
230 MNP_INSTANCE_DATA *Instance;\r
231 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
232 EFI_TPL OldTpl;\r
233\r
234 if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {\r
235\r
236 return EFI_INVALID_PARAMETER;\r
237 }\r
238\r
239 if (Ipv6Flag) {\r
240 //\r
241 // Currently IPv6 isn't supported.\r
242 //\r
243 return EFI_UNSUPPORTED;\r
244 }\r
245\r
246 if (!IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress))) {\r
247 //\r
248 // The IPv4 address passed in is not a multicast address.\r
249 //\r
250 return EFI_INVALID_PARAMETER;\r
251 }\r
252\r
253 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
254\r
e48e37fc 255 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 256\r
257 if (!Instance->Configured) {\r
258\r
259 Status = EFI_NOT_STARTED;\r
260 goto ON_EXIT;\r
261 }\r
262\r
263 Snp = Instance->MnpServiceData->Snp;\r
264 ASSERT (Snp != NULL);\r
265\r
266 if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {\r
267 //\r
268 // Translate the IPv4 address into a multicast MAC address if the NIC is an\r
269 // ethernet NIC.\r
270 //\r
271 MacAddress->Addr[0] = 0x01;\r
272 MacAddress->Addr[1] = 0x00;\r
273 MacAddress->Addr[2] = 0x5E;\r
4eb65aff 274 MacAddress->Addr[3] = (UINT8) (IpAddress->v4.Addr[1] & 0x7F);\r
8a67d61d 275 MacAddress->Addr[4] = IpAddress->v4.Addr[2];\r
276 MacAddress->Addr[5] = IpAddress->v4.Addr[3];\r
277\r
278 Status = EFI_SUCCESS;\r
279 } else {\r
280 //\r
281 // Invoke Snp to translate the multicast IP address.\r
282 //\r
283 Status = Snp->MCastIpToMac (\r
284 Snp,\r
285 Ipv6Flag,\r
286 IpAddress,\r
287 MacAddress\r
288 );\r
289 }\r
290\r
291ON_EXIT:\r
e48e37fc 292 gBS->RestoreTPL (OldTpl);\r
8a67d61d 293\r
294 return Status;\r
295}\r
296\r
8a67d61d 297/**\r
b6c4ecad 298 Enables and disables receive filters for multicast address. This function may \r
299 be unsupported in some MNP implementations.\r
300 \r
301 The Groups() function only adds and removes multicast MAC addresses from the \r
302 filter list. The MNP driver does not transmit or process Internet Group\r
303 Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is\r
304 NULL, then all joined groups are left.\r
305 \r
306 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
307 @param JoinFlag Set to TRUE to join this multicast group.\r
308 Set to FALSE to leave this multicast group.\r
309 @param MacAddress Pointer to the multicast MAC group (address) to join or\r
310 leave.\r
311\r
312 @retval EFI_SUCCESS The requested operation completed successfully.\r
313 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
314 * This is NULL.\r
315 * JoinFlag is TRUE and MacAddress is NULL.\r
316 * MacAddress is not a valid multicast MAC\r
317 address.\r
318 * The MNP multicast group settings are\r
319 unchanged.\r
320 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
321 configured.\r
322 @retval EFI_ALREADY_STARTED The supplied multicast group is already joined.\r
323 @retval EFI_NOT_FOUND The supplied multicast group is not joined.\r
324 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
325 The MNP child driver instance has been reset to\r
326 startup defaults.\r
327 @retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP\r
328 implementation.\r
329 @retval Other The requested operation could not be completed.\r
330 The MNP multicast group settings are unchanged.\r
8a67d61d 331\r
332**/\r
333EFI_STATUS\r
334EFIAPI\r
335MnpGroups (\r
336 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
337 IN BOOLEAN JoinFlag,\r
338 IN EFI_MAC_ADDRESS *MacAddress OPTIONAL\r
339 )\r
340{\r
341 MNP_INSTANCE_DATA *Instance;\r
342 EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
343 MNP_GROUP_CONTROL_BLOCK *GroupCtrlBlk;\r
344 MNP_GROUP_ADDRESS *GroupAddress;\r
e48e37fc 345 LIST_ENTRY *ListEntry;\r
8a67d61d 346 BOOLEAN AddressExist;\r
347 EFI_TPL OldTpl;\r
348 EFI_STATUS Status;\r
349\r
350 if (This == NULL || (JoinFlag && (MacAddress == NULL))) {\r
351 //\r
352 // This is NULL, or it's a join operation but MacAddress is NULL.\r
353 //\r
354 return EFI_INVALID_PARAMETER;\r
355 }\r
356\r
357 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
358 SnpMode = Instance->MnpServiceData->Snp->Mode;\r
359\r
e48e37fc 360 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 361\r
362 if (!Instance->Configured) {\r
363\r
364 Status = EFI_NOT_STARTED;\r
365 goto ON_EXIT;\r
366 }\r
367\r
368 if ((!Instance->ConfigData.EnableMulticastReceive) ||\r
369 ((MacAddress != NULL) && !NET_MAC_IS_MULTICAST (MacAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize))) {\r
370 //\r
371 // The instance isn't configured to do mulitcast receive. OR\r
372 // the passed in MacAddress is not a mutlticast mac address.\r
373 //\r
374 Status = EFI_INVALID_PARAMETER;\r
375 goto ON_EXIT;\r
376 }\r
377\r
378 Status = EFI_SUCCESS;\r
379 AddressExist = FALSE;\r
380 GroupCtrlBlk = NULL;\r
381\r
382 if (MacAddress != NULL) {\r
383 //\r
384 // Search the instance's GroupCtrlBlkList to find the specific address.\r
385 //\r
386 NET_LIST_FOR_EACH (ListEntry, &Instance->GroupCtrlBlkList) {\r
387\r
388 GroupCtrlBlk = NET_LIST_USER_STRUCT (\r
389 ListEntry,\r
390 MNP_GROUP_CONTROL_BLOCK,\r
391 CtrlBlkEntry\r
392 );\r
393 GroupAddress = GroupCtrlBlk->GroupAddress;\r
e48e37fc 394 if (0 == CompareMem (\r
8a67d61d 395 MacAddress,\r
396 &GroupAddress->Address,\r
397 SnpMode->HwAddressSize\r
398 )) {\r
399 //\r
400 // There is already the same multicast mac address configured.\r
401 //\r
402 AddressExist = TRUE;\r
403 break;\r
404 }\r
405 }\r
406\r
407 if (JoinFlag && AddressExist) {\r
408 //\r
409 // The multicast mac address to join already exists.\r
410 //\r
411 Status = EFI_ALREADY_STARTED;\r
412 }\r
413\r
414 if (!JoinFlag && !AddressExist) {\r
415 //\r
416 // The multicast mac address to leave doesn't exist in this instance.\r
417 //\r
418 Status = EFI_NOT_FOUND;\r
419 }\r
420\r
421 if (EFI_ERROR (Status)) {\r
422 goto ON_EXIT;\r
423 }\r
e48e37fc 424 } else if (IsListEmpty (&Instance->GroupCtrlBlkList)) {\r
8a67d61d 425 //\r
426 // The MacAddress is NULL and there is no configured multicast mac address,\r
427 // just return.\r
428 //\r
429 goto ON_EXIT;\r
430 }\r
431\r
432 //\r
433 // OK, it is time to take action.\r
434 //\r
435 Status = MnpGroupOp (Instance, JoinFlag, MacAddress, GroupCtrlBlk);\r
436\r
437ON_EXIT:\r
e48e37fc 438 gBS->RestoreTPL (OldTpl);\r
8a67d61d 439\r
440 return Status;\r
441}\r
442\r
8a67d61d 443/**\r
b6c4ecad 444 Places asynchronous outgoing data packets into the transmit queue.\r
445 \r
446 The Transmit() function places a completion token into the transmit packet \r
447 queue. This function is always asynchronous.\r
448 The caller must fill in the Token.Event and Token.TxData fields in the\r
449 completion token, and these fields cannot be NULL. When the transmit operation\r
450 completes, the MNP updates the Token.Status field and the Token.Event is\r
451 signaled.\r
452 Note: There may be a performance penalty if the packet needs to be\r
453 defragmented before it can be transmitted by the network device. Systems in\r
454 which performance is critical should review the requirements and features of\r
455 the underlying communications device and drivers.\r
456 \r
457 \r
458 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
459 @param Token Pointer to a token associated with the transmit data\r
460 descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN is\r
461 defined in "Related Definitions" below.\r
462\r
463 @retval EFI_SUCCESS The transmit completion token was cached.\r
8a67d61d 464 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
465 configured.\r
b6c4ecad 466 @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r
467 TRUE:\r
468 * This is NULL.\r
469 * Token is NULL.\r
470 * Token.Event is NULL.\r
471 * Token.TxData is NULL.\r
472 * Token.TxData.DestinationAddress is not\r
473 NULL and Token.TxData.HeaderLength is zero.\r
474 * Token.TxData.FragmentCount is zero.\r
475 * (Token.TxData.HeaderLength +\r
476 Token.TxData.DataLength) is not equal to the\r
477 sum of the\r
478 Token.TxData.FragmentTable[].FragmentLength\r
479 fields.\r
480 * One or more of the\r
481 Token.TxData.FragmentTable[].FragmentLength\r
482 fields is zero.\r
483 * One or more of the\r
484 Token.TxData.FragmentTable[].FragmentBufferfields\r
485 is NULL.\r
486 * Token.TxData.DataLength is greater than MTU.\r
8a67d61d 487 @retval EFI_ACCESS_DENIED The transmit completion token is already in the\r
488 transmit queue.\r
489 @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a\r
b6c4ecad 490 lack of system resources (usually memory). \r
8a67d61d 491 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
492 The MNP child driver instance has been reset to\r
493 startup defaults.\r
494 @retval EFI_NOT_READY The transmit request could not be queued because\r
495 the transmit queue is full.\r
496\r
497**/\r
498EFI_STATUS\r
499EFIAPI\r
500MnpTransmit (\r
501 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
502 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
503 )\r
504{\r
505 EFI_STATUS Status;\r
506 MNP_INSTANCE_DATA *Instance;\r
507 MNP_SERVICE_DATA *MnpServiceData;\r
508 UINT8 *PktBuf;\r
509 UINT32 PktLen;\r
510 EFI_TPL OldTpl;\r
511\r
512 if ((This == NULL) || (Token == NULL)) {\r
513\r
514 return EFI_INVALID_PARAMETER;\r
515 }\r
516\r
517 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
518\r
e48e37fc 519 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 520\r
521 if (!Instance->Configured) {\r
522\r
523 Status = EFI_NOT_STARTED;\r
524 goto ON_EXIT;\r
525 }\r
526\r
527 if (!MnpIsValidTxToken (Instance, Token)) {\r
528 //\r
529 // The Token is invalid.\r
530 //\r
531 Status = EFI_INVALID_PARAMETER;\r
532 goto ON_EXIT;\r
533 }\r
534\r
535 MnpServiceData = Instance->MnpServiceData;\r
536 NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
537\r
538 //\r
539 // Build the tx packet\r
540 //\r
541 MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);\r
542\r
543 //\r
544 // OK, send the packet synchronously.\r
545 //\r
546 Status = MnpSyncSendPacket (MnpServiceData, PktBuf, PktLen, Token);\r
547\r
548ON_EXIT:\r
e48e37fc 549 gBS->RestoreTPL (OldTpl);\r
8a67d61d 550\r
551 return Status;\r
552}\r
553\r
554\r
555/**\r
b6c4ecad 556 Places an asynchronous receiving request into the receiving queue.\r
557 \r
558 The Receive() function places a completion token into the receive packet \r
559 queue. This function is always asynchronous.\r
560 The caller must fill in the Token.Event field in the completion token, and\r
561 this field cannot be NULL. When the receive operation completes, the MNP\r
562 updates the Token.Status and Token.RxData fields and the Token.Event is\r
563 signaled.\r
564 \r
565 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
566 @param Token Pointer to a token associated with the receive\r
567 data descriptor. Type\r
568 EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in\r
569 EFI_MANAGED_NETWORK_PROTOCOL.Transmit().\r
8a67d61d 570\r
571 @retval EFI_SUCCESS The receive completion token was cached.\r
572 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
573 configured.\r
b6c4ecad 574 @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r
575 TRUE:\r
576 * This is NULL.\r
577 * Token is NULL.\r
578 * Token.Event is NULL\r
8a67d61d 579 @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a\r
580 lack of system resources (usually memory).\r
581 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
582 The MNP child driver instance has been reset to\r
583 startup defaults.\r
584 @retval EFI_ACCESS_DENIED The receive completion token was already in the\r
585 receive queue.\r
586 @retval EFI_NOT_READY The receive request could not be queued because\r
587 the receive queue is full.\r
588\r
589**/\r
590EFI_STATUS\r
591EFIAPI\r
592MnpReceive (\r
593 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
594 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
595 )\r
596{\r
597 EFI_STATUS Status;\r
598 MNP_INSTANCE_DATA *Instance;\r
599 EFI_TPL OldTpl;\r
600\r
601 if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {\r
602\r
603 return EFI_INVALID_PARAMETER;\r
604 }\r
605\r
606 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
607\r
e48e37fc 608 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 609\r
610 if (!Instance->Configured) {\r
611\r
612 Status = EFI_NOT_STARTED;\r
613 goto ON_EXIT;\r
614 }\r
615\r
616 //\r
617 // Check whether this token(event) is already in the rx token queue.\r
618 //\r
619 Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token);\r
620 if (EFI_ERROR (Status)) {\r
621\r
622 goto ON_EXIT;\r
623 }\r
624\r
625 //\r
626 // Insert the Token into the RxTokenMap.\r
627 //\r
628 Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL);\r
629\r
630 if (!EFI_ERROR (Status)) {\r
631 //\r
632 // Try to deliver any buffered packets.\r
633 //\r
634 Status = MnpInstanceDeliverPacket (Instance);\r
36ee91ca 635\r
636 //\r
637 // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r
638 //\r
639 NetLibDispatchDpc ();\r
8a67d61d 640 }\r
641\r
642ON_EXIT:\r
e48e37fc 643 gBS->RestoreTPL (OldTpl);\r
8a67d61d 644\r
645 return Status;\r
646}\r
647\r
8a67d61d 648/**\r
b6c4ecad 649 Aborts an asynchronous transmit or receive request. \r
650 \r
651 The Cancel() function is used to abort a pending transmit or receive request.\r
652 If the token is in the transmit or receive request queues, after calling this\r
653 function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r
654 signaled. If the token is not in one of the queues, which usually means that\r
655 the asynchronous operation has completed, this function will not signal the\r
656 token and EFI_NOT_FOUND is returned.\r
657\r
658 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
659 @param Token Pointer to a token that has been issued by\r
660 EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or\r
661 EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all pending\r
662 tokens are aborted.\r
8a67d61d 663\r
664 @retval EFI_SUCCESS The asynchronous I/O request was aborted and\r
b6c4ecad 665 Token.Event was signaled. When Token is NULL,\r
666 all pending requests were aborted and their\r
667 events were signaled.\r
8a67d61d 668 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
669 configured.\r
670 @retval EFI_INVALID_PARAMETER This is NULL.\r
b6c4ecad 671 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O\r
672 request was not found in the transmit or\r
673 receive queue. It has either completed or was\r
674 not issued by Transmit() and Receive().\r
8a67d61d 675\r
676**/\r
677EFI_STATUS\r
678EFIAPI\r
679MnpCancel (\r
680 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
681 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL\r
682 )\r
683{\r
684 EFI_STATUS Status;\r
685 MNP_INSTANCE_DATA *Instance;\r
686 EFI_TPL OldTpl;\r
687\r
688 if (This == NULL) {\r
689\r
690 return EFI_INVALID_PARAMETER;\r
691 }\r
692\r
693 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
694\r
e48e37fc 695 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 696\r
697 if (!Instance->Configured) {\r
698\r
699 Status = EFI_NOT_STARTED;\r
700 goto ON_EXIT;\r
701 }\r
702\r
703 //\r
704 // Iterate the RxTokenMap to cancel the specified Token.\r
705 //\r
706 Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token);\r
707\r
708 if (Token != NULL) {\r
709\r
710 Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;\r
711 }\r
712\r
36ee91ca 713 //\r
714 // Dispatch the DPC queued by the NotifyFunction of the cancled token's events.\r
715 //\r
716 NetLibDispatchDpc ();\r
717\r
8a67d61d 718ON_EXIT:\r
e48e37fc 719 gBS->RestoreTPL (OldTpl);\r
8a67d61d 720\r
721 return Status;\r
722}\r
723\r
8a67d61d 724/**\r
b6c4ecad 725 Polls for incoming data packets and processes outgoing data packets. \r
726 \r
727 The Poll() function can be used by network drivers and applications to \r
728 increase the rate that data packets are moved between the communications\r
729 device and the transmit and receive queues.\r
730 Normally, a periodic timer event internally calls the Poll() function. But, in\r
731 some systems, the periodic timer event may not call Poll() fast enough to\r
732 transmit and/or receive all data packets without missing packets. Drivers and\r
733 applications that are experiencing packet loss should try calling the Poll()\r
734 function more often.\r
735\r
736 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
737\r
738 @retval EFI_SUCCESS Incoming or outgoing data was processed.\r
739 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
740 configured.\r
741 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The\r
742 MNP child driver instance has been reset to startup\r
743 defaults.\r
744 @retval EFI_NOT_READY No incoming or outgoing data was processed. Consider\r
745 increasing the polling rate.\r
746 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive\r
747 queue. Consider increasing the polling rate.\r
8a67d61d 748\r
749**/\r
750EFI_STATUS\r
751EFIAPI\r
752MnpPoll (\r
753 IN EFI_MANAGED_NETWORK_PROTOCOL *This\r
754 )\r
755{\r
756 EFI_STATUS Status;\r
757 MNP_INSTANCE_DATA *Instance;\r
758 EFI_TPL OldTpl;\r
759\r
760 if (This == NULL) {\r
761 return EFI_INVALID_PARAMETER;\r
762 }\r
763\r
764 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
765\r
e48e37fc 766 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 767\r
768 if (!Instance->Configured) {\r
769 Status = EFI_NOT_STARTED;\r
770 goto ON_EXIT;\r
771 }\r
772\r
773 //\r
774 // Try to receive packets.\r
775 //\r
776 Status = MnpReceivePacket (Instance->MnpServiceData);\r
777\r
36ee91ca 778 NetLibDispatchDpc ();\r
779\r
8a67d61d 780ON_EXIT:\r
e48e37fc 781 gBS->RestoreTPL (OldTpl);\r
8a67d61d 782\r
783 return Status;\r
784}\r
36ee91ca 785\r