4 * Copyright(c) 2010-2014 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>
55 #include <rte_tailq.h>
57 #include <rte_alarm.h>
58 #include <rte_ether.h>
59 #include <rte_ethdev.h>
60 #include <rte_atomic.h>
61 #include <rte_malloc.h>
62 #include <rte_random.h>
65 #include "ixgbe_logs.h"
66 #include "ixgbe/ixgbe_api.h"
67 #include "ixgbe/ixgbe_vf.h"
68 #include "ixgbe/ixgbe_common.h"
69 #include "ixgbe_ethdev.h"
70 #include "ixgbe_bypass.h"
71 #include "ixgbe_rxtx.h"
74 * High threshold controlling when to start sending XOFF frames. Must be at
75 * least 8 bytes less than receive packet buffer size. This value is in units
78 #define IXGBE_FC_HI 0x80
81 * Low threshold controlling when to start sending XON frames. This value is
82 * in units of 1024 bytes.
84 #define IXGBE_FC_LO 0x40
86 /* Timer value included in XOFF frames. */
87 #define IXGBE_FC_PAUSE 0x680
89 #define IXGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
90 #define IXGBE_LINK_UP_CHECK_TIMEOUT 1000 /* ms */
91 #define IXGBE_VMDQ_NUM_UC_MAC 4096 /* Maximum nb. of UC MAC addr. */
93 #define IXGBE_MMW_SIZE_DEFAULT 0x4
94 #define IXGBE_MMW_SIZE_JUMBO_FRAME 0x14
97 * Default values for RX/TX configuration
99 #define IXGBE_DEFAULT_RX_FREE_THRESH 32
100 #define IXGBE_DEFAULT_RX_PTHRESH 8
101 #define IXGBE_DEFAULT_RX_HTHRESH 8
102 #define IXGBE_DEFAULT_RX_WTHRESH 0
104 #define IXGBE_DEFAULT_TX_FREE_THRESH 32
105 #define IXGBE_DEFAULT_TX_PTHRESH 32
106 #define IXGBE_DEFAULT_TX_HTHRESH 0
107 #define IXGBE_DEFAULT_TX_WTHRESH 0
108 #define IXGBE_DEFAULT_TX_RSBIT_THRESH 32
110 /* Bit shift and mask */
111 #define IXGBE_4_BIT_WIDTH (CHAR_BIT / 2)
112 #define IXGBE_4_BIT_MASK RTE_LEN2MASK(IXGBE_4_BIT_WIDTH, uint8_t)
113 #define IXGBE_8_BIT_WIDTH CHAR_BIT
114 #define IXGBE_8_BIT_MASK UINT8_MAX
116 #define IXGBEVF_PMD_NAME "rte_ixgbevf_pmd" /* PMD name */
118 #define IXGBE_QUEUE_STAT_COUNTERS (sizeof(hw_stats->qprc) / sizeof(hw_stats->qprc[0]))
120 static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev);
121 static int ixgbe_dev_configure(struct rte_eth_dev *dev);
122 static int ixgbe_dev_start(struct rte_eth_dev *dev);
123 static void ixgbe_dev_stop(struct rte_eth_dev *dev);
124 static int ixgbe_dev_set_link_up(struct rte_eth_dev *dev);
125 static int ixgbe_dev_set_link_down(struct rte_eth_dev *dev);
126 static void ixgbe_dev_close(struct rte_eth_dev *dev);
127 static void ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
128 static void ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
129 static void ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
130 static void ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev);
131 static int ixgbe_dev_link_update(struct rte_eth_dev *dev,
132 int wait_to_complete);
133 static void ixgbe_dev_stats_get(struct rte_eth_dev *dev,
134 struct rte_eth_stats *stats);
135 static void ixgbe_dev_stats_reset(struct rte_eth_dev *dev);
136 static int ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
140 static void ixgbe_dev_info_get(struct rte_eth_dev *dev,
141 struct rte_eth_dev_info *dev_info);
142 static void ixgbevf_dev_info_get(struct rte_eth_dev *dev,
143 struct rte_eth_dev_info *dev_info);
144 static int ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
146 static int ixgbe_vlan_filter_set(struct rte_eth_dev *dev,
147 uint16_t vlan_id, int on);
148 static void ixgbe_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid_id);
149 static void ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
150 uint16_t queue, bool on);
151 static void ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue,
153 static void ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask);
154 static void ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue);
155 static void ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue);
156 static void ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev);
157 static void ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev);
159 static int ixgbe_dev_led_on(struct rte_eth_dev *dev);
160 static int ixgbe_dev_led_off(struct rte_eth_dev *dev);
161 static int ixgbe_flow_ctrl_get(struct rte_eth_dev *dev,
162 struct rte_eth_fc_conf *fc_conf);
163 static int ixgbe_flow_ctrl_set(struct rte_eth_dev *dev,
164 struct rte_eth_fc_conf *fc_conf);
165 static int ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev,
166 struct rte_eth_pfc_conf *pfc_conf);
167 static int ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
168 struct rte_eth_rss_reta_entry64 *reta_conf,
170 static int ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
171 struct rte_eth_rss_reta_entry64 *reta_conf,
173 static void ixgbe_dev_link_status_print(struct rte_eth_dev *dev);
174 static int ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev);
175 static int ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev);
176 static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev);
177 static void ixgbe_dev_interrupt_handler(struct rte_intr_handle *handle,
179 static void ixgbe_dev_interrupt_delayed_handler(void *param);
180 static void ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
181 uint32_t index, uint32_t pool);
182 static void ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index);
183 static void ixgbe_dcb_init(struct ixgbe_hw *hw,struct ixgbe_dcb_config *dcb_config);
185 /* For Virtual Function support */
186 static int eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev);
187 static int ixgbevf_dev_configure(struct rte_eth_dev *dev);
188 static int ixgbevf_dev_start(struct rte_eth_dev *dev);
189 static void ixgbevf_dev_stop(struct rte_eth_dev *dev);
190 static void ixgbevf_dev_close(struct rte_eth_dev *dev);
191 static void ixgbevf_intr_disable(struct ixgbe_hw *hw);
192 static void ixgbevf_dev_stats_get(struct rte_eth_dev *dev,
193 struct rte_eth_stats *stats);
194 static void ixgbevf_dev_stats_reset(struct rte_eth_dev *dev);
195 static int ixgbevf_vlan_filter_set(struct rte_eth_dev *dev,
196 uint16_t vlan_id, int on);
197 static void ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev,
198 uint16_t queue, int on);
199 static void ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
200 static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
202 /* For Eth VMDQ APIs support */
203 static int ixgbe_uc_hash_table_set(struct rte_eth_dev *dev, struct
204 ether_addr* mac_addr,uint8_t on);
205 static int ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev,uint8_t on);
206 static int ixgbe_set_pool_rx_mode(struct rte_eth_dev *dev, uint16_t pool,
207 uint16_t rx_mask, uint8_t on);
208 static int ixgbe_set_pool_rx(struct rte_eth_dev *dev,uint16_t pool,uint8_t on);
209 static int ixgbe_set_pool_tx(struct rte_eth_dev *dev,uint16_t pool,uint8_t on);
210 static int ixgbe_set_pool_vlan_filter(struct rte_eth_dev *dev, uint16_t vlan,
211 uint64_t pool_mask,uint8_t vlan_on);
212 static int ixgbe_mirror_rule_set(struct rte_eth_dev *dev,
213 struct rte_eth_vmdq_mirror_conf *mirror_conf,
214 uint8_t rule_id, uint8_t on);
215 static int ixgbe_mirror_rule_reset(struct rte_eth_dev *dev,
218 static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
219 uint16_t queue_idx, uint16_t tx_rate);
220 static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
221 uint16_t tx_rate, uint64_t q_msk);
223 static void ixgbevf_add_mac_addr(struct rte_eth_dev *dev,
224 struct ether_addr *mac_addr,
225 uint32_t index, uint32_t pool);
226 static void ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
227 static int ixgbe_syn_filter_set(struct rte_eth_dev *dev,
228 struct rte_eth_syn_filter *filter,
230 static int ixgbe_syn_filter_get(struct rte_eth_dev *dev,
231 struct rte_eth_syn_filter *filter);
232 static int ixgbe_syn_filter_handle(struct rte_eth_dev *dev,
233 enum rte_filter_op filter_op,
235 static int ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
236 struct ixgbe_5tuple_filter *filter);
237 static void ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
238 struct ixgbe_5tuple_filter *filter);
239 static int ixgbe_add_del_ntuple_filter(struct rte_eth_dev *dev,
240 struct rte_eth_ntuple_filter *filter,
242 static int ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
243 enum rte_filter_op filter_op,
245 static int ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
246 struct rte_eth_ntuple_filter *filter);
247 static int ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
248 struct rte_eth_ethertype_filter *filter,
250 static int ixgbe_ethertype_filter_handle(struct rte_eth_dev *dev,
251 enum rte_filter_op filter_op,
253 static int ixgbe_get_ethertype_filter(struct rte_eth_dev *dev,
254 struct rte_eth_ethertype_filter *filter);
255 static int ixgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
256 enum rte_filter_type filter_type,
257 enum rte_filter_op filter_op,
259 static int ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
262 * Define VF Stats MACRO for Non "cleared on read" register
264 #define UPDATE_VF_STAT(reg, last, cur) \
266 u32 latest = IXGBE_READ_REG(hw, reg); \
267 cur += latest - last; \
271 #define UPDATE_VF_STAT_36BIT(lsb, msb, last, cur) \
273 u64 new_lsb = IXGBE_READ_REG(hw, lsb); \
274 u64 new_msb = IXGBE_READ_REG(hw, msb); \
275 u64 latest = ((new_msb << 32) | new_lsb); \
276 cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \
280 #define IXGBE_SET_HWSTRIP(h, q) do{\
281 uint32_t idx = (q) / (sizeof ((h)->bitmap[0]) * NBBY); \
282 uint32_t bit = (q) % (sizeof ((h)->bitmap[0]) * NBBY); \
283 (h)->bitmap[idx] |= 1 << bit;\
286 #define IXGBE_CLEAR_HWSTRIP(h, q) do{\
287 uint32_t idx = (q) / (sizeof ((h)->bitmap[0]) * NBBY); \
288 uint32_t bit = (q) % (sizeof ((h)->bitmap[0]) * NBBY); \
289 (h)->bitmap[idx] &= ~(1 << bit);\
292 #define IXGBE_GET_HWSTRIP(h, q, r) do{\
293 uint32_t idx = (q) / (sizeof ((h)->bitmap[0]) * NBBY); \
294 uint32_t bit = (q) % (sizeof ((h)->bitmap[0]) * NBBY); \
295 (r) = (h)->bitmap[idx] >> bit & 1;\
299 * The set of PCI devices this driver supports
301 static struct rte_pci_id pci_id_ixgbe_map[] = {
303 #define RTE_PCI_DEV_ID_DECL_IXGBE(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
304 #include "rte_pci_dev_ids.h"
306 { .vendor_id = 0, /* sentinel */ },
311 * The set of PCI devices this driver supports (for 82599 VF)
313 static struct rte_pci_id pci_id_ixgbevf_map[] = {
315 #define RTE_PCI_DEV_ID_DECL_IXGBEVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
316 #include "rte_pci_dev_ids.h"
317 { .vendor_id = 0, /* sentinel */ },
321 static struct eth_dev_ops ixgbe_eth_dev_ops = {
322 .dev_configure = ixgbe_dev_configure,
323 .dev_start = ixgbe_dev_start,
324 .dev_stop = ixgbe_dev_stop,
325 .dev_set_link_up = ixgbe_dev_set_link_up,
326 .dev_set_link_down = ixgbe_dev_set_link_down,
327 .dev_close = ixgbe_dev_close,
328 .promiscuous_enable = ixgbe_dev_promiscuous_enable,
329 .promiscuous_disable = ixgbe_dev_promiscuous_disable,
330 .allmulticast_enable = ixgbe_dev_allmulticast_enable,
331 .allmulticast_disable = ixgbe_dev_allmulticast_disable,
332 .link_update = ixgbe_dev_link_update,
333 .stats_get = ixgbe_dev_stats_get,
334 .stats_reset = ixgbe_dev_stats_reset,
335 .queue_stats_mapping_set = ixgbe_dev_queue_stats_mapping_set,
336 .dev_infos_get = ixgbe_dev_info_get,
337 .mtu_set = ixgbe_dev_mtu_set,
338 .vlan_filter_set = ixgbe_vlan_filter_set,
339 .vlan_tpid_set = ixgbe_vlan_tpid_set,
340 .vlan_offload_set = ixgbe_vlan_offload_set,
341 .vlan_strip_queue_set = ixgbe_vlan_strip_queue_set,
342 .rx_queue_start = ixgbe_dev_rx_queue_start,
343 .rx_queue_stop = ixgbe_dev_rx_queue_stop,
344 .tx_queue_start = ixgbe_dev_tx_queue_start,
345 .tx_queue_stop = ixgbe_dev_tx_queue_stop,
346 .rx_queue_setup = ixgbe_dev_rx_queue_setup,
347 .rx_queue_release = ixgbe_dev_rx_queue_release,
348 .rx_queue_count = ixgbe_dev_rx_queue_count,
349 .rx_descriptor_done = ixgbe_dev_rx_descriptor_done,
350 .tx_queue_setup = ixgbe_dev_tx_queue_setup,
351 .tx_queue_release = ixgbe_dev_tx_queue_release,
352 .dev_led_on = ixgbe_dev_led_on,
353 .dev_led_off = ixgbe_dev_led_off,
354 .flow_ctrl_get = ixgbe_flow_ctrl_get,
355 .flow_ctrl_set = ixgbe_flow_ctrl_set,
356 .priority_flow_ctrl_set = ixgbe_priority_flow_ctrl_set,
357 .mac_addr_add = ixgbe_add_rar,
358 .mac_addr_remove = ixgbe_remove_rar,
359 .uc_hash_table_set = ixgbe_uc_hash_table_set,
360 .uc_all_hash_table_set = ixgbe_uc_all_hash_table_set,
361 .mirror_rule_set = ixgbe_mirror_rule_set,
362 .mirror_rule_reset = ixgbe_mirror_rule_reset,
363 .set_vf_rx_mode = ixgbe_set_pool_rx_mode,
364 .set_vf_rx = ixgbe_set_pool_rx,
365 .set_vf_tx = ixgbe_set_pool_tx,
366 .set_vf_vlan_filter = ixgbe_set_pool_vlan_filter,
367 .set_queue_rate_limit = ixgbe_set_queue_rate_limit,
368 .set_vf_rate_limit = ixgbe_set_vf_rate_limit,
369 .reta_update = ixgbe_dev_rss_reta_update,
370 .reta_query = ixgbe_dev_rss_reta_query,
371 #ifdef RTE_NIC_BYPASS
372 .bypass_init = ixgbe_bypass_init,
373 .bypass_state_set = ixgbe_bypass_state_store,
374 .bypass_state_show = ixgbe_bypass_state_show,
375 .bypass_event_set = ixgbe_bypass_event_store,
376 .bypass_event_show = ixgbe_bypass_event_show,
377 .bypass_wd_timeout_set = ixgbe_bypass_wd_timeout_store,
378 .bypass_wd_timeout_show = ixgbe_bypass_wd_timeout_show,
379 .bypass_ver_show = ixgbe_bypass_ver_show,
380 .bypass_wd_reset = ixgbe_bypass_wd_reset,
381 #endif /* RTE_NIC_BYPASS */
382 .rss_hash_update = ixgbe_dev_rss_hash_update,
383 .rss_hash_conf_get = ixgbe_dev_rss_hash_conf_get,
384 .filter_ctrl = ixgbe_dev_filter_ctrl,
388 * dev_ops for virtual function, bare necessities for basic vf
389 * operation have been implemented
391 static struct eth_dev_ops ixgbevf_eth_dev_ops = {
393 .dev_configure = ixgbevf_dev_configure,
394 .dev_start = ixgbevf_dev_start,
395 .dev_stop = ixgbevf_dev_stop,
396 .link_update = ixgbe_dev_link_update,
397 .stats_get = ixgbevf_dev_stats_get,
398 .stats_reset = ixgbevf_dev_stats_reset,
399 .dev_close = ixgbevf_dev_close,
400 .dev_infos_get = ixgbevf_dev_info_get,
401 .mtu_set = ixgbevf_dev_set_mtu,
402 .vlan_filter_set = ixgbevf_vlan_filter_set,
403 .vlan_strip_queue_set = ixgbevf_vlan_strip_queue_set,
404 .vlan_offload_set = ixgbevf_vlan_offload_set,
405 .rx_queue_setup = ixgbe_dev_rx_queue_setup,
406 .rx_queue_release = ixgbe_dev_rx_queue_release,
407 .tx_queue_setup = ixgbe_dev_tx_queue_setup,
408 .tx_queue_release = ixgbe_dev_tx_queue_release,
409 .mac_addr_add = ixgbevf_add_mac_addr,
410 .mac_addr_remove = ixgbevf_remove_mac_addr,
414 * Atomically reads the link status information from global
415 * structure rte_eth_dev.
418 * - Pointer to the structure rte_eth_dev to read from.
419 * - Pointer to the buffer to be saved with the link status.
422 * - On success, zero.
423 * - On failure, negative value.
426 rte_ixgbe_dev_atomic_read_link_status(struct rte_eth_dev *dev,
427 struct rte_eth_link *link)
429 struct rte_eth_link *dst = link;
430 struct rte_eth_link *src = &(dev->data->dev_link);
432 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
433 *(uint64_t *)src) == 0)
440 * Atomically writes the link status information into global
441 * structure rte_eth_dev.
444 * - Pointer to the structure rte_eth_dev to read from.
445 * - Pointer to the buffer to be saved with the link status.
448 * - On success, zero.
449 * - On failure, negative value.
452 rte_ixgbe_dev_atomic_write_link_status(struct rte_eth_dev *dev,
453 struct rte_eth_link *link)
455 struct rte_eth_link *dst = &(dev->data->dev_link);
456 struct rte_eth_link *src = link;
458 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
459 *(uint64_t *)src) == 0)
466 * This function is the same as ixgbe_is_sfp() in ixgbe/ixgbe.h.
469 ixgbe_is_sfp(struct ixgbe_hw *hw)
471 switch (hw->phy.type) {
472 case ixgbe_phy_sfp_avago:
473 case ixgbe_phy_sfp_ftl:
474 case ixgbe_phy_sfp_intel:
475 case ixgbe_phy_sfp_unknown:
476 case ixgbe_phy_sfp_passive_tyco:
477 case ixgbe_phy_sfp_passive_unknown:
484 static inline int32_t
485 ixgbe_pf_reset_hw(struct ixgbe_hw *hw)
490 status = ixgbe_reset_hw(hw);
492 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
493 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
494 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
495 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
496 IXGBE_WRITE_FLUSH(hw);
502 ixgbe_enable_intr(struct rte_eth_dev *dev)
504 struct ixgbe_interrupt *intr =
505 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
506 struct ixgbe_hw *hw =
507 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
509 IXGBE_WRITE_REG(hw, IXGBE_EIMS, intr->mask);
510 IXGBE_WRITE_FLUSH(hw);
514 * This function is based on ixgbe_disable_intr() in ixgbe/ixgbe.h.
517 ixgbe_disable_intr(struct ixgbe_hw *hw)
519 PMD_INIT_FUNC_TRACE();
521 if (hw->mac.type == ixgbe_mac_82598EB) {
522 IXGBE_WRITE_REG(hw, IXGBE_EIMC, ~0);
524 IXGBE_WRITE_REG(hw, IXGBE_EIMC, 0xFFFF0000);
525 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), ~0);
526 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), ~0);
528 IXGBE_WRITE_FLUSH(hw);
532 * This function resets queue statistics mapping registers.
533 * From Niantic datasheet, Initialization of Statistics section:
534 * "...if software requires the queue counters, the RQSMR and TQSM registers
535 * must be re-programmed following a device reset.
538 ixgbe_reset_qstat_mappings(struct ixgbe_hw *hw)
542 for(i = 0; i != IXGBE_NB_STAT_MAPPING_REGS; i++) {
543 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), 0);
544 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), 0);
550 ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
555 #define QSM_REG_NB_BITS_PER_QMAP_FIELD 8
556 #define NB_QMAP_FIELDS_PER_QSM_REG 4
557 #define QMAP_FIELD_RESERVED_BITS_MASK 0x0f
559 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
560 struct ixgbe_stat_mapping_registers *stat_mappings =
561 IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(eth_dev->data->dev_private);
562 uint32_t qsmr_mask = 0;
563 uint32_t clearing_mask = QMAP_FIELD_RESERVED_BITS_MASK;
567 if ((hw->mac.type != ixgbe_mac_82599EB) &&
568 (hw->mac.type != ixgbe_mac_X540) &&
569 (hw->mac.type != ixgbe_mac_X550) &&
570 (hw->mac.type != ixgbe_mac_X550EM_x))
573 PMD_INIT_LOG(INFO, "Setting port %d, %s queue_id %d to stat index %d",
574 (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
577 n = (uint8_t)(queue_id / NB_QMAP_FIELDS_PER_QSM_REG);
578 if (n >= IXGBE_NB_STAT_MAPPING_REGS) {
579 PMD_INIT_LOG(ERR, "Nb of stat mapping registers exceeded");
582 offset = (uint8_t)(queue_id % NB_QMAP_FIELDS_PER_QSM_REG);
584 /* Now clear any previous stat_idx set */
585 clearing_mask <<= (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
587 stat_mappings->tqsm[n] &= ~clearing_mask;
589 stat_mappings->rqsmr[n] &= ~clearing_mask;
591 q_map = (uint32_t)stat_idx;
592 q_map &= QMAP_FIELD_RESERVED_BITS_MASK;
593 qsmr_mask = q_map << (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
595 stat_mappings->tqsm[n] |= qsmr_mask;
597 stat_mappings->rqsmr[n] |= qsmr_mask;
599 PMD_INIT_LOG(INFO, "Set port %d, %s queue_id %d to stat index %d",
600 (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
602 PMD_INIT_LOG(INFO, "%s[%d] = 0x%08x", is_rx ? "RQSMR" : "TQSM", n,
603 is_rx ? stat_mappings->rqsmr[n] : stat_mappings->tqsm[n]);
605 /* Now write the mapping in the appropriate register */
607 PMD_INIT_LOG(INFO, "Write 0x%x to RX IXGBE stat mapping reg:%d",
608 stat_mappings->rqsmr[n], n);
609 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(n), stat_mappings->rqsmr[n]);
612 PMD_INIT_LOG(INFO, "Write 0x%x to TX IXGBE stat mapping reg:%d",
613 stat_mappings->tqsm[n], n);
614 IXGBE_WRITE_REG(hw, IXGBE_TQSM(n), stat_mappings->tqsm[n]);
620 ixgbe_restore_statistics_mapping(struct rte_eth_dev * dev)
622 struct ixgbe_stat_mapping_registers *stat_mappings =
623 IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(dev->data->dev_private);
624 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
627 /* write whatever was in stat mapping table to the NIC */
628 for (i = 0; i < IXGBE_NB_STAT_MAPPING_REGS; i++) {
630 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), stat_mappings->rqsmr[i]);
633 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), stat_mappings->tqsm[i]);
638 ixgbe_dcb_init(struct ixgbe_hw *hw,struct ixgbe_dcb_config *dcb_config)
641 struct ixgbe_dcb_tc_config *tc;
642 uint8_t dcb_max_tc = IXGBE_DCB_MAX_TRAFFIC_CLASS;
644 dcb_config->num_tcs.pg_tcs = dcb_max_tc;
645 dcb_config->num_tcs.pfc_tcs = dcb_max_tc;
646 for (i = 0; i < dcb_max_tc; i++) {
647 tc = &dcb_config->tc_config[i];
648 tc->path[IXGBE_DCB_TX_CONFIG].bwg_id = i;
649 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
650 (uint8_t)(100/dcb_max_tc + (i & 1));
651 tc->path[IXGBE_DCB_RX_CONFIG].bwg_id = i;
652 tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
653 (uint8_t)(100/dcb_max_tc + (i & 1));
654 tc->pfc = ixgbe_dcb_pfc_disabled;
657 /* Initialize default user to priority mapping, UPx->TC0 */
658 tc = &dcb_config->tc_config[0];
659 tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
660 tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
661 for (i = 0; i< IXGBE_DCB_MAX_BW_GROUP; i++) {
662 dcb_config->bw_percentage[IXGBE_DCB_TX_CONFIG][i] = 100;
663 dcb_config->bw_percentage[IXGBE_DCB_RX_CONFIG][i] = 100;
665 dcb_config->rx_pba_cfg = ixgbe_dcb_pba_equal;
666 dcb_config->pfc_mode_enable = false;
667 dcb_config->vt_mode = true;
668 dcb_config->round_robin_enable = false;
669 /* support all DCB capabilities in 82599 */
670 dcb_config->support.capabilities = 0xFF;
672 /*we only support 4 Tcs for X540, X550 */
673 if (hw->mac.type == ixgbe_mac_X540 ||
674 hw->mac.type == ixgbe_mac_X550 ||
675 hw->mac.type == ixgbe_mac_X550EM_x) {
676 dcb_config->num_tcs.pg_tcs = 4;
677 dcb_config->num_tcs.pfc_tcs = 4;
682 * Ensure that all locks are released before first NVM or PHY access
685 ixgbe_swfw_lock_reset(struct ixgbe_hw *hw)
690 * Phy lock should not fail in this early stage. If this is the case,
691 * it is due to an improper exit of the application.
692 * So force the release of the faulty lock. Release of common lock
693 * is done automatically by swfw_sync function.
695 mask = IXGBE_GSSR_PHY0_SM << hw->bus.func;
696 if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
697 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released", hw->bus.func);
699 ixgbe_release_swfw_semaphore(hw, mask);
702 * These ones are more tricky since they are common to all ports; but
703 * swfw_sync retries last long enough (1s) to be almost sure that if
704 * lock can not be taken it is due to an improper lock of the
707 mask = IXGBE_GSSR_EEP_SM | IXGBE_GSSR_MAC_CSR_SM | IXGBE_GSSR_SW_MNG_SM;
708 if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
709 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
711 ixgbe_release_swfw_semaphore(hw, mask);
715 * This function is based on code in ixgbe_attach() in ixgbe/ixgbe.c.
716 * It returns 0 on success.
719 eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
721 struct rte_pci_device *pci_dev;
722 struct ixgbe_hw *hw =
723 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
724 struct ixgbe_vfta * shadow_vfta =
725 IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
726 struct ixgbe_hwstrip *hwstrip =
727 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
728 struct ixgbe_dcb_config *dcb_config =
729 IXGBE_DEV_PRIVATE_TO_DCB_CFG(eth_dev->data->dev_private);
730 struct ixgbe_filter_info *filter_info =
731 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
736 PMD_INIT_FUNC_TRACE();
738 eth_dev->dev_ops = &ixgbe_eth_dev_ops;
739 eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
740 eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
743 * For secondary processes, we don't initialise any further as primary
744 * has already done this work. Only check we don't need a different
745 * RX and TX function.
747 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
748 struct igb_tx_queue *txq;
749 /* TX queue function in primary, set by last queue initialized
750 * Tx queue may not initialized by primary process */
751 if (eth_dev->data->tx_queues) {
752 txq = eth_dev->data->tx_queues[eth_dev->data->nb_tx_queues-1];
753 set_tx_function(eth_dev, txq);
755 /* Use default TX function if we get here */
756 PMD_INIT_LOG(INFO, "No TX queues configured yet. "
757 "Using default TX function.");
760 if (eth_dev->data->scattered_rx)
761 eth_dev->rx_pkt_burst = ixgbe_recv_scattered_pkts;
764 pci_dev = eth_dev->pci_dev;
766 /* Vendor and Device ID need to be set before init of shared code */
767 hw->device_id = pci_dev->id.device_id;
768 hw->vendor_id = pci_dev->id.vendor_id;
769 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
770 hw->allow_unsupported_sfp = 1;
772 /* Initialize the shared code (base driver) */
773 #ifdef RTE_NIC_BYPASS
774 diag = ixgbe_bypass_init_shared_code(hw);
776 diag = ixgbe_init_shared_code(hw);
777 #endif /* RTE_NIC_BYPASS */
779 if (diag != IXGBE_SUCCESS) {
780 PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
784 /* pick up the PCI bus settings for reporting later */
785 ixgbe_get_bus_info(hw);
787 /* Unlock any pending hardware semaphore */
788 ixgbe_swfw_lock_reset(hw);
790 /* Initialize DCB configuration*/
791 memset(dcb_config, 0, sizeof(struct ixgbe_dcb_config));
792 ixgbe_dcb_init(hw,dcb_config);
793 /* Get Hardware Flow Control setting */
794 hw->fc.requested_mode = ixgbe_fc_full;
795 hw->fc.current_mode = ixgbe_fc_full;
796 hw->fc.pause_time = IXGBE_FC_PAUSE;
797 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
798 hw->fc.low_water[i] = IXGBE_FC_LO;
799 hw->fc.high_water[i] = IXGBE_FC_HI;
803 /* Make sure we have a good EEPROM before we read from it */
804 diag = ixgbe_validate_eeprom_checksum(hw, &csum);
805 if (diag != IXGBE_SUCCESS) {
806 PMD_INIT_LOG(ERR, "The EEPROM checksum is not valid: %d", diag);
810 #ifdef RTE_NIC_BYPASS
811 diag = ixgbe_bypass_init_hw(hw);
813 diag = ixgbe_init_hw(hw);
814 #endif /* RTE_NIC_BYPASS */
817 * Devices with copper phys will fail to initialise if ixgbe_init_hw()
818 * is called too soon after the kernel driver unbinding/binding occurs.
819 * The failure occurs in ixgbe_identify_phy_generic() for all devices,
820 * but for non-copper devies, ixgbe_identify_sfp_module_generic() is
821 * also called. See ixgbe_identify_phy_82599(). The reason for the
822 * failure is not known, and only occuts when virtualisation features
823 * are disabled in the bios. A delay of 100ms was found to be enough by
824 * trial-and-error, and is doubled to be safe.
826 if (diag && (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)) {
828 diag = ixgbe_init_hw(hw);
831 if (diag == IXGBE_ERR_EEPROM_VERSION) {
832 PMD_INIT_LOG(ERR, "This device is a pre-production adapter/"
833 "LOM. Please be aware there may be issues associated "
834 "with your hardware.");
835 PMD_INIT_LOG(ERR, "If you are experiencing problems "
836 "please contact your Intel or hardware representative "
837 "who provided you with this hardware.");
838 } else if (diag == IXGBE_ERR_SFP_NOT_SUPPORTED)
839 PMD_INIT_LOG(ERR, "Unsupported SFP+ Module");
841 PMD_INIT_LOG(ERR, "Hardware Initialization Failure: %d", diag);
845 /* disable interrupt */
846 ixgbe_disable_intr(hw);
848 /* reset mappings for queue statistics hw counters*/
849 ixgbe_reset_qstat_mappings(hw);
851 /* Allocate memory for storing MAC addresses */
852 eth_dev->data->mac_addrs = rte_zmalloc("ixgbe", ETHER_ADDR_LEN *
853 hw->mac.num_rar_entries, 0);
854 if (eth_dev->data->mac_addrs == NULL) {
856 "Failed to allocate %u bytes needed to store "
858 ETHER_ADDR_LEN * hw->mac.num_rar_entries);
861 /* Copy the permanent MAC address */
862 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
863 ð_dev->data->mac_addrs[0]);
865 /* Allocate memory for storing hash filter MAC addresses */
866 eth_dev->data->hash_mac_addrs = rte_zmalloc("ixgbe", ETHER_ADDR_LEN *
867 IXGBE_VMDQ_NUM_UC_MAC, 0);
868 if (eth_dev->data->hash_mac_addrs == NULL) {
870 "Failed to allocate %d bytes needed to store MAC addresses",
871 ETHER_ADDR_LEN * IXGBE_VMDQ_NUM_UC_MAC);
875 /* initialize the vfta */
876 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
878 /* initialize the hw strip bitmap*/
879 memset(hwstrip, 0, sizeof(*hwstrip));
881 /* initialize PF if max_vfs not zero */
882 ixgbe_pf_host_init(eth_dev);
884 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
885 /* let hardware know driver is loaded */
886 ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
887 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
888 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
889 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
890 IXGBE_WRITE_FLUSH(hw);
892 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
893 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d, SFP+: %d",
894 (int) hw->mac.type, (int) hw->phy.type,
895 (int) hw->phy.sfp_type);
897 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d",
898 (int) hw->mac.type, (int) hw->phy.type);
900 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
901 eth_dev->data->port_id, pci_dev->id.vendor_id,
902 pci_dev->id.device_id);
904 rte_intr_callback_register(&(pci_dev->intr_handle),
905 ixgbe_dev_interrupt_handler, (void *)eth_dev);
907 /* enable uio intr after callback register */
908 rte_intr_enable(&(pci_dev->intr_handle));
910 /* enable support intr */
911 ixgbe_enable_intr(eth_dev);
913 /* initialize 5tuple filter list */
914 TAILQ_INIT(&filter_info->fivetuple_list);
915 memset(filter_info->fivetuple_mask, 0,
916 sizeof(uint32_t) * IXGBE_5TUPLE_ARRAY_SIZE);
923 * Negotiate mailbox API version with the PF.
924 * After reset API version is always set to the basic one (ixgbe_mbox_api_10).
925 * Then we try to negotiate starting with the most recent one.
926 * If all negotiation attempts fail, then we will proceed with
927 * the default one (ixgbe_mbox_api_10).
930 ixgbevf_negotiate_api(struct ixgbe_hw *hw)
934 /* start with highest supported, proceed down */
935 static const enum ixgbe_pfvf_api_rev sup_ver[] = {
941 i != RTE_DIM(sup_ver) &&
942 ixgbevf_negotiate_api_version(hw, sup_ver[i]) != 0;
948 generate_random_mac_addr(struct ether_addr *mac_addr)
952 /* Set Organizationally Unique Identifier (OUI) prefix. */
953 mac_addr->addr_bytes[0] = 0x00;
954 mac_addr->addr_bytes[1] = 0x09;
955 mac_addr->addr_bytes[2] = 0xC0;
956 /* Force indication of locally assigned MAC address. */
957 mac_addr->addr_bytes[0] |= ETHER_LOCAL_ADMIN_ADDR;
958 /* Generate the last 3 bytes of the MAC address with a random number. */
960 memcpy(&mac_addr->addr_bytes[3], &random, 3);
964 * Virtual Function device init
967 eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
971 struct rte_pci_device *pci_dev;
972 struct ixgbe_hw *hw =
973 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
974 struct ixgbe_vfta * shadow_vfta =
975 IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
976 struct ixgbe_hwstrip *hwstrip =
977 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
978 struct ether_addr *perm_addr = (struct ether_addr *) hw->mac.perm_addr;
980 PMD_INIT_FUNC_TRACE();
982 eth_dev->dev_ops = &ixgbevf_eth_dev_ops;
983 eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
984 eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
986 /* for secondary processes, we don't initialise any further as primary
987 * has already done this work. Only check we don't need a different
989 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
990 if (eth_dev->data->scattered_rx)
991 eth_dev->rx_pkt_burst = ixgbe_recv_scattered_pkts;
995 pci_dev = eth_dev->pci_dev;
997 hw->device_id = pci_dev->id.device_id;
998 hw->vendor_id = pci_dev->id.vendor_id;
999 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1001 /* initialize the vfta */
1002 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
1004 /* initialize the hw strip bitmap*/
1005 memset(hwstrip, 0, sizeof(*hwstrip));
1007 /* Initialize the shared code (base driver) */
1008 diag = ixgbe_init_shared_code(hw);
1009 if (diag != IXGBE_SUCCESS) {
1010 PMD_INIT_LOG(ERR, "Shared code init failed for ixgbevf: %d", diag);
1014 /* init_mailbox_params */
1015 hw->mbx.ops.init_params(hw);
1017 /* Disable the interrupts for VF */
1018 ixgbevf_intr_disable(hw);
1020 hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
1021 diag = hw->mac.ops.reset_hw(hw);
1024 * The VF reset operation returns the IXGBE_ERR_INVALID_MAC_ADDR when
1025 * the underlying PF driver has not assigned a MAC address to the VF.
1026 * In this case, assign a random MAC address.
1028 if ((diag != IXGBE_SUCCESS) && (diag != IXGBE_ERR_INVALID_MAC_ADDR)) {
1029 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
1033 /* negotiate mailbox API version to use with the PF. */
1034 ixgbevf_negotiate_api(hw);
1036 /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
1037 ixgbevf_get_queues(hw, &tcs, &tc);
1039 /* Allocate memory for storing MAC addresses */
1040 eth_dev->data->mac_addrs = rte_zmalloc("ixgbevf", ETHER_ADDR_LEN *
1041 hw->mac.num_rar_entries, 0);
1042 if (eth_dev->data->mac_addrs == NULL) {
1044 "Failed to allocate %u bytes needed to store "
1046 ETHER_ADDR_LEN * hw->mac.num_rar_entries);
1050 /* Generate a random MAC address, if none was assigned by PF. */
1051 if (is_zero_ether_addr(perm_addr)) {
1052 generate_random_mac_addr(perm_addr);
1053 diag = ixgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
1055 rte_free(eth_dev->data->mac_addrs);
1056 eth_dev->data->mac_addrs = NULL;
1059 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1060 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1061 "%02x:%02x:%02x:%02x:%02x:%02x",
1062 perm_addr->addr_bytes[0],
1063 perm_addr->addr_bytes[1],
1064 perm_addr->addr_bytes[2],
1065 perm_addr->addr_bytes[3],
1066 perm_addr->addr_bytes[4],
1067 perm_addr->addr_bytes[5]);
1070 /* Copy the permanent MAC address */
1071 ether_addr_copy(perm_addr, ð_dev->data->mac_addrs[0]);
1073 /* reset the hardware with the new settings */
1074 diag = hw->mac.ops.start_hw(hw);
1080 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
1084 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
1085 eth_dev->data->port_id, pci_dev->id.vendor_id,
1086 pci_dev->id.device_id, "ixgbe_mac_82599_vf");
1091 static struct eth_driver rte_ixgbe_pmd = {
1093 .name = "rte_ixgbe_pmd",
1094 .id_table = pci_id_ixgbe_map,
1095 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1097 .eth_dev_init = eth_ixgbe_dev_init,
1098 .dev_private_size = sizeof(struct ixgbe_adapter),
1102 * virtual function driver struct
1104 static struct eth_driver rte_ixgbevf_pmd = {
1106 .name = "rte_ixgbevf_pmd",
1107 .id_table = pci_id_ixgbevf_map,
1108 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1110 .eth_dev_init = eth_ixgbevf_dev_init,
1111 .dev_private_size = sizeof(struct ixgbe_adapter),
1115 * Driver initialization routine.
1116 * Invoked once at EAL init time.
1117 * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
1120 rte_ixgbe_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
1122 PMD_INIT_FUNC_TRACE();
1124 rte_eth_driver_register(&rte_ixgbe_pmd);
1129 * VF Driver initialization routine.
1130 * Invoked one at EAL init time.
1131 * Register itself as the [Virtual Poll Mode] Driver of PCI niantic devices.
1134 rte_ixgbevf_pmd_init(const char *name __rte_unused, const char *param __rte_unused)
1136 PMD_INIT_FUNC_TRACE();
1138 rte_eth_driver_register(&rte_ixgbevf_pmd);
1143 ixgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1145 struct ixgbe_hw *hw =
1146 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1147 struct ixgbe_vfta * shadow_vfta =
1148 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1153 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
1154 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
1155 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(vid_idx));
1160 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vid_idx), vfta);
1162 /* update local VFTA copy */
1163 shadow_vfta->vfta[vid_idx] = vfta;
1169 ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
1172 ixgbe_vlan_hw_strip_enable(dev, queue);
1174 ixgbe_vlan_hw_strip_disable(dev, queue);
1178 ixgbe_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid)
1180 struct ixgbe_hw *hw =
1181 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1183 /* Only the high 16-bits is valid */
1184 IXGBE_WRITE_REG(hw, IXGBE_EXVET, tpid << 16);
1188 ixgbe_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1190 struct ixgbe_hw *hw =
1191 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1194 PMD_INIT_FUNC_TRACE();
1196 /* Filter Table Disable */
1197 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1198 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
1200 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1204 ixgbe_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1206 struct ixgbe_hw *hw =
1207 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1208 struct ixgbe_vfta * shadow_vfta =
1209 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1213 PMD_INIT_FUNC_TRACE();
1215 /* Filter Table Enable */
1216 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1217 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1218 vlnctrl |= IXGBE_VLNCTRL_VFE;
1220 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1222 /* write whatever is in local vfta copy */
1223 for (i = 0; i < IXGBE_VFTA_SIZE; i++)
1224 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), shadow_vfta->vfta[i]);
1228 ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev, uint16_t queue, bool on)
1230 struct ixgbe_hwstrip *hwstrip =
1231 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(dev->data->dev_private);
1233 if(queue >= IXGBE_MAX_RX_QUEUE_NUM)
1237 IXGBE_SET_HWSTRIP(hwstrip, queue);
1239 IXGBE_CLEAR_HWSTRIP(hwstrip, queue);
1243 ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue)
1245 struct ixgbe_hw *hw =
1246 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1249 PMD_INIT_FUNC_TRACE();
1251 if (hw->mac.type == ixgbe_mac_82598EB) {
1252 /* No queue level support */
1253 PMD_INIT_LOG(INFO, "82598EB not support queue level hw strip");
1257 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1258 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
1259 ctrl &= ~IXGBE_RXDCTL_VME;
1260 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
1262 /* record those setting for HW strip per queue */
1263 ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 0);
1267 ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue)
1269 struct ixgbe_hw *hw =
1270 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1273 PMD_INIT_FUNC_TRACE();
1275 if (hw->mac.type == ixgbe_mac_82598EB) {
1276 /* No queue level supported */
1277 PMD_INIT_LOG(INFO, "82598EB not support queue level hw strip");
1281 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1282 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
1283 ctrl |= IXGBE_RXDCTL_VME;
1284 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
1286 /* record those setting for HW strip per queue */
1287 ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 1);
1291 ixgbe_vlan_hw_strip_disable_all(struct rte_eth_dev *dev)
1293 struct ixgbe_hw *hw =
1294 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1298 PMD_INIT_FUNC_TRACE();
1300 if (hw->mac.type == ixgbe_mac_82598EB) {
1301 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1302 ctrl &= ~IXGBE_VLNCTRL_VME;
1303 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
1306 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1307 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1308 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1309 ctrl &= ~IXGBE_RXDCTL_VME;
1310 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), ctrl);
1312 /* record those setting for HW strip per queue */
1313 ixgbe_vlan_hw_strip_bitmap_set(dev, i, 0);
1319 ixgbe_vlan_hw_strip_enable_all(struct rte_eth_dev *dev)
1321 struct ixgbe_hw *hw =
1322 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1326 PMD_INIT_FUNC_TRACE();
1328 if (hw->mac.type == ixgbe_mac_82598EB) {
1329 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1330 ctrl |= IXGBE_VLNCTRL_VME;
1331 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
1334 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1335 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1336 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1337 ctrl |= IXGBE_RXDCTL_VME;
1338 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), ctrl);
1340 /* record those setting for HW strip per queue */
1341 ixgbe_vlan_hw_strip_bitmap_set(dev, i, 1);
1347 ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev)
1349 struct ixgbe_hw *hw =
1350 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1353 PMD_INIT_FUNC_TRACE();
1355 /* DMATXCTRL: Geric Double VLAN Disable */
1356 ctrl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1357 ctrl &= ~IXGBE_DMATXCTL_GDV;
1358 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
1360 /* CTRL_EXT: Global Double VLAN Disable */
1361 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
1362 ctrl &= ~IXGBE_EXTENDED_VLAN;
1363 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
1368 ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev)
1370 struct ixgbe_hw *hw =
1371 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1374 PMD_INIT_FUNC_TRACE();
1376 /* DMATXCTRL: Geric Double VLAN Enable */
1377 ctrl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1378 ctrl |= IXGBE_DMATXCTL_GDV;
1379 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
1381 /* CTRL_EXT: Global Double VLAN Enable */
1382 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
1383 ctrl |= IXGBE_EXTENDED_VLAN;
1384 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
1387 * VET EXT field in the EXVET register = 0x8100 by default
1388 * So no need to change. Same to VT field of DMATXCTL register
1393 ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1395 if(mask & ETH_VLAN_STRIP_MASK){
1396 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1397 ixgbe_vlan_hw_strip_enable_all(dev);
1399 ixgbe_vlan_hw_strip_disable_all(dev);
1402 if(mask & ETH_VLAN_FILTER_MASK){
1403 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1404 ixgbe_vlan_hw_filter_enable(dev);
1406 ixgbe_vlan_hw_filter_disable(dev);
1409 if(mask & ETH_VLAN_EXTEND_MASK){
1410 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1411 ixgbe_vlan_hw_extend_enable(dev);
1413 ixgbe_vlan_hw_extend_disable(dev);
1418 ixgbe_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1420 struct ixgbe_hw *hw =
1421 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1422 /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
1423 uint32_t vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1424 vlanctrl |= IXGBE_VLNCTRL_VFE ; /* enable vlan filters */
1425 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
1429 ixgbe_dev_configure(struct rte_eth_dev *dev)
1431 struct ixgbe_interrupt *intr =
1432 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1434 PMD_INIT_FUNC_TRACE();
1436 /* set flag to update link status after init */
1437 intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1443 * Configure device link speed and setup link.
1444 * It returns 0 on success.
1447 ixgbe_dev_start(struct rte_eth_dev *dev)
1449 struct ixgbe_hw *hw =
1450 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1451 struct ixgbe_vf_info *vfinfo =
1452 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
1453 int err, link_up = 0, negotiate = 0;
1459 PMD_INIT_FUNC_TRACE();
1461 /* IXGBE devices don't support half duplex */
1462 if ((dev->data->dev_conf.link_duplex != ETH_LINK_AUTONEG_DUPLEX) &&
1463 (dev->data->dev_conf.link_duplex != ETH_LINK_FULL_DUPLEX)) {
1464 PMD_INIT_LOG(ERR, "Invalid link_duplex (%hu) for port %hhu",
1465 dev->data->dev_conf.link_duplex,
1466 dev->data->port_id);
1471 hw->adapter_stopped = FALSE;
1472 ixgbe_stop_adapter(hw);
1474 /* reinitialize adapter
1475 * this calls reset and start */
1476 status = ixgbe_pf_reset_hw(hw);
1479 hw->mac.ops.start_hw(hw);
1480 hw->mac.get_link_status = true;
1482 /* configure PF module if SRIOV enabled */
1483 ixgbe_pf_host_configure(dev);
1485 /* initialize transmission unit */
1486 ixgbe_dev_tx_init(dev);
1488 /* This can fail when allocating mbufs for descriptor rings */
1489 err = ixgbe_dev_rx_init(dev);
1491 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1495 err = ixgbe_dev_rxtx_start(dev);
1497 PMD_INIT_LOG(ERR, "Unable to start rxtx queues");
1501 /* Skip link setup if loopback mode is enabled for 82599. */
1502 if (hw->mac.type == ixgbe_mac_82599EB &&
1503 dev->data->dev_conf.lpbk_mode == IXGBE_LPBK_82599_TX_RX)
1504 goto skip_link_setup;
1506 if (ixgbe_is_sfp(hw) && hw->phy.multispeed_fiber) {
1507 err = hw->mac.ops.setup_sfp(hw);
1512 /* Turn on the laser */
1513 ixgbe_enable_tx_laser(hw);
1515 err = ixgbe_check_link(hw, &speed, &link_up, 0);
1518 dev->data->dev_link.link_status = link_up;
1520 err = ixgbe_get_link_capabilities(hw, &speed, &negotiate);
1524 switch(dev->data->dev_conf.link_speed) {
1525 case ETH_LINK_SPEED_AUTONEG:
1526 speed = (hw->mac.type != ixgbe_mac_82598EB) ?
1527 IXGBE_LINK_SPEED_82599_AUTONEG :
1528 IXGBE_LINK_SPEED_82598_AUTONEG;
1530 case ETH_LINK_SPEED_100:
1532 * Invalid for 82598 but error will be detected by
1533 * ixgbe_setup_link()
1535 speed = IXGBE_LINK_SPEED_100_FULL;
1537 case ETH_LINK_SPEED_1000:
1538 speed = IXGBE_LINK_SPEED_1GB_FULL;
1540 case ETH_LINK_SPEED_10000:
1541 speed = IXGBE_LINK_SPEED_10GB_FULL;
1544 PMD_INIT_LOG(ERR, "Invalid link_speed (%hu) for port %hhu",
1545 dev->data->dev_conf.link_speed,
1546 dev->data->port_id);
1550 err = ixgbe_setup_link(hw, speed, link_up);
1556 /* check if lsc interrupt is enabled */
1557 if (dev->data->dev_conf.intr_conf.lsc != 0)
1558 ixgbe_dev_lsc_interrupt_setup(dev);
1560 /* resume enabled intr since hw reset */
1561 ixgbe_enable_intr(dev);
1563 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
1564 ETH_VLAN_EXTEND_MASK;
1565 ixgbe_vlan_offload_set(dev, mask);
1567 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1568 /* Enable vlan filtering for VMDq */
1569 ixgbe_vmdq_vlan_hw_filter_enable(dev);
1572 /* Configure DCB hw */
1573 ixgbe_configure_dcb(dev);
1575 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_NONE) {
1576 err = ixgbe_fdir_configure(dev);
1581 /* Restore vf rate limit */
1582 if (vfinfo != NULL) {
1583 for (vf = 0; vf < dev->pci_dev->max_vfs; vf++)
1584 for (idx = 0; idx < IXGBE_MAX_QUEUE_NUM_PER_VF; idx++)
1585 if (vfinfo[vf].tx_rate[idx] != 0)
1586 ixgbe_set_vf_rate_limit(dev, vf,
1587 vfinfo[vf].tx_rate[idx],
1591 ixgbe_restore_statistics_mapping(dev);
1596 PMD_INIT_LOG(ERR, "failure in ixgbe_dev_start(): %d", err);
1597 ixgbe_dev_clear_queues(dev);
1602 * Stop device: disable rx and tx functions to allow for reconfiguring.
1605 ixgbe_dev_stop(struct rte_eth_dev *dev)
1607 struct rte_eth_link link;
1608 struct ixgbe_hw *hw =
1609 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1610 struct ixgbe_vf_info *vfinfo =
1611 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
1612 struct ixgbe_filter_info *filter_info =
1613 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1614 struct ixgbe_5tuple_filter *p_5tuple, *p_5tuple_next;
1617 PMD_INIT_FUNC_TRACE();
1619 /* disable interrupts */
1620 ixgbe_disable_intr(hw);
1623 ixgbe_pf_reset_hw(hw);
1624 hw->adapter_stopped = FALSE;
1627 ixgbe_stop_adapter(hw);
1629 for (vf = 0; vfinfo != NULL &&
1630 vf < dev->pci_dev->max_vfs; vf++)
1631 vfinfo[vf].clear_to_send = false;
1633 /* Turn off the laser */
1634 ixgbe_disable_tx_laser(hw);
1636 ixgbe_dev_clear_queues(dev);
1638 /* Clear stored conf */
1639 dev->data->scattered_rx = 0;
1641 /* Clear recorded link status */
1642 memset(&link, 0, sizeof(link));
1643 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
1645 /* Remove all ntuple filters of the device */
1646 for (p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list);
1647 p_5tuple != NULL; p_5tuple = p_5tuple_next) {
1648 p_5tuple_next = TAILQ_NEXT(p_5tuple, entries);
1649 TAILQ_REMOVE(&filter_info->fivetuple_list,
1653 memset(filter_info->fivetuple_mask, 0,
1654 sizeof(uint32_t) * IXGBE_5TUPLE_ARRAY_SIZE);
1659 * Set device link up: enable tx laser.
1662 ixgbe_dev_set_link_up(struct rte_eth_dev *dev)
1664 struct ixgbe_hw *hw =
1665 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1666 if (hw->mac.type == ixgbe_mac_82599EB) {
1667 #ifdef RTE_NIC_BYPASS
1668 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
1669 /* Not suported in bypass mode */
1670 PMD_INIT_LOG(ERR, "Set link up is not supported "
1671 "by device id 0x%x", hw->device_id);
1675 /* Turn on the laser */
1676 ixgbe_enable_tx_laser(hw);
1680 PMD_INIT_LOG(ERR, "Set link up is not supported by device id 0x%x",
1686 * Set device link down: disable tx laser.
1689 ixgbe_dev_set_link_down(struct rte_eth_dev *dev)
1691 struct ixgbe_hw *hw =
1692 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1693 if (hw->mac.type == ixgbe_mac_82599EB) {
1694 #ifdef RTE_NIC_BYPASS
1695 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
1696 /* Not suported in bypass mode */
1697 PMD_INIT_LOG(ERR, "Set link down is not supported "
1698 "by device id 0x%x", hw->device_id);
1702 /* Turn off the laser */
1703 ixgbe_disable_tx_laser(hw);
1707 PMD_INIT_LOG(ERR, "Set link down is not supported by device id 0x%x",
1713 * Reest and stop device.
1716 ixgbe_dev_close(struct rte_eth_dev *dev)
1718 struct ixgbe_hw *hw =
1719 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1721 PMD_INIT_FUNC_TRACE();
1723 ixgbe_pf_reset_hw(hw);
1725 ixgbe_dev_stop(dev);
1726 hw->adapter_stopped = 1;
1728 ixgbe_disable_pcie_master(hw);
1730 /* reprogram the RAR[0] in case user changed it. */
1731 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
1735 * This function is based on ixgbe_update_stats_counters() in ixgbe/ixgbe.c
1738 ixgbe_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1740 struct ixgbe_hw *hw =
1741 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1742 struct ixgbe_hw_stats *hw_stats =
1743 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1744 uint32_t bprc, lxon, lxoff, total;
1745 uint64_t total_missed_rx, total_qbrc, total_qprc;
1748 total_missed_rx = 0;
1752 hw_stats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
1753 hw_stats->illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC);
1754 hw_stats->errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC);
1755 hw_stats->mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC);
1757 for (i = 0; i < 8; i++) {
1759 mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
1760 /* global total per queue */
1761 hw_stats->mpc[i] += mp;
1762 /* Running comprehensive total for stats display */
1763 total_missed_rx += hw_stats->mpc[i];
1764 if (hw->mac.type == ixgbe_mac_82598EB)
1765 hw_stats->rnbc[i] +=
1766 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
1767 hw_stats->pxontxc[i] +=
1768 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
1769 hw_stats->pxonrxc[i] +=
1770 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
1771 hw_stats->pxofftxc[i] +=
1772 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
1773 hw_stats->pxoffrxc[i] +=
1774 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
1775 hw_stats->pxon2offc[i] +=
1776 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
1778 for (i = 0; i < IXGBE_QUEUE_STAT_COUNTERS; i++) {
1779 hw_stats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
1780 hw_stats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
1781 hw_stats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
1782 hw_stats->qbrc[i] +=
1783 ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)) << 32);
1784 hw_stats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
1785 hw_stats->qbtc[i] +=
1786 ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)) << 32);
1787 hw_stats->qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
1789 total_qprc += hw_stats->qprc[i];
1790 total_qbrc += hw_stats->qbrc[i];
1792 hw_stats->mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC);
1793 hw_stats->mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC);
1794 hw_stats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
1796 /* Note that gprc counts missed packets */
1797 hw_stats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
1799 if (hw->mac.type != ixgbe_mac_82598EB) {
1800 hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
1801 hw_stats->gorc += ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32);
1802 hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
1803 hw_stats->gotc += ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32);
1804 hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
1805 hw_stats->tor += ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32);
1806 hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
1807 hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
1809 hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
1810 hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
1811 /* 82598 only has a counter in the high register */
1812 hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
1813 hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
1814 hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
1818 * Workaround: mprc hardware is incorrectly counting
1819 * broadcasts, so for now we subtract those.
1821 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
1822 hw_stats->bprc += bprc;
1823 hw_stats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
1824 if (hw->mac.type == ixgbe_mac_82598EB)
1825 hw_stats->mprc -= bprc;
1827 hw_stats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
1828 hw_stats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
1829 hw_stats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
1830 hw_stats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
1831 hw_stats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
1832 hw_stats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
1834 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
1835 hw_stats->lxontxc += lxon;
1836 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
1837 hw_stats->lxofftxc += lxoff;
1838 total = lxon + lxoff;
1840 hw_stats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
1841 hw_stats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
1842 hw_stats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
1843 hw_stats->gptc -= total;
1844 hw_stats->mptc -= total;
1845 hw_stats->ptc64 -= total;
1846 hw_stats->gotc -= total * ETHER_MIN_LEN;
1848 hw_stats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
1849 hw_stats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
1850 hw_stats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
1851 hw_stats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
1852 hw_stats->mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC);
1853 hw_stats->mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC);
1854 hw_stats->mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC);
1855 hw_stats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
1856 hw_stats->tpt += IXGBE_READ_REG(hw, IXGBE_TPT);
1857 hw_stats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
1858 hw_stats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
1859 hw_stats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
1860 hw_stats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
1861 hw_stats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
1862 hw_stats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
1863 hw_stats->xec += IXGBE_READ_REG(hw, IXGBE_XEC);
1864 hw_stats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
1865 hw_stats->fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
1866 /* Only read FCOE on 82599 */
1867 if (hw->mac.type != ixgbe_mac_82598EB) {
1868 hw_stats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
1869 hw_stats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
1870 hw_stats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
1871 hw_stats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
1872 hw_stats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
1878 /* Fill out the rte_eth_stats statistics structure */
1879 stats->ipackets = total_qprc;
1880 stats->ibytes = total_qbrc;
1881 stats->opackets = hw_stats->gptc;
1882 stats->obytes = hw_stats->gotc;
1883 stats->imcasts = hw_stats->mprc;
1885 for (i = 0; i < IXGBE_QUEUE_STAT_COUNTERS; i++) {
1886 stats->q_ipackets[i] = hw_stats->qprc[i];
1887 stats->q_opackets[i] = hw_stats->qptc[i];
1888 stats->q_ibytes[i] = hw_stats->qbrc[i];
1889 stats->q_obytes[i] = hw_stats->qbtc[i];
1890 stats->q_errors[i] = hw_stats->qprdc[i];
1894 stats->ibadcrc = hw_stats->crcerrs;
1895 stats->ibadlen = hw_stats->rlec + hw_stats->ruc + hw_stats->roc;
1896 stats->imissed = total_missed_rx;
1897 stats->ierrors = stats->ibadcrc +
1900 hw_stats->illerrc + hw_stats->errbc;
1905 /* XON/XOFF pause frames */
1906 stats->tx_pause_xon = hw_stats->lxontxc;
1907 stats->rx_pause_xon = hw_stats->lxonrxc;
1908 stats->tx_pause_xoff = hw_stats->lxofftxc;
1909 stats->rx_pause_xoff = hw_stats->lxoffrxc;
1911 /* Flow Director Stats registers */
1912 hw_stats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
1913 hw_stats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
1914 stats->fdirmatch = hw_stats->fdirmatch;
1915 stats->fdirmiss = hw_stats->fdirmiss;
1919 ixgbe_dev_stats_reset(struct rte_eth_dev *dev)
1921 struct ixgbe_hw_stats *stats =
1922 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1924 /* HW registers are cleared on read */
1925 ixgbe_dev_stats_get(dev, NULL);
1927 /* Reset software totals */
1928 memset(stats, 0, sizeof(*stats));
1932 ixgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1934 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1935 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats*)
1936 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1938 /* Good Rx packet, include VF loopback */
1939 UPDATE_VF_STAT(IXGBE_VFGPRC,
1940 hw_stats->last_vfgprc, hw_stats->vfgprc);
1942 /* Good Rx octets, include VF loopback */
1943 UPDATE_VF_STAT_36BIT(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
1944 hw_stats->last_vfgorc, hw_stats->vfgorc);
1946 /* Good Tx packet, include VF loopback */
1947 UPDATE_VF_STAT(IXGBE_VFGPTC,
1948 hw_stats->last_vfgptc, hw_stats->vfgptc);
1950 /* Good Tx octets, include VF loopback */
1951 UPDATE_VF_STAT_36BIT(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
1952 hw_stats->last_vfgotc, hw_stats->vfgotc);
1954 /* Rx Multicst Packet */
1955 UPDATE_VF_STAT(IXGBE_VFMPRC,
1956 hw_stats->last_vfmprc, hw_stats->vfmprc);
1961 stats->ipackets = hw_stats->vfgprc;
1962 stats->ibytes = hw_stats->vfgorc;
1963 stats->opackets = hw_stats->vfgptc;
1964 stats->obytes = hw_stats->vfgotc;
1965 stats->imcasts = hw_stats->vfmprc;
1969 ixgbevf_dev_stats_reset(struct rte_eth_dev *dev)
1971 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats*)
1972 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1974 /* Sync HW register to the last stats */
1975 ixgbevf_dev_stats_get(dev, NULL);
1977 /* reset HW current stats*/
1978 hw_stats->vfgprc = 0;
1979 hw_stats->vfgorc = 0;
1980 hw_stats->vfgptc = 0;
1981 hw_stats->vfgotc = 0;
1982 hw_stats->vfmprc = 0;
1987 ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1989 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1991 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
1992 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
1993 dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL register */
1994 dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS register */
1995 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
1996 dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
1997 dev_info->max_vfs = dev->pci_dev->max_vfs;
1998 if (hw->mac.type == ixgbe_mac_82598EB)
1999 dev_info->max_vmdq_pools = ETH_16_POOLS;
2001 dev_info->max_vmdq_pools = ETH_64_POOLS;
2002 dev_info->vmdq_queue_num = dev_info->max_rx_queues;
2003 dev_info->rx_offload_capa =
2004 DEV_RX_OFFLOAD_VLAN_STRIP |
2005 DEV_RX_OFFLOAD_IPV4_CKSUM |
2006 DEV_RX_OFFLOAD_UDP_CKSUM |
2007 DEV_RX_OFFLOAD_TCP_CKSUM;
2008 dev_info->tx_offload_capa =
2009 DEV_TX_OFFLOAD_VLAN_INSERT |
2010 DEV_TX_OFFLOAD_IPV4_CKSUM |
2011 DEV_TX_OFFLOAD_UDP_CKSUM |
2012 DEV_TX_OFFLOAD_TCP_CKSUM |
2013 DEV_TX_OFFLOAD_SCTP_CKSUM |
2014 DEV_TX_OFFLOAD_TCP_TSO;
2016 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2018 .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
2019 .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
2020 .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
2022 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
2026 dev_info->default_txconf = (struct rte_eth_txconf) {
2028 .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
2029 .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
2030 .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
2032 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
2033 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
2034 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
2035 ETH_TXQ_FLAGS_NOOFFLOADS,
2037 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
2038 dev_info->flow_type_rss_offloads = IXGBE_RSS_OFFLOAD_ALL;
2042 ixgbevf_dev_info_get(struct rte_eth_dev *dev,
2043 struct rte_eth_dev_info *dev_info)
2045 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2047 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
2048 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
2049 dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL reg */
2050 dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS reg */
2051 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
2052 dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
2053 dev_info->max_vfs = dev->pci_dev->max_vfs;
2054 if (hw->mac.type == ixgbe_mac_82598EB)
2055 dev_info->max_vmdq_pools = ETH_16_POOLS;
2057 dev_info->max_vmdq_pools = ETH_64_POOLS;
2058 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
2059 DEV_RX_OFFLOAD_IPV4_CKSUM |
2060 DEV_RX_OFFLOAD_UDP_CKSUM |
2061 DEV_RX_OFFLOAD_TCP_CKSUM;
2062 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
2063 DEV_TX_OFFLOAD_IPV4_CKSUM |
2064 DEV_TX_OFFLOAD_UDP_CKSUM |
2065 DEV_TX_OFFLOAD_TCP_CKSUM |
2066 DEV_TX_OFFLOAD_SCTP_CKSUM;
2068 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2070 .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
2071 .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
2072 .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
2074 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
2078 dev_info->default_txconf = (struct rte_eth_txconf) {
2080 .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
2081 .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
2082 .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
2084 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
2085 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
2086 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
2087 ETH_TXQ_FLAGS_NOOFFLOADS,
2091 /* return 0 means link status changed, -1 means not changed */
2093 ixgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2095 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2096 struct rte_eth_link link, old;
2097 ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
2101 link.link_status = 0;
2102 link.link_speed = 0;
2103 link.link_duplex = 0;
2104 memset(&old, 0, sizeof(old));
2105 rte_ixgbe_dev_atomic_read_link_status(dev, &old);
2107 /* check if it needs to wait to complete, if lsc interrupt is enabled */
2108 if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
2109 diag = ixgbe_check_link(hw, &link_speed, &link_up, 0);
2111 diag = ixgbe_check_link(hw, &link_speed, &link_up, 1);
2113 link.link_speed = ETH_LINK_SPEED_100;
2114 link.link_duplex = ETH_LINK_HALF_DUPLEX;
2115 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
2116 if (link.link_status == old.link_status)
2121 if (link_speed == IXGBE_LINK_SPEED_UNKNOWN &&
2122 !hw->mac.get_link_status) {
2123 memcpy(&link, &old, sizeof(link));
2128 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
2129 if (link.link_status == old.link_status)
2133 link.link_status = 1;
2134 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2136 switch (link_speed) {
2138 case IXGBE_LINK_SPEED_UNKNOWN:
2139 link.link_duplex = ETH_LINK_HALF_DUPLEX;
2140 link.link_speed = ETH_LINK_SPEED_100;
2143 case IXGBE_LINK_SPEED_100_FULL:
2144 link.link_speed = ETH_LINK_SPEED_100;
2147 case IXGBE_LINK_SPEED_1GB_FULL:
2148 link.link_speed = ETH_LINK_SPEED_1000;
2151 case IXGBE_LINK_SPEED_10GB_FULL:
2152 link.link_speed = ETH_LINK_SPEED_10000;
2155 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
2157 if (link.link_status == old.link_status)
2164 ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
2166 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2169 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2170 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2171 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2175 ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
2177 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2180 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2181 fctrl &= (~IXGBE_FCTRL_UPE);
2182 if (dev->data->all_multicast == 1)
2183 fctrl |= IXGBE_FCTRL_MPE;
2185 fctrl &= (~IXGBE_FCTRL_MPE);
2186 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2190 ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
2192 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2195 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2196 fctrl |= IXGBE_FCTRL_MPE;
2197 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2201 ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
2203 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2206 if (dev->data->promiscuous == 1)
2207 return; /* must remain in all_multicast mode */
2209 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2210 fctrl &= (~IXGBE_FCTRL_MPE);
2211 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2215 * It clears the interrupt causes and enables the interrupt.
2216 * It will be called once only during nic initialized.
2219 * Pointer to struct rte_eth_dev.
2222 * - On success, zero.
2223 * - On failure, a negative value.
2226 ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev)
2228 struct ixgbe_interrupt *intr =
2229 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2231 ixgbe_dev_link_status_print(dev);
2232 intr->mask |= IXGBE_EICR_LSC;
2238 * It reads ICR and sets flag (IXGBE_EICR_LSC) for the link_update.
2241 * Pointer to struct rte_eth_dev.
2244 * - On success, zero.
2245 * - On failure, a negative value.
2248 ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
2251 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2252 struct ixgbe_interrupt *intr =
2253 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2255 /* clear all cause mask */
2256 ixgbe_disable_intr(hw);
2258 /* read-on-clear nic registers here */
2259 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2260 PMD_DRV_LOG(INFO, "eicr %x", eicr);
2263 if (eicr & IXGBE_EICR_LSC) {
2264 /* set flag for async link update */
2265 intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2268 if (eicr & IXGBE_EICR_MAILBOX)
2269 intr->flags |= IXGBE_FLAG_MAILBOX;
2275 * It gets and then prints the link status.
2278 * Pointer to struct rte_eth_dev.
2281 * - On success, zero.
2282 * - On failure, a negative value.
2285 ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
2287 struct rte_eth_link link;
2289 memset(&link, 0, sizeof(link));
2290 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
2291 if (link.link_status) {
2292 PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
2293 (int)(dev->data->port_id),
2294 (unsigned)link.link_speed,
2295 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2296 "full-duplex" : "half-duplex");
2298 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2299 (int)(dev->data->port_id));
2301 PMD_INIT_LOG(INFO, "PCI Address: %04d:%02d:%02d:%d",
2302 dev->pci_dev->addr.domain,
2303 dev->pci_dev->addr.bus,
2304 dev->pci_dev->addr.devid,
2305 dev->pci_dev->addr.function);
2309 * It executes link_update after knowing an interrupt occurred.
2312 * Pointer to struct rte_eth_dev.
2315 * - On success, zero.
2316 * - On failure, a negative value.
2319 ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
2321 struct ixgbe_interrupt *intr =
2322 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2324 struct rte_eth_link link;
2325 int intr_enable_delay = false;
2327 PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
2329 if (intr->flags & IXGBE_FLAG_MAILBOX) {
2330 ixgbe_pf_mbx_process(dev);
2331 intr->flags &= ~IXGBE_FLAG_MAILBOX;
2334 if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
2335 /* get the link status before link update, for predicting later */
2336 memset(&link, 0, sizeof(link));
2337 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
2339 ixgbe_dev_link_update(dev, 0);
2342 if (!link.link_status)
2343 /* handle it 1 sec later, wait it being stable */
2344 timeout = IXGBE_LINK_UP_CHECK_TIMEOUT;
2345 /* likely to down */
2347 /* handle it 4 sec later, wait it being stable */
2348 timeout = IXGBE_LINK_DOWN_CHECK_TIMEOUT;
2350 ixgbe_dev_link_status_print(dev);
2352 intr_enable_delay = true;
2355 if (intr_enable_delay) {
2356 if (rte_eal_alarm_set(timeout * 1000,
2357 ixgbe_dev_interrupt_delayed_handler, (void*)dev) < 0)
2358 PMD_DRV_LOG(ERR, "Error setting alarm");
2360 PMD_DRV_LOG(DEBUG, "enable intr immediately");
2361 ixgbe_enable_intr(dev);
2362 rte_intr_enable(&(dev->pci_dev->intr_handle));
2370 * Interrupt handler which shall be registered for alarm callback for delayed
2371 * handling specific interrupt to wait for the stable nic state. As the
2372 * NIC interrupt state is not stable for ixgbe after link is just down,
2373 * it needs to wait 4 seconds to get the stable status.
2376 * Pointer to interrupt handle.
2378 * The address of parameter (struct rte_eth_dev *) regsitered before.
2384 ixgbe_dev_interrupt_delayed_handler(void *param)
2386 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2387 struct ixgbe_interrupt *intr =
2388 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2389 struct ixgbe_hw *hw =
2390 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2393 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2394 if (eicr & IXGBE_EICR_MAILBOX)
2395 ixgbe_pf_mbx_process(dev);
2397 if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
2398 ixgbe_dev_link_update(dev, 0);
2399 intr->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
2400 ixgbe_dev_link_status_print(dev);
2401 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
2404 PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
2405 ixgbe_enable_intr(dev);
2406 rte_intr_enable(&(dev->pci_dev->intr_handle));
2410 * Interrupt handler triggered by NIC for handling
2411 * specific interrupt.
2414 * Pointer to interrupt handle.
2416 * The address of parameter (struct rte_eth_dev *) regsitered before.
2422 ixgbe_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
2425 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2426 ixgbe_dev_interrupt_get_status(dev);
2427 ixgbe_dev_interrupt_action(dev);
2431 ixgbe_dev_led_on(struct rte_eth_dev *dev)
2433 struct ixgbe_hw *hw;
2435 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2436 return (ixgbe_led_on(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP);
2440 ixgbe_dev_led_off(struct rte_eth_dev *dev)
2442 struct ixgbe_hw *hw;
2444 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2445 return (ixgbe_led_off(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP);
2449 ixgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2451 struct ixgbe_hw *hw;
2457 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2459 fc_conf->pause_time = hw->fc.pause_time;
2460 fc_conf->high_water = hw->fc.high_water[0];
2461 fc_conf->low_water = hw->fc.low_water[0];
2462 fc_conf->send_xon = hw->fc.send_xon;
2463 fc_conf->autoneg = !hw->fc.disable_fc_autoneg;
2466 * Return rx_pause status according to actual setting of
2469 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2470 if (mflcn_reg & (IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_RFCE))
2476 * Return tx_pause status according to actual setting of
2479 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
2480 if (fccfg_reg & (IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY))
2485 if (rx_pause && tx_pause)
2486 fc_conf->mode = RTE_FC_FULL;
2488 fc_conf->mode = RTE_FC_RX_PAUSE;
2490 fc_conf->mode = RTE_FC_TX_PAUSE;
2492 fc_conf->mode = RTE_FC_NONE;
2498 ixgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2500 struct ixgbe_hw *hw;
2502 uint32_t rx_buf_size;
2503 uint32_t max_high_water;
2505 enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
2512 PMD_INIT_FUNC_TRACE();
2514 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2515 if (fc_conf->autoneg != !hw->fc.disable_fc_autoneg)
2517 rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0));
2518 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2521 * At least reserve one Ethernet frame for watermark
2522 * high_water/low_water in kilo bytes for ixgbe
2524 max_high_water = (rx_buf_size - ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
2525 if ((fc_conf->high_water > max_high_water) ||
2526 (fc_conf->high_water < fc_conf->low_water)) {
2527 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
2528 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
2532 hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[fc_conf->mode];
2533 hw->fc.pause_time = fc_conf->pause_time;
2534 hw->fc.high_water[0] = fc_conf->high_water;
2535 hw->fc.low_water[0] = fc_conf->low_water;
2536 hw->fc.send_xon = fc_conf->send_xon;
2538 err = ixgbe_fc_enable(hw);
2540 /* Not negotiated is not an error case */
2541 if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED)) {
2543 /* check if we want to forward MAC frames - driver doesn't have native
2544 * capability to do that, so we'll write the registers ourselves */
2546 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2548 /* set or clear MFLCN.PMCF bit depending on configuration */
2549 if (fc_conf->mac_ctrl_frame_fwd != 0)
2550 mflcn |= IXGBE_MFLCN_PMCF;
2552 mflcn &= ~IXGBE_MFLCN_PMCF;
2554 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn);
2555 IXGBE_WRITE_FLUSH(hw);
2560 PMD_INIT_LOG(ERR, "ixgbe_fc_enable = 0x%x", err);
2565 * ixgbe_pfc_enable_generic - Enable flow control
2566 * @hw: pointer to hardware structure
2567 * @tc_num: traffic class number
2568 * Enable flow control according to the current settings.
2571 ixgbe_dcb_pfc_enable_generic(struct ixgbe_hw *hw,uint8_t tc_num)
2574 uint32_t mflcn_reg, fccfg_reg;
2576 uint32_t fcrtl, fcrth;
2580 /* Validate the water mark configuration */
2581 if (!hw->fc.pause_time) {
2582 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2586 /* Low water mark of zero causes XOFF floods */
2587 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
2588 /* High/Low water can not be 0 */
2589 if( (!hw->fc.high_water[tc_num])|| (!hw->fc.low_water[tc_num])) {
2590 PMD_INIT_LOG(ERR, "Invalid water mark configuration");
2591 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2595 if(hw->fc.low_water[tc_num] >= hw->fc.high_water[tc_num]) {
2596 PMD_INIT_LOG(ERR, "Invalid water mark configuration");
2597 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2601 /* Negotiate the fc mode to use */
2602 ixgbe_fc_autoneg(hw);
2604 /* Disable any previous flow control settings */
2605 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2606 mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_SHIFT | IXGBE_MFLCN_RFCE|IXGBE_MFLCN_RPFCE);
2608 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
2609 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
2611 switch (hw->fc.current_mode) {
2614 * If the count of enabled RX Priority Flow control >1,
2615 * and the TX pause can not be disabled
2618 for (i =0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
2619 reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
2620 if (reg & IXGBE_FCRTH_FCEN)
2624 fccfg_reg |=IXGBE_FCCFG_TFCE_PRIORITY;
2626 case ixgbe_fc_rx_pause:
2628 * Rx Flow control is enabled and Tx Flow control is
2629 * disabled by software override. Since there really
2630 * isn't a way to advertise that we are capable of RX
2631 * Pause ONLY, we will advertise that we support both
2632 * symmetric and asymmetric Rx PAUSE. Later, we will
2633 * disable the adapter's ability to send PAUSE frames.
2635 mflcn_reg |= IXGBE_MFLCN_RPFCE;
2637 * If the count of enabled RX Priority Flow control >1,
2638 * and the TX pause can not be disabled
2641 for (i =0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
2642 reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
2643 if (reg & IXGBE_FCRTH_FCEN)
2647 fccfg_reg |=IXGBE_FCCFG_TFCE_PRIORITY;
2649 case ixgbe_fc_tx_pause:
2651 * Tx Flow control is enabled, and Rx Flow control is
2652 * disabled by software override.
2654 fccfg_reg |=IXGBE_FCCFG_TFCE_PRIORITY;
2657 /* Flow control (both Rx and Tx) is enabled by SW override. */
2658 mflcn_reg |= IXGBE_MFLCN_RPFCE;
2659 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
2662 PMD_DRV_LOG(DEBUG, "Flow control param set incorrectly");
2663 ret_val = IXGBE_ERR_CONFIG;
2668 /* Set 802.3x based flow control settings. */
2669 mflcn_reg |= IXGBE_MFLCN_DPF;
2670 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
2671 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
2673 /* Set up and enable Rx high/low water mark thresholds, enable XON. */
2674 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
2675 hw->fc.high_water[tc_num]) {
2676 fcrtl = (hw->fc.low_water[tc_num] << 10) | IXGBE_FCRTL_XONE;
2677 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), fcrtl);
2678 fcrth = (hw->fc.high_water[tc_num] << 10) | IXGBE_FCRTH_FCEN;
2680 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), 0);
2682 * In order to prevent Tx hangs when the internal Tx
2683 * switch is enabled we must set the high water mark
2684 * to the maximum FCRTH value. This allows the Tx
2685 * switch to function even under heavy Rx workloads.
2687 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num)) - 32;
2689 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(tc_num), fcrth);
2691 /* Configure pause time (2 TCs per register) */
2692 reg = hw->fc.pause_time * 0x00010001;
2693 for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
2694 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
2696 /* Configure flow control refresh threshold value */
2697 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
2704 ixgbe_dcb_pfc_enable(struct rte_eth_dev *dev,uint8_t tc_num)
2706 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2707 int32_t ret_val = IXGBE_NOT_IMPLEMENTED;
2709 if(hw->mac.type != ixgbe_mac_82598EB) {
2710 ret_val = ixgbe_dcb_pfc_enable_generic(hw,tc_num);
2716 ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
2719 uint32_t rx_buf_size;
2720 uint32_t max_high_water;
2722 uint8_t map[IXGBE_DCB_MAX_USER_PRIORITY] = { 0 };
2723 struct ixgbe_hw *hw =
2724 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2725 struct ixgbe_dcb_config *dcb_config =
2726 IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
2728 enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
2735 PMD_INIT_FUNC_TRACE();
2737 ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_RX_CONFIG, map);
2738 tc_num = map[pfc_conf->priority];
2739 rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num));
2740 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2742 * At least reserve one Ethernet frame for watermark
2743 * high_water/low_water in kilo bytes for ixgbe
2745 max_high_water = (rx_buf_size - ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
2746 if ((pfc_conf->fc.high_water > max_high_water) ||
2747 (pfc_conf->fc.high_water <= pfc_conf->fc.low_water)) {
2748 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
2749 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
2753 hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[pfc_conf->fc.mode];
2754 hw->fc.pause_time = pfc_conf->fc.pause_time;
2755 hw->fc.send_xon = pfc_conf->fc.send_xon;
2756 hw->fc.low_water[tc_num] = pfc_conf->fc.low_water;
2757 hw->fc.high_water[tc_num] = pfc_conf->fc.high_water;
2759 err = ixgbe_dcb_pfc_enable(dev,tc_num);
2761 /* Not negotiated is not an error case */
2762 if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED))
2765 PMD_INIT_LOG(ERR, "ixgbe_dcb_pfc_enable = 0x%x", err);
2770 ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
2771 struct rte_eth_rss_reta_entry64 *reta_conf,
2776 uint16_t idx, shift;
2777 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2779 PMD_INIT_FUNC_TRACE();
2780 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2781 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2782 "(%d) doesn't match the number hardware can supported "
2783 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2787 for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
2788 idx = i / RTE_RETA_GROUP_SIZE;
2789 shift = i % RTE_RETA_GROUP_SIZE;
2790 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2794 if (mask == IXGBE_4_BIT_MASK)
2797 r = IXGBE_READ_REG(hw, IXGBE_RETA(i >> 2));
2798 for (j = 0, reta = 0; j < IXGBE_4_BIT_WIDTH; j++) {
2799 if (mask & (0x1 << j))
2800 reta |= reta_conf[idx].reta[shift + j] <<
2803 reta |= r & (IXGBE_8_BIT_MASK <<
2806 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2813 ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
2814 struct rte_eth_rss_reta_entry64 *reta_conf,
2819 uint16_t idx, shift;
2820 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2822 PMD_INIT_FUNC_TRACE();
2823 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2824 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2825 "(%d) doesn't match the number hardware can supported "
2826 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2830 for (i = 0; i < ETH_RSS_RETA_SIZE_128; i += IXGBE_4_BIT_WIDTH) {
2831 idx = i / RTE_RETA_GROUP_SIZE;
2832 shift = i % RTE_RETA_GROUP_SIZE;
2833 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2838 reta = IXGBE_READ_REG(hw, IXGBE_RETA(i >> 2));
2839 for (j = 0; j < IXGBE_4_BIT_WIDTH; j++) {
2840 if (mask & (0x1 << j))
2841 reta_conf[idx].reta[shift + j] =
2842 ((reta >> (CHAR_BIT * j)) &
2851 ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
2852 uint32_t index, uint32_t pool)
2854 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2855 uint32_t enable_addr = 1;
2857 ixgbe_set_rar(hw, index, mac_addr->addr_bytes, pool, enable_addr);
2861 ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index)
2863 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2865 ixgbe_clear_rar(hw, index);
2869 ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
2873 struct ixgbe_hw *hw;
2874 struct rte_eth_dev_info dev_info;
2875 uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
2877 ixgbe_dev_info_get(dev, &dev_info);
2879 /* check that mtu is within the allowed range */
2880 if ((mtu < ETHER_MIN_MTU) || (frame_size > dev_info.max_rx_pktlen))
2883 /* refuse mtu that requires the support of scattered packets when this
2884 * feature has not been enabled before. */
2885 if (!dev->data->scattered_rx &&
2886 (frame_size + 2 * IXGBE_VLAN_TAG_SIZE >
2887 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
2890 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2891 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2893 /* switch to jumbo mode if needed */
2894 if (frame_size > ETHER_MAX_LEN) {
2895 dev->data->dev_conf.rxmode.jumbo_frame = 1;
2896 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2898 dev->data->dev_conf.rxmode.jumbo_frame = 0;
2899 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
2901 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2903 /* update max frame size */
2904 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
2906 maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
2907 maxfrs &= 0x0000FFFF;
2908 maxfrs |= (dev->data->dev_conf.rxmode.max_rx_pkt_len << 16);
2909 IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, maxfrs);
2915 * Virtual Function operations
2918 ixgbevf_intr_disable(struct ixgbe_hw *hw)
2920 PMD_INIT_FUNC_TRACE();
2922 /* Clear interrupt mask to stop from interrupts being generated */
2923 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
2925 IXGBE_WRITE_FLUSH(hw);
2929 ixgbevf_dev_configure(struct rte_eth_dev *dev)
2931 struct rte_eth_conf* conf = &dev->data->dev_conf;
2933 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
2934 dev->data->port_id);
2937 * VF has no ability to enable/disable HW CRC
2938 * Keep the persistent behavior the same as Host PF
2940 #ifndef RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC
2941 if (!conf->rxmode.hw_strip_crc) {
2942 PMD_INIT_LOG(INFO, "VF can't disable HW CRC Strip");
2943 conf->rxmode.hw_strip_crc = 1;
2946 if (conf->rxmode.hw_strip_crc) {
2947 PMD_INIT_LOG(INFO, "VF can't enable HW CRC Strip");
2948 conf->rxmode.hw_strip_crc = 0;
2956 ixgbevf_dev_start(struct rte_eth_dev *dev)
2958 struct ixgbe_hw *hw =
2959 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2962 PMD_INIT_FUNC_TRACE();
2964 hw->mac.ops.reset_hw(hw);
2965 hw->mac.get_link_status = true;
2967 /* negotiate mailbox API version to use with the PF. */
2968 ixgbevf_negotiate_api(hw);
2970 ixgbevf_dev_tx_init(dev);
2972 /* This can fail when allocating mbufs for descriptor rings */
2973 err = ixgbevf_dev_rx_init(dev);
2975 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
2976 ixgbe_dev_clear_queues(dev);
2981 ixgbevf_set_vfta_all(dev,1);
2984 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
2985 ETH_VLAN_EXTEND_MASK;
2986 ixgbevf_vlan_offload_set(dev, mask);
2988 ixgbevf_dev_rxtx_start(dev);
2994 ixgbevf_dev_stop(struct rte_eth_dev *dev)
2996 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2998 PMD_INIT_FUNC_TRACE();
3000 hw->adapter_stopped = TRUE;
3001 ixgbe_stop_adapter(hw);
3004 * Clear what we set, but we still keep shadow_vfta to
3005 * restore after device starts
3007 ixgbevf_set_vfta_all(dev,0);
3009 /* Clear stored conf */
3010 dev->data->scattered_rx = 0;
3012 ixgbe_dev_clear_queues(dev);
3016 ixgbevf_dev_close(struct rte_eth_dev *dev)
3018 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3020 PMD_INIT_FUNC_TRACE();
3024 ixgbevf_dev_stop(dev);
3026 /* reprogram the RAR[0] in case user changed it. */
3027 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
3030 static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
3032 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3033 struct ixgbe_vfta * shadow_vfta =
3034 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3035 int i = 0, j = 0, vfta = 0, mask = 1;
3037 for (i = 0; i < IXGBE_VFTA_SIZE; i++){
3038 vfta = shadow_vfta->vfta[i];
3041 for (j = 0; j < 32; j++){
3043 ixgbe_set_vfta(hw, (i<<5)+j, 0, on);
3052 ixgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3054 struct ixgbe_hw *hw =
3055 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3056 struct ixgbe_vfta * shadow_vfta =
3057 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3058 uint32_t vid_idx = 0;
3059 uint32_t vid_bit = 0;
3062 PMD_INIT_FUNC_TRACE();
3064 /* vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf */
3065 ret = ixgbe_set_vfta(hw, vlan_id, 0, !!on);
3067 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
3070 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
3071 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
3073 /* Save what we set and retore it after device reset */
3075 shadow_vfta->vfta[vid_idx] |= vid_bit;
3077 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
3083 ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
3085 struct ixgbe_hw *hw =
3086 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3089 PMD_INIT_FUNC_TRACE();
3091 if(queue >= hw->mac.max_rx_queues)
3094 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
3096 ctrl |= IXGBE_RXDCTL_VME;
3098 ctrl &= ~IXGBE_RXDCTL_VME;
3099 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
3101 ixgbe_vlan_hw_strip_bitmap_set( dev, queue, on);
3105 ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
3107 struct ixgbe_hw *hw =
3108 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3112 /* VF function only support hw strip feature, others are not support */
3113 if(mask & ETH_VLAN_STRIP_MASK){
3114 on = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
3116 for(i=0; i < hw->mac.max_rx_queues; i++)
3117 ixgbevf_vlan_strip_queue_set(dev,i,on);
3122 ixgbe_vmdq_mode_check(struct ixgbe_hw *hw)
3126 /* we only need to do this if VMDq is enabled */
3127 reg_val = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3128 if (!(reg_val & IXGBE_VT_CTL_VT_ENABLE)) {
3129 PMD_INIT_LOG(ERR, "VMDq must be enabled for this setting");
3137 ixgbe_uta_vector(struct ixgbe_hw *hw, struct ether_addr* uc_addr)
3139 uint32_t vector = 0;
3140 switch (hw->mac.mc_filter_type) {
3141 case 0: /* use bits [47:36] of the address */
3142 vector = ((uc_addr->addr_bytes[4] >> 4) |
3143 (((uint16_t)uc_addr->addr_bytes[5]) << 4));
3145 case 1: /* use bits [46:35] of the address */
3146 vector = ((uc_addr->addr_bytes[4] >> 3) |
3147 (((uint16_t)uc_addr->addr_bytes[5]) << 5));
3149 case 2: /* use bits [45:34] of the address */
3150 vector = ((uc_addr->addr_bytes[4] >> 2) |
3151 (((uint16_t)uc_addr->addr_bytes[5]) << 6));
3153 case 3: /* use bits [43:32] of the address */
3154 vector = ((uc_addr->addr_bytes[4]) |
3155 (((uint16_t)uc_addr->addr_bytes[5]) << 8));
3157 default: /* Invalid mc_filter_type */
3161 /* vector can only be 12-bits or boundary will be exceeded */
3167 ixgbe_uc_hash_table_set(struct rte_eth_dev *dev,struct ether_addr* mac_addr,
3175 const uint32_t ixgbe_uta_idx_mask = 0x7F;
3176 const uint32_t ixgbe_uta_bit_shift = 5;
3177 const uint32_t ixgbe_uta_bit_mask = (0x1 << ixgbe_uta_bit_shift) - 1;
3178 const uint32_t bit1 = 0x1;
3180 struct ixgbe_hw *hw =
3181 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3182 struct ixgbe_uta_info *uta_info =
3183 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
3185 /* The UTA table only exists on 82599 hardware and newer */
3186 if (hw->mac.type < ixgbe_mac_82599EB)
3189 vector = ixgbe_uta_vector(hw,mac_addr);
3190 uta_idx = (vector >> ixgbe_uta_bit_shift) & ixgbe_uta_idx_mask;
3191 uta_shift = vector & ixgbe_uta_bit_mask;
3193 rc = ((uta_info->uta_shadow[uta_idx] >> uta_shift & bit1) != 0);
3197 reg_val = IXGBE_READ_REG(hw, IXGBE_UTA(uta_idx));
3199 uta_info->uta_in_use++;
3200 reg_val |= (bit1 << uta_shift);
3201 uta_info->uta_shadow[uta_idx] |= (bit1 << uta_shift);
3203 uta_info->uta_in_use--;
3204 reg_val &= ~(bit1 << uta_shift);
3205 uta_info->uta_shadow[uta_idx] &= ~(bit1 << uta_shift);
3208 IXGBE_WRITE_REG(hw, IXGBE_UTA(uta_idx), reg_val);
3210 if (uta_info->uta_in_use > 0)
3211 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
3212 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
3214 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,hw->mac.mc_filter_type);
3220 ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on)
3223 struct ixgbe_hw *hw =
3224 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3225 struct ixgbe_uta_info *uta_info =
3226 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
3228 /* The UTA table only exists on 82599 hardware and newer */
3229 if (hw->mac.type < ixgbe_mac_82599EB)
3233 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
3234 uta_info->uta_shadow[i] = ~0;
3235 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
3238 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
3239 uta_info->uta_shadow[i] = 0;
3240 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
3248 ixgbe_convert_vm_rx_mask_to_val(uint16_t rx_mask, uint32_t orig_val)
3250 uint32_t new_val = orig_val;
3252 if (rx_mask & ETH_VMDQ_ACCEPT_UNTAG)
3253 new_val |= IXGBE_VMOLR_AUPE;
3254 if (rx_mask & ETH_VMDQ_ACCEPT_HASH_MC)
3255 new_val |= IXGBE_VMOLR_ROMPE;
3256 if (rx_mask & ETH_VMDQ_ACCEPT_HASH_UC)
3257 new_val |= IXGBE_VMOLR_ROPE;
3258 if (rx_mask & ETH_VMDQ_ACCEPT_BROADCAST)
3259 new_val |= IXGBE_VMOLR_BAM;
3260 if (rx_mask & ETH_VMDQ_ACCEPT_MULTICAST)
3261 new_val |= IXGBE_VMOLR_MPE;
3267 ixgbe_set_pool_rx_mode(struct rte_eth_dev *dev, uint16_t pool,
3268 uint16_t rx_mask, uint8_t on)
3272 struct ixgbe_hw *hw =
3273 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3274 uint32_t vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
3276 if (hw->mac.type == ixgbe_mac_82598EB) {
3277 PMD_INIT_LOG(ERR, "setting VF receive mode set should be done"
3278 " on 82599 hardware and newer");
3281 if (ixgbe_vmdq_mode_check(hw) < 0)
3284 val = ixgbe_convert_vm_rx_mask_to_val(rx_mask, val);
3291 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
3297 ixgbe_set_pool_rx(struct rte_eth_dev *dev, uint16_t pool, uint8_t on)
3301 const uint8_t bit1 = 0x1;
3303 struct ixgbe_hw *hw =
3304 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3306 if (ixgbe_vmdq_mode_check(hw) < 0)
3309 addr = IXGBE_VFRE(pool >= ETH_64_POOLS/2);
3310 reg = IXGBE_READ_REG(hw, addr);
3318 IXGBE_WRITE_REG(hw, addr,reg);
3324 ixgbe_set_pool_tx(struct rte_eth_dev *dev, uint16_t pool, uint8_t on)
3328 const uint8_t bit1 = 0x1;
3330 struct ixgbe_hw *hw =
3331 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3333 if (ixgbe_vmdq_mode_check(hw) < 0)
3336 addr = IXGBE_VFTE(pool >= ETH_64_POOLS/2);
3337 reg = IXGBE_READ_REG(hw, addr);
3345 IXGBE_WRITE_REG(hw, addr,reg);
3351 ixgbe_set_pool_vlan_filter(struct rte_eth_dev *dev, uint16_t vlan,
3352 uint64_t pool_mask, uint8_t vlan_on)
3356 struct ixgbe_hw *hw =
3357 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3359 if (ixgbe_vmdq_mode_check(hw) < 0)
3361 for (pool_idx = 0; pool_idx < ETH_64_POOLS; pool_idx++) {
3362 if (pool_mask & ((uint64_t)(1ULL << pool_idx)))
3363 ret = hw->mac.ops.set_vfta(hw,vlan,pool_idx,vlan_on);
3372 ixgbe_mirror_rule_set(struct rte_eth_dev *dev,
3373 struct rte_eth_vmdq_mirror_conf *mirror_conf,
3374 uint8_t rule_id, uint8_t on)
3376 uint32_t mr_ctl,vlvf;
3377 uint32_t mp_lsb = 0;
3378 uint32_t mv_msb = 0;
3379 uint32_t mv_lsb = 0;
3380 uint32_t mp_msb = 0;
3383 uint64_t vlan_mask = 0;
3385 const uint8_t pool_mask_offset = 32;
3386 const uint8_t vlan_mask_offset = 32;
3387 const uint8_t dst_pool_offset = 8;
3388 const uint8_t rule_mr_offset = 4;
3389 const uint8_t mirror_rule_mask= 0x0F;
3391 struct ixgbe_mirror_info *mr_info =
3392 (IXGBE_DEV_PRIVATE_TO_PFDATA(dev->data->dev_private));
3393 struct ixgbe_hw *hw =
3394 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3396 if (ixgbe_vmdq_mode_check(hw) < 0)
3399 /* Check if vlan mask is valid */
3400 if ((mirror_conf->rule_type_mask & ETH_VMDQ_VLAN_MIRROR) && (on)) {
3401 if (mirror_conf->vlan.vlan_mask == 0)
3405 /* Check if vlan id is valid and find conresponding VLAN ID index in VLVF */
3406 if (mirror_conf->rule_type_mask & ETH_VMDQ_VLAN_MIRROR) {
3407 for (i = 0;i < IXGBE_VLVF_ENTRIES; i++) {
3408 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
3409 /* search vlan id related pool vlan filter index */
3410 reg_index = ixgbe_find_vlvf_slot(hw,
3411 mirror_conf->vlan.vlan_id[i]);
3414 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(reg_index));
3415 if ((vlvf & IXGBE_VLVF_VIEN) &&
3416 ((vlvf & IXGBE_VLVF_VLANID_MASK)
3417 == mirror_conf->vlan.vlan_id[i]))
3418 vlan_mask |= (1ULL << reg_index);
3425 mv_lsb = vlan_mask & 0xFFFFFFFF;
3426 mv_msb = vlan_mask >> vlan_mask_offset;
3428 mr_info->mr_conf[rule_id].vlan.vlan_mask =
3429 mirror_conf->vlan.vlan_mask;
3430 for(i = 0 ;i < ETH_VMDQ_MAX_VLAN_FILTERS; i++) {
3431 if(mirror_conf->vlan.vlan_mask & (1ULL << i))
3432 mr_info->mr_conf[rule_id].vlan.vlan_id[i] =
3433 mirror_conf->vlan.vlan_id[i];
3438 mr_info->mr_conf[rule_id].vlan.vlan_mask = 0;
3439 for(i = 0 ;i < ETH_VMDQ_MAX_VLAN_FILTERS; i++)
3440 mr_info->mr_conf[rule_id].vlan.vlan_id[i] = 0;
3445 * if enable pool mirror, write related pool mask register,if disable
3446 * pool mirror, clear PFMRVM register
3448 if (mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) {
3450 mp_lsb = mirror_conf->pool_mask & 0xFFFFFFFF;
3451 mp_msb = mirror_conf->pool_mask >> pool_mask_offset;
3452 mr_info->mr_conf[rule_id].pool_mask =
3453 mirror_conf->pool_mask;
3458 mr_info->mr_conf[rule_id].pool_mask = 0;
3462 /* read mirror control register and recalculate it */
3463 mr_ctl = IXGBE_READ_REG(hw,IXGBE_MRCTL(rule_id));
3466 mr_ctl |= mirror_conf->rule_type_mask;
3467 mr_ctl &= mirror_rule_mask;
3468 mr_ctl |= mirror_conf->dst_pool << dst_pool_offset;
3470 mr_ctl &= ~(mirror_conf->rule_type_mask & mirror_rule_mask);
3472 mr_info->mr_conf[rule_id].rule_type_mask = (uint8_t)(mr_ctl & mirror_rule_mask);
3473 mr_info->mr_conf[rule_id].dst_pool = mirror_conf->dst_pool;
3475 /* write mirrror control register */
3476 IXGBE_WRITE_REG(hw, IXGBE_MRCTL(rule_id), mr_ctl);
3478 /* write pool mirrror control register */
3479 if (mirror_conf->rule_type_mask & ETH_VMDQ_POOL_MIRROR) {
3480 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id), mp_lsb);
3481 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id + rule_mr_offset),
3484 /* write VLAN mirrror control register */
3485 if (mirror_conf->rule_type_mask & ETH_VMDQ_VLAN_MIRROR) {
3486 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id), mv_lsb);
3487 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id + rule_mr_offset),
3495 ixgbe_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t rule_id)
3498 uint32_t lsb_val = 0;
3499 uint32_t msb_val = 0;
3500 const uint8_t rule_mr_offset = 4;
3502 struct ixgbe_hw *hw =
3503 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3504 struct ixgbe_mirror_info *mr_info =
3505 (IXGBE_DEV_PRIVATE_TO_PFDATA(dev->data->dev_private));
3507 if (ixgbe_vmdq_mode_check(hw) < 0)
3510 memset(&mr_info->mr_conf[rule_id], 0,
3511 sizeof(struct rte_eth_vmdq_mirror_conf));
3513 /* clear PFVMCTL register */
3514 IXGBE_WRITE_REG(hw, IXGBE_MRCTL(rule_id), mr_ctl);
3516 /* clear pool mask register */
3517 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id), lsb_val);
3518 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id + rule_mr_offset), msb_val);
3520 /* clear vlan mask register */
3521 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id), lsb_val);
3522 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id + rule_mr_offset), msb_val);
3527 static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
3528 uint16_t queue_idx, uint16_t tx_rate)
3530 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3531 uint32_t rf_dec, rf_int;
3533 uint16_t link_speed = dev->data->dev_link.link_speed;
3535 if (queue_idx >= hw->mac.max_tx_queues)
3539 /* Calculate the rate factor values to set */
3540 rf_int = (uint32_t)link_speed / (uint32_t)tx_rate;
3541 rf_dec = (uint32_t)link_speed % (uint32_t)tx_rate;
3542 rf_dec = (rf_dec << IXGBE_RTTBCNRC_RF_INT_SHIFT) / tx_rate;
3544 bcnrc_val = IXGBE_RTTBCNRC_RS_ENA;
3545 bcnrc_val |= ((rf_int << IXGBE_RTTBCNRC_RF_INT_SHIFT) &
3546 IXGBE_RTTBCNRC_RF_INT_MASK_M);
3547 bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK);
3553 * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
3554 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported, otherwise
3557 if ((dev->data->dev_conf.rxmode.jumbo_frame == 1) &&
3558 (dev->data->dev_conf.rxmode.max_rx_pkt_len >=
3559 IXGBE_MAX_JUMBO_FRAME_SIZE))
3560 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM,
3561 IXGBE_MMW_SIZE_JUMBO_FRAME);
3563 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM,
3564 IXGBE_MMW_SIZE_DEFAULT);
3566 /* Set RTTBCNRC of queue X */
3567 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_idx);
3568 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
3569 IXGBE_WRITE_FLUSH(hw);
3574 static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
3575 uint16_t tx_rate, uint64_t q_msk)
3577 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3578 struct ixgbe_vf_info *vfinfo =
3579 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
3580 uint8_t nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
3581 uint32_t queue_stride =
3582 IXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
3583 uint32_t queue_idx = vf * queue_stride, idx = 0, vf_idx;
3584 uint32_t queue_end = queue_idx + nb_q_per_pool - 1;
3585 uint16_t total_rate = 0;
3587 if (queue_end >= hw->mac.max_tx_queues)
3590 if (vfinfo != NULL) {
3591 for (vf_idx = 0; vf_idx < dev->pci_dev->max_vfs; vf_idx++) {
3594 for (idx = 0; idx < RTE_DIM(vfinfo[vf_idx].tx_rate);
3596 total_rate += vfinfo[vf_idx].tx_rate[idx];
3601 /* Store tx_rate for this vf. */
3602 for (idx = 0; idx < nb_q_per_pool; idx++) {
3603 if (((uint64_t)0x1 << idx) & q_msk) {
3604 if (vfinfo[vf].tx_rate[idx] != tx_rate)
3605 vfinfo[vf].tx_rate[idx] = tx_rate;
3606 total_rate += tx_rate;
3610 if (total_rate > dev->data->dev_link.link_speed) {
3612 * Reset stored TX rate of the VF if it causes exceed
3615 memset(vfinfo[vf].tx_rate, 0, sizeof(vfinfo[vf].tx_rate));
3619 /* Set RTTBCNRC of each queue/pool for vf X */
3620 for (; queue_idx <= queue_end; queue_idx++) {
3622 ixgbe_set_queue_rate_limit(dev, queue_idx, tx_rate);
3630 ixgbevf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
3631 __attribute__((unused)) uint32_t index,
3632 __attribute__((unused)) uint32_t pool)
3634 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3638 * On a 82599 VF, adding again the same MAC addr is not an idempotent
3639 * operation. Trap this case to avoid exhausting the [very limited]
3640 * set of PF resources used to store VF MAC addresses.
3642 if (memcmp(hw->mac.perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
3644 diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
3647 PMD_DRV_LOG(ERR, "Unable to add MAC address - diag=%d", diag);
3651 ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
3653 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3654 struct ether_addr *perm_addr = (struct ether_addr *) hw->mac.perm_addr;
3655 struct ether_addr *mac_addr;
3660 * The IXGBE_VF_SET_MACVLAN command of the ixgbe-pf driver does
3661 * not support the deletion of a given MAC address.
3662 * Instead, it imposes to delete all MAC addresses, then to add again
3663 * all MAC addresses with the exception of the one to be deleted.
3665 (void) ixgbevf_set_uc_addr_vf(hw, 0, NULL);
3668 * Add again all MAC addresses, with the exception of the deleted one
3669 * and of the permanent MAC address.
3671 for (i = 0, mac_addr = dev->data->mac_addrs;
3672 i < hw->mac.num_rar_entries; i++, mac_addr++) {
3673 /* Skip the deleted MAC address */
3676 /* Skip NULL MAC addresses */
3677 if (is_zero_ether_addr(mac_addr))
3679 /* Skip the permanent MAC address */
3680 if (memcmp(perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
3682 diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
3685 "Adding again MAC address "
3686 "%02x:%02x:%02x:%02x:%02x:%02x failed "
3688 mac_addr->addr_bytes[0],
3689 mac_addr->addr_bytes[1],
3690 mac_addr->addr_bytes[2],
3691 mac_addr->addr_bytes[3],
3692 mac_addr->addr_bytes[4],
3693 mac_addr->addr_bytes[5],
3698 #define MAC_TYPE_FILTER_SUP(type) do {\
3699 if ((type) != ixgbe_mac_82599EB && (type) != ixgbe_mac_X540 &&\
3700 (type) != ixgbe_mac_X550)\
3705 ixgbe_syn_filter_set(struct rte_eth_dev *dev,
3706 struct rte_eth_syn_filter *filter,
3709 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3712 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
3715 synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
3718 if (synqf & IXGBE_SYN_FILTER_ENABLE)
3720 synqf = (uint32_t)(((filter->queue << IXGBE_SYN_FILTER_QUEUE_SHIFT) &
3721 IXGBE_SYN_FILTER_QUEUE) | IXGBE_SYN_FILTER_ENABLE);
3723 if (filter->hig_pri)
3724 synqf |= IXGBE_SYN_FILTER_SYNQFP;
3726 synqf &= ~IXGBE_SYN_FILTER_SYNQFP;
3728 if (!(synqf & IXGBE_SYN_FILTER_ENABLE))
3730 synqf &= ~(IXGBE_SYN_FILTER_QUEUE | IXGBE_SYN_FILTER_ENABLE);
3732 IXGBE_WRITE_REG(hw, IXGBE_SYNQF, synqf);
3733 IXGBE_WRITE_FLUSH(hw);
3738 ixgbe_syn_filter_get(struct rte_eth_dev *dev,
3739 struct rte_eth_syn_filter *filter)
3741 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3742 uint32_t synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
3744 if (synqf & IXGBE_SYN_FILTER_ENABLE) {
3745 filter->hig_pri = (synqf & IXGBE_SYN_FILTER_SYNQFP) ? 1 : 0;
3746 filter->queue = (uint16_t)((synqf & IXGBE_SYN_FILTER_QUEUE) >> 1);
3753 ixgbe_syn_filter_handle(struct rte_eth_dev *dev,
3754 enum rte_filter_op filter_op,
3757 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3760 MAC_TYPE_FILTER_SUP(hw->mac.type);
3762 if (filter_op == RTE_ETH_FILTER_NOP)
3766 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3771 switch (filter_op) {
3772 case RTE_ETH_FILTER_ADD:
3773 ret = ixgbe_syn_filter_set(dev,
3774 (struct rte_eth_syn_filter *)arg,
3777 case RTE_ETH_FILTER_DELETE:
3778 ret = ixgbe_syn_filter_set(dev,
3779 (struct rte_eth_syn_filter *)arg,
3782 case RTE_ETH_FILTER_GET:
3783 ret = ixgbe_syn_filter_get(dev,
3784 (struct rte_eth_syn_filter *)arg);
3787 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
3796 static inline enum ixgbe_5tuple_protocol
3797 convert_protocol_type(uint8_t protocol_value)
3799 if (protocol_value == IPPROTO_TCP)
3800 return IXGBE_FILTER_PROTOCOL_TCP;
3801 else if (protocol_value == IPPROTO_UDP)
3802 return IXGBE_FILTER_PROTOCOL_UDP;
3803 else if (protocol_value == IPPROTO_SCTP)
3804 return IXGBE_FILTER_PROTOCOL_SCTP;
3806 return IXGBE_FILTER_PROTOCOL_NONE;
3810 * add a 5tuple filter
3813 * dev: Pointer to struct rte_eth_dev.
3814 * index: the index the filter allocates.
3815 * filter: ponter to the filter that will be added.
3816 * rx_queue: the queue id the filter assigned to.
3819 * - On success, zero.
3820 * - On failure, a negative value.
3823 ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
3824 struct ixgbe_5tuple_filter *filter)
3826 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3827 struct ixgbe_filter_info *filter_info =
3828 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3830 uint32_t ftqf, sdpqf;
3831 uint32_t l34timir = 0;
3832 uint8_t mask = 0xff;
3835 * look for an unused 5tuple filter index,
3836 * and insert the filter to list.
3838 for (i = 0; i < IXGBE_MAX_FTQF_FILTERS; i++) {
3839 idx = i / (sizeof(uint32_t) * NBBY);
3840 shift = i % (sizeof(uint32_t) * NBBY);
3841 if (!(filter_info->fivetuple_mask[idx] & (1 << shift))) {
3842 filter_info->fivetuple_mask[idx] |= 1 << shift;
3844 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
3850 if (i >= IXGBE_MAX_FTQF_FILTERS) {
3851 PMD_DRV_LOG(ERR, "5tuple filters are full.");
3855 sdpqf = (uint32_t)(filter->filter_info.dst_port <<
3856 IXGBE_SDPQF_DSTPORT_SHIFT);
3857 sdpqf = sdpqf | (filter->filter_info.src_port & IXGBE_SDPQF_SRCPORT);
3859 ftqf = (uint32_t)(filter->filter_info.proto &
3860 IXGBE_FTQF_PROTOCOL_MASK);
3861 ftqf |= (uint32_t)((filter->filter_info.priority &
3862 IXGBE_FTQF_PRIORITY_MASK) << IXGBE_FTQF_PRIORITY_SHIFT);
3863 if (filter->filter_info.src_ip_mask == 0) /* 0 means compare. */
3864 mask &= IXGBE_FTQF_SOURCE_ADDR_MASK;
3865 if (filter->filter_info.dst_ip_mask == 0)
3866 mask &= IXGBE_FTQF_DEST_ADDR_MASK;
3867 if (filter->filter_info.src_port_mask == 0)
3868 mask &= IXGBE_FTQF_SOURCE_PORT_MASK;
3869 if (filter->filter_info.dst_port_mask == 0)
3870 mask &= IXGBE_FTQF_DEST_PORT_MASK;
3871 if (filter->filter_info.proto_mask == 0)
3872 mask &= IXGBE_FTQF_PROTOCOL_COMP_MASK;
3873 ftqf |= mask << IXGBE_FTQF_5TUPLE_MASK_SHIFT;
3874 ftqf |= IXGBE_FTQF_POOL_MASK_EN;
3875 ftqf |= IXGBE_FTQF_QUEUE_ENABLE;
3877 IXGBE_WRITE_REG(hw, IXGBE_DAQF(idx), filter->filter_info.dst_ip);
3878 IXGBE_WRITE_REG(hw, IXGBE_SAQF(idx), filter->filter_info.src_ip);
3879 IXGBE_WRITE_REG(hw, IXGBE_SDPQF(idx), sdpqf);
3880 IXGBE_WRITE_REG(hw, IXGBE_FTQF(idx), ftqf);
3882 l34timir |= IXGBE_L34T_IMIR_RESERVE;
3883 l34timir |= (uint32_t)(filter->queue <<
3884 IXGBE_L34T_IMIR_QUEUE_SHIFT);
3885 IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(i), l34timir);
3890 * remove a 5tuple filter
3893 * dev: Pointer to struct rte_eth_dev.
3894 * filter: the pointer of the filter will be removed.
3897 ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
3898 struct ixgbe_5tuple_filter *filter)
3900 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3901 struct ixgbe_filter_info *filter_info =
3902 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3903 uint16_t index = filter->index;
3905 filter_info->fivetuple_mask[index / (sizeof(uint32_t) * NBBY)] &=
3906 ~(1 << (index % (sizeof(uint32_t) * NBBY)));
3907 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
3910 IXGBE_WRITE_REG(hw, IXGBE_DAQF(index), 0);
3911 IXGBE_WRITE_REG(hw, IXGBE_SAQF(index), 0);
3912 IXGBE_WRITE_REG(hw, IXGBE_SDPQF(index), 0);
3913 IXGBE_WRITE_REG(hw, IXGBE_FTQF(index), 0);
3914 IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(index), 0);
3918 ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
3920 struct ixgbe_hw *hw;
3921 uint32_t max_frame = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
3923 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3925 if ((mtu < ETHER_MIN_MTU) || (max_frame > ETHER_MAX_JUMBO_FRAME_LEN))
3928 /* refuse mtu that requires the support of scattered packets when this
3929 * feature has not been enabled before. */
3930 if (!dev->data->scattered_rx &&
3931 (max_frame + 2 * IXGBE_VLAN_TAG_SIZE >
3932 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
3936 * When supported by the underlying PF driver, use the IXGBE_VF_SET_MTU
3937 * request of the version 2.0 of the mailbox API.
3938 * For now, use the IXGBE_VF_SET_LPE request of the version 1.0
3939 * of the mailbox API.
3940 * This call to IXGBE_SET_LPE action won't work with ixgbe pf drivers
3941 * prior to 3.11.33 which contains the following change:
3942 * "ixgbe: Enable jumbo frames support w/ SR-IOV"
3944 ixgbevf_rlpml_set_vf(hw, max_frame);
3946 /* update max frame size */
3947 dev->data->dev_conf.rxmode.max_rx_pkt_len = max_frame;
3951 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
3952 if ((type) != ixgbe_mac_82599EB && (type) != ixgbe_mac_X540)\
3956 static inline struct ixgbe_5tuple_filter *
3957 ixgbe_5tuple_filter_lookup(struct ixgbe_5tuple_filter_list *filter_list,
3958 struct ixgbe_5tuple_filter_info *key)
3960 struct ixgbe_5tuple_filter *it;
3962 TAILQ_FOREACH(it, filter_list, entries) {
3963 if (memcmp(key, &it->filter_info,
3964 sizeof(struct ixgbe_5tuple_filter_info)) == 0) {
3971 /* translate elements in struct rte_eth_ntuple_filter to struct ixgbe_5tuple_filter_info*/
3973 ntuple_filter_to_5tuple(struct rte_eth_ntuple_filter *filter,
3974 struct ixgbe_5tuple_filter_info *filter_info)
3976 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM ||
3977 filter->priority > IXGBE_5TUPLE_MAX_PRI ||
3978 filter->priority < IXGBE_5TUPLE_MIN_PRI)
3981 switch (filter->dst_ip_mask) {
3983 filter_info->dst_ip_mask = 0;
3984 filter_info->dst_ip = filter->dst_ip;
3987 filter_info->dst_ip_mask = 1;
3990 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
3994 switch (filter->src_ip_mask) {
3996 filter_info->src_ip_mask = 0;
3997 filter_info->src_ip = filter->src_ip;
4000 filter_info->src_ip_mask = 1;
4003 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
4007 switch (filter->dst_port_mask) {
4009 filter_info->dst_port_mask = 0;
4010 filter_info->dst_port = filter->dst_port;
4013 filter_info->dst_port_mask = 1;
4016 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
4020 switch (filter->src_port_mask) {
4022 filter_info->src_port_mask = 0;
4023 filter_info->src_port = filter->src_port;
4026 filter_info->src_port_mask = 1;
4029 PMD_DRV_LOG(ERR, "invalid src_port mask.");
4033 switch (filter->proto_mask) {
4035 filter_info->proto_mask = 0;
4036 filter_info->proto =
4037 convert_protocol_type(filter->proto);
4040 filter_info->proto_mask = 1;
4043 PMD_DRV_LOG(ERR, "invalid protocol mask.");
4047 filter_info->priority = (uint8_t)filter->priority;
4052 * add or delete a ntuple filter
4055 * dev: Pointer to struct rte_eth_dev.
4056 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4057 * add: if true, add filter, if false, remove filter
4060 * - On success, zero.
4061 * - On failure, a negative value.
4064 ixgbe_add_del_ntuple_filter(struct rte_eth_dev *dev,
4065 struct rte_eth_ntuple_filter *ntuple_filter,
4068 struct ixgbe_filter_info *filter_info =
4069 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4070 struct ixgbe_5tuple_filter_info filter_5tuple;
4071 struct ixgbe_5tuple_filter *filter;
4074 if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
4075 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
4079 memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
4080 ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
4084 filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
4086 if (filter != NULL && add) {
4087 PMD_DRV_LOG(ERR, "filter exists.");
4090 if (filter == NULL && !add) {
4091 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4096 filter = rte_zmalloc("ixgbe_5tuple_filter",
4097 sizeof(struct ixgbe_5tuple_filter), 0);
4100 (void)rte_memcpy(&filter->filter_info,
4102 sizeof(struct ixgbe_5tuple_filter_info));
4103 filter->queue = ntuple_filter->queue;
4104 ret = ixgbe_add_5tuple_filter(dev, filter);
4110 ixgbe_remove_5tuple_filter(dev, filter);
4116 * get a ntuple filter
4119 * dev: Pointer to struct rte_eth_dev.
4120 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4123 * - On success, zero.
4124 * - On failure, a negative value.
4127 ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
4128 struct rte_eth_ntuple_filter *ntuple_filter)
4130 struct ixgbe_filter_info *filter_info =
4131 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4132 struct ixgbe_5tuple_filter_info filter_5tuple;
4133 struct ixgbe_5tuple_filter *filter;
4136 if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
4137 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
4141 memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
4142 ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
4146 filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
4148 if (filter == NULL) {
4149 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4152 ntuple_filter->queue = filter->queue;
4157 * ixgbe_ntuple_filter_handle - Handle operations for ntuple filter.
4158 * @dev: pointer to rte_eth_dev structure
4159 * @filter_op:operation will be taken.
4160 * @arg: a pointer to specific structure corresponding to the filter_op
4163 * - On success, zero.
4164 * - On failure, a negative value.
4167 ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
4168 enum rte_filter_op filter_op,
4171 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4174 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
4176 if (filter_op == RTE_ETH_FILTER_NOP)
4180 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4185 switch (filter_op) {
4186 case RTE_ETH_FILTER_ADD:
4187 ret = ixgbe_add_del_ntuple_filter(dev,
4188 (struct rte_eth_ntuple_filter *)arg,
4191 case RTE_ETH_FILTER_DELETE:
4192 ret = ixgbe_add_del_ntuple_filter(dev,
4193 (struct rte_eth_ntuple_filter *)arg,
4196 case RTE_ETH_FILTER_GET:
4197 ret = ixgbe_get_ntuple_filter(dev,
4198 (struct rte_eth_ntuple_filter *)arg);
4201 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4209 ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
4214 for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
4215 if (filter_info->ethertype_filters[i] == ethertype &&
4216 (filter_info->ethertype_mask & (1 << i)))
4223 ixgbe_ethertype_filter_insert(struct ixgbe_filter_info *filter_info,
4228 for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
4229 if (!(filter_info->ethertype_mask & (1 << i))) {
4230 filter_info->ethertype_mask |= 1 << i;
4231 filter_info->ethertype_filters[i] = ethertype;
4239 ixgbe_ethertype_filter_remove(struct ixgbe_filter_info *filter_info,
4242 if (idx >= IXGBE_MAX_ETQF_FILTERS)
4244 filter_info->ethertype_mask &= ~(1 << idx);
4245 filter_info->ethertype_filters[idx] = 0;
4250 ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
4251 struct rte_eth_ethertype_filter *filter,
4254 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4255 struct ixgbe_filter_info *filter_info =
4256 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4261 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
4264 if (filter->ether_type == ETHER_TYPE_IPv4 ||
4265 filter->ether_type == ETHER_TYPE_IPv6) {
4266 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
4267 " ethertype filter.", filter->ether_type);
4271 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
4272 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
4275 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
4276 PMD_DRV_LOG(ERR, "drop option is unsupported.");
4280 ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
4281 if (ret >= 0 && add) {
4282 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
4283 filter->ether_type);
4286 if (ret < 0 && !add) {
4287 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4288 filter->ether_type);
4293 ret = ixgbe_ethertype_filter_insert(filter_info,
4294 filter->ether_type);
4296 PMD_DRV_LOG(ERR, "ethertype filters are full.");
4299 etqf = IXGBE_ETQF_FILTER_EN;
4300 etqf |= (uint32_t)filter->ether_type;
4301 etqs |= (uint32_t)((filter->queue <<
4302 IXGBE_ETQS_RX_QUEUE_SHIFT) &
4303 IXGBE_ETQS_RX_QUEUE);
4304 etqs |= IXGBE_ETQS_QUEUE_EN;
4306 ret = ixgbe_ethertype_filter_remove(filter_info, (uint8_t)ret);
4310 IXGBE_WRITE_REG(hw, IXGBE_ETQF(ret), etqf);
4311 IXGBE_WRITE_REG(hw, IXGBE_ETQS(ret), etqs);
4312 IXGBE_WRITE_FLUSH(hw);
4318 ixgbe_get_ethertype_filter(struct rte_eth_dev *dev,
4319 struct rte_eth_ethertype_filter *filter)
4321 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4322 struct ixgbe_filter_info *filter_info =
4323 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4324 uint32_t etqf, etqs;
4327 ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
4329 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4330 filter->ether_type);
4334 etqf = IXGBE_READ_REG(hw, IXGBE_ETQF(ret));
4335 if (etqf & IXGBE_ETQF_FILTER_EN) {
4336 etqs = IXGBE_READ_REG(hw, IXGBE_ETQS(ret));
4337 filter->ether_type = etqf & IXGBE_ETQF_ETHERTYPE;
4339 filter->queue = (etqs & IXGBE_ETQS_RX_QUEUE) >>
4340 IXGBE_ETQS_RX_QUEUE_SHIFT;
4347 * ixgbe_ethertype_filter_handle - Handle operations for ethertype filter.
4348 * @dev: pointer to rte_eth_dev structure
4349 * @filter_op:operation will be taken.
4350 * @arg: a pointer to specific structure corresponding to the filter_op
4353 ixgbe_ethertype_filter_handle(struct rte_eth_dev *dev,
4354 enum rte_filter_op filter_op,
4357 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4360 MAC_TYPE_FILTER_SUP(hw->mac.type);
4362 if (filter_op == RTE_ETH_FILTER_NOP)
4366 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4371 switch (filter_op) {
4372 case RTE_ETH_FILTER_ADD:
4373 ret = ixgbe_add_del_ethertype_filter(dev,
4374 (struct rte_eth_ethertype_filter *)arg,
4377 case RTE_ETH_FILTER_DELETE:
4378 ret = ixgbe_add_del_ethertype_filter(dev,
4379 (struct rte_eth_ethertype_filter *)arg,
4382 case RTE_ETH_FILTER_GET:
4383 ret = ixgbe_get_ethertype_filter(dev,
4384 (struct rte_eth_ethertype_filter *)arg);
4387 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4395 ixgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
4396 enum rte_filter_type filter_type,
4397 enum rte_filter_op filter_op,
4402 switch (filter_type) {
4403 case RTE_ETH_FILTER_NTUPLE:
4404 ret = ixgbe_ntuple_filter_handle(dev, filter_op, arg);
4406 case RTE_ETH_FILTER_ETHERTYPE:
4407 ret = ixgbe_ethertype_filter_handle(dev, filter_op, arg);
4409 case RTE_ETH_FILTER_SYN:
4410 ret = ixgbe_syn_filter_handle(dev, filter_op, arg);
4412 case RTE_ETH_FILTER_FDIR:
4413 ret = ixgbe_fdir_ctrl_func(dev, filter_op, arg);
4416 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
4424 static struct rte_driver rte_ixgbe_driver = {
4426 .init = rte_ixgbe_pmd_init,
4429 static struct rte_driver rte_ixgbevf_driver = {
4431 .init = rte_ixgbevf_pmd_init,
4434 PMD_REGISTER_DRIVER(rte_ixgbe_driver);
4435 PMD_REGISTER_DRIVER(rte_ixgbevf_driver);