xref: /freebsd/sys/dev/ixl/ixl_pf.h (revision 85732ac8)
1 /******************************************************************************
2 
3   Copyright (c) 2013-2018, Intel Corporation
4   All rights reserved.
5 
6   Redistribution and use in source and binary forms, with or without
7   modification, are permitted provided that the following conditions are met:
8 
9    1. Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11 
12    2. Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in the
14       documentation and/or other materials provided with the distribution.
15 
16    3. Neither the name of the Intel Corporation nor the names of its
17       contributors may be used to endorse or promote products derived from
18       this software without specific prior written permission.
19 
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   POSSIBILITY OF SUCH DAMAGE.
31 
32 ******************************************************************************/
33 /*$FreeBSD$*/
34 
35 
36 #ifndef _IXL_PF_H_
37 #define _IXL_PF_H_
38 
39 #include "ixl.h"
40 #include "ixl_pf_qmgr.h"
41 
42 #define	VF_FLAG_ENABLED			0x01
43 #define	VF_FLAG_SET_MAC_CAP		0x02
44 #define	VF_FLAG_VLAN_CAP		0x04
45 #define	VF_FLAG_PROMISC_CAP		0x08
46 #define	VF_FLAG_MAC_ANTI_SPOOF		0x10
47 
48 #define IXL_ICR0_CRIT_ERR_MASK 			\
49     (I40E_PFINT_ICR0_PCI_EXCEPTION_MASK | 	\
50      I40E_PFINT_ICR0_ECC_ERR_MASK | 		\
51      I40E_PFINT_ICR0_PE_CRITERR_MASK)
52 
53 /* VF Interrupts */
54 #define IXL_VPINT_LNKLSTN_REG(hw, vector, vf_num) \
55 	I40E_VPINT_LNKLSTN(((vector) - 1) + \
56 	    (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num)))
57 
58 #define IXL_VFINT_DYN_CTLN_REG(hw, vector, vf_num) \
59 	I40E_VFINT_DYN_CTLN(((vector) - 1) + \
60 	    (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num)))
61 
62 /* Used in struct ixl_pf's state field */
63 enum ixl_pf_state {
64 	IXL_PF_STATE_ADAPTER_RESETTING	= (1 << 0),
65 	IXL_PF_STATE_MDD_PENDING	= (1 << 1),
66 	IXL_PF_STATE_PF_RESET_REQ	= (1 << 2),
67 	IXL_PF_STATE_VF_RESET_REQ	= (1 << 3),
68 	IXL_PF_STATE_PF_CRIT_ERR	= (1 << 4),
69 	IXL_PF_STATE_CORE_RESET_REQ	= (1 << 5),
70 	IXL_PF_STATE_GLOB_RESET_REQ	= (1 << 6),
71 	IXL_PF_STATE_EMP_RESET_REQ	= (1 << 7),
72 	IXL_PF_STATE_FW_LLDP_DISABLED	= (1 << 8),
73 };
74 
75 struct ixl_vf {
76 	struct ixl_vsi		vsi;
77 	u32			vf_flags;
78 	u32			num_mdd_events;
79 
80 	u8			mac[ETHER_ADDR_LEN];
81 	u16			vf_num;
82 	u32			version;
83 
84 	struct ixl_pf_qtag	qtag;
85 	struct sysctl_ctx_list	ctx;
86 };
87 
88 /* Physical controller structure */
89 struct ixl_pf {
90 	struct ixl_vsi		vsi;
91 
92 	struct i40e_hw		hw;
93 	struct i40e_osdep	osdep;
94 	device_t		dev;
95 
96 	struct resource		*pci_mem;
97 
98 #ifdef IXL_IW
99 	int			iw_msix;
100 	bool			iw_enabled;
101 #endif
102 	u32			state;
103 	u8			supported_speeds;
104 
105 	struct ixl_pf_qmgr	qmgr;
106 	struct ixl_pf_qtag	qtag;
107 
108 	/* Tunable values */
109 	bool			enable_tx_fc_filter;
110 	int			dynamic_rx_itr;
111 	int			dynamic_tx_itr;
112 	int			tx_itr;
113 	int			rx_itr;
114 	int			enable_vf_loopback;
115 
116 	bool			link_up;
117 	int			advertised_speed;
118 	int			fc; /* link flow ctrl setting */
119 	enum ixl_dbg_mask	dbg_mask;
120 	bool			has_i2c;
121 
122 	/* Misc stats maintained by the driver */
123 	u64			admin_irq;
124 
125 	/* Statistics from hw */
126 	struct i40e_hw_port_stats 	stats;
127 	struct i40e_hw_port_stats	stats_offsets;
128 	bool 				stat_offsets_loaded;
129 
130 	/* I2C access methods */
131 	u8			i2c_access_method;
132 	s32	(*read_i2c_byte)(struct ixl_pf *pf, u8 byte_offset,
133 	    u8 dev_addr, u8 *data);
134 	s32	(*write_i2c_byte)(struct ixl_pf *pf, u8 byte_offset,
135 	    u8 dev_addr, u8 data);
136 
137 	/* SR-IOV */
138 	struct ixl_vf		*vfs;
139 	int			num_vfs;
140 	uint16_t		veb_seid;
141 	struct if_irq		iov_irq;
142 };
143 
144 /*
145  * Defines used for NVM update ioctls.
146  * This value is used in the Solaris tool, too.
147  */
148 #define I40E_NVM_ACCESS \
149      (((((((('E' << 4) + '1') << 4) + 'K') << 4) + 'G') << 4) | 5)
150 
151 #define IXL_DEFAULT_PHY_INT_MASK \
152      ((~(I40E_AQ_EVENT_LINK_UPDOWN | I40E_AQ_EVENT_MODULE_QUAL_FAIL \
153       | I40E_AQ_EVENT_MEDIA_NA)) & 0x3FF)
154 
155 /*** Sysctl help messages; displayed with "sysctl -d" ***/
156 
157 #define IXL_SYSCTL_HELP_SET_ADVERTISE	\
158 "\nControl advertised link speed.\n"	\
159 "Flags:\n"				\
160 "\t 0x1 - advertise 100M\n"		\
161 "\t 0x2 - advertise 1G\n"		\
162 "\t 0x4 - advertise 10G\n"		\
163 "\t 0x8 - advertise 20G\n"		\
164 "\t0x10 - advertise 25G\n"		\
165 "\t0x20 - advertise 40G\n\n"		\
166 "Set to 0 to disable link.\n"		\
167 "Use \"sysctl -x\" to view flags properly."
168 
169 #define IXL_SYSCTL_HELP_SUPPORTED_SPEED	\
170 "\nSupported link speeds.\n"		\
171 "Flags:\n"				\
172 "\t 0x1 - 100M\n"			\
173 "\t 0x2 - 1G\n"				\
174 "\t 0x4 - 10G\n"			\
175 "\t 0x8 - 20G\n"			\
176 "\t0x10 - 25G\n"			\
177 "\t0x20 - 40G\n\n"			\
178 "Use \"sysctl -x\" to view flags properly."
179 
180 #define IXL_SYSCTL_HELP_FC				\
181 "\nSet flow control mode using the values below.\n" 	\
182 "\t0 - off\n" 						\
183 "\t1 - rx pause\n" 					\
184 "\t2 - tx pause\n"					\
185 "\t3 - tx and rx pause"
186 
187 #define IXL_SYSCTL_HELP_LINK_STATUS					\
188 "\nExecutes a \"Get Link Status\" command on the Admin Queue, and displays" \
189 " the response."
190 
191 #define IXL_SYSCTL_HELP_FW_LLDP		\
192 "\nFW LLDP engine:\n"			\
193 "\t0 - disable\n"			\
194 "\t1 - enable\n"
195 
196 #define IXL_SYSCTL_HELP_READ_I2C		\
197 "\nRead a byte from I2C bus\n"			\
198 "Input: 32-bit value\n"				\
199 "\tbits 0-7:   device address (0xA0 or 0xA2)\n"	\
200 "\tbits 8-15:  offset (0-255)\n"		\
201 "\tbits 16-31: unused\n"			\
202 "Output: 8-bit value read"
203 
204 #define IXL_SYSCTL_HELP_WRITE_I2C		\
205 "\nWrite a byte to the I2C bus\n"		\
206 "Input: 32-bit value\n"				\
207 "\tbits 0-7:   device address (0xA0 or 0xA2)\n"	\
208 "\tbits 8-15:  offset (0-255)\n"		\
209 "\tbits 16-23: value to write\n"		\
210 "\tbits 24-31: unused\n"			\
211 "Output: 8-bit value written"
212 
213 #define IXL_SYSCTL_HELP_I2C_METHOD		\
214 "\nI2C access method that driver will use:\n"	\
215 "\t0 - best available method\n"			\
216 "\t1 - bit bang via I2CPARAMS register\n"	\
217 "\t2 - register read/write via I2CCMD register\n" \
218 "\t3 - Use Admin Queue command (best)\n"	\
219 "Using the Admin Queue is only supported on 710 devices with FW version 1.7 or higher"
220 
221 #define IXL_SYSCTL_HELP_VF_LOOPBACK		\
222 "\nDetermines mode that embedded device switch will use when SR-IOV is initialized:\n"	\
223 "\t0 - Disable (VEPA)\n"			\
224 "\t1 - Enable (VEB)\n"				\
225 "Enabling this will allow VFs in separate VMs to communicate over the hardware bridge."
226 
227 extern const char * const ixl_fc_string[6];
228 
229 MALLOC_DECLARE(M_IXL);
230 
231 /*** Functions / Macros ***/
232 /* Adjust the level here to 10 or over to print stats messages */
233 #define	I40E_VC_DEBUG(p, level, ...)				\
234 	do {							\
235 		if (level < 10)					\
236 			ixl_dbg(p, IXL_DBG_IOV_VC, ##__VA_ARGS__); \
237 	} while (0)
238 
239 #define	i40e_send_vf_nack(pf, vf, op, st) \
240 	ixl_send_vf_nack_msg((pf), (vf), (op), (st), __FILE__, __LINE__)
241 
242 /* Debug printing */
243 #define ixl_dbg(pf, m, s, ...) ixl_debug_core(pf->dev, pf->dbg_mask, m, s, ##__VA_ARGS__)
244 #define ixl_dbg_info(pf, s, ...) ixl_debug_core(pf->dev, pf->dbg_mask, IXL_DBG_INFO, s, ##__VA_ARGS__)
245 #define ixl_dbg_filter(pf, s, ...) ixl_debug_core(pf->dev, pf->dbg_mask, IXL_DBG_FILTER, s, ##__VA_ARGS__)
246 #define ixl_dbg_iov(pf, s, ...) ixl_debug_core(pf->dev, pf->dbg_mask, IXL_DBG_IOV, s, ##__VA_ARGS__)
247 
248 /* PF-only function declarations */
249 int	ixl_setup_interface(device_t, struct ixl_pf *);
250 void	ixl_print_nvm_cmd(device_t, struct i40e_nvm_access *);
251 char *	ixl_aq_speed_to_str(enum i40e_aq_link_speed);
252 
253 void	ixl_handle_que(void *context, int pending);
254 
255 void	ixl_init(void *);
256 void	ixl_local_timer(void *);
257 void	ixl_register_vlan(void *, struct ifnet *, u16);
258 void	ixl_unregister_vlan(void *, struct ifnet *, u16);
259 int	ixl_intr(void *);
260 int	ixl_msix_que(void *);
261 int	ixl_msix_adminq(void *);
262 void	ixl_do_adminq(void *, int);
263 
264 int	ixl_res_alloc_cmp(const void *, const void *);
265 char *	ixl_switch_res_type_string(u8);
266 char *	ixl_switch_element_string(struct sbuf *,
267 	    struct i40e_aqc_switch_config_element_resp *);
268 void	ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *,
269 		    struct sysctl_oid_list *, struct i40e_hw_port_stats *);
270 
271 void    ixl_media_status(struct ifnet *, struct ifmediareq *);
272 int     ixl_media_change(struct ifnet *);
273 int     ixl_ioctl(struct ifnet *, u_long, caddr_t);
274 
275 void	ixl_enable_queue(struct i40e_hw *, int);
276 void	ixl_disable_queue(struct i40e_hw *, int);
277 void	ixl_enable_intr0(struct i40e_hw *);
278 void	ixl_disable_intr0(struct i40e_hw *);
279 void	ixl_nvm_version_str(struct i40e_hw *hw, struct sbuf *buf);
280 void	ixl_stat_update48(struct i40e_hw *, u32, u32, bool,
281 		    u64 *, u64 *);
282 void	ixl_stat_update32(struct i40e_hw *, u32, bool,
283 		    u64 *, u64 *);
284 
285 void	ixl_stop(struct ixl_pf *);
286 int	ixl_get_hw_capabilities(struct ixl_pf *);
287 void	ixl_link_up_msg(struct ixl_pf *);
288 void    ixl_update_link_status(struct ixl_pf *);
289 int	ixl_setup_stations(struct ixl_pf *);
290 int	ixl_switch_config(struct ixl_pf *);
291 void	ixl_stop_locked(struct ixl_pf *);
292 int	ixl_teardown_hw_structs(struct ixl_pf *);
293 int	ixl_reset(struct ixl_pf *);
294 void	ixl_init_locked(struct ixl_pf *);
295 void	ixl_set_rss_key(struct ixl_pf *);
296 void	ixl_set_rss_pctypes(struct ixl_pf *);
297 void	ixl_set_rss_hlut(struct ixl_pf *);
298 int	ixl_setup_adminq_msix(struct ixl_pf *);
299 int	ixl_setup_adminq_tq(struct ixl_pf *);
300 int	ixl_teardown_adminq_msix(struct ixl_pf *);
301 void	ixl_configure_intr0_msix(struct ixl_pf *);
302 void	ixl_configure_queue_intr_msix(struct ixl_pf *);
303 void	ixl_free_adminq_tq(struct ixl_pf *);
304 int	ixl_setup_legacy(struct ixl_pf *);
305 int	ixl_init_msix(struct ixl_pf *);
306 void	ixl_configure_itr(struct ixl_pf *);
307 void	ixl_configure_legacy(struct ixl_pf *);
308 void	ixl_free_pci_resources(struct ixl_pf *);
309 void	ixl_link_event(struct ixl_pf *, struct i40e_arq_event_info *);
310 void	ixl_config_rss(struct ixl_pf *);
311 int	ixl_set_advertised_speeds(struct ixl_pf *, int, bool);
312 void	ixl_set_initial_advertised_speeds(struct ixl_pf *);
313 void	ixl_print_nvm_version(struct ixl_pf *pf);
314 void	ixl_add_device_sysctls(struct ixl_pf *);
315 void	ixl_handle_mdd_event(struct ixl_pf *);
316 void	ixl_add_hw_stats(struct ixl_pf *);
317 void	ixl_update_stats_counters(struct ixl_pf *);
318 void	ixl_pf_reset_stats(struct ixl_pf *);
319 void	ixl_get_bus_info(struct ixl_pf *pf);
320 int	ixl_aq_get_link_status(struct ixl_pf *,
321     struct i40e_aqc_get_link_status *);
322 
323 int	ixl_handle_nvmupd_cmd(struct ixl_pf *, struct ifdrv *);
324 void	ixl_handle_empr_reset(struct ixl_pf *);
325 int	ixl_prepare_for_reset(struct ixl_pf *pf, bool is_up);
326 int	ixl_rebuild_hw_structs_after_reset(struct ixl_pf *);
327 
328 void	ixl_set_queue_rx_itr(struct ixl_rx_queue *);
329 void	ixl_set_queue_tx_itr(struct ixl_tx_queue *);
330 
331 void	ixl_add_filter(struct ixl_vsi *, const u8 *, s16 vlan);
332 void	ixl_del_filter(struct ixl_vsi *, const u8 *, s16 vlan);
333 void	ixl_reconfigure_filters(struct ixl_vsi *vsi);
334 
335 int	ixl_disable_rings(struct ixl_pf *, struct ixl_vsi *, struct ixl_pf_qtag *);
336 int	ixl_disable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
337 int	ixl_disable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
338 int	ixl_disable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16);
339 
340 int	ixl_enable_rings(struct ixl_vsi *);
341 int	ixl_enable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
342 int	ixl_enable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
343 int	ixl_enable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16);
344 
345 void	ixl_update_eth_stats(struct ixl_vsi *);
346 void	ixl_cap_txcsum_tso(struct ixl_vsi *, struct ifnet *, int);
347 int	ixl_initialize_vsi(struct ixl_vsi *);
348 void	ixl_add_ifmedia(struct ixl_vsi *, u64);
349 int	ixl_setup_queue_msix(struct ixl_vsi *);
350 int	ixl_setup_queue_tqs(struct ixl_vsi *);
351 int	ixl_teardown_queue_msix(struct ixl_vsi *);
352 void	ixl_free_queue_tqs(struct ixl_vsi *);
353 void	ixl_enable_intr(struct ixl_vsi *);
354 void	ixl_disable_rings_intr(struct ixl_vsi *);
355 void	ixl_set_promisc(struct ixl_vsi *);
356 void	ixl_add_multi(struct ixl_vsi *);
357 int	ixl_del_multi(struct ixl_vsi *);
358 void	ixl_setup_vlan_filters(struct ixl_vsi *);
359 void	ixl_init_filters(struct ixl_vsi *);
360 void	ixl_add_hw_filters(struct ixl_vsi *, int, int);
361 void	ixl_del_hw_filters(struct ixl_vsi *, int);
362 void	ixl_del_default_hw_filters(struct ixl_vsi *);
363 struct ixl_mac_filter *
364 		ixl_find_filter(struct ixl_vsi *, const u8 *, s16);
365 void	ixl_add_mc_filter(struct ixl_vsi *, u8 *);
366 void	ixl_free_mac_filters(struct ixl_vsi *vsi);
367 void	ixl_update_vsi_stats(struct ixl_vsi *);
368 void	ixl_vsi_reset_stats(struct ixl_vsi *);
369 
370 void	ixl_vsi_free_queues(struct ixl_vsi *vsi);
371 
372 void	 ixl_if_init(if_ctx_t ctx);
373 void	 ixl_if_stop(if_ctx_t ctx);
374 
375 /*
376  * I2C Function prototypes
377  */
378 int	ixl_find_i2c_interface(struct ixl_pf *);
379 s32	ixl_read_i2c_byte_bb(struct ixl_pf *pf, u8 byte_offset,
380 	    u8 dev_addr, u8 *data);
381 s32	ixl_write_i2c_byte_bb(struct ixl_pf *pf, u8 byte_offset,
382 	    u8 dev_addr, u8 data);
383 s32	ixl_read_i2c_byte_reg(struct ixl_pf *pf, u8 byte_offset,
384 	    u8 dev_addr, u8 *data);
385 s32	ixl_write_i2c_byte_reg(struct ixl_pf *pf, u8 byte_offset,
386 	    u8 dev_addr, u8 data);
387 s32	ixl_read_i2c_byte_aq(struct ixl_pf *pf, u8 byte_offset,
388 	    u8 dev_addr, u8 *data);
389 s32	ixl_write_i2c_byte_aq(struct ixl_pf *pf, u8 byte_offset,
390 	    u8 dev_addr, u8 data);
391 
392 int	ixl_get_fw_lldp_status(struct ixl_pf *pf);
393 int	ixl_attach_get_link_status(struct ixl_pf *);
394 u64		ixl_max_aq_speed_to_value(u8);
395 
396 #endif /* _IXL_PF_H_ */
397