1347285Shselasky/*-
2347285Shselasky * SPDX-License-Identifier: BSD-3-Clause
3347285Shselasky *
4347285Shselasky * Copyright (c) 2017-2019 Mellanox Technologies.
5347285Shselasky * All rights reserved.
6347285Shselasky *
7347285Shselasky * Redistribution and use in source and binary forms, with or without
8347285Shselasky * modification, are permitted provided that the following conditions
9347285Shselasky * are met:
10347285Shselasky * 1. Redistributions of source code must retain the above copyright
11347285Shselasky *    notice, this list of conditions and the following disclaimer.
12347285Shselasky * 2. Redistributions in binary form must reproduce the above copyright
13347285Shselasky *    notice, this list of conditions and the following disclaimer in the
14347285Shselasky *    documentation and/or other materials provided with the distribution.
15347285Shselasky * 3. Neither the name of Mellanox nor the names of contributors
16347285Shselasky *    may be used to endorse or promote products derived from this software
17347285Shselasky *    without specific prior written permission.
18347285Shselasky *
19347285Shselasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20347285Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21347285Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22347285Shselasky * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23347285Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24347285Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25347285Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26347285Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27347285Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28347285Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29347285Shselasky * SUCH DAMAGE.
30347285Shselasky *
31347285Shselasky * $FreeBSD: stable/11/sys/dev/mlxfw/mlxfw.h 347285 2019-05-08 10:49:05Z hselasky $
32347285Shselasky */
33347285Shselasky
34347285Shselasky#ifndef _MLXFW_H
35347285Shselasky#define _MLXFW_H
36347285Shselasky
37347285Shselasky#include <sys/firmware.h>
38347285Shselasky
39347285Shselasky#define NLA_ALIGNTO		4
40347285Shselasky#define NLA_ALIGN(len)		(((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
41347285Shselasky
42347285Shselaskyenum mlxfw_fsm_state {
43347285Shselasky	MLXFW_FSM_STATE_IDLE,
44347285Shselasky	MLXFW_FSM_STATE_LOCKED,
45347285Shselasky	MLXFW_FSM_STATE_INITIALIZE,
46347285Shselasky	MLXFW_FSM_STATE_DOWNLOAD,
47347285Shselasky	MLXFW_FSM_STATE_VERIFY,
48347285Shselasky	MLXFW_FSM_STATE_APPLY,
49347285Shselasky	MLXFW_FSM_STATE_ACTIVATE,
50347285Shselasky};
51347285Shselasky
52347285Shselaskyenum mlxfw_fsm_state_err {
53347285Shselasky	MLXFW_FSM_STATE_ERR_OK,
54347285Shselasky	MLXFW_FSM_STATE_ERR_ERROR,
55347285Shselasky	MLXFW_FSM_STATE_ERR_REJECTED_DIGEST_ERR,
56347285Shselasky	MLXFW_FSM_STATE_ERR_REJECTED_NOT_APPLICABLE,
57347285Shselasky	MLXFW_FSM_STATE_ERR_REJECTED_UNKNOWN_KEY,
58347285Shselasky	MLXFW_FSM_STATE_ERR_REJECTED_AUTH_FAILED,
59347285Shselasky	MLXFW_FSM_STATE_ERR_REJECTED_UNSIGNED,
60347285Shselasky	MLXFW_FSM_STATE_ERR_REJECTED_KEY_NOT_APPLICABLE,
61347285Shselasky	MLXFW_FSM_STATE_ERR_REJECTED_BAD_FORMAT,
62347285Shselasky	MLXFW_FSM_STATE_ERR_BLOCKED_PENDING_RESET,
63347285Shselasky	MLXFW_FSM_STATE_ERR_MAX,
64347285Shselasky};
65347285Shselasky
66347285Shselaskystruct mlxfw_dev;
67347285Shselaskystruct firmware;
68347285Shselasky
69347285Shselaskystruct mlxfw_dev_ops {
70347285Shselasky	int (*component_query)(struct mlxfw_dev *mlxfw_dev, u16 component_index,
71347285Shselasky			       u32 *p_max_size, u8 *p_align_bits,
72347285Shselasky			       u16 *p_max_write_size);
73347285Shselasky
74347285Shselasky	int (*fsm_lock)(struct mlxfw_dev *mlxfw_dev, u32 *fwhandle);
75347285Shselasky
76347285Shselasky	int (*fsm_component_update)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
77347285Shselasky				    u16 component_index, u32 component_size);
78347285Shselasky
79347285Shselasky	int (*fsm_block_download)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
80347285Shselasky				  u8 *data, u16 size, u32 offset);
81347285Shselasky
82347285Shselasky	int (*fsm_component_verify)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
83347285Shselasky				    u16 component_index);
84347285Shselasky
85347285Shselasky	int (*fsm_activate)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
86347285Shselasky
87347285Shselasky	int (*fsm_query_state)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
88347285Shselasky			       enum mlxfw_fsm_state *fsm_state,
89347285Shselasky			       enum mlxfw_fsm_state_err *fsm_state_err);
90347285Shselasky
91347285Shselasky	void (*fsm_cancel)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
92347285Shselasky
93347285Shselasky	void (*fsm_release)(struct mlxfw_dev *mlxfw_dev, u32 fwhandle);
94347285Shselasky};
95347285Shselasky
96347285Shselaskystruct mlxfw_dev {
97347285Shselasky	const struct mlxfw_dev_ops *ops;
98347285Shselasky	const char *psid;
99347285Shselasky	u16 psid_size;
100347285Shselasky};
101347285Shselasky
102347285Shselaskyint mlxfw_firmware_flash(struct mlxfw_dev *mlxfw_dev,
103347285Shselasky			 const struct firmware *firmware);
104347285Shselasky#endif
105