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_xstat *xstats, unsigned n);
178 static int ixgbevf_dev_xstats_get(struct rte_eth_dev *dev,
179 struct rte_eth_xstat *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_xstat *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].value = *(uint64_t *)(((char *)hw_stats) +
2823 rte_ixgbe_stats_strings[i].offset);
2827 /* RX Priority Stats */
2828 for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
2829 for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
2830 xstats[count].id = count;
2831 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
2832 rte_ixgbe_rxq_strings[stat].offset +
2833 (sizeof(uint64_t) * i));
2838 /* TX Priority Stats */
2839 for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
2840 for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
2841 xstats[count].id = count;
2842 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
2843 rte_ixgbe_txq_strings[stat].offset +
2844 (sizeof(uint64_t) * i));
2852 ixgbe_dev_xstats_reset(struct rte_eth_dev *dev)
2854 struct ixgbe_hw_stats *stats =
2855 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2857 unsigned count = ixgbe_xstats_calc_num();
2859 /* HW registers are cleared on read */
2860 ixgbe_dev_xstats_get(dev, NULL, count);
2862 /* Reset software totals */
2863 memset(stats, 0, sizeof(*stats));
2867 ixgbevf_update_stats(struct rte_eth_dev *dev)
2869 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2870 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
2871 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2873 /* Good Rx packet, include VF loopback */
2874 UPDATE_VF_STAT(IXGBE_VFGPRC,
2875 hw_stats->last_vfgprc, hw_stats->vfgprc);
2877 /* Good Rx octets, include VF loopback */
2878 UPDATE_VF_STAT_36BIT(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
2879 hw_stats->last_vfgorc, hw_stats->vfgorc);
2881 /* Good Tx packet, include VF loopback */
2882 UPDATE_VF_STAT(IXGBE_VFGPTC,
2883 hw_stats->last_vfgptc, hw_stats->vfgptc);
2885 /* Good Tx octets, include VF loopback */
2886 UPDATE_VF_STAT_36BIT(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
2887 hw_stats->last_vfgotc, hw_stats->vfgotc);
2889 /* Rx Multicst Packet */
2890 UPDATE_VF_STAT(IXGBE_VFMPRC,
2891 hw_stats->last_vfmprc, hw_stats->vfmprc);
2895 ixgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2898 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
2899 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2902 if (n < IXGBEVF_NB_XSTATS)
2903 return IXGBEVF_NB_XSTATS;
2905 ixgbevf_update_stats(dev);
2910 /* Extended stats */
2911 for (i = 0; i < IXGBEVF_NB_XSTATS; i++) {
2913 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
2914 rte_ixgbevf_stats_strings[i].offset);
2917 return IXGBEVF_NB_XSTATS;
2921 ixgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2923 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
2924 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2926 ixgbevf_update_stats(dev);
2931 stats->ipackets = hw_stats->vfgprc;
2932 stats->ibytes = hw_stats->vfgorc;
2933 stats->opackets = hw_stats->vfgptc;
2934 stats->obytes = hw_stats->vfgotc;
2938 ixgbevf_dev_stats_reset(struct rte_eth_dev *dev)
2940 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
2941 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2943 /* Sync HW register to the last stats */
2944 ixgbevf_dev_stats_get(dev, NULL);
2946 /* reset HW current stats*/
2947 hw_stats->vfgprc = 0;
2948 hw_stats->vfgorc = 0;
2949 hw_stats->vfgptc = 0;
2950 hw_stats->vfgotc = 0;
2954 ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2956 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2957 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
2959 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
2960 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
2961 if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
2963 * When DCB/VT is off, maximum number of queues changes,
2964 * except for 82598EB, which remains constant.
2966 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_NONE &&
2967 hw->mac.type != ixgbe_mac_82598EB)
2968 dev_info->max_tx_queues = IXGBE_NONE_MODE_TX_NB_QUEUES;
2970 dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL register */
2971 dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS register */
2972 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
2973 dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
2974 dev_info->max_vfs = dev->pci_dev->max_vfs;
2975 if (hw->mac.type == ixgbe_mac_82598EB)
2976 dev_info->max_vmdq_pools = ETH_16_POOLS;
2978 dev_info->max_vmdq_pools = ETH_64_POOLS;
2979 dev_info->vmdq_queue_num = dev_info->max_rx_queues;
2980 dev_info->rx_offload_capa =
2981 DEV_RX_OFFLOAD_VLAN_STRIP |
2982 DEV_RX_OFFLOAD_IPV4_CKSUM |
2983 DEV_RX_OFFLOAD_UDP_CKSUM |
2984 DEV_RX_OFFLOAD_TCP_CKSUM;
2987 * RSC is only supported by 82599 and x540 PF devices in a non-SR-IOV
2990 if ((hw->mac.type == ixgbe_mac_82599EB ||
2991 hw->mac.type == ixgbe_mac_X540) &&
2992 !RTE_ETH_DEV_SRIOV(dev).active)
2993 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TCP_LRO;
2995 if (hw->mac.type == ixgbe_mac_X550 ||
2996 hw->mac.type == ixgbe_mac_X550EM_x ||
2997 hw->mac.type == ixgbe_mac_X550EM_a)
2998 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
3000 dev_info->tx_offload_capa =
3001 DEV_TX_OFFLOAD_VLAN_INSERT |
3002 DEV_TX_OFFLOAD_IPV4_CKSUM |
3003 DEV_TX_OFFLOAD_UDP_CKSUM |
3004 DEV_TX_OFFLOAD_TCP_CKSUM |
3005 DEV_TX_OFFLOAD_SCTP_CKSUM |
3006 DEV_TX_OFFLOAD_TCP_TSO;
3008 if (hw->mac.type == ixgbe_mac_X550 ||
3009 hw->mac.type == ixgbe_mac_X550EM_x ||
3010 hw->mac.type == ixgbe_mac_X550EM_a)
3011 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
3013 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3015 .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
3016 .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
3017 .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
3019 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
3023 dev_info->default_txconf = (struct rte_eth_txconf) {
3025 .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
3026 .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
3027 .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
3029 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
3030 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
3031 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
3032 ETH_TXQ_FLAGS_NOOFFLOADS,
3035 dev_info->rx_desc_lim = rx_desc_lim;
3036 dev_info->tx_desc_lim = tx_desc_lim;
3038 dev_info->hash_key_size = IXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
3039 dev_info->reta_size = ixgbe_reta_size_get(hw->mac.type);
3040 dev_info->flow_type_rss_offloads = IXGBE_RSS_OFFLOAD_ALL;
3042 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
3043 if (hw->mac.type == ixgbe_mac_X540 ||
3044 hw->mac.type == ixgbe_mac_X540_vf ||
3045 hw->mac.type == ixgbe_mac_X550 ||
3046 hw->mac.type == ixgbe_mac_X550_vf) {
3047 dev_info->speed_capa |= ETH_LINK_SPEED_100M;
3051 static const uint32_t *
3052 ixgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev)
3054 static const uint32_t ptypes[] = {
3055 /* For non-vec functions,
3056 * refers to ixgbe_rxd_pkt_info_to_pkt_type();
3057 * for vec functions,
3058 * refers to _recv_raw_pkts_vec().
3062 RTE_PTYPE_L3_IPV4_EXT,
3064 RTE_PTYPE_L3_IPV6_EXT,
3068 RTE_PTYPE_TUNNEL_IP,
3069 RTE_PTYPE_INNER_L3_IPV6,
3070 RTE_PTYPE_INNER_L3_IPV6_EXT,
3071 RTE_PTYPE_INNER_L4_TCP,
3072 RTE_PTYPE_INNER_L4_UDP,
3076 if (dev->rx_pkt_burst == ixgbe_recv_pkts ||
3077 dev->rx_pkt_burst == ixgbe_recv_pkts_lro_single_alloc ||
3078 dev->rx_pkt_burst == ixgbe_recv_pkts_lro_bulk_alloc ||
3079 dev->rx_pkt_burst == ixgbe_recv_pkts_bulk_alloc)
3085 ixgbevf_dev_info_get(struct rte_eth_dev *dev,
3086 struct rte_eth_dev_info *dev_info)
3088 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3090 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
3091 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
3092 dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL reg */
3093 dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS reg */
3094 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
3095 dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
3096 dev_info->max_vfs = dev->pci_dev->max_vfs;
3097 if (hw->mac.type == ixgbe_mac_82598EB)
3098 dev_info->max_vmdq_pools = ETH_16_POOLS;
3100 dev_info->max_vmdq_pools = ETH_64_POOLS;
3101 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
3102 DEV_RX_OFFLOAD_IPV4_CKSUM |
3103 DEV_RX_OFFLOAD_UDP_CKSUM |
3104 DEV_RX_OFFLOAD_TCP_CKSUM;
3105 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
3106 DEV_TX_OFFLOAD_IPV4_CKSUM |
3107 DEV_TX_OFFLOAD_UDP_CKSUM |
3108 DEV_TX_OFFLOAD_TCP_CKSUM |
3109 DEV_TX_OFFLOAD_SCTP_CKSUM |
3110 DEV_TX_OFFLOAD_TCP_TSO;
3112 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3114 .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
3115 .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
3116 .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
3118 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
3122 dev_info->default_txconf = (struct rte_eth_txconf) {
3124 .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
3125 .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
3126 .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
3128 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
3129 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
3130 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
3131 ETH_TXQ_FLAGS_NOOFFLOADS,
3134 dev_info->rx_desc_lim = rx_desc_lim;
3135 dev_info->tx_desc_lim = tx_desc_lim;
3138 /* return 0 means link status changed, -1 means not changed */
3140 ixgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
3142 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3143 struct rte_eth_link link, old;
3144 ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
3148 link.link_status = ETH_LINK_DOWN;
3149 link.link_speed = 0;
3150 link.link_duplex = ETH_LINK_HALF_DUPLEX;
3151 memset(&old, 0, sizeof(old));
3152 rte_ixgbe_dev_atomic_read_link_status(dev, &old);
3154 hw->mac.get_link_status = true;
3156 /* check if it needs to wait to complete, if lsc interrupt is enabled */
3157 if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
3158 diag = ixgbe_check_link(hw, &link_speed, &link_up, 0);
3160 diag = ixgbe_check_link(hw, &link_speed, &link_up, 1);
3163 link.link_speed = ETH_SPEED_NUM_100M;
3164 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3165 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
3166 if (link.link_status == old.link_status)
3172 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
3173 if (link.link_status == old.link_status)
3177 link.link_status = ETH_LINK_UP;
3178 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3180 switch (link_speed) {
3182 case IXGBE_LINK_SPEED_UNKNOWN:
3183 link.link_duplex = ETH_LINK_FULL_DUPLEX;
3184 link.link_speed = ETH_SPEED_NUM_100M;
3187 case IXGBE_LINK_SPEED_100_FULL:
3188 link.link_speed = ETH_SPEED_NUM_100M;
3191 case IXGBE_LINK_SPEED_1GB_FULL:
3192 link.link_speed = ETH_SPEED_NUM_1G;
3195 case IXGBE_LINK_SPEED_10GB_FULL:
3196 link.link_speed = ETH_SPEED_NUM_10G;
3199 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
3201 if (link.link_status == old.link_status)
3208 ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
3210 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3213 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3214 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3215 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3219 ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
3221 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3224 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3225 fctrl &= (~IXGBE_FCTRL_UPE);
3226 if (dev->data->all_multicast == 1)
3227 fctrl |= IXGBE_FCTRL_MPE;
3229 fctrl &= (~IXGBE_FCTRL_MPE);
3230 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3234 ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
3236 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3239 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3240 fctrl |= IXGBE_FCTRL_MPE;
3241 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3245 ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
3247 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3250 if (dev->data->promiscuous == 1)
3251 return; /* must remain in all_multicast mode */
3253 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3254 fctrl &= (~IXGBE_FCTRL_MPE);
3255 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3259 * It clears the interrupt causes and enables the interrupt.
3260 * It will be called once only during nic initialized.
3263 * Pointer to struct rte_eth_dev.
3266 * - On success, zero.
3267 * - On failure, a negative value.
3270 ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev)
3272 struct ixgbe_interrupt *intr =
3273 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3275 ixgbe_dev_link_status_print(dev);
3276 intr->mask |= IXGBE_EICR_LSC;
3282 * It clears the interrupt causes and enables the interrupt.
3283 * It will be called once only during nic initialized.
3286 * Pointer to struct rte_eth_dev.
3289 * - On success, zero.
3290 * - On failure, a negative value.
3293 ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
3295 struct ixgbe_interrupt *intr =
3296 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3298 intr->mask |= IXGBE_EICR_RTX_QUEUE;
3304 * It reads ICR and sets flag (IXGBE_EICR_LSC) for the link_update.
3307 * Pointer to struct rte_eth_dev.
3310 * - On success, zero.
3311 * - On failure, a negative value.
3314 ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
3317 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3318 struct ixgbe_interrupt *intr =
3319 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3321 /* clear all cause mask */
3322 ixgbe_disable_intr(hw);
3324 /* read-on-clear nic registers here */
3325 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
3326 PMD_DRV_LOG(DEBUG, "eicr %x", eicr);
3330 /* set flag for async link update */
3331 if (eicr & IXGBE_EICR_LSC)
3332 intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3334 if (eicr & IXGBE_EICR_MAILBOX)
3335 intr->flags |= IXGBE_FLAG_MAILBOX;
3337 if (hw->mac.type == ixgbe_mac_X550EM_x &&
3338 hw->phy.type == ixgbe_phy_x550em_ext_t &&
3339 (eicr & IXGBE_EICR_GPI_SDP0_X550EM_x))
3340 intr->flags |= IXGBE_FLAG_PHY_INTERRUPT;
3346 * It gets and then prints the link status.
3349 * Pointer to struct rte_eth_dev.
3352 * - On success, zero.
3353 * - On failure, a negative value.
3356 ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
3358 struct rte_eth_link link;
3360 memset(&link, 0, sizeof(link));
3361 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
3362 if (link.link_status) {
3363 PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
3364 (int)(dev->data->port_id),
3365 (unsigned)link.link_speed,
3366 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
3367 "full-duplex" : "half-duplex");
3369 PMD_INIT_LOG(INFO, " Port %d: Link Down",
3370 (int)(dev->data->port_id));
3372 PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
3373 dev->pci_dev->addr.domain,
3374 dev->pci_dev->addr.bus,
3375 dev->pci_dev->addr.devid,
3376 dev->pci_dev->addr.function);
3380 * It executes link_update after knowing an interrupt occurred.
3383 * Pointer to struct rte_eth_dev.
3386 * - On success, zero.
3387 * - On failure, a negative value.
3390 ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
3392 struct ixgbe_interrupt *intr =
3393 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3395 struct rte_eth_link link;
3396 int intr_enable_delay = false;
3397 struct ixgbe_hw *hw =
3398 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3400 PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
3402 if (intr->flags & IXGBE_FLAG_MAILBOX) {
3403 ixgbe_pf_mbx_process(dev);
3404 intr->flags &= ~IXGBE_FLAG_MAILBOX;
3407 if (intr->flags & IXGBE_FLAG_PHY_INTERRUPT) {
3408 ixgbe_handle_lasi(hw);
3409 intr->flags &= ~IXGBE_FLAG_PHY_INTERRUPT;
3412 if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3413 /* get the link status before link update, for predicting later */
3414 memset(&link, 0, sizeof(link));
3415 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
3417 ixgbe_dev_link_update(dev, 0);
3420 if (!link.link_status)
3421 /* handle it 1 sec later, wait it being stable */
3422 timeout = IXGBE_LINK_UP_CHECK_TIMEOUT;
3423 /* likely to down */
3425 /* handle it 4 sec later, wait it being stable */
3426 timeout = IXGBE_LINK_DOWN_CHECK_TIMEOUT;
3428 ixgbe_dev_link_status_print(dev);
3430 intr_enable_delay = true;
3433 if (intr_enable_delay) {
3434 if (rte_eal_alarm_set(timeout * 1000,
3435 ixgbe_dev_interrupt_delayed_handler, (void *)dev) < 0)
3436 PMD_DRV_LOG(ERR, "Error setting alarm");
3438 PMD_DRV_LOG(DEBUG, "enable intr immediately");
3439 ixgbe_enable_intr(dev);
3440 rte_intr_enable(&(dev->pci_dev->intr_handle));
3448 * Interrupt handler which shall be registered for alarm callback for delayed
3449 * handling specific interrupt to wait for the stable nic state. As the
3450 * NIC interrupt state is not stable for ixgbe after link is just down,
3451 * it needs to wait 4 seconds to get the stable status.
3454 * Pointer to interrupt handle.
3456 * The address of parameter (struct rte_eth_dev *) regsitered before.
3462 ixgbe_dev_interrupt_delayed_handler(void *param)
3464 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
3465 struct ixgbe_interrupt *intr =
3466 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3467 struct ixgbe_hw *hw =
3468 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3471 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
3472 if (eicr & IXGBE_EICR_MAILBOX)
3473 ixgbe_pf_mbx_process(dev);
3475 if (intr->flags & IXGBE_FLAG_PHY_INTERRUPT) {
3476 ixgbe_handle_lasi(hw);
3477 intr->flags &= ~IXGBE_FLAG_PHY_INTERRUPT;
3480 if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3481 ixgbe_dev_link_update(dev, 0);
3482 intr->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3483 ixgbe_dev_link_status_print(dev);
3484 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
3487 PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
3488 ixgbe_enable_intr(dev);
3489 rte_intr_enable(&(dev->pci_dev->intr_handle));
3493 * Interrupt handler triggered by NIC for handling
3494 * specific interrupt.
3497 * Pointer to interrupt handle.
3499 * The address of parameter (struct rte_eth_dev *) regsitered before.
3505 ixgbe_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
3508 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
3510 ixgbe_dev_interrupt_get_status(dev);
3511 ixgbe_dev_interrupt_action(dev);
3515 ixgbe_dev_led_on(struct rte_eth_dev *dev)
3517 struct ixgbe_hw *hw;
3519 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3520 return ixgbe_led_on(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP;
3524 ixgbe_dev_led_off(struct rte_eth_dev *dev)
3526 struct ixgbe_hw *hw;
3528 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3529 return ixgbe_led_off(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP;
3533 ixgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3535 struct ixgbe_hw *hw;
3541 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3543 fc_conf->pause_time = hw->fc.pause_time;
3544 fc_conf->high_water = hw->fc.high_water[0];
3545 fc_conf->low_water = hw->fc.low_water[0];
3546 fc_conf->send_xon = hw->fc.send_xon;
3547 fc_conf->autoneg = !hw->fc.disable_fc_autoneg;
3550 * Return rx_pause status according to actual setting of
3553 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
3554 if (mflcn_reg & (IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_RFCE))
3560 * Return tx_pause status according to actual setting of
3563 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
3564 if (fccfg_reg & (IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY))
3569 if (rx_pause && tx_pause)
3570 fc_conf->mode = RTE_FC_FULL;
3572 fc_conf->mode = RTE_FC_RX_PAUSE;
3574 fc_conf->mode = RTE_FC_TX_PAUSE;
3576 fc_conf->mode = RTE_FC_NONE;
3582 ixgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3584 struct ixgbe_hw *hw;
3586 uint32_t rx_buf_size;
3587 uint32_t max_high_water;
3589 enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
3596 PMD_INIT_FUNC_TRACE();
3598 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3599 rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0));
3600 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
3603 * At least reserve one Ethernet frame for watermark
3604 * high_water/low_water in kilo bytes for ixgbe
3606 max_high_water = (rx_buf_size - ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
3607 if ((fc_conf->high_water > max_high_water) ||
3608 (fc_conf->high_water < fc_conf->low_water)) {
3609 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
3610 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
3614 hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[fc_conf->mode];
3615 hw->fc.pause_time = fc_conf->pause_time;
3616 hw->fc.high_water[0] = fc_conf->high_water;
3617 hw->fc.low_water[0] = fc_conf->low_water;
3618 hw->fc.send_xon = fc_conf->send_xon;
3619 hw->fc.disable_fc_autoneg = !fc_conf->autoneg;
3621 err = ixgbe_fc_enable(hw);
3623 /* Not negotiated is not an error case */
3624 if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED)) {
3626 /* check if we want to forward MAC frames - driver doesn't have native
3627 * capability to do that, so we'll write the registers ourselves */
3629 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
3631 /* set or clear MFLCN.PMCF bit depending on configuration */
3632 if (fc_conf->mac_ctrl_frame_fwd != 0)
3633 mflcn |= IXGBE_MFLCN_PMCF;
3635 mflcn &= ~IXGBE_MFLCN_PMCF;
3637 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn);
3638 IXGBE_WRITE_FLUSH(hw);
3643 PMD_INIT_LOG(ERR, "ixgbe_fc_enable = 0x%x", err);
3648 * ixgbe_pfc_enable_generic - Enable flow control
3649 * @hw: pointer to hardware structure
3650 * @tc_num: traffic class number
3651 * Enable flow control according to the current settings.
3654 ixgbe_dcb_pfc_enable_generic(struct ixgbe_hw *hw, uint8_t tc_num)
3657 uint32_t mflcn_reg, fccfg_reg;
3659 uint32_t fcrtl, fcrth;
3663 /* Validate the water mark configuration */
3664 if (!hw->fc.pause_time) {
3665 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
3669 /* Low water mark of zero causes XOFF floods */
3670 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
3671 /* High/Low water can not be 0 */
3672 if ((!hw->fc.high_water[tc_num]) || (!hw->fc.low_water[tc_num])) {
3673 PMD_INIT_LOG(ERR, "Invalid water mark configuration");
3674 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
3678 if (hw->fc.low_water[tc_num] >= hw->fc.high_water[tc_num]) {
3679 PMD_INIT_LOG(ERR, "Invalid water mark configuration");
3680 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
3684 /* Negotiate the fc mode to use */
3685 ixgbe_fc_autoneg(hw);
3687 /* Disable any previous flow control settings */
3688 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
3689 mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_SHIFT | IXGBE_MFLCN_RFCE|IXGBE_MFLCN_RPFCE);
3691 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
3692 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
3694 switch (hw->fc.current_mode) {
3697 * If the count of enabled RX Priority Flow control >1,
3698 * and the TX pause can not be disabled
3701 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
3702 reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
3703 if (reg & IXGBE_FCRTH_FCEN)
3707 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
3709 case ixgbe_fc_rx_pause:
3711 * Rx Flow control is enabled and Tx Flow control is
3712 * disabled by software override. Since there really
3713 * isn't a way to advertise that we are capable of RX
3714 * Pause ONLY, we will advertise that we support both
3715 * symmetric and asymmetric Rx PAUSE. Later, we will
3716 * disable the adapter's ability to send PAUSE frames.
3718 mflcn_reg |= IXGBE_MFLCN_RPFCE;
3720 * If the count of enabled RX Priority Flow control >1,
3721 * and the TX pause can not be disabled
3724 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
3725 reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
3726 if (reg & IXGBE_FCRTH_FCEN)
3730 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
3732 case ixgbe_fc_tx_pause:
3734 * Tx Flow control is enabled, and Rx Flow control is
3735 * disabled by software override.
3737 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
3740 /* Flow control (both Rx and Tx) is enabled by SW override. */
3741 mflcn_reg |= IXGBE_MFLCN_RPFCE;
3742 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
3745 PMD_DRV_LOG(DEBUG, "Flow control param set incorrectly");
3746 ret_val = IXGBE_ERR_CONFIG;
3750 /* Set 802.3x based flow control settings. */
3751 mflcn_reg |= IXGBE_MFLCN_DPF;
3752 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
3753 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
3755 /* Set up and enable Rx high/low water mark thresholds, enable XON. */
3756 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
3757 hw->fc.high_water[tc_num]) {
3758 fcrtl = (hw->fc.low_water[tc_num] << 10) | IXGBE_FCRTL_XONE;
3759 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), fcrtl);
3760 fcrth = (hw->fc.high_water[tc_num] << 10) | IXGBE_FCRTH_FCEN;
3762 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), 0);
3764 * In order to prevent Tx hangs when the internal Tx
3765 * switch is enabled we must set the high water mark
3766 * to the maximum FCRTH value. This allows the Tx
3767 * switch to function even under heavy Rx workloads.
3769 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num)) - 32;
3771 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(tc_num), fcrth);
3773 /* Configure pause time (2 TCs per register) */
3774 reg = hw->fc.pause_time * 0x00010001;
3775 for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
3776 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
3778 /* Configure flow control refresh threshold value */
3779 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
3786 ixgbe_dcb_pfc_enable(struct rte_eth_dev *dev, uint8_t tc_num)
3788 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3789 int32_t ret_val = IXGBE_NOT_IMPLEMENTED;
3791 if (hw->mac.type != ixgbe_mac_82598EB) {
3792 ret_val = ixgbe_dcb_pfc_enable_generic(hw, tc_num);
3798 ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
3801 uint32_t rx_buf_size;
3802 uint32_t max_high_water;
3804 uint8_t map[IXGBE_DCB_MAX_USER_PRIORITY] = { 0 };
3805 struct ixgbe_hw *hw =
3806 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3807 struct ixgbe_dcb_config *dcb_config =
3808 IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
3810 enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
3817 PMD_INIT_FUNC_TRACE();
3819 ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_RX_CONFIG, map);
3820 tc_num = map[pfc_conf->priority];
3821 rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num));
3822 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
3824 * At least reserve one Ethernet frame for watermark
3825 * high_water/low_water in kilo bytes for ixgbe
3827 max_high_water = (rx_buf_size - ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
3828 if ((pfc_conf->fc.high_water > max_high_water) ||
3829 (pfc_conf->fc.high_water <= pfc_conf->fc.low_water)) {
3830 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
3831 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
3835 hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[pfc_conf->fc.mode];
3836 hw->fc.pause_time = pfc_conf->fc.pause_time;
3837 hw->fc.send_xon = pfc_conf->fc.send_xon;
3838 hw->fc.low_water[tc_num] = pfc_conf->fc.low_water;
3839 hw->fc.high_water[tc_num] = pfc_conf->fc.high_water;
3841 err = ixgbe_dcb_pfc_enable(dev, tc_num);
3843 /* Not negotiated is not an error case */
3844 if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED))
3847 PMD_INIT_LOG(ERR, "ixgbe_dcb_pfc_enable = 0x%x", err);
3852 ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
3853 struct rte_eth_rss_reta_entry64 *reta_conf,
3856 uint16_t i, sp_reta_size;
3859 uint16_t idx, shift;
3860 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3863 PMD_INIT_FUNC_TRACE();
3865 if (!ixgbe_rss_update_sp(hw->mac.type)) {
3866 PMD_DRV_LOG(ERR, "RSS reta update is not supported on this "
3871 sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
3872 if (reta_size != sp_reta_size) {
3873 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3874 "(%d) doesn't match the number hardware can supported "
3875 "(%d)\n", reta_size, sp_reta_size);
3879 for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
3880 idx = i / RTE_RETA_GROUP_SIZE;
3881 shift = i % RTE_RETA_GROUP_SIZE;
3882 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3886 reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
3887 if (mask == IXGBE_4_BIT_MASK)
3890 r = IXGBE_READ_REG(hw, reta_reg);
3891 for (j = 0, reta = 0; j < IXGBE_4_BIT_WIDTH; j++) {
3892 if (mask & (0x1 << j))
3893 reta |= reta_conf[idx].reta[shift + j] <<
3896 reta |= r & (IXGBE_8_BIT_MASK <<
3899 IXGBE_WRITE_REG(hw, reta_reg, reta);
3906 ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
3907 struct rte_eth_rss_reta_entry64 *reta_conf,
3910 uint16_t i, sp_reta_size;
3913 uint16_t idx, shift;
3914 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3917 PMD_INIT_FUNC_TRACE();
3918 sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
3919 if (reta_size != sp_reta_size) {
3920 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3921 "(%d) doesn't match the number hardware can supported "
3922 "(%d)\n", reta_size, sp_reta_size);
3926 for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
3927 idx = i / RTE_RETA_GROUP_SIZE;
3928 shift = i % RTE_RETA_GROUP_SIZE;
3929 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3934 reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
3935 reta = IXGBE_READ_REG(hw, reta_reg);
3936 for (j = 0; j < IXGBE_4_BIT_WIDTH; j++) {
3937 if (mask & (0x1 << j))
3938 reta_conf[idx].reta[shift + j] =
3939 ((reta >> (CHAR_BIT * j)) &
3948 ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
3949 uint32_t index, uint32_t pool)
3951 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3952 uint32_t enable_addr = 1;
3954 ixgbe_set_rar(hw, index, mac_addr->addr_bytes, pool, enable_addr);
3958 ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index)
3960 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3962 ixgbe_clear_rar(hw, index);
3966 ixgbe_set_default_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
3968 ixgbe_remove_rar(dev, 0);
3970 ixgbe_add_rar(dev, addr, 0, 0);
3974 ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
3978 struct ixgbe_hw *hw;
3979 struct rte_eth_dev_info dev_info;
3980 uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
3982 ixgbe_dev_info_get(dev, &dev_info);
3984 /* check that mtu is within the allowed range */
3985 if ((mtu < ETHER_MIN_MTU) || (frame_size > dev_info.max_rx_pktlen))
3988 /* refuse mtu that requires the support of scattered packets when this
3989 * feature has not been enabled before.
3991 if (!dev->data->scattered_rx &&
3992 (frame_size + 2 * IXGBE_VLAN_TAG_SIZE >
3993 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
3996 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3997 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3999 /* switch to jumbo mode if needed */
4000 if (frame_size > ETHER_MAX_LEN) {
4001 dev->data->dev_conf.rxmode.jumbo_frame = 1;
4002 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
4004 dev->data->dev_conf.rxmode.jumbo_frame = 0;
4005 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
4007 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4009 /* update max frame size */
4010 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
4012 maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
4013 maxfrs &= 0x0000FFFF;
4014 maxfrs |= (dev->data->dev_conf.rxmode.max_rx_pkt_len << 16);
4015 IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, maxfrs);
4021 * Virtual Function operations
4024 ixgbevf_intr_disable(struct ixgbe_hw *hw)
4026 PMD_INIT_FUNC_TRACE();
4028 /* Clear interrupt mask to stop from interrupts being generated */
4029 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
4031 IXGBE_WRITE_FLUSH(hw);
4035 ixgbevf_intr_enable(struct ixgbe_hw *hw)
4037 PMD_INIT_FUNC_TRACE();
4039 /* VF enable interrupt autoclean */
4040 IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, IXGBE_VF_IRQ_ENABLE_MASK);
4041 IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, IXGBE_VF_IRQ_ENABLE_MASK);
4042 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, IXGBE_VF_IRQ_ENABLE_MASK);
4044 IXGBE_WRITE_FLUSH(hw);
4048 ixgbevf_dev_configure(struct rte_eth_dev *dev)
4050 struct rte_eth_conf *conf = &dev->data->dev_conf;
4051 struct ixgbe_adapter *adapter =
4052 (struct ixgbe_adapter *)dev->data->dev_private;
4054 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
4055 dev->data->port_id);
4058 * VF has no ability to enable/disable HW CRC
4059 * Keep the persistent behavior the same as Host PF
4061 #ifndef RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC
4062 if (!conf->rxmode.hw_strip_crc) {
4063 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
4064 conf->rxmode.hw_strip_crc = 1;
4067 if (conf->rxmode.hw_strip_crc) {
4068 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
4069 conf->rxmode.hw_strip_crc = 0;
4074 * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
4075 * allocation or vector Rx preconditions we will reset it.
4077 adapter->rx_bulk_alloc_allowed = true;
4078 adapter->rx_vec_allowed = true;
4084 ixgbevf_dev_start(struct rte_eth_dev *dev)
4086 struct ixgbe_hw *hw =
4087 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4088 uint32_t intr_vector = 0;
4089 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4093 PMD_INIT_FUNC_TRACE();
4095 hw->mac.ops.reset_hw(hw);
4096 hw->mac.get_link_status = true;
4098 /* negotiate mailbox API version to use with the PF. */
4099 ixgbevf_negotiate_api(hw);
4101 ixgbevf_dev_tx_init(dev);
4103 /* This can fail when allocating mbufs for descriptor rings */
4104 err = ixgbevf_dev_rx_init(dev);
4106 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
4107 ixgbe_dev_clear_queues(dev);
4112 ixgbevf_set_vfta_all(dev, 1);
4115 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK |
4116 ETH_VLAN_EXTEND_MASK;
4117 ixgbevf_vlan_offload_set(dev, mask);
4119 ixgbevf_dev_rxtx_start(dev);
4121 /* check and configure queue intr-vector mapping */
4122 if (dev->data->dev_conf.intr_conf.rxq != 0) {
4123 intr_vector = dev->data->nb_rx_queues;
4124 if (rte_intr_efd_enable(intr_handle, intr_vector))
4128 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
4129 intr_handle->intr_vec =
4130 rte_zmalloc("intr_vec",
4131 dev->data->nb_rx_queues * sizeof(int), 0);
4132 if (intr_handle->intr_vec == NULL) {
4133 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
4134 " intr_vec\n", dev->data->nb_rx_queues);
4138 ixgbevf_configure_msix(dev);
4140 rte_intr_enable(intr_handle);
4142 /* Re-enable interrupt for VF */
4143 ixgbevf_intr_enable(hw);
4149 ixgbevf_dev_stop(struct rte_eth_dev *dev)
4151 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4152 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4154 PMD_INIT_FUNC_TRACE();
4156 hw->adapter_stopped = 1;
4157 ixgbe_stop_adapter(hw);
4160 * Clear what we set, but we still keep shadow_vfta to
4161 * restore after device starts
4163 ixgbevf_set_vfta_all(dev, 0);
4165 /* Clear stored conf */
4166 dev->data->scattered_rx = 0;
4168 ixgbe_dev_clear_queues(dev);
4170 /* Clean datapath event and queue/vec mapping */
4171 rte_intr_efd_disable(intr_handle);
4172 if (intr_handle->intr_vec != NULL) {
4173 rte_free(intr_handle->intr_vec);
4174 intr_handle->intr_vec = NULL;
4179 ixgbevf_dev_close(struct rte_eth_dev *dev)
4181 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4183 PMD_INIT_FUNC_TRACE();
4187 ixgbevf_dev_stop(dev);
4189 ixgbe_dev_free_queues(dev);
4192 * Remove the VF MAC address ro ensure
4193 * that the VF traffic goes to the PF
4194 * after stop, close and detach of the VF
4196 ixgbevf_remove_mac_addr(dev, 0);
4199 static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
4201 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4202 struct ixgbe_vfta *shadow_vfta =
4203 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
4204 int i = 0, j = 0, vfta = 0, mask = 1;
4206 for (i = 0; i < IXGBE_VFTA_SIZE; i++) {
4207 vfta = shadow_vfta->vfta[i];
4210 for (j = 0; j < 32; j++) {
4212 ixgbe_set_vfta(hw, (i<<5)+j, 0, on);
4221 ixgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
4223 struct ixgbe_hw *hw =
4224 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4225 struct ixgbe_vfta *shadow_vfta =
4226 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
4227 uint32_t vid_idx = 0;
4228 uint32_t vid_bit = 0;
4231 PMD_INIT_FUNC_TRACE();
4233 /* vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf */
4234 ret = ixgbe_set_vfta(hw, vlan_id, 0, !!on);
4236 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
4239 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
4240 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
4242 /* Save what we set and retore it after device reset */
4244 shadow_vfta->vfta[vid_idx] |= vid_bit;
4246 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
4252 ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
4254 struct ixgbe_hw *hw =
4255 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4258 PMD_INIT_FUNC_TRACE();
4260 if (queue >= hw->mac.max_rx_queues)
4263 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
4265 ctrl |= IXGBE_RXDCTL_VME;
4267 ctrl &= ~IXGBE_RXDCTL_VME;
4268 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
4270 ixgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
4274 ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4276 struct ixgbe_hw *hw =
4277 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4281 /* VF function only support hw strip feature, others are not support */
4282 if (mask & ETH_VLAN_STRIP_MASK) {
4283 on = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
4285 for (i = 0; i < hw->mac.max_rx_queues; i++)
4286 ixgbevf_vlan_strip_queue_set(dev, i, on);
4291 ixgbe_vmdq_mode_check(struct ixgbe_hw *hw)
4295 /* we only need to do this if VMDq is enabled */
4296 reg_val = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
4297 if (!(reg_val & IXGBE_VT_CTL_VT_ENABLE)) {
4298 PMD_INIT_LOG(ERR, "VMDq must be enabled for this setting");
4306 ixgbe_uta_vector(struct ixgbe_hw *hw, struct ether_addr *uc_addr)
4308 uint32_t vector = 0;
4310 switch (hw->mac.mc_filter_type) {
4311 case 0: /* use bits [47:36] of the address */
4312 vector = ((uc_addr->addr_bytes[4] >> 4) |
4313 (((uint16_t)uc_addr->addr_bytes[5]) << 4));
4315 case 1: /* use bits [46:35] of the address */
4316 vector = ((uc_addr->addr_bytes[4] >> 3) |
4317 (((uint16_t)uc_addr->addr_bytes[5]) << 5));
4319 case 2: /* use bits [45:34] of the address */
4320 vector = ((uc_addr->addr_bytes[4] >> 2) |
4321 (((uint16_t)uc_addr->addr_bytes[5]) << 6));
4323 case 3: /* use bits [43:32] of the address */
4324 vector = ((uc_addr->addr_bytes[4]) |
4325 (((uint16_t)uc_addr->addr_bytes[5]) << 8));
4327 default: /* Invalid mc_filter_type */
4331 /* vector can only be 12-bits or boundary will be exceeded */
4337 ixgbe_uc_hash_table_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
4345 const uint32_t ixgbe_uta_idx_mask = 0x7F;
4346 const uint32_t ixgbe_uta_bit_shift = 5;
4347 const uint32_t ixgbe_uta_bit_mask = (0x1 << ixgbe_uta_bit_shift) - 1;
4348 const uint32_t bit1 = 0x1;
4350 struct ixgbe_hw *hw =
4351 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4352 struct ixgbe_uta_info *uta_info =
4353 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
4355 /* The UTA table only exists on 82599 hardware and newer */
4356 if (hw->mac.type < ixgbe_mac_82599EB)
4359 vector = ixgbe_uta_vector(hw, mac_addr);
4360 uta_idx = (vector >> ixgbe_uta_bit_shift) & ixgbe_uta_idx_mask;
4361 uta_shift = vector & ixgbe_uta_bit_mask;
4363 rc = ((uta_info->uta_shadow[uta_idx] >> uta_shift & bit1) != 0);
4367 reg_val = IXGBE_READ_REG(hw, IXGBE_UTA(uta_idx));
4369 uta_info->uta_in_use++;
4370 reg_val |= (bit1 << uta_shift);
4371 uta_info->uta_shadow[uta_idx] |= (bit1 << uta_shift);
4373 uta_info->uta_in_use--;
4374 reg_val &= ~(bit1 << uta_shift);
4375 uta_info->uta_shadow[uta_idx] &= ~(bit1 << uta_shift);
4378 IXGBE_WRITE_REG(hw, IXGBE_UTA(uta_idx), reg_val);
4380 if (uta_info->uta_in_use > 0)
4381 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
4382 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
4384 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
4390 ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on)
4393 struct ixgbe_hw *hw =
4394 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4395 struct ixgbe_uta_info *uta_info =
4396 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
4398 /* The UTA table only exists on 82599 hardware and newer */
4399 if (hw->mac.type < ixgbe_mac_82599EB)
4403 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
4404 uta_info->uta_shadow[i] = ~0;
4405 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
4408 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
4409 uta_info->uta_shadow[i] = 0;
4410 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
4418 ixgbe_convert_vm_rx_mask_to_val(uint16_t rx_mask, uint32_t orig_val)
4420 uint32_t new_val = orig_val;
4422 if (rx_mask & ETH_VMDQ_ACCEPT_UNTAG)
4423 new_val |= IXGBE_VMOLR_AUPE;
4424 if (rx_mask & ETH_VMDQ_ACCEPT_HASH_MC)
4425 new_val |= IXGBE_VMOLR_ROMPE;
4426 if (rx_mask & ETH_VMDQ_ACCEPT_HASH_UC)
4427 new_val |= IXGBE_VMOLR_ROPE;
4428 if (rx_mask & ETH_VMDQ_ACCEPT_BROADCAST)
4429 new_val |= IXGBE_VMOLR_BAM;
4430 if (rx_mask & ETH_VMDQ_ACCEPT_MULTICAST)
4431 new_val |= IXGBE_VMOLR_MPE;
4437 ixgbe_set_pool_rx_mode(struct rte_eth_dev *dev, uint16_t pool,
4438 uint16_t rx_mask, uint8_t on)
4442 struct ixgbe_hw *hw =
4443 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4444 uint32_t vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
4446 if (hw->mac.type == ixgbe_mac_82598EB) {
4447 PMD_INIT_LOG(ERR, "setting VF receive mode set should be done"
4448 " on 82599 hardware and newer");
4451 if (ixgbe_vmdq_mode_check(hw) < 0)
4454 val = ixgbe_convert_vm_rx_mask_to_val(rx_mask, val);
4461 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
4467 ixgbe_set_pool_rx(struct rte_eth_dev *dev, uint16_t pool, uint8_t on)
4471 const uint8_t bit1 = 0x1;
4473 struct ixgbe_hw *hw =
4474 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4476 if (ixgbe_vmdq_mode_check(hw) < 0)
4479 if (pool >= ETH_64_POOLS)
4482 /* for pool >= 32, set bit in PFVFRE[1], otherwise PFVFRE[0] */
4484 addr = IXGBE_VFRE(1);
4485 val = bit1 << (pool - 32);
4487 addr = IXGBE_VFRE(0);
4491 reg = IXGBE_READ_REG(hw, addr);
4498 IXGBE_WRITE_REG(hw, addr, reg);
4504 ixgbe_set_pool_tx(struct rte_eth_dev *dev, uint16_t pool, uint8_t on)
4508 const uint8_t bit1 = 0x1;
4510 struct ixgbe_hw *hw =
4511 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4513 if (ixgbe_vmdq_mode_check(hw) < 0)
4516 if (pool >= ETH_64_POOLS)
4519 /* for pool >= 32, set bit in PFVFTE[1], otherwise PFVFTE[0] */
4521 addr = IXGBE_VFTE(1);
4522 val = bit1 << (pool - 32);
4524 addr = IXGBE_VFTE(0);
4528 reg = IXGBE_READ_REG(hw, addr);
4535 IXGBE_WRITE_REG(hw, addr, reg);
4541 ixgbe_set_pool_vlan_filter(struct rte_eth_dev *dev, uint16_t vlan,
4542 uint64_t pool_mask, uint8_t vlan_on)
4546 struct ixgbe_hw *hw =
4547 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4549 if (ixgbe_vmdq_mode_check(hw) < 0)
4551 for (pool_idx = 0; pool_idx < ETH_64_POOLS; pool_idx++) {
4552 if (pool_mask & ((uint64_t)(1ULL << pool_idx))) {
4553 ret = hw->mac.ops.set_vfta(hw, vlan, pool_idx, vlan_on);
4562 #define IXGBE_MRCTL_VPME 0x01 /* Virtual Pool Mirroring. */
4563 #define IXGBE_MRCTL_UPME 0x02 /* Uplink Port Mirroring. */
4564 #define IXGBE_MRCTL_DPME 0x04 /* Downlink Port Mirroring. */
4565 #define IXGBE_MRCTL_VLME 0x08 /* VLAN Mirroring. */
4566 #define IXGBE_INVALID_MIRROR_TYPE(mirror_type) \
4567 ((mirror_type) & ~(uint8_t)(ETH_MIRROR_VIRTUAL_POOL_UP | \
4568 ETH_MIRROR_UPLINK_PORT | ETH_MIRROR_DOWNLINK_PORT | ETH_MIRROR_VLAN))
4571 ixgbe_mirror_rule_set(struct rte_eth_dev *dev,
4572 struct rte_eth_mirror_conf *mirror_conf,
4573 uint8_t rule_id, uint8_t on)
4575 uint32_t mr_ctl, vlvf;
4576 uint32_t mp_lsb = 0;
4577 uint32_t mv_msb = 0;
4578 uint32_t mv_lsb = 0;
4579 uint32_t mp_msb = 0;
4582 uint64_t vlan_mask = 0;
4584 const uint8_t pool_mask_offset = 32;
4585 const uint8_t vlan_mask_offset = 32;
4586 const uint8_t dst_pool_offset = 8;
4587 const uint8_t rule_mr_offset = 4;
4588 const uint8_t mirror_rule_mask = 0x0F;
4590 struct ixgbe_mirror_info *mr_info =
4591 (IXGBE_DEV_PRIVATE_TO_PFDATA(dev->data->dev_private));
4592 struct ixgbe_hw *hw =
4593 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4594 uint8_t mirror_type = 0;
4596 if (ixgbe_vmdq_mode_check(hw) < 0)
4599 if (rule_id >= IXGBE_MAX_MIRROR_RULES)
4602 if (IXGBE_INVALID_MIRROR_TYPE(mirror_conf->rule_type)) {
4603 PMD_DRV_LOG(ERR, "unsupported mirror type 0x%x.",
4604 mirror_conf->rule_type);
4608 if (mirror_conf->rule_type & ETH_MIRROR_VLAN) {
4609 mirror_type |= IXGBE_MRCTL_VLME;
4610 /* Check if vlan id is valid and find conresponding VLAN ID index in VLVF */
4611 for (i = 0; i < IXGBE_VLVF_ENTRIES; i++) {
4612 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
4613 /* search vlan id related pool vlan filter index */
4614 reg_index = ixgbe_find_vlvf_slot(hw,
4615 mirror_conf->vlan.vlan_id[i]);
4618 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(reg_index));
4619 if ((vlvf & IXGBE_VLVF_VIEN) &&
4620 ((vlvf & IXGBE_VLVF_VLANID_MASK) ==
4621 mirror_conf->vlan.vlan_id[i]))
4622 vlan_mask |= (1ULL << reg_index);
4629 mv_lsb = vlan_mask & 0xFFFFFFFF;
4630 mv_msb = vlan_mask >> vlan_mask_offset;
4632 mr_info->mr_conf[rule_id].vlan.vlan_mask =
4633 mirror_conf->vlan.vlan_mask;
4634 for (i = 0; i < ETH_VMDQ_MAX_VLAN_FILTERS; i++) {
4635 if (mirror_conf->vlan.vlan_mask & (1ULL << i))
4636 mr_info->mr_conf[rule_id].vlan.vlan_id[i] =
4637 mirror_conf->vlan.vlan_id[i];
4642 mr_info->mr_conf[rule_id].vlan.vlan_mask = 0;
4643 for (i = 0; i < ETH_VMDQ_MAX_VLAN_FILTERS; i++)
4644 mr_info->mr_conf[rule_id].vlan.vlan_id[i] = 0;
4649 * if enable pool mirror, write related pool mask register,if disable
4650 * pool mirror, clear PFMRVM register
4652 if (mirror_conf->rule_type & ETH_MIRROR_VIRTUAL_POOL_UP) {
4653 mirror_type |= IXGBE_MRCTL_VPME;
4655 mp_lsb = mirror_conf->pool_mask & 0xFFFFFFFF;
4656 mp_msb = mirror_conf->pool_mask >> pool_mask_offset;
4657 mr_info->mr_conf[rule_id].pool_mask =
4658 mirror_conf->pool_mask;
4663 mr_info->mr_conf[rule_id].pool_mask = 0;
4666 if (mirror_conf->rule_type & ETH_MIRROR_UPLINK_PORT)
4667 mirror_type |= IXGBE_MRCTL_UPME;
4668 if (mirror_conf->rule_type & ETH_MIRROR_DOWNLINK_PORT)
4669 mirror_type |= IXGBE_MRCTL_DPME;
4671 /* read mirror control register and recalculate it */
4672 mr_ctl = IXGBE_READ_REG(hw, IXGBE_MRCTL(rule_id));
4675 mr_ctl |= mirror_type;
4676 mr_ctl &= mirror_rule_mask;
4677 mr_ctl |= mirror_conf->dst_pool << dst_pool_offset;
4679 mr_ctl &= ~(mirror_conf->rule_type & mirror_rule_mask);
4681 mr_info->mr_conf[rule_id].rule_type = mirror_conf->rule_type;
4682 mr_info->mr_conf[rule_id].dst_pool = mirror_conf->dst_pool;
4684 /* write mirrror control register */
4685 IXGBE_WRITE_REG(hw, IXGBE_MRCTL(rule_id), mr_ctl);
4687 /* write pool mirrror control register */
4688 if (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) {
4689 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id), mp_lsb);
4690 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id + rule_mr_offset),
4693 /* write VLAN mirrror control register */
4694 if (mirror_conf->rule_type == ETH_MIRROR_VLAN) {
4695 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id), mv_lsb);
4696 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id + rule_mr_offset),
4704 ixgbe_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t rule_id)
4707 uint32_t lsb_val = 0;
4708 uint32_t msb_val = 0;
4709 const uint8_t rule_mr_offset = 4;
4711 struct ixgbe_hw *hw =
4712 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4713 struct ixgbe_mirror_info *mr_info =
4714 (IXGBE_DEV_PRIVATE_TO_PFDATA(dev->data->dev_private));
4716 if (ixgbe_vmdq_mode_check(hw) < 0)
4719 memset(&mr_info->mr_conf[rule_id], 0,
4720 sizeof(struct rte_eth_mirror_conf));
4722 /* clear PFVMCTL register */
4723 IXGBE_WRITE_REG(hw, IXGBE_MRCTL(rule_id), mr_ctl);
4725 /* clear pool mask register */
4726 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id), lsb_val);
4727 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id + rule_mr_offset), msb_val);
4729 /* clear vlan mask register */
4730 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id), lsb_val);
4731 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id + rule_mr_offset), msb_val);
4737 ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
4740 struct ixgbe_hw *hw =
4741 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4743 mask = IXGBE_READ_REG(hw, IXGBE_VTEIMS);
4744 mask |= (1 << IXGBE_MISC_VEC_ID);
4745 RTE_SET_USED(queue_id);
4746 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
4748 rte_intr_enable(&dev->pci_dev->intr_handle);
4754 ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
4757 struct ixgbe_hw *hw =
4758 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4760 mask = IXGBE_READ_REG(hw, IXGBE_VTEIMS);
4761 mask &= ~(1 << IXGBE_MISC_VEC_ID);
4762 RTE_SET_USED(queue_id);
4763 IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
4769 ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
4772 struct ixgbe_hw *hw =
4773 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4774 struct ixgbe_interrupt *intr =
4775 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4777 if (queue_id < 16) {
4778 ixgbe_disable_intr(hw);
4779 intr->mask |= (1 << queue_id);
4780 ixgbe_enable_intr(dev);
4781 } else if (queue_id < 32) {
4782 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(0));
4783 mask &= (1 << queue_id);
4784 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
4785 } else if (queue_id < 64) {
4786 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(1));
4787 mask &= (1 << (queue_id - 32));
4788 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
4790 rte_intr_enable(&dev->pci_dev->intr_handle);
4796 ixgbe_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
4799 struct ixgbe_hw *hw =
4800 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4801 struct ixgbe_interrupt *intr =
4802 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4804 if (queue_id < 16) {
4805 ixgbe_disable_intr(hw);
4806 intr->mask &= ~(1 << queue_id);
4807 ixgbe_enable_intr(dev);
4808 } else if (queue_id < 32) {
4809 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(0));
4810 mask &= ~(1 << queue_id);
4811 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
4812 } else if (queue_id < 64) {
4813 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(1));
4814 mask &= ~(1 << (queue_id - 32));
4815 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
4822 ixgbevf_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
4823 uint8_t queue, uint8_t msix_vector)
4827 if (direction == -1) {
4829 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
4830 tmp = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
4833 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, tmp);
4835 /* rx or tx cause */
4836 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
4837 idx = ((16 * (queue & 1)) + (8 * direction));
4838 tmp = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1));
4839 tmp &= ~(0xFF << idx);
4840 tmp |= (msix_vector << idx);
4841 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), tmp);
4846 * set the IVAR registers, mapping interrupt causes to vectors
4848 * pointer to ixgbe_hw struct
4850 * 0 for Rx, 1 for Tx, -1 for other causes
4852 * queue to map the corresponding interrupt to
4854 * the vector to map to the corresponding queue
4857 ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
4858 uint8_t queue, uint8_t msix_vector)
4862 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
4863 if (hw->mac.type == ixgbe_mac_82598EB) {
4864 if (direction == -1)
4866 idx = (((direction * 64) + queue) >> 2) & 0x1F;
4867 tmp = IXGBE_READ_REG(hw, IXGBE_IVAR(idx));
4868 tmp &= ~(0xFF << (8 * (queue & 0x3)));
4869 tmp |= (msix_vector << (8 * (queue & 0x3)));
4870 IXGBE_WRITE_REG(hw, IXGBE_IVAR(idx), tmp);
4871 } else if ((hw->mac.type == ixgbe_mac_82599EB) ||
4872 (hw->mac.type == ixgbe_mac_X540)) {
4873 if (direction == -1) {
4875 idx = ((queue & 1) * 8);
4876 tmp = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
4877 tmp &= ~(0xFF << idx);
4878 tmp |= (msix_vector << idx);
4879 IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, tmp);
4881 /* rx or tx causes */
4882 idx = ((16 * (queue & 1)) + (8 * direction));
4883 tmp = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
4884 tmp &= ~(0xFF << idx);
4885 tmp |= (msix_vector << idx);
4886 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), tmp);
4892 ixgbevf_configure_msix(struct rte_eth_dev *dev)
4894 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4895 struct ixgbe_hw *hw =
4896 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4898 uint32_t vector_idx = IXGBE_MISC_VEC_ID;
4900 /* won't configure msix register if no mapping is done
4901 * between intr vector and event fd.
4903 if (!rte_intr_dp_is_en(intr_handle))
4906 /* Configure all RX queues of VF */
4907 for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
4908 /* Force all queue use vector 0,
4909 * as IXGBE_VF_MAXMSIVECOTR = 1
4911 ixgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
4912 intr_handle->intr_vec[q_idx] = vector_idx;
4915 /* Configure VF other cause ivar */
4916 ixgbevf_set_ivar_map(hw, -1, 1, vector_idx);
4920 * Sets up the hardware to properly generate MSI-X interrupts
4922 * board private structure
4925 ixgbe_configure_msix(struct rte_eth_dev *dev)
4927 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4928 struct ixgbe_hw *hw =
4929 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4930 uint32_t queue_id, base = IXGBE_MISC_VEC_ID;
4931 uint32_t vec = IXGBE_MISC_VEC_ID;
4935 /* won't configure msix register if no mapping is done
4936 * between intr vector and event fd
4938 if (!rte_intr_dp_is_en(intr_handle))
4941 if (rte_intr_allow_others(intr_handle))
4942 vec = base = IXGBE_RX_VEC_START;
4944 /* setup GPIE for MSI-x mode */
4945 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
4946 gpie |= IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4947 IXGBE_GPIE_OCD | IXGBE_GPIE_EIAME;
4948 /* auto clearing and auto setting corresponding bits in EIMS
4949 * when MSI-X interrupt is triggered
4951 if (hw->mac.type == ixgbe_mac_82598EB) {
4952 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4954 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4955 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4957 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4959 /* Populate the IVAR table and set the ITR values to the
4960 * corresponding register.
4962 for (queue_id = 0; queue_id < dev->data->nb_rx_queues;
4964 /* by default, 1:1 mapping */
4965 ixgbe_set_ivar_map(hw, 0, queue_id, vec);
4966 intr_handle->intr_vec[queue_id] = vec;
4967 if (vec < base + intr_handle->nb_efd - 1)
4971 switch (hw->mac.type) {
4972 case ixgbe_mac_82598EB:
4973 ixgbe_set_ivar_map(hw, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
4976 case ixgbe_mac_82599EB:
4977 case ixgbe_mac_X540:
4978 ixgbe_set_ivar_map(hw, -1, 1, IXGBE_MISC_VEC_ID);
4983 IXGBE_WRITE_REG(hw, IXGBE_EITR(IXGBE_MISC_VEC_ID),
4984 IXGBE_MIN_INTER_INTERRUPT_INTERVAL_DEFAULT & 0xFFF);
4986 /* set up to autoclear timer, and the vectors */
4987 mask = IXGBE_EIMS_ENABLE_MASK;
4988 mask &= ~(IXGBE_EIMS_OTHER |
4989 IXGBE_EIMS_MAILBOX |
4992 IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask);
4995 static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
4996 uint16_t queue_idx, uint16_t tx_rate)
4998 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4999 uint32_t rf_dec, rf_int;
5001 uint16_t link_speed = dev->data->dev_link.link_speed;
5003 if (queue_idx >= hw->mac.max_tx_queues)
5007 /* Calculate the rate factor values to set */
5008 rf_int = (uint32_t)link_speed / (uint32_t)tx_rate;
5009 rf_dec = (uint32_t)link_speed % (uint32_t)tx_rate;
5010 rf_dec = (rf_dec << IXGBE_RTTBCNRC_RF_INT_SHIFT) / tx_rate;
5012 bcnrc_val = IXGBE_RTTBCNRC_RS_ENA;
5013 bcnrc_val |= ((rf_int << IXGBE_RTTBCNRC_RF_INT_SHIFT) &
5014 IXGBE_RTTBCNRC_RF_INT_MASK_M);
5015 bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK);
5021 * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
5022 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported, otherwise
5025 if ((dev->data->dev_conf.rxmode.jumbo_frame == 1) &&
5026 (dev->data->dev_conf.rxmode.max_rx_pkt_len >=
5027 IXGBE_MAX_JUMBO_FRAME_SIZE))
5028 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM,
5029 IXGBE_MMW_SIZE_JUMBO_FRAME);
5031 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM,
5032 IXGBE_MMW_SIZE_DEFAULT);
5034 /* Set RTTBCNRC of queue X */
5035 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_idx);
5036 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
5037 IXGBE_WRITE_FLUSH(hw);
5042 static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
5043 uint16_t tx_rate, uint64_t q_msk)
5045 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5046 struct ixgbe_vf_info *vfinfo =
5047 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
5048 uint8_t nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
5049 uint32_t queue_stride =
5050 IXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
5051 uint32_t queue_idx = vf * queue_stride, idx = 0, vf_idx;
5052 uint32_t queue_end = queue_idx + nb_q_per_pool - 1;
5053 uint16_t total_rate = 0;
5055 if (queue_end >= hw->mac.max_tx_queues)
5058 if (vfinfo != NULL) {
5059 for (vf_idx = 0; vf_idx < dev->pci_dev->max_vfs; vf_idx++) {
5062 for (idx = 0; idx < RTE_DIM(vfinfo[vf_idx].tx_rate);
5064 total_rate += vfinfo[vf_idx].tx_rate[idx];
5069 /* Store tx_rate for this vf. */
5070 for (idx = 0; idx < nb_q_per_pool; idx++) {
5071 if (((uint64_t)0x1 << idx) & q_msk) {
5072 if (vfinfo[vf].tx_rate[idx] != tx_rate)
5073 vfinfo[vf].tx_rate[idx] = tx_rate;
5074 total_rate += tx_rate;
5078 if (total_rate > dev->data->dev_link.link_speed) {
5080 * Reset stored TX rate of the VF if it causes exceed
5083 memset(vfinfo[vf].tx_rate, 0, sizeof(vfinfo[vf].tx_rate));
5087 /* Set RTTBCNRC of each queue/pool for vf X */
5088 for (; queue_idx <= queue_end; queue_idx++) {
5090 ixgbe_set_queue_rate_limit(dev, queue_idx, tx_rate);
5098 ixgbevf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
5099 __attribute__((unused)) uint32_t index,
5100 __attribute__((unused)) uint32_t pool)
5102 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5106 * On a 82599 VF, adding again the same MAC addr is not an idempotent
5107 * operation. Trap this case to avoid exhausting the [very limited]
5108 * set of PF resources used to store VF MAC addresses.
5110 if (memcmp(hw->mac.perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
5112 diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
5115 PMD_DRV_LOG(ERR, "Unable to add MAC address - diag=%d", diag);
5119 ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
5121 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5122 struct ether_addr *perm_addr = (struct ether_addr *) hw->mac.perm_addr;
5123 struct ether_addr *mac_addr;
5128 * The IXGBE_VF_SET_MACVLAN command of the ixgbe-pf driver does
5129 * not support the deletion of a given MAC address.
5130 * Instead, it imposes to delete all MAC addresses, then to add again
5131 * all MAC addresses with the exception of the one to be deleted.
5133 (void) ixgbevf_set_uc_addr_vf(hw, 0, NULL);
5136 * Add again all MAC addresses, with the exception of the deleted one
5137 * and of the permanent MAC address.
5139 for (i = 0, mac_addr = dev->data->mac_addrs;
5140 i < hw->mac.num_rar_entries; i++, mac_addr++) {
5141 /* Skip the deleted MAC address */
5144 /* Skip NULL MAC addresses */
5145 if (is_zero_ether_addr(mac_addr))
5147 /* Skip the permanent MAC address */
5148 if (memcmp(perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
5150 diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
5153 "Adding again MAC address "
5154 "%02x:%02x:%02x:%02x:%02x:%02x failed "
5156 mac_addr->addr_bytes[0],
5157 mac_addr->addr_bytes[1],
5158 mac_addr->addr_bytes[2],
5159 mac_addr->addr_bytes[3],
5160 mac_addr->addr_bytes[4],
5161 mac_addr->addr_bytes[5],
5167 ixgbevf_set_default_mac_addr(struct rte_eth_dev *dev, struct ether_addr *addr)
5169 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5171 hw->mac.ops.set_rar(hw, 0, (void *)addr, 0, 0);
5174 #define MAC_TYPE_FILTER_SUP(type) do {\
5175 if ((type) != ixgbe_mac_82599EB && (type) != ixgbe_mac_X540 &&\
5176 (type) != ixgbe_mac_X550 && (type) != ixgbe_mac_X550EM_x &&\
5177 (type) != ixgbe_mac_X550EM_a)\
5182 ixgbe_syn_filter_set(struct rte_eth_dev *dev,
5183 struct rte_eth_syn_filter *filter,
5186 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5189 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
5192 synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
5195 if (synqf & IXGBE_SYN_FILTER_ENABLE)
5197 synqf = (uint32_t)(((filter->queue << IXGBE_SYN_FILTER_QUEUE_SHIFT) &
5198 IXGBE_SYN_FILTER_QUEUE) | IXGBE_SYN_FILTER_ENABLE);
5200 if (filter->hig_pri)
5201 synqf |= IXGBE_SYN_FILTER_SYNQFP;
5203 synqf &= ~IXGBE_SYN_FILTER_SYNQFP;
5205 if (!(synqf & IXGBE_SYN_FILTER_ENABLE))
5207 synqf &= ~(IXGBE_SYN_FILTER_QUEUE | IXGBE_SYN_FILTER_ENABLE);
5209 IXGBE_WRITE_REG(hw, IXGBE_SYNQF, synqf);
5210 IXGBE_WRITE_FLUSH(hw);
5215 ixgbe_syn_filter_get(struct rte_eth_dev *dev,
5216 struct rte_eth_syn_filter *filter)
5218 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5219 uint32_t synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
5221 if (synqf & IXGBE_SYN_FILTER_ENABLE) {
5222 filter->hig_pri = (synqf & IXGBE_SYN_FILTER_SYNQFP) ? 1 : 0;
5223 filter->queue = (uint16_t)((synqf & IXGBE_SYN_FILTER_QUEUE) >> 1);
5230 ixgbe_syn_filter_handle(struct rte_eth_dev *dev,
5231 enum rte_filter_op filter_op,
5234 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5237 MAC_TYPE_FILTER_SUP(hw->mac.type);
5239 if (filter_op == RTE_ETH_FILTER_NOP)
5243 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
5248 switch (filter_op) {
5249 case RTE_ETH_FILTER_ADD:
5250 ret = ixgbe_syn_filter_set(dev,
5251 (struct rte_eth_syn_filter *)arg,
5254 case RTE_ETH_FILTER_DELETE:
5255 ret = ixgbe_syn_filter_set(dev,
5256 (struct rte_eth_syn_filter *)arg,
5259 case RTE_ETH_FILTER_GET:
5260 ret = ixgbe_syn_filter_get(dev,
5261 (struct rte_eth_syn_filter *)arg);
5264 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
5273 static inline enum ixgbe_5tuple_protocol
5274 convert_protocol_type(uint8_t protocol_value)
5276 if (protocol_value == IPPROTO_TCP)
5277 return IXGBE_FILTER_PROTOCOL_TCP;
5278 else if (protocol_value == IPPROTO_UDP)
5279 return IXGBE_FILTER_PROTOCOL_UDP;
5280 else if (protocol_value == IPPROTO_SCTP)
5281 return IXGBE_FILTER_PROTOCOL_SCTP;
5283 return IXGBE_FILTER_PROTOCOL_NONE;
5287 * add a 5tuple filter
5290 * dev: Pointer to struct rte_eth_dev.
5291 * index: the index the filter allocates.
5292 * filter: ponter to the filter that will be added.
5293 * rx_queue: the queue id the filter assigned to.
5296 * - On success, zero.
5297 * - On failure, a negative value.
5300 ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
5301 struct ixgbe_5tuple_filter *filter)
5303 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5304 struct ixgbe_filter_info *filter_info =
5305 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5307 uint32_t ftqf, sdpqf;
5308 uint32_t l34timir = 0;
5309 uint8_t mask = 0xff;
5312 * look for an unused 5tuple filter index,
5313 * and insert the filter to list.
5315 for (i = 0; i < IXGBE_MAX_FTQF_FILTERS; i++) {
5316 idx = i / (sizeof(uint32_t) * NBBY);
5317 shift = i % (sizeof(uint32_t) * NBBY);
5318 if (!(filter_info->fivetuple_mask[idx] & (1 << shift))) {
5319 filter_info->fivetuple_mask[idx] |= 1 << shift;
5321 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
5327 if (i >= IXGBE_MAX_FTQF_FILTERS) {
5328 PMD_DRV_LOG(ERR, "5tuple filters are full.");
5332 sdpqf = (uint32_t)(filter->filter_info.dst_port <<
5333 IXGBE_SDPQF_DSTPORT_SHIFT);
5334 sdpqf = sdpqf | (filter->filter_info.src_port & IXGBE_SDPQF_SRCPORT);
5336 ftqf = (uint32_t)(filter->filter_info.proto &
5337 IXGBE_FTQF_PROTOCOL_MASK);
5338 ftqf |= (uint32_t)((filter->filter_info.priority &
5339 IXGBE_FTQF_PRIORITY_MASK) << IXGBE_FTQF_PRIORITY_SHIFT);
5340 if (filter->filter_info.src_ip_mask == 0) /* 0 means compare. */
5341 mask &= IXGBE_FTQF_SOURCE_ADDR_MASK;
5342 if (filter->filter_info.dst_ip_mask == 0)
5343 mask &= IXGBE_FTQF_DEST_ADDR_MASK;
5344 if (filter->filter_info.src_port_mask == 0)
5345 mask &= IXGBE_FTQF_SOURCE_PORT_MASK;
5346 if (filter->filter_info.dst_port_mask == 0)
5347 mask &= IXGBE_FTQF_DEST_PORT_MASK;
5348 if (filter->filter_info.proto_mask == 0)
5349 mask &= IXGBE_FTQF_PROTOCOL_COMP_MASK;
5350 ftqf |= mask << IXGBE_FTQF_5TUPLE_MASK_SHIFT;
5351 ftqf |= IXGBE_FTQF_POOL_MASK_EN;
5352 ftqf |= IXGBE_FTQF_QUEUE_ENABLE;
5354 IXGBE_WRITE_REG(hw, IXGBE_DAQF(i), filter->filter_info.dst_ip);
5355 IXGBE_WRITE_REG(hw, IXGBE_SAQF(i), filter->filter_info.src_ip);
5356 IXGBE_WRITE_REG(hw, IXGBE_SDPQF(i), sdpqf);
5357 IXGBE_WRITE_REG(hw, IXGBE_FTQF(i), ftqf);
5359 l34timir |= IXGBE_L34T_IMIR_RESERVE;
5360 l34timir |= (uint32_t)(filter->queue <<
5361 IXGBE_L34T_IMIR_QUEUE_SHIFT);
5362 IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(i), l34timir);
5367 * remove a 5tuple filter
5370 * dev: Pointer to struct rte_eth_dev.
5371 * filter: the pointer of the filter will be removed.
5374 ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
5375 struct ixgbe_5tuple_filter *filter)
5377 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5378 struct ixgbe_filter_info *filter_info =
5379 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5380 uint16_t index = filter->index;
5382 filter_info->fivetuple_mask[index / (sizeof(uint32_t) * NBBY)] &=
5383 ~(1 << (index % (sizeof(uint32_t) * NBBY)));
5384 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
5387 IXGBE_WRITE_REG(hw, IXGBE_DAQF(index), 0);
5388 IXGBE_WRITE_REG(hw, IXGBE_SAQF(index), 0);
5389 IXGBE_WRITE_REG(hw, IXGBE_SDPQF(index), 0);
5390 IXGBE_WRITE_REG(hw, IXGBE_FTQF(index), 0);
5391 IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(index), 0);
5395 ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
5397 struct ixgbe_hw *hw;
5398 uint32_t max_frame = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
5400 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5402 if ((mtu < ETHER_MIN_MTU) || (max_frame > ETHER_MAX_JUMBO_FRAME_LEN))
5405 /* refuse mtu that requires the support of scattered packets when this
5406 * feature has not been enabled before.
5408 if (!dev->data->scattered_rx &&
5409 (max_frame + 2 * IXGBE_VLAN_TAG_SIZE >
5410 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
5414 * When supported by the underlying PF driver, use the IXGBE_VF_SET_MTU
5415 * request of the version 2.0 of the mailbox API.
5416 * For now, use the IXGBE_VF_SET_LPE request of the version 1.0
5417 * of the mailbox API.
5418 * This call to IXGBE_SET_LPE action won't work with ixgbe pf drivers
5419 * prior to 3.11.33 which contains the following change:
5420 * "ixgbe: Enable jumbo frames support w/ SR-IOV"
5422 ixgbevf_rlpml_set_vf(hw, max_frame);
5424 /* update max frame size */
5425 dev->data->dev_conf.rxmode.max_rx_pkt_len = max_frame;
5429 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
5430 if ((type) != ixgbe_mac_82599EB && (type) != ixgbe_mac_X540)\
5434 static inline struct ixgbe_5tuple_filter *
5435 ixgbe_5tuple_filter_lookup(struct ixgbe_5tuple_filter_list *filter_list,
5436 struct ixgbe_5tuple_filter_info *key)
5438 struct ixgbe_5tuple_filter *it;
5440 TAILQ_FOREACH(it, filter_list, entries) {
5441 if (memcmp(key, &it->filter_info,
5442 sizeof(struct ixgbe_5tuple_filter_info)) == 0) {
5449 /* translate elements in struct rte_eth_ntuple_filter to struct ixgbe_5tuple_filter_info*/
5451 ntuple_filter_to_5tuple(struct rte_eth_ntuple_filter *filter,
5452 struct ixgbe_5tuple_filter_info *filter_info)
5454 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM ||
5455 filter->priority > IXGBE_5TUPLE_MAX_PRI ||
5456 filter->priority < IXGBE_5TUPLE_MIN_PRI)
5459 switch (filter->dst_ip_mask) {
5461 filter_info->dst_ip_mask = 0;
5462 filter_info->dst_ip = filter->dst_ip;
5465 filter_info->dst_ip_mask = 1;
5468 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
5472 switch (filter->src_ip_mask) {
5474 filter_info->src_ip_mask = 0;
5475 filter_info->src_ip = filter->src_ip;
5478 filter_info->src_ip_mask = 1;
5481 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
5485 switch (filter->dst_port_mask) {
5487 filter_info->dst_port_mask = 0;
5488 filter_info->dst_port = filter->dst_port;
5491 filter_info->dst_port_mask = 1;
5494 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
5498 switch (filter->src_port_mask) {
5500 filter_info->src_port_mask = 0;
5501 filter_info->src_port = filter->src_port;
5504 filter_info->src_port_mask = 1;
5507 PMD_DRV_LOG(ERR, "invalid src_port mask.");
5511 switch (filter->proto_mask) {
5513 filter_info->proto_mask = 0;
5514 filter_info->proto =
5515 convert_protocol_type(filter->proto);
5518 filter_info->proto_mask = 1;
5521 PMD_DRV_LOG(ERR, "invalid protocol mask.");
5525 filter_info->priority = (uint8_t)filter->priority;
5530 * add or delete a ntuple filter
5533 * dev: Pointer to struct rte_eth_dev.
5534 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
5535 * add: if true, add filter, if false, remove filter
5538 * - On success, zero.
5539 * - On failure, a negative value.
5542 ixgbe_add_del_ntuple_filter(struct rte_eth_dev *dev,
5543 struct rte_eth_ntuple_filter *ntuple_filter,
5546 struct ixgbe_filter_info *filter_info =
5547 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5548 struct ixgbe_5tuple_filter_info filter_5tuple;
5549 struct ixgbe_5tuple_filter *filter;
5552 if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
5553 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
5557 memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
5558 ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
5562 filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
5564 if (filter != NULL && add) {
5565 PMD_DRV_LOG(ERR, "filter exists.");
5568 if (filter == NULL && !add) {
5569 PMD_DRV_LOG(ERR, "filter doesn't exist.");
5574 filter = rte_zmalloc("ixgbe_5tuple_filter",
5575 sizeof(struct ixgbe_5tuple_filter), 0);
5578 (void)rte_memcpy(&filter->filter_info,
5580 sizeof(struct ixgbe_5tuple_filter_info));
5581 filter->queue = ntuple_filter->queue;
5582 ret = ixgbe_add_5tuple_filter(dev, filter);
5588 ixgbe_remove_5tuple_filter(dev, filter);
5594 * get a ntuple filter
5597 * dev: Pointer to struct rte_eth_dev.
5598 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
5601 * - On success, zero.
5602 * - On failure, a negative value.
5605 ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
5606 struct rte_eth_ntuple_filter *ntuple_filter)
5608 struct ixgbe_filter_info *filter_info =
5609 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5610 struct ixgbe_5tuple_filter_info filter_5tuple;
5611 struct ixgbe_5tuple_filter *filter;
5614 if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
5615 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
5619 memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
5620 ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
5624 filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
5626 if (filter == NULL) {
5627 PMD_DRV_LOG(ERR, "filter doesn't exist.");
5630 ntuple_filter->queue = filter->queue;
5635 * ixgbe_ntuple_filter_handle - Handle operations for ntuple filter.
5636 * @dev: pointer to rte_eth_dev structure
5637 * @filter_op:operation will be taken.
5638 * @arg: a pointer to specific structure corresponding to the filter_op
5641 * - On success, zero.
5642 * - On failure, a negative value.
5645 ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
5646 enum rte_filter_op filter_op,
5649 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5652 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
5654 if (filter_op == RTE_ETH_FILTER_NOP)
5658 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
5663 switch (filter_op) {
5664 case RTE_ETH_FILTER_ADD:
5665 ret = ixgbe_add_del_ntuple_filter(dev,
5666 (struct rte_eth_ntuple_filter *)arg,
5669 case RTE_ETH_FILTER_DELETE:
5670 ret = ixgbe_add_del_ntuple_filter(dev,
5671 (struct rte_eth_ntuple_filter *)arg,
5674 case RTE_ETH_FILTER_GET:
5675 ret = ixgbe_get_ntuple_filter(dev,
5676 (struct rte_eth_ntuple_filter *)arg);
5679 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
5687 ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
5692 for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
5693 if (filter_info->ethertype_filters[i] == ethertype &&
5694 (filter_info->ethertype_mask & (1 << i)))
5701 ixgbe_ethertype_filter_insert(struct ixgbe_filter_info *filter_info,
5706 for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
5707 if (!(filter_info->ethertype_mask & (1 << i))) {
5708 filter_info->ethertype_mask |= 1 << i;
5709 filter_info->ethertype_filters[i] = ethertype;
5717 ixgbe_ethertype_filter_remove(struct ixgbe_filter_info *filter_info,
5720 if (idx >= IXGBE_MAX_ETQF_FILTERS)
5722 filter_info->ethertype_mask &= ~(1 << idx);
5723 filter_info->ethertype_filters[idx] = 0;
5728 ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
5729 struct rte_eth_ethertype_filter *filter,
5732 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5733 struct ixgbe_filter_info *filter_info =
5734 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5739 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
5742 if (filter->ether_type == ETHER_TYPE_IPv4 ||
5743 filter->ether_type == ETHER_TYPE_IPv6) {
5744 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
5745 " ethertype filter.", filter->ether_type);
5749 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
5750 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
5753 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
5754 PMD_DRV_LOG(ERR, "drop option is unsupported.");
5758 ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
5759 if (ret >= 0 && add) {
5760 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
5761 filter->ether_type);
5764 if (ret < 0 && !add) {
5765 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
5766 filter->ether_type);
5771 ret = ixgbe_ethertype_filter_insert(filter_info,
5772 filter->ether_type);
5774 PMD_DRV_LOG(ERR, "ethertype filters are full.");
5777 etqf = IXGBE_ETQF_FILTER_EN;
5778 etqf |= (uint32_t)filter->ether_type;
5779 etqs |= (uint32_t)((filter->queue <<
5780 IXGBE_ETQS_RX_QUEUE_SHIFT) &
5781 IXGBE_ETQS_RX_QUEUE);
5782 etqs |= IXGBE_ETQS_QUEUE_EN;
5784 ret = ixgbe_ethertype_filter_remove(filter_info, (uint8_t)ret);
5788 IXGBE_WRITE_REG(hw, IXGBE_ETQF(ret), etqf);
5789 IXGBE_WRITE_REG(hw, IXGBE_ETQS(ret), etqs);
5790 IXGBE_WRITE_FLUSH(hw);
5796 ixgbe_get_ethertype_filter(struct rte_eth_dev *dev,
5797 struct rte_eth_ethertype_filter *filter)
5799 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5800 struct ixgbe_filter_info *filter_info =
5801 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5802 uint32_t etqf, etqs;
5805 ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
5807 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
5808 filter->ether_type);
5812 etqf = IXGBE_READ_REG(hw, IXGBE_ETQF(ret));
5813 if (etqf & IXGBE_ETQF_FILTER_EN) {
5814 etqs = IXGBE_READ_REG(hw, IXGBE_ETQS(ret));
5815 filter->ether_type = etqf & IXGBE_ETQF_ETHERTYPE;
5817 filter->queue = (etqs & IXGBE_ETQS_RX_QUEUE) >>
5818 IXGBE_ETQS_RX_QUEUE_SHIFT;
5825 * ixgbe_ethertype_filter_handle - Handle operations for ethertype filter.
5826 * @dev: pointer to rte_eth_dev structure
5827 * @filter_op:operation will be taken.
5828 * @arg: a pointer to specific structure corresponding to the filter_op
5831 ixgbe_ethertype_filter_handle(struct rte_eth_dev *dev,
5832 enum rte_filter_op filter_op,
5835 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5838 MAC_TYPE_FILTER_SUP(hw->mac.type);
5840 if (filter_op == RTE_ETH_FILTER_NOP)
5844 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
5849 switch (filter_op) {
5850 case RTE_ETH_FILTER_ADD:
5851 ret = ixgbe_add_del_ethertype_filter(dev,
5852 (struct rte_eth_ethertype_filter *)arg,
5855 case RTE_ETH_FILTER_DELETE:
5856 ret = ixgbe_add_del_ethertype_filter(dev,
5857 (struct rte_eth_ethertype_filter *)arg,
5860 case RTE_ETH_FILTER_GET:
5861 ret = ixgbe_get_ethertype_filter(dev,
5862 (struct rte_eth_ethertype_filter *)arg);
5865 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
5873 ixgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
5874 enum rte_filter_type filter_type,
5875 enum rte_filter_op filter_op,
5880 switch (filter_type) {
5881 case RTE_ETH_FILTER_NTUPLE:
5882 ret = ixgbe_ntuple_filter_handle(dev, filter_op, arg);
5884 case RTE_ETH_FILTER_ETHERTYPE:
5885 ret = ixgbe_ethertype_filter_handle(dev, filter_op, arg);
5887 case RTE_ETH_FILTER_SYN:
5888 ret = ixgbe_syn_filter_handle(dev, filter_op, arg);
5890 case RTE_ETH_FILTER_FDIR:
5891 ret = ixgbe_fdir_ctrl_func(dev, filter_op, arg);
5893 case RTE_ETH_FILTER_L2_TUNNEL:
5894 ret = ixgbe_dev_l2_tunnel_filter_handle(dev, filter_op, arg);
5897 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
5906 ixgbe_dev_addr_list_itr(__attribute__((unused)) struct ixgbe_hw *hw,
5907 u8 **mc_addr_ptr, u32 *vmdq)
5912 mc_addr = *mc_addr_ptr;
5913 *mc_addr_ptr = (mc_addr + sizeof(struct ether_addr));
5918 ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
5919 struct ether_addr *mc_addr_set,
5920 uint32_t nb_mc_addr)
5922 struct ixgbe_hw *hw;
5925 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5926 mc_addr_list = (u8 *)mc_addr_set;
5927 return ixgbe_update_mc_addr_list(hw, mc_addr_list, nb_mc_addr,
5928 ixgbe_dev_addr_list_itr, TRUE);
5932 ixgbe_read_systime_cyclecounter(struct rte_eth_dev *dev)
5934 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5935 uint64_t systime_cycles;
5937 switch (hw->mac.type) {
5938 case ixgbe_mac_X550:
5939 case ixgbe_mac_X550EM_x:
5940 case ixgbe_mac_X550EM_a:
5941 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
5942 systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
5943 systime_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
5947 systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
5948 systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
5952 return systime_cycles;
5956 ixgbe_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
5958 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5959 uint64_t rx_tstamp_cycles;
5961 switch (hw->mac.type) {
5962 case ixgbe_mac_X550:
5963 case ixgbe_mac_X550EM_x:
5964 case ixgbe_mac_X550EM_a:
5965 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
5966 rx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
5967 rx_tstamp_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPH)
5971 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
5972 rx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
5973 rx_tstamp_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPH)
5977 return rx_tstamp_cycles;
5981 ixgbe_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
5983 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5984 uint64_t tx_tstamp_cycles;
5986 switch (hw->mac.type) {
5987 case ixgbe_mac_X550:
5988 case ixgbe_mac_X550EM_x:
5989 case ixgbe_mac_X550EM_a:
5990 /* TXSTMPL stores ns and TXSTMPH stores seconds. */
5991 tx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
5992 tx_tstamp_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPH)
5996 /* TXSTMPL stores ns and TXSTMPH stores seconds. */
5997 tx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
5998 tx_tstamp_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPH)
6002 return tx_tstamp_cycles;
6006 ixgbe_start_timecounters(struct rte_eth_dev *dev)
6008 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6009 struct ixgbe_adapter *adapter =
6010 (struct ixgbe_adapter *)dev->data->dev_private;
6011 struct rte_eth_link link;
6012 uint32_t incval = 0;
6015 /* Get current link speed. */
6016 memset(&link, 0, sizeof(link));
6017 ixgbe_dev_link_update(dev, 1);
6018 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
6020 switch (link.link_speed) {
6021 case ETH_SPEED_NUM_100M:
6022 incval = IXGBE_INCVAL_100;
6023 shift = IXGBE_INCVAL_SHIFT_100;
6025 case ETH_SPEED_NUM_1G:
6026 incval = IXGBE_INCVAL_1GB;
6027 shift = IXGBE_INCVAL_SHIFT_1GB;
6029 case ETH_SPEED_NUM_10G:
6031 incval = IXGBE_INCVAL_10GB;
6032 shift = IXGBE_INCVAL_SHIFT_10GB;
6036 switch (hw->mac.type) {
6037 case ixgbe_mac_X550:
6038 case ixgbe_mac_X550EM_x:
6039 case ixgbe_mac_X550EM_a:
6040 /* Independent of link speed. */
6042 /* Cycles read will be interpreted as ns. */
6045 case ixgbe_mac_X540:
6046 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, incval);
6048 case ixgbe_mac_82599EB:
6049 incval >>= IXGBE_INCVAL_SHIFT_82599;
6050 shift -= IXGBE_INCVAL_SHIFT_82599;
6051 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA,
6052 (1 << IXGBE_INCPER_SHIFT_82599) | incval);
6055 /* Not supported. */
6059 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
6060 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
6061 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
6063 adapter->systime_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
6064 adapter->systime_tc.cc_shift = shift;
6065 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
6067 adapter->rx_tstamp_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
6068 adapter->rx_tstamp_tc.cc_shift = shift;
6069 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
6071 adapter->tx_tstamp_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
6072 adapter->tx_tstamp_tc.cc_shift = shift;
6073 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
6077 ixgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
6079 struct ixgbe_adapter *adapter =
6080 (struct ixgbe_adapter *)dev->data->dev_private;
6082 adapter->systime_tc.nsec += delta;
6083 adapter->rx_tstamp_tc.nsec += delta;
6084 adapter->tx_tstamp_tc.nsec += delta;
6090 ixgbe_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
6093 struct ixgbe_adapter *adapter =
6094 (struct ixgbe_adapter *)dev->data->dev_private;
6096 ns = rte_timespec_to_ns(ts);
6097 /* Set the timecounters to a new value. */
6098 adapter->systime_tc.nsec = ns;
6099 adapter->rx_tstamp_tc.nsec = ns;
6100 adapter->tx_tstamp_tc.nsec = ns;
6106 ixgbe_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
6108 uint64_t ns, systime_cycles;
6109 struct ixgbe_adapter *adapter =
6110 (struct ixgbe_adapter *)dev->data->dev_private;
6112 systime_cycles = ixgbe_read_systime_cyclecounter(dev);
6113 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
6114 *ts = rte_ns_to_timespec(ns);
6120 ixgbe_timesync_enable(struct rte_eth_dev *dev)
6122 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6126 /* Stop the timesync system time. */
6127 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0x0);
6128 /* Reset the timesync system time value. */
6129 IXGBE_WRITE_REG(hw, IXGBE_SYSTIML, 0x0);
6130 IXGBE_WRITE_REG(hw, IXGBE_SYSTIMH, 0x0);
6132 /* Enable system time for platforms where it isn't on by default. */
6133 tsauxc = IXGBE_READ_REG(hw, IXGBE_TSAUXC);
6134 tsauxc &= ~IXGBE_TSAUXC_DISABLE_SYSTIME;
6135 IXGBE_WRITE_REG(hw, IXGBE_TSAUXC, tsauxc);
6137 ixgbe_start_timecounters(dev);
6139 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
6140 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588),
6142 IXGBE_ETQF_FILTER_EN |
6145 /* Enable timestamping of received PTP packets. */
6146 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
6147 tsync_ctl |= IXGBE_TSYNCRXCTL_ENABLED;
6148 IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
6150 /* Enable timestamping of transmitted PTP packets. */
6151 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
6152 tsync_ctl |= IXGBE_TSYNCTXCTL_ENABLED;
6153 IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
6155 IXGBE_WRITE_FLUSH(hw);
6161 ixgbe_timesync_disable(struct rte_eth_dev *dev)
6163 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6166 /* Disable timestamping of transmitted PTP packets. */
6167 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
6168 tsync_ctl &= ~IXGBE_TSYNCTXCTL_ENABLED;
6169 IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
6171 /* Disable timestamping of received PTP packets. */
6172 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
6173 tsync_ctl &= ~IXGBE_TSYNCRXCTL_ENABLED;
6174 IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
6176 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
6177 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588), 0);
6179 /* Stop incrementating the System Time registers. */
6180 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0);
6186 ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
6187 struct timespec *timestamp,
6188 uint32_t flags __rte_unused)
6190 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6191 struct ixgbe_adapter *adapter =
6192 (struct ixgbe_adapter *)dev->data->dev_private;
6193 uint32_t tsync_rxctl;
6194 uint64_t rx_tstamp_cycles;
6197 tsync_rxctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
6198 if ((tsync_rxctl & IXGBE_TSYNCRXCTL_VALID) == 0)
6201 rx_tstamp_cycles = ixgbe_read_rx_tstamp_cyclecounter(dev);
6202 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
6203 *timestamp = rte_ns_to_timespec(ns);
6209 ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
6210 struct timespec *timestamp)
6212 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6213 struct ixgbe_adapter *adapter =
6214 (struct ixgbe_adapter *)dev->data->dev_private;
6215 uint32_t tsync_txctl;
6216 uint64_t tx_tstamp_cycles;
6219 tsync_txctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
6220 if ((tsync_txctl & IXGBE_TSYNCTXCTL_VALID) == 0)
6223 tx_tstamp_cycles = ixgbe_read_tx_tstamp_cyclecounter(dev);
6224 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
6225 *timestamp = rte_ns_to_timespec(ns);
6231 ixgbe_get_reg_length(struct rte_eth_dev *dev)
6233 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6236 const struct reg_info *reg_group;
6237 const struct reg_info **reg_set = (hw->mac.type == ixgbe_mac_82598EB) ?
6238 ixgbe_regs_mac_82598EB : ixgbe_regs_others;
6240 while ((reg_group = reg_set[g_ind++]))
6241 count += ixgbe_regs_group_count(reg_group);
6247 ixgbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
6251 const struct reg_info *reg_group;
6253 while ((reg_group = ixgbevf_regs[g_ind++]))
6254 count += ixgbe_regs_group_count(reg_group);
6260 ixgbe_get_regs(struct rte_eth_dev *dev,
6261 struct rte_dev_reg_info *regs)
6263 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6264 uint32_t *data = regs->data;
6267 const struct reg_info *reg_group;
6268 const struct reg_info **reg_set = (hw->mac.type == ixgbe_mac_82598EB) ?
6269 ixgbe_regs_mac_82598EB : ixgbe_regs_others;
6271 /* Support only full register dump */
6272 if ((regs->length == 0) ||
6273 (regs->length == (uint32_t)ixgbe_get_reg_length(dev))) {
6274 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
6276 while ((reg_group = reg_set[g_ind++]))
6277 count += ixgbe_read_regs_group(dev, &data[count],
6286 ixgbevf_get_regs(struct rte_eth_dev *dev,
6287 struct rte_dev_reg_info *regs)
6289 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6290 uint32_t *data = regs->data;
6293 const struct reg_info *reg_group;
6295 /* Support only full register dump */
6296 if ((regs->length == 0) ||
6297 (regs->length == (uint32_t)ixgbevf_get_reg_length(dev))) {
6298 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
6300 while ((reg_group = ixgbevf_regs[g_ind++]))
6301 count += ixgbe_read_regs_group(dev, &data[count],
6310 ixgbe_get_eeprom_length(struct rte_eth_dev *dev)
6312 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6314 /* Return unit is byte count */
6315 return hw->eeprom.word_size * 2;
6319 ixgbe_get_eeprom(struct rte_eth_dev *dev,
6320 struct rte_dev_eeprom_info *in_eeprom)
6322 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6323 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
6324 uint16_t *data = in_eeprom->data;
6327 first = in_eeprom->offset >> 1;
6328 length = in_eeprom->length >> 1;
6329 if ((first > hw->eeprom.word_size) ||
6330 ((first + length) > hw->eeprom.word_size))
6333 in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
6335 return eeprom->ops.read_buffer(hw, first, length, data);
6339 ixgbe_set_eeprom(struct rte_eth_dev *dev,
6340 struct rte_dev_eeprom_info *in_eeprom)
6342 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6343 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
6344 uint16_t *data = in_eeprom->data;
6347 first = in_eeprom->offset >> 1;
6348 length = in_eeprom->length >> 1;
6349 if ((first > hw->eeprom.word_size) ||
6350 ((first + length) > hw->eeprom.word_size))
6353 in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
6355 return eeprom->ops.write_buffer(hw, first, length, data);
6359 ixgbe_reta_size_get(enum ixgbe_mac_type mac_type) {
6361 case ixgbe_mac_X550:
6362 case ixgbe_mac_X550EM_x:
6363 case ixgbe_mac_X550EM_a:
6364 return ETH_RSS_RETA_SIZE_512;
6365 case ixgbe_mac_X550_vf:
6366 case ixgbe_mac_X550EM_x_vf:
6367 case ixgbe_mac_X550EM_a_vf:
6368 return ETH_RSS_RETA_SIZE_64;
6370 return ETH_RSS_RETA_SIZE_128;
6375 ixgbe_reta_reg_get(enum ixgbe_mac_type mac_type, uint16_t reta_idx) {
6377 case ixgbe_mac_X550:
6378 case ixgbe_mac_X550EM_x:
6379 case ixgbe_mac_X550EM_a:
6380 if (reta_idx < ETH_RSS_RETA_SIZE_128)
6381 return IXGBE_RETA(reta_idx >> 2);
6383 return IXGBE_ERETA((reta_idx - ETH_RSS_RETA_SIZE_128) >> 2);
6384 case ixgbe_mac_X550_vf:
6385 case ixgbe_mac_X550EM_x_vf:
6386 case ixgbe_mac_X550EM_a_vf:
6387 return IXGBE_VFRETA(reta_idx >> 2);
6389 return IXGBE_RETA(reta_idx >> 2);
6394 ixgbe_mrqc_reg_get(enum ixgbe_mac_type mac_type) {
6396 case ixgbe_mac_X550_vf:
6397 case ixgbe_mac_X550EM_x_vf:
6398 case ixgbe_mac_X550EM_a_vf:
6399 return IXGBE_VFMRQC;
6406 ixgbe_rssrk_reg_get(enum ixgbe_mac_type mac_type, uint8_t i) {
6408 case ixgbe_mac_X550_vf:
6409 case ixgbe_mac_X550EM_x_vf:
6410 case ixgbe_mac_X550EM_a_vf:
6411 return IXGBE_VFRSSRK(i);
6413 return IXGBE_RSSRK(i);
6418 ixgbe_rss_update_sp(enum ixgbe_mac_type mac_type) {
6420 case ixgbe_mac_82599_vf:
6421 case ixgbe_mac_X540_vf:
6429 ixgbe_dev_get_dcb_info(struct rte_eth_dev *dev,
6430 struct rte_eth_dcb_info *dcb_info)
6432 struct ixgbe_dcb_config *dcb_config =
6433 IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
6434 struct ixgbe_dcb_tc_config *tc;
6437 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
6438 dcb_info->nb_tcs = dcb_config->num_tcs.pg_tcs;
6440 dcb_info->nb_tcs = 1;
6442 if (dcb_config->vt_mode) { /* vt is enabled*/
6443 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
6444 &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
6445 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++)
6446 dcb_info->prio_tc[i] = vmdq_rx_conf->dcb_tc[i];
6447 for (i = 0; i < vmdq_rx_conf->nb_queue_pools; i++) {
6448 for (j = 0; j < dcb_info->nb_tcs; j++) {
6449 dcb_info->tc_queue.tc_rxq[i][j].base =
6450 i * dcb_info->nb_tcs + j;
6451 dcb_info->tc_queue.tc_rxq[i][j].nb_queue = 1;
6452 dcb_info->tc_queue.tc_txq[i][j].base =
6453 i * dcb_info->nb_tcs + j;
6454 dcb_info->tc_queue.tc_txq[i][j].nb_queue = 1;
6457 } else { /* vt is disabled*/
6458 struct rte_eth_dcb_rx_conf *rx_conf =
6459 &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
6460 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++)
6461 dcb_info->prio_tc[i] = rx_conf->dcb_tc[i];
6462 if (dcb_info->nb_tcs == ETH_4_TCS) {
6463 for (i = 0; i < dcb_info->nb_tcs; i++) {
6464 dcb_info->tc_queue.tc_rxq[0][i].base = i * 32;
6465 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 16;
6467 dcb_info->tc_queue.tc_txq[0][0].base = 0;
6468 dcb_info->tc_queue.tc_txq[0][1].base = 64;
6469 dcb_info->tc_queue.tc_txq[0][2].base = 96;
6470 dcb_info->tc_queue.tc_txq[0][3].base = 112;
6471 dcb_info->tc_queue.tc_txq[0][0].nb_queue = 64;
6472 dcb_info->tc_queue.tc_txq[0][1].nb_queue = 32;
6473 dcb_info->tc_queue.tc_txq[0][2].nb_queue = 16;
6474 dcb_info->tc_queue.tc_txq[0][3].nb_queue = 16;
6475 } else if (dcb_info->nb_tcs == ETH_8_TCS) {
6476 for (i = 0; i < dcb_info->nb_tcs; i++) {
6477 dcb_info->tc_queue.tc_rxq[0][i].base = i * 16;
6478 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 16;
6480 dcb_info->tc_queue.tc_txq[0][0].base = 0;
6481 dcb_info->tc_queue.tc_txq[0][1].base = 32;
6482 dcb_info->tc_queue.tc_txq[0][2].base = 64;
6483 dcb_info->tc_queue.tc_txq[0][3].base = 80;
6484 dcb_info->tc_queue.tc_txq[0][4].base = 96;
6485 dcb_info->tc_queue.tc_txq[0][5].base = 104;
6486 dcb_info->tc_queue.tc_txq[0][6].base = 112;
6487 dcb_info->tc_queue.tc_txq[0][7].base = 120;
6488 dcb_info->tc_queue.tc_txq[0][0].nb_queue = 32;
6489 dcb_info->tc_queue.tc_txq[0][1].nb_queue = 32;
6490 dcb_info->tc_queue.tc_txq[0][2].nb_queue = 16;
6491 dcb_info->tc_queue.tc_txq[0][3].nb_queue = 16;
6492 dcb_info->tc_queue.tc_txq[0][4].nb_queue = 8;
6493 dcb_info->tc_queue.tc_txq[0][5].nb_queue = 8;
6494 dcb_info->tc_queue.tc_txq[0][6].nb_queue = 8;
6495 dcb_info->tc_queue.tc_txq[0][7].nb_queue = 8;
6498 for (i = 0; i < dcb_info->nb_tcs; i++) {
6499 tc = &dcb_config->tc_config[i];
6500 dcb_info->tc_bws[i] = tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent;
6505 /* Update e-tag ether type */
6507 ixgbe_update_e_tag_eth_type(struct ixgbe_hw *hw,
6508 uint16_t ether_type)
6510 uint32_t etag_etype;
6512 if (hw->mac.type != ixgbe_mac_X550 &&
6513 hw->mac.type != ixgbe_mac_X550EM_x &&
6514 hw->mac.type != ixgbe_mac_X550EM_a) {
6518 etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
6519 etag_etype &= ~IXGBE_ETAG_ETYPE_MASK;
6520 etag_etype |= ether_type;
6521 IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
6522 IXGBE_WRITE_FLUSH(hw);
6527 /* Config l2 tunnel ether type */
6529 ixgbe_dev_l2_tunnel_eth_type_conf(struct rte_eth_dev *dev,
6530 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6533 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6535 if (l2_tunnel == NULL)
6538 switch (l2_tunnel->l2_tunnel_type) {
6539 case RTE_L2_TUNNEL_TYPE_E_TAG:
6540 ret = ixgbe_update_e_tag_eth_type(hw, l2_tunnel->ether_type);
6543 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6551 /* Enable e-tag tunnel */
6553 ixgbe_e_tag_enable(struct ixgbe_hw *hw)
6555 uint32_t etag_etype;
6557 if (hw->mac.type != ixgbe_mac_X550 &&
6558 hw->mac.type != ixgbe_mac_X550EM_x &&
6559 hw->mac.type != ixgbe_mac_X550EM_a) {
6563 etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
6564 etag_etype |= IXGBE_ETAG_ETYPE_VALID;
6565 IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
6566 IXGBE_WRITE_FLUSH(hw);
6571 /* Enable l2 tunnel */
6573 ixgbe_dev_l2_tunnel_enable(struct rte_eth_dev *dev,
6574 enum rte_eth_tunnel_type l2_tunnel_type)
6577 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6579 switch (l2_tunnel_type) {
6580 case RTE_L2_TUNNEL_TYPE_E_TAG:
6581 ret = ixgbe_e_tag_enable(hw);
6584 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6592 /* Disable e-tag tunnel */
6594 ixgbe_e_tag_disable(struct ixgbe_hw *hw)
6596 uint32_t etag_etype;
6598 if (hw->mac.type != ixgbe_mac_X550 &&
6599 hw->mac.type != ixgbe_mac_X550EM_x &&
6600 hw->mac.type != ixgbe_mac_X550EM_a) {
6604 etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
6605 etag_etype &= ~IXGBE_ETAG_ETYPE_VALID;
6606 IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
6607 IXGBE_WRITE_FLUSH(hw);
6612 /* Disable l2 tunnel */
6614 ixgbe_dev_l2_tunnel_disable(struct rte_eth_dev *dev,
6615 enum rte_eth_tunnel_type l2_tunnel_type)
6618 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6620 switch (l2_tunnel_type) {
6621 case RTE_L2_TUNNEL_TYPE_E_TAG:
6622 ret = ixgbe_e_tag_disable(hw);
6625 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6634 ixgbe_e_tag_filter_del(struct rte_eth_dev *dev,
6635 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6638 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6639 uint32_t i, rar_entries;
6640 uint32_t rar_low, rar_high;
6642 if (hw->mac.type != ixgbe_mac_X550 &&
6643 hw->mac.type != ixgbe_mac_X550EM_x &&
6644 hw->mac.type != ixgbe_mac_X550EM_a) {
6648 rar_entries = ixgbe_get_num_rx_addrs(hw);
6650 for (i = 1; i < rar_entries; i++) {
6651 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(i));
6652 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(i));
6653 if ((rar_high & IXGBE_RAH_AV) &&
6654 (rar_high & IXGBE_RAH_ADTYPE) &&
6655 ((rar_low & IXGBE_RAL_ETAG_FILTER_MASK) ==
6656 l2_tunnel->tunnel_id)) {
6657 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
6658 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
6660 ixgbe_clear_vmdq(hw, i, IXGBE_CLEAR_VMDQ_ALL);
6670 ixgbe_e_tag_filter_add(struct rte_eth_dev *dev,
6671 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6674 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6675 uint32_t i, rar_entries;
6676 uint32_t rar_low, rar_high;
6678 if (hw->mac.type != ixgbe_mac_X550 &&
6679 hw->mac.type != ixgbe_mac_X550EM_x &&
6680 hw->mac.type != ixgbe_mac_X550EM_a) {
6684 /* One entry for one tunnel. Try to remove potential existing entry. */
6685 ixgbe_e_tag_filter_del(dev, l2_tunnel);
6687 rar_entries = ixgbe_get_num_rx_addrs(hw);
6689 for (i = 1; i < rar_entries; i++) {
6690 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(i));
6691 if (rar_high & IXGBE_RAH_AV) {
6694 ixgbe_set_vmdq(hw, i, l2_tunnel->pool);
6695 rar_high = IXGBE_RAH_AV | IXGBE_RAH_ADTYPE;
6696 rar_low = l2_tunnel->tunnel_id;
6698 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), rar_low);
6699 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), rar_high);
6705 PMD_INIT_LOG(NOTICE, "The table of E-tag forwarding rule is full."
6706 " Please remove a rule before adding a new one.");
6710 /* Add l2 tunnel filter */
6712 ixgbe_dev_l2_tunnel_filter_add(struct rte_eth_dev *dev,
6713 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6717 switch (l2_tunnel->l2_tunnel_type) {
6718 case RTE_L2_TUNNEL_TYPE_E_TAG:
6719 ret = ixgbe_e_tag_filter_add(dev, l2_tunnel);
6722 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6730 /* Delete l2 tunnel filter */
6732 ixgbe_dev_l2_tunnel_filter_del(struct rte_eth_dev *dev,
6733 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6737 switch (l2_tunnel->l2_tunnel_type) {
6738 case RTE_L2_TUNNEL_TYPE_E_TAG:
6739 ret = ixgbe_e_tag_filter_del(dev, l2_tunnel);
6742 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6751 * ixgbe_dev_l2_tunnel_filter_handle - Handle operations for l2 tunnel filter.
6752 * @dev: pointer to rte_eth_dev structure
6753 * @filter_op:operation will be taken.
6754 * @arg: a pointer to specific structure corresponding to the filter_op
6757 ixgbe_dev_l2_tunnel_filter_handle(struct rte_eth_dev *dev,
6758 enum rte_filter_op filter_op,
6763 if (filter_op == RTE_ETH_FILTER_NOP)
6767 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
6772 switch (filter_op) {
6773 case RTE_ETH_FILTER_ADD:
6774 ret = ixgbe_dev_l2_tunnel_filter_add
6776 (struct rte_eth_l2_tunnel_conf *)arg);
6778 case RTE_ETH_FILTER_DELETE:
6779 ret = ixgbe_dev_l2_tunnel_filter_del
6781 (struct rte_eth_l2_tunnel_conf *)arg);
6784 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
6792 ixgbe_e_tag_forwarding_en_dis(struct rte_eth_dev *dev, bool en)
6796 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6798 if (hw->mac.type != ixgbe_mac_X550 &&
6799 hw->mac.type != ixgbe_mac_X550EM_x &&
6800 hw->mac.type != ixgbe_mac_X550EM_a) {
6804 ctrl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
6805 ctrl &= ~IXGBE_VT_CTL_POOLING_MODE_MASK;
6807 ctrl |= IXGBE_VT_CTL_POOLING_MODE_ETAG;
6808 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, ctrl);
6813 /* Enable l2 tunnel forwarding */
6815 ixgbe_dev_l2_tunnel_forwarding_enable
6816 (struct rte_eth_dev *dev,
6817 enum rte_eth_tunnel_type l2_tunnel_type)
6821 switch (l2_tunnel_type) {
6822 case RTE_L2_TUNNEL_TYPE_E_TAG:
6823 ret = ixgbe_e_tag_forwarding_en_dis(dev, 1);
6826 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6834 /* Disable l2 tunnel forwarding */
6836 ixgbe_dev_l2_tunnel_forwarding_disable
6837 (struct rte_eth_dev *dev,
6838 enum rte_eth_tunnel_type l2_tunnel_type)
6842 switch (l2_tunnel_type) {
6843 case RTE_L2_TUNNEL_TYPE_E_TAG:
6844 ret = ixgbe_e_tag_forwarding_en_dis(dev, 0);
6847 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6856 ixgbe_e_tag_insertion_en_dis(struct rte_eth_dev *dev,
6857 struct rte_eth_l2_tunnel_conf *l2_tunnel,
6861 uint32_t vmtir, vmvir;
6862 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6864 if (l2_tunnel->vf_id >= dev->pci_dev->max_vfs) {
6866 "VF id %u should be less than %u",
6868 dev->pci_dev->max_vfs);
6872 if (hw->mac.type != ixgbe_mac_X550 &&
6873 hw->mac.type != ixgbe_mac_X550EM_x &&
6874 hw->mac.type != ixgbe_mac_X550EM_a) {
6879 vmtir = l2_tunnel->tunnel_id;
6883 IXGBE_WRITE_REG(hw, IXGBE_VMTIR(l2_tunnel->vf_id), vmtir);
6885 vmvir = IXGBE_READ_REG(hw, IXGBE_VMVIR(l2_tunnel->vf_id));
6886 vmvir &= ~IXGBE_VMVIR_TAGA_MASK;
6888 vmvir |= IXGBE_VMVIR_TAGA_ETAG_INSERT;
6889 IXGBE_WRITE_REG(hw, IXGBE_VMVIR(l2_tunnel->vf_id), vmvir);
6894 /* Enable l2 tunnel tag insertion */
6896 ixgbe_dev_l2_tunnel_insertion_enable(struct rte_eth_dev *dev,
6897 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6901 switch (l2_tunnel->l2_tunnel_type) {
6902 case RTE_L2_TUNNEL_TYPE_E_TAG:
6903 ret = ixgbe_e_tag_insertion_en_dis(dev, l2_tunnel, 1);
6906 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6914 /* Disable l2 tunnel tag insertion */
6916 ixgbe_dev_l2_tunnel_insertion_disable
6917 (struct rte_eth_dev *dev,
6918 struct rte_eth_l2_tunnel_conf *l2_tunnel)
6922 switch (l2_tunnel->l2_tunnel_type) {
6923 case RTE_L2_TUNNEL_TYPE_E_TAG:
6924 ret = ixgbe_e_tag_insertion_en_dis(dev, l2_tunnel, 0);
6927 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6936 ixgbe_e_tag_stripping_en_dis(struct rte_eth_dev *dev,
6941 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6943 if (hw->mac.type != ixgbe_mac_X550 &&
6944 hw->mac.type != ixgbe_mac_X550EM_x &&
6945 hw->mac.type != ixgbe_mac_X550EM_a) {
6949 qde = IXGBE_READ_REG(hw, IXGBE_QDE);
6951 qde |= IXGBE_QDE_STRIP_TAG;
6953 qde &= ~IXGBE_QDE_STRIP_TAG;
6954 qde &= ~IXGBE_QDE_READ;
6955 qde |= IXGBE_QDE_WRITE;
6956 IXGBE_WRITE_REG(hw, IXGBE_QDE, qde);
6961 /* Enable l2 tunnel tag stripping */
6963 ixgbe_dev_l2_tunnel_stripping_enable
6964 (struct rte_eth_dev *dev,
6965 enum rte_eth_tunnel_type l2_tunnel_type)
6969 switch (l2_tunnel_type) {
6970 case RTE_L2_TUNNEL_TYPE_E_TAG:
6971 ret = ixgbe_e_tag_stripping_en_dis(dev, 1);
6974 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6982 /* Disable l2 tunnel tag stripping */
6984 ixgbe_dev_l2_tunnel_stripping_disable
6985 (struct rte_eth_dev *dev,
6986 enum rte_eth_tunnel_type l2_tunnel_type)
6990 switch (l2_tunnel_type) {
6991 case RTE_L2_TUNNEL_TYPE_E_TAG:
6992 ret = ixgbe_e_tag_stripping_en_dis(dev, 0);
6995 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7003 /* Enable/disable l2 tunnel offload functions */
7005 ixgbe_dev_l2_tunnel_offload_set
7006 (struct rte_eth_dev *dev,
7007 struct rte_eth_l2_tunnel_conf *l2_tunnel,
7013 if (l2_tunnel == NULL)
7017 if (mask & ETH_L2_TUNNEL_ENABLE_MASK) {
7019 ret = ixgbe_dev_l2_tunnel_enable(
7021 l2_tunnel->l2_tunnel_type);
7023 ret = ixgbe_dev_l2_tunnel_disable(
7025 l2_tunnel->l2_tunnel_type);
7028 if (mask & ETH_L2_TUNNEL_INSERTION_MASK) {
7030 ret = ixgbe_dev_l2_tunnel_insertion_enable(
7034 ret = ixgbe_dev_l2_tunnel_insertion_disable(
7039 if (mask & ETH_L2_TUNNEL_STRIPPING_MASK) {
7041 ret = ixgbe_dev_l2_tunnel_stripping_enable(
7043 l2_tunnel->l2_tunnel_type);
7045 ret = ixgbe_dev_l2_tunnel_stripping_disable(
7047 l2_tunnel->l2_tunnel_type);
7050 if (mask & ETH_L2_TUNNEL_FORWARDING_MASK) {
7052 ret = ixgbe_dev_l2_tunnel_forwarding_enable(
7054 l2_tunnel->l2_tunnel_type);
7056 ret = ixgbe_dev_l2_tunnel_forwarding_disable(
7058 l2_tunnel->l2_tunnel_type);
7065 ixgbe_update_vxlan_port(struct ixgbe_hw *hw,
7068 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, port);
7069 IXGBE_WRITE_FLUSH(hw);
7074 /* There's only one register for VxLAN UDP port.
7075 * So, we cannot add several ports. Will update it.
7078 ixgbe_add_vxlan_port(struct ixgbe_hw *hw,
7082 PMD_DRV_LOG(ERR, "Add VxLAN port 0 is not allowed.");
7086 return ixgbe_update_vxlan_port(hw, port);
7089 /* We cannot delete the VxLAN port. For there's a register for VxLAN
7090 * UDP port, it must have a value.
7091 * So, will reset it to the original value 0.
7094 ixgbe_del_vxlan_port(struct ixgbe_hw *hw,
7099 cur_port = (uint16_t)IXGBE_READ_REG(hw, IXGBE_VXLANCTRL);
7101 if (cur_port != port) {
7102 PMD_DRV_LOG(ERR, "Port %u does not exist.", port);
7106 return ixgbe_update_vxlan_port(hw, 0);
7109 /* Add UDP tunneling port */
7111 ixgbe_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
7112 struct rte_eth_udp_tunnel *udp_tunnel)
7115 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7117 if (hw->mac.type != ixgbe_mac_X550 &&
7118 hw->mac.type != ixgbe_mac_X550EM_x &&
7119 hw->mac.type != ixgbe_mac_X550EM_a) {
7123 if (udp_tunnel == NULL)
7126 switch (udp_tunnel->prot_type) {
7127 case RTE_TUNNEL_TYPE_VXLAN:
7128 ret = ixgbe_add_vxlan_port(hw, udp_tunnel->udp_port);
7131 case RTE_TUNNEL_TYPE_GENEVE:
7132 case RTE_TUNNEL_TYPE_TEREDO:
7133 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
7138 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7146 /* Remove UDP tunneling port */
7148 ixgbe_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
7149 struct rte_eth_udp_tunnel *udp_tunnel)
7152 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7154 if (hw->mac.type != ixgbe_mac_X550 &&
7155 hw->mac.type != ixgbe_mac_X550EM_x &&
7156 hw->mac.type != ixgbe_mac_X550EM_a) {
7160 if (udp_tunnel == NULL)
7163 switch (udp_tunnel->prot_type) {
7164 case RTE_TUNNEL_TYPE_VXLAN:
7165 ret = ixgbe_del_vxlan_port(hw, udp_tunnel->udp_port);
7167 case RTE_TUNNEL_TYPE_GENEVE:
7168 case RTE_TUNNEL_TYPE_TEREDO:
7169 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
7173 PMD_DRV_LOG(ERR, "Invalid tunnel type");
7181 /* ixgbevf_update_xcast_mode - Update Multicast mode
7182 * @hw: pointer to the HW structure
7183 * @netdev: pointer to net device structure
7184 * @xcast_mode: new multicast mode
7186 * Updates the Multicast Mode of VF.
7188 static int ixgbevf_update_xcast_mode(struct ixgbe_hw *hw,
7191 struct ixgbe_mbx_info *mbx = &hw->mbx;
7195 switch (hw->api_version) {
7196 case ixgbe_mbox_api_12:
7202 msgbuf[0] = IXGBE_VF_UPDATE_XCAST_MODE;
7203 msgbuf[1] = xcast_mode;
7205 err = mbx->ops.write_posted(hw, msgbuf, 2, 0);
7209 err = mbx->ops.read_posted(hw, msgbuf, 2, 0);
7213 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
7214 if (msgbuf[0] == (IXGBE_VF_UPDATE_XCAST_MODE | IXGBE_VT_MSGTYPE_NACK))
7221 ixgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
7223 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7225 ixgbevf_update_xcast_mode(hw, IXGBEVF_XCAST_MODE_ALLMULTI);
7229 ixgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
7231 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7233 ixgbevf_update_xcast_mode(hw, IXGBEVF_XCAST_MODE_NONE);
7236 static struct rte_driver rte_ixgbe_driver = {
7238 .init = rte_ixgbe_pmd_init,
7241 static struct rte_driver rte_ixgbevf_driver = {
7243 .init = rte_ixgbevf_pmd_init,
7246 PMD_REGISTER_DRIVER(rte_ixgbe_driver);
7247 PMD_REGISTER_DRIVER(rte_ixgbevf_driver);