xref: /freebsd/sys/dev/mlxfw/mlxfw.h (revision 315ee00f)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2017-2019 Mellanox Technologies.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
18  *
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
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef _MLXFW_H
33 #define _MLXFW_H
34 
35 #include <sys/firmware.h>
36 
37 #define NLA_ALIGNTO		4
38 #define NLA_ALIGN(len)		(((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
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 struct firmware;
66 
67 struct mlxfw_dev_ops {
68 	int (*component_query)(struct mlxfw_dev *mlxfw_dev, u16 component_index,
69 			       u32 *p_max_size, u8 *p_align_bits,
70 			       u16 *p_max_write_size);
71 
72 	int (*fsm_lock)(struct mlxfw_dev *mlxfw_dev, u32 *fwhandle);
73 
74 	int (*fsm_component_update)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
75 				    u16 component_index, u32 component_size);
76 
77 	int (*fsm_block_download)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
78 				  u8 *data, u16 size, u32 offset);
79 
80 	int (*fsm_component_verify)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
81 				    u16 component_index);
82 
83 	int (*fsm_activate)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
84 
85 	int (*fsm_query_state)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
86 			       enum mlxfw_fsm_state *fsm_state,
87 			       enum mlxfw_fsm_state_err *fsm_state_err);
88 
89 	void (*fsm_cancel)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
90 
91 	void (*fsm_release)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
92 };
93 
94 struct mlxfw_dev {
95 	const struct mlxfw_dev_ops *ops;
96 	const char *psid;
97 	u16 psid_size;
98 };
99 
100 int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
101 			 const struct firmware *firmware);
102 #endif
103