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 
20 FILE_LICENCE ( GPL2_OR_LATER );
21 
22 #include "../../mlx_lib/mlx_reg_access/mlx_reg_access.h"
23 #include "../../include/public/mlx_icmd.h"
24 #include "../../include/public/mlx_bail.h"
25 #include "../../include/public/mlx_memory.h"
26 
27 static
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;
85 icmd_err:
86 bad_param:
87  return status;
88 }
89 
90 
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 MLX_INVALID_PARAMETER
mlx_uint32 register_id
#define REG_TLV_HEADER_LEN
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
#define MAD_CLASS_REG_ACCESS
#define REG_ACCESS_MAX_REG_SIZE
REG_ACCESS_OPT
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
#define TLV_OPERATION_SIZE
#define OUT
Definition: mlx_utils.h:29
mlx_uint32 len
mlx_uint32 status
struct reg_tlv reg_tlv
#define MLX_SUCCESS
struct operation_tlv operation_tlv
#define REG_ACCESS_TLV_REG
mlx_uint32 cls
mlx_uint32 len
mlx_uint32 method
size_t mlx_size
mlx_uint32 Type
uint16_t mlx_uint16
void mlx_void
#define IN
Definition: mlx_utils.h:28
mlx_uint8 data[REG_ACCESS_MAX_REG_SIZE]
FILE_LICENCE(GPL2_OR_LATER)
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_uint32 Type
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)
#define MLX_CHECK_STATUS(id, status, label, message)
Definition: mlx_bail.h:37
#define TLV_OPERATION
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define OP_TLV_SIZE