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