You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mlx_reg_access.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include "../../mlx_lib/mlx_reg_access/mlx_reg_access.h"
  21. #include "../../include/public/mlx_icmd.h"
  22. #include "../../include/public/mlx_bail.h"
  23. #include "../../include/public/mlx_memory.h"
  24. static
  25. mlx_status
  26. init_operation_tlv(
  27. IN struct mail_box_tlv *mail_box_tlv,
  28. IN mlx_uint16 reg_id,
  29. IN REG_ACCESS_OPT reg_opt
  30. )
  31. {
  32. #define TLV_OPERATION 1
  33. mail_box_tlv->operation_tlv.Type = TLV_OPERATION;
  34. #define MAD_CLASS_REG_ACCESS 1
  35. mail_box_tlv->operation_tlv.cls = MAD_CLASS_REG_ACCESS;
  36. #define TLV_OPERATION_SIZE 4
  37. mail_box_tlv->operation_tlv.len = TLV_OPERATION_SIZE;
  38. mail_box_tlv->operation_tlv.method = reg_opt;
  39. mail_box_tlv->operation_tlv.register_id = reg_id;
  40. return MLX_SUCCESS;
  41. }
  42. mlx_status
  43. mlx_reg_access(
  44. IN mlx_utils *utils,
  45. IN mlx_uint16 reg_id,
  46. IN REG_ACCESS_OPT reg_opt,
  47. IN OUT mlx_void *reg_data,
  48. IN mlx_size reg_size,
  49. OUT mlx_uint32 *reg_status
  50. )
  51. {
  52. mlx_status status = MLX_SUCCESS;
  53. struct mail_box_tlv mail_box_tlv;
  54. if (utils == NULL || reg_data == NULL || reg_status == NULL
  55. || reg_size > REG_ACCESS_MAX_REG_SIZE) {
  56. status = MLX_INVALID_PARAMETER;
  57. goto bad_param;
  58. }
  59. mlx_memory_set(utils, &mail_box_tlv, 0, sizeof(mail_box_tlv));
  60. init_operation_tlv(&mail_box_tlv, reg_id, reg_opt);
  61. #define REG_ACCESS_TLV_REG 3
  62. #define REG_TLV_HEADER_LEN 4
  63. #define OP_TLV_SIZE 16
  64. mail_box_tlv.reg_tlv.Type = REG_ACCESS_TLV_REG;
  65. mail_box_tlv.reg_tlv.len = ((reg_size + REG_TLV_HEADER_LEN + 3) >> 2); // length is in dwords round up
  66. mlx_memory_cpy(utils, &mail_box_tlv.reg_tlv.data, reg_data, reg_size);
  67. reg_size += OP_TLV_SIZE + REG_TLV_HEADER_LEN;
  68. status = mlx_icmd_send_command(utils, FLASH_REG_ACCESS, &mail_box_tlv, reg_size, reg_size);
  69. MLX_CHECK_STATUS(utils, status, icmd_err, "failed to send icmd");
  70. mlx_memory_cpy(utils, reg_data, &mail_box_tlv.reg_tlv.data,
  71. reg_size - (OP_TLV_SIZE + REG_TLV_HEADER_LEN));
  72. *reg_status = mail_box_tlv.operation_tlv.status;
  73. icmd_err:
  74. bad_param:
  75. return status;
  76. }