net/ixgbe: ensure link status is updated
[dpdk.git] / drivers / net / ixgbe / ixgbe_ethdev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <sys/queue.h>
35 #include <stdio.h>
36 #include <errno.h>
37 #include <stdint.h>
38 #include <string.h>
39 #include <unistd.h>
40 #include <stdarg.h>
41 #include <inttypes.h>
42 #include <netinet/in.h>
43 #include <rte_byteorder.h>
44 #include <rte_common.h>
45 #include <rte_cycles.h>
46
47 #include <rte_interrupts.h>
48 #include <rte_log.h>
49 #include <rte_debug.h>
50 #include <rte_pci.h>
51 #include <rte_atomic.h>
52 #include <rte_branch_prediction.h>
53 #include <rte_memory.h>
54 #include <rte_memzone.h>
55 #include <rte_eal.h>
56 #include <rte_alarm.h>
57 #include <rte_ether.h>
58 #include <rte_ethdev.h>
59 #include <rte_ethdev_pci.h>
60 #include <rte_atomic.h>
61 #include <rte_malloc.h>
62 #include <rte_random.h>
63 #include <rte_dev.h>
64 #include <rte_hash_crc.h>
65
66 #include "ixgbe_logs.h"
67 #include "base/ixgbe_api.h"
68 #include "base/ixgbe_vf.h"
69 #include "base/ixgbe_common.h"
70 #include "ixgbe_ethdev.h"
71 #include "ixgbe_bypass.h"
72 #include "ixgbe_rxtx.h"
73 #include "base/ixgbe_type.h"
74 #include "base/ixgbe_phy.h"
75 #include "ixgbe_regs.h"
76
77 /*
78  * High threshold controlling when to start sending XOFF frames. Must be at
79  * least 8 bytes less than receive packet buffer size. This value is in units
80  * of 1024 bytes.
81  */
82 #define IXGBE_FC_HI    0x80
83
84 /*
85  * Low threshold controlling when to start sending XON frames. This value is
86  * in units of 1024 bytes.
87  */
88 #define IXGBE_FC_LO    0x40
89
90 /* Default minimum inter-interrupt interval for EITR configuration */
91 #define IXGBE_MIN_INTER_INTERRUPT_INTERVAL_DEFAULT    0x79E
92
93 /* Timer value included in XOFF frames. */
94 #define IXGBE_FC_PAUSE 0x680
95
96 #define IXGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
97 #define IXGBE_LINK_UP_CHECK_TIMEOUT   1000 /* ms */
98 #define IXGBE_VMDQ_NUM_UC_MAC         4096 /* Maximum nb. of UC MAC addr. */
99
100 #define IXGBE_MMW_SIZE_DEFAULT        0x4
101 #define IXGBE_MMW_SIZE_JUMBO_FRAME    0x14
102 #define IXGBE_MAX_RING_DESC           4096 /* replicate define from rxtx */
103
104 /*
105  *  Default values for RX/TX configuration
106  */
107 #define IXGBE_DEFAULT_RX_FREE_THRESH  32
108 #define IXGBE_DEFAULT_RX_PTHRESH      8
109 #define IXGBE_DEFAULT_RX_HTHRESH      8
110 #define IXGBE_DEFAULT_RX_WTHRESH      0
111
112 #define IXGBE_DEFAULT_TX_FREE_THRESH  32
113 #define IXGBE_DEFAULT_TX_PTHRESH      32
114 #define IXGBE_DEFAULT_TX_HTHRESH      0
115 #define IXGBE_DEFAULT_TX_WTHRESH      0
116 #define IXGBE_DEFAULT_TX_RSBIT_THRESH 32
117
118 /* Bit shift and mask */
119 #define IXGBE_4_BIT_WIDTH  (CHAR_BIT / 2)
120 #define IXGBE_4_BIT_MASK   RTE_LEN2MASK(IXGBE_4_BIT_WIDTH, uint8_t)
121 #define IXGBE_8_BIT_WIDTH  CHAR_BIT
122 #define IXGBE_8_BIT_MASK   UINT8_MAX
123
124 #define IXGBEVF_PMD_NAME "rte_ixgbevf_pmd" /* PMD name */
125
126 #define IXGBE_QUEUE_STAT_COUNTERS (sizeof(hw_stats->qprc) / sizeof(hw_stats->qprc[0]))
127
128 #define IXGBE_HKEY_MAX_INDEX 10
129
130 /* Additional timesync values. */
131 #define NSEC_PER_SEC             1000000000L
132 #define IXGBE_INCVAL_10GB        0x66666666
133 #define IXGBE_INCVAL_1GB         0x40000000
134 #define IXGBE_INCVAL_100         0x50000000
135 #define IXGBE_INCVAL_SHIFT_10GB  28
136 #define IXGBE_INCVAL_SHIFT_1GB   24
137 #define IXGBE_INCVAL_SHIFT_100   21
138 #define IXGBE_INCVAL_SHIFT_82599 7
139 #define IXGBE_INCPER_SHIFT_82599 24
140
141 #define IXGBE_CYCLECOUNTER_MASK   0xffffffffffffffffULL
142
143 #define IXGBE_VT_CTL_POOLING_MODE_MASK         0x00030000
144 #define IXGBE_VT_CTL_POOLING_MODE_ETAG         0x00010000
145 #define DEFAULT_ETAG_ETYPE                     0x893f
146 #define IXGBE_ETAG_ETYPE                       0x00005084
147 #define IXGBE_ETAG_ETYPE_MASK                  0x0000ffff
148 #define IXGBE_ETAG_ETYPE_VALID                 0x80000000
149 #define IXGBE_RAH_ADTYPE                       0x40000000
150 #define IXGBE_RAL_ETAG_FILTER_MASK             0x00003fff
151 #define IXGBE_VMVIR_TAGA_MASK                  0x18000000
152 #define IXGBE_VMVIR_TAGA_ETAG_INSERT           0x08000000
153 #define IXGBE_VMTIR(_i) (0x00017000 + ((_i) * 4)) /* 64 of these (0-63) */
154 #define IXGBE_QDE_STRIP_TAG                    0x00000004
155 #define IXGBE_VTEICR_MASK                      0x07
156
157 #define IXGBE_EXVET_VET_EXT_SHIFT              16
158 #define IXGBE_DMATXCTL_VT_MASK                 0xFFFF0000
159
160 static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev);
161 static int eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev);
162 static int ixgbe_fdir_filter_init(struct rte_eth_dev *eth_dev);
163 static int ixgbe_fdir_filter_uninit(struct rte_eth_dev *eth_dev);
164 static int ixgbe_l2_tn_filter_init(struct rte_eth_dev *eth_dev);
165 static int ixgbe_l2_tn_filter_uninit(struct rte_eth_dev *eth_dev);
166 static int ixgbe_ntuple_filter_uninit(struct rte_eth_dev *eth_dev);
167 static int  ixgbe_dev_configure(struct rte_eth_dev *dev);
168 static int  ixgbe_dev_start(struct rte_eth_dev *dev);
169 static void ixgbe_dev_stop(struct rte_eth_dev *dev);
170 static int  ixgbe_dev_set_link_up(struct rte_eth_dev *dev);
171 static int  ixgbe_dev_set_link_down(struct rte_eth_dev *dev);
172 static void ixgbe_dev_close(struct rte_eth_dev *dev);
173 static void ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
174 static void ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
175 static void ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
176 static void ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev);
177 static int ixgbe_dev_link_update(struct rte_eth_dev *dev,
178                                 int wait_to_complete);
179 static void ixgbe_dev_stats_get(struct rte_eth_dev *dev,
180                                 struct rte_eth_stats *stats);
181 static int ixgbe_dev_xstats_get(struct rte_eth_dev *dev,
182                                 struct rte_eth_xstat *xstats, unsigned n);
183 static int ixgbevf_dev_xstats_get(struct rte_eth_dev *dev,
184                                   struct rte_eth_xstat *xstats, unsigned n);
185 static int
186 ixgbe_dev_xstats_get_by_ids(struct rte_eth_dev *dev, uint64_t *ids,
187                 uint64_t *values, unsigned int n);
188 static void ixgbe_dev_stats_reset(struct rte_eth_dev *dev);
189 static void ixgbe_dev_xstats_reset(struct rte_eth_dev *dev);
190 static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
191         struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit);
192 static int ixgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
193         struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit);
194 static int ixgbe_dev_xstats_get_names_by_ids(
195         __rte_unused struct rte_eth_dev *dev,
196         struct rte_eth_xstat_name *xstats_names,
197         uint64_t *ids,
198         unsigned int limit);
199 static int ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
200                                              uint16_t queue_id,
201                                              uint8_t stat_idx,
202                                              uint8_t is_rx);
203 static int ixgbe_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
204                                  size_t fw_size);
205 static void ixgbe_dev_info_get(struct rte_eth_dev *dev,
206                                struct rte_eth_dev_info *dev_info);
207 static const uint32_t *ixgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev);
208 static void ixgbevf_dev_info_get(struct rte_eth_dev *dev,
209                                  struct rte_eth_dev_info *dev_info);
210 static int ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
211
212 static int ixgbe_vlan_filter_set(struct rte_eth_dev *dev,
213                 uint16_t vlan_id, int on);
214 static int ixgbe_vlan_tpid_set(struct rte_eth_dev *dev,
215                                enum rte_vlan_type vlan_type,
216                                uint16_t tpid_id);
217 static void ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
218                 uint16_t queue, bool on);
219 static void ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue,
220                 int on);
221 static void ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask);
222 static void ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue);
223 static void ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue);
224 static void ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev);
225 static void ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev);
226
227 static int ixgbe_dev_led_on(struct rte_eth_dev *dev);
228 static int ixgbe_dev_led_off(struct rte_eth_dev *dev);
229 static int ixgbe_flow_ctrl_get(struct rte_eth_dev *dev,
230                                struct rte_eth_fc_conf *fc_conf);
231 static int ixgbe_flow_ctrl_set(struct rte_eth_dev *dev,
232                                struct rte_eth_fc_conf *fc_conf);
233 static int ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev,
234                 struct rte_eth_pfc_conf *pfc_conf);
235 static int ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
236                         struct rte_eth_rss_reta_entry64 *reta_conf,
237                         uint16_t reta_size);
238 static int ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
239                         struct rte_eth_rss_reta_entry64 *reta_conf,
240                         uint16_t reta_size);
241 static void ixgbe_dev_link_status_print(struct rte_eth_dev *dev);
242 static int ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev);
243 static int ixgbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev);
244 static int ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
245 static int ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev);
246 static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev,
247                                       struct rte_intr_handle *handle);
248 static void ixgbe_dev_interrupt_handler(void *param);
249 static void ixgbe_dev_interrupt_delayed_handler(void *param);
250 static void ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
251                 uint32_t index, uint32_t pool);
252 static void ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index);
253 static void ixgbe_set_default_mac_addr(struct rte_eth_dev *dev,
254                                            struct ether_addr *mac_addr);
255 static void ixgbe_dcb_init(struct ixgbe_hw *hw, struct ixgbe_dcb_config *dcb_config);
256 static bool is_device_supported(struct rte_eth_dev *dev,
257                                 struct rte_pci_driver *drv);
258
259 /* For Virtual Function support */
260 static int eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev);
261 static int eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev);
262 static int  ixgbevf_dev_configure(struct rte_eth_dev *dev);
263 static int  ixgbevf_dev_start(struct rte_eth_dev *dev);
264 static void ixgbevf_dev_stop(struct rte_eth_dev *dev);
265 static void ixgbevf_dev_close(struct rte_eth_dev *dev);
266 static void ixgbevf_intr_disable(struct ixgbe_hw *hw);
267 static void ixgbevf_intr_enable(struct ixgbe_hw *hw);
268 static void ixgbevf_dev_stats_get(struct rte_eth_dev *dev,
269                 struct rte_eth_stats *stats);
270 static void ixgbevf_dev_stats_reset(struct rte_eth_dev *dev);
271 static int ixgbevf_vlan_filter_set(struct rte_eth_dev *dev,
272                 uint16_t vlan_id, int on);
273 static void ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev,
274                 uint16_t queue, int on);
275 static void ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
276 static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
277 static int ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
278                                             uint16_t queue_id);
279 static int ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
280                                              uint16_t queue_id);
281 static void ixgbevf_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
282                                  uint8_t queue, uint8_t msix_vector);
283 static void ixgbevf_configure_msix(struct rte_eth_dev *dev);
284 static void ixgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev);
285 static void ixgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev);
286
287 /* For Eth VMDQ APIs support */
288 static int ixgbe_uc_hash_table_set(struct rte_eth_dev *dev, struct
289                 ether_addr * mac_addr, uint8_t on);
290 static int ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on);
291 static int ixgbe_mirror_rule_set(struct rte_eth_dev *dev,
292                 struct rte_eth_mirror_conf *mirror_conf,
293                 uint8_t rule_id, uint8_t on);
294 static int ixgbe_mirror_rule_reset(struct rte_eth_dev *dev,
295                 uint8_t rule_id);
296 static int ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
297                                           uint16_t queue_id);
298 static int ixgbe_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
299                                            uint16_t queue_id);
300 static void ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
301                                uint8_t queue, uint8_t msix_vector);
302 static void ixgbe_configure_msix(struct rte_eth_dev *dev);
303
304 static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
305                 uint16_t queue_idx, uint16_t tx_rate);
306
307 static void ixgbevf_add_mac_addr(struct rte_eth_dev *dev,
308                                  struct ether_addr *mac_addr,
309                                  uint32_t index, uint32_t pool);
310 static void ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
311 static void ixgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
312                                              struct ether_addr *mac_addr);
313 static int ixgbe_syn_filter_get(struct rte_eth_dev *dev,
314                         struct rte_eth_syn_filter *filter);
315 static int ixgbe_syn_filter_handle(struct rte_eth_dev *dev,
316                         enum rte_filter_op filter_op,
317                         void *arg);
318 static int ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
319                         struct ixgbe_5tuple_filter *filter);
320 static void ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
321                         struct ixgbe_5tuple_filter *filter);
322 static int ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
323                                 enum rte_filter_op filter_op,
324                                 void *arg);
325 static int ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
326                         struct rte_eth_ntuple_filter *filter);
327 static int ixgbe_ethertype_filter_handle(struct rte_eth_dev *dev,
328                                 enum rte_filter_op filter_op,
329                                 void *arg);
330 static int ixgbe_get_ethertype_filter(struct rte_eth_dev *dev,
331                         struct rte_eth_ethertype_filter *filter);
332 static int ixgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
333                      enum rte_filter_type filter_type,
334                      enum rte_filter_op filter_op,
335                      void *arg);
336 static int ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
337
338 static int ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
339                                       struct ether_addr *mc_addr_set,
340                                       uint32_t nb_mc_addr);
341 static int ixgbe_dev_get_dcb_info(struct rte_eth_dev *dev,
342                                    struct rte_eth_dcb_info *dcb_info);
343
344 static int ixgbe_get_reg_length(struct rte_eth_dev *dev);
345 static int ixgbe_get_regs(struct rte_eth_dev *dev,
346                             struct rte_dev_reg_info *regs);
347 static int ixgbe_get_eeprom_length(struct rte_eth_dev *dev);
348 static int ixgbe_get_eeprom(struct rte_eth_dev *dev,
349                                 struct rte_dev_eeprom_info *eeprom);
350 static int ixgbe_set_eeprom(struct rte_eth_dev *dev,
351                                 struct rte_dev_eeprom_info *eeprom);
352
353 static int ixgbevf_get_reg_length(struct rte_eth_dev *dev);
354 static int ixgbevf_get_regs(struct rte_eth_dev *dev,
355                                 struct rte_dev_reg_info *regs);
356
357 static int ixgbe_timesync_enable(struct rte_eth_dev *dev);
358 static int ixgbe_timesync_disable(struct rte_eth_dev *dev);
359 static int ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
360                                             struct timespec *timestamp,
361                                             uint32_t flags);
362 static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
363                                             struct timespec *timestamp);
364 static int ixgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
365 static int ixgbe_timesync_read_time(struct rte_eth_dev *dev,
366                                    struct timespec *timestamp);
367 static int ixgbe_timesync_write_time(struct rte_eth_dev *dev,
368                                    const struct timespec *timestamp);
369 static void ixgbevf_dev_interrupt_handler(void *param);
370
371 static int ixgbe_dev_l2_tunnel_eth_type_conf
372         (struct rte_eth_dev *dev, struct rte_eth_l2_tunnel_conf *l2_tunnel);
373 static int ixgbe_dev_l2_tunnel_offload_set
374         (struct rte_eth_dev *dev,
375          struct rte_eth_l2_tunnel_conf *l2_tunnel,
376          uint32_t mask,
377          uint8_t en);
378 static int ixgbe_dev_l2_tunnel_filter_handle(struct rte_eth_dev *dev,
379                                              enum rte_filter_op filter_op,
380                                              void *arg);
381
382 static int ixgbe_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
383                                          struct rte_eth_udp_tunnel *udp_tunnel);
384 static int ixgbe_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
385                                          struct rte_eth_udp_tunnel *udp_tunnel);
386 static int ixgbe_filter_restore(struct rte_eth_dev *dev);
387 static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev);
388
389 /*
390  * Define VF Stats MACRO for Non "cleared on read" register
391  */
392 #define UPDATE_VF_STAT(reg, last, cur)                          \
393 {                                                               \
394         uint32_t latest = IXGBE_READ_REG(hw, reg);              \
395         cur += (latest - last) & UINT_MAX;                      \
396         last = latest;                                          \
397 }
398
399 #define UPDATE_VF_STAT_36BIT(lsb, msb, last, cur)                \
400 {                                                                \
401         u64 new_lsb = IXGBE_READ_REG(hw, lsb);                   \
402         u64 new_msb = IXGBE_READ_REG(hw, msb);                   \
403         u64 latest = ((new_msb << 32) | new_lsb);                \
404         cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \
405         last = latest;                                           \
406 }
407
408 #define IXGBE_SET_HWSTRIP(h, q) do {\
409                 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
410                 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
411                 (h)->bitmap[idx] |= 1 << bit;\
412         } while (0)
413
414 #define IXGBE_CLEAR_HWSTRIP(h, q) do {\
415                 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
416                 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
417                 (h)->bitmap[idx] &= ~(1 << bit);\
418         } while (0)
419
420 #define IXGBE_GET_HWSTRIP(h, q, r) do {\
421                 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
422                 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
423                 (r) = (h)->bitmap[idx] >> bit & 1;\
424         } while (0)
425
426 /*
427  * The set of PCI devices this driver supports
428  */
429 static const struct rte_pci_id pci_id_ixgbe_map[] = {
430         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598) },
431         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_BX) },
432         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_DUAL_PORT) },
433         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_SINGLE_PORT) },
434         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT) },
435         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT2) },
436         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_SFP_LOM) },
437         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_CX4) },
438         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_CX4_DUAL_PORT) },
439         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_DA_DUAL_PORT) },
440         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) },
441         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_XF_LR) },
442         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4) },
443         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4_MEZZ) },
444         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KR) },
445         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_COMBO_BACKPLANE) },
446         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) },
447         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_CX4) },
448         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP) },
449         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_SUBDEV_ID_82599_SFP) },
450         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_SUBDEV_ID_82599_RNDC) },
451         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_SUBDEV_ID_82599_560FLR) },
452         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_SUBDEV_ID_82599_ECNA_DP) },
453         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BACKPLANE_FCOE) },
454         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_FCOE) },
455         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_EM) },
456         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF2) },
457         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF_QP) },
458         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_QSFP_SF_QP) },
459         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599EN_SFP) },
460         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_XAUI_LOM) },
461         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_T3_LOM) },
462         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_LS) },
463         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T) },
464         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T1) },
465         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_SFP) },
466         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_10G_T) },
467         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_1G_T) },
468         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550T) },
469         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550T1) },
470         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_KR) },
471         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_KR_L) },
472         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SFP_N) },
473         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SGMII) },
474         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SGMII_L) },
475         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_10G_T) },
476         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_QSFP) },
477         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_QSFP_N) },
478         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SFP) },
479         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_1G_T) },
480         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_1G_T_L) },
481         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_KX4) },
482         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_KR) },
483 #ifdef RTE_NIC_BYPASS
484         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BYPASS) },
485 #endif
486         { .vendor_id = 0, /* sentinel */ },
487 };
488
489 /*
490  * The set of PCI devices this driver supports (for 82599 VF)
491  */
492 static const struct rte_pci_id pci_id_ixgbevf_map[] = {
493         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF) },
494         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF_HV) },
495         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF) },
496         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF_HV) },
497         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550_VF_HV) },
498         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550_VF) },
499         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_VF) },
500         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_VF_HV) },
501         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_VF) },
502         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_VF_HV) },
503         { .vendor_id = 0, /* sentinel */ },
504 };
505
506 static const struct rte_eth_desc_lim rx_desc_lim = {
507         .nb_max = IXGBE_MAX_RING_DESC,
508         .nb_min = IXGBE_MIN_RING_DESC,
509         .nb_align = IXGBE_RXD_ALIGN,
510 };
511
512 static const struct rte_eth_desc_lim tx_desc_lim = {
513         .nb_max = IXGBE_MAX_RING_DESC,
514         .nb_min = IXGBE_MIN_RING_DESC,
515         .nb_align = IXGBE_TXD_ALIGN,
516         .nb_seg_max = IXGBE_TX_MAX_SEG,
517         .nb_mtu_seg_max = IXGBE_TX_MAX_SEG,
518 };
519
520 static const struct eth_dev_ops ixgbe_eth_dev_ops = {
521         .dev_configure        = ixgbe_dev_configure,
522         .dev_start            = ixgbe_dev_start,
523         .dev_stop             = ixgbe_dev_stop,
524         .dev_set_link_up    = ixgbe_dev_set_link_up,
525         .dev_set_link_down  = ixgbe_dev_set_link_down,
526         .dev_close            = ixgbe_dev_close,
527         .promiscuous_enable   = ixgbe_dev_promiscuous_enable,
528         .promiscuous_disable  = ixgbe_dev_promiscuous_disable,
529         .allmulticast_enable  = ixgbe_dev_allmulticast_enable,
530         .allmulticast_disable = ixgbe_dev_allmulticast_disable,
531         .link_update          = ixgbe_dev_link_update,
532         .stats_get            = ixgbe_dev_stats_get,
533         .xstats_get           = ixgbe_dev_xstats_get,
534         .xstats_get_by_ids    = ixgbe_dev_xstats_get_by_ids,
535         .stats_reset          = ixgbe_dev_stats_reset,
536         .xstats_reset         = ixgbe_dev_xstats_reset,
537         .xstats_get_names     = ixgbe_dev_xstats_get_names,
538         .xstats_get_names_by_ids = ixgbe_dev_xstats_get_names_by_ids,
539         .queue_stats_mapping_set = ixgbe_dev_queue_stats_mapping_set,
540         .fw_version_get       = ixgbe_fw_version_get,
541         .dev_infos_get        = ixgbe_dev_info_get,
542         .dev_supported_ptypes_get = ixgbe_dev_supported_ptypes_get,
543         .mtu_set              = ixgbe_dev_mtu_set,
544         .vlan_filter_set      = ixgbe_vlan_filter_set,
545         .vlan_tpid_set        = ixgbe_vlan_tpid_set,
546         .vlan_offload_set     = ixgbe_vlan_offload_set,
547         .vlan_strip_queue_set = ixgbe_vlan_strip_queue_set,
548         .rx_queue_start       = ixgbe_dev_rx_queue_start,
549         .rx_queue_stop        = ixgbe_dev_rx_queue_stop,
550         .tx_queue_start       = ixgbe_dev_tx_queue_start,
551         .tx_queue_stop        = ixgbe_dev_tx_queue_stop,
552         .rx_queue_setup       = ixgbe_dev_rx_queue_setup,
553         .rx_queue_intr_enable = ixgbe_dev_rx_queue_intr_enable,
554         .rx_queue_intr_disable = ixgbe_dev_rx_queue_intr_disable,
555         .rx_queue_release     = ixgbe_dev_rx_queue_release,
556         .rx_queue_count       = ixgbe_dev_rx_queue_count,
557         .rx_descriptor_done   = ixgbe_dev_rx_descriptor_done,
558         .rx_descriptor_status = ixgbe_dev_rx_descriptor_status,
559         .tx_descriptor_status = ixgbe_dev_tx_descriptor_status,
560         .tx_queue_setup       = ixgbe_dev_tx_queue_setup,
561         .tx_queue_release     = ixgbe_dev_tx_queue_release,
562         .dev_led_on           = ixgbe_dev_led_on,
563         .dev_led_off          = ixgbe_dev_led_off,
564         .flow_ctrl_get        = ixgbe_flow_ctrl_get,
565         .flow_ctrl_set        = ixgbe_flow_ctrl_set,
566         .priority_flow_ctrl_set = ixgbe_priority_flow_ctrl_set,
567         .mac_addr_add         = ixgbe_add_rar,
568         .mac_addr_remove      = ixgbe_remove_rar,
569         .mac_addr_set         = ixgbe_set_default_mac_addr,
570         .uc_hash_table_set    = ixgbe_uc_hash_table_set,
571         .uc_all_hash_table_set  = ixgbe_uc_all_hash_table_set,
572         .mirror_rule_set      = ixgbe_mirror_rule_set,
573         .mirror_rule_reset    = ixgbe_mirror_rule_reset,
574         .set_queue_rate_limit = ixgbe_set_queue_rate_limit,
575         .reta_update          = ixgbe_dev_rss_reta_update,
576         .reta_query           = ixgbe_dev_rss_reta_query,
577 #ifdef RTE_NIC_BYPASS
578         .bypass_init          = ixgbe_bypass_init,
579         .bypass_state_set     = ixgbe_bypass_state_store,
580         .bypass_state_show    = ixgbe_bypass_state_show,
581         .bypass_event_set     = ixgbe_bypass_event_store,
582         .bypass_event_show    = ixgbe_bypass_event_show,
583         .bypass_wd_timeout_set  = ixgbe_bypass_wd_timeout_store,
584         .bypass_wd_timeout_show = ixgbe_bypass_wd_timeout_show,
585         .bypass_ver_show      = ixgbe_bypass_ver_show,
586         .bypass_wd_reset      = ixgbe_bypass_wd_reset,
587 #endif /* RTE_NIC_BYPASS */
588         .rss_hash_update      = ixgbe_dev_rss_hash_update,
589         .rss_hash_conf_get    = ixgbe_dev_rss_hash_conf_get,
590         .filter_ctrl          = ixgbe_dev_filter_ctrl,
591         .set_mc_addr_list     = ixgbe_dev_set_mc_addr_list,
592         .rxq_info_get         = ixgbe_rxq_info_get,
593         .txq_info_get         = ixgbe_txq_info_get,
594         .timesync_enable      = ixgbe_timesync_enable,
595         .timesync_disable     = ixgbe_timesync_disable,
596         .timesync_read_rx_timestamp = ixgbe_timesync_read_rx_timestamp,
597         .timesync_read_tx_timestamp = ixgbe_timesync_read_tx_timestamp,
598         .get_reg              = ixgbe_get_regs,
599         .get_eeprom_length    = ixgbe_get_eeprom_length,
600         .get_eeprom           = ixgbe_get_eeprom,
601         .set_eeprom           = ixgbe_set_eeprom,
602         .get_dcb_info         = ixgbe_dev_get_dcb_info,
603         .timesync_adjust_time = ixgbe_timesync_adjust_time,
604         .timesync_read_time   = ixgbe_timesync_read_time,
605         .timesync_write_time  = ixgbe_timesync_write_time,
606         .l2_tunnel_eth_type_conf = ixgbe_dev_l2_tunnel_eth_type_conf,
607         .l2_tunnel_offload_set   = ixgbe_dev_l2_tunnel_offload_set,
608         .udp_tunnel_port_add  = ixgbe_dev_udp_tunnel_port_add,
609         .udp_tunnel_port_del  = ixgbe_dev_udp_tunnel_port_del,
610 };
611
612 /*
613  * dev_ops for virtual function, bare necessities for basic vf
614  * operation have been implemented
615  */
616 static const struct eth_dev_ops ixgbevf_eth_dev_ops = {
617         .dev_configure        = ixgbevf_dev_configure,
618         .dev_start            = ixgbevf_dev_start,
619         .dev_stop             = ixgbevf_dev_stop,
620         .link_update          = ixgbe_dev_link_update,
621         .stats_get            = ixgbevf_dev_stats_get,
622         .xstats_get           = ixgbevf_dev_xstats_get,
623         .stats_reset          = ixgbevf_dev_stats_reset,
624         .xstats_reset         = ixgbevf_dev_stats_reset,
625         .xstats_get_names     = ixgbevf_dev_xstats_get_names,
626         .dev_close            = ixgbevf_dev_close,
627         .allmulticast_enable  = ixgbevf_dev_allmulticast_enable,
628         .allmulticast_disable = ixgbevf_dev_allmulticast_disable,
629         .dev_infos_get        = ixgbevf_dev_info_get,
630         .dev_supported_ptypes_get = ixgbe_dev_supported_ptypes_get,
631         .mtu_set              = ixgbevf_dev_set_mtu,
632         .vlan_filter_set      = ixgbevf_vlan_filter_set,
633         .vlan_strip_queue_set = ixgbevf_vlan_strip_queue_set,
634         .vlan_offload_set     = ixgbevf_vlan_offload_set,
635         .rx_queue_setup       = ixgbe_dev_rx_queue_setup,
636         .rx_queue_release     = ixgbe_dev_rx_queue_release,
637         .rx_descriptor_done   = ixgbe_dev_rx_descriptor_done,
638         .rx_descriptor_status = ixgbe_dev_rx_descriptor_status,
639         .tx_descriptor_status = ixgbe_dev_tx_descriptor_status,
640         .tx_queue_setup       = ixgbe_dev_tx_queue_setup,
641         .tx_queue_release     = ixgbe_dev_tx_queue_release,
642         .rx_queue_intr_enable = ixgbevf_dev_rx_queue_intr_enable,
643         .rx_queue_intr_disable = ixgbevf_dev_rx_queue_intr_disable,
644         .mac_addr_add         = ixgbevf_add_mac_addr,
645         .mac_addr_remove      = ixgbevf_remove_mac_addr,
646         .set_mc_addr_list     = ixgbe_dev_set_mc_addr_list,
647         .rxq_info_get         = ixgbe_rxq_info_get,
648         .txq_info_get         = ixgbe_txq_info_get,
649         .mac_addr_set         = ixgbevf_set_default_mac_addr,
650         .get_reg              = ixgbevf_get_regs,
651         .reta_update          = ixgbe_dev_rss_reta_update,
652         .reta_query           = ixgbe_dev_rss_reta_query,
653         .rss_hash_update      = ixgbe_dev_rss_hash_update,
654         .rss_hash_conf_get    = ixgbe_dev_rss_hash_conf_get,
655 };
656
657 /* store statistics names and its offset in stats structure */
658 struct rte_ixgbe_xstats_name_off {
659         char name[RTE_ETH_XSTATS_NAME_SIZE];
660         unsigned offset;
661 };
662
663 static const struct rte_ixgbe_xstats_name_off rte_ixgbe_stats_strings[] = {
664         {"rx_crc_errors", offsetof(struct ixgbe_hw_stats, crcerrs)},
665         {"rx_illegal_byte_errors", offsetof(struct ixgbe_hw_stats, illerrc)},
666         {"rx_error_bytes", offsetof(struct ixgbe_hw_stats, errbc)},
667         {"mac_local_errors", offsetof(struct ixgbe_hw_stats, mlfc)},
668         {"mac_remote_errors", offsetof(struct ixgbe_hw_stats, mrfc)},
669         {"rx_length_errors", offsetof(struct ixgbe_hw_stats, rlec)},
670         {"tx_xon_packets", offsetof(struct ixgbe_hw_stats, lxontxc)},
671         {"rx_xon_packets", offsetof(struct ixgbe_hw_stats, lxonrxc)},
672         {"tx_xoff_packets", offsetof(struct ixgbe_hw_stats, lxofftxc)},
673         {"rx_xoff_packets", offsetof(struct ixgbe_hw_stats, lxoffrxc)},
674         {"rx_size_64_packets", offsetof(struct ixgbe_hw_stats, prc64)},
675         {"rx_size_65_to_127_packets", offsetof(struct ixgbe_hw_stats, prc127)},
676         {"rx_size_128_to_255_packets", offsetof(struct ixgbe_hw_stats, prc255)},
677         {"rx_size_256_to_511_packets", offsetof(struct ixgbe_hw_stats, prc511)},
678         {"rx_size_512_to_1023_packets", offsetof(struct ixgbe_hw_stats,
679                 prc1023)},
680         {"rx_size_1024_to_max_packets", offsetof(struct ixgbe_hw_stats,
681                 prc1522)},
682         {"rx_broadcast_packets", offsetof(struct ixgbe_hw_stats, bprc)},
683         {"rx_multicast_packets", offsetof(struct ixgbe_hw_stats, mprc)},
684         {"rx_fragment_errors", offsetof(struct ixgbe_hw_stats, rfc)},
685         {"rx_undersize_errors", offsetof(struct ixgbe_hw_stats, ruc)},
686         {"rx_oversize_errors", offsetof(struct ixgbe_hw_stats, roc)},
687         {"rx_jabber_errors", offsetof(struct ixgbe_hw_stats, rjc)},
688         {"rx_management_packets", offsetof(struct ixgbe_hw_stats, mngprc)},
689         {"rx_management_dropped", offsetof(struct ixgbe_hw_stats, mngpdc)},
690         {"tx_management_packets", offsetof(struct ixgbe_hw_stats, mngptc)},
691         {"rx_total_packets", offsetof(struct ixgbe_hw_stats, tpr)},
692         {"rx_total_bytes", offsetof(struct ixgbe_hw_stats, tor)},
693         {"tx_total_packets", offsetof(struct ixgbe_hw_stats, tpt)},
694         {"tx_size_64_packets", offsetof(struct ixgbe_hw_stats, ptc64)},
695         {"tx_size_65_to_127_packets", offsetof(struct ixgbe_hw_stats, ptc127)},
696         {"tx_size_128_to_255_packets", offsetof(struct ixgbe_hw_stats, ptc255)},
697         {"tx_size_256_to_511_packets", offsetof(struct ixgbe_hw_stats, ptc511)},
698         {"tx_size_512_to_1023_packets", offsetof(struct ixgbe_hw_stats,
699                 ptc1023)},
700         {"tx_size_1024_to_max_packets", offsetof(struct ixgbe_hw_stats,
701                 ptc1522)},
702         {"tx_multicast_packets", offsetof(struct ixgbe_hw_stats, mptc)},
703         {"tx_broadcast_packets", offsetof(struct ixgbe_hw_stats, bptc)},
704         {"rx_mac_short_packet_dropped", offsetof(struct ixgbe_hw_stats, mspdc)},
705         {"rx_l3_l4_xsum_error", offsetof(struct ixgbe_hw_stats, xec)},
706
707         {"flow_director_added_filters", offsetof(struct ixgbe_hw_stats,
708                 fdirustat_add)},
709         {"flow_director_removed_filters", offsetof(struct ixgbe_hw_stats,
710                 fdirustat_remove)},
711         {"flow_director_filter_add_errors", offsetof(struct ixgbe_hw_stats,
712                 fdirfstat_fadd)},
713         {"flow_director_filter_remove_errors", offsetof(struct ixgbe_hw_stats,
714                 fdirfstat_fremove)},
715         {"flow_director_matched_filters", offsetof(struct ixgbe_hw_stats,
716                 fdirmatch)},
717         {"flow_director_missed_filters", offsetof(struct ixgbe_hw_stats,
718                 fdirmiss)},
719
720         {"rx_fcoe_crc_errors", offsetof(struct ixgbe_hw_stats, fccrc)},
721         {"rx_fcoe_dropped", offsetof(struct ixgbe_hw_stats, fcoerpdc)},
722         {"rx_fcoe_mbuf_allocation_errors", offsetof(struct ixgbe_hw_stats,
723                 fclast)},
724         {"rx_fcoe_packets", offsetof(struct ixgbe_hw_stats, fcoeprc)},
725         {"tx_fcoe_packets", offsetof(struct ixgbe_hw_stats, fcoeptc)},
726         {"rx_fcoe_bytes", offsetof(struct ixgbe_hw_stats, fcoedwrc)},
727         {"tx_fcoe_bytes", offsetof(struct ixgbe_hw_stats, fcoedwtc)},
728         {"rx_fcoe_no_direct_data_placement", offsetof(struct ixgbe_hw_stats,
729                 fcoe_noddp)},
730         {"rx_fcoe_no_direct_data_placement_ext_buff",
731                 offsetof(struct ixgbe_hw_stats, fcoe_noddp_ext_buff)},
732
733         {"tx_flow_control_xon_packets", offsetof(struct ixgbe_hw_stats,
734                 lxontxc)},
735         {"rx_flow_control_xon_packets", offsetof(struct ixgbe_hw_stats,
736                 lxonrxc)},
737         {"tx_flow_control_xoff_packets", offsetof(struct ixgbe_hw_stats,
738                 lxofftxc)},
739         {"rx_flow_control_xoff_packets", offsetof(struct ixgbe_hw_stats,
740                 lxoffrxc)},
741         {"rx_total_missed_packets", offsetof(struct ixgbe_hw_stats, mpctotal)},
742 };
743
744 #define IXGBE_NB_HW_STATS (sizeof(rte_ixgbe_stats_strings) / \
745                            sizeof(rte_ixgbe_stats_strings[0]))
746
747 /* MACsec statistics */
748 static const struct rte_ixgbe_xstats_name_off rte_ixgbe_macsec_strings[] = {
749         {"out_pkts_untagged", offsetof(struct ixgbe_macsec_stats,
750                 out_pkts_untagged)},
751         {"out_pkts_encrypted", offsetof(struct ixgbe_macsec_stats,
752                 out_pkts_encrypted)},
753         {"out_pkts_protected", offsetof(struct ixgbe_macsec_stats,
754                 out_pkts_protected)},
755         {"out_octets_encrypted", offsetof(struct ixgbe_macsec_stats,
756                 out_octets_encrypted)},
757         {"out_octets_protected", offsetof(struct ixgbe_macsec_stats,
758                 out_octets_protected)},
759         {"in_pkts_untagged", offsetof(struct ixgbe_macsec_stats,
760                 in_pkts_untagged)},
761         {"in_pkts_badtag", offsetof(struct ixgbe_macsec_stats,
762                 in_pkts_badtag)},
763         {"in_pkts_nosci", offsetof(struct ixgbe_macsec_stats,
764                 in_pkts_nosci)},
765         {"in_pkts_unknownsci", offsetof(struct ixgbe_macsec_stats,
766                 in_pkts_unknownsci)},
767         {"in_octets_decrypted", offsetof(struct ixgbe_macsec_stats,
768                 in_octets_decrypted)},
769         {"in_octets_validated", offsetof(struct ixgbe_macsec_stats,
770                 in_octets_validated)},
771         {"in_pkts_unchecked", offsetof(struct ixgbe_macsec_stats,
772                 in_pkts_unchecked)},
773         {"in_pkts_delayed", offsetof(struct ixgbe_macsec_stats,
774                 in_pkts_delayed)},
775         {"in_pkts_late", offsetof(struct ixgbe_macsec_stats,
776                 in_pkts_late)},
777         {"in_pkts_ok", offsetof(struct ixgbe_macsec_stats,
778                 in_pkts_ok)},
779         {"in_pkts_invalid", offsetof(struct ixgbe_macsec_stats,
780                 in_pkts_invalid)},
781         {"in_pkts_notvalid", offsetof(struct ixgbe_macsec_stats,
782                 in_pkts_notvalid)},
783         {"in_pkts_unusedsa", offsetof(struct ixgbe_macsec_stats,
784                 in_pkts_unusedsa)},
785         {"in_pkts_notusingsa", offsetof(struct ixgbe_macsec_stats,
786                 in_pkts_notusingsa)},
787 };
788
789 #define IXGBE_NB_MACSEC_STATS (sizeof(rte_ixgbe_macsec_strings) / \
790                            sizeof(rte_ixgbe_macsec_strings[0]))
791
792 /* Per-queue statistics */
793 static const struct rte_ixgbe_xstats_name_off rte_ixgbe_rxq_strings[] = {
794         {"mbuf_allocation_errors", offsetof(struct ixgbe_hw_stats, rnbc)},
795         {"dropped", offsetof(struct ixgbe_hw_stats, mpc)},
796         {"xon_packets", offsetof(struct ixgbe_hw_stats, pxonrxc)},
797         {"xoff_packets", offsetof(struct ixgbe_hw_stats, pxoffrxc)},
798 };
799
800 #define IXGBE_NB_RXQ_PRIO_STATS (sizeof(rte_ixgbe_rxq_strings) / \
801                            sizeof(rte_ixgbe_rxq_strings[0]))
802 #define IXGBE_NB_RXQ_PRIO_VALUES 8
803
804 static const struct rte_ixgbe_xstats_name_off rte_ixgbe_txq_strings[] = {
805         {"xon_packets", offsetof(struct ixgbe_hw_stats, pxontxc)},
806         {"xoff_packets", offsetof(struct ixgbe_hw_stats, pxofftxc)},
807         {"xon_to_xoff_packets", offsetof(struct ixgbe_hw_stats,
808                 pxon2offc)},
809 };
810
811 #define IXGBE_NB_TXQ_PRIO_STATS (sizeof(rte_ixgbe_txq_strings) / \
812                            sizeof(rte_ixgbe_txq_strings[0]))
813 #define IXGBE_NB_TXQ_PRIO_VALUES 8
814
815 static const struct rte_ixgbe_xstats_name_off rte_ixgbevf_stats_strings[] = {
816         {"rx_multicast_packets", offsetof(struct ixgbevf_hw_stats, vfmprc)},
817 };
818
819 #define IXGBEVF_NB_XSTATS (sizeof(rte_ixgbevf_stats_strings) /  \
820                 sizeof(rte_ixgbevf_stats_strings[0]))
821
822 /**
823  * Atomically reads the link status information from global
824  * structure rte_eth_dev.
825  *
826  * @param dev
827  *   - Pointer to the structure rte_eth_dev to read from.
828  *   - Pointer to the buffer to be saved with the link status.
829  *
830  * @return
831  *   - On success, zero.
832  *   - On failure, negative value.
833  */
834 static inline int
835 rte_ixgbe_dev_atomic_read_link_status(struct rte_eth_dev *dev,
836                                 struct rte_eth_link *link)
837 {
838         struct rte_eth_link *dst = link;
839         struct rte_eth_link *src = &(dev->data->dev_link);
840
841         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
842                                         *(uint64_t *)src) == 0)
843                 return -1;
844
845         return 0;
846 }
847
848 /**
849  * Atomically writes the link status information into global
850  * structure rte_eth_dev.
851  *
852  * @param dev
853  *   - Pointer to the structure rte_eth_dev to read from.
854  *   - Pointer to the buffer to be saved with the link status.
855  *
856  * @return
857  *   - On success, zero.
858  *   - On failure, negative value.
859  */
860 static inline int
861 rte_ixgbe_dev_atomic_write_link_status(struct rte_eth_dev *dev,
862                                 struct rte_eth_link *link)
863 {
864         struct rte_eth_link *dst = &(dev->data->dev_link);
865         struct rte_eth_link *src = link;
866
867         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
868                                         *(uint64_t *)src) == 0)
869                 return -1;
870
871         return 0;
872 }
873
874 /*
875  * This function is the same as ixgbe_is_sfp() in base/ixgbe.h.
876  */
877 static inline int
878 ixgbe_is_sfp(struct ixgbe_hw *hw)
879 {
880         switch (hw->phy.type) {
881         case ixgbe_phy_sfp_avago:
882         case ixgbe_phy_sfp_ftl:
883         case ixgbe_phy_sfp_intel:
884         case ixgbe_phy_sfp_unknown:
885         case ixgbe_phy_sfp_passive_tyco:
886         case ixgbe_phy_sfp_passive_unknown:
887                 return 1;
888         default:
889                 return 0;
890         }
891 }
892
893 static inline int32_t
894 ixgbe_pf_reset_hw(struct ixgbe_hw *hw)
895 {
896         uint32_t ctrl_ext;
897         int32_t status;
898
899         status = ixgbe_reset_hw(hw);
900
901         ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
902         /* Set PF Reset Done bit so PF/VF Mail Ops can work */
903         ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
904         IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
905         IXGBE_WRITE_FLUSH(hw);
906
907         if (status == IXGBE_ERR_SFP_NOT_PRESENT)
908                 status = IXGBE_SUCCESS;
909         return status;
910 }
911
912 static inline void
913 ixgbe_enable_intr(struct rte_eth_dev *dev)
914 {
915         struct ixgbe_interrupt *intr =
916                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
917         struct ixgbe_hw *hw =
918                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
919
920         IXGBE_WRITE_REG(hw, IXGBE_EIMS, intr->mask);
921         IXGBE_WRITE_FLUSH(hw);
922 }
923
924 /*
925  * This function is based on ixgbe_disable_intr() in base/ixgbe.h.
926  */
927 static void
928 ixgbe_disable_intr(struct ixgbe_hw *hw)
929 {
930         PMD_INIT_FUNC_TRACE();
931
932         if (hw->mac.type == ixgbe_mac_82598EB) {
933                 IXGBE_WRITE_REG(hw, IXGBE_EIMC, ~0);
934         } else {
935                 IXGBE_WRITE_REG(hw, IXGBE_EIMC, 0xFFFF0000);
936                 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), ~0);
937                 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), ~0);
938         }
939         IXGBE_WRITE_FLUSH(hw);
940 }
941
942 /*
943  * This function resets queue statistics mapping registers.
944  * From Niantic datasheet, Initialization of Statistics section:
945  * "...if software requires the queue counters, the RQSMR and TQSM registers
946  * must be re-programmed following a device reset.
947  */
948 static void
949 ixgbe_reset_qstat_mappings(struct ixgbe_hw *hw)
950 {
951         uint32_t i;
952
953         for (i = 0; i != IXGBE_NB_STAT_MAPPING_REGS; i++) {
954                 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), 0);
955                 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), 0);
956         }
957 }
958
959
960 static int
961 ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
962                                   uint16_t queue_id,
963                                   uint8_t stat_idx,
964                                   uint8_t is_rx)
965 {
966 #define QSM_REG_NB_BITS_PER_QMAP_FIELD 8
967 #define NB_QMAP_FIELDS_PER_QSM_REG 4
968 #define QMAP_FIELD_RESERVED_BITS_MASK 0x0f
969
970         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
971         struct ixgbe_stat_mapping_registers *stat_mappings =
972                 IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(eth_dev->data->dev_private);
973         uint32_t qsmr_mask = 0;
974         uint32_t clearing_mask = QMAP_FIELD_RESERVED_BITS_MASK;
975         uint32_t q_map;
976         uint8_t n, offset;
977
978         if ((hw->mac.type != ixgbe_mac_82599EB) &&
979                 (hw->mac.type != ixgbe_mac_X540) &&
980                 (hw->mac.type != ixgbe_mac_X550) &&
981                 (hw->mac.type != ixgbe_mac_X550EM_x) &&
982                 (hw->mac.type != ixgbe_mac_X550EM_a))
983                 return -ENOSYS;
984
985         PMD_INIT_LOG(DEBUG, "Setting port %d, %s queue_id %d to stat index %d",
986                      (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
987                      queue_id, stat_idx);
988
989         n = (uint8_t)(queue_id / NB_QMAP_FIELDS_PER_QSM_REG);
990         if (n >= IXGBE_NB_STAT_MAPPING_REGS) {
991                 PMD_INIT_LOG(ERR, "Nb of stat mapping registers exceeded");
992                 return -EIO;
993         }
994         offset = (uint8_t)(queue_id % NB_QMAP_FIELDS_PER_QSM_REG);
995
996         /* Now clear any previous stat_idx set */
997         clearing_mask <<= (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
998         if (!is_rx)
999                 stat_mappings->tqsm[n] &= ~clearing_mask;
1000         else
1001                 stat_mappings->rqsmr[n] &= ~clearing_mask;
1002
1003         q_map = (uint32_t)stat_idx;
1004         q_map &= QMAP_FIELD_RESERVED_BITS_MASK;
1005         qsmr_mask = q_map << (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
1006         if (!is_rx)
1007                 stat_mappings->tqsm[n] |= qsmr_mask;
1008         else
1009                 stat_mappings->rqsmr[n] |= qsmr_mask;
1010
1011         PMD_INIT_LOG(DEBUG, "Set port %d, %s queue_id %d to stat index %d",
1012                      (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
1013                      queue_id, stat_idx);
1014         PMD_INIT_LOG(DEBUG, "%s[%d] = 0x%08x", is_rx ? "RQSMR" : "TQSM", n,
1015                      is_rx ? stat_mappings->rqsmr[n] : stat_mappings->tqsm[n]);
1016
1017         /* Now write the mapping in the appropriate register */
1018         if (is_rx) {
1019                 PMD_INIT_LOG(DEBUG, "Write 0x%x to RX IXGBE stat mapping reg:%d",
1020                              stat_mappings->rqsmr[n], n);
1021                 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(n), stat_mappings->rqsmr[n]);
1022         } else {
1023                 PMD_INIT_LOG(DEBUG, "Write 0x%x to TX IXGBE stat mapping reg:%d",
1024                              stat_mappings->tqsm[n], n);
1025                 IXGBE_WRITE_REG(hw, IXGBE_TQSM(n), stat_mappings->tqsm[n]);
1026         }
1027         return 0;
1028 }
1029
1030 static void
1031 ixgbe_restore_statistics_mapping(struct rte_eth_dev *dev)
1032 {
1033         struct ixgbe_stat_mapping_registers *stat_mappings =
1034                 IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(dev->data->dev_private);
1035         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1036         int i;
1037
1038         /* write whatever was in stat mapping table to the NIC */
1039         for (i = 0; i < IXGBE_NB_STAT_MAPPING_REGS; i++) {
1040                 /* rx */
1041                 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), stat_mappings->rqsmr[i]);
1042
1043                 /* tx */
1044                 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), stat_mappings->tqsm[i]);
1045         }
1046 }
1047
1048 static void
1049 ixgbe_dcb_init(struct ixgbe_hw *hw, struct ixgbe_dcb_config *dcb_config)
1050 {
1051         uint8_t i;
1052         struct ixgbe_dcb_tc_config *tc;
1053         uint8_t dcb_max_tc = IXGBE_DCB_MAX_TRAFFIC_CLASS;
1054
1055         dcb_config->num_tcs.pg_tcs = dcb_max_tc;
1056         dcb_config->num_tcs.pfc_tcs = dcb_max_tc;
1057         for (i = 0; i < dcb_max_tc; i++) {
1058                 tc = &dcb_config->tc_config[i];
1059                 tc->path[IXGBE_DCB_TX_CONFIG].bwg_id = i;
1060                 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
1061                                  (uint8_t)(100/dcb_max_tc + (i & 1));
1062                 tc->path[IXGBE_DCB_RX_CONFIG].bwg_id = i;
1063                 tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
1064                                  (uint8_t)(100/dcb_max_tc + (i & 1));
1065                 tc->pfc = ixgbe_dcb_pfc_disabled;
1066         }
1067
1068         /* Initialize default user to priority mapping, UPx->TC0 */
1069         tc = &dcb_config->tc_config[0];
1070         tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
1071         tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
1072         for (i = 0; i < IXGBE_DCB_MAX_BW_GROUP; i++) {
1073                 dcb_config->bw_percentage[IXGBE_DCB_TX_CONFIG][i] = 100;
1074                 dcb_config->bw_percentage[IXGBE_DCB_RX_CONFIG][i] = 100;
1075         }
1076         dcb_config->rx_pba_cfg = ixgbe_dcb_pba_equal;
1077         dcb_config->pfc_mode_enable = false;
1078         dcb_config->vt_mode = true;
1079         dcb_config->round_robin_enable = false;
1080         /* support all DCB capabilities in 82599 */
1081         dcb_config->support.capabilities = 0xFF;
1082
1083         /*we only support 4 Tcs for X540, X550 */
1084         if (hw->mac.type == ixgbe_mac_X540 ||
1085                 hw->mac.type == ixgbe_mac_X550 ||
1086                 hw->mac.type == ixgbe_mac_X550EM_x ||
1087                 hw->mac.type == ixgbe_mac_X550EM_a) {
1088                 dcb_config->num_tcs.pg_tcs = 4;
1089                 dcb_config->num_tcs.pfc_tcs = 4;
1090         }
1091 }
1092
1093 /*
1094  * Ensure that all locks are released before first NVM or PHY access
1095  */
1096 static void
1097 ixgbe_swfw_lock_reset(struct ixgbe_hw *hw)
1098 {
1099         uint16_t mask;
1100
1101         /*
1102          * Phy lock should not fail in this early stage. If this is the case,
1103          * it is due to an improper exit of the application.
1104          * So force the release of the faulty lock. Release of common lock
1105          * is done automatically by swfw_sync function.
1106          */
1107         mask = IXGBE_GSSR_PHY0_SM << hw->bus.func;
1108         if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
1109                 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released", hw->bus.func);
1110         }
1111         ixgbe_release_swfw_semaphore(hw, mask);
1112
1113         /*
1114          * These ones are more tricky since they are common to all ports; but
1115          * swfw_sync retries last long enough (1s) to be almost sure that if
1116          * lock can not be taken it is due to an improper lock of the
1117          * semaphore.
1118          */
1119         mask = IXGBE_GSSR_EEP_SM | IXGBE_GSSR_MAC_CSR_SM | IXGBE_GSSR_SW_MNG_SM;
1120         if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
1121                 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
1122         }
1123         ixgbe_release_swfw_semaphore(hw, mask);
1124 }
1125
1126 /*
1127  * This function is based on code in ixgbe_attach() in base/ixgbe.c.
1128  * It returns 0 on success.
1129  */
1130 static int
1131 eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
1132 {
1133         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
1134         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1135         struct ixgbe_hw *hw =
1136                 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1137         struct ixgbe_vfta *shadow_vfta =
1138                 IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
1139         struct ixgbe_hwstrip *hwstrip =
1140                 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
1141         struct ixgbe_dcb_config *dcb_config =
1142                 IXGBE_DEV_PRIVATE_TO_DCB_CFG(eth_dev->data->dev_private);
1143         struct ixgbe_filter_info *filter_info =
1144                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
1145         struct ixgbe_bw_conf *bw_conf =
1146                 IXGBE_DEV_PRIVATE_TO_BW_CONF(eth_dev->data->dev_private);
1147         uint32_t ctrl_ext;
1148         uint16_t csum;
1149         int diag, i;
1150
1151         PMD_INIT_FUNC_TRACE();
1152
1153         eth_dev->dev_ops = &ixgbe_eth_dev_ops;
1154         eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
1155         eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
1156         eth_dev->tx_pkt_prepare = &ixgbe_prep_pkts;
1157
1158         /*
1159          * For secondary processes, we don't initialise any further as primary
1160          * has already done this work. Only check we don't need a different
1161          * RX and TX function.
1162          */
1163         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1164                 struct ixgbe_tx_queue *txq;
1165                 /* TX queue function in primary, set by last queue initialized
1166                  * Tx queue may not initialized by primary process
1167                  */
1168                 if (eth_dev->data->tx_queues) {
1169                         txq = eth_dev->data->tx_queues[eth_dev->data->nb_tx_queues-1];
1170                         ixgbe_set_tx_function(eth_dev, txq);
1171                 } else {
1172                         /* Use default TX function if we get here */
1173                         PMD_INIT_LOG(NOTICE, "No TX queues configured yet. "
1174                                      "Using default TX function.");
1175                 }
1176
1177                 ixgbe_set_rx_function(eth_dev);
1178
1179                 return 0;
1180         }
1181
1182         rte_eth_copy_pci_info(eth_dev, pci_dev);
1183         eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1184
1185         /* Vendor and Device ID need to be set before init of shared code */
1186         hw->device_id = pci_dev->id.device_id;
1187         hw->vendor_id = pci_dev->id.vendor_id;
1188         hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1189         hw->allow_unsupported_sfp = 1;
1190
1191         /* Initialize the shared code (base driver) */
1192 #ifdef RTE_NIC_BYPASS
1193         diag = ixgbe_bypass_init_shared_code(hw);
1194 #else
1195         diag = ixgbe_init_shared_code(hw);
1196 #endif /* RTE_NIC_BYPASS */
1197
1198         if (diag != IXGBE_SUCCESS) {
1199                 PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
1200                 return -EIO;
1201         }
1202
1203         /* pick up the PCI bus settings for reporting later */
1204         ixgbe_get_bus_info(hw);
1205
1206         /* Unlock any pending hardware semaphore */
1207         ixgbe_swfw_lock_reset(hw);
1208
1209         /* Initialize DCB configuration*/
1210         memset(dcb_config, 0, sizeof(struct ixgbe_dcb_config));
1211         ixgbe_dcb_init(hw, dcb_config);
1212         /* Get Hardware Flow Control setting */
1213         hw->fc.requested_mode = ixgbe_fc_full;
1214         hw->fc.current_mode = ixgbe_fc_full;
1215         hw->fc.pause_time = IXGBE_FC_PAUSE;
1216         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
1217                 hw->fc.low_water[i] = IXGBE_FC_LO;
1218                 hw->fc.high_water[i] = IXGBE_FC_HI;
1219         }
1220         hw->fc.send_xon = 1;
1221
1222         /* Make sure we have a good EEPROM before we read from it */
1223         diag = ixgbe_validate_eeprom_checksum(hw, &csum);
1224         if (diag != IXGBE_SUCCESS) {
1225                 PMD_INIT_LOG(ERR, "The EEPROM checksum is not valid: %d", diag);
1226                 return -EIO;
1227         }
1228
1229 #ifdef RTE_NIC_BYPASS
1230         diag = ixgbe_bypass_init_hw(hw);
1231 #else
1232         diag = ixgbe_init_hw(hw);
1233 #endif /* RTE_NIC_BYPASS */
1234
1235         /*
1236          * Devices with copper phys will fail to initialise if ixgbe_init_hw()
1237          * is called too soon after the kernel driver unbinding/binding occurs.
1238          * The failure occurs in ixgbe_identify_phy_generic() for all devices,
1239          * but for non-copper devies, ixgbe_identify_sfp_module_generic() is
1240          * also called. See ixgbe_identify_phy_82599(). The reason for the
1241          * failure is not known, and only occuts when virtualisation features
1242          * are disabled in the bios. A delay of 100ms  was found to be enough by
1243          * trial-and-error, and is doubled to be safe.
1244          */
1245         if (diag && (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)) {
1246                 rte_delay_ms(200);
1247                 diag = ixgbe_init_hw(hw);
1248         }
1249
1250         if (diag == IXGBE_ERR_SFP_NOT_PRESENT)
1251                 diag = IXGBE_SUCCESS;
1252
1253         if (diag == IXGBE_ERR_EEPROM_VERSION) {
1254                 PMD_INIT_LOG(ERR, "This device is a pre-production adapter/"
1255                              "LOM.  Please be aware there may be issues associated "
1256                              "with your hardware.");
1257                 PMD_INIT_LOG(ERR, "If you are experiencing problems "
1258                              "please contact your Intel or hardware representative "
1259                              "who provided you with this hardware.");
1260         } else if (diag == IXGBE_ERR_SFP_NOT_SUPPORTED)
1261                 PMD_INIT_LOG(ERR, "Unsupported SFP+ Module");
1262         if (diag) {
1263                 PMD_INIT_LOG(ERR, "Hardware Initialization Failure: %d", diag);
1264                 return -EIO;
1265         }
1266
1267         /* Reset the hw statistics */
1268         ixgbe_dev_stats_reset(eth_dev);
1269
1270         /* disable interrupt */
1271         ixgbe_disable_intr(hw);
1272
1273         /* reset mappings for queue statistics hw counters*/
1274         ixgbe_reset_qstat_mappings(hw);
1275
1276         /* Allocate memory for storing MAC addresses */
1277         eth_dev->data->mac_addrs = rte_zmalloc("ixgbe", ETHER_ADDR_LEN *
1278                                                hw->mac.num_rar_entries, 0);
1279         if (eth_dev->data->mac_addrs == NULL) {
1280                 PMD_INIT_LOG(ERR,
1281                              "Failed to allocate %u bytes needed to store "
1282                              "MAC addresses",
1283                              ETHER_ADDR_LEN * hw->mac.num_rar_entries);
1284                 return -ENOMEM;
1285         }
1286         /* Copy the permanent MAC address */
1287         ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
1288                         &eth_dev->data->mac_addrs[0]);
1289
1290         /* Allocate memory for storing hash filter MAC addresses */
1291         eth_dev->data->hash_mac_addrs = rte_zmalloc("ixgbe", ETHER_ADDR_LEN *
1292                                                     IXGBE_VMDQ_NUM_UC_MAC, 0);
1293         if (eth_dev->data->hash_mac_addrs == NULL) {
1294                 PMD_INIT_LOG(ERR,
1295                              "Failed to allocate %d bytes needed to store MAC addresses",
1296                              ETHER_ADDR_LEN * IXGBE_VMDQ_NUM_UC_MAC);
1297                 return -ENOMEM;
1298         }
1299
1300         /* initialize the vfta */
1301         memset(shadow_vfta, 0, sizeof(*shadow_vfta));
1302
1303         /* initialize the hw strip bitmap*/
1304         memset(hwstrip, 0, sizeof(*hwstrip));
1305
1306         /* initialize PF if max_vfs not zero */
1307         ixgbe_pf_host_init(eth_dev);
1308
1309         ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
1310         /* let hardware know driver is loaded */
1311         ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
1312         /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1313         ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
1314         IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
1315         IXGBE_WRITE_FLUSH(hw);
1316
1317         if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
1318                 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d, SFP+: %d",
1319                              (int) hw->mac.type, (int) hw->phy.type,
1320                              (int) hw->phy.sfp_type);
1321         else
1322                 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d",
1323                              (int) hw->mac.type, (int) hw->phy.type);
1324
1325         PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
1326                      eth_dev->data->port_id, pci_dev->id.vendor_id,
1327                      pci_dev->id.device_id);
1328
1329         rte_intr_callback_register(intr_handle,
1330                                    ixgbe_dev_interrupt_handler, eth_dev);
1331
1332         /* enable uio/vfio intr/eventfd mapping */
1333         rte_intr_enable(intr_handle);
1334
1335         /* enable support intr */
1336         ixgbe_enable_intr(eth_dev);
1337
1338         /* initialize filter info */
1339         memset(filter_info, 0,
1340                sizeof(struct ixgbe_filter_info));
1341
1342         /* initialize 5tuple filter list */
1343         TAILQ_INIT(&filter_info->fivetuple_list);
1344
1345         /* initialize flow director filter list & hash */
1346         ixgbe_fdir_filter_init(eth_dev);
1347
1348         /* initialize l2 tunnel filter list & hash */
1349         ixgbe_l2_tn_filter_init(eth_dev);
1350
1351         TAILQ_INIT(&filter_ntuple_list);
1352         TAILQ_INIT(&filter_ethertype_list);
1353         TAILQ_INIT(&filter_syn_list);
1354         TAILQ_INIT(&filter_fdir_list);
1355         TAILQ_INIT(&filter_l2_tunnel_list);
1356         TAILQ_INIT(&ixgbe_flow_list);
1357
1358         /* initialize bandwidth configuration info */
1359         memset(bw_conf, 0, sizeof(struct ixgbe_bw_conf));
1360
1361         return 0;
1362 }
1363
1364 static int
1365 eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
1366 {
1367         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
1368         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1369         struct ixgbe_hw *hw;
1370
1371         PMD_INIT_FUNC_TRACE();
1372
1373         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1374                 return -EPERM;
1375
1376         hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1377
1378         if (hw->adapter_stopped == 0)
1379                 ixgbe_dev_close(eth_dev);
1380
1381         eth_dev->dev_ops = NULL;
1382         eth_dev->rx_pkt_burst = NULL;
1383         eth_dev->tx_pkt_burst = NULL;
1384
1385         /* Unlock any pending hardware semaphore */
1386         ixgbe_swfw_lock_reset(hw);
1387
1388         /* disable uio intr before callback unregister */
1389         rte_intr_disable(intr_handle);
1390         rte_intr_callback_unregister(intr_handle,
1391                                      ixgbe_dev_interrupt_handler, eth_dev);
1392
1393         /* uninitialize PF if max_vfs not zero */
1394         ixgbe_pf_host_uninit(eth_dev);
1395
1396         rte_free(eth_dev->data->mac_addrs);
1397         eth_dev->data->mac_addrs = NULL;
1398
1399         rte_free(eth_dev->data->hash_mac_addrs);
1400         eth_dev->data->hash_mac_addrs = NULL;
1401
1402         /* remove all the fdir filters & hash */
1403         ixgbe_fdir_filter_uninit(eth_dev);
1404
1405         /* remove all the L2 tunnel filters & hash */
1406         ixgbe_l2_tn_filter_uninit(eth_dev);
1407
1408         /* Remove all ntuple filters of the device */
1409         ixgbe_ntuple_filter_uninit(eth_dev);
1410
1411         /* clear all the filters list */
1412         ixgbe_filterlist_flush();
1413
1414         return 0;
1415 }
1416
1417 static int ixgbe_ntuple_filter_uninit(struct rte_eth_dev *eth_dev)
1418 {
1419         struct ixgbe_filter_info *filter_info =
1420                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
1421         struct ixgbe_5tuple_filter *p_5tuple;
1422
1423         while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list))) {
1424                 TAILQ_REMOVE(&filter_info->fivetuple_list,
1425                              p_5tuple,
1426                              entries);
1427                 rte_free(p_5tuple);
1428         }
1429         memset(filter_info->fivetuple_mask, 0,
1430                sizeof(uint32_t) * IXGBE_5TUPLE_ARRAY_SIZE);
1431
1432         return 0;
1433 }
1434
1435 static int ixgbe_fdir_filter_uninit(struct rte_eth_dev *eth_dev)
1436 {
1437         struct ixgbe_hw_fdir_info *fdir_info =
1438                 IXGBE_DEV_PRIVATE_TO_FDIR_INFO(eth_dev->data->dev_private);
1439         struct ixgbe_fdir_filter *fdir_filter;
1440
1441                 if (fdir_info->hash_map)
1442                 rte_free(fdir_info->hash_map);
1443         if (fdir_info->hash_handle)
1444                 rte_hash_free(fdir_info->hash_handle);
1445
1446         while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
1447                 TAILQ_REMOVE(&fdir_info->fdir_list,
1448                              fdir_filter,
1449                              entries);
1450                 rte_free(fdir_filter);
1451         }
1452
1453         return 0;
1454 }
1455
1456 static int ixgbe_l2_tn_filter_uninit(struct rte_eth_dev *eth_dev)
1457 {
1458         struct ixgbe_l2_tn_info *l2_tn_info =
1459                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(eth_dev->data->dev_private);
1460         struct ixgbe_l2_tn_filter *l2_tn_filter;
1461
1462         if (l2_tn_info->hash_map)
1463                 rte_free(l2_tn_info->hash_map);
1464         if (l2_tn_info->hash_handle)
1465                 rte_hash_free(l2_tn_info->hash_handle);
1466
1467         while ((l2_tn_filter = TAILQ_FIRST(&l2_tn_info->l2_tn_list))) {
1468                 TAILQ_REMOVE(&l2_tn_info->l2_tn_list,
1469                              l2_tn_filter,
1470                              entries);
1471                 rte_free(l2_tn_filter);
1472         }
1473
1474         return 0;
1475 }
1476
1477 static int ixgbe_fdir_filter_init(struct rte_eth_dev *eth_dev)
1478 {
1479         struct ixgbe_hw_fdir_info *fdir_info =
1480                 IXGBE_DEV_PRIVATE_TO_FDIR_INFO(eth_dev->data->dev_private);
1481         char fdir_hash_name[RTE_HASH_NAMESIZE];
1482         struct rte_hash_parameters fdir_hash_params = {
1483                 .name = fdir_hash_name,
1484                 .entries = IXGBE_MAX_FDIR_FILTER_NUM,
1485                 .key_len = sizeof(union ixgbe_atr_input),
1486                 .hash_func = rte_hash_crc,
1487                 .hash_func_init_val = 0,
1488                 .socket_id = rte_socket_id(),
1489         };
1490
1491         TAILQ_INIT(&fdir_info->fdir_list);
1492         snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
1493                  "fdir_%s", eth_dev->data->name);
1494         fdir_info->hash_handle = rte_hash_create(&fdir_hash_params);
1495         if (!fdir_info->hash_handle) {
1496                 PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
1497                 return -EINVAL;
1498         }
1499         fdir_info->hash_map = rte_zmalloc("ixgbe",
1500                                           sizeof(struct ixgbe_fdir_filter *) *
1501                                           IXGBE_MAX_FDIR_FILTER_NUM,
1502                                           0);
1503         if (!fdir_info->hash_map) {
1504                 PMD_INIT_LOG(ERR,
1505                              "Failed to allocate memory for fdir hash map!");
1506                 return -ENOMEM;
1507         }
1508         fdir_info->mask_added = FALSE;
1509
1510         return 0;
1511 }
1512
1513 static int ixgbe_l2_tn_filter_init(struct rte_eth_dev *eth_dev)
1514 {
1515         struct ixgbe_l2_tn_info *l2_tn_info =
1516                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(eth_dev->data->dev_private);
1517         char l2_tn_hash_name[RTE_HASH_NAMESIZE];
1518         struct rte_hash_parameters l2_tn_hash_params = {
1519                 .name = l2_tn_hash_name,
1520                 .entries = IXGBE_MAX_L2_TN_FILTER_NUM,
1521                 .key_len = sizeof(struct ixgbe_l2_tn_key),
1522                 .hash_func = rte_hash_crc,
1523                 .hash_func_init_val = 0,
1524                 .socket_id = rte_socket_id(),
1525         };
1526
1527         TAILQ_INIT(&l2_tn_info->l2_tn_list);
1528         snprintf(l2_tn_hash_name, RTE_HASH_NAMESIZE,
1529                  "l2_tn_%s", eth_dev->data->name);
1530         l2_tn_info->hash_handle = rte_hash_create(&l2_tn_hash_params);
1531         if (!l2_tn_info->hash_handle) {
1532                 PMD_INIT_LOG(ERR, "Failed to create L2 TN hash table!");
1533                 return -EINVAL;
1534         }
1535         l2_tn_info->hash_map = rte_zmalloc("ixgbe",
1536                                    sizeof(struct ixgbe_l2_tn_filter *) *
1537                                    IXGBE_MAX_L2_TN_FILTER_NUM,
1538                                    0);
1539         if (!l2_tn_info->hash_map) {
1540                 PMD_INIT_LOG(ERR,
1541                         "Failed to allocate memory for L2 TN hash map!");
1542                 return -ENOMEM;
1543         }
1544         l2_tn_info->e_tag_en = FALSE;
1545         l2_tn_info->e_tag_fwd_en = FALSE;
1546         l2_tn_info->e_tag_ether_type = DEFAULT_ETAG_ETYPE;
1547
1548         return 0;
1549 }
1550 /*
1551  * Negotiate mailbox API version with the PF.
1552  * After reset API version is always set to the basic one (ixgbe_mbox_api_10).
1553  * Then we try to negotiate starting with the most recent one.
1554  * If all negotiation attempts fail, then we will proceed with
1555  * the default one (ixgbe_mbox_api_10).
1556  */
1557 static void
1558 ixgbevf_negotiate_api(struct ixgbe_hw *hw)
1559 {
1560         int32_t i;
1561
1562         /* start with highest supported, proceed down */
1563         static const enum ixgbe_pfvf_api_rev sup_ver[] = {
1564                 ixgbe_mbox_api_12,
1565                 ixgbe_mbox_api_11,
1566                 ixgbe_mbox_api_10,
1567         };
1568
1569         for (i = 0;
1570                         i != RTE_DIM(sup_ver) &&
1571                         ixgbevf_negotiate_api_version(hw, sup_ver[i]) != 0;
1572                         i++)
1573                 ;
1574 }
1575
1576 static void
1577 generate_random_mac_addr(struct ether_addr *mac_addr)
1578 {
1579         uint64_t random;
1580
1581         /* Set Organizationally Unique Identifier (OUI) prefix. */
1582         mac_addr->addr_bytes[0] = 0x00;
1583         mac_addr->addr_bytes[1] = 0x09;
1584         mac_addr->addr_bytes[2] = 0xC0;
1585         /* Force indication of locally assigned MAC address. */
1586         mac_addr->addr_bytes[0] |= ETHER_LOCAL_ADMIN_ADDR;
1587         /* Generate the last 3 bytes of the MAC address with a random number. */
1588         random = rte_rand();
1589         memcpy(&mac_addr->addr_bytes[3], &random, 3);
1590 }
1591
1592 /*
1593  * Virtual Function device init
1594  */
1595 static int
1596 eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
1597 {
1598         int diag;
1599         uint32_t tc, tcs;
1600         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
1601         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1602         struct ixgbe_hw *hw =
1603                 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1604         struct ixgbe_vfta *shadow_vfta =
1605                 IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
1606         struct ixgbe_hwstrip *hwstrip =
1607                 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
1608         struct ether_addr *perm_addr = (struct ether_addr *) hw->mac.perm_addr;
1609
1610         PMD_INIT_FUNC_TRACE();
1611
1612         eth_dev->dev_ops = &ixgbevf_eth_dev_ops;
1613         eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
1614         eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
1615
1616         /* for secondary processes, we don't initialise any further as primary
1617          * has already done this work. Only check we don't need a different
1618          * RX function
1619          */
1620         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1621                 struct ixgbe_tx_queue *txq;
1622                 /* TX queue function in primary, set by last queue initialized
1623                  * Tx queue may not initialized by primary process
1624                  */
1625                 if (eth_dev->data->tx_queues) {
1626                         txq = eth_dev->data->tx_queues[eth_dev->data->nb_tx_queues - 1];
1627                         ixgbe_set_tx_function(eth_dev, txq);
1628                 } else {
1629                         /* Use default TX function if we get here */
1630                         PMD_INIT_LOG(NOTICE,
1631                                      "No TX queues configured yet. Using default TX function.");
1632                 }
1633
1634                 ixgbe_set_rx_function(eth_dev);
1635
1636                 return 0;
1637         }
1638
1639         rte_eth_copy_pci_info(eth_dev, pci_dev);
1640         eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1641
1642         hw->device_id = pci_dev->id.device_id;
1643         hw->vendor_id = pci_dev->id.vendor_id;
1644         hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1645
1646         /* initialize the vfta */
1647         memset(shadow_vfta, 0, sizeof(*shadow_vfta));
1648
1649         /* initialize the hw strip bitmap*/
1650         memset(hwstrip, 0, sizeof(*hwstrip));
1651
1652         /* Initialize the shared code (base driver) */
1653         diag = ixgbe_init_shared_code(hw);
1654         if (diag != IXGBE_SUCCESS) {
1655                 PMD_INIT_LOG(ERR, "Shared code init failed for ixgbevf: %d", diag);
1656                 return -EIO;
1657         }
1658
1659         /* init_mailbox_params */
1660         hw->mbx.ops.init_params(hw);
1661
1662         /* Reset the hw statistics */
1663         ixgbevf_dev_stats_reset(eth_dev);
1664
1665         /* Disable the interrupts for VF */
1666         ixgbevf_intr_disable(hw);
1667
1668         hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
1669         diag = hw->mac.ops.reset_hw(hw);
1670
1671         /*
1672          * The VF reset operation returns the IXGBE_ERR_INVALID_MAC_ADDR when
1673          * the underlying PF driver has not assigned a MAC address to the VF.
1674          * In this case, assign a random MAC address.
1675          */
1676         if ((diag != IXGBE_SUCCESS) && (diag != IXGBE_ERR_INVALID_MAC_ADDR)) {
1677                 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
1678                 return diag;
1679         }
1680
1681         /* negotiate mailbox API version to use with the PF. */
1682         ixgbevf_negotiate_api(hw);
1683
1684         /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
1685         ixgbevf_get_queues(hw, &tcs, &tc);
1686
1687         /* Allocate memory for storing MAC addresses */
1688         eth_dev->data->mac_addrs = rte_zmalloc("ixgbevf", ETHER_ADDR_LEN *
1689                                                hw->mac.num_rar_entries, 0);
1690         if (eth_dev->data->mac_addrs == NULL) {
1691                 PMD_INIT_LOG(ERR,
1692                              "Failed to allocate %u bytes needed to store "
1693                              "MAC addresses",
1694                              ETHER_ADDR_LEN * hw->mac.num_rar_entries);
1695                 return -ENOMEM;
1696         }
1697
1698         /* Generate a random MAC address, if none was assigned by PF. */
1699         if (is_zero_ether_addr(perm_addr)) {
1700                 generate_random_mac_addr(perm_addr);
1701                 diag = ixgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
1702                 if (diag) {
1703                         rte_free(eth_dev->data->mac_addrs);
1704                         eth_dev->data->mac_addrs = NULL;
1705                         return diag;
1706                 }
1707                 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1708                 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1709                              "%02x:%02x:%02x:%02x:%02x:%02x",
1710                              perm_addr->addr_bytes[0],
1711                              perm_addr->addr_bytes[1],
1712                              perm_addr->addr_bytes[2],
1713                              perm_addr->addr_bytes[3],
1714                              perm_addr->addr_bytes[4],
1715                              perm_addr->addr_bytes[5]);
1716         }
1717
1718         /* Copy the permanent MAC address */
1719         ether_addr_copy(perm_addr, &eth_dev->data->mac_addrs[0]);
1720
1721         /* reset the hardware with the new settings */
1722         diag = hw->mac.ops.start_hw(hw);
1723         switch (diag) {
1724         case  0:
1725                 break;
1726
1727         default:
1728                 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
1729                 return -EIO;
1730         }
1731
1732         rte_intr_callback_register(intr_handle,
1733                                    ixgbevf_dev_interrupt_handler, eth_dev);
1734         rte_intr_enable(intr_handle);
1735         ixgbevf_intr_enable(hw);
1736
1737         PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
1738                      eth_dev->data->port_id, pci_dev->id.vendor_id,
1739                      pci_dev->id.device_id, "ixgbe_mac_82599_vf");
1740
1741         return 0;
1742 }
1743
1744 /* Virtual Function device uninit */
1745
1746 static int
1747 eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
1748 {
1749         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(eth_dev);
1750         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1751         struct ixgbe_hw *hw;
1752
1753         PMD_INIT_FUNC_TRACE();
1754
1755         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1756                 return -EPERM;
1757
1758         hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1759
1760         if (hw->adapter_stopped == 0)
1761                 ixgbevf_dev_close(eth_dev);
1762
1763         eth_dev->dev_ops = NULL;
1764         eth_dev->rx_pkt_burst = NULL;
1765         eth_dev->tx_pkt_burst = NULL;
1766
1767         /* Disable the interrupts for VF */
1768         ixgbevf_intr_disable(hw);
1769
1770         rte_free(eth_dev->data->mac_addrs);
1771         eth_dev->data->mac_addrs = NULL;
1772
1773         rte_intr_disable(intr_handle);
1774         rte_intr_callback_unregister(intr_handle,
1775                                      ixgbevf_dev_interrupt_handler, eth_dev);
1776
1777         return 0;
1778 }
1779
1780 static int eth_ixgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1781         struct rte_pci_device *pci_dev)
1782 {
1783         return rte_eth_dev_pci_generic_probe(pci_dev,
1784                 sizeof(struct ixgbe_adapter), eth_ixgbe_dev_init);
1785 }
1786
1787 static int eth_ixgbe_pci_remove(struct rte_pci_device *pci_dev)
1788 {
1789         return rte_eth_dev_pci_generic_remove(pci_dev, eth_ixgbe_dev_uninit);
1790 }
1791
1792 static struct rte_pci_driver rte_ixgbe_pmd = {
1793         .id_table = pci_id_ixgbe_map,
1794         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1795         .probe = eth_ixgbe_pci_probe,
1796         .remove = eth_ixgbe_pci_remove,
1797 };
1798
1799 static int eth_ixgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1800         struct rte_pci_device *pci_dev)
1801 {
1802         return rte_eth_dev_pci_generic_probe(pci_dev,
1803                 sizeof(struct ixgbe_adapter), eth_ixgbevf_dev_init);
1804 }
1805
1806 static int eth_ixgbevf_pci_remove(struct rte_pci_device *pci_dev)
1807 {
1808         return rte_eth_dev_pci_generic_remove(pci_dev, eth_ixgbevf_dev_uninit);
1809 }
1810
1811 /*
1812  * virtual function driver struct
1813  */
1814 static struct rte_pci_driver rte_ixgbevf_pmd = {
1815         .id_table = pci_id_ixgbevf_map,
1816         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1817         .probe = eth_ixgbevf_pci_probe,
1818         .remove = eth_ixgbevf_pci_remove,
1819 };
1820
1821 static int
1822 ixgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1823 {
1824         struct ixgbe_hw *hw =
1825                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1826         struct ixgbe_vfta *shadow_vfta =
1827                 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1828         uint32_t vfta;
1829         uint32_t vid_idx;
1830         uint32_t vid_bit;
1831
1832         vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
1833         vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
1834         vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(vid_idx));
1835         if (on)
1836                 vfta |= vid_bit;
1837         else
1838                 vfta &= ~vid_bit;
1839         IXGBE_WRITE_REG(hw, IXGBE_VFTA(vid_idx), vfta);
1840
1841         /* update local VFTA copy */
1842         shadow_vfta->vfta[vid_idx] = vfta;
1843
1844         return 0;
1845 }
1846
1847 static void
1848 ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
1849 {
1850         if (on)
1851                 ixgbe_vlan_hw_strip_enable(dev, queue);
1852         else
1853                 ixgbe_vlan_hw_strip_disable(dev, queue);
1854 }
1855
1856 static int
1857 ixgbe_vlan_tpid_set(struct rte_eth_dev *dev,
1858                     enum rte_vlan_type vlan_type,
1859                     uint16_t tpid)
1860 {
1861         struct ixgbe_hw *hw =
1862                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1863         int ret = 0;
1864         uint32_t reg;
1865         uint32_t qinq;
1866
1867         qinq = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1868         qinq &= IXGBE_DMATXCTL_GDV;
1869
1870         switch (vlan_type) {
1871         case ETH_VLAN_TYPE_INNER:
1872                 if (qinq) {
1873                         reg = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1874                         reg = (reg & (~IXGBE_VLNCTRL_VET)) | (uint32_t)tpid;
1875                         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, reg);
1876                         reg = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1877                         reg = (reg & (~IXGBE_DMATXCTL_VT_MASK))
1878                                 | ((uint32_t)tpid << IXGBE_DMATXCTL_VT_SHIFT);
1879                         IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg);
1880                 } else {
1881                         ret = -ENOTSUP;
1882                         PMD_DRV_LOG(ERR, "Inner type is not supported"
1883                                     " by single VLAN");
1884                 }
1885                 break;
1886         case ETH_VLAN_TYPE_OUTER:
1887                 if (qinq) {
1888                         /* Only the high 16-bits is valid */
1889                         IXGBE_WRITE_REG(hw, IXGBE_EXVET, (uint32_t)tpid <<
1890                                         IXGBE_EXVET_VET_EXT_SHIFT);
1891                 } else {
1892                         reg = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1893                         reg = (reg & (~IXGBE_VLNCTRL_VET)) | (uint32_t)tpid;
1894                         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, reg);
1895                         reg = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1896                         reg = (reg & (~IXGBE_DMATXCTL_VT_MASK))
1897                                 | ((uint32_t)tpid << IXGBE_DMATXCTL_VT_SHIFT);
1898                         IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg);
1899                 }
1900
1901                 break;
1902         default:
1903                 ret = -EINVAL;
1904                 PMD_DRV_LOG(ERR, "Unsupported VLAN type %d", vlan_type);
1905                 break;
1906         }
1907
1908         return ret;
1909 }
1910
1911 void
1912 ixgbe_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1913 {
1914         struct ixgbe_hw *hw =
1915                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1916         uint32_t vlnctrl;
1917
1918         PMD_INIT_FUNC_TRACE();
1919
1920         /* Filter Table Disable */
1921         vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1922         vlnctrl &= ~IXGBE_VLNCTRL_VFE;
1923
1924         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1925 }
1926
1927 void
1928 ixgbe_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1929 {
1930         struct ixgbe_hw *hw =
1931                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1932         struct ixgbe_vfta *shadow_vfta =
1933                 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1934         uint32_t vlnctrl;
1935         uint16_t i;
1936
1937         PMD_INIT_FUNC_TRACE();
1938
1939         /* Filter Table Enable */
1940         vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1941         vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1942         vlnctrl |= IXGBE_VLNCTRL_VFE;
1943
1944         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1945
1946         /* write whatever is in local vfta copy */
1947         for (i = 0; i < IXGBE_VFTA_SIZE; i++)
1948                 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), shadow_vfta->vfta[i]);
1949 }
1950
1951 static void
1952 ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev, uint16_t queue, bool on)
1953 {
1954         struct ixgbe_hwstrip *hwstrip =
1955                 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(dev->data->dev_private);
1956         struct ixgbe_rx_queue *rxq;
1957
1958         if (queue >= IXGBE_MAX_RX_QUEUE_NUM)
1959                 return;
1960
1961         if (on)
1962                 IXGBE_SET_HWSTRIP(hwstrip, queue);
1963         else
1964                 IXGBE_CLEAR_HWSTRIP(hwstrip, queue);
1965
1966         if (queue >= dev->data->nb_rx_queues)
1967                 return;
1968
1969         rxq = dev->data->rx_queues[queue];
1970
1971         if (on)
1972                 rxq->vlan_flags = PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED;
1973         else
1974                 rxq->vlan_flags = PKT_RX_VLAN_PKT;
1975 }
1976
1977 static void
1978 ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue)
1979 {
1980         struct ixgbe_hw *hw =
1981                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1982         uint32_t ctrl;
1983
1984         PMD_INIT_FUNC_TRACE();
1985
1986         if (hw->mac.type == ixgbe_mac_82598EB) {
1987                 /* No queue level support */
1988                 PMD_INIT_LOG(NOTICE, "82598EB not support queue level hw strip");
1989                 return;
1990         }
1991
1992         /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1993         ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
1994         ctrl &= ~IXGBE_RXDCTL_VME;
1995         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
1996
1997         /* record those setting for HW strip per queue */
1998         ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 0);
1999 }
2000
2001 static void
2002 ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue)
2003 {
2004         struct ixgbe_hw *hw =
2005                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2006         uint32_t ctrl;
2007
2008         PMD_INIT_FUNC_TRACE();
2009
2010         if (hw->mac.type == ixgbe_mac_82598EB) {
2011                 /* No queue level supported */
2012                 PMD_INIT_LOG(NOTICE, "82598EB not support queue level hw strip");
2013                 return;
2014         }
2015
2016         /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
2017         ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
2018         ctrl |= IXGBE_RXDCTL_VME;
2019         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
2020
2021         /* record those setting for HW strip per queue */
2022         ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 1);
2023 }
2024
2025 void
2026 ixgbe_vlan_hw_strip_disable_all(struct rte_eth_dev *dev)
2027 {
2028         struct ixgbe_hw *hw =
2029                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2030         uint32_t ctrl;
2031         uint16_t i;
2032         struct ixgbe_rx_queue *rxq;
2033
2034         PMD_INIT_FUNC_TRACE();
2035
2036         if (hw->mac.type == ixgbe_mac_82598EB) {
2037                 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
2038                 ctrl &= ~IXGBE_VLNCTRL_VME;
2039                 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
2040         } else {
2041                 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
2042                 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2043                         rxq = dev->data->rx_queues[i];
2044                         ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
2045                         ctrl &= ~IXGBE_RXDCTL_VME;
2046                         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxq->reg_idx), ctrl);
2047
2048                         /* record those setting for HW strip per queue */
2049                         ixgbe_vlan_hw_strip_bitmap_set(dev, i, 0);
2050                 }
2051         }
2052 }
2053
2054 void
2055 ixgbe_vlan_hw_strip_enable_all(struct rte_eth_dev *dev)
2056 {
2057         struct ixgbe_hw *hw =
2058                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2059         uint32_t ctrl;
2060         uint16_t i;
2061         struct ixgbe_rx_queue *rxq;
2062
2063         PMD_INIT_FUNC_TRACE();
2064
2065         if (hw->mac.type == ixgbe_mac_82598EB) {
2066                 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
2067                 ctrl |= IXGBE_VLNCTRL_VME;
2068                 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
2069         } else {
2070                 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
2071                 for (i = 0; i < dev->data->nb_rx_queues; i++) {
2072                         rxq = dev->data->rx_queues[i];
2073                         ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
2074                         ctrl |= IXGBE_RXDCTL_VME;
2075                         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxq->reg_idx), ctrl);
2076
2077                         /* record those setting for HW strip per queue */
2078                         ixgbe_vlan_hw_strip_bitmap_set(dev, i, 1);
2079                 }
2080         }
2081 }
2082
2083 static void
2084 ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2085 {
2086         struct ixgbe_hw *hw =
2087                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2088         uint32_t ctrl;
2089
2090         PMD_INIT_FUNC_TRACE();
2091
2092         /* DMATXCTRL: Geric Double VLAN Disable */
2093         ctrl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2094         ctrl &= ~IXGBE_DMATXCTL_GDV;
2095         IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
2096
2097         /* CTRL_EXT: Global Double VLAN Disable */
2098         ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
2099         ctrl &= ~IXGBE_EXTENDED_VLAN;
2100         IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
2101
2102 }
2103
2104 static void
2105 ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2106 {
2107         struct ixgbe_hw *hw =
2108                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2109         uint32_t ctrl;
2110
2111         PMD_INIT_FUNC_TRACE();
2112
2113         /* DMATXCTRL: Geric Double VLAN Enable */
2114         ctrl  = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2115         ctrl |= IXGBE_DMATXCTL_GDV;
2116         IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
2117
2118         /* CTRL_EXT: Global Double VLAN Enable */
2119         ctrl  = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
2120         ctrl |= IXGBE_EXTENDED_VLAN;
2121         IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
2122
2123         /* Clear pooling mode of PFVTCTL. It's required by X550. */
2124         if (hw->mac.type == ixgbe_mac_X550 ||
2125             hw->mac.type == ixgbe_mac_X550EM_x ||
2126             hw->mac.type == ixgbe_mac_X550EM_a) {
2127                 ctrl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2128                 ctrl &= ~IXGBE_VT_CTL_POOLING_MODE_MASK;
2129                 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, ctrl);
2130         }
2131
2132         /*
2133          * VET EXT field in the EXVET register = 0x8100 by default
2134          * So no need to change. Same to VT field of DMATXCTL register
2135          */
2136 }
2137
2138 static void
2139 ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2140 {
2141         if (mask & ETH_VLAN_STRIP_MASK) {
2142                 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2143                         ixgbe_vlan_hw_strip_enable_all(dev);
2144                 else
2145                         ixgbe_vlan_hw_strip_disable_all(dev);
2146         }
2147
2148         if (mask & ETH_VLAN_FILTER_MASK) {
2149                 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2150                         ixgbe_vlan_hw_filter_enable(dev);
2151                 else
2152                         ixgbe_vlan_hw_filter_disable(dev);
2153         }
2154
2155         if (mask & ETH_VLAN_EXTEND_MASK) {
2156                 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2157                         ixgbe_vlan_hw_extend_enable(dev);
2158                 else
2159                         ixgbe_vlan_hw_extend_disable(dev);
2160         }
2161 }
2162
2163 static void
2164 ixgbe_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2165 {
2166         struct ixgbe_hw *hw =
2167                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2168         /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
2169         uint32_t vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
2170
2171         vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
2172         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
2173 }
2174
2175 static int
2176 ixgbe_check_vf_rss_rxq_num(struct rte_eth_dev *dev, uint16_t nb_rx_q)
2177 {
2178         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
2179
2180         switch (nb_rx_q) {
2181         case 1:
2182         case 2:
2183                 RTE_ETH_DEV_SRIOV(dev).active = ETH_64_POOLS;
2184                 break;
2185         case 4:
2186                 RTE_ETH_DEV_SRIOV(dev).active = ETH_32_POOLS;
2187                 break;
2188         default:
2189                 return -EINVAL;
2190         }
2191
2192         RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
2193         RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx = pci_dev->max_vfs * nb_rx_q;
2194
2195         return 0;
2196 }
2197
2198 static int
2199 ixgbe_check_mq_mode(struct rte_eth_dev *dev)
2200 {
2201         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
2202         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2203         uint16_t nb_rx_q = dev->data->nb_rx_queues;
2204         uint16_t nb_tx_q = dev->data->nb_tx_queues;
2205
2206         if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
2207                 /* check multi-queue mode */
2208                 switch (dev_conf->rxmode.mq_mode) {
2209                 case ETH_MQ_RX_VMDQ_DCB:
2210                         PMD_INIT_LOG(INFO, "ETH_MQ_RX_VMDQ_DCB mode supported in SRIOV");
2211                         break;
2212                 case ETH_MQ_RX_VMDQ_DCB_RSS:
2213                         /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
2214                         PMD_INIT_LOG(ERR, "SRIOV active,"
2215                                         " unsupported mq_mode rx %d.",
2216                                         dev_conf->rxmode.mq_mode);
2217                         return -EINVAL;
2218                 case ETH_MQ_RX_RSS:
2219                 case ETH_MQ_RX_VMDQ_RSS:
2220                         dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
2221                         if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
2222                                 if (ixgbe_check_vf_rss_rxq_num(dev, nb_rx_q)) {
2223                                         PMD_INIT_LOG(ERR, "SRIOV is active,"
2224                                                 " invalid queue number"
2225                                                 " for VMDQ RSS, allowed"
2226                                                 " value are 1, 2 or 4.");
2227                                         return -EINVAL;
2228                                 }
2229                         break;
2230                 case ETH_MQ_RX_VMDQ_ONLY:
2231                 case ETH_MQ_RX_NONE:
2232                         /* if nothing mq mode configure, use default scheme */
2233                         dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
2234                         if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
2235                                 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
2236                         break;
2237                 default: /* ETH_MQ_RX_DCB, ETH_MQ_RX_DCB_RSS or ETH_MQ_TX_DCB*/
2238                         /* SRIOV only works in VMDq enable mode */
2239                         PMD_INIT_LOG(ERR, "SRIOV is active,"
2240                                         " wrong mq_mode rx %d.",
2241                                         dev_conf->rxmode.mq_mode);
2242                         return -EINVAL;
2243                 }
2244
2245                 switch (dev_conf->txmode.mq_mode) {
2246                 case ETH_MQ_TX_VMDQ_DCB:
2247                         PMD_INIT_LOG(INFO, "ETH_MQ_TX_VMDQ_DCB mode supported in SRIOV");
2248                         dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_DCB;
2249                         break;
2250                 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
2251                         dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
2252                         break;
2253                 }
2254
2255                 /* check valid queue number */
2256                 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
2257                     (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
2258                         PMD_INIT_LOG(ERR, "SRIOV is active,"
2259                                         " nb_rx_q=%d nb_tx_q=%d queue number"
2260                                         " must be less than or equal to %d.",
2261                                         nb_rx_q, nb_tx_q,
2262                                         RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
2263                         return -EINVAL;
2264                 }
2265         } else {
2266                 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB_RSS) {
2267                         PMD_INIT_LOG(ERR, "VMDQ+DCB+RSS mq_mode is"
2268                                           " not supported.");
2269                         return -EINVAL;
2270                 }
2271                 /* check configuration for vmdb+dcb mode */
2272                 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
2273                         const struct rte_eth_vmdq_dcb_conf *conf;
2274
2275                         if (nb_rx_q != IXGBE_VMDQ_DCB_NB_QUEUES) {
2276                                 PMD_INIT_LOG(ERR, "VMDQ+DCB, nb_rx_q != %d.",
2277                                                 IXGBE_VMDQ_DCB_NB_QUEUES);
2278                                 return -EINVAL;
2279                         }
2280                         conf = &dev_conf->rx_adv_conf.vmdq_dcb_conf;
2281                         if (!(conf->nb_queue_pools == ETH_16_POOLS ||
2282                                conf->nb_queue_pools == ETH_32_POOLS)) {
2283                                 PMD_INIT_LOG(ERR, "VMDQ+DCB selected,"
2284                                                 " nb_queue_pools must be %d or %d.",
2285                                                 ETH_16_POOLS, ETH_32_POOLS);
2286                                 return -EINVAL;
2287                         }
2288                 }
2289                 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
2290                         const struct rte_eth_vmdq_dcb_tx_conf *conf;
2291
2292                         if (nb_tx_q != IXGBE_VMDQ_DCB_NB_QUEUES) {
2293                                 PMD_INIT_LOG(ERR, "VMDQ+DCB, nb_tx_q != %d",
2294                                                  IXGBE_VMDQ_DCB_NB_QUEUES);
2295                                 return -EINVAL;
2296                         }
2297                         conf = &dev_conf->tx_adv_conf.vmdq_dcb_tx_conf;
2298                         if (!(conf->nb_queue_pools == ETH_16_POOLS ||
2299                                conf->nb_queue_pools == ETH_32_POOLS)) {
2300                                 PMD_INIT_LOG(ERR, "VMDQ+DCB selected,"
2301                                                 " nb_queue_pools != %d and"
2302                                                 " nb_queue_pools != %d.",
2303                                                 ETH_16_POOLS, ETH_32_POOLS);
2304                                 return -EINVAL;
2305                         }
2306                 }
2307
2308                 /* For DCB mode check our configuration before we go further */
2309                 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
2310                         const struct rte_eth_dcb_rx_conf *conf;
2311
2312                         if (nb_rx_q != IXGBE_DCB_NB_QUEUES) {
2313                                 PMD_INIT_LOG(ERR, "DCB selected, nb_rx_q != %d.",
2314                                                  IXGBE_DCB_NB_QUEUES);
2315                                 return -EINVAL;
2316                         }
2317                         conf = &dev_conf->rx_adv_conf.dcb_rx_conf;
2318                         if (!(conf->nb_tcs == ETH_4_TCS ||
2319                                conf->nb_tcs == ETH_8_TCS)) {
2320                                 PMD_INIT_LOG(ERR, "DCB selected, nb_tcs != %d"
2321                                                 " and nb_tcs != %d.",
2322                                                 ETH_4_TCS, ETH_8_TCS);
2323                                 return -EINVAL;
2324                         }
2325                 }
2326
2327                 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
2328                         const struct rte_eth_dcb_tx_conf *conf;
2329
2330                         if (nb_tx_q != IXGBE_DCB_NB_QUEUES) {
2331                                 PMD_INIT_LOG(ERR, "DCB, nb_tx_q != %d.",
2332                                                  IXGBE_DCB_NB_QUEUES);
2333                                 return -EINVAL;
2334                         }
2335                         conf = &dev_conf->tx_adv_conf.dcb_tx_conf;
2336                         if (!(conf->nb_tcs == ETH_4_TCS ||
2337                                conf->nb_tcs == ETH_8_TCS)) {
2338                                 PMD_INIT_LOG(ERR, "DCB selected, nb_tcs != %d"
2339                                                 " and nb_tcs != %d.",
2340                                                 ETH_4_TCS, ETH_8_TCS);
2341                                 return -EINVAL;
2342                         }
2343                 }
2344
2345                 /*
2346                  * When DCB/VT is off, maximum number of queues changes,
2347                  * except for 82598EB, which remains constant.
2348                  */
2349                 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_NONE &&
2350                                 hw->mac.type != ixgbe_mac_82598EB) {
2351                         if (nb_tx_q > IXGBE_NONE_MODE_TX_NB_QUEUES) {
2352                                 PMD_INIT_LOG(ERR,
2353                                              "Neither VT nor DCB are enabled, "
2354                                              "nb_tx_q > %d.",
2355                                              IXGBE_NONE_MODE_TX_NB_QUEUES);
2356                                 return -EINVAL;
2357                         }
2358                 }
2359         }
2360         return 0;
2361 }
2362
2363 static int
2364 ixgbe_dev_configure(struct rte_eth_dev *dev)
2365 {
2366         struct ixgbe_interrupt *intr =
2367                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2368         struct ixgbe_adapter *adapter =
2369                 (struct ixgbe_adapter *)dev->data->dev_private;
2370         int ret;
2371
2372         PMD_INIT_FUNC_TRACE();
2373         /* multipe queue mode checking */
2374         ret  = ixgbe_check_mq_mode(dev);
2375         if (ret != 0) {
2376                 PMD_DRV_LOG(ERR, "ixgbe_check_mq_mode fails with %d.",
2377                             ret);
2378                 return ret;
2379         }
2380
2381         /* set flag to update link status after init */
2382         intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2383
2384         /*
2385          * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
2386          * allocation or vector Rx preconditions we will reset it.
2387          */
2388         adapter->rx_bulk_alloc_allowed = true;
2389         adapter->rx_vec_allowed = true;
2390
2391         return 0;
2392 }
2393
2394 static void
2395 ixgbe_dev_phy_intr_setup(struct rte_eth_dev *dev)
2396 {
2397         struct ixgbe_hw *hw =
2398                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2399         struct ixgbe_interrupt *intr =
2400                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2401         uint32_t gpie;
2402
2403         /* only set up it on X550EM_X */
2404         if (hw->mac.type == ixgbe_mac_X550EM_x) {
2405                 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2406                 gpie |= IXGBE_SDP0_GPIEN_X550EM_x;
2407                 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2408                 if (hw->phy.type == ixgbe_phy_x550em_ext_t)
2409                         intr->mask |= IXGBE_EICR_GPI_SDP0_X550EM_x;
2410         }
2411 }
2412
2413 int
2414 ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
2415                         uint16_t tx_rate, uint64_t q_msk)
2416 {
2417         struct ixgbe_hw *hw;
2418         struct ixgbe_vf_info *vfinfo;
2419         struct rte_eth_link link;
2420         uint8_t  nb_q_per_pool;
2421         uint32_t queue_stride;
2422         uint32_t queue_idx, idx = 0, vf_idx;
2423         uint32_t queue_end;
2424         uint16_t total_rate = 0;
2425         struct rte_pci_device *pci_dev;
2426
2427         pci_dev = IXGBE_DEV_TO_PCI(dev);
2428         rte_eth_link_get_nowait(dev->data->port_id, &link);
2429
2430         if (vf >= pci_dev->max_vfs)
2431                 return -EINVAL;
2432
2433         if (tx_rate > link.link_speed)
2434                 return -EINVAL;
2435
2436         if (q_msk == 0)
2437                 return 0;
2438
2439         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2440         vfinfo = *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
2441         nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
2442         queue_stride = IXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
2443         queue_idx = vf * queue_stride;
2444         queue_end = queue_idx + nb_q_per_pool - 1;
2445         if (queue_end >= hw->mac.max_tx_queues)
2446                 return -EINVAL;
2447
2448         if (vfinfo) {
2449                 for (vf_idx = 0; vf_idx < pci_dev->max_vfs; vf_idx++) {
2450                         if (vf_idx == vf)
2451                                 continue;
2452                         for (idx = 0; idx < RTE_DIM(vfinfo[vf_idx].tx_rate);
2453                                 idx++)
2454                                 total_rate += vfinfo[vf_idx].tx_rate[idx];
2455                 }
2456         } else {
2457                 return -EINVAL;
2458         }
2459
2460         /* Store tx_rate for this vf. */
2461         for (idx = 0; idx < nb_q_per_pool; idx++) {
2462                 if (((uint64_t)0x1 << idx) & q_msk) {
2463                         if (vfinfo[vf].tx_rate[idx] != tx_rate)
2464                                 vfinfo[vf].tx_rate[idx] = tx_rate;
2465                         total_rate += tx_rate;
2466                 }
2467         }
2468
2469         if (total_rate > dev->data->dev_link.link_speed) {
2470                 /* Reset stored TX rate of the VF if it causes exceed
2471                  * link speed.
2472                  */
2473                 memset(vfinfo[vf].tx_rate, 0, sizeof(vfinfo[vf].tx_rate));
2474                 return -EINVAL;
2475         }
2476
2477         /* Set RTTBCNRC of each queue/pool for vf X  */
2478         for (; queue_idx <= queue_end; queue_idx++) {
2479                 if (0x1 & q_msk)
2480                         ixgbe_set_queue_rate_limit(dev, queue_idx, tx_rate);
2481                 q_msk = q_msk >> 1;
2482         }
2483
2484         return 0;
2485 }
2486
2487 /*
2488  * Configure device link speed and setup link.
2489  * It returns 0 on success.
2490  */
2491 static int
2492 ixgbe_dev_start(struct rte_eth_dev *dev)
2493 {
2494         struct ixgbe_hw *hw =
2495                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2496         struct ixgbe_vf_info *vfinfo =
2497                 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
2498         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
2499         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2500         uint32_t intr_vector = 0;
2501         int err, link_up = 0, negotiate = 0;
2502         uint32_t speed = 0;
2503         int mask = 0;
2504         int status;
2505         uint16_t vf, idx;
2506         uint32_t *link_speeds;
2507
2508         PMD_INIT_FUNC_TRACE();
2509
2510         /* IXGBE devices don't support:
2511         *    - half duplex (checked afterwards for valid speeds)
2512         *    - fixed speed: TODO implement
2513         */
2514         if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED) {
2515                 PMD_INIT_LOG(ERR, "Invalid link_speeds for port %hhu; fix speed not supported",
2516                              dev->data->port_id);
2517                 return -EINVAL;
2518         }
2519
2520         /* disable uio/vfio intr/eventfd mapping */
2521         rte_intr_disable(intr_handle);
2522
2523         /* stop adapter */
2524         hw->adapter_stopped = 0;
2525         ixgbe_stop_adapter(hw);
2526
2527         /* reinitialize adapter
2528          * this calls reset and start
2529          */
2530         status = ixgbe_pf_reset_hw(hw);
2531         if (status != 0)
2532                 return -1;
2533         hw->mac.ops.start_hw(hw);
2534         hw->mac.get_link_status = true;
2535
2536         /* configure PF module if SRIOV enabled */
2537         ixgbe_pf_host_configure(dev);
2538
2539         ixgbe_dev_phy_intr_setup(dev);
2540
2541         /* check and configure queue intr-vector mapping */
2542         if ((rte_intr_cap_multiple(intr_handle) ||
2543              !RTE_ETH_DEV_SRIOV(dev).active) &&
2544             dev->data->dev_conf.intr_conf.rxq != 0) {
2545                 intr_vector = dev->data->nb_rx_queues;
2546                 if (intr_vector > IXGBE_MAX_INTR_QUEUE_NUM) {
2547                         PMD_INIT_LOG(ERR, "At most %d intr queues supported",
2548                                         IXGBE_MAX_INTR_QUEUE_NUM);
2549                         return -ENOTSUP;
2550                 }
2551                 if (rte_intr_efd_enable(intr_handle, intr_vector))
2552                         return -1;
2553         }
2554
2555         if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
2556                 intr_handle->intr_vec =
2557                         rte_zmalloc("intr_vec",
2558                                     dev->data->nb_rx_queues * sizeof(int), 0);
2559                 if (intr_handle->intr_vec == NULL) {
2560                         PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
2561                                      " intr_vec", dev->data->nb_rx_queues);
2562                         return -ENOMEM;
2563                 }
2564         }
2565
2566         /* confiugre msix for sleep until rx interrupt */
2567         ixgbe_configure_msix(dev);
2568
2569         /* initialize transmission unit */
2570         ixgbe_dev_tx_init(dev);
2571
2572         /* This can fail when allocating mbufs for descriptor rings */
2573         err = ixgbe_dev_rx_init(dev);
2574         if (err) {
2575                 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
2576                 goto error;
2577         }
2578
2579     mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK |
2580                 ETH_VLAN_EXTEND_MASK;
2581         ixgbe_vlan_offload_set(dev, mask);
2582
2583         if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
2584                 /* Enable vlan filtering for VMDq */
2585                 ixgbe_vmdq_vlan_hw_filter_enable(dev);
2586         }
2587
2588         /* Configure DCB hw */
2589         ixgbe_configure_dcb(dev);
2590
2591         if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_NONE) {
2592                 err = ixgbe_fdir_configure(dev);
2593                 if (err)
2594                         goto error;
2595         }
2596
2597         /* Restore vf rate limit */
2598         if (vfinfo != NULL) {
2599                 for (vf = 0; vf < pci_dev->max_vfs; vf++)
2600                         for (idx = 0; idx < IXGBE_MAX_QUEUE_NUM_PER_VF; idx++)
2601                                 if (vfinfo[vf].tx_rate[idx] != 0)
2602                                         ixgbe_set_vf_rate_limit(
2603                                                 dev, vf,
2604                                                 vfinfo[vf].tx_rate[idx],
2605                                                 1 << idx);
2606         }
2607
2608         ixgbe_restore_statistics_mapping(dev);
2609
2610         err = ixgbe_dev_rxtx_start(dev);
2611         if (err < 0) {
2612                 PMD_INIT_LOG(ERR, "Unable to start rxtx queues");
2613                 goto error;
2614         }
2615
2616         /* Skip link setup if loopback mode is enabled for 82599. */
2617         if (hw->mac.type == ixgbe_mac_82599EB &&
2618                         dev->data->dev_conf.lpbk_mode == IXGBE_LPBK_82599_TX_RX)
2619                 goto skip_link_setup;
2620
2621         if (ixgbe_is_sfp(hw) && hw->phy.multispeed_fiber) {
2622                 err = hw->mac.ops.setup_sfp(hw);
2623                 if (err)
2624                         goto error;
2625         }
2626
2627         if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
2628                 /* Turn on the copper */
2629                 ixgbe_set_phy_power(hw, true);
2630         } else {
2631                 /* Turn on the laser */
2632                 ixgbe_enable_tx_laser(hw);
2633         }
2634
2635         err = ixgbe_check_link(hw, &speed, &link_up, 0);
2636         if (err)
2637                 goto error;
2638         dev->data->dev_link.link_status = link_up;
2639
2640         err = ixgbe_get_link_capabilities(hw, &speed, &negotiate);
2641         if (err)
2642                 goto error;
2643
2644         link_speeds = &dev->data->dev_conf.link_speeds;
2645         if (*link_speeds & ~(ETH_LINK_SPEED_100M | ETH_LINK_SPEED_1G |
2646                         ETH_LINK_SPEED_10G)) {
2647                 PMD_INIT_LOG(ERR, "Invalid link setting");
2648                 goto error;
2649         }
2650
2651         speed = 0x0;
2652         if (*link_speeds == ETH_LINK_SPEED_AUTONEG) {
2653                 speed = (hw->mac.type != ixgbe_mac_82598EB) ?
2654                                 IXGBE_LINK_SPEED_82599_AUTONEG :
2655                                 IXGBE_LINK_SPEED_82598_AUTONEG;
2656         } else {
2657                 if (*link_speeds & ETH_LINK_SPEED_10G)
2658                         speed |= IXGBE_LINK_SPEED_10GB_FULL;
2659                 if (*link_speeds & ETH_LINK_SPEED_1G)
2660                         speed |= IXGBE_LINK_SPEED_1GB_FULL;
2661                 if (*link_speeds & ETH_LINK_SPEED_100M)
2662                         speed |= IXGBE_LINK_SPEED_100_FULL;
2663         }
2664
2665         err = ixgbe_setup_link(hw, speed, link_up);
2666         if (err)
2667                 goto error;
2668
2669 skip_link_setup:
2670
2671         if (rte_intr_allow_others(intr_handle)) {
2672                 /* check if lsc interrupt is enabled */
2673                 if (dev->data->dev_conf.intr_conf.lsc != 0)
2674                         ixgbe_dev_lsc_interrupt_setup(dev);
2675                 ixgbe_dev_macsec_interrupt_setup(dev);
2676         } else {
2677                 rte_intr_callback_unregister(intr_handle,
2678                                              ixgbe_dev_interrupt_handler, dev);
2679                 if (dev->data->dev_conf.intr_conf.lsc != 0)
2680                         PMD_INIT_LOG(INFO, "lsc won't enable because of"
2681                                      " no intr multiplex");
2682         }
2683
2684         /* check if rxq interrupt is enabled */
2685         if (dev->data->dev_conf.intr_conf.rxq != 0 &&
2686             rte_intr_dp_is_en(intr_handle))
2687                 ixgbe_dev_rxq_interrupt_setup(dev);
2688
2689         /* enable uio/vfio intr/eventfd mapping */
2690         rte_intr_enable(intr_handle);
2691
2692         /* resume enabled intr since hw reset */
2693         ixgbe_enable_intr(dev);
2694         ixgbe_l2_tunnel_conf(dev);
2695         ixgbe_filter_restore(dev);
2696
2697         return 0;
2698
2699 error:
2700         PMD_INIT_LOG(ERR, "failure in ixgbe_dev_start(): %d", err);
2701         ixgbe_dev_clear_queues(dev);
2702         return -EIO;
2703 }
2704
2705 /*
2706  * Stop device: disable rx and tx functions to allow for reconfiguring.
2707  */
2708 static void
2709 ixgbe_dev_stop(struct rte_eth_dev *dev)
2710 {
2711         struct rte_eth_link link;
2712         struct ixgbe_hw *hw =
2713                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2714         struct ixgbe_vf_info *vfinfo =
2715                 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
2716         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
2717         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2718         int vf;
2719
2720         PMD_INIT_FUNC_TRACE();
2721
2722         /* disable interrupts */
2723         ixgbe_disable_intr(hw);
2724
2725         /* reset the NIC */
2726         ixgbe_pf_reset_hw(hw);
2727         hw->adapter_stopped = 0;
2728
2729         /* stop adapter */
2730         ixgbe_stop_adapter(hw);
2731
2732         for (vf = 0; vfinfo != NULL && vf < pci_dev->max_vfs; vf++)
2733                 vfinfo[vf].clear_to_send = false;
2734
2735         if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
2736                 /* Turn off the copper */
2737                 ixgbe_set_phy_power(hw, false);
2738         } else {
2739                 /* Turn off the laser */
2740                 ixgbe_disable_tx_laser(hw);
2741         }
2742
2743         ixgbe_dev_clear_queues(dev);
2744
2745         /* Clear stored conf */
2746         dev->data->scattered_rx = 0;
2747         dev->data->lro = 0;
2748
2749         /* Clear recorded link status */
2750         memset(&link, 0, sizeof(link));
2751         rte_ixgbe_dev_atomic_write_link_status(dev, &link);
2752
2753         if (!rte_intr_allow_others(intr_handle))
2754                 /* resume to the default handler */
2755                 rte_intr_callback_register(intr_handle,
2756                                            ixgbe_dev_interrupt_handler,
2757                                            (void *)dev);
2758
2759         /* Clean datapath event and queue/vec mapping */
2760         rte_intr_efd_disable(intr_handle);
2761         if (intr_handle->intr_vec != NULL) {
2762                 rte_free(intr_handle->intr_vec);
2763                 intr_handle->intr_vec = NULL;
2764         }
2765 }
2766
2767 /*
2768  * Set device link up: enable tx.
2769  */
2770 static int
2771 ixgbe_dev_set_link_up(struct rte_eth_dev *dev)
2772 {
2773         struct ixgbe_hw *hw =
2774                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2775         if (hw->mac.type == ixgbe_mac_82599EB) {
2776 #ifdef RTE_NIC_BYPASS
2777                 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
2778                         /* Not suported in bypass mode */
2779                         PMD_INIT_LOG(ERR, "Set link up is not supported "
2780                                      "by device id 0x%x", hw->device_id);
2781                         return -ENOTSUP;
2782                 }
2783 #endif
2784         }
2785
2786         if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
2787                 /* Turn on the copper */
2788                 ixgbe_set_phy_power(hw, true);
2789         } else {
2790                 /* Turn on the laser */
2791                 ixgbe_enable_tx_laser(hw);
2792         }
2793
2794         return 0;
2795 }
2796
2797 /*
2798  * Set device link down: disable tx.
2799  */
2800 static int
2801 ixgbe_dev_set_link_down(struct rte_eth_dev *dev)
2802 {
2803         struct ixgbe_hw *hw =
2804                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2805         if (hw->mac.type == ixgbe_mac_82599EB) {
2806 #ifdef RTE_NIC_BYPASS
2807                 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
2808                         /* Not suported in bypass mode */
2809                         PMD_INIT_LOG(ERR, "Set link down is not supported "
2810                                      "by device id 0x%x", hw->device_id);
2811                         return -ENOTSUP;
2812                 }
2813 #endif
2814         }
2815
2816         if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
2817                 /* Turn off the copper */
2818                 ixgbe_set_phy_power(hw, false);
2819         } else {
2820                 /* Turn off the laser */
2821                 ixgbe_disable_tx_laser(hw);
2822         }
2823
2824         return 0;
2825 }
2826
2827 /*
2828  * Reest and stop device.
2829  */
2830 static void
2831 ixgbe_dev_close(struct rte_eth_dev *dev)
2832 {
2833         struct ixgbe_hw *hw =
2834                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2835
2836         PMD_INIT_FUNC_TRACE();
2837
2838         ixgbe_pf_reset_hw(hw);
2839
2840         ixgbe_dev_stop(dev);
2841         hw->adapter_stopped = 1;
2842
2843         ixgbe_dev_free_queues(dev);
2844
2845         ixgbe_disable_pcie_master(hw);
2846
2847         /* reprogram the RAR[0] in case user changed it. */
2848         ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
2849 }
2850
2851 static void
2852 ixgbe_read_stats_registers(struct ixgbe_hw *hw,
2853                            struct ixgbe_hw_stats *hw_stats,
2854                            struct ixgbe_macsec_stats *macsec_stats,
2855                            uint64_t *total_missed_rx, uint64_t *total_qbrc,
2856                            uint64_t *total_qprc, uint64_t *total_qprdc)
2857 {
2858         uint32_t bprc, lxon, lxoff, total;
2859         uint32_t delta_gprc = 0;
2860         unsigned i;
2861         /* Workaround for RX byte count not including CRC bytes when CRC
2862          * strip is enabled. CRC bytes are removed from counters when crc_strip
2863          * is disabled.
2864          */
2865         int crc_strip = (IXGBE_READ_REG(hw, IXGBE_HLREG0) &
2866                         IXGBE_HLREG0_RXCRCSTRP);
2867
2868         hw_stats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
2869         hw_stats->illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC);
2870         hw_stats->errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC);
2871         hw_stats->mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC);
2872
2873         for (i = 0; i < 8; i++) {
2874                 uint32_t mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
2875
2876                 /* global total per queue */
2877                 hw_stats->mpc[i] += mp;
2878                 /* Running comprehensive total for stats display */
2879                 *total_missed_rx += hw_stats->mpc[i];
2880                 if (hw->mac.type == ixgbe_mac_82598EB) {
2881                         hw_stats->rnbc[i] +=
2882                             IXGBE_READ_REG(hw, IXGBE_RNBC(i));
2883                         hw_stats->pxonrxc[i] +=
2884                                 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
2885                         hw_stats->pxoffrxc[i] +=
2886                                 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
2887                 } else {
2888                         hw_stats->pxonrxc[i] +=
2889                                 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
2890                         hw_stats->pxoffrxc[i] +=
2891                                 IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
2892                         hw_stats->pxon2offc[i] +=
2893                                 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
2894                 }
2895                 hw_stats->pxontxc[i] +=
2896                     IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
2897                 hw_stats->pxofftxc[i] +=
2898                     IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
2899         }
2900         for (i = 0; i < IXGBE_QUEUE_STAT_COUNTERS; i++) {
2901                 uint32_t delta_qprc = IXGBE_READ_REG(hw, IXGBE_QPRC(i));
2902                 uint32_t delta_qptc = IXGBE_READ_REG(hw, IXGBE_QPTC(i));
2903                 uint32_t delta_qprdc = IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
2904
2905                 delta_gprc += delta_qprc;
2906
2907                 hw_stats->qprc[i] += delta_qprc;
2908                 hw_stats->qptc[i] += delta_qptc;
2909
2910                 hw_stats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
2911                 hw_stats->qbrc[i] +=
2912                     ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)) << 32);
2913                 if (crc_strip == 0)
2914                         hw_stats->qbrc[i] -= delta_qprc * ETHER_CRC_LEN;
2915
2916                 hw_stats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
2917                 hw_stats->qbtc[i] +=
2918                     ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)) << 32);
2919
2920                 hw_stats->qprdc[i] += delta_qprdc;
2921                 *total_qprdc += hw_stats->qprdc[i];
2922
2923                 *total_qprc += hw_stats->qprc[i];
2924                 *total_qbrc += hw_stats->qbrc[i];
2925         }
2926         hw_stats->mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC);
2927         hw_stats->mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC);
2928         hw_stats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
2929
2930         /*
2931          * An errata states that gprc actually counts good + missed packets:
2932          * Workaround to set gprc to summated queue packet receives
2933          */
2934         hw_stats->gprc = *total_qprc;
2935
2936         if (hw->mac.type != ixgbe_mac_82598EB) {
2937                 hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
2938                 hw_stats->gorc += ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32);
2939                 hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
2940                 hw_stats->gotc += ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32);
2941                 hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
2942                 hw_stats->tor += ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32);
2943                 hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
2944                 hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
2945         } else {
2946                 hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
2947                 hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
2948                 /* 82598 only has a counter in the high register */
2949                 hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
2950                 hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
2951                 hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
2952         }
2953         uint64_t old_tpr = hw_stats->tpr;
2954
2955         hw_stats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
2956         hw_stats->tpt += IXGBE_READ_REG(hw, IXGBE_TPT);
2957
2958         if (crc_strip == 0)
2959                 hw_stats->gorc -= delta_gprc * ETHER_CRC_LEN;
2960
2961         uint64_t delta_gptc = IXGBE_READ_REG(hw, IXGBE_GPTC);
2962         hw_stats->gptc += delta_gptc;
2963         hw_stats->gotc -= delta_gptc * ETHER_CRC_LEN;
2964         hw_stats->tor -= (hw_stats->tpr - old_tpr) * ETHER_CRC_LEN;
2965
2966         /*
2967          * Workaround: mprc hardware is incorrectly counting
2968          * broadcasts, so for now we subtract those.
2969          */
2970         bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
2971         hw_stats->bprc += bprc;
2972         hw_stats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
2973         if (hw->mac.type == ixgbe_mac_82598EB)
2974                 hw_stats->mprc -= bprc;
2975
2976         hw_stats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
2977         hw_stats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
2978         hw_stats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
2979         hw_stats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
2980         hw_stats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
2981         hw_stats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
2982
2983         lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
2984         hw_stats->lxontxc += lxon;
2985         lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
2986         hw_stats->lxofftxc += lxoff;
2987         total = lxon + lxoff;
2988
2989         hw_stats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
2990         hw_stats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
2991         hw_stats->gptc -= total;
2992         hw_stats->mptc -= total;
2993         hw_stats->ptc64 -= total;
2994         hw_stats->gotc -= total * ETHER_MIN_LEN;
2995
2996         hw_stats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
2997         hw_stats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
2998         hw_stats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
2999         hw_stats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
3000         hw_stats->mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC);
3001         hw_stats->mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC);
3002         hw_stats->mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC);
3003         hw_stats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3004         hw_stats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3005         hw_stats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3006         hw_stats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3007         hw_stats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
3008         hw_stats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3009         hw_stats->xec += IXGBE_READ_REG(hw, IXGBE_XEC);
3010         hw_stats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
3011         hw_stats->fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
3012         /* Only read FCOE on 82599 */
3013         if (hw->mac.type != ixgbe_mac_82598EB) {
3014                 hw_stats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
3015                 hw_stats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
3016                 hw_stats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
3017                 hw_stats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
3018                 hw_stats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
3019         }
3020
3021         /* Flow Director Stats registers */
3022         hw_stats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
3023         hw_stats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
3024
3025         /* MACsec Stats registers */
3026         macsec_stats->out_pkts_untagged += IXGBE_READ_REG(hw, IXGBE_LSECTXUT);
3027         macsec_stats->out_pkts_encrypted +=
3028                 IXGBE_READ_REG(hw, IXGBE_LSECTXPKTE);
3029         macsec_stats->out_pkts_protected +=
3030                 IXGBE_READ_REG(hw, IXGBE_LSECTXPKTP);
3031         macsec_stats->out_octets_encrypted +=
3032                 IXGBE_READ_REG(hw, IXGBE_LSECTXOCTE);
3033         macsec_stats->out_octets_protected +=
3034                 IXGBE_READ_REG(hw, IXGBE_LSECTXOCTP);
3035         macsec_stats->in_pkts_untagged += IXGBE_READ_REG(hw, IXGBE_LSECRXUT);
3036         macsec_stats->in_pkts_badtag += IXGBE_READ_REG(hw, IXGBE_LSECRXBAD);
3037         macsec_stats->in_pkts_nosci += IXGBE_READ_REG(hw, IXGBE_LSECRXNOSCI);
3038         macsec_stats->in_pkts_unknownsci +=
3039                 IXGBE_READ_REG(hw, IXGBE_LSECRXUNSCI);
3040         macsec_stats->in_octets_decrypted +=
3041                 IXGBE_READ_REG(hw, IXGBE_LSECRXOCTD);
3042         macsec_stats->in_octets_validated +=
3043                 IXGBE_READ_REG(hw, IXGBE_LSECRXOCTV);
3044         macsec_stats->in_pkts_unchecked += IXGBE_READ_REG(hw, IXGBE_LSECRXUNCH);
3045         macsec_stats->in_pkts_delayed += IXGBE_READ_REG(hw, IXGBE_LSECRXDELAY);
3046         macsec_stats->in_pkts_late += IXGBE_READ_REG(hw, IXGBE_LSECRXLATE);
3047         for (i = 0; i < 2; i++) {
3048                 macsec_stats->in_pkts_ok +=
3049                         IXGBE_READ_REG(hw, IXGBE_LSECRXOK(i));
3050                 macsec_stats->in_pkts_invalid +=
3051                         IXGBE_READ_REG(hw, IXGBE_LSECRXINV(i));
3052                 macsec_stats->in_pkts_notvalid +=
3053                         IXGBE_READ_REG(hw, IXGBE_LSECRXNV(i));
3054         }
3055         macsec_stats->in_pkts_unusedsa += IXGBE_READ_REG(hw, IXGBE_LSECRXUNSA);
3056         macsec_stats->in_pkts_notusingsa +=
3057                 IXGBE_READ_REG(hw, IXGBE_LSECRXNUSA);
3058 }
3059
3060 /*
3061  * This function is based on ixgbe_update_stats_counters() in ixgbe/ixgbe.c
3062  */
3063 static void
3064 ixgbe_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
3065 {
3066         struct ixgbe_hw *hw =
3067                         IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3068         struct ixgbe_hw_stats *hw_stats =
3069                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3070         struct ixgbe_macsec_stats *macsec_stats =
3071                         IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
3072                                 dev->data->dev_private);
3073         uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
3074         unsigned i;
3075
3076         total_missed_rx = 0;
3077         total_qbrc = 0;
3078         total_qprc = 0;
3079         total_qprdc = 0;
3080
3081         ixgbe_read_stats_registers(hw, hw_stats, macsec_stats, &total_missed_rx,
3082                         &total_qbrc, &total_qprc, &total_qprdc);
3083
3084         if (stats == NULL)
3085                 return;
3086
3087         /* Fill out the rte_eth_stats statistics structure */
3088         stats->ipackets = total_qprc;
3089         stats->ibytes = total_qbrc;
3090         stats->opackets = hw_stats->gptc;
3091         stats->obytes = hw_stats->gotc;
3092
3093         for (i = 0; i < IXGBE_QUEUE_STAT_COUNTERS; i++) {
3094                 stats->q_ipackets[i] = hw_stats->qprc[i];
3095                 stats->q_opackets[i] = hw_stats->qptc[i];
3096                 stats->q_ibytes[i] = hw_stats->qbrc[i];
3097                 stats->q_obytes[i] = hw_stats->qbtc[i];
3098                 stats->q_errors[i] = hw_stats->qprdc[i];
3099         }
3100
3101         /* Rx Errors */
3102         stats->imissed  = total_missed_rx;
3103         stats->ierrors  = hw_stats->crcerrs +
3104                           hw_stats->mspdc +
3105                           hw_stats->rlec +
3106                           hw_stats->ruc +
3107                           hw_stats->roc +
3108                           hw_stats->illerrc +
3109                           hw_stats->errbc +
3110                           hw_stats->rfc +
3111                           hw_stats->fccrc +
3112                           hw_stats->fclast;
3113
3114         /* Tx Errors */
3115         stats->oerrors  = 0;
3116 }
3117
3118 static void
3119 ixgbe_dev_stats_reset(struct rte_eth_dev *dev)
3120 {
3121         struct ixgbe_hw_stats *stats =
3122                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3123
3124         /* HW registers are cleared on read */
3125         ixgbe_dev_stats_get(dev, NULL);
3126
3127         /* Reset software totals */
3128         memset(stats, 0, sizeof(*stats));
3129 }
3130
3131 /* This function calculates the number of xstats based on the current config */
3132 static unsigned
3133 ixgbe_xstats_calc_num(void) {
3134         return IXGBE_NB_HW_STATS + IXGBE_NB_MACSEC_STATS +
3135                 (IXGBE_NB_RXQ_PRIO_STATS * IXGBE_NB_RXQ_PRIO_VALUES) +
3136                 (IXGBE_NB_TXQ_PRIO_STATS * IXGBE_NB_TXQ_PRIO_VALUES);
3137 }
3138
3139 static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3140         struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit)
3141 {
3142         const unsigned cnt_stats = ixgbe_xstats_calc_num();
3143         unsigned stat, i, count;
3144
3145         if (xstats_names != NULL) {
3146                 count = 0;
3147
3148                 /* Note: limit >= cnt_stats checked upstream
3149                  * in rte_eth_xstats_names()
3150                  */
3151
3152                 /* Extended stats from ixgbe_hw_stats */
3153                 for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
3154                         snprintf(xstats_names[count].name,
3155                                 sizeof(xstats_names[count].name),
3156                                 "%s",
3157                                 rte_ixgbe_stats_strings[i].name);
3158                         count++;
3159                 }
3160
3161                 /* MACsec Stats */
3162                 for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
3163                         snprintf(xstats_names[count].name,
3164                                 sizeof(xstats_names[count].name),
3165                                 "%s",
3166                                 rte_ixgbe_macsec_strings[i].name);
3167                         count++;
3168                 }
3169
3170                 /* RX Priority Stats */
3171                 for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
3172                         for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
3173                                 snprintf(xstats_names[count].name,
3174                                         sizeof(xstats_names[count].name),
3175                                         "rx_priority%u_%s", i,
3176                                         rte_ixgbe_rxq_strings[stat].name);
3177                                 count++;
3178                         }
3179                 }
3180
3181                 /* TX Priority Stats */
3182                 for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
3183                         for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
3184                                 snprintf(xstats_names[count].name,
3185                                         sizeof(xstats_names[count].name),
3186                                         "tx_priority%u_%s", i,
3187                                         rte_ixgbe_txq_strings[stat].name);
3188                                 count++;
3189                         }
3190                 }
3191         }
3192         return cnt_stats;
3193 }
3194
3195 static int ixgbe_dev_xstats_get_names_by_ids(
3196         __rte_unused struct rte_eth_dev *dev,
3197         struct rte_eth_xstat_name *xstats_names,
3198         uint64_t *ids,
3199         unsigned int limit)
3200 {
3201         if (!ids) {
3202                 const unsigned int cnt_stats = ixgbe_xstats_calc_num();
3203                 unsigned int stat, i, count;
3204
3205                 if (xstats_names != NULL) {
3206                         count = 0;
3207
3208                         /* Note: limit >= cnt_stats checked upstream
3209                          * in rte_eth_xstats_names()
3210                          */
3211
3212                         /* Extended stats from ixgbe_hw_stats */
3213                         for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
3214                                 snprintf(xstats_names[count].name,
3215                                         sizeof(xstats_names[count].name),
3216                                         "%s",
3217                                         rte_ixgbe_stats_strings[i].name);
3218                                 count++;
3219                         }
3220
3221                         /* MACsec Stats */
3222                         for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
3223                                 snprintf(xstats_names[count].name,
3224                                         sizeof(xstats_names[count].name),
3225                                         "%s",
3226                                         rte_ixgbe_macsec_strings[i].name);
3227                                 count++;
3228                         }
3229
3230                         /* RX Priority Stats */
3231                         for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
3232                                 for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
3233                                         snprintf(xstats_names[count].name,
3234                                             sizeof(xstats_names[count].name),
3235                                             "rx_priority%u_%s", i,
3236                                             rte_ixgbe_rxq_strings[stat].name);
3237                                         count++;
3238                                 }
3239                         }
3240
3241                         /* TX Priority Stats */
3242                         for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
3243                                 for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
3244                                         snprintf(xstats_names[count].name,
3245                                             sizeof(xstats_names[count].name),
3246                                             "tx_priority%u_%s", i,
3247                                             rte_ixgbe_txq_strings[stat].name);
3248                                         count++;
3249                                 }
3250                         }
3251                 }
3252                 return cnt_stats;
3253         }
3254
3255         uint16_t i;
3256         uint16_t size = ixgbe_xstats_calc_num();
3257         struct rte_eth_xstat_name xstats_names_copy[size];
3258
3259         ixgbe_dev_xstats_get_names_by_ids(dev, xstats_names_copy, NULL,
3260                         size);
3261
3262         for (i = 0; i < limit; i++) {
3263                 if (ids[i] >= size) {
3264                         PMD_INIT_LOG(ERR, "id value isn't valid");
3265                         return -1;
3266                 }
3267                 strcpy(xstats_names[i].name,
3268                                 xstats_names_copy[ids[i]].name);
3269         }
3270         return limit;
3271 }
3272
3273 static int ixgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3274         struct rte_eth_xstat_name *xstats_names, unsigned limit)
3275 {
3276         unsigned i;
3277
3278         if (limit < IXGBEVF_NB_XSTATS && xstats_names != NULL)
3279                 return -ENOMEM;
3280
3281         if (xstats_names != NULL)
3282                 for (i = 0; i < IXGBEVF_NB_XSTATS; i++)
3283                         snprintf(xstats_names[i].name,
3284                                 sizeof(xstats_names[i].name),
3285                                 "%s", rte_ixgbevf_stats_strings[i].name);
3286         return IXGBEVF_NB_XSTATS;
3287 }
3288
3289 static int
3290 ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3291                                          unsigned n)
3292 {
3293         struct ixgbe_hw *hw =
3294                         IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3295         struct ixgbe_hw_stats *hw_stats =
3296                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3297         struct ixgbe_macsec_stats *macsec_stats =
3298                         IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
3299                                 dev->data->dev_private);
3300         uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
3301         unsigned i, stat, count = 0;
3302
3303         count = ixgbe_xstats_calc_num();
3304
3305         if (n < count)
3306                 return count;
3307
3308         total_missed_rx = 0;
3309         total_qbrc = 0;
3310         total_qprc = 0;
3311         total_qprdc = 0;
3312
3313         ixgbe_read_stats_registers(hw, hw_stats, macsec_stats, &total_missed_rx,
3314                         &total_qbrc, &total_qprc, &total_qprdc);
3315
3316         /* If this is a reset xstats is NULL, and we have cleared the
3317          * registers by reading them.
3318          */
3319         if (!xstats)
3320                 return 0;
3321
3322         /* Extended stats from ixgbe_hw_stats */
3323         count = 0;
3324         for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
3325                 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3326                                 rte_ixgbe_stats_strings[i].offset);
3327                 xstats[count].id = count;
3328                 count++;
3329         }
3330
3331         /* MACsec Stats */
3332         for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
3333                 xstats[count].value = *(uint64_t *)(((char *)macsec_stats) +
3334                                 rte_ixgbe_macsec_strings[i].offset);
3335                 xstats[count].id = count;
3336                 count++;
3337         }
3338
3339         /* RX Priority Stats */
3340         for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
3341                 for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
3342                         xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3343                                         rte_ixgbe_rxq_strings[stat].offset +
3344                                         (sizeof(uint64_t) * i));
3345                         xstats[count].id = count;
3346                         count++;
3347                 }
3348         }
3349
3350         /* TX Priority Stats */
3351         for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
3352                 for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
3353                         xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3354                                         rte_ixgbe_txq_strings[stat].offset +
3355                                         (sizeof(uint64_t) * i));
3356                         xstats[count].id = count;
3357                         count++;
3358                 }
3359         }
3360         return count;
3361 }
3362
3363 static int
3364 ixgbe_dev_xstats_get_by_ids(struct rte_eth_dev *dev, uint64_t *ids,
3365                 uint64_t *values, unsigned int n)
3366 {
3367         if (!ids) {
3368                 struct ixgbe_hw *hw =
3369                                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3370                 struct ixgbe_hw_stats *hw_stats =
3371                                 IXGBE_DEV_PRIVATE_TO_STATS(
3372                                                 dev->data->dev_private);
3373                 struct ixgbe_macsec_stats *macsec_stats =
3374                                 IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
3375                                         dev->data->dev_private);
3376                 uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
3377                 unsigned int i, stat, count = 0;
3378
3379                 count = ixgbe_xstats_calc_num();
3380
3381                 if (!ids && n < count)
3382                         return count;
3383
3384                 total_missed_rx = 0;
3385                 total_qbrc = 0;
3386                 total_qprc = 0;
3387                 total_qprdc = 0;
3388
3389                 ixgbe_read_stats_registers(hw, hw_stats, macsec_stats,
3390                                 &total_missed_rx, &total_qbrc, &total_qprc,
3391                                 &total_qprdc);
3392
3393                 /* If this is a reset xstats is NULL, and we have cleared the
3394                  * registers by reading them.
3395                  */
3396                 if (!ids && !values)
3397                         return 0;
3398
3399                 /* Extended stats from ixgbe_hw_stats */
3400                 count = 0;
3401                 for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
3402                         values[count] = *(uint64_t *)(((char *)hw_stats) +
3403                                         rte_ixgbe_stats_strings[i].offset);
3404                         count++;
3405                 }
3406
3407                 /* MACsec Stats */
3408                 for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
3409                         values[count] = *(uint64_t *)(((char *)macsec_stats) +
3410                                         rte_ixgbe_macsec_strings[i].offset);
3411                         count++;
3412                 }
3413
3414                 /* RX Priority Stats */
3415                 for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
3416                         for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
3417                                 values[count] =
3418                                         *(uint64_t *)(((char *)hw_stats) +
3419                                         rte_ixgbe_rxq_strings[stat].offset +
3420                                         (sizeof(uint64_t) * i));
3421                                 count++;
3422                         }
3423                 }
3424
3425                 /* TX Priority Stats */
3426                 for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
3427                         for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
3428                                 values[count] =
3429                                         *(uint64_t *)(((char *)hw_stats) +
3430                                         rte_ixgbe_txq_strings[stat].offset +
3431                                         (sizeof(uint64_t) * i));
3432                                 count++;
3433                         }
3434                 }
3435                 return count;
3436         }
3437
3438         uint16_t i;
3439         uint16_t size = ixgbe_xstats_calc_num();
3440         uint64_t values_copy[size];
3441
3442         ixgbe_dev_xstats_get_by_ids(dev, NULL, values_copy, size);
3443
3444         for (i = 0; i < n; i++) {
3445                 if (ids[i] >= size) {
3446                         PMD_INIT_LOG(ERR, "id value isn't valid");
3447                         return -1;
3448                 }
3449                 values[i] = values_copy[ids[i]];
3450         }
3451         return n;
3452 }
3453
3454 static void
3455 ixgbe_dev_xstats_reset(struct rte_eth_dev *dev)
3456 {
3457         struct ixgbe_hw_stats *stats =
3458                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3459         struct ixgbe_macsec_stats *macsec_stats =
3460                         IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
3461                                 dev->data->dev_private);
3462
3463         unsigned count = ixgbe_xstats_calc_num();
3464
3465         /* HW registers are cleared on read */
3466         ixgbe_dev_xstats_get(dev, NULL, count);
3467
3468         /* Reset software totals */
3469         memset(stats, 0, sizeof(*stats));
3470         memset(macsec_stats, 0, sizeof(*macsec_stats));
3471 }
3472
3473 static void
3474 ixgbevf_update_stats(struct rte_eth_dev *dev)
3475 {
3476         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3477         struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
3478                           IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3479
3480         /* Good Rx packet, include VF loopback */
3481         UPDATE_VF_STAT(IXGBE_VFGPRC,
3482             hw_stats->last_vfgprc, hw_stats->vfgprc);
3483
3484         /* Good Rx octets, include VF loopback */
3485         UPDATE_VF_STAT_36BIT(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
3486             hw_stats->last_vfgorc, hw_stats->vfgorc);
3487
3488         /* Good Tx packet, include VF loopback */
3489         UPDATE_VF_STAT(IXGBE_VFGPTC,
3490             hw_stats->last_vfgptc, hw_stats->vfgptc);
3491
3492         /* Good Tx octets, include VF loopback */
3493         UPDATE_VF_STAT_36BIT(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
3494             hw_stats->last_vfgotc, hw_stats->vfgotc);
3495
3496         /* Rx Multicst Packet */
3497         UPDATE_VF_STAT(IXGBE_VFMPRC,
3498             hw_stats->last_vfmprc, hw_stats->vfmprc);
3499 }
3500
3501 static int
3502 ixgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3503                        unsigned n)
3504 {
3505         struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
3506                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3507         unsigned i;
3508
3509         if (n < IXGBEVF_NB_XSTATS)
3510                 return IXGBEVF_NB_XSTATS;
3511
3512         ixgbevf_update_stats(dev);
3513
3514         if (!xstats)
3515                 return 0;
3516
3517         /* Extended stats */
3518         for (i = 0; i < IXGBEVF_NB_XSTATS; i++) {
3519                 xstats[i].id = i;
3520                 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
3521                         rte_ixgbevf_stats_strings[i].offset);
3522         }
3523
3524         return IXGBEVF_NB_XSTATS;
3525 }
3526
3527 static void
3528 ixgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
3529 {
3530         struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
3531                           IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3532
3533         ixgbevf_update_stats(dev);
3534
3535         if (stats == NULL)
3536                 return;
3537
3538         stats->ipackets = hw_stats->vfgprc;
3539         stats->ibytes = hw_stats->vfgorc;
3540         stats->opackets = hw_stats->vfgptc;
3541         stats->obytes = hw_stats->vfgotc;
3542 }
3543
3544 static void
3545 ixgbevf_dev_stats_reset(struct rte_eth_dev *dev)
3546 {
3547         struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
3548                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3549
3550         /* Sync HW register to the last stats */
3551         ixgbevf_dev_stats_get(dev, NULL);
3552
3553         /* reset HW current stats*/
3554         hw_stats->vfgprc = 0;
3555         hw_stats->vfgorc = 0;
3556         hw_stats->vfgptc = 0;
3557         hw_stats->vfgotc = 0;
3558 }
3559
3560 static int
3561 ixgbe_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3562 {
3563         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3564         u16 eeprom_verh, eeprom_verl;
3565         u32 etrack_id;
3566         int ret;
3567
3568         ixgbe_read_eeprom(hw, 0x2e, &eeprom_verh);
3569         ixgbe_read_eeprom(hw, 0x2d, &eeprom_verl);
3570
3571         etrack_id = (eeprom_verh << 16) | eeprom_verl;
3572         ret = snprintf(fw_version, fw_size, "0x%08x", etrack_id);
3573
3574         ret += 1; /* add the size of '\0' */
3575         if (fw_size < (u32)ret)
3576                 return ret;
3577         else
3578                 return 0;
3579 }
3580
3581 static void
3582 ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3583 {
3584         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
3585         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3586         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
3587
3588         dev_info->pci_dev = pci_dev;
3589         dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
3590         dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
3591         if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
3592                 /*
3593                  * When DCB/VT is off, maximum number of queues changes,
3594                  * except for 82598EB, which remains constant.
3595                  */
3596                 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_NONE &&
3597                                 hw->mac.type != ixgbe_mac_82598EB)
3598                         dev_info->max_tx_queues = IXGBE_NONE_MODE_TX_NB_QUEUES;
3599         }
3600         dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL register */
3601         dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS register */
3602         dev_info->max_mac_addrs = hw->mac.num_rar_entries;
3603         dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
3604         dev_info->max_vfs = pci_dev->max_vfs;
3605         if (hw->mac.type == ixgbe_mac_82598EB)
3606                 dev_info->max_vmdq_pools = ETH_16_POOLS;
3607         else
3608                 dev_info->max_vmdq_pools = ETH_64_POOLS;
3609         dev_info->vmdq_queue_num = dev_info->max_rx_queues;
3610         dev_info->rx_offload_capa =
3611                 DEV_RX_OFFLOAD_VLAN_STRIP |
3612                 DEV_RX_OFFLOAD_IPV4_CKSUM |
3613                 DEV_RX_OFFLOAD_UDP_CKSUM  |
3614                 DEV_RX_OFFLOAD_TCP_CKSUM;
3615
3616         /*
3617          * RSC is only supported by 82599 and x540 PF devices in a non-SR-IOV
3618          * mode.
3619          */
3620         if ((hw->mac.type == ixgbe_mac_82599EB ||
3621              hw->mac.type == ixgbe_mac_X540) &&
3622             !RTE_ETH_DEV_SRIOV(dev).active)
3623                 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TCP_LRO;
3624
3625         if (hw->mac.type == ixgbe_mac_82599EB ||
3626             hw->mac.type == ixgbe_mac_X540)
3627                 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_MACSEC_STRIP;
3628
3629         if (hw->mac.type == ixgbe_mac_X550 ||
3630             hw->mac.type == ixgbe_mac_X550EM_x ||
3631             hw->mac.type == ixgbe_mac_X550EM_a)
3632                 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
3633
3634         dev_info->tx_offload_capa =
3635                 DEV_TX_OFFLOAD_VLAN_INSERT |
3636                 DEV_TX_OFFLOAD_IPV4_CKSUM  |
3637                 DEV_TX_OFFLOAD_UDP_CKSUM   |
3638                 DEV_TX_OFFLOAD_TCP_CKSUM   |
3639                 DEV_TX_OFFLOAD_SCTP_CKSUM  |
3640                 DEV_TX_OFFLOAD_TCP_TSO;
3641
3642         if (hw->mac.type == ixgbe_mac_82599EB ||
3643             hw->mac.type == ixgbe_mac_X540)
3644                 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_MACSEC_INSERT;
3645
3646         if (hw->mac.type == ixgbe_mac_X550 ||
3647             hw->mac.type == ixgbe_mac_X550EM_x ||
3648             hw->mac.type == ixgbe_mac_X550EM_a)
3649                 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3650
3651         dev_info->default_rxconf = (struct rte_eth_rxconf) {
3652                 .rx_thresh = {
3653                         .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
3654                         .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
3655                         .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
3656                 },
3657                 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
3658                 .rx_drop_en = 0,
3659         };
3660
3661         dev_info->default_txconf = (struct rte_eth_txconf) {
3662                 .tx_thresh = {
3663                         .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
3664                         .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
3665                         .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
3666                 },
3667                 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
3668                 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
3669                 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
3670                                 ETH_TXQ_FLAGS_NOOFFLOADS,
3671         };
3672
3673         dev_info->rx_desc_lim = rx_desc_lim;
3674         dev_info->tx_desc_lim = tx_desc_lim;
3675
3676         dev_info->hash_key_size = IXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
3677         dev_info->reta_size = ixgbe_reta_size_get(hw->mac.type);
3678         dev_info->flow_type_rss_offloads = IXGBE_RSS_OFFLOAD_ALL;
3679
3680         dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
3681         if (hw->mac.type == ixgbe_mac_X540 ||
3682             hw->mac.type == ixgbe_mac_X540_vf ||
3683             hw->mac.type == ixgbe_mac_X550 ||
3684             hw->mac.type == ixgbe_mac_X550_vf) {
3685                 dev_info->speed_capa |= ETH_LINK_SPEED_100M;
3686         }
3687 }
3688
3689 static const uint32_t *
3690 ixgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev)
3691 {
3692         static const uint32_t ptypes[] = {
3693                 /* For non-vec functions,
3694                  * refers to ixgbe_rxd_pkt_info_to_pkt_type();
3695                  * for vec functions,
3696                  * refers to _recv_raw_pkts_vec().
3697                  */
3698                 RTE_PTYPE_L2_ETHER,
3699                 RTE_PTYPE_L3_IPV4,
3700                 RTE_PTYPE_L3_IPV4_EXT,
3701                 RTE_PTYPE_L3_IPV6,
3702                 RTE_PTYPE_L3_IPV6_EXT,
3703                 RTE_PTYPE_L4_SCTP,
3704                 RTE_PTYPE_L4_TCP,
3705                 RTE_PTYPE_L4_UDP,
3706                 RTE_PTYPE_TUNNEL_IP,
3707                 RTE_PTYPE_INNER_L3_IPV6,
3708                 RTE_PTYPE_INNER_L3_IPV6_EXT,
3709                 RTE_PTYPE_INNER_L4_TCP,
3710                 RTE_PTYPE_INNER_L4_UDP,
3711                 RTE_PTYPE_UNKNOWN
3712         };
3713
3714         if (dev->rx_pkt_burst == ixgbe_recv_pkts ||
3715             dev->rx_pkt_burst == ixgbe_recv_pkts_lro_single_alloc ||
3716             dev->rx_pkt_burst == ixgbe_recv_pkts_lro_bulk_alloc ||
3717             dev->rx_pkt_burst == ixgbe_recv_pkts_bulk_alloc)
3718                 return ptypes;
3719         return NULL;
3720 }
3721
3722 static void
3723 ixgbevf_dev_info_get(struct rte_eth_dev *dev,
3724                      struct rte_eth_dev_info *dev_info)
3725 {
3726         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
3727         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3728
3729         dev_info->pci_dev = pci_dev;
3730         dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
3731         dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
3732         dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL reg */
3733         dev_info->max_rx_pktlen = 9728; /* includes CRC, cf MAXFRS reg */
3734         dev_info->max_mac_addrs = hw->mac.num_rar_entries;
3735         dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
3736         dev_info->max_vfs = pci_dev->max_vfs;
3737         if (hw->mac.type == ixgbe_mac_82598EB)
3738                 dev_info->max_vmdq_pools = ETH_16_POOLS;
3739         else
3740                 dev_info->max_vmdq_pools = ETH_64_POOLS;
3741         dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
3742                                 DEV_RX_OFFLOAD_IPV4_CKSUM |
3743                                 DEV_RX_OFFLOAD_UDP_CKSUM  |
3744                                 DEV_RX_OFFLOAD_TCP_CKSUM;
3745         dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
3746                                 DEV_TX_OFFLOAD_IPV4_CKSUM  |
3747                                 DEV_TX_OFFLOAD_UDP_CKSUM   |
3748                                 DEV_TX_OFFLOAD_TCP_CKSUM   |
3749                                 DEV_TX_OFFLOAD_SCTP_CKSUM  |
3750                                 DEV_TX_OFFLOAD_TCP_TSO;
3751
3752         dev_info->default_rxconf = (struct rte_eth_rxconf) {
3753                 .rx_thresh = {
3754                         .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
3755                         .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
3756                         .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
3757                 },
3758                 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
3759                 .rx_drop_en = 0,
3760         };
3761
3762         dev_info->default_txconf = (struct rte_eth_txconf) {
3763                 .tx_thresh = {
3764                         .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
3765                         .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
3766                         .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
3767                 },
3768                 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
3769                 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
3770                 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
3771                                 ETH_TXQ_FLAGS_NOOFFLOADS,
3772         };
3773
3774         dev_info->rx_desc_lim = rx_desc_lim;
3775         dev_info->tx_desc_lim = tx_desc_lim;
3776 }
3777
3778 /* return 0 means link status changed, -1 means not changed */
3779 static int
3780 ixgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
3781 {
3782         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3783         struct rte_eth_link link, old;
3784         ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
3785         struct ixgbe_interrupt *intr =
3786                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3787         int link_up;
3788         int diag;
3789         u32 speed = 0;
3790         bool autoneg = false;
3791
3792         link.link_status = ETH_LINK_DOWN;
3793         link.link_speed = 0;
3794         link.link_duplex = ETH_LINK_HALF_DUPLEX;
3795         memset(&old, 0, sizeof(old));
3796         rte_ixgbe_dev_atomic_read_link_status(dev, &old);
3797
3798         hw->mac.get_link_status = true;
3799
3800         if ((intr->flags & IXGBE_FLAG_NEED_LINK_CONFIG) &&
3801                 hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) {
3802                 speed = hw->phy.autoneg_advertised;
3803                 if (!speed)
3804                         ixgbe_get_link_capabilities(hw, &speed, &autoneg);
3805                 ixgbe_setup_link(hw, speed, true);
3806         }
3807
3808         /* check if it needs to wait to complete, if lsc interrupt is enabled */
3809         if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
3810                 diag = ixgbe_check_link(hw, &link_speed, &link_up, 0);
3811         else
3812                 diag = ixgbe_check_link(hw, &link_speed, &link_up, 1);
3813
3814         if (diag != 0) {
3815                 link.link_speed = ETH_SPEED_NUM_100M;
3816                 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3817                 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
3818                 if (link.link_status == old.link_status)
3819                         return -1;
3820                 return 0;
3821         }
3822
3823         if (link_up == 0) {
3824                 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
3825                 intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
3826                 if (link.link_status == old.link_status)
3827                         return -1;
3828                 return 0;
3829         }
3830         intr->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3831         link.link_status = ETH_LINK_UP;
3832         link.link_duplex = ETH_LINK_FULL_DUPLEX;
3833
3834         switch (link_speed) {
3835         default:
3836         case IXGBE_LINK_SPEED_UNKNOWN:
3837                 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3838                 link.link_speed = ETH_SPEED_NUM_100M;
3839                 break;
3840
3841         case IXGBE_LINK_SPEED_100_FULL:
3842                 link.link_speed = ETH_SPEED_NUM_100M;
3843                 break;
3844
3845         case IXGBE_LINK_SPEED_1GB_FULL:
3846                 link.link_speed = ETH_SPEED_NUM_1G;
3847                 break;
3848
3849         case IXGBE_LINK_SPEED_10GB_FULL:
3850                 link.link_speed = ETH_SPEED_NUM_10G;
3851                 break;
3852         }
3853         rte_ixgbe_dev_atomic_write_link_status(dev, &link);
3854
3855         if (link.link_status == old.link_status)
3856                 return -1;
3857
3858         return 0;
3859 }
3860
3861 static void
3862 ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
3863 {
3864         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3865         uint32_t fctrl;
3866
3867         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3868         fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3869         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3870 }
3871
3872 static void
3873 ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
3874 {
3875         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3876         uint32_t fctrl;
3877
3878         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3879         fctrl &= (~IXGBE_FCTRL_UPE);
3880         if (dev->data->all_multicast == 1)
3881                 fctrl |= IXGBE_FCTRL_MPE;
3882         else
3883                 fctrl &= (~IXGBE_FCTRL_MPE);
3884         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3885 }
3886
3887 static void
3888 ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
3889 {
3890         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3891         uint32_t fctrl;
3892
3893         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3894         fctrl |= IXGBE_FCTRL_MPE;
3895         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3896 }
3897
3898 static void
3899 ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
3900 {
3901         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3902         uint32_t fctrl;
3903
3904         if (dev->data->promiscuous == 1)
3905                 return; /* must remain in all_multicast mode */
3906
3907         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3908         fctrl &= (~IXGBE_FCTRL_MPE);
3909         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3910 }
3911
3912 /**
3913  * It clears the interrupt causes and enables the interrupt.
3914  * It will be called once only during nic initialized.
3915  *
3916  * @param dev
3917  *  Pointer to struct rte_eth_dev.
3918  *
3919  * @return
3920  *  - On success, zero.
3921  *  - On failure, a negative value.
3922  */
3923 static int
3924 ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev)
3925 {
3926         struct ixgbe_interrupt *intr =
3927                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3928
3929         ixgbe_dev_link_status_print(dev);
3930         intr->mask |= IXGBE_EICR_LSC;
3931
3932         return 0;
3933 }
3934
3935 /**
3936  * It clears the interrupt causes and enables the interrupt.
3937  * It will be called once only during nic initialized.
3938  *
3939  * @param dev
3940  *  Pointer to struct rte_eth_dev.
3941  *
3942  * @return
3943  *  - On success, zero.
3944  *  - On failure, a negative value.
3945  */
3946 static int
3947 ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
3948 {
3949         struct ixgbe_interrupt *intr =
3950                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3951
3952         intr->mask |= IXGBE_EICR_RTX_QUEUE;
3953
3954         return 0;
3955 }
3956
3957 /**
3958  * It clears the interrupt causes and enables the interrupt.
3959  * It will be called once only during nic initialized.
3960  *
3961  * @param dev
3962  *  Pointer to struct rte_eth_dev.
3963  *
3964  * @return
3965  *  - On success, zero.
3966  *  - On failure, a negative value.
3967  */
3968 static int
3969 ixgbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev)
3970 {
3971         struct ixgbe_interrupt *intr =
3972                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3973
3974         intr->mask |= IXGBE_EICR_LINKSEC;
3975
3976         return 0;
3977 }
3978
3979 /*
3980  * It reads ICR and sets flag (IXGBE_EICR_LSC) for the link_update.
3981  *
3982  * @param dev
3983  *  Pointer to struct rte_eth_dev.
3984  *
3985  * @return
3986  *  - On success, zero.
3987  *  - On failure, a negative value.
3988  */
3989 static int
3990 ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
3991 {
3992         uint32_t eicr;
3993         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3994         struct ixgbe_interrupt *intr =
3995                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3996
3997         /* clear all cause mask */
3998         ixgbe_disable_intr(hw);
3999
4000         /* read-on-clear nic registers here */
4001         eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
4002         PMD_DRV_LOG(DEBUG, "eicr %x", eicr);
4003
4004         intr->flags = 0;
4005
4006         /* set flag for async link update */
4007         if (eicr & IXGBE_EICR_LSC)
4008                 intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4009
4010         if (eicr & IXGBE_EICR_MAILBOX)
4011                 intr->flags |= IXGBE_FLAG_MAILBOX;
4012
4013         if (eicr & IXGBE_EICR_LINKSEC)
4014                 intr->flags |= IXGBE_FLAG_MACSEC;
4015
4016         if (hw->mac.type ==  ixgbe_mac_X550EM_x &&
4017             hw->phy.type == ixgbe_phy_x550em_ext_t &&
4018             (eicr & IXGBE_EICR_GPI_SDP0_X550EM_x))
4019                 intr->flags |= IXGBE_FLAG_PHY_INTERRUPT;
4020
4021         return 0;
4022 }
4023
4024 /**
4025  * It gets and then prints the link status.
4026  *
4027  * @param dev
4028  *  Pointer to struct rte_eth_dev.
4029  *
4030  * @return
4031  *  - On success, zero.
4032  *  - On failure, a negative value.
4033  */
4034 static void
4035 ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
4036 {
4037         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
4038         struct rte_eth_link link;
4039
4040         memset(&link, 0, sizeof(link));
4041         rte_ixgbe_dev_atomic_read_link_status(dev, &link);
4042         if (link.link_status) {
4043                 PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
4044                                         (int)(dev->data->port_id),
4045                                         (unsigned)link.link_speed,
4046                         link.link_duplex == ETH_LINK_FULL_DUPLEX ?
4047                                         "full-duplex" : "half-duplex");
4048         } else {
4049                 PMD_INIT_LOG(INFO, " Port %d: Link Down",
4050                                 (int)(dev->data->port_id));
4051         }
4052         PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
4053                                 pci_dev->addr.domain,
4054                                 pci_dev->addr.bus,
4055                                 pci_dev->addr.devid,
4056                                 pci_dev->addr.function);
4057 }
4058
4059 /*
4060  * It executes link_update after knowing an interrupt occurred.
4061  *
4062  * @param dev
4063  *  Pointer to struct rte_eth_dev.
4064  *
4065  * @return
4066  *  - On success, zero.
4067  *  - On failure, a negative value.
4068  */
4069 static int
4070 ixgbe_dev_interrupt_action(struct rte_eth_dev *dev,
4071                            struct rte_intr_handle *intr_handle)
4072 {
4073         struct ixgbe_interrupt *intr =
4074                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4075         int64_t timeout;
4076         struct rte_eth_link link;
4077         struct ixgbe_hw *hw =
4078                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4079
4080         PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
4081
4082         if (intr->flags & IXGBE_FLAG_MAILBOX) {
4083                 ixgbe_pf_mbx_process(dev);
4084                 intr->flags &= ~IXGBE_FLAG_MAILBOX;
4085         }
4086
4087         if (intr->flags & IXGBE_FLAG_PHY_INTERRUPT) {
4088                 ixgbe_handle_lasi(hw);
4089                 intr->flags &= ~IXGBE_FLAG_PHY_INTERRUPT;
4090         }
4091
4092         if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4093                 /* get the link status before link update, for predicting later */
4094                 memset(&link, 0, sizeof(link));
4095                 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
4096
4097                 ixgbe_dev_link_update(dev, 0);
4098
4099                 /* likely to up */
4100                 if (!link.link_status)
4101                         /* handle it 1 sec later, wait it being stable */
4102                         timeout = IXGBE_LINK_UP_CHECK_TIMEOUT;
4103                 /* likely to down */
4104                 else
4105                         /* handle it 4 sec later, wait it being stable */
4106                         timeout = IXGBE_LINK_DOWN_CHECK_TIMEOUT;
4107
4108                 ixgbe_dev_link_status_print(dev);
4109                 intr->mask_original = intr->mask;
4110                 /* only disable lsc interrupt */
4111                 intr->mask &= ~IXGBE_EIMS_LSC;
4112                 if (rte_eal_alarm_set(timeout * 1000,
4113                                       ixgbe_dev_interrupt_delayed_handler, (void *)dev) < 0)
4114                         PMD_DRV_LOG(ERR, "Error setting alarm");
4115                 else
4116                         intr->mask = intr->mask_original;
4117         }
4118
4119         PMD_DRV_LOG(DEBUG, "enable intr immediately");
4120         ixgbe_enable_intr(dev);
4121         rte_intr_enable(intr_handle);
4122
4123         return 0;
4124 }
4125
4126 /**
4127  * Interrupt handler which shall be registered for alarm callback for delayed
4128  * handling specific interrupt to wait for the stable nic state. As the
4129  * NIC interrupt state is not stable for ixgbe after link is just down,
4130  * it needs to wait 4 seconds to get the stable status.
4131  *
4132  * @param handle
4133  *  Pointer to interrupt handle.
4134  * @param param
4135  *  The address of parameter (struct rte_eth_dev *) regsitered before.
4136  *
4137  * @return
4138  *  void
4139  */
4140 static void
4141 ixgbe_dev_interrupt_delayed_handler(void *param)
4142 {
4143         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
4144         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
4145         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
4146         struct ixgbe_interrupt *intr =
4147                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4148         struct ixgbe_hw *hw =
4149                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4150         uint32_t eicr;
4151
4152         ixgbe_disable_intr(hw);
4153
4154         eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
4155         if (eicr & IXGBE_EICR_MAILBOX)
4156                 ixgbe_pf_mbx_process(dev);
4157
4158         if (intr->flags & IXGBE_FLAG_PHY_INTERRUPT) {
4159                 ixgbe_handle_lasi(hw);
4160                 intr->flags &= ~IXGBE_FLAG_PHY_INTERRUPT;
4161         }
4162
4163         if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4164                 ixgbe_dev_link_update(dev, 0);
4165                 intr->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4166                 ixgbe_dev_link_status_print(dev);
4167                 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
4168         }
4169
4170         if (intr->flags & IXGBE_FLAG_MACSEC) {
4171                 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_MACSEC,
4172                                               NULL);
4173                 intr->flags &= ~IXGBE_FLAG_MACSEC;
4174         }
4175
4176         /* restore original mask */
4177         intr->mask = intr->mask_original;
4178         intr->mask_original = 0;
4179
4180         PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
4181         ixgbe_enable_intr(dev);
4182         rte_intr_enable(intr_handle);
4183 }
4184
4185 /**
4186  * Interrupt handler triggered by NIC  for handling
4187  * specific interrupt.
4188  *
4189  * @param handle
4190  *  Pointer to interrupt handle.
4191  * @param param
4192  *  The address of parameter (struct rte_eth_dev *) regsitered before.
4193  *
4194  * @return
4195  *  void
4196  */
4197 static void
4198 ixgbe_dev_interrupt_handler(void *param)
4199 {
4200         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
4201
4202         ixgbe_dev_interrupt_get_status(dev);
4203         ixgbe_dev_interrupt_action(dev, dev->intr_handle);
4204 }
4205
4206 static int
4207 ixgbe_dev_led_on(struct rte_eth_dev *dev)
4208 {
4209         struct ixgbe_hw *hw;
4210
4211         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4212         return ixgbe_led_on(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP;
4213 }
4214
4215 static int
4216 ixgbe_dev_led_off(struct rte_eth_dev *dev)
4217 {
4218         struct ixgbe_hw *hw;
4219
4220         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4221         return ixgbe_led_off(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP;
4222 }
4223
4224 static int
4225 ixgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4226 {
4227         struct ixgbe_hw *hw;
4228         uint32_t mflcn_reg;
4229         uint32_t fccfg_reg;
4230         int rx_pause;
4231         int tx_pause;
4232
4233         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4234
4235         fc_conf->pause_time = hw->fc.pause_time;
4236         fc_conf->high_water = hw->fc.high_water[0];
4237         fc_conf->low_water = hw->fc.low_water[0];
4238         fc_conf->send_xon = hw->fc.send_xon;
4239         fc_conf->autoneg = !hw->fc.disable_fc_autoneg;
4240
4241         /*
4242          * Return rx_pause status according to actual setting of
4243          * MFLCN register.
4244          */
4245         mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4246         if (mflcn_reg & (IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_RFCE))
4247                 rx_pause = 1;
4248         else
4249                 rx_pause = 0;
4250
4251         /*
4252          * Return tx_pause status according to actual setting of
4253          * FCCFG register.
4254          */
4255         fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
4256         if (fccfg_reg & (IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY))
4257                 tx_pause = 1;
4258         else
4259                 tx_pause = 0;
4260
4261         if (rx_pause && tx_pause)
4262                 fc_conf->mode = RTE_FC_FULL;
4263         else if (rx_pause)
4264                 fc_conf->mode = RTE_FC_RX_PAUSE;
4265         else if (tx_pause)
4266                 fc_conf->mode = RTE_FC_TX_PAUSE;
4267         else
4268                 fc_conf->mode = RTE_FC_NONE;
4269
4270         return 0;
4271 }
4272
4273 static int
4274 ixgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4275 {
4276         struct ixgbe_hw *hw;
4277         int err;
4278         uint32_t rx_buf_size;
4279         uint32_t max_high_water;
4280         uint32_t mflcn;
4281         enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
4282                 ixgbe_fc_none,
4283                 ixgbe_fc_rx_pause,
4284                 ixgbe_fc_tx_pause,
4285                 ixgbe_fc_full
4286         };
4287
4288         PMD_INIT_FUNC_TRACE();
4289
4290         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4291         rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0));
4292         PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
4293
4294         /*
4295          * At least reserve one Ethernet frame for watermark
4296          * high_water/low_water in kilo bytes for ixgbe
4297          */
4298         max_high_water = (rx_buf_size - ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
4299         if ((fc_conf->high_water > max_high_water) ||
4300                 (fc_conf->high_water < fc_conf->low_water)) {
4301                 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
4302                 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
4303                 return -EINVAL;
4304         }
4305
4306         hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[fc_conf->mode];
4307         hw->fc.pause_time     = fc_conf->pause_time;
4308         hw->fc.high_water[0]  = fc_conf->high_water;
4309         hw->fc.low_water[0]   = fc_conf->low_water;
4310         hw->fc.send_xon       = fc_conf->send_xon;
4311         hw->fc.disable_fc_autoneg = !fc_conf->autoneg;
4312
4313         err = ixgbe_fc_enable(hw);
4314
4315         /* Not negotiated is not an error case */
4316         if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED)) {
4317
4318                 /* check if we want to forward MAC frames - driver doesn't have native
4319                  * capability to do that, so we'll write the registers ourselves */
4320
4321                 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4322
4323                 /* set or clear MFLCN.PMCF bit depending on configuration */
4324                 if (fc_conf->mac_ctrl_frame_fwd != 0)
4325                         mflcn |= IXGBE_MFLCN_PMCF;
4326                 else
4327                         mflcn &= ~IXGBE_MFLCN_PMCF;
4328
4329                 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn);
4330                 IXGBE_WRITE_FLUSH(hw);
4331
4332                 return 0;
4333         }
4334
4335         PMD_INIT_LOG(ERR, "ixgbe_fc_enable = 0x%x", err);
4336         return -EIO;
4337 }
4338
4339 /**
4340  *  ixgbe_pfc_enable_generic - Enable flow control
4341  *  @hw: pointer to hardware structure
4342  *  @tc_num: traffic class number
4343  *  Enable flow control according to the current settings.
4344  */
4345 static int
4346 ixgbe_dcb_pfc_enable_generic(struct ixgbe_hw *hw, uint8_t tc_num)
4347 {
4348         int ret_val = 0;
4349         uint32_t mflcn_reg, fccfg_reg;
4350         uint32_t reg;
4351         uint32_t fcrtl, fcrth;
4352         uint8_t i;
4353         uint8_t nb_rx_en;
4354
4355         /* Validate the water mark configuration */
4356         if (!hw->fc.pause_time) {
4357                 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
4358                 goto out;
4359         }
4360
4361         /* Low water mark of zero causes XOFF floods */
4362         if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
4363                  /* High/Low water can not be 0 */
4364                 if ((!hw->fc.high_water[tc_num]) || (!hw->fc.low_water[tc_num])) {
4365                         PMD_INIT_LOG(ERR, "Invalid water mark configuration");
4366                         ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
4367                         goto out;
4368                 }
4369
4370                 if (hw->fc.low_water[tc_num] >= hw->fc.high_water[tc_num]) {
4371                         PMD_INIT_LOG(ERR, "Invalid water mark configuration");
4372                         ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
4373                         goto out;
4374                 }
4375         }
4376         /* Negotiate the fc mode to use */
4377         ixgbe_fc_autoneg(hw);
4378
4379         /* Disable any previous flow control settings */
4380         mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4381         mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_SHIFT | IXGBE_MFLCN_RFCE|IXGBE_MFLCN_RPFCE);
4382
4383         fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
4384         fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
4385
4386         switch (hw->fc.current_mode) {
4387         case ixgbe_fc_none:
4388                 /*
4389                  * If the count of enabled RX Priority Flow control >1,
4390                  * and the TX pause can not be disabled
4391                  */
4392                 nb_rx_en = 0;
4393                 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
4394                         reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
4395                         if (reg & IXGBE_FCRTH_FCEN)
4396                                 nb_rx_en++;
4397                 }
4398                 if (nb_rx_en > 1)
4399                         fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
4400                 break;
4401         case ixgbe_fc_rx_pause:
4402                 /*
4403                  * Rx Flow control is enabled and Tx Flow control is
4404                  * disabled by software override. Since there really
4405                  * isn't a way to advertise that we are capable of RX
4406                  * Pause ONLY, we will advertise that we support both
4407                  * symmetric and asymmetric Rx PAUSE.  Later, we will
4408                  * disable the adapter's ability to send PAUSE frames.
4409                  */
4410                 mflcn_reg |= IXGBE_MFLCN_RPFCE;
4411                 /*
4412                  * If the count of enabled RX Priority Flow control >1,
4413                  * and the TX pause can not be disabled
4414                  */
4415                 nb_rx_en = 0;
4416                 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
4417                         reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
4418                         if (reg & IXGBE_FCRTH_FCEN)
4419                                 nb_rx_en++;
4420                 }
4421                 if (nb_rx_en > 1)
4422                         fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
4423                 break;
4424         case ixgbe_fc_tx_pause:
4425                 /*
4426                  * Tx Flow control is enabled, and Rx Flow control is
4427                  * disabled by software override.
4428                  */
4429                 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
4430                 break;
4431         case ixgbe_fc_full:
4432                 /* Flow control (both Rx and Tx) is enabled by SW override. */
4433                 mflcn_reg |= IXGBE_MFLCN_RPFCE;
4434                 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
4435                 break;
4436         default:
4437                 PMD_DRV_LOG(DEBUG, "Flow control param set incorrectly");
4438                 ret_val = IXGBE_ERR_CONFIG;
4439                 goto out;
4440         }
4441
4442         /* Set 802.3x based flow control settings. */
4443         mflcn_reg |= IXGBE_MFLCN_DPF;
4444         IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
4445         IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
4446
4447         /* Set up and enable Rx high/low water mark thresholds, enable XON. */
4448         if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
4449                 hw->fc.high_water[tc_num]) {
4450                 fcrtl = (hw->fc.low_water[tc_num] << 10) | IXGBE_FCRTL_XONE;
4451                 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), fcrtl);
4452                 fcrth = (hw->fc.high_water[tc_num] << 10) | IXGBE_FCRTH_FCEN;
4453         } else {
4454                 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), 0);
4455                 /*
4456                  * In order to prevent Tx hangs when the internal Tx
4457                  * switch is enabled we must set the high water mark
4458                  * to the maximum FCRTH value.  This allows the Tx
4459                  * switch to function even under heavy Rx workloads.
4460                  */
4461                 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num)) - 32;
4462         }
4463         IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(tc_num), fcrth);
4464
4465         /* Configure pause time (2 TCs per register) */
4466         reg = hw->fc.pause_time * 0x00010001;
4467         for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
4468                 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
4469
4470         /* Configure flow control refresh threshold value */
4471         IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
4472
4473 out:
4474         return ret_val;
4475 }
4476
4477 static int
4478 ixgbe_dcb_pfc_enable(struct rte_eth_dev *dev, uint8_t tc_num)
4479 {
4480         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4481         int32_t ret_val = IXGBE_NOT_IMPLEMENTED;
4482
4483         if (hw->mac.type != ixgbe_mac_82598EB) {
4484                 ret_val = ixgbe_dcb_pfc_enable_generic(hw, tc_num);
4485         }
4486         return ret_val;
4487 }
4488
4489 static int
4490 ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
4491 {
4492         int err;
4493         uint32_t rx_buf_size;
4494         uint32_t max_high_water;
4495         uint8_t tc_num;
4496         uint8_t  map[IXGBE_DCB_MAX_USER_PRIORITY] = { 0 };
4497         struct ixgbe_hw *hw =
4498                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4499         struct ixgbe_dcb_config *dcb_config =
4500                 IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
4501
4502         enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
4503                 ixgbe_fc_none,
4504                 ixgbe_fc_rx_pause,
4505                 ixgbe_fc_tx_pause,
4506                 ixgbe_fc_full
4507         };
4508
4509         PMD_INIT_FUNC_TRACE();
4510
4511         ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_RX_CONFIG, map);
4512         tc_num = map[pfc_conf->priority];
4513         rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num));
4514         PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
4515         /*
4516          * At least reserve one Ethernet frame for watermark
4517          * high_water/low_water in kilo bytes for ixgbe
4518          */
4519         max_high_water = (rx_buf_size - ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
4520         if ((pfc_conf->fc.high_water > max_high_water) ||
4521             (pfc_conf->fc.high_water <= pfc_conf->fc.low_water)) {
4522                 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
4523                 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
4524                 return -EINVAL;
4525         }
4526
4527         hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[pfc_conf->fc.mode];
4528         hw->fc.pause_time = pfc_conf->fc.pause_time;
4529         hw->fc.send_xon = pfc_conf->fc.send_xon;
4530         hw->fc.low_water[tc_num] =  pfc_conf->fc.low_water;
4531         hw->fc.high_water[tc_num] = pfc_conf->fc.high_water;
4532
4533         err = ixgbe_dcb_pfc_enable(dev, tc_num);
4534
4535         /* Not negotiated is not an error case */
4536         if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED))
4537                 return 0;
4538
4539         PMD_INIT_LOG(ERR, "ixgbe_dcb_pfc_enable = 0x%x", err);
4540         return -EIO;
4541 }
4542
4543 static int
4544 ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
4545                           struct rte_eth_rss_reta_entry64 *reta_conf,
4546                           uint16_t reta_size)
4547 {
4548         uint16_t i, sp_reta_size;
4549         uint8_t j, mask;
4550         uint32_t reta, r;
4551         uint16_t idx, shift;
4552         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4553         uint32_t reta_reg;
4554
4555         PMD_INIT_FUNC_TRACE();
4556
4557         if (!ixgbe_rss_update_sp(hw->mac.type)) {
4558                 PMD_DRV_LOG(ERR, "RSS reta update is not supported on this "
4559                         "NIC.");
4560                 return -ENOTSUP;
4561         }
4562
4563         sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
4564         if (reta_size != sp_reta_size) {
4565                 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
4566                         "(%d) doesn't match the number hardware can supported "
4567                         "(%d)", reta_size, sp_reta_size);
4568                 return -EINVAL;
4569         }
4570
4571         for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
4572                 idx = i / RTE_RETA_GROUP_SIZE;
4573                 shift = i % RTE_RETA_GROUP_SIZE;
4574                 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
4575                                                 IXGBE_4_BIT_MASK);
4576                 if (!mask)
4577                         continue;
4578                 reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
4579                 if (mask == IXGBE_4_BIT_MASK)
4580                         r = 0;
4581                 else
4582                         r = IXGBE_READ_REG(hw, reta_reg);
4583                 for (j = 0, reta = 0; j < IXGBE_4_BIT_WIDTH; j++) {
4584                         if (mask & (0x1 << j))
4585                                 reta |= reta_conf[idx].reta[shift + j] <<
4586                                                         (CHAR_BIT * j);
4587                         else
4588                                 reta |= r & (IXGBE_8_BIT_MASK <<
4589                                                 (CHAR_BIT * j));
4590                 }
4591                 IXGBE_WRITE_REG(hw, reta_reg, reta);
4592         }
4593
4594         return 0;
4595 }
4596
4597 static int
4598 ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
4599                          struct rte_eth_rss_reta_entry64 *reta_conf,
4600                          uint16_t reta_size)
4601 {
4602         uint16_t i, sp_reta_size;
4603         uint8_t j, mask;
4604         uint32_t reta;
4605         uint16_t idx, shift;
4606         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4607         uint32_t reta_reg;
4608
4609         PMD_INIT_FUNC_TRACE();
4610         sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
4611         if (reta_size != sp_reta_size) {
4612                 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
4613                         "(%d) doesn't match the number hardware can supported "
4614                         "(%d)", reta_size, sp_reta_size);
4615                 return -EINVAL;
4616         }
4617
4618         for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
4619                 idx = i / RTE_RETA_GROUP_SIZE;
4620                 shift = i % RTE_RETA_GROUP_SIZE;
4621                 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
4622                                                 IXGBE_4_BIT_MASK);
4623                 if (!mask)
4624                         continue;
4625
4626                 reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
4627                 reta = IXGBE_READ_REG(hw, reta_reg);
4628                 for (j = 0; j < IXGBE_4_BIT_WIDTH; j++) {
4629                         if (mask & (0x1 << j))
4630                                 reta_conf[idx].reta[shift + j] =
4631                                         ((reta >> (CHAR_BIT * j)) &
4632                                                 IXGBE_8_BIT_MASK);
4633                 }
4634         }
4635
4636         return 0;
4637 }
4638
4639 static void
4640 ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
4641                                 uint32_t index, uint32_t pool)
4642 {
4643         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4644         uint32_t enable_addr = 1;
4645
4646         ixgbe_set_rar(hw, index, mac_addr->addr_bytes, pool, enable_addr);
4647 }
4648
4649 static void
4650 ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index)
4651 {
4652         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4653
4654         ixgbe_clear_rar(hw, index);
4655 }
4656
4657 static void
4658 ixgbe_set_default_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
4659 {
4660         ixgbe_remove_rar(dev, 0);
4661
4662         ixgbe_add_rar(dev, addr, 0, 0);
4663 }
4664
4665 static bool
4666 is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
4667 {
4668         if (strcmp(dev->data->drv_name, drv->driver.name))
4669                 return false;
4670
4671         return true;
4672 }
4673
4674 bool
4675 is_ixgbe_supported(struct rte_eth_dev *dev)
4676 {
4677         return is_device_supported(dev, &rte_ixgbe_pmd);
4678 }
4679
4680 static int
4681 ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
4682 {
4683         uint32_t hlreg0;
4684         uint32_t maxfrs;
4685         struct ixgbe_hw *hw;
4686         struct rte_eth_dev_info dev_info;
4687         uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
4688
4689         ixgbe_dev_info_get(dev, &dev_info);
4690
4691         /* check that mtu is within the allowed range */
4692         if ((mtu < ETHER_MIN_MTU) || (frame_size > dev_info.max_rx_pktlen))
4693                 return -EINVAL;
4694
4695         /* refuse mtu that requires the support of scattered packets when this
4696          * feature has not been enabled before.
4697          */
4698         if (!dev->data->scattered_rx &&
4699             (frame_size + 2 * IXGBE_VLAN_TAG_SIZE >
4700              dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
4701                 return -EINVAL;
4702
4703         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4704         hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
4705
4706         /* switch to jumbo mode if needed */
4707         if (frame_size > ETHER_MAX_LEN) {
4708                 dev->data->dev_conf.rxmode.jumbo_frame = 1;
4709                 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
4710         } else {
4711                 dev->data->dev_conf.rxmode.jumbo_frame = 0;
4712                 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
4713         }
4714         IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4715
4716         /* update max frame size */
4717         dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
4718
4719         maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
4720         maxfrs &= 0x0000FFFF;
4721         maxfrs |= (dev->data->dev_conf.rxmode.max_rx_pkt_len << 16);
4722         IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, maxfrs);
4723
4724         return 0;
4725 }
4726
4727 /*
4728  * Virtual Function operations
4729  */
4730 static void
4731 ixgbevf_intr_disable(struct ixgbe_hw *hw)
4732 {
4733         PMD_INIT_FUNC_TRACE();
4734
4735         /* Clear interrupt mask to stop from interrupts being generated */
4736         IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
4737
4738         IXGBE_WRITE_FLUSH(hw);
4739 }
4740
4741 static void
4742 ixgbevf_intr_enable(struct ixgbe_hw *hw)
4743 {
4744         PMD_INIT_FUNC_TRACE();
4745
4746         /* VF enable interrupt autoclean */
4747         IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, IXGBE_VF_IRQ_ENABLE_MASK);
4748         IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, IXGBE_VF_IRQ_ENABLE_MASK);
4749         IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, IXGBE_VF_IRQ_ENABLE_MASK);
4750
4751         IXGBE_WRITE_FLUSH(hw);
4752 }
4753
4754 static int
4755 ixgbevf_dev_configure(struct rte_eth_dev *dev)
4756 {
4757         struct rte_eth_conf *conf = &dev->data->dev_conf;
4758         struct ixgbe_adapter *adapter =
4759                         (struct ixgbe_adapter *)dev->data->dev_private;
4760
4761         PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
4762                      dev->data->port_id);
4763
4764         /*
4765          * VF has no ability to enable/disable HW CRC
4766          * Keep the persistent behavior the same as Host PF
4767          */
4768 #ifndef RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC
4769         if (!conf->rxmode.hw_strip_crc) {
4770                 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
4771                 conf->rxmode.hw_strip_crc = 1;
4772         }
4773 #else
4774         if (conf->rxmode.hw_strip_crc) {
4775                 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
4776                 conf->rxmode.hw_strip_crc = 0;
4777         }
4778 #endif
4779
4780         /*
4781          * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
4782          * allocation or vector Rx preconditions we will reset it.
4783          */
4784         adapter->rx_bulk_alloc_allowed = true;
4785         adapter->rx_vec_allowed = true;
4786
4787         return 0;
4788 }
4789
4790 static int
4791 ixgbevf_dev_start(struct rte_eth_dev *dev)
4792 {
4793         struct ixgbe_hw *hw =
4794                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4795         uint32_t intr_vector = 0;
4796         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
4797         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
4798
4799         int err, mask = 0;
4800
4801         PMD_INIT_FUNC_TRACE();
4802
4803         hw->mac.ops.reset_hw(hw);
4804         hw->mac.get_link_status = true;
4805
4806         /* negotiate mailbox API version to use with the PF. */
4807         ixgbevf_negotiate_api(hw);
4808
4809         ixgbevf_dev_tx_init(dev);
4810
4811         /* This can fail when allocating mbufs for descriptor rings */
4812         err = ixgbevf_dev_rx_init(dev);
4813         if (err) {
4814                 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
4815                 ixgbe_dev_clear_queues(dev);
4816                 return err;
4817         }
4818
4819         /* Set vfta */
4820         ixgbevf_set_vfta_all(dev, 1);
4821
4822         /* Set HW strip */
4823         mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK |
4824                 ETH_VLAN_EXTEND_MASK;
4825         ixgbevf_vlan_offload_set(dev, mask);
4826
4827         ixgbevf_dev_rxtx_start(dev);
4828
4829         /* check and configure queue intr-vector mapping */
4830         if (dev->data->dev_conf.intr_conf.rxq != 0) {
4831                 intr_vector = dev->data->nb_rx_queues;
4832                 if (rte_intr_efd_enable(intr_handle, intr_vector))
4833                         return -1;
4834         }
4835
4836         if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
4837                 intr_handle->intr_vec =
4838                         rte_zmalloc("intr_vec",
4839                                     dev->data->nb_rx_queues * sizeof(int), 0);
4840                 if (intr_handle->intr_vec == NULL) {
4841                         PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
4842                                      " intr_vec", dev->data->nb_rx_queues);
4843                         return -ENOMEM;
4844                 }
4845         }
4846         ixgbevf_configure_msix(dev);
4847
4848         rte_intr_enable(intr_handle);
4849
4850         /* Re-enable interrupt for VF */
4851         ixgbevf_intr_enable(hw);
4852
4853         return 0;
4854 }
4855
4856 static void
4857 ixgbevf_dev_stop(struct rte_eth_dev *dev)
4858 {
4859         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4860         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
4861         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
4862
4863         PMD_INIT_FUNC_TRACE();
4864
4865         ixgbevf_intr_disable(hw);
4866
4867         hw->adapter_stopped = 1;
4868         ixgbe_stop_adapter(hw);
4869
4870         /*
4871           * Clear what we set, but we still keep shadow_vfta to
4872           * restore after device starts
4873           */
4874         ixgbevf_set_vfta_all(dev, 0);
4875
4876         /* Clear stored conf */
4877         dev->data->scattered_rx = 0;
4878
4879         ixgbe_dev_clear_queues(dev);
4880
4881         /* Clean datapath event and queue/vec mapping */
4882         rte_intr_efd_disable(intr_handle);
4883         if (intr_handle->intr_vec != NULL) {
4884                 rte_free(intr_handle->intr_vec);
4885                 intr_handle->intr_vec = NULL;
4886         }
4887 }
4888
4889 static void
4890 ixgbevf_dev_close(struct rte_eth_dev *dev)
4891 {
4892         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4893
4894         PMD_INIT_FUNC_TRACE();
4895
4896         ixgbe_reset_hw(hw);
4897
4898         ixgbevf_dev_stop(dev);
4899
4900         ixgbe_dev_free_queues(dev);
4901
4902         /**
4903          * Remove the VF MAC address ro ensure
4904          * that the VF traffic goes to the PF
4905          * after stop, close and detach of the VF
4906          **/
4907         ixgbevf_remove_mac_addr(dev, 0);
4908 }
4909
4910 static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
4911 {
4912         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4913         struct ixgbe_vfta *shadow_vfta =
4914                 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
4915         int i = 0, j = 0, vfta = 0, mask = 1;
4916
4917         for (i = 0; i < IXGBE_VFTA_SIZE; i++) {
4918                 vfta = shadow_vfta->vfta[i];
4919                 if (vfta) {
4920                         mask = 1;
4921                         for (j = 0; j < 32; j++) {
4922                                 if (vfta & mask)
4923                                         ixgbe_set_vfta(hw, (i<<5)+j, 0,
4924                                                        on, false);
4925                                 mask <<= 1;
4926                         }
4927                 }
4928         }
4929
4930 }
4931
4932 static int
4933 ixgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
4934 {
4935         struct ixgbe_hw *hw =
4936                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4937         struct ixgbe_vfta *shadow_vfta =
4938                 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
4939         uint32_t vid_idx = 0;
4940         uint32_t vid_bit = 0;
4941         int ret = 0;
4942
4943         PMD_INIT_FUNC_TRACE();
4944
4945         /* vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf */
4946         ret = ixgbe_set_vfta(hw, vlan_id, 0, !!on, false);
4947         if (ret) {
4948                 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
4949                 return ret;
4950         }
4951         vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
4952         vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
4953
4954         /* Save what we set and retore it after device reset */
4955         if (on)
4956                 shadow_vfta->vfta[vid_idx] |= vid_bit;
4957         else
4958                 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
4959
4960         return 0;
4961 }
4962
4963 static void
4964 ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
4965 {
4966         struct ixgbe_hw *hw =
4967                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4968         uint32_t ctrl;
4969
4970         PMD_INIT_FUNC_TRACE();
4971
4972         if (queue >= hw->mac.max_rx_queues)
4973                 return;
4974
4975         ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
4976         if (on)
4977                 ctrl |= IXGBE_RXDCTL_VME;
4978         else
4979                 ctrl &= ~IXGBE_RXDCTL_VME;
4980         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
4981
4982         ixgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
4983 }
4984
4985 static void
4986 ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4987 {
4988         struct ixgbe_hw *hw =
4989                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4990         uint16_t i;
4991         int on = 0;
4992
4993         /* VF function only support hw strip feature, others are not support */
4994         if (mask & ETH_VLAN_STRIP_MASK) {
4995                 on = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
4996
4997                 for (i = 0; i < hw->mac.max_rx_queues; i++)
4998                         ixgbevf_vlan_strip_queue_set(dev, i, on);
4999         }
5000 }
5001
5002 int
5003 ixgbe_vt_check(struct ixgbe_hw *hw)
5004 {
5005         uint32_t reg_val;
5006
5007         /* if Virtualization Technology is enabled */
5008         reg_val = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
5009         if (!(reg_val & IXGBE_VT_CTL_VT_ENABLE)) {
5010                 PMD_INIT_LOG(ERR, "VT must be enabled for this setting");
5011                 return -1;
5012         }
5013
5014         return 0;
5015 }
5016
5017 static uint32_t
5018 ixgbe_uta_vector(struct ixgbe_hw *hw, struct ether_addr *uc_addr)
5019 {
5020         uint32_t vector = 0;
5021
5022         switch (hw->mac.mc_filter_type) {
5023         case 0:   /* use bits [47:36] of the address */
5024                 vector = ((uc_addr->addr_bytes[4] >> 4) |
5025                         (((uint16_t)uc_addr->addr_bytes[5]) << 4));
5026                 break;
5027         case 1:   /* use bits [46:35] of the address */
5028                 vector = ((uc_addr->addr_bytes[4] >> 3) |
5029                         (((uint16_t)uc_addr->addr_bytes[5]) << 5));
5030                 break;
5031         case 2:   /* use bits [45:34] of the address */
5032                 vector = ((uc_addr->addr_bytes[4] >> 2) |
5033                         (((uint16_t)uc_addr->addr_bytes[5]) << 6));
5034                 break;
5035         case 3:   /* use bits [43:32] of the address */
5036                 vector = ((uc_addr->addr_bytes[4]) |
5037                         (((uint16_t)uc_addr->addr_bytes[5]) << 8));
5038                 break;
5039         default:  /* Invalid mc_filter_type */
5040                 break;
5041         }
5042
5043         /* vector can only be 12-bits or boundary will be exceeded */
5044         vector &= 0xFFF;
5045         return vector;
5046 }
5047
5048 static int
5049 ixgbe_uc_hash_table_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
5050                         uint8_t on)
5051 {
5052         uint32_t vector;
5053         uint32_t uta_idx;
5054         uint32_t reg_val;
5055         uint32_t uta_shift;
5056         uint32_t rc;
5057         const uint32_t ixgbe_uta_idx_mask = 0x7F;
5058         const uint32_t ixgbe_uta_bit_shift = 5;
5059         const uint32_t ixgbe_uta_bit_mask = (0x1 << ixgbe_uta_bit_shift) - 1;
5060         const uint32_t bit1 = 0x1;
5061
5062         struct ixgbe_hw *hw =
5063                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5064         struct ixgbe_uta_info *uta_info =
5065                 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
5066
5067         /* The UTA table only exists on 82599 hardware and newer */
5068         if (hw->mac.type < ixgbe_mac_82599EB)
5069                 return -ENOTSUP;
5070
5071         vector = ixgbe_uta_vector(hw, mac_addr);
5072         uta_idx = (vector >> ixgbe_uta_bit_shift) & ixgbe_uta_idx_mask;
5073         uta_shift = vector & ixgbe_uta_bit_mask;
5074
5075         rc = ((uta_info->uta_shadow[uta_idx] >> uta_shift & bit1) != 0);
5076         if (rc == on)
5077                 return 0;
5078
5079         reg_val = IXGBE_READ_REG(hw, IXGBE_UTA(uta_idx));
5080         if (on) {
5081                 uta_info->uta_in_use++;
5082                 reg_val |= (bit1 << uta_shift);
5083                 uta_info->uta_shadow[uta_idx] |= (bit1 << uta_shift);
5084         } else {
5085                 uta_info->uta_in_use--;
5086                 reg_val &= ~(bit1 << uta_shift);
5087                 uta_info->uta_shadow[uta_idx] &= ~(bit1 << uta_shift);
5088         }
5089
5090         IXGBE_WRITE_REG(hw, IXGBE_UTA(uta_idx), reg_val);
5091
5092         if (uta_info->uta_in_use > 0)
5093                 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
5094                                 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
5095         else
5096                 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
5097
5098         return 0;
5099 }
5100
5101 static int
5102 ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on)
5103 {
5104         int i;
5105         struct ixgbe_hw *hw =
5106                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5107         struct ixgbe_uta_info *uta_info =
5108                 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
5109
5110         /* The UTA table only exists on 82599 hardware and newer */
5111         if (hw->mac.type < ixgbe_mac_82599EB)
5112                 return -ENOTSUP;
5113
5114         if (on) {
5115                 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
5116                         uta_info->uta_shadow[i] = ~0;
5117                         IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
5118                 }
5119         } else {
5120                 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
5121                         uta_info->uta_shadow[i] = 0;
5122                         IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
5123                 }
5124         }
5125         return 0;
5126
5127 }
5128
5129 uint32_t
5130 ixgbe_convert_vm_rx_mask_to_val(uint16_t rx_mask, uint32_t orig_val)
5131 {
5132         uint32_t new_val = orig_val;
5133
5134         if (rx_mask & ETH_VMDQ_ACCEPT_UNTAG)
5135                 new_val |= IXGBE_VMOLR_AUPE;
5136         if (rx_mask & ETH_VMDQ_ACCEPT_HASH_MC)
5137                 new_val |= IXGBE_VMOLR_ROMPE;
5138         if (rx_mask & ETH_VMDQ_ACCEPT_HASH_UC)
5139                 new_val |= IXGBE_VMOLR_ROPE;
5140         if (rx_mask & ETH_VMDQ_ACCEPT_BROADCAST)
5141                 new_val |= IXGBE_VMOLR_BAM;
5142         if (rx_mask & ETH_VMDQ_ACCEPT_MULTICAST)
5143                 new_val |= IXGBE_VMOLR_MPE;
5144
5145         return new_val;
5146 }
5147
5148 #define IXGBE_MRCTL_VPME  0x01 /* Virtual Pool Mirroring. */
5149 #define IXGBE_MRCTL_UPME  0x02 /* Uplink Port Mirroring. */
5150 #define IXGBE_MRCTL_DPME  0x04 /* Downlink Port Mirroring. */
5151 #define IXGBE_MRCTL_VLME  0x08 /* VLAN Mirroring. */
5152 #define IXGBE_INVALID_MIRROR_TYPE(mirror_type) \
5153         ((mirror_type) & ~(uint8_t)(ETH_MIRROR_VIRTUAL_POOL_UP | \
5154         ETH_MIRROR_UPLINK_PORT | ETH_MIRROR_DOWNLINK_PORT | ETH_MIRROR_VLAN))
5155
5156 static int
5157 ixgbe_mirror_rule_set(struct rte_eth_dev *dev,
5158                       struct rte_eth_mirror_conf *mirror_conf,
5159                       uint8_t rule_id, uint8_t on)
5160 {
5161         uint32_t mr_ctl, vlvf;
5162         uint32_t mp_lsb = 0;
5163         uint32_t mv_msb = 0;
5164         uint32_t mv_lsb = 0;
5165         uint32_t mp_msb = 0;
5166         uint8_t i = 0;
5167         int reg_index = 0;
5168         uint64_t vlan_mask = 0;
5169
5170         const uint8_t pool_mask_offset = 32;
5171         const uint8_t vlan_mask_offset = 32;
5172         const uint8_t dst_pool_offset = 8;
5173         const uint8_t rule_mr_offset  = 4;
5174         const uint8_t mirror_rule_mask = 0x0F;
5175
5176         struct ixgbe_mirror_info *mr_info =
5177                         (IXGBE_DEV_PRIVATE_TO_PFDATA(dev->data->dev_private));
5178         struct ixgbe_hw *hw =
5179                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5180         uint8_t mirror_type = 0;
5181
5182         if (ixgbe_vt_check(hw) < 0)
5183                 return -ENOTSUP;
5184
5185         if (rule_id >= IXGBE_MAX_MIRROR_RULES)
5186                 return -EINVAL;
5187
5188         if (IXGBE_INVALID_MIRROR_TYPE(mirror_conf->rule_type)) {
5189                 PMD_DRV_LOG(ERR, "unsupported mirror type 0x%x.",
5190                             mirror_conf->rule_type);
5191                 return -EINVAL;
5192         }
5193
5194         if (mirror_conf->rule_type & ETH_MIRROR_VLAN) {
5195                 mirror_type |= IXGBE_MRCTL_VLME;
5196                 /* Check if vlan id is valid and find conresponding VLAN ID
5197                  * index in VLVF
5198                  */
5199                 for (i = 0; i < IXGBE_VLVF_ENTRIES; i++) {
5200                         if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
5201                                 /* search vlan id related pool vlan filter
5202                                  * index
5203                                  */
5204                                 reg_index = ixgbe_find_vlvf_slot(
5205                                                 hw,
5206                                                 mirror_conf->vlan.vlan_id[i],
5207                                                 false);
5208                                 if (reg_index < 0)
5209                                         return -EINVAL;
5210                                 vlvf = IXGBE_READ_REG(hw,
5211                                                       IXGBE_VLVF(reg_index));
5212                                 if ((vlvf & IXGBE_VLVF_VIEN) &&
5213                                     ((vlvf & IXGBE_VLVF_VLANID_MASK) ==
5214                                       mirror_conf->vlan.vlan_id[i]))
5215                                         vlan_mask |= (1ULL << reg_index);
5216                                 else
5217                                         return -EINVAL;
5218                         }
5219                 }
5220
5221                 if (on) {
5222                         mv_lsb = vlan_mask & 0xFFFFFFFF;
5223                         mv_msb = vlan_mask >> vlan_mask_offset;
5224
5225                         mr_info->mr_conf[rule_id].vlan.vlan_mask =
5226                                                 mirror_conf->vlan.vlan_mask;
5227                         for (i = 0; i < ETH_VMDQ_MAX_VLAN_FILTERS; i++) {
5228                                 if (mirror_conf->vlan.vlan_mask & (1ULL << i))
5229                                         mr_info->mr_conf[rule_id].vlan.vlan_id[i] =
5230                                                 mirror_conf->vlan.vlan_id[i];
5231                         }
5232                 } else {
5233                         mv_lsb = 0;
5234                         mv_msb = 0;
5235                         mr_info->mr_conf[rule_id].vlan.vlan_mask = 0;
5236                         for (i = 0; i < ETH_VMDQ_MAX_VLAN_FILTERS; i++)
5237                                 mr_info->mr_conf[rule_id].vlan.vlan_id[i] = 0;
5238                 }
5239         }
5240
5241         /**
5242          * if enable pool mirror, write related pool mask register,if disable
5243          * pool mirror, clear PFMRVM register
5244          */
5245         if (mirror_conf->rule_type & ETH_MIRROR_VIRTUAL_POOL_UP) {
5246                 mirror_type |= IXGBE_MRCTL_VPME;
5247                 if (on) {
5248                         mp_lsb = mirror_conf->pool_mask & 0xFFFFFFFF;
5249                         mp_msb = mirror_conf->pool_mask >> pool_mask_offset;
5250                         mr_info->mr_conf[rule_id].pool_mask =
5251                                         mirror_conf->pool_mask;
5252
5253                 } else {
5254                         mp_lsb = 0;
5255                         mp_msb = 0;
5256                         mr_info->mr_conf[rule_id].pool_mask = 0;
5257                 }
5258         }
5259         if (mirror_conf->rule_type & ETH_MIRROR_UPLINK_PORT)
5260                 mirror_type |= IXGBE_MRCTL_UPME;
5261         if (mirror_conf->rule_type & ETH_MIRROR_DOWNLINK_PORT)
5262                 mirror_type |= IXGBE_MRCTL_DPME;
5263
5264         /* read  mirror control register and recalculate it */
5265         mr_ctl = IXGBE_READ_REG(hw, IXGBE_MRCTL(rule_id));
5266
5267         if (on) {
5268                 mr_ctl |= mirror_type;
5269                 mr_ctl &= mirror_rule_mask;
5270                 mr_ctl |= mirror_conf->dst_pool << dst_pool_offset;
5271         } else {
5272                 mr_ctl &= ~(mirror_conf->rule_type & mirror_rule_mask);
5273         }
5274
5275         mr_info->mr_conf[rule_id].rule_type = mirror_conf->rule_type;
5276         mr_info->mr_conf[rule_id].dst_pool = mirror_conf->dst_pool;
5277
5278         /* write mirrror control  register */
5279         IXGBE_WRITE_REG(hw, IXGBE_MRCTL(rule_id), mr_ctl);
5280
5281         /* write pool mirrror control  register */
5282         if (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) {
5283                 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id), mp_lsb);
5284                 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id + rule_mr_offset),
5285                                 mp_msb);
5286         }
5287         /* write VLAN mirrror control  register */
5288         if (mirror_conf->rule_type == ETH_MIRROR_VLAN) {
5289                 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id), mv_lsb);
5290                 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id + rule_mr_offset),
5291                                 mv_msb);
5292         }
5293
5294         return 0;
5295 }
5296
5297 static int
5298 ixgbe_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t rule_id)
5299 {
5300         int mr_ctl = 0;
5301         uint32_t lsb_val = 0;
5302         uint32_t msb_val = 0;
5303         const uint8_t rule_mr_offset = 4;
5304
5305         struct ixgbe_hw *hw =
5306                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5307         struct ixgbe_mirror_info *mr_info =
5308                 (IXGBE_DEV_PRIVATE_TO_PFDATA(dev->data->dev_private));
5309
5310         if (ixgbe_vt_check(hw) < 0)
5311                 return -ENOTSUP;
5312
5313         memset(&mr_info->mr_conf[rule_id], 0,
5314                sizeof(struct rte_eth_mirror_conf));
5315
5316         /* clear PFVMCTL register */
5317         IXGBE_WRITE_REG(hw, IXGBE_MRCTL(rule_id), mr_ctl);
5318
5319         /* clear pool mask register */
5320         IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id), lsb_val);
5321         IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id + rule_mr_offset), msb_val);
5322
5323         /* clear vlan mask register */
5324         IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id), lsb_val);
5325         IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id + rule_mr_offset), msb_val);
5326
5327         return 0;
5328 }
5329
5330 static int
5331 ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
5332 {
5333         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
5334         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5335         uint32_t mask;
5336         struct ixgbe_hw *hw =
5337                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5338
5339         mask = IXGBE_READ_REG(hw, IXGBE_VTEIMS);
5340         mask |= (1 << IXGBE_MISC_VEC_ID);
5341         RTE_SET_USED(queue_id);
5342         IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
5343
5344         rte_intr_enable(intr_handle);
5345
5346         return 0;
5347 }
5348
5349 static int
5350 ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
5351 {
5352         uint32_t mask;
5353         struct ixgbe_hw *hw =
5354                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5355
5356         mask = IXGBE_READ_REG(hw, IXGBE_VTEIMS);
5357         mask &= ~(1 << IXGBE_MISC_VEC_ID);
5358         RTE_SET_USED(queue_id);
5359         IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
5360
5361         return 0;
5362 }
5363
5364 static int
5365 ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
5366 {
5367         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
5368         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5369         uint32_t mask;
5370         struct ixgbe_hw *hw =
5371                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5372         struct ixgbe_interrupt *intr =
5373                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
5374
5375         if (queue_id < 16) {
5376                 ixgbe_disable_intr(hw);
5377                 intr->mask |= (1 << queue_id);
5378                 ixgbe_enable_intr(dev);
5379         } else if (queue_id < 32) {
5380                 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(0));
5381                 mask &= (1 << queue_id);
5382                 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
5383         } else if (queue_id < 64) {
5384                 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(1));
5385                 mask &= (1 << (queue_id - 32));
5386                 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
5387         }
5388         rte_intr_enable(intr_handle);
5389
5390         return 0;
5391 }
5392
5393 static int
5394 ixgbe_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
5395 {
5396         uint32_t mask;
5397         struct ixgbe_hw *hw =
5398                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5399         struct ixgbe_interrupt *intr =
5400                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
5401
5402         if (queue_id < 16) {
5403                 ixgbe_disable_intr(hw);
5404                 intr->mask &= ~(1 << queue_id);
5405                 ixgbe_enable_intr(dev);
5406         } else if (queue_id < 32) {
5407                 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(0));
5408                 mask &= ~(1 << queue_id);
5409                 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
5410         } else if (queue_id < 64) {
5411                 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(1));
5412                 mask &= ~(1 << (queue_id - 32));
5413                 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
5414         }
5415
5416         return 0;
5417 }
5418
5419 static void
5420 ixgbevf_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
5421                      uint8_t queue, uint8_t msix_vector)
5422 {
5423         uint32_t tmp, idx;
5424
5425         if (direction == -1) {
5426                 /* other causes */
5427                 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
5428                 tmp = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
5429                 tmp &= ~0xFF;
5430                 tmp |= msix_vector;
5431                 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, tmp);
5432         } else {
5433                 /* rx or tx cause */
5434                 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
5435                 idx = ((16 * (queue & 1)) + (8 * direction));
5436                 tmp = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1));
5437                 tmp &= ~(0xFF << idx);
5438                 tmp |= (msix_vector << idx);
5439                 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), tmp);
5440         }
5441 }
5442
5443 /**
5444  * set the IVAR registers, mapping interrupt causes to vectors
5445  * @param hw
5446  *  pointer to ixgbe_hw struct
5447  * @direction
5448  *  0 for Rx, 1 for Tx, -1 for other causes
5449  * @queue
5450  *  queue to map the corresponding interrupt to
5451  * @msix_vector
5452  *  the vector to map to the corresponding queue
5453  */
5454 static void
5455 ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
5456                    uint8_t queue, uint8_t msix_vector)
5457 {
5458         uint32_t tmp, idx;
5459
5460         msix_vector |= IXGBE_IVAR_ALLOC_VAL;
5461         if (hw->mac.type == ixgbe_mac_82598EB) {
5462                 if (direction == -1)
5463                         direction = 0;
5464                 idx = (((direction * 64) + queue) >> 2) & 0x1F;
5465                 tmp = IXGBE_READ_REG(hw, IXGBE_IVAR(idx));
5466                 tmp &= ~(0xFF << (8 * (queue & 0x3)));
5467                 tmp |= (msix_vector << (8 * (queue & 0x3)));
5468                 IXGBE_WRITE_REG(hw, IXGBE_IVAR(idx), tmp);
5469         } else if ((hw->mac.type == ixgbe_mac_82599EB) ||
5470                         (hw->mac.type == ixgbe_mac_X540)) {
5471                 if (direction == -1) {
5472                         /* other causes */
5473                         idx = ((queue & 1) * 8);
5474                         tmp = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
5475                         tmp &= ~(0xFF << idx);
5476                         tmp |= (msix_vector << idx);
5477                         IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, tmp);
5478                 } else {
5479                         /* rx or tx causes */
5480                         idx = ((16 * (queue & 1)) + (8 * direction));
5481                         tmp = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
5482                         tmp &= ~(0xFF << idx);
5483                         tmp |= (msix_vector << idx);
5484                         IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), tmp);
5485                 }
5486         }
5487 }
5488
5489 static void
5490 ixgbevf_configure_msix(struct rte_eth_dev *dev)
5491 {
5492         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
5493         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5494         struct ixgbe_hw *hw =
5495                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5496         uint32_t q_idx;
5497         uint32_t vector_idx = IXGBE_MISC_VEC_ID;
5498
5499         /* Configure VF other cause ivar */
5500         ixgbevf_set_ivar_map(hw, -1, 1, vector_idx);
5501
5502         /* won't configure msix register if no mapping is done
5503          * between intr vector and event fd.
5504          */
5505         if (!rte_intr_dp_is_en(intr_handle))
5506                 return;
5507
5508         /* Configure all RX queues of VF */
5509         for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
5510                 /* Force all queue use vector 0,
5511                  * as IXGBE_VF_MAXMSIVECOTR = 1
5512                  */
5513                 ixgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
5514                 intr_handle->intr_vec[q_idx] = vector_idx;
5515         }
5516 }
5517
5518 /**
5519  * Sets up the hardware to properly generate MSI-X interrupts
5520  * @hw
5521  *  board private structure
5522  */
5523 static void
5524 ixgbe_configure_msix(struct rte_eth_dev *dev)
5525 {
5526         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
5527         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5528         struct ixgbe_hw *hw =
5529                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5530         uint32_t queue_id, base = IXGBE_MISC_VEC_ID;
5531         uint32_t vec = IXGBE_MISC_VEC_ID;
5532         uint32_t mask;
5533         uint32_t gpie;
5534
5535         /* won't configure msix register if no mapping is done
5536          * between intr vector and event fd
5537          */
5538         if (!rte_intr_dp_is_en(intr_handle))
5539                 return;
5540
5541         if (rte_intr_allow_others(intr_handle))
5542                 vec = base = IXGBE_RX_VEC_START;
5543
5544         /* setup GPIE for MSI-x mode */
5545         gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
5546         gpie |= IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5547                 IXGBE_GPIE_OCD | IXGBE_GPIE_EIAME;
5548         /* auto clearing and auto setting corresponding bits in EIMS
5549          * when MSI-X interrupt is triggered
5550          */
5551         if (hw->mac.type == ixgbe_mac_82598EB) {
5552                 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5553         } else {
5554                 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5555                 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5556         }
5557         IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5558
5559         /* Populate the IVAR table and set the ITR values to the
5560          * corresponding register.
5561          */
5562         for (queue_id = 0; queue_id < dev->data->nb_rx_queues;
5563              queue_id++) {
5564                 /* by default, 1:1 mapping */
5565                 ixgbe_set_ivar_map(hw, 0, queue_id, vec);
5566                 intr_handle->intr_vec[queue_id] = vec;
5567                 if (vec < base + intr_handle->nb_efd - 1)
5568                         vec++;
5569         }
5570
5571         switch (hw->mac.type) {
5572         case ixgbe_mac_82598EB:
5573                 ixgbe_set_ivar_map(hw, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
5574                                    IXGBE_MISC_VEC_ID);
5575                 break;
5576         case ixgbe_mac_82599EB:
5577         case ixgbe_mac_X540:
5578                 ixgbe_set_ivar_map(hw, -1, 1, IXGBE_MISC_VEC_ID);
5579                 break;
5580         default:
5581                 break;
5582         }
5583         IXGBE_WRITE_REG(hw, IXGBE_EITR(IXGBE_MISC_VEC_ID),
5584                         IXGBE_MIN_INTER_INTERRUPT_INTERVAL_DEFAULT & 0xFFF);
5585
5586         /* set up to autoclear timer, and the vectors */
5587         mask = IXGBE_EIMS_ENABLE_MASK;
5588         mask &= ~(IXGBE_EIMS_OTHER |
5589                   IXGBE_EIMS_MAILBOX |
5590                   IXGBE_EIMS_LSC);
5591
5592         IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask);
5593 }
5594
5595 static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
5596         uint16_t queue_idx, uint16_t tx_rate)
5597 {
5598         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5599         uint32_t rf_dec, rf_int;
5600         uint32_t bcnrc_val;
5601         uint16_t link_speed = dev->data->dev_link.link_speed;
5602
5603         if (queue_idx >= hw->mac.max_tx_queues)
5604                 return -EINVAL;
5605
5606         if (tx_rate != 0) {
5607                 /* Calculate the rate factor values to set */
5608                 rf_int = (uint32_t)link_speed / (uint32_t)tx_rate;
5609                 rf_dec = (uint32_t)link_speed % (uint32_t)tx_rate;
5610                 rf_dec = (rf_dec << IXGBE_RTTBCNRC_RF_INT_SHIFT) / tx_rate;
5611
5612                 bcnrc_val = IXGBE_RTTBCNRC_RS_ENA;
5613                 bcnrc_val |= ((rf_int << IXGBE_RTTBCNRC_RF_INT_SHIFT) &
5614                                 IXGBE_RTTBCNRC_RF_INT_MASK_M);
5615                 bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK);
5616         } else {
5617                 bcnrc_val = 0;
5618         }
5619
5620         /*
5621          * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
5622          * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported, otherwise
5623          * set as 0x4.
5624          */
5625         if ((dev->data->dev_conf.rxmode.jumbo_frame == 1) &&
5626                 (dev->data->dev_conf.rxmode.max_rx_pkt_len >=
5627                                 IXGBE_MAX_JUMBO_FRAME_SIZE))
5628                 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM,
5629                         IXGBE_MMW_SIZE_JUMBO_FRAME);
5630         else
5631                 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM,
5632                         IXGBE_MMW_SIZE_DEFAULT);
5633
5634         /* Set RTTBCNRC of queue X */
5635         IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_idx);
5636         IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
5637         IXGBE_WRITE_FLUSH(hw);
5638
5639         return 0;
5640 }
5641
5642 static void
5643 ixgbevf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
5644                      __attribute__((unused)) uint32_t index,
5645                      __attribute__((unused)) uint32_t pool)
5646 {
5647         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5648         int diag;
5649
5650         /*
5651          * On a 82599 VF, adding again the same MAC addr is not an idempotent
5652          * operation. Trap this case to avoid exhausting the [very limited]
5653          * set of PF resources used to store VF MAC addresses.
5654          */
5655         if (memcmp(hw->mac.perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
5656                 return;
5657         diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
5658         if (diag == 0)
5659                 return;
5660         PMD_DRV_LOG(ERR, "Unable to add MAC address - diag=%d", diag);
5661 }
5662
5663 static void
5664 ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
5665 {
5666         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5667         struct ether_addr *perm_addr = (struct ether_addr *) hw->mac.perm_addr;
5668         struct ether_addr *mac_addr;
5669         uint32_t i;
5670         int diag;
5671
5672         /*
5673          * The IXGBE_VF_SET_MACVLAN command of the ixgbe-pf driver does
5674          * not support the deletion of a given MAC address.
5675          * Instead, it imposes to delete all MAC addresses, then to add again
5676          * all MAC addresses with the exception of the one to be deleted.
5677          */
5678         (void) ixgbevf_set_uc_addr_vf(hw, 0, NULL);
5679
5680         /*
5681          * Add again all MAC addresses, with the exception of the deleted one
5682          * and of the permanent MAC address.
5683          */
5684         for (i = 0, mac_addr = dev->data->mac_addrs;
5685              i < hw->mac.num_rar_entries; i++, mac_addr++) {
5686                 /* Skip the deleted MAC address */
5687                 if (i == index)
5688                         continue;
5689                 /* Skip NULL MAC addresses */
5690                 if (is_zero_ether_addr(mac_addr))
5691                         continue;
5692                 /* Skip the permanent MAC address */
5693                 if (memcmp(perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
5694                         continue;
5695                 diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
5696                 if (diag != 0)
5697                         PMD_DRV_LOG(ERR,
5698                                     "Adding again MAC address "
5699                                     "%02x:%02x:%02x:%02x:%02x:%02x failed "
5700                                     "diag=%d",
5701                                     mac_addr->addr_bytes[0],
5702                                     mac_addr->addr_bytes[1],
5703                                     mac_addr->addr_bytes[2],
5704                                     mac_addr->addr_bytes[3],
5705                                     mac_addr->addr_bytes[4],
5706                                     mac_addr->addr_bytes[5],
5707                                     diag);
5708         }
5709 }
5710
5711 static void
5712 ixgbevf_set_default_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
5713 {
5714         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5715
5716         hw->mac.ops.set_rar(hw, 0, (void *)addr, 0, 0);
5717 }
5718
5719 int
5720 ixgbe_syn_filter_set(struct rte_eth_dev *dev,
5721                         struct rte_eth_syn_filter *filter,
5722                         bool add)
5723 {
5724         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5725         struct ixgbe_filter_info *filter_info =
5726                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5727         uint32_t syn_info;
5728         uint32_t synqf;
5729
5730         if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
5731                 return -EINVAL;
5732
5733         syn_info = filter_info->syn_info;
5734
5735         if (add) {
5736                 if (syn_info & IXGBE_SYN_FILTER_ENABLE)
5737                         return -EINVAL;
5738                 synqf = (uint32_t)(((filter->queue << IXGBE_SYN_FILTER_QUEUE_SHIFT) &
5739                         IXGBE_SYN_FILTER_QUEUE) | IXGBE_SYN_FILTER_ENABLE);
5740
5741                 if (filter->hig_pri)
5742                         synqf |= IXGBE_SYN_FILTER_SYNQFP;
5743                 else
5744                         synqf &= ~IXGBE_SYN_FILTER_SYNQFP;
5745         } else {
5746                 synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
5747                 if (!(syn_info & IXGBE_SYN_FILTER_ENABLE))
5748                         return -ENOENT;
5749                 synqf &= ~(IXGBE_SYN_FILTER_QUEUE | IXGBE_SYN_FILTER_ENABLE);
5750         }
5751
5752         filter_info->syn_info = synqf;
5753         IXGBE_WRITE_REG(hw, IXGBE_SYNQF, synqf);
5754         IXGBE_WRITE_FLUSH(hw);
5755         return 0;
5756 }
5757
5758 static int
5759 ixgbe_syn_filter_get(struct rte_eth_dev *dev,
5760                         struct rte_eth_syn_filter *filter)
5761 {
5762         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5763         uint32_t synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
5764
5765         if (synqf & IXGBE_SYN_FILTER_ENABLE) {
5766                 filter->hig_pri = (synqf & IXGBE_SYN_FILTER_SYNQFP) ? 1 : 0;
5767                 filter->queue = (uint16_t)((synqf & IXGBE_SYN_FILTER_QUEUE) >> 1);
5768                 return 0;
5769         }
5770         return -ENOENT;
5771 }
5772
5773 static int
5774 ixgbe_syn_filter_handle(struct rte_eth_dev *dev,
5775                         enum rte_filter_op filter_op,
5776                         void *arg)
5777 {
5778         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5779         int ret;
5780
5781         MAC_TYPE_FILTER_SUP(hw->mac.type);
5782
5783         if (filter_op == RTE_ETH_FILTER_NOP)
5784                 return 0;
5785
5786         if (arg == NULL) {
5787                 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
5788                             filter_op);
5789                 return -EINVAL;
5790         }
5791
5792         switch (filter_op) {
5793         case RTE_ETH_FILTER_ADD:
5794                 ret = ixgbe_syn_filter_set(dev,
5795                                 (struct rte_eth_syn_filter *)arg,
5796                                 TRUE);
5797                 break;
5798         case RTE_ETH_FILTER_DELETE:
5799                 ret = ixgbe_syn_filter_set(dev,
5800                                 (struct rte_eth_syn_filter *)arg,
5801                                 FALSE);
5802                 break;
5803         case RTE_ETH_FILTER_GET:
5804                 ret = ixgbe_syn_filter_get(dev,
5805                                 (struct rte_eth_syn_filter *)arg);
5806                 break;
5807         default:
5808                 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
5809                 ret = -EINVAL;
5810                 break;
5811         }
5812
5813         return ret;
5814 }
5815
5816
5817 static inline enum ixgbe_5tuple_protocol
5818 convert_protocol_type(uint8_t protocol_value)
5819 {
5820         if (protocol_value == IPPROTO_TCP)
5821                 return IXGBE_FILTER_PROTOCOL_TCP;
5822         else if (protocol_value == IPPROTO_UDP)
5823                 return IXGBE_FILTER_PROTOCOL_UDP;
5824         else if (protocol_value == IPPROTO_SCTP)
5825                 return IXGBE_FILTER_PROTOCOL_SCTP;
5826         else
5827                 return IXGBE_FILTER_PROTOCOL_NONE;
5828 }
5829
5830 /* inject a 5-tuple filter to HW */
5831 static inline void
5832 ixgbe_inject_5tuple_filter(struct rte_eth_dev *dev,
5833                            struct ixgbe_5tuple_filter *filter)
5834 {
5835         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5836         int i;
5837         uint32_t ftqf, sdpqf;
5838         uint32_t l34timir = 0;
5839         uint8_t mask = 0xff;
5840
5841         i = filter->index;
5842
5843         sdpqf = (uint32_t)(filter->filter_info.dst_port <<
5844                                 IXGBE_SDPQF_DSTPORT_SHIFT);
5845         sdpqf = sdpqf | (filter->filter_info.src_port & IXGBE_SDPQF_SRCPORT);
5846
5847         ftqf = (uint32_t)(filter->filter_info.proto &
5848                 IXGBE_FTQF_PROTOCOL_MASK);
5849         ftqf |= (uint32_t)((filter->filter_info.priority &
5850                 IXGBE_FTQF_PRIORITY_MASK) << IXGBE_FTQF_PRIORITY_SHIFT);
5851         if (filter->filter_info.src_ip_mask == 0) /* 0 means compare. */
5852                 mask &= IXGBE_FTQF_SOURCE_ADDR_MASK;
5853         if (filter->filter_info.dst_ip_mask == 0)
5854                 mask &= IXGBE_FTQF_DEST_ADDR_MASK;
5855         if (filter->filter_info.src_port_mask == 0)
5856                 mask &= IXGBE_FTQF_SOURCE_PORT_MASK;
5857         if (filter->filter_info.dst_port_mask == 0)
5858                 mask &= IXGBE_FTQF_DEST_PORT_MASK;
5859         if (filter->filter_info.proto_mask == 0)
5860                 mask &= IXGBE_FTQF_PROTOCOL_COMP_MASK;
5861         ftqf |= mask << IXGBE_FTQF_5TUPLE_MASK_SHIFT;
5862         ftqf |= IXGBE_FTQF_POOL_MASK_EN;
5863         ftqf |= IXGBE_FTQF_QUEUE_ENABLE;
5864
5865         IXGBE_WRITE_REG(hw, IXGBE_DAQF(i), filter->filter_info.dst_ip);
5866         IXGBE_WRITE_REG(hw, IXGBE_SAQF(i), filter->filter_info.src_ip);
5867         IXGBE_WRITE_REG(hw, IXGBE_SDPQF(i), sdpqf);
5868         IXGBE_WRITE_REG(hw, IXGBE_FTQF(i), ftqf);
5869
5870         l34timir |= IXGBE_L34T_IMIR_RESERVE;
5871         l34timir |= (uint32_t)(filter->queue <<
5872                                 IXGBE_L34T_IMIR_QUEUE_SHIFT);
5873         IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(i), l34timir);
5874 }
5875
5876 /*
5877  * add a 5tuple filter
5878  *
5879  * @param
5880  * dev: Pointer to struct rte_eth_dev.
5881  * index: the index the filter allocates.
5882  * filter: ponter to the filter that will be added.
5883  * rx_queue: the queue id the filter assigned to.
5884  *
5885  * @return
5886  *    - On success, zero.
5887  *    - On failure, a negative value.
5888  */
5889 static int
5890 ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
5891                         struct ixgbe_5tuple_filter *filter)
5892 {
5893         struct ixgbe_filter_info *filter_info =
5894                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5895         int i, idx, shift;
5896
5897         /*
5898          * look for an unused 5tuple filter index,
5899          * and insert the filter to list.
5900          */
5901         for (i = 0; i < IXGBE_MAX_FTQF_FILTERS; i++) {
5902                 idx = i / (sizeof(uint32_t) * NBBY);
5903                 shift = i % (sizeof(uint32_t) * NBBY);
5904                 if (!(filter_info->fivetuple_mask[idx] & (1 << shift))) {
5905                         filter_info->fivetuple_mask[idx] |= 1 << shift;
5906                         filter->index = i;
5907                         TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
5908                                           filter,
5909                                           entries);
5910                         break;
5911                 }
5912         }
5913         if (i >= IXGBE_MAX_FTQF_FILTERS) {
5914                 PMD_DRV_LOG(ERR, "5tuple filters are full.");
5915                 return -ENOSYS;
5916         }
5917
5918         ixgbe_inject_5tuple_filter(dev, filter);
5919
5920         return 0;
5921 }
5922
5923 /*
5924  * remove a 5tuple filter
5925  *
5926  * @param
5927  * dev: Pointer to struct rte_eth_dev.
5928  * filter: the pointer of the filter will be removed.
5929  */
5930 static void
5931 ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
5932                         struct ixgbe_5tuple_filter *filter)
5933 {
5934         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5935         struct ixgbe_filter_info *filter_info =
5936                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5937         uint16_t index = filter->index;
5938
5939         filter_info->fivetuple_mask[index / (sizeof(uint32_t) * NBBY)] &=
5940                                 ~(1 << (index % (sizeof(uint32_t) * NBBY)));
5941         TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
5942         rte_free(filter);
5943
5944         IXGBE_WRITE_REG(hw, IXGBE_DAQF(index), 0);
5945         IXGBE_WRITE_REG(hw, IXGBE_SAQF(index), 0);
5946         IXGBE_WRITE_REG(hw, IXGBE_SDPQF(index), 0);
5947         IXGBE_WRITE_REG(hw, IXGBE_FTQF(index), 0);
5948         IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(index), 0);
5949 }
5950
5951 static int
5952 ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
5953 {
5954         struct ixgbe_hw *hw;
5955         uint32_t max_frame = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
5956
5957         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5958
5959         if ((mtu < ETHER_MIN_MTU) || (max_frame > ETHER_MAX_JUMBO_FRAME_LEN))
5960                 return -EINVAL;
5961
5962         /* refuse mtu that requires the support of scattered packets when this
5963          * feature has not been enabled before.
5964          */
5965         if (!dev->data->scattered_rx &&
5966             (max_frame + 2 * IXGBE_VLAN_TAG_SIZE >
5967              dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
5968                 return -EINVAL;
5969
5970         /*
5971          * When supported by the underlying PF driver, use the IXGBE_VF_SET_MTU
5972          * request of the version 2.0 of the mailbox API.
5973          * For now, use the IXGBE_VF_SET_LPE request of the version 1.0
5974          * of the mailbox API.
5975          * This call to IXGBE_SET_LPE action won't work with ixgbe pf drivers
5976          * prior to 3.11.33 which contains the following change:
5977          * "ixgbe: Enable jumbo frames support w/ SR-IOV"
5978          */
5979         ixgbevf_rlpml_set_vf(hw, max_frame);
5980
5981         /* update max frame size */
5982         dev->data->dev_conf.rxmode.max_rx_pkt_len = max_frame;
5983         return 0;
5984 }
5985
5986 static inline struct ixgbe_5tuple_filter *
5987 ixgbe_5tuple_filter_lookup(struct ixgbe_5tuple_filter_list *filter_list,
5988                         struct ixgbe_5tuple_filter_info *key)
5989 {
5990         struct ixgbe_5tuple_filter *it;
5991
5992         TAILQ_FOREACH(it, filter_list, entries) {
5993                 if (memcmp(key, &it->filter_info,
5994                         sizeof(struct ixgbe_5tuple_filter_info)) == 0) {
5995                         return it;
5996                 }
5997         }
5998         return NULL;
5999 }
6000
6001 /* translate elements in struct rte_eth_ntuple_filter to struct ixgbe_5tuple_filter_info*/
6002 static inline int
6003 ntuple_filter_to_5tuple(struct rte_eth_ntuple_filter *filter,
6004                         struct ixgbe_5tuple_filter_info *filter_info)
6005 {
6006         if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM ||
6007                 filter->priority > IXGBE_5TUPLE_MAX_PRI ||
6008                 filter->priority < IXGBE_5TUPLE_MIN_PRI)
6009                 return -EINVAL;
6010
6011         switch (filter->dst_ip_mask) {
6012         case UINT32_MAX:
6013                 filter_info->dst_ip_mask = 0;
6014                 filter_info->dst_ip = filter->dst_ip;
6015                 break;
6016         case 0:
6017                 filter_info->dst_ip_mask = 1;
6018                 break;
6019         default:
6020                 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
6021                 return -EINVAL;
6022         }
6023
6024         switch (filter->src_ip_mask) {
6025         case UINT32_MAX:
6026                 filter_info->src_ip_mask = 0;
6027                 filter_info->src_ip = filter->src_ip;
6028                 break;
6029         case 0:
6030                 filter_info->src_ip_mask = 1;
6031                 break;
6032         default:
6033                 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
6034                 return -EINVAL;
6035         }
6036
6037         switch (filter->dst_port_mask) {
6038         case UINT16_MAX:
6039                 filter_info->dst_port_mask = 0;
6040                 filter_info->dst_port = filter->dst_port;
6041                 break;
6042         case 0:
6043                 filter_info->dst_port_mask = 1;
6044                 break;
6045         default:
6046                 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
6047                 return -EINVAL;
6048         }
6049
6050         switch (filter->src_port_mask) {
6051         case UINT16_MAX:
6052                 filter_info->src_port_mask = 0;
6053                 filter_info->src_port = filter->src_port;
6054                 break;
6055         case 0:
6056                 filter_info->src_port_mask = 1;
6057                 break;
6058         default:
6059                 PMD_DRV_LOG(ERR, "invalid src_port mask.");
6060                 return -EINVAL;
6061         }
6062
6063         switch (filter->proto_mask) {
6064         case UINT8_MAX:
6065                 filter_info->proto_mask = 0;
6066                 filter_info->proto =
6067                         convert_protocol_type(filter->proto);
6068                 break;
6069         case 0:
6070                 filter_info->proto_mask = 1;
6071                 break;
6072         default:
6073                 PMD_DRV_LOG(ERR, "invalid protocol mask.");
6074                 return -EINVAL;
6075         }
6076
6077         filter_info->priority = (uint8_t)filter->priority;
6078         return 0;
6079 }
6080
6081 /*
6082  * add or delete a ntuple filter
6083  *
6084  * @param
6085  * dev: Pointer to struct rte_eth_dev.
6086  * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
6087  * add: if true, add filter, if false, remove filter
6088  *
6089  * @return
6090  *    - On success, zero.
6091  *    - On failure, a negative value.
6092  */
6093 int
6094 ixgbe_add_del_ntuple_filter(struct rte_eth_dev *dev,
6095                         struct rte_eth_ntuple_filter *ntuple_filter,
6096                         bool add)
6097 {
6098         struct ixgbe_filter_info *filter_info =
6099                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6100         struct ixgbe_5tuple_filter_info filter_5tuple;
6101         struct ixgbe_5tuple_filter *filter;
6102         int ret;
6103
6104         if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
6105                 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
6106                 return -EINVAL;
6107         }
6108
6109         memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
6110         ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
6111         if (ret < 0)
6112                 return ret;
6113
6114         filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
6115                                          &filter_5tuple);
6116         if (filter != NULL && add) {
6117                 PMD_DRV_LOG(ERR, "filter exists.");
6118                 return -EEXIST;
6119         }
6120         if (filter == NULL && !add) {
6121                 PMD_DRV_LOG(ERR, "filter doesn't exist.");
6122                 return -ENOENT;
6123         }
6124
6125         if (add) {
6126                 filter = rte_zmalloc("ixgbe_5tuple_filter",
6127                                 sizeof(struct ixgbe_5tuple_filter), 0);
6128                 if (filter == NULL)
6129                         return -ENOMEM;
6130                 (void)rte_memcpy(&filter->filter_info,
6131                                  &filter_5tuple,
6132                                  sizeof(struct ixgbe_5tuple_filter_info));
6133                 filter->queue = ntuple_filter->queue;
6134                 ret = ixgbe_add_5tuple_filter(dev, filter);
6135                 if (ret < 0) {
6136                         rte_free(filter);
6137                         return ret;
6138                 }
6139         } else
6140                 ixgbe_remove_5tuple_filter(dev, filter);
6141
6142         return 0;
6143 }
6144
6145 /*
6146  * get a ntuple filter
6147  *
6148  * @param
6149  * dev: Pointer to struct rte_eth_dev.
6150  * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
6151  *
6152  * @return
6153  *    - On success, zero.
6154  *    - On failure, a negative value.
6155  */
6156 static int
6157 ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
6158                         struct rte_eth_ntuple_filter *ntuple_filter)
6159 {
6160         struct ixgbe_filter_info *filter_info =
6161                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6162         struct ixgbe_5tuple_filter_info filter_5tuple;
6163         struct ixgbe_5tuple_filter *filter;
6164         int ret;
6165
6166         if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
6167                 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
6168                 return -EINVAL;
6169         }
6170
6171         memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
6172         ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
6173         if (ret < 0)
6174                 return ret;
6175
6176         filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
6177                                          &filter_5tuple);
6178         if (filter == NULL) {
6179                 PMD_DRV_LOG(ERR, "filter doesn't exist.");
6180                 return -ENOENT;
6181         }
6182         ntuple_filter->queue = filter->queue;
6183         return 0;
6184 }
6185
6186 /*
6187  * ixgbe_ntuple_filter_handle - Handle operations for ntuple filter.
6188  * @dev: pointer to rte_eth_dev structure
6189  * @filter_op:operation will be taken.
6190  * @arg: a pointer to specific structure corresponding to the filter_op
6191  *
6192  * @return
6193  *    - On success, zero.
6194  *    - On failure, a negative value.
6195  */
6196 static int
6197 ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
6198                                 enum rte_filter_op filter_op,
6199                                 void *arg)
6200 {
6201         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6202         int ret;
6203
6204         MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
6205
6206         if (filter_op == RTE_ETH_FILTER_NOP)
6207                 return 0;
6208
6209         if (arg == NULL) {
6210                 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
6211                             filter_op);
6212                 return -EINVAL;
6213         }
6214
6215         switch (filter_op) {
6216         case RTE_ETH_FILTER_ADD:
6217                 ret = ixgbe_add_del_ntuple_filter(dev,
6218                         (struct rte_eth_ntuple_filter *)arg,
6219                         TRUE);
6220                 break;
6221         case RTE_ETH_FILTER_DELETE:
6222                 ret = ixgbe_add_del_ntuple_filter(dev,
6223                         (struct rte_eth_ntuple_filter *)arg,
6224                         FALSE);
6225                 break;
6226         case RTE_ETH_FILTER_GET:
6227                 ret = ixgbe_get_ntuple_filter(dev,
6228                         (struct rte_eth_ntuple_filter *)arg);
6229                 break;
6230         default:
6231                 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
6232                 ret = -EINVAL;
6233                 break;
6234         }
6235         return ret;
6236 }
6237
6238 int
6239 ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
6240                         struct rte_eth_ethertype_filter *filter,
6241                         bool add)
6242 {
6243         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6244         struct ixgbe_filter_info *filter_info =
6245                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6246         uint32_t etqf = 0;
6247         uint32_t etqs = 0;
6248         int ret;
6249         struct ixgbe_ethertype_filter ethertype_filter;
6250
6251         if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
6252                 return -EINVAL;
6253
6254         if (filter->ether_type == ETHER_TYPE_IPv4 ||
6255                 filter->ether_type == ETHER_TYPE_IPv6) {
6256                 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
6257                         " ethertype filter.", filter->ether_type);
6258                 return -EINVAL;
6259         }
6260
6261         if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
6262                 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
6263                 return -EINVAL;
6264         }
6265         if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
6266                 PMD_DRV_LOG(ERR, "drop option is unsupported.");
6267                 return -EINVAL;
6268         }
6269
6270         ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
6271         if (ret >= 0 && add) {
6272                 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
6273                             filter->ether_type);
6274                 return -EEXIST;
6275         }
6276         if (ret < 0 && !add) {
6277                 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
6278                             filter->ether_type);
6279                 return -ENOENT;
6280         }
6281
6282         if (add) {
6283                 etqf = IXGBE_ETQF_FILTER_EN;
6284                 etqf |= (uint32_t)filter->ether_type;
6285                 etqs |= (uint32_t)((filter->queue <<
6286                                     IXGBE_ETQS_RX_QUEUE_SHIFT) &
6287                                     IXGBE_ETQS_RX_QUEUE);
6288                 etqs |= IXGBE_ETQS_QUEUE_EN;
6289
6290                 ethertype_filter.ethertype = filter->ether_type;
6291                 ethertype_filter.etqf = etqf;
6292                 ethertype_filter.etqs = etqs;
6293                 ethertype_filter.conf = FALSE;
6294                 ret = ixgbe_ethertype_filter_insert(filter_info,
6295                                                     &ethertype_filter);
6296                 if (ret < 0) {
6297                         PMD_DRV_LOG(ERR, "ethertype filters are full.");
6298                         return -ENOSPC;
6299                 }
6300         } else {
6301                 ret = ixgbe_ethertype_filter_remove(filter_info, (uint8_t)ret);
6302                 if (ret < 0)
6303                         return -ENOSYS;
6304         }
6305         IXGBE_WRITE_REG(hw, IXGBE_ETQF(ret), etqf);
6306         IXGBE_WRITE_REG(hw, IXGBE_ETQS(ret), etqs);
6307         IXGBE_WRITE_FLUSH(hw);
6308
6309         return 0;
6310 }
6311
6312 static int
6313 ixgbe_get_ethertype_filter(struct rte_eth_dev *dev,
6314                         struct rte_eth_ethertype_filter *filter)
6315 {
6316         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6317         struct ixgbe_filter_info *filter_info =
6318                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6319         uint32_t etqf, etqs;
6320         int ret;
6321
6322         ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
6323         if (ret < 0) {
6324                 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
6325                             filter->ether_type);
6326                 return -ENOENT;
6327         }
6328
6329         etqf = IXGBE_READ_REG(hw, IXGBE_ETQF(ret));
6330         if (etqf & IXGBE_ETQF_FILTER_EN) {
6331                 etqs = IXGBE_READ_REG(hw, IXGBE_ETQS(ret));
6332                 filter->ether_type = etqf & IXGBE_ETQF_ETHERTYPE;
6333                 filter->flags = 0;
6334                 filter->queue = (etqs & IXGBE_ETQS_RX_QUEUE) >>
6335                                IXGBE_ETQS_RX_QUEUE_SHIFT;
6336                 return 0;
6337         }
6338         return -ENOENT;
6339 }
6340
6341 /*
6342  * ixgbe_ethertype_filter_handle - Handle operations for ethertype filter.
6343  * @dev: pointer to rte_eth_dev structure
6344  * @filter_op:operation will be taken.
6345  * @arg: a pointer to specific structure corresponding to the filter_op
6346  */
6347 static int
6348 ixgbe_ethertype_filter_handle(struct rte_eth_dev *dev,
6349                                 enum rte_filter_op filter_op,
6350                                 void *arg)
6351 {
6352         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6353         int ret;
6354
6355         MAC_TYPE_FILTER_SUP(hw->mac.type);
6356
6357         if (filter_op == RTE_ETH_FILTER_NOP)
6358                 return 0;
6359
6360         if (arg == NULL) {
6361                 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
6362                             filter_op);
6363                 return -EINVAL;
6364         }
6365
6366         switch (filter_op) {
6367         case RTE_ETH_FILTER_ADD:
6368                 ret = ixgbe_add_del_ethertype_filter(dev,
6369                         (struct rte_eth_ethertype_filter *)arg,
6370                         TRUE);
6371                 break;
6372         case RTE_ETH_FILTER_DELETE:
6373                 ret = ixgbe_add_del_ethertype_filter(dev,
6374                         (struct rte_eth_ethertype_filter *)arg,
6375                         FALSE);
6376                 break;
6377         case RTE_ETH_FILTER_GET:
6378                 ret = ixgbe_get_ethertype_filter(dev,
6379                         (struct rte_eth_ethertype_filter *)arg);
6380                 break;
6381         default:
6382                 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
6383                 ret = -EINVAL;
6384                 break;
6385         }
6386         return ret;
6387 }
6388
6389 static int
6390 ixgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
6391                      enum rte_filter_type filter_type,
6392                      enum rte_filter_op filter_op,
6393                      void *arg)
6394 {
6395         int ret = 0;
6396
6397         switch (filter_type) {
6398         case RTE_ETH_FILTER_NTUPLE:
6399                 ret = ixgbe_ntuple_filter_handle(dev, filter_op, arg);
6400                 break;
6401         case RTE_ETH_FILTER_ETHERTYPE:
6402                 ret = ixgbe_ethertype_filter_handle(dev, filter_op, arg);
6403                 break;
6404         case RTE_ETH_FILTER_SYN:
6405                 ret = ixgbe_syn_filter_handle(dev, filter_op, arg);
6406                 break;
6407         case RTE_ETH_FILTER_FDIR:
6408                 ret = ixgbe_fdir_ctrl_func(dev, filter_op, arg);
6409                 break;
6410         case RTE_ETH_FILTER_L2_TUNNEL:
6411                 ret = ixgbe_dev_l2_tunnel_filter_handle(dev, filter_op, arg);
6412                 break;
6413         case RTE_ETH_FILTER_GENERIC:
6414                 if (filter_op != RTE_ETH_FILTER_GET)
6415                         return -EINVAL;
6416                 *(const void **)arg = &ixgbe_flow_ops;
6417                 break;
6418         default:
6419                 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
6420                                                         filter_type);
6421                 ret = -EINVAL;
6422                 break;
6423         }
6424
6425         return ret;
6426 }
6427
6428 static u8 *
6429 ixgbe_dev_addr_list_itr(__attribute__((unused)) struct ixgbe_hw *hw,
6430                         u8 **mc_addr_ptr, u32 *vmdq)
6431 {
6432         u8 *mc_addr;
6433
6434         *vmdq = 0;
6435         mc_addr = *mc_addr_ptr;
6436         *mc_addr_ptr = (mc_addr + sizeof(struct ether_addr));
6437         return mc_addr;
6438 }
6439
6440 static int
6441 ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
6442                           struct ether_addr *mc_addr_set,
6443                           uint32_t nb_mc_addr)
6444 {
6445         struct ixgbe_hw *hw;
6446         u8 *mc_addr_list;
6447
6448         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6449         mc_addr_list = (u8 *)mc_addr_set;
6450         return ixgbe_update_mc_addr_list(hw, mc_addr_list, nb_mc_addr,
6451                                          ixgbe_dev_addr_list_itr, TRUE);
6452 }
6453
6454 static uint64_t
6455 ixgbe_read_systime_cyclecounter(struct rte_eth_dev *dev)
6456 {
6457         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6458         uint64_t systime_cycles;
6459
6460         switch (hw->mac.type) {
6461         case ixgbe_mac_X550:
6462         case ixgbe_mac_X550EM_x:
6463         case ixgbe_mac_X550EM_a:
6464                 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
6465                 systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
6466                 systime_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
6467                                 * NSEC_PER_SEC;
6468                 break;
6469         default:
6470                 systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
6471                 systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
6472                                 << 32;
6473         }
6474
6475         return systime_cycles;
6476 }
6477
6478 static uint64_t
6479 ixgbe_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
6480 {
6481         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6482         uint64_t rx_tstamp_cycles;
6483
6484         switch (hw->mac.type) {
6485         case ixgbe_mac_X550:
6486         case ixgbe_mac_X550EM_x:
6487         case ixgbe_mac_X550EM_a:
6488                 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
6489                 rx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
6490                 rx_tstamp_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPH)
6491                                 * NSEC_PER_SEC;
6492                 break;
6493         default:
6494                 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
6495                 rx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
6496                 rx_tstamp_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPH)
6497                                 << 32;
6498         }
6499
6500         return rx_tstamp_cycles;
6501 }
6502
6503 static uint64_t
6504 ixgbe_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
6505 {
6506         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6507         uint64_t tx_tstamp_cycles;
6508
6509         switch (hw->mac.type) {
6510         case ixgbe_mac_X550:
6511         case ixgbe_mac_X550EM_x:
6512         case ixgbe_mac_X550EM_a:
6513                 /* TXSTMPL stores ns and TXSTMPH stores seconds. */
6514                 tx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
6515                 tx_tstamp_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPH)
6516                                 * NSEC_PER_SEC;
6517                 break;
6518         default:
6519                 /* TXSTMPL stores ns and TXSTMPH stores seconds. */
6520                 tx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
6521                 tx_tstamp_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPH)
6522                                 << 32;
6523         }
6524
6525         return tx_tstamp_cycles;
6526 }
6527
6528 static void
6529 ixgbe_start_timecounters(struct rte_eth_dev *dev)
6530 {
6531         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6532         struct ixgbe_adapter *adapter =
6533                 (struct ixgbe_adapter *)dev->data->dev_private;
6534         struct rte_eth_link link;
6535         uint32_t incval = 0;
6536         uint32_t shift = 0;
6537
6538         /* Get current link speed. */
6539         memset(&link, 0, sizeof(link));
6540         ixgbe_dev_link_update(dev, 1);
6541         rte_ixgbe_dev_atomic_read_link_status(dev, &link);
6542
6543         switch (link.link_speed) {
6544         case ETH_SPEED_NUM_100M:
6545                 incval = IXGBE_INCVAL_100;
6546                 shift = IXGBE_INCVAL_SHIFT_100;
6547                 break;
6548         case ETH_SPEED_NUM_1G:
6549                 incval = IXGBE_INCVAL_1GB;
6550                 shift = IXGBE_INCVAL_SHIFT_1GB;
6551                 break;
6552         case ETH_SPEED_NUM_10G:
6553         default:
6554                 incval = IXGBE_INCVAL_10GB;
6555                 shift = IXGBE_INCVAL_SHIFT_10GB;
6556                 break;
6557         }
6558
6559         switch (hw->mac.type) {
6560         case ixgbe_mac_X550:
6561         case ixgbe_mac_X550EM_x:
6562         case ixgbe_mac_X550EM_a:
6563                 /* Independent of link speed. */
6564                 incval = 1;
6565                 /* Cycles read will be interpreted as ns. */
6566                 shift = 0;
6567                 /* Fall-through */
6568         case ixgbe_mac_X540:
6569                 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, incval);
6570                 break;
6571         case ixgbe_mac_82599EB:
6572                 incval >>= IXGBE_INCVAL_SHIFT_82599;
6573                 shift -= IXGBE_INCVAL_SHIFT_82599;
6574                 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA,
6575                                 (1 << IXGBE_INCPER_SHIFT_82599) | incval);
6576                 break;
6577         default:
6578                 /* Not supported. */
6579                 return;
6580         }
6581
6582         memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
6583         memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
6584         memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
6585
6586         adapter->systime_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
6587         adapter->systime_tc.cc_shift = shift;
6588         adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
6589
6590         adapter->rx_tstamp_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
6591         adapter->rx_tstamp_tc.cc_shift = shift;
6592         adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
6593
6594         adapter->tx_tstamp_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
6595         adapter->tx_tstamp_tc.cc_shift = shift;
6596         adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
6597 }
6598
6599 static int
6600 ixgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
6601 {
6602         struct ixgbe_adapter *adapter =
6603                         (struct ixgbe_adapter *)dev->data->dev_private;
6604
6605         adapter->systime_tc.nsec += delta;
6606         adapter->rx_tstamp_tc.nsec += delta;
6607         adapter->tx_tstamp_tc.nsec += delta;
6608
6609         return 0;
6610 }
6611
6612 static int
6613 ixgbe_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
6614 {
6615         uint64_t ns;
6616         struct ixgbe_adapter *adapter =
6617                         (struct ixgbe_adapter *)dev->data->dev_private;
6618
6619         ns = rte_timespec_to_ns(ts);
6620         /* Set the timecounters to a new value. */
6621         adapter->systime_tc.nsec = ns;
6622         adapter->rx_tstamp_tc.nsec = ns;
6623         adapter->tx_tstamp_tc.nsec = ns;
6624
6625         return 0;
6626 }
6627
6628 static int
6629 ixgbe_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
6630 {
6631         uint64_t ns, systime_cycles;
6632         struct ixgbe_adapter *adapter =
6633                         (struct ixgbe_adapter *)dev->data->dev_private;
6634
6635         systime_cycles = ixgbe_read_systime_cyclecounter(dev);
6636         ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
6637         *ts = rte_ns_to_timespec(ns);
6638
6639         return 0;
6640 }
6641
6642 static int
6643 ixgbe_timesync_enable(struct rte_eth_dev *dev)
6644 {
6645         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6646         uint32_t tsync_ctl;
6647         uint32_t tsauxc;
6648
6649         /* Stop the timesync system time. */
6650         IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0x0);
6651         /* Reset the timesync system time value. */
6652         IXGBE_WRITE_REG(hw, IXGBE_SYSTIML, 0x0);
6653         IXGBE_WRITE_REG(hw, IXGBE_SYSTIMH, 0x0);
6654
6655         /* Enable system time for platforms where it isn't on by default. */
6656         tsauxc = IXGBE_READ_REG(hw, IXGBE_TSAUXC);
6657         tsauxc &= ~IXGBE_TSAUXC_DISABLE_SYSTIME;
6658         IXGBE_WRITE_REG(hw, IXGBE_TSAUXC, tsauxc);
6659
6660         ixgbe_start_timecounters(dev);
6661
6662         /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
6663         IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588),
6664                         (ETHER_TYPE_1588 |
6665                          IXGBE_ETQF_FILTER_EN |
6666                          IXGBE_ETQF_1588));
6667
6668         /* Enable timestamping of received PTP packets. */
6669         tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
6670         tsync_ctl |= IXGBE_TSYNCRXCTL_ENABLED;
6671         IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
6672
6673         /* Enable timestamping of transmitted PTP packets. */
6674         tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
6675         tsync_ctl |= IXGBE_TSYNCTXCTL_ENABLED;
6676         IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
6677
6678         IXGBE_WRITE_FLUSH(hw);
6679
6680         return 0;
6681 }
6682
6683 static int
6684 ixgbe_timesync_disable(struct rte_eth_dev *dev)
6685 {
6686         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6687         uint32_t tsync_ctl;
6688
6689         /* Disable timestamping of transmitted PTP packets. */
6690         tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
6691         tsync_ctl &= ~IXGBE_TSYNCTXCTL_ENABLED;
6692         IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
6693
6694         /* Disable timestamping of received PTP packets. */
6695         tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
6696         tsync_ctl &= ~IXGBE_TSYNCRXCTL_ENABLED;
6697         IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
6698
6699         /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
6700         IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588), 0);
6701
6702         /* Stop incrementating the System Time registers. */
6703         IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0);
6704
6705         return 0;
6706 }
6707
6708 static int
6709 ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
6710                                  struct timespec *timestamp,
6711                                  uint32_t flags __rte_unused)
6712 {
6713         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6714         struct ixgbe_adapter *adapter =
6715                 (struct ixgbe_adapter *)dev->data->dev_private;
6716         uint32_t tsync_rxctl;
6717         uint64_t rx_tstamp_cycles;
6718         uint64_t ns;
6719
6720         tsync_rxctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
6721         if ((tsync_rxctl & IXGBE_TSYNCRXCTL_VALID) == 0)
6722                 return -EINVAL;
6723
6724         rx_tstamp_cycles = ixgbe_read_rx_tstamp_cyclecounter(dev);
6725         ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
6726         *timestamp = rte_ns_to_timespec(ns);
6727
6728         return  0;
6729 }
6730
6731 static int
6732 ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
6733                                  struct timespec *timestamp)
6734 {
6735         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6736         struct ixgbe_adapter *adapter =
6737                 (struct ixgbe_adapter *)dev->data->dev_private;
6738         uint32_t tsync_txctl;
6739         uint64_t tx_tstamp_cycles;
6740         uint64_t ns;
6741
6742         tsync_txctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
6743         if ((tsync_txctl & IXGBE_TSYNCTXCTL_VALID) == 0)
6744                 return -EINVAL;
6745
6746         tx_tstamp_cycles = ixgbe_read_tx_tstamp_cyclecounter(dev);
6747         ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
6748         *timestamp = rte_ns_to_timespec(ns);
6749
6750         return 0;
6751 }
6752
6753 static int
6754 ixgbe_get_reg_length(struct rte_eth_dev *dev)
6755 {
6756         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6757         int count = 0;
6758         int g_ind = 0;
6759         const struct reg_info *reg_group;
6760         const struct reg_info **reg_set = (hw->mac.type == ixgbe_mac_82598EB) ?
6761                                     ixgbe_regs_mac_82598EB : ixgbe_regs_others;
6762
6763         while ((reg_group = reg_set[g_ind++]))
6764                 count += ixgbe_regs_group_count(reg_group);
6765
6766         return count;
6767 }
6768
6769 static int
6770 ixgbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
6771 {
6772         int count = 0;
6773         int g_ind = 0;
6774         const struct reg_info *reg_group;
6775
6776         while ((reg_group = ixgbevf_regs[g_ind++]))
6777                 count += ixgbe_regs_group_count(reg_group);
6778
6779         return count;
6780 }
6781
6782 static int
6783 ixgbe_get_regs(struct rte_eth_dev *dev,
6784               struct rte_dev_reg_info *regs)
6785 {
6786         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6787         uint32_t *data = regs->data;
6788         int g_ind = 0;
6789         int count = 0;
6790         const struct reg_info *reg_group;
6791         const struct reg_info **reg_set = (hw->mac.type == ixgbe_mac_82598EB) ?
6792                                     ixgbe_regs_mac_82598EB : ixgbe_regs_others;
6793
6794         if (data == NULL) {
6795                 regs->length = ixgbe_get_reg_length(dev);
6796                 regs->width = sizeof(uint32_t);
6797                 return 0;
6798         }
6799
6800         /* Support only full register dump */
6801         if ((regs->length == 0) ||
6802             (regs->length == (uint32_t)ixgbe_get_reg_length(dev))) {
6803                 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
6804                         hw->device_id;
6805                 while ((reg_group = reg_set[g_ind++]))
6806                         count += ixgbe_read_regs_group(dev, &data[count],
6807                                 reg_group);
6808                 return 0;
6809         }
6810
6811         return -ENOTSUP;
6812 }
6813
6814 static int
6815 ixgbevf_get_regs(struct rte_eth_dev *dev,
6816                 struct rte_dev_reg_info *regs)
6817 {
6818         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6819         uint32_t *data = regs->data;
6820         int g_ind = 0;
6821         int count = 0;
6822         const struct reg_info *reg_group;
6823
6824         if (data == NULL) {
6825                 regs->length = ixgbevf_get_reg_length(dev);
6826                 regs->width = sizeof(uint32_t);
6827                 return 0;
6828         }
6829
6830         /* Support only full register dump */
6831         if ((regs->length == 0) ||
6832             (regs->length == (uint32_t)ixgbevf_get_reg_length(dev))) {
6833                 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
6834                         hw->device_id;
6835                 while ((reg_group = ixgbevf_regs[g_ind++]))
6836                         count += ixgbe_read_regs_group(dev, &data[count],
6837                                                       reg_group);
6838                 return 0;
6839         }
6840
6841         return -ENOTSUP;
6842 }
6843
6844 static int
6845 ixgbe_get_eeprom_length(struct rte_eth_dev *dev)
6846 {
6847         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6848
6849         /* Return unit is byte count */
6850         return hw->eeprom.word_size * 2;
6851 }
6852
6853 static int
6854 ixgbe_get_eeprom(struct rte_eth_dev *dev,
6855                 struct rte_dev_eeprom_info *in_eeprom)
6856 {
6857         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6858         struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
6859         uint16_t *data = in_eeprom->data;
6860         int first, length;
6861
6862         first = in_eeprom->offset >> 1;
6863         length = in_eeprom->length >> 1;
6864         if ((first > hw->eeprom.word_size) ||
6865             ((first + length) > hw->eeprom.word_size))
6866                 return -EINVAL;
6867
6868         in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
6869
6870         return eeprom->ops.read_buffer(hw, first, length, data);
6871 }
6872
6873 static int
6874 ixgbe_set_eeprom(struct rte_eth_dev *dev,
6875                 struct rte_dev_eeprom_info *in_eeprom)
6876 {
6877         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6878         struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
6879         uint16_t *data = in_eeprom->data;
6880         int first, length;
6881
6882         first = in_eeprom->offset >> 1;
6883         length = in_eeprom->length >> 1;
6884         if ((first > hw->eeprom.word_size) ||
6885             ((first + length) > hw->eeprom.word_size))
6886                 return -EINVAL;
6887
6888         in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
6889
6890         return eeprom->ops.write_buffer(hw,  first, length, data);
6891 }
6892
6893 uint16_t
6894 ixgbe_reta_size_get(enum ixgbe_mac_type mac_type) {
6895         switch (mac_type) {
6896         case ixgbe_mac_X550:
6897         case ixgbe_mac_X550EM_x:
6898         case ixgbe_mac_X550EM_a:
6899                 return ETH_RSS_RETA_SIZE_512;
6900         case ixgbe_mac_X550_vf:
6901         case ixgbe_mac_X550EM_x_vf:
6902         case ixgbe_mac_X550EM_a_vf:
6903                 return ETH_RSS_RETA_SIZE_64;
6904         default:
6905                 return ETH_RSS_RETA_SIZE_128;
6906         }
6907 }
6908
6909 uint32_t
6910 ixgbe_reta_reg_get(enum ixgbe_mac_type mac_type, uint16_t reta_idx) {
6911         switch (mac_type) {
6912         case ixgbe_mac_X550:
6913         case ixgbe_mac_X550EM_x:
6914         case ixgbe_mac_X550EM_a:
6915                 if (reta_idx < ETH_RSS_RETA_SIZE_128)
6916                         return IXGBE_RETA(reta_idx >> 2);
6917                 else
6918                         return IXGBE_ERETA((reta_idx - ETH_RSS_RETA_SIZE_128) >> 2);
6919         case ixgbe_mac_X550_vf:
6920         case ixgbe_mac_X550EM_x_vf:
6921         case ixgbe_mac_X550EM_a_vf:
6922                 return IXGBE_VFRETA(reta_idx >> 2);
6923         default:
6924                 return IXGBE_RETA(reta_idx >> 2);
6925         }
6926 }
6927
6928 uint32_t
6929 ixgbe_mrqc_reg_get(enum ixgbe_mac_type mac_type) {
6930         switch (mac_type) {
6931         case ixgbe_mac_X550_vf:
6932         case ixgbe_mac_X550EM_x_vf:
6933         case ixgbe_mac_X550EM_a_vf:
6934                 return IXGBE_VFMRQC;
6935         default:
6936                 return IXGBE_MRQC;
6937         }
6938 }
6939
6940 uint32_t
6941 ixgbe_rssrk_reg_get(enum ixgbe_mac_type mac_type, uint8_t i) {
6942         switch (mac_type) {
6943         case ixgbe_mac_X550_vf:
6944         case ixgbe_mac_X550EM_x_vf:
6945         case ixgbe_mac_X550EM_a_vf:
6946                 return IXGBE_VFRSSRK(i);
6947         default:
6948                 return IXGBE_RSSRK(i);
6949         }
6950 }
6951
6952 bool
6953 ixgbe_rss_update_sp(enum ixgbe_mac_type mac_type) {
6954         switch (mac_type) {
6955         case ixgbe_mac_82599_vf:
6956         case ixgbe_mac_X540_vf:
6957                 return 0;
6958         default:
6959                 return 1;
6960         }
6961 }
6962
6963 static int
6964 ixgbe_dev_get_dcb_info(struct rte_eth_dev *dev,
6965                         struct rte_eth_dcb_info *dcb_info)
6966 {
6967         struct ixgbe_dcb_config *dcb_config =
6968                         IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
6969         struct ixgbe_dcb_tc_config *tc;
6970         uint8_t i, j;
6971
6972         if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
6973                 dcb_info->nb_tcs = dcb_config->num_tcs.pg_tcs;
6974         else
6975                 dcb_info->nb_tcs = 1;
6976
6977         if (dcb_config->vt_mode) { /* vt is enabled*/
6978                 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
6979                                 &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
6980                 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++)
6981                         dcb_info->prio_tc[i] = vmdq_rx_conf->dcb_tc[i];
6982                 for (i = 0; i < vmdq_rx_conf->nb_queue_pools; i++) {
6983                         for (j = 0; j < dcb_info->nb_tcs; j++) {
6984                                 dcb_info->tc_queue.tc_rxq[i][j].base =
6985                                                 i * dcb_info->nb_tcs + j;
6986                                 dcb_info->tc_queue.tc_rxq[i][j].nb_queue = 1;
6987                                 dcb_info->tc_queue.tc_txq[i][j].base =
6988                                                 i * dcb_info->nb_tcs + j;
6989                                 dcb_info->tc_queue.tc_txq[i][j].nb_queue = 1;
6990                         }
6991                 }
6992         } else { /* vt is disabled*/
6993                 struct rte_eth_dcb_rx_conf *rx_conf =
6994                                 &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
6995                 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++)
6996                         dcb_info->prio_tc[i] = rx_conf->dcb_tc[i];
6997                 if (dcb_info->nb_tcs == ETH_4_TCS) {
6998                         for (i = 0; i < dcb_info->nb_tcs; i++) {
6999                                 dcb_info->tc_queue.tc_rxq[0][i].base = i * 32;
7000                                 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 16;
7001                         }
7002                         dcb_info->tc_queue.tc_txq[0][0].base = 0;
7003                         dcb_info->tc_queue.tc_txq[0][1].base = 64;
7004                         dcb_info->tc_queue.tc_txq[0][2].base = 96;
7005                         dcb_info->tc_queue.tc_txq[0][3].base = 112;
7006                         dcb_info->tc_queue.tc_txq[0][0].nb_queue = 64;
7007                         dcb_info->tc_queue.tc_txq[0][1].nb_queue = 32;
7008                         dcb_info->tc_queue.tc_txq[0][2].nb_queue = 16;
7009                         dcb_info->tc_queue.tc_txq[0][3].nb_queue = 16;
7010                 } else if (dcb_info->nb_tcs == ETH_8_TCS) {
7011                         for (i = 0; i < dcb_info->nb_tcs; i++) {
7012                                 dcb_info->tc_queue.tc_rxq[0][i].base = i * 16;
7013                                 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 16;
7014                         }
7015                         dcb_info->tc_queue.tc_txq[0][0].base = 0;
7016                         dcb_info->tc_queue.tc_txq[0][1].base = 32;
7017                         dcb_info->tc_queue.tc_txq[0][2].base = 64;
7018                         dcb_info->tc_queue.tc_txq[0][3].base = 80;
7019                         dcb_info->tc_queue.tc_txq[0][4].base = 96;
7020                         dcb_info->tc_queue.tc_txq[0][5].base = 104;
7021                         dcb_info->tc_queue.tc_txq[0][6].base = 112;
7022                         dcb_info->tc_queue.tc_txq[0][7].base = 120;
7023                         dcb_info->tc_queue.tc_txq[0][0].nb_queue = 32;
7024                         dcb_info->tc_queue.tc_txq[0][1].nb_queue = 32;
7025                         dcb_info->tc_queue.tc_txq[0][2].nb_queue = 16;
7026                         dcb_info->tc_queue.tc_txq[0][3].nb_queue = 16;
7027                         dcb_info->tc_queue.tc_txq[0][4].nb_queue = 8;
7028                         dcb_info->tc_queue.tc_txq[0][5].nb_queue = 8;
7029                         dcb_info->tc_queue.tc_txq[0][6].nb_queue = 8;
7030                         dcb_info->tc_queue.tc_txq[0][7].nb_queue = 8;
7031                 }
7032         }
7033         for (i = 0; i < dcb_info->nb_tcs; i++) {
7034                 tc = &dcb_config->tc_config[i];
7035                 dcb_info->tc_bws[i] = tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent;
7036         }
7037         return 0;
7038 }
7039
7040 /* Update e-tag ether type */
7041 static int
7042 ixgbe_update_e_tag_eth_type(struct ixgbe_hw *hw,
7043                             uint16_t ether_type)
7044 {
7045         uint32_t etag_etype;
7046
7047         if (hw->mac.type != ixgbe_mac_X550 &&
7048             hw->mac.type != ixgbe_mac_X550EM_x &&
7049             hw->mac.type != ixgbe_mac_X550EM_a) {
7050                 return -ENOTSUP;
7051         }
7052
7053         etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
7054         etag_etype &= ~IXGBE_ETAG_ETYPE_MASK;
7055         etag_etype |= ether_type;
7056         IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
7057         IXGBE_WRITE_FLUSH(hw);
7058
7059         return 0;
7060 }
7061
7062 /* Config l2 tunnel ether type */
7063 static int
7064 ixgbe_dev_l2_tunnel_eth_type_conf(struct rte_eth_dev *dev,
7065                                   struct rte_eth_l2_tunnel_conf *l2_tunnel)
7066 {
7067         int ret = 0;
7068         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7069         struct ixgbe_l2_tn_info *l2_tn_info =
7070                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
7071
7072         if (l2_tunnel == NULL)
7073                 return -EINVAL;
7074
7075         switch (l2_tunnel->l2_tunnel_type) {
7076         case RTE_L2_TUNNEL_TYPE_E_TAG:
7077                 l2_tn_info->e_tag_ether_type = l2_tunnel->ether_type;
7078                 ret = ixgbe_update_e_tag_eth_type(hw, l2_tunnel->ether_type);
7079                 break;
7080         default:
7081                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7082                 ret = -EINVAL;
7083                 break;
7084         }
7085
7086         return ret;
7087 }
7088
7089 /* Enable e-tag tunnel */
7090 static int
7091 ixgbe_e_tag_enable(struct ixgbe_hw *hw)
7092 {
7093         uint32_t etag_etype;
7094
7095         if (hw->mac.type != ixgbe_mac_X550 &&
7096             hw->mac.type != ixgbe_mac_X550EM_x &&
7097             hw->mac.type != ixgbe_mac_X550EM_a) {
7098                 return -ENOTSUP;
7099         }
7100
7101         etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
7102         etag_etype |= IXGBE_ETAG_ETYPE_VALID;
7103         IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
7104         IXGBE_WRITE_FLUSH(hw);
7105
7106         return 0;
7107 }
7108
7109 /* Enable l2 tunnel */
7110 static int
7111 ixgbe_dev_l2_tunnel_enable(struct rte_eth_dev *dev,
7112                            enum rte_eth_tunnel_type l2_tunnel_type)
7113 {
7114         int ret = 0;
7115         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7116         struct ixgbe_l2_tn_info *l2_tn_info =
7117                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
7118
7119         switch (l2_tunnel_type) {
7120         case RTE_L2_TUNNEL_TYPE_E_TAG:
7121                 l2_tn_info->e_tag_en = TRUE;
7122                 ret = ixgbe_e_tag_enable(hw);
7123                 break;
7124         default:
7125                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7126                 ret = -EINVAL;
7127                 break;
7128         }
7129
7130         return ret;
7131 }
7132
7133 /* Disable e-tag tunnel */
7134 static int
7135 ixgbe_e_tag_disable(struct ixgbe_hw *hw)
7136 {
7137         uint32_t etag_etype;
7138
7139         if (hw->mac.type != ixgbe_mac_X550 &&
7140             hw->mac.type != ixgbe_mac_X550EM_x &&
7141             hw->mac.type != ixgbe_mac_X550EM_a) {
7142                 return -ENOTSUP;
7143         }
7144
7145         etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
7146         etag_etype &= ~IXGBE_ETAG_ETYPE_VALID;
7147         IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
7148         IXGBE_WRITE_FLUSH(hw);
7149
7150         return 0;
7151 }
7152
7153 /* Disable l2 tunnel */
7154 static int
7155 ixgbe_dev_l2_tunnel_disable(struct rte_eth_dev *dev,
7156                             enum rte_eth_tunnel_type l2_tunnel_type)
7157 {
7158         int ret = 0;
7159         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7160         struct ixgbe_l2_tn_info *l2_tn_info =
7161                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
7162
7163         switch (l2_tunnel_type) {
7164         case RTE_L2_TUNNEL_TYPE_E_TAG:
7165                 l2_tn_info->e_tag_en = FALSE;
7166                 ret = ixgbe_e_tag_disable(hw);
7167                 break;
7168         default:
7169                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7170                 ret = -EINVAL;
7171                 break;
7172         }
7173
7174         return ret;
7175 }
7176
7177 static int
7178 ixgbe_e_tag_filter_del(struct rte_eth_dev *dev,
7179                        struct rte_eth_l2_tunnel_conf *l2_tunnel)
7180 {
7181         int ret = 0;
7182         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7183         uint32_t i, rar_entries;
7184         uint32_t rar_low, rar_high;
7185
7186         if (hw->mac.type != ixgbe_mac_X550 &&
7187             hw->mac.type != ixgbe_mac_X550EM_x &&
7188             hw->mac.type != ixgbe_mac_X550EM_a) {
7189                 return -ENOTSUP;
7190         }
7191
7192         rar_entries = ixgbe_get_num_rx_addrs(hw);
7193
7194         for (i = 1; i < rar_entries; i++) {
7195                 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(i));
7196                 rar_low  = IXGBE_READ_REG(hw, IXGBE_RAL(i));
7197                 if ((rar_high & IXGBE_RAH_AV) &&
7198                     (rar_high & IXGBE_RAH_ADTYPE) &&
7199                     ((rar_low & IXGBE_RAL_ETAG_FILTER_MASK) ==
7200                      l2_tunnel->tunnel_id)) {
7201                         IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
7202                         IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
7203
7204                         ixgbe_clear_vmdq(hw, i, IXGBE_CLEAR_VMDQ_ALL);
7205
7206                         return ret;
7207                 }
7208         }
7209
7210         return ret;
7211 }
7212
7213 static int
7214 ixgbe_e_tag_filter_add(struct rte_eth_dev *dev,
7215                        struct rte_eth_l2_tunnel_conf *l2_tunnel)
7216 {
7217         int ret = 0;
7218         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7219         uint32_t i, rar_entries;
7220         uint32_t rar_low, rar_high;
7221
7222         if (hw->mac.type != ixgbe_mac_X550 &&
7223             hw->mac.type != ixgbe_mac_X550EM_x &&
7224             hw->mac.type != ixgbe_mac_X550EM_a) {
7225                 return -ENOTSUP;
7226         }
7227
7228         /* One entry for one tunnel. Try to remove potential existing entry. */
7229         ixgbe_e_tag_filter_del(dev, l2_tunnel);
7230
7231         rar_entries = ixgbe_get_num_rx_addrs(hw);
7232
7233         for (i = 1; i < rar_entries; i++) {
7234                 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(i));
7235                 if (rar_high & IXGBE_RAH_AV) {
7236                         continue;
7237                 } else {
7238                         ixgbe_set_vmdq(hw, i, l2_tunnel->pool);
7239                         rar_high = IXGBE_RAH_AV | IXGBE_RAH_ADTYPE;
7240                         rar_low = l2_tunnel->tunnel_id;
7241
7242                         IXGBE_WRITE_REG(hw, IXGBE_RAL(i), rar_low);
7243                         IXGBE_WRITE_REG(hw, IXGBE_RAH(i), rar_high);
7244
7245                         return ret;
7246                 }
7247         }
7248
7249         PMD_INIT_LOG(NOTICE, "The table of E-tag forwarding rule is full."
7250                      " Please remove a rule before adding a new one.");
7251         return -EINVAL;
7252 }
7253
7254 static inline struct ixgbe_l2_tn_filter *
7255 ixgbe_l2_tn_filter_lookup(struct ixgbe_l2_tn_info *l2_tn_info,
7256                           struct ixgbe_l2_tn_key *key)
7257 {
7258         int ret;
7259
7260         ret = rte_hash_lookup(l2_tn_info->hash_handle, (const void *)key);
7261         if (ret < 0)
7262                 return NULL;
7263
7264         return l2_tn_info->hash_map[ret];
7265 }
7266
7267 static inline int
7268 ixgbe_insert_l2_tn_filter(struct ixgbe_l2_tn_info *l2_tn_info,
7269                           struct ixgbe_l2_tn_filter *l2_tn_filter)
7270 {
7271         int ret;
7272
7273         ret = rte_hash_add_key(l2_tn_info->hash_handle,
7274                                &l2_tn_filter->key);
7275
7276         if (ret < 0) {
7277                 PMD_DRV_LOG(ERR,
7278                             "Failed to insert L2 tunnel filter"
7279                             " to hash table %d!",
7280                             ret);
7281                 return ret;
7282         }
7283
7284         l2_tn_info->hash_map[ret] = l2_tn_filter;
7285
7286         TAILQ_INSERT_TAIL(&l2_tn_info->l2_tn_list, l2_tn_filter, entries);
7287
7288         return 0;
7289 }
7290
7291 static inline int
7292 ixgbe_remove_l2_tn_filter(struct ixgbe_l2_tn_info *l2_tn_info,
7293                           struct ixgbe_l2_tn_key *key)
7294 {
7295         int ret;
7296         struct ixgbe_l2_tn_filter *l2_tn_filter;
7297
7298         ret = rte_hash_del_key(l2_tn_info->hash_handle, key);
7299
7300         if (ret < 0) {
7301                 PMD_DRV_LOG(ERR,
7302                             "No such L2 tunnel filter to delete %d!",
7303                             ret);
7304                 return ret;
7305         }
7306
7307         l2_tn_filter = l2_tn_info->hash_map[ret];
7308         l2_tn_info->hash_map[ret] = NULL;
7309
7310         TAILQ_REMOVE(&l2_tn_info->l2_tn_list, l2_tn_filter, entries);
7311         rte_free(l2_tn_filter);
7312
7313         return 0;
7314 }
7315
7316 /* Add l2 tunnel filter */
7317 int
7318 ixgbe_dev_l2_tunnel_filter_add(struct rte_eth_dev *dev,
7319                                struct rte_eth_l2_tunnel_conf *l2_tunnel,
7320                                bool restore)
7321 {
7322         int ret;
7323         struct ixgbe_l2_tn_info *l2_tn_info =
7324                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
7325         struct ixgbe_l2_tn_key key;
7326         struct ixgbe_l2_tn_filter *node;
7327
7328         if (!restore) {
7329                 key.l2_tn_type = l2_tunnel->l2_tunnel_type;
7330                 key.tn_id = l2_tunnel->tunnel_id;
7331
7332                 node = ixgbe_l2_tn_filter_lookup(l2_tn_info, &key);
7333
7334                 if (node) {
7335                         PMD_DRV_LOG(ERR,
7336                                     "The L2 tunnel filter already exists!");
7337                         return -EINVAL;
7338                 }
7339
7340                 node = rte_zmalloc("ixgbe_l2_tn",
7341                                    sizeof(struct ixgbe_l2_tn_filter),
7342                                    0);
7343                 if (!node)
7344                         return -ENOMEM;
7345
7346                 (void)rte_memcpy(&node->key,
7347                                  &key,
7348                                  sizeof(struct ixgbe_l2_tn_key));
7349                 node->pool = l2_tunnel->pool;
7350                 ret = ixgbe_insert_l2_tn_filter(l2_tn_info, node);
7351                 if (ret < 0) {
7352                         rte_free(node);
7353                         return ret;
7354                 }
7355         }
7356
7357         switch (l2_tunnel->l2_tunnel_type) {
7358         case RTE_L2_TUNNEL_TYPE_E_TAG:
7359                 ret = ixgbe_e_tag_filter_add(dev, l2_tunnel);
7360                 break;
7361         default:
7362                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7363                 ret = -EINVAL;
7364                 break;
7365         }
7366
7367         if ((!restore) && (ret < 0))
7368                 (void)ixgbe_remove_l2_tn_filter(l2_tn_info, &key);
7369
7370         return ret;
7371 }
7372
7373 /* Delete l2 tunnel filter */
7374 int
7375 ixgbe_dev_l2_tunnel_filter_del(struct rte_eth_dev *dev,
7376                                struct rte_eth_l2_tunnel_conf *l2_tunnel)
7377 {
7378         int ret;
7379         struct ixgbe_l2_tn_info *l2_tn_info =
7380                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
7381         struct ixgbe_l2_tn_key key;
7382
7383         key.l2_tn_type = l2_tunnel->l2_tunnel_type;
7384         key.tn_id = l2_tunnel->tunnel_id;
7385         ret = ixgbe_remove_l2_tn_filter(l2_tn_info, &key);
7386         if (ret < 0)
7387                 return ret;
7388
7389         switch (l2_tunnel->l2_tunnel_type) {
7390         case RTE_L2_TUNNEL_TYPE_E_TAG:
7391                 ret = ixgbe_e_tag_filter_del(dev, l2_tunnel);
7392                 break;
7393         default:
7394                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7395                 ret = -EINVAL;
7396                 break;
7397         }
7398
7399         return ret;
7400 }
7401
7402 /**
7403  * ixgbe_dev_l2_tunnel_filter_handle - Handle operations for l2 tunnel filter.
7404  * @dev: pointer to rte_eth_dev structure
7405  * @filter_op:operation will be taken.
7406  * @arg: a pointer to specific structure corresponding to the filter_op
7407  */
7408 static int
7409 ixgbe_dev_l2_tunnel_filter_handle(struct rte_eth_dev *dev,
7410                                   enum rte_filter_op filter_op,
7411                                   void *arg)
7412 {
7413         int ret;
7414
7415         if (filter_op == RTE_ETH_FILTER_NOP)
7416                 return 0;
7417
7418         if (arg == NULL) {
7419                 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
7420                             filter_op);
7421                 return -EINVAL;
7422         }
7423
7424         switch (filter_op) {
7425         case RTE_ETH_FILTER_ADD:
7426                 ret = ixgbe_dev_l2_tunnel_filter_add
7427                         (dev,
7428                          (struct rte_eth_l2_tunnel_conf *)arg,
7429                          FALSE);
7430                 break;
7431         case RTE_ETH_FILTER_DELETE:
7432                 ret = ixgbe_dev_l2_tunnel_filter_del
7433                         (dev,
7434                          (struct rte_eth_l2_tunnel_conf *)arg);
7435                 break;
7436         default:
7437                 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
7438                 ret = -EINVAL;
7439                 break;
7440         }
7441         return ret;
7442 }
7443
7444 static int
7445 ixgbe_e_tag_forwarding_en_dis(struct rte_eth_dev *dev, bool en)
7446 {
7447         int ret = 0;
7448         uint32_t ctrl;
7449         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7450
7451         if (hw->mac.type != ixgbe_mac_X550 &&
7452             hw->mac.type != ixgbe_mac_X550EM_x &&
7453             hw->mac.type != ixgbe_mac_X550EM_a) {
7454                 return -ENOTSUP;
7455         }
7456
7457         ctrl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
7458         ctrl &= ~IXGBE_VT_CTL_POOLING_MODE_MASK;
7459         if (en)
7460                 ctrl |= IXGBE_VT_CTL_POOLING_MODE_ETAG;
7461         IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, ctrl);
7462
7463         return ret;
7464 }
7465
7466 /* Enable l2 tunnel forwarding */
7467 static int
7468 ixgbe_dev_l2_tunnel_forwarding_enable
7469         (struct rte_eth_dev *dev,
7470          enum rte_eth_tunnel_type l2_tunnel_type)
7471 {
7472         struct ixgbe_l2_tn_info *l2_tn_info =
7473                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
7474         int ret = 0;
7475
7476         switch (l2_tunnel_type) {
7477         case RTE_L2_TUNNEL_TYPE_E_TAG:
7478                 l2_tn_info->e_tag_fwd_en = TRUE;
7479                 ret = ixgbe_e_tag_forwarding_en_dis(dev, 1);
7480                 break;
7481         default:
7482                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7483                 ret = -EINVAL;
7484                 break;
7485         }
7486
7487         return ret;
7488 }
7489
7490 /* Disable l2 tunnel forwarding */
7491 static int
7492 ixgbe_dev_l2_tunnel_forwarding_disable
7493         (struct rte_eth_dev *dev,
7494          enum rte_eth_tunnel_type l2_tunnel_type)
7495 {
7496         struct ixgbe_l2_tn_info *l2_tn_info =
7497                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
7498         int ret = 0;
7499
7500         switch (l2_tunnel_type) {
7501         case RTE_L2_TUNNEL_TYPE_E_TAG:
7502                 l2_tn_info->e_tag_fwd_en = FALSE;
7503                 ret = ixgbe_e_tag_forwarding_en_dis(dev, 0);
7504                 break;
7505         default:
7506                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7507                 ret = -EINVAL;
7508                 break;
7509         }
7510
7511         return ret;
7512 }
7513
7514 static int
7515 ixgbe_e_tag_insertion_en_dis(struct rte_eth_dev *dev,
7516                              struct rte_eth_l2_tunnel_conf *l2_tunnel,
7517                              bool en)
7518 {
7519         struct rte_pci_device *pci_dev = IXGBE_DEV_TO_PCI(dev);
7520         int ret = 0;
7521         uint32_t vmtir, vmvir;
7522         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7523
7524         if (l2_tunnel->vf_id >= pci_dev->max_vfs) {
7525                 PMD_DRV_LOG(ERR,
7526                             "VF id %u should be less than %u",
7527                             l2_tunnel->vf_id,
7528                             pci_dev->max_vfs);
7529                 return -EINVAL;
7530         }
7531
7532         if (hw->mac.type != ixgbe_mac_X550 &&
7533             hw->mac.type != ixgbe_mac_X550EM_x &&
7534             hw->mac.type != ixgbe_mac_X550EM_a) {
7535                 return -ENOTSUP;
7536         }
7537
7538         if (en)
7539                 vmtir = l2_tunnel->tunnel_id;
7540         else
7541                 vmtir = 0;
7542
7543         IXGBE_WRITE_REG(hw, IXGBE_VMTIR(l2_tunnel->vf_id), vmtir);
7544
7545         vmvir = IXGBE_READ_REG(hw, IXGBE_VMVIR(l2_tunnel->vf_id));
7546         vmvir &= ~IXGBE_VMVIR_TAGA_MASK;
7547         if (en)
7548                 vmvir |= IXGBE_VMVIR_TAGA_ETAG_INSERT;
7549         IXGBE_WRITE_REG(hw, IXGBE_VMVIR(l2_tunnel->vf_id), vmvir);
7550
7551         return ret;
7552 }
7553
7554 /* Enable l2 tunnel tag insertion */
7555 static int
7556 ixgbe_dev_l2_tunnel_insertion_enable(struct rte_eth_dev *dev,
7557                                      struct rte_eth_l2_tunnel_conf *l2_tunnel)
7558 {
7559         int ret = 0;
7560
7561         switch (l2_tunnel->l2_tunnel_type) {
7562         case RTE_L2_TUNNEL_TYPE_E_TAG:
7563                 ret = ixgbe_e_tag_insertion_en_dis(dev, l2_tunnel, 1);
7564                 break;
7565         default:
7566                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7567                 ret = -EINVAL;
7568                 break;
7569         }
7570
7571         return ret;
7572 }
7573
7574 /* Disable l2 tunnel tag insertion */
7575 static int
7576 ixgbe_dev_l2_tunnel_insertion_disable
7577         (struct rte_eth_dev *dev,
7578          struct rte_eth_l2_tunnel_conf *l2_tunnel)
7579 {
7580         int ret = 0;
7581
7582         switch (l2_tunnel->l2_tunnel_type) {
7583         case RTE_L2_TUNNEL_TYPE_E_TAG:
7584                 ret = ixgbe_e_tag_insertion_en_dis(dev, l2_tunnel, 0);
7585                 break;
7586         default:
7587                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7588                 ret = -EINVAL;
7589                 break;
7590         }
7591
7592         return ret;
7593 }
7594
7595 static int
7596 ixgbe_e_tag_stripping_en_dis(struct rte_eth_dev *dev,
7597                              bool en)
7598 {
7599         int ret = 0;
7600         uint32_t qde;
7601         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7602
7603         if (hw->mac.type != ixgbe_mac_X550 &&
7604             hw->mac.type != ixgbe_mac_X550EM_x &&
7605             hw->mac.type != ixgbe_mac_X550EM_a) {
7606                 return -ENOTSUP;
7607         }
7608
7609         qde = IXGBE_READ_REG(hw, IXGBE_QDE);
7610         if (en)
7611                 qde |= IXGBE_QDE_STRIP_TAG;
7612         else
7613                 qde &= ~IXGBE_QDE_STRIP_TAG;
7614         qde &= ~IXGBE_QDE_READ;
7615         qde |= IXGBE_QDE_WRITE;
7616         IXGBE_WRITE_REG(hw, IXGBE_QDE, qde);
7617
7618         return ret;
7619 }
7620
7621 /* Enable l2 tunnel tag stripping */
7622 static int
7623 ixgbe_dev_l2_tunnel_stripping_enable
7624         (struct rte_eth_dev *dev,
7625          enum rte_eth_tunnel_type l2_tunnel_type)
7626 {
7627         int ret = 0;
7628
7629         switch (l2_tunnel_type) {
7630         case RTE_L2_TUNNEL_TYPE_E_TAG:
7631                 ret = ixgbe_e_tag_stripping_en_dis(dev, 1);
7632                 break;
7633         default:
7634                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7635                 ret = -EINVAL;
7636                 break;
7637         }
7638
7639         return ret;
7640 }
7641
7642 /* Disable l2 tunnel tag stripping */
7643 static int
7644 ixgbe_dev_l2_tunnel_stripping_disable
7645         (struct rte_eth_dev *dev,
7646          enum rte_eth_tunnel_type l2_tunnel_type)
7647 {
7648         int ret = 0;
7649
7650         switch (l2_tunnel_type) {
7651         case RTE_L2_TUNNEL_TYPE_E_TAG:
7652                 ret = ixgbe_e_tag_stripping_en_dis(dev, 0);
7653                 break;
7654         default:
7655                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7656                 ret = -EINVAL;
7657                 break;
7658         }
7659
7660         return ret;
7661 }
7662
7663 /* Enable/disable l2 tunnel offload functions */
7664 static int
7665 ixgbe_dev_l2_tunnel_offload_set
7666         (struct rte_eth_dev *dev,
7667          struct rte_eth_l2_tunnel_conf *l2_tunnel,
7668          uint32_t mask,
7669          uint8_t en)
7670 {
7671         int ret = 0;
7672
7673         if (l2_tunnel == NULL)
7674                 return -EINVAL;
7675
7676         ret = -EINVAL;
7677         if (mask & ETH_L2_TUNNEL_ENABLE_MASK) {
7678                 if (en)
7679                         ret = ixgbe_dev_l2_tunnel_enable(
7680                                 dev,
7681                                 l2_tunnel->l2_tunnel_type);
7682                 else
7683                         ret = ixgbe_dev_l2_tunnel_disable(
7684                                 dev,
7685                                 l2_tunnel->l2_tunnel_type);
7686         }
7687
7688         if (mask & ETH_L2_TUNNEL_INSERTION_MASK) {
7689                 if (en)
7690                         ret = ixgbe_dev_l2_tunnel_insertion_enable(
7691                                 dev,
7692                                 l2_tunnel);
7693                 else
7694                         ret = ixgbe_dev_l2_tunnel_insertion_disable(
7695                                 dev,
7696                                 l2_tunnel);
7697         }
7698
7699         if (mask & ETH_L2_TUNNEL_STRIPPING_MASK) {
7700                 if (en)
7701                         ret = ixgbe_dev_l2_tunnel_stripping_enable(
7702                                 dev,
7703                                 l2_tunnel->l2_tunnel_type);
7704                 else
7705                         ret = ixgbe_dev_l2_tunnel_stripping_disable(
7706                                 dev,
7707                                 l2_tunnel->l2_tunnel_type);
7708         }
7709
7710         if (mask & ETH_L2_TUNNEL_FORWARDING_MASK) {
7711                 if (en)
7712                         ret = ixgbe_dev_l2_tunnel_forwarding_enable(
7713                                 dev,
7714                                 l2_tunnel->l2_tunnel_type);
7715                 else
7716                         ret = ixgbe_dev_l2_tunnel_forwarding_disable(
7717                                 dev,
7718                                 l2_tunnel->l2_tunnel_type);
7719         }
7720
7721         return ret;
7722 }
7723
7724 static int
7725 ixgbe_update_vxlan_port(struct ixgbe_hw *hw,
7726                         uint16_t port)
7727 {
7728         IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, port);
7729         IXGBE_WRITE_FLUSH(hw);
7730
7731         return 0;
7732 }
7733
7734 /* There's only one register for VxLAN UDP port.
7735  * So, we cannot add several ports. Will update it.
7736  */
7737 static int
7738 ixgbe_add_vxlan_port(struct ixgbe_hw *hw,
7739                      uint16_t port)
7740 {
7741         if (port == 0) {
7742                 PMD_DRV_LOG(ERR, "Add VxLAN port 0 is not allowed.");
7743                 return -EINVAL;
7744         }
7745
7746         return ixgbe_update_vxlan_port(hw, port);
7747 }
7748
7749 /* We cannot delete the VxLAN port. For there's a register for VxLAN
7750  * UDP port, it must have a value.
7751  * So, will reset it to the original value 0.
7752  */
7753 static int
7754 ixgbe_del_vxlan_port(struct ixgbe_hw *hw,
7755                      uint16_t port)
7756 {
7757         uint16_t cur_port;
7758
7759         cur_port = (uint16_t)IXGBE_READ_REG(hw, IXGBE_VXLANCTRL);
7760
7761         if (cur_port != port) {
7762                 PMD_DRV_LOG(ERR, "Port %u does not exist.", port);
7763                 return -EINVAL;
7764         }
7765
7766         return ixgbe_update_vxlan_port(hw, 0);
7767 }
7768
7769 /* Add UDP tunneling port */
7770 static int
7771 ixgbe_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
7772                               struct rte_eth_udp_tunnel *udp_tunnel)
7773 {
7774         int ret = 0;
7775         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7776
7777         if (hw->mac.type != ixgbe_mac_X550 &&
7778             hw->mac.type != ixgbe_mac_X550EM_x &&
7779             hw->mac.type != ixgbe_mac_X550EM_a) {
7780                 return -ENOTSUP;
7781         }
7782
7783         if (udp_tunnel == NULL)
7784                 return -EINVAL;
7785
7786         switch (udp_tunnel->prot_type) {
7787         case RTE_TUNNEL_TYPE_VXLAN:
7788                 ret = ixgbe_add_vxlan_port(hw, udp_tunnel->udp_port);
7789                 break;
7790
7791         case RTE_TUNNEL_TYPE_GENEVE:
7792         case RTE_TUNNEL_TYPE_TEREDO:
7793                 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
7794                 ret = -EINVAL;
7795                 break;
7796
7797         default:
7798                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7799                 ret = -EINVAL;
7800                 break;
7801         }
7802
7803         return ret;
7804 }
7805
7806 /* Remove UDP tunneling port */
7807 static int
7808 ixgbe_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
7809                               struct rte_eth_udp_tunnel *udp_tunnel)
7810 {
7811         int ret = 0;
7812         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7813
7814         if (hw->mac.type != ixgbe_mac_X550 &&
7815             hw->mac.type != ixgbe_mac_X550EM_x &&
7816             hw->mac.type != ixgbe_mac_X550EM_a) {
7817                 return -ENOTSUP;
7818         }
7819
7820         if (udp_tunnel == NULL)
7821                 return -EINVAL;
7822
7823         switch (udp_tunnel->prot_type) {
7824         case RTE_TUNNEL_TYPE_VXLAN:
7825                 ret = ixgbe_del_vxlan_port(hw, udp_tunnel->udp_port);
7826                 break;
7827         case RTE_TUNNEL_TYPE_GENEVE:
7828         case RTE_TUNNEL_TYPE_TEREDO:
7829                 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
7830                 ret = -EINVAL;
7831                 break;
7832         default:
7833                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7834                 ret = -EINVAL;
7835                 break;
7836         }
7837
7838         return ret;
7839 }
7840
7841 static void
7842 ixgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
7843 {
7844         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7845
7846         hw->mac.ops.update_xcast_mode(hw, IXGBEVF_XCAST_MODE_ALLMULTI);
7847 }
7848
7849 static void
7850 ixgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
7851 {
7852         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7853
7854         hw->mac.ops.update_xcast_mode(hw, IXGBEVF_XCAST_MODE_NONE);
7855 }
7856
7857 static void ixgbevf_mbx_process(struct rte_eth_dev *dev)
7858 {
7859         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7860         u32 in_msg = 0;
7861
7862         if (ixgbe_read_mbx(hw, &in_msg, 1, 0))
7863                 return;
7864
7865         /* PF reset VF event */
7866         if (in_msg == IXGBE_PF_CONTROL_MSG)
7867                 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET, NULL);
7868 }
7869
7870 static int
7871 ixgbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
7872 {
7873         uint32_t eicr;
7874         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7875         struct ixgbe_interrupt *intr =
7876                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
7877         ixgbevf_intr_disable(hw);
7878
7879         /* read-on-clear nic registers here */
7880         eicr = IXGBE_READ_REG(hw, IXGBE_VTEICR);
7881         intr->flags = 0;
7882
7883         /* only one misc vector supported - mailbox */
7884         eicr &= IXGBE_VTEICR_MASK;
7885         if (eicr == IXGBE_MISC_VEC_ID)
7886                 intr->flags |= IXGBE_FLAG_MAILBOX;
7887
7888         return 0;
7889 }
7890
7891 static int
7892 ixgbevf_dev_interrupt_action(struct rte_eth_dev *dev)
7893 {
7894         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7895         struct ixgbe_interrupt *intr =
7896                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
7897
7898         if (intr->flags & IXGBE_FLAG_MAILBOX) {
7899                 ixgbevf_mbx_process(dev);
7900                 intr->flags &= ~IXGBE_FLAG_MAILBOX;
7901         }
7902
7903         ixgbevf_intr_enable(hw);
7904
7905         return 0;
7906 }
7907
7908 static void
7909 ixgbevf_dev_interrupt_handler(void *param)
7910 {
7911         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7912
7913         ixgbevf_dev_interrupt_get_status(dev);
7914         ixgbevf_dev_interrupt_action(dev);
7915 }
7916
7917 /**
7918  *  ixgbe_disable_sec_tx_path_generic - Stops the transmit data path
7919  *  @hw: pointer to hardware structure
7920  *
7921  *  Stops the transmit data path and waits for the HW to internally empty
7922  *  the Tx security block
7923  **/
7924 int ixgbe_disable_sec_tx_path_generic(struct ixgbe_hw *hw)
7925 {
7926 #define IXGBE_MAX_SECTX_POLL 40
7927
7928         int i;
7929         int sectxreg;
7930
7931         sectxreg = IXGBE_READ_REG(hw, IXGBE_SECTXCTRL);
7932         sectxreg |= IXGBE_SECTXCTRL_TX_DIS;
7933         IXGBE_WRITE_REG(hw, IXGBE_SECTXCTRL, sectxreg);
7934         for (i = 0; i < IXGBE_MAX_SECTX_POLL; i++) {
7935                 sectxreg = IXGBE_READ_REG(hw, IXGBE_SECTXSTAT);
7936                 if (sectxreg & IXGBE_SECTXSTAT_SECTX_RDY)
7937                         break;
7938                 /* Use interrupt-safe sleep just in case */
7939                 usec_delay(1000);
7940         }
7941
7942         /* For informational purposes only */
7943         if (i >= IXGBE_MAX_SECTX_POLL)
7944                 PMD_DRV_LOG(DEBUG, "Tx unit being enabled before security "
7945                          "path fully disabled.  Continuing with init.");
7946
7947         return IXGBE_SUCCESS;
7948 }
7949
7950 /**
7951  *  ixgbe_enable_sec_tx_path_generic - Enables the transmit data path
7952  *  @hw: pointer to hardware structure
7953  *
7954  *  Enables the transmit data path.
7955  **/
7956 int ixgbe_enable_sec_tx_path_generic(struct ixgbe_hw *hw)
7957 {
7958         uint32_t sectxreg;
7959
7960         sectxreg = IXGBE_READ_REG(hw, IXGBE_SECTXCTRL);
7961         sectxreg &= ~IXGBE_SECTXCTRL_TX_DIS;
7962         IXGBE_WRITE_REG(hw, IXGBE_SECTXCTRL, sectxreg);
7963         IXGBE_WRITE_FLUSH(hw);
7964
7965         return IXGBE_SUCCESS;
7966 }
7967
7968 /* restore n-tuple filter */
7969 static inline void
7970 ixgbe_ntuple_filter_restore(struct rte_eth_dev *dev)
7971 {
7972         struct ixgbe_filter_info *filter_info =
7973                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
7974         struct ixgbe_5tuple_filter *node;
7975
7976         TAILQ_FOREACH(node, &filter_info->fivetuple_list, entries) {
7977                 ixgbe_inject_5tuple_filter(dev, node);
7978         }
7979 }
7980
7981 /* restore ethernet type filter */
7982 static inline void
7983 ixgbe_ethertype_filter_restore(struct rte_eth_dev *dev)
7984 {
7985         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7986         struct ixgbe_filter_info *filter_info =
7987                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
7988         int i;
7989
7990         for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
7991                 if (filter_info->ethertype_mask & (1 << i)) {
7992                         IXGBE_WRITE_REG(hw, IXGBE_ETQF(i),
7993                                         filter_info->ethertype_filters[i].etqf);
7994                         IXGBE_WRITE_REG(hw, IXGBE_ETQS(i),
7995                                         filter_info->ethertype_filters[i].etqs);
7996                         IXGBE_WRITE_FLUSH(hw);
7997                 }
7998         }
7999 }
8000
8001 /* restore SYN filter */
8002 static inline void
8003 ixgbe_syn_filter_restore(struct rte_eth_dev *dev)
8004 {
8005         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8006         struct ixgbe_filter_info *filter_info =
8007                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8008         uint32_t synqf;
8009
8010         synqf = filter_info->syn_info;
8011
8012         if (synqf & IXGBE_SYN_FILTER_ENABLE) {
8013                 IXGBE_WRITE_REG(hw, IXGBE_SYNQF, synqf);
8014                 IXGBE_WRITE_FLUSH(hw);
8015         }
8016 }
8017
8018 /* restore L2 tunnel filter */
8019 static inline void
8020 ixgbe_l2_tn_filter_restore(struct rte_eth_dev *dev)
8021 {
8022         struct ixgbe_l2_tn_info *l2_tn_info =
8023                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
8024         struct ixgbe_l2_tn_filter *node;
8025         struct rte_eth_l2_tunnel_conf l2_tn_conf;
8026
8027         TAILQ_FOREACH(node, &l2_tn_info->l2_tn_list, entries) {
8028                 l2_tn_conf.l2_tunnel_type = node->key.l2_tn_type;
8029                 l2_tn_conf.tunnel_id      = node->key.tn_id;
8030                 l2_tn_conf.pool           = node->pool;
8031                 (void)ixgbe_dev_l2_tunnel_filter_add(dev, &l2_tn_conf, TRUE);
8032         }
8033 }
8034
8035 static int
8036 ixgbe_filter_restore(struct rte_eth_dev *dev)
8037 {
8038         ixgbe_ntuple_filter_restore(dev);
8039         ixgbe_ethertype_filter_restore(dev);
8040         ixgbe_syn_filter_restore(dev);
8041         ixgbe_fdir_filter_restore(dev);
8042         ixgbe_l2_tn_filter_restore(dev);
8043
8044         return 0;
8045 }
8046
8047 static void
8048 ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev)
8049 {
8050         struct ixgbe_l2_tn_info *l2_tn_info =
8051                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
8052         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8053
8054         if (l2_tn_info->e_tag_en)
8055                 (void)ixgbe_e_tag_enable(hw);
8056
8057         if (l2_tn_info->e_tag_fwd_en)
8058                 (void)ixgbe_e_tag_forwarding_en_dis(dev, 1);
8059
8060         (void)ixgbe_update_e_tag_eth_type(hw, l2_tn_info->e_tag_ether_type);
8061 }
8062
8063 /* remove all the n-tuple filters */
8064 void
8065 ixgbe_clear_all_ntuple_filter(struct rte_eth_dev *dev)
8066 {
8067         struct ixgbe_filter_info *filter_info =
8068                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8069         struct ixgbe_5tuple_filter *p_5tuple;
8070
8071         while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list)))
8072                 ixgbe_remove_5tuple_filter(dev, p_5tuple);
8073 }
8074
8075 /* remove all the ether type filters */
8076 void
8077 ixgbe_clear_all_ethertype_filter(struct rte_eth_dev *dev)
8078 {
8079         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8080         struct ixgbe_filter_info *filter_info =
8081                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8082         int i;
8083
8084         for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
8085                 if (filter_info->ethertype_mask & (1 << i) &&
8086                     !filter_info->ethertype_filters[i].conf) {
8087                         (void)ixgbe_ethertype_filter_remove(filter_info,
8088                                                             (uint8_t)i);
8089                         IXGBE_WRITE_REG(hw, IXGBE_ETQF(i), 0);
8090                         IXGBE_WRITE_REG(hw, IXGBE_ETQS(i), 0);
8091                         IXGBE_WRITE_FLUSH(hw);
8092                 }
8093         }
8094 }
8095
8096 /* remove the SYN filter */
8097 void
8098 ixgbe_clear_syn_filter(struct rte_eth_dev *dev)
8099 {
8100         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8101         struct ixgbe_filter_info *filter_info =
8102                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8103
8104         if (filter_info->syn_info & IXGBE_SYN_FILTER_ENABLE) {
8105                 filter_info->syn_info = 0;
8106
8107                 IXGBE_WRITE_REG(hw, IXGBE_SYNQF, 0);
8108                 IXGBE_WRITE_FLUSH(hw);
8109         }
8110 }
8111
8112 /* remove all the L2 tunnel filters */
8113 int
8114 ixgbe_clear_all_l2_tn_filter(struct rte_eth_dev *dev)
8115 {
8116         struct ixgbe_l2_tn_info *l2_tn_info =
8117                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
8118         struct ixgbe_l2_tn_filter *l2_tn_filter;
8119         struct rte_eth_l2_tunnel_conf l2_tn_conf;
8120         int ret = 0;
8121
8122         while ((l2_tn_filter = TAILQ_FIRST(&l2_tn_info->l2_tn_list))) {
8123                 l2_tn_conf.l2_tunnel_type = l2_tn_filter->key.l2_tn_type;
8124                 l2_tn_conf.tunnel_id      = l2_tn_filter->key.tn_id;
8125                 l2_tn_conf.pool           = l2_tn_filter->pool;
8126                 ret = ixgbe_dev_l2_tunnel_filter_del(dev, &l2_tn_conf);
8127                 if (ret < 0)
8128                         return ret;
8129         }
8130
8131         return 0;
8132 }
8133
8134 RTE_PMD_REGISTER_PCI(net_ixgbe, rte_ixgbe_pmd);
8135 RTE_PMD_REGISTER_PCI_TABLE(net_ixgbe, pci_id_ixgbe_map);
8136 RTE_PMD_REGISTER_KMOD_DEP(net_ixgbe, "* igb_uio | uio_pci_generic | vfio");
8137 RTE_PMD_REGISTER_PCI(net_ixgbe_vf, rte_ixgbevf_pmd);
8138 RTE_PMD_REGISTER_PCI_TABLE(net_ixgbe_vf, pci_id_ixgbevf_map);
8139 RTE_PMD_REGISTER_KMOD_DEP(net_ixgbe_vf, "* igb_uio | vfio");