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 static int eth_igb_configure(struct rte_eth_dev *dev);
72 static int eth_igb_start(struct rte_eth_dev *dev);
73 static void eth_igb_stop(struct rte_eth_dev *dev);
74 static int eth_igb_dev_set_link_up(struct rte_eth_dev *dev);
75 static int eth_igb_dev_set_link_down(struct rte_eth_dev *dev);
76 static void eth_igb_close(struct rte_eth_dev *dev);
77 static void eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
78 static void eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
79 static void eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
80 static void eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
81 static int eth_igb_link_update(struct rte_eth_dev *dev,
82 int wait_to_complete);
83 static int eth_igb_stats_get(struct rte_eth_dev *dev,
84 struct rte_eth_stats *rte_stats);
85 static int eth_igb_xstats_get(struct rte_eth_dev *dev,
86 struct rte_eth_xstat *xstats, unsigned n);
87 static int eth_igb_xstats_get_by_id(struct rte_eth_dev *dev,
89 uint64_t *values, unsigned int n);
90 static int eth_igb_xstats_get_names(struct rte_eth_dev *dev,
91 struct rte_eth_xstat_name *xstats_names,
93 static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
94 struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
96 static void eth_igb_stats_reset(struct rte_eth_dev *dev);
97 static void eth_igb_xstats_reset(struct rte_eth_dev *dev);
98 static int eth_igb_fw_version_get(struct rte_eth_dev *dev,
99 char *fw_version, size_t fw_size);
100 static void eth_igb_infos_get(struct rte_eth_dev *dev,
101 struct rte_eth_dev_info *dev_info);
102 static const uint32_t *eth_igb_supported_ptypes_get(struct rte_eth_dev *dev);
103 static void eth_igbvf_infos_get(struct rte_eth_dev *dev,
104 struct rte_eth_dev_info *dev_info);
105 static int eth_igb_flow_ctrl_get(struct rte_eth_dev *dev,
106 struct rte_eth_fc_conf *fc_conf);
107 static int eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
108 struct rte_eth_fc_conf *fc_conf);
109 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on);
110 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
111 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
112 static int eth_igb_interrupt_action(struct rte_eth_dev *dev,
113 struct rte_intr_handle *handle);
114 static void eth_igb_interrupt_handler(void *param);
115 static int igb_hardware_init(struct e1000_hw *hw);
116 static void igb_hw_control_acquire(struct e1000_hw *hw);
117 static void igb_hw_control_release(struct e1000_hw *hw);
118 static void igb_init_manageability(struct e1000_hw *hw);
119 static void igb_release_manageability(struct e1000_hw *hw);
121 static int eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
123 static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
124 uint16_t vlan_id, int on);
125 static int eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
126 enum rte_vlan_type vlan_type,
128 static int eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
130 static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
131 static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
132 static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
133 static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
134 static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
135 static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
137 static int eth_igb_led_on(struct rte_eth_dev *dev);
138 static int eth_igb_led_off(struct rte_eth_dev *dev);
140 static void igb_intr_disable(struct e1000_hw *hw);
141 static int igb_get_rx_buffer_size(struct e1000_hw *hw);
142 static int eth_igb_rar_set(struct rte_eth_dev *dev,
143 struct ether_addr *mac_addr,
144 uint32_t index, uint32_t pool);
145 static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
146 static int eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
147 struct ether_addr *addr);
149 static void igbvf_intr_disable(struct e1000_hw *hw);
150 static int igbvf_dev_configure(struct rte_eth_dev *dev);
151 static int igbvf_dev_start(struct rte_eth_dev *dev);
152 static void igbvf_dev_stop(struct rte_eth_dev *dev);
153 static void igbvf_dev_close(struct rte_eth_dev *dev);
154 static void igbvf_promiscuous_enable(struct rte_eth_dev *dev);
155 static void igbvf_promiscuous_disable(struct rte_eth_dev *dev);
156 static void igbvf_allmulticast_enable(struct rte_eth_dev *dev);
157 static void igbvf_allmulticast_disable(struct rte_eth_dev *dev);
158 static int eth_igbvf_link_update(struct e1000_hw *hw);
159 static int eth_igbvf_stats_get(struct rte_eth_dev *dev,
160 struct rte_eth_stats *rte_stats);
161 static int eth_igbvf_xstats_get(struct rte_eth_dev *dev,
162 struct rte_eth_xstat *xstats, unsigned n);
163 static int eth_igbvf_xstats_get_names(struct rte_eth_dev *dev,
164 struct rte_eth_xstat_name *xstats_names,
166 static void eth_igbvf_stats_reset(struct rte_eth_dev *dev);
167 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
168 uint16_t vlan_id, int on);
169 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
170 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
171 static int igbvf_default_mac_addr_set(struct rte_eth_dev *dev,
172 struct ether_addr *addr);
173 static int igbvf_get_reg_length(struct rte_eth_dev *dev);
174 static int igbvf_get_regs(struct rte_eth_dev *dev,
175 struct rte_dev_reg_info *regs);
177 static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
178 struct rte_eth_rss_reta_entry64 *reta_conf,
180 static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
181 struct rte_eth_rss_reta_entry64 *reta_conf,
184 static int eth_igb_syn_filter_get(struct rte_eth_dev *dev,
185 struct rte_eth_syn_filter *filter);
186 static int eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
187 enum rte_filter_op filter_op,
189 static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
190 struct rte_eth_ntuple_filter *ntuple_filter);
191 static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
192 struct rte_eth_ntuple_filter *ntuple_filter);
193 static int eth_igb_get_flex_filter(struct rte_eth_dev *dev,
194 struct rte_eth_flex_filter *filter);
195 static int eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
196 enum rte_filter_op filter_op,
198 static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
199 struct rte_eth_ntuple_filter *ntuple_filter);
200 static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
201 struct rte_eth_ntuple_filter *ntuple_filter);
202 static int igb_get_ntuple_filter(struct rte_eth_dev *dev,
203 struct rte_eth_ntuple_filter *filter);
204 static int igb_ntuple_filter_handle(struct rte_eth_dev *dev,
205 enum rte_filter_op filter_op,
207 static int igb_ethertype_filter_handle(struct rte_eth_dev *dev,
208 enum rte_filter_op filter_op,
210 static int igb_get_ethertype_filter(struct rte_eth_dev *dev,
211 struct rte_eth_ethertype_filter *filter);
212 static int eth_igb_filter_ctrl(struct rte_eth_dev *dev,
213 enum rte_filter_type filter_type,
214 enum rte_filter_op filter_op,
216 static int eth_igb_get_reg_length(struct rte_eth_dev *dev);
217 static int eth_igb_get_regs(struct rte_eth_dev *dev,
218 struct rte_dev_reg_info *regs);
219 static int eth_igb_get_eeprom_length(struct rte_eth_dev *dev);
220 static int eth_igb_get_eeprom(struct rte_eth_dev *dev,
221 struct rte_dev_eeprom_info *eeprom);
222 static int eth_igb_set_eeprom(struct rte_eth_dev *dev,
223 struct rte_dev_eeprom_info *eeprom);
224 static int eth_igb_get_module_info(struct rte_eth_dev *dev,
225 struct rte_eth_dev_module_info *modinfo);
226 static int eth_igb_get_module_eeprom(struct rte_eth_dev *dev,
227 struct rte_dev_eeprom_info *info);
228 static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
229 struct ether_addr *mc_addr_set,
230 uint32_t nb_mc_addr);
231 static int igb_timesync_enable(struct rte_eth_dev *dev);
232 static int igb_timesync_disable(struct rte_eth_dev *dev);
233 static int igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
234 struct timespec *timestamp,
236 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
237 struct timespec *timestamp);
238 static int igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
239 static int igb_timesync_read_time(struct rte_eth_dev *dev,
240 struct timespec *timestamp);
241 static int igb_timesync_write_time(struct rte_eth_dev *dev,
242 const struct timespec *timestamp);
243 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
245 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
247 static void eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
248 uint8_t queue, uint8_t msix_vector);
249 static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
250 uint8_t index, uint8_t offset);
251 static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
252 static void eth_igbvf_interrupt_handler(void *param);
253 static void igbvf_mbx_process(struct rte_eth_dev *dev);
254 static int igb_filter_restore(struct rte_eth_dev *dev);
257 * Define VF Stats MACRO for Non "cleared on read" register
259 #define UPDATE_VF_STAT(reg, last, cur) \
261 u32 latest = E1000_READ_REG(hw, reg); \
262 cur += (latest - last) & UINT_MAX; \
266 #define IGB_FC_PAUSE_TIME 0x0680
267 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
268 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
270 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
272 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
275 * The set of PCI devices this driver supports
277 static const struct rte_pci_id pci_id_igb_map[] = {
278 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576) },
279 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_FIBER) },
280 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES) },
281 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER) },
282 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER_ET2) },
283 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS) },
284 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS_SERDES) },
285 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES_QUAD) },
287 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_COPPER) },
288 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_FIBER_SERDES) },
289 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575GB_QUAD_COPPER) },
291 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER) },
292 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_FIBER) },
293 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SERDES) },
294 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SGMII) },
295 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER_DUAL) },
296 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_QUAD_FIBER) },
298 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_COPPER) },
299 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_FIBER) },
300 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SERDES) },
301 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SGMII) },
302 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_DA4) },
303 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER) },
304 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_OEM1) },
305 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_IT) },
306 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_FIBER) },
307 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES) },
308 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SGMII) },
309 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_FLASHLESS) },
310 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES_FLASHLESS) },
311 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I211_COPPER) },
312 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
313 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_SGMII) },
314 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
315 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SGMII) },
316 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SERDES) },
317 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_BACKPLANE) },
318 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SFP) },
319 { .vendor_id = 0, /* sentinel */ },
323 * The set of PCI devices this driver supports (for 82576&I350 VF)
325 static const struct rte_pci_id pci_id_igbvf_map[] = {
326 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF) },
327 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF_HV) },
328 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF) },
329 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF_HV) },
330 { .vendor_id = 0, /* sentinel */ },
333 static const struct rte_eth_desc_lim rx_desc_lim = {
334 .nb_max = E1000_MAX_RING_DESC,
335 .nb_min = E1000_MIN_RING_DESC,
336 .nb_align = IGB_RXD_ALIGN,
339 static const struct rte_eth_desc_lim tx_desc_lim = {
340 .nb_max = E1000_MAX_RING_DESC,
341 .nb_min = E1000_MIN_RING_DESC,
342 .nb_align = IGB_RXD_ALIGN,
343 .nb_seg_max = IGB_TX_MAX_SEG,
344 .nb_mtu_seg_max = IGB_TX_MAX_MTU_SEG,
347 static const struct eth_dev_ops eth_igb_ops = {
348 .dev_configure = eth_igb_configure,
349 .dev_start = eth_igb_start,
350 .dev_stop = eth_igb_stop,
351 .dev_set_link_up = eth_igb_dev_set_link_up,
352 .dev_set_link_down = eth_igb_dev_set_link_down,
353 .dev_close = eth_igb_close,
354 .promiscuous_enable = eth_igb_promiscuous_enable,
355 .promiscuous_disable = eth_igb_promiscuous_disable,
356 .allmulticast_enable = eth_igb_allmulticast_enable,
357 .allmulticast_disable = eth_igb_allmulticast_disable,
358 .link_update = eth_igb_link_update,
359 .stats_get = eth_igb_stats_get,
360 .xstats_get = eth_igb_xstats_get,
361 .xstats_get_by_id = eth_igb_xstats_get_by_id,
362 .xstats_get_names_by_id = eth_igb_xstats_get_names_by_id,
363 .xstats_get_names = eth_igb_xstats_get_names,
364 .stats_reset = eth_igb_stats_reset,
365 .xstats_reset = eth_igb_xstats_reset,
366 .fw_version_get = eth_igb_fw_version_get,
367 .dev_infos_get = eth_igb_infos_get,
368 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
369 .mtu_set = eth_igb_mtu_set,
370 .vlan_filter_set = eth_igb_vlan_filter_set,
371 .vlan_tpid_set = eth_igb_vlan_tpid_set,
372 .vlan_offload_set = eth_igb_vlan_offload_set,
373 .rx_queue_setup = eth_igb_rx_queue_setup,
374 .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
375 .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
376 .rx_queue_release = eth_igb_rx_queue_release,
377 .rx_queue_count = eth_igb_rx_queue_count,
378 .rx_descriptor_done = eth_igb_rx_descriptor_done,
379 .rx_descriptor_status = eth_igb_rx_descriptor_status,
380 .tx_descriptor_status = eth_igb_tx_descriptor_status,
381 .tx_queue_setup = eth_igb_tx_queue_setup,
382 .tx_queue_release = eth_igb_tx_queue_release,
383 .tx_done_cleanup = eth_igb_tx_done_cleanup,
384 .dev_led_on = eth_igb_led_on,
385 .dev_led_off = eth_igb_led_off,
386 .flow_ctrl_get = eth_igb_flow_ctrl_get,
387 .flow_ctrl_set = eth_igb_flow_ctrl_set,
388 .mac_addr_add = eth_igb_rar_set,
389 .mac_addr_remove = eth_igb_rar_clear,
390 .mac_addr_set = eth_igb_default_mac_addr_set,
391 .reta_update = eth_igb_rss_reta_update,
392 .reta_query = eth_igb_rss_reta_query,
393 .rss_hash_update = eth_igb_rss_hash_update,
394 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
395 .filter_ctrl = eth_igb_filter_ctrl,
396 .set_mc_addr_list = eth_igb_set_mc_addr_list,
397 .rxq_info_get = igb_rxq_info_get,
398 .txq_info_get = igb_txq_info_get,
399 .timesync_enable = igb_timesync_enable,
400 .timesync_disable = igb_timesync_disable,
401 .timesync_read_rx_timestamp = igb_timesync_read_rx_timestamp,
402 .timesync_read_tx_timestamp = igb_timesync_read_tx_timestamp,
403 .get_reg = eth_igb_get_regs,
404 .get_eeprom_length = eth_igb_get_eeprom_length,
405 .get_eeprom = eth_igb_get_eeprom,
406 .set_eeprom = eth_igb_set_eeprom,
407 .get_module_info = eth_igb_get_module_info,
408 .get_module_eeprom = eth_igb_get_module_eeprom,
409 .timesync_adjust_time = igb_timesync_adjust_time,
410 .timesync_read_time = igb_timesync_read_time,
411 .timesync_write_time = igb_timesync_write_time,
415 * dev_ops for virtual function, bare necessities for basic vf
416 * operation have been implemented
418 static const struct eth_dev_ops igbvf_eth_dev_ops = {
419 .dev_configure = igbvf_dev_configure,
420 .dev_start = igbvf_dev_start,
421 .dev_stop = igbvf_dev_stop,
422 .dev_close = igbvf_dev_close,
423 .promiscuous_enable = igbvf_promiscuous_enable,
424 .promiscuous_disable = igbvf_promiscuous_disable,
425 .allmulticast_enable = igbvf_allmulticast_enable,
426 .allmulticast_disable = igbvf_allmulticast_disable,
427 .link_update = eth_igb_link_update,
428 .stats_get = eth_igbvf_stats_get,
429 .xstats_get = eth_igbvf_xstats_get,
430 .xstats_get_names = eth_igbvf_xstats_get_names,
431 .stats_reset = eth_igbvf_stats_reset,
432 .xstats_reset = eth_igbvf_stats_reset,
433 .vlan_filter_set = igbvf_vlan_filter_set,
434 .dev_infos_get = eth_igbvf_infos_get,
435 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
436 .rx_queue_setup = eth_igb_rx_queue_setup,
437 .rx_queue_release = eth_igb_rx_queue_release,
438 .rx_descriptor_done = eth_igb_rx_descriptor_done,
439 .rx_descriptor_status = eth_igb_rx_descriptor_status,
440 .tx_descriptor_status = eth_igb_tx_descriptor_status,
441 .tx_queue_setup = eth_igb_tx_queue_setup,
442 .tx_queue_release = eth_igb_tx_queue_release,
443 .set_mc_addr_list = eth_igb_set_mc_addr_list,
444 .rxq_info_get = igb_rxq_info_get,
445 .txq_info_get = igb_txq_info_get,
446 .mac_addr_set = igbvf_default_mac_addr_set,
447 .get_reg = igbvf_get_regs,
450 /* store statistics names and its offset in stats structure */
451 struct rte_igb_xstats_name_off {
452 char name[RTE_ETH_XSTATS_NAME_SIZE];
456 static const struct rte_igb_xstats_name_off rte_igb_stats_strings[] = {
457 {"rx_crc_errors", offsetof(struct e1000_hw_stats, crcerrs)},
458 {"rx_align_errors", offsetof(struct e1000_hw_stats, algnerrc)},
459 {"rx_symbol_errors", offsetof(struct e1000_hw_stats, symerrs)},
460 {"rx_missed_packets", offsetof(struct e1000_hw_stats, mpc)},
461 {"tx_single_collision_packets", offsetof(struct e1000_hw_stats, scc)},
462 {"tx_multiple_collision_packets", offsetof(struct e1000_hw_stats, mcc)},
463 {"tx_excessive_collision_packets", offsetof(struct e1000_hw_stats,
465 {"tx_late_collisions", offsetof(struct e1000_hw_stats, latecol)},
466 {"tx_total_collisions", offsetof(struct e1000_hw_stats, colc)},
467 {"tx_deferred_packets", offsetof(struct e1000_hw_stats, dc)},
468 {"tx_no_carrier_sense_packets", offsetof(struct e1000_hw_stats, tncrs)},
469 {"rx_carrier_ext_errors", offsetof(struct e1000_hw_stats, cexterr)},
470 {"rx_length_errors", offsetof(struct e1000_hw_stats, rlec)},
471 {"rx_xon_packets", offsetof(struct e1000_hw_stats, xonrxc)},
472 {"tx_xon_packets", offsetof(struct e1000_hw_stats, xontxc)},
473 {"rx_xoff_packets", offsetof(struct e1000_hw_stats, xoffrxc)},
474 {"tx_xoff_packets", offsetof(struct e1000_hw_stats, xofftxc)},
475 {"rx_flow_control_unsupported_packets", offsetof(struct e1000_hw_stats,
477 {"rx_size_64_packets", offsetof(struct e1000_hw_stats, prc64)},
478 {"rx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, prc127)},
479 {"rx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, prc255)},
480 {"rx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, prc511)},
481 {"rx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
483 {"rx_size_1024_to_max_packets", offsetof(struct e1000_hw_stats,
485 {"rx_broadcast_packets", offsetof(struct e1000_hw_stats, bprc)},
486 {"rx_multicast_packets", offsetof(struct e1000_hw_stats, mprc)},
487 {"rx_undersize_errors", offsetof(struct e1000_hw_stats, ruc)},
488 {"rx_fragment_errors", offsetof(struct e1000_hw_stats, rfc)},
489 {"rx_oversize_errors", offsetof(struct e1000_hw_stats, roc)},
490 {"rx_jabber_errors", offsetof(struct e1000_hw_stats, rjc)},
491 {"rx_management_packets", offsetof(struct e1000_hw_stats, mgprc)},
492 {"rx_management_dropped", offsetof(struct e1000_hw_stats, mgpdc)},
493 {"tx_management_packets", offsetof(struct e1000_hw_stats, mgptc)},
494 {"rx_total_packets", offsetof(struct e1000_hw_stats, tpr)},
495 {"tx_total_packets", offsetof(struct e1000_hw_stats, tpt)},
496 {"rx_total_bytes", offsetof(struct e1000_hw_stats, tor)},
497 {"tx_total_bytes", offsetof(struct e1000_hw_stats, tot)},
498 {"tx_size_64_packets", offsetof(struct e1000_hw_stats, ptc64)},
499 {"tx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, ptc127)},
500 {"tx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, ptc255)},
501 {"tx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, ptc511)},
502 {"tx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
504 {"tx_size_1023_to_max_packets", offsetof(struct e1000_hw_stats,
506 {"tx_multicast_packets", offsetof(struct e1000_hw_stats, mptc)},
507 {"tx_broadcast_packets", offsetof(struct e1000_hw_stats, bptc)},
508 {"tx_tso_packets", offsetof(struct e1000_hw_stats, tsctc)},
509 {"tx_tso_errors", offsetof(struct e1000_hw_stats, tsctfc)},
510 {"rx_sent_to_host_packets", offsetof(struct e1000_hw_stats, rpthc)},
511 {"tx_sent_by_host_packets", offsetof(struct e1000_hw_stats, hgptc)},
512 {"rx_code_violation_packets", offsetof(struct e1000_hw_stats, scvpc)},
514 {"interrupt_assert_count", offsetof(struct e1000_hw_stats, iac)},
517 #define IGB_NB_XSTATS (sizeof(rte_igb_stats_strings) / \
518 sizeof(rte_igb_stats_strings[0]))
520 static const struct rte_igb_xstats_name_off rte_igbvf_stats_strings[] = {
521 {"rx_multicast_packets", offsetof(struct e1000_vf_stats, mprc)},
522 {"rx_good_loopback_packets", offsetof(struct e1000_vf_stats, gprlbc)},
523 {"tx_good_loopback_packets", offsetof(struct e1000_vf_stats, gptlbc)},
524 {"rx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gorlbc)},
525 {"tx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gotlbc)},
528 #define IGBVF_NB_XSTATS (sizeof(rte_igbvf_stats_strings) / \
529 sizeof(rte_igbvf_stats_strings[0]))
533 igb_intr_enable(struct rte_eth_dev *dev)
535 struct e1000_interrupt *intr =
536 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
537 struct e1000_hw *hw =
538 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
540 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
541 E1000_WRITE_FLUSH(hw);
545 igb_intr_disable(struct e1000_hw *hw)
547 E1000_WRITE_REG(hw, E1000_IMC, ~0);
548 E1000_WRITE_FLUSH(hw);
552 igbvf_intr_enable(struct rte_eth_dev *dev)
554 struct e1000_hw *hw =
555 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
557 /* only for mailbox */
558 E1000_WRITE_REG(hw, E1000_EIAM, 1 << E1000_VTIVAR_MISC_MAILBOX);
559 E1000_WRITE_REG(hw, E1000_EIAC, 1 << E1000_VTIVAR_MISC_MAILBOX);
560 E1000_WRITE_REG(hw, E1000_EIMS, 1 << E1000_VTIVAR_MISC_MAILBOX);
561 E1000_WRITE_FLUSH(hw);
564 /* only for mailbox now. If RX/TX needed, should extend this function. */
566 igbvf_set_ivar_map(struct e1000_hw *hw, uint8_t msix_vector)
571 tmp |= (msix_vector & E1000_VTIVAR_MISC_INTR_MASK);
572 tmp |= E1000_VTIVAR_VALID;
573 E1000_WRITE_REG(hw, E1000_VTIVAR_MISC, tmp);
577 eth_igbvf_configure_msix_intr(struct rte_eth_dev *dev)
579 struct e1000_hw *hw =
580 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
582 /* Configure VF other cause ivar */
583 igbvf_set_ivar_map(hw, E1000_VTIVAR_MISC_MAILBOX);
586 static inline int32_t
587 igb_pf_reset_hw(struct e1000_hw *hw)
592 status = e1000_reset_hw(hw);
594 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
595 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
596 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
597 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
598 E1000_WRITE_FLUSH(hw);
604 igb_identify_hardware(struct rte_eth_dev *dev, struct rte_pci_device *pci_dev)
606 struct e1000_hw *hw =
607 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
610 hw->vendor_id = pci_dev->id.vendor_id;
611 hw->device_id = pci_dev->id.device_id;
612 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
613 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
615 e1000_set_mac_type(hw);
617 /* need to check if it is a vf device below */
621 igb_reset_swfw_lock(struct e1000_hw *hw)
626 * Do mac ops initialization manually here, since we will need
627 * some function pointers set by this call.
629 ret_val = e1000_init_mac_params(hw);
634 * SMBI lock should not fail in this early stage. If this is the case,
635 * it is due to an improper exit of the application.
636 * So force the release of the faulty lock.
638 if (e1000_get_hw_semaphore_generic(hw) < 0) {
639 PMD_DRV_LOG(DEBUG, "SMBI lock released");
641 e1000_put_hw_semaphore_generic(hw);
643 if (hw->mac.ops.acquire_swfw_sync != NULL) {
647 * Phy lock should not fail in this early stage. If this is the case,
648 * it is due to an improper exit of the application.
649 * So force the release of the faulty lock.
651 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
652 if (hw->bus.func > E1000_FUNC_1)
654 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
655 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
658 hw->mac.ops.release_swfw_sync(hw, mask);
661 * This one is more tricky since it is common to all ports; but
662 * swfw_sync retries last long enough (1s) to be almost sure that if
663 * lock can not be taken it is due to an improper lock of the
666 mask = E1000_SWFW_EEP_SM;
667 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
668 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
670 hw->mac.ops.release_swfw_sync(hw, mask);
673 return E1000_SUCCESS;
676 /* Remove all ntuple filters of the device */
677 static int igb_ntuple_filter_uninit(struct rte_eth_dev *eth_dev)
679 struct e1000_filter_info *filter_info =
680 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
681 struct e1000_5tuple_filter *p_5tuple;
682 struct e1000_2tuple_filter *p_2tuple;
684 while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list))) {
685 TAILQ_REMOVE(&filter_info->fivetuple_list,
689 filter_info->fivetuple_mask = 0;
690 while ((p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list))) {
691 TAILQ_REMOVE(&filter_info->twotuple_list,
695 filter_info->twotuple_mask = 0;
700 /* Remove all flex filters of the device */
701 static int igb_flex_filter_uninit(struct rte_eth_dev *eth_dev)
703 struct e1000_filter_info *filter_info =
704 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
705 struct e1000_flex_filter *p_flex;
707 while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
708 TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
711 filter_info->flex_mask = 0;
717 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
720 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
721 struct e1000_hw *hw =
722 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
723 struct e1000_vfta * shadow_vfta =
724 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
725 struct e1000_filter_info *filter_info =
726 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
727 struct e1000_adapter *adapter =
728 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
732 eth_dev->dev_ops = ð_igb_ops;
733 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
734 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
735 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
737 /* for secondary processes, we don't initialise any further as primary
738 * has already done this work. Only check we don't need a different
740 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
741 if (eth_dev->data->scattered_rx)
742 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
746 rte_eth_copy_pci_info(eth_dev, pci_dev);
748 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
750 igb_identify_hardware(eth_dev, pci_dev);
751 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
756 e1000_get_bus_info(hw);
758 /* Reset any pending lock */
759 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
764 /* Finish initialization */
765 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
771 hw->phy.autoneg_wait_to_complete = 0;
772 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
775 if (hw->phy.media_type == e1000_media_type_copper) {
776 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
777 hw->phy.disable_polarity_correction = 0;
778 hw->phy.ms_type = e1000_ms_hw_default;
782 * Start from a known state, this is important in reading the nvm
787 /* Make sure we have a good EEPROM before we read from it */
788 if (e1000_validate_nvm_checksum(hw) < 0) {
790 * Some PCI-E parts fail the first check due to
791 * the link being in sleep state, call it again,
792 * if it fails a second time its a real issue.
794 if (e1000_validate_nvm_checksum(hw) < 0) {
795 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
801 /* Read the permanent MAC address out of the EEPROM */
802 if (e1000_read_mac_addr(hw) != 0) {
803 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
808 /* Allocate memory for storing MAC addresses */
809 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
810 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
811 if (eth_dev->data->mac_addrs == NULL) {
812 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
813 "store MAC addresses",
814 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
819 /* Copy the permanent MAC address */
820 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
822 /* initialize the vfta */
823 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
825 /* Now initialize the hardware */
826 if (igb_hardware_init(hw) != 0) {
827 PMD_INIT_LOG(ERR, "Hardware initialization failed");
828 rte_free(eth_dev->data->mac_addrs);
829 eth_dev->data->mac_addrs = NULL;
833 hw->mac.get_link_status = 1;
834 adapter->stopped = 0;
836 /* Indicate SOL/IDER usage */
837 if (e1000_check_reset_block(hw) < 0) {
838 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
842 /* initialize PF if max_vfs not zero */
843 igb_pf_host_init(eth_dev);
845 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
846 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
847 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
848 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
849 E1000_WRITE_FLUSH(hw);
851 PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
852 eth_dev->data->port_id, pci_dev->id.vendor_id,
853 pci_dev->id.device_id);
855 rte_intr_callback_register(&pci_dev->intr_handle,
856 eth_igb_interrupt_handler,
859 /* enable uio/vfio intr/eventfd mapping */
860 rte_intr_enable(&pci_dev->intr_handle);
862 /* enable support intr */
863 igb_intr_enable(eth_dev);
865 /* initialize filter info */
866 memset(filter_info, 0,
867 sizeof(struct e1000_filter_info));
869 TAILQ_INIT(&filter_info->flex_list);
870 TAILQ_INIT(&filter_info->twotuple_list);
871 TAILQ_INIT(&filter_info->fivetuple_list);
873 TAILQ_INIT(&igb_filter_ntuple_list);
874 TAILQ_INIT(&igb_filter_ethertype_list);
875 TAILQ_INIT(&igb_filter_syn_list);
876 TAILQ_INIT(&igb_filter_flex_list);
877 TAILQ_INIT(&igb_filter_rss_list);
878 TAILQ_INIT(&igb_flow_list);
883 igb_hw_control_release(hw);
889 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
891 struct rte_pci_device *pci_dev;
892 struct rte_intr_handle *intr_handle;
894 struct e1000_adapter *adapter =
895 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
896 struct e1000_filter_info *filter_info =
897 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
899 PMD_INIT_FUNC_TRACE();
901 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
904 hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
905 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
906 intr_handle = &pci_dev->intr_handle;
908 if (adapter->stopped == 0)
909 eth_igb_close(eth_dev);
911 eth_dev->dev_ops = NULL;
912 eth_dev->rx_pkt_burst = NULL;
913 eth_dev->tx_pkt_burst = NULL;
915 /* Reset any pending lock */
916 igb_reset_swfw_lock(hw);
918 rte_free(eth_dev->data->mac_addrs);
919 eth_dev->data->mac_addrs = NULL;
921 /* uninitialize PF if max_vfs not zero */
922 igb_pf_host_uninit(eth_dev);
924 /* disable uio intr before callback unregister */
925 rte_intr_disable(intr_handle);
926 rte_intr_callback_unregister(intr_handle,
927 eth_igb_interrupt_handler, eth_dev);
929 /* clear the SYN filter info */
930 filter_info->syn_info = 0;
932 /* clear the ethertype filters info */
933 filter_info->ethertype_mask = 0;
934 memset(filter_info->ethertype_filters, 0,
935 E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
937 /* clear the rss filter info */
938 memset(&filter_info->rss_info, 0,
939 sizeof(struct igb_rte_flow_rss_conf));
941 /* remove all ntuple filters of the device */
942 igb_ntuple_filter_uninit(eth_dev);
944 /* remove all flex filters of the device */
945 igb_flex_filter_uninit(eth_dev);
947 /* clear all the filters list */
948 igb_filterlist_flush(eth_dev);
954 * Virtual Function device init
957 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
959 struct rte_pci_device *pci_dev;
960 struct rte_intr_handle *intr_handle;
961 struct e1000_adapter *adapter =
962 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
963 struct e1000_hw *hw =
964 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
966 struct ether_addr *perm_addr = (struct ether_addr *)hw->mac.perm_addr;
968 PMD_INIT_FUNC_TRACE();
970 eth_dev->dev_ops = &igbvf_eth_dev_ops;
971 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
972 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
973 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
975 /* for secondary processes, we don't initialise any further as primary
976 * has already done this work. Only check we don't need a different
978 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
979 if (eth_dev->data->scattered_rx)
980 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
984 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
985 rte_eth_copy_pci_info(eth_dev, pci_dev);
987 hw->device_id = pci_dev->id.device_id;
988 hw->vendor_id = pci_dev->id.vendor_id;
989 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
990 adapter->stopped = 0;
992 /* Initialize the shared code (base driver) */
993 diag = e1000_setup_init_funcs(hw, TRUE);
995 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
1000 /* init_mailbox_params */
1001 hw->mbx.ops.init_params(hw);
1003 /* Disable the interrupts for VF */
1004 igbvf_intr_disable(hw);
1006 diag = hw->mac.ops.reset_hw(hw);
1008 /* Allocate memory for storing MAC addresses */
1009 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
1010 hw->mac.rar_entry_count, 0);
1011 if (eth_dev->data->mac_addrs == NULL) {
1013 "Failed to allocate %d bytes needed to store MAC "
1015 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
1019 /* Generate a random MAC address, if none was assigned by PF. */
1020 if (is_zero_ether_addr(perm_addr)) {
1021 eth_random_addr(perm_addr->addr_bytes);
1022 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1023 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1024 "%02x:%02x:%02x:%02x:%02x:%02x",
1025 perm_addr->addr_bytes[0],
1026 perm_addr->addr_bytes[1],
1027 perm_addr->addr_bytes[2],
1028 perm_addr->addr_bytes[3],
1029 perm_addr->addr_bytes[4],
1030 perm_addr->addr_bytes[5]);
1033 diag = e1000_rar_set(hw, perm_addr->addr_bytes, 0);
1035 rte_free(eth_dev->data->mac_addrs);
1036 eth_dev->data->mac_addrs = NULL;
1039 /* Copy the permanent MAC address */
1040 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
1041 ð_dev->data->mac_addrs[0]);
1043 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
1045 eth_dev->data->port_id, pci_dev->id.vendor_id,
1046 pci_dev->id.device_id, "igb_mac_82576_vf");
1048 intr_handle = &pci_dev->intr_handle;
1049 rte_intr_callback_register(intr_handle,
1050 eth_igbvf_interrupt_handler, eth_dev);
1056 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
1058 struct e1000_adapter *adapter =
1059 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
1060 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1062 PMD_INIT_FUNC_TRACE();
1064 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1067 if (adapter->stopped == 0)
1068 igbvf_dev_close(eth_dev);
1070 eth_dev->dev_ops = NULL;
1071 eth_dev->rx_pkt_burst = NULL;
1072 eth_dev->tx_pkt_burst = NULL;
1074 rte_free(eth_dev->data->mac_addrs);
1075 eth_dev->data->mac_addrs = NULL;
1077 /* disable uio intr before callback unregister */
1078 rte_intr_disable(&pci_dev->intr_handle);
1079 rte_intr_callback_unregister(&pci_dev->intr_handle,
1080 eth_igbvf_interrupt_handler,
1086 static int eth_igb_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1087 struct rte_pci_device *pci_dev)
1089 return rte_eth_dev_pci_generic_probe(pci_dev,
1090 sizeof(struct e1000_adapter), eth_igb_dev_init);
1093 static int eth_igb_pci_remove(struct rte_pci_device *pci_dev)
1095 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igb_dev_uninit);
1098 static struct rte_pci_driver rte_igb_pmd = {
1099 .id_table = pci_id_igb_map,
1100 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
1101 RTE_PCI_DRV_IOVA_AS_VA,
1102 .probe = eth_igb_pci_probe,
1103 .remove = eth_igb_pci_remove,
1107 static int eth_igbvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1108 struct rte_pci_device *pci_dev)
1110 return rte_eth_dev_pci_generic_probe(pci_dev,
1111 sizeof(struct e1000_adapter), eth_igbvf_dev_init);
1114 static int eth_igbvf_pci_remove(struct rte_pci_device *pci_dev)
1116 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igbvf_dev_uninit);
1120 * virtual function driver struct
1122 static struct rte_pci_driver rte_igbvf_pmd = {
1123 .id_table = pci_id_igbvf_map,
1124 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_IOVA_AS_VA,
1125 .probe = eth_igbvf_pci_probe,
1126 .remove = eth_igbvf_pci_remove,
1130 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1132 struct e1000_hw *hw =
1133 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1134 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
1135 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
1136 rctl |= E1000_RCTL_VFE;
1137 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1141 igb_check_mq_mode(struct rte_eth_dev *dev)
1143 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1144 enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
1145 uint16_t nb_rx_q = dev->data->nb_rx_queues;
1146 uint16_t nb_tx_q = dev->data->nb_tx_queues;
1148 if ((rx_mq_mode & ETH_MQ_RX_DCB_FLAG) ||
1149 tx_mq_mode == ETH_MQ_TX_DCB ||
1150 tx_mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1151 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
1154 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
1155 /* Check multi-queue mode.
1156 * To no break software we accept ETH_MQ_RX_NONE as this might
1157 * be used to turn off VLAN filter.
1160 if (rx_mq_mode == ETH_MQ_RX_NONE ||
1161 rx_mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1162 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
1163 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
1165 /* Only support one queue on VFs.
1166 * RSS together with SRIOV is not supported.
1168 PMD_INIT_LOG(ERR, "SRIOV is active,"
1169 " wrong mq_mode rx %d.",
1173 /* TX mode is not used here, so mode might be ignored.*/
1174 if (tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1175 /* SRIOV only works in VMDq enable mode */
1176 PMD_INIT_LOG(WARNING, "SRIOV is active,"
1177 " TX mode %d is not supported. "
1178 " Driver will behave as %d mode.",
1179 tx_mq_mode, ETH_MQ_TX_VMDQ_ONLY);
1182 /* check valid queue number */
1183 if ((nb_rx_q > 1) || (nb_tx_q > 1)) {
1184 PMD_INIT_LOG(ERR, "SRIOV is active,"
1185 " only support one queue on VFs.");
1189 /* To no break software that set invalid mode, only display
1190 * warning if invalid mode is used.
1192 if (rx_mq_mode != ETH_MQ_RX_NONE &&
1193 rx_mq_mode != ETH_MQ_RX_VMDQ_ONLY &&
1194 rx_mq_mode != ETH_MQ_RX_RSS) {
1195 /* RSS together with VMDq not supported*/
1196 PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
1201 if (tx_mq_mode != ETH_MQ_TX_NONE &&
1202 tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1203 PMD_INIT_LOG(WARNING, "TX mode %d is not supported."
1204 " Due to txmode is meaningless in this"
1205 " driver, just ignore.",
1213 eth_igb_configure(struct rte_eth_dev *dev)
1215 struct e1000_interrupt *intr =
1216 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1219 PMD_INIT_FUNC_TRACE();
1221 /* multipe queue mode checking */
1222 ret = igb_check_mq_mode(dev);
1224 PMD_DRV_LOG(ERR, "igb_check_mq_mode fails with %d.",
1229 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1230 PMD_INIT_FUNC_TRACE();
1236 eth_igb_rxtx_control(struct rte_eth_dev *dev,
1239 struct e1000_hw *hw =
1240 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1241 uint32_t tctl, rctl;
1243 tctl = E1000_READ_REG(hw, E1000_TCTL);
1244 rctl = E1000_READ_REG(hw, E1000_RCTL);
1248 tctl |= E1000_TCTL_EN;
1249 rctl |= E1000_RCTL_EN;
1252 tctl &= ~E1000_TCTL_EN;
1253 rctl &= ~E1000_RCTL_EN;
1255 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1256 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1257 E1000_WRITE_FLUSH(hw);
1261 eth_igb_start(struct rte_eth_dev *dev)
1263 struct e1000_hw *hw =
1264 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1265 struct e1000_adapter *adapter =
1266 E1000_DEV_PRIVATE(dev->data->dev_private);
1267 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1268 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1270 uint32_t intr_vector = 0;
1276 PMD_INIT_FUNC_TRACE();
1278 /* disable uio/vfio intr/eventfd mapping */
1279 rte_intr_disable(intr_handle);
1281 /* Power up the phy. Needed to make the link go Up */
1282 eth_igb_dev_set_link_up(dev);
1285 * Packet Buffer Allocation (PBA)
1286 * Writing PBA sets the receive portion of the buffer
1287 * the remainder is used for the transmit buffer.
1289 if (hw->mac.type == e1000_82575) {
1292 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
1293 E1000_WRITE_REG(hw, E1000_PBA, pba);
1296 /* Put the address into the Receive Address Array */
1297 e1000_rar_set(hw, hw->mac.addr, 0);
1299 /* Initialize the hardware */
1300 if (igb_hardware_init(hw)) {
1301 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
1304 adapter->stopped = 0;
1306 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1308 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1309 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1310 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
1311 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1312 E1000_WRITE_FLUSH(hw);
1314 /* configure PF module if SRIOV enabled */
1315 igb_pf_host_configure(dev);
1317 /* check and configure queue intr-vector mapping */
1318 if ((rte_intr_cap_multiple(intr_handle) ||
1319 !RTE_ETH_DEV_SRIOV(dev).active) &&
1320 dev->data->dev_conf.intr_conf.rxq != 0) {
1321 intr_vector = dev->data->nb_rx_queues;
1322 if (rte_intr_efd_enable(intr_handle, intr_vector))
1326 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1327 intr_handle->intr_vec =
1328 rte_zmalloc("intr_vec",
1329 dev->data->nb_rx_queues * sizeof(int), 0);
1330 if (intr_handle->intr_vec == NULL) {
1331 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1332 " intr_vec", dev->data->nb_rx_queues);
1337 /* confiugre msix for rx interrupt */
1338 eth_igb_configure_msix_intr(dev);
1340 /* Configure for OS presence */
1341 igb_init_manageability(hw);
1343 eth_igb_tx_init(dev);
1345 /* This can fail when allocating mbufs for descriptor rings */
1346 ret = eth_igb_rx_init(dev);
1348 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1349 igb_dev_clear_queues(dev);
1353 e1000_clear_hw_cntrs_base_generic(hw);
1356 * VLAN Offload Settings
1358 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
1359 ETH_VLAN_EXTEND_MASK;
1360 ret = eth_igb_vlan_offload_set(dev, mask);
1362 PMD_INIT_LOG(ERR, "Unable to set vlan offload");
1363 igb_dev_clear_queues(dev);
1367 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1368 /* Enable VLAN filter since VMDq always use VLAN filter */
1369 igb_vmdq_vlan_hw_filter_enable(dev);
1372 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
1373 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
1374 (hw->mac.type == e1000_i211)) {
1375 /* Configure EITR with the maximum possible value (0xFFFF) */
1376 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
1379 /* Setup link speed and duplex */
1380 speeds = &dev->data->dev_conf.link_speeds;
1381 if (*speeds == ETH_LINK_SPEED_AUTONEG) {
1382 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
1383 hw->mac.autoneg = 1;
1386 autoneg = (*speeds & ETH_LINK_SPEED_FIXED) == 0;
1389 hw->phy.autoneg_advertised = 0;
1391 if (*speeds & ~(ETH_LINK_SPEED_10M_HD | ETH_LINK_SPEED_10M |
1392 ETH_LINK_SPEED_100M_HD | ETH_LINK_SPEED_100M |
1393 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_FIXED)) {
1395 goto error_invalid_config;
1397 if (*speeds & ETH_LINK_SPEED_10M_HD) {
1398 hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
1401 if (*speeds & ETH_LINK_SPEED_10M) {
1402 hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
1405 if (*speeds & ETH_LINK_SPEED_100M_HD) {
1406 hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
1409 if (*speeds & ETH_LINK_SPEED_100M) {
1410 hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
1413 if (*speeds & ETH_LINK_SPEED_1G) {
1414 hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
1417 if (num_speeds == 0 || (!autoneg && (num_speeds > 1)))
1418 goto error_invalid_config;
1420 /* Set/reset the mac.autoneg based on the link speed,
1424 hw->mac.autoneg = 0;
1425 hw->mac.forced_speed_duplex =
1426 hw->phy.autoneg_advertised;
1428 hw->mac.autoneg = 1;
1432 e1000_setup_link(hw);
1434 if (rte_intr_allow_others(intr_handle)) {
1435 /* check if lsc interrupt is enabled */
1436 if (dev->data->dev_conf.intr_conf.lsc != 0)
1437 eth_igb_lsc_interrupt_setup(dev, TRUE);
1439 eth_igb_lsc_interrupt_setup(dev, FALSE);
1441 rte_intr_callback_unregister(intr_handle,
1442 eth_igb_interrupt_handler,
1444 if (dev->data->dev_conf.intr_conf.lsc != 0)
1445 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1446 " no intr multiplex");
1449 /* check if rxq interrupt is enabled */
1450 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1451 rte_intr_dp_is_en(intr_handle))
1452 eth_igb_rxq_interrupt_setup(dev);
1454 /* enable uio/vfio intr/eventfd mapping */
1455 rte_intr_enable(intr_handle);
1457 /* resume enabled intr since hw reset */
1458 igb_intr_enable(dev);
1460 /* restore all types filter */
1461 igb_filter_restore(dev);
1463 eth_igb_rxtx_control(dev, true);
1464 eth_igb_link_update(dev, 0);
1466 PMD_INIT_LOG(DEBUG, "<<");
1470 error_invalid_config:
1471 PMD_INIT_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
1472 dev->data->dev_conf.link_speeds, dev->data->port_id);
1473 igb_dev_clear_queues(dev);
1477 /*********************************************************************
1479 * This routine disables all traffic on the adapter by issuing a
1480 * global reset on the MAC.
1482 **********************************************************************/
1484 eth_igb_stop(struct rte_eth_dev *dev)
1486 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1487 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1488 struct rte_eth_link link;
1489 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1491 eth_igb_rxtx_control(dev, false);
1493 igb_intr_disable(hw);
1495 /* disable intr eventfd mapping */
1496 rte_intr_disable(intr_handle);
1498 igb_pf_reset_hw(hw);
1499 E1000_WRITE_REG(hw, E1000_WUC, 0);
1501 /* Set bit for Go Link disconnect */
1502 if (hw->mac.type >= e1000_82580) {
1505 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1506 phpm_reg |= E1000_82580_PM_GO_LINKD;
1507 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1510 /* Power down the phy. Needed to make the link go Down */
1511 eth_igb_dev_set_link_down(dev);
1513 igb_dev_clear_queues(dev);
1515 /* clear the recorded link status */
1516 memset(&link, 0, sizeof(link));
1517 rte_eth_linkstatus_set(dev, &link);
1519 if (!rte_intr_allow_others(intr_handle))
1520 /* resume to the default handler */
1521 rte_intr_callback_register(intr_handle,
1522 eth_igb_interrupt_handler,
1525 /* Clean datapath event and queue/vec mapping */
1526 rte_intr_efd_disable(intr_handle);
1527 if (intr_handle->intr_vec != NULL) {
1528 rte_free(intr_handle->intr_vec);
1529 intr_handle->intr_vec = NULL;
1534 eth_igb_dev_set_link_up(struct rte_eth_dev *dev)
1536 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1538 if (hw->phy.media_type == e1000_media_type_copper)
1539 e1000_power_up_phy(hw);
1541 e1000_power_up_fiber_serdes_link(hw);
1547 eth_igb_dev_set_link_down(struct rte_eth_dev *dev)
1549 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1551 if (hw->phy.media_type == e1000_media_type_copper)
1552 e1000_power_down_phy(hw);
1554 e1000_shutdown_fiber_serdes_link(hw);
1560 eth_igb_close(struct rte_eth_dev *dev)
1562 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1563 struct e1000_adapter *adapter =
1564 E1000_DEV_PRIVATE(dev->data->dev_private);
1565 struct rte_eth_link link;
1566 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1567 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1570 adapter->stopped = 1;
1572 e1000_phy_hw_reset(hw);
1573 igb_release_manageability(hw);
1574 igb_hw_control_release(hw);
1576 /* Clear bit for Go Link disconnect */
1577 if (hw->mac.type >= e1000_82580) {
1580 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1581 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1582 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1585 igb_dev_free_queues(dev);
1587 if (intr_handle->intr_vec) {
1588 rte_free(intr_handle->intr_vec);
1589 intr_handle->intr_vec = NULL;
1592 memset(&link, 0, sizeof(link));
1593 rte_eth_linkstatus_set(dev, &link);
1597 igb_get_rx_buffer_size(struct e1000_hw *hw)
1599 uint32_t rx_buf_size;
1600 if (hw->mac.type == e1000_82576) {
1601 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1602 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1603 /* PBS needs to be translated according to a lookup table */
1604 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1605 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1606 rx_buf_size = (rx_buf_size << 10);
1607 } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1608 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1610 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1616 /*********************************************************************
1618 * Initialize the hardware
1620 **********************************************************************/
1622 igb_hardware_init(struct e1000_hw *hw)
1624 uint32_t rx_buf_size;
1627 /* Let the firmware know the OS is in control */
1628 igb_hw_control_acquire(hw);
1631 * These parameters control the automatic generation (Tx) and
1632 * response (Rx) to Ethernet PAUSE frames.
1633 * - High water mark should allow for at least two standard size (1518)
1634 * frames to be received after sending an XOFF.
1635 * - Low water mark works best when it is very near the high water mark.
1636 * This allows the receiver to restart by sending XON when it has
1637 * drained a bit. Here we use an arbitrary value of 1500 which will
1638 * restart after one full frame is pulled from the buffer. There
1639 * could be several smaller frames in the buffer and if so they will
1640 * not trigger the XON until their total number reduces the buffer
1642 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1644 rx_buf_size = igb_get_rx_buffer_size(hw);
1646 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
1647 hw->fc.low_water = hw->fc.high_water - 1500;
1648 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1649 hw->fc.send_xon = 1;
1651 /* Set Flow control, use the tunable location if sane */
1652 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1653 hw->fc.requested_mode = igb_fc_setting;
1655 hw->fc.requested_mode = e1000_fc_none;
1657 /* Issue a global reset */
1658 igb_pf_reset_hw(hw);
1659 E1000_WRITE_REG(hw, E1000_WUC, 0);
1661 diag = e1000_init_hw(hw);
1665 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1666 e1000_get_phy_info(hw);
1667 e1000_check_for_link(hw);
1672 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1674 igb_read_stats_registers(struct e1000_hw *hw, struct e1000_hw_stats *stats)
1678 uint64_t old_gprc = stats->gprc;
1679 uint64_t old_gptc = stats->gptc;
1680 uint64_t old_tpr = stats->tpr;
1681 uint64_t old_tpt = stats->tpt;
1682 uint64_t old_rpthc = stats->rpthc;
1683 uint64_t old_hgptc = stats->hgptc;
1685 if(hw->phy.media_type == e1000_media_type_copper ||
1686 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1688 E1000_READ_REG(hw,E1000_SYMERRS);
1689 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1692 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1693 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1694 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1695 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1697 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1698 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1699 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1700 stats->dc += E1000_READ_REG(hw, E1000_DC);
1701 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1702 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1703 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1705 ** For watchdog management we need to know if we have been
1706 ** paused during the last interval, so capture that here.
1708 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1709 stats->xoffrxc += pause_frames;
1710 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1711 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1712 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1713 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1714 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1715 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1716 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1717 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1718 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1719 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1720 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1721 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1723 /* For the 64-bit byte counters the low dword must be read first. */
1724 /* Both registers clear on the read of the high dword */
1726 /* Workaround CRC bytes included in size, take away 4 bytes/packet */
1727 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1728 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1729 stats->gorc -= (stats->gprc - old_gprc) * ETHER_CRC_LEN;
1730 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1731 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1732 stats->gotc -= (stats->gptc - old_gptc) * ETHER_CRC_LEN;
1734 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1735 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1736 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1737 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1738 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1740 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1741 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1743 stats->tor += E1000_READ_REG(hw, E1000_TORL);
1744 stats->tor += ((uint64_t)E1000_READ_REG(hw, E1000_TORH) << 32);
1745 stats->tor -= (stats->tpr - old_tpr) * ETHER_CRC_LEN;
1746 stats->tot += E1000_READ_REG(hw, E1000_TOTL);
1747 stats->tot += ((uint64_t)E1000_READ_REG(hw, E1000_TOTH) << 32);
1748 stats->tot -= (stats->tpt - old_tpt) * ETHER_CRC_LEN;
1750 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1751 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1752 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1753 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1754 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1755 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1756 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1757 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1759 /* Interrupt Counts */
1761 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1762 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1763 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1764 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1765 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1766 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1767 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1768 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1769 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1771 /* Host to Card Statistics */
1773 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1774 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1775 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1776 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1777 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1778 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1779 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1780 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1781 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1782 stats->hgorc -= (stats->rpthc - old_rpthc) * ETHER_CRC_LEN;
1783 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1784 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1785 stats->hgotc -= (stats->hgptc - old_hgptc) * ETHER_CRC_LEN;
1786 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1787 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1788 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1790 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1791 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1792 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1793 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1794 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1795 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1799 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1801 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1802 struct e1000_hw_stats *stats =
1803 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1805 igb_read_stats_registers(hw, stats);
1807 if (rte_stats == NULL)
1811 rte_stats->imissed = stats->mpc;
1812 rte_stats->ierrors = stats->crcerrs +
1813 stats->rlec + stats->ruc + stats->roc +
1814 stats->rxerrc + stats->algnerrc + stats->cexterr;
1817 rte_stats->oerrors = stats->ecol + stats->latecol;
1819 rte_stats->ipackets = stats->gprc;
1820 rte_stats->opackets = stats->gptc;
1821 rte_stats->ibytes = stats->gorc;
1822 rte_stats->obytes = stats->gotc;
1827 eth_igb_stats_reset(struct rte_eth_dev *dev)
1829 struct e1000_hw_stats *hw_stats =
1830 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1832 /* HW registers are cleared on read */
1833 eth_igb_stats_get(dev, NULL);
1835 /* Reset software totals */
1836 memset(hw_stats, 0, sizeof(*hw_stats));
1840 eth_igb_xstats_reset(struct rte_eth_dev *dev)
1842 struct e1000_hw_stats *stats =
1843 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1845 /* HW registers are cleared on read */
1846 eth_igb_xstats_get(dev, NULL, IGB_NB_XSTATS);
1848 /* Reset software totals */
1849 memset(stats, 0, sizeof(*stats));
1852 static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1853 struct rte_eth_xstat_name *xstats_names,
1854 __rte_unused unsigned int size)
1858 if (xstats_names == NULL)
1859 return IGB_NB_XSTATS;
1861 /* Note: limit checked in rte_eth_xstats_names() */
1863 for (i = 0; i < IGB_NB_XSTATS; i++) {
1864 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
1865 "%s", rte_igb_stats_strings[i].name);
1868 return IGB_NB_XSTATS;
1871 static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
1872 struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
1878 if (xstats_names == NULL)
1879 return IGB_NB_XSTATS;
1881 for (i = 0; i < IGB_NB_XSTATS; i++)
1882 snprintf(xstats_names[i].name,
1883 sizeof(xstats_names[i].name),
1884 "%s", rte_igb_stats_strings[i].name);
1886 return IGB_NB_XSTATS;
1889 struct rte_eth_xstat_name xstats_names_copy[IGB_NB_XSTATS];
1891 eth_igb_xstats_get_names_by_id(dev, xstats_names_copy, NULL,
1894 for (i = 0; i < limit; i++) {
1895 if (ids[i] >= IGB_NB_XSTATS) {
1896 PMD_INIT_LOG(ERR, "id value isn't valid");
1899 strcpy(xstats_names[i].name,
1900 xstats_names_copy[ids[i]].name);
1907 eth_igb_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1910 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1911 struct e1000_hw_stats *hw_stats =
1912 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1915 if (n < IGB_NB_XSTATS)
1916 return IGB_NB_XSTATS;
1918 igb_read_stats_registers(hw, hw_stats);
1920 /* If this is a reset xstats is NULL, and we have cleared the
1921 * registers by reading them.
1926 /* Extended stats */
1927 for (i = 0; i < IGB_NB_XSTATS; i++) {
1929 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
1930 rte_igb_stats_strings[i].offset);
1933 return IGB_NB_XSTATS;
1937 eth_igb_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1938 uint64_t *values, unsigned int n)
1943 struct e1000_hw *hw =
1944 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1945 struct e1000_hw_stats *hw_stats =
1946 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1948 if (n < IGB_NB_XSTATS)
1949 return IGB_NB_XSTATS;
1951 igb_read_stats_registers(hw, hw_stats);
1953 /* If this is a reset xstats is NULL, and we have cleared the
1954 * registers by reading them.
1959 /* Extended stats */
1960 for (i = 0; i < IGB_NB_XSTATS; i++)
1961 values[i] = *(uint64_t *)(((char *)hw_stats) +
1962 rte_igb_stats_strings[i].offset);
1964 return IGB_NB_XSTATS;
1967 uint64_t values_copy[IGB_NB_XSTATS];
1969 eth_igb_xstats_get_by_id(dev, NULL, values_copy,
1972 for (i = 0; i < n; i++) {
1973 if (ids[i] >= IGB_NB_XSTATS) {
1974 PMD_INIT_LOG(ERR, "id value isn't valid");
1977 values[i] = values_copy[ids[i]];
1984 igbvf_read_stats_registers(struct e1000_hw *hw, struct e1000_vf_stats *hw_stats)
1986 /* Good Rx packets, include VF loopback */
1987 UPDATE_VF_STAT(E1000_VFGPRC,
1988 hw_stats->last_gprc, hw_stats->gprc);
1990 /* Good Rx octets, include VF loopback */
1991 UPDATE_VF_STAT(E1000_VFGORC,
1992 hw_stats->last_gorc, hw_stats->gorc);
1994 /* Good Tx packets, include VF loopback */
1995 UPDATE_VF_STAT(E1000_VFGPTC,
1996 hw_stats->last_gptc, hw_stats->gptc);
1998 /* Good Tx octets, include VF loopback */
1999 UPDATE_VF_STAT(E1000_VFGOTC,
2000 hw_stats->last_gotc, hw_stats->gotc);
2002 /* Rx Multicst packets */
2003 UPDATE_VF_STAT(E1000_VFMPRC,
2004 hw_stats->last_mprc, hw_stats->mprc);
2006 /* Good Rx loopback packets */
2007 UPDATE_VF_STAT(E1000_VFGPRLBC,
2008 hw_stats->last_gprlbc, hw_stats->gprlbc);
2010 /* Good Rx loopback octets */
2011 UPDATE_VF_STAT(E1000_VFGORLBC,
2012 hw_stats->last_gorlbc, hw_stats->gorlbc);
2014 /* Good Tx loopback packets */
2015 UPDATE_VF_STAT(E1000_VFGPTLBC,
2016 hw_stats->last_gptlbc, hw_stats->gptlbc);
2018 /* Good Tx loopback octets */
2019 UPDATE_VF_STAT(E1000_VFGOTLBC,
2020 hw_stats->last_gotlbc, hw_stats->gotlbc);
2023 static int eth_igbvf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2024 struct rte_eth_xstat_name *xstats_names,
2025 __rte_unused unsigned limit)
2029 if (xstats_names != NULL)
2030 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2031 snprintf(xstats_names[i].name,
2032 sizeof(xstats_names[i].name), "%s",
2033 rte_igbvf_stats_strings[i].name);
2035 return IGBVF_NB_XSTATS;
2039 eth_igbvf_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2042 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2043 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2044 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2047 if (n < IGBVF_NB_XSTATS)
2048 return IGBVF_NB_XSTATS;
2050 igbvf_read_stats_registers(hw, hw_stats);
2055 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2057 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
2058 rte_igbvf_stats_strings[i].offset);
2061 return IGBVF_NB_XSTATS;
2065 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
2067 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2068 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2069 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2071 igbvf_read_stats_registers(hw, hw_stats);
2073 if (rte_stats == NULL)
2076 rte_stats->ipackets = hw_stats->gprc;
2077 rte_stats->ibytes = hw_stats->gorc;
2078 rte_stats->opackets = hw_stats->gptc;
2079 rte_stats->obytes = hw_stats->gotc;
2084 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
2086 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
2087 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2089 /* Sync HW register to the last stats */
2090 eth_igbvf_stats_get(dev, NULL);
2092 /* reset HW current stats*/
2093 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
2094 offsetof(struct e1000_vf_stats, gprc));
2098 eth_igb_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
2101 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2102 struct e1000_fw_version fw;
2105 e1000_get_fw_version(hw, &fw);
2107 switch (hw->mac.type) {
2110 if (!(e1000_get_flash_presence_i210(hw))) {
2111 ret = snprintf(fw_version, fw_size,
2113 fw.invm_major, fw.invm_minor,
2119 /* if option rom is valid, display its version too */
2121 ret = snprintf(fw_version, fw_size,
2122 "%d.%d, 0x%08x, %d.%d.%d",
2123 fw.eep_major, fw.eep_minor, fw.etrack_id,
2124 fw.or_major, fw.or_build, fw.or_patch);
2127 if (fw.etrack_id != 0X0000) {
2128 ret = snprintf(fw_version, fw_size,
2130 fw.eep_major, fw.eep_minor,
2133 ret = snprintf(fw_version, fw_size,
2135 fw.eep_major, fw.eep_minor,
2142 ret += 1; /* add the size of '\0' */
2143 if (fw_size < (u32)ret)
2150 eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2152 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2154 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2155 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2156 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2157 dev_info->rx_queue_offload_capa = igb_get_rx_queue_offloads_capa(dev);
2158 dev_info->rx_offload_capa = igb_get_rx_port_offloads_capa(dev) |
2159 dev_info->rx_queue_offload_capa;
2160 dev_info->tx_queue_offload_capa = igb_get_tx_queue_offloads_capa(dev);
2161 dev_info->tx_offload_capa = igb_get_tx_port_offloads_capa(dev) |
2162 dev_info->tx_queue_offload_capa;
2164 switch (hw->mac.type) {
2166 dev_info->max_rx_queues = 4;
2167 dev_info->max_tx_queues = 4;
2168 dev_info->max_vmdq_pools = 0;
2172 dev_info->max_rx_queues = 16;
2173 dev_info->max_tx_queues = 16;
2174 dev_info->max_vmdq_pools = ETH_8_POOLS;
2175 dev_info->vmdq_queue_num = 16;
2179 dev_info->max_rx_queues = 8;
2180 dev_info->max_tx_queues = 8;
2181 dev_info->max_vmdq_pools = ETH_8_POOLS;
2182 dev_info->vmdq_queue_num = 8;
2186 dev_info->max_rx_queues = 8;
2187 dev_info->max_tx_queues = 8;
2188 dev_info->max_vmdq_pools = ETH_8_POOLS;
2189 dev_info->vmdq_queue_num = 8;
2193 dev_info->max_rx_queues = 8;
2194 dev_info->max_tx_queues = 8;
2198 dev_info->max_rx_queues = 4;
2199 dev_info->max_tx_queues = 4;
2200 dev_info->max_vmdq_pools = 0;
2204 dev_info->max_rx_queues = 2;
2205 dev_info->max_tx_queues = 2;
2206 dev_info->max_vmdq_pools = 0;
2210 /* Should not happen */
2213 dev_info->hash_key_size = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
2214 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
2215 dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
2217 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2219 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2220 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2221 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2223 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2228 dev_info->default_txconf = (struct rte_eth_txconf) {
2230 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2231 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2232 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2237 dev_info->rx_desc_lim = rx_desc_lim;
2238 dev_info->tx_desc_lim = tx_desc_lim;
2240 dev_info->speed_capa = ETH_LINK_SPEED_10M_HD | ETH_LINK_SPEED_10M |
2241 ETH_LINK_SPEED_100M_HD | ETH_LINK_SPEED_100M |
2245 static const uint32_t *
2246 eth_igb_supported_ptypes_get(struct rte_eth_dev *dev)
2248 static const uint32_t ptypes[] = {
2249 /* refers to igb_rxd_pkt_info_to_pkt_type() */
2252 RTE_PTYPE_L3_IPV4_EXT,
2254 RTE_PTYPE_L3_IPV6_EXT,
2258 RTE_PTYPE_TUNNEL_IP,
2259 RTE_PTYPE_INNER_L3_IPV6,
2260 RTE_PTYPE_INNER_L3_IPV6_EXT,
2261 RTE_PTYPE_INNER_L4_TCP,
2262 RTE_PTYPE_INNER_L4_UDP,
2266 if (dev->rx_pkt_burst == eth_igb_recv_pkts ||
2267 dev->rx_pkt_burst == eth_igb_recv_scattered_pkts)
2273 eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2275 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2277 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2278 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2279 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2280 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
2281 DEV_TX_OFFLOAD_IPV4_CKSUM |
2282 DEV_TX_OFFLOAD_UDP_CKSUM |
2283 DEV_TX_OFFLOAD_TCP_CKSUM |
2284 DEV_TX_OFFLOAD_SCTP_CKSUM |
2285 DEV_TX_OFFLOAD_TCP_TSO;
2286 switch (hw->mac.type) {
2288 dev_info->max_rx_queues = 2;
2289 dev_info->max_tx_queues = 2;
2291 case e1000_vfadapt_i350:
2292 dev_info->max_rx_queues = 1;
2293 dev_info->max_tx_queues = 1;
2296 /* Should not happen */
2300 dev_info->rx_queue_offload_capa = igb_get_rx_queue_offloads_capa(dev);
2301 dev_info->rx_offload_capa = igb_get_rx_port_offloads_capa(dev) |
2302 dev_info->rx_queue_offload_capa;
2303 dev_info->tx_queue_offload_capa = igb_get_tx_queue_offloads_capa(dev);
2304 dev_info->tx_offload_capa = igb_get_tx_port_offloads_capa(dev) |
2305 dev_info->tx_queue_offload_capa;
2307 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2309 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2310 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2311 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2313 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2318 dev_info->default_txconf = (struct rte_eth_txconf) {
2320 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2321 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2322 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2327 dev_info->rx_desc_lim = rx_desc_lim;
2328 dev_info->tx_desc_lim = tx_desc_lim;
2331 /* return 0 means link status changed, -1 means not changed */
2333 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2335 struct e1000_hw *hw =
2336 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2337 struct rte_eth_link link;
2338 int link_check, count;
2341 hw->mac.get_link_status = 1;
2343 /* possible wait-to-complete in up to 9 seconds */
2344 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
2345 /* Read the real link status */
2346 switch (hw->phy.media_type) {
2347 case e1000_media_type_copper:
2348 /* Do the work to read phy */
2349 e1000_check_for_link(hw);
2350 link_check = !hw->mac.get_link_status;
2353 case e1000_media_type_fiber:
2354 e1000_check_for_link(hw);
2355 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
2359 case e1000_media_type_internal_serdes:
2360 e1000_check_for_link(hw);
2361 link_check = hw->mac.serdes_has_link;
2364 /* VF device is type_unknown */
2365 case e1000_media_type_unknown:
2366 eth_igbvf_link_update(hw);
2367 link_check = !hw->mac.get_link_status;
2373 if (link_check || wait_to_complete == 0)
2375 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
2377 memset(&link, 0, sizeof(link));
2379 /* Now we check if a transition has happened */
2381 uint16_t duplex, speed;
2382 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
2383 link.link_duplex = (duplex == FULL_DUPLEX) ?
2384 ETH_LINK_FULL_DUPLEX :
2385 ETH_LINK_HALF_DUPLEX;
2386 link.link_speed = speed;
2387 link.link_status = ETH_LINK_UP;
2388 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2389 ETH_LINK_SPEED_FIXED);
2390 } else if (!link_check) {
2391 link.link_speed = 0;
2392 link.link_duplex = ETH_LINK_HALF_DUPLEX;
2393 link.link_status = ETH_LINK_DOWN;
2394 link.link_autoneg = ETH_LINK_FIXED;
2397 return rte_eth_linkstatus_set(dev, &link);
2401 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
2402 * For ASF and Pass Through versions of f/w this means
2403 * that the driver is loaded.
2406 igb_hw_control_acquire(struct e1000_hw *hw)
2410 /* Let firmware know the driver has taken over */
2411 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2412 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2416 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
2417 * For ASF and Pass Through versions of f/w this means that the
2418 * driver is no longer loaded.
2421 igb_hw_control_release(struct e1000_hw *hw)
2425 /* Let firmware taken over control of h/w */
2426 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2427 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
2428 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2432 * Bit of a misnomer, what this really means is
2433 * to enable OS management of the system... aka
2434 * to disable special hardware management features.
2437 igb_init_manageability(struct e1000_hw *hw)
2439 if (e1000_enable_mng_pass_thru(hw)) {
2440 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
2441 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2443 /* disable hardware interception of ARP */
2444 manc &= ~(E1000_MANC_ARP_EN);
2446 /* enable receiving management packets to the host */
2447 manc |= E1000_MANC_EN_MNG2HOST;
2448 manc2h |= 1 << 5; /* Mng Port 623 */
2449 manc2h |= 1 << 6; /* Mng Port 664 */
2450 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
2451 E1000_WRITE_REG(hw, E1000_MANC, manc);
2456 igb_release_manageability(struct e1000_hw *hw)
2458 if (e1000_enable_mng_pass_thru(hw)) {
2459 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2461 manc |= E1000_MANC_ARP_EN;
2462 manc &= ~E1000_MANC_EN_MNG2HOST;
2464 E1000_WRITE_REG(hw, E1000_MANC, manc);
2469 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
2471 struct e1000_hw *hw =
2472 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2475 rctl = E1000_READ_REG(hw, E1000_RCTL);
2476 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2477 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2481 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
2483 struct e1000_hw *hw =
2484 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2487 rctl = E1000_READ_REG(hw, E1000_RCTL);
2488 rctl &= (~E1000_RCTL_UPE);
2489 if (dev->data->all_multicast == 1)
2490 rctl |= E1000_RCTL_MPE;
2492 rctl &= (~E1000_RCTL_MPE);
2493 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2497 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
2499 struct e1000_hw *hw =
2500 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2503 rctl = E1000_READ_REG(hw, E1000_RCTL);
2504 rctl |= E1000_RCTL_MPE;
2505 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2509 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
2511 struct e1000_hw *hw =
2512 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2515 if (dev->data->promiscuous == 1)
2516 return; /* must remain in all_multicast mode */
2517 rctl = E1000_READ_REG(hw, E1000_RCTL);
2518 rctl &= (~E1000_RCTL_MPE);
2519 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2523 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2525 struct e1000_hw *hw =
2526 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2527 struct e1000_vfta * shadow_vfta =
2528 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2533 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
2534 E1000_VFTA_ENTRY_MASK);
2535 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
2536 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
2541 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
2543 /* update local VFTA copy */
2544 shadow_vfta->vfta[vid_idx] = vfta;
2550 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
2551 enum rte_vlan_type vlan_type,
2554 struct e1000_hw *hw =
2555 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2558 qinq = E1000_READ_REG(hw, E1000_CTRL_EXT);
2559 qinq &= E1000_CTRL_EXT_EXT_VLAN;
2561 /* only outer TPID of double VLAN can be configured*/
2562 if (qinq && vlan_type == ETH_VLAN_TYPE_OUTER) {
2563 reg = E1000_READ_REG(hw, E1000_VET);
2564 reg = (reg & (~E1000_VET_VET_EXT)) |
2565 ((uint32_t)tpid << E1000_VET_VET_EXT_SHIFT);
2566 E1000_WRITE_REG(hw, E1000_VET, reg);
2571 /* all other TPID values are read-only*/
2572 PMD_DRV_LOG(ERR, "Not supported");
2578 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
2580 struct e1000_hw *hw =
2581 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2584 /* Filter Table Disable */
2585 reg = E1000_READ_REG(hw, E1000_RCTL);
2586 reg &= ~E1000_RCTL_CFIEN;
2587 reg &= ~E1000_RCTL_VFE;
2588 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2592 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2594 struct e1000_hw *hw =
2595 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2596 struct e1000_vfta * shadow_vfta =
2597 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2601 /* Filter Table Enable, CFI not used for packet acceptance */
2602 reg = E1000_READ_REG(hw, E1000_RCTL);
2603 reg &= ~E1000_RCTL_CFIEN;
2604 reg |= E1000_RCTL_VFE;
2605 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2607 /* restore VFTA table */
2608 for (i = 0; i < IGB_VFTA_SIZE; i++)
2609 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
2613 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
2615 struct e1000_hw *hw =
2616 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2619 /* VLAN Mode Disable */
2620 reg = E1000_READ_REG(hw, E1000_CTRL);
2621 reg &= ~E1000_CTRL_VME;
2622 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2626 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
2628 struct e1000_hw *hw =
2629 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2632 /* VLAN Mode Enable */
2633 reg = E1000_READ_REG(hw, E1000_CTRL);
2634 reg |= E1000_CTRL_VME;
2635 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2639 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2641 struct e1000_hw *hw =
2642 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2645 /* CTRL_EXT: Extended VLAN */
2646 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2647 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
2648 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2650 /* Update maximum packet length */
2651 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
2652 E1000_WRITE_REG(hw, E1000_RLPML,
2653 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2658 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2660 struct e1000_hw *hw =
2661 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2664 /* CTRL_EXT: Extended VLAN */
2665 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2666 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
2667 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2669 /* Update maximum packet length */
2670 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
2671 E1000_WRITE_REG(hw, E1000_RLPML,
2672 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2677 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2679 struct rte_eth_rxmode *rxmode;
2681 rxmode = &dev->data->dev_conf.rxmode;
2682 if(mask & ETH_VLAN_STRIP_MASK){
2683 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
2684 igb_vlan_hw_strip_enable(dev);
2686 igb_vlan_hw_strip_disable(dev);
2689 if(mask & ETH_VLAN_FILTER_MASK){
2690 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
2691 igb_vlan_hw_filter_enable(dev);
2693 igb_vlan_hw_filter_disable(dev);
2696 if(mask & ETH_VLAN_EXTEND_MASK){
2697 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
2698 igb_vlan_hw_extend_enable(dev);
2700 igb_vlan_hw_extend_disable(dev);
2708 * It enables the interrupt mask and then enable the interrupt.
2711 * Pointer to struct rte_eth_dev.
2716 * - On success, zero.
2717 * - On failure, a negative value.
2720 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
2722 struct e1000_interrupt *intr =
2723 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2726 intr->mask |= E1000_ICR_LSC;
2728 intr->mask &= ~E1000_ICR_LSC;
2733 /* It clears the interrupt causes and enables the interrupt.
2734 * It will be called once only during nic initialized.
2737 * Pointer to struct rte_eth_dev.
2740 * - On success, zero.
2741 * - On failure, a negative value.
2743 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev)
2745 uint32_t mask, regval;
2746 struct e1000_hw *hw =
2747 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2748 struct rte_eth_dev_info dev_info;
2750 memset(&dev_info, 0, sizeof(dev_info));
2751 eth_igb_infos_get(dev, &dev_info);
2753 mask = 0xFFFFFFFF >> (32 - dev_info.max_rx_queues);
2754 regval = E1000_READ_REG(hw, E1000_EIMS);
2755 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
2761 * It reads ICR and gets interrupt causes, check it and set a bit flag
2762 * to update link status.
2765 * Pointer to struct rte_eth_dev.
2768 * - On success, zero.
2769 * - On failure, a negative value.
2772 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
2775 struct e1000_hw *hw =
2776 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2777 struct e1000_interrupt *intr =
2778 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2780 igb_intr_disable(hw);
2782 /* read-on-clear nic registers here */
2783 icr = E1000_READ_REG(hw, E1000_ICR);
2786 if (icr & E1000_ICR_LSC) {
2787 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
2790 if (icr & E1000_ICR_VMMB)
2791 intr->flags |= E1000_FLAG_MAILBOX;
2797 * It executes link_update after knowing an interrupt is prsent.
2800 * Pointer to struct rte_eth_dev.
2803 * - On success, zero.
2804 * - On failure, a negative value.
2807 eth_igb_interrupt_action(struct rte_eth_dev *dev,
2808 struct rte_intr_handle *intr_handle)
2810 struct e1000_hw *hw =
2811 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2812 struct e1000_interrupt *intr =
2813 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2814 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2815 struct rte_eth_link link;
2818 if (intr->flags & E1000_FLAG_MAILBOX) {
2819 igb_pf_mbx_process(dev);
2820 intr->flags &= ~E1000_FLAG_MAILBOX;
2823 igb_intr_enable(dev);
2824 rte_intr_enable(intr_handle);
2826 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
2827 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
2829 /* set get_link_status to check register later */
2830 hw->mac.get_link_status = 1;
2831 ret = eth_igb_link_update(dev, 0);
2833 /* check if link has changed */
2837 rte_eth_linkstatus_get(dev, &link);
2838 if (link.link_status) {
2840 " Port %d: Link Up - speed %u Mbps - %s",
2842 (unsigned)link.link_speed,
2843 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2844 "full-duplex" : "half-duplex");
2846 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2847 dev->data->port_id);
2850 PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
2851 pci_dev->addr.domain,
2853 pci_dev->addr.devid,
2854 pci_dev->addr.function);
2855 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
2863 * Interrupt handler which shall be registered at first.
2866 * Pointer to interrupt handle.
2868 * The address of parameter (struct rte_eth_dev *) regsitered before.
2874 eth_igb_interrupt_handler(void *param)
2876 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2878 eth_igb_interrupt_get_status(dev);
2879 eth_igb_interrupt_action(dev, dev->intr_handle);
2883 eth_igbvf_interrupt_get_status(struct rte_eth_dev *dev)
2886 struct e1000_hw *hw =
2887 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2888 struct e1000_interrupt *intr =
2889 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2891 igbvf_intr_disable(hw);
2893 /* read-on-clear nic registers here */
2894 eicr = E1000_READ_REG(hw, E1000_EICR);
2897 if (eicr == E1000_VTIVAR_MISC_MAILBOX)
2898 intr->flags |= E1000_FLAG_MAILBOX;
2903 void igbvf_mbx_process(struct rte_eth_dev *dev)
2905 struct e1000_hw *hw =
2906 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2907 struct e1000_mbx_info *mbx = &hw->mbx;
2910 /* peek the message first */
2911 in_msg = E1000_READ_REG(hw, E1000_VMBMEM(0));
2913 /* PF reset VF event */
2914 if (in_msg == E1000_PF_CONTROL_MSG) {
2915 /* dummy mbx read to ack pf */
2916 if (mbx->ops.read(hw, &in_msg, 1, 0))
2918 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
2924 eth_igbvf_interrupt_action(struct rte_eth_dev *dev, struct rte_intr_handle *intr_handle)
2926 struct e1000_interrupt *intr =
2927 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2929 if (intr->flags & E1000_FLAG_MAILBOX) {
2930 igbvf_mbx_process(dev);
2931 intr->flags &= ~E1000_FLAG_MAILBOX;
2934 igbvf_intr_enable(dev);
2935 rte_intr_enable(intr_handle);
2941 eth_igbvf_interrupt_handler(void *param)
2943 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2945 eth_igbvf_interrupt_get_status(dev);
2946 eth_igbvf_interrupt_action(dev, dev->intr_handle);
2950 eth_igb_led_on(struct rte_eth_dev *dev)
2952 struct e1000_hw *hw;
2954 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2955 return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
2959 eth_igb_led_off(struct rte_eth_dev *dev)
2961 struct e1000_hw *hw;
2963 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2964 return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
2968 eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2970 struct e1000_hw *hw;
2975 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2976 fc_conf->pause_time = hw->fc.pause_time;
2977 fc_conf->high_water = hw->fc.high_water;
2978 fc_conf->low_water = hw->fc.low_water;
2979 fc_conf->send_xon = hw->fc.send_xon;
2980 fc_conf->autoneg = hw->mac.autoneg;
2983 * Return rx_pause and tx_pause status according to actual setting of
2984 * the TFCE and RFCE bits in the CTRL register.
2986 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2987 if (ctrl & E1000_CTRL_TFCE)
2992 if (ctrl & E1000_CTRL_RFCE)
2997 if (rx_pause && tx_pause)
2998 fc_conf->mode = RTE_FC_FULL;
3000 fc_conf->mode = RTE_FC_RX_PAUSE;
3002 fc_conf->mode = RTE_FC_TX_PAUSE;
3004 fc_conf->mode = RTE_FC_NONE;
3010 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3012 struct e1000_hw *hw;
3014 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
3020 uint32_t rx_buf_size;
3021 uint32_t max_high_water;
3024 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3025 if (fc_conf->autoneg != hw->mac.autoneg)
3027 rx_buf_size = igb_get_rx_buffer_size(hw);
3028 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
3030 /* At least reserve one Ethernet frame for watermark */
3031 max_high_water = rx_buf_size - ETHER_MAX_LEN;
3032 if ((fc_conf->high_water > max_high_water) ||
3033 (fc_conf->high_water < fc_conf->low_water)) {
3034 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
3035 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
3039 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
3040 hw->fc.pause_time = fc_conf->pause_time;
3041 hw->fc.high_water = fc_conf->high_water;
3042 hw->fc.low_water = fc_conf->low_water;
3043 hw->fc.send_xon = fc_conf->send_xon;
3045 err = e1000_setup_link_generic(hw);
3046 if (err == E1000_SUCCESS) {
3048 /* check if we want to forward MAC frames - driver doesn't have native
3049 * capability to do that, so we'll write the registers ourselves */
3051 rctl = E1000_READ_REG(hw, E1000_RCTL);
3053 /* set or clear MFLCN.PMCF bit depending on configuration */
3054 if (fc_conf->mac_ctrl_frame_fwd != 0)
3055 rctl |= E1000_RCTL_PMCF;
3057 rctl &= ~E1000_RCTL_PMCF;
3059 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3060 E1000_WRITE_FLUSH(hw);
3065 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
3069 #define E1000_RAH_POOLSEL_SHIFT (18)
3071 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
3072 uint32_t index, uint32_t pool)
3074 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3077 e1000_rar_set(hw, mac_addr->addr_bytes, index);
3078 rah = E1000_READ_REG(hw, E1000_RAH(index));
3079 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
3080 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
3085 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
3087 uint8_t addr[ETHER_ADDR_LEN];
3088 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3090 memset(addr, 0, sizeof(addr));
3092 e1000_rar_set(hw, addr, index);
3096 eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
3097 struct ether_addr *addr)
3099 eth_igb_rar_clear(dev, 0);
3100 eth_igb_rar_set(dev, (void *)addr, 0, 0);
3105 * Virtual Function operations
3108 igbvf_intr_disable(struct e1000_hw *hw)
3110 PMD_INIT_FUNC_TRACE();
3112 /* Clear interrupt mask to stop from interrupts being generated */
3113 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
3115 E1000_WRITE_FLUSH(hw);
3119 igbvf_stop_adapter(struct rte_eth_dev *dev)
3123 struct rte_eth_dev_info dev_info;
3124 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3126 memset(&dev_info, 0, sizeof(dev_info));
3127 eth_igbvf_infos_get(dev, &dev_info);
3129 /* Clear interrupt mask to stop from interrupts being generated */
3130 igbvf_intr_disable(hw);
3132 /* Clear any pending interrupts, flush previous writes */
3133 E1000_READ_REG(hw, E1000_EICR);
3135 /* Disable the transmit unit. Each queue must be disabled. */
3136 for (i = 0; i < dev_info.max_tx_queues; i++)
3137 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
3139 /* Disable the receive unit by stopping each queue */
3140 for (i = 0; i < dev_info.max_rx_queues; i++) {
3141 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
3142 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
3143 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
3144 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
3148 /* flush all queues disables */
3149 E1000_WRITE_FLUSH(hw);
3153 static int eth_igbvf_link_update(struct e1000_hw *hw)
3155 struct e1000_mbx_info *mbx = &hw->mbx;
3156 struct e1000_mac_info *mac = &hw->mac;
3157 int ret_val = E1000_SUCCESS;
3159 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
3162 * We only want to run this if there has been a rst asserted.
3163 * in this case that could mean a link change, device reset,
3164 * or a virtual function reset
3167 /* If we were hit with a reset or timeout drop the link */
3168 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
3169 mac->get_link_status = TRUE;
3171 if (!mac->get_link_status)
3174 /* if link status is down no point in checking to see if pf is up */
3175 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
3178 /* if we passed all the tests above then the link is up and we no
3179 * longer need to check for link */
3180 mac->get_link_status = FALSE;
3188 igbvf_dev_configure(struct rte_eth_dev *dev)
3190 struct rte_eth_conf* conf = &dev->data->dev_conf;
3192 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
3193 dev->data->port_id);
3196 * VF has no ability to enable/disable HW CRC
3197 * Keep the persistent behavior the same as Host PF
3199 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
3200 if (rte_eth_dev_must_keep_crc(conf->rxmode.offloads)) {
3201 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
3202 conf->rxmode.offloads |= DEV_RX_OFFLOAD_CRC_STRIP;
3205 if (!rte_eth_dev_must_keep_crc(conf->rxmode.offloads)) {
3206 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
3207 conf->rxmode.offloads &= ~DEV_RX_OFFLOAD_CRC_STRIP;
3215 igbvf_dev_start(struct rte_eth_dev *dev)
3217 struct e1000_hw *hw =
3218 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3219 struct e1000_adapter *adapter =
3220 E1000_DEV_PRIVATE(dev->data->dev_private);
3221 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3222 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3224 uint32_t intr_vector = 0;
3226 PMD_INIT_FUNC_TRACE();
3228 hw->mac.ops.reset_hw(hw);
3229 adapter->stopped = 0;
3232 igbvf_set_vfta_all(dev,1);
3234 eth_igbvf_tx_init(dev);
3236 /* This can fail when allocating mbufs for descriptor rings */
3237 ret = eth_igbvf_rx_init(dev);
3239 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
3240 igb_dev_clear_queues(dev);
3244 /* check and configure queue intr-vector mapping */
3245 if (rte_intr_cap_multiple(intr_handle) &&
3246 dev->data->dev_conf.intr_conf.rxq) {
3247 intr_vector = dev->data->nb_rx_queues;
3248 ret = rte_intr_efd_enable(intr_handle, intr_vector);
3253 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
3254 intr_handle->intr_vec =
3255 rte_zmalloc("intr_vec",
3256 dev->data->nb_rx_queues * sizeof(int), 0);
3257 if (!intr_handle->intr_vec) {
3258 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
3259 " intr_vec", dev->data->nb_rx_queues);
3264 eth_igbvf_configure_msix_intr(dev);
3266 /* enable uio/vfio intr/eventfd mapping */
3267 rte_intr_enable(intr_handle);
3269 /* resume enabled intr since hw reset */
3270 igbvf_intr_enable(dev);
3276 igbvf_dev_stop(struct rte_eth_dev *dev)
3278 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3279 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3281 PMD_INIT_FUNC_TRACE();
3283 igbvf_stop_adapter(dev);
3286 * Clear what we set, but we still keep shadow_vfta to
3287 * restore after device starts
3289 igbvf_set_vfta_all(dev,0);
3291 igb_dev_clear_queues(dev);
3293 /* disable intr eventfd mapping */
3294 rte_intr_disable(intr_handle);
3296 /* Clean datapath event and queue/vec mapping */
3297 rte_intr_efd_disable(intr_handle);
3298 if (intr_handle->intr_vec) {
3299 rte_free(intr_handle->intr_vec);
3300 intr_handle->intr_vec = NULL;
3305 igbvf_dev_close(struct rte_eth_dev *dev)
3307 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3308 struct e1000_adapter *adapter =
3309 E1000_DEV_PRIVATE(dev->data->dev_private);
3310 struct ether_addr addr;
3312 PMD_INIT_FUNC_TRACE();
3316 igbvf_dev_stop(dev);
3317 adapter->stopped = 1;
3318 igb_dev_free_queues(dev);
3321 * reprogram the RAR with a zero mac address,
3322 * to ensure that the VF traffic goes to the PF
3323 * after stop, close and detach of the VF.
3326 memset(&addr, 0, sizeof(addr));
3327 igbvf_default_mac_addr_set(dev, &addr);
3331 igbvf_promiscuous_enable(struct rte_eth_dev *dev)
3333 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3335 /* Set both unicast and multicast promisc */
3336 e1000_promisc_set_vf(hw, e1000_promisc_enabled);
3340 igbvf_promiscuous_disable(struct rte_eth_dev *dev)
3342 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3344 /* If in allmulticast mode leave multicast promisc */
3345 if (dev->data->all_multicast == 1)
3346 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3348 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3352 igbvf_allmulticast_enable(struct rte_eth_dev *dev)
3354 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3356 /* In promiscuous mode multicast promisc already set */
3357 if (dev->data->promiscuous == 0)
3358 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3362 igbvf_allmulticast_disable(struct rte_eth_dev *dev)
3364 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3366 /* In promiscuous mode leave multicast promisc enabled */
3367 if (dev->data->promiscuous == 0)
3368 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3371 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
3373 struct e1000_mbx_info *mbx = &hw->mbx;
3377 /* After set vlan, vlan strip will also be enabled in igb driver*/
3378 msgbuf[0] = E1000_VF_SET_VLAN;
3380 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
3382 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
3384 err = mbx->ops.write_posted(hw, msgbuf, 2, 0);
3388 err = mbx->ops.read_posted(hw, msgbuf, 2, 0);
3392 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
3393 if (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK))
3400 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
3402 struct e1000_hw *hw =
3403 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3404 struct e1000_vfta * shadow_vfta =
3405 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3406 int i = 0, j = 0, vfta = 0, mask = 1;
3408 for (i = 0; i < IGB_VFTA_SIZE; i++){
3409 vfta = shadow_vfta->vfta[i];
3412 for (j = 0; j < 32; j++){
3415 (uint16_t)((i<<5)+j), on);
3424 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3426 struct e1000_hw *hw =
3427 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3428 struct e1000_vfta * shadow_vfta =
3429 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3430 uint32_t vid_idx = 0;
3431 uint32_t vid_bit = 0;
3434 PMD_INIT_FUNC_TRACE();
3436 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
3437 ret = igbvf_set_vfta(hw, vlan_id, !!on);
3439 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
3442 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
3443 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
3445 /*Save what we set and retore it after device reset*/
3447 shadow_vfta->vfta[vid_idx] |= vid_bit;
3449 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
3455 igbvf_default_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *addr)
3457 struct e1000_hw *hw =
3458 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3460 /* index is not used by rar_set() */
3461 hw->mac.ops.rar_set(hw, (void *)addr, 0);
3467 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
3468 struct rte_eth_rss_reta_entry64 *reta_conf,
3473 uint16_t idx, shift;
3474 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3476 if (reta_size != ETH_RSS_RETA_SIZE_128) {
3477 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3478 "(%d) doesn't match the number hardware can supported "
3479 "(%d)", reta_size, ETH_RSS_RETA_SIZE_128);
3483 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3484 idx = i / RTE_RETA_GROUP_SIZE;
3485 shift = i % RTE_RETA_GROUP_SIZE;
3486 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3490 if (mask == IGB_4_BIT_MASK)
3493 r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3494 for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
3495 if (mask & (0x1 << j))
3496 reta |= reta_conf[idx].reta[shift + j] <<
3499 reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
3501 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
3508 eth_igb_rss_reta_query(struct rte_eth_dev *dev,
3509 struct rte_eth_rss_reta_entry64 *reta_conf,
3514 uint16_t idx, shift;
3515 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3517 if (reta_size != ETH_RSS_RETA_SIZE_128) {
3518 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3519 "(%d) doesn't match the number hardware can supported "
3520 "(%d)", reta_size, ETH_RSS_RETA_SIZE_128);
3524 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3525 idx = i / RTE_RETA_GROUP_SIZE;
3526 shift = i % RTE_RETA_GROUP_SIZE;
3527 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3531 reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3532 for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
3533 if (mask & (0x1 << j))
3534 reta_conf[idx].reta[shift + j] =
3535 ((reta >> (CHAR_BIT * j)) &
3544 eth_igb_syn_filter_set(struct rte_eth_dev *dev,
3545 struct rte_eth_syn_filter *filter,
3548 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3549 struct e1000_filter_info *filter_info =
3550 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3551 uint32_t synqf, rfctl;
3553 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3556 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3559 if (synqf & E1000_SYN_FILTER_ENABLE)
3562 synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
3563 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
3565 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3566 if (filter->hig_pri)
3567 rfctl |= E1000_RFCTL_SYNQFP;
3569 rfctl &= ~E1000_RFCTL_SYNQFP;
3571 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
3573 if (!(synqf & E1000_SYN_FILTER_ENABLE))
3578 filter_info->syn_info = synqf;
3579 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
3580 E1000_WRITE_FLUSH(hw);
3585 eth_igb_syn_filter_get(struct rte_eth_dev *dev,
3586 struct rte_eth_syn_filter *filter)
3588 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3589 uint32_t synqf, rfctl;
3591 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3592 if (synqf & E1000_SYN_FILTER_ENABLE) {
3593 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3594 filter->hig_pri = (rfctl & E1000_RFCTL_SYNQFP) ? 1 : 0;
3595 filter->queue = (uint8_t)((synqf & E1000_SYN_FILTER_QUEUE) >>
3596 E1000_SYN_FILTER_QUEUE_SHIFT);
3604 eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
3605 enum rte_filter_op filter_op,
3608 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3611 MAC_TYPE_FILTER_SUP(hw->mac.type);
3613 if (filter_op == RTE_ETH_FILTER_NOP)
3617 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3622 switch (filter_op) {
3623 case RTE_ETH_FILTER_ADD:
3624 ret = eth_igb_syn_filter_set(dev,
3625 (struct rte_eth_syn_filter *)arg,
3628 case RTE_ETH_FILTER_DELETE:
3629 ret = eth_igb_syn_filter_set(dev,
3630 (struct rte_eth_syn_filter *)arg,
3633 case RTE_ETH_FILTER_GET:
3634 ret = eth_igb_syn_filter_get(dev,
3635 (struct rte_eth_syn_filter *)arg);
3638 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
3646 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
3648 ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
3649 struct e1000_2tuple_filter_info *filter_info)
3651 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3653 if (filter->priority > E1000_2TUPLE_MAX_PRI)
3654 return -EINVAL; /* filter index is out of range. */
3655 if (filter->tcp_flags > TCP_FLAG_ALL)
3656 return -EINVAL; /* flags is invalid. */
3658 switch (filter->dst_port_mask) {
3660 filter_info->dst_port_mask = 0;
3661 filter_info->dst_port = filter->dst_port;
3664 filter_info->dst_port_mask = 1;
3667 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3671 switch (filter->proto_mask) {
3673 filter_info->proto_mask = 0;
3674 filter_info->proto = filter->proto;
3677 filter_info->proto_mask = 1;
3680 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3684 filter_info->priority = (uint8_t)filter->priority;
3685 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3686 filter_info->tcp_flags = filter->tcp_flags;
3688 filter_info->tcp_flags = 0;
3693 static inline struct e1000_2tuple_filter *
3694 igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
3695 struct e1000_2tuple_filter_info *key)
3697 struct e1000_2tuple_filter *it;
3699 TAILQ_FOREACH(it, filter_list, entries) {
3700 if (memcmp(key, &it->filter_info,
3701 sizeof(struct e1000_2tuple_filter_info)) == 0) {
3708 /* inject a igb 2tuple filter to HW */
3710 igb_inject_2uple_filter(struct rte_eth_dev *dev,
3711 struct e1000_2tuple_filter *filter)
3713 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3714 uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
3715 uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3719 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3720 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3721 imir |= E1000_IMIR_PORT_BP;
3723 imir &= ~E1000_IMIR_PORT_BP;
3725 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3727 ttqf |= E1000_TTQF_QUEUE_ENABLE;
3728 ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
3729 ttqf |= (uint32_t)(filter->filter_info.proto &
3730 E1000_TTQF_PROTOCOL_MASK);
3731 if (filter->filter_info.proto_mask == 0)
3732 ttqf &= ~E1000_TTQF_MASK_ENABLE;
3734 /* tcp flags bits setting. */
3735 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3736 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3737 imir_ext |= E1000_IMIREXT_CTRL_URG;
3738 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3739 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3740 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3741 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3742 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3743 imir_ext |= E1000_IMIREXT_CTRL_RST;
3744 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3745 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3746 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3747 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3749 imir_ext |= E1000_IMIREXT_CTRL_BP;
3751 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3752 E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
3753 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3757 * igb_add_2tuple_filter - add a 2tuple filter
3760 * dev: Pointer to struct rte_eth_dev.
3761 * ntuple_filter: ponter to the filter that will be added.
3764 * - On success, zero.
3765 * - On failure, a negative value.
3768 igb_add_2tuple_filter(struct rte_eth_dev *dev,
3769 struct rte_eth_ntuple_filter *ntuple_filter)
3771 struct e1000_filter_info *filter_info =
3772 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3773 struct e1000_2tuple_filter *filter;
3776 filter = rte_zmalloc("e1000_2tuple_filter",
3777 sizeof(struct e1000_2tuple_filter), 0);
3781 ret = ntuple_filter_to_2tuple(ntuple_filter,
3782 &filter->filter_info);
3787 if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3788 &filter->filter_info) != NULL) {
3789 PMD_DRV_LOG(ERR, "filter exists.");
3793 filter->queue = ntuple_filter->queue;
3796 * look for an unused 2tuple filter index,
3797 * and insert the filter to list.
3799 for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
3800 if (!(filter_info->twotuple_mask & (1 << i))) {
3801 filter_info->twotuple_mask |= 1 << i;
3803 TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
3809 if (i >= E1000_MAX_TTQF_FILTERS) {
3810 PMD_DRV_LOG(ERR, "2tuple filters are full.");
3815 igb_inject_2uple_filter(dev, filter);
3820 igb_delete_2tuple_filter(struct rte_eth_dev *dev,
3821 struct e1000_2tuple_filter *filter)
3823 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3824 struct e1000_filter_info *filter_info =
3825 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3827 filter_info->twotuple_mask &= ~(1 << filter->index);
3828 TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
3831 E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
3832 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3833 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3838 * igb_remove_2tuple_filter - remove a 2tuple filter
3841 * dev: Pointer to struct rte_eth_dev.
3842 * ntuple_filter: ponter to the filter that will be removed.
3845 * - On success, zero.
3846 * - On failure, a negative value.
3849 igb_remove_2tuple_filter(struct rte_eth_dev *dev,
3850 struct rte_eth_ntuple_filter *ntuple_filter)
3852 struct e1000_filter_info *filter_info =
3853 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3854 struct e1000_2tuple_filter_info filter_2tuple;
3855 struct e1000_2tuple_filter *filter;
3858 memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
3859 ret = ntuple_filter_to_2tuple(ntuple_filter,
3864 filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3866 if (filter == NULL) {
3867 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3871 igb_delete_2tuple_filter(dev, filter);
3876 /* inject a igb flex filter to HW */
3878 igb_inject_flex_filter(struct rte_eth_dev *dev,
3879 struct e1000_flex_filter *filter)
3881 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3882 uint32_t wufc, queueing;
3886 wufc = E1000_READ_REG(hw, E1000_WUFC);
3887 if (filter->index < E1000_MAX_FHFT)
3888 reg_off = E1000_FHFT(filter->index);
3890 reg_off = E1000_FHFT_EXT(filter->index - E1000_MAX_FHFT);
3892 E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
3893 (E1000_WUFC_FLX0 << filter->index));
3894 queueing = filter->filter_info.len |
3895 (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
3896 (filter->filter_info.priority <<
3897 E1000_FHFT_QUEUEING_PRIO_SHIFT);
3898 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
3901 for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
3902 E1000_WRITE_REG(hw, reg_off,
3903 filter->filter_info.dwords[j]);
3904 reg_off += sizeof(uint32_t);
3905 E1000_WRITE_REG(hw, reg_off,
3906 filter->filter_info.dwords[++j]);
3907 reg_off += sizeof(uint32_t);
3908 E1000_WRITE_REG(hw, reg_off,
3909 (uint32_t)filter->filter_info.mask[i]);
3910 reg_off += sizeof(uint32_t) * 2;
3915 static inline struct e1000_flex_filter *
3916 eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
3917 struct e1000_flex_filter_info *key)
3919 struct e1000_flex_filter *it;
3921 TAILQ_FOREACH(it, filter_list, entries) {
3922 if (memcmp(key, &it->filter_info,
3923 sizeof(struct e1000_flex_filter_info)) == 0)
3930 /* remove a flex byte filter
3932 * dev: Pointer to struct rte_eth_dev.
3933 * filter: the pointer of the filter will be removed.
3936 igb_remove_flex_filter(struct rte_eth_dev *dev,
3937 struct e1000_flex_filter *filter)
3939 struct e1000_filter_info *filter_info =
3940 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3941 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3945 wufc = E1000_READ_REG(hw, E1000_WUFC);
3946 if (filter->index < E1000_MAX_FHFT)
3947 reg_off = E1000_FHFT(filter->index);
3949 reg_off = E1000_FHFT_EXT(filter->index - E1000_MAX_FHFT);
3951 for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
3952 E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
3954 E1000_WRITE_REG(hw, E1000_WUFC, wufc &
3955 (~(E1000_WUFC_FLX0 << filter->index)));
3957 filter_info->flex_mask &= ~(1 << filter->index);
3958 TAILQ_REMOVE(&filter_info->flex_list, filter, entries);
3963 eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
3964 struct rte_eth_flex_filter *filter,
3967 struct e1000_filter_info *filter_info =
3968 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3969 struct e1000_flex_filter *flex_filter, *it;
3973 flex_filter = rte_zmalloc("e1000_flex_filter",
3974 sizeof(struct e1000_flex_filter), 0);
3975 if (flex_filter == NULL)
3978 flex_filter->filter_info.len = filter->len;
3979 flex_filter->filter_info.priority = filter->priority;
3980 memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
3981 for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
3983 /* reverse bits in flex filter's mask*/
3984 for (shift = 0; shift < CHAR_BIT; shift++) {
3985 if (filter->mask[i] & (0x01 << shift))
3986 mask |= (0x80 >> shift);
3988 flex_filter->filter_info.mask[i] = mask;
3991 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
3992 &flex_filter->filter_info);
3993 if (it == NULL && !add) {
3994 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3995 rte_free(flex_filter);
3998 if (it != NULL && add) {
3999 PMD_DRV_LOG(ERR, "filter exists.");
4000 rte_free(flex_filter);
4005 flex_filter->queue = filter->queue;
4007 * look for an unused flex filter index
4008 * and insert the filter into the list.
4010 for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
4011 if (!(filter_info->flex_mask & (1 << i))) {
4012 filter_info->flex_mask |= 1 << i;
4013 flex_filter->index = i;
4014 TAILQ_INSERT_TAIL(&filter_info->flex_list,
4020 if (i >= E1000_MAX_FLEX_FILTERS) {
4021 PMD_DRV_LOG(ERR, "flex filters are full.");
4022 rte_free(flex_filter);
4026 igb_inject_flex_filter(dev, flex_filter);
4029 igb_remove_flex_filter(dev, it);
4030 rte_free(flex_filter);
4037 eth_igb_get_flex_filter(struct rte_eth_dev *dev,
4038 struct rte_eth_flex_filter *filter)
4040 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4041 struct e1000_filter_info *filter_info =
4042 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4043 struct e1000_flex_filter flex_filter, *it;
4044 uint32_t wufc, queueing, wufc_en = 0;
4046 memset(&flex_filter, 0, sizeof(struct e1000_flex_filter));
4047 flex_filter.filter_info.len = filter->len;
4048 flex_filter.filter_info.priority = filter->priority;
4049 memcpy(flex_filter.filter_info.dwords, filter->bytes, filter->len);
4050 memcpy(flex_filter.filter_info.mask, filter->mask,
4051 RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT);
4053 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
4054 &flex_filter.filter_info);
4056 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4060 wufc = E1000_READ_REG(hw, E1000_WUFC);
4061 wufc_en = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << it->index);
4063 if ((wufc & wufc_en) == wufc_en) {
4064 uint32_t reg_off = 0;
4065 if (it->index < E1000_MAX_FHFT)
4066 reg_off = E1000_FHFT(it->index);
4068 reg_off = E1000_FHFT_EXT(it->index - E1000_MAX_FHFT);
4070 queueing = E1000_READ_REG(hw,
4071 reg_off + E1000_FHFT_QUEUEING_OFFSET);
4072 filter->len = queueing & E1000_FHFT_QUEUEING_LEN;
4073 filter->priority = (queueing & E1000_FHFT_QUEUEING_PRIO) >>
4074 E1000_FHFT_QUEUEING_PRIO_SHIFT;
4075 filter->queue = (queueing & E1000_FHFT_QUEUEING_QUEUE) >>
4076 E1000_FHFT_QUEUEING_QUEUE_SHIFT;
4083 eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
4084 enum rte_filter_op filter_op,
4087 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4088 struct rte_eth_flex_filter *filter;
4091 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
4093 if (filter_op == RTE_ETH_FILTER_NOP)
4097 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
4102 filter = (struct rte_eth_flex_filter *)arg;
4103 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN
4104 || filter->len % sizeof(uint64_t) != 0) {
4105 PMD_DRV_LOG(ERR, "filter's length is out of range");
4108 if (filter->priority > E1000_MAX_FLEX_FILTER_PRI) {
4109 PMD_DRV_LOG(ERR, "filter's priority is out of range");
4113 switch (filter_op) {
4114 case RTE_ETH_FILTER_ADD:
4115 ret = eth_igb_add_del_flex_filter(dev, filter, TRUE);
4117 case RTE_ETH_FILTER_DELETE:
4118 ret = eth_igb_add_del_flex_filter(dev, filter, FALSE);
4120 case RTE_ETH_FILTER_GET:
4121 ret = eth_igb_get_flex_filter(dev, filter);
4124 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
4132 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
4134 ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
4135 struct e1000_5tuple_filter_info *filter_info)
4137 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
4139 if (filter->priority > E1000_2TUPLE_MAX_PRI)
4140 return -EINVAL; /* filter index is out of range. */
4141 if (filter->tcp_flags > TCP_FLAG_ALL)
4142 return -EINVAL; /* flags is invalid. */
4144 switch (filter->dst_ip_mask) {
4146 filter_info->dst_ip_mask = 0;
4147 filter_info->dst_ip = filter->dst_ip;
4150 filter_info->dst_ip_mask = 1;
4153 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
4157 switch (filter->src_ip_mask) {
4159 filter_info->src_ip_mask = 0;
4160 filter_info->src_ip = filter->src_ip;
4163 filter_info->src_ip_mask = 1;
4166 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
4170 switch (filter->dst_port_mask) {
4172 filter_info->dst_port_mask = 0;
4173 filter_info->dst_port = filter->dst_port;
4176 filter_info->dst_port_mask = 1;
4179 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
4183 switch (filter->src_port_mask) {
4185 filter_info->src_port_mask = 0;
4186 filter_info->src_port = filter->src_port;
4189 filter_info->src_port_mask = 1;
4192 PMD_DRV_LOG(ERR, "invalid src_port mask.");
4196 switch (filter->proto_mask) {
4198 filter_info->proto_mask = 0;
4199 filter_info->proto = filter->proto;
4202 filter_info->proto_mask = 1;
4205 PMD_DRV_LOG(ERR, "invalid protocol mask.");
4209 filter_info->priority = (uint8_t)filter->priority;
4210 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
4211 filter_info->tcp_flags = filter->tcp_flags;
4213 filter_info->tcp_flags = 0;
4218 static inline struct e1000_5tuple_filter *
4219 igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
4220 struct e1000_5tuple_filter_info *key)
4222 struct e1000_5tuple_filter *it;
4224 TAILQ_FOREACH(it, filter_list, entries) {
4225 if (memcmp(key, &it->filter_info,
4226 sizeof(struct e1000_5tuple_filter_info)) == 0) {
4233 /* inject a igb 5-tuple filter to HW */
4235 igb_inject_5tuple_filter_82576(struct rte_eth_dev *dev,
4236 struct e1000_5tuple_filter *filter)
4238 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4239 uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
4240 uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
4244 ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
4245 if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
4246 ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
4247 if (filter->filter_info.dst_ip_mask == 0)
4248 ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
4249 if (filter->filter_info.src_port_mask == 0)
4250 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
4251 if (filter->filter_info.proto_mask == 0)
4252 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
4253 ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
4254 E1000_FTQF_QUEUE_MASK;
4255 ftqf |= E1000_FTQF_QUEUE_ENABLE;
4256 E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
4257 E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
4258 E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
4260 spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
4261 E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
4263 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
4264 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
4265 imir |= E1000_IMIR_PORT_BP;
4267 imir &= ~E1000_IMIR_PORT_BP;
4268 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
4270 /* tcp flags bits setting. */
4271 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
4272 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
4273 imir_ext |= E1000_IMIREXT_CTRL_URG;
4274 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
4275 imir_ext |= E1000_IMIREXT_CTRL_ACK;
4276 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
4277 imir_ext |= E1000_IMIREXT_CTRL_PSH;
4278 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
4279 imir_ext |= E1000_IMIREXT_CTRL_RST;
4280 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
4281 imir_ext |= E1000_IMIREXT_CTRL_SYN;
4282 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
4283 imir_ext |= E1000_IMIREXT_CTRL_FIN;
4285 imir_ext |= E1000_IMIREXT_CTRL_BP;
4287 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
4288 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
4292 * igb_add_5tuple_filter_82576 - add a 5tuple filter
4295 * dev: Pointer to struct rte_eth_dev.
4296 * ntuple_filter: ponter to the filter that will be added.
4299 * - On success, zero.
4300 * - On failure, a negative value.
4303 igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
4304 struct rte_eth_ntuple_filter *ntuple_filter)
4306 struct e1000_filter_info *filter_info =
4307 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4308 struct e1000_5tuple_filter *filter;
4312 filter = rte_zmalloc("e1000_5tuple_filter",
4313 sizeof(struct e1000_5tuple_filter), 0);
4317 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4318 &filter->filter_info);
4324 if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4325 &filter->filter_info) != NULL) {
4326 PMD_DRV_LOG(ERR, "filter exists.");
4330 filter->queue = ntuple_filter->queue;
4333 * look for an unused 5tuple filter index,
4334 * and insert the filter to list.
4336 for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
4337 if (!(filter_info->fivetuple_mask & (1 << i))) {
4338 filter_info->fivetuple_mask |= 1 << i;
4340 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
4346 if (i >= E1000_MAX_FTQF_FILTERS) {
4347 PMD_DRV_LOG(ERR, "5tuple filters are full.");
4352 igb_inject_5tuple_filter_82576(dev, filter);
4357 igb_delete_5tuple_filter_82576(struct rte_eth_dev *dev,
4358 struct e1000_5tuple_filter *filter)
4360 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4361 struct e1000_filter_info *filter_info =
4362 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4364 filter_info->fivetuple_mask &= ~(1 << filter->index);
4365 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
4368 E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
4369 E1000_FTQF_VF_BP | E1000_FTQF_MASK);
4370 E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
4371 E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
4372 E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
4373 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
4374 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
4379 * igb_remove_5tuple_filter_82576 - remove a 5tuple filter
4382 * dev: Pointer to struct rte_eth_dev.
4383 * ntuple_filter: ponter to the filter that will be removed.
4386 * - On success, zero.
4387 * - On failure, a negative value.
4390 igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
4391 struct rte_eth_ntuple_filter *ntuple_filter)
4393 struct e1000_filter_info *filter_info =
4394 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4395 struct e1000_5tuple_filter_info filter_5tuple;
4396 struct e1000_5tuple_filter *filter;
4399 memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
4400 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4405 filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4407 if (filter == NULL) {
4408 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4412 igb_delete_5tuple_filter_82576(dev, filter);
4418 eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
4421 struct e1000_hw *hw;
4422 struct rte_eth_dev_info dev_info;
4423 uint32_t frame_size = mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN +
4426 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4428 #ifdef RTE_LIBRTE_82571_SUPPORT
4429 /* XXX: not bigger than max_rx_pktlen */
4430 if (hw->mac.type == e1000_82571)
4433 eth_igb_infos_get(dev, &dev_info);
4435 /* check that mtu is within the allowed range */
4436 if ((mtu < ETHER_MIN_MTU) ||
4437 (frame_size > dev_info.max_rx_pktlen))
4440 /* refuse mtu that requires the support of scattered packets when this
4441 * feature has not been enabled before. */
4442 if (!dev->data->scattered_rx &&
4443 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)
4446 rctl = E1000_READ_REG(hw, E1000_RCTL);
4448 /* switch to jumbo mode if needed */
4449 if (frame_size > ETHER_MAX_LEN) {
4450 dev->data->dev_conf.rxmode.offloads |=
4451 DEV_RX_OFFLOAD_JUMBO_FRAME;
4452 rctl |= E1000_RCTL_LPE;
4454 dev->data->dev_conf.rxmode.offloads &=
4455 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
4456 rctl &= ~E1000_RCTL_LPE;
4458 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
4460 /* update max frame size */
4461 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
4463 E1000_WRITE_REG(hw, E1000_RLPML,
4464 dev->data->dev_conf.rxmode.max_rx_pkt_len);
4470 * igb_add_del_ntuple_filter - add or delete a ntuple filter
4473 * dev: Pointer to struct rte_eth_dev.
4474 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4475 * add: if true, add filter, if false, remove filter
4478 * - On success, zero.
4479 * - On failure, a negative value.
4482 igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
4483 struct rte_eth_ntuple_filter *ntuple_filter,
4486 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4489 switch (ntuple_filter->flags) {
4490 case RTE_5TUPLE_FLAGS:
4491 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4492 if (hw->mac.type != e1000_82576)
4495 ret = igb_add_5tuple_filter_82576(dev,
4498 ret = igb_remove_5tuple_filter_82576(dev,
4501 case RTE_2TUPLE_FLAGS:
4502 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4503 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350 &&
4504 hw->mac.type != e1000_i210 &&
4505 hw->mac.type != e1000_i211)
4508 ret = igb_add_2tuple_filter(dev, ntuple_filter);
4510 ret = igb_remove_2tuple_filter(dev, ntuple_filter);
4521 * igb_get_ntuple_filter - get a ntuple filter
4524 * dev: Pointer to struct rte_eth_dev.
4525 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4528 * - On success, zero.
4529 * - On failure, a negative value.
4532 igb_get_ntuple_filter(struct rte_eth_dev *dev,
4533 struct rte_eth_ntuple_filter *ntuple_filter)
4535 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4536 struct e1000_filter_info *filter_info =
4537 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4538 struct e1000_5tuple_filter_info filter_5tuple;
4539 struct e1000_2tuple_filter_info filter_2tuple;
4540 struct e1000_5tuple_filter *p_5tuple_filter;
4541 struct e1000_2tuple_filter *p_2tuple_filter;
4544 switch (ntuple_filter->flags) {
4545 case RTE_5TUPLE_FLAGS:
4546 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4547 if (hw->mac.type != e1000_82576)
4549 memset(&filter_5tuple,
4551 sizeof(struct e1000_5tuple_filter_info));
4552 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4556 p_5tuple_filter = igb_5tuple_filter_lookup_82576(
4557 &filter_info->fivetuple_list,
4559 if (p_5tuple_filter == NULL) {
4560 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4563 ntuple_filter->queue = p_5tuple_filter->queue;
4565 case RTE_2TUPLE_FLAGS:
4566 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4567 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
4569 memset(&filter_2tuple,
4571 sizeof(struct e1000_2tuple_filter_info));
4572 ret = ntuple_filter_to_2tuple(ntuple_filter, &filter_2tuple);
4575 p_2tuple_filter = igb_2tuple_filter_lookup(
4576 &filter_info->twotuple_list,
4578 if (p_2tuple_filter == NULL) {
4579 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4582 ntuple_filter->queue = p_2tuple_filter->queue;
4593 * igb_ntuple_filter_handle - Handle operations for ntuple filter.
4594 * @dev: pointer to rte_eth_dev structure
4595 * @filter_op:operation will be taken.
4596 * @arg: a pointer to specific structure corresponding to the filter_op
4599 igb_ntuple_filter_handle(struct rte_eth_dev *dev,
4600 enum rte_filter_op filter_op,
4603 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4606 MAC_TYPE_FILTER_SUP(hw->mac.type);
4608 if (filter_op == RTE_ETH_FILTER_NOP)
4612 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4617 switch (filter_op) {
4618 case RTE_ETH_FILTER_ADD:
4619 ret = igb_add_del_ntuple_filter(dev,
4620 (struct rte_eth_ntuple_filter *)arg,
4623 case RTE_ETH_FILTER_DELETE:
4624 ret = igb_add_del_ntuple_filter(dev,
4625 (struct rte_eth_ntuple_filter *)arg,
4628 case RTE_ETH_FILTER_GET:
4629 ret = igb_get_ntuple_filter(dev,
4630 (struct rte_eth_ntuple_filter *)arg);
4633 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4641 igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
4646 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4647 if (filter_info->ethertype_filters[i].ethertype == ethertype &&
4648 (filter_info->ethertype_mask & (1 << i)))
4655 igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
4656 uint16_t ethertype, uint32_t etqf)
4660 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4661 if (!(filter_info->ethertype_mask & (1 << i))) {
4662 filter_info->ethertype_mask |= 1 << i;
4663 filter_info->ethertype_filters[i].ethertype = ethertype;
4664 filter_info->ethertype_filters[i].etqf = etqf;
4672 igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
4675 if (idx >= E1000_MAX_ETQF_FILTERS)
4677 filter_info->ethertype_mask &= ~(1 << idx);
4678 filter_info->ethertype_filters[idx].ethertype = 0;
4679 filter_info->ethertype_filters[idx].etqf = 0;
4685 igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
4686 struct rte_eth_ethertype_filter *filter,
4689 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4690 struct e1000_filter_info *filter_info =
4691 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4695 if (filter->ether_type == ETHER_TYPE_IPv4 ||
4696 filter->ether_type == ETHER_TYPE_IPv6) {
4697 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
4698 " ethertype filter.", filter->ether_type);
4702 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
4703 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
4706 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
4707 PMD_DRV_LOG(ERR, "drop option is unsupported.");
4711 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4712 if (ret >= 0 && add) {
4713 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
4714 filter->ether_type);
4717 if (ret < 0 && !add) {
4718 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4719 filter->ether_type);
4724 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
4725 etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
4726 etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
4727 ret = igb_ethertype_filter_insert(filter_info,
4728 filter->ether_type, etqf);
4730 PMD_DRV_LOG(ERR, "ethertype filters are full.");
4734 ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
4738 E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
4739 E1000_WRITE_FLUSH(hw);
4745 igb_get_ethertype_filter(struct rte_eth_dev *dev,
4746 struct rte_eth_ethertype_filter *filter)
4748 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4749 struct e1000_filter_info *filter_info =
4750 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4754 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4756 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4757 filter->ether_type);
4761 etqf = E1000_READ_REG(hw, E1000_ETQF(ret));
4762 if (etqf & E1000_ETQF_FILTER_ENABLE) {
4763 filter->ether_type = etqf & E1000_ETQF_ETHERTYPE;
4765 filter->queue = (etqf & E1000_ETQF_QUEUE) >>
4766 E1000_ETQF_QUEUE_SHIFT;
4774 * igb_ethertype_filter_handle - Handle operations for ethertype filter.
4775 * @dev: pointer to rte_eth_dev structure
4776 * @filter_op:operation will be taken.
4777 * @arg: a pointer to specific structure corresponding to the filter_op
4780 igb_ethertype_filter_handle(struct rte_eth_dev *dev,
4781 enum rte_filter_op filter_op,
4784 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4787 MAC_TYPE_FILTER_SUP(hw->mac.type);
4789 if (filter_op == RTE_ETH_FILTER_NOP)
4793 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4798 switch (filter_op) {
4799 case RTE_ETH_FILTER_ADD:
4800 ret = igb_add_del_ethertype_filter(dev,
4801 (struct rte_eth_ethertype_filter *)arg,
4804 case RTE_ETH_FILTER_DELETE:
4805 ret = igb_add_del_ethertype_filter(dev,
4806 (struct rte_eth_ethertype_filter *)arg,
4809 case RTE_ETH_FILTER_GET:
4810 ret = igb_get_ethertype_filter(dev,
4811 (struct rte_eth_ethertype_filter *)arg);
4814 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4822 eth_igb_filter_ctrl(struct rte_eth_dev *dev,
4823 enum rte_filter_type filter_type,
4824 enum rte_filter_op filter_op,
4829 switch (filter_type) {
4830 case RTE_ETH_FILTER_NTUPLE:
4831 ret = igb_ntuple_filter_handle(dev, filter_op, arg);
4833 case RTE_ETH_FILTER_ETHERTYPE:
4834 ret = igb_ethertype_filter_handle(dev, filter_op, arg);
4836 case RTE_ETH_FILTER_SYN:
4837 ret = eth_igb_syn_filter_handle(dev, filter_op, arg);
4839 case RTE_ETH_FILTER_FLEXIBLE:
4840 ret = eth_igb_flex_filter_handle(dev, filter_op, arg);
4842 case RTE_ETH_FILTER_GENERIC:
4843 if (filter_op != RTE_ETH_FILTER_GET)
4845 *(const void **)arg = &igb_flow_ops;
4848 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
4857 eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
4858 struct ether_addr *mc_addr_set,
4859 uint32_t nb_mc_addr)
4861 struct e1000_hw *hw;
4863 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4864 e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
4869 igb_read_systime_cyclecounter(struct rte_eth_dev *dev)
4871 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4872 uint64_t systime_cycles;
4874 switch (hw->mac.type) {
4878 * Need to read System Time Residue Register to be able
4879 * to read the other two registers.
4881 E1000_READ_REG(hw, E1000_SYSTIMR);
4882 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
4883 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4884 systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4891 * Need to read System Time Residue Register to be able
4892 * to read the other two registers.
4894 E1000_READ_REG(hw, E1000_SYSTIMR);
4895 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4896 /* Only the 8 LSB are valid. */
4897 systime_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_SYSTIMH)
4901 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4902 systime_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4907 return systime_cycles;
4911 igb_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4913 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4914 uint64_t rx_tstamp_cycles;
4916 switch (hw->mac.type) {
4919 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4920 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4921 rx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4927 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4928 /* Only the 8 LSB are valid. */
4929 rx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_RXSTMPH)
4933 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4934 rx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4939 return rx_tstamp_cycles;
4943 igb_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4945 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4946 uint64_t tx_tstamp_cycles;
4948 switch (hw->mac.type) {
4951 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4952 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4953 tx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4959 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4960 /* Only the 8 LSB are valid. */
4961 tx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_TXSTMPH)
4965 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4966 tx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4971 return tx_tstamp_cycles;
4975 igb_start_timecounters(struct rte_eth_dev *dev)
4977 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4978 struct e1000_adapter *adapter =
4979 (struct e1000_adapter *)dev->data->dev_private;
4980 uint32_t incval = 1;
4982 uint64_t mask = E1000_CYCLECOUNTER_MASK;
4984 switch (hw->mac.type) {
4988 /* 32 LSB bits + 8 MSB bits = 40 bits */
4989 mask = (1ULL << 40) - 1;
4994 * Start incrementing the register
4995 * used to timestamp PTP packets.
4997 E1000_WRITE_REG(hw, E1000_TIMINCA, incval);
5000 incval = E1000_INCVALUE_82576;
5001 shift = IGB_82576_TSYNC_SHIFT;
5002 E1000_WRITE_REG(hw, E1000_TIMINCA,
5003 E1000_INCPERIOD_82576 | incval);
5010 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
5011 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
5012 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
5014 adapter->systime_tc.cc_mask = mask;
5015 adapter->systime_tc.cc_shift = shift;
5016 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
5018 adapter->rx_tstamp_tc.cc_mask = mask;
5019 adapter->rx_tstamp_tc.cc_shift = shift;
5020 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
5022 adapter->tx_tstamp_tc.cc_mask = mask;
5023 adapter->tx_tstamp_tc.cc_shift = shift;
5024 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
5028 igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
5030 struct e1000_adapter *adapter =
5031 (struct e1000_adapter *)dev->data->dev_private;
5033 adapter->systime_tc.nsec += delta;
5034 adapter->rx_tstamp_tc.nsec += delta;
5035 adapter->tx_tstamp_tc.nsec += delta;
5041 igb_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
5044 struct e1000_adapter *adapter =
5045 (struct e1000_adapter *)dev->data->dev_private;
5047 ns = rte_timespec_to_ns(ts);
5049 /* Set the timecounters to a new value. */
5050 adapter->systime_tc.nsec = ns;
5051 adapter->rx_tstamp_tc.nsec = ns;
5052 adapter->tx_tstamp_tc.nsec = ns;
5058 igb_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
5060 uint64_t ns, systime_cycles;
5061 struct e1000_adapter *adapter =
5062 (struct e1000_adapter *)dev->data->dev_private;
5064 systime_cycles = igb_read_systime_cyclecounter(dev);
5065 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
5066 *ts = rte_ns_to_timespec(ns);
5072 igb_timesync_enable(struct rte_eth_dev *dev)
5074 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5078 /* Stop the timesync system time. */
5079 E1000_WRITE_REG(hw, E1000_TIMINCA, 0x0);
5080 /* Reset the timesync system time value. */
5081 switch (hw->mac.type) {
5087 E1000_WRITE_REG(hw, E1000_SYSTIMR, 0x0);
5090 E1000_WRITE_REG(hw, E1000_SYSTIML, 0x0);
5091 E1000_WRITE_REG(hw, E1000_SYSTIMH, 0x0);
5094 /* Not supported. */
5098 /* Enable system time for it isn't on by default. */
5099 tsauxc = E1000_READ_REG(hw, E1000_TSAUXC);
5100 tsauxc &= ~E1000_TSAUXC_DISABLE_SYSTIME;
5101 E1000_WRITE_REG(hw, E1000_TSAUXC, tsauxc);
5103 igb_start_timecounters(dev);
5105 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
5106 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588),
5108 E1000_ETQF_FILTER_ENABLE |
5111 /* Enable timestamping of received PTP packets. */
5112 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5113 tsync_ctl |= E1000_TSYNCRXCTL_ENABLED;
5114 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
5116 /* Enable Timestamping of transmitted PTP packets. */
5117 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5118 tsync_ctl |= E1000_TSYNCTXCTL_ENABLED;
5119 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
5125 igb_timesync_disable(struct rte_eth_dev *dev)
5127 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5130 /* Disable timestamping of transmitted PTP packets. */
5131 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5132 tsync_ctl &= ~E1000_TSYNCTXCTL_ENABLED;
5133 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
5135 /* Disable timestamping of received PTP packets. */
5136 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5137 tsync_ctl &= ~E1000_TSYNCRXCTL_ENABLED;
5138 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
5140 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
5141 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588), 0);
5143 /* Stop incrementating the System Time registers. */
5144 E1000_WRITE_REG(hw, E1000_TIMINCA, 0);
5150 igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
5151 struct timespec *timestamp,
5152 uint32_t flags __rte_unused)
5154 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5155 struct e1000_adapter *adapter =
5156 (struct e1000_adapter *)dev->data->dev_private;
5157 uint32_t tsync_rxctl;
5158 uint64_t rx_tstamp_cycles;
5161 tsync_rxctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5162 if ((tsync_rxctl & E1000_TSYNCRXCTL_VALID) == 0)
5165 rx_tstamp_cycles = igb_read_rx_tstamp_cyclecounter(dev);
5166 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
5167 *timestamp = rte_ns_to_timespec(ns);
5173 igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
5174 struct timespec *timestamp)
5176 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5177 struct e1000_adapter *adapter =
5178 (struct e1000_adapter *)dev->data->dev_private;
5179 uint32_t tsync_txctl;
5180 uint64_t tx_tstamp_cycles;
5183 tsync_txctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5184 if ((tsync_txctl & E1000_TSYNCTXCTL_VALID) == 0)
5187 tx_tstamp_cycles = igb_read_tx_tstamp_cyclecounter(dev);
5188 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
5189 *timestamp = rte_ns_to_timespec(ns);
5195 eth_igb_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5199 const struct reg_info *reg_group;
5201 while ((reg_group = igb_regs[g_ind++]))
5202 count += igb_reg_group_count(reg_group);
5208 igbvf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5212 const struct reg_info *reg_group;
5214 while ((reg_group = igbvf_regs[g_ind++]))
5215 count += igb_reg_group_count(reg_group);
5221 eth_igb_get_regs(struct rte_eth_dev *dev,
5222 struct rte_dev_reg_info *regs)
5224 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5225 uint32_t *data = regs->data;
5228 const struct reg_info *reg_group;
5231 regs->length = eth_igb_get_reg_length(dev);
5232 regs->width = sizeof(uint32_t);
5236 /* Support only full register dump */
5237 if ((regs->length == 0) ||
5238 (regs->length == (uint32_t)eth_igb_get_reg_length(dev))) {
5239 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5241 while ((reg_group = igb_regs[g_ind++]))
5242 count += igb_read_regs_group(dev, &data[count],
5251 igbvf_get_regs(struct rte_eth_dev *dev,
5252 struct rte_dev_reg_info *regs)
5254 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5255 uint32_t *data = regs->data;
5258 const struct reg_info *reg_group;
5261 regs->length = igbvf_get_reg_length(dev);
5262 regs->width = sizeof(uint32_t);
5266 /* Support only full register dump */
5267 if ((regs->length == 0) ||
5268 (regs->length == (uint32_t)igbvf_get_reg_length(dev))) {
5269 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5271 while ((reg_group = igbvf_regs[g_ind++]))
5272 count += igb_read_regs_group(dev, &data[count],
5281 eth_igb_get_eeprom_length(struct rte_eth_dev *dev)
5283 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5285 /* Return unit is byte count */
5286 return hw->nvm.word_size * 2;
5290 eth_igb_get_eeprom(struct rte_eth_dev *dev,
5291 struct rte_dev_eeprom_info *in_eeprom)
5293 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5294 struct e1000_nvm_info *nvm = &hw->nvm;
5295 uint16_t *data = in_eeprom->data;
5298 first = in_eeprom->offset >> 1;
5299 length = in_eeprom->length >> 1;
5300 if ((first >= hw->nvm.word_size) ||
5301 ((first + length) >= hw->nvm.word_size))
5304 in_eeprom->magic = hw->vendor_id |
5305 ((uint32_t)hw->device_id << 16);
5307 if ((nvm->ops.read) == NULL)
5310 return nvm->ops.read(hw, first, length, data);
5314 eth_igb_set_eeprom(struct rte_eth_dev *dev,
5315 struct rte_dev_eeprom_info *in_eeprom)
5317 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5318 struct e1000_nvm_info *nvm = &hw->nvm;
5319 uint16_t *data = in_eeprom->data;
5322 first = in_eeprom->offset >> 1;
5323 length = in_eeprom->length >> 1;
5324 if ((first >= hw->nvm.word_size) ||
5325 ((first + length) >= hw->nvm.word_size))
5328 in_eeprom->magic = (uint32_t)hw->vendor_id |
5329 ((uint32_t)hw->device_id << 16);
5331 if ((nvm->ops.write) == NULL)
5333 return nvm->ops.write(hw, first, length, data);
5337 eth_igb_get_module_info(struct rte_eth_dev *dev,
5338 struct rte_eth_dev_module_info *modinfo)
5340 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5342 uint32_t status = 0;
5343 uint16_t sff8472_rev, addr_mode;
5344 bool page_swap = false;
5346 if (hw->phy.media_type == e1000_media_type_copper ||
5347 hw->phy.media_type == e1000_media_type_unknown)
5350 /* Check whether we support SFF-8472 or not */
5351 status = e1000_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev);
5355 /* addressing mode is not supported */
5356 status = e1000_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode);
5360 /* addressing mode is not supported */
5361 if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) {
5363 "Address change required to access page 0xA2, "
5364 "but not supported. Please report the module "
5365 "type to the driver maintainers.\n");
5369 if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) {
5370 /* We have an SFP, but it does not support SFF-8472 */
5371 modinfo->type = RTE_ETH_MODULE_SFF_8079;
5372 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
5374 /* We have an SFP which supports a revision of SFF-8472 */
5375 modinfo->type = RTE_ETH_MODULE_SFF_8472;
5376 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
5383 eth_igb_get_module_eeprom(struct rte_eth_dev *dev,
5384 struct rte_dev_eeprom_info *info)
5386 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5388 uint32_t status = 0;
5389 uint16_t dataword[RTE_ETH_MODULE_SFF_8472_LEN / 2 + 1];
5390 u16 first_word, last_word;
5393 if (info->length == 0)
5396 first_word = info->offset >> 1;
5397 last_word = (info->offset + info->length - 1) >> 1;
5399 /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
5400 for (i = 0; i < last_word - first_word + 1; i++) {
5401 status = e1000_read_phy_reg_i2c(hw, (first_word + i) * 2,
5404 /* Error occurred while reading module */
5408 dataword[i] = rte_be_to_cpu_16(dataword[i]);
5411 memcpy(info->data, (u8 *)dataword + (info->offset & 1), info->length);
5417 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
5419 struct e1000_hw *hw =
5420 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5421 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5422 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5423 uint32_t vec = E1000_MISC_VEC_ID;
5425 if (rte_intr_allow_others(intr_handle))
5426 vec = E1000_RX_VEC_START;
5428 uint32_t mask = 1 << (queue_id + vec);
5430 E1000_WRITE_REG(hw, E1000_EIMC, mask);
5431 E1000_WRITE_FLUSH(hw);
5437 eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
5439 struct e1000_hw *hw =
5440 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5441 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5442 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5443 uint32_t vec = E1000_MISC_VEC_ID;
5445 if (rte_intr_allow_others(intr_handle))
5446 vec = E1000_RX_VEC_START;
5448 uint32_t mask = 1 << (queue_id + vec);
5451 regval = E1000_READ_REG(hw, E1000_EIMS);
5452 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
5453 E1000_WRITE_FLUSH(hw);
5455 rte_intr_enable(intr_handle);
5461 eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
5462 uint8_t index, uint8_t offset)
5464 uint32_t val = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
5467 val &= ~((uint32_t)0xFF << offset);
5469 /* write vector and valid bit */
5470 val |= (msix_vector | E1000_IVAR_VALID) << offset;
5472 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, val);
5476 eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
5477 uint8_t queue, uint8_t msix_vector)
5481 if (hw->mac.type == e1000_82575) {
5483 tmp = E1000_EICR_RX_QUEUE0 << queue;
5484 else if (direction == 1)
5485 tmp = E1000_EICR_TX_QUEUE0 << queue;
5486 E1000_WRITE_REG(hw, E1000_MSIXBM(msix_vector), tmp);
5487 } else if (hw->mac.type == e1000_82576) {
5488 if ((direction == 0) || (direction == 1))
5489 eth_igb_write_ivar(hw, msix_vector, queue & 0x7,
5490 ((queue & 0x8) << 1) +
5492 } else if ((hw->mac.type == e1000_82580) ||
5493 (hw->mac.type == e1000_i350) ||
5494 (hw->mac.type == e1000_i354) ||
5495 (hw->mac.type == e1000_i210) ||
5496 (hw->mac.type == e1000_i211)) {
5497 if ((direction == 0) || (direction == 1))
5498 eth_igb_write_ivar(hw, msix_vector,
5500 ((queue & 0x1) << 4) +
5505 /* Sets up the hardware to generate MSI-X interrupts properly
5507 * board private structure
5510 eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
5513 uint32_t tmpval, regval, intr_mask;
5514 struct e1000_hw *hw =
5515 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5516 uint32_t vec = E1000_MISC_VEC_ID;
5517 uint32_t base = E1000_MISC_VEC_ID;
5518 uint32_t misc_shift = 0;
5519 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5520 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5522 /* won't configure msix register if no mapping is done
5523 * between intr vector and event fd
5525 if (!rte_intr_dp_is_en(intr_handle))
5528 if (rte_intr_allow_others(intr_handle)) {
5529 vec = base = E1000_RX_VEC_START;
5533 /* set interrupt vector for other causes */
5534 if (hw->mac.type == e1000_82575) {
5535 tmpval = E1000_READ_REG(hw, E1000_CTRL_EXT);
5536 /* enable MSI-X PBA support */
5537 tmpval |= E1000_CTRL_EXT_PBA_CLR;
5539 /* Auto-Mask interrupts upon ICR read */
5540 tmpval |= E1000_CTRL_EXT_EIAME;
5541 tmpval |= E1000_CTRL_EXT_IRCA;
5543 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmpval);
5545 /* enable msix_other interrupt */
5546 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), 0, E1000_EIMS_OTHER);
5547 regval = E1000_READ_REG(hw, E1000_EIAC);
5548 E1000_WRITE_REG(hw, E1000_EIAC, regval | E1000_EIMS_OTHER);
5549 regval = E1000_READ_REG(hw, E1000_EIAM);
5550 E1000_WRITE_REG(hw, E1000_EIMS, regval | E1000_EIMS_OTHER);
5551 } else if ((hw->mac.type == e1000_82576) ||
5552 (hw->mac.type == e1000_82580) ||
5553 (hw->mac.type == e1000_i350) ||
5554 (hw->mac.type == e1000_i354) ||
5555 (hw->mac.type == e1000_i210) ||
5556 (hw->mac.type == e1000_i211)) {
5557 /* turn on MSI-X capability first */
5558 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
5559 E1000_GPIE_PBA | E1000_GPIE_EIAME |
5561 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
5563 regval = E1000_READ_REG(hw, E1000_EIAC);
5564 E1000_WRITE_REG(hw, E1000_EIAC, regval | intr_mask);
5566 /* enable msix_other interrupt */
5567 regval = E1000_READ_REG(hw, E1000_EIMS);
5568 E1000_WRITE_REG(hw, E1000_EIMS, regval | intr_mask);
5569 tmpval = (dev->data->nb_rx_queues | E1000_IVAR_VALID) << 8;
5570 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmpval);
5573 /* use EIAM to auto-mask when MSI-X interrupt
5574 * is asserted, this saves a register write for every interrupt
5576 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
5578 regval = E1000_READ_REG(hw, E1000_EIAM);
5579 E1000_WRITE_REG(hw, E1000_EIAM, regval | intr_mask);
5581 for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
5582 eth_igb_assign_msix_vector(hw, 0, queue_id, vec);
5583 intr_handle->intr_vec[queue_id] = vec;
5584 if (vec < base + intr_handle->nb_efd - 1)
5588 E1000_WRITE_FLUSH(hw);
5591 /* restore n-tuple filter */
5593 igb_ntuple_filter_restore(struct rte_eth_dev *dev)
5595 struct e1000_filter_info *filter_info =
5596 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5597 struct e1000_5tuple_filter *p_5tuple;
5598 struct e1000_2tuple_filter *p_2tuple;
5600 TAILQ_FOREACH(p_5tuple, &filter_info->fivetuple_list, entries) {
5601 igb_inject_5tuple_filter_82576(dev, p_5tuple);
5604 TAILQ_FOREACH(p_2tuple, &filter_info->twotuple_list, entries) {
5605 igb_inject_2uple_filter(dev, p_2tuple);
5609 /* restore SYN filter */
5611 igb_syn_filter_restore(struct rte_eth_dev *dev)
5613 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5614 struct e1000_filter_info *filter_info =
5615 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5618 synqf = filter_info->syn_info;
5620 if (synqf & E1000_SYN_FILTER_ENABLE) {
5621 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
5622 E1000_WRITE_FLUSH(hw);
5626 /* restore ethernet type filter */
5628 igb_ethertype_filter_restore(struct rte_eth_dev *dev)
5630 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5631 struct e1000_filter_info *filter_info =
5632 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5635 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
5636 if (filter_info->ethertype_mask & (1 << i)) {
5637 E1000_WRITE_REG(hw, E1000_ETQF(i),
5638 filter_info->ethertype_filters[i].etqf);
5639 E1000_WRITE_FLUSH(hw);
5644 /* restore flex byte filter */
5646 igb_flex_filter_restore(struct rte_eth_dev *dev)
5648 struct e1000_filter_info *filter_info =
5649 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5650 struct e1000_flex_filter *flex_filter;
5652 TAILQ_FOREACH(flex_filter, &filter_info->flex_list, entries) {
5653 igb_inject_flex_filter(dev, flex_filter);
5657 /* restore rss filter */
5659 igb_rss_filter_restore(struct rte_eth_dev *dev)
5661 struct e1000_filter_info *filter_info =
5662 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5664 if (filter_info->rss_info.conf.queue_num)
5665 igb_config_rss_filter(dev, &filter_info->rss_info, TRUE);
5668 /* restore all types filter */
5670 igb_filter_restore(struct rte_eth_dev *dev)
5672 igb_ntuple_filter_restore(dev);
5673 igb_ethertype_filter_restore(dev);
5674 igb_syn_filter_restore(dev);
5675 igb_flex_filter_restore(dev);
5676 igb_rss_filter_restore(dev);
5681 RTE_PMD_REGISTER_PCI(net_e1000_igb, rte_igb_pmd);
5682 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb, pci_id_igb_map);
5683 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb, "* igb_uio | uio_pci_generic | vfio-pci");
5684 RTE_PMD_REGISTER_PCI(net_e1000_igb_vf, rte_igbvf_pmd);
5685 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb_vf, pci_id_igbvf_map);
5686 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb_vf, "* igb_uio | vfio-pci");
5688 /* see e1000_logs.c */
5689 RTE_INIT(e1000_init_log);
5691 e1000_init_log(void)
5693 e1000_igb_init_log();