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