]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/get_status.c
Import SnpDxe, Tcp4Dxe, Udp4Dxe and MnpDxe.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / get_status.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 get_status.c
13
14 Abstract:
15
16 Revision history:
17 2000-Feb-03 M(f)J Genesis.
18
19 **/
20
21 #include "Snp.h"
22
23 STATIC
24 /**
25 this routine calls undi to get the status of the interrupts, get the list of
26 transmit buffers that completed transmitting!
27
28 @param snp pointer to snp driver structure
29 @param InterruptStatusPtr a non null pointer gets the interrupt status
30 @param TransmitBufferListPtrs a non null ointer gets the list of pointers of
31 previously transmitted buffers whose
32 transmission was completed asynchrnously.
33
34
35 **/
36 EFI_STATUS
37 pxe_getstatus (
38 SNP_DRIVER *snp,
39 UINT32 *InterruptStatusPtr,
40 VOID **TransmitBufferListPtr
41 )
42 {
43 PXE_DB_GET_STATUS *db;
44 UINT16 InterruptFlags;
45 UINT64 TempData;
46
47 db = snp->db;
48 snp->cdb.OpCode = PXE_OPCODE_GET_STATUS;
49
50 snp->cdb.OpFlags = 0;
51
52 if (TransmitBufferListPtr != NULL) {
53 snp->cdb.OpFlags |= PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS;
54 }
55
56 if (InterruptStatusPtr != NULL) {
57 snp->cdb.OpFlags |= PXE_OPFLAGS_GET_INTERRUPT_STATUS;
58 }
59
60 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
61 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;
62
63 //
64 // size DB for return of one buffer
65 //
66 snp->cdb.DBsize = (UINT16) (((UINT16) (sizeof (PXE_DB_GET_STATUS)) - (UINT16) (sizeof db->TxBuffer)) + (UINT16) (sizeof db->TxBuffer[0]));
67
68 snp->cdb.DBaddr = (UINT64)(UINTN) db;
69
70 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;
71 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
72 snp->cdb.IFnum = snp->if_num;
73 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
74
75 //
76 // Issue UNDI command and check result.
77 //
78 DEBUG ((EFI_D_NET, "\nsnp->undi.get_status() "));
79
80 (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);
81
82 if (snp->cdb.StatCode != EFI_SUCCESS) {
83 DEBUG (
84 (EFI_D_NET,
85 "\nsnp->undi.get_status() %xh:%xh\n",
86 snp->cdb.StatFlags,
87 snp->cdb.StatFlags)
88 );
89
90 return EFI_DEVICE_ERROR;
91 }
92 //
93 // report the values back..
94 //
95 if (InterruptStatusPtr != NULL) {
96 InterruptFlags = (UINT16) (snp->cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_INTERRUPT_MASK);
97
98 *InterruptStatusPtr = 0;
99
100 if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_RECEIVE) {
101 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;
102 }
103
104 if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_TRANSMIT) {
105 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;
106 }
107
108 if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_COMMAND) {
109 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;
110 }
111
112 if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_SOFTWARE) {
113 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;
114 }
115
116 }
117
118 if (TransmitBufferListPtr != NULL) {
119 *TransmitBufferListPtr =
120 (
121 (snp->cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN) ||
122 (snp->cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY)
123 ) ? 0 : (VOID *) (UINTN) db->TxBuffer[0];
124
125 TempData = (UINT64) (UINTN) (*TransmitBufferListPtr);
126 if (snp->IsOldUndi && (TempData >= FOUR_GIGABYTES)) {
127 del_v2p ((VOID *) (UINTN) (db->TxBuffer[0]));
128 }
129 }
130
131 return EFI_SUCCESS;
132 }
133
134
135 /**
136 This is the SNP interface routine for getting the status
137 This routine basically retrieves snp structure, checks the SNP state and
138 calls the pxe_getstatus routine to actually get the undi status
139
140 @param this context pointer
141 @param InterruptStatusPtr a non null pointer gets the interrupt status
142 @param TransmitBufferListPtrs a non null ointer gets the list of pointers of
143 previously transmitted buffers whose
144 transmission was completed asynchrnously.
145
146
147 **/
148 EFI_STATUS
149 EFIAPI
150 snp_undi32_get_status (
151 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,
152 OUT UINT32 *InterruptStatusPtr OPTIONAL,
153 OUT VOID **TransmitBufferListPtr OPTIONAL
154 )
155 {
156 SNP_DRIVER *snp;
157 EFI_TPL OldTpl;
158 EFI_STATUS Status;
159
160 if (this == NULL) {
161 return EFI_INVALID_PARAMETER;
162 }
163
164 if (InterruptStatusPtr == NULL && TransmitBufferListPtr == NULL) {
165 return EFI_INVALID_PARAMETER;
166 }
167
168 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
169
170 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
171
172 if (snp == NULL) {
173 return EFI_DEVICE_ERROR;
174 }
175
176 switch (snp->mode.State) {
177 case EfiSimpleNetworkInitialized:
178 break;
179
180 case EfiSimpleNetworkStopped:
181 Status = EFI_NOT_STARTED;
182 goto ON_EXIT;
183
184 default:
185 Status = EFI_DEVICE_ERROR;
186 goto ON_EXIT;
187 }
188
189 Status = pxe_getstatus (snp, InterruptStatusPtr, TransmitBufferListPtr);
190
191 ON_EXIT:
192 gBS->RestoreTPL (OldTpl);
193
194 return Status;
195 }