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