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