1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2017-2019 Mellanox Technologies. All rights reserved */
7 #include <linux/firmware.h>
8 #include <linux/netlink.h>
10 enum mlxfw_fsm_state {
12 MLXFW_FSM_STATE_LOCKED,
13 MLXFW_FSM_STATE_INITIALIZE,
14 MLXFW_FSM_STATE_DOWNLOAD,
15 MLXFW_FSM_STATE_VERIFY,
16 MLXFW_FSM_STATE_APPLY,
17 MLXFW_FSM_STATE_ACTIVATE,
20 enum mlxfw_fsm_state_err {
21 MLXFW_FSM_STATE_ERR_OK,
22 MLXFW_FSM_STATE_ERR_ERROR,
23 MLXFW_FSM_STATE_ERR_REJECTED_DIGEST_ERR,
24 MLXFW_FSM_STATE_ERR_REJECTED_NOT_APPLICABLE,
25 MLXFW_FSM_STATE_ERR_REJECTED_UNKNOWN_KEY,
26 MLXFW_FSM_STATE_ERR_REJECTED_AUTH_FAILED,
27 MLXFW_FSM_STATE_ERR_REJECTED_UNSIGNED,
28 MLXFW_FSM_STATE_ERR_REJECTED_KEY_NOT_APPLICABLE,
29 MLXFW_FSM_STATE_ERR_REJECTED_BAD_FORMAT,
30 MLXFW_FSM_STATE_ERR_BLOCKED_PENDING_RESET,
31 MLXFW_FSM_STATE_ERR_MAX,
36 struct mlxfw_dev_ops {
37 int (*component_query)(struct mlxfw_dev *mlxfw_dev, u16 component_index,
38 u32 *p_max_size, u8 *p_align_bits,
39 u16 *p_max_write_size);
41 int (*fsm_lock)(struct mlxfw_dev *mlxfw_dev, u32 *fwhandle);
43 int (*fsm_component_update)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
44 u16 component_index, u32 component_size);
46 int (*fsm_block_download)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
47 u8 *data, u16 size, u32 offset);
49 int (*fsm_component_verify)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
52 int (*fsm_activate)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
54 int (*fsm_query_state)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
55 enum mlxfw_fsm_state *fsm_state,
56 enum mlxfw_fsm_state_err *fsm_state_err);
58 void (*fsm_cancel)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
60 void (*fsm_release)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
62 void (*status_notify)(struct mlxfw_dev *mlxfw_dev,
63 const char *msg, const char *comp_name,
64 u32 done_bytes, u32 total_bytes);
68 const struct mlxfw_dev_ops *ops;
73 #if IS_REACHABLE(CONFIG_MLXFW)
74 int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
75 const struct firmware *firmware,
76 struct netlink_ext_ack *extack);
79 int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
80 const struct firmware *firmware,
81 struct netlink_ext_ack *extack)