1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2015-2018 Netronome Systems, Inc. */
3 
4 #ifndef NSP_NSP_H
5 #define NSP_NSP_H 1
6 
7 #include <linux/types.h>
8 #include <linux/if_ether.h>
9 
10 struct firmware;
11 struct nfp_cpp;
12 struct nfp_nsp;
13 
14 struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp);
15 void nfp_nsp_close(struct nfp_nsp *state);
16 u16 nfp_nsp_get_abi_ver_major(struct nfp_nsp *state);
17 u16 nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state);
18 int nfp_nsp_wait(struct nfp_nsp *state);
19 int nfp_nsp_device_soft_reset(struct nfp_nsp *state);
20 int nfp_nsp_load_fw(struct nfp_nsp *state, const struct firmware *fw);
21 int nfp_nsp_write_flash(struct nfp_nsp *state, const struct firmware *fw);
22 int nfp_nsp_mac_reinit(struct nfp_nsp *state);
23 int nfp_nsp_load_stored_fw(struct nfp_nsp *state);
24 int nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, unsigned int size);
25 int nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state, void *buf,
26 				   unsigned int size, const char *default_val);
27 int nfp_nsp_hwinfo_set(struct nfp_nsp *state, void *buf, unsigned int size);
28 int nfp_nsp_fw_loaded(struct nfp_nsp *state);
29 int nfp_nsp_read_module_eeprom(struct nfp_nsp *state, int eth_index,
30 			       unsigned int offset, void *data,
31 			       unsigned int len, unsigned int *read_len);
32 
nfp_nsp_has_mac_reinit(struct nfp_nsp * state)33 static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state)
34 {
35 	return nfp_nsp_get_abi_ver_minor(state) > 20;
36 }
37 
nfp_nsp_has_stored_fw_load(struct nfp_nsp * state)38 static inline bool nfp_nsp_has_stored_fw_load(struct nfp_nsp *state)
39 {
40 	return nfp_nsp_get_abi_ver_minor(state) > 23;
41 }
42 
nfp_nsp_has_hwinfo_lookup(struct nfp_nsp * state)43 static inline bool nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state)
44 {
45 	return nfp_nsp_get_abi_ver_minor(state) > 24;
46 }
47 
nfp_nsp_has_hwinfo_set(struct nfp_nsp * state)48 static inline bool nfp_nsp_has_hwinfo_set(struct nfp_nsp *state)
49 {
50 	return nfp_nsp_get_abi_ver_minor(state) > 25;
51 }
52 
nfp_nsp_has_fw_loaded(struct nfp_nsp * state)53 static inline bool nfp_nsp_has_fw_loaded(struct nfp_nsp *state)
54 {
55 	return nfp_nsp_get_abi_ver_minor(state) > 25;
56 }
57 
nfp_nsp_has_versions(struct nfp_nsp * state)58 static inline bool nfp_nsp_has_versions(struct nfp_nsp *state)
59 {
60 	return nfp_nsp_get_abi_ver_minor(state) > 27;
61 }
62 
nfp_nsp_has_read_module_eeprom(struct nfp_nsp * state)63 static inline bool nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state)
64 {
65 	return nfp_nsp_get_abi_ver_minor(state) > 28;
66 }
67 
68 enum nfp_eth_interface {
69 	NFP_INTERFACE_NONE	= 0,
70 	NFP_INTERFACE_SFP	= 1,
71 	NFP_INTERFACE_SFPP	= 10,
72 	NFP_INTERFACE_SFP28	= 28,
73 	NFP_INTERFACE_QSFP	= 40,
74 	NFP_INTERFACE_RJ45	= 45,
75 	NFP_INTERFACE_CXP	= 100,
76 	NFP_INTERFACE_QSFP28	= 112,
77 };
78 
79 enum nfp_eth_media {
80 	NFP_MEDIA_DAC_PASSIVE = 0,
81 	NFP_MEDIA_DAC_ACTIVE,
82 	NFP_MEDIA_FIBRE,
83 };
84 
85 enum nfp_eth_aneg {
86 	NFP_ANEG_AUTO = 0,
87 	NFP_ANEG_SEARCH,
88 	NFP_ANEG_25G_CONSORTIUM,
89 	NFP_ANEG_25G_IEEE,
90 	NFP_ANEG_DISABLED,
91 };
92 
93 enum nfp_eth_fec {
94 	NFP_FEC_AUTO_BIT = 0,
95 	NFP_FEC_BASER_BIT,
96 	NFP_FEC_REED_SOLOMON_BIT,
97 	NFP_FEC_DISABLED_BIT,
98 };
99 
100 #define NFP_FEC_AUTO		BIT(NFP_FEC_AUTO_BIT)
101 #define NFP_FEC_BASER		BIT(NFP_FEC_BASER_BIT)
102 #define NFP_FEC_REED_SOLOMON	BIT(NFP_FEC_REED_SOLOMON_BIT)
103 #define NFP_FEC_DISABLED	BIT(NFP_FEC_DISABLED_BIT)
104 
105 /* Defines the valid values of the 'abi_drv_reset' hwinfo key */
106 #define NFP_NSP_DRV_RESET_DISK			0
107 #define NFP_NSP_DRV_RESET_ALWAYS		1
108 #define NFP_NSP_DRV_RESET_NEVER			2
109 #define NFP_NSP_DRV_RESET_DEFAULT		"0"
110 
111 /* Defines the valid values of the 'app_fw_from_flash' hwinfo key */
112 #define NFP_NSP_APP_FW_LOAD_DISK		0
113 #define NFP_NSP_APP_FW_LOAD_FLASH		1
114 #define NFP_NSP_APP_FW_LOAD_PREF		2
115 #define NFP_NSP_APP_FW_LOAD_DEFAULT		"2"
116 
117 /* Define the default value for the 'abi_drv_load_ifc' key */
118 #define NFP_NSP_DRV_LOAD_IFC_DEFAULT		"0x10ff"
119 
120 /**
121  * struct nfp_eth_table - ETH table information
122  * @count:	number of table entries
123  * @max_index:	max of @index fields of all @ports
124  * @ports:	table of ports
125  *
126  * @ports.eth_index:	port index according to legacy ethX numbering
127  * @ports.index:	chip-wide first channel index
128  * @ports.nbi:		NBI index
129  * @ports.base:		first channel index (within NBI)
130  * @ports.lanes:	number of channels
131  * @ports.speed:	interface speed (in Mbps)
132  * @ports.interface:	interface (module) plugged in
133  * @ports.media:	media type of the @interface
134  * @ports.fec:		forward error correction mode
135  * @ports.act_fec:	active forward error correction mode
136  * @ports.aneg:		auto negotiation mode
137  * @ports.mac_addr:	interface MAC address
138  * @ports.label_port:	port id
139  * @ports.label_subport:  id of interface within port (for split ports)
140  * @ports.enabled:	is enabled?
141  * @ports.tx_enabled:	is TX enabled?
142  * @ports.rx_enabled:	is RX enabled?
143  * @ports.override_changed: is media reconfig pending?
144  *
145  * @ports.port_type:	one of %PORT_* defines for ethtool
146  * @ports.port_lanes:	total number of lanes on the port (sum of lanes of all
147  *			subports)
148  * @ports.is_split:	is interface part of a split port
149  * @ports.fec_modes_supported:	bitmap of FEC modes supported
150  */
151 struct nfp_eth_table {
152 	unsigned int count;
153 	unsigned int max_index;
154 	struct nfp_eth_table_port {
155 		unsigned int eth_index;
156 		unsigned int index;
157 		unsigned int nbi;
158 		unsigned int base;
159 		unsigned int lanes;
160 		unsigned int speed;
161 
162 		unsigned int interface;
163 		enum nfp_eth_media media;
164 
165 		enum nfp_eth_fec fec;
166 		enum nfp_eth_fec act_fec;
167 		enum nfp_eth_aneg aneg;
168 
169 		u8 mac_addr[ETH_ALEN];
170 
171 		u8 label_port;
172 		u8 label_subport;
173 
174 		bool enabled;
175 		bool tx_enabled;
176 		bool rx_enabled;
177 		bool supp_aneg;
178 
179 		bool override_changed;
180 
181 		/* Computed fields */
182 		u8 port_type;
183 
184 		unsigned int port_lanes;
185 
186 		bool is_split;
187 
188 		unsigned int fec_modes_supported;
189 	} ports[];
190 };
191 
192 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
193 struct nfp_eth_table *
194 __nfp_eth_read_ports(struct nfp_cpp *cpp, struct nfp_nsp *nsp);
195 
196 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, bool enable);
197 int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx,
198 			   bool configed);
199 int
200 nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode);
201 
202 int nfp_eth_set_idmode(struct nfp_cpp *cpp, unsigned int idx, bool state);
203 
nfp_eth_can_support_fec(struct nfp_eth_table_port * eth_port)204 static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port)
205 {
206 	return !!eth_port->fec_modes_supported;
207 }
208 
209 static inline unsigned int
nfp_eth_supported_fec_modes(struct nfp_eth_table_port * eth_port)210 nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port)
211 {
212 	return eth_port->fec_modes_supported;
213 }
214 
215 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx);
216 int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
217 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
218 
219 int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
220 int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed);
221 int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes);
222 
223 /**
224  * struct nfp_nsp_identify - NSP static information
225  * @version:      opaque version string
226  * @flags:        version flags
227  * @br_primary:   branch id of primary bootloader
228  * @br_secondary: branch id of secondary bootloader
229  * @br_nsp:       branch id of NSP
230  * @primary:      version of primarary bootloader
231  * @secondary:    version id of secondary bootloader
232  * @nsp:          version id of NSP
233  * @sensor_mask:  mask of present sensors available on NIC
234  */
235 struct nfp_nsp_identify {
236 	char version[40];
237 	u8 flags;
238 	u8 br_primary;
239 	u8 br_secondary;
240 	u8 br_nsp;
241 	u16 primary;
242 	u16 secondary;
243 	u16 nsp;
244 	u64 sensor_mask;
245 };
246 
247 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp);
248 
249 enum nfp_nsp_sensor_id {
250 	NFP_SENSOR_CHIP_TEMPERATURE,
251 	NFP_SENSOR_ASSEMBLY_POWER,
252 	NFP_SENSOR_ASSEMBLY_12V_POWER,
253 	NFP_SENSOR_ASSEMBLY_3V3_POWER,
254 };
255 
256 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
257 			  long *val);
258 
259 #define NFP_NSP_VERSION_BUFSZ	1024 /* reasonable size, not in the ABI */
260 
261 enum nfp_nsp_versions {
262 	NFP_VERSIONS_BSP,
263 	NFP_VERSIONS_CPLD,
264 	NFP_VERSIONS_APP,
265 	NFP_VERSIONS_BUNDLE,
266 	NFP_VERSIONS_UNDI,
267 	NFP_VERSIONS_NCSI,
268 	NFP_VERSIONS_CFGR,
269 };
270 
271 int nfp_nsp_versions(struct nfp_nsp *state, void *buf, unsigned int size);
272 const char *nfp_nsp_versions_get(enum nfp_nsp_versions id, bool flash,
273 				 const u8 *buf, unsigned int size);
274 #endif
275