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);
109 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
110 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
111 static int eth_igb_interrupt_action(struct rte_eth_dev *dev);
112 static void eth_igb_interrupt_handler(struct rte_intr_handle *handle,
114 static int igb_hardware_init(struct e1000_hw *hw);
115 static void igb_hw_control_acquire(struct e1000_hw *hw);
116 static void igb_hw_control_release(struct e1000_hw *hw);
117 static void igb_init_manageability(struct e1000_hw *hw);
118 static void igb_release_manageability(struct e1000_hw *hw);
120 static int eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
122 static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
123 uint16_t vlan_id, int on);
124 static void eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid_id);
125 static void eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
127 static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
128 static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
129 static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
130 static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
131 static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
132 static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
134 static int eth_igb_led_on(struct rte_eth_dev *dev);
135 static int eth_igb_led_off(struct rte_eth_dev *dev);
137 static void igb_intr_disable(struct e1000_hw *hw);
138 static int igb_get_rx_buffer_size(struct e1000_hw *hw);
139 static void eth_igb_rar_set(struct rte_eth_dev *dev,
140 struct ether_addr *mac_addr,
141 uint32_t index, uint32_t pool);
142 static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
143 static void eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
144 struct ether_addr *addr);
146 static void igbvf_intr_disable(struct e1000_hw *hw);
147 static int igbvf_dev_configure(struct rte_eth_dev *dev);
148 static int igbvf_dev_start(struct rte_eth_dev *dev);
149 static void igbvf_dev_stop(struct rte_eth_dev *dev);
150 static void igbvf_dev_close(struct rte_eth_dev *dev);
151 static int eth_igbvf_link_update(struct e1000_hw *hw);
152 static void eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats);
153 static void eth_igbvf_stats_reset(struct rte_eth_dev *dev);
154 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
155 uint16_t vlan_id, int on);
156 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
157 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
158 static void igbvf_default_mac_addr_set(struct rte_eth_dev *dev,
159 struct ether_addr *addr);
160 static int igbvf_get_reg_length(struct rte_eth_dev *dev);
161 static int igbvf_get_regs(struct rte_eth_dev *dev,
162 struct rte_dev_reg_info *regs);
164 static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
165 struct rte_eth_rss_reta_entry64 *reta_conf,
167 static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
168 struct rte_eth_rss_reta_entry64 *reta_conf,
171 static int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
172 struct rte_eth_syn_filter *filter,
174 static int eth_igb_syn_filter_get(struct rte_eth_dev *dev,
175 struct rte_eth_syn_filter *filter);
176 static int eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
177 enum rte_filter_op filter_op,
179 static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
180 struct rte_eth_ntuple_filter *ntuple_filter);
181 static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
182 struct rte_eth_ntuple_filter *ntuple_filter);
183 static int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
184 struct rte_eth_flex_filter *filter,
186 static int eth_igb_get_flex_filter(struct rte_eth_dev *dev,
187 struct rte_eth_flex_filter *filter);
188 static int eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
189 enum rte_filter_op filter_op,
191 static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
192 struct rte_eth_ntuple_filter *ntuple_filter);
193 static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
194 struct rte_eth_ntuple_filter *ntuple_filter);
195 static int igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
196 struct rte_eth_ntuple_filter *filter,
198 static int igb_get_ntuple_filter(struct rte_eth_dev *dev,
199 struct rte_eth_ntuple_filter *filter);
200 static int igb_ntuple_filter_handle(struct rte_eth_dev *dev,
201 enum rte_filter_op filter_op,
203 static int igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
204 struct rte_eth_ethertype_filter *filter,
206 static int igb_ethertype_filter_handle(struct rte_eth_dev *dev,
207 enum rte_filter_op filter_op,
209 static int igb_get_ethertype_filter(struct rte_eth_dev *dev,
210 struct rte_eth_ethertype_filter *filter);
211 static int eth_igb_filter_ctrl(struct rte_eth_dev *dev,
212 enum rte_filter_type filter_type,
213 enum rte_filter_op filter_op,
215 static int eth_igb_get_reg_length(struct rte_eth_dev *dev);
216 static int eth_igb_get_regs(struct rte_eth_dev *dev,
217 struct rte_dev_reg_info *regs);
218 static int eth_igb_get_eeprom_length(struct rte_eth_dev *dev);
219 static int eth_igb_get_eeprom(struct rte_eth_dev *dev,
220 struct rte_dev_eeprom_info *eeprom);
221 static int eth_igb_set_eeprom(struct rte_eth_dev *dev,
222 struct rte_dev_eeprom_info *eeprom);
223 static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
224 struct ether_addr *mc_addr_set,
225 uint32_t nb_mc_addr);
226 static int igb_timesync_enable(struct rte_eth_dev *dev);
227 static int igb_timesync_disable(struct rte_eth_dev *dev);
228 static int igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
229 struct timespec *timestamp,
231 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
232 struct timespec *timestamp);
233 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
235 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
237 static void eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
238 uint8_t queue, uint8_t msix_vector);
239 static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
240 uint8_t index, uint8_t offset);
241 static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
244 * Define VF Stats MACRO for Non "cleared on read" register
246 #define UPDATE_VF_STAT(reg, last, cur) \
248 u32 latest = E1000_READ_REG(hw, reg); \
249 cur += (latest - last) & UINT_MAX; \
253 #define IGB_FC_PAUSE_TIME 0x0680
254 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
255 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
257 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
259 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
262 * The set of PCI devices this driver supports
264 static const struct rte_pci_id pci_id_igb_map[] = {
266 #define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
267 #include "rte_pci_dev_ids.h"
273 * The set of PCI devices this driver supports (for 82576&I350 VF)
275 static const struct rte_pci_id pci_id_igbvf_map[] = {
277 #define RTE_PCI_DEV_ID_DECL_IGBVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
278 #include "rte_pci_dev_ids.h"
283 static const struct rte_eth_desc_lim rx_desc_lim = {
284 .nb_max = E1000_MAX_RING_DESC,
285 .nb_min = E1000_MIN_RING_DESC,
286 .nb_align = IGB_RXD_ALIGN,
289 static const struct rte_eth_desc_lim tx_desc_lim = {
290 .nb_max = E1000_MAX_RING_DESC,
291 .nb_min = E1000_MIN_RING_DESC,
292 .nb_align = IGB_RXD_ALIGN,
295 static const struct eth_dev_ops eth_igb_ops = {
296 .dev_configure = eth_igb_configure,
297 .dev_start = eth_igb_start,
298 .dev_stop = eth_igb_stop,
299 .dev_close = eth_igb_close,
300 .promiscuous_enable = eth_igb_promiscuous_enable,
301 .promiscuous_disable = eth_igb_promiscuous_disable,
302 .allmulticast_enable = eth_igb_allmulticast_enable,
303 .allmulticast_disable = eth_igb_allmulticast_disable,
304 .link_update = eth_igb_link_update,
305 .stats_get = eth_igb_stats_get,
306 .stats_reset = eth_igb_stats_reset,
307 .dev_infos_get = eth_igb_infos_get,
308 .mtu_set = eth_igb_mtu_set,
309 .vlan_filter_set = eth_igb_vlan_filter_set,
310 .vlan_tpid_set = eth_igb_vlan_tpid_set,
311 .vlan_offload_set = eth_igb_vlan_offload_set,
312 .rx_queue_setup = eth_igb_rx_queue_setup,
313 .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
314 .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
315 .rx_queue_release = eth_igb_rx_queue_release,
316 .rx_queue_count = eth_igb_rx_queue_count,
317 .rx_descriptor_done = eth_igb_rx_descriptor_done,
318 .tx_queue_setup = eth_igb_tx_queue_setup,
319 .tx_queue_release = eth_igb_tx_queue_release,
320 .dev_led_on = eth_igb_led_on,
321 .dev_led_off = eth_igb_led_off,
322 .flow_ctrl_get = eth_igb_flow_ctrl_get,
323 .flow_ctrl_set = eth_igb_flow_ctrl_set,
324 .mac_addr_add = eth_igb_rar_set,
325 .mac_addr_remove = eth_igb_rar_clear,
326 .mac_addr_set = eth_igb_default_mac_addr_set,
327 .reta_update = eth_igb_rss_reta_update,
328 .reta_query = eth_igb_rss_reta_query,
329 .rss_hash_update = eth_igb_rss_hash_update,
330 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
331 .filter_ctrl = eth_igb_filter_ctrl,
332 .set_mc_addr_list = eth_igb_set_mc_addr_list,
333 .rxq_info_get = igb_rxq_info_get,
334 .txq_info_get = igb_txq_info_get,
335 .timesync_enable = igb_timesync_enable,
336 .timesync_disable = igb_timesync_disable,
337 .timesync_read_rx_timestamp = igb_timesync_read_rx_timestamp,
338 .timesync_read_tx_timestamp = igb_timesync_read_tx_timestamp,
339 .get_reg_length = eth_igb_get_reg_length,
340 .get_reg = eth_igb_get_regs,
341 .get_eeprom_length = eth_igb_get_eeprom_length,
342 .get_eeprom = eth_igb_get_eeprom,
343 .set_eeprom = eth_igb_set_eeprom,
347 * dev_ops for virtual function, bare necessities for basic vf
348 * operation have been implemented
350 static const struct eth_dev_ops igbvf_eth_dev_ops = {
351 .dev_configure = igbvf_dev_configure,
352 .dev_start = igbvf_dev_start,
353 .dev_stop = igbvf_dev_stop,
354 .dev_close = igbvf_dev_close,
355 .link_update = eth_igb_link_update,
356 .stats_get = eth_igbvf_stats_get,
357 .stats_reset = eth_igbvf_stats_reset,
358 .vlan_filter_set = igbvf_vlan_filter_set,
359 .dev_infos_get = eth_igbvf_infos_get,
360 .rx_queue_setup = eth_igb_rx_queue_setup,
361 .rx_queue_release = eth_igb_rx_queue_release,
362 .tx_queue_setup = eth_igb_tx_queue_setup,
363 .tx_queue_release = eth_igb_tx_queue_release,
364 .set_mc_addr_list = eth_igb_set_mc_addr_list,
365 .rxq_info_get = igb_rxq_info_get,
366 .txq_info_get = igb_txq_info_get,
367 .mac_addr_set = igbvf_default_mac_addr_set,
368 .get_reg_length = igbvf_get_reg_length,
369 .get_reg = igbvf_get_regs,
373 * Atomically reads the link status information from global
374 * structure rte_eth_dev.
377 * - Pointer to the structure rte_eth_dev to read from.
378 * - Pointer to the buffer to be saved with the link status.
381 * - On success, zero.
382 * - On failure, negative value.
385 rte_igb_dev_atomic_read_link_status(struct rte_eth_dev *dev,
386 struct rte_eth_link *link)
388 struct rte_eth_link *dst = link;
389 struct rte_eth_link *src = &(dev->data->dev_link);
391 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
392 *(uint64_t *)src) == 0)
399 * Atomically writes the link status information into global
400 * structure rte_eth_dev.
403 * - Pointer to the structure rte_eth_dev to read from.
404 * - Pointer to the buffer to be saved with the link status.
407 * - On success, zero.
408 * - On failure, negative value.
411 rte_igb_dev_atomic_write_link_status(struct rte_eth_dev *dev,
412 struct rte_eth_link *link)
414 struct rte_eth_link *dst = &(dev->data->dev_link);
415 struct rte_eth_link *src = link;
417 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
418 *(uint64_t *)src) == 0)
425 igb_intr_enable(struct rte_eth_dev *dev)
427 struct e1000_interrupt *intr =
428 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
429 struct e1000_hw *hw =
430 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
432 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
433 E1000_WRITE_FLUSH(hw);
437 igb_intr_disable(struct e1000_hw *hw)
439 E1000_WRITE_REG(hw, E1000_IMC, ~0);
440 E1000_WRITE_FLUSH(hw);
443 static inline int32_t
444 igb_pf_reset_hw(struct e1000_hw *hw)
449 status = e1000_reset_hw(hw);
451 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
452 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
453 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
454 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
455 E1000_WRITE_FLUSH(hw);
461 igb_identify_hardware(struct rte_eth_dev *dev)
463 struct e1000_hw *hw =
464 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
466 hw->vendor_id = dev->pci_dev->id.vendor_id;
467 hw->device_id = dev->pci_dev->id.device_id;
468 hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
469 hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
471 e1000_set_mac_type(hw);
473 /* need to check if it is a vf device below */
477 igb_reset_swfw_lock(struct e1000_hw *hw)
482 * Do mac ops initialization manually here, since we will need
483 * some function pointers set by this call.
485 ret_val = e1000_init_mac_params(hw);
490 * SMBI lock should not fail in this early stage. If this is the case,
491 * it is due to an improper exit of the application.
492 * So force the release of the faulty lock.
494 if (e1000_get_hw_semaphore_generic(hw) < 0) {
495 PMD_DRV_LOG(DEBUG, "SMBI lock released");
497 e1000_put_hw_semaphore_generic(hw);
499 if (hw->mac.ops.acquire_swfw_sync != NULL) {
503 * Phy lock should not fail in this early stage. If this is the case,
504 * it is due to an improper exit of the application.
505 * So force the release of the faulty lock.
507 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
508 if (hw->bus.func > E1000_FUNC_1)
510 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
511 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
514 hw->mac.ops.release_swfw_sync(hw, mask);
517 * This one is more tricky since it is common to all ports; but
518 * swfw_sync retries last long enough (1s) to be almost sure that if
519 * lock can not be taken it is due to an improper lock of the
522 mask = E1000_SWFW_EEP_SM;
523 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
524 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
526 hw->mac.ops.release_swfw_sync(hw, mask);
529 return E1000_SUCCESS;
533 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
536 struct rte_pci_device *pci_dev;
537 struct e1000_hw *hw =
538 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
539 struct e1000_vfta * shadow_vfta =
540 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
541 struct e1000_filter_info *filter_info =
542 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
543 struct e1000_adapter *adapter =
544 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
548 pci_dev = eth_dev->pci_dev;
549 eth_dev->dev_ops = ð_igb_ops;
550 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
551 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
553 /* for secondary processes, we don't initialise any further as primary
554 * has already done this work. Only check we don't need a different
556 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
557 if (eth_dev->data->scattered_rx)
558 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
562 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
564 igb_identify_hardware(eth_dev);
565 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
570 e1000_get_bus_info(hw);
572 /* Reset any pending lock */
573 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
578 /* Finish initialization */
579 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
585 hw->phy.autoneg_wait_to_complete = 0;
586 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
589 if (hw->phy.media_type == e1000_media_type_copper) {
590 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
591 hw->phy.disable_polarity_correction = 0;
592 hw->phy.ms_type = e1000_ms_hw_default;
596 * Start from a known state, this is important in reading the nvm
601 /* Make sure we have a good EEPROM before we read from it */
602 if (e1000_validate_nvm_checksum(hw) < 0) {
604 * Some PCI-E parts fail the first check due to
605 * the link being in sleep state, call it again,
606 * if it fails a second time its a real issue.
608 if (e1000_validate_nvm_checksum(hw) < 0) {
609 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
615 /* Read the permanent MAC address out of the EEPROM */
616 if (e1000_read_mac_addr(hw) != 0) {
617 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
622 /* Allocate memory for storing MAC addresses */
623 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
624 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
625 if (eth_dev->data->mac_addrs == NULL) {
626 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
627 "store MAC addresses",
628 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
633 /* Copy the permanent MAC address */
634 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
636 /* initialize the vfta */
637 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
639 /* Now initialize the hardware */
640 if (igb_hardware_init(hw) != 0) {
641 PMD_INIT_LOG(ERR, "Hardware initialization failed");
642 rte_free(eth_dev->data->mac_addrs);
643 eth_dev->data->mac_addrs = NULL;
647 hw->mac.get_link_status = 1;
648 adapter->stopped = 0;
650 /* Indicate SOL/IDER usage */
651 if (e1000_check_reset_block(hw) < 0) {
652 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
656 /* initialize PF if max_vfs not zero */
657 igb_pf_host_init(eth_dev);
659 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
660 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
661 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
662 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
663 E1000_WRITE_FLUSH(hw);
665 PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
666 eth_dev->data->port_id, pci_dev->id.vendor_id,
667 pci_dev->id.device_id);
669 /* enable support intr */
670 igb_intr_enable(eth_dev);
672 TAILQ_INIT(&filter_info->flex_list);
673 filter_info->flex_mask = 0;
674 TAILQ_INIT(&filter_info->twotuple_list);
675 filter_info->twotuple_mask = 0;
676 TAILQ_INIT(&filter_info->fivetuple_list);
677 filter_info->fivetuple_mask = 0;
682 igb_hw_control_release(hw);
688 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
690 struct rte_pci_device *pci_dev;
692 struct e1000_adapter *adapter =
693 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
695 PMD_INIT_FUNC_TRACE();
697 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
700 hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
701 pci_dev = eth_dev->pci_dev;
703 if (adapter->stopped == 0)
704 eth_igb_close(eth_dev);
706 eth_dev->dev_ops = NULL;
707 eth_dev->rx_pkt_burst = NULL;
708 eth_dev->tx_pkt_burst = NULL;
710 /* Reset any pending lock */
711 igb_reset_swfw_lock(hw);
713 rte_free(eth_dev->data->mac_addrs);
714 eth_dev->data->mac_addrs = NULL;
716 /* uninitialize PF if max_vfs not zero */
717 igb_pf_host_uninit(eth_dev);
719 /* disable uio intr before callback unregister */
720 rte_intr_disable(&(pci_dev->intr_handle));
721 rte_intr_callback_unregister(&(pci_dev->intr_handle),
722 eth_igb_interrupt_handler, (void *)eth_dev);
728 * Virtual Function device init
731 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
733 struct rte_pci_device *pci_dev;
734 struct e1000_adapter *adapter =
735 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
736 struct e1000_hw *hw =
737 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
740 PMD_INIT_FUNC_TRACE();
742 eth_dev->dev_ops = &igbvf_eth_dev_ops;
743 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
744 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
746 /* for secondary processes, we don't initialise any further as primary
747 * has already done this work. Only check we don't need a different
749 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
750 if (eth_dev->data->scattered_rx)
751 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
755 pci_dev = eth_dev->pci_dev;
757 hw->device_id = pci_dev->id.device_id;
758 hw->vendor_id = pci_dev->id.vendor_id;
759 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
760 adapter->stopped = 0;
762 /* Initialize the shared code (base driver) */
763 diag = e1000_setup_init_funcs(hw, TRUE);
765 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
770 /* init_mailbox_params */
771 hw->mbx.ops.init_params(hw);
773 /* Disable the interrupts for VF */
774 igbvf_intr_disable(hw);
776 diag = hw->mac.ops.reset_hw(hw);
778 /* Allocate memory for storing MAC addresses */
779 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
780 hw->mac.rar_entry_count, 0);
781 if (eth_dev->data->mac_addrs == NULL) {
783 "Failed to allocate %d bytes needed to store MAC "
785 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
789 /* Copy the permanent MAC address */
790 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
791 ð_dev->data->mac_addrs[0]);
793 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
795 eth_dev->data->port_id, pci_dev->id.vendor_id,
796 pci_dev->id.device_id, "igb_mac_82576_vf");
802 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
804 struct e1000_adapter *adapter =
805 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
807 PMD_INIT_FUNC_TRACE();
809 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
812 if (adapter->stopped == 0)
813 igbvf_dev_close(eth_dev);
815 eth_dev->dev_ops = NULL;
816 eth_dev->rx_pkt_burst = NULL;
817 eth_dev->tx_pkt_burst = NULL;
819 rte_free(eth_dev->data->mac_addrs);
820 eth_dev->data->mac_addrs = NULL;
825 static struct eth_driver rte_igb_pmd = {
827 .name = "rte_igb_pmd",
828 .id_table = pci_id_igb_map,
829 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
830 RTE_PCI_DRV_DETACHABLE,
832 .eth_dev_init = eth_igb_dev_init,
833 .eth_dev_uninit = eth_igb_dev_uninit,
834 .dev_private_size = sizeof(struct e1000_adapter),
838 * virtual function driver struct
840 static struct eth_driver rte_igbvf_pmd = {
842 .name = "rte_igbvf_pmd",
843 .id_table = pci_id_igbvf_map,
844 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
846 .eth_dev_init = eth_igbvf_dev_init,
847 .eth_dev_uninit = eth_igbvf_dev_uninit,
848 .dev_private_size = sizeof(struct e1000_adapter),
852 rte_igb_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
854 rte_eth_driver_register(&rte_igb_pmd);
859 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
861 struct e1000_hw *hw =
862 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
863 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
864 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
865 rctl |= E1000_RCTL_VFE;
866 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
870 * VF Driver initialization routine.
871 * Invoked one at EAL init time.
872 * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
875 rte_igbvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
877 PMD_INIT_FUNC_TRACE();
879 rte_eth_driver_register(&rte_igbvf_pmd);
884 igb_check_mq_mode(struct rte_eth_dev *dev)
886 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
887 enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
888 uint16_t nb_rx_q = dev->data->nb_rx_queues;
889 uint16_t nb_tx_q = dev->data->nb_rx_queues;
891 if ((rx_mq_mode & ETH_MQ_RX_DCB_FLAG) ||
892 tx_mq_mode == ETH_MQ_TX_DCB ||
893 tx_mq_mode == ETH_MQ_TX_VMDQ_DCB) {
894 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
897 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
898 /* Check multi-queue mode.
899 * To no break software we accept ETH_MQ_RX_NONE as this might
900 * be used to turn off VLAN filter.
903 if (rx_mq_mode == ETH_MQ_RX_NONE ||
904 rx_mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
905 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
906 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
908 /* Only support one queue on VFs.
909 * RSS together with SRIOV is not supported.
911 PMD_INIT_LOG(ERR, "SRIOV is active,"
912 " wrong mq_mode rx %d.",
916 /* TX mode is not used here, so mode might be ignored.*/
917 if (tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
918 /* SRIOV only works in VMDq enable mode */
919 PMD_INIT_LOG(WARNING, "SRIOV is active,"
920 " TX mode %d is not supported. "
921 " Driver will behave as %d mode.",
922 tx_mq_mode, ETH_MQ_TX_VMDQ_ONLY);
925 /* check valid queue number */
926 if ((nb_rx_q > 1) || (nb_tx_q > 1)) {
927 PMD_INIT_LOG(ERR, "SRIOV is active,"
928 " only support one queue on VFs.");
932 /* To no break software that set invalid mode, only display
933 * warning if invalid mode is used.
935 if (rx_mq_mode != ETH_MQ_RX_NONE &&
936 rx_mq_mode != ETH_MQ_RX_VMDQ_ONLY &&
937 rx_mq_mode != ETH_MQ_RX_RSS) {
938 /* RSS together with VMDq not supported*/
939 PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
944 if (tx_mq_mode != ETH_MQ_TX_NONE &&
945 tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
946 PMD_INIT_LOG(WARNING, "TX mode %d is not supported."
947 " Due to txmode is meaningless in this"
948 " driver, just ignore.",
956 eth_igb_configure(struct rte_eth_dev *dev)
958 struct e1000_interrupt *intr =
959 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
962 PMD_INIT_FUNC_TRACE();
964 /* multipe queue mode checking */
965 ret = igb_check_mq_mode(dev);
967 PMD_DRV_LOG(ERR, "igb_check_mq_mode fails with %d.",
972 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
973 PMD_INIT_FUNC_TRACE();
979 eth_igb_start(struct rte_eth_dev *dev)
981 struct e1000_hw *hw =
982 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
983 struct e1000_adapter *adapter =
984 E1000_DEV_PRIVATE(dev->data->dev_private);
985 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
987 uint32_t intr_vector = 0;
990 PMD_INIT_FUNC_TRACE();
992 /* Power up the phy. Needed to make the link go Up */
993 e1000_power_up_phy(hw);
996 * Packet Buffer Allocation (PBA)
997 * Writing PBA sets the receive portion of the buffer
998 * the remainder is used for the transmit buffer.
1000 if (hw->mac.type == e1000_82575) {
1003 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
1004 E1000_WRITE_REG(hw, E1000_PBA, pba);
1007 /* Put the address into the Receive Address Array */
1008 e1000_rar_set(hw, hw->mac.addr, 0);
1010 /* Initialize the hardware */
1011 if (igb_hardware_init(hw)) {
1012 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
1015 adapter->stopped = 0;
1017 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1019 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1020 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1021 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
1022 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1023 E1000_WRITE_FLUSH(hw);
1025 /* configure PF module if SRIOV enabled */
1026 igb_pf_host_configure(dev);
1028 /* check and configure queue intr-vector mapping */
1029 if (dev->data->dev_conf.intr_conf.rxq != 0)
1030 intr_vector = dev->data->nb_rx_queues;
1032 if (rte_intr_efd_enable(intr_handle, intr_vector))
1035 if (rte_intr_dp_is_en(intr_handle)) {
1036 intr_handle->intr_vec =
1037 rte_zmalloc("intr_vec",
1038 dev->data->nb_rx_queues * sizeof(int), 0);
1039 if (intr_handle->intr_vec == NULL) {
1040 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1041 " intr_vec\n", dev->data->nb_rx_queues);
1046 /* confiugre msix for rx interrupt */
1047 eth_igb_configure_msix_intr(dev);
1049 /* Configure for OS presence */
1050 igb_init_manageability(hw);
1052 eth_igb_tx_init(dev);
1054 /* This can fail when allocating mbufs for descriptor rings */
1055 ret = eth_igb_rx_init(dev);
1057 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1058 igb_dev_clear_queues(dev);
1062 e1000_clear_hw_cntrs_base_generic(hw);
1065 * VLAN Offload Settings
1067 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
1068 ETH_VLAN_EXTEND_MASK;
1069 eth_igb_vlan_offload_set(dev, mask);
1071 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1072 /* Enable VLAN filter since VMDq always use VLAN filter */
1073 igb_vmdq_vlan_hw_filter_enable(dev);
1076 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
1077 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
1078 (hw->mac.type == e1000_i211)) {
1079 /* Configure EITR with the maximum possible value (0xFFFF) */
1080 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
1083 /* Setup link speed and duplex */
1084 switch (dev->data->dev_conf.link_speed) {
1085 case ETH_LINK_SPEED_AUTONEG:
1086 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
1087 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
1088 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
1089 hw->phy.autoneg_advertised = E1000_ALL_HALF_DUPLEX;
1090 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
1091 hw->phy.autoneg_advertised = E1000_ALL_FULL_DUPLEX;
1093 goto error_invalid_config;
1095 case ETH_LINK_SPEED_10:
1096 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
1097 hw->phy.autoneg_advertised = E1000_ALL_10_SPEED;
1098 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
1099 hw->phy.autoneg_advertised = ADVERTISE_10_HALF;
1100 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
1101 hw->phy.autoneg_advertised = ADVERTISE_10_FULL;
1103 goto error_invalid_config;
1105 case ETH_LINK_SPEED_100:
1106 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
1107 hw->phy.autoneg_advertised = E1000_ALL_100_SPEED;
1108 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
1109 hw->phy.autoneg_advertised = ADVERTISE_100_HALF;
1110 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
1111 hw->phy.autoneg_advertised = ADVERTISE_100_FULL;
1113 goto error_invalid_config;
1115 case ETH_LINK_SPEED_1000:
1116 if ((dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX) ||
1117 (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX))
1118 hw->phy.autoneg_advertised = ADVERTISE_1000_FULL;
1120 goto error_invalid_config;
1122 case ETH_LINK_SPEED_10000:
1124 goto error_invalid_config;
1126 e1000_setup_link(hw);
1128 /* check if lsc interrupt feature is enabled */
1129 if (dev->data->dev_conf.intr_conf.lsc != 0) {
1130 if (rte_intr_allow_others(intr_handle)) {
1131 rte_intr_callback_register(intr_handle,
1132 eth_igb_interrupt_handler,
1134 eth_igb_lsc_interrupt_setup(dev);
1136 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1137 " no intr multiplex\n");
1140 /* check if rxq interrupt is enabled */
1141 if (dev->data->dev_conf.intr_conf.rxq != 0)
1142 eth_igb_rxq_interrupt_setup(dev);
1144 /* enable uio/vfio intr/eventfd mapping */
1145 rte_intr_enable(intr_handle);
1147 /* resume enabled intr since hw reset */
1148 igb_intr_enable(dev);
1150 PMD_INIT_LOG(DEBUG, "<<");
1154 error_invalid_config:
1155 PMD_INIT_LOG(ERR, "Invalid link_speed/link_duplex (%u/%u) for port %u",
1156 dev->data->dev_conf.link_speed,
1157 dev->data->dev_conf.link_duplex, dev->data->port_id);
1158 igb_dev_clear_queues(dev);
1162 /*********************************************************************
1164 * This routine disables all traffic on the adapter by issuing a
1165 * global reset on the MAC.
1167 **********************************************************************/
1169 eth_igb_stop(struct rte_eth_dev *dev)
1171 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1172 struct e1000_filter_info *filter_info =
1173 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1174 struct rte_eth_link link;
1175 struct e1000_flex_filter *p_flex;
1176 struct e1000_5tuple_filter *p_5tuple, *p_5tuple_next;
1177 struct e1000_2tuple_filter *p_2tuple, *p_2tuple_next;
1178 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1180 igb_intr_disable(hw);
1182 /* disable intr eventfd mapping */
1183 rte_intr_disable(intr_handle);
1185 igb_pf_reset_hw(hw);
1186 E1000_WRITE_REG(hw, E1000_WUC, 0);
1188 /* Set bit for Go Link disconnect */
1189 if (hw->mac.type >= e1000_82580) {
1192 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1193 phpm_reg |= E1000_82580_PM_GO_LINKD;
1194 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1197 /* Power down the phy. Needed to make the link go Down */
1198 if (hw->phy.media_type == e1000_media_type_copper)
1199 e1000_power_down_phy(hw);
1201 e1000_shutdown_fiber_serdes_link(hw);
1203 igb_dev_clear_queues(dev);
1205 /* clear the recorded link status */
1206 memset(&link, 0, sizeof(link));
1207 rte_igb_dev_atomic_write_link_status(dev, &link);
1209 /* Remove all flex filters of the device */
1210 while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
1211 TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
1214 filter_info->flex_mask = 0;
1216 /* Remove all ntuple filters of the device */
1217 for (p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list);
1218 p_5tuple != NULL; p_5tuple = p_5tuple_next) {
1219 p_5tuple_next = TAILQ_NEXT(p_5tuple, entries);
1220 TAILQ_REMOVE(&filter_info->fivetuple_list,
1224 filter_info->fivetuple_mask = 0;
1225 for (p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list);
1226 p_2tuple != NULL; p_2tuple = p_2tuple_next) {
1227 p_2tuple_next = TAILQ_NEXT(p_2tuple, entries);
1228 TAILQ_REMOVE(&filter_info->twotuple_list,
1232 filter_info->twotuple_mask = 0;
1234 /* Clean datapath event and queue/vec mapping */
1235 rte_intr_efd_disable(intr_handle);
1236 if (intr_handle->intr_vec != NULL) {
1237 rte_free(intr_handle->intr_vec);
1238 intr_handle->intr_vec = NULL;
1243 eth_igb_close(struct rte_eth_dev *dev)
1245 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1246 struct e1000_adapter *adapter =
1247 E1000_DEV_PRIVATE(dev->data->dev_private);
1248 struct rte_eth_link link;
1249 struct rte_pci_device *pci_dev;
1252 adapter->stopped = 1;
1254 e1000_phy_hw_reset(hw);
1255 igb_release_manageability(hw);
1256 igb_hw_control_release(hw);
1258 /* Clear bit for Go Link disconnect */
1259 if (hw->mac.type >= e1000_82580) {
1262 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1263 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1264 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1267 igb_dev_free_queues(dev);
1269 pci_dev = dev->pci_dev;
1270 if (pci_dev->intr_handle.intr_vec) {
1271 rte_free(pci_dev->intr_handle.intr_vec);
1272 pci_dev->intr_handle.intr_vec = NULL;
1275 memset(&link, 0, sizeof(link));
1276 rte_igb_dev_atomic_write_link_status(dev, &link);
1280 igb_get_rx_buffer_size(struct e1000_hw *hw)
1282 uint32_t rx_buf_size;
1283 if (hw->mac.type == e1000_82576) {
1284 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1285 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1286 /* PBS needs to be translated according to a lookup table */
1287 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1288 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1289 rx_buf_size = (rx_buf_size << 10);
1290 } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1291 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1293 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1299 /*********************************************************************
1301 * Initialize the hardware
1303 **********************************************************************/
1305 igb_hardware_init(struct e1000_hw *hw)
1307 uint32_t rx_buf_size;
1310 /* Let the firmware know the OS is in control */
1311 igb_hw_control_acquire(hw);
1314 * These parameters control the automatic generation (Tx) and
1315 * response (Rx) to Ethernet PAUSE frames.
1316 * - High water mark should allow for at least two standard size (1518)
1317 * frames to be received after sending an XOFF.
1318 * - Low water mark works best when it is very near the high water mark.
1319 * This allows the receiver to restart by sending XON when it has
1320 * drained a bit. Here we use an arbitrary value of 1500 which will
1321 * restart after one full frame is pulled from the buffer. There
1322 * could be several smaller frames in the buffer and if so they will
1323 * not trigger the XON until their total number reduces the buffer
1325 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1327 rx_buf_size = igb_get_rx_buffer_size(hw);
1329 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
1330 hw->fc.low_water = hw->fc.high_water - 1500;
1331 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1332 hw->fc.send_xon = 1;
1334 /* Set Flow control, use the tunable location if sane */
1335 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1336 hw->fc.requested_mode = igb_fc_setting;
1338 hw->fc.requested_mode = e1000_fc_none;
1340 /* Issue a global reset */
1341 igb_pf_reset_hw(hw);
1342 E1000_WRITE_REG(hw, E1000_WUC, 0);
1344 diag = e1000_init_hw(hw);
1348 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1349 e1000_get_phy_info(hw);
1350 e1000_check_for_link(hw);
1355 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1357 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1359 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1360 struct e1000_hw_stats *stats =
1361 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1364 if(hw->phy.media_type == e1000_media_type_copper ||
1365 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1367 E1000_READ_REG(hw,E1000_SYMERRS);
1368 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1371 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1372 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1373 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1374 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1376 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1377 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1378 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1379 stats->dc += E1000_READ_REG(hw, E1000_DC);
1380 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1381 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1382 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1384 ** For watchdog management we need to know if we have been
1385 ** paused during the last interval, so capture that here.
1387 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1388 stats->xoffrxc += pause_frames;
1389 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1390 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1391 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1392 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1393 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1394 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1395 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1396 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1397 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1398 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1399 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1400 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1402 /* For the 64-bit byte counters the low dword must be read first. */
1403 /* Both registers clear on the read of the high dword */
1405 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1406 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1407 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1408 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1410 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1411 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1412 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1413 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1414 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1416 stats->tor += E1000_READ_REG(hw, E1000_TORL);
1417 stats->tor += ((uint64_t)E1000_READ_REG(hw, E1000_TORH) << 32);
1418 stats->tot += E1000_READ_REG(hw, E1000_TOTL);
1419 stats->tot += ((uint64_t)E1000_READ_REG(hw, E1000_TOTH) << 32);
1421 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1422 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1423 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1424 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1425 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1426 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1427 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1428 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1429 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1430 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1432 /* Interrupt Counts */
1434 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1435 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1436 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1437 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1438 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1439 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1440 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1441 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1442 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1444 /* Host to Card Statistics */
1446 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1447 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1448 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1449 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1450 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1451 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1452 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1453 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1454 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1455 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1456 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1457 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1458 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1459 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1461 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1462 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1463 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1464 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1465 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1466 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1468 if (rte_stats == NULL)
1472 rte_stats->ibadcrc = stats->crcerrs;
1473 rte_stats->ibadlen = stats->rlec + stats->ruc + stats->roc;
1474 rte_stats->imissed = stats->mpc;
1475 rte_stats->ierrors = rte_stats->ibadcrc +
1476 rte_stats->ibadlen +
1477 rte_stats->imissed +
1478 stats->rxerrc + stats->algnerrc + stats->cexterr;
1481 rte_stats->oerrors = stats->ecol + stats->latecol;
1483 /* XON/XOFF pause frames */
1484 rte_stats->tx_pause_xon = stats->xontxc;
1485 rte_stats->rx_pause_xon = stats->xonrxc;
1486 rte_stats->tx_pause_xoff = stats->xofftxc;
1487 rte_stats->rx_pause_xoff = stats->xoffrxc;
1489 rte_stats->ipackets = stats->gprc;
1490 rte_stats->opackets = stats->gptc;
1491 rte_stats->ibytes = stats->gorc;
1492 rte_stats->obytes = stats->gotc;
1496 eth_igb_stats_reset(struct rte_eth_dev *dev)
1498 struct e1000_hw_stats *hw_stats =
1499 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1501 /* HW registers are cleared on read */
1502 eth_igb_stats_get(dev, NULL);
1504 /* Reset software totals */
1505 memset(hw_stats, 0, sizeof(*hw_stats));
1509 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1511 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1512 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
1513 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1515 /* Good Rx packets, include VF loopback */
1516 UPDATE_VF_STAT(E1000_VFGPRC,
1517 hw_stats->last_gprc, hw_stats->gprc);
1519 /* Good Rx octets, include VF loopback */
1520 UPDATE_VF_STAT(E1000_VFGORC,
1521 hw_stats->last_gorc, hw_stats->gorc);
1523 /* Good Tx packets, include VF loopback */
1524 UPDATE_VF_STAT(E1000_VFGPTC,
1525 hw_stats->last_gptc, hw_stats->gptc);
1527 /* Good Tx octets, include VF loopback */
1528 UPDATE_VF_STAT(E1000_VFGOTC,
1529 hw_stats->last_gotc, hw_stats->gotc);
1531 /* Rx Multicst packets */
1532 UPDATE_VF_STAT(E1000_VFMPRC,
1533 hw_stats->last_mprc, hw_stats->mprc);
1535 /* Good Rx loopback packets */
1536 UPDATE_VF_STAT(E1000_VFGPRLBC,
1537 hw_stats->last_gprlbc, hw_stats->gprlbc);
1539 /* Good Rx loopback octets */
1540 UPDATE_VF_STAT(E1000_VFGORLBC,
1541 hw_stats->last_gorlbc, hw_stats->gorlbc);
1543 /* Good Tx loopback packets */
1544 UPDATE_VF_STAT(E1000_VFGPTLBC,
1545 hw_stats->last_gptlbc, hw_stats->gptlbc);
1547 /* Good Tx loopback octets */
1548 UPDATE_VF_STAT(E1000_VFGOTLBC,
1549 hw_stats->last_gotlbc, hw_stats->gotlbc);
1551 if (rte_stats == NULL)
1554 rte_stats->ipackets = hw_stats->gprc;
1555 rte_stats->ibytes = hw_stats->gorc;
1556 rte_stats->opackets = hw_stats->gptc;
1557 rte_stats->obytes = hw_stats->gotc;
1558 rte_stats->imcasts = hw_stats->mprc;
1559 rte_stats->ilbpackets = hw_stats->gprlbc;
1560 rte_stats->ilbbytes = hw_stats->gorlbc;
1561 rte_stats->olbpackets = hw_stats->gptlbc;
1562 rte_stats->olbbytes = hw_stats->gotlbc;
1567 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
1569 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
1570 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1572 /* Sync HW register to the last stats */
1573 eth_igbvf_stats_get(dev, NULL);
1575 /* reset HW current stats*/
1576 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
1577 offsetof(struct e1000_vf_stats, gprc));
1582 eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1584 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1586 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1587 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
1588 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1589 dev_info->rx_offload_capa =
1590 DEV_RX_OFFLOAD_VLAN_STRIP |
1591 DEV_RX_OFFLOAD_IPV4_CKSUM |
1592 DEV_RX_OFFLOAD_UDP_CKSUM |
1593 DEV_RX_OFFLOAD_TCP_CKSUM;
1594 dev_info->tx_offload_capa =
1595 DEV_TX_OFFLOAD_VLAN_INSERT |
1596 DEV_TX_OFFLOAD_IPV4_CKSUM |
1597 DEV_TX_OFFLOAD_UDP_CKSUM |
1598 DEV_TX_OFFLOAD_TCP_CKSUM |
1599 DEV_TX_OFFLOAD_SCTP_CKSUM |
1600 DEV_TX_OFFLOAD_TCP_TSO;
1602 switch (hw->mac.type) {
1604 dev_info->max_rx_queues = 4;
1605 dev_info->max_tx_queues = 4;
1606 dev_info->max_vmdq_pools = 0;
1610 dev_info->max_rx_queues = 16;
1611 dev_info->max_tx_queues = 16;
1612 dev_info->max_vmdq_pools = ETH_8_POOLS;
1613 dev_info->vmdq_queue_num = 16;
1617 dev_info->max_rx_queues = 8;
1618 dev_info->max_tx_queues = 8;
1619 dev_info->max_vmdq_pools = ETH_8_POOLS;
1620 dev_info->vmdq_queue_num = 8;
1624 dev_info->max_rx_queues = 8;
1625 dev_info->max_tx_queues = 8;
1626 dev_info->max_vmdq_pools = ETH_8_POOLS;
1627 dev_info->vmdq_queue_num = 8;
1631 dev_info->max_rx_queues = 8;
1632 dev_info->max_tx_queues = 8;
1636 dev_info->max_rx_queues = 4;
1637 dev_info->max_tx_queues = 4;
1638 dev_info->max_vmdq_pools = 0;
1642 dev_info->max_rx_queues = 2;
1643 dev_info->max_tx_queues = 2;
1644 dev_info->max_vmdq_pools = 0;
1648 /* Should not happen */
1651 dev_info->hash_key_size = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
1652 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
1653 dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
1655 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1657 .pthresh = IGB_DEFAULT_RX_PTHRESH,
1658 .hthresh = IGB_DEFAULT_RX_HTHRESH,
1659 .wthresh = IGB_DEFAULT_RX_WTHRESH,
1661 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
1665 dev_info->default_txconf = (struct rte_eth_txconf) {
1667 .pthresh = IGB_DEFAULT_TX_PTHRESH,
1668 .hthresh = IGB_DEFAULT_TX_HTHRESH,
1669 .wthresh = IGB_DEFAULT_TX_WTHRESH,
1674 dev_info->rx_desc_lim = rx_desc_lim;
1675 dev_info->tx_desc_lim = tx_desc_lim;
1679 eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1681 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1683 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1684 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
1685 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1686 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
1687 DEV_RX_OFFLOAD_IPV4_CKSUM |
1688 DEV_RX_OFFLOAD_UDP_CKSUM |
1689 DEV_RX_OFFLOAD_TCP_CKSUM;
1690 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
1691 DEV_TX_OFFLOAD_IPV4_CKSUM |
1692 DEV_TX_OFFLOAD_UDP_CKSUM |
1693 DEV_TX_OFFLOAD_TCP_CKSUM |
1694 DEV_TX_OFFLOAD_SCTP_CKSUM |
1695 DEV_TX_OFFLOAD_TCP_TSO;
1696 switch (hw->mac.type) {
1698 dev_info->max_rx_queues = 2;
1699 dev_info->max_tx_queues = 2;
1701 case e1000_vfadapt_i350:
1702 dev_info->max_rx_queues = 1;
1703 dev_info->max_tx_queues = 1;
1706 /* Should not happen */
1710 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1712 .pthresh = IGB_DEFAULT_RX_PTHRESH,
1713 .hthresh = IGB_DEFAULT_RX_HTHRESH,
1714 .wthresh = IGB_DEFAULT_RX_WTHRESH,
1716 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
1720 dev_info->default_txconf = (struct rte_eth_txconf) {
1722 .pthresh = IGB_DEFAULT_TX_PTHRESH,
1723 .hthresh = IGB_DEFAULT_TX_HTHRESH,
1724 .wthresh = IGB_DEFAULT_TX_WTHRESH,
1729 dev_info->rx_desc_lim = rx_desc_lim;
1730 dev_info->tx_desc_lim = tx_desc_lim;
1733 /* return 0 means link status changed, -1 means not changed */
1735 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1737 struct e1000_hw *hw =
1738 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1739 struct rte_eth_link link, old;
1740 int link_check, count;
1743 hw->mac.get_link_status = 1;
1745 /* possible wait-to-complete in up to 9 seconds */
1746 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
1747 /* Read the real link status */
1748 switch (hw->phy.media_type) {
1749 case e1000_media_type_copper:
1750 /* Do the work to read phy */
1751 e1000_check_for_link(hw);
1752 link_check = !hw->mac.get_link_status;
1755 case e1000_media_type_fiber:
1756 e1000_check_for_link(hw);
1757 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
1761 case e1000_media_type_internal_serdes:
1762 e1000_check_for_link(hw);
1763 link_check = hw->mac.serdes_has_link;
1766 /* VF device is type_unknown */
1767 case e1000_media_type_unknown:
1768 eth_igbvf_link_update(hw);
1769 link_check = !hw->mac.get_link_status;
1775 if (link_check || wait_to_complete == 0)
1777 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
1779 memset(&link, 0, sizeof(link));
1780 rte_igb_dev_atomic_read_link_status(dev, &link);
1783 /* Now we check if a transition has happened */
1785 hw->mac.ops.get_link_up_info(hw, &link.link_speed,
1787 link.link_status = 1;
1788 } else if (!link_check) {
1789 link.link_speed = 0;
1790 link.link_duplex = 0;
1791 link.link_status = 0;
1793 rte_igb_dev_atomic_write_link_status(dev, &link);
1796 if (old.link_status == link.link_status)
1804 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
1805 * For ASF and Pass Through versions of f/w this means
1806 * that the driver is loaded.
1809 igb_hw_control_acquire(struct e1000_hw *hw)
1813 /* Let firmware know the driver has taken over */
1814 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1815 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
1819 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
1820 * For ASF and Pass Through versions of f/w this means that the
1821 * driver is no longer loaded.
1824 igb_hw_control_release(struct e1000_hw *hw)
1828 /* Let firmware taken over control of h/w */
1829 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1830 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
1831 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
1835 * Bit of a misnomer, what this really means is
1836 * to enable OS management of the system... aka
1837 * to disable special hardware management features.
1840 igb_init_manageability(struct e1000_hw *hw)
1842 if (e1000_enable_mng_pass_thru(hw)) {
1843 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
1844 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1846 /* disable hardware interception of ARP */
1847 manc &= ~(E1000_MANC_ARP_EN);
1849 /* enable receiving management packets to the host */
1850 manc |= E1000_MANC_EN_MNG2HOST;
1851 manc2h |= 1 << 5; /* Mng Port 623 */
1852 manc2h |= 1 << 6; /* Mng Port 664 */
1853 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
1854 E1000_WRITE_REG(hw, E1000_MANC, manc);
1859 igb_release_manageability(struct e1000_hw *hw)
1861 if (e1000_enable_mng_pass_thru(hw)) {
1862 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
1864 manc |= E1000_MANC_ARP_EN;
1865 manc &= ~E1000_MANC_EN_MNG2HOST;
1867 E1000_WRITE_REG(hw, E1000_MANC, manc);
1872 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
1874 struct e1000_hw *hw =
1875 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1878 rctl = E1000_READ_REG(hw, E1000_RCTL);
1879 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
1880 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1884 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
1886 struct e1000_hw *hw =
1887 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1890 rctl = E1000_READ_REG(hw, E1000_RCTL);
1891 rctl &= (~E1000_RCTL_UPE);
1892 if (dev->data->all_multicast == 1)
1893 rctl |= E1000_RCTL_MPE;
1895 rctl &= (~E1000_RCTL_MPE);
1896 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1900 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
1902 struct e1000_hw *hw =
1903 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1906 rctl = E1000_READ_REG(hw, E1000_RCTL);
1907 rctl |= E1000_RCTL_MPE;
1908 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1912 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
1914 struct e1000_hw *hw =
1915 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1918 if (dev->data->promiscuous == 1)
1919 return; /* must remain in all_multicast mode */
1920 rctl = E1000_READ_REG(hw, E1000_RCTL);
1921 rctl &= (~E1000_RCTL_MPE);
1922 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1926 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1928 struct e1000_hw *hw =
1929 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1930 struct e1000_vfta * shadow_vfta =
1931 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1936 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
1937 E1000_VFTA_ENTRY_MASK);
1938 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
1939 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
1944 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
1946 /* update local VFTA copy */
1947 shadow_vfta->vfta[vid_idx] = vfta;
1953 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid)
1955 struct e1000_hw *hw =
1956 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1957 uint32_t reg = ETHER_TYPE_VLAN ;
1959 reg |= (tpid << 16);
1960 E1000_WRITE_REG(hw, E1000_VET, reg);
1964 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1966 struct e1000_hw *hw =
1967 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1970 /* Filter Table Disable */
1971 reg = E1000_READ_REG(hw, E1000_RCTL);
1972 reg &= ~E1000_RCTL_CFIEN;
1973 reg &= ~E1000_RCTL_VFE;
1974 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1978 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1980 struct e1000_hw *hw =
1981 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1982 struct e1000_vfta * shadow_vfta =
1983 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1987 /* Filter Table Enable, CFI not used for packet acceptance */
1988 reg = E1000_READ_REG(hw, E1000_RCTL);
1989 reg &= ~E1000_RCTL_CFIEN;
1990 reg |= E1000_RCTL_VFE;
1991 E1000_WRITE_REG(hw, E1000_RCTL, reg);
1993 /* restore VFTA table */
1994 for (i = 0; i < IGB_VFTA_SIZE; i++)
1995 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
1999 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
2001 struct e1000_hw *hw =
2002 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2005 /* VLAN Mode Disable */
2006 reg = E1000_READ_REG(hw, E1000_CTRL);
2007 reg &= ~E1000_CTRL_VME;
2008 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2012 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
2014 struct e1000_hw *hw =
2015 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2018 /* VLAN Mode Enable */
2019 reg = E1000_READ_REG(hw, E1000_CTRL);
2020 reg |= E1000_CTRL_VME;
2021 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2025 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2027 struct e1000_hw *hw =
2028 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2031 /* CTRL_EXT: Extended VLAN */
2032 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2033 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
2034 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2036 /* Update maximum packet length */
2037 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
2038 E1000_WRITE_REG(hw, E1000_RLPML,
2039 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2044 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2046 struct e1000_hw *hw =
2047 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2050 /* CTRL_EXT: Extended VLAN */
2051 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2052 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
2053 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2055 /* Update maximum packet length */
2056 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
2057 E1000_WRITE_REG(hw, E1000_RLPML,
2058 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2063 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2065 if(mask & ETH_VLAN_STRIP_MASK){
2066 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2067 igb_vlan_hw_strip_enable(dev);
2069 igb_vlan_hw_strip_disable(dev);
2072 if(mask & ETH_VLAN_FILTER_MASK){
2073 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2074 igb_vlan_hw_filter_enable(dev);
2076 igb_vlan_hw_filter_disable(dev);
2079 if(mask & ETH_VLAN_EXTEND_MASK){
2080 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2081 igb_vlan_hw_extend_enable(dev);
2083 igb_vlan_hw_extend_disable(dev);
2089 * It enables the interrupt mask and then enable the interrupt.
2092 * Pointer to struct rte_eth_dev.
2095 * - On success, zero.
2096 * - On failure, a negative value.
2099 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev)
2101 struct e1000_interrupt *intr =
2102 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2104 intr->mask |= E1000_ICR_LSC;
2109 /* It clears the interrupt causes and enables the interrupt.
2110 * It will be called once only during nic initialized.
2113 * Pointer to struct rte_eth_dev.
2116 * - On success, zero.
2117 * - On failure, a negative value.
2119 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev)
2121 uint32_t mask, regval;
2122 struct e1000_hw *hw =
2123 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2124 struct rte_eth_dev_info dev_info;
2126 memset(&dev_info, 0, sizeof(dev_info));
2127 eth_igb_infos_get(dev, &dev_info);
2129 mask = 0xFFFFFFFF >> (32 - dev_info.max_rx_queues);
2130 regval = E1000_READ_REG(hw, E1000_EIMS);
2131 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
2137 * It reads ICR and gets interrupt causes, check it and set a bit flag
2138 * to update link status.
2141 * Pointer to struct rte_eth_dev.
2144 * - On success, zero.
2145 * - On failure, a negative value.
2148 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
2151 struct e1000_hw *hw =
2152 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2153 struct e1000_interrupt *intr =
2154 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2156 igb_intr_disable(hw);
2158 /* read-on-clear nic registers here */
2159 icr = E1000_READ_REG(hw, E1000_ICR);
2162 if (icr & E1000_ICR_LSC) {
2163 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
2166 if (icr & E1000_ICR_VMMB)
2167 intr->flags |= E1000_FLAG_MAILBOX;
2173 * It executes link_update after knowing an interrupt is prsent.
2176 * Pointer to struct rte_eth_dev.
2179 * - On success, zero.
2180 * - On failure, a negative value.
2183 eth_igb_interrupt_action(struct rte_eth_dev *dev)
2185 struct e1000_hw *hw =
2186 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2187 struct e1000_interrupt *intr =
2188 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2189 uint32_t tctl, rctl;
2190 struct rte_eth_link link;
2193 if (intr->flags & E1000_FLAG_MAILBOX) {
2194 igb_pf_mbx_process(dev);
2195 intr->flags &= ~E1000_FLAG_MAILBOX;
2198 igb_intr_enable(dev);
2199 rte_intr_enable(&(dev->pci_dev->intr_handle));
2201 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
2202 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
2204 /* set get_link_status to check register later */
2205 hw->mac.get_link_status = 1;
2206 ret = eth_igb_link_update(dev, 0);
2208 /* check if link has changed */
2212 memset(&link, 0, sizeof(link));
2213 rte_igb_dev_atomic_read_link_status(dev, &link);
2214 if (link.link_status) {
2216 " Port %d: Link Up - speed %u Mbps - %s",
2218 (unsigned)link.link_speed,
2219 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2220 "full-duplex" : "half-duplex");
2222 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2223 dev->data->port_id);
2226 PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
2227 dev->pci_dev->addr.domain,
2228 dev->pci_dev->addr.bus,
2229 dev->pci_dev->addr.devid,
2230 dev->pci_dev->addr.function);
2231 tctl = E1000_READ_REG(hw, E1000_TCTL);
2232 rctl = E1000_READ_REG(hw, E1000_RCTL);
2233 if (link.link_status) {
2235 tctl |= E1000_TCTL_EN;
2236 rctl |= E1000_RCTL_EN;
2239 tctl &= ~E1000_TCTL_EN;
2240 rctl &= ~E1000_RCTL_EN;
2242 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
2243 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2244 E1000_WRITE_FLUSH(hw);
2245 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
2252 * Interrupt handler which shall be registered at first.
2255 * Pointer to interrupt handle.
2257 * The address of parameter (struct rte_eth_dev *) regsitered before.
2263 eth_igb_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
2266 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2268 eth_igb_interrupt_get_status(dev);
2269 eth_igb_interrupt_action(dev);
2273 eth_igb_led_on(struct rte_eth_dev *dev)
2275 struct e1000_hw *hw;
2277 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2278 return (e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
2282 eth_igb_led_off(struct rte_eth_dev *dev)
2284 struct e1000_hw *hw;
2286 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2287 return (e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
2291 eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2293 struct e1000_hw *hw;
2298 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2299 fc_conf->pause_time = hw->fc.pause_time;
2300 fc_conf->high_water = hw->fc.high_water;
2301 fc_conf->low_water = hw->fc.low_water;
2302 fc_conf->send_xon = hw->fc.send_xon;
2303 fc_conf->autoneg = hw->mac.autoneg;
2306 * Return rx_pause and tx_pause status according to actual setting of
2307 * the TFCE and RFCE bits in the CTRL register.
2309 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2310 if (ctrl & E1000_CTRL_TFCE)
2315 if (ctrl & E1000_CTRL_RFCE)
2320 if (rx_pause && tx_pause)
2321 fc_conf->mode = RTE_FC_FULL;
2323 fc_conf->mode = RTE_FC_RX_PAUSE;
2325 fc_conf->mode = RTE_FC_TX_PAUSE;
2327 fc_conf->mode = RTE_FC_NONE;
2333 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2335 struct e1000_hw *hw;
2337 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
2343 uint32_t rx_buf_size;
2344 uint32_t max_high_water;
2347 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2348 if (fc_conf->autoneg != hw->mac.autoneg)
2350 rx_buf_size = igb_get_rx_buffer_size(hw);
2351 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2353 /* At least reserve one Ethernet frame for watermark */
2354 max_high_water = rx_buf_size - ETHER_MAX_LEN;
2355 if ((fc_conf->high_water > max_high_water) ||
2356 (fc_conf->high_water < fc_conf->low_water)) {
2357 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
2358 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
2362 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
2363 hw->fc.pause_time = fc_conf->pause_time;
2364 hw->fc.high_water = fc_conf->high_water;
2365 hw->fc.low_water = fc_conf->low_water;
2366 hw->fc.send_xon = fc_conf->send_xon;
2368 err = e1000_setup_link_generic(hw);
2369 if (err == E1000_SUCCESS) {
2371 /* check if we want to forward MAC frames - driver doesn't have native
2372 * capability to do that, so we'll write the registers ourselves */
2374 rctl = E1000_READ_REG(hw, E1000_RCTL);
2376 /* set or clear MFLCN.PMCF bit depending on configuration */
2377 if (fc_conf->mac_ctrl_frame_fwd != 0)
2378 rctl |= E1000_RCTL_PMCF;
2380 rctl &= ~E1000_RCTL_PMCF;
2382 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2383 E1000_WRITE_FLUSH(hw);
2388 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
2392 #define E1000_RAH_POOLSEL_SHIFT (18)
2394 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
2395 uint32_t index, __rte_unused uint32_t pool)
2397 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2400 e1000_rar_set(hw, mac_addr->addr_bytes, index);
2401 rah = E1000_READ_REG(hw, E1000_RAH(index));
2402 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
2403 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
2407 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
2409 uint8_t addr[ETHER_ADDR_LEN];
2410 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2412 memset(addr, 0, sizeof(addr));
2414 e1000_rar_set(hw, addr, index);
2418 eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
2419 struct ether_addr *addr)
2421 eth_igb_rar_clear(dev, 0);
2423 eth_igb_rar_set(dev, (void *)addr, 0, 0);
2426 * Virtual Function operations
2429 igbvf_intr_disable(struct e1000_hw *hw)
2431 PMD_INIT_FUNC_TRACE();
2433 /* Clear interrupt mask to stop from interrupts being generated */
2434 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
2436 E1000_WRITE_FLUSH(hw);
2440 igbvf_stop_adapter(struct rte_eth_dev *dev)
2444 struct rte_eth_dev_info dev_info;
2445 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2447 memset(&dev_info, 0, sizeof(dev_info));
2448 eth_igbvf_infos_get(dev, &dev_info);
2450 /* Clear interrupt mask to stop from interrupts being generated */
2451 igbvf_intr_disable(hw);
2453 /* Clear any pending interrupts, flush previous writes */
2454 E1000_READ_REG(hw, E1000_EICR);
2456 /* Disable the transmit unit. Each queue must be disabled. */
2457 for (i = 0; i < dev_info.max_tx_queues; i++)
2458 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
2460 /* Disable the receive unit by stopping each queue */
2461 for (i = 0; i < dev_info.max_rx_queues; i++) {
2462 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
2463 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
2464 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
2465 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
2469 /* flush all queues disables */
2470 E1000_WRITE_FLUSH(hw);
2474 static int eth_igbvf_link_update(struct e1000_hw *hw)
2476 struct e1000_mbx_info *mbx = &hw->mbx;
2477 struct e1000_mac_info *mac = &hw->mac;
2478 int ret_val = E1000_SUCCESS;
2480 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
2483 * We only want to run this if there has been a rst asserted.
2484 * in this case that could mean a link change, device reset,
2485 * or a virtual function reset
2488 /* If we were hit with a reset or timeout drop the link */
2489 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
2490 mac->get_link_status = TRUE;
2492 if (!mac->get_link_status)
2495 /* if link status is down no point in checking to see if pf is up */
2496 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
2499 /* if we passed all the tests above then the link is up and we no
2500 * longer need to check for link */
2501 mac->get_link_status = FALSE;
2509 igbvf_dev_configure(struct rte_eth_dev *dev)
2511 struct rte_eth_conf* conf = &dev->data->dev_conf;
2513 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
2514 dev->data->port_id);
2517 * VF has no ability to enable/disable HW CRC
2518 * Keep the persistent behavior the same as Host PF
2520 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
2521 if (!conf->rxmode.hw_strip_crc) {
2522 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
2523 conf->rxmode.hw_strip_crc = 1;
2526 if (conf->rxmode.hw_strip_crc) {
2527 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
2528 conf->rxmode.hw_strip_crc = 0;
2536 igbvf_dev_start(struct rte_eth_dev *dev)
2538 struct e1000_hw *hw =
2539 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2540 struct e1000_adapter *adapter =
2541 E1000_DEV_PRIVATE(dev->data->dev_private);
2544 PMD_INIT_FUNC_TRACE();
2546 hw->mac.ops.reset_hw(hw);
2547 adapter->stopped = 0;
2550 igbvf_set_vfta_all(dev,1);
2552 eth_igbvf_tx_init(dev);
2554 /* This can fail when allocating mbufs for descriptor rings */
2555 ret = eth_igbvf_rx_init(dev);
2557 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
2558 igb_dev_clear_queues(dev);
2566 igbvf_dev_stop(struct rte_eth_dev *dev)
2568 PMD_INIT_FUNC_TRACE();
2570 igbvf_stop_adapter(dev);
2573 * Clear what we set, but we still keep shadow_vfta to
2574 * restore after device starts
2576 igbvf_set_vfta_all(dev,0);
2578 igb_dev_clear_queues(dev);
2582 igbvf_dev_close(struct rte_eth_dev *dev)
2584 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2585 struct e1000_adapter *adapter =
2586 E1000_DEV_PRIVATE(dev->data->dev_private);
2588 PMD_INIT_FUNC_TRACE();
2592 igbvf_dev_stop(dev);
2593 adapter->stopped = 1;
2594 igb_dev_free_queues(dev);
2597 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
2599 struct e1000_mbx_info *mbx = &hw->mbx;
2602 /* After set vlan, vlan strip will also be enabled in igb driver*/
2603 msgbuf[0] = E1000_VF_SET_VLAN;
2605 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
2607 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
2609 return (mbx->ops.write_posted(hw, msgbuf, 2, 0));
2612 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
2614 struct e1000_hw *hw =
2615 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2616 struct e1000_vfta * shadow_vfta =
2617 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2618 int i = 0, j = 0, vfta = 0, mask = 1;
2620 for (i = 0; i < IGB_VFTA_SIZE; i++){
2621 vfta = shadow_vfta->vfta[i];
2624 for (j = 0; j < 32; j++){
2627 (uint16_t)((i<<5)+j), on);
2636 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2638 struct e1000_hw *hw =
2639 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2640 struct e1000_vfta * shadow_vfta =
2641 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2642 uint32_t vid_idx = 0;
2643 uint32_t vid_bit = 0;
2646 PMD_INIT_FUNC_TRACE();
2648 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
2649 ret = igbvf_set_vfta(hw, vlan_id, !!on);
2651 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
2654 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
2655 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
2657 /*Save what we set and retore it after device reset*/
2659 shadow_vfta->vfta[vid_idx] |= vid_bit;
2661 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
2667 igbvf_default_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *addr)
2669 struct e1000_hw *hw =
2670 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2672 /* index is not used by rar_set() */
2673 hw->mac.ops.rar_set(hw, (void *)addr, 0);
2678 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
2679 struct rte_eth_rss_reta_entry64 *reta_conf,
2684 uint16_t idx, shift;
2685 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2687 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2688 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2689 "(%d) doesn't match the number hardware can supported "
2690 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2694 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
2695 idx = i / RTE_RETA_GROUP_SIZE;
2696 shift = i % RTE_RETA_GROUP_SIZE;
2697 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2701 if (mask == IGB_4_BIT_MASK)
2704 r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
2705 for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
2706 if (mask & (0x1 << j))
2707 reta |= reta_conf[idx].reta[shift + j] <<
2710 reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
2712 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
2719 eth_igb_rss_reta_query(struct rte_eth_dev *dev,
2720 struct rte_eth_rss_reta_entry64 *reta_conf,
2725 uint16_t idx, shift;
2726 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2728 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2729 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2730 "(%d) doesn't match the number hardware can supported "
2731 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2735 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
2736 idx = i / RTE_RETA_GROUP_SIZE;
2737 shift = i % RTE_RETA_GROUP_SIZE;
2738 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2742 reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
2743 for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
2744 if (mask & (0x1 << j))
2745 reta_conf[idx].reta[shift + j] =
2746 ((reta >> (CHAR_BIT * j)) &
2754 #define MAC_TYPE_FILTER_SUP(type) do {\
2755 if ((type) != e1000_82580 && (type) != e1000_i350 &&\
2756 (type) != e1000_82576)\
2761 eth_igb_syn_filter_set(struct rte_eth_dev *dev,
2762 struct rte_eth_syn_filter *filter,
2765 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2766 uint32_t synqf, rfctl;
2768 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
2771 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
2774 if (synqf & E1000_SYN_FILTER_ENABLE)
2777 synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
2778 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
2780 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
2781 if (filter->hig_pri)
2782 rfctl |= E1000_RFCTL_SYNQFP;
2784 rfctl &= ~E1000_RFCTL_SYNQFP;
2786 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
2788 if (!(synqf & E1000_SYN_FILTER_ENABLE))
2793 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
2794 E1000_WRITE_FLUSH(hw);
2799 eth_igb_syn_filter_get(struct rte_eth_dev *dev,
2800 struct rte_eth_syn_filter *filter)
2802 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2803 uint32_t synqf, rfctl;
2805 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
2806 if (synqf & E1000_SYN_FILTER_ENABLE) {
2807 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
2808 filter->hig_pri = (rfctl & E1000_RFCTL_SYNQFP) ? 1 : 0;
2809 filter->queue = (uint8_t)((synqf & E1000_SYN_FILTER_QUEUE) >>
2810 E1000_SYN_FILTER_QUEUE_SHIFT);
2818 eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
2819 enum rte_filter_op filter_op,
2822 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2825 MAC_TYPE_FILTER_SUP(hw->mac.type);
2827 if (filter_op == RTE_ETH_FILTER_NOP)
2831 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
2836 switch (filter_op) {
2837 case RTE_ETH_FILTER_ADD:
2838 ret = eth_igb_syn_filter_set(dev,
2839 (struct rte_eth_syn_filter *)arg,
2842 case RTE_ETH_FILTER_DELETE:
2843 ret = eth_igb_syn_filter_set(dev,
2844 (struct rte_eth_syn_filter *)arg,
2847 case RTE_ETH_FILTER_GET:
2848 ret = eth_igb_syn_filter_get(dev,
2849 (struct rte_eth_syn_filter *)arg);
2852 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
2860 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
2861 if ((type) != e1000_82580 && (type) != e1000_i350)\
2865 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
2867 ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
2868 struct e1000_2tuple_filter_info *filter_info)
2870 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
2872 if (filter->priority > E1000_2TUPLE_MAX_PRI)
2873 return -EINVAL; /* filter index is out of range. */
2874 if (filter->tcp_flags > TCP_FLAG_ALL)
2875 return -EINVAL; /* flags is invalid. */
2877 switch (filter->dst_port_mask) {
2879 filter_info->dst_port_mask = 0;
2880 filter_info->dst_port = filter->dst_port;
2883 filter_info->dst_port_mask = 1;
2886 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
2890 switch (filter->proto_mask) {
2892 filter_info->proto_mask = 0;
2893 filter_info->proto = filter->proto;
2896 filter_info->proto_mask = 1;
2899 PMD_DRV_LOG(ERR, "invalid protocol mask.");
2903 filter_info->priority = (uint8_t)filter->priority;
2904 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
2905 filter_info->tcp_flags = filter->tcp_flags;
2907 filter_info->tcp_flags = 0;
2912 static inline struct e1000_2tuple_filter *
2913 igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
2914 struct e1000_2tuple_filter_info *key)
2916 struct e1000_2tuple_filter *it;
2918 TAILQ_FOREACH(it, filter_list, entries) {
2919 if (memcmp(key, &it->filter_info,
2920 sizeof(struct e1000_2tuple_filter_info)) == 0) {
2928 * igb_add_2tuple_filter - add a 2tuple filter
2931 * dev: Pointer to struct rte_eth_dev.
2932 * ntuple_filter: ponter to the filter that will be added.
2935 * - On success, zero.
2936 * - On failure, a negative value.
2939 igb_add_2tuple_filter(struct rte_eth_dev *dev,
2940 struct rte_eth_ntuple_filter *ntuple_filter)
2942 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2943 struct e1000_filter_info *filter_info =
2944 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
2945 struct e1000_2tuple_filter *filter;
2946 uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
2947 uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
2950 filter = rte_zmalloc("e1000_2tuple_filter",
2951 sizeof(struct e1000_2tuple_filter), 0);
2955 ret = ntuple_filter_to_2tuple(ntuple_filter,
2956 &filter->filter_info);
2961 if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
2962 &filter->filter_info) != NULL) {
2963 PMD_DRV_LOG(ERR, "filter exists.");
2967 filter->queue = ntuple_filter->queue;
2970 * look for an unused 2tuple filter index,
2971 * and insert the filter to list.
2973 for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
2974 if (!(filter_info->twotuple_mask & (1 << i))) {
2975 filter_info->twotuple_mask |= 1 << i;
2977 TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
2983 if (i >= E1000_MAX_TTQF_FILTERS) {
2984 PMD_DRV_LOG(ERR, "2tuple filters are full.");
2989 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
2990 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
2991 imir |= E1000_IMIR_PORT_BP;
2993 imir &= ~E1000_IMIR_PORT_BP;
2995 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
2997 ttqf |= E1000_TTQF_QUEUE_ENABLE;
2998 ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
2999 ttqf |= (uint32_t)(filter->filter_info.proto & E1000_TTQF_PROTOCOL_MASK);
3000 if (filter->filter_info.proto_mask == 0)
3001 ttqf &= ~E1000_TTQF_MASK_ENABLE;
3003 /* tcp flags bits setting. */
3004 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3005 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3006 imir_ext |= E1000_IMIREXT_CTRL_URG;
3007 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3008 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3009 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3010 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3011 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3012 imir_ext |= E1000_IMIREXT_CTRL_RST;
3013 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3014 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3015 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3016 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3018 imir_ext |= E1000_IMIREXT_CTRL_BP;
3019 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3020 E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
3021 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3026 * igb_remove_2tuple_filter - remove a 2tuple filter
3029 * dev: Pointer to struct rte_eth_dev.
3030 * ntuple_filter: ponter to the filter that will be removed.
3033 * - On success, zero.
3034 * - On failure, a negative value.
3037 igb_remove_2tuple_filter(struct rte_eth_dev *dev,
3038 struct rte_eth_ntuple_filter *ntuple_filter)
3040 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3041 struct e1000_filter_info *filter_info =
3042 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3043 struct e1000_2tuple_filter_info filter_2tuple;
3044 struct e1000_2tuple_filter *filter;
3047 memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
3048 ret = ntuple_filter_to_2tuple(ntuple_filter,
3053 filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3055 if (filter == NULL) {
3056 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3060 filter_info->twotuple_mask &= ~(1 << filter->index);
3061 TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
3064 E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
3065 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3066 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3070 static inline struct e1000_flex_filter *
3071 eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
3072 struct e1000_flex_filter_info *key)
3074 struct e1000_flex_filter *it;
3076 TAILQ_FOREACH(it, filter_list, entries) {
3077 if (memcmp(key, &it->filter_info,
3078 sizeof(struct e1000_flex_filter_info)) == 0)
3086 eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
3087 struct rte_eth_flex_filter *filter,
3090 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3091 struct e1000_filter_info *filter_info =
3092 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3093 struct e1000_flex_filter *flex_filter, *it;
3094 uint32_t wufc, queueing, mask;
3096 uint8_t shift, i, j = 0;
3098 flex_filter = rte_zmalloc("e1000_flex_filter",
3099 sizeof(struct e1000_flex_filter), 0);
3100 if (flex_filter == NULL)
3103 flex_filter->filter_info.len = filter->len;
3104 flex_filter->filter_info.priority = filter->priority;
3105 memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
3106 for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
3108 /* reverse bits in flex filter's mask*/
3109 for (shift = 0; shift < CHAR_BIT; shift++) {
3110 if (filter->mask[i] & (0x01 << shift))
3111 mask |= (0x80 >> shift);
3113 flex_filter->filter_info.mask[i] = mask;
3116 wufc = E1000_READ_REG(hw, E1000_WUFC);
3117 if (flex_filter->index < E1000_MAX_FHFT)
3118 reg_off = E1000_FHFT(flex_filter->index);
3120 reg_off = E1000_FHFT_EXT(flex_filter->index - E1000_MAX_FHFT);
3123 if (eth_igb_flex_filter_lookup(&filter_info->flex_list,
3124 &flex_filter->filter_info) != NULL) {
3125 PMD_DRV_LOG(ERR, "filter exists.");
3126 rte_free(flex_filter);
3129 flex_filter->queue = filter->queue;
3131 * look for an unused flex filter index
3132 * and insert the filter into the list.
3134 for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
3135 if (!(filter_info->flex_mask & (1 << i))) {
3136 filter_info->flex_mask |= 1 << i;
3137 flex_filter->index = i;
3138 TAILQ_INSERT_TAIL(&filter_info->flex_list,
3144 if (i >= E1000_MAX_FLEX_FILTERS) {
3145 PMD_DRV_LOG(ERR, "flex filters are full.");
3146 rte_free(flex_filter);
3150 E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
3151 (E1000_WUFC_FLX0 << flex_filter->index));
3152 queueing = filter->len |
3153 (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
3154 (filter->priority << E1000_FHFT_QUEUEING_PRIO_SHIFT);
3155 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
3157 for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
3158 E1000_WRITE_REG(hw, reg_off,
3159 flex_filter->filter_info.dwords[j]);
3160 reg_off += sizeof(uint32_t);
3161 E1000_WRITE_REG(hw, reg_off,
3162 flex_filter->filter_info.dwords[++j]);
3163 reg_off += sizeof(uint32_t);
3164 E1000_WRITE_REG(hw, reg_off,
3165 (uint32_t)flex_filter->filter_info.mask[i]);
3166 reg_off += sizeof(uint32_t) * 2;
3170 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
3171 &flex_filter->filter_info);
3173 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3174 rte_free(flex_filter);
3178 for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
3179 E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
3180 E1000_WRITE_REG(hw, E1000_WUFC, wufc &
3181 (~(E1000_WUFC_FLX0 << it->index)));
3183 filter_info->flex_mask &= ~(1 << it->index);
3184 TAILQ_REMOVE(&filter_info->flex_list, it, entries);
3186 rte_free(flex_filter);
3193 eth_igb_get_flex_filter(struct rte_eth_dev *dev,
3194 struct rte_eth_flex_filter *filter)
3196 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3197 struct e1000_filter_info *filter_info =
3198 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3199 struct e1000_flex_filter flex_filter, *it;
3200 uint32_t wufc, queueing, wufc_en = 0;
3202 memset(&flex_filter, 0, sizeof(struct e1000_flex_filter));
3203 flex_filter.filter_info.len = filter->len;
3204 flex_filter.filter_info.priority = filter->priority;
3205 memcpy(flex_filter.filter_info.dwords, filter->bytes, filter->len);
3206 memcpy(flex_filter.filter_info.mask, filter->mask,
3207 RTE_ALIGN(filter->len, sizeof(char)) / sizeof(char));
3209 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
3210 &flex_filter.filter_info);
3212 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3216 wufc = E1000_READ_REG(hw, E1000_WUFC);
3217 wufc_en = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << it->index);
3219 if ((wufc & wufc_en) == wufc_en) {
3220 uint32_t reg_off = 0;
3221 if (it->index < E1000_MAX_FHFT)
3222 reg_off = E1000_FHFT(it->index);
3224 reg_off = E1000_FHFT_EXT(it->index - E1000_MAX_FHFT);
3226 queueing = E1000_READ_REG(hw,
3227 reg_off + E1000_FHFT_QUEUEING_OFFSET);
3228 filter->len = queueing & E1000_FHFT_QUEUEING_LEN;
3229 filter->priority = (queueing & E1000_FHFT_QUEUEING_PRIO) >>
3230 E1000_FHFT_QUEUEING_PRIO_SHIFT;
3231 filter->queue = (queueing & E1000_FHFT_QUEUEING_QUEUE) >>
3232 E1000_FHFT_QUEUEING_QUEUE_SHIFT;
3239 eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
3240 enum rte_filter_op filter_op,
3243 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3244 struct rte_eth_flex_filter *filter;
3247 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
3249 if (filter_op == RTE_ETH_FILTER_NOP)
3253 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3258 filter = (struct rte_eth_flex_filter *)arg;
3259 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN
3260 || filter->len % sizeof(uint64_t) != 0) {
3261 PMD_DRV_LOG(ERR, "filter's length is out of range");
3264 if (filter->priority > E1000_MAX_FLEX_FILTER_PRI) {
3265 PMD_DRV_LOG(ERR, "filter's priority is out of range");
3269 switch (filter_op) {
3270 case RTE_ETH_FILTER_ADD:
3271 ret = eth_igb_add_del_flex_filter(dev, filter, TRUE);
3273 case RTE_ETH_FILTER_DELETE:
3274 ret = eth_igb_add_del_flex_filter(dev, filter, FALSE);
3276 case RTE_ETH_FILTER_GET:
3277 ret = eth_igb_get_flex_filter(dev, filter);
3280 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
3288 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
3290 ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
3291 struct e1000_5tuple_filter_info *filter_info)
3293 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
3295 if (filter->priority > E1000_2TUPLE_MAX_PRI)
3296 return -EINVAL; /* filter index is out of range. */
3297 if (filter->tcp_flags > TCP_FLAG_ALL)
3298 return -EINVAL; /* flags is invalid. */
3300 switch (filter->dst_ip_mask) {
3302 filter_info->dst_ip_mask = 0;
3303 filter_info->dst_ip = filter->dst_ip;
3306 filter_info->dst_ip_mask = 1;
3309 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
3313 switch (filter->src_ip_mask) {
3315 filter_info->src_ip_mask = 0;
3316 filter_info->src_ip = filter->src_ip;
3319 filter_info->src_ip_mask = 1;
3322 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
3326 switch (filter->dst_port_mask) {
3328 filter_info->dst_port_mask = 0;
3329 filter_info->dst_port = filter->dst_port;
3332 filter_info->dst_port_mask = 1;
3335 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3339 switch (filter->src_port_mask) {
3341 filter_info->src_port_mask = 0;
3342 filter_info->src_port = filter->src_port;
3345 filter_info->src_port_mask = 1;
3348 PMD_DRV_LOG(ERR, "invalid src_port mask.");
3352 switch (filter->proto_mask) {
3354 filter_info->proto_mask = 0;
3355 filter_info->proto = filter->proto;
3358 filter_info->proto_mask = 1;
3361 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3365 filter_info->priority = (uint8_t)filter->priority;
3366 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3367 filter_info->tcp_flags = filter->tcp_flags;
3369 filter_info->tcp_flags = 0;
3374 static inline struct e1000_5tuple_filter *
3375 igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
3376 struct e1000_5tuple_filter_info *key)
3378 struct e1000_5tuple_filter *it;
3380 TAILQ_FOREACH(it, filter_list, entries) {
3381 if (memcmp(key, &it->filter_info,
3382 sizeof(struct e1000_5tuple_filter_info)) == 0) {
3390 * igb_add_5tuple_filter_82576 - add a 5tuple filter
3393 * dev: Pointer to struct rte_eth_dev.
3394 * ntuple_filter: ponter to the filter that will be added.
3397 * - On success, zero.
3398 * - On failure, a negative value.
3401 igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
3402 struct rte_eth_ntuple_filter *ntuple_filter)
3404 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3405 struct e1000_filter_info *filter_info =
3406 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3407 struct e1000_5tuple_filter *filter;
3408 uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
3409 uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3413 filter = rte_zmalloc("e1000_5tuple_filter",
3414 sizeof(struct e1000_5tuple_filter), 0);
3418 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3419 &filter->filter_info);
3425 if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
3426 &filter->filter_info) != NULL) {
3427 PMD_DRV_LOG(ERR, "filter exists.");
3431 filter->queue = ntuple_filter->queue;
3434 * look for an unused 5tuple filter index,
3435 * and insert the filter to list.
3437 for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
3438 if (!(filter_info->fivetuple_mask & (1 << i))) {
3439 filter_info->fivetuple_mask |= 1 << i;
3441 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
3447 if (i >= E1000_MAX_FTQF_FILTERS) {
3448 PMD_DRV_LOG(ERR, "5tuple filters are full.");
3453 ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
3454 if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
3455 ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
3456 if (filter->filter_info.dst_ip_mask == 0)
3457 ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
3458 if (filter->filter_info.src_port_mask == 0)
3459 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
3460 if (filter->filter_info.proto_mask == 0)
3461 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
3462 ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
3463 E1000_FTQF_QUEUE_MASK;
3464 ftqf |= E1000_FTQF_QUEUE_ENABLE;
3465 E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
3466 E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
3467 E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
3469 spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
3470 E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
3472 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3473 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3474 imir |= E1000_IMIR_PORT_BP;
3476 imir &= ~E1000_IMIR_PORT_BP;
3477 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3479 /* tcp flags bits setting. */
3480 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3481 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3482 imir_ext |= E1000_IMIREXT_CTRL_URG;
3483 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3484 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3485 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3486 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3487 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3488 imir_ext |= E1000_IMIREXT_CTRL_RST;
3489 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3490 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3491 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3492 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3494 imir_ext |= E1000_IMIREXT_CTRL_BP;
3495 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3496 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3501 * igb_remove_5tuple_filter_82576 - remove a 5tuple filter
3504 * dev: Pointer to struct rte_eth_dev.
3505 * ntuple_filter: ponter to the filter that will be removed.
3508 * - On success, zero.
3509 * - On failure, a negative value.
3512 igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
3513 struct rte_eth_ntuple_filter *ntuple_filter)
3515 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3516 struct e1000_filter_info *filter_info =
3517 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3518 struct e1000_5tuple_filter_info filter_5tuple;
3519 struct e1000_5tuple_filter *filter;
3522 memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
3523 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3528 filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
3530 if (filter == NULL) {
3531 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3535 filter_info->fivetuple_mask &= ~(1 << filter->index);
3536 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
3539 E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
3540 E1000_FTQF_VF_BP | E1000_FTQF_MASK);
3541 E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
3542 E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
3543 E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
3544 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3545 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3550 eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
3553 struct e1000_hw *hw;
3554 struct rte_eth_dev_info dev_info;
3555 uint32_t frame_size = mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN +
3558 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3560 #ifdef RTE_LIBRTE_82571_SUPPORT
3561 /* XXX: not bigger than max_rx_pktlen */
3562 if (hw->mac.type == e1000_82571)
3565 eth_igb_infos_get(dev, &dev_info);
3567 /* check that mtu is within the allowed range */
3568 if ((mtu < ETHER_MIN_MTU) ||
3569 (frame_size > dev_info.max_rx_pktlen))
3572 /* refuse mtu that requires the support of scattered packets when this
3573 * feature has not been enabled before. */
3574 if (!dev->data->scattered_rx &&
3575 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)
3578 rctl = E1000_READ_REG(hw, E1000_RCTL);
3580 /* switch to jumbo mode if needed */
3581 if (frame_size > ETHER_MAX_LEN) {
3582 dev->data->dev_conf.rxmode.jumbo_frame = 1;
3583 rctl |= E1000_RCTL_LPE;
3585 dev->data->dev_conf.rxmode.jumbo_frame = 0;
3586 rctl &= ~E1000_RCTL_LPE;
3588 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3590 /* update max frame size */
3591 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
3593 E1000_WRITE_REG(hw, E1000_RLPML,
3594 dev->data->dev_conf.rxmode.max_rx_pkt_len);
3600 * igb_add_del_ntuple_filter - add or delete a ntuple filter
3603 * dev: Pointer to struct rte_eth_dev.
3604 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
3605 * add: if true, add filter, if false, remove filter
3608 * - On success, zero.
3609 * - On failure, a negative value.
3612 igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
3613 struct rte_eth_ntuple_filter *ntuple_filter,
3616 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3619 switch (ntuple_filter->flags) {
3620 case RTE_5TUPLE_FLAGS:
3621 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3622 if (hw->mac.type != e1000_82576)
3625 ret = igb_add_5tuple_filter_82576(dev,
3628 ret = igb_remove_5tuple_filter_82576(dev,
3631 case RTE_2TUPLE_FLAGS:
3632 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3633 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
3636 ret = igb_add_2tuple_filter(dev, ntuple_filter);
3638 ret = igb_remove_2tuple_filter(dev, ntuple_filter);
3649 * igb_get_ntuple_filter - get a ntuple filter
3652 * dev: Pointer to struct rte_eth_dev.
3653 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
3656 * - On success, zero.
3657 * - On failure, a negative value.
3660 igb_get_ntuple_filter(struct rte_eth_dev *dev,
3661 struct rte_eth_ntuple_filter *ntuple_filter)
3663 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3664 struct e1000_filter_info *filter_info =
3665 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3666 struct e1000_5tuple_filter_info filter_5tuple;
3667 struct e1000_2tuple_filter_info filter_2tuple;
3668 struct e1000_5tuple_filter *p_5tuple_filter;
3669 struct e1000_2tuple_filter *p_2tuple_filter;
3672 switch (ntuple_filter->flags) {
3673 case RTE_5TUPLE_FLAGS:
3674 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3675 if (hw->mac.type != e1000_82576)
3677 memset(&filter_5tuple,
3679 sizeof(struct e1000_5tuple_filter_info));
3680 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3684 p_5tuple_filter = igb_5tuple_filter_lookup_82576(
3685 &filter_info->fivetuple_list,
3687 if (p_5tuple_filter == NULL) {
3688 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3691 ntuple_filter->queue = p_5tuple_filter->queue;
3693 case RTE_2TUPLE_FLAGS:
3694 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3695 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
3697 memset(&filter_2tuple,
3699 sizeof(struct e1000_2tuple_filter_info));
3700 ret = ntuple_filter_to_2tuple(ntuple_filter, &filter_2tuple);
3703 p_2tuple_filter = igb_2tuple_filter_lookup(
3704 &filter_info->twotuple_list,
3706 if (p_2tuple_filter == NULL) {
3707 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3710 ntuple_filter->queue = p_2tuple_filter->queue;
3721 * igb_ntuple_filter_handle - Handle operations for ntuple filter.
3722 * @dev: pointer to rte_eth_dev structure
3723 * @filter_op:operation will be taken.
3724 * @arg: a pointer to specific structure corresponding to the filter_op
3727 igb_ntuple_filter_handle(struct rte_eth_dev *dev,
3728 enum rte_filter_op filter_op,
3731 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3734 MAC_TYPE_FILTER_SUP(hw->mac.type);
3736 if (filter_op == RTE_ETH_FILTER_NOP)
3740 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3745 switch (filter_op) {
3746 case RTE_ETH_FILTER_ADD:
3747 ret = igb_add_del_ntuple_filter(dev,
3748 (struct rte_eth_ntuple_filter *)arg,
3751 case RTE_ETH_FILTER_DELETE:
3752 ret = igb_add_del_ntuple_filter(dev,
3753 (struct rte_eth_ntuple_filter *)arg,
3756 case RTE_ETH_FILTER_GET:
3757 ret = igb_get_ntuple_filter(dev,
3758 (struct rte_eth_ntuple_filter *)arg);
3761 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3769 igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
3774 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
3775 if (filter_info->ethertype_filters[i] == ethertype &&
3776 (filter_info->ethertype_mask & (1 << i)))
3783 igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
3788 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
3789 if (!(filter_info->ethertype_mask & (1 << i))) {
3790 filter_info->ethertype_mask |= 1 << i;
3791 filter_info->ethertype_filters[i] = ethertype;
3799 igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
3802 if (idx >= E1000_MAX_ETQF_FILTERS)
3804 filter_info->ethertype_mask &= ~(1 << idx);
3805 filter_info->ethertype_filters[idx] = 0;
3811 igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
3812 struct rte_eth_ethertype_filter *filter,
3815 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3816 struct e1000_filter_info *filter_info =
3817 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3821 if (filter->ether_type == ETHER_TYPE_IPv4 ||
3822 filter->ether_type == ETHER_TYPE_IPv6) {
3823 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
3824 " ethertype filter.", filter->ether_type);
3828 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
3829 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
3832 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
3833 PMD_DRV_LOG(ERR, "drop option is unsupported.");
3837 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
3838 if (ret >= 0 && add) {
3839 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
3840 filter->ether_type);
3843 if (ret < 0 && !add) {
3844 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
3845 filter->ether_type);
3850 ret = igb_ethertype_filter_insert(filter_info,
3851 filter->ether_type);
3853 PMD_DRV_LOG(ERR, "ethertype filters are full.");
3857 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
3858 etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
3859 etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
3861 ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
3865 E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
3866 E1000_WRITE_FLUSH(hw);
3872 igb_get_ethertype_filter(struct rte_eth_dev *dev,
3873 struct rte_eth_ethertype_filter *filter)
3875 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3876 struct e1000_filter_info *filter_info =
3877 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3881 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
3883 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
3884 filter->ether_type);
3888 etqf = E1000_READ_REG(hw, E1000_ETQF(ret));
3889 if (etqf & E1000_ETQF_FILTER_ENABLE) {
3890 filter->ether_type = etqf & E1000_ETQF_ETHERTYPE;
3892 filter->queue = (etqf & E1000_ETQF_QUEUE) >>
3893 E1000_ETQF_QUEUE_SHIFT;
3901 * igb_ethertype_filter_handle - Handle operations for ethertype filter.
3902 * @dev: pointer to rte_eth_dev structure
3903 * @filter_op:operation will be taken.
3904 * @arg: a pointer to specific structure corresponding to the filter_op
3907 igb_ethertype_filter_handle(struct rte_eth_dev *dev,
3908 enum rte_filter_op filter_op,
3911 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3914 MAC_TYPE_FILTER_SUP(hw->mac.type);
3916 if (filter_op == RTE_ETH_FILTER_NOP)
3920 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3925 switch (filter_op) {
3926 case RTE_ETH_FILTER_ADD:
3927 ret = igb_add_del_ethertype_filter(dev,
3928 (struct rte_eth_ethertype_filter *)arg,
3931 case RTE_ETH_FILTER_DELETE:
3932 ret = igb_add_del_ethertype_filter(dev,
3933 (struct rte_eth_ethertype_filter *)arg,
3936 case RTE_ETH_FILTER_GET:
3937 ret = igb_get_ethertype_filter(dev,
3938 (struct rte_eth_ethertype_filter *)arg);
3941 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3949 eth_igb_filter_ctrl(struct rte_eth_dev *dev,
3950 enum rte_filter_type filter_type,
3951 enum rte_filter_op filter_op,
3956 switch (filter_type) {
3957 case RTE_ETH_FILTER_NTUPLE:
3958 ret = igb_ntuple_filter_handle(dev, filter_op, arg);
3960 case RTE_ETH_FILTER_ETHERTYPE:
3961 ret = igb_ethertype_filter_handle(dev, filter_op, arg);
3963 case RTE_ETH_FILTER_SYN:
3964 ret = eth_igb_syn_filter_handle(dev, filter_op, arg);
3966 case RTE_ETH_FILTER_FLEXIBLE:
3967 ret = eth_igb_flex_filter_handle(dev, filter_op, arg);
3970 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
3979 eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
3980 struct ether_addr *mc_addr_set,
3981 uint32_t nb_mc_addr)
3983 struct e1000_hw *hw;
3985 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3986 e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
3991 igb_timesync_enable(struct rte_eth_dev *dev)
3993 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3997 /* Enable system time for it isn't on by default. */
3998 tsauxc = E1000_READ_REG(hw, E1000_TSAUXC);
3999 tsauxc &= ~E1000_TSAUXC_DISABLE_SYSTIME;
4000 E1000_WRITE_REG(hw, E1000_TSAUXC, tsauxc);
4002 /* Start incrementing the register used to timestamp PTP packets. */
4003 E1000_WRITE_REG(hw, E1000_TIMINCA, E1000_TIMINCA_INIT);
4005 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
4006 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588),
4008 E1000_ETQF_FILTER_ENABLE |
4011 /* Enable timestamping of received PTP packets. */
4012 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4013 tsync_ctl |= E1000_TSYNCRXCTL_ENABLED;
4014 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
4016 /* Enable Timestamping of transmitted PTP packets. */
4017 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4018 tsync_ctl |= E1000_TSYNCTXCTL_ENABLED;
4019 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
4025 igb_timesync_disable(struct rte_eth_dev *dev)
4027 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4030 /* Disable timestamping of transmitted PTP packets. */
4031 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4032 tsync_ctl &= ~E1000_TSYNCTXCTL_ENABLED;
4033 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
4035 /* Disable timestamping of received PTP packets. */
4036 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4037 tsync_ctl &= ~E1000_TSYNCRXCTL_ENABLED;
4038 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
4040 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
4041 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588), 0);
4043 /* Stop incrementating the System Time registers. */
4044 E1000_WRITE_REG(hw, E1000_TIMINCA, 0);
4050 igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
4051 struct timespec *timestamp,
4052 uint32_t flags __rte_unused)
4054 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4055 uint32_t tsync_rxctl;
4059 tsync_rxctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4060 if ((tsync_rxctl & E1000_TSYNCRXCTL_VALID) == 0)
4063 rx_stmpl = E1000_READ_REG(hw, E1000_RXSTMPL);
4064 rx_stmph = E1000_READ_REG(hw, E1000_RXSTMPH);
4066 timestamp->tv_sec = (uint64_t)(((uint64_t)rx_stmph << 32) | rx_stmpl);
4067 timestamp->tv_nsec = 0;
4073 igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
4074 struct timespec *timestamp)
4076 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4077 uint32_t tsync_txctl;
4081 tsync_txctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4082 if ((tsync_txctl & E1000_TSYNCTXCTL_VALID) == 0)
4085 tx_stmpl = E1000_READ_REG(hw, E1000_TXSTMPL);
4086 tx_stmph = E1000_READ_REG(hw, E1000_TXSTMPH);
4088 timestamp->tv_sec = (uint64_t)(((uint64_t)tx_stmph << 32) | tx_stmpl);
4089 timestamp->tv_nsec = 0;
4095 eth_igb_get_reg_length(struct rte_eth_dev *dev __rte_unused)
4099 const struct reg_info *reg_group;
4101 while ((reg_group = igb_regs[g_ind++]))
4102 count += igb_reg_group_count(reg_group);
4108 igbvf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
4112 const struct reg_info *reg_group;
4114 while ((reg_group = igbvf_regs[g_ind++]))
4115 count += igb_reg_group_count(reg_group);
4121 eth_igb_get_regs(struct rte_eth_dev *dev,
4122 struct rte_dev_reg_info *regs)
4124 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4125 uint32_t *data = regs->data;
4128 const struct reg_info *reg_group;
4130 /* Support only full register dump */
4131 if ((regs->length == 0) ||
4132 (regs->length == (uint32_t)eth_igb_get_reg_length(dev))) {
4133 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
4135 while ((reg_group = igb_regs[g_ind++]))
4136 count += igb_read_regs_group(dev, &data[count],
4145 igbvf_get_regs(struct rte_eth_dev *dev,
4146 struct rte_dev_reg_info *regs)
4148 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4149 uint32_t *data = regs->data;
4152 const struct reg_info *reg_group;
4154 /* Support only full register dump */
4155 if ((regs->length == 0) ||
4156 (regs->length == (uint32_t)igbvf_get_reg_length(dev))) {
4157 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
4159 while ((reg_group = igbvf_regs[g_ind++]))
4160 count += igb_read_regs_group(dev, &data[count],
4169 eth_igb_get_eeprom_length(struct rte_eth_dev *dev)
4171 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4173 /* Return unit is byte count */
4174 return hw->nvm.word_size * 2;
4178 eth_igb_get_eeprom(struct rte_eth_dev *dev,
4179 struct rte_dev_eeprom_info *in_eeprom)
4181 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4182 struct e1000_nvm_info *nvm = &hw->nvm;
4183 uint16_t *data = in_eeprom->data;
4186 first = in_eeprom->offset >> 1;
4187 length = in_eeprom->length >> 1;
4188 if ((first >= hw->nvm.word_size) ||
4189 ((first + length) >= hw->nvm.word_size))
4192 in_eeprom->magic = hw->vendor_id |
4193 ((uint32_t)hw->device_id << 16);
4195 if ((nvm->ops.read) == NULL)
4198 return nvm->ops.read(hw, first, length, data);
4202 eth_igb_set_eeprom(struct rte_eth_dev *dev,
4203 struct rte_dev_eeprom_info *in_eeprom)
4205 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4206 struct e1000_nvm_info *nvm = &hw->nvm;
4207 uint16_t *data = in_eeprom->data;
4210 first = in_eeprom->offset >> 1;
4211 length = in_eeprom->length >> 1;
4212 if ((first >= hw->nvm.word_size) ||
4213 ((first + length) >= hw->nvm.word_size))
4216 in_eeprom->magic = (uint32_t)hw->vendor_id |
4217 ((uint32_t)hw->device_id << 16);
4219 if ((nvm->ops.write) == NULL)
4221 return nvm->ops.write(hw, first, length, data);
4224 static struct rte_driver pmd_igb_drv = {
4226 .init = rte_igb_pmd_init,
4229 static struct rte_driver pmd_igbvf_drv = {
4231 .init = rte_igbvf_pmd_init,
4235 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
4237 struct e1000_hw *hw =
4238 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4239 uint32_t mask = 1 << queue_id;
4241 E1000_WRITE_REG(hw, E1000_EIMC, mask);
4242 E1000_WRITE_FLUSH(hw);
4248 eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
4250 struct e1000_hw *hw =
4251 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4252 uint32_t mask = 1 << queue_id;
4255 regval = E1000_READ_REG(hw, E1000_EIMS);
4256 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
4257 E1000_WRITE_FLUSH(hw);
4259 rte_intr_enable(&dev->pci_dev->intr_handle);
4265 eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
4266 uint8_t index, uint8_t offset)
4268 uint32_t val = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
4271 val &= ~((uint32_t)0xFF << offset);
4273 /* write vector and valid bit */
4274 val |= (msix_vector | E1000_IVAR_VALID) << offset;
4276 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, val);
4280 eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
4281 uint8_t queue, uint8_t msix_vector)
4285 if (hw->mac.type == e1000_82575) {
4287 tmp = E1000_EICR_RX_QUEUE0 << queue;
4288 else if (direction == 1)
4289 tmp = E1000_EICR_TX_QUEUE0 << queue;
4290 E1000_WRITE_REG(hw, E1000_MSIXBM(msix_vector), tmp);
4291 } else if (hw->mac.type == e1000_82576) {
4292 if ((direction == 0) || (direction == 1))
4293 eth_igb_write_ivar(hw, msix_vector, queue & 0x7,
4294 ((queue & 0x8) << 1) +
4296 } else if ((hw->mac.type == e1000_82580) ||
4297 (hw->mac.type == e1000_i350) ||
4298 (hw->mac.type == e1000_i354) ||
4299 (hw->mac.type == e1000_i210) ||
4300 (hw->mac.type == e1000_i211)) {
4301 if ((direction == 0) || (direction == 1))
4302 eth_igb_write_ivar(hw, msix_vector,
4304 ((queue & 0x1) << 4) +
4309 /* Sets up the hardware to generate MSI-X interrupts properly
4311 * board private structure
4314 eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
4317 uint32_t tmpval, regval, intr_mask;
4318 struct e1000_hw *hw =
4319 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4321 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4323 /* won't configure msix register if no mapping is done
4324 * between intr vector and event fd
4326 if (!rte_intr_dp_is_en(intr_handle))
4329 /* set interrupt vector for other causes */
4330 if (hw->mac.type == e1000_82575) {
4331 tmpval = E1000_READ_REG(hw, E1000_CTRL_EXT);
4332 /* enable MSI-X PBA support */
4333 tmpval |= E1000_CTRL_EXT_PBA_CLR;
4335 /* Auto-Mask interrupts upon ICR read */
4336 tmpval |= E1000_CTRL_EXT_EIAME;
4337 tmpval |= E1000_CTRL_EXT_IRCA;
4339 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmpval);
4341 /* enable msix_other interrupt */
4342 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), 0, E1000_EIMS_OTHER);
4343 regval = E1000_READ_REG(hw, E1000_EIAC);
4344 E1000_WRITE_REG(hw, E1000_EIAC, regval | E1000_EIMS_OTHER);
4345 regval = E1000_READ_REG(hw, E1000_EIAM);
4346 E1000_WRITE_REG(hw, E1000_EIMS, regval | E1000_EIMS_OTHER);
4347 } else if ((hw->mac.type == e1000_82576) ||
4348 (hw->mac.type == e1000_82580) ||
4349 (hw->mac.type == e1000_i350) ||
4350 (hw->mac.type == e1000_i354) ||
4351 (hw->mac.type == e1000_i210) ||
4352 (hw->mac.type == e1000_i211)) {
4353 /* turn on MSI-X capability first */
4354 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
4355 E1000_GPIE_PBA | E1000_GPIE_EIAME |
4358 intr_mask = (1 << intr_handle->max_intr) - 1;
4359 regval = E1000_READ_REG(hw, E1000_EIAC);
4360 E1000_WRITE_REG(hw, E1000_EIAC, regval | intr_mask);
4362 /* enable msix_other interrupt */
4363 regval = E1000_READ_REG(hw, E1000_EIMS);
4364 E1000_WRITE_REG(hw, E1000_EIMS, regval | intr_mask);
4365 tmpval = (dev->data->nb_rx_queues | E1000_IVAR_VALID) << 8;
4366 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmpval);
4369 /* use EIAM to auto-mask when MSI-X interrupt
4370 * is asserted, this saves a register write for every interrupt
4372 intr_mask = (1 << intr_handle->nb_efd) - 1;
4373 regval = E1000_READ_REG(hw, E1000_EIAM);
4374 E1000_WRITE_REG(hw, E1000_EIAM, regval | intr_mask);
4376 for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
4377 eth_igb_assign_msix_vector(hw, 0, queue_id, vec);
4378 intr_handle->intr_vec[queue_id] = vec;
4379 if (vec < intr_handle->nb_efd - 1)
4383 E1000_WRITE_FLUSH(hw);
4386 PMD_REGISTER_DRIVER(pmd_igb_drv);
4387 PMD_REGISTER_DRIVER(pmd_igbvf_drv);