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