xref: /freebsd/sys/dev/ixl/ixl_pf.h (revision 1a498d2e689f9e8220e2ad64b018eb1f0d11127e)
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 	/*
91 	 * This is first so that iflib_get_softc can return
92 	 * either the VSI or the PF structures.
93 	 */
94 	struct ixl_vsi		vsi;
95 
96 	struct i40e_hw		hw;
97 	struct i40e_osdep	osdep;
98 	device_t		dev;
99 
100 	struct resource		*pci_mem;
101 
102 #ifdef IXL_IW
103 	int			iw_msix;
104 	bool			iw_enabled;
105 #endif
106 	int			if_flags;
107 	u32			state;
108 	u8			supported_speeds;
109 
110 	struct ixl_pf_qmgr	qmgr;
111 	struct ixl_pf_qtag	qtag;
112 
113 	/* Tunable values */
114 	bool			enable_msix;
115 	int			max_queues;
116 	bool			enable_tx_fc_filter;
117 	int			dynamic_rx_itr;
118 	int			dynamic_tx_itr;
119 	int			tx_itr;
120 	int			rx_itr;
121 
122 	bool			link_up;
123 	int			advertised_speed;
124 	int			fc; /* link flow ctrl setting */
125 	enum ixl_dbg_mask	dbg_mask;
126 	bool			has_i2c;
127 
128 	/* Misc stats maintained by the driver */
129 	u64			watchdog_events;
130 	u64			admin_irq;
131 
132 	/* Statistics from hw */
133 	struct i40e_hw_port_stats 	stats;
134 	struct i40e_hw_port_stats	stats_offsets;
135 	bool 				stat_offsets_loaded;
136 
137 	/* I2C access methods */
138 	u8			i2c_access_method;
139 	s32	(*read_i2c_byte)(struct ixl_pf *pf, u8 byte_offset,
140 	    u8 dev_addr, u8 *data);
141 	s32	(*write_i2c_byte)(struct ixl_pf *pf, u8 byte_offset,
142 	    u8 dev_addr, u8 data);
143 
144 	/* SR-IOV */
145 	struct ixl_vf		*vfs;
146 	int			num_vfs;
147 	uint16_t		veb_seid;
148 	struct task		vflr_task;
149 	int			vc_debug_lvl;
150 };
151 
152 /*
153  * Defines used for NVM update ioctls.
154  * This value is used in the Solaris tool, too.
155  */
156 #define I40E_NVM_ACCESS \
157      (((((((('E' << 4) + '1') << 4) + 'K') << 4) + 'G') << 4) | 5)
158 
159 #define IXL_DEFAULT_PHY_INT_MASK \
160      ((~(I40E_AQ_EVENT_LINK_UPDOWN | I40E_AQ_EVENT_MODULE_QUAL_FAIL \
161       | I40E_AQ_EVENT_MEDIA_NA)) & 0x3FF)
162 
163 /*** Sysctl help messages; displayed with "sysctl -d" ***/
164 
165 #define IXL_SYSCTL_HELP_SET_ADVERTISE	\
166 "\nControl advertised link speed.\n"	\
167 "Flags:\n"				\
168 "\t 0x1 - advertise 100M\n"		\
169 "\t 0x2 - advertise 1G\n"		\
170 "\t 0x4 - advertise 10G\n"		\
171 "\t 0x8 - advertise 20G\n"		\
172 "\t0x10 - advertise 25G\n"		\
173 "\t0x20 - advertise 40G\n\n"		\
174 "Set to 0 to disable link.\n"		\
175 "Use \"sysctl -x\" to view flags properly."
176 
177 #define IXL_SYSCTL_HELP_SUPPORTED_SPEED	\
178 "\nSupported link speeds.\n"		\
179 "Flags:\n"				\
180 "\t 0x1 - 100M\n"			\
181 "\t 0x2 - 1G\n"				\
182 "\t 0x4 - 10G\n"			\
183 "\t 0x8 - 20G\n"			\
184 "\t0x10 - 25G\n"			\
185 "\t0x20 - 40G\n\n"			\
186 "Use \"sysctl -x\" to view flags properly."
187 
188 #define IXL_SYSCTL_HELP_FC				\
189 "\nSet flow control mode using the values below.\n" 	\
190 "\t0 - off\n" 						\
191 "\t1 - rx pause\n" 					\
192 "\t2 - tx pause\n"					\
193 "\t3 - tx and rx pause"
194 
195 #define IXL_SYSCTL_HELP_LINK_STATUS					\
196 "\nExecutes a \"Get Link Status\" command on the Admin Queue, and displays" \
197 " the response."
198 
199 #define IXL_SYSCTL_HELP_FW_LLDP		\
200 "\nFW LLDP engine:\n"			\
201 "\t0 - disable\n"			\
202 "\t1 - enable\n"
203 
204 #define IXL_SYSCTL_HELP_READ_I2C		\
205 "\nRead a byte from 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-31: unused\n"			\
210 "Output: 8-bit value read"
211 
212 #define IXL_SYSCTL_HELP_WRITE_I2C		\
213 "\nWrite a byte to the I2C bus\n"		\
214 "Input: 32-bit value\n"				\
215 "\tbits 0-7:   device address (0xA0 or 0xA2)\n"	\
216 "\tbits 8-15:  offset (0-255)\n"		\
217 "\tbits 16-23: value to write\n"		\
218 "\tbits 24-31: unused\n"			\
219 "Output: 8-bit value written"
220 
221 #define IXL_SYSCTL_HELP_I2C_METHOD		\
222 "\nI2C access method that driver will use:\n"	\
223 "\t0 - best available method\n"			\
224 "\t1 - bit bang via I2CPARAMS register\n"	\
225 "\t2 - register read/write via I2CCMD register\n" \
226 "\t3 - Use Admin Queue command (best)\n"	\
227 "Using the Admin Queue is only supported on 710 devices with FW version 1.7 or higher"
228 
229 extern const char * const ixl_fc_string[6];
230 
231 MALLOC_DECLARE(M_IXL);
232 
233 /*** Functions / Macros ***/
234 /* Adjust the level here to 10 or over to print stats messages */
235 #define	I40E_VC_DEBUG(p, level, ...)				\
236 	do {							\
237 		if (level < 10)					\
238 			ixl_dbg(p, IXL_DBG_IOV_VC, ##__VA_ARGS__); \
239 	} while (0)
240 
241 #define	i40e_send_vf_nack(pf, vf, op, st) \
242 	ixl_send_vf_nack_msg((pf), (vf), (op), (st), __FILE__, __LINE__)
243 
244 /* Debug printing */
245 #define ixl_dbg(p, m, s, ...)	ixl_debug_core(p, m, s, ##__VA_ARGS__)
246 void	ixl_debug_core(struct ixl_pf *, enum ixl_dbg_mask, char *, ...);
247 
248 /* For stats sysctl naming */
249 #define QUEUE_NAME_LEN 32
250 
251 /* For netmap(4) compatibility */
252 #define ixl_disable_intr(vsi)	ixl_disable_rings_intr(vsi)
253 
254 /* PF-only function declarations */
255 int	ixl_setup_interface(device_t, struct ixl_pf *);
256 void	ixl_print_nvm_cmd(device_t, struct i40e_nvm_access *);
257 char *	ixl_aq_speed_to_str(enum i40e_aq_link_speed);
258 
259 void	ixl_handle_que(void *context, int pending);
260 
261 void	ixl_init(void *);
262 void	ixl_local_timer(void *);
263 void	ixl_register_vlan(void *, struct ifnet *, u16);
264 void	ixl_unregister_vlan(void *, struct ifnet *, u16);
265 int	ixl_intr(void *);
266 int	ixl_msix_que(void *);
267 int	ixl_msix_adminq(void *);
268 void	ixl_do_adminq(void *, int);
269 
270 int	ixl_res_alloc_cmp(const void *, const void *);
271 char *	ixl_switch_res_type_string(u8);
272 char *	ixl_switch_element_string(struct sbuf *,
273 	    struct i40e_aqc_switch_config_element_resp *);
274 void	ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *,
275 		    struct sysctl_oid_list *, struct i40e_hw_port_stats *);
276 void	ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *,
277 		    struct sysctl_oid_list *,
278 		    struct i40e_eth_stats *);
279 
280 void    ixl_media_status(struct ifnet *, struct ifmediareq *);
281 int     ixl_media_change(struct ifnet *);
282 int     ixl_ioctl(struct ifnet *, u_long, caddr_t);
283 
284 void	ixl_enable_queue(struct i40e_hw *, int);
285 void	ixl_disable_queue(struct i40e_hw *, int);
286 void	ixl_enable_intr0(struct i40e_hw *);
287 void	ixl_disable_intr0(struct i40e_hw *);
288 void	ixl_nvm_version_str(struct i40e_hw *hw, struct sbuf *buf);
289 void	ixl_stat_update48(struct i40e_hw *, u32, u32, bool,
290 		    u64 *, u64 *);
291 void	ixl_stat_update32(struct i40e_hw *, u32, bool,
292 		    u64 *, u64 *);
293 
294 void	ixl_stop(struct ixl_pf *);
295 void	ixl_add_vsi_sysctls(struct ixl_pf *pf, struct ixl_vsi *vsi, struct sysctl_ctx_list *ctx, const char *sysctl_name);
296 int	ixl_get_hw_capabilities(struct ixl_pf *);
297 void	ixl_link_up_msg(struct ixl_pf *);
298 void    ixl_update_link_status(struct ixl_pf *);
299 int	ixl_setup_stations(struct ixl_pf *);
300 int	ixl_switch_config(struct ixl_pf *);
301 void	ixl_stop_locked(struct ixl_pf *);
302 int	ixl_teardown_hw_structs(struct ixl_pf *);
303 int	ixl_reset(struct ixl_pf *);
304 void	ixl_init_locked(struct ixl_pf *);
305 void	ixl_set_rss_key(struct ixl_pf *);
306 void	ixl_set_rss_pctypes(struct ixl_pf *);
307 void	ixl_set_rss_hlut(struct ixl_pf *);
308 int	ixl_setup_adminq_msix(struct ixl_pf *);
309 int	ixl_setup_adminq_tq(struct ixl_pf *);
310 int	ixl_teardown_adminq_msix(struct ixl_pf *);
311 void	ixl_configure_intr0_msix(struct ixl_pf *);
312 void	ixl_configure_queue_intr_msix(struct ixl_pf *);
313 void	ixl_free_adminq_tq(struct ixl_pf *);
314 int	ixl_setup_legacy(struct ixl_pf *);
315 int	ixl_init_msix(struct ixl_pf *);
316 void	ixl_configure_itr(struct ixl_pf *);
317 void	ixl_configure_legacy(struct ixl_pf *);
318 void	ixl_free_pci_resources(struct ixl_pf *);
319 void	ixl_link_event(struct ixl_pf *, struct i40e_arq_event_info *);
320 void	ixl_config_rss(struct ixl_pf *);
321 int	ixl_set_advertised_speeds(struct ixl_pf *, int, bool);
322 void	ixl_set_initial_advertised_speeds(struct ixl_pf *);
323 void	ixl_print_nvm_version(struct ixl_pf *pf);
324 void	ixl_add_device_sysctls(struct ixl_pf *);
325 void	ixl_handle_mdd_event(struct ixl_pf *);
326 void	ixl_add_hw_stats(struct ixl_pf *);
327 void	ixl_update_stats_counters(struct ixl_pf *);
328 void	ixl_pf_reset_stats(struct ixl_pf *);
329 void	ixl_get_bus_info(struct ixl_pf *pf);
330 int	ixl_aq_get_link_status(struct ixl_pf *,
331     struct i40e_aqc_get_link_status *);
332 
333 int	ixl_handle_nvmupd_cmd(struct ixl_pf *, struct ifdrv *);
334 void	ixl_handle_empr_reset(struct ixl_pf *);
335 int	ixl_prepare_for_reset(struct ixl_pf *pf, bool is_up);
336 int	ixl_rebuild_hw_structs_after_reset(struct ixl_pf *, bool is_up);
337 
338 void	ixl_set_queue_rx_itr(struct ixl_rx_queue *);
339 void	ixl_set_queue_tx_itr(struct ixl_tx_queue *);
340 
341 void	ixl_add_filter(struct ixl_vsi *, const u8 *, s16 vlan);
342 void	ixl_del_filter(struct ixl_vsi *, const u8 *, s16 vlan);
343 void	ixl_reconfigure_filters(struct ixl_vsi *vsi);
344 
345 int	ixl_disable_rings(struct ixl_vsi *);
346 int	ixl_disable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
347 int	ixl_disable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
348 int	ixl_disable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16);
349 
350 int	ixl_enable_rings(struct ixl_vsi *);
351 int	ixl_enable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
352 int	ixl_enable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
353 int	ixl_enable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16);
354 
355 void	ixl_update_eth_stats(struct ixl_vsi *);
356 void	ixl_cap_txcsum_tso(struct ixl_vsi *, struct ifnet *, int);
357 int	ixl_initialize_vsi(struct ixl_vsi *);
358 void	ixl_add_ifmedia(struct ixl_vsi *, u64);
359 int	ixl_setup_queue_msix(struct ixl_vsi *);
360 int	ixl_setup_queue_tqs(struct ixl_vsi *);
361 int	ixl_teardown_queue_msix(struct ixl_vsi *);
362 void	ixl_free_queue_tqs(struct ixl_vsi *);
363 void	ixl_enable_intr(struct ixl_vsi *);
364 void	ixl_disable_rings_intr(struct ixl_vsi *);
365 void	ixl_set_promisc(struct ixl_vsi *);
366 void	ixl_add_multi(struct ixl_vsi *);
367 void	ixl_del_multi(struct ixl_vsi *);
368 void	ixl_setup_vlan_filters(struct ixl_vsi *);
369 void	ixl_init_filters(struct ixl_vsi *);
370 void	ixl_add_hw_filters(struct ixl_vsi *, int, int);
371 void	ixl_del_hw_filters(struct ixl_vsi *, int);
372 struct ixl_mac_filter *
373 		ixl_find_filter(struct ixl_vsi *, const u8 *, s16);
374 void	ixl_add_mc_filter(struct ixl_vsi *, u8 *);
375 void	ixl_free_mac_filters(struct ixl_vsi *vsi);
376 void	ixl_update_vsi_stats(struct ixl_vsi *);
377 void	ixl_vsi_reset_stats(struct ixl_vsi *);
378 
379 void	ixl_vsi_free_queues(struct ixl_vsi *vsi);
380 
381 void	 ixl_if_init(if_ctx_t ctx);
382 void	 ixl_if_stop(if_ctx_t ctx);
383 
384 /*
385  * I2C Function prototypes
386  */
387 int	ixl_find_i2c_interface(struct ixl_pf *);
388 s32	ixl_read_i2c_byte_bb(struct ixl_pf *pf, u8 byte_offset,
389 	    u8 dev_addr, u8 *data);
390 s32	ixl_write_i2c_byte_bb(struct ixl_pf *pf, u8 byte_offset,
391 	    u8 dev_addr, u8 data);
392 s32	ixl_read_i2c_byte_reg(struct ixl_pf *pf, u8 byte_offset,
393 	    u8 dev_addr, u8 *data);
394 s32	ixl_write_i2c_byte_reg(struct ixl_pf *pf, u8 byte_offset,
395 	    u8 dev_addr, u8 data);
396 s32	ixl_read_i2c_byte_aq(struct ixl_pf *pf, u8 byte_offset,
397 	    u8 dev_addr, u8 *data);
398 s32	ixl_write_i2c_byte_aq(struct ixl_pf *pf, u8 byte_offset,
399 	    u8 dev_addr, u8 data);
400 
401 int	ixl_get_fw_lldp_status(struct ixl_pf *pf);
402 int	ixl_attach_get_link_status(struct ixl_pf *);
403 
404 #endif /* _IXL_PF_H_ */
405