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