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