]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/MnpDxe/MnpMain.c
NetworkPkg: Apply uncrustify changes
[mirror_edk2.git] / NetworkPkg / 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
d1050b9d
MK
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
d1050b9d
MK
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
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
8a67d61d 90/**\r
779ae357 91 Sets or clears the operational parameters for the MNP child driver.\r
92\r
93 The Configure() function is used to set, change, or reset the operational\r
b6c4ecad 94 parameters for the MNP child driver instance. Until the operational parameters\r
95 have been set, no network traffic can be sent or received by this MNP child\r
96 driver instance. Once the operational parameters have been reset, no more\r
97 traffic can be sent or received until the operational parameters have been set\r
98 again.\r
99 Each MNP child driver instance can be started and stopped independently of\r
100 each other by setting or resetting their receive filter settings with the\r
101 Configure() function.\r
102 After any successful call to Configure(), the MNP child driver instance is\r
103 started. The internal periodic timer (if supported) is enabled. Data can be\r
104 transmitted and may be received if the receive filters have also been enabled.\r
105 Note: If multiple MNP child driver instances will receive the same packet\r
106 because of overlapping receive filter settings, then the first MNP child\r
107 driver instance will receive the original packet and additional instances will\r
108 receive copies of the original packet.\r
109 Note: Warning: Receive filter settings that overlap will consume extra\r
110 processor and/or DMA resources and degrade system and network performance.\r
111\r
6e4bac4d 112 @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
113 @param[in] MnpConfigData Pointer to configuration data that will be assigned\r
114 to the MNP child driver instance. If NULL, the MNP\r
115 child driver instance is reset to startup defaults\r
116 and all pending transmit and receive requests are\r
117 flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is\r
118 defined in EFI_MANAGED_NETWORK_PROTOCOL.GetModeData().\r
8a67d61d 119\r
120 @retval EFI_SUCCESS The operation completed successfully.\r
b6c4ecad 121 @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r
122 TRUE:\r
123 * This is NULL.\r
124 * MnpConfigData.ProtocolTypeFilter is not\r
125 valid.\r
126 The operational data for the MNP child driver\r
127 instance is unchanged.\r
128 @retval EFI_OUT_OF_RESOURCES Required system resources (usually memory)\r
129 could not be allocated.\r
130 The MNP child driver instance has been reset to\r
131 startup defaults.\r
132 @retval EFI_UNSUPPORTED The requested feature is unsupported in\r
133 this [MNP] implementation. The operational data\r
134 for the MNP child driver instance is unchanged.\r
135 @retval EFI_DEVICE_ERROR An unexpected network or system error\r
136 occurred. The MNP child driver instance has\r
137 been reset to startup defaults.\r
6e4bac4d 138 @retval Others The MNP child driver instance has been reset to\r
8a67d61d 139 startup defaults.\r
140\r
141**/\r
142EFI_STATUS\r
143EFIAPI\r
144MnpConfigure (\r
d1050b9d
MK
145 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
146 IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL\r
8a67d61d 147 )\r
148{\r
149 MNP_INSTANCE_DATA *Instance;\r
150 EFI_TPL OldTpl;\r
151 EFI_STATUS Status;\r
152\r
153 if ((This == NULL) ||\r
779ae357 154 ((MnpConfigData != NULL) &&\r
155 (MnpConfigData->ProtocolTypeFilter > 0) &&\r
156 (MnpConfigData->ProtocolTypeFilter <= 1500))\r
d1050b9d
MK
157 )\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
8a67d61d 185/**\r
779ae357 186 Translates an IP multicast address to a hardware (MAC) multicast address. This\r
187 function may be unsupported in some MNP implementations.\r
188\r
b6c4ecad 189 The McastIpToMac() function translates an IP multicast address to a hardware\r
190 (MAC) multicast address. This function may be implemented by calling the\r
6e4bac4d 191 underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be\r
b6c4ecad 192 unsupported in some MNP implementations.\r
193\r
6e4bac4d 194 @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
195 @param[in] Ipv6Flag Set to TRUE to if IpAddress is an IPv6 multicast address.\r
196 Set to FALSE if IpAddress is an IPv4 multicast address.\r
197 @param[in] IpAddress Pointer to the multicast IP address (in network byte\r
198 order) to convert.\r
779ae357 199 @param[out] MacAddress Pointer to the resulting multicast MAC address.\r
b6c4ecad 200\r
201 @retval EFI_SUCCESS The operation completed successfully.\r
202 @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:\r
203 * This is NULL.\r
204 * IpAddress is NULL.\r
205 * IpAddress is not a valid multicast IP\r
206 address.\r
207 * MacAddress is NULL.\r
208 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
209 configured.\r
210 @retval EFI_UNSUPPORTED The requested feature is unsupported in this\r
211 MNP implementation.\r
212 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
6e4bac4d 213 @retval Others The address could not be converted.\r
8a67d61d 214**/\r
215EFI_STATUS\r
216EFIAPI\r
217MnpMcastIpToMac (\r
d1050b9d
MK
218 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
219 IN BOOLEAN Ipv6Flag,\r
220 IN EFI_IP_ADDRESS *IpAddress,\r
221 OUT EFI_MAC_ADDRESS *MacAddress\r
8a67d61d 222 )\r
223{\r
d1050b9d
MK
224 EFI_STATUS Status;\r
225 MNP_INSTANCE_DATA *Instance;\r
226 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
227 EFI_TPL OldTpl;\r
228 EFI_IPv6_ADDRESS *Ip6Address;\r
8a67d61d 229\r
230 if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {\r
8a67d61d 231 return EFI_INVALID_PARAMETER;\r
232 }\r
233\r
87f89c08 234 Ip6Address = &IpAddress->v6;\r
8a67d61d 235\r
87f89c08 236 if ((Ipv6Flag && !IP6_IS_MULTICAST (Ip6Address)) ||\r
237 (!Ipv6Flag && !IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress)))\r
d1050b9d
MK
238 )\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
8a67d61d 251 Status = EFI_NOT_STARTED;\r
252 goto ON_EXIT;\r
253 }\r
254\r
779ae357 255 Snp = Instance->MnpServiceData->MnpDeviceData->Snp;\r
8a67d61d 256 ASSERT (Snp != NULL);\r
257\r
779ae357 258 ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));\r
87f89c08 259\r
8a67d61d 260 if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {\r
87f89c08 261 if (!Ipv6Flag) {\r
262 //\r
263 // Translate the IPv4 address into a multicast MAC address if the NIC is an\r
264 // ethernet NIC according to RFC1112..\r
265 //\r
266 MacAddress->Addr[0] = 0x01;\r
267 MacAddress->Addr[1] = 0x00;\r
268 MacAddress->Addr[2] = 0x5E;\r
d1050b9d 269 MacAddress->Addr[3] = (UINT8)(IpAddress->v4.Addr[1] & 0x7F);\r
87f89c08 270 MacAddress->Addr[4] = IpAddress->v4.Addr[2];\r
271 MacAddress->Addr[5] = IpAddress->v4.Addr[3];\r
272 } else {\r
273 //\r
779ae357 274 // Translate the IPv6 address into a multicast MAC address if the NIC is an\r
87f89c08 275 // ethernet NIC according to RFC2464.\r
276 //\r
779ae357 277\r
87f89c08 278 MacAddress->Addr[0] = 0x33;\r
279 MacAddress->Addr[1] = 0x33;\r
280 MacAddress->Addr[2] = Ip6Address->Addr[12];\r
281 MacAddress->Addr[3] = Ip6Address->Addr[13];\r
282 MacAddress->Addr[4] = Ip6Address->Addr[14];\r
283 MacAddress->Addr[5] = Ip6Address->Addr[15];\r
284 }\r
8a67d61d 285\r
286 Status = EFI_SUCCESS;\r
287 } else {\r
288 //\r
289 // Invoke Snp to translate the multicast IP address.\r
290 //\r
291 Status = Snp->MCastIpToMac (\r
292 Snp,\r
293 Ipv6Flag,\r
294 IpAddress,\r
295 MacAddress\r
296 );\r
297 }\r
298\r
299ON_EXIT:\r
e48e37fc 300 gBS->RestoreTPL (OldTpl);\r
8a67d61d 301\r
302 return Status;\r
303}\r
304\r
8a67d61d 305/**\r
779ae357 306 Enables and disables receive filters for multicast address. This function may\r
b6c4ecad 307 be unsupported in some MNP implementations.\r
779ae357 308\r
309 The Groups() function only adds and removes multicast MAC addresses from the\r
b6c4ecad 310 filter list. The MNP driver does not transmit or process Internet Group\r
311 Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is\r
312 NULL, then all joined groups are left.\r
779ae357 313\r
3e8c18da 314 @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
315 @param[in] JoinFlag Set to TRUE to join this multicast group.\r
316 Set to FALSE to leave this multicast group.\r
317 @param[in] MacAddress Pointer to the multicast MAC group (address) to join or\r
318 leave.\r
b6c4ecad 319\r
320 @retval EFI_SUCCESS The requested operation completed successfully.\r
321 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
322 * This is NULL.\r
323 * JoinFlag is TRUE and MacAddress is NULL.\r
324 * MacAddress is not a valid multicast MAC\r
325 address.\r
326 * The MNP multicast group settings are\r
327 unchanged.\r
328 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
329 configured.\r
330 @retval EFI_ALREADY_STARTED The supplied multicast group is already joined.\r
331 @retval EFI_NOT_FOUND The supplied multicast group is not joined.\r
332 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r
333 The MNP child driver instance has been reset to\r
334 startup defaults.\r
335 @retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP\r
336 implementation.\r
6e4bac4d 337 @retval Others The requested operation could not be completed.\r
b6c4ecad 338 The MNP multicast group settings are unchanged.\r
8a67d61d 339\r
340**/\r
341EFI_STATUS\r
342EFIAPI\r
343MnpGroups (\r
d1050b9d
MK
344 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
345 IN BOOLEAN JoinFlag,\r
346 IN EFI_MAC_ADDRESS *MacAddress OPTIONAL\r
8a67d61d 347 )\r
348{\r
d1050b9d
MK
349 MNP_INSTANCE_DATA *Instance;\r
350 EFI_SIMPLE_NETWORK_MODE *SnpMode;\r
351 MNP_GROUP_CONTROL_BLOCK *GroupCtrlBlk;\r
352 MNP_GROUP_ADDRESS *GroupAddress;\r
353 LIST_ENTRY *ListEntry;\r
354 BOOLEAN AddressExist;\r
355 EFI_TPL OldTpl;\r
356 EFI_STATUS Status;\r
357\r
358 if ((This == NULL) || (JoinFlag && (MacAddress == NULL))) {\r
8a67d61d 359 //\r
360 // This is NULL, or it's a join operation but MacAddress is NULL.\r
361 //\r
362 return EFI_INVALID_PARAMETER;\r
363 }\r
364\r
d1050b9d
MK
365 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
366 SnpMode = Instance->MnpServiceData->MnpDeviceData->Snp->Mode;\r
8a67d61d 367\r
e48e37fc 368 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 369\r
370 if (!Instance->Configured) {\r
8a67d61d 371 Status = EFI_NOT_STARTED;\r
372 goto ON_EXIT;\r
373 }\r
374\r
375 if ((!Instance->ConfigData.EnableMulticastReceive) ||\r
d1050b9d
MK
376 ((MacAddress != NULL) && !NET_MAC_IS_MULTICAST (MacAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize)))\r
377 {\r
8a67d61d 378 //\r
5feb1fbd
AC
379 // The instance isn't configured to do multicast receive. OR\r
380 // the passed in MacAddress is not a multicast mac address.\r
8a67d61d 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
8a67d61d 395 GroupCtrlBlk = NET_LIST_USER_STRUCT (\r
d1050b9d
MK
396 ListEntry,\r
397 MNP_GROUP_CONTROL_BLOCK,\r
398 CtrlBlkEntry\r
399 );\r
8a67d61d 400 GroupAddress = GroupCtrlBlk->GroupAddress;\r
e48e37fc 401 if (0 == CompareMem (\r
d1050b9d
MK
402 MacAddress,\r
403 &GroupAddress->Address,\r
404 SnpMode->HwAddressSize\r
405 ))\r
406 {\r
8a67d61d 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
d1050b9d
MK
509 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
510 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
8a67d61d 511 )\r
512{\r
d1050b9d
MK
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
8a67d61d 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
8a67d61d 529 Status = EFI_NOT_STARTED;\r
530 goto ON_EXIT;\r
531 }\r
532\r
533 if (!MnpIsValidTxToken (Instance, Token)) {\r
534 //\r
535 // The Token is invalid.\r
536 //\r
537 Status = EFI_INVALID_PARAMETER;\r
538 goto ON_EXIT;\r
539 }\r
540\r
541 MnpServiceData = Instance->MnpServiceData;\r
542 NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r
543\r
544 //\r
545 // Build the tx packet\r
546 //\r
05074499
FS
547 Status = MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);\r
548 if (EFI_ERROR (Status)) {\r
549 goto ON_EXIT;\r
550 }\r
8a67d61d 551\r
552 //\r
553 // OK, send the packet synchronously.\r
554 //\r
555 Status = MnpSyncSendPacket (MnpServiceData, PktBuf, PktLen, Token);\r
556\r
557ON_EXIT:\r
e48e37fc 558 gBS->RestoreTPL (OldTpl);\r
8a67d61d 559\r
560 return Status;\r
561}\r
562\r
8a67d61d 563/**\r
b6c4ecad 564 Places an asynchronous receiving request into the receiving queue.\r
779ae357 565\r
566 The Receive() function places a completion token into the receive packet\r
b6c4ecad 567 queue. This function is always asynchronous.\r
568 The caller must fill in the Token.Event field in the completion token, and\r
569 this field cannot be NULL. When the receive operation completes, the MNP\r
570 updates the Token.Status and Token.RxData fields and the Token.Event is\r
571 signaled.\r
779ae357 572\r
6e4bac4d 573 @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
574 @param[in] Token Pointer to a token associated with the receive\r
575 data descriptor. Type\r
576 EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in\r
577 EFI_MANAGED_NETWORK_PROTOCOL.Transmit().\r
8a67d61d 578\r
579 @retval EFI_SUCCESS The receive completion token was cached.\r
580 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
581 configured.\r
b6c4ecad 582 @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r
583 TRUE:\r
584 * This is NULL.\r
585 * Token is NULL.\r
586 * Token.Event is NULL\r
8a67d61d 587 @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a\r
588 lack of system resources (usually memory).\r
589 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r
590 The MNP child driver instance has been reset to\r
591 startup defaults.\r
592 @retval EFI_ACCESS_DENIED The receive completion token was already in the\r
593 receive queue.\r
594 @retval EFI_NOT_READY The receive request could not be queued because\r
595 the receive queue is full.\r
596\r
597**/\r
598EFI_STATUS\r
599EFIAPI\r
600MnpReceive (\r
d1050b9d
MK
601 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
602 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r
8a67d61d 603 )\r
604{\r
605 EFI_STATUS Status;\r
606 MNP_INSTANCE_DATA *Instance;\r
607 EFI_TPL OldTpl;\r
608\r
609 if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {\r
8a67d61d 610 return EFI_INVALID_PARAMETER;\r
611 }\r
612\r
613 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
614\r
e48e37fc 615 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 616\r
617 if (!Instance->Configured) {\r
8a67d61d 618 Status = EFI_NOT_STARTED;\r
619 goto ON_EXIT;\r
620 }\r
621\r
622 //\r
623 // Check whether this token(event) is already in the rx token queue.\r
624 //\r
d1050b9d 625 Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *)Token);\r
8a67d61d 626 if (EFI_ERROR (Status)) {\r
8a67d61d 627 goto ON_EXIT;\r
628 }\r
629\r
630 //\r
631 // Insert the Token into the RxTokenMap.\r
632 //\r
d1050b9d 633 Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *)Token, NULL);\r
8a67d61d 634 if (!EFI_ERROR (Status)) {\r
635 //\r
636 // Try to deliver any buffered packets.\r
637 //\r
638 Status = MnpInstanceDeliverPacket (Instance);\r
36ee91ca 639\r
640 //\r
641 // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r
642 //\r
d8d26fb2 643 DispatchDpc ();\r
8a67d61d 644 }\r
645\r
646ON_EXIT:\r
e48e37fc 647 gBS->RestoreTPL (OldTpl);\r
8a67d61d 648\r
649 return Status;\r
650}\r
651\r
8a67d61d 652/**\r
779ae357 653 Aborts an asynchronous transmit or receive request.\r
654\r
b6c4ecad 655 The Cancel() function is used to abort a pending transmit or receive request.\r
656 If the token is in the transmit or receive request queues, after calling this\r
657 function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r
658 signaled. If the token is not in one of the queues, which usually means that\r
659 the asynchronous operation has completed, this function will not signal the\r
660 token and EFI_NOT_FOUND is returned.\r
661\r
3e8c18da 662 @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
663 @param[in] Token Pointer to a token that has been issued by\r
664 EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or\r
779ae357 665 EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all\r
87f89c08 666 pending tokens are aborted.\r
8a67d61d 667\r
668 @retval EFI_SUCCESS The asynchronous I/O request was aborted and\r
b6c4ecad 669 Token.Event was signaled. When Token is NULL,\r
670 all pending requests were aborted and their\r
671 events were signaled.\r
8a67d61d 672 @retval EFI_NOT_STARTED This MNP child driver instance has not been\r
673 configured.\r
674 @retval EFI_INVALID_PARAMETER This is NULL.\r
b6c4ecad 675 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O\r
676 request was not found in the transmit or\r
677 receive queue. It has either completed or was\r
678 not issued by Transmit() and Receive().\r
8a67d61d 679\r
680**/\r
681EFI_STATUS\r
682EFIAPI\r
683MnpCancel (\r
d1050b9d
MK
684 IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r
685 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL\r
8a67d61d 686 )\r
687{\r
688 EFI_STATUS Status;\r
689 MNP_INSTANCE_DATA *Instance;\r
690 EFI_TPL OldTpl;\r
691\r
692 if (This == NULL) {\r
8a67d61d 693 return EFI_INVALID_PARAMETER;\r
694 }\r
695\r
696 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r
697\r
e48e37fc 698 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 699\r
700 if (!Instance->Configured) {\r
8a67d61d 701 Status = EFI_NOT_STARTED;\r
702 goto ON_EXIT;\r
703 }\r
704\r
705 //\r
706 // Iterate the RxTokenMap to cancel the specified Token.\r
707 //\r
d1050b9d 708 Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *)Token);\r
8a67d61d 709 if (Token != NULL) {\r
8a67d61d 710 Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;\r
711 }\r
712\r
36ee91ca 713 //\r
5feb1fbd 714 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
36ee91ca 715 //\r
d8d26fb2 716 DispatchDpc ();\r
36ee91ca 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
779ae357 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
b6c4ecad 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
6e4bac4d 736 @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r
b6c4ecad 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
d1050b9d 753 IN EFI_MANAGED_NETWORK_PROTOCOL *This\r
8a67d61d 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
779ae357 776 Status = MnpReceivePacket (Instance->MnpServiceData->MnpDeviceData);\r
8a67d61d 777\r
a4df47f1 778 //\r
779 // Dispatch the DPC queued by the NotifyFunction of rx token's events.\r
780 //\r
d8d26fb2 781 DispatchDpc ();\r
36ee91ca 782\r
8a67d61d 783ON_EXIT:\r
e48e37fc 784 gBS->RestoreTPL (OldTpl);\r
8a67d61d 785\r
786 return Status;\r
787}\r