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