2 Implementation of reading and writing operations on the NVRAM device
3 attached to a network interface.
5 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 This routine calls Undi to read the desired number of eeprom bytes.
15 @param Snp pointer to the snp driver structure
16 @param Offset eeprom register value relative to the base address
17 @param BufferSize number of bytes to read
18 @param Buffer pointer where to read into
20 @retval EFI_SUCCESS The NVRAM access was performed.
21 @retval EFI_INVALID_PARAMETER Invalid UNDI command.
22 @retval EFI_UNSUPPORTED Command is not supported by UNDI.
23 @retval EFI_DEVICE_ERROR Fail to execute UNDI command.
37 Snp
->Cdb
.OpCode
= PXE_OPCODE_NVDATA
;
39 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_NVDATA_READ
;
41 Snp
->Cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
42 Snp
->Cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
44 Snp
->Cdb
.DBsize
= (UINT16
)sizeof (PXE_DB_NVDATA
);
45 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
)Db
;
47 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
48 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
49 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
50 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
53 // Issue UNDI command and check result.
55 DEBUG ((DEBUG_NET
, "\nsnp->undi.nvdata () "));
57 (*Snp
->IssueUndi32Command
)((UINT64
)(UINTN
)&Snp
->Cdb
);
59 switch (Snp
->Cdb
.StatCode
) {
60 case PXE_STATCODE_SUCCESS
:
63 case PXE_STATCODE_UNSUPPORTED
:
66 "\nsnp->undi.nvdata() %xh:%xh\n",
71 return EFI_UNSUPPORTED
;
76 "\nsnp->undi.nvdata() %xh:%xh\n",
81 return EFI_DEVICE_ERROR
;
84 ASSERT (Offset
< sizeof (Db
->Data
));
86 CopyMem (Buffer
, &Db
->Data
.Byte
[Offset
], BufferSize
);
92 Performs read and write operations on the NVRAM device attached to a network
95 This function performs read and write operations on the NVRAM device attached
96 to a network interface. If ReadWrite is TRUE, a read operation is performed.
97 If ReadWrite is FALSE, a write operation is performed. Offset specifies the
98 byte offset at which to start either operation. Offset must be a multiple of
99 NvRamAccessSize , and it must have a value between zero and NvRamSize.
100 BufferSize specifies the length of the read or write operation. BufferSize must
101 also be a multiple of NvRamAccessSize, and Offset + BufferSize must not exceed
103 If any of the above conditions is not met, then EFI_INVALID_PARAMETER will be
105 If all the conditions are met and the operation is "read," the NVRAM device
106 attached to the network interface will be read into Buffer and EFI_SUCCESS
107 will be returned. If this is a write operation, the contents of Buffer will be
108 used to update the contents of the NVRAM device attached to the network
109 interface and EFI_SUCCESS will be returned.
111 It does the basic checking on the input parameters and retrieves snp structure
112 and then calls the read_nvdata() call which does the actual reading
114 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
115 @param ReadWrite TRUE for read operations, FALSE for write operations.
116 @param Offset Byte offset in the NVRAM device at which to start the read or
117 write operation. This must be a multiple of NvRamAccessSize
118 and less than NvRamSize. (See EFI_SIMPLE_NETWORK_MODE)
119 @param BufferSize The number of bytes to read or write from the NVRAM device.
120 This must also be a multiple of NvramAccessSize.
121 @param Buffer A pointer to the data buffer.
123 @retval EFI_SUCCESS The NVRAM access was performed.
124 @retval EFI_NOT_STARTED The network interface has not been started.
125 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
126 * The This parameter is NULL
127 * The This parameter does not point to a valid
128 EFI_SIMPLE_NETWORK_PROTOCOL structure
129 * The Offset parameter is not a multiple of
130 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize
131 * The Offset parameter is not less than
132 EFI_SIMPLE_NETWORK_MODE.NvRamSize
133 * The BufferSize parameter is not a multiple of
134 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize
135 * The Buffer parameter is NULL
136 @retval EFI_DEVICE_ERROR The command could not be sent to the network
138 @retval EFI_UNSUPPORTED This function is not supported by the network
145 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
146 IN BOOLEAN ReadWrite
,
157 // Get pointer to SNP driver instance for *this.
160 return EFI_INVALID_PARAMETER
;
163 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
165 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
168 // Return error if the SNP is not initialized.
170 switch (Snp
->Mode
.State
) {
171 case EfiSimpleNetworkInitialized
:
174 case EfiSimpleNetworkStopped
:
175 Status
= EFI_NOT_STARTED
;
179 Status
= EFI_DEVICE_ERROR
;
184 // Return error if non-volatile memory variables are not valid.
186 if ((Snp
->Mode
.NvRamSize
== 0) || (Snp
->Mode
.NvRamAccessSize
== 0)) {
187 Status
= EFI_UNSUPPORTED
;
192 // Check for invalid parameter combinations.
194 if ((BufferSize
== 0) ||
196 (Offset
>= Snp
->Mode
.NvRamSize
) ||
197 (Offset
+ BufferSize
> Snp
->Mode
.NvRamSize
) ||
198 (BufferSize
% Snp
->Mode
.NvRamAccessSize
!= 0) ||
199 (Offset
% Snp
->Mode
.NvRamAccessSize
!= 0)
202 Status
= EFI_INVALID_PARAMETER
;
207 // check the implementation flags of undi if we can write the nvdata!
210 Status
= EFI_UNSUPPORTED
;
212 Status
= PxeNvDataRead (Snp
, Offset
, BufferSize
, Buffer
);
216 gBS
->RestoreTPL (OldTpl
);