mlxfw.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * drivers/net/ethernet/mellanox/mlxfw/mlxfw.h
  3. * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
  4. * Copyright (c) 2017 Yotam Gigi <yotamg@mellanox.com>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the names of the copyright holders nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * Alternatively, this software may be distributed under the terms of the
  19. * GNU General Public License ("GPL") version 2 as published by the Free
  20. * Software Foundation.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _MLXFW_H
  35. #define _MLXFW_H
  36. #include <linux/firmware.h>
  37. enum mlxfw_fsm_state {
  38. MLXFW_FSM_STATE_IDLE,
  39. MLXFW_FSM_STATE_LOCKED,
  40. MLXFW_FSM_STATE_INITIALIZE,
  41. MLXFW_FSM_STATE_DOWNLOAD,
  42. MLXFW_FSM_STATE_VERIFY,
  43. MLXFW_FSM_STATE_APPLY,
  44. MLXFW_FSM_STATE_ACTIVATE,
  45. };
  46. enum mlxfw_fsm_state_err {
  47. MLXFW_FSM_STATE_ERR_OK,
  48. MLXFW_FSM_STATE_ERR_ERROR,
  49. MLXFW_FSM_STATE_ERR_REJECTED_DIGEST_ERR,
  50. MLXFW_FSM_STATE_ERR_REJECTED_NOT_APPLICABLE,
  51. MLXFW_FSM_STATE_ERR_REJECTED_UNKNOWN_KEY,
  52. MLXFW_FSM_STATE_ERR_REJECTED_AUTH_FAILED,
  53. MLXFW_FSM_STATE_ERR_REJECTED_UNSIGNED,
  54. MLXFW_FSM_STATE_ERR_REJECTED_KEY_NOT_APPLICABLE,
  55. MLXFW_FSM_STATE_ERR_REJECTED_BAD_FORMAT,
  56. MLXFW_FSM_STATE_ERR_BLOCKED_PENDING_RESET,
  57. MLXFW_FSM_STATE_ERR_MAX,
  58. };
  59. struct mlxfw_dev;
  60. struct mlxfw_dev_ops {
  61. int (*component_query)(struct mlxfw_dev *mlxfw_dev, u16 component_index,
  62. u32 *p_max_size, u8 *p_align_bits,
  63. u16 *p_max_write_size);
  64. int (*fsm_lock)(struct mlxfw_dev *mlxfw_dev, u32 *fwhandle);
  65. int (*fsm_component_update)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
  66. u16 component_index, u32 component_size);
  67. int (*fsm_block_download)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
  68. u8 *data, u16 size, u32 offset);
  69. int (*fsm_component_verify)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
  70. u16 component_index);
  71. int (*fsm_activate)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
  72. int (*fsm_query_state)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
  73. enum mlxfw_fsm_state *fsm_state,
  74. enum mlxfw_fsm_state_err *fsm_state_err);
  75. void (*fsm_cancel)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
  76. void (*fsm_release)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
  77. };
  78. struct mlxfw_dev {
  79. const struct mlxfw_dev_ops *ops;
  80. const char *psid;
  81. u16 psid_size;
  82. };
  83. #if IS_REACHABLE(CONFIG_MLXFW)
  84. int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
  85. const struct firmware *firmware);
  86. #else
  87. static inline
  88. int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
  89. const struct firmware *firmware)
  90. {
  91. return -EOPNOTSUPP;
  92. }
  93. #endif
  94. #endif