| 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 |
#include <linux/netlink.h> |
| 9 |
#include <linux/device.h> |
| 10 |
#include <net/devlink.h> |
| 11 |
|
| 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 |
{ |
| 22 |
return devlink_to_dev(mlxfw_dev->devlink); |
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 90 |
int (*fsm_reactivate)(struct mlxfw_dev *mlxfw_dev, u8 *status); |
| 91 |
|
| 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 |
|
| 101 |
#if IS_REACHABLE(CONFIG_MLXFW) |
| 102 |
int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev, |
| 103 |
const struct firmware *firmware, |
| 104 |
struct netlink_ext_ack *extack); |
| 105 |
#else |
| 106 |
static inline |
| 107 |
int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev, |
| 108 |
const struct firmware *firmware, |
| 109 |
struct netlink_ext_ack *extack) |
| 110 |
{ |
| 111 |
return -EOPNOTSUPP; |
| 112 |
} |
| 113 |
#endif |
| 114 |
|
| 115 |
#endif |