2 Declaration of structures and functions of MnpDxe driver.
4 Copyright (c) 2005 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "MnpDriver.h"
20 #define NET_ETHER_FCS_SIZE 4
22 #define MNP_SYS_POLL_INTERVAL (10 * TICKS_PER_MS) // 10 milliseconds
23 #define MNP_TIMEOUT_CHECK_INTERVAL (10 * TICKS_PER_MS) // 10 milliseconds
24 #define MNP_TX_TIMEOUT_TIME (500 * TICKS_PER_MS) // 500 milliseconds
25 #define MNP_INIT_NET_BUFFER_NUM 512
26 #define MNP_NET_BUFFER_INCREASEMENT 64
27 #define MNP_MAX_NET_BUFFER_NUM 65536
29 #define MNP_MAX_RCVD_PACKET_QUE_SIZE 256
31 #define MNP_RECEIVE_UNICAST 0x01
32 #define MNP_RECEIVE_BROADCAST 0x02
34 #define UNICAST_PACKET MNP_RECEIVE_UNICAST
35 #define BROADCAST_PACKET MNP_RECEIVE_BROADCAST
37 #define MNP_INSTANCE_DATA_SIGNATURE SIGNATURE_32 ('M', 'n', 'p', 'I')
39 #define MNP_INSTANCE_DATA_FROM_THIS(a) \
44 MNP_INSTANCE_DATA_SIGNATURE \
47 typedef struct _MNP_INSTANCE_DATA
{
50 MNP_SERVICE_DATA
*MnpServiceData
;
56 EFI_MANAGED_NETWORK_PROTOCOL ManagedNetwork
;
61 LIST_ENTRY GroupCtrlBlkList
;
65 LIST_ENTRY RxDeliveredPacketQueue
;
66 LIST_ENTRY RcvdPacketQueue
;
67 UINTN RcvdPacketQueueSize
;
69 EFI_MANAGED_NETWORK_CONFIG_DATA ConfigData
;
74 typedef struct _MNP_GROUP_ADDRESS
{
76 EFI_MAC_ADDRESS Address
;
80 typedef struct _MNP_GROUP_CONTROL_BLOCK
{
81 LIST_ENTRY CtrlBlkEntry
;
82 MNP_GROUP_ADDRESS
*GroupAddress
;
83 } MNP_GROUP_CONTROL_BLOCK
;
85 typedef struct _MNP_RXDATA_WRAP
{
87 MNP_INSTANCE_DATA
*Instance
;
88 EFI_MANAGED_NETWORK_RECEIVE_DATA RxData
;
94 Initialize the mnp service context data.
96 @param MnpServiceData Pointer to the mnp service context data.
97 @param ImageHandle The driver image handle.
98 @param ControllerHandle Handle of device to bind driver to.
100 @retval EFI_SUCCESS The mnp service context is initialized.
101 @retval Other Some error occurs.
105 MnpInitializeServiceData (
106 IN MNP_SERVICE_DATA
*MnpServiceData
,
107 IN EFI_HANDLE ImageHandle
,
108 IN EFI_HANDLE ControllerHandle
112 Flush the mnp service context data.
114 @param MnpServiceData Pointer to the mnp service context data.
115 @param ImageHandle The driver image handle.
119 MnpFlushServiceData (
120 IN MNP_SERVICE_DATA
*MnpServiceData
,
121 IN EFI_HANDLE ImageHandle
125 Initialize the mnp instance context data.
127 @param MnpServiceData Pointer to the mnp service context data.
128 @param Instance Pointer to the mnp instance context data to
133 MnpInitializeInstanceData (
134 IN MNP_SERVICE_DATA
*MnpServiceData
,
135 IN MNP_INSTANCE_DATA
*Instance
139 Check whether the token specified by Arg maches the token in Item.
141 @param Map Pointer to the NET_MAP.
142 @param Item Pointer to the NET_MAP_ITEM
143 @param Arg Pointer to the Arg, it's a pointer to the token to
146 @retval EFI_SUCCESS The token specified by Arg is different from the
148 @retval EFI_ACCESS_DENIED The token specified by Arg is the same as that in
155 IN NET_MAP_ITEM
*Item
,
160 Cancel the token specified by Arg if it matches the token in Item.
162 @param Map Pointer to the NET_MAP.
163 @param Item Pointer to the NET_MAP_ITEM
164 @param Arg Pointer to the Arg, it's a pointer to the token to
167 @retval EFI_SUCCESS The Arg is NULL, and the token in Item is
168 cancelled, or the Arg isn't NULL, and the token in
169 Item is different from the Arg.
170 @retval EFI_ABORTED The Arg isn't NULL, the token in Item mathces the
171 Arg, and the token is cancelled.
177 IN NET_MAP_ITEM
*Item
,
182 Flush the instance's received data.
184 @param Instance Pointer to the mnp instance context data.
188 MnpFlushRcvdDataQueue (
189 IN MNP_INSTANCE_DATA
*Instance
193 Configure the Instance using ConfigData.
195 @param Instance Pointer to the mnp instance context data.
196 @param ConfigData Pointer to the configuration data used to configure
199 @retval EFI_SUCCESS The Instance is configured.
200 @retval EFI_UNSUPPORTED EnableReceiveTimestamps is on and the
201 implementation doesn't support it.
202 @retval Other Some error occurs.
206 MnpConfigureInstance (
207 IN MNP_INSTANCE_DATA
*Instance
,
208 IN EFI_MANAGED_NETWORK_CONFIG_DATA
*ConfigData OPTIONAL
212 Do the group operations for this instance.
214 @param Instance Pointer to the instance context data.
215 @param JoinFlag Set to TRUE to join a group. Set to TRUE to leave a
217 @param MacAddress Pointer to the group address to join or leave.
218 @param CtrlBlk Pointer to the group control block if JoinFlag if
221 @retval EFI_SUCCESS The group operation finished.
222 @retval Other Some error occurs.
227 IN MNP_INSTANCE_DATA
*Instance
,
229 IN EFI_MAC_ADDRESS
*MacAddr OPTIONAL
,
230 IN MNP_GROUP_CONTROL_BLOCK
*CtrlBlk OPTIONAL
234 Validates the Mnp transmit token.
236 @param Instance Pointer to the Mnp instance context data.
237 @param Token Pointer to the transmit token to check.
239 @return The Token is valid or not.
244 IN MNP_INSTANCE_DATA
*Instance
,
245 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*Token
249 Build the packet to transmit from the TxData passed in.
251 @param MnpServiceData Pointer to the mnp service context data.
252 @param TxData Pointer to the transmit data containing the
253 information to build the packet.
254 @param PktBuf Pointer to record the address of the packet.
255 @param PktLen Pointer to a UINT32 variable used to record the
261 IN MNP_SERVICE_DATA
*MnpServiceData
,
262 IN EFI_MANAGED_NETWORK_TRANSMIT_DATA
*TxData
,
268 Synchronously send out the packet.
270 @param MnpServiceData Pointer to the mnp service context data.
271 @param Packet Pointer to the pakcet buffer.
272 @param Length The length of the packet.
273 @param Token Pointer to the token the packet generated from.
275 @retval EFI_SUCCESS The packet is sent out.
276 @retval EFI_TIMEOUT Time out occurs, the packet isn't sent.
277 @retval EFI_DEVICE_ERROR An unexpected network error occurs.
282 IN MNP_SERVICE_DATA
*MnpServiceData
,
285 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*Token
289 Try to deliver the received packet to the instance.
291 @param Instance Pointer to the mnp instance context data.
293 @retval EFI_SUCCESS The received packet is delivered, or there is no
294 packet to deliver, or there is no available receive
296 @retval EFI_OUT_OF_RESOURCES The deliver fails due to lack of memory resource.
300 MnpInstanceDeliverPacket (
301 IN MNP_INSTANCE_DATA
*Instance
305 Recycle the RxData and other resources used to hold and deliver the received
308 @param Event The event this notify function registered to.
309 @param Context Pointer to the context data registerd to the Event.
320 Try to receive a packet and deliver it.
322 @param MnpServiceData Pointer to the mnp service context data.
324 @retval EFI_SUCCESS add return value to function comment
325 @retval EFI_NOT_STARTED The simple network protocol is not started.
326 @retval EFI_NOT_READY No packet received.
327 @retval EFI_DEVICE_ERROR An unexpected error occurs.
332 IN MNP_SERVICE_DATA
*MnpServiceData
336 Allocate a free NET_BUF from MnpServiceData->FreeNbufQue. If there is none
337 in the queue, first try to allocate some and add them into the queue, then
338 fetch the NET_BUF from the updated FreeNbufQue.
340 @param MnpServiceData Pointer to the MNP_SERVICE_DATA.
342 @return Pointer to the allocated free NET_BUF structure, if NULL the operation is failed.
347 IN MNP_SERVICE_DATA
*MnpServiceData
351 Try to reclaim the Nbuf into the buffer pool.
353 @param MnpServiceData Pointer to the mnp service context data.
354 @param Nbuf Pointer to the NET_BUF to free.
359 IN MNP_SERVICE_DATA
*MnpServiceData
,
364 Remove the received packets if timeout occurs.
366 @param Event The event this notify function registered to.
367 @param Context Pointer to the context data registered to the
373 MnpCheckPacketTimeout (
379 Poll to receive the packets from Snp. This function is either called by upperlayer
380 protocols/applications or the system poll timer notify mechanism.
382 @param Event The event this notify function registered to.
383 @param Context Pointer to the context data registered to the
395 Returns the operational parameters for the current MNP child driver. May also
396 support returning the underlying SNP driver mode data.
398 The GetModeData() function is used to read the current mode data (operational
399 parameters) from the MNP or the underlying SNP.
401 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
402 @param MnpConfigData Pointer to storage for MNP operational parameters. Type
403 EFI_MANAGED_NETWORK_CONFIG_DATA is defined in "Related
405 @param SnpModeData Pointer to storage for SNP operational parameters. This
406 feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE
407 is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.
409 @retval EFI_SUCCESS The operation completed successfully.
410 @retval EFI_INVALID_PARAMETER This is NULL.
411 @retval EFI_UNSUPPORTED The requested feature is unsupported in this
413 @retval EFI_NOT_STARTED This MNP child driver instance has not been
414 configured. The default values are returned in
415 MnpConfigData if it is not NULL.
416 @retval Other The mode data could not be read.
422 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
423 OUT EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData
, OPTIONAL
424 OUT EFI_SIMPLE_NETWORK_MODE
*SnpModeData OPTIONAL
428 Sets or clears the operational parameters for the MNP child driver.
430 The Configure() function is used to set, change, or reset the operational
431 parameters for the MNP child driver instance. Until the operational parameters
432 have been set, no network traffic can be sent or received by this MNP child
433 driver instance. Once the operational parameters have been reset, no more
434 traffic can be sent or received until the operational parameters have been set
436 Each MNP child driver instance can be started and stopped independently of
437 each other by setting or resetting their receive filter settings with the
438 Configure() function.
439 After any successful call to Configure(), the MNP child driver instance is
440 started. The internal periodic timer (if supported) is enabled. Data can be
441 transmitted and may be received if the receive filters have also been enabled.
442 Note: If multiple MNP child driver instances will receive the same packet
443 because of overlapping receive filter settings, then the first MNP child
444 driver instance will receive the original packet and additional instances will
445 receive copies of the original packet.
446 Note: Warning: Receive filter settings that overlap will consume extra
447 processor and/or DMA resources and degrade system and network performance.
449 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
450 @param MnpConfigData Pointer to configuration data that will be assigned
451 to the MNP child driver instance. If NULL, the MNP
452 child driver instance is reset to startup defaults
453 and all pending transmit and receive requests are
454 flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is
456 EFI_MANAGED_NETWORK_PROTOCOL.GetModeData().
458 @retval EFI_SUCCESS The operation completed successfully.
459 @retval EFI_INVALID_PARAMETER One or more of the following conditions is
462 * MnpConfigData.ProtocolTypeFilter is not
464 The operational data for the MNP child driver
465 instance is unchanged.
466 @retval EFI_OUT_OF_RESOURCES Required system resources (usually memory)
467 could not be allocated.
468 The MNP child driver instance has been reset to
470 @retval EFI_UNSUPPORTED The requested feature is unsupported in
471 this [MNP] implementation. The operational data
472 for the MNP child driver instance is unchanged.
473 @retval EFI_DEVICE_ERROR An unexpected network or system error
474 occurred. The MNP child driver instance has
475 been reset to startup defaults.
476 @retval Other The MNP child driver instance has been reset to
483 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
484 IN EFI_MANAGED_NETWORK_CONFIG_DATA
*MnpConfigData OPTIONAL
488 Translates an IP multicast address to a hardware (MAC) multicast address. This
489 function may be unsupported in some MNP implementations.
491 The McastIpToMac() function translates an IP multicast address to a hardware
492 (MAC) multicast address. This function may be implemented by calling the
493 underlying EFI_SIMPLE_NETWORK.MCastIpToMac() function, which may also be
494 unsupported in some MNP implementations.
496 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
497 @param Ipv6Flag Set to TRUE to if IpAddress is an IPv6 multicast address.
498 Set to FALSE if IpAddress is an IPv4 multicast address.
499 @param IpAddress Pointer to the multicast IP address (in network byte order)
501 @param MacAddress Pointer to the resulting multicast MAC address.
503 @retval EFI_SUCCESS The operation completed successfully.
504 @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:
507 * IpAddress is not a valid multicast IP
509 * MacAddress is NULL.
510 @retval EFI_NOT_STARTED This MNP child driver instance has not been
512 @retval EFI_UNSUPPORTED The requested feature is unsupported in this
514 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
515 @retval Other The address could not be converted.
520 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
522 IN EFI_IP_ADDRESS
*IpAddress
,
523 OUT EFI_MAC_ADDRESS
*MacAddress
527 Enables and disables receive filters for multicast address. This function may
528 be unsupported in some MNP implementations.
530 The Groups() function only adds and removes multicast MAC addresses from the
531 filter list. The MNP driver does not transmit or process Internet Group
532 Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is
533 NULL, then all joined groups are left.
535 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
536 @param JoinFlag Set to TRUE to join this multicast group.
537 Set to FALSE to leave this multicast group.
538 @param MacAddress Pointer to the multicast MAC group (address) to join or
541 @retval EFI_SUCCESS The requested operation completed successfully.
542 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
544 * JoinFlag is TRUE and MacAddress is NULL.
545 * MacAddress is not a valid multicast MAC
547 * The MNP multicast group settings are
549 @retval EFI_NOT_STARTED This MNP child driver instance has not been
551 @retval EFI_ALREADY_STARTED The supplied multicast group is already joined.
552 @retval EFI_NOT_FOUND The supplied multicast group is not joined.
553 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.
554 The MNP child driver instance has been reset to
556 @retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP
558 @retval Other The requested operation could not be completed.
559 The MNP multicast group settings are unchanged.
565 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
567 IN EFI_MAC_ADDRESS
*MacAddress OPTIONAL
571 Places asynchronous outgoing data packets into the transmit queue.
573 The Transmit() function places a completion token into the transmit packet
574 queue. This function is always asynchronous.
575 The caller must fill in the Token.Event and Token.TxData fields in the
576 completion token, and these fields cannot be NULL. When the transmit operation
577 completes, the MNP updates the Token.Status field and the Token.Event is
579 Note: There may be a performance penalty if the packet needs to be
580 defragmented before it can be transmitted by the network device. Systems in
581 which performance is critical should review the requirements and features of
582 the underlying communications device and drivers.
585 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
586 @param Token Pointer to a token associated with the transmit data
587 descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN is
588 defined in "Related Definitions" below.
590 @retval EFI_SUCCESS The transmit completion token was cached.
591 @retval EFI_NOT_STARTED This MNP child driver instance has not been
593 @retval EFI_INVALID_PARAMETER One or more of the following conditions is
597 * Token.Event is NULL.
598 * Token.TxData is NULL.
599 * Token.TxData.DestinationAddress is not
600 NULL and Token.TxData.HeaderLength is zero.
601 * Token.TxData.FragmentCount is zero.
602 * (Token.TxData.HeaderLength +
603 Token.TxData.DataLength) is not equal to the
605 Token.TxData.FragmentTable[].FragmentLength
608 Token.TxData.FragmentTable[].FragmentLength
611 Token.TxData.FragmentTable[].FragmentBufferfields
613 * Token.TxData.DataLength is greater than MTU.
614 @retval EFI_ACCESS_DENIED The transmit completion token is already in the
616 @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
617 lack of system resources (usually memory).
618 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
619 The MNP child driver instance has been reset to
621 @retval EFI_NOT_READY The transmit request could not be queued because
622 the transmit queue is full.
628 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
629 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*Token
633 Aborts an asynchronous transmit or receive request.
635 The Cancel() function is used to abort a pending transmit or receive request.
636 If the token is in the transmit or receive request queues, after calling this
637 function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
638 signaled. If the token is not in one of the queues, which usually means that
639 the asynchronous operation has completed, this function will not signal the
640 token and EFI_NOT_FOUND is returned.
642 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
643 @param Token Pointer to a token that has been issued by
644 EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or
645 EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all pending
648 @retval EFI_SUCCESS The asynchronous I/O request was aborted and
649 Token.Event was signaled. When Token is NULL,
650 all pending requests were aborted and their
651 events were signaled.
652 @retval EFI_NOT_STARTED This MNP child driver instance has not been
654 @retval EFI_INVALID_PARAMETER This is NULL.
655 @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O
656 request was not found in the transmit or
657 receive queue. It has either completed or was
658 not issued by Transmit() and Receive().
664 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
665 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*Token OPTIONAL
669 Places an asynchronous receiving request into the receiving queue.
671 The Receive() function places a completion token into the receive packet
672 queue. This function is always asynchronous.
673 The caller must fill in the Token.Event field in the completion token, and
674 this field cannot be NULL. When the receive operation completes, the MNP
675 updates the Token.Status and Token.RxData fields and the Token.Event is
678 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
679 @param Token Pointer to a token associated with the receive
680 data descriptor. Type
681 EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in
682 EFI_MANAGED_NETWORK_PROTOCOL.Transmit().
684 @retval EFI_SUCCESS The receive completion token was cached.
685 @retval EFI_NOT_STARTED This MNP child driver instance has not been
687 @retval EFI_INVALID_PARAMETER One or more of the following conditions is
691 * Token.Event is NULL
692 @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a
693 lack of system resources (usually memory).
694 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
695 The MNP child driver instance has been reset to
697 @retval EFI_ACCESS_DENIED The receive completion token was already in the
699 @retval EFI_NOT_READY The receive request could not be queued because
700 the receive queue is full.
706 IN EFI_MANAGED_NETWORK_PROTOCOL
*This
,
707 IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN
*Token
711 Polls for incoming data packets and processes outgoing data packets.
713 The Poll() function can be used by network drivers and applications to
714 increase the rate that data packets are moved between the communications
715 device and the transmit and receive queues.
716 Normally, a periodic timer event internally calls the Poll() function. But, in
717 some systems, the periodic timer event may not call Poll() fast enough to
718 transmit and/or receive all data packets without missing packets. Drivers and
719 applications that are experiencing packet loss should try calling the Poll()
722 @param This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.
724 @retval EFI_SUCCESS Incoming or outgoing data was processed.
725 @retval EFI_NOT_STARTED This MNP child driver instance has not been
727 @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The
728 MNP child driver instance has been reset to startup
730 @retval EFI_NOT_READY No incoming or outgoing data was processed. Consider
731 increasing the polling rate.
732 @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive
733 queue. Consider increasing the polling rate.
739 IN EFI_MANAGED_NETWORK_PROTOCOL
*This