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