4 * Copyright(c) 2010-2015 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_memory.h>
49 #include <rte_memzone.h>
51 #include <rte_atomic.h>
52 #include <rte_malloc.h>
55 #include "e1000_logs.h"
56 #include "base/e1000_api.h"
57 #include "e1000_ethdev.h"
61 * Default values for port configuration
63 #define IGB_DEFAULT_RX_FREE_THRESH 32
64 #define IGB_DEFAULT_RX_PTHRESH 8
65 #define IGB_DEFAULT_RX_HTHRESH 8
66 #define IGB_DEFAULT_RX_WTHRESH 0
68 #define IGB_DEFAULT_TX_PTHRESH 32
69 #define IGB_DEFAULT_TX_HTHRESH 0
70 #define IGB_DEFAULT_TX_WTHRESH 0
72 #define IGB_HKEY_MAX_INDEX 10
74 /* Bit shift and mask */
75 #define IGB_4_BIT_WIDTH (CHAR_BIT / 2)
76 #define IGB_4_BIT_MASK RTE_LEN2MASK(IGB_4_BIT_WIDTH, uint8_t)
77 #define IGB_8_BIT_WIDTH CHAR_BIT
78 #define IGB_8_BIT_MASK UINT8_MAX
80 /* Additional timesync values. */
81 #define E1000_CYCLECOUNTER_MASK 0xffffffffffffffff
82 #define E1000_ETQF_FILTER_1588 3
83 #define IGB_82576_TSYNC_SHIFT 16
84 #define E1000_INCPERIOD_82576 (1 << E1000_TIMINCA_16NS_SHIFT)
85 #define E1000_INCVALUE_82576 (16 << IGB_82576_TSYNC_SHIFT)
86 #define E1000_TSAUXC_DISABLE_SYSTIME 0x80000000
88 static int eth_igb_configure(struct rte_eth_dev *dev);
89 static int eth_igb_start(struct rte_eth_dev *dev);
90 static void eth_igb_stop(struct rte_eth_dev *dev);
91 static void eth_igb_close(struct rte_eth_dev *dev);
92 static void eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
93 static void eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
94 static void eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
95 static void eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
96 static int eth_igb_link_update(struct rte_eth_dev *dev,
97 int wait_to_complete);
98 static void eth_igb_stats_get(struct rte_eth_dev *dev,
99 struct rte_eth_stats *rte_stats);
100 static int eth_igb_xstats_get(struct rte_eth_dev *dev,
101 struct rte_eth_xstats *xstats, unsigned n);
102 static void eth_igb_stats_reset(struct rte_eth_dev *dev);
103 static void eth_igb_xstats_reset(struct rte_eth_dev *dev);
104 static void eth_igb_infos_get(struct rte_eth_dev *dev,
105 struct rte_eth_dev_info *dev_info);
106 static void eth_igbvf_infos_get(struct rte_eth_dev *dev,
107 struct rte_eth_dev_info *dev_info);
108 static int eth_igb_flow_ctrl_get(struct rte_eth_dev *dev,
109 struct rte_eth_fc_conf *fc_conf);
110 static int eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
111 struct rte_eth_fc_conf *fc_conf);
112 static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev);
113 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
114 static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
115 static int eth_igb_interrupt_action(struct rte_eth_dev *dev);
116 static void eth_igb_interrupt_handler(struct rte_intr_handle *handle,
118 static int igb_hardware_init(struct e1000_hw *hw);
119 static void igb_hw_control_acquire(struct e1000_hw *hw);
120 static void igb_hw_control_release(struct e1000_hw *hw);
121 static void igb_init_manageability(struct e1000_hw *hw);
122 static void igb_release_manageability(struct e1000_hw *hw);
124 static int eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
126 static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
127 uint16_t vlan_id, int on);
128 static void eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid_id);
129 static void eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
131 static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
132 static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
133 static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
134 static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
135 static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
136 static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
138 static int eth_igb_led_on(struct rte_eth_dev *dev);
139 static int eth_igb_led_off(struct rte_eth_dev *dev);
141 static void igb_intr_disable(struct e1000_hw *hw);
142 static int igb_get_rx_buffer_size(struct e1000_hw *hw);
143 static void eth_igb_rar_set(struct rte_eth_dev *dev,
144 struct ether_addr *mac_addr,
145 uint32_t index, uint32_t pool);
146 static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
147 static void eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
148 struct ether_addr *addr);
150 static void igbvf_intr_disable(struct e1000_hw *hw);
151 static int igbvf_dev_configure(struct rte_eth_dev *dev);
152 static int igbvf_dev_start(struct rte_eth_dev *dev);
153 static void igbvf_dev_stop(struct rte_eth_dev *dev);
154 static void igbvf_dev_close(struct rte_eth_dev *dev);
155 static int eth_igbvf_link_update(struct e1000_hw *hw);
156 static void eth_igbvf_stats_get(struct rte_eth_dev *dev,
157 struct rte_eth_stats *rte_stats);
158 static int eth_igbvf_xstats_get(struct rte_eth_dev *dev,
159 struct rte_eth_xstats *xstats, unsigned n);
160 static void eth_igbvf_stats_reset(struct rte_eth_dev *dev);
161 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
162 uint16_t vlan_id, int on);
163 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
164 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
165 static void igbvf_default_mac_addr_set(struct rte_eth_dev *dev,
166 struct ether_addr *addr);
167 static int igbvf_get_reg_length(struct rte_eth_dev *dev);
168 static int igbvf_get_regs(struct rte_eth_dev *dev,
169 struct rte_dev_reg_info *regs);
171 static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
172 struct rte_eth_rss_reta_entry64 *reta_conf,
174 static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
175 struct rte_eth_rss_reta_entry64 *reta_conf,
178 static int eth_igb_syn_filter_set(struct rte_eth_dev *dev,
179 struct rte_eth_syn_filter *filter,
181 static int eth_igb_syn_filter_get(struct rte_eth_dev *dev,
182 struct rte_eth_syn_filter *filter);
183 static int eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
184 enum rte_filter_op filter_op,
186 static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
187 struct rte_eth_ntuple_filter *ntuple_filter);
188 static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
189 struct rte_eth_ntuple_filter *ntuple_filter);
190 static int eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
191 struct rte_eth_flex_filter *filter,
193 static int eth_igb_get_flex_filter(struct rte_eth_dev *dev,
194 struct rte_eth_flex_filter *filter);
195 static int eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
196 enum rte_filter_op filter_op,
198 static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
199 struct rte_eth_ntuple_filter *ntuple_filter);
200 static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
201 struct rte_eth_ntuple_filter *ntuple_filter);
202 static int igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
203 struct rte_eth_ntuple_filter *filter,
205 static int igb_get_ntuple_filter(struct rte_eth_dev *dev,
206 struct rte_eth_ntuple_filter *filter);
207 static int igb_ntuple_filter_handle(struct rte_eth_dev *dev,
208 enum rte_filter_op filter_op,
210 static int igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
211 struct rte_eth_ethertype_filter *filter,
213 static int igb_ethertype_filter_handle(struct rte_eth_dev *dev,
214 enum rte_filter_op filter_op,
216 static int igb_get_ethertype_filter(struct rte_eth_dev *dev,
217 struct rte_eth_ethertype_filter *filter);
218 static int eth_igb_filter_ctrl(struct rte_eth_dev *dev,
219 enum rte_filter_type filter_type,
220 enum rte_filter_op filter_op,
222 static int eth_igb_get_reg_length(struct rte_eth_dev *dev);
223 static int eth_igb_get_regs(struct rte_eth_dev *dev,
224 struct rte_dev_reg_info *regs);
225 static int eth_igb_get_eeprom_length(struct rte_eth_dev *dev);
226 static int eth_igb_get_eeprom(struct rte_eth_dev *dev,
227 struct rte_dev_eeprom_info *eeprom);
228 static int eth_igb_set_eeprom(struct rte_eth_dev *dev,
229 struct rte_dev_eeprom_info *eeprom);
230 static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
231 struct ether_addr *mc_addr_set,
232 uint32_t nb_mc_addr);
233 static int igb_timesync_enable(struct rte_eth_dev *dev);
234 static int igb_timesync_disable(struct rte_eth_dev *dev);
235 static int igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
236 struct timespec *timestamp,
238 static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
239 struct timespec *timestamp);
240 static int igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
241 static int igb_timesync_read_time(struct rte_eth_dev *dev,
242 struct timespec *timestamp);
243 static int igb_timesync_write_time(struct rte_eth_dev *dev,
244 const struct timespec *timestamp);
245 static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
247 static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
249 static void eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
250 uint8_t queue, uint8_t msix_vector);
251 static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
252 uint8_t index, uint8_t offset);
253 static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
256 * Define VF Stats MACRO for Non "cleared on read" register
258 #define UPDATE_VF_STAT(reg, last, cur) \
260 u32 latest = E1000_READ_REG(hw, reg); \
261 cur += (latest - last) & UINT_MAX; \
265 #define IGB_FC_PAUSE_TIME 0x0680
266 #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
267 #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
269 #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
271 static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
274 * The set of PCI devices this driver supports
276 static const struct rte_pci_id pci_id_igb_map[] = {
278 #define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
279 #include "rte_pci_dev_ids.h"
285 * The set of PCI devices this driver supports (for 82576&I350 VF)
287 static const struct rte_pci_id pci_id_igbvf_map[] = {
289 #define RTE_PCI_DEV_ID_DECL_IGBVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
290 #include "rte_pci_dev_ids.h"
295 static const struct rte_eth_desc_lim rx_desc_lim = {
296 .nb_max = E1000_MAX_RING_DESC,
297 .nb_min = E1000_MIN_RING_DESC,
298 .nb_align = IGB_RXD_ALIGN,
301 static const struct rte_eth_desc_lim tx_desc_lim = {
302 .nb_max = E1000_MAX_RING_DESC,
303 .nb_min = E1000_MIN_RING_DESC,
304 .nb_align = IGB_RXD_ALIGN,
307 static const struct eth_dev_ops eth_igb_ops = {
308 .dev_configure = eth_igb_configure,
309 .dev_start = eth_igb_start,
310 .dev_stop = eth_igb_stop,
311 .dev_close = eth_igb_close,
312 .promiscuous_enable = eth_igb_promiscuous_enable,
313 .promiscuous_disable = eth_igb_promiscuous_disable,
314 .allmulticast_enable = eth_igb_allmulticast_enable,
315 .allmulticast_disable = eth_igb_allmulticast_disable,
316 .link_update = eth_igb_link_update,
317 .stats_get = eth_igb_stats_get,
318 .xstats_get = eth_igb_xstats_get,
319 .stats_reset = eth_igb_stats_reset,
320 .xstats_reset = eth_igb_xstats_reset,
321 .dev_infos_get = eth_igb_infos_get,
322 .mtu_set = eth_igb_mtu_set,
323 .vlan_filter_set = eth_igb_vlan_filter_set,
324 .vlan_tpid_set = eth_igb_vlan_tpid_set,
325 .vlan_offload_set = eth_igb_vlan_offload_set,
326 .rx_queue_setup = eth_igb_rx_queue_setup,
327 .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
328 .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
329 .rx_queue_release = eth_igb_rx_queue_release,
330 .rx_queue_count = eth_igb_rx_queue_count,
331 .rx_descriptor_done = eth_igb_rx_descriptor_done,
332 .tx_queue_setup = eth_igb_tx_queue_setup,
333 .tx_queue_release = eth_igb_tx_queue_release,
334 .dev_led_on = eth_igb_led_on,
335 .dev_led_off = eth_igb_led_off,
336 .flow_ctrl_get = eth_igb_flow_ctrl_get,
337 .flow_ctrl_set = eth_igb_flow_ctrl_set,
338 .mac_addr_add = eth_igb_rar_set,
339 .mac_addr_remove = eth_igb_rar_clear,
340 .mac_addr_set = eth_igb_default_mac_addr_set,
341 .reta_update = eth_igb_rss_reta_update,
342 .reta_query = eth_igb_rss_reta_query,
343 .rss_hash_update = eth_igb_rss_hash_update,
344 .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
345 .filter_ctrl = eth_igb_filter_ctrl,
346 .set_mc_addr_list = eth_igb_set_mc_addr_list,
347 .rxq_info_get = igb_rxq_info_get,
348 .txq_info_get = igb_txq_info_get,
349 .timesync_enable = igb_timesync_enable,
350 .timesync_disable = igb_timesync_disable,
351 .timesync_read_rx_timestamp = igb_timesync_read_rx_timestamp,
352 .timesync_read_tx_timestamp = igb_timesync_read_tx_timestamp,
353 .get_reg_length = eth_igb_get_reg_length,
354 .get_reg = eth_igb_get_regs,
355 .get_eeprom_length = eth_igb_get_eeprom_length,
356 .get_eeprom = eth_igb_get_eeprom,
357 .set_eeprom = eth_igb_set_eeprom,
358 .timesync_adjust_time = igb_timesync_adjust_time,
359 .timesync_read_time = igb_timesync_read_time,
360 .timesync_write_time = igb_timesync_write_time,
364 * dev_ops for virtual function, bare necessities for basic vf
365 * operation have been implemented
367 static const struct eth_dev_ops igbvf_eth_dev_ops = {
368 .dev_configure = igbvf_dev_configure,
369 .dev_start = igbvf_dev_start,
370 .dev_stop = igbvf_dev_stop,
371 .dev_close = igbvf_dev_close,
372 .link_update = eth_igb_link_update,
373 .stats_get = eth_igbvf_stats_get,
374 .xstats_get = eth_igbvf_xstats_get,
375 .stats_reset = eth_igbvf_stats_reset,
376 .xstats_reset = eth_igbvf_stats_reset,
377 .vlan_filter_set = igbvf_vlan_filter_set,
378 .dev_infos_get = eth_igbvf_infos_get,
379 .rx_queue_setup = eth_igb_rx_queue_setup,
380 .rx_queue_release = eth_igb_rx_queue_release,
381 .tx_queue_setup = eth_igb_tx_queue_setup,
382 .tx_queue_release = eth_igb_tx_queue_release,
383 .set_mc_addr_list = eth_igb_set_mc_addr_list,
384 .rxq_info_get = igb_rxq_info_get,
385 .txq_info_get = igb_txq_info_get,
386 .mac_addr_set = igbvf_default_mac_addr_set,
387 .get_reg_length = igbvf_get_reg_length,
388 .get_reg = igbvf_get_regs,
391 /* store statistics names and its offset in stats structure */
392 struct rte_igb_xstats_name_off {
393 char name[RTE_ETH_XSTATS_NAME_SIZE];
397 static const struct rte_igb_xstats_name_off rte_igb_stats_strings[] = {
398 {"rx_crc_errors", offsetof(struct e1000_hw_stats, crcerrs)},
399 {"rx_align_errors", offsetof(struct e1000_hw_stats, algnerrc)},
400 {"rx_symbol_errors", offsetof(struct e1000_hw_stats, symerrs)},
401 {"rx_missed_packets", offsetof(struct e1000_hw_stats, mpc)},
402 {"tx_single_collision_packets", offsetof(struct e1000_hw_stats, scc)},
403 {"tx_multiple_collision_packets", offsetof(struct e1000_hw_stats, mcc)},
404 {"tx_excessive_collision_packets", offsetof(struct e1000_hw_stats,
406 {"tx_late_collisions", offsetof(struct e1000_hw_stats, latecol)},
407 {"tx_total_collisions", offsetof(struct e1000_hw_stats, colc)},
408 {"tx_deferred_packets", offsetof(struct e1000_hw_stats, dc)},
409 {"tx_no_carrier_sense_packets", offsetof(struct e1000_hw_stats, tncrs)},
410 {"rx_carrier_ext_errors", offsetof(struct e1000_hw_stats, cexterr)},
411 {"rx_length_errors", offsetof(struct e1000_hw_stats, rlec)},
412 {"rx_xon_packets", offsetof(struct e1000_hw_stats, xonrxc)},
413 {"tx_xon_packets", offsetof(struct e1000_hw_stats, xontxc)},
414 {"rx_xoff_packets", offsetof(struct e1000_hw_stats, xoffrxc)},
415 {"tx_xoff_packets", offsetof(struct e1000_hw_stats, xofftxc)},
416 {"rx_flow_control_unsupported_packets", offsetof(struct e1000_hw_stats,
418 {"rx_size_64_packets", offsetof(struct e1000_hw_stats, prc64)},
419 {"rx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, prc127)},
420 {"rx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, prc255)},
421 {"rx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, prc511)},
422 {"rx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
424 {"rx_size_1024_to_max_packets", offsetof(struct e1000_hw_stats,
426 {"rx_broadcast_packets", offsetof(struct e1000_hw_stats, bprc)},
427 {"rx_multicast_packets", offsetof(struct e1000_hw_stats, mprc)},
428 {"rx_undersize_errors", offsetof(struct e1000_hw_stats, ruc)},
429 {"rx_fragment_errors", offsetof(struct e1000_hw_stats, rfc)},
430 {"rx_oversize_errors", offsetof(struct e1000_hw_stats, roc)},
431 {"rx_jabber_errors", offsetof(struct e1000_hw_stats, rjc)},
432 {"rx_management_packets", offsetof(struct e1000_hw_stats, mgprc)},
433 {"rx_management_dropped", offsetof(struct e1000_hw_stats, mgpdc)},
434 {"tx_management_packets", offsetof(struct e1000_hw_stats, mgptc)},
435 {"rx_total_packets", offsetof(struct e1000_hw_stats, tpr)},
436 {"tx_total_packets", offsetof(struct e1000_hw_stats, tpt)},
437 {"rx_total_bytes", offsetof(struct e1000_hw_stats, tor)},
438 {"tx_total_bytes", offsetof(struct e1000_hw_stats, tot)},
439 {"tx_size_64_packets", offsetof(struct e1000_hw_stats, ptc64)},
440 {"tx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, ptc127)},
441 {"tx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, ptc255)},
442 {"tx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, ptc511)},
443 {"tx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
445 {"tx_size_1023_to_max_packets", offsetof(struct e1000_hw_stats,
447 {"tx_multicast_packets", offsetof(struct e1000_hw_stats, mptc)},
448 {"tx_broadcast_packets", offsetof(struct e1000_hw_stats, bptc)},
449 {"tx_tso_packets", offsetof(struct e1000_hw_stats, tsctc)},
450 {"tx_tso_errors", offsetof(struct e1000_hw_stats, tsctfc)},
451 {"rx_sent_to_host_packets", offsetof(struct e1000_hw_stats, rpthc)},
452 {"tx_sent_by_host_packets", offsetof(struct e1000_hw_stats, hgptc)},
453 {"rx_code_violation_packets", offsetof(struct e1000_hw_stats, scvpc)},
455 {"interrupt_assert_count", offsetof(struct e1000_hw_stats, iac)},
458 #define IGB_NB_XSTATS (sizeof(rte_igb_stats_strings) / \
459 sizeof(rte_igb_stats_strings[0]))
461 static const struct rte_igb_xstats_name_off rte_igbvf_stats_strings[] = {
462 {"rx_multicast_packets", offsetof(struct e1000_vf_stats, mprc)},
463 {"rx_good_loopback_packets", offsetof(struct e1000_vf_stats, gprlbc)},
464 {"tx_good_loopback_packets", offsetof(struct e1000_vf_stats, gptlbc)},
465 {"rx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gorlbc)},
466 {"tx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gotlbc)},
469 #define IGBVF_NB_XSTATS (sizeof(rte_igbvf_stats_strings) / \
470 sizeof(rte_igbvf_stats_strings[0]))
473 * Atomically reads the link status information from global
474 * structure rte_eth_dev.
477 * - Pointer to the structure rte_eth_dev to read from.
478 * - Pointer to the buffer to be saved with the link status.
481 * - On success, zero.
482 * - On failure, negative value.
485 rte_igb_dev_atomic_read_link_status(struct rte_eth_dev *dev,
486 struct rte_eth_link *link)
488 struct rte_eth_link *dst = link;
489 struct rte_eth_link *src = &(dev->data->dev_link);
491 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
492 *(uint64_t *)src) == 0)
499 * Atomically writes the link status information into global
500 * structure rte_eth_dev.
503 * - Pointer to the structure rte_eth_dev to read from.
504 * - Pointer to the buffer to be saved with the link status.
507 * - On success, zero.
508 * - On failure, negative value.
511 rte_igb_dev_atomic_write_link_status(struct rte_eth_dev *dev,
512 struct rte_eth_link *link)
514 struct rte_eth_link *dst = &(dev->data->dev_link);
515 struct rte_eth_link *src = link;
517 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
518 *(uint64_t *)src) == 0)
525 igb_intr_enable(struct rte_eth_dev *dev)
527 struct e1000_interrupt *intr =
528 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
529 struct e1000_hw *hw =
530 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
532 E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
533 E1000_WRITE_FLUSH(hw);
537 igb_intr_disable(struct e1000_hw *hw)
539 E1000_WRITE_REG(hw, E1000_IMC, ~0);
540 E1000_WRITE_FLUSH(hw);
543 static inline int32_t
544 igb_pf_reset_hw(struct e1000_hw *hw)
549 status = e1000_reset_hw(hw);
551 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
552 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
553 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
554 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
555 E1000_WRITE_FLUSH(hw);
561 igb_identify_hardware(struct rte_eth_dev *dev)
563 struct e1000_hw *hw =
564 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
566 hw->vendor_id = dev->pci_dev->id.vendor_id;
567 hw->device_id = dev->pci_dev->id.device_id;
568 hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
569 hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
571 e1000_set_mac_type(hw);
573 /* need to check if it is a vf device below */
577 igb_reset_swfw_lock(struct e1000_hw *hw)
582 * Do mac ops initialization manually here, since we will need
583 * some function pointers set by this call.
585 ret_val = e1000_init_mac_params(hw);
590 * SMBI lock should not fail in this early stage. If this is the case,
591 * it is due to an improper exit of the application.
592 * So force the release of the faulty lock.
594 if (e1000_get_hw_semaphore_generic(hw) < 0) {
595 PMD_DRV_LOG(DEBUG, "SMBI lock released");
597 e1000_put_hw_semaphore_generic(hw);
599 if (hw->mac.ops.acquire_swfw_sync != NULL) {
603 * Phy lock should not fail in this early stage. If this is the case,
604 * it is due to an improper exit of the application.
605 * So force the release of the faulty lock.
607 mask = E1000_SWFW_PHY0_SM << hw->bus.func;
608 if (hw->bus.func > E1000_FUNC_1)
610 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
611 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
614 hw->mac.ops.release_swfw_sync(hw, mask);
617 * This one is more tricky since it is common to all ports; but
618 * swfw_sync retries last long enough (1s) to be almost sure that if
619 * lock can not be taken it is due to an improper lock of the
622 mask = E1000_SWFW_EEP_SM;
623 if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
624 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
626 hw->mac.ops.release_swfw_sync(hw, mask);
629 return E1000_SUCCESS;
633 eth_igb_dev_init(struct rte_eth_dev *eth_dev)
636 struct rte_pci_device *pci_dev;
637 struct e1000_hw *hw =
638 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
639 struct e1000_vfta * shadow_vfta =
640 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
641 struct e1000_filter_info *filter_info =
642 E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
643 struct e1000_adapter *adapter =
644 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
648 pci_dev = eth_dev->pci_dev;
650 eth_dev->dev_ops = ð_igb_ops;
651 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
652 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
654 /* for secondary processes, we don't initialise any further as primary
655 * has already done this work. Only check we don't need a different
657 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
658 if (eth_dev->data->scattered_rx)
659 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
663 rte_eth_copy_pci_info(eth_dev, pci_dev);
665 hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
667 igb_identify_hardware(eth_dev);
668 if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
673 e1000_get_bus_info(hw);
675 /* Reset any pending lock */
676 if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
681 /* Finish initialization */
682 if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
688 hw->phy.autoneg_wait_to_complete = 0;
689 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
692 if (hw->phy.media_type == e1000_media_type_copper) {
693 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
694 hw->phy.disable_polarity_correction = 0;
695 hw->phy.ms_type = e1000_ms_hw_default;
699 * Start from a known state, this is important in reading the nvm
704 /* Make sure we have a good EEPROM before we read from it */
705 if (e1000_validate_nvm_checksum(hw) < 0) {
707 * Some PCI-E parts fail the first check due to
708 * the link being in sleep state, call it again,
709 * if it fails a second time its a real issue.
711 if (e1000_validate_nvm_checksum(hw) < 0) {
712 PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
718 /* Read the permanent MAC address out of the EEPROM */
719 if (e1000_read_mac_addr(hw) != 0) {
720 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
725 /* Allocate memory for storing MAC addresses */
726 eth_dev->data->mac_addrs = rte_zmalloc("e1000",
727 ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
728 if (eth_dev->data->mac_addrs == NULL) {
729 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
730 "store MAC addresses",
731 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
736 /* Copy the permanent MAC address */
737 ether_addr_copy((struct ether_addr *)hw->mac.addr, ð_dev->data->mac_addrs[0]);
739 /* initialize the vfta */
740 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
742 /* Now initialize the hardware */
743 if (igb_hardware_init(hw) != 0) {
744 PMD_INIT_LOG(ERR, "Hardware initialization failed");
745 rte_free(eth_dev->data->mac_addrs);
746 eth_dev->data->mac_addrs = NULL;
750 hw->mac.get_link_status = 1;
751 adapter->stopped = 0;
753 /* Indicate SOL/IDER usage */
754 if (e1000_check_reset_block(hw) < 0) {
755 PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
759 /* initialize PF if max_vfs not zero */
760 igb_pf_host_init(eth_dev);
762 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
763 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
764 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
765 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
766 E1000_WRITE_FLUSH(hw);
768 PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
769 eth_dev->data->port_id, pci_dev->id.vendor_id,
770 pci_dev->id.device_id);
772 rte_intr_callback_register(&pci_dev->intr_handle,
773 eth_igb_interrupt_handler,
776 /* enable uio/vfio intr/eventfd mapping */
777 rte_intr_enable(&pci_dev->intr_handle);
779 /* enable support intr */
780 igb_intr_enable(eth_dev);
782 TAILQ_INIT(&filter_info->flex_list);
783 filter_info->flex_mask = 0;
784 TAILQ_INIT(&filter_info->twotuple_list);
785 filter_info->twotuple_mask = 0;
786 TAILQ_INIT(&filter_info->fivetuple_list);
787 filter_info->fivetuple_mask = 0;
792 igb_hw_control_release(hw);
798 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
800 struct rte_pci_device *pci_dev;
802 struct e1000_adapter *adapter =
803 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
805 PMD_INIT_FUNC_TRACE();
807 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
810 hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
811 pci_dev = eth_dev->pci_dev;
813 if (adapter->stopped == 0)
814 eth_igb_close(eth_dev);
816 eth_dev->dev_ops = NULL;
817 eth_dev->rx_pkt_burst = NULL;
818 eth_dev->tx_pkt_burst = NULL;
820 /* Reset any pending lock */
821 igb_reset_swfw_lock(hw);
823 rte_free(eth_dev->data->mac_addrs);
824 eth_dev->data->mac_addrs = NULL;
826 /* uninitialize PF if max_vfs not zero */
827 igb_pf_host_uninit(eth_dev);
829 /* disable uio intr before callback unregister */
830 rte_intr_disable(&(pci_dev->intr_handle));
831 rte_intr_callback_unregister(&(pci_dev->intr_handle),
832 eth_igb_interrupt_handler, (void *)eth_dev);
838 * Virtual Function device init
841 eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
843 struct rte_pci_device *pci_dev;
844 struct e1000_adapter *adapter =
845 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
846 struct e1000_hw *hw =
847 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
850 PMD_INIT_FUNC_TRACE();
852 eth_dev->dev_ops = &igbvf_eth_dev_ops;
853 eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
854 eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
856 /* for secondary processes, we don't initialise any further as primary
857 * has already done this work. Only check we don't need a different
859 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
860 if (eth_dev->data->scattered_rx)
861 eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
865 pci_dev = eth_dev->pci_dev;
867 rte_eth_copy_pci_info(eth_dev, pci_dev);
869 hw->device_id = pci_dev->id.device_id;
870 hw->vendor_id = pci_dev->id.vendor_id;
871 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
872 adapter->stopped = 0;
874 /* Initialize the shared code (base driver) */
875 diag = e1000_setup_init_funcs(hw, TRUE);
877 PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
882 /* init_mailbox_params */
883 hw->mbx.ops.init_params(hw);
885 /* Disable the interrupts for VF */
886 igbvf_intr_disable(hw);
888 diag = hw->mac.ops.reset_hw(hw);
890 /* Allocate memory for storing MAC addresses */
891 eth_dev->data->mac_addrs = rte_zmalloc("igbvf", ETHER_ADDR_LEN *
892 hw->mac.rar_entry_count, 0);
893 if (eth_dev->data->mac_addrs == NULL) {
895 "Failed to allocate %d bytes needed to store MAC "
897 ETHER_ADDR_LEN * hw->mac.rar_entry_count);
901 /* Copy the permanent MAC address */
902 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
903 ð_dev->data->mac_addrs[0]);
905 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
907 eth_dev->data->port_id, pci_dev->id.vendor_id,
908 pci_dev->id.device_id, "igb_mac_82576_vf");
914 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
916 struct e1000_adapter *adapter =
917 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
919 PMD_INIT_FUNC_TRACE();
921 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
924 if (adapter->stopped == 0)
925 igbvf_dev_close(eth_dev);
927 eth_dev->dev_ops = NULL;
928 eth_dev->rx_pkt_burst = NULL;
929 eth_dev->tx_pkt_burst = NULL;
931 rte_free(eth_dev->data->mac_addrs);
932 eth_dev->data->mac_addrs = NULL;
937 static struct eth_driver rte_igb_pmd = {
939 .name = "rte_igb_pmd",
940 .id_table = pci_id_igb_map,
941 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
942 RTE_PCI_DRV_DETACHABLE,
944 .eth_dev_init = eth_igb_dev_init,
945 .eth_dev_uninit = eth_igb_dev_uninit,
946 .dev_private_size = sizeof(struct e1000_adapter),
950 * virtual function driver struct
952 static struct eth_driver rte_igbvf_pmd = {
954 .name = "rte_igbvf_pmd",
955 .id_table = pci_id_igbvf_map,
956 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_DETACHABLE,
958 .eth_dev_init = eth_igbvf_dev_init,
959 .eth_dev_uninit = eth_igbvf_dev_uninit,
960 .dev_private_size = sizeof(struct e1000_adapter),
964 rte_igb_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
966 rte_eth_driver_register(&rte_igb_pmd);
971 igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
973 struct e1000_hw *hw =
974 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
975 /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
976 uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
977 rctl |= E1000_RCTL_VFE;
978 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
982 * VF Driver initialization routine.
983 * Invoked one at EAL init time.
984 * Register itself as the [Virtual Poll Mode] Driver of PCI IGB devices.
987 rte_igbvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
989 PMD_INIT_FUNC_TRACE();
991 rte_eth_driver_register(&rte_igbvf_pmd);
996 igb_check_mq_mode(struct rte_eth_dev *dev)
998 enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
999 enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
1000 uint16_t nb_rx_q = dev->data->nb_rx_queues;
1001 uint16_t nb_tx_q = dev->data->nb_rx_queues;
1003 if ((rx_mq_mode & ETH_MQ_RX_DCB_FLAG) ||
1004 tx_mq_mode == ETH_MQ_TX_DCB ||
1005 tx_mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1006 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
1009 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
1010 /* Check multi-queue mode.
1011 * To no break software we accept ETH_MQ_RX_NONE as this might
1012 * be used to turn off VLAN filter.
1015 if (rx_mq_mode == ETH_MQ_RX_NONE ||
1016 rx_mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1017 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
1018 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
1020 /* Only support one queue on VFs.
1021 * RSS together with SRIOV is not supported.
1023 PMD_INIT_LOG(ERR, "SRIOV is active,"
1024 " wrong mq_mode rx %d.",
1028 /* TX mode is not used here, so mode might be ignored.*/
1029 if (tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1030 /* SRIOV only works in VMDq enable mode */
1031 PMD_INIT_LOG(WARNING, "SRIOV is active,"
1032 " TX mode %d is not supported. "
1033 " Driver will behave as %d mode.",
1034 tx_mq_mode, ETH_MQ_TX_VMDQ_ONLY);
1037 /* check valid queue number */
1038 if ((nb_rx_q > 1) || (nb_tx_q > 1)) {
1039 PMD_INIT_LOG(ERR, "SRIOV is active,"
1040 " only support one queue on VFs.");
1044 /* To no break software that set invalid mode, only display
1045 * warning if invalid mode is used.
1047 if (rx_mq_mode != ETH_MQ_RX_NONE &&
1048 rx_mq_mode != ETH_MQ_RX_VMDQ_ONLY &&
1049 rx_mq_mode != ETH_MQ_RX_RSS) {
1050 /* RSS together with VMDq not supported*/
1051 PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
1056 if (tx_mq_mode != ETH_MQ_TX_NONE &&
1057 tx_mq_mode != ETH_MQ_TX_VMDQ_ONLY) {
1058 PMD_INIT_LOG(WARNING, "TX mode %d is not supported."
1059 " Due to txmode is meaningless in this"
1060 " driver, just ignore.",
1068 eth_igb_configure(struct rte_eth_dev *dev)
1070 struct e1000_interrupt *intr =
1071 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1074 PMD_INIT_FUNC_TRACE();
1076 /* multipe queue mode checking */
1077 ret = igb_check_mq_mode(dev);
1079 PMD_DRV_LOG(ERR, "igb_check_mq_mode fails with %d.",
1084 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1085 PMD_INIT_FUNC_TRACE();
1091 eth_igb_start(struct rte_eth_dev *dev)
1093 struct e1000_hw *hw =
1094 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1095 struct e1000_adapter *adapter =
1096 E1000_DEV_PRIVATE(dev->data->dev_private);
1097 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1099 uint32_t intr_vector = 0;
1102 PMD_INIT_FUNC_TRACE();
1104 /* Power up the phy. Needed to make the link go Up */
1105 e1000_power_up_phy(hw);
1108 * Packet Buffer Allocation (PBA)
1109 * Writing PBA sets the receive portion of the buffer
1110 * the remainder is used for the transmit buffer.
1112 if (hw->mac.type == e1000_82575) {
1115 pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
1116 E1000_WRITE_REG(hw, E1000_PBA, pba);
1119 /* Put the address into the Receive Address Array */
1120 e1000_rar_set(hw, hw->mac.addr, 0);
1122 /* Initialize the hardware */
1123 if (igb_hardware_init(hw)) {
1124 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
1127 adapter->stopped = 0;
1129 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1131 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1132 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1133 ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
1134 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1135 E1000_WRITE_FLUSH(hw);
1137 /* configure PF module if SRIOV enabled */
1138 igb_pf_host_configure(dev);
1140 /* check and configure queue intr-vector mapping */
1141 if ((rte_intr_cap_multiple(intr_handle) ||
1142 !RTE_ETH_DEV_SRIOV(dev).active) &&
1143 dev->data->dev_conf.intr_conf.rxq != 0) {
1144 intr_vector = dev->data->nb_rx_queues;
1145 if (rte_intr_efd_enable(intr_handle, intr_vector))
1149 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1150 intr_handle->intr_vec =
1151 rte_zmalloc("intr_vec",
1152 dev->data->nb_rx_queues * sizeof(int), 0);
1153 if (intr_handle->intr_vec == NULL) {
1154 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1155 " intr_vec\n", dev->data->nb_rx_queues);
1160 /* confiugre msix for rx interrupt */
1161 eth_igb_configure_msix_intr(dev);
1163 /* Configure for OS presence */
1164 igb_init_manageability(hw);
1166 eth_igb_tx_init(dev);
1168 /* This can fail when allocating mbufs for descriptor rings */
1169 ret = eth_igb_rx_init(dev);
1171 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1172 igb_dev_clear_queues(dev);
1176 e1000_clear_hw_cntrs_base_generic(hw);
1179 * VLAN Offload Settings
1181 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
1182 ETH_VLAN_EXTEND_MASK;
1183 eth_igb_vlan_offload_set(dev, mask);
1185 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1186 /* Enable VLAN filter since VMDq always use VLAN filter */
1187 igb_vmdq_vlan_hw_filter_enable(dev);
1190 if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
1191 (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
1192 (hw->mac.type == e1000_i211)) {
1193 /* Configure EITR with the maximum possible value (0xFFFF) */
1194 E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
1197 /* Setup link speed and duplex */
1198 switch (dev->data->dev_conf.link_speed) {
1199 case ETH_LINK_SPEED_AUTONEG:
1200 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
1201 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
1202 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
1203 hw->phy.autoneg_advertised = E1000_ALL_HALF_DUPLEX;
1204 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
1205 hw->phy.autoneg_advertised = E1000_ALL_FULL_DUPLEX;
1207 goto error_invalid_config;
1209 case ETH_LINK_SPEED_10:
1210 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
1211 hw->phy.autoneg_advertised = E1000_ALL_10_SPEED;
1212 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
1213 hw->phy.autoneg_advertised = ADVERTISE_10_HALF;
1214 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
1215 hw->phy.autoneg_advertised = ADVERTISE_10_FULL;
1217 goto error_invalid_config;
1219 case ETH_LINK_SPEED_100:
1220 if (dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX)
1221 hw->phy.autoneg_advertised = E1000_ALL_100_SPEED;
1222 else if (dev->data->dev_conf.link_duplex == ETH_LINK_HALF_DUPLEX)
1223 hw->phy.autoneg_advertised = ADVERTISE_100_HALF;
1224 else if (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX)
1225 hw->phy.autoneg_advertised = ADVERTISE_100_FULL;
1227 goto error_invalid_config;
1229 case ETH_LINK_SPEED_1000:
1230 if ((dev->data->dev_conf.link_duplex == ETH_LINK_AUTONEG_DUPLEX) ||
1231 (dev->data->dev_conf.link_duplex == ETH_LINK_FULL_DUPLEX))
1232 hw->phy.autoneg_advertised = ADVERTISE_1000_FULL;
1234 goto error_invalid_config;
1236 case ETH_LINK_SPEED_10000:
1238 goto error_invalid_config;
1240 e1000_setup_link(hw);
1242 if (rte_intr_allow_others(intr_handle)) {
1243 /* check if lsc interrupt is enabled */
1244 if (dev->data->dev_conf.intr_conf.lsc != 0)
1245 eth_igb_lsc_interrupt_setup(dev);
1247 rte_intr_callback_unregister(intr_handle,
1248 eth_igb_interrupt_handler,
1250 if (dev->data->dev_conf.intr_conf.lsc != 0)
1251 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1252 " no intr multiplex\n");
1255 /* check if rxq interrupt is enabled */
1256 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1257 rte_intr_dp_is_en(intr_handle))
1258 eth_igb_rxq_interrupt_setup(dev);
1260 /* enable uio/vfio intr/eventfd mapping */
1261 rte_intr_enable(intr_handle);
1263 /* resume enabled intr since hw reset */
1264 igb_intr_enable(dev);
1266 PMD_INIT_LOG(DEBUG, "<<");
1270 error_invalid_config:
1271 PMD_INIT_LOG(ERR, "Invalid link_speed/link_duplex (%u/%u) for port %u",
1272 dev->data->dev_conf.link_speed,
1273 dev->data->dev_conf.link_duplex, dev->data->port_id);
1274 igb_dev_clear_queues(dev);
1278 /*********************************************************************
1280 * This routine disables all traffic on the adapter by issuing a
1281 * global reset on the MAC.
1283 **********************************************************************/
1285 eth_igb_stop(struct rte_eth_dev *dev)
1287 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1288 struct e1000_filter_info *filter_info =
1289 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1290 struct rte_eth_link link;
1291 struct e1000_flex_filter *p_flex;
1292 struct e1000_5tuple_filter *p_5tuple, *p_5tuple_next;
1293 struct e1000_2tuple_filter *p_2tuple, *p_2tuple_next;
1294 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1296 igb_intr_disable(hw);
1298 /* disable intr eventfd mapping */
1299 rte_intr_disable(intr_handle);
1301 igb_pf_reset_hw(hw);
1302 E1000_WRITE_REG(hw, E1000_WUC, 0);
1304 /* Set bit for Go Link disconnect */
1305 if (hw->mac.type >= e1000_82580) {
1308 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1309 phpm_reg |= E1000_82580_PM_GO_LINKD;
1310 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1313 /* Power down the phy. Needed to make the link go Down */
1314 if (hw->phy.media_type == e1000_media_type_copper)
1315 e1000_power_down_phy(hw);
1317 e1000_shutdown_fiber_serdes_link(hw);
1319 igb_dev_clear_queues(dev);
1321 /* clear the recorded link status */
1322 memset(&link, 0, sizeof(link));
1323 rte_igb_dev_atomic_write_link_status(dev, &link);
1325 /* Remove all flex filters of the device */
1326 while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
1327 TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
1330 filter_info->flex_mask = 0;
1332 /* Remove all ntuple filters of the device */
1333 for (p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list);
1334 p_5tuple != NULL; p_5tuple = p_5tuple_next) {
1335 p_5tuple_next = TAILQ_NEXT(p_5tuple, entries);
1336 TAILQ_REMOVE(&filter_info->fivetuple_list,
1340 filter_info->fivetuple_mask = 0;
1341 for (p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list);
1342 p_2tuple != NULL; p_2tuple = p_2tuple_next) {
1343 p_2tuple_next = TAILQ_NEXT(p_2tuple, entries);
1344 TAILQ_REMOVE(&filter_info->twotuple_list,
1348 filter_info->twotuple_mask = 0;
1350 if (!rte_intr_allow_others(intr_handle))
1351 /* resume to the default handler */
1352 rte_intr_callback_register(intr_handle,
1353 eth_igb_interrupt_handler,
1356 /* Clean datapath event and queue/vec mapping */
1357 rte_intr_efd_disable(intr_handle);
1358 if (intr_handle->intr_vec != NULL) {
1359 rte_free(intr_handle->intr_vec);
1360 intr_handle->intr_vec = NULL;
1365 eth_igb_close(struct rte_eth_dev *dev)
1367 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1368 struct e1000_adapter *adapter =
1369 E1000_DEV_PRIVATE(dev->data->dev_private);
1370 struct rte_eth_link link;
1371 struct rte_pci_device *pci_dev;
1374 adapter->stopped = 1;
1376 e1000_phy_hw_reset(hw);
1377 igb_release_manageability(hw);
1378 igb_hw_control_release(hw);
1380 /* Clear bit for Go Link disconnect */
1381 if (hw->mac.type >= e1000_82580) {
1384 phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1385 phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1386 E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1389 igb_dev_free_queues(dev);
1391 pci_dev = dev->pci_dev;
1392 if (pci_dev->intr_handle.intr_vec) {
1393 rte_free(pci_dev->intr_handle.intr_vec);
1394 pci_dev->intr_handle.intr_vec = NULL;
1397 memset(&link, 0, sizeof(link));
1398 rte_igb_dev_atomic_write_link_status(dev, &link);
1402 igb_get_rx_buffer_size(struct e1000_hw *hw)
1404 uint32_t rx_buf_size;
1405 if (hw->mac.type == e1000_82576) {
1406 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1407 } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1408 /* PBS needs to be translated according to a lookup table */
1409 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1410 rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1411 rx_buf_size = (rx_buf_size << 10);
1412 } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1413 rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1415 rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1421 /*********************************************************************
1423 * Initialize the hardware
1425 **********************************************************************/
1427 igb_hardware_init(struct e1000_hw *hw)
1429 uint32_t rx_buf_size;
1432 /* Let the firmware know the OS is in control */
1433 igb_hw_control_acquire(hw);
1436 * These parameters control the automatic generation (Tx) and
1437 * response (Rx) to Ethernet PAUSE frames.
1438 * - High water mark should allow for at least two standard size (1518)
1439 * frames to be received after sending an XOFF.
1440 * - Low water mark works best when it is very near the high water mark.
1441 * This allows the receiver to restart by sending XON when it has
1442 * drained a bit. Here we use an arbitrary value of 1500 which will
1443 * restart after one full frame is pulled from the buffer. There
1444 * could be several smaller frames in the buffer and if so they will
1445 * not trigger the XON until their total number reduces the buffer
1447 * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1449 rx_buf_size = igb_get_rx_buffer_size(hw);
1451 hw->fc.high_water = rx_buf_size - (ETHER_MAX_LEN * 2);
1452 hw->fc.low_water = hw->fc.high_water - 1500;
1453 hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1454 hw->fc.send_xon = 1;
1456 /* Set Flow control, use the tunable location if sane */
1457 if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1458 hw->fc.requested_mode = igb_fc_setting;
1460 hw->fc.requested_mode = e1000_fc_none;
1462 /* Issue a global reset */
1463 igb_pf_reset_hw(hw);
1464 E1000_WRITE_REG(hw, E1000_WUC, 0);
1466 diag = e1000_init_hw(hw);
1470 E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN << 16 | ETHER_TYPE_VLAN);
1471 e1000_get_phy_info(hw);
1472 e1000_check_for_link(hw);
1477 /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1479 igb_read_stats_registers(struct e1000_hw *hw, struct e1000_hw_stats *stats)
1483 uint64_t old_gprc = stats->gprc;
1484 uint64_t old_gptc = stats->gptc;
1485 uint64_t old_tpr = stats->tpr;
1486 uint64_t old_tpt = stats->tpt;
1487 uint64_t old_rpthc = stats->rpthc;
1488 uint64_t old_hgptc = stats->hgptc;
1490 if(hw->phy.media_type == e1000_media_type_copper ||
1491 (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1493 E1000_READ_REG(hw,E1000_SYMERRS);
1494 stats->sec += E1000_READ_REG(hw, E1000_SEC);
1497 stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1498 stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1499 stats->scc += E1000_READ_REG(hw, E1000_SCC);
1500 stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1502 stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1503 stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1504 stats->colc += E1000_READ_REG(hw, E1000_COLC);
1505 stats->dc += E1000_READ_REG(hw, E1000_DC);
1506 stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1507 stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1508 stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1510 ** For watchdog management we need to know if we have been
1511 ** paused during the last interval, so capture that here.
1513 pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1514 stats->xoffrxc += pause_frames;
1515 stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1516 stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1517 stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1518 stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1519 stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1520 stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1521 stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1522 stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1523 stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1524 stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1525 stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1526 stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1528 /* For the 64-bit byte counters the low dword must be read first. */
1529 /* Both registers clear on the read of the high dword */
1531 /* Workaround CRC bytes included in size, take away 4 bytes/packet */
1532 stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1533 stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1534 stats->gorc -= (stats->gprc - old_gprc) * ETHER_CRC_LEN;
1535 stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1536 stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1537 stats->gotc -= (stats->gptc - old_gptc) * ETHER_CRC_LEN;
1539 stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1540 stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1541 stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1542 stats->roc += E1000_READ_REG(hw, E1000_ROC);
1543 stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1545 stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1546 stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1548 stats->tor += E1000_READ_REG(hw, E1000_TORL);
1549 stats->tor += ((uint64_t)E1000_READ_REG(hw, E1000_TORH) << 32);
1550 stats->tor -= (stats->tpr - old_tpr) * ETHER_CRC_LEN;
1551 stats->tot += E1000_READ_REG(hw, E1000_TOTL);
1552 stats->tot += ((uint64_t)E1000_READ_REG(hw, E1000_TOTH) << 32);
1553 stats->tot -= (stats->tpt - old_tpt) * ETHER_CRC_LEN;
1555 stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1556 stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1557 stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1558 stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1559 stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1560 stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1561 stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1562 stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1564 /* Interrupt Counts */
1566 stats->iac += E1000_READ_REG(hw, E1000_IAC);
1567 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1568 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1569 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1570 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1571 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1572 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1573 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1574 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1576 /* Host to Card Statistics */
1578 stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1579 stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1580 stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1581 stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1582 stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1583 stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1584 stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1585 stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1586 stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1587 stats->hgorc -= (stats->rpthc - old_rpthc) * ETHER_CRC_LEN;
1588 stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1589 stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1590 stats->hgotc -= (stats->hgptc - old_hgptc) * ETHER_CRC_LEN;
1591 stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1592 stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1593 stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1595 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1596 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1597 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1598 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1599 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1600 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1604 eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1606 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1607 struct e1000_hw_stats *stats =
1608 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1610 igb_read_stats_registers(hw, stats);
1612 if (rte_stats == NULL)
1616 rte_stats->imissed = stats->mpc;
1617 rte_stats->ierrors = stats->crcerrs +
1618 stats->rlec + stats->ruc + stats->roc +
1619 rte_stats->imissed +
1620 stats->rxerrc + stats->algnerrc + stats->cexterr;
1623 rte_stats->oerrors = stats->ecol + stats->latecol;
1625 rte_stats->ipackets = stats->gprc;
1626 rte_stats->opackets = stats->gptc;
1627 rte_stats->ibytes = stats->gorc;
1628 rte_stats->obytes = stats->gotc;
1632 eth_igb_stats_reset(struct rte_eth_dev *dev)
1634 struct e1000_hw_stats *hw_stats =
1635 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1637 /* HW registers are cleared on read */
1638 eth_igb_stats_get(dev, NULL);
1640 /* Reset software totals */
1641 memset(hw_stats, 0, sizeof(*hw_stats));
1645 eth_igb_xstats_reset(struct rte_eth_dev *dev)
1647 struct e1000_hw_stats *stats =
1648 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1650 /* HW registers are cleared on read */
1651 eth_igb_xstats_get(dev, NULL, IGB_NB_XSTATS);
1653 /* Reset software totals */
1654 memset(stats, 0, sizeof(*stats));
1658 eth_igb_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
1661 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1662 struct e1000_hw_stats *hw_stats =
1663 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1666 if (n < IGB_NB_XSTATS)
1667 return IGB_NB_XSTATS;
1669 igb_read_stats_registers(hw, hw_stats);
1671 /* If this is a reset xstats is NULL, and we have cleared the
1672 * registers by reading them.
1677 /* Extended stats */
1678 for (i = 0; i < IGB_NB_XSTATS; i++) {
1679 snprintf(xstats[i].name, sizeof(xstats[i].name),
1680 "%s", rte_igb_stats_strings[i].name);
1681 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
1682 rte_igb_stats_strings[i].offset);
1685 return IGB_NB_XSTATS;
1689 igbvf_read_stats_registers(struct e1000_hw *hw, struct e1000_vf_stats *hw_stats)
1691 /* Good Rx packets, include VF loopback */
1692 UPDATE_VF_STAT(E1000_VFGPRC,
1693 hw_stats->last_gprc, hw_stats->gprc);
1695 /* Good Rx octets, include VF loopback */
1696 UPDATE_VF_STAT(E1000_VFGORC,
1697 hw_stats->last_gorc, hw_stats->gorc);
1699 /* Good Tx packets, include VF loopback */
1700 UPDATE_VF_STAT(E1000_VFGPTC,
1701 hw_stats->last_gptc, hw_stats->gptc);
1703 /* Good Tx octets, include VF loopback */
1704 UPDATE_VF_STAT(E1000_VFGOTC,
1705 hw_stats->last_gotc, hw_stats->gotc);
1707 /* Rx Multicst packets */
1708 UPDATE_VF_STAT(E1000_VFMPRC,
1709 hw_stats->last_mprc, hw_stats->mprc);
1711 /* Good Rx loopback packets */
1712 UPDATE_VF_STAT(E1000_VFGPRLBC,
1713 hw_stats->last_gprlbc, hw_stats->gprlbc);
1715 /* Good Rx loopback octets */
1716 UPDATE_VF_STAT(E1000_VFGORLBC,
1717 hw_stats->last_gorlbc, hw_stats->gorlbc);
1719 /* Good Tx loopback packets */
1720 UPDATE_VF_STAT(E1000_VFGPTLBC,
1721 hw_stats->last_gptlbc, hw_stats->gptlbc);
1723 /* Good Tx loopback octets */
1724 UPDATE_VF_STAT(E1000_VFGOTLBC,
1725 hw_stats->last_gotlbc, hw_stats->gotlbc);
1729 eth_igbvf_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
1732 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1733 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
1734 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1737 if (n < IGBVF_NB_XSTATS)
1738 return IGBVF_NB_XSTATS;
1740 igbvf_read_stats_registers(hw, hw_stats);
1745 for (i = 0; i < IGBVF_NB_XSTATS; i++) {
1746 snprintf(xstats[i].name, sizeof(xstats[i].name), "%s",
1747 rte_igbvf_stats_strings[i].name);
1748 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
1749 rte_igbvf_stats_strings[i].offset);
1752 return IGBVF_NB_XSTATS;
1756 eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1758 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1759 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
1760 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1762 igbvf_read_stats_registers(hw, hw_stats);
1764 if (rte_stats == NULL)
1767 rte_stats->ipackets = hw_stats->gprc;
1768 rte_stats->ibytes = hw_stats->gorc;
1769 rte_stats->opackets = hw_stats->gptc;
1770 rte_stats->obytes = hw_stats->gotc;
1771 rte_stats->imcasts = hw_stats->mprc;
1772 rte_stats->ilbpackets = hw_stats->gprlbc;
1773 rte_stats->ilbbytes = hw_stats->gorlbc;
1774 rte_stats->olbpackets = hw_stats->gptlbc;
1775 rte_stats->olbbytes = hw_stats->gotlbc;
1779 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
1781 struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
1782 E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1784 /* Sync HW register to the last stats */
1785 eth_igbvf_stats_get(dev, NULL);
1787 /* reset HW current stats*/
1788 memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
1789 offsetof(struct e1000_vf_stats, gprc));
1793 eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1795 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1797 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1798 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
1799 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1800 dev_info->rx_offload_capa =
1801 DEV_RX_OFFLOAD_VLAN_STRIP |
1802 DEV_RX_OFFLOAD_IPV4_CKSUM |
1803 DEV_RX_OFFLOAD_UDP_CKSUM |
1804 DEV_RX_OFFLOAD_TCP_CKSUM;
1805 dev_info->tx_offload_capa =
1806 DEV_TX_OFFLOAD_VLAN_INSERT |
1807 DEV_TX_OFFLOAD_IPV4_CKSUM |
1808 DEV_TX_OFFLOAD_UDP_CKSUM |
1809 DEV_TX_OFFLOAD_TCP_CKSUM |
1810 DEV_TX_OFFLOAD_SCTP_CKSUM |
1811 DEV_TX_OFFLOAD_TCP_TSO;
1813 switch (hw->mac.type) {
1815 dev_info->max_rx_queues = 4;
1816 dev_info->max_tx_queues = 4;
1817 dev_info->max_vmdq_pools = 0;
1821 dev_info->max_rx_queues = 16;
1822 dev_info->max_tx_queues = 16;
1823 dev_info->max_vmdq_pools = ETH_8_POOLS;
1824 dev_info->vmdq_queue_num = 16;
1828 dev_info->max_rx_queues = 8;
1829 dev_info->max_tx_queues = 8;
1830 dev_info->max_vmdq_pools = ETH_8_POOLS;
1831 dev_info->vmdq_queue_num = 8;
1835 dev_info->max_rx_queues = 8;
1836 dev_info->max_tx_queues = 8;
1837 dev_info->max_vmdq_pools = ETH_8_POOLS;
1838 dev_info->vmdq_queue_num = 8;
1842 dev_info->max_rx_queues = 8;
1843 dev_info->max_tx_queues = 8;
1847 dev_info->max_rx_queues = 4;
1848 dev_info->max_tx_queues = 4;
1849 dev_info->max_vmdq_pools = 0;
1853 dev_info->max_rx_queues = 2;
1854 dev_info->max_tx_queues = 2;
1855 dev_info->max_vmdq_pools = 0;
1859 /* Should not happen */
1862 dev_info->hash_key_size = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
1863 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
1864 dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
1866 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1868 .pthresh = IGB_DEFAULT_RX_PTHRESH,
1869 .hthresh = IGB_DEFAULT_RX_HTHRESH,
1870 .wthresh = IGB_DEFAULT_RX_WTHRESH,
1872 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
1876 dev_info->default_txconf = (struct rte_eth_txconf) {
1878 .pthresh = IGB_DEFAULT_TX_PTHRESH,
1879 .hthresh = IGB_DEFAULT_TX_HTHRESH,
1880 .wthresh = IGB_DEFAULT_TX_WTHRESH,
1885 dev_info->rx_desc_lim = rx_desc_lim;
1886 dev_info->tx_desc_lim = tx_desc_lim;
1890 eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1892 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1894 dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1895 dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
1896 dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1897 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
1898 DEV_RX_OFFLOAD_IPV4_CKSUM |
1899 DEV_RX_OFFLOAD_UDP_CKSUM |
1900 DEV_RX_OFFLOAD_TCP_CKSUM;
1901 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
1902 DEV_TX_OFFLOAD_IPV4_CKSUM |
1903 DEV_TX_OFFLOAD_UDP_CKSUM |
1904 DEV_TX_OFFLOAD_TCP_CKSUM |
1905 DEV_TX_OFFLOAD_SCTP_CKSUM |
1906 DEV_TX_OFFLOAD_TCP_TSO;
1907 switch (hw->mac.type) {
1909 dev_info->max_rx_queues = 2;
1910 dev_info->max_tx_queues = 2;
1912 case e1000_vfadapt_i350:
1913 dev_info->max_rx_queues = 1;
1914 dev_info->max_tx_queues = 1;
1917 /* Should not happen */
1921 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1923 .pthresh = IGB_DEFAULT_RX_PTHRESH,
1924 .hthresh = IGB_DEFAULT_RX_HTHRESH,
1925 .wthresh = IGB_DEFAULT_RX_WTHRESH,
1927 .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
1931 dev_info->default_txconf = (struct rte_eth_txconf) {
1933 .pthresh = IGB_DEFAULT_TX_PTHRESH,
1934 .hthresh = IGB_DEFAULT_TX_HTHRESH,
1935 .wthresh = IGB_DEFAULT_TX_WTHRESH,
1940 dev_info->rx_desc_lim = rx_desc_lim;
1941 dev_info->tx_desc_lim = tx_desc_lim;
1944 /* return 0 means link status changed, -1 means not changed */
1946 eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1948 struct e1000_hw *hw =
1949 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1950 struct rte_eth_link link, old;
1951 int link_check, count;
1954 hw->mac.get_link_status = 1;
1956 /* possible wait-to-complete in up to 9 seconds */
1957 for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
1958 /* Read the real link status */
1959 switch (hw->phy.media_type) {
1960 case e1000_media_type_copper:
1961 /* Do the work to read phy */
1962 e1000_check_for_link(hw);
1963 link_check = !hw->mac.get_link_status;
1966 case e1000_media_type_fiber:
1967 e1000_check_for_link(hw);
1968 link_check = (E1000_READ_REG(hw, E1000_STATUS) &
1972 case e1000_media_type_internal_serdes:
1973 e1000_check_for_link(hw);
1974 link_check = hw->mac.serdes_has_link;
1977 /* VF device is type_unknown */
1978 case e1000_media_type_unknown:
1979 eth_igbvf_link_update(hw);
1980 link_check = !hw->mac.get_link_status;
1986 if (link_check || wait_to_complete == 0)
1988 rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
1990 memset(&link, 0, sizeof(link));
1991 rte_igb_dev_atomic_read_link_status(dev, &link);
1994 /* Now we check if a transition has happened */
1996 hw->mac.ops.get_link_up_info(hw, &link.link_speed,
1998 link.link_status = 1;
1999 } else if (!link_check) {
2000 link.link_speed = 0;
2001 link.link_duplex = 0;
2002 link.link_status = 0;
2004 rte_igb_dev_atomic_write_link_status(dev, &link);
2007 if (old.link_status == link.link_status)
2015 * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
2016 * For ASF and Pass Through versions of f/w this means
2017 * that the driver is loaded.
2020 igb_hw_control_acquire(struct e1000_hw *hw)
2024 /* Let firmware know the driver has taken over */
2025 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2026 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2030 * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
2031 * For ASF and Pass Through versions of f/w this means that the
2032 * driver is no longer loaded.
2035 igb_hw_control_release(struct e1000_hw *hw)
2039 /* Let firmware taken over control of h/w */
2040 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2041 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
2042 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2046 * Bit of a misnomer, what this really means is
2047 * to enable OS management of the system... aka
2048 * to disable special hardware management features.
2051 igb_init_manageability(struct e1000_hw *hw)
2053 if (e1000_enable_mng_pass_thru(hw)) {
2054 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
2055 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2057 /* disable hardware interception of ARP */
2058 manc &= ~(E1000_MANC_ARP_EN);
2060 /* enable receiving management packets to the host */
2061 manc |= E1000_MANC_EN_MNG2HOST;
2062 manc2h |= 1 << 5; /* Mng Port 623 */
2063 manc2h |= 1 << 6; /* Mng Port 664 */
2064 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
2065 E1000_WRITE_REG(hw, E1000_MANC, manc);
2070 igb_release_manageability(struct e1000_hw *hw)
2072 if (e1000_enable_mng_pass_thru(hw)) {
2073 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2075 manc |= E1000_MANC_ARP_EN;
2076 manc &= ~E1000_MANC_EN_MNG2HOST;
2078 E1000_WRITE_REG(hw, E1000_MANC, manc);
2083 eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
2085 struct e1000_hw *hw =
2086 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2089 rctl = E1000_READ_REG(hw, E1000_RCTL);
2090 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2091 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2095 eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
2097 struct e1000_hw *hw =
2098 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2101 rctl = E1000_READ_REG(hw, E1000_RCTL);
2102 rctl &= (~E1000_RCTL_UPE);
2103 if (dev->data->all_multicast == 1)
2104 rctl |= E1000_RCTL_MPE;
2106 rctl &= (~E1000_RCTL_MPE);
2107 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2111 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
2113 struct e1000_hw *hw =
2114 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2117 rctl = E1000_READ_REG(hw, E1000_RCTL);
2118 rctl |= E1000_RCTL_MPE;
2119 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2123 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
2125 struct e1000_hw *hw =
2126 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2129 if (dev->data->promiscuous == 1)
2130 return; /* must remain in all_multicast mode */
2131 rctl = E1000_READ_REG(hw, E1000_RCTL);
2132 rctl &= (~E1000_RCTL_MPE);
2133 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2137 eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2139 struct e1000_hw *hw =
2140 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2141 struct e1000_vfta * shadow_vfta =
2142 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2147 vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
2148 E1000_VFTA_ENTRY_MASK);
2149 vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
2150 vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
2155 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
2157 /* update local VFTA copy */
2158 shadow_vfta->vfta[vid_idx] = vfta;
2164 eth_igb_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid)
2166 struct e1000_hw *hw =
2167 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2168 uint32_t reg = ETHER_TYPE_VLAN ;
2170 reg |= (tpid << 16);
2171 E1000_WRITE_REG(hw, E1000_VET, reg);
2175 igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
2177 struct e1000_hw *hw =
2178 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2181 /* Filter Table Disable */
2182 reg = E1000_READ_REG(hw, E1000_RCTL);
2183 reg &= ~E1000_RCTL_CFIEN;
2184 reg &= ~E1000_RCTL_VFE;
2185 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2189 igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2191 struct e1000_hw *hw =
2192 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2193 struct e1000_vfta * shadow_vfta =
2194 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2198 /* Filter Table Enable, CFI not used for packet acceptance */
2199 reg = E1000_READ_REG(hw, E1000_RCTL);
2200 reg &= ~E1000_RCTL_CFIEN;
2201 reg |= E1000_RCTL_VFE;
2202 E1000_WRITE_REG(hw, E1000_RCTL, reg);
2204 /* restore VFTA table */
2205 for (i = 0; i < IGB_VFTA_SIZE; i++)
2206 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
2210 igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
2212 struct e1000_hw *hw =
2213 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2216 /* VLAN Mode Disable */
2217 reg = E1000_READ_REG(hw, E1000_CTRL);
2218 reg &= ~E1000_CTRL_VME;
2219 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2223 igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
2225 struct e1000_hw *hw =
2226 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2229 /* VLAN Mode Enable */
2230 reg = E1000_READ_REG(hw, E1000_CTRL);
2231 reg |= E1000_CTRL_VME;
2232 E1000_WRITE_REG(hw, E1000_CTRL, reg);
2236 igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2238 struct e1000_hw *hw =
2239 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2242 /* CTRL_EXT: Extended VLAN */
2243 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2244 reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
2245 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2247 /* Update maximum packet length */
2248 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
2249 E1000_WRITE_REG(hw, E1000_RLPML,
2250 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2255 igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2257 struct e1000_hw *hw =
2258 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2261 /* CTRL_EXT: Extended VLAN */
2262 reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2263 reg |= E1000_CTRL_EXT_EXTEND_VLAN;
2264 E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2266 /* Update maximum packet length */
2267 if (dev->data->dev_conf.rxmode.jumbo_frame == 1)
2268 E1000_WRITE_REG(hw, E1000_RLPML,
2269 dev->data->dev_conf.rxmode.max_rx_pkt_len +
2274 eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2276 if(mask & ETH_VLAN_STRIP_MASK){
2277 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2278 igb_vlan_hw_strip_enable(dev);
2280 igb_vlan_hw_strip_disable(dev);
2283 if(mask & ETH_VLAN_FILTER_MASK){
2284 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2285 igb_vlan_hw_filter_enable(dev);
2287 igb_vlan_hw_filter_disable(dev);
2290 if(mask & ETH_VLAN_EXTEND_MASK){
2291 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2292 igb_vlan_hw_extend_enable(dev);
2294 igb_vlan_hw_extend_disable(dev);
2300 * It enables the interrupt mask and then enable the interrupt.
2303 * Pointer to struct rte_eth_dev.
2306 * - On success, zero.
2307 * - On failure, a negative value.
2310 eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev)
2312 struct e1000_interrupt *intr =
2313 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2315 intr->mask |= E1000_ICR_LSC;
2320 /* It clears the interrupt causes and enables the interrupt.
2321 * It will be called once only during nic initialized.
2324 * Pointer to struct rte_eth_dev.
2327 * - On success, zero.
2328 * - On failure, a negative value.
2330 static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev)
2332 uint32_t mask, regval;
2333 struct e1000_hw *hw =
2334 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2335 struct rte_eth_dev_info dev_info;
2337 memset(&dev_info, 0, sizeof(dev_info));
2338 eth_igb_infos_get(dev, &dev_info);
2340 mask = 0xFFFFFFFF >> (32 - dev_info.max_rx_queues);
2341 regval = E1000_READ_REG(hw, E1000_EIMS);
2342 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
2348 * It reads ICR and gets interrupt causes, check it and set a bit flag
2349 * to update link status.
2352 * Pointer to struct rte_eth_dev.
2355 * - On success, zero.
2356 * - On failure, a negative value.
2359 eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
2362 struct e1000_hw *hw =
2363 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2364 struct e1000_interrupt *intr =
2365 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2367 igb_intr_disable(hw);
2369 /* read-on-clear nic registers here */
2370 icr = E1000_READ_REG(hw, E1000_ICR);
2373 if (icr & E1000_ICR_LSC) {
2374 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
2377 if (icr & E1000_ICR_VMMB)
2378 intr->flags |= E1000_FLAG_MAILBOX;
2384 * It executes link_update after knowing an interrupt is prsent.
2387 * Pointer to struct rte_eth_dev.
2390 * - On success, zero.
2391 * - On failure, a negative value.
2394 eth_igb_interrupt_action(struct rte_eth_dev *dev)
2396 struct e1000_hw *hw =
2397 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2398 struct e1000_interrupt *intr =
2399 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2400 uint32_t tctl, rctl;
2401 struct rte_eth_link link;
2404 if (intr->flags & E1000_FLAG_MAILBOX) {
2405 igb_pf_mbx_process(dev);
2406 intr->flags &= ~E1000_FLAG_MAILBOX;
2409 igb_intr_enable(dev);
2410 rte_intr_enable(&(dev->pci_dev->intr_handle));
2412 if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
2413 intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
2415 /* set get_link_status to check register later */
2416 hw->mac.get_link_status = 1;
2417 ret = eth_igb_link_update(dev, 0);
2419 /* check if link has changed */
2423 memset(&link, 0, sizeof(link));
2424 rte_igb_dev_atomic_read_link_status(dev, &link);
2425 if (link.link_status) {
2427 " Port %d: Link Up - speed %u Mbps - %s",
2429 (unsigned)link.link_speed,
2430 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2431 "full-duplex" : "half-duplex");
2433 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2434 dev->data->port_id);
2437 PMD_INIT_LOG(DEBUG, "PCI Address: %04d:%02d:%02d:%d",
2438 dev->pci_dev->addr.domain,
2439 dev->pci_dev->addr.bus,
2440 dev->pci_dev->addr.devid,
2441 dev->pci_dev->addr.function);
2442 tctl = E1000_READ_REG(hw, E1000_TCTL);
2443 rctl = E1000_READ_REG(hw, E1000_RCTL);
2444 if (link.link_status) {
2446 tctl |= E1000_TCTL_EN;
2447 rctl |= E1000_RCTL_EN;
2450 tctl &= ~E1000_TCTL_EN;
2451 rctl &= ~E1000_RCTL_EN;
2453 E1000_WRITE_REG(hw, E1000_TCTL, tctl);
2454 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2455 E1000_WRITE_FLUSH(hw);
2456 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
2463 * Interrupt handler which shall be registered at first.
2466 * Pointer to interrupt handle.
2468 * The address of parameter (struct rte_eth_dev *) regsitered before.
2474 eth_igb_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
2477 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2479 eth_igb_interrupt_get_status(dev);
2480 eth_igb_interrupt_action(dev);
2484 eth_igb_led_on(struct rte_eth_dev *dev)
2486 struct e1000_hw *hw;
2488 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2489 return (e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
2493 eth_igb_led_off(struct rte_eth_dev *dev)
2495 struct e1000_hw *hw;
2497 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2498 return (e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
2502 eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2504 struct e1000_hw *hw;
2509 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2510 fc_conf->pause_time = hw->fc.pause_time;
2511 fc_conf->high_water = hw->fc.high_water;
2512 fc_conf->low_water = hw->fc.low_water;
2513 fc_conf->send_xon = hw->fc.send_xon;
2514 fc_conf->autoneg = hw->mac.autoneg;
2517 * Return rx_pause and tx_pause status according to actual setting of
2518 * the TFCE and RFCE bits in the CTRL register.
2520 ctrl = E1000_READ_REG(hw, E1000_CTRL);
2521 if (ctrl & E1000_CTRL_TFCE)
2526 if (ctrl & E1000_CTRL_RFCE)
2531 if (rx_pause && tx_pause)
2532 fc_conf->mode = RTE_FC_FULL;
2534 fc_conf->mode = RTE_FC_RX_PAUSE;
2536 fc_conf->mode = RTE_FC_TX_PAUSE;
2538 fc_conf->mode = RTE_FC_NONE;
2544 eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2546 struct e1000_hw *hw;
2548 enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
2554 uint32_t rx_buf_size;
2555 uint32_t max_high_water;
2558 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2559 if (fc_conf->autoneg != hw->mac.autoneg)
2561 rx_buf_size = igb_get_rx_buffer_size(hw);
2562 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2564 /* At least reserve one Ethernet frame for watermark */
2565 max_high_water = rx_buf_size - ETHER_MAX_LEN;
2566 if ((fc_conf->high_water > max_high_water) ||
2567 (fc_conf->high_water < fc_conf->low_water)) {
2568 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
2569 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
2573 hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
2574 hw->fc.pause_time = fc_conf->pause_time;
2575 hw->fc.high_water = fc_conf->high_water;
2576 hw->fc.low_water = fc_conf->low_water;
2577 hw->fc.send_xon = fc_conf->send_xon;
2579 err = e1000_setup_link_generic(hw);
2580 if (err == E1000_SUCCESS) {
2582 /* check if we want to forward MAC frames - driver doesn't have native
2583 * capability to do that, so we'll write the registers ourselves */
2585 rctl = E1000_READ_REG(hw, E1000_RCTL);
2587 /* set or clear MFLCN.PMCF bit depending on configuration */
2588 if (fc_conf->mac_ctrl_frame_fwd != 0)
2589 rctl |= E1000_RCTL_PMCF;
2591 rctl &= ~E1000_RCTL_PMCF;
2593 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2594 E1000_WRITE_FLUSH(hw);
2599 PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
2603 #define E1000_RAH_POOLSEL_SHIFT (18)
2605 eth_igb_rar_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
2606 uint32_t index, __rte_unused uint32_t pool)
2608 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2611 e1000_rar_set(hw, mac_addr->addr_bytes, index);
2612 rah = E1000_READ_REG(hw, E1000_RAH(index));
2613 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
2614 E1000_WRITE_REG(hw, E1000_RAH(index), rah);
2618 eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
2620 uint8_t addr[ETHER_ADDR_LEN];
2621 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2623 memset(addr, 0, sizeof(addr));
2625 e1000_rar_set(hw, addr, index);
2629 eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
2630 struct ether_addr *addr)
2632 eth_igb_rar_clear(dev, 0);
2634 eth_igb_rar_set(dev, (void *)addr, 0, 0);
2637 * Virtual Function operations
2640 igbvf_intr_disable(struct e1000_hw *hw)
2642 PMD_INIT_FUNC_TRACE();
2644 /* Clear interrupt mask to stop from interrupts being generated */
2645 E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
2647 E1000_WRITE_FLUSH(hw);
2651 igbvf_stop_adapter(struct rte_eth_dev *dev)
2655 struct rte_eth_dev_info dev_info;
2656 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2658 memset(&dev_info, 0, sizeof(dev_info));
2659 eth_igbvf_infos_get(dev, &dev_info);
2661 /* Clear interrupt mask to stop from interrupts being generated */
2662 igbvf_intr_disable(hw);
2664 /* Clear any pending interrupts, flush previous writes */
2665 E1000_READ_REG(hw, E1000_EICR);
2667 /* Disable the transmit unit. Each queue must be disabled. */
2668 for (i = 0; i < dev_info.max_tx_queues; i++)
2669 E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
2671 /* Disable the receive unit by stopping each queue */
2672 for (i = 0; i < dev_info.max_rx_queues; i++) {
2673 reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
2674 reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
2675 E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
2676 while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
2680 /* flush all queues disables */
2681 E1000_WRITE_FLUSH(hw);
2685 static int eth_igbvf_link_update(struct e1000_hw *hw)
2687 struct e1000_mbx_info *mbx = &hw->mbx;
2688 struct e1000_mac_info *mac = &hw->mac;
2689 int ret_val = E1000_SUCCESS;
2691 PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
2694 * We only want to run this if there has been a rst asserted.
2695 * in this case that could mean a link change, device reset,
2696 * or a virtual function reset
2699 /* If we were hit with a reset or timeout drop the link */
2700 if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
2701 mac->get_link_status = TRUE;
2703 if (!mac->get_link_status)
2706 /* if link status is down no point in checking to see if pf is up */
2707 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
2710 /* if we passed all the tests above then the link is up and we no
2711 * longer need to check for link */
2712 mac->get_link_status = FALSE;
2720 igbvf_dev_configure(struct rte_eth_dev *dev)
2722 struct rte_eth_conf* conf = &dev->data->dev_conf;
2724 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
2725 dev->data->port_id);
2728 * VF has no ability to enable/disable HW CRC
2729 * Keep the persistent behavior the same as Host PF
2731 #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
2732 if (!conf->rxmode.hw_strip_crc) {
2733 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
2734 conf->rxmode.hw_strip_crc = 1;
2737 if (conf->rxmode.hw_strip_crc) {
2738 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
2739 conf->rxmode.hw_strip_crc = 0;
2747 igbvf_dev_start(struct rte_eth_dev *dev)
2749 struct e1000_hw *hw =
2750 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2751 struct e1000_adapter *adapter =
2752 E1000_DEV_PRIVATE(dev->data->dev_private);
2755 PMD_INIT_FUNC_TRACE();
2757 hw->mac.ops.reset_hw(hw);
2758 adapter->stopped = 0;
2761 igbvf_set_vfta_all(dev,1);
2763 eth_igbvf_tx_init(dev);
2765 /* This can fail when allocating mbufs for descriptor rings */
2766 ret = eth_igbvf_rx_init(dev);
2768 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
2769 igb_dev_clear_queues(dev);
2777 igbvf_dev_stop(struct rte_eth_dev *dev)
2779 PMD_INIT_FUNC_TRACE();
2781 igbvf_stop_adapter(dev);
2784 * Clear what we set, but we still keep shadow_vfta to
2785 * restore after device starts
2787 igbvf_set_vfta_all(dev,0);
2789 igb_dev_clear_queues(dev);
2793 igbvf_dev_close(struct rte_eth_dev *dev)
2795 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2796 struct e1000_adapter *adapter =
2797 E1000_DEV_PRIVATE(dev->data->dev_private);
2799 PMD_INIT_FUNC_TRACE();
2803 igbvf_dev_stop(dev);
2804 adapter->stopped = 1;
2805 igb_dev_free_queues(dev);
2808 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
2810 struct e1000_mbx_info *mbx = &hw->mbx;
2814 /* After set vlan, vlan strip will also be enabled in igb driver*/
2815 msgbuf[0] = E1000_VF_SET_VLAN;
2817 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
2819 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
2821 err = mbx->ops.write_posted(hw, msgbuf, 2, 0);
2825 err = mbx->ops.read_posted(hw, msgbuf, 2, 0);
2829 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
2830 if (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK))
2837 static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
2839 struct e1000_hw *hw =
2840 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2841 struct e1000_vfta * shadow_vfta =
2842 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2843 int i = 0, j = 0, vfta = 0, mask = 1;
2845 for (i = 0; i < IGB_VFTA_SIZE; i++){
2846 vfta = shadow_vfta->vfta[i];
2849 for (j = 0; j < 32; j++){
2852 (uint16_t)((i<<5)+j), on);
2861 igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2863 struct e1000_hw *hw =
2864 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2865 struct e1000_vfta * shadow_vfta =
2866 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2867 uint32_t vid_idx = 0;
2868 uint32_t vid_bit = 0;
2871 PMD_INIT_FUNC_TRACE();
2873 /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
2874 ret = igbvf_set_vfta(hw, vlan_id, !!on);
2876 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
2879 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
2880 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
2882 /*Save what we set and retore it after device reset*/
2884 shadow_vfta->vfta[vid_idx] |= vid_bit;
2886 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
2892 igbvf_default_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *addr)
2894 struct e1000_hw *hw =
2895 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2897 /* index is not used by rar_set() */
2898 hw->mac.ops.rar_set(hw, (void *)addr, 0);
2903 eth_igb_rss_reta_update(struct rte_eth_dev *dev,
2904 struct rte_eth_rss_reta_entry64 *reta_conf,
2909 uint16_t idx, shift;
2910 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2912 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2913 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2914 "(%d) doesn't match the number hardware can supported "
2915 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2919 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
2920 idx = i / RTE_RETA_GROUP_SIZE;
2921 shift = i % RTE_RETA_GROUP_SIZE;
2922 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2926 if (mask == IGB_4_BIT_MASK)
2929 r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
2930 for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
2931 if (mask & (0x1 << j))
2932 reta |= reta_conf[idx].reta[shift + j] <<
2935 reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
2937 E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
2944 eth_igb_rss_reta_query(struct rte_eth_dev *dev,
2945 struct rte_eth_rss_reta_entry64 *reta_conf,
2950 uint16_t idx, shift;
2951 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2953 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2954 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2955 "(%d) doesn't match the number hardware can supported "
2956 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2960 for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
2961 idx = i / RTE_RETA_GROUP_SIZE;
2962 shift = i % RTE_RETA_GROUP_SIZE;
2963 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2967 reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
2968 for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
2969 if (mask & (0x1 << j))
2970 reta_conf[idx].reta[shift + j] =
2971 ((reta >> (CHAR_BIT * j)) &
2979 #define MAC_TYPE_FILTER_SUP(type) do {\
2980 if ((type) != e1000_82580 && (type) != e1000_i350 &&\
2981 (type) != e1000_82576)\
2986 eth_igb_syn_filter_set(struct rte_eth_dev *dev,
2987 struct rte_eth_syn_filter *filter,
2990 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2991 uint32_t synqf, rfctl;
2993 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
2996 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
2999 if (synqf & E1000_SYN_FILTER_ENABLE)
3002 synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
3003 E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
3005 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3006 if (filter->hig_pri)
3007 rfctl |= E1000_RFCTL_SYNQFP;
3009 rfctl &= ~E1000_RFCTL_SYNQFP;
3011 E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
3013 if (!(synqf & E1000_SYN_FILTER_ENABLE))
3018 E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
3019 E1000_WRITE_FLUSH(hw);
3024 eth_igb_syn_filter_get(struct rte_eth_dev *dev,
3025 struct rte_eth_syn_filter *filter)
3027 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3028 uint32_t synqf, rfctl;
3030 synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3031 if (synqf & E1000_SYN_FILTER_ENABLE) {
3032 rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3033 filter->hig_pri = (rfctl & E1000_RFCTL_SYNQFP) ? 1 : 0;
3034 filter->queue = (uint8_t)((synqf & E1000_SYN_FILTER_QUEUE) >>
3035 E1000_SYN_FILTER_QUEUE_SHIFT);
3043 eth_igb_syn_filter_handle(struct rte_eth_dev *dev,
3044 enum rte_filter_op filter_op,
3047 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3050 MAC_TYPE_FILTER_SUP(hw->mac.type);
3052 if (filter_op == RTE_ETH_FILTER_NOP)
3056 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3061 switch (filter_op) {
3062 case RTE_ETH_FILTER_ADD:
3063 ret = eth_igb_syn_filter_set(dev,
3064 (struct rte_eth_syn_filter *)arg,
3067 case RTE_ETH_FILTER_DELETE:
3068 ret = eth_igb_syn_filter_set(dev,
3069 (struct rte_eth_syn_filter *)arg,
3072 case RTE_ETH_FILTER_GET:
3073 ret = eth_igb_syn_filter_get(dev,
3074 (struct rte_eth_syn_filter *)arg);
3077 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
3085 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
3086 if ((type) != e1000_82580 && (type) != e1000_i350)\
3090 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
3092 ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
3093 struct e1000_2tuple_filter_info *filter_info)
3095 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3097 if (filter->priority > E1000_2TUPLE_MAX_PRI)
3098 return -EINVAL; /* filter index is out of range. */
3099 if (filter->tcp_flags > TCP_FLAG_ALL)
3100 return -EINVAL; /* flags is invalid. */
3102 switch (filter->dst_port_mask) {
3104 filter_info->dst_port_mask = 0;
3105 filter_info->dst_port = filter->dst_port;
3108 filter_info->dst_port_mask = 1;
3111 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3115 switch (filter->proto_mask) {
3117 filter_info->proto_mask = 0;
3118 filter_info->proto = filter->proto;
3121 filter_info->proto_mask = 1;
3124 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3128 filter_info->priority = (uint8_t)filter->priority;
3129 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3130 filter_info->tcp_flags = filter->tcp_flags;
3132 filter_info->tcp_flags = 0;
3137 static inline struct e1000_2tuple_filter *
3138 igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
3139 struct e1000_2tuple_filter_info *key)
3141 struct e1000_2tuple_filter *it;
3143 TAILQ_FOREACH(it, filter_list, entries) {
3144 if (memcmp(key, &it->filter_info,
3145 sizeof(struct e1000_2tuple_filter_info)) == 0) {
3153 * igb_add_2tuple_filter - add a 2tuple filter
3156 * dev: Pointer to struct rte_eth_dev.
3157 * ntuple_filter: ponter to the filter that will be added.
3160 * - On success, zero.
3161 * - On failure, a negative value.
3164 igb_add_2tuple_filter(struct rte_eth_dev *dev,
3165 struct rte_eth_ntuple_filter *ntuple_filter)
3167 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3168 struct e1000_filter_info *filter_info =
3169 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3170 struct e1000_2tuple_filter *filter;
3171 uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
3172 uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3175 filter = rte_zmalloc("e1000_2tuple_filter",
3176 sizeof(struct e1000_2tuple_filter), 0);
3180 ret = ntuple_filter_to_2tuple(ntuple_filter,
3181 &filter->filter_info);
3186 if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3187 &filter->filter_info) != NULL) {
3188 PMD_DRV_LOG(ERR, "filter exists.");
3192 filter->queue = ntuple_filter->queue;
3195 * look for an unused 2tuple filter index,
3196 * and insert the filter to list.
3198 for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
3199 if (!(filter_info->twotuple_mask & (1 << i))) {
3200 filter_info->twotuple_mask |= 1 << i;
3202 TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
3208 if (i >= E1000_MAX_TTQF_FILTERS) {
3209 PMD_DRV_LOG(ERR, "2tuple filters are full.");
3214 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3215 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3216 imir |= E1000_IMIR_PORT_BP;
3218 imir &= ~E1000_IMIR_PORT_BP;
3220 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3222 ttqf |= E1000_TTQF_QUEUE_ENABLE;
3223 ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
3224 ttqf |= (uint32_t)(filter->filter_info.proto & E1000_TTQF_PROTOCOL_MASK);
3225 if (filter->filter_info.proto_mask == 0)
3226 ttqf &= ~E1000_TTQF_MASK_ENABLE;
3228 /* tcp flags bits setting. */
3229 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3230 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3231 imir_ext |= E1000_IMIREXT_CTRL_URG;
3232 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3233 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3234 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3235 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3236 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3237 imir_ext |= E1000_IMIREXT_CTRL_RST;
3238 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3239 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3240 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3241 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3243 imir_ext |= E1000_IMIREXT_CTRL_BP;
3244 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3245 E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
3246 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3251 * igb_remove_2tuple_filter - remove a 2tuple filter
3254 * dev: Pointer to struct rte_eth_dev.
3255 * ntuple_filter: ponter to the filter that will be removed.
3258 * - On success, zero.
3259 * - On failure, a negative value.
3262 igb_remove_2tuple_filter(struct rte_eth_dev *dev,
3263 struct rte_eth_ntuple_filter *ntuple_filter)
3265 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3266 struct e1000_filter_info *filter_info =
3267 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3268 struct e1000_2tuple_filter_info filter_2tuple;
3269 struct e1000_2tuple_filter *filter;
3272 memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
3273 ret = ntuple_filter_to_2tuple(ntuple_filter,
3278 filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
3280 if (filter == NULL) {
3281 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3285 filter_info->twotuple_mask &= ~(1 << filter->index);
3286 TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
3289 E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
3290 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3291 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3295 static inline struct e1000_flex_filter *
3296 eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
3297 struct e1000_flex_filter_info *key)
3299 struct e1000_flex_filter *it;
3301 TAILQ_FOREACH(it, filter_list, entries) {
3302 if (memcmp(key, &it->filter_info,
3303 sizeof(struct e1000_flex_filter_info)) == 0)
3311 eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
3312 struct rte_eth_flex_filter *filter,
3315 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3316 struct e1000_filter_info *filter_info =
3317 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3318 struct e1000_flex_filter *flex_filter, *it;
3319 uint32_t wufc, queueing, mask;
3321 uint8_t shift, i, j = 0;
3323 flex_filter = rte_zmalloc("e1000_flex_filter",
3324 sizeof(struct e1000_flex_filter), 0);
3325 if (flex_filter == NULL)
3328 flex_filter->filter_info.len = filter->len;
3329 flex_filter->filter_info.priority = filter->priority;
3330 memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
3331 for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
3333 /* reverse bits in flex filter's mask*/
3334 for (shift = 0; shift < CHAR_BIT; shift++) {
3335 if (filter->mask[i] & (0x01 << shift))
3336 mask |= (0x80 >> shift);
3338 flex_filter->filter_info.mask[i] = mask;
3341 wufc = E1000_READ_REG(hw, E1000_WUFC);
3342 if (flex_filter->index < E1000_MAX_FHFT)
3343 reg_off = E1000_FHFT(flex_filter->index);
3345 reg_off = E1000_FHFT_EXT(flex_filter->index - E1000_MAX_FHFT);
3348 if (eth_igb_flex_filter_lookup(&filter_info->flex_list,
3349 &flex_filter->filter_info) != NULL) {
3350 PMD_DRV_LOG(ERR, "filter exists.");
3351 rte_free(flex_filter);
3354 flex_filter->queue = filter->queue;
3356 * look for an unused flex filter index
3357 * and insert the filter into the list.
3359 for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
3360 if (!(filter_info->flex_mask & (1 << i))) {
3361 filter_info->flex_mask |= 1 << i;
3362 flex_filter->index = i;
3363 TAILQ_INSERT_TAIL(&filter_info->flex_list,
3369 if (i >= E1000_MAX_FLEX_FILTERS) {
3370 PMD_DRV_LOG(ERR, "flex filters are full.");
3371 rte_free(flex_filter);
3375 E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
3376 (E1000_WUFC_FLX0 << flex_filter->index));
3377 queueing = filter->len |
3378 (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
3379 (filter->priority << E1000_FHFT_QUEUEING_PRIO_SHIFT);
3380 E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
3382 for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
3383 E1000_WRITE_REG(hw, reg_off,
3384 flex_filter->filter_info.dwords[j]);
3385 reg_off += sizeof(uint32_t);
3386 E1000_WRITE_REG(hw, reg_off,
3387 flex_filter->filter_info.dwords[++j]);
3388 reg_off += sizeof(uint32_t);
3389 E1000_WRITE_REG(hw, reg_off,
3390 (uint32_t)flex_filter->filter_info.mask[i]);
3391 reg_off += sizeof(uint32_t) * 2;
3395 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
3396 &flex_filter->filter_info);
3398 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3399 rte_free(flex_filter);
3403 for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
3404 E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
3405 E1000_WRITE_REG(hw, E1000_WUFC, wufc &
3406 (~(E1000_WUFC_FLX0 << it->index)));
3408 filter_info->flex_mask &= ~(1 << it->index);
3409 TAILQ_REMOVE(&filter_info->flex_list, it, entries);
3411 rte_free(flex_filter);
3418 eth_igb_get_flex_filter(struct rte_eth_dev *dev,
3419 struct rte_eth_flex_filter *filter)
3421 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3422 struct e1000_filter_info *filter_info =
3423 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3424 struct e1000_flex_filter flex_filter, *it;
3425 uint32_t wufc, queueing, wufc_en = 0;
3427 memset(&flex_filter, 0, sizeof(struct e1000_flex_filter));
3428 flex_filter.filter_info.len = filter->len;
3429 flex_filter.filter_info.priority = filter->priority;
3430 memcpy(flex_filter.filter_info.dwords, filter->bytes, filter->len);
3431 memcpy(flex_filter.filter_info.mask, filter->mask,
3432 RTE_ALIGN(filter->len, sizeof(char)) / sizeof(char));
3434 it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
3435 &flex_filter.filter_info);
3437 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3441 wufc = E1000_READ_REG(hw, E1000_WUFC);
3442 wufc_en = E1000_WUFC_FLEX_HQ | (E1000_WUFC_FLX0 << it->index);
3444 if ((wufc & wufc_en) == wufc_en) {
3445 uint32_t reg_off = 0;
3446 if (it->index < E1000_MAX_FHFT)
3447 reg_off = E1000_FHFT(it->index);
3449 reg_off = E1000_FHFT_EXT(it->index - E1000_MAX_FHFT);
3451 queueing = E1000_READ_REG(hw,
3452 reg_off + E1000_FHFT_QUEUEING_OFFSET);
3453 filter->len = queueing & E1000_FHFT_QUEUEING_LEN;
3454 filter->priority = (queueing & E1000_FHFT_QUEUEING_PRIO) >>
3455 E1000_FHFT_QUEUEING_PRIO_SHIFT;
3456 filter->queue = (queueing & E1000_FHFT_QUEUEING_QUEUE) >>
3457 E1000_FHFT_QUEUEING_QUEUE_SHIFT;
3464 eth_igb_flex_filter_handle(struct rte_eth_dev *dev,
3465 enum rte_filter_op filter_op,
3468 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3469 struct rte_eth_flex_filter *filter;
3472 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
3474 if (filter_op == RTE_ETH_FILTER_NOP)
3478 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3483 filter = (struct rte_eth_flex_filter *)arg;
3484 if (filter->len == 0 || filter->len > E1000_MAX_FLEX_FILTER_LEN
3485 || filter->len % sizeof(uint64_t) != 0) {
3486 PMD_DRV_LOG(ERR, "filter's length is out of range");
3489 if (filter->priority > E1000_MAX_FLEX_FILTER_PRI) {
3490 PMD_DRV_LOG(ERR, "filter's priority is out of range");
3494 switch (filter_op) {
3495 case RTE_ETH_FILTER_ADD:
3496 ret = eth_igb_add_del_flex_filter(dev, filter, TRUE);
3498 case RTE_ETH_FILTER_DELETE:
3499 ret = eth_igb_add_del_flex_filter(dev, filter, FALSE);
3501 case RTE_ETH_FILTER_GET:
3502 ret = eth_igb_get_flex_filter(dev, filter);
3505 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
3513 /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
3515 ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
3516 struct e1000_5tuple_filter_info *filter_info)
3518 if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
3520 if (filter->priority > E1000_2TUPLE_MAX_PRI)
3521 return -EINVAL; /* filter index is out of range. */
3522 if (filter->tcp_flags > TCP_FLAG_ALL)
3523 return -EINVAL; /* flags is invalid. */
3525 switch (filter->dst_ip_mask) {
3527 filter_info->dst_ip_mask = 0;
3528 filter_info->dst_ip = filter->dst_ip;
3531 filter_info->dst_ip_mask = 1;
3534 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
3538 switch (filter->src_ip_mask) {
3540 filter_info->src_ip_mask = 0;
3541 filter_info->src_ip = filter->src_ip;
3544 filter_info->src_ip_mask = 1;
3547 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
3551 switch (filter->dst_port_mask) {
3553 filter_info->dst_port_mask = 0;
3554 filter_info->dst_port = filter->dst_port;
3557 filter_info->dst_port_mask = 1;
3560 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3564 switch (filter->src_port_mask) {
3566 filter_info->src_port_mask = 0;
3567 filter_info->src_port = filter->src_port;
3570 filter_info->src_port_mask = 1;
3573 PMD_DRV_LOG(ERR, "invalid src_port mask.");
3577 switch (filter->proto_mask) {
3579 filter_info->proto_mask = 0;
3580 filter_info->proto = filter->proto;
3583 filter_info->proto_mask = 1;
3586 PMD_DRV_LOG(ERR, "invalid protocol mask.");
3590 filter_info->priority = (uint8_t)filter->priority;
3591 if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3592 filter_info->tcp_flags = filter->tcp_flags;
3594 filter_info->tcp_flags = 0;
3599 static inline struct e1000_5tuple_filter *
3600 igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
3601 struct e1000_5tuple_filter_info *key)
3603 struct e1000_5tuple_filter *it;
3605 TAILQ_FOREACH(it, filter_list, entries) {
3606 if (memcmp(key, &it->filter_info,
3607 sizeof(struct e1000_5tuple_filter_info)) == 0) {
3615 * igb_add_5tuple_filter_82576 - add a 5tuple filter
3618 * dev: Pointer to struct rte_eth_dev.
3619 * ntuple_filter: ponter to the filter that will be added.
3622 * - On success, zero.
3623 * - On failure, a negative value.
3626 igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
3627 struct rte_eth_ntuple_filter *ntuple_filter)
3629 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3630 struct e1000_filter_info *filter_info =
3631 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3632 struct e1000_5tuple_filter *filter;
3633 uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
3634 uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
3638 filter = rte_zmalloc("e1000_5tuple_filter",
3639 sizeof(struct e1000_5tuple_filter), 0);
3643 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3644 &filter->filter_info);
3650 if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
3651 &filter->filter_info) != NULL) {
3652 PMD_DRV_LOG(ERR, "filter exists.");
3656 filter->queue = ntuple_filter->queue;
3659 * look for an unused 5tuple filter index,
3660 * and insert the filter to list.
3662 for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
3663 if (!(filter_info->fivetuple_mask & (1 << i))) {
3664 filter_info->fivetuple_mask |= 1 << i;
3666 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
3672 if (i >= E1000_MAX_FTQF_FILTERS) {
3673 PMD_DRV_LOG(ERR, "5tuple filters are full.");
3678 ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
3679 if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
3680 ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
3681 if (filter->filter_info.dst_ip_mask == 0)
3682 ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
3683 if (filter->filter_info.src_port_mask == 0)
3684 ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
3685 if (filter->filter_info.proto_mask == 0)
3686 ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
3687 ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
3688 E1000_FTQF_QUEUE_MASK;
3689 ftqf |= E1000_FTQF_QUEUE_ENABLE;
3690 E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
3691 E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
3692 E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
3694 spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
3695 E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
3697 imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
3698 if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
3699 imir |= E1000_IMIR_PORT_BP;
3701 imir &= ~E1000_IMIR_PORT_BP;
3702 imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
3704 /* tcp flags bits setting. */
3705 if (filter->filter_info.tcp_flags & TCP_FLAG_ALL) {
3706 if (filter->filter_info.tcp_flags & TCP_URG_FLAG)
3707 imir_ext |= E1000_IMIREXT_CTRL_URG;
3708 if (filter->filter_info.tcp_flags & TCP_ACK_FLAG)
3709 imir_ext |= E1000_IMIREXT_CTRL_ACK;
3710 if (filter->filter_info.tcp_flags & TCP_PSH_FLAG)
3711 imir_ext |= E1000_IMIREXT_CTRL_PSH;
3712 if (filter->filter_info.tcp_flags & TCP_RST_FLAG)
3713 imir_ext |= E1000_IMIREXT_CTRL_RST;
3714 if (filter->filter_info.tcp_flags & TCP_SYN_FLAG)
3715 imir_ext |= E1000_IMIREXT_CTRL_SYN;
3716 if (filter->filter_info.tcp_flags & TCP_FIN_FLAG)
3717 imir_ext |= E1000_IMIREXT_CTRL_FIN;
3719 imir_ext |= E1000_IMIREXT_CTRL_BP;
3720 E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
3721 E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
3726 * igb_remove_5tuple_filter_82576 - remove a 5tuple filter
3729 * dev: Pointer to struct rte_eth_dev.
3730 * ntuple_filter: ponter to the filter that will be removed.
3733 * - On success, zero.
3734 * - On failure, a negative value.
3737 igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
3738 struct rte_eth_ntuple_filter *ntuple_filter)
3740 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3741 struct e1000_filter_info *filter_info =
3742 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3743 struct e1000_5tuple_filter_info filter_5tuple;
3744 struct e1000_5tuple_filter *filter;
3747 memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
3748 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3753 filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
3755 if (filter == NULL) {
3756 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3760 filter_info->fivetuple_mask &= ~(1 << filter->index);
3761 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
3764 E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
3765 E1000_FTQF_VF_BP | E1000_FTQF_MASK);
3766 E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
3767 E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
3768 E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
3769 E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
3770 E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
3775 eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
3778 struct e1000_hw *hw;
3779 struct rte_eth_dev_info dev_info;
3780 uint32_t frame_size = mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN +
3783 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3785 #ifdef RTE_LIBRTE_82571_SUPPORT
3786 /* XXX: not bigger than max_rx_pktlen */
3787 if (hw->mac.type == e1000_82571)
3790 eth_igb_infos_get(dev, &dev_info);
3792 /* check that mtu is within the allowed range */
3793 if ((mtu < ETHER_MIN_MTU) ||
3794 (frame_size > dev_info.max_rx_pktlen))
3797 /* refuse mtu that requires the support of scattered packets when this
3798 * feature has not been enabled before. */
3799 if (!dev->data->scattered_rx &&
3800 frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)
3803 rctl = E1000_READ_REG(hw, E1000_RCTL);
3805 /* switch to jumbo mode if needed */
3806 if (frame_size > ETHER_MAX_LEN) {
3807 dev->data->dev_conf.rxmode.jumbo_frame = 1;
3808 rctl |= E1000_RCTL_LPE;
3810 dev->data->dev_conf.rxmode.jumbo_frame = 0;
3811 rctl &= ~E1000_RCTL_LPE;
3813 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3815 /* update max frame size */
3816 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
3818 E1000_WRITE_REG(hw, E1000_RLPML,
3819 dev->data->dev_conf.rxmode.max_rx_pkt_len);
3825 * igb_add_del_ntuple_filter - add or delete a ntuple filter
3828 * dev: Pointer to struct rte_eth_dev.
3829 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
3830 * add: if true, add filter, if false, remove filter
3833 * - On success, zero.
3834 * - On failure, a negative value.
3837 igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
3838 struct rte_eth_ntuple_filter *ntuple_filter,
3841 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3844 switch (ntuple_filter->flags) {
3845 case RTE_5TUPLE_FLAGS:
3846 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3847 if (hw->mac.type != e1000_82576)
3850 ret = igb_add_5tuple_filter_82576(dev,
3853 ret = igb_remove_5tuple_filter_82576(dev,
3856 case RTE_2TUPLE_FLAGS:
3857 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3858 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
3861 ret = igb_add_2tuple_filter(dev, ntuple_filter);
3863 ret = igb_remove_2tuple_filter(dev, ntuple_filter);
3874 * igb_get_ntuple_filter - get a ntuple filter
3877 * dev: Pointer to struct rte_eth_dev.
3878 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
3881 * - On success, zero.
3882 * - On failure, a negative value.
3885 igb_get_ntuple_filter(struct rte_eth_dev *dev,
3886 struct rte_eth_ntuple_filter *ntuple_filter)
3888 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3889 struct e1000_filter_info *filter_info =
3890 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3891 struct e1000_5tuple_filter_info filter_5tuple;
3892 struct e1000_2tuple_filter_info filter_2tuple;
3893 struct e1000_5tuple_filter *p_5tuple_filter;
3894 struct e1000_2tuple_filter *p_2tuple_filter;
3897 switch (ntuple_filter->flags) {
3898 case RTE_5TUPLE_FLAGS:
3899 case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3900 if (hw->mac.type != e1000_82576)
3902 memset(&filter_5tuple,
3904 sizeof(struct e1000_5tuple_filter_info));
3905 ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
3909 p_5tuple_filter = igb_5tuple_filter_lookup_82576(
3910 &filter_info->fivetuple_list,
3912 if (p_5tuple_filter == NULL) {
3913 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3916 ntuple_filter->queue = p_5tuple_filter->queue;
3918 case RTE_2TUPLE_FLAGS:
3919 case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
3920 if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
3922 memset(&filter_2tuple,
3924 sizeof(struct e1000_2tuple_filter_info));
3925 ret = ntuple_filter_to_2tuple(ntuple_filter, &filter_2tuple);
3928 p_2tuple_filter = igb_2tuple_filter_lookup(
3929 &filter_info->twotuple_list,
3931 if (p_2tuple_filter == NULL) {
3932 PMD_DRV_LOG(ERR, "filter doesn't exist.");
3935 ntuple_filter->queue = p_2tuple_filter->queue;
3946 * igb_ntuple_filter_handle - Handle operations for ntuple filter.
3947 * @dev: pointer to rte_eth_dev structure
3948 * @filter_op:operation will be taken.
3949 * @arg: a pointer to specific structure corresponding to the filter_op
3952 igb_ntuple_filter_handle(struct rte_eth_dev *dev,
3953 enum rte_filter_op filter_op,
3956 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3959 MAC_TYPE_FILTER_SUP(hw->mac.type);
3961 if (filter_op == RTE_ETH_FILTER_NOP)
3965 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
3970 switch (filter_op) {
3971 case RTE_ETH_FILTER_ADD:
3972 ret = igb_add_del_ntuple_filter(dev,
3973 (struct rte_eth_ntuple_filter *)arg,
3976 case RTE_ETH_FILTER_DELETE:
3977 ret = igb_add_del_ntuple_filter(dev,
3978 (struct rte_eth_ntuple_filter *)arg,
3981 case RTE_ETH_FILTER_GET:
3982 ret = igb_get_ntuple_filter(dev,
3983 (struct rte_eth_ntuple_filter *)arg);
3986 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
3994 igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
3999 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4000 if (filter_info->ethertype_filters[i] == ethertype &&
4001 (filter_info->ethertype_mask & (1 << i)))
4008 igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
4013 for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4014 if (!(filter_info->ethertype_mask & (1 << i))) {
4015 filter_info->ethertype_mask |= 1 << i;
4016 filter_info->ethertype_filters[i] = ethertype;
4024 igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
4027 if (idx >= E1000_MAX_ETQF_FILTERS)
4029 filter_info->ethertype_mask &= ~(1 << idx);
4030 filter_info->ethertype_filters[idx] = 0;
4036 igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
4037 struct rte_eth_ethertype_filter *filter,
4040 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4041 struct e1000_filter_info *filter_info =
4042 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4046 if (filter->ether_type == ETHER_TYPE_IPv4 ||
4047 filter->ether_type == ETHER_TYPE_IPv6) {
4048 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
4049 " ethertype filter.", filter->ether_type);
4053 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
4054 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
4057 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
4058 PMD_DRV_LOG(ERR, "drop option is unsupported.");
4062 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4063 if (ret >= 0 && add) {
4064 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
4065 filter->ether_type);
4068 if (ret < 0 && !add) {
4069 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4070 filter->ether_type);
4075 ret = igb_ethertype_filter_insert(filter_info,
4076 filter->ether_type);
4078 PMD_DRV_LOG(ERR, "ethertype filters are full.");
4082 etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
4083 etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
4084 etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
4086 ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
4090 E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
4091 E1000_WRITE_FLUSH(hw);
4097 igb_get_ethertype_filter(struct rte_eth_dev *dev,
4098 struct rte_eth_ethertype_filter *filter)
4100 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4101 struct e1000_filter_info *filter_info =
4102 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4106 ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4108 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4109 filter->ether_type);
4113 etqf = E1000_READ_REG(hw, E1000_ETQF(ret));
4114 if (etqf & E1000_ETQF_FILTER_ENABLE) {
4115 filter->ether_type = etqf & E1000_ETQF_ETHERTYPE;
4117 filter->queue = (etqf & E1000_ETQF_QUEUE) >>
4118 E1000_ETQF_QUEUE_SHIFT;
4126 * igb_ethertype_filter_handle - Handle operations for ethertype filter.
4127 * @dev: pointer to rte_eth_dev structure
4128 * @filter_op:operation will be taken.
4129 * @arg: a pointer to specific structure corresponding to the filter_op
4132 igb_ethertype_filter_handle(struct rte_eth_dev *dev,
4133 enum rte_filter_op filter_op,
4136 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4139 MAC_TYPE_FILTER_SUP(hw->mac.type);
4141 if (filter_op == RTE_ETH_FILTER_NOP)
4145 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4150 switch (filter_op) {
4151 case RTE_ETH_FILTER_ADD:
4152 ret = igb_add_del_ethertype_filter(dev,
4153 (struct rte_eth_ethertype_filter *)arg,
4156 case RTE_ETH_FILTER_DELETE:
4157 ret = igb_add_del_ethertype_filter(dev,
4158 (struct rte_eth_ethertype_filter *)arg,
4161 case RTE_ETH_FILTER_GET:
4162 ret = igb_get_ethertype_filter(dev,
4163 (struct rte_eth_ethertype_filter *)arg);
4166 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4174 eth_igb_filter_ctrl(struct rte_eth_dev *dev,
4175 enum rte_filter_type filter_type,
4176 enum rte_filter_op filter_op,
4181 switch (filter_type) {
4182 case RTE_ETH_FILTER_NTUPLE:
4183 ret = igb_ntuple_filter_handle(dev, filter_op, arg);
4185 case RTE_ETH_FILTER_ETHERTYPE:
4186 ret = igb_ethertype_filter_handle(dev, filter_op, arg);
4188 case RTE_ETH_FILTER_SYN:
4189 ret = eth_igb_syn_filter_handle(dev, filter_op, arg);
4191 case RTE_ETH_FILTER_FLEXIBLE:
4192 ret = eth_igb_flex_filter_handle(dev, filter_op, arg);
4195 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
4204 eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
4205 struct ether_addr *mc_addr_set,
4206 uint32_t nb_mc_addr)
4208 struct e1000_hw *hw;
4210 hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4211 e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
4216 igb_read_systime_cyclecounter(struct rte_eth_dev *dev)
4218 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4219 uint64_t systime_cycles;
4221 switch (hw->mac.type) {
4225 * Need to read System Time Residue Register to be able
4226 * to read the other two registers.
4228 E1000_READ_REG(hw, E1000_SYSTIMR);
4229 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
4230 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4231 systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4238 * Need to read System Time Residue Register to be able
4239 * to read the other two registers.
4241 E1000_READ_REG(hw, E1000_SYSTIMR);
4242 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4243 /* Only the 8 LSB are valid. */
4244 systime_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_SYSTIMH)
4248 systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4249 systime_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4254 return systime_cycles;
4258 igb_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4260 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4261 uint64_t rx_tstamp_cycles;
4263 switch (hw->mac.type) {
4266 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4267 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4268 rx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4274 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4275 /* Only the 8 LSB are valid. */
4276 rx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_RXSTMPH)
4280 rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4281 rx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4286 return rx_tstamp_cycles;
4290 igb_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4292 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4293 uint64_t tx_tstamp_cycles;
4295 switch (hw->mac.type) {
4298 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4299 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4300 tx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4306 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4307 /* Only the 8 LSB are valid. */
4308 tx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_TXSTMPH)
4312 tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4313 tx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4318 return tx_tstamp_cycles;
4322 igb_start_timecounters(struct rte_eth_dev *dev)
4324 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4325 struct e1000_adapter *adapter =
4326 (struct e1000_adapter *)dev->data->dev_private;
4327 uint32_t incval = 1;
4329 uint64_t mask = E1000_CYCLECOUNTER_MASK;
4331 switch (hw->mac.type) {
4335 /* 32 LSB bits + 8 MSB bits = 40 bits */
4336 mask = (1ULL << 40) - 1;
4341 * Start incrementing the register
4342 * used to timestamp PTP packets.
4344 E1000_WRITE_REG(hw, E1000_TIMINCA, incval);
4347 incval = E1000_INCVALUE_82576;
4348 shift = IGB_82576_TSYNC_SHIFT;
4349 E1000_WRITE_REG(hw, E1000_TIMINCA,
4350 E1000_INCPERIOD_82576 | incval);
4357 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
4358 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4359 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4361 adapter->systime_tc.cc_mask = mask;
4362 adapter->systime_tc.cc_shift = shift;
4363 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
4365 adapter->rx_tstamp_tc.cc_mask = mask;
4366 adapter->rx_tstamp_tc.cc_shift = shift;
4367 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4369 adapter->tx_tstamp_tc.cc_mask = mask;
4370 adapter->tx_tstamp_tc.cc_shift = shift;
4371 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4375 igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
4377 struct e1000_adapter *adapter =
4378 (struct e1000_adapter *)dev->data->dev_private;
4380 adapter->systime_tc.nsec += delta;
4381 adapter->rx_tstamp_tc.nsec += delta;
4382 adapter->tx_tstamp_tc.nsec += delta;
4388 igb_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
4391 struct e1000_adapter *adapter =
4392 (struct e1000_adapter *)dev->data->dev_private;
4394 ns = rte_timespec_to_ns(ts);
4396 /* Set the timecounters to a new value. */
4397 adapter->systime_tc.nsec = ns;
4398 adapter->rx_tstamp_tc.nsec = ns;
4399 adapter->tx_tstamp_tc.nsec = ns;
4405 igb_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
4407 uint64_t ns, systime_cycles;
4408 struct e1000_adapter *adapter =
4409 (struct e1000_adapter *)dev->data->dev_private;
4411 systime_cycles = igb_read_systime_cyclecounter(dev);
4412 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
4413 *ts = rte_ns_to_timespec(ns);
4419 igb_timesync_enable(struct rte_eth_dev *dev)
4421 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4425 /* Stop the timesync system time. */
4426 E1000_WRITE_REG(hw, E1000_TIMINCA, 0x0);
4427 /* Reset the timesync system time value. */
4428 switch (hw->mac.type) {
4434 E1000_WRITE_REG(hw, E1000_SYSTIMR, 0x0);
4437 E1000_WRITE_REG(hw, E1000_SYSTIML, 0x0);
4438 E1000_WRITE_REG(hw, E1000_SYSTIMH, 0x0);
4441 /* Not supported. */
4445 /* Enable system time for it isn't on by default. */
4446 tsauxc = E1000_READ_REG(hw, E1000_TSAUXC);
4447 tsauxc &= ~E1000_TSAUXC_DISABLE_SYSTIME;
4448 E1000_WRITE_REG(hw, E1000_TSAUXC, tsauxc);
4450 igb_start_timecounters(dev);
4452 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
4453 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588),
4455 E1000_ETQF_FILTER_ENABLE |
4458 /* Enable timestamping of received PTP packets. */
4459 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4460 tsync_ctl |= E1000_TSYNCRXCTL_ENABLED;
4461 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
4463 /* Enable Timestamping of transmitted PTP packets. */
4464 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4465 tsync_ctl |= E1000_TSYNCTXCTL_ENABLED;
4466 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
4472 igb_timesync_disable(struct rte_eth_dev *dev)
4474 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4477 /* Disable timestamping of transmitted PTP packets. */
4478 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4479 tsync_ctl &= ~E1000_TSYNCTXCTL_ENABLED;
4480 E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
4482 /* Disable timestamping of received PTP packets. */
4483 tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4484 tsync_ctl &= ~E1000_TSYNCRXCTL_ENABLED;
4485 E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
4487 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
4488 E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588), 0);
4490 /* Stop incrementating the System Time registers. */
4491 E1000_WRITE_REG(hw, E1000_TIMINCA, 0);
4497 igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
4498 struct timespec *timestamp,
4499 uint32_t flags __rte_unused)
4501 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4502 struct e1000_adapter *adapter =
4503 (struct e1000_adapter *)dev->data->dev_private;
4504 uint32_t tsync_rxctl;
4505 uint64_t rx_tstamp_cycles;
4508 tsync_rxctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
4509 if ((tsync_rxctl & E1000_TSYNCRXCTL_VALID) == 0)
4512 rx_tstamp_cycles = igb_read_rx_tstamp_cyclecounter(dev);
4513 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
4514 *timestamp = rte_ns_to_timespec(ns);
4520 igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
4521 struct timespec *timestamp)
4523 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4524 struct e1000_adapter *adapter =
4525 (struct e1000_adapter *)dev->data->dev_private;
4526 uint32_t tsync_txctl;
4527 uint64_t tx_tstamp_cycles;
4530 tsync_txctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
4531 if ((tsync_txctl & E1000_TSYNCTXCTL_VALID) == 0)
4534 tx_tstamp_cycles = igb_read_tx_tstamp_cyclecounter(dev);
4535 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
4536 *timestamp = rte_ns_to_timespec(ns);
4542 eth_igb_get_reg_length(struct rte_eth_dev *dev __rte_unused)
4546 const struct reg_info *reg_group;
4548 while ((reg_group = igb_regs[g_ind++]))
4549 count += igb_reg_group_count(reg_group);
4555 igbvf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
4559 const struct reg_info *reg_group;
4561 while ((reg_group = igbvf_regs[g_ind++]))
4562 count += igb_reg_group_count(reg_group);
4568 eth_igb_get_regs(struct rte_eth_dev *dev,
4569 struct rte_dev_reg_info *regs)
4571 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4572 uint32_t *data = regs->data;
4575 const struct reg_info *reg_group;
4577 /* Support only full register dump */
4578 if ((regs->length == 0) ||
4579 (regs->length == (uint32_t)eth_igb_get_reg_length(dev))) {
4580 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
4582 while ((reg_group = igb_regs[g_ind++]))
4583 count += igb_read_regs_group(dev, &data[count],
4592 igbvf_get_regs(struct rte_eth_dev *dev,
4593 struct rte_dev_reg_info *regs)
4595 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4596 uint32_t *data = regs->data;
4599 const struct reg_info *reg_group;
4601 /* Support only full register dump */
4602 if ((regs->length == 0) ||
4603 (regs->length == (uint32_t)igbvf_get_reg_length(dev))) {
4604 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
4606 while ((reg_group = igbvf_regs[g_ind++]))
4607 count += igb_read_regs_group(dev, &data[count],
4616 eth_igb_get_eeprom_length(struct rte_eth_dev *dev)
4618 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4620 /* Return unit is byte count */
4621 return hw->nvm.word_size * 2;
4625 eth_igb_get_eeprom(struct rte_eth_dev *dev,
4626 struct rte_dev_eeprom_info *in_eeprom)
4628 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4629 struct e1000_nvm_info *nvm = &hw->nvm;
4630 uint16_t *data = in_eeprom->data;
4633 first = in_eeprom->offset >> 1;
4634 length = in_eeprom->length >> 1;
4635 if ((first >= hw->nvm.word_size) ||
4636 ((first + length) >= hw->nvm.word_size))
4639 in_eeprom->magic = hw->vendor_id |
4640 ((uint32_t)hw->device_id << 16);
4642 if ((nvm->ops.read) == NULL)
4645 return nvm->ops.read(hw, first, length, data);
4649 eth_igb_set_eeprom(struct rte_eth_dev *dev,
4650 struct rte_dev_eeprom_info *in_eeprom)
4652 struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4653 struct e1000_nvm_info *nvm = &hw->nvm;
4654 uint16_t *data = in_eeprom->data;
4657 first = in_eeprom->offset >> 1;
4658 length = in_eeprom->length >> 1;
4659 if ((first >= hw->nvm.word_size) ||
4660 ((first + length) >= hw->nvm.word_size))
4663 in_eeprom->magic = (uint32_t)hw->vendor_id |
4664 ((uint32_t)hw->device_id << 16);
4666 if ((nvm->ops.write) == NULL)
4668 return nvm->ops.write(hw, first, length, data);
4671 static struct rte_driver pmd_igb_drv = {
4673 .init = rte_igb_pmd_init,
4676 static struct rte_driver pmd_igbvf_drv = {
4678 .init = rte_igbvf_pmd_init,
4682 eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
4684 struct e1000_hw *hw =
4685 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4686 uint32_t mask = 1 << queue_id;
4688 E1000_WRITE_REG(hw, E1000_EIMC, mask);
4689 E1000_WRITE_FLUSH(hw);
4695 eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
4697 struct e1000_hw *hw =
4698 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4699 uint32_t mask = 1 << queue_id;
4702 regval = E1000_READ_REG(hw, E1000_EIMS);
4703 E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
4704 E1000_WRITE_FLUSH(hw);
4706 rte_intr_enable(&dev->pci_dev->intr_handle);
4712 eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
4713 uint8_t index, uint8_t offset)
4715 uint32_t val = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
4718 val &= ~((uint32_t)0xFF << offset);
4720 /* write vector and valid bit */
4721 val |= (msix_vector | E1000_IVAR_VALID) << offset;
4723 E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, val);
4727 eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
4728 uint8_t queue, uint8_t msix_vector)
4732 if (hw->mac.type == e1000_82575) {
4734 tmp = E1000_EICR_RX_QUEUE0 << queue;
4735 else if (direction == 1)
4736 tmp = E1000_EICR_TX_QUEUE0 << queue;
4737 E1000_WRITE_REG(hw, E1000_MSIXBM(msix_vector), tmp);
4738 } else if (hw->mac.type == e1000_82576) {
4739 if ((direction == 0) || (direction == 1))
4740 eth_igb_write_ivar(hw, msix_vector, queue & 0x7,
4741 ((queue & 0x8) << 1) +
4743 } else if ((hw->mac.type == e1000_82580) ||
4744 (hw->mac.type == e1000_i350) ||
4745 (hw->mac.type == e1000_i354) ||
4746 (hw->mac.type == e1000_i210) ||
4747 (hw->mac.type == e1000_i211)) {
4748 if ((direction == 0) || (direction == 1))
4749 eth_igb_write_ivar(hw, msix_vector,
4751 ((queue & 0x1) << 4) +
4756 /* Sets up the hardware to generate MSI-X interrupts properly
4758 * board private structure
4761 eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
4764 uint32_t tmpval, regval, intr_mask;
4765 struct e1000_hw *hw =
4766 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4767 uint32_t vec = E1000_MISC_VEC_ID;
4768 uint32_t base = E1000_MISC_VEC_ID;
4769 uint32_t misc_shift = 0;
4771 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
4773 /* won't configure msix register if no mapping is done
4774 * between intr vector and event fd
4776 if (!rte_intr_dp_is_en(intr_handle))
4779 if (rte_intr_allow_others(intr_handle)) {
4780 vec = base = E1000_RX_VEC_START;
4784 /* set interrupt vector for other causes */
4785 if (hw->mac.type == e1000_82575) {
4786 tmpval = E1000_READ_REG(hw, E1000_CTRL_EXT);
4787 /* enable MSI-X PBA support */
4788 tmpval |= E1000_CTRL_EXT_PBA_CLR;
4790 /* Auto-Mask interrupts upon ICR read */
4791 tmpval |= E1000_CTRL_EXT_EIAME;
4792 tmpval |= E1000_CTRL_EXT_IRCA;
4794 E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmpval);
4796 /* enable msix_other interrupt */
4797 E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), 0, E1000_EIMS_OTHER);
4798 regval = E1000_READ_REG(hw, E1000_EIAC);
4799 E1000_WRITE_REG(hw, E1000_EIAC, regval | E1000_EIMS_OTHER);
4800 regval = E1000_READ_REG(hw, E1000_EIAM);
4801 E1000_WRITE_REG(hw, E1000_EIMS, regval | E1000_EIMS_OTHER);
4802 } else if ((hw->mac.type == e1000_82576) ||
4803 (hw->mac.type == e1000_82580) ||
4804 (hw->mac.type == e1000_i350) ||
4805 (hw->mac.type == e1000_i354) ||
4806 (hw->mac.type == e1000_i210) ||
4807 (hw->mac.type == e1000_i211)) {
4808 /* turn on MSI-X capability first */
4809 E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
4810 E1000_GPIE_PBA | E1000_GPIE_EIAME |
4812 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
4814 regval = E1000_READ_REG(hw, E1000_EIAC);
4815 E1000_WRITE_REG(hw, E1000_EIAC, regval | intr_mask);
4817 /* enable msix_other interrupt */
4818 regval = E1000_READ_REG(hw, E1000_EIMS);
4819 E1000_WRITE_REG(hw, E1000_EIMS, regval | intr_mask);
4820 tmpval = (dev->data->nb_rx_queues | E1000_IVAR_VALID) << 8;
4821 E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmpval);
4824 /* use EIAM to auto-mask when MSI-X interrupt
4825 * is asserted, this saves a register write for every interrupt
4827 intr_mask = RTE_LEN2MASK(intr_handle->nb_efd, uint32_t) <<
4829 regval = E1000_READ_REG(hw, E1000_EIAM);
4830 E1000_WRITE_REG(hw, E1000_EIAM, regval | intr_mask);
4832 for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
4833 eth_igb_assign_msix_vector(hw, 0, queue_id, vec);
4834 intr_handle->intr_vec[queue_id] = vec;
4835 if (vec < base + intr_handle->nb_efd - 1)
4839 E1000_WRITE_FLUSH(hw);
4842 PMD_REGISTER_DRIVER(pmd_igb_drv);
4843 PMD_REGISTER_DRIVER(pmd_igbvf_drv);