xref: /linux/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.h (revision 06d07429858317ded2db7986113a9e0129cd599b)
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 
nfp_nsp_has_read_media(struct nfp_nsp * state)68 static inline bool nfp_nsp_has_read_media(struct nfp_nsp *state)
69 {
70 	return nfp_nsp_get_abi_ver_minor(state) > 33;
71 }
72 
73 enum nfp_eth_interface {
74 	NFP_INTERFACE_NONE	= 0,
75 	NFP_INTERFACE_SFP	= 1,
76 	NFP_INTERFACE_SFPP	= 10,
77 	NFP_INTERFACE_SFP28	= 28,
78 	NFP_INTERFACE_QSFP	= 40,
79 	NFP_INTERFACE_RJ45	= 45,
80 	NFP_INTERFACE_CXP	= 100,
81 	NFP_INTERFACE_QSFP28	= 112,
82 };
83 
84 enum nfp_eth_media {
85 	NFP_MEDIA_DAC_PASSIVE = 0,
86 	NFP_MEDIA_DAC_ACTIVE,
87 	NFP_MEDIA_FIBRE,
88 };
89 
90 enum nfp_eth_aneg {
91 	NFP_ANEG_AUTO = 0,
92 	NFP_ANEG_SEARCH,
93 	NFP_ANEG_25G_CONSORTIUM,
94 	NFP_ANEG_25G_IEEE,
95 	NFP_ANEG_DISABLED,
96 };
97 
98 enum nfp_eth_fec {
99 	NFP_FEC_AUTO_BIT = 0,
100 	NFP_FEC_BASER_BIT,
101 	NFP_FEC_REED_SOLOMON_BIT,
102 	NFP_FEC_DISABLED_BIT,
103 };
104 
105 /* link modes about RJ45 haven't been used, so there's no mapping to them */
106 enum nfp_ethtool_link_mode_list {
107 	NFP_MEDIA_W0_RJ45_10M,
108 	NFP_MEDIA_W0_RJ45_10M_HD,
109 	NFP_MEDIA_W0_RJ45_100M,
110 	NFP_MEDIA_W0_RJ45_100M_HD,
111 	NFP_MEDIA_W0_RJ45_1G,
112 	NFP_MEDIA_W0_RJ45_2P5G,
113 	NFP_MEDIA_W0_RJ45_5G,
114 	NFP_MEDIA_W0_RJ45_10G,
115 	NFP_MEDIA_1000BASE_CX,
116 	NFP_MEDIA_1000BASE_KX,
117 	NFP_MEDIA_10GBASE_KX4,
118 	NFP_MEDIA_10GBASE_KR,
119 	NFP_MEDIA_10GBASE_CX4,
120 	NFP_MEDIA_10GBASE_CR,
121 	NFP_MEDIA_10GBASE_SR,
122 	NFP_MEDIA_10GBASE_ER,
123 	NFP_MEDIA_25GBASE_KR,
124 	NFP_MEDIA_25GBASE_KR_S,
125 	NFP_MEDIA_25GBASE_CR,
126 	NFP_MEDIA_25GBASE_CR_S,
127 	NFP_MEDIA_25GBASE_SR,
128 	NFP_MEDIA_40GBASE_CR4,
129 	NFP_MEDIA_40GBASE_KR4,
130 	NFP_MEDIA_40GBASE_SR4,
131 	NFP_MEDIA_40GBASE_LR4,
132 	NFP_MEDIA_50GBASE_KR,
133 	NFP_MEDIA_50GBASE_SR,
134 	NFP_MEDIA_50GBASE_CR,
135 	NFP_MEDIA_50GBASE_LR,
136 	NFP_MEDIA_50GBASE_ER,
137 	NFP_MEDIA_50GBASE_FR,
138 	NFP_MEDIA_100GBASE_KR4,
139 	NFP_MEDIA_100GBASE_SR4,
140 	NFP_MEDIA_100GBASE_CR4,
141 	NFP_MEDIA_100GBASE_KP4,
142 	NFP_MEDIA_100GBASE_CR10,
143 	NFP_MEDIA_10GBASE_LR,
144 	NFP_MEDIA_25GBASE_LR,
145 	NFP_MEDIA_25GBASE_ER,
146 	NFP_MEDIA_LINK_MODES_NUMBER
147 };
148 
149 #define NFP_FEC_AUTO		BIT(NFP_FEC_AUTO_BIT)
150 #define NFP_FEC_BASER		BIT(NFP_FEC_BASER_BIT)
151 #define NFP_FEC_REED_SOLOMON	BIT(NFP_FEC_REED_SOLOMON_BIT)
152 #define NFP_FEC_DISABLED	BIT(NFP_FEC_DISABLED_BIT)
153 
154 /* Defines the valid values of the 'abi_drv_reset' hwinfo key */
155 #define NFP_NSP_DRV_RESET_DISK			0
156 #define NFP_NSP_DRV_RESET_ALWAYS		1
157 #define NFP_NSP_DRV_RESET_NEVER			2
158 #define NFP_NSP_DRV_RESET_DEFAULT		"0"
159 
160 /* Defines the valid values of the 'app_fw_from_flash' hwinfo key */
161 #define NFP_NSP_APP_FW_LOAD_DISK		0
162 #define NFP_NSP_APP_FW_LOAD_FLASH		1
163 #define NFP_NSP_APP_FW_LOAD_PREF		2
164 #define NFP_NSP_APP_FW_LOAD_DEFAULT		"2"
165 
166 /* Define the default value for the 'abi_drv_load_ifc' key */
167 #define NFP_NSP_DRV_LOAD_IFC_DEFAULT		"0x10ff"
168 
169 /**
170  * struct nfp_eth_table - ETH table information
171  * @count:	number of table entries
172  * @max_index:	max of @index fields of all @ports
173  * @ports:	table of ports
174  *
175  * @ports.eth_index:	port index according to legacy ethX numbering
176  * @ports.index:	chip-wide first channel index
177  * @ports.nbi:		NBI index
178  * @ports.base:		first channel index (within NBI)
179  * @ports.lanes:	number of channels
180  * @ports.speed:	interface speed (in Mbps)
181  * @ports.interface:	interface (module) plugged in
182  * @ports.media:	media type of the @interface
183  * @ports.fec:		forward error correction mode
184  * @ports.act_fec:	active forward error correction mode
185  * @ports.aneg:		auto negotiation mode
186  * @ports.mac_addr:	interface MAC address
187  * @ports.label_port:	port id
188  * @ports.label_subport:  id of interface within port (for split ports)
189  * @ports.enabled:	is enabled?
190  * @ports.tx_enabled:	is TX enabled?
191  * @ports.rx_enabled:	is RX enabled?
192  * @ports.rx_pause:	Switch of RX pause frame
193  * @ports.tx_pause:	Switch of Tx pause frame
194  * @ports.override_changed: is media reconfig pending?
195  *
196  * @ports.port_type:	one of %PORT_* defines for ethtool
197  * @ports.port_lanes:	total number of lanes on the port (sum of lanes of all
198  *			subports)
199  * @ports.is_split:	is interface part of a split port
200  * @ports.fec_modes_supported:	bitmap of FEC modes supported
201  *
202  * @ports.link_modes_supp:	bitmap of link modes supported
203  * @ports.link_modes_ad:	bitmap of link modes advertised
204  */
205 struct nfp_eth_table {
206 	unsigned int count;
207 	unsigned int max_index;
208 	struct nfp_eth_table_port {
209 		unsigned int eth_index;
210 		unsigned int index;
211 		unsigned int nbi;
212 		unsigned int base;
213 		unsigned int lanes;
214 		unsigned int speed;
215 
216 		unsigned int interface;
217 		enum nfp_eth_media media;
218 
219 		enum nfp_eth_fec fec;
220 		enum nfp_eth_fec act_fec;
221 		enum nfp_eth_aneg aneg;
222 
223 		u8 mac_addr[ETH_ALEN];
224 
225 		u8 label_port;
226 		u8 label_subport;
227 
228 		bool enabled;
229 		bool tx_enabled;
230 		bool rx_enabled;
231 		bool supp_aneg;
232 		bool rx_pause;
233 		bool tx_pause;
234 
235 		bool override_changed;
236 
237 		/* Computed fields */
238 		u8 port_type;
239 
240 		unsigned int port_lanes;
241 
242 		bool is_split;
243 
244 		unsigned int fec_modes_supported;
245 
246 		u64 link_modes_supp[2];
247 		u64 link_modes_ad[2];
248 	} ports[] __counted_by(count);
249 };
250 
251 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
252 struct nfp_eth_table *
253 __nfp_eth_read_ports(struct nfp_cpp *cpp, struct nfp_nsp *nsp);
254 
255 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, bool enable);
256 int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx,
257 			   bool configed);
258 int
259 nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode);
260 
261 int nfp_eth_set_idmode(struct nfp_cpp *cpp, unsigned int idx, bool state);
262 int nfp_eth_set_pauseparam(struct nfp_cpp *cpp, unsigned int idx,
263 			   unsigned int tx_pause, unsigned int rx_pause);
264 
nfp_eth_can_support_fec(struct nfp_eth_table_port * eth_port)265 static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port)
266 {
267 	return !!eth_port->fec_modes_supported;
268 }
269 
270 static inline unsigned int
nfp_eth_supported_fec_modes(struct nfp_eth_table_port * eth_port)271 nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port)
272 {
273 	return eth_port->fec_modes_supported;
274 }
275 
276 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx);
277 int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
278 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
279 
280 int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
281 int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed);
282 int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes);
283 
284 /**
285  * struct nfp_nsp_identify - NSP static information
286  * @version:      opaque version string
287  * @flags:        version flags
288  * @br_primary:   branch id of primary bootloader
289  * @br_secondary: branch id of secondary bootloader
290  * @br_nsp:       branch id of NSP
291  * @primary:      version of primarary bootloader
292  * @secondary:    version id of secondary bootloader
293  * @nsp:          version id of NSP
294  * @sensor_mask:  mask of present sensors available on NIC
295  */
296 struct nfp_nsp_identify {
297 	char version[40];
298 	u8 flags;
299 	u8 br_primary;
300 	u8 br_secondary;
301 	u8 br_nsp;
302 	u16 primary;
303 	u16 secondary;
304 	u16 nsp;
305 	u64 sensor_mask;
306 };
307 
308 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp);
309 
310 enum nfp_nsp_sensor_id {
311 	NFP_SENSOR_CHIP_TEMPERATURE,
312 	NFP_SENSOR_ASSEMBLY_POWER,
313 	NFP_SENSOR_ASSEMBLY_12V_POWER,
314 	NFP_SENSOR_ASSEMBLY_3V3_POWER,
315 };
316 
317 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
318 			  long *val);
319 
320 struct nfp_eth_media_buf {
321 	u8 eth_index;
322 	u8 reserved[7];
323 	__le64 supported_modes[2];
324 	__le64 advertised_modes[2];
325 };
326 
327 int nfp_nsp_read_media(struct nfp_nsp *state, void *buf, unsigned int size);
328 
329 #define NFP_NSP_VERSION_BUFSZ	1024 /* reasonable size, not in the ABI */
330 
331 enum nfp_nsp_versions {
332 	NFP_VERSIONS_BSP,
333 	NFP_VERSIONS_CPLD,
334 	NFP_VERSIONS_APP,
335 	NFP_VERSIONS_BUNDLE,
336 	NFP_VERSIONS_UNDI,
337 	NFP_VERSIONS_NCSI,
338 	NFP_VERSIONS_CFGR,
339 };
340 
341 int nfp_nsp_versions(struct nfp_nsp *state, void *buf, unsigned int size);
342 const char *nfp_nsp_versions_get(enum nfp_nsp_versions id, bool flash,
343 				 const u8 *buf, unsigned int size);
344 #endif
345