Skip to content

Commit 410ed13

Browse files
yotamgidavem330
authored andcommitted
Add the mlxfw module for Mellanox firmware flash process
The mlxfw module is in charge of common logic needed to flash Mellanox devices firmware, which consists of: - Parse the Mellanox Firmware Archive version 2 (MFA2) format, which is the format used to store the Mellanox firmware. The MFA2 format file can hold firmware for many different silicon variants, differentiated by a unique ID called PSID. In addition, the MFA2 file data section is compressed using xz compression to save both file-system space and memory at extraction time. - Implement the firmware flash state machine logic, which is a common logic for Mellanox products needed to flash the firmware to the device. As the module is shared between different Mellanox products, it defines a set of callbacks to be implemented by the specific driver for hardware interaction. Signed-off-by: Yotam Gigi <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ff5f58f commit 410ed13

File tree

14 files changed

+1537
-0
lines changed

14 files changed

+1537
-0
lines changed

MAINTAINERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8330,6 +8330,14 @@ W: http://www.mellanox.com
83308330
Q: http://patchwork.ozlabs.org/project/netdev/list/
83318331
F: drivers/net/ethernet/mellanox/mlxsw/
83328332

8333+
MELLANOX FIRMWARE FLASH LIBRARY (mlxfw)
8334+
M: Yotam Gigi <[email protected]>
8335+
8336+
S: Supported
8337+
W: http://www.mellanox.com
8338+
Q: http://patchwork.ozlabs.org/project/netdev/list/
8339+
F: drivers/net/ethernet/mellanox/mlxfw/
8340+
83338341
MELLANOX MLXCPLD I2C AND MUX DRIVER
83348342
M: Vadim Pasternak <[email protected]>
83358343
M: Michael Shych <[email protected]>

drivers/net/ethernet/mellanox/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ if NET_VENDOR_MELLANOX
1919
source "drivers/net/ethernet/mellanox/mlx4/Kconfig"
2020
source "drivers/net/ethernet/mellanox/mlx5/core/Kconfig"
2121
source "drivers/net/ethernet/mellanox/mlxsw/Kconfig"
22+
source "drivers/net/ethernet/mellanox/mlxfw/Kconfig"
2223

2324
endif # NET_VENDOR_MELLANOX

drivers/net/ethernet/mellanox/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
obj-$(CONFIG_MLX4_CORE) += mlx4/
66
obj-$(CONFIG_MLX5_CORE) += mlx5/core/
77
obj-$(CONFIG_MLXSW_CORE) += mlxsw/
8+
obj-$(CONFIG_MLXFW) += mlxfw/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Mellanox firmware flash library configuration
3+
#
4+
5+
config MLXFW
6+
tristate "mlxfw" if COMPILE_TEST
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
obj-$(CONFIG_MLXFW) += mlxfw.o
2+
mlxfw-objs := mlxfw_fsm.o mlxfw_mfa2_tlv_multi.o mlxfw_mfa2.o
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* drivers/net/ethernet/mellanox/mlxfw/mlxfw.h
3+
* Copyright (c) 2017 Mellanox Technologies. All rights reserved.
4+
* Copyright (c) 2017 Yotam Gigi <[email protected]>
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
* 3. Neither the names of the copyright holders nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* Alternatively, this software may be distributed under the terms of the
19+
* GNU General Public License ("GPL") version 2 as published by the Free
20+
* Software Foundation.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
* POSSIBILITY OF SUCH DAMAGE.
33+
*/
34+
35+
#ifndef _MLXFW_H
36+
#define _MLXFW_H
37+
38+
#include <linux/firmware.h>
39+
40+
enum mlxfw_fsm_state {
41+
MLXFW_FSM_STATE_IDLE,
42+
MLXFW_FSM_STATE_LOCKED,
43+
MLXFW_FSM_STATE_INITIALIZE,
44+
MLXFW_FSM_STATE_DOWNLOAD,
45+
MLXFW_FSM_STATE_VERIFY,
46+
MLXFW_FSM_STATE_APPLY,
47+
MLXFW_FSM_STATE_ACTIVATE,
48+
};
49+
50+
enum mlxfw_fsm_state_err {
51+
MLXFW_FSM_STATE_ERR_OK,
52+
MLXFW_FSM_STATE_ERR_ERROR,
53+
MLXFW_FSM_STATE_ERR_REJECTED_DIGEST_ERR,
54+
MLXFW_FSM_STATE_ERR_REJECTED_NOT_APPLICABLE,
55+
MLXFW_FSM_STATE_ERR_REJECTED_UNKNOWN_KEY,
56+
MLXFW_FSM_STATE_ERR_REJECTED_AUTH_FAILED,
57+
MLXFW_FSM_STATE_ERR_REJECTED_UNSIGNED,
58+
MLXFW_FSM_STATE_ERR_REJECTED_KEY_NOT_APPLICABLE,
59+
MLXFW_FSM_STATE_ERR_REJECTED_BAD_FORMAT,
60+
MLXFW_FSM_STATE_ERR_BLOCKED_PENDING_RESET,
61+
MLXFW_FSM_STATE_ERR_MAX,
62+
};
63+
64+
struct mlxfw_dev;
65+
66+
struct mlxfw_dev_ops {
67+
int (*component_query)(struct mlxfw_dev *mlxfw_dev, u16 component_index,
68+
u32 *p_max_size, u8 *p_align_bits,
69+
u16 *p_max_write_size);
70+
71+
int (*fsm_lock)(struct mlxfw_dev *mlxfw_dev, u32 *fwhandle);
72+
73+
int (*fsm_component_update)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
74+
u16 component_index, u32 component_size);
75+
76+
int (*fsm_block_download)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
77+
u8 *data, u16 size, u32 offset);
78+
79+
int (*fsm_component_verify)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
80+
u16 component_index);
81+
82+
int (*fsm_activate)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
83+
84+
int (*fsm_query_state)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
85+
enum mlxfw_fsm_state *fsm_state,
86+
enum mlxfw_fsm_state_err *fsm_state_err);
87+
88+
void (*fsm_cancel)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
89+
90+
void (*fsm_release)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
91+
};
92+
93+
struct mlxfw_dev {
94+
const struct mlxfw_dev_ops *ops;
95+
const char *psid;
96+
u16 psid_size;
97+
};
98+
99+
int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
100+
const struct firmware *firmware);
101+
102+
#endif

0 commit comments

Comments
 (0)