iPXE
Macros | Functions | Variables
mlx_nvconfig.c File Reference
#include "../../mlx_lib/mlx_nvconfig/mlx_nvconfig.h"
#include "../../include/public/mlx_memory.h"
#include "../../include/public/mlx_bail.h"

Go to the source code of this file.

Macros

#define TlvMappingEntry(_tlv_type, _real_tlv_type, _class_code, _fw_reset_needed)
 
#define WARM_REBOOT_RESET   ((mlx_uint64)0x1 << 38)
 

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
static mlx_status nvconfig_set_fw_reset_level (IN mlx_utils *utils, IN mlx_uint16 tlv_type)
 
static mlx_status nvconfig_get_tlv_type_and_class (IN mlx_uint16 tlv_type, OUT mlx_uint16 *real_tlv_type, OUT NVRAM_CLASS_CODE *class_code)
 
static void nvconfig_fill_tlv_type (IN mlx_uint8 port, IN NVRAM_CLASS_CODE class_code, IN mlx_uint16 tlv_type, OUT union nvconfig_tlv_type *nvconfig_tlv_type)
 
mlx_status nvconfig_query_capability (IN mlx_utils *utils, IN mlx_uint8 port, IN mlx_uint16 tlv_type, OUT mlx_boolean *read_supported, OUT mlx_boolean *write_supported)
 
mlx_status nvconfig_nvdata_invalidate (IN mlx_utils *utils, IN mlx_uint8 port, IN mlx_uint16 tlv_type)
 
mlx_status nvconfig_nvdata_access (IN mlx_utils *utils, IN mlx_uint8 port, IN mlx_uint16 tlv_type, IN REG_ACCESS_OPT opt, IN mlx_size data_size, IN NV_DEFAULT_OPT def_en, IN NVDA_WRITER_ID writer_id, IN OUT mlx_uint8 *version, IN OUT mlx_void *data)
 

Variables

struct nvconfig_tlv_mapping nvconfig_tlv_mapping []
 

Macro Definition Documentation

◆ TlvMappingEntry

#define TlvMappingEntry (   _tlv_type,
  _real_tlv_type,
  _class_code,
  _fw_reset_needed 
)
Value:
{ \
.tlv_type = _tlv_type, \
.real_tlv_type = _real_tlv_type, \
.class_code = _class_code, \
.fw_reset_needed = _fw_reset_needed, \
}

Definition at line 26 of file mlx_nvconfig.c.

◆ WARM_REBOOT_RESET

#define WARM_REBOOT_RESET   ((mlx_uint64)0x1 << 38)

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ nvconfig_set_fw_reset_level()

static mlx_status nvconfig_set_fw_reset_level ( IN mlx_utils utils,
IN mlx_uint16  tlv_type 
)
static

Definition at line 75 of file mlx_nvconfig.c.

79 {
80 #define WARM_REBOOT_RESET ((mlx_uint64)0x1 << 38)
82  mlx_uint32 reg_status;
84  mlx_uint8 index = 0;
85  mlx_boolean reset_needed = FALSE;
86 
87  for (index = 0 ; nvconfig_tlv_mapping[index].tlv_type != 0 ; index++) {
88  if (nvconfig_tlv_mapping[index].tlv_type == tlv_type) {
90  }
91  }
92 
93  if (reset_needed == FALSE) {
94  goto no_fw_reset_needed;
95  }
96  status = mlx_reg_access(utils, REG_ID_MFRL, REG_ACCESS_WRITE, &mfrl, sizeof(mfrl),
97  &reg_status);
98  MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
99 
100  if (reg_status != 0) {
101  MLX_DEBUG_ERROR(utils,"nvconfig_set_fw_reset_level failed with status = %d\n", reg_status);
102  status = MLX_FAILED;
103  goto reg_err;
104  }
105 reg_err:
106 no_fw_reset_needed:
107  return status;
108 }
uint8_t mlx_boolean
#define REG_ID_MFRL
mlx_boolean fw_reset_needed
Definition: mlx_nvconfig.h:67
uint8_t status
Status.
Definition: ena.h:16
uint32_t mlx_uint32
#define WARM_REBOOT_RESET
#define MLX_SUCCESS
#define MLX_FAILED
uint8_t mlx_uint8
#define MLX_DEBUG_ERROR(...)
Definition: mlx_logging.h:29
#define FALSE
Definition: tlan.h:45
int mlx_status
mlx_status mlx_reg_access(IN mlx_utils *utils, IN mlx_uint16 reg_id, IN REG_ACCESS_OPT reg_opt, IN OUT mlx_void *reg_data, IN mlx_size reg_size, OUT mlx_uint32 *reg_status)
uint64_t mlx_uint64
#define MLX_CHECK_STATUS(id, status, label, message)
Definition: mlx_bail.h:37
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21

References FALSE, nvconfig_tlv_mapping::fw_reset_needed, index, MLX_CHECK_STATUS, MLX_DEBUG_ERROR, MLX_FAILED, mlx_reg_access(), MLX_SUCCESS, REG_ACCESS_WRITE, REG_ID_MFRL, status, nvconfig_tlv_mapping::tlv_type, and WARM_REBOOT_RESET.

Referenced by nvconfig_nvdata_access().

◆ nvconfig_get_tlv_type_and_class()

static mlx_status nvconfig_get_tlv_type_and_class ( IN mlx_uint16  tlv_type,
OUT mlx_uint16 real_tlv_type,
OUT NVRAM_CLASS_CODE class_code 
)
static

Definition at line 113 of file mlx_nvconfig.c.

118 {
119  mlx_uint8 index = 0;
120  for ( ; nvconfig_tlv_mapping[index].tlv_type != 0 ; index ++) {
121  if ( nvconfig_tlv_mapping[index].tlv_type == tlv_type) {
122  *real_tlv_type = nvconfig_tlv_mapping[index].real_tlv_type;
123  *class_code = nvconfig_tlv_mapping[index].class_code;
124  return MLX_SUCCESS;
125  }
126  }
127  return MLX_NOT_FOUND;
128 }
#define MLX_NOT_FOUND
NVRAM_CLASS_CODE class_code
Definition: mlx_nvconfig.h:66
mlx_uint16 real_tlv_type
Definition: mlx_nvconfig.h:65
#define MLX_SUCCESS
uint8_t mlx_uint8
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21

References nvconfig_tlv_mapping::class_code, index, MLX_NOT_FOUND, MLX_SUCCESS, nvconfig_tlv_mapping::real_tlv_type, and nvconfig_tlv_mapping::tlv_type.

Referenced by nvconfig_nvdata_access(), nvconfig_nvdata_invalidate(), and nvconfig_query_capability().

◆ nvconfig_fill_tlv_type()

static void nvconfig_fill_tlv_type ( IN mlx_uint8  port,
IN NVRAM_CLASS_CODE  class_code,
IN mlx_uint16  tlv_type,
OUT union nvconfig_tlv_type nvconfig_tlv_type 
)
static

Definition at line 131 of file mlx_nvconfig.c.

137 {
138  switch (class_code) {
141  nvconfig_tlv_type->global.param_idx = tlv_type;
142  break;
146  break;
151  break;
152  }
153 }
struct nvconfig_tlv_type_per_port per_port
Definition: mlx_nvconfig.h:71
struct nvconfig_tlv_type_global global
Definition: mlx_nvconfig.h:73
struct nvconfig_tlv_type_per_host per_host
Definition: mlx_nvconfig.h:72
u8 port
Port number.
Definition: CIB_PRM.h:31

References nvconfig_tlv_mapping::class_code, nvconfig_tlv_type::global, NVRAM_TLV_CLASS_GLOBAL, NVRAM_TLV_CLASS_HOST, NVRAM_TLV_CLASS_PHYSICAL_PORT, nvconfig_tlv_type_per_port::param_class, nvconfig_tlv_type_per_host::param_class, nvconfig_tlv_type_global::param_class, nvconfig_tlv_type_per_port::param_idx, nvconfig_tlv_type_per_host::param_idx, nvconfig_tlv_type_global::param_idx, nvconfig_tlv_type::per_host, nvconfig_tlv_type::per_port, port, nvconfig_tlv_type_per_port::port, and nvconfig_tlv_mapping::tlv_type.

Referenced by nvconfig_nvdata_access(), nvconfig_nvdata_invalidate(), and nvconfig_query_capability().

◆ nvconfig_query_capability()

mlx_status nvconfig_query_capability ( IN mlx_utils utils,
IN mlx_uint8  port,
IN mlx_uint16  tlv_type,
OUT mlx_boolean read_supported,
OUT mlx_boolean write_supported 
)

Definition at line 155 of file mlx_nvconfig.c.

162 {
164  struct nvconfig_nvqc nvqc;
165  mlx_uint32 reg_status;
166  NVRAM_CLASS_CODE class_code;
167  mlx_uint16 real_tlv_type;
168 
169  if (utils == NULL || read_supported == NULL || write_supported == NULL) {
171  goto bad_param;
172  }
173 
174  status = nvconfig_get_tlv_type_and_class(tlv_type, &real_tlv_type, &class_code);
175  MLX_CHECK_STATUS(utils, status, tlv_not_supported, "tlv not supported");
176 
177  mlx_memory_set(utils, &nvqc, 0, sizeof(nvqc));
178  nvconfig_fill_tlv_type(port, class_code, real_tlv_type, &nvqc.tlv_type);
179 
180  status = mlx_reg_access(utils, REG_ID_NVQC, REG_ACCESS_READ, &nvqc, sizeof(nvqc),
181  &reg_status);
182  MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
183  if (reg_status != 0) {
184  MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
185  status = MLX_FAILED;
186  goto reg_err;
187  }
188  *read_supported = nvqc.support_rd;
189  *write_supported = nvqc.support_wr;
190 reg_err:
191 tlv_not_supported:
192 bad_param:
193  return status;
194 }
static mlx_status nvconfig_get_tlv_type_and_class(IN mlx_uint16 tlv_type, OUT mlx_uint16 *real_tlv_type, OUT NVRAM_CLASS_CODE *class_code)
Definition: mlx_nvconfig.c:113
#define MLX_INVALID_PARAMETER
#define REG_ID_NVQC
static void nvconfig_fill_tlv_type(IN mlx_uint8 port, IN NVRAM_CLASS_CODE class_code, IN mlx_uint16 tlv_type, OUT union nvconfig_tlv_type *nvconfig_tlv_type)
Definition: mlx_nvconfig.c:131
uint8_t status
Status.
Definition: ena.h:16
uint32_t mlx_uint32
mlx_status mlx_memory_set(IN mlx_utils *utils, IN mlx_void *block, IN mlx_int32 value, IN mlx_size size)
Definition: mlx_memory.c:171
u8 port
Port number.
Definition: CIB_PRM.h:31
#define MLX_SUCCESS
#define MLX_FAILED
uint16_t mlx_uint16
union nvconfig_tlv_type tlv_type
Definition: mlx_nvconfig.h:78
#define MLX_DEBUG_ERROR(...)
Definition: mlx_logging.h:29
int mlx_status
mlx_status mlx_reg_access(IN mlx_utils *utils, IN mlx_uint16 reg_id, IN REG_ACCESS_OPT reg_opt, IN OUT mlx_void *reg_data, IN mlx_size reg_size, OUT mlx_uint32 *reg_status)
NVRAM_CLASS_CODE
Definition: mlx_nvconfig.h:28
#define MLX_CHECK_STATUS(id, status, label, message)
Definition: mlx_bail.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References MLX_CHECK_STATUS, MLX_DEBUG_ERROR, MLX_FAILED, MLX_INVALID_PARAMETER, mlx_memory_set(), mlx_reg_access(), MLX_SUCCESS, NULL, nvconfig_fill_tlv_type(), nvconfig_get_tlv_type_and_class(), port, REG_ACCESS_READ, REG_ID_NVQC, status, nvconfig_nvqc::support_rd, nvconfig_nvqc::support_wr, and nvconfig_nvqc::tlv_type.

◆ nvconfig_nvdata_invalidate()

mlx_status nvconfig_nvdata_invalidate ( IN mlx_utils utils,
IN mlx_uint8  port,
IN mlx_uint16  tlv_type 
)

Definition at line 197 of file mlx_nvconfig.c.

202 {
204  struct nvconfig_header nv_header;
205  mlx_uint32 reg_status;
206  NVRAM_CLASS_CODE class_code;
207  mlx_uint16 real_tlv_type;
208 
209  if (utils == NULL) {
211  goto bad_param;
212  }
213 
214  status = nvconfig_get_tlv_type_and_class(tlv_type, &real_tlv_type, &class_code);
215  MLX_CHECK_STATUS(utils, status, tlv_not_supported, "tlv not supported");
216 
217  mlx_memory_set(utils, &nv_header, 0, sizeof(nv_header));
218  nvconfig_fill_tlv_type(port, class_code, real_tlv_type, &nv_header.tlv_type);
219 
220  status = mlx_reg_access(utils, REG_ID_NVDI, REG_ACCESS_WRITE, &nv_header, sizeof(nv_header),
221  &reg_status);
222  MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
223  if (reg_status != 0) {
224  MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
225  status = MLX_FAILED;
226  goto reg_err;
227  }
228 reg_err:
229 tlv_not_supported:
230 bad_param:
231  return status;
232 }
static mlx_status nvconfig_get_tlv_type_and_class(IN mlx_uint16 tlv_type, OUT mlx_uint16 *real_tlv_type, OUT NVRAM_CLASS_CODE *class_code)
Definition: mlx_nvconfig.c:113
#define MLX_INVALID_PARAMETER
#define REG_ID_NVDI
static void nvconfig_fill_tlv_type(IN mlx_uint8 port, IN NVRAM_CLASS_CODE class_code, IN mlx_uint16 tlv_type, OUT union nvconfig_tlv_type *nvconfig_tlv_type)
Definition: mlx_nvconfig.c:131
uint8_t status
Status.
Definition: ena.h:16
uint32_t mlx_uint32
union nvconfig_tlv_type tlv_type
Definition: mlx_nvconfig.h:105
mlx_status mlx_memory_set(IN mlx_utils *utils, IN mlx_void *block, IN mlx_int32 value, IN mlx_size size)
Definition: mlx_memory.c:171
u8 port
Port number.
Definition: CIB_PRM.h:31
#define MLX_SUCCESS
#define MLX_FAILED
uint16_t mlx_uint16
#define MLX_DEBUG_ERROR(...)
Definition: mlx_logging.h:29
int mlx_status
mlx_status mlx_reg_access(IN mlx_utils *utils, IN mlx_uint16 reg_id, IN REG_ACCESS_OPT reg_opt, IN OUT mlx_void *reg_data, IN mlx_size reg_size, OUT mlx_uint32 *reg_status)
NVRAM_CLASS_CODE
Definition: mlx_nvconfig.h:28
#define MLX_CHECK_STATUS(id, status, label, message)
Definition: mlx_bail.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References MLX_CHECK_STATUS, MLX_DEBUG_ERROR, MLX_FAILED, MLX_INVALID_PARAMETER, mlx_memory_set(), mlx_reg_access(), MLX_SUCCESS, NULL, nvconfig_fill_tlv_type(), nvconfig_get_tlv_type_and_class(), port, REG_ACCESS_WRITE, REG_ID_NVDI, status, and nvconfig_header::tlv_type.

◆ nvconfig_nvdata_access()

mlx_status nvconfig_nvdata_access ( IN mlx_utils utils,
IN mlx_uint8  port,
IN mlx_uint16  tlv_type,
IN REG_ACCESS_OPT  opt,
IN mlx_size  data_size,
IN NV_DEFAULT_OPT  def_en,
IN NVDA_WRITER_ID  writer_id,
IN OUT mlx_uint8 version,
IN OUT mlx_void data 
)

Definition at line 235 of file mlx_nvconfig.c.

246 {
248  struct nvconfig_nvda nvda;
249  mlx_uint32 reg_status;
250  mlx_uint32 real_size_to_read;
252  NVRAM_CLASS_CODE class_code;
253  mlx_uint16 real_tlv_type;
254  mlx_size data_size_align_to_dword;
255 
256  if (utils == NULL || data == NULL || data_size > NVCONFIG_MAX_TLV_SIZE) {
258  goto bad_param;
259  }
260 
261  status = nvconfig_get_tlv_type_and_class(tlv_type, &real_tlv_type, &class_code);
262  MLX_CHECK_STATUS(utils, status, tlv_not_supported, "tlv not supported");
263 
264  data_size_align_to_dword = ((data_size + 3) / sizeof(mlx_uint32)) * sizeof(mlx_uint32);
265  mlx_memory_set(utils, &nvda, 0, sizeof(nvda));
266  nvda.nv_header.length = data_size_align_to_dword;
267  nvda.nv_header.access_mode = def_en;
268  nvda.nv_header.version = *version;
269  nvda.nv_header.writer_id = writer_id;
270 
271  nvconfig_fill_tlv_type(port, class_code, real_tlv_type, &nvda.nv_header.tlv_type);
272 
273  mlx_memory_cpy(utils, nvda.data, data, data_size);
274  for (index = 0 ; index * 4 < NVCONFIG_MAX_TLV_SIZE ; index++) {
275  mlx_memory_be32_to_cpu(utils,(((mlx_uint32 *)nvda.data)[index]), ((mlx_uint32 *)nvda.data) + index);
276  }
277  status = mlx_reg_access(utils, REG_ID_NVDA, opt, &nvda,
278  data_size_align_to_dword + sizeof(nvda.nv_header), &reg_status);
279  MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
280  if (reg_status != 0) {
281  MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
282  status = MLX_FAILED;
283  goto reg_err;
284  }
285  for (index = 0 ; index * 4 < NVCONFIG_MAX_TLV_SIZE ; index++) {
286  mlx_memory_cpu_to_be32(utils,(((mlx_uint32 *)nvda.data)[index]), ((mlx_uint32 *)nvda.data) + index);
287  }
288  if (opt == REG_ACCESS_READ) {
289  real_size_to_read = (nvda.nv_header.length > data_size) ? data_size :
290  nvda.nv_header.length;
291  mlx_memory_cpy(utils, data, nvda.data, real_size_to_read);
292  *version = nvda.nv_header.version;
293  } else {
294  nvconfig_set_fw_reset_level(utils, tlv_type);
295  }
296 reg_err:
297 tlv_not_supported:
298 bad_param:
299  return status;
300 }
mlx_status mlx_memory_cpu_to_be32(IN mlx_utils *utils, IN mlx_uint32 source, IN mlx_uint32 *destination)
Definition: mlx_memory.c:207
static mlx_status nvconfig_get_tlv_type_and_class(IN mlx_uint16 tlv_type, OUT mlx_uint16 *real_tlv_type, OUT NVRAM_CLASS_CODE *class_code)
Definition: mlx_nvconfig.c:113
#define MLX_INVALID_PARAMETER
static void nvconfig_fill_tlv_type(IN mlx_uint8 port, IN NVRAM_CLASS_CODE class_code, IN mlx_uint16 tlv_type, OUT union nvconfig_tlv_type *nvconfig_tlv_type)
Definition: mlx_nvconfig.c:131
uint8_t status
Status.
Definition: ena.h:16
uint32_t mlx_uint32
mlx_status mlx_memory_set(IN mlx_utils *utils, IN mlx_void *block, IN mlx_int32 value, IN mlx_size size)
Definition: mlx_memory.c:171
u8 port
Port number.
Definition: CIB_PRM.h:31
u32 version
Version number.
Definition: ath9k_hw.c:1983
static mlx_status nvconfig_set_fw_reset_level(IN mlx_utils *utils, IN mlx_uint16 tlv_type)
Definition: mlx_nvconfig.c:75
#define MLX_SUCCESS
size_t mlx_size
#define REG_ID_NVDA
#define MLX_FAILED
uint16_t mlx_uint16
#define NVCONFIG_MAX_TLV_SIZE
Definition: mlx_nvconfig.h:112
mlx_status mlx_memory_cpy(IN mlx_utils *utils, OUT mlx_void *destination_buffer, IN mlx_void *source_buffer, IN mlx_size length)
Definition: mlx_memory.c:189
#define MLX_DEBUG_ERROR(...)
Definition: mlx_logging.h:29
int mlx_status
mlx_status mlx_memory_be32_to_cpu(IN mlx_utils *utils, IN mlx_uint32 source, IN mlx_uint32 *destination)
Definition: mlx_memory.c:224
mlx_status mlx_reg_access(IN mlx_utils *utils, IN mlx_uint16 reg_id, IN REG_ACCESS_OPT reg_opt, IN OUT mlx_void *reg_data, IN mlx_size reg_size, OUT mlx_uint32 *reg_status)
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
NVRAM_CLASS_CODE
Definition: mlx_nvconfig.h:28
#define MLX_CHECK_STATUS(id, status, label, message)
Definition: mlx_bail.h:37
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References nvconfig_header::access_mode, data, nvconfig_nvda::data, index, nvconfig_header::length, MLX_CHECK_STATUS, MLX_DEBUG_ERROR, MLX_FAILED, MLX_INVALID_PARAMETER, mlx_memory_be32_to_cpu(), mlx_memory_cpu_to_be32(), mlx_memory_cpy(), mlx_memory_set(), mlx_reg_access(), MLX_SUCCESS, NULL, nvconfig_nvda::nv_header, nvconfig_fill_tlv_type(), nvconfig_get_tlv_type_and_class(), NVCONFIG_MAX_TLV_SIZE, nvconfig_set_fw_reset_level(), port, REG_ACCESS_READ, REG_ID_NVDA, status, nvconfig_header::tlv_type, nvconfig_header::version, version, and nvconfig_header::writer_id.

Referenced by nvconfig_nvdata_default_access(), and nvconfig_read_rom_ini_values().

Variable Documentation

◆ nvconfig_tlv_mapping

Definition at line 33 of file mlx_nvconfig.c.