xref: /freebsd/sys/dev/ixl/ixl_pf.h (revision 488ab515d6cc02f6f743f0badfc8e94eb553cd30)
1 /******************************************************************************
2 
3   Copyright (c) 2013-2017, 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_PF_STATE_EMPR_RESETTING	(1 << 0)
49 #define IXL_PF_STATE_FW_LLDP_DISABLED	(1 << 1)
50 
51 struct ixl_vf {
52 	struct ixl_vsi		vsi;
53 	uint32_t		vf_flags;
54 
55 	uint8_t			mac[ETHER_ADDR_LEN];
56 	uint16_t		vf_num;
57 	uint32_t		version;
58 
59 	struct ixl_pf_qtag	qtag;
60 	struct sysctl_ctx_list	ctx;
61 };
62 
63 /* Physical controller structure */
64 struct ixl_pf {
65 	struct i40e_hw		hw;
66 	struct i40e_osdep	osdep;
67 	device_t		dev;
68 	struct ixl_vsi		vsi;
69 
70 	struct resource		*pci_mem;
71 	struct resource		*msix_mem;
72 
73 	/*
74 	 * Interrupt resources: this set is
75 	 * either used for legacy, or for Link
76 	 * when doing MSIX
77 	 */
78 	void			*tag;
79 	struct resource 	*res;
80 
81 	struct callout		timer;
82 	int			msix;
83 #ifdef IXL_IW
84 	int			iw_msix;
85 	bool			iw_enabled;
86 #endif
87 	int			if_flags;
88 	int			state;
89 	bool			init_in_progress;
90 	u8			supported_speeds;
91 
92 	struct ixl_pf_qmgr	qmgr;
93 	struct ixl_pf_qtag	qtag;
94 
95 	/* Tunable values */
96 	bool			enable_msix;
97 	int			max_queues;
98 	bool			enable_tx_fc_filter;
99 	int			dynamic_rx_itr;
100 	int			dynamic_tx_itr;
101 	int			tx_itr;
102 	int			rx_itr;
103 
104 	struct mtx		pf_mtx;
105 
106 	u32			qbase;
107 	u32 			admvec;
108 	struct task     	adminq;
109 	struct taskqueue	*tq;
110 
111 	bool			link_up;
112 	u32			link_speed;
113 	int			advertised_speed;
114 	int			fc; /* link flow ctrl setting */
115 	enum ixl_dbg_mask	dbg_mask;
116 	bool			has_i2c;
117 
118 	/* Misc stats maintained by the driver */
119 	u64			watchdog_events;
120 	u64			admin_irq;
121 
122 	/* Statistics from hw */
123 	struct i40e_hw_port_stats 	stats;
124 	struct i40e_hw_port_stats	stats_offsets;
125 	bool 				stat_offsets_loaded;
126 
127 	/* SR-IOV */
128 	struct ixl_vf		*vfs;
129 	int			num_vfs;
130 	uint16_t		veb_seid;
131 	struct task		vflr_task;
132 	int			vc_debug_lvl;
133 };
134 
135 /*
136  * Defines used for NVM update ioctls.
137  * This value is used in the Solaris tool, too.
138  */
139 #define I40E_NVM_ACCESS \
140      (((((((('E' << 4) + '1') << 4) + 'K') << 4) + 'G') << 4) | 5)
141 
142 #define IXL_DEFAULT_PHY_INT_MASK \
143      ((~(I40E_AQ_EVENT_LINK_UPDOWN | I40E_AQ_EVENT_MODULE_QUAL_FAIL \
144       | I40E_AQ_EVENT_MEDIA_NA)) & 0x3FF)
145 
146 /*** Sysctl help messages; displayed with "sysctl -d" ***/
147 
148 #define IXL_SYSCTL_HELP_SET_ADVERTISE	\
149 "\nControl advertised link speed.\n"	\
150 "Flags:\n"				\
151 "\t 0x1 - advertise 100M\n"		\
152 "\t 0x2 - advertise 1G\n"		\
153 "\t 0x4 - advertise 10G\n"		\
154 "\t 0x8 - advertise 20G\n"		\
155 "\t0x10 - advertise 25G\n"		\
156 "\t0x20 - advertise 40G\n\n"		\
157 "Set to 0 to disable link.\n"		\
158 "Use \"sysctl -x\" to view flags properly."
159 
160 #define IXL_SYSCTL_HELP_SUPPORTED_SPEED	\
161 "\nSupported link speeds.\n"		\
162 "Flags:\n"				\
163 "\t 0x1 - 100M\n"			\
164 "\t 0x2 - 1G\n"				\
165 "\t 0x4 - 10G\n"			\
166 "\t 0x8 - 20G\n"			\
167 "\t0x10 - 25G\n"			\
168 "\t0x20 - 40G\n\n"			\
169 "Use \"sysctl -x\" to view flags properly."
170 
171 #define IXL_SYSCTL_HELP_FC				\
172 "\nSet flow control mode using the values below.\n" 	\
173 "\t0 - off\n" 						\
174 "\t1 - rx pause\n" 					\
175 "\t2 - tx pause\n"					\
176 "\t3 - tx and rx pause"
177 
178 #define IXL_SYSCTL_HELP_LINK_STATUS					\
179 "\nExecutes a \"Get Link Status\" command on the Admin Queue, and displays" \
180 " the response."			\
181 
182 #define IXL_SYSCTL_HELP_FW_LLDP		\
183 "\nFW LLDP engine:\n"			\
184 "\t0 - disable\n"			\
185 "\t1 - enable\n"
186 
187 extern const char * const ixl_fc_string[6];
188 
189 MALLOC_DECLARE(M_IXL);
190 
191 /*** Functions / Macros ***/
192 /* Adjust the level here to 10 or over to print stats messages */
193 #define	I40E_VC_DEBUG(p, level, ...)				\
194 	do {							\
195 		if (level < 10)					\
196 			ixl_dbg(p, IXL_DBG_IOV_VC, ##__VA_ARGS__); \
197 	} while (0)
198 
199 #define	i40e_send_vf_nack(pf, vf, op, st) \
200 	ixl_send_vf_nack_msg((pf), (vf), (op), (st), __FILE__, __LINE__)
201 
202 #define IXL_PF_LOCK_INIT(_sc, _name) \
203         mtx_init(&(_sc)->pf_mtx, _name, "IXL PF Lock", MTX_DEF)
204 #define IXL_PF_LOCK(_sc)              mtx_lock(&(_sc)->pf_mtx)
205 #define IXL_PF_UNLOCK(_sc)            mtx_unlock(&(_sc)->pf_mtx)
206 #define IXL_PF_LOCK_DESTROY(_sc)      mtx_destroy(&(_sc)->pf_mtx)
207 #define IXL_PF_LOCK_ASSERT(_sc)       mtx_assert(&(_sc)->pf_mtx, MA_OWNED)
208 
209 /* Debug printing */
210 #define ixl_dbg(p, m, s, ...)	ixl_debug_core(p, m, s, ##__VA_ARGS__)
211 void	ixl_debug_core(struct ixl_pf *, enum ixl_dbg_mask, char *, ...);
212 
213 /* For stats sysctl naming */
214 #define QUEUE_NAME_LEN 32
215 
216 /* For netmap(4) compatibility */
217 #define ixl_disable_intr(vsi)	ixl_disable_rings_intr(vsi)
218 
219 /*
220  * PF-only function declarations
221  */
222 
223 int	ixl_setup_interface(device_t, struct ixl_vsi *);
224 void	ixl_print_nvm_cmd(device_t, struct i40e_nvm_access *);
225 char *	ixl_aq_speed_to_str(enum i40e_aq_link_speed);
226 
227 void	ixl_handle_que(void *context, int pending);
228 
229 void	ixl_init(void *);
230 void	ixl_local_timer(void *);
231 void	ixl_register_vlan(void *, struct ifnet *, u16);
232 void	ixl_unregister_vlan(void *, struct ifnet *, u16);
233 void	ixl_intr(void *);
234 void	ixl_msix_que(void *);
235 void	ixl_msix_adminq(void *);
236 void	ixl_do_adminq(void *, int);
237 
238 int	ixl_res_alloc_cmp(const void *, const void *);
239 char *	ixl_switch_res_type_string(u8);
240 char *	ixl_switch_element_string(struct sbuf *,
241 	    struct i40e_aqc_switch_config_element_resp *);
242 void	ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *,
243 		    struct sysctl_oid_list *, struct i40e_hw_port_stats *);
244 void	ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *,
245 		    struct sysctl_oid_list *,
246 		    struct i40e_eth_stats *);
247 
248 void    ixl_media_status(struct ifnet *, struct ifmediareq *);
249 int     ixl_media_change(struct ifnet *);
250 int     ixl_ioctl(struct ifnet *, u_long, caddr_t);
251 
252 void	ixl_enable_queue(struct i40e_hw *, int);
253 void	ixl_disable_queue(struct i40e_hw *, int);
254 void	ixl_enable_intr0(struct i40e_hw *);
255 void	ixl_disable_intr0(struct i40e_hw *);
256 void	ixl_nvm_version_str(struct i40e_hw *hw, struct sbuf *buf);
257 void	ixl_stat_update48(struct i40e_hw *, u32, u32, bool,
258 		    u64 *, u64 *);
259 void	ixl_stat_update32(struct i40e_hw *, u32, bool,
260 		    u64 *, u64 *);
261 
262 void	ixl_stop(struct ixl_pf *);
263 void	ixl_add_vsi_sysctls(struct ixl_pf *pf, struct ixl_vsi *vsi, struct sysctl_ctx_list *ctx, const char *sysctl_name);
264 int	ixl_get_hw_capabilities(struct ixl_pf *);
265 void	ixl_link_up_msg(struct ixl_pf *);
266 void    ixl_update_link_status(struct ixl_pf *);
267 int     ixl_allocate_pci_resources(struct ixl_pf *);
268 int	ixl_setup_stations(struct ixl_pf *);
269 int	ixl_switch_config(struct ixl_pf *);
270 void	ixl_stop_locked(struct ixl_pf *);
271 int	ixl_teardown_hw_structs(struct ixl_pf *);
272 int	ixl_reset(struct ixl_pf *);
273 void	ixl_init_locked(struct ixl_pf *);
274 void	ixl_set_rss_key(struct ixl_pf *);
275 void	ixl_set_rss_pctypes(struct ixl_pf *);
276 void	ixl_set_rss_hlut(struct ixl_pf *);
277 int	ixl_setup_adminq_msix(struct ixl_pf *);
278 int	ixl_setup_adminq_tq(struct ixl_pf *);
279 int	ixl_teardown_adminq_msix(struct ixl_pf *);
280 void	ixl_configure_intr0_msix(struct ixl_pf *);
281 void	ixl_configure_queue_intr_msix(struct ixl_pf *);
282 void	ixl_free_adminq_tq(struct ixl_pf *);
283 int	ixl_setup_legacy(struct ixl_pf *);
284 int	ixl_init_msix(struct ixl_pf *);
285 void	ixl_configure_itr(struct ixl_pf *);
286 void	ixl_configure_legacy(struct ixl_pf *);
287 void	ixl_free_pci_resources(struct ixl_pf *);
288 void	ixl_link_event(struct ixl_pf *, struct i40e_arq_event_info *);
289 void	ixl_config_rss(struct ixl_pf *);
290 int	ixl_set_advertised_speeds(struct ixl_pf *, int, bool);
291 void	ixl_set_initial_advertised_speeds(struct ixl_pf *);
292 void	ixl_print_nvm_version(struct ixl_pf *pf);
293 void	ixl_add_device_sysctls(struct ixl_pf *);
294 void	ixl_handle_mdd_event(struct ixl_pf *);
295 void	ixl_add_hw_stats(struct ixl_pf *);
296 void	ixl_update_stats_counters(struct ixl_pf *);
297 void	ixl_pf_reset_stats(struct ixl_pf *);
298 void	ixl_get_bus_info(struct ixl_pf *pf);
299 int	ixl_aq_get_link_status(struct ixl_pf *,
300     struct i40e_aqc_get_link_status *);
301 
302 int	ixl_handle_nvmupd_cmd(struct ixl_pf *, struct ifdrv *);
303 void	ixl_handle_empr_reset(struct ixl_pf *);
304 int	ixl_prepare_for_reset(struct ixl_pf *pf, bool is_up);
305 int	ixl_rebuild_hw_structs_after_reset(struct ixl_pf *, bool is_up);
306 
307 void	ixl_set_queue_rx_itr(struct ixl_queue *);
308 void	ixl_set_queue_tx_itr(struct ixl_queue *);
309 
310 void	ixl_add_filter(struct ixl_vsi *, const u8 *, s16 vlan);
311 void	ixl_del_filter(struct ixl_vsi *, const u8 *, s16 vlan);
312 void	ixl_reconfigure_filters(struct ixl_vsi *vsi);
313 
314 int	ixl_disable_rings(struct ixl_vsi *);
315 int	ixl_disable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
316 int	ixl_disable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
317 int	ixl_disable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16);
318 
319 int	ixl_enable_rings(struct ixl_vsi *);
320 int	ixl_enable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
321 int	ixl_enable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
322 int	ixl_enable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16);
323 
324 void	ixl_update_eth_stats(struct ixl_vsi *);
325 void	ixl_cap_txcsum_tso(struct ixl_vsi *, struct ifnet *, int);
326 int	ixl_initialize_vsi(struct ixl_vsi *);
327 void	ixl_add_ifmedia(struct ixl_vsi *, u64);
328 int	ixl_setup_queue_msix(struct ixl_vsi *);
329 int	ixl_setup_queue_tqs(struct ixl_vsi *);
330 int	ixl_teardown_queue_msix(struct ixl_vsi *);
331 void	ixl_free_queue_tqs(struct ixl_vsi *);
332 void	ixl_enable_intr(struct ixl_vsi *);
333 void	ixl_disable_rings_intr(struct ixl_vsi *);
334 void	ixl_set_promisc(struct ixl_vsi *);
335 void	ixl_add_multi(struct ixl_vsi *);
336 void	ixl_del_multi(struct ixl_vsi *);
337 void	ixl_setup_vlan_filters(struct ixl_vsi *);
338 void	ixl_init_filters(struct ixl_vsi *);
339 void	ixl_add_hw_filters(struct ixl_vsi *, int, int);
340 void	ixl_del_hw_filters(struct ixl_vsi *, int);
341 struct ixl_mac_filter *
342 		ixl_find_filter(struct ixl_vsi *, const u8 *, s16);
343 void	ixl_add_mc_filter(struct ixl_vsi *, u8 *);
344 void	ixl_free_mac_filters(struct ixl_vsi *vsi);
345 void	ixl_update_vsi_stats(struct ixl_vsi *);
346 void	ixl_vsi_reset_stats(struct ixl_vsi *);
347 
348 int	ixl_vsi_setup_queues(struct ixl_vsi *vsi);
349 void	ixl_vsi_free_queues(struct ixl_vsi *vsi);
350 
351 /*
352  * I2C Function prototypes
353  */
354 int	ixl_find_i2c_interface(struct ixl_pf *);
355 s32	ixl_read_i2c_byte(struct ixl_pf *pf, u8 byte_offset,
356 	    u8 dev_addr, u8 *data);
357 s32	ixl_write_i2c_byte(struct ixl_pf *pf, u8 byte_offset,
358 	    u8 dev_addr, u8 data);
359 
360 int	ixl_get_fw_lldp_status(struct ixl_pf *pf);
361 int	ixl_attach_get_link_status(struct ixl_pf *);
362 
363 #endif /* _IXL_PF_H_ */
364