4 * Copyright(c) 2010-2015 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>
40 #include <rte_common.h>
41 #include <rte_interrupts.h>
42 #include <rte_byteorder.h>
44 #include <rte_debug.h>
46 #include <rte_ether.h>
47 #include <rte_ethdev.h>
48 #include <rte_memory.h>
49 #include <rte_memzone.h>
51 #include <rte_atomic.h>
52 #include <rte_malloc.h>
55 #include "e1000_logs.h"
56 #include "base/e1000_api.h"
57 #include "e1000_ethdev.h"
60 * Default values for port configuration
62 #define IGB_DEFAULT_RX_FREE_THRESH 32
63 #define IGB_DEFAULT_RX_PTHRESH 8
64 #define IGB_DEFAULT_RX_HTHRESH 8
65 #define IGB_DEFAULT_RX_WTHRESH 0
67 #define IGB_DEFAULT_TX_PTHRESH 32
68 #define IGB_DEFAULT_TX_HTHRESH 0
69 #define IGB_DEFAULT_TX_WTHRESH 0
71 /* Bit shift and mask */
72 #define IGB_4_BIT_WIDTH (CHAR_BIT / 2)
73 #define IGB_4_BIT_MASK RTE_LEN2MASK(IGB_4_BIT_WIDTH, uint8_t)
74 #define IGB_8_BIT_WIDTH CHAR_BIT
75 #define IGB_8_BIT_MASK UINT8_MAX
77 static int eth_igb_configure(struct rte_eth_dev *dev);
78 static int eth_igb_start(struct rte_eth_dev *dev);
79 static void eth_igb_stop(struct rte_eth_dev *dev);
80 static void eth_igb_close(struct rte_eth_dev *dev);
81 static void eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
82 static void eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
83 static void eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
84 static void eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
85 static int eth_igb_link_update(struct rte_eth_dev *dev,
86 int wait_to_complete);
87 static void eth_igb_stats_get(struct rte_eth_dev *dev,
88 struct rte_eth_stats *rte_stats);
89 static void eth_igb_stats_reset(struct rte_eth_dev *dev);
90 static void eth_igb_infos_get(struct rte_eth_dev *dev,
91 struct rte_eth_dev_info *dev_info);
92 static void eth_igbvf_infos_get(struct rte_eth_dev *dev,
93 struct rte_eth_dev_info *dev_info);
94 static int eth_igb_flow_ctrl_get(struct rte_eth_dev *dev,
95 struct rte_eth_fc_conf *fc_conf);
96 static int eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
97 struct rte_eth_fc_conf *fc_conf);
98 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev);
99 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
100 static int eth_igb_interrupt_action(struct rte_eth_dev *dev);
101 static void eth_igb_interrupt_handler(struct rte_intr_handle *handle,
103 static int igb_hardware_init(struct e1000_hw *hw);
104 static void igb_hw_control_acquire(struct e1000_hw *hw);
105 static void igb_hw_control_release(struct e1000_hw *hw);
106 static void igb_init_manageability(struct e1000_hw *hw);
107 static void igb_release_manageability(struct e1000_hw *hw);
109 static int eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
111 static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
112 uint16_t vlan_id, int on);
113 static void eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid_id);
114 static void eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
116 static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
117 static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
118 static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
119 static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
120 static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
121 static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
123 static int eth_igb_led_on(struct rte_eth_dev *dev);
124 static int eth_igb_led_off(struct rte_eth_dev *dev);
126 static void igb_intr_disable(struct e1000_hw *hw);
127 static int igb_get_rx_buffer_size(struct e1000_hw *hw);
128 static void eth_igb_rar_set(struct rte_eth_dev *dev,
129 struct ether_addr *mac_addr,
130 uint32_t index, uint32_t pool);
131 static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
133 static void igbvf_intr_disable(struct e1000_hw *hw);
134 static int igbvf_dev_configure(struct rte_eth_dev *dev);
135 static int igbvf_dev_start(struct rte_eth_dev *dev);
136 static void igbvf_dev_stop(struct rte_eth_dev *dev);
137 static void igbvf_dev_close(struct rte_eth_dev *dev);
138 static int eth_igbvf_link_update(struct e1000_hw *hw);
139 static void eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats);
140 static void eth_igbvf_stats_reset(struct rte_eth_dev *dev);
141 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
142 uint16_t vlan_id, int on);
143 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
144 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
145 static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
146 struct rte_eth_rss_reta_entry64 *reta_conf,
148 static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
149 struct rte_eth_rss_reta_entry64 *reta_conf,
152 static int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
153 struct rte_eth_syn_filter *filter,
155 static int eth_igb_syn_filter_get(struct rte_eth_dev *dev,
156 struct rte_eth_syn_filter *filter);
157 static int eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
158 enum rte_filter_op filter_op,
160 static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
161 struct rte_eth_ntuple_filter *ntuple_filter);
162 static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
163 struct rte_eth_ntuple_filter *ntuple_filter);
164 static int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
165 struct rte_eth_flex_filter *filter,
167 static int eth_igb_get_flex_filter(struct rte_eth_dev *dev,
168 struct rte_eth_flex_filter *filter);
169 static int eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
170 enum rte_filter_op filter_op,
172 static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
173 struct rte_eth_ntuple_filter *ntuple_filter);
174 static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
175 struct rte_eth_ntuple_filter *ntuple_filter);
176 static int igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
177 struct rte_eth_ntuple_filter *filter,
179 static int igb_get_ntuple_filter(struct rte_eth_dev *dev,
180 struct rte_eth_ntuple_filter *filter);
181 static int igb_ntuple_filter_handle(struct rte_eth_dev *dev,
182 enum rte_filter_op filter_op,
184 static int igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
185 struct rte_eth_ethertype_filter *filter,
187 static int igb_ethertype_filter_handle(struct rte_eth_dev *dev,
188 enum rte_filter_op filter_op,
190 static int igb_get_ethertype_filter(struct rte_eth_dev *dev,
191 struct rte_eth_ethertype_filter *filter);
192 static int eth_igb_filter_ctrl(struct rte_eth_dev *dev,
193 enum rte_filter_type filter_type,
194 enum rte_filter_op filter_op,
197 static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
198 struct ether_addr *mc_addr_set,
199 uint32_t nb_mc_addr);
202 * Define VF Stats MACRO for Non "cleared on read" register
204 #define UPDATE_VF_STAT(reg, last, cur) \
206 u32 latest = E1000_READ_REG(hw, reg); \
207 cur += latest - last; \
212 #define IGB_FC_PAUSE_TIME 0x0680
213 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
214 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
216 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
218 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
221 * The set of PCI devices this driver supports
223 static const struct rte_pci_id pci_id_igb_map[] = {
225 #define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
226 #include "rte_pci_dev_ids.h"
232 * The set of PCI devices this driver supports (for 82576&I350 VF)
234 static const struct rte_pci_id pci_id_igbvf_map[] = {
236 #define RTE_PCI_DEV_ID_DECL_IGBVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
237 #include "rte_pci_dev_ids.h"
242 static const struct eth_dev_ops eth_igb_ops = {
243 .dev_configure = eth_igb_configure,
244 .dev_start = eth_igb_start,
245 .dev_stop = eth_igb_stop,
246 .dev_close = eth_igb_close,
247 .promiscuous_enable = eth_igb_promiscuous_enable,
248 .promiscuous_disable = eth_igb_promiscuous_disable,
249 .allmulticast_enable = eth_igb_allmulticast_enable,
250 .allmulticast_disable = eth_igb_allmulticast_disable,
251 .link_update = eth_igb_link_update,
252 .stats_get = eth_igb_stats_get,
253 .stats_reset = eth_igb_stats_reset,
254 .dev_infos_get = eth_igb_infos_get,
255 .mtu_set = eth_igb_mtu_set,
256 .vlan_filter_set = eth_igb_vlan_filter_set,
257 .vlan_tpid_set = eth_igb_vlan_tpid_set,
258 .vlan_offload_set = eth_igb_vlan_offload_set,
259 .rx_queue_setup = eth_igb_rx_queue_setup,
260 .rx_queue_release = eth_igb_rx_queue_release,
261 .rx_queue_count = eth_igb_rx_queue_count,
262 .rx_descriptor_done = eth_igb_rx_descriptor_done,
263 .tx_queue_setup = eth_igb_tx_queue_setup,
264 .tx_queue_release = eth_igb_tx_queue_release,
265 .dev_led_on = eth_igb_led_on,
266 .dev_led_off = eth_igb_led_off,
267 .flow_ctrl_get = eth_igb_flow_ctrl_get,
268 .flow_ctrl_set = eth_igb_flow_ctrl_set,
269 .mac_addr_add = eth_igb_rar_set,
270 .mac_addr_remove = eth_igb_rar_clear,
271 .reta_update = eth_igb_rss_reta_update,
272 .reta_query = eth_igb_rss_reta_query,
273 .rss_hash_update = eth_igb_rss_hash_update,
274 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
275 .filter_ctrl = eth_igb_filter_ctrl,
276 .set_mc_addr_list = eth_igb_set_mc_addr_list,
280 * dev_ops for virtual function, bare necessities for basic vf
281 * operation have been implemented
283 static const struct eth_dev_ops igbvf_eth_dev_ops = {
284 .dev_configure = igbvf_dev_configure,
285 .dev_start = igbvf_dev_start,
286 .dev_stop = igbvf_dev_stop,
287 .dev_close = igbvf_dev_close,
288 .link_update = eth_igb_link_update,
289 .stats_get = eth_igbvf_stats_get,
290 .stats_reset = eth_igbvf_stats_reset,
291 .vlan_filter_set = igbvf_vlan_filter_set,
292 .dev_infos_get = eth_igbvf_infos_get,
293 .rx_queue_setup = eth_igb_rx_queue_setup,
294 .rx_queue_release = eth_igb_rx_queue_release,
295 .tx_queue_setup = eth_igb_tx_queue_setup,
296 .tx_queue_release = eth_igb_tx_queue_release,
297 .set_mc_addr_list = eth_igb_set_mc_addr_list,
301 * Atomically reads the link status information from global
302 * structure rte_eth_dev.
305 * - Pointer to the structure rte_eth_dev to read from.
306 * - Pointer to the buffer to be saved with the link status.
309 * - On success, zero.
310 * - On failure, negative value.
313 rte_igb_dev_atomic_read_link_status(struct rte_eth_dev *dev,
314 struct rte_eth_link *link)
316 struct rte_eth_link *dst = link;
317 struct rte_eth_link *src = &(dev->data->dev_link);
319 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
320 *(uint64_t *)src) == 0)
327 * Atomically writes the link status information into global
328 * structure rte_eth_dev.
331 * - Pointer to the structure rte_eth_dev to read from.
332 * - Pointer to the buffer to be saved with the link status.
335 * - On success, zero.
336 * - On failure, negative value.
339 rte_igb_dev_atomic_write_link_status(struct rte_eth_dev *dev,
340 struct rte_eth_link *link)
342 struct rte_eth_link *dst = &(dev->data->dev_link);
343 struct rte_eth_link *src = link;
345 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
346 *(uint64_t *)src) == 0)
353 igb_intr_enable(struct rte_eth_dev *dev)
355 struct e1000_interrupt *intr =
356 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
357 struct e1000_hw *hw =
358 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
360 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
361 E1000_WRITE_FLUSH(hw);
365 igb_intr_disable(struct e1000_hw *hw)
367 E1000_WRITE_REG(hw, E1000_IMC, ~0);
368 E1000_WRITE_FLUSH(hw);
371 static inline int32_t
372 igb_pf_reset_hw(struct e1000_hw *hw)
377 status = e1000_reset_hw(hw);
379 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
380 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
381 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
382 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
383 E1000_WRITE_FLUSH(hw);
389 igb_identify_hardware(struct rte_eth_dev *dev)
391 struct e1000_hw *hw =
392 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
394 hw->vendor_id = dev->pci_dev->id.vendor_id;
395 hw->device_id = dev->pci_dev->id.device_id;
396 hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
397 hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
399 e1000_set_mac_type(hw);
401 /* need to check if it is a vf device below */
405 igb_reset_swfw_lock(struct e1000_hw *hw)
410 * Do mac ops initialization manually here, since we will need
411 * some function pointers set by this call.
413 ret_val = e1000_init_mac_params(hw);
418 * SMBI lock should not fail in this early stage. If this is the case,
419 * it is due to an improper exit of the application.
420 * So force the release of the faulty lock.
422 if (e1000_get_hw_semaphore_generic(hw) < 0) {
423 PMD_DRV_LOG(DEBUG, "SMBI lock released");
425 e1000_put_hw_semaphore_generic(hw);
427 if (hw->mac.ops.acquire_swfw_sync != NULL) {
431 * Phy lock should not fail in this early stage. If this is the case,
432 * it is due to an improper exit of the application.
433 * So force the release of the faulty lock.
435 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
436 if (hw->bus.func > E1000_FUNC_1)
438 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
439 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
442 hw->mac.ops.release_swfw_sync(hw, mask);
445 * This one is more tricky since it is common to all ports; but
446 * swfw_sync retries last long enough (1s) to be almost sure that if
447 * lock can not be taken it is due to an improper lock of the
450 mask = E1000_SWFW_EEP_SM;
451 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
452 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
454 hw->mac.ops.release_swfw_sync(hw, mask);
457 return E1000_SUCCESS;
461 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
464 struct rte_pci_device *pci_dev;
465 struct e1000_hw *hw =
466 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
467 struct e1000_vfta * shadow_vfta =
468 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
469 struct e1000_filter_info *filter_info =
470 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
473 pci_dev = eth_dev->pci_dev;
474 eth_dev->dev_ops = ð_igb_ops;
475 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
476 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
478 /* for secondary processes, we don't initialise any further as primary
479 * has already done this work. Only check we don't need a different
481 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
482 if (eth_dev->data->scattered_rx)
483 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
487 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
489 igb_identify_hardware(eth_dev);
490 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
495 e1000_get_bus_info(hw);
497 /* Reset any pending lock */
498 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
503 /* Finish initialization */
504 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
510 hw->phy.autoneg_wait_to_complete = 0;
511 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
514 if (hw->phy.media_type == e1000_media_type_copper) {
515 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
516 hw->phy.disable_polarity_correction = 0;
517 hw->phy.ms_type = e1000_ms_hw_default;
521 * Start from a known state, this is important in reading the nvm
526 /* Make sure we have a good EEPROM before we read from it */
527 if (e1000_validate_nvm_checksum(hw) < 0) {
529 * Some PCI-E parts fail the first check due to
530 * the link being in sleep state, call it again,
531 * if it fails a second time its a real issue.
533 if (e1000_validate_nvm_checksum(hw) < 0) {
534 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
540 /* Read the permanent MAC address out of the EEPROM */
541 if (e1000_read_mac_addr(hw) != 0) {
542 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
547 /* Allocate memory for storing MAC addresses */
548 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
549 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
550 if (eth_dev->data->mac_addrs == NULL) {
551 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
552 "store MAC addresses",
553 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
558 /* Copy the permanent MAC address */
559 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
561 /* initialize the vfta */
562 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
564 /* Now initialize the hardware */
565 if (igb_hardware_init(hw) != 0) {
566 PMD_INIT_LOG(ERR, "Hardware initialization failed");
567 rte_free(eth_dev->data->mac_addrs);
568 eth_dev->data->mac_addrs = NULL;
572 hw->mac.get_link_status = 1;
574 /* Indicate SOL/IDER usage */
575 if (e1000_check_reset_block(hw) < 0) {
576 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
580 /* initialize PF if max_vfs not zero */
581 igb_pf_host_init(eth_dev);
583 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
584 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
585 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
586 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
587 E1000_WRITE_FLUSH(hw);
589 PMD_INIT_LOG(INFO, "port_id %d vendorID=0x%x deviceID=0x%x",
590 eth_dev->data->port_id, pci_dev->id.vendor_id,
591 pci_dev->id.device_id);
593 rte_intr_callback_register(&(pci_dev->intr_handle),
594 eth_igb_interrupt_handler, (void *)eth_dev);
596 /* enable uio intr after callback register */
597 rte_intr_enable(&(pci_dev->intr_handle));
599 /* enable support intr */
600 igb_intr_enable(eth_dev);
602 TAILQ_INIT(&filter_info->flex_list);
603 filter_info->flex_mask = 0;
604 TAILQ_INIT(&filter_info->twotuple_list);
605 filter_info->twotuple_mask = 0;
606 TAILQ_INIT(&filter_info->fivetuple_list);
607 filter_info->fivetuple_mask = 0;
612 igb_hw_control_release(hw);
618 * Virtual Function device init
621 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
623 struct rte_pci_device *pci_dev;
624 struct e1000_hw *hw =
625 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
628 PMD_INIT_FUNC_TRACE();
630 eth_dev->dev_ops = &igbvf_eth_dev_ops;
631 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
632 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
634 /* for secondary processes, we don't initialise any further as primary
635 * has already done this work. Only check we don't need a different
637 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
638 if (eth_dev->data->scattered_rx)
639 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
643 pci_dev = eth_dev->pci_dev;
645 hw->device_id = pci_dev->id.device_id;
646 hw->vendor_id = pci_dev->id.vendor_id;
647 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
649 /* Initialize the shared code (base driver) */
650 diag = e1000_setup_init_funcs(hw, TRUE);
652 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
657 /* init_mailbox_params */
658 hw->mbx.ops.init_params(hw);
660 /* Disable the interrupts for VF */
661 igbvf_intr_disable(hw);
663 diag = hw->mac.ops.reset_hw(hw);
665 /* Allocate memory for storing MAC addresses */
666 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
667 hw->mac.rar_entry_count, 0);
668 if (eth_dev->data->mac_addrs == NULL) {
670 "Failed to allocate %d bytes needed to store MAC "
672 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
676 /* Copy the permanent MAC address */
677 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
678 ð_dev->data->mac_addrs[0]);
680 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
682 eth_dev->data->port_id, pci_dev->id.vendor_id,
683 pci_dev->id.device_id, "igb_mac_82576_vf");
688 static struct eth_driver rte_igb_pmd = {
690 .name = "rte_igb_pmd",
691 .id_table = pci_id_igb_map,
692 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
694 .eth_dev_init = eth_igb_dev_init,
695 .dev_private_size = sizeof(struct e1000_adapter),
699 * virtual function driver struct
701 static struct eth_driver rte_igbvf_pmd = {
703 .name = "rte_igbvf_pmd",
704 .id_table = pci_id_igbvf_map,
705 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
707 .eth_dev_init = eth_igbvf_dev_init,
708 .dev_private_size = sizeof(struct e1000_adapter),
712 rte_igb_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
714 rte_eth_driver_register(&rte_igb_pmd);
719 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
721 struct e1000_hw *hw =
722 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
723 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
724 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
725 rctl |= E1000_RCTL_VFE;
726 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
730 * VF Driver initialization routine.
731 * Invoked one at EAL init time.
732 * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
735 rte_igbvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
737 PMD_INIT_FUNC_TRACE();
739 rte_eth_driver_register(&rte_igbvf_pmd);
744 eth_igb_configure(struct rte_eth_dev *dev)
746 struct e1000_interrupt *intr =
747 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
749 PMD_INIT_FUNC_TRACE();
750 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
751 PMD_INIT_FUNC_TRACE();
757 eth_igb_start(struct rte_eth_dev *dev)
759 struct e1000_hw *hw =
760 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
764 PMD_INIT_FUNC_TRACE();
766 /* Power up the phy. Needed to make the link go Up */
767 e1000_power_up_phy(hw);
770 * Packet Buffer Allocation (PBA)
771 * Writing PBA sets the receive portion of the buffer
772 * the remainder is used for the transmit buffer.
774 if (hw->mac.type == e1000_82575) {
777 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
778 E1000_WRITE_REG(hw, E1000_PBA, pba);
781 /* Put the address into the Receive Address Array */
782 e1000_rar_set(hw, hw->mac.addr, 0);
784 /* Initialize the hardware */
785 if (igb_hardware_init(hw)) {
786 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
790 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
792 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
793 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
794 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
795 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
796 E1000_WRITE_FLUSH(hw);
798 /* configure PF module if SRIOV enabled */
799 igb_pf_host_configure(dev);
801 /* Configure for OS presence */
802 igb_init_manageability(hw);
804 eth_igb_tx_init(dev);
806 /* This can fail when allocating mbufs for descriptor rings */
807 ret = eth_igb_rx_init(dev);
809 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
810 igb_dev_clear_queues(dev);
814 e1000_clear_hw_cntrs_base_generic(hw);
817 * VLAN Offload Settings
819 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
820 ETH_VLAN_EXTEND_MASK;
821 eth_igb_vlan_offload_set(dev, mask);
823 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
824 /* Enable VLAN filter since VMDq always use VLAN filter */
825 igb_vmdq_vlan_hw_filter_enable(dev);
829 * Configure the Interrupt Moderation register (EITR) with the maximum
830 * possible value (0xFFFF) to minimize "System Partial Write" issued by
831 * spurious [DMA] memory updates of RX and TX ring descriptors.
833 * With a EITR granularity of 2 microseconds in the 82576, only 7/8
834 * spurious memory updates per second should be expected.
835 * ((65535 * 2) / 1000.1000 ~= 0.131 second).
837 * Because interrupts are not used at all, the MSI-X is not activated
838 * and interrupt moderation is controlled by EITR[0].
840 * Note that having [almost] disabled memory updates of RX and TX ring
841 * descriptors through the Interrupt Moderation mechanism, memory
842 * updates of ring descriptors are now moderated by the configurable
843 * value of Write-Back Threshold registers.
845 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
846 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
847 (hw->mac.type == e1000_i211)) {
850 /* Enable all RX & TX queues in the IVAR registers */
851 ivar = (uint32_t) ((E1000_IVAR_VALID << 16) | E1000_IVAR_VALID);
852 for (i = 0; i < 8; i++)
853 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, i, ivar);
855 /* Configure EITR with the maximum possible value (0xFFFF) */
856 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
859 /* Setup link speed and duplex */
860 switch (dev->data->dev_conf.link_speed) {
861 case ETH_LINK_SPEED_AUTONEG:
862 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
863 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
864 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
865 hw->phy.autoneg_advertised = E1000_ALL_HALF_DUPLEX;
866 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
867 hw->phy.autoneg_advertised = E1000_ALL_FULL_DUPLEX;
869 goto error_invalid_config;
871 case ETH_LINK_SPEED_10:
872 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
873 hw->phy.autoneg_advertised = E1000_ALL_10_SPEED;
874 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
875 hw->phy.autoneg_advertised = ADVERTISE_10_HALF;
876 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
877 hw->phy.autoneg_advertised = ADVERTISE_10_FULL;
879 goto error_invalid_config;
881 case ETH_LINK_SPEED_100:
882 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
883 hw->phy.autoneg_advertised = E1000_ALL_100_SPEED;
884 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
885 hw->phy.autoneg_advertised = ADVERTISE_100_HALF;
886 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
887 hw->phy.autoneg_advertised = ADVERTISE_100_FULL;
889 goto error_invalid_config;
891 case ETH_LINK_SPEED_1000:
892 if ((dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX) ||
893 (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX))
894 hw->phy.autoneg_advertised = ADVERTISE_1000_FULL;
896 goto error_invalid_config;
898 case ETH_LINK_SPEED_10000:
900 goto error_invalid_config;
902 e1000_setup_link(hw);
904 /* check if lsc interrupt feature is enabled */
905 if (dev->data->dev_conf.intr_conf.lsc != 0)
906 ret = eth_igb_lsc_interrupt_setup(dev);
908 /* resume enabled intr since hw reset */
909 igb_intr_enable(dev);
911 PMD_INIT_LOG(DEBUG, "<<");
915 error_invalid_config:
916 PMD_INIT_LOG(ERR, "Invalid link_speed/link_duplex (%u/%u) for port %u",
917 dev->data->dev_conf.link_speed,
918 dev->data->dev_conf.link_duplex, dev->data->port_id);
919 igb_dev_clear_queues(dev);
923 /*********************************************************************
925 * This routine disables all traffic on the adapter by issuing a
926 * global reset on the MAC.
928 **********************************************************************/
930 eth_igb_stop(struct rte_eth_dev *dev)
932 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
933 struct e1000_filter_info *filter_info =
934 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
935 struct rte_eth_link link;
936 struct e1000_flex_filter *p_flex;
937 struct e1000_5tuple_filter *p_5tuple, *p_5tuple_next;
938 struct e1000_2tuple_filter *p_2tuple, *p_2tuple_next;
940 igb_intr_disable(hw);
942 E1000_WRITE_REG(hw, E1000_WUC, 0);
944 /* Set bit for Go Link disconnect */
945 if (hw->mac.type >= e1000_82580) {
948 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
949 phpm_reg |= E1000_82580_PM_GO_LINKD;
950 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
953 /* Power down the phy. Needed to make the link go Down */
954 if (hw->phy.media_type == e1000_media_type_copper)
955 e1000_power_down_phy(hw);
957 e1000_shutdown_fiber_serdes_link(hw);
959 igb_dev_clear_queues(dev);
961 /* clear the recorded link status */
962 memset(&link, 0, sizeof(link));
963 rte_igb_dev_atomic_write_link_status(dev, &link);
965 /* Remove all flex filters of the device */
966 while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
967 TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
970 filter_info->flex_mask = 0;
972 /* Remove all ntuple filters of the device */
973 for (p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list);
974 p_5tuple != NULL; p_5tuple = p_5tuple_next) {
975 p_5tuple_next = TAILQ_NEXT(p_5tuple, entries);
976 TAILQ_REMOVE(&filter_info->fivetuple_list,
980 filter_info->fivetuple_mask = 0;
981 for (p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list);
982 p_2tuple != NULL; p_2tuple = p_2tuple_next) {
983 p_2tuple_next = TAILQ_NEXT(p_2tuple, entries);
984 TAILQ_REMOVE(&filter_info->twotuple_list,
988 filter_info->twotuple_mask = 0;
992 eth_igb_close(struct rte_eth_dev *dev)
994 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
995 struct rte_eth_link link;
998 e1000_phy_hw_reset(hw);
999 igb_release_manageability(hw);
1000 igb_hw_control_release(hw);
1002 /* Clear bit for Go Link disconnect */
1003 if (hw->mac.type >= e1000_82580) {
1006 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1007 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1008 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1011 igb_dev_clear_queues(dev);
1013 memset(&link, 0, sizeof(link));
1014 rte_igb_dev_atomic_write_link_status(dev, &link);
1018 igb_get_rx_buffer_size(struct e1000_hw *hw)
1020 uint32_t rx_buf_size;
1021 if (hw->mac.type == e1000_82576) {
1022 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1023 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1024 /* PBS needs to be translated according to a lookup table */
1025 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1026 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1027 rx_buf_size = (rx_buf_size << 10);
1028 } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1029 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1031 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1037 /*********************************************************************
1039 * Initialize the hardware
1041 **********************************************************************/
1043 igb_hardware_init(struct e1000_hw *hw)
1045 uint32_t rx_buf_size;
1048 /* Let the firmware know the OS is in control */
1049 igb_hw_control_acquire(hw);
1052 * These parameters control the automatic generation (Tx) and
1053 * response (Rx) to Ethernet PAUSE frames.
1054 * - High water mark should allow for at least two standard size (1518)
1055 * frames to be received after sending an XOFF.
1056 * - Low water mark works best when it is very near the high water mark.
1057 * This allows the receiver to restart by sending XON when it has
1058 * drained a bit. Here we use an arbitrary value of 1500 which will
1059 * restart after one full frame is pulled from the buffer. There
1060 * could be several smaller frames in the buffer and if so they will
1061 * not trigger the XON until their total number reduces the buffer
1063 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1065 rx_buf_size = igb_get_rx_buffer_size(hw);
1067 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
1068 hw->fc.low_water = hw->fc.high_water - 1500;
1069 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1070 hw->fc.send_xon = 1;
1072 /* Set Flow control, use the tunable location if sane */
1073 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1074 hw->fc.requested_mode = igb_fc_setting;
1076 hw->fc.requested_mode = e1000_fc_none;
1078 /* Issue a global reset */
1079 igb_pf_reset_hw(hw);
1080 E1000_WRITE_REG(hw, E1000_WUC, 0);
1082 diag = e1000_init_hw(hw);
1086 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1087 e1000_get_phy_info(hw);
1088 e1000_check_for_link(hw);
1093 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1095 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1097 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1098 struct e1000_hw_stats *stats =
1099 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1102 if(hw->phy.media_type == e1000_media_type_copper ||
1103 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1105 E1000_READ_REG(hw,E1000_SYMERRS);
1106 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1109 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1110 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1111 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1112 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1114 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1115 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1116 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1117 stats->dc += E1000_READ_REG(hw, E1000_DC);
1118 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1119 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1120 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1122 ** For watchdog management we need to know if we have been
1123 ** paused during the last interval, so capture that here.
1125 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1126 stats->xoffrxc += pause_frames;
1127 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1128 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1129 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1130 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1131 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1132 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1133 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1134 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1135 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1136 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1137 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1138 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1140 /* For the 64-bit byte counters the low dword must be read first. */
1141 /* Both registers clear on the read of the high dword */
1143 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1144 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1145 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1146 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1148 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1149 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1150 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1151 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1152 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1154 stats->tor += E1000_READ_REG(hw, E1000_TORH);
1155 stats->tot += E1000_READ_REG(hw, E1000_TOTH);
1157 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1158 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1159 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1160 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1161 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1162 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1163 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1164 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1165 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1166 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1168 /* Interrupt Counts */
1170 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1171 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1172 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1173 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1174 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1175 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1176 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1177 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1178 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1180 /* Host to Card Statistics */
1182 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1183 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1184 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1185 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1186 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1187 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1188 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1189 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1190 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1191 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1192 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1193 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1194 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1195 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1197 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1198 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1199 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1200 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1201 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1202 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1204 if (rte_stats == NULL)
1208 rte_stats->ibadcrc = stats->crcerrs;
1209 rte_stats->ibadlen = stats->rlec + stats->ruc + stats->roc;
1210 rte_stats->imissed = stats->mpc;
1211 rte_stats->ierrors = rte_stats->ibadcrc +
1212 rte_stats->ibadlen +
1213 rte_stats->imissed +
1214 stats->rxerrc + stats->algnerrc + stats->cexterr;
1217 rte_stats->oerrors = stats->ecol + stats->latecol;
1219 /* XON/XOFF pause frames */
1220 rte_stats->tx_pause_xon = stats->xontxc;
1221 rte_stats->rx_pause_xon = stats->xonrxc;
1222 rte_stats->tx_pause_xoff = stats->xofftxc;
1223 rte_stats->rx_pause_xoff = stats->xoffrxc;
1225 rte_stats->ipackets = stats->gprc;
1226 rte_stats->opackets = stats->gptc;
1227 rte_stats->ibytes = stats->gorc;
1228 rte_stats->obytes = stats->gotc;
1232 eth_igb_stats_reset(struct rte_eth_dev *dev)
1234 struct e1000_hw_stats *hw_stats =
1235 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1237 /* HW registers are cleared on read */
1238 eth_igb_stats_get(dev, NULL);
1240 /* Reset software totals */
1241 memset(hw_stats, 0, sizeof(*hw_stats));
1245 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1247 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1248 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
1249 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1251 /* Good Rx packets, include VF loopback */
1252 UPDATE_VF_STAT(E1000_VFGPRC,
1253 hw_stats->last_gprc, hw_stats->gprc);
1255 /* Good Rx octets, include VF loopback */
1256 UPDATE_VF_STAT(E1000_VFGORC,
1257 hw_stats->last_gorc, hw_stats->gorc);
1259 /* Good Tx packets, include VF loopback */
1260 UPDATE_VF_STAT(E1000_VFGPTC,
1261 hw_stats->last_gptc, hw_stats->gptc);
1263 /* Good Tx octets, include VF loopback */
1264 UPDATE_VF_STAT(E1000_VFGOTC,
1265 hw_stats->last_gotc, hw_stats->gotc);
1267 /* Rx Multicst packets */
1268 UPDATE_VF_STAT(E1000_VFMPRC,
1269 hw_stats->last_mprc, hw_stats->mprc);
1271 /* Good Rx loopback packets */
1272 UPDATE_VF_STAT(E1000_VFGPRLBC,
1273 hw_stats->last_gprlbc, hw_stats->gprlbc);
1275 /* Good Rx loopback octets */
1276 UPDATE_VF_STAT(E1000_VFGORLBC,
1277 hw_stats->last_gorlbc, hw_stats->gorlbc);
1279 /* Good Tx loopback packets */
1280 UPDATE_VF_STAT(E1000_VFGPTLBC,
1281 hw_stats->last_gptlbc, hw_stats->gptlbc);
1283 /* Good Tx loopback octets */
1284 UPDATE_VF_STAT(E1000_VFGOTLBC,
1285 hw_stats->last_gotlbc, hw_stats->gotlbc);
1287 if (rte_stats == NULL)
1290 rte_stats->ipackets = hw_stats->gprc;
1291 rte_stats->ibytes = hw_stats->gorc;
1292 rte_stats->opackets = hw_stats->gptc;
1293 rte_stats->obytes = hw_stats->gotc;
1294 rte_stats->imcasts = hw_stats->mprc;
1295 rte_stats->ilbpackets = hw_stats->gprlbc;
1296 rte_stats->ilbbytes = hw_stats->gorlbc;
1297 rte_stats->olbpackets = hw_stats->gptlbc;
1298 rte_stats->olbbytes = hw_stats->gotlbc;
1303 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
1305 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
1306 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1308 /* Sync HW register to the last stats */
1309 eth_igbvf_stats_get(dev, NULL);
1311 /* reset HW current stats*/
1312 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
1313 offsetof(struct e1000_vf_stats, gprc));
1318 eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1320 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1322 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1323 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
1324 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1325 dev_info->rx_offload_capa =
1326 DEV_RX_OFFLOAD_VLAN_STRIP |
1327 DEV_RX_OFFLOAD_IPV4_CKSUM |
1328 DEV_RX_OFFLOAD_UDP_CKSUM |
1329 DEV_RX_OFFLOAD_TCP_CKSUM;
1330 dev_info->tx_offload_capa =
1331 DEV_TX_OFFLOAD_VLAN_INSERT |
1332 DEV_TX_OFFLOAD_IPV4_CKSUM |
1333 DEV_TX_OFFLOAD_UDP_CKSUM |
1334 DEV_TX_OFFLOAD_TCP_CKSUM |
1335 DEV_TX_OFFLOAD_SCTP_CKSUM;
1337 switch (hw->mac.type) {
1339 dev_info->max_rx_queues = 4;
1340 dev_info->max_tx_queues = 4;
1341 dev_info->max_vmdq_pools = 0;
1345 dev_info->max_rx_queues = 16;
1346 dev_info->max_tx_queues = 16;
1347 dev_info->max_vmdq_pools = ETH_8_POOLS;
1348 dev_info->vmdq_queue_num = 16;
1352 dev_info->max_rx_queues = 8;
1353 dev_info->max_tx_queues = 8;
1354 dev_info->max_vmdq_pools = ETH_8_POOLS;
1355 dev_info->vmdq_queue_num = 8;
1359 dev_info->max_rx_queues = 8;
1360 dev_info->max_tx_queues = 8;
1361 dev_info->max_vmdq_pools = ETH_8_POOLS;
1362 dev_info->vmdq_queue_num = 8;
1366 dev_info->max_rx_queues = 8;
1367 dev_info->max_tx_queues = 8;
1371 dev_info->max_rx_queues = 4;
1372 dev_info->max_tx_queues = 4;
1373 dev_info->max_vmdq_pools = 0;
1377 dev_info->max_rx_queues = 2;
1378 dev_info->max_tx_queues = 2;
1379 dev_info->max_vmdq_pools = 0;
1383 /* Should not happen */
1386 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
1387 dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
1389 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1391 .pthresh = IGB_DEFAULT_RX_PTHRESH,
1392 .hthresh = IGB_DEFAULT_RX_HTHRESH,
1393 .wthresh = IGB_DEFAULT_RX_WTHRESH,
1395 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
1399 dev_info->default_txconf = (struct rte_eth_txconf) {
1401 .pthresh = IGB_DEFAULT_TX_PTHRESH,
1402 .hthresh = IGB_DEFAULT_TX_HTHRESH,
1403 .wthresh = IGB_DEFAULT_TX_WTHRESH,
1410 eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1412 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1414 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1415 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
1416 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1417 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
1418 DEV_RX_OFFLOAD_IPV4_CKSUM |
1419 DEV_RX_OFFLOAD_UDP_CKSUM |
1420 DEV_RX_OFFLOAD_TCP_CKSUM;
1421 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
1422 DEV_TX_OFFLOAD_IPV4_CKSUM |
1423 DEV_TX_OFFLOAD_UDP_CKSUM |
1424 DEV_TX_OFFLOAD_TCP_CKSUM |
1425 DEV_TX_OFFLOAD_SCTP_CKSUM;
1426 switch (hw->mac.type) {
1428 dev_info->max_rx_queues = 2;
1429 dev_info->max_tx_queues = 2;
1431 case e1000_vfadapt_i350:
1432 dev_info->max_rx_queues = 1;
1433 dev_info->max_tx_queues = 1;
1436 /* Should not happen */
1440 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1442 .pthresh = IGB_DEFAULT_RX_PTHRESH,
1443 .hthresh = IGB_DEFAULT_RX_HTHRESH,
1444 .wthresh = IGB_DEFAULT_RX_WTHRESH,
1446 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
1450 dev_info->default_txconf = (struct rte_eth_txconf) {
1452 .pthresh = IGB_DEFAULT_TX_PTHRESH,
1453 .hthresh = IGB_DEFAULT_TX_HTHRESH,
1454 .wthresh = IGB_DEFAULT_TX_WTHRESH,
1460 /* return 0 means link status changed, -1 means not changed */
1462 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1464 struct e1000_hw *hw =
1465 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1466 struct rte_eth_link link, old;
1467 int link_check, count;
1470 hw->mac.get_link_status = 1;
1472 /* possible wait-to-complete in up to 9 seconds */
1473 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
1474 /* Read the real link status */
1475 switch (hw->phy.media_type) {
1476 case e1000_media_type_copper:
1477 /* Do the work to read phy */
1478 e1000_check_for_link(hw);
1479 link_check = !hw->mac.get_link_status;
1482 case e1000_media_type_fiber:
1483 e1000_check_for_link(hw);
1484 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
1488 case e1000_media_type_internal_serdes:
1489 e1000_check_for_link(hw);
1490 link_check = hw->mac.serdes_has_link;
1493 /* VF device is type_unknown */
1494 case e1000_media_type_unknown:
1495 eth_igbvf_link_update(hw);
1496 link_check = !hw->mac.get_link_status;
1502 if (link_check || wait_to_complete == 0)
1504 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
1506 memset(&link, 0, sizeof(link));
1507 rte_igb_dev_atomic_read_link_status(dev, &link);
1510 /* Now we check if a transition has happened */
1512 hw->mac.ops.get_link_up_info(hw, &link.link_speed,
1514 link.link_status = 1;
1515 } else if (!link_check) {
1516 link.link_speed = 0;
1517 link.link_duplex = 0;
1518 link.link_status = 0;
1520 rte_igb_dev_atomic_write_link_status(dev, &link);
1523 if (old.link_status == link.link_status)
1531 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
1532 * For ASF and Pass Through versions of f/w this means
1533 * that the driver is loaded.
1536 igb_hw_control_acquire(struct e1000_hw *hw)
1540 /* Let firmware know the driver has taken over */
1541 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1542 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1546 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
1547 * For ASF and Pass Through versions of f/w this means that the
1548 * driver is no longer loaded.
1551 igb_hw_control_release(struct e1000_hw *hw)
1555 /* Let firmware taken over control of h/w */
1556 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1557 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1558 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1562 * Bit of a misnomer, what this really means is
1563 * to enable OS management of the system... aka
1564 * to disable special hardware management features.
1567 igb_init_manageability(struct e1000_hw *hw)
1569 if (e1000_enable_mng_pass_thru(hw)) {
1570 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
1571 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1573 /* disable hardware interception of ARP */
1574 manc &= ~(E1000_MANC_ARP_EN);
1576 /* enable receiving management packets to the host */
1577 manc |= E1000_MANC_EN_MNG2HOST;
1578 manc2h |= 1 << 5; /* Mng Port 623 */
1579 manc2h |= 1 << 6; /* Mng Port 664 */
1580 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
1581 E1000_WRITE_REG(hw, E1000_MANC, manc);
1586 igb_release_manageability(struct e1000_hw *hw)
1588 if (e1000_enable_mng_pass_thru(hw)) {
1589 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1591 manc |= E1000_MANC_ARP_EN;
1592 manc &= ~E1000_MANC_EN_MNG2HOST;
1594 E1000_WRITE_REG(hw, E1000_MANC, manc);
1599 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
1601 struct e1000_hw *hw =
1602 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1605 rctl = E1000_READ_REG(hw, E1000_RCTL);
1606 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1607 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1611 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
1613 struct e1000_hw *hw =
1614 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1617 rctl = E1000_READ_REG(hw, E1000_RCTL);
1618 rctl &= (~E1000_RCTL_UPE);
1619 if (dev->data->all_multicast == 1)
1620 rctl |= E1000_RCTL_MPE;
1622 rctl &= (~E1000_RCTL_MPE);
1623 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1627 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
1629 struct e1000_hw *hw =
1630 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1633 rctl = E1000_READ_REG(hw, E1000_RCTL);
1634 rctl |= E1000_RCTL_MPE;
1635 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1639 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
1641 struct e1000_hw *hw =
1642 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1645 if (dev->data->promiscuous == 1)
1646 return; /* must remain in all_multicast mode */
1647 rctl = E1000_READ_REG(hw, E1000_RCTL);
1648 rctl &= (~E1000_RCTL_MPE);
1649 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1653 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1655 struct e1000_hw *hw =
1656 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1657 struct e1000_vfta * shadow_vfta =
1658 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1663 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
1664 E1000_VFTA_ENTRY_MASK);
1665 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
1666 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
1671 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
1673 /* update local VFTA copy */
1674 shadow_vfta->vfta[vid_idx] = vfta;
1680 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid)
1682 struct e1000_hw *hw =
1683 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1684 uint32_t reg = ETHER_TYPE_VLAN ;
1686 reg |= (tpid << 16);
1687 E1000_WRITE_REG(hw, E1000_VET, reg);
1691 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1693 struct e1000_hw *hw =
1694 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1697 /* Filter Table Disable */
1698 reg = E1000_READ_REG(hw, E1000_RCTL);
1699 reg &= ~E1000_RCTL_CFIEN;
1700 reg &= ~E1000_RCTL_VFE;
1701 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1705 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1707 struct e1000_hw *hw =
1708 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1709 struct e1000_vfta * shadow_vfta =
1710 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1714 /* Filter Table Enable, CFI not used for packet acceptance */
1715 reg = E1000_READ_REG(hw, E1000_RCTL);
1716 reg &= ~E1000_RCTL_CFIEN;
1717 reg |= E1000_RCTL_VFE;
1718 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1720 /* restore VFTA table */
1721 for (i = 0; i < IGB_VFTA_SIZE; i++)
1722 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
1726 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
1728 struct e1000_hw *hw =
1729 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1732 /* VLAN Mode Disable */
1733 reg = E1000_READ_REG(hw, E1000_CTRL);
1734 reg &= ~E1000_CTRL_VME;
1735 E1000_WRITE_REG(hw, E1000_CTRL, reg);
1739 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
1741 struct e1000_hw *hw =
1742 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1745 /* VLAN Mode Enable */
1746 reg = E1000_READ_REG(hw, E1000_CTRL);
1747 reg |= E1000_CTRL_VME;
1748 E1000_WRITE_REG(hw, E1000_CTRL, reg);
1752 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
1754 struct e1000_hw *hw =
1755 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1758 /* CTRL_EXT: Extended VLAN */
1759 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1760 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
1761 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1763 /* Update maximum packet length */
1764 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
1765 E1000_WRITE_REG(hw, E1000_RLPML,
1766 dev->data->dev_conf.rxmode.max_rx_pkt_len +
1771 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
1773 struct e1000_hw *hw =
1774 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1777 /* CTRL_EXT: Extended VLAN */
1778 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1779 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
1780 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1782 /* Update maximum packet length */
1783 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
1784 E1000_WRITE_REG(hw, E1000_RLPML,
1785 dev->data->dev_conf.rxmode.max_rx_pkt_len +
1790 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1792 if(mask & ETH_VLAN_STRIP_MASK){
1793 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1794 igb_vlan_hw_strip_enable(dev);
1796 igb_vlan_hw_strip_disable(dev);
1799 if(mask & ETH_VLAN_FILTER_MASK){
1800 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1801 igb_vlan_hw_filter_enable(dev);
1803 igb_vlan_hw_filter_disable(dev);
1806 if(mask & ETH_VLAN_EXTEND_MASK){
1807 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1808 igb_vlan_hw_extend_enable(dev);
1810 igb_vlan_hw_extend_disable(dev);
1816 * It enables the interrupt mask and then enable the interrupt.
1819 * Pointer to struct rte_eth_dev.
1822 * - On success, zero.
1823 * - On failure, a negative value.
1826 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev)
1828 struct e1000_interrupt *intr =
1829 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1831 intr->mask |= E1000_ICR_LSC;
1837 * It reads ICR and gets interrupt causes, check it and set a bit flag
1838 * to update link status.
1841 * Pointer to struct rte_eth_dev.
1844 * - On success, zero.
1845 * - On failure, a negative value.
1848 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
1851 struct e1000_hw *hw =
1852 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1853 struct e1000_interrupt *intr =
1854 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1856 igb_intr_disable(hw);
1858 /* read-on-clear nic registers here */
1859 icr = E1000_READ_REG(hw, E1000_ICR);
1862 if (icr & E1000_ICR_LSC) {
1863 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1866 if (icr & E1000_ICR_VMMB)
1867 intr->flags |= E1000_FLAG_MAILBOX;
1873 * It executes link_update after knowing an interrupt is prsent.
1876 * Pointer to struct rte_eth_dev.
1879 * - On success, zero.
1880 * - On failure, a negative value.
1883 eth_igb_interrupt_action(struct rte_eth_dev *dev)
1885 struct e1000_hw *hw =
1886 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1887 struct e1000_interrupt *intr =
1888 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1889 uint32_t tctl, rctl;
1890 struct rte_eth_link link;
1893 if (intr->flags & E1000_FLAG_MAILBOX) {
1894 igb_pf_mbx_process(dev);
1895 intr->flags &= ~E1000_FLAG_MAILBOX;
1898 igb_intr_enable(dev);
1899 rte_intr_enable(&(dev->pci_dev->intr_handle));
1901 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
1902 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
1904 /* set get_link_status to check register later */
1905 hw->mac.get_link_status = 1;
1906 ret = eth_igb_link_update(dev, 0);
1908 /* check if link has changed */
1912 memset(&link, 0, sizeof(link));
1913 rte_igb_dev_atomic_read_link_status(dev, &link);
1914 if (link.link_status) {
1916 " Port %d: Link Up - speed %u Mbps - %s",
1918 (unsigned)link.link_speed,
1919 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
1920 "full-duplex" : "half-duplex");
1922 PMD_INIT_LOG(INFO, " Port %d: Link Down",
1923 dev->data->port_id);
1925 PMD_INIT_LOG(INFO, "PCI Address: %04d:%02d:%02d:%d",
1926 dev->pci_dev->addr.domain,
1927 dev->pci_dev->addr.bus,
1928 dev->pci_dev->addr.devid,
1929 dev->pci_dev->addr.function);
1930 tctl = E1000_READ_REG(hw, E1000_TCTL);
1931 rctl = E1000_READ_REG(hw, E1000_RCTL);
1932 if (link.link_status) {
1934 tctl |= E1000_TCTL_EN;
1935 rctl |= E1000_RCTL_EN;
1938 tctl &= ~E1000_TCTL_EN;
1939 rctl &= ~E1000_RCTL_EN;
1941 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1942 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1943 E1000_WRITE_FLUSH(hw);
1944 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
1951 * Interrupt handler which shall be registered at first.
1954 * Pointer to interrupt handle.
1956 * The address of parameter (struct rte_eth_dev *) regsitered before.
1962 eth_igb_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
1965 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1967 eth_igb_interrupt_get_status(dev);
1968 eth_igb_interrupt_action(dev);
1972 eth_igb_led_on(struct rte_eth_dev *dev)
1974 struct e1000_hw *hw;
1976 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1977 return (e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
1981 eth_igb_led_off(struct rte_eth_dev *dev)
1983 struct e1000_hw *hw;
1985 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1986 return (e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
1990 eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1992 struct e1000_hw *hw;
1997 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1998 fc_conf->pause_time = hw->fc.pause_time;
1999 fc_conf->high_water = hw->fc.high_water;
2000 fc_conf->low_water = hw->fc.low_water;
2001 fc_conf->send_xon = hw->fc.send_xon;
2002 fc_conf->autoneg = hw->mac.autoneg;
2005 * Return rx_pause and tx_pause status according to actual setting of
2006 * the TFCE and RFCE bits in the CTRL register.
2008 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2009 if (ctrl & E1000_CTRL_TFCE)
2014 if (ctrl & E1000_CTRL_RFCE)
2019 if (rx_pause && tx_pause)
2020 fc_conf->mode = RTE_FC_FULL;
2022 fc_conf->mode = RTE_FC_RX_PAUSE;
2024 fc_conf->mode = RTE_FC_TX_PAUSE;
2026 fc_conf->mode = RTE_FC_NONE;
2032 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2034 struct e1000_hw *hw;
2036 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
2042 uint32_t rx_buf_size;
2043 uint32_t max_high_water;
2046 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2047 if (fc_conf->autoneg != hw->mac.autoneg)
2049 rx_buf_size = igb_get_rx_buffer_size(hw);
2050 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2052 /* At least reserve one Ethernet frame for watermark */
2053 max_high_water = rx_buf_size - ETHER_MAX_LEN;
2054 if ((fc_conf->high_water > max_high_water) ||
2055 (fc_conf->high_water < fc_conf->low_water)) {
2056 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
2057 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
2061 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
2062 hw->fc.pause_time = fc_conf->pause_time;
2063 hw->fc.high_water = fc_conf->high_water;
2064 hw->fc.low_water = fc_conf->low_water;
2065 hw->fc.send_xon = fc_conf->send_xon;
2067 err = e1000_setup_link_generic(hw);
2068 if (err == E1000_SUCCESS) {
2070 /* check if we want to forward MAC frames - driver doesn't have native
2071 * capability to do that, so we'll write the registers ourselves */
2073 rctl = E1000_READ_REG(hw, E1000_RCTL);
2075 /* set or clear MFLCN.PMCF bit depending on configuration */
2076 if (fc_conf->mac_ctrl_frame_fwd != 0)
2077 rctl |= E1000_RCTL_PMCF;
2079 rctl &= ~E1000_RCTL_PMCF;
2081 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2082 E1000_WRITE_FLUSH(hw);
2087 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
2091 #define E1000_RAH_POOLSEL_SHIFT (18)
2093 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
2094 uint32_t index, __rte_unused uint32_t pool)
2096 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2099 e1000_rar_set(hw, mac_addr->addr_bytes, index);
2100 rah = E1000_READ_REG(hw, E1000_RAH(index));
2101 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
2102 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
2106 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
2108 uint8_t addr[ETHER_ADDR_LEN];
2109 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2111 memset(addr, 0, sizeof(addr));
2113 e1000_rar_set(hw, addr, index);
2117 * Virtual Function operations
2120 igbvf_intr_disable(struct e1000_hw *hw)
2122 PMD_INIT_FUNC_TRACE();
2124 /* Clear interrupt mask to stop from interrupts being generated */
2125 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
2127 E1000_WRITE_FLUSH(hw);
2131 igbvf_stop_adapter(struct rte_eth_dev *dev)
2135 struct rte_eth_dev_info dev_info;
2136 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2138 memset(&dev_info, 0, sizeof(dev_info));
2139 eth_igbvf_infos_get(dev, &dev_info);
2141 /* Clear interrupt mask to stop from interrupts being generated */
2142 igbvf_intr_disable(hw);
2144 /* Clear any pending interrupts, flush previous writes */
2145 E1000_READ_REG(hw, E1000_EICR);
2147 /* Disable the transmit unit. Each queue must be disabled. */
2148 for (i = 0; i < dev_info.max_tx_queues; i++)
2149 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
2151 /* Disable the receive unit by stopping each queue */
2152 for (i = 0; i < dev_info.max_rx_queues; i++) {
2153 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
2154 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
2155 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
2156 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
2160 /* flush all queues disables */
2161 E1000_WRITE_FLUSH(hw);
2165 static int eth_igbvf_link_update(struct e1000_hw *hw)
2167 struct e1000_mbx_info *mbx = &hw->mbx;
2168 struct e1000_mac_info *mac = &hw->mac;
2169 int ret_val = E1000_SUCCESS;
2171 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
2174 * We only want to run this if there has been a rst asserted.
2175 * in this case that could mean a link change, device reset,
2176 * or a virtual function reset
2179 /* If we were hit with a reset or timeout drop the link */
2180 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
2181 mac->get_link_status = TRUE;
2183 if (!mac->get_link_status)
2186 /* if link status is down no point in checking to see if pf is up */
2187 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
2190 /* if we passed all the tests above then the link is up and we no
2191 * longer need to check for link */
2192 mac->get_link_status = FALSE;
2200 igbvf_dev_configure(struct rte_eth_dev *dev)
2202 struct rte_eth_conf* conf = &dev->data->dev_conf;
2204 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
2205 dev->data->port_id);
2208 * VF has no ability to enable/disable HW CRC
2209 * Keep the persistent behavior the same as Host PF
2211 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
2212 if (!conf->rxmode.hw_strip_crc) {
2213 PMD_INIT_LOG(INFO, "VF can't disable HW CRC Strip");
2214 conf->rxmode.hw_strip_crc = 1;
2217 if (conf->rxmode.hw_strip_crc) {
2218 PMD_INIT_LOG(INFO, "VF can't enable HW CRC Strip");
2219 conf->rxmode.hw_strip_crc = 0;
2227 igbvf_dev_start(struct rte_eth_dev *dev)
2229 struct e1000_hw *hw =
2230 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2233 PMD_INIT_FUNC_TRACE();
2235 hw->mac.ops.reset_hw(hw);
2238 igbvf_set_vfta_all(dev,1);
2240 eth_igbvf_tx_init(dev);
2242 /* This can fail when allocating mbufs for descriptor rings */
2243 ret = eth_igbvf_rx_init(dev);
2245 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
2246 igb_dev_clear_queues(dev);
2254 igbvf_dev_stop(struct rte_eth_dev *dev)
2256 PMD_INIT_FUNC_TRACE();
2258 igbvf_stop_adapter(dev);
2261 * Clear what we set, but we still keep shadow_vfta to
2262 * restore after device starts
2264 igbvf_set_vfta_all(dev,0);
2266 igb_dev_clear_queues(dev);
2270 igbvf_dev_close(struct rte_eth_dev *dev)
2272 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2274 PMD_INIT_FUNC_TRACE();
2278 igbvf_dev_stop(dev);
2281 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
2283 struct e1000_mbx_info *mbx = &hw->mbx;
2286 /* After set vlan, vlan strip will also be enabled in igb driver*/
2287 msgbuf[0] = E1000_VF_SET_VLAN;
2289 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
2291 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
2293 return (mbx->ops.write_posted(hw, msgbuf, 2, 0));
2296 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
2298 struct e1000_hw *hw =
2299 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2300 struct e1000_vfta * shadow_vfta =
2301 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2302 int i = 0, j = 0, vfta = 0, mask = 1;
2304 for (i = 0; i < IGB_VFTA_SIZE; i++){
2305 vfta = shadow_vfta->vfta[i];
2308 for (j = 0; j < 32; j++){
2311 (uint16_t)((i<<5)+j), on);
2320 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2322 struct e1000_hw *hw =
2323 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2324 struct e1000_vfta * shadow_vfta =
2325 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2326 uint32_t vid_idx = 0;
2327 uint32_t vid_bit = 0;
2330 PMD_INIT_FUNC_TRACE();
2332 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
2333 ret = igbvf_set_vfta(hw, vlan_id, !!on);
2335 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
2338 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
2339 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
2341 /*Save what we set and retore it after device reset*/
2343 shadow_vfta->vfta[vid_idx] |= vid_bit;
2345 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
2351 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
2352 struct rte_eth_rss_reta_entry64 *reta_conf,
2357 uint16_t idx, shift;
2358 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2360 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2361 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2362 "(%d) doesn't match the number hardware can supported "
2363 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2367 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
2368 idx = i / RTE_RETA_GROUP_SIZE;
2369 shift = i % RTE_RETA_GROUP_SIZE;
2370 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2374 if (mask == IGB_4_BIT_MASK)
2377 r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
2378 for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
2379 if (mask & (0x1 << j))
2380 reta |= reta_conf[idx].reta[shift + j] <<
2383 reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
2385 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
2392 eth_igb_rss_reta_query(struct rte_eth_dev *dev,
2393 struct rte_eth_rss_reta_entry64 *reta_conf,
2398 uint16_t idx, shift;
2399 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2401 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2402 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2403 "(%d) doesn't match the number hardware can supported "
2404 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2408 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
2409 idx = i / RTE_RETA_GROUP_SIZE;
2410 shift = i % RTE_RETA_GROUP_SIZE;
2411 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2415 reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
2416 for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
2417 if (mask & (0x1 << j))
2418 reta_conf[idx].reta[shift + j] =
2419 ((reta >> (CHAR_BIT * j)) &
2427 #define MAC_TYPE_FILTER_SUP(type) do {\
2428 if ((type) != e1000_82580 && (type) != e1000_i350 &&\
2429 (type) != e1000_82576)\
2434 eth_igb_syn_filter_set(struct rte_eth_dev *dev,
2435 struct rte_eth_syn_filter *filter,
2438 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2439 uint32_t synqf, rfctl;
2441 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
2444 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
2447 if (synqf & E1000_SYN_FILTER_ENABLE)
2450 synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
2451 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
2453 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
2454 if (filter->hig_pri)
2455 rfctl |= E1000_RFCTL_SYNQFP;
2457 rfctl &= ~E1000_RFCTL_SYNQFP;
2459 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
2461 if (!(synqf & E1000_SYN_FILTER_ENABLE))
2466 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
2467 E1000_WRITE_FLUSH(hw);
2472 eth_igb_syn_filter_get(struct rte_eth_dev *dev,
2473 struct rte_eth_syn_filter *filter)
2475 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2476 uint32_t synqf, rfctl;
2478 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
2479 if (synqf & E1000_SYN_FILTER_ENABLE) {
2480 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
2481 filter->hig_pri = (rfctl & E1000_RFCTL_SYNQFP) ? 1 : 0;
2482 filter->queue = (uint8_t)((synqf & E1000_SYN_FILTER_QUEUE) >>
2483 E1000_SYN_FILTER_QUEUE_SHIFT);
2491 eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
2492 enum rte_filter_op filter_op,
2495 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2498 MAC_TYPE_FILTER_SUP(hw->mac.type);
2500 if (filter_op == RTE_ETH_FILTER_NOP)
2504 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
2509 switch (filter_op) {
2510 case RTE_ETH_FILTER_ADD:
2511 ret = eth_igb_syn_filter_set(dev,
2512 (struct rte_eth_syn_filter *)arg,
2515 case RTE_ETH_FILTER_DELETE:
2516 ret = eth_igb_syn_filter_set(dev,
2517 (struct rte_eth_syn_filter *)arg,
2520 case RTE_ETH_FILTER_GET:
2521 ret = eth_igb_syn_filter_get(dev,
2522 (struct rte_eth_syn_filter *)arg);
2525 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
2533 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
2534 if ((type) != e1000_82580 && (type) != e1000_i350)\
2538 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
2540 ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
2541 struct e1000_2tuple_filter_info *filter_info)
2543 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
2545 if (filter->priority > E1000_2TUPLE_MAX_PRI)
2546 return -EINVAL; /* filter index is out of range. */
2547 if (filter->tcp_flags > TCP_FLAG_ALL)
2548 return -EINVAL; /* flags is invalid. */
2550 switch (filter->dst_port_mask) {
2552 filter_info->dst_port_mask = 0;
2553 filter_info->dst_port = filter->dst_port;
2556 filter_info->dst_port_mask = 1;
2559 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
2563 switch (filter->proto_mask) {
2565 filter_info->proto_mask = 0;
2566 filter_info->proto = filter->proto;
2569 filter_info->proto_mask = 1;
2572 PMD_DRV_LOG(ERR, "invalid protocol mask.");
2576 filter_info->priority = (uint8_t)filter->priority;
2577 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
2578 filter_info->tcp_flags = filter->tcp_flags;
2580 filter_info->tcp_flags = 0;
2585 static inline struct e1000_2tuple_filter *
2586 igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
2587 struct e1000_2tuple_filter_info *key)
2589 struct e1000_2tuple_filter *it;
2591 TAILQ_FOREACH(it, filter_list, entries) {
2592 if (memcmp(key, &it->filter_info,
2593 sizeof(struct e1000_2tuple_filter_info)) == 0) {
2601 * igb_add_2tuple_filter - add a 2tuple filter
2604 * dev: Pointer to struct rte_eth_dev.
2605 * ntuple_filter: ponter to the filter that will be added.
2608 * - On success, zero.
2609 * - On failure, a negative value.
2612 igb_add_2tuple_filter(struct rte_eth_dev *dev,
2613 struct rte_eth_ntuple_filter *ntuple_filter)
2615 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2616 struct e1000_filter_info *filter_info =
2617 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
2618 struct e1000_2tuple_filter *filter;
2619 uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
2620 uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
2623 filter = rte_zmalloc("e1000_2tuple_filter",
2624 sizeof(struct e1000_2tuple_filter), 0);
2628 ret = ntuple_filter_to_2tuple(ntuple_filter,
2629 &filter->filter_info);
2634 if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
2635 &filter->filter_info) != NULL) {
2636 PMD_DRV_LOG(ERR, "filter exists.");
2640 filter->queue = ntuple_filter->queue;
2643 * look for an unused 2tuple filter index,
2644 * and insert the filter to list.
2646 for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
2647 if (!(filter_info->twotuple_mask & (1 << i))) {
2648 filter_info->twotuple_mask |= 1 << i;
2650 TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
2656 if (i >= E1000_MAX_TTQF_FILTERS) {
2657 PMD_DRV_LOG(ERR, "2tuple filters are full.");
2662 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
2663 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
2664 imir |= E1000_IMIR_PORT_BP;
2666 imir &= ~E1000_IMIR_PORT_BP;
2668 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
2670 ttqf |= E1000_TTQF_QUEUE_ENABLE;
2671 ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
2672 ttqf |= (uint32_t)(filter->filter_info.proto & E1000_TTQF_PROTOCOL_MASK);
2673 if (filter->filter_info.proto_mask == 0)
2674 ttqf &= ~E1000_TTQF_MASK_ENABLE;
2676 /* tcp flags bits setting. */
2677 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
2678 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
2679 imir_ext |= E1000_IMIREXT_CTRL_URG;
2680 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
2681 imir_ext |= E1000_IMIREXT_CTRL_ACK;
2682 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
2683 imir_ext |= E1000_IMIREXT_CTRL_PSH;
2684 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
2685 imir_ext |= E1000_IMIREXT_CTRL_RST;
2686 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
2687 imir_ext |= E1000_IMIREXT_CTRL_SYN;
2688 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
2689 imir_ext |= E1000_IMIREXT_CTRL_FIN;
2691 imir_ext |= E1000_IMIREXT_CTRL_BP;
2692 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
2693 E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
2694 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
2699 * igb_remove_2tuple_filter - remove a 2tuple filter
2702 * dev: Pointer to struct rte_eth_dev.
2703 * ntuple_filter: ponter to the filter that will be removed.
2706 * - On success, zero.
2707 * - On failure, a negative value.
2710 igb_remove_2tuple_filter(struct rte_eth_dev *dev,
2711 struct rte_eth_ntuple_filter *ntuple_filter)
2713 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2714 struct e1000_filter_info *filter_info =
2715 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
2716 struct e1000_2tuple_filter_info filter_2tuple;
2717 struct e1000_2tuple_filter *filter;
2720 memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
2721 ret = ntuple_filter_to_2tuple(ntuple_filter,
2726 filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
2728 if (filter == NULL) {
2729 PMD_DRV_LOG(ERR, "filter doesn't exist.");
2733 filter_info->twotuple_mask &= ~(1 << filter->index);
2734 TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
2737 E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
2738 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
2739 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
2743 static inline struct e1000_flex_filter *
2744 eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
2745 struct e1000_flex_filter_info *key)
2747 struct e1000_flex_filter *it;
2749 TAILQ_FOREACH(it, filter_list, entries) {
2750 if (memcmp(key, &it->filter_info,
2751 sizeof(struct e1000_flex_filter_info)) == 0)
2759 eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
2760 struct rte_eth_flex_filter *filter,
2763 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2764 struct e1000_filter_info *filter_info =
2765 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
2766 struct e1000_flex_filter *flex_filter, *it;
2767 uint32_t wufc, queueing, mask;
2769 uint8_t shift, i, j = 0;
2771 flex_filter = rte_zmalloc("e1000_flex_filter",
2772 sizeof(struct e1000_flex_filter), 0);
2773 if (flex_filter == NULL)
2776 flex_filter->filter_info.len = filter->len;
2777 flex_filter->filter_info.priority = filter->priority;
2778 memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
2779 for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
2781 /* reverse bits in flex filter's mask*/
2782 for (shift = 0; shift < CHAR_BIT; shift++) {
2783 if (filter->mask[i] & (0x01 << shift))
2784 mask |= (0x80 >> shift);
2786 flex_filter->filter_info.mask[i] = mask;
2789 wufc = E1000_READ_REG(hw, E1000_WUFC);
2790 if (flex_filter->index < E1000_MAX_FHFT)
2791 reg_off = E1000_FHFT(flex_filter->index);
2793 reg_off = E1000_FHFT_EXT(flex_filter->index - E1000_MAX_FHFT);
2796 if (eth_igb_flex_filter_lookup(&filter_info->flex_list,
2797 &flex_filter->filter_info) != NULL) {
2798 PMD_DRV_LOG(ERR, "filter exists.");
2799 rte_free(flex_filter);
2802 flex_filter->queue = filter->queue;
2804 * look for an unused flex filter index
2805 * and insert the filter into the list.
2807 for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
2808 if (!(filter_info->flex_mask & (1 << i))) {
2809 filter_info->flex_mask |= 1 << i;
2810 flex_filter->index = i;
2811 TAILQ_INSERT_TAIL(&filter_info->flex_list,
2817 if (i >= E1000_MAX_FLEX_FILTERS) {
2818 PMD_DRV_LOG(ERR, "flex filters are full.");
2819 rte_free(flex_filter);
2823 E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
2824 (E1000_WUFC_FLX0 << flex_filter->index));
2825 queueing = filter->len |
2826 (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
2827 (filter->priority << E1000_FHFT_QUEUEING_PRIO_SHIFT);
2828 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
2830 for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
2831 E1000_WRITE_REG(hw, reg_off,
2832 flex_filter->filter_info.dwords[j]);
2833 reg_off += sizeof(uint32_t);
2834 E1000_WRITE_REG(hw, reg_off,
2835 flex_filter->filter_info.dwords[++j]);
2836 reg_off += sizeof(uint32_t);
2837 E1000_WRITE_REG(hw, reg_off,
2838 (uint32_t)flex_filter->filter_info.mask[i]);
2839 reg_off += sizeof(uint32_t) * 2;
2843 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
2844 &flex_filter->filter_info);
2846 PMD_DRV_LOG(ERR, "filter doesn't exist.");
2847 rte_free(flex_filter);
2851 for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
2852 E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
2853 E1000_WRITE_REG(hw, E1000_WUFC, wufc &
2854 (~(E1000_WUFC_FLX0 << it->index)));
2856 filter_info->flex_mask &= ~(1 << it->index);
2857 TAILQ_REMOVE(&filter_info->flex_list, it, entries);
2859 rte_free(flex_filter);
2866 eth_igb_get_flex_filter(struct rte_eth_dev *dev,
2867 struct rte_eth_flex_filter *filter)
2869 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2870 struct e1000_filter_info *filter_info =
2871 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
2872 struct e1000_flex_filter flex_filter, *it;
2873 uint32_t wufc, queueing, wufc_en = 0;
2875 memset(&flex_filter, 0, sizeof(struct e1000_flex_filter));
2876 flex_filter.filter_info.len = filter->len;
2877 flex_filter.filter_info.priority = filter->priority;
2878 memcpy(flex_filter.filter_info.dwords, filter->bytes, filter->len);
2879 memcpy(flex_filter.filter_info.mask, filter->mask,
2880 RTE_ALIGN(filter->len, sizeof(char)) / sizeof(char));
2882 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
2883 &flex_filter.filter_info);
2885 PMD_DRV_LOG(ERR, "filter doesn't exist.");
2889 wufc = E1000_READ_REG(hw, E1000_WUFC);
2890 wufc_en = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << it->index);
2892 if ((wufc & wufc_en) == wufc_en) {
2893 uint32_t reg_off = 0;
2894 if (it->index < E1000_MAX_FHFT)
2895 reg_off = E1000_FHFT(it->index);
2897 reg_off = E1000_FHFT_EXT(it->index - E1000_MAX_FHFT);
2899 queueing = E1000_READ_REG(hw,
2900 reg_off + E1000_FHFT_QUEUEING_OFFSET);
2901 filter->len = queueing & E1000_FHFT_QUEUEING_LEN;
2902 filter->priority = (queueing & E1000_FHFT_QUEUEING_PRIO) >>
2903 E1000_FHFT_QUEUEING_PRIO_SHIFT;
2904 filter->queue = (queueing & E1000_FHFT_QUEUEING_QUEUE) >>
2905 E1000_FHFT_QUEUEING_QUEUE_SHIFT;
2912 eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
2913 enum rte_filter_op filter_op,
2916 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2917 struct rte_eth_flex_filter *filter;
2920 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
2922 if (filter_op == RTE_ETH_FILTER_NOP)
2926 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
2931 filter = (struct rte_eth_flex_filter *)arg;
2932 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN
2933 || filter->len % sizeof(uint64_t) != 0) {
2934 PMD_DRV_LOG(ERR, "filter's length is out of range");
2937 if (filter->priority > E1000_MAX_FLEX_FILTER_PRI) {
2938 PMD_DRV_LOG(ERR, "filter's priority is out of range");
2942 switch (filter_op) {
2943 case RTE_ETH_FILTER_ADD:
2944 ret = eth_igb_add_del_flex_filter(dev, filter, TRUE);
2946 case RTE_ETH_FILTER_DELETE:
2947 ret = eth_igb_add_del_flex_filter(dev, filter, FALSE);
2949 case RTE_ETH_FILTER_GET:
2950 ret = eth_igb_get_flex_filter(dev, filter);
2953 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
2961 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
2963 ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
2964 struct e1000_5tuple_filter_info *filter_info)
2966 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
2968 if (filter->priority > E1000_2TUPLE_MAX_PRI)
2969 return -EINVAL; /* filter index is out of range. */
2970 if (filter->tcp_flags > TCP_FLAG_ALL)
2971 return -EINVAL; /* flags is invalid. */
2973 switch (filter->dst_ip_mask) {
2975 filter_info->dst_ip_mask = 0;
2976 filter_info->dst_ip = filter->dst_ip;
2979 filter_info->dst_ip_mask = 1;
2982 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
2986 switch (filter->src_ip_mask) {
2988 filter_info->src_ip_mask = 0;
2989 filter_info->src_ip = filter->src_ip;
2992 filter_info->src_ip_mask = 1;
2995 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
2999 switch (filter->dst_port_mask) {
3001 filter_info->dst_port_mask = 0;
3002 filter_info->dst_port = filter->dst_port;
3005 filter_info->dst_port_mask = 1;
3008 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3012 switch (filter->src_port_mask) {
3014 filter_info->src_port_mask = 0;
3015 filter_info->src_port = filter->src_port;
3018 filter_info->src_port_mask = 1;
3021 PMD_DRV_LOG(ERR, "invalid src_port mask.");
3025 switch (filter->proto_mask) {
3027 filter_info->proto_mask = 0;
3028 filter_info->proto = filter->proto;
3031 filter_info->proto_mask = 1;
3034 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3038 filter_info->priority = (uint8_t)filter->priority;
3039 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3040 filter_info->tcp_flags = filter->tcp_flags;
3042 filter_info->tcp_flags = 0;
3047 static inline struct e1000_5tuple_filter *
3048 igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
3049 struct e1000_5tuple_filter_info *key)
3051 struct e1000_5tuple_filter *it;
3053 TAILQ_FOREACH(it, filter_list, entries) {
3054 if (memcmp(key, &it->filter_info,
3055 sizeof(struct e1000_5tuple_filter_info)) == 0) {
3063 * igb_add_5tuple_filter_82576 - add a 5tuple filter
3066 * dev: Pointer to struct rte_eth_dev.
3067 * ntuple_filter: ponter to the filter that will be added.
3070 * - On success, zero.
3071 * - On failure, a negative value.
3074 igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
3075 struct rte_eth_ntuple_filter *ntuple_filter)
3077 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3078 struct e1000_filter_info *filter_info =
3079 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3080 struct e1000_5tuple_filter *filter;
3081 uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
3082 uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3086 filter = rte_zmalloc("e1000_5tuple_filter",
3087 sizeof(struct e1000_5tuple_filter), 0);
3091 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3092 &filter->filter_info);
3098 if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
3099 &filter->filter_info) != NULL) {
3100 PMD_DRV_LOG(ERR, "filter exists.");
3104 filter->queue = ntuple_filter->queue;
3107 * look for an unused 5tuple filter index,
3108 * and insert the filter to list.
3110 for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
3111 if (!(filter_info->fivetuple_mask & (1 << i))) {
3112 filter_info->fivetuple_mask |= 1 << i;
3114 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
3120 if (i >= E1000_MAX_FTQF_FILTERS) {
3121 PMD_DRV_LOG(ERR, "5tuple filters are full.");
3126 ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
3127 if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
3128 ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
3129 if (filter->filter_info.dst_ip_mask == 0)
3130 ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
3131 if (filter->filter_info.src_port_mask == 0)
3132 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
3133 if (filter->filter_info.proto_mask == 0)
3134 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
3135 ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
3136 E1000_FTQF_QUEUE_MASK;
3137 ftqf |= E1000_FTQF_QUEUE_ENABLE;
3138 E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
3139 E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
3140 E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
3142 spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
3143 E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
3145 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3146 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3147 imir |= E1000_IMIR_PORT_BP;
3149 imir &= ~E1000_IMIR_PORT_BP;
3150 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3152 /* tcp flags bits setting. */
3153 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3154 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3155 imir_ext |= E1000_IMIREXT_CTRL_URG;
3156 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3157 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3158 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3159 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3160 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3161 imir_ext |= E1000_IMIREXT_CTRL_RST;
3162 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3163 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3164 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3165 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3167 imir_ext |= E1000_IMIREXT_CTRL_BP;
3168 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3169 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3174 * igb_remove_5tuple_filter_82576 - remove a 5tuple filter
3177 * dev: Pointer to struct rte_eth_dev.
3178 * ntuple_filter: ponter to the filter that will be removed.
3181 * - On success, zero.
3182 * - On failure, a negative value.
3185 igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
3186 struct rte_eth_ntuple_filter *ntuple_filter)
3188 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3189 struct e1000_filter_info *filter_info =
3190 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3191 struct e1000_5tuple_filter_info filter_5tuple;
3192 struct e1000_5tuple_filter *filter;
3195 memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
3196 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3201 filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
3203 if (filter == NULL) {
3204 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3208 filter_info->fivetuple_mask &= ~(1 << filter->index);
3209 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
3212 E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
3213 E1000_FTQF_VF_BP | E1000_FTQF_MASK);
3214 E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
3215 E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
3216 E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
3217 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3218 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3223 eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
3226 struct e1000_hw *hw;
3227 struct rte_eth_dev_info dev_info;
3228 uint32_t frame_size = mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN +
3231 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3233 #ifdef RTE_LIBRTE_82571_SUPPORT
3234 /* XXX: not bigger than max_rx_pktlen */
3235 if (hw->mac.type == e1000_82571)
3238 eth_igb_infos_get(dev, &dev_info);
3240 /* check that mtu is within the allowed range */
3241 if ((mtu < ETHER_MIN_MTU) ||
3242 (frame_size > dev_info.max_rx_pktlen))
3245 /* refuse mtu that requires the support of scattered packets when this
3246 * feature has not been enabled before. */
3247 if (!dev->data->scattered_rx &&
3248 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)
3251 rctl = E1000_READ_REG(hw, E1000_RCTL);
3253 /* switch to jumbo mode if needed */
3254 if (frame_size > ETHER_MAX_LEN) {
3255 dev->data->dev_conf.rxmode.jumbo_frame = 1;
3256 rctl |= E1000_RCTL_LPE;
3258 dev->data->dev_conf.rxmode.jumbo_frame = 0;
3259 rctl &= ~E1000_RCTL_LPE;
3261 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3263 /* update max frame size */
3264 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
3266 E1000_WRITE_REG(hw, E1000_RLPML,
3267 dev->data->dev_conf.rxmode.max_rx_pkt_len);
3273 * igb_add_del_ntuple_filter - add or delete a ntuple filter
3276 * dev: Pointer to struct rte_eth_dev.
3277 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
3278 * add: if true, add filter, if false, remove filter
3281 * - On success, zero.
3282 * - On failure, a negative value.
3285 igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
3286 struct rte_eth_ntuple_filter *ntuple_filter,
3289 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3292 switch (ntuple_filter->flags) {
3293 case RTE_5TUPLE_FLAGS:
3294 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3295 if (hw->mac.type != e1000_82576)
3298 ret = igb_add_5tuple_filter_82576(dev,
3301 ret = igb_remove_5tuple_filter_82576(dev,
3304 case RTE_2TUPLE_FLAGS:
3305 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3306 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
3309 ret = igb_add_2tuple_filter(dev, ntuple_filter);
3311 ret = igb_remove_2tuple_filter(dev, ntuple_filter);
3322 * igb_get_ntuple_filter - get a ntuple filter
3325 * dev: Pointer to struct rte_eth_dev.
3326 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
3329 * - On success, zero.
3330 * - On failure, a negative value.
3333 igb_get_ntuple_filter(struct rte_eth_dev *dev,
3334 struct rte_eth_ntuple_filter *ntuple_filter)
3336 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3337 struct e1000_filter_info *filter_info =
3338 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3339 struct e1000_5tuple_filter_info filter_5tuple;
3340 struct e1000_2tuple_filter_info filter_2tuple;
3341 struct e1000_5tuple_filter *p_5tuple_filter;
3342 struct e1000_2tuple_filter *p_2tuple_filter;
3345 switch (ntuple_filter->flags) {
3346 case RTE_5TUPLE_FLAGS:
3347 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3348 if (hw->mac.type != e1000_82576)
3350 memset(&filter_5tuple,
3352 sizeof(struct e1000_5tuple_filter_info));
3353 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3357 p_5tuple_filter = igb_5tuple_filter_lookup_82576(
3358 &filter_info->fivetuple_list,
3360 if (p_5tuple_filter == NULL) {
3361 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3364 ntuple_filter->queue = p_5tuple_filter->queue;
3366 case RTE_2TUPLE_FLAGS:
3367 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3368 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
3370 memset(&filter_2tuple,
3372 sizeof(struct e1000_2tuple_filter_info));
3373 ret = ntuple_filter_to_2tuple(ntuple_filter, &filter_2tuple);
3376 p_2tuple_filter = igb_2tuple_filter_lookup(
3377 &filter_info->twotuple_list,
3379 if (p_2tuple_filter == NULL) {
3380 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3383 ntuple_filter->queue = p_2tuple_filter->queue;
3394 * igb_ntuple_filter_handle - Handle operations for ntuple filter.
3395 * @dev: pointer to rte_eth_dev structure
3396 * @filter_op:operation will be taken.
3397 * @arg: a pointer to specific structure corresponding to the filter_op
3400 igb_ntuple_filter_handle(struct rte_eth_dev *dev,
3401 enum rte_filter_op filter_op,
3404 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3407 MAC_TYPE_FILTER_SUP(hw->mac.type);
3409 if (filter_op == RTE_ETH_FILTER_NOP)
3413 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3418 switch (filter_op) {
3419 case RTE_ETH_FILTER_ADD:
3420 ret = igb_add_del_ntuple_filter(dev,
3421 (struct rte_eth_ntuple_filter *)arg,
3424 case RTE_ETH_FILTER_DELETE:
3425 ret = igb_add_del_ntuple_filter(dev,
3426 (struct rte_eth_ntuple_filter *)arg,
3429 case RTE_ETH_FILTER_GET:
3430 ret = igb_get_ntuple_filter(dev,
3431 (struct rte_eth_ntuple_filter *)arg);
3434 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3442 igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
3447 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
3448 if (filter_info->ethertype_filters[i] == ethertype &&
3449 (filter_info->ethertype_mask & (1 << i)))
3456 igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
3461 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
3462 if (!(filter_info->ethertype_mask & (1 << i))) {
3463 filter_info->ethertype_mask |= 1 << i;
3464 filter_info->ethertype_filters[i] = ethertype;
3472 igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
3475 if (idx >= E1000_MAX_ETQF_FILTERS)
3477 filter_info->ethertype_mask &= ~(1 << idx);
3478 filter_info->ethertype_filters[idx] = 0;
3484 igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
3485 struct rte_eth_ethertype_filter *filter,
3488 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3489 struct e1000_filter_info *filter_info =
3490 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3494 if (filter->ether_type == ETHER_TYPE_IPv4 ||
3495 filter->ether_type == ETHER_TYPE_IPv6) {
3496 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
3497 " ethertype filter.", filter->ether_type);
3501 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
3502 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
3505 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
3506 PMD_DRV_LOG(ERR, "drop option is unsupported.");
3510 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
3511 if (ret >= 0 && add) {
3512 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
3513 filter->ether_type);
3516 if (ret < 0 && !add) {
3517 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
3518 filter->ether_type);
3523 ret = igb_ethertype_filter_insert(filter_info,
3524 filter->ether_type);
3526 PMD_DRV_LOG(ERR, "ethertype filters are full.");
3530 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
3531 etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
3532 etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
3534 ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
3538 E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
3539 E1000_WRITE_FLUSH(hw);
3545 igb_get_ethertype_filter(struct rte_eth_dev *dev,
3546 struct rte_eth_ethertype_filter *filter)
3548 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3549 struct e1000_filter_info *filter_info =
3550 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3554 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
3556 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
3557 filter->ether_type);
3561 etqf = E1000_READ_REG(hw, E1000_ETQF(ret));
3562 if (etqf & E1000_ETQF_FILTER_ENABLE) {
3563 filter->ether_type = etqf & E1000_ETQF_ETHERTYPE;
3565 filter->queue = (etqf & E1000_ETQF_QUEUE) >>
3566 E1000_ETQF_QUEUE_SHIFT;
3574 * igb_ethertype_filter_handle - Handle operations for ethertype filter.
3575 * @dev: pointer to rte_eth_dev structure
3576 * @filter_op:operation will be taken.
3577 * @arg: a pointer to specific structure corresponding to the filter_op
3580 igb_ethertype_filter_handle(struct rte_eth_dev *dev,
3581 enum rte_filter_op filter_op,
3584 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3587 MAC_TYPE_FILTER_SUP(hw->mac.type);
3589 if (filter_op == RTE_ETH_FILTER_NOP)
3593 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3598 switch (filter_op) {
3599 case RTE_ETH_FILTER_ADD:
3600 ret = igb_add_del_ethertype_filter(dev,
3601 (struct rte_eth_ethertype_filter *)arg,
3604 case RTE_ETH_FILTER_DELETE:
3605 ret = igb_add_del_ethertype_filter(dev,
3606 (struct rte_eth_ethertype_filter *)arg,
3609 case RTE_ETH_FILTER_GET:
3610 ret = igb_get_ethertype_filter(dev,
3611 (struct rte_eth_ethertype_filter *)arg);
3614 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3622 eth_igb_filter_ctrl(struct rte_eth_dev *dev,
3623 enum rte_filter_type filter_type,
3624 enum rte_filter_op filter_op,
3629 switch (filter_type) {
3630 case RTE_ETH_FILTER_NTUPLE:
3631 ret = igb_ntuple_filter_handle(dev, filter_op, arg);
3633 case RTE_ETH_FILTER_ETHERTYPE:
3634 ret = igb_ethertype_filter_handle(dev, filter_op, arg);
3636 case RTE_ETH_FILTER_SYN:
3637 ret = eth_igb_syn_filter_handle(dev, filter_op, arg);
3639 case RTE_ETH_FILTER_FLEXIBLE:
3640 ret = eth_igb_flex_filter_handle(dev, filter_op, arg);
3643 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
3652 eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
3653 struct ether_addr *mc_addr_set,
3654 uint32_t nb_mc_addr)
3656 struct e1000_hw *hw;
3658 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3659 e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
3663 static struct rte_driver pmd_igb_drv = {
3665 .init = rte_igb_pmd_init,
3668 static struct rte_driver pmd_igbvf_drv = {
3670 .init = rte_igbvf_pmd_init,
3673 PMD_REGISTER_DRIVER(pmd_igb_drv);
3674 PMD_REGISTER_DRIVER(pmd_igbvf_drv);