4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/queue.h>
40 #include <rte_common.h>
41 #include <rte_interrupts.h>
42 #include <rte_byteorder.h>
44 #include <rte_debug.h>
46 #include <rte_ether.h>
47 #include <rte_ethdev.h>
48 #include <rte_memory.h>
49 #include <rte_memzone.h>
51 #include <rte_atomic.h>
52 #include <rte_malloc.h>
55 #include "e1000_logs.h"
56 #include "base/e1000_api.h"
57 #include "e1000_ethdev.h"
61 * Default values for port configuration
63 #define IGB_DEFAULT_RX_FREE_THRESH 32
64 #define IGB_DEFAULT_RX_PTHRESH 8
65 #define IGB_DEFAULT_RX_HTHRESH 8
66 #define IGB_DEFAULT_RX_WTHRESH 0
68 #define IGB_DEFAULT_TX_PTHRESH 32
69 #define IGB_DEFAULT_TX_HTHRESH 0
70 #define IGB_DEFAULT_TX_WTHRESH 0
72 #define IGB_HKEY_MAX_INDEX 10
74 /* Bit shift and mask */
75 #define IGB_4_BIT_WIDTH (CHAR_BIT / 2)
76 #define IGB_4_BIT_MASK RTE_LEN2MASK(IGB_4_BIT_WIDTH, uint8_t)
77 #define IGB_8_BIT_WIDTH CHAR_BIT
78 #define IGB_8_BIT_MASK UINT8_MAX
80 /* Additional timesync values. */
81 #define E1000_ETQF_FILTER_1588 3
82 #define E1000_TIMINCA_INCVALUE 16000000
83 #define E1000_TIMINCA_INIT ((0x02 << E1000_TIMINCA_16NS_SHIFT) \
84 | E1000_TIMINCA_INCVALUE)
85 #define E1000_TSAUXC_DISABLE_SYSTIME 0x80000000
87 static int eth_igb_configure(struct rte_eth_dev *dev);
88 static int eth_igb_start(struct rte_eth_dev *dev);
89 static void eth_igb_stop(struct rte_eth_dev *dev);
90 static void eth_igb_close(struct rte_eth_dev *dev);
91 static void eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
92 static void eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
93 static void eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
94 static void eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
95 static int eth_igb_link_update(struct rte_eth_dev *dev,
96 int wait_to_complete);
97 static void eth_igb_stats_get(struct rte_eth_dev *dev,
98 struct rte_eth_stats *rte_stats);
99 static void eth_igb_stats_reset(struct rte_eth_dev *dev);
100 static void eth_igb_infos_get(struct rte_eth_dev *dev,
101 struct rte_eth_dev_info *dev_info);
102 static void eth_igbvf_infos_get(struct rte_eth_dev *dev,
103 struct rte_eth_dev_info *dev_info);
104 static int eth_igb_flow_ctrl_get(struct rte_eth_dev *dev,
105 struct rte_eth_fc_conf *fc_conf);
106 static int eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
107 struct rte_eth_fc_conf *fc_conf);
108 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev);
110 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
112 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
113 static int eth_igb_interrupt_action(struct rte_eth_dev *dev);
114 static void eth_igb_interrupt_handler(struct rte_intr_handle *handle,
116 static int igb_hardware_init(struct e1000_hw *hw);
117 static void igb_hw_control_acquire(struct e1000_hw *hw);
118 static void igb_hw_control_release(struct e1000_hw *hw);
119 static void igb_init_manageability(struct e1000_hw *hw);
120 static void igb_release_manageability(struct e1000_hw *hw);
122 static int eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
124 static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
125 uint16_t vlan_id, int on);
126 static void eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid_id);
127 static void eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
129 static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
130 static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
131 static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
132 static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
133 static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
134 static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
136 static int eth_igb_led_on(struct rte_eth_dev *dev);
137 static int eth_igb_led_off(struct rte_eth_dev *dev);
139 static void igb_intr_disable(struct e1000_hw *hw);
140 static int igb_get_rx_buffer_size(struct e1000_hw *hw);
141 static void eth_igb_rar_set(struct rte_eth_dev *dev,
142 struct ether_addr *mac_addr,
143 uint32_t index, uint32_t pool);
144 static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
145 static void eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
146 struct ether_addr *addr);
148 static void igbvf_intr_disable(struct e1000_hw *hw);
149 static int igbvf_dev_configure(struct rte_eth_dev *dev);
150 static int igbvf_dev_start(struct rte_eth_dev *dev);
151 static void igbvf_dev_stop(struct rte_eth_dev *dev);
152 static void igbvf_dev_close(struct rte_eth_dev *dev);
153 static int eth_igbvf_link_update(struct e1000_hw *hw);
154 static void eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats);
155 static void eth_igbvf_stats_reset(struct rte_eth_dev *dev);
156 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
157 uint16_t vlan_id, int on);
158 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
159 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
160 static void igbvf_default_mac_addr_set(struct rte_eth_dev *dev,
161 struct ether_addr *addr);
162 static int igbvf_get_reg_length(struct rte_eth_dev *dev);
163 static int igbvf_get_regs(struct rte_eth_dev *dev,
164 struct rte_dev_reg_info *regs);
166 static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
167 struct rte_eth_rss_reta_entry64 *reta_conf,
169 static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
170 struct rte_eth_rss_reta_entry64 *reta_conf,
173 static int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
174 struct rte_eth_syn_filter *filter,
176 static int eth_igb_syn_filter_get(struct rte_eth_dev *dev,
177 struct rte_eth_syn_filter *filter);
178 static int eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
179 enum rte_filter_op filter_op,
181 static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
182 struct rte_eth_ntuple_filter *ntuple_filter);
183 static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
184 struct rte_eth_ntuple_filter *ntuple_filter);
185 static int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
186 struct rte_eth_flex_filter *filter,
188 static int eth_igb_get_flex_filter(struct rte_eth_dev *dev,
189 struct rte_eth_flex_filter *filter);
190 static int eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
191 enum rte_filter_op filter_op,
193 static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
194 struct rte_eth_ntuple_filter *ntuple_filter);
195 static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
196 struct rte_eth_ntuple_filter *ntuple_filter);
197 static int igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
198 struct rte_eth_ntuple_filter *filter,
200 static int igb_get_ntuple_filter(struct rte_eth_dev *dev,
201 struct rte_eth_ntuple_filter *filter);
202 static int igb_ntuple_filter_handle(struct rte_eth_dev *dev,
203 enum rte_filter_op filter_op,
205 static int igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
206 struct rte_eth_ethertype_filter *filter,
208 static int igb_ethertype_filter_handle(struct rte_eth_dev *dev,
209 enum rte_filter_op filter_op,
211 static int igb_get_ethertype_filter(struct rte_eth_dev *dev,
212 struct rte_eth_ethertype_filter *filter);
213 static int eth_igb_filter_ctrl(struct rte_eth_dev *dev,
214 enum rte_filter_type filter_type,
215 enum rte_filter_op filter_op,
217 static int eth_igb_get_reg_length(struct rte_eth_dev *dev);
218 static int eth_igb_get_regs(struct rte_eth_dev *dev,
219 struct rte_dev_reg_info *regs);
220 static int eth_igb_get_eeprom_length(struct rte_eth_dev *dev);
221 static int eth_igb_get_eeprom(struct rte_eth_dev *dev,
222 struct rte_dev_eeprom_info *eeprom);
223 static int eth_igb_set_eeprom(struct rte_eth_dev *dev,
224 struct rte_dev_eeprom_info *eeprom);
225 static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
226 struct ether_addr *mc_addr_set,
227 uint32_t nb_mc_addr);
228 static int igb_timesync_enable(struct rte_eth_dev *dev);
229 static int igb_timesync_disable(struct rte_eth_dev *dev);
230 static int igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
231 struct timespec *timestamp,
233 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
234 struct timespec *timestamp);
236 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
238 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
240 static void eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
241 uint8_t queue, uint8_t msix_vector);
242 static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
243 uint8_t index, uint8_t offset);
245 static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
248 * Define VF Stats MACRO for Non "cleared on read" register
250 #define UPDATE_VF_STAT(reg, last, cur) \
252 u32 latest = E1000_READ_REG(hw, reg); \
253 cur += latest - last; \
258 #define IGB_FC_PAUSE_TIME 0x0680
259 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
260 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
262 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
264 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
267 * The set of PCI devices this driver supports
269 static const struct rte_pci_id pci_id_igb_map[] = {
271 #define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
272 #include "rte_pci_dev_ids.h"
278 * The set of PCI devices this driver supports (for 82576&I350 VF)
280 static const struct rte_pci_id pci_id_igbvf_map[] = {
282 #define RTE_PCI_DEV_ID_DECL_IGBVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
283 #include "rte_pci_dev_ids.h"
288 static const struct eth_dev_ops eth_igb_ops = {
289 .dev_configure = eth_igb_configure,
290 .dev_start = eth_igb_start,
291 .dev_stop = eth_igb_stop,
292 .dev_close = eth_igb_close,
293 .promiscuous_enable = eth_igb_promiscuous_enable,
294 .promiscuous_disable = eth_igb_promiscuous_disable,
295 .allmulticast_enable = eth_igb_allmulticast_enable,
296 .allmulticast_disable = eth_igb_allmulticast_disable,
297 .link_update = eth_igb_link_update,
298 .stats_get = eth_igb_stats_get,
299 .stats_reset = eth_igb_stats_reset,
300 .dev_infos_get = eth_igb_infos_get,
301 .mtu_set = eth_igb_mtu_set,
302 .vlan_filter_set = eth_igb_vlan_filter_set,
303 .vlan_tpid_set = eth_igb_vlan_tpid_set,
304 .vlan_offload_set = eth_igb_vlan_offload_set,
305 .rx_queue_setup = eth_igb_rx_queue_setup,
307 .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
308 .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
310 .rx_queue_release = eth_igb_rx_queue_release,
311 .rx_queue_count = eth_igb_rx_queue_count,
312 .rx_descriptor_done = eth_igb_rx_descriptor_done,
313 .tx_queue_setup = eth_igb_tx_queue_setup,
314 .tx_queue_release = eth_igb_tx_queue_release,
315 .dev_led_on = eth_igb_led_on,
316 .dev_led_off = eth_igb_led_off,
317 .flow_ctrl_get = eth_igb_flow_ctrl_get,
318 .flow_ctrl_set = eth_igb_flow_ctrl_set,
319 .mac_addr_add = eth_igb_rar_set,
320 .mac_addr_remove = eth_igb_rar_clear,
321 .mac_addr_set = eth_igb_default_mac_addr_set,
322 .reta_update = eth_igb_rss_reta_update,
323 .reta_query = eth_igb_rss_reta_query,
324 .rss_hash_update = eth_igb_rss_hash_update,
325 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
326 .filter_ctrl = eth_igb_filter_ctrl,
327 .set_mc_addr_list = eth_igb_set_mc_addr_list,
328 .timesync_enable = igb_timesync_enable,
329 .timesync_disable = igb_timesync_disable,
330 .timesync_read_rx_timestamp = igb_timesync_read_rx_timestamp,
331 .timesync_read_tx_timestamp = igb_timesync_read_tx_timestamp,
332 .get_reg_length = eth_igb_get_reg_length,
333 .get_reg = eth_igb_get_regs,
334 .get_eeprom_length = eth_igb_get_eeprom_length,
335 .get_eeprom = eth_igb_get_eeprom,
336 .set_eeprom = eth_igb_set_eeprom,
340 * dev_ops for virtual function, bare necessities for basic vf
341 * operation have been implemented
343 static const struct eth_dev_ops igbvf_eth_dev_ops = {
344 .dev_configure = igbvf_dev_configure,
345 .dev_start = igbvf_dev_start,
346 .dev_stop = igbvf_dev_stop,
347 .dev_close = igbvf_dev_close,
348 .link_update = eth_igb_link_update,
349 .stats_get = eth_igbvf_stats_get,
350 .stats_reset = eth_igbvf_stats_reset,
351 .vlan_filter_set = igbvf_vlan_filter_set,
352 .dev_infos_get = eth_igbvf_infos_get,
353 .rx_queue_setup = eth_igb_rx_queue_setup,
354 .rx_queue_release = eth_igb_rx_queue_release,
355 .tx_queue_setup = eth_igb_tx_queue_setup,
356 .tx_queue_release = eth_igb_tx_queue_release,
357 .set_mc_addr_list = eth_igb_set_mc_addr_list,
358 .mac_addr_set = igbvf_default_mac_addr_set,
359 .get_reg_length = igbvf_get_reg_length,
360 .get_reg = igbvf_get_regs,
364 * Atomically reads the link status information from global
365 * structure rte_eth_dev.
368 * - Pointer to the structure rte_eth_dev to read from.
369 * - Pointer to the buffer to be saved with the link status.
372 * - On success, zero.
373 * - On failure, negative value.
376 rte_igb_dev_atomic_read_link_status(struct rte_eth_dev *dev,
377 struct rte_eth_link *link)
379 struct rte_eth_link *dst = link;
380 struct rte_eth_link *src = &(dev->data->dev_link);
382 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
383 *(uint64_t *)src) == 0)
390 * Atomically writes the link status information into global
391 * structure rte_eth_dev.
394 * - Pointer to the structure rte_eth_dev to read from.
395 * - Pointer to the buffer to be saved with the link status.
398 * - On success, zero.
399 * - On failure, negative value.
402 rte_igb_dev_atomic_write_link_status(struct rte_eth_dev *dev,
403 struct rte_eth_link *link)
405 struct rte_eth_link *dst = &(dev->data->dev_link);
406 struct rte_eth_link *src = link;
408 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
409 *(uint64_t *)src) == 0)
416 igb_intr_enable(struct rte_eth_dev *dev)
418 struct e1000_interrupt *intr =
419 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
420 struct e1000_hw *hw =
421 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
423 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
424 E1000_WRITE_FLUSH(hw);
428 igb_intr_disable(struct e1000_hw *hw)
430 E1000_WRITE_REG(hw, E1000_IMC, ~0);
431 E1000_WRITE_FLUSH(hw);
434 static inline int32_t
435 igb_pf_reset_hw(struct e1000_hw *hw)
440 status = e1000_reset_hw(hw);
442 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
443 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
444 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
445 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
446 E1000_WRITE_FLUSH(hw);
452 igb_identify_hardware(struct rte_eth_dev *dev)
454 struct e1000_hw *hw =
455 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
457 hw->vendor_id = dev->pci_dev->id.vendor_id;
458 hw->device_id = dev->pci_dev->id.device_id;
459 hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
460 hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
462 e1000_set_mac_type(hw);
464 /* need to check if it is a vf device below */
468 igb_reset_swfw_lock(struct e1000_hw *hw)
473 * Do mac ops initialization manually here, since we will need
474 * some function pointers set by this call.
476 ret_val = e1000_init_mac_params(hw);
481 * SMBI lock should not fail in this early stage. If this is the case,
482 * it is due to an improper exit of the application.
483 * So force the release of the faulty lock.
485 if (e1000_get_hw_semaphore_generic(hw) < 0) {
486 PMD_DRV_LOG(DEBUG, "SMBI lock released");
488 e1000_put_hw_semaphore_generic(hw);
490 if (hw->mac.ops.acquire_swfw_sync != NULL) {
494 * Phy lock should not fail in this early stage. If this is the case,
495 * it is due to an improper exit of the application.
496 * So force the release of the faulty lock.
498 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
499 if (hw->bus.func > E1000_FUNC_1)
501 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
502 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
505 hw->mac.ops.release_swfw_sync(hw, mask);
508 * This one is more tricky since it is common to all ports; but
509 * swfw_sync retries last long enough (1s) to be almost sure that if
510 * lock can not be taken it is due to an improper lock of the
513 mask = E1000_SWFW_EEP_SM;
514 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
515 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
517 hw->mac.ops.release_swfw_sync(hw, mask);
520 return E1000_SUCCESS;
524 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
527 struct rte_pci_device *pci_dev;
528 struct e1000_hw *hw =
529 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
530 struct e1000_vfta * shadow_vfta =
531 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
532 struct e1000_filter_info *filter_info =
533 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
534 struct e1000_adapter *adapter =
535 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
539 pci_dev = eth_dev->pci_dev;
540 eth_dev->dev_ops = ð_igb_ops;
541 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
542 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
544 /* for secondary processes, we don't initialise any further as primary
545 * has already done this work. Only check we don't need a different
547 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
548 if (eth_dev->data->scattered_rx)
549 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
553 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
555 igb_identify_hardware(eth_dev);
556 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
561 e1000_get_bus_info(hw);
563 /* Reset any pending lock */
564 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
569 /* Finish initialization */
570 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
576 hw->phy.autoneg_wait_to_complete = 0;
577 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
580 if (hw->phy.media_type == e1000_media_type_copper) {
581 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
582 hw->phy.disable_polarity_correction = 0;
583 hw->phy.ms_type = e1000_ms_hw_default;
587 * Start from a known state, this is important in reading the nvm
592 /* Make sure we have a good EEPROM before we read from it */
593 if (e1000_validate_nvm_checksum(hw) < 0) {
595 * Some PCI-E parts fail the first check due to
596 * the link being in sleep state, call it again,
597 * if it fails a second time its a real issue.
599 if (e1000_validate_nvm_checksum(hw) < 0) {
600 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
606 /* Read the permanent MAC address out of the EEPROM */
607 if (e1000_read_mac_addr(hw) != 0) {
608 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
613 /* Allocate memory for storing MAC addresses */
614 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
615 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
616 if (eth_dev->data->mac_addrs == NULL) {
617 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
618 "store MAC addresses",
619 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
624 /* Copy the permanent MAC address */
625 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
627 /* initialize the vfta */
628 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
630 /* Now initialize the hardware */
631 if (igb_hardware_init(hw) != 0) {
632 PMD_INIT_LOG(ERR, "Hardware initialization failed");
633 rte_free(eth_dev->data->mac_addrs);
634 eth_dev->data->mac_addrs = NULL;
638 hw->mac.get_link_status = 1;
639 adapter->stopped = 0;
641 /* Indicate SOL/IDER usage */
642 if (e1000_check_reset_block(hw) < 0) {
643 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
647 /* initialize PF if max_vfs not zero */
648 igb_pf_host_init(eth_dev);
650 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
651 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
652 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
653 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
654 E1000_WRITE_FLUSH(hw);
656 PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
657 eth_dev->data->port_id, pci_dev->id.vendor_id,
658 pci_dev->id.device_id);
660 /* enable support intr */
661 igb_intr_enable(eth_dev);
663 TAILQ_INIT(&filter_info->flex_list);
664 filter_info->flex_mask = 0;
665 TAILQ_INIT(&filter_info->twotuple_list);
666 filter_info->twotuple_mask = 0;
667 TAILQ_INIT(&filter_info->fivetuple_list);
668 filter_info->fivetuple_mask = 0;
673 igb_hw_control_release(hw);
679 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
681 struct rte_pci_device *pci_dev;
683 struct e1000_adapter *adapter =
684 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
686 PMD_INIT_FUNC_TRACE();
688 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
691 hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
692 pci_dev = eth_dev->pci_dev;
694 if (adapter->stopped == 0)
695 eth_igb_close(eth_dev);
697 eth_dev->dev_ops = NULL;
698 eth_dev->rx_pkt_burst = NULL;
699 eth_dev->tx_pkt_burst = NULL;
701 /* Reset any pending lock */
702 igb_reset_swfw_lock(hw);
704 rte_free(eth_dev->data->mac_addrs);
705 eth_dev->data->mac_addrs = NULL;
707 /* uninitialize PF if max_vfs not zero */
708 igb_pf_host_uninit(eth_dev);
710 /* disable uio intr before callback unregister */
711 rte_intr_disable(&(pci_dev->intr_handle));
712 rte_intr_callback_unregister(&(pci_dev->intr_handle),
713 eth_igb_interrupt_handler, (void *)eth_dev);
719 * Virtual Function device init
722 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
724 struct rte_pci_device *pci_dev;
725 struct e1000_adapter *adapter =
726 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
727 struct e1000_hw *hw =
728 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
731 PMD_INIT_FUNC_TRACE();
733 eth_dev->dev_ops = &igbvf_eth_dev_ops;
734 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
735 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
737 /* for secondary processes, we don't initialise any further as primary
738 * has already done this work. Only check we don't need a different
740 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
741 if (eth_dev->data->scattered_rx)
742 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
746 pci_dev = eth_dev->pci_dev;
748 hw->device_id = pci_dev->id.device_id;
749 hw->vendor_id = pci_dev->id.vendor_id;
750 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
751 adapter->stopped = 0;
753 /* Initialize the shared code (base driver) */
754 diag = e1000_setup_init_funcs(hw, TRUE);
756 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
761 /* init_mailbox_params */
762 hw->mbx.ops.init_params(hw);
764 /* Disable the interrupts for VF */
765 igbvf_intr_disable(hw);
767 diag = hw->mac.ops.reset_hw(hw);
769 /* Allocate memory for storing MAC addresses */
770 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
771 hw->mac.rar_entry_count, 0);
772 if (eth_dev->data->mac_addrs == NULL) {
774 "Failed to allocate %d bytes needed to store MAC "
776 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
780 /* Copy the permanent MAC address */
781 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
782 ð_dev->data->mac_addrs[0]);
784 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
786 eth_dev->data->port_id, pci_dev->id.vendor_id,
787 pci_dev->id.device_id, "igb_mac_82576_vf");
793 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
795 struct e1000_adapter *adapter =
796 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
798 PMD_INIT_FUNC_TRACE();
800 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
803 if (adapter->stopped == 0)
804 igbvf_dev_close(eth_dev);
806 eth_dev->dev_ops = NULL;
807 eth_dev->rx_pkt_burst = NULL;
808 eth_dev->tx_pkt_burst = NULL;
810 rte_free(eth_dev->data->mac_addrs);
811 eth_dev->data->mac_addrs = NULL;
816 static struct eth_driver rte_igb_pmd = {
818 .name = "rte_igb_pmd",
819 .id_table = pci_id_igb_map,
820 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
821 RTE_PCI_DRV_DETACHABLE,
823 .eth_dev_init = eth_igb_dev_init,
824 .eth_dev_uninit = eth_igb_dev_uninit,
825 .dev_private_size = sizeof(struct e1000_adapter),
829 * virtual function driver struct
831 static struct eth_driver rte_igbvf_pmd = {
833 .name = "rte_igbvf_pmd",
834 .id_table = pci_id_igbvf_map,
835 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
837 .eth_dev_init = eth_igbvf_dev_init,
838 .eth_dev_uninit = eth_igbvf_dev_uninit,
839 .dev_private_size = sizeof(struct e1000_adapter),
843 rte_igb_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
845 rte_eth_driver_register(&rte_igb_pmd);
850 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
852 struct e1000_hw *hw =
853 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
854 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
855 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
856 rctl |= E1000_RCTL_VFE;
857 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
861 * VF Driver initialization routine.
862 * Invoked one at EAL init time.
863 * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
866 rte_igbvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
868 PMD_INIT_FUNC_TRACE();
870 rte_eth_driver_register(&rte_igbvf_pmd);
875 eth_igb_configure(struct rte_eth_dev *dev)
877 struct e1000_interrupt *intr =
878 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
880 PMD_INIT_FUNC_TRACE();
881 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
882 PMD_INIT_FUNC_TRACE();
888 eth_igb_start(struct rte_eth_dev *dev)
890 struct e1000_hw *hw =
891 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
892 struct e1000_adapter *adapter =
893 E1000_DEV_PRIVATE(dev->data->dev_private);
894 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
897 uint32_t intr_vector = 0;
901 PMD_INIT_FUNC_TRACE();
903 /* Power up the phy. Needed to make the link go Up */
904 e1000_power_up_phy(hw);
907 * Packet Buffer Allocation (PBA)
908 * Writing PBA sets the receive portion of the buffer
909 * the remainder is used for the transmit buffer.
911 if (hw->mac.type == e1000_82575) {
914 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
915 E1000_WRITE_REG(hw, E1000_PBA, pba);
918 /* Put the address into the Receive Address Array */
919 e1000_rar_set(hw, hw->mac.addr, 0);
921 /* Initialize the hardware */
922 if (igb_hardware_init(hw)) {
923 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
926 adapter->stopped = 0;
928 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
930 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
931 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
932 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
933 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
934 E1000_WRITE_FLUSH(hw);
936 /* configure PF module if SRIOV enabled */
937 igb_pf_host_configure(dev);
940 /* check and configure queue intr-vector mapping */
941 if (dev->data->dev_conf.intr_conf.rxq != 0)
942 intr_vector = dev->data->nb_rx_queues;
944 if (rte_intr_efd_enable(intr_handle, intr_vector))
947 if (rte_intr_dp_is_en(intr_handle)) {
948 intr_handle->intr_vec =
949 rte_zmalloc("intr_vec",
950 dev->data->nb_rx_queues * sizeof(int), 0);
951 if (intr_handle->intr_vec == NULL) {
952 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
953 " intr_vec\n", dev->data->nb_rx_queues);
959 /* confiugre msix for rx interrupt */
960 eth_igb_configure_msix_intr(dev);
962 /* Configure for OS presence */
963 igb_init_manageability(hw);
965 eth_igb_tx_init(dev);
967 /* This can fail when allocating mbufs for descriptor rings */
968 ret = eth_igb_rx_init(dev);
970 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
971 igb_dev_clear_queues(dev);
975 e1000_clear_hw_cntrs_base_generic(hw);
978 * VLAN Offload Settings
980 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
981 ETH_VLAN_EXTEND_MASK;
982 eth_igb_vlan_offload_set(dev, mask);
984 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
985 /* Enable VLAN filter since VMDq always use VLAN filter */
986 igb_vmdq_vlan_hw_filter_enable(dev);
989 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
990 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
991 (hw->mac.type == e1000_i211)) {
992 /* Configure EITR with the maximum possible value (0xFFFF) */
993 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
996 /* Setup link speed and duplex */
997 switch (dev->data->dev_conf.link_speed) {
998 case ETH_LINK_SPEED_AUTONEG:
999 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
1000 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
1001 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
1002 hw->phy.autoneg_advertised = E1000_ALL_HALF_DUPLEX;
1003 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
1004 hw->phy.autoneg_advertised = E1000_ALL_FULL_DUPLEX;
1006 goto error_invalid_config;
1008 case ETH_LINK_SPEED_10:
1009 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
1010 hw->phy.autoneg_advertised = E1000_ALL_10_SPEED;
1011 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
1012 hw->phy.autoneg_advertised = ADVERTISE_10_HALF;
1013 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
1014 hw->phy.autoneg_advertised = ADVERTISE_10_FULL;
1016 goto error_invalid_config;
1018 case ETH_LINK_SPEED_100:
1019 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
1020 hw->phy.autoneg_advertised = E1000_ALL_100_SPEED;
1021 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
1022 hw->phy.autoneg_advertised = ADVERTISE_100_HALF;
1023 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
1024 hw->phy.autoneg_advertised = ADVERTISE_100_FULL;
1026 goto error_invalid_config;
1028 case ETH_LINK_SPEED_1000:
1029 if ((dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX) ||
1030 (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX))
1031 hw->phy.autoneg_advertised = ADVERTISE_1000_FULL;
1033 goto error_invalid_config;
1035 case ETH_LINK_SPEED_10000:
1037 goto error_invalid_config;
1039 e1000_setup_link(hw);
1041 /* check if lsc interrupt feature is enabled */
1042 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1043 if (rte_intr_allow_others(intr_handle)) {
1044 rte_intr_callback_register(intr_handle,
1045 eth_igb_interrupt_handler,
1047 eth_igb_lsc_interrupt_setup(dev);
1049 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1050 " no intr multiplex\n");
1054 /* check if rxq interrupt is enabled */
1055 if (dev->data->dev_conf.intr_conf.rxq != 0)
1056 eth_igb_rxq_interrupt_setup(dev);
1059 /* enable uio/vfio intr/eventfd mapping */
1060 rte_intr_enable(intr_handle);
1062 /* resume enabled intr since hw reset */
1063 igb_intr_enable(dev);
1065 PMD_INIT_LOG(DEBUG, "<<");
1069 error_invalid_config:
1070 PMD_INIT_LOG(ERR, "Invalid link_speed/link_duplex (%u/%u) for port %u",
1071 dev->data->dev_conf.link_speed,
1072 dev->data->dev_conf.link_duplex, dev->data->port_id);
1073 igb_dev_clear_queues(dev);
1077 /*********************************************************************
1079 * This routine disables all traffic on the adapter by issuing a
1080 * global reset on the MAC.
1082 **********************************************************************/
1084 eth_igb_stop(struct rte_eth_dev *dev)
1086 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1087 struct e1000_filter_info *filter_info =
1088 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1089 struct rte_eth_link link;
1090 struct e1000_flex_filter *p_flex;
1091 struct e1000_5tuple_filter *p_5tuple, *p_5tuple_next;
1092 struct e1000_2tuple_filter *p_2tuple, *p_2tuple_next;
1093 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1095 igb_intr_disable(hw);
1097 /* disable intr eventfd mapping */
1098 rte_intr_disable(intr_handle);
1100 igb_pf_reset_hw(hw);
1101 E1000_WRITE_REG(hw, E1000_WUC, 0);
1103 /* Set bit for Go Link disconnect */
1104 if (hw->mac.type >= e1000_82580) {
1107 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1108 phpm_reg |= E1000_82580_PM_GO_LINKD;
1109 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1112 /* Power down the phy. Needed to make the link go Down */
1113 if (hw->phy.media_type == e1000_media_type_copper)
1114 e1000_power_down_phy(hw);
1116 e1000_shutdown_fiber_serdes_link(hw);
1118 igb_dev_clear_queues(dev);
1120 /* clear the recorded link status */
1121 memset(&link, 0, sizeof(link));
1122 rte_igb_dev_atomic_write_link_status(dev, &link);
1124 /* Remove all flex filters of the device */
1125 while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
1126 TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
1129 filter_info->flex_mask = 0;
1131 /* Remove all ntuple filters of the device */
1132 for (p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list);
1133 p_5tuple != NULL; p_5tuple = p_5tuple_next) {
1134 p_5tuple_next = TAILQ_NEXT(p_5tuple, entries);
1135 TAILQ_REMOVE(&filter_info->fivetuple_list,
1139 filter_info->fivetuple_mask = 0;
1140 for (p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list);
1141 p_2tuple != NULL; p_2tuple = p_2tuple_next) {
1142 p_2tuple_next = TAILQ_NEXT(p_2tuple, entries);
1143 TAILQ_REMOVE(&filter_info->twotuple_list,
1147 filter_info->twotuple_mask = 0;
1150 /* Clean datapath event and queue/vec mapping */
1151 rte_intr_efd_disable(intr_handle);
1152 if (intr_handle->intr_vec != NULL) {
1153 rte_free(intr_handle->intr_vec);
1154 intr_handle->intr_vec = NULL;
1160 eth_igb_close(struct rte_eth_dev *dev)
1162 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1163 struct e1000_adapter *adapter =
1164 E1000_DEV_PRIVATE(dev->data->dev_private);
1165 struct rte_eth_link link;
1167 struct rte_pci_device *pci_dev;
1171 adapter->stopped = 1;
1173 e1000_phy_hw_reset(hw);
1174 igb_release_manageability(hw);
1175 igb_hw_control_release(hw);
1177 /* Clear bit for Go Link disconnect */
1178 if (hw->mac.type >= e1000_82580) {
1181 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1182 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1183 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1186 igb_dev_free_queues(dev);
1189 pci_dev = dev->pci_dev;
1190 if (pci_dev->intr_handle.intr_vec) {
1191 rte_free(pci_dev->intr_handle.intr_vec);
1192 pci_dev->intr_handle.intr_vec = NULL;
1196 memset(&link, 0, sizeof(link));
1197 rte_igb_dev_atomic_write_link_status(dev, &link);
1201 igb_get_rx_buffer_size(struct e1000_hw *hw)
1203 uint32_t rx_buf_size;
1204 if (hw->mac.type == e1000_82576) {
1205 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1206 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1207 /* PBS needs to be translated according to a lookup table */
1208 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1209 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1210 rx_buf_size = (rx_buf_size << 10);
1211 } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1212 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1214 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1220 /*********************************************************************
1222 * Initialize the hardware
1224 **********************************************************************/
1226 igb_hardware_init(struct e1000_hw *hw)
1228 uint32_t rx_buf_size;
1231 /* Let the firmware know the OS is in control */
1232 igb_hw_control_acquire(hw);
1235 * These parameters control the automatic generation (Tx) and
1236 * response (Rx) to Ethernet PAUSE frames.
1237 * - High water mark should allow for at least two standard size (1518)
1238 * frames to be received after sending an XOFF.
1239 * - Low water mark works best when it is very near the high water mark.
1240 * This allows the receiver to restart by sending XON when it has
1241 * drained a bit. Here we use an arbitrary value of 1500 which will
1242 * restart after one full frame is pulled from the buffer. There
1243 * could be several smaller frames in the buffer and if so they will
1244 * not trigger the XON until their total number reduces the buffer
1246 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1248 rx_buf_size = igb_get_rx_buffer_size(hw);
1250 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
1251 hw->fc.low_water = hw->fc.high_water - 1500;
1252 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1253 hw->fc.send_xon = 1;
1255 /* Set Flow control, use the tunable location if sane */
1256 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1257 hw->fc.requested_mode = igb_fc_setting;
1259 hw->fc.requested_mode = e1000_fc_none;
1261 /* Issue a global reset */
1262 igb_pf_reset_hw(hw);
1263 E1000_WRITE_REG(hw, E1000_WUC, 0);
1265 diag = e1000_init_hw(hw);
1269 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1270 e1000_get_phy_info(hw);
1271 e1000_check_for_link(hw);
1276 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1278 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1280 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1281 struct e1000_hw_stats *stats =
1282 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1285 if(hw->phy.media_type == e1000_media_type_copper ||
1286 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1288 E1000_READ_REG(hw,E1000_SYMERRS);
1289 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1292 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1293 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1294 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1295 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1297 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1298 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1299 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1300 stats->dc += E1000_READ_REG(hw, E1000_DC);
1301 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1302 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1303 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1305 ** For watchdog management we need to know if we have been
1306 ** paused during the last interval, so capture that here.
1308 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1309 stats->xoffrxc += pause_frames;
1310 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1311 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1312 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1313 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1314 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1315 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1316 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1317 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1318 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1319 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1320 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1321 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1323 /* For the 64-bit byte counters the low dword must be read first. */
1324 /* Both registers clear on the read of the high dword */
1326 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1327 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1328 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1329 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1331 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1332 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1333 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1334 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1335 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1337 stats->tor += E1000_READ_REG(hw, E1000_TORH);
1338 stats->tot += E1000_READ_REG(hw, E1000_TOTH);
1340 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1341 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1342 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1343 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1344 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1345 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1346 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1347 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1348 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1349 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1351 /* Interrupt Counts */
1353 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1354 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1355 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1356 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1357 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1358 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1359 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1360 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1361 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1363 /* Host to Card Statistics */
1365 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1366 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1367 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1368 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1369 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1370 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1371 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1372 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1373 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1374 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1375 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1376 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1377 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1378 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1380 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1381 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1382 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1383 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1384 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1385 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1387 if (rte_stats == NULL)
1391 rte_stats->ibadcrc = stats->crcerrs;
1392 rte_stats->ibadlen = stats->rlec + stats->ruc + stats->roc;
1393 rte_stats->imissed = stats->mpc;
1394 rte_stats->ierrors = rte_stats->ibadcrc +
1395 rte_stats->ibadlen +
1396 rte_stats->imissed +
1397 stats->rxerrc + stats->algnerrc + stats->cexterr;
1400 rte_stats->oerrors = stats->ecol + stats->latecol;
1402 /* XON/XOFF pause frames */
1403 rte_stats->tx_pause_xon = stats->xontxc;
1404 rte_stats->rx_pause_xon = stats->xonrxc;
1405 rte_stats->tx_pause_xoff = stats->xofftxc;
1406 rte_stats->rx_pause_xoff = stats->xoffrxc;
1408 rte_stats->ipackets = stats->gprc;
1409 rte_stats->opackets = stats->gptc;
1410 rte_stats->ibytes = stats->gorc;
1411 rte_stats->obytes = stats->gotc;
1415 eth_igb_stats_reset(struct rte_eth_dev *dev)
1417 struct e1000_hw_stats *hw_stats =
1418 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1420 /* HW registers are cleared on read */
1421 eth_igb_stats_get(dev, NULL);
1423 /* Reset software totals */
1424 memset(hw_stats, 0, sizeof(*hw_stats));
1428 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1430 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1431 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
1432 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1434 /* Good Rx packets, include VF loopback */
1435 UPDATE_VF_STAT(E1000_VFGPRC,
1436 hw_stats->last_gprc, hw_stats->gprc);
1438 /* Good Rx octets, include VF loopback */
1439 UPDATE_VF_STAT(E1000_VFGORC,
1440 hw_stats->last_gorc, hw_stats->gorc);
1442 /* Good Tx packets, include VF loopback */
1443 UPDATE_VF_STAT(E1000_VFGPTC,
1444 hw_stats->last_gptc, hw_stats->gptc);
1446 /* Good Tx octets, include VF loopback */
1447 UPDATE_VF_STAT(E1000_VFGOTC,
1448 hw_stats->last_gotc, hw_stats->gotc);
1450 /* Rx Multicst packets */
1451 UPDATE_VF_STAT(E1000_VFMPRC,
1452 hw_stats->last_mprc, hw_stats->mprc);
1454 /* Good Rx loopback packets */
1455 UPDATE_VF_STAT(E1000_VFGPRLBC,
1456 hw_stats->last_gprlbc, hw_stats->gprlbc);
1458 /* Good Rx loopback octets */
1459 UPDATE_VF_STAT(E1000_VFGORLBC,
1460 hw_stats->last_gorlbc, hw_stats->gorlbc);
1462 /* Good Tx loopback packets */
1463 UPDATE_VF_STAT(E1000_VFGPTLBC,
1464 hw_stats->last_gptlbc, hw_stats->gptlbc);
1466 /* Good Tx loopback octets */
1467 UPDATE_VF_STAT(E1000_VFGOTLBC,
1468 hw_stats->last_gotlbc, hw_stats->gotlbc);
1470 if (rte_stats == NULL)
1473 rte_stats->ipackets = hw_stats->gprc;
1474 rte_stats->ibytes = hw_stats->gorc;
1475 rte_stats->opackets = hw_stats->gptc;
1476 rte_stats->obytes = hw_stats->gotc;
1477 rte_stats->imcasts = hw_stats->mprc;
1478 rte_stats->ilbpackets = hw_stats->gprlbc;
1479 rte_stats->ilbbytes = hw_stats->gorlbc;
1480 rte_stats->olbpackets = hw_stats->gptlbc;
1481 rte_stats->olbbytes = hw_stats->gotlbc;
1486 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
1488 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
1489 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1491 /* Sync HW register to the last stats */
1492 eth_igbvf_stats_get(dev, NULL);
1494 /* reset HW current stats*/
1495 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
1496 offsetof(struct e1000_vf_stats, gprc));
1501 eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1503 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1505 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1506 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
1507 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1508 dev_info->rx_offload_capa =
1509 DEV_RX_OFFLOAD_VLAN_STRIP |
1510 DEV_RX_OFFLOAD_IPV4_CKSUM |
1511 DEV_RX_OFFLOAD_UDP_CKSUM |
1512 DEV_RX_OFFLOAD_TCP_CKSUM;
1513 dev_info->tx_offload_capa =
1514 DEV_TX_OFFLOAD_VLAN_INSERT |
1515 DEV_TX_OFFLOAD_IPV4_CKSUM |
1516 DEV_TX_OFFLOAD_UDP_CKSUM |
1517 DEV_TX_OFFLOAD_TCP_CKSUM |
1518 DEV_TX_OFFLOAD_SCTP_CKSUM;
1520 switch (hw->mac.type) {
1522 dev_info->max_rx_queues = 4;
1523 dev_info->max_tx_queues = 4;
1524 dev_info->max_vmdq_pools = 0;
1528 dev_info->max_rx_queues = 16;
1529 dev_info->max_tx_queues = 16;
1530 dev_info->max_vmdq_pools = ETH_8_POOLS;
1531 dev_info->vmdq_queue_num = 16;
1535 dev_info->max_rx_queues = 8;
1536 dev_info->max_tx_queues = 8;
1537 dev_info->max_vmdq_pools = ETH_8_POOLS;
1538 dev_info->vmdq_queue_num = 8;
1542 dev_info->max_rx_queues = 8;
1543 dev_info->max_tx_queues = 8;
1544 dev_info->max_vmdq_pools = ETH_8_POOLS;
1545 dev_info->vmdq_queue_num = 8;
1549 dev_info->max_rx_queues = 8;
1550 dev_info->max_tx_queues = 8;
1554 dev_info->max_rx_queues = 4;
1555 dev_info->max_tx_queues = 4;
1556 dev_info->max_vmdq_pools = 0;
1560 dev_info->max_rx_queues = 2;
1561 dev_info->max_tx_queues = 2;
1562 dev_info->max_vmdq_pools = 0;
1566 /* Should not happen */
1569 dev_info->hash_key_size = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
1570 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
1571 dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
1573 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1575 .pthresh = IGB_DEFAULT_RX_PTHRESH,
1576 .hthresh = IGB_DEFAULT_RX_HTHRESH,
1577 .wthresh = IGB_DEFAULT_RX_WTHRESH,
1579 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
1583 dev_info->default_txconf = (struct rte_eth_txconf) {
1585 .pthresh = IGB_DEFAULT_TX_PTHRESH,
1586 .hthresh = IGB_DEFAULT_TX_HTHRESH,
1587 .wthresh = IGB_DEFAULT_TX_WTHRESH,
1594 eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1596 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1598 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1599 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
1600 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1601 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
1602 DEV_RX_OFFLOAD_IPV4_CKSUM |
1603 DEV_RX_OFFLOAD_UDP_CKSUM |
1604 DEV_RX_OFFLOAD_TCP_CKSUM;
1605 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
1606 DEV_TX_OFFLOAD_IPV4_CKSUM |
1607 DEV_TX_OFFLOAD_UDP_CKSUM |
1608 DEV_TX_OFFLOAD_TCP_CKSUM |
1609 DEV_TX_OFFLOAD_SCTP_CKSUM;
1610 switch (hw->mac.type) {
1612 dev_info->max_rx_queues = 2;
1613 dev_info->max_tx_queues = 2;
1615 case e1000_vfadapt_i350:
1616 dev_info->max_rx_queues = 1;
1617 dev_info->max_tx_queues = 1;
1620 /* Should not happen */
1624 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1626 .pthresh = IGB_DEFAULT_RX_PTHRESH,
1627 .hthresh = IGB_DEFAULT_RX_HTHRESH,
1628 .wthresh = IGB_DEFAULT_RX_WTHRESH,
1630 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
1634 dev_info->default_txconf = (struct rte_eth_txconf) {
1636 .pthresh = IGB_DEFAULT_TX_PTHRESH,
1637 .hthresh = IGB_DEFAULT_TX_HTHRESH,
1638 .wthresh = IGB_DEFAULT_TX_WTHRESH,
1644 /* return 0 means link status changed, -1 means not changed */
1646 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1648 struct e1000_hw *hw =
1649 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1650 struct rte_eth_link link, old;
1651 int link_check, count;
1654 hw->mac.get_link_status = 1;
1656 /* possible wait-to-complete in up to 9 seconds */
1657 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
1658 /* Read the real link status */
1659 switch (hw->phy.media_type) {
1660 case e1000_media_type_copper:
1661 /* Do the work to read phy */
1662 e1000_check_for_link(hw);
1663 link_check = !hw->mac.get_link_status;
1666 case e1000_media_type_fiber:
1667 e1000_check_for_link(hw);
1668 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
1672 case e1000_media_type_internal_serdes:
1673 e1000_check_for_link(hw);
1674 link_check = hw->mac.serdes_has_link;
1677 /* VF device is type_unknown */
1678 case e1000_media_type_unknown:
1679 eth_igbvf_link_update(hw);
1680 link_check = !hw->mac.get_link_status;
1686 if (link_check || wait_to_complete == 0)
1688 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
1690 memset(&link, 0, sizeof(link));
1691 rte_igb_dev_atomic_read_link_status(dev, &link);
1694 /* Now we check if a transition has happened */
1696 hw->mac.ops.get_link_up_info(hw, &link.link_speed,
1698 link.link_status = 1;
1699 } else if (!link_check) {
1700 link.link_speed = 0;
1701 link.link_duplex = 0;
1702 link.link_status = 0;
1704 rte_igb_dev_atomic_write_link_status(dev, &link);
1707 if (old.link_status == link.link_status)
1715 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
1716 * For ASF and Pass Through versions of f/w this means
1717 * that the driver is loaded.
1720 igb_hw_control_acquire(struct e1000_hw *hw)
1724 /* Let firmware know the driver has taken over */
1725 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1726 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1730 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
1731 * For ASF and Pass Through versions of f/w this means that the
1732 * driver is no longer loaded.
1735 igb_hw_control_release(struct e1000_hw *hw)
1739 /* Let firmware taken over control of h/w */
1740 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1741 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1742 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1746 * Bit of a misnomer, what this really means is
1747 * to enable OS management of the system... aka
1748 * to disable special hardware management features.
1751 igb_init_manageability(struct e1000_hw *hw)
1753 if (e1000_enable_mng_pass_thru(hw)) {
1754 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
1755 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1757 /* disable hardware interception of ARP */
1758 manc &= ~(E1000_MANC_ARP_EN);
1760 /* enable receiving management packets to the host */
1761 manc |= E1000_MANC_EN_MNG2HOST;
1762 manc2h |= 1 << 5; /* Mng Port 623 */
1763 manc2h |= 1 << 6; /* Mng Port 664 */
1764 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
1765 E1000_WRITE_REG(hw, E1000_MANC, manc);
1770 igb_release_manageability(struct e1000_hw *hw)
1772 if (e1000_enable_mng_pass_thru(hw)) {
1773 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1775 manc |= E1000_MANC_ARP_EN;
1776 manc &= ~E1000_MANC_EN_MNG2HOST;
1778 E1000_WRITE_REG(hw, E1000_MANC, manc);
1783 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
1785 struct e1000_hw *hw =
1786 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1789 rctl = E1000_READ_REG(hw, E1000_RCTL);
1790 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1791 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1795 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
1797 struct e1000_hw *hw =
1798 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1801 rctl = E1000_READ_REG(hw, E1000_RCTL);
1802 rctl &= (~E1000_RCTL_UPE);
1803 if (dev->data->all_multicast == 1)
1804 rctl |= E1000_RCTL_MPE;
1806 rctl &= (~E1000_RCTL_MPE);
1807 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1811 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
1813 struct e1000_hw *hw =
1814 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1817 rctl = E1000_READ_REG(hw, E1000_RCTL);
1818 rctl |= E1000_RCTL_MPE;
1819 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1823 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
1825 struct e1000_hw *hw =
1826 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1829 if (dev->data->promiscuous == 1)
1830 return; /* must remain in all_multicast mode */
1831 rctl = E1000_READ_REG(hw, E1000_RCTL);
1832 rctl &= (~E1000_RCTL_MPE);
1833 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1837 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1839 struct e1000_hw *hw =
1840 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1841 struct e1000_vfta * shadow_vfta =
1842 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1847 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
1848 E1000_VFTA_ENTRY_MASK);
1849 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
1850 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
1855 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
1857 /* update local VFTA copy */
1858 shadow_vfta->vfta[vid_idx] = vfta;
1864 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid)
1866 struct e1000_hw *hw =
1867 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1868 uint32_t reg = ETHER_TYPE_VLAN ;
1870 reg |= (tpid << 16);
1871 E1000_WRITE_REG(hw, E1000_VET, reg);
1875 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1877 struct e1000_hw *hw =
1878 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1881 /* Filter Table Disable */
1882 reg = E1000_READ_REG(hw, E1000_RCTL);
1883 reg &= ~E1000_RCTL_CFIEN;
1884 reg &= ~E1000_RCTL_VFE;
1885 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1889 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1891 struct e1000_hw *hw =
1892 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1893 struct e1000_vfta * shadow_vfta =
1894 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1898 /* Filter Table Enable, CFI not used for packet acceptance */
1899 reg = E1000_READ_REG(hw, E1000_RCTL);
1900 reg &= ~E1000_RCTL_CFIEN;
1901 reg |= E1000_RCTL_VFE;
1902 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1904 /* restore VFTA table */
1905 for (i = 0; i < IGB_VFTA_SIZE; i++)
1906 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
1910 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
1912 struct e1000_hw *hw =
1913 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1916 /* VLAN Mode Disable */
1917 reg = E1000_READ_REG(hw, E1000_CTRL);
1918 reg &= ~E1000_CTRL_VME;
1919 E1000_WRITE_REG(hw, E1000_CTRL, reg);
1923 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
1925 struct e1000_hw *hw =
1926 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1929 /* VLAN Mode Enable */
1930 reg = E1000_READ_REG(hw, E1000_CTRL);
1931 reg |= E1000_CTRL_VME;
1932 E1000_WRITE_REG(hw, E1000_CTRL, reg);
1936 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
1938 struct e1000_hw *hw =
1939 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1942 /* CTRL_EXT: Extended VLAN */
1943 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1944 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
1945 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1947 /* Update maximum packet length */
1948 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
1949 E1000_WRITE_REG(hw, E1000_RLPML,
1950 dev->data->dev_conf.rxmode.max_rx_pkt_len +
1955 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
1957 struct e1000_hw *hw =
1958 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1961 /* CTRL_EXT: Extended VLAN */
1962 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
1963 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
1964 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
1966 /* Update maximum packet length */
1967 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
1968 E1000_WRITE_REG(hw, E1000_RLPML,
1969 dev->data->dev_conf.rxmode.max_rx_pkt_len +
1974 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1976 if(mask & ETH_VLAN_STRIP_MASK){
1977 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1978 igb_vlan_hw_strip_enable(dev);
1980 igb_vlan_hw_strip_disable(dev);
1983 if(mask & ETH_VLAN_FILTER_MASK){
1984 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1985 igb_vlan_hw_filter_enable(dev);
1987 igb_vlan_hw_filter_disable(dev);
1990 if(mask & ETH_VLAN_EXTEND_MASK){
1991 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1992 igb_vlan_hw_extend_enable(dev);
1994 igb_vlan_hw_extend_disable(dev);
2000 * It enables the interrupt mask and then enable the interrupt.
2003 * Pointer to struct rte_eth_dev.
2006 * - On success, zero.
2007 * - On failure, a negative value.
2010 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev)
2012 struct e1000_interrupt *intr =
2013 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2015 intr->mask |= E1000_ICR_LSC;
2021 /* It clears the interrupt causes and enables the interrupt.
2022 * It will be called once only during nic initialized.
2025 * Pointer to struct rte_eth_dev.
2028 * - On success, zero.
2029 * - On failure, a negative value.
2031 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev)
2033 uint32_t mask, regval;
2034 struct e1000_hw *hw =
2035 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2036 struct rte_eth_dev_info dev_info;
2038 memset(&dev_info, 0, sizeof(dev_info));
2039 eth_igb_infos_get(dev, &dev_info);
2041 mask = 0xFFFFFFFF >> (32 - dev_info.max_rx_queues);
2042 regval = E1000_READ_REG(hw, E1000_EIMS);
2043 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
2050 * It reads ICR and gets interrupt causes, check it and set a bit flag
2051 * to update link status.
2054 * Pointer to struct rte_eth_dev.
2057 * - On success, zero.
2058 * - On failure, a negative value.
2061 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
2064 struct e1000_hw *hw =
2065 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2066 struct e1000_interrupt *intr =
2067 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2069 igb_intr_disable(hw);
2071 /* read-on-clear nic registers here */
2072 icr = E1000_READ_REG(hw, E1000_ICR);
2075 if (icr & E1000_ICR_LSC) {
2076 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
2079 if (icr & E1000_ICR_VMMB)
2080 intr->flags |= E1000_FLAG_MAILBOX;
2086 * It executes link_update after knowing an interrupt is prsent.
2089 * Pointer to struct rte_eth_dev.
2092 * - On success, zero.
2093 * - On failure, a negative value.
2096 eth_igb_interrupt_action(struct rte_eth_dev *dev)
2098 struct e1000_hw *hw =
2099 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2100 struct e1000_interrupt *intr =
2101 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2102 uint32_t tctl, rctl;
2103 struct rte_eth_link link;
2106 if (intr->flags & E1000_FLAG_MAILBOX) {
2107 igb_pf_mbx_process(dev);
2108 intr->flags &= ~E1000_FLAG_MAILBOX;
2111 igb_intr_enable(dev);
2112 rte_intr_enable(&(dev->pci_dev->intr_handle));
2114 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
2115 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
2117 /* set get_link_status to check register later */
2118 hw->mac.get_link_status = 1;
2119 ret = eth_igb_link_update(dev, 0);
2121 /* check if link has changed */
2125 memset(&link, 0, sizeof(link));
2126 rte_igb_dev_atomic_read_link_status(dev, &link);
2127 if (link.link_status) {
2129 " Port %d: Link Up - speed %u Mbps - %s",
2131 (unsigned)link.link_speed,
2132 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2133 "full-duplex" : "half-duplex");
2135 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2136 dev->data->port_id);
2139 PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
2140 dev->pci_dev->addr.domain,
2141 dev->pci_dev->addr.bus,
2142 dev->pci_dev->addr.devid,
2143 dev->pci_dev->addr.function);
2144 tctl = E1000_READ_REG(hw, E1000_TCTL);
2145 rctl = E1000_READ_REG(hw, E1000_RCTL);
2146 if (link.link_status) {
2148 tctl |= E1000_TCTL_EN;
2149 rctl |= E1000_RCTL_EN;
2152 tctl &= ~E1000_TCTL_EN;
2153 rctl &= ~E1000_RCTL_EN;
2155 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
2156 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2157 E1000_WRITE_FLUSH(hw);
2158 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
2165 * Interrupt handler which shall be registered at first.
2168 * Pointer to interrupt handle.
2170 * The address of parameter (struct rte_eth_dev *) regsitered before.
2176 eth_igb_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
2179 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2181 eth_igb_interrupt_get_status(dev);
2182 eth_igb_interrupt_action(dev);
2186 eth_igb_led_on(struct rte_eth_dev *dev)
2188 struct e1000_hw *hw;
2190 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2191 return (e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
2195 eth_igb_led_off(struct rte_eth_dev *dev)
2197 struct e1000_hw *hw;
2199 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2200 return (e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
2204 eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2206 struct e1000_hw *hw;
2211 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2212 fc_conf->pause_time = hw->fc.pause_time;
2213 fc_conf->high_water = hw->fc.high_water;
2214 fc_conf->low_water = hw->fc.low_water;
2215 fc_conf->send_xon = hw->fc.send_xon;
2216 fc_conf->autoneg = hw->mac.autoneg;
2219 * Return rx_pause and tx_pause status according to actual setting of
2220 * the TFCE and RFCE bits in the CTRL register.
2222 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2223 if (ctrl & E1000_CTRL_TFCE)
2228 if (ctrl & E1000_CTRL_RFCE)
2233 if (rx_pause && tx_pause)
2234 fc_conf->mode = RTE_FC_FULL;
2236 fc_conf->mode = RTE_FC_RX_PAUSE;
2238 fc_conf->mode = RTE_FC_TX_PAUSE;
2240 fc_conf->mode = RTE_FC_NONE;
2246 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2248 struct e1000_hw *hw;
2250 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
2256 uint32_t rx_buf_size;
2257 uint32_t max_high_water;
2260 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2261 if (fc_conf->autoneg != hw->mac.autoneg)
2263 rx_buf_size = igb_get_rx_buffer_size(hw);
2264 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2266 /* At least reserve one Ethernet frame for watermark */
2267 max_high_water = rx_buf_size - ETHER_MAX_LEN;
2268 if ((fc_conf->high_water > max_high_water) ||
2269 (fc_conf->high_water < fc_conf->low_water)) {
2270 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
2271 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
2275 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
2276 hw->fc.pause_time = fc_conf->pause_time;
2277 hw->fc.high_water = fc_conf->high_water;
2278 hw->fc.low_water = fc_conf->low_water;
2279 hw->fc.send_xon = fc_conf->send_xon;
2281 err = e1000_setup_link_generic(hw);
2282 if (err == E1000_SUCCESS) {
2284 /* check if we want to forward MAC frames - driver doesn't have native
2285 * capability to do that, so we'll write the registers ourselves */
2287 rctl = E1000_READ_REG(hw, E1000_RCTL);
2289 /* set or clear MFLCN.PMCF bit depending on configuration */
2290 if (fc_conf->mac_ctrl_frame_fwd != 0)
2291 rctl |= E1000_RCTL_PMCF;
2293 rctl &= ~E1000_RCTL_PMCF;
2295 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2296 E1000_WRITE_FLUSH(hw);
2301 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
2305 #define E1000_RAH_POOLSEL_SHIFT (18)
2307 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
2308 uint32_t index, __rte_unused uint32_t pool)
2310 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2313 e1000_rar_set(hw, mac_addr->addr_bytes, index);
2314 rah = E1000_READ_REG(hw, E1000_RAH(index));
2315 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
2316 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
2320 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
2322 uint8_t addr[ETHER_ADDR_LEN];
2323 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2325 memset(addr, 0, sizeof(addr));
2327 e1000_rar_set(hw, addr, index);
2331 eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
2332 struct ether_addr *addr)
2334 eth_igb_rar_clear(dev, 0);
2336 eth_igb_rar_set(dev, (void *)addr, 0, 0);
2339 * Virtual Function operations
2342 igbvf_intr_disable(struct e1000_hw *hw)
2344 PMD_INIT_FUNC_TRACE();
2346 /* Clear interrupt mask to stop from interrupts being generated */
2347 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
2349 E1000_WRITE_FLUSH(hw);
2353 igbvf_stop_adapter(struct rte_eth_dev *dev)
2357 struct rte_eth_dev_info dev_info;
2358 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2360 memset(&dev_info, 0, sizeof(dev_info));
2361 eth_igbvf_infos_get(dev, &dev_info);
2363 /* Clear interrupt mask to stop from interrupts being generated */
2364 igbvf_intr_disable(hw);
2366 /* Clear any pending interrupts, flush previous writes */
2367 E1000_READ_REG(hw, E1000_EICR);
2369 /* Disable the transmit unit. Each queue must be disabled. */
2370 for (i = 0; i < dev_info.max_tx_queues; i++)
2371 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
2373 /* Disable the receive unit by stopping each queue */
2374 for (i = 0; i < dev_info.max_rx_queues; i++) {
2375 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
2376 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
2377 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
2378 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
2382 /* flush all queues disables */
2383 E1000_WRITE_FLUSH(hw);
2387 static int eth_igbvf_link_update(struct e1000_hw *hw)
2389 struct e1000_mbx_info *mbx = &hw->mbx;
2390 struct e1000_mac_info *mac = &hw->mac;
2391 int ret_val = E1000_SUCCESS;
2393 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
2396 * We only want to run this if there has been a rst asserted.
2397 * in this case that could mean a link change, device reset,
2398 * or a virtual function reset
2401 /* If we were hit with a reset or timeout drop the link */
2402 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
2403 mac->get_link_status = TRUE;
2405 if (!mac->get_link_status)
2408 /* if link status is down no point in checking to see if pf is up */
2409 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
2412 /* if we passed all the tests above then the link is up and we no
2413 * longer need to check for link */
2414 mac->get_link_status = FALSE;
2422 igbvf_dev_configure(struct rte_eth_dev *dev)
2424 struct rte_eth_conf* conf = &dev->data->dev_conf;
2426 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
2427 dev->data->port_id);
2430 * VF has no ability to enable/disable HW CRC
2431 * Keep the persistent behavior the same as Host PF
2433 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
2434 if (!conf->rxmode.hw_strip_crc) {
2435 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
2436 conf->rxmode.hw_strip_crc = 1;
2439 if (conf->rxmode.hw_strip_crc) {
2440 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
2441 conf->rxmode.hw_strip_crc = 0;
2449 igbvf_dev_start(struct rte_eth_dev *dev)
2451 struct e1000_hw *hw =
2452 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2453 struct e1000_adapter *adapter =
2454 E1000_DEV_PRIVATE(dev->data->dev_private);
2457 PMD_INIT_FUNC_TRACE();
2459 hw->mac.ops.reset_hw(hw);
2460 adapter->stopped = 0;
2463 igbvf_set_vfta_all(dev,1);
2465 eth_igbvf_tx_init(dev);
2467 /* This can fail when allocating mbufs for descriptor rings */
2468 ret = eth_igbvf_rx_init(dev);
2470 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
2471 igb_dev_clear_queues(dev);
2479 igbvf_dev_stop(struct rte_eth_dev *dev)
2481 PMD_INIT_FUNC_TRACE();
2483 igbvf_stop_adapter(dev);
2486 * Clear what we set, but we still keep shadow_vfta to
2487 * restore after device starts
2489 igbvf_set_vfta_all(dev,0);
2491 igb_dev_clear_queues(dev);
2495 igbvf_dev_close(struct rte_eth_dev *dev)
2497 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2498 struct e1000_adapter *adapter =
2499 E1000_DEV_PRIVATE(dev->data->dev_private);
2501 PMD_INIT_FUNC_TRACE();
2505 igbvf_dev_stop(dev);
2506 adapter->stopped = 1;
2507 igb_dev_free_queues(dev);
2510 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
2512 struct e1000_mbx_info *mbx = &hw->mbx;
2515 /* After set vlan, vlan strip will also be enabled in igb driver*/
2516 msgbuf[0] = E1000_VF_SET_VLAN;
2518 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
2520 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
2522 return (mbx->ops.write_posted(hw, msgbuf, 2, 0));
2525 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
2527 struct e1000_hw *hw =
2528 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2529 struct e1000_vfta * shadow_vfta =
2530 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2531 int i = 0, j = 0, vfta = 0, mask = 1;
2533 for (i = 0; i < IGB_VFTA_SIZE; i++){
2534 vfta = shadow_vfta->vfta[i];
2537 for (j = 0; j < 32; j++){
2540 (uint16_t)((i<<5)+j), on);
2549 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2551 struct e1000_hw *hw =
2552 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2553 struct e1000_vfta * shadow_vfta =
2554 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2555 uint32_t vid_idx = 0;
2556 uint32_t vid_bit = 0;
2559 PMD_INIT_FUNC_TRACE();
2561 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
2562 ret = igbvf_set_vfta(hw, vlan_id, !!on);
2564 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
2567 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
2568 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
2570 /*Save what we set and retore it after device reset*/
2572 shadow_vfta->vfta[vid_idx] |= vid_bit;
2574 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
2580 igbvf_default_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *addr)
2582 struct e1000_hw *hw =
2583 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2585 /* index is not used by rar_set() */
2586 hw->mac.ops.rar_set(hw, (void *)addr, 0);
2591 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
2592 struct rte_eth_rss_reta_entry64 *reta_conf,
2597 uint16_t idx, shift;
2598 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2600 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2601 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2602 "(%d) doesn't match the number hardware can supported "
2603 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2607 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
2608 idx = i / RTE_RETA_GROUP_SIZE;
2609 shift = i % RTE_RETA_GROUP_SIZE;
2610 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2614 if (mask == IGB_4_BIT_MASK)
2617 r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
2618 for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
2619 if (mask & (0x1 << j))
2620 reta |= reta_conf[idx].reta[shift + j] <<
2623 reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
2625 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
2632 eth_igb_rss_reta_query(struct rte_eth_dev *dev,
2633 struct rte_eth_rss_reta_entry64 *reta_conf,
2638 uint16_t idx, shift;
2639 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2641 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2642 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2643 "(%d) doesn't match the number hardware can supported "
2644 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2648 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
2649 idx = i / RTE_RETA_GROUP_SIZE;
2650 shift = i % RTE_RETA_GROUP_SIZE;
2651 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2655 reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
2656 for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
2657 if (mask & (0x1 << j))
2658 reta_conf[idx].reta[shift + j] =
2659 ((reta >> (CHAR_BIT * j)) &
2667 #define MAC_TYPE_FILTER_SUP(type) do {\
2668 if ((type) != e1000_82580 && (type) != e1000_i350 &&\
2669 (type) != e1000_82576)\
2674 eth_igb_syn_filter_set(struct rte_eth_dev *dev,
2675 struct rte_eth_syn_filter *filter,
2678 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2679 uint32_t synqf, rfctl;
2681 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
2684 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
2687 if (synqf & E1000_SYN_FILTER_ENABLE)
2690 synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
2691 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
2693 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
2694 if (filter->hig_pri)
2695 rfctl |= E1000_RFCTL_SYNQFP;
2697 rfctl &= ~E1000_RFCTL_SYNQFP;
2699 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
2701 if (!(synqf & E1000_SYN_FILTER_ENABLE))
2706 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
2707 E1000_WRITE_FLUSH(hw);
2712 eth_igb_syn_filter_get(struct rte_eth_dev *dev,
2713 struct rte_eth_syn_filter *filter)
2715 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2716 uint32_t synqf, rfctl;
2718 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
2719 if (synqf & E1000_SYN_FILTER_ENABLE) {
2720 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
2721 filter->hig_pri = (rfctl & E1000_RFCTL_SYNQFP) ? 1 : 0;
2722 filter->queue = (uint8_t)((synqf & E1000_SYN_FILTER_QUEUE) >>
2723 E1000_SYN_FILTER_QUEUE_SHIFT);
2731 eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
2732 enum rte_filter_op filter_op,
2735 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2738 MAC_TYPE_FILTER_SUP(hw->mac.type);
2740 if (filter_op == RTE_ETH_FILTER_NOP)
2744 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
2749 switch (filter_op) {
2750 case RTE_ETH_FILTER_ADD:
2751 ret = eth_igb_syn_filter_set(dev,
2752 (struct rte_eth_syn_filter *)arg,
2755 case RTE_ETH_FILTER_DELETE:
2756 ret = eth_igb_syn_filter_set(dev,
2757 (struct rte_eth_syn_filter *)arg,
2760 case RTE_ETH_FILTER_GET:
2761 ret = eth_igb_syn_filter_get(dev,
2762 (struct rte_eth_syn_filter *)arg);
2765 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
2773 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
2774 if ((type) != e1000_82580 && (type) != e1000_i350)\
2778 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
2780 ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
2781 struct e1000_2tuple_filter_info *filter_info)
2783 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
2785 if (filter->priority > E1000_2TUPLE_MAX_PRI)
2786 return -EINVAL; /* filter index is out of range. */
2787 if (filter->tcp_flags > TCP_FLAG_ALL)
2788 return -EINVAL; /* flags is invalid. */
2790 switch (filter->dst_port_mask) {
2792 filter_info->dst_port_mask = 0;
2793 filter_info->dst_port = filter->dst_port;
2796 filter_info->dst_port_mask = 1;
2799 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
2803 switch (filter->proto_mask) {
2805 filter_info->proto_mask = 0;
2806 filter_info->proto = filter->proto;
2809 filter_info->proto_mask = 1;
2812 PMD_DRV_LOG(ERR, "invalid protocol mask.");
2816 filter_info->priority = (uint8_t)filter->priority;
2817 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
2818 filter_info->tcp_flags = filter->tcp_flags;
2820 filter_info->tcp_flags = 0;
2825 static inline struct e1000_2tuple_filter *
2826 igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
2827 struct e1000_2tuple_filter_info *key)
2829 struct e1000_2tuple_filter *it;
2831 TAILQ_FOREACH(it, filter_list, entries) {
2832 if (memcmp(key, &it->filter_info,
2833 sizeof(struct e1000_2tuple_filter_info)) == 0) {
2841 * igb_add_2tuple_filter - add a 2tuple filter
2844 * dev: Pointer to struct rte_eth_dev.
2845 * ntuple_filter: ponter to the filter that will be added.
2848 * - On success, zero.
2849 * - On failure, a negative value.
2852 igb_add_2tuple_filter(struct rte_eth_dev *dev,
2853 struct rte_eth_ntuple_filter *ntuple_filter)
2855 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2856 struct e1000_filter_info *filter_info =
2857 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
2858 struct e1000_2tuple_filter *filter;
2859 uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
2860 uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
2863 filter = rte_zmalloc("e1000_2tuple_filter",
2864 sizeof(struct e1000_2tuple_filter), 0);
2868 ret = ntuple_filter_to_2tuple(ntuple_filter,
2869 &filter->filter_info);
2874 if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
2875 &filter->filter_info) != NULL) {
2876 PMD_DRV_LOG(ERR, "filter exists.");
2880 filter->queue = ntuple_filter->queue;
2883 * look for an unused 2tuple filter index,
2884 * and insert the filter to list.
2886 for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
2887 if (!(filter_info->twotuple_mask & (1 << i))) {
2888 filter_info->twotuple_mask |= 1 << i;
2890 TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
2896 if (i >= E1000_MAX_TTQF_FILTERS) {
2897 PMD_DRV_LOG(ERR, "2tuple filters are full.");
2902 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
2903 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
2904 imir |= E1000_IMIR_PORT_BP;
2906 imir &= ~E1000_IMIR_PORT_BP;
2908 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
2910 ttqf |= E1000_TTQF_QUEUE_ENABLE;
2911 ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
2912 ttqf |= (uint32_t)(filter->filter_info.proto & E1000_TTQF_PROTOCOL_MASK);
2913 if (filter->filter_info.proto_mask == 0)
2914 ttqf &= ~E1000_TTQF_MASK_ENABLE;
2916 /* tcp flags bits setting. */
2917 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
2918 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
2919 imir_ext |= E1000_IMIREXT_CTRL_URG;
2920 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
2921 imir_ext |= E1000_IMIREXT_CTRL_ACK;
2922 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
2923 imir_ext |= E1000_IMIREXT_CTRL_PSH;
2924 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
2925 imir_ext |= E1000_IMIREXT_CTRL_RST;
2926 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
2927 imir_ext |= E1000_IMIREXT_CTRL_SYN;
2928 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
2929 imir_ext |= E1000_IMIREXT_CTRL_FIN;
2931 imir_ext |= E1000_IMIREXT_CTRL_BP;
2932 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
2933 E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
2934 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
2939 * igb_remove_2tuple_filter - remove a 2tuple filter
2942 * dev: Pointer to struct rte_eth_dev.
2943 * ntuple_filter: ponter to the filter that will be removed.
2946 * - On success, zero.
2947 * - On failure, a negative value.
2950 igb_remove_2tuple_filter(struct rte_eth_dev *dev,
2951 struct rte_eth_ntuple_filter *ntuple_filter)
2953 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2954 struct e1000_filter_info *filter_info =
2955 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
2956 struct e1000_2tuple_filter_info filter_2tuple;
2957 struct e1000_2tuple_filter *filter;
2960 memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
2961 ret = ntuple_filter_to_2tuple(ntuple_filter,
2966 filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
2968 if (filter == NULL) {
2969 PMD_DRV_LOG(ERR, "filter doesn't exist.");
2973 filter_info->twotuple_mask &= ~(1 << filter->index);
2974 TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
2977 E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
2978 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
2979 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
2983 static inline struct e1000_flex_filter *
2984 eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
2985 struct e1000_flex_filter_info *key)
2987 struct e1000_flex_filter *it;
2989 TAILQ_FOREACH(it, filter_list, entries) {
2990 if (memcmp(key, &it->filter_info,
2991 sizeof(struct e1000_flex_filter_info)) == 0)
2999 eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
3000 struct rte_eth_flex_filter *filter,
3003 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3004 struct e1000_filter_info *filter_info =
3005 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3006 struct e1000_flex_filter *flex_filter, *it;
3007 uint32_t wufc, queueing, mask;
3009 uint8_t shift, i, j = 0;
3011 flex_filter = rte_zmalloc("e1000_flex_filter",
3012 sizeof(struct e1000_flex_filter), 0);
3013 if (flex_filter == NULL)
3016 flex_filter->filter_info.len = filter->len;
3017 flex_filter->filter_info.priority = filter->priority;
3018 memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
3019 for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
3021 /* reverse bits in flex filter's mask*/
3022 for (shift = 0; shift < CHAR_BIT; shift++) {
3023 if (filter->mask[i] & (0x01 << shift))
3024 mask |= (0x80 >> shift);
3026 flex_filter->filter_info.mask[i] = mask;
3029 wufc = E1000_READ_REG(hw, E1000_WUFC);
3030 if (flex_filter->index < E1000_MAX_FHFT)
3031 reg_off = E1000_FHFT(flex_filter->index);
3033 reg_off = E1000_FHFT_EXT(flex_filter->index - E1000_MAX_FHFT);
3036 if (eth_igb_flex_filter_lookup(&filter_info->flex_list,
3037 &flex_filter->filter_info) != NULL) {
3038 PMD_DRV_LOG(ERR, "filter exists.");
3039 rte_free(flex_filter);
3042 flex_filter->queue = filter->queue;
3044 * look for an unused flex filter index
3045 * and insert the filter into the list.
3047 for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
3048 if (!(filter_info->flex_mask & (1 << i))) {
3049 filter_info->flex_mask |= 1 << i;
3050 flex_filter->index = i;
3051 TAILQ_INSERT_TAIL(&filter_info->flex_list,
3057 if (i >= E1000_MAX_FLEX_FILTERS) {
3058 PMD_DRV_LOG(ERR, "flex filters are full.");
3059 rte_free(flex_filter);
3063 E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
3064 (E1000_WUFC_FLX0 << flex_filter->index));
3065 queueing = filter->len |
3066 (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
3067 (filter->priority << E1000_FHFT_QUEUEING_PRIO_SHIFT);
3068 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
3070 for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
3071 E1000_WRITE_REG(hw, reg_off,
3072 flex_filter->filter_info.dwords[j]);
3073 reg_off += sizeof(uint32_t);
3074 E1000_WRITE_REG(hw, reg_off,
3075 flex_filter->filter_info.dwords[++j]);
3076 reg_off += sizeof(uint32_t);
3077 E1000_WRITE_REG(hw, reg_off,
3078 (uint32_t)flex_filter->filter_info.mask[i]);
3079 reg_off += sizeof(uint32_t) * 2;
3083 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
3084 &flex_filter->filter_info);
3086 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3087 rte_free(flex_filter);
3091 for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
3092 E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
3093 E1000_WRITE_REG(hw, E1000_WUFC, wufc &
3094 (~(E1000_WUFC_FLX0 << it->index)));
3096 filter_info->flex_mask &= ~(1 << it->index);
3097 TAILQ_REMOVE(&filter_info->flex_list, it, entries);
3099 rte_free(flex_filter);
3106 eth_igb_get_flex_filter(struct rte_eth_dev *dev,
3107 struct rte_eth_flex_filter *filter)
3109 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3110 struct e1000_filter_info *filter_info =
3111 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3112 struct e1000_flex_filter flex_filter, *it;
3113 uint32_t wufc, queueing, wufc_en = 0;
3115 memset(&flex_filter, 0, sizeof(struct e1000_flex_filter));
3116 flex_filter.filter_info.len = filter->len;
3117 flex_filter.filter_info.priority = filter->priority;
3118 memcpy(flex_filter.filter_info.dwords, filter->bytes, filter->len);
3119 memcpy(flex_filter.filter_info.mask, filter->mask,
3120 RTE_ALIGN(filter->len, sizeof(char)) / sizeof(char));
3122 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
3123 &flex_filter.filter_info);
3125 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3129 wufc = E1000_READ_REG(hw, E1000_WUFC);
3130 wufc_en = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << it->index);
3132 if ((wufc & wufc_en) == wufc_en) {
3133 uint32_t reg_off = 0;
3134 if (it->index < E1000_MAX_FHFT)
3135 reg_off = E1000_FHFT(it->index);
3137 reg_off = E1000_FHFT_EXT(it->index - E1000_MAX_FHFT);
3139 queueing = E1000_READ_REG(hw,
3140 reg_off + E1000_FHFT_QUEUEING_OFFSET);
3141 filter->len = queueing & E1000_FHFT_QUEUEING_LEN;
3142 filter->priority = (queueing & E1000_FHFT_QUEUEING_PRIO) >>
3143 E1000_FHFT_QUEUEING_PRIO_SHIFT;
3144 filter->queue = (queueing & E1000_FHFT_QUEUEING_QUEUE) >>
3145 E1000_FHFT_QUEUEING_QUEUE_SHIFT;
3152 eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
3153 enum rte_filter_op filter_op,
3156 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3157 struct rte_eth_flex_filter *filter;
3160 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
3162 if (filter_op == RTE_ETH_FILTER_NOP)
3166 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3171 filter = (struct rte_eth_flex_filter *)arg;
3172 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN
3173 || filter->len % sizeof(uint64_t) != 0) {
3174 PMD_DRV_LOG(ERR, "filter's length is out of range");
3177 if (filter->priority > E1000_MAX_FLEX_FILTER_PRI) {
3178 PMD_DRV_LOG(ERR, "filter's priority is out of range");
3182 switch (filter_op) {
3183 case RTE_ETH_FILTER_ADD:
3184 ret = eth_igb_add_del_flex_filter(dev, filter, TRUE);
3186 case RTE_ETH_FILTER_DELETE:
3187 ret = eth_igb_add_del_flex_filter(dev, filter, FALSE);
3189 case RTE_ETH_FILTER_GET:
3190 ret = eth_igb_get_flex_filter(dev, filter);
3193 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
3201 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
3203 ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
3204 struct e1000_5tuple_filter_info *filter_info)
3206 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
3208 if (filter->priority > E1000_2TUPLE_MAX_PRI)
3209 return -EINVAL; /* filter index is out of range. */
3210 if (filter->tcp_flags > TCP_FLAG_ALL)
3211 return -EINVAL; /* flags is invalid. */
3213 switch (filter->dst_ip_mask) {
3215 filter_info->dst_ip_mask = 0;
3216 filter_info->dst_ip = filter->dst_ip;
3219 filter_info->dst_ip_mask = 1;
3222 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
3226 switch (filter->src_ip_mask) {
3228 filter_info->src_ip_mask = 0;
3229 filter_info->src_ip = filter->src_ip;
3232 filter_info->src_ip_mask = 1;
3235 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
3239 switch (filter->dst_port_mask) {
3241 filter_info->dst_port_mask = 0;
3242 filter_info->dst_port = filter->dst_port;
3245 filter_info->dst_port_mask = 1;
3248 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3252 switch (filter->src_port_mask) {
3254 filter_info->src_port_mask = 0;
3255 filter_info->src_port = filter->src_port;
3258 filter_info->src_port_mask = 1;
3261 PMD_DRV_LOG(ERR, "invalid src_port mask.");
3265 switch (filter->proto_mask) {
3267 filter_info->proto_mask = 0;
3268 filter_info->proto = filter->proto;
3271 filter_info->proto_mask = 1;
3274 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3278 filter_info->priority = (uint8_t)filter->priority;
3279 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3280 filter_info->tcp_flags = filter->tcp_flags;
3282 filter_info->tcp_flags = 0;
3287 static inline struct e1000_5tuple_filter *
3288 igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
3289 struct e1000_5tuple_filter_info *key)
3291 struct e1000_5tuple_filter *it;
3293 TAILQ_FOREACH(it, filter_list, entries) {
3294 if (memcmp(key, &it->filter_info,
3295 sizeof(struct e1000_5tuple_filter_info)) == 0) {
3303 * igb_add_5tuple_filter_82576 - add a 5tuple filter
3306 * dev: Pointer to struct rte_eth_dev.
3307 * ntuple_filter: ponter to the filter that will be added.
3310 * - On success, zero.
3311 * - On failure, a negative value.
3314 igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
3315 struct rte_eth_ntuple_filter *ntuple_filter)
3317 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3318 struct e1000_filter_info *filter_info =
3319 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3320 struct e1000_5tuple_filter *filter;
3321 uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
3322 uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3326 filter = rte_zmalloc("e1000_5tuple_filter",
3327 sizeof(struct e1000_5tuple_filter), 0);
3331 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3332 &filter->filter_info);
3338 if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
3339 &filter->filter_info) != NULL) {
3340 PMD_DRV_LOG(ERR, "filter exists.");
3344 filter->queue = ntuple_filter->queue;
3347 * look for an unused 5tuple filter index,
3348 * and insert the filter to list.
3350 for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
3351 if (!(filter_info->fivetuple_mask & (1 << i))) {
3352 filter_info->fivetuple_mask |= 1 << i;
3354 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
3360 if (i >= E1000_MAX_FTQF_FILTERS) {
3361 PMD_DRV_LOG(ERR, "5tuple filters are full.");
3366 ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
3367 if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
3368 ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
3369 if (filter->filter_info.dst_ip_mask == 0)
3370 ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
3371 if (filter->filter_info.src_port_mask == 0)
3372 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
3373 if (filter->filter_info.proto_mask == 0)
3374 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
3375 ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
3376 E1000_FTQF_QUEUE_MASK;
3377 ftqf |= E1000_FTQF_QUEUE_ENABLE;
3378 E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
3379 E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
3380 E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
3382 spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
3383 E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
3385 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3386 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3387 imir |= E1000_IMIR_PORT_BP;
3389 imir &= ~E1000_IMIR_PORT_BP;
3390 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3392 /* tcp flags bits setting. */
3393 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3394 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3395 imir_ext |= E1000_IMIREXT_CTRL_URG;
3396 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3397 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3398 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3399 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3400 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3401 imir_ext |= E1000_IMIREXT_CTRL_RST;
3402 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3403 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3404 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3405 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3407 imir_ext |= E1000_IMIREXT_CTRL_BP;
3408 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3409 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3414 * igb_remove_5tuple_filter_82576 - remove a 5tuple filter
3417 * dev: Pointer to struct rte_eth_dev.
3418 * ntuple_filter: ponter to the filter that will be removed.
3421 * - On success, zero.
3422 * - On failure, a negative value.
3425 igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
3426 struct rte_eth_ntuple_filter *ntuple_filter)
3428 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3429 struct e1000_filter_info *filter_info =
3430 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3431 struct e1000_5tuple_filter_info filter_5tuple;
3432 struct e1000_5tuple_filter *filter;
3435 memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
3436 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3441 filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
3443 if (filter == NULL) {
3444 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3448 filter_info->fivetuple_mask &= ~(1 << filter->index);
3449 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
3452 E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
3453 E1000_FTQF_VF_BP | E1000_FTQF_MASK);
3454 E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
3455 E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
3456 E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
3457 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3458 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3463 eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
3466 struct e1000_hw *hw;
3467 struct rte_eth_dev_info dev_info;
3468 uint32_t frame_size = mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN +
3471 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3473 #ifdef RTE_LIBRTE_82571_SUPPORT
3474 /* XXX: not bigger than max_rx_pktlen */
3475 if (hw->mac.type == e1000_82571)
3478 eth_igb_infos_get(dev, &dev_info);
3480 /* check that mtu is within the allowed range */
3481 if ((mtu < ETHER_MIN_MTU) ||
3482 (frame_size > dev_info.max_rx_pktlen))
3485 /* refuse mtu that requires the support of scattered packets when this
3486 * feature has not been enabled before. */
3487 if (!dev->data->scattered_rx &&
3488 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)
3491 rctl = E1000_READ_REG(hw, E1000_RCTL);
3493 /* switch to jumbo mode if needed */
3494 if (frame_size > ETHER_MAX_LEN) {
3495 dev->data->dev_conf.rxmode.jumbo_frame = 1;
3496 rctl |= E1000_RCTL_LPE;
3498 dev->data->dev_conf.rxmode.jumbo_frame = 0;
3499 rctl &= ~E1000_RCTL_LPE;
3501 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3503 /* update max frame size */
3504 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
3506 E1000_WRITE_REG(hw, E1000_RLPML,
3507 dev->data->dev_conf.rxmode.max_rx_pkt_len);
3513 * igb_add_del_ntuple_filter - add or delete a ntuple filter
3516 * dev: Pointer to struct rte_eth_dev.
3517 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
3518 * add: if true, add filter, if false, remove filter
3521 * - On success, zero.
3522 * - On failure, a negative value.
3525 igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
3526 struct rte_eth_ntuple_filter *ntuple_filter,
3529 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3532 switch (ntuple_filter->flags) {
3533 case RTE_5TUPLE_FLAGS:
3534 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3535 if (hw->mac.type != e1000_82576)
3538 ret = igb_add_5tuple_filter_82576(dev,
3541 ret = igb_remove_5tuple_filter_82576(dev,
3544 case RTE_2TUPLE_FLAGS:
3545 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3546 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
3549 ret = igb_add_2tuple_filter(dev, ntuple_filter);
3551 ret = igb_remove_2tuple_filter(dev, ntuple_filter);
3562 * igb_get_ntuple_filter - get a ntuple filter
3565 * dev: Pointer to struct rte_eth_dev.
3566 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
3569 * - On success, zero.
3570 * - On failure, a negative value.
3573 igb_get_ntuple_filter(struct rte_eth_dev *dev,
3574 struct rte_eth_ntuple_filter *ntuple_filter)
3576 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3577 struct e1000_filter_info *filter_info =
3578 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3579 struct e1000_5tuple_filter_info filter_5tuple;
3580 struct e1000_2tuple_filter_info filter_2tuple;
3581 struct e1000_5tuple_filter *p_5tuple_filter;
3582 struct e1000_2tuple_filter *p_2tuple_filter;
3585 switch (ntuple_filter->flags) {
3586 case RTE_5TUPLE_FLAGS:
3587 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3588 if (hw->mac.type != e1000_82576)
3590 memset(&filter_5tuple,
3592 sizeof(struct e1000_5tuple_filter_info));
3593 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3597 p_5tuple_filter = igb_5tuple_filter_lookup_82576(
3598 &filter_info->fivetuple_list,
3600 if (p_5tuple_filter == NULL) {
3601 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3604 ntuple_filter->queue = p_5tuple_filter->queue;
3606 case RTE_2TUPLE_FLAGS:
3607 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3608 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
3610 memset(&filter_2tuple,
3612 sizeof(struct e1000_2tuple_filter_info));
3613 ret = ntuple_filter_to_2tuple(ntuple_filter, &filter_2tuple);
3616 p_2tuple_filter = igb_2tuple_filter_lookup(
3617 &filter_info->twotuple_list,
3619 if (p_2tuple_filter == NULL) {
3620 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3623 ntuple_filter->queue = p_2tuple_filter->queue;
3634 * igb_ntuple_filter_handle - Handle operations for ntuple filter.
3635 * @dev: pointer to rte_eth_dev structure
3636 * @filter_op:operation will be taken.
3637 * @arg: a pointer to specific structure corresponding to the filter_op
3640 igb_ntuple_filter_handle(struct rte_eth_dev *dev,
3641 enum rte_filter_op filter_op,
3644 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3647 MAC_TYPE_FILTER_SUP(hw->mac.type);
3649 if (filter_op == RTE_ETH_FILTER_NOP)
3653 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3658 switch (filter_op) {
3659 case RTE_ETH_FILTER_ADD:
3660 ret = igb_add_del_ntuple_filter(dev,
3661 (struct rte_eth_ntuple_filter *)arg,
3664 case RTE_ETH_FILTER_DELETE:
3665 ret = igb_add_del_ntuple_filter(dev,
3666 (struct rte_eth_ntuple_filter *)arg,
3669 case RTE_ETH_FILTER_GET:
3670 ret = igb_get_ntuple_filter(dev,
3671 (struct rte_eth_ntuple_filter *)arg);
3674 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3682 igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
3687 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
3688 if (filter_info->ethertype_filters[i] == ethertype &&
3689 (filter_info->ethertype_mask & (1 << i)))
3696 igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
3701 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
3702 if (!(filter_info->ethertype_mask & (1 << i))) {
3703 filter_info->ethertype_mask |= 1 << i;
3704 filter_info->ethertype_filters[i] = ethertype;
3712 igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
3715 if (idx >= E1000_MAX_ETQF_FILTERS)
3717 filter_info->ethertype_mask &= ~(1 << idx);
3718 filter_info->ethertype_filters[idx] = 0;
3724 igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
3725 struct rte_eth_ethertype_filter *filter,
3728 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3729 struct e1000_filter_info *filter_info =
3730 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3734 if (filter->ether_type == ETHER_TYPE_IPv4 ||
3735 filter->ether_type == ETHER_TYPE_IPv6) {
3736 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
3737 " ethertype filter.", filter->ether_type);
3741 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
3742 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
3745 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
3746 PMD_DRV_LOG(ERR, "drop option is unsupported.");
3750 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
3751 if (ret >= 0 && add) {
3752 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
3753 filter->ether_type);
3756 if (ret < 0 && !add) {
3757 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
3758 filter->ether_type);
3763 ret = igb_ethertype_filter_insert(filter_info,
3764 filter->ether_type);
3766 PMD_DRV_LOG(ERR, "ethertype filters are full.");
3770 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
3771 etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
3772 etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
3774 ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
3778 E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
3779 E1000_WRITE_FLUSH(hw);
3785 igb_get_ethertype_filter(struct rte_eth_dev *dev,
3786 struct rte_eth_ethertype_filter *filter)
3788 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3789 struct e1000_filter_info *filter_info =
3790 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3794 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
3796 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
3797 filter->ether_type);
3801 etqf = E1000_READ_REG(hw, E1000_ETQF(ret));
3802 if (etqf & E1000_ETQF_FILTER_ENABLE) {
3803 filter->ether_type = etqf & E1000_ETQF_ETHERTYPE;
3805 filter->queue = (etqf & E1000_ETQF_QUEUE) >>
3806 E1000_ETQF_QUEUE_SHIFT;
3814 * igb_ethertype_filter_handle - Handle operations for ethertype filter.
3815 * @dev: pointer to rte_eth_dev structure
3816 * @filter_op:operation will be taken.
3817 * @arg: a pointer to specific structure corresponding to the filter_op
3820 igb_ethertype_filter_handle(struct rte_eth_dev *dev,
3821 enum rte_filter_op filter_op,
3824 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3827 MAC_TYPE_FILTER_SUP(hw->mac.type);
3829 if (filter_op == RTE_ETH_FILTER_NOP)
3833 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3838 switch (filter_op) {
3839 case RTE_ETH_FILTER_ADD:
3840 ret = igb_add_del_ethertype_filter(dev,
3841 (struct rte_eth_ethertype_filter *)arg,
3844 case RTE_ETH_FILTER_DELETE:
3845 ret = igb_add_del_ethertype_filter(dev,
3846 (struct rte_eth_ethertype_filter *)arg,
3849 case RTE_ETH_FILTER_GET:
3850 ret = igb_get_ethertype_filter(dev,
3851 (struct rte_eth_ethertype_filter *)arg);
3854 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3862 eth_igb_filter_ctrl(struct rte_eth_dev *dev,
3863 enum rte_filter_type filter_type,
3864 enum rte_filter_op filter_op,
3869 switch (filter_type) {
3870 case RTE_ETH_FILTER_NTUPLE:
3871 ret = igb_ntuple_filter_handle(dev, filter_op, arg);
3873 case RTE_ETH_FILTER_ETHERTYPE:
3874 ret = igb_ethertype_filter_handle(dev, filter_op, arg);
3876 case RTE_ETH_FILTER_SYN:
3877 ret = eth_igb_syn_filter_handle(dev, filter_op, arg);
3879 case RTE_ETH_FILTER_FLEXIBLE:
3880 ret = eth_igb_flex_filter_handle(dev, filter_op, arg);
3883 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
3892 eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
3893 struct ether_addr *mc_addr_set,
3894 uint32_t nb_mc_addr)
3896 struct e1000_hw *hw;
3898 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3899 e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
3904 igb_timesync_enable(struct rte_eth_dev *dev)
3906 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3910 /* Enable system time for it isn't on by default. */
3911 tsauxc = E1000_READ_REG(hw, E1000_TSAUXC);
3912 tsauxc &= ~E1000_TSAUXC_DISABLE_SYSTIME;
3913 E1000_WRITE_REG(hw, E1000_TSAUXC, tsauxc);
3915 /* Start incrementing the register used to timestamp PTP packets. */
3916 E1000_WRITE_REG(hw, E1000_TIMINCA, E1000_TIMINCA_INIT);
3918 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
3919 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588),
3921 E1000_ETQF_FILTER_ENABLE |
3924 /* Enable timestamping of received PTP packets. */
3925 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
3926 tsync_ctl |= E1000_TSYNCRXCTL_ENABLED;
3927 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
3929 /* Enable Timestamping of transmitted PTP packets. */
3930 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
3931 tsync_ctl |= E1000_TSYNCTXCTL_ENABLED;
3932 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
3938 igb_timesync_disable(struct rte_eth_dev *dev)
3940 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3943 /* Disable timestamping of transmitted PTP packets. */
3944 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
3945 tsync_ctl &= ~E1000_TSYNCTXCTL_ENABLED;
3946 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
3948 /* Disable timestamping of received PTP packets. */
3949 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
3950 tsync_ctl &= ~E1000_TSYNCRXCTL_ENABLED;
3951 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
3953 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
3954 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588), 0);
3956 /* Stop incrementating the System Time registers. */
3957 E1000_WRITE_REG(hw, E1000_TIMINCA, 0);
3963 igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
3964 struct timespec *timestamp,
3965 uint32_t flags __rte_unused)
3967 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3968 uint32_t tsync_rxctl;
3972 tsync_rxctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
3973 if ((tsync_rxctl & E1000_TSYNCRXCTL_VALID) == 0)
3976 rx_stmpl = E1000_READ_REG(hw, E1000_RXSTMPL);
3977 rx_stmph = E1000_READ_REG(hw, E1000_RXSTMPH);
3979 timestamp->tv_sec = (uint64_t)(((uint64_t)rx_stmph << 32) | rx_stmpl);
3980 timestamp->tv_nsec = 0;
3986 igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
3987 struct timespec *timestamp)
3989 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3990 uint32_t tsync_txctl;
3994 tsync_txctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
3995 if ((tsync_txctl & E1000_TSYNCTXCTL_VALID) == 0)
3998 tx_stmpl = E1000_READ_REG(hw, E1000_TXSTMPL);
3999 tx_stmph = E1000_READ_REG(hw, E1000_TXSTMPH);
4001 timestamp->tv_sec = (uint64_t)(((uint64_t)tx_stmph << 32) | tx_stmpl);
4002 timestamp->tv_nsec = 0;
4008 eth_igb_get_reg_length(struct rte_eth_dev *dev __rte_unused)
4012 const struct reg_info *reg_group;
4014 while ((reg_group = igb_regs[g_ind++]))
4015 count += igb_reg_group_count(reg_group);
4021 igbvf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
4025 const struct reg_info *reg_group;
4027 while ((reg_group = igbvf_regs[g_ind++]))
4028 count += igb_reg_group_count(reg_group);
4034 eth_igb_get_regs(struct rte_eth_dev *dev,
4035 struct rte_dev_reg_info *regs)
4037 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4038 uint32_t *data = regs->data;
4041 const struct reg_info *reg_group;
4043 /* Support only full register dump */
4044 if ((regs->length == 0) ||
4045 (regs->length == (uint32_t)eth_igb_get_reg_length(dev))) {
4046 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
4048 while ((reg_group = igb_regs[g_ind++]))
4049 count += igb_read_regs_group(dev, &data[count],
4058 igbvf_get_regs(struct rte_eth_dev *dev,
4059 struct rte_dev_reg_info *regs)
4061 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4062 uint32_t *data = regs->data;
4065 const struct reg_info *reg_group;
4067 /* Support only full register dump */
4068 if ((regs->length == 0) ||
4069 (regs->length == (uint32_t)igbvf_get_reg_length(dev))) {
4070 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
4072 while ((reg_group = igbvf_regs[g_ind++]))
4073 count += igb_read_regs_group(dev, &data[count],
4082 eth_igb_get_eeprom_length(struct rte_eth_dev *dev)
4084 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4086 /* Return unit is byte count */
4087 return hw->nvm.word_size * 2;
4091 eth_igb_get_eeprom(struct rte_eth_dev *dev,
4092 struct rte_dev_eeprom_info *in_eeprom)
4094 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4095 struct e1000_nvm_info *nvm = &hw->nvm;
4096 uint16_t *data = in_eeprom->data;
4099 first = in_eeprom->offset >> 1;
4100 length = in_eeprom->length >> 1;
4101 if ((first >= hw->nvm.word_size) ||
4102 ((first + length) >= hw->nvm.word_size))
4105 in_eeprom->magic = hw->vendor_id |
4106 ((uint32_t)hw->device_id << 16);
4108 if ((nvm->ops.read) == NULL)
4111 return nvm->ops.read(hw, first, length, data);
4115 eth_igb_set_eeprom(struct rte_eth_dev *dev,
4116 struct rte_dev_eeprom_info *in_eeprom)
4118 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4119 struct e1000_nvm_info *nvm = &hw->nvm;
4120 uint16_t *data = in_eeprom->data;
4123 first = in_eeprom->offset >> 1;
4124 length = in_eeprom->length >> 1;
4125 if ((first >= hw->nvm.word_size) ||
4126 ((first + length) >= hw->nvm.word_size))
4129 in_eeprom->magic = (uint32_t)hw->vendor_id |
4130 ((uint32_t)hw->device_id << 16);
4132 if ((nvm->ops.write) == NULL)
4134 return nvm->ops.write(hw, first, length, data);
4137 static struct rte_driver pmd_igb_drv = {
4139 .init = rte_igb_pmd_init,
4142 static struct rte_driver pmd_igbvf_drv = {
4144 .init = rte_igbvf_pmd_init,
4149 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
4151 struct e1000_hw *hw =
4152 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4153 uint32_t mask = 1 << queue_id;
4155 E1000_WRITE_REG(hw, E1000_EIMC, mask);
4156 E1000_WRITE_FLUSH(hw);
4162 eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
4164 struct e1000_hw *hw =
4165 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4166 uint32_t mask = 1 << queue_id;
4169 regval = E1000_READ_REG(hw, E1000_EIMS);
4170 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
4171 E1000_WRITE_FLUSH(hw);
4173 rte_intr_enable(&dev->pci_dev->intr_handle);
4179 eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
4180 uint8_t index, uint8_t offset)
4182 uint32_t val = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
4185 val &= ~((uint32_t)0xFF << offset);
4187 /* write vector and valid bit */
4188 val |= (msix_vector | E1000_IVAR_VALID) << offset;
4190 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, val);
4194 eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
4195 uint8_t queue, uint8_t msix_vector)
4199 if (hw->mac.type == e1000_82575) {
4201 tmp = E1000_EICR_RX_QUEUE0 << queue;
4202 else if (direction == 1)
4203 tmp = E1000_EICR_TX_QUEUE0 << queue;
4204 E1000_WRITE_REG(hw, E1000_MSIXBM(msix_vector), tmp);
4205 } else if (hw->mac.type == e1000_82576) {
4206 if ((direction == 0) || (direction == 1))
4207 eth_igb_write_ivar(hw, msix_vector, queue & 0x7,
4208 ((queue & 0x8) << 1) +
4210 } else if ((hw->mac.type == e1000_82580) ||
4211 (hw->mac.type == e1000_i350) ||
4212 (hw->mac.type == e1000_i354) ||
4213 (hw->mac.type == e1000_i210) ||
4214 (hw->mac.type == e1000_i211)) {
4215 if ((direction == 0) || (direction == 1))
4216 eth_igb_write_ivar(hw, msix_vector,
4218 ((queue & 0x1) << 4) +
4224 /* Sets up the hardware to generate MSI-X interrupts properly
4226 * board private structure
4229 eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
4233 uint32_t tmpval, regval, intr_mask;
4234 struct e1000_hw *hw =
4235 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4238 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4240 /* won't configure msix register if no mapping is done
4241 * between intr vector and event fd
4243 if (!rte_intr_dp_is_en(intr_handle))
4247 /* set interrupt vector for other causes */
4248 if (hw->mac.type == e1000_82575) {
4249 tmpval = E1000_READ_REG(hw, E1000_CTRL_EXT);
4250 /* enable MSI-X PBA support */
4251 tmpval |= E1000_CTRL_EXT_PBA_CLR;
4253 /* Auto-Mask interrupts upon ICR read */
4254 tmpval |= E1000_CTRL_EXT_EIAME;
4255 tmpval |= E1000_CTRL_EXT_IRCA;
4257 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmpval);
4259 /* enable msix_other interrupt */
4260 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), 0, E1000_EIMS_OTHER);
4261 regval = E1000_READ_REG(hw, E1000_EIAC);
4262 E1000_WRITE_REG(hw, E1000_EIAC, regval | E1000_EIMS_OTHER);
4263 regval = E1000_READ_REG(hw, E1000_EIAM);
4264 E1000_WRITE_REG(hw, E1000_EIMS, regval | E1000_EIMS_OTHER);
4265 } else if ((hw->mac.type == e1000_82576) ||
4266 (hw->mac.type == e1000_82580) ||
4267 (hw->mac.type == e1000_i350) ||
4268 (hw->mac.type == e1000_i354) ||
4269 (hw->mac.type == e1000_i210) ||
4270 (hw->mac.type == e1000_i211)) {
4271 /* turn on MSI-X capability first */
4272 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
4273 E1000_GPIE_PBA | E1000_GPIE_EIAME |
4276 intr_mask = (1 << intr_handle->max_intr) - 1;
4277 regval = E1000_READ_REG(hw, E1000_EIAC);
4278 E1000_WRITE_REG(hw, E1000_EIAC, regval | intr_mask);
4280 /* enable msix_other interrupt */
4281 regval = E1000_READ_REG(hw, E1000_EIMS);
4282 E1000_WRITE_REG(hw, E1000_EIMS, regval | intr_mask);
4283 tmpval = (dev->data->nb_rx_queues | E1000_IVAR_VALID) << 8;
4284 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmpval);
4287 /* use EIAM to auto-mask when MSI-X interrupt
4288 * is asserted, this saves a register write for every interrupt
4290 intr_mask = (1 << intr_handle->nb_efd) - 1;
4291 regval = E1000_READ_REG(hw, E1000_EIAM);
4292 E1000_WRITE_REG(hw, E1000_EIAM, regval | intr_mask);
4294 for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
4295 eth_igb_assign_msix_vector(hw, 0, queue_id, vec);
4296 intr_handle->intr_vec[queue_id] = vec;
4297 if (vec < intr_handle->nb_efd - 1)
4301 E1000_WRITE_FLUSH(hw);
4305 PMD_REGISTER_DRIVER(pmd_igb_drv);
4306 PMD_REGISTER_DRIVER(pmd_igbvf_drv);