4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/queue.h>
40 #include <rte_common.h>
41 #include <rte_interrupts.h>
42 #include <rte_byteorder.h>
44 #include <rte_debug.h>
46 #include <rte_ether.h>
47 #include <rte_ethdev.h>
48 #include <rte_ethdev_pci.h>
49 #include <rte_memory.h>
50 #include <rte_memzone.h>
52 #include <rte_atomic.h>
53 #include <rte_malloc.h>
56 #include "e1000_logs.h"
57 #include "base/e1000_api.h"
58 #include "e1000_ethdev.h"
62 * Default values for port configuration
64 #define IGB_DEFAULT_RX_FREE_THRESH 32
66 #define IGB_DEFAULT_RX_PTHRESH ((hw->mac.type == e1000_i354) ? 12 : 8)
67 #define IGB_DEFAULT_RX_HTHRESH 8
68 #define IGB_DEFAULT_RX_WTHRESH ((hw->mac.type == e1000_82576) ? 1 : 4)
70 #define IGB_DEFAULT_TX_PTHRESH ((hw->mac.type == e1000_i354) ? 20 : 8)
71 #define IGB_DEFAULT_TX_HTHRESH 1
72 #define IGB_DEFAULT_TX_WTHRESH ((hw->mac.type == e1000_82576) ? 1 : 16)
74 #define IGB_HKEY_MAX_INDEX 10
76 /* Bit shift and mask */
77 #define IGB_4_BIT_WIDTH (CHAR_BIT / 2)
78 #define IGB_4_BIT_MASK RTE_LEN2MASK(IGB_4_BIT_WIDTH, uint8_t)
79 #define IGB_8_BIT_WIDTH CHAR_BIT
80 #define IGB_8_BIT_MASK UINT8_MAX
82 /* Additional timesync values. */
83 #define E1000_CYCLECOUNTER_MASK 0xffffffffffffffffULL
84 #define E1000_ETQF_FILTER_1588 3
85 #define IGB_82576_TSYNC_SHIFT 16
86 #define E1000_INCPERIOD_82576 (1 << E1000_TIMINCA_16NS_SHIFT)
87 #define E1000_INCVALUE_82576 (16 << IGB_82576_TSYNC_SHIFT)
88 #define E1000_TSAUXC_DISABLE_SYSTIME 0x80000000
90 #define E1000_VTIVAR_MISC 0x01740
91 #define E1000_VTIVAR_MISC_MASK 0xFF
92 #define E1000_VTIVAR_VALID 0x80
93 #define E1000_VTIVAR_MISC_MAILBOX 0
94 #define E1000_VTIVAR_MISC_INTR_MASK 0x3
96 /* External VLAN Enable bit mask */
97 #define E1000_CTRL_EXT_EXT_VLAN (1 << 26)
99 /* External VLAN Ether Type bit mask and shift */
100 #define E1000_VET_VET_EXT 0xFFFF0000
101 #define E1000_VET_VET_EXT_SHIFT 16
103 static int eth_igb_configure(struct rte_eth_dev *dev);
104 static int eth_igb_start(struct rte_eth_dev *dev);
105 static void eth_igb_stop(struct rte_eth_dev *dev);
106 static int eth_igb_dev_set_link_up(struct rte_eth_dev *dev);
107 static int eth_igb_dev_set_link_down(struct rte_eth_dev *dev);
108 static void eth_igb_close(struct rte_eth_dev *dev);
109 static void eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
110 static void eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
111 static void eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
112 static void eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
113 static int eth_igb_link_update(struct rte_eth_dev *dev,
114 int wait_to_complete);
115 static void eth_igb_stats_get(struct rte_eth_dev *dev,
116 struct rte_eth_stats *rte_stats);
117 static int eth_igb_xstats_get(struct rte_eth_dev *dev,
118 struct rte_eth_xstat *xstats, unsigned n);
119 static int eth_igb_xstats_get_by_id(struct rte_eth_dev *dev,
121 uint64_t *values, unsigned int n);
122 static int eth_igb_xstats_get_names(struct rte_eth_dev *dev,
123 struct rte_eth_xstat_name *xstats_names,
125 static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
126 struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
128 static void eth_igb_stats_reset(struct rte_eth_dev *dev);
129 static void eth_igb_xstats_reset(struct rte_eth_dev *dev);
130 static int eth_igb_fw_version_get(struct rte_eth_dev *dev,
131 char *fw_version, size_t fw_size);
132 static void eth_igb_infos_get(struct rte_eth_dev *dev,
133 struct rte_eth_dev_info *dev_info);
134 static const uint32_t *eth_igb_supported_ptypes_get(struct rte_eth_dev *dev);
135 static void eth_igbvf_infos_get(struct rte_eth_dev *dev,
136 struct rte_eth_dev_info *dev_info);
137 static int eth_igb_flow_ctrl_get(struct rte_eth_dev *dev,
138 struct rte_eth_fc_conf *fc_conf);
139 static int eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
140 struct rte_eth_fc_conf *fc_conf);
141 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev);
142 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
143 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
144 static int eth_igb_interrupt_action(struct rte_eth_dev *dev,
145 struct rte_intr_handle *handle);
146 static void eth_igb_interrupt_handler(void *param);
147 static int igb_hardware_init(struct e1000_hw *hw);
148 static void igb_hw_control_acquire(struct e1000_hw *hw);
149 static void igb_hw_control_release(struct e1000_hw *hw);
150 static void igb_init_manageability(struct e1000_hw *hw);
151 static void igb_release_manageability(struct e1000_hw *hw);
153 static int eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
155 static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
156 uint16_t vlan_id, int on);
157 static int eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
158 enum rte_vlan_type vlan_type,
160 static void eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
162 static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
163 static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
164 static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
165 static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
166 static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
167 static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
169 static int eth_igb_led_on(struct rte_eth_dev *dev);
170 static int eth_igb_led_off(struct rte_eth_dev *dev);
172 static void igb_intr_disable(struct e1000_hw *hw);
173 static int igb_get_rx_buffer_size(struct e1000_hw *hw);
174 static int eth_igb_rar_set(struct rte_eth_dev *dev,
175 struct ether_addr *mac_addr,
176 uint32_t index, uint32_t pool);
177 static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
178 static void eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
179 struct ether_addr *addr);
181 static void igbvf_intr_disable(struct e1000_hw *hw);
182 static int igbvf_dev_configure(struct rte_eth_dev *dev);
183 static int igbvf_dev_start(struct rte_eth_dev *dev);
184 static void igbvf_dev_stop(struct rte_eth_dev *dev);
185 static void igbvf_dev_close(struct rte_eth_dev *dev);
186 static void igbvf_promiscuous_enable(struct rte_eth_dev *dev);
187 static void igbvf_promiscuous_disable(struct rte_eth_dev *dev);
188 static void igbvf_allmulticast_enable(struct rte_eth_dev *dev);
189 static void igbvf_allmulticast_disable(struct rte_eth_dev *dev);
190 static int eth_igbvf_link_update(struct e1000_hw *hw);
191 static void eth_igbvf_stats_get(struct rte_eth_dev *dev,
192 struct rte_eth_stats *rte_stats);
193 static int eth_igbvf_xstats_get(struct rte_eth_dev *dev,
194 struct rte_eth_xstat *xstats, unsigned n);
195 static int eth_igbvf_xstats_get_names(struct rte_eth_dev *dev,
196 struct rte_eth_xstat_name *xstats_names,
198 static void eth_igbvf_stats_reset(struct rte_eth_dev *dev);
199 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
200 uint16_t vlan_id, int on);
201 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
202 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
203 static void igbvf_default_mac_addr_set(struct rte_eth_dev *dev,
204 struct ether_addr *addr);
205 static int igbvf_get_reg_length(struct rte_eth_dev *dev);
206 static int igbvf_get_regs(struct rte_eth_dev *dev,
207 struct rte_dev_reg_info *regs);
209 static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
210 struct rte_eth_rss_reta_entry64 *reta_conf,
212 static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
213 struct rte_eth_rss_reta_entry64 *reta_conf,
216 static int eth_igb_syn_filter_get(struct rte_eth_dev *dev,
217 struct rte_eth_syn_filter *filter);
218 static int eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
219 enum rte_filter_op filter_op,
221 static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
222 struct rte_eth_ntuple_filter *ntuple_filter);
223 static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
224 struct rte_eth_ntuple_filter *ntuple_filter);
225 static int eth_igb_get_flex_filter(struct rte_eth_dev *dev,
226 struct rte_eth_flex_filter *filter);
227 static int eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
228 enum rte_filter_op filter_op,
230 static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
231 struct rte_eth_ntuple_filter *ntuple_filter);
232 static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
233 struct rte_eth_ntuple_filter *ntuple_filter);
234 static int igb_get_ntuple_filter(struct rte_eth_dev *dev,
235 struct rte_eth_ntuple_filter *filter);
236 static int igb_ntuple_filter_handle(struct rte_eth_dev *dev,
237 enum rte_filter_op filter_op,
239 static int igb_ethertype_filter_handle(struct rte_eth_dev *dev,
240 enum rte_filter_op filter_op,
242 static int igb_get_ethertype_filter(struct rte_eth_dev *dev,
243 struct rte_eth_ethertype_filter *filter);
244 static int eth_igb_filter_ctrl(struct rte_eth_dev *dev,
245 enum rte_filter_type filter_type,
246 enum rte_filter_op filter_op,
248 static int eth_igb_get_reg_length(struct rte_eth_dev *dev);
249 static int eth_igb_get_regs(struct rte_eth_dev *dev,
250 struct rte_dev_reg_info *regs);
251 static int eth_igb_get_eeprom_length(struct rte_eth_dev *dev);
252 static int eth_igb_get_eeprom(struct rte_eth_dev *dev,
253 struct rte_dev_eeprom_info *eeprom);
254 static int eth_igb_set_eeprom(struct rte_eth_dev *dev,
255 struct rte_dev_eeprom_info *eeprom);
256 static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
257 struct ether_addr *mc_addr_set,
258 uint32_t nb_mc_addr);
259 static int igb_timesync_enable(struct rte_eth_dev *dev);
260 static int igb_timesync_disable(struct rte_eth_dev *dev);
261 static int igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
262 struct timespec *timestamp,
264 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
265 struct timespec *timestamp);
266 static int igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
267 static int igb_timesync_read_time(struct rte_eth_dev *dev,
268 struct timespec *timestamp);
269 static int igb_timesync_write_time(struct rte_eth_dev *dev,
270 const struct timespec *timestamp);
271 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
273 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
275 static void eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
276 uint8_t queue, uint8_t msix_vector);
277 static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
278 uint8_t index, uint8_t offset);
279 static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
280 static void eth_igbvf_interrupt_handler(void *param);
281 static void igbvf_mbx_process(struct rte_eth_dev *dev);
282 static int igb_filter_restore(struct rte_eth_dev *dev);
285 * Define VF Stats MACRO for Non "cleared on read" register
287 #define UPDATE_VF_STAT(reg, last, cur) \
289 u32 latest = E1000_READ_REG(hw, reg); \
290 cur += (latest - last) & UINT_MAX; \
294 #define IGB_FC_PAUSE_TIME 0x0680
295 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
296 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
298 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
300 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
303 * The set of PCI devices this driver supports
305 static const struct rte_pci_id pci_id_igb_map[] = {
306 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576) },
307 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_FIBER) },
308 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES) },
309 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER) },
310 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER_ET2) },
311 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS) },
312 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS_SERDES) },
313 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES_QUAD) },
315 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_COPPER) },
316 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_FIBER_SERDES) },
317 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575GB_QUAD_COPPER) },
319 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER) },
320 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_FIBER) },
321 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SERDES) },
322 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SGMII) },
323 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER_DUAL) },
324 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_QUAD_FIBER) },
326 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_COPPER) },
327 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_FIBER) },
328 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SERDES) },
329 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SGMII) },
330 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_DA4) },
331 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER) },
332 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_OEM1) },
333 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_IT) },
334 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_FIBER) },
335 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES) },
336 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SGMII) },
337 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I211_COPPER) },
338 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
339 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_SGMII) },
340 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
341 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SGMII) },
342 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SERDES) },
343 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_BACKPLANE) },
344 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SFP) },
345 { .vendor_id = 0, /* sentinel */ },
349 * The set of PCI devices this driver supports (for 82576&I350 VF)
351 static const struct rte_pci_id pci_id_igbvf_map[] = {
352 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF) },
353 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF_HV) },
354 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF) },
355 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF_HV) },
356 { .vendor_id = 0, /* sentinel */ },
359 static const struct rte_eth_desc_lim rx_desc_lim = {
360 .nb_max = E1000_MAX_RING_DESC,
361 .nb_min = E1000_MIN_RING_DESC,
362 .nb_align = IGB_RXD_ALIGN,
365 static const struct rte_eth_desc_lim tx_desc_lim = {
366 .nb_max = E1000_MAX_RING_DESC,
367 .nb_min = E1000_MIN_RING_DESC,
368 .nb_align = IGB_RXD_ALIGN,
369 .nb_seg_max = IGB_TX_MAX_SEG,
370 .nb_mtu_seg_max = IGB_TX_MAX_MTU_SEG,
373 static const struct eth_dev_ops eth_igb_ops = {
374 .dev_configure = eth_igb_configure,
375 .dev_start = eth_igb_start,
376 .dev_stop = eth_igb_stop,
377 .dev_set_link_up = eth_igb_dev_set_link_up,
378 .dev_set_link_down = eth_igb_dev_set_link_down,
379 .dev_close = eth_igb_close,
380 .promiscuous_enable = eth_igb_promiscuous_enable,
381 .promiscuous_disable = eth_igb_promiscuous_disable,
382 .allmulticast_enable = eth_igb_allmulticast_enable,
383 .allmulticast_disable = eth_igb_allmulticast_disable,
384 .link_update = eth_igb_link_update,
385 .stats_get = eth_igb_stats_get,
386 .xstats_get = eth_igb_xstats_get,
387 .xstats_get_by_id = eth_igb_xstats_get_by_id,
388 .xstats_get_names_by_id = eth_igb_xstats_get_names_by_id,
389 .xstats_get_names = eth_igb_xstats_get_names,
390 .stats_reset = eth_igb_stats_reset,
391 .xstats_reset = eth_igb_xstats_reset,
392 .fw_version_get = eth_igb_fw_version_get,
393 .dev_infos_get = eth_igb_infos_get,
394 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
395 .mtu_set = eth_igb_mtu_set,
396 .vlan_filter_set = eth_igb_vlan_filter_set,
397 .vlan_tpid_set = eth_igb_vlan_tpid_set,
398 .vlan_offload_set = eth_igb_vlan_offload_set,
399 .rx_queue_setup = eth_igb_rx_queue_setup,
400 .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
401 .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
402 .rx_queue_release = eth_igb_rx_queue_release,
403 .rx_queue_count = eth_igb_rx_queue_count,
404 .rx_descriptor_done = eth_igb_rx_descriptor_done,
405 .rx_descriptor_status = eth_igb_rx_descriptor_status,
406 .tx_descriptor_status = eth_igb_tx_descriptor_status,
407 .tx_queue_setup = eth_igb_tx_queue_setup,
408 .tx_queue_release = eth_igb_tx_queue_release,
409 .tx_done_cleanup = eth_igb_tx_done_cleanup,
410 .dev_led_on = eth_igb_led_on,
411 .dev_led_off = eth_igb_led_off,
412 .flow_ctrl_get = eth_igb_flow_ctrl_get,
413 .flow_ctrl_set = eth_igb_flow_ctrl_set,
414 .mac_addr_add = eth_igb_rar_set,
415 .mac_addr_remove = eth_igb_rar_clear,
416 .mac_addr_set = eth_igb_default_mac_addr_set,
417 .reta_update = eth_igb_rss_reta_update,
418 .reta_query = eth_igb_rss_reta_query,
419 .rss_hash_update = eth_igb_rss_hash_update,
420 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
421 .filter_ctrl = eth_igb_filter_ctrl,
422 .set_mc_addr_list = eth_igb_set_mc_addr_list,
423 .rxq_info_get = igb_rxq_info_get,
424 .txq_info_get = igb_txq_info_get,
425 .timesync_enable = igb_timesync_enable,
426 .timesync_disable = igb_timesync_disable,
427 .timesync_read_rx_timestamp = igb_timesync_read_rx_timestamp,
428 .timesync_read_tx_timestamp = igb_timesync_read_tx_timestamp,
429 .get_reg = eth_igb_get_regs,
430 .get_eeprom_length = eth_igb_get_eeprom_length,
431 .get_eeprom = eth_igb_get_eeprom,
432 .set_eeprom = eth_igb_set_eeprom,
433 .timesync_adjust_time = igb_timesync_adjust_time,
434 .timesync_read_time = igb_timesync_read_time,
435 .timesync_write_time = igb_timesync_write_time,
439 * dev_ops for virtual function, bare necessities for basic vf
440 * operation have been implemented
442 static const struct eth_dev_ops igbvf_eth_dev_ops = {
443 .dev_configure = igbvf_dev_configure,
444 .dev_start = igbvf_dev_start,
445 .dev_stop = igbvf_dev_stop,
446 .dev_close = igbvf_dev_close,
447 .promiscuous_enable = igbvf_promiscuous_enable,
448 .promiscuous_disable = igbvf_promiscuous_disable,
449 .allmulticast_enable = igbvf_allmulticast_enable,
450 .allmulticast_disable = igbvf_allmulticast_disable,
451 .link_update = eth_igb_link_update,
452 .stats_get = eth_igbvf_stats_get,
453 .xstats_get = eth_igbvf_xstats_get,
454 .xstats_get_names = eth_igbvf_xstats_get_names,
455 .stats_reset = eth_igbvf_stats_reset,
456 .xstats_reset = eth_igbvf_stats_reset,
457 .vlan_filter_set = igbvf_vlan_filter_set,
458 .dev_infos_get = eth_igbvf_infos_get,
459 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
460 .rx_queue_setup = eth_igb_rx_queue_setup,
461 .rx_queue_release = eth_igb_rx_queue_release,
462 .tx_queue_setup = eth_igb_tx_queue_setup,
463 .tx_queue_release = eth_igb_tx_queue_release,
464 .set_mc_addr_list = eth_igb_set_mc_addr_list,
465 .rxq_info_get = igb_rxq_info_get,
466 .txq_info_get = igb_txq_info_get,
467 .mac_addr_set = igbvf_default_mac_addr_set,
468 .get_reg = igbvf_get_regs,
471 /* store statistics names and its offset in stats structure */
472 struct rte_igb_xstats_name_off {
473 char name[RTE_ETH_XSTATS_NAME_SIZE];
477 static const struct rte_igb_xstats_name_off rte_igb_stats_strings[] = {
478 {"rx_crc_errors", offsetof(struct e1000_hw_stats, crcerrs)},
479 {"rx_align_errors", offsetof(struct e1000_hw_stats, algnerrc)},
480 {"rx_symbol_errors", offsetof(struct e1000_hw_stats, symerrs)},
481 {"rx_missed_packets", offsetof(struct e1000_hw_stats, mpc)},
482 {"tx_single_collision_packets", offsetof(struct e1000_hw_stats, scc)},
483 {"tx_multiple_collision_packets", offsetof(struct e1000_hw_stats, mcc)},
484 {"tx_excessive_collision_packets", offsetof(struct e1000_hw_stats,
486 {"tx_late_collisions", offsetof(struct e1000_hw_stats, latecol)},
487 {"tx_total_collisions", offsetof(struct e1000_hw_stats, colc)},
488 {"tx_deferred_packets", offsetof(struct e1000_hw_stats, dc)},
489 {"tx_no_carrier_sense_packets", offsetof(struct e1000_hw_stats, tncrs)},
490 {"rx_carrier_ext_errors", offsetof(struct e1000_hw_stats, cexterr)},
491 {"rx_length_errors", offsetof(struct e1000_hw_stats, rlec)},
492 {"rx_xon_packets", offsetof(struct e1000_hw_stats, xonrxc)},
493 {"tx_xon_packets", offsetof(struct e1000_hw_stats, xontxc)},
494 {"rx_xoff_packets", offsetof(struct e1000_hw_stats, xoffrxc)},
495 {"tx_xoff_packets", offsetof(struct e1000_hw_stats, xofftxc)},
496 {"rx_flow_control_unsupported_packets", offsetof(struct e1000_hw_stats,
498 {"rx_size_64_packets", offsetof(struct e1000_hw_stats, prc64)},
499 {"rx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, prc127)},
500 {"rx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, prc255)},
501 {"rx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, prc511)},
502 {"rx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
504 {"rx_size_1024_to_max_packets", offsetof(struct e1000_hw_stats,
506 {"rx_broadcast_packets", offsetof(struct e1000_hw_stats, bprc)},
507 {"rx_multicast_packets", offsetof(struct e1000_hw_stats, mprc)},
508 {"rx_undersize_errors", offsetof(struct e1000_hw_stats, ruc)},
509 {"rx_fragment_errors", offsetof(struct e1000_hw_stats, rfc)},
510 {"rx_oversize_errors", offsetof(struct e1000_hw_stats, roc)},
511 {"rx_jabber_errors", offsetof(struct e1000_hw_stats, rjc)},
512 {"rx_management_packets", offsetof(struct e1000_hw_stats, mgprc)},
513 {"rx_management_dropped", offsetof(struct e1000_hw_stats, mgpdc)},
514 {"tx_management_packets", offsetof(struct e1000_hw_stats, mgptc)},
515 {"rx_total_packets", offsetof(struct e1000_hw_stats, tpr)},
516 {"tx_total_packets", offsetof(struct e1000_hw_stats, tpt)},
517 {"rx_total_bytes", offsetof(struct e1000_hw_stats, tor)},
518 {"tx_total_bytes", offsetof(struct e1000_hw_stats, tot)},
519 {"tx_size_64_packets", offsetof(struct e1000_hw_stats, ptc64)},
520 {"tx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, ptc127)},
521 {"tx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, ptc255)},
522 {"tx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, ptc511)},
523 {"tx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
525 {"tx_size_1023_to_max_packets", offsetof(struct e1000_hw_stats,
527 {"tx_multicast_packets", offsetof(struct e1000_hw_stats, mptc)},
528 {"tx_broadcast_packets", offsetof(struct e1000_hw_stats, bptc)},
529 {"tx_tso_packets", offsetof(struct e1000_hw_stats, tsctc)},
530 {"tx_tso_errors", offsetof(struct e1000_hw_stats, tsctfc)},
531 {"rx_sent_to_host_packets", offsetof(struct e1000_hw_stats, rpthc)},
532 {"tx_sent_by_host_packets", offsetof(struct e1000_hw_stats, hgptc)},
533 {"rx_code_violation_packets", offsetof(struct e1000_hw_stats, scvpc)},
535 {"interrupt_assert_count", offsetof(struct e1000_hw_stats, iac)},
538 #define IGB_NB_XSTATS (sizeof(rte_igb_stats_strings) / \
539 sizeof(rte_igb_stats_strings[0]))
541 static const struct rte_igb_xstats_name_off rte_igbvf_stats_strings[] = {
542 {"rx_multicast_packets", offsetof(struct e1000_vf_stats, mprc)},
543 {"rx_good_loopback_packets", offsetof(struct e1000_vf_stats, gprlbc)},
544 {"tx_good_loopback_packets", offsetof(struct e1000_vf_stats, gptlbc)},
545 {"rx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gorlbc)},
546 {"tx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gotlbc)},
549 #define IGBVF_NB_XSTATS (sizeof(rte_igbvf_stats_strings) / \
550 sizeof(rte_igbvf_stats_strings[0]))
553 * Atomically reads the link status information from global
554 * structure rte_eth_dev.
557 * - Pointer to the structure rte_eth_dev to read from.
558 * - Pointer to the buffer to be saved with the link status.
561 * - On success, zero.
562 * - On failure, negative value.
565 rte_igb_dev_atomic_read_link_status(struct rte_eth_dev *dev,
566 struct rte_eth_link *link)
568 struct rte_eth_link *dst = link;
569 struct rte_eth_link *src = &(dev->data->dev_link);
571 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
572 *(uint64_t *)src) == 0)
579 * Atomically writes the link status information into global
580 * structure rte_eth_dev.
583 * - Pointer to the structure rte_eth_dev to read from.
584 * - Pointer to the buffer to be saved with the link status.
587 * - On success, zero.
588 * - On failure, negative value.
591 rte_igb_dev_atomic_write_link_status(struct rte_eth_dev *dev,
592 struct rte_eth_link *link)
594 struct rte_eth_link *dst = &(dev->data->dev_link);
595 struct rte_eth_link *src = link;
597 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
598 *(uint64_t *)src) == 0)
605 igb_intr_enable(struct rte_eth_dev *dev)
607 struct e1000_interrupt *intr =
608 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
609 struct e1000_hw *hw =
610 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
612 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
613 E1000_WRITE_FLUSH(hw);
617 igb_intr_disable(struct e1000_hw *hw)
619 E1000_WRITE_REG(hw, E1000_IMC, ~0);
620 E1000_WRITE_FLUSH(hw);
624 igbvf_intr_enable(struct rte_eth_dev *dev)
626 struct e1000_hw *hw =
627 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
629 /* only for mailbox */
630 E1000_WRITE_REG(hw, E1000_EIAM, 1 << E1000_VTIVAR_MISC_MAILBOX);
631 E1000_WRITE_REG(hw, E1000_EIAC, 1 << E1000_VTIVAR_MISC_MAILBOX);
632 E1000_WRITE_REG(hw, E1000_EIMS, 1 << E1000_VTIVAR_MISC_MAILBOX);
633 E1000_WRITE_FLUSH(hw);
636 /* only for mailbox now. If RX/TX needed, should extend this function. */
638 igbvf_set_ivar_map(struct e1000_hw *hw, uint8_t msix_vector)
643 tmp |= (msix_vector & E1000_VTIVAR_MISC_INTR_MASK);
644 tmp |= E1000_VTIVAR_VALID;
645 E1000_WRITE_REG(hw, E1000_VTIVAR_MISC, tmp);
649 eth_igbvf_configure_msix_intr(struct rte_eth_dev *dev)
651 struct e1000_hw *hw =
652 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
654 /* Configure VF other cause ivar */
655 igbvf_set_ivar_map(hw, E1000_VTIVAR_MISC_MAILBOX);
658 static inline int32_t
659 igb_pf_reset_hw(struct e1000_hw *hw)
664 status = e1000_reset_hw(hw);
666 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
667 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
668 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
669 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
670 E1000_WRITE_FLUSH(hw);
676 igb_identify_hardware(struct rte_eth_dev *dev, struct rte_pci_device *pci_dev)
678 struct e1000_hw *hw =
679 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
682 hw->vendor_id = pci_dev->id.vendor_id;
683 hw->device_id = pci_dev->id.device_id;
684 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
685 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
687 e1000_set_mac_type(hw);
689 /* need to check if it is a vf device below */
693 igb_reset_swfw_lock(struct e1000_hw *hw)
698 * Do mac ops initialization manually here, since we will need
699 * some function pointers set by this call.
701 ret_val = e1000_init_mac_params(hw);
706 * SMBI lock should not fail in this early stage. If this is the case,
707 * it is due to an improper exit of the application.
708 * So force the release of the faulty lock.
710 if (e1000_get_hw_semaphore_generic(hw) < 0) {
711 PMD_DRV_LOG(DEBUG, "SMBI lock released");
713 e1000_put_hw_semaphore_generic(hw);
715 if (hw->mac.ops.acquire_swfw_sync != NULL) {
719 * Phy lock should not fail in this early stage. If this is the case,
720 * it is due to an improper exit of the application.
721 * So force the release of the faulty lock.
723 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
724 if (hw->bus.func > E1000_FUNC_1)
726 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
727 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
730 hw->mac.ops.release_swfw_sync(hw, mask);
733 * This one is more tricky since it is common to all ports; but
734 * swfw_sync retries last long enough (1s) to be almost sure that if
735 * lock can not be taken it is due to an improper lock of the
738 mask = E1000_SWFW_EEP_SM;
739 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
740 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
742 hw->mac.ops.release_swfw_sync(hw, mask);
745 return E1000_SUCCESS;
748 /* Remove all ntuple filters of the device */
749 static int igb_ntuple_filter_uninit(struct rte_eth_dev *eth_dev)
751 struct e1000_filter_info *filter_info =
752 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
753 struct e1000_5tuple_filter *p_5tuple;
754 struct e1000_2tuple_filter *p_2tuple;
756 while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list))) {
757 TAILQ_REMOVE(&filter_info->fivetuple_list,
761 filter_info->fivetuple_mask = 0;
762 while ((p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list))) {
763 TAILQ_REMOVE(&filter_info->twotuple_list,
767 filter_info->twotuple_mask = 0;
772 /* Remove all flex filters of the device */
773 static int igb_flex_filter_uninit(struct rte_eth_dev *eth_dev)
775 struct e1000_filter_info *filter_info =
776 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
777 struct e1000_flex_filter *p_flex;
779 while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
780 TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
783 filter_info->flex_mask = 0;
789 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
792 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
793 struct e1000_hw *hw =
794 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
795 struct e1000_vfta * shadow_vfta =
796 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
797 struct e1000_filter_info *filter_info =
798 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
799 struct e1000_adapter *adapter =
800 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
804 eth_dev->dev_ops = ð_igb_ops;
805 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
806 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
807 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
809 /* for secondary processes, we don't initialise any further as primary
810 * has already done this work. Only check we don't need a different
812 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
813 if (eth_dev->data->scattered_rx)
814 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
818 rte_eth_copy_pci_info(eth_dev, pci_dev);
819 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
821 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
823 igb_identify_hardware(eth_dev, pci_dev);
824 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
829 e1000_get_bus_info(hw);
831 /* Reset any pending lock */
832 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
837 /* Finish initialization */
838 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
844 hw->phy.autoneg_wait_to_complete = 0;
845 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
848 if (hw->phy.media_type == e1000_media_type_copper) {
849 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
850 hw->phy.disable_polarity_correction = 0;
851 hw->phy.ms_type = e1000_ms_hw_default;
855 * Start from a known state, this is important in reading the nvm
860 /* Make sure we have a good EEPROM before we read from it */
861 if (e1000_validate_nvm_checksum(hw) < 0) {
863 * Some PCI-E parts fail the first check due to
864 * the link being in sleep state, call it again,
865 * if it fails a second time its a real issue.
867 if (e1000_validate_nvm_checksum(hw) < 0) {
868 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
874 /* Read the permanent MAC address out of the EEPROM */
875 if (e1000_read_mac_addr(hw) != 0) {
876 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
881 /* Allocate memory for storing MAC addresses */
882 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
883 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
884 if (eth_dev->data->mac_addrs == NULL) {
885 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
886 "store MAC addresses",
887 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
892 /* Copy the permanent MAC address */
893 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
895 /* initialize the vfta */
896 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
898 /* Now initialize the hardware */
899 if (igb_hardware_init(hw) != 0) {
900 PMD_INIT_LOG(ERR, "Hardware initialization failed");
901 rte_free(eth_dev->data->mac_addrs);
902 eth_dev->data->mac_addrs = NULL;
906 hw->mac.get_link_status = 1;
907 adapter->stopped = 0;
909 /* Indicate SOL/IDER usage */
910 if (e1000_check_reset_block(hw) < 0) {
911 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
915 /* initialize PF if max_vfs not zero */
916 igb_pf_host_init(eth_dev);
918 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
919 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
920 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
921 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
922 E1000_WRITE_FLUSH(hw);
924 PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
925 eth_dev->data->port_id, pci_dev->id.vendor_id,
926 pci_dev->id.device_id);
928 rte_intr_callback_register(&pci_dev->intr_handle,
929 eth_igb_interrupt_handler,
932 /* enable uio/vfio intr/eventfd mapping */
933 rte_intr_enable(&pci_dev->intr_handle);
935 /* enable support intr */
936 igb_intr_enable(eth_dev);
938 /* initialize filter info */
939 memset(filter_info, 0,
940 sizeof(struct e1000_filter_info));
942 TAILQ_INIT(&filter_info->flex_list);
943 TAILQ_INIT(&filter_info->twotuple_list);
944 TAILQ_INIT(&filter_info->fivetuple_list);
946 TAILQ_INIT(&igb_filter_ntuple_list);
947 TAILQ_INIT(&igb_filter_ethertype_list);
948 TAILQ_INIT(&igb_filter_syn_list);
949 TAILQ_INIT(&igb_filter_flex_list);
950 TAILQ_INIT(&igb_flow_list);
955 igb_hw_control_release(hw);
961 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
963 struct rte_pci_device *pci_dev;
964 struct rte_intr_handle *intr_handle;
966 struct e1000_adapter *adapter =
967 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
968 struct e1000_filter_info *filter_info =
969 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
971 PMD_INIT_FUNC_TRACE();
973 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
976 hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
977 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
978 intr_handle = &pci_dev->intr_handle;
980 if (adapter->stopped == 0)
981 eth_igb_close(eth_dev);
983 eth_dev->dev_ops = NULL;
984 eth_dev->rx_pkt_burst = NULL;
985 eth_dev->tx_pkt_burst = NULL;
987 /* Reset any pending lock */
988 igb_reset_swfw_lock(hw);
990 rte_free(eth_dev->data->mac_addrs);
991 eth_dev->data->mac_addrs = NULL;
993 /* uninitialize PF if max_vfs not zero */
994 igb_pf_host_uninit(eth_dev);
996 /* disable uio intr before callback unregister */
997 rte_intr_disable(intr_handle);
998 rte_intr_callback_unregister(intr_handle,
999 eth_igb_interrupt_handler, eth_dev);
1001 /* clear the SYN filter info */
1002 filter_info->syn_info = 0;
1004 /* clear the ethertype filters info */
1005 filter_info->ethertype_mask = 0;
1006 memset(filter_info->ethertype_filters, 0,
1007 E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
1009 /* remove all ntuple filters of the device */
1010 igb_ntuple_filter_uninit(eth_dev);
1012 /* remove all flex filters of the device */
1013 igb_flex_filter_uninit(eth_dev);
1019 * Virtual Function device init
1022 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
1024 struct rte_pci_device *pci_dev;
1025 struct rte_intr_handle *intr_handle;
1026 struct e1000_adapter *adapter =
1027 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
1028 struct e1000_hw *hw =
1029 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1031 struct ether_addr *perm_addr = (struct ether_addr *)hw->mac.perm_addr;
1033 PMD_INIT_FUNC_TRACE();
1035 eth_dev->dev_ops = &igbvf_eth_dev_ops;
1036 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
1037 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
1038 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
1040 /* for secondary processes, we don't initialise any further as primary
1041 * has already done this work. Only check we don't need a different
1043 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1044 if (eth_dev->data->scattered_rx)
1045 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
1049 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1050 rte_eth_copy_pci_info(eth_dev, pci_dev);
1051 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1053 hw->device_id = pci_dev->id.device_id;
1054 hw->vendor_id = pci_dev->id.vendor_id;
1055 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1056 adapter->stopped = 0;
1058 /* Initialize the shared code (base driver) */
1059 diag = e1000_setup_init_funcs(hw, TRUE);
1061 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
1066 /* init_mailbox_params */
1067 hw->mbx.ops.init_params(hw);
1069 /* Disable the interrupts for VF */
1070 igbvf_intr_disable(hw);
1072 diag = hw->mac.ops.reset_hw(hw);
1074 /* Allocate memory for storing MAC addresses */
1075 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
1076 hw->mac.rar_entry_count, 0);
1077 if (eth_dev->data->mac_addrs == NULL) {
1079 "Failed to allocate %d bytes needed to store MAC "
1081 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
1085 /* Generate a random MAC address, if none was assigned by PF. */
1086 if (is_zero_ether_addr(perm_addr)) {
1087 eth_random_addr(perm_addr->addr_bytes);
1088 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1089 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1090 "%02x:%02x:%02x:%02x:%02x:%02x",
1091 perm_addr->addr_bytes[0],
1092 perm_addr->addr_bytes[1],
1093 perm_addr->addr_bytes[2],
1094 perm_addr->addr_bytes[3],
1095 perm_addr->addr_bytes[4],
1096 perm_addr->addr_bytes[5]);
1099 diag = e1000_rar_set(hw, perm_addr->addr_bytes, 0);
1101 rte_free(eth_dev->data->mac_addrs);
1102 eth_dev->data->mac_addrs = NULL;
1105 /* Copy the permanent MAC address */
1106 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
1107 ð_dev->data->mac_addrs[0]);
1109 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
1111 eth_dev->data->port_id, pci_dev->id.vendor_id,
1112 pci_dev->id.device_id, "igb_mac_82576_vf");
1114 intr_handle = &pci_dev->intr_handle;
1115 rte_intr_callback_register(intr_handle,
1116 eth_igbvf_interrupt_handler, eth_dev);
1122 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
1124 struct e1000_adapter *adapter =
1125 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
1126 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1128 PMD_INIT_FUNC_TRACE();
1130 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1133 if (adapter->stopped == 0)
1134 igbvf_dev_close(eth_dev);
1136 eth_dev->dev_ops = NULL;
1137 eth_dev->rx_pkt_burst = NULL;
1138 eth_dev->tx_pkt_burst = NULL;
1140 rte_free(eth_dev->data->mac_addrs);
1141 eth_dev->data->mac_addrs = NULL;
1143 /* disable uio intr before callback unregister */
1144 rte_intr_disable(&pci_dev->intr_handle);
1145 rte_intr_callback_unregister(&pci_dev->intr_handle,
1146 eth_igbvf_interrupt_handler,
1152 static int eth_igb_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1153 struct rte_pci_device *pci_dev)
1155 return rte_eth_dev_pci_generic_probe(pci_dev,
1156 sizeof(struct e1000_adapter), eth_igb_dev_init);
1159 static int eth_igb_pci_remove(struct rte_pci_device *pci_dev)
1161 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igb_dev_uninit);
1164 static struct rte_pci_driver rte_igb_pmd = {
1165 .id_table = pci_id_igb_map,
1166 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1167 .probe = eth_igb_pci_probe,
1168 .remove = eth_igb_pci_remove,
1172 static int eth_igbvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1173 struct rte_pci_device *pci_dev)
1175 return rte_eth_dev_pci_generic_probe(pci_dev,
1176 sizeof(struct e1000_adapter), eth_igbvf_dev_init);
1179 static int eth_igbvf_pci_remove(struct rte_pci_device *pci_dev)
1181 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igbvf_dev_uninit);
1185 * virtual function driver struct
1187 static struct rte_pci_driver rte_igbvf_pmd = {
1188 .id_table = pci_id_igbvf_map,
1189 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1190 .probe = eth_igbvf_pci_probe,
1191 .remove = eth_igbvf_pci_remove,
1195 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1197 struct e1000_hw *hw =
1198 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1199 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
1200 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
1201 rctl |= E1000_RCTL_VFE;
1202 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1206 igb_check_mq_mode(struct rte_eth_dev *dev)
1208 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1209 enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
1210 uint16_t nb_rx_q = dev->data->nb_rx_queues;
1211 uint16_t nb_tx_q = dev->data->nb_rx_queues;
1213 if ((rx_mq_mode & ETH_MQ_RX_DCB_FLAG) ||
1214 tx_mq_mode == ETH_MQ_TX_DCB ||
1215 tx_mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1216 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
1219 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
1220 /* Check multi-queue mode.
1221 * To no break software we accept ETH_MQ_RX_NONE as this might
1222 * be used to turn off VLAN filter.
1225 if (rx_mq_mode == ETH_MQ_RX_NONE ||
1226 rx_mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1227 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
1228 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
1230 /* Only support one queue on VFs.
1231 * RSS together with SRIOV is not supported.
1233 PMD_INIT_LOG(ERR, "SRIOV is active,"
1234 " wrong mq_mode rx %d.",
1238 /* TX mode is not used here, so mode might be ignored.*/
1239 if (tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1240 /* SRIOV only works in VMDq enable mode */
1241 PMD_INIT_LOG(WARNING, "SRIOV is active,"
1242 " TX mode %d is not supported. "
1243 " Driver will behave as %d mode.",
1244 tx_mq_mode, ETH_MQ_TX_VMDQ_ONLY);
1247 /* check valid queue number */
1248 if ((nb_rx_q > 1) || (nb_tx_q > 1)) {
1249 PMD_INIT_LOG(ERR, "SRIOV is active,"
1250 " only support one queue on VFs.");
1254 /* To no break software that set invalid mode, only display
1255 * warning if invalid mode is used.
1257 if (rx_mq_mode != ETH_MQ_RX_NONE &&
1258 rx_mq_mode != ETH_MQ_RX_VMDQ_ONLY &&
1259 rx_mq_mode != ETH_MQ_RX_RSS) {
1260 /* RSS together with VMDq not supported*/
1261 PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
1266 if (tx_mq_mode != ETH_MQ_TX_NONE &&
1267 tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1268 PMD_INIT_LOG(WARNING, "TX mode %d is not supported."
1269 " Due to txmode is meaningless in this"
1270 " driver, just ignore.",
1278 eth_igb_configure(struct rte_eth_dev *dev)
1280 struct e1000_interrupt *intr =
1281 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1284 PMD_INIT_FUNC_TRACE();
1286 /* multipe queue mode checking */
1287 ret = igb_check_mq_mode(dev);
1289 PMD_DRV_LOG(ERR, "igb_check_mq_mode fails with %d.",
1294 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1295 PMD_INIT_FUNC_TRACE();
1301 eth_igb_start(struct rte_eth_dev *dev)
1303 struct e1000_hw *hw =
1304 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1305 struct e1000_adapter *adapter =
1306 E1000_DEV_PRIVATE(dev->data->dev_private);
1307 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1308 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1310 uint32_t intr_vector = 0;
1316 PMD_INIT_FUNC_TRACE();
1318 /* disable uio/vfio intr/eventfd mapping */
1319 rte_intr_disable(intr_handle);
1321 /* Power up the phy. Needed to make the link go Up */
1322 eth_igb_dev_set_link_up(dev);
1325 * Packet Buffer Allocation (PBA)
1326 * Writing PBA sets the receive portion of the buffer
1327 * the remainder is used for the transmit buffer.
1329 if (hw->mac.type == e1000_82575) {
1332 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
1333 E1000_WRITE_REG(hw, E1000_PBA, pba);
1336 /* Put the address into the Receive Address Array */
1337 e1000_rar_set(hw, hw->mac.addr, 0);
1339 /* Initialize the hardware */
1340 if (igb_hardware_init(hw)) {
1341 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
1344 adapter->stopped = 0;
1346 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1348 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1349 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1350 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
1351 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1352 E1000_WRITE_FLUSH(hw);
1354 /* configure PF module if SRIOV enabled */
1355 igb_pf_host_configure(dev);
1357 /* check and configure queue intr-vector mapping */
1358 if ((rte_intr_cap_multiple(intr_handle) ||
1359 !RTE_ETH_DEV_SRIOV(dev).active) &&
1360 dev->data->dev_conf.intr_conf.rxq != 0) {
1361 intr_vector = dev->data->nb_rx_queues;
1362 if (rte_intr_efd_enable(intr_handle, intr_vector))
1366 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1367 intr_handle->intr_vec =
1368 rte_zmalloc("intr_vec",
1369 dev->data->nb_rx_queues * sizeof(int), 0);
1370 if (intr_handle->intr_vec == NULL) {
1371 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1372 " intr_vec", dev->data->nb_rx_queues);
1377 /* confiugre msix for rx interrupt */
1378 eth_igb_configure_msix_intr(dev);
1380 /* Configure for OS presence */
1381 igb_init_manageability(hw);
1383 eth_igb_tx_init(dev);
1385 /* This can fail when allocating mbufs for descriptor rings */
1386 ret = eth_igb_rx_init(dev);
1388 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1389 igb_dev_clear_queues(dev);
1393 e1000_clear_hw_cntrs_base_generic(hw);
1396 * VLAN Offload Settings
1398 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
1399 ETH_VLAN_EXTEND_MASK;
1400 eth_igb_vlan_offload_set(dev, mask);
1402 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1403 /* Enable VLAN filter since VMDq always use VLAN filter */
1404 igb_vmdq_vlan_hw_filter_enable(dev);
1407 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
1408 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
1409 (hw->mac.type == e1000_i211)) {
1410 /* Configure EITR with the maximum possible value (0xFFFF) */
1411 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
1414 /* Setup link speed and duplex */
1415 speeds = &dev->data->dev_conf.link_speeds;
1416 if (*speeds == ETH_LINK_SPEED_AUTONEG) {
1417 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
1418 hw->mac.autoneg = 1;
1421 autoneg = (*speeds & ETH_LINK_SPEED_FIXED) == 0;
1424 hw->phy.autoneg_advertised = 0;
1426 if (*speeds & ~(ETH_LINK_SPEED_10M_HD | ETH_LINK_SPEED_10M |
1427 ETH_LINK_SPEED_100M_HD | ETH_LINK_SPEED_100M |
1428 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_FIXED)) {
1430 goto error_invalid_config;
1432 if (*speeds & ETH_LINK_SPEED_10M_HD) {
1433 hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
1436 if (*speeds & ETH_LINK_SPEED_10M) {
1437 hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
1440 if (*speeds & ETH_LINK_SPEED_100M_HD) {
1441 hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
1444 if (*speeds & ETH_LINK_SPEED_100M) {
1445 hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
1448 if (*speeds & ETH_LINK_SPEED_1G) {
1449 hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
1452 if (num_speeds == 0 || (!autoneg && (num_speeds > 1)))
1453 goto error_invalid_config;
1455 /* Set/reset the mac.autoneg based on the link speed,
1459 hw->mac.autoneg = 0;
1460 hw->mac.forced_speed_duplex =
1461 hw->phy.autoneg_advertised;
1463 hw->mac.autoneg = 1;
1467 e1000_setup_link(hw);
1469 if (rte_intr_allow_others(intr_handle)) {
1470 /* check if lsc interrupt is enabled */
1471 if (dev->data->dev_conf.intr_conf.lsc != 0)
1472 eth_igb_lsc_interrupt_setup(dev);
1474 rte_intr_callback_unregister(intr_handle,
1475 eth_igb_interrupt_handler,
1477 if (dev->data->dev_conf.intr_conf.lsc != 0)
1478 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1479 " no intr multiplex");
1482 /* check if rxq interrupt is enabled */
1483 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1484 rte_intr_dp_is_en(intr_handle))
1485 eth_igb_rxq_interrupt_setup(dev);
1487 /* enable uio/vfio intr/eventfd mapping */
1488 rte_intr_enable(intr_handle);
1490 /* resume enabled intr since hw reset */
1491 igb_intr_enable(dev);
1493 /* restore all types filter */
1494 igb_filter_restore(dev);
1496 PMD_INIT_LOG(DEBUG, "<<");
1500 error_invalid_config:
1501 PMD_INIT_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
1502 dev->data->dev_conf.link_speeds, dev->data->port_id);
1503 igb_dev_clear_queues(dev);
1507 /*********************************************************************
1509 * This routine disables all traffic on the adapter by issuing a
1510 * global reset on the MAC.
1512 **********************************************************************/
1514 eth_igb_stop(struct rte_eth_dev *dev)
1516 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1517 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1518 struct rte_eth_link link;
1519 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1521 igb_intr_disable(hw);
1523 /* disable intr eventfd mapping */
1524 rte_intr_disable(intr_handle);
1526 igb_pf_reset_hw(hw);
1527 E1000_WRITE_REG(hw, E1000_WUC, 0);
1529 /* Set bit for Go Link disconnect */
1530 if (hw->mac.type >= e1000_82580) {
1533 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1534 phpm_reg |= E1000_82580_PM_GO_LINKD;
1535 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1538 /* Power down the phy. Needed to make the link go Down */
1539 eth_igb_dev_set_link_down(dev);
1541 igb_dev_clear_queues(dev);
1543 /* clear the recorded link status */
1544 memset(&link, 0, sizeof(link));
1545 rte_igb_dev_atomic_write_link_status(dev, &link);
1547 if (!rte_intr_allow_others(intr_handle))
1548 /* resume to the default handler */
1549 rte_intr_callback_register(intr_handle,
1550 eth_igb_interrupt_handler,
1553 /* Clean datapath event and queue/vec mapping */
1554 rte_intr_efd_disable(intr_handle);
1555 if (intr_handle->intr_vec != NULL) {
1556 rte_free(intr_handle->intr_vec);
1557 intr_handle->intr_vec = NULL;
1562 eth_igb_dev_set_link_up(struct rte_eth_dev *dev)
1564 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1566 if (hw->phy.media_type == e1000_media_type_copper)
1567 e1000_power_up_phy(hw);
1569 e1000_power_up_fiber_serdes_link(hw);
1575 eth_igb_dev_set_link_down(struct rte_eth_dev *dev)
1577 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1579 if (hw->phy.media_type == e1000_media_type_copper)
1580 e1000_power_down_phy(hw);
1582 e1000_shutdown_fiber_serdes_link(hw);
1588 eth_igb_close(struct rte_eth_dev *dev)
1590 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1591 struct e1000_adapter *adapter =
1592 E1000_DEV_PRIVATE(dev->data->dev_private);
1593 struct rte_eth_link link;
1594 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1595 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1598 adapter->stopped = 1;
1600 e1000_phy_hw_reset(hw);
1601 igb_release_manageability(hw);
1602 igb_hw_control_release(hw);
1604 /* Clear bit for Go Link disconnect */
1605 if (hw->mac.type >= e1000_82580) {
1608 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1609 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1610 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1613 igb_dev_free_queues(dev);
1615 if (intr_handle->intr_vec) {
1616 rte_free(intr_handle->intr_vec);
1617 intr_handle->intr_vec = NULL;
1620 memset(&link, 0, sizeof(link));
1621 rte_igb_dev_atomic_write_link_status(dev, &link);
1625 igb_get_rx_buffer_size(struct e1000_hw *hw)
1627 uint32_t rx_buf_size;
1628 if (hw->mac.type == e1000_82576) {
1629 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1630 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1631 /* PBS needs to be translated according to a lookup table */
1632 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1633 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1634 rx_buf_size = (rx_buf_size << 10);
1635 } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1636 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1638 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1644 /*********************************************************************
1646 * Initialize the hardware
1648 **********************************************************************/
1650 igb_hardware_init(struct e1000_hw *hw)
1652 uint32_t rx_buf_size;
1655 /* Let the firmware know the OS is in control */
1656 igb_hw_control_acquire(hw);
1659 * These parameters control the automatic generation (Tx) and
1660 * response (Rx) to Ethernet PAUSE frames.
1661 * - High water mark should allow for at least two standard size (1518)
1662 * frames to be received after sending an XOFF.
1663 * - Low water mark works best when it is very near the high water mark.
1664 * This allows the receiver to restart by sending XON when it has
1665 * drained a bit. Here we use an arbitrary value of 1500 which will
1666 * restart after one full frame is pulled from the buffer. There
1667 * could be several smaller frames in the buffer and if so they will
1668 * not trigger the XON until their total number reduces the buffer
1670 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1672 rx_buf_size = igb_get_rx_buffer_size(hw);
1674 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
1675 hw->fc.low_water = hw->fc.high_water - 1500;
1676 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1677 hw->fc.send_xon = 1;
1679 /* Set Flow control, use the tunable location if sane */
1680 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1681 hw->fc.requested_mode = igb_fc_setting;
1683 hw->fc.requested_mode = e1000_fc_none;
1685 /* Issue a global reset */
1686 igb_pf_reset_hw(hw);
1687 E1000_WRITE_REG(hw, E1000_WUC, 0);
1689 diag = e1000_init_hw(hw);
1693 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1694 e1000_get_phy_info(hw);
1695 e1000_check_for_link(hw);
1700 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1702 igb_read_stats_registers(struct e1000_hw *hw, struct e1000_hw_stats *stats)
1706 uint64_t old_gprc = stats->gprc;
1707 uint64_t old_gptc = stats->gptc;
1708 uint64_t old_tpr = stats->tpr;
1709 uint64_t old_tpt = stats->tpt;
1710 uint64_t old_rpthc = stats->rpthc;
1711 uint64_t old_hgptc = stats->hgptc;
1713 if(hw->phy.media_type == e1000_media_type_copper ||
1714 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1716 E1000_READ_REG(hw,E1000_SYMERRS);
1717 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1720 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1721 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1722 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1723 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1725 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1726 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1727 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1728 stats->dc += E1000_READ_REG(hw, E1000_DC);
1729 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1730 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1731 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1733 ** For watchdog management we need to know if we have been
1734 ** paused during the last interval, so capture that here.
1736 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1737 stats->xoffrxc += pause_frames;
1738 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1739 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1740 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1741 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1742 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1743 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1744 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1745 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1746 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1747 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1748 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1749 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1751 /* For the 64-bit byte counters the low dword must be read first. */
1752 /* Both registers clear on the read of the high dword */
1754 /* Workaround CRC bytes included in size, take away 4 bytes/packet */
1755 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1756 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1757 stats->gorc -= (stats->gprc - old_gprc) * ETHER_CRC_LEN;
1758 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1759 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1760 stats->gotc -= (stats->gptc - old_gptc) * ETHER_CRC_LEN;
1762 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1763 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1764 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1765 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1766 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1768 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1769 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1771 stats->tor += E1000_READ_REG(hw, E1000_TORL);
1772 stats->tor += ((uint64_t)E1000_READ_REG(hw, E1000_TORH) << 32);
1773 stats->tor -= (stats->tpr - old_tpr) * ETHER_CRC_LEN;
1774 stats->tot += E1000_READ_REG(hw, E1000_TOTL);
1775 stats->tot += ((uint64_t)E1000_READ_REG(hw, E1000_TOTH) << 32);
1776 stats->tot -= (stats->tpt - old_tpt) * ETHER_CRC_LEN;
1778 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1779 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1780 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1781 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1782 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1783 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1784 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1785 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1787 /* Interrupt Counts */
1789 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1790 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1791 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1792 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1793 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1794 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1795 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1796 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1797 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1799 /* Host to Card Statistics */
1801 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1802 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1803 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1804 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1805 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1806 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1807 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1808 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1809 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1810 stats->hgorc -= (stats->rpthc - old_rpthc) * ETHER_CRC_LEN;
1811 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1812 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1813 stats->hgotc -= (stats->hgptc - old_hgptc) * ETHER_CRC_LEN;
1814 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1815 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1816 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1818 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1819 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1820 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1821 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1822 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1823 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1827 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1829 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1830 struct e1000_hw_stats *stats =
1831 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1833 igb_read_stats_registers(hw, stats);
1835 if (rte_stats == NULL)
1839 rte_stats->imissed = stats->mpc;
1840 rte_stats->ierrors = stats->crcerrs +
1841 stats->rlec + stats->ruc + stats->roc +
1842 stats->rxerrc + stats->algnerrc + stats->cexterr;
1845 rte_stats->oerrors = stats->ecol + stats->latecol;
1847 rte_stats->ipackets = stats->gprc;
1848 rte_stats->opackets = stats->gptc;
1849 rte_stats->ibytes = stats->gorc;
1850 rte_stats->obytes = stats->gotc;
1854 eth_igb_stats_reset(struct rte_eth_dev *dev)
1856 struct e1000_hw_stats *hw_stats =
1857 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1859 /* HW registers are cleared on read */
1860 eth_igb_stats_get(dev, NULL);
1862 /* Reset software totals */
1863 memset(hw_stats, 0, sizeof(*hw_stats));
1867 eth_igb_xstats_reset(struct rte_eth_dev *dev)
1869 struct e1000_hw_stats *stats =
1870 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1872 /* HW registers are cleared on read */
1873 eth_igb_xstats_get(dev, NULL, IGB_NB_XSTATS);
1875 /* Reset software totals */
1876 memset(stats, 0, sizeof(*stats));
1879 static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1880 struct rte_eth_xstat_name *xstats_names,
1881 __rte_unused unsigned int size)
1885 if (xstats_names == NULL)
1886 return IGB_NB_XSTATS;
1888 /* Note: limit checked in rte_eth_xstats_names() */
1890 for (i = 0; i < IGB_NB_XSTATS; i++) {
1891 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
1892 "%s", rte_igb_stats_strings[i].name);
1895 return IGB_NB_XSTATS;
1898 static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
1899 struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
1905 if (xstats_names == NULL)
1906 return IGB_NB_XSTATS;
1908 for (i = 0; i < IGB_NB_XSTATS; i++)
1909 snprintf(xstats_names[i].name,
1910 sizeof(xstats_names[i].name),
1911 "%s", rte_igb_stats_strings[i].name);
1913 return IGB_NB_XSTATS;
1916 struct rte_eth_xstat_name xstats_names_copy[IGB_NB_XSTATS];
1918 eth_igb_xstats_get_names_by_id(dev, xstats_names_copy, NULL,
1921 for (i = 0; i < limit; i++) {
1922 if (ids[i] >= IGB_NB_XSTATS) {
1923 PMD_INIT_LOG(ERR, "id value isn't valid");
1926 strcpy(xstats_names[i].name,
1927 xstats_names_copy[ids[i]].name);
1934 eth_igb_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1937 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1938 struct e1000_hw_stats *hw_stats =
1939 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1942 if (n < IGB_NB_XSTATS)
1943 return IGB_NB_XSTATS;
1945 igb_read_stats_registers(hw, hw_stats);
1947 /* If this is a reset xstats is NULL, and we have cleared the
1948 * registers by reading them.
1953 /* Extended stats */
1954 for (i = 0; i < IGB_NB_XSTATS; i++) {
1956 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
1957 rte_igb_stats_strings[i].offset);
1960 return IGB_NB_XSTATS;
1964 eth_igb_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1965 uint64_t *values, unsigned int n)
1970 struct e1000_hw *hw =
1971 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1972 struct e1000_hw_stats *hw_stats =
1973 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1975 if (n < IGB_NB_XSTATS)
1976 return IGB_NB_XSTATS;
1978 igb_read_stats_registers(hw, hw_stats);
1980 /* If this is a reset xstats is NULL, and we have cleared the
1981 * registers by reading them.
1986 /* Extended stats */
1987 for (i = 0; i < IGB_NB_XSTATS; i++)
1988 values[i] = *(uint64_t *)(((char *)hw_stats) +
1989 rte_igb_stats_strings[i].offset);
1991 return IGB_NB_XSTATS;
1994 uint64_t values_copy[IGB_NB_XSTATS];
1996 eth_igb_xstats_get_by_id(dev, NULL, values_copy,
1999 for (i = 0; i < n; i++) {
2000 if (ids[i] >= IGB_NB_XSTATS) {
2001 PMD_INIT_LOG(ERR, "id value isn't valid");
2004 values[i] = values_copy[ids[i]];
2011 igbvf_read_stats_registers(struct e1000_hw *hw, struct e1000_vf_stats *hw_stats)
2013 /* Good Rx packets, include VF loopback */
2014 UPDATE_VF_STAT(E1000_VFGPRC,
2015 hw_stats->last_gprc, hw_stats->gprc);
2017 /* Good Rx octets, include VF loopback */
2018 UPDATE_VF_STAT(E1000_VFGORC,
2019 hw_stats->last_gorc, hw_stats->gorc);
2021 /* Good Tx packets, include VF loopback */
2022 UPDATE_VF_STAT(E1000_VFGPTC,
2023 hw_stats->last_gptc, hw_stats->gptc);
2025 /* Good Tx octets, include VF loopback */
2026 UPDATE_VF_STAT(E1000_VFGOTC,
2027 hw_stats->last_gotc, hw_stats->gotc);
2029 /* Rx Multicst packets */
2030 UPDATE_VF_STAT(E1000_VFMPRC,
2031 hw_stats->last_mprc, hw_stats->mprc);
2033 /* Good Rx loopback packets */
2034 UPDATE_VF_STAT(E1000_VFGPRLBC,
2035 hw_stats->last_gprlbc, hw_stats->gprlbc);
2037 /* Good Rx loopback octets */
2038 UPDATE_VF_STAT(E1000_VFGORLBC,
2039 hw_stats->last_gorlbc, hw_stats->gorlbc);
2041 /* Good Tx loopback packets */
2042 UPDATE_VF_STAT(E1000_VFGPTLBC,
2043 hw_stats->last_gptlbc, hw_stats->gptlbc);
2045 /* Good Tx loopback octets */
2046 UPDATE_VF_STAT(E1000_VFGOTLBC,
2047 hw_stats->last_gotlbc, hw_stats->gotlbc);
2050 static int eth_igbvf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2051 struct rte_eth_xstat_name *xstats_names,
2052 __rte_unused unsigned limit)
2056 if (xstats_names != NULL)
2057 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2058 snprintf(xstats_names[i].name,
2059 sizeof(xstats_names[i].name), "%s",
2060 rte_igbvf_stats_strings[i].name);
2062 return IGBVF_NB_XSTATS;
2066 eth_igbvf_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2069 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2070 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2071 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2074 if (n < IGBVF_NB_XSTATS)
2075 return IGBVF_NB_XSTATS;
2077 igbvf_read_stats_registers(hw, hw_stats);
2082 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2084 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
2085 rte_igbvf_stats_strings[i].offset);
2088 return IGBVF_NB_XSTATS;
2092 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
2094 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2095 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2096 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2098 igbvf_read_stats_registers(hw, hw_stats);
2100 if (rte_stats == NULL)
2103 rte_stats->ipackets = hw_stats->gprc;
2104 rte_stats->ibytes = hw_stats->gorc;
2105 rte_stats->opackets = hw_stats->gptc;
2106 rte_stats->obytes = hw_stats->gotc;
2110 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
2112 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
2113 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2115 /* Sync HW register to the last stats */
2116 eth_igbvf_stats_get(dev, NULL);
2118 /* reset HW current stats*/
2119 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
2120 offsetof(struct e1000_vf_stats, gprc));
2124 eth_igb_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
2127 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2128 struct e1000_fw_version fw;
2131 e1000_get_fw_version(hw, &fw);
2133 switch (hw->mac.type) {
2136 if (!(e1000_get_flash_presence_i210(hw))) {
2137 ret = snprintf(fw_version, fw_size,
2139 fw.invm_major, fw.invm_minor,
2145 /* if option rom is valid, display its version too */
2147 ret = snprintf(fw_version, fw_size,
2148 "%d.%d, 0x%08x, %d.%d.%d",
2149 fw.eep_major, fw.eep_minor, fw.etrack_id,
2150 fw.or_major, fw.or_build, fw.or_patch);
2153 if (fw.etrack_id != 0X0000) {
2154 ret = snprintf(fw_version, fw_size,
2156 fw.eep_major, fw.eep_minor,
2159 ret = snprintf(fw_version, fw_size,
2161 fw.eep_major, fw.eep_minor,
2168 ret += 1; /* add the size of '\0' */
2169 if (fw_size < (u32)ret)
2176 eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2178 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2180 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2181 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2182 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2183 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2184 dev_info->rx_offload_capa =
2185 DEV_RX_OFFLOAD_VLAN_STRIP |
2186 DEV_RX_OFFLOAD_IPV4_CKSUM |
2187 DEV_RX_OFFLOAD_UDP_CKSUM |
2188 DEV_RX_OFFLOAD_TCP_CKSUM;
2189 dev_info->tx_offload_capa =
2190 DEV_TX_OFFLOAD_VLAN_INSERT |
2191 DEV_TX_OFFLOAD_IPV4_CKSUM |
2192 DEV_TX_OFFLOAD_UDP_CKSUM |
2193 DEV_TX_OFFLOAD_TCP_CKSUM |
2194 DEV_TX_OFFLOAD_SCTP_CKSUM |
2195 DEV_TX_OFFLOAD_TCP_TSO;
2197 switch (hw->mac.type) {
2199 dev_info->max_rx_queues = 4;
2200 dev_info->max_tx_queues = 4;
2201 dev_info->max_vmdq_pools = 0;
2205 dev_info->max_rx_queues = 16;
2206 dev_info->max_tx_queues = 16;
2207 dev_info->max_vmdq_pools = ETH_8_POOLS;
2208 dev_info->vmdq_queue_num = 16;
2212 dev_info->max_rx_queues = 8;
2213 dev_info->max_tx_queues = 8;
2214 dev_info->max_vmdq_pools = ETH_8_POOLS;
2215 dev_info->vmdq_queue_num = 8;
2219 dev_info->max_rx_queues = 8;
2220 dev_info->max_tx_queues = 8;
2221 dev_info->max_vmdq_pools = ETH_8_POOLS;
2222 dev_info->vmdq_queue_num = 8;
2226 dev_info->max_rx_queues = 8;
2227 dev_info->max_tx_queues = 8;
2231 dev_info->max_rx_queues = 4;
2232 dev_info->max_tx_queues = 4;
2233 dev_info->max_vmdq_pools = 0;
2237 dev_info->max_rx_queues = 2;
2238 dev_info->max_tx_queues = 2;
2239 dev_info->max_vmdq_pools = 0;
2243 /* Should not happen */
2246 dev_info->hash_key_size = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
2247 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
2248 dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
2250 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2252 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2253 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2254 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2256 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2260 dev_info->default_txconf = (struct rte_eth_txconf) {
2262 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2263 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2264 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2269 dev_info->rx_desc_lim = rx_desc_lim;
2270 dev_info->tx_desc_lim = tx_desc_lim;
2272 dev_info->speed_capa = ETH_LINK_SPEED_10M_HD | ETH_LINK_SPEED_10M |
2273 ETH_LINK_SPEED_100M_HD | ETH_LINK_SPEED_100M |
2277 static const uint32_t *
2278 eth_igb_supported_ptypes_get(struct rte_eth_dev *dev)
2280 static const uint32_t ptypes[] = {
2281 /* refers to igb_rxd_pkt_info_to_pkt_type() */
2284 RTE_PTYPE_L3_IPV4_EXT,
2286 RTE_PTYPE_L3_IPV6_EXT,
2290 RTE_PTYPE_TUNNEL_IP,
2291 RTE_PTYPE_INNER_L3_IPV6,
2292 RTE_PTYPE_INNER_L3_IPV6_EXT,
2293 RTE_PTYPE_INNER_L4_TCP,
2294 RTE_PTYPE_INNER_L4_UDP,
2298 if (dev->rx_pkt_burst == eth_igb_recv_pkts ||
2299 dev->rx_pkt_burst == eth_igb_recv_scattered_pkts)
2305 eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2307 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2309 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2310 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2311 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2312 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2313 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
2314 DEV_RX_OFFLOAD_IPV4_CKSUM |
2315 DEV_RX_OFFLOAD_UDP_CKSUM |
2316 DEV_RX_OFFLOAD_TCP_CKSUM;
2317 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
2318 DEV_TX_OFFLOAD_IPV4_CKSUM |
2319 DEV_TX_OFFLOAD_UDP_CKSUM |
2320 DEV_TX_OFFLOAD_TCP_CKSUM |
2321 DEV_TX_OFFLOAD_SCTP_CKSUM |
2322 DEV_TX_OFFLOAD_TCP_TSO;
2323 switch (hw->mac.type) {
2325 dev_info->max_rx_queues = 2;
2326 dev_info->max_tx_queues = 2;
2328 case e1000_vfadapt_i350:
2329 dev_info->max_rx_queues = 1;
2330 dev_info->max_tx_queues = 1;
2333 /* Should not happen */
2337 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2339 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2340 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2341 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2343 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2347 dev_info->default_txconf = (struct rte_eth_txconf) {
2349 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2350 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2351 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2356 dev_info->rx_desc_lim = rx_desc_lim;
2357 dev_info->tx_desc_lim = tx_desc_lim;
2360 /* return 0 means link status changed, -1 means not changed */
2362 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2364 struct e1000_hw *hw =
2365 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2366 struct rte_eth_link link, old;
2367 int link_check, count;
2370 hw->mac.get_link_status = 1;
2372 /* possible wait-to-complete in up to 9 seconds */
2373 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
2374 /* Read the real link status */
2375 switch (hw->phy.media_type) {
2376 case e1000_media_type_copper:
2377 /* Do the work to read phy */
2378 e1000_check_for_link(hw);
2379 link_check = !hw->mac.get_link_status;
2382 case e1000_media_type_fiber:
2383 e1000_check_for_link(hw);
2384 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
2388 case e1000_media_type_internal_serdes:
2389 e1000_check_for_link(hw);
2390 link_check = hw->mac.serdes_has_link;
2393 /* VF device is type_unknown */
2394 case e1000_media_type_unknown:
2395 eth_igbvf_link_update(hw);
2396 link_check = !hw->mac.get_link_status;
2402 if (link_check || wait_to_complete == 0)
2404 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
2406 memset(&link, 0, sizeof(link));
2407 rte_igb_dev_atomic_read_link_status(dev, &link);
2410 /* Now we check if a transition has happened */
2412 uint16_t duplex, speed;
2413 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
2414 link.link_duplex = (duplex == FULL_DUPLEX) ?
2415 ETH_LINK_FULL_DUPLEX :
2416 ETH_LINK_HALF_DUPLEX;
2417 link.link_speed = speed;
2418 link.link_status = ETH_LINK_UP;
2419 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2420 ETH_LINK_SPEED_FIXED);
2421 } else if (!link_check) {
2422 link.link_speed = 0;
2423 link.link_duplex = ETH_LINK_HALF_DUPLEX;
2424 link.link_status = ETH_LINK_DOWN;
2425 link.link_autoneg = ETH_LINK_SPEED_FIXED;
2427 rte_igb_dev_atomic_write_link_status(dev, &link);
2430 if (old.link_status == link.link_status)
2438 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
2439 * For ASF and Pass Through versions of f/w this means
2440 * that the driver is loaded.
2443 igb_hw_control_acquire(struct e1000_hw *hw)
2447 /* Let firmware know the driver has taken over */
2448 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2449 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2453 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
2454 * For ASF and Pass Through versions of f/w this means that the
2455 * driver is no longer loaded.
2458 igb_hw_control_release(struct e1000_hw *hw)
2462 /* Let firmware taken over control of h/w */
2463 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2464 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
2465 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2469 * Bit of a misnomer, what this really means is
2470 * to enable OS management of the system... aka
2471 * to disable special hardware management features.
2474 igb_init_manageability(struct e1000_hw *hw)
2476 if (e1000_enable_mng_pass_thru(hw)) {
2477 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
2478 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2480 /* disable hardware interception of ARP */
2481 manc &= ~(E1000_MANC_ARP_EN);
2483 /* enable receiving management packets to the host */
2484 manc |= E1000_MANC_EN_MNG2HOST;
2485 manc2h |= 1 << 5; /* Mng Port 623 */
2486 manc2h |= 1 << 6; /* Mng Port 664 */
2487 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
2488 E1000_WRITE_REG(hw, E1000_MANC, manc);
2493 igb_release_manageability(struct e1000_hw *hw)
2495 if (e1000_enable_mng_pass_thru(hw)) {
2496 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2498 manc |= E1000_MANC_ARP_EN;
2499 manc &= ~E1000_MANC_EN_MNG2HOST;
2501 E1000_WRITE_REG(hw, E1000_MANC, manc);
2506 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
2508 struct e1000_hw *hw =
2509 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2512 rctl = E1000_READ_REG(hw, E1000_RCTL);
2513 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2514 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2518 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
2520 struct e1000_hw *hw =
2521 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2524 rctl = E1000_READ_REG(hw, E1000_RCTL);
2525 rctl &= (~E1000_RCTL_UPE);
2526 if (dev->data->all_multicast == 1)
2527 rctl |= E1000_RCTL_MPE;
2529 rctl &= (~E1000_RCTL_MPE);
2530 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2534 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
2536 struct e1000_hw *hw =
2537 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2540 rctl = E1000_READ_REG(hw, E1000_RCTL);
2541 rctl |= E1000_RCTL_MPE;
2542 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2546 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
2548 struct e1000_hw *hw =
2549 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2552 if (dev->data->promiscuous == 1)
2553 return; /* must remain in all_multicast mode */
2554 rctl = E1000_READ_REG(hw, E1000_RCTL);
2555 rctl &= (~E1000_RCTL_MPE);
2556 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2560 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2562 struct e1000_hw *hw =
2563 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2564 struct e1000_vfta * shadow_vfta =
2565 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2570 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
2571 E1000_VFTA_ENTRY_MASK);
2572 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
2573 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
2578 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
2580 /* update local VFTA copy */
2581 shadow_vfta->vfta[vid_idx] = vfta;
2587 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
2588 enum rte_vlan_type vlan_type,
2591 struct e1000_hw *hw =
2592 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2595 qinq = E1000_READ_REG(hw, E1000_CTRL_EXT);
2596 qinq &= E1000_CTRL_EXT_EXT_VLAN;
2598 /* only outer TPID of double VLAN can be configured*/
2599 if (qinq && vlan_type == ETH_VLAN_TYPE_OUTER) {
2600 reg = E1000_READ_REG(hw, E1000_VET);
2601 reg = (reg & (~E1000_VET_VET_EXT)) |
2602 ((uint32_t)tpid << E1000_VET_VET_EXT_SHIFT);
2603 E1000_WRITE_REG(hw, E1000_VET, reg);
2608 /* all other TPID values are read-only*/
2609 PMD_DRV_LOG(ERR, "Not supported");
2615 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
2617 struct e1000_hw *hw =
2618 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2621 /* Filter Table Disable */
2622 reg = E1000_READ_REG(hw, E1000_RCTL);
2623 reg &= ~E1000_RCTL_CFIEN;
2624 reg &= ~E1000_RCTL_VFE;
2625 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2629 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2631 struct e1000_hw *hw =
2632 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2633 struct e1000_vfta * shadow_vfta =
2634 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2638 /* Filter Table Enable, CFI not used for packet acceptance */
2639 reg = E1000_READ_REG(hw, E1000_RCTL);
2640 reg &= ~E1000_RCTL_CFIEN;
2641 reg |= E1000_RCTL_VFE;
2642 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2644 /* restore VFTA table */
2645 for (i = 0; i < IGB_VFTA_SIZE; i++)
2646 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
2650 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
2652 struct e1000_hw *hw =
2653 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2656 /* VLAN Mode Disable */
2657 reg = E1000_READ_REG(hw, E1000_CTRL);
2658 reg &= ~E1000_CTRL_VME;
2659 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2663 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
2665 struct e1000_hw *hw =
2666 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2669 /* VLAN Mode Enable */
2670 reg = E1000_READ_REG(hw, E1000_CTRL);
2671 reg |= E1000_CTRL_VME;
2672 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2676 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2678 struct e1000_hw *hw =
2679 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2682 /* CTRL_EXT: Extended VLAN */
2683 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2684 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
2685 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2687 /* Update maximum packet length */
2688 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
2689 E1000_WRITE_REG(hw, E1000_RLPML,
2690 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2695 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2697 struct e1000_hw *hw =
2698 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2701 /* CTRL_EXT: Extended VLAN */
2702 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2703 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
2704 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2706 /* Update maximum packet length */
2707 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
2708 E1000_WRITE_REG(hw, E1000_RLPML,
2709 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2714 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2716 if(mask & ETH_VLAN_STRIP_MASK){
2717 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2718 igb_vlan_hw_strip_enable(dev);
2720 igb_vlan_hw_strip_disable(dev);
2723 if(mask & ETH_VLAN_FILTER_MASK){
2724 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2725 igb_vlan_hw_filter_enable(dev);
2727 igb_vlan_hw_filter_disable(dev);
2730 if(mask & ETH_VLAN_EXTEND_MASK){
2731 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2732 igb_vlan_hw_extend_enable(dev);
2734 igb_vlan_hw_extend_disable(dev);
2740 * It enables the interrupt mask and then enable the interrupt.
2743 * Pointer to struct rte_eth_dev.
2746 * - On success, zero.
2747 * - On failure, a negative value.
2750 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev)
2752 struct e1000_interrupt *intr =
2753 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2755 intr->mask |= E1000_ICR_LSC;
2760 /* It clears the interrupt causes and enables the interrupt.
2761 * It will be called once only during nic initialized.
2764 * Pointer to struct rte_eth_dev.
2767 * - On success, zero.
2768 * - On failure, a negative value.
2770 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev)
2772 uint32_t mask, regval;
2773 struct e1000_hw *hw =
2774 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2775 struct rte_eth_dev_info dev_info;
2777 memset(&dev_info, 0, sizeof(dev_info));
2778 eth_igb_infos_get(dev, &dev_info);
2780 mask = 0xFFFFFFFF >> (32 - dev_info.max_rx_queues);
2781 regval = E1000_READ_REG(hw, E1000_EIMS);
2782 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
2788 * It reads ICR and gets interrupt causes, check it and set a bit flag
2789 * to update link status.
2792 * Pointer to struct rte_eth_dev.
2795 * - On success, zero.
2796 * - On failure, a negative value.
2799 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
2802 struct e1000_hw *hw =
2803 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2804 struct e1000_interrupt *intr =
2805 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2807 igb_intr_disable(hw);
2809 /* read-on-clear nic registers here */
2810 icr = E1000_READ_REG(hw, E1000_ICR);
2813 if (icr & E1000_ICR_LSC) {
2814 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
2817 if (icr & E1000_ICR_VMMB)
2818 intr->flags |= E1000_FLAG_MAILBOX;
2824 * It executes link_update after knowing an interrupt is prsent.
2827 * Pointer to struct rte_eth_dev.
2830 * - On success, zero.
2831 * - On failure, a negative value.
2834 eth_igb_interrupt_action(struct rte_eth_dev *dev,
2835 struct rte_intr_handle *intr_handle)
2837 struct e1000_hw *hw =
2838 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2839 struct e1000_interrupt *intr =
2840 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2841 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2842 uint32_t tctl, rctl;
2843 struct rte_eth_link link;
2846 if (intr->flags & E1000_FLAG_MAILBOX) {
2847 igb_pf_mbx_process(dev);
2848 intr->flags &= ~E1000_FLAG_MAILBOX;
2851 igb_intr_enable(dev);
2852 rte_intr_enable(intr_handle);
2854 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
2855 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
2857 /* set get_link_status to check register later */
2858 hw->mac.get_link_status = 1;
2859 ret = eth_igb_link_update(dev, 0);
2861 /* check if link has changed */
2865 memset(&link, 0, sizeof(link));
2866 rte_igb_dev_atomic_read_link_status(dev, &link);
2867 if (link.link_status) {
2869 " Port %d: Link Up - speed %u Mbps - %s",
2871 (unsigned)link.link_speed,
2872 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2873 "full-duplex" : "half-duplex");
2875 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2876 dev->data->port_id);
2879 PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
2880 pci_dev->addr.domain,
2882 pci_dev->addr.devid,
2883 pci_dev->addr.function);
2884 tctl = E1000_READ_REG(hw, E1000_TCTL);
2885 rctl = E1000_READ_REG(hw, E1000_RCTL);
2886 if (link.link_status) {
2888 tctl |= E1000_TCTL_EN;
2889 rctl |= E1000_RCTL_EN;
2892 tctl &= ~E1000_TCTL_EN;
2893 rctl &= ~E1000_RCTL_EN;
2895 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
2896 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2897 E1000_WRITE_FLUSH(hw);
2898 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
2905 * Interrupt handler which shall be registered at first.
2908 * Pointer to interrupt handle.
2910 * The address of parameter (struct rte_eth_dev *) regsitered before.
2916 eth_igb_interrupt_handler(void *param)
2918 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2920 eth_igb_interrupt_get_status(dev);
2921 eth_igb_interrupt_action(dev, dev->intr_handle);
2925 eth_igbvf_interrupt_get_status(struct rte_eth_dev *dev)
2928 struct e1000_hw *hw =
2929 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2930 struct e1000_interrupt *intr =
2931 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2933 igbvf_intr_disable(hw);
2935 /* read-on-clear nic registers here */
2936 eicr = E1000_READ_REG(hw, E1000_EICR);
2939 if (eicr == E1000_VTIVAR_MISC_MAILBOX)
2940 intr->flags |= E1000_FLAG_MAILBOX;
2945 void igbvf_mbx_process(struct rte_eth_dev *dev)
2947 struct e1000_hw *hw =
2948 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2949 struct e1000_mbx_info *mbx = &hw->mbx;
2952 if (mbx->ops.read(hw, &in_msg, 1, 0))
2955 /* PF reset VF event */
2956 if (in_msg == E1000_PF_CONTROL_MSG)
2957 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET, NULL);
2961 eth_igbvf_interrupt_action(struct rte_eth_dev *dev, struct rte_intr_handle *intr_handle)
2963 struct e1000_interrupt *intr =
2964 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2966 if (intr->flags & E1000_FLAG_MAILBOX) {
2967 igbvf_mbx_process(dev);
2968 intr->flags &= ~E1000_FLAG_MAILBOX;
2971 igbvf_intr_enable(dev);
2972 rte_intr_enable(intr_handle);
2978 eth_igbvf_interrupt_handler(void *param)
2980 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2982 eth_igbvf_interrupt_get_status(dev);
2983 eth_igbvf_interrupt_action(dev, dev->intr_handle);
2987 eth_igb_led_on(struct rte_eth_dev *dev)
2989 struct e1000_hw *hw;
2991 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2992 return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
2996 eth_igb_led_off(struct rte_eth_dev *dev)
2998 struct e1000_hw *hw;
3000 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3001 return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
3005 eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3007 struct e1000_hw *hw;
3012 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3013 fc_conf->pause_time = hw->fc.pause_time;
3014 fc_conf->high_water = hw->fc.high_water;
3015 fc_conf->low_water = hw->fc.low_water;
3016 fc_conf->send_xon = hw->fc.send_xon;
3017 fc_conf->autoneg = hw->mac.autoneg;
3020 * Return rx_pause and tx_pause status according to actual setting of
3021 * the TFCE and RFCE bits in the CTRL register.
3023 ctrl = E1000_READ_REG(hw, E1000_CTRL);
3024 if (ctrl & E1000_CTRL_TFCE)
3029 if (ctrl & E1000_CTRL_RFCE)
3034 if (rx_pause && tx_pause)
3035 fc_conf->mode = RTE_FC_FULL;
3037 fc_conf->mode = RTE_FC_RX_PAUSE;
3039 fc_conf->mode = RTE_FC_TX_PAUSE;
3041 fc_conf->mode = RTE_FC_NONE;
3047 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3049 struct e1000_hw *hw;
3051 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
3057 uint32_t rx_buf_size;
3058 uint32_t max_high_water;
3061 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3062 if (fc_conf->autoneg != hw->mac.autoneg)
3064 rx_buf_size = igb_get_rx_buffer_size(hw);
3065 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
3067 /* At least reserve one Ethernet frame for watermark */
3068 max_high_water = rx_buf_size - ETHER_MAX_LEN;
3069 if ((fc_conf->high_water > max_high_water) ||
3070 (fc_conf->high_water < fc_conf->low_water)) {
3071 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
3072 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
3076 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
3077 hw->fc.pause_time = fc_conf->pause_time;
3078 hw->fc.high_water = fc_conf->high_water;
3079 hw->fc.low_water = fc_conf->low_water;
3080 hw->fc.send_xon = fc_conf->send_xon;
3082 err = e1000_setup_link_generic(hw);
3083 if (err == E1000_SUCCESS) {
3085 /* check if we want to forward MAC frames - driver doesn't have native
3086 * capability to do that, so we'll write the registers ourselves */
3088 rctl = E1000_READ_REG(hw, E1000_RCTL);
3090 /* set or clear MFLCN.PMCF bit depending on configuration */
3091 if (fc_conf->mac_ctrl_frame_fwd != 0)
3092 rctl |= E1000_RCTL_PMCF;
3094 rctl &= ~E1000_RCTL_PMCF;
3096 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3097 E1000_WRITE_FLUSH(hw);
3102 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
3106 #define E1000_RAH_POOLSEL_SHIFT (18)
3108 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
3109 uint32_t index, uint32_t pool)
3111 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3114 e1000_rar_set(hw, mac_addr->addr_bytes, index);
3115 rah = E1000_READ_REG(hw, E1000_RAH(index));
3116 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
3117 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
3122 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
3124 uint8_t addr[ETHER_ADDR_LEN];
3125 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3127 memset(addr, 0, sizeof(addr));
3129 e1000_rar_set(hw, addr, index);
3133 eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
3134 struct ether_addr *addr)
3136 eth_igb_rar_clear(dev, 0);
3138 eth_igb_rar_set(dev, (void *)addr, 0, 0);
3141 * Virtual Function operations
3144 igbvf_intr_disable(struct e1000_hw *hw)
3146 PMD_INIT_FUNC_TRACE();
3148 /* Clear interrupt mask to stop from interrupts being generated */
3149 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
3151 E1000_WRITE_FLUSH(hw);
3155 igbvf_stop_adapter(struct rte_eth_dev *dev)
3159 struct rte_eth_dev_info dev_info;
3160 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3162 memset(&dev_info, 0, sizeof(dev_info));
3163 eth_igbvf_infos_get(dev, &dev_info);
3165 /* Clear interrupt mask to stop from interrupts being generated */
3166 igbvf_intr_disable(hw);
3168 /* Clear any pending interrupts, flush previous writes */
3169 E1000_READ_REG(hw, E1000_EICR);
3171 /* Disable the transmit unit. Each queue must be disabled. */
3172 for (i = 0; i < dev_info.max_tx_queues; i++)
3173 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
3175 /* Disable the receive unit by stopping each queue */
3176 for (i = 0; i < dev_info.max_rx_queues; i++) {
3177 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
3178 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
3179 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
3180 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
3184 /* flush all queues disables */
3185 E1000_WRITE_FLUSH(hw);
3189 static int eth_igbvf_link_update(struct e1000_hw *hw)
3191 struct e1000_mbx_info *mbx = &hw->mbx;
3192 struct e1000_mac_info *mac = &hw->mac;
3193 int ret_val = E1000_SUCCESS;
3195 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
3198 * We only want to run this if there has been a rst asserted.
3199 * in this case that could mean a link change, device reset,
3200 * or a virtual function reset
3203 /* If we were hit with a reset or timeout drop the link */
3204 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
3205 mac->get_link_status = TRUE;
3207 if (!mac->get_link_status)
3210 /* if link status is down no point in checking to see if pf is up */
3211 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
3214 /* if we passed all the tests above then the link is up and we no
3215 * longer need to check for link */
3216 mac->get_link_status = FALSE;
3224 igbvf_dev_configure(struct rte_eth_dev *dev)
3226 struct rte_eth_conf* conf = &dev->data->dev_conf;
3228 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
3229 dev->data->port_id);
3232 * VF has no ability to enable/disable HW CRC
3233 * Keep the persistent behavior the same as Host PF
3235 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
3236 if (!conf->rxmode.hw_strip_crc) {
3237 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
3238 conf->rxmode.hw_strip_crc = 1;
3241 if (conf->rxmode.hw_strip_crc) {
3242 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
3243 conf->rxmode.hw_strip_crc = 0;
3251 igbvf_dev_start(struct rte_eth_dev *dev)
3253 struct e1000_hw *hw =
3254 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3255 struct e1000_adapter *adapter =
3256 E1000_DEV_PRIVATE(dev->data->dev_private);
3257 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3258 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3260 uint32_t intr_vector = 0;
3262 PMD_INIT_FUNC_TRACE();
3264 hw->mac.ops.reset_hw(hw);
3265 adapter->stopped = 0;
3268 igbvf_set_vfta_all(dev,1);
3270 eth_igbvf_tx_init(dev);
3272 /* This can fail when allocating mbufs for descriptor rings */
3273 ret = eth_igbvf_rx_init(dev);
3275 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
3276 igb_dev_clear_queues(dev);
3280 /* check and configure queue intr-vector mapping */
3281 if (dev->data->dev_conf.intr_conf.rxq != 0) {
3282 intr_vector = dev->data->nb_rx_queues;
3283 ret = rte_intr_efd_enable(intr_handle, intr_vector);
3288 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
3289 intr_handle->intr_vec =
3290 rte_zmalloc("intr_vec",
3291 dev->data->nb_rx_queues * sizeof(int), 0);
3292 if (!intr_handle->intr_vec) {
3293 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
3294 " intr_vec", dev->data->nb_rx_queues);
3299 eth_igbvf_configure_msix_intr(dev);
3301 /* enable uio/vfio intr/eventfd mapping */
3302 rte_intr_enable(intr_handle);
3304 /* resume enabled intr since hw reset */
3305 igbvf_intr_enable(dev);
3311 igbvf_dev_stop(struct rte_eth_dev *dev)
3313 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3314 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3316 PMD_INIT_FUNC_TRACE();
3318 igbvf_stop_adapter(dev);
3321 * Clear what we set, but we still keep shadow_vfta to
3322 * restore after device starts
3324 igbvf_set_vfta_all(dev,0);
3326 igb_dev_clear_queues(dev);
3328 /* disable intr eventfd mapping */
3329 rte_intr_disable(intr_handle);
3331 /* Clean datapath event and queue/vec mapping */
3332 rte_intr_efd_disable(intr_handle);
3333 if (intr_handle->intr_vec) {
3334 rte_free(intr_handle->intr_vec);
3335 intr_handle->intr_vec = NULL;
3340 igbvf_dev_close(struct rte_eth_dev *dev)
3342 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3343 struct e1000_adapter *adapter =
3344 E1000_DEV_PRIVATE(dev->data->dev_private);
3345 struct ether_addr addr;
3347 PMD_INIT_FUNC_TRACE();
3351 igbvf_dev_stop(dev);
3352 adapter->stopped = 1;
3353 igb_dev_free_queues(dev);
3356 * reprogram the RAR with a zero mac address,
3357 * to ensure that the VF traffic goes to the PF
3358 * after stop, close and detach of the VF.
3361 memset(&addr, 0, sizeof(addr));
3362 igbvf_default_mac_addr_set(dev, &addr);
3366 igbvf_promiscuous_enable(struct rte_eth_dev *dev)
3368 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3370 /* Set both unicast and multicast promisc */
3371 e1000_promisc_set_vf(hw, e1000_promisc_enabled);
3375 igbvf_promiscuous_disable(struct rte_eth_dev *dev)
3377 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3379 /* If in allmulticast mode leave multicast promisc */
3380 if (dev->data->all_multicast == 1)
3381 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3383 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3387 igbvf_allmulticast_enable(struct rte_eth_dev *dev)
3389 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3391 /* In promiscuous mode multicast promisc already set */
3392 if (dev->data->promiscuous == 0)
3393 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3397 igbvf_allmulticast_disable(struct rte_eth_dev *dev)
3399 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3401 /* In promiscuous mode leave multicast promisc enabled */
3402 if (dev->data->promiscuous == 0)
3403 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3406 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
3408 struct e1000_mbx_info *mbx = &hw->mbx;
3412 /* After set vlan, vlan strip will also be enabled in igb driver*/
3413 msgbuf[0] = E1000_VF_SET_VLAN;
3415 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
3417 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
3419 err = mbx->ops.write_posted(hw, msgbuf, 2, 0);
3423 err = mbx->ops.read_posted(hw, msgbuf, 2, 0);
3427 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
3428 if (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK))
3435 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
3437 struct e1000_hw *hw =
3438 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3439 struct e1000_vfta * shadow_vfta =
3440 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3441 int i = 0, j = 0, vfta = 0, mask = 1;
3443 for (i = 0; i < IGB_VFTA_SIZE; i++){
3444 vfta = shadow_vfta->vfta[i];
3447 for (j = 0; j < 32; j++){
3450 (uint16_t)((i<<5)+j), on);
3459 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3461 struct e1000_hw *hw =
3462 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3463 struct e1000_vfta * shadow_vfta =
3464 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3465 uint32_t vid_idx = 0;
3466 uint32_t vid_bit = 0;
3469 PMD_INIT_FUNC_TRACE();
3471 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
3472 ret = igbvf_set_vfta(hw, vlan_id, !!on);
3474 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
3477 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
3478 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
3480 /*Save what we set and retore it after device reset*/
3482 shadow_vfta->vfta[vid_idx] |= vid_bit;
3484 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
3490 igbvf_default_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *addr)
3492 struct e1000_hw *hw =
3493 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3495 /* index is not used by rar_set() */
3496 hw->mac.ops.rar_set(hw, (void *)addr, 0);
3501 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
3502 struct rte_eth_rss_reta_entry64 *reta_conf,
3507 uint16_t idx, shift;
3508 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3510 if (reta_size != ETH_RSS_RETA_SIZE_128) {
3511 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3512 "(%d) doesn't match the number hardware can supported "
3513 "(%d)", reta_size, ETH_RSS_RETA_SIZE_128);
3517 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3518 idx = i / RTE_RETA_GROUP_SIZE;
3519 shift = i % RTE_RETA_GROUP_SIZE;
3520 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3524 if (mask == IGB_4_BIT_MASK)
3527 r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3528 for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
3529 if (mask & (0x1 << j))
3530 reta |= reta_conf[idx].reta[shift + j] <<
3533 reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
3535 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
3542 eth_igb_rss_reta_query(struct rte_eth_dev *dev,
3543 struct rte_eth_rss_reta_entry64 *reta_conf,
3548 uint16_t idx, shift;
3549 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3551 if (reta_size != ETH_RSS_RETA_SIZE_128) {
3552 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3553 "(%d) doesn't match the number hardware can supported "
3554 "(%d)", reta_size, ETH_RSS_RETA_SIZE_128);
3558 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3559 idx = i / RTE_RETA_GROUP_SIZE;
3560 shift = i % RTE_RETA_GROUP_SIZE;
3561 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3565 reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3566 for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
3567 if (mask & (0x1 << j))
3568 reta_conf[idx].reta[shift + j] =
3569 ((reta >> (CHAR_BIT * j)) &
3578 eth_igb_syn_filter_set(struct rte_eth_dev *dev,
3579 struct rte_eth_syn_filter *filter,
3582 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3583 struct e1000_filter_info *filter_info =
3584 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3585 uint32_t synqf, rfctl;
3587 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3590 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3593 if (synqf & E1000_SYN_FILTER_ENABLE)
3596 synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
3597 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
3599 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3600 if (filter->hig_pri)
3601 rfctl |= E1000_RFCTL_SYNQFP;
3603 rfctl &= ~E1000_RFCTL_SYNQFP;
3605 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
3607 if (!(synqf & E1000_SYN_FILTER_ENABLE))
3612 filter_info->syn_info = synqf;
3613 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
3614 E1000_WRITE_FLUSH(hw);
3619 eth_igb_syn_filter_get(struct rte_eth_dev *dev,
3620 struct rte_eth_syn_filter *filter)
3622 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3623 uint32_t synqf, rfctl;
3625 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3626 if (synqf & E1000_SYN_FILTER_ENABLE) {
3627 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3628 filter->hig_pri = (rfctl & E1000_RFCTL_SYNQFP) ? 1 : 0;
3629 filter->queue = (uint8_t)((synqf & E1000_SYN_FILTER_QUEUE) >>
3630 E1000_SYN_FILTER_QUEUE_SHIFT);
3638 eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
3639 enum rte_filter_op filter_op,
3642 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3645 MAC_TYPE_FILTER_SUP(hw->mac.type);
3647 if (filter_op == RTE_ETH_FILTER_NOP)
3651 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3656 switch (filter_op) {
3657 case RTE_ETH_FILTER_ADD:
3658 ret = eth_igb_syn_filter_set(dev,
3659 (struct rte_eth_syn_filter *)arg,
3662 case RTE_ETH_FILTER_DELETE:
3663 ret = eth_igb_syn_filter_set(dev,
3664 (struct rte_eth_syn_filter *)arg,
3667 case RTE_ETH_FILTER_GET:
3668 ret = eth_igb_syn_filter_get(dev,
3669 (struct rte_eth_syn_filter *)arg);
3672 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
3680 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
3682 ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
3683 struct e1000_2tuple_filter_info *filter_info)
3685 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3687 if (filter->priority > E1000_2TUPLE_MAX_PRI)
3688 return -EINVAL; /* filter index is out of range. */
3689 if (filter->tcp_flags > TCP_FLAG_ALL)
3690 return -EINVAL; /* flags is invalid. */
3692 switch (filter->dst_port_mask) {
3694 filter_info->dst_port_mask = 0;
3695 filter_info->dst_port = filter->dst_port;
3698 filter_info->dst_port_mask = 1;
3701 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3705 switch (filter->proto_mask) {
3707 filter_info->proto_mask = 0;
3708 filter_info->proto = filter->proto;
3711 filter_info->proto_mask = 1;
3714 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3718 filter_info->priority = (uint8_t)filter->priority;
3719 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3720 filter_info->tcp_flags = filter->tcp_flags;
3722 filter_info->tcp_flags = 0;
3727 static inline struct e1000_2tuple_filter *
3728 igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
3729 struct e1000_2tuple_filter_info *key)
3731 struct e1000_2tuple_filter *it;
3733 TAILQ_FOREACH(it, filter_list, entries) {
3734 if (memcmp(key, &it->filter_info,
3735 sizeof(struct e1000_2tuple_filter_info)) == 0) {
3742 /* inject a igb 2tuple filter to HW */
3744 igb_inject_2uple_filter(struct rte_eth_dev *dev,
3745 struct e1000_2tuple_filter *filter)
3747 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3748 uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
3749 uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3753 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3754 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3755 imir |= E1000_IMIR_PORT_BP;
3757 imir &= ~E1000_IMIR_PORT_BP;
3759 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3761 ttqf |= E1000_TTQF_QUEUE_ENABLE;
3762 ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
3763 ttqf |= (uint32_t)(filter->filter_info.proto &
3764 E1000_TTQF_PROTOCOL_MASK);
3765 if (filter->filter_info.proto_mask == 0)
3766 ttqf &= ~E1000_TTQF_MASK_ENABLE;
3768 /* tcp flags bits setting. */
3769 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3770 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3771 imir_ext |= E1000_IMIREXT_CTRL_URG;
3772 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3773 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3774 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3775 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3776 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3777 imir_ext |= E1000_IMIREXT_CTRL_RST;
3778 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3779 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3780 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3781 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3783 imir_ext |= E1000_IMIREXT_CTRL_BP;
3785 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3786 E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
3787 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3791 * igb_add_2tuple_filter - add a 2tuple filter
3794 * dev: Pointer to struct rte_eth_dev.
3795 * ntuple_filter: ponter to the filter that will be added.
3798 * - On success, zero.
3799 * - On failure, a negative value.
3802 igb_add_2tuple_filter(struct rte_eth_dev *dev,
3803 struct rte_eth_ntuple_filter *ntuple_filter)
3805 struct e1000_filter_info *filter_info =
3806 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3807 struct e1000_2tuple_filter *filter;
3810 filter = rte_zmalloc("e1000_2tuple_filter",
3811 sizeof(struct e1000_2tuple_filter), 0);
3815 ret = ntuple_filter_to_2tuple(ntuple_filter,
3816 &filter->filter_info);
3821 if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3822 &filter->filter_info) != NULL) {
3823 PMD_DRV_LOG(ERR, "filter exists.");
3827 filter->queue = ntuple_filter->queue;
3830 * look for an unused 2tuple filter index,
3831 * and insert the filter to list.
3833 for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
3834 if (!(filter_info->twotuple_mask & (1 << i))) {
3835 filter_info->twotuple_mask |= 1 << i;
3837 TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
3843 if (i >= E1000_MAX_TTQF_FILTERS) {
3844 PMD_DRV_LOG(ERR, "2tuple filters are full.");
3849 igb_inject_2uple_filter(dev, filter);
3854 * igb_remove_2tuple_filter - remove a 2tuple filter
3857 * dev: Pointer to struct rte_eth_dev.
3858 * ntuple_filter: ponter to the filter that will be removed.
3861 * - On success, zero.
3862 * - On failure, a negative value.
3865 igb_remove_2tuple_filter(struct rte_eth_dev *dev,
3866 struct rte_eth_ntuple_filter *ntuple_filter)
3868 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3869 struct e1000_filter_info *filter_info =
3870 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3871 struct e1000_2tuple_filter_info filter_2tuple;
3872 struct e1000_2tuple_filter *filter;
3875 memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
3876 ret = ntuple_filter_to_2tuple(ntuple_filter,
3881 filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3883 if (filter == NULL) {
3884 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3888 filter_info->twotuple_mask &= ~(1 << filter->index);
3889 TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
3892 E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
3893 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3894 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3898 /* inject a igb flex filter to HW */
3900 igb_inject_flex_filter(struct rte_eth_dev *dev,
3901 struct e1000_flex_filter *filter)
3903 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3904 uint32_t wufc, queueing;
3908 wufc = E1000_READ_REG(hw, E1000_WUFC);
3909 if (filter->index < E1000_MAX_FHFT)
3910 reg_off = E1000_FHFT(filter->index);
3912 reg_off = E1000_FHFT_EXT(filter->index - E1000_MAX_FHFT);
3914 E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
3915 (E1000_WUFC_FLX0 << filter->index));
3916 queueing = filter->filter_info.len |
3917 (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
3918 (filter->filter_info.priority <<
3919 E1000_FHFT_QUEUEING_PRIO_SHIFT);
3920 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
3923 for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
3924 E1000_WRITE_REG(hw, reg_off,
3925 filter->filter_info.dwords[j]);
3926 reg_off += sizeof(uint32_t);
3927 E1000_WRITE_REG(hw, reg_off,
3928 filter->filter_info.dwords[++j]);
3929 reg_off += sizeof(uint32_t);
3930 E1000_WRITE_REG(hw, reg_off,
3931 (uint32_t)filter->filter_info.mask[i]);
3932 reg_off += sizeof(uint32_t) * 2;
3937 static inline struct e1000_flex_filter *
3938 eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
3939 struct e1000_flex_filter_info *key)
3941 struct e1000_flex_filter *it;
3943 TAILQ_FOREACH(it, filter_list, entries) {
3944 if (memcmp(key, &it->filter_info,
3945 sizeof(struct e1000_flex_filter_info)) == 0)
3952 /* remove a flex byte filter
3954 * dev: Pointer to struct rte_eth_dev.
3955 * filter: the pointer of the filter will be removed.
3958 igb_remove_flex_filter(struct rte_eth_dev *dev,
3959 struct e1000_flex_filter *filter)
3961 struct e1000_filter_info *filter_info =
3962 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3963 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3967 wufc = E1000_READ_REG(hw, E1000_WUFC);
3968 if (filter->index < E1000_MAX_FHFT)
3969 reg_off = E1000_FHFT(filter->index);
3971 reg_off = E1000_FHFT_EXT(filter->index - E1000_MAX_FHFT);
3973 for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
3974 E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
3976 E1000_WRITE_REG(hw, E1000_WUFC, wufc &
3977 (~(E1000_WUFC_FLX0 << filter->index)));
3979 filter_info->flex_mask &= ~(1 << filter->index);
3980 TAILQ_REMOVE(&filter_info->flex_list, filter, entries);
3985 eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
3986 struct rte_eth_flex_filter *filter,
3989 struct e1000_filter_info *filter_info =
3990 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3991 struct e1000_flex_filter *flex_filter, *it;
3995 flex_filter = rte_zmalloc("e1000_flex_filter",
3996 sizeof(struct e1000_flex_filter), 0);
3997 if (flex_filter == NULL)
4000 flex_filter->filter_info.len = filter->len;
4001 flex_filter->filter_info.priority = filter->priority;
4002 memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
4003 for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
4005 /* reverse bits in flex filter's mask*/
4006 for (shift = 0; shift < CHAR_BIT; shift++) {
4007 if (filter->mask[i] & (0x01 << shift))
4008 mask |= (0x80 >> shift);
4010 flex_filter->filter_info.mask[i] = mask;
4013 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
4014 &flex_filter->filter_info);
4015 if (it == NULL && !add) {
4016 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4017 rte_free(flex_filter);
4020 if (it != NULL && add) {
4021 PMD_DRV_LOG(ERR, "filter exists.");
4022 rte_free(flex_filter);
4027 flex_filter->queue = filter->queue;
4029 * look for an unused flex filter index
4030 * and insert the filter into the list.
4032 for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
4033 if (!(filter_info->flex_mask & (1 << i))) {
4034 filter_info->flex_mask |= 1 << i;
4035 flex_filter->index = i;
4036 TAILQ_INSERT_TAIL(&filter_info->flex_list,
4042 if (i >= E1000_MAX_FLEX_FILTERS) {
4043 PMD_DRV_LOG(ERR, "flex filters are full.");
4044 rte_free(flex_filter);
4048 igb_inject_flex_filter(dev, flex_filter);
4051 igb_remove_flex_filter(dev, it);
4052 rte_free(flex_filter);
4059 eth_igb_get_flex_filter(struct rte_eth_dev *dev,
4060 struct rte_eth_flex_filter *filter)
4062 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4063 struct e1000_filter_info *filter_info =
4064 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4065 struct e1000_flex_filter flex_filter, *it;
4066 uint32_t wufc, queueing, wufc_en = 0;
4068 memset(&flex_filter, 0, sizeof(struct e1000_flex_filter));
4069 flex_filter.filter_info.len = filter->len;
4070 flex_filter.filter_info.priority = filter->priority;
4071 memcpy(flex_filter.filter_info.dwords, filter->bytes, filter->len);
4072 memcpy(flex_filter.filter_info.mask, filter->mask,
4073 RTE_ALIGN(filter->len, sizeof(char)) / sizeof(char));
4075 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
4076 &flex_filter.filter_info);
4078 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4082 wufc = E1000_READ_REG(hw, E1000_WUFC);
4083 wufc_en = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << it->index);
4085 if ((wufc & wufc_en) == wufc_en) {
4086 uint32_t reg_off = 0;
4087 if (it->index < E1000_MAX_FHFT)
4088 reg_off = E1000_FHFT(it->index);
4090 reg_off = E1000_FHFT_EXT(it->index - E1000_MAX_FHFT);
4092 queueing = E1000_READ_REG(hw,
4093 reg_off + E1000_FHFT_QUEUEING_OFFSET);
4094 filter->len = queueing & E1000_FHFT_QUEUEING_LEN;
4095 filter->priority = (queueing & E1000_FHFT_QUEUEING_PRIO) >>
4096 E1000_FHFT_QUEUEING_PRIO_SHIFT;
4097 filter->queue = (queueing & E1000_FHFT_QUEUEING_QUEUE) >>
4098 E1000_FHFT_QUEUEING_QUEUE_SHIFT;
4105 eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
4106 enum rte_filter_op filter_op,
4109 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4110 struct rte_eth_flex_filter *filter;
4113 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
4115 if (filter_op == RTE_ETH_FILTER_NOP)
4119 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
4124 filter = (struct rte_eth_flex_filter *)arg;
4125 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN
4126 || filter->len % sizeof(uint64_t) != 0) {
4127 PMD_DRV_LOG(ERR, "filter's length is out of range");
4130 if (filter->priority > E1000_MAX_FLEX_FILTER_PRI) {
4131 PMD_DRV_LOG(ERR, "filter's priority is out of range");
4135 switch (filter_op) {
4136 case RTE_ETH_FILTER_ADD:
4137 ret = eth_igb_add_del_flex_filter(dev, filter, TRUE);
4139 case RTE_ETH_FILTER_DELETE:
4140 ret = eth_igb_add_del_flex_filter(dev, filter, FALSE);
4142 case RTE_ETH_FILTER_GET:
4143 ret = eth_igb_get_flex_filter(dev, filter);
4146 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
4154 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
4156 ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
4157 struct e1000_5tuple_filter_info *filter_info)
4159 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
4161 if (filter->priority > E1000_2TUPLE_MAX_PRI)
4162 return -EINVAL; /* filter index is out of range. */
4163 if (filter->tcp_flags > TCP_FLAG_ALL)
4164 return -EINVAL; /* flags is invalid. */
4166 switch (filter->dst_ip_mask) {
4168 filter_info->dst_ip_mask = 0;
4169 filter_info->dst_ip = filter->dst_ip;
4172 filter_info->dst_ip_mask = 1;
4175 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
4179 switch (filter->src_ip_mask) {
4181 filter_info->src_ip_mask = 0;
4182 filter_info->src_ip = filter->src_ip;
4185 filter_info->src_ip_mask = 1;
4188 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
4192 switch (filter->dst_port_mask) {
4194 filter_info->dst_port_mask = 0;
4195 filter_info->dst_port = filter->dst_port;
4198 filter_info->dst_port_mask = 1;
4201 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
4205 switch (filter->src_port_mask) {
4207 filter_info->src_port_mask = 0;
4208 filter_info->src_port = filter->src_port;
4211 filter_info->src_port_mask = 1;
4214 PMD_DRV_LOG(ERR, "invalid src_port mask.");
4218 switch (filter->proto_mask) {
4220 filter_info->proto_mask = 0;
4221 filter_info->proto = filter->proto;
4224 filter_info->proto_mask = 1;
4227 PMD_DRV_LOG(ERR, "invalid protocol mask.");
4231 filter_info->priority = (uint8_t)filter->priority;
4232 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
4233 filter_info->tcp_flags = filter->tcp_flags;
4235 filter_info->tcp_flags = 0;
4240 static inline struct e1000_5tuple_filter *
4241 igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
4242 struct e1000_5tuple_filter_info *key)
4244 struct e1000_5tuple_filter *it;
4246 TAILQ_FOREACH(it, filter_list, entries) {
4247 if (memcmp(key, &it->filter_info,
4248 sizeof(struct e1000_5tuple_filter_info)) == 0) {
4255 /* inject a igb 5-tuple filter to HW */
4257 igb_inject_5tuple_filter_82576(struct rte_eth_dev *dev,
4258 struct e1000_5tuple_filter *filter)
4260 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4261 uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
4262 uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
4266 ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
4267 if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
4268 ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
4269 if (filter->filter_info.dst_ip_mask == 0)
4270 ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
4271 if (filter->filter_info.src_port_mask == 0)
4272 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
4273 if (filter->filter_info.proto_mask == 0)
4274 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
4275 ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
4276 E1000_FTQF_QUEUE_MASK;
4277 ftqf |= E1000_FTQF_QUEUE_ENABLE;
4278 E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
4279 E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
4280 E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
4282 spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
4283 E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
4285 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
4286 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
4287 imir |= E1000_IMIR_PORT_BP;
4289 imir &= ~E1000_IMIR_PORT_BP;
4290 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
4292 /* tcp flags bits setting. */
4293 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
4294 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
4295 imir_ext |= E1000_IMIREXT_CTRL_URG;
4296 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
4297 imir_ext |= E1000_IMIREXT_CTRL_ACK;
4298 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
4299 imir_ext |= E1000_IMIREXT_CTRL_PSH;
4300 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
4301 imir_ext |= E1000_IMIREXT_CTRL_RST;
4302 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
4303 imir_ext |= E1000_IMIREXT_CTRL_SYN;
4304 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
4305 imir_ext |= E1000_IMIREXT_CTRL_FIN;
4307 imir_ext |= E1000_IMIREXT_CTRL_BP;
4309 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
4310 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
4314 * igb_add_5tuple_filter_82576 - add a 5tuple filter
4317 * dev: Pointer to struct rte_eth_dev.
4318 * ntuple_filter: ponter to the filter that will be added.
4321 * - On success, zero.
4322 * - On failure, a negative value.
4325 igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
4326 struct rte_eth_ntuple_filter *ntuple_filter)
4328 struct e1000_filter_info *filter_info =
4329 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4330 struct e1000_5tuple_filter *filter;
4334 filter = rte_zmalloc("e1000_5tuple_filter",
4335 sizeof(struct e1000_5tuple_filter), 0);
4339 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4340 &filter->filter_info);
4346 if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4347 &filter->filter_info) != NULL) {
4348 PMD_DRV_LOG(ERR, "filter exists.");
4352 filter->queue = ntuple_filter->queue;
4355 * look for an unused 5tuple filter index,
4356 * and insert the filter to list.
4358 for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
4359 if (!(filter_info->fivetuple_mask & (1 << i))) {
4360 filter_info->fivetuple_mask |= 1 << i;
4362 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
4368 if (i >= E1000_MAX_FTQF_FILTERS) {
4369 PMD_DRV_LOG(ERR, "5tuple filters are full.");
4374 igb_inject_5tuple_filter_82576(dev, filter);
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_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4394 struct e1000_filter_info *filter_info =
4395 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4396 struct e1000_5tuple_filter_info filter_5tuple;
4397 struct e1000_5tuple_filter *filter;
4400 memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
4401 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4406 filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4408 if (filter == NULL) {
4409 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4413 filter_info->fivetuple_mask &= ~(1 << filter->index);
4414 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
4417 E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
4418 E1000_FTQF_VF_BP | E1000_FTQF_MASK);
4419 E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
4420 E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
4421 E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
4422 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
4423 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
4428 eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
4431 struct e1000_hw *hw;
4432 struct rte_eth_dev_info dev_info;
4433 uint32_t frame_size = mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN +
4436 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4438 #ifdef RTE_LIBRTE_82571_SUPPORT
4439 /* XXX: not bigger than max_rx_pktlen */
4440 if (hw->mac.type == e1000_82571)
4443 eth_igb_infos_get(dev, &dev_info);
4445 /* check that mtu is within the allowed range */
4446 if ((mtu < ETHER_MIN_MTU) ||
4447 (frame_size > dev_info.max_rx_pktlen))
4450 /* refuse mtu that requires the support of scattered packets when this
4451 * feature has not been enabled before. */
4452 if (!dev->data->scattered_rx &&
4453 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)
4456 rctl = E1000_READ_REG(hw, E1000_RCTL);
4458 /* switch to jumbo mode if needed */
4459 if (frame_size > ETHER_MAX_LEN) {
4460 dev->data->dev_conf.rxmode.jumbo_frame = 1;
4461 rctl |= E1000_RCTL_LPE;
4463 dev->data->dev_conf.rxmode.jumbo_frame = 0;
4464 rctl &= ~E1000_RCTL_LPE;
4466 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
4468 /* update max frame size */
4469 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
4471 E1000_WRITE_REG(hw, E1000_RLPML,
4472 dev->data->dev_conf.rxmode.max_rx_pkt_len);
4478 * igb_add_del_ntuple_filter - add or delete a ntuple filter
4481 * dev: Pointer to struct rte_eth_dev.
4482 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4483 * add: if true, add filter, if false, remove filter
4486 * - On success, zero.
4487 * - On failure, a negative value.
4490 igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
4491 struct rte_eth_ntuple_filter *ntuple_filter,
4494 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4497 switch (ntuple_filter->flags) {
4498 case RTE_5TUPLE_FLAGS:
4499 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4500 if (hw->mac.type != e1000_82576)
4503 ret = igb_add_5tuple_filter_82576(dev,
4506 ret = igb_remove_5tuple_filter_82576(dev,
4509 case RTE_2TUPLE_FLAGS:
4510 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4511 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350 &&
4512 hw->mac.type != e1000_i210 &&
4513 hw->mac.type != e1000_i211)
4516 ret = igb_add_2tuple_filter(dev, ntuple_filter);
4518 ret = igb_remove_2tuple_filter(dev, ntuple_filter);
4529 * igb_get_ntuple_filter - get a ntuple filter
4532 * dev: Pointer to struct rte_eth_dev.
4533 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4536 * - On success, zero.
4537 * - On failure, a negative value.
4540 igb_get_ntuple_filter(struct rte_eth_dev *dev,
4541 struct rte_eth_ntuple_filter *ntuple_filter)
4543 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4544 struct e1000_filter_info *filter_info =
4545 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4546 struct e1000_5tuple_filter_info filter_5tuple;
4547 struct e1000_2tuple_filter_info filter_2tuple;
4548 struct e1000_5tuple_filter *p_5tuple_filter;
4549 struct e1000_2tuple_filter *p_2tuple_filter;
4552 switch (ntuple_filter->flags) {
4553 case RTE_5TUPLE_FLAGS:
4554 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4555 if (hw->mac.type != e1000_82576)
4557 memset(&filter_5tuple,
4559 sizeof(struct e1000_5tuple_filter_info));
4560 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4564 p_5tuple_filter = igb_5tuple_filter_lookup_82576(
4565 &filter_info->fivetuple_list,
4567 if (p_5tuple_filter == NULL) {
4568 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4571 ntuple_filter->queue = p_5tuple_filter->queue;
4573 case RTE_2TUPLE_FLAGS:
4574 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4575 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
4577 memset(&filter_2tuple,
4579 sizeof(struct e1000_2tuple_filter_info));
4580 ret = ntuple_filter_to_2tuple(ntuple_filter, &filter_2tuple);
4583 p_2tuple_filter = igb_2tuple_filter_lookup(
4584 &filter_info->twotuple_list,
4586 if (p_2tuple_filter == NULL) {
4587 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4590 ntuple_filter->queue = p_2tuple_filter->queue;
4601 * igb_ntuple_filter_handle - Handle operations for ntuple filter.
4602 * @dev: pointer to rte_eth_dev structure
4603 * @filter_op:operation will be taken.
4604 * @arg: a pointer to specific structure corresponding to the filter_op
4607 igb_ntuple_filter_handle(struct rte_eth_dev *dev,
4608 enum rte_filter_op filter_op,
4611 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4614 MAC_TYPE_FILTER_SUP(hw->mac.type);
4616 if (filter_op == RTE_ETH_FILTER_NOP)
4620 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4625 switch (filter_op) {
4626 case RTE_ETH_FILTER_ADD:
4627 ret = igb_add_del_ntuple_filter(dev,
4628 (struct rte_eth_ntuple_filter *)arg,
4631 case RTE_ETH_FILTER_DELETE:
4632 ret = igb_add_del_ntuple_filter(dev,
4633 (struct rte_eth_ntuple_filter *)arg,
4636 case RTE_ETH_FILTER_GET:
4637 ret = igb_get_ntuple_filter(dev,
4638 (struct rte_eth_ntuple_filter *)arg);
4641 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4649 igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
4654 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4655 if (filter_info->ethertype_filters[i].ethertype == ethertype &&
4656 (filter_info->ethertype_mask & (1 << i)))
4663 igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
4664 uint16_t ethertype, uint32_t etqf)
4668 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4669 if (!(filter_info->ethertype_mask & (1 << i))) {
4670 filter_info->ethertype_mask |= 1 << i;
4671 filter_info->ethertype_filters[i].ethertype = ethertype;
4672 filter_info->ethertype_filters[i].etqf = etqf;
4680 igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
4683 if (idx >= E1000_MAX_ETQF_FILTERS)
4685 filter_info->ethertype_mask &= ~(1 << idx);
4686 filter_info->ethertype_filters[idx].ethertype = 0;
4687 filter_info->ethertype_filters[idx].etqf = 0;
4693 igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
4694 struct rte_eth_ethertype_filter *filter,
4697 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4698 struct e1000_filter_info *filter_info =
4699 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4703 if (filter->ether_type == ETHER_TYPE_IPv4 ||
4704 filter->ether_type == ETHER_TYPE_IPv6) {
4705 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
4706 " ethertype filter.", filter->ether_type);
4710 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
4711 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
4714 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
4715 PMD_DRV_LOG(ERR, "drop option is unsupported.");
4719 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4720 if (ret >= 0 && add) {
4721 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
4722 filter->ether_type);
4725 if (ret < 0 && !add) {
4726 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4727 filter->ether_type);
4732 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
4733 etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
4734 etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
4735 ret = igb_ethertype_filter_insert(filter_info,
4736 filter->ether_type, etqf);
4738 PMD_DRV_LOG(ERR, "ethertype filters are full.");
4742 ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
4746 E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
4747 E1000_WRITE_FLUSH(hw);
4753 igb_get_ethertype_filter(struct rte_eth_dev *dev,
4754 struct rte_eth_ethertype_filter *filter)
4756 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4757 struct e1000_filter_info *filter_info =
4758 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4762 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4764 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4765 filter->ether_type);
4769 etqf = E1000_READ_REG(hw, E1000_ETQF(ret));
4770 if (etqf & E1000_ETQF_FILTER_ENABLE) {
4771 filter->ether_type = etqf & E1000_ETQF_ETHERTYPE;
4773 filter->queue = (etqf & E1000_ETQF_QUEUE) >>
4774 E1000_ETQF_QUEUE_SHIFT;
4782 * igb_ethertype_filter_handle - Handle operations for ethertype filter.
4783 * @dev: pointer to rte_eth_dev structure
4784 * @filter_op:operation will be taken.
4785 * @arg: a pointer to specific structure corresponding to the filter_op
4788 igb_ethertype_filter_handle(struct rte_eth_dev *dev,
4789 enum rte_filter_op filter_op,
4792 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4795 MAC_TYPE_FILTER_SUP(hw->mac.type);
4797 if (filter_op == RTE_ETH_FILTER_NOP)
4801 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4806 switch (filter_op) {
4807 case RTE_ETH_FILTER_ADD:
4808 ret = igb_add_del_ethertype_filter(dev,
4809 (struct rte_eth_ethertype_filter *)arg,
4812 case RTE_ETH_FILTER_DELETE:
4813 ret = igb_add_del_ethertype_filter(dev,
4814 (struct rte_eth_ethertype_filter *)arg,
4817 case RTE_ETH_FILTER_GET:
4818 ret = igb_get_ethertype_filter(dev,
4819 (struct rte_eth_ethertype_filter *)arg);
4822 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4830 eth_igb_filter_ctrl(struct rte_eth_dev *dev,
4831 enum rte_filter_type filter_type,
4832 enum rte_filter_op filter_op,
4837 switch (filter_type) {
4838 case RTE_ETH_FILTER_NTUPLE:
4839 ret = igb_ntuple_filter_handle(dev, filter_op, arg);
4841 case RTE_ETH_FILTER_ETHERTYPE:
4842 ret = igb_ethertype_filter_handle(dev, filter_op, arg);
4844 case RTE_ETH_FILTER_SYN:
4845 ret = eth_igb_syn_filter_handle(dev, filter_op, arg);
4847 case RTE_ETH_FILTER_FLEXIBLE:
4848 ret = eth_igb_flex_filter_handle(dev, filter_op, arg);
4850 case RTE_ETH_FILTER_GENERIC:
4851 if (filter_op != RTE_ETH_FILTER_GET)
4853 *(const void **)arg = &igb_flow_ops;
4856 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
4865 eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
4866 struct ether_addr *mc_addr_set,
4867 uint32_t nb_mc_addr)
4869 struct e1000_hw *hw;
4871 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4872 e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
4877 igb_read_systime_cyclecounter(struct rte_eth_dev *dev)
4879 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4880 uint64_t systime_cycles;
4882 switch (hw->mac.type) {
4886 * Need to read System Time Residue Register to be able
4887 * to read the other two registers.
4889 E1000_READ_REG(hw, E1000_SYSTIMR);
4890 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
4891 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4892 systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4899 * Need to read System Time Residue Register to be able
4900 * to read the other two registers.
4902 E1000_READ_REG(hw, E1000_SYSTIMR);
4903 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4904 /* Only the 8 LSB are valid. */
4905 systime_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_SYSTIMH)
4909 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4910 systime_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4915 return systime_cycles;
4919 igb_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4921 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4922 uint64_t rx_tstamp_cycles;
4924 switch (hw->mac.type) {
4927 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4928 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4929 rx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4935 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4936 /* Only the 8 LSB are valid. */
4937 rx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_RXSTMPH)
4941 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4942 rx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4947 return rx_tstamp_cycles;
4951 igb_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4953 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4954 uint64_t tx_tstamp_cycles;
4956 switch (hw->mac.type) {
4959 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4960 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4961 tx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4967 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4968 /* Only the 8 LSB are valid. */
4969 tx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_TXSTMPH)
4973 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4974 tx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4979 return tx_tstamp_cycles;
4983 igb_start_timecounters(struct rte_eth_dev *dev)
4985 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4986 struct e1000_adapter *adapter =
4987 (struct e1000_adapter *)dev->data->dev_private;
4988 uint32_t incval = 1;
4990 uint64_t mask = E1000_CYCLECOUNTER_MASK;
4992 switch (hw->mac.type) {
4996 /* 32 LSB bits + 8 MSB bits = 40 bits */
4997 mask = (1ULL << 40) - 1;
5002 * Start incrementing the register
5003 * used to timestamp PTP packets.
5005 E1000_WRITE_REG(hw, E1000_TIMINCA, incval);
5008 incval = E1000_INCVALUE_82576;
5009 shift = IGB_82576_TSYNC_SHIFT;
5010 E1000_WRITE_REG(hw, E1000_TIMINCA,
5011 E1000_INCPERIOD_82576 | incval);
5018 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
5019 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
5020 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
5022 adapter->systime_tc.cc_mask = mask;
5023 adapter->systime_tc.cc_shift = shift;
5024 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
5026 adapter->rx_tstamp_tc.cc_mask = mask;
5027 adapter->rx_tstamp_tc.cc_shift = shift;
5028 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
5030 adapter->tx_tstamp_tc.cc_mask = mask;
5031 adapter->tx_tstamp_tc.cc_shift = shift;
5032 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
5036 igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
5038 struct e1000_adapter *adapter =
5039 (struct e1000_adapter *)dev->data->dev_private;
5041 adapter->systime_tc.nsec += delta;
5042 adapter->rx_tstamp_tc.nsec += delta;
5043 adapter->tx_tstamp_tc.nsec += delta;
5049 igb_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
5052 struct e1000_adapter *adapter =
5053 (struct e1000_adapter *)dev->data->dev_private;
5055 ns = rte_timespec_to_ns(ts);
5057 /* Set the timecounters to a new value. */
5058 adapter->systime_tc.nsec = ns;
5059 adapter->rx_tstamp_tc.nsec = ns;
5060 adapter->tx_tstamp_tc.nsec = ns;
5066 igb_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
5068 uint64_t ns, systime_cycles;
5069 struct e1000_adapter *adapter =
5070 (struct e1000_adapter *)dev->data->dev_private;
5072 systime_cycles = igb_read_systime_cyclecounter(dev);
5073 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
5074 *ts = rte_ns_to_timespec(ns);
5080 igb_timesync_enable(struct rte_eth_dev *dev)
5082 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5086 /* Stop the timesync system time. */
5087 E1000_WRITE_REG(hw, E1000_TIMINCA, 0x0);
5088 /* Reset the timesync system time value. */
5089 switch (hw->mac.type) {
5095 E1000_WRITE_REG(hw, E1000_SYSTIMR, 0x0);
5098 E1000_WRITE_REG(hw, E1000_SYSTIML, 0x0);
5099 E1000_WRITE_REG(hw, E1000_SYSTIMH, 0x0);
5102 /* Not supported. */
5106 /* Enable system time for it isn't on by default. */
5107 tsauxc = E1000_READ_REG(hw, E1000_TSAUXC);
5108 tsauxc &= ~E1000_TSAUXC_DISABLE_SYSTIME;
5109 E1000_WRITE_REG(hw, E1000_TSAUXC, tsauxc);
5111 igb_start_timecounters(dev);
5113 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
5114 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588),
5116 E1000_ETQF_FILTER_ENABLE |
5119 /* Enable timestamping of received PTP packets. */
5120 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5121 tsync_ctl |= E1000_TSYNCRXCTL_ENABLED;
5122 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
5124 /* Enable Timestamping of transmitted PTP packets. */
5125 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5126 tsync_ctl |= E1000_TSYNCTXCTL_ENABLED;
5127 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
5133 igb_timesync_disable(struct rte_eth_dev *dev)
5135 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5138 /* Disable timestamping of transmitted PTP packets. */
5139 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5140 tsync_ctl &= ~E1000_TSYNCTXCTL_ENABLED;
5141 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
5143 /* Disable timestamping of received PTP packets. */
5144 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5145 tsync_ctl &= ~E1000_TSYNCRXCTL_ENABLED;
5146 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
5148 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
5149 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588), 0);
5151 /* Stop incrementating the System Time registers. */
5152 E1000_WRITE_REG(hw, E1000_TIMINCA, 0);
5158 igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
5159 struct timespec *timestamp,
5160 uint32_t flags __rte_unused)
5162 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5163 struct e1000_adapter *adapter =
5164 (struct e1000_adapter *)dev->data->dev_private;
5165 uint32_t tsync_rxctl;
5166 uint64_t rx_tstamp_cycles;
5169 tsync_rxctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5170 if ((tsync_rxctl & E1000_TSYNCRXCTL_VALID) == 0)
5173 rx_tstamp_cycles = igb_read_rx_tstamp_cyclecounter(dev);
5174 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
5175 *timestamp = rte_ns_to_timespec(ns);
5181 igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
5182 struct timespec *timestamp)
5184 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5185 struct e1000_adapter *adapter =
5186 (struct e1000_adapter *)dev->data->dev_private;
5187 uint32_t tsync_txctl;
5188 uint64_t tx_tstamp_cycles;
5191 tsync_txctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5192 if ((tsync_txctl & E1000_TSYNCTXCTL_VALID) == 0)
5195 tx_tstamp_cycles = igb_read_tx_tstamp_cyclecounter(dev);
5196 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
5197 *timestamp = rte_ns_to_timespec(ns);
5203 eth_igb_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5207 const struct reg_info *reg_group;
5209 while ((reg_group = igb_regs[g_ind++]))
5210 count += igb_reg_group_count(reg_group);
5216 igbvf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5220 const struct reg_info *reg_group;
5222 while ((reg_group = igbvf_regs[g_ind++]))
5223 count += igb_reg_group_count(reg_group);
5229 eth_igb_get_regs(struct rte_eth_dev *dev,
5230 struct rte_dev_reg_info *regs)
5232 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5233 uint32_t *data = regs->data;
5236 const struct reg_info *reg_group;
5239 regs->length = eth_igb_get_reg_length(dev);
5240 regs->width = sizeof(uint32_t);
5244 /* Support only full register dump */
5245 if ((regs->length == 0) ||
5246 (regs->length == (uint32_t)eth_igb_get_reg_length(dev))) {
5247 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5249 while ((reg_group = igb_regs[g_ind++]))
5250 count += igb_read_regs_group(dev, &data[count],
5259 igbvf_get_regs(struct rte_eth_dev *dev,
5260 struct rte_dev_reg_info *regs)
5262 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5263 uint32_t *data = regs->data;
5266 const struct reg_info *reg_group;
5269 regs->length = igbvf_get_reg_length(dev);
5270 regs->width = sizeof(uint32_t);
5274 /* Support only full register dump */
5275 if ((regs->length == 0) ||
5276 (regs->length == (uint32_t)igbvf_get_reg_length(dev))) {
5277 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5279 while ((reg_group = igbvf_regs[g_ind++]))
5280 count += igb_read_regs_group(dev, &data[count],
5289 eth_igb_get_eeprom_length(struct rte_eth_dev *dev)
5291 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5293 /* Return unit is byte count */
5294 return hw->nvm.word_size * 2;
5298 eth_igb_get_eeprom(struct rte_eth_dev *dev,
5299 struct rte_dev_eeprom_info *in_eeprom)
5301 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5302 struct e1000_nvm_info *nvm = &hw->nvm;
5303 uint16_t *data = in_eeprom->data;
5306 first = in_eeprom->offset >> 1;
5307 length = in_eeprom->length >> 1;
5308 if ((first >= hw->nvm.word_size) ||
5309 ((first + length) >= hw->nvm.word_size))
5312 in_eeprom->magic = hw->vendor_id |
5313 ((uint32_t)hw->device_id << 16);
5315 if ((nvm->ops.read) == NULL)
5318 return nvm->ops.read(hw, first, length, data);
5322 eth_igb_set_eeprom(struct rte_eth_dev *dev,
5323 struct rte_dev_eeprom_info *in_eeprom)
5325 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5326 struct e1000_nvm_info *nvm = &hw->nvm;
5327 uint16_t *data = in_eeprom->data;
5330 first = in_eeprom->offset >> 1;
5331 length = in_eeprom->length >> 1;
5332 if ((first >= hw->nvm.word_size) ||
5333 ((first + length) >= hw->nvm.word_size))
5336 in_eeprom->magic = (uint32_t)hw->vendor_id |
5337 ((uint32_t)hw->device_id << 16);
5339 if ((nvm->ops.write) == NULL)
5341 return nvm->ops.write(hw, first, length, data);
5345 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
5347 struct e1000_hw *hw =
5348 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5349 uint32_t mask = 1 << queue_id;
5351 E1000_WRITE_REG(hw, E1000_EIMC, mask);
5352 E1000_WRITE_FLUSH(hw);
5358 eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
5360 struct e1000_hw *hw =
5361 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5362 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5363 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5364 uint32_t mask = 1 << queue_id;
5367 regval = E1000_READ_REG(hw, E1000_EIMS);
5368 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
5369 E1000_WRITE_FLUSH(hw);
5371 rte_intr_enable(intr_handle);
5377 eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
5378 uint8_t index, uint8_t offset)
5380 uint32_t val = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
5383 val &= ~((uint32_t)0xFF << offset);
5385 /* write vector and valid bit */
5386 val |= (msix_vector | E1000_IVAR_VALID) << offset;
5388 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, val);
5392 eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
5393 uint8_t queue, uint8_t msix_vector)
5397 if (hw->mac.type == e1000_82575) {
5399 tmp = E1000_EICR_RX_QUEUE0 << queue;
5400 else if (direction == 1)
5401 tmp = E1000_EICR_TX_QUEUE0 << queue;
5402 E1000_WRITE_REG(hw, E1000_MSIXBM(msix_vector), tmp);
5403 } else if (hw->mac.type == e1000_82576) {
5404 if ((direction == 0) || (direction == 1))
5405 eth_igb_write_ivar(hw, msix_vector, queue & 0x7,
5406 ((queue & 0x8) << 1) +
5408 } else if ((hw->mac.type == e1000_82580) ||
5409 (hw->mac.type == e1000_i350) ||
5410 (hw->mac.type == e1000_i354) ||
5411 (hw->mac.type == e1000_i210) ||
5412 (hw->mac.type == e1000_i211)) {
5413 if ((direction == 0) || (direction == 1))
5414 eth_igb_write_ivar(hw, msix_vector,
5416 ((queue & 0x1) << 4) +
5421 /* Sets up the hardware to generate MSI-X interrupts properly
5423 * board private structure
5426 eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
5429 uint32_t tmpval, regval, intr_mask;
5430 struct e1000_hw *hw =
5431 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5432 uint32_t vec = E1000_MISC_VEC_ID;
5433 uint32_t base = E1000_MISC_VEC_ID;
5434 uint32_t misc_shift = 0;
5435 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5436 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5438 /* won't configure msix register if no mapping is done
5439 * between intr vector and event fd
5441 if (!rte_intr_dp_is_en(intr_handle))
5444 if (rte_intr_allow_others(intr_handle)) {
5445 vec = base = E1000_RX_VEC_START;
5449 /* set interrupt vector for other causes */
5450 if (hw->mac.type == e1000_82575) {
5451 tmpval = E1000_READ_REG(hw, E1000_CTRL_EXT);
5452 /* enable MSI-X PBA support */
5453 tmpval |= E1000_CTRL_EXT_PBA_CLR;
5455 /* Auto-Mask interrupts upon ICR read */
5456 tmpval |= E1000_CTRL_EXT_EIAME;
5457 tmpval |= E1000_CTRL_EXT_IRCA;
5459 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmpval);
5461 /* enable msix_other interrupt */
5462 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), 0, E1000_EIMS_OTHER);
5463 regval = E1000_READ_REG(hw, E1000_EIAC);
5464 E1000_WRITE_REG(hw, E1000_EIAC, regval | E1000_EIMS_OTHER);
5465 regval = E1000_READ_REG(hw, E1000_EIAM);
5466 E1000_WRITE_REG(hw, E1000_EIMS, regval | E1000_EIMS_OTHER);
5467 } else if ((hw->mac.type == e1000_82576) ||
5468 (hw->mac.type == e1000_82580) ||
5469 (hw->mac.type == e1000_i350) ||
5470 (hw->mac.type == e1000_i354) ||
5471 (hw->mac.type == e1000_i210) ||
5472 (hw->mac.type == e1000_i211)) {
5473 /* turn on MSI-X capability first */
5474 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
5475 E1000_GPIE_PBA | E1000_GPIE_EIAME |
5477 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
5479 regval = E1000_READ_REG(hw, E1000_EIAC);
5480 E1000_WRITE_REG(hw, E1000_EIAC, regval | intr_mask);
5482 /* enable msix_other interrupt */
5483 regval = E1000_READ_REG(hw, E1000_EIMS);
5484 E1000_WRITE_REG(hw, E1000_EIMS, regval | intr_mask);
5485 tmpval = (dev->data->nb_rx_queues | E1000_IVAR_VALID) << 8;
5486 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmpval);
5489 /* use EIAM to auto-mask when MSI-X interrupt
5490 * is asserted, this saves a register write for every interrupt
5492 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
5494 regval = E1000_READ_REG(hw, E1000_EIAM);
5495 E1000_WRITE_REG(hw, E1000_EIAM, regval | intr_mask);
5497 for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
5498 eth_igb_assign_msix_vector(hw, 0, queue_id, vec);
5499 intr_handle->intr_vec[queue_id] = vec;
5500 if (vec < base + intr_handle->nb_efd - 1)
5504 E1000_WRITE_FLUSH(hw);
5507 /* restore n-tuple filter */
5509 igb_ntuple_filter_restore(struct rte_eth_dev *dev)
5511 struct e1000_filter_info *filter_info =
5512 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5513 struct e1000_5tuple_filter *p_5tuple;
5514 struct e1000_2tuple_filter *p_2tuple;
5516 TAILQ_FOREACH(p_5tuple, &filter_info->fivetuple_list, entries) {
5517 igb_inject_5tuple_filter_82576(dev, p_5tuple);
5520 TAILQ_FOREACH(p_2tuple, &filter_info->twotuple_list, entries) {
5521 igb_inject_2uple_filter(dev, p_2tuple);
5525 /* restore SYN filter */
5527 igb_syn_filter_restore(struct rte_eth_dev *dev)
5529 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5530 struct e1000_filter_info *filter_info =
5531 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5534 synqf = filter_info->syn_info;
5536 if (synqf & E1000_SYN_FILTER_ENABLE) {
5537 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
5538 E1000_WRITE_FLUSH(hw);
5542 /* restore ethernet type filter */
5544 igb_ethertype_filter_restore(struct rte_eth_dev *dev)
5546 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5547 struct e1000_filter_info *filter_info =
5548 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5551 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
5552 if (filter_info->ethertype_mask & (1 << i)) {
5553 E1000_WRITE_REG(hw, E1000_ETQF(i),
5554 filter_info->ethertype_filters[i].etqf);
5555 E1000_WRITE_FLUSH(hw);
5560 /* restore flex byte filter */
5562 igb_flex_filter_restore(struct rte_eth_dev *dev)
5564 struct e1000_filter_info *filter_info =
5565 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5566 struct e1000_flex_filter *flex_filter;
5568 TAILQ_FOREACH(flex_filter, &filter_info->flex_list, entries) {
5569 igb_inject_flex_filter(dev, flex_filter);
5573 /* restore all types filter */
5575 igb_filter_restore(struct rte_eth_dev *dev)
5577 igb_ntuple_filter_restore(dev);
5578 igb_ethertype_filter_restore(dev);
5579 igb_syn_filter_restore(dev);
5580 igb_flex_filter_restore(dev);
5585 RTE_PMD_REGISTER_PCI(net_e1000_igb, rte_igb_pmd);
5586 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb, pci_id_igb_map);
5587 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb, "* igb_uio | uio_pci_generic | vfio-pci");
5588 RTE_PMD_REGISTER_PCI(net_e1000_igb_vf, rte_igbvf_pmd);
5589 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb_vf, pci_id_igbvf_map);
5590 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb_vf, "* igb_uio | vfio-pci");