Branch data Line data Source code
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 : : struct nfp_nsp;
12 : :
13 : : struct nfp_nsp *nfp_nsp_open(struct nfp_cpp *cpp);
14 : : void nfp_nsp_close(struct nfp_nsp *state);
15 : : uint16_t nfp_nsp_get_abi_ver_major(struct nfp_nsp *state);
16 : : uint16_t nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state);
17 : : int nfp_nsp_wait(struct nfp_nsp *state);
18 : : int nfp_nsp_device_soft_reset(struct nfp_nsp *state);
19 : : int nfp_nsp_load_fw(struct nfp_nsp *state, void *buf, size_t size);
20 : : int nfp_nsp_mac_reinit(struct nfp_nsp *state);
21 : : int nfp_nsp_read_identify(struct nfp_nsp *state, void *buf, size_t size);
22 : : int nfp_nsp_read_sensors(struct nfp_nsp *state, uint32_t sensor_mask,
23 : : void *buf, size_t size);
24 : :
25 : : static inline bool
26 : : nfp_nsp_has_mac_reinit(struct nfp_nsp *state)
27 : : {
28 : : return nfp_nsp_get_abi_ver_minor(state) > 20;
29 : : }
30 : :
31 : : static inline bool
32 : : nfp_nsp_has_stored_fw_load(struct nfp_nsp *state)
33 : : {
34 : 0 : return nfp_nsp_get_abi_ver_minor(state) > 23;
35 : : }
36 : :
37 : : static inline bool
38 : : nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state)
39 : : {
40 : : return nfp_nsp_get_abi_ver_minor(state) > 24;
41 : : }
42 : :
43 : : static inline bool
44 : : nfp_nsp_has_hwinfo_set(struct nfp_nsp *state)
45 : : {
46 : : return nfp_nsp_get_abi_ver_minor(state) > 25;
47 : : }
48 : :
49 : : static inline bool
50 : : nfp_nsp_has_fw_loaded(struct nfp_nsp *state)
51 : : {
52 : : return nfp_nsp_get_abi_ver_minor(state) > 25;
53 : : }
54 : :
55 : : static inline bool
56 : : nfp_nsp_has_versions(struct nfp_nsp *state)
57 : : {
58 : : return nfp_nsp_get_abi_ver_minor(state) > 27;
59 : : }
60 : :
61 : : static inline bool
62 : : nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state)
63 : : {
64 : : return nfp_nsp_get_abi_ver_minor(state) > 28;
65 : : }
66 : :
67 : : static inline bool
68 : : 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 : : NFP_FEC_INVALID_BIT,
104 : : };
105 : :
106 : : #define NFP_FEC_AUTO RTE_BIT32(NFP_FEC_AUTO_BIT)
107 : : #define NFP_FEC_BASER RTE_BIT32(NFP_FEC_BASER_BIT)
108 : : #define NFP_FEC_REED_SOLOMON RTE_BIT32(NFP_FEC_REED_SOLOMON_BIT)
109 : : #define NFP_FEC_DISABLED RTE_BIT32(NFP_FEC_DISABLED_BIT)
110 : :
111 : : /* ETH table information */
112 : : struct nfp_eth_table {
113 : : uint32_t count; /**< Number of table entries */
114 : : uint32_t max_index; /**< Max of @index fields of all @ports */
115 : : struct nfp_eth_table_port {
116 : : /** Port index according to legacy ethX numbering */
117 : : uint32_t eth_index;
118 : : uint32_t index; /**< Chip-wide first channel index */
119 : : uint32_t nbi; /**< NBI index */
120 : : uint32_t base; /**< First channel index (within NBI) */
121 : : uint32_t lanes; /**< Number of channels */
122 : : uint32_t speed; /**< Interface speed (in Mbps) */
123 : :
124 : : uint32_t interface; /**< Interface (module) plugged in */
125 : : enum nfp_eth_media media; /**< Media type of the @interface */
126 : :
127 : : enum nfp_eth_fec fec; /**< Forward Error Correction mode */
128 : : enum nfp_eth_fec act_fec; /**< Active Forward Error Correction mode */
129 : : enum nfp_eth_aneg aneg; /**< Auto negotiation mode */
130 : :
131 : : struct rte_ether_addr mac_addr; /**< Interface MAC address */
132 : :
133 : : uint8_t label_port; /**< Port id */
134 : : /** Id of interface within port (for split ports) */
135 : : uint8_t label_subport;
136 : :
137 : : bool enabled; /**< Enable port */
138 : : bool tx_enabled; /**< Enable TX */
139 : : bool rx_enabled; /**< Enable RX */
140 : : bool supp_aneg; /**< Support auto negotiation */
141 : :
142 : : bool override_changed; /**< Media reconfig pending */
143 : : bool rx_pause_enabled; /**< Switch of RX pause frame */
144 : : bool tx_pause_enabled; /**< Switch of TX pause frame */
145 : :
146 : : uint8_t port_type; /**< One of %PORT_* */
147 : : /** Sum of lanes of all subports of this port */
148 : : uint32_t port_lanes;
149 : :
150 : : bool is_split; /**< Split port */
151 : :
152 : : uint32_t fec_modes_supported; /**< Bitmap of FEC modes supported */
153 : : } ports[]; /**< Table of ports */
154 : : };
155 : :
156 : : struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
157 : :
158 : : int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, uint32_t idx, bool enable);
159 : : int nfp_eth_set_configured(struct nfp_cpp *cpp, uint32_t idx, bool configured);
160 : : int nfp_eth_set_fec(struct nfp_cpp *cpp, uint32_t idx, enum nfp_eth_fec mode);
161 : :
162 : : int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, size_t size);
163 : : int nfp_nsp_write_eth_table(struct nfp_nsp *state, const void *buf,
164 : : size_t size);
165 : : void nfp_nsp_config_set_state(struct nfp_nsp *state, void *entries,
166 : : uint32_t idx);
167 : : void nfp_nsp_config_clear_state(struct nfp_nsp *state);
168 : : void nfp_nsp_config_set_modified(struct nfp_nsp *state, bool modified);
169 : : void *nfp_nsp_config_entries(struct nfp_nsp *state);
170 : : struct nfp_cpp *nfp_nsp_cpp(struct nfp_nsp *state);
171 : : bool nfp_nsp_config_modified(struct nfp_nsp *state);
172 : : uint32_t nfp_nsp_config_idx(struct nfp_nsp *state);
173 : : int nfp_nsp_hwinfo_set(struct nfp_nsp *state,
174 : : const void *buf,
175 : : size_t size);
176 : : int nfp_nsp_read_media(struct nfp_nsp *state,
177 : : void *buf,
178 : : size_t size);
179 : :
180 : : static inline bool
181 : : nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port)
182 : : {
183 [ # # ]: 0 : return eth_port->fec_modes_supported != 0;
184 : : }
185 : :
186 : : static inline uint32_t
187 : : nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port)
188 : : {
189 [ # # # # ]: 0 : return eth_port->fec_modes_supported;
190 : : }
191 : :
192 : : struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, uint32_t idx);
193 : : int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
194 : : void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
195 : :
196 : : int nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
197 : : int nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed);
198 : : int nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes);
199 : : int nfp_eth_set_tx_pause(struct nfp_nsp *nsp, bool tx_pause);
200 : : int nfp_eth_set_rx_pause(struct nfp_nsp *nsp, bool rx_pause);
201 : :
202 : : /* NSP static information */
203 : : struct nfp_nsp_identify {
204 : : char version[40]; /**< Opaque version string */
205 : : uint8_t flags; /**< Version flags */
206 : : uint8_t br_primary; /**< Branch id of primary bootloader */
207 : : uint8_t br_secondary; /**< Branch id of secondary bootloader */
208 : : uint8_t br_nsp; /**< Branch id of NSP */
209 : : uint16_t primary; /**< Version of primary bootloader */
210 : : uint16_t secondary; /**< Version id of secondary bootloader */
211 : : uint16_t nsp; /**< Version id of NSP */
212 : : uint64_t sensor_mask; /**< Mask of present sensors available on NIC */
213 : : };
214 : :
215 : : struct nfp_nsp_identify *nfp_nsp_identify(struct nfp_nsp *nsp);
216 : :
217 : : enum nfp_nsp_sensor_id {
218 : : NFP_SENSOR_CHIP_TEMPERATURE,
219 : : NFP_SENSOR_ASSEMBLY_POWER,
220 : : NFP_SENSOR_ASSEMBLY_12V_POWER,
221 : : NFP_SENSOR_ASSEMBLY_3V3_POWER,
222 : : };
223 : :
224 : : int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
225 : : uint32_t *val);
226 : : bool nfp_nsp_fw_loaded(struct nfp_nsp *state);
227 : :
228 : : /* The buf used to receive bitmap of link modes */
229 : : struct nfp_eth_media_buf {
230 : : uint8_t eth_index;
231 : : uint8_t reserved[7];
232 : : uint64_t supported_modes[2];
233 : : uint64_t reserved_2[2];
234 : : };
235 : :
236 : : /* Link modes about RJ45 haven't been used, so there's no mapping to them */
237 : : enum nfp_link_mode_list {
238 : : NFP_MEDIA_W0_RJ45_10M,
239 : : NFP_MEDIA_W0_RJ45_10M_HD,
240 : : NFP_MEDIA_W0_RJ45_100M,
241 : : NFP_MEDIA_W0_RJ45_100M_HD,
242 : : NFP_MEDIA_W0_RJ45_1G,
243 : : NFP_MEDIA_W0_RJ45_2P5G,
244 : : NFP_MEDIA_W0_RJ45_5G,
245 : : NFP_MEDIA_W0_RJ45_10G,
246 : : NFP_MEDIA_1000BASE_CX,
247 : : NFP_MEDIA_1000BASE_KX,
248 : : NFP_MEDIA_10GBASE_KX4,
249 : : NFP_MEDIA_10GBASE_KR,
250 : : NFP_MEDIA_10GBASE_CX4,
251 : : NFP_MEDIA_10GBASE_CR,
252 : : NFP_MEDIA_10GBASE_SR,
253 : : NFP_MEDIA_10GBASE_ER,
254 : : NFP_MEDIA_25GBASE_KR,
255 : : NFP_MEDIA_25GBASE_KR_S,
256 : : NFP_MEDIA_25GBASE_CR,
257 : : NFP_MEDIA_25GBASE_CR_S,
258 : : NFP_MEDIA_25GBASE_SR,
259 : : NFP_MEDIA_40GBASE_CR4,
260 : : NFP_MEDIA_40GBASE_KR4,
261 : : NFP_MEDIA_40GBASE_SR4,
262 : : NFP_MEDIA_40GBASE_LR4,
263 : : NFP_MEDIA_50GBASE_KR,
264 : : NFP_MEDIA_50GBASE_SR,
265 : : NFP_MEDIA_50GBASE_CR,
266 : : NFP_MEDIA_50GBASE_LR,
267 : : NFP_MEDIA_50GBASE_ER,
268 : : NFP_MEDIA_50GBASE_FR,
269 : : NFP_MEDIA_100GBASE_KR4,
270 : : NFP_MEDIA_100GBASE_SR4,
271 : : NFP_MEDIA_100GBASE_CR4,
272 : : NFP_MEDIA_100GBASE_KP4,
273 : : NFP_MEDIA_100GBASE_CR10,
274 : : NFP_MEDIA_10GBASE_LR,
275 : : NFP_MEDIA_25GBASE_LR,
276 : : NFP_MEDIA_25GBASE_ER,
277 : : NFP_MEDIA_LINK_MODES_NUMBER
278 : : };
279 : :
280 : : #endif /* __NSP_NSP_H__ */
|