1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2017-2019 Mellanox Technologies. All rights reserved */
3 
4 #ifndef _MLXFW_H
5 #define _MLXFW_H
6 
7 #include <linux/firmware.h>
8 
9 enum mlxfw_fsm_state {
10 	MLXFW_FSM_STATE_IDLE,
11 	MLXFW_FSM_STATE_LOCKED,
12 	MLXFW_FSM_STATE_INITIALIZE,
13 	MLXFW_FSM_STATE_DOWNLOAD,
14 	MLXFW_FSM_STATE_VERIFY,
15 	MLXFW_FSM_STATE_APPLY,
16 	MLXFW_FSM_STATE_ACTIVATE,
17 };
18 
19 enum mlxfw_fsm_state_err {
20 	MLXFW_FSM_STATE_ERR_OK,
21 	MLXFW_FSM_STATE_ERR_ERROR,
22 	MLXFW_FSM_STATE_ERR_REJECTED_DIGEST_ERR,
23 	MLXFW_FSM_STATE_ERR_REJECTED_NOT_APPLICABLE,
24 	MLXFW_FSM_STATE_ERR_REJECTED_UNKNOWN_KEY,
25 	MLXFW_FSM_STATE_ERR_REJECTED_AUTH_FAILED,
26 	MLXFW_FSM_STATE_ERR_REJECTED_UNSIGNED,
27 	MLXFW_FSM_STATE_ERR_REJECTED_KEY_NOT_APPLICABLE,
28 	MLXFW_FSM_STATE_ERR_REJECTED_BAD_FORMAT,
29 	MLXFW_FSM_STATE_ERR_BLOCKED_PENDING_RESET,
30 	MLXFW_FSM_STATE_ERR_MAX,
31 };
32 
33 struct mlxfw_dev;
34 
35 struct mlxfw_dev_ops {
36 	int (*component_query)(struct mlxfw_dev *mlxfw_dev, u16 component_index,
37 			       u32 *p_max_size, u8 *p_align_bits,
38 			       u16 *p_max_write_size);
39 
40 	int (*fsm_lock)(struct mlxfw_dev *mlxfw_dev, u32 *fwhandle);
41 
42 	int (*fsm_component_update)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
43 				    u16 component_index, u32 component_size);
44 
45 	int (*fsm_block_download)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
46 				  u8 *data, u16 size, u32 offset);
47 
48 	int (*fsm_component_verify)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
49 				    u16 component_index);
50 
51 	int (*fsm_activate)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
52 
53 	int (*fsm_query_state)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
54 			       enum mlxfw_fsm_state *fsm_state,
55 			       enum mlxfw_fsm_state_err *fsm_state_err);
56 
57 	void (*fsm_cancel)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
58 
59 	void (*fsm_release)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
60 };
61 
62 struct mlxfw_dev {
63 	const struct mlxfw_dev_ops *ops;
64 	const char *psid;
65 	u16 psid_size;
66 };
67 
68 #if IS_REACHABLE(CONFIG_MLXFW)
69 int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
70 			 const struct firmware *firmware);
71 #else
72 static inline
73 int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
74 			 const struct firmware *firmware)
75 {
76 	return -EOPNOTSUPP;
77 }
78 #endif
79 
80 #endif
81