• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_LINK_MODES_NUMBER
144 };
145 
146 #define NFP_FEC_AUTO		BIT(NFP_FEC_AUTO_BIT)
147 #define NFP_FEC_BASER		BIT(NFP_FEC_BASER_BIT)
148 #define NFP_FEC_REED_SOLOMON	BIT(NFP_FEC_REED_SOLOMON_BIT)
149 #define NFP_FEC_DISABLED	BIT(NFP_FEC_DISABLED_BIT)
150 
151 /* Defines the valid values of the 'abi_drv_reset' hwinfo key */
152 #define NFP_NSP_DRV_RESET_DISK			0
153 #define NFP_NSP_DRV_RESET_ALWAYS		1
154 #define NFP_NSP_DRV_RESET_NEVER			2
155 #define NFP_NSP_DRV_RESET_DEFAULT		"0"
156 
157 /* Defines the valid values of the 'app_fw_from_flash' hwinfo key */
158 #define NFP_NSP_APP_FW_LOAD_DISK		0
159 #define NFP_NSP_APP_FW_LOAD_FLASH		1
160 #define NFP_NSP_APP_FW_LOAD_PREF		2
161 #define NFP_NSP_APP_FW_LOAD_DEFAULT		"2"
162 
163 /* Define the default value for the 'abi_drv_load_ifc' key */
164 #define NFP_NSP_DRV_LOAD_IFC_DEFAULT		"0x10ff"
165 
166 /**
167  * struct nfp_eth_table - ETH table information
168  * @count:	number of table entries
169  * @max_index:	max of @index fields of all @ports
170  * @ports:	table of ports
171  *
172  * @ports.eth_index:	port index according to legacy ethX numbering
173  * @ports.index:	chip-wide first channel index
174  * @ports.nbi:		NBI index
175  * @ports.base:		first channel index (within NBI)
176  * @ports.lanes:	number of channels
177  * @ports.speed:	interface speed (in Mbps)
178  * @ports.interface:	interface (module) plugged in
179  * @ports.media:	media type of the @interface
180  * @ports.fec:		forward error correction mode
181  * @ports.act_fec:	active forward error correction mode
182  * @ports.aneg:		auto negotiation mode
183  * @ports.mac_addr:	interface MAC address
184  * @ports.label_port:	port id
185  * @ports.label_subport:  id of interface within port (for split ports)
186  * @ports.enabled:	is enabled?
187  * @ports.tx_enabled:	is TX enabled?
188  * @ports.rx_enabled:	is RX enabled?
189  * @ports.override_changed: is media reconfig pending?
190  *
191  * @ports.port_type:	one of %PORT_* defines for ethtool
192  * @ports.port_lanes:	total number of lanes on the port (sum of lanes of all
193  *			subports)
194  * @ports.is_split:	is interface part of a split port
195  * @ports.fec_modes_supported:	bitmap of FEC modes supported
196  */
197 struct nfp_eth_table {
198 	unsigned int count;
199 	unsigned int max_index;
200 	struct nfp_eth_table_port {
201 		unsigned int eth_index;
202 		unsigned int index;
203 		unsigned int nbi;
204 		unsigned int base;
205 		unsigned int lanes;
206 		unsigned int speed;
207 
208 		unsigned int interface;
209 		enum nfp_eth_media media;
210 
211 		enum nfp_eth_fec fec;
212 		enum nfp_eth_fec act_fec;
213 		enum nfp_eth_aneg aneg;
214 
215 		u8 mac_addr[ETH_ALEN];
216 
217 		u8 label_port;
218 		u8 label_subport;
219 
220 		bool enabled;
221 		bool tx_enabled;
222 		bool rx_enabled;
223 		bool supp_aneg;
224 
225 		bool override_changed;
226 
227 		/* Computed fields */
228 		u8 port_type;
229 
230 		unsigned int port_lanes;
231 
232 		bool is_split;
233 
234 		unsigned int fec_modes_supported;
235 	} ports[];
236 };
237 
238 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
239 struct nfp_eth_table *
240 __nfp_eth_read_ports(struct nfp_cpp *cpp, struct nfp_nsp *nsp);
241 
242 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, bool enable);
243 int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx,
244 			   bool configed);
245 int
246 nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode);
247 
248 int nfp_eth_set_idmode(struct nfp_cpp *cpp, unsigned int idx, bool state);
249 
nfp_eth_can_support_fec(struct nfp_eth_table_port * eth_port)250 static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port)
251 {
252 	return !!eth_port->fec_modes_supported;
253 }
254 
255 static inline unsigned int
nfp_eth_supported_fec_modes(struct nfp_eth_table_port * eth_port)256 nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port)
257 {
258 	return eth_port->fec_modes_supported;
259 }
260 
261 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx);
262 int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
263 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
264 
265 int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
266 int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed);
267 int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes);
268 
269 /**
270  * struct nfp_nsp_identify - NSP static information
271  * @version:      opaque version string
272  * @flags:        version flags
273  * @br_primary:   branch id of primary bootloader
274  * @br_secondary: branch id of secondary bootloader
275  * @br_nsp:       branch id of NSP
276  * @primary:      version of primarary bootloader
277  * @secondary:    version id of secondary bootloader
278  * @nsp:          version id of NSP
279  * @sensor_mask:  mask of present sensors available on NIC
280  */
281 struct nfp_nsp_identify {
282 	char version[40];
283 	u8 flags;
284 	u8 br_primary;
285 	u8 br_secondary;
286 	u8 br_nsp;
287 	u16 primary;
288 	u16 secondary;
289 	u16 nsp;
290 	u64 sensor_mask;
291 };
292 
293 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp);
294 
295 enum nfp_nsp_sensor_id {
296 	NFP_SENSOR_CHIP_TEMPERATURE,
297 	NFP_SENSOR_ASSEMBLY_POWER,
298 	NFP_SENSOR_ASSEMBLY_12V_POWER,
299 	NFP_SENSOR_ASSEMBLY_3V3_POWER,
300 };
301 
302 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
303 			  long *val);
304 
305 struct nfp_eth_media_buf {
306 	u8 eth_index;
307 	u8 reserved[7];
308 	__le64 supported_modes[2];
309 	__le64 advertised_modes[2];
310 };
311 
312 int nfp_nsp_read_media(struct nfp_nsp *state, void *buf, unsigned int size);
313 int nfp_eth_read_media(struct nfp_cpp *cpp, struct nfp_eth_media_buf *ethm);
314 
315 #define NFP_NSP_VERSION_BUFSZ	1024 /* reasonable size, not in the ABI */
316 
317 enum nfp_nsp_versions {
318 	NFP_VERSIONS_BSP,
319 	NFP_VERSIONS_CPLD,
320 	NFP_VERSIONS_APP,
321 	NFP_VERSIONS_BUNDLE,
322 	NFP_VERSIONS_UNDI,
323 	NFP_VERSIONS_NCSI,
324 	NFP_VERSIONS_CFGR,
325 };
326 
327 int nfp_nsp_versions(struct nfp_nsp *state, void *buf, unsigned int size);
328 const char *nfp_nsp_versions_get(enum nfp_nsp_versions id, bool flash,
329 				 const u8 *buf, unsigned int size);
330 #endif
331