Home | History | Annotate | Download | only in Lan9118Dxe
      1 /** @file
      2 *
      3 *  Copyright (c) 2012-2014, ARM Limited. All rights reserved.
      4 *
      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 #ifndef __LAN9118_DXE_H__
     16 #define __LAN9118_DXE_H__
     17 
     18 #include <Uefi.h>
     19 #include <Uefi/UefiSpec.h>
     20 #include <Base.h>
     21 
     22 // Protocols used by this driver
     23 #include <Protocol/SimpleNetwork.h>
     24 #include <Protocol/ComponentName2.h>
     25 #include <Protocol/PxeBaseCode.h>
     26 #include <Protocol/DevicePath.h>
     27 
     28 // Libraries used by this driver
     29 #include <Library/UefiLib.h>
     30 #include <Library/DebugLib.h>
     31 #include <Library/UefiBootServicesTableLib.h>
     32 #include <Library/MemoryAllocationLib.h>
     33 #include <Library/IoLib.h>
     34 #include <Library/PcdLib.h>
     35 #include <Library/NetLib.h>
     36 #include <Library/DevicePathLib.h>
     37 
     38 #include "Lan9118DxeUtil.h"
     39 #include "Lan9118DxeHw.h"
     40 
     41 #define LAN9118_STALL     2
     42 
     43 #define LAN9118_DEFAULT_MAC_ADDRL     0x00F70200
     44 #define LAN9118_DEFAULT_MAC_ADDRH     0x00009040
     45 
     46 #define LAN9118_TX_DATA_SIZE          4608
     47 #define LAN9118_TX_STATUS_SIZE        512
     48 #define LAN9118_RX_DATA_SIZE          10560
     49 #define LAN9118_RX_STATUS_SIZE        704
     50 
     51 #define LAN9118_TX_RING_NUM_ENTRIES 32
     52 
     53 /*------------------------------------------------------------------------------
     54   LAN9118 Information Structure
     55 ------------------------------------------------------------------------------*/
     56 
     57 typedef struct {
     58   // Driver signature
     59   UINT32            Signature;
     60   EFI_HANDLE        ControllerHandle;
     61 
     62   // EFI SNP protocol instances
     63   EFI_SIMPLE_NETWORK_PROTOCOL Snp;
     64   EFI_SIMPLE_NETWORK_MODE SnpMode;
     65 
     66   // EFI Snp statistics instance
     67   EFI_NETWORK_STATISTICS Stats;
     68 
     69   // Saved transmitted buffers so we can notify consumers when packets have been sent.
     70   UINT16  NextPacketTag;
     71   VOID    *TxRing[LAN9118_TX_RING_NUM_ENTRIES];
     72 } LAN9118_DRIVER;
     73 
     74 #define LAN9118_SIGNATURE                       SIGNATURE_32('l', 'a', 'n', '9')
     75 #define INSTANCE_FROM_SNP_THIS(a)               CR(a, LAN9118_DRIVER, Snp, LAN9118_SIGNATURE)
     76 
     77 
     78 /*---------------------------------------------------------------------------------------------------------------------
     79 
     80   UEFI-Compliant functions for EFI_SIMPLE_NETWORK_PROTOCOL
     81 
     82   Refer to the Simple Network Protocol section (21.1) in the UEFI 2.3.1 Specification for related definitions
     83 
     84 ---------------------------------------------------------------------------------------------------------------------*/
     85 
     86 
     87 /*
     88  *  UEFI Start() function
     89  *
     90  *  Parameters:
     91  *
     92  *  @param pobj:  A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
     93  *
     94  *  Description:
     95  *
     96  *  This function starts a network interface. If the network interface successfully starts, then
     97  *  EFI_SUCCESS will be returned.
     98  */
     99 EFI_STATUS
    100 EFIAPI
    101 SnpStart (
    102   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp
    103   );
    104 
    105 /*
    106  *  UEFI Stop() function
    107  *
    108  */
    109 EFI_STATUS
    110 EFIAPI
    111 SnpStop (
    112   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp
    113   );
    114 
    115 /*
    116  *  UEFI Initialize() function
    117  *
    118  */
    119 EFI_STATUS
    120 EFIAPI
    121 SnpInitialize (
    122   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,
    123   IN        UINTN rx_buff_size,
    124   IN        UINTN tx_buff_size
    125   );
    126 
    127 /*
    128  *  UEFI Reset() function
    129  *
    130  */
    131 EFI_STATUS
    132 EFIAPI
    133 SnpReset (
    134   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,
    135   IN        BOOLEAN ext_ver
    136   );
    137 
    138 /*
    139  *  UEFI Shutdown() function
    140  *
    141  */
    142 EFI_STATUS
    143 EFIAPI
    144 SnpShutdown (
    145   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp
    146   );
    147 
    148 /*
    149  *  UEFI ReceiveFilters() function
    150  *
    151  */
    152 EFI_STATUS
    153 EFIAPI
    154 SnpReceiveFilters (
    155   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,
    156   IN        UINT32 enable,
    157   IN        UINT32 disable,
    158   IN        BOOLEAN reset_mfilter,
    159   IN        UINTN num_mfilter,
    160   IN        EFI_MAC_ADDRESS *mfilter
    161   );
    162 
    163 /*
    164  *  UEFI StationAddress() function
    165  *
    166  */
    167 EFI_STATUS
    168 EFIAPI
    169 SnpStationAddress (
    170   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,
    171   IN        BOOLEAN reset,
    172   IN        EFI_MAC_ADDRESS *new_maddr
    173   );
    174 
    175 /*
    176  *  UEFI Statistics() function
    177  *
    178  */
    179 EFI_STATUS
    180 EFIAPI
    181 SnpStatistics (
    182   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,
    183   IN        BOOLEAN reset,
    184   IN  OUT   UINTN *stat_size,
    185       OUT   EFI_NETWORK_STATISTICS *stat_table
    186   );
    187 
    188 /*
    189  *  UEFI MCastIPtoMAC() function
    190  *
    191  */
    192 EFI_STATUS
    193 EFIAPI
    194 SnpMcastIptoMac (
    195   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,
    196   IN        BOOLEAN use_ipv6,
    197   IN        EFI_IP_ADDRESS *ip_addr,
    198       OUT   EFI_MAC_ADDRESS *mac_addr
    199   );
    200 
    201 /*
    202  *  UEFI NvData() function
    203  *
    204  */
    205 EFI_STATUS
    206 EFIAPI
    207 SnpNvData (
    208   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,
    209   IN        BOOLEAN read_write,
    210   IN        UINTN offset,
    211   IN        UINTN buff_size,
    212   IN  OUT   VOID *data
    213   );
    214 
    215 /*
    216  *  UEFI GetStatus() function
    217  *
    218  */
    219 EFI_STATUS
    220 EFIAPI
    221 SnpGetStatus (
    222   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,
    223       OUT   UINT32 *irq_stat  OPTIONAL,
    224       OUT   VOID **tx_buff    OPTIONAL
    225   );
    226 
    227 /*
    228  *  UEFI Transmit() function
    229  *
    230  */
    231 EFI_STATUS
    232 EFIAPI
    233 SnpTransmit (
    234   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,
    235   IN        UINTN hdr_size,
    236   IN        UINTN buff_size,
    237   IN        VOID *data,
    238   IN        EFI_MAC_ADDRESS *src_addr   OPTIONAL,
    239   IN        EFI_MAC_ADDRESS *dest_addr  OPTIONAL,
    240   IN        UINT16 *protocol            OPTIONAL
    241   );
    242 
    243 /*
    244  *  UEFI Receive() function
    245  *
    246  */
    247 EFI_STATUS
    248 EFIAPI
    249 SnpReceive (
    250   IN        EFI_SIMPLE_NETWORK_PROTOCOL* Snp,
    251       OUT   UINTN *hdr_size               OPTIONAL,
    252   IN  OUT   UINTN *buff_size,
    253       OUT   VOID *data,
    254       OUT   EFI_MAC_ADDRESS *src_addr     OPTIONAL,
    255       OUT   EFI_MAC_ADDRESS *dest_addr    OPTIONAL,
    256       OUT   UINT16 *protocol              OPTIONAL
    257   );
    258 
    259 
    260 /*---------------------------------------------------------------------------------------------------------------------
    261 
    262   UEFI-Compliant functions for EFI_COMPONENT_NAME2_PROTOCOL
    263 
    264   Refer to the Component Name Protocol section (10.5) in the UEFI 2.3.1 Specification for related definitions
    265 
    266 ---------------------------------------------------------------------------------------------------------------------*/
    267 
    268 /*
    269  *  UEFI GetDriverName() function
    270  *
    271  */
    272 EFI_STATUS
    273 EFIAPI
    274 SnpGetDriverName (
    275   IN        EFI_COMPONENT_NAME2_PROTOCOL *Snp,
    276   IN        CHAR8 *Lang,
    277       OUT   CHAR16 **DriverName
    278   );
    279 
    280 /*
    281  *  UEFI GetControllerName() function
    282  *
    283  */
    284 EFI_STATUS
    285 EFIAPI
    286 SnpGetControllerName (
    287   IN        EFI_COMPONENT_NAME2_PROTOCOL *Cnp,
    288   IN        EFI_HANDLE ControllerHandle,
    289   IN        EFI_HANDLE ChildHandle            OPTIONAL,
    290   IN        CHAR8 *Lang,
    291       OUT   CHAR16 **ControllerName
    292   );
    293 
    294 /*------------------------------------------------------------------------------
    295   Utility functions
    296 ------------------------------------------------------------------------------*/
    297 
    298 EFI_MAC_ADDRESS
    299 GetCurrentMacAddress (
    300   VOID
    301   );
    302 
    303 #endif // __LAN9118_DXE_H__
    304