4 * Copyright(c) 2010-2013 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.
35 #include <sys/queue.h>
41 #include <rte_common.h>
42 #include <rte_interrupts.h>
43 #include <rte_byteorder.h>
45 #include <rte_debug.h>
47 #include <rte_ether.h>
48 #include <rte_ethdev.h>
49 #include <rte_memory.h>
50 #include <rte_memzone.h>
51 #include <rte_tailq.h>
53 #include <rte_atomic.h>
54 #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_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);
124 * Define VF Stats MACRO for Non "cleared on read" register
126 #define UPDATE_VF_STAT(reg, last, cur) \
128 u32 latest = E1000_READ_REG(hw, reg); \
129 cur += latest - last; \
134 #define IGB_FC_PAUSE_TIME 0x0680
135 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
136 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
138 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
141 * The set of PCI devices this driver supports
143 static struct rte_pci_id pci_id_igb_map[] = {
145 #define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
146 #include "rte_pci_dev_ids.h"
152 * The set of PCI devices this driver supports (for 82576&I350 VF)
154 static struct rte_pci_id pci_id_igbvf_map[] = {
156 #define RTE_PCI_DEV_ID_DECL_IGBVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
157 #include "rte_pci_dev_ids.h"
162 static struct eth_dev_ops eth_igb_ops = {
163 .dev_configure = eth_igb_configure,
164 .dev_start = eth_igb_start,
165 .dev_stop = eth_igb_stop,
166 .dev_close = eth_igb_close,
167 .promiscuous_enable = eth_igb_promiscuous_enable,
168 .promiscuous_disable = eth_igb_promiscuous_disable,
169 .allmulticast_enable = eth_igb_allmulticast_enable,
170 .allmulticast_disable = eth_igb_allmulticast_disable,
171 .link_update = eth_igb_link_update,
172 .stats_get = eth_igb_stats_get,
173 .stats_reset = eth_igb_stats_reset,
174 .dev_infos_get = eth_igb_infos_get,
175 .vlan_filter_set = eth_igb_vlan_filter_set,
176 .vlan_tpid_set = eth_igb_vlan_tpid_set,
177 .vlan_offload_set = eth_igb_vlan_offload_set,
178 .rx_queue_setup = eth_igb_rx_queue_setup,
179 .rx_queue_release = eth_igb_rx_queue_release,
180 .tx_queue_setup = eth_igb_tx_queue_setup,
181 .tx_queue_release = eth_igb_tx_queue_release,
182 .dev_led_on = eth_igb_led_on,
183 .dev_led_off = eth_igb_led_off,
184 .flow_ctrl_set = eth_igb_flow_ctrl_set,
185 .mac_addr_add = eth_igb_rar_set,
186 .mac_addr_remove = eth_igb_rar_clear,
190 * dev_ops for virtual function, bare necessities for basic vf
191 * operation have been implemented
193 static struct eth_dev_ops igbvf_eth_dev_ops = {
194 .dev_configure = igbvf_dev_configure,
195 .dev_start = igbvf_dev_start,
196 .dev_stop = igbvf_dev_stop,
197 .dev_close = igbvf_dev_close,
198 .link_update = eth_igb_link_update,
199 .stats_get = eth_igbvf_stats_get,
200 .stats_reset = eth_igbvf_stats_reset,
201 .vlan_filter_set = igbvf_vlan_filter_set,
202 .dev_infos_get = eth_igb_infos_get,
203 .rx_queue_setup = eth_igb_rx_queue_setup,
204 .rx_queue_release = eth_igb_rx_queue_release,
205 .tx_queue_setup = eth_igb_tx_queue_setup,
206 .tx_queue_release = eth_igb_tx_queue_release,
210 * Atomically reads the link status information from global
211 * structure rte_eth_dev.
214 * - Pointer to the structure rte_eth_dev to read from.
215 * - Pointer to the buffer to be saved with the link status.
218 * - On success, zero.
219 * - On failure, negative value.
222 rte_igb_dev_atomic_read_link_status(struct rte_eth_dev *dev,
223 struct rte_eth_link *link)
225 struct rte_eth_link *dst = link;
226 struct rte_eth_link *src = &(dev->data->dev_link);
228 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
229 *(uint64_t *)src) == 0)
236 * Atomically writes the link status information into global
237 * structure rte_eth_dev.
240 * - Pointer to the structure rte_eth_dev to read from.
241 * - Pointer to the buffer to be saved with the link status.
244 * - On success, zero.
245 * - On failure, negative value.
248 rte_igb_dev_atomic_write_link_status(struct rte_eth_dev *dev,
249 struct rte_eth_link *link)
251 struct rte_eth_link *dst = &(dev->data->dev_link);
252 struct rte_eth_link *src = link;
254 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
255 *(uint64_t *)src) == 0)
262 igb_identify_hardware(struct rte_eth_dev *dev)
264 struct e1000_hw *hw =
265 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
267 hw->vendor_id = dev->pci_dev->id.vendor_id;
268 hw->device_id = dev->pci_dev->id.device_id;
269 hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
270 hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
272 e1000_set_mac_type(hw);
274 /* need to check if it is a vf device below */
278 eth_igb_dev_init(__attribute__((unused)) struct eth_driver *eth_drv,
279 struct rte_eth_dev *eth_dev)
282 struct rte_pci_device *pci_dev;
283 struct e1000_hw *hw =
284 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
285 struct e1000_vfta * shadow_vfta =
286 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
288 pci_dev = eth_dev->pci_dev;
289 eth_dev->dev_ops = ð_igb_ops;
290 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
291 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
293 /* for secondary processes, we don't initialise any further as primary
294 * has already done this work. Only check we don't need a different
296 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
297 if (eth_dev->data->scattered_rx)
298 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
302 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
304 igb_identify_hardware(eth_dev);
305 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
310 e1000_get_bus_info(hw);
313 hw->phy.autoneg_wait_to_complete = 0;
314 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
317 if (hw->phy.media_type == e1000_media_type_copper) {
318 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
319 hw->phy.disable_polarity_correction = 0;
320 hw->phy.ms_type = e1000_ms_hw_default;
324 * Start from a known state, this is important in reading the nvm
329 /* Make sure we have a good EEPROM before we read from it */
330 if (e1000_validate_nvm_checksum(hw) < 0) {
332 * Some PCI-E parts fail the first check due to
333 * the link being in sleep state, call it again,
334 * if it fails a second time its a real issue.
336 if (e1000_validate_nvm_checksum(hw) < 0) {
337 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
343 /* Read the permanent MAC address out of the EEPROM */
344 if (e1000_read_mac_addr(hw) != 0) {
345 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
350 /* Allocate memory for storing MAC addresses */
351 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
352 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
353 if (eth_dev->data->mac_addrs == NULL) {
354 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
355 "store MAC addresses",
356 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
361 /* Copy the permanent MAC address */
362 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
364 /* initialize the vfta */
365 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
367 /* Now initialize the hardware */
368 if (igb_hardware_init(hw) != 0) {
369 PMD_INIT_LOG(ERR, "Hardware initialization failed");
370 rte_free(eth_dev->data->mac_addrs);
371 eth_dev->data->mac_addrs = NULL;
375 hw->mac.get_link_status = 1;
377 /* Indicate SOL/IDER usage */
378 if (e1000_check_reset_block(hw) < 0) {
379 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
383 PMD_INIT_LOG(INFO, "port_id %d vendorID=0x%x deviceID=0x%x\n",
384 eth_dev->data->port_id, pci_dev->id.vendor_id,
385 pci_dev->id.device_id);
387 rte_intr_callback_register(&(pci_dev->intr_handle),
388 eth_igb_interrupt_handler, (void *)eth_dev);
393 igb_hw_control_release(hw);
399 * Virtual Function device init
402 eth_igbvf_dev_init(__attribute__((unused)) struct eth_driver *eth_drv,
403 struct rte_eth_dev *eth_dev)
405 struct rte_pci_device *pci_dev;
406 struct e1000_hw *hw =
407 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
410 PMD_INIT_LOG(DEBUG, "eth_igbvf_dev_init");
412 eth_dev->dev_ops = &igbvf_eth_dev_ops;
413 pci_dev = eth_dev->pci_dev;
415 hw->device_id = pci_dev->id.device_id;
416 hw->vendor_id = pci_dev->id.vendor_id;
417 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
419 /* Initialize the shared code */
420 diag = e1000_setup_init_funcs(hw, TRUE);
422 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
427 /* init_mailbox_params */
428 hw->mbx.ops.init_params(hw);
430 /* Disable the interrupts for VF */
431 igbvf_intr_disable(hw);
433 diag = hw->mac.ops.reset_hw(hw);
435 /* Allocate memory for storing MAC addresses */
436 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
437 hw->mac.rar_entry_count, 0);
438 if (eth_dev->data->mac_addrs == NULL) {
440 "Failed to allocate %d bytes needed to store MAC "
442 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
445 /* Copy the permanent MAC address */
446 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
447 ð_dev->data->mac_addrs[0]);
449 PMD_INIT_LOG(DEBUG, "\nport %d vendorID=0x%x deviceID=0x%x "
451 eth_dev->data->port_id, pci_dev->id.vendor_id,
452 pci_dev->id.device_id,
458 static struct eth_driver rte_igb_pmd = {
460 .name = "rte_igb_pmd",
461 .id_table = pci_id_igb_map,
462 .drv_flags = RTE_PCI_DRV_NEED_IGB_UIO,
464 .eth_dev_init = eth_igb_dev_init,
465 .dev_private_size = sizeof(struct e1000_adapter),
469 * virtual function driver struct
471 static struct eth_driver rte_igbvf_pmd = {
473 .name = "rte_igbvf_pmd",
474 .id_table = pci_id_igbvf_map,
475 .drv_flags = RTE_PCI_DRV_NEED_IGB_UIO,
477 .eth_dev_init = eth_igbvf_dev_init,
478 .dev_private_size = sizeof(struct e1000_adapter),
482 rte_igb_pmd_init(void)
484 rte_eth_driver_register(&rte_igb_pmd);
489 * VF Driver initialization routine.
490 * Invoked one at EAL init time.
491 * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
494 rte_igbvf_pmd_init(void)
496 DEBUGFUNC("rte_igbvf_pmd_init");
498 rte_eth_driver_register(&rte_igbvf_pmd);
503 eth_igb_configure(struct rte_eth_dev *dev)
505 struct e1000_interrupt *intr =
506 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
508 PMD_INIT_LOG(DEBUG, ">>");
510 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
512 PMD_INIT_LOG(DEBUG, "<<");
518 eth_igb_start(struct rte_eth_dev *dev)
520 struct e1000_hw *hw =
521 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
524 PMD_INIT_LOG(DEBUG, ">>");
526 igb_intr_disable(hw);
528 /* Power up the phy. Needed to make the link go Up */
529 e1000_power_up_phy(hw);
532 * Packet Buffer Allocation (PBA)
533 * Writing PBA sets the receive portion of the buffer
534 * the remainder is used for the transmit buffer.
536 if (hw->mac.type == e1000_82575) {
539 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
540 E1000_WRITE_REG(hw, E1000_PBA, pba);
543 /* Put the address into the Receive Address Array */
544 e1000_rar_set(hw, hw->mac.addr, 0);
546 /* Initialize the hardware */
547 if (igb_hardware_init(hw)) {
548 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
552 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN);
554 /* Configure for OS presence */
555 igb_init_manageability(hw);
557 eth_igb_tx_init(dev);
559 /* This can fail when allocating mbufs for descriptor rings */
560 ret = eth_igb_rx_init(dev);
562 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
563 igb_dev_clear_queues(dev);
567 e1000_clear_hw_cntrs_base_generic(hw);
570 * VLAN Offload Settings
572 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
573 ETH_VLAN_EXTEND_MASK;
574 eth_igb_vlan_offload_set(dev, mask);
577 * Configure the Interrupt Moderation register (EITR) with the maximum
578 * possible value (0xFFFF) to minimize "System Partial Write" issued by
579 * spurious [DMA] memory updates of RX and TX ring descriptors.
581 * With a EITR granularity of 2 microseconds in the 82576, only 7/8
582 * spurious memory updates per second should be expected.
583 * ((65535 * 2) / 1000.1000 ~= 0.131 second).
585 * Because interrupts are not used at all, the MSI-X is not activated
586 * and interrupt moderation is controlled by EITR[0].
588 * Note that having [almost] disabled memory updates of RX and TX ring
589 * descriptors through the Interrupt Moderation mechanism, memory
590 * updates of ring descriptors are now moderated by the configurable
591 * value of Write-Back Threshold registers.
593 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
594 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210)) {
597 /* Enable all RX & TX queues in the IVAR registers */
598 ivar = (uint32_t) ((E1000_IVAR_VALID << 16) | E1000_IVAR_VALID);
599 for (i = 0; i < 8; i++)
600 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, i, ivar);
602 /* Configure EITR with the maximum possible value (0xFFFF) */
603 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
606 /* Setup link speed and duplex */
607 switch (dev->data->dev_conf.link_speed) {
608 case ETH_LINK_SPEED_AUTONEG:
609 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
610 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
611 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
612 hw->phy.autoneg_advertised = E1000_ALL_HALF_DUPLEX;
613 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
614 hw->phy.autoneg_advertised = E1000_ALL_FULL_DUPLEX;
616 goto error_invalid_config;
618 case ETH_LINK_SPEED_10:
619 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
620 hw->phy.autoneg_advertised = E1000_ALL_10_SPEED;
621 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
622 hw->phy.autoneg_advertised = ADVERTISE_10_HALF;
623 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
624 hw->phy.autoneg_advertised = ADVERTISE_10_FULL;
626 goto error_invalid_config;
628 case ETH_LINK_SPEED_100:
629 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
630 hw->phy.autoneg_advertised = E1000_ALL_100_SPEED;
631 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
632 hw->phy.autoneg_advertised = ADVERTISE_100_HALF;
633 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
634 hw->phy.autoneg_advertised = ADVERTISE_100_FULL;
636 goto error_invalid_config;
638 case ETH_LINK_SPEED_1000:
639 if ((dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX) ||
640 (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX))
641 hw->phy.autoneg_advertised = ADVERTISE_1000_FULL;
643 goto error_invalid_config;
645 case ETH_LINK_SPEED_10000:
647 goto error_invalid_config;
649 e1000_setup_link(hw);
651 /* check if lsc interrupt feature is enabled */
652 if (dev->data->dev_conf.intr_conf.lsc != 0) {
653 ret = eth_igb_interrupt_setup(dev);
655 PMD_INIT_LOG(ERR, "Unable to setup interrupts");
656 igb_dev_clear_queues(dev);
661 PMD_INIT_LOG(DEBUG, "<<");
665 error_invalid_config:
666 PMD_INIT_LOG(ERR, "Invalid link_speed/link_duplex (%u/%u) for port %u\n",
667 dev->data->dev_conf.link_speed,
668 dev->data->dev_conf.link_duplex, dev->data->port_id);
669 igb_dev_clear_queues(dev);
673 /*********************************************************************
675 * This routine disables all traffic on the adapter by issuing a
676 * global reset on the MAC.
678 **********************************************************************/
680 eth_igb_stop(struct rte_eth_dev *dev)
682 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
683 struct rte_eth_link link;
685 igb_intr_disable(hw);
687 E1000_WRITE_REG(hw, E1000_WUC, 0);
689 /* Power down the phy. Needed to make the link go Down */
690 e1000_power_down_phy(hw);
692 igb_dev_clear_queues(dev);
694 /* clear the recorded link status */
695 memset(&link, 0, sizeof(link));
696 rte_igb_dev_atomic_write_link_status(dev, &link);
700 eth_igb_close(struct rte_eth_dev *dev)
702 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
703 struct rte_eth_link link;
706 e1000_phy_hw_reset(hw);
707 igb_release_manageability(hw);
708 igb_hw_control_release(hw);
710 igb_dev_clear_queues(dev);
712 memset(&link, 0, sizeof(link));
713 rte_igb_dev_atomic_write_link_status(dev, &link);
717 igb_get_rx_buffer_size(struct e1000_hw *hw)
719 uint32_t rx_buf_size;
720 if (hw->mac.type == e1000_82576) {
721 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
722 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
723 /* PBS needs to be translated according to a lookup table */
724 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
725 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
726 rx_buf_size = (rx_buf_size << 10);
727 } else if (hw->mac.type == e1000_i210) {
728 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
730 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
736 /*********************************************************************
738 * Initialize the hardware
740 **********************************************************************/
742 igb_hardware_init(struct e1000_hw *hw)
744 uint32_t rx_buf_size;
747 /* Let the firmware know the OS is in control */
748 igb_hw_control_acquire(hw);
751 * These parameters control the automatic generation (Tx) and
752 * response (Rx) to Ethernet PAUSE frames.
753 * - High water mark should allow for at least two standard size (1518)
754 * frames to be received after sending an XOFF.
755 * - Low water mark works best when it is very near the high water mark.
756 * This allows the receiver to restart by sending XON when it has
757 * drained a bit. Here we use an arbitary value of 1500 which will
758 * restart after one full frame is pulled from the buffer. There
759 * could be several smaller frames in the buffer and if so they will
760 * not trigger the XON until their total number reduces the buffer
762 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
764 rx_buf_size = igb_get_rx_buffer_size(hw);
766 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
767 hw->fc.low_water = hw->fc.high_water - 1500;
768 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
771 /* Set Flow control, use the tunable location if sane */
772 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
773 hw->fc.requested_mode = igb_fc_setting;
775 hw->fc.requested_mode = e1000_fc_none;
777 /* Issue a global reset */
779 E1000_WRITE_REG(hw, E1000_WUC, 0);
781 diag = e1000_init_hw(hw);
785 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN);
786 e1000_get_phy_info(hw);
787 e1000_check_for_link(hw);
792 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
794 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
796 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
797 struct e1000_hw_stats *stats =
798 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
801 if(hw->phy.media_type == e1000_media_type_copper ||
802 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
804 E1000_READ_REG(hw,E1000_SYMERRS);
805 stats->sec += E1000_READ_REG(hw, E1000_SEC);
808 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
809 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
810 stats->scc += E1000_READ_REG(hw, E1000_SCC);
811 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
813 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
814 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
815 stats->colc += E1000_READ_REG(hw, E1000_COLC);
816 stats->dc += E1000_READ_REG(hw, E1000_DC);
817 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
818 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
819 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
821 ** For watchdog management we need to know if we have been
822 ** paused during the last interval, so capture that here.
824 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
825 stats->xoffrxc += pause_frames;
826 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
827 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
828 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
829 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
830 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
831 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
832 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
833 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
834 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
835 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
836 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
837 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
839 /* For the 64-bit byte counters the low dword must be read first. */
840 /* Both registers clear on the read of the high dword */
842 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
843 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
844 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
845 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
847 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
848 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
849 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
850 stats->roc += E1000_READ_REG(hw, E1000_ROC);
851 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
853 stats->tor += E1000_READ_REG(hw, E1000_TORH);
854 stats->tot += E1000_READ_REG(hw, E1000_TOTH);
856 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
857 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
858 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
859 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
860 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
861 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
862 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
863 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
864 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
865 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
867 /* Interrupt Counts */
869 stats->iac += E1000_READ_REG(hw, E1000_IAC);
870 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
871 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
872 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
873 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
874 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
875 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
876 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
877 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
879 /* Host to Card Statistics */
881 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
882 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
883 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
884 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
885 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
886 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
887 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
888 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
889 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
890 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
891 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
892 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
893 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
894 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
896 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
897 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
898 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
899 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
900 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
901 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
903 if (rte_stats == NULL)
907 rte_stats->ierrors = stats->rxerrc + stats->crcerrs + stats->algnerrc +
908 stats->ruc + stats->roc + stats->mpc + stats->cexterr;
911 rte_stats->oerrors = stats->ecol + stats->latecol;
913 rte_stats->ipackets = stats->gprc;
914 rte_stats->opackets = stats->gptc;
915 rte_stats->ibytes = stats->gorc;
916 rte_stats->obytes = stats->gotc;
920 eth_igb_stats_reset(struct rte_eth_dev *dev)
922 struct e1000_hw_stats *hw_stats =
923 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
925 /* HW registers are cleared on read */
926 eth_igb_stats_get(dev, NULL);
928 /* Reset software totals */
929 memset(hw_stats, 0, sizeof(*hw_stats));
933 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
935 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
936 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
937 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
939 /* Good Rx packets, include VF loopback */
940 UPDATE_VF_STAT(E1000_VFGPRC,
941 hw_stats->last_gprc, hw_stats->gprc);
943 /* Good Rx octets, include VF loopback */
944 UPDATE_VF_STAT(E1000_VFGORC,
945 hw_stats->last_gorc, hw_stats->gorc);
947 /* Good Tx packets, include VF loopback */
948 UPDATE_VF_STAT(E1000_VFGPTC,
949 hw_stats->last_gptc, hw_stats->gptc);
951 /* Good Tx octets, include VF loopback */
952 UPDATE_VF_STAT(E1000_VFGOTC,
953 hw_stats->last_gotc, hw_stats->gotc);
955 /* Rx Multicst packets */
956 UPDATE_VF_STAT(E1000_VFMPRC,
957 hw_stats->last_mprc, hw_stats->mprc);
959 /* Good Rx loopback packets */
960 UPDATE_VF_STAT(E1000_VFGPRLBC,
961 hw_stats->last_gprlbc, hw_stats->gprlbc);
963 /* Good Rx loopback octets */
964 UPDATE_VF_STAT(E1000_VFGORLBC,
965 hw_stats->last_gorlbc, hw_stats->gorlbc);
967 /* Good Tx loopback packets */
968 UPDATE_VF_STAT(E1000_VFGPTLBC,
969 hw_stats->last_gptlbc, hw_stats->gptlbc);
971 /* Good Tx loopback octets */
972 UPDATE_VF_STAT(E1000_VFGOTLBC,
973 hw_stats->last_gotlbc, hw_stats->gotlbc);
975 if (rte_stats == NULL)
978 memset(rte_stats, 0, sizeof(*rte_stats));
979 rte_stats->ipackets = hw_stats->gprc;
980 rte_stats->ibytes = hw_stats->gorc;
981 rte_stats->opackets = hw_stats->gptc;
982 rte_stats->obytes = hw_stats->gotc;
983 rte_stats->imcasts = hw_stats->mprc;
984 rte_stats->ilbpackets = hw_stats->gprlbc;
985 rte_stats->ilbbytes = hw_stats->gorlbc;
986 rte_stats->olbpackets = hw_stats->gptlbc;
987 rte_stats->olbbytes = hw_stats->gotlbc;
992 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
994 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
995 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
997 /* Sync HW register to the last stats */
998 eth_igbvf_stats_get(dev, NULL);
1000 /* reset HW current stats*/
1001 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
1002 offsetof(struct e1000_vf_stats, gprc));
1007 eth_igb_infos_get(struct rte_eth_dev *dev,
1008 struct rte_eth_dev_info *dev_info)
1010 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1012 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1013 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
1014 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1016 switch (hw->mac.type) {
1018 dev_info->max_rx_queues = 4;
1019 dev_info->max_tx_queues = 4;
1023 dev_info->max_rx_queues = 16;
1024 dev_info->max_tx_queues = 16;
1028 dev_info->max_rx_queues = 8;
1029 dev_info->max_tx_queues = 8;
1033 dev_info->max_rx_queues = 8;
1034 dev_info->max_tx_queues = 8;
1038 dev_info->max_rx_queues = 4;
1039 dev_info->max_tx_queues = 4;
1043 dev_info->max_rx_queues = 2;
1044 dev_info->max_tx_queues = 2;
1047 case e1000_vfadapt_i350:
1048 dev_info->max_rx_queues = 1;
1049 dev_info->max_tx_queues = 1;
1053 /* Should not happen */
1054 dev_info->max_rx_queues = 0;
1055 dev_info->max_tx_queues = 0;
1059 /* return 0 means link status changed, -1 means not changed */
1061 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1063 struct e1000_hw *hw =
1064 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1065 struct rte_eth_link link, old;
1066 int link_check, count;
1069 hw->mac.get_link_status = 1;
1071 /* possible wait-to-complete in up to 9 seconds */
1072 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
1073 /* Read the real link status */
1074 switch (hw->phy.media_type) {
1075 case e1000_media_type_copper:
1076 /* Do the work to read phy */
1077 e1000_check_for_link(hw);
1078 link_check = !hw->mac.get_link_status;
1081 case e1000_media_type_fiber:
1082 e1000_check_for_link(hw);
1083 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
1087 case e1000_media_type_internal_serdes:
1088 e1000_check_for_link(hw);
1089 link_check = hw->mac.serdes_has_link;
1092 /* VF device is type_unknown */
1093 case e1000_media_type_unknown:
1094 eth_igbvf_link_update(hw);
1095 link_check = !hw->mac.get_link_status;
1101 if (link_check || wait_to_complete == 0)
1103 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
1105 memset(&link, 0, sizeof(link));
1106 rte_igb_dev_atomic_read_link_status(dev, &link);
1109 /* Now we check if a transition has happened */
1111 hw->mac.ops.get_link_up_info(hw, &link.link_speed,
1113 link.link_status = 1;
1114 } else if (!link_check) {
1115 link.link_speed = 0;
1116 link.link_duplex = 0;
1117 link.link_status = 0;
1119 rte_igb_dev_atomic_write_link_status(dev, &link);
1122 if (old.link_status == link.link_status)
1130 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
1131 * For ASF and Pass Through versions of f/w this means
1132 * that the driver is loaded.
1135 igb_hw_control_acquire(struct e1000_hw *hw)
1139 /* Let firmware know the driver has taken over */
1140 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1141 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1145 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
1146 * For ASF and Pass Through versions of f/w this means that the
1147 * driver is no longer loaded.
1150 igb_hw_control_release(struct e1000_hw *hw)
1154 /* Let firmware taken over control of h/w */
1155 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1156 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1157 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1161 * Bit of a misnomer, what this really means is
1162 * to enable OS management of the system... aka
1163 * to disable special hardware management features.
1166 igb_init_manageability(struct e1000_hw *hw)
1168 if (e1000_enable_mng_pass_thru(hw)) {
1169 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
1170 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1172 /* disable hardware interception of ARP */
1173 manc &= ~(E1000_MANC_ARP_EN);
1175 /* enable receiving management packets to the host */
1176 manc |= E1000_MANC_EN_MNG2HOST;
1177 manc2h |= 1 << 5; /* Mng Port 623 */
1178 manc2h |= 1 << 6; /* Mng Port 664 */
1179 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
1180 E1000_WRITE_REG(hw, E1000_MANC, manc);
1185 igb_release_manageability(struct e1000_hw *hw)
1187 if (e1000_enable_mng_pass_thru(hw)) {
1188 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1190 manc |= E1000_MANC_ARP_EN;
1191 manc &= ~E1000_MANC_EN_MNG2HOST;
1193 E1000_WRITE_REG(hw, E1000_MANC, manc);
1198 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
1200 struct e1000_hw *hw =
1201 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1204 rctl = E1000_READ_REG(hw, E1000_RCTL);
1205 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1206 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1210 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
1212 struct e1000_hw *hw =
1213 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1216 rctl = E1000_READ_REG(hw, E1000_RCTL);
1217 rctl &= (~E1000_RCTL_UPE);
1218 if (dev->data->all_multicast == 1)
1219 rctl |= E1000_RCTL_MPE;
1221 rctl &= (~E1000_RCTL_MPE);
1222 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1226 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
1228 struct e1000_hw *hw =
1229 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1232 rctl = E1000_READ_REG(hw, E1000_RCTL);
1233 rctl |= E1000_RCTL_MPE;
1234 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1238 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
1240 struct e1000_hw *hw =
1241 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1244 if (dev->data->promiscuous == 1)
1245 return; /* must remain in all_multicast mode */
1246 rctl = E1000_READ_REG(hw, E1000_RCTL);
1247 rctl &= (~E1000_RCTL_MPE);
1248 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1252 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1254 struct e1000_hw *hw =
1255 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1256 struct e1000_vfta * shadow_vfta =
1257 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1262 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
1263 E1000_VFTA_ENTRY_MASK);
1264 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
1265 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
1270 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
1272 /* update local VFTA copy */
1273 shadow_vfta->vfta[vid_idx] = vfta;
1279 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid)
1281 struct e1000_hw *hw =
1282 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1283 uint32_t reg = ETHER_TYPE_VLAN ;
1285 reg |= (tpid << 16);
1286 E1000_WRITE_REG(hw, E1000_VET, reg);
1290 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1292 struct e1000_hw *hw =
1293 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1296 /* Filter Table Disable */
1297 reg = E1000_READ_REG(hw, E1000_RCTL);
1298 reg &= ~E1000_RCTL_CFIEN;
1299 reg &= ~E1000_RCTL_VFE;
1300 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1304 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1306 struct e1000_hw *hw =
1307 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1308 struct e1000_vfta * shadow_vfta =
1309 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1313 /* Filter Table Enable, CFI not used for packet acceptance */
1314 reg = E1000_READ_REG(hw, E1000_RCTL);
1315 reg &= ~E1000_RCTL_CFIEN;
1316 reg |= E1000_RCTL_VFE;
1317 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1319 /* restore VFTA table */
1320 for (i = 0; i < IGB_VFTA_SIZE; i++)
1321 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
1325 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
1327 struct e1000_hw *hw =
1328 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1331 /* VLAN Mode Disable */
1332 reg = E1000_READ_REG(hw, E1000_CTRL);
1333 reg &= ~E1000_CTRL_VME;
1334 E1000_WRITE_REG(hw, E1000_CTRL, reg);
1336 /* Update maximum frame size */
1337 E1000_WRITE_REG(hw, E1000_RLPML,
1338 dev->data->dev_conf.rxmode.max_rx_pkt_len + VLAN_TAG_SIZE);
1342 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
1344 struct e1000_hw *hw =
1345 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1348 /* VLAN Mode Enable */
1349 reg = E1000_READ_REG(hw, E1000_CTRL);
1350 reg |= E1000_CTRL_VME;
1351 E1000_WRITE_REG(hw, E1000_CTRL, reg);
1353 /* Update maximum frame size */
1354 E1000_WRITE_REG(hw, E1000_RLPML,
1355 dev->data->dev_conf.rxmode.max_rx_pkt_len);
1360 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
1362 struct e1000_hw *hw =
1363 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1366 /* CTRL_EXT: Extended VLAN */
1367 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1368 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
1369 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1374 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
1376 struct e1000_hw *hw =
1377 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1380 /* CTRL_EXT: Extended VLAN */
1381 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1382 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
1383 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1387 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1389 if(mask & ETH_VLAN_STRIP_MASK){
1390 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1391 igb_vlan_hw_strip_enable(dev);
1393 igb_vlan_hw_strip_disable(dev);
1396 if(mask & ETH_VLAN_FILTER_MASK){
1397 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1398 igb_vlan_hw_filter_enable(dev);
1400 igb_vlan_hw_filter_disable(dev);
1403 if(mask & ETH_VLAN_EXTEND_MASK){
1404 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1405 igb_vlan_hw_extend_enable(dev);
1407 igb_vlan_hw_extend_disable(dev);
1412 igb_intr_disable(struct e1000_hw *hw)
1414 E1000_WRITE_REG(hw, E1000_IMC, ~0);
1415 E1000_WRITE_FLUSH(hw);
1419 * It enables the interrupt mask and then enable the interrupt.
1422 * Pointer to struct rte_eth_dev.
1425 * - On success, zero.
1426 * - On failure, a negative value.
1429 eth_igb_interrupt_setup(struct rte_eth_dev *dev)
1431 struct e1000_hw *hw =
1432 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1434 E1000_WRITE_REG(hw, E1000_IMS, E1000_ICR_LSC);
1435 E1000_WRITE_FLUSH(hw);
1436 rte_intr_enable(&(dev->pci_dev->intr_handle));
1442 * It reads ICR and gets interrupt causes, check it and set a bit flag
1443 * to update link status.
1446 * Pointer to struct rte_eth_dev.
1449 * - On success, zero.
1450 * - On failure, a negative value.
1453 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
1456 struct e1000_hw *hw =
1457 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1458 struct e1000_interrupt *intr =
1459 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1461 /* read-on-clear nic registers here */
1462 icr = E1000_READ_REG(hw, E1000_ICR);
1463 if (icr & E1000_ICR_LSC) {
1464 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1471 * It executes link_update after knowing an interrupt is prsent.
1474 * Pointer to struct rte_eth_dev.
1477 * - On success, zero.
1478 * - On failure, a negative value.
1481 eth_igb_interrupt_action(struct rte_eth_dev *dev)
1483 struct e1000_hw *hw =
1484 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1485 struct e1000_interrupt *intr =
1486 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1487 uint32_t tctl, rctl;
1488 struct rte_eth_link link;
1491 if (!(intr->flags & E1000_FLAG_NEED_LINK_UPDATE))
1494 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
1495 rte_intr_enable(&(dev->pci_dev->intr_handle));
1497 /* set get_link_status to check register later */
1498 hw->mac.get_link_status = 1;
1499 ret = eth_igb_link_update(dev, 0);
1501 /* check if link has changed */
1505 memset(&link, 0, sizeof(link));
1506 rte_igb_dev_atomic_read_link_status(dev, &link);
1507 if (link.link_status) {
1509 " Port %d: Link Up - speed %u Mbps - %s\n",
1510 dev->data->port_id, (unsigned)link.link_speed,
1511 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
1512 "full-duplex" : "half-duplex");
1514 PMD_INIT_LOG(INFO, " Port %d: Link Down\n",
1515 dev->data->port_id);
1517 PMD_INIT_LOG(INFO, "PCI Address: %04d:%02d:%02d:%d",
1518 dev->pci_dev->addr.domain,
1519 dev->pci_dev->addr.bus,
1520 dev->pci_dev->addr.devid,
1521 dev->pci_dev->addr.function);
1522 tctl = E1000_READ_REG(hw, E1000_TCTL);
1523 rctl = E1000_READ_REG(hw, E1000_RCTL);
1524 if (link.link_status) {
1526 tctl |= E1000_TCTL_EN;
1527 rctl |= E1000_RCTL_EN;
1530 tctl &= ~E1000_TCTL_EN;
1531 rctl &= ~E1000_RCTL_EN;
1533 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1534 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1535 E1000_WRITE_FLUSH(hw);
1541 * Interrupt handler which shall be registered at first.
1544 * Pointer to interrupt handle.
1546 * The address of parameter (struct rte_eth_dev *) regsitered before.
1552 eth_igb_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
1555 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1557 eth_igb_interrupt_get_status(dev);
1558 eth_igb_interrupt_action(dev);
1559 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
1563 eth_igb_led_on(struct rte_eth_dev *dev)
1565 struct e1000_hw *hw;
1567 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1568 return (e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
1572 eth_igb_led_off(struct rte_eth_dev *dev)
1574 struct e1000_hw *hw;
1576 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1577 return (e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
1581 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1583 struct e1000_hw *hw;
1585 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
1591 uint32_t rx_buf_size;
1592 uint32_t max_high_water;
1594 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1595 rx_buf_size = igb_get_rx_buffer_size(hw);
1596 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x \n", rx_buf_size);
1598 /* At least reserve one Ethernet frame for watermark */
1599 max_high_water = rx_buf_size - ETHER_MAX_LEN;
1600 if ((fc_conf->high_water > max_high_water) ||
1601 (fc_conf->high_water < fc_conf->low_water)) {
1602 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value \n");
1603 PMD_INIT_LOG(ERR, "high water must <= 0x%x \n", max_high_water);
1607 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
1608 hw->fc.pause_time = fc_conf->pause_time;
1609 hw->fc.high_water = fc_conf->high_water;
1610 hw->fc.low_water = fc_conf->low_water;
1611 hw->fc.send_xon = fc_conf->send_xon;
1613 err = e1000_setup_link_generic(hw);
1614 if (err == E1000_SUCCESS) {
1618 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x \n", err);
1623 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
1624 uint32_t index, __rte_unused uint32_t pool)
1626 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1628 e1000_rar_set(hw, mac_addr->addr_bytes, index);
1632 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
1634 uint8_t addr[ETHER_ADDR_LEN];
1635 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1637 memset(addr, 0, sizeof(addr));
1639 e1000_rar_set(hw, addr, index);
1643 * Virtual Function operations
1646 igbvf_intr_disable(struct e1000_hw *hw)
1648 PMD_INIT_LOG(DEBUG, "igbvf_intr_disable");
1650 /* Clear interrupt mask to stop from interrupts being generated */
1651 E1000_WRITE_REG(hw, E1000_EIMC, ~0);
1653 E1000_WRITE_FLUSH(hw);
1657 igbvf_stop_adapter(struct rte_eth_dev *dev)
1661 struct rte_eth_dev_info dev_info;
1662 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1664 memset(&dev_info, 0, sizeof(dev_info));
1665 eth_igb_infos_get(dev, &dev_info);
1667 /* Clear interrupt mask to stop from interrupts being generated */
1668 E1000_WRITE_REG(hw, E1000_EIMC, ~0);
1670 /* Clear any pending interrupts, flush previous writes */
1671 E1000_READ_REG(hw, E1000_EICR);
1673 /* Disable the transmit unit. Each queue must be disabled. */
1674 for (i = 0; i < dev_info.max_tx_queues; i++)
1675 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
1677 /* Disable the receive unit by stopping each queue */
1678 for (i = 0; i < dev_info.max_rx_queues; i++) {
1679 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
1680 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
1681 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
1682 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
1686 /* flush all queues disables */
1687 E1000_WRITE_FLUSH(hw);
1691 static int eth_igbvf_link_update(struct e1000_hw *hw)
1693 struct e1000_mbx_info *mbx = &hw->mbx;
1694 struct e1000_mac_info *mac = &hw->mac;
1695 int ret_val = E1000_SUCCESS;
1697 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
1700 * We only want to run this if there has been a rst asserted.
1701 * in this case that could mean a link change, device reset,
1702 * or a virtual function reset
1705 /* If we were hit with a reset or timeout drop the link */
1706 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
1707 mac->get_link_status = TRUE;
1709 if (!mac->get_link_status)
1712 /* if link status is down no point in checking to see if pf is up */
1713 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
1716 /* if we passed all the tests above then the link is up and we no
1717 * longer need to check for link */
1718 mac->get_link_status = FALSE;
1726 igbvf_dev_configure(struct rte_eth_dev *dev)
1728 struct rte_eth_conf* conf = &dev->data->dev_conf;
1730 PMD_INIT_LOG(DEBUG, "\nConfigured Virtual Function port id: %d\n",
1731 dev->data->port_id);
1734 * VF has no ability to enable/disable HW CRC
1735 * Keep the persistent behavior the same as Host PF
1737 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
1738 if (!conf->rxmode.hw_strip_crc) {
1739 PMD_INIT_LOG(INFO, "VF can't disable HW CRC Strip\n");
1740 conf->rxmode.hw_strip_crc = 1;
1743 if (conf->rxmode.hw_strip_crc) {
1744 PMD_INIT_LOG(INFO, "VF can't enable HW CRC Strip\n");
1745 conf->rxmode.hw_strip_crc = 0;
1753 igbvf_dev_start(struct rte_eth_dev *dev)
1757 PMD_INIT_LOG(DEBUG, "igbvf_dev_start");
1760 igbvf_set_vfta_all(dev,1);
1762 eth_igbvf_tx_init(dev);
1764 /* This can fail when allocating mbufs for descriptor rings */
1765 ret = eth_igbvf_rx_init(dev);
1767 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1768 igb_dev_clear_queues(dev);
1776 igbvf_dev_stop(struct rte_eth_dev *dev)
1778 PMD_INIT_LOG(DEBUG, "igbvf_dev_stop");
1780 igbvf_stop_adapter(dev);
1783 * Clear what we set, but we still keep shadow_vfta to
1784 * restore after device starts
1786 igbvf_set_vfta_all(dev,0);
1788 igb_dev_clear_queues(dev);
1792 igbvf_dev_close(struct rte_eth_dev *dev)
1794 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1796 PMD_INIT_LOG(DEBUG, "igbvf_dev_close");
1800 igbvf_dev_stop(dev);
1803 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
1805 struct e1000_mbx_info *mbx = &hw->mbx;
1808 /* After set vlan, vlan strip will also be enabled in igb driver*/
1809 msgbuf[0] = E1000_VF_SET_VLAN;
1811 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
1813 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
1815 return (mbx->ops.write_posted(hw, msgbuf, 2, 0));
1818 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
1820 struct e1000_hw *hw =
1821 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1822 struct e1000_vfta * shadow_vfta =
1823 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1824 int i = 0, j = 0, vfta = 0, mask = 1;
1826 for (i = 0; i < IGB_VFTA_SIZE; i++){
1827 vfta = shadow_vfta->vfta[i];
1830 for (j = 0; j < 32; j++){
1833 (uint16_t)((i<<5)+j), on);
1842 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1844 struct e1000_hw *hw =
1845 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1846 struct e1000_vfta * shadow_vfta =
1847 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1848 uint32_t vid_idx = 0;
1849 uint32_t vid_bit = 0;
1852 PMD_INIT_LOG(DEBUG, "igbvf_vlan_filter_set");
1854 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
1855 ret = igbvf_set_vfta(hw, vlan_id, !!on);
1857 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
1860 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
1861 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
1863 /*Save what we set and retore it after device reset*/
1865 shadow_vfta->vfta[vid_idx] |= vid_bit;
1867 shadow_vfta->vfta[vid_idx] &= ~vid_bit;