]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/shutdown.c
Import SnpDxe, Tcp4Dxe, Udp4Dxe and MnpDxe.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / shutdown.c
1 /** @file
2 Copyright (c) 2004 - 2007, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 Module name:
12 shutdown.c
13
14 Abstract:
15
16 Revision history:
17 2000-Feb-14 M(f)J Genesis.
18
19 **/
20
21 #include "Snp.h"
22
23
24 /**
25 this routine calls undi to shut down the interface.
26
27 @param snp pointer to snp driver structure
28
29
30 **/
31 EFI_STATUS
32 pxe_shutdown (
33 IN SNP_DRIVER *snp
34 )
35 {
36 snp->cdb.OpCode = PXE_OPCODE_SHUTDOWN;
37 snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED;
38 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
39 snp->cdb.DBsize = PXE_DBSIZE_NOT_USED;
40 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
41 snp->cdb.DBaddr = PXE_DBADDR_NOT_USED;
42 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;
43 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
44 snp->cdb.IFnum = snp->if_num;
45 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
46
47 //
48 // Issue UNDI command and check result.
49 //
50 DEBUG ((EFI_D_NET, "\nsnp->undi.shutdown() "));
51
52 (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);
53
54 if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {
55 //
56 // UNDI could not be shutdown. Return UNDI error.
57 //
58 DEBUG ((EFI_D_WARN, "\nsnp->undi.shutdown() %xh:%xh\n", snp->cdb.StatFlags, snp->cdb.StatCode));
59
60 return EFI_DEVICE_ERROR;
61 }
62 //
63 // Free allocated memory.
64 //
65 if (snp->tx_rx_buffer != NULL) {
66 snp->IoFncs->FreeBuffer (
67 snp->IoFncs,
68 SNP_MEM_PAGES (snp->tx_rx_bufsize),
69 (VOID *) snp->tx_rx_buffer
70 );
71 }
72
73 snp->tx_rx_buffer = NULL;
74 snp->tx_rx_bufsize = 0;
75
76 return EFI_SUCCESS;
77 }
78
79
80 /**
81 This is the SNP interface routine for shutting down the interface
82 This routine basically retrieves snp structure, checks the SNP state and
83 calls the pxe_shutdown routine to actually do the undi shutdown
84
85 @param this context pointer
86
87
88 **/
89 EFI_STATUS
90 EFIAPI
91 snp_undi32_shutdown (
92 IN EFI_SIMPLE_NETWORK_PROTOCOL *this
93 )
94 {
95 SNP_DRIVER *snp;
96 EFI_STATUS Status;
97 EFI_TPL OldTpl;
98
99 //
100 //
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 //
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 //
127 //
128 Status = pxe_shutdown (snp);
129
130 snp->mode.State = EfiSimpleNetworkStarted;
131 snp->mode.ReceiveFilterSetting = 0;
132
133 snp->mode.MCastFilterCount = 0;
134 snp->mode.ReceiveFilterSetting = 0;
135 ZeroMem (snp->mode.MCastFilter, sizeof snp->mode.MCastFilter);
136 CopyMem (
137 &snp->mode.CurrentAddress,
138 &snp->mode.PermanentAddress,
139 sizeof (EFI_MAC_ADDRESS)
140 );
141
142 gBS->CloseEvent (snp->snp.WaitForPacket);
143
144 ON_EXIT:
145 gBS->RestoreTPL (OldTpl);
146
147 return Status;
148 }