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_names(struct rte_eth_dev *dev,
120 struct rte_eth_xstat_name *xstats_names,
122 static void eth_igb_stats_reset(struct rte_eth_dev *dev);
123 static void eth_igb_xstats_reset(struct rte_eth_dev *dev);
124 static int eth_igb_fw_version_get(struct rte_eth_dev *dev,
125 char *fw_version, size_t fw_size);
126 static void eth_igb_infos_get(struct rte_eth_dev *dev,
127 struct rte_eth_dev_info *dev_info);
128 static const uint32_t *eth_igb_supported_ptypes_get(struct rte_eth_dev *dev);
129 static void eth_igbvf_infos_get(struct rte_eth_dev *dev,
130 struct rte_eth_dev_info *dev_info);
131 static int eth_igb_flow_ctrl_get(struct rte_eth_dev *dev,
132 struct rte_eth_fc_conf *fc_conf);
133 static int eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
134 struct rte_eth_fc_conf *fc_conf);
135 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev);
136 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
137 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
138 static int eth_igb_interrupt_action(struct rte_eth_dev *dev,
139 struct rte_intr_handle *handle);
140 static void eth_igb_interrupt_handler(void *param);
141 static int igb_hardware_init(struct e1000_hw *hw);
142 static void igb_hw_control_acquire(struct e1000_hw *hw);
143 static void igb_hw_control_release(struct e1000_hw *hw);
144 static void igb_init_manageability(struct e1000_hw *hw);
145 static void igb_release_manageability(struct e1000_hw *hw);
147 static int eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
149 static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
150 uint16_t vlan_id, int on);
151 static int eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
152 enum rte_vlan_type vlan_type,
154 static void eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
156 static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
157 static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
158 static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
159 static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
160 static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
161 static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
163 static int eth_igb_led_on(struct rte_eth_dev *dev);
164 static int eth_igb_led_off(struct rte_eth_dev *dev);
166 static void igb_intr_disable(struct e1000_hw *hw);
167 static int igb_get_rx_buffer_size(struct e1000_hw *hw);
168 static void eth_igb_rar_set(struct rte_eth_dev *dev,
169 struct ether_addr *mac_addr,
170 uint32_t index, uint32_t pool);
171 static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
172 static void eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
173 struct ether_addr *addr);
175 static void igbvf_intr_disable(struct e1000_hw *hw);
176 static int igbvf_dev_configure(struct rte_eth_dev *dev);
177 static int igbvf_dev_start(struct rte_eth_dev *dev);
178 static void igbvf_dev_stop(struct rte_eth_dev *dev);
179 static void igbvf_dev_close(struct rte_eth_dev *dev);
180 static void igbvf_promiscuous_enable(struct rte_eth_dev *dev);
181 static void igbvf_promiscuous_disable(struct rte_eth_dev *dev);
182 static void igbvf_allmulticast_enable(struct rte_eth_dev *dev);
183 static void igbvf_allmulticast_disable(struct rte_eth_dev *dev);
184 static int eth_igbvf_link_update(struct e1000_hw *hw);
185 static void eth_igbvf_stats_get(struct rte_eth_dev *dev,
186 struct rte_eth_stats *rte_stats);
187 static int eth_igbvf_xstats_get(struct rte_eth_dev *dev,
188 struct rte_eth_xstat *xstats, unsigned n);
189 static int eth_igbvf_xstats_get_names(struct rte_eth_dev *dev,
190 struct rte_eth_xstat_name *xstats_names,
192 static void eth_igbvf_stats_reset(struct rte_eth_dev *dev);
193 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
194 uint16_t vlan_id, int on);
195 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
196 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
197 static void igbvf_default_mac_addr_set(struct rte_eth_dev *dev,
198 struct ether_addr *addr);
199 static int igbvf_get_reg_length(struct rte_eth_dev *dev);
200 static int igbvf_get_regs(struct rte_eth_dev *dev,
201 struct rte_dev_reg_info *regs);
203 static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
204 struct rte_eth_rss_reta_entry64 *reta_conf,
206 static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
207 struct rte_eth_rss_reta_entry64 *reta_conf,
210 static int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
211 struct rte_eth_syn_filter *filter,
213 static int eth_igb_syn_filter_get(struct rte_eth_dev *dev,
214 struct rte_eth_syn_filter *filter);
215 static int eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
216 enum rte_filter_op filter_op,
218 static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
219 struct rte_eth_ntuple_filter *ntuple_filter);
220 static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
221 struct rte_eth_ntuple_filter *ntuple_filter);
222 static int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
223 struct rte_eth_flex_filter *filter,
225 static int eth_igb_get_flex_filter(struct rte_eth_dev *dev,
226 struct rte_eth_flex_filter *filter);
227 static int eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
228 enum rte_filter_op filter_op,
230 static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
231 struct rte_eth_ntuple_filter *ntuple_filter);
232 static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
233 struct rte_eth_ntuple_filter *ntuple_filter);
234 static int igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
235 struct rte_eth_ntuple_filter *filter,
237 static int igb_get_ntuple_filter(struct rte_eth_dev *dev,
238 struct rte_eth_ntuple_filter *filter);
239 static int igb_ntuple_filter_handle(struct rte_eth_dev *dev,
240 enum rte_filter_op filter_op,
242 static int igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
243 struct rte_eth_ethertype_filter *filter,
245 static int igb_ethertype_filter_handle(struct rte_eth_dev *dev,
246 enum rte_filter_op filter_op,
248 static int igb_get_ethertype_filter(struct rte_eth_dev *dev,
249 struct rte_eth_ethertype_filter *filter);
250 static int eth_igb_filter_ctrl(struct rte_eth_dev *dev,
251 enum rte_filter_type filter_type,
252 enum rte_filter_op filter_op,
254 static int eth_igb_get_reg_length(struct rte_eth_dev *dev);
255 static int eth_igb_get_regs(struct rte_eth_dev *dev,
256 struct rte_dev_reg_info *regs);
257 static int eth_igb_get_eeprom_length(struct rte_eth_dev *dev);
258 static int eth_igb_get_eeprom(struct rte_eth_dev *dev,
259 struct rte_dev_eeprom_info *eeprom);
260 static int eth_igb_set_eeprom(struct rte_eth_dev *dev,
261 struct rte_dev_eeprom_info *eeprom);
262 static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
263 struct ether_addr *mc_addr_set,
264 uint32_t nb_mc_addr);
265 static int igb_timesync_enable(struct rte_eth_dev *dev);
266 static int igb_timesync_disable(struct rte_eth_dev *dev);
267 static int igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
268 struct timespec *timestamp,
270 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
271 struct timespec *timestamp);
272 static int igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
273 static int igb_timesync_read_time(struct rte_eth_dev *dev,
274 struct timespec *timestamp);
275 static int igb_timesync_write_time(struct rte_eth_dev *dev,
276 const struct timespec *timestamp);
277 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
279 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
281 static void eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
282 uint8_t queue, uint8_t msix_vector);
283 static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
284 uint8_t index, uint8_t offset);
285 static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
286 static void eth_igbvf_interrupt_handler(void *param);
287 static void igbvf_mbx_process(struct rte_eth_dev *dev);
290 * Define VF Stats MACRO for Non "cleared on read" register
292 #define UPDATE_VF_STAT(reg, last, cur) \
294 u32 latest = E1000_READ_REG(hw, reg); \
295 cur += (latest - last) & UINT_MAX; \
299 #define IGB_FC_PAUSE_TIME 0x0680
300 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
301 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
303 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
305 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
308 * The set of PCI devices this driver supports
310 static const struct rte_pci_id pci_id_igb_map[] = {
311 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576) },
312 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_FIBER) },
313 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES) },
314 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER) },
315 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER_ET2) },
316 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS) },
317 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS_SERDES) },
318 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES_QUAD) },
320 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_COPPER) },
321 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_FIBER_SERDES) },
322 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575GB_QUAD_COPPER) },
324 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER) },
325 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_FIBER) },
326 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SERDES) },
327 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SGMII) },
328 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER_DUAL) },
329 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_QUAD_FIBER) },
331 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_COPPER) },
332 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_FIBER) },
333 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SERDES) },
334 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SGMII) },
335 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_DA4) },
336 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER) },
337 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_OEM1) },
338 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_IT) },
339 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_FIBER) },
340 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES) },
341 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SGMII) },
342 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I211_COPPER) },
343 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
344 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_SGMII) },
345 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
346 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SGMII) },
347 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SERDES) },
348 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_BACKPLANE) },
349 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SFP) },
350 { .vendor_id = 0, /* sentinel */ },
354 * The set of PCI devices this driver supports (for 82576&I350 VF)
356 static const struct rte_pci_id pci_id_igbvf_map[] = {
357 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF) },
358 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF_HV) },
359 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF) },
360 { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF_HV) },
361 { .vendor_id = 0, /* sentinel */ },
364 static const struct rte_eth_desc_lim rx_desc_lim = {
365 .nb_max = E1000_MAX_RING_DESC,
366 .nb_min = E1000_MIN_RING_DESC,
367 .nb_align = IGB_RXD_ALIGN,
370 static const struct rte_eth_desc_lim tx_desc_lim = {
371 .nb_max = E1000_MAX_RING_DESC,
372 .nb_min = E1000_MIN_RING_DESC,
373 .nb_align = IGB_RXD_ALIGN,
374 .nb_seg_max = IGB_TX_MAX_SEG,
375 .nb_mtu_seg_max = IGB_TX_MAX_MTU_SEG,
378 static const struct eth_dev_ops eth_igb_ops = {
379 .dev_configure = eth_igb_configure,
380 .dev_start = eth_igb_start,
381 .dev_stop = eth_igb_stop,
382 .dev_set_link_up = eth_igb_dev_set_link_up,
383 .dev_set_link_down = eth_igb_dev_set_link_down,
384 .dev_close = eth_igb_close,
385 .promiscuous_enable = eth_igb_promiscuous_enable,
386 .promiscuous_disable = eth_igb_promiscuous_disable,
387 .allmulticast_enable = eth_igb_allmulticast_enable,
388 .allmulticast_disable = eth_igb_allmulticast_disable,
389 .link_update = eth_igb_link_update,
390 .stats_get = eth_igb_stats_get,
391 .xstats_get = eth_igb_xstats_get,
392 .xstats_get_names = eth_igb_xstats_get_names,
393 .stats_reset = eth_igb_stats_reset,
394 .xstats_reset = eth_igb_xstats_reset,
395 .fw_version_get = eth_igb_fw_version_get,
396 .dev_infos_get = eth_igb_infos_get,
397 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
398 .mtu_set = eth_igb_mtu_set,
399 .vlan_filter_set = eth_igb_vlan_filter_set,
400 .vlan_tpid_set = eth_igb_vlan_tpid_set,
401 .vlan_offload_set = eth_igb_vlan_offload_set,
402 .rx_queue_setup = eth_igb_rx_queue_setup,
403 .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
404 .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
405 .rx_queue_release = eth_igb_rx_queue_release,
406 .rx_queue_count = eth_igb_rx_queue_count,
407 .rx_descriptor_done = eth_igb_rx_descriptor_done,
408 .rx_descriptor_status = eth_igb_rx_descriptor_status,
409 .tx_descriptor_status = eth_igb_tx_descriptor_status,
410 .tx_queue_setup = eth_igb_tx_queue_setup,
411 .tx_queue_release = eth_igb_tx_queue_release,
412 .tx_done_cleanup = eth_igb_tx_done_cleanup,
413 .dev_led_on = eth_igb_led_on,
414 .dev_led_off = eth_igb_led_off,
415 .flow_ctrl_get = eth_igb_flow_ctrl_get,
416 .flow_ctrl_set = eth_igb_flow_ctrl_set,
417 .mac_addr_add = eth_igb_rar_set,
418 .mac_addr_remove = eth_igb_rar_clear,
419 .mac_addr_set = eth_igb_default_mac_addr_set,
420 .reta_update = eth_igb_rss_reta_update,
421 .reta_query = eth_igb_rss_reta_query,
422 .rss_hash_update = eth_igb_rss_hash_update,
423 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
424 .filter_ctrl = eth_igb_filter_ctrl,
425 .set_mc_addr_list = eth_igb_set_mc_addr_list,
426 .rxq_info_get = igb_rxq_info_get,
427 .txq_info_get = igb_txq_info_get,
428 .timesync_enable = igb_timesync_enable,
429 .timesync_disable = igb_timesync_disable,
430 .timesync_read_rx_timestamp = igb_timesync_read_rx_timestamp,
431 .timesync_read_tx_timestamp = igb_timesync_read_tx_timestamp,
432 .get_reg = eth_igb_get_regs,
433 .get_eeprom_length = eth_igb_get_eeprom_length,
434 .get_eeprom = eth_igb_get_eeprom,
435 .set_eeprom = eth_igb_set_eeprom,
436 .timesync_adjust_time = igb_timesync_adjust_time,
437 .timesync_read_time = igb_timesync_read_time,
438 .timesync_write_time = igb_timesync_write_time,
442 * dev_ops for virtual function, bare necessities for basic vf
443 * operation have been implemented
445 static const struct eth_dev_ops igbvf_eth_dev_ops = {
446 .dev_configure = igbvf_dev_configure,
447 .dev_start = igbvf_dev_start,
448 .dev_stop = igbvf_dev_stop,
449 .dev_close = igbvf_dev_close,
450 .promiscuous_enable = igbvf_promiscuous_enable,
451 .promiscuous_disable = igbvf_promiscuous_disable,
452 .allmulticast_enable = igbvf_allmulticast_enable,
453 .allmulticast_disable = igbvf_allmulticast_disable,
454 .link_update = eth_igb_link_update,
455 .stats_get = eth_igbvf_stats_get,
456 .xstats_get = eth_igbvf_xstats_get,
457 .xstats_get_names = eth_igbvf_xstats_get_names,
458 .stats_reset = eth_igbvf_stats_reset,
459 .xstats_reset = eth_igbvf_stats_reset,
460 .vlan_filter_set = igbvf_vlan_filter_set,
461 .dev_infos_get = eth_igbvf_infos_get,
462 .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
463 .rx_queue_setup = eth_igb_rx_queue_setup,
464 .rx_queue_release = eth_igb_rx_queue_release,
465 .tx_queue_setup = eth_igb_tx_queue_setup,
466 .tx_queue_release = eth_igb_tx_queue_release,
467 .set_mc_addr_list = eth_igb_set_mc_addr_list,
468 .rxq_info_get = igb_rxq_info_get,
469 .txq_info_get = igb_txq_info_get,
470 .mac_addr_set = igbvf_default_mac_addr_set,
471 .get_reg = igbvf_get_regs,
474 /* store statistics names and its offset in stats structure */
475 struct rte_igb_xstats_name_off {
476 char name[RTE_ETH_XSTATS_NAME_SIZE];
480 static const struct rte_igb_xstats_name_off rte_igb_stats_strings[] = {
481 {"rx_crc_errors", offsetof(struct e1000_hw_stats, crcerrs)},
482 {"rx_align_errors", offsetof(struct e1000_hw_stats, algnerrc)},
483 {"rx_symbol_errors", offsetof(struct e1000_hw_stats, symerrs)},
484 {"rx_missed_packets", offsetof(struct e1000_hw_stats, mpc)},
485 {"tx_single_collision_packets", offsetof(struct e1000_hw_stats, scc)},
486 {"tx_multiple_collision_packets", offsetof(struct e1000_hw_stats, mcc)},
487 {"tx_excessive_collision_packets", offsetof(struct e1000_hw_stats,
489 {"tx_late_collisions", offsetof(struct e1000_hw_stats, latecol)},
490 {"tx_total_collisions", offsetof(struct e1000_hw_stats, colc)},
491 {"tx_deferred_packets", offsetof(struct e1000_hw_stats, dc)},
492 {"tx_no_carrier_sense_packets", offsetof(struct e1000_hw_stats, tncrs)},
493 {"rx_carrier_ext_errors", offsetof(struct e1000_hw_stats, cexterr)},
494 {"rx_length_errors", offsetof(struct e1000_hw_stats, rlec)},
495 {"rx_xon_packets", offsetof(struct e1000_hw_stats, xonrxc)},
496 {"tx_xon_packets", offsetof(struct e1000_hw_stats, xontxc)},
497 {"rx_xoff_packets", offsetof(struct e1000_hw_stats, xoffrxc)},
498 {"tx_xoff_packets", offsetof(struct e1000_hw_stats, xofftxc)},
499 {"rx_flow_control_unsupported_packets", offsetof(struct e1000_hw_stats,
501 {"rx_size_64_packets", offsetof(struct e1000_hw_stats, prc64)},
502 {"rx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, prc127)},
503 {"rx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, prc255)},
504 {"rx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, prc511)},
505 {"rx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
507 {"rx_size_1024_to_max_packets", offsetof(struct e1000_hw_stats,
509 {"rx_broadcast_packets", offsetof(struct e1000_hw_stats, bprc)},
510 {"rx_multicast_packets", offsetof(struct e1000_hw_stats, mprc)},
511 {"rx_undersize_errors", offsetof(struct e1000_hw_stats, ruc)},
512 {"rx_fragment_errors", offsetof(struct e1000_hw_stats, rfc)},
513 {"rx_oversize_errors", offsetof(struct e1000_hw_stats, roc)},
514 {"rx_jabber_errors", offsetof(struct e1000_hw_stats, rjc)},
515 {"rx_management_packets", offsetof(struct e1000_hw_stats, mgprc)},
516 {"rx_management_dropped", offsetof(struct e1000_hw_stats, mgpdc)},
517 {"tx_management_packets", offsetof(struct e1000_hw_stats, mgptc)},
518 {"rx_total_packets", offsetof(struct e1000_hw_stats, tpr)},
519 {"tx_total_packets", offsetof(struct e1000_hw_stats, tpt)},
520 {"rx_total_bytes", offsetof(struct e1000_hw_stats, tor)},
521 {"tx_total_bytes", offsetof(struct e1000_hw_stats, tot)},
522 {"tx_size_64_packets", offsetof(struct e1000_hw_stats, ptc64)},
523 {"tx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, ptc127)},
524 {"tx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, ptc255)},
525 {"tx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, ptc511)},
526 {"tx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
528 {"tx_size_1023_to_max_packets", offsetof(struct e1000_hw_stats,
530 {"tx_multicast_packets", offsetof(struct e1000_hw_stats, mptc)},
531 {"tx_broadcast_packets", offsetof(struct e1000_hw_stats, bptc)},
532 {"tx_tso_packets", offsetof(struct e1000_hw_stats, tsctc)},
533 {"tx_tso_errors", offsetof(struct e1000_hw_stats, tsctfc)},
534 {"rx_sent_to_host_packets", offsetof(struct e1000_hw_stats, rpthc)},
535 {"tx_sent_by_host_packets", offsetof(struct e1000_hw_stats, hgptc)},
536 {"rx_code_violation_packets", offsetof(struct e1000_hw_stats, scvpc)},
538 {"interrupt_assert_count", offsetof(struct e1000_hw_stats, iac)},
541 #define IGB_NB_XSTATS (sizeof(rte_igb_stats_strings) / \
542 sizeof(rte_igb_stats_strings[0]))
544 static const struct rte_igb_xstats_name_off rte_igbvf_stats_strings[] = {
545 {"rx_multicast_packets", offsetof(struct e1000_vf_stats, mprc)},
546 {"rx_good_loopback_packets", offsetof(struct e1000_vf_stats, gprlbc)},
547 {"tx_good_loopback_packets", offsetof(struct e1000_vf_stats, gptlbc)},
548 {"rx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gorlbc)},
549 {"tx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gotlbc)},
552 #define IGBVF_NB_XSTATS (sizeof(rte_igbvf_stats_strings) / \
553 sizeof(rte_igbvf_stats_strings[0]))
556 * Atomically reads the link status information from global
557 * structure rte_eth_dev.
560 * - Pointer to the structure rte_eth_dev to read from.
561 * - Pointer to the buffer to be saved with the link status.
564 * - On success, zero.
565 * - On failure, negative value.
568 rte_igb_dev_atomic_read_link_status(struct rte_eth_dev *dev,
569 struct rte_eth_link *link)
571 struct rte_eth_link *dst = link;
572 struct rte_eth_link *src = &(dev->data->dev_link);
574 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
575 *(uint64_t *)src) == 0)
582 * Atomically writes the link status information into global
583 * structure rte_eth_dev.
586 * - Pointer to the structure rte_eth_dev to read from.
587 * - Pointer to the buffer to be saved with the link status.
590 * - On success, zero.
591 * - On failure, negative value.
594 rte_igb_dev_atomic_write_link_status(struct rte_eth_dev *dev,
595 struct rte_eth_link *link)
597 struct rte_eth_link *dst = &(dev->data->dev_link);
598 struct rte_eth_link *src = link;
600 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
601 *(uint64_t *)src) == 0)
608 igb_intr_enable(struct rte_eth_dev *dev)
610 struct e1000_interrupt *intr =
611 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
612 struct e1000_hw *hw =
613 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
615 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
616 E1000_WRITE_FLUSH(hw);
620 igb_intr_disable(struct e1000_hw *hw)
622 E1000_WRITE_REG(hw, E1000_IMC, ~0);
623 E1000_WRITE_FLUSH(hw);
627 igbvf_intr_enable(struct rte_eth_dev *dev)
629 struct e1000_hw *hw =
630 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
632 /* only for mailbox */
633 E1000_WRITE_REG(hw, E1000_EIAM, 1 << E1000_VTIVAR_MISC_MAILBOX);
634 E1000_WRITE_REG(hw, E1000_EIAC, 1 << E1000_VTIVAR_MISC_MAILBOX);
635 E1000_WRITE_REG(hw, E1000_EIMS, 1 << E1000_VTIVAR_MISC_MAILBOX);
636 E1000_WRITE_FLUSH(hw);
639 /* only for mailbox now. If RX/TX needed, should extend this function. */
641 igbvf_set_ivar_map(struct e1000_hw *hw, uint8_t msix_vector)
646 tmp |= (msix_vector & E1000_VTIVAR_MISC_INTR_MASK);
647 tmp |= E1000_VTIVAR_VALID;
648 E1000_WRITE_REG(hw, E1000_VTIVAR_MISC, tmp);
652 eth_igbvf_configure_msix_intr(struct rte_eth_dev *dev)
654 struct e1000_hw *hw =
655 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
657 /* Configure VF other cause ivar */
658 igbvf_set_ivar_map(hw, E1000_VTIVAR_MISC_MAILBOX);
661 static inline int32_t
662 igb_pf_reset_hw(struct e1000_hw *hw)
667 status = e1000_reset_hw(hw);
669 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
670 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
671 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
672 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
673 E1000_WRITE_FLUSH(hw);
679 igb_identify_hardware(struct rte_eth_dev *dev, struct rte_pci_device *pci_dev)
681 struct e1000_hw *hw =
682 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
685 hw->vendor_id = pci_dev->id.vendor_id;
686 hw->device_id = pci_dev->id.device_id;
687 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
688 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
690 e1000_set_mac_type(hw);
692 /* need to check if it is a vf device below */
696 igb_reset_swfw_lock(struct e1000_hw *hw)
701 * Do mac ops initialization manually here, since we will need
702 * some function pointers set by this call.
704 ret_val = e1000_init_mac_params(hw);
709 * SMBI lock should not fail in this early stage. If this is the case,
710 * it is due to an improper exit of the application.
711 * So force the release of the faulty lock.
713 if (e1000_get_hw_semaphore_generic(hw) < 0) {
714 PMD_DRV_LOG(DEBUG, "SMBI lock released");
716 e1000_put_hw_semaphore_generic(hw);
718 if (hw->mac.ops.acquire_swfw_sync != NULL) {
722 * Phy lock should not fail in this early stage. If this is the case,
723 * it is due to an improper exit of the application.
724 * So force the release of the faulty lock.
726 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
727 if (hw->bus.func > E1000_FUNC_1)
729 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
730 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
733 hw->mac.ops.release_swfw_sync(hw, mask);
736 * This one is more tricky since it is common to all ports; but
737 * swfw_sync retries last long enough (1s) to be almost sure that if
738 * lock can not be taken it is due to an improper lock of the
741 mask = E1000_SWFW_EEP_SM;
742 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
743 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
745 hw->mac.ops.release_swfw_sync(hw, mask);
748 return E1000_SUCCESS;
752 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
755 struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
756 struct e1000_hw *hw =
757 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
758 struct e1000_vfta * shadow_vfta =
759 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
760 struct e1000_filter_info *filter_info =
761 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
762 struct e1000_adapter *adapter =
763 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
767 eth_dev->dev_ops = ð_igb_ops;
768 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
769 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
770 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
772 /* for secondary processes, we don't initialise any further as primary
773 * has already done this work. Only check we don't need a different
775 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
776 if (eth_dev->data->scattered_rx)
777 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
781 rte_eth_copy_pci_info(eth_dev, pci_dev);
782 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
784 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
786 igb_identify_hardware(eth_dev, pci_dev);
787 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
792 e1000_get_bus_info(hw);
794 /* Reset any pending lock */
795 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
800 /* Finish initialization */
801 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
807 hw->phy.autoneg_wait_to_complete = 0;
808 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
811 if (hw->phy.media_type == e1000_media_type_copper) {
812 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
813 hw->phy.disable_polarity_correction = 0;
814 hw->phy.ms_type = e1000_ms_hw_default;
818 * Start from a known state, this is important in reading the nvm
823 /* Make sure we have a good EEPROM before we read from it */
824 if (e1000_validate_nvm_checksum(hw) < 0) {
826 * Some PCI-E parts fail the first check due to
827 * the link being in sleep state, call it again,
828 * if it fails a second time its a real issue.
830 if (e1000_validate_nvm_checksum(hw) < 0) {
831 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
837 /* Read the permanent MAC address out of the EEPROM */
838 if (e1000_read_mac_addr(hw) != 0) {
839 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
844 /* Allocate memory for storing MAC addresses */
845 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
846 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
847 if (eth_dev->data->mac_addrs == NULL) {
848 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
849 "store MAC addresses",
850 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
855 /* Copy the permanent MAC address */
856 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
858 /* initialize the vfta */
859 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
861 /* Now initialize the hardware */
862 if (igb_hardware_init(hw) != 0) {
863 PMD_INIT_LOG(ERR, "Hardware initialization failed");
864 rte_free(eth_dev->data->mac_addrs);
865 eth_dev->data->mac_addrs = NULL;
869 hw->mac.get_link_status = 1;
870 adapter->stopped = 0;
872 /* Indicate SOL/IDER usage */
873 if (e1000_check_reset_block(hw) < 0) {
874 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
878 /* initialize PF if max_vfs not zero */
879 igb_pf_host_init(eth_dev);
881 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
882 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
883 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
884 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
885 E1000_WRITE_FLUSH(hw);
887 PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
888 eth_dev->data->port_id, pci_dev->id.vendor_id,
889 pci_dev->id.device_id);
891 rte_intr_callback_register(&pci_dev->intr_handle,
892 eth_igb_interrupt_handler,
895 /* enable uio/vfio intr/eventfd mapping */
896 rte_intr_enable(&pci_dev->intr_handle);
898 /* enable support intr */
899 igb_intr_enable(eth_dev);
901 TAILQ_INIT(&filter_info->flex_list);
902 filter_info->flex_mask = 0;
903 TAILQ_INIT(&filter_info->twotuple_list);
904 filter_info->twotuple_mask = 0;
905 TAILQ_INIT(&filter_info->fivetuple_list);
906 filter_info->fivetuple_mask = 0;
911 igb_hw_control_release(hw);
917 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
919 struct rte_pci_device *pci_dev;
920 struct rte_intr_handle *intr_handle;
922 struct e1000_adapter *adapter =
923 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
925 PMD_INIT_FUNC_TRACE();
927 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
930 hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
931 pci_dev = E1000_DEV_TO_PCI(eth_dev);
932 intr_handle = &pci_dev->intr_handle;
934 if (adapter->stopped == 0)
935 eth_igb_close(eth_dev);
937 eth_dev->dev_ops = NULL;
938 eth_dev->rx_pkt_burst = NULL;
939 eth_dev->tx_pkt_burst = NULL;
941 /* Reset any pending lock */
942 igb_reset_swfw_lock(hw);
944 rte_free(eth_dev->data->mac_addrs);
945 eth_dev->data->mac_addrs = NULL;
947 /* uninitialize PF if max_vfs not zero */
948 igb_pf_host_uninit(eth_dev);
950 /* disable uio intr before callback unregister */
951 rte_intr_disable(intr_handle);
952 rte_intr_callback_unregister(intr_handle,
953 eth_igb_interrupt_handler, eth_dev);
959 * Virtual Function device init
962 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
964 struct rte_pci_device *pci_dev;
965 struct rte_intr_handle *intr_handle;
966 struct e1000_adapter *adapter =
967 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
968 struct e1000_hw *hw =
969 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
971 struct ether_addr *perm_addr = (struct ether_addr *)hw->mac.perm_addr;
973 PMD_INIT_FUNC_TRACE();
975 eth_dev->dev_ops = &igbvf_eth_dev_ops;
976 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
977 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
978 eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
980 /* for secondary processes, we don't initialise any further as primary
981 * has already done this work. Only check we don't need a different
983 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
984 if (eth_dev->data->scattered_rx)
985 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
989 pci_dev = E1000_DEV_TO_PCI(eth_dev);
990 rte_eth_copy_pci_info(eth_dev, pci_dev);
991 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
993 hw->device_id = pci_dev->id.device_id;
994 hw->vendor_id = pci_dev->id.vendor_id;
995 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
996 adapter->stopped = 0;
998 /* Initialize the shared code (base driver) */
999 diag = e1000_setup_init_funcs(hw, TRUE);
1001 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
1006 /* init_mailbox_params */
1007 hw->mbx.ops.init_params(hw);
1009 /* Disable the interrupts for VF */
1010 igbvf_intr_disable(hw);
1012 diag = hw->mac.ops.reset_hw(hw);
1014 /* Allocate memory for storing MAC addresses */
1015 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
1016 hw->mac.rar_entry_count, 0);
1017 if (eth_dev->data->mac_addrs == NULL) {
1019 "Failed to allocate %d bytes needed to store MAC "
1021 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
1025 /* Generate a random MAC address, if none was assigned by PF. */
1026 if (is_zero_ether_addr(perm_addr)) {
1027 eth_random_addr(perm_addr->addr_bytes);
1028 diag = e1000_rar_set(hw, perm_addr->addr_bytes, 0);
1030 rte_free(eth_dev->data->mac_addrs);
1031 eth_dev->data->mac_addrs = NULL;
1034 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1035 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1036 "%02x:%02x:%02x:%02x:%02x:%02x",
1037 perm_addr->addr_bytes[0],
1038 perm_addr->addr_bytes[1],
1039 perm_addr->addr_bytes[2],
1040 perm_addr->addr_bytes[3],
1041 perm_addr->addr_bytes[4],
1042 perm_addr->addr_bytes[5]);
1045 /* Copy the permanent MAC address */
1046 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
1047 ð_dev->data->mac_addrs[0]);
1049 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
1051 eth_dev->data->port_id, pci_dev->id.vendor_id,
1052 pci_dev->id.device_id, "igb_mac_82576_vf");
1054 intr_handle = &pci_dev->intr_handle;
1055 rte_intr_callback_register(intr_handle,
1056 eth_igbvf_interrupt_handler, eth_dev);
1062 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
1064 struct e1000_adapter *adapter =
1065 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
1066 struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(eth_dev);
1068 PMD_INIT_FUNC_TRACE();
1070 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1073 if (adapter->stopped == 0)
1074 igbvf_dev_close(eth_dev);
1076 eth_dev->dev_ops = NULL;
1077 eth_dev->rx_pkt_burst = NULL;
1078 eth_dev->tx_pkt_burst = NULL;
1080 rte_free(eth_dev->data->mac_addrs);
1081 eth_dev->data->mac_addrs = NULL;
1083 /* disable uio intr before callback unregister */
1084 rte_intr_disable(&pci_dev->intr_handle);
1085 rte_intr_callback_unregister(&pci_dev->intr_handle,
1086 eth_igbvf_interrupt_handler,
1092 static int eth_igb_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1093 struct rte_pci_device *pci_dev)
1095 return rte_eth_dev_pci_generic_probe(pci_dev,
1096 sizeof(struct e1000_adapter), eth_igb_dev_init);
1099 static int eth_igb_pci_remove(struct rte_pci_device *pci_dev)
1101 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igb_dev_uninit);
1104 static struct rte_pci_driver rte_igb_pmd = {
1105 .id_table = pci_id_igb_map,
1106 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1107 .probe = eth_igb_pci_probe,
1108 .remove = eth_igb_pci_remove,
1112 static int eth_igbvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1113 struct rte_pci_device *pci_dev)
1115 return rte_eth_dev_pci_generic_probe(pci_dev,
1116 sizeof(struct e1000_adapter), eth_igbvf_dev_init);
1119 static int eth_igbvf_pci_remove(struct rte_pci_device *pci_dev)
1121 return rte_eth_dev_pci_generic_remove(pci_dev, eth_igbvf_dev_uninit);
1125 * virtual function driver struct
1127 static struct rte_pci_driver rte_igbvf_pmd = {
1128 .id_table = pci_id_igbvf_map,
1129 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1130 .probe = eth_igbvf_pci_probe,
1131 .remove = eth_igbvf_pci_remove,
1135 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1137 struct e1000_hw *hw =
1138 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1139 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
1140 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
1141 rctl |= E1000_RCTL_VFE;
1142 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1146 igb_check_mq_mode(struct rte_eth_dev *dev)
1148 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1149 enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
1150 uint16_t nb_rx_q = dev->data->nb_rx_queues;
1151 uint16_t nb_tx_q = dev->data->nb_rx_queues;
1153 if ((rx_mq_mode & ETH_MQ_RX_DCB_FLAG) ||
1154 tx_mq_mode == ETH_MQ_TX_DCB ||
1155 tx_mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1156 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
1159 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
1160 /* Check multi-queue mode.
1161 * To no break software we accept ETH_MQ_RX_NONE as this might
1162 * be used to turn off VLAN filter.
1165 if (rx_mq_mode == ETH_MQ_RX_NONE ||
1166 rx_mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1167 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
1168 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
1170 /* Only support one queue on VFs.
1171 * RSS together with SRIOV is not supported.
1173 PMD_INIT_LOG(ERR, "SRIOV is active,"
1174 " wrong mq_mode rx %d.",
1178 /* TX mode is not used here, so mode might be ignored.*/
1179 if (tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1180 /* SRIOV only works in VMDq enable mode */
1181 PMD_INIT_LOG(WARNING, "SRIOV is active,"
1182 " TX mode %d is not supported. "
1183 " Driver will behave as %d mode.",
1184 tx_mq_mode, ETH_MQ_TX_VMDQ_ONLY);
1187 /* check valid queue number */
1188 if ((nb_rx_q > 1) || (nb_tx_q > 1)) {
1189 PMD_INIT_LOG(ERR, "SRIOV is active,"
1190 " only support one queue on VFs.");
1194 /* To no break software that set invalid mode, only display
1195 * warning if invalid mode is used.
1197 if (rx_mq_mode != ETH_MQ_RX_NONE &&
1198 rx_mq_mode != ETH_MQ_RX_VMDQ_ONLY &&
1199 rx_mq_mode != ETH_MQ_RX_RSS) {
1200 /* RSS together with VMDq not supported*/
1201 PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
1206 if (tx_mq_mode != ETH_MQ_TX_NONE &&
1207 tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1208 PMD_INIT_LOG(WARNING, "TX mode %d is not supported."
1209 " Due to txmode is meaningless in this"
1210 " driver, just ignore.",
1218 eth_igb_configure(struct rte_eth_dev *dev)
1220 struct e1000_interrupt *intr =
1221 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1224 PMD_INIT_FUNC_TRACE();
1226 /* multipe queue mode checking */
1227 ret = igb_check_mq_mode(dev);
1229 PMD_DRV_LOG(ERR, "igb_check_mq_mode fails with %d.",
1234 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1235 PMD_INIT_FUNC_TRACE();
1241 eth_igb_start(struct rte_eth_dev *dev)
1243 struct e1000_hw *hw =
1244 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1245 struct e1000_adapter *adapter =
1246 E1000_DEV_PRIVATE(dev->data->dev_private);
1247 struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
1248 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1250 uint32_t intr_vector = 0;
1256 PMD_INIT_FUNC_TRACE();
1258 /* disable uio/vfio intr/eventfd mapping */
1259 rte_intr_disable(intr_handle);
1261 /* Power up the phy. Needed to make the link go Up */
1262 eth_igb_dev_set_link_up(dev);
1265 * Packet Buffer Allocation (PBA)
1266 * Writing PBA sets the receive portion of the buffer
1267 * the remainder is used for the transmit buffer.
1269 if (hw->mac.type == e1000_82575) {
1272 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
1273 E1000_WRITE_REG(hw, E1000_PBA, pba);
1276 /* Put the address into the Receive Address Array */
1277 e1000_rar_set(hw, hw->mac.addr, 0);
1279 /* Initialize the hardware */
1280 if (igb_hardware_init(hw)) {
1281 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
1284 adapter->stopped = 0;
1286 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1288 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1289 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1290 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
1291 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1292 E1000_WRITE_FLUSH(hw);
1294 /* configure PF module if SRIOV enabled */
1295 igb_pf_host_configure(dev);
1297 /* check and configure queue intr-vector mapping */
1298 if ((rte_intr_cap_multiple(intr_handle) ||
1299 !RTE_ETH_DEV_SRIOV(dev).active) &&
1300 dev->data->dev_conf.intr_conf.rxq != 0) {
1301 intr_vector = dev->data->nb_rx_queues;
1302 if (rte_intr_efd_enable(intr_handle, intr_vector))
1306 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1307 intr_handle->intr_vec =
1308 rte_zmalloc("intr_vec",
1309 dev->data->nb_rx_queues * sizeof(int), 0);
1310 if (intr_handle->intr_vec == NULL) {
1311 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1312 " intr_vec", dev->data->nb_rx_queues);
1317 /* confiugre msix for rx interrupt */
1318 eth_igb_configure_msix_intr(dev);
1320 /* Configure for OS presence */
1321 igb_init_manageability(hw);
1323 eth_igb_tx_init(dev);
1325 /* This can fail when allocating mbufs for descriptor rings */
1326 ret = eth_igb_rx_init(dev);
1328 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1329 igb_dev_clear_queues(dev);
1333 e1000_clear_hw_cntrs_base_generic(hw);
1336 * VLAN Offload Settings
1338 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
1339 ETH_VLAN_EXTEND_MASK;
1340 eth_igb_vlan_offload_set(dev, mask);
1342 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1343 /* Enable VLAN filter since VMDq always use VLAN filter */
1344 igb_vmdq_vlan_hw_filter_enable(dev);
1347 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
1348 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
1349 (hw->mac.type == e1000_i211)) {
1350 /* Configure EITR with the maximum possible value (0xFFFF) */
1351 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
1354 /* Setup link speed and duplex */
1355 speeds = &dev->data->dev_conf.link_speeds;
1356 if (*speeds == ETH_LINK_SPEED_AUTONEG) {
1357 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
1358 hw->mac.autoneg = 1;
1361 autoneg = (*speeds & ETH_LINK_SPEED_FIXED) == 0;
1364 hw->phy.autoneg_advertised = 0;
1366 if (*speeds & ~(ETH_LINK_SPEED_10M_HD | ETH_LINK_SPEED_10M |
1367 ETH_LINK_SPEED_100M_HD | ETH_LINK_SPEED_100M |
1368 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_FIXED)) {
1370 goto error_invalid_config;
1372 if (*speeds & ETH_LINK_SPEED_10M_HD) {
1373 hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
1376 if (*speeds & ETH_LINK_SPEED_10M) {
1377 hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
1380 if (*speeds & ETH_LINK_SPEED_100M_HD) {
1381 hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
1384 if (*speeds & ETH_LINK_SPEED_100M) {
1385 hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
1388 if (*speeds & ETH_LINK_SPEED_1G) {
1389 hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
1392 if (num_speeds == 0 || (!autoneg && (num_speeds > 1)))
1393 goto error_invalid_config;
1395 /* Set/reset the mac.autoneg based on the link speed,
1399 hw->mac.autoneg = 0;
1400 hw->mac.forced_speed_duplex =
1401 hw->phy.autoneg_advertised;
1403 hw->mac.autoneg = 1;
1407 e1000_setup_link(hw);
1409 if (rte_intr_allow_others(intr_handle)) {
1410 /* check if lsc interrupt is enabled */
1411 if (dev->data->dev_conf.intr_conf.lsc != 0)
1412 eth_igb_lsc_interrupt_setup(dev);
1414 rte_intr_callback_unregister(intr_handle,
1415 eth_igb_interrupt_handler,
1417 if (dev->data->dev_conf.intr_conf.lsc != 0)
1418 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1419 " no intr multiplex");
1422 /* check if rxq interrupt is enabled */
1423 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1424 rte_intr_dp_is_en(intr_handle))
1425 eth_igb_rxq_interrupt_setup(dev);
1427 /* enable uio/vfio intr/eventfd mapping */
1428 rte_intr_enable(intr_handle);
1430 /* resume enabled intr since hw reset */
1431 igb_intr_enable(dev);
1433 PMD_INIT_LOG(DEBUG, "<<");
1437 error_invalid_config:
1438 PMD_INIT_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
1439 dev->data->dev_conf.link_speeds, dev->data->port_id);
1440 igb_dev_clear_queues(dev);
1444 /*********************************************************************
1446 * This routine disables all traffic on the adapter by issuing a
1447 * global reset on the MAC.
1449 **********************************************************************/
1451 eth_igb_stop(struct rte_eth_dev *dev)
1453 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1454 struct e1000_filter_info *filter_info =
1455 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1456 struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
1457 struct rte_eth_link link;
1458 struct e1000_flex_filter *p_flex;
1459 struct e1000_5tuple_filter *p_5tuple, *p_5tuple_next;
1460 struct e1000_2tuple_filter *p_2tuple, *p_2tuple_next;
1461 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1463 igb_intr_disable(hw);
1465 /* disable intr eventfd mapping */
1466 rte_intr_disable(intr_handle);
1468 igb_pf_reset_hw(hw);
1469 E1000_WRITE_REG(hw, E1000_WUC, 0);
1471 /* Set bit for Go Link disconnect */
1472 if (hw->mac.type >= e1000_82580) {
1475 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1476 phpm_reg |= E1000_82580_PM_GO_LINKD;
1477 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1480 /* Power down the phy. Needed to make the link go Down */
1481 eth_igb_dev_set_link_down(dev);
1483 igb_dev_clear_queues(dev);
1485 /* clear the recorded link status */
1486 memset(&link, 0, sizeof(link));
1487 rte_igb_dev_atomic_write_link_status(dev, &link);
1489 /* Remove all flex filters of the device */
1490 while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
1491 TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
1494 filter_info->flex_mask = 0;
1496 /* Remove all ntuple filters of the device */
1497 for (p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list);
1498 p_5tuple != NULL; p_5tuple = p_5tuple_next) {
1499 p_5tuple_next = TAILQ_NEXT(p_5tuple, entries);
1500 TAILQ_REMOVE(&filter_info->fivetuple_list,
1504 filter_info->fivetuple_mask = 0;
1505 for (p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list);
1506 p_2tuple != NULL; p_2tuple = p_2tuple_next) {
1507 p_2tuple_next = TAILQ_NEXT(p_2tuple, entries);
1508 TAILQ_REMOVE(&filter_info->twotuple_list,
1512 filter_info->twotuple_mask = 0;
1514 if (!rte_intr_allow_others(intr_handle))
1515 /* resume to the default handler */
1516 rte_intr_callback_register(intr_handle,
1517 eth_igb_interrupt_handler,
1520 /* Clean datapath event and queue/vec mapping */
1521 rte_intr_efd_disable(intr_handle);
1522 if (intr_handle->intr_vec != NULL) {
1523 rte_free(intr_handle->intr_vec);
1524 intr_handle->intr_vec = NULL;
1529 eth_igb_dev_set_link_up(struct rte_eth_dev *dev)
1531 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1533 if (hw->phy.media_type == e1000_media_type_copper)
1534 e1000_power_up_phy(hw);
1536 e1000_power_up_fiber_serdes_link(hw);
1542 eth_igb_dev_set_link_down(struct rte_eth_dev *dev)
1544 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1546 if (hw->phy.media_type == e1000_media_type_copper)
1547 e1000_power_down_phy(hw);
1549 e1000_shutdown_fiber_serdes_link(hw);
1555 eth_igb_close(struct rte_eth_dev *dev)
1557 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1558 struct e1000_adapter *adapter =
1559 E1000_DEV_PRIVATE(dev->data->dev_private);
1560 struct rte_eth_link link;
1561 struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
1562 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1565 adapter->stopped = 1;
1567 e1000_phy_hw_reset(hw);
1568 igb_release_manageability(hw);
1569 igb_hw_control_release(hw);
1571 /* Clear bit for Go Link disconnect */
1572 if (hw->mac.type >= e1000_82580) {
1575 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1576 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1577 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1580 igb_dev_free_queues(dev);
1582 if (intr_handle->intr_vec) {
1583 rte_free(intr_handle->intr_vec);
1584 intr_handle->intr_vec = NULL;
1587 memset(&link, 0, sizeof(link));
1588 rte_igb_dev_atomic_write_link_status(dev, &link);
1592 igb_get_rx_buffer_size(struct e1000_hw *hw)
1594 uint32_t rx_buf_size;
1595 if (hw->mac.type == e1000_82576) {
1596 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1597 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1598 /* PBS needs to be translated according to a lookup table */
1599 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1600 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1601 rx_buf_size = (rx_buf_size << 10);
1602 } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1603 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1605 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1611 /*********************************************************************
1613 * Initialize the hardware
1615 **********************************************************************/
1617 igb_hardware_init(struct e1000_hw *hw)
1619 uint32_t rx_buf_size;
1622 /* Let the firmware know the OS is in control */
1623 igb_hw_control_acquire(hw);
1626 * These parameters control the automatic generation (Tx) and
1627 * response (Rx) to Ethernet PAUSE frames.
1628 * - High water mark should allow for at least two standard size (1518)
1629 * frames to be received after sending an XOFF.
1630 * - Low water mark works best when it is very near the high water mark.
1631 * This allows the receiver to restart by sending XON when it has
1632 * drained a bit. Here we use an arbitrary value of 1500 which will
1633 * restart after one full frame is pulled from the buffer. There
1634 * could be several smaller frames in the buffer and if so they will
1635 * not trigger the XON until their total number reduces the buffer
1637 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1639 rx_buf_size = igb_get_rx_buffer_size(hw);
1641 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
1642 hw->fc.low_water = hw->fc.high_water - 1500;
1643 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1644 hw->fc.send_xon = 1;
1646 /* Set Flow control, use the tunable location if sane */
1647 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1648 hw->fc.requested_mode = igb_fc_setting;
1650 hw->fc.requested_mode = e1000_fc_none;
1652 /* Issue a global reset */
1653 igb_pf_reset_hw(hw);
1654 E1000_WRITE_REG(hw, E1000_WUC, 0);
1656 diag = e1000_init_hw(hw);
1660 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1661 e1000_get_phy_info(hw);
1662 e1000_check_for_link(hw);
1667 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1669 igb_read_stats_registers(struct e1000_hw *hw, struct e1000_hw_stats *stats)
1673 uint64_t old_gprc = stats->gprc;
1674 uint64_t old_gptc = stats->gptc;
1675 uint64_t old_tpr = stats->tpr;
1676 uint64_t old_tpt = stats->tpt;
1677 uint64_t old_rpthc = stats->rpthc;
1678 uint64_t old_hgptc = stats->hgptc;
1680 if(hw->phy.media_type == e1000_media_type_copper ||
1681 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1683 E1000_READ_REG(hw,E1000_SYMERRS);
1684 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1687 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1688 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1689 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1690 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1692 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1693 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1694 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1695 stats->dc += E1000_READ_REG(hw, E1000_DC);
1696 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1697 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1698 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1700 ** For watchdog management we need to know if we have been
1701 ** paused during the last interval, so capture that here.
1703 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1704 stats->xoffrxc += pause_frames;
1705 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1706 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1707 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1708 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1709 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1710 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1711 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1712 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1713 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1714 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1715 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1716 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1718 /* For the 64-bit byte counters the low dword must be read first. */
1719 /* Both registers clear on the read of the high dword */
1721 /* Workaround CRC bytes included in size, take away 4 bytes/packet */
1722 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1723 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1724 stats->gorc -= (stats->gprc - old_gprc) * ETHER_CRC_LEN;
1725 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1726 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1727 stats->gotc -= (stats->gptc - old_gptc) * ETHER_CRC_LEN;
1729 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1730 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1731 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1732 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1733 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1735 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1736 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1738 stats->tor += E1000_READ_REG(hw, E1000_TORL);
1739 stats->tor += ((uint64_t)E1000_READ_REG(hw, E1000_TORH) << 32);
1740 stats->tor -= (stats->tpr - old_tpr) * ETHER_CRC_LEN;
1741 stats->tot += E1000_READ_REG(hw, E1000_TOTL);
1742 stats->tot += ((uint64_t)E1000_READ_REG(hw, E1000_TOTH) << 32);
1743 stats->tot -= (stats->tpt - old_tpt) * ETHER_CRC_LEN;
1745 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1746 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1747 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1748 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1749 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1750 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1751 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1752 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1754 /* Interrupt Counts */
1756 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1757 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1758 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1759 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1760 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1761 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1762 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1763 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1764 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1766 /* Host to Card Statistics */
1768 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1769 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1770 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1771 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1772 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1773 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1774 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1775 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1776 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1777 stats->hgorc -= (stats->rpthc - old_rpthc) * ETHER_CRC_LEN;
1778 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1779 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1780 stats->hgotc -= (stats->hgptc - old_hgptc) * ETHER_CRC_LEN;
1781 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1782 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1783 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1785 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1786 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1787 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1788 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1789 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1790 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1794 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1796 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1797 struct e1000_hw_stats *stats =
1798 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1800 igb_read_stats_registers(hw, stats);
1802 if (rte_stats == NULL)
1806 rte_stats->imissed = stats->mpc;
1807 rte_stats->ierrors = stats->crcerrs +
1808 stats->rlec + stats->ruc + stats->roc +
1809 stats->rxerrc + stats->algnerrc + stats->cexterr;
1812 rte_stats->oerrors = stats->ecol + stats->latecol;
1814 rte_stats->ipackets = stats->gprc;
1815 rte_stats->opackets = stats->gptc;
1816 rte_stats->ibytes = stats->gorc;
1817 rte_stats->obytes = stats->gotc;
1821 eth_igb_stats_reset(struct rte_eth_dev *dev)
1823 struct e1000_hw_stats *hw_stats =
1824 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1826 /* HW registers are cleared on read */
1827 eth_igb_stats_get(dev, NULL);
1829 /* Reset software totals */
1830 memset(hw_stats, 0, sizeof(*hw_stats));
1834 eth_igb_xstats_reset(struct rte_eth_dev *dev)
1836 struct e1000_hw_stats *stats =
1837 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1839 /* HW registers are cleared on read */
1840 eth_igb_xstats_get(dev, NULL, IGB_NB_XSTATS);
1842 /* Reset software totals */
1843 memset(stats, 0, sizeof(*stats));
1846 static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1847 struct rte_eth_xstat_name *xstats_names,
1848 __rte_unused unsigned limit)
1852 if (xstats_names == NULL)
1853 return IGB_NB_XSTATS;
1855 /* Note: limit checked in rte_eth_xstats_names() */
1857 for (i = 0; i < IGB_NB_XSTATS; i++) {
1858 snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
1859 "%s", rte_igb_stats_strings[i].name);
1862 return IGB_NB_XSTATS;
1866 eth_igb_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1869 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1870 struct e1000_hw_stats *hw_stats =
1871 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1874 if (n < IGB_NB_XSTATS)
1875 return IGB_NB_XSTATS;
1877 igb_read_stats_registers(hw, hw_stats);
1879 /* If this is a reset xstats is NULL, and we have cleared the
1880 * registers by reading them.
1885 /* Extended stats */
1886 for (i = 0; i < IGB_NB_XSTATS; i++) {
1888 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
1889 rte_igb_stats_strings[i].offset);
1892 return IGB_NB_XSTATS;
1896 igbvf_read_stats_registers(struct e1000_hw *hw, struct e1000_vf_stats *hw_stats)
1898 /* Good Rx packets, include VF loopback */
1899 UPDATE_VF_STAT(E1000_VFGPRC,
1900 hw_stats->last_gprc, hw_stats->gprc);
1902 /* Good Rx octets, include VF loopback */
1903 UPDATE_VF_STAT(E1000_VFGORC,
1904 hw_stats->last_gorc, hw_stats->gorc);
1906 /* Good Tx packets, include VF loopback */
1907 UPDATE_VF_STAT(E1000_VFGPTC,
1908 hw_stats->last_gptc, hw_stats->gptc);
1910 /* Good Tx octets, include VF loopback */
1911 UPDATE_VF_STAT(E1000_VFGOTC,
1912 hw_stats->last_gotc, hw_stats->gotc);
1914 /* Rx Multicst packets */
1915 UPDATE_VF_STAT(E1000_VFMPRC,
1916 hw_stats->last_mprc, hw_stats->mprc);
1918 /* Good Rx loopback packets */
1919 UPDATE_VF_STAT(E1000_VFGPRLBC,
1920 hw_stats->last_gprlbc, hw_stats->gprlbc);
1922 /* Good Rx loopback octets */
1923 UPDATE_VF_STAT(E1000_VFGORLBC,
1924 hw_stats->last_gorlbc, hw_stats->gorlbc);
1926 /* Good Tx loopback packets */
1927 UPDATE_VF_STAT(E1000_VFGPTLBC,
1928 hw_stats->last_gptlbc, hw_stats->gptlbc);
1930 /* Good Tx loopback octets */
1931 UPDATE_VF_STAT(E1000_VFGOTLBC,
1932 hw_stats->last_gotlbc, hw_stats->gotlbc);
1935 static int eth_igbvf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1936 struct rte_eth_xstat_name *xstats_names,
1937 __rte_unused unsigned limit)
1941 if (xstats_names != NULL)
1942 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
1943 snprintf(xstats_names[i].name,
1944 sizeof(xstats_names[i].name), "%s",
1945 rte_igbvf_stats_strings[i].name);
1947 return IGBVF_NB_XSTATS;
1951 eth_igbvf_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1954 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1955 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
1956 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1959 if (n < IGBVF_NB_XSTATS)
1960 return IGBVF_NB_XSTATS;
1962 igbvf_read_stats_registers(hw, hw_stats);
1967 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
1969 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
1970 rte_igbvf_stats_strings[i].offset);
1973 return IGBVF_NB_XSTATS;
1977 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1979 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1980 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
1981 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1983 igbvf_read_stats_registers(hw, hw_stats);
1985 if (rte_stats == NULL)
1988 rte_stats->ipackets = hw_stats->gprc;
1989 rte_stats->ibytes = hw_stats->gorc;
1990 rte_stats->opackets = hw_stats->gptc;
1991 rte_stats->obytes = hw_stats->gotc;
1995 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
1997 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
1998 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2000 /* Sync HW register to the last stats */
2001 eth_igbvf_stats_get(dev, NULL);
2003 /* reset HW current stats*/
2004 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
2005 offsetof(struct e1000_vf_stats, gprc));
2009 eth_igb_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
2012 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2013 struct e1000_fw_version fw;
2016 e1000_get_fw_version(hw, &fw);
2018 switch (hw->mac.type) {
2021 if (!(e1000_get_flash_presence_i210(hw))) {
2022 ret = snprintf(fw_version, fw_size,
2024 fw.invm_major, fw.invm_minor,
2030 /* if option rom is valid, display its version too */
2032 ret = snprintf(fw_version, fw_size,
2033 "%d.%d, 0x%08x, %d.%d.%d",
2034 fw.eep_major, fw.eep_minor, fw.etrack_id,
2035 fw.or_major, fw.or_build, fw.or_patch);
2038 if (fw.etrack_id != 0X0000) {
2039 ret = snprintf(fw_version, fw_size,
2041 fw.eep_major, fw.eep_minor,
2044 ret = snprintf(fw_version, fw_size,
2046 fw.eep_major, fw.eep_minor,
2053 ret += 1; /* add the size of '\0' */
2054 if (fw_size < (u32)ret)
2061 eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2063 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2065 dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
2066 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2067 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2068 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2069 dev_info->rx_offload_capa =
2070 DEV_RX_OFFLOAD_VLAN_STRIP |
2071 DEV_RX_OFFLOAD_IPV4_CKSUM |
2072 DEV_RX_OFFLOAD_UDP_CKSUM |
2073 DEV_RX_OFFLOAD_TCP_CKSUM;
2074 dev_info->tx_offload_capa =
2075 DEV_TX_OFFLOAD_VLAN_INSERT |
2076 DEV_TX_OFFLOAD_IPV4_CKSUM |
2077 DEV_TX_OFFLOAD_UDP_CKSUM |
2078 DEV_TX_OFFLOAD_TCP_CKSUM |
2079 DEV_TX_OFFLOAD_SCTP_CKSUM |
2080 DEV_TX_OFFLOAD_TCP_TSO;
2082 switch (hw->mac.type) {
2084 dev_info->max_rx_queues = 4;
2085 dev_info->max_tx_queues = 4;
2086 dev_info->max_vmdq_pools = 0;
2090 dev_info->max_rx_queues = 16;
2091 dev_info->max_tx_queues = 16;
2092 dev_info->max_vmdq_pools = ETH_8_POOLS;
2093 dev_info->vmdq_queue_num = 16;
2097 dev_info->max_rx_queues = 8;
2098 dev_info->max_tx_queues = 8;
2099 dev_info->max_vmdq_pools = ETH_8_POOLS;
2100 dev_info->vmdq_queue_num = 8;
2104 dev_info->max_rx_queues = 8;
2105 dev_info->max_tx_queues = 8;
2106 dev_info->max_vmdq_pools = ETH_8_POOLS;
2107 dev_info->vmdq_queue_num = 8;
2111 dev_info->max_rx_queues = 8;
2112 dev_info->max_tx_queues = 8;
2116 dev_info->max_rx_queues = 4;
2117 dev_info->max_tx_queues = 4;
2118 dev_info->max_vmdq_pools = 0;
2122 dev_info->max_rx_queues = 2;
2123 dev_info->max_tx_queues = 2;
2124 dev_info->max_vmdq_pools = 0;
2128 /* Should not happen */
2131 dev_info->hash_key_size = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
2132 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
2133 dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
2135 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2137 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2138 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2139 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2141 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2145 dev_info->default_txconf = (struct rte_eth_txconf) {
2147 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2148 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2149 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2154 dev_info->rx_desc_lim = rx_desc_lim;
2155 dev_info->tx_desc_lim = tx_desc_lim;
2157 dev_info->speed_capa = ETH_LINK_SPEED_10M_HD | ETH_LINK_SPEED_10M |
2158 ETH_LINK_SPEED_100M_HD | ETH_LINK_SPEED_100M |
2162 static const uint32_t *
2163 eth_igb_supported_ptypes_get(struct rte_eth_dev *dev)
2165 static const uint32_t ptypes[] = {
2166 /* refers to igb_rxd_pkt_info_to_pkt_type() */
2169 RTE_PTYPE_L3_IPV4_EXT,
2171 RTE_PTYPE_L3_IPV6_EXT,
2175 RTE_PTYPE_TUNNEL_IP,
2176 RTE_PTYPE_INNER_L3_IPV6,
2177 RTE_PTYPE_INNER_L3_IPV6_EXT,
2178 RTE_PTYPE_INNER_L4_TCP,
2179 RTE_PTYPE_INNER_L4_UDP,
2183 if (dev->rx_pkt_burst == eth_igb_recv_pkts ||
2184 dev->rx_pkt_burst == eth_igb_recv_scattered_pkts)
2190 eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2192 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2194 dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
2195 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2196 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2197 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2198 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
2199 DEV_RX_OFFLOAD_IPV4_CKSUM |
2200 DEV_RX_OFFLOAD_UDP_CKSUM |
2201 DEV_RX_OFFLOAD_TCP_CKSUM;
2202 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
2203 DEV_TX_OFFLOAD_IPV4_CKSUM |
2204 DEV_TX_OFFLOAD_UDP_CKSUM |
2205 DEV_TX_OFFLOAD_TCP_CKSUM |
2206 DEV_TX_OFFLOAD_SCTP_CKSUM |
2207 DEV_TX_OFFLOAD_TCP_TSO;
2208 switch (hw->mac.type) {
2210 dev_info->max_rx_queues = 2;
2211 dev_info->max_tx_queues = 2;
2213 case e1000_vfadapt_i350:
2214 dev_info->max_rx_queues = 1;
2215 dev_info->max_tx_queues = 1;
2218 /* Should not happen */
2222 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2224 .pthresh = IGB_DEFAULT_RX_PTHRESH,
2225 .hthresh = IGB_DEFAULT_RX_HTHRESH,
2226 .wthresh = IGB_DEFAULT_RX_WTHRESH,
2228 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2232 dev_info->default_txconf = (struct rte_eth_txconf) {
2234 .pthresh = IGB_DEFAULT_TX_PTHRESH,
2235 .hthresh = IGB_DEFAULT_TX_HTHRESH,
2236 .wthresh = IGB_DEFAULT_TX_WTHRESH,
2241 dev_info->rx_desc_lim = rx_desc_lim;
2242 dev_info->tx_desc_lim = tx_desc_lim;
2245 /* return 0 means link status changed, -1 means not changed */
2247 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2249 struct e1000_hw *hw =
2250 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2251 struct rte_eth_link link, old;
2252 int link_check, count;
2255 hw->mac.get_link_status = 1;
2257 /* possible wait-to-complete in up to 9 seconds */
2258 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
2259 /* Read the real link status */
2260 switch (hw->phy.media_type) {
2261 case e1000_media_type_copper:
2262 /* Do the work to read phy */
2263 e1000_check_for_link(hw);
2264 link_check = !hw->mac.get_link_status;
2267 case e1000_media_type_fiber:
2268 e1000_check_for_link(hw);
2269 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
2273 case e1000_media_type_internal_serdes:
2274 e1000_check_for_link(hw);
2275 link_check = hw->mac.serdes_has_link;
2278 /* VF device is type_unknown */
2279 case e1000_media_type_unknown:
2280 eth_igbvf_link_update(hw);
2281 link_check = !hw->mac.get_link_status;
2287 if (link_check || wait_to_complete == 0)
2289 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
2291 memset(&link, 0, sizeof(link));
2292 rte_igb_dev_atomic_read_link_status(dev, &link);
2295 /* Now we check if a transition has happened */
2297 uint16_t duplex, speed;
2298 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
2299 link.link_duplex = (duplex == FULL_DUPLEX) ?
2300 ETH_LINK_FULL_DUPLEX :
2301 ETH_LINK_HALF_DUPLEX;
2302 link.link_speed = speed;
2303 link.link_status = ETH_LINK_UP;
2304 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2305 ETH_LINK_SPEED_FIXED);
2306 } else if (!link_check) {
2307 link.link_speed = 0;
2308 link.link_duplex = ETH_LINK_HALF_DUPLEX;
2309 link.link_status = ETH_LINK_DOWN;
2310 link.link_autoneg = ETH_LINK_SPEED_FIXED;
2312 rte_igb_dev_atomic_write_link_status(dev, &link);
2315 if (old.link_status == link.link_status)
2323 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
2324 * For ASF and Pass Through versions of f/w this means
2325 * that the driver is loaded.
2328 igb_hw_control_acquire(struct e1000_hw *hw)
2332 /* Let firmware know the driver has taken over */
2333 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2334 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2338 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
2339 * For ASF and Pass Through versions of f/w this means that the
2340 * driver is no longer loaded.
2343 igb_hw_control_release(struct e1000_hw *hw)
2347 /* Let firmware taken over control of h/w */
2348 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2349 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
2350 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2354 * Bit of a misnomer, what this really means is
2355 * to enable OS management of the system... aka
2356 * to disable special hardware management features.
2359 igb_init_manageability(struct e1000_hw *hw)
2361 if (e1000_enable_mng_pass_thru(hw)) {
2362 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
2363 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2365 /* disable hardware interception of ARP */
2366 manc &= ~(E1000_MANC_ARP_EN);
2368 /* enable receiving management packets to the host */
2369 manc |= E1000_MANC_EN_MNG2HOST;
2370 manc2h |= 1 << 5; /* Mng Port 623 */
2371 manc2h |= 1 << 6; /* Mng Port 664 */
2372 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
2373 E1000_WRITE_REG(hw, E1000_MANC, manc);
2378 igb_release_manageability(struct e1000_hw *hw)
2380 if (e1000_enable_mng_pass_thru(hw)) {
2381 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2383 manc |= E1000_MANC_ARP_EN;
2384 manc &= ~E1000_MANC_EN_MNG2HOST;
2386 E1000_WRITE_REG(hw, E1000_MANC, manc);
2391 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
2393 struct e1000_hw *hw =
2394 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2397 rctl = E1000_READ_REG(hw, E1000_RCTL);
2398 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2399 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2403 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
2405 struct e1000_hw *hw =
2406 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2409 rctl = E1000_READ_REG(hw, E1000_RCTL);
2410 rctl &= (~E1000_RCTL_UPE);
2411 if (dev->data->all_multicast == 1)
2412 rctl |= E1000_RCTL_MPE;
2414 rctl &= (~E1000_RCTL_MPE);
2415 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2419 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
2421 struct e1000_hw *hw =
2422 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2425 rctl = E1000_READ_REG(hw, E1000_RCTL);
2426 rctl |= E1000_RCTL_MPE;
2427 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2431 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
2433 struct e1000_hw *hw =
2434 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2437 if (dev->data->promiscuous == 1)
2438 return; /* must remain in all_multicast mode */
2439 rctl = E1000_READ_REG(hw, E1000_RCTL);
2440 rctl &= (~E1000_RCTL_MPE);
2441 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2445 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2447 struct e1000_hw *hw =
2448 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2449 struct e1000_vfta * shadow_vfta =
2450 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2455 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
2456 E1000_VFTA_ENTRY_MASK);
2457 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
2458 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
2463 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
2465 /* update local VFTA copy */
2466 shadow_vfta->vfta[vid_idx] = vfta;
2472 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
2473 enum rte_vlan_type vlan_type,
2476 struct e1000_hw *hw =
2477 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2480 qinq = E1000_READ_REG(hw, E1000_CTRL_EXT);
2481 qinq &= E1000_CTRL_EXT_EXT_VLAN;
2483 /* only outer TPID of double VLAN can be configured*/
2484 if (qinq && vlan_type == ETH_VLAN_TYPE_OUTER) {
2485 reg = E1000_READ_REG(hw, E1000_VET);
2486 reg = (reg & (~E1000_VET_VET_EXT)) |
2487 ((uint32_t)tpid << E1000_VET_VET_EXT_SHIFT);
2488 E1000_WRITE_REG(hw, E1000_VET, reg);
2493 /* all other TPID values are read-only*/
2494 PMD_DRV_LOG(ERR, "Not supported");
2500 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
2502 struct e1000_hw *hw =
2503 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2506 /* Filter Table Disable */
2507 reg = E1000_READ_REG(hw, E1000_RCTL);
2508 reg &= ~E1000_RCTL_CFIEN;
2509 reg &= ~E1000_RCTL_VFE;
2510 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2514 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2516 struct e1000_hw *hw =
2517 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2518 struct e1000_vfta * shadow_vfta =
2519 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2523 /* Filter Table Enable, CFI not used for packet acceptance */
2524 reg = E1000_READ_REG(hw, E1000_RCTL);
2525 reg &= ~E1000_RCTL_CFIEN;
2526 reg |= E1000_RCTL_VFE;
2527 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2529 /* restore VFTA table */
2530 for (i = 0; i < IGB_VFTA_SIZE; i++)
2531 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
2535 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
2537 struct e1000_hw *hw =
2538 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2541 /* VLAN Mode Disable */
2542 reg = E1000_READ_REG(hw, E1000_CTRL);
2543 reg &= ~E1000_CTRL_VME;
2544 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2548 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
2550 struct e1000_hw *hw =
2551 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2554 /* VLAN Mode Enable */
2555 reg = E1000_READ_REG(hw, E1000_CTRL);
2556 reg |= E1000_CTRL_VME;
2557 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2561 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2563 struct e1000_hw *hw =
2564 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2567 /* CTRL_EXT: Extended VLAN */
2568 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2569 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
2570 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2572 /* Update maximum packet length */
2573 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
2574 E1000_WRITE_REG(hw, E1000_RLPML,
2575 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2580 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2582 struct e1000_hw *hw =
2583 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2586 /* CTRL_EXT: Extended VLAN */
2587 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2588 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
2589 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2591 /* Update maximum packet length */
2592 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
2593 E1000_WRITE_REG(hw, E1000_RLPML,
2594 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2599 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2601 if(mask & ETH_VLAN_STRIP_MASK){
2602 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2603 igb_vlan_hw_strip_enable(dev);
2605 igb_vlan_hw_strip_disable(dev);
2608 if(mask & ETH_VLAN_FILTER_MASK){
2609 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2610 igb_vlan_hw_filter_enable(dev);
2612 igb_vlan_hw_filter_disable(dev);
2615 if(mask & ETH_VLAN_EXTEND_MASK){
2616 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2617 igb_vlan_hw_extend_enable(dev);
2619 igb_vlan_hw_extend_disable(dev);
2625 * It enables the interrupt mask and then enable the interrupt.
2628 * Pointer to struct rte_eth_dev.
2631 * - On success, zero.
2632 * - On failure, a negative value.
2635 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev)
2637 struct e1000_interrupt *intr =
2638 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2640 intr->mask |= E1000_ICR_LSC;
2645 /* It clears the interrupt causes and enables the interrupt.
2646 * It will be called once only during nic initialized.
2649 * Pointer to struct rte_eth_dev.
2652 * - On success, zero.
2653 * - On failure, a negative value.
2655 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev)
2657 uint32_t mask, regval;
2658 struct e1000_hw *hw =
2659 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2660 struct rte_eth_dev_info dev_info;
2662 memset(&dev_info, 0, sizeof(dev_info));
2663 eth_igb_infos_get(dev, &dev_info);
2665 mask = 0xFFFFFFFF >> (32 - dev_info.max_rx_queues);
2666 regval = E1000_READ_REG(hw, E1000_EIMS);
2667 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
2673 * It reads ICR and gets interrupt causes, check it and set a bit flag
2674 * to update link status.
2677 * Pointer to struct rte_eth_dev.
2680 * - On success, zero.
2681 * - On failure, a negative value.
2684 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
2687 struct e1000_hw *hw =
2688 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2689 struct e1000_interrupt *intr =
2690 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2692 igb_intr_disable(hw);
2694 /* read-on-clear nic registers here */
2695 icr = E1000_READ_REG(hw, E1000_ICR);
2698 if (icr & E1000_ICR_LSC) {
2699 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
2702 if (icr & E1000_ICR_VMMB)
2703 intr->flags |= E1000_FLAG_MAILBOX;
2709 * It executes link_update after knowing an interrupt is prsent.
2712 * Pointer to struct rte_eth_dev.
2715 * - On success, zero.
2716 * - On failure, a negative value.
2719 eth_igb_interrupt_action(struct rte_eth_dev *dev,
2720 struct rte_intr_handle *intr_handle)
2722 struct e1000_hw *hw =
2723 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2724 struct e1000_interrupt *intr =
2725 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2726 struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
2727 uint32_t tctl, rctl;
2728 struct rte_eth_link link;
2731 if (intr->flags & E1000_FLAG_MAILBOX) {
2732 igb_pf_mbx_process(dev);
2733 intr->flags &= ~E1000_FLAG_MAILBOX;
2736 igb_intr_enable(dev);
2737 rte_intr_enable(intr_handle);
2739 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
2740 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
2742 /* set get_link_status to check register later */
2743 hw->mac.get_link_status = 1;
2744 ret = eth_igb_link_update(dev, 0);
2746 /* check if link has changed */
2750 memset(&link, 0, sizeof(link));
2751 rte_igb_dev_atomic_read_link_status(dev, &link);
2752 if (link.link_status) {
2754 " Port %d: Link Up - speed %u Mbps - %s",
2756 (unsigned)link.link_speed,
2757 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2758 "full-duplex" : "half-duplex");
2760 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2761 dev->data->port_id);
2764 PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
2765 pci_dev->addr.domain,
2767 pci_dev->addr.devid,
2768 pci_dev->addr.function);
2769 tctl = E1000_READ_REG(hw, E1000_TCTL);
2770 rctl = E1000_READ_REG(hw, E1000_RCTL);
2771 if (link.link_status) {
2773 tctl |= E1000_TCTL_EN;
2774 rctl |= E1000_RCTL_EN;
2777 tctl &= ~E1000_TCTL_EN;
2778 rctl &= ~E1000_RCTL_EN;
2780 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
2781 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2782 E1000_WRITE_FLUSH(hw);
2783 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
2790 * Interrupt handler which shall be registered at first.
2793 * Pointer to interrupt handle.
2795 * The address of parameter (struct rte_eth_dev *) regsitered before.
2801 eth_igb_interrupt_handler(void *param)
2803 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2805 eth_igb_interrupt_get_status(dev);
2806 eth_igb_interrupt_action(dev, dev->intr_handle);
2810 eth_igbvf_interrupt_get_status(struct rte_eth_dev *dev)
2813 struct e1000_hw *hw =
2814 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2815 struct e1000_interrupt *intr =
2816 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2818 igbvf_intr_disable(hw);
2820 /* read-on-clear nic registers here */
2821 eicr = E1000_READ_REG(hw, E1000_EICR);
2824 if (eicr == E1000_VTIVAR_MISC_MAILBOX)
2825 intr->flags |= E1000_FLAG_MAILBOX;
2830 void igbvf_mbx_process(struct rte_eth_dev *dev)
2832 struct e1000_hw *hw =
2833 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2834 struct e1000_mbx_info *mbx = &hw->mbx;
2837 if (mbx->ops.read(hw, &in_msg, 1, 0))
2840 /* PF reset VF event */
2841 if (in_msg == E1000_PF_CONTROL_MSG)
2842 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET, NULL);
2846 eth_igbvf_interrupt_action(struct rte_eth_dev *dev, struct rte_intr_handle *intr_handle)
2848 struct e1000_interrupt *intr =
2849 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2851 if (intr->flags & E1000_FLAG_MAILBOX) {
2852 igbvf_mbx_process(dev);
2853 intr->flags &= ~E1000_FLAG_MAILBOX;
2856 igbvf_intr_enable(dev);
2857 rte_intr_enable(intr_handle);
2863 eth_igbvf_interrupt_handler(void *param)
2865 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2867 eth_igbvf_interrupt_get_status(dev);
2868 eth_igbvf_interrupt_action(dev, dev->intr_handle);
2872 eth_igb_led_on(struct rte_eth_dev *dev)
2874 struct e1000_hw *hw;
2876 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2877 return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
2881 eth_igb_led_off(struct rte_eth_dev *dev)
2883 struct e1000_hw *hw;
2885 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2886 return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
2890 eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2892 struct e1000_hw *hw;
2897 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2898 fc_conf->pause_time = hw->fc.pause_time;
2899 fc_conf->high_water = hw->fc.high_water;
2900 fc_conf->low_water = hw->fc.low_water;
2901 fc_conf->send_xon = hw->fc.send_xon;
2902 fc_conf->autoneg = hw->mac.autoneg;
2905 * Return rx_pause and tx_pause status according to actual setting of
2906 * the TFCE and RFCE bits in the CTRL register.
2908 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2909 if (ctrl & E1000_CTRL_TFCE)
2914 if (ctrl & E1000_CTRL_RFCE)
2919 if (rx_pause && tx_pause)
2920 fc_conf->mode = RTE_FC_FULL;
2922 fc_conf->mode = RTE_FC_RX_PAUSE;
2924 fc_conf->mode = RTE_FC_TX_PAUSE;
2926 fc_conf->mode = RTE_FC_NONE;
2932 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2934 struct e1000_hw *hw;
2936 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
2942 uint32_t rx_buf_size;
2943 uint32_t max_high_water;
2946 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2947 if (fc_conf->autoneg != hw->mac.autoneg)
2949 rx_buf_size = igb_get_rx_buffer_size(hw);
2950 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2952 /* At least reserve one Ethernet frame for watermark */
2953 max_high_water = rx_buf_size - ETHER_MAX_LEN;
2954 if ((fc_conf->high_water > max_high_water) ||
2955 (fc_conf->high_water < fc_conf->low_water)) {
2956 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
2957 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
2961 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
2962 hw->fc.pause_time = fc_conf->pause_time;
2963 hw->fc.high_water = fc_conf->high_water;
2964 hw->fc.low_water = fc_conf->low_water;
2965 hw->fc.send_xon = fc_conf->send_xon;
2967 err = e1000_setup_link_generic(hw);
2968 if (err == E1000_SUCCESS) {
2970 /* check if we want to forward MAC frames - driver doesn't have native
2971 * capability to do that, so we'll write the registers ourselves */
2973 rctl = E1000_READ_REG(hw, E1000_RCTL);
2975 /* set or clear MFLCN.PMCF bit depending on configuration */
2976 if (fc_conf->mac_ctrl_frame_fwd != 0)
2977 rctl |= E1000_RCTL_PMCF;
2979 rctl &= ~E1000_RCTL_PMCF;
2981 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2982 E1000_WRITE_FLUSH(hw);
2987 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
2991 #define E1000_RAH_POOLSEL_SHIFT (18)
2993 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
2994 uint32_t index, __rte_unused uint32_t pool)
2996 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2999 e1000_rar_set(hw, mac_addr->addr_bytes, index);
3000 rah = E1000_READ_REG(hw, E1000_RAH(index));
3001 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
3002 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
3006 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
3008 uint8_t addr[ETHER_ADDR_LEN];
3009 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3011 memset(addr, 0, sizeof(addr));
3013 e1000_rar_set(hw, addr, index);
3017 eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
3018 struct ether_addr *addr)
3020 eth_igb_rar_clear(dev, 0);
3022 eth_igb_rar_set(dev, (void *)addr, 0, 0);
3025 * Virtual Function operations
3028 igbvf_intr_disable(struct e1000_hw *hw)
3030 PMD_INIT_FUNC_TRACE();
3032 /* Clear interrupt mask to stop from interrupts being generated */
3033 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
3035 E1000_WRITE_FLUSH(hw);
3039 igbvf_stop_adapter(struct rte_eth_dev *dev)
3043 struct rte_eth_dev_info dev_info;
3044 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3046 memset(&dev_info, 0, sizeof(dev_info));
3047 eth_igbvf_infos_get(dev, &dev_info);
3049 /* Clear interrupt mask to stop from interrupts being generated */
3050 igbvf_intr_disable(hw);
3052 /* Clear any pending interrupts, flush previous writes */
3053 E1000_READ_REG(hw, E1000_EICR);
3055 /* Disable the transmit unit. Each queue must be disabled. */
3056 for (i = 0; i < dev_info.max_tx_queues; i++)
3057 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
3059 /* Disable the receive unit by stopping each queue */
3060 for (i = 0; i < dev_info.max_rx_queues; i++) {
3061 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
3062 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
3063 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
3064 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
3068 /* flush all queues disables */
3069 E1000_WRITE_FLUSH(hw);
3073 static int eth_igbvf_link_update(struct e1000_hw *hw)
3075 struct e1000_mbx_info *mbx = &hw->mbx;
3076 struct e1000_mac_info *mac = &hw->mac;
3077 int ret_val = E1000_SUCCESS;
3079 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
3082 * We only want to run this if there has been a rst asserted.
3083 * in this case that could mean a link change, device reset,
3084 * or a virtual function reset
3087 /* If we were hit with a reset or timeout drop the link */
3088 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
3089 mac->get_link_status = TRUE;
3091 if (!mac->get_link_status)
3094 /* if link status is down no point in checking to see if pf is up */
3095 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
3098 /* if we passed all the tests above then the link is up and we no
3099 * longer need to check for link */
3100 mac->get_link_status = FALSE;
3108 igbvf_dev_configure(struct rte_eth_dev *dev)
3110 struct rte_eth_conf* conf = &dev->data->dev_conf;
3112 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
3113 dev->data->port_id);
3116 * VF has no ability to enable/disable HW CRC
3117 * Keep the persistent behavior the same as Host PF
3119 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
3120 if (!conf->rxmode.hw_strip_crc) {
3121 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
3122 conf->rxmode.hw_strip_crc = 1;
3125 if (conf->rxmode.hw_strip_crc) {
3126 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
3127 conf->rxmode.hw_strip_crc = 0;
3135 igbvf_dev_start(struct rte_eth_dev *dev)
3137 struct e1000_hw *hw =
3138 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3139 struct e1000_adapter *adapter =
3140 E1000_DEV_PRIVATE(dev->data->dev_private);
3141 struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
3142 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3144 uint32_t intr_vector = 0;
3146 PMD_INIT_FUNC_TRACE();
3148 hw->mac.ops.reset_hw(hw);
3149 adapter->stopped = 0;
3152 igbvf_set_vfta_all(dev,1);
3154 eth_igbvf_tx_init(dev);
3156 /* This can fail when allocating mbufs for descriptor rings */
3157 ret = eth_igbvf_rx_init(dev);
3159 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
3160 igb_dev_clear_queues(dev);
3164 /* check and configure queue intr-vector mapping */
3165 if (dev->data->dev_conf.intr_conf.rxq != 0) {
3166 intr_vector = dev->data->nb_rx_queues;
3167 ret = rte_intr_efd_enable(intr_handle, intr_vector);
3172 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
3173 intr_handle->intr_vec =
3174 rte_zmalloc("intr_vec",
3175 dev->data->nb_rx_queues * sizeof(int), 0);
3176 if (!intr_handle->intr_vec) {
3177 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
3178 " intr_vec", dev->data->nb_rx_queues);
3183 eth_igbvf_configure_msix_intr(dev);
3185 /* enable uio/vfio intr/eventfd mapping */
3186 rte_intr_enable(intr_handle);
3188 /* resume enabled intr since hw reset */
3189 igbvf_intr_enable(dev);
3195 igbvf_dev_stop(struct rte_eth_dev *dev)
3197 struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
3198 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
3200 PMD_INIT_FUNC_TRACE();
3202 igbvf_stop_adapter(dev);
3205 * Clear what we set, but we still keep shadow_vfta to
3206 * restore after device starts
3208 igbvf_set_vfta_all(dev,0);
3210 igb_dev_clear_queues(dev);
3212 /* disable intr eventfd mapping */
3213 rte_intr_disable(intr_handle);
3215 /* Clean datapath event and queue/vec mapping */
3216 rte_intr_efd_disable(intr_handle);
3217 if (intr_handle->intr_vec) {
3218 rte_free(intr_handle->intr_vec);
3219 intr_handle->intr_vec = NULL;
3224 igbvf_dev_close(struct rte_eth_dev *dev)
3226 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3227 struct e1000_adapter *adapter =
3228 E1000_DEV_PRIVATE(dev->data->dev_private);
3229 struct ether_addr addr;
3231 PMD_INIT_FUNC_TRACE();
3235 igbvf_dev_stop(dev);
3236 adapter->stopped = 1;
3237 igb_dev_free_queues(dev);
3240 * reprogram the RAR with a zero mac address,
3241 * to ensure that the VF traffic goes to the PF
3242 * after stop, close and detach of the VF.
3245 memset(&addr, 0, sizeof(addr));
3246 igbvf_default_mac_addr_set(dev, &addr);
3250 igbvf_promiscuous_enable(struct rte_eth_dev *dev)
3252 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3254 /* Set both unicast and multicast promisc */
3255 e1000_promisc_set_vf(hw, e1000_promisc_enabled);
3259 igbvf_promiscuous_disable(struct rte_eth_dev *dev)
3261 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3263 /* If in allmulticast mode leave multicast promisc */
3264 if (dev->data->all_multicast == 1)
3265 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3267 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3271 igbvf_allmulticast_enable(struct rte_eth_dev *dev)
3273 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3275 /* In promiscuous mode multicast promisc already set */
3276 if (dev->data->promiscuous == 0)
3277 e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3281 igbvf_allmulticast_disable(struct rte_eth_dev *dev)
3283 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3285 /* In promiscuous mode leave multicast promisc enabled */
3286 if (dev->data->promiscuous == 0)
3287 e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3290 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
3292 struct e1000_mbx_info *mbx = &hw->mbx;
3296 /* After set vlan, vlan strip will also be enabled in igb driver*/
3297 msgbuf[0] = E1000_VF_SET_VLAN;
3299 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
3301 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
3303 err = mbx->ops.write_posted(hw, msgbuf, 2, 0);
3307 err = mbx->ops.read_posted(hw, msgbuf, 2, 0);
3311 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
3312 if (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK))
3319 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
3321 struct e1000_hw *hw =
3322 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3323 struct e1000_vfta * shadow_vfta =
3324 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3325 int i = 0, j = 0, vfta = 0, mask = 1;
3327 for (i = 0; i < IGB_VFTA_SIZE; i++){
3328 vfta = shadow_vfta->vfta[i];
3331 for (j = 0; j < 32; j++){
3334 (uint16_t)((i<<5)+j), on);
3343 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3345 struct e1000_hw *hw =
3346 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3347 struct e1000_vfta * shadow_vfta =
3348 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3349 uint32_t vid_idx = 0;
3350 uint32_t vid_bit = 0;
3353 PMD_INIT_FUNC_TRACE();
3355 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
3356 ret = igbvf_set_vfta(hw, vlan_id, !!on);
3358 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
3361 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
3362 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
3364 /*Save what we set and retore it after device reset*/
3366 shadow_vfta->vfta[vid_idx] |= vid_bit;
3368 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
3374 igbvf_default_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *addr)
3376 struct e1000_hw *hw =
3377 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3379 /* index is not used by rar_set() */
3380 hw->mac.ops.rar_set(hw, (void *)addr, 0);
3385 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
3386 struct rte_eth_rss_reta_entry64 *reta_conf,
3391 uint16_t idx, shift;
3392 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3394 if (reta_size != ETH_RSS_RETA_SIZE_128) {
3395 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3396 "(%d) doesn't match the number hardware can supported "
3397 "(%d)", reta_size, ETH_RSS_RETA_SIZE_128);
3401 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3402 idx = i / RTE_RETA_GROUP_SIZE;
3403 shift = i % RTE_RETA_GROUP_SIZE;
3404 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3408 if (mask == IGB_4_BIT_MASK)
3411 r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3412 for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
3413 if (mask & (0x1 << j))
3414 reta |= reta_conf[idx].reta[shift + j] <<
3417 reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
3419 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
3426 eth_igb_rss_reta_query(struct rte_eth_dev *dev,
3427 struct rte_eth_rss_reta_entry64 *reta_conf,
3432 uint16_t idx, shift;
3433 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3435 if (reta_size != ETH_RSS_RETA_SIZE_128) {
3436 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3437 "(%d) doesn't match the number hardware can supported "
3438 "(%d)", reta_size, ETH_RSS_RETA_SIZE_128);
3442 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3443 idx = i / RTE_RETA_GROUP_SIZE;
3444 shift = i % RTE_RETA_GROUP_SIZE;
3445 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3449 reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3450 for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
3451 if (mask & (0x1 << j))
3452 reta_conf[idx].reta[shift + j] =
3453 ((reta >> (CHAR_BIT * j)) &
3461 #define MAC_TYPE_FILTER_SUP(type) do {\
3462 if ((type) != e1000_82580 && (type) != e1000_i350 &&\
3463 (type) != e1000_82576)\
3468 eth_igb_syn_filter_set(struct rte_eth_dev *dev,
3469 struct rte_eth_syn_filter *filter,
3472 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3473 uint32_t synqf, rfctl;
3475 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3478 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3481 if (synqf & E1000_SYN_FILTER_ENABLE)
3484 synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
3485 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
3487 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3488 if (filter->hig_pri)
3489 rfctl |= E1000_RFCTL_SYNQFP;
3491 rfctl &= ~E1000_RFCTL_SYNQFP;
3493 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
3495 if (!(synqf & E1000_SYN_FILTER_ENABLE))
3500 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
3501 E1000_WRITE_FLUSH(hw);
3506 eth_igb_syn_filter_get(struct rte_eth_dev *dev,
3507 struct rte_eth_syn_filter *filter)
3509 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3510 uint32_t synqf, rfctl;
3512 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3513 if (synqf & E1000_SYN_FILTER_ENABLE) {
3514 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3515 filter->hig_pri = (rfctl & E1000_RFCTL_SYNQFP) ? 1 : 0;
3516 filter->queue = (uint8_t)((synqf & E1000_SYN_FILTER_QUEUE) >>
3517 E1000_SYN_FILTER_QUEUE_SHIFT);
3525 eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
3526 enum rte_filter_op filter_op,
3529 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3532 MAC_TYPE_FILTER_SUP(hw->mac.type);
3534 if (filter_op == RTE_ETH_FILTER_NOP)
3538 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3543 switch (filter_op) {
3544 case RTE_ETH_FILTER_ADD:
3545 ret = eth_igb_syn_filter_set(dev,
3546 (struct rte_eth_syn_filter *)arg,
3549 case RTE_ETH_FILTER_DELETE:
3550 ret = eth_igb_syn_filter_set(dev,
3551 (struct rte_eth_syn_filter *)arg,
3554 case RTE_ETH_FILTER_GET:
3555 ret = eth_igb_syn_filter_get(dev,
3556 (struct rte_eth_syn_filter *)arg);
3559 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
3567 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
3568 if ((type) != e1000_82580 && (type) != e1000_i350)\
3572 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
3574 ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
3575 struct e1000_2tuple_filter_info *filter_info)
3577 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3579 if (filter->priority > E1000_2TUPLE_MAX_PRI)
3580 return -EINVAL; /* filter index is out of range. */
3581 if (filter->tcp_flags > TCP_FLAG_ALL)
3582 return -EINVAL; /* flags is invalid. */
3584 switch (filter->dst_port_mask) {
3586 filter_info->dst_port_mask = 0;
3587 filter_info->dst_port = filter->dst_port;
3590 filter_info->dst_port_mask = 1;
3593 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3597 switch (filter->proto_mask) {
3599 filter_info->proto_mask = 0;
3600 filter_info->proto = filter->proto;
3603 filter_info->proto_mask = 1;
3606 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3610 filter_info->priority = (uint8_t)filter->priority;
3611 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3612 filter_info->tcp_flags = filter->tcp_flags;
3614 filter_info->tcp_flags = 0;
3619 static inline struct e1000_2tuple_filter *
3620 igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
3621 struct e1000_2tuple_filter_info *key)
3623 struct e1000_2tuple_filter *it;
3625 TAILQ_FOREACH(it, filter_list, entries) {
3626 if (memcmp(key, &it->filter_info,
3627 sizeof(struct e1000_2tuple_filter_info)) == 0) {
3635 * igb_add_2tuple_filter - add a 2tuple filter
3638 * dev: Pointer to struct rte_eth_dev.
3639 * ntuple_filter: ponter to the filter that will be added.
3642 * - On success, zero.
3643 * - On failure, a negative value.
3646 igb_add_2tuple_filter(struct rte_eth_dev *dev,
3647 struct rte_eth_ntuple_filter *ntuple_filter)
3649 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3650 struct e1000_filter_info *filter_info =
3651 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3652 struct e1000_2tuple_filter *filter;
3653 uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
3654 uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3657 filter = rte_zmalloc("e1000_2tuple_filter",
3658 sizeof(struct e1000_2tuple_filter), 0);
3662 ret = ntuple_filter_to_2tuple(ntuple_filter,
3663 &filter->filter_info);
3668 if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3669 &filter->filter_info) != NULL) {
3670 PMD_DRV_LOG(ERR, "filter exists.");
3674 filter->queue = ntuple_filter->queue;
3677 * look for an unused 2tuple filter index,
3678 * and insert the filter to list.
3680 for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
3681 if (!(filter_info->twotuple_mask & (1 << i))) {
3682 filter_info->twotuple_mask |= 1 << i;
3684 TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
3690 if (i >= E1000_MAX_TTQF_FILTERS) {
3691 PMD_DRV_LOG(ERR, "2tuple filters are full.");
3696 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3697 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3698 imir |= E1000_IMIR_PORT_BP;
3700 imir &= ~E1000_IMIR_PORT_BP;
3702 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3704 ttqf |= E1000_TTQF_QUEUE_ENABLE;
3705 ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
3706 ttqf |= (uint32_t)(filter->filter_info.proto & E1000_TTQF_PROTOCOL_MASK);
3707 if (filter->filter_info.proto_mask == 0)
3708 ttqf &= ~E1000_TTQF_MASK_ENABLE;
3710 /* tcp flags bits setting. */
3711 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3712 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3713 imir_ext |= E1000_IMIREXT_CTRL_URG;
3714 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3715 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3716 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3717 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3718 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3719 imir_ext |= E1000_IMIREXT_CTRL_RST;
3720 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3721 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3722 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3723 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3725 imir_ext |= E1000_IMIREXT_CTRL_BP;
3726 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3727 E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
3728 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3733 * igb_remove_2tuple_filter - remove a 2tuple filter
3736 * dev: Pointer to struct rte_eth_dev.
3737 * ntuple_filter: ponter to the filter that will be removed.
3740 * - On success, zero.
3741 * - On failure, a negative value.
3744 igb_remove_2tuple_filter(struct rte_eth_dev *dev,
3745 struct rte_eth_ntuple_filter *ntuple_filter)
3747 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3748 struct e1000_filter_info *filter_info =
3749 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3750 struct e1000_2tuple_filter_info filter_2tuple;
3751 struct e1000_2tuple_filter *filter;
3754 memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
3755 ret = ntuple_filter_to_2tuple(ntuple_filter,
3760 filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3762 if (filter == NULL) {
3763 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3767 filter_info->twotuple_mask &= ~(1 << filter->index);
3768 TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
3771 E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
3772 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3773 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3777 static inline struct e1000_flex_filter *
3778 eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
3779 struct e1000_flex_filter_info *key)
3781 struct e1000_flex_filter *it;
3783 TAILQ_FOREACH(it, filter_list, entries) {
3784 if (memcmp(key, &it->filter_info,
3785 sizeof(struct e1000_flex_filter_info)) == 0)
3793 eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
3794 struct rte_eth_flex_filter *filter,
3797 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3798 struct e1000_filter_info *filter_info =
3799 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3800 struct e1000_flex_filter *flex_filter, *it;
3801 uint32_t wufc, queueing, mask;
3803 uint8_t shift, i, j = 0;
3805 flex_filter = rte_zmalloc("e1000_flex_filter",
3806 sizeof(struct e1000_flex_filter), 0);
3807 if (flex_filter == NULL)
3810 flex_filter->filter_info.len = filter->len;
3811 flex_filter->filter_info.priority = filter->priority;
3812 memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
3813 for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
3815 /* reverse bits in flex filter's mask*/
3816 for (shift = 0; shift < CHAR_BIT; shift++) {
3817 if (filter->mask[i] & (0x01 << shift))
3818 mask |= (0x80 >> shift);
3820 flex_filter->filter_info.mask[i] = mask;
3823 wufc = E1000_READ_REG(hw, E1000_WUFC);
3824 if (flex_filter->index < E1000_MAX_FHFT)
3825 reg_off = E1000_FHFT(flex_filter->index);
3827 reg_off = E1000_FHFT_EXT(flex_filter->index - E1000_MAX_FHFT);
3830 if (eth_igb_flex_filter_lookup(&filter_info->flex_list,
3831 &flex_filter->filter_info) != NULL) {
3832 PMD_DRV_LOG(ERR, "filter exists.");
3833 rte_free(flex_filter);
3836 flex_filter->queue = filter->queue;
3838 * look for an unused flex filter index
3839 * and insert the filter into the list.
3841 for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
3842 if (!(filter_info->flex_mask & (1 << i))) {
3843 filter_info->flex_mask |= 1 << i;
3844 flex_filter->index = i;
3845 TAILQ_INSERT_TAIL(&filter_info->flex_list,
3851 if (i >= E1000_MAX_FLEX_FILTERS) {
3852 PMD_DRV_LOG(ERR, "flex filters are full.");
3853 rte_free(flex_filter);
3857 E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
3858 (E1000_WUFC_FLX0 << flex_filter->index));
3859 queueing = filter->len |
3860 (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
3861 (filter->priority << E1000_FHFT_QUEUEING_PRIO_SHIFT);
3862 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
3864 for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
3865 E1000_WRITE_REG(hw, reg_off,
3866 flex_filter->filter_info.dwords[j]);
3867 reg_off += sizeof(uint32_t);
3868 E1000_WRITE_REG(hw, reg_off,
3869 flex_filter->filter_info.dwords[++j]);
3870 reg_off += sizeof(uint32_t);
3871 E1000_WRITE_REG(hw, reg_off,
3872 (uint32_t)flex_filter->filter_info.mask[i]);
3873 reg_off += sizeof(uint32_t) * 2;
3877 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
3878 &flex_filter->filter_info);
3880 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3881 rte_free(flex_filter);
3885 for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
3886 E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
3887 E1000_WRITE_REG(hw, E1000_WUFC, wufc &
3888 (~(E1000_WUFC_FLX0 << it->index)));
3890 filter_info->flex_mask &= ~(1 << it->index);
3891 TAILQ_REMOVE(&filter_info->flex_list, it, entries);
3893 rte_free(flex_filter);
3900 eth_igb_get_flex_filter(struct rte_eth_dev *dev,
3901 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, wufc_en = 0;
3909 memset(&flex_filter, 0, sizeof(struct e1000_flex_filter));
3910 flex_filter.filter_info.len = filter->len;
3911 flex_filter.filter_info.priority = filter->priority;
3912 memcpy(flex_filter.filter_info.dwords, filter->bytes, filter->len);
3913 memcpy(flex_filter.filter_info.mask, filter->mask,
3914 RTE_ALIGN(filter->len, sizeof(char)) / sizeof(char));
3916 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
3917 &flex_filter.filter_info);
3919 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3923 wufc = E1000_READ_REG(hw, E1000_WUFC);
3924 wufc_en = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << it->index);
3926 if ((wufc & wufc_en) == wufc_en) {
3927 uint32_t reg_off = 0;
3928 if (it->index < E1000_MAX_FHFT)
3929 reg_off = E1000_FHFT(it->index);
3931 reg_off = E1000_FHFT_EXT(it->index - E1000_MAX_FHFT);
3933 queueing = E1000_READ_REG(hw,
3934 reg_off + E1000_FHFT_QUEUEING_OFFSET);
3935 filter->len = queueing & E1000_FHFT_QUEUEING_LEN;
3936 filter->priority = (queueing & E1000_FHFT_QUEUEING_PRIO) >>
3937 E1000_FHFT_QUEUEING_PRIO_SHIFT;
3938 filter->queue = (queueing & E1000_FHFT_QUEUEING_QUEUE) >>
3939 E1000_FHFT_QUEUEING_QUEUE_SHIFT;
3946 eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
3947 enum rte_filter_op filter_op,
3950 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3951 struct rte_eth_flex_filter *filter;
3954 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
3956 if (filter_op == RTE_ETH_FILTER_NOP)
3960 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3965 filter = (struct rte_eth_flex_filter *)arg;
3966 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN
3967 || filter->len % sizeof(uint64_t) != 0) {
3968 PMD_DRV_LOG(ERR, "filter's length is out of range");
3971 if (filter->priority > E1000_MAX_FLEX_FILTER_PRI) {
3972 PMD_DRV_LOG(ERR, "filter's priority is out of range");
3976 switch (filter_op) {
3977 case RTE_ETH_FILTER_ADD:
3978 ret = eth_igb_add_del_flex_filter(dev, filter, TRUE);
3980 case RTE_ETH_FILTER_DELETE:
3981 ret = eth_igb_add_del_flex_filter(dev, filter, FALSE);
3983 case RTE_ETH_FILTER_GET:
3984 ret = eth_igb_get_flex_filter(dev, filter);
3987 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
3995 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
3997 ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
3998 struct e1000_5tuple_filter_info *filter_info)
4000 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
4002 if (filter->priority > E1000_2TUPLE_MAX_PRI)
4003 return -EINVAL; /* filter index is out of range. */
4004 if (filter->tcp_flags > TCP_FLAG_ALL)
4005 return -EINVAL; /* flags is invalid. */
4007 switch (filter->dst_ip_mask) {
4009 filter_info->dst_ip_mask = 0;
4010 filter_info->dst_ip = filter->dst_ip;
4013 filter_info->dst_ip_mask = 1;
4016 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
4020 switch (filter->src_ip_mask) {
4022 filter_info->src_ip_mask = 0;
4023 filter_info->src_ip = filter->src_ip;
4026 filter_info->src_ip_mask = 1;
4029 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
4033 switch (filter->dst_port_mask) {
4035 filter_info->dst_port_mask = 0;
4036 filter_info->dst_port = filter->dst_port;
4039 filter_info->dst_port_mask = 1;
4042 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
4046 switch (filter->src_port_mask) {
4048 filter_info->src_port_mask = 0;
4049 filter_info->src_port = filter->src_port;
4052 filter_info->src_port_mask = 1;
4055 PMD_DRV_LOG(ERR, "invalid src_port mask.");
4059 switch (filter->proto_mask) {
4061 filter_info->proto_mask = 0;
4062 filter_info->proto = filter->proto;
4065 filter_info->proto_mask = 1;
4068 PMD_DRV_LOG(ERR, "invalid protocol mask.");
4072 filter_info->priority = (uint8_t)filter->priority;
4073 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
4074 filter_info->tcp_flags = filter->tcp_flags;
4076 filter_info->tcp_flags = 0;
4081 static inline struct e1000_5tuple_filter *
4082 igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
4083 struct e1000_5tuple_filter_info *key)
4085 struct e1000_5tuple_filter *it;
4087 TAILQ_FOREACH(it, filter_list, entries) {
4088 if (memcmp(key, &it->filter_info,
4089 sizeof(struct e1000_5tuple_filter_info)) == 0) {
4097 * igb_add_5tuple_filter_82576 - add a 5tuple filter
4100 * dev: Pointer to struct rte_eth_dev.
4101 * ntuple_filter: ponter to the filter that will be added.
4104 * - On success, zero.
4105 * - On failure, a negative value.
4108 igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
4109 struct rte_eth_ntuple_filter *ntuple_filter)
4111 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4112 struct e1000_filter_info *filter_info =
4113 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4114 struct e1000_5tuple_filter *filter;
4115 uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
4116 uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
4120 filter = rte_zmalloc("e1000_5tuple_filter",
4121 sizeof(struct e1000_5tuple_filter), 0);
4125 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4126 &filter->filter_info);
4132 if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4133 &filter->filter_info) != NULL) {
4134 PMD_DRV_LOG(ERR, "filter exists.");
4138 filter->queue = ntuple_filter->queue;
4141 * look for an unused 5tuple filter index,
4142 * and insert the filter to list.
4144 for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
4145 if (!(filter_info->fivetuple_mask & (1 << i))) {
4146 filter_info->fivetuple_mask |= 1 << i;
4148 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
4154 if (i >= E1000_MAX_FTQF_FILTERS) {
4155 PMD_DRV_LOG(ERR, "5tuple filters are full.");
4160 ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
4161 if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
4162 ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
4163 if (filter->filter_info.dst_ip_mask == 0)
4164 ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
4165 if (filter->filter_info.src_port_mask == 0)
4166 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
4167 if (filter->filter_info.proto_mask == 0)
4168 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
4169 ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
4170 E1000_FTQF_QUEUE_MASK;
4171 ftqf |= E1000_FTQF_QUEUE_ENABLE;
4172 E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
4173 E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
4174 E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
4176 spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
4177 E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
4179 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
4180 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
4181 imir |= E1000_IMIR_PORT_BP;
4183 imir &= ~E1000_IMIR_PORT_BP;
4184 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
4186 /* tcp flags bits setting. */
4187 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
4188 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
4189 imir_ext |= E1000_IMIREXT_CTRL_URG;
4190 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
4191 imir_ext |= E1000_IMIREXT_CTRL_ACK;
4192 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
4193 imir_ext |= E1000_IMIREXT_CTRL_PSH;
4194 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
4195 imir_ext |= E1000_IMIREXT_CTRL_RST;
4196 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
4197 imir_ext |= E1000_IMIREXT_CTRL_SYN;
4198 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
4199 imir_ext |= E1000_IMIREXT_CTRL_FIN;
4201 imir_ext |= E1000_IMIREXT_CTRL_BP;
4202 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
4203 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
4208 * igb_remove_5tuple_filter_82576 - remove a 5tuple filter
4211 * dev: Pointer to struct rte_eth_dev.
4212 * ntuple_filter: ponter to the filter that will be removed.
4215 * - On success, zero.
4216 * - On failure, a negative value.
4219 igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
4220 struct rte_eth_ntuple_filter *ntuple_filter)
4222 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4223 struct e1000_filter_info *filter_info =
4224 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4225 struct e1000_5tuple_filter_info filter_5tuple;
4226 struct e1000_5tuple_filter *filter;
4229 memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
4230 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4235 filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4237 if (filter == NULL) {
4238 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4242 filter_info->fivetuple_mask &= ~(1 << filter->index);
4243 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
4246 E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
4247 E1000_FTQF_VF_BP | E1000_FTQF_MASK);
4248 E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
4249 E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
4250 E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
4251 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
4252 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
4257 eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
4260 struct e1000_hw *hw;
4261 struct rte_eth_dev_info dev_info;
4262 uint32_t frame_size = mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN +
4265 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4267 #ifdef RTE_LIBRTE_82571_SUPPORT
4268 /* XXX: not bigger than max_rx_pktlen */
4269 if (hw->mac.type == e1000_82571)
4272 eth_igb_infos_get(dev, &dev_info);
4274 /* check that mtu is within the allowed range */
4275 if ((mtu < ETHER_MIN_MTU) ||
4276 (frame_size > dev_info.max_rx_pktlen))
4279 /* refuse mtu that requires the support of scattered packets when this
4280 * feature has not been enabled before. */
4281 if (!dev->data->scattered_rx &&
4282 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)
4285 rctl = E1000_READ_REG(hw, E1000_RCTL);
4287 /* switch to jumbo mode if needed */
4288 if (frame_size > ETHER_MAX_LEN) {
4289 dev->data->dev_conf.rxmode.jumbo_frame = 1;
4290 rctl |= E1000_RCTL_LPE;
4292 dev->data->dev_conf.rxmode.jumbo_frame = 0;
4293 rctl &= ~E1000_RCTL_LPE;
4295 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
4297 /* update max frame size */
4298 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
4300 E1000_WRITE_REG(hw, E1000_RLPML,
4301 dev->data->dev_conf.rxmode.max_rx_pkt_len);
4307 * igb_add_del_ntuple_filter - add or delete a ntuple filter
4310 * dev: Pointer to struct rte_eth_dev.
4311 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4312 * add: if true, add filter, if false, remove filter
4315 * - On success, zero.
4316 * - On failure, a negative value.
4319 igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
4320 struct rte_eth_ntuple_filter *ntuple_filter,
4323 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4326 switch (ntuple_filter->flags) {
4327 case RTE_5TUPLE_FLAGS:
4328 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4329 if (hw->mac.type != e1000_82576)
4332 ret = igb_add_5tuple_filter_82576(dev,
4335 ret = igb_remove_5tuple_filter_82576(dev,
4338 case RTE_2TUPLE_FLAGS:
4339 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4340 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
4343 ret = igb_add_2tuple_filter(dev, ntuple_filter);
4345 ret = igb_remove_2tuple_filter(dev, ntuple_filter);
4356 * igb_get_ntuple_filter - get a ntuple filter
4359 * dev: Pointer to struct rte_eth_dev.
4360 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4363 * - On success, zero.
4364 * - On failure, a negative value.
4367 igb_get_ntuple_filter(struct rte_eth_dev *dev,
4368 struct rte_eth_ntuple_filter *ntuple_filter)
4370 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4371 struct e1000_filter_info *filter_info =
4372 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4373 struct e1000_5tuple_filter_info filter_5tuple;
4374 struct e1000_2tuple_filter_info filter_2tuple;
4375 struct e1000_5tuple_filter *p_5tuple_filter;
4376 struct e1000_2tuple_filter *p_2tuple_filter;
4379 switch (ntuple_filter->flags) {
4380 case RTE_5TUPLE_FLAGS:
4381 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4382 if (hw->mac.type != e1000_82576)
4384 memset(&filter_5tuple,
4386 sizeof(struct e1000_5tuple_filter_info));
4387 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4391 p_5tuple_filter = igb_5tuple_filter_lookup_82576(
4392 &filter_info->fivetuple_list,
4394 if (p_5tuple_filter == NULL) {
4395 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4398 ntuple_filter->queue = p_5tuple_filter->queue;
4400 case RTE_2TUPLE_FLAGS:
4401 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4402 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
4404 memset(&filter_2tuple,
4406 sizeof(struct e1000_2tuple_filter_info));
4407 ret = ntuple_filter_to_2tuple(ntuple_filter, &filter_2tuple);
4410 p_2tuple_filter = igb_2tuple_filter_lookup(
4411 &filter_info->twotuple_list,
4413 if (p_2tuple_filter == NULL) {
4414 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4417 ntuple_filter->queue = p_2tuple_filter->queue;
4428 * igb_ntuple_filter_handle - Handle operations for ntuple filter.
4429 * @dev: pointer to rte_eth_dev structure
4430 * @filter_op:operation will be taken.
4431 * @arg: a pointer to specific structure corresponding to the filter_op
4434 igb_ntuple_filter_handle(struct rte_eth_dev *dev,
4435 enum rte_filter_op filter_op,
4438 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4441 MAC_TYPE_FILTER_SUP(hw->mac.type);
4443 if (filter_op == RTE_ETH_FILTER_NOP)
4447 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4452 switch (filter_op) {
4453 case RTE_ETH_FILTER_ADD:
4454 ret = igb_add_del_ntuple_filter(dev,
4455 (struct rte_eth_ntuple_filter *)arg,
4458 case RTE_ETH_FILTER_DELETE:
4459 ret = igb_add_del_ntuple_filter(dev,
4460 (struct rte_eth_ntuple_filter *)arg,
4463 case RTE_ETH_FILTER_GET:
4464 ret = igb_get_ntuple_filter(dev,
4465 (struct rte_eth_ntuple_filter *)arg);
4468 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4476 igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
4481 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4482 if (filter_info->ethertype_filters[i] == ethertype &&
4483 (filter_info->ethertype_mask & (1 << i)))
4490 igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
4495 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4496 if (!(filter_info->ethertype_mask & (1 << i))) {
4497 filter_info->ethertype_mask |= 1 << i;
4498 filter_info->ethertype_filters[i] = ethertype;
4506 igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
4509 if (idx >= E1000_MAX_ETQF_FILTERS)
4511 filter_info->ethertype_mask &= ~(1 << idx);
4512 filter_info->ethertype_filters[idx] = 0;
4518 igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
4519 struct rte_eth_ethertype_filter *filter,
4522 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4523 struct e1000_filter_info *filter_info =
4524 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4528 if (filter->ether_type == ETHER_TYPE_IPv4 ||
4529 filter->ether_type == ETHER_TYPE_IPv6) {
4530 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
4531 " ethertype filter.", filter->ether_type);
4535 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
4536 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
4539 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
4540 PMD_DRV_LOG(ERR, "drop option is unsupported.");
4544 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4545 if (ret >= 0 && add) {
4546 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
4547 filter->ether_type);
4550 if (ret < 0 && !add) {
4551 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4552 filter->ether_type);
4557 ret = igb_ethertype_filter_insert(filter_info,
4558 filter->ether_type);
4560 PMD_DRV_LOG(ERR, "ethertype filters are full.");
4564 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
4565 etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
4566 etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
4568 ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
4572 E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
4573 E1000_WRITE_FLUSH(hw);
4579 igb_get_ethertype_filter(struct rte_eth_dev *dev,
4580 struct rte_eth_ethertype_filter *filter)
4582 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4583 struct e1000_filter_info *filter_info =
4584 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4588 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4590 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4591 filter->ether_type);
4595 etqf = E1000_READ_REG(hw, E1000_ETQF(ret));
4596 if (etqf & E1000_ETQF_FILTER_ENABLE) {
4597 filter->ether_type = etqf & E1000_ETQF_ETHERTYPE;
4599 filter->queue = (etqf & E1000_ETQF_QUEUE) >>
4600 E1000_ETQF_QUEUE_SHIFT;
4608 * igb_ethertype_filter_handle - Handle operations for ethertype filter.
4609 * @dev: pointer to rte_eth_dev structure
4610 * @filter_op:operation will be taken.
4611 * @arg: a pointer to specific structure corresponding to the filter_op
4614 igb_ethertype_filter_handle(struct rte_eth_dev *dev,
4615 enum rte_filter_op filter_op,
4618 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4621 MAC_TYPE_FILTER_SUP(hw->mac.type);
4623 if (filter_op == RTE_ETH_FILTER_NOP)
4627 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4632 switch (filter_op) {
4633 case RTE_ETH_FILTER_ADD:
4634 ret = igb_add_del_ethertype_filter(dev,
4635 (struct rte_eth_ethertype_filter *)arg,
4638 case RTE_ETH_FILTER_DELETE:
4639 ret = igb_add_del_ethertype_filter(dev,
4640 (struct rte_eth_ethertype_filter *)arg,
4643 case RTE_ETH_FILTER_GET:
4644 ret = igb_get_ethertype_filter(dev,
4645 (struct rte_eth_ethertype_filter *)arg);
4648 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4656 eth_igb_filter_ctrl(struct rte_eth_dev *dev,
4657 enum rte_filter_type filter_type,
4658 enum rte_filter_op filter_op,
4663 switch (filter_type) {
4664 case RTE_ETH_FILTER_NTUPLE:
4665 ret = igb_ntuple_filter_handle(dev, filter_op, arg);
4667 case RTE_ETH_FILTER_ETHERTYPE:
4668 ret = igb_ethertype_filter_handle(dev, filter_op, arg);
4670 case RTE_ETH_FILTER_SYN:
4671 ret = eth_igb_syn_filter_handle(dev, filter_op, arg);
4673 case RTE_ETH_FILTER_FLEXIBLE:
4674 ret = eth_igb_flex_filter_handle(dev, filter_op, arg);
4677 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
4686 eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
4687 struct ether_addr *mc_addr_set,
4688 uint32_t nb_mc_addr)
4690 struct e1000_hw *hw;
4692 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4693 e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
4698 igb_read_systime_cyclecounter(struct rte_eth_dev *dev)
4700 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4701 uint64_t systime_cycles;
4703 switch (hw->mac.type) {
4707 * Need to read System Time Residue Register to be able
4708 * to read the other two registers.
4710 E1000_READ_REG(hw, E1000_SYSTIMR);
4711 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
4712 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4713 systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4720 * Need to read System Time Residue Register to be able
4721 * to read the other two registers.
4723 E1000_READ_REG(hw, E1000_SYSTIMR);
4724 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4725 /* Only the 8 LSB are valid. */
4726 systime_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_SYSTIMH)
4730 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4731 systime_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4736 return systime_cycles;
4740 igb_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4742 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4743 uint64_t rx_tstamp_cycles;
4745 switch (hw->mac.type) {
4748 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4749 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4750 rx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4756 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4757 /* Only the 8 LSB are valid. */
4758 rx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_RXSTMPH)
4762 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4763 rx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4768 return rx_tstamp_cycles;
4772 igb_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4774 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4775 uint64_t tx_tstamp_cycles;
4777 switch (hw->mac.type) {
4780 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4781 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4782 tx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4788 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4789 /* Only the 8 LSB are valid. */
4790 tx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_TXSTMPH)
4794 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4795 tx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4800 return tx_tstamp_cycles;
4804 igb_start_timecounters(struct rte_eth_dev *dev)
4806 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4807 struct e1000_adapter *adapter =
4808 (struct e1000_adapter *)dev->data->dev_private;
4809 uint32_t incval = 1;
4811 uint64_t mask = E1000_CYCLECOUNTER_MASK;
4813 switch (hw->mac.type) {
4817 /* 32 LSB bits + 8 MSB bits = 40 bits */
4818 mask = (1ULL << 40) - 1;
4823 * Start incrementing the register
4824 * used to timestamp PTP packets.
4826 E1000_WRITE_REG(hw, E1000_TIMINCA, incval);
4829 incval = E1000_INCVALUE_82576;
4830 shift = IGB_82576_TSYNC_SHIFT;
4831 E1000_WRITE_REG(hw, E1000_TIMINCA,
4832 E1000_INCPERIOD_82576 | incval);
4839 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
4840 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4841 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4843 adapter->systime_tc.cc_mask = mask;
4844 adapter->systime_tc.cc_shift = shift;
4845 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
4847 adapter->rx_tstamp_tc.cc_mask = mask;
4848 adapter->rx_tstamp_tc.cc_shift = shift;
4849 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4851 adapter->tx_tstamp_tc.cc_mask = mask;
4852 adapter->tx_tstamp_tc.cc_shift = shift;
4853 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4857 igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
4859 struct e1000_adapter *adapter =
4860 (struct e1000_adapter *)dev->data->dev_private;
4862 adapter->systime_tc.nsec += delta;
4863 adapter->rx_tstamp_tc.nsec += delta;
4864 adapter->tx_tstamp_tc.nsec += delta;
4870 igb_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
4873 struct e1000_adapter *adapter =
4874 (struct e1000_adapter *)dev->data->dev_private;
4876 ns = rte_timespec_to_ns(ts);
4878 /* Set the timecounters to a new value. */
4879 adapter->systime_tc.nsec = ns;
4880 adapter->rx_tstamp_tc.nsec = ns;
4881 adapter->tx_tstamp_tc.nsec = ns;
4887 igb_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
4889 uint64_t ns, systime_cycles;
4890 struct e1000_adapter *adapter =
4891 (struct e1000_adapter *)dev->data->dev_private;
4893 systime_cycles = igb_read_systime_cyclecounter(dev);
4894 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
4895 *ts = rte_ns_to_timespec(ns);
4901 igb_timesync_enable(struct rte_eth_dev *dev)
4903 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4907 /* Stop the timesync system time. */
4908 E1000_WRITE_REG(hw, E1000_TIMINCA, 0x0);
4909 /* Reset the timesync system time value. */
4910 switch (hw->mac.type) {
4916 E1000_WRITE_REG(hw, E1000_SYSTIMR, 0x0);
4919 E1000_WRITE_REG(hw, E1000_SYSTIML, 0x0);
4920 E1000_WRITE_REG(hw, E1000_SYSTIMH, 0x0);
4923 /* Not supported. */
4927 /* Enable system time for it isn't on by default. */
4928 tsauxc = E1000_READ_REG(hw, E1000_TSAUXC);
4929 tsauxc &= ~E1000_TSAUXC_DISABLE_SYSTIME;
4930 E1000_WRITE_REG(hw, E1000_TSAUXC, tsauxc);
4932 igb_start_timecounters(dev);
4934 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
4935 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588),
4937 E1000_ETQF_FILTER_ENABLE |
4940 /* Enable timestamping of received PTP packets. */
4941 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4942 tsync_ctl |= E1000_TSYNCRXCTL_ENABLED;
4943 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
4945 /* Enable Timestamping of transmitted PTP packets. */
4946 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4947 tsync_ctl |= E1000_TSYNCTXCTL_ENABLED;
4948 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
4954 igb_timesync_disable(struct rte_eth_dev *dev)
4956 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4959 /* Disable timestamping of transmitted PTP packets. */
4960 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4961 tsync_ctl &= ~E1000_TSYNCTXCTL_ENABLED;
4962 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
4964 /* Disable timestamping of received PTP packets. */
4965 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4966 tsync_ctl &= ~E1000_TSYNCRXCTL_ENABLED;
4967 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
4969 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
4970 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588), 0);
4972 /* Stop incrementating the System Time registers. */
4973 E1000_WRITE_REG(hw, E1000_TIMINCA, 0);
4979 igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
4980 struct timespec *timestamp,
4981 uint32_t flags __rte_unused)
4983 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4984 struct e1000_adapter *adapter =
4985 (struct e1000_adapter *)dev->data->dev_private;
4986 uint32_t tsync_rxctl;
4987 uint64_t rx_tstamp_cycles;
4990 tsync_rxctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4991 if ((tsync_rxctl & E1000_TSYNCRXCTL_VALID) == 0)
4994 rx_tstamp_cycles = igb_read_rx_tstamp_cyclecounter(dev);
4995 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
4996 *timestamp = rte_ns_to_timespec(ns);
5002 igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
5003 struct timespec *timestamp)
5005 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5006 struct e1000_adapter *adapter =
5007 (struct e1000_adapter *)dev->data->dev_private;
5008 uint32_t tsync_txctl;
5009 uint64_t tx_tstamp_cycles;
5012 tsync_txctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5013 if ((tsync_txctl & E1000_TSYNCTXCTL_VALID) == 0)
5016 tx_tstamp_cycles = igb_read_tx_tstamp_cyclecounter(dev);
5017 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
5018 *timestamp = rte_ns_to_timespec(ns);
5024 eth_igb_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5028 const struct reg_info *reg_group;
5030 while ((reg_group = igb_regs[g_ind++]))
5031 count += igb_reg_group_count(reg_group);
5037 igbvf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5041 const struct reg_info *reg_group;
5043 while ((reg_group = igbvf_regs[g_ind++]))
5044 count += igb_reg_group_count(reg_group);
5050 eth_igb_get_regs(struct rte_eth_dev *dev,
5051 struct rte_dev_reg_info *regs)
5053 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5054 uint32_t *data = regs->data;
5057 const struct reg_info *reg_group;
5060 regs->length = eth_igb_get_reg_length(dev);
5061 regs->width = sizeof(uint32_t);
5065 /* Support only full register dump */
5066 if ((regs->length == 0) ||
5067 (regs->length == (uint32_t)eth_igb_get_reg_length(dev))) {
5068 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5070 while ((reg_group = igb_regs[g_ind++]))
5071 count += igb_read_regs_group(dev, &data[count],
5080 igbvf_get_regs(struct rte_eth_dev *dev,
5081 struct rte_dev_reg_info *regs)
5083 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5084 uint32_t *data = regs->data;
5087 const struct reg_info *reg_group;
5090 regs->length = igbvf_get_reg_length(dev);
5091 regs->width = sizeof(uint32_t);
5095 /* Support only full register dump */
5096 if ((regs->length == 0) ||
5097 (regs->length == (uint32_t)igbvf_get_reg_length(dev))) {
5098 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5100 while ((reg_group = igbvf_regs[g_ind++]))
5101 count += igb_read_regs_group(dev, &data[count],
5110 eth_igb_get_eeprom_length(struct rte_eth_dev *dev)
5112 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5114 /* Return unit is byte count */
5115 return hw->nvm.word_size * 2;
5119 eth_igb_get_eeprom(struct rte_eth_dev *dev,
5120 struct rte_dev_eeprom_info *in_eeprom)
5122 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5123 struct e1000_nvm_info *nvm = &hw->nvm;
5124 uint16_t *data = in_eeprom->data;
5127 first = in_eeprom->offset >> 1;
5128 length = in_eeprom->length >> 1;
5129 if ((first >= hw->nvm.word_size) ||
5130 ((first + length) >= hw->nvm.word_size))
5133 in_eeprom->magic = hw->vendor_id |
5134 ((uint32_t)hw->device_id << 16);
5136 if ((nvm->ops.read) == NULL)
5139 return nvm->ops.read(hw, first, length, data);
5143 eth_igb_set_eeprom(struct rte_eth_dev *dev,
5144 struct rte_dev_eeprom_info *in_eeprom)
5146 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5147 struct e1000_nvm_info *nvm = &hw->nvm;
5148 uint16_t *data = in_eeprom->data;
5151 first = in_eeprom->offset >> 1;
5152 length = in_eeprom->length >> 1;
5153 if ((first >= hw->nvm.word_size) ||
5154 ((first + length) >= hw->nvm.word_size))
5157 in_eeprom->magic = (uint32_t)hw->vendor_id |
5158 ((uint32_t)hw->device_id << 16);
5160 if ((nvm->ops.write) == NULL)
5162 return nvm->ops.write(hw, first, length, data);
5166 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
5168 struct e1000_hw *hw =
5169 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5170 uint32_t mask = 1 << queue_id;
5172 E1000_WRITE_REG(hw, E1000_EIMC, mask);
5173 E1000_WRITE_FLUSH(hw);
5179 eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
5181 struct e1000_hw *hw =
5182 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5183 struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
5184 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5185 uint32_t mask = 1 << queue_id;
5188 regval = E1000_READ_REG(hw, E1000_EIMS);
5189 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
5190 E1000_WRITE_FLUSH(hw);
5192 rte_intr_enable(intr_handle);
5198 eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
5199 uint8_t index, uint8_t offset)
5201 uint32_t val = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
5204 val &= ~((uint32_t)0xFF << offset);
5206 /* write vector and valid bit */
5207 val |= (msix_vector | E1000_IVAR_VALID) << offset;
5209 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, val);
5213 eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
5214 uint8_t queue, uint8_t msix_vector)
5218 if (hw->mac.type == e1000_82575) {
5220 tmp = E1000_EICR_RX_QUEUE0 << queue;
5221 else if (direction == 1)
5222 tmp = E1000_EICR_TX_QUEUE0 << queue;
5223 E1000_WRITE_REG(hw, E1000_MSIXBM(msix_vector), tmp);
5224 } else if (hw->mac.type == e1000_82576) {
5225 if ((direction == 0) || (direction == 1))
5226 eth_igb_write_ivar(hw, msix_vector, queue & 0x7,
5227 ((queue & 0x8) << 1) +
5229 } else if ((hw->mac.type == e1000_82580) ||
5230 (hw->mac.type == e1000_i350) ||
5231 (hw->mac.type == e1000_i354) ||
5232 (hw->mac.type == e1000_i210) ||
5233 (hw->mac.type == e1000_i211)) {
5234 if ((direction == 0) || (direction == 1))
5235 eth_igb_write_ivar(hw, msix_vector,
5237 ((queue & 0x1) << 4) +
5242 /* Sets up the hardware to generate MSI-X interrupts properly
5244 * board private structure
5247 eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
5250 uint32_t tmpval, regval, intr_mask;
5251 struct e1000_hw *hw =
5252 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5253 uint32_t vec = E1000_MISC_VEC_ID;
5254 uint32_t base = E1000_MISC_VEC_ID;
5255 uint32_t misc_shift = 0;
5256 struct rte_pci_device *pci_dev = E1000_DEV_TO_PCI(dev);
5257 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
5259 /* won't configure msix register if no mapping is done
5260 * between intr vector and event fd
5262 if (!rte_intr_dp_is_en(intr_handle))
5265 if (rte_intr_allow_others(intr_handle)) {
5266 vec = base = E1000_RX_VEC_START;
5270 /* set interrupt vector for other causes */
5271 if (hw->mac.type == e1000_82575) {
5272 tmpval = E1000_READ_REG(hw, E1000_CTRL_EXT);
5273 /* enable MSI-X PBA support */
5274 tmpval |= E1000_CTRL_EXT_PBA_CLR;
5276 /* Auto-Mask interrupts upon ICR read */
5277 tmpval |= E1000_CTRL_EXT_EIAME;
5278 tmpval |= E1000_CTRL_EXT_IRCA;
5280 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmpval);
5282 /* enable msix_other interrupt */
5283 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), 0, E1000_EIMS_OTHER);
5284 regval = E1000_READ_REG(hw, E1000_EIAC);
5285 E1000_WRITE_REG(hw, E1000_EIAC, regval | E1000_EIMS_OTHER);
5286 regval = E1000_READ_REG(hw, E1000_EIAM);
5287 E1000_WRITE_REG(hw, E1000_EIMS, regval | E1000_EIMS_OTHER);
5288 } else if ((hw->mac.type == e1000_82576) ||
5289 (hw->mac.type == e1000_82580) ||
5290 (hw->mac.type == e1000_i350) ||
5291 (hw->mac.type == e1000_i354) ||
5292 (hw->mac.type == e1000_i210) ||
5293 (hw->mac.type == e1000_i211)) {
5294 /* turn on MSI-X capability first */
5295 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
5296 E1000_GPIE_PBA | E1000_GPIE_EIAME |
5298 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
5300 regval = E1000_READ_REG(hw, E1000_EIAC);
5301 E1000_WRITE_REG(hw, E1000_EIAC, regval | intr_mask);
5303 /* enable msix_other interrupt */
5304 regval = E1000_READ_REG(hw, E1000_EIMS);
5305 E1000_WRITE_REG(hw, E1000_EIMS, regval | intr_mask);
5306 tmpval = (dev->data->nb_rx_queues | E1000_IVAR_VALID) << 8;
5307 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmpval);
5310 /* use EIAM to auto-mask when MSI-X interrupt
5311 * is asserted, this saves a register write for every interrupt
5313 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
5315 regval = E1000_READ_REG(hw, E1000_EIAM);
5316 E1000_WRITE_REG(hw, E1000_EIAM, regval | intr_mask);
5318 for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
5319 eth_igb_assign_msix_vector(hw, 0, queue_id, vec);
5320 intr_handle->intr_vec[queue_id] = vec;
5321 if (vec < base + intr_handle->nb_efd - 1)
5325 E1000_WRITE_FLUSH(hw);
5328 RTE_PMD_REGISTER_PCI(net_e1000_igb, rte_igb_pmd);
5329 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb, pci_id_igb_map);
5330 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb, "* igb_uio | uio_pci_generic | vfio");
5331 RTE_PMD_REGISTER_PCI(net_e1000_igb_vf, rte_igbvf_pmd);
5332 RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb_vf, pci_id_igbvf_map);
5333 RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb_vf, "* igb_uio | vfio");