1 /** @file
2     Implementation of resetting a network adapter.
3 
4 Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under the
6 terms and conditions of the BSD License which accompanies this distribution. The
7 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 reset the NIC.
20 
21   @param  Snp                 Pointer to the snp driver structure.
22 
23   @return EFI_SUCCESSFUL      The NIC was reset.
24   @retval EFI_DEVICE_ERROR    The NIC cannot be reset.
25 
26 **/
27 EFI_STATUS
PxeReset(SNP_DRIVER * Snp)28 PxeReset (
29   SNP_DRIVER *Snp
30   )
31 {
32   Snp->Cdb.OpCode     = PXE_OPCODE_RESET;
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.reset()  "));
47 
48   (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
49 
50   if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {
51     DEBUG (
52       (EFI_D_WARN,
53       "\nsnp->undi32.reset()  %xh:%xh\n",
54       Snp->Cdb.StatFlags,
55       Snp->Cdb.StatCode)
56       );
57 
58     //
59     // UNDI could not be reset. Return UNDI error.
60     //
61     return EFI_DEVICE_ERROR;
62   }
63 
64   return EFI_SUCCESS;
65 }
66 
67 
68 /**
69   Resets a network adapter and reinitializes it with the parameters that were
70   provided in the previous call to Initialize().
71 
72   This function resets a network adapter and reinitializes it with the parameters
73   that were provided in the previous call to Initialize(). The transmit and
74   receive queues are emptied and all pending interrupts are cleared.
75   Receive filters, the station address, the statistics, and the multicast-IP-to-HW
76   MAC addresses are not reset by this call. If the network interface was
77   successfully reset, then EFI_SUCCESS will be returned. If the driver has not
78   been initialized, EFI_DEVICE_ERROR will be returned.
79 
80   @param This                 A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
81   @param ExtendedVerification Indicates that the driver may perform a more
82                               exhaustive verification operation of the device
83                               during reset.
84 
85   @retval EFI_SUCCESS           The network interface was reset.
86   @retval EFI_NOT_STARTED       The network interface has not been started.
87   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
88   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
89   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
90 
91 **/
92 EFI_STATUS
93 EFIAPI
SnpUndi32Reset(IN EFI_SIMPLE_NETWORK_PROTOCOL * This,IN BOOLEAN ExtendedVerification)94 SnpUndi32Reset (
95   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
96   IN BOOLEAN                     ExtendedVerification
97   )
98 {
99   SNP_DRIVER  *Snp;
100   EFI_TPL     OldTpl;
101   EFI_STATUS  Status;
102 
103   //
104   // Resolve Warning 4 unreferenced parameter problem
105   //
106   ExtendedVerification = 0;
107   DEBUG ((EFI_D_WARN, "ExtendedVerification = %d is not implemented!\n", ExtendedVerification));
108 
109   if (This == NULL) {
110     return EFI_INVALID_PARAMETER;
111   }
112 
113   Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
114 
115   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
116 
117   switch (Snp->Mode.State) {
118   case EfiSimpleNetworkInitialized:
119     break;
120 
121   case EfiSimpleNetworkStopped:
122     Status = EFI_NOT_STARTED;
123     goto ON_EXIT;
124 
125   default:
126     Status = EFI_DEVICE_ERROR;
127     goto ON_EXIT;
128   }
129 
130   Status = PxeReset (Snp);
131 
132 ON_EXIT:
133   gBS->RestoreTPL (OldTpl);
134 
135   return Status;
136 }
137