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
14 This routine calls Undi to read the desired number of eeprom bytes.
16 @param Snp pointer to the snp driver structure
17 @param Offset eeprom register value relative to the base address
18 @param BufferSize number of bytes to read
19 @param Buffer pointer where to read into
21 @retval EFI_SUCCESS The NVRAM access was performed.
22 @retval EFI_INVALID_PARAMETER Invalid UNDI command.
23 @retval EFI_UNSUPPORTED Command is not supported by UNDI.
24 @retval EFI_DEVICE_ERROR Fail to execute UNDI command.
38 Snp
->Cdb
.OpCode
= PXE_OPCODE_NVDATA
;
40 Snp
->Cdb
.OpFlags
= PXE_OPFLAGS_NVDATA_READ
;
42 Snp
->Cdb
.CPBsize
= PXE_CPBSIZE_NOT_USED
;
43 Snp
->Cdb
.CPBaddr
= PXE_CPBADDR_NOT_USED
;
45 Snp
->Cdb
.DBsize
= (UINT16
) sizeof (PXE_DB_NVDATA
);
46 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
) Db
;
48 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
49 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
50 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
51 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
54 // Issue UNDI command and check result.
56 DEBUG ((EFI_D_NET
, "\nsnp->undi.nvdata () "));
58 (*Snp
->IssueUndi32Command
) ((UINT64
)(UINTN
) &Snp
->Cdb
);
60 switch (Snp
->Cdb
.StatCode
) {
61 case PXE_STATCODE_SUCCESS
:
64 case PXE_STATCODE_UNSUPPORTED
:
67 "\nsnp->undi.nvdata() %xh:%xh\n",
72 return EFI_UNSUPPORTED
;
77 "\nsnp->undi.nvdata() %xh:%xh\n",
82 return EFI_DEVICE_ERROR
;
85 ASSERT (Offset
< sizeof (Db
->Data
));
87 CopyMem (Buffer
, &Db
->Data
.Byte
[Offset
], BufferSize
);
94 Performs read and write operations on the NVRAM device attached to a network
97 This function performs read and write operations on the NVRAM device attached
98 to a network interface. If ReadWrite is TRUE, a read operation is performed.
99 If ReadWrite is FALSE, a write operation is performed. Offset specifies the
100 byte offset at which to start either operation. Offset must be a multiple of
101 NvRamAccessSize , and it must have a value between zero and NvRamSize.
102 BufferSize specifies the length of the read or write operation. BufferSize must
103 also be a multiple of NvRamAccessSize, and Offset + BufferSize must not exceed
105 If any of the above conditions is not met, then EFI_INVALID_PARAMETER will be
107 If all the conditions are met and the operation is "read," the NVRAM device
108 attached to the network interface will be read into Buffer and EFI_SUCCESS
109 will be returned. If this is a write operation, the contents of Buffer will be
110 used to update the contents of the NVRAM device attached to the network
111 interface and EFI_SUCCESS will be returned.
113 It does the basic checking on the input parameters and retrieves snp structure
114 and then calls the read_nvdata() call which does the actual reading
116 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
117 @param ReadWrite TRUE for read operations, FALSE for write operations.
118 @param Offset Byte offset in the NVRAM device at which to start the read or
119 write operation. This must be a multiple of NvRamAccessSize
120 and less than NvRamSize. (See EFI_SIMPLE_NETWORK_MODE)
121 @param BufferSize The number of bytes to read or write from the NVRAM device.
122 This must also be a multiple of NvramAccessSize.
123 @param Buffer A pointer to the data buffer.
125 @retval EFI_SUCCESS The NVRAM access was performed.
126 @retval EFI_NOT_STARTED The network interface has not been started.
127 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
128 * The This parameter is NULL
129 * The This parameter does not point to a valid
130 EFI_SIMPLE_NETWORK_PROTOCOL structure
131 * The Offset parameter is not a multiple of
132 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize
133 * The Offset parameter is not less than
134 EFI_SIMPLE_NETWORK_MODE.NvRamSize
135 * The BufferSize parameter is not a multiple of
136 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize
137 * The Buffer parameter is NULL
138 @retval EFI_DEVICE_ERROR The command could not be sent to the network
140 @retval EFI_UNSUPPORTED This function is not supported by the network
147 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
148 IN BOOLEAN ReadWrite
,
159 // Get pointer to SNP driver instance for *this.
162 return EFI_INVALID_PARAMETER
;
165 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
167 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
170 // Return error if the SNP is not initialized.
172 switch (Snp
->Mode
.State
) {
173 case EfiSimpleNetworkInitialized
:
176 case EfiSimpleNetworkStopped
:
177 Status
= EFI_NOT_STARTED
;
181 Status
= EFI_DEVICE_ERROR
;
185 // Return error if non-volatile memory variables are not valid.
187 if (Snp
->Mode
.NvRamSize
== 0 || Snp
->Mode
.NvRamAccessSize
== 0) {
188 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)
201 Status
= EFI_INVALID_PARAMETER
;
205 // check the implementation flags of undi if we can write the nvdata!
208 Status
= EFI_UNSUPPORTED
;
210 Status
= PxeNvDataRead (Snp
, Offset
, BufferSize
, Buffer
);
214 gBS
->RestoreTPL (OldTpl
);