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