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_set(struct rte_eth_dev *dev,
217 struct rte_eth_syn_filter *filter,
219 static int eth_igb_syn_filter_get(struct rte_eth_dev *dev,
220 struct rte_eth_syn_filter *filter);
221 static int eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
222 enum rte_filter_op filter_op,
224 static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
225 struct rte_eth_ntuple_filter *ntuple_filter);
226 static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
227 struct rte_eth_ntuple_filter *ntuple_filter);
228 static int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
229 struct rte_eth_flex_filter *filter,
231 static int eth_igb_get_flex_filter(struct rte_eth_dev *dev,
232 struct rte_eth_flex_filter *filter);
233 static int eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
234 enum rte_filter_op filter_op,
236 static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
237 struct rte_eth_ntuple_filter *ntuple_filter);
238 static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
239 struct rte_eth_ntuple_filter *ntuple_filter);
240 static int igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
241 struct rte_eth_ntuple_filter *filter,
243 static int igb_get_ntuple_filter(struct rte_eth_dev *dev,
244 struct rte_eth_ntuple_filter *filter);
245 static int igb_ntuple_filter_handle(struct rte_eth_dev *dev,
246 enum rte_filter_op filter_op,
248 static int igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
249 struct rte_eth_ethertype_filter *filter,
251 static int igb_ethertype_filter_handle(struct rte_eth_dev *dev,
252 enum rte_filter_op filter_op,
254 static int igb_get_ethertype_filter(struct rte_eth_dev *dev,
255 struct rte_eth_ethertype_filter *filter);
256 static int eth_igb_filter_ctrl(struct rte_eth_dev *dev,
257 enum rte_filter_type filter_type,
258 enum rte_filter_op filter_op,
260 static int eth_igb_get_reg_length(struct rte_eth_dev *dev);
261 static int eth_igb_get_regs(struct rte_eth_dev *dev,
262 struct rte_dev_reg_info *regs);
263 static int eth_igb_get_eeprom_length(struct rte_eth_dev *dev);
264 static int eth_igb_get_eeprom(struct rte_eth_dev *dev,
265 struct rte_dev_eeprom_info *eeprom);
266 static int eth_igb_set_eeprom(struct rte_eth_dev *dev,
267 struct rte_dev_eeprom_info *eeprom);
268 static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
269 struct ether_addr *mc_addr_set,
270 uint32_t nb_mc_addr);
271 static int igb_timesync_enable(struct rte_eth_dev *dev);
272 static int igb_timesync_disable(struct rte_eth_dev *dev);
273 static int igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
274 struct timespec *timestamp,
276 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
277 struct timespec *timestamp);
278 static int igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
279 static int igb_timesync_read_time(struct rte_eth_dev *dev,
280 struct timespec *timestamp);
281 static int igb_timesync_write_time(struct rte_eth_dev *dev,
282 const struct timespec *timestamp);
283 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
285 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
287 static void eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
288 uint8_t queue, uint8_t msix_vector);
289 static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
290 uint8_t index, uint8_t offset);
291 static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
292 static void eth_igbvf_interrupt_handler(void *param);
293 static void igbvf_mbx_process(struct rte_eth_dev *dev);
294 static int igb_filter_restore(struct rte_eth_dev *dev);
297 * Define VF Stats MACRO for Non "cleared on read" register
299 #define UPDATE_VF_STAT(reg, last, cur) \
301 u32 latest = E1000_READ_REG(hw, reg); \
302 cur += (latest - last) & UINT_MAX; \
306 #define IGB_FC_PAUSE_TIME 0x0680
307 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
308 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
310 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
312 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
315 * The set of PCI devices this driver supports
317 static const struct rte_pci_id pci_id_igb_map[] = {
318 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576) },
319 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_FIBER) },
320 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES) },
321 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER) },
322 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER_ET2) },
323 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS) },
324 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS_SERDES) },
325 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES_QUAD) },
327 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_COPPER) },
328 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_FIBER_SERDES) },
329 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575GB_QUAD_COPPER) },
331 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER) },
332 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_FIBER) },
333 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SERDES) },
334 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SGMII) },
335 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER_DUAL) },
336 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_QUAD_FIBER) },
338 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_COPPER) },
339 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_FIBER) },
340 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SERDES) },
341 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SGMII) },
342 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_DA4) },
343 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER) },
344 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_OEM1) },
345 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_IT) },
346 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_FIBER) },
347 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES) },
348 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SGMII) },
349 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I211_COPPER) },
350 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
351 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_SGMII) },
352 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
353 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SGMII) },
354 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SERDES) },
355 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_BACKPLANE) },
356 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SFP) },
357 { .vendor_id = 0, /* sentinel */ },
361 * The set of PCI devices this driver supports (for 82576&I350 VF)
363 static const struct rte_pci_id pci_id_igbvf_map[] = {
364 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF) },
365 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF_HV) },
366 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF) },
367 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF_HV) },
368 { .vendor_id = 0, /* sentinel */ },
371 static const struct rte_eth_desc_lim rx_desc_lim = {
372 .nb_max = E1000_MAX_RING_DESC,
373 .nb_min = E1000_MIN_RING_DESC,
374 .nb_align = IGB_RXD_ALIGN,
377 static const struct rte_eth_desc_lim tx_desc_lim = {
378 .nb_max = E1000_MAX_RING_DESC,
379 .nb_min = E1000_MIN_RING_DESC,
380 .nb_align = IGB_RXD_ALIGN,
381 .nb_seg_max = IGB_TX_MAX_SEG,
382 .nb_mtu_seg_max = IGB_TX_MAX_MTU_SEG,
385 static const struct eth_dev_ops eth_igb_ops = {
386 .dev_configure = eth_igb_configure,
387 .dev_start = eth_igb_start,
388 .dev_stop = eth_igb_stop,
389 .dev_set_link_up = eth_igb_dev_set_link_up,
390 .dev_set_link_down = eth_igb_dev_set_link_down,
391 .dev_close = eth_igb_close,
392 .promiscuous_enable = eth_igb_promiscuous_enable,
393 .promiscuous_disable = eth_igb_promiscuous_disable,
394 .allmulticast_enable = eth_igb_allmulticast_enable,
395 .allmulticast_disable = eth_igb_allmulticast_disable,
396 .link_update = eth_igb_link_update,
397 .stats_get = eth_igb_stats_get,
398 .xstats_get = eth_igb_xstats_get,
399 .xstats_get_by_id = eth_igb_xstats_get_by_id,
400 .xstats_get_names_by_id = eth_igb_xstats_get_names_by_id,
401 .xstats_get_names = eth_igb_xstats_get_names,
402 .stats_reset = eth_igb_stats_reset,
403 .xstats_reset = eth_igb_xstats_reset,
404 .fw_version_get = eth_igb_fw_version_get,
405 .dev_infos_get = eth_igb_infos_get,
406 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
407 .mtu_set = eth_igb_mtu_set,
408 .vlan_filter_set = eth_igb_vlan_filter_set,
409 .vlan_tpid_set = eth_igb_vlan_tpid_set,
410 .vlan_offload_set = eth_igb_vlan_offload_set,
411 .rx_queue_setup = eth_igb_rx_queue_setup,
412 .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
413 .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
414 .rx_queue_release = eth_igb_rx_queue_release,
415 .rx_queue_count = eth_igb_rx_queue_count,
416 .rx_descriptor_done = eth_igb_rx_descriptor_done,
417 .rx_descriptor_status = eth_igb_rx_descriptor_status,
418 .tx_descriptor_status = eth_igb_tx_descriptor_status,
419 .tx_queue_setup = eth_igb_tx_queue_setup,
420 .tx_queue_release = eth_igb_tx_queue_release,
421 .tx_done_cleanup = eth_igb_tx_done_cleanup,
422 .dev_led_on = eth_igb_led_on,
423 .dev_led_off = eth_igb_led_off,
424 .flow_ctrl_get = eth_igb_flow_ctrl_get,
425 .flow_ctrl_set = eth_igb_flow_ctrl_set,
426 .mac_addr_add = eth_igb_rar_set,
427 .mac_addr_remove = eth_igb_rar_clear,
428 .mac_addr_set = eth_igb_default_mac_addr_set,
429 .reta_update = eth_igb_rss_reta_update,
430 .reta_query = eth_igb_rss_reta_query,
431 .rss_hash_update = eth_igb_rss_hash_update,
432 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
433 .filter_ctrl = eth_igb_filter_ctrl,
434 .set_mc_addr_list = eth_igb_set_mc_addr_list,
435 .rxq_info_get = igb_rxq_info_get,
436 .txq_info_get = igb_txq_info_get,
437 .timesync_enable = igb_timesync_enable,
438 .timesync_disable = igb_timesync_disable,
439 .timesync_read_rx_timestamp = igb_timesync_read_rx_timestamp,
440 .timesync_read_tx_timestamp = igb_timesync_read_tx_timestamp,
441 .get_reg = eth_igb_get_regs,
442 .get_eeprom_length = eth_igb_get_eeprom_length,
443 .get_eeprom = eth_igb_get_eeprom,
444 .set_eeprom = eth_igb_set_eeprom,
445 .timesync_adjust_time = igb_timesync_adjust_time,
446 .timesync_read_time = igb_timesync_read_time,
447 .timesync_write_time = igb_timesync_write_time,
451 * dev_ops for virtual function, bare necessities for basic vf
452 * operation have been implemented
454 static const struct eth_dev_ops igbvf_eth_dev_ops = {
455 .dev_configure = igbvf_dev_configure,
456 .dev_start = igbvf_dev_start,
457 .dev_stop = igbvf_dev_stop,
458 .dev_close = igbvf_dev_close,
459 .promiscuous_enable = igbvf_promiscuous_enable,
460 .promiscuous_disable = igbvf_promiscuous_disable,
461 .allmulticast_enable = igbvf_allmulticast_enable,
462 .allmulticast_disable = igbvf_allmulticast_disable,
463 .link_update = eth_igb_link_update,
464 .stats_get = eth_igbvf_stats_get,
465 .xstats_get = eth_igbvf_xstats_get,
466 .xstats_get_names = eth_igbvf_xstats_get_names,
467 .stats_reset = eth_igbvf_stats_reset,
468 .xstats_reset = eth_igbvf_stats_reset,
469 .vlan_filter_set = igbvf_vlan_filter_set,
470 .dev_infos_get = eth_igbvf_infos_get,
471 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
472 .rx_queue_setup = eth_igb_rx_queue_setup,
473 .rx_queue_release = eth_igb_rx_queue_release,
474 .tx_queue_setup = eth_igb_tx_queue_setup,
475 .tx_queue_release = eth_igb_tx_queue_release,
476 .set_mc_addr_list = eth_igb_set_mc_addr_list,
477 .rxq_info_get = igb_rxq_info_get,
478 .txq_info_get = igb_txq_info_get,
479 .mac_addr_set = igbvf_default_mac_addr_set,
480 .get_reg = igbvf_get_regs,
483 /* store statistics names and its offset in stats structure */
484 struct rte_igb_xstats_name_off {
485 char name[RTE_ETH_XSTATS_NAME_SIZE];
489 static const struct rte_igb_xstats_name_off rte_igb_stats_strings[] = {
490 {"rx_crc_errors", offsetof(struct e1000_hw_stats, crcerrs)},
491 {"rx_align_errors", offsetof(struct e1000_hw_stats, algnerrc)},
492 {"rx_symbol_errors", offsetof(struct e1000_hw_stats, symerrs)},
493 {"rx_missed_packets", offsetof(struct e1000_hw_stats, mpc)},
494 {"tx_single_collision_packets", offsetof(struct e1000_hw_stats, scc)},
495 {"tx_multiple_collision_packets", offsetof(struct e1000_hw_stats, mcc)},
496 {"tx_excessive_collision_packets", offsetof(struct e1000_hw_stats,
498 {"tx_late_collisions", offsetof(struct e1000_hw_stats, latecol)},
499 {"tx_total_collisions", offsetof(struct e1000_hw_stats, colc)},
500 {"tx_deferred_packets", offsetof(struct e1000_hw_stats, dc)},
501 {"tx_no_carrier_sense_packets", offsetof(struct e1000_hw_stats, tncrs)},
502 {"rx_carrier_ext_errors", offsetof(struct e1000_hw_stats, cexterr)},
503 {"rx_length_errors", offsetof(struct e1000_hw_stats, rlec)},
504 {"rx_xon_packets", offsetof(struct e1000_hw_stats, xonrxc)},
505 {"tx_xon_packets", offsetof(struct e1000_hw_stats, xontxc)},
506 {"rx_xoff_packets", offsetof(struct e1000_hw_stats, xoffrxc)},
507 {"tx_xoff_packets", offsetof(struct e1000_hw_stats, xofftxc)},
508 {"rx_flow_control_unsupported_packets", offsetof(struct e1000_hw_stats,
510 {"rx_size_64_packets", offsetof(struct e1000_hw_stats, prc64)},
511 {"rx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, prc127)},
512 {"rx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, prc255)},
513 {"rx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, prc511)},
514 {"rx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
516 {"rx_size_1024_to_max_packets", offsetof(struct e1000_hw_stats,
518 {"rx_broadcast_packets", offsetof(struct e1000_hw_stats, bprc)},
519 {"rx_multicast_packets", offsetof(struct e1000_hw_stats, mprc)},
520 {"rx_undersize_errors", offsetof(struct e1000_hw_stats, ruc)},
521 {"rx_fragment_errors", offsetof(struct e1000_hw_stats, rfc)},
522 {"rx_oversize_errors", offsetof(struct e1000_hw_stats, roc)},
523 {"rx_jabber_errors", offsetof(struct e1000_hw_stats, rjc)},
524 {"rx_management_packets", offsetof(struct e1000_hw_stats, mgprc)},
525 {"rx_management_dropped", offsetof(struct e1000_hw_stats, mgpdc)},
526 {"tx_management_packets", offsetof(struct e1000_hw_stats, mgptc)},
527 {"rx_total_packets", offsetof(struct e1000_hw_stats, tpr)},
528 {"tx_total_packets", offsetof(struct e1000_hw_stats, tpt)},
529 {"rx_total_bytes", offsetof(struct e1000_hw_stats, tor)},
530 {"tx_total_bytes", offsetof(struct e1000_hw_stats, tot)},
531 {"tx_size_64_packets", offsetof(struct e1000_hw_stats, ptc64)},
532 {"tx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, ptc127)},
533 {"tx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, ptc255)},
534 {"tx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, ptc511)},
535 {"tx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
537 {"tx_size_1023_to_max_packets", offsetof(struct e1000_hw_stats,
539 {"tx_multicast_packets", offsetof(struct e1000_hw_stats, mptc)},
540 {"tx_broadcast_packets", offsetof(struct e1000_hw_stats, bptc)},
541 {"tx_tso_packets", offsetof(struct e1000_hw_stats, tsctc)},
542 {"tx_tso_errors", offsetof(struct e1000_hw_stats, tsctfc)},
543 {"rx_sent_to_host_packets", offsetof(struct e1000_hw_stats, rpthc)},
544 {"tx_sent_by_host_packets", offsetof(struct e1000_hw_stats, hgptc)},
545 {"rx_code_violation_packets", offsetof(struct e1000_hw_stats, scvpc)},
547 {"interrupt_assert_count", offsetof(struct e1000_hw_stats, iac)},
550 #define IGB_NB_XSTATS (sizeof(rte_igb_stats_strings) / \
551 sizeof(rte_igb_stats_strings[0]))
553 static const struct rte_igb_xstats_name_off rte_igbvf_stats_strings[] = {
554 {"rx_multicast_packets", offsetof(struct e1000_vf_stats, mprc)},
555 {"rx_good_loopback_packets", offsetof(struct e1000_vf_stats, gprlbc)},
556 {"tx_good_loopback_packets", offsetof(struct e1000_vf_stats, gptlbc)},
557 {"rx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gorlbc)},
558 {"tx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gotlbc)},
561 #define IGBVF_NB_XSTATS (sizeof(rte_igbvf_stats_strings) / \
562 sizeof(rte_igbvf_stats_strings[0]))
565 * Atomically reads the link status information from global
566 * structure rte_eth_dev.
569 * - Pointer to the structure rte_eth_dev to read from.
570 * - Pointer to the buffer to be saved with the link status.
573 * - On success, zero.
574 * - On failure, negative value.
577 rte_igb_dev_atomic_read_link_status(struct rte_eth_dev *dev,
578 struct rte_eth_link *link)
580 struct rte_eth_link *dst = link;
581 struct rte_eth_link *src = &(dev->data->dev_link);
583 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
584 *(uint64_t *)src) == 0)
591 * Atomically writes the link status information into global
592 * structure rte_eth_dev.
595 * - Pointer to the structure rte_eth_dev to read from.
596 * - Pointer to the buffer to be saved with the link status.
599 * - On success, zero.
600 * - On failure, negative value.
603 rte_igb_dev_atomic_write_link_status(struct rte_eth_dev *dev,
604 struct rte_eth_link *link)
606 struct rte_eth_link *dst = &(dev->data->dev_link);
607 struct rte_eth_link *src = link;
609 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
610 *(uint64_t *)src) == 0)
617 igb_intr_enable(struct rte_eth_dev *dev)
619 struct e1000_interrupt *intr =
620 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
621 struct e1000_hw *hw =
622 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
624 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
625 E1000_WRITE_FLUSH(hw);
629 igb_intr_disable(struct e1000_hw *hw)
631 E1000_WRITE_REG(hw, E1000_IMC, ~0);
632 E1000_WRITE_FLUSH(hw);
636 igbvf_intr_enable(struct rte_eth_dev *dev)
638 struct e1000_hw *hw =
639 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
641 /* only for mailbox */
642 E1000_WRITE_REG(hw, E1000_EIAM, 1 << E1000_VTIVAR_MISC_MAILBOX);
643 E1000_WRITE_REG(hw, E1000_EIAC, 1 << E1000_VTIVAR_MISC_MAILBOX);
644 E1000_WRITE_REG(hw, E1000_EIMS, 1 << E1000_VTIVAR_MISC_MAILBOX);
645 E1000_WRITE_FLUSH(hw);
648 /* only for mailbox now. If RX/TX needed, should extend this function. */
650 igbvf_set_ivar_map(struct e1000_hw *hw, uint8_t msix_vector)
655 tmp |= (msix_vector & E1000_VTIVAR_MISC_INTR_MASK);
656 tmp |= E1000_VTIVAR_VALID;
657 E1000_WRITE_REG(hw, E1000_VTIVAR_MISC, tmp);
661 eth_igbvf_configure_msix_intr(struct rte_eth_dev *dev)
663 struct e1000_hw *hw =
664 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
666 /* Configure VF other cause ivar */
667 igbvf_set_ivar_map(hw, E1000_VTIVAR_MISC_MAILBOX);
670 static inline int32_t
671 igb_pf_reset_hw(struct e1000_hw *hw)
676 status = e1000_reset_hw(hw);
678 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
679 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
680 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
681 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
682 E1000_WRITE_FLUSH(hw);
688 igb_identify_hardware(struct rte_eth_dev *dev, struct rte_pci_device *pci_dev)
690 struct e1000_hw *hw =
691 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
694 hw->vendor_id = pci_dev->id.vendor_id;
695 hw->device_id = pci_dev->id.device_id;
696 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
697 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
699 e1000_set_mac_type(hw);
701 /* need to check if it is a vf device below */
705 igb_reset_swfw_lock(struct e1000_hw *hw)
710 * Do mac ops initialization manually here, since we will need
711 * some function pointers set by this call.
713 ret_val = e1000_init_mac_params(hw);
718 * SMBI lock should not fail in this early stage. If this is the case,
719 * it is due to an improper exit of the application.
720 * So force the release of the faulty lock.
722 if (e1000_get_hw_semaphore_generic(hw) < 0) {
723 PMD_DRV_LOG(DEBUG, "SMBI lock released");
725 e1000_put_hw_semaphore_generic(hw);
727 if (hw->mac.ops.acquire_swfw_sync != NULL) {
731 * Phy lock should not fail in this early stage. If this is the case,
732 * it is due to an improper exit of the application.
733 * So force the release of the faulty lock.
735 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
736 if (hw->bus.func > E1000_FUNC_1)
738 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
739 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
742 hw->mac.ops.release_swfw_sync(hw, mask);
745 * This one is more tricky since it is common to all ports; but
746 * swfw_sync retries last long enough (1s) to be almost sure that if
747 * lock can not be taken it is due to an improper lock of the
750 mask = E1000_SWFW_EEP_SM;
751 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
752 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
754 hw->mac.ops.release_swfw_sync(hw, mask);
757 return E1000_SUCCESS;
761 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
764 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
765 struct e1000_hw *hw =
766 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
767 struct e1000_vfta * shadow_vfta =
768 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
769 struct e1000_filter_info *filter_info =
770 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
771 struct e1000_adapter *adapter =
772 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
776 eth_dev->dev_ops = ð_igb_ops;
777 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
778 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
779 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
781 /* for secondary processes, we don't initialise any further as primary
782 * has already done this work. Only check we don't need a different
784 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
785 if (eth_dev->data->scattered_rx)
786 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
790 rte_eth_copy_pci_info(eth_dev, pci_dev);
791 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
793 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
795 igb_identify_hardware(eth_dev, pci_dev);
796 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
801 e1000_get_bus_info(hw);
803 /* Reset any pending lock */
804 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
809 /* Finish initialization */
810 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
816 hw->phy.autoneg_wait_to_complete = 0;
817 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
820 if (hw->phy.media_type == e1000_media_type_copper) {
821 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
822 hw->phy.disable_polarity_correction = 0;
823 hw->phy.ms_type = e1000_ms_hw_default;
827 * Start from a known state, this is important in reading the nvm
832 /* Make sure we have a good EEPROM before we read from it */
833 if (e1000_validate_nvm_checksum(hw) < 0) {
835 * Some PCI-E parts fail the first check due to
836 * the link being in sleep state, call it again,
837 * if it fails a second time its a real issue.
839 if (e1000_validate_nvm_checksum(hw) < 0) {
840 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
846 /* Read the permanent MAC address out of the EEPROM */
847 if (e1000_read_mac_addr(hw) != 0) {
848 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
853 /* Allocate memory for storing MAC addresses */
854 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
855 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
856 if (eth_dev->data->mac_addrs == NULL) {
857 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
858 "store MAC addresses",
859 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
864 /* Copy the permanent MAC address */
865 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
867 /* initialize the vfta */
868 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
870 /* Now initialize the hardware */
871 if (igb_hardware_init(hw) != 0) {
872 PMD_INIT_LOG(ERR, "Hardware initialization failed");
873 rte_free(eth_dev->data->mac_addrs);
874 eth_dev->data->mac_addrs = NULL;
878 hw->mac.get_link_status = 1;
879 adapter->stopped = 0;
881 /* Indicate SOL/IDER usage */
882 if (e1000_check_reset_block(hw) < 0) {
883 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
887 /* initialize PF if max_vfs not zero */
888 igb_pf_host_init(eth_dev);
890 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
891 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
892 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
893 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
894 E1000_WRITE_FLUSH(hw);
896 PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
897 eth_dev->data->port_id, pci_dev->id.vendor_id,
898 pci_dev->id.device_id);
900 rte_intr_callback_register(&pci_dev->intr_handle,
901 eth_igb_interrupt_handler,
904 /* enable uio/vfio intr/eventfd mapping */
905 rte_intr_enable(&pci_dev->intr_handle);
907 /* enable support intr */
908 igb_intr_enable(eth_dev);
910 /* initialize filter info */
911 memset(filter_info, 0,
912 sizeof(struct e1000_filter_info));
914 TAILQ_INIT(&filter_info->flex_list);
915 TAILQ_INIT(&filter_info->twotuple_list);
916 TAILQ_INIT(&filter_info->fivetuple_list);
921 igb_hw_control_release(hw);
927 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
929 struct rte_pci_device *pci_dev;
930 struct rte_intr_handle *intr_handle;
932 struct e1000_adapter *adapter =
933 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
934 struct e1000_filter_info *filter_info =
935 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
937 PMD_INIT_FUNC_TRACE();
939 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
942 hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
943 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
944 intr_handle = &pci_dev->intr_handle;
946 if (adapter->stopped == 0)
947 eth_igb_close(eth_dev);
949 eth_dev->dev_ops = NULL;
950 eth_dev->rx_pkt_burst = NULL;
951 eth_dev->tx_pkt_burst = NULL;
953 /* Reset any pending lock */
954 igb_reset_swfw_lock(hw);
956 rte_free(eth_dev->data->mac_addrs);
957 eth_dev->data->mac_addrs = NULL;
959 /* uninitialize PF if max_vfs not zero */
960 igb_pf_host_uninit(eth_dev);
962 /* disable uio intr before callback unregister */
963 rte_intr_disable(intr_handle);
964 rte_intr_callback_unregister(intr_handle,
965 eth_igb_interrupt_handler, eth_dev);
967 /* clear the SYN filter info */
968 filter_info->syn_info = 0;
974 * Virtual Function device init
977 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
979 struct rte_pci_device *pci_dev;
980 struct rte_intr_handle *intr_handle;
981 struct e1000_adapter *adapter =
982 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
983 struct e1000_hw *hw =
984 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
986 struct ether_addr *perm_addr = (struct ether_addr *)hw->mac.perm_addr;
988 PMD_INIT_FUNC_TRACE();
990 eth_dev->dev_ops = &igbvf_eth_dev_ops;
991 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
992 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
993 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
995 /* for secondary processes, we don't initialise any further as primary
996 * has already done this work. Only check we don't need a different
998 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
999 if (eth_dev->data->scattered_rx)
1000 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
1004 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1005 rte_eth_copy_pci_info(eth_dev, pci_dev);
1006 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
1008 hw->device_id = pci_dev->id.device_id;
1009 hw->vendor_id = pci_dev->id.vendor_id;
1010 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1011 adapter->stopped = 0;
1013 /* Initialize the shared code (base driver) */
1014 diag = e1000_setup_init_funcs(hw, TRUE);
1016 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
1021 /* init_mailbox_params */
1022 hw->mbx.ops.init_params(hw);
1024 /* Disable the interrupts for VF */
1025 igbvf_intr_disable(hw);
1027 diag = hw->mac.ops.reset_hw(hw);
1029 /* Allocate memory for storing MAC addresses */
1030 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
1031 hw->mac.rar_entry_count, 0);
1032 if (eth_dev->data->mac_addrs == NULL) {
1034 "Failed to allocate %d bytes needed to store MAC "
1036 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
1040 /* Generate a random MAC address, if none was assigned by PF. */
1041 if (is_zero_ether_addr(perm_addr)) {
1042 eth_random_addr(perm_addr->addr_bytes);
1043 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1044 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1045 "%02x:%02x:%02x:%02x:%02x:%02x",
1046 perm_addr->addr_bytes[0],
1047 perm_addr->addr_bytes[1],
1048 perm_addr->addr_bytes[2],
1049 perm_addr->addr_bytes[3],
1050 perm_addr->addr_bytes[4],
1051 perm_addr->addr_bytes[5]);
1054 diag = e1000_rar_set(hw, perm_addr->addr_bytes, 0);
1056 rte_free(eth_dev->data->mac_addrs);
1057 eth_dev->data->mac_addrs = NULL;
1060 /* Copy the permanent MAC address */
1061 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
1062 ð_dev->data->mac_addrs[0]);
1064 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
1066 eth_dev->data->port_id, pci_dev->id.vendor_id,
1067 pci_dev->id.device_id, "igb_mac_82576_vf");
1069 intr_handle = &pci_dev->intr_handle;
1070 rte_intr_callback_register(intr_handle,
1071 eth_igbvf_interrupt_handler, eth_dev);
1077 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
1079 struct e1000_adapter *adapter =
1080 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
1081 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1083 PMD_INIT_FUNC_TRACE();
1085 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1088 if (adapter->stopped == 0)
1089 igbvf_dev_close(eth_dev);
1091 eth_dev->dev_ops = NULL;
1092 eth_dev->rx_pkt_burst = NULL;
1093 eth_dev->tx_pkt_burst = NULL;
1095 rte_free(eth_dev->data->mac_addrs);
1096 eth_dev->data->mac_addrs = NULL;
1098 /* disable uio intr before callback unregister */
1099 rte_intr_disable(&pci_dev->intr_handle);
1100 rte_intr_callback_unregister(&pci_dev->intr_handle,
1101 eth_igbvf_interrupt_handler,
1107 static int eth_igb_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1108 struct rte_pci_device *pci_dev)
1110 return rte_eth_dev_pci_generic_probe(pci_dev,
1111 sizeof(struct e1000_adapter), eth_igb_dev_init);
1114 static int eth_igb_pci_remove(struct rte_pci_device *pci_dev)
1116 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igb_dev_uninit);
1119 static struct rte_pci_driver rte_igb_pmd = {
1120 .id_table = pci_id_igb_map,
1121 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1122 .probe = eth_igb_pci_probe,
1123 .remove = eth_igb_pci_remove,
1127 static int eth_igbvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1128 struct rte_pci_device *pci_dev)
1130 return rte_eth_dev_pci_generic_probe(pci_dev,
1131 sizeof(struct e1000_adapter), eth_igbvf_dev_init);
1134 static int eth_igbvf_pci_remove(struct rte_pci_device *pci_dev)
1136 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igbvf_dev_uninit);
1140 * virtual function driver struct
1142 static struct rte_pci_driver rte_igbvf_pmd = {
1143 .id_table = pci_id_igbvf_map,
1144 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1145 .probe = eth_igbvf_pci_probe,
1146 .remove = eth_igbvf_pci_remove,
1150 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1152 struct e1000_hw *hw =
1153 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1154 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
1155 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
1156 rctl |= E1000_RCTL_VFE;
1157 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1161 igb_check_mq_mode(struct rte_eth_dev *dev)
1163 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1164 enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
1165 uint16_t nb_rx_q = dev->data->nb_rx_queues;
1166 uint16_t nb_tx_q = dev->data->nb_rx_queues;
1168 if ((rx_mq_mode & ETH_MQ_RX_DCB_FLAG) ||
1169 tx_mq_mode == ETH_MQ_TX_DCB ||
1170 tx_mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1171 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
1174 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
1175 /* Check multi-queue mode.
1176 * To no break software we accept ETH_MQ_RX_NONE as this might
1177 * be used to turn off VLAN filter.
1180 if (rx_mq_mode == ETH_MQ_RX_NONE ||
1181 rx_mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1182 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
1183 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
1185 /* Only support one queue on VFs.
1186 * RSS together with SRIOV is not supported.
1188 PMD_INIT_LOG(ERR, "SRIOV is active,"
1189 " wrong mq_mode rx %d.",
1193 /* TX mode is not used here, so mode might be ignored.*/
1194 if (tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1195 /* SRIOV only works in VMDq enable mode */
1196 PMD_INIT_LOG(WARNING, "SRIOV is active,"
1197 " TX mode %d is not supported. "
1198 " Driver will behave as %d mode.",
1199 tx_mq_mode, ETH_MQ_TX_VMDQ_ONLY);
1202 /* check valid queue number */
1203 if ((nb_rx_q > 1) || (nb_tx_q > 1)) {
1204 PMD_INIT_LOG(ERR, "SRIOV is active,"
1205 " only support one queue on VFs.");
1209 /* To no break software that set invalid mode, only display
1210 * warning if invalid mode is used.
1212 if (rx_mq_mode != ETH_MQ_RX_NONE &&
1213 rx_mq_mode != ETH_MQ_RX_VMDQ_ONLY &&
1214 rx_mq_mode != ETH_MQ_RX_RSS) {
1215 /* RSS together with VMDq not supported*/
1216 PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
1221 if (tx_mq_mode != ETH_MQ_TX_NONE &&
1222 tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1223 PMD_INIT_LOG(WARNING, "TX mode %d is not supported."
1224 " Due to txmode is meaningless in this"
1225 " driver, just ignore.",
1233 eth_igb_configure(struct rte_eth_dev *dev)
1235 struct e1000_interrupt *intr =
1236 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1239 PMD_INIT_FUNC_TRACE();
1241 /* multipe queue mode checking */
1242 ret = igb_check_mq_mode(dev);
1244 PMD_DRV_LOG(ERR, "igb_check_mq_mode fails with %d.",
1249 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1250 PMD_INIT_FUNC_TRACE();
1256 eth_igb_start(struct rte_eth_dev *dev)
1258 struct e1000_hw *hw =
1259 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1260 struct e1000_adapter *adapter =
1261 E1000_DEV_PRIVATE(dev->data->dev_private);
1262 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1263 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1265 uint32_t intr_vector = 0;
1271 PMD_INIT_FUNC_TRACE();
1273 /* disable uio/vfio intr/eventfd mapping */
1274 rte_intr_disable(intr_handle);
1276 /* Power up the phy. Needed to make the link go Up */
1277 eth_igb_dev_set_link_up(dev);
1280 * Packet Buffer Allocation (PBA)
1281 * Writing PBA sets the receive portion of the buffer
1282 * the remainder is used for the transmit buffer.
1284 if (hw->mac.type == e1000_82575) {
1287 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
1288 E1000_WRITE_REG(hw, E1000_PBA, pba);
1291 /* Put the address into the Receive Address Array */
1292 e1000_rar_set(hw, hw->mac.addr, 0);
1294 /* Initialize the hardware */
1295 if (igb_hardware_init(hw)) {
1296 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
1299 adapter->stopped = 0;
1301 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1303 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1304 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1305 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
1306 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1307 E1000_WRITE_FLUSH(hw);
1309 /* configure PF module if SRIOV enabled */
1310 igb_pf_host_configure(dev);
1312 /* check and configure queue intr-vector mapping */
1313 if ((rte_intr_cap_multiple(intr_handle) ||
1314 !RTE_ETH_DEV_SRIOV(dev).active) &&
1315 dev->data->dev_conf.intr_conf.rxq != 0) {
1316 intr_vector = dev->data->nb_rx_queues;
1317 if (rte_intr_efd_enable(intr_handle, intr_vector))
1321 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1322 intr_handle->intr_vec =
1323 rte_zmalloc("intr_vec",
1324 dev->data->nb_rx_queues * sizeof(int), 0);
1325 if (intr_handle->intr_vec == NULL) {
1326 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1327 " intr_vec", dev->data->nb_rx_queues);
1332 /* confiugre msix for rx interrupt */
1333 eth_igb_configure_msix_intr(dev);
1335 /* Configure for OS presence */
1336 igb_init_manageability(hw);
1338 eth_igb_tx_init(dev);
1340 /* This can fail when allocating mbufs for descriptor rings */
1341 ret = eth_igb_rx_init(dev);
1343 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1344 igb_dev_clear_queues(dev);
1348 e1000_clear_hw_cntrs_base_generic(hw);
1351 * VLAN Offload Settings
1353 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
1354 ETH_VLAN_EXTEND_MASK;
1355 eth_igb_vlan_offload_set(dev, mask);
1357 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1358 /* Enable VLAN filter since VMDq always use VLAN filter */
1359 igb_vmdq_vlan_hw_filter_enable(dev);
1362 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
1363 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
1364 (hw->mac.type == e1000_i211)) {
1365 /* Configure EITR with the maximum possible value (0xFFFF) */
1366 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
1369 /* Setup link speed and duplex */
1370 speeds = &dev->data->dev_conf.link_speeds;
1371 if (*speeds == ETH_LINK_SPEED_AUTONEG) {
1372 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
1373 hw->mac.autoneg = 1;
1376 autoneg = (*speeds & ETH_LINK_SPEED_FIXED) == 0;
1379 hw->phy.autoneg_advertised = 0;
1381 if (*speeds & ~(ETH_LINK_SPEED_10M_HD | ETH_LINK_SPEED_10M |
1382 ETH_LINK_SPEED_100M_HD | ETH_LINK_SPEED_100M |
1383 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_FIXED)) {
1385 goto error_invalid_config;
1387 if (*speeds & ETH_LINK_SPEED_10M_HD) {
1388 hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
1391 if (*speeds & ETH_LINK_SPEED_10M) {
1392 hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
1395 if (*speeds & ETH_LINK_SPEED_100M_HD) {
1396 hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
1399 if (*speeds & ETH_LINK_SPEED_100M) {
1400 hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
1403 if (*speeds & ETH_LINK_SPEED_1G) {
1404 hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
1407 if (num_speeds == 0 || (!autoneg && (num_speeds > 1)))
1408 goto error_invalid_config;
1410 /* Set/reset the mac.autoneg based on the link speed,
1414 hw->mac.autoneg = 0;
1415 hw->mac.forced_speed_duplex =
1416 hw->phy.autoneg_advertised;
1418 hw->mac.autoneg = 1;
1422 e1000_setup_link(hw);
1424 if (rte_intr_allow_others(intr_handle)) {
1425 /* check if lsc interrupt is enabled */
1426 if (dev->data->dev_conf.intr_conf.lsc != 0)
1427 eth_igb_lsc_interrupt_setup(dev);
1429 rte_intr_callback_unregister(intr_handle,
1430 eth_igb_interrupt_handler,
1432 if (dev->data->dev_conf.intr_conf.lsc != 0)
1433 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1434 " no intr multiplex");
1437 /* check if rxq interrupt is enabled */
1438 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1439 rte_intr_dp_is_en(intr_handle))
1440 eth_igb_rxq_interrupt_setup(dev);
1442 /* enable uio/vfio intr/eventfd mapping */
1443 rte_intr_enable(intr_handle);
1445 /* resume enabled intr since hw reset */
1446 igb_intr_enable(dev);
1448 /* restore all types filter */
1449 igb_filter_restore(dev);
1451 PMD_INIT_LOG(DEBUG, "<<");
1455 error_invalid_config:
1456 PMD_INIT_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
1457 dev->data->dev_conf.link_speeds, dev->data->port_id);
1458 igb_dev_clear_queues(dev);
1462 /*********************************************************************
1464 * This routine disables all traffic on the adapter by issuing a
1465 * global reset on the MAC.
1467 **********************************************************************/
1469 eth_igb_stop(struct rte_eth_dev *dev)
1471 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1472 struct e1000_filter_info *filter_info =
1473 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1474 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1475 struct rte_eth_link link;
1476 struct e1000_flex_filter *p_flex;
1477 struct e1000_5tuple_filter *p_5tuple, *p_5tuple_next;
1478 struct e1000_2tuple_filter *p_2tuple, *p_2tuple_next;
1479 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1481 igb_intr_disable(hw);
1483 /* disable intr eventfd mapping */
1484 rte_intr_disable(intr_handle);
1486 igb_pf_reset_hw(hw);
1487 E1000_WRITE_REG(hw, E1000_WUC, 0);
1489 /* Set bit for Go Link disconnect */
1490 if (hw->mac.type >= e1000_82580) {
1493 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1494 phpm_reg |= E1000_82580_PM_GO_LINKD;
1495 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1498 /* Power down the phy. Needed to make the link go Down */
1499 eth_igb_dev_set_link_down(dev);
1501 igb_dev_clear_queues(dev);
1503 /* clear the recorded link status */
1504 memset(&link, 0, sizeof(link));
1505 rte_igb_dev_atomic_write_link_status(dev, &link);
1507 /* Remove all flex filters of the device */
1508 while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
1509 TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
1512 filter_info->flex_mask = 0;
1514 /* Remove all ntuple filters of the device */
1515 for (p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list);
1516 p_5tuple != NULL; p_5tuple = p_5tuple_next) {
1517 p_5tuple_next = TAILQ_NEXT(p_5tuple, entries);
1518 TAILQ_REMOVE(&filter_info->fivetuple_list,
1522 filter_info->fivetuple_mask = 0;
1523 for (p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list);
1524 p_2tuple != NULL; p_2tuple = p_2tuple_next) {
1525 p_2tuple_next = TAILQ_NEXT(p_2tuple, entries);
1526 TAILQ_REMOVE(&filter_info->twotuple_list,
1530 filter_info->twotuple_mask = 0;
1532 if (!rte_intr_allow_others(intr_handle))
1533 /* resume to the default handler */
1534 rte_intr_callback_register(intr_handle,
1535 eth_igb_interrupt_handler,
1538 /* Clean datapath event and queue/vec mapping */
1539 rte_intr_efd_disable(intr_handle);
1540 if (intr_handle->intr_vec != NULL) {
1541 rte_free(intr_handle->intr_vec);
1542 intr_handle->intr_vec = NULL;
1547 eth_igb_dev_set_link_up(struct rte_eth_dev *dev)
1549 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1551 if (hw->phy.media_type == e1000_media_type_copper)
1552 e1000_power_up_phy(hw);
1554 e1000_power_up_fiber_serdes_link(hw);
1560 eth_igb_dev_set_link_down(struct rte_eth_dev *dev)
1562 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1564 if (hw->phy.media_type == e1000_media_type_copper)
1565 e1000_power_down_phy(hw);
1567 e1000_shutdown_fiber_serdes_link(hw);
1573 eth_igb_close(struct rte_eth_dev *dev)
1575 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1576 struct e1000_adapter *adapter =
1577 E1000_DEV_PRIVATE(dev->data->dev_private);
1578 struct rte_eth_link link;
1579 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1580 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1583 adapter->stopped = 1;
1585 e1000_phy_hw_reset(hw);
1586 igb_release_manageability(hw);
1587 igb_hw_control_release(hw);
1589 /* Clear bit for Go Link disconnect */
1590 if (hw->mac.type >= e1000_82580) {
1593 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1594 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1595 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1598 igb_dev_free_queues(dev);
1600 if (intr_handle->intr_vec) {
1601 rte_free(intr_handle->intr_vec);
1602 intr_handle->intr_vec = NULL;
1605 memset(&link, 0, sizeof(link));
1606 rte_igb_dev_atomic_write_link_status(dev, &link);
1610 igb_get_rx_buffer_size(struct e1000_hw *hw)
1612 uint32_t rx_buf_size;
1613 if (hw->mac.type == e1000_82576) {
1614 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1615 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1616 /* PBS needs to be translated according to a lookup table */
1617 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1618 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1619 rx_buf_size = (rx_buf_size << 10);
1620 } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1621 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1623 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1629 /*********************************************************************
1631 * Initialize the hardware
1633 **********************************************************************/
1635 igb_hardware_init(struct e1000_hw *hw)
1637 uint32_t rx_buf_size;
1640 /* Let the firmware know the OS is in control */
1641 igb_hw_control_acquire(hw);
1644 * These parameters control the automatic generation (Tx) and
1645 * response (Rx) to Ethernet PAUSE frames.
1646 * - High water mark should allow for at least two standard size (1518)
1647 * frames to be received after sending an XOFF.
1648 * - Low water mark works best when it is very near the high water mark.
1649 * This allows the receiver to restart by sending XON when it has
1650 * drained a bit. Here we use an arbitrary value of 1500 which will
1651 * restart after one full frame is pulled from the buffer. There
1652 * could be several smaller frames in the buffer and if so they will
1653 * not trigger the XON until their total number reduces the buffer
1655 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1657 rx_buf_size = igb_get_rx_buffer_size(hw);
1659 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
1660 hw->fc.low_water = hw->fc.high_water - 1500;
1661 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1662 hw->fc.send_xon = 1;
1664 /* Set Flow control, use the tunable location if sane */
1665 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1666 hw->fc.requested_mode = igb_fc_setting;
1668 hw->fc.requested_mode = e1000_fc_none;
1670 /* Issue a global reset */
1671 igb_pf_reset_hw(hw);
1672 E1000_WRITE_REG(hw, E1000_WUC, 0);
1674 diag = e1000_init_hw(hw);
1678 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1679 e1000_get_phy_info(hw);
1680 e1000_check_for_link(hw);
1685 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1687 igb_read_stats_registers(struct e1000_hw *hw, struct e1000_hw_stats *stats)
1691 uint64_t old_gprc = stats->gprc;
1692 uint64_t old_gptc = stats->gptc;
1693 uint64_t old_tpr = stats->tpr;
1694 uint64_t old_tpt = stats->tpt;
1695 uint64_t old_rpthc = stats->rpthc;
1696 uint64_t old_hgptc = stats->hgptc;
1698 if(hw->phy.media_type == e1000_media_type_copper ||
1699 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1701 E1000_READ_REG(hw,E1000_SYMERRS);
1702 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1705 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1706 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1707 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1708 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1710 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1711 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1712 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1713 stats->dc += E1000_READ_REG(hw, E1000_DC);
1714 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1715 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1716 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1718 ** For watchdog management we need to know if we have been
1719 ** paused during the last interval, so capture that here.
1721 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1722 stats->xoffrxc += pause_frames;
1723 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1724 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1725 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1726 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1727 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1728 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1729 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1730 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1731 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1732 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1733 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1734 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1736 /* For the 64-bit byte counters the low dword must be read first. */
1737 /* Both registers clear on the read of the high dword */
1739 /* Workaround CRC bytes included in size, take away 4 bytes/packet */
1740 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1741 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1742 stats->gorc -= (stats->gprc - old_gprc) * ETHER_CRC_LEN;
1743 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1744 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1745 stats->gotc -= (stats->gptc - old_gptc) * ETHER_CRC_LEN;
1747 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1748 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1749 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1750 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1751 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1753 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1754 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1756 stats->tor += E1000_READ_REG(hw, E1000_TORL);
1757 stats->tor += ((uint64_t)E1000_READ_REG(hw, E1000_TORH) << 32);
1758 stats->tor -= (stats->tpr - old_tpr) * ETHER_CRC_LEN;
1759 stats->tot += E1000_READ_REG(hw, E1000_TOTL);
1760 stats->tot += ((uint64_t)E1000_READ_REG(hw, E1000_TOTH) << 32);
1761 stats->tot -= (stats->tpt - old_tpt) * ETHER_CRC_LEN;
1763 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1764 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1765 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1766 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1767 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1768 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1769 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1770 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1772 /* Interrupt Counts */
1774 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1775 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1776 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1777 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1778 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1779 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1780 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1781 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1782 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1784 /* Host to Card Statistics */
1786 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1787 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1788 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1789 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1790 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1791 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1792 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1793 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1794 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1795 stats->hgorc -= (stats->rpthc - old_rpthc) * ETHER_CRC_LEN;
1796 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1797 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1798 stats->hgotc -= (stats->hgptc - old_hgptc) * ETHER_CRC_LEN;
1799 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1800 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1801 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1803 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1804 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1805 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1806 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1807 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1808 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1812 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1814 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1815 struct e1000_hw_stats *stats =
1816 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1818 igb_read_stats_registers(hw, stats);
1820 if (rte_stats == NULL)
1824 rte_stats->imissed = stats->mpc;
1825 rte_stats->ierrors = stats->crcerrs +
1826 stats->rlec + stats->ruc + stats->roc +
1827 stats->rxerrc + stats->algnerrc + stats->cexterr;
1830 rte_stats->oerrors = stats->ecol + stats->latecol;
1832 rte_stats->ipackets = stats->gprc;
1833 rte_stats->opackets = stats->gptc;
1834 rte_stats->ibytes = stats->gorc;
1835 rte_stats->obytes = stats->gotc;
1839 eth_igb_stats_reset(struct rte_eth_dev *dev)
1841 struct e1000_hw_stats *hw_stats =
1842 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1844 /* HW registers are cleared on read */
1845 eth_igb_stats_get(dev, NULL);
1847 /* Reset software totals */
1848 memset(hw_stats, 0, sizeof(*hw_stats));
1852 eth_igb_xstats_reset(struct rte_eth_dev *dev)
1854 struct e1000_hw_stats *stats =
1855 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1857 /* HW registers are cleared on read */
1858 eth_igb_xstats_get(dev, NULL, IGB_NB_XSTATS);
1860 /* Reset software totals */
1861 memset(stats, 0, sizeof(*stats));
1864 static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1865 struct rte_eth_xstat_name *xstats_names,
1866 __rte_unused unsigned int size)
1870 if (xstats_names == NULL)
1871 return IGB_NB_XSTATS;
1873 /* Note: limit checked in rte_eth_xstats_names() */
1875 for (i = 0; i < IGB_NB_XSTATS; i++) {
1876 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
1877 "%s", rte_igb_stats_strings[i].name);
1880 return IGB_NB_XSTATS;
1883 static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
1884 struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
1890 if (xstats_names == NULL)
1891 return IGB_NB_XSTATS;
1893 for (i = 0; i < IGB_NB_XSTATS; i++)
1894 snprintf(xstats_names[i].name,
1895 sizeof(xstats_names[i].name),
1896 "%s", rte_igb_stats_strings[i].name);
1898 return IGB_NB_XSTATS;
1901 struct rte_eth_xstat_name xstats_names_copy[IGB_NB_XSTATS];
1903 eth_igb_xstats_get_names_by_id(dev, xstats_names_copy, NULL,
1906 for (i = 0; i < limit; i++) {
1907 if (ids[i] >= IGB_NB_XSTATS) {
1908 PMD_INIT_LOG(ERR, "id value isn't valid");
1911 strcpy(xstats_names[i].name,
1912 xstats_names_copy[ids[i]].name);
1919 eth_igb_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1922 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1923 struct e1000_hw_stats *hw_stats =
1924 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1927 if (n < IGB_NB_XSTATS)
1928 return IGB_NB_XSTATS;
1930 igb_read_stats_registers(hw, hw_stats);
1932 /* If this is a reset xstats is NULL, and we have cleared the
1933 * registers by reading them.
1938 /* Extended stats */
1939 for (i = 0; i < IGB_NB_XSTATS; i++) {
1941 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
1942 rte_igb_stats_strings[i].offset);
1945 return IGB_NB_XSTATS;
1949 eth_igb_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1950 uint64_t *values, unsigned int n)
1955 struct e1000_hw *hw =
1956 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1957 struct e1000_hw_stats *hw_stats =
1958 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1960 if (n < IGB_NB_XSTATS)
1961 return IGB_NB_XSTATS;
1963 igb_read_stats_registers(hw, hw_stats);
1965 /* If this is a reset xstats is NULL, and we have cleared the
1966 * registers by reading them.
1971 /* Extended stats */
1972 for (i = 0; i < IGB_NB_XSTATS; i++)
1973 values[i] = *(uint64_t *)(((char *)hw_stats) +
1974 rte_igb_stats_strings[i].offset);
1976 return IGB_NB_XSTATS;
1979 uint64_t values_copy[IGB_NB_XSTATS];
1981 eth_igb_xstats_get_by_id(dev, NULL, values_copy,
1984 for (i = 0; i < n; i++) {
1985 if (ids[i] >= IGB_NB_XSTATS) {
1986 PMD_INIT_LOG(ERR, "id value isn't valid");
1989 values[i] = values_copy[ids[i]];
1996 igbvf_read_stats_registers(struct e1000_hw *hw, struct e1000_vf_stats *hw_stats)
1998 /* Good Rx packets, include VF loopback */
1999 UPDATE_VF_STAT(E1000_VFGPRC,
2000 hw_stats->last_gprc, hw_stats->gprc);
2002 /* Good Rx octets, include VF loopback */
2003 UPDATE_VF_STAT(E1000_VFGORC,
2004 hw_stats->last_gorc, hw_stats->gorc);
2006 /* Good Tx packets, include VF loopback */
2007 UPDATE_VF_STAT(E1000_VFGPTC,
2008 hw_stats->last_gptc, hw_stats->gptc);
2010 /* Good Tx octets, include VF loopback */
2011 UPDATE_VF_STAT(E1000_VFGOTC,
2012 hw_stats->last_gotc, hw_stats->gotc);
2014 /* Rx Multicst packets */
2015 UPDATE_VF_STAT(E1000_VFMPRC,
2016 hw_stats->last_mprc, hw_stats->mprc);
2018 /* Good Rx loopback packets */
2019 UPDATE_VF_STAT(E1000_VFGPRLBC,
2020 hw_stats->last_gprlbc, hw_stats->gprlbc);
2022 /* Good Rx loopback octets */
2023 UPDATE_VF_STAT(E1000_VFGORLBC,
2024 hw_stats->last_gorlbc, hw_stats->gorlbc);
2026 /* Good Tx loopback packets */
2027 UPDATE_VF_STAT(E1000_VFGPTLBC,
2028 hw_stats->last_gptlbc, hw_stats->gptlbc);
2030 /* Good Tx loopback octets */
2031 UPDATE_VF_STAT(E1000_VFGOTLBC,
2032 hw_stats->last_gotlbc, hw_stats->gotlbc);
2035 static int eth_igbvf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2036 struct rte_eth_xstat_name *xstats_names,
2037 __rte_unused unsigned limit)
2041 if (xstats_names != NULL)
2042 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2043 snprintf(xstats_names[i].name,
2044 sizeof(xstats_names[i].name), "%s",
2045 rte_igbvf_stats_strings[i].name);
2047 return IGBVF_NB_XSTATS;
2051 eth_igbvf_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2054 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2055 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2056 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2059 if (n < IGBVF_NB_XSTATS)
2060 return IGBVF_NB_XSTATS;
2062 igbvf_read_stats_registers(hw, hw_stats);
2067 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2069 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
2070 rte_igbvf_stats_strings[i].offset);
2073 return IGBVF_NB_XSTATS;
2077 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
2079 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2080 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2081 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2083 igbvf_read_stats_registers(hw, hw_stats);
2085 if (rte_stats == NULL)
2088 rte_stats->ipackets = hw_stats->gprc;
2089 rte_stats->ibytes = hw_stats->gorc;
2090 rte_stats->opackets = hw_stats->gptc;
2091 rte_stats->obytes = hw_stats->gotc;
2095 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
2097 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
2098 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2100 /* Sync HW register to the last stats */
2101 eth_igbvf_stats_get(dev, NULL);
2103 /* reset HW current stats*/
2104 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
2105 offsetof(struct e1000_vf_stats, gprc));
2109 eth_igb_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
2112 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2113 struct e1000_fw_version fw;
2116 e1000_get_fw_version(hw, &fw);
2118 switch (hw->mac.type) {
2121 if (!(e1000_get_flash_presence_i210(hw))) {
2122 ret = snprintf(fw_version, fw_size,
2124 fw.invm_major, fw.invm_minor,
2130 /* if option rom is valid, display its version too */
2132 ret = snprintf(fw_version, fw_size,
2133 "%d.%d, 0x%08x, %d.%d.%d",
2134 fw.eep_major, fw.eep_minor, fw.etrack_id,
2135 fw.or_major, fw.or_build, fw.or_patch);
2138 if (fw.etrack_id != 0X0000) {
2139 ret = snprintf(fw_version, fw_size,
2141 fw.eep_major, fw.eep_minor,
2144 ret = snprintf(fw_version, fw_size,
2146 fw.eep_major, fw.eep_minor,
2153 ret += 1; /* add the size of '\0' */
2154 if (fw_size < (u32)ret)
2161 eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2163 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2165 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2166 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2167 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2168 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2169 dev_info->rx_offload_capa =
2170 DEV_RX_OFFLOAD_VLAN_STRIP |
2171 DEV_RX_OFFLOAD_IPV4_CKSUM |
2172 DEV_RX_OFFLOAD_UDP_CKSUM |
2173 DEV_RX_OFFLOAD_TCP_CKSUM;
2174 dev_info->tx_offload_capa =
2175 DEV_TX_OFFLOAD_VLAN_INSERT |
2176 DEV_TX_OFFLOAD_IPV4_CKSUM |
2177 DEV_TX_OFFLOAD_UDP_CKSUM |
2178 DEV_TX_OFFLOAD_TCP_CKSUM |
2179 DEV_TX_OFFLOAD_SCTP_CKSUM |
2180 DEV_TX_OFFLOAD_TCP_TSO;
2182 switch (hw->mac.type) {
2184 dev_info->max_rx_queues = 4;
2185 dev_info->max_tx_queues = 4;
2186 dev_info->max_vmdq_pools = 0;
2190 dev_info->max_rx_queues = 16;
2191 dev_info->max_tx_queues = 16;
2192 dev_info->max_vmdq_pools = ETH_8_POOLS;
2193 dev_info->vmdq_queue_num = 16;
2197 dev_info->max_rx_queues = 8;
2198 dev_info->max_tx_queues = 8;
2199 dev_info->max_vmdq_pools = ETH_8_POOLS;
2200 dev_info->vmdq_queue_num = 8;
2204 dev_info->max_rx_queues = 8;
2205 dev_info->max_tx_queues = 8;
2206 dev_info->max_vmdq_pools = ETH_8_POOLS;
2207 dev_info->vmdq_queue_num = 8;
2211 dev_info->max_rx_queues = 8;
2212 dev_info->max_tx_queues = 8;
2216 dev_info->max_rx_queues = 4;
2217 dev_info->max_tx_queues = 4;
2218 dev_info->max_vmdq_pools = 0;
2222 dev_info->max_rx_queues = 2;
2223 dev_info->max_tx_queues = 2;
2224 dev_info->max_vmdq_pools = 0;
2228 /* Should not happen */
2231 dev_info->hash_key_size = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
2232 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
2233 dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
2235 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2237 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2238 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2239 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2241 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2245 dev_info->default_txconf = (struct rte_eth_txconf) {
2247 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2248 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2249 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2254 dev_info->rx_desc_lim = rx_desc_lim;
2255 dev_info->tx_desc_lim = tx_desc_lim;
2257 dev_info->speed_capa = ETH_LINK_SPEED_10M_HD | ETH_LINK_SPEED_10M |
2258 ETH_LINK_SPEED_100M_HD | ETH_LINK_SPEED_100M |
2262 static const uint32_t *
2263 eth_igb_supported_ptypes_get(struct rte_eth_dev *dev)
2265 static const uint32_t ptypes[] = {
2266 /* refers to igb_rxd_pkt_info_to_pkt_type() */
2269 RTE_PTYPE_L3_IPV4_EXT,
2271 RTE_PTYPE_L3_IPV6_EXT,
2275 RTE_PTYPE_TUNNEL_IP,
2276 RTE_PTYPE_INNER_L3_IPV6,
2277 RTE_PTYPE_INNER_L3_IPV6_EXT,
2278 RTE_PTYPE_INNER_L4_TCP,
2279 RTE_PTYPE_INNER_L4_UDP,
2283 if (dev->rx_pkt_burst == eth_igb_recv_pkts ||
2284 dev->rx_pkt_burst == eth_igb_recv_scattered_pkts)
2290 eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2292 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2294 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2295 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2296 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2297 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2298 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
2299 DEV_RX_OFFLOAD_IPV4_CKSUM |
2300 DEV_RX_OFFLOAD_UDP_CKSUM |
2301 DEV_RX_OFFLOAD_TCP_CKSUM;
2302 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
2303 DEV_TX_OFFLOAD_IPV4_CKSUM |
2304 DEV_TX_OFFLOAD_UDP_CKSUM |
2305 DEV_TX_OFFLOAD_TCP_CKSUM |
2306 DEV_TX_OFFLOAD_SCTP_CKSUM |
2307 DEV_TX_OFFLOAD_TCP_TSO;
2308 switch (hw->mac.type) {
2310 dev_info->max_rx_queues = 2;
2311 dev_info->max_tx_queues = 2;
2313 case e1000_vfadapt_i350:
2314 dev_info->max_rx_queues = 1;
2315 dev_info->max_tx_queues = 1;
2318 /* Should not happen */
2322 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2324 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2325 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2326 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2328 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2332 dev_info->default_txconf = (struct rte_eth_txconf) {
2334 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2335 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2336 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2341 dev_info->rx_desc_lim = rx_desc_lim;
2342 dev_info->tx_desc_lim = tx_desc_lim;
2345 /* return 0 means link status changed, -1 means not changed */
2347 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2349 struct e1000_hw *hw =
2350 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2351 struct rte_eth_link link, old;
2352 int link_check, count;
2355 hw->mac.get_link_status = 1;
2357 /* possible wait-to-complete in up to 9 seconds */
2358 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
2359 /* Read the real link status */
2360 switch (hw->phy.media_type) {
2361 case e1000_media_type_copper:
2362 /* Do the work to read phy */
2363 e1000_check_for_link(hw);
2364 link_check = !hw->mac.get_link_status;
2367 case e1000_media_type_fiber:
2368 e1000_check_for_link(hw);
2369 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
2373 case e1000_media_type_internal_serdes:
2374 e1000_check_for_link(hw);
2375 link_check = hw->mac.serdes_has_link;
2378 /* VF device is type_unknown */
2379 case e1000_media_type_unknown:
2380 eth_igbvf_link_update(hw);
2381 link_check = !hw->mac.get_link_status;
2387 if (link_check || wait_to_complete == 0)
2389 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
2391 memset(&link, 0, sizeof(link));
2392 rte_igb_dev_atomic_read_link_status(dev, &link);
2395 /* Now we check if a transition has happened */
2397 uint16_t duplex, speed;
2398 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
2399 link.link_duplex = (duplex == FULL_DUPLEX) ?
2400 ETH_LINK_FULL_DUPLEX :
2401 ETH_LINK_HALF_DUPLEX;
2402 link.link_speed = speed;
2403 link.link_status = ETH_LINK_UP;
2404 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2405 ETH_LINK_SPEED_FIXED);
2406 } else if (!link_check) {
2407 link.link_speed = 0;
2408 link.link_duplex = ETH_LINK_HALF_DUPLEX;
2409 link.link_status = ETH_LINK_DOWN;
2410 link.link_autoneg = ETH_LINK_SPEED_FIXED;
2412 rte_igb_dev_atomic_write_link_status(dev, &link);
2415 if (old.link_status == link.link_status)
2423 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
2424 * For ASF and Pass Through versions of f/w this means
2425 * that the driver is loaded.
2428 igb_hw_control_acquire(struct e1000_hw *hw)
2432 /* Let firmware know the driver has taken over */
2433 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2434 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2438 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
2439 * For ASF and Pass Through versions of f/w this means that the
2440 * driver is no longer loaded.
2443 igb_hw_control_release(struct e1000_hw *hw)
2447 /* Let firmware taken over control of h/w */
2448 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2449 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
2450 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2454 * Bit of a misnomer, what this really means is
2455 * to enable OS management of the system... aka
2456 * to disable special hardware management features.
2459 igb_init_manageability(struct e1000_hw *hw)
2461 if (e1000_enable_mng_pass_thru(hw)) {
2462 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
2463 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2465 /* disable hardware interception of ARP */
2466 manc &= ~(E1000_MANC_ARP_EN);
2468 /* enable receiving management packets to the host */
2469 manc |= E1000_MANC_EN_MNG2HOST;
2470 manc2h |= 1 << 5; /* Mng Port 623 */
2471 manc2h |= 1 << 6; /* Mng Port 664 */
2472 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
2473 E1000_WRITE_REG(hw, E1000_MANC, manc);
2478 igb_release_manageability(struct e1000_hw *hw)
2480 if (e1000_enable_mng_pass_thru(hw)) {
2481 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2483 manc |= E1000_MANC_ARP_EN;
2484 manc &= ~E1000_MANC_EN_MNG2HOST;
2486 E1000_WRITE_REG(hw, E1000_MANC, manc);
2491 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
2493 struct e1000_hw *hw =
2494 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2497 rctl = E1000_READ_REG(hw, E1000_RCTL);
2498 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2499 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2503 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
2505 struct e1000_hw *hw =
2506 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2509 rctl = E1000_READ_REG(hw, E1000_RCTL);
2510 rctl &= (~E1000_RCTL_UPE);
2511 if (dev->data->all_multicast == 1)
2512 rctl |= E1000_RCTL_MPE;
2514 rctl &= (~E1000_RCTL_MPE);
2515 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2519 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
2521 struct e1000_hw *hw =
2522 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2525 rctl = E1000_READ_REG(hw, E1000_RCTL);
2526 rctl |= E1000_RCTL_MPE;
2527 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2531 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
2533 struct e1000_hw *hw =
2534 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2537 if (dev->data->promiscuous == 1)
2538 return; /* must remain in all_multicast mode */
2539 rctl = E1000_READ_REG(hw, E1000_RCTL);
2540 rctl &= (~E1000_RCTL_MPE);
2541 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2545 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2547 struct e1000_hw *hw =
2548 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2549 struct e1000_vfta * shadow_vfta =
2550 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2555 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
2556 E1000_VFTA_ENTRY_MASK);
2557 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
2558 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
2563 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
2565 /* update local VFTA copy */
2566 shadow_vfta->vfta[vid_idx] = vfta;
2572 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
2573 enum rte_vlan_type vlan_type,
2576 struct e1000_hw *hw =
2577 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2580 qinq = E1000_READ_REG(hw, E1000_CTRL_EXT);
2581 qinq &= E1000_CTRL_EXT_EXT_VLAN;
2583 /* only outer TPID of double VLAN can be configured*/
2584 if (qinq && vlan_type == ETH_VLAN_TYPE_OUTER) {
2585 reg = E1000_READ_REG(hw, E1000_VET);
2586 reg = (reg & (~E1000_VET_VET_EXT)) |
2587 ((uint32_t)tpid << E1000_VET_VET_EXT_SHIFT);
2588 E1000_WRITE_REG(hw, E1000_VET, reg);
2593 /* all other TPID values are read-only*/
2594 PMD_DRV_LOG(ERR, "Not supported");
2600 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
2602 struct e1000_hw *hw =
2603 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2606 /* Filter Table Disable */
2607 reg = E1000_READ_REG(hw, E1000_RCTL);
2608 reg &= ~E1000_RCTL_CFIEN;
2609 reg &= ~E1000_RCTL_VFE;
2610 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2614 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2616 struct e1000_hw *hw =
2617 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2618 struct e1000_vfta * shadow_vfta =
2619 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2623 /* Filter Table Enable, CFI not used for packet acceptance */
2624 reg = E1000_READ_REG(hw, E1000_RCTL);
2625 reg &= ~E1000_RCTL_CFIEN;
2626 reg |= E1000_RCTL_VFE;
2627 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2629 /* restore VFTA table */
2630 for (i = 0; i < IGB_VFTA_SIZE; i++)
2631 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
2635 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
2637 struct e1000_hw *hw =
2638 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2641 /* VLAN Mode Disable */
2642 reg = E1000_READ_REG(hw, E1000_CTRL);
2643 reg &= ~E1000_CTRL_VME;
2644 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2648 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
2650 struct e1000_hw *hw =
2651 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2654 /* VLAN Mode Enable */
2655 reg = E1000_READ_REG(hw, E1000_CTRL);
2656 reg |= E1000_CTRL_VME;
2657 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2661 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2663 struct e1000_hw *hw =
2664 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2667 /* CTRL_EXT: Extended VLAN */
2668 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2669 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
2670 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2672 /* Update maximum packet length */
2673 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
2674 E1000_WRITE_REG(hw, E1000_RLPML,
2675 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2680 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2682 struct e1000_hw *hw =
2683 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2686 /* CTRL_EXT: Extended VLAN */
2687 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2688 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
2689 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2691 /* Update maximum packet length */
2692 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
2693 E1000_WRITE_REG(hw, E1000_RLPML,
2694 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2699 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2701 if(mask & ETH_VLAN_STRIP_MASK){
2702 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2703 igb_vlan_hw_strip_enable(dev);
2705 igb_vlan_hw_strip_disable(dev);
2708 if(mask & ETH_VLAN_FILTER_MASK){
2709 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2710 igb_vlan_hw_filter_enable(dev);
2712 igb_vlan_hw_filter_disable(dev);
2715 if(mask & ETH_VLAN_EXTEND_MASK){
2716 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2717 igb_vlan_hw_extend_enable(dev);
2719 igb_vlan_hw_extend_disable(dev);
2725 * It enables the interrupt mask and then enable the interrupt.
2728 * Pointer to struct rte_eth_dev.
2731 * - On success, zero.
2732 * - On failure, a negative value.
2735 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev)
2737 struct e1000_interrupt *intr =
2738 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2740 intr->mask |= E1000_ICR_LSC;
2745 /* It clears the interrupt causes and enables the interrupt.
2746 * It will be called once only during nic initialized.
2749 * Pointer to struct rte_eth_dev.
2752 * - On success, zero.
2753 * - On failure, a negative value.
2755 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev)
2757 uint32_t mask, regval;
2758 struct e1000_hw *hw =
2759 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2760 struct rte_eth_dev_info dev_info;
2762 memset(&dev_info, 0, sizeof(dev_info));
2763 eth_igb_infos_get(dev, &dev_info);
2765 mask = 0xFFFFFFFF >> (32 - dev_info.max_rx_queues);
2766 regval = E1000_READ_REG(hw, E1000_EIMS);
2767 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
2773 * It reads ICR and gets interrupt causes, check it and set a bit flag
2774 * to update link status.
2777 * Pointer to struct rte_eth_dev.
2780 * - On success, zero.
2781 * - On failure, a negative value.
2784 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
2787 struct e1000_hw *hw =
2788 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2789 struct e1000_interrupt *intr =
2790 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2792 igb_intr_disable(hw);
2794 /* read-on-clear nic registers here */
2795 icr = E1000_READ_REG(hw, E1000_ICR);
2798 if (icr & E1000_ICR_LSC) {
2799 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
2802 if (icr & E1000_ICR_VMMB)
2803 intr->flags |= E1000_FLAG_MAILBOX;
2809 * It executes link_update after knowing an interrupt is prsent.
2812 * Pointer to struct rte_eth_dev.
2815 * - On success, zero.
2816 * - On failure, a negative value.
2819 eth_igb_interrupt_action(struct rte_eth_dev *dev,
2820 struct rte_intr_handle *intr_handle)
2822 struct e1000_hw *hw =
2823 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2824 struct e1000_interrupt *intr =
2825 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2826 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2827 uint32_t tctl, rctl;
2828 struct rte_eth_link link;
2831 if (intr->flags & E1000_FLAG_MAILBOX) {
2832 igb_pf_mbx_process(dev);
2833 intr->flags &= ~E1000_FLAG_MAILBOX;
2836 igb_intr_enable(dev);
2837 rte_intr_enable(intr_handle);
2839 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
2840 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
2842 /* set get_link_status to check register later */
2843 hw->mac.get_link_status = 1;
2844 ret = eth_igb_link_update(dev, 0);
2846 /* check if link has changed */
2850 memset(&link, 0, sizeof(link));
2851 rte_igb_dev_atomic_read_link_status(dev, &link);
2852 if (link.link_status) {
2854 " Port %d: Link Up - speed %u Mbps - %s",
2856 (unsigned)link.link_speed,
2857 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2858 "full-duplex" : "half-duplex");
2860 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2861 dev->data->port_id);
2864 PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
2865 pci_dev->addr.domain,
2867 pci_dev->addr.devid,
2868 pci_dev->addr.function);
2869 tctl = E1000_READ_REG(hw, E1000_TCTL);
2870 rctl = E1000_READ_REG(hw, E1000_RCTL);
2871 if (link.link_status) {
2873 tctl |= E1000_TCTL_EN;
2874 rctl |= E1000_RCTL_EN;
2877 tctl &= ~E1000_TCTL_EN;
2878 rctl &= ~E1000_RCTL_EN;
2880 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
2881 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2882 E1000_WRITE_FLUSH(hw);
2883 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
2890 * Interrupt handler which shall be registered at first.
2893 * Pointer to interrupt handle.
2895 * The address of parameter (struct rte_eth_dev *) regsitered before.
2901 eth_igb_interrupt_handler(void *param)
2903 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2905 eth_igb_interrupt_get_status(dev);
2906 eth_igb_interrupt_action(dev, dev->intr_handle);
2910 eth_igbvf_interrupt_get_status(struct rte_eth_dev *dev)
2913 struct e1000_hw *hw =
2914 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2915 struct e1000_interrupt *intr =
2916 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2918 igbvf_intr_disable(hw);
2920 /* read-on-clear nic registers here */
2921 eicr = E1000_READ_REG(hw, E1000_EICR);
2924 if (eicr == E1000_VTIVAR_MISC_MAILBOX)
2925 intr->flags |= E1000_FLAG_MAILBOX;
2930 void igbvf_mbx_process(struct rte_eth_dev *dev)
2932 struct e1000_hw *hw =
2933 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2934 struct e1000_mbx_info *mbx = &hw->mbx;
2937 if (mbx->ops.read(hw, &in_msg, 1, 0))
2940 /* PF reset VF event */
2941 if (in_msg == E1000_PF_CONTROL_MSG)
2942 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET, NULL);
2946 eth_igbvf_interrupt_action(struct rte_eth_dev *dev, struct rte_intr_handle *intr_handle)
2948 struct e1000_interrupt *intr =
2949 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2951 if (intr->flags & E1000_FLAG_MAILBOX) {
2952 igbvf_mbx_process(dev);
2953 intr->flags &= ~E1000_FLAG_MAILBOX;
2956 igbvf_intr_enable(dev);
2957 rte_intr_enable(intr_handle);
2963 eth_igbvf_interrupt_handler(void *param)
2965 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2967 eth_igbvf_interrupt_get_status(dev);
2968 eth_igbvf_interrupt_action(dev, dev->intr_handle);
2972 eth_igb_led_on(struct rte_eth_dev *dev)
2974 struct e1000_hw *hw;
2976 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2977 return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
2981 eth_igb_led_off(struct rte_eth_dev *dev)
2983 struct e1000_hw *hw;
2985 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2986 return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
2990 eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2992 struct e1000_hw *hw;
2997 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2998 fc_conf->pause_time = hw->fc.pause_time;
2999 fc_conf->high_water = hw->fc.high_water;
3000 fc_conf->low_water = hw->fc.low_water;
3001 fc_conf->send_xon = hw->fc.send_xon;
3002 fc_conf->autoneg = hw->mac.autoneg;
3005 * Return rx_pause and tx_pause status according to actual setting of
3006 * the TFCE and RFCE bits in the CTRL register.
3008 ctrl = E1000_READ_REG(hw, E1000_CTRL);
3009 if (ctrl & E1000_CTRL_TFCE)
3014 if (ctrl & E1000_CTRL_RFCE)
3019 if (rx_pause && tx_pause)
3020 fc_conf->mode = RTE_FC_FULL;
3022 fc_conf->mode = RTE_FC_RX_PAUSE;
3024 fc_conf->mode = RTE_FC_TX_PAUSE;
3026 fc_conf->mode = RTE_FC_NONE;
3032 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3034 struct e1000_hw *hw;
3036 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
3042 uint32_t rx_buf_size;
3043 uint32_t max_high_water;
3046 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3047 if (fc_conf->autoneg != hw->mac.autoneg)
3049 rx_buf_size = igb_get_rx_buffer_size(hw);
3050 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
3052 /* At least reserve one Ethernet frame for watermark */
3053 max_high_water = rx_buf_size - ETHER_MAX_LEN;
3054 if ((fc_conf->high_water > max_high_water) ||
3055 (fc_conf->high_water < fc_conf->low_water)) {
3056 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
3057 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
3061 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
3062 hw->fc.pause_time = fc_conf->pause_time;
3063 hw->fc.high_water = fc_conf->high_water;
3064 hw->fc.low_water = fc_conf->low_water;
3065 hw->fc.send_xon = fc_conf->send_xon;
3067 err = e1000_setup_link_generic(hw);
3068 if (err == E1000_SUCCESS) {
3070 /* check if we want to forward MAC frames - driver doesn't have native
3071 * capability to do that, so we'll write the registers ourselves */
3073 rctl = E1000_READ_REG(hw, E1000_RCTL);
3075 /* set or clear MFLCN.PMCF bit depending on configuration */
3076 if (fc_conf->mac_ctrl_frame_fwd != 0)
3077 rctl |= E1000_RCTL_PMCF;
3079 rctl &= ~E1000_RCTL_PMCF;
3081 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3082 E1000_WRITE_FLUSH(hw);
3087 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
3091 #define E1000_RAH_POOLSEL_SHIFT (18)
3093 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
3094 uint32_t index, uint32_t pool)
3096 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3099 e1000_rar_set(hw, mac_addr->addr_bytes, index);
3100 rah = E1000_READ_REG(hw, E1000_RAH(index));
3101 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
3102 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
3107 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
3109 uint8_t addr[ETHER_ADDR_LEN];
3110 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3112 memset(addr, 0, sizeof(addr));
3114 e1000_rar_set(hw, addr, index);
3118 eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
3119 struct ether_addr *addr)
3121 eth_igb_rar_clear(dev, 0);
3123 eth_igb_rar_set(dev, (void *)addr, 0, 0);
3126 * Virtual Function operations
3129 igbvf_intr_disable(struct e1000_hw *hw)
3131 PMD_INIT_FUNC_TRACE();
3133 /* Clear interrupt mask to stop from interrupts being generated */
3134 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
3136 E1000_WRITE_FLUSH(hw);
3140 igbvf_stop_adapter(struct rte_eth_dev *dev)
3144 struct rte_eth_dev_info dev_info;
3145 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3147 memset(&dev_info, 0, sizeof(dev_info));
3148 eth_igbvf_infos_get(dev, &dev_info);
3150 /* Clear interrupt mask to stop from interrupts being generated */
3151 igbvf_intr_disable(hw);
3153 /* Clear any pending interrupts, flush previous writes */
3154 E1000_READ_REG(hw, E1000_EICR);
3156 /* Disable the transmit unit. Each queue must be disabled. */
3157 for (i = 0; i < dev_info.max_tx_queues; i++)
3158 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
3160 /* Disable the receive unit by stopping each queue */
3161 for (i = 0; i < dev_info.max_rx_queues; i++) {
3162 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
3163 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
3164 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
3165 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
3169 /* flush all queues disables */
3170 E1000_WRITE_FLUSH(hw);
3174 static int eth_igbvf_link_update(struct e1000_hw *hw)
3176 struct e1000_mbx_info *mbx = &hw->mbx;
3177 struct e1000_mac_info *mac = &hw->mac;
3178 int ret_val = E1000_SUCCESS;
3180 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
3183 * We only want to run this if there has been a rst asserted.
3184 * in this case that could mean a link change, device reset,
3185 * or a virtual function reset
3188 /* If we were hit with a reset or timeout drop the link */
3189 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
3190 mac->get_link_status = TRUE;
3192 if (!mac->get_link_status)
3195 /* if link status is down no point in checking to see if pf is up */
3196 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
3199 /* if we passed all the tests above then the link is up and we no
3200 * longer need to check for link */
3201 mac->get_link_status = FALSE;
3209 igbvf_dev_configure(struct rte_eth_dev *dev)
3211 struct rte_eth_conf* conf = &dev->data->dev_conf;
3213 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
3214 dev->data->port_id);
3217 * VF has no ability to enable/disable HW CRC
3218 * Keep the persistent behavior the same as Host PF
3220 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
3221 if (!conf->rxmode.hw_strip_crc) {
3222 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
3223 conf->rxmode.hw_strip_crc = 1;
3226 if (conf->rxmode.hw_strip_crc) {
3227 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
3228 conf->rxmode.hw_strip_crc = 0;
3236 igbvf_dev_start(struct rte_eth_dev *dev)
3238 struct e1000_hw *hw =
3239 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3240 struct e1000_adapter *adapter =
3241 E1000_DEV_PRIVATE(dev->data->dev_private);
3242 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3243 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3245 uint32_t intr_vector = 0;
3247 PMD_INIT_FUNC_TRACE();
3249 hw->mac.ops.reset_hw(hw);
3250 adapter->stopped = 0;
3253 igbvf_set_vfta_all(dev,1);
3255 eth_igbvf_tx_init(dev);
3257 /* This can fail when allocating mbufs for descriptor rings */
3258 ret = eth_igbvf_rx_init(dev);
3260 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
3261 igb_dev_clear_queues(dev);
3265 /* check and configure queue intr-vector mapping */
3266 if (dev->data->dev_conf.intr_conf.rxq != 0) {
3267 intr_vector = dev->data->nb_rx_queues;
3268 ret = rte_intr_efd_enable(intr_handle, intr_vector);
3273 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
3274 intr_handle->intr_vec =
3275 rte_zmalloc("intr_vec",
3276 dev->data->nb_rx_queues * sizeof(int), 0);
3277 if (!intr_handle->intr_vec) {
3278 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
3279 " intr_vec", dev->data->nb_rx_queues);
3284 eth_igbvf_configure_msix_intr(dev);
3286 /* enable uio/vfio intr/eventfd mapping */
3287 rte_intr_enable(intr_handle);
3289 /* resume enabled intr since hw reset */
3290 igbvf_intr_enable(dev);
3296 igbvf_dev_stop(struct rte_eth_dev *dev)
3298 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3299 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3301 PMD_INIT_FUNC_TRACE();
3303 igbvf_stop_adapter(dev);
3306 * Clear what we set, but we still keep shadow_vfta to
3307 * restore after device starts
3309 igbvf_set_vfta_all(dev,0);
3311 igb_dev_clear_queues(dev);
3313 /* disable intr eventfd mapping */
3314 rte_intr_disable(intr_handle);
3316 /* Clean datapath event and queue/vec mapping */
3317 rte_intr_efd_disable(intr_handle);
3318 if (intr_handle->intr_vec) {
3319 rte_free(intr_handle->intr_vec);
3320 intr_handle->intr_vec = NULL;
3325 igbvf_dev_close(struct rte_eth_dev *dev)
3327 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3328 struct e1000_adapter *adapter =
3329 E1000_DEV_PRIVATE(dev->data->dev_private);
3330 struct ether_addr addr;
3332 PMD_INIT_FUNC_TRACE();
3336 igbvf_dev_stop(dev);
3337 adapter->stopped = 1;
3338 igb_dev_free_queues(dev);
3341 * reprogram the RAR with a zero mac address,
3342 * to ensure that the VF traffic goes to the PF
3343 * after stop, close and detach of the VF.
3346 memset(&addr, 0, sizeof(addr));
3347 igbvf_default_mac_addr_set(dev, &addr);
3351 igbvf_promiscuous_enable(struct rte_eth_dev *dev)
3353 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3355 /* Set both unicast and multicast promisc */
3356 e1000_promisc_set_vf(hw, e1000_promisc_enabled);
3360 igbvf_promiscuous_disable(struct rte_eth_dev *dev)
3362 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3364 /* If in allmulticast mode leave multicast promisc */
3365 if (dev->data->all_multicast == 1)
3366 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3368 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3372 igbvf_allmulticast_enable(struct rte_eth_dev *dev)
3374 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3376 /* In promiscuous mode multicast promisc already set */
3377 if (dev->data->promiscuous == 0)
3378 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3382 igbvf_allmulticast_disable(struct rte_eth_dev *dev)
3384 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3386 /* In promiscuous mode leave multicast promisc enabled */
3387 if (dev->data->promiscuous == 0)
3388 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3391 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
3393 struct e1000_mbx_info *mbx = &hw->mbx;
3397 /* After set vlan, vlan strip will also be enabled in igb driver*/
3398 msgbuf[0] = E1000_VF_SET_VLAN;
3400 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
3402 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
3404 err = mbx->ops.write_posted(hw, msgbuf, 2, 0);
3408 err = mbx->ops.read_posted(hw, msgbuf, 2, 0);
3412 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
3413 if (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK))
3420 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
3422 struct e1000_hw *hw =
3423 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3424 struct e1000_vfta * shadow_vfta =
3425 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3426 int i = 0, j = 0, vfta = 0, mask = 1;
3428 for (i = 0; i < IGB_VFTA_SIZE; i++){
3429 vfta = shadow_vfta->vfta[i];
3432 for (j = 0; j < 32; j++){
3435 (uint16_t)((i<<5)+j), on);
3444 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3446 struct e1000_hw *hw =
3447 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3448 struct e1000_vfta * shadow_vfta =
3449 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3450 uint32_t vid_idx = 0;
3451 uint32_t vid_bit = 0;
3454 PMD_INIT_FUNC_TRACE();
3456 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
3457 ret = igbvf_set_vfta(hw, vlan_id, !!on);
3459 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
3462 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
3463 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
3465 /*Save what we set and retore it after device reset*/
3467 shadow_vfta->vfta[vid_idx] |= vid_bit;
3469 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
3475 igbvf_default_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *addr)
3477 struct e1000_hw *hw =
3478 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3480 /* index is not used by rar_set() */
3481 hw->mac.ops.rar_set(hw, (void *)addr, 0);
3486 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
3487 struct rte_eth_rss_reta_entry64 *reta_conf,
3492 uint16_t idx, shift;
3493 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3495 if (reta_size != ETH_RSS_RETA_SIZE_128) {
3496 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3497 "(%d) doesn't match the number hardware can supported "
3498 "(%d)", reta_size, ETH_RSS_RETA_SIZE_128);
3502 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3503 idx = i / RTE_RETA_GROUP_SIZE;
3504 shift = i % RTE_RETA_GROUP_SIZE;
3505 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3509 if (mask == IGB_4_BIT_MASK)
3512 r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3513 for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
3514 if (mask & (0x1 << j))
3515 reta |= reta_conf[idx].reta[shift + j] <<
3518 reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
3520 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
3527 eth_igb_rss_reta_query(struct rte_eth_dev *dev,
3528 struct rte_eth_rss_reta_entry64 *reta_conf,
3533 uint16_t idx, shift;
3534 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3536 if (reta_size != ETH_RSS_RETA_SIZE_128) {
3537 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3538 "(%d) doesn't match the number hardware can supported "
3539 "(%d)", reta_size, ETH_RSS_RETA_SIZE_128);
3543 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3544 idx = i / RTE_RETA_GROUP_SIZE;
3545 shift = i % RTE_RETA_GROUP_SIZE;
3546 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3550 reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3551 for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
3552 if (mask & (0x1 << j))
3553 reta_conf[idx].reta[shift + j] =
3554 ((reta >> (CHAR_BIT * j)) &
3562 #define MAC_TYPE_FILTER_SUP(type) do {\
3563 if ((type) != e1000_82580 && (type) != e1000_i350 &&\
3564 (type) != e1000_82576 && (type) != e1000_i210 &&\
3565 (type) != e1000_i211)\
3570 eth_igb_syn_filter_set(struct rte_eth_dev *dev,
3571 struct rte_eth_syn_filter *filter,
3574 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3575 struct e1000_filter_info *filter_info =
3576 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3577 uint32_t synqf, rfctl;
3579 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3582 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3585 if (synqf & E1000_SYN_FILTER_ENABLE)
3588 synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
3589 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
3591 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3592 if (filter->hig_pri)
3593 rfctl |= E1000_RFCTL_SYNQFP;
3595 rfctl &= ~E1000_RFCTL_SYNQFP;
3597 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
3599 if (!(synqf & E1000_SYN_FILTER_ENABLE))
3604 filter_info->syn_info = synqf;
3605 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
3606 E1000_WRITE_FLUSH(hw);
3611 eth_igb_syn_filter_get(struct rte_eth_dev *dev,
3612 struct rte_eth_syn_filter *filter)
3614 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3615 uint32_t synqf, rfctl;
3617 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3618 if (synqf & E1000_SYN_FILTER_ENABLE) {
3619 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3620 filter->hig_pri = (rfctl & E1000_RFCTL_SYNQFP) ? 1 : 0;
3621 filter->queue = (uint8_t)((synqf & E1000_SYN_FILTER_QUEUE) >>
3622 E1000_SYN_FILTER_QUEUE_SHIFT);
3630 eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
3631 enum rte_filter_op filter_op,
3634 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3637 MAC_TYPE_FILTER_SUP(hw->mac.type);
3639 if (filter_op == RTE_ETH_FILTER_NOP)
3643 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3648 switch (filter_op) {
3649 case RTE_ETH_FILTER_ADD:
3650 ret = eth_igb_syn_filter_set(dev,
3651 (struct rte_eth_syn_filter *)arg,
3654 case RTE_ETH_FILTER_DELETE:
3655 ret = eth_igb_syn_filter_set(dev,
3656 (struct rte_eth_syn_filter *)arg,
3659 case RTE_ETH_FILTER_GET:
3660 ret = eth_igb_syn_filter_get(dev,
3661 (struct rte_eth_syn_filter *)arg);
3664 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
3672 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
3673 if ((type) != e1000_82580 && (type) != e1000_i350 &&\
3674 (type) != e1000_i210 && (type) != e1000_i211)\
3678 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
3680 ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
3681 struct e1000_2tuple_filter_info *filter_info)
3683 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3685 if (filter->priority > E1000_2TUPLE_MAX_PRI)
3686 return -EINVAL; /* filter index is out of range. */
3687 if (filter->tcp_flags > TCP_FLAG_ALL)
3688 return -EINVAL; /* flags is invalid. */
3690 switch (filter->dst_port_mask) {
3692 filter_info->dst_port_mask = 0;
3693 filter_info->dst_port = filter->dst_port;
3696 filter_info->dst_port_mask = 1;
3699 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3703 switch (filter->proto_mask) {
3705 filter_info->proto_mask = 0;
3706 filter_info->proto = filter->proto;
3709 filter_info->proto_mask = 1;
3712 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3716 filter_info->priority = (uint8_t)filter->priority;
3717 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3718 filter_info->tcp_flags = filter->tcp_flags;
3720 filter_info->tcp_flags = 0;
3725 static inline struct e1000_2tuple_filter *
3726 igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
3727 struct e1000_2tuple_filter_info *key)
3729 struct e1000_2tuple_filter *it;
3731 TAILQ_FOREACH(it, filter_list, entries) {
3732 if (memcmp(key, &it->filter_info,
3733 sizeof(struct e1000_2tuple_filter_info)) == 0) {
3741 * igb_add_2tuple_filter - add a 2tuple filter
3744 * dev: Pointer to struct rte_eth_dev.
3745 * ntuple_filter: ponter to the filter that will be added.
3748 * - On success, zero.
3749 * - On failure, a negative value.
3752 igb_add_2tuple_filter(struct rte_eth_dev *dev,
3753 struct rte_eth_ntuple_filter *ntuple_filter)
3755 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3756 struct e1000_filter_info *filter_info =
3757 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3758 struct e1000_2tuple_filter *filter;
3759 uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
3760 uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3763 filter = rte_zmalloc("e1000_2tuple_filter",
3764 sizeof(struct e1000_2tuple_filter), 0);
3768 ret = ntuple_filter_to_2tuple(ntuple_filter,
3769 &filter->filter_info);
3774 if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3775 &filter->filter_info) != NULL) {
3776 PMD_DRV_LOG(ERR, "filter exists.");
3780 filter->queue = ntuple_filter->queue;
3783 * look for an unused 2tuple filter index,
3784 * and insert the filter to list.
3786 for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
3787 if (!(filter_info->twotuple_mask & (1 << i))) {
3788 filter_info->twotuple_mask |= 1 << i;
3790 TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
3796 if (i >= E1000_MAX_TTQF_FILTERS) {
3797 PMD_DRV_LOG(ERR, "2tuple filters are full.");
3802 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3803 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3804 imir |= E1000_IMIR_PORT_BP;
3806 imir &= ~E1000_IMIR_PORT_BP;
3808 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3810 ttqf |= E1000_TTQF_QUEUE_ENABLE;
3811 ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
3812 ttqf |= (uint32_t)(filter->filter_info.proto & E1000_TTQF_PROTOCOL_MASK);
3813 if (filter->filter_info.proto_mask == 0)
3814 ttqf &= ~E1000_TTQF_MASK_ENABLE;
3816 /* tcp flags bits setting. */
3817 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3818 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3819 imir_ext |= E1000_IMIREXT_CTRL_URG;
3820 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3821 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3822 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3823 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3824 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3825 imir_ext |= E1000_IMIREXT_CTRL_RST;
3826 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3827 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3828 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3829 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3831 imir_ext |= E1000_IMIREXT_CTRL_BP;
3832 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3833 E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
3834 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3839 * igb_remove_2tuple_filter - remove a 2tuple filter
3842 * dev: Pointer to struct rte_eth_dev.
3843 * ntuple_filter: ponter to the filter that will be removed.
3846 * - On success, zero.
3847 * - On failure, a negative value.
3850 igb_remove_2tuple_filter(struct rte_eth_dev *dev,
3851 struct rte_eth_ntuple_filter *ntuple_filter)
3853 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3854 struct e1000_filter_info *filter_info =
3855 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3856 struct e1000_2tuple_filter_info filter_2tuple;
3857 struct e1000_2tuple_filter *filter;
3860 memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
3861 ret = ntuple_filter_to_2tuple(ntuple_filter,
3866 filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3868 if (filter == NULL) {
3869 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3873 filter_info->twotuple_mask &= ~(1 << filter->index);
3874 TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
3877 E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
3878 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3879 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3883 static inline struct e1000_flex_filter *
3884 eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
3885 struct e1000_flex_filter_info *key)
3887 struct e1000_flex_filter *it;
3889 TAILQ_FOREACH(it, filter_list, entries) {
3890 if (memcmp(key, &it->filter_info,
3891 sizeof(struct e1000_flex_filter_info)) == 0)
3899 eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
3900 struct rte_eth_flex_filter *filter,
3903 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3904 struct e1000_filter_info *filter_info =
3905 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3906 struct e1000_flex_filter *flex_filter, *it;
3907 uint32_t wufc, queueing, mask;
3909 uint8_t shift, i, j = 0;
3911 flex_filter = rte_zmalloc("e1000_flex_filter",
3912 sizeof(struct e1000_flex_filter), 0);
3913 if (flex_filter == NULL)
3916 flex_filter->filter_info.len = filter->len;
3917 flex_filter->filter_info.priority = filter->priority;
3918 memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
3919 for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
3921 /* reverse bits in flex filter's mask*/
3922 for (shift = 0; shift < CHAR_BIT; shift++) {
3923 if (filter->mask[i] & (0x01 << shift))
3924 mask |= (0x80 >> shift);
3926 flex_filter->filter_info.mask[i] = mask;
3929 wufc = E1000_READ_REG(hw, E1000_WUFC);
3932 if (eth_igb_flex_filter_lookup(&filter_info->flex_list,
3933 &flex_filter->filter_info) != NULL) {
3934 PMD_DRV_LOG(ERR, "filter exists.");
3935 rte_free(flex_filter);
3938 flex_filter->queue = filter->queue;
3940 * look for an unused flex filter index
3941 * and insert the filter into the list.
3943 for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
3944 if (!(filter_info->flex_mask & (1 << i))) {
3945 filter_info->flex_mask |= 1 << i;
3946 flex_filter->index = i;
3947 TAILQ_INSERT_TAIL(&filter_info->flex_list,
3953 if (i >= E1000_MAX_FLEX_FILTERS) {
3954 PMD_DRV_LOG(ERR, "flex filters are full.");
3955 rte_free(flex_filter);
3959 if (flex_filter->index < E1000_MAX_FHFT)
3960 reg_off = E1000_FHFT(flex_filter->index);
3962 reg_off = E1000_FHFT_EXT(flex_filter->index - E1000_MAX_FHFT);
3964 E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
3965 (E1000_WUFC_FLX0 << flex_filter->index));
3966 queueing = filter->len |
3967 (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
3968 (filter->priority << E1000_FHFT_QUEUEING_PRIO_SHIFT);
3969 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
3971 for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
3972 E1000_WRITE_REG(hw, reg_off,
3973 flex_filter->filter_info.dwords[j]);
3974 reg_off += sizeof(uint32_t);
3975 E1000_WRITE_REG(hw, reg_off,
3976 flex_filter->filter_info.dwords[++j]);
3977 reg_off += sizeof(uint32_t);
3978 E1000_WRITE_REG(hw, reg_off,
3979 (uint32_t)flex_filter->filter_info.mask[i]);
3980 reg_off += sizeof(uint32_t) * 2;
3984 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
3985 &flex_filter->filter_info);
3987 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3988 rte_free(flex_filter);
3992 if (it->index < E1000_MAX_FHFT)
3993 reg_off = E1000_FHFT(it->index);
3995 reg_off = E1000_FHFT_EXT(it->index - E1000_MAX_FHFT);
3997 for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
3998 E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
3999 E1000_WRITE_REG(hw, E1000_WUFC, wufc &
4000 (~(E1000_WUFC_FLX0 << it->index)));
4002 filter_info->flex_mask &= ~(1 << it->index);
4003 TAILQ_REMOVE(&filter_info->flex_list, it, entries);
4005 rte_free(flex_filter);
4012 eth_igb_get_flex_filter(struct rte_eth_dev *dev,
4013 struct rte_eth_flex_filter *filter)
4015 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4016 struct e1000_filter_info *filter_info =
4017 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4018 struct e1000_flex_filter flex_filter, *it;
4019 uint32_t wufc, queueing, wufc_en = 0;
4021 memset(&flex_filter, 0, sizeof(struct e1000_flex_filter));
4022 flex_filter.filter_info.len = filter->len;
4023 flex_filter.filter_info.priority = filter->priority;
4024 memcpy(flex_filter.filter_info.dwords, filter->bytes, filter->len);
4025 memcpy(flex_filter.filter_info.mask, filter->mask,
4026 RTE_ALIGN(filter->len, sizeof(char)) / sizeof(char));
4028 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
4029 &flex_filter.filter_info);
4031 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4035 wufc = E1000_READ_REG(hw, E1000_WUFC);
4036 wufc_en = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << it->index);
4038 if ((wufc & wufc_en) == wufc_en) {
4039 uint32_t reg_off = 0;
4040 if (it->index < E1000_MAX_FHFT)
4041 reg_off = E1000_FHFT(it->index);
4043 reg_off = E1000_FHFT_EXT(it->index - E1000_MAX_FHFT);
4045 queueing = E1000_READ_REG(hw,
4046 reg_off + E1000_FHFT_QUEUEING_OFFSET);
4047 filter->len = queueing & E1000_FHFT_QUEUEING_LEN;
4048 filter->priority = (queueing & E1000_FHFT_QUEUEING_PRIO) >>
4049 E1000_FHFT_QUEUEING_PRIO_SHIFT;
4050 filter->queue = (queueing & E1000_FHFT_QUEUEING_QUEUE) >>
4051 E1000_FHFT_QUEUEING_QUEUE_SHIFT;
4058 eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
4059 enum rte_filter_op filter_op,
4062 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4063 struct rte_eth_flex_filter *filter;
4066 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
4068 if (filter_op == RTE_ETH_FILTER_NOP)
4072 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
4077 filter = (struct rte_eth_flex_filter *)arg;
4078 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN
4079 || filter->len % sizeof(uint64_t) != 0) {
4080 PMD_DRV_LOG(ERR, "filter's length is out of range");
4083 if (filter->priority > E1000_MAX_FLEX_FILTER_PRI) {
4084 PMD_DRV_LOG(ERR, "filter's priority is out of range");
4088 switch (filter_op) {
4089 case RTE_ETH_FILTER_ADD:
4090 ret = eth_igb_add_del_flex_filter(dev, filter, TRUE);
4092 case RTE_ETH_FILTER_DELETE:
4093 ret = eth_igb_add_del_flex_filter(dev, filter, FALSE);
4095 case RTE_ETH_FILTER_GET:
4096 ret = eth_igb_get_flex_filter(dev, filter);
4099 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
4107 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
4109 ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
4110 struct e1000_5tuple_filter_info *filter_info)
4112 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
4114 if (filter->priority > E1000_2TUPLE_MAX_PRI)
4115 return -EINVAL; /* filter index is out of range. */
4116 if (filter->tcp_flags > TCP_FLAG_ALL)
4117 return -EINVAL; /* flags is invalid. */
4119 switch (filter->dst_ip_mask) {
4121 filter_info->dst_ip_mask = 0;
4122 filter_info->dst_ip = filter->dst_ip;
4125 filter_info->dst_ip_mask = 1;
4128 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
4132 switch (filter->src_ip_mask) {
4134 filter_info->src_ip_mask = 0;
4135 filter_info->src_ip = filter->src_ip;
4138 filter_info->src_ip_mask = 1;
4141 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
4145 switch (filter->dst_port_mask) {
4147 filter_info->dst_port_mask = 0;
4148 filter_info->dst_port = filter->dst_port;
4151 filter_info->dst_port_mask = 1;
4154 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
4158 switch (filter->src_port_mask) {
4160 filter_info->src_port_mask = 0;
4161 filter_info->src_port = filter->src_port;
4164 filter_info->src_port_mask = 1;
4167 PMD_DRV_LOG(ERR, "invalid src_port mask.");
4171 switch (filter->proto_mask) {
4173 filter_info->proto_mask = 0;
4174 filter_info->proto = filter->proto;
4177 filter_info->proto_mask = 1;
4180 PMD_DRV_LOG(ERR, "invalid protocol mask.");
4184 filter_info->priority = (uint8_t)filter->priority;
4185 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
4186 filter_info->tcp_flags = filter->tcp_flags;
4188 filter_info->tcp_flags = 0;
4193 static inline struct e1000_5tuple_filter *
4194 igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
4195 struct e1000_5tuple_filter_info *key)
4197 struct e1000_5tuple_filter *it;
4199 TAILQ_FOREACH(it, filter_list, entries) {
4200 if (memcmp(key, &it->filter_info,
4201 sizeof(struct e1000_5tuple_filter_info)) == 0) {
4209 * igb_add_5tuple_filter_82576 - add a 5tuple filter
4212 * dev: Pointer to struct rte_eth_dev.
4213 * ntuple_filter: ponter to the filter that will be added.
4216 * - On success, zero.
4217 * - On failure, a negative value.
4220 igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
4221 struct rte_eth_ntuple_filter *ntuple_filter)
4223 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4224 struct e1000_filter_info *filter_info =
4225 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4226 struct e1000_5tuple_filter *filter;
4227 uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
4228 uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
4232 filter = rte_zmalloc("e1000_5tuple_filter",
4233 sizeof(struct e1000_5tuple_filter), 0);
4237 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4238 &filter->filter_info);
4244 if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4245 &filter->filter_info) != NULL) {
4246 PMD_DRV_LOG(ERR, "filter exists.");
4250 filter->queue = ntuple_filter->queue;
4253 * look for an unused 5tuple filter index,
4254 * and insert the filter to list.
4256 for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
4257 if (!(filter_info->fivetuple_mask & (1 << i))) {
4258 filter_info->fivetuple_mask |= 1 << i;
4260 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
4266 if (i >= E1000_MAX_FTQF_FILTERS) {
4267 PMD_DRV_LOG(ERR, "5tuple filters are full.");
4272 ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
4273 if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
4274 ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
4275 if (filter->filter_info.dst_ip_mask == 0)
4276 ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
4277 if (filter->filter_info.src_port_mask == 0)
4278 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
4279 if (filter->filter_info.proto_mask == 0)
4280 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
4281 ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
4282 E1000_FTQF_QUEUE_MASK;
4283 ftqf |= E1000_FTQF_QUEUE_ENABLE;
4284 E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
4285 E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
4286 E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
4288 spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
4289 E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
4291 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
4292 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
4293 imir |= E1000_IMIR_PORT_BP;
4295 imir &= ~E1000_IMIR_PORT_BP;
4296 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
4298 /* tcp flags bits setting. */
4299 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
4300 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
4301 imir_ext |= E1000_IMIREXT_CTRL_URG;
4302 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
4303 imir_ext |= E1000_IMIREXT_CTRL_ACK;
4304 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
4305 imir_ext |= E1000_IMIREXT_CTRL_PSH;
4306 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
4307 imir_ext |= E1000_IMIREXT_CTRL_RST;
4308 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
4309 imir_ext |= E1000_IMIREXT_CTRL_SYN;
4310 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
4311 imir_ext |= E1000_IMIREXT_CTRL_FIN;
4313 imir_ext |= E1000_IMIREXT_CTRL_BP;
4314 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
4315 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
4320 * igb_remove_5tuple_filter_82576 - remove a 5tuple filter
4323 * dev: Pointer to struct rte_eth_dev.
4324 * ntuple_filter: ponter to the filter that will be removed.
4327 * - On success, zero.
4328 * - On failure, a negative value.
4331 igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
4332 struct rte_eth_ntuple_filter *ntuple_filter)
4334 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4335 struct e1000_filter_info *filter_info =
4336 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4337 struct e1000_5tuple_filter_info filter_5tuple;
4338 struct e1000_5tuple_filter *filter;
4341 memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
4342 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4347 filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4349 if (filter == NULL) {
4350 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4354 filter_info->fivetuple_mask &= ~(1 << filter->index);
4355 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
4358 E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
4359 E1000_FTQF_VF_BP | E1000_FTQF_MASK);
4360 E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
4361 E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
4362 E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
4363 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
4364 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
4369 eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
4372 struct e1000_hw *hw;
4373 struct rte_eth_dev_info dev_info;
4374 uint32_t frame_size = mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN +
4377 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4379 #ifdef RTE_LIBRTE_82571_SUPPORT
4380 /* XXX: not bigger than max_rx_pktlen */
4381 if (hw->mac.type == e1000_82571)
4384 eth_igb_infos_get(dev, &dev_info);
4386 /* check that mtu is within the allowed range */
4387 if ((mtu < ETHER_MIN_MTU) ||
4388 (frame_size > dev_info.max_rx_pktlen))
4391 /* refuse mtu that requires the support of scattered packets when this
4392 * feature has not been enabled before. */
4393 if (!dev->data->scattered_rx &&
4394 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)
4397 rctl = E1000_READ_REG(hw, E1000_RCTL);
4399 /* switch to jumbo mode if needed */
4400 if (frame_size > ETHER_MAX_LEN) {
4401 dev->data->dev_conf.rxmode.jumbo_frame = 1;
4402 rctl |= E1000_RCTL_LPE;
4404 dev->data->dev_conf.rxmode.jumbo_frame = 0;
4405 rctl &= ~E1000_RCTL_LPE;
4407 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
4409 /* update max frame size */
4410 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
4412 E1000_WRITE_REG(hw, E1000_RLPML,
4413 dev->data->dev_conf.rxmode.max_rx_pkt_len);
4419 * igb_add_del_ntuple_filter - add or delete a ntuple filter
4422 * dev: Pointer to struct rte_eth_dev.
4423 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4424 * add: if true, add filter, if false, remove filter
4427 * - On success, zero.
4428 * - On failure, a negative value.
4431 igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
4432 struct rte_eth_ntuple_filter *ntuple_filter,
4435 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4438 switch (ntuple_filter->flags) {
4439 case RTE_5TUPLE_FLAGS:
4440 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4441 if (hw->mac.type != e1000_82576)
4444 ret = igb_add_5tuple_filter_82576(dev,
4447 ret = igb_remove_5tuple_filter_82576(dev,
4450 case RTE_2TUPLE_FLAGS:
4451 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4452 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350 &&
4453 hw->mac.type != e1000_i210 &&
4454 hw->mac.type != e1000_i211)
4457 ret = igb_add_2tuple_filter(dev, ntuple_filter);
4459 ret = igb_remove_2tuple_filter(dev, ntuple_filter);
4470 * igb_get_ntuple_filter - get a ntuple filter
4473 * dev: Pointer to struct rte_eth_dev.
4474 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4477 * - On success, zero.
4478 * - On failure, a negative value.
4481 igb_get_ntuple_filter(struct rte_eth_dev *dev,
4482 struct rte_eth_ntuple_filter *ntuple_filter)
4484 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4485 struct e1000_filter_info *filter_info =
4486 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4487 struct e1000_5tuple_filter_info filter_5tuple;
4488 struct e1000_2tuple_filter_info filter_2tuple;
4489 struct e1000_5tuple_filter *p_5tuple_filter;
4490 struct e1000_2tuple_filter *p_2tuple_filter;
4493 switch (ntuple_filter->flags) {
4494 case RTE_5TUPLE_FLAGS:
4495 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4496 if (hw->mac.type != e1000_82576)
4498 memset(&filter_5tuple,
4500 sizeof(struct e1000_5tuple_filter_info));
4501 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4505 p_5tuple_filter = igb_5tuple_filter_lookup_82576(
4506 &filter_info->fivetuple_list,
4508 if (p_5tuple_filter == NULL) {
4509 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4512 ntuple_filter->queue = p_5tuple_filter->queue;
4514 case RTE_2TUPLE_FLAGS:
4515 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4516 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
4518 memset(&filter_2tuple,
4520 sizeof(struct e1000_2tuple_filter_info));
4521 ret = ntuple_filter_to_2tuple(ntuple_filter, &filter_2tuple);
4524 p_2tuple_filter = igb_2tuple_filter_lookup(
4525 &filter_info->twotuple_list,
4527 if (p_2tuple_filter == NULL) {
4528 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4531 ntuple_filter->queue = p_2tuple_filter->queue;
4542 * igb_ntuple_filter_handle - Handle operations for ntuple filter.
4543 * @dev: pointer to rte_eth_dev structure
4544 * @filter_op:operation will be taken.
4545 * @arg: a pointer to specific structure corresponding to the filter_op
4548 igb_ntuple_filter_handle(struct rte_eth_dev *dev,
4549 enum rte_filter_op filter_op,
4552 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4555 MAC_TYPE_FILTER_SUP(hw->mac.type);
4557 if (filter_op == RTE_ETH_FILTER_NOP)
4561 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4566 switch (filter_op) {
4567 case RTE_ETH_FILTER_ADD:
4568 ret = igb_add_del_ntuple_filter(dev,
4569 (struct rte_eth_ntuple_filter *)arg,
4572 case RTE_ETH_FILTER_DELETE:
4573 ret = igb_add_del_ntuple_filter(dev,
4574 (struct rte_eth_ntuple_filter *)arg,
4577 case RTE_ETH_FILTER_GET:
4578 ret = igb_get_ntuple_filter(dev,
4579 (struct rte_eth_ntuple_filter *)arg);
4582 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4590 igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
4595 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4596 if (filter_info->ethertype_filters[i] == ethertype &&
4597 (filter_info->ethertype_mask & (1 << i)))
4604 igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
4609 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4610 if (!(filter_info->ethertype_mask & (1 << i))) {
4611 filter_info->ethertype_mask |= 1 << i;
4612 filter_info->ethertype_filters[i] = ethertype;
4620 igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
4623 if (idx >= E1000_MAX_ETQF_FILTERS)
4625 filter_info->ethertype_mask &= ~(1 << idx);
4626 filter_info->ethertype_filters[idx] = 0;
4632 igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
4633 struct rte_eth_ethertype_filter *filter,
4636 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4637 struct e1000_filter_info *filter_info =
4638 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4642 if (filter->ether_type == ETHER_TYPE_IPv4 ||
4643 filter->ether_type == ETHER_TYPE_IPv6) {
4644 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
4645 " ethertype filter.", filter->ether_type);
4649 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
4650 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
4653 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
4654 PMD_DRV_LOG(ERR, "drop option is unsupported.");
4658 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4659 if (ret >= 0 && add) {
4660 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
4661 filter->ether_type);
4664 if (ret < 0 && !add) {
4665 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4666 filter->ether_type);
4671 ret = igb_ethertype_filter_insert(filter_info,
4672 filter->ether_type);
4674 PMD_DRV_LOG(ERR, "ethertype filters are full.");
4678 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
4679 etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
4680 etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
4682 ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
4686 E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
4687 E1000_WRITE_FLUSH(hw);
4693 igb_get_ethertype_filter(struct rte_eth_dev *dev,
4694 struct rte_eth_ethertype_filter *filter)
4696 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4697 struct e1000_filter_info *filter_info =
4698 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4702 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4704 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4705 filter->ether_type);
4709 etqf = E1000_READ_REG(hw, E1000_ETQF(ret));
4710 if (etqf & E1000_ETQF_FILTER_ENABLE) {
4711 filter->ether_type = etqf & E1000_ETQF_ETHERTYPE;
4713 filter->queue = (etqf & E1000_ETQF_QUEUE) >>
4714 E1000_ETQF_QUEUE_SHIFT;
4722 * igb_ethertype_filter_handle - Handle operations for ethertype filter.
4723 * @dev: pointer to rte_eth_dev structure
4724 * @filter_op:operation will be taken.
4725 * @arg: a pointer to specific structure corresponding to the filter_op
4728 igb_ethertype_filter_handle(struct rte_eth_dev *dev,
4729 enum rte_filter_op filter_op,
4732 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4735 MAC_TYPE_FILTER_SUP(hw->mac.type);
4737 if (filter_op == RTE_ETH_FILTER_NOP)
4741 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4746 switch (filter_op) {
4747 case RTE_ETH_FILTER_ADD:
4748 ret = igb_add_del_ethertype_filter(dev,
4749 (struct rte_eth_ethertype_filter *)arg,
4752 case RTE_ETH_FILTER_DELETE:
4753 ret = igb_add_del_ethertype_filter(dev,
4754 (struct rte_eth_ethertype_filter *)arg,
4757 case RTE_ETH_FILTER_GET:
4758 ret = igb_get_ethertype_filter(dev,
4759 (struct rte_eth_ethertype_filter *)arg);
4762 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4770 eth_igb_filter_ctrl(struct rte_eth_dev *dev,
4771 enum rte_filter_type filter_type,
4772 enum rte_filter_op filter_op,
4777 switch (filter_type) {
4778 case RTE_ETH_FILTER_NTUPLE:
4779 ret = igb_ntuple_filter_handle(dev, filter_op, arg);
4781 case RTE_ETH_FILTER_ETHERTYPE:
4782 ret = igb_ethertype_filter_handle(dev, filter_op, arg);
4784 case RTE_ETH_FILTER_SYN:
4785 ret = eth_igb_syn_filter_handle(dev, filter_op, arg);
4787 case RTE_ETH_FILTER_FLEXIBLE:
4788 ret = eth_igb_flex_filter_handle(dev, filter_op, arg);
4791 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
4800 eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
4801 struct ether_addr *mc_addr_set,
4802 uint32_t nb_mc_addr)
4804 struct e1000_hw *hw;
4806 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4807 e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
4812 igb_read_systime_cyclecounter(struct rte_eth_dev *dev)
4814 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4815 uint64_t systime_cycles;
4817 switch (hw->mac.type) {
4821 * Need to read System Time Residue Register to be able
4822 * to read the other two registers.
4824 E1000_READ_REG(hw, E1000_SYSTIMR);
4825 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
4826 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4827 systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4834 * Need to read System Time Residue Register to be able
4835 * to read the other two registers.
4837 E1000_READ_REG(hw, E1000_SYSTIMR);
4838 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4839 /* Only the 8 LSB are valid. */
4840 systime_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_SYSTIMH)
4844 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4845 systime_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4850 return systime_cycles;
4854 igb_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4856 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4857 uint64_t rx_tstamp_cycles;
4859 switch (hw->mac.type) {
4862 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4863 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4864 rx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4870 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4871 /* Only the 8 LSB are valid. */
4872 rx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_RXSTMPH)
4876 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4877 rx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4882 return rx_tstamp_cycles;
4886 igb_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4888 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4889 uint64_t tx_tstamp_cycles;
4891 switch (hw->mac.type) {
4894 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4895 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4896 tx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4902 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4903 /* Only the 8 LSB are valid. */
4904 tx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_TXSTMPH)
4908 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4909 tx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4914 return tx_tstamp_cycles;
4918 igb_start_timecounters(struct rte_eth_dev *dev)
4920 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4921 struct e1000_adapter *adapter =
4922 (struct e1000_adapter *)dev->data->dev_private;
4923 uint32_t incval = 1;
4925 uint64_t mask = E1000_CYCLECOUNTER_MASK;
4927 switch (hw->mac.type) {
4931 /* 32 LSB bits + 8 MSB bits = 40 bits */
4932 mask = (1ULL << 40) - 1;
4937 * Start incrementing the register
4938 * used to timestamp PTP packets.
4940 E1000_WRITE_REG(hw, E1000_TIMINCA, incval);
4943 incval = E1000_INCVALUE_82576;
4944 shift = IGB_82576_TSYNC_SHIFT;
4945 E1000_WRITE_REG(hw, E1000_TIMINCA,
4946 E1000_INCPERIOD_82576 | incval);
4953 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
4954 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4955 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4957 adapter->systime_tc.cc_mask = mask;
4958 adapter->systime_tc.cc_shift = shift;
4959 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
4961 adapter->rx_tstamp_tc.cc_mask = mask;
4962 adapter->rx_tstamp_tc.cc_shift = shift;
4963 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4965 adapter->tx_tstamp_tc.cc_mask = mask;
4966 adapter->tx_tstamp_tc.cc_shift = shift;
4967 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4971 igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
4973 struct e1000_adapter *adapter =
4974 (struct e1000_adapter *)dev->data->dev_private;
4976 adapter->systime_tc.nsec += delta;
4977 adapter->rx_tstamp_tc.nsec += delta;
4978 adapter->tx_tstamp_tc.nsec += delta;
4984 igb_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
4987 struct e1000_adapter *adapter =
4988 (struct e1000_adapter *)dev->data->dev_private;
4990 ns = rte_timespec_to_ns(ts);
4992 /* Set the timecounters to a new value. */
4993 adapter->systime_tc.nsec = ns;
4994 adapter->rx_tstamp_tc.nsec = ns;
4995 adapter->tx_tstamp_tc.nsec = ns;
5001 igb_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
5003 uint64_t ns, systime_cycles;
5004 struct e1000_adapter *adapter =
5005 (struct e1000_adapter *)dev->data->dev_private;
5007 systime_cycles = igb_read_systime_cyclecounter(dev);
5008 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
5009 *ts = rte_ns_to_timespec(ns);
5015 igb_timesync_enable(struct rte_eth_dev *dev)
5017 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5021 /* Stop the timesync system time. */
5022 E1000_WRITE_REG(hw, E1000_TIMINCA, 0x0);
5023 /* Reset the timesync system time value. */
5024 switch (hw->mac.type) {
5030 E1000_WRITE_REG(hw, E1000_SYSTIMR, 0x0);
5033 E1000_WRITE_REG(hw, E1000_SYSTIML, 0x0);
5034 E1000_WRITE_REG(hw, E1000_SYSTIMH, 0x0);
5037 /* Not supported. */
5041 /* Enable system time for it isn't on by default. */
5042 tsauxc = E1000_READ_REG(hw, E1000_TSAUXC);
5043 tsauxc &= ~E1000_TSAUXC_DISABLE_SYSTIME;
5044 E1000_WRITE_REG(hw, E1000_TSAUXC, tsauxc);
5046 igb_start_timecounters(dev);
5048 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
5049 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588),
5051 E1000_ETQF_FILTER_ENABLE |
5054 /* Enable timestamping of received PTP packets. */
5055 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5056 tsync_ctl |= E1000_TSYNCRXCTL_ENABLED;
5057 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
5059 /* Enable Timestamping of transmitted PTP packets. */
5060 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5061 tsync_ctl |= E1000_TSYNCTXCTL_ENABLED;
5062 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
5068 igb_timesync_disable(struct rte_eth_dev *dev)
5070 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5073 /* Disable timestamping of transmitted PTP packets. */
5074 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5075 tsync_ctl &= ~E1000_TSYNCTXCTL_ENABLED;
5076 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
5078 /* Disable timestamping of received PTP packets. */
5079 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5080 tsync_ctl &= ~E1000_TSYNCRXCTL_ENABLED;
5081 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
5083 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
5084 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588), 0);
5086 /* Stop incrementating the System Time registers. */
5087 E1000_WRITE_REG(hw, E1000_TIMINCA, 0);
5093 igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
5094 struct timespec *timestamp,
5095 uint32_t flags __rte_unused)
5097 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5098 struct e1000_adapter *adapter =
5099 (struct e1000_adapter *)dev->data->dev_private;
5100 uint32_t tsync_rxctl;
5101 uint64_t rx_tstamp_cycles;
5104 tsync_rxctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5105 if ((tsync_rxctl & E1000_TSYNCRXCTL_VALID) == 0)
5108 rx_tstamp_cycles = igb_read_rx_tstamp_cyclecounter(dev);
5109 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
5110 *timestamp = rte_ns_to_timespec(ns);
5116 igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
5117 struct timespec *timestamp)
5119 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5120 struct e1000_adapter *adapter =
5121 (struct e1000_adapter *)dev->data->dev_private;
5122 uint32_t tsync_txctl;
5123 uint64_t tx_tstamp_cycles;
5126 tsync_txctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5127 if ((tsync_txctl & E1000_TSYNCTXCTL_VALID) == 0)
5130 tx_tstamp_cycles = igb_read_tx_tstamp_cyclecounter(dev);
5131 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
5132 *timestamp = rte_ns_to_timespec(ns);
5138 eth_igb_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5142 const struct reg_info *reg_group;
5144 while ((reg_group = igb_regs[g_ind++]))
5145 count += igb_reg_group_count(reg_group);
5151 igbvf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5155 const struct reg_info *reg_group;
5157 while ((reg_group = igbvf_regs[g_ind++]))
5158 count += igb_reg_group_count(reg_group);
5164 eth_igb_get_regs(struct rte_eth_dev *dev,
5165 struct rte_dev_reg_info *regs)
5167 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5168 uint32_t *data = regs->data;
5171 const struct reg_info *reg_group;
5174 regs->length = eth_igb_get_reg_length(dev);
5175 regs->width = sizeof(uint32_t);
5179 /* Support only full register dump */
5180 if ((regs->length == 0) ||
5181 (regs->length == (uint32_t)eth_igb_get_reg_length(dev))) {
5182 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5184 while ((reg_group = igb_regs[g_ind++]))
5185 count += igb_read_regs_group(dev, &data[count],
5194 igbvf_get_regs(struct rte_eth_dev *dev,
5195 struct rte_dev_reg_info *regs)
5197 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5198 uint32_t *data = regs->data;
5201 const struct reg_info *reg_group;
5204 regs->length = igbvf_get_reg_length(dev);
5205 regs->width = sizeof(uint32_t);
5209 /* Support only full register dump */
5210 if ((regs->length == 0) ||
5211 (regs->length == (uint32_t)igbvf_get_reg_length(dev))) {
5212 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5214 while ((reg_group = igbvf_regs[g_ind++]))
5215 count += igb_read_regs_group(dev, &data[count],
5224 eth_igb_get_eeprom_length(struct rte_eth_dev *dev)
5226 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5228 /* Return unit is byte count */
5229 return hw->nvm.word_size * 2;
5233 eth_igb_get_eeprom(struct rte_eth_dev *dev,
5234 struct rte_dev_eeprom_info *in_eeprom)
5236 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5237 struct e1000_nvm_info *nvm = &hw->nvm;
5238 uint16_t *data = in_eeprom->data;
5241 first = in_eeprom->offset >> 1;
5242 length = in_eeprom->length >> 1;
5243 if ((first >= hw->nvm.word_size) ||
5244 ((first + length) >= hw->nvm.word_size))
5247 in_eeprom->magic = hw->vendor_id |
5248 ((uint32_t)hw->device_id << 16);
5250 if ((nvm->ops.read) == NULL)
5253 return nvm->ops.read(hw, first, length, data);
5257 eth_igb_set_eeprom(struct rte_eth_dev *dev,
5258 struct rte_dev_eeprom_info *in_eeprom)
5260 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5261 struct e1000_nvm_info *nvm = &hw->nvm;
5262 uint16_t *data = in_eeprom->data;
5265 first = in_eeprom->offset >> 1;
5266 length = in_eeprom->length >> 1;
5267 if ((first >= hw->nvm.word_size) ||
5268 ((first + length) >= hw->nvm.word_size))
5271 in_eeprom->magic = (uint32_t)hw->vendor_id |
5272 ((uint32_t)hw->device_id << 16);
5274 if ((nvm->ops.write) == NULL)
5276 return nvm->ops.write(hw, first, length, data);
5280 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
5282 struct e1000_hw *hw =
5283 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5284 uint32_t mask = 1 << queue_id;
5286 E1000_WRITE_REG(hw, E1000_EIMC, mask);
5287 E1000_WRITE_FLUSH(hw);
5293 eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
5295 struct e1000_hw *hw =
5296 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5297 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5298 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5299 uint32_t mask = 1 << queue_id;
5302 regval = E1000_READ_REG(hw, E1000_EIMS);
5303 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
5304 E1000_WRITE_FLUSH(hw);
5306 rte_intr_enable(intr_handle);
5312 eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
5313 uint8_t index, uint8_t offset)
5315 uint32_t val = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
5318 val &= ~((uint32_t)0xFF << offset);
5320 /* write vector and valid bit */
5321 val |= (msix_vector | E1000_IVAR_VALID) << offset;
5323 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, val);
5327 eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
5328 uint8_t queue, uint8_t msix_vector)
5332 if (hw->mac.type == e1000_82575) {
5334 tmp = E1000_EICR_RX_QUEUE0 << queue;
5335 else if (direction == 1)
5336 tmp = E1000_EICR_TX_QUEUE0 << queue;
5337 E1000_WRITE_REG(hw, E1000_MSIXBM(msix_vector), tmp);
5338 } else if (hw->mac.type == e1000_82576) {
5339 if ((direction == 0) || (direction == 1))
5340 eth_igb_write_ivar(hw, msix_vector, queue & 0x7,
5341 ((queue & 0x8) << 1) +
5343 } else if ((hw->mac.type == e1000_82580) ||
5344 (hw->mac.type == e1000_i350) ||
5345 (hw->mac.type == e1000_i354) ||
5346 (hw->mac.type == e1000_i210) ||
5347 (hw->mac.type == e1000_i211)) {
5348 if ((direction == 0) || (direction == 1))
5349 eth_igb_write_ivar(hw, msix_vector,
5351 ((queue & 0x1) << 4) +
5356 /* Sets up the hardware to generate MSI-X interrupts properly
5358 * board private structure
5361 eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
5364 uint32_t tmpval, regval, intr_mask;
5365 struct e1000_hw *hw =
5366 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5367 uint32_t vec = E1000_MISC_VEC_ID;
5368 uint32_t base = E1000_MISC_VEC_ID;
5369 uint32_t misc_shift = 0;
5370 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5371 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5373 /* won't configure msix register if no mapping is done
5374 * between intr vector and event fd
5376 if (!rte_intr_dp_is_en(intr_handle))
5379 if (rte_intr_allow_others(intr_handle)) {
5380 vec = base = E1000_RX_VEC_START;
5384 /* set interrupt vector for other causes */
5385 if (hw->mac.type == e1000_82575) {
5386 tmpval = E1000_READ_REG(hw, E1000_CTRL_EXT);
5387 /* enable MSI-X PBA support */
5388 tmpval |= E1000_CTRL_EXT_PBA_CLR;
5390 /* Auto-Mask interrupts upon ICR read */
5391 tmpval |= E1000_CTRL_EXT_EIAME;
5392 tmpval |= E1000_CTRL_EXT_IRCA;
5394 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmpval);
5396 /* enable msix_other interrupt */
5397 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), 0, E1000_EIMS_OTHER);
5398 regval = E1000_READ_REG(hw, E1000_EIAC);
5399 E1000_WRITE_REG(hw, E1000_EIAC, regval | E1000_EIMS_OTHER);
5400 regval = E1000_READ_REG(hw, E1000_EIAM);
5401 E1000_WRITE_REG(hw, E1000_EIMS, regval | E1000_EIMS_OTHER);
5402 } else if ((hw->mac.type == e1000_82576) ||
5403 (hw->mac.type == e1000_82580) ||
5404 (hw->mac.type == e1000_i350) ||
5405 (hw->mac.type == e1000_i354) ||
5406 (hw->mac.type == e1000_i210) ||
5407 (hw->mac.type == e1000_i211)) {
5408 /* turn on MSI-X capability first */
5409 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
5410 E1000_GPIE_PBA | E1000_GPIE_EIAME |
5412 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
5414 regval = E1000_READ_REG(hw, E1000_EIAC);
5415 E1000_WRITE_REG(hw, E1000_EIAC, regval | intr_mask);
5417 /* enable msix_other interrupt */
5418 regval = E1000_READ_REG(hw, E1000_EIMS);
5419 E1000_WRITE_REG(hw, E1000_EIMS, regval | intr_mask);
5420 tmpval = (dev->data->nb_rx_queues | E1000_IVAR_VALID) << 8;
5421 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmpval);
5424 /* use EIAM to auto-mask when MSI-X interrupt
5425 * is asserted, this saves a register write for every interrupt
5427 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
5429 regval = E1000_READ_REG(hw, E1000_EIAM);
5430 E1000_WRITE_REG(hw, E1000_EIAM, regval | intr_mask);
5432 for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
5433 eth_igb_assign_msix_vector(hw, 0, queue_id, vec);
5434 intr_handle->intr_vec[queue_id] = vec;
5435 if (vec < base + intr_handle->nb_efd - 1)
5439 E1000_WRITE_FLUSH(hw);
5442 /* restore SYN filter */
5444 igb_syn_filter_restore(struct rte_eth_dev *dev)
5446 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5447 struct e1000_filter_info *filter_info =
5448 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5451 synqf = filter_info->syn_info;
5453 if (synqf & E1000_SYN_FILTER_ENABLE) {
5454 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
5455 E1000_WRITE_FLUSH(hw);
5459 /* restore all types filter */
5461 igb_filter_restore(struct rte_eth_dev *dev)
5463 igb_syn_filter_restore(dev);
5468 RTE_PMD_REGISTER_PCI(net_e1000_igb, rte_igb_pmd);
5469 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb, pci_id_igb_map);
5470 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb, "* igb_uio | uio_pci_generic | vfio-pci");
5471 RTE_PMD_REGISTER_PCI(net_e1000_igb_vf, rte_igbvf_pmd);
5472 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb_vf, pci_id_igbvf_map);
5473 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb_vf, "* igb_uio | vfio-pci");