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_read_module_eeprom(struct nfp_nsp *state, int eth_index,
26 			       unsigned int offset, void *data,
27 			       unsigned int len, unsigned int *read_len);
28 
29 static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state)
30 {
31 	return nfp_nsp_get_abi_ver_minor(state) > 20;
32 }
33 
34 static inline bool nfp_nsp_has_stored_fw_load(struct nfp_nsp *state)
35 {
36 	return nfp_nsp_get_abi_ver_minor(state) > 23;
37 }
38 
39 static inline bool nfp_nsp_has_hwinfo_lookup(struct nfp_nsp *state)
40 {
41 	return nfp_nsp_get_abi_ver_minor(state) > 24;
42 }
43 
44 static inline bool nfp_nsp_has_versions(struct nfp_nsp *state)
45 {
46 	return nfp_nsp_get_abi_ver_minor(state) > 27;
47 }
48 
49 static inline bool nfp_nsp_has_read_module_eeprom(struct nfp_nsp *state)
50 {
51 	return nfp_nsp_get_abi_ver_minor(state) > 28;
52 }
53 
54 enum nfp_eth_interface {
55 	NFP_INTERFACE_NONE	= 0,
56 	NFP_INTERFACE_SFP	= 1,
57 	NFP_INTERFACE_SFPP	= 10,
58 	NFP_INTERFACE_SFP28	= 28,
59 	NFP_INTERFACE_QSFP	= 40,
60 	NFP_INTERFACE_RJ45	= 45,
61 	NFP_INTERFACE_CXP	= 100,
62 	NFP_INTERFACE_QSFP28	= 112,
63 };
64 
65 enum nfp_eth_media {
66 	NFP_MEDIA_DAC_PASSIVE = 0,
67 	NFP_MEDIA_DAC_ACTIVE,
68 	NFP_MEDIA_FIBRE,
69 };
70 
71 enum nfp_eth_aneg {
72 	NFP_ANEG_AUTO = 0,
73 	NFP_ANEG_SEARCH,
74 	NFP_ANEG_25G_CONSORTIUM,
75 	NFP_ANEG_25G_IEEE,
76 	NFP_ANEG_DISABLED,
77 };
78 
79 enum nfp_eth_fec {
80 	NFP_FEC_AUTO_BIT = 0,
81 	NFP_FEC_BASER_BIT,
82 	NFP_FEC_REED_SOLOMON_BIT,
83 	NFP_FEC_DISABLED_BIT,
84 };
85 
86 #define NFP_FEC_AUTO		BIT(NFP_FEC_AUTO_BIT)
87 #define NFP_FEC_BASER		BIT(NFP_FEC_BASER_BIT)
88 #define NFP_FEC_REED_SOLOMON	BIT(NFP_FEC_REED_SOLOMON_BIT)
89 #define NFP_FEC_DISABLED	BIT(NFP_FEC_DISABLED_BIT)
90 
91 /**
92  * struct nfp_eth_table - ETH table information
93  * @count:	number of table entries
94  * @max_index:	max of @index fields of all @ports
95  * @ports:	table of ports
96  *
97  * @ports.eth_index:	port index according to legacy ethX numbering
98  * @ports.index:	chip-wide first channel index
99  * @ports.nbi:		NBI index
100  * @ports.base:		first channel index (within NBI)
101  * @ports.lanes:	number of channels
102  * @ports.speed:	interface speed (in Mbps)
103  * @ports.interface:	interface (module) plugged in
104  * @ports.media:	media type of the @interface
105  * @ports.fec:		forward error correction mode
106  * @ports.aneg:		auto negotiation mode
107  * @ports.mac_addr:	interface MAC address
108  * @ports.label_port:	port id
109  * @ports.label_subport:  id of interface within port (for split ports)
110  * @ports.enabled:	is enabled?
111  * @ports.tx_enabled:	is TX enabled?
112  * @ports.rx_enabled:	is RX enabled?
113  * @ports.override_changed: is media reconfig pending?
114  *
115  * @ports.port_type:	one of %PORT_* defines for ethtool
116  * @ports.port_lanes:	total number of lanes on the port (sum of lanes of all
117  *			subports)
118  * @ports.is_split:	is interface part of a split port
119  * @ports.fec_modes_supported:	bitmap of FEC modes supported
120  */
121 struct nfp_eth_table {
122 	unsigned int count;
123 	unsigned int max_index;
124 	struct nfp_eth_table_port {
125 		unsigned int eth_index;
126 		unsigned int index;
127 		unsigned int nbi;
128 		unsigned int base;
129 		unsigned int lanes;
130 		unsigned int speed;
131 
132 		unsigned int interface;
133 		enum nfp_eth_media media;
134 
135 		enum nfp_eth_fec fec;
136 		enum nfp_eth_aneg aneg;
137 
138 		u8 mac_addr[ETH_ALEN];
139 
140 		u8 label_port;
141 		u8 label_subport;
142 
143 		bool enabled;
144 		bool tx_enabled;
145 		bool rx_enabled;
146 
147 		bool override_changed;
148 
149 		/* Computed fields */
150 		u8 port_type;
151 
152 		unsigned int port_lanes;
153 
154 		bool is_split;
155 
156 		unsigned int fec_modes_supported;
157 	} ports[0];
158 };
159 
160 struct nfp_eth_table *nfp_eth_read_ports(struct nfp_cpp *cpp);
161 struct nfp_eth_table *
162 __nfp_eth_read_ports(struct nfp_cpp *cpp, struct nfp_nsp *nsp);
163 
164 int nfp_eth_set_mod_enable(struct nfp_cpp *cpp, unsigned int idx, bool enable);
165 int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx,
166 			   bool configed);
167 int
168 nfp_eth_set_fec(struct nfp_cpp *cpp, unsigned int idx, enum nfp_eth_fec mode);
169 
170 static inline bool nfp_eth_can_support_fec(struct nfp_eth_table_port *eth_port)
171 {
172 	return !!eth_port->fec_modes_supported;
173 }
174 
175 static inline unsigned int
176 nfp_eth_supported_fec_modes(struct nfp_eth_table_port *eth_port)
177 {
178 	return eth_port->fec_modes_supported;
179 }
180 
181 struct nfp_nsp *nfp_eth_config_start(struct nfp_cpp *cpp, unsigned int idx);
182 int nfp_eth_config_commit_end(struct nfp_nsp *nsp);
183 void nfp_eth_config_cleanup_end(struct nfp_nsp *nsp);
184 
185 int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode);
186 int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed);
187 int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes);
188 
189 /**
190  * struct nfp_nsp_identify - NSP static information
191  * @version:      opaque version string
192  * @flags:        version flags
193  * @br_primary:   branch id of primary bootloader
194  * @br_secondary: branch id of secondary bootloader
195  * @br_nsp:       branch id of NSP
196  * @primary:      version of primarary bootloader
197  * @secondary:    version id of secondary bootloader
198  * @nsp:          version id of NSP
199  * @sensor_mask:  mask of present sensors available on NIC
200  */
201 struct nfp_nsp_identify {
202 	char version[40];
203 	u8 flags;
204 	u8 br_primary;
205 	u8 br_secondary;
206 	u8 br_nsp;
207 	u16 primary;
208 	u16 secondary;
209 	u16 nsp;
210 	u64 sensor_mask;
211 };
212 
213 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp);
214 
215 enum nfp_nsp_sensor_id {
216 	NFP_SENSOR_CHIP_TEMPERATURE,
217 	NFP_SENSOR_ASSEMBLY_POWER,
218 	NFP_SENSOR_ASSEMBLY_12V_POWER,
219 	NFP_SENSOR_ASSEMBLY_3V3_POWER,
220 };
221 
222 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
223 			  long *val);
224 
225 #define NFP_NSP_VERSION_BUFSZ	1024 /* reasonable size, not in the ABI */
226 
227 enum nfp_nsp_versions {
228 	NFP_VERSIONS_BSP,
229 	NFP_VERSIONS_CPLD,
230 	NFP_VERSIONS_APP,
231 	NFP_VERSIONS_BUNDLE,
232 	NFP_VERSIONS_UNDI,
233 	NFP_VERSIONS_NCSI,
234 	NFP_VERSIONS_CFGR,
235 };
236 
237 int nfp_nsp_versions(struct nfp_nsp *state, void *buf, unsigned int size);
238 const char *nfp_nsp_versions_get(enum nfp_nsp_versions id, bool flash,
239 				 const u8 *buf, unsigned int size);
240 #endif
241