iPXE
mlx_reg_access.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Mellanox Technologies Ltd.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  */
00019 
00020 FILE_LICENCE ( GPL2_OR_LATER );
00021 
00022 #include "../../mlx_lib/mlx_reg_access/mlx_reg_access.h"
00023 #include "../../include/public/mlx_icmd.h"
00024 #include "../../include/public/mlx_bail.h"
00025 #include "../../include/public/mlx_memory.h"
00026 
00027 static
00028 mlx_status
00029 init_operation_tlv(
00030                 IN struct mail_box_tlv *mail_box_tlv,
00031                 IN mlx_uint16  reg_id,
00032                 IN REG_ACCESS_OPT reg_opt
00033                 )
00034 {
00035 #define TLV_OPERATION 1
00036         mail_box_tlv->operation_tlv.Type                        = TLV_OPERATION;
00037 #define MAD_CLASS_REG_ACCESS 1
00038         mail_box_tlv->operation_tlv.cls                 = MAD_CLASS_REG_ACCESS;
00039 #define TLV_OPERATION_SIZE 4
00040         mail_box_tlv->operation_tlv.len                 = TLV_OPERATION_SIZE;
00041         mail_box_tlv->operation_tlv.method                      = reg_opt;
00042         mail_box_tlv->operation_tlv.register_id = reg_id;
00043         return MLX_SUCCESS;
00044 }
00045 
00046 mlx_status
00047 mlx_reg_access(
00048                 IN mlx_utils *utils,
00049                 IN mlx_uint16  reg_id,
00050                 IN REG_ACCESS_OPT reg_opt,
00051                 IN OUT mlx_void *reg_data,
00052         IN mlx_size reg_size,
00053         OUT mlx_uint32 *reg_status
00054                 )
00055 {
00056         mlx_status status = MLX_SUCCESS;
00057         struct mail_box_tlv mail_box_tlv;
00058 
00059         if (utils == NULL || reg_data == NULL || reg_status == NULL
00060                         || reg_size > REG_ACCESS_MAX_REG_SIZE) {
00061                 status = MLX_INVALID_PARAMETER;
00062                 goto bad_param;
00063         }
00064 
00065         mlx_memory_set(utils, &mail_box_tlv, 0, sizeof(mail_box_tlv));
00066 
00067         init_operation_tlv(&mail_box_tlv, reg_id, reg_opt);
00068 
00069 #define REG_ACCESS_TLV_REG 3
00070 #define REG_TLV_HEADER_LEN 4
00071 #define OP_TLV_SIZE 16
00072         mail_box_tlv.reg_tlv.Type = REG_ACCESS_TLV_REG;
00073         mail_box_tlv.reg_tlv.len  = ((reg_size + REG_TLV_HEADER_LEN + 3) >> 2); // length is in dwords round up
00074         mlx_memory_cpy(utils, &mail_box_tlv.reg_tlv.data, reg_data, reg_size);
00075 
00076         reg_size += OP_TLV_SIZE + REG_TLV_HEADER_LEN;
00077 
00078         status = mlx_icmd_send_command(utils, FLASH_REG_ACCESS, &mail_box_tlv, reg_size, reg_size);
00079         MLX_CHECK_STATUS(utils, status, icmd_err, "failed to send icmd");
00080 
00081         mlx_memory_cpy(utils, reg_data, &mail_box_tlv.reg_tlv.data,
00082                         reg_size - (OP_TLV_SIZE + REG_TLV_HEADER_LEN));
00083 
00084         *reg_status = mail_box_tlv.operation_tlv.status;
00085 icmd_err:
00086 bad_param:
00087         return status;
00088 }
00089 
00090