Shalom Toledo | 2bb3e10 | 2019-01-24 07:33:05 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ |
| 2 | /* Copyright (c) 2017-2019 Mellanox Technologies. All rights reserved */ |
Yotam Gigi | 410ed13 | 2017-05-23 21:56:23 +0200 | [diff] [blame] | 3 | |
| 4 | #ifndef _MLXFW_H |
| 5 | #define _MLXFW_H |
| 6 | |
| 7 | #include <linux/firmware.h> |
Jiri Pirko | 44f18db | 2019-06-04 15:40:39 +0200 | [diff] [blame] | 8 | #include <linux/netlink.h> |
Saeed Mahameed | 6a3f707 | 2020-02-21 21:46:05 +0000 | [diff] [blame] | 9 | #include <linux/device.h> |
Saeed Mahameed | 4ae5756 | 2020-02-21 21:45:58 +0000 | [diff] [blame] | 10 | #include <net/devlink.h> |
Yotam Gigi | 410ed13 | 2017-05-23 21:56:23 +0200 | [diff] [blame] | 11 | |
Saeed Mahameed | 6a3f707 | 2020-02-21 21:46:05 +0000 | [diff] [blame] | 12 | struct mlxfw_dev { |
| 13 | const struct mlxfw_dev_ops *ops; |
| 14 | const char *psid; |
| 15 | u16 psid_size; |
| 16 | struct devlink *devlink; |
| 17 | }; |
| 18 | |
| 19 | static inline |
| 20 | struct device *mlxfw_dev_dev(struct mlxfw_dev *mlxfw_dev) |
| 21 | { |
Leon Romanovsky | 2131463 | 2021-10-12 16:15:21 +0300 | [diff] [blame] | 22 | return devlink_to_dev(mlxfw_dev->devlink); |
Saeed Mahameed | 6a3f707 | 2020-02-21 21:46:05 +0000 | [diff] [blame] | 23 | } |
| 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 Gigi | 410ed13 | 2017-05-23 21:56:23 +0200 | [diff] [blame] | 34 | enum 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 | |
| 44 | enum 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 Elisha | 958dfd0 | 2020-02-21 21:46:09 +0000 | [diff] [blame] | 58 | enum 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 Gigi | 410ed13 | 2017-05-23 21:56:23 +0200 | [diff] [blame] | 72 | struct 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 Elisha | 958dfd0 | 2020-02-21 21:46:09 +0000 | [diff] [blame] | 90 | int (*fsm_reactivate)(struct mlxfw_dev *mlxfw_dev, u8 *status); |
| 91 | |
Yotam Gigi | 410ed13 | 2017-05-23 21:56:23 +0200 | [diff] [blame] | 92 | 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 Gerlitz | c1c1d86 | 2017-07-02 18:57:28 +0300 | [diff] [blame] | 101 | #if IS_REACHABLE(CONFIG_MLXFW) |
Yotam Gigi | 410ed13 | 2017-05-23 21:56:23 +0200 | [diff] [blame] | 102 | int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev, |
Jiri Pirko | 44f18db | 2019-06-04 15:40:39 +0200 | [diff] [blame] | 103 | const struct firmware *firmware, |
| 104 | struct netlink_ext_ack *extack); |
Or Gerlitz | c2df613 | 2017-06-06 17:40:54 +0300 | [diff] [blame] | 105 | #else |
| 106 | static inline |
| 107 | int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev, |
Jiri Pirko | 44f18db | 2019-06-04 15:40:39 +0200 | [diff] [blame] | 108 | const struct firmware *firmware, |
| 109 | struct netlink_ext_ack *extack) |
Or Gerlitz | c2df613 | 2017-06-06 17:40:54 +0300 | [diff] [blame] | 110 | { |
| 111 | return -EOPNOTSUPP; |
| 112 | } |
| 113 | #endif |
Yotam Gigi | 410ed13 | 2017-05-23 21:56:23 +0200 | [diff] [blame] | 114 | |
| 115 | #endif |