Home | History | Annotate | Download | only in SnpDxe
      1 /** @file
      2     Implementation of shuting down a network adapter.
      3 
      4 Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
      5 This program and the accompanying materials are licensed
      6 and made available under the terms and conditions of the BSD License which
      7 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 "Snp.h"
     16 
     17 
     18 /**
     19   Call UNDI to shut down the interface.
     20 
     21   @param  Snp   Pointer to snp driver structure.
     22 
     23   @retval EFI_SUCCESS        UNDI is shut down successfully.
     24   @retval EFI_DEVICE_ERROR   UNDI could not be shut down.
     25 
     26 **/
     27 EFI_STATUS
     28 PxeShutdown (
     29   IN SNP_DRIVER *Snp
     30   )
     31 {
     32   Snp->Cdb.OpCode     = PXE_OPCODE_SHUTDOWN;
     33   Snp->Cdb.OpFlags    = PXE_OPFLAGS_NOT_USED;
     34   Snp->Cdb.CPBsize    = PXE_CPBSIZE_NOT_USED;
     35   Snp->Cdb.DBsize     = PXE_DBSIZE_NOT_USED;
     36   Snp->Cdb.CPBaddr    = PXE_CPBADDR_NOT_USED;
     37   Snp->Cdb.DBaddr     = PXE_DBADDR_NOT_USED;
     38   Snp->Cdb.StatCode   = PXE_STATCODE_INITIALIZE;
     39   Snp->Cdb.StatFlags  = PXE_STATFLAGS_INITIALIZE;
     40   Snp->Cdb.IFnum      = Snp->IfNum;
     41   Snp->Cdb.Control    = PXE_CONTROL_LAST_CDB_IN_LIST;
     42 
     43   //
     44   // Issue UNDI command and check result.
     45   //
     46   DEBUG ((EFI_D_NET, "\nsnp->undi.shutdown()  "));
     47 
     48   (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
     49 
     50   if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {
     51     //
     52     // UNDI could not be shutdown. Return UNDI error.
     53     //
     54     DEBUG ((EFI_D_WARN, "\nsnp->undi.shutdown()  %xh:%xh\n", Snp->Cdb.StatFlags, Snp->Cdb.StatCode));
     55 
     56     return EFI_DEVICE_ERROR;
     57   }
     58   //
     59   // Free allocated memory.
     60   //
     61   if (Snp->TxRxBuffer != NULL) {
     62     Snp->PciIo->FreeBuffer (
     63                   Snp->PciIo,
     64                   SNP_MEM_PAGES (Snp->TxRxBufferSize),
     65                   (VOID *) Snp->TxRxBuffer
     66                   );
     67   }
     68 
     69   Snp->TxRxBuffer      = NULL;
     70   Snp->TxRxBufferSize  = 0;
     71 
     72   return EFI_SUCCESS;
     73 }
     74 
     75 
     76 /**
     77   Resets a network adapter and leaves it in a state that is safe for another
     78   driver to initialize.
     79 
     80   This function releases the memory buffers assigned in the Initialize() call.
     81   Pending transmits and receives are lost, and interrupts are cleared and disabled.
     82   After this call, only the Initialize() and Stop() calls may be used. If the
     83   network interface was successfully shutdown, then EFI_SUCCESS will be returned.
     84   If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
     85 
     86   @param  This  A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
     87 
     88   @retval EFI_SUCCESS           The network interface was shutdown.
     89   @retval EFI_NOT_STARTED       The network interface has not been started.
     90   @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
     91                                 EFI_SIMPLE_NETWORK_PROTOCOL structure.
     92   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
     93 
     94 **/
     95 EFI_STATUS
     96 EFIAPI
     97 SnpUndi32Shutdown (
     98   IN EFI_SIMPLE_NETWORK_PROTOCOL *This
     99   )
    100 {
    101   SNP_DRIVER  *Snp;
    102   EFI_STATUS  Status;
    103   EFI_TPL     OldTpl;
    104 
    105   //
    106   // Get pointer to SNP driver instance for *This.
    107   //
    108   if (This == NULL) {
    109     return EFI_INVALID_PARAMETER;
    110   }
    111 
    112   Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
    113 
    114   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
    115 
    116   //
    117   // Return error if the SNP is not initialized.
    118   //
    119   switch (Snp->Mode.State) {
    120   case EfiSimpleNetworkInitialized:
    121     break;
    122 
    123   case EfiSimpleNetworkStopped:
    124     Status = EFI_NOT_STARTED;
    125     goto ON_EXIT;
    126 
    127   default:
    128     Status = EFI_DEVICE_ERROR;
    129     goto ON_EXIT;
    130   }
    131 
    132   Status                          = PxeShutdown (Snp);
    133 
    134   Snp->Mode.State                 = EfiSimpleNetworkStarted;
    135   Snp->Mode.ReceiveFilterSetting  = 0;
    136 
    137   Snp->Mode.MCastFilterCount      = 0;
    138   Snp->Mode.ReceiveFilterSetting  = 0;
    139   ZeroMem (Snp->Mode.MCastFilter, sizeof Snp->Mode.MCastFilter);
    140   CopyMem (
    141     &Snp->Mode.CurrentAddress,
    142     &Snp->Mode.PermanentAddress,
    143     sizeof (EFI_MAC_ADDRESS)
    144     );
    145 
    146   gBS->CloseEvent (Snp->Snp.WaitForPacket);
    147 
    148 ON_EXIT:
    149   gBS->RestoreTPL (OldTpl);
    150 
    151   return Status;
    152 }
    153