3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
27 #include <Protocol/SimpleNetwork.h>
28 #include <Protocol/PciIo.h>
29 #include <Protocol/NetworkInterfaceIdentifier.h>
30 #include <Protocol/DevicePath.h>
32 #include <Library/DebugLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/BaseLib.h>
37 #include <Library/UefiLib.h>
38 #include <Library/MemoryAllocationLib.h>
40 #include <IndustryStandard/Pci22.h>
42 #define FOUR_GIGABYTES (UINT64) 0x100000000ULL
45 #define SNP_DRIVER_SIGNATURE EFI_SIGNATURE_32 ('s', 'n', 'd', 's')
46 #define MAX_MAP_LENGTH 100
48 #define PCI_BAR_IO_MASK 0x00000003
49 #define PCI_BAR_IO_MODE 0x00000001
51 #define PCI_BAR_MEM_MASK 0x0000000F
52 #define PCI_BAR_MEM_MODE 0x00000000
53 #define PCI_BAR_MEM_64BIT 0x00000004
59 EFI_SIMPLE_NETWORK_PROTOCOL snp
;
60 EFI_SIMPLE_NETWORK_MODE mode
;
62 EFI_HANDLE device_handle
;
63 EFI_DEVICE_PATH_PROTOCOL
*device_path
;
66 // Local instance data needed by SNP driver
68 // Pointer to S/W UNDI API entry point
69 // This will be NULL for H/W UNDI
71 EFI_STATUS (*issue_undi32_command
) (UINT64 cdb
);
76 // undi interface number, if one undi manages more nics
81 // Allocated tx/rx buffer that was passed to UNDI Initialize.
86 // mappable buffers for receive and fill header for undi3.0
87 // these will be used if the user buffers are above 4GB limit (instead of
88 // mapping the user buffers)
91 VOID
*ReceiveBufUnmap
;
93 VOID
*FillHdrBufUnmap
;
95 EFI_PCI_IO_PROTOCOL
*IoFncs
;
100 // Buffers for command descriptor block, command parameter block
109 // UNDI structure, we need to remember the init info for a long time!
111 PXE_DB_GET_INIT_INFO init_info
;
113 VOID
*SnpDriverUnmap
;
115 // when ever we map an address, we must remember it's address and the un-map
116 // cookie so that we can unmap later
119 EFI_PHYSICAL_ADDRESS virt
;
121 } map_list
[MAX_MAP_LENGTH
];
125 #define EFI_SIMPLE_NETWORK_DEV_FROM_THIS(a) CR (a, SNP_DRIVER, snp, SNP_DRIVER_SIGNATURE)
130 extern EFI_COMPONENT_NAME_PROTOCOL gSimpleNetworkComponentName
;
131 extern EFI_COMPONENT_NAME2_PROTOCOL gSimpleNetworkComponentName2
;
134 // Virtual to physical mapping for all UNDI 3.0s.
136 extern struct s_v2p
{
140 EFI_PHYSICAL_ADDRESS paddr
;
148 EFI_PCI_IO_PROTOCOL_OPERATION type
,
169 snp_undi32_callback_block_30 (
176 snp_undi32_callback_delay_30 (
177 IN UINT64 MicroSeconds
183 snp_undi32_callback_memio_30 (
184 IN UINT8 ReadOrWrite
,
186 IN UINT64 MemOrPortAddress
,
187 IN OUT UINT64 BufferPtr
193 snp_undi32_callback_v2p_30 (
195 IN OUT UINT64 DeviceAddrPtr
201 snp_undi32_callback_block (
209 snp_undi32_callback_delay (
211 IN UINT64 MicroSeconds
217 snp_undi32_callback_memio (
219 IN UINT8 ReadOrWrite
,
221 IN UINT64 MemOrPortAddr
,
222 IN OUT UINT64 BufferPtr
228 snp_undi32_callback_map (
233 IN OUT UINT64 DeviceAddrPtr
239 snp_undi32_callback_unmap (
244 IN UINT64 DeviceAddr
// not a pointer to device address
250 snp_undi32_callback_sync (
255 IN UINT64 DeviceAddr
// not a pointer to device address
263 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this
271 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this
278 snp_undi32_initialize (
279 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
280 IN UINTN extra_rx_buffer_size OPTIONAL
,
281 IN UINTN extra_tx_buffer_size OPTIONAL
289 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
290 IN BOOLEAN ExtendedVerification
297 snp_undi32_shutdown (
298 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this
305 snp_undi32_receive_filters (
306 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
309 IN BOOLEAN reset_mcast_filter
,
310 IN UINTN mcast_filter_count OPTIONAL
,
311 IN EFI_MAC_ADDRESS
* mcast_filter OPTIONAL
318 snp_undi32_station_address (
319 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
321 IN EFI_MAC_ADDRESS
*new OPTIONAL
328 snp_undi32_statistics (
329 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
331 IN OUT UINTN
*statistics_size OPTIONAL
,
332 IN OUT EFI_NETWORK_STATISTICS
* statistics_table OPTIONAL
339 snp_undi32_mcast_ip_to_mac (
340 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
342 IN EFI_IP_ADDRESS
*IP
,
343 OUT EFI_MAC_ADDRESS
*MAC
351 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
352 IN BOOLEAN read_write
,
354 IN UINTN buffer_size
,
362 snp_undi32_get_status (
363 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
364 OUT UINT32
*interrupt_status OPTIONAL
,
365 OUT VOID
**tx_buffer OPTIONAL
372 snp_undi32_transmit (
373 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
374 IN UINTN header_size
,
375 IN UINTN buffer_size
,
377 IN EFI_MAC_ADDRESS
* src_addr OPTIONAL
,
378 IN EFI_MAC_ADDRESS
* dest_addr OPTIONAL
,
379 IN UINT16
*protocol OPTIONAL
387 IN EFI_SIMPLE_NETWORK_PROTOCOL
* this,
388 OUT UINTN
*header_size OPTIONAL
,
389 IN OUT UINTN
*buffer_size
,
391 OUT EFI_MAC_ADDRESS
* src_addr OPTIONAL
,
392 OUT EFI_MAC_ADDRESS
* dest_addr OPTIONAL
,
393 OUT UINT16
*protocol OPTIONAL
399 (*issue_undi32_command
) (
410 Install all the driver protocol
412 @param ImageHandle Driver image handle
413 @param SystemTable System services table
415 @retval EFI_SUCEESS Initialization routine has found UNDI hardware, loaded it's
416 ROM, and installed a notify event for the Network
417 Indentifier Interface Protocol successfully.
418 @retval Other Return value from HandleProtocol for DeviceIoProtocol or
424 InitializeSnpNiiDriver (
425 IN EFI_HANDLE ImageHandle
,
426 IN EFI_SYSTEM_TABLE
*SystemTable
430 #define SNP_MEM_PAGES(x) (((x) - 1) / 4096 + 1)