]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/SnpDxe/Get_status.c
Code Scrub:
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Get_status.c
CommitLineData
75d0f44d 1/** @file\r
2Copyright (c) 2004 - 2007, Intel Corporation\r
3All rights reserved. This program and the accompanying materials\r
4are licensed and made available under the terms and conditions of the BSD License\r
5which accompanies this distribution. The full text of the license may be found at\r
6http://opensource.org/licenses/bsd-license.php\r
7\r
8THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
9WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
10\r
11Module name:\r
12 get_status.c\r
13\r
14Abstract:\r
15\r
16Revision history:\r
17 2000-Feb-03 M(f)J Genesis.\r
18\r
19**/\r
20\r
21#include "Snp.h"\r
22\r
75d0f44d 23/**\r
24 this routine calls undi to get the status of the interrupts, get the list of\r
25 transmit buffers that completed transmitting!\r
26\r
27 @param snp pointer to snp driver structure\r
28 @param InterruptStatusPtr a non null pointer gets the interrupt status\r
29 @param TransmitBufferListPtrs a non null ointer gets the list of pointers of\r
30 previously transmitted buffers whose\r
31 transmission was completed asynchrnously.\r
32\r
33\r
34**/\r
35EFI_STATUS\r
36pxe_getstatus (\r
37 SNP_DRIVER *snp,\r
38 UINT32 *InterruptStatusPtr,\r
39 VOID **TransmitBufferListPtr\r
40 )\r
41{\r
42 PXE_DB_GET_STATUS *db;\r
43 UINT16 InterruptFlags;\r
44\r
45 db = snp->db;\r
46 snp->cdb.OpCode = PXE_OPCODE_GET_STATUS;\r
47\r
48 snp->cdb.OpFlags = 0;\r
49\r
50 if (TransmitBufferListPtr != NULL) {\r
51 snp->cdb.OpFlags |= PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS;\r
52 }\r
53\r
54 if (InterruptStatusPtr != NULL) {\r
55 snp->cdb.OpFlags |= PXE_OPFLAGS_GET_INTERRUPT_STATUS;\r
56 }\r
57\r
58 snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
59 snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
60\r
61 //\r
62 // size DB for return of one buffer\r
63 //\r
64 snp->cdb.DBsize = (UINT16) (((UINT16) (sizeof (PXE_DB_GET_STATUS)) - (UINT16) (sizeof db->TxBuffer)) + (UINT16) (sizeof db->TxBuffer[0]));\r
65\r
66 snp->cdb.DBaddr = (UINT64)(UINTN) db;\r
67\r
68 snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
69 snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
70 snp->cdb.IFnum = snp->if_num;\r
71 snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
72\r
73 //\r
74 // Issue UNDI command and check result.\r
75 //\r
76 DEBUG ((EFI_D_NET, "\nsnp->undi.get_status() "));\r
77\r
78 (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r
79\r
80 if (snp->cdb.StatCode != EFI_SUCCESS) {\r
81 DEBUG (\r
82 (EFI_D_NET,\r
83 "\nsnp->undi.get_status() %xh:%xh\n",\r
84 snp->cdb.StatFlags,\r
85 snp->cdb.StatFlags)\r
86 );\r
87\r
88 return EFI_DEVICE_ERROR;\r
89 }\r
90 //\r
91 // report the values back..\r
92 //\r
93 if (InterruptStatusPtr != NULL) {\r
94 InterruptFlags = (UINT16) (snp->cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_INTERRUPT_MASK);\r
95\r
96 *InterruptStatusPtr = 0;\r
97\r
98 if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_RECEIVE) {\r
99 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;\r
100 }\r
101\r
102 if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_TRANSMIT) {\r
103 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;\r
104 }\r
105\r
106 if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_COMMAND) {\r
107 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;\r
108 }\r
109\r
110 if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_SOFTWARE) {\r
111 *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;\r
112 }\r
113\r
114 }\r
115\r
116 if (TransmitBufferListPtr != NULL) {\r
117 *TransmitBufferListPtr =\r
118 (\r
119 (snp->cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN) ||\r
120 (snp->cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY)\r
121 ) ? 0 : (VOID *) (UINTN) db->TxBuffer[0];\r
122\r
123 }\r
124\r
125 return EFI_SUCCESS;\r
126}\r
127\r
128\r
129/**\r
130 This is the SNP interface routine for getting the status\r
131 This routine basically retrieves snp structure, checks the SNP state and\r
132 calls the pxe_getstatus routine to actually get the undi status\r
133\r
134 @param this context pointer\r
135 @param InterruptStatusPtr a non null pointer gets the interrupt status\r
136 @param TransmitBufferListPtrs a non null ointer gets the list of pointers of\r
137 previously transmitted buffers whose\r
138 transmission was completed asynchrnously.\r
139\r
140\r
141**/\r
142EFI_STATUS\r
143EFIAPI\r
144snp_undi32_get_status (\r
145 IN EFI_SIMPLE_NETWORK_PROTOCOL * this,\r
146 OUT UINT32 *InterruptStatusPtr OPTIONAL,\r
147 OUT VOID **TransmitBufferListPtr OPTIONAL\r
148 )\r
149{\r
150 SNP_DRIVER *snp;\r
151 EFI_TPL OldTpl;\r
152 EFI_STATUS Status;\r
153\r
154 if (this == NULL) {\r
155 return EFI_INVALID_PARAMETER;\r
156 }\r
157\r
158 if (InterruptStatusPtr == NULL && TransmitBufferListPtr == NULL) {\r
159 return EFI_INVALID_PARAMETER;\r
160 }\r
161\r
162 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\r
163\r
164 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
165\r
166 if (snp == NULL) {\r
167 return EFI_DEVICE_ERROR;\r
168 }\r
169\r
170 switch (snp->mode.State) {\r
171 case EfiSimpleNetworkInitialized:\r
172 break;\r
173\r
174 case EfiSimpleNetworkStopped:\r
175 Status = EFI_NOT_STARTED;\r
176 goto ON_EXIT;\r
177\r
178 default:\r
179 Status = EFI_DEVICE_ERROR;\r
180 goto ON_EXIT;\r
181 }\r
182\r
183 Status = pxe_getstatus (snp, InterruptStatusPtr, TransmitBufferListPtr);\r
184\r
185ON_EXIT:\r
186 gBS->RestoreTPL (OldTpl);\r
187\r
188 return Status;\r
189}\r