blob: e6475ea77cd1828f1db09824fc2e245a0b662464 [file] [log] [blame]
Shalom Toledo2bb3e102019-01-24 07:33:05 +00001/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2/* Copyright (c) 2017-2019 Mellanox Technologies. All rights reserved */
Yotam Gigi410ed132017-05-23 21:56:23 +02003
4#ifndef _MLXFW_H
5#define _MLXFW_H
6
7#include <linux/firmware.h>
Jiri Pirko44f18db2019-06-04 15:40:39 +02008#include <linux/netlink.h>
Saeed Mahameed6a3f7072020-02-21 21:46:05 +00009#include <linux/device.h>
Saeed Mahameed4ae57562020-02-21 21:45:58 +000010#include <net/devlink.h>
Yotam Gigi410ed132017-05-23 21:56:23 +020011
Saeed Mahameed6a3f7072020-02-21 21:46:05 +000012struct mlxfw_dev {
13 const struct mlxfw_dev_ops *ops;
14 const char *psid;
15 u16 psid_size;
16 struct devlink *devlink;
17};
18
19static inline
20struct device *mlxfw_dev_dev(struct mlxfw_dev *mlxfw_dev)
21{
Leon Romanovsky21314632021-10-12 16:15:21 +030022 return devlink_to_dev(mlxfw_dev->devlink);
Saeed Mahameed6a3f7072020-02-21 21:46:05 +000023}
24
25#define MLXFW_PRFX "mlxfw: "
26
27#define mlxfw_info(mlxfw_dev, fmt, ...) \
28 dev_info(mlxfw_dev_dev(mlxfw_dev), MLXFW_PRFX fmt, ## __VA_ARGS__)
29#define mlxfw_err(mlxfw_dev, fmt, ...) \
30 dev_err(mlxfw_dev_dev(mlxfw_dev), MLXFW_PRFX fmt, ## __VA_ARGS__)
31#define mlxfw_dbg(mlxfw_dev, fmt, ...) \
32 dev_dbg(mlxfw_dev_dev(mlxfw_dev), MLXFW_PRFX fmt, ## __VA_ARGS__)
33
Yotam Gigi410ed132017-05-23 21:56:23 +020034enum mlxfw_fsm_state {
35 MLXFW_FSM_STATE_IDLE,
36 MLXFW_FSM_STATE_LOCKED,
37 MLXFW_FSM_STATE_INITIALIZE,
38 MLXFW_FSM_STATE_DOWNLOAD,
39 MLXFW_FSM_STATE_VERIFY,
40 MLXFW_FSM_STATE_APPLY,
41 MLXFW_FSM_STATE_ACTIVATE,
42};
43
44enum mlxfw_fsm_state_err {
45 MLXFW_FSM_STATE_ERR_OK,
46 MLXFW_FSM_STATE_ERR_ERROR,
47 MLXFW_FSM_STATE_ERR_REJECTED_DIGEST_ERR,
48 MLXFW_FSM_STATE_ERR_REJECTED_NOT_APPLICABLE,
49 MLXFW_FSM_STATE_ERR_REJECTED_UNKNOWN_KEY,
50 MLXFW_FSM_STATE_ERR_REJECTED_AUTH_FAILED,
51 MLXFW_FSM_STATE_ERR_REJECTED_UNSIGNED,
52 MLXFW_FSM_STATE_ERR_REJECTED_KEY_NOT_APPLICABLE,
53 MLXFW_FSM_STATE_ERR_REJECTED_BAD_FORMAT,
54 MLXFW_FSM_STATE_ERR_BLOCKED_PENDING_RESET,
55 MLXFW_FSM_STATE_ERR_MAX,
56};
57
Eran Ben Elisha958dfd02020-02-21 21:46:09 +000058enum mlxfw_fsm_reactivate_status {
59 MLXFW_FSM_REACTIVATE_STATUS_OK,
60 MLXFW_FSM_REACTIVATE_STATUS_BUSY,
61 MLXFW_FSM_REACTIVATE_STATUS_PROHIBITED_FW_VER_ERR,
62 MLXFW_FSM_REACTIVATE_STATUS_FIRST_PAGE_COPY_FAILED,
63 MLXFW_FSM_REACTIVATE_STATUS_FIRST_PAGE_ERASE_FAILED,
64 MLXFW_FSM_REACTIVATE_STATUS_FIRST_PAGE_RESTORE_FAILED,
65 MLXFW_FSM_REACTIVATE_STATUS_CANDIDATE_FW_DEACTIVATION_FAILED,
66 MLXFW_FSM_REACTIVATE_STATUS_FW_ALREADY_ACTIVATED,
67 MLXFW_FSM_REACTIVATE_STATUS_ERR_DEVICE_RESET_REQUIRED,
68 MLXFW_FSM_REACTIVATE_STATUS_ERR_FW_PROGRAMMING_NEEDED,
69 MLXFW_FSM_REACTIVATE_STATUS_MAX,
70};
71
Yotam Gigi410ed132017-05-23 21:56:23 +020072struct mlxfw_dev_ops {
73 int (*component_query)(struct mlxfw_dev *mlxfw_dev, u16 component_index,
74 u32 *p_max_size, u8 *p_align_bits,
75 u16 *p_max_write_size);
76
77 int (*fsm_lock)(struct mlxfw_dev *mlxfw_dev, u32 *fwhandle);
78
79 int (*fsm_component_update)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
80 u16 component_index, u32 component_size);
81
82 int (*fsm_block_download)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
83 u8 *data, u16 size, u32 offset);
84
85 int (*fsm_component_verify)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
86 u16 component_index);
87
88 int (*fsm_activate)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
89
Eran Ben Elisha958dfd02020-02-21 21:46:09 +000090 int (*fsm_reactivate)(struct mlxfw_dev *mlxfw_dev, u8 *status);
91
Yotam Gigi410ed132017-05-23 21:56:23 +020092 int (*fsm_query_state)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
93 enum mlxfw_fsm_state *fsm_state,
94 enum mlxfw_fsm_state_err *fsm_state_err);
95
96 void (*fsm_cancel)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
97
98 void (*fsm_release)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
99};
100
Or Gerlitzc1c1d862017-07-02 18:57:28 +0300101#if IS_REACHABLE(CONFIG_MLXFW)
Yotam Gigi410ed132017-05-23 21:56:23 +0200102int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
Jiri Pirko44f18db2019-06-04 15:40:39 +0200103 const struct firmware *firmware,
104 struct netlink_ext_ack *extack);
Or Gerlitzc2df6132017-06-06 17:40:54 +0300105#else
106static inline
107int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
Jiri Pirko44f18db2019-06-04 15:40:39 +0200108 const struct firmware *firmware,
109 struct netlink_ext_ack *extack)
Or Gerlitzc2df6132017-06-06 17:40:54 +0300110{
111 return -EOPNOTSUPP;
112}
113#endif
Yotam Gigi410ed132017-05-23 21:56:23 +0200114
115#endif