1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
11 #include <rte_common.h>
12 #include <rte_interrupts.h>
13 #include <rte_byteorder.h>
15 #include <rte_debug.h>
17 #include <rte_bus_pci.h>
18 #include <rte_ether.h>
19 #include <rte_ethdev_driver.h>
20 #include <rte_ethdev_pci.h>
21 #include <rte_memory.h>
23 #include <rte_malloc.h>
26 #include "e1000_logs.h"
27 #include "base/e1000_api.h"
28 #include "e1000_ethdev.h"
32 * Default values for port configuration
34 #define IGB_DEFAULT_RX_FREE_THRESH 32
36 #define IGB_DEFAULT_RX_PTHRESH ((hw->mac.type == e1000_i354) ? 12 : 8)
37 #define IGB_DEFAULT_RX_HTHRESH 8
38 #define IGB_DEFAULT_RX_WTHRESH ((hw->mac.type == e1000_82576) ? 1 : 4)
40 #define IGB_DEFAULT_TX_PTHRESH ((hw->mac.type == e1000_i354) ? 20 : 8)
41 #define IGB_DEFAULT_TX_HTHRESH 1
42 #define IGB_DEFAULT_TX_WTHRESH ((hw->mac.type == e1000_82576) ? 1 : 16)
44 /* Bit shift and mask */
45 #define IGB_4_BIT_WIDTH (CHAR_BIT / 2)
46 #define IGB_4_BIT_MASK RTE_LEN2MASK(IGB_4_BIT_WIDTH, uint8_t)
47 #define IGB_8_BIT_WIDTH CHAR_BIT
48 #define IGB_8_BIT_MASK UINT8_MAX
50 /* Additional timesync values. */
51 #define E1000_CYCLECOUNTER_MASK 0xffffffffffffffffULL
52 #define E1000_ETQF_FILTER_1588 3
53 #define IGB_82576_TSYNC_SHIFT 16
54 #define E1000_INCPERIOD_82576 (1 << E1000_TIMINCA_16NS_SHIFT)
55 #define E1000_INCVALUE_82576 (16 << IGB_82576_TSYNC_SHIFT)
56 #define E1000_TSAUXC_DISABLE_SYSTIME 0x80000000
58 #define E1000_VTIVAR_MISC 0x01740
59 #define E1000_VTIVAR_MISC_MASK 0xFF
60 #define E1000_VTIVAR_VALID 0x80
61 #define E1000_VTIVAR_MISC_MAILBOX 0
62 #define E1000_VTIVAR_MISC_INTR_MASK 0x3
64 /* External VLAN Enable bit mask */
65 #define E1000_CTRL_EXT_EXT_VLAN (1 << 26)
67 /* External VLAN Ether Type bit mask and shift */
68 #define E1000_VET_VET_EXT 0xFFFF0000
69 #define E1000_VET_VET_EXT_SHIFT 16
71 /* MSI-X other interrupt vector */
72 #define IGB_MSIX_OTHER_INTR_VEC 0
74 static int eth_igb_configure(struct rte_eth_dev *dev);
75 static int eth_igb_start(struct rte_eth_dev *dev);
76 static void eth_igb_stop(struct rte_eth_dev *dev);
77 static int eth_igb_dev_set_link_up(struct rte_eth_dev *dev);
78 static int eth_igb_dev_set_link_down(struct rte_eth_dev *dev);
79 static void eth_igb_close(struct rte_eth_dev *dev);
80 static int eth_igb_reset(struct rte_eth_dev *dev);
81 static void eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
82 static void eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
83 static void eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
84 static void eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
85 static int eth_igb_link_update(struct rte_eth_dev *dev,
86 int wait_to_complete);
87 static int eth_igb_stats_get(struct rte_eth_dev *dev,
88 struct rte_eth_stats *rte_stats);
89 static int eth_igb_xstats_get(struct rte_eth_dev *dev,
90 struct rte_eth_xstat *xstats, unsigned n);
91 static int eth_igb_xstats_get_by_id(struct rte_eth_dev *dev,
93 uint64_t *values, unsigned int n);
94 static int eth_igb_xstats_get_names(struct rte_eth_dev *dev,
95 struct rte_eth_xstat_name *xstats_names,
97 static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
98 struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
100 static void eth_igb_stats_reset(struct rte_eth_dev *dev);
101 static void eth_igb_xstats_reset(struct rte_eth_dev *dev);
102 static int eth_igb_fw_version_get(struct rte_eth_dev *dev,
103 char *fw_version, size_t fw_size);
104 static void eth_igb_infos_get(struct rte_eth_dev *dev,
105 struct rte_eth_dev_info *dev_info);
106 static const uint32_t *eth_igb_supported_ptypes_get(struct rte_eth_dev *dev);
107 static void eth_igbvf_infos_get(struct rte_eth_dev *dev,
108 struct rte_eth_dev_info *dev_info);
109 static int eth_igb_flow_ctrl_get(struct rte_eth_dev *dev,
110 struct rte_eth_fc_conf *fc_conf);
111 static int eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
112 struct rte_eth_fc_conf *fc_conf);
113 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on);
114 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
115 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
116 static int eth_igb_interrupt_action(struct rte_eth_dev *dev,
117 struct rte_intr_handle *handle);
118 static void eth_igb_interrupt_handler(void *param);
119 static int igb_hardware_init(struct e1000_hw *hw);
120 static void igb_hw_control_acquire(struct e1000_hw *hw);
121 static void igb_hw_control_release(struct e1000_hw *hw);
122 static void igb_init_manageability(struct e1000_hw *hw);
123 static void igb_release_manageability(struct e1000_hw *hw);
125 static int eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
127 static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
128 uint16_t vlan_id, int on);
129 static int eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
130 enum rte_vlan_type vlan_type,
132 static int eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
134 static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
135 static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
136 static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
137 static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
138 static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
139 static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
141 static int eth_igb_led_on(struct rte_eth_dev *dev);
142 static int eth_igb_led_off(struct rte_eth_dev *dev);
144 static void igb_intr_disable(struct rte_eth_dev *dev);
145 static int igb_get_rx_buffer_size(struct e1000_hw *hw);
146 static int eth_igb_rar_set(struct rte_eth_dev *dev,
147 struct ether_addr *mac_addr,
148 uint32_t index, uint32_t pool);
149 static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
150 static int eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
151 struct ether_addr *addr);
153 static void igbvf_intr_disable(struct e1000_hw *hw);
154 static int igbvf_dev_configure(struct rte_eth_dev *dev);
155 static int igbvf_dev_start(struct rte_eth_dev *dev);
156 static void igbvf_dev_stop(struct rte_eth_dev *dev);
157 static void igbvf_dev_close(struct rte_eth_dev *dev);
158 static void igbvf_promiscuous_enable(struct rte_eth_dev *dev);
159 static void igbvf_promiscuous_disable(struct rte_eth_dev *dev);
160 static void igbvf_allmulticast_enable(struct rte_eth_dev *dev);
161 static void igbvf_allmulticast_disable(struct rte_eth_dev *dev);
162 static int eth_igbvf_link_update(struct e1000_hw *hw);
163 static int eth_igbvf_stats_get(struct rte_eth_dev *dev,
164 struct rte_eth_stats *rte_stats);
165 static int eth_igbvf_xstats_get(struct rte_eth_dev *dev,
166 struct rte_eth_xstat *xstats, unsigned n);
167 static int eth_igbvf_xstats_get_names(struct rte_eth_dev *dev,
168 struct rte_eth_xstat_name *xstats_names,
170 static void eth_igbvf_stats_reset(struct rte_eth_dev *dev);
171 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
172 uint16_t vlan_id, int on);
173 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
174 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
175 static int igbvf_default_mac_addr_set(struct rte_eth_dev *dev,
176 struct ether_addr *addr);
177 static int igbvf_get_reg_length(struct rte_eth_dev *dev);
178 static int igbvf_get_regs(struct rte_eth_dev *dev,
179 struct rte_dev_reg_info *regs);
181 static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
182 struct rte_eth_rss_reta_entry64 *reta_conf,
184 static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
185 struct rte_eth_rss_reta_entry64 *reta_conf,
188 static int eth_igb_syn_filter_get(struct rte_eth_dev *dev,
189 struct rte_eth_syn_filter *filter);
190 static int eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
191 enum rte_filter_op filter_op,
193 static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
194 struct rte_eth_ntuple_filter *ntuple_filter);
195 static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
196 struct rte_eth_ntuple_filter *ntuple_filter);
197 static int eth_igb_get_flex_filter(struct rte_eth_dev *dev,
198 struct rte_eth_flex_filter *filter);
199 static int eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
200 enum rte_filter_op filter_op,
202 static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
203 struct rte_eth_ntuple_filter *ntuple_filter);
204 static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
205 struct rte_eth_ntuple_filter *ntuple_filter);
206 static int igb_get_ntuple_filter(struct rte_eth_dev *dev,
207 struct rte_eth_ntuple_filter *filter);
208 static int igb_ntuple_filter_handle(struct rte_eth_dev *dev,
209 enum rte_filter_op filter_op,
211 static int igb_ethertype_filter_handle(struct rte_eth_dev *dev,
212 enum rte_filter_op filter_op,
214 static int igb_get_ethertype_filter(struct rte_eth_dev *dev,
215 struct rte_eth_ethertype_filter *filter);
216 static int eth_igb_filter_ctrl(struct rte_eth_dev *dev,
217 enum rte_filter_type filter_type,
218 enum rte_filter_op filter_op,
220 static int eth_igb_get_reg_length(struct rte_eth_dev *dev);
221 static int eth_igb_get_regs(struct rte_eth_dev *dev,
222 struct rte_dev_reg_info *regs);
223 static int eth_igb_get_eeprom_length(struct rte_eth_dev *dev);
224 static int eth_igb_get_eeprom(struct rte_eth_dev *dev,
225 struct rte_dev_eeprom_info *eeprom);
226 static int eth_igb_set_eeprom(struct rte_eth_dev *dev,
227 struct rte_dev_eeprom_info *eeprom);
228 static int eth_igb_get_module_info(struct rte_eth_dev *dev,
229 struct rte_eth_dev_module_info *modinfo);
230 static int eth_igb_get_module_eeprom(struct rte_eth_dev *dev,
231 struct rte_dev_eeprom_info *info);
232 static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
233 struct ether_addr *mc_addr_set,
234 uint32_t nb_mc_addr);
235 static int igb_timesync_enable(struct rte_eth_dev *dev);
236 static int igb_timesync_disable(struct rte_eth_dev *dev);
237 static int igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
238 struct timespec *timestamp,
240 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
241 struct timespec *timestamp);
242 static int igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
243 static int igb_timesync_read_time(struct rte_eth_dev *dev,
244 struct timespec *timestamp);
245 static int igb_timesync_write_time(struct rte_eth_dev *dev,
246 const struct timespec *timestamp);
247 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
249 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
251 static void eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
252 uint8_t queue, uint8_t msix_vector);
253 static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
254 uint8_t index, uint8_t offset);
255 static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
256 static void eth_igbvf_interrupt_handler(void *param);
257 static void igbvf_mbx_process(struct rte_eth_dev *dev);
258 static int igb_filter_restore(struct rte_eth_dev *dev);
261 * Define VF Stats MACRO for Non "cleared on read" register
263 #define UPDATE_VF_STAT(reg, last, cur) \
265 u32 latest = E1000_READ_REG(hw, reg); \
266 cur += (latest - last) & UINT_MAX; \
270 #define IGB_FC_PAUSE_TIME 0x0680
271 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
272 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
274 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
276 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
279 * The set of PCI devices this driver supports
281 static const struct rte_pci_id pci_id_igb_map[] = {
282 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576) },
283 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_FIBER) },
284 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES) },
285 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER) },
286 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER_ET2) },
287 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS) },
288 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS_SERDES) },
289 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES_QUAD) },
291 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_COPPER) },
292 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_FIBER_SERDES) },
293 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575GB_QUAD_COPPER) },
295 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER) },
296 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_FIBER) },
297 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SERDES) },
298 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SGMII) },
299 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER_DUAL) },
300 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_QUAD_FIBER) },
302 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_COPPER) },
303 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_FIBER) },
304 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SERDES) },
305 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SGMII) },
306 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_DA4) },
307 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER) },
308 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_OEM1) },
309 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_IT) },
310 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_FIBER) },
311 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES) },
312 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SGMII) },
313 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_FLASHLESS) },
314 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES_FLASHLESS) },
315 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I211_COPPER) },
316 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
317 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_SGMII) },
318 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
319 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SGMII) },
320 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SERDES) },
321 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_BACKPLANE) },
322 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SFP) },
323 { .vendor_id = 0, /* sentinel */ },
327 * The set of PCI devices this driver supports (for 82576&I350 VF)
329 static const struct rte_pci_id pci_id_igbvf_map[] = {
330 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF) },
331 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF_HV) },
332 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF) },
333 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF_HV) },
334 { .vendor_id = 0, /* sentinel */ },
337 static const struct rte_eth_desc_lim rx_desc_lim = {
338 .nb_max = E1000_MAX_RING_DESC,
339 .nb_min = E1000_MIN_RING_DESC,
340 .nb_align = IGB_RXD_ALIGN,
343 static const struct rte_eth_desc_lim tx_desc_lim = {
344 .nb_max = E1000_MAX_RING_DESC,
345 .nb_min = E1000_MIN_RING_DESC,
346 .nb_align = IGB_RXD_ALIGN,
347 .nb_seg_max = IGB_TX_MAX_SEG,
348 .nb_mtu_seg_max = IGB_TX_MAX_MTU_SEG,
351 static const struct eth_dev_ops eth_igb_ops = {
352 .dev_configure = eth_igb_configure,
353 .dev_start = eth_igb_start,
354 .dev_stop = eth_igb_stop,
355 .dev_set_link_up = eth_igb_dev_set_link_up,
356 .dev_set_link_down = eth_igb_dev_set_link_down,
357 .dev_close = eth_igb_close,
358 .dev_reset = eth_igb_reset,
359 .promiscuous_enable = eth_igb_promiscuous_enable,
360 .promiscuous_disable = eth_igb_promiscuous_disable,
361 .allmulticast_enable = eth_igb_allmulticast_enable,
362 .allmulticast_disable = eth_igb_allmulticast_disable,
363 .link_update = eth_igb_link_update,
364 .stats_get = eth_igb_stats_get,
365 .xstats_get = eth_igb_xstats_get,
366 .xstats_get_by_id = eth_igb_xstats_get_by_id,
367 .xstats_get_names_by_id = eth_igb_xstats_get_names_by_id,
368 .xstats_get_names = eth_igb_xstats_get_names,
369 .stats_reset = eth_igb_stats_reset,
370 .xstats_reset = eth_igb_xstats_reset,
371 .fw_version_get = eth_igb_fw_version_get,
372 .dev_infos_get = eth_igb_infos_get,
373 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
374 .mtu_set = eth_igb_mtu_set,
375 .vlan_filter_set = eth_igb_vlan_filter_set,
376 .vlan_tpid_set = eth_igb_vlan_tpid_set,
377 .vlan_offload_set = eth_igb_vlan_offload_set,
378 .rx_queue_setup = eth_igb_rx_queue_setup,
379 .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
380 .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
381 .rx_queue_release = eth_igb_rx_queue_release,
382 .rx_queue_count = eth_igb_rx_queue_count,
383 .rx_descriptor_done = eth_igb_rx_descriptor_done,
384 .rx_descriptor_status = eth_igb_rx_descriptor_status,
385 .tx_descriptor_status = eth_igb_tx_descriptor_status,
386 .tx_queue_setup = eth_igb_tx_queue_setup,
387 .tx_queue_release = eth_igb_tx_queue_release,
388 .tx_done_cleanup = eth_igb_tx_done_cleanup,
389 .dev_led_on = eth_igb_led_on,
390 .dev_led_off = eth_igb_led_off,
391 .flow_ctrl_get = eth_igb_flow_ctrl_get,
392 .flow_ctrl_set = eth_igb_flow_ctrl_set,
393 .mac_addr_add = eth_igb_rar_set,
394 .mac_addr_remove = eth_igb_rar_clear,
395 .mac_addr_set = eth_igb_default_mac_addr_set,
396 .reta_update = eth_igb_rss_reta_update,
397 .reta_query = eth_igb_rss_reta_query,
398 .rss_hash_update = eth_igb_rss_hash_update,
399 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
400 .filter_ctrl = eth_igb_filter_ctrl,
401 .set_mc_addr_list = eth_igb_set_mc_addr_list,
402 .rxq_info_get = igb_rxq_info_get,
403 .txq_info_get = igb_txq_info_get,
404 .timesync_enable = igb_timesync_enable,
405 .timesync_disable = igb_timesync_disable,
406 .timesync_read_rx_timestamp = igb_timesync_read_rx_timestamp,
407 .timesync_read_tx_timestamp = igb_timesync_read_tx_timestamp,
408 .get_reg = eth_igb_get_regs,
409 .get_eeprom_length = eth_igb_get_eeprom_length,
410 .get_eeprom = eth_igb_get_eeprom,
411 .set_eeprom = eth_igb_set_eeprom,
412 .get_module_info = eth_igb_get_module_info,
413 .get_module_eeprom = eth_igb_get_module_eeprom,
414 .timesync_adjust_time = igb_timesync_adjust_time,
415 .timesync_read_time = igb_timesync_read_time,
416 .timesync_write_time = igb_timesync_write_time,
420 * dev_ops for virtual function, bare necessities for basic vf
421 * operation have been implemented
423 static const struct eth_dev_ops igbvf_eth_dev_ops = {
424 .dev_configure = igbvf_dev_configure,
425 .dev_start = igbvf_dev_start,
426 .dev_stop = igbvf_dev_stop,
427 .dev_close = igbvf_dev_close,
428 .promiscuous_enable = igbvf_promiscuous_enable,
429 .promiscuous_disable = igbvf_promiscuous_disable,
430 .allmulticast_enable = igbvf_allmulticast_enable,
431 .allmulticast_disable = igbvf_allmulticast_disable,
432 .link_update = eth_igb_link_update,
433 .stats_get = eth_igbvf_stats_get,
434 .xstats_get = eth_igbvf_xstats_get,
435 .xstats_get_names = eth_igbvf_xstats_get_names,
436 .stats_reset = eth_igbvf_stats_reset,
437 .xstats_reset = eth_igbvf_stats_reset,
438 .vlan_filter_set = igbvf_vlan_filter_set,
439 .dev_infos_get = eth_igbvf_infos_get,
440 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
441 .rx_queue_setup = eth_igb_rx_queue_setup,
442 .rx_queue_release = eth_igb_rx_queue_release,
443 .rx_descriptor_done = eth_igb_rx_descriptor_done,
444 .rx_descriptor_status = eth_igb_rx_descriptor_status,
445 .tx_descriptor_status = eth_igb_tx_descriptor_status,
446 .tx_queue_setup = eth_igb_tx_queue_setup,
447 .tx_queue_release = eth_igb_tx_queue_release,
448 .set_mc_addr_list = eth_igb_set_mc_addr_list,
449 .rxq_info_get = igb_rxq_info_get,
450 .txq_info_get = igb_txq_info_get,
451 .mac_addr_set = igbvf_default_mac_addr_set,
452 .get_reg = igbvf_get_regs,
455 /* store statistics names and its offset in stats structure */
456 struct rte_igb_xstats_name_off {
457 char name[RTE_ETH_XSTATS_NAME_SIZE];
461 static const struct rte_igb_xstats_name_off rte_igb_stats_strings[] = {
462 {"rx_crc_errors", offsetof(struct e1000_hw_stats, crcerrs)},
463 {"rx_align_errors", offsetof(struct e1000_hw_stats, algnerrc)},
464 {"rx_symbol_errors", offsetof(struct e1000_hw_stats, symerrs)},
465 {"rx_missed_packets", offsetof(struct e1000_hw_stats, mpc)},
466 {"tx_single_collision_packets", offsetof(struct e1000_hw_stats, scc)},
467 {"tx_multiple_collision_packets", offsetof(struct e1000_hw_stats, mcc)},
468 {"tx_excessive_collision_packets", offsetof(struct e1000_hw_stats,
470 {"tx_late_collisions", offsetof(struct e1000_hw_stats, latecol)},
471 {"tx_total_collisions", offsetof(struct e1000_hw_stats, colc)},
472 {"tx_deferred_packets", offsetof(struct e1000_hw_stats, dc)},
473 {"tx_no_carrier_sense_packets", offsetof(struct e1000_hw_stats, tncrs)},
474 {"rx_carrier_ext_errors", offsetof(struct e1000_hw_stats, cexterr)},
475 {"rx_length_errors", offsetof(struct e1000_hw_stats, rlec)},
476 {"rx_xon_packets", offsetof(struct e1000_hw_stats, xonrxc)},
477 {"tx_xon_packets", offsetof(struct e1000_hw_stats, xontxc)},
478 {"rx_xoff_packets", offsetof(struct e1000_hw_stats, xoffrxc)},
479 {"tx_xoff_packets", offsetof(struct e1000_hw_stats, xofftxc)},
480 {"rx_flow_control_unsupported_packets", offsetof(struct e1000_hw_stats,
482 {"rx_size_64_packets", offsetof(struct e1000_hw_stats, prc64)},
483 {"rx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, prc127)},
484 {"rx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, prc255)},
485 {"rx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, prc511)},
486 {"rx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
488 {"rx_size_1024_to_max_packets", offsetof(struct e1000_hw_stats,
490 {"rx_broadcast_packets", offsetof(struct e1000_hw_stats, bprc)},
491 {"rx_multicast_packets", offsetof(struct e1000_hw_stats, mprc)},
492 {"rx_undersize_errors", offsetof(struct e1000_hw_stats, ruc)},
493 {"rx_fragment_errors", offsetof(struct e1000_hw_stats, rfc)},
494 {"rx_oversize_errors", offsetof(struct e1000_hw_stats, roc)},
495 {"rx_jabber_errors", offsetof(struct e1000_hw_stats, rjc)},
496 {"rx_management_packets", offsetof(struct e1000_hw_stats, mgprc)},
497 {"rx_management_dropped", offsetof(struct e1000_hw_stats, mgpdc)},
498 {"tx_management_packets", offsetof(struct e1000_hw_stats, mgptc)},
499 {"rx_total_packets", offsetof(struct e1000_hw_stats, tpr)},
500 {"tx_total_packets", offsetof(struct e1000_hw_stats, tpt)},
501 {"rx_total_bytes", offsetof(struct e1000_hw_stats, tor)},
502 {"tx_total_bytes", offsetof(struct e1000_hw_stats, tot)},
503 {"tx_size_64_packets", offsetof(struct e1000_hw_stats, ptc64)},
504 {"tx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, ptc127)},
505 {"tx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, ptc255)},
506 {"tx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, ptc511)},
507 {"tx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
509 {"tx_size_1023_to_max_packets", offsetof(struct e1000_hw_stats,
511 {"tx_multicast_packets", offsetof(struct e1000_hw_stats, mptc)},
512 {"tx_broadcast_packets", offsetof(struct e1000_hw_stats, bptc)},
513 {"tx_tso_packets", offsetof(struct e1000_hw_stats, tsctc)},
514 {"tx_tso_errors", offsetof(struct e1000_hw_stats, tsctfc)},
515 {"rx_sent_to_host_packets", offsetof(struct e1000_hw_stats, rpthc)},
516 {"tx_sent_by_host_packets", offsetof(struct e1000_hw_stats, hgptc)},
517 {"rx_code_violation_packets", offsetof(struct e1000_hw_stats, scvpc)},
519 {"interrupt_assert_count", offsetof(struct e1000_hw_stats, iac)},
522 #define IGB_NB_XSTATS (sizeof(rte_igb_stats_strings) / \
523 sizeof(rte_igb_stats_strings[0]))
525 static const struct rte_igb_xstats_name_off rte_igbvf_stats_strings[] = {
526 {"rx_multicast_packets", offsetof(struct e1000_vf_stats, mprc)},
527 {"rx_good_loopback_packets", offsetof(struct e1000_vf_stats, gprlbc)},
528 {"tx_good_loopback_packets", offsetof(struct e1000_vf_stats, gptlbc)},
529 {"rx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gorlbc)},
530 {"tx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gotlbc)},
533 #define IGBVF_NB_XSTATS (sizeof(rte_igbvf_stats_strings) / \
534 sizeof(rte_igbvf_stats_strings[0]))
538 igb_intr_enable(struct rte_eth_dev *dev)
540 struct e1000_interrupt *intr =
541 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
542 struct e1000_hw *hw =
543 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
544 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
545 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
547 if (rte_intr_allow_others(intr_handle) &&
548 dev->data->dev_conf.intr_conf.lsc != 0) {
549 E1000_WRITE_REG(hw, E1000_EIMS, 1 << IGB_MSIX_OTHER_INTR_VEC);
552 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
553 E1000_WRITE_FLUSH(hw);
557 igb_intr_disable(struct rte_eth_dev *dev)
559 struct e1000_hw *hw =
560 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
561 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
562 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
564 if (rte_intr_allow_others(intr_handle) &&
565 dev->data->dev_conf.intr_conf.lsc != 0) {
566 E1000_WRITE_REG(hw, E1000_EIMC, 1 << IGB_MSIX_OTHER_INTR_VEC);
569 E1000_WRITE_REG(hw, E1000_IMC, ~0);
570 E1000_WRITE_FLUSH(hw);
574 igbvf_intr_enable(struct rte_eth_dev *dev)
576 struct e1000_hw *hw =
577 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
579 /* only for mailbox */
580 E1000_WRITE_REG(hw, E1000_EIAM, 1 << E1000_VTIVAR_MISC_MAILBOX);
581 E1000_WRITE_REG(hw, E1000_EIAC, 1 << E1000_VTIVAR_MISC_MAILBOX);
582 E1000_WRITE_REG(hw, E1000_EIMS, 1 << E1000_VTIVAR_MISC_MAILBOX);
583 E1000_WRITE_FLUSH(hw);
586 /* only for mailbox now. If RX/TX needed, should extend this function. */
588 igbvf_set_ivar_map(struct e1000_hw *hw, uint8_t msix_vector)
593 tmp |= (msix_vector & E1000_VTIVAR_MISC_INTR_MASK);
594 tmp |= E1000_VTIVAR_VALID;
595 E1000_WRITE_REG(hw, E1000_VTIVAR_MISC, tmp);
599 eth_igbvf_configure_msix_intr(struct rte_eth_dev *dev)
601 struct e1000_hw *hw =
602 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
604 /* Configure VF other cause ivar */
605 igbvf_set_ivar_map(hw, E1000_VTIVAR_MISC_MAILBOX);
608 static inline int32_t
609 igb_pf_reset_hw(struct e1000_hw *hw)
614 status = e1000_reset_hw(hw);
616 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
617 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
618 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
619 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
620 E1000_WRITE_FLUSH(hw);
626 igb_identify_hardware(struct rte_eth_dev *dev, struct rte_pci_device *pci_dev)
628 struct e1000_hw *hw =
629 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
632 hw->vendor_id = pci_dev->id.vendor_id;
633 hw->device_id = pci_dev->id.device_id;
634 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
635 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
637 e1000_set_mac_type(hw);
639 /* need to check if it is a vf device below */
643 igb_reset_swfw_lock(struct e1000_hw *hw)
648 * Do mac ops initialization manually here, since we will need
649 * some function pointers set by this call.
651 ret_val = e1000_init_mac_params(hw);
656 * SMBI lock should not fail in this early stage. If this is the case,
657 * it is due to an improper exit of the application.
658 * So force the release of the faulty lock.
660 if (e1000_get_hw_semaphore_generic(hw) < 0) {
661 PMD_DRV_LOG(DEBUG, "SMBI lock released");
663 e1000_put_hw_semaphore_generic(hw);
665 if (hw->mac.ops.acquire_swfw_sync != NULL) {
669 * Phy lock should not fail in this early stage. If this is the case,
670 * it is due to an improper exit of the application.
671 * So force the release of the faulty lock.
673 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
674 if (hw->bus.func > E1000_FUNC_1)
676 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
677 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
680 hw->mac.ops.release_swfw_sync(hw, mask);
683 * This one is more tricky since it is common to all ports; but
684 * swfw_sync retries last long enough (1s) to be almost sure that if
685 * lock can not be taken it is due to an improper lock of the
688 mask = E1000_SWFW_EEP_SM;
689 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
690 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
692 hw->mac.ops.release_swfw_sync(hw, mask);
695 return E1000_SUCCESS;
698 /* Remove all ntuple filters of the device */
699 static int igb_ntuple_filter_uninit(struct rte_eth_dev *eth_dev)
701 struct e1000_filter_info *filter_info =
702 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
703 struct e1000_5tuple_filter *p_5tuple;
704 struct e1000_2tuple_filter *p_2tuple;
706 while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list))) {
707 TAILQ_REMOVE(&filter_info->fivetuple_list,
711 filter_info->fivetuple_mask = 0;
712 while ((p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list))) {
713 TAILQ_REMOVE(&filter_info->twotuple_list,
717 filter_info->twotuple_mask = 0;
722 /* Remove all flex filters of the device */
723 static int igb_flex_filter_uninit(struct rte_eth_dev *eth_dev)
725 struct e1000_filter_info *filter_info =
726 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
727 struct e1000_flex_filter *p_flex;
729 while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
730 TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
733 filter_info->flex_mask = 0;
739 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
742 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
743 struct e1000_hw *hw =
744 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
745 struct e1000_vfta * shadow_vfta =
746 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
747 struct e1000_filter_info *filter_info =
748 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
749 struct e1000_adapter *adapter =
750 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
754 eth_dev->dev_ops = ð_igb_ops;
755 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
756 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
757 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
759 /* for secondary processes, we don't initialise any further as primary
760 * has already done this work. Only check we don't need a different
762 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
763 if (eth_dev->data->scattered_rx)
764 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
768 rte_eth_copy_pci_info(eth_dev, pci_dev);
770 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
772 igb_identify_hardware(eth_dev, pci_dev);
773 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
778 e1000_get_bus_info(hw);
780 /* Reset any pending lock */
781 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
786 /* Finish initialization */
787 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
793 hw->phy.autoneg_wait_to_complete = 0;
794 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
797 if (hw->phy.media_type == e1000_media_type_copper) {
798 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
799 hw->phy.disable_polarity_correction = 0;
800 hw->phy.ms_type = e1000_ms_hw_default;
804 * Start from a known state, this is important in reading the nvm
809 /* Make sure we have a good EEPROM before we read from it */
810 if (e1000_validate_nvm_checksum(hw) < 0) {
812 * Some PCI-E parts fail the first check due to
813 * the link being in sleep state, call it again,
814 * if it fails a second time its a real issue.
816 if (e1000_validate_nvm_checksum(hw) < 0) {
817 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
823 /* Read the permanent MAC address out of the EEPROM */
824 if (e1000_read_mac_addr(hw) != 0) {
825 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
830 /* Allocate memory for storing MAC addresses */
831 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
832 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
833 if (eth_dev->data->mac_addrs == NULL) {
834 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
835 "store MAC addresses",
836 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
841 /* Copy the permanent MAC address */
842 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
844 /* initialize the vfta */
845 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
847 /* Now initialize the hardware */
848 if (igb_hardware_init(hw) != 0) {
849 PMD_INIT_LOG(ERR, "Hardware initialization failed");
850 rte_free(eth_dev->data->mac_addrs);
851 eth_dev->data->mac_addrs = NULL;
855 hw->mac.get_link_status = 1;
856 adapter->stopped = 0;
858 /* Indicate SOL/IDER usage */
859 if (e1000_check_reset_block(hw) < 0) {
860 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
864 /* initialize PF if max_vfs not zero */
865 igb_pf_host_init(eth_dev);
867 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
868 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
869 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
870 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
871 E1000_WRITE_FLUSH(hw);
873 PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
874 eth_dev->data->port_id, pci_dev->id.vendor_id,
875 pci_dev->id.device_id);
877 rte_intr_callback_register(&pci_dev->intr_handle,
878 eth_igb_interrupt_handler,
881 /* enable uio/vfio intr/eventfd mapping */
882 rte_intr_enable(&pci_dev->intr_handle);
884 /* enable support intr */
885 igb_intr_enable(eth_dev);
887 /* initialize filter info */
888 memset(filter_info, 0,
889 sizeof(struct e1000_filter_info));
891 TAILQ_INIT(&filter_info->flex_list);
892 TAILQ_INIT(&filter_info->twotuple_list);
893 TAILQ_INIT(&filter_info->fivetuple_list);
895 TAILQ_INIT(&igb_filter_ntuple_list);
896 TAILQ_INIT(&igb_filter_ethertype_list);
897 TAILQ_INIT(&igb_filter_syn_list);
898 TAILQ_INIT(&igb_filter_flex_list);
899 TAILQ_INIT(&igb_filter_rss_list);
900 TAILQ_INIT(&igb_flow_list);
905 igb_hw_control_release(hw);
911 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
913 struct rte_pci_device *pci_dev;
914 struct rte_intr_handle *intr_handle;
916 struct e1000_adapter *adapter =
917 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
918 struct e1000_filter_info *filter_info =
919 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
921 PMD_INIT_FUNC_TRACE();
923 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
926 hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
927 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
928 intr_handle = &pci_dev->intr_handle;
930 if (adapter->stopped == 0)
931 eth_igb_close(eth_dev);
933 eth_dev->dev_ops = NULL;
934 eth_dev->rx_pkt_burst = NULL;
935 eth_dev->tx_pkt_burst = NULL;
937 /* Reset any pending lock */
938 igb_reset_swfw_lock(hw);
940 /* uninitialize PF if max_vfs not zero */
941 igb_pf_host_uninit(eth_dev);
943 /* disable uio intr before callback unregister */
944 rte_intr_disable(intr_handle);
945 rte_intr_callback_unregister(intr_handle,
946 eth_igb_interrupt_handler, eth_dev);
948 /* clear the SYN filter info */
949 filter_info->syn_info = 0;
951 /* clear the ethertype filters info */
952 filter_info->ethertype_mask = 0;
953 memset(filter_info->ethertype_filters, 0,
954 E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
956 /* clear the rss filter info */
957 memset(&filter_info->rss_info, 0,
958 sizeof(struct igb_rte_flow_rss_conf));
960 /* remove all ntuple filters of the device */
961 igb_ntuple_filter_uninit(eth_dev);
963 /* remove all flex filters of the device */
964 igb_flex_filter_uninit(eth_dev);
966 /* clear all the filters list */
967 igb_filterlist_flush(eth_dev);
973 * Virtual Function device init
976 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
978 struct rte_pci_device *pci_dev;
979 struct rte_intr_handle *intr_handle;
980 struct e1000_adapter *adapter =
981 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
982 struct e1000_hw *hw =
983 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
985 struct ether_addr *perm_addr = (struct ether_addr *)hw->mac.perm_addr;
987 PMD_INIT_FUNC_TRACE();
989 eth_dev->dev_ops = &igbvf_eth_dev_ops;
990 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
991 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
992 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
994 /* for secondary processes, we don't initialise any further as primary
995 * has already done this work. Only check we don't need a different
997 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
998 if (eth_dev->data->scattered_rx)
999 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
1003 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1004 rte_eth_copy_pci_info(eth_dev, pci_dev);
1006 hw->device_id = pci_dev->id.device_id;
1007 hw->vendor_id = pci_dev->id.vendor_id;
1008 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1009 adapter->stopped = 0;
1011 /* Initialize the shared code (base driver) */
1012 diag = e1000_setup_init_funcs(hw, TRUE);
1014 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
1019 /* init_mailbox_params */
1020 hw->mbx.ops.init_params(hw);
1022 /* Disable the interrupts for VF */
1023 igbvf_intr_disable(hw);
1025 diag = hw->mac.ops.reset_hw(hw);
1027 /* Allocate memory for storing MAC addresses */
1028 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
1029 hw->mac.rar_entry_count, 0);
1030 if (eth_dev->data->mac_addrs == NULL) {
1032 "Failed to allocate %d bytes needed to store MAC "
1034 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
1038 /* Generate a random MAC address, if none was assigned by PF. */
1039 if (is_zero_ether_addr(perm_addr)) {
1040 eth_random_addr(perm_addr->addr_bytes);
1041 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1042 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1043 "%02x:%02x:%02x:%02x:%02x:%02x",
1044 perm_addr->addr_bytes[0],
1045 perm_addr->addr_bytes[1],
1046 perm_addr->addr_bytes[2],
1047 perm_addr->addr_bytes[3],
1048 perm_addr->addr_bytes[4],
1049 perm_addr->addr_bytes[5]);
1052 diag = e1000_rar_set(hw, perm_addr->addr_bytes, 0);
1054 rte_free(eth_dev->data->mac_addrs);
1055 eth_dev->data->mac_addrs = NULL;
1058 /* Copy the permanent MAC address */
1059 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
1060 ð_dev->data->mac_addrs[0]);
1062 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
1064 eth_dev->data->port_id, pci_dev->id.vendor_id,
1065 pci_dev->id.device_id, "igb_mac_82576_vf");
1067 intr_handle = &pci_dev->intr_handle;
1068 rte_intr_callback_register(intr_handle,
1069 eth_igbvf_interrupt_handler, eth_dev);
1075 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
1077 struct e1000_adapter *adapter =
1078 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
1079 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1081 PMD_INIT_FUNC_TRACE();
1083 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1086 if (adapter->stopped == 0)
1087 igbvf_dev_close(eth_dev);
1089 eth_dev->dev_ops = NULL;
1090 eth_dev->rx_pkt_burst = NULL;
1091 eth_dev->tx_pkt_burst = NULL;
1093 /* disable uio intr before callback unregister */
1094 rte_intr_disable(&pci_dev->intr_handle);
1095 rte_intr_callback_unregister(&pci_dev->intr_handle,
1096 eth_igbvf_interrupt_handler,
1102 static int eth_igb_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1103 struct rte_pci_device *pci_dev)
1105 return rte_eth_dev_pci_generic_probe(pci_dev,
1106 sizeof(struct e1000_adapter), eth_igb_dev_init);
1109 static int eth_igb_pci_remove(struct rte_pci_device *pci_dev)
1111 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igb_dev_uninit);
1114 static struct rte_pci_driver rte_igb_pmd = {
1115 .id_table = pci_id_igb_map,
1116 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
1117 RTE_PCI_DRV_IOVA_AS_VA,
1118 .probe = eth_igb_pci_probe,
1119 .remove = eth_igb_pci_remove,
1123 static int eth_igbvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1124 struct rte_pci_device *pci_dev)
1126 return rte_eth_dev_pci_generic_probe(pci_dev,
1127 sizeof(struct e1000_adapter), eth_igbvf_dev_init);
1130 static int eth_igbvf_pci_remove(struct rte_pci_device *pci_dev)
1132 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igbvf_dev_uninit);
1136 * virtual function driver struct
1138 static struct rte_pci_driver rte_igbvf_pmd = {
1139 .id_table = pci_id_igbvf_map,
1140 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_IOVA_AS_VA,
1141 .probe = eth_igbvf_pci_probe,
1142 .remove = eth_igbvf_pci_remove,
1146 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1148 struct e1000_hw *hw =
1149 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1150 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
1151 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
1152 rctl |= E1000_RCTL_VFE;
1153 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1157 igb_check_mq_mode(struct rte_eth_dev *dev)
1159 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1160 enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
1161 uint16_t nb_rx_q = dev->data->nb_rx_queues;
1162 uint16_t nb_tx_q = dev->data->nb_tx_queues;
1164 if ((rx_mq_mode & ETH_MQ_RX_DCB_FLAG) ||
1165 tx_mq_mode == ETH_MQ_TX_DCB ||
1166 tx_mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1167 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
1170 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
1171 /* Check multi-queue mode.
1172 * To no break software we accept ETH_MQ_RX_NONE as this might
1173 * be used to turn off VLAN filter.
1176 if (rx_mq_mode == ETH_MQ_RX_NONE ||
1177 rx_mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1178 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
1179 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
1181 /* Only support one queue on VFs.
1182 * RSS together with SRIOV is not supported.
1184 PMD_INIT_LOG(ERR, "SRIOV is active,"
1185 " wrong mq_mode rx %d.",
1189 /* TX mode is not used here, so mode might be ignored.*/
1190 if (tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1191 /* SRIOV only works in VMDq enable mode */
1192 PMD_INIT_LOG(WARNING, "SRIOV is active,"
1193 " TX mode %d is not supported. "
1194 " Driver will behave as %d mode.",
1195 tx_mq_mode, ETH_MQ_TX_VMDQ_ONLY);
1198 /* check valid queue number */
1199 if ((nb_rx_q > 1) || (nb_tx_q > 1)) {
1200 PMD_INIT_LOG(ERR, "SRIOV is active,"
1201 " only support one queue on VFs.");
1205 /* To no break software that set invalid mode, only display
1206 * warning if invalid mode is used.
1208 if (rx_mq_mode != ETH_MQ_RX_NONE &&
1209 rx_mq_mode != ETH_MQ_RX_VMDQ_ONLY &&
1210 rx_mq_mode != ETH_MQ_RX_RSS) {
1211 /* RSS together with VMDq not supported*/
1212 PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
1217 if (tx_mq_mode != ETH_MQ_TX_NONE &&
1218 tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1219 PMD_INIT_LOG(WARNING, "TX mode %d is not supported."
1220 " Due to txmode is meaningless in this"
1221 " driver, just ignore.",
1229 eth_igb_configure(struct rte_eth_dev *dev)
1231 struct e1000_interrupt *intr =
1232 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1235 PMD_INIT_FUNC_TRACE();
1237 /* multipe queue mode checking */
1238 ret = igb_check_mq_mode(dev);
1240 PMD_DRV_LOG(ERR, "igb_check_mq_mode fails with %d.",
1245 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1246 PMD_INIT_FUNC_TRACE();
1252 eth_igb_rxtx_control(struct rte_eth_dev *dev,
1255 struct e1000_hw *hw =
1256 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1257 uint32_t tctl, rctl;
1259 tctl = E1000_READ_REG(hw, E1000_TCTL);
1260 rctl = E1000_READ_REG(hw, E1000_RCTL);
1264 tctl |= E1000_TCTL_EN;
1265 rctl |= E1000_RCTL_EN;
1268 tctl &= ~E1000_TCTL_EN;
1269 rctl &= ~E1000_RCTL_EN;
1271 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1272 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1273 E1000_WRITE_FLUSH(hw);
1277 eth_igb_start(struct rte_eth_dev *dev)
1279 struct e1000_hw *hw =
1280 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1281 struct e1000_adapter *adapter =
1282 E1000_DEV_PRIVATE(dev->data->dev_private);
1283 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1284 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1286 uint32_t intr_vector = 0;
1292 PMD_INIT_FUNC_TRACE();
1294 /* disable uio/vfio intr/eventfd mapping */
1295 rte_intr_disable(intr_handle);
1297 /* Power up the phy. Needed to make the link go Up */
1298 eth_igb_dev_set_link_up(dev);
1301 * Packet Buffer Allocation (PBA)
1302 * Writing PBA sets the receive portion of the buffer
1303 * the remainder is used for the transmit buffer.
1305 if (hw->mac.type == e1000_82575) {
1308 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
1309 E1000_WRITE_REG(hw, E1000_PBA, pba);
1312 /* Put the address into the Receive Address Array */
1313 e1000_rar_set(hw, hw->mac.addr, 0);
1315 /* Initialize the hardware */
1316 if (igb_hardware_init(hw)) {
1317 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
1320 adapter->stopped = 0;
1322 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1324 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1325 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1326 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
1327 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1328 E1000_WRITE_FLUSH(hw);
1330 /* configure PF module if SRIOV enabled */
1331 igb_pf_host_configure(dev);
1333 /* check and configure queue intr-vector mapping */
1334 if ((rte_intr_cap_multiple(intr_handle) ||
1335 !RTE_ETH_DEV_SRIOV(dev).active) &&
1336 dev->data->dev_conf.intr_conf.rxq != 0) {
1337 intr_vector = dev->data->nb_rx_queues;
1338 if (rte_intr_efd_enable(intr_handle, intr_vector))
1342 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1343 intr_handle->intr_vec =
1344 rte_zmalloc("intr_vec",
1345 dev->data->nb_rx_queues * sizeof(int), 0);
1346 if (intr_handle->intr_vec == NULL) {
1347 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1348 " intr_vec", dev->data->nb_rx_queues);
1353 /* confiugre msix for rx interrupt */
1354 eth_igb_configure_msix_intr(dev);
1356 /* Configure for OS presence */
1357 igb_init_manageability(hw);
1359 eth_igb_tx_init(dev);
1361 /* This can fail when allocating mbufs for descriptor rings */
1362 ret = eth_igb_rx_init(dev);
1364 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1365 igb_dev_clear_queues(dev);
1369 e1000_clear_hw_cntrs_base_generic(hw);
1372 * VLAN Offload Settings
1374 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
1375 ETH_VLAN_EXTEND_MASK;
1376 ret = eth_igb_vlan_offload_set(dev, mask);
1378 PMD_INIT_LOG(ERR, "Unable to set vlan offload");
1379 igb_dev_clear_queues(dev);
1383 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1384 /* Enable VLAN filter since VMDq always use VLAN filter */
1385 igb_vmdq_vlan_hw_filter_enable(dev);
1388 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
1389 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
1390 (hw->mac.type == e1000_i211)) {
1391 /* Configure EITR with the maximum possible value (0xFFFF) */
1392 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
1395 /* Setup link speed and duplex */
1396 speeds = &dev->data->dev_conf.link_speeds;
1397 if (*speeds == ETH_LINK_SPEED_AUTONEG) {
1398 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
1399 hw->mac.autoneg = 1;
1402 autoneg = (*speeds & ETH_LINK_SPEED_FIXED) == 0;
1405 hw->phy.autoneg_advertised = 0;
1407 if (*speeds & ~(ETH_LINK_SPEED_10M_HD | ETH_LINK_SPEED_10M |
1408 ETH_LINK_SPEED_100M_HD | ETH_LINK_SPEED_100M |
1409 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_FIXED)) {
1411 goto error_invalid_config;
1413 if (*speeds & ETH_LINK_SPEED_10M_HD) {
1414 hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
1417 if (*speeds & ETH_LINK_SPEED_10M) {
1418 hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
1421 if (*speeds & ETH_LINK_SPEED_100M_HD) {
1422 hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
1425 if (*speeds & ETH_LINK_SPEED_100M) {
1426 hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
1429 if (*speeds & ETH_LINK_SPEED_1G) {
1430 hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
1433 if (num_speeds == 0 || (!autoneg && (num_speeds > 1)))
1434 goto error_invalid_config;
1436 /* Set/reset the mac.autoneg based on the link speed,
1440 hw->mac.autoneg = 0;
1441 hw->mac.forced_speed_duplex =
1442 hw->phy.autoneg_advertised;
1444 hw->mac.autoneg = 1;
1448 e1000_setup_link(hw);
1450 if (rte_intr_allow_others(intr_handle)) {
1451 /* check if lsc interrupt is enabled */
1452 if (dev->data->dev_conf.intr_conf.lsc != 0)
1453 eth_igb_lsc_interrupt_setup(dev, TRUE);
1455 eth_igb_lsc_interrupt_setup(dev, FALSE);
1457 rte_intr_callback_unregister(intr_handle,
1458 eth_igb_interrupt_handler,
1460 if (dev->data->dev_conf.intr_conf.lsc != 0)
1461 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1462 " no intr multiplex");
1465 /* check if rxq interrupt is enabled */
1466 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1467 rte_intr_dp_is_en(intr_handle))
1468 eth_igb_rxq_interrupt_setup(dev);
1470 /* enable uio/vfio intr/eventfd mapping */
1471 rte_intr_enable(intr_handle);
1473 /* resume enabled intr since hw reset */
1474 igb_intr_enable(dev);
1476 /* restore all types filter */
1477 igb_filter_restore(dev);
1479 eth_igb_rxtx_control(dev, true);
1480 eth_igb_link_update(dev, 0);
1482 PMD_INIT_LOG(DEBUG, "<<");
1486 error_invalid_config:
1487 PMD_INIT_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
1488 dev->data->dev_conf.link_speeds, dev->data->port_id);
1489 igb_dev_clear_queues(dev);
1493 /*********************************************************************
1495 * This routine disables all traffic on the adapter by issuing a
1496 * global reset on the MAC.
1498 **********************************************************************/
1500 eth_igb_stop(struct rte_eth_dev *dev)
1502 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1503 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1504 struct rte_eth_link link;
1505 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1507 eth_igb_rxtx_control(dev, false);
1509 igb_intr_disable(dev);
1511 /* disable intr eventfd mapping */
1512 rte_intr_disable(intr_handle);
1514 igb_pf_reset_hw(hw);
1515 E1000_WRITE_REG(hw, E1000_WUC, 0);
1517 /* Set bit for Go Link disconnect */
1518 if (hw->mac.type >= e1000_82580) {
1521 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1522 phpm_reg |= E1000_82580_PM_GO_LINKD;
1523 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1526 /* Power down the phy. Needed to make the link go Down */
1527 eth_igb_dev_set_link_down(dev);
1529 igb_dev_clear_queues(dev);
1531 /* clear the recorded link status */
1532 memset(&link, 0, sizeof(link));
1533 rte_eth_linkstatus_set(dev, &link);
1535 if (!rte_intr_allow_others(intr_handle))
1536 /* resume to the default handler */
1537 rte_intr_callback_register(intr_handle,
1538 eth_igb_interrupt_handler,
1541 /* Clean datapath event and queue/vec mapping */
1542 rte_intr_efd_disable(intr_handle);
1543 if (intr_handle->intr_vec != NULL) {
1544 rte_free(intr_handle->intr_vec);
1545 intr_handle->intr_vec = NULL;
1550 eth_igb_dev_set_link_up(struct rte_eth_dev *dev)
1552 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1554 if (hw->phy.media_type == e1000_media_type_copper)
1555 e1000_power_up_phy(hw);
1557 e1000_power_up_fiber_serdes_link(hw);
1563 eth_igb_dev_set_link_down(struct rte_eth_dev *dev)
1565 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1567 if (hw->phy.media_type == e1000_media_type_copper)
1568 e1000_power_down_phy(hw);
1570 e1000_shutdown_fiber_serdes_link(hw);
1576 eth_igb_close(struct rte_eth_dev *dev)
1578 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1579 struct e1000_adapter *adapter =
1580 E1000_DEV_PRIVATE(dev->data->dev_private);
1581 struct rte_eth_link link;
1582 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1583 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1586 adapter->stopped = 1;
1588 e1000_phy_hw_reset(hw);
1589 igb_release_manageability(hw);
1590 igb_hw_control_release(hw);
1592 /* Clear bit for Go Link disconnect */
1593 if (hw->mac.type >= e1000_82580) {
1596 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1597 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1598 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1601 igb_dev_free_queues(dev);
1603 if (intr_handle->intr_vec) {
1604 rte_free(intr_handle->intr_vec);
1605 intr_handle->intr_vec = NULL;
1608 memset(&link, 0, sizeof(link));
1609 rte_eth_linkstatus_set(dev, &link);
1616 eth_igb_reset(struct rte_eth_dev *dev)
1620 /* When a DPDK PMD PF begin to reset PF port, it should notify all
1621 * its VF to make them align with it. The detailed notification
1622 * mechanism is PMD specific and is currently not implemented.
1623 * To avoid unexpected behavior in VF, currently reset of PF with
1624 * SR-IOV activation is not supported. It might be supported later.
1626 if (dev->data->sriov.active)
1629 ret = eth_igb_dev_uninit(dev);
1633 ret = eth_igb_dev_init(dev);
1640 igb_get_rx_buffer_size(struct e1000_hw *hw)
1642 uint32_t rx_buf_size;
1643 if (hw->mac.type == e1000_82576) {
1644 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1645 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1646 /* PBS needs to be translated according to a lookup table */
1647 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1648 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1649 rx_buf_size = (rx_buf_size << 10);
1650 } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1651 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1653 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1659 /*********************************************************************
1661 * Initialize the hardware
1663 **********************************************************************/
1665 igb_hardware_init(struct e1000_hw *hw)
1667 uint32_t rx_buf_size;
1670 /* Let the firmware know the OS is in control */
1671 igb_hw_control_acquire(hw);
1674 * These parameters control the automatic generation (Tx) and
1675 * response (Rx) to Ethernet PAUSE frames.
1676 * - High water mark should allow for at least two standard size (1518)
1677 * frames to be received after sending an XOFF.
1678 * - Low water mark works best when it is very near the high water mark.
1679 * This allows the receiver to restart by sending XON when it has
1680 * drained a bit. Here we use an arbitrary value of 1500 which will
1681 * restart after one full frame is pulled from the buffer. There
1682 * could be several smaller frames in the buffer and if so they will
1683 * not trigger the XON until their total number reduces the buffer
1685 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1687 rx_buf_size = igb_get_rx_buffer_size(hw);
1689 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
1690 hw->fc.low_water = hw->fc.high_water - 1500;
1691 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1692 hw->fc.send_xon = 1;
1694 /* Set Flow control, use the tunable location if sane */
1695 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1696 hw->fc.requested_mode = igb_fc_setting;
1698 hw->fc.requested_mode = e1000_fc_none;
1700 /* Issue a global reset */
1701 igb_pf_reset_hw(hw);
1702 E1000_WRITE_REG(hw, E1000_WUC, 0);
1704 diag = e1000_init_hw(hw);
1708 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1709 e1000_get_phy_info(hw);
1710 e1000_check_for_link(hw);
1715 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1717 igb_read_stats_registers(struct e1000_hw *hw, struct e1000_hw_stats *stats)
1721 uint64_t old_gprc = stats->gprc;
1722 uint64_t old_gptc = stats->gptc;
1723 uint64_t old_tpr = stats->tpr;
1724 uint64_t old_tpt = stats->tpt;
1725 uint64_t old_rpthc = stats->rpthc;
1726 uint64_t old_hgptc = stats->hgptc;
1728 if(hw->phy.media_type == e1000_media_type_copper ||
1729 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1731 E1000_READ_REG(hw,E1000_SYMERRS);
1732 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1735 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1736 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1737 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1738 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1740 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1741 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1742 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1743 stats->dc += E1000_READ_REG(hw, E1000_DC);
1744 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1745 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1746 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1748 ** For watchdog management we need to know if we have been
1749 ** paused during the last interval, so capture that here.
1751 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1752 stats->xoffrxc += pause_frames;
1753 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1754 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1755 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1756 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1757 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1758 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1759 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1760 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1761 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1762 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1763 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1764 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1766 /* For the 64-bit byte counters the low dword must be read first. */
1767 /* Both registers clear on the read of the high dword */
1769 /* Workaround CRC bytes included in size, take away 4 bytes/packet */
1770 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1771 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1772 stats->gorc -= (stats->gprc - old_gprc) * ETHER_CRC_LEN;
1773 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1774 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1775 stats->gotc -= (stats->gptc - old_gptc) * ETHER_CRC_LEN;
1777 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1778 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1779 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1780 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1781 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1783 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1784 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1786 stats->tor += E1000_READ_REG(hw, E1000_TORL);
1787 stats->tor += ((uint64_t)E1000_READ_REG(hw, E1000_TORH) << 32);
1788 stats->tor -= (stats->tpr - old_tpr) * ETHER_CRC_LEN;
1789 stats->tot += E1000_READ_REG(hw, E1000_TOTL);
1790 stats->tot += ((uint64_t)E1000_READ_REG(hw, E1000_TOTH) << 32);
1791 stats->tot -= (stats->tpt - old_tpt) * ETHER_CRC_LEN;
1793 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1794 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1795 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1796 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1797 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1798 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1799 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1800 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1802 /* Interrupt Counts */
1804 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1805 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1806 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1807 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1808 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1809 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1810 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1811 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1812 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1814 /* Host to Card Statistics */
1816 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1817 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1818 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1819 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1820 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1821 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1822 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1823 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1824 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1825 stats->hgorc -= (stats->rpthc - old_rpthc) * ETHER_CRC_LEN;
1826 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1827 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1828 stats->hgotc -= (stats->hgptc - old_hgptc) * ETHER_CRC_LEN;
1829 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1830 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1831 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1833 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1834 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1835 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1836 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1837 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1838 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1842 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1844 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1845 struct e1000_hw_stats *stats =
1846 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1848 igb_read_stats_registers(hw, stats);
1850 if (rte_stats == NULL)
1854 rte_stats->imissed = stats->mpc;
1855 rte_stats->ierrors = stats->crcerrs +
1856 stats->rlec + stats->ruc + stats->roc +
1857 stats->rxerrc + stats->algnerrc + stats->cexterr;
1860 rte_stats->oerrors = stats->ecol + stats->latecol;
1862 rte_stats->ipackets = stats->gprc;
1863 rte_stats->opackets = stats->gptc;
1864 rte_stats->ibytes = stats->gorc;
1865 rte_stats->obytes = stats->gotc;
1870 eth_igb_stats_reset(struct rte_eth_dev *dev)
1872 struct e1000_hw_stats *hw_stats =
1873 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1875 /* HW registers are cleared on read */
1876 eth_igb_stats_get(dev, NULL);
1878 /* Reset software totals */
1879 memset(hw_stats, 0, sizeof(*hw_stats));
1883 eth_igb_xstats_reset(struct rte_eth_dev *dev)
1885 struct e1000_hw_stats *stats =
1886 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1888 /* HW registers are cleared on read */
1889 eth_igb_xstats_get(dev, NULL, IGB_NB_XSTATS);
1891 /* Reset software totals */
1892 memset(stats, 0, sizeof(*stats));
1895 static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1896 struct rte_eth_xstat_name *xstats_names,
1897 __rte_unused unsigned int size)
1901 if (xstats_names == NULL)
1902 return IGB_NB_XSTATS;
1904 /* Note: limit checked in rte_eth_xstats_names() */
1906 for (i = 0; i < IGB_NB_XSTATS; i++) {
1907 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
1908 "%s", rte_igb_stats_strings[i].name);
1911 return IGB_NB_XSTATS;
1914 static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
1915 struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
1921 if (xstats_names == NULL)
1922 return IGB_NB_XSTATS;
1924 for (i = 0; i < IGB_NB_XSTATS; i++)
1925 snprintf(xstats_names[i].name,
1926 sizeof(xstats_names[i].name),
1927 "%s", rte_igb_stats_strings[i].name);
1929 return IGB_NB_XSTATS;
1932 struct rte_eth_xstat_name xstats_names_copy[IGB_NB_XSTATS];
1934 eth_igb_xstats_get_names_by_id(dev, xstats_names_copy, NULL,
1937 for (i = 0; i < limit; i++) {
1938 if (ids[i] >= IGB_NB_XSTATS) {
1939 PMD_INIT_LOG(ERR, "id value isn't valid");
1942 strcpy(xstats_names[i].name,
1943 xstats_names_copy[ids[i]].name);
1950 eth_igb_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1953 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1954 struct e1000_hw_stats *hw_stats =
1955 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1958 if (n < IGB_NB_XSTATS)
1959 return IGB_NB_XSTATS;
1961 igb_read_stats_registers(hw, hw_stats);
1963 /* If this is a reset xstats is NULL, and we have cleared the
1964 * registers by reading them.
1969 /* Extended stats */
1970 for (i = 0; i < IGB_NB_XSTATS; i++) {
1972 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
1973 rte_igb_stats_strings[i].offset);
1976 return IGB_NB_XSTATS;
1980 eth_igb_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1981 uint64_t *values, unsigned int n)
1986 struct e1000_hw *hw =
1987 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1988 struct e1000_hw_stats *hw_stats =
1989 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1991 if (n < IGB_NB_XSTATS)
1992 return IGB_NB_XSTATS;
1994 igb_read_stats_registers(hw, hw_stats);
1996 /* If this is a reset xstats is NULL, and we have cleared the
1997 * registers by reading them.
2002 /* Extended stats */
2003 for (i = 0; i < IGB_NB_XSTATS; i++)
2004 values[i] = *(uint64_t *)(((char *)hw_stats) +
2005 rte_igb_stats_strings[i].offset);
2007 return IGB_NB_XSTATS;
2010 uint64_t values_copy[IGB_NB_XSTATS];
2012 eth_igb_xstats_get_by_id(dev, NULL, values_copy,
2015 for (i = 0; i < n; i++) {
2016 if (ids[i] >= IGB_NB_XSTATS) {
2017 PMD_INIT_LOG(ERR, "id value isn't valid");
2020 values[i] = values_copy[ids[i]];
2027 igbvf_read_stats_registers(struct e1000_hw *hw, struct e1000_vf_stats *hw_stats)
2029 /* Good Rx packets, include VF loopback */
2030 UPDATE_VF_STAT(E1000_VFGPRC,
2031 hw_stats->last_gprc, hw_stats->gprc);
2033 /* Good Rx octets, include VF loopback */
2034 UPDATE_VF_STAT(E1000_VFGORC,
2035 hw_stats->last_gorc, hw_stats->gorc);
2037 /* Good Tx packets, include VF loopback */
2038 UPDATE_VF_STAT(E1000_VFGPTC,
2039 hw_stats->last_gptc, hw_stats->gptc);
2041 /* Good Tx octets, include VF loopback */
2042 UPDATE_VF_STAT(E1000_VFGOTC,
2043 hw_stats->last_gotc, hw_stats->gotc);
2045 /* Rx Multicst packets */
2046 UPDATE_VF_STAT(E1000_VFMPRC,
2047 hw_stats->last_mprc, hw_stats->mprc);
2049 /* Good Rx loopback packets */
2050 UPDATE_VF_STAT(E1000_VFGPRLBC,
2051 hw_stats->last_gprlbc, hw_stats->gprlbc);
2053 /* Good Rx loopback octets */
2054 UPDATE_VF_STAT(E1000_VFGORLBC,
2055 hw_stats->last_gorlbc, hw_stats->gorlbc);
2057 /* Good Tx loopback packets */
2058 UPDATE_VF_STAT(E1000_VFGPTLBC,
2059 hw_stats->last_gptlbc, hw_stats->gptlbc);
2061 /* Good Tx loopback octets */
2062 UPDATE_VF_STAT(E1000_VFGOTLBC,
2063 hw_stats->last_gotlbc, hw_stats->gotlbc);
2066 static int eth_igbvf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2067 struct rte_eth_xstat_name *xstats_names,
2068 __rte_unused unsigned limit)
2072 if (xstats_names != NULL)
2073 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2074 snprintf(xstats_names[i].name,
2075 sizeof(xstats_names[i].name), "%s",
2076 rte_igbvf_stats_strings[i].name);
2078 return IGBVF_NB_XSTATS;
2082 eth_igbvf_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2085 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2086 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2087 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2090 if (n < IGBVF_NB_XSTATS)
2091 return IGBVF_NB_XSTATS;
2093 igbvf_read_stats_registers(hw, hw_stats);
2098 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2100 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
2101 rte_igbvf_stats_strings[i].offset);
2104 return IGBVF_NB_XSTATS;
2108 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
2110 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2111 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2112 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2114 igbvf_read_stats_registers(hw, hw_stats);
2116 if (rte_stats == NULL)
2119 rte_stats->ipackets = hw_stats->gprc;
2120 rte_stats->ibytes = hw_stats->gorc;
2121 rte_stats->opackets = hw_stats->gptc;
2122 rte_stats->obytes = hw_stats->gotc;
2127 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
2129 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
2130 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2132 /* Sync HW register to the last stats */
2133 eth_igbvf_stats_get(dev, NULL);
2135 /* reset HW current stats*/
2136 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
2137 offsetof(struct e1000_vf_stats, gprc));
2141 eth_igb_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
2144 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2145 struct e1000_fw_version fw;
2148 e1000_get_fw_version(hw, &fw);
2150 switch (hw->mac.type) {
2153 if (!(e1000_get_flash_presence_i210(hw))) {
2154 ret = snprintf(fw_version, fw_size,
2156 fw.invm_major, fw.invm_minor,
2162 /* if option rom is valid, display its version too */
2164 ret = snprintf(fw_version, fw_size,
2165 "%d.%d, 0x%08x, %d.%d.%d",
2166 fw.eep_major, fw.eep_minor, fw.etrack_id,
2167 fw.or_major, fw.or_build, fw.or_patch);
2170 if (fw.etrack_id != 0X0000) {
2171 ret = snprintf(fw_version, fw_size,
2173 fw.eep_major, fw.eep_minor,
2176 ret = snprintf(fw_version, fw_size,
2178 fw.eep_major, fw.eep_minor,
2185 ret += 1; /* add the size of '\0' */
2186 if (fw_size < (u32)ret)
2193 eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2195 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2197 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2198 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2199 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2200 dev_info->rx_queue_offload_capa = igb_get_rx_queue_offloads_capa(dev);
2201 dev_info->rx_offload_capa = igb_get_rx_port_offloads_capa(dev) |
2202 dev_info->rx_queue_offload_capa;
2203 dev_info->tx_queue_offload_capa = igb_get_tx_queue_offloads_capa(dev);
2204 dev_info->tx_offload_capa = igb_get_tx_port_offloads_capa(dev) |
2205 dev_info->tx_queue_offload_capa;
2207 switch (hw->mac.type) {
2209 dev_info->max_rx_queues = 4;
2210 dev_info->max_tx_queues = 4;
2211 dev_info->max_vmdq_pools = 0;
2215 dev_info->max_rx_queues = 16;
2216 dev_info->max_tx_queues = 16;
2217 dev_info->max_vmdq_pools = ETH_8_POOLS;
2218 dev_info->vmdq_queue_num = 16;
2222 dev_info->max_rx_queues = 8;
2223 dev_info->max_tx_queues = 8;
2224 dev_info->max_vmdq_pools = ETH_8_POOLS;
2225 dev_info->vmdq_queue_num = 8;
2229 dev_info->max_rx_queues = 8;
2230 dev_info->max_tx_queues = 8;
2231 dev_info->max_vmdq_pools = ETH_8_POOLS;
2232 dev_info->vmdq_queue_num = 8;
2236 dev_info->max_rx_queues = 8;
2237 dev_info->max_tx_queues = 8;
2241 dev_info->max_rx_queues = 4;
2242 dev_info->max_tx_queues = 4;
2243 dev_info->max_vmdq_pools = 0;
2247 dev_info->max_rx_queues = 2;
2248 dev_info->max_tx_queues = 2;
2249 dev_info->max_vmdq_pools = 0;
2253 /* Should not happen */
2256 dev_info->hash_key_size = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
2257 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
2258 dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
2260 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2262 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2263 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2264 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2266 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2271 dev_info->default_txconf = (struct rte_eth_txconf) {
2273 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2274 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2275 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2280 dev_info->rx_desc_lim = rx_desc_lim;
2281 dev_info->tx_desc_lim = tx_desc_lim;
2283 dev_info->speed_capa = ETH_LINK_SPEED_10M_HD | ETH_LINK_SPEED_10M |
2284 ETH_LINK_SPEED_100M_HD | ETH_LINK_SPEED_100M |
2287 dev_info->max_mtu = dev_info->max_rx_pktlen - E1000_ETH_OVERHEAD;
2288 dev_info->min_mtu = ETHER_MIN_MTU;
2292 static const uint32_t *
2293 eth_igb_supported_ptypes_get(struct rte_eth_dev *dev)
2295 static const uint32_t ptypes[] = {
2296 /* refers to igb_rxd_pkt_info_to_pkt_type() */
2299 RTE_PTYPE_L3_IPV4_EXT,
2301 RTE_PTYPE_L3_IPV6_EXT,
2305 RTE_PTYPE_TUNNEL_IP,
2306 RTE_PTYPE_INNER_L3_IPV6,
2307 RTE_PTYPE_INNER_L3_IPV6_EXT,
2308 RTE_PTYPE_INNER_L4_TCP,
2309 RTE_PTYPE_INNER_L4_UDP,
2313 if (dev->rx_pkt_burst == eth_igb_recv_pkts ||
2314 dev->rx_pkt_burst == eth_igb_recv_scattered_pkts)
2320 eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2322 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2324 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2325 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2326 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2327 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
2328 DEV_TX_OFFLOAD_IPV4_CKSUM |
2329 DEV_TX_OFFLOAD_UDP_CKSUM |
2330 DEV_TX_OFFLOAD_TCP_CKSUM |
2331 DEV_TX_OFFLOAD_SCTP_CKSUM |
2332 DEV_TX_OFFLOAD_TCP_TSO;
2333 switch (hw->mac.type) {
2335 dev_info->max_rx_queues = 2;
2336 dev_info->max_tx_queues = 2;
2338 case e1000_vfadapt_i350:
2339 dev_info->max_rx_queues = 1;
2340 dev_info->max_tx_queues = 1;
2343 /* Should not happen */
2347 dev_info->rx_queue_offload_capa = igb_get_rx_queue_offloads_capa(dev);
2348 dev_info->rx_offload_capa = igb_get_rx_port_offloads_capa(dev) |
2349 dev_info->rx_queue_offload_capa;
2350 dev_info->tx_queue_offload_capa = igb_get_tx_queue_offloads_capa(dev);
2351 dev_info->tx_offload_capa = igb_get_tx_port_offloads_capa(dev) |
2352 dev_info->tx_queue_offload_capa;
2354 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2356 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2357 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2358 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2360 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2365 dev_info->default_txconf = (struct rte_eth_txconf) {
2367 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2368 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2369 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2374 dev_info->rx_desc_lim = rx_desc_lim;
2375 dev_info->tx_desc_lim = tx_desc_lim;
2378 /* return 0 means link status changed, -1 means not changed */
2380 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2382 struct e1000_hw *hw =
2383 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2384 struct rte_eth_link link;
2385 int link_check, count;
2388 hw->mac.get_link_status = 1;
2390 /* possible wait-to-complete in up to 9 seconds */
2391 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
2392 /* Read the real link status */
2393 switch (hw->phy.media_type) {
2394 case e1000_media_type_copper:
2395 /* Do the work to read phy */
2396 e1000_check_for_link(hw);
2397 link_check = !hw->mac.get_link_status;
2400 case e1000_media_type_fiber:
2401 e1000_check_for_link(hw);
2402 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
2406 case e1000_media_type_internal_serdes:
2407 e1000_check_for_link(hw);
2408 link_check = hw->mac.serdes_has_link;
2411 /* VF device is type_unknown */
2412 case e1000_media_type_unknown:
2413 eth_igbvf_link_update(hw);
2414 link_check = !hw->mac.get_link_status;
2420 if (link_check || wait_to_complete == 0)
2422 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
2424 memset(&link, 0, sizeof(link));
2426 /* Now we check if a transition has happened */
2428 uint16_t duplex, speed;
2429 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
2430 link.link_duplex = (duplex == FULL_DUPLEX) ?
2431 ETH_LINK_FULL_DUPLEX :
2432 ETH_LINK_HALF_DUPLEX;
2433 link.link_speed = speed;
2434 link.link_status = ETH_LINK_UP;
2435 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2436 ETH_LINK_SPEED_FIXED);
2437 } else if (!link_check) {
2438 link.link_speed = 0;
2439 link.link_duplex = ETH_LINK_HALF_DUPLEX;
2440 link.link_status = ETH_LINK_DOWN;
2441 link.link_autoneg = ETH_LINK_FIXED;
2444 return rte_eth_linkstatus_set(dev, &link);
2448 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
2449 * For ASF and Pass Through versions of f/w this means
2450 * that the driver is loaded.
2453 igb_hw_control_acquire(struct e1000_hw *hw)
2457 /* Let firmware know the driver has taken over */
2458 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2459 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2463 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
2464 * For ASF and Pass Through versions of f/w this means that the
2465 * driver is no longer loaded.
2468 igb_hw_control_release(struct e1000_hw *hw)
2472 /* Let firmware taken over control of h/w */
2473 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2474 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
2475 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2479 * Bit of a misnomer, what this really means is
2480 * to enable OS management of the system... aka
2481 * to disable special hardware management features.
2484 igb_init_manageability(struct e1000_hw *hw)
2486 if (e1000_enable_mng_pass_thru(hw)) {
2487 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
2488 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2490 /* disable hardware interception of ARP */
2491 manc &= ~(E1000_MANC_ARP_EN);
2493 /* enable receiving management packets to the host */
2494 manc |= E1000_MANC_EN_MNG2HOST;
2495 manc2h |= 1 << 5; /* Mng Port 623 */
2496 manc2h |= 1 << 6; /* Mng Port 664 */
2497 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
2498 E1000_WRITE_REG(hw, E1000_MANC, manc);
2503 igb_release_manageability(struct e1000_hw *hw)
2505 if (e1000_enable_mng_pass_thru(hw)) {
2506 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2508 manc |= E1000_MANC_ARP_EN;
2509 manc &= ~E1000_MANC_EN_MNG2HOST;
2511 E1000_WRITE_REG(hw, E1000_MANC, manc);
2516 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
2518 struct e1000_hw *hw =
2519 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2522 rctl = E1000_READ_REG(hw, E1000_RCTL);
2523 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2524 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2528 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
2530 struct e1000_hw *hw =
2531 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2534 rctl = E1000_READ_REG(hw, E1000_RCTL);
2535 rctl &= (~E1000_RCTL_UPE);
2536 if (dev->data->all_multicast == 1)
2537 rctl |= E1000_RCTL_MPE;
2539 rctl &= (~E1000_RCTL_MPE);
2540 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2544 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
2546 struct e1000_hw *hw =
2547 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2550 rctl = E1000_READ_REG(hw, E1000_RCTL);
2551 rctl |= E1000_RCTL_MPE;
2552 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2556 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
2558 struct e1000_hw *hw =
2559 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2562 if (dev->data->promiscuous == 1)
2563 return; /* must remain in all_multicast mode */
2564 rctl = E1000_READ_REG(hw, E1000_RCTL);
2565 rctl &= (~E1000_RCTL_MPE);
2566 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2570 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2572 struct e1000_hw *hw =
2573 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2574 struct e1000_vfta * shadow_vfta =
2575 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2580 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
2581 E1000_VFTA_ENTRY_MASK);
2582 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
2583 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
2588 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
2590 /* update local VFTA copy */
2591 shadow_vfta->vfta[vid_idx] = vfta;
2597 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
2598 enum rte_vlan_type vlan_type,
2601 struct e1000_hw *hw =
2602 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2605 qinq = E1000_READ_REG(hw, E1000_CTRL_EXT);
2606 qinq &= E1000_CTRL_EXT_EXT_VLAN;
2608 /* only outer TPID of double VLAN can be configured*/
2609 if (qinq && vlan_type == ETH_VLAN_TYPE_OUTER) {
2610 reg = E1000_READ_REG(hw, E1000_VET);
2611 reg = (reg & (~E1000_VET_VET_EXT)) |
2612 ((uint32_t)tpid << E1000_VET_VET_EXT_SHIFT);
2613 E1000_WRITE_REG(hw, E1000_VET, reg);
2618 /* all other TPID values are read-only*/
2619 PMD_DRV_LOG(ERR, "Not supported");
2625 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
2627 struct e1000_hw *hw =
2628 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2631 /* Filter Table Disable */
2632 reg = E1000_READ_REG(hw, E1000_RCTL);
2633 reg &= ~E1000_RCTL_CFIEN;
2634 reg &= ~E1000_RCTL_VFE;
2635 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2639 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2641 struct e1000_hw *hw =
2642 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2643 struct e1000_vfta * shadow_vfta =
2644 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2648 /* Filter Table Enable, CFI not used for packet acceptance */
2649 reg = E1000_READ_REG(hw, E1000_RCTL);
2650 reg &= ~E1000_RCTL_CFIEN;
2651 reg |= E1000_RCTL_VFE;
2652 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2654 /* restore VFTA table */
2655 for (i = 0; i < IGB_VFTA_SIZE; i++)
2656 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
2660 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
2662 struct e1000_hw *hw =
2663 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2666 /* VLAN Mode Disable */
2667 reg = E1000_READ_REG(hw, E1000_CTRL);
2668 reg &= ~E1000_CTRL_VME;
2669 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2673 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
2675 struct e1000_hw *hw =
2676 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2679 /* VLAN Mode Enable */
2680 reg = E1000_READ_REG(hw, E1000_CTRL);
2681 reg |= E1000_CTRL_VME;
2682 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2686 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2688 struct e1000_hw *hw =
2689 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2692 /* CTRL_EXT: Extended VLAN */
2693 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2694 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
2695 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2697 /* Update maximum packet length */
2698 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
2699 E1000_WRITE_REG(hw, E1000_RLPML,
2700 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2705 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2707 struct e1000_hw *hw =
2708 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2711 /* CTRL_EXT: Extended VLAN */
2712 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2713 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
2714 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2716 /* Update maximum packet length */
2717 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
2718 E1000_WRITE_REG(hw, E1000_RLPML,
2719 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2724 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2726 struct rte_eth_rxmode *rxmode;
2728 rxmode = &dev->data->dev_conf.rxmode;
2729 if(mask & ETH_VLAN_STRIP_MASK){
2730 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
2731 igb_vlan_hw_strip_enable(dev);
2733 igb_vlan_hw_strip_disable(dev);
2736 if(mask & ETH_VLAN_FILTER_MASK){
2737 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
2738 igb_vlan_hw_filter_enable(dev);
2740 igb_vlan_hw_filter_disable(dev);
2743 if(mask & ETH_VLAN_EXTEND_MASK){
2744 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
2745 igb_vlan_hw_extend_enable(dev);
2747 igb_vlan_hw_extend_disable(dev);
2755 * It enables the interrupt mask and then enable the interrupt.
2758 * Pointer to struct rte_eth_dev.
2763 * - On success, zero.
2764 * - On failure, a negative value.
2767 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
2769 struct e1000_interrupt *intr =
2770 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2773 intr->mask |= E1000_ICR_LSC;
2775 intr->mask &= ~E1000_ICR_LSC;
2780 /* It clears the interrupt causes and enables the interrupt.
2781 * It will be called once only during nic initialized.
2784 * Pointer to struct rte_eth_dev.
2787 * - On success, zero.
2788 * - On failure, a negative value.
2790 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev)
2792 uint32_t mask, regval;
2793 struct e1000_hw *hw =
2794 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2795 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2796 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2797 int misc_shift = rte_intr_allow_others(intr_handle) ? 1 : 0;
2798 struct rte_eth_dev_info dev_info;
2800 memset(&dev_info, 0, sizeof(dev_info));
2801 eth_igb_infos_get(dev, &dev_info);
2803 mask = (0xFFFFFFFF >> (32 - dev_info.max_rx_queues)) << misc_shift;
2804 regval = E1000_READ_REG(hw, E1000_EIMS);
2805 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
2811 * It reads ICR and gets interrupt causes, check it and set a bit flag
2812 * to update link status.
2815 * Pointer to struct rte_eth_dev.
2818 * - On success, zero.
2819 * - On failure, a negative value.
2822 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
2825 struct e1000_hw *hw =
2826 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2827 struct e1000_interrupt *intr =
2828 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2830 igb_intr_disable(dev);
2832 /* read-on-clear nic registers here */
2833 icr = E1000_READ_REG(hw, E1000_ICR);
2836 if (icr & E1000_ICR_LSC) {
2837 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
2840 if (icr & E1000_ICR_VMMB)
2841 intr->flags |= E1000_FLAG_MAILBOX;
2847 * It executes link_update after knowing an interrupt is prsent.
2850 * Pointer to struct rte_eth_dev.
2853 * - On success, zero.
2854 * - On failure, a negative value.
2857 eth_igb_interrupt_action(struct rte_eth_dev *dev,
2858 struct rte_intr_handle *intr_handle)
2860 struct e1000_hw *hw =
2861 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2862 struct e1000_interrupt *intr =
2863 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2864 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2865 struct rte_eth_link link;
2868 if (intr->flags & E1000_FLAG_MAILBOX) {
2869 igb_pf_mbx_process(dev);
2870 intr->flags &= ~E1000_FLAG_MAILBOX;
2873 igb_intr_enable(dev);
2874 rte_intr_enable(intr_handle);
2876 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
2877 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
2879 /* set get_link_status to check register later */
2880 hw->mac.get_link_status = 1;
2881 ret = eth_igb_link_update(dev, 0);
2883 /* check if link has changed */
2887 rte_eth_linkstatus_get(dev, &link);
2888 if (link.link_status) {
2890 " Port %d: Link Up - speed %u Mbps - %s",
2892 (unsigned)link.link_speed,
2893 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2894 "full-duplex" : "half-duplex");
2896 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2897 dev->data->port_id);
2900 PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
2901 pci_dev->addr.domain,
2903 pci_dev->addr.devid,
2904 pci_dev->addr.function);
2905 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
2913 * Interrupt handler which shall be registered at first.
2916 * Pointer to interrupt handle.
2918 * The address of parameter (struct rte_eth_dev *) regsitered before.
2924 eth_igb_interrupt_handler(void *param)
2926 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2928 eth_igb_interrupt_get_status(dev);
2929 eth_igb_interrupt_action(dev, dev->intr_handle);
2933 eth_igbvf_interrupt_get_status(struct rte_eth_dev *dev)
2936 struct e1000_hw *hw =
2937 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2938 struct e1000_interrupt *intr =
2939 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2941 igbvf_intr_disable(hw);
2943 /* read-on-clear nic registers here */
2944 eicr = E1000_READ_REG(hw, E1000_EICR);
2947 if (eicr == E1000_VTIVAR_MISC_MAILBOX)
2948 intr->flags |= E1000_FLAG_MAILBOX;
2953 void igbvf_mbx_process(struct rte_eth_dev *dev)
2955 struct e1000_hw *hw =
2956 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2957 struct e1000_mbx_info *mbx = &hw->mbx;
2960 /* peek the message first */
2961 in_msg = E1000_READ_REG(hw, E1000_VMBMEM(0));
2963 /* PF reset VF event */
2964 if (in_msg == E1000_PF_CONTROL_MSG) {
2965 /* dummy mbx read to ack pf */
2966 if (mbx->ops.read(hw, &in_msg, 1, 0))
2968 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
2974 eth_igbvf_interrupt_action(struct rte_eth_dev *dev, struct rte_intr_handle *intr_handle)
2976 struct e1000_interrupt *intr =
2977 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2979 if (intr->flags & E1000_FLAG_MAILBOX) {
2980 igbvf_mbx_process(dev);
2981 intr->flags &= ~E1000_FLAG_MAILBOX;
2984 igbvf_intr_enable(dev);
2985 rte_intr_enable(intr_handle);
2991 eth_igbvf_interrupt_handler(void *param)
2993 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2995 eth_igbvf_interrupt_get_status(dev);
2996 eth_igbvf_interrupt_action(dev, dev->intr_handle);
3000 eth_igb_led_on(struct rte_eth_dev *dev)
3002 struct e1000_hw *hw;
3004 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3005 return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
3009 eth_igb_led_off(struct rte_eth_dev *dev)
3011 struct e1000_hw *hw;
3013 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3014 return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
3018 eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3020 struct e1000_hw *hw;
3025 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3026 fc_conf->pause_time = hw->fc.pause_time;
3027 fc_conf->high_water = hw->fc.high_water;
3028 fc_conf->low_water = hw->fc.low_water;
3029 fc_conf->send_xon = hw->fc.send_xon;
3030 fc_conf->autoneg = hw->mac.autoneg;
3033 * Return rx_pause and tx_pause status according to actual setting of
3034 * the TFCE and RFCE bits in the CTRL register.
3036 ctrl = E1000_READ_REG(hw, E1000_CTRL);
3037 if (ctrl & E1000_CTRL_TFCE)
3042 if (ctrl & E1000_CTRL_RFCE)
3047 if (rx_pause && tx_pause)
3048 fc_conf->mode = RTE_FC_FULL;
3050 fc_conf->mode = RTE_FC_RX_PAUSE;
3052 fc_conf->mode = RTE_FC_TX_PAUSE;
3054 fc_conf->mode = RTE_FC_NONE;
3060 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3062 struct e1000_hw *hw;
3064 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
3070 uint32_t rx_buf_size;
3071 uint32_t max_high_water;
3074 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3075 if (fc_conf->autoneg != hw->mac.autoneg)
3077 rx_buf_size = igb_get_rx_buffer_size(hw);
3078 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
3080 /* At least reserve one Ethernet frame for watermark */
3081 max_high_water = rx_buf_size - ETHER_MAX_LEN;
3082 if ((fc_conf->high_water > max_high_water) ||
3083 (fc_conf->high_water < fc_conf->low_water)) {
3084 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
3085 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
3089 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
3090 hw->fc.pause_time = fc_conf->pause_time;
3091 hw->fc.high_water = fc_conf->high_water;
3092 hw->fc.low_water = fc_conf->low_water;
3093 hw->fc.send_xon = fc_conf->send_xon;
3095 err = e1000_setup_link_generic(hw);
3096 if (err == E1000_SUCCESS) {
3098 /* check if we want to forward MAC frames - driver doesn't have native
3099 * capability to do that, so we'll write the registers ourselves */
3101 rctl = E1000_READ_REG(hw, E1000_RCTL);
3103 /* set or clear MFLCN.PMCF bit depending on configuration */
3104 if (fc_conf->mac_ctrl_frame_fwd != 0)
3105 rctl |= E1000_RCTL_PMCF;
3107 rctl &= ~E1000_RCTL_PMCF;
3109 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3110 E1000_WRITE_FLUSH(hw);
3115 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
3119 #define E1000_RAH_POOLSEL_SHIFT (18)
3121 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
3122 uint32_t index, uint32_t pool)
3124 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3127 e1000_rar_set(hw, mac_addr->addr_bytes, index);
3128 rah = E1000_READ_REG(hw, E1000_RAH(index));
3129 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
3130 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
3135 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
3137 uint8_t addr[ETHER_ADDR_LEN];
3138 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3140 memset(addr, 0, sizeof(addr));
3142 e1000_rar_set(hw, addr, index);
3146 eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
3147 struct ether_addr *addr)
3149 eth_igb_rar_clear(dev, 0);
3150 eth_igb_rar_set(dev, (void *)addr, 0, 0);
3155 * Virtual Function operations
3158 igbvf_intr_disable(struct e1000_hw *hw)
3160 PMD_INIT_FUNC_TRACE();
3162 /* Clear interrupt mask to stop from interrupts being generated */
3163 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
3165 E1000_WRITE_FLUSH(hw);
3169 igbvf_stop_adapter(struct rte_eth_dev *dev)
3173 struct rte_eth_dev_info dev_info;
3174 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3176 memset(&dev_info, 0, sizeof(dev_info));
3177 eth_igbvf_infos_get(dev, &dev_info);
3179 /* Clear interrupt mask to stop from interrupts being generated */
3180 igbvf_intr_disable(hw);
3182 /* Clear any pending interrupts, flush previous writes */
3183 E1000_READ_REG(hw, E1000_EICR);
3185 /* Disable the transmit unit. Each queue must be disabled. */
3186 for (i = 0; i < dev_info.max_tx_queues; i++)
3187 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
3189 /* Disable the receive unit by stopping each queue */
3190 for (i = 0; i < dev_info.max_rx_queues; i++) {
3191 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
3192 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
3193 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
3194 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
3198 /* flush all queues disables */
3199 E1000_WRITE_FLUSH(hw);
3203 static int eth_igbvf_link_update(struct e1000_hw *hw)
3205 struct e1000_mbx_info *mbx = &hw->mbx;
3206 struct e1000_mac_info *mac = &hw->mac;
3207 int ret_val = E1000_SUCCESS;
3209 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
3212 * We only want to run this if there has been a rst asserted.
3213 * in this case that could mean a link change, device reset,
3214 * or a virtual function reset
3217 /* If we were hit with a reset or timeout drop the link */
3218 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
3219 mac->get_link_status = TRUE;
3221 if (!mac->get_link_status)
3224 /* if link status is down no point in checking to see if pf is up */
3225 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
3228 /* if we passed all the tests above then the link is up and we no
3229 * longer need to check for link */
3230 mac->get_link_status = FALSE;
3238 igbvf_dev_configure(struct rte_eth_dev *dev)
3240 struct rte_eth_conf* conf = &dev->data->dev_conf;
3242 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
3243 dev->data->port_id);
3246 * VF has no ability to enable/disable HW CRC
3247 * Keep the persistent behavior the same as Host PF
3249 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
3250 if (conf->rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC) {
3251 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
3252 conf->rxmode.offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
3255 if (!(conf->rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)) {
3256 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
3257 conf->rxmode.offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
3265 igbvf_dev_start(struct rte_eth_dev *dev)
3267 struct e1000_hw *hw =
3268 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3269 struct e1000_adapter *adapter =
3270 E1000_DEV_PRIVATE(dev->data->dev_private);
3271 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3272 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3274 uint32_t intr_vector = 0;
3276 PMD_INIT_FUNC_TRACE();
3278 hw->mac.ops.reset_hw(hw);
3279 adapter->stopped = 0;
3282 igbvf_set_vfta_all(dev,1);
3284 eth_igbvf_tx_init(dev);
3286 /* This can fail when allocating mbufs for descriptor rings */
3287 ret = eth_igbvf_rx_init(dev);
3289 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
3290 igb_dev_clear_queues(dev);
3294 /* check and configure queue intr-vector mapping */
3295 if (rte_intr_cap_multiple(intr_handle) &&
3296 dev->data->dev_conf.intr_conf.rxq) {
3297 intr_vector = dev->data->nb_rx_queues;
3298 ret = rte_intr_efd_enable(intr_handle, intr_vector);
3303 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
3304 intr_handle->intr_vec =
3305 rte_zmalloc("intr_vec",
3306 dev->data->nb_rx_queues * sizeof(int), 0);
3307 if (!intr_handle->intr_vec) {
3308 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
3309 " intr_vec", dev->data->nb_rx_queues);
3314 eth_igbvf_configure_msix_intr(dev);
3316 /* enable uio/vfio intr/eventfd mapping */
3317 rte_intr_enable(intr_handle);
3319 /* resume enabled intr since hw reset */
3320 igbvf_intr_enable(dev);
3326 igbvf_dev_stop(struct rte_eth_dev *dev)
3328 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3329 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3331 PMD_INIT_FUNC_TRACE();
3333 igbvf_stop_adapter(dev);
3336 * Clear what we set, but we still keep shadow_vfta to
3337 * restore after device starts
3339 igbvf_set_vfta_all(dev,0);
3341 igb_dev_clear_queues(dev);
3343 /* disable intr eventfd mapping */
3344 rte_intr_disable(intr_handle);
3346 /* Clean datapath event and queue/vec mapping */
3347 rte_intr_efd_disable(intr_handle);
3348 if (intr_handle->intr_vec) {
3349 rte_free(intr_handle->intr_vec);
3350 intr_handle->intr_vec = NULL;
3355 igbvf_dev_close(struct rte_eth_dev *dev)
3357 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3358 struct e1000_adapter *adapter =
3359 E1000_DEV_PRIVATE(dev->data->dev_private);
3360 struct ether_addr addr;
3362 PMD_INIT_FUNC_TRACE();
3366 igbvf_dev_stop(dev);
3367 adapter->stopped = 1;
3368 igb_dev_free_queues(dev);
3371 * reprogram the RAR with a zero mac address,
3372 * to ensure that the VF traffic goes to the PF
3373 * after stop, close and detach of the VF.
3376 memset(&addr, 0, sizeof(addr));
3377 igbvf_default_mac_addr_set(dev, &addr);
3381 igbvf_promiscuous_enable(struct rte_eth_dev *dev)
3383 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3385 /* Set both unicast and multicast promisc */
3386 e1000_promisc_set_vf(hw, e1000_promisc_enabled);
3390 igbvf_promiscuous_disable(struct rte_eth_dev *dev)
3392 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3394 /* If in allmulticast mode leave multicast promisc */
3395 if (dev->data->all_multicast == 1)
3396 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3398 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3402 igbvf_allmulticast_enable(struct rte_eth_dev *dev)
3404 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3406 /* In promiscuous mode multicast promisc already set */
3407 if (dev->data->promiscuous == 0)
3408 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3412 igbvf_allmulticast_disable(struct rte_eth_dev *dev)
3414 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3416 /* In promiscuous mode leave multicast promisc enabled */
3417 if (dev->data->promiscuous == 0)
3418 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3421 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
3423 struct e1000_mbx_info *mbx = &hw->mbx;
3427 /* After set vlan, vlan strip will also be enabled in igb driver*/
3428 msgbuf[0] = E1000_VF_SET_VLAN;
3430 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
3432 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
3434 err = mbx->ops.write_posted(hw, msgbuf, 2, 0);
3438 err = mbx->ops.read_posted(hw, msgbuf, 2, 0);
3442 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
3443 if (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK))
3450 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
3452 struct e1000_hw *hw =
3453 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3454 struct e1000_vfta * shadow_vfta =
3455 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3456 int i = 0, j = 0, vfta = 0, mask = 1;
3458 for (i = 0; i < IGB_VFTA_SIZE; i++){
3459 vfta = shadow_vfta->vfta[i];
3462 for (j = 0; j < 32; j++){
3465 (uint16_t)((i<<5)+j), on);
3474 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3476 struct e1000_hw *hw =
3477 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3478 struct e1000_vfta * shadow_vfta =
3479 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3480 uint32_t vid_idx = 0;
3481 uint32_t vid_bit = 0;
3484 PMD_INIT_FUNC_TRACE();
3486 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
3487 ret = igbvf_set_vfta(hw, vlan_id, !!on);
3489 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
3492 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
3493 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
3495 /*Save what we set and retore it after device reset*/
3497 shadow_vfta->vfta[vid_idx] |= vid_bit;
3499 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
3505 igbvf_default_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *addr)
3507 struct e1000_hw *hw =
3508 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3510 /* index is not used by rar_set() */
3511 hw->mac.ops.rar_set(hw, (void *)addr, 0);
3517 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
3518 struct rte_eth_rss_reta_entry64 *reta_conf,
3523 uint16_t idx, shift;
3524 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3526 if (reta_size != ETH_RSS_RETA_SIZE_128) {
3527 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3528 "(%d) doesn't match the number hardware can supported "
3529 "(%d)", reta_size, ETH_RSS_RETA_SIZE_128);
3533 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3534 idx = i / RTE_RETA_GROUP_SIZE;
3535 shift = i % RTE_RETA_GROUP_SIZE;
3536 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3540 if (mask == IGB_4_BIT_MASK)
3543 r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3544 for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
3545 if (mask & (0x1 << j))
3546 reta |= reta_conf[idx].reta[shift + j] <<
3549 reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
3551 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
3558 eth_igb_rss_reta_query(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 != 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, ETH_RSS_RETA_SIZE_128);
3574 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3575 idx = i / RTE_RETA_GROUP_SIZE;
3576 shift = i % RTE_RETA_GROUP_SIZE;
3577 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3581 reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3582 for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
3583 if (mask & (0x1 << j))
3584 reta_conf[idx].reta[shift + j] =
3585 ((reta >> (CHAR_BIT * j)) &
3594 eth_igb_syn_filter_set(struct rte_eth_dev *dev,
3595 struct rte_eth_syn_filter *filter,
3598 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3599 struct e1000_filter_info *filter_info =
3600 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3601 uint32_t synqf, rfctl;
3603 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3606 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3609 if (synqf & E1000_SYN_FILTER_ENABLE)
3612 synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
3613 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
3615 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3616 if (filter->hig_pri)
3617 rfctl |= E1000_RFCTL_SYNQFP;
3619 rfctl &= ~E1000_RFCTL_SYNQFP;
3621 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
3623 if (!(synqf & E1000_SYN_FILTER_ENABLE))
3628 filter_info->syn_info = synqf;
3629 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
3630 E1000_WRITE_FLUSH(hw);
3635 eth_igb_syn_filter_get(struct rte_eth_dev *dev,
3636 struct rte_eth_syn_filter *filter)
3638 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3639 uint32_t synqf, rfctl;
3641 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3642 if (synqf & E1000_SYN_FILTER_ENABLE) {
3643 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3644 filter->hig_pri = (rfctl & E1000_RFCTL_SYNQFP) ? 1 : 0;
3645 filter->queue = (uint8_t)((synqf & E1000_SYN_FILTER_QUEUE) >>
3646 E1000_SYN_FILTER_QUEUE_SHIFT);
3654 eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
3655 enum rte_filter_op filter_op,
3658 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3661 MAC_TYPE_FILTER_SUP(hw->mac.type);
3663 if (filter_op == RTE_ETH_FILTER_NOP)
3667 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3672 switch (filter_op) {
3673 case RTE_ETH_FILTER_ADD:
3674 ret = eth_igb_syn_filter_set(dev,
3675 (struct rte_eth_syn_filter *)arg,
3678 case RTE_ETH_FILTER_DELETE:
3679 ret = eth_igb_syn_filter_set(dev,
3680 (struct rte_eth_syn_filter *)arg,
3683 case RTE_ETH_FILTER_GET:
3684 ret = eth_igb_syn_filter_get(dev,
3685 (struct rte_eth_syn_filter *)arg);
3688 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
3696 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
3698 ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
3699 struct e1000_2tuple_filter_info *filter_info)
3701 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3703 if (filter->priority > E1000_2TUPLE_MAX_PRI)
3704 return -EINVAL; /* filter index is out of range. */
3705 if (filter->tcp_flags > TCP_FLAG_ALL)
3706 return -EINVAL; /* flags is invalid. */
3708 switch (filter->dst_port_mask) {
3710 filter_info->dst_port_mask = 0;
3711 filter_info->dst_port = filter->dst_port;
3714 filter_info->dst_port_mask = 1;
3717 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3721 switch (filter->proto_mask) {
3723 filter_info->proto_mask = 0;
3724 filter_info->proto = filter->proto;
3727 filter_info->proto_mask = 1;
3730 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3734 filter_info->priority = (uint8_t)filter->priority;
3735 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3736 filter_info->tcp_flags = filter->tcp_flags;
3738 filter_info->tcp_flags = 0;
3743 static inline struct e1000_2tuple_filter *
3744 igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
3745 struct e1000_2tuple_filter_info *key)
3747 struct e1000_2tuple_filter *it;
3749 TAILQ_FOREACH(it, filter_list, entries) {
3750 if (memcmp(key, &it->filter_info,
3751 sizeof(struct e1000_2tuple_filter_info)) == 0) {
3758 /* inject a igb 2tuple filter to HW */
3760 igb_inject_2uple_filter(struct rte_eth_dev *dev,
3761 struct e1000_2tuple_filter *filter)
3763 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3764 uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
3765 uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3769 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3770 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3771 imir |= E1000_IMIR_PORT_BP;
3773 imir &= ~E1000_IMIR_PORT_BP;
3775 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3777 ttqf |= E1000_TTQF_QUEUE_ENABLE;
3778 ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
3779 ttqf |= (uint32_t)(filter->filter_info.proto &
3780 E1000_TTQF_PROTOCOL_MASK);
3781 if (filter->filter_info.proto_mask == 0)
3782 ttqf &= ~E1000_TTQF_MASK_ENABLE;
3784 /* tcp flags bits setting. */
3785 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3786 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3787 imir_ext |= E1000_IMIREXT_CTRL_URG;
3788 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3789 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3790 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3791 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3792 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3793 imir_ext |= E1000_IMIREXT_CTRL_RST;
3794 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3795 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3796 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3797 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3799 imir_ext |= E1000_IMIREXT_CTRL_BP;
3801 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3802 E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
3803 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3807 * igb_add_2tuple_filter - add a 2tuple filter
3810 * dev: Pointer to struct rte_eth_dev.
3811 * ntuple_filter: ponter to the filter that will be added.
3814 * - On success, zero.
3815 * - On failure, a negative value.
3818 igb_add_2tuple_filter(struct rte_eth_dev *dev,
3819 struct rte_eth_ntuple_filter *ntuple_filter)
3821 struct e1000_filter_info *filter_info =
3822 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3823 struct e1000_2tuple_filter *filter;
3826 filter = rte_zmalloc("e1000_2tuple_filter",
3827 sizeof(struct e1000_2tuple_filter), 0);
3831 ret = ntuple_filter_to_2tuple(ntuple_filter,
3832 &filter->filter_info);
3837 if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3838 &filter->filter_info) != NULL) {
3839 PMD_DRV_LOG(ERR, "filter exists.");
3843 filter->queue = ntuple_filter->queue;
3846 * look for an unused 2tuple filter index,
3847 * and insert the filter to list.
3849 for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
3850 if (!(filter_info->twotuple_mask & (1 << i))) {
3851 filter_info->twotuple_mask |= 1 << i;
3853 TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
3859 if (i >= E1000_MAX_TTQF_FILTERS) {
3860 PMD_DRV_LOG(ERR, "2tuple filters are full.");
3865 igb_inject_2uple_filter(dev, filter);
3870 igb_delete_2tuple_filter(struct rte_eth_dev *dev,
3871 struct e1000_2tuple_filter *filter)
3873 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3874 struct e1000_filter_info *filter_info =
3875 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3877 filter_info->twotuple_mask &= ~(1 << filter->index);
3878 TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
3881 E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
3882 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3883 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3888 * igb_remove_2tuple_filter - remove a 2tuple filter
3891 * dev: Pointer to struct rte_eth_dev.
3892 * ntuple_filter: ponter to the filter that will be removed.
3895 * - On success, zero.
3896 * - On failure, a negative value.
3899 igb_remove_2tuple_filter(struct rte_eth_dev *dev,
3900 struct rte_eth_ntuple_filter *ntuple_filter)
3902 struct e1000_filter_info *filter_info =
3903 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3904 struct e1000_2tuple_filter_info filter_2tuple;
3905 struct e1000_2tuple_filter *filter;
3908 memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
3909 ret = ntuple_filter_to_2tuple(ntuple_filter,
3914 filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3916 if (filter == NULL) {
3917 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3921 igb_delete_2tuple_filter(dev, filter);
3926 /* inject a igb flex filter to HW */
3928 igb_inject_flex_filter(struct rte_eth_dev *dev,
3929 struct e1000_flex_filter *filter)
3931 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3932 uint32_t wufc, queueing;
3936 wufc = E1000_READ_REG(hw, E1000_WUFC);
3937 if (filter->index < E1000_MAX_FHFT)
3938 reg_off = E1000_FHFT(filter->index);
3940 reg_off = E1000_FHFT_EXT(filter->index - E1000_MAX_FHFT);
3942 E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
3943 (E1000_WUFC_FLX0 << filter->index));
3944 queueing = filter->filter_info.len |
3945 (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
3946 (filter->filter_info.priority <<
3947 E1000_FHFT_QUEUEING_PRIO_SHIFT);
3948 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
3951 for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
3952 E1000_WRITE_REG(hw, reg_off,
3953 filter->filter_info.dwords[j]);
3954 reg_off += sizeof(uint32_t);
3955 E1000_WRITE_REG(hw, reg_off,
3956 filter->filter_info.dwords[++j]);
3957 reg_off += sizeof(uint32_t);
3958 E1000_WRITE_REG(hw, reg_off,
3959 (uint32_t)filter->filter_info.mask[i]);
3960 reg_off += sizeof(uint32_t) * 2;
3965 static inline struct e1000_flex_filter *
3966 eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
3967 struct e1000_flex_filter_info *key)
3969 struct e1000_flex_filter *it;
3971 TAILQ_FOREACH(it, filter_list, entries) {
3972 if (memcmp(key, &it->filter_info,
3973 sizeof(struct e1000_flex_filter_info)) == 0)
3980 /* remove a flex byte filter
3982 * dev: Pointer to struct rte_eth_dev.
3983 * filter: the pointer of the filter will be removed.
3986 igb_remove_flex_filter(struct rte_eth_dev *dev,
3987 struct e1000_flex_filter *filter)
3989 struct e1000_filter_info *filter_info =
3990 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3991 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3995 wufc = E1000_READ_REG(hw, E1000_WUFC);
3996 if (filter->index < E1000_MAX_FHFT)
3997 reg_off = E1000_FHFT(filter->index);
3999 reg_off = E1000_FHFT_EXT(filter->index - E1000_MAX_FHFT);
4001 for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
4002 E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
4004 E1000_WRITE_REG(hw, E1000_WUFC, wufc &
4005 (~(E1000_WUFC_FLX0 << filter->index)));
4007 filter_info->flex_mask &= ~(1 << filter->index);
4008 TAILQ_REMOVE(&filter_info->flex_list, filter, entries);
4013 eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
4014 struct rte_eth_flex_filter *filter,
4017 struct e1000_filter_info *filter_info =
4018 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4019 struct e1000_flex_filter *flex_filter, *it;
4023 flex_filter = rte_zmalloc("e1000_flex_filter",
4024 sizeof(struct e1000_flex_filter), 0);
4025 if (flex_filter == NULL)
4028 flex_filter->filter_info.len = filter->len;
4029 flex_filter->filter_info.priority = filter->priority;
4030 memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
4031 for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
4033 /* reverse bits in flex filter's mask*/
4034 for (shift = 0; shift < CHAR_BIT; shift++) {
4035 if (filter->mask[i] & (0x01 << shift))
4036 mask |= (0x80 >> shift);
4038 flex_filter->filter_info.mask[i] = mask;
4041 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
4042 &flex_filter->filter_info);
4043 if (it == NULL && !add) {
4044 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4045 rte_free(flex_filter);
4048 if (it != NULL && add) {
4049 PMD_DRV_LOG(ERR, "filter exists.");
4050 rte_free(flex_filter);
4055 flex_filter->queue = filter->queue;
4057 * look for an unused flex filter index
4058 * and insert the filter into the list.
4060 for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
4061 if (!(filter_info->flex_mask & (1 << i))) {
4062 filter_info->flex_mask |= 1 << i;
4063 flex_filter->index = i;
4064 TAILQ_INSERT_TAIL(&filter_info->flex_list,
4070 if (i >= E1000_MAX_FLEX_FILTERS) {
4071 PMD_DRV_LOG(ERR, "flex filters are full.");
4072 rte_free(flex_filter);
4076 igb_inject_flex_filter(dev, flex_filter);
4079 igb_remove_flex_filter(dev, it);
4080 rte_free(flex_filter);
4087 eth_igb_get_flex_filter(struct rte_eth_dev *dev,
4088 struct rte_eth_flex_filter *filter)
4090 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4091 struct e1000_filter_info *filter_info =
4092 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4093 struct e1000_flex_filter flex_filter, *it;
4094 uint32_t wufc, queueing, wufc_en = 0;
4096 memset(&flex_filter, 0, sizeof(struct e1000_flex_filter));
4097 flex_filter.filter_info.len = filter->len;
4098 flex_filter.filter_info.priority = filter->priority;
4099 memcpy(flex_filter.filter_info.dwords, filter->bytes, filter->len);
4100 memcpy(flex_filter.filter_info.mask, filter->mask,
4101 RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT);
4103 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
4104 &flex_filter.filter_info);
4106 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4110 wufc = E1000_READ_REG(hw, E1000_WUFC);
4111 wufc_en = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << it->index);
4113 if ((wufc & wufc_en) == wufc_en) {
4114 uint32_t reg_off = 0;
4115 if (it->index < E1000_MAX_FHFT)
4116 reg_off = E1000_FHFT(it->index);
4118 reg_off = E1000_FHFT_EXT(it->index - E1000_MAX_FHFT);
4120 queueing = E1000_READ_REG(hw,
4121 reg_off + E1000_FHFT_QUEUEING_OFFSET);
4122 filter->len = queueing & E1000_FHFT_QUEUEING_LEN;
4123 filter->priority = (queueing & E1000_FHFT_QUEUEING_PRIO) >>
4124 E1000_FHFT_QUEUEING_PRIO_SHIFT;
4125 filter->queue = (queueing & E1000_FHFT_QUEUEING_QUEUE) >>
4126 E1000_FHFT_QUEUEING_QUEUE_SHIFT;
4133 eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
4134 enum rte_filter_op filter_op,
4137 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4138 struct rte_eth_flex_filter *filter;
4141 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
4143 if (filter_op == RTE_ETH_FILTER_NOP)
4147 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
4152 filter = (struct rte_eth_flex_filter *)arg;
4153 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN
4154 || filter->len % sizeof(uint64_t) != 0) {
4155 PMD_DRV_LOG(ERR, "filter's length is out of range");
4158 if (filter->priority > E1000_MAX_FLEX_FILTER_PRI) {
4159 PMD_DRV_LOG(ERR, "filter's priority is out of range");
4163 switch (filter_op) {
4164 case RTE_ETH_FILTER_ADD:
4165 ret = eth_igb_add_del_flex_filter(dev, filter, TRUE);
4167 case RTE_ETH_FILTER_DELETE:
4168 ret = eth_igb_add_del_flex_filter(dev, filter, FALSE);
4170 case RTE_ETH_FILTER_GET:
4171 ret = eth_igb_get_flex_filter(dev, filter);
4174 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
4182 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
4184 ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
4185 struct e1000_5tuple_filter_info *filter_info)
4187 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
4189 if (filter->priority > E1000_2TUPLE_MAX_PRI)
4190 return -EINVAL; /* filter index is out of range. */
4191 if (filter->tcp_flags > TCP_FLAG_ALL)
4192 return -EINVAL; /* flags is invalid. */
4194 switch (filter->dst_ip_mask) {
4196 filter_info->dst_ip_mask = 0;
4197 filter_info->dst_ip = filter->dst_ip;
4200 filter_info->dst_ip_mask = 1;
4203 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
4207 switch (filter->src_ip_mask) {
4209 filter_info->src_ip_mask = 0;
4210 filter_info->src_ip = filter->src_ip;
4213 filter_info->src_ip_mask = 1;
4216 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
4220 switch (filter->dst_port_mask) {
4222 filter_info->dst_port_mask = 0;
4223 filter_info->dst_port = filter->dst_port;
4226 filter_info->dst_port_mask = 1;
4229 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
4233 switch (filter->src_port_mask) {
4235 filter_info->src_port_mask = 0;
4236 filter_info->src_port = filter->src_port;
4239 filter_info->src_port_mask = 1;
4242 PMD_DRV_LOG(ERR, "invalid src_port mask.");
4246 switch (filter->proto_mask) {
4248 filter_info->proto_mask = 0;
4249 filter_info->proto = filter->proto;
4252 filter_info->proto_mask = 1;
4255 PMD_DRV_LOG(ERR, "invalid protocol mask.");
4259 filter_info->priority = (uint8_t)filter->priority;
4260 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
4261 filter_info->tcp_flags = filter->tcp_flags;
4263 filter_info->tcp_flags = 0;
4268 static inline struct e1000_5tuple_filter *
4269 igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
4270 struct e1000_5tuple_filter_info *key)
4272 struct e1000_5tuple_filter *it;
4274 TAILQ_FOREACH(it, filter_list, entries) {
4275 if (memcmp(key, &it->filter_info,
4276 sizeof(struct e1000_5tuple_filter_info)) == 0) {
4283 /* inject a igb 5-tuple filter to HW */
4285 igb_inject_5tuple_filter_82576(struct rte_eth_dev *dev,
4286 struct e1000_5tuple_filter *filter)
4288 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4289 uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
4290 uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
4294 ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
4295 if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
4296 ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
4297 if (filter->filter_info.dst_ip_mask == 0)
4298 ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
4299 if (filter->filter_info.src_port_mask == 0)
4300 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
4301 if (filter->filter_info.proto_mask == 0)
4302 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
4303 ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
4304 E1000_FTQF_QUEUE_MASK;
4305 ftqf |= E1000_FTQF_QUEUE_ENABLE;
4306 E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
4307 E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
4308 E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
4310 spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
4311 E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
4313 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
4314 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
4315 imir |= E1000_IMIR_PORT_BP;
4317 imir &= ~E1000_IMIR_PORT_BP;
4318 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
4320 /* tcp flags bits setting. */
4321 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
4322 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
4323 imir_ext |= E1000_IMIREXT_CTRL_URG;
4324 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
4325 imir_ext |= E1000_IMIREXT_CTRL_ACK;
4326 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
4327 imir_ext |= E1000_IMIREXT_CTRL_PSH;
4328 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
4329 imir_ext |= E1000_IMIREXT_CTRL_RST;
4330 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
4331 imir_ext |= E1000_IMIREXT_CTRL_SYN;
4332 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
4333 imir_ext |= E1000_IMIREXT_CTRL_FIN;
4335 imir_ext |= E1000_IMIREXT_CTRL_BP;
4337 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
4338 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
4342 * igb_add_5tuple_filter_82576 - add a 5tuple filter
4345 * dev: Pointer to struct rte_eth_dev.
4346 * ntuple_filter: ponter to the filter that will be added.
4349 * - On success, zero.
4350 * - On failure, a negative value.
4353 igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
4354 struct rte_eth_ntuple_filter *ntuple_filter)
4356 struct e1000_filter_info *filter_info =
4357 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4358 struct e1000_5tuple_filter *filter;
4362 filter = rte_zmalloc("e1000_5tuple_filter",
4363 sizeof(struct e1000_5tuple_filter), 0);
4367 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4368 &filter->filter_info);
4374 if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4375 &filter->filter_info) != NULL) {
4376 PMD_DRV_LOG(ERR, "filter exists.");
4380 filter->queue = ntuple_filter->queue;
4383 * look for an unused 5tuple filter index,
4384 * and insert the filter to list.
4386 for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
4387 if (!(filter_info->fivetuple_mask & (1 << i))) {
4388 filter_info->fivetuple_mask |= 1 << i;
4390 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
4396 if (i >= E1000_MAX_FTQF_FILTERS) {
4397 PMD_DRV_LOG(ERR, "5tuple filters are full.");
4402 igb_inject_5tuple_filter_82576(dev, filter);
4407 igb_delete_5tuple_filter_82576(struct rte_eth_dev *dev,
4408 struct e1000_5tuple_filter *filter)
4410 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4411 struct e1000_filter_info *filter_info =
4412 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4414 filter_info->fivetuple_mask &= ~(1 << filter->index);
4415 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
4418 E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
4419 E1000_FTQF_VF_BP | E1000_FTQF_MASK);
4420 E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
4421 E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
4422 E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
4423 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
4424 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
4429 * igb_remove_5tuple_filter_82576 - remove a 5tuple filter
4432 * dev: Pointer to struct rte_eth_dev.
4433 * ntuple_filter: ponter to the filter that will be removed.
4436 * - On success, zero.
4437 * - On failure, a negative value.
4440 igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
4441 struct rte_eth_ntuple_filter *ntuple_filter)
4443 struct e1000_filter_info *filter_info =
4444 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4445 struct e1000_5tuple_filter_info filter_5tuple;
4446 struct e1000_5tuple_filter *filter;
4449 memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
4450 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4455 filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4457 if (filter == NULL) {
4458 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4462 igb_delete_5tuple_filter_82576(dev, filter);
4468 eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
4471 struct e1000_hw *hw;
4472 struct rte_eth_dev_info dev_info;
4473 uint32_t frame_size = mtu + E1000_ETH_OVERHEAD;
4475 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4477 #ifdef RTE_LIBRTE_82571_SUPPORT
4478 /* XXX: not bigger than max_rx_pktlen */
4479 if (hw->mac.type == e1000_82571)
4482 eth_igb_infos_get(dev, &dev_info);
4484 /* check that mtu is within the allowed range */
4485 if ((mtu < ETHER_MIN_MTU) ||
4486 (frame_size > dev_info.max_rx_pktlen))
4489 /* refuse mtu that requires the support of scattered packets when this
4490 * feature has not been enabled before. */
4491 if (!dev->data->scattered_rx &&
4492 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)
4495 rctl = E1000_READ_REG(hw, E1000_RCTL);
4497 /* switch to jumbo mode if needed */
4498 if (frame_size > ETHER_MAX_LEN) {
4499 dev->data->dev_conf.rxmode.offloads |=
4500 DEV_RX_OFFLOAD_JUMBO_FRAME;
4501 rctl |= E1000_RCTL_LPE;
4503 dev->data->dev_conf.rxmode.offloads &=
4504 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
4505 rctl &= ~E1000_RCTL_LPE;
4507 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
4509 /* update max frame size */
4510 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
4512 E1000_WRITE_REG(hw, E1000_RLPML,
4513 dev->data->dev_conf.rxmode.max_rx_pkt_len);
4519 * igb_add_del_ntuple_filter - add or delete a ntuple filter
4522 * dev: Pointer to struct rte_eth_dev.
4523 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4524 * add: if true, add filter, if false, remove filter
4527 * - On success, zero.
4528 * - On failure, a negative value.
4531 igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
4532 struct rte_eth_ntuple_filter *ntuple_filter,
4535 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4538 switch (ntuple_filter->flags) {
4539 case RTE_5TUPLE_FLAGS:
4540 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4541 if (hw->mac.type != e1000_82576)
4544 ret = igb_add_5tuple_filter_82576(dev,
4547 ret = igb_remove_5tuple_filter_82576(dev,
4550 case RTE_2TUPLE_FLAGS:
4551 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4552 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350 &&
4553 hw->mac.type != e1000_i210 &&
4554 hw->mac.type != e1000_i211)
4557 ret = igb_add_2tuple_filter(dev, ntuple_filter);
4559 ret = igb_remove_2tuple_filter(dev, ntuple_filter);
4570 * igb_get_ntuple_filter - get a ntuple filter
4573 * dev: Pointer to struct rte_eth_dev.
4574 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4577 * - On success, zero.
4578 * - On failure, a negative value.
4581 igb_get_ntuple_filter(struct rte_eth_dev *dev,
4582 struct rte_eth_ntuple_filter *ntuple_filter)
4584 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4585 struct e1000_filter_info *filter_info =
4586 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4587 struct e1000_5tuple_filter_info filter_5tuple;
4588 struct e1000_2tuple_filter_info filter_2tuple;
4589 struct e1000_5tuple_filter *p_5tuple_filter;
4590 struct e1000_2tuple_filter *p_2tuple_filter;
4593 switch (ntuple_filter->flags) {
4594 case RTE_5TUPLE_FLAGS:
4595 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4596 if (hw->mac.type != e1000_82576)
4598 memset(&filter_5tuple,
4600 sizeof(struct e1000_5tuple_filter_info));
4601 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4605 p_5tuple_filter = igb_5tuple_filter_lookup_82576(
4606 &filter_info->fivetuple_list,
4608 if (p_5tuple_filter == NULL) {
4609 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4612 ntuple_filter->queue = p_5tuple_filter->queue;
4614 case RTE_2TUPLE_FLAGS:
4615 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4616 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
4618 memset(&filter_2tuple,
4620 sizeof(struct e1000_2tuple_filter_info));
4621 ret = ntuple_filter_to_2tuple(ntuple_filter, &filter_2tuple);
4624 p_2tuple_filter = igb_2tuple_filter_lookup(
4625 &filter_info->twotuple_list,
4627 if (p_2tuple_filter == NULL) {
4628 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4631 ntuple_filter->queue = p_2tuple_filter->queue;
4642 * igb_ntuple_filter_handle - Handle operations for ntuple filter.
4643 * @dev: pointer to rte_eth_dev structure
4644 * @filter_op:operation will be taken.
4645 * @arg: a pointer to specific structure corresponding to the filter_op
4648 igb_ntuple_filter_handle(struct rte_eth_dev *dev,
4649 enum rte_filter_op filter_op,
4652 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4655 MAC_TYPE_FILTER_SUP(hw->mac.type);
4657 if (filter_op == RTE_ETH_FILTER_NOP)
4661 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4666 switch (filter_op) {
4667 case RTE_ETH_FILTER_ADD:
4668 ret = igb_add_del_ntuple_filter(dev,
4669 (struct rte_eth_ntuple_filter *)arg,
4672 case RTE_ETH_FILTER_DELETE:
4673 ret = igb_add_del_ntuple_filter(dev,
4674 (struct rte_eth_ntuple_filter *)arg,
4677 case RTE_ETH_FILTER_GET:
4678 ret = igb_get_ntuple_filter(dev,
4679 (struct rte_eth_ntuple_filter *)arg);
4682 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4690 igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
4695 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4696 if (filter_info->ethertype_filters[i].ethertype == ethertype &&
4697 (filter_info->ethertype_mask & (1 << i)))
4704 igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
4705 uint16_t ethertype, uint32_t etqf)
4709 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4710 if (!(filter_info->ethertype_mask & (1 << i))) {
4711 filter_info->ethertype_mask |= 1 << i;
4712 filter_info->ethertype_filters[i].ethertype = ethertype;
4713 filter_info->ethertype_filters[i].etqf = etqf;
4721 igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
4724 if (idx >= E1000_MAX_ETQF_FILTERS)
4726 filter_info->ethertype_mask &= ~(1 << idx);
4727 filter_info->ethertype_filters[idx].ethertype = 0;
4728 filter_info->ethertype_filters[idx].etqf = 0;
4734 igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
4735 struct rte_eth_ethertype_filter *filter,
4738 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4739 struct e1000_filter_info *filter_info =
4740 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4744 if (filter->ether_type == ETHER_TYPE_IPv4 ||
4745 filter->ether_type == ETHER_TYPE_IPv6) {
4746 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
4747 " ethertype filter.", filter->ether_type);
4751 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
4752 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
4755 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
4756 PMD_DRV_LOG(ERR, "drop option is unsupported.");
4760 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4761 if (ret >= 0 && add) {
4762 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
4763 filter->ether_type);
4766 if (ret < 0 && !add) {
4767 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4768 filter->ether_type);
4773 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
4774 etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
4775 etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
4776 ret = igb_ethertype_filter_insert(filter_info,
4777 filter->ether_type, etqf);
4779 PMD_DRV_LOG(ERR, "ethertype filters are full.");
4783 ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
4787 E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
4788 E1000_WRITE_FLUSH(hw);
4794 igb_get_ethertype_filter(struct rte_eth_dev *dev,
4795 struct rte_eth_ethertype_filter *filter)
4797 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4798 struct e1000_filter_info *filter_info =
4799 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4803 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4805 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4806 filter->ether_type);
4810 etqf = E1000_READ_REG(hw, E1000_ETQF(ret));
4811 if (etqf & E1000_ETQF_FILTER_ENABLE) {
4812 filter->ether_type = etqf & E1000_ETQF_ETHERTYPE;
4814 filter->queue = (etqf & E1000_ETQF_QUEUE) >>
4815 E1000_ETQF_QUEUE_SHIFT;
4823 * igb_ethertype_filter_handle - Handle operations for ethertype filter.
4824 * @dev: pointer to rte_eth_dev structure
4825 * @filter_op:operation will be taken.
4826 * @arg: a pointer to specific structure corresponding to the filter_op
4829 igb_ethertype_filter_handle(struct rte_eth_dev *dev,
4830 enum rte_filter_op filter_op,
4833 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4836 MAC_TYPE_FILTER_SUP(hw->mac.type);
4838 if (filter_op == RTE_ETH_FILTER_NOP)
4842 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4847 switch (filter_op) {
4848 case RTE_ETH_FILTER_ADD:
4849 ret = igb_add_del_ethertype_filter(dev,
4850 (struct rte_eth_ethertype_filter *)arg,
4853 case RTE_ETH_FILTER_DELETE:
4854 ret = igb_add_del_ethertype_filter(dev,
4855 (struct rte_eth_ethertype_filter *)arg,
4858 case RTE_ETH_FILTER_GET:
4859 ret = igb_get_ethertype_filter(dev,
4860 (struct rte_eth_ethertype_filter *)arg);
4863 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4871 eth_igb_filter_ctrl(struct rte_eth_dev *dev,
4872 enum rte_filter_type filter_type,
4873 enum rte_filter_op filter_op,
4878 switch (filter_type) {
4879 case RTE_ETH_FILTER_NTUPLE:
4880 ret = igb_ntuple_filter_handle(dev, filter_op, arg);
4882 case RTE_ETH_FILTER_ETHERTYPE:
4883 ret = igb_ethertype_filter_handle(dev, filter_op, arg);
4885 case RTE_ETH_FILTER_SYN:
4886 ret = eth_igb_syn_filter_handle(dev, filter_op, arg);
4888 case RTE_ETH_FILTER_FLEXIBLE:
4889 ret = eth_igb_flex_filter_handle(dev, filter_op, arg);
4891 case RTE_ETH_FILTER_GENERIC:
4892 if (filter_op != RTE_ETH_FILTER_GET)
4894 *(const void **)arg = &igb_flow_ops;
4897 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
4906 eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
4907 struct ether_addr *mc_addr_set,
4908 uint32_t nb_mc_addr)
4910 struct e1000_hw *hw;
4912 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4913 e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
4918 igb_read_systime_cyclecounter(struct rte_eth_dev *dev)
4920 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4921 uint64_t systime_cycles;
4923 switch (hw->mac.type) {
4927 * Need to read System Time Residue Register to be able
4928 * to read the other two registers.
4930 E1000_READ_REG(hw, E1000_SYSTIMR);
4931 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
4932 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4933 systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4940 * Need to read System Time Residue Register to be able
4941 * to read the other two registers.
4943 E1000_READ_REG(hw, E1000_SYSTIMR);
4944 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4945 /* Only the 8 LSB are valid. */
4946 systime_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_SYSTIMH)
4950 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4951 systime_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4956 return systime_cycles;
4960 igb_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4962 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4963 uint64_t rx_tstamp_cycles;
4965 switch (hw->mac.type) {
4968 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4969 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4970 rx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4976 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4977 /* Only the 8 LSB are valid. */
4978 rx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_RXSTMPH)
4982 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4983 rx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4988 return rx_tstamp_cycles;
4992 igb_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4994 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4995 uint64_t tx_tstamp_cycles;
4997 switch (hw->mac.type) {
5000 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
5001 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
5002 tx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
5008 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
5009 /* Only the 8 LSB are valid. */
5010 tx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_TXSTMPH)
5014 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
5015 tx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
5020 return tx_tstamp_cycles;
5024 igb_start_timecounters(struct rte_eth_dev *dev)
5026 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5027 struct e1000_adapter *adapter =
5028 (struct e1000_adapter *)dev->data->dev_private;
5029 uint32_t incval = 1;
5031 uint64_t mask = E1000_CYCLECOUNTER_MASK;
5033 switch (hw->mac.type) {
5037 /* 32 LSB bits + 8 MSB bits = 40 bits */
5038 mask = (1ULL << 40) - 1;
5043 * Start incrementing the register
5044 * used to timestamp PTP packets.
5046 E1000_WRITE_REG(hw, E1000_TIMINCA, incval);
5049 incval = E1000_INCVALUE_82576;
5050 shift = IGB_82576_TSYNC_SHIFT;
5051 E1000_WRITE_REG(hw, E1000_TIMINCA,
5052 E1000_INCPERIOD_82576 | incval);
5059 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
5060 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
5061 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
5063 adapter->systime_tc.cc_mask = mask;
5064 adapter->systime_tc.cc_shift = shift;
5065 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
5067 adapter->rx_tstamp_tc.cc_mask = mask;
5068 adapter->rx_tstamp_tc.cc_shift = shift;
5069 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
5071 adapter->tx_tstamp_tc.cc_mask = mask;
5072 adapter->tx_tstamp_tc.cc_shift = shift;
5073 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
5077 igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
5079 struct e1000_adapter *adapter =
5080 (struct e1000_adapter *)dev->data->dev_private;
5082 adapter->systime_tc.nsec += delta;
5083 adapter->rx_tstamp_tc.nsec += delta;
5084 adapter->tx_tstamp_tc.nsec += delta;
5090 igb_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
5093 struct e1000_adapter *adapter =
5094 (struct e1000_adapter *)dev->data->dev_private;
5096 ns = rte_timespec_to_ns(ts);
5098 /* Set the timecounters to a new value. */
5099 adapter->systime_tc.nsec = ns;
5100 adapter->rx_tstamp_tc.nsec = ns;
5101 adapter->tx_tstamp_tc.nsec = ns;
5107 igb_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
5109 uint64_t ns, systime_cycles;
5110 struct e1000_adapter *adapter =
5111 (struct e1000_adapter *)dev->data->dev_private;
5113 systime_cycles = igb_read_systime_cyclecounter(dev);
5114 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
5115 *ts = rte_ns_to_timespec(ns);
5121 igb_timesync_enable(struct rte_eth_dev *dev)
5123 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5127 /* Stop the timesync system time. */
5128 E1000_WRITE_REG(hw, E1000_TIMINCA, 0x0);
5129 /* Reset the timesync system time value. */
5130 switch (hw->mac.type) {
5136 E1000_WRITE_REG(hw, E1000_SYSTIMR, 0x0);
5139 E1000_WRITE_REG(hw, E1000_SYSTIML, 0x0);
5140 E1000_WRITE_REG(hw, E1000_SYSTIMH, 0x0);
5143 /* Not supported. */
5147 /* Enable system time for it isn't on by default. */
5148 tsauxc = E1000_READ_REG(hw, E1000_TSAUXC);
5149 tsauxc &= ~E1000_TSAUXC_DISABLE_SYSTIME;
5150 E1000_WRITE_REG(hw, E1000_TSAUXC, tsauxc);
5152 igb_start_timecounters(dev);
5154 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
5155 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588),
5157 E1000_ETQF_FILTER_ENABLE |
5160 /* Enable timestamping of received PTP packets. */
5161 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5162 tsync_ctl |= E1000_TSYNCRXCTL_ENABLED;
5163 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
5165 /* Enable Timestamping of transmitted PTP packets. */
5166 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5167 tsync_ctl |= E1000_TSYNCTXCTL_ENABLED;
5168 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
5174 igb_timesync_disable(struct rte_eth_dev *dev)
5176 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5179 /* Disable timestamping of transmitted PTP packets. */
5180 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5181 tsync_ctl &= ~E1000_TSYNCTXCTL_ENABLED;
5182 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
5184 /* Disable timestamping of received PTP packets. */
5185 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5186 tsync_ctl &= ~E1000_TSYNCRXCTL_ENABLED;
5187 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
5189 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
5190 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588), 0);
5192 /* Stop incrementating the System Time registers. */
5193 E1000_WRITE_REG(hw, E1000_TIMINCA, 0);
5199 igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
5200 struct timespec *timestamp,
5201 uint32_t flags __rte_unused)
5203 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5204 struct e1000_adapter *adapter =
5205 (struct e1000_adapter *)dev->data->dev_private;
5206 uint32_t tsync_rxctl;
5207 uint64_t rx_tstamp_cycles;
5210 tsync_rxctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5211 if ((tsync_rxctl & E1000_TSYNCRXCTL_VALID) == 0)
5214 rx_tstamp_cycles = igb_read_rx_tstamp_cyclecounter(dev);
5215 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
5216 *timestamp = rte_ns_to_timespec(ns);
5222 igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
5223 struct timespec *timestamp)
5225 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5226 struct e1000_adapter *adapter =
5227 (struct e1000_adapter *)dev->data->dev_private;
5228 uint32_t tsync_txctl;
5229 uint64_t tx_tstamp_cycles;
5232 tsync_txctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5233 if ((tsync_txctl & E1000_TSYNCTXCTL_VALID) == 0)
5236 tx_tstamp_cycles = igb_read_tx_tstamp_cyclecounter(dev);
5237 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
5238 *timestamp = rte_ns_to_timespec(ns);
5244 eth_igb_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5248 const struct reg_info *reg_group;
5250 while ((reg_group = igb_regs[g_ind++]))
5251 count += igb_reg_group_count(reg_group);
5257 igbvf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5261 const struct reg_info *reg_group;
5263 while ((reg_group = igbvf_regs[g_ind++]))
5264 count += igb_reg_group_count(reg_group);
5270 eth_igb_get_regs(struct rte_eth_dev *dev,
5271 struct rte_dev_reg_info *regs)
5273 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5274 uint32_t *data = regs->data;
5277 const struct reg_info *reg_group;
5280 regs->length = eth_igb_get_reg_length(dev);
5281 regs->width = sizeof(uint32_t);
5285 /* Support only full register dump */
5286 if ((regs->length == 0) ||
5287 (regs->length == (uint32_t)eth_igb_get_reg_length(dev))) {
5288 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5290 while ((reg_group = igb_regs[g_ind++]))
5291 count += igb_read_regs_group(dev, &data[count],
5300 igbvf_get_regs(struct rte_eth_dev *dev,
5301 struct rte_dev_reg_info *regs)
5303 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5304 uint32_t *data = regs->data;
5307 const struct reg_info *reg_group;
5310 regs->length = igbvf_get_reg_length(dev);
5311 regs->width = sizeof(uint32_t);
5315 /* Support only full register dump */
5316 if ((regs->length == 0) ||
5317 (regs->length == (uint32_t)igbvf_get_reg_length(dev))) {
5318 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5320 while ((reg_group = igbvf_regs[g_ind++]))
5321 count += igb_read_regs_group(dev, &data[count],
5330 eth_igb_get_eeprom_length(struct rte_eth_dev *dev)
5332 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5334 /* Return unit is byte count */
5335 return hw->nvm.word_size * 2;
5339 eth_igb_get_eeprom(struct rte_eth_dev *dev,
5340 struct rte_dev_eeprom_info *in_eeprom)
5342 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5343 struct e1000_nvm_info *nvm = &hw->nvm;
5344 uint16_t *data = in_eeprom->data;
5347 first = in_eeprom->offset >> 1;
5348 length = in_eeprom->length >> 1;
5349 if ((first >= hw->nvm.word_size) ||
5350 ((first + length) >= hw->nvm.word_size))
5353 in_eeprom->magic = hw->vendor_id |
5354 ((uint32_t)hw->device_id << 16);
5356 if ((nvm->ops.read) == NULL)
5359 return nvm->ops.read(hw, first, length, data);
5363 eth_igb_set_eeprom(struct rte_eth_dev *dev,
5364 struct rte_dev_eeprom_info *in_eeprom)
5366 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5367 struct e1000_nvm_info *nvm = &hw->nvm;
5368 uint16_t *data = in_eeprom->data;
5371 first = in_eeprom->offset >> 1;
5372 length = in_eeprom->length >> 1;
5373 if ((first >= hw->nvm.word_size) ||
5374 ((first + length) >= hw->nvm.word_size))
5377 in_eeprom->magic = (uint32_t)hw->vendor_id |
5378 ((uint32_t)hw->device_id << 16);
5380 if ((nvm->ops.write) == NULL)
5382 return nvm->ops.write(hw, first, length, data);
5386 eth_igb_get_module_info(struct rte_eth_dev *dev,
5387 struct rte_eth_dev_module_info *modinfo)
5389 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5391 uint32_t status = 0;
5392 uint16_t sff8472_rev, addr_mode;
5393 bool page_swap = false;
5395 if (hw->phy.media_type == e1000_media_type_copper ||
5396 hw->phy.media_type == e1000_media_type_unknown)
5399 /* Check whether we support SFF-8472 or not */
5400 status = e1000_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev);
5404 /* addressing mode is not supported */
5405 status = e1000_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode);
5409 /* addressing mode is not supported */
5410 if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) {
5412 "Address change required to access page 0xA2, "
5413 "but not supported. Please report the module "
5414 "type to the driver maintainers.\n");
5418 if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) {
5419 /* We have an SFP, but it does not support SFF-8472 */
5420 modinfo->type = RTE_ETH_MODULE_SFF_8079;
5421 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
5423 /* We have an SFP which supports a revision of SFF-8472 */
5424 modinfo->type = RTE_ETH_MODULE_SFF_8472;
5425 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
5432 eth_igb_get_module_eeprom(struct rte_eth_dev *dev,
5433 struct rte_dev_eeprom_info *info)
5435 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5437 uint32_t status = 0;
5438 uint16_t dataword[RTE_ETH_MODULE_SFF_8472_LEN / 2 + 1];
5439 u16 first_word, last_word;
5442 if (info->length == 0)
5445 first_word = info->offset >> 1;
5446 last_word = (info->offset + info->length - 1) >> 1;
5448 /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
5449 for (i = 0; i < last_word - first_word + 1; i++) {
5450 status = e1000_read_phy_reg_i2c(hw, (first_word + i) * 2,
5453 /* Error occurred while reading module */
5457 dataword[i] = rte_be_to_cpu_16(dataword[i]);
5460 memcpy(info->data, (u8 *)dataword + (info->offset & 1), info->length);
5466 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
5468 struct e1000_hw *hw =
5469 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5470 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5471 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5472 uint32_t vec = E1000_MISC_VEC_ID;
5474 if (rte_intr_allow_others(intr_handle))
5475 vec = E1000_RX_VEC_START;
5477 uint32_t mask = 1 << (queue_id + vec);
5479 E1000_WRITE_REG(hw, E1000_EIMC, mask);
5480 E1000_WRITE_FLUSH(hw);
5486 eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
5488 struct e1000_hw *hw =
5489 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5490 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5491 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5492 uint32_t vec = E1000_MISC_VEC_ID;
5494 if (rte_intr_allow_others(intr_handle))
5495 vec = E1000_RX_VEC_START;
5497 uint32_t mask = 1 << (queue_id + vec);
5500 regval = E1000_READ_REG(hw, E1000_EIMS);
5501 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
5502 E1000_WRITE_FLUSH(hw);
5504 rte_intr_enable(intr_handle);
5510 eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
5511 uint8_t index, uint8_t offset)
5513 uint32_t val = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
5516 val &= ~((uint32_t)0xFF << offset);
5518 /* write vector and valid bit */
5519 val |= (msix_vector | E1000_IVAR_VALID) << offset;
5521 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, val);
5525 eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
5526 uint8_t queue, uint8_t msix_vector)
5530 if (hw->mac.type == e1000_82575) {
5532 tmp = E1000_EICR_RX_QUEUE0 << queue;
5533 else if (direction == 1)
5534 tmp = E1000_EICR_TX_QUEUE0 << queue;
5535 E1000_WRITE_REG(hw, E1000_MSIXBM(msix_vector), tmp);
5536 } else if (hw->mac.type == e1000_82576) {
5537 if ((direction == 0) || (direction == 1))
5538 eth_igb_write_ivar(hw, msix_vector, queue & 0x7,
5539 ((queue & 0x8) << 1) +
5541 } else if ((hw->mac.type == e1000_82580) ||
5542 (hw->mac.type == e1000_i350) ||
5543 (hw->mac.type == e1000_i354) ||
5544 (hw->mac.type == e1000_i210) ||
5545 (hw->mac.type == e1000_i211)) {
5546 if ((direction == 0) || (direction == 1))
5547 eth_igb_write_ivar(hw, msix_vector,
5549 ((queue & 0x1) << 4) +
5554 /* Sets up the hardware to generate MSI-X interrupts properly
5556 * board private structure
5559 eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
5562 uint32_t tmpval, regval, intr_mask;
5563 struct e1000_hw *hw =
5564 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5565 uint32_t vec = E1000_MISC_VEC_ID;
5566 uint32_t base = E1000_MISC_VEC_ID;
5567 uint32_t misc_shift = 0;
5568 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5569 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5571 /* won't configure msix register if no mapping is done
5572 * between intr vector and event fd
5574 if (!rte_intr_dp_is_en(intr_handle))
5577 if (rte_intr_allow_others(intr_handle)) {
5578 vec = base = E1000_RX_VEC_START;
5582 /* set interrupt vector for other causes */
5583 if (hw->mac.type == e1000_82575) {
5584 tmpval = E1000_READ_REG(hw, E1000_CTRL_EXT);
5585 /* enable MSI-X PBA support */
5586 tmpval |= E1000_CTRL_EXT_PBA_CLR;
5588 /* Auto-Mask interrupts upon ICR read */
5589 tmpval |= E1000_CTRL_EXT_EIAME;
5590 tmpval |= E1000_CTRL_EXT_IRCA;
5592 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmpval);
5594 /* enable msix_other interrupt */
5595 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), 0, E1000_EIMS_OTHER);
5596 regval = E1000_READ_REG(hw, E1000_EIAC);
5597 E1000_WRITE_REG(hw, E1000_EIAC, regval | E1000_EIMS_OTHER);
5598 regval = E1000_READ_REG(hw, E1000_EIAM);
5599 E1000_WRITE_REG(hw, E1000_EIMS, regval | E1000_EIMS_OTHER);
5600 } else if ((hw->mac.type == e1000_82576) ||
5601 (hw->mac.type == e1000_82580) ||
5602 (hw->mac.type == e1000_i350) ||
5603 (hw->mac.type == e1000_i354) ||
5604 (hw->mac.type == e1000_i210) ||
5605 (hw->mac.type == e1000_i211)) {
5606 /* turn on MSI-X capability first */
5607 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
5608 E1000_GPIE_PBA | E1000_GPIE_EIAME |
5610 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
5613 if (dev->data->dev_conf.intr_conf.lsc != 0)
5614 intr_mask |= (1 << IGB_MSIX_OTHER_INTR_VEC);
5616 regval = E1000_READ_REG(hw, E1000_EIAC);
5617 E1000_WRITE_REG(hw, E1000_EIAC, regval | intr_mask);
5619 /* enable msix_other interrupt */
5620 regval = E1000_READ_REG(hw, E1000_EIMS);
5621 E1000_WRITE_REG(hw, E1000_EIMS, regval | intr_mask);
5622 tmpval = (IGB_MSIX_OTHER_INTR_VEC | E1000_IVAR_VALID) << 8;
5623 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmpval);
5626 /* use EIAM to auto-mask when MSI-X interrupt
5627 * is asserted, this saves a register write for every interrupt
5629 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
5632 if (dev->data->dev_conf.intr_conf.lsc != 0)
5633 intr_mask |= (1 << IGB_MSIX_OTHER_INTR_VEC);
5635 regval = E1000_READ_REG(hw, E1000_EIAM);
5636 E1000_WRITE_REG(hw, E1000_EIAM, regval | intr_mask);
5638 for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
5639 eth_igb_assign_msix_vector(hw, 0, queue_id, vec);
5640 intr_handle->intr_vec[queue_id] = vec;
5641 if (vec < base + intr_handle->nb_efd - 1)
5645 E1000_WRITE_FLUSH(hw);
5648 /* restore n-tuple filter */
5650 igb_ntuple_filter_restore(struct rte_eth_dev *dev)
5652 struct e1000_filter_info *filter_info =
5653 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5654 struct e1000_5tuple_filter *p_5tuple;
5655 struct e1000_2tuple_filter *p_2tuple;
5657 TAILQ_FOREACH(p_5tuple, &filter_info->fivetuple_list, entries) {
5658 igb_inject_5tuple_filter_82576(dev, p_5tuple);
5661 TAILQ_FOREACH(p_2tuple, &filter_info->twotuple_list, entries) {
5662 igb_inject_2uple_filter(dev, p_2tuple);
5666 /* restore SYN filter */
5668 igb_syn_filter_restore(struct rte_eth_dev *dev)
5670 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5671 struct e1000_filter_info *filter_info =
5672 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5675 synqf = filter_info->syn_info;
5677 if (synqf & E1000_SYN_FILTER_ENABLE) {
5678 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
5679 E1000_WRITE_FLUSH(hw);
5683 /* restore ethernet type filter */
5685 igb_ethertype_filter_restore(struct rte_eth_dev *dev)
5687 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5688 struct e1000_filter_info *filter_info =
5689 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5692 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
5693 if (filter_info->ethertype_mask & (1 << i)) {
5694 E1000_WRITE_REG(hw, E1000_ETQF(i),
5695 filter_info->ethertype_filters[i].etqf);
5696 E1000_WRITE_FLUSH(hw);
5701 /* restore flex byte filter */
5703 igb_flex_filter_restore(struct rte_eth_dev *dev)
5705 struct e1000_filter_info *filter_info =
5706 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5707 struct e1000_flex_filter *flex_filter;
5709 TAILQ_FOREACH(flex_filter, &filter_info->flex_list, entries) {
5710 igb_inject_flex_filter(dev, flex_filter);
5714 /* restore rss filter */
5716 igb_rss_filter_restore(struct rte_eth_dev *dev)
5718 struct e1000_filter_info *filter_info =
5719 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5721 if (filter_info->rss_info.conf.queue_num)
5722 igb_config_rss_filter(dev, &filter_info->rss_info, TRUE);
5725 /* restore all types filter */
5727 igb_filter_restore(struct rte_eth_dev *dev)
5729 igb_ntuple_filter_restore(dev);
5730 igb_ethertype_filter_restore(dev);
5731 igb_syn_filter_restore(dev);
5732 igb_flex_filter_restore(dev);
5733 igb_rss_filter_restore(dev);
5738 RTE_PMD_REGISTER_PCI(net_e1000_igb, rte_igb_pmd);
5739 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb, pci_id_igb_map);
5740 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb, "* igb_uio | uio_pci_generic | vfio-pci");
5741 RTE_PMD_REGISTER_PCI(net_e1000_igb_vf, rte_igbvf_pmd);
5742 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb_vf, pci_id_igbvf_map);
5743 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb_vf, "* igb_uio | vfio-pci");
5745 /* see e1000_logs.c */
5746 RTE_INIT(e1000_init_log)
5748 e1000_igb_init_log();