xref: /freebsd/sys/dev/ixl/ixl_pf.h (revision 1c05a6ea6b849ff95e539c31adea887c644a6a01)
1 /******************************************************************************
2 
3   Copyright (c) 2013-2015, 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 
50 struct ixl_vf {
51 	struct ixl_vsi		vsi;
52 	uint32_t		vf_flags;
53 
54 	uint8_t			mac[ETHER_ADDR_LEN];
55 	uint16_t		vf_num;
56 	uint32_t		version;
57 
58 	struct ixl_pf_qtag	qtag;
59 	struct sysctl_ctx_list	ctx;
60 };
61 
62 /* Physical controller structure */
63 struct ixl_pf {
64 	struct i40e_hw		hw;
65 	struct i40e_osdep	osdep;
66 	device_t		dev;
67 	struct ixl_vsi		vsi;
68 
69 	struct resource		*pci_mem;
70 	struct resource		*msix_mem;
71 
72 	/*
73 	 * Interrupt resources: this set is
74 	 * either used for legacy, or for Link
75 	 * when doing MSIX
76 	 */
77 	void			*tag;
78 	struct resource 	*res;
79 
80 	struct callout		timer;
81 	int			msix;
82 #ifdef IXL_IW
83 	int			iw_msix;
84 	bool			iw_enabled;
85 #endif
86 	int			if_flags;
87 	int			state;
88 	bool			init_in_progress;
89 	u8			supported_speeds;
90 
91 	struct ixl_pf_qmgr	qmgr;
92 	struct ixl_pf_qtag	qtag;
93 
94 	/* Tunable values */
95 	bool			enable_msix;
96 	int			max_queues;
97 	int			ringsz;
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_FC				\
161 "\nSet flow control mode using the values below.\n" 	\
162 "\t0 - off\n" 						\
163 "\t1 - rx pause\n" 					\
164 "\t2 - tx pause\n"					\
165 "\t3 - tx and rx pause"
166 
167 #define IXL_SYSCTL_HELP_LINK_STATUS					\
168 "\nExecutes a \"Get Link Status\" command on the Admin Queue, and displays" \
169 " the response."			\
170 
171 extern const char * const ixl_fc_string[6];
172 
173 MALLOC_DECLARE(M_IXL);
174 
175 /*** Functions / Macros ***/
176 /* Adjust the level here to 10 or over to print stats messages */
177 #define	I40E_VC_DEBUG(p, level, ...)				\
178 	do {							\
179 		if (level < 10)					\
180 			ixl_dbg(p, IXL_DBG_IOV_VC, ##__VA_ARGS__); \
181 	} while (0)
182 
183 #define	i40e_send_vf_nack(pf, vf, op, st) \
184 	ixl_send_vf_nack_msg((pf), (vf), (op), (st), __FILE__, __LINE__)
185 
186 #define IXL_PF_LOCK_INIT(_sc, _name) \
187         mtx_init(&(_sc)->pf_mtx, _name, "IXL PF Lock", MTX_DEF)
188 #define IXL_PF_LOCK(_sc)              mtx_lock(&(_sc)->pf_mtx)
189 #define IXL_PF_UNLOCK(_sc)            mtx_unlock(&(_sc)->pf_mtx)
190 #define IXL_PF_LOCK_DESTROY(_sc)      mtx_destroy(&(_sc)->pf_mtx)
191 #define IXL_PF_LOCK_ASSERT(_sc)       mtx_assert(&(_sc)->pf_mtx, MA_OWNED)
192 
193 /* Debug printing */
194 #define ixl_dbg(p, m, s, ...)	ixl_debug_core(p, m, s, ##__VA_ARGS__)
195 void	ixl_debug_core(struct ixl_pf *, enum ixl_dbg_mask, char *, ...);
196 
197 /* For stats sysctl naming */
198 #define QUEUE_NAME_LEN 32
199 
200 /* For netmap(4) compatibility */
201 #define ixl_disable_intr(vsi)	ixl_disable_rings_intr(vsi)
202 
203 /*
204  * PF-only function declarations
205  */
206 
207 void	ixl_set_busmaster(device_t);
208 void	ixl_set_msix_enable(device_t);
209 int	ixl_setup_interface(device_t, struct ixl_vsi *);
210 void	ixl_print_nvm_cmd(device_t, struct i40e_nvm_access *);
211 char *	ixl_aq_speed_to_str(enum i40e_aq_link_speed);
212 
213 void	ixl_handle_que(void *context, int pending);
214 
215 void	ixl_init(void *);
216 void	ixl_local_timer(void *);
217 void	ixl_register_vlan(void *, struct ifnet *, u16);
218 void	ixl_unregister_vlan(void *, struct ifnet *, u16);
219 void	ixl_intr(void *);
220 void	ixl_msix_que(void *);
221 void	ixl_msix_adminq(void *);
222 void	ixl_do_adminq(void *, int);
223 
224 int	ixl_res_alloc_cmp(const void *, const void *);
225 char *	ixl_switch_res_type_string(u8);
226 char *	ixl_switch_element_string(struct sbuf *,
227 	    struct i40e_aqc_switch_config_element_resp *);
228 void	ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *,
229 		    struct sysctl_oid_list *, struct i40e_hw_port_stats *);
230 void	ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *,
231 		    struct sysctl_oid_list *,
232 		    struct i40e_eth_stats *);
233 
234 void    ixl_media_status(struct ifnet *, struct ifmediareq *);
235 int     ixl_media_change(struct ifnet *);
236 int     ixl_ioctl(struct ifnet *, u_long, caddr_t);
237 
238 void	ixl_enable_queue(struct i40e_hw *, int);
239 void	ixl_disable_queue(struct i40e_hw *, int);
240 void	ixl_enable_intr0(struct i40e_hw *);
241 void	ixl_disable_intr0(struct i40e_hw *);
242 void	ixl_nvm_version_str(struct i40e_hw *hw, struct sbuf *buf);
243 void	ixl_stat_update48(struct i40e_hw *, u32, u32, bool,
244 		    u64 *, u64 *);
245 void	ixl_stat_update32(struct i40e_hw *, u32, bool,
246 		    u64 *, u64 *);
247 
248 void	ixl_stop(struct ixl_pf *);
249 void	ixl_add_vsi_sysctls(struct ixl_pf *pf, struct ixl_vsi *vsi, struct sysctl_ctx_list *ctx, const char *sysctl_name);
250 int	ixl_get_hw_capabilities(struct ixl_pf *);
251 void	ixl_link_up_msg(struct ixl_pf *);
252 void    ixl_update_link_status(struct ixl_pf *);
253 int     ixl_allocate_pci_resources(struct ixl_pf *);
254 int	ixl_setup_stations(struct ixl_pf *);
255 int	ixl_switch_config(struct ixl_pf *);
256 void	ixl_stop_locked(struct ixl_pf *);
257 int	ixl_teardown_hw_structs(struct ixl_pf *);
258 int	ixl_reset(struct ixl_pf *);
259 void	ixl_init_locked(struct ixl_pf *);
260 void	ixl_set_rss_key(struct ixl_pf *);
261 void	ixl_set_rss_pctypes(struct ixl_pf *);
262 void	ixl_set_rss_hlut(struct ixl_pf *);
263 int	ixl_setup_adminq_msix(struct ixl_pf *);
264 int	ixl_setup_adminq_tq(struct ixl_pf *);
265 int	ixl_teardown_adminq_msix(struct ixl_pf *);
266 void	ixl_configure_intr0_msix(struct ixl_pf *);
267 void	ixl_configure_queue_intr_msix(struct ixl_pf *);
268 void	ixl_free_adminq_tq(struct ixl_pf *);
269 int	ixl_setup_legacy(struct ixl_pf *);
270 int	ixl_init_msix(struct ixl_pf *);
271 void	ixl_configure_itr(struct ixl_pf *);
272 void	ixl_configure_legacy(struct ixl_pf *);
273 void	ixl_free_pci_resources(struct ixl_pf *);
274 void	ixl_link_event(struct ixl_pf *, struct i40e_arq_event_info *);
275 void	ixl_config_rss(struct ixl_pf *);
276 int	ixl_set_advertised_speeds(struct ixl_pf *, int);
277 void	ixl_get_initial_advertised_speeds(struct ixl_pf *);
278 void	ixl_print_nvm_version(struct ixl_pf *pf);
279 void	ixl_add_device_sysctls(struct ixl_pf *);
280 void	ixl_handle_mdd_event(struct ixl_pf *);
281 void	ixl_add_hw_stats(struct ixl_pf *);
282 void	ixl_update_stats_counters(struct ixl_pf *);
283 void	ixl_pf_reset_stats(struct ixl_pf *);
284 void	ixl_get_bus_info(struct ixl_pf *pf);
285 int	ixl_aq_get_link_status(struct ixl_pf *,
286     struct i40e_aqc_get_link_status *);
287 
288 int	ixl_handle_nvmupd_cmd(struct ixl_pf *, struct ifdrv *);
289 void	ixl_handle_empr_reset(struct ixl_pf *);
290 int	ixl_rebuild_hw_structs_after_reset(struct ixl_pf *);
291 
292 void	ixl_set_queue_rx_itr(struct ixl_queue *);
293 void	ixl_set_queue_tx_itr(struct ixl_queue *);
294 
295 void	ixl_add_filter(struct ixl_vsi *, const u8 *, s16 vlan);
296 void	ixl_del_filter(struct ixl_vsi *, const u8 *, s16 vlan);
297 void	ixl_reconfigure_filters(struct ixl_vsi *vsi);
298 
299 int	ixl_disable_rings(struct ixl_vsi *);
300 int	ixl_disable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
301 int	ixl_disable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
302 int	ixl_disable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16);
303 
304 int	ixl_enable_rings(struct ixl_vsi *);
305 int	ixl_enable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
306 int	ixl_enable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16);
307 int	ixl_enable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16);
308 
309 void	ixl_update_eth_stats(struct ixl_vsi *);
310 void	ixl_cap_txcsum_tso(struct ixl_vsi *, struct ifnet *, int);
311 int	ixl_initialize_vsi(struct ixl_vsi *);
312 void	ixl_add_ifmedia(struct ixl_vsi *, u64);
313 int	ixl_setup_queue_msix(struct ixl_vsi *);
314 int	ixl_setup_queue_tqs(struct ixl_vsi *);
315 int	ixl_teardown_queue_msix(struct ixl_vsi *);
316 void	ixl_free_queue_tqs(struct ixl_vsi *);
317 void	ixl_enable_intr(struct ixl_vsi *);
318 void	ixl_disable_rings_intr(struct ixl_vsi *);
319 void	ixl_set_promisc(struct ixl_vsi *);
320 void	ixl_add_multi(struct ixl_vsi *);
321 void	ixl_del_multi(struct ixl_vsi *);
322 void	ixl_setup_vlan_filters(struct ixl_vsi *);
323 void	ixl_init_filters(struct ixl_vsi *);
324 void	ixl_add_hw_filters(struct ixl_vsi *, int, int);
325 void	ixl_del_hw_filters(struct ixl_vsi *, int);
326 struct ixl_mac_filter *
327 		ixl_find_filter(struct ixl_vsi *, const u8 *, s16);
328 void	ixl_add_mc_filter(struct ixl_vsi *, u8 *);
329 void	ixl_free_mac_filters(struct ixl_vsi *vsi);
330 void	ixl_update_vsi_stats(struct ixl_vsi *);
331 void	ixl_vsi_reset_stats(struct ixl_vsi *);
332 
333 /*
334  * I2C Function prototypes
335  */
336 int	ixl_find_i2c_interface(struct ixl_pf *);
337 s32	ixl_read_i2c_byte(struct ixl_pf *pf, u8 byte_offset,
338 	    u8 dev_addr, u8 *data);
339 s32	ixl_write_i2c_byte(struct ixl_pf *pf, u8 byte_offset,
340 	    u8 dev_addr, u8 data);
341 
342 #endif /* _IXL_PF_H_ */
343