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