1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
11 #include <rte_string_fns.h>
12 #include <rte_common.h>
13 #include <rte_interrupts.h>
14 #include <rte_byteorder.h>
16 #include <rte_debug.h>
18 #include <rte_bus_pci.h>
19 #include <rte_ether.h>
20 #include <ethdev_driver.h>
21 #include <ethdev_pci.h>
22 #include <rte_memory.h>
24 #include <rte_malloc.h>
27 #include "e1000_logs.h"
28 #include "base/e1000_api.h"
29 #include "e1000_ethdev.h"
33 * Default values for port configuration
35 #define IGB_DEFAULT_RX_FREE_THRESH 32
37 #define IGB_DEFAULT_RX_PTHRESH ((hw->mac.type == e1000_i354) ? 12 : 8)
38 #define IGB_DEFAULT_RX_HTHRESH 8
39 #define IGB_DEFAULT_RX_WTHRESH ((hw->mac.type == e1000_82576) ? 1 : 4)
41 #define IGB_DEFAULT_TX_PTHRESH ((hw->mac.type == e1000_i354) ? 20 : 8)
42 #define IGB_DEFAULT_TX_HTHRESH 1
43 #define IGB_DEFAULT_TX_WTHRESH ((hw->mac.type == e1000_82576) ? 1 : 16)
45 /* Bit shift and mask */
46 #define IGB_4_BIT_WIDTH (CHAR_BIT / 2)
47 #define IGB_4_BIT_MASK RTE_LEN2MASK(IGB_4_BIT_WIDTH, uint8_t)
48 #define IGB_8_BIT_WIDTH CHAR_BIT
49 #define IGB_8_BIT_MASK UINT8_MAX
51 /* Additional timesync values. */
52 #define E1000_CYCLECOUNTER_MASK 0xffffffffffffffffULL
53 #define E1000_ETQF_FILTER_1588 3
54 #define IGB_82576_TSYNC_SHIFT 16
55 #define E1000_INCPERIOD_82576 (1 << E1000_TIMINCA_16NS_SHIFT)
56 #define E1000_INCVALUE_82576 (16 << IGB_82576_TSYNC_SHIFT)
57 #define E1000_TSAUXC_DISABLE_SYSTIME 0x80000000
59 #define E1000_VTIVAR_MISC 0x01740
60 #define E1000_VTIVAR_MISC_MASK 0xFF
61 #define E1000_VTIVAR_VALID 0x80
62 #define E1000_VTIVAR_MISC_MAILBOX 0
63 #define E1000_VTIVAR_MISC_INTR_MASK 0x3
65 /* External VLAN Enable bit mask */
66 #define E1000_CTRL_EXT_EXT_VLAN (1 << 26)
68 /* External VLAN Ether Type bit mask and shift */
69 #define E1000_VET_VET_EXT 0xFFFF0000
70 #define E1000_VET_VET_EXT_SHIFT 16
72 /* MSI-X other interrupt vector */
73 #define IGB_MSIX_OTHER_INTR_VEC 0
75 static int eth_igb_configure(struct rte_eth_dev *dev);
76 static int eth_igb_start(struct rte_eth_dev *dev);
77 static int eth_igb_stop(struct rte_eth_dev *dev);
78 static int eth_igb_dev_set_link_up(struct rte_eth_dev *dev);
79 static int eth_igb_dev_set_link_down(struct rte_eth_dev *dev);
80 static int eth_igb_close(struct rte_eth_dev *dev);
81 static int eth_igb_reset(struct rte_eth_dev *dev);
82 static int eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
83 static int eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
84 static int eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
85 static int eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
86 static int eth_igb_link_update(struct rte_eth_dev *dev,
87 int wait_to_complete);
88 static int eth_igb_stats_get(struct rte_eth_dev *dev,
89 struct rte_eth_stats *rte_stats);
90 static int eth_igb_xstats_get(struct rte_eth_dev *dev,
91 struct rte_eth_xstat *xstats, unsigned n);
92 static int eth_igb_xstats_get_by_id(struct rte_eth_dev *dev,
94 uint64_t *values, unsigned int n);
95 static int eth_igb_xstats_get_names(struct rte_eth_dev *dev,
96 struct rte_eth_xstat_name *xstats_names,
98 static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
99 const uint64_t *ids, struct rte_eth_xstat_name *xstats_names,
101 static int eth_igb_stats_reset(struct rte_eth_dev *dev);
102 static int eth_igb_xstats_reset(struct rte_eth_dev *dev);
103 static int eth_igb_fw_version_get(struct rte_eth_dev *dev,
104 char *fw_version, size_t fw_size);
105 static int eth_igb_infos_get(struct rte_eth_dev *dev,
106 struct rte_eth_dev_info *dev_info);
107 static const uint32_t *eth_igb_supported_ptypes_get(struct rte_eth_dev *dev);
108 static int eth_igbvf_infos_get(struct rte_eth_dev *dev,
109 struct rte_eth_dev_info *dev_info);
110 static int eth_igb_flow_ctrl_get(struct rte_eth_dev *dev,
111 struct rte_eth_fc_conf *fc_conf);
112 static int eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
113 struct rte_eth_fc_conf *fc_conf);
114 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on);
115 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
116 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
117 static int eth_igb_interrupt_action(struct rte_eth_dev *dev,
118 struct rte_intr_handle *handle);
119 static void eth_igb_interrupt_handler(void *param);
120 static int igb_hardware_init(struct e1000_hw *hw);
121 static void igb_hw_control_acquire(struct e1000_hw *hw);
122 static void igb_hw_control_release(struct e1000_hw *hw);
123 static void igb_init_manageability(struct e1000_hw *hw);
124 static void igb_release_manageability(struct e1000_hw *hw);
126 static int eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
128 static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
129 uint16_t vlan_id, int on);
130 static int eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
131 enum rte_vlan_type vlan_type,
133 static int eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
135 static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
136 static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
137 static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
138 static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
139 static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
140 static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
142 static int eth_igb_led_on(struct rte_eth_dev *dev);
143 static int eth_igb_led_off(struct rte_eth_dev *dev);
145 static void igb_intr_disable(struct rte_eth_dev *dev);
146 static int igb_get_rx_buffer_size(struct e1000_hw *hw);
147 static int eth_igb_rar_set(struct rte_eth_dev *dev,
148 struct rte_ether_addr *mac_addr,
149 uint32_t index, uint32_t pool);
150 static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
151 static int eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
152 struct rte_ether_addr *addr);
154 static void igbvf_intr_disable(struct e1000_hw *hw);
155 static int igbvf_dev_configure(struct rte_eth_dev *dev);
156 static int igbvf_dev_start(struct rte_eth_dev *dev);
157 static int igbvf_dev_stop(struct rte_eth_dev *dev);
158 static int igbvf_dev_close(struct rte_eth_dev *dev);
159 static int igbvf_promiscuous_enable(struct rte_eth_dev *dev);
160 static int igbvf_promiscuous_disable(struct rte_eth_dev *dev);
161 static int igbvf_allmulticast_enable(struct rte_eth_dev *dev);
162 static int igbvf_allmulticast_disable(struct rte_eth_dev *dev);
163 static int eth_igbvf_link_update(struct e1000_hw *hw);
164 static int eth_igbvf_stats_get(struct rte_eth_dev *dev,
165 struct rte_eth_stats *rte_stats);
166 static int eth_igbvf_xstats_get(struct rte_eth_dev *dev,
167 struct rte_eth_xstat *xstats, unsigned n);
168 static int eth_igbvf_xstats_get_names(struct rte_eth_dev *dev,
169 struct rte_eth_xstat_name *xstats_names,
171 static int eth_igbvf_stats_reset(struct rte_eth_dev *dev);
172 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
173 uint16_t vlan_id, int on);
174 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
175 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
176 static int igbvf_default_mac_addr_set(struct rte_eth_dev *dev,
177 struct rte_ether_addr *addr);
178 static int igbvf_get_reg_length(struct rte_eth_dev *dev);
179 static int igbvf_get_regs(struct rte_eth_dev *dev,
180 struct rte_dev_reg_info *regs);
182 static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
183 struct rte_eth_rss_reta_entry64 *reta_conf,
185 static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
186 struct rte_eth_rss_reta_entry64 *reta_conf,
189 static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
190 struct rte_eth_ntuple_filter *ntuple_filter);
191 static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
192 struct rte_eth_ntuple_filter *ntuple_filter);
193 static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
194 struct rte_eth_ntuple_filter *ntuple_filter);
195 static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
196 struct rte_eth_ntuple_filter *ntuple_filter);
197 static int eth_igb_flow_ops_get(struct rte_eth_dev *dev,
198 const struct rte_flow_ops **ops);
199 static int eth_igb_get_reg_length(struct rte_eth_dev *dev);
200 static int eth_igb_get_regs(struct rte_eth_dev *dev,
201 struct rte_dev_reg_info *regs);
202 static int eth_igb_get_eeprom_length(struct rte_eth_dev *dev);
203 static int eth_igb_get_eeprom(struct rte_eth_dev *dev,
204 struct rte_dev_eeprom_info *eeprom);
205 static int eth_igb_set_eeprom(struct rte_eth_dev *dev,
206 struct rte_dev_eeprom_info *eeprom);
207 static int eth_igb_get_module_info(struct rte_eth_dev *dev,
208 struct rte_eth_dev_module_info *modinfo);
209 static int eth_igb_get_module_eeprom(struct rte_eth_dev *dev,
210 struct rte_dev_eeprom_info *info);
211 static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
212 struct rte_ether_addr *mc_addr_set,
213 uint32_t nb_mc_addr);
214 static int igb_timesync_enable(struct rte_eth_dev *dev);
215 static int igb_timesync_disable(struct rte_eth_dev *dev);
216 static int igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
217 struct timespec *timestamp,
219 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
220 struct timespec *timestamp);
221 static int igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
222 static int igb_timesync_read_time(struct rte_eth_dev *dev,
223 struct timespec *timestamp);
224 static int igb_timesync_write_time(struct rte_eth_dev *dev,
225 const struct timespec *timestamp);
226 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
228 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
230 static void eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
231 uint8_t queue, uint8_t msix_vector);
232 static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
233 uint8_t index, uint8_t offset);
234 static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
235 static void eth_igbvf_interrupt_handler(void *param);
236 static void igbvf_mbx_process(struct rte_eth_dev *dev);
237 static int igb_filter_restore(struct rte_eth_dev *dev);
240 * Define VF Stats MACRO for Non "cleared on read" register
242 #define UPDATE_VF_STAT(reg, last, cur) \
244 u32 latest = E1000_READ_REG(hw, reg); \
245 cur += (latest - last) & UINT_MAX; \
249 #define IGB_FC_PAUSE_TIME 0x0680
250 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
251 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
253 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
255 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
258 * The set of PCI devices this driver supports
260 static const struct rte_pci_id pci_id_igb_map[] = {
261 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576) },
262 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_FIBER) },
263 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES) },
264 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER) },
265 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER_ET2) },
266 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS) },
267 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS_SERDES) },
268 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES_QUAD) },
270 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_COPPER) },
271 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_FIBER_SERDES) },
272 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575GB_QUAD_COPPER) },
274 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER) },
275 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_FIBER) },
276 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SERDES) },
277 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SGMII) },
278 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER_DUAL) },
279 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_QUAD_FIBER) },
281 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_COPPER) },
282 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_FIBER) },
283 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SERDES) },
284 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SGMII) },
285 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_DA4) },
286 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER) },
287 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_OEM1) },
288 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_IT) },
289 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_FIBER) },
290 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES) },
291 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SGMII) },
292 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_FLASHLESS) },
293 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES_FLASHLESS) },
294 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I211_COPPER) },
295 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
296 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_SGMII) },
297 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
298 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SGMII) },
299 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SERDES) },
300 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_BACKPLANE) },
301 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SFP) },
302 { .vendor_id = 0, /* sentinel */ },
306 * The set of PCI devices this driver supports (for 82576&I350 VF)
308 static const struct rte_pci_id pci_id_igbvf_map[] = {
309 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF) },
310 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF_HV) },
311 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF) },
312 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF_HV) },
313 { .vendor_id = 0, /* sentinel */ },
316 static const struct rte_eth_desc_lim rx_desc_lim = {
317 .nb_max = E1000_MAX_RING_DESC,
318 .nb_min = E1000_MIN_RING_DESC,
319 .nb_align = IGB_RXD_ALIGN,
322 static const struct rte_eth_desc_lim tx_desc_lim = {
323 .nb_max = E1000_MAX_RING_DESC,
324 .nb_min = E1000_MIN_RING_DESC,
325 .nb_align = IGB_RXD_ALIGN,
326 .nb_seg_max = IGB_TX_MAX_SEG,
327 .nb_mtu_seg_max = IGB_TX_MAX_MTU_SEG,
330 static const struct eth_dev_ops eth_igb_ops = {
331 .dev_configure = eth_igb_configure,
332 .dev_start = eth_igb_start,
333 .dev_stop = eth_igb_stop,
334 .dev_set_link_up = eth_igb_dev_set_link_up,
335 .dev_set_link_down = eth_igb_dev_set_link_down,
336 .dev_close = eth_igb_close,
337 .dev_reset = eth_igb_reset,
338 .promiscuous_enable = eth_igb_promiscuous_enable,
339 .promiscuous_disable = eth_igb_promiscuous_disable,
340 .allmulticast_enable = eth_igb_allmulticast_enable,
341 .allmulticast_disable = eth_igb_allmulticast_disable,
342 .link_update = eth_igb_link_update,
343 .stats_get = eth_igb_stats_get,
344 .xstats_get = eth_igb_xstats_get,
345 .xstats_get_by_id = eth_igb_xstats_get_by_id,
346 .xstats_get_names_by_id = eth_igb_xstats_get_names_by_id,
347 .xstats_get_names = eth_igb_xstats_get_names,
348 .stats_reset = eth_igb_stats_reset,
349 .xstats_reset = eth_igb_xstats_reset,
350 .fw_version_get = eth_igb_fw_version_get,
351 .dev_infos_get = eth_igb_infos_get,
352 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
353 .mtu_set = eth_igb_mtu_set,
354 .vlan_filter_set = eth_igb_vlan_filter_set,
355 .vlan_tpid_set = eth_igb_vlan_tpid_set,
356 .vlan_offload_set = eth_igb_vlan_offload_set,
357 .rx_queue_setup = eth_igb_rx_queue_setup,
358 .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
359 .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
360 .rx_queue_release = eth_igb_rx_queue_release,
361 .tx_queue_setup = eth_igb_tx_queue_setup,
362 .tx_queue_release = eth_igb_tx_queue_release,
363 .tx_done_cleanup = eth_igb_tx_done_cleanup,
364 .dev_led_on = eth_igb_led_on,
365 .dev_led_off = eth_igb_led_off,
366 .flow_ctrl_get = eth_igb_flow_ctrl_get,
367 .flow_ctrl_set = eth_igb_flow_ctrl_set,
368 .mac_addr_add = eth_igb_rar_set,
369 .mac_addr_remove = eth_igb_rar_clear,
370 .mac_addr_set = eth_igb_default_mac_addr_set,
371 .reta_update = eth_igb_rss_reta_update,
372 .reta_query = eth_igb_rss_reta_query,
373 .rss_hash_update = eth_igb_rss_hash_update,
374 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
375 .flow_ops_get = eth_igb_flow_ops_get,
376 .set_mc_addr_list = eth_igb_set_mc_addr_list,
377 .rxq_info_get = igb_rxq_info_get,
378 .txq_info_get = igb_txq_info_get,
379 .timesync_enable = igb_timesync_enable,
380 .timesync_disable = igb_timesync_disable,
381 .timesync_read_rx_timestamp = igb_timesync_read_rx_timestamp,
382 .timesync_read_tx_timestamp = igb_timesync_read_tx_timestamp,
383 .get_reg = eth_igb_get_regs,
384 .get_eeprom_length = eth_igb_get_eeprom_length,
385 .get_eeprom = eth_igb_get_eeprom,
386 .set_eeprom = eth_igb_set_eeprom,
387 .get_module_info = eth_igb_get_module_info,
388 .get_module_eeprom = eth_igb_get_module_eeprom,
389 .timesync_adjust_time = igb_timesync_adjust_time,
390 .timesync_read_time = igb_timesync_read_time,
391 .timesync_write_time = igb_timesync_write_time,
395 * dev_ops for virtual function, bare necessities for basic vf
396 * operation have been implemented
398 static const struct eth_dev_ops igbvf_eth_dev_ops = {
399 .dev_configure = igbvf_dev_configure,
400 .dev_start = igbvf_dev_start,
401 .dev_stop = igbvf_dev_stop,
402 .dev_close = igbvf_dev_close,
403 .promiscuous_enable = igbvf_promiscuous_enable,
404 .promiscuous_disable = igbvf_promiscuous_disable,
405 .allmulticast_enable = igbvf_allmulticast_enable,
406 .allmulticast_disable = igbvf_allmulticast_disable,
407 .link_update = eth_igb_link_update,
408 .stats_get = eth_igbvf_stats_get,
409 .xstats_get = eth_igbvf_xstats_get,
410 .xstats_get_names = eth_igbvf_xstats_get_names,
411 .stats_reset = eth_igbvf_stats_reset,
412 .xstats_reset = eth_igbvf_stats_reset,
413 .vlan_filter_set = igbvf_vlan_filter_set,
414 .dev_infos_get = eth_igbvf_infos_get,
415 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
416 .rx_queue_setup = eth_igb_rx_queue_setup,
417 .rx_queue_release = eth_igb_rx_queue_release,
418 .tx_queue_setup = eth_igb_tx_queue_setup,
419 .tx_queue_release = eth_igb_tx_queue_release,
420 .tx_done_cleanup = eth_igb_tx_done_cleanup,
421 .set_mc_addr_list = eth_igb_set_mc_addr_list,
422 .rxq_info_get = igb_rxq_info_get,
423 .txq_info_get = igb_txq_info_get,
424 .mac_addr_set = igbvf_default_mac_addr_set,
425 .get_reg = igbvf_get_regs,
428 /* store statistics names and its offset in stats structure */
429 struct rte_igb_xstats_name_off {
430 char name[RTE_ETH_XSTATS_NAME_SIZE];
434 static const struct rte_igb_xstats_name_off rte_igb_stats_strings[] = {
435 {"rx_crc_errors", offsetof(struct e1000_hw_stats, crcerrs)},
436 {"rx_align_errors", offsetof(struct e1000_hw_stats, algnerrc)},
437 {"rx_symbol_errors", offsetof(struct e1000_hw_stats, symerrs)},
438 {"rx_missed_packets", offsetof(struct e1000_hw_stats, mpc)},
439 {"tx_single_collision_packets", offsetof(struct e1000_hw_stats, scc)},
440 {"tx_multiple_collision_packets", offsetof(struct e1000_hw_stats, mcc)},
441 {"tx_excessive_collision_packets", offsetof(struct e1000_hw_stats,
443 {"tx_late_collisions", offsetof(struct e1000_hw_stats, latecol)},
444 {"tx_total_collisions", offsetof(struct e1000_hw_stats, colc)},
445 {"tx_deferred_packets", offsetof(struct e1000_hw_stats, dc)},
446 {"tx_no_carrier_sense_packets", offsetof(struct e1000_hw_stats, tncrs)},
447 {"rx_carrier_ext_errors", offsetof(struct e1000_hw_stats, cexterr)},
448 {"rx_length_errors", offsetof(struct e1000_hw_stats, rlec)},
449 {"rx_xon_packets", offsetof(struct e1000_hw_stats, xonrxc)},
450 {"tx_xon_packets", offsetof(struct e1000_hw_stats, xontxc)},
451 {"rx_xoff_packets", offsetof(struct e1000_hw_stats, xoffrxc)},
452 {"tx_xoff_packets", offsetof(struct e1000_hw_stats, xofftxc)},
453 {"rx_flow_control_unsupported_packets", offsetof(struct e1000_hw_stats,
455 {"rx_size_64_packets", offsetof(struct e1000_hw_stats, prc64)},
456 {"rx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, prc127)},
457 {"rx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, prc255)},
458 {"rx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, prc511)},
459 {"rx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
461 {"rx_size_1024_to_max_packets", offsetof(struct e1000_hw_stats,
463 {"rx_broadcast_packets", offsetof(struct e1000_hw_stats, bprc)},
464 {"rx_multicast_packets", offsetof(struct e1000_hw_stats, mprc)},
465 {"rx_undersize_errors", offsetof(struct e1000_hw_stats, ruc)},
466 {"rx_fragment_errors", offsetof(struct e1000_hw_stats, rfc)},
467 {"rx_oversize_errors", offsetof(struct e1000_hw_stats, roc)},
468 {"rx_jabber_errors", offsetof(struct e1000_hw_stats, rjc)},
469 {"rx_management_packets", offsetof(struct e1000_hw_stats, mgprc)},
470 {"rx_management_dropped", offsetof(struct e1000_hw_stats, mgpdc)},
471 {"tx_management_packets", offsetof(struct e1000_hw_stats, mgptc)},
472 {"rx_total_packets", offsetof(struct e1000_hw_stats, tpr)},
473 {"tx_total_packets", offsetof(struct e1000_hw_stats, tpt)},
474 {"rx_total_bytes", offsetof(struct e1000_hw_stats, tor)},
475 {"tx_total_bytes", offsetof(struct e1000_hw_stats, tot)},
476 {"tx_size_64_packets", offsetof(struct e1000_hw_stats, ptc64)},
477 {"tx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, ptc127)},
478 {"tx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, ptc255)},
479 {"tx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, ptc511)},
480 {"tx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
482 {"tx_size_1023_to_max_packets", offsetof(struct e1000_hw_stats,
484 {"tx_multicast_packets", offsetof(struct e1000_hw_stats, mptc)},
485 {"tx_broadcast_packets", offsetof(struct e1000_hw_stats, bptc)},
486 {"tx_tso_packets", offsetof(struct e1000_hw_stats, tsctc)},
487 {"tx_tso_errors", offsetof(struct e1000_hw_stats, tsctfc)},
488 {"rx_sent_to_host_packets", offsetof(struct e1000_hw_stats, rpthc)},
489 {"tx_sent_by_host_packets", offsetof(struct e1000_hw_stats, hgptc)},
490 {"rx_code_violation_packets", offsetof(struct e1000_hw_stats, scvpc)},
492 {"interrupt_assert_count", offsetof(struct e1000_hw_stats, iac)},
495 #define IGB_NB_XSTATS (sizeof(rte_igb_stats_strings) / \
496 sizeof(rte_igb_stats_strings[0]))
498 static const struct rte_igb_xstats_name_off rte_igbvf_stats_strings[] = {
499 {"rx_multicast_packets", offsetof(struct e1000_vf_stats, mprc)},
500 {"rx_good_loopback_packets", offsetof(struct e1000_vf_stats, gprlbc)},
501 {"tx_good_loopback_packets", offsetof(struct e1000_vf_stats, gptlbc)},
502 {"rx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gorlbc)},
503 {"tx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gotlbc)},
506 #define IGBVF_NB_XSTATS (sizeof(rte_igbvf_stats_strings) / \
507 sizeof(rte_igbvf_stats_strings[0]))
511 igb_intr_enable(struct rte_eth_dev *dev)
513 struct e1000_interrupt *intr =
514 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
515 struct e1000_hw *hw =
516 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
517 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
518 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
520 if (rte_intr_allow_others(intr_handle) &&
521 dev->data->dev_conf.intr_conf.lsc != 0) {
522 E1000_WRITE_REG(hw, E1000_EIMS, 1 << IGB_MSIX_OTHER_INTR_VEC);
525 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
526 E1000_WRITE_FLUSH(hw);
530 igb_intr_disable(struct rte_eth_dev *dev)
532 struct e1000_hw *hw =
533 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
534 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
535 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
537 if (rte_intr_allow_others(intr_handle) &&
538 dev->data->dev_conf.intr_conf.lsc != 0) {
539 E1000_WRITE_REG(hw, E1000_EIMC, 1 << IGB_MSIX_OTHER_INTR_VEC);
542 E1000_WRITE_REG(hw, E1000_IMC, ~0);
543 E1000_WRITE_FLUSH(hw);
547 igbvf_intr_enable(struct rte_eth_dev *dev)
549 struct e1000_hw *hw =
550 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
552 /* only for mailbox */
553 E1000_WRITE_REG(hw, E1000_EIAM, 1 << E1000_VTIVAR_MISC_MAILBOX);
554 E1000_WRITE_REG(hw, E1000_EIAC, 1 << E1000_VTIVAR_MISC_MAILBOX);
555 E1000_WRITE_REG(hw, E1000_EIMS, 1 << E1000_VTIVAR_MISC_MAILBOX);
556 E1000_WRITE_FLUSH(hw);
559 /* only for mailbox now. If RX/TX needed, should extend this function. */
561 igbvf_set_ivar_map(struct e1000_hw *hw, uint8_t msix_vector)
566 tmp |= (msix_vector & E1000_VTIVAR_MISC_INTR_MASK);
567 tmp |= E1000_VTIVAR_VALID;
568 E1000_WRITE_REG(hw, E1000_VTIVAR_MISC, tmp);
572 eth_igbvf_configure_msix_intr(struct rte_eth_dev *dev)
574 struct e1000_hw *hw =
575 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
577 /* Configure VF other cause ivar */
578 igbvf_set_ivar_map(hw, E1000_VTIVAR_MISC_MAILBOX);
581 static inline int32_t
582 igb_pf_reset_hw(struct e1000_hw *hw)
587 status = e1000_reset_hw(hw);
589 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
590 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
591 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
592 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
593 E1000_WRITE_FLUSH(hw);
599 igb_identify_hardware(struct rte_eth_dev *dev, struct rte_pci_device *pci_dev)
601 struct e1000_hw *hw =
602 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
605 hw->vendor_id = pci_dev->id.vendor_id;
606 hw->device_id = pci_dev->id.device_id;
607 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
608 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
610 e1000_set_mac_type(hw);
612 /* need to check if it is a vf device below */
616 igb_reset_swfw_lock(struct e1000_hw *hw)
621 * Do mac ops initialization manually here, since we will need
622 * some function pointers set by this call.
624 ret_val = e1000_init_mac_params(hw);
629 * SMBI lock should not fail in this early stage. If this is the case,
630 * it is due to an improper exit of the application.
631 * So force the release of the faulty lock.
633 if (e1000_get_hw_semaphore_generic(hw) < 0) {
634 PMD_DRV_LOG(DEBUG, "SMBI lock released");
636 e1000_put_hw_semaphore_generic(hw);
638 if (hw->mac.ops.acquire_swfw_sync != NULL) {
642 * Phy lock should not fail in this early stage. If this is the case,
643 * it is due to an improper exit of the application.
644 * So force the release of the faulty lock.
646 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
647 if (hw->bus.func > E1000_FUNC_1)
649 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
650 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
653 hw->mac.ops.release_swfw_sync(hw, mask);
656 * This one is more tricky since it is common to all ports; but
657 * swfw_sync retries last long enough (1s) to be almost sure that if
658 * lock can not be taken it is due to an improper lock of the
661 mask = E1000_SWFW_EEP_SM;
662 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
663 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
665 hw->mac.ops.release_swfw_sync(hw, mask);
668 return E1000_SUCCESS;
671 /* Remove all ntuple filters of the device */
672 static int igb_ntuple_filter_uninit(struct rte_eth_dev *eth_dev)
674 struct e1000_filter_info *filter_info =
675 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
676 struct e1000_5tuple_filter *p_5tuple;
677 struct e1000_2tuple_filter *p_2tuple;
679 while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list))) {
680 TAILQ_REMOVE(&filter_info->fivetuple_list,
684 filter_info->fivetuple_mask = 0;
685 while ((p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list))) {
686 TAILQ_REMOVE(&filter_info->twotuple_list,
690 filter_info->twotuple_mask = 0;
695 /* Remove all flex filters of the device */
696 static int igb_flex_filter_uninit(struct rte_eth_dev *eth_dev)
698 struct e1000_filter_info *filter_info =
699 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
700 struct e1000_flex_filter *p_flex;
702 while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
703 TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
706 filter_info->flex_mask = 0;
712 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
715 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
716 struct e1000_hw *hw =
717 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
718 struct e1000_vfta * shadow_vfta =
719 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
720 struct e1000_filter_info *filter_info =
721 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
722 struct e1000_adapter *adapter =
723 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
727 eth_dev->dev_ops = ð_igb_ops;
728 eth_dev->rx_queue_count = eth_igb_rx_queue_count;
729 eth_dev->rx_descriptor_status = eth_igb_rx_descriptor_status;
730 eth_dev->tx_descriptor_status = eth_igb_tx_descriptor_status;
731 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
732 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
733 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
735 /* for secondary processes, we don't initialise any further as primary
736 * has already done this work. Only check we don't need a different
738 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
739 if (eth_dev->data->scattered_rx)
740 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
744 rte_eth_copy_pci_info(eth_dev, pci_dev);
746 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
748 igb_identify_hardware(eth_dev, pci_dev);
749 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
754 e1000_get_bus_info(hw);
756 /* Reset any pending lock */
757 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
762 /* Finish initialization */
763 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
769 hw->phy.autoneg_wait_to_complete = 0;
770 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
773 if (hw->phy.media_type == e1000_media_type_copper) {
774 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
775 hw->phy.disable_polarity_correction = 0;
776 hw->phy.ms_type = e1000_ms_hw_default;
780 * Start from a known state, this is important in reading the nvm
785 /* Make sure we have a good EEPROM before we read from it */
786 if (e1000_validate_nvm_checksum(hw) < 0) {
788 * Some PCI-E parts fail the first check due to
789 * the link being in sleep state, call it again,
790 * if it fails a second time its a real issue.
792 if (e1000_validate_nvm_checksum(hw) < 0) {
793 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
799 /* Read the permanent MAC address out of the EEPROM */
800 if (e1000_read_mac_addr(hw) != 0) {
801 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
806 /* Allocate memory for storing MAC addresses */
807 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
808 RTE_ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
809 if (eth_dev->data->mac_addrs == NULL) {
810 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
811 "store MAC addresses",
812 RTE_ETHER_ADDR_LEN * hw->mac.rar_entry_count);
817 /* Copy the permanent MAC address */
818 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
819 ð_dev->data->mac_addrs[0]);
821 /* initialize the vfta */
822 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
824 /* Now initialize the hardware */
825 if (igb_hardware_init(hw) != 0) {
826 PMD_INIT_LOG(ERR, "Hardware initialization failed");
827 rte_free(eth_dev->data->mac_addrs);
828 eth_dev->data->mac_addrs = NULL;
832 hw->mac.get_link_status = 1;
833 adapter->stopped = 0;
835 /* Indicate SOL/IDER usage */
836 if (e1000_check_reset_block(hw) < 0) {
837 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
841 /* initialize PF if max_vfs not zero */
842 igb_pf_host_init(eth_dev);
844 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
845 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
846 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
847 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
848 E1000_WRITE_FLUSH(hw);
850 PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
851 eth_dev->data->port_id, pci_dev->id.vendor_id,
852 pci_dev->id.device_id);
854 rte_intr_callback_register(pci_dev->intr_handle,
855 eth_igb_interrupt_handler,
858 /* enable uio/vfio intr/eventfd mapping */
859 rte_intr_enable(pci_dev->intr_handle);
861 /* enable support intr */
862 igb_intr_enable(eth_dev);
864 eth_igb_dev_set_link_down(eth_dev);
866 /* initialize filter info */
867 memset(filter_info, 0,
868 sizeof(struct e1000_filter_info));
870 TAILQ_INIT(&filter_info->flex_list);
871 TAILQ_INIT(&filter_info->twotuple_list);
872 TAILQ_INIT(&filter_info->fivetuple_list);
874 TAILQ_INIT(&igb_filter_ntuple_list);
875 TAILQ_INIT(&igb_filter_ethertype_list);
876 TAILQ_INIT(&igb_filter_syn_list);
877 TAILQ_INIT(&igb_filter_flex_list);
878 TAILQ_INIT(&igb_filter_rss_list);
879 TAILQ_INIT(&igb_flow_list);
884 igb_hw_control_release(hw);
890 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
892 PMD_INIT_FUNC_TRACE();
894 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
897 eth_igb_close(eth_dev);
903 * Virtual Function device init
906 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
908 struct rte_pci_device *pci_dev;
909 struct rte_intr_handle *intr_handle;
910 struct e1000_adapter *adapter =
911 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
912 struct e1000_hw *hw =
913 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
915 struct rte_ether_addr *perm_addr =
916 (struct rte_ether_addr *)hw->mac.perm_addr;
918 PMD_INIT_FUNC_TRACE();
920 eth_dev->dev_ops = &igbvf_eth_dev_ops;
921 eth_dev->rx_descriptor_status = eth_igb_rx_descriptor_status;
922 eth_dev->tx_descriptor_status = eth_igb_tx_descriptor_status;
923 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
924 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
925 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
927 /* for secondary processes, we don't initialise any further as primary
928 * has already done this work. Only check we don't need a different
930 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
931 if (eth_dev->data->scattered_rx)
932 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
936 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
937 rte_eth_copy_pci_info(eth_dev, pci_dev);
939 hw->device_id = pci_dev->id.device_id;
940 hw->vendor_id = pci_dev->id.vendor_id;
941 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
942 adapter->stopped = 0;
944 /* Initialize the shared code (base driver) */
945 diag = e1000_setup_init_funcs(hw, TRUE);
947 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
952 /* init_mailbox_params */
953 hw->mbx.ops.init_params(hw);
955 /* Disable the interrupts for VF */
956 igbvf_intr_disable(hw);
958 diag = hw->mac.ops.reset_hw(hw);
960 /* Allocate memory for storing MAC addresses */
961 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", RTE_ETHER_ADDR_LEN *
962 hw->mac.rar_entry_count, 0);
963 if (eth_dev->data->mac_addrs == NULL) {
965 "Failed to allocate %d bytes needed to store MAC "
967 RTE_ETHER_ADDR_LEN * hw->mac.rar_entry_count);
971 /* Generate a random MAC address, if none was assigned by PF. */
972 if (rte_is_zero_ether_addr(perm_addr)) {
973 rte_eth_random_addr(perm_addr->addr_bytes);
974 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
975 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
976 RTE_ETHER_ADDR_PRT_FMT,
977 RTE_ETHER_ADDR_BYTES(perm_addr));
980 diag = e1000_rar_set(hw, perm_addr->addr_bytes, 0);
982 rte_free(eth_dev->data->mac_addrs);
983 eth_dev->data->mac_addrs = NULL;
986 /* Copy the permanent MAC address */
987 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
988 ð_dev->data->mac_addrs[0]);
990 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
992 eth_dev->data->port_id, pci_dev->id.vendor_id,
993 pci_dev->id.device_id, "igb_mac_82576_vf");
995 intr_handle = pci_dev->intr_handle;
996 rte_intr_callback_register(intr_handle,
997 eth_igbvf_interrupt_handler, eth_dev);
1003 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
1005 PMD_INIT_FUNC_TRACE();
1007 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1010 igbvf_dev_close(eth_dev);
1015 static int eth_igb_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1016 struct rte_pci_device *pci_dev)
1018 return rte_eth_dev_pci_generic_probe(pci_dev,
1019 sizeof(struct e1000_adapter), eth_igb_dev_init);
1022 static int eth_igb_pci_remove(struct rte_pci_device *pci_dev)
1024 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igb_dev_uninit);
1027 static struct rte_pci_driver rte_igb_pmd = {
1028 .id_table = pci_id_igb_map,
1029 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1030 .probe = eth_igb_pci_probe,
1031 .remove = eth_igb_pci_remove,
1035 static int eth_igbvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1036 struct rte_pci_device *pci_dev)
1038 return rte_eth_dev_pci_generic_probe(pci_dev,
1039 sizeof(struct e1000_adapter), eth_igbvf_dev_init);
1042 static int eth_igbvf_pci_remove(struct rte_pci_device *pci_dev)
1044 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igbvf_dev_uninit);
1048 * virtual function driver struct
1050 static struct rte_pci_driver rte_igbvf_pmd = {
1051 .id_table = pci_id_igbvf_map,
1052 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1053 .probe = eth_igbvf_pci_probe,
1054 .remove = eth_igbvf_pci_remove,
1058 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1060 struct e1000_hw *hw =
1061 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1062 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
1063 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
1064 rctl |= E1000_RCTL_VFE;
1065 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1069 igb_check_mq_mode(struct rte_eth_dev *dev)
1071 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1072 enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
1073 uint16_t nb_rx_q = dev->data->nb_rx_queues;
1074 uint16_t nb_tx_q = dev->data->nb_tx_queues;
1076 if ((rx_mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) ||
1077 tx_mq_mode == RTE_ETH_MQ_TX_DCB ||
1078 tx_mq_mode == RTE_ETH_MQ_TX_VMDQ_DCB) {
1079 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
1082 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
1083 /* Check multi-queue mode.
1084 * To no break software we accept RTE_ETH_MQ_RX_NONE as this might
1085 * be used to turn off VLAN filter.
1088 if (rx_mq_mode == RTE_ETH_MQ_RX_NONE ||
1089 rx_mq_mode == RTE_ETH_MQ_RX_VMDQ_ONLY) {
1090 dev->data->dev_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_VMDQ_ONLY;
1091 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
1093 /* Only support one queue on VFs.
1094 * RSS together with SRIOV is not supported.
1096 PMD_INIT_LOG(ERR, "SRIOV is active,"
1097 " wrong mq_mode rx %d.",
1101 /* TX mode is not used here, so mode might be ignored.*/
1102 if (tx_mq_mode != RTE_ETH_MQ_TX_VMDQ_ONLY) {
1103 /* SRIOV only works in VMDq enable mode */
1104 PMD_INIT_LOG(WARNING, "SRIOV is active,"
1105 " TX mode %d is not supported. "
1106 " Driver will behave as %d mode.",
1107 tx_mq_mode, RTE_ETH_MQ_TX_VMDQ_ONLY);
1110 /* check valid queue number */
1111 if ((nb_rx_q > 1) || (nb_tx_q > 1)) {
1112 PMD_INIT_LOG(ERR, "SRIOV is active,"
1113 " only support one queue on VFs.");
1117 /* To no break software that set invalid mode, only display
1118 * warning if invalid mode is used.
1120 if (rx_mq_mode != RTE_ETH_MQ_RX_NONE &&
1121 rx_mq_mode != RTE_ETH_MQ_RX_VMDQ_ONLY &&
1122 rx_mq_mode != RTE_ETH_MQ_RX_RSS) {
1123 /* RSS together with VMDq not supported*/
1124 PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
1129 if (tx_mq_mode != RTE_ETH_MQ_TX_NONE &&
1130 tx_mq_mode != RTE_ETH_MQ_TX_VMDQ_ONLY) {
1131 PMD_INIT_LOG(WARNING, "TX mode %d is not supported."
1132 " Due to txmode is meaningless in this"
1133 " driver, just ignore.",
1141 eth_igb_configure(struct rte_eth_dev *dev)
1143 struct e1000_interrupt *intr =
1144 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1147 PMD_INIT_FUNC_TRACE();
1149 if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
1150 dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
1152 /* multiple queue mode checking */
1153 ret = igb_check_mq_mode(dev);
1155 PMD_DRV_LOG(ERR, "igb_check_mq_mode fails with %d.",
1160 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1161 PMD_INIT_FUNC_TRACE();
1167 eth_igb_rxtx_control(struct rte_eth_dev *dev,
1170 struct e1000_hw *hw =
1171 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1172 uint32_t tctl, rctl;
1174 tctl = E1000_READ_REG(hw, E1000_TCTL);
1175 rctl = E1000_READ_REG(hw, E1000_RCTL);
1179 tctl |= E1000_TCTL_EN;
1180 rctl |= E1000_RCTL_EN;
1183 tctl &= ~E1000_TCTL_EN;
1184 rctl &= ~E1000_RCTL_EN;
1186 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1187 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1188 E1000_WRITE_FLUSH(hw);
1192 eth_igb_start(struct rte_eth_dev *dev)
1194 struct e1000_hw *hw =
1195 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1196 struct e1000_adapter *adapter =
1197 E1000_DEV_PRIVATE(dev->data->dev_private);
1198 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1199 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1201 uint32_t intr_vector = 0;
1207 PMD_INIT_FUNC_TRACE();
1209 /* disable uio/vfio intr/eventfd mapping */
1210 rte_intr_disable(intr_handle);
1212 /* Power up the phy. Needed to make the link go Up */
1213 eth_igb_dev_set_link_up(dev);
1216 * Packet Buffer Allocation (PBA)
1217 * Writing PBA sets the receive portion of the buffer
1218 * the remainder is used for the transmit buffer.
1220 if (hw->mac.type == e1000_82575) {
1223 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
1224 E1000_WRITE_REG(hw, E1000_PBA, pba);
1227 /* Put the address into the Receive Address Array */
1228 e1000_rar_set(hw, hw->mac.addr, 0);
1230 /* Initialize the hardware */
1231 if (igb_hardware_init(hw)) {
1232 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
1235 adapter->stopped = 0;
1237 E1000_WRITE_REG(hw, E1000_VET,
1238 RTE_ETHER_TYPE_VLAN << 16 | RTE_ETHER_TYPE_VLAN);
1240 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1241 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1242 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
1243 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1244 E1000_WRITE_FLUSH(hw);
1246 /* configure PF module if SRIOV enabled */
1247 igb_pf_host_configure(dev);
1249 /* check and configure queue intr-vector mapping */
1250 if ((rte_intr_cap_multiple(intr_handle) ||
1251 !RTE_ETH_DEV_SRIOV(dev).active) &&
1252 dev->data->dev_conf.intr_conf.rxq != 0) {
1253 intr_vector = dev->data->nb_rx_queues;
1254 if (rte_intr_efd_enable(intr_handle, intr_vector))
1258 /* Allocate the vector list */
1259 if (rte_intr_dp_is_en(intr_handle)) {
1260 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
1261 dev->data->nb_rx_queues)) {
1262 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1263 " intr_vec", dev->data->nb_rx_queues);
1268 /* configure MSI-X for Rx interrupt */
1269 eth_igb_configure_msix_intr(dev);
1271 /* Configure for OS presence */
1272 igb_init_manageability(hw);
1274 eth_igb_tx_init(dev);
1276 /* This can fail when allocating mbufs for descriptor rings */
1277 ret = eth_igb_rx_init(dev);
1279 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1280 igb_dev_clear_queues(dev);
1284 e1000_clear_hw_cntrs_base_generic(hw);
1287 * VLAN Offload Settings
1289 mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
1290 RTE_ETH_VLAN_EXTEND_MASK;
1291 ret = eth_igb_vlan_offload_set(dev, mask);
1293 PMD_INIT_LOG(ERR, "Unable to set vlan offload");
1294 igb_dev_clear_queues(dev);
1298 if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_VMDQ_ONLY) {
1299 /* Enable VLAN filter since VMDq always use VLAN filter */
1300 igb_vmdq_vlan_hw_filter_enable(dev);
1303 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
1304 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
1305 (hw->mac.type == e1000_i211)) {
1306 /* Configure EITR with the maximum possible value (0xFFFF) */
1307 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
1310 /* Setup link speed and duplex */
1311 speeds = &dev->data->dev_conf.link_speeds;
1312 if (*speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
1313 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
1314 hw->mac.autoneg = 1;
1317 autoneg = (*speeds & RTE_ETH_LINK_SPEED_FIXED) == 0;
1320 hw->phy.autoneg_advertised = 0;
1322 if (*speeds & ~(RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
1323 RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
1324 RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_FIXED)) {
1326 goto error_invalid_config;
1328 if (*speeds & RTE_ETH_LINK_SPEED_10M_HD) {
1329 hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
1332 if (*speeds & RTE_ETH_LINK_SPEED_10M) {
1333 hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
1336 if (*speeds & RTE_ETH_LINK_SPEED_100M_HD) {
1337 hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
1340 if (*speeds & RTE_ETH_LINK_SPEED_100M) {
1341 hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
1344 if (*speeds & RTE_ETH_LINK_SPEED_1G) {
1345 hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
1348 if (num_speeds == 0 || (!autoneg && (num_speeds > 1)))
1349 goto error_invalid_config;
1351 /* Set/reset the mac.autoneg based on the link speed,
1355 hw->mac.autoneg = 0;
1356 hw->mac.forced_speed_duplex =
1357 hw->phy.autoneg_advertised;
1359 hw->mac.autoneg = 1;
1363 e1000_setup_link(hw);
1365 if (rte_intr_allow_others(intr_handle)) {
1366 /* check if lsc interrupt is enabled */
1367 if (dev->data->dev_conf.intr_conf.lsc != 0)
1368 eth_igb_lsc_interrupt_setup(dev, TRUE);
1370 eth_igb_lsc_interrupt_setup(dev, FALSE);
1372 rte_intr_callback_unregister(intr_handle,
1373 eth_igb_interrupt_handler,
1375 if (dev->data->dev_conf.intr_conf.lsc != 0)
1376 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1377 " no intr multiplex");
1380 /* check if rxq interrupt is enabled */
1381 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1382 rte_intr_dp_is_en(intr_handle))
1383 eth_igb_rxq_interrupt_setup(dev);
1385 /* enable uio/vfio intr/eventfd mapping */
1386 rte_intr_enable(intr_handle);
1388 /* resume enabled intr since hw reset */
1389 igb_intr_enable(dev);
1391 /* restore all types filter */
1392 igb_filter_restore(dev);
1394 eth_igb_rxtx_control(dev, true);
1395 eth_igb_link_update(dev, 0);
1397 PMD_INIT_LOG(DEBUG, "<<");
1401 error_invalid_config:
1402 PMD_INIT_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
1403 dev->data->dev_conf.link_speeds, dev->data->port_id);
1404 igb_dev_clear_queues(dev);
1408 /*********************************************************************
1410 * This routine disables all traffic on the adapter by issuing a
1411 * global reset on the MAC.
1413 **********************************************************************/
1415 eth_igb_stop(struct rte_eth_dev *dev)
1417 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1418 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1419 struct rte_eth_link link;
1420 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1421 struct e1000_adapter *adapter =
1422 E1000_DEV_PRIVATE(dev->data->dev_private);
1424 if (adapter->stopped)
1427 eth_igb_rxtx_control(dev, false);
1429 igb_intr_disable(dev);
1431 /* disable intr eventfd mapping */
1432 rte_intr_disable(intr_handle);
1434 igb_pf_reset_hw(hw);
1435 E1000_WRITE_REG(hw, E1000_WUC, 0);
1437 /* Set bit for Go Link disconnect if PHY reset is not blocked */
1438 if (hw->mac.type >= e1000_82580 &&
1439 (e1000_check_reset_block(hw) != E1000_BLK_PHY_RESET)) {
1442 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1443 phpm_reg |= E1000_82580_PM_GO_LINKD;
1444 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1447 /* Power down the phy. Needed to make the link go Down */
1448 eth_igb_dev_set_link_down(dev);
1450 igb_dev_clear_queues(dev);
1452 /* clear the recorded link status */
1453 memset(&link, 0, sizeof(link));
1454 rte_eth_linkstatus_set(dev, &link);
1456 if (!rte_intr_allow_others(intr_handle))
1457 /* resume to the default handler */
1458 rte_intr_callback_register(intr_handle,
1459 eth_igb_interrupt_handler,
1462 /* Clean datapath event and queue/vec mapping */
1463 rte_intr_efd_disable(intr_handle);
1464 rte_intr_vec_list_free(intr_handle);
1466 adapter->stopped = true;
1467 dev->data->dev_started = 0;
1473 eth_igb_dev_set_link_up(struct rte_eth_dev *dev)
1475 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1477 if (hw->phy.media_type == e1000_media_type_copper)
1478 e1000_power_up_phy(hw);
1480 e1000_power_up_fiber_serdes_link(hw);
1486 eth_igb_dev_set_link_down(struct rte_eth_dev *dev)
1488 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1490 if (hw->phy.media_type == e1000_media_type_copper)
1491 e1000_power_down_phy(hw);
1493 e1000_shutdown_fiber_serdes_link(hw);
1499 eth_igb_close(struct rte_eth_dev *dev)
1501 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1502 struct rte_eth_link link;
1503 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1504 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1505 struct e1000_filter_info *filter_info =
1506 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1509 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1512 ret = eth_igb_stop(dev);
1514 e1000_phy_hw_reset(hw);
1515 igb_release_manageability(hw);
1516 igb_hw_control_release(hw);
1518 /* Clear bit for Go Link disconnect if PHY reset is not blocked */
1519 if (hw->mac.type >= e1000_82580 &&
1520 (e1000_check_reset_block(hw) != E1000_BLK_PHY_RESET)) {
1523 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1524 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1525 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1528 igb_dev_free_queues(dev);
1530 /* Cleanup vector list */
1531 rte_intr_vec_list_free(intr_handle);
1533 memset(&link, 0, sizeof(link));
1534 rte_eth_linkstatus_set(dev, &link);
1536 /* Reset any pending lock */
1537 igb_reset_swfw_lock(hw);
1539 /* uninitialize PF if max_vfs not zero */
1540 igb_pf_host_uninit(dev);
1542 rte_intr_callback_unregister(intr_handle,
1543 eth_igb_interrupt_handler, dev);
1545 /* clear the SYN filter info */
1546 filter_info->syn_info = 0;
1548 /* clear the ethertype filters info */
1549 filter_info->ethertype_mask = 0;
1550 memset(filter_info->ethertype_filters, 0,
1551 E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
1553 /* clear the rss filter info */
1554 memset(&filter_info->rss_info, 0,
1555 sizeof(struct igb_rte_flow_rss_conf));
1557 /* remove all ntuple filters of the device */
1558 igb_ntuple_filter_uninit(dev);
1560 /* remove all flex filters of the device */
1561 igb_flex_filter_uninit(dev);
1563 /* clear all the filters list */
1564 igb_filterlist_flush(dev);
1573 eth_igb_reset(struct rte_eth_dev *dev)
1577 /* When a DPDK PMD PF begin to reset PF port, it should notify all
1578 * its VF to make them align with it. The detailed notification
1579 * mechanism is PMD specific and is currently not implemented.
1580 * To avoid unexpected behavior in VF, currently reset of PF with
1581 * SR-IOV activation is not supported. It might be supported later.
1583 if (dev->data->sriov.active)
1586 ret = eth_igb_dev_uninit(dev);
1590 ret = eth_igb_dev_init(dev);
1597 igb_get_rx_buffer_size(struct e1000_hw *hw)
1599 uint32_t rx_buf_size;
1600 if (hw->mac.type == e1000_82576) {
1601 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1602 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1603 /* PBS needs to be translated according to a lookup table */
1604 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1605 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1606 rx_buf_size = (rx_buf_size << 10);
1607 } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1608 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1610 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1616 /*********************************************************************
1618 * Initialize the hardware
1620 **********************************************************************/
1622 igb_hardware_init(struct e1000_hw *hw)
1624 uint32_t rx_buf_size;
1627 /* Let the firmware know the OS is in control */
1628 igb_hw_control_acquire(hw);
1631 * These parameters control the automatic generation (Tx) and
1632 * response (Rx) to Ethernet PAUSE frames.
1633 * - High water mark should allow for at least two standard size (1518)
1634 * frames to be received after sending an XOFF.
1635 * - Low water mark works best when it is very near the high water mark.
1636 * This allows the receiver to restart by sending XON when it has
1637 * drained a bit. Here we use an arbitrary value of 1500 which will
1638 * restart after one full frame is pulled from the buffer. There
1639 * could be several smaller frames in the buffer and if so they will
1640 * not trigger the XON until their total number reduces the buffer
1642 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1644 rx_buf_size = igb_get_rx_buffer_size(hw);
1646 hw->fc.high_water = rx_buf_size - (RTE_ETHER_MAX_LEN * 2);
1647 hw->fc.low_water = hw->fc.high_water - 1500;
1648 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1649 hw->fc.send_xon = 1;
1651 /* Set Flow control, use the tunable location if sane */
1652 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1653 hw->fc.requested_mode = igb_fc_setting;
1655 hw->fc.requested_mode = e1000_fc_none;
1657 /* Issue a global reset */
1658 igb_pf_reset_hw(hw);
1659 E1000_WRITE_REG(hw, E1000_WUC, 0);
1661 diag = e1000_init_hw(hw);
1665 E1000_WRITE_REG(hw, E1000_VET,
1666 RTE_ETHER_TYPE_VLAN << 16 | RTE_ETHER_TYPE_VLAN);
1667 e1000_get_phy_info(hw);
1668 e1000_check_for_link(hw);
1673 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1675 igb_read_stats_registers(struct e1000_hw *hw, struct e1000_hw_stats *stats)
1679 uint64_t old_gprc = stats->gprc;
1680 uint64_t old_gptc = stats->gptc;
1681 uint64_t old_tpr = stats->tpr;
1682 uint64_t old_tpt = stats->tpt;
1683 uint64_t old_rpthc = stats->rpthc;
1684 uint64_t old_hgptc = stats->hgptc;
1686 if(hw->phy.media_type == e1000_media_type_copper ||
1687 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1689 E1000_READ_REG(hw,E1000_SYMERRS);
1690 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1693 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1694 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1695 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1696 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1698 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1699 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1700 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1701 stats->dc += E1000_READ_REG(hw, E1000_DC);
1702 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1703 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1704 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1706 ** For watchdog management we need to know if we have been
1707 ** paused during the last interval, so capture that here.
1709 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1710 stats->xoffrxc += pause_frames;
1711 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1712 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1713 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1714 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1715 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1716 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1717 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1718 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1719 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1720 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1721 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1722 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1724 /* For the 64-bit byte counters the low dword must be read first. */
1725 /* Both registers clear on the read of the high dword */
1727 /* Workaround CRC bytes included in size, take away 4 bytes/packet */
1728 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1729 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1730 stats->gorc -= (stats->gprc - old_gprc) * RTE_ETHER_CRC_LEN;
1731 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1732 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1733 stats->gotc -= (stats->gptc - old_gptc) * RTE_ETHER_CRC_LEN;
1735 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1736 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1737 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1738 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1739 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1741 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1742 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1744 stats->tor += E1000_READ_REG(hw, E1000_TORL);
1745 stats->tor += ((uint64_t)E1000_READ_REG(hw, E1000_TORH) << 32);
1746 stats->tor -= (stats->tpr - old_tpr) * RTE_ETHER_CRC_LEN;
1747 stats->tot += E1000_READ_REG(hw, E1000_TOTL);
1748 stats->tot += ((uint64_t)E1000_READ_REG(hw, E1000_TOTH) << 32);
1749 stats->tot -= (stats->tpt - old_tpt) * RTE_ETHER_CRC_LEN;
1751 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1752 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1753 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1754 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1755 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1756 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1757 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1758 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1760 /* Interrupt Counts */
1762 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1763 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1764 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1765 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1766 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1767 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1768 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1769 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1770 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1772 /* Host to Card Statistics */
1774 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1775 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1776 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1777 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1778 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1779 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1780 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1781 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1782 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1783 stats->hgorc -= (stats->rpthc - old_rpthc) * RTE_ETHER_CRC_LEN;
1784 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1785 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1786 stats->hgotc -= (stats->hgptc - old_hgptc) * RTE_ETHER_CRC_LEN;
1787 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1788 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1789 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1791 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1792 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1793 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1794 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1795 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1796 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1800 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1802 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1803 struct e1000_hw_stats *stats =
1804 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1806 igb_read_stats_registers(hw, stats);
1808 if (rte_stats == NULL)
1812 rte_stats->imissed = stats->mpc;
1813 rte_stats->ierrors = stats->crcerrs + stats->rlec +
1814 stats->rxerrc + stats->algnerrc + stats->cexterr;
1817 rte_stats->oerrors = stats->ecol + stats->latecol;
1819 rte_stats->ipackets = stats->gprc;
1820 rte_stats->opackets = stats->gptc;
1821 rte_stats->ibytes = stats->gorc;
1822 rte_stats->obytes = stats->gotc;
1827 eth_igb_stats_reset(struct rte_eth_dev *dev)
1829 struct e1000_hw_stats *hw_stats =
1830 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1832 /* HW registers are cleared on read */
1833 eth_igb_stats_get(dev, NULL);
1835 /* Reset software totals */
1836 memset(hw_stats, 0, sizeof(*hw_stats));
1842 eth_igb_xstats_reset(struct rte_eth_dev *dev)
1844 struct e1000_hw_stats *stats =
1845 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1847 /* HW registers are cleared on read */
1848 eth_igb_xstats_get(dev, NULL, IGB_NB_XSTATS);
1850 /* Reset software totals */
1851 memset(stats, 0, sizeof(*stats));
1856 static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1857 struct rte_eth_xstat_name *xstats_names,
1858 __rte_unused unsigned int size)
1862 if (xstats_names == NULL)
1863 return IGB_NB_XSTATS;
1865 /* Note: limit checked in rte_eth_xstats_names() */
1867 for (i = 0; i < IGB_NB_XSTATS; i++) {
1868 strlcpy(xstats_names[i].name, rte_igb_stats_strings[i].name,
1869 sizeof(xstats_names[i].name));
1872 return IGB_NB_XSTATS;
1875 static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
1876 const uint64_t *ids, struct rte_eth_xstat_name *xstats_names,
1882 if (xstats_names == NULL)
1883 return IGB_NB_XSTATS;
1885 for (i = 0; i < IGB_NB_XSTATS; i++)
1886 strlcpy(xstats_names[i].name,
1887 rte_igb_stats_strings[i].name,
1888 sizeof(xstats_names[i].name));
1890 return IGB_NB_XSTATS;
1893 struct rte_eth_xstat_name xstats_names_copy[IGB_NB_XSTATS];
1895 eth_igb_xstats_get_names_by_id(dev, NULL, xstats_names_copy,
1898 for (i = 0; i < limit; i++) {
1899 if (ids[i] >= IGB_NB_XSTATS) {
1900 PMD_INIT_LOG(ERR, "id value isn't valid");
1903 strcpy(xstats_names[i].name,
1904 xstats_names_copy[ids[i]].name);
1911 eth_igb_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1914 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1915 struct e1000_hw_stats *hw_stats =
1916 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1919 if (n < IGB_NB_XSTATS)
1920 return IGB_NB_XSTATS;
1922 igb_read_stats_registers(hw, hw_stats);
1924 /* If this is a reset xstats is NULL, and we have cleared the
1925 * registers by reading them.
1930 /* Extended stats */
1931 for (i = 0; i < IGB_NB_XSTATS; i++) {
1933 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
1934 rte_igb_stats_strings[i].offset);
1937 return IGB_NB_XSTATS;
1941 eth_igb_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1942 uint64_t *values, unsigned int n)
1947 struct e1000_hw *hw =
1948 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1949 struct e1000_hw_stats *hw_stats =
1950 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1952 if (n < IGB_NB_XSTATS)
1953 return IGB_NB_XSTATS;
1955 igb_read_stats_registers(hw, hw_stats);
1957 /* If this is a reset xstats is NULL, and we have cleared the
1958 * registers by reading them.
1963 /* Extended stats */
1964 for (i = 0; i < IGB_NB_XSTATS; i++)
1965 values[i] = *(uint64_t *)(((char *)hw_stats) +
1966 rte_igb_stats_strings[i].offset);
1968 return IGB_NB_XSTATS;
1971 uint64_t values_copy[IGB_NB_XSTATS];
1973 eth_igb_xstats_get_by_id(dev, NULL, values_copy,
1976 for (i = 0; i < n; i++) {
1977 if (ids[i] >= IGB_NB_XSTATS) {
1978 PMD_INIT_LOG(ERR, "id value isn't valid");
1981 values[i] = values_copy[ids[i]];
1988 igbvf_read_stats_registers(struct e1000_hw *hw, struct e1000_vf_stats *hw_stats)
1990 /* Good Rx packets, include VF loopback */
1991 UPDATE_VF_STAT(E1000_VFGPRC,
1992 hw_stats->last_gprc, hw_stats->gprc);
1994 /* Good Rx octets, include VF loopback */
1995 UPDATE_VF_STAT(E1000_VFGORC,
1996 hw_stats->last_gorc, hw_stats->gorc);
1998 /* Good Tx packets, include VF loopback */
1999 UPDATE_VF_STAT(E1000_VFGPTC,
2000 hw_stats->last_gptc, hw_stats->gptc);
2002 /* Good Tx octets, include VF loopback */
2003 UPDATE_VF_STAT(E1000_VFGOTC,
2004 hw_stats->last_gotc, hw_stats->gotc);
2006 /* Rx Multicst packets */
2007 UPDATE_VF_STAT(E1000_VFMPRC,
2008 hw_stats->last_mprc, hw_stats->mprc);
2010 /* Good Rx loopback packets */
2011 UPDATE_VF_STAT(E1000_VFGPRLBC,
2012 hw_stats->last_gprlbc, hw_stats->gprlbc);
2014 /* Good Rx loopback octets */
2015 UPDATE_VF_STAT(E1000_VFGORLBC,
2016 hw_stats->last_gorlbc, hw_stats->gorlbc);
2018 /* Good Tx loopback packets */
2019 UPDATE_VF_STAT(E1000_VFGPTLBC,
2020 hw_stats->last_gptlbc, hw_stats->gptlbc);
2022 /* Good Tx loopback octets */
2023 UPDATE_VF_STAT(E1000_VFGOTLBC,
2024 hw_stats->last_gotlbc, hw_stats->gotlbc);
2027 static int eth_igbvf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2028 struct rte_eth_xstat_name *xstats_names,
2029 __rte_unused unsigned limit)
2033 if (xstats_names != NULL)
2034 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2035 strlcpy(xstats_names[i].name,
2036 rte_igbvf_stats_strings[i].name,
2037 sizeof(xstats_names[i].name));
2039 return IGBVF_NB_XSTATS;
2043 eth_igbvf_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2046 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2047 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2048 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2051 if (n < IGBVF_NB_XSTATS)
2052 return IGBVF_NB_XSTATS;
2054 igbvf_read_stats_registers(hw, hw_stats);
2059 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2061 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
2062 rte_igbvf_stats_strings[i].offset);
2065 return IGBVF_NB_XSTATS;
2069 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
2071 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2072 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2073 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2075 igbvf_read_stats_registers(hw, hw_stats);
2077 if (rte_stats == NULL)
2080 rte_stats->ipackets = hw_stats->gprc;
2081 rte_stats->ibytes = hw_stats->gorc;
2082 rte_stats->opackets = hw_stats->gptc;
2083 rte_stats->obytes = hw_stats->gotc;
2088 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
2090 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
2091 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2093 /* Sync HW register to the last stats */
2094 eth_igbvf_stats_get(dev, NULL);
2096 /* reset HW current stats*/
2097 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
2098 offsetof(struct e1000_vf_stats, gprc));
2104 eth_igb_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
2107 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2108 struct e1000_fw_version fw;
2111 e1000_get_fw_version(hw, &fw);
2113 switch (hw->mac.type) {
2116 if (!(e1000_get_flash_presence_i210(hw))) {
2117 ret = snprintf(fw_version, fw_size,
2119 fw.invm_major, fw.invm_minor,
2125 /* if option rom is valid, display its version too */
2127 ret = snprintf(fw_version, fw_size,
2128 "%d.%d, 0x%08x, %d.%d.%d",
2129 fw.eep_major, fw.eep_minor, fw.etrack_id,
2130 fw.or_major, fw.or_build, fw.or_patch);
2133 if (fw.etrack_id != 0X0000) {
2134 ret = snprintf(fw_version, fw_size,
2136 fw.eep_major, fw.eep_minor,
2139 ret = snprintf(fw_version, fw_size,
2141 fw.eep_major, fw.eep_minor,
2150 ret += 1; /* add the size of '\0' */
2151 if (fw_size < (size_t)ret)
2158 eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2160 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2162 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2163 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2164 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2165 dev_info->rx_queue_offload_capa = igb_get_rx_queue_offloads_capa(dev);
2166 dev_info->rx_offload_capa = igb_get_rx_port_offloads_capa(dev) |
2167 dev_info->rx_queue_offload_capa;
2168 dev_info->tx_queue_offload_capa = igb_get_tx_queue_offloads_capa(dev);
2169 dev_info->tx_offload_capa = igb_get_tx_port_offloads_capa(dev) |
2170 dev_info->tx_queue_offload_capa;
2171 dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
2173 switch (hw->mac.type) {
2175 dev_info->max_rx_queues = 4;
2176 dev_info->max_tx_queues = 4;
2177 dev_info->max_vmdq_pools = 0;
2181 dev_info->max_rx_queues = 16;
2182 dev_info->max_tx_queues = 16;
2183 dev_info->max_vmdq_pools = RTE_ETH_8_POOLS;
2184 dev_info->vmdq_queue_num = 16;
2188 dev_info->max_rx_queues = 8;
2189 dev_info->max_tx_queues = 8;
2190 dev_info->max_vmdq_pools = RTE_ETH_8_POOLS;
2191 dev_info->vmdq_queue_num = 8;
2195 dev_info->max_rx_queues = 8;
2196 dev_info->max_tx_queues = 8;
2197 dev_info->max_vmdq_pools = RTE_ETH_8_POOLS;
2198 dev_info->vmdq_queue_num = 8;
2202 dev_info->max_rx_queues = 8;
2203 dev_info->max_tx_queues = 8;
2207 dev_info->max_rx_queues = 4;
2208 dev_info->max_tx_queues = 4;
2209 dev_info->max_vmdq_pools = 0;
2213 dev_info->max_rx_queues = 2;
2214 dev_info->max_tx_queues = 2;
2215 dev_info->max_vmdq_pools = 0;
2219 /* Should not happen */
2222 dev_info->hash_key_size = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
2223 dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_128;
2224 dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
2226 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2228 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2229 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2230 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2232 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2237 dev_info->default_txconf = (struct rte_eth_txconf) {
2239 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2240 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2241 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2246 dev_info->rx_desc_lim = rx_desc_lim;
2247 dev_info->tx_desc_lim = tx_desc_lim;
2249 dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
2250 RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
2251 RTE_ETH_LINK_SPEED_1G;
2253 dev_info->max_mtu = dev_info->max_rx_pktlen - E1000_ETH_OVERHEAD;
2254 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
2259 static const uint32_t *
2260 eth_igb_supported_ptypes_get(struct rte_eth_dev *dev)
2262 static const uint32_t ptypes[] = {
2263 /* refers to igb_rxd_pkt_info_to_pkt_type() */
2266 RTE_PTYPE_L3_IPV4_EXT,
2268 RTE_PTYPE_L3_IPV6_EXT,
2272 RTE_PTYPE_TUNNEL_IP,
2273 RTE_PTYPE_INNER_L3_IPV6,
2274 RTE_PTYPE_INNER_L3_IPV6_EXT,
2275 RTE_PTYPE_INNER_L4_TCP,
2276 RTE_PTYPE_INNER_L4_UDP,
2280 if (dev->rx_pkt_burst == eth_igb_recv_pkts ||
2281 dev->rx_pkt_burst == eth_igb_recv_scattered_pkts)
2287 eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2289 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2291 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2292 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2293 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2294 dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
2295 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
2296 RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
2297 RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
2298 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
2299 RTE_ETH_TX_OFFLOAD_TCP_TSO;
2300 switch (hw->mac.type) {
2302 dev_info->max_rx_queues = 2;
2303 dev_info->max_tx_queues = 2;
2305 case e1000_vfadapt_i350:
2306 dev_info->max_rx_queues = 1;
2307 dev_info->max_tx_queues = 1;
2310 /* Should not happen */
2314 dev_info->rx_queue_offload_capa = igb_get_rx_queue_offloads_capa(dev);
2315 dev_info->rx_offload_capa = igb_get_rx_port_offloads_capa(dev) |
2316 dev_info->rx_queue_offload_capa;
2317 dev_info->tx_queue_offload_capa = igb_get_tx_queue_offloads_capa(dev);
2318 dev_info->tx_offload_capa = igb_get_tx_port_offloads_capa(dev) |
2319 dev_info->tx_queue_offload_capa;
2321 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2323 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2324 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2325 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2327 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2332 dev_info->default_txconf = (struct rte_eth_txconf) {
2334 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2335 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2336 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2341 dev_info->rx_desc_lim = rx_desc_lim;
2342 dev_info->tx_desc_lim = tx_desc_lim;
2347 /* return 0 means link status changed, -1 means not changed */
2349 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2351 struct e1000_hw *hw =
2352 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2353 struct rte_eth_link link;
2354 int link_check, count;
2357 hw->mac.get_link_status = 1;
2359 /* possible wait-to-complete in up to 9 seconds */
2360 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
2361 /* Read the real link status */
2362 switch (hw->phy.media_type) {
2363 case e1000_media_type_copper:
2364 /* Do the work to read phy */
2365 e1000_check_for_link(hw);
2366 link_check = !hw->mac.get_link_status;
2369 case e1000_media_type_fiber:
2370 e1000_check_for_link(hw);
2371 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
2375 case e1000_media_type_internal_serdes:
2376 e1000_check_for_link(hw);
2377 link_check = hw->mac.serdes_has_link;
2380 /* VF device is type_unknown */
2381 case e1000_media_type_unknown:
2382 eth_igbvf_link_update(hw);
2383 link_check = !hw->mac.get_link_status;
2389 if (link_check || wait_to_complete == 0)
2391 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
2393 memset(&link, 0, sizeof(link));
2395 /* Now we check if a transition has happened */
2397 uint16_t duplex, speed;
2398 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
2399 link.link_duplex = (duplex == FULL_DUPLEX) ?
2400 RTE_ETH_LINK_FULL_DUPLEX :
2401 RTE_ETH_LINK_HALF_DUPLEX;
2402 link.link_speed = speed;
2403 link.link_status = RTE_ETH_LINK_UP;
2404 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2405 RTE_ETH_LINK_SPEED_FIXED);
2406 } else if (!link_check) {
2407 link.link_speed = 0;
2408 link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
2409 link.link_status = RTE_ETH_LINK_DOWN;
2410 link.link_autoneg = RTE_ETH_LINK_FIXED;
2413 return rte_eth_linkstatus_set(dev, &link);
2417 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
2418 * For ASF and Pass Through versions of f/w this means
2419 * that the driver is loaded.
2422 igb_hw_control_acquire(struct e1000_hw *hw)
2426 /* Let firmware know the driver has taken over */
2427 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2428 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2432 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
2433 * For ASF and Pass Through versions of f/w this means that the
2434 * driver is no longer loaded.
2437 igb_hw_control_release(struct e1000_hw *hw)
2441 /* Let firmware taken over control of h/w */
2442 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2443 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
2444 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2448 * Bit of a misnomer, what this really means is
2449 * to enable OS management of the system... aka
2450 * to disable special hardware management features.
2453 igb_init_manageability(struct e1000_hw *hw)
2455 if (e1000_enable_mng_pass_thru(hw)) {
2456 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
2457 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2459 /* disable hardware interception of ARP */
2460 manc &= ~(E1000_MANC_ARP_EN);
2462 /* enable receiving management packets to the host */
2463 manc |= E1000_MANC_EN_MNG2HOST;
2464 manc2h |= 1 << 5; /* Mng Port 623 */
2465 manc2h |= 1 << 6; /* Mng Port 664 */
2466 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
2467 E1000_WRITE_REG(hw, E1000_MANC, manc);
2472 igb_release_manageability(struct e1000_hw *hw)
2474 if (e1000_enable_mng_pass_thru(hw)) {
2475 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2477 manc |= E1000_MANC_ARP_EN;
2478 manc &= ~E1000_MANC_EN_MNG2HOST;
2480 E1000_WRITE_REG(hw, E1000_MANC, manc);
2485 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
2487 struct e1000_hw *hw =
2488 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2491 rctl = E1000_READ_REG(hw, E1000_RCTL);
2492 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2493 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2499 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
2501 struct e1000_hw *hw =
2502 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2505 rctl = E1000_READ_REG(hw, E1000_RCTL);
2506 rctl &= (~E1000_RCTL_UPE);
2507 if (dev->data->all_multicast == 1)
2508 rctl |= E1000_RCTL_MPE;
2510 rctl &= (~E1000_RCTL_MPE);
2511 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2517 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
2519 struct e1000_hw *hw =
2520 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2523 rctl = E1000_READ_REG(hw, E1000_RCTL);
2524 rctl |= E1000_RCTL_MPE;
2525 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2531 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
2533 struct e1000_hw *hw =
2534 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2537 if (dev->data->promiscuous == 1)
2538 return 0; /* must remain in all_multicast mode */
2539 rctl = E1000_READ_REG(hw, E1000_RCTL);
2540 rctl &= (~E1000_RCTL_MPE);
2541 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2547 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2549 struct e1000_hw *hw =
2550 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2551 struct e1000_vfta * shadow_vfta =
2552 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2557 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
2558 E1000_VFTA_ENTRY_MASK);
2559 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
2560 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
2565 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
2567 /* update local VFTA copy */
2568 shadow_vfta->vfta[vid_idx] = vfta;
2574 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
2575 enum rte_vlan_type vlan_type,
2578 struct e1000_hw *hw =
2579 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2582 qinq = E1000_READ_REG(hw, E1000_CTRL_EXT);
2583 qinq &= E1000_CTRL_EXT_EXT_VLAN;
2585 /* only outer TPID of double VLAN can be configured*/
2586 if (qinq && vlan_type == RTE_ETH_VLAN_TYPE_OUTER) {
2587 reg = E1000_READ_REG(hw, E1000_VET);
2588 reg = (reg & (~E1000_VET_VET_EXT)) |
2589 ((uint32_t)tpid << E1000_VET_VET_EXT_SHIFT);
2590 E1000_WRITE_REG(hw, E1000_VET, reg);
2595 /* all other TPID values are read-only*/
2596 PMD_DRV_LOG(ERR, "Not supported");
2602 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
2604 struct e1000_hw *hw =
2605 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2608 /* Filter Table Disable */
2609 reg = E1000_READ_REG(hw, E1000_RCTL);
2610 reg &= ~E1000_RCTL_CFIEN;
2611 reg &= ~E1000_RCTL_VFE;
2612 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2616 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2618 struct e1000_hw *hw =
2619 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2620 struct e1000_vfta * shadow_vfta =
2621 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2625 /* Filter Table Enable, CFI not used for packet acceptance */
2626 reg = E1000_READ_REG(hw, E1000_RCTL);
2627 reg &= ~E1000_RCTL_CFIEN;
2628 reg |= E1000_RCTL_VFE;
2629 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2631 /* restore VFTA table */
2632 for (i = 0; i < IGB_VFTA_SIZE; i++)
2633 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
2637 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
2639 struct e1000_hw *hw =
2640 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2643 /* VLAN Mode Disable */
2644 reg = E1000_READ_REG(hw, E1000_CTRL);
2645 reg &= ~E1000_CTRL_VME;
2646 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2650 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
2652 struct e1000_hw *hw =
2653 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2656 /* VLAN Mode Enable */
2657 reg = E1000_READ_REG(hw, E1000_CTRL);
2658 reg |= E1000_CTRL_VME;
2659 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2663 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2665 struct e1000_hw *hw =
2666 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2669 /* CTRL_EXT: Extended VLAN */
2670 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2671 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
2672 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2674 /* Update maximum packet length */
2675 E1000_WRITE_REG(hw, E1000_RLPML, dev->data->mtu + E1000_ETH_OVERHEAD);
2679 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2681 struct e1000_hw *hw =
2682 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2685 /* CTRL_EXT: Extended VLAN */
2686 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2687 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
2688 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2690 /* Update maximum packet length */
2691 E1000_WRITE_REG(hw, E1000_RLPML,
2692 dev->data->mtu + E1000_ETH_OVERHEAD + VLAN_TAG_SIZE);
2696 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2698 struct rte_eth_rxmode *rxmode;
2700 rxmode = &dev->data->dev_conf.rxmode;
2701 if (mask & RTE_ETH_VLAN_STRIP_MASK) {
2702 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
2703 igb_vlan_hw_strip_enable(dev);
2705 igb_vlan_hw_strip_disable(dev);
2708 if (mask & RTE_ETH_VLAN_FILTER_MASK) {
2709 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
2710 igb_vlan_hw_filter_enable(dev);
2712 igb_vlan_hw_filter_disable(dev);
2715 if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
2716 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
2717 igb_vlan_hw_extend_enable(dev);
2719 igb_vlan_hw_extend_disable(dev);
2727 * It enables the interrupt mask and then enable the interrupt.
2730 * Pointer to struct rte_eth_dev.
2735 * - On success, zero.
2736 * - On failure, a negative value.
2739 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
2741 struct e1000_interrupt *intr =
2742 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2745 intr->mask |= E1000_ICR_LSC;
2747 intr->mask &= ~E1000_ICR_LSC;
2752 /* It clears the interrupt causes and enables the interrupt.
2753 * It will be called once only during nic initialized.
2756 * Pointer to struct rte_eth_dev.
2759 * - On success, zero.
2760 * - On failure, a negative value.
2762 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev)
2764 uint32_t mask, regval;
2766 struct e1000_hw *hw =
2767 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2768 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2769 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2770 int misc_shift = rte_intr_allow_others(intr_handle) ? 1 : 0;
2771 struct rte_eth_dev_info dev_info;
2773 memset(&dev_info, 0, sizeof(dev_info));
2774 ret = eth_igb_infos_get(dev, &dev_info);
2778 mask = (0xFFFFFFFF >> (32 - dev_info.max_rx_queues)) << misc_shift;
2779 regval = E1000_READ_REG(hw, E1000_EIMS);
2780 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
2786 * It reads ICR and gets interrupt causes, check it and set a bit flag
2787 * to update link status.
2790 * Pointer to struct rte_eth_dev.
2793 * - On success, zero.
2794 * - On failure, a negative value.
2797 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
2800 struct e1000_hw *hw =
2801 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2802 struct e1000_interrupt *intr =
2803 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2805 igb_intr_disable(dev);
2807 /* read-on-clear nic registers here */
2808 icr = E1000_READ_REG(hw, E1000_ICR);
2811 if (icr & E1000_ICR_LSC) {
2812 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
2815 if (icr & E1000_ICR_VMMB)
2816 intr->flags |= E1000_FLAG_MAILBOX;
2822 * It executes link_update after knowing an interrupt is present.
2825 * Pointer to struct rte_eth_dev.
2828 * - On success, zero.
2829 * - On failure, a negative value.
2832 eth_igb_interrupt_action(struct rte_eth_dev *dev,
2833 struct rte_intr_handle *intr_handle)
2835 struct e1000_hw *hw =
2836 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2837 struct e1000_interrupt *intr =
2838 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2839 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2840 struct rte_eth_link link;
2843 if (intr->flags & E1000_FLAG_MAILBOX) {
2844 igb_pf_mbx_process(dev);
2845 intr->flags &= ~E1000_FLAG_MAILBOX;
2848 igb_intr_enable(dev);
2849 rte_intr_ack(intr_handle);
2851 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
2852 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
2854 /* set get_link_status to check register later */
2855 hw->mac.get_link_status = 1;
2856 ret = eth_igb_link_update(dev, 0);
2858 /* check if link has changed */
2862 rte_eth_linkstatus_get(dev, &link);
2863 if (link.link_status) {
2865 " Port %d: Link Up - speed %u Mbps - %s",
2867 (unsigned)link.link_speed,
2868 link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
2869 "full-duplex" : "half-duplex");
2871 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2872 dev->data->port_id);
2875 PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
2876 pci_dev->addr.domain,
2878 pci_dev->addr.devid,
2879 pci_dev->addr.function);
2880 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
2887 * Interrupt handler which shall be registered at first.
2890 * Pointer to interrupt handle.
2892 * The address of parameter (struct rte_eth_dev *) registered before.
2898 eth_igb_interrupt_handler(void *param)
2900 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2902 eth_igb_interrupt_get_status(dev);
2903 eth_igb_interrupt_action(dev, dev->intr_handle);
2907 eth_igbvf_interrupt_get_status(struct rte_eth_dev *dev)
2910 struct e1000_hw *hw =
2911 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2912 struct e1000_interrupt *intr =
2913 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2915 igbvf_intr_disable(hw);
2917 /* read-on-clear nic registers here */
2918 eicr = E1000_READ_REG(hw, E1000_EICR);
2921 if (eicr == E1000_VTIVAR_MISC_MAILBOX)
2922 intr->flags |= E1000_FLAG_MAILBOX;
2927 void igbvf_mbx_process(struct rte_eth_dev *dev)
2929 struct e1000_hw *hw =
2930 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2931 struct e1000_mbx_info *mbx = &hw->mbx;
2934 /* peek the message first */
2935 in_msg = E1000_READ_REG(hw, E1000_VMBMEM(0));
2937 /* PF reset VF event */
2938 if (in_msg == E1000_PF_CONTROL_MSG) {
2939 /* dummy mbx read to ack pf */
2940 if (mbx->ops.read(hw, &in_msg, 1, 0))
2942 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
2948 eth_igbvf_interrupt_action(struct rte_eth_dev *dev, struct rte_intr_handle *intr_handle)
2950 struct e1000_interrupt *intr =
2951 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2953 if (intr->flags & E1000_FLAG_MAILBOX) {
2954 igbvf_mbx_process(dev);
2955 intr->flags &= ~E1000_FLAG_MAILBOX;
2958 igbvf_intr_enable(dev);
2959 rte_intr_ack(intr_handle);
2965 eth_igbvf_interrupt_handler(void *param)
2967 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2969 eth_igbvf_interrupt_get_status(dev);
2970 eth_igbvf_interrupt_action(dev, dev->intr_handle);
2974 eth_igb_led_on(struct rte_eth_dev *dev)
2976 struct e1000_hw *hw;
2978 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2979 return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
2983 eth_igb_led_off(struct rte_eth_dev *dev)
2985 struct e1000_hw *hw;
2987 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2988 return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
2992 eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2994 struct e1000_hw *hw;
2999 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3000 fc_conf->pause_time = hw->fc.pause_time;
3001 fc_conf->high_water = hw->fc.high_water;
3002 fc_conf->low_water = hw->fc.low_water;
3003 fc_conf->send_xon = hw->fc.send_xon;
3004 fc_conf->autoneg = hw->mac.autoneg;
3007 * Return rx_pause and tx_pause status according to actual setting of
3008 * the TFCE and RFCE bits in the CTRL register.
3010 ctrl = E1000_READ_REG(hw, E1000_CTRL);
3011 if (ctrl & E1000_CTRL_TFCE)
3016 if (ctrl & E1000_CTRL_RFCE)
3021 if (rx_pause && tx_pause)
3022 fc_conf->mode = RTE_ETH_FC_FULL;
3024 fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
3026 fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
3028 fc_conf->mode = RTE_ETH_FC_NONE;
3034 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3036 struct e1000_hw *hw;
3038 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
3044 uint32_t rx_buf_size;
3045 uint32_t max_high_water;
3049 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3050 if (fc_conf->autoneg != hw->mac.autoneg)
3052 rx_buf_size = igb_get_rx_buffer_size(hw);
3053 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
3055 /* At least reserve one Ethernet frame for watermark */
3056 max_high_water = rx_buf_size - RTE_ETHER_MAX_LEN;
3057 if ((fc_conf->high_water > max_high_water) ||
3058 (fc_conf->high_water < fc_conf->low_water)) {
3059 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
3060 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
3064 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
3065 hw->fc.pause_time = fc_conf->pause_time;
3066 hw->fc.high_water = fc_conf->high_water;
3067 hw->fc.low_water = fc_conf->low_water;
3068 hw->fc.send_xon = fc_conf->send_xon;
3070 err = e1000_setup_link_generic(hw);
3071 if (err == E1000_SUCCESS) {
3073 /* check if we want to forward MAC frames - driver doesn't have native
3074 * capability to do that, so we'll write the registers ourselves */
3076 rctl = E1000_READ_REG(hw, E1000_RCTL);
3078 /* set or clear MFLCN.PMCF bit depending on configuration */
3079 if (fc_conf->mac_ctrl_frame_fwd != 0)
3080 rctl |= E1000_RCTL_PMCF;
3082 rctl &= ~E1000_RCTL_PMCF;
3084 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3087 * check if we want to change flow control mode - driver doesn't have native
3088 * capability to do that, so we'll write the registers ourselves
3090 ctrl = E1000_READ_REG(hw, E1000_CTRL);
3093 * set or clear E1000_CTRL_RFCE and E1000_CTRL_TFCE bits depending
3096 switch (fc_conf->mode) {
3097 case RTE_ETH_FC_NONE:
3098 ctrl &= ~E1000_CTRL_RFCE & ~E1000_CTRL_TFCE;
3100 case RTE_ETH_FC_RX_PAUSE:
3101 ctrl |= E1000_CTRL_RFCE;
3102 ctrl &= ~E1000_CTRL_TFCE;
3104 case RTE_ETH_FC_TX_PAUSE:
3105 ctrl |= E1000_CTRL_TFCE;
3106 ctrl &= ~E1000_CTRL_RFCE;
3108 case RTE_ETH_FC_FULL:
3109 ctrl |= E1000_CTRL_RFCE | E1000_CTRL_TFCE;
3112 PMD_INIT_LOG(ERR, "invalid flow control mode");
3116 E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
3118 E1000_WRITE_FLUSH(hw);
3123 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
3127 #define E1000_RAH_POOLSEL_SHIFT (18)
3129 eth_igb_rar_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
3130 uint32_t index, uint32_t pool)
3132 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3135 e1000_rar_set(hw, mac_addr->addr_bytes, index);
3136 rah = E1000_READ_REG(hw, E1000_RAH(index));
3137 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
3138 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
3143 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
3145 uint8_t addr[RTE_ETHER_ADDR_LEN];
3146 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3148 memset(addr, 0, sizeof(addr));
3150 e1000_rar_set(hw, addr, index);
3154 eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
3155 struct rte_ether_addr *addr)
3157 eth_igb_rar_clear(dev, 0);
3158 eth_igb_rar_set(dev, (void *)addr, 0, 0);
3163 * Virtual Function operations
3166 igbvf_intr_disable(struct e1000_hw *hw)
3168 PMD_INIT_FUNC_TRACE();
3170 /* Clear interrupt mask to stop from interrupts being generated */
3171 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
3173 E1000_WRITE_FLUSH(hw);
3177 igbvf_stop_adapter(struct rte_eth_dev *dev)
3181 struct rte_eth_dev_info dev_info;
3182 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3185 memset(&dev_info, 0, sizeof(dev_info));
3186 ret = eth_igbvf_infos_get(dev, &dev_info);
3190 /* Clear interrupt mask to stop from interrupts being generated */
3191 igbvf_intr_disable(hw);
3193 /* Clear any pending interrupts, flush previous writes */
3194 E1000_READ_REG(hw, E1000_EICR);
3196 /* Disable the transmit unit. Each queue must be disabled. */
3197 for (i = 0; i < dev_info.max_tx_queues; i++)
3198 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
3200 /* Disable the receive unit by stopping each queue */
3201 for (i = 0; i < dev_info.max_rx_queues; i++) {
3202 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
3203 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
3204 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
3205 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
3209 /* flush all queues disables */
3210 E1000_WRITE_FLUSH(hw);
3214 static int eth_igbvf_link_update(struct e1000_hw *hw)
3216 struct e1000_mbx_info *mbx = &hw->mbx;
3217 struct e1000_mac_info *mac = &hw->mac;
3218 int ret_val = E1000_SUCCESS;
3220 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
3223 * We only want to run this if there has been a rst asserted.
3224 * in this case that could mean a link change, device reset,
3225 * or a virtual function reset
3228 /* If we were hit with a reset or timeout drop the link */
3229 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
3230 mac->get_link_status = TRUE;
3232 if (!mac->get_link_status)
3235 /* if link status is down no point in checking to see if pf is up */
3236 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
3239 /* if we passed all the tests above then the link is up and we no
3240 * longer need to check for link */
3241 mac->get_link_status = FALSE;
3249 igbvf_dev_configure(struct rte_eth_dev *dev)
3251 struct rte_eth_conf* conf = &dev->data->dev_conf;
3253 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
3254 dev->data->port_id);
3256 if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
3257 dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
3260 * VF has no ability to enable/disable HW CRC
3261 * Keep the persistent behavior the same as Host PF
3263 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
3264 if (conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
3265 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
3266 conf->rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_KEEP_CRC;
3269 if (!(conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)) {
3270 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
3271 conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
3279 igbvf_dev_start(struct rte_eth_dev *dev)
3281 struct e1000_hw *hw =
3282 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3283 struct e1000_adapter *adapter =
3284 E1000_DEV_PRIVATE(dev->data->dev_private);
3285 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3286 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
3288 uint32_t intr_vector = 0;
3290 PMD_INIT_FUNC_TRACE();
3292 hw->mac.ops.reset_hw(hw);
3293 adapter->stopped = 0;
3296 igbvf_set_vfta_all(dev,1);
3298 eth_igbvf_tx_init(dev);
3300 /* This can fail when allocating mbufs for descriptor rings */
3301 ret = eth_igbvf_rx_init(dev);
3303 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
3304 igb_dev_clear_queues(dev);
3308 /* check and configure queue intr-vector mapping */
3309 if (rte_intr_cap_multiple(intr_handle) &&
3310 dev->data->dev_conf.intr_conf.rxq) {
3311 intr_vector = dev->data->nb_rx_queues;
3312 ret = rte_intr_efd_enable(intr_handle, intr_vector);
3317 /* Allocate the vector list */
3318 if (rte_intr_dp_is_en(intr_handle)) {
3319 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
3320 dev->data->nb_rx_queues)) {
3321 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
3322 " intr_vec", dev->data->nb_rx_queues);
3327 eth_igbvf_configure_msix_intr(dev);
3329 /* enable uio/vfio intr/eventfd mapping */
3330 rte_intr_enable(intr_handle);
3332 /* resume enabled intr since hw reset */
3333 igbvf_intr_enable(dev);
3339 igbvf_dev_stop(struct rte_eth_dev *dev)
3341 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3342 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
3343 struct e1000_adapter *adapter =
3344 E1000_DEV_PRIVATE(dev->data->dev_private);
3346 if (adapter->stopped)
3349 PMD_INIT_FUNC_TRACE();
3351 igbvf_stop_adapter(dev);
3354 * Clear what we set, but we still keep shadow_vfta to
3355 * restore after device starts
3357 igbvf_set_vfta_all(dev,0);
3359 igb_dev_clear_queues(dev);
3361 /* disable intr eventfd mapping */
3362 rte_intr_disable(intr_handle);
3364 /* Clean datapath event and queue/vec mapping */
3365 rte_intr_efd_disable(intr_handle);
3367 /* Clean vector list */
3368 rte_intr_vec_list_free(intr_handle);
3370 adapter->stopped = true;
3371 dev->data->dev_started = 0;
3377 igbvf_dev_close(struct rte_eth_dev *dev)
3379 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3380 struct rte_ether_addr addr;
3381 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3384 PMD_INIT_FUNC_TRACE();
3386 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3391 ret = igbvf_dev_stop(dev);
3395 igb_dev_free_queues(dev);
3398 * reprogram the RAR with a zero mac address,
3399 * to ensure that the VF traffic goes to the PF
3400 * after stop, close and detach of the VF.
3403 memset(&addr, 0, sizeof(addr));
3404 igbvf_default_mac_addr_set(dev, &addr);
3406 rte_intr_callback_unregister(pci_dev->intr_handle,
3407 eth_igbvf_interrupt_handler,
3414 igbvf_promiscuous_enable(struct rte_eth_dev *dev)
3416 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3418 /* Set both unicast and multicast promisc */
3419 e1000_promisc_set_vf(hw, e1000_promisc_enabled);
3425 igbvf_promiscuous_disable(struct rte_eth_dev *dev)
3427 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3429 /* If in allmulticast mode leave multicast promisc */
3430 if (dev->data->all_multicast == 1)
3431 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3433 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3439 igbvf_allmulticast_enable(struct rte_eth_dev *dev)
3441 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3443 /* In promiscuous mode multicast promisc already set */
3444 if (dev->data->promiscuous == 0)
3445 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3451 igbvf_allmulticast_disable(struct rte_eth_dev *dev)
3453 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3455 /* In promiscuous mode leave multicast promisc enabled */
3456 if (dev->data->promiscuous == 0)
3457 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3462 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
3464 struct e1000_mbx_info *mbx = &hw->mbx;
3468 /* After set vlan, vlan strip will also be enabled in igb driver*/
3469 msgbuf[0] = E1000_VF_SET_VLAN;
3471 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
3473 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
3475 err = mbx->ops.write_posted(hw, msgbuf, 2, 0);
3479 err = mbx->ops.read_posted(hw, msgbuf, 2, 0);
3483 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
3484 if (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK))
3491 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
3493 struct e1000_hw *hw =
3494 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3495 struct e1000_vfta * shadow_vfta =
3496 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3497 int i = 0, j = 0, vfta = 0, mask = 1;
3499 for (i = 0; i < IGB_VFTA_SIZE; i++){
3500 vfta = shadow_vfta->vfta[i];
3503 for (j = 0; j < 32; j++){
3506 (uint16_t)((i<<5)+j), on);
3515 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3517 struct e1000_hw *hw =
3518 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3519 struct e1000_vfta * shadow_vfta =
3520 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3521 uint32_t vid_idx = 0;
3522 uint32_t vid_bit = 0;
3525 PMD_INIT_FUNC_TRACE();
3527 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
3528 ret = igbvf_set_vfta(hw, vlan_id, !!on);
3530 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
3533 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
3534 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
3536 /*Save what we set and retore it after device reset*/
3538 shadow_vfta->vfta[vid_idx] |= vid_bit;
3540 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
3546 igbvf_default_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
3548 struct e1000_hw *hw =
3549 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3551 /* index is not used by rar_set() */
3552 hw->mac.ops.rar_set(hw, (void *)addr, 0);
3558 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
3559 struct rte_eth_rss_reta_entry64 *reta_conf,
3564 uint16_t idx, shift;
3565 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3567 if (reta_size != RTE_ETH_RSS_RETA_SIZE_128) {
3568 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3569 "(%d) doesn't match the number hardware can supported "
3570 "(%d)", reta_size, RTE_ETH_RSS_RETA_SIZE_128);
3574 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3575 idx = i / RTE_ETH_RETA_GROUP_SIZE;
3576 shift = i % RTE_ETH_RETA_GROUP_SIZE;
3577 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3581 if (mask == IGB_4_BIT_MASK)
3584 r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3585 for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
3586 if (mask & (0x1 << j))
3587 reta |= reta_conf[idx].reta[shift + j] <<
3590 reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
3592 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
3599 eth_igb_rss_reta_query(struct rte_eth_dev *dev,
3600 struct rte_eth_rss_reta_entry64 *reta_conf,
3605 uint16_t idx, shift;
3606 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3608 if (reta_size != RTE_ETH_RSS_RETA_SIZE_128) {
3609 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3610 "(%d) doesn't match the number hardware can supported "
3611 "(%d)", reta_size, RTE_ETH_RSS_RETA_SIZE_128);
3615 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3616 idx = i / RTE_ETH_RETA_GROUP_SIZE;
3617 shift = i % RTE_ETH_RETA_GROUP_SIZE;
3618 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3622 reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3623 for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
3624 if (mask & (0x1 << j))
3625 reta_conf[idx].reta[shift + j] =
3626 ((reta >> (CHAR_BIT * j)) &
3635 eth_igb_syn_filter_set(struct rte_eth_dev *dev,
3636 struct rte_eth_syn_filter *filter,
3639 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3640 struct e1000_filter_info *filter_info =
3641 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3642 uint32_t synqf, rfctl;
3644 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3647 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3650 if (synqf & E1000_SYN_FILTER_ENABLE)
3653 synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
3654 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
3656 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3657 if (filter->hig_pri)
3658 rfctl |= E1000_RFCTL_SYNQFP;
3660 rfctl &= ~E1000_RFCTL_SYNQFP;
3662 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
3664 if (!(synqf & E1000_SYN_FILTER_ENABLE))
3669 filter_info->syn_info = synqf;
3670 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
3671 E1000_WRITE_FLUSH(hw);
3675 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
3677 ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
3678 struct e1000_2tuple_filter_info *filter_info)
3680 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3682 if (filter->priority > E1000_2TUPLE_MAX_PRI)
3683 return -EINVAL; /* filter index is out of range. */
3684 if (filter->tcp_flags > RTE_NTUPLE_TCP_FLAGS_MASK)
3685 return -EINVAL; /* flags is invalid. */
3687 switch (filter->dst_port_mask) {
3689 filter_info->dst_port_mask = 0;
3690 filter_info->dst_port = filter->dst_port;
3693 filter_info->dst_port_mask = 1;
3696 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3700 switch (filter->proto_mask) {
3702 filter_info->proto_mask = 0;
3703 filter_info->proto = filter->proto;
3706 filter_info->proto_mask = 1;
3709 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3713 filter_info->priority = (uint8_t)filter->priority;
3714 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3715 filter_info->tcp_flags = filter->tcp_flags;
3717 filter_info->tcp_flags = 0;
3722 static inline struct e1000_2tuple_filter *
3723 igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
3724 struct e1000_2tuple_filter_info *key)
3726 struct e1000_2tuple_filter *it;
3728 TAILQ_FOREACH(it, filter_list, entries) {
3729 if (memcmp(key, &it->filter_info,
3730 sizeof(struct e1000_2tuple_filter_info)) == 0) {
3737 /* inject a igb 2tuple filter to HW */
3739 igb_inject_2uple_filter(struct rte_eth_dev *dev,
3740 struct e1000_2tuple_filter *filter)
3742 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3743 uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
3744 uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3748 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3749 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3750 imir |= E1000_IMIR_PORT_BP;
3752 imir &= ~E1000_IMIR_PORT_BP;
3754 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3756 ttqf |= E1000_TTQF_QUEUE_ENABLE;
3757 ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
3758 ttqf |= (uint32_t)(filter->filter_info.proto &
3759 E1000_TTQF_PROTOCOL_MASK);
3760 if (filter->filter_info.proto_mask == 0)
3761 ttqf &= ~E1000_TTQF_MASK_ENABLE;
3763 /* tcp flags bits setting. */
3764 if (filter->filter_info.tcp_flags & RTE_NTUPLE_TCP_FLAGS_MASK) {
3765 if (filter->filter_info.tcp_flags & RTE_TCP_URG_FLAG)
3766 imir_ext |= E1000_IMIREXT_CTRL_URG;
3767 if (filter->filter_info.tcp_flags & RTE_TCP_ACK_FLAG)
3768 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3769 if (filter->filter_info.tcp_flags & RTE_TCP_PSH_FLAG)
3770 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3771 if (filter->filter_info.tcp_flags & RTE_TCP_RST_FLAG)
3772 imir_ext |= E1000_IMIREXT_CTRL_RST;
3773 if (filter->filter_info.tcp_flags & RTE_TCP_SYN_FLAG)
3774 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3775 if (filter->filter_info.tcp_flags & RTE_TCP_FIN_FLAG)
3776 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3778 imir_ext |= E1000_IMIREXT_CTRL_BP;
3780 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3781 E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
3782 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3786 * igb_add_2tuple_filter - add a 2tuple filter
3789 * dev: Pointer to struct rte_eth_dev.
3790 * ntuple_filter: pointer to the filter that will be added.
3793 * - On success, zero.
3794 * - On failure, a negative value.
3797 igb_add_2tuple_filter(struct rte_eth_dev *dev,
3798 struct rte_eth_ntuple_filter *ntuple_filter)
3800 struct e1000_filter_info *filter_info =
3801 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3802 struct e1000_2tuple_filter *filter;
3805 filter = rte_zmalloc("e1000_2tuple_filter",
3806 sizeof(struct e1000_2tuple_filter), 0);
3810 ret = ntuple_filter_to_2tuple(ntuple_filter,
3811 &filter->filter_info);
3816 if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3817 &filter->filter_info) != NULL) {
3818 PMD_DRV_LOG(ERR, "filter exists.");
3822 filter->queue = ntuple_filter->queue;
3825 * look for an unused 2tuple filter index,
3826 * and insert the filter to list.
3828 for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
3829 if (!(filter_info->twotuple_mask & (1 << i))) {
3830 filter_info->twotuple_mask |= 1 << i;
3832 TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
3838 if (i >= E1000_MAX_TTQF_FILTERS) {
3839 PMD_DRV_LOG(ERR, "2tuple filters are full.");
3844 igb_inject_2uple_filter(dev, filter);
3849 igb_delete_2tuple_filter(struct rte_eth_dev *dev,
3850 struct e1000_2tuple_filter *filter)
3852 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3853 struct e1000_filter_info *filter_info =
3854 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3856 filter_info->twotuple_mask &= ~(1 << filter->index);
3857 TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
3860 E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
3861 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3862 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3867 * igb_remove_2tuple_filter - remove a 2tuple filter
3870 * dev: Pointer to struct rte_eth_dev.
3871 * ntuple_filter: pointer to the filter that will be removed.
3874 * - On success, zero.
3875 * - On failure, a negative value.
3878 igb_remove_2tuple_filter(struct rte_eth_dev *dev,
3879 struct rte_eth_ntuple_filter *ntuple_filter)
3881 struct e1000_filter_info *filter_info =
3882 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3883 struct e1000_2tuple_filter_info filter_2tuple;
3884 struct e1000_2tuple_filter *filter;
3887 memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
3888 ret = ntuple_filter_to_2tuple(ntuple_filter,
3893 filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3895 if (filter == NULL) {
3896 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3900 igb_delete_2tuple_filter(dev, filter);
3905 /* inject a igb flex filter to HW */
3907 igb_inject_flex_filter(struct rte_eth_dev *dev,
3908 struct e1000_flex_filter *filter)
3910 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3911 uint32_t wufc, queueing;
3915 wufc = E1000_READ_REG(hw, E1000_WUFC);
3916 if (filter->index < E1000_MAX_FHFT)
3917 reg_off = E1000_FHFT(filter->index);
3919 reg_off = E1000_FHFT_EXT(filter->index - E1000_MAX_FHFT);
3921 E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
3922 (E1000_WUFC_FLX0 << filter->index));
3923 queueing = filter->filter_info.len |
3924 (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
3925 (filter->filter_info.priority <<
3926 E1000_FHFT_QUEUEING_PRIO_SHIFT);
3927 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
3930 for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
3931 E1000_WRITE_REG(hw, reg_off,
3932 filter->filter_info.dwords[j]);
3933 reg_off += sizeof(uint32_t);
3934 E1000_WRITE_REG(hw, reg_off,
3935 filter->filter_info.dwords[++j]);
3936 reg_off += sizeof(uint32_t);
3937 E1000_WRITE_REG(hw, reg_off,
3938 (uint32_t)filter->filter_info.mask[i]);
3939 reg_off += sizeof(uint32_t) * 2;
3944 static inline struct e1000_flex_filter *
3945 eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
3946 struct e1000_flex_filter_info *key)
3948 struct e1000_flex_filter *it;
3950 TAILQ_FOREACH(it, filter_list, entries) {
3951 if (memcmp(key, &it->filter_info,
3952 sizeof(struct e1000_flex_filter_info)) == 0)
3959 /* remove a flex byte filter
3961 * dev: Pointer to struct rte_eth_dev.
3962 * filter: the pointer of the filter will be removed.
3965 igb_remove_flex_filter(struct rte_eth_dev *dev,
3966 struct e1000_flex_filter *filter)
3968 struct e1000_filter_info *filter_info =
3969 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3970 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3974 wufc = E1000_READ_REG(hw, E1000_WUFC);
3975 if (filter->index < E1000_MAX_FHFT)
3976 reg_off = E1000_FHFT(filter->index);
3978 reg_off = E1000_FHFT_EXT(filter->index - E1000_MAX_FHFT);
3980 for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
3981 E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
3983 E1000_WRITE_REG(hw, E1000_WUFC, wufc &
3984 (~(E1000_WUFC_FLX0 << filter->index)));
3986 filter_info->flex_mask &= ~(1 << filter->index);
3987 TAILQ_REMOVE(&filter_info->flex_list, filter, entries);
3992 eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
3993 struct igb_flex_filter *filter,
3996 struct e1000_filter_info *filter_info =
3997 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3998 struct e1000_flex_filter *flex_filter, *it;
4002 flex_filter = rte_zmalloc("e1000_flex_filter",
4003 sizeof(struct e1000_flex_filter), 0);
4004 if (flex_filter == NULL)
4007 flex_filter->filter_info.len = filter->len;
4008 flex_filter->filter_info.priority = filter->priority;
4009 memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
4010 for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
4012 /* reverse bits in flex filter's mask*/
4013 for (shift = 0; shift < CHAR_BIT; shift++) {
4014 if (filter->mask[i] & (0x01 << shift))
4015 mask |= (0x80 >> shift);
4017 flex_filter->filter_info.mask[i] = mask;
4020 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
4021 &flex_filter->filter_info);
4022 if (it == NULL && !add) {
4023 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4024 rte_free(flex_filter);
4027 if (it != NULL && add) {
4028 PMD_DRV_LOG(ERR, "filter exists.");
4029 rte_free(flex_filter);
4034 flex_filter->queue = filter->queue;
4036 * look for an unused flex filter index
4037 * and insert the filter into the list.
4039 for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
4040 if (!(filter_info->flex_mask & (1 << i))) {
4041 filter_info->flex_mask |= 1 << i;
4042 flex_filter->index = i;
4043 TAILQ_INSERT_TAIL(&filter_info->flex_list,
4049 if (i >= E1000_MAX_FLEX_FILTERS) {
4050 PMD_DRV_LOG(ERR, "flex filters are full.");
4051 rte_free(flex_filter);
4055 igb_inject_flex_filter(dev, flex_filter);
4058 igb_remove_flex_filter(dev, it);
4059 rte_free(flex_filter);
4065 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
4067 ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
4068 struct e1000_5tuple_filter_info *filter_info)
4070 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
4072 if (filter->priority > E1000_2TUPLE_MAX_PRI)
4073 return -EINVAL; /* filter index is out of range. */
4074 if (filter->tcp_flags > RTE_NTUPLE_TCP_FLAGS_MASK)
4075 return -EINVAL; /* flags is invalid. */
4077 switch (filter->dst_ip_mask) {
4079 filter_info->dst_ip_mask = 0;
4080 filter_info->dst_ip = filter->dst_ip;
4083 filter_info->dst_ip_mask = 1;
4086 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
4090 switch (filter->src_ip_mask) {
4092 filter_info->src_ip_mask = 0;
4093 filter_info->src_ip = filter->src_ip;
4096 filter_info->src_ip_mask = 1;
4099 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
4103 switch (filter->dst_port_mask) {
4105 filter_info->dst_port_mask = 0;
4106 filter_info->dst_port = filter->dst_port;
4109 filter_info->dst_port_mask = 1;
4112 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
4116 switch (filter->src_port_mask) {
4118 filter_info->src_port_mask = 0;
4119 filter_info->src_port = filter->src_port;
4122 filter_info->src_port_mask = 1;
4125 PMD_DRV_LOG(ERR, "invalid src_port mask.");
4129 switch (filter->proto_mask) {
4131 filter_info->proto_mask = 0;
4132 filter_info->proto = filter->proto;
4135 filter_info->proto_mask = 1;
4138 PMD_DRV_LOG(ERR, "invalid protocol mask.");
4142 filter_info->priority = (uint8_t)filter->priority;
4143 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
4144 filter_info->tcp_flags = filter->tcp_flags;
4146 filter_info->tcp_flags = 0;
4151 static inline struct e1000_5tuple_filter *
4152 igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
4153 struct e1000_5tuple_filter_info *key)
4155 struct e1000_5tuple_filter *it;
4157 TAILQ_FOREACH(it, filter_list, entries) {
4158 if (memcmp(key, &it->filter_info,
4159 sizeof(struct e1000_5tuple_filter_info)) == 0) {
4166 /* inject a igb 5-tuple filter to HW */
4168 igb_inject_5tuple_filter_82576(struct rte_eth_dev *dev,
4169 struct e1000_5tuple_filter *filter)
4171 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4172 uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
4173 uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
4177 ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
4178 if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
4179 ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
4180 if (filter->filter_info.dst_ip_mask == 0)
4181 ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
4182 if (filter->filter_info.src_port_mask == 0)
4183 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
4184 if (filter->filter_info.proto_mask == 0)
4185 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
4186 ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
4187 E1000_FTQF_QUEUE_MASK;
4188 ftqf |= E1000_FTQF_QUEUE_ENABLE;
4189 E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
4190 E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
4191 E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
4193 spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
4194 E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
4196 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
4197 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
4198 imir |= E1000_IMIR_PORT_BP;
4200 imir &= ~E1000_IMIR_PORT_BP;
4201 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
4203 /* tcp flags bits setting. */
4204 if (filter->filter_info.tcp_flags & RTE_NTUPLE_TCP_FLAGS_MASK) {
4205 if (filter->filter_info.tcp_flags & RTE_TCP_URG_FLAG)
4206 imir_ext |= E1000_IMIREXT_CTRL_URG;
4207 if (filter->filter_info.tcp_flags & RTE_TCP_ACK_FLAG)
4208 imir_ext |= E1000_IMIREXT_CTRL_ACK;
4209 if (filter->filter_info.tcp_flags & RTE_TCP_PSH_FLAG)
4210 imir_ext |= E1000_IMIREXT_CTRL_PSH;
4211 if (filter->filter_info.tcp_flags & RTE_TCP_RST_FLAG)
4212 imir_ext |= E1000_IMIREXT_CTRL_RST;
4213 if (filter->filter_info.tcp_flags & RTE_TCP_SYN_FLAG)
4214 imir_ext |= E1000_IMIREXT_CTRL_SYN;
4215 if (filter->filter_info.tcp_flags & RTE_TCP_FIN_FLAG)
4216 imir_ext |= E1000_IMIREXT_CTRL_FIN;
4218 imir_ext |= E1000_IMIREXT_CTRL_BP;
4220 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
4221 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
4225 * igb_add_5tuple_filter_82576 - add a 5tuple filter
4228 * dev: Pointer to struct rte_eth_dev.
4229 * ntuple_filter: pointer to the filter that will be added.
4232 * - On success, zero.
4233 * - On failure, a negative value.
4236 igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
4237 struct rte_eth_ntuple_filter *ntuple_filter)
4239 struct e1000_filter_info *filter_info =
4240 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4241 struct e1000_5tuple_filter *filter;
4245 filter = rte_zmalloc("e1000_5tuple_filter",
4246 sizeof(struct e1000_5tuple_filter), 0);
4250 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4251 &filter->filter_info);
4257 if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4258 &filter->filter_info) != NULL) {
4259 PMD_DRV_LOG(ERR, "filter exists.");
4263 filter->queue = ntuple_filter->queue;
4266 * look for an unused 5tuple filter index,
4267 * and insert the filter to list.
4269 for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
4270 if (!(filter_info->fivetuple_mask & (1 << i))) {
4271 filter_info->fivetuple_mask |= 1 << i;
4273 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
4279 if (i >= E1000_MAX_FTQF_FILTERS) {
4280 PMD_DRV_LOG(ERR, "5tuple filters are full.");
4285 igb_inject_5tuple_filter_82576(dev, filter);
4290 igb_delete_5tuple_filter_82576(struct rte_eth_dev *dev,
4291 struct e1000_5tuple_filter *filter)
4293 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4294 struct e1000_filter_info *filter_info =
4295 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4297 filter_info->fivetuple_mask &= ~(1 << filter->index);
4298 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
4301 E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
4302 E1000_FTQF_VF_BP | E1000_FTQF_MASK);
4303 E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
4304 E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
4305 E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
4306 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
4307 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
4312 * igb_remove_5tuple_filter_82576 - remove a 5tuple filter
4315 * dev: Pointer to struct rte_eth_dev.
4316 * ntuple_filter: pointer to the filter that will be removed.
4319 * - On success, zero.
4320 * - On failure, a negative value.
4323 igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
4324 struct rte_eth_ntuple_filter *ntuple_filter)
4326 struct e1000_filter_info *filter_info =
4327 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4328 struct e1000_5tuple_filter_info filter_5tuple;
4329 struct e1000_5tuple_filter *filter;
4332 memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
4333 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4338 filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4340 if (filter == NULL) {
4341 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4345 igb_delete_5tuple_filter_82576(dev, filter);
4351 eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
4354 struct e1000_hw *hw;
4355 uint32_t frame_size = mtu + E1000_ETH_OVERHEAD;
4357 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4359 #ifdef RTE_LIBRTE_82571_SUPPORT
4360 /* XXX: not bigger than max_rx_pktlen */
4361 if (hw->mac.type == e1000_82571)
4365 * If device is started, refuse mtu that requires the support of
4366 * scattered packets when this feature has not been enabled before.
4368 if (dev->data->dev_started && !dev->data->scattered_rx &&
4369 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
4370 PMD_INIT_LOG(ERR, "Stop port first.");
4374 rctl = E1000_READ_REG(hw, E1000_RCTL);
4376 /* switch to jumbo mode if needed */
4377 if (mtu > RTE_ETHER_MTU)
4378 rctl |= E1000_RCTL_LPE;
4380 rctl &= ~E1000_RCTL_LPE;
4381 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
4383 E1000_WRITE_REG(hw, E1000_RLPML, frame_size);
4389 * igb_add_del_ntuple_filter - add or delete a ntuple filter
4392 * dev: Pointer to struct rte_eth_dev.
4393 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4394 * add: if true, add filter, if false, remove filter
4397 * - On success, zero.
4398 * - On failure, a negative value.
4401 igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
4402 struct rte_eth_ntuple_filter *ntuple_filter,
4405 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4408 switch (ntuple_filter->flags) {
4409 case RTE_5TUPLE_FLAGS:
4410 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4411 if (hw->mac.type != e1000_82576)
4414 ret = igb_add_5tuple_filter_82576(dev,
4417 ret = igb_remove_5tuple_filter_82576(dev,
4420 case RTE_2TUPLE_FLAGS:
4421 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4422 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350 &&
4423 hw->mac.type != e1000_i210 &&
4424 hw->mac.type != e1000_i211)
4427 ret = igb_add_2tuple_filter(dev, ntuple_filter);
4429 ret = igb_remove_2tuple_filter(dev, ntuple_filter);
4440 igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
4445 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4446 if (filter_info->ethertype_filters[i].ethertype == ethertype &&
4447 (filter_info->ethertype_mask & (1 << i)))
4454 igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
4455 uint16_t ethertype, uint32_t etqf)
4459 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4460 if (!(filter_info->ethertype_mask & (1 << i))) {
4461 filter_info->ethertype_mask |= 1 << i;
4462 filter_info->ethertype_filters[i].ethertype = ethertype;
4463 filter_info->ethertype_filters[i].etqf = etqf;
4471 igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
4474 if (idx >= E1000_MAX_ETQF_FILTERS)
4476 filter_info->ethertype_mask &= ~(1 << idx);
4477 filter_info->ethertype_filters[idx].ethertype = 0;
4478 filter_info->ethertype_filters[idx].etqf = 0;
4484 igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
4485 struct rte_eth_ethertype_filter *filter,
4488 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4489 struct e1000_filter_info *filter_info =
4490 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4494 if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
4495 filter->ether_type == RTE_ETHER_TYPE_IPV6) {
4496 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
4497 " ethertype filter.", filter->ether_type);
4501 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
4502 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
4505 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
4506 PMD_DRV_LOG(ERR, "drop option is unsupported.");
4510 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4511 if (ret >= 0 && add) {
4512 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
4513 filter->ether_type);
4516 if (ret < 0 && !add) {
4517 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4518 filter->ether_type);
4523 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
4524 etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
4525 etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
4526 ret = igb_ethertype_filter_insert(filter_info,
4527 filter->ether_type, etqf);
4529 PMD_DRV_LOG(ERR, "ethertype filters are full.");
4533 ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
4537 E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
4538 E1000_WRITE_FLUSH(hw);
4544 eth_igb_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
4545 const struct rte_flow_ops **ops)
4547 *ops = &igb_flow_ops;
4552 eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
4553 struct rte_ether_addr *mc_addr_set,
4554 uint32_t nb_mc_addr)
4556 struct e1000_hw *hw;
4558 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4559 e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
4564 igb_read_systime_cyclecounter(struct rte_eth_dev *dev)
4566 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4567 uint64_t systime_cycles;
4569 switch (hw->mac.type) {
4573 * Need to read System Time Residue Register to be able
4574 * to read the other two registers.
4576 E1000_READ_REG(hw, E1000_SYSTIMR);
4577 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
4578 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4579 systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4586 * Need to read System Time Residue Register to be able
4587 * to read the other two registers.
4589 E1000_READ_REG(hw, E1000_SYSTIMR);
4590 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4591 /* Only the 8 LSB are valid. */
4592 systime_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_SYSTIMH)
4596 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4597 systime_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4602 return systime_cycles;
4606 igb_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4608 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4609 uint64_t rx_tstamp_cycles;
4611 switch (hw->mac.type) {
4614 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4615 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4616 rx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4622 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4623 /* Only the 8 LSB are valid. */
4624 rx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_RXSTMPH)
4628 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4629 rx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4634 return rx_tstamp_cycles;
4638 igb_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4640 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4641 uint64_t tx_tstamp_cycles;
4643 switch (hw->mac.type) {
4646 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4647 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4648 tx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4654 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4655 /* Only the 8 LSB are valid. */
4656 tx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_TXSTMPH)
4660 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4661 tx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4666 return tx_tstamp_cycles;
4670 igb_start_timecounters(struct rte_eth_dev *dev)
4672 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4673 struct e1000_adapter *adapter = dev->data->dev_private;
4674 uint32_t incval = 1;
4676 uint64_t mask = E1000_CYCLECOUNTER_MASK;
4678 switch (hw->mac.type) {
4682 /* 32 LSB bits + 8 MSB bits = 40 bits */
4683 mask = (1ULL << 40) - 1;
4688 * Start incrementing the register
4689 * used to timestamp PTP packets.
4691 E1000_WRITE_REG(hw, E1000_TIMINCA, incval);
4694 incval = E1000_INCVALUE_82576;
4695 shift = IGB_82576_TSYNC_SHIFT;
4696 E1000_WRITE_REG(hw, E1000_TIMINCA,
4697 E1000_INCPERIOD_82576 | incval);
4704 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
4705 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4706 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4708 adapter->systime_tc.cc_mask = mask;
4709 adapter->systime_tc.cc_shift = shift;
4710 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
4712 adapter->rx_tstamp_tc.cc_mask = mask;
4713 adapter->rx_tstamp_tc.cc_shift = shift;
4714 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4716 adapter->tx_tstamp_tc.cc_mask = mask;
4717 adapter->tx_tstamp_tc.cc_shift = shift;
4718 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4722 igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
4724 struct e1000_adapter *adapter = dev->data->dev_private;
4726 adapter->systime_tc.nsec += delta;
4727 adapter->rx_tstamp_tc.nsec += delta;
4728 adapter->tx_tstamp_tc.nsec += delta;
4734 igb_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
4737 struct e1000_adapter *adapter = dev->data->dev_private;
4739 ns = rte_timespec_to_ns(ts);
4741 /* Set the timecounters to a new value. */
4742 adapter->systime_tc.nsec = ns;
4743 adapter->rx_tstamp_tc.nsec = ns;
4744 adapter->tx_tstamp_tc.nsec = ns;
4750 igb_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
4752 uint64_t ns, systime_cycles;
4753 struct e1000_adapter *adapter = dev->data->dev_private;
4755 systime_cycles = igb_read_systime_cyclecounter(dev);
4756 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
4757 *ts = rte_ns_to_timespec(ns);
4763 igb_timesync_enable(struct rte_eth_dev *dev)
4765 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4769 /* Stop the timesync system time. */
4770 E1000_WRITE_REG(hw, E1000_TIMINCA, 0x0);
4771 /* Reset the timesync system time value. */
4772 switch (hw->mac.type) {
4778 E1000_WRITE_REG(hw, E1000_SYSTIMR, 0x0);
4781 E1000_WRITE_REG(hw, E1000_SYSTIML, 0x0);
4782 E1000_WRITE_REG(hw, E1000_SYSTIMH, 0x0);
4785 /* Not supported. */
4789 /* Enable system time for it isn't on by default. */
4790 tsauxc = E1000_READ_REG(hw, E1000_TSAUXC);
4791 tsauxc &= ~E1000_TSAUXC_DISABLE_SYSTIME;
4792 E1000_WRITE_REG(hw, E1000_TSAUXC, tsauxc);
4794 igb_start_timecounters(dev);
4796 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
4797 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588),
4798 (RTE_ETHER_TYPE_1588 |
4799 E1000_ETQF_FILTER_ENABLE |
4802 /* Enable timestamping of received PTP packets. */
4803 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4804 tsync_ctl |= E1000_TSYNCRXCTL_ENABLED;
4805 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
4807 /* Enable Timestamping of transmitted PTP packets. */
4808 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4809 tsync_ctl |= E1000_TSYNCTXCTL_ENABLED;
4810 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
4816 igb_timesync_disable(struct rte_eth_dev *dev)
4818 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4821 /* Disable timestamping of transmitted PTP packets. */
4822 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4823 tsync_ctl &= ~E1000_TSYNCTXCTL_ENABLED;
4824 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
4826 /* Disable timestamping of received PTP packets. */
4827 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4828 tsync_ctl &= ~E1000_TSYNCRXCTL_ENABLED;
4829 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
4831 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
4832 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588), 0);
4834 /* Stop incrementing the System Time registers. */
4835 E1000_WRITE_REG(hw, E1000_TIMINCA, 0);
4841 igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
4842 struct timespec *timestamp,
4843 uint32_t flags __rte_unused)
4845 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4846 struct e1000_adapter *adapter = dev->data->dev_private;
4847 uint32_t tsync_rxctl;
4848 uint64_t rx_tstamp_cycles;
4851 tsync_rxctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4852 if ((tsync_rxctl & E1000_TSYNCRXCTL_VALID) == 0)
4855 rx_tstamp_cycles = igb_read_rx_tstamp_cyclecounter(dev);
4856 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
4857 *timestamp = rte_ns_to_timespec(ns);
4863 igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
4864 struct timespec *timestamp)
4866 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4867 struct e1000_adapter *adapter = dev->data->dev_private;
4868 uint32_t tsync_txctl;
4869 uint64_t tx_tstamp_cycles;
4872 tsync_txctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4873 if ((tsync_txctl & E1000_TSYNCTXCTL_VALID) == 0)
4876 tx_tstamp_cycles = igb_read_tx_tstamp_cyclecounter(dev);
4877 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
4878 *timestamp = rte_ns_to_timespec(ns);
4884 eth_igb_get_reg_length(struct rte_eth_dev *dev __rte_unused)
4888 const struct reg_info *reg_group;
4890 while ((reg_group = igb_regs[g_ind++]))
4891 count += igb_reg_group_count(reg_group);
4897 igbvf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
4901 const struct reg_info *reg_group;
4903 while ((reg_group = igbvf_regs[g_ind++]))
4904 count += igb_reg_group_count(reg_group);
4910 eth_igb_get_regs(struct rte_eth_dev *dev,
4911 struct rte_dev_reg_info *regs)
4913 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4914 uint32_t *data = regs->data;
4917 const struct reg_info *reg_group;
4920 regs->length = eth_igb_get_reg_length(dev);
4921 regs->width = sizeof(uint32_t);
4925 /* Support only full register dump */
4926 if ((regs->length == 0) ||
4927 (regs->length == (uint32_t)eth_igb_get_reg_length(dev))) {
4928 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
4930 while ((reg_group = igb_regs[g_ind++]))
4931 count += igb_read_regs_group(dev, &data[count],
4940 igbvf_get_regs(struct rte_eth_dev *dev,
4941 struct rte_dev_reg_info *regs)
4943 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4944 uint32_t *data = regs->data;
4947 const struct reg_info *reg_group;
4950 regs->length = igbvf_get_reg_length(dev);
4951 regs->width = sizeof(uint32_t);
4955 /* Support only full register dump */
4956 if ((regs->length == 0) ||
4957 (regs->length == (uint32_t)igbvf_get_reg_length(dev))) {
4958 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
4960 while ((reg_group = igbvf_regs[g_ind++]))
4961 count += igb_read_regs_group(dev, &data[count],
4970 eth_igb_get_eeprom_length(struct rte_eth_dev *dev)
4972 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4974 /* Return unit is byte count */
4975 return hw->nvm.word_size * 2;
4979 eth_igb_get_eeprom(struct rte_eth_dev *dev,
4980 struct rte_dev_eeprom_info *in_eeprom)
4982 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4983 struct e1000_nvm_info *nvm = &hw->nvm;
4984 uint16_t *data = in_eeprom->data;
4987 first = in_eeprom->offset >> 1;
4988 length = in_eeprom->length >> 1;
4989 if ((first >= hw->nvm.word_size) ||
4990 ((first + length) >= hw->nvm.word_size))
4993 in_eeprom->magic = hw->vendor_id |
4994 ((uint32_t)hw->device_id << 16);
4996 if ((nvm->ops.read) == NULL)
4999 return nvm->ops.read(hw, first, length, data);
5003 eth_igb_set_eeprom(struct rte_eth_dev *dev,
5004 struct rte_dev_eeprom_info *in_eeprom)
5006 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5007 struct e1000_nvm_info *nvm = &hw->nvm;
5008 uint16_t *data = in_eeprom->data;
5011 first = in_eeprom->offset >> 1;
5012 length = in_eeprom->length >> 1;
5013 if ((first >= hw->nvm.word_size) ||
5014 ((first + length) >= hw->nvm.word_size))
5017 in_eeprom->magic = (uint32_t)hw->vendor_id |
5018 ((uint32_t)hw->device_id << 16);
5020 if ((nvm->ops.write) == NULL)
5022 return nvm->ops.write(hw, first, length, data);
5026 eth_igb_get_module_info(struct rte_eth_dev *dev,
5027 struct rte_eth_dev_module_info *modinfo)
5029 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5031 uint32_t status = 0;
5032 uint16_t sff8472_rev, addr_mode;
5033 bool page_swap = false;
5035 if (hw->phy.media_type == e1000_media_type_copper ||
5036 hw->phy.media_type == e1000_media_type_unknown)
5039 /* Check whether we support SFF-8472 or not */
5040 status = e1000_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev);
5044 /* addressing mode is not supported */
5045 status = e1000_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode);
5049 /* addressing mode is not supported */
5050 if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) {
5052 "Address change required to access page 0xA2, "
5053 "but not supported. Please report the module "
5054 "type to the driver maintainers.\n");
5058 if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) {
5059 /* We have an SFP, but it does not support SFF-8472 */
5060 modinfo->type = RTE_ETH_MODULE_SFF_8079;
5061 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
5063 /* We have an SFP which supports a revision of SFF-8472 */
5064 modinfo->type = RTE_ETH_MODULE_SFF_8472;
5065 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
5072 eth_igb_get_module_eeprom(struct rte_eth_dev *dev,
5073 struct rte_dev_eeprom_info *info)
5075 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5077 uint32_t status = 0;
5078 uint16_t dataword[RTE_ETH_MODULE_SFF_8472_LEN / 2 + 1];
5079 u16 first_word, last_word;
5082 first_word = info->offset >> 1;
5083 last_word = (info->offset + info->length - 1) >> 1;
5085 /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
5086 for (i = 0; i < last_word - first_word + 1; i++) {
5087 status = e1000_read_phy_reg_i2c(hw, (first_word + i) * 2,
5090 /* Error occurred while reading module */
5094 dataword[i] = rte_be_to_cpu_16(dataword[i]);
5097 memcpy(info->data, (u8 *)dataword + (info->offset & 1), info->length);
5103 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
5105 struct e1000_hw *hw =
5106 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5107 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5108 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5109 uint32_t vec = E1000_MISC_VEC_ID;
5111 if (rte_intr_allow_others(intr_handle))
5112 vec = E1000_RX_VEC_START;
5114 uint32_t mask = 1 << (queue_id + vec);
5116 E1000_WRITE_REG(hw, E1000_EIMC, mask);
5117 E1000_WRITE_FLUSH(hw);
5123 eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
5125 struct e1000_hw *hw =
5126 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5127 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5128 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5129 uint32_t vec = E1000_MISC_VEC_ID;
5131 if (rte_intr_allow_others(intr_handle))
5132 vec = E1000_RX_VEC_START;
5134 uint32_t mask = 1 << (queue_id + vec);
5137 regval = E1000_READ_REG(hw, E1000_EIMS);
5138 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
5139 E1000_WRITE_FLUSH(hw);
5141 rte_intr_ack(intr_handle);
5147 eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
5148 uint8_t index, uint8_t offset)
5150 uint32_t val = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
5153 val &= ~((uint32_t)0xFF << offset);
5155 /* write vector and valid bit */
5156 val |= (msix_vector | E1000_IVAR_VALID) << offset;
5158 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, val);
5162 eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
5163 uint8_t queue, uint8_t msix_vector)
5167 if (hw->mac.type == e1000_82575) {
5169 tmp = E1000_EICR_RX_QUEUE0 << queue;
5170 else if (direction == 1)
5171 tmp = E1000_EICR_TX_QUEUE0 << queue;
5172 E1000_WRITE_REG(hw, E1000_MSIXBM(msix_vector), tmp);
5173 } else if (hw->mac.type == e1000_82576) {
5174 if ((direction == 0) || (direction == 1))
5175 eth_igb_write_ivar(hw, msix_vector, queue & 0x7,
5176 ((queue & 0x8) << 1) +
5178 } else if ((hw->mac.type == e1000_82580) ||
5179 (hw->mac.type == e1000_i350) ||
5180 (hw->mac.type == e1000_i354) ||
5181 (hw->mac.type == e1000_i210) ||
5182 (hw->mac.type == e1000_i211)) {
5183 if ((direction == 0) || (direction == 1))
5184 eth_igb_write_ivar(hw, msix_vector,
5186 ((queue & 0x1) << 4) +
5191 /* Sets up the hardware to generate MSI-X interrupts properly
5193 * board private structure
5196 eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
5198 int queue_id, nb_efd;
5199 uint32_t tmpval, regval, intr_mask;
5200 struct e1000_hw *hw =
5201 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5202 uint32_t vec = E1000_MISC_VEC_ID;
5203 uint32_t base = E1000_MISC_VEC_ID;
5204 uint32_t misc_shift = 0;
5205 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5206 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5208 /* won't configure msix register if no mapping is done
5209 * between intr vector and event fd
5211 if (!rte_intr_dp_is_en(intr_handle))
5214 if (rte_intr_allow_others(intr_handle)) {
5215 vec = base = E1000_RX_VEC_START;
5219 /* set interrupt vector for other causes */
5220 if (hw->mac.type == e1000_82575) {
5221 tmpval = E1000_READ_REG(hw, E1000_CTRL_EXT);
5222 /* enable MSI-X PBA support */
5223 tmpval |= E1000_CTRL_EXT_PBA_CLR;
5225 /* Auto-Mask interrupts upon ICR read */
5226 tmpval |= E1000_CTRL_EXT_EIAME;
5227 tmpval |= E1000_CTRL_EXT_IRCA;
5229 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmpval);
5231 /* enable msix_other interrupt */
5232 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), 0, E1000_EIMS_OTHER);
5233 regval = E1000_READ_REG(hw, E1000_EIAC);
5234 E1000_WRITE_REG(hw, E1000_EIAC, regval | E1000_EIMS_OTHER);
5235 regval = E1000_READ_REG(hw, E1000_EIAM);
5236 E1000_WRITE_REG(hw, E1000_EIMS, regval | E1000_EIMS_OTHER);
5237 } else if ((hw->mac.type == e1000_82576) ||
5238 (hw->mac.type == e1000_82580) ||
5239 (hw->mac.type == e1000_i350) ||
5240 (hw->mac.type == e1000_i354) ||
5241 (hw->mac.type == e1000_i210) ||
5242 (hw->mac.type == e1000_i211)) {
5243 /* turn on MSI-X capability first */
5244 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
5245 E1000_GPIE_PBA | E1000_GPIE_EIAME |
5247 nb_efd = rte_intr_nb_efd_get(intr_handle);
5251 intr_mask = RTE_LEN2MASK(nb_efd, uint32_t) << misc_shift;
5253 if (dev->data->dev_conf.intr_conf.lsc != 0)
5254 intr_mask |= (1 << IGB_MSIX_OTHER_INTR_VEC);
5256 regval = E1000_READ_REG(hw, E1000_EIAC);
5257 E1000_WRITE_REG(hw, E1000_EIAC, regval | intr_mask);
5259 /* enable msix_other interrupt */
5260 regval = E1000_READ_REG(hw, E1000_EIMS);
5261 E1000_WRITE_REG(hw, E1000_EIMS, regval | intr_mask);
5262 tmpval = (IGB_MSIX_OTHER_INTR_VEC | E1000_IVAR_VALID) << 8;
5263 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmpval);
5266 /* use EIAM to auto-mask when MSI-X interrupt
5267 * is asserted, this saves a register write for every interrupt
5269 nb_efd = rte_intr_nb_efd_get(intr_handle);
5273 intr_mask = RTE_LEN2MASK(nb_efd, uint32_t) << misc_shift;
5275 if (dev->data->dev_conf.intr_conf.lsc != 0)
5276 intr_mask |= (1 << IGB_MSIX_OTHER_INTR_VEC);
5278 regval = E1000_READ_REG(hw, E1000_EIAM);
5279 E1000_WRITE_REG(hw, E1000_EIAM, regval | intr_mask);
5281 for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
5282 eth_igb_assign_msix_vector(hw, 0, queue_id, vec);
5283 rte_intr_vec_list_index_set(intr_handle, queue_id, vec);
5284 if (vec < base + rte_intr_nb_efd_get(intr_handle) - 1)
5288 E1000_WRITE_FLUSH(hw);
5291 /* restore n-tuple filter */
5293 igb_ntuple_filter_restore(struct rte_eth_dev *dev)
5295 struct e1000_filter_info *filter_info =
5296 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5297 struct e1000_5tuple_filter *p_5tuple;
5298 struct e1000_2tuple_filter *p_2tuple;
5300 TAILQ_FOREACH(p_5tuple, &filter_info->fivetuple_list, entries) {
5301 igb_inject_5tuple_filter_82576(dev, p_5tuple);
5304 TAILQ_FOREACH(p_2tuple, &filter_info->twotuple_list, entries) {
5305 igb_inject_2uple_filter(dev, p_2tuple);
5309 /* restore SYN filter */
5311 igb_syn_filter_restore(struct rte_eth_dev *dev)
5313 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5314 struct e1000_filter_info *filter_info =
5315 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5318 synqf = filter_info->syn_info;
5320 if (synqf & E1000_SYN_FILTER_ENABLE) {
5321 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
5322 E1000_WRITE_FLUSH(hw);
5326 /* restore ethernet type filter */
5328 igb_ethertype_filter_restore(struct rte_eth_dev *dev)
5330 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5331 struct e1000_filter_info *filter_info =
5332 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5335 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
5336 if (filter_info->ethertype_mask & (1 << i)) {
5337 E1000_WRITE_REG(hw, E1000_ETQF(i),
5338 filter_info->ethertype_filters[i].etqf);
5339 E1000_WRITE_FLUSH(hw);
5344 /* restore flex byte filter */
5346 igb_flex_filter_restore(struct rte_eth_dev *dev)
5348 struct e1000_filter_info *filter_info =
5349 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5350 struct e1000_flex_filter *flex_filter;
5352 TAILQ_FOREACH(flex_filter, &filter_info->flex_list, entries) {
5353 igb_inject_flex_filter(dev, flex_filter);
5357 /* restore rss filter */
5359 igb_rss_filter_restore(struct rte_eth_dev *dev)
5361 struct e1000_filter_info *filter_info =
5362 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5364 if (filter_info->rss_info.conf.queue_num)
5365 igb_config_rss_filter(dev, &filter_info->rss_info, TRUE);
5368 /* restore all types filter */
5370 igb_filter_restore(struct rte_eth_dev *dev)
5372 igb_ntuple_filter_restore(dev);
5373 igb_ethertype_filter_restore(dev);
5374 igb_syn_filter_restore(dev);
5375 igb_flex_filter_restore(dev);
5376 igb_rss_filter_restore(dev);
5381 RTE_PMD_REGISTER_PCI(net_e1000_igb, rte_igb_pmd);
5382 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb, pci_id_igb_map);
5383 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb, "* igb_uio | uio_pci_generic | vfio-pci");
5384 RTE_PMD_REGISTER_PCI(net_e1000_igb_vf, rte_igbvf_pmd);
5385 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb_vf, pci_id_igbvf_map);
5386 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb_vf, "* igb_uio | vfio-pci");