]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/MnpDxe/MnpMain.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpMain.c
CommitLineData
8a67d61d 1/** @file\r
3e8c18da 2 Implementation of Managed Network Protocol public services.\r
8a67d61d 3\r
05074499 4Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
8a67d61d 6\r
8a67d61d 7**/\r
8a67d61d 8\r
6e4bac4d 9#include "MnpImpl.h"\r
8a67d61d 10\r
11/**\r
b6c4ecad 12 Returns the operational parameters for the current MNP child driver. May also\r
779ae357 13 support returning the underlying SNP driver mode data.\r
14\r
b6c4ecad 15 The GetModeData() function is used to read the current mode data (operational\r
779ae357 16 parameters) from the MNP or the underlying SNP.\r
b6c4ecad 17\r
3e8c18da 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
779ae357 25\r
b6c4ecad 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
6e4bac4d 33 @retval Others The mode data could not be read.\r
8a67d61d 34\r
35**/\r
36EFI_STATUS\r
37EFIAPI\r
38MnpGetModeData (\r
779ae357 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
8a67d61d 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
dd29f3ed 48 UINT32 InterruptStatus;\r
8a67d61d 49\r
50 if (This == NULL) {\r
8a67d61d 51 return EFI_INVALID_PARAMETER;\r
52 }\r
53\r
54 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
55\r
e48e37fc 56 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 57\r
58 if (MnpConfigData != NULL) {\r
59 //\r
60 // Copy the instance configuration data.\r
61 //\r
687a2e5f 62 CopyMem (MnpConfigData, &Instance->ConfigData, sizeof (*MnpConfigData));\r
8a67d61d 63 }\r
64\r
65 if (SnpModeData != NULL) {\r
66 //\r
67 // Copy the underlayer Snp mode data.\r
68 //\r
779ae357 69 Snp = Instance->MnpServiceData->MnpDeviceData->Snp;\r
dd29f3ed 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
687a2e5f 76 CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));\r
8a67d61d 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
e48e37fc 85 gBS->RestoreTPL (OldTpl);\r
8a67d61d 86\r
87 return Status;\r
88}\r
89\r
90\r
91/**\r
779ae357 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
b6c4ecad 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
6e4bac4d 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
8a67d61d 120\r
121 @retval EFI_SUCCESS The operation completed successfully.\r
b6c4ecad 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
6e4bac4d 139 @retval Others The MNP child driver instance has been reset to\r
8a67d61d 140 startup defaults.\r
141\r
142**/\r
143EFI_STATUS\r
144EFIAPI\r
145MnpConfigure (\r
779ae357 146 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
147 IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL\r
8a67d61d 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
779ae357 155 ((MnpConfigData != NULL) &&\r
156 (MnpConfigData->ProtocolTypeFilter > 0) &&\r
157 (MnpConfigData->ProtocolTypeFilter <= 1500))\r
158 ) {\r
8a67d61d 159 return EFI_INVALID_PARAMETER;\r
160 }\r
161\r
162 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
163\r
e48e37fc 164 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 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
e48e37fc 180 gBS->RestoreTPL (OldTpl);\r
8a67d61d 181\r
182 return Status;\r
183}\r
184\r
185\r
186/**\r
779ae357 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
b6c4ecad 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
6e4bac4d 192 underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be\r
b6c4ecad 193 unsupported in some MNP implementations.\r
194\r
6e4bac4d 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
779ae357 200 @param[out] MacAddress Pointer to the resulting multicast MAC address.\r
b6c4ecad 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
6e4bac4d 214 @retval Others The address could not be converted.\r
8a67d61d 215**/\r
216EFI_STATUS\r
217EFIAPI\r
218MnpMcastIpToMac (\r
779ae357 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
8a67d61d 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
87f89c08 229 EFI_IPv6_ADDRESS *Ip6Address;\r
8a67d61d 230\r
231 if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {\r
8a67d61d 232 return EFI_INVALID_PARAMETER;\r
233 }\r
234\r
87f89c08 235 Ip6Address = &IpAddress->v6;\r
8a67d61d 236\r
87f89c08 237 if ((Ipv6Flag && !IP6_IS_MULTICAST (Ip6Address)) ||\r
238 (!Ipv6Flag && !IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress)))\r
239 ) {\r
8a67d61d 240 //\r
87f89c08 241 // The IP address passed in is not a multicast address.\r
8a67d61d 242 //\r
243 return EFI_INVALID_PARAMETER;\r
244 }\r
245\r
246 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
247\r
e48e37fc 248 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 249\r
250 if (!Instance->Configured) {\r
251\r
252 Status = EFI_NOT_STARTED;\r
253 goto ON_EXIT;\r
254 }\r
255\r
779ae357 256 Snp = Instance->MnpServiceData->MnpDeviceData->Snp;\r
8a67d61d 257 ASSERT (Snp != NULL);\r
258\r
779ae357 259 ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));\r
87f89c08 260\r
8a67d61d 261 if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {\r
87f89c08 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
779ae357 275 // Translate the IPv6 address into a multicast MAC address if the NIC is an\r
87f89c08 276 // ethernet NIC according to RFC2464.\r
277 //\r
779ae357 278\r
87f89c08 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
8a67d61d 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
e48e37fc 301 gBS->RestoreTPL (OldTpl);\r
8a67d61d 302\r
303 return Status;\r
304}\r
305\r
8a67d61d 306/**\r
779ae357 307 Enables and disables receive filters for multicast address. This function may\r
b6c4ecad 308 be unsupported in some MNP implementations.\r
779ae357 309\r
310 The Groups() function only adds and removes multicast MAC addresses from the\r
b6c4ecad 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
779ae357 314\r
3e8c18da 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
b6c4ecad 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
6e4bac4d 338 @retval Others The requested operation could not be completed.\r
b6c4ecad 339 The MNP multicast group settings are unchanged.\r
8a67d61d 340\r
341**/\r
342EFI_STATUS\r
343EFIAPI\r
344MnpGroups (\r
779ae357 345 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
346 IN BOOLEAN JoinFlag,\r
347 IN EFI_MAC_ADDRESS *MacAddress OPTIONAL\r
8a67d61d 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
e48e37fc 354 LIST_ENTRY *ListEntry;\r
8a67d61d 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
779ae357 367 SnpMode = Instance->MnpServiceData->MnpDeviceData->Snp->Mode;\r
8a67d61d 368\r
e48e37fc 369 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 370\r
371 if (!Instance->Configured) {\r
8a67d61d 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
e48e37fc 402 if (0 == CompareMem (\r
8a67d61d 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
e48e37fc 432 } else if (IsListEmpty (&Instance->GroupCtrlBlkList)) {\r
8a67d61d 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
e48e37fc 446 gBS->RestoreTPL (OldTpl);\r
8a67d61d 447\r
448 return Status;\r
449}\r
450\r
8a67d61d 451/**\r
b6c4ecad 452 Places asynchronous outgoing data packets into the transmit queue.\r
779ae357 453\r
454 The Transmit() function places a completion token into the transmit packet\r
b6c4ecad 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
779ae357 464\r
465\r
3e8c18da 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
6e4bac4d 468 descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN\r
87f89c08 469 is defined in "Related Definitions" below.\r
b6c4ecad 470\r
471 @retval EFI_SUCCESS The transmit completion token was cached.\r
8a67d61d 472 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
473 configured.\r
b6c4ecad 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
8a67d61d 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
779ae357 498 lack of system resources (usually memory).\r
8a67d61d 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
779ae357 509 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
510 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
8a67d61d 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
8a67d61d 521 return EFI_INVALID_PARAMETER;\r
522 }\r
523\r
524 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
525\r
e48e37fc 526 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 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
05074499
FS
548 Status = MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);\r
549 if (EFI_ERROR (Status)) {\r
550 goto ON_EXIT;\r
551 }\r
8a67d61d 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
e48e37fc 559 gBS->RestoreTPL (OldTpl);\r
8a67d61d 560\r
561 return Status;\r
562}\r
563\r
564\r
565/**\r
b6c4ecad 566 Places an asynchronous receiving request into the receiving queue.\r
779ae357 567\r
568 The Receive() function places a completion token into the receive packet\r
b6c4ecad 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
779ae357 574\r
6e4bac4d 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
8a67d61d 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
b6c4ecad 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
8a67d61d 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
779ae357 603 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
604 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
8a67d61d 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
8a67d61d 612 return EFI_INVALID_PARAMETER;\r
613 }\r
614\r
615 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
616\r
e48e37fc 617 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 618\r
619 if (!Instance->Configured) {\r
8a67d61d 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
8a67d61d 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
8a67d61d 636 if (!EFI_ERROR (Status)) {\r
637 //\r
638 // Try to deliver any buffered packets.\r
639 //\r
640 Status = MnpInstanceDeliverPacket (Instance);\r
36ee91ca 641\r
642 //\r
643 // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r
644 //\r
d8d26fb2 645 DispatchDpc ();\r
8a67d61d 646 }\r
647\r
648ON_EXIT:\r
e48e37fc 649 gBS->RestoreTPL (OldTpl);\r
8a67d61d 650\r
651 return Status;\r
652}\r
653\r
8a67d61d 654/**\r
779ae357 655 Aborts an asynchronous transmit or receive request.\r
656\r
b6c4ecad 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
3e8c18da 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
779ae357 667 EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all\r
87f89c08 668 pending tokens are aborted.\r
8a67d61d 669\r
670 @retval EFI_SUCCESS The asynchronous I/O request was aborted and\r
b6c4ecad 671 Token.Event was signaled. When Token is NULL,\r
672 all pending requests were aborted and their\r
673 events were signaled.\r
8a67d61d 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
b6c4ecad 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
8a67d61d 681\r
682**/\r
683EFI_STATUS\r
684EFIAPI\r
685MnpCancel (\r
779ae357 686 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
687 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL\r
8a67d61d 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
8a67d61d 695 return EFI_INVALID_PARAMETER;\r
696 }\r
697\r
698 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
699\r
e48e37fc 700 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 701\r
702 if (!Instance->Configured) {\r
8a67d61d 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
8a67d61d 711 if (Token != NULL) {\r
8a67d61d 712 Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;\r
713 }\r
714\r
36ee91ca 715 //\r
716 // Dispatch the DPC queued by the NotifyFunction of the cancled token's events.\r
717 //\r
d8d26fb2 718 DispatchDpc ();\r
36ee91ca 719\r
8a67d61d 720ON_EXIT:\r
e48e37fc 721 gBS->RestoreTPL (OldTpl);\r
8a67d61d 722\r
723 return Status;\r
724}\r
725\r
8a67d61d 726/**\r
779ae357 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
b6c4ecad 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
6e4bac4d 738 @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
b6c4ecad 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
8a67d61d 750\r
751**/\r
752EFI_STATUS\r
753EFIAPI\r
754MnpPoll (\r
779ae357 755 IN EFI_MANAGED_NETWORK_PROTOCOL *This\r
8a67d61d 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
e48e37fc 768 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 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
779ae357 778 Status = MnpReceivePacket (Instance->MnpServiceData->MnpDeviceData);\r
8a67d61d 779\r
a4df47f1 780 //\r
781 // Dispatch the DPC queued by the NotifyFunction of rx token's events.\r
782 //\r
d8d26fb2 783 DispatchDpc ();\r
36ee91ca 784\r
8a67d61d 785ON_EXIT:\r
e48e37fc 786 gBS->RestoreTPL (OldTpl);\r
8a67d61d 787\r
788 return Status;\r
789}\r