iPXE
Defines | 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.

Defines

#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 []

Define Documentation

#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.

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

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER  )
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.

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

Referenced by nvconfig_nvdata_access().

{
#define WARM_REBOOT_RESET ((mlx_uint64)0x1 << 38)
        mlx_status status = MLX_SUCCESS;
        mlx_uint32 reg_status;
        mlx_uint64 mfrl = WARM_REBOOT_RESET ;
        mlx_uint8 index = 0;
        mlx_boolean reset_needed = FALSE;

        for (index = 0 ; nvconfig_tlv_mapping[index].tlv_type != 0 ; index++) {
                if (nvconfig_tlv_mapping[index].tlv_type == tlv_type) {
                        reset_needed = nvconfig_tlv_mapping[index].fw_reset_needed;
                }
        }

        if (reset_needed == FALSE) {
                goto no_fw_reset_needed;
        }
        status = mlx_reg_access(utils, REG_ID_MFRL, REG_ACCESS_WRITE, &mfrl, sizeof(mfrl),
                                &reg_status);
        MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");

        if (reg_status != 0) {
                MLX_DEBUG_ERROR(utils,"nvconfig_set_fw_reset_level failed with status = %d\n", reg_status);
                status = MLX_FAILED;
                goto reg_err;
        }
reg_err:
no_fw_reset_needed:
        return status;
}
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]
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]
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.

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(), status, nvconfig_nvqc::support_rd, nvconfig_nvqc::support_wr, and nvconfig_nvqc::tlv_type.

{
        mlx_status status = MLX_SUCCESS;
        struct nvconfig_nvqc nvqc;
        mlx_uint32 reg_status;
        NVRAM_CLASS_CODE class_code;
        mlx_uint16 real_tlv_type;

        if (utils == NULL || read_supported == NULL || write_supported == NULL) {
                status = MLX_INVALID_PARAMETER;
                goto bad_param;
        }

        status = nvconfig_get_tlv_type_and_class(tlv_type, &real_tlv_type, &class_code);
        MLX_CHECK_STATUS(utils, status, tlv_not_supported, "tlv not supported");

        mlx_memory_set(utils, &nvqc, 0, sizeof(nvqc));
        nvconfig_fill_tlv_type(port, class_code, real_tlv_type, &nvqc.tlv_type);

        status = mlx_reg_access(utils, REG_ID_NVQC, REG_ACCESS_READ, &nvqc, sizeof(nvqc),
                        &reg_status);
        MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
        if (reg_status != 0) {
                MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
                status = MLX_FAILED;
                goto reg_err;
        }
        *read_supported = nvqc.support_rd;
        *write_supported = nvqc.support_wr;
reg_err:
tlv_not_supported:
bad_param:
        return status;
}

Definition at line 197 of file mlx_nvconfig.c.

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(), status, and nvconfig_header::tlv_type.

{
        mlx_status status = MLX_SUCCESS;
        struct nvconfig_header nv_header;
        mlx_uint32 reg_status;
        NVRAM_CLASS_CODE class_code;
        mlx_uint16 real_tlv_type;

        if (utils == NULL) {
                status = MLX_INVALID_PARAMETER;
                goto bad_param;
        }

        status = nvconfig_get_tlv_type_and_class(tlv_type, &real_tlv_type, &class_code);
        MLX_CHECK_STATUS(utils, status, tlv_not_supported, "tlv not supported");

        mlx_memory_set(utils, &nv_header, 0, sizeof(nv_header));
        nvconfig_fill_tlv_type(port, class_code, real_tlv_type, &nv_header.tlv_type);

        status = mlx_reg_access(utils, REG_ID_NVDI, REG_ACCESS_WRITE, &nv_header, sizeof(nv_header),
                        &reg_status);
        MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
        if (reg_status != 0) {
                MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
                status = MLX_FAILED;
                goto reg_err;
        }
reg_err:
tlv_not_supported:
bad_param:
        return status;
}
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.

References nvconfig_header::access_mode, 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(), 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().

{
        mlx_status status = MLX_SUCCESS;
        struct nvconfig_nvda nvda;
        mlx_uint32 reg_status;
        mlx_uint32 real_size_to_read;
        mlx_uint32 index;
        NVRAM_CLASS_CODE class_code;
        mlx_uint16 real_tlv_type;
        mlx_size data_size_align_to_dword;

        if (utils == NULL || data == NULL || data_size > NVCONFIG_MAX_TLV_SIZE) {
                status = MLX_INVALID_PARAMETER;
                goto bad_param;
        }

        status = nvconfig_get_tlv_type_and_class(tlv_type, &real_tlv_type, &class_code);
        MLX_CHECK_STATUS(utils, status, tlv_not_supported, "tlv not supported");

        data_size_align_to_dword = ((data_size + 3) / sizeof(mlx_uint32)) * sizeof(mlx_uint32);
        mlx_memory_set(utils, &nvda, 0, sizeof(nvda));
        nvda.nv_header.length = data_size_align_to_dword;
        nvda.nv_header.access_mode = def_en;
        nvda.nv_header.version = *version;
        nvda.nv_header.writer_id = writer_id;

        nvconfig_fill_tlv_type(port, class_code, real_tlv_type, &nvda.nv_header.tlv_type);

        mlx_memory_cpy(utils, nvda.data, data, data_size);
        for (index = 0 ; index * 4 < NVCONFIG_MAX_TLV_SIZE ; index++) {
                mlx_memory_be32_to_cpu(utils,(((mlx_uint32 *)nvda.data)[index]), ((mlx_uint32 *)nvda.data) + index);
        }
        status = mlx_reg_access(utils, REG_ID_NVDA, opt, &nvda,
                        data_size_align_to_dword + sizeof(nvda.nv_header), &reg_status);
        MLX_CHECK_STATUS(utils, status, reg_err, "mlx_reg_access failed ");
        if (reg_status != 0) {
                MLX_DEBUG_ERROR(utils,"mlx_reg_access failed with status = %d\n", reg_status);
                status = MLX_FAILED;
                goto reg_err;
        }
        for (index = 0 ; index * 4 < NVCONFIG_MAX_TLV_SIZE ; index++) {
                mlx_memory_cpu_to_be32(utils,(((mlx_uint32 *)nvda.data)[index]), ((mlx_uint32 *)nvda.data) + index);
        }
        if (opt == REG_ACCESS_READ) {
                real_size_to_read = (nvda.nv_header.length > data_size) ? data_size :
                                nvda.nv_header.length;
                mlx_memory_cpy(utils, data, nvda.data, real_size_to_read);
                *version = nvda.nv_header.version;
        } else {
                nvconfig_set_fw_reset_level(utils, tlv_type);
        }
reg_err:
tlv_not_supported:
bad_param:
        return status;
}

Variable Documentation

Definition at line 33 of file mlx_nvconfig.c.