4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 #include <sys/queue.h>
42 #include <netinet/in.h>
43 #include <rte_byteorder.h>
44 #include <rte_common.h>
45 #include <rte_cycles.h>
47 #include <rte_interrupts.h>
49 #include <rte_debug.h>
51 #include <rte_atomic.h>
52 #include <rte_branch_prediction.h>
53 #include <rte_memory.h>
54 #include <rte_memzone.h>
56 #include <rte_alarm.h>
57 #include <rte_ether.h>
58 #include <rte_ethdev.h>
59 #include <rte_atomic.h>
60 #include <rte_malloc.h>
61 #include <rte_random.h>
64 #include "ixgbe_logs.h"
65 #include "base/ixgbe_api.h"
66 #include "base/ixgbe_vf.h"
67 #include "base/ixgbe_common.h"
68 #include "ixgbe_ethdev.h"
69 #include "ixgbe_bypass.h"
70 #include "ixgbe_rxtx.h"
71 #include "base/ixgbe_type.h"
72 #include "base/ixgbe_phy.h"
73 #include "ixgbe_regs.h"
76 * High threshold controlling when to start sending XOFF frames. Must be at
77 * least 8 bytes less than receive packet buffer size. This value is in units
80 #define IXGBE_FC_HI 0x80
83 * Low threshold controlling when to start sending XON frames. This value is
84 * in units of 1024 bytes.
86 #define IXGBE_FC_LO 0x40
88 /* Default minimum inter-interrupt interval for EITR configuration */
89 #define IXGBE_MIN_INTER_INTERRUPT_INTERVAL_DEFAULT 0x79E
91 /* Timer value included in XOFF frames. */
92 #define IXGBE_FC_PAUSE 0x680
94 #define IXGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
95 #define IXGBE_LINK_UP_CHECK_TIMEOUT 1000 /* ms */
96 #define IXGBE_VMDQ_NUM_UC_MAC 4096 /* Maximum nb. of UC MAC addr. */
98 #define IXGBE_MMW_SIZE_DEFAULT 0x4
99 #define IXGBE_MMW_SIZE_JUMBO_FRAME 0x14
100 #define IXGBE_MAX_RING_DESC 4096 /* replicate define from rxtx */
103 * Default values for RX/TX configuration
105 #define IXGBE_DEFAULT_RX_FREE_THRESH 32
106 #define IXGBE_DEFAULT_RX_PTHRESH 8
107 #define IXGBE_DEFAULT_RX_HTHRESH 8
108 #define IXGBE_DEFAULT_RX_WTHRESH 0
110 #define IXGBE_DEFAULT_TX_FREE_THRESH 32
111 #define IXGBE_DEFAULT_TX_PTHRESH 32
112 #define IXGBE_DEFAULT_TX_HTHRESH 0
113 #define IXGBE_DEFAULT_TX_WTHRESH 0
114 #define IXGBE_DEFAULT_TX_RSBIT_THRESH 32
116 /* Bit shift and mask */
117 #define IXGBE_4_BIT_WIDTH (CHAR_BIT / 2)
118 #define IXGBE_4_BIT_MASK RTE_LEN2MASK(IXGBE_4_BIT_WIDTH, uint8_t)
119 #define IXGBE_8_BIT_WIDTH CHAR_BIT
120 #define IXGBE_8_BIT_MASK UINT8_MAX
122 #define IXGBEVF_PMD_NAME "rte_ixgbevf_pmd" /* PMD name */
124 #define IXGBE_QUEUE_STAT_COUNTERS (sizeof(hw_stats->qprc) / sizeof(hw_stats->qprc[0]))
126 #define IXGBE_HKEY_MAX_INDEX 10
128 /* Additional timesync values. */
129 #define NSEC_PER_SEC 1000000000L
130 #define IXGBE_INCVAL_10GB 0x66666666
131 #define IXGBE_INCVAL_1GB 0x40000000
132 #define IXGBE_INCVAL_100 0x50000000
133 #define IXGBE_INCVAL_SHIFT_10GB 28
134 #define IXGBE_INCVAL_SHIFT_1GB 24
135 #define IXGBE_INCVAL_SHIFT_100 21
136 #define IXGBE_INCVAL_SHIFT_82599 7
137 #define IXGBE_INCPER_SHIFT_82599 24
139 #define IXGBE_CYCLECOUNTER_MASK 0xffffffffffffffffULL
141 #define IXGBE_VT_CTL_POOLING_MODE_MASK 0x00030000
142 #define IXGBE_VT_CTL_POOLING_MODE_ETAG 0x00010000
143 #define DEFAULT_ETAG_ETYPE 0x893f
144 #define IXGBE_ETAG_ETYPE 0x00005084
145 #define IXGBE_ETAG_ETYPE_MASK 0x0000ffff
146 #define IXGBE_ETAG_ETYPE_VALID 0x80000000
147 #define IXGBE_RAH_ADTYPE 0x40000000
148 #define IXGBE_RAL_ETAG_FILTER_MASK 0x00003fff
149 #define IXGBE_VMVIR_TAGA_MASK 0x18000000
150 #define IXGBE_VMVIR_TAGA_ETAG_INSERT 0x08000000
151 #define IXGBE_VMTIR(_i) (0x00017000 + ((_i) * 4)) /* 64 of these (0-63) */
152 #define IXGBE_QDE_STRIP_TAG 0x00000004
154 enum ixgbevf_xcast_modes {
155 IXGBEVF_XCAST_MODE_NONE = 0,
156 IXGBEVF_XCAST_MODE_MULTI,
157 IXGBEVF_XCAST_MODE_ALLMULTI,
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_dev_configure(struct rte_eth_dev *dev);
163 static int ixgbe_dev_start(struct rte_eth_dev *dev);
164 static void ixgbe_dev_stop(struct rte_eth_dev *dev);
165 static int ixgbe_dev_set_link_up(struct rte_eth_dev *dev);
166 static int ixgbe_dev_set_link_down(struct rte_eth_dev *dev);
167 static void ixgbe_dev_close(struct rte_eth_dev *dev);
168 static void ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
169 static void ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
170 static void ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
171 static void ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev);
172 static int ixgbe_dev_link_update(struct rte_eth_dev *dev,
173 int wait_to_complete);
174 static void ixgbe_dev_stats_get(struct rte_eth_dev *dev,
175 struct rte_eth_stats *stats);
176 static int ixgbe_dev_xstats_get(struct rte_eth_dev *dev,
177 struct rte_eth_xstats *xstats, unsigned n);
178 static int ixgbevf_dev_xstats_get(struct rte_eth_dev *dev,
179 struct rte_eth_xstats *xstats, unsigned n);
180 static void ixgbe_dev_stats_reset(struct rte_eth_dev *dev);
181 static void ixgbe_dev_xstats_reset(struct rte_eth_dev *dev);
182 static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
183 struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit);
184 static int ixgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
185 struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit);
186 static int ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
190 static void ixgbe_dev_info_get(struct rte_eth_dev *dev,
191 struct rte_eth_dev_info *dev_info);
192 static const uint32_t *ixgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev);
193 static void ixgbevf_dev_info_get(struct rte_eth_dev *dev,
194 struct rte_eth_dev_info *dev_info);
195 static int ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
197 static int ixgbe_vlan_filter_set(struct rte_eth_dev *dev,
198 uint16_t vlan_id, int on);
199 static int ixgbe_vlan_tpid_set(struct rte_eth_dev *dev,
200 enum rte_vlan_type vlan_type,
202 static void ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
203 uint16_t queue, bool on);
204 static void ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue,
206 static void ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask);
207 static void ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue);
208 static void ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue);
209 static void ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev);
210 static void ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev);
212 static int ixgbe_dev_led_on(struct rte_eth_dev *dev);
213 static int ixgbe_dev_led_off(struct rte_eth_dev *dev);
214 static int ixgbe_flow_ctrl_get(struct rte_eth_dev *dev,
215 struct rte_eth_fc_conf *fc_conf);
216 static int ixgbe_flow_ctrl_set(struct rte_eth_dev *dev,
217 struct rte_eth_fc_conf *fc_conf);
218 static int ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev,
219 struct rte_eth_pfc_conf *pfc_conf);
220 static int ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
221 struct rte_eth_rss_reta_entry64 *reta_conf,
223 static int ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
224 struct rte_eth_rss_reta_entry64 *reta_conf,
226 static void ixgbe_dev_link_status_print(struct rte_eth_dev *dev);
227 static int ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev);
228 static int ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
229 static int ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev);
230 static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev);
231 static void ixgbe_dev_interrupt_handler(struct rte_intr_handle *handle,
233 static void ixgbe_dev_interrupt_delayed_handler(void *param);
234 static void ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
235 uint32_t index, uint32_t pool);
236 static void ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index);
237 static void ixgbe_set_default_mac_addr(struct rte_eth_dev *dev,
238 struct ether_addr *mac_addr);
239 static void ixgbe_dcb_init(struct ixgbe_hw *hw, struct ixgbe_dcb_config *dcb_config);
241 /* For Virtual Function support */
242 static int eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev);
243 static int eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev);
244 static int ixgbevf_dev_configure(struct rte_eth_dev *dev);
245 static int ixgbevf_dev_start(struct rte_eth_dev *dev);
246 static void ixgbevf_dev_stop(struct rte_eth_dev *dev);
247 static void ixgbevf_dev_close(struct rte_eth_dev *dev);
248 static void ixgbevf_intr_disable(struct ixgbe_hw *hw);
249 static void ixgbevf_intr_enable(struct ixgbe_hw *hw);
250 static void ixgbevf_dev_stats_get(struct rte_eth_dev *dev,
251 struct rte_eth_stats *stats);
252 static void ixgbevf_dev_stats_reset(struct rte_eth_dev *dev);
253 static int ixgbevf_vlan_filter_set(struct rte_eth_dev *dev,
254 uint16_t vlan_id, int on);
255 static void ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev,
256 uint16_t queue, int on);
257 static void ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
258 static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
259 static int ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
261 static int ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
263 static void ixgbevf_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
264 uint8_t queue, uint8_t msix_vector);
265 static void ixgbevf_configure_msix(struct rte_eth_dev *dev);
266 static void ixgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev);
267 static void ixgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev);
269 /* For Eth VMDQ APIs support */
270 static int ixgbe_uc_hash_table_set(struct rte_eth_dev *dev, struct
271 ether_addr * mac_addr, uint8_t on);
272 static int ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on);
273 static int ixgbe_set_pool_rx_mode(struct rte_eth_dev *dev, uint16_t pool,
274 uint16_t rx_mask, uint8_t on);
275 static int ixgbe_set_pool_rx(struct rte_eth_dev *dev, uint16_t pool, uint8_t on);
276 static int ixgbe_set_pool_tx(struct rte_eth_dev *dev, uint16_t pool, uint8_t on);
277 static int ixgbe_set_pool_vlan_filter(struct rte_eth_dev *dev, uint16_t vlan,
278 uint64_t pool_mask, uint8_t vlan_on);
279 static int ixgbe_mirror_rule_set(struct rte_eth_dev *dev,
280 struct rte_eth_mirror_conf *mirror_conf,
281 uint8_t rule_id, uint8_t on);
282 static int ixgbe_mirror_rule_reset(struct rte_eth_dev *dev,
284 static int ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
286 static int ixgbe_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
288 static void ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
289 uint8_t queue, uint8_t msix_vector);
290 static void ixgbe_configure_msix(struct rte_eth_dev *dev);
292 static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
293 uint16_t queue_idx, uint16_t tx_rate);
294 static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
295 uint16_t tx_rate, uint64_t q_msk);
297 static void ixgbevf_add_mac_addr(struct rte_eth_dev *dev,
298 struct ether_addr *mac_addr,
299 uint32_t index, uint32_t pool);
300 static void ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
301 static void ixgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
302 struct ether_addr *mac_addr);
303 static int ixgbe_syn_filter_set(struct rte_eth_dev *dev,
304 struct rte_eth_syn_filter *filter,
306 static int ixgbe_syn_filter_get(struct rte_eth_dev *dev,
307 struct rte_eth_syn_filter *filter);
308 static int ixgbe_syn_filter_handle(struct rte_eth_dev *dev,
309 enum rte_filter_op filter_op,
311 static int ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
312 struct ixgbe_5tuple_filter *filter);
313 static void ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
314 struct ixgbe_5tuple_filter *filter);
315 static int ixgbe_add_del_ntuple_filter(struct rte_eth_dev *dev,
316 struct rte_eth_ntuple_filter *filter,
318 static int ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
319 enum rte_filter_op filter_op,
321 static int ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
322 struct rte_eth_ntuple_filter *filter);
323 static int ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
324 struct rte_eth_ethertype_filter *filter,
326 static int ixgbe_ethertype_filter_handle(struct rte_eth_dev *dev,
327 enum rte_filter_op filter_op,
329 static int ixgbe_get_ethertype_filter(struct rte_eth_dev *dev,
330 struct rte_eth_ethertype_filter *filter);
331 static int ixgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
332 enum rte_filter_type filter_type,
333 enum rte_filter_op filter_op,
335 static int ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
337 static int ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
338 struct ether_addr *mc_addr_set,
339 uint32_t nb_mc_addr);
340 static int ixgbe_dev_get_dcb_info(struct rte_eth_dev *dev,
341 struct rte_eth_dcb_info *dcb_info);
343 static int ixgbe_get_reg_length(struct rte_eth_dev *dev);
344 static int ixgbe_get_regs(struct rte_eth_dev *dev,
345 struct rte_dev_reg_info *regs);
346 static int ixgbe_get_eeprom_length(struct rte_eth_dev *dev);
347 static int ixgbe_get_eeprom(struct rte_eth_dev *dev,
348 struct rte_dev_eeprom_info *eeprom);
349 static int ixgbe_set_eeprom(struct rte_eth_dev *dev,
350 struct rte_dev_eeprom_info *eeprom);
352 static int ixgbevf_get_reg_length(struct rte_eth_dev *dev);
353 static int ixgbevf_get_regs(struct rte_eth_dev *dev,
354 struct rte_dev_reg_info *regs);
356 static int ixgbe_timesync_enable(struct rte_eth_dev *dev);
357 static int ixgbe_timesync_disable(struct rte_eth_dev *dev);
358 static int ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
359 struct timespec *timestamp,
361 static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
362 struct timespec *timestamp);
363 static int ixgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
364 static int ixgbe_timesync_read_time(struct rte_eth_dev *dev,
365 struct timespec *timestamp);
366 static int ixgbe_timesync_write_time(struct rte_eth_dev *dev,
367 const struct timespec *timestamp);
369 static int ixgbe_dev_l2_tunnel_eth_type_conf
370 (struct rte_eth_dev *dev, struct rte_eth_l2_tunnel_conf *l2_tunnel);
371 static int ixgbe_dev_l2_tunnel_offload_set
372 (struct rte_eth_dev *dev,
373 struct rte_eth_l2_tunnel_conf *l2_tunnel,
376 static int ixgbe_dev_l2_tunnel_filter_handle(struct rte_eth_dev *dev,
377 enum rte_filter_op filter_op,
380 static int ixgbe_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
381 struct rte_eth_udp_tunnel *udp_tunnel);
382 static int ixgbe_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
383 struct rte_eth_udp_tunnel *udp_tunnel);
386 * Define VF Stats MACRO for Non "cleared on read" register
388 #define UPDATE_VF_STAT(reg, last, cur) \
390 uint32_t latest = IXGBE_READ_REG(hw, reg); \
391 cur += (latest - last) & UINT_MAX; \
395 #define UPDATE_VF_STAT_36BIT(lsb, msb, last, cur) \
397 u64 new_lsb = IXGBE_READ_REG(hw, lsb); \
398 u64 new_msb = IXGBE_READ_REG(hw, msb); \
399 u64 latest = ((new_msb << 32) | new_lsb); \
400 cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \
404 #define IXGBE_SET_HWSTRIP(h, q) do {\
405 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
406 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
407 (h)->bitmap[idx] |= 1 << bit;\
410 #define IXGBE_CLEAR_HWSTRIP(h, q) do {\
411 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
412 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
413 (h)->bitmap[idx] &= ~(1 << bit);\
416 #define IXGBE_GET_HWSTRIP(h, q, r) do {\
417 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
418 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
419 (r) = (h)->bitmap[idx] >> bit & 1;\
423 * The set of PCI devices this driver supports
425 static const struct rte_pci_id pci_id_ixgbe_map[] = {
427 #define RTE_PCI_DEV_ID_DECL_IXGBE(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
428 #include "rte_pci_dev_ids.h"
430 { .vendor_id = 0, /* sentinel */ },
435 * The set of PCI devices this driver supports (for 82599 VF)
437 static const struct rte_pci_id pci_id_ixgbevf_map[] = {
439 #define RTE_PCI_DEV_ID_DECL_IXGBEVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
440 #include "rte_pci_dev_ids.h"
441 { .vendor_id = 0, /* sentinel */ },
445 static const struct rte_eth_desc_lim rx_desc_lim = {
446 .nb_max = IXGBE_MAX_RING_DESC,
447 .nb_min = IXGBE_MIN_RING_DESC,
448 .nb_align = IXGBE_RXD_ALIGN,
451 static const struct rte_eth_desc_lim tx_desc_lim = {
452 .nb_max = IXGBE_MAX_RING_DESC,
453 .nb_min = IXGBE_MIN_RING_DESC,
454 .nb_align = IXGBE_TXD_ALIGN,
457 static const struct eth_dev_ops ixgbe_eth_dev_ops = {
458 .dev_configure = ixgbe_dev_configure,
459 .dev_start = ixgbe_dev_start,
460 .dev_stop = ixgbe_dev_stop,
461 .dev_set_link_up = ixgbe_dev_set_link_up,
462 .dev_set_link_down = ixgbe_dev_set_link_down,
463 .dev_close = ixgbe_dev_close,
464 .promiscuous_enable = ixgbe_dev_promiscuous_enable,
465 .promiscuous_disable = ixgbe_dev_promiscuous_disable,
466 .allmulticast_enable = ixgbe_dev_allmulticast_enable,
467 .allmulticast_disable = ixgbe_dev_allmulticast_disable,
468 .link_update = ixgbe_dev_link_update,
469 .stats_get = ixgbe_dev_stats_get,
470 .xstats_get = ixgbe_dev_xstats_get,
471 .stats_reset = ixgbe_dev_stats_reset,
472 .xstats_reset = ixgbe_dev_xstats_reset,
473 .xstats_get_names = ixgbe_dev_xstats_get_names,
474 .queue_stats_mapping_set = ixgbe_dev_queue_stats_mapping_set,
475 .dev_infos_get = ixgbe_dev_info_get,
476 .dev_supported_ptypes_get = ixgbe_dev_supported_ptypes_get,
477 .mtu_set = ixgbe_dev_mtu_set,
478 .vlan_filter_set = ixgbe_vlan_filter_set,
479 .vlan_tpid_set = ixgbe_vlan_tpid_set,
480 .vlan_offload_set = ixgbe_vlan_offload_set,
481 .vlan_strip_queue_set = ixgbe_vlan_strip_queue_set,
482 .rx_queue_start = ixgbe_dev_rx_queue_start,
483 .rx_queue_stop = ixgbe_dev_rx_queue_stop,
484 .tx_queue_start = ixgbe_dev_tx_queue_start,
485 .tx_queue_stop = ixgbe_dev_tx_queue_stop,
486 .rx_queue_setup = ixgbe_dev_rx_queue_setup,
487 .rx_queue_intr_enable = ixgbe_dev_rx_queue_intr_enable,
488 .rx_queue_intr_disable = ixgbe_dev_rx_queue_intr_disable,
489 .rx_queue_release = ixgbe_dev_rx_queue_release,
490 .rx_queue_count = ixgbe_dev_rx_queue_count,
491 .rx_descriptor_done = ixgbe_dev_rx_descriptor_done,
492 .tx_queue_setup = ixgbe_dev_tx_queue_setup,
493 .tx_queue_release = ixgbe_dev_tx_queue_release,
494 .dev_led_on = ixgbe_dev_led_on,
495 .dev_led_off = ixgbe_dev_led_off,
496 .flow_ctrl_get = ixgbe_flow_ctrl_get,
497 .flow_ctrl_set = ixgbe_flow_ctrl_set,
498 .priority_flow_ctrl_set = ixgbe_priority_flow_ctrl_set,
499 .mac_addr_add = ixgbe_add_rar,
500 .mac_addr_remove = ixgbe_remove_rar,
501 .mac_addr_set = ixgbe_set_default_mac_addr,
502 .uc_hash_table_set = ixgbe_uc_hash_table_set,
503 .uc_all_hash_table_set = ixgbe_uc_all_hash_table_set,
504 .mirror_rule_set = ixgbe_mirror_rule_set,
505 .mirror_rule_reset = ixgbe_mirror_rule_reset,
506 .set_vf_rx_mode = ixgbe_set_pool_rx_mode,
507 .set_vf_rx = ixgbe_set_pool_rx,
508 .set_vf_tx = ixgbe_set_pool_tx,
509 .set_vf_vlan_filter = ixgbe_set_pool_vlan_filter,
510 .set_queue_rate_limit = ixgbe_set_queue_rate_limit,
511 .set_vf_rate_limit = ixgbe_set_vf_rate_limit,
512 .reta_update = ixgbe_dev_rss_reta_update,
513 .reta_query = ixgbe_dev_rss_reta_query,
514 #ifdef RTE_NIC_BYPASS
515 .bypass_init = ixgbe_bypass_init,
516 .bypass_state_set = ixgbe_bypass_state_store,
517 .bypass_state_show = ixgbe_bypass_state_show,
518 .bypass_event_set = ixgbe_bypass_event_store,
519 .bypass_event_show = ixgbe_bypass_event_show,
520 .bypass_wd_timeout_set = ixgbe_bypass_wd_timeout_store,
521 .bypass_wd_timeout_show = ixgbe_bypass_wd_timeout_show,
522 .bypass_ver_show = ixgbe_bypass_ver_show,
523 .bypass_wd_reset = ixgbe_bypass_wd_reset,
524 #endif /* RTE_NIC_BYPASS */
525 .rss_hash_update = ixgbe_dev_rss_hash_update,
526 .rss_hash_conf_get = ixgbe_dev_rss_hash_conf_get,
527 .filter_ctrl = ixgbe_dev_filter_ctrl,
528 .set_mc_addr_list = ixgbe_dev_set_mc_addr_list,
529 .rxq_info_get = ixgbe_rxq_info_get,
530 .txq_info_get = ixgbe_txq_info_get,
531 .timesync_enable = ixgbe_timesync_enable,
532 .timesync_disable = ixgbe_timesync_disable,
533 .timesync_read_rx_timestamp = ixgbe_timesync_read_rx_timestamp,
534 .timesync_read_tx_timestamp = ixgbe_timesync_read_tx_timestamp,
535 .get_reg_length = ixgbe_get_reg_length,
536 .get_reg = ixgbe_get_regs,
537 .get_eeprom_length = ixgbe_get_eeprom_length,
538 .get_eeprom = ixgbe_get_eeprom,
539 .set_eeprom = ixgbe_set_eeprom,
540 .get_dcb_info = ixgbe_dev_get_dcb_info,
541 .timesync_adjust_time = ixgbe_timesync_adjust_time,
542 .timesync_read_time = ixgbe_timesync_read_time,
543 .timesync_write_time = ixgbe_timesync_write_time,
544 .l2_tunnel_eth_type_conf = ixgbe_dev_l2_tunnel_eth_type_conf,
545 .l2_tunnel_offload_set = ixgbe_dev_l2_tunnel_offload_set,
546 .udp_tunnel_port_add = ixgbe_dev_udp_tunnel_port_add,
547 .udp_tunnel_port_del = ixgbe_dev_udp_tunnel_port_del,
551 * dev_ops for virtual function, bare necessities for basic vf
552 * operation have been implemented
554 static const struct eth_dev_ops ixgbevf_eth_dev_ops = {
555 .dev_configure = ixgbevf_dev_configure,
556 .dev_start = ixgbevf_dev_start,
557 .dev_stop = ixgbevf_dev_stop,
558 .link_update = ixgbe_dev_link_update,
559 .stats_get = ixgbevf_dev_stats_get,
560 .xstats_get = ixgbevf_dev_xstats_get,
561 .stats_reset = ixgbevf_dev_stats_reset,
562 .xstats_reset = ixgbevf_dev_stats_reset,
563 .xstats_get_names = ixgbevf_dev_xstats_get_names,
564 .dev_close = ixgbevf_dev_close,
565 .allmulticast_enable = ixgbevf_dev_allmulticast_enable,
566 .allmulticast_disable = ixgbevf_dev_allmulticast_disable,
567 .dev_infos_get = ixgbevf_dev_info_get,
568 .dev_supported_ptypes_get = ixgbe_dev_supported_ptypes_get,
569 .mtu_set = ixgbevf_dev_set_mtu,
570 .vlan_filter_set = ixgbevf_vlan_filter_set,
571 .vlan_strip_queue_set = ixgbevf_vlan_strip_queue_set,
572 .vlan_offload_set = ixgbevf_vlan_offload_set,
573 .rx_queue_setup = ixgbe_dev_rx_queue_setup,
574 .rx_queue_release = ixgbe_dev_rx_queue_release,
575 .rx_descriptor_done = ixgbe_dev_rx_descriptor_done,
576 .tx_queue_setup = ixgbe_dev_tx_queue_setup,
577 .tx_queue_release = ixgbe_dev_tx_queue_release,
578 .rx_queue_intr_enable = ixgbevf_dev_rx_queue_intr_enable,
579 .rx_queue_intr_disable = ixgbevf_dev_rx_queue_intr_disable,
580 .mac_addr_add = ixgbevf_add_mac_addr,
581 .mac_addr_remove = ixgbevf_remove_mac_addr,
582 .set_mc_addr_list = ixgbe_dev_set_mc_addr_list,
583 .rxq_info_get = ixgbe_rxq_info_get,
584 .txq_info_get = ixgbe_txq_info_get,
585 .mac_addr_set = ixgbevf_set_default_mac_addr,
586 .get_reg_length = ixgbevf_get_reg_length,
587 .get_reg = ixgbevf_get_regs,
588 .reta_update = ixgbe_dev_rss_reta_update,
589 .reta_query = ixgbe_dev_rss_reta_query,
590 .rss_hash_update = ixgbe_dev_rss_hash_update,
591 .rss_hash_conf_get = ixgbe_dev_rss_hash_conf_get,
594 /* store statistics names and its offset in stats structure */
595 struct rte_ixgbe_xstats_name_off {
596 char name[RTE_ETH_XSTATS_NAME_SIZE];
600 static const struct rte_ixgbe_xstats_name_off rte_ixgbe_stats_strings[] = {
601 {"rx_crc_errors", offsetof(struct ixgbe_hw_stats, crcerrs)},
602 {"rx_illegal_byte_errors", offsetof(struct ixgbe_hw_stats, illerrc)},
603 {"rx_error_bytes", offsetof(struct ixgbe_hw_stats, errbc)},
604 {"mac_local_errors", offsetof(struct ixgbe_hw_stats, mlfc)},
605 {"mac_remote_errors", offsetof(struct ixgbe_hw_stats, mrfc)},
606 {"rx_length_errors", offsetof(struct ixgbe_hw_stats, rlec)},
607 {"tx_xon_packets", offsetof(struct ixgbe_hw_stats, lxontxc)},
608 {"rx_xon_packets", offsetof(struct ixgbe_hw_stats, lxonrxc)},
609 {"tx_xoff_packets", offsetof(struct ixgbe_hw_stats, lxofftxc)},
610 {"rx_xoff_packets", offsetof(struct ixgbe_hw_stats, lxoffrxc)},
611 {"rx_size_64_packets", offsetof(struct ixgbe_hw_stats, prc64)},
612 {"rx_size_65_to_127_packets", offsetof(struct ixgbe_hw_stats, prc127)},
613 {"rx_size_128_to_255_packets", offsetof(struct ixgbe_hw_stats, prc255)},
614 {"rx_size_256_to_511_packets", offsetof(struct ixgbe_hw_stats, prc511)},
615 {"rx_size_512_to_1023_packets", offsetof(struct ixgbe_hw_stats,
617 {"rx_size_1024_to_max_packets", offsetof(struct ixgbe_hw_stats,
619 {"rx_broadcast_packets", offsetof(struct ixgbe_hw_stats, bprc)},
620 {"rx_multicast_packets", offsetof(struct ixgbe_hw_stats, mprc)},
621 {"rx_fragment_errors", offsetof(struct ixgbe_hw_stats, rfc)},
622 {"rx_undersize_errors", offsetof(struct ixgbe_hw_stats, ruc)},
623 {"rx_oversize_errors", offsetof(struct ixgbe_hw_stats, roc)},
624 {"rx_jabber_errors", offsetof(struct ixgbe_hw_stats, rjc)},
625 {"rx_management_packets", offsetof(struct ixgbe_hw_stats, mngprc)},
626 {"rx_management_dropped", offsetof(struct ixgbe_hw_stats, mngpdc)},
627 {"tx_management_packets", offsetof(struct ixgbe_hw_stats, mngptc)},
628 {"rx_total_packets", offsetof(struct ixgbe_hw_stats, tpr)},
629 {"rx_total_bytes", offsetof(struct ixgbe_hw_stats, tor)},
630 {"tx_total_packets", offsetof(struct ixgbe_hw_stats, tpt)},
631 {"tx_size_64_packets", offsetof(struct ixgbe_hw_stats, ptc64)},
632 {"tx_size_65_to_127_packets", offsetof(struct ixgbe_hw_stats, ptc127)},
633 {"tx_size_128_to_255_packets", offsetof(struct ixgbe_hw_stats, ptc255)},
634 {"tx_size_256_to_511_packets", offsetof(struct ixgbe_hw_stats, ptc511)},
635 {"tx_size_512_to_1023_packets", offsetof(struct ixgbe_hw_stats,
637 {"tx_size_1024_to_max_packets", offsetof(struct ixgbe_hw_stats,
639 {"tx_multicast_packets", offsetof(struct ixgbe_hw_stats, mptc)},
640 {"tx_broadcast_packets", offsetof(struct ixgbe_hw_stats, bptc)},
641 {"rx_mac_short_packet_dropped", offsetof(struct ixgbe_hw_stats, mspdc)},
642 {"rx_l3_l4_xsum_error", offsetof(struct ixgbe_hw_stats, xec)},
644 {"flow_director_added_filters", offsetof(struct ixgbe_hw_stats,
646 {"flow_director_removed_filters", offsetof(struct ixgbe_hw_stats,
648 {"flow_director_filter_add_errors", offsetof(struct ixgbe_hw_stats,
650 {"flow_director_filter_remove_errors", offsetof(struct ixgbe_hw_stats,
652 {"flow_director_matched_filters", offsetof(struct ixgbe_hw_stats,
654 {"flow_director_missed_filters", offsetof(struct ixgbe_hw_stats,
657 {"rx_fcoe_crc_errors", offsetof(struct ixgbe_hw_stats, fccrc)},
658 {"rx_fcoe_dropped", offsetof(struct ixgbe_hw_stats, fcoerpdc)},
659 {"rx_fcoe_mbuf_allocation_errors", offsetof(struct ixgbe_hw_stats,
661 {"rx_fcoe_packets", offsetof(struct ixgbe_hw_stats, fcoeprc)},
662 {"tx_fcoe_packets", offsetof(struct ixgbe_hw_stats, fcoeptc)},
663 {"rx_fcoe_bytes", offsetof(struct ixgbe_hw_stats, fcoedwrc)},
664 {"tx_fcoe_bytes", offsetof(struct ixgbe_hw_stats, fcoedwtc)},
665 {"rx_fcoe_no_direct_data_placement", offsetof(struct ixgbe_hw_stats,
667 {"rx_fcoe_no_direct_data_placement_ext_buff",
668 offsetof(struct ixgbe_hw_stats, fcoe_noddp_ext_buff)},
670 {"tx_flow_control_xon_packets", offsetof(struct ixgbe_hw_stats,
672 {"rx_flow_control_xon_packets", offsetof(struct ixgbe_hw_stats,
674 {"tx_flow_control_xoff_packets", offsetof(struct ixgbe_hw_stats,
676 {"rx_flow_control_xoff_packets", offsetof(struct ixgbe_hw_stats,
678 {"rx_total_missed_packets", offsetof(struct ixgbe_hw_stats, mpctotal)},
681 #define IXGBE_NB_HW_STATS (sizeof(rte_ixgbe_stats_strings) / \
682 sizeof(rte_ixgbe_stats_strings[0]))
684 /* Per-queue statistics */
685 static const struct rte_ixgbe_xstats_name_off rte_ixgbe_rxq_strings[] = {
686 {"mbuf_allocation_errors", offsetof(struct ixgbe_hw_stats, rnbc)},
687 {"dropped", offsetof(struct ixgbe_hw_stats, mpc)},
688 {"xon_packets", offsetof(struct ixgbe_hw_stats, pxonrxc)},
689 {"xoff_packets", offsetof(struct ixgbe_hw_stats, pxoffrxc)},
692 #define IXGBE_NB_RXQ_PRIO_STATS (sizeof(rte_ixgbe_rxq_strings) / \
693 sizeof(rte_ixgbe_rxq_strings[0]))
694 #define IXGBE_NB_RXQ_PRIO_VALUES 8
696 static const struct rte_ixgbe_xstats_name_off rte_ixgbe_txq_strings[] = {
697 {"xon_packets", offsetof(struct ixgbe_hw_stats, pxontxc)},
698 {"xoff_packets", offsetof(struct ixgbe_hw_stats, pxofftxc)},
699 {"xon_to_xoff_packets", offsetof(struct ixgbe_hw_stats,
703 #define IXGBE_NB_TXQ_PRIO_STATS (sizeof(rte_ixgbe_txq_strings) / \
704 sizeof(rte_ixgbe_txq_strings[0]))
705 #define IXGBE_NB_TXQ_PRIO_VALUES 8
707 static const struct rte_ixgbe_xstats_name_off rte_ixgbevf_stats_strings[] = {
708 {"rx_multicast_packets", offsetof(struct ixgbevf_hw_stats, vfmprc)},
711 #define IXGBEVF_NB_XSTATS (sizeof(rte_ixgbevf_stats_strings) / \
712 sizeof(rte_ixgbevf_stats_strings[0]))
715 * Atomically reads the link status information from global
716 * structure rte_eth_dev.
719 * - Pointer to the structure rte_eth_dev to read from.
720 * - Pointer to the buffer to be saved with the link status.
723 * - On success, zero.
724 * - On failure, negative value.
727 rte_ixgbe_dev_atomic_read_link_status(struct rte_eth_dev *dev,
728 struct rte_eth_link *link)
730 struct rte_eth_link *dst = link;
731 struct rte_eth_link *src = &(dev->data->dev_link);
733 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
734 *(uint64_t *)src) == 0)
741 * Atomically writes the link status information into global
742 * structure rte_eth_dev.
745 * - Pointer to the structure rte_eth_dev to read from.
746 * - Pointer to the buffer to be saved with the link status.
749 * - On success, zero.
750 * - On failure, negative value.
753 rte_ixgbe_dev_atomic_write_link_status(struct rte_eth_dev *dev,
754 struct rte_eth_link *link)
756 struct rte_eth_link *dst = &(dev->data->dev_link);
757 struct rte_eth_link *src = link;
759 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
760 *(uint64_t *)src) == 0)
767 * This function is the same as ixgbe_is_sfp() in base/ixgbe.h.
770 ixgbe_is_sfp(struct ixgbe_hw *hw)
772 switch (hw->phy.type) {
773 case ixgbe_phy_sfp_avago:
774 case ixgbe_phy_sfp_ftl:
775 case ixgbe_phy_sfp_intel:
776 case ixgbe_phy_sfp_unknown:
777 case ixgbe_phy_sfp_passive_tyco:
778 case ixgbe_phy_sfp_passive_unknown:
785 static inline int32_t
786 ixgbe_pf_reset_hw(struct ixgbe_hw *hw)
791 status = ixgbe_reset_hw(hw);
793 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
794 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
795 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
796 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
797 IXGBE_WRITE_FLUSH(hw);
803 ixgbe_enable_intr(struct rte_eth_dev *dev)
805 struct ixgbe_interrupt *intr =
806 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
807 struct ixgbe_hw *hw =
808 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
810 IXGBE_WRITE_REG(hw, IXGBE_EIMS, intr->mask);
811 IXGBE_WRITE_FLUSH(hw);
815 * This function is based on ixgbe_disable_intr() in base/ixgbe.h.
818 ixgbe_disable_intr(struct ixgbe_hw *hw)
820 PMD_INIT_FUNC_TRACE();
822 if (hw->mac.type == ixgbe_mac_82598EB) {
823 IXGBE_WRITE_REG(hw, IXGBE_EIMC, ~0);
825 IXGBE_WRITE_REG(hw, IXGBE_EIMC, 0xFFFF0000);
826 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), ~0);
827 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), ~0);
829 IXGBE_WRITE_FLUSH(hw);
833 * This function resets queue statistics mapping registers.
834 * From Niantic datasheet, Initialization of Statistics section:
835 * "...if software requires the queue counters, the RQSMR and TQSM registers
836 * must be re-programmed following a device reset.
839 ixgbe_reset_qstat_mappings(struct ixgbe_hw *hw)
843 for (i = 0; i != IXGBE_NB_STAT_MAPPING_REGS; i++) {
844 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), 0);
845 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), 0);
851 ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
856 #define QSM_REG_NB_BITS_PER_QMAP_FIELD 8
857 #define NB_QMAP_FIELDS_PER_QSM_REG 4
858 #define QMAP_FIELD_RESERVED_BITS_MASK 0x0f
860 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
861 struct ixgbe_stat_mapping_registers *stat_mappings =
862 IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(eth_dev->data->dev_private);
863 uint32_t qsmr_mask = 0;
864 uint32_t clearing_mask = QMAP_FIELD_RESERVED_BITS_MASK;
868 if ((hw->mac.type != ixgbe_mac_82599EB) &&
869 (hw->mac.type != ixgbe_mac_X540) &&
870 (hw->mac.type != ixgbe_mac_X550) &&
871 (hw->mac.type != ixgbe_mac_X550EM_x) &&
872 (hw->mac.type != ixgbe_mac_X550EM_a))
875 PMD_INIT_LOG(DEBUG, "Setting port %d, %s queue_id %d to stat index %d",
876 (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
879 n = (uint8_t)(queue_id / NB_QMAP_FIELDS_PER_QSM_REG);
880 if (n >= IXGBE_NB_STAT_MAPPING_REGS) {
881 PMD_INIT_LOG(ERR, "Nb of stat mapping registers exceeded");
884 offset = (uint8_t)(queue_id % NB_QMAP_FIELDS_PER_QSM_REG);
886 /* Now clear any previous stat_idx set */
887 clearing_mask <<= (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
889 stat_mappings->tqsm[n] &= ~clearing_mask;
891 stat_mappings->rqsmr[n] &= ~clearing_mask;
893 q_map = (uint32_t)stat_idx;
894 q_map &= QMAP_FIELD_RESERVED_BITS_MASK;
895 qsmr_mask = q_map << (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
897 stat_mappings->tqsm[n] |= qsmr_mask;
899 stat_mappings->rqsmr[n] |= qsmr_mask;
901 PMD_INIT_LOG(DEBUG, "Set port %d, %s queue_id %d to stat index %d",
902 (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
904 PMD_INIT_LOG(DEBUG, "%s[%d] = 0x%08x", is_rx ? "RQSMR" : "TQSM", n,
905 is_rx ? stat_mappings->rqsmr[n] : stat_mappings->tqsm[n]);
907 /* Now write the mapping in the appropriate register */
909 PMD_INIT_LOG(DEBUG, "Write 0x%x to RX IXGBE stat mapping reg:%d",
910 stat_mappings->rqsmr[n], n);
911 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(n), stat_mappings->rqsmr[n]);
913 PMD_INIT_LOG(DEBUG, "Write 0x%x to TX IXGBE stat mapping reg:%d",
914 stat_mappings->tqsm[n], n);
915 IXGBE_WRITE_REG(hw, IXGBE_TQSM(n), stat_mappings->tqsm[n]);
921 ixgbe_restore_statistics_mapping(struct rte_eth_dev *dev)
923 struct ixgbe_stat_mapping_registers *stat_mappings =
924 IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(dev->data->dev_private);
925 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
928 /* write whatever was in stat mapping table to the NIC */
929 for (i = 0; i < IXGBE_NB_STAT_MAPPING_REGS; i++) {
931 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), stat_mappings->rqsmr[i]);
934 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), stat_mappings->tqsm[i]);
939 ixgbe_dcb_init(struct ixgbe_hw *hw, struct ixgbe_dcb_config *dcb_config)
942 struct ixgbe_dcb_tc_config *tc;
943 uint8_t dcb_max_tc = IXGBE_DCB_MAX_TRAFFIC_CLASS;
945 dcb_config->num_tcs.pg_tcs = dcb_max_tc;
946 dcb_config->num_tcs.pfc_tcs = dcb_max_tc;
947 for (i = 0; i < dcb_max_tc; i++) {
948 tc = &dcb_config->tc_config[i];
949 tc->path[IXGBE_DCB_TX_CONFIG].bwg_id = i;
950 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
951 (uint8_t)(100/dcb_max_tc + (i & 1));
952 tc->path[IXGBE_DCB_RX_CONFIG].bwg_id = i;
953 tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
954 (uint8_t)(100/dcb_max_tc + (i & 1));
955 tc->pfc = ixgbe_dcb_pfc_disabled;
958 /* Initialize default user to priority mapping, UPx->TC0 */
959 tc = &dcb_config->tc_config[0];
960 tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
961 tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
962 for (i = 0; i < IXGBE_DCB_MAX_BW_GROUP; i++) {
963 dcb_config->bw_percentage[IXGBE_DCB_TX_CONFIG][i] = 100;
964 dcb_config->bw_percentage[IXGBE_DCB_RX_CONFIG][i] = 100;
966 dcb_config->rx_pba_cfg = ixgbe_dcb_pba_equal;
967 dcb_config->pfc_mode_enable = false;
968 dcb_config->vt_mode = true;
969 dcb_config->round_robin_enable = false;
970 /* support all DCB capabilities in 82599 */
971 dcb_config->support.capabilities = 0xFF;
973 /*we only support 4 Tcs for X540, X550 */
974 if (hw->mac.type == ixgbe_mac_X540 ||
975 hw->mac.type == ixgbe_mac_X550 ||
976 hw->mac.type == ixgbe_mac_X550EM_x ||
977 hw->mac.type == ixgbe_mac_X550EM_a) {
978 dcb_config->num_tcs.pg_tcs = 4;
979 dcb_config->num_tcs.pfc_tcs = 4;
984 * Ensure that all locks are released before first NVM or PHY access
987 ixgbe_swfw_lock_reset(struct ixgbe_hw *hw)
992 * Phy lock should not fail in this early stage. If this is the case,
993 * it is due to an improper exit of the application.
994 * So force the release of the faulty lock. Release of common lock
995 * is done automatically by swfw_sync function.
997 mask = IXGBE_GSSR_PHY0_SM << hw->bus.func;
998 if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
999 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released", hw->bus.func);
1001 ixgbe_release_swfw_semaphore(hw, mask);
1004 * These ones are more tricky since they are common to all ports; but
1005 * swfw_sync retries last long enough (1s) to be almost sure that if
1006 * lock can not be taken it is due to an improper lock of the
1009 mask = IXGBE_GSSR_EEP_SM | IXGBE_GSSR_MAC_CSR_SM | IXGBE_GSSR_SW_MNG_SM;
1010 if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
1011 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
1013 ixgbe_release_swfw_semaphore(hw, mask);
1017 * This function is based on code in ixgbe_attach() in base/ixgbe.c.
1018 * It returns 0 on success.
1021 eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
1023 struct rte_pci_device *pci_dev;
1024 struct ixgbe_hw *hw =
1025 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1026 struct ixgbe_vfta *shadow_vfta =
1027 IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
1028 struct ixgbe_hwstrip *hwstrip =
1029 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
1030 struct ixgbe_dcb_config *dcb_config =
1031 IXGBE_DEV_PRIVATE_TO_DCB_CFG(eth_dev->data->dev_private);
1032 struct ixgbe_filter_info *filter_info =
1033 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
1038 PMD_INIT_FUNC_TRACE();
1040 eth_dev->dev_ops = &ixgbe_eth_dev_ops;
1041 eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
1042 eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
1045 * For secondary processes, we don't initialise any further as primary
1046 * has already done this work. Only check we don't need a different
1047 * RX and TX function.
1049 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1050 struct ixgbe_tx_queue *txq;
1051 /* TX queue function in primary, set by last queue initialized
1052 * Tx queue may not initialized by primary process
1054 if (eth_dev->data->tx_queues) {
1055 txq = eth_dev->data->tx_queues[eth_dev->data->nb_tx_queues-1];
1056 ixgbe_set_tx_function(eth_dev, txq);
1058 /* Use default TX function if we get here */
1059 PMD_INIT_LOG(NOTICE, "No TX queues configured yet. "
1060 "Using default TX function.");
1063 ixgbe_set_rx_function(eth_dev);
1067 pci_dev = eth_dev->pci_dev;
1069 rte_eth_copy_pci_info(eth_dev, pci_dev);
1071 /* Vendor and Device ID need to be set before init of shared code */
1072 hw->device_id = pci_dev->id.device_id;
1073 hw->vendor_id = pci_dev->id.vendor_id;
1074 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1075 hw->allow_unsupported_sfp = 1;
1077 /* Initialize the shared code (base driver) */
1078 #ifdef RTE_NIC_BYPASS
1079 diag = ixgbe_bypass_init_shared_code(hw);
1081 diag = ixgbe_init_shared_code(hw);
1082 #endif /* RTE_NIC_BYPASS */
1084 if (diag != IXGBE_SUCCESS) {
1085 PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
1089 /* pick up the PCI bus settings for reporting later */
1090 ixgbe_get_bus_info(hw);
1092 /* Unlock any pending hardware semaphore */
1093 ixgbe_swfw_lock_reset(hw);
1095 /* Initialize DCB configuration*/
1096 memset(dcb_config, 0, sizeof(struct ixgbe_dcb_config));
1097 ixgbe_dcb_init(hw, dcb_config);
1098 /* Get Hardware Flow Control setting */
1099 hw->fc.requested_mode = ixgbe_fc_full;
1100 hw->fc.current_mode = ixgbe_fc_full;
1101 hw->fc.pause_time = IXGBE_FC_PAUSE;
1102 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
1103 hw->fc.low_water[i] = IXGBE_FC_LO;
1104 hw->fc.high_water[i] = IXGBE_FC_HI;
1106 hw->fc.send_xon = 1;
1108 /* Make sure we have a good EEPROM before we read from it */
1109 diag = ixgbe_validate_eeprom_checksum(hw, &csum);
1110 if (diag != IXGBE_SUCCESS) {
1111 PMD_INIT_LOG(ERR, "The EEPROM checksum is not valid: %d", diag);
1115 #ifdef RTE_NIC_BYPASS
1116 diag = ixgbe_bypass_init_hw(hw);
1118 diag = ixgbe_init_hw(hw);
1119 #endif /* RTE_NIC_BYPASS */
1122 * Devices with copper phys will fail to initialise if ixgbe_init_hw()
1123 * is called too soon after the kernel driver unbinding/binding occurs.
1124 * The failure occurs in ixgbe_identify_phy_generic() for all devices,
1125 * but for non-copper devies, ixgbe_identify_sfp_module_generic() is
1126 * also called. See ixgbe_identify_phy_82599(). The reason for the
1127 * failure is not known, and only occuts when virtualisation features
1128 * are disabled in the bios. A delay of 100ms was found to be enough by
1129 * trial-and-error, and is doubled to be safe.
1131 if (diag && (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)) {
1133 diag = ixgbe_init_hw(hw);
1136 if (diag == IXGBE_ERR_EEPROM_VERSION) {
1137 PMD_INIT_LOG(ERR, "This device is a pre-production adapter/"
1138 "LOM. Please be aware there may be issues associated "
1139 "with your hardware.");
1140 PMD_INIT_LOG(ERR, "If you are experiencing problems "
1141 "please contact your Intel or hardware representative "
1142 "who provided you with this hardware.");
1143 } else if (diag == IXGBE_ERR_SFP_NOT_SUPPORTED)
1144 PMD_INIT_LOG(ERR, "Unsupported SFP+ Module");
1146 PMD_INIT_LOG(ERR, "Hardware Initialization Failure: %d", diag);
1150 /* Reset the hw statistics */
1151 ixgbe_dev_stats_reset(eth_dev);
1153 /* disable interrupt */
1154 ixgbe_disable_intr(hw);
1156 /* reset mappings for queue statistics hw counters*/
1157 ixgbe_reset_qstat_mappings(hw);
1159 /* Allocate memory for storing MAC addresses */
1160 eth_dev->data->mac_addrs = rte_zmalloc("ixgbe", ETHER_ADDR_LEN *
1161 hw->mac.num_rar_entries, 0);
1162 if (eth_dev->data->mac_addrs == NULL) {
1164 "Failed to allocate %u bytes needed to store "
1166 ETHER_ADDR_LEN * hw->mac.num_rar_entries);
1169 /* Copy the permanent MAC address */
1170 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
1171 ð_dev->data->mac_addrs[0]);
1173 /* Allocate memory for storing hash filter MAC addresses */
1174 eth_dev->data->hash_mac_addrs = rte_zmalloc("ixgbe", ETHER_ADDR_LEN *
1175 IXGBE_VMDQ_NUM_UC_MAC, 0);
1176 if (eth_dev->data->hash_mac_addrs == NULL) {
1178 "Failed to allocate %d bytes needed to store MAC addresses",
1179 ETHER_ADDR_LEN * IXGBE_VMDQ_NUM_UC_MAC);
1183 /* initialize the vfta */
1184 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
1186 /* initialize the hw strip bitmap*/
1187 memset(hwstrip, 0, sizeof(*hwstrip));
1189 /* initialize PF if max_vfs not zero */
1190 ixgbe_pf_host_init(eth_dev);
1192 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
1193 /* let hardware know driver is loaded */
1194 ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
1195 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1196 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
1197 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
1198 IXGBE_WRITE_FLUSH(hw);
1200 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
1201 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d, SFP+: %d",
1202 (int) hw->mac.type, (int) hw->phy.type,
1203 (int) hw->phy.sfp_type);
1205 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d",
1206 (int) hw->mac.type, (int) hw->phy.type);
1208 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
1209 eth_dev->data->port_id, pci_dev->id.vendor_id,
1210 pci_dev->id.device_id);
1212 rte_intr_callback_register(&pci_dev->intr_handle,
1213 ixgbe_dev_interrupt_handler,
1216 /* enable uio/vfio intr/eventfd mapping */
1217 rte_intr_enable(&pci_dev->intr_handle);
1219 /* enable support intr */
1220 ixgbe_enable_intr(eth_dev);
1222 /* initialize 5tuple filter list */
1223 TAILQ_INIT(&filter_info->fivetuple_list);
1224 memset(filter_info->fivetuple_mask, 0,
1225 sizeof(uint32_t) * IXGBE_5TUPLE_ARRAY_SIZE);
1231 eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
1233 struct rte_pci_device *pci_dev;
1234 struct ixgbe_hw *hw;
1236 PMD_INIT_FUNC_TRACE();
1238 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1241 hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1242 pci_dev = eth_dev->pci_dev;
1244 if (hw->adapter_stopped == 0)
1245 ixgbe_dev_close(eth_dev);
1247 eth_dev->dev_ops = NULL;
1248 eth_dev->rx_pkt_burst = NULL;
1249 eth_dev->tx_pkt_burst = NULL;
1251 /* Unlock any pending hardware semaphore */
1252 ixgbe_swfw_lock_reset(hw);
1254 /* disable uio intr before callback unregister */
1255 rte_intr_disable(&(pci_dev->intr_handle));
1256 rte_intr_callback_unregister(&(pci_dev->intr_handle),
1257 ixgbe_dev_interrupt_handler, (void *)eth_dev);
1259 /* uninitialize PF if max_vfs not zero */
1260 ixgbe_pf_host_uninit(eth_dev);
1262 rte_free(eth_dev->data->mac_addrs);
1263 eth_dev->data->mac_addrs = NULL;
1265 rte_free(eth_dev->data->hash_mac_addrs);
1266 eth_dev->data->hash_mac_addrs = NULL;
1272 * Negotiate mailbox API version with the PF.
1273 * After reset API version is always set to the basic one (ixgbe_mbox_api_10).
1274 * Then we try to negotiate starting with the most recent one.
1275 * If all negotiation attempts fail, then we will proceed with
1276 * the default one (ixgbe_mbox_api_10).
1279 ixgbevf_negotiate_api(struct ixgbe_hw *hw)
1283 /* start with highest supported, proceed down */
1284 static const enum ixgbe_pfvf_api_rev sup_ver[] = {
1291 i != RTE_DIM(sup_ver) &&
1292 ixgbevf_negotiate_api_version(hw, sup_ver[i]) != 0;
1298 generate_random_mac_addr(struct ether_addr *mac_addr)
1302 /* Set Organizationally Unique Identifier (OUI) prefix. */
1303 mac_addr->addr_bytes[0] = 0x00;
1304 mac_addr->addr_bytes[1] = 0x09;
1305 mac_addr->addr_bytes[2] = 0xC0;
1306 /* Force indication of locally assigned MAC address. */
1307 mac_addr->addr_bytes[0] |= ETHER_LOCAL_ADMIN_ADDR;
1308 /* Generate the last 3 bytes of the MAC address with a random number. */
1309 random = rte_rand();
1310 memcpy(&mac_addr->addr_bytes[3], &random, 3);
1314 * Virtual Function device init
1317 eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
1321 struct rte_pci_device *pci_dev;
1322 struct ixgbe_hw *hw =
1323 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1324 struct ixgbe_vfta *shadow_vfta =
1325 IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
1326 struct ixgbe_hwstrip *hwstrip =
1327 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
1328 struct ether_addr *perm_addr = (struct ether_addr *) hw->mac.perm_addr;
1330 PMD_INIT_FUNC_TRACE();
1332 eth_dev->dev_ops = &ixgbevf_eth_dev_ops;
1333 eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
1334 eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
1336 /* for secondary processes, we don't initialise any further as primary
1337 * has already done this work. Only check we don't need a different
1340 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1341 struct ixgbe_tx_queue *txq;
1342 /* TX queue function in primary, set by last queue initialized
1343 * Tx queue may not initialized by primary process
1345 if (eth_dev->data->tx_queues) {
1346 txq = eth_dev->data->tx_queues[eth_dev->data->nb_tx_queues - 1];
1347 ixgbe_set_tx_function(eth_dev, txq);
1349 /* Use default TX function if we get here */
1350 PMD_INIT_LOG(NOTICE,
1351 "No TX queues configured yet. Using default TX function.");
1354 ixgbe_set_rx_function(eth_dev);
1359 pci_dev = eth_dev->pci_dev;
1361 rte_eth_copy_pci_info(eth_dev, pci_dev);
1363 hw->device_id = pci_dev->id.device_id;
1364 hw->vendor_id = pci_dev->id.vendor_id;
1365 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1367 /* initialize the vfta */
1368 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
1370 /* initialize the hw strip bitmap*/
1371 memset(hwstrip, 0, sizeof(*hwstrip));
1373 /* Initialize the shared code (base driver) */
1374 diag = ixgbe_init_shared_code(hw);
1375 if (diag != IXGBE_SUCCESS) {
1376 PMD_INIT_LOG(ERR, "Shared code init failed for ixgbevf: %d", diag);
1380 /* init_mailbox_params */
1381 hw->mbx.ops.init_params(hw);
1383 /* Reset the hw statistics */
1384 ixgbevf_dev_stats_reset(eth_dev);
1386 /* Disable the interrupts for VF */
1387 ixgbevf_intr_disable(hw);
1389 hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
1390 diag = hw->mac.ops.reset_hw(hw);
1393 * The VF reset operation returns the IXGBE_ERR_INVALID_MAC_ADDR when
1394 * the underlying PF driver has not assigned a MAC address to the VF.
1395 * In this case, assign a random MAC address.
1397 if ((diag != IXGBE_SUCCESS) && (diag != IXGBE_ERR_INVALID_MAC_ADDR)) {
1398 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
1402 /* negotiate mailbox API version to use with the PF. */
1403 ixgbevf_negotiate_api(hw);
1405 /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
1406 ixgbevf_get_queues(hw, &tcs, &tc);
1408 /* Allocate memory for storing MAC addresses */
1409 eth_dev->data->mac_addrs = rte_zmalloc("ixgbevf", ETHER_ADDR_LEN *
1410 hw->mac.num_rar_entries, 0);
1411 if (eth_dev->data->mac_addrs == NULL) {
1413 "Failed to allocate %u bytes needed to store "
1415 ETHER_ADDR_LEN * hw->mac.num_rar_entries);
1419 /* Generate a random MAC address, if none was assigned by PF. */
1420 if (is_zero_ether_addr(perm_addr)) {
1421 generate_random_mac_addr(perm_addr);
1422 diag = ixgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
1424 rte_free(eth_dev->data->mac_addrs);
1425 eth_dev->data->mac_addrs = NULL;
1428 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1429 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1430 "%02x:%02x:%02x:%02x:%02x:%02x",
1431 perm_addr->addr_bytes[0],
1432 perm_addr->addr_bytes[1],
1433 perm_addr->addr_bytes[2],
1434 perm_addr->addr_bytes[3],
1435 perm_addr->addr_bytes[4],
1436 perm_addr->addr_bytes[5]);
1439 /* Copy the permanent MAC address */
1440 ether_addr_copy(perm_addr, ð_dev->data->mac_addrs[0]);
1442 /* reset the hardware with the new settings */
1443 diag = hw->mac.ops.start_hw(hw);
1449 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
1453 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
1454 eth_dev->data->port_id, pci_dev->id.vendor_id,
1455 pci_dev->id.device_id, "ixgbe_mac_82599_vf");
1460 /* Virtual Function device uninit */
1463 eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
1465 struct ixgbe_hw *hw;
1467 PMD_INIT_FUNC_TRACE();
1469 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1472 hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1474 if (hw->adapter_stopped == 0)
1475 ixgbevf_dev_close(eth_dev);
1477 eth_dev->dev_ops = NULL;
1478 eth_dev->rx_pkt_burst = NULL;
1479 eth_dev->tx_pkt_burst = NULL;
1481 /* Disable the interrupts for VF */
1482 ixgbevf_intr_disable(hw);
1484 rte_free(eth_dev->data->mac_addrs);
1485 eth_dev->data->mac_addrs = NULL;
1490 static struct eth_driver rte_ixgbe_pmd = {
1492 .name = "rte_ixgbe_pmd",
1493 .id_table = pci_id_ixgbe_map,
1494 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
1495 RTE_PCI_DRV_DETACHABLE,
1497 .eth_dev_init = eth_ixgbe_dev_init,
1498 .eth_dev_uninit = eth_ixgbe_dev_uninit,
1499 .dev_private_size = sizeof(struct ixgbe_adapter),
1503 * virtual function driver struct
1505 static struct eth_driver rte_ixgbevf_pmd = {
1507 .name = "rte_ixgbevf_pmd",
1508 .id_table = pci_id_ixgbevf_map,
1509 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
1511 .eth_dev_init = eth_ixgbevf_dev_init,
1512 .eth_dev_uninit = eth_ixgbevf_dev_uninit,
1513 .dev_private_size = sizeof(struct ixgbe_adapter),
1517 * Driver initialization routine.
1518 * Invoked once at EAL init time.
1519 * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
1522 rte_ixgbe_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
1524 PMD_INIT_FUNC_TRACE();
1526 rte_eth_driver_register(&rte_ixgbe_pmd);
1531 * VF Driver initialization routine.
1532 * Invoked one at EAL init time.
1533 * Register itself as the [Virtual Poll Mode] Driver of PCI niantic devices.
1536 rte_ixgbevf_pmd_init(const char *name __rte_unused, const char *param __rte_unused)
1538 PMD_INIT_FUNC_TRACE();
1540 rte_eth_driver_register(&rte_ixgbevf_pmd);
1545 ixgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1547 struct ixgbe_hw *hw =
1548 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1549 struct ixgbe_vfta *shadow_vfta =
1550 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1555 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
1556 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
1557 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(vid_idx));
1562 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vid_idx), vfta);
1564 /* update local VFTA copy */
1565 shadow_vfta->vfta[vid_idx] = vfta;
1571 ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
1574 ixgbe_vlan_hw_strip_enable(dev, queue);
1576 ixgbe_vlan_hw_strip_disable(dev, queue);
1580 ixgbe_vlan_tpid_set(struct rte_eth_dev *dev,
1581 enum rte_vlan_type vlan_type,
1584 struct ixgbe_hw *hw =
1585 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1588 switch (vlan_type) {
1589 case ETH_VLAN_TYPE_INNER:
1590 /* Only the high 16-bits is valid */
1591 IXGBE_WRITE_REG(hw, IXGBE_EXVET, tpid << 16);
1595 PMD_DRV_LOG(ERR, "Unsupported vlan type %d\n", vlan_type);
1603 ixgbe_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1605 struct ixgbe_hw *hw =
1606 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1609 PMD_INIT_FUNC_TRACE();
1611 /* Filter Table Disable */
1612 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1613 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
1615 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1619 ixgbe_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1621 struct ixgbe_hw *hw =
1622 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1623 struct ixgbe_vfta *shadow_vfta =
1624 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1628 PMD_INIT_FUNC_TRACE();
1630 /* Filter Table Enable */
1631 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1632 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1633 vlnctrl |= IXGBE_VLNCTRL_VFE;
1635 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1637 /* write whatever is in local vfta copy */
1638 for (i = 0; i < IXGBE_VFTA_SIZE; i++)
1639 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), shadow_vfta->vfta[i]);
1643 ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev, uint16_t queue, bool on)
1645 struct ixgbe_hwstrip *hwstrip =
1646 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(dev->data->dev_private);
1647 struct ixgbe_rx_queue *rxq;
1649 if (queue >= IXGBE_MAX_RX_QUEUE_NUM)
1653 IXGBE_SET_HWSTRIP(hwstrip, queue);
1655 IXGBE_CLEAR_HWSTRIP(hwstrip, queue);
1657 if (queue >= dev->data->nb_rx_queues)
1660 rxq = dev->data->rx_queues[queue];
1663 rxq->vlan_flags = PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED;
1665 rxq->vlan_flags = PKT_RX_VLAN_PKT;
1669 ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue)
1671 struct ixgbe_hw *hw =
1672 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1675 PMD_INIT_FUNC_TRACE();
1677 if (hw->mac.type == ixgbe_mac_82598EB) {
1678 /* No queue level support */
1679 PMD_INIT_LOG(NOTICE, "82598EB not support queue level hw strip");
1683 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1684 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
1685 ctrl &= ~IXGBE_RXDCTL_VME;
1686 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
1688 /* record those setting for HW strip per queue */
1689 ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 0);
1693 ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue)
1695 struct ixgbe_hw *hw =
1696 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1699 PMD_INIT_FUNC_TRACE();
1701 if (hw->mac.type == ixgbe_mac_82598EB) {
1702 /* No queue level supported */
1703 PMD_INIT_LOG(NOTICE, "82598EB not support queue level hw strip");
1707 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1708 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
1709 ctrl |= IXGBE_RXDCTL_VME;
1710 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
1712 /* record those setting for HW strip per queue */
1713 ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 1);
1717 ixgbe_vlan_hw_strip_disable_all(struct rte_eth_dev *dev)
1719 struct ixgbe_hw *hw =
1720 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1724 PMD_INIT_FUNC_TRACE();
1726 if (hw->mac.type == ixgbe_mac_82598EB) {
1727 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1728 ctrl &= ~IXGBE_VLNCTRL_VME;
1729 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
1731 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1732 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1733 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1734 ctrl &= ~IXGBE_RXDCTL_VME;
1735 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), ctrl);
1737 /* record those setting for HW strip per queue */
1738 ixgbe_vlan_hw_strip_bitmap_set(dev, i, 0);
1744 ixgbe_vlan_hw_strip_enable_all(struct rte_eth_dev *dev)
1746 struct ixgbe_hw *hw =
1747 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1751 PMD_INIT_FUNC_TRACE();
1753 if (hw->mac.type == ixgbe_mac_82598EB) {
1754 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1755 ctrl |= IXGBE_VLNCTRL_VME;
1756 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
1758 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1759 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1760 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1761 ctrl |= IXGBE_RXDCTL_VME;
1762 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), ctrl);
1764 /* record those setting for HW strip per queue */
1765 ixgbe_vlan_hw_strip_bitmap_set(dev, i, 1);
1771 ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev)
1773 struct ixgbe_hw *hw =
1774 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1777 PMD_INIT_FUNC_TRACE();
1779 /* DMATXCTRL: Geric Double VLAN Disable */
1780 ctrl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1781 ctrl &= ~IXGBE_DMATXCTL_GDV;
1782 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
1784 /* CTRL_EXT: Global Double VLAN Disable */
1785 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
1786 ctrl &= ~IXGBE_EXTENDED_VLAN;
1787 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
1792 ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev)
1794 struct ixgbe_hw *hw =
1795 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1798 PMD_INIT_FUNC_TRACE();
1800 /* DMATXCTRL: Geric Double VLAN Enable */
1801 ctrl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1802 ctrl |= IXGBE_DMATXCTL_GDV;
1803 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
1805 /* CTRL_EXT: Global Double VLAN Enable */
1806 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
1807 ctrl |= IXGBE_EXTENDED_VLAN;
1808 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
1810 /* Clear pooling mode of PFVTCTL. It's required by X550. */
1811 if (hw->mac.type == ixgbe_mac_X550 ||
1812 hw->mac.type == ixgbe_mac_X550EM_x ||
1813 hw->mac.type == ixgbe_mac_X550EM_a) {
1814 ctrl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
1815 ctrl &= ~IXGBE_VT_CTL_POOLING_MODE_MASK;
1816 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, ctrl);
1820 * VET EXT field in the EXVET register = 0x8100 by default
1821 * So no need to change. Same to VT field of DMATXCTL register
1826 ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1828 if (mask & ETH_VLAN_STRIP_MASK) {
1829 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1830 ixgbe_vlan_hw_strip_enable_all(dev);
1832 ixgbe_vlan_hw_strip_disable_all(dev);
1835 if (mask & ETH_VLAN_FILTER_MASK) {
1836 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1837 ixgbe_vlan_hw_filter_enable(dev);
1839 ixgbe_vlan_hw_filter_disable(dev);
1842 if (mask & ETH_VLAN_EXTEND_MASK) {
1843 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1844 ixgbe_vlan_hw_extend_enable(dev);
1846 ixgbe_vlan_hw_extend_disable(dev);
1851 ixgbe_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1853 struct ixgbe_hw *hw =
1854 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1855 /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
1856 uint32_t vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1858 vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
1859 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
1863 ixgbe_check_vf_rss_rxq_num(struct rte_eth_dev *dev, uint16_t nb_rx_q)
1868 RTE_ETH_DEV_SRIOV(dev).active = ETH_64_POOLS;
1871 RTE_ETH_DEV_SRIOV(dev).active = ETH_32_POOLS;
1877 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
1878 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx = dev->pci_dev->max_vfs * nb_rx_q;
1884 ixgbe_check_mq_mode(struct rte_eth_dev *dev)
1886 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
1887 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1888 uint16_t nb_rx_q = dev->data->nb_rx_queues;
1889 uint16_t nb_tx_q = dev->data->nb_tx_queues;
1891 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
1892 /* check multi-queue mode */
1893 switch (dev_conf->rxmode.mq_mode) {
1894 case ETH_MQ_RX_VMDQ_DCB:
1895 case ETH_MQ_RX_VMDQ_DCB_RSS:
1896 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
1897 PMD_INIT_LOG(ERR, "SRIOV active,"
1898 " unsupported mq_mode rx %d.",
1899 dev_conf->rxmode.mq_mode);
1902 case ETH_MQ_RX_VMDQ_RSS:
1903 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
1904 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
1905 if (ixgbe_check_vf_rss_rxq_num(dev, nb_rx_q)) {
1906 PMD_INIT_LOG(ERR, "SRIOV is active,"
1907 " invalid queue number"
1908 " for VMDQ RSS, allowed"
1909 " value are 1, 2 or 4.");
1913 case ETH_MQ_RX_VMDQ_ONLY:
1914 case ETH_MQ_RX_NONE:
1915 /* if nothing mq mode configure, use default scheme */
1916 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
1917 if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
1918 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
1920 default: /* ETH_MQ_RX_DCB, ETH_MQ_RX_DCB_RSS or ETH_MQ_TX_DCB*/
1921 /* SRIOV only works in VMDq enable mode */
1922 PMD_INIT_LOG(ERR, "SRIOV is active,"
1923 " wrong mq_mode rx %d.",
1924 dev_conf->rxmode.mq_mode);
1928 switch (dev_conf->txmode.mq_mode) {
1929 case ETH_MQ_TX_VMDQ_DCB:
1930 /* DCB VMDQ in SRIOV mode, not implement yet */
1931 PMD_INIT_LOG(ERR, "SRIOV is active,"
1932 " unsupported VMDQ mq_mode tx %d.",
1933 dev_conf->txmode.mq_mode);
1935 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
1936 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
1940 /* check valid queue number */
1941 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
1942 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
1943 PMD_INIT_LOG(ERR, "SRIOV is active,"
1944 " nb_rx_q=%d nb_tx_q=%d queue number"
1945 " must be less than or equal to %d.",
1947 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
1951 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB_RSS) {
1952 PMD_INIT_LOG(ERR, "VMDQ+DCB+RSS mq_mode is"
1956 /* check configuration for vmdb+dcb mode */
1957 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
1958 const struct rte_eth_vmdq_dcb_conf *conf;
1960 if (nb_rx_q != IXGBE_VMDQ_DCB_NB_QUEUES) {
1961 PMD_INIT_LOG(ERR, "VMDQ+DCB, nb_rx_q != %d.",
1962 IXGBE_VMDQ_DCB_NB_QUEUES);
1965 conf = &dev_conf->rx_adv_conf.vmdq_dcb_conf;
1966 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1967 conf->nb_queue_pools == ETH_32_POOLS)) {
1968 PMD_INIT_LOG(ERR, "VMDQ+DCB selected,"
1969 " nb_queue_pools must be %d or %d.",
1970 ETH_16_POOLS, ETH_32_POOLS);
1974 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1975 const struct rte_eth_vmdq_dcb_tx_conf *conf;
1977 if (nb_tx_q != IXGBE_VMDQ_DCB_NB_QUEUES) {
1978 PMD_INIT_LOG(ERR, "VMDQ+DCB, nb_tx_q != %d",
1979 IXGBE_VMDQ_DCB_NB_QUEUES);
1982 conf = &dev_conf->tx_adv_conf.vmdq_dcb_tx_conf;
1983 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1984 conf->nb_queue_pools == ETH_32_POOLS)) {
1985 PMD_INIT_LOG(ERR, "VMDQ+DCB selected,"
1986 " nb_queue_pools != %d and"
1987 " nb_queue_pools != %d.",
1988 ETH_16_POOLS, ETH_32_POOLS);
1993 /* For DCB mode check our configuration before we go further */
1994 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
1995 const struct rte_eth_dcb_rx_conf *conf;
1997 if (nb_rx_q != IXGBE_DCB_NB_QUEUES) {
1998 PMD_INIT_LOG(ERR, "DCB selected, nb_rx_q != %d.",
1999 IXGBE_DCB_NB_QUEUES);
2002 conf = &dev_conf->rx_adv_conf.dcb_rx_conf;
2003 if (!(conf->nb_tcs == ETH_4_TCS ||
2004 conf->nb_tcs == ETH_8_TCS)) {
2005 PMD_INIT_LOG(ERR, "DCB selected, nb_tcs != %d"
2006 " and nb_tcs != %d.",
2007 ETH_4_TCS, ETH_8_TCS);
2012 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
2013 const struct rte_eth_dcb_tx_conf *conf;
2015 if (nb_tx_q != IXGBE_DCB_NB_QUEUES) {
2016 PMD_INIT_LOG(ERR, "DCB, nb_tx_q != %d.",
2017 IXGBE_DCB_NB_QUEUES);
2020 conf = &dev_conf->tx_adv_conf.dcb_tx_conf;
2021 if (!(conf->nb_tcs == ETH_4_TCS ||
2022 conf->nb_tcs == ETH_8_TCS)) {
2023 PMD_INIT_LOG(ERR, "DCB selected, nb_tcs != %d"
2024 " and nb_tcs != %d.",
2025 ETH_4_TCS, ETH_8_TCS);
2031 * When DCB/VT is off, maximum number of queues changes,
2032 * except for 82598EB, which remains constant.
2034 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_NONE &&
2035 hw->mac.type != ixgbe_mac_82598EB) {
2036 if (nb_tx_q > IXGBE_NONE_MODE_TX_NB_QUEUES) {
2038 "Neither VT nor DCB are enabled, "
2040 IXGBE_NONE_MODE_TX_NB_QUEUES);
2049 ixgbe_dev_configure(struct rte_eth_dev *dev)
2051 struct ixgbe_interrupt *intr =
2052 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2053 struct ixgbe_adapter *adapter =
2054 (struct ixgbe_adapter *)dev->data->dev_private;
2057 PMD_INIT_FUNC_TRACE();
2058 /* multipe queue mode checking */
2059 ret = ixgbe_check_mq_mode(dev);
2061 PMD_DRV_LOG(ERR, "ixgbe_check_mq_mode fails with %d.",
2066 /* set flag to update link status after init */
2067 intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2070 * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
2071 * allocation or vector Rx preconditions we will reset it.
2073 adapter->rx_bulk_alloc_allowed = true;
2074 adapter->rx_vec_allowed = true;
2080 ixgbe_dev_phy_intr_setup(struct rte_eth_dev *dev)
2082 struct ixgbe_hw *hw =
2083 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2084 struct ixgbe_interrupt *intr =
2085 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2088 /* only set up it on X550EM_X */
2089 if (hw->mac.type == ixgbe_mac_X550EM_x) {
2090 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2091 gpie |= IXGBE_SDP0_GPIEN_X550EM_x;
2092 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2093 if (hw->phy.type == ixgbe_phy_x550em_ext_t)
2094 intr->mask |= IXGBE_EICR_GPI_SDP0_X550EM_x;
2099 * Configure device link speed and setup link.
2100 * It returns 0 on success.
2103 ixgbe_dev_start(struct rte_eth_dev *dev)
2105 struct ixgbe_hw *hw =
2106 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2107 struct ixgbe_vf_info *vfinfo =
2108 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
2109 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
2110 uint32_t intr_vector = 0;
2111 int err, link_up = 0, negotiate = 0;
2116 uint32_t *link_speeds;
2118 PMD_INIT_FUNC_TRACE();
2120 /* IXGBE devices don't support:
2121 * - half duplex (checked afterwards for valid speeds)
2122 * - fixed speed: TODO implement
2124 if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED) {
2125 PMD_INIT_LOG(ERR, "Invalid link_speeds for port %hhu; fix speed not supported",
2126 dev->data->port_id);
2130 /* disable uio/vfio intr/eventfd mapping */
2131 rte_intr_disable(intr_handle);
2134 hw->adapter_stopped = 0;
2135 ixgbe_stop_adapter(hw);
2137 /* reinitialize adapter
2138 * this calls reset and start
2140 status = ixgbe_pf_reset_hw(hw);
2143 hw->mac.ops.start_hw(hw);
2144 hw->mac.get_link_status = true;
2146 /* configure PF module if SRIOV enabled */
2147 ixgbe_pf_host_configure(dev);
2149 ixgbe_dev_phy_intr_setup(dev);
2151 /* check and configure queue intr-vector mapping */
2152 if ((rte_intr_cap_multiple(intr_handle) ||
2153 !RTE_ETH_DEV_SRIOV(dev).active) &&
2154 dev->data->dev_conf.intr_conf.rxq != 0) {
2155 intr_vector = dev->data->nb_rx_queues;
2156 if (intr_vector > IXGBE_MAX_INTR_QUEUE_NUM) {
2157 PMD_INIT_LOG(ERR, "At most %d intr queues supported",
2158 IXGBE_MAX_INTR_QUEUE_NUM);
2161 if (rte_intr_efd_enable(intr_handle, intr_vector))
2165 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
2166 intr_handle->intr_vec =
2167 rte_zmalloc("intr_vec",
2168 dev->data->nb_rx_queues * sizeof(int), 0);
2169 if (intr_handle->intr_vec == NULL) {
2170 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
2171 " intr_vec\n", dev->data->nb_rx_queues);
2176 /* confiugre msix for sleep until rx interrupt */
2177 ixgbe_configure_msix(dev);
2179 /* initialize transmission unit */
2180 ixgbe_dev_tx_init(dev);
2182 /* This can fail when allocating mbufs for descriptor rings */
2183 err = ixgbe_dev_rx_init(dev);
2185 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
2189 err = ixgbe_dev_rxtx_start(dev);
2191 PMD_INIT_LOG(ERR, "Unable to start rxtx queues");
2195 /* Skip link setup if loopback mode is enabled for 82599. */
2196 if (hw->mac.type == ixgbe_mac_82599EB &&
2197 dev->data->dev_conf.lpbk_mode == IXGBE_LPBK_82599_TX_RX)
2198 goto skip_link_setup;
2200 if (ixgbe_is_sfp(hw) && hw->phy.multispeed_fiber) {
2201 err = hw->mac.ops.setup_sfp(hw);
2206 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
2207 /* Turn on the copper */
2208 ixgbe_set_phy_power(hw, true);
2210 /* Turn on the laser */
2211 ixgbe_enable_tx_laser(hw);
2214 err = ixgbe_check_link(hw, &speed, &link_up, 0);
2217 dev->data->dev_link.link_status = link_up;
2219 err = ixgbe_get_link_capabilities(hw, &speed, &negotiate);
2223 link_speeds = &dev->data->dev_conf.link_speeds;
2224 if (*link_speeds & ~(ETH_LINK_SPEED_100M | ETH_LINK_SPEED_1G |
2225 ETH_LINK_SPEED_10G)) {
2226 PMD_INIT_LOG(ERR, "Invalid link setting");
2231 if (*link_speeds == ETH_LINK_SPEED_AUTONEG) {
2232 speed = (hw->mac.type != ixgbe_mac_82598EB) ?
2233 IXGBE_LINK_SPEED_82599_AUTONEG :
2234 IXGBE_LINK_SPEED_82598_AUTONEG;
2236 if (*link_speeds & ETH_LINK_SPEED_10G)
2237 speed |= IXGBE_LINK_SPEED_10GB_FULL;
2238 if (*link_speeds & ETH_LINK_SPEED_1G)
2239 speed |= IXGBE_LINK_SPEED_1GB_FULL;
2240 if (*link_speeds & ETH_LINK_SPEED_100M)
2241 speed |= IXGBE_LINK_SPEED_100_FULL;
2244 err = ixgbe_setup_link(hw, speed, link_up);
2250 if (rte_intr_allow_others(intr_handle)) {
2251 /* check if lsc interrupt is enabled */
2252 if (dev->data->dev_conf.intr_conf.lsc != 0)
2253 ixgbe_dev_lsc_interrupt_setup(dev);
2255 rte_intr_callback_unregister(intr_handle,
2256 ixgbe_dev_interrupt_handler,
2258 if (dev->data->dev_conf.intr_conf.lsc != 0)
2259 PMD_INIT_LOG(INFO, "lsc won't enable because of"
2260 " no intr multiplex\n");
2263 /* check if rxq interrupt is enabled */
2264 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
2265 rte_intr_dp_is_en(intr_handle))
2266 ixgbe_dev_rxq_interrupt_setup(dev);
2268 /* enable uio/vfio intr/eventfd mapping */
2269 rte_intr_enable(intr_handle);
2271 /* resume enabled intr since hw reset */
2272 ixgbe_enable_intr(dev);
2274 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK |
2275 ETH_VLAN_EXTEND_MASK;
2276 ixgbe_vlan_offload_set(dev, mask);
2278 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
2279 /* Enable vlan filtering for VMDq */
2280 ixgbe_vmdq_vlan_hw_filter_enable(dev);
2283 /* Configure DCB hw */
2284 ixgbe_configure_dcb(dev);
2286 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_NONE) {
2287 err = ixgbe_fdir_configure(dev);
2292 /* Restore vf rate limit */
2293 if (vfinfo != NULL) {
2294 for (vf = 0; vf < dev->pci_dev->max_vfs; vf++)
2295 for (idx = 0; idx < IXGBE_MAX_QUEUE_NUM_PER_VF; idx++)
2296 if (vfinfo[vf].tx_rate[idx] != 0)
2297 ixgbe_set_vf_rate_limit(dev, vf,
2298 vfinfo[vf].tx_rate[idx],
2302 ixgbe_restore_statistics_mapping(dev);
2307 PMD_INIT_LOG(ERR, "failure in ixgbe_dev_start(): %d", err);
2308 ixgbe_dev_clear_queues(dev);
2313 * Stop device: disable rx and tx functions to allow for reconfiguring.
2316 ixgbe_dev_stop(struct rte_eth_dev *dev)
2318 struct rte_eth_link link;
2319 struct ixgbe_hw *hw =
2320 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2321 struct ixgbe_vf_info *vfinfo =
2322 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
2323 struct ixgbe_filter_info *filter_info =
2324 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
2325 struct ixgbe_5tuple_filter *p_5tuple, *p_5tuple_next;
2326 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
2329 PMD_INIT_FUNC_TRACE();
2331 /* disable interrupts */
2332 ixgbe_disable_intr(hw);
2335 ixgbe_pf_reset_hw(hw);
2336 hw->adapter_stopped = 0;
2339 ixgbe_stop_adapter(hw);
2341 for (vf = 0; vfinfo != NULL &&
2342 vf < dev->pci_dev->max_vfs; vf++)
2343 vfinfo[vf].clear_to_send = false;
2345 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
2346 /* Turn off the copper */
2347 ixgbe_set_phy_power(hw, false);
2349 /* Turn off the laser */
2350 ixgbe_disable_tx_laser(hw);
2353 ixgbe_dev_clear_queues(dev);
2355 /* Clear stored conf */
2356 dev->data->scattered_rx = 0;
2359 /* Clear recorded link status */
2360 memset(&link, 0, sizeof(link));
2361 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
2363 /* Remove all ntuple filters of the device */
2364 for (p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list);
2365 p_5tuple != NULL; p_5tuple = p_5tuple_next) {
2366 p_5tuple_next = TAILQ_NEXT(p_5tuple, entries);
2367 TAILQ_REMOVE(&filter_info->fivetuple_list,
2371 memset(filter_info->fivetuple_mask, 0,
2372 sizeof(uint32_t) * IXGBE_5TUPLE_ARRAY_SIZE);
2374 if (!rte_intr_allow_others(intr_handle))
2375 /* resume to the default handler */
2376 rte_intr_callback_register(intr_handle,
2377 ixgbe_dev_interrupt_handler,
2380 /* Clean datapath event and queue/vec mapping */
2381 rte_intr_efd_disable(intr_handle);
2382 if (intr_handle->intr_vec != NULL) {
2383 rte_free(intr_handle->intr_vec);
2384 intr_handle->intr_vec = NULL;
2389 * Set device link up: enable tx.
2392 ixgbe_dev_set_link_up(struct rte_eth_dev *dev)
2394 struct ixgbe_hw *hw =
2395 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2396 if (hw->mac.type == ixgbe_mac_82599EB) {
2397 #ifdef RTE_NIC_BYPASS
2398 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
2399 /* Not suported in bypass mode */
2400 PMD_INIT_LOG(ERR, "Set link up is not supported "
2401 "by device id 0x%x", hw->device_id);
2407 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
2408 /* Turn on the copper */
2409 ixgbe_set_phy_power(hw, true);
2411 /* Turn on the laser */
2412 ixgbe_enable_tx_laser(hw);
2419 * Set device link down: disable tx.
2422 ixgbe_dev_set_link_down(struct rte_eth_dev *dev)
2424 struct ixgbe_hw *hw =
2425 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2426 if (hw->mac.type == ixgbe_mac_82599EB) {
2427 #ifdef RTE_NIC_BYPASS
2428 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
2429 /* Not suported in bypass mode */
2430 PMD_INIT_LOG(ERR, "Set link down is not supported "
2431 "by device id 0x%x", hw->device_id);
2437 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
2438 /* Turn off the copper */
2439 ixgbe_set_phy_power(hw, false);
2441 /* Turn off the laser */
2442 ixgbe_disable_tx_laser(hw);
2449 * Reest and stop device.
2452 ixgbe_dev_close(struct rte_eth_dev *dev)
2454 struct ixgbe_hw *hw =
2455 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2457 PMD_INIT_FUNC_TRACE();
2459 ixgbe_pf_reset_hw(hw);
2461 ixgbe_dev_stop(dev);
2462 hw->adapter_stopped = 1;
2464 ixgbe_dev_free_queues(dev);
2466 ixgbe_disable_pcie_master(hw);
2468 /* reprogram the RAR[0] in case user changed it. */
2469 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
2473 ixgbe_read_stats_registers(struct ixgbe_hw *hw,
2474 struct ixgbe_hw_stats *hw_stats,
2475 uint64_t *total_missed_rx, uint64_t *total_qbrc,
2476 uint64_t *total_qprc, uint64_t *total_qprdc)
2478 uint32_t bprc, lxon, lxoff, total;
2479 uint32_t delta_gprc = 0;
2481 /* Workaround for RX byte count not including CRC bytes when CRC
2482 + * strip is enabled. CRC bytes are removed from counters when crc_strip
2485 int crc_strip = (IXGBE_READ_REG(hw, IXGBE_HLREG0) &
2486 IXGBE_HLREG0_RXCRCSTRP);
2488 hw_stats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
2489 hw_stats->illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC);
2490 hw_stats->errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC);
2491 hw_stats->mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC);
2493 for (i = 0; i < 8; i++) {
2494 uint32_t mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
2496 /* global total per queue */
2497 hw_stats->mpc[i] += mp;
2498 /* Running comprehensive total for stats display */
2499 *total_missed_rx += hw_stats->mpc[i];
2500 if (hw->mac.type == ixgbe_mac_82598EB) {
2501 hw_stats->rnbc[i] +=
2502 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
2503 hw_stats->pxonrxc[i] +=
2504 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
2505 hw_stats->pxoffrxc[i] +=
2506 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
2508 hw_stats->pxonrxc[i] +=
2509 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
2510 hw_stats->pxoffrxc[i] +=
2511 IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
2512 hw_stats->pxon2offc[i] +=
2513 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
2515 hw_stats->pxontxc[i] +=
2516 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
2517 hw_stats->pxofftxc[i] +=
2518 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
2520 for (i = 0; i < IXGBE_QUEUE_STAT_COUNTERS; i++) {
2521 uint32_t delta_qprc = IXGBE_READ_REG(hw, IXGBE_QPRC(i));
2522 uint32_t delta_qptc = IXGBE_READ_REG(hw, IXGBE_QPTC(i));
2523 uint32_t delta_qprdc = IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
2525 delta_gprc += delta_qprc;
2527 hw_stats->qprc[i] += delta_qprc;
2528 hw_stats->qptc[i] += delta_qptc;
2530 hw_stats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
2531 hw_stats->qbrc[i] +=
2532 ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)) << 32);
2534 hw_stats->qbrc[i] -= delta_qprc * ETHER_CRC_LEN;
2536 hw_stats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
2537 hw_stats->qbtc[i] +=
2538 ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)) << 32);
2540 hw_stats->qprdc[i] += delta_qprdc;
2541 *total_qprdc += hw_stats->qprdc[i];
2543 *total_qprc += hw_stats->qprc[i];
2544 *total_qbrc += hw_stats->qbrc[i];
2546 hw_stats->mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC);
2547 hw_stats->mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC);
2548 hw_stats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
2551 * An errata states that gprc actually counts good + missed packets:
2552 * Workaround to set gprc to summated queue packet receives
2554 hw_stats->gprc = *total_qprc;
2556 if (hw->mac.type != ixgbe_mac_82598EB) {
2557 hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
2558 hw_stats->gorc += ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32);
2559 hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
2560 hw_stats->gotc += ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32);
2561 hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
2562 hw_stats->tor += ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32);
2563 hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
2564 hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
2566 hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
2567 hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
2568 /* 82598 only has a counter in the high register */
2569 hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
2570 hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
2571 hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
2573 uint64_t old_tpr = hw_stats->tpr;
2575 hw_stats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
2576 hw_stats->tpt += IXGBE_READ_REG(hw, IXGBE_TPT);
2579 hw_stats->gorc -= delta_gprc * ETHER_CRC_LEN;
2581 uint64_t delta_gptc = IXGBE_READ_REG(hw, IXGBE_GPTC);
2582 hw_stats->gptc += delta_gptc;
2583 hw_stats->gotc -= delta_gptc * ETHER_CRC_LEN;
2584 hw_stats->tor -= (hw_stats->tpr - old_tpr) * ETHER_CRC_LEN;
2587 * Workaround: mprc hardware is incorrectly counting
2588 * broadcasts, so for now we subtract those.
2590 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
2591 hw_stats->bprc += bprc;
2592 hw_stats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
2593 if (hw->mac.type == ixgbe_mac_82598EB)
2594 hw_stats->mprc -= bprc;
2596 hw_stats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
2597 hw_stats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
2598 hw_stats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
2599 hw_stats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
2600 hw_stats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
2601 hw_stats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
2603 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
2604 hw_stats->lxontxc += lxon;
2605 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
2606 hw_stats->lxofftxc += lxoff;
2607 total = lxon + lxoff;
2609 hw_stats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
2610 hw_stats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
2611 hw_stats->gptc -= total;
2612 hw_stats->mptc -= total;
2613 hw_stats->ptc64 -= total;
2614 hw_stats->gotc -= total * ETHER_MIN_LEN;
2616 hw_stats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
2617 hw_stats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
2618 hw_stats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
2619 hw_stats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
2620 hw_stats->mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC);
2621 hw_stats->mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC);
2622 hw_stats->mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC);
2623 hw_stats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
2624 hw_stats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
2625 hw_stats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
2626 hw_stats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
2627 hw_stats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
2628 hw_stats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
2629 hw_stats->xec += IXGBE_READ_REG(hw, IXGBE_XEC);
2630 hw_stats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
2631 hw_stats->fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
2632 /* Only read FCOE on 82599 */
2633 if (hw->mac.type != ixgbe_mac_82598EB) {
2634 hw_stats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
2635 hw_stats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
2636 hw_stats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
2637 hw_stats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
2638 hw_stats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
2641 /* Flow Director Stats registers */
2642 hw_stats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
2643 hw_stats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
2647 * This function is based on ixgbe_update_stats_counters() in ixgbe/ixgbe.c
2650 ixgbe_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2652 struct ixgbe_hw *hw =
2653 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2654 struct ixgbe_hw_stats *hw_stats =
2655 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2656 uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
2659 total_missed_rx = 0;
2664 ixgbe_read_stats_registers(hw, hw_stats, &total_missed_rx, &total_qbrc,
2665 &total_qprc, &total_qprdc);
2670 /* Fill out the rte_eth_stats statistics structure */
2671 stats->ipackets = total_qprc;
2672 stats->ibytes = total_qbrc;
2673 stats->opackets = hw_stats->gptc;
2674 stats->obytes = hw_stats->gotc;
2676 for (i = 0; i < IXGBE_QUEUE_STAT_COUNTERS; i++) {
2677 stats->q_ipackets[i] = hw_stats->qprc[i];
2678 stats->q_opackets[i] = hw_stats->qptc[i];
2679 stats->q_ibytes[i] = hw_stats->qbrc[i];
2680 stats->q_obytes[i] = hw_stats->qbtc[i];
2681 stats->q_errors[i] = hw_stats->qprdc[i];
2685 stats->imissed = total_missed_rx;
2686 stats->ierrors = hw_stats->crcerrs +
2702 ixgbe_dev_stats_reset(struct rte_eth_dev *dev)
2704 struct ixgbe_hw_stats *stats =
2705 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2707 /* HW registers are cleared on read */
2708 ixgbe_dev_stats_get(dev, NULL);
2710 /* Reset software totals */
2711 memset(stats, 0, sizeof(*stats));
2714 /* This function calculates the number of xstats based on the current config */
2716 ixgbe_xstats_calc_num(void) {
2717 return IXGBE_NB_HW_STATS +
2718 (IXGBE_NB_RXQ_PRIO_STATS * IXGBE_NB_RXQ_PRIO_VALUES) +
2719 (IXGBE_NB_TXQ_PRIO_STATS * IXGBE_NB_TXQ_PRIO_VALUES);
2722 static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2723 struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit)
2725 const unsigned cnt_stats = ixgbe_xstats_calc_num();
2726 unsigned stat, i, count;
2728 if (xstats_names != NULL) {
2731 /* Note: limit >= cnt_stats checked upstream
2732 * in rte_eth_xstats_names()
2735 /* Extended stats from ixgbe_hw_stats */
2736 for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
2737 xstats_names[count].id = count;
2738 snprintf(xstats_names[count].name,
2739 sizeof(xstats_names[count].name),
2741 rte_ixgbe_stats_strings[i].name);
2745 /* RX Priority Stats */
2746 for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
2747 for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
2748 xstats_names[count].id = count;
2749 snprintf(xstats_names[count].name,
2750 sizeof(xstats_names[count].name),
2751 "rx_priority%u_%s", i,
2752 rte_ixgbe_rxq_strings[stat].name);
2757 /* TX Priority Stats */
2758 for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
2759 for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
2760 xstats_names[count].id = count;
2761 snprintf(xstats_names[count].name,
2762 sizeof(xstats_names[count].name),
2763 "tx_priority%u_%s", i,
2764 rte_ixgbe_txq_strings[stat].name);
2772 static int ixgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2773 struct rte_eth_xstat_name *xstats_names, unsigned limit)
2777 if (limit < IXGBEVF_NB_XSTATS && xstats_names != NULL)
2780 if (xstats_names != NULL)
2781 for (i = 0; i < IXGBEVF_NB_XSTATS; i++)
2782 snprintf(xstats_names[i].name,
2783 sizeof(xstats_names[i].name),
2784 "%s", rte_ixgbevf_stats_strings[i].name);
2785 return IXGBEVF_NB_XSTATS;
2789 ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
2792 struct ixgbe_hw *hw =
2793 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2794 struct ixgbe_hw_stats *hw_stats =
2795 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2796 uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
2797 unsigned i, stat, count = 0;
2799 count = ixgbe_xstats_calc_num();
2804 total_missed_rx = 0;
2809 ixgbe_read_stats_registers(hw, hw_stats, &total_missed_rx, &total_qbrc,
2810 &total_qprc, &total_qprdc);
2812 /* If this is a reset xstats is NULL, and we have cleared the
2813 * registers by reading them.
2818 /* Extended stats from ixgbe_hw_stats */
2820 for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
2821 xstats[count].id = count;
2822 xstats[count].name[0] = '\0';
2823 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
2824 rte_ixgbe_stats_strings[i].offset);
2828 /* RX Priority Stats */
2829 for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
2830 for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
2831 xstats[count].id = count;
2832 xstats[count].name[0] = '\0';
2833 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
2834 rte_ixgbe_rxq_strings[stat].offset +
2835 (sizeof(uint64_t) * i));
2840 /* TX Priority Stats */
2841 for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
2842 for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
2843 xstats[count].id = count;
2844 xstats[count].name[0] = '\0';
2845 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
2846 rte_ixgbe_txq_strings[stat].offset +
2847 (sizeof(uint64_t) * i));
2855 ixgbe_dev_xstats_reset(struct rte_eth_dev *dev)
2857 struct ixgbe_hw_stats *stats =
2858 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2860 unsigned count = ixgbe_xstats_calc_num();
2862 /* HW registers are cleared on read */
2863 ixgbe_dev_xstats_get(dev, NULL, count);
2865 /* Reset software totals */
2866 memset(stats, 0, sizeof(*stats));
2870 ixgbevf_update_stats(struct rte_eth_dev *dev)
2872 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2873 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
2874 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2876 /* Good Rx packet, include VF loopback */
2877 UPDATE_VF_STAT(IXGBE_VFGPRC,
2878 hw_stats->last_vfgprc, hw_stats->vfgprc);
2880 /* Good Rx octets, include VF loopback */
2881 UPDATE_VF_STAT_36BIT(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
2882 hw_stats->last_vfgorc, hw_stats->vfgorc);
2884 /* Good Tx packet, include VF loopback */
2885 UPDATE_VF_STAT(IXGBE_VFGPTC,
2886 hw_stats->last_vfgptc, hw_stats->vfgptc);
2888 /* Good Tx octets, include VF loopback */
2889 UPDATE_VF_STAT_36BIT(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
2890 hw_stats->last_vfgotc, hw_stats->vfgotc);
2892 /* Rx Multicst Packet */
2893 UPDATE_VF_STAT(IXGBE_VFMPRC,
2894 hw_stats->last_vfmprc, hw_stats->vfmprc);
2898 ixgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
2901 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
2902 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2905 if (n < IXGBEVF_NB_XSTATS)
2906 return IXGBEVF_NB_XSTATS;
2908 ixgbevf_update_stats(dev);
2913 /* Extended stats */
2914 for (i = 0; i < IXGBEVF_NB_XSTATS; i++) {
2916 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
2917 rte_ixgbevf_stats_strings[i].offset);
2920 return IXGBEVF_NB_XSTATS;
2924 ixgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2926 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
2927 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2929 ixgbevf_update_stats(dev);
2934 stats->ipackets = hw_stats->vfgprc;
2935 stats->ibytes = hw_stats->vfgorc;
2936 stats->opackets = hw_stats->vfgptc;
2937 stats->obytes = hw_stats->vfgotc;
2941 ixgbevf_dev_stats_reset(struct rte_eth_dev *dev)
2943 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
2944 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2946 /* Sync HW register to the last stats */
2947 ixgbevf_dev_stats_get(dev, NULL);
2949 /* reset HW current stats*/
2950 hw_stats->vfgprc = 0;
2951 hw_stats->vfgorc = 0;
2952 hw_stats->vfgptc = 0;
2953 hw_stats->vfgotc = 0;
2957 ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2959 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2960 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
2962 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
2963 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
2964 if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
2966 * When DCB/VT is off, maximum number of queues changes,
2967 * except for 82598EB, which remains constant.
2969 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_NONE &&
2970 hw->mac.type != ixgbe_mac_82598EB)
2971 dev_info->max_tx_queues = IXGBE_NONE_MODE_TX_NB_QUEUES;
2973 dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL register */
2974 dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS register */
2975 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
2976 dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
2977 dev_info->max_vfs = dev->pci_dev->max_vfs;
2978 if (hw->mac.type == ixgbe_mac_82598EB)
2979 dev_info->max_vmdq_pools = ETH_16_POOLS;
2981 dev_info->max_vmdq_pools = ETH_64_POOLS;
2982 dev_info->vmdq_queue_num = dev_info->max_rx_queues;
2983 dev_info->rx_offload_capa =
2984 DEV_RX_OFFLOAD_VLAN_STRIP |
2985 DEV_RX_OFFLOAD_IPV4_CKSUM |
2986 DEV_RX_OFFLOAD_UDP_CKSUM |
2987 DEV_RX_OFFLOAD_TCP_CKSUM;
2990 * RSC is only supported by 82599 and x540 PF devices in a non-SR-IOV
2993 if ((hw->mac.type == ixgbe_mac_82599EB ||
2994 hw->mac.type == ixgbe_mac_X540) &&
2995 !RTE_ETH_DEV_SRIOV(dev).active)
2996 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TCP_LRO;
2998 if (hw->mac.type == ixgbe_mac_X550 ||
2999 hw->mac.type == ixgbe_mac_X550EM_x ||
3000 hw->mac.type == ixgbe_mac_X550EM_a)
3001 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
3003 dev_info->tx_offload_capa =
3004 DEV_TX_OFFLOAD_VLAN_INSERT |
3005 DEV_TX_OFFLOAD_IPV4_CKSUM |
3006 DEV_TX_OFFLOAD_UDP_CKSUM |
3007 DEV_TX_OFFLOAD_TCP_CKSUM |
3008 DEV_TX_OFFLOAD_SCTP_CKSUM |
3009 DEV_TX_OFFLOAD_TCP_TSO;
3011 if (hw->mac.type == ixgbe_mac_X550 ||
3012 hw->mac.type == ixgbe_mac_X550EM_x ||
3013 hw->mac.type == ixgbe_mac_X550EM_a)
3014 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3016 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3018 .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
3019 .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
3020 .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
3022 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
3026 dev_info->default_txconf = (struct rte_eth_txconf) {
3028 .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
3029 .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
3030 .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
3032 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
3033 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
3034 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
3035 ETH_TXQ_FLAGS_NOOFFLOADS,
3038 dev_info->rx_desc_lim = rx_desc_lim;
3039 dev_info->tx_desc_lim = tx_desc_lim;
3041 dev_info->hash_key_size = IXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
3042 dev_info->reta_size = ixgbe_reta_size_get(hw->mac.type);
3043 dev_info->flow_type_rss_offloads = IXGBE_RSS_OFFLOAD_ALL;
3045 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
3046 if (hw->mac.type == ixgbe_mac_X540 ||
3047 hw->mac.type == ixgbe_mac_X540_vf ||
3048 hw->mac.type == ixgbe_mac_X550 ||
3049 hw->mac.type == ixgbe_mac_X550_vf) {
3050 dev_info->speed_capa |= ETH_LINK_SPEED_100M;
3054 static const uint32_t *
3055 ixgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev)
3057 static const uint32_t ptypes[] = {
3058 /* For non-vec functions,
3059 * refers to ixgbe_rxd_pkt_info_to_pkt_type();
3060 * for vec functions,
3061 * refers to _recv_raw_pkts_vec().
3065 RTE_PTYPE_L3_IPV4_EXT,
3067 RTE_PTYPE_L3_IPV6_EXT,
3071 RTE_PTYPE_TUNNEL_IP,
3072 RTE_PTYPE_INNER_L3_IPV6,
3073 RTE_PTYPE_INNER_L3_IPV6_EXT,
3074 RTE_PTYPE_INNER_L4_TCP,
3075 RTE_PTYPE_INNER_L4_UDP,
3079 if (dev->rx_pkt_burst == ixgbe_recv_pkts ||
3080 dev->rx_pkt_burst == ixgbe_recv_pkts_lro_single_alloc ||
3081 dev->rx_pkt_burst == ixgbe_recv_pkts_lro_bulk_alloc ||
3082 dev->rx_pkt_burst == ixgbe_recv_pkts_bulk_alloc)
3088 ixgbevf_dev_info_get(struct rte_eth_dev *dev,
3089 struct rte_eth_dev_info *dev_info)
3091 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3093 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
3094 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
3095 dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL reg */
3096 dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS reg */
3097 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
3098 dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
3099 dev_info->max_vfs = dev->pci_dev->max_vfs;
3100 if (hw->mac.type == ixgbe_mac_82598EB)
3101 dev_info->max_vmdq_pools = ETH_16_POOLS;
3103 dev_info->max_vmdq_pools = ETH_64_POOLS;
3104 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
3105 DEV_RX_OFFLOAD_IPV4_CKSUM |
3106 DEV_RX_OFFLOAD_UDP_CKSUM |
3107 DEV_RX_OFFLOAD_TCP_CKSUM;
3108 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
3109 DEV_TX_OFFLOAD_IPV4_CKSUM |
3110 DEV_TX_OFFLOAD_UDP_CKSUM |
3111 DEV_TX_OFFLOAD_TCP_CKSUM |
3112 DEV_TX_OFFLOAD_SCTP_CKSUM |
3113 DEV_TX_OFFLOAD_TCP_TSO;
3115 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3117 .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
3118 .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
3119 .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
3121 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
3125 dev_info->default_txconf = (struct rte_eth_txconf) {
3127 .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
3128 .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
3129 .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
3131 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
3132 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
3133 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
3134 ETH_TXQ_FLAGS_NOOFFLOADS,
3137 dev_info->rx_desc_lim = rx_desc_lim;
3138 dev_info->tx_desc_lim = tx_desc_lim;
3141 /* return 0 means link status changed, -1 means not changed */
3143 ixgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
3145 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3146 struct rte_eth_link link, old;
3147 ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
3151 link.link_status = ETH_LINK_DOWN;
3152 link.link_speed = 0;
3153 link.link_duplex = ETH_LINK_HALF_DUPLEX;
3154 memset(&old, 0, sizeof(old));
3155 rte_ixgbe_dev_atomic_read_link_status(dev, &old);
3157 hw->mac.get_link_status = true;
3159 /* check if it needs to wait to complete, if lsc interrupt is enabled */
3160 if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
3161 diag = ixgbe_check_link(hw, &link_speed, &link_up, 0);
3163 diag = ixgbe_check_link(hw, &link_speed, &link_up, 1);
3166 link.link_speed = ETH_SPEED_NUM_100M;
3167 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3168 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
3169 if (link.link_status == old.link_status)
3175 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
3176 if (link.link_status == old.link_status)
3180 link.link_status = ETH_LINK_UP;
3181 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3183 switch (link_speed) {
3185 case IXGBE_LINK_SPEED_UNKNOWN:
3186 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3187 link.link_speed = ETH_SPEED_NUM_100M;
3190 case IXGBE_LINK_SPEED_100_FULL:
3191 link.link_speed = ETH_SPEED_NUM_100M;
3194 case IXGBE_LINK_SPEED_1GB_FULL:
3195 link.link_speed = ETH_SPEED_NUM_1G;
3198 case IXGBE_LINK_SPEED_10GB_FULL:
3199 link.link_speed = ETH_SPEED_NUM_10G;
3202 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
3204 if (link.link_status == old.link_status)
3211 ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
3213 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3216 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3217 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3218 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3222 ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
3224 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3227 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3228 fctrl &= (~IXGBE_FCTRL_UPE);
3229 if (dev->data->all_multicast == 1)
3230 fctrl |= IXGBE_FCTRL_MPE;
3232 fctrl &= (~IXGBE_FCTRL_MPE);
3233 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3237 ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
3239 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3242 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3243 fctrl |= IXGBE_FCTRL_MPE;
3244 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3248 ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
3250 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3253 if (dev->data->promiscuous == 1)
3254 return; /* must remain in all_multicast mode */
3256 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3257 fctrl &= (~IXGBE_FCTRL_MPE);
3258 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3262 * It clears the interrupt causes and enables the interrupt.
3263 * It will be called once only during nic initialized.
3266 * Pointer to struct rte_eth_dev.
3269 * - On success, zero.
3270 * - On failure, a negative value.
3273 ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev)
3275 struct ixgbe_interrupt *intr =
3276 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3278 ixgbe_dev_link_status_print(dev);
3279 intr->mask |= IXGBE_EICR_LSC;
3285 * It clears the interrupt causes and enables the interrupt.
3286 * It will be called once only during nic initialized.
3289 * Pointer to struct rte_eth_dev.
3292 * - On success, zero.
3293 * - On failure, a negative value.
3296 ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
3298 struct ixgbe_interrupt *intr =
3299 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3301 intr->mask |= IXGBE_EICR_RTX_QUEUE;
3307 * It reads ICR and sets flag (IXGBE_EICR_LSC) for the link_update.
3310 * Pointer to struct rte_eth_dev.
3313 * - On success, zero.
3314 * - On failure, a negative value.
3317 ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
3320 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3321 struct ixgbe_interrupt *intr =
3322 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3324 /* clear all cause mask */
3325 ixgbe_disable_intr(hw);
3327 /* read-on-clear nic registers here */
3328 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
3329 PMD_DRV_LOG(DEBUG, "eicr %x", eicr);
3333 /* set flag for async link update */
3334 if (eicr & IXGBE_EICR_LSC)
3335 intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3337 if (eicr & IXGBE_EICR_MAILBOX)
3338 intr->flags |= IXGBE_FLAG_MAILBOX;
3340 if (hw->mac.type == ixgbe_mac_X550EM_x &&
3341 hw->phy.type == ixgbe_phy_x550em_ext_t &&
3342 (eicr & IXGBE_EICR_GPI_SDP0_X550EM_x))
3343 intr->flags |= IXGBE_FLAG_PHY_INTERRUPT;
3349 * It gets and then prints the link status.
3352 * Pointer to struct rte_eth_dev.
3355 * - On success, zero.
3356 * - On failure, a negative value.
3359 ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
3361 struct rte_eth_link link;
3363 memset(&link, 0, sizeof(link));
3364 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
3365 if (link.link_status) {
3366 PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
3367 (int)(dev->data->port_id),
3368 (unsigned)link.link_speed,
3369 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
3370 "full-duplex" : "half-duplex");
3372 PMD_INIT_LOG(INFO, " Port %d: Link Down",
3373 (int)(dev->data->port_id));
3375 PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
3376 dev->pci_dev->addr.domain,
3377 dev->pci_dev->addr.bus,
3378 dev->pci_dev->addr.devid,
3379 dev->pci_dev->addr.function);
3383 * It executes link_update after knowing an interrupt occurred.
3386 * Pointer to struct rte_eth_dev.
3389 * - On success, zero.
3390 * - On failure, a negative value.
3393 ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
3395 struct ixgbe_interrupt *intr =
3396 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3398 struct rte_eth_link link;
3399 int intr_enable_delay = false;
3400 struct ixgbe_hw *hw =
3401 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3403 PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
3405 if (intr->flags & IXGBE_FLAG_MAILBOX) {
3406 ixgbe_pf_mbx_process(dev);
3407 intr->flags &= ~IXGBE_FLAG_MAILBOX;
3410 if (intr->flags & IXGBE_FLAG_PHY_INTERRUPT) {
3411 ixgbe_handle_lasi(hw);
3412 intr->flags &= ~IXGBE_FLAG_PHY_INTERRUPT;
3415 if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3416 /* get the link status before link update, for predicting later */
3417 memset(&link, 0, sizeof(link));
3418 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
3420 ixgbe_dev_link_update(dev, 0);
3423 if (!link.link_status)
3424 /* handle it 1 sec later, wait it being stable */
3425 timeout = IXGBE_LINK_UP_CHECK_TIMEOUT;
3426 /* likely to down */
3428 /* handle it 4 sec later, wait it being stable */
3429 timeout = IXGBE_LINK_DOWN_CHECK_TIMEOUT;
3431 ixgbe_dev_link_status_print(dev);
3433 intr_enable_delay = true;
3436 if (intr_enable_delay) {
3437 if (rte_eal_alarm_set(timeout * 1000,
3438 ixgbe_dev_interrupt_delayed_handler, (void *)dev) < 0)
3439 PMD_DRV_LOG(ERR, "Error setting alarm");
3441 PMD_DRV_LOG(DEBUG, "enable intr immediately");
3442 ixgbe_enable_intr(dev);
3443 rte_intr_enable(&(dev->pci_dev->intr_handle));
3451 * Interrupt handler which shall be registered for alarm callback for delayed
3452 * handling specific interrupt to wait for the stable nic state. As the
3453 * NIC interrupt state is not stable for ixgbe after link is just down,
3454 * it needs to wait 4 seconds to get the stable status.
3457 * Pointer to interrupt handle.
3459 * The address of parameter (struct rte_eth_dev *) regsitered before.
3465 ixgbe_dev_interrupt_delayed_handler(void *param)
3467 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
3468 struct ixgbe_interrupt *intr =
3469 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3470 struct ixgbe_hw *hw =
3471 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3474 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
3475 if (eicr & IXGBE_EICR_MAILBOX)
3476 ixgbe_pf_mbx_process(dev);
3478 if (intr->flags & IXGBE_FLAG_PHY_INTERRUPT) {
3479 ixgbe_handle_lasi(hw);
3480 intr->flags &= ~IXGBE_FLAG_PHY_INTERRUPT;
3483 if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3484 ixgbe_dev_link_update(dev, 0);
3485 intr->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3486 ixgbe_dev_link_status_print(dev);
3487 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
3490 PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
3491 ixgbe_enable_intr(dev);
3492 rte_intr_enable(&(dev->pci_dev->intr_handle));
3496 * Interrupt handler triggered by NIC for handling
3497 * specific interrupt.
3500 * Pointer to interrupt handle.
3502 * The address of parameter (struct rte_eth_dev *) regsitered before.
3508 ixgbe_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
3511 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
3513 ixgbe_dev_interrupt_get_status(dev);
3514 ixgbe_dev_interrupt_action(dev);
3518 ixgbe_dev_led_on(struct rte_eth_dev *dev)
3520 struct ixgbe_hw *hw;
3522 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3523 return ixgbe_led_on(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP;
3527 ixgbe_dev_led_off(struct rte_eth_dev *dev)
3529 struct ixgbe_hw *hw;
3531 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3532 return ixgbe_led_off(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP;
3536 ixgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3538 struct ixgbe_hw *hw;
3544 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3546 fc_conf->pause_time = hw->fc.pause_time;
3547 fc_conf->high_water = hw->fc.high_water[0];
3548 fc_conf->low_water = hw->fc.low_water[0];
3549 fc_conf->send_xon = hw->fc.send_xon;
3550 fc_conf->autoneg = !hw->fc.disable_fc_autoneg;
3553 * Return rx_pause status according to actual setting of
3556 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
3557 if (mflcn_reg & (IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_RFCE))
3563 * Return tx_pause status according to actual setting of
3566 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
3567 if (fccfg_reg & (IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY))
3572 if (rx_pause && tx_pause)
3573 fc_conf->mode = RTE_FC_FULL;
3575 fc_conf->mode = RTE_FC_RX_PAUSE;
3577 fc_conf->mode = RTE_FC_TX_PAUSE;
3579 fc_conf->mode = RTE_FC_NONE;
3585 ixgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3587 struct ixgbe_hw *hw;
3589 uint32_t rx_buf_size;
3590 uint32_t max_high_water;
3592 enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
3599 PMD_INIT_FUNC_TRACE();
3601 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3602 rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0));
3603 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
3606 * At least reserve one Ethernet frame for watermark
3607 * high_water/low_water in kilo bytes for ixgbe
3609 max_high_water = (rx_buf_size - ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
3610 if ((fc_conf->high_water > max_high_water) ||
3611 (fc_conf->high_water < fc_conf->low_water)) {
3612 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
3613 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
3617 hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[fc_conf->mode];
3618 hw->fc.pause_time = fc_conf->pause_time;
3619 hw->fc.high_water[0] = fc_conf->high_water;
3620 hw->fc.low_water[0] = fc_conf->low_water;
3621 hw->fc.send_xon = fc_conf->send_xon;
3622 hw->fc.disable_fc_autoneg = !fc_conf->autoneg;
3624 err = ixgbe_fc_enable(hw);
3626 /* Not negotiated is not an error case */
3627 if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED)) {
3629 /* check if we want to forward MAC frames - driver doesn't have native
3630 * capability to do that, so we'll write the registers ourselves */
3632 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
3634 /* set or clear MFLCN.PMCF bit depending on configuration */
3635 if (fc_conf->mac_ctrl_frame_fwd != 0)
3636 mflcn |= IXGBE_MFLCN_PMCF;
3638 mflcn &= ~IXGBE_MFLCN_PMCF;
3640 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn);
3641 IXGBE_WRITE_FLUSH(hw);
3646 PMD_INIT_LOG(ERR, "ixgbe_fc_enable = 0x%x", err);
3651 * ixgbe_pfc_enable_generic - Enable flow control
3652 * @hw: pointer to hardware structure
3653 * @tc_num: traffic class number
3654 * Enable flow control according to the current settings.
3657 ixgbe_dcb_pfc_enable_generic(struct ixgbe_hw *hw, uint8_t tc_num)
3660 uint32_t mflcn_reg, fccfg_reg;
3662 uint32_t fcrtl, fcrth;
3666 /* Validate the water mark configuration */
3667 if (!hw->fc.pause_time) {
3668 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
3672 /* Low water mark of zero causes XOFF floods */
3673 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
3674 /* High/Low water can not be 0 */
3675 if ((!hw->fc.high_water[tc_num]) || (!hw->fc.low_water[tc_num])) {
3676 PMD_INIT_LOG(ERR, "Invalid water mark configuration");
3677 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
3681 if (hw->fc.low_water[tc_num] >= hw->fc.high_water[tc_num]) {
3682 PMD_INIT_LOG(ERR, "Invalid water mark configuration");
3683 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
3687 /* Negotiate the fc mode to use */
3688 ixgbe_fc_autoneg(hw);
3690 /* Disable any previous flow control settings */
3691 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
3692 mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_SHIFT | IXGBE_MFLCN_RFCE|IXGBE_MFLCN_RPFCE);
3694 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
3695 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
3697 switch (hw->fc.current_mode) {
3700 * If the count of enabled RX Priority Flow control >1,
3701 * and the TX pause can not be disabled
3704 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
3705 reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
3706 if (reg & IXGBE_FCRTH_FCEN)
3710 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
3712 case ixgbe_fc_rx_pause:
3714 * Rx Flow control is enabled and Tx Flow control is
3715 * disabled by software override. Since there really
3716 * isn't a way to advertise that we are capable of RX
3717 * Pause ONLY, we will advertise that we support both
3718 * symmetric and asymmetric Rx PAUSE. Later, we will
3719 * disable the adapter's ability to send PAUSE frames.
3721 mflcn_reg |= IXGBE_MFLCN_RPFCE;
3723 * If the count of enabled RX Priority Flow control >1,
3724 * and the TX pause can not be disabled
3727 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
3728 reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
3729 if (reg & IXGBE_FCRTH_FCEN)
3733 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
3735 case ixgbe_fc_tx_pause:
3737 * Tx Flow control is enabled, and Rx Flow control is
3738 * disabled by software override.
3740 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
3743 /* Flow control (both Rx and Tx) is enabled by SW override. */
3744 mflcn_reg |= IXGBE_MFLCN_RPFCE;
3745 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
3748 PMD_DRV_LOG(DEBUG, "Flow control param set incorrectly");
3749 ret_val = IXGBE_ERR_CONFIG;
3753 /* Set 802.3x based flow control settings. */
3754 mflcn_reg |= IXGBE_MFLCN_DPF;
3755 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
3756 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
3758 /* Set up and enable Rx high/low water mark thresholds, enable XON. */
3759 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
3760 hw->fc.high_water[tc_num]) {
3761 fcrtl = (hw->fc.low_water[tc_num] << 10) | IXGBE_FCRTL_XONE;
3762 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), fcrtl);
3763 fcrth = (hw->fc.high_water[tc_num] << 10) | IXGBE_FCRTH_FCEN;
3765 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), 0);
3767 * In order to prevent Tx hangs when the internal Tx
3768 * switch is enabled we must set the high water mark
3769 * to the maximum FCRTH value. This allows the Tx
3770 * switch to function even under heavy Rx workloads.
3772 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num)) - 32;
3774 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(tc_num), fcrth);
3776 /* Configure pause time (2 TCs per register) */
3777 reg = hw->fc.pause_time * 0x00010001;
3778 for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
3779 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
3781 /* Configure flow control refresh threshold value */
3782 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
3789 ixgbe_dcb_pfc_enable(struct rte_eth_dev *dev, uint8_t tc_num)
3791 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3792 int32_t ret_val = IXGBE_NOT_IMPLEMENTED;
3794 if (hw->mac.type != ixgbe_mac_82598EB) {
3795 ret_val = ixgbe_dcb_pfc_enable_generic(hw, tc_num);
3801 ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
3804 uint32_t rx_buf_size;
3805 uint32_t max_high_water;
3807 uint8_t map[IXGBE_DCB_MAX_USER_PRIORITY] = { 0 };
3808 struct ixgbe_hw *hw =
3809 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3810 struct ixgbe_dcb_config *dcb_config =
3811 IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
3813 enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
3820 PMD_INIT_FUNC_TRACE();
3822 ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_RX_CONFIG, map);
3823 tc_num = map[pfc_conf->priority];
3824 rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num));
3825 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
3827 * At least reserve one Ethernet frame for watermark
3828 * high_water/low_water in kilo bytes for ixgbe
3830 max_high_water = (rx_buf_size - ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
3831 if ((pfc_conf->fc.high_water > max_high_water) ||
3832 (pfc_conf->fc.high_water <= pfc_conf->fc.low_water)) {
3833 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
3834 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
3838 hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[pfc_conf->fc.mode];
3839 hw->fc.pause_time = pfc_conf->fc.pause_time;
3840 hw->fc.send_xon = pfc_conf->fc.send_xon;
3841 hw->fc.low_water[tc_num] = pfc_conf->fc.low_water;
3842 hw->fc.high_water[tc_num] = pfc_conf->fc.high_water;
3844 err = ixgbe_dcb_pfc_enable(dev, tc_num);
3846 /* Not negotiated is not an error case */
3847 if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED))
3850 PMD_INIT_LOG(ERR, "ixgbe_dcb_pfc_enable = 0x%x", err);
3855 ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
3856 struct rte_eth_rss_reta_entry64 *reta_conf,
3859 uint16_t i, sp_reta_size;
3862 uint16_t idx, shift;
3863 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3866 PMD_INIT_FUNC_TRACE();
3868 if (!ixgbe_rss_update_sp(hw->mac.type)) {
3869 PMD_DRV_LOG(ERR, "RSS reta update is not supported on this "
3874 sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
3875 if (reta_size != sp_reta_size) {
3876 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3877 "(%d) doesn't match the number hardware can supported "
3878 "(%d)\n", reta_size, sp_reta_size);
3882 for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
3883 idx = i / RTE_RETA_GROUP_SIZE;
3884 shift = i % RTE_RETA_GROUP_SIZE;
3885 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3889 reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
3890 if (mask == IXGBE_4_BIT_MASK)
3893 r = IXGBE_READ_REG(hw, reta_reg);
3894 for (j = 0, reta = 0; j < IXGBE_4_BIT_WIDTH; j++) {
3895 if (mask & (0x1 << j))
3896 reta |= reta_conf[idx].reta[shift + j] <<
3899 reta |= r & (IXGBE_8_BIT_MASK <<
3902 IXGBE_WRITE_REG(hw, reta_reg, reta);
3909 ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
3910 struct rte_eth_rss_reta_entry64 *reta_conf,
3913 uint16_t i, sp_reta_size;
3916 uint16_t idx, shift;
3917 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3920 PMD_INIT_FUNC_TRACE();
3921 sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
3922 if (reta_size != sp_reta_size) {
3923 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3924 "(%d) doesn't match the number hardware can supported "
3925 "(%d)\n", reta_size, sp_reta_size);
3929 for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
3930 idx = i / RTE_RETA_GROUP_SIZE;
3931 shift = i % RTE_RETA_GROUP_SIZE;
3932 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3937 reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
3938 reta = IXGBE_READ_REG(hw, reta_reg);
3939 for (j = 0; j < IXGBE_4_BIT_WIDTH; j++) {
3940 if (mask & (0x1 << j))
3941 reta_conf[idx].reta[shift + j] =
3942 ((reta >> (CHAR_BIT * j)) &
3951 ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
3952 uint32_t index, uint32_t pool)
3954 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3955 uint32_t enable_addr = 1;
3957 ixgbe_set_rar(hw, index, mac_addr->addr_bytes, pool, enable_addr);
3961 ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index)
3963 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3965 ixgbe_clear_rar(hw, index);
3969 ixgbe_set_default_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
3971 ixgbe_remove_rar(dev, 0);
3973 ixgbe_add_rar(dev, addr, 0, 0);
3977 ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
3981 struct ixgbe_hw *hw;
3982 struct rte_eth_dev_info dev_info;
3983 uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
3985 ixgbe_dev_info_get(dev, &dev_info);
3987 /* check that mtu is within the allowed range */
3988 if ((mtu < ETHER_MIN_MTU) || (frame_size > dev_info.max_rx_pktlen))
3991 /* refuse mtu that requires the support of scattered packets when this
3992 * feature has not been enabled before.
3994 if (!dev->data->scattered_rx &&
3995 (frame_size + 2 * IXGBE_VLAN_TAG_SIZE >
3996 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
3999 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4000 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
4002 /* switch to jumbo mode if needed */
4003 if (frame_size > ETHER_MAX_LEN) {
4004 dev->data->dev_conf.rxmode.jumbo_frame = 1;
4005 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
4007 dev->data->dev_conf.rxmode.jumbo_frame = 0;
4008 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
4010 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4012 /* update max frame size */
4013 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
4015 maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
4016 maxfrs &= 0x0000FFFF;
4017 maxfrs |= (dev->data->dev_conf.rxmode.max_rx_pkt_len << 16);
4018 IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, maxfrs);
4024 * Virtual Function operations
4027 ixgbevf_intr_disable(struct ixgbe_hw *hw)
4029 PMD_INIT_FUNC_TRACE();
4031 /* Clear interrupt mask to stop from interrupts being generated */
4032 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
4034 IXGBE_WRITE_FLUSH(hw);
4038 ixgbevf_intr_enable(struct ixgbe_hw *hw)
4040 PMD_INIT_FUNC_TRACE();
4042 /* VF enable interrupt autoclean */
4043 IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, IXGBE_VF_IRQ_ENABLE_MASK);
4044 IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, IXGBE_VF_IRQ_ENABLE_MASK);
4045 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, IXGBE_VF_IRQ_ENABLE_MASK);
4047 IXGBE_WRITE_FLUSH(hw);
4051 ixgbevf_dev_configure(struct rte_eth_dev *dev)
4053 struct rte_eth_conf *conf = &dev->data->dev_conf;
4054 struct ixgbe_adapter *adapter =
4055 (struct ixgbe_adapter *)dev->data->dev_private;
4057 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
4058 dev->data->port_id);
4061 * VF has no ability to enable/disable HW CRC
4062 * Keep the persistent behavior the same as Host PF
4064 #ifndef RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC
4065 if (!conf->rxmode.hw_strip_crc) {
4066 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
4067 conf->rxmode.hw_strip_crc = 1;
4070 if (conf->rxmode.hw_strip_crc) {
4071 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
4072 conf->rxmode.hw_strip_crc = 0;
4077 * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
4078 * allocation or vector Rx preconditions we will reset it.
4080 adapter->rx_bulk_alloc_allowed = true;
4081 adapter->rx_vec_allowed = true;
4087 ixgbevf_dev_start(struct rte_eth_dev *dev)
4089 struct ixgbe_hw *hw =
4090 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4091 uint32_t intr_vector = 0;
4092 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4096 PMD_INIT_FUNC_TRACE();
4098 hw->mac.ops.reset_hw(hw);
4099 hw->mac.get_link_status = true;
4101 /* negotiate mailbox API version to use with the PF. */
4102 ixgbevf_negotiate_api(hw);
4104 ixgbevf_dev_tx_init(dev);
4106 /* This can fail when allocating mbufs for descriptor rings */
4107 err = ixgbevf_dev_rx_init(dev);
4109 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
4110 ixgbe_dev_clear_queues(dev);
4115 ixgbevf_set_vfta_all(dev, 1);
4118 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK |
4119 ETH_VLAN_EXTEND_MASK;
4120 ixgbevf_vlan_offload_set(dev, mask);
4122 ixgbevf_dev_rxtx_start(dev);
4124 /* check and configure queue intr-vector mapping */
4125 if (dev->data->dev_conf.intr_conf.rxq != 0) {
4126 intr_vector = dev->data->nb_rx_queues;
4127 if (rte_intr_efd_enable(intr_handle, intr_vector))
4131 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
4132 intr_handle->intr_vec =
4133 rte_zmalloc("intr_vec",
4134 dev->data->nb_rx_queues * sizeof(int), 0);
4135 if (intr_handle->intr_vec == NULL) {
4136 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
4137 " intr_vec\n", dev->data->nb_rx_queues);
4141 ixgbevf_configure_msix(dev);
4143 rte_intr_enable(intr_handle);
4145 /* Re-enable interrupt for VF */
4146 ixgbevf_intr_enable(hw);
4152 ixgbevf_dev_stop(struct rte_eth_dev *dev)
4154 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4155 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4157 PMD_INIT_FUNC_TRACE();
4159 hw->adapter_stopped = 1;
4160 ixgbe_stop_adapter(hw);
4163 * Clear what we set, but we still keep shadow_vfta to
4164 * restore after device starts
4166 ixgbevf_set_vfta_all(dev, 0);
4168 /* Clear stored conf */
4169 dev->data->scattered_rx = 0;
4171 ixgbe_dev_clear_queues(dev);
4173 /* Clean datapath event and queue/vec mapping */
4174 rte_intr_efd_disable(intr_handle);
4175 if (intr_handle->intr_vec != NULL) {
4176 rte_free(intr_handle->intr_vec);
4177 intr_handle->intr_vec = NULL;
4182 ixgbevf_dev_close(struct rte_eth_dev *dev)
4184 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4186 PMD_INIT_FUNC_TRACE();
4190 ixgbevf_dev_stop(dev);
4192 ixgbe_dev_free_queues(dev);
4195 * Remove the VF MAC address ro ensure
4196 * that the VF traffic goes to the PF
4197 * after stop, close and detach of the VF
4199 ixgbevf_remove_mac_addr(dev, 0);
4202 static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
4204 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4205 struct ixgbe_vfta *shadow_vfta =
4206 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
4207 int i = 0, j = 0, vfta = 0, mask = 1;
4209 for (i = 0; i < IXGBE_VFTA_SIZE; i++) {
4210 vfta = shadow_vfta->vfta[i];
4213 for (j = 0; j < 32; j++) {
4215 ixgbe_set_vfta(hw, (i<<5)+j, 0, on);
4224 ixgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
4226 struct ixgbe_hw *hw =
4227 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4228 struct ixgbe_vfta *shadow_vfta =
4229 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
4230 uint32_t vid_idx = 0;
4231 uint32_t vid_bit = 0;
4234 PMD_INIT_FUNC_TRACE();
4236 /* vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf */
4237 ret = ixgbe_set_vfta(hw, vlan_id, 0, !!on);
4239 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
4242 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
4243 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
4245 /* Save what we set and retore it after device reset */
4247 shadow_vfta->vfta[vid_idx] |= vid_bit;
4249 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
4255 ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
4257 struct ixgbe_hw *hw =
4258 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4261 PMD_INIT_FUNC_TRACE();
4263 if (queue >= hw->mac.max_rx_queues)
4266 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
4268 ctrl |= IXGBE_RXDCTL_VME;
4270 ctrl &= ~IXGBE_RXDCTL_VME;
4271 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
4273 ixgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
4277 ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4279 struct ixgbe_hw *hw =
4280 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4284 /* VF function only support hw strip feature, others are not support */
4285 if (mask & ETH_VLAN_STRIP_MASK) {
4286 on = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
4288 for (i = 0; i < hw->mac.max_rx_queues; i++)
4289 ixgbevf_vlan_strip_queue_set(dev, i, on);
4294 ixgbe_vmdq_mode_check(struct ixgbe_hw *hw)
4298 /* we only need to do this if VMDq is enabled */
4299 reg_val = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
4300 if (!(reg_val & IXGBE_VT_CTL_VT_ENABLE)) {
4301 PMD_INIT_LOG(ERR, "VMDq must be enabled for this setting");
4309 ixgbe_uta_vector(struct ixgbe_hw *hw, struct ether_addr *uc_addr)
4311 uint32_t vector = 0;
4313 switch (hw->mac.mc_filter_type) {
4314 case 0: /* use bits [47:36] of the address */
4315 vector = ((uc_addr->addr_bytes[4] >> 4) |
4316 (((uint16_t)uc_addr->addr_bytes[5]) << 4));
4318 case 1: /* use bits [46:35] of the address */
4319 vector = ((uc_addr->addr_bytes[4] >> 3) |
4320 (((uint16_t)uc_addr->addr_bytes[5]) << 5));
4322 case 2: /* use bits [45:34] of the address */
4323 vector = ((uc_addr->addr_bytes[4] >> 2) |
4324 (((uint16_t)uc_addr->addr_bytes[5]) << 6));
4326 case 3: /* use bits [43:32] of the address */
4327 vector = ((uc_addr->addr_bytes[4]) |
4328 (((uint16_t)uc_addr->addr_bytes[5]) << 8));
4330 default: /* Invalid mc_filter_type */
4334 /* vector can only be 12-bits or boundary will be exceeded */
4340 ixgbe_uc_hash_table_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
4348 const uint32_t ixgbe_uta_idx_mask = 0x7F;
4349 const uint32_t ixgbe_uta_bit_shift = 5;
4350 const uint32_t ixgbe_uta_bit_mask = (0x1 << ixgbe_uta_bit_shift) - 1;
4351 const uint32_t bit1 = 0x1;
4353 struct ixgbe_hw *hw =
4354 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4355 struct ixgbe_uta_info *uta_info =
4356 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
4358 /* The UTA table only exists on 82599 hardware and newer */
4359 if (hw->mac.type < ixgbe_mac_82599EB)
4362 vector = ixgbe_uta_vector(hw, mac_addr);
4363 uta_idx = (vector >> ixgbe_uta_bit_shift) & ixgbe_uta_idx_mask;
4364 uta_shift = vector & ixgbe_uta_bit_mask;
4366 rc = ((uta_info->uta_shadow[uta_idx] >> uta_shift & bit1) != 0);
4370 reg_val = IXGBE_READ_REG(hw, IXGBE_UTA(uta_idx));
4372 uta_info->uta_in_use++;
4373 reg_val |= (bit1 << uta_shift);
4374 uta_info->uta_shadow[uta_idx] |= (bit1 << uta_shift);
4376 uta_info->uta_in_use--;
4377 reg_val &= ~(bit1 << uta_shift);
4378 uta_info->uta_shadow[uta_idx] &= ~(bit1 << uta_shift);
4381 IXGBE_WRITE_REG(hw, IXGBE_UTA(uta_idx), reg_val);
4383 if (uta_info->uta_in_use > 0)
4384 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
4385 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
4387 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
4393 ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on)
4396 struct ixgbe_hw *hw =
4397 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4398 struct ixgbe_uta_info *uta_info =
4399 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
4401 /* The UTA table only exists on 82599 hardware and newer */
4402 if (hw->mac.type < ixgbe_mac_82599EB)
4406 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
4407 uta_info->uta_shadow[i] = ~0;
4408 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
4411 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
4412 uta_info->uta_shadow[i] = 0;
4413 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
4421 ixgbe_convert_vm_rx_mask_to_val(uint16_t rx_mask, uint32_t orig_val)
4423 uint32_t new_val = orig_val;
4425 if (rx_mask & ETH_VMDQ_ACCEPT_UNTAG)
4426 new_val |= IXGBE_VMOLR_AUPE;
4427 if (rx_mask & ETH_VMDQ_ACCEPT_HASH_MC)
4428 new_val |= IXGBE_VMOLR_ROMPE;
4429 if (rx_mask & ETH_VMDQ_ACCEPT_HASH_UC)
4430 new_val |= IXGBE_VMOLR_ROPE;
4431 if (rx_mask & ETH_VMDQ_ACCEPT_BROADCAST)
4432 new_val |= IXGBE_VMOLR_BAM;
4433 if (rx_mask & ETH_VMDQ_ACCEPT_MULTICAST)
4434 new_val |= IXGBE_VMOLR_MPE;
4440 ixgbe_set_pool_rx_mode(struct rte_eth_dev *dev, uint16_t pool,
4441 uint16_t rx_mask, uint8_t on)
4445 struct ixgbe_hw *hw =
4446 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4447 uint32_t vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4449 if (hw->mac.type == ixgbe_mac_82598EB) {
4450 PMD_INIT_LOG(ERR, "setting VF receive mode set should be done"
4451 " on 82599 hardware and newer");
4454 if (ixgbe_vmdq_mode_check(hw) < 0)
4457 val = ixgbe_convert_vm_rx_mask_to_val(rx_mask, val);
4464 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4470 ixgbe_set_pool_rx(struct rte_eth_dev *dev, uint16_t pool, uint8_t on)
4474 const uint8_t bit1 = 0x1;
4476 struct ixgbe_hw *hw =
4477 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4479 if (ixgbe_vmdq_mode_check(hw) < 0)
4482 if (pool >= ETH_64_POOLS)
4485 /* for pool >= 32, set bit in PFVFRE[1], otherwise PFVFRE[0] */
4487 addr = IXGBE_VFRE(1);
4488 val = bit1 << (pool - 32);
4490 addr = IXGBE_VFRE(0);
4494 reg = IXGBE_READ_REG(hw, addr);
4501 IXGBE_WRITE_REG(hw, addr, reg);
4507 ixgbe_set_pool_tx(struct rte_eth_dev *dev, uint16_t pool, uint8_t on)
4511 const uint8_t bit1 = 0x1;
4513 struct ixgbe_hw *hw =
4514 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4516 if (ixgbe_vmdq_mode_check(hw) < 0)
4519 if (pool >= ETH_64_POOLS)
4522 /* for pool >= 32, set bit in PFVFTE[1], otherwise PFVFTE[0] */
4524 addr = IXGBE_VFTE(1);
4525 val = bit1 << (pool - 32);
4527 addr = IXGBE_VFTE(0);
4531 reg = IXGBE_READ_REG(hw, addr);
4538 IXGBE_WRITE_REG(hw, addr, reg);
4544 ixgbe_set_pool_vlan_filter(struct rte_eth_dev *dev, uint16_t vlan,
4545 uint64_t pool_mask, uint8_t vlan_on)
4549 struct ixgbe_hw *hw =
4550 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4552 if (ixgbe_vmdq_mode_check(hw) < 0)
4554 for (pool_idx = 0; pool_idx < ETH_64_POOLS; pool_idx++) {
4555 if (pool_mask & ((uint64_t)(1ULL << pool_idx))) {
4556 ret = hw->mac.ops.set_vfta(hw, vlan, pool_idx, vlan_on);
4565 #define IXGBE_MRCTL_VPME 0x01 /* Virtual Pool Mirroring. */
4566 #define IXGBE_MRCTL_UPME 0x02 /* Uplink Port Mirroring. */
4567 #define IXGBE_MRCTL_DPME 0x04 /* Downlink Port Mirroring. */
4568 #define IXGBE_MRCTL_VLME 0x08 /* VLAN Mirroring. */
4569 #define IXGBE_INVALID_MIRROR_TYPE(mirror_type) \
4570 ((mirror_type) & ~(uint8_t)(ETH_MIRROR_VIRTUAL_POOL_UP | \
4571 ETH_MIRROR_UPLINK_PORT | ETH_MIRROR_DOWNLINK_PORT | ETH_MIRROR_VLAN))
4574 ixgbe_mirror_rule_set(struct rte_eth_dev *dev,
4575 struct rte_eth_mirror_conf *mirror_conf,
4576 uint8_t rule_id, uint8_t on)
4578 uint32_t mr_ctl, vlvf;
4579 uint32_t mp_lsb = 0;
4580 uint32_t mv_msb = 0;
4581 uint32_t mv_lsb = 0;
4582 uint32_t mp_msb = 0;
4585 uint64_t vlan_mask = 0;
4587 const uint8_t pool_mask_offset = 32;
4588 const uint8_t vlan_mask_offset = 32;
4589 const uint8_t dst_pool_offset = 8;
4590 const uint8_t rule_mr_offset = 4;
4591 const uint8_t mirror_rule_mask = 0x0F;
4593 struct ixgbe_mirror_info *mr_info =
4594 (IXGBE_DEV_PRIVATE_TO_PFDATA(dev->data->dev_private));
4595 struct ixgbe_hw *hw =
4596 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4597 uint8_t mirror_type = 0;
4599 if (ixgbe_vmdq_mode_check(hw) < 0)
4602 if (rule_id >= IXGBE_MAX_MIRROR_RULES)
4605 if (IXGBE_INVALID_MIRROR_TYPE(mirror_conf->rule_type)) {
4606 PMD_DRV_LOG(ERR, "unsupported mirror type 0x%x.",
4607 mirror_conf->rule_type);
4611 if (mirror_conf->rule_type & ETH_MIRROR_VLAN) {
4612 mirror_type |= IXGBE_MRCTL_VLME;
4613 /* Check if vlan id is valid and find conresponding VLAN ID index in VLVF */
4614 for (i = 0; i < IXGBE_VLVF_ENTRIES; i++) {
4615 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
4616 /* search vlan id related pool vlan filter index */
4617 reg_index = ixgbe_find_vlvf_slot(hw,
4618 mirror_conf->vlan.vlan_id[i]);
4621 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(reg_index));
4622 if ((vlvf & IXGBE_VLVF_VIEN) &&
4623 ((vlvf & IXGBE_VLVF_VLANID_MASK) ==
4624 mirror_conf->vlan.vlan_id[i]))
4625 vlan_mask |= (1ULL << reg_index);
4632 mv_lsb = vlan_mask & 0xFFFFFFFF;
4633 mv_msb = vlan_mask >> vlan_mask_offset;
4635 mr_info->mr_conf[rule_id].vlan.vlan_mask =
4636 mirror_conf->vlan.vlan_mask;
4637 for (i = 0; i < ETH_VMDQ_MAX_VLAN_FILTERS; i++) {
4638 if (mirror_conf->vlan.vlan_mask & (1ULL << i))
4639 mr_info->mr_conf[rule_id].vlan.vlan_id[i] =
4640 mirror_conf->vlan.vlan_id[i];
4645 mr_info->mr_conf[rule_id].vlan.vlan_mask = 0;
4646 for (i = 0; i < ETH_VMDQ_MAX_VLAN_FILTERS; i++)
4647 mr_info->mr_conf[rule_id].vlan.vlan_id[i] = 0;
4652 * if enable pool mirror, write related pool mask register,if disable
4653 * pool mirror, clear PFMRVM register
4655 if (mirror_conf->rule_type & ETH_MIRROR_VIRTUAL_POOL_UP) {
4656 mirror_type |= IXGBE_MRCTL_VPME;
4658 mp_lsb = mirror_conf->pool_mask & 0xFFFFFFFF;
4659 mp_msb = mirror_conf->pool_mask >> pool_mask_offset;
4660 mr_info->mr_conf[rule_id].pool_mask =
4661 mirror_conf->pool_mask;
4666 mr_info->mr_conf[rule_id].pool_mask = 0;
4669 if (mirror_conf->rule_type & ETH_MIRROR_UPLINK_PORT)
4670 mirror_type |= IXGBE_MRCTL_UPME;
4671 if (mirror_conf->rule_type & ETH_MIRROR_DOWNLINK_PORT)
4672 mirror_type |= IXGBE_MRCTL_DPME;
4674 /* read mirror control register and recalculate it */
4675 mr_ctl = IXGBE_READ_REG(hw, IXGBE_MRCTL(rule_id));
4678 mr_ctl |= mirror_type;
4679 mr_ctl &= mirror_rule_mask;
4680 mr_ctl |= mirror_conf->dst_pool << dst_pool_offset;
4682 mr_ctl &= ~(mirror_conf->rule_type & mirror_rule_mask);
4684 mr_info->mr_conf[rule_id].rule_type = mirror_conf->rule_type;
4685 mr_info->mr_conf[rule_id].dst_pool = mirror_conf->dst_pool;
4687 /* write mirrror control register */
4688 IXGBE_WRITE_REG(hw, IXGBE_MRCTL(rule_id), mr_ctl);
4690 /* write pool mirrror control register */
4691 if (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) {
4692 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id), mp_lsb);
4693 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id + rule_mr_offset),
4696 /* write VLAN mirrror control register */
4697 if (mirror_conf->rule_type == ETH_MIRROR_VLAN) {
4698 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id), mv_lsb);
4699 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id + rule_mr_offset),
4707 ixgbe_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t rule_id)
4710 uint32_t lsb_val = 0;
4711 uint32_t msb_val = 0;
4712 const uint8_t rule_mr_offset = 4;
4714 struct ixgbe_hw *hw =
4715 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4716 struct ixgbe_mirror_info *mr_info =
4717 (IXGBE_DEV_PRIVATE_TO_PFDATA(dev->data->dev_private));
4719 if (ixgbe_vmdq_mode_check(hw) < 0)
4722 memset(&mr_info->mr_conf[rule_id], 0,
4723 sizeof(struct rte_eth_mirror_conf));
4725 /* clear PFVMCTL register */
4726 IXGBE_WRITE_REG(hw, IXGBE_MRCTL(rule_id), mr_ctl);
4728 /* clear pool mask register */
4729 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id), lsb_val);
4730 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id + rule_mr_offset), msb_val);
4732 /* clear vlan mask register */
4733 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id), lsb_val);
4734 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id + rule_mr_offset), msb_val);
4740 ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
4743 struct ixgbe_hw *hw =
4744 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4746 mask = IXGBE_READ_REG(hw, IXGBE_VTEIMS);
4747 mask |= (1 << IXGBE_MISC_VEC_ID);
4748 RTE_SET_USED(queue_id);
4749 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
4751 rte_intr_enable(&dev->pci_dev->intr_handle);
4757 ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
4760 struct ixgbe_hw *hw =
4761 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4763 mask = IXGBE_READ_REG(hw, IXGBE_VTEIMS);
4764 mask &= ~(1 << IXGBE_MISC_VEC_ID);
4765 RTE_SET_USED(queue_id);
4766 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
4772 ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
4775 struct ixgbe_hw *hw =
4776 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4777 struct ixgbe_interrupt *intr =
4778 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4780 if (queue_id < 16) {
4781 ixgbe_disable_intr(hw);
4782 intr->mask |= (1 << queue_id);
4783 ixgbe_enable_intr(dev);
4784 } else if (queue_id < 32) {
4785 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(0));
4786 mask &= (1 << queue_id);
4787 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
4788 } else if (queue_id < 64) {
4789 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(1));
4790 mask &= (1 << (queue_id - 32));
4791 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
4793 rte_intr_enable(&dev->pci_dev->intr_handle);
4799 ixgbe_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
4802 struct ixgbe_hw *hw =
4803 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4804 struct ixgbe_interrupt *intr =
4805 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4807 if (queue_id < 16) {
4808 ixgbe_disable_intr(hw);
4809 intr->mask &= ~(1 << queue_id);
4810 ixgbe_enable_intr(dev);
4811 } else if (queue_id < 32) {
4812 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(0));
4813 mask &= ~(1 << queue_id);
4814 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
4815 } else if (queue_id < 64) {
4816 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(1));
4817 mask &= ~(1 << (queue_id - 32));
4818 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
4825 ixgbevf_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
4826 uint8_t queue, uint8_t msix_vector)
4830 if (direction == -1) {
4832 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
4833 tmp = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
4836 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, tmp);
4838 /* rx or tx cause */
4839 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
4840 idx = ((16 * (queue & 1)) + (8 * direction));
4841 tmp = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1));
4842 tmp &= ~(0xFF << idx);
4843 tmp |= (msix_vector << idx);
4844 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), tmp);
4849 * set the IVAR registers, mapping interrupt causes to vectors
4851 * pointer to ixgbe_hw struct
4853 * 0 for Rx, 1 for Tx, -1 for other causes
4855 * queue to map the corresponding interrupt to
4857 * the vector to map to the corresponding queue
4860 ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
4861 uint8_t queue, uint8_t msix_vector)
4865 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
4866 if (hw->mac.type == ixgbe_mac_82598EB) {
4867 if (direction == -1)
4869 idx = (((direction * 64) + queue) >> 2) & 0x1F;
4870 tmp = IXGBE_READ_REG(hw, IXGBE_IVAR(idx));
4871 tmp &= ~(0xFF << (8 * (queue & 0x3)));
4872 tmp |= (msix_vector << (8 * (queue & 0x3)));
4873 IXGBE_WRITE_REG(hw, IXGBE_IVAR(idx), tmp);
4874 } else if ((hw->mac.type == ixgbe_mac_82599EB) ||
4875 (hw->mac.type == ixgbe_mac_X540)) {
4876 if (direction == -1) {
4878 idx = ((queue & 1) * 8);
4879 tmp = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
4880 tmp &= ~(0xFF << idx);
4881 tmp |= (msix_vector << idx);
4882 IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, tmp);
4884 /* rx or tx causes */
4885 idx = ((16 * (queue & 1)) + (8 * direction));
4886 tmp = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
4887 tmp &= ~(0xFF << idx);
4888 tmp |= (msix_vector << idx);
4889 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), tmp);
4895 ixgbevf_configure_msix(struct rte_eth_dev *dev)
4897 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4898 struct ixgbe_hw *hw =
4899 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4901 uint32_t vector_idx = IXGBE_MISC_VEC_ID;
4903 /* won't configure msix register if no mapping is done
4904 * between intr vector and event fd.
4906 if (!rte_intr_dp_is_en(intr_handle))
4909 /* Configure all RX queues of VF */
4910 for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
4911 /* Force all queue use vector 0,
4912 * as IXGBE_VF_MAXMSIVECOTR = 1
4914 ixgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
4915 intr_handle->intr_vec[q_idx] = vector_idx;
4918 /* Configure VF other cause ivar */
4919 ixgbevf_set_ivar_map(hw, -1, 1, vector_idx);
4923 * Sets up the hardware to properly generate MSI-X interrupts
4925 * board private structure
4928 ixgbe_configure_msix(struct rte_eth_dev *dev)
4930 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4931 struct ixgbe_hw *hw =
4932 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4933 uint32_t queue_id, base = IXGBE_MISC_VEC_ID;
4934 uint32_t vec = IXGBE_MISC_VEC_ID;
4938 /* won't configure msix register if no mapping is done
4939 * between intr vector and event fd
4941 if (!rte_intr_dp_is_en(intr_handle))
4944 if (rte_intr_allow_others(intr_handle))
4945 vec = base = IXGBE_RX_VEC_START;
4947 /* setup GPIE for MSI-x mode */
4948 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
4949 gpie |= IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4950 IXGBE_GPIE_OCD | IXGBE_GPIE_EIAME;
4951 /* auto clearing and auto setting corresponding bits in EIMS
4952 * when MSI-X interrupt is triggered
4954 if (hw->mac.type == ixgbe_mac_82598EB) {
4955 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4957 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4958 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4960 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4962 /* Populate the IVAR table and set the ITR values to the
4963 * corresponding register.
4965 for (queue_id = 0; queue_id < dev->data->nb_rx_queues;
4967 /* by default, 1:1 mapping */
4968 ixgbe_set_ivar_map(hw, 0, queue_id, vec);
4969 intr_handle->intr_vec[queue_id] = vec;
4970 if (vec < base + intr_handle->nb_efd - 1)
4974 switch (hw->mac.type) {
4975 case ixgbe_mac_82598EB:
4976 ixgbe_set_ivar_map(hw, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
4979 case ixgbe_mac_82599EB:
4980 case ixgbe_mac_X540:
4981 ixgbe_set_ivar_map(hw, -1, 1, IXGBE_MISC_VEC_ID);
4986 IXGBE_WRITE_REG(hw, IXGBE_EITR(IXGBE_MISC_VEC_ID),
4987 IXGBE_MIN_INTER_INTERRUPT_INTERVAL_DEFAULT & 0xFFF);
4989 /* set up to autoclear timer, and the vectors */
4990 mask = IXGBE_EIMS_ENABLE_MASK;
4991 mask &= ~(IXGBE_EIMS_OTHER |
4992 IXGBE_EIMS_MAILBOX |
4995 IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask);
4998 static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
4999 uint16_t queue_idx, uint16_t tx_rate)
5001 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5002 uint32_t rf_dec, rf_int;
5004 uint16_t link_speed = dev->data->dev_link.link_speed;
5006 if (queue_idx >= hw->mac.max_tx_queues)
5010 /* Calculate the rate factor values to set */
5011 rf_int = (uint32_t)link_speed / (uint32_t)tx_rate;
5012 rf_dec = (uint32_t)link_speed % (uint32_t)tx_rate;
5013 rf_dec = (rf_dec << IXGBE_RTTBCNRC_RF_INT_SHIFT) / tx_rate;
5015 bcnrc_val = IXGBE_RTTBCNRC_RS_ENA;
5016 bcnrc_val |= ((rf_int << IXGBE_RTTBCNRC_RF_INT_SHIFT) &
5017 IXGBE_RTTBCNRC_RF_INT_MASK_M);
5018 bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK);
5024 * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
5025 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported, otherwise
5028 if ((dev->data->dev_conf.rxmode.jumbo_frame == 1) &&
5029 (dev->data->dev_conf.rxmode.max_rx_pkt_len >=
5030 IXGBE_MAX_JUMBO_FRAME_SIZE))
5031 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM,
5032 IXGBE_MMW_SIZE_JUMBO_FRAME);
5034 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM,
5035 IXGBE_MMW_SIZE_DEFAULT);
5037 /* Set RTTBCNRC of queue X */
5038 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_idx);
5039 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
5040 IXGBE_WRITE_FLUSH(hw);
5045 static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
5046 uint16_t tx_rate, uint64_t q_msk)
5048 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5049 struct ixgbe_vf_info *vfinfo =
5050 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
5051 uint8_t nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
5052 uint32_t queue_stride =
5053 IXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
5054 uint32_t queue_idx = vf * queue_stride, idx = 0, vf_idx;
5055 uint32_t queue_end = queue_idx + nb_q_per_pool - 1;
5056 uint16_t total_rate = 0;
5058 if (queue_end >= hw->mac.max_tx_queues)
5061 if (vfinfo != NULL) {
5062 for (vf_idx = 0; vf_idx < dev->pci_dev->max_vfs; vf_idx++) {
5065 for (idx = 0; idx < RTE_DIM(vfinfo[vf_idx].tx_rate);
5067 total_rate += vfinfo[vf_idx].tx_rate[idx];
5072 /* Store tx_rate for this vf. */
5073 for (idx = 0; idx < nb_q_per_pool; idx++) {
5074 if (((uint64_t)0x1 << idx) & q_msk) {
5075 if (vfinfo[vf].tx_rate[idx] != tx_rate)
5076 vfinfo[vf].tx_rate[idx] = tx_rate;
5077 total_rate += tx_rate;
5081 if (total_rate > dev->data->dev_link.link_speed) {
5083 * Reset stored TX rate of the VF if it causes exceed
5086 memset(vfinfo[vf].tx_rate, 0, sizeof(vfinfo[vf].tx_rate));
5090 /* Set RTTBCNRC of each queue/pool for vf X */
5091 for (; queue_idx <= queue_end; queue_idx++) {
5093 ixgbe_set_queue_rate_limit(dev, queue_idx, tx_rate);
5101 ixgbevf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
5102 __attribute__((unused)) uint32_t index,
5103 __attribute__((unused)) uint32_t pool)
5105 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5109 * On a 82599 VF, adding again the same MAC addr is not an idempotent
5110 * operation. Trap this case to avoid exhausting the [very limited]
5111 * set of PF resources used to store VF MAC addresses.
5113 if (memcmp(hw->mac.perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
5115 diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
5118 PMD_DRV_LOG(ERR, "Unable to add MAC address - diag=%d", diag);
5122 ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
5124 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5125 struct ether_addr *perm_addr = (struct ether_addr *) hw->mac.perm_addr;
5126 struct ether_addr *mac_addr;
5131 * The IXGBE_VF_SET_MACVLAN command of the ixgbe-pf driver does
5132 * not support the deletion of a given MAC address.
5133 * Instead, it imposes to delete all MAC addresses, then to add again
5134 * all MAC addresses with the exception of the one to be deleted.
5136 (void) ixgbevf_set_uc_addr_vf(hw, 0, NULL);
5139 * Add again all MAC addresses, with the exception of the deleted one
5140 * and of the permanent MAC address.
5142 for (i = 0, mac_addr = dev->data->mac_addrs;
5143 i < hw->mac.num_rar_entries; i++, mac_addr++) {
5144 /* Skip the deleted MAC address */
5147 /* Skip NULL MAC addresses */
5148 if (is_zero_ether_addr(mac_addr))
5150 /* Skip the permanent MAC address */
5151 if (memcmp(perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
5153 diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
5156 "Adding again MAC address "
5157 "%02x:%02x:%02x:%02x:%02x:%02x failed "
5159 mac_addr->addr_bytes[0],
5160 mac_addr->addr_bytes[1],
5161 mac_addr->addr_bytes[2],
5162 mac_addr->addr_bytes[3],
5163 mac_addr->addr_bytes[4],
5164 mac_addr->addr_bytes[5],
5170 ixgbevf_set_default_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
5172 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5174 hw->mac.ops.set_rar(hw, 0, (void *)addr, 0, 0);
5177 #define MAC_TYPE_FILTER_SUP(type) do {\
5178 if ((type) != ixgbe_mac_82599EB && (type) != ixgbe_mac_X540 &&\
5179 (type) != ixgbe_mac_X550 && (type) != ixgbe_mac_X550EM_x &&\
5180 (type) != ixgbe_mac_X550EM_a)\
5185 ixgbe_syn_filter_set(struct rte_eth_dev *dev,
5186 struct rte_eth_syn_filter *filter,
5189 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5192 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
5195 synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
5198 if (synqf & IXGBE_SYN_FILTER_ENABLE)
5200 synqf = (uint32_t)(((filter->queue << IXGBE_SYN_FILTER_QUEUE_SHIFT) &
5201 IXGBE_SYN_FILTER_QUEUE) | IXGBE_SYN_FILTER_ENABLE);
5203 if (filter->hig_pri)
5204 synqf |= IXGBE_SYN_FILTER_SYNQFP;
5206 synqf &= ~IXGBE_SYN_FILTER_SYNQFP;
5208 if (!(synqf & IXGBE_SYN_FILTER_ENABLE))
5210 synqf &= ~(IXGBE_SYN_FILTER_QUEUE | IXGBE_SYN_FILTER_ENABLE);
5212 IXGBE_WRITE_REG(hw, IXGBE_SYNQF, synqf);
5213 IXGBE_WRITE_FLUSH(hw);
5218 ixgbe_syn_filter_get(struct rte_eth_dev *dev,
5219 struct rte_eth_syn_filter *filter)
5221 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5222 uint32_t synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
5224 if (synqf & IXGBE_SYN_FILTER_ENABLE) {
5225 filter->hig_pri = (synqf & IXGBE_SYN_FILTER_SYNQFP) ? 1 : 0;
5226 filter->queue = (uint16_t)((synqf & IXGBE_SYN_FILTER_QUEUE) >> 1);
5233 ixgbe_syn_filter_handle(struct rte_eth_dev *dev,
5234 enum rte_filter_op filter_op,
5237 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5240 MAC_TYPE_FILTER_SUP(hw->mac.type);
5242 if (filter_op == RTE_ETH_FILTER_NOP)
5246 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
5251 switch (filter_op) {
5252 case RTE_ETH_FILTER_ADD:
5253 ret = ixgbe_syn_filter_set(dev,
5254 (struct rte_eth_syn_filter *)arg,
5257 case RTE_ETH_FILTER_DELETE:
5258 ret = ixgbe_syn_filter_set(dev,
5259 (struct rte_eth_syn_filter *)arg,
5262 case RTE_ETH_FILTER_GET:
5263 ret = ixgbe_syn_filter_get(dev,
5264 (struct rte_eth_syn_filter *)arg);
5267 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
5276 static inline enum ixgbe_5tuple_protocol
5277 convert_protocol_type(uint8_t protocol_value)
5279 if (protocol_value == IPPROTO_TCP)
5280 return IXGBE_FILTER_PROTOCOL_TCP;
5281 else if (protocol_value == IPPROTO_UDP)
5282 return IXGBE_FILTER_PROTOCOL_UDP;
5283 else if (protocol_value == IPPROTO_SCTP)
5284 return IXGBE_FILTER_PROTOCOL_SCTP;
5286 return IXGBE_FILTER_PROTOCOL_NONE;
5290 * add a 5tuple filter
5293 * dev: Pointer to struct rte_eth_dev.
5294 * index: the index the filter allocates.
5295 * filter: ponter to the filter that will be added.
5296 * rx_queue: the queue id the filter assigned to.
5299 * - On success, zero.
5300 * - On failure, a negative value.
5303 ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
5304 struct ixgbe_5tuple_filter *filter)
5306 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5307 struct ixgbe_filter_info *filter_info =
5308 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5310 uint32_t ftqf, sdpqf;
5311 uint32_t l34timir = 0;
5312 uint8_t mask = 0xff;
5315 * look for an unused 5tuple filter index,
5316 * and insert the filter to list.
5318 for (i = 0; i < IXGBE_MAX_FTQF_FILTERS; i++) {
5319 idx = i / (sizeof(uint32_t) * NBBY);
5320 shift = i % (sizeof(uint32_t) * NBBY);
5321 if (!(filter_info->fivetuple_mask[idx] & (1 << shift))) {
5322 filter_info->fivetuple_mask[idx] |= 1 << shift;
5324 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
5330 if (i >= IXGBE_MAX_FTQF_FILTERS) {
5331 PMD_DRV_LOG(ERR, "5tuple filters are full.");
5335 sdpqf = (uint32_t)(filter->filter_info.dst_port <<
5336 IXGBE_SDPQF_DSTPORT_SHIFT);
5337 sdpqf = sdpqf | (filter->filter_info.src_port & IXGBE_SDPQF_SRCPORT);
5339 ftqf = (uint32_t)(filter->filter_info.proto &
5340 IXGBE_FTQF_PROTOCOL_MASK);
5341 ftqf |= (uint32_t)((filter->filter_info.priority &
5342 IXGBE_FTQF_PRIORITY_MASK) << IXGBE_FTQF_PRIORITY_SHIFT);
5343 if (filter->filter_info.src_ip_mask == 0) /* 0 means compare. */
5344 mask &= IXGBE_FTQF_SOURCE_ADDR_MASK;
5345 if (filter->filter_info.dst_ip_mask == 0)
5346 mask &= IXGBE_FTQF_DEST_ADDR_MASK;
5347 if (filter->filter_info.src_port_mask == 0)
5348 mask &= IXGBE_FTQF_SOURCE_PORT_MASK;
5349 if (filter->filter_info.dst_port_mask == 0)
5350 mask &= IXGBE_FTQF_DEST_PORT_MASK;
5351 if (filter->filter_info.proto_mask == 0)
5352 mask &= IXGBE_FTQF_PROTOCOL_COMP_MASK;
5353 ftqf |= mask << IXGBE_FTQF_5TUPLE_MASK_SHIFT;
5354 ftqf |= IXGBE_FTQF_POOL_MASK_EN;
5355 ftqf |= IXGBE_FTQF_QUEUE_ENABLE;
5357 IXGBE_WRITE_REG(hw, IXGBE_DAQF(i), filter->filter_info.dst_ip);
5358 IXGBE_WRITE_REG(hw, IXGBE_SAQF(i), filter->filter_info.src_ip);
5359 IXGBE_WRITE_REG(hw, IXGBE_SDPQF(i), sdpqf);
5360 IXGBE_WRITE_REG(hw, IXGBE_FTQF(i), ftqf);
5362 l34timir |= IXGBE_L34T_IMIR_RESERVE;
5363 l34timir |= (uint32_t)(filter->queue <<
5364 IXGBE_L34T_IMIR_QUEUE_SHIFT);
5365 IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(i), l34timir);
5370 * remove a 5tuple filter
5373 * dev: Pointer to struct rte_eth_dev.
5374 * filter: the pointer of the filter will be removed.
5377 ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
5378 struct ixgbe_5tuple_filter *filter)
5380 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5381 struct ixgbe_filter_info *filter_info =
5382 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5383 uint16_t index = filter->index;
5385 filter_info->fivetuple_mask[index / (sizeof(uint32_t) * NBBY)] &=
5386 ~(1 << (index % (sizeof(uint32_t) * NBBY)));
5387 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
5390 IXGBE_WRITE_REG(hw, IXGBE_DAQF(index), 0);
5391 IXGBE_WRITE_REG(hw, IXGBE_SAQF(index), 0);
5392 IXGBE_WRITE_REG(hw, IXGBE_SDPQF(index), 0);
5393 IXGBE_WRITE_REG(hw, IXGBE_FTQF(index), 0);
5394 IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(index), 0);
5398 ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
5400 struct ixgbe_hw *hw;
5401 uint32_t max_frame = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
5403 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5405 if ((mtu < ETHER_MIN_MTU) || (max_frame > ETHER_MAX_JUMBO_FRAME_LEN))
5408 /* refuse mtu that requires the support of scattered packets when this
5409 * feature has not been enabled before.
5411 if (!dev->data->scattered_rx &&
5412 (max_frame + 2 * IXGBE_VLAN_TAG_SIZE >
5413 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
5417 * When supported by the underlying PF driver, use the IXGBE_VF_SET_MTU
5418 * request of the version 2.0 of the mailbox API.
5419 * For now, use the IXGBE_VF_SET_LPE request of the version 1.0
5420 * of the mailbox API.
5421 * This call to IXGBE_SET_LPE action won't work with ixgbe pf drivers
5422 * prior to 3.11.33 which contains the following change:
5423 * "ixgbe: Enable jumbo frames support w/ SR-IOV"
5425 ixgbevf_rlpml_set_vf(hw, max_frame);
5427 /* update max frame size */
5428 dev->data->dev_conf.rxmode.max_rx_pkt_len = max_frame;
5432 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
5433 if ((type) != ixgbe_mac_82599EB && (type) != ixgbe_mac_X540)\
5437 static inline struct ixgbe_5tuple_filter *
5438 ixgbe_5tuple_filter_lookup(struct ixgbe_5tuple_filter_list *filter_list,
5439 struct ixgbe_5tuple_filter_info *key)
5441 struct ixgbe_5tuple_filter *it;
5443 TAILQ_FOREACH(it, filter_list, entries) {
5444 if (memcmp(key, &it->filter_info,
5445 sizeof(struct ixgbe_5tuple_filter_info)) == 0) {
5452 /* translate elements in struct rte_eth_ntuple_filter to struct ixgbe_5tuple_filter_info*/
5454 ntuple_filter_to_5tuple(struct rte_eth_ntuple_filter *filter,
5455 struct ixgbe_5tuple_filter_info *filter_info)
5457 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM ||
5458 filter->priority > IXGBE_5TUPLE_MAX_PRI ||
5459 filter->priority < IXGBE_5TUPLE_MIN_PRI)
5462 switch (filter->dst_ip_mask) {
5464 filter_info->dst_ip_mask = 0;
5465 filter_info->dst_ip = filter->dst_ip;
5468 filter_info->dst_ip_mask = 1;
5471 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
5475 switch (filter->src_ip_mask) {
5477 filter_info->src_ip_mask = 0;
5478 filter_info->src_ip = filter->src_ip;
5481 filter_info->src_ip_mask = 1;
5484 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
5488 switch (filter->dst_port_mask) {
5490 filter_info->dst_port_mask = 0;
5491 filter_info->dst_port = filter->dst_port;
5494 filter_info->dst_port_mask = 1;
5497 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
5501 switch (filter->src_port_mask) {
5503 filter_info->src_port_mask = 0;
5504 filter_info->src_port = filter->src_port;
5507 filter_info->src_port_mask = 1;
5510 PMD_DRV_LOG(ERR, "invalid src_port mask.");
5514 switch (filter->proto_mask) {
5516 filter_info->proto_mask = 0;
5517 filter_info->proto =
5518 convert_protocol_type(filter->proto);
5521 filter_info->proto_mask = 1;
5524 PMD_DRV_LOG(ERR, "invalid protocol mask.");
5528 filter_info->priority = (uint8_t)filter->priority;
5533 * add or delete a ntuple filter
5536 * dev: Pointer to struct rte_eth_dev.
5537 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
5538 * add: if true, add filter, if false, remove filter
5541 * - On success, zero.
5542 * - On failure, a negative value.
5545 ixgbe_add_del_ntuple_filter(struct rte_eth_dev *dev,
5546 struct rte_eth_ntuple_filter *ntuple_filter,
5549 struct ixgbe_filter_info *filter_info =
5550 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5551 struct ixgbe_5tuple_filter_info filter_5tuple;
5552 struct ixgbe_5tuple_filter *filter;
5555 if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
5556 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
5560 memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
5561 ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
5565 filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
5567 if (filter != NULL && add) {
5568 PMD_DRV_LOG(ERR, "filter exists.");
5571 if (filter == NULL && !add) {
5572 PMD_DRV_LOG(ERR, "filter doesn't exist.");
5577 filter = rte_zmalloc("ixgbe_5tuple_filter",
5578 sizeof(struct ixgbe_5tuple_filter), 0);
5581 (void)rte_memcpy(&filter->filter_info,
5583 sizeof(struct ixgbe_5tuple_filter_info));
5584 filter->queue = ntuple_filter->queue;
5585 ret = ixgbe_add_5tuple_filter(dev, filter);
5591 ixgbe_remove_5tuple_filter(dev, filter);
5597 * get a ntuple filter
5600 * dev: Pointer to struct rte_eth_dev.
5601 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
5604 * - On success, zero.
5605 * - On failure, a negative value.
5608 ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
5609 struct rte_eth_ntuple_filter *ntuple_filter)
5611 struct ixgbe_filter_info *filter_info =
5612 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5613 struct ixgbe_5tuple_filter_info filter_5tuple;
5614 struct ixgbe_5tuple_filter *filter;
5617 if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
5618 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
5622 memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
5623 ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
5627 filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
5629 if (filter == NULL) {
5630 PMD_DRV_LOG(ERR, "filter doesn't exist.");
5633 ntuple_filter->queue = filter->queue;
5638 * ixgbe_ntuple_filter_handle - Handle operations for ntuple filter.
5639 * @dev: pointer to rte_eth_dev structure
5640 * @filter_op:operation will be taken.
5641 * @arg: a pointer to specific structure corresponding to the filter_op
5644 * - On success, zero.
5645 * - On failure, a negative value.
5648 ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
5649 enum rte_filter_op filter_op,
5652 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5655 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
5657 if (filter_op == RTE_ETH_FILTER_NOP)
5661 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
5666 switch (filter_op) {
5667 case RTE_ETH_FILTER_ADD:
5668 ret = ixgbe_add_del_ntuple_filter(dev,
5669 (struct rte_eth_ntuple_filter *)arg,
5672 case RTE_ETH_FILTER_DELETE:
5673 ret = ixgbe_add_del_ntuple_filter(dev,
5674 (struct rte_eth_ntuple_filter *)arg,
5677 case RTE_ETH_FILTER_GET:
5678 ret = ixgbe_get_ntuple_filter(dev,
5679 (struct rte_eth_ntuple_filter *)arg);
5682 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
5690 ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
5695 for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
5696 if (filter_info->ethertype_filters[i] == ethertype &&
5697 (filter_info->ethertype_mask & (1 << i)))
5704 ixgbe_ethertype_filter_insert(struct ixgbe_filter_info *filter_info,
5709 for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
5710 if (!(filter_info->ethertype_mask & (1 << i))) {
5711 filter_info->ethertype_mask |= 1 << i;
5712 filter_info->ethertype_filters[i] = ethertype;
5720 ixgbe_ethertype_filter_remove(struct ixgbe_filter_info *filter_info,
5723 if (idx >= IXGBE_MAX_ETQF_FILTERS)
5725 filter_info->ethertype_mask &= ~(1 << idx);
5726 filter_info->ethertype_filters[idx] = 0;
5731 ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
5732 struct rte_eth_ethertype_filter *filter,
5735 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5736 struct ixgbe_filter_info *filter_info =
5737 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5742 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
5745 if (filter->ether_type == ETHER_TYPE_IPv4 ||
5746 filter->ether_type == ETHER_TYPE_IPv6) {
5747 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
5748 " ethertype filter.", filter->ether_type);
5752 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
5753 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
5756 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
5757 PMD_DRV_LOG(ERR, "drop option is unsupported.");
5761 ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
5762 if (ret >= 0 && add) {
5763 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
5764 filter->ether_type);
5767 if (ret < 0 && !add) {
5768 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
5769 filter->ether_type);
5774 ret = ixgbe_ethertype_filter_insert(filter_info,
5775 filter->ether_type);
5777 PMD_DRV_LOG(ERR, "ethertype filters are full.");
5780 etqf = IXGBE_ETQF_FILTER_EN;
5781 etqf |= (uint32_t)filter->ether_type;
5782 etqs |= (uint32_t)((filter->queue <<
5783 IXGBE_ETQS_RX_QUEUE_SHIFT) &
5784 IXGBE_ETQS_RX_QUEUE);
5785 etqs |= IXGBE_ETQS_QUEUE_EN;
5787 ret = ixgbe_ethertype_filter_remove(filter_info, (uint8_t)ret);
5791 IXGBE_WRITE_REG(hw, IXGBE_ETQF(ret), etqf);
5792 IXGBE_WRITE_REG(hw, IXGBE_ETQS(ret), etqs);
5793 IXGBE_WRITE_FLUSH(hw);
5799 ixgbe_get_ethertype_filter(struct rte_eth_dev *dev,
5800 struct rte_eth_ethertype_filter *filter)
5802 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5803 struct ixgbe_filter_info *filter_info =
5804 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5805 uint32_t etqf, etqs;
5808 ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
5810 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
5811 filter->ether_type);
5815 etqf = IXGBE_READ_REG(hw, IXGBE_ETQF(ret));
5816 if (etqf & IXGBE_ETQF_FILTER_EN) {
5817 etqs = IXGBE_READ_REG(hw, IXGBE_ETQS(ret));
5818 filter->ether_type = etqf & IXGBE_ETQF_ETHERTYPE;
5820 filter->queue = (etqs & IXGBE_ETQS_RX_QUEUE) >>
5821 IXGBE_ETQS_RX_QUEUE_SHIFT;
5828 * ixgbe_ethertype_filter_handle - Handle operations for ethertype filter.
5829 * @dev: pointer to rte_eth_dev structure
5830 * @filter_op:operation will be taken.
5831 * @arg: a pointer to specific structure corresponding to the filter_op
5834 ixgbe_ethertype_filter_handle(struct rte_eth_dev *dev,
5835 enum rte_filter_op filter_op,
5838 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5841 MAC_TYPE_FILTER_SUP(hw->mac.type);
5843 if (filter_op == RTE_ETH_FILTER_NOP)
5847 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
5852 switch (filter_op) {
5853 case RTE_ETH_FILTER_ADD:
5854 ret = ixgbe_add_del_ethertype_filter(dev,
5855 (struct rte_eth_ethertype_filter *)arg,
5858 case RTE_ETH_FILTER_DELETE:
5859 ret = ixgbe_add_del_ethertype_filter(dev,
5860 (struct rte_eth_ethertype_filter *)arg,
5863 case RTE_ETH_FILTER_GET:
5864 ret = ixgbe_get_ethertype_filter(dev,
5865 (struct rte_eth_ethertype_filter *)arg);
5868 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
5876 ixgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
5877 enum rte_filter_type filter_type,
5878 enum rte_filter_op filter_op,
5883 switch (filter_type) {
5884 case RTE_ETH_FILTER_NTUPLE:
5885 ret = ixgbe_ntuple_filter_handle(dev, filter_op, arg);
5887 case RTE_ETH_FILTER_ETHERTYPE:
5888 ret = ixgbe_ethertype_filter_handle(dev, filter_op, arg);
5890 case RTE_ETH_FILTER_SYN:
5891 ret = ixgbe_syn_filter_handle(dev, filter_op, arg);
5893 case RTE_ETH_FILTER_FDIR:
5894 ret = ixgbe_fdir_ctrl_func(dev, filter_op, arg);
5896 case RTE_ETH_FILTER_L2_TUNNEL:
5897 ret = ixgbe_dev_l2_tunnel_filter_handle(dev, filter_op, arg);
5900 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
5909 ixgbe_dev_addr_list_itr(__attribute__((unused)) struct ixgbe_hw *hw,
5910 u8 **mc_addr_ptr, u32 *vmdq)
5915 mc_addr = *mc_addr_ptr;
5916 *mc_addr_ptr = (mc_addr + sizeof(struct ether_addr));
5921 ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
5922 struct ether_addr *mc_addr_set,
5923 uint32_t nb_mc_addr)
5925 struct ixgbe_hw *hw;
5928 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5929 mc_addr_list = (u8 *)mc_addr_set;
5930 return ixgbe_update_mc_addr_list(hw, mc_addr_list, nb_mc_addr,
5931 ixgbe_dev_addr_list_itr, TRUE);
5935 ixgbe_read_systime_cyclecounter(struct rte_eth_dev *dev)
5937 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5938 uint64_t systime_cycles;
5940 switch (hw->mac.type) {
5941 case ixgbe_mac_X550:
5942 case ixgbe_mac_X550EM_x:
5943 case ixgbe_mac_X550EM_a:
5944 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
5945 systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
5946 systime_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
5950 systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
5951 systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
5955 return systime_cycles;
5959 ixgbe_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
5961 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5962 uint64_t rx_tstamp_cycles;
5964 switch (hw->mac.type) {
5965 case ixgbe_mac_X550:
5966 case ixgbe_mac_X550EM_x:
5967 case ixgbe_mac_X550EM_a:
5968 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
5969 rx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
5970 rx_tstamp_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPH)
5974 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
5975 rx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
5976 rx_tstamp_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPH)
5980 return rx_tstamp_cycles;
5984 ixgbe_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
5986 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5987 uint64_t tx_tstamp_cycles;
5989 switch (hw->mac.type) {
5990 case ixgbe_mac_X550:
5991 case ixgbe_mac_X550EM_x:
5992 case ixgbe_mac_X550EM_a:
5993 /* TXSTMPL stores ns and TXSTMPH stores seconds. */
5994 tx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
5995 tx_tstamp_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPH)
5999 /* TXSTMPL stores ns and TXSTMPH stores seconds. */
6000 tx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
6001 tx_tstamp_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPH)
6005 return tx_tstamp_cycles;
6009 ixgbe_start_timecounters(struct rte_eth_dev *dev)
6011 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6012 struct ixgbe_adapter *adapter =
6013 (struct ixgbe_adapter *)dev->data->dev_private;
6014 struct rte_eth_link link;
6015 uint32_t incval = 0;
6018 /* Get current link speed. */
6019 memset(&link, 0, sizeof(link));
6020 ixgbe_dev_link_update(dev, 1);
6021 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
6023 switch (link.link_speed) {
6024 case ETH_SPEED_NUM_100M:
6025 incval = IXGBE_INCVAL_100;
6026 shift = IXGBE_INCVAL_SHIFT_100;
6028 case ETH_SPEED_NUM_1G:
6029 incval = IXGBE_INCVAL_1GB;
6030 shift = IXGBE_INCVAL_SHIFT_1GB;
6032 case ETH_SPEED_NUM_10G:
6034 incval = IXGBE_INCVAL_10GB;
6035 shift = IXGBE_INCVAL_SHIFT_10GB;
6039 switch (hw->mac.type) {
6040 case ixgbe_mac_X550:
6041 case ixgbe_mac_X550EM_x:
6042 case ixgbe_mac_X550EM_a:
6043 /* Independent of link speed. */
6045 /* Cycles read will be interpreted as ns. */
6048 case ixgbe_mac_X540:
6049 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, incval);
6051 case ixgbe_mac_82599EB:
6052 incval >>= IXGBE_INCVAL_SHIFT_82599;
6053 shift -= IXGBE_INCVAL_SHIFT_82599;
6054 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA,
6055 (1 << IXGBE_INCPER_SHIFT_82599) | incval);
6058 /* Not supported. */
6062 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
6063 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
6064 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
6066 adapter->systime_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
6067 adapter->systime_tc.cc_shift = shift;
6068 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
6070 adapter->rx_tstamp_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
6071 adapter->rx_tstamp_tc.cc_shift = shift;
6072 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
6074 adapter->tx_tstamp_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
6075 adapter->tx_tstamp_tc.cc_shift = shift;
6076 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
6080 ixgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
6082 struct ixgbe_adapter *adapter =
6083 (struct ixgbe_adapter *)dev->data->dev_private;
6085 adapter->systime_tc.nsec += delta;
6086 adapter->rx_tstamp_tc.nsec += delta;
6087 adapter->tx_tstamp_tc.nsec += delta;
6093 ixgbe_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
6096 struct ixgbe_adapter *adapter =
6097 (struct ixgbe_adapter *)dev->data->dev_private;
6099 ns = rte_timespec_to_ns(ts);
6100 /* Set the timecounters to a new value. */
6101 adapter->systime_tc.nsec = ns;
6102 adapter->rx_tstamp_tc.nsec = ns;
6103 adapter->tx_tstamp_tc.nsec = ns;
6109 ixgbe_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
6111 uint64_t ns, systime_cycles;
6112 struct ixgbe_adapter *adapter =
6113 (struct ixgbe_adapter *)dev->data->dev_private;
6115 systime_cycles = ixgbe_read_systime_cyclecounter(dev);
6116 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
6117 *ts = rte_ns_to_timespec(ns);
6123 ixgbe_timesync_enable(struct rte_eth_dev *dev)
6125 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6129 /* Stop the timesync system time. */
6130 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0x0);
6131 /* Reset the timesync system time value. */
6132 IXGBE_WRITE_REG(hw, IXGBE_SYSTIML, 0x0);
6133 IXGBE_WRITE_REG(hw, IXGBE_SYSTIMH, 0x0);
6135 /* Enable system time for platforms where it isn't on by default. */
6136 tsauxc = IXGBE_READ_REG(hw, IXGBE_TSAUXC);
6137 tsauxc &= ~IXGBE_TSAUXC_DISABLE_SYSTIME;
6138 IXGBE_WRITE_REG(hw, IXGBE_TSAUXC, tsauxc);
6140 ixgbe_start_timecounters(dev);
6142 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
6143 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588),
6145 IXGBE_ETQF_FILTER_EN |
6148 /* Enable timestamping of received PTP packets. */
6149 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
6150 tsync_ctl |= IXGBE_TSYNCRXCTL_ENABLED;
6151 IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
6153 /* Enable timestamping of transmitted PTP packets. */
6154 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
6155 tsync_ctl |= IXGBE_TSYNCTXCTL_ENABLED;
6156 IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
6158 IXGBE_WRITE_FLUSH(hw);
6164 ixgbe_timesync_disable(struct rte_eth_dev *dev)
6166 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6169 /* Disable timestamping of transmitted PTP packets. */
6170 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
6171 tsync_ctl &= ~IXGBE_TSYNCTXCTL_ENABLED;
6172 IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
6174 /* Disable timestamping of received PTP packets. */
6175 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
6176 tsync_ctl &= ~IXGBE_TSYNCRXCTL_ENABLED;
6177 IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
6179 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
6180 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588), 0);
6182 /* Stop incrementating the System Time registers. */
6183 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0);
6189 ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
6190 struct timespec *timestamp,
6191 uint32_t flags __rte_unused)
6193 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6194 struct ixgbe_adapter *adapter =
6195 (struct ixgbe_adapter *)dev->data->dev_private;
6196 uint32_t tsync_rxctl;
6197 uint64_t rx_tstamp_cycles;
6200 tsync_rxctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
6201 if ((tsync_rxctl & IXGBE_TSYNCRXCTL_VALID) == 0)
6204 rx_tstamp_cycles = ixgbe_read_rx_tstamp_cyclecounter(dev);
6205 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
6206 *timestamp = rte_ns_to_timespec(ns);
6212 ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
6213 struct timespec *timestamp)
6215 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6216 struct ixgbe_adapter *adapter =
6217 (struct ixgbe_adapter *)dev->data->dev_private;
6218 uint32_t tsync_txctl;
6219 uint64_t tx_tstamp_cycles;
6222 tsync_txctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
6223 if ((tsync_txctl & IXGBE_TSYNCTXCTL_VALID) == 0)
6226 tx_tstamp_cycles = ixgbe_read_tx_tstamp_cyclecounter(dev);
6227 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
6228 *timestamp = rte_ns_to_timespec(ns);
6234 ixgbe_get_reg_length(struct rte_eth_dev *dev)
6236 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6239 const struct reg_info *reg_group;
6240 const struct reg_info **reg_set = (hw->mac.type == ixgbe_mac_82598EB) ?
6241 ixgbe_regs_mac_82598EB : ixgbe_regs_others;
6243 while ((reg_group = reg_set[g_ind++]))
6244 count += ixgbe_regs_group_count(reg_group);
6250 ixgbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
6254 const struct reg_info *reg_group;
6256 while ((reg_group = ixgbevf_regs[g_ind++]))
6257 count += ixgbe_regs_group_count(reg_group);
6263 ixgbe_get_regs(struct rte_eth_dev *dev,
6264 struct rte_dev_reg_info *regs)
6266 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6267 uint32_t *data = regs->data;
6270 const struct reg_info *reg_group;
6271 const struct reg_info **reg_set = (hw->mac.type == ixgbe_mac_82598EB) ?
6272 ixgbe_regs_mac_82598EB : ixgbe_regs_others;
6274 /* Support only full register dump */
6275 if ((regs->length == 0) ||
6276 (regs->length == (uint32_t)ixgbe_get_reg_length(dev))) {
6277 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
6279 while ((reg_group = reg_set[g_ind++]))
6280 count += ixgbe_read_regs_group(dev, &data[count],
6289 ixgbevf_get_regs(struct rte_eth_dev *dev,
6290 struct rte_dev_reg_info *regs)
6292 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6293 uint32_t *data = regs->data;
6296 const struct reg_info *reg_group;
6298 /* Support only full register dump */
6299 if ((regs->length == 0) ||
6300 (regs->length == (uint32_t)ixgbevf_get_reg_length(dev))) {
6301 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
6303 while ((reg_group = ixgbevf_regs[g_ind++]))
6304 count += ixgbe_read_regs_group(dev, &data[count],
6313 ixgbe_get_eeprom_length(struct rte_eth_dev *dev)
6315 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6317 /* Return unit is byte count */
6318 return hw->eeprom.word_size * 2;
6322 ixgbe_get_eeprom(struct rte_eth_dev *dev,
6323 struct rte_dev_eeprom_info *in_eeprom)
6325 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6326 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
6327 uint16_t *data = in_eeprom->data;
6330 first = in_eeprom->offset >> 1;
6331 length = in_eeprom->length >> 1;
6332 if ((first > hw->eeprom.word_size) ||
6333 ((first + length) > hw->eeprom.word_size))
6336 in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
6338 return eeprom->ops.read_buffer(hw, first, length, data);
6342 ixgbe_set_eeprom(struct rte_eth_dev *dev,
6343 struct rte_dev_eeprom_info *in_eeprom)
6345 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6346 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
6347 uint16_t *data = in_eeprom->data;
6350 first = in_eeprom->offset >> 1;
6351 length = in_eeprom->length >> 1;
6352 if ((first > hw->eeprom.word_size) ||
6353 ((first + length) > hw->eeprom.word_size))
6356 in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
6358 return eeprom->ops.write_buffer(hw, first, length, data);
6362 ixgbe_reta_size_get(enum ixgbe_mac_type mac_type) {
6364 case ixgbe_mac_X550:
6365 case ixgbe_mac_X550EM_x:
6366 case ixgbe_mac_X550EM_a:
6367 return ETH_RSS_RETA_SIZE_512;
6368 case ixgbe_mac_X550_vf:
6369 case ixgbe_mac_X550EM_x_vf:
6370 case ixgbe_mac_X550EM_a_vf:
6371 return ETH_RSS_RETA_SIZE_64;
6373 return ETH_RSS_RETA_SIZE_128;
6378 ixgbe_reta_reg_get(enum ixgbe_mac_type mac_type, uint16_t reta_idx) {
6380 case ixgbe_mac_X550:
6381 case ixgbe_mac_X550EM_x:
6382 case ixgbe_mac_X550EM_a:
6383 if (reta_idx < ETH_RSS_RETA_SIZE_128)
6384 return IXGBE_RETA(reta_idx >> 2);
6386 return IXGBE_ERETA((reta_idx - ETH_RSS_RETA_SIZE_128) >> 2);
6387 case ixgbe_mac_X550_vf:
6388 case ixgbe_mac_X550EM_x_vf:
6389 case ixgbe_mac_X550EM_a_vf:
6390 return IXGBE_VFRETA(reta_idx >> 2);
6392 return IXGBE_RETA(reta_idx >> 2);
6397 ixgbe_mrqc_reg_get(enum ixgbe_mac_type mac_type) {
6399 case ixgbe_mac_X550_vf:
6400 case ixgbe_mac_X550EM_x_vf:
6401 case ixgbe_mac_X550EM_a_vf:
6402 return IXGBE_VFMRQC;
6409 ixgbe_rssrk_reg_get(enum ixgbe_mac_type mac_type, uint8_t i) {
6411 case ixgbe_mac_X550_vf:
6412 case ixgbe_mac_X550EM_x_vf:
6413 case ixgbe_mac_X550EM_a_vf:
6414 return IXGBE_VFRSSRK(i);
6416 return IXGBE_RSSRK(i);
6421 ixgbe_rss_update_sp(enum ixgbe_mac_type mac_type) {
6423 case ixgbe_mac_82599_vf:
6424 case ixgbe_mac_X540_vf:
6432 ixgbe_dev_get_dcb_info(struct rte_eth_dev *dev,
6433 struct rte_eth_dcb_info *dcb_info)
6435 struct ixgbe_dcb_config *dcb_config =
6436 IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
6437 struct ixgbe_dcb_tc_config *tc;
6440 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
6441 dcb_info->nb_tcs = dcb_config->num_tcs.pg_tcs;
6443 dcb_info->nb_tcs = 1;
6445 if (dcb_config->vt_mode) { /* vt is enabled*/
6446 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
6447 &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
6448 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++)
6449 dcb_info->prio_tc[i] = vmdq_rx_conf->dcb_tc[i];
6450 for (i = 0; i < vmdq_rx_conf->nb_queue_pools; i++) {
6451 for (j = 0; j < dcb_info->nb_tcs; j++) {
6452 dcb_info->tc_queue.tc_rxq[i][j].base =
6453 i * dcb_info->nb_tcs + j;
6454 dcb_info->tc_queue.tc_rxq[i][j].nb_queue = 1;
6455 dcb_info->tc_queue.tc_txq[i][j].base =
6456 i * dcb_info->nb_tcs + j;
6457 dcb_info->tc_queue.tc_txq[i][j].nb_queue = 1;
6460 } else { /* vt is disabled*/
6461 struct rte_eth_dcb_rx_conf *rx_conf =
6462 &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
6463 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++)
6464 dcb_info->prio_tc[i] = rx_conf->dcb_tc[i];
6465 if (dcb_info->nb_tcs == ETH_4_TCS) {
6466 for (i = 0; i < dcb_info->nb_tcs; i++) {
6467 dcb_info->tc_queue.tc_rxq[0][i].base = i * 32;
6468 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 16;
6470 dcb_info->tc_queue.tc_txq[0][0].base = 0;
6471 dcb_info->tc_queue.tc_txq[0][1].base = 64;
6472 dcb_info->tc_queue.tc_txq[0][2].base = 96;
6473 dcb_info->tc_queue.tc_txq[0][3].base = 112;
6474 dcb_info->tc_queue.tc_txq[0][0].nb_queue = 64;
6475 dcb_info->tc_queue.tc_txq[0][1].nb_queue = 32;
6476 dcb_info->tc_queue.tc_txq[0][2].nb_queue = 16;
6477 dcb_info->tc_queue.tc_txq[0][3].nb_queue = 16;
6478 } else if (dcb_info->nb_tcs == ETH_8_TCS) {
6479 for (i = 0; i < dcb_info->nb_tcs; i++) {
6480 dcb_info->tc_queue.tc_rxq[0][i].base = i * 16;
6481 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 16;
6483 dcb_info->tc_queue.tc_txq[0][0].base = 0;
6484 dcb_info->tc_queue.tc_txq[0][1].base = 32;
6485 dcb_info->tc_queue.tc_txq[0][2].base = 64;
6486 dcb_info->tc_queue.tc_txq[0][3].base = 80;
6487 dcb_info->tc_queue.tc_txq[0][4].base = 96;
6488 dcb_info->tc_queue.tc_txq[0][5].base = 104;
6489 dcb_info->tc_queue.tc_txq[0][6].base = 112;
6490 dcb_info->tc_queue.tc_txq[0][7].base = 120;
6491 dcb_info->tc_queue.tc_txq[0][0].nb_queue = 32;
6492 dcb_info->tc_queue.tc_txq[0][1].nb_queue = 32;
6493 dcb_info->tc_queue.tc_txq[0][2].nb_queue = 16;
6494 dcb_info->tc_queue.tc_txq[0][3].nb_queue = 16;
6495 dcb_info->tc_queue.tc_txq[0][4].nb_queue = 8;
6496 dcb_info->tc_queue.tc_txq[0][5].nb_queue = 8;
6497 dcb_info->tc_queue.tc_txq[0][6].nb_queue = 8;
6498 dcb_info->tc_queue.tc_txq[0][7].nb_queue = 8;
6501 for (i = 0; i < dcb_info->nb_tcs; i++) {
6502 tc = &dcb_config->tc_config[i];
6503 dcb_info->tc_bws[i] = tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent;
6508 /* Update e-tag ether type */
6510 ixgbe_update_e_tag_eth_type(struct ixgbe_hw *hw,
6511 uint16_t ether_type)
6513 uint32_t etag_etype;
6515 if (hw->mac.type != ixgbe_mac_X550 &&
6516 hw->mac.type != ixgbe_mac_X550EM_x &&
6517 hw->mac.type != ixgbe_mac_X550EM_a) {
6521 etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
6522 etag_etype &= ~IXGBE_ETAG_ETYPE_MASK;
6523 etag_etype |= ether_type;
6524 IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
6525 IXGBE_WRITE_FLUSH(hw);
6530 /* Config l2 tunnel ether type */
6532 ixgbe_dev_l2_tunnel_eth_type_conf(struct rte_eth_dev *dev,
6533 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6536 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6538 if (l2_tunnel == NULL)
6541 switch (l2_tunnel->l2_tunnel_type) {
6542 case RTE_L2_TUNNEL_TYPE_E_TAG:
6543 ret = ixgbe_update_e_tag_eth_type(hw, l2_tunnel->ether_type);
6546 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6554 /* Enable e-tag tunnel */
6556 ixgbe_e_tag_enable(struct ixgbe_hw *hw)
6558 uint32_t etag_etype;
6560 if (hw->mac.type != ixgbe_mac_X550 &&
6561 hw->mac.type != ixgbe_mac_X550EM_x &&
6562 hw->mac.type != ixgbe_mac_X550EM_a) {
6566 etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
6567 etag_etype |= IXGBE_ETAG_ETYPE_VALID;
6568 IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
6569 IXGBE_WRITE_FLUSH(hw);
6574 /* Enable l2 tunnel */
6576 ixgbe_dev_l2_tunnel_enable(struct rte_eth_dev *dev,
6577 enum rte_eth_tunnel_type l2_tunnel_type)
6580 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6582 switch (l2_tunnel_type) {
6583 case RTE_L2_TUNNEL_TYPE_E_TAG:
6584 ret = ixgbe_e_tag_enable(hw);
6587 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6595 /* Disable e-tag tunnel */
6597 ixgbe_e_tag_disable(struct ixgbe_hw *hw)
6599 uint32_t etag_etype;
6601 if (hw->mac.type != ixgbe_mac_X550 &&
6602 hw->mac.type != ixgbe_mac_X550EM_x &&
6603 hw->mac.type != ixgbe_mac_X550EM_a) {
6607 etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
6608 etag_etype &= ~IXGBE_ETAG_ETYPE_VALID;
6609 IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
6610 IXGBE_WRITE_FLUSH(hw);
6615 /* Disable l2 tunnel */
6617 ixgbe_dev_l2_tunnel_disable(struct rte_eth_dev *dev,
6618 enum rte_eth_tunnel_type l2_tunnel_type)
6621 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6623 switch (l2_tunnel_type) {
6624 case RTE_L2_TUNNEL_TYPE_E_TAG:
6625 ret = ixgbe_e_tag_disable(hw);
6628 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6637 ixgbe_e_tag_filter_del(struct rte_eth_dev *dev,
6638 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6641 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6642 uint32_t i, rar_entries;
6643 uint32_t rar_low, rar_high;
6645 if (hw->mac.type != ixgbe_mac_X550 &&
6646 hw->mac.type != ixgbe_mac_X550EM_x &&
6647 hw->mac.type != ixgbe_mac_X550EM_a) {
6651 rar_entries = ixgbe_get_num_rx_addrs(hw);
6653 for (i = 1; i < rar_entries; i++) {
6654 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(i));
6655 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(i));
6656 if ((rar_high & IXGBE_RAH_AV) &&
6657 (rar_high & IXGBE_RAH_ADTYPE) &&
6658 ((rar_low & IXGBE_RAL_ETAG_FILTER_MASK) ==
6659 l2_tunnel->tunnel_id)) {
6660 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
6661 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
6663 ixgbe_clear_vmdq(hw, i, IXGBE_CLEAR_VMDQ_ALL);
6673 ixgbe_e_tag_filter_add(struct rte_eth_dev *dev,
6674 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6677 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6678 uint32_t i, rar_entries;
6679 uint32_t rar_low, rar_high;
6681 if (hw->mac.type != ixgbe_mac_X550 &&
6682 hw->mac.type != ixgbe_mac_X550EM_x &&
6683 hw->mac.type != ixgbe_mac_X550EM_a) {
6687 /* One entry for one tunnel. Try to remove potential existing entry. */
6688 ixgbe_e_tag_filter_del(dev, l2_tunnel);
6690 rar_entries = ixgbe_get_num_rx_addrs(hw);
6692 for (i = 1; i < rar_entries; i++) {
6693 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(i));
6694 if (rar_high & IXGBE_RAH_AV) {
6697 ixgbe_set_vmdq(hw, i, l2_tunnel->pool);
6698 rar_high = IXGBE_RAH_AV | IXGBE_RAH_ADTYPE;
6699 rar_low = l2_tunnel->tunnel_id;
6701 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), rar_low);
6702 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), rar_high);
6708 PMD_INIT_LOG(NOTICE, "The table of E-tag forwarding rule is full."
6709 " Please remove a rule before adding a new one.");
6713 /* Add l2 tunnel filter */
6715 ixgbe_dev_l2_tunnel_filter_add(struct rte_eth_dev *dev,
6716 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6720 switch (l2_tunnel->l2_tunnel_type) {
6721 case RTE_L2_TUNNEL_TYPE_E_TAG:
6722 ret = ixgbe_e_tag_filter_add(dev, l2_tunnel);
6725 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6733 /* Delete l2 tunnel filter */
6735 ixgbe_dev_l2_tunnel_filter_del(struct rte_eth_dev *dev,
6736 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6740 switch (l2_tunnel->l2_tunnel_type) {
6741 case RTE_L2_TUNNEL_TYPE_E_TAG:
6742 ret = ixgbe_e_tag_filter_del(dev, l2_tunnel);
6745 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6754 * ixgbe_dev_l2_tunnel_filter_handle - Handle operations for l2 tunnel filter.
6755 * @dev: pointer to rte_eth_dev structure
6756 * @filter_op:operation will be taken.
6757 * @arg: a pointer to specific structure corresponding to the filter_op
6760 ixgbe_dev_l2_tunnel_filter_handle(struct rte_eth_dev *dev,
6761 enum rte_filter_op filter_op,
6766 if (filter_op == RTE_ETH_FILTER_NOP)
6770 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
6775 switch (filter_op) {
6776 case RTE_ETH_FILTER_ADD:
6777 ret = ixgbe_dev_l2_tunnel_filter_add
6779 (struct rte_eth_l2_tunnel_conf *)arg);
6781 case RTE_ETH_FILTER_DELETE:
6782 ret = ixgbe_dev_l2_tunnel_filter_del
6784 (struct rte_eth_l2_tunnel_conf *)arg);
6787 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
6795 ixgbe_e_tag_forwarding_en_dis(struct rte_eth_dev *dev, bool en)
6799 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6801 if (hw->mac.type != ixgbe_mac_X550 &&
6802 hw->mac.type != ixgbe_mac_X550EM_x &&
6803 hw->mac.type != ixgbe_mac_X550EM_a) {
6807 ctrl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
6808 ctrl &= ~IXGBE_VT_CTL_POOLING_MODE_MASK;
6810 ctrl |= IXGBE_VT_CTL_POOLING_MODE_ETAG;
6811 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, ctrl);
6816 /* Enable l2 tunnel forwarding */
6818 ixgbe_dev_l2_tunnel_forwarding_enable
6819 (struct rte_eth_dev *dev,
6820 enum rte_eth_tunnel_type l2_tunnel_type)
6824 switch (l2_tunnel_type) {
6825 case RTE_L2_TUNNEL_TYPE_E_TAG:
6826 ret = ixgbe_e_tag_forwarding_en_dis(dev, 1);
6829 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6837 /* Disable l2 tunnel forwarding */
6839 ixgbe_dev_l2_tunnel_forwarding_disable
6840 (struct rte_eth_dev *dev,
6841 enum rte_eth_tunnel_type l2_tunnel_type)
6845 switch (l2_tunnel_type) {
6846 case RTE_L2_TUNNEL_TYPE_E_TAG:
6847 ret = ixgbe_e_tag_forwarding_en_dis(dev, 0);
6850 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6859 ixgbe_e_tag_insertion_en_dis(struct rte_eth_dev *dev,
6860 struct rte_eth_l2_tunnel_conf *l2_tunnel,
6864 uint32_t vmtir, vmvir;
6865 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6867 if (l2_tunnel->vf_id >= dev->pci_dev->max_vfs) {
6869 "VF id %u should be less than %u",
6871 dev->pci_dev->max_vfs);
6875 if (hw->mac.type != ixgbe_mac_X550 &&
6876 hw->mac.type != ixgbe_mac_X550EM_x &&
6877 hw->mac.type != ixgbe_mac_X550EM_a) {
6882 vmtir = l2_tunnel->tunnel_id;
6886 IXGBE_WRITE_REG(hw, IXGBE_VMTIR(l2_tunnel->vf_id), vmtir);
6888 vmvir = IXGBE_READ_REG(hw, IXGBE_VMVIR(l2_tunnel->vf_id));
6889 vmvir &= ~IXGBE_VMVIR_TAGA_MASK;
6891 vmvir |= IXGBE_VMVIR_TAGA_ETAG_INSERT;
6892 IXGBE_WRITE_REG(hw, IXGBE_VMVIR(l2_tunnel->vf_id), vmvir);
6897 /* Enable l2 tunnel tag insertion */
6899 ixgbe_dev_l2_tunnel_insertion_enable(struct rte_eth_dev *dev,
6900 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6904 switch (l2_tunnel->l2_tunnel_type) {
6905 case RTE_L2_TUNNEL_TYPE_E_TAG:
6906 ret = ixgbe_e_tag_insertion_en_dis(dev, l2_tunnel, 1);
6909 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6917 /* Disable l2 tunnel tag insertion */
6919 ixgbe_dev_l2_tunnel_insertion_disable
6920 (struct rte_eth_dev *dev,
6921 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6925 switch (l2_tunnel->l2_tunnel_type) {
6926 case RTE_L2_TUNNEL_TYPE_E_TAG:
6927 ret = ixgbe_e_tag_insertion_en_dis(dev, l2_tunnel, 0);
6930 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6939 ixgbe_e_tag_stripping_en_dis(struct rte_eth_dev *dev,
6944 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6946 if (hw->mac.type != ixgbe_mac_X550 &&
6947 hw->mac.type != ixgbe_mac_X550EM_x &&
6948 hw->mac.type != ixgbe_mac_X550EM_a) {
6952 qde = IXGBE_READ_REG(hw, IXGBE_QDE);
6954 qde |= IXGBE_QDE_STRIP_TAG;
6956 qde &= ~IXGBE_QDE_STRIP_TAG;
6957 qde &= ~IXGBE_QDE_READ;
6958 qde |= IXGBE_QDE_WRITE;
6959 IXGBE_WRITE_REG(hw, IXGBE_QDE, qde);
6964 /* Enable l2 tunnel tag stripping */
6966 ixgbe_dev_l2_tunnel_stripping_enable
6967 (struct rte_eth_dev *dev,
6968 enum rte_eth_tunnel_type l2_tunnel_type)
6972 switch (l2_tunnel_type) {
6973 case RTE_L2_TUNNEL_TYPE_E_TAG:
6974 ret = ixgbe_e_tag_stripping_en_dis(dev, 1);
6977 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6985 /* Disable l2 tunnel tag stripping */
6987 ixgbe_dev_l2_tunnel_stripping_disable
6988 (struct rte_eth_dev *dev,
6989 enum rte_eth_tunnel_type l2_tunnel_type)
6993 switch (l2_tunnel_type) {
6994 case RTE_L2_TUNNEL_TYPE_E_TAG:
6995 ret = ixgbe_e_tag_stripping_en_dis(dev, 0);
6998 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7006 /* Enable/disable l2 tunnel offload functions */
7008 ixgbe_dev_l2_tunnel_offload_set
7009 (struct rte_eth_dev *dev,
7010 struct rte_eth_l2_tunnel_conf *l2_tunnel,
7016 if (l2_tunnel == NULL)
7020 if (mask & ETH_L2_TUNNEL_ENABLE_MASK) {
7022 ret = ixgbe_dev_l2_tunnel_enable(
7024 l2_tunnel->l2_tunnel_type);
7026 ret = ixgbe_dev_l2_tunnel_disable(
7028 l2_tunnel->l2_tunnel_type);
7031 if (mask & ETH_L2_TUNNEL_INSERTION_MASK) {
7033 ret = ixgbe_dev_l2_tunnel_insertion_enable(
7037 ret = ixgbe_dev_l2_tunnel_insertion_disable(
7042 if (mask & ETH_L2_TUNNEL_STRIPPING_MASK) {
7044 ret = ixgbe_dev_l2_tunnel_stripping_enable(
7046 l2_tunnel->l2_tunnel_type);
7048 ret = ixgbe_dev_l2_tunnel_stripping_disable(
7050 l2_tunnel->l2_tunnel_type);
7053 if (mask & ETH_L2_TUNNEL_FORWARDING_MASK) {
7055 ret = ixgbe_dev_l2_tunnel_forwarding_enable(
7057 l2_tunnel->l2_tunnel_type);
7059 ret = ixgbe_dev_l2_tunnel_forwarding_disable(
7061 l2_tunnel->l2_tunnel_type);
7068 ixgbe_update_vxlan_port(struct ixgbe_hw *hw,
7071 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, port);
7072 IXGBE_WRITE_FLUSH(hw);
7077 /* There's only one register for VxLAN UDP port.
7078 * So, we cannot add several ports. Will update it.
7081 ixgbe_add_vxlan_port(struct ixgbe_hw *hw,
7085 PMD_DRV_LOG(ERR, "Add VxLAN port 0 is not allowed.");
7089 return ixgbe_update_vxlan_port(hw, port);
7092 /* We cannot delete the VxLAN port. For there's a register for VxLAN
7093 * UDP port, it must have a value.
7094 * So, will reset it to the original value 0.
7097 ixgbe_del_vxlan_port(struct ixgbe_hw *hw,
7102 cur_port = (uint16_t)IXGBE_READ_REG(hw, IXGBE_VXLANCTRL);
7104 if (cur_port != port) {
7105 PMD_DRV_LOG(ERR, "Port %u does not exist.", port);
7109 return ixgbe_update_vxlan_port(hw, 0);
7112 /* Add UDP tunneling port */
7114 ixgbe_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
7115 struct rte_eth_udp_tunnel *udp_tunnel)
7118 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7120 if (hw->mac.type != ixgbe_mac_X550 &&
7121 hw->mac.type != ixgbe_mac_X550EM_x &&
7122 hw->mac.type != ixgbe_mac_X550EM_a) {
7126 if (udp_tunnel == NULL)
7129 switch (udp_tunnel->prot_type) {
7130 case RTE_TUNNEL_TYPE_VXLAN:
7131 ret = ixgbe_add_vxlan_port(hw, udp_tunnel->udp_port);
7134 case RTE_TUNNEL_TYPE_GENEVE:
7135 case RTE_TUNNEL_TYPE_TEREDO:
7136 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
7141 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7149 /* Remove UDP tunneling port */
7151 ixgbe_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
7152 struct rte_eth_udp_tunnel *udp_tunnel)
7155 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7157 if (hw->mac.type != ixgbe_mac_X550 &&
7158 hw->mac.type != ixgbe_mac_X550EM_x &&
7159 hw->mac.type != ixgbe_mac_X550EM_a) {
7163 if (udp_tunnel == NULL)
7166 switch (udp_tunnel->prot_type) {
7167 case RTE_TUNNEL_TYPE_VXLAN:
7168 ret = ixgbe_del_vxlan_port(hw, udp_tunnel->udp_port);
7170 case RTE_TUNNEL_TYPE_GENEVE:
7171 case RTE_TUNNEL_TYPE_TEREDO:
7172 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
7176 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7184 /* ixgbevf_update_xcast_mode - Update Multicast mode
7185 * @hw: pointer to the HW structure
7186 * @netdev: pointer to net device structure
7187 * @xcast_mode: new multicast mode
7189 * Updates the Multicast Mode of VF.
7191 static int ixgbevf_update_xcast_mode(struct ixgbe_hw *hw,
7194 struct ixgbe_mbx_info *mbx = &hw->mbx;
7198 switch (hw->api_version) {
7199 case ixgbe_mbox_api_12:
7205 msgbuf[0] = IXGBE_VF_UPDATE_XCAST_MODE;
7206 msgbuf[1] = xcast_mode;
7208 err = mbx->ops.write_posted(hw, msgbuf, 2, 0);
7212 err = mbx->ops.read_posted(hw, msgbuf, 2, 0);
7216 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
7217 if (msgbuf[0] == (IXGBE_VF_UPDATE_XCAST_MODE | IXGBE_VT_MSGTYPE_NACK))
7224 ixgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
7226 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7228 ixgbevf_update_xcast_mode(hw, IXGBEVF_XCAST_MODE_ALLMULTI);
7232 ixgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
7234 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7236 ixgbevf_update_xcast_mode(hw, IXGBEVF_XCAST_MODE_NONE);
7239 static struct rte_driver rte_ixgbe_driver = {
7241 .init = rte_ixgbe_pmd_init,
7244 static struct rte_driver rte_ixgbevf_driver = {
7246 .init = rte_ixgbevf_pmd_init,
7249 PMD_REGISTER_DRIVER(rte_ixgbe_driver);
7250 PMD_REGISTER_DRIVER(rte_ixgbevf_driver);