xref: /freebsd/sys/dev/ice/ice_nvm.h (revision edf8578117e8844e02c0121147f45e4609b30680)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2023, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
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  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND 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 COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _ICE_NVM_H_
33 #define _ICE_NVM_H_
34 
35 #define ICE_NVM_CMD_READ		0x0000000B
36 #define ICE_NVM_CMD_WRITE		0x0000000C
37 
38 /* NVM Access config bits */
39 #define ICE_NVM_CFG_MODULE_M		MAKEMASK(0xFF, 0)
40 #define ICE_NVM_CFG_MODULE_S		0
41 #define ICE_NVM_CFG_FLAGS_M		MAKEMASK(0xF, 8)
42 #define ICE_NVM_CFG_FLAGS_S		8
43 #define ICE_NVM_CFG_EXT_FLAGS_M		MAKEMASK(0xF, 12)
44 #define ICE_NVM_CFG_EXT_FLAGS_S		12
45 #define ICE_NVM_CFG_ADAPTER_INFO_M	MAKEMASK(0xFFFF, 16)
46 #define ICE_NVM_CFG_ADAPTER_INFO_S	16
47 
48 /* NVM Read Get Driver Features */
49 #define ICE_NVM_GET_FEATURES_MODULE	0xE
50 #define ICE_NVM_GET_FEATURES_FLAGS	0xF
51 
52 /* NVM Read/Write Mapped Space */
53 #define ICE_NVM_REG_RW_MODULE	0x0
54 #define ICE_NVM_REG_RW_FLAGS	0x1
55 
56 #pragma pack(1)
57 struct ice_orom_civd_info {
58 	u8 signature[4];	/* Must match ASCII '$CIV' characters */
59 	u8 checksum;		/* Simple modulo 256 sum of all structure bytes must equal 0 */
60 	__le32 combo_ver;	/* Combo Image Version number */
61 	u8 combo_name_len;	/* Length of the unicode combo image version string, max of 32 */
62 	__le16 combo_name[32];	/* Unicode string representing the Combo Image version */
63 };
64 #pragma pack()
65 
66 #define ICE_NVM_ACCESS_MAJOR_VER	0
67 #define ICE_NVM_ACCESS_MINOR_VER	5
68 
69 /* NVM Access feature flags. Other bits in the features field are reserved and
70  * should be set to zero when reporting the ice_nvm_features structure.
71  */
72 #define ICE_NVM_FEATURES_0_REG_ACCESS	BIT(1)
73 
74 /* NVM Access Features */
75 struct ice_nvm_features {
76 	u8 major;		/* Major version (informational only) */
77 	u8 minor;		/* Minor version (informational only) */
78 	u16 size;		/* size of ice_nvm_features structure */
79 	u8 features[12];	/* Array of feature bits */
80 };
81 
82 /* NVM Access command */
83 struct ice_nvm_access_cmd {
84 	u32 command;		/* NVM command: READ or WRITE */
85 	u32 config;		/* NVM command configuration */
86 	u32 offset;		/* offset to read/write, in bytes */
87 	u32 data_size;		/* size of data field, in bytes */
88 };
89 
90 /* NVM Access data */
91 union ice_nvm_access_data {
92 	u32 regval;	/* Storage for register value */
93 	struct ice_nvm_features drv_features; /* NVM features */
94 };
95 
96 u32 ice_nvm_access_get_module(struct ice_nvm_access_cmd *cmd);
97 u32 ice_nvm_access_get_flags(struct ice_nvm_access_cmd *cmd);
98 u32 ice_nvm_access_get_adapter(struct ice_nvm_access_cmd *cmd);
99 enum ice_status
100 ice_nvm_access_read(struct ice_hw *hw, struct ice_nvm_access_cmd *cmd,
101 		    union ice_nvm_access_data *data);
102 enum ice_status
103 ice_nvm_access_write(struct ice_hw *hw, struct ice_nvm_access_cmd *cmd,
104 		     union ice_nvm_access_data *data);
105 enum ice_status
106 ice_nvm_access_get_features(struct ice_nvm_access_cmd *cmd,
107 			    union ice_nvm_access_data *data);
108 enum ice_status
109 ice_handle_nvm_access(struct ice_hw *hw, struct ice_nvm_access_cmd *cmd,
110 		      union ice_nvm_access_data *data);
111 enum ice_status
112 ice_acquire_nvm(struct ice_hw *hw, enum ice_aq_res_access_type access);
113 void ice_release_nvm(struct ice_hw *hw);
114 enum ice_status
115 ice_aq_read_nvm(struct ice_hw *hw, u16 module_typeid, u32 offset, u16 length,
116 		void *data, bool last_command, bool read_shadow_ram,
117 		struct ice_sq_cd *cd);
118 enum ice_status
119 ice_read_flat_nvm(struct ice_hw *hw, u32 offset, u32 *length, u8 *data,
120 		  bool read_shadow_ram);
121 enum ice_status
122 ice_get_pfa_module_tlv(struct ice_hw *hw, u16 *module_tlv, u16 *module_tlv_len,
123 		       u16 module_type);
124 enum ice_status
125 ice_get_nvm_minsrevs(struct ice_hw *hw, struct ice_minsrev_info *minsrevs);
126 enum ice_status
127 ice_update_nvm_minsrevs(struct ice_hw *hw, struct ice_minsrev_info *minsrevs);
128 enum ice_status
129 ice_get_inactive_orom_ver(struct ice_hw *hw, struct ice_orom_info *orom);
130 enum ice_status
131 ice_get_inactive_nvm_ver(struct ice_hw *hw, struct ice_nvm_info *nvm);
132 enum ice_status
133 ice_get_inactive_netlist_ver(struct ice_hw *hw, struct ice_netlist_info *netlist);
134 enum ice_status
135 ice_read_pba_string(struct ice_hw *hw, u8 *pba_num, u32 pba_num_size);
136 enum ice_status ice_init_nvm(struct ice_hw *hw);
137 enum ice_status ice_read_sr_word(struct ice_hw *hw, u16 offset, u16 *data);
138 enum ice_status ice_read_sr_word_aq(struct ice_hw *hw, u16 offset, u16 *data);
139 enum ice_status
140 ice_read_sr_buf(struct ice_hw *hw, u16 offset, u16 *words, u16 *data);
141 enum ice_status
142 ice_aq_erase_nvm(struct ice_hw *hw, u16 module_typeid, struct ice_sq_cd *cd);
143 enum ice_status
144 ice_aq_update_nvm(struct ice_hw *hw, u16 module_typeid, u32 offset,
145 		  u16 length, void *data, bool last_command, u8 command_flags,
146 		  struct ice_sq_cd *cd);
147 enum ice_status
148 ice_aq_read_nvm_cfg(struct ice_hw *hw, u8 cmd_flags, u16 field_id, void *data,
149 		    u16 buf_size, u16 *elem_count, struct ice_sq_cd *cd);
150 enum ice_status
151 ice_aq_write_nvm_cfg(struct ice_hw *hw, u8 cmd_flags, void *data, u16 buf_size,
152 		     u16 elem_count, struct ice_sq_cd *cd);
153 enum ice_status ice_update_sr_checksum(struct ice_hw *hw);
154 enum ice_status ice_validate_sr_checksum(struct ice_hw *hw, u16 *checksum);
155 enum ice_status ice_nvm_validate_checksum(struct ice_hw *hw);
156 enum ice_status ice_nvm_recalculate_checksum(struct ice_hw *hw);
157 enum ice_status
158 ice_nvm_write_activate(struct ice_hw *hw, u16 cmd_flags, u8 *response_flags);
159 #endif /* _ICE_NVM_H_ */
160