xref: /dpdk/drivers/net/nfp/nfpcore/nfp_nsp.h (revision 8bd6f5403743ccea850514e29d38fb239312f61d)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Netronome Systems, Inc.
3  * All rights reserved.
4  */
5 
6 #ifndef __NSP_NSP_H__
7 #define __NSP_NSP_H__
8 
9 #include "nfp_cpp.h"
10 
11 /* EEPROM byte offsets */
12 #define SFP_SFF8472_COMPLIANCE          0x5e
13 #define SFP_SFF_REV_COMPLIANCE          1
14 #define NSP_SFF_EEPROM_BLOCK_LEN        8
15 
16 /* Defines the valid values of the 'abi_drv_reset' hwinfo key */
17 #define NFP_NSP_DRV_RESET_DISK                  0
18 #define NFP_NSP_DRV_RESET_ALWAYS                1
19 #define NFP_NSP_DRV_RESET_NEVER                 2
20 #define NFP_NSP_DRV_RESET_DEFAULT               "0"
21 
22 /* Defines the valid values of the 'app_fw_from_flash' hwinfo key */
23 #define NFP_NSP_APP_FW_LOAD_DISK                0
24 #define NFP_NSP_APP_FW_LOAD_FLASH               1
25 #define NFP_NSP_APP_FW_LOAD_PREF                2
26 #define NFP_NSP_APP_FW_LOAD_DEFAULT             "2"
27 
28 struct nfp_nsp;
29 
30 struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp);
31 void nfp_nsp_close(struct nfp_nsp *state);
32 uint16_t nfp_nsp_get_abi_ver_major(struct nfp_nsp *state);
33 uint16_t nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state);
34 int nfp_nsp_wait(struct nfp_nsp *state);
35 int nfp_nsp_device_soft_reset(struct nfp_nsp *state);
36 int nfp_nsp_device_activate(struct nfp_nsp *state);
37 int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size);
38 int nfp_nsp_mac_reinit(struct nfp_nsp *state);
39 int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size);
40 int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask,
41 		void *buf, size_t size);
42 
43 static inline bool
44 nfp_nsp_has_mac_reinit(struct nfp_nsp *state)
45 {
46 	return nfp_nsp_get_abi_ver_minor(state) > 20;
47 }
48 
49 static inline bool
50 nfp_nsp_has_stored_fw_load(struct nfp_nsp *state)
51 {
52 	return nfp_nsp_get_abi_ver_minor(state) > 23;
53 }
54 
55 static inline bool
56 nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state)
57 {
58 	return nfp_nsp_get_abi_ver_minor(state) > 24;
59 }
60 
61 static inline bool
62 nfp_nsp_has_hwinfo_set(struct nfp_nsp *state)
63 {
64 	return nfp_nsp_get_abi_ver_minor(state) > 25;
65 }
66 
67 static inline bool
68 nfp_nsp_has_fw_loaded(struct nfp_nsp *state)
69 {
70 	return nfp_nsp_get_abi_ver_minor(state) > 25;
71 }
72 
73 static inline bool
74 nfp_nsp_has_versions(struct nfp_nsp *state)
75 {
76 	return nfp_nsp_get_abi_ver_minor(state) > 27;
77 }
78 
79 static inline bool
80 nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state)
81 {
82 	return nfp_nsp_get_abi_ver_minor(state) > 28;
83 }
84 
85 static inline bool
86 nfp_nsp_has_read_media(struct nfp_nsp *state)
87 {
88 	return nfp_nsp_get_abi_ver_minor(state) > 33;
89 }
90 
91 enum nfp_eth_interface {
92 	NFP_INTERFACE_NONE      = 0,
93 	NFP_INTERFACE_SFP       = 1,
94 	NFP_INTERFACE_SFPP      = 10,
95 	NFP_INTERFACE_SFP28     = 28,
96 	NFP_INTERFACE_QSFP      = 40,
97 	NFP_INTERFACE_RJ45      = 45,
98 	NFP_INTERFACE_CXP       = 100,
99 	NFP_INTERFACE_QSFP28    = 112,
100 };
101 
102 enum nfp_eth_media {
103 	NFP_MEDIA_DAC_PASSIVE = 0,
104 	NFP_MEDIA_DAC_ACTIVE,
105 	NFP_MEDIA_FIBRE,
106 };
107 
108 enum nfp_eth_aneg {
109 	NFP_ANEG_AUTO = 0,
110 	NFP_ANEG_SEARCH,
111 	NFP_ANEG_25G_CONSORTIUM,
112 	NFP_ANEG_25G_IEEE,
113 	NFP_ANEG_DISABLED,
114 };
115 
116 enum nfp_eth_fec {
117 	NFP_FEC_AUTO_BIT = 0,
118 	NFP_FEC_BASER_BIT,
119 	NFP_FEC_REED_SOLOMON_BIT,
120 	NFP_FEC_DISABLED_BIT,
121 	NFP_FEC_INVALID_BIT,
122 };
123 
124 #define NFP_FEC_AUTO            RTE_BIT32(NFP_FEC_AUTO_BIT)
125 #define NFP_FEC_BASER           RTE_BIT32(NFP_FEC_BASER_BIT)
126 #define NFP_FEC_REED_SOLOMON    RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT)
127 #define NFP_FEC_DISABLED        RTE_BIT32(NFP_FEC_DISABLED_BIT)
128 
129 /* ETH table information */
130 struct nfp_eth_table {
131 	uint32_t count;     /**< Number of table entries */
132 	uint32_t max_index; /**< Max of @index fields of all @ports */
133 	struct nfp_eth_table_port {
134 		/** Port index according to legacy ethX numbering */
135 		uint32_t eth_index;
136 		uint32_t index;  /**< Chip-wide first channel index */
137 		uint32_t nbi;    /**< NBI index */
138 		uint32_t base;   /**< First channel index (within NBI) */
139 		uint32_t lanes;  /**< Number of channels */
140 		uint32_t speed;  /**< Interface speed (in Mbps) */
141 
142 		uint32_t interface;  /**< Interface (module) plugged in */
143 		enum nfp_eth_media media; /**< Media type of the @interface */
144 
145 		enum nfp_eth_fec fec;     /**< Forward Error Correction mode */
146 		enum nfp_eth_fec act_fec; /**< Active Forward Error Correction mode */
147 		enum nfp_eth_aneg aneg;   /**< Auto negotiation mode */
148 
149 		struct rte_ether_addr mac_addr;  /**< Interface MAC address */
150 
151 		uint8_t label_port;    /**< Port id */
152 		/** Id of interface within port (for split ports) */
153 		uint8_t label_subport;
154 
155 		bool enabled;     /**< Enable port */
156 		bool tx_enabled;  /**< Enable TX */
157 		bool rx_enabled;  /**< Enable RX */
158 		bool supp_aneg;   /**< Support auto negotiation */
159 
160 		bool override_changed;  /**< Media reconfig pending */
161 		bool rx_pause_enabled;  /**< Switch of RX pause frame */
162 		bool tx_pause_enabled;  /**< Switch of TX pause frame */
163 
164 		uint8_t port_type;    /**< One of %PORT_* */
165 		/** Sum of lanes of all subports of this port */
166 		uint32_t port_lanes;
167 
168 		bool is_split;   /**< Split port */
169 
170 		uint32_t fec_modes_supported;  /**< Bitmap of FEC modes supported */
171 	} ports[]; /**< Table of ports */
172 };
173 
174 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
175 
176 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, bool enable);
177 int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, bool configured);
178 int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode);
179 
180 int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size);
181 int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf,
182 		size_t size);
183 void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries,
184 		uint32_t idx);
185 void nfp_nsp_config_clear_state(struct nfp_nsp *state);
186 void nfp_nsp_config_set_modified(struct nfp_nsp *state, bool modified);
187 void *nfp_nsp_config_entries(struct nfp_nsp *state);
188 struct nfp_cpp *nfp_nsp_cpp(struct nfp_nsp *state);
189 bool nfp_nsp_config_modified(struct nfp_nsp *state);
190 uint32_t nfp_nsp_config_idx(struct nfp_nsp *state);
191 int nfp_nsp_hwinfo_set(struct nfp_nsp *state,
192 		const void *buf,
193 		size_t size);
194 int nfp_nsp_read_media(struct nfp_nsp *state,
195 		void *buf,
196 		size_t size);
197 
198 static inline bool
199 nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port)
200 {
201 	return eth_port->fec_modes_supported != 0;
202 }
203 
204 static inline uint32_t
205 nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port)
206 {
207 	return eth_port->fec_modes_supported;
208 }
209 
210 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx);
211 int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
212 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
213 
214 int nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
215 int nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed);
216 int nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes);
217 int nfp_eth_set_tx_pause(struct nfp_nsp *nsp, bool tx_pause);
218 int nfp_eth_set_rx_pause(struct nfp_nsp *nsp, bool rx_pause);
219 int nfp_eth_set_idmode(struct nfp_cpp *cpp, uint32_t idx, bool is_on);
220 
221 /* NSP static information */
222 struct nfp_nsp_identify {
223 	char version[40];      /**< Opaque version string */
224 	uint8_t flags;         /**< Version flags */
225 	uint8_t br_primary;    /**< Branch id of primary bootloader */
226 	uint8_t br_secondary;  /**< Branch id of secondary bootloader */
227 	uint8_t br_nsp;        /**< Branch id of NSP */
228 	uint16_t primary;      /**< Version of primary bootloader */
229 	uint16_t secondary;    /**< Version id of secondary bootloader */
230 	uint16_t nsp;          /**< Version id of NSP */
231 	uint64_t sensor_mask;  /**< Mask of present sensors available on NIC */
232 };
233 
234 struct nfp_nsp_identify *nfp_nsp_identify(struct nfp_nsp *nsp);
235 
236 enum nfp_nsp_sensor_id {
237 	NFP_SENSOR_CHIP_TEMPERATURE,
238 	NFP_SENSOR_ASSEMBLY_POWER,
239 	NFP_SENSOR_ASSEMBLY_12V_POWER,
240 	NFP_SENSOR_ASSEMBLY_3V3_POWER,
241 };
242 
243 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
244 		uint32_t *val);
245 bool nfp_nsp_fw_loaded(struct nfp_nsp *state);
246 int nfp_nsp_load_stored_fw(struct nfp_nsp *state);
247 int nfp_nsp_hwinfo_lookup(struct nfp_nsp *state, void *buf, uint32_t size);
248 int nfp_nsp_hwinfo_lookup_optional(struct nfp_nsp *state,
249 		void *buf, size_t size, const char *default_val);
250 int nfp_nsp_read_module_eeprom(struct nfp_nsp *state, int eth_index,
251 		uint32_t offset, void *data,
252 		uint32_t len, uint32_t *read_len);
253 
254 /* The buf used to receive bitmap of link modes */
255 struct nfp_eth_media_buf {
256 	uint8_t eth_index;
257 	uint8_t reserved[7];
258 	uint64_t supported_modes[2];
259 	uint64_t reserved_2[2];
260 };
261 
262 /* Link modes about RJ45 haven't been used, so there's no mapping to them */
263 enum nfp_link_mode_list {
264 	NFP_MEDIA_W0_RJ45_10M,
265 	NFP_MEDIA_W0_RJ45_10M_HD,
266 	NFP_MEDIA_W0_RJ45_100M,
267 	NFP_MEDIA_W0_RJ45_100M_HD,
268 	NFP_MEDIA_W0_RJ45_1G,
269 	NFP_MEDIA_W0_RJ45_2P5G,
270 	NFP_MEDIA_W0_RJ45_5G,
271 	NFP_MEDIA_W0_RJ45_10G,
272 	NFP_MEDIA_1000BASE_CX,
273 	NFP_MEDIA_1000BASE_KX,
274 	NFP_MEDIA_10GBASE_KX4,
275 	NFP_MEDIA_10GBASE_KR,
276 	NFP_MEDIA_10GBASE_CX4,
277 	NFP_MEDIA_10GBASE_CR,
278 	NFP_MEDIA_10GBASE_SR,
279 	NFP_MEDIA_10GBASE_ER,
280 	NFP_MEDIA_25GBASE_KR,
281 	NFP_MEDIA_25GBASE_KR_S,
282 	NFP_MEDIA_25GBASE_CR,
283 	NFP_MEDIA_25GBASE_CR_S,
284 	NFP_MEDIA_25GBASE_SR,
285 	NFP_MEDIA_40GBASE_CR4,
286 	NFP_MEDIA_40GBASE_KR4,
287 	NFP_MEDIA_40GBASE_SR4,
288 	NFP_MEDIA_40GBASE_LR4,
289 	NFP_MEDIA_50GBASE_KR,
290 	NFP_MEDIA_50GBASE_SR,
291 	NFP_MEDIA_50GBASE_CR,
292 	NFP_MEDIA_50GBASE_LR,
293 	NFP_MEDIA_50GBASE_ER,
294 	NFP_MEDIA_50GBASE_FR,
295 	NFP_MEDIA_100GBASE_KR4,
296 	NFP_MEDIA_100GBASE_SR4,
297 	NFP_MEDIA_100GBASE_CR4,
298 	NFP_MEDIA_100GBASE_KP4,
299 	NFP_MEDIA_100GBASE_CR10,
300 	NFP_MEDIA_10GBASE_LR,
301 	NFP_MEDIA_25GBASE_LR,
302 	NFP_MEDIA_25GBASE_ER,
303 	NFP_MEDIA_LINK_MODES_NUMBER
304 };
305 
306 #endif /* __NSP_NSP_H__ */
307