2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2017-2019 Mellanox Technologies.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Mellanox nor the names of contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/firmware.h>
40 #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
42 enum mlxfw_fsm_state {
44 MLXFW_FSM_STATE_LOCKED,
45 MLXFW_FSM_STATE_INITIALIZE,
46 MLXFW_FSM_STATE_DOWNLOAD,
47 MLXFW_FSM_STATE_VERIFY,
48 MLXFW_FSM_STATE_APPLY,
49 MLXFW_FSM_STATE_ACTIVATE,
52 enum mlxfw_fsm_state_err {
53 MLXFW_FSM_STATE_ERR_OK,
54 MLXFW_FSM_STATE_ERR_ERROR,
55 MLXFW_FSM_STATE_ERR_REJECTED_DIGEST_ERR,
56 MLXFW_FSM_STATE_ERR_REJECTED_NOT_APPLICABLE,
57 MLXFW_FSM_STATE_ERR_REJECTED_UNKNOWN_KEY,
58 MLXFW_FSM_STATE_ERR_REJECTED_AUTH_FAILED,
59 MLXFW_FSM_STATE_ERR_REJECTED_UNSIGNED,
60 MLXFW_FSM_STATE_ERR_REJECTED_KEY_NOT_APPLICABLE,
61 MLXFW_FSM_STATE_ERR_REJECTED_BAD_FORMAT,
62 MLXFW_FSM_STATE_ERR_BLOCKED_PENDING_RESET,
63 MLXFW_FSM_STATE_ERR_MAX,
69 struct mlxfw_dev_ops {
70 int (*component_query)(struct mlxfw_dev *mlxfw_dev, u16 component_index,
71 u32 *p_max_size, u8 *p_align_bits,
72 u16 *p_max_write_size);
74 int (*fsm_lock)(struct mlxfw_dev *mlxfw_dev, u32 *fwhandle);
76 int (*fsm_component_update)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
77 u16 component_index, u32 component_size);
79 int (*fsm_block_download)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
80 u8 *data, u16 size, u32 offset);
82 int (*fsm_component_verify)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
85 int (*fsm_activate)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
87 int (*fsm_query_state)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
88 enum mlxfw_fsm_state *fsm_state,
89 enum mlxfw_fsm_state_err *fsm_state_err);
91 void (*fsm_cancel)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
93 void (*fsm_release)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
97 const struct mlxfw_dev_ops *ops;
102 int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
103 const struct firmware *firmware);