iPXE
mlx_reg_access.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Mellanox Technologies Ltd.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20FILE_LICENCE ( GPL2_OR_LATER );
21
26
27static
31 IN mlx_uint16 reg_id,
32 IN REG_ACCESS_OPT reg_opt
33 )
34{
35#define TLV_OPERATION 1
37#define MAD_CLASS_REG_ACCESS 1
39#define TLV_OPERATION_SIZE 4
43 return MLX_SUCCESS;
44}
45
48 IN mlx_utils *utils,
49 IN mlx_uint16 reg_id,
50 IN REG_ACCESS_OPT reg_opt,
51 IN OUT mlx_void *reg_data,
52 IN mlx_size reg_size,
53 OUT mlx_uint32 *reg_status
54 )
55{
58
59 if (utils == NULL || reg_data == NULL || reg_status == NULL
60 || reg_size > REG_ACCESS_MAX_REG_SIZE) {
62 goto bad_param;
63 }
64
65 mlx_memory_set(utils, &mail_box_tlv, 0, sizeof(mail_box_tlv));
66
67 init_operation_tlv(&mail_box_tlv, reg_id, reg_opt);
68
69#define REG_ACCESS_TLV_REG 3
70#define REG_TLV_HEADER_LEN 4
71#define OP_TLV_SIZE 16
73 mail_box_tlv.reg_tlv.len = ((reg_size + REG_TLV_HEADER_LEN + 3) >> 2); // length is in dwords round up
74 mlx_memory_cpy(utils, &mail_box_tlv.reg_tlv.data, reg_data, reg_size);
75
76 reg_size += OP_TLV_SIZE + REG_TLV_HEADER_LEN;
77
78 status = mlx_icmd_send_command(utils, FLASH_REG_ACCESS, &mail_box_tlv, reg_size, reg_size);
79 MLX_CHECK_STATUS(utils, status, icmd_err, "failed to send icmd");
80
81 mlx_memory_cpy(utils, reg_data, &mail_box_tlv.reg_tlv.data,
82 reg_size - (OP_TLV_SIZE + REG_TLV_HEADER_LEN));
83
84 *reg_status = mail_box_tlv.operation_tlv.status;
85icmd_err:
86bad_param:
87 return status;
88}
89
90
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
uint8_t status
Status.
Definition ena.h:5
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define MLX_CHECK_STATUS(id, status, label, message)
Definition mlx_bail.h:37
@ FLASH_REG_ACCESS
Definition mlx_icmd.h:36
mlx_status mlx_icmd_send_command(IN mlx_utils *utils, IN mlx_uint16 opcode, IN OUT mlx_void *data, IN mlx_uint32 write_data_size, IN mlx_uint32 read_data_size)
Definition mlx_icmd.c:310
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
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
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)
#define REG_TLV_HEADER_LEN
#define OP_TLV_SIZE
#define TLV_OPERATION_SIZE
static mlx_status init_operation_tlv(IN struct mail_box_tlv *mail_box_tlv, IN mlx_uint16 reg_id, IN REG_ACCESS_OPT reg_opt)
#define REG_ACCESS_TLV_REG
#define MAD_CLASS_REG_ACCESS
#define TLV_OPERATION
REG_ACCESS_OPT
#define REG_ACCESS_MAX_REG_SIZE
uint16_t mlx_uint16
uint32_t mlx_uint32
size_t mlx_size
#define MLX_INVALID_PARAMETER
void mlx_void
#define MLX_SUCCESS
int mlx_status
#define IN
Definition mlx_utils.h:28
#define OUT
Definition mlx_utils.h:29
struct reg_tlv reg_tlv
struct operation_tlv operation_tlv
mlx_uint32 status
mlx_uint32 Type
mlx_uint32 len
mlx_uint32 register_id
mlx_uint32 method
mlx_uint32 cls
mlx_uint32 Type
mlx_uint32 len
mlx_uint8 data[REG_ACCESS_MAX_REG_SIZE]