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 
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 
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 
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 
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 
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 
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 
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 
178 		bool override_changed;
179 
180 		/* Computed fields */
181 		u8 port_type;
182 
183 		unsigned int port_lanes;
184 
185 		bool is_split;
186 
187 		unsigned int fec_modes_supported;
188 	} ports[];
189 };
190 
191 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
192 struct nfp_eth_table *
193 __nfp_eth_read_ports(struct nfp_cpp *cpp, struct nfp_nsp *nsp);
194 
195 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, bool enable);
196 int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx,
197 			   bool configed);
198 int
199 nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode);
200 
201 int nfp_eth_set_idmode(struct nfp_cpp *cpp, unsigned int idx, bool state);
202 
203 static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port)
204 {
205 	return !!eth_port->fec_modes_supported;
206 }
207 
208 static inline unsigned int
209 nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port)
210 {
211 	return eth_port->fec_modes_supported;
212 }
213 
214 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx);
215 int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
216 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
217 
218 int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
219 int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed);
220 int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes);
221 
222 /**
223  * struct nfp_nsp_identify - NSP static information
224  * @version:      opaque version string
225  * @flags:        version flags
226  * @br_primary:   branch id of primary bootloader
227  * @br_secondary: branch id of secondary bootloader
228  * @br_nsp:       branch id of NSP
229  * @primary:      version of primarary bootloader
230  * @secondary:    version id of secondary bootloader
231  * @nsp:          version id of NSP
232  * @sensor_mask:  mask of present sensors available on NIC
233  */
234 struct nfp_nsp_identify {
235 	char version[40];
236 	u8 flags;
237 	u8 br_primary;
238 	u8 br_secondary;
239 	u8 br_nsp;
240 	u16 primary;
241 	u16 secondary;
242 	u16 nsp;
243 	u64 sensor_mask;
244 };
245 
246 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp);
247 
248 enum nfp_nsp_sensor_id {
249 	NFP_SENSOR_CHIP_TEMPERATURE,
250 	NFP_SENSOR_ASSEMBLY_POWER,
251 	NFP_SENSOR_ASSEMBLY_12V_POWER,
252 	NFP_SENSOR_ASSEMBLY_3V3_POWER,
253 };
254 
255 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
256 			  long *val);
257 
258 #define NFP_NSP_VERSION_BUFSZ	1024 /* reasonable size, not in the ABI */
259 
260 enum nfp_nsp_versions {
261 	NFP_VERSIONS_BSP,
262 	NFP_VERSIONS_CPLD,
263 	NFP_VERSIONS_APP,
264 	NFP_VERSIONS_BUNDLE,
265 	NFP_VERSIONS_UNDI,
266 	NFP_VERSIONS_NCSI,
267 	NFP_VERSIONS_CFGR,
268 };
269 
270 int nfp_nsp_versions(struct nfp_nsp *state, void *buf, unsigned int size);
271 const char *nfp_nsp_versions_get(enum nfp_nsp_versions id, bool flash,
272 				 const u8 *buf, unsigned int size);
273 #endif
274