• 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_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.override_changed: is media reconfig pending?
193  *
194  * @ports.port_type:	one of %PORT_* defines for ethtool
195  * @ports.port_lanes:	total number of lanes on the port (sum of lanes of all
196  *			subports)
197  * @ports.is_split:	is interface part of a split port
198  * @ports.fec_modes_supported:	bitmap of FEC modes supported
199  *
200  * @ports.link_modes_supp:	bitmap of link modes supported
201  * @ports.link_modes_ad:	bitmap of link modes advertised
202  */
203 struct nfp_eth_table {
204 	unsigned int count;
205 	unsigned int max_index;
206 	struct nfp_eth_table_port {
207 		unsigned int eth_index;
208 		unsigned int index;
209 		unsigned int nbi;
210 		unsigned int base;
211 		unsigned int lanes;
212 		unsigned int speed;
213 
214 		unsigned int interface;
215 		enum nfp_eth_media media;
216 
217 		enum nfp_eth_fec fec;
218 		enum nfp_eth_fec act_fec;
219 		enum nfp_eth_aneg aneg;
220 
221 		u8 mac_addr[ETH_ALEN];
222 
223 		u8 label_port;
224 		u8 label_subport;
225 
226 		bool enabled;
227 		bool tx_enabled;
228 		bool rx_enabled;
229 		bool supp_aneg;
230 
231 		bool override_changed;
232 
233 		/* Computed fields */
234 		u8 port_type;
235 
236 		unsigned int port_lanes;
237 
238 		bool is_split;
239 
240 		unsigned int fec_modes_supported;
241 
242 		u64 link_modes_supp[2];
243 		u64 link_modes_ad[2];
244 	} ports[];
245 };
246 
247 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
248 struct nfp_eth_table *
249 __nfp_eth_read_ports(struct nfp_cpp *cpp, struct nfp_nsp *nsp);
250 
251 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, bool enable);
252 int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx,
253 			   bool configed);
254 int
255 nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode);
256 
257 int nfp_eth_set_idmode(struct nfp_cpp *cpp, unsigned int idx, bool state);
258 
nfp_eth_can_support_fec(struct nfp_eth_table_port * eth_port)259 static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port)
260 {
261 	return !!eth_port->fec_modes_supported;
262 }
263 
264 static inline unsigned int
nfp_eth_supported_fec_modes(struct nfp_eth_table_port * eth_port)265 nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port)
266 {
267 	return eth_port->fec_modes_supported;
268 }
269 
270 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx);
271 int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
272 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
273 
274 int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
275 int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed);
276 int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes);
277 
278 /**
279  * struct nfp_nsp_identify - NSP static information
280  * @version:      opaque version string
281  * @flags:        version flags
282  * @br_primary:   branch id of primary bootloader
283  * @br_secondary: branch id of secondary bootloader
284  * @br_nsp:       branch id of NSP
285  * @primary:      version of primarary bootloader
286  * @secondary:    version id of secondary bootloader
287  * @nsp:          version id of NSP
288  * @sensor_mask:  mask of present sensors available on NIC
289  */
290 struct nfp_nsp_identify {
291 	char version[40];
292 	u8 flags;
293 	u8 br_primary;
294 	u8 br_secondary;
295 	u8 br_nsp;
296 	u16 primary;
297 	u16 secondary;
298 	u16 nsp;
299 	u64 sensor_mask;
300 };
301 
302 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp);
303 
304 enum nfp_nsp_sensor_id {
305 	NFP_SENSOR_CHIP_TEMPERATURE,
306 	NFP_SENSOR_ASSEMBLY_POWER,
307 	NFP_SENSOR_ASSEMBLY_12V_POWER,
308 	NFP_SENSOR_ASSEMBLY_3V3_POWER,
309 };
310 
311 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
312 			  long *val);
313 
314 struct nfp_eth_media_buf {
315 	u8 eth_index;
316 	u8 reserved[7];
317 	__le64 supported_modes[2];
318 	__le64 advertised_modes[2];
319 };
320 
321 int nfp_nsp_read_media(struct nfp_nsp *state, void *buf, unsigned int size);
322 
323 #define NFP_NSP_VERSION_BUFSZ	1024 /* reasonable size, not in the ABI */
324 
325 enum nfp_nsp_versions {
326 	NFP_VERSIONS_BSP,
327 	NFP_VERSIONS_CPLD,
328 	NFP_VERSIONS_APP,
329 	NFP_VERSIONS_BUNDLE,
330 	NFP_VERSIONS_UNDI,
331 	NFP_VERSIONS_NCSI,
332 	NFP_VERSIONS_CFGR,
333 };
334 
335 int nfp_nsp_versions(struct nfp_nsp *state, void *buf, unsigned int size);
336 const char *nfp_nsp_versions_get(enum nfp_nsp_versions id, bool flash,
337 				 const u8 *buf, unsigned int size);
338 #endif
339