4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/queue.h>
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>
50 #include <rte_tailq.h>
52 #include <rte_atomic.h>
53 #include <rte_malloc.h>
56 #include "e1000_logs.h"
57 #include "e1000/e1000_api.h"
58 #include "e1000_ethdev.h"
60 static int eth_igb_configure(struct rte_eth_dev *dev);
61 static int eth_igb_start(struct rte_eth_dev *dev);
62 static void eth_igb_stop(struct rte_eth_dev *dev);
63 static void eth_igb_close(struct rte_eth_dev *dev);
64 static void eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
65 static void eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
66 static void eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
67 static void eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
68 static int eth_igb_link_update(struct rte_eth_dev *dev,
69 int wait_to_complete);
70 static void eth_igb_stats_get(struct rte_eth_dev *dev,
71 struct rte_eth_stats *rte_stats);
72 static void eth_igb_stats_reset(struct rte_eth_dev *dev);
73 static void eth_igb_infos_get(struct rte_eth_dev *dev,
74 struct rte_eth_dev_info *dev_info);
75 static int eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
76 struct rte_eth_fc_conf *fc_conf);
77 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev);
78 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
79 static int eth_igb_interrupt_action(struct rte_eth_dev *dev);
80 static void eth_igb_interrupt_handler(struct rte_intr_handle *handle,
82 static int igb_hardware_init(struct e1000_hw *hw);
83 static void igb_hw_control_acquire(struct e1000_hw *hw);
84 static void igb_hw_control_release(struct e1000_hw *hw);
85 static void igb_init_manageability(struct e1000_hw *hw);
86 static void igb_release_manageability(struct e1000_hw *hw);
88 static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
89 uint16_t vlan_id, int on);
90 static void eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid_id);
91 static void eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
93 static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
94 static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
95 static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
96 static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
97 static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
98 static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
100 static int eth_igb_led_on(struct rte_eth_dev *dev);
101 static int eth_igb_led_off(struct rte_eth_dev *dev);
103 static void igb_intr_disable(struct e1000_hw *hw);
104 static int igb_get_rx_buffer_size(struct e1000_hw *hw);
105 static void eth_igb_rar_set(struct rte_eth_dev *dev,
106 struct ether_addr *mac_addr,
107 uint32_t index, uint32_t pool);
108 static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
110 static void igbvf_intr_disable(struct e1000_hw *hw);
111 static int igbvf_dev_configure(struct rte_eth_dev *dev);
112 static int igbvf_dev_start(struct rte_eth_dev *dev);
113 static void igbvf_dev_stop(struct rte_eth_dev *dev);
114 static void igbvf_dev_close(struct rte_eth_dev *dev);
115 static int eth_igbvf_link_update(struct e1000_hw *hw);
116 static void eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats);
117 static void eth_igbvf_stats_reset(struct rte_eth_dev *dev);
118 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
119 uint16_t vlan_id, int on);
120 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
121 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
122 static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
123 struct rte_eth_rss_reta *reta_conf);
124 static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
125 struct rte_eth_rss_reta *reta_conf);
127 static int eth_igb_add_syn_filter(struct rte_eth_dev *dev,
128 struct rte_syn_filter *filter, uint16_t rx_queue);
129 static int eth_igb_remove_syn_filter(struct rte_eth_dev *dev);
130 static int eth_igb_get_syn_filter(struct rte_eth_dev *dev,
131 struct rte_syn_filter *filter, uint16_t *rx_queue);
132 static int eth_igb_add_ethertype_filter(struct rte_eth_dev *dev,
134 struct rte_ethertype_filter *filter, uint16_t rx_queue);
135 static int eth_igb_remove_ethertype_filter(struct rte_eth_dev *dev,
137 static int eth_igb_get_ethertype_filter(struct rte_eth_dev *dev,
139 struct rte_ethertype_filter *filter, uint16_t *rx_queue);
140 static int eth_igb_add_2tuple_filter(struct rte_eth_dev *dev,
142 struct rte_2tuple_filter *filter, uint16_t rx_queue);
143 static int eth_igb_remove_2tuple_filter(struct rte_eth_dev *dev,
145 static int eth_igb_get_2tuple_filter(struct rte_eth_dev *dev,
147 struct rte_2tuple_filter *filter, uint16_t *rx_queue);
148 static int eth_igb_add_flex_filter(struct rte_eth_dev *dev,
150 struct rte_flex_filter *filter, uint16_t rx_queue);
151 static int eth_igb_remove_flex_filter(struct rte_eth_dev *dev,
153 static int eth_igb_get_flex_filter(struct rte_eth_dev *dev,
155 struct rte_flex_filter *filter, uint16_t *rx_queue);
156 static int eth_igb_add_5tuple_filter(struct rte_eth_dev *dev,
158 struct rte_5tuple_filter *filter, uint16_t rx_queue);
159 static int eth_igb_remove_5tuple_filter(struct rte_eth_dev *dev,
161 static int eth_igb_get_5tuple_filter(struct rte_eth_dev *dev,
163 struct rte_5tuple_filter *filter, uint16_t *rx_queue);
166 * Define VF Stats MACRO for Non "cleared on read" register
168 #define UPDATE_VF_STAT(reg, last, cur) \
170 u32 latest = E1000_READ_REG(hw, reg); \
171 cur += latest - last; \
176 #define IGB_FC_PAUSE_TIME 0x0680
177 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
178 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
180 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
182 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
185 * The set of PCI devices this driver supports
187 static struct rte_pci_id pci_id_igb_map[] = {
189 #define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
190 #include "rte_pci_dev_ids.h"
196 * The set of PCI devices this driver supports (for 82576&I350 VF)
198 static struct rte_pci_id pci_id_igbvf_map[] = {
200 #define RTE_PCI_DEV_ID_DECL_IGBVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
201 #include "rte_pci_dev_ids.h"
206 static struct eth_dev_ops eth_igb_ops = {
207 .dev_configure = eth_igb_configure,
208 .dev_start = eth_igb_start,
209 .dev_stop = eth_igb_stop,
210 .dev_close = eth_igb_close,
211 .promiscuous_enable = eth_igb_promiscuous_enable,
212 .promiscuous_disable = eth_igb_promiscuous_disable,
213 .allmulticast_enable = eth_igb_allmulticast_enable,
214 .allmulticast_disable = eth_igb_allmulticast_disable,
215 .link_update = eth_igb_link_update,
216 .stats_get = eth_igb_stats_get,
217 .stats_reset = eth_igb_stats_reset,
218 .dev_infos_get = eth_igb_infos_get,
219 .vlan_filter_set = eth_igb_vlan_filter_set,
220 .vlan_tpid_set = eth_igb_vlan_tpid_set,
221 .vlan_offload_set = eth_igb_vlan_offload_set,
222 .rx_queue_setup = eth_igb_rx_queue_setup,
223 .rx_queue_release = eth_igb_rx_queue_release,
224 .rx_queue_count = eth_igb_rx_queue_count,
225 .rx_descriptor_done = eth_igb_rx_descriptor_done,
226 .tx_queue_setup = eth_igb_tx_queue_setup,
227 .tx_queue_release = eth_igb_tx_queue_release,
228 .dev_led_on = eth_igb_led_on,
229 .dev_led_off = eth_igb_led_off,
230 .flow_ctrl_set = eth_igb_flow_ctrl_set,
231 .mac_addr_add = eth_igb_rar_set,
232 .mac_addr_remove = eth_igb_rar_clear,
233 .reta_update = eth_igb_rss_reta_update,
234 .reta_query = eth_igb_rss_reta_query,
235 .rss_hash_update = eth_igb_rss_hash_update,
236 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
237 .add_syn_filter = eth_igb_add_syn_filter,
238 .remove_syn_filter = eth_igb_remove_syn_filter,
239 .get_syn_filter = eth_igb_get_syn_filter,
240 .add_ethertype_filter = eth_igb_add_ethertype_filter,
241 .remove_ethertype_filter = eth_igb_remove_ethertype_filter,
242 .get_ethertype_filter = eth_igb_get_ethertype_filter,
243 .add_2tuple_filter = eth_igb_add_2tuple_filter,
244 .remove_2tuple_filter = eth_igb_remove_2tuple_filter,
245 .get_2tuple_filter = eth_igb_get_2tuple_filter,
246 .add_flex_filter = eth_igb_add_flex_filter,
247 .remove_flex_filter = eth_igb_remove_flex_filter,
248 .get_flex_filter = eth_igb_get_flex_filter,
249 .add_5tuple_filter = eth_igb_add_5tuple_filter,
250 .remove_5tuple_filter = eth_igb_remove_5tuple_filter,
251 .get_5tuple_filter = eth_igb_get_5tuple_filter,
255 * dev_ops for virtual function, bare necessities for basic vf
256 * operation have been implemented
258 static struct eth_dev_ops igbvf_eth_dev_ops = {
259 .dev_configure = igbvf_dev_configure,
260 .dev_start = igbvf_dev_start,
261 .dev_stop = igbvf_dev_stop,
262 .dev_close = igbvf_dev_close,
263 .link_update = eth_igb_link_update,
264 .stats_get = eth_igbvf_stats_get,
265 .stats_reset = eth_igbvf_stats_reset,
266 .vlan_filter_set = igbvf_vlan_filter_set,
267 .dev_infos_get = eth_igb_infos_get,
268 .rx_queue_setup = eth_igb_rx_queue_setup,
269 .rx_queue_release = eth_igb_rx_queue_release,
270 .tx_queue_setup = eth_igb_tx_queue_setup,
271 .tx_queue_release = eth_igb_tx_queue_release,
275 * Atomically reads the link status information from global
276 * structure rte_eth_dev.
279 * - Pointer to the structure rte_eth_dev to read from.
280 * - Pointer to the buffer to be saved with the link status.
283 * - On success, zero.
284 * - On failure, negative value.
287 rte_igb_dev_atomic_read_link_status(struct rte_eth_dev *dev,
288 struct rte_eth_link *link)
290 struct rte_eth_link *dst = link;
291 struct rte_eth_link *src = &(dev->data->dev_link);
293 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
294 *(uint64_t *)src) == 0)
301 * Atomically writes the link status information into 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_write_link_status(struct rte_eth_dev *dev,
314 struct rte_eth_link *link)
316 struct rte_eth_link *dst = &(dev->data->dev_link);
317 struct rte_eth_link *src = link;
319 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
320 *(uint64_t *)src) == 0)
327 igb_intr_enable(struct rte_eth_dev *dev)
329 struct e1000_interrupt *intr =
330 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
331 struct e1000_hw *hw =
332 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
334 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
335 E1000_WRITE_FLUSH(hw);
339 igb_intr_disable(struct e1000_hw *hw)
341 E1000_WRITE_REG(hw, E1000_IMC, ~0);
342 E1000_WRITE_FLUSH(hw);
345 static inline int32_t
346 igb_pf_reset_hw(struct e1000_hw *hw)
351 status = e1000_reset_hw(hw);
353 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
354 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
355 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
356 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
357 E1000_WRITE_FLUSH(hw);
363 igb_identify_hardware(struct rte_eth_dev *dev)
365 struct e1000_hw *hw =
366 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
368 hw->vendor_id = dev->pci_dev->id.vendor_id;
369 hw->device_id = dev->pci_dev->id.device_id;
370 hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
371 hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
373 e1000_set_mac_type(hw);
375 /* need to check if it is a vf device below */
379 igb_reset_swfw_lock(struct e1000_hw *hw)
384 * Do mac ops initialization manually here, since we will need
385 * some function pointers set by this call.
387 ret_val = e1000_init_mac_params(hw);
392 * SMBI lock should not fail in this early stage. If this is the case,
393 * it is due to an improper exit of the application.
394 * So force the release of the faulty lock.
396 if (e1000_get_hw_semaphore_generic(hw) < 0) {
397 DEBUGOUT("SMBI lock released");
399 e1000_put_hw_semaphore_generic(hw);
401 if (hw->mac.ops.acquire_swfw_sync != NULL) {
405 * Phy lock should not fail in this early stage. If this is the case,
406 * it is due to an improper exit of the application.
407 * So force the release of the faulty lock.
409 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
410 if (hw->bus.func > E1000_FUNC_1)
412 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
413 DEBUGOUT1("SWFW phy%d lock released", hw->bus.func);
415 hw->mac.ops.release_swfw_sync(hw, mask);
418 * This one is more tricky since it is common to all ports; but
419 * swfw_sync retries last long enough (1s) to be almost sure that if
420 * lock can not be taken it is due to an improper lock of the
423 mask = E1000_SWFW_EEP_SM;
424 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
425 DEBUGOUT("SWFW common locks released");
427 hw->mac.ops.release_swfw_sync(hw, mask);
430 return E1000_SUCCESS;
434 eth_igb_dev_init(__attribute__((unused)) struct eth_driver *eth_drv,
435 struct rte_eth_dev *eth_dev)
438 struct rte_pci_device *pci_dev;
439 struct e1000_hw *hw =
440 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
441 struct e1000_vfta * shadow_vfta =
442 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
445 pci_dev = eth_dev->pci_dev;
446 eth_dev->dev_ops = ð_igb_ops;
447 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
448 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
450 /* for secondary processes, we don't initialise any further as primary
451 * has already done this work. Only check we don't need a different
453 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
454 if (eth_dev->data->scattered_rx)
455 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
459 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
461 igb_identify_hardware(eth_dev);
462 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
467 e1000_get_bus_info(hw);
469 /* Reset any pending lock */
470 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
475 /* Finish initialization */
476 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
482 hw->phy.autoneg_wait_to_complete = 0;
483 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
486 if (hw->phy.media_type == e1000_media_type_copper) {
487 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
488 hw->phy.disable_polarity_correction = 0;
489 hw->phy.ms_type = e1000_ms_hw_default;
493 * Start from a known state, this is important in reading the nvm
498 /* Make sure we have a good EEPROM before we read from it */
499 if (e1000_validate_nvm_checksum(hw) < 0) {
501 * Some PCI-E parts fail the first check due to
502 * the link being in sleep state, call it again,
503 * if it fails a second time its a real issue.
505 if (e1000_validate_nvm_checksum(hw) < 0) {
506 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
512 /* Read the permanent MAC address out of the EEPROM */
513 if (e1000_read_mac_addr(hw) != 0) {
514 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
519 /* Allocate memory for storing MAC addresses */
520 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
521 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
522 if (eth_dev->data->mac_addrs == NULL) {
523 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
524 "store MAC addresses",
525 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
530 /* Copy the permanent MAC address */
531 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
533 /* initialize the vfta */
534 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
536 /* Now initialize the hardware */
537 if (igb_hardware_init(hw) != 0) {
538 PMD_INIT_LOG(ERR, "Hardware initialization failed");
539 rte_free(eth_dev->data->mac_addrs);
540 eth_dev->data->mac_addrs = NULL;
544 hw->mac.get_link_status = 1;
546 /* Indicate SOL/IDER usage */
547 if (e1000_check_reset_block(hw) < 0) {
548 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
552 /* initialize PF if max_vfs not zero */
553 igb_pf_host_init(eth_dev);
555 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
556 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
557 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
558 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
559 E1000_WRITE_FLUSH(hw);
561 PMD_INIT_LOG(INFO, "port_id %d vendorID=0x%x deviceID=0x%x\n",
562 eth_dev->data->port_id, pci_dev->id.vendor_id,
563 pci_dev->id.device_id);
565 rte_intr_callback_register(&(pci_dev->intr_handle),
566 eth_igb_interrupt_handler, (void *)eth_dev);
568 /* enable uio intr after callback register */
569 rte_intr_enable(&(pci_dev->intr_handle));
571 /* enable support intr */
572 igb_intr_enable(eth_dev);
577 igb_hw_control_release(hw);
583 * Virtual Function device init
586 eth_igbvf_dev_init(__attribute__((unused)) struct eth_driver *eth_drv,
587 struct rte_eth_dev *eth_dev)
589 struct rte_pci_device *pci_dev;
590 struct e1000_hw *hw =
591 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
594 PMD_INIT_LOG(DEBUG, "eth_igbvf_dev_init");
596 eth_dev->dev_ops = &igbvf_eth_dev_ops;
597 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
598 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
600 /* for secondary processes, we don't initialise any further as primary
601 * has already done this work. Only check we don't need a different
603 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
604 if (eth_dev->data->scattered_rx)
605 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
609 pci_dev = eth_dev->pci_dev;
611 hw->device_id = pci_dev->id.device_id;
612 hw->vendor_id = pci_dev->id.vendor_id;
613 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
615 /* Initialize the shared code */
616 diag = e1000_setup_init_funcs(hw, TRUE);
618 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
623 /* init_mailbox_params */
624 hw->mbx.ops.init_params(hw);
626 /* Disable the interrupts for VF */
627 igbvf_intr_disable(hw);
629 diag = hw->mac.ops.reset_hw(hw);
631 /* Allocate memory for storing MAC addresses */
632 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
633 hw->mac.rar_entry_count, 0);
634 if (eth_dev->data->mac_addrs == NULL) {
636 "Failed to allocate %d bytes needed to store MAC "
638 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
642 /* Copy the permanent MAC address */
643 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
644 ð_dev->data->mac_addrs[0]);
646 PMD_INIT_LOG(DEBUG, "\nport %d vendorID=0x%x deviceID=0x%x "
648 eth_dev->data->port_id, pci_dev->id.vendor_id,
649 pci_dev->id.device_id,
655 static struct eth_driver rte_igb_pmd = {
657 .name = "rte_igb_pmd",
658 .id_table = pci_id_igb_map,
659 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
661 .eth_dev_init = eth_igb_dev_init,
662 .dev_private_size = sizeof(struct e1000_adapter),
666 * virtual function driver struct
668 static struct eth_driver rte_igbvf_pmd = {
670 .name = "rte_igbvf_pmd",
671 .id_table = pci_id_igbvf_map,
672 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
674 .eth_dev_init = eth_igbvf_dev_init,
675 .dev_private_size = sizeof(struct e1000_adapter),
679 rte_igb_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
681 rte_eth_driver_register(&rte_igb_pmd);
686 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
688 struct e1000_hw *hw =
689 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
690 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
691 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
692 rctl |= E1000_RCTL_VFE;
693 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
697 * VF Driver initialization routine.
698 * Invoked one at EAL init time.
699 * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
702 rte_igbvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
704 DEBUGFUNC("rte_igbvf_pmd_init");
706 rte_eth_driver_register(&rte_igbvf_pmd);
711 eth_igb_configure(struct rte_eth_dev *dev)
713 struct e1000_interrupt *intr =
714 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
716 PMD_INIT_LOG(DEBUG, ">>");
718 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
720 PMD_INIT_LOG(DEBUG, "<<");
726 eth_igb_start(struct rte_eth_dev *dev)
728 struct e1000_hw *hw =
729 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
733 PMD_INIT_LOG(DEBUG, ">>");
735 /* Power up the phy. Needed to make the link go Up */
736 e1000_power_up_phy(hw);
739 * Packet Buffer Allocation (PBA)
740 * Writing PBA sets the receive portion of the buffer
741 * the remainder is used for the transmit buffer.
743 if (hw->mac.type == e1000_82575) {
746 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
747 E1000_WRITE_REG(hw, E1000_PBA, pba);
750 /* Put the address into the Receive Address Array */
751 e1000_rar_set(hw, hw->mac.addr, 0);
753 /* Initialize the hardware */
754 if (igb_hardware_init(hw)) {
755 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
759 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
761 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
762 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
763 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
764 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
765 E1000_WRITE_FLUSH(hw);
767 /* configure PF module if SRIOV enabled */
768 igb_pf_host_configure(dev);
770 /* Configure for OS presence */
771 igb_init_manageability(hw);
773 eth_igb_tx_init(dev);
775 /* This can fail when allocating mbufs for descriptor rings */
776 ret = eth_igb_rx_init(dev);
778 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
779 igb_dev_clear_queues(dev);
783 e1000_clear_hw_cntrs_base_generic(hw);
786 * VLAN Offload Settings
788 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
789 ETH_VLAN_EXTEND_MASK;
790 eth_igb_vlan_offload_set(dev, mask);
792 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
793 /* Enable VLAN filter since VMDq always use VLAN filter */
794 igb_vmdq_vlan_hw_filter_enable(dev);
798 * Configure the Interrupt Moderation register (EITR) with the maximum
799 * possible value (0xFFFF) to minimize "System Partial Write" issued by
800 * spurious [DMA] memory updates of RX and TX ring descriptors.
802 * With a EITR granularity of 2 microseconds in the 82576, only 7/8
803 * spurious memory updates per second should be expected.
804 * ((65535 * 2) / 1000.1000 ~= 0.131 second).
806 * Because interrupts are not used at all, the MSI-X is not activated
807 * and interrupt moderation is controlled by EITR[0].
809 * Note that having [almost] disabled memory updates of RX and TX ring
810 * descriptors through the Interrupt Moderation mechanism, memory
811 * updates of ring descriptors are now moderated by the configurable
812 * value of Write-Back Threshold registers.
814 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
815 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210)) {
818 /* Enable all RX & TX queues in the IVAR registers */
819 ivar = (uint32_t) ((E1000_IVAR_VALID << 16) | E1000_IVAR_VALID);
820 for (i = 0; i < 8; i++)
821 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, i, ivar);
823 /* Configure EITR with the maximum possible value (0xFFFF) */
824 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
827 /* Setup link speed and duplex */
828 switch (dev->data->dev_conf.link_speed) {
829 case ETH_LINK_SPEED_AUTONEG:
830 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
831 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
832 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
833 hw->phy.autoneg_advertised = E1000_ALL_HALF_DUPLEX;
834 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
835 hw->phy.autoneg_advertised = E1000_ALL_FULL_DUPLEX;
837 goto error_invalid_config;
839 case ETH_LINK_SPEED_10:
840 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
841 hw->phy.autoneg_advertised = E1000_ALL_10_SPEED;
842 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
843 hw->phy.autoneg_advertised = ADVERTISE_10_HALF;
844 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
845 hw->phy.autoneg_advertised = ADVERTISE_10_FULL;
847 goto error_invalid_config;
849 case ETH_LINK_SPEED_100:
850 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
851 hw->phy.autoneg_advertised = E1000_ALL_100_SPEED;
852 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
853 hw->phy.autoneg_advertised = ADVERTISE_100_HALF;
854 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
855 hw->phy.autoneg_advertised = ADVERTISE_100_FULL;
857 goto error_invalid_config;
859 case ETH_LINK_SPEED_1000:
860 if ((dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX) ||
861 (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX))
862 hw->phy.autoneg_advertised = ADVERTISE_1000_FULL;
864 goto error_invalid_config;
866 case ETH_LINK_SPEED_10000:
868 goto error_invalid_config;
870 e1000_setup_link(hw);
872 /* check if lsc interrupt feature is enabled */
873 if (dev->data->dev_conf.intr_conf.lsc != 0)
874 ret = eth_igb_lsc_interrupt_setup(dev);
876 /* resume enabled intr since hw reset */
877 igb_intr_enable(dev);
879 PMD_INIT_LOG(DEBUG, "<<");
883 error_invalid_config:
884 PMD_INIT_LOG(ERR, "Invalid link_speed/link_duplex (%u/%u) for port %u\n",
885 dev->data->dev_conf.link_speed,
886 dev->data->dev_conf.link_duplex, dev->data->port_id);
887 igb_dev_clear_queues(dev);
891 /*********************************************************************
893 * This routine disables all traffic on the adapter by issuing a
894 * global reset on the MAC.
896 **********************************************************************/
898 eth_igb_stop(struct rte_eth_dev *dev)
900 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
901 struct rte_eth_link link;
903 igb_intr_disable(hw);
905 E1000_WRITE_REG(hw, E1000_WUC, 0);
907 /* Set bit for Go Link disconnect */
908 if (hw->mac.type >= e1000_82580) {
911 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
912 phpm_reg |= E1000_82580_PM_GO_LINKD;
913 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
916 /* Power down the phy. Needed to make the link go Down */
917 e1000_power_down_phy(hw);
919 igb_dev_clear_queues(dev);
921 /* clear the recorded link status */
922 memset(&link, 0, sizeof(link));
923 rte_igb_dev_atomic_write_link_status(dev, &link);
927 eth_igb_close(struct rte_eth_dev *dev)
929 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
930 struct rte_eth_link link;
933 e1000_phy_hw_reset(hw);
934 igb_release_manageability(hw);
935 igb_hw_control_release(hw);
937 /* Clear bit for Go Link disconnect */
938 if (hw->mac.type >= e1000_82580) {
941 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
942 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
943 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
946 igb_dev_clear_queues(dev);
948 memset(&link, 0, sizeof(link));
949 rte_igb_dev_atomic_write_link_status(dev, &link);
953 igb_get_rx_buffer_size(struct e1000_hw *hw)
955 uint32_t rx_buf_size;
956 if (hw->mac.type == e1000_82576) {
957 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
958 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
959 /* PBS needs to be translated according to a lookup table */
960 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
961 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
962 rx_buf_size = (rx_buf_size << 10);
963 } else if (hw->mac.type == e1000_i210) {
964 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
966 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
972 /*********************************************************************
974 * Initialize the hardware
976 **********************************************************************/
978 igb_hardware_init(struct e1000_hw *hw)
980 uint32_t rx_buf_size;
983 /* Let the firmware know the OS is in control */
984 igb_hw_control_acquire(hw);
987 * These parameters control the automatic generation (Tx) and
988 * response (Rx) to Ethernet PAUSE frames.
989 * - High water mark should allow for at least two standard size (1518)
990 * frames to be received after sending an XOFF.
991 * - Low water mark works best when it is very near the high water mark.
992 * This allows the receiver to restart by sending XON when it has
993 * drained a bit. Here we use an arbitrary value of 1500 which will
994 * restart after one full frame is pulled from the buffer. There
995 * could be several smaller frames in the buffer and if so they will
996 * not trigger the XON until their total number reduces the buffer
998 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1000 rx_buf_size = igb_get_rx_buffer_size(hw);
1002 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
1003 hw->fc.low_water = hw->fc.high_water - 1500;
1004 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1005 hw->fc.send_xon = 1;
1007 /* Set Flow control, use the tunable location if sane */
1008 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1009 hw->fc.requested_mode = igb_fc_setting;
1011 hw->fc.requested_mode = e1000_fc_none;
1013 /* Issue a global reset */
1014 igb_pf_reset_hw(hw);
1015 E1000_WRITE_REG(hw, E1000_WUC, 0);
1017 diag = e1000_init_hw(hw);
1021 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1022 e1000_get_phy_info(hw);
1023 e1000_check_for_link(hw);
1028 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1030 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1032 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1033 struct e1000_hw_stats *stats =
1034 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1037 if(hw->phy.media_type == e1000_media_type_copper ||
1038 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1040 E1000_READ_REG(hw,E1000_SYMERRS);
1041 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1044 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1045 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1046 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1047 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1049 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1050 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1051 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1052 stats->dc += E1000_READ_REG(hw, E1000_DC);
1053 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1054 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1055 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1057 ** For watchdog management we need to know if we have been
1058 ** paused during the last interval, so capture that here.
1060 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1061 stats->xoffrxc += pause_frames;
1062 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1063 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1064 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1065 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1066 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1067 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1068 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1069 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1070 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1071 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1072 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1073 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1075 /* For the 64-bit byte counters the low dword must be read first. */
1076 /* Both registers clear on the read of the high dword */
1078 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1079 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1080 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1081 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1083 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1084 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1085 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1086 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1087 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1089 stats->tor += E1000_READ_REG(hw, E1000_TORH);
1090 stats->tot += E1000_READ_REG(hw, E1000_TOTH);
1092 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1093 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1094 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1095 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1096 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1097 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1098 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1099 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1100 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1101 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1103 /* Interrupt Counts */
1105 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1106 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1107 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1108 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1109 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1110 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1111 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1112 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1113 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1115 /* Host to Card Statistics */
1117 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1118 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1119 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1120 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1121 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1122 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1123 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1124 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1125 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1126 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1127 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1128 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1129 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1130 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1132 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1133 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1134 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1135 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1136 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1137 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1139 if (rte_stats == NULL)
1143 rte_stats->ierrors = stats->rxerrc + stats->crcerrs + stats->algnerrc +
1144 stats->ruc + stats->roc + stats->mpc + stats->cexterr;
1147 rte_stats->oerrors = stats->ecol + stats->latecol;
1149 /* XON/XOFF pause frames */
1150 rte_stats->tx_pause_xon = stats->xontxc;
1151 rte_stats->rx_pause_xon = stats->xonrxc;
1152 rte_stats->tx_pause_xoff = stats->xofftxc;
1153 rte_stats->rx_pause_xoff = stats->xoffrxc;
1155 rte_stats->ipackets = stats->gprc;
1156 rte_stats->opackets = stats->gptc;
1157 rte_stats->ibytes = stats->gorc;
1158 rte_stats->obytes = stats->gotc;
1162 eth_igb_stats_reset(struct rte_eth_dev *dev)
1164 struct e1000_hw_stats *hw_stats =
1165 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1167 /* HW registers are cleared on read */
1168 eth_igb_stats_get(dev, NULL);
1170 /* Reset software totals */
1171 memset(hw_stats, 0, sizeof(*hw_stats));
1175 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1177 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1178 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
1179 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1181 /* Good Rx packets, include VF loopback */
1182 UPDATE_VF_STAT(E1000_VFGPRC,
1183 hw_stats->last_gprc, hw_stats->gprc);
1185 /* Good Rx octets, include VF loopback */
1186 UPDATE_VF_STAT(E1000_VFGORC,
1187 hw_stats->last_gorc, hw_stats->gorc);
1189 /* Good Tx packets, include VF loopback */
1190 UPDATE_VF_STAT(E1000_VFGPTC,
1191 hw_stats->last_gptc, hw_stats->gptc);
1193 /* Good Tx octets, include VF loopback */
1194 UPDATE_VF_STAT(E1000_VFGOTC,
1195 hw_stats->last_gotc, hw_stats->gotc);
1197 /* Rx Multicst packets */
1198 UPDATE_VF_STAT(E1000_VFMPRC,
1199 hw_stats->last_mprc, hw_stats->mprc);
1201 /* Good Rx loopback packets */
1202 UPDATE_VF_STAT(E1000_VFGPRLBC,
1203 hw_stats->last_gprlbc, hw_stats->gprlbc);
1205 /* Good Rx loopback octets */
1206 UPDATE_VF_STAT(E1000_VFGORLBC,
1207 hw_stats->last_gorlbc, hw_stats->gorlbc);
1209 /* Good Tx loopback packets */
1210 UPDATE_VF_STAT(E1000_VFGPTLBC,
1211 hw_stats->last_gptlbc, hw_stats->gptlbc);
1213 /* Good Tx loopback octets */
1214 UPDATE_VF_STAT(E1000_VFGOTLBC,
1215 hw_stats->last_gotlbc, hw_stats->gotlbc);
1217 if (rte_stats == NULL)
1220 memset(rte_stats, 0, sizeof(*rte_stats));
1221 rte_stats->ipackets = hw_stats->gprc;
1222 rte_stats->ibytes = hw_stats->gorc;
1223 rte_stats->opackets = hw_stats->gptc;
1224 rte_stats->obytes = hw_stats->gotc;
1225 rte_stats->imcasts = hw_stats->mprc;
1226 rte_stats->ilbpackets = hw_stats->gprlbc;
1227 rte_stats->ilbbytes = hw_stats->gorlbc;
1228 rte_stats->olbpackets = hw_stats->gptlbc;
1229 rte_stats->olbbytes = hw_stats->gotlbc;
1234 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
1236 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
1237 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1239 /* Sync HW register to the last stats */
1240 eth_igbvf_stats_get(dev, NULL);
1242 /* reset HW current stats*/
1243 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
1244 offsetof(struct e1000_vf_stats, gprc));
1249 eth_igb_infos_get(struct rte_eth_dev *dev,
1250 struct rte_eth_dev_info *dev_info)
1252 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1254 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1255 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
1256 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1257 dev_info->rx_offload_capa =
1258 DEV_RX_OFFLOAD_VLAN_STRIP |
1259 DEV_RX_OFFLOAD_IPV4_CKSUM |
1260 DEV_RX_OFFLOAD_UDP_CKSUM |
1261 DEV_RX_OFFLOAD_TCP_CKSUM;
1262 dev_info->tx_offload_capa =
1263 DEV_TX_OFFLOAD_VLAN_INSERT |
1264 DEV_TX_OFFLOAD_IPV4_CKSUM |
1265 DEV_TX_OFFLOAD_UDP_CKSUM |
1266 DEV_TX_OFFLOAD_TCP_CKSUM |
1267 DEV_TX_OFFLOAD_SCTP_CKSUM;
1269 switch (hw->mac.type) {
1271 dev_info->max_rx_queues = 4;
1272 dev_info->max_tx_queues = 4;
1273 dev_info->max_vmdq_pools = 0;
1277 dev_info->max_rx_queues = 16;
1278 dev_info->max_tx_queues = 16;
1279 dev_info->max_vmdq_pools = ETH_8_POOLS;
1283 dev_info->max_rx_queues = 8;
1284 dev_info->max_tx_queues = 8;
1285 dev_info->max_vmdq_pools = ETH_8_POOLS;
1289 dev_info->max_rx_queues = 8;
1290 dev_info->max_tx_queues = 8;
1291 dev_info->max_vmdq_pools = ETH_8_POOLS;
1295 dev_info->max_rx_queues = 8;
1296 dev_info->max_tx_queues = 8;
1300 dev_info->max_rx_queues = 4;
1301 dev_info->max_tx_queues = 4;
1302 dev_info->max_vmdq_pools = 0;
1306 dev_info->max_rx_queues = 2;
1307 dev_info->max_tx_queues = 2;
1308 dev_info->max_vmdq_pools = 0;
1311 case e1000_vfadapt_i350:
1312 dev_info->max_rx_queues = 1;
1313 dev_info->max_tx_queues = 1;
1314 dev_info->max_vmdq_pools = 0;
1318 /* Should not happen */
1319 dev_info->max_rx_queues = 0;
1320 dev_info->max_tx_queues = 0;
1321 dev_info->max_vmdq_pools = 0;
1325 /* return 0 means link status changed, -1 means not changed */
1327 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1329 struct e1000_hw *hw =
1330 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1331 struct rte_eth_link link, old;
1332 int link_check, count;
1335 hw->mac.get_link_status = 1;
1337 /* possible wait-to-complete in up to 9 seconds */
1338 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
1339 /* Read the real link status */
1340 switch (hw->phy.media_type) {
1341 case e1000_media_type_copper:
1342 /* Do the work to read phy */
1343 e1000_check_for_link(hw);
1344 link_check = !hw->mac.get_link_status;
1347 case e1000_media_type_fiber:
1348 e1000_check_for_link(hw);
1349 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
1353 case e1000_media_type_internal_serdes:
1354 e1000_check_for_link(hw);
1355 link_check = hw->mac.serdes_has_link;
1358 /* VF device is type_unknown */
1359 case e1000_media_type_unknown:
1360 eth_igbvf_link_update(hw);
1361 link_check = !hw->mac.get_link_status;
1367 if (link_check || wait_to_complete == 0)
1369 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
1371 memset(&link, 0, sizeof(link));
1372 rte_igb_dev_atomic_read_link_status(dev, &link);
1375 /* Now we check if a transition has happened */
1377 hw->mac.ops.get_link_up_info(hw, &link.link_speed,
1379 link.link_status = 1;
1380 } else if (!link_check) {
1381 link.link_speed = 0;
1382 link.link_duplex = 0;
1383 link.link_status = 0;
1385 rte_igb_dev_atomic_write_link_status(dev, &link);
1388 if (old.link_status == link.link_status)
1396 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
1397 * For ASF and Pass Through versions of f/w this means
1398 * that the driver is loaded.
1401 igb_hw_control_acquire(struct e1000_hw *hw)
1405 /* Let firmware know the driver has taken over */
1406 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1407 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1411 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
1412 * For ASF and Pass Through versions of f/w this means that the
1413 * driver is no longer loaded.
1416 igb_hw_control_release(struct e1000_hw *hw)
1420 /* Let firmware taken over control of h/w */
1421 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1422 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1423 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1427 * Bit of a misnomer, what this really means is
1428 * to enable OS management of the system... aka
1429 * to disable special hardware management features.
1432 igb_init_manageability(struct e1000_hw *hw)
1434 if (e1000_enable_mng_pass_thru(hw)) {
1435 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
1436 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1438 /* disable hardware interception of ARP */
1439 manc &= ~(E1000_MANC_ARP_EN);
1441 /* enable receiving management packets to the host */
1442 manc |= E1000_MANC_EN_MNG2HOST;
1443 manc2h |= 1 << 5; /* Mng Port 623 */
1444 manc2h |= 1 << 6; /* Mng Port 664 */
1445 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
1446 E1000_WRITE_REG(hw, E1000_MANC, manc);
1451 igb_release_manageability(struct e1000_hw *hw)
1453 if (e1000_enable_mng_pass_thru(hw)) {
1454 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1456 manc |= E1000_MANC_ARP_EN;
1457 manc &= ~E1000_MANC_EN_MNG2HOST;
1459 E1000_WRITE_REG(hw, E1000_MANC, manc);
1464 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
1466 struct e1000_hw *hw =
1467 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1470 rctl = E1000_READ_REG(hw, E1000_RCTL);
1471 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1472 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1476 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
1478 struct e1000_hw *hw =
1479 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1482 rctl = E1000_READ_REG(hw, E1000_RCTL);
1483 rctl &= (~E1000_RCTL_UPE);
1484 if (dev->data->all_multicast == 1)
1485 rctl |= E1000_RCTL_MPE;
1487 rctl &= (~E1000_RCTL_MPE);
1488 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1492 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
1494 struct e1000_hw *hw =
1495 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1498 rctl = E1000_READ_REG(hw, E1000_RCTL);
1499 rctl |= E1000_RCTL_MPE;
1500 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1504 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
1506 struct e1000_hw *hw =
1507 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1510 if (dev->data->promiscuous == 1)
1511 return; /* must remain in all_multicast mode */
1512 rctl = E1000_READ_REG(hw, E1000_RCTL);
1513 rctl &= (~E1000_RCTL_MPE);
1514 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1518 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1520 struct e1000_hw *hw =
1521 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1522 struct e1000_vfta * shadow_vfta =
1523 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1528 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
1529 E1000_VFTA_ENTRY_MASK);
1530 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
1531 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
1536 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
1538 /* update local VFTA copy */
1539 shadow_vfta->vfta[vid_idx] = vfta;
1545 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid)
1547 struct e1000_hw *hw =
1548 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1549 uint32_t reg = ETHER_TYPE_VLAN ;
1551 reg |= (tpid << 16);
1552 E1000_WRITE_REG(hw, E1000_VET, reg);
1556 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1558 struct e1000_hw *hw =
1559 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1562 /* Filter Table Disable */
1563 reg = E1000_READ_REG(hw, E1000_RCTL);
1564 reg &= ~E1000_RCTL_CFIEN;
1565 reg &= ~E1000_RCTL_VFE;
1566 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1570 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1572 struct e1000_hw *hw =
1573 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1574 struct e1000_vfta * shadow_vfta =
1575 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1579 /* Filter Table Enable, CFI not used for packet acceptance */
1580 reg = E1000_READ_REG(hw, E1000_RCTL);
1581 reg &= ~E1000_RCTL_CFIEN;
1582 reg |= E1000_RCTL_VFE;
1583 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1585 /* restore VFTA table */
1586 for (i = 0; i < IGB_VFTA_SIZE; i++)
1587 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
1591 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
1593 struct e1000_hw *hw =
1594 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1597 /* VLAN Mode Disable */
1598 reg = E1000_READ_REG(hw, E1000_CTRL);
1599 reg &= ~E1000_CTRL_VME;
1600 E1000_WRITE_REG(hw, E1000_CTRL, reg);
1604 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
1606 struct e1000_hw *hw =
1607 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1610 /* VLAN Mode Enable */
1611 reg = E1000_READ_REG(hw, E1000_CTRL);
1612 reg |= E1000_CTRL_VME;
1613 E1000_WRITE_REG(hw, E1000_CTRL, reg);
1617 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
1619 struct e1000_hw *hw =
1620 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1623 /* CTRL_EXT: Extended VLAN */
1624 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1625 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
1626 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1628 /* Update maximum packet length */
1629 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
1630 E1000_WRITE_REG(hw, E1000_RLPML,
1631 dev->data->dev_conf.rxmode.max_rx_pkt_len +
1636 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
1638 struct e1000_hw *hw =
1639 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1642 /* CTRL_EXT: Extended VLAN */
1643 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1644 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
1645 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1647 /* Update maximum packet length */
1648 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
1649 E1000_WRITE_REG(hw, E1000_RLPML,
1650 dev->data->dev_conf.rxmode.max_rx_pkt_len +
1655 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1657 if(mask & ETH_VLAN_STRIP_MASK){
1658 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1659 igb_vlan_hw_strip_enable(dev);
1661 igb_vlan_hw_strip_disable(dev);
1664 if(mask & ETH_VLAN_FILTER_MASK){
1665 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1666 igb_vlan_hw_filter_enable(dev);
1668 igb_vlan_hw_filter_disable(dev);
1671 if(mask & ETH_VLAN_EXTEND_MASK){
1672 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1673 igb_vlan_hw_extend_enable(dev);
1675 igb_vlan_hw_extend_disable(dev);
1681 * It enables the interrupt mask and then enable the interrupt.
1684 * Pointer to struct rte_eth_dev.
1687 * - On success, zero.
1688 * - On failure, a negative value.
1691 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev)
1693 struct e1000_interrupt *intr =
1694 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1696 intr->mask |= E1000_ICR_LSC;
1702 * It reads ICR and gets interrupt causes, check it and set a bit flag
1703 * to update link status.
1706 * Pointer to struct rte_eth_dev.
1709 * - On success, zero.
1710 * - On failure, a negative value.
1713 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
1716 struct e1000_hw *hw =
1717 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1718 struct e1000_interrupt *intr =
1719 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1721 igb_intr_disable(hw);
1723 /* read-on-clear nic registers here */
1724 icr = E1000_READ_REG(hw, E1000_ICR);
1727 if (icr & E1000_ICR_LSC) {
1728 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1731 if (icr & E1000_ICR_VMMB)
1732 intr->flags |= E1000_FLAG_MAILBOX;
1738 * It executes link_update after knowing an interrupt is prsent.
1741 * Pointer to struct rte_eth_dev.
1744 * - On success, zero.
1745 * - On failure, a negative value.
1748 eth_igb_interrupt_action(struct rte_eth_dev *dev)
1750 struct e1000_hw *hw =
1751 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1752 struct e1000_interrupt *intr =
1753 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1754 uint32_t tctl, rctl;
1755 struct rte_eth_link link;
1758 if (intr->flags & E1000_FLAG_MAILBOX) {
1759 igb_pf_mbx_process(dev);
1760 intr->flags &= ~E1000_FLAG_MAILBOX;
1763 igb_intr_enable(dev);
1764 rte_intr_enable(&(dev->pci_dev->intr_handle));
1766 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
1767 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
1769 /* set get_link_status to check register later */
1770 hw->mac.get_link_status = 1;
1771 ret = eth_igb_link_update(dev, 0);
1773 /* check if link has changed */
1777 memset(&link, 0, sizeof(link));
1778 rte_igb_dev_atomic_read_link_status(dev, &link);
1779 if (link.link_status) {
1781 " Port %d: Link Up - speed %u Mbps - %s\n",
1782 dev->data->port_id, (unsigned)link.link_speed,
1783 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
1784 "full-duplex" : "half-duplex");
1786 PMD_INIT_LOG(INFO, " Port %d: Link Down\n",
1787 dev->data->port_id);
1789 PMD_INIT_LOG(INFO, "PCI Address: %04d:%02d:%02d:%d",
1790 dev->pci_dev->addr.domain,
1791 dev->pci_dev->addr.bus,
1792 dev->pci_dev->addr.devid,
1793 dev->pci_dev->addr.function);
1794 tctl = E1000_READ_REG(hw, E1000_TCTL);
1795 rctl = E1000_READ_REG(hw, E1000_RCTL);
1796 if (link.link_status) {
1798 tctl |= E1000_TCTL_EN;
1799 rctl |= E1000_RCTL_EN;
1802 tctl &= ~E1000_TCTL_EN;
1803 rctl &= ~E1000_RCTL_EN;
1805 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1806 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1807 E1000_WRITE_FLUSH(hw);
1808 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
1815 * Interrupt handler which shall be registered at first.
1818 * Pointer to interrupt handle.
1820 * The address of parameter (struct rte_eth_dev *) regsitered before.
1826 eth_igb_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
1829 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1831 eth_igb_interrupt_get_status(dev);
1832 eth_igb_interrupt_action(dev);
1836 eth_igb_led_on(struct rte_eth_dev *dev)
1838 struct e1000_hw *hw;
1840 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1841 return (e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
1845 eth_igb_led_off(struct rte_eth_dev *dev)
1847 struct e1000_hw *hw;
1849 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1850 return (e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
1854 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1856 struct e1000_hw *hw;
1858 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
1864 uint32_t rx_buf_size;
1865 uint32_t max_high_water;
1868 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1869 rx_buf_size = igb_get_rx_buffer_size(hw);
1870 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x \n", rx_buf_size);
1872 /* At least reserve one Ethernet frame for watermark */
1873 max_high_water = rx_buf_size - ETHER_MAX_LEN;
1874 if ((fc_conf->high_water > max_high_water) ||
1875 (fc_conf->high_water < fc_conf->low_water)) {
1876 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value \n");
1877 PMD_INIT_LOG(ERR, "high water must <= 0x%x \n", max_high_water);
1881 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
1882 hw->fc.pause_time = fc_conf->pause_time;
1883 hw->fc.high_water = fc_conf->high_water;
1884 hw->fc.low_water = fc_conf->low_water;
1885 hw->fc.send_xon = fc_conf->send_xon;
1887 err = e1000_setup_link_generic(hw);
1888 if (err == E1000_SUCCESS) {
1890 /* check if we want to forward MAC frames - driver doesn't have native
1891 * capability to do that, so we'll write the registers ourselves */
1893 rctl = E1000_READ_REG(hw, E1000_RCTL);
1895 /* set or clear MFLCN.PMCF bit depending on configuration */
1896 if (fc_conf->mac_ctrl_frame_fwd != 0)
1897 rctl |= E1000_RCTL_PMCF;
1899 rctl &= ~E1000_RCTL_PMCF;
1901 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1902 E1000_WRITE_FLUSH(hw);
1907 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x \n", err);
1911 #define E1000_RAH_POOLSEL_SHIFT (18)
1913 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
1914 uint32_t index, __rte_unused uint32_t pool)
1916 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1919 e1000_rar_set(hw, mac_addr->addr_bytes, index);
1920 rah = E1000_READ_REG(hw, E1000_RAH(index));
1921 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
1922 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
1926 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
1928 uint8_t addr[ETHER_ADDR_LEN];
1929 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1931 memset(addr, 0, sizeof(addr));
1933 e1000_rar_set(hw, addr, index);
1937 * Virtual Function operations
1940 igbvf_intr_disable(struct e1000_hw *hw)
1942 PMD_INIT_LOG(DEBUG, "igbvf_intr_disable");
1944 /* Clear interrupt mask to stop from interrupts being generated */
1945 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
1947 E1000_WRITE_FLUSH(hw);
1951 igbvf_stop_adapter(struct rte_eth_dev *dev)
1955 struct rte_eth_dev_info dev_info;
1956 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1958 memset(&dev_info, 0, sizeof(dev_info));
1959 eth_igb_infos_get(dev, &dev_info);
1961 /* Clear interrupt mask to stop from interrupts being generated */
1962 igbvf_intr_disable(hw);
1964 /* Clear any pending interrupts, flush previous writes */
1965 E1000_READ_REG(hw, E1000_EICR);
1967 /* Disable the transmit unit. Each queue must be disabled. */
1968 for (i = 0; i < dev_info.max_tx_queues; i++)
1969 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
1971 /* Disable the receive unit by stopping each queue */
1972 for (i = 0; i < dev_info.max_rx_queues; i++) {
1973 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
1974 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
1975 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
1976 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
1980 /* flush all queues disables */
1981 E1000_WRITE_FLUSH(hw);
1985 static int eth_igbvf_link_update(struct e1000_hw *hw)
1987 struct e1000_mbx_info *mbx = &hw->mbx;
1988 struct e1000_mac_info *mac = &hw->mac;
1989 int ret_val = E1000_SUCCESS;
1991 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
1994 * We only want to run this if there has been a rst asserted.
1995 * in this case that could mean a link change, device reset,
1996 * or a virtual function reset
1999 /* If we were hit with a reset or timeout drop the link */
2000 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
2001 mac->get_link_status = TRUE;
2003 if (!mac->get_link_status)
2006 /* if link status is down no point in checking to see if pf is up */
2007 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
2010 /* if we passed all the tests above then the link is up and we no
2011 * longer need to check for link */
2012 mac->get_link_status = FALSE;
2020 igbvf_dev_configure(struct rte_eth_dev *dev)
2022 struct rte_eth_conf* conf = &dev->data->dev_conf;
2024 PMD_INIT_LOG(DEBUG, "\nConfigured Virtual Function port id: %d\n",
2025 dev->data->port_id);
2028 * VF has no ability to enable/disable HW CRC
2029 * Keep the persistent behavior the same as Host PF
2031 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
2032 if (!conf->rxmode.hw_strip_crc) {
2033 PMD_INIT_LOG(INFO, "VF can't disable HW CRC Strip\n");
2034 conf->rxmode.hw_strip_crc = 1;
2037 if (conf->rxmode.hw_strip_crc) {
2038 PMD_INIT_LOG(INFO, "VF can't enable HW CRC Strip\n");
2039 conf->rxmode.hw_strip_crc = 0;
2047 igbvf_dev_start(struct rte_eth_dev *dev)
2049 struct e1000_hw *hw =
2050 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2053 PMD_INIT_LOG(DEBUG, "igbvf_dev_start");
2055 hw->mac.ops.reset_hw(hw);
2058 igbvf_set_vfta_all(dev,1);
2060 eth_igbvf_tx_init(dev);
2062 /* This can fail when allocating mbufs for descriptor rings */
2063 ret = eth_igbvf_rx_init(dev);
2065 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
2066 igb_dev_clear_queues(dev);
2074 igbvf_dev_stop(struct rte_eth_dev *dev)
2076 PMD_INIT_LOG(DEBUG, "igbvf_dev_stop");
2078 igbvf_stop_adapter(dev);
2081 * Clear what we set, but we still keep shadow_vfta to
2082 * restore after device starts
2084 igbvf_set_vfta_all(dev,0);
2086 igb_dev_clear_queues(dev);
2090 igbvf_dev_close(struct rte_eth_dev *dev)
2092 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2094 PMD_INIT_LOG(DEBUG, "igbvf_dev_close");
2098 igbvf_dev_stop(dev);
2101 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
2103 struct e1000_mbx_info *mbx = &hw->mbx;
2106 /* After set vlan, vlan strip will also be enabled in igb driver*/
2107 msgbuf[0] = E1000_VF_SET_VLAN;
2109 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
2111 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
2113 return (mbx->ops.write_posted(hw, msgbuf, 2, 0));
2116 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
2118 struct e1000_hw *hw =
2119 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2120 struct e1000_vfta * shadow_vfta =
2121 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2122 int i = 0, j = 0, vfta = 0, mask = 1;
2124 for (i = 0; i < IGB_VFTA_SIZE; i++){
2125 vfta = shadow_vfta->vfta[i];
2128 for (j = 0; j < 32; j++){
2131 (uint16_t)((i<<5)+j), on);
2140 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2142 struct e1000_hw *hw =
2143 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2144 struct e1000_vfta * shadow_vfta =
2145 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2146 uint32_t vid_idx = 0;
2147 uint32_t vid_bit = 0;
2150 PMD_INIT_LOG(DEBUG, "igbvf_vlan_filter_set");
2152 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
2153 ret = igbvf_set_vfta(hw, vlan_id, !!on);
2155 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
2158 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
2159 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
2161 /*Save what we set and retore it after device reset*/
2163 shadow_vfta->vfta[vid_idx] |= vid_bit;
2165 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
2171 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
2172 struct rte_eth_rss_reta *reta_conf)
2176 struct e1000_hw *hw =
2177 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2180 * Update Redirection Table RETA[n],n=0...31,The redirection table has
2181 * 128-entries in 32 registers
2183 for(i = 0; i < ETH_RSS_RETA_NUM_ENTRIES; i += 4) {
2184 if (i < ETH_RSS_RETA_NUM_ENTRIES/2)
2185 mask = (uint8_t)((reta_conf->mask_lo >> i) & 0xF);
2187 mask = (uint8_t)((reta_conf->mask_hi >>
2188 (i - ETH_RSS_RETA_NUM_ENTRIES/2)) & 0xF);
2191 /* If all 4 entries were set,don't need read RETA register */
2193 reta = E1000_READ_REG(hw,E1000_RETA(i >> 2));
2195 for (j = 0; j < 4; j++) {
2196 if (mask & (0x1 << j)) {
2198 reta &= ~(0xFF << 8 * j);
2199 reta |= reta_conf->reta[i + j] << 8 * j;
2202 E1000_WRITE_REG(hw, E1000_RETA(i >> 2),reta);
2210 eth_igb_rss_reta_query(struct rte_eth_dev *dev,
2211 struct rte_eth_rss_reta *reta_conf)
2215 struct e1000_hw *hw =
2216 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2219 * Read Redirection Table RETA[n],n=0...31,The redirection table has
2220 * 128-entries in 32 registers
2222 for(i = 0; i < ETH_RSS_RETA_NUM_ENTRIES; i += 4) {
2223 if (i < ETH_RSS_RETA_NUM_ENTRIES/2)
2224 mask = (uint8_t)((reta_conf->mask_lo >> i) & 0xF);
2226 mask = (uint8_t)((reta_conf->mask_hi >>
2227 (i - ETH_RSS_RETA_NUM_ENTRIES/2)) & 0xF);
2230 reta = E1000_READ_REG(hw,E1000_RETA(i >> 2));
2231 for (j = 0; j < 4; j++) {
2232 if (mask & (0x1 << j))
2233 reta_conf->reta[i + j] =
2234 (uint8_t)((reta >> 8 * j) & 0xFF);
2242 #define MAC_TYPE_FILTER_SUP(type) do {\
2243 if ((type) != e1000_82580 && (type) != e1000_i350 &&\
2244 (type) != e1000_82576)\
2249 * add the syn filter
2252 * dev: Pointer to struct rte_eth_dev.
2253 * filter: ponter to the filter that will be added.
2254 * rx_queue: the queue id the filter assigned to.
2257 * - On success, zero.
2258 * - On failure, a negative value.
2261 eth_igb_add_syn_filter(struct rte_eth_dev *dev,
2262 struct rte_syn_filter *filter, uint16_t rx_queue)
2264 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2265 uint32_t synqf, rfctl;
2267 MAC_TYPE_FILTER_SUP(hw->mac.type);
2269 if (rx_queue >= IGB_MAX_RX_QUEUE_NUM)
2272 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
2273 if (synqf & E1000_SYN_FILTER_ENABLE)
2276 synqf = (uint32_t)(((rx_queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
2277 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
2279 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
2280 if (filter->hig_pri)
2281 rfctl |= E1000_RFCTL_SYNQFP;
2283 rfctl &= ~E1000_RFCTL_SYNQFP;
2285 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
2286 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
2291 * remove the syn filter
2294 * dev: Pointer to struct rte_eth_dev.
2297 * - On success, zero.
2298 * - On failure, a negative value.
2301 eth_igb_remove_syn_filter(struct rte_eth_dev *dev)
2303 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2305 MAC_TYPE_FILTER_SUP(hw->mac.type);
2307 E1000_WRITE_REG(hw, E1000_SYNQF(0), 0);
2312 * get the syn filter's info
2315 * dev: Pointer to struct rte_eth_dev.
2316 * filter: ponter to the filter that returns.
2317 * *rx_queue: pointer to the queue id the filter assigned to.
2320 * - On success, zero.
2321 * - On failure, a negative value.
2324 eth_igb_get_syn_filter(struct rte_eth_dev *dev,
2325 struct rte_syn_filter *filter, uint16_t *rx_queue)
2327 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2328 uint32_t synqf, rfctl;
2330 MAC_TYPE_FILTER_SUP(hw->mac.type);
2331 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
2332 if (synqf & E1000_SYN_FILTER_ENABLE) {
2333 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
2334 filter->hig_pri = (rfctl & E1000_RFCTL_SYNQFP) ? 1 : 0;
2335 *rx_queue = (uint8_t)((synqf & E1000_SYN_FILTER_QUEUE) >>
2336 E1000_SYN_FILTER_QUEUE_SHIFT);
2343 * add an ethertype filter
2346 * dev: Pointer to struct rte_eth_dev.
2347 * index: the index the filter allocates.
2348 * filter: ponter to the filter that will be added.
2349 * rx_queue: the queue id the filter assigned to.
2352 * - On success, zero.
2353 * - On failure, a negative value.
2356 eth_igb_add_ethertype_filter(struct rte_eth_dev *dev, uint16_t index,
2357 struct rte_ethertype_filter *filter, uint16_t rx_queue)
2359 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2362 MAC_TYPE_FILTER_SUP(hw->mac.type);
2364 if (index >= E1000_MAX_ETQF_FILTERS || rx_queue >= IGB_MAX_RX_QUEUE_NUM)
2367 etqf = E1000_READ_REG(hw, E1000_ETQF(index));
2368 if (etqf & E1000_ETQF_FILTER_ENABLE)
2369 return -EINVAL; /* filter index is in use. */
2373 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
2374 etqf |= (uint32_t)(filter->ethertype & E1000_ETQF_ETHERTYPE);
2375 etqf |= rx_queue << E1000_ETQF_QUEUE_SHIFT;
2377 if (filter->priority_en) {
2378 PMD_INIT_LOG(ERR, "vlan and priority (%d) is not supported"
2379 " in E1000.", filter->priority);
2383 E1000_WRITE_REG(hw, E1000_ETQF(index), etqf);
2388 * remove an ethertype filter
2391 * dev: Pointer to struct rte_eth_dev.
2392 * index: the index the filter allocates.
2395 * - On success, zero.
2396 * - On failure, a negative value.
2399 eth_igb_remove_ethertype_filter(struct rte_eth_dev *dev, uint16_t index)
2401 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2403 MAC_TYPE_FILTER_SUP(hw->mac.type);
2405 if (index >= E1000_MAX_ETQF_FILTERS)
2408 E1000_WRITE_REG(hw, E1000_ETQF(index), 0);
2413 * get an ethertype filter
2416 * dev: Pointer to struct rte_eth_dev.
2417 * index: the index the filter allocates.
2418 * filter: ponter to the filter that will be gotten.
2419 * *rx_queue: the ponited of the queue id the filter assigned to.
2422 * - On success, zero.
2423 * - On failure, a negative value.
2426 eth_igb_get_ethertype_filter(struct rte_eth_dev *dev, uint16_t index,
2427 struct rte_ethertype_filter *filter, uint16_t *rx_queue)
2429 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2432 MAC_TYPE_FILTER_SUP(hw->mac.type);
2434 if (index >= E1000_MAX_ETQF_FILTERS)
2437 etqf = E1000_READ_REG(hw, E1000_ETQF(index));
2438 if (etqf & E1000_ETQF_FILTER_ENABLE) {
2439 filter->ethertype = etqf & E1000_ETQF_ETHERTYPE;
2440 filter->priority_en = 0;
2441 *rx_queue = (etqf & E1000_ETQF_QUEUE) >> E1000_ETQF_QUEUE_SHIFT;
2447 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
2448 if ((type) != e1000_82580 && (type) != e1000_i350)\
2453 * add a 2tuple filter
2456 * dev: Pointer to struct rte_eth_dev.
2457 * index: the index the filter allocates.
2458 * filter: ponter to the filter that will be added.
2459 * rx_queue: the queue id the filter assigned to.
2462 * - On success, zero.
2463 * - On failure, a negative value.
2466 eth_igb_add_2tuple_filter(struct rte_eth_dev *dev, uint16_t index,
2467 struct rte_2tuple_filter *filter, uint16_t rx_queue)
2469 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2470 uint32_t ttqf, imir = 0;
2471 uint32_t imir_ext = 0;
2473 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
2475 if (index >= E1000_MAX_TTQF_FILTERS ||
2476 rx_queue >= IGB_MAX_RX_QUEUE_NUM ||
2477 filter->priority > E1000_2TUPLE_MAX_PRI)
2478 return -EINVAL; /* filter index is out of range. */
2479 if (filter->tcp_flags > TCP_FLAG_ALL)
2480 return -EINVAL; /* flags is invalid. */
2482 ttqf = E1000_READ_REG(hw, E1000_TTQF(index));
2483 if (ttqf & E1000_TTQF_QUEUE_ENABLE)
2484 return -EINVAL; /* filter index is in use. */
2486 imir = (uint32_t)(filter->dst_port & E1000_IMIR_DSTPORT);
2487 if (filter->dst_port_mask == 1) /* 1b means not compare. */
2488 imir |= E1000_IMIR_PORT_BP;
2490 imir &= ~E1000_IMIR_PORT_BP;
2492 imir |= filter->priority << E1000_IMIR_PRIORITY_SHIFT;
2495 ttqf |= E1000_TTQF_QUEUE_ENABLE;
2496 ttqf |= (uint32_t)(rx_queue << E1000_TTQF_QUEUE_SHIFT);
2497 ttqf |= (uint32_t)(filter->protocol & E1000_TTQF_PROTOCOL_MASK);
2498 if (filter->protocol_mask == 1)
2499 ttqf |= E1000_TTQF_MASK_ENABLE;
2501 ttqf &= ~E1000_TTQF_MASK_ENABLE;
2503 imir_ext |= E1000_IMIR_EXT_SIZE_BP;
2504 /* tcp flags bits setting. */
2505 if (filter->tcp_flags & TCP_FLAG_ALL) {
2506 if (filter->tcp_flags & TCP_UGR_FLAG)
2507 imir_ext |= E1000_IMIR_EXT_CTRL_UGR;
2508 if (filter->tcp_flags & TCP_ACK_FLAG)
2509 imir_ext |= E1000_IMIR_EXT_CTRL_ACK;
2510 if (filter->tcp_flags & TCP_PSH_FLAG)
2511 imir_ext |= E1000_IMIR_EXT_CTRL_PSH;
2512 if (filter->tcp_flags & TCP_RST_FLAG)
2513 imir_ext |= E1000_IMIR_EXT_CTRL_RST;
2514 if (filter->tcp_flags & TCP_SYN_FLAG)
2515 imir_ext |= E1000_IMIR_EXT_CTRL_SYN;
2516 if (filter->tcp_flags & TCP_FIN_FLAG)
2517 imir_ext |= E1000_IMIR_EXT_CTRL_FIN;
2518 imir_ext &= ~E1000_IMIR_EXT_CTRL_BP;
2520 imir_ext |= E1000_IMIR_EXT_CTRL_BP;
2521 E1000_WRITE_REG(hw, E1000_IMIR(index), imir);
2522 E1000_WRITE_REG(hw, E1000_TTQF(index), ttqf);
2523 E1000_WRITE_REG(hw, E1000_IMIREXT(index), imir_ext);
2528 * remove a 2tuple filter
2531 * dev: Pointer to struct rte_eth_dev.
2532 * index: the index the filter allocates.
2535 * - On success, zero.
2536 * - On failure, a negative value.
2539 eth_igb_remove_2tuple_filter(struct rte_eth_dev *dev,
2542 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2544 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
2546 if (index >= E1000_MAX_TTQF_FILTERS)
2547 return -EINVAL; /* filter index is out of range */
2549 E1000_WRITE_REG(hw, E1000_TTQF(index), 0);
2550 E1000_WRITE_REG(hw, E1000_IMIR(index), 0);
2551 E1000_WRITE_REG(hw, E1000_IMIREXT(index), 0);
2556 * get a 2tuple filter
2559 * dev: Pointer to struct rte_eth_dev.
2560 * index: the index the filter allocates.
2561 * filter: ponter to the filter that returns.
2562 * *rx_queue: pointer of the queue id the filter assigned to.
2565 * - On success, zero.
2566 * - On failure, a negative value.
2569 eth_igb_get_2tuple_filter(struct rte_eth_dev *dev, uint16_t index,
2570 struct rte_2tuple_filter *filter, uint16_t *rx_queue)
2572 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2573 uint32_t imir, ttqf, imir_ext;
2575 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
2577 if (index >= E1000_MAX_TTQF_FILTERS)
2578 return -EINVAL; /* filter index is out of range. */
2580 ttqf = E1000_READ_REG(hw, E1000_TTQF(index));
2581 if (ttqf & E1000_TTQF_QUEUE_ENABLE) {
2582 imir = E1000_READ_REG(hw, E1000_IMIR(index));
2583 filter->protocol = ttqf & E1000_TTQF_PROTOCOL_MASK;
2584 filter->protocol_mask = (ttqf & E1000_TTQF_MASK_ENABLE) ? 1 : 0;
2585 *rx_queue = (ttqf & E1000_TTQF_RX_QUEUE_MASK) >>
2586 E1000_TTQF_QUEUE_SHIFT;
2587 filter->dst_port = (uint16_t)(imir & E1000_IMIR_DSTPORT);
2588 filter->dst_port_mask = (imir & E1000_IMIR_PORT_BP) ? 1 : 0;
2589 filter->priority = (imir & E1000_IMIR_PRIORITY) >>
2590 E1000_IMIR_PRIORITY_SHIFT;
2592 imir_ext = E1000_READ_REG(hw, E1000_IMIREXT(index));
2593 if (!(imir_ext & E1000_IMIR_EXT_CTRL_BP)) {
2594 if (imir_ext & E1000_IMIR_EXT_CTRL_UGR)
2595 filter->tcp_flags |= TCP_UGR_FLAG;
2596 if (imir_ext & E1000_IMIR_EXT_CTRL_ACK)
2597 filter->tcp_flags |= TCP_ACK_FLAG;
2598 if (imir_ext & E1000_IMIR_EXT_CTRL_PSH)
2599 filter->tcp_flags |= TCP_PSH_FLAG;
2600 if (imir_ext & E1000_IMIR_EXT_CTRL_RST)
2601 filter->tcp_flags |= TCP_RST_FLAG;
2602 if (imir_ext & E1000_IMIR_EXT_CTRL_SYN)
2603 filter->tcp_flags |= TCP_SYN_FLAG;
2604 if (imir_ext & E1000_IMIR_EXT_CTRL_FIN)
2605 filter->tcp_flags |= TCP_FIN_FLAG;
2607 filter->tcp_flags = 0;
2617 * dev: Pointer to struct rte_eth_dev.
2618 * index: the index the filter allocates.
2619 * filter: ponter to the filter that will be added.
2620 * rx_queue: the queue id the filter assigned to.
2623 * - On success, zero.
2624 * - On failure, a negative value.
2627 eth_igb_add_flex_filter(struct rte_eth_dev *dev, uint16_t index,
2628 struct rte_flex_filter *filter, uint16_t rx_queue)
2630 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2631 uint32_t wufc, en_bits = 0;
2632 uint32_t queueing = 0;
2633 uint32_t reg_off = 0;
2636 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
2638 if (index >= E1000_MAX_FLEXIBLE_FILTERS)
2639 return -EINVAL; /* filter index is out of range. */
2641 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN ||
2642 filter->len % 8 != 0 ||
2643 filter->priority > E1000_MAX_FLEX_FILTER_PRI)
2646 wufc = E1000_READ_REG(hw, E1000_WUFC);
2647 en_bits = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << index);
2648 if ((wufc & en_bits) == en_bits)
2649 return -EINVAL; /* the filter is in use. */
2651 E1000_WRITE_REG(hw, E1000_WUFC,
2652 wufc | E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << index));
2655 if (index < E1000_MAX_FHFT)
2656 reg_off = E1000_FHFT(index);
2658 reg_off = E1000_FHFT_EXT(index - E1000_MAX_FHFT);
2660 for (i = 0; i < 16; i++) {
2661 E1000_WRITE_REG(hw, reg_off + i*4*4, filter->dwords[j]);
2662 E1000_WRITE_REG(hw, reg_off + (i*4+1)*4, filter->dwords[++j]);
2663 E1000_WRITE_REG(hw, reg_off + (i*4+2)*4,
2664 (uint32_t)filter->mask[i]);
2667 queueing |= filter->len |
2668 (rx_queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
2669 (filter->priority << E1000_FHFT_QUEUEING_PRIO_SHIFT);
2670 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET, queueing);
2675 * remove a flex filter
2678 * dev: Pointer to struct rte_eth_dev.
2679 * index: the index the filter allocates.
2682 * - On success, zero.
2683 * - On failure, a negative value.
2686 eth_igb_remove_flex_filter(struct rte_eth_dev *dev,
2689 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2690 uint32_t wufc, reg_off = 0;
2693 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
2695 if (index >= E1000_MAX_FLEXIBLE_FILTERS)
2696 return -EINVAL; /* filter index is out of range. */
2698 wufc = E1000_READ_REG(hw, E1000_WUFC);
2699 E1000_WRITE_REG(hw, E1000_WUFC, wufc & (~(E1000_WUFC_FLX0 << index)));
2701 if (index < E1000_MAX_FHFT)
2702 reg_off = E1000_FHFT(index);
2704 reg_off = E1000_FHFT_EXT(index - E1000_MAX_FHFT);
2706 for (i = 0; i < 64; i++)
2707 E1000_WRITE_REG(hw, reg_off + i*4, 0);
2715 * dev: Pointer to struct rte_eth_dev.
2716 * index: the index the filter allocates.
2717 * filter: ponter to the filter that returns.
2718 * *rx_queue: the pointer of the queue id the filter assigned to.
2721 * - On success, zero.
2722 * - On failure, a negative value.
2725 eth_igb_get_flex_filter(struct rte_eth_dev *dev, uint16_t index,
2726 struct rte_flex_filter *filter, uint16_t *rx_queue)
2728 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2729 uint32_t wufc, queueing, wufc_en = 0;
2732 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
2734 if (index >= E1000_MAX_FLEXIBLE_FILTERS)
2735 return -EINVAL; /* filter index is out of range. */
2737 wufc = E1000_READ_REG(hw, E1000_WUFC);
2738 wufc_en = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << index);
2740 if ((wufc & wufc_en) == wufc_en) {
2741 uint32_t reg_off = 0;
2743 if (index < E1000_MAX_FHFT)
2744 reg_off = E1000_FHFT(index);
2746 reg_off = E1000_FHFT_EXT(index - E1000_MAX_FHFT);
2748 for (i = 0; i < 16; i++, j = i * 2) {
2750 E1000_READ_REG(hw, reg_off + i*4*4);
2751 filter->dwords[j+1] =
2752 E1000_READ_REG(hw, reg_off + (i*4+1)*4);
2754 E1000_READ_REG(hw, reg_off + (i*4+2)*4);
2756 queueing = E1000_READ_REG(hw,
2757 reg_off + E1000_FHFT_QUEUEING_OFFSET);
2758 filter->len = queueing & E1000_FHFT_QUEUEING_LEN;
2759 filter->priority = (queueing & E1000_FHFT_QUEUEING_PRIO) >>
2760 E1000_FHFT_QUEUEING_PRIO_SHIFT;
2761 *rx_queue = (queueing & E1000_FHFT_QUEUEING_QUEUE) >>
2762 E1000_FHFT_QUEUEING_QUEUE_SHIFT;
2769 * add a 5tuple filter
2772 * dev: Pointer to struct rte_eth_dev.
2773 * index: the index the filter allocates.
2774 * filter: ponter to the filter that will be added.
2775 * rx_queue: the queue id the filter assigned to.
2778 * - On success, zero.
2779 * - On failure, a negative value.
2782 eth_igb_add_5tuple_filter(struct rte_eth_dev *dev, uint16_t index,
2783 struct rte_5tuple_filter *filter, uint16_t rx_queue)
2785 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2786 uint32_t ftqf, spqf = 0;
2788 uint32_t imir_ext = 0;
2790 if (hw->mac.type != e1000_82576)
2793 if (index >= E1000_MAX_FTQF_FILTERS ||
2794 rx_queue >= IGB_MAX_RX_QUEUE_NUM_82576)
2795 return -EINVAL; /* filter index is out of range. */
2797 ftqf = E1000_READ_REG(hw, E1000_FTQF(index));
2798 if (ftqf & E1000_FTQF_QUEUE_ENABLE)
2799 return -EINVAL; /* filter index is in use. */
2802 ftqf |= filter->protocol & E1000_FTQF_PROTOCOL_MASK;
2803 if (filter->src_ip_mask == 1) /* 1b means not compare. */
2804 ftqf |= E1000_FTQF_SOURCE_ADDR_MASK;
2805 if (filter->dst_ip_mask == 1)
2806 ftqf |= E1000_FTQF_DEST_ADDR_MASK;
2807 if (filter->src_port_mask == 1)
2808 ftqf |= E1000_FTQF_SOURCE_PORT_MASK;
2809 if (filter->protocol_mask == 1)
2810 ftqf |= E1000_FTQF_PROTOCOL_COMP_MASK;
2811 ftqf |= (rx_queue << E1000_FTQF_QUEUE_SHIFT) & E1000_FTQF_QUEUE_MASK;
2812 ftqf |= E1000_FTQF_VF_MASK_EN;
2813 ftqf |= E1000_FTQF_QUEUE_ENABLE;
2814 E1000_WRITE_REG(hw, E1000_FTQF(index), ftqf);
2815 E1000_WRITE_REG(hw, E1000_DAQF(index), filter->dst_ip);
2816 E1000_WRITE_REG(hw, E1000_SAQF(index), filter->src_ip);
2818 spqf |= filter->src_port & E1000_SPQF_SRCPORT;
2819 E1000_WRITE_REG(hw, E1000_SPQF(index), spqf);
2821 imir |= (uint32_t)(filter->dst_port & E1000_IMIR_DSTPORT);
2822 if (filter->dst_port_mask == 1) /* 1b means not compare. */
2823 imir |= E1000_IMIR_PORT_BP;
2825 imir &= ~E1000_IMIR_PORT_BP;
2826 imir |= filter->priority << E1000_IMIR_PRIORITY_SHIFT;
2828 imir_ext |= E1000_IMIR_EXT_SIZE_BP;
2829 /* tcp flags bits setting. */
2830 if (filter->tcp_flags & TCP_FLAG_ALL) {
2831 if (filter->tcp_flags & TCP_UGR_FLAG)
2832 imir_ext |= E1000_IMIR_EXT_CTRL_UGR;
2833 if (filter->tcp_flags & TCP_ACK_FLAG)
2834 imir_ext |= E1000_IMIR_EXT_CTRL_ACK;
2835 if (filter->tcp_flags & TCP_PSH_FLAG)
2836 imir_ext |= E1000_IMIR_EXT_CTRL_PSH;
2837 if (filter->tcp_flags & TCP_RST_FLAG)
2838 imir_ext |= E1000_IMIR_EXT_CTRL_RST;
2839 if (filter->tcp_flags & TCP_SYN_FLAG)
2840 imir_ext |= E1000_IMIR_EXT_CTRL_SYN;
2841 if (filter->tcp_flags & TCP_FIN_FLAG)
2842 imir_ext |= E1000_IMIR_EXT_CTRL_FIN;
2844 imir_ext |= E1000_IMIR_EXT_CTRL_BP;
2845 E1000_WRITE_REG(hw, E1000_IMIR(index), imir);
2846 E1000_WRITE_REG(hw, E1000_IMIREXT(index), imir_ext);
2851 * remove a 5tuple filter
2854 * dev: Pointer to struct rte_eth_dev.
2855 * index: the index the filter allocates
2858 * - On success, zero.
2859 * - On failure, a negative value.
2862 eth_igb_remove_5tuple_filter(struct rte_eth_dev *dev,
2865 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2867 if (hw->mac.type != e1000_82576)
2870 if (index >= E1000_MAX_FTQF_FILTERS)
2871 return -EINVAL; /* filter index is out of range. */
2873 E1000_WRITE_REG(hw, E1000_FTQF(index), 0);
2874 E1000_WRITE_REG(hw, E1000_DAQF(index), 0);
2875 E1000_WRITE_REG(hw, E1000_SAQF(index), 0);
2876 E1000_WRITE_REG(hw, E1000_SPQF(index), 0);
2877 E1000_WRITE_REG(hw, E1000_IMIR(index), 0);
2878 E1000_WRITE_REG(hw, E1000_IMIREXT(index), 0);
2883 * get a 5tuple filter
2886 * dev: Pointer to struct rte_eth_dev.
2887 * index: the index the filter allocates
2888 * filter: ponter to the filter that returns
2889 * *rx_queue: pointer of the queue id the filter assigned to
2892 * - On success, zero.
2893 * - On failure, a negative value.
2896 eth_igb_get_5tuple_filter(struct rte_eth_dev *dev, uint16_t index,
2897 struct rte_5tuple_filter *filter, uint16_t *rx_queue)
2899 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2900 uint32_t spqf, ftqf, imir, imir_ext;
2902 if (hw->mac.type != e1000_82576)
2905 if (index >= E1000_MAX_FTQF_FILTERS)
2906 return -EINVAL; /* filter index is out of range. */
2908 ftqf = E1000_READ_REG(hw, E1000_FTQF(index));
2909 if (ftqf & E1000_FTQF_QUEUE_ENABLE) {
2910 filter->src_ip_mask =
2911 (ftqf & E1000_FTQF_SOURCE_ADDR_MASK) ? 1 : 0;
2912 filter->dst_ip_mask =
2913 (ftqf & E1000_FTQF_DEST_ADDR_MASK) ? 1 : 0;
2914 filter->src_port_mask =
2915 (ftqf & E1000_FTQF_SOURCE_PORT_MASK) ? 1 : 0;
2916 filter->protocol_mask =
2917 (ftqf & E1000_FTQF_PROTOCOL_COMP_MASK) ? 1 : 0;
2919 (uint8_t)ftqf & E1000_FTQF_PROTOCOL_MASK;
2920 *rx_queue = (uint16_t)((ftqf & E1000_FTQF_QUEUE_MASK) >>
2921 E1000_FTQF_QUEUE_SHIFT);
2923 spqf = E1000_READ_REG(hw, E1000_SPQF(index));
2924 filter->src_port = spqf & E1000_SPQF_SRCPORT;
2926 filter->dst_ip = E1000_READ_REG(hw, E1000_DAQF(index));
2927 filter->src_ip = E1000_READ_REG(hw, E1000_SAQF(index));
2929 imir = E1000_READ_REG(hw, E1000_IMIR(index));
2930 filter->dst_port_mask = (imir & E1000_IMIR_PORT_BP) ? 1 : 0;
2931 filter->dst_port = (uint16_t)(imir & E1000_IMIR_DSTPORT);
2932 filter->priority = (imir & E1000_IMIR_PRIORITY) >>
2933 E1000_IMIR_PRIORITY_SHIFT;
2935 imir_ext = E1000_READ_REG(hw, E1000_IMIREXT(index));
2936 if (!(imir_ext & E1000_IMIR_EXT_CTRL_BP)) {
2937 if (imir_ext & E1000_IMIR_EXT_CTRL_UGR)
2938 filter->tcp_flags |= TCP_UGR_FLAG;
2939 if (imir_ext & E1000_IMIR_EXT_CTRL_ACK)
2940 filter->tcp_flags |= TCP_ACK_FLAG;
2941 if (imir_ext & E1000_IMIR_EXT_CTRL_PSH)
2942 filter->tcp_flags |= TCP_PSH_FLAG;
2943 if (imir_ext & E1000_IMIR_EXT_CTRL_RST)
2944 filter->tcp_flags |= TCP_RST_FLAG;
2945 if (imir_ext & E1000_IMIR_EXT_CTRL_SYN)
2946 filter->tcp_flags |= TCP_SYN_FLAG;
2947 if (imir_ext & E1000_IMIR_EXT_CTRL_FIN)
2948 filter->tcp_flags |= TCP_FIN_FLAG;
2950 filter->tcp_flags = 0;
2956 static struct rte_driver pmd_igb_drv = {
2958 .init = rte_igb_pmd_init,
2961 static struct rte_driver pmd_igbvf_drv = {
2963 .init = rte_igbvf_pmd_init,
2966 PMD_REGISTER_DRIVER(pmd_igb_drv);
2967 PMD_REGISTER_DRIVER(pmd_igbvf_drv);