]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Network/SnpDxe/Nvdata.c
MdeModulePkg: Update DBsize in SNP GetStatus command.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Nvdata.c
... / ...
CommitLineData
1/** @file\r
2 Implementation of reading and writing operations on the NVRAM device\r
3 attached to a network interface.\r
4 \r
5Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials are licensed \r
7and made available under the terms and conditions of the BSD License which \r
8accompanies this distribution. The full text of the license may be found at \r
9http://opensource.org/licenses/bsd-license.php \r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "Snp.h"\r
17\r
18\r
19/**\r
20 This routine calls Undi to read the desired number of eeprom bytes.\r
21\r
22 @param Snp pointer to the snp driver structure\r
23 @param Offset eeprom register value relative to the base address\r
24 @param BufferSize number of bytes to read\r
25 @param Buffer pointer where to read into\r
26\r
27 @retval EFI_SUCCESS The NVRAM access was performed.\r
28 @retval EFI_INVALID_PARAMETER Invalid UNDI command.\r
29 @retval EFI_UNSUPPORTED Command is not supported by UNDI.\r
30 @retval EFI_DEVICE_ERROR Fail to execute UNDI command.\r
31\r
32**/\r
33EFI_STATUS\r
34PxeNvDataRead (\r
35 IN SNP_DRIVER *Snp,\r
36 IN UINTN Offset,\r
37 IN UINTN BufferSize,\r
38 IN OUT VOID *Buffer\r
39 )\r
40{\r
41 PXE_DB_NVDATA *Db;\r
42\r
43 Db = Snp->Db;\r
44 Snp->Cdb.OpCode = PXE_OPCODE_NVDATA;\r
45\r
46 Snp->Cdb.OpFlags = PXE_OPFLAGS_NVDATA_READ;\r
47\r
48 Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
49 Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
50\r
51 Snp->Cdb.DBsize = (UINT16) sizeof (PXE_DB_NVDATA);\r
52 Snp->Cdb.DBaddr = (UINT64)(UINTN) Db;\r
53\r
54 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
55 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
56 Snp->Cdb.IFnum = Snp->IfNum;\r
57 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
58\r
59 //\r
60 // Issue UNDI command and check result.\r
61 //\r
62 DEBUG ((EFI_D_NET, "\nsnp->undi.nvdata () "));\r
63\r
64 (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);\r
65\r
66 switch (Snp->Cdb.StatCode) {\r
67 case PXE_STATCODE_SUCCESS:\r
68 break;\r
69\r
70 case PXE_STATCODE_UNSUPPORTED:\r
71 DEBUG (\r
72 (EFI_D_NET,\r
73 "\nsnp->undi.nvdata() %xh:%xh\n",\r
74 Snp->Cdb.StatFlags,\r
75 Snp->Cdb.StatCode)\r
76 );\r
77\r
78 return EFI_UNSUPPORTED;\r
79\r
80 default:\r
81 DEBUG (\r
82 (EFI_D_NET,\r
83 "\nsnp->undi.nvdata() %xh:%xh\n",\r
84 Snp->Cdb.StatFlags,\r
85 Snp->Cdb.StatCode)\r
86 );\r
87\r
88 return EFI_DEVICE_ERROR;\r
89 }\r
90\r
91 ASSERT (Offset < sizeof (Db->Data));\r
92\r
93 CopyMem (Buffer, &Db->Data.Byte[Offset], BufferSize);\r
94\r
95 return EFI_SUCCESS;\r
96}\r
97\r
98\r
99/**\r
100 Performs read and write operations on the NVRAM device attached to a network \r
101 interface.\r
102 \r
103 This function performs read and write operations on the NVRAM device attached \r
104 to a network interface. If ReadWrite is TRUE, a read operation is performed.\r
105 If ReadWrite is FALSE, a write operation is performed. Offset specifies the \r
106 byte offset at which to start either operation. Offset must be a multiple of \r
107 NvRamAccessSize , and it must have a value between zero and NvRamSize. \r
108 BufferSize specifies the length of the read or write operation. BufferSize must\r
109 also be a multiple of NvRamAccessSize, and Offset + BufferSize must not exceed\r
110 NvRamSize. \r
111 If any of the above conditions is not met, then EFI_INVALID_PARAMETER will be \r
112 returned. \r
113 If all the conditions are met and the operation is "read," the NVRAM device \r
114 attached to the network interface will be read into Buffer and EFI_SUCCESS \r
115 will be returned. If this is a write operation, the contents of Buffer will be\r
116 used to update the contents of the NVRAM device attached to the network \r
117 interface and EFI_SUCCESS will be returned.\r
118 \r
119 It does the basic checking on the input parameters and retrieves snp structure\r
120 and then calls the read_nvdata() call which does the actual reading\r
121\r
122 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
123 @param ReadWrite TRUE for read operations, FALSE for write operations.\r
124 @param Offset Byte offset in the NVRAM device at which to start the read or \r
125 write operation. This must be a multiple of NvRamAccessSize \r
126 and less than NvRamSize. (See EFI_SIMPLE_NETWORK_MODE) \r
127 @param BufferSize The number of bytes to read or write from the NVRAM device. \r
128 This must also be a multiple of NvramAccessSize.\r
129 @param Buffer A pointer to the data buffer.\r
130\r
131 @retval EFI_SUCCESS The NVRAM access was performed.\r
132 @retval EFI_NOT_STARTED The network interface has not been started.\r
133 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
134 * The This parameter is NULL \r
135 * The This parameter does not point to a valid \r
136 EFI_SIMPLE_NETWORK_PROTOCOL structure\r
137 * The Offset parameter is not a multiple of \r
138 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize\r
139 * The Offset parameter is not less than \r
140 EFI_SIMPLE_NETWORK_MODE.NvRamSize\r
141 * The BufferSize parameter is not a multiple of \r
142 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize\r
143 * The Buffer parameter is NULL\r
144 @retval EFI_DEVICE_ERROR The command could not be sent to the network \r
145 interface.\r
146 @retval EFI_UNSUPPORTED This function is not supported by the network\r
147 interface.\r
148\r
149**/\r
150EFI_STATUS\r
151EFIAPI\r
152SnpUndi32NvData (\r
153 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
154 IN BOOLEAN ReadWrite,\r
155 IN UINTN Offset,\r
156 IN UINTN BufferSize,\r
157 IN OUT VOID *Buffer\r
158 )\r
159{\r
160 SNP_DRIVER *Snp;\r
161 EFI_TPL OldTpl;\r
162 EFI_STATUS Status;\r
163\r
164 //\r
165 // Get pointer to SNP driver instance for *this.\r
166 //\r
167 if (This == NULL) {\r
168 return EFI_INVALID_PARAMETER;\r
169 }\r
170\r
171 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r
172\r
173 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
174\r
175 //\r
176 // Return error if the SNP is not initialized.\r
177 //\r
178 switch (Snp->Mode.State) {\r
179 case EfiSimpleNetworkInitialized:\r
180 break;\r
181\r
182 case EfiSimpleNetworkStopped:\r
183 Status = EFI_NOT_STARTED;\r
184 goto ON_EXIT;\r
185\r
186 default:\r
187 Status = EFI_DEVICE_ERROR;\r
188 goto ON_EXIT;\r
189 }\r
190 //\r
191 // Return error if non-volatile memory variables are not valid.\r
192 //\r
193 if (Snp->Mode.NvRamSize == 0 || Snp->Mode.NvRamAccessSize == 0) {\r
194 Status = EFI_UNSUPPORTED;\r
195 goto ON_EXIT;\r
196 }\r
197 //\r
198 // Check for invalid parameter combinations.\r
199 //\r
200 if ((BufferSize == 0) ||\r
201 (Buffer == NULL) ||\r
202 (Offset >= Snp->Mode.NvRamSize) ||\r
203 (Offset + BufferSize > Snp->Mode.NvRamSize) ||\r
204 (BufferSize % Snp->Mode.NvRamAccessSize != 0) ||\r
205 (Offset % Snp->Mode.NvRamAccessSize != 0)\r
206 ) {\r
207 Status = EFI_INVALID_PARAMETER;\r
208 goto ON_EXIT;\r
209 }\r
210 //\r
211 // check the implementation flags of undi if we can write the nvdata!\r
212 //\r
213 if (!ReadWrite) {\r
214 Status = EFI_UNSUPPORTED;\r
215 } else {\r
216 Status = PxeNvDataRead (Snp, Offset, BufferSize, Buffer);\r
217 }\r
218\r
219ON_EXIT:\r
220 gBS->RestoreTPL (OldTpl);\r
221\r
222 return Status;\r
223}\r