xref: /freebsd/sys/dev/mlxfw/mlxfw.h (revision 7ef62cebc2f965b0f640263e179276928885e33d)
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  * $FreeBSD$
32  */
33 
34 #ifndef _MLXFW_H
35 #define _MLXFW_H
36 
37 #include <sys/firmware.h>
38 
39 #define NLA_ALIGNTO		4
40 #define NLA_ALIGN(len)		(((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
41 
42 enum mlxfw_fsm_state {
43 	MLXFW_FSM_STATE_IDLE,
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,
50 };
51 
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,
64 };
65 
66 struct mlxfw_dev;
67 struct firmware;
68 
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);
73 
74 	int (*fsm_lock)(struct mlxfw_dev *mlxfw_dev, u32 *fwhandle);
75 
76 	int (*fsm_component_update)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
77 				    u16 component_index, u32 component_size);
78 
79 	int (*fsm_block_download)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
80 				  u8 *data, u16 size, u32 offset);
81 
82 	int (*fsm_component_verify)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
83 				    u16 component_index);
84 
85 	int (*fsm_activate)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
86 
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);
90 
91 	void (*fsm_cancel)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
92 
93 	void (*fsm_release)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
94 };
95 
96 struct mlxfw_dev {
97 	const struct mlxfw_dev_ops *ops;
98 	const char *psid;
99 	u16 psid_size;
100 };
101 
102 int mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
103 			 const struct firmware *firmware);
104 #endif
105