]> git.proxmox.com Git - mirror_edk2.git/blob - OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/SimpleNetwork.c
1b9e26195f349933421d3d988158c6fe1a537935
[mirror_edk2.git] / OptionRomPkg / Bus / Usb / UsbNetworking / Ax88772 / SimpleNetwork.c
1 /** @file
2 Provides the Simple Network functions.
3
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 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
9
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.
12
13 **/
14
15 #include "Ax88772.h"
16
17 /**
18 This function updates the filtering on the receiver.
19
20 This support routine calls ::Ax88772MacAddressSet to update
21 the MAC address. This routine then rebuilds the multicast
22 hash by calling ::Ax88772MulticastClear and ::Ax88772MulticastSet.
23 Finally this routine enables the receiver by calling
24 ::Ax88772RxControl.
25
26 @param [in] pSimpleNetwork Simple network mode pointer
27
28 @retval EFI_SUCCESS This operation was successful.
29 @retval EFI_NOT_STARTED The network interface was not started.
30 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
31 EFI_SIMPLE_NETWORK_PROTOCOL structure.
32 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
33 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
34
35 **/
36 EFI_STATUS
37 ReceiveFilterUpdate (
38 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork
39 )
40 {
41 EFI_SIMPLE_NETWORK_MODE * pMode;
42 NIC_DEVICE * pNicDevice;
43 EFI_STATUS Status;
44 UINT32 Index;
45
46 DBG_ENTER ( );
47
48 //
49 // Set the MAC address
50 //
51 pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
52 pMode = pSimpleNetwork->Mode;
53 Status = Ax88772MacAddressSet ( pNicDevice,
54 &pMode->CurrentAddress.Addr[0]);
55 if ( !EFI_ERROR ( Status )) {
56 //
57 // Clear the multicast hash table
58 //
59 Ax88772MulticastClear ( pNicDevice );
60
61 //
62 // Load the multicast hash table
63 //
64 if ( 0 != ( pMode->ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST )) {
65 for ( Index = 0;
66 ( !EFI_ERROR ( Status )) && ( Index < pMode->MCastFilterCount );
67 Index++ ) {
68 //
69 // Enable the next multicast address
70 //
71 Ax88772MulticastSet ( pNicDevice,
72 &pMode->MCastFilter[ Index ].Addr[0]);
73 }
74 }
75
76 //
77 // Enable the receiver
78 //
79 if ( !EFI_ERROR ( Status )) {
80 Status = Ax88772RxControl ( pNicDevice, pMode->ReceiveFilterSetting );
81 }
82 }
83
84 //
85 // Return the operation status
86 //
87 DBG_EXIT_STATUS ( Status );
88 return Status;
89 }
90
91
92 /**
93 This function updates the SNP driver status.
94
95 This function gets the current interrupt and recycled transmit
96 buffer status from the network interface. The interrupt status
97 and the media status are returned as a bit mask in InterruptStatus.
98 If InterruptStatus is NULL, the interrupt status will not be read.
99 Upon successful return of the media status, the MediaPresent field
100 of EFI_SIMPLE_NETWORK_MODE will be updated to reflect any change
101 of media status. If TxBuf is not NULL, a recycled transmit buffer
102 address will be retrived. If a recycled transmit buffer address
103 is returned in TxBuf, then the buffer has been successfully
104 transmitted, and the status for that buffer is cleared.
105
106 This function calls ::Ax88772Rx to update the media status and
107 queue any receive packets.
108
109 @param [in] pSimpleNetwork Protocol instance pointer
110 @param [in] pInterruptStatus A pointer to the bit mask of the current active interrupts.
111 If this is NULL, the interrupt status will not be read from
112 the device. If this is not NULL, the interrupt status will
113 be read from teh device. When the interrupt status is read,
114 it will also be cleared. Clearing the transmit interrupt
115 does not empty the recycled transmit buffer array.
116 @param [out] ppTxBuf Recycled transmit buffer address. The network interface will
117 not transmit if its internal recycled transmit buffer array is
118 full. Reading the transmit buffer does not clear the transmit
119 interrupt. If this is NULL, then the transmit buffer status
120 will not be read. If there are not transmit buffers to recycle
121 and TxBuf is not NULL, *TxBuf will be set to NULL.
122
123 @retval EFI_SUCCESS This operation was successful.
124 @retval EFI_NOT_STARTED The network interface was not started.
125 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
126 EFI_SIMPLE_NETWORK_PROTOCOL structure.
127 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
128
129 **/
130 EFI_STATUS
131 EFIAPI
132 SN_GetStatus (
133 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
134 OUT UINT32 * pInterruptStatus,
135 OUT VOID ** ppTxBuf
136 )
137 {
138 BOOLEAN bLinkIdle;
139 EFI_SIMPLE_NETWORK_MODE * pMode;
140 NIC_DEVICE * pNicDevice;
141 EFI_STATUS Status;
142 EFI_TPL TplPrevious;
143
144 DBG_ENTER ( );
145
146 //
147 // Verify the parameters
148 //
149 if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
150 //
151 // Return the transmit buffer
152 //
153 pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
154 if (( NULL != ppTxBuf ) && ( NULL != pNicDevice->pTxBuffer )) {
155 *ppTxBuf = pNicDevice->pTxBuffer;
156 pNicDevice->pTxBuffer = NULL;
157 }
158
159 //
160 // Determine if interface is running
161 //
162 pMode = pSimpleNetwork->Mode;
163 if ( EfiSimpleNetworkStopped != pMode->State ) {
164 //
165 // Synchronize with Ax88772Timer
166 //
167 VERIFY_TPL ( TPL_AX88772 );
168 TplPrevious = gBS->RaiseTPL ( TPL_AX88772 );
169
170 //
171 // Update the link status
172 //
173 bLinkIdle = pNicDevice->bLinkIdle;
174 pNicDevice->bLinkIdle = TRUE;
175 Ax88772Rx ( pNicDevice, bLinkIdle );
176 pMode->MediaPresent = pNicDevice->bLinkUp;
177
178 //
179 // Release the synchronization with Ax88772Timer
180 //
181 gBS->RestoreTPL ( TplPrevious );
182
183 //
184 // Return the interrupt status
185 //
186 if ( NULL != pInterruptStatus ) {
187 *pInterruptStatus = 0;
188 }
189 Status = EFI_SUCCESS;
190 }
191 else {
192 Status = EFI_NOT_STARTED;
193 }
194 }
195 else {
196 Status = EFI_INVALID_PARAMETER;
197 }
198
199 //
200 // Return the operation status
201 //
202 DBG_EXIT_STATUS ( Status );
203 return Status;
204 }
205
206
207 /**
208 Resets the network adapter and allocates the transmit and receive buffers
209 required by the network interface; optionally, also requests allocation of
210 additional transmit and receive buffers. This routine must be called before
211 any other routine in the Simple Network protocol is called.
212
213 @param [in] pSimpleNetwork Protocol instance pointer
214 @param [in] ExtraRxBufferSize Size in bytes to add to the receive buffer allocation
215 @param [in] ExtraTxBufferSize Size in bytes to add to the transmit buffer allocation
216
217 @retval EFI_SUCCESS This operation was successful.
218 @retval EFI_NOT_STARTED The network interface was not started.
219 @retval EFI_OUT_OF_RESORUCES There was not enough memory for the transmit and receive buffers
220 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
221 EFI_SIMPLE_NETWORK_PROTOCOL structure.
222 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
223 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
224
225 **/
226 EFI_STATUS
227 EFIAPI
228 SN_Initialize (
229 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
230 IN UINTN ExtraRxBufferSize,
231 IN UINTN ExtraTxBufferSize
232 )
233 {
234 EFI_SIMPLE_NETWORK_MODE * pMode;
235 EFI_STATUS Status;
236
237 DBG_ENTER ( );
238
239 //
240 // Verify the parameters
241 //
242 if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
243 //
244 // Determine if the interface is already started
245 //
246 pMode = pSimpleNetwork->Mode;
247 if ( EfiSimpleNetworkStarted == pMode->State ) {
248 if (( 0 == ExtraRxBufferSize ) && ( 0 == ExtraTxBufferSize )) {
249 //
250 // Start the adapter
251 //
252 Status = SN_Reset ( pSimpleNetwork, FALSE );
253 if ( !EFI_ERROR ( Status )) {
254 //
255 // Update the network state
256 //
257 pMode->State = EfiSimpleNetworkInitialized;
258 }
259 }
260 else {
261 Status = EFI_UNSUPPORTED;
262 }
263 }
264 else {
265 Status = EFI_NOT_STARTED;
266 }
267 }
268 else {
269 Status = EFI_INVALID_PARAMETER;
270 }
271
272 //
273 // Return the operation status
274 //
275 DBG_EXIT_STATUS ( Status );
276 return Status;
277 }
278
279
280 /**
281 This function converts a multicast IP address to a multicast HW MAC address
282 for all packet transactions.
283
284 @param [in] pSimpleNetwork Protocol instance pointer
285 @param [in] bIPv6 Set to TRUE if the multicast IP address is IPv6 [RFC2460].
286 Set to FALSE if the multicast IP address is IPv4 [RFC 791].
287 @param [in] pIP The multicast IP address that is to be converted to a
288 multicast HW MAC address.
289 @param [in] pMAC The multicast HW MAC address that is to be generated from IP.
290
291 @retval EFI_SUCCESS This operation was successful.
292 @retval EFI_NOT_STARTED The network interface was not started.
293 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
294 EFI_SIMPLE_NETWORK_PROTOCOL structure.
295 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
296 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
297
298 **/
299 EFI_STATUS
300 EFIAPI
301 SN_MCastIPtoMAC (
302 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
303 IN BOOLEAN bIPv6,
304 IN EFI_IP_ADDRESS * pIP,
305 IN EFI_MAC_ADDRESS * pMAC
306 )
307 {
308 EFI_STATUS Status;
309
310 DBG_ENTER ( );
311
312 //
313 // This is not currently supported
314 //
315 Status = EFI_UNSUPPORTED;
316
317 //
318 // Return the operation status
319 //
320 DBG_EXIT_STATUS ( Status );
321 return Status;
322 }
323
324
325 /**
326 This function performs read and write operations on the NVRAM device
327 attached to a network interface.
328
329 @param [in] pSimpleNetwork Protocol instance pointer
330 @param [in] ReadWrite TRUE for read operations, FALSE for write operations.
331 @param [in] Offset Byte offset in the NVRAM device at which to start the
332 read or write operation. This must be a multiple of
333 NvRamAccessSize and less than NvRamSize.
334 @param [in] BufferSize The number of bytes to read or write from the NVRAM device.
335 This must also be a multiple of NvramAccessSize.
336 @param [in, out] pBuffer A pointer to the data buffer.
337
338 @retval EFI_SUCCESS This operation was successful.
339 @retval EFI_NOT_STARTED The network interface was not started.
340 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
341 EFI_SIMPLE_NETWORK_PROTOCOL structure.
342 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
343 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
344
345 **/
346 EFI_STATUS
347 EFIAPI
348 SN_NvData (
349 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
350 IN BOOLEAN ReadWrite,
351 IN UINTN Offset,
352 IN UINTN BufferSize,
353 IN OUT VOID * pBuffer
354 )
355 {
356 EFI_STATUS Status;
357
358 DBG_ENTER ( );
359
360 //
361 // This is not currently supported
362 //
363 Status = EFI_UNSUPPORTED;
364
365 //
366 // Return the operation status
367 //
368 DBG_EXIT_STATUS ( Status );
369 return Status;
370 }
371
372
373 /**
374 Attempt to receive a packet from the network adapter.
375
376 This function retrieves one packet from the receive queue of the network
377 interface. If there are no packets on the receive queue, then EFI_NOT_READY
378 will be returned. If there is a packet on the receive queue, and the size
379 of the packet is smaller than BufferSize, then the contents of the packet
380 will be placed in Buffer, and BufferSize will be udpated with the actual
381 size of the packet. In addition, if SrcAddr, DestAddr, and Protocol are
382 not NULL, then these values will be extracted from the media header and
383 returned. If BufferSize is smaller than the received packet, then the
384 size of the receive packet will be placed in BufferSize and
385 EFI_BUFFER_TOO_SMALL will be returned.
386
387 This routine calls ::Ax88772Rx to update the media status and
388 empty the network adapter of receive packets.
389
390 @param [in] pSimpleNetwork Protocol instance pointer
391 @param [out] pHeaderSize The size, in bytes, of the media header to be filled in by
392 the Transmit() function. If HeaderSize is non-zero, then
393 it must be equal to SimpleNetwork->Mode->MediaHeaderSize
394 and DestAddr and Protocol parameters must not be NULL.
395 @param [out] pBufferSize The size, in bytes, of the entire packet (media header and
396 data) to be transmitted through the network interface.
397 @param [out] pBuffer A pointer to the packet (media header followed by data) to
398 to be transmitted. This parameter can not be NULL. If
399 HeaderSize is zero, then the media header is Buffer must
400 already be filled in by the caller. If HeaderSize is nonzero,
401 then the media header will be filled in by the Transmit()
402 function.
403 @param [out] pSrcAddr The source HW MAC address. If HeaderSize is zero, then
404 this parameter is ignored. If HeaderSize is nonzero and
405 SrcAddr is NULL, then SimpleNetwork->Mode->CurrentAddress
406 is used for the source HW MAC address.
407 @param [out] pDestAddr The destination HW MAC address. If HeaderSize is zero, then
408 this parameter is ignored.
409 @param [out] pProtocol The type of header to build. If HeaderSize is zero, then
410 this parameter is ignored.
411
412 @retval EFI_SUCCESS This operation was successful.
413 @retval EFI_NOT_STARTED The network interface was not started.
414 @retval EFI_NOT_READY No packets have been received on the network interface.
415 @retval EFI_BUFFER_TOO_SMALL The packet is larger than BufferSize bytes.
416 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
417 EFI_SIMPLE_NETWORK_PROTOCOL structure.
418 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
419
420 **/
421 EFI_STATUS
422 EFIAPI
423 SN_Receive (
424 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
425 OUT UINTN * pHeaderSize,
426 OUT UINTN * pBufferSize,
427 OUT VOID * pBuffer,
428 OUT EFI_MAC_ADDRESS * pSrcAddr,
429 OUT EFI_MAC_ADDRESS * pDestAddr,
430 OUT UINT16 * pProtocol
431 )
432 {
433 ETHERNET_HEADER * pHeader;
434 EFI_SIMPLE_NETWORK_MODE * pMode;
435 NIC_DEVICE * pNicDevice;
436 RX_TX_PACKET * pRxPacket;
437 EFI_STATUS Status;
438 EFI_TPL TplPrevious;
439 UINT16 Type;
440
441 DBG_ENTER ( );
442
443 //
444 // Verify the parameters
445 //
446 if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
447 //
448 // The interface must be running
449 //
450 pMode = pSimpleNetwork->Mode;
451 if ( EfiSimpleNetworkInitialized == pMode->State ) {
452 //
453 // Synchronize with Ax88772Timer
454 //
455 VERIFY_TPL ( TPL_AX88772 );
456 TplPrevious = gBS->RaiseTPL ( TPL_AX88772 );
457
458 //
459 // Update the link status
460 //
461 pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
462 Ax88772Rx ( pNicDevice, FALSE );
463 pMode->MediaPresent = pNicDevice->bLinkUp;
464 if ( pMode->MediaPresent ) {
465 //
466 // Attempt to receive a packet
467 //
468 pRxPacket = pNicDevice->pRxHead;
469 if ( NULL != pRxPacket ) {
470 pNicDevice->pRxHead = pRxPacket->pNext;
471 if ( NULL == pNicDevice->pRxHead ) {
472 pNicDevice->pRxTail = NULL;
473 }
474
475 //
476 // Copy the received packet into the receive buffer
477 //
478 *pBufferSize = pRxPacket->Length;
479 CopyMem ( pBuffer, &pRxPacket->Data[0], pRxPacket->Length );
480 pHeader = (ETHERNET_HEADER *) &pRxPacket->Data[0];
481 if ( NULL != pHeaderSize ) {
482 *pHeaderSize = sizeof ( *pHeader );
483 }
484 if ( NULL != pDestAddr ) {
485 CopyMem ( pDestAddr, &pHeader->dest_addr, PXE_HWADDR_LEN_ETHER );
486 }
487 if ( NULL != pSrcAddr ) {
488 CopyMem ( pSrcAddr, &pHeader->src_addr, PXE_HWADDR_LEN_ETHER );
489 }
490 if ( NULL != pProtocol ) {
491 Type = pHeader->type;
492 Type = (UINT16)(( Type >> 8 ) | ( Type << 8 ));
493 *pProtocol = Type;
494 }
495 Status = EFI_SUCCESS;
496 }
497 else {
498 //
499 // No receive packets available
500 //
501 Status = EFI_NOT_READY;
502 }
503 }
504 else {
505 //
506 // Link no up
507 //
508 Status = EFI_NOT_READY;
509 }
510
511 //
512 // Release the synchronization with Ax88772Timer
513 //
514 gBS->RestoreTPL ( TplPrevious );
515 }
516 else {
517 Status = EFI_NOT_STARTED;
518 }
519 }
520 else {
521 Status = EFI_INVALID_PARAMETER;
522 }
523
524 //
525 // Return the operation status
526 //
527 DBG_EXIT_STATUS ( Status );
528 return Status;
529 }
530
531
532 /**
533 This function is used to enable and disable the hardware and software receive
534 filters for the underlying network device.
535
536 The receive filter change is broken down into three steps:
537
538 1. The filter mask bits that are set (ON) in the Enable parameter
539 are added to the current receive filter settings.
540
541 2. The filter mask bits that are set (ON) in the Disable parameter
542 are subtracted from the updated receive filter settins.
543
544 3. If the resulting filter settigns is not supported by the hardware
545 a more liberal setting is selected.
546
547 If the same bits are set in the Enable and Disable parameters, then the bits
548 in the Disable parameter takes precedence.
549
550 If the ResetMCastFilter parameter is TRUE, then the multicast address list
551 filter is disabled (irregardless of what other multicast bits are set in
552 the enable and Disable parameters). The SNP->Mode->MCastFilterCount field
553 is set to zero. The SNP->Mode->MCastFilter contents are undefined.
554
555 After enableing or disabling receive filter settings, software should
556 verify the new settings by checking the SNP->Mode->ReceeiveFilterSettings,
557 SNP->Mode->MCastFilterCount and SNP->Mode->MCastFilter fields.
558
559 Note: Some network drivers and/or devices will automatically promote
560 receive filter settings if the requested setting can not be honored.
561 For example, if a request for four multicast addresses is made and
562 the underlying hardware only supports two multicast addresses the
563 driver might set the promiscuous or promiscuous multicast receive filters
564 instead. The receiving software is responsible for discarding any extra
565 packets that get through the hardware receive filters.
566
567 If ResetMCastFilter is TRUE, then the multicast receive filter list
568 on the network interface will be reset to the default multicast receive
569 filter list. If ResetMCastFilter is FALSE, and this network interface
570 allows the multicast receive filter list to be modified, then the
571 MCastFilterCnt and MCastFilter are used to update the current multicast
572 receive filter list. The modified receive filter list settings can be
573 found in the MCastFilter field of EFI_SIMPLE_NETWORK_MODE.
574
575 This routine calls ::ReceiveFilterUpdate to update the receive
576 state in the network adapter.
577
578 @param [in] pSimpleNetwork Protocol instance pointer
579 @param [in] Enable A bit mask of receive filters to enable on the network interface.
580 @param [in] Disable A bit mask of receive filters to disable on the network interface.
581 For backward compatibility with EFI 1.1 platforms, the
582 EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST bit must be set
583 when the ResetMCastFilter parameter is TRUE.
584 @param [in] bResetMCastFilter Set to TRUE to reset the contents of the multicast receive
585 filters on the network interface to their default values.
586 @param [in] MCastFilterCnt Number of multicast HW MAC address in the new MCastFilter list.
587 This value must be less than or equal to the MaxMCastFilterCnt
588 field of EFI_SIMPLE_NETWORK_MODE. This field is optional if
589 ResetMCastFilter is TRUE.
590 @param [in] pMCastFilter A pointer to a list of new multicast receive filter HW MAC
591 addresses. This list will replace any existing multicast
592 HW MAC address list. This field is optional if ResetMCastFilter
593 is TRUE.
594
595 @retval EFI_SUCCESS This operation was successful.
596 @retval EFI_NOT_STARTED The network interface was not started.
597 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
598 EFI_SIMPLE_NETWORK_PROTOCOL structure.
599 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
600 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
601
602 **/
603 EFI_STATUS
604 EFIAPI
605 SN_ReceiveFilters (
606 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
607 IN UINT32 Enable,
608 IN UINT32 Disable,
609 IN BOOLEAN bResetMCastFilter,
610 IN UINTN MCastFilterCnt,
611 IN EFI_MAC_ADDRESS * pMCastFilter
612 )
613 {
614 EFI_SIMPLE_NETWORK_MODE * pMode;
615 EFI_MAC_ADDRESS * pMulticastAddress;
616 EFI_MAC_ADDRESS * pTableEnd;
617 EFI_STATUS Status;
618
619 DBG_ENTER ( );
620
621 //
622 // Verify the parameters
623 //
624 Status = EFI_INVALID_PARAMETER;
625 if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
626 pMode = pSimpleNetwork->Mode;
627
628 //
629 // Update the multicast list if necessary
630 //
631 if ( !bResetMCastFilter ) {
632 if ( 0 != MCastFilterCnt ) {
633 if (( MAX_MCAST_FILTER_CNT >= MCastFilterCnt )
634 && ( NULL != pMCastFilter )) {
635 //
636 // Verify the multicast addresses
637 //
638 pMulticastAddress = pMCastFilter;
639 pTableEnd = pMulticastAddress + MCastFilterCnt;
640 while ( pTableEnd > pMulticastAddress ) {
641 //
642 // The first digit of the multicast address must have the LSB set
643 //
644 if ( 0 == ( pMulticastAddress->Addr[0] & 1 )) {
645 //
646 // Invalid multicast address
647 //
648 break;
649 }
650 pMulticastAddress += 1;
651 }
652 if ( pTableEnd == pMulticastAddress ) {
653 //
654 // Update the multicast filter list.
655 //
656 CopyMem (&pMode->MCastFilter[0],
657 pMCastFilter,
658 MCastFilterCnt * sizeof ( *pMCastFilter ));
659 Status = EFI_SUCCESS;
660 }
661 }
662 }
663 else {
664 Status = EFI_SUCCESS;
665 }
666 }
667 else {
668 //
669 // No multicast address list is specified
670 //
671 MCastFilterCnt = 0;
672 Status = EFI_SUCCESS;
673 }
674 if ( !EFI_ERROR ( Status )) {
675 //
676 // The parameters are valid!
677 //
678 pMode->ReceiveFilterSetting |= Enable;
679 pMode->ReceiveFilterSetting &= ~Disable;
680 pMode->MCastFilterCount = (UINT32)MCastFilterCnt;
681
682 //
683 // Update the receive filters in the adapter
684 //
685 Status = ReceiveFilterUpdate ( pSimpleNetwork );
686 }
687 }
688
689 //
690 // Return the operation status
691 //
692 DBG_EXIT_STATUS ( Status );
693 return Status;
694 }
695
696
697 /**
698 Reset the network adapter.
699
700 Resets a network adapter and reinitializes it with the parameters that
701 were provided in the previous call to Initialize (). The transmit and
702 receive queues are cleared. Receive filters, the station address, the
703 statistics, and the multicast-IP-to-HW MAC addresses are not reset by
704 this call.
705
706 This routine calls ::Ax88772Reset to perform the adapter specific
707 reset operation. This routine also starts the link negotiation
708 by calling ::Ax88772NegotiateLinkStart.
709
710 @param [in] pSimpleNetwork Protocol instance pointer
711 @param [in] bExtendedVerification Indicates that the driver may perform a more
712 exhaustive verification operation of the device
713 during reset.
714
715 @retval EFI_SUCCESS This operation was successful.
716 @retval EFI_NOT_STARTED The network interface was not started.
717 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
718 EFI_SIMPLE_NETWORK_PROTOCOL structure.
719 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
720 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
721
722 **/
723 EFI_STATUS
724 EFIAPI
725 SN_Reset (
726 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
727 IN BOOLEAN bExtendedVerification
728 )
729 {
730 EFI_SIMPLE_NETWORK_MODE * pMode;
731 NIC_DEVICE * pNicDevice;
732 RX_TX_PACKET * pRxPacket;
733 EFI_STATUS Status;
734 EFI_TPL TplPrevious;
735
736 DBG_ENTER ( );
737
738 //
739 // Verify the parameters
740 //
741 if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
742 //
743 // Synchronize with Ax88772Timer
744 //
745 VERIFY_TPL ( TPL_AX88772 );
746 TplPrevious = gBS->RaiseTPL ( TPL_AX88772 );
747
748 //
749 // Update the device state
750 //
751 pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
752 pNicDevice->bComplete = FALSE;
753 pNicDevice->bLinkUp = FALSE;
754
755 pMode = pSimpleNetwork->Mode;
756 pMode->MediaPresent = FALSE;
757
758 //
759 // Discard any received packets
760 //
761 while ( NULL != pNicDevice->pRxHead ) {
762 //
763 // Remove the packet from the received packet list
764 //
765 pRxPacket = pNicDevice->pRxHead;
766 pNicDevice->pRxHead = pRxPacket->pNext;
767
768 //
769 // Queue the packet to the free list
770 //
771 pRxPacket->pNext = pNicDevice->pRxFree;
772 pNicDevice->pRxFree = pRxPacket;
773 }
774 pNicDevice->pRxTail = NULL;
775
776 //
777 // Reset the device
778 //
779 Status = Ax88772Reset ( pNicDevice );
780 if ( !EFI_ERROR ( Status )) {
781 //
782 // Update the receive filters in the adapter
783 //
784 Status = ReceiveFilterUpdate ( pSimpleNetwork );
785
786 //
787 // Try to get a connection to the network
788 //
789 if ( !EFI_ERROR ( Status )) {
790 //
791 // Start the autonegotiation
792 //
793 Status = Ax88772NegotiateLinkStart ( pNicDevice );
794 }
795 }
796
797 //
798 // Release the synchronization with Ax88772Timer
799 //
800 gBS->RestoreTPL ( TplPrevious );
801 }
802 else {
803 Status = EFI_INVALID_PARAMETER;
804 }
805
806 //
807 // Return the operation status
808 //
809 DBG_EXIT_STATUS ( Status );
810 return Status;
811 }
812
813
814 /**
815 Initialize the simple network protocol.
816
817 This routine calls ::Ax88772MacAddressGet to obtain the
818 MAC address.
819
820 @param [in] pNicDevice NIC_DEVICE_INSTANCE pointer
821
822 @retval EFI_SUCCESS Setup was successful
823
824 **/
825 EFI_STATUS
826 SN_Setup (
827 IN NIC_DEVICE * pNicDevice
828 )
829 {
830 EFI_SIMPLE_NETWORK_MODE * pMode;
831 EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork;
832 EFI_STATUS Status;
833
834 DBG_ENTER ( );
835
836 //
837 // Initialize the simple network protocol
838 //
839 pSimpleNetwork = &pNicDevice->SimpleNetwork;
840 pSimpleNetwork->Revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION;
841 pSimpleNetwork->Start = (EFI_SIMPLE_NETWORK_START)SN_Start;
842 pSimpleNetwork->Stop = (EFI_SIMPLE_NETWORK_STOP)SN_Stop;
843 pSimpleNetwork->Initialize = (EFI_SIMPLE_NETWORK_INITIALIZE)SN_Initialize;
844 pSimpleNetwork->Reset = (EFI_SIMPLE_NETWORK_RESET)SN_Reset;
845 pSimpleNetwork->Shutdown = (EFI_SIMPLE_NETWORK_SHUTDOWN)SN_Shutdown;
846 pSimpleNetwork->ReceiveFilters = (EFI_SIMPLE_NETWORK_RECEIVE_FILTERS)SN_ReceiveFilters;
847 pSimpleNetwork->StationAddress = (EFI_SIMPLE_NETWORK_STATION_ADDRESS)SN_StationAddress;
848 pSimpleNetwork->Statistics = (EFI_SIMPLE_NETWORK_STATISTICS)SN_Statistics;
849 pSimpleNetwork->MCastIpToMac = (EFI_SIMPLE_NETWORK_MCAST_IP_TO_MAC)SN_MCastIPtoMAC;
850 pSimpleNetwork->NvData = (EFI_SIMPLE_NETWORK_NVDATA)SN_NvData;
851 pSimpleNetwork->GetStatus = (EFI_SIMPLE_NETWORK_GET_STATUS)SN_GetStatus;
852 pSimpleNetwork->Transmit = (EFI_SIMPLE_NETWORK_TRANSMIT)SN_Transmit;
853 pSimpleNetwork->Receive = (EFI_SIMPLE_NETWORK_RECEIVE)SN_Receive;
854 pSimpleNetwork->WaitForPacket = NULL;
855 pMode = &pNicDevice->SimpleNetworkData;
856 pSimpleNetwork->Mode = pMode;
857
858 pMode->State = EfiSimpleNetworkStopped;
859 pMode->HwAddressSize = PXE_HWADDR_LEN_ETHER;
860 pMode->MediaHeaderSize = sizeof ( ETHERNET_HEADER );
861 pMode->MaxPacketSize = AX88772_MAX_PKT_SIZE;
862 pMode->NvRamSize = 0;
863 pMode->NvRamAccessSize = 0;
864 pMode->ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
865 | EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
866 | EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
867 | EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS
868 | EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;
869 pMode->ReceiveFilterSetting = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
870 | EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST;
871 pMode->MaxMCastFilterCount = MAX_MCAST_FILTER_CNT;
872 pMode->MCastFilterCount = 0;
873 SetMem ( &pMode->BroadcastAddress,
874 PXE_HWADDR_LEN_ETHER,
875 0xff );
876 pMode->IfType = EfiNetworkInterfaceUndi;
877 pMode->MacAddressChangeable = TRUE;
878 pMode->MultipleTxSupported = TRUE;
879 pMode->MediaPresentSupported = TRUE;
880 pMode->MediaPresent = FALSE;
881
882 //
883 // Read the MAC address
884 //
885 pNicDevice->PhyId = PHY_ID_INTERNAL;
886 pNicDevice->b100Mbps = TRUE;
887 pNicDevice->bFullDuplex = TRUE;
888 Status = Ax88772MacAddressGet (
889 pNicDevice,
890 &pMode->PermanentAddress.Addr[0]);
891 if ( !EFI_ERROR ( Status )) {
892 //
893 // Display the MAC address
894 //
895 DEBUG (( DEBUG_MAC_ADDRESS | DEBUG_INFO,
896 "MAC: %02x-%02x-%02x-%02x-%02x-%02x\n",
897 pMode->PermanentAddress.Addr[0],
898 pMode->PermanentAddress.Addr[1],
899 pMode->PermanentAddress.Addr[2],
900 pMode->PermanentAddress.Addr[3],
901 pMode->PermanentAddress.Addr[4],
902 pMode->PermanentAddress.Addr[5]));
903
904 //
905 // Use the hardware address as the current address
906 //
907 CopyMem ( &pMode->CurrentAddress,
908 &pMode->PermanentAddress,
909 PXE_HWADDR_LEN_ETHER );
910 }
911
912 //
913 // Return the setup status
914 //
915 DBG_EXIT_STATUS ( Status );
916 return Status;
917 }
918
919
920 /**
921 This routine starts the network interface.
922
923 @param [in] pSimpleNetwork Protocol instance pointer
924
925 @retval EFI_SUCCESS This operation was successful.
926 @retval EFI_ALREADY_STARTED The network interface was already started.
927 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
928 EFI_SIMPLE_NETWORK_PROTOCOL structure.
929 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
930 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
931
932 **/
933 EFI_STATUS
934 EFIAPI
935 SN_Start (
936 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork
937 )
938 {
939 NIC_DEVICE * pNicDevice;
940 EFI_SIMPLE_NETWORK_MODE * pMode;
941 EFI_STATUS Status;
942
943 DBG_ENTER ( );
944
945 //
946 // Verify the parameters
947 //
948 Status = EFI_INVALID_PARAMETER;
949 if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
950 pMode = pSimpleNetwork->Mode;
951 if ( EfiSimpleNetworkStopped == pMode->State ) {
952 //
953 // Initialize the mode structure
954 // NVRAM access is not supported
955 //
956 ZeroMem ( pMode, sizeof ( *pMode ));
957
958 pMode->State = EfiSimpleNetworkStarted;
959 pMode->HwAddressSize = PXE_HWADDR_LEN_ETHER;
960 pMode->MediaHeaderSize = sizeof ( ETHERNET_HEADER );
961 pMode->MaxPacketSize = AX88772_MAX_PKT_SIZE;
962 pMode->ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
963 | EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
964 | EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
965 | EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS
966 | EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;
967 pMode->ReceiveFilterSetting = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST;
968 pMode->MaxMCastFilterCount = MAX_MCAST_FILTER_CNT;
969 pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
970 Status = Ax88772MacAddressGet ( pNicDevice, &pMode->PermanentAddress.Addr[0]);
971 CopyMem ( &pMode->CurrentAddress,
972 &pMode->PermanentAddress,
973 sizeof ( pMode->CurrentAddress ));
974 pMode->BroadcastAddress.Addr[0] = 0xff;
975 pMode->BroadcastAddress.Addr[1] = 0xff;
976 pMode->BroadcastAddress.Addr[2] = 0xff;
977 pMode->BroadcastAddress.Addr[3] = 0xff;
978 pMode->BroadcastAddress.Addr[4] = 0xff;
979 pMode->BroadcastAddress.Addr[5] = 0xff;
980 pMode->IfType = 1;
981 pMode->MacAddressChangeable = TRUE;
982 pMode->MultipleTxSupported = TRUE;
983 pMode->MediaPresentSupported = TRUE;
984 pMode->MediaPresent = FALSE;
985 }
986 else {
987 Status = EFI_ALREADY_STARTED;
988 }
989 }
990
991 //
992 // Return the operation status
993 //
994 DBG_EXIT_STATUS ( Status );
995 return Status;
996 }
997
998
999 /**
1000 Set the MAC address.
1001
1002 This function modifies or resets the current station address of a
1003 network interface. If Reset is TRUE, then the current station address
1004 is set ot the network interface's permanent address. If Reset if FALSE
1005 then the current station address is changed to the address specified by
1006 pNew.
1007
1008 This routine calls ::Ax88772MacAddressSet to update the MAC address
1009 in the network adapter.
1010
1011 @param [in] pSimpleNetwork Protocol instance pointer
1012 @param [in] bReset Flag used to reset the station address to the
1013 network interface's permanent address.
1014 @param [in] pNew New station address to be used for the network
1015 interface.
1016
1017 @retval EFI_SUCCESS This operation was successful.
1018 @retval EFI_NOT_STARTED The network interface was not started.
1019 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
1020 EFI_SIMPLE_NETWORK_PROTOCOL structure.
1021 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1022 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
1023
1024 **/
1025 EFI_STATUS
1026 EFIAPI
1027 SN_StationAddress (
1028 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
1029 IN BOOLEAN bReset,
1030 IN EFI_MAC_ADDRESS * pNew
1031 )
1032 {
1033 NIC_DEVICE * pNicDevice;
1034 EFI_SIMPLE_NETWORK_MODE * pMode;
1035 EFI_STATUS Status;
1036
1037 DBG_ENTER ( );
1038
1039 //
1040 // Verify the parameters
1041 //
1042 if (( NULL != pSimpleNetwork )
1043 && ( NULL != pSimpleNetwork->Mode )
1044 && (( !bReset ) || ( bReset && ( NULL != pNew )))) {
1045 //
1046 // Verify that the adapter is already started
1047 //
1048 pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
1049 pMode = pSimpleNetwork->Mode;
1050 if ( EfiSimpleNetworkStarted == pMode->State ) {
1051 //
1052 // Determine the adapter MAC address
1053 //
1054 if ( bReset ) {
1055 //
1056 // Use the permanent address
1057 //
1058 CopyMem ( &pMode->CurrentAddress,
1059 &pMode->PermanentAddress,
1060 sizeof ( pMode->CurrentAddress ));
1061 }
1062 else {
1063 //
1064 // Use the specified address
1065 //
1066 CopyMem ( &pMode->CurrentAddress,
1067 pNew,
1068 sizeof ( pMode->CurrentAddress ));
1069 }
1070
1071 //
1072 // Update the address on the adapter
1073 //
1074 Status = Ax88772MacAddressSet ( pNicDevice, &pMode->CurrentAddress.Addr[0]);
1075 }
1076 else {
1077 Status = EFI_NOT_STARTED;
1078 }
1079 }
1080 else {
1081 Status = EFI_INVALID_PARAMETER;
1082 }
1083
1084 //
1085 // Return the operation status
1086 //
1087 DBG_EXIT_STATUS ( Status );
1088 return Status;
1089 }
1090
1091
1092 /**
1093 This function resets or collects the statistics on a network interface.
1094 If the size of the statistics table specified by StatisticsSize is not
1095 big enough for all of the statistics that are collected by the network
1096 interface, then a partial buffer of statistics is returned in
1097 StatisticsTable.
1098
1099 @param [in] pSimpleNetwork Protocol instance pointer
1100 @param [in] bReset Set to TRUE to reset the statistics for the network interface.
1101 @param [in, out] pStatisticsSize On input the size, in bytes, of StatisticsTable. On output
1102 the size, in bytes, of the resulting table of statistics.
1103 @param [out] pStatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
1104 conains the statistics.
1105
1106 @retval EFI_SUCCESS This operation was successful.
1107 @retval EFI_NOT_STARTED The network interface was not started.
1108 @retval EFI_BUFFER_TOO_SMALL The pStatisticsTable is NULL or the buffer is too small.
1109 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
1110 EFI_SIMPLE_NETWORK_PROTOCOL structure.
1111 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1112 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
1113
1114 **/
1115 EFI_STATUS
1116 EFIAPI
1117 SN_Statistics (
1118 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
1119 IN BOOLEAN bReset,
1120 IN OUT UINTN * pStatisticsSize,
1121 OUT EFI_NETWORK_STATISTICS * pStatisticsTable
1122 )
1123 {
1124 EFI_STATUS Status;
1125
1126 DBG_ENTER ( );
1127
1128 //
1129 // This is not currently supported
1130 //
1131 Status = EFI_UNSUPPORTED;
1132
1133 //
1134 // Return the operation status
1135 //
1136 DBG_EXIT_STATUS ( Status );
1137 return Status;
1138 }
1139
1140
1141 /**
1142 This function stops a network interface. This call is only valid
1143 if the network interface is in the started state.
1144
1145 @param [in] pSimpleNetwork Protocol instance pointer
1146
1147 @retval EFI_SUCCESS This operation was successful.
1148 @retval EFI_NOT_STARTED The network interface was not started.
1149 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
1150 EFI_SIMPLE_NETWORK_PROTOCOL structure.
1151 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1152 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
1153
1154 **/
1155 EFI_STATUS
1156 EFIAPI
1157 SN_Stop (
1158 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork
1159 )
1160 {
1161 EFI_SIMPLE_NETWORK_MODE * pMode;
1162 EFI_STATUS Status;
1163
1164 DBG_ENTER ( );
1165
1166 //
1167 // Verify the parameters
1168 //
1169 if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
1170 //
1171 // Determine if the interface is started
1172 //
1173 pMode = pSimpleNetwork->Mode;
1174 if ( EfiSimpleNetworkStopped != pMode->State ) {
1175 if ( EfiSimpleNetworkStarted == pMode->State ) {
1176 //
1177 // Release the resources acquired in SN_Start
1178 //
1179
1180 //
1181 // Mark the adapter as stopped
1182 //
1183 pMode->State = EfiSimpleNetworkStopped;
1184 Status = EFI_SUCCESS;
1185 }
1186 else {
1187 Status = EFI_UNSUPPORTED;
1188 }
1189 }
1190 else {
1191 Status = EFI_NOT_STARTED;
1192 }
1193 }
1194 else {
1195 Status = EFI_INVALID_PARAMETER;
1196 }
1197
1198 //
1199 // Return the operation status
1200 //
1201 DBG_EXIT_STATUS ( Status );
1202 return Status;
1203 }
1204
1205
1206 /**
1207 This function releases the memory buffers assigned in the Initialize() call.
1208 Pending transmits and receives are lost, and interrupts are cleared and disabled.
1209 After this call, only Initialize() and Stop() calls may be used.
1210
1211 @param [in] pSimpleNetwork Protocol instance pointer
1212
1213 @retval EFI_SUCCESS This operation was successful.
1214 @retval EFI_NOT_STARTED The network interface was not started.
1215 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
1216 EFI_SIMPLE_NETWORK_PROTOCOL structure.
1217 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1218 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
1219
1220 **/
1221 EFI_STATUS
1222 EFIAPI
1223 SN_Shutdown (
1224 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork
1225 )
1226 {
1227 EFI_SIMPLE_NETWORK_MODE * pMode;
1228 UINT32 RxFilter;
1229 EFI_STATUS Status;
1230
1231 DBG_ENTER ( );
1232
1233 //
1234 // Verify the parameters
1235 //
1236 if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
1237 //
1238 // Determine if the interface is already started
1239 //
1240 pMode = pSimpleNetwork->Mode;
1241 if ( EfiSimpleNetworkInitialized == pMode->State ) {
1242 //
1243 // Stop the adapter
1244 //
1245 RxFilter = pMode->ReceiveFilterSetting;
1246 pMode->ReceiveFilterSetting = 0;
1247 Status = SN_Reset ( pSimpleNetwork, FALSE );
1248 pMode->ReceiveFilterSetting = RxFilter;
1249 if ( !EFI_ERROR ( Status )) {
1250 //
1251 // Release the resources acquired by SN_Initialize
1252 //
1253
1254 //
1255 // Update the network state
1256 //
1257 pMode->State = EfiSimpleNetworkStarted;
1258 }
1259 }
1260 else {
1261 Status = EFI_NOT_STARTED;
1262 }
1263 }
1264 else {
1265 Status = EFI_INVALID_PARAMETER;
1266 }
1267
1268 //
1269 // Return the operation status
1270 //
1271 DBG_EXIT_STATUS ( Status );
1272 return Status;
1273 }
1274
1275
1276 /**
1277 Send a packet over the network.
1278
1279 This function places the packet specified by Header and Buffer on
1280 the transmit queue. This function performs a non-blocking transmit
1281 operation. When the transmit is complete, the buffer is returned
1282 via the GetStatus() call.
1283
1284 This routine calls ::Ax88772Rx to empty the network adapter of
1285 receive packets. The routine then passes the transmit packet
1286 to the network adapter.
1287
1288 @param [in] pSimpleNetwork Protocol instance pointer
1289 @param [in] HeaderSize The size, in bytes, of the media header to be filled in by
1290 the Transmit() function. If HeaderSize is non-zero, then
1291 it must be equal to SimpleNetwork->Mode->MediaHeaderSize
1292 and DestAddr and Protocol parameters must not be NULL.
1293 @param [in] BufferSize The size, in bytes, of the entire packet (media header and
1294 data) to be transmitted through the network interface.
1295 @param [in] pBuffer A pointer to the packet (media header followed by data) to
1296 to be transmitted. This parameter can not be NULL. If
1297 HeaderSize is zero, then the media header is Buffer must
1298 already be filled in by the caller. If HeaderSize is nonzero,
1299 then the media header will be filled in by the Transmit()
1300 function.
1301 @param [in] pSrcAddr The source HW MAC address. If HeaderSize is zero, then
1302 this parameter is ignored. If HeaderSize is nonzero and
1303 SrcAddr is NULL, then SimpleNetwork->Mode->CurrentAddress
1304 is used for the source HW MAC address.
1305 @param [in] pDestAddr The destination HW MAC address. If HeaderSize is zero, then
1306 this parameter is ignored.
1307 @param [in] pProtocol The type of header to build. If HeaderSize is zero, then
1308 this parameter is ignored.
1309
1310 @retval EFI_SUCCESS This operation was successful.
1311 @retval EFI_NOT_STARTED The network interface was not started.
1312 @retval EFI_NOT_READY The network interface is too busy to accept this transmit request.
1313 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
1314 @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
1315 EFI_SIMPLE_NETWORK_PROTOCOL structure.
1316 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1317
1318 **/
1319 EFI_STATUS
1320 EFIAPI
1321 SN_Transmit (
1322 IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
1323 IN UINTN HeaderSize,
1324 IN UINTN BufferSize,
1325 IN VOID * pBuffer,
1326 IN EFI_MAC_ADDRESS * pSrcAddr,
1327 IN EFI_MAC_ADDRESS * pDestAddr,
1328 IN UINT16 * pProtocol
1329 )
1330 {
1331 RX_TX_PACKET Packet;
1332 ETHERNET_HEADER * pHeader;
1333 EFI_SIMPLE_NETWORK_MODE * pMode;
1334 NIC_DEVICE * pNicDevice;
1335 EFI_USB_IO_PROTOCOL * pUsbIo;
1336 EFI_STATUS Status;
1337 EFI_TPL TplPrevious;
1338 UINTN TransferLength;
1339 UINT32 TransferStatus;
1340 UINT16 Type;
1341
1342 DBG_ENTER ( );
1343
1344 //
1345 // Verify the parameters
1346 //
1347 if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
1348 //
1349 // The interface must be running
1350 //
1351 pMode = pSimpleNetwork->Mode;
1352 if ( EfiSimpleNetworkInitialized == pMode->State ) {
1353 //
1354 // Synchronize with Ax88772Timer
1355 //
1356 VERIFY_TPL ( TPL_AX88772 );
1357 TplPrevious = gBS->RaiseTPL ( TPL_AX88772 );
1358
1359 //
1360 // Update the link status
1361 //
1362 pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
1363 Ax88772Rx ( pNicDevice, FALSE );
1364 pMode->MediaPresent = pNicDevice->bLinkUp;
1365
1366 //
1367 // Release the synchronization with Ax88772Timer
1368 //
1369 gBS->RestoreTPL ( TplPrevious );
1370 if ( pMode->MediaPresent ) {
1371 //
1372 // Copy the packet into the USB buffer
1373 //
1374 CopyMem ( &Packet.Data[0], pBuffer, BufferSize );
1375 Packet.Length = (UINT16) BufferSize;
1376
1377 //
1378 // Transmit the packet
1379 //
1380 pHeader = (ETHERNET_HEADER *) &Packet.Data[0];
1381 if ( 0 != HeaderSize ) {
1382 if ( NULL != pDestAddr ) {
1383 CopyMem ( &pHeader->dest_addr, pDestAddr, PXE_HWADDR_LEN_ETHER );
1384 }
1385 if ( NULL != pSrcAddr ) {
1386 CopyMem ( &pHeader->src_addr, pSrcAddr, PXE_HWADDR_LEN_ETHER );
1387 }
1388 else {
1389 CopyMem ( &pHeader->src_addr, &pMode->CurrentAddress.Addr[0], PXE_HWADDR_LEN_ETHER );
1390 }
1391 if ( NULL != pProtocol ) {
1392 Type = *pProtocol;
1393 }
1394 else {
1395 Type = Packet.Length;
1396 }
1397 Type = (UINT16)(( Type >> 8 ) | ( Type << 8 ));
1398 pHeader->type = Type;
1399 }
1400 if ( Packet.Length < MIN_ETHERNET_PKT_SIZE ) {
1401 Packet.Length = MIN_ETHERNET_PKT_SIZE;
1402 ZeroMem ( &Packet.Data[ BufferSize ],
1403 Packet.Length - BufferSize );
1404 }
1405 DEBUG (( DEBUG_TX | DEBUG_INFO,
1406 "TX: %02x-%02x-%02x-%02x-%02x-%02x %02x-%02x-%02x-%02x-%02x-%02x %02x-%02x %d bytes\r\n",
1407 Packet.Data[0],
1408 Packet.Data[1],
1409 Packet.Data[2],
1410 Packet.Data[3],
1411 Packet.Data[4],
1412 Packet.Data[5],
1413 Packet.Data[6],
1414 Packet.Data[7],
1415 Packet.Data[8],
1416 Packet.Data[9],
1417 Packet.Data[10],
1418 Packet.Data[11],
1419 Packet.Data[12],
1420 Packet.Data[13],
1421 Packet.Length ));
1422 Packet.LengthBar = ~Packet.Length;
1423 TransferLength = sizeof ( Packet.Length )
1424 + sizeof ( Packet.LengthBar )
1425 + Packet.Length;
1426
1427 //
1428 // Work around USB bus driver bug where a timeout set by receive
1429 // succeeds but the timeout expires immediately after, causing the
1430 // transmit operation to timeout.
1431 //
1432 pUsbIo = pNicDevice->pUsbIo;
1433 Status = pUsbIo->UsbBulkTransfer ( pUsbIo,
1434 BULK_OUT_ENDPOINT,
1435 &Packet.Length,
1436 &TransferLength,
1437 0xfffffffe,
1438 &TransferStatus );
1439 if ( !EFI_ERROR ( Status )) {
1440 Status = TransferStatus;
1441 }
1442 if (( !EFI_ERROR ( Status ))
1443 && ( TransferLength != (UINTN)( Packet.Length + 4 ))) {
1444 Status = EFI_WARN_WRITE_FAILURE;
1445 }
1446 if ( EFI_SUCCESS == Status ) {
1447 pNicDevice->pTxBuffer = pBuffer;
1448 }
1449 else {
1450 DEBUG (( DEBUG_ERROR | DEBUG_INFO,
1451 "Ax88772 USB transmit error, TransferLength: %d, Status: %r\r\n",
1452 sizeof ( Packet.Length ) + Packet.Length,
1453 Status ));
1454 //
1455 // Reset the controller to fix the error
1456 //
1457 if ( EFI_DEVICE_ERROR == Status ) {
1458 SN_Reset ( pSimpleNetwork, FALSE );
1459 }
1460 }
1461 }
1462 else {
1463 //
1464 // No packets available.
1465 //
1466 Status = EFI_NOT_READY;
1467 }
1468 }
1469 else {
1470 Status = EFI_NOT_STARTED;
1471 }
1472 }
1473 else {
1474 DEBUG (( DEBUG_ERROR | DEBUG_INFO,
1475 "Ax88772 invalid transmit parameter\r\n"
1476 " 0x%08x: HeaderSize\r\n"
1477 " 0x%08x: BufferSize\r\n"
1478 " 0x%08x: Buffer\r\n"
1479 " 0x%08x: SrcAddr\r\n"
1480 " 0x%08x: DestAddr\r\n"
1481 " 0x%04x: Protocol\r\n",
1482 HeaderSize,
1483 BufferSize,
1484 pBuffer,
1485 pSrcAddr,
1486 pDestAddr,
1487 pProtocol ));
1488 Status = EFI_INVALID_PARAMETER;
1489 }
1490
1491 //
1492 // Return the operation status
1493 //
1494 DBG_EXIT_STATUS ( Status );
1495 return Status;
1496 }