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>
42 #include <netinet/in.h>
43 #include <rte_byteorder.h>
44 #include <rte_common.h>
45 #include <rte_cycles.h>
47 #include <rte_interrupts.h>
49 #include <rte_debug.h>
51 #include <rte_atomic.h>
52 #include <rte_branch_prediction.h>
53 #include <rte_memory.h>
54 #include <rte_memzone.h>
56 #include <rte_alarm.h>
57 #include <rte_ether.h>
58 #include <rte_ethdev.h>
59 #include <rte_atomic.h>
60 #include <rte_malloc.h>
61 #include <rte_random.h>
64 #include "ixgbe_logs.h"
65 #include "base/ixgbe_api.h"
66 #include "base/ixgbe_vf.h"
67 #include "base/ixgbe_common.h"
68 #include "ixgbe_ethdev.h"
69 #include "ixgbe_bypass.h"
70 #include "ixgbe_rxtx.h"
73 * High threshold controlling when to start sending XOFF frames. Must be at
74 * least 8 bytes less than receive packet buffer size. This value is in units
77 #define IXGBE_FC_HI 0x80
80 * Low threshold controlling when to start sending XON frames. This value is
81 * in units of 1024 bytes.
83 #define IXGBE_FC_LO 0x40
85 /* Timer value included in XOFF frames. */
86 #define IXGBE_FC_PAUSE 0x680
88 #define IXGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
89 #define IXGBE_LINK_UP_CHECK_TIMEOUT 1000 /* ms */
90 #define IXGBE_VMDQ_NUM_UC_MAC 4096 /* Maximum nb. of UC MAC addr. */
92 #define IXGBE_MMW_SIZE_DEFAULT 0x4
93 #define IXGBE_MMW_SIZE_JUMBO_FRAME 0x14
96 * Default values for RX/TX configuration
98 #define IXGBE_DEFAULT_RX_FREE_THRESH 32
99 #define IXGBE_DEFAULT_RX_PTHRESH 8
100 #define IXGBE_DEFAULT_RX_HTHRESH 8
101 #define IXGBE_DEFAULT_RX_WTHRESH 0
103 #define IXGBE_DEFAULT_TX_FREE_THRESH 32
104 #define IXGBE_DEFAULT_TX_PTHRESH 32
105 #define IXGBE_DEFAULT_TX_HTHRESH 0
106 #define IXGBE_DEFAULT_TX_WTHRESH 0
107 #define IXGBE_DEFAULT_TX_RSBIT_THRESH 32
109 /* Bit shift and mask */
110 #define IXGBE_4_BIT_WIDTH (CHAR_BIT / 2)
111 #define IXGBE_4_BIT_MASK RTE_LEN2MASK(IXGBE_4_BIT_WIDTH, uint8_t)
112 #define IXGBE_8_BIT_WIDTH CHAR_BIT
113 #define IXGBE_8_BIT_MASK UINT8_MAX
115 #define IXGBEVF_PMD_NAME "rte_ixgbevf_pmd" /* PMD name */
117 #define IXGBE_QUEUE_STAT_COUNTERS (sizeof(hw_stats->qprc) / sizeof(hw_stats->qprc[0]))
119 #define IXGBE_HKEY_MAX_INDEX 10
121 /* Additional timesync values. */
122 #define IXGBE_TIMINCA_16NS_SHIFT 24
123 #define IXGBE_TIMINCA_INCVALUE 16000000
124 #define IXGBE_TIMINCA_INIT ((0x02 << IXGBE_TIMINCA_16NS_SHIFT) \
125 | IXGBE_TIMINCA_INCVALUE)
127 static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev);
128 static int ixgbe_dev_configure(struct rte_eth_dev *dev);
129 static int ixgbe_dev_start(struct rte_eth_dev *dev);
130 static void ixgbe_dev_stop(struct rte_eth_dev *dev);
131 static int ixgbe_dev_set_link_up(struct rte_eth_dev *dev);
132 static int ixgbe_dev_set_link_down(struct rte_eth_dev *dev);
133 static void ixgbe_dev_close(struct rte_eth_dev *dev);
134 static void ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
135 static void ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
136 static void ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
137 static void ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev);
138 static int ixgbe_dev_link_update(struct rte_eth_dev *dev,
139 int wait_to_complete);
140 static void ixgbe_dev_stats_get(struct rte_eth_dev *dev,
141 struct rte_eth_stats *stats);
142 static void ixgbe_dev_stats_reset(struct rte_eth_dev *dev);
143 static int ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
147 static void ixgbe_dev_info_get(struct rte_eth_dev *dev,
148 struct rte_eth_dev_info *dev_info);
149 static void ixgbevf_dev_info_get(struct rte_eth_dev *dev,
150 struct rte_eth_dev_info *dev_info);
151 static int ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
153 static int ixgbe_vlan_filter_set(struct rte_eth_dev *dev,
154 uint16_t vlan_id, int on);
155 static void ixgbe_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid_id);
156 static void ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
157 uint16_t queue, bool on);
158 static void ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue,
160 static void ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask);
161 static void ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue);
162 static void ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue);
163 static void ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev);
164 static void ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev);
166 static int ixgbe_dev_led_on(struct rte_eth_dev *dev);
167 static int ixgbe_dev_led_off(struct rte_eth_dev *dev);
168 static int ixgbe_flow_ctrl_get(struct rte_eth_dev *dev,
169 struct rte_eth_fc_conf *fc_conf);
170 static int ixgbe_flow_ctrl_set(struct rte_eth_dev *dev,
171 struct rte_eth_fc_conf *fc_conf);
172 static int ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev,
173 struct rte_eth_pfc_conf *pfc_conf);
174 static int ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
175 struct rte_eth_rss_reta_entry64 *reta_conf,
177 static int ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
178 struct rte_eth_rss_reta_entry64 *reta_conf,
180 static void ixgbe_dev_link_status_print(struct rte_eth_dev *dev);
181 static int ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev);
182 static int ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev);
183 static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev);
184 static void ixgbe_dev_interrupt_handler(struct rte_intr_handle *handle,
186 static void ixgbe_dev_interrupt_delayed_handler(void *param);
187 static void ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
188 uint32_t index, uint32_t pool);
189 static void ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index);
190 static void ixgbe_dcb_init(struct ixgbe_hw *hw,struct ixgbe_dcb_config *dcb_config);
192 /* For Virtual Function support */
193 static int eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev);
194 static int ixgbevf_dev_configure(struct rte_eth_dev *dev);
195 static int ixgbevf_dev_start(struct rte_eth_dev *dev);
196 static void ixgbevf_dev_stop(struct rte_eth_dev *dev);
197 static void ixgbevf_dev_close(struct rte_eth_dev *dev);
198 static void ixgbevf_intr_disable(struct ixgbe_hw *hw);
199 static void ixgbevf_dev_stats_get(struct rte_eth_dev *dev,
200 struct rte_eth_stats *stats);
201 static void ixgbevf_dev_stats_reset(struct rte_eth_dev *dev);
202 static int ixgbevf_vlan_filter_set(struct rte_eth_dev *dev,
203 uint16_t vlan_id, int on);
204 static void ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev,
205 uint16_t queue, int on);
206 static void ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
207 static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
209 /* For Eth VMDQ APIs support */
210 static int ixgbe_uc_hash_table_set(struct rte_eth_dev *dev, struct
211 ether_addr* mac_addr,uint8_t on);
212 static int ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev,uint8_t on);
213 static int ixgbe_set_pool_rx_mode(struct rte_eth_dev *dev, uint16_t pool,
214 uint16_t rx_mask, uint8_t on);
215 static int ixgbe_set_pool_rx(struct rte_eth_dev *dev,uint16_t pool,uint8_t on);
216 static int ixgbe_set_pool_tx(struct rte_eth_dev *dev,uint16_t pool,uint8_t on);
217 static int ixgbe_set_pool_vlan_filter(struct rte_eth_dev *dev, uint16_t vlan,
218 uint64_t pool_mask,uint8_t vlan_on);
219 static int ixgbe_mirror_rule_set(struct rte_eth_dev *dev,
220 struct rte_eth_mirror_conf *mirror_conf,
221 uint8_t rule_id, uint8_t on);
222 static int ixgbe_mirror_rule_reset(struct rte_eth_dev *dev,
225 static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
226 uint16_t queue_idx, uint16_t tx_rate);
227 static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
228 uint16_t tx_rate, uint64_t q_msk);
230 static void ixgbevf_add_mac_addr(struct rte_eth_dev *dev,
231 struct ether_addr *mac_addr,
232 uint32_t index, uint32_t pool);
233 static void ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
234 static int ixgbe_syn_filter_set(struct rte_eth_dev *dev,
235 struct rte_eth_syn_filter *filter,
237 static int ixgbe_syn_filter_get(struct rte_eth_dev *dev,
238 struct rte_eth_syn_filter *filter);
239 static int ixgbe_syn_filter_handle(struct rte_eth_dev *dev,
240 enum rte_filter_op filter_op,
242 static int ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
243 struct ixgbe_5tuple_filter *filter);
244 static void ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
245 struct ixgbe_5tuple_filter *filter);
246 static int ixgbe_add_del_ntuple_filter(struct rte_eth_dev *dev,
247 struct rte_eth_ntuple_filter *filter,
249 static int ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
250 enum rte_filter_op filter_op,
252 static int ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
253 struct rte_eth_ntuple_filter *filter);
254 static int ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
255 struct rte_eth_ethertype_filter *filter,
257 static int ixgbe_ethertype_filter_handle(struct rte_eth_dev *dev,
258 enum rte_filter_op filter_op,
260 static int ixgbe_get_ethertype_filter(struct rte_eth_dev *dev,
261 struct rte_eth_ethertype_filter *filter);
262 static int ixgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
263 enum rte_filter_type filter_type,
264 enum rte_filter_op filter_op,
266 static int ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
268 static int ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
269 struct ether_addr *mc_addr_set,
270 uint32_t nb_mc_addr);
272 static int ixgbe_timesync_enable(struct rte_eth_dev *dev);
273 static int ixgbe_timesync_disable(struct rte_eth_dev *dev);
274 static int ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
275 struct timespec *timestamp,
277 static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
278 struct timespec *timestamp);
281 * Define VF Stats MACRO for Non "cleared on read" register
283 #define UPDATE_VF_STAT(reg, last, cur) \
285 u32 latest = IXGBE_READ_REG(hw, reg); \
286 cur += latest - last; \
290 #define UPDATE_VF_STAT_36BIT(lsb, msb, last, cur) \
292 u64 new_lsb = IXGBE_READ_REG(hw, lsb); \
293 u64 new_msb = IXGBE_READ_REG(hw, msb); \
294 u64 latest = ((new_msb << 32) | new_lsb); \
295 cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \
299 #define IXGBE_SET_HWSTRIP(h, q) do{\
300 uint32_t idx = (q) / (sizeof ((h)->bitmap[0]) * NBBY); \
301 uint32_t bit = (q) % (sizeof ((h)->bitmap[0]) * NBBY); \
302 (h)->bitmap[idx] |= 1 << bit;\
305 #define IXGBE_CLEAR_HWSTRIP(h, q) do{\
306 uint32_t idx = (q) / (sizeof ((h)->bitmap[0]) * NBBY); \
307 uint32_t bit = (q) % (sizeof ((h)->bitmap[0]) * NBBY); \
308 (h)->bitmap[idx] &= ~(1 << bit);\
311 #define IXGBE_GET_HWSTRIP(h, q, r) do{\
312 uint32_t idx = (q) / (sizeof ((h)->bitmap[0]) * NBBY); \
313 uint32_t bit = (q) % (sizeof ((h)->bitmap[0]) * NBBY); \
314 (r) = (h)->bitmap[idx] >> bit & 1;\
318 * The set of PCI devices this driver supports
320 static const struct rte_pci_id pci_id_ixgbe_map[] = {
322 #define RTE_PCI_DEV_ID_DECL_IXGBE(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
323 #include "rte_pci_dev_ids.h"
325 { .vendor_id = 0, /* sentinel */ },
330 * The set of PCI devices this driver supports (for 82599 VF)
332 static const struct rte_pci_id pci_id_ixgbevf_map[] = {
334 #define RTE_PCI_DEV_ID_DECL_IXGBEVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
335 #include "rte_pci_dev_ids.h"
336 { .vendor_id = 0, /* sentinel */ },
340 static const struct eth_dev_ops ixgbe_eth_dev_ops = {
341 .dev_configure = ixgbe_dev_configure,
342 .dev_start = ixgbe_dev_start,
343 .dev_stop = ixgbe_dev_stop,
344 .dev_set_link_up = ixgbe_dev_set_link_up,
345 .dev_set_link_down = ixgbe_dev_set_link_down,
346 .dev_close = ixgbe_dev_close,
347 .promiscuous_enable = ixgbe_dev_promiscuous_enable,
348 .promiscuous_disable = ixgbe_dev_promiscuous_disable,
349 .allmulticast_enable = ixgbe_dev_allmulticast_enable,
350 .allmulticast_disable = ixgbe_dev_allmulticast_disable,
351 .link_update = ixgbe_dev_link_update,
352 .stats_get = ixgbe_dev_stats_get,
353 .stats_reset = ixgbe_dev_stats_reset,
354 .queue_stats_mapping_set = ixgbe_dev_queue_stats_mapping_set,
355 .dev_infos_get = ixgbe_dev_info_get,
356 .mtu_set = ixgbe_dev_mtu_set,
357 .vlan_filter_set = ixgbe_vlan_filter_set,
358 .vlan_tpid_set = ixgbe_vlan_tpid_set,
359 .vlan_offload_set = ixgbe_vlan_offload_set,
360 .vlan_strip_queue_set = ixgbe_vlan_strip_queue_set,
361 .rx_queue_start = ixgbe_dev_rx_queue_start,
362 .rx_queue_stop = ixgbe_dev_rx_queue_stop,
363 .tx_queue_start = ixgbe_dev_tx_queue_start,
364 .tx_queue_stop = ixgbe_dev_tx_queue_stop,
365 .rx_queue_setup = ixgbe_dev_rx_queue_setup,
366 .rx_queue_release = ixgbe_dev_rx_queue_release,
367 .rx_queue_count = ixgbe_dev_rx_queue_count,
368 .rx_descriptor_done = ixgbe_dev_rx_descriptor_done,
369 .tx_queue_setup = ixgbe_dev_tx_queue_setup,
370 .tx_queue_release = ixgbe_dev_tx_queue_release,
371 .dev_led_on = ixgbe_dev_led_on,
372 .dev_led_off = ixgbe_dev_led_off,
373 .flow_ctrl_get = ixgbe_flow_ctrl_get,
374 .flow_ctrl_set = ixgbe_flow_ctrl_set,
375 .priority_flow_ctrl_set = ixgbe_priority_flow_ctrl_set,
376 .mac_addr_add = ixgbe_add_rar,
377 .mac_addr_remove = ixgbe_remove_rar,
378 .uc_hash_table_set = ixgbe_uc_hash_table_set,
379 .uc_all_hash_table_set = ixgbe_uc_all_hash_table_set,
380 .mirror_rule_set = ixgbe_mirror_rule_set,
381 .mirror_rule_reset = ixgbe_mirror_rule_reset,
382 .set_vf_rx_mode = ixgbe_set_pool_rx_mode,
383 .set_vf_rx = ixgbe_set_pool_rx,
384 .set_vf_tx = ixgbe_set_pool_tx,
385 .set_vf_vlan_filter = ixgbe_set_pool_vlan_filter,
386 .set_queue_rate_limit = ixgbe_set_queue_rate_limit,
387 .set_vf_rate_limit = ixgbe_set_vf_rate_limit,
388 .reta_update = ixgbe_dev_rss_reta_update,
389 .reta_query = ixgbe_dev_rss_reta_query,
390 #ifdef RTE_NIC_BYPASS
391 .bypass_init = ixgbe_bypass_init,
392 .bypass_state_set = ixgbe_bypass_state_store,
393 .bypass_state_show = ixgbe_bypass_state_show,
394 .bypass_event_set = ixgbe_bypass_event_store,
395 .bypass_event_show = ixgbe_bypass_event_show,
396 .bypass_wd_timeout_set = ixgbe_bypass_wd_timeout_store,
397 .bypass_wd_timeout_show = ixgbe_bypass_wd_timeout_show,
398 .bypass_ver_show = ixgbe_bypass_ver_show,
399 .bypass_wd_reset = ixgbe_bypass_wd_reset,
400 #endif /* RTE_NIC_BYPASS */
401 .rss_hash_update = ixgbe_dev_rss_hash_update,
402 .rss_hash_conf_get = ixgbe_dev_rss_hash_conf_get,
403 .filter_ctrl = ixgbe_dev_filter_ctrl,
404 .set_mc_addr_list = ixgbe_dev_set_mc_addr_list,
405 .timesync_enable = ixgbe_timesync_enable,
406 .timesync_disable = ixgbe_timesync_disable,
407 .timesync_read_rx_timestamp = ixgbe_timesync_read_rx_timestamp,
408 .timesync_read_tx_timestamp = ixgbe_timesync_read_tx_timestamp,
412 * dev_ops for virtual function, bare necessities for basic vf
413 * operation have been implemented
415 static const struct eth_dev_ops ixgbevf_eth_dev_ops = {
416 .dev_configure = ixgbevf_dev_configure,
417 .dev_start = ixgbevf_dev_start,
418 .dev_stop = ixgbevf_dev_stop,
419 .link_update = ixgbe_dev_link_update,
420 .stats_get = ixgbevf_dev_stats_get,
421 .stats_reset = ixgbevf_dev_stats_reset,
422 .dev_close = ixgbevf_dev_close,
423 .dev_infos_get = ixgbevf_dev_info_get,
424 .mtu_set = ixgbevf_dev_set_mtu,
425 .vlan_filter_set = ixgbevf_vlan_filter_set,
426 .vlan_strip_queue_set = ixgbevf_vlan_strip_queue_set,
427 .vlan_offload_set = ixgbevf_vlan_offload_set,
428 .rx_queue_setup = ixgbe_dev_rx_queue_setup,
429 .rx_queue_release = ixgbe_dev_rx_queue_release,
430 .tx_queue_setup = ixgbe_dev_tx_queue_setup,
431 .tx_queue_release = ixgbe_dev_tx_queue_release,
432 .mac_addr_add = ixgbevf_add_mac_addr,
433 .mac_addr_remove = ixgbevf_remove_mac_addr,
434 .set_mc_addr_list = ixgbe_dev_set_mc_addr_list,
438 * Atomically reads the link status information from global
439 * structure rte_eth_dev.
442 * - Pointer to the structure rte_eth_dev to read from.
443 * - Pointer to the buffer to be saved with the link status.
446 * - On success, zero.
447 * - On failure, negative value.
450 rte_ixgbe_dev_atomic_read_link_status(struct rte_eth_dev *dev,
451 struct rte_eth_link *link)
453 struct rte_eth_link *dst = link;
454 struct rte_eth_link *src = &(dev->data->dev_link);
456 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
457 *(uint64_t *)src) == 0)
464 * Atomically writes the link status information into global
465 * structure rte_eth_dev.
468 * - Pointer to the structure rte_eth_dev to read from.
469 * - Pointer to the buffer to be saved with the link status.
472 * - On success, zero.
473 * - On failure, negative value.
476 rte_ixgbe_dev_atomic_write_link_status(struct rte_eth_dev *dev,
477 struct rte_eth_link *link)
479 struct rte_eth_link *dst = &(dev->data->dev_link);
480 struct rte_eth_link *src = link;
482 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
483 *(uint64_t *)src) == 0)
490 * This function is the same as ixgbe_is_sfp() in base/ixgbe.h.
493 ixgbe_is_sfp(struct ixgbe_hw *hw)
495 switch (hw->phy.type) {
496 case ixgbe_phy_sfp_avago:
497 case ixgbe_phy_sfp_ftl:
498 case ixgbe_phy_sfp_intel:
499 case ixgbe_phy_sfp_unknown:
500 case ixgbe_phy_sfp_passive_tyco:
501 case ixgbe_phy_sfp_passive_unknown:
508 static inline int32_t
509 ixgbe_pf_reset_hw(struct ixgbe_hw *hw)
514 status = ixgbe_reset_hw(hw);
516 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
517 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
518 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
519 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
520 IXGBE_WRITE_FLUSH(hw);
526 ixgbe_enable_intr(struct rte_eth_dev *dev)
528 struct ixgbe_interrupt *intr =
529 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
530 struct ixgbe_hw *hw =
531 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
533 IXGBE_WRITE_REG(hw, IXGBE_EIMS, intr->mask);
534 IXGBE_WRITE_FLUSH(hw);
538 * This function is based on ixgbe_disable_intr() in base/ixgbe.h.
541 ixgbe_disable_intr(struct ixgbe_hw *hw)
543 PMD_INIT_FUNC_TRACE();
545 if (hw->mac.type == ixgbe_mac_82598EB) {
546 IXGBE_WRITE_REG(hw, IXGBE_EIMC, ~0);
548 IXGBE_WRITE_REG(hw, IXGBE_EIMC, 0xFFFF0000);
549 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), ~0);
550 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), ~0);
552 IXGBE_WRITE_FLUSH(hw);
556 * This function resets queue statistics mapping registers.
557 * From Niantic datasheet, Initialization of Statistics section:
558 * "...if software requires the queue counters, the RQSMR and TQSM registers
559 * must be re-programmed following a device reset.
562 ixgbe_reset_qstat_mappings(struct ixgbe_hw *hw)
566 for(i = 0; i != IXGBE_NB_STAT_MAPPING_REGS; i++) {
567 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), 0);
568 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), 0);
574 ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
579 #define QSM_REG_NB_BITS_PER_QMAP_FIELD 8
580 #define NB_QMAP_FIELDS_PER_QSM_REG 4
581 #define QMAP_FIELD_RESERVED_BITS_MASK 0x0f
583 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
584 struct ixgbe_stat_mapping_registers *stat_mappings =
585 IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(eth_dev->data->dev_private);
586 uint32_t qsmr_mask = 0;
587 uint32_t clearing_mask = QMAP_FIELD_RESERVED_BITS_MASK;
591 if ((hw->mac.type != ixgbe_mac_82599EB) &&
592 (hw->mac.type != ixgbe_mac_X540) &&
593 (hw->mac.type != ixgbe_mac_X550) &&
594 (hw->mac.type != ixgbe_mac_X550EM_x))
597 PMD_INIT_LOG(INFO, "Setting port %d, %s queue_id %d to stat index %d",
598 (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
601 n = (uint8_t)(queue_id / NB_QMAP_FIELDS_PER_QSM_REG);
602 if (n >= IXGBE_NB_STAT_MAPPING_REGS) {
603 PMD_INIT_LOG(ERR, "Nb of stat mapping registers exceeded");
606 offset = (uint8_t)(queue_id % NB_QMAP_FIELDS_PER_QSM_REG);
608 /* Now clear any previous stat_idx set */
609 clearing_mask <<= (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
611 stat_mappings->tqsm[n] &= ~clearing_mask;
613 stat_mappings->rqsmr[n] &= ~clearing_mask;
615 q_map = (uint32_t)stat_idx;
616 q_map &= QMAP_FIELD_RESERVED_BITS_MASK;
617 qsmr_mask = q_map << (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
619 stat_mappings->tqsm[n] |= qsmr_mask;
621 stat_mappings->rqsmr[n] |= qsmr_mask;
623 PMD_INIT_LOG(INFO, "Set port %d, %s queue_id %d to stat index %d",
624 (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
626 PMD_INIT_LOG(INFO, "%s[%d] = 0x%08x", is_rx ? "RQSMR" : "TQSM", n,
627 is_rx ? stat_mappings->rqsmr[n] : stat_mappings->tqsm[n]);
629 /* Now write the mapping in the appropriate register */
631 PMD_INIT_LOG(INFO, "Write 0x%x to RX IXGBE stat mapping reg:%d",
632 stat_mappings->rqsmr[n], n);
633 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(n), stat_mappings->rqsmr[n]);
636 PMD_INIT_LOG(INFO, "Write 0x%x to TX IXGBE stat mapping reg:%d",
637 stat_mappings->tqsm[n], n);
638 IXGBE_WRITE_REG(hw, IXGBE_TQSM(n), stat_mappings->tqsm[n]);
644 ixgbe_restore_statistics_mapping(struct rte_eth_dev * dev)
646 struct ixgbe_stat_mapping_registers *stat_mappings =
647 IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(dev->data->dev_private);
648 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
651 /* write whatever was in stat mapping table to the NIC */
652 for (i = 0; i < IXGBE_NB_STAT_MAPPING_REGS; i++) {
654 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), stat_mappings->rqsmr[i]);
657 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), stat_mappings->tqsm[i]);
662 ixgbe_dcb_init(struct ixgbe_hw *hw,struct ixgbe_dcb_config *dcb_config)
665 struct ixgbe_dcb_tc_config *tc;
666 uint8_t dcb_max_tc = IXGBE_DCB_MAX_TRAFFIC_CLASS;
668 dcb_config->num_tcs.pg_tcs = dcb_max_tc;
669 dcb_config->num_tcs.pfc_tcs = dcb_max_tc;
670 for (i = 0; i < dcb_max_tc; i++) {
671 tc = &dcb_config->tc_config[i];
672 tc->path[IXGBE_DCB_TX_CONFIG].bwg_id = i;
673 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
674 (uint8_t)(100/dcb_max_tc + (i & 1));
675 tc->path[IXGBE_DCB_RX_CONFIG].bwg_id = i;
676 tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
677 (uint8_t)(100/dcb_max_tc + (i & 1));
678 tc->pfc = ixgbe_dcb_pfc_disabled;
681 /* Initialize default user to priority mapping, UPx->TC0 */
682 tc = &dcb_config->tc_config[0];
683 tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
684 tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
685 for (i = 0; i< IXGBE_DCB_MAX_BW_GROUP; i++) {
686 dcb_config->bw_percentage[IXGBE_DCB_TX_CONFIG][i] = 100;
687 dcb_config->bw_percentage[IXGBE_DCB_RX_CONFIG][i] = 100;
689 dcb_config->rx_pba_cfg = ixgbe_dcb_pba_equal;
690 dcb_config->pfc_mode_enable = false;
691 dcb_config->vt_mode = true;
692 dcb_config->round_robin_enable = false;
693 /* support all DCB capabilities in 82599 */
694 dcb_config->support.capabilities = 0xFF;
696 /*we only support 4 Tcs for X540, X550 */
697 if (hw->mac.type == ixgbe_mac_X540 ||
698 hw->mac.type == ixgbe_mac_X550 ||
699 hw->mac.type == ixgbe_mac_X550EM_x) {
700 dcb_config->num_tcs.pg_tcs = 4;
701 dcb_config->num_tcs.pfc_tcs = 4;
706 * Ensure that all locks are released before first NVM or PHY access
709 ixgbe_swfw_lock_reset(struct ixgbe_hw *hw)
714 * Phy lock should not fail in this early stage. If this is the case,
715 * it is due to an improper exit of the application.
716 * So force the release of the faulty lock. Release of common lock
717 * is done automatically by swfw_sync function.
719 mask = IXGBE_GSSR_PHY0_SM << hw->bus.func;
720 if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
721 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released", hw->bus.func);
723 ixgbe_release_swfw_semaphore(hw, mask);
726 * These ones are more tricky since they are common to all ports; but
727 * swfw_sync retries last long enough (1s) to be almost sure that if
728 * lock can not be taken it is due to an improper lock of the
731 mask = IXGBE_GSSR_EEP_SM | IXGBE_GSSR_MAC_CSR_SM | IXGBE_GSSR_SW_MNG_SM;
732 if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
733 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
735 ixgbe_release_swfw_semaphore(hw, mask);
739 * This function is based on code in ixgbe_attach() in base/ixgbe.c.
740 * It returns 0 on success.
743 eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev)
745 struct rte_pci_device *pci_dev;
746 struct ixgbe_hw *hw =
747 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
748 struct ixgbe_vfta * shadow_vfta =
749 IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
750 struct ixgbe_hwstrip *hwstrip =
751 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
752 struct ixgbe_dcb_config *dcb_config =
753 IXGBE_DEV_PRIVATE_TO_DCB_CFG(eth_dev->data->dev_private);
754 struct ixgbe_filter_info *filter_info =
755 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
760 PMD_INIT_FUNC_TRACE();
762 eth_dev->dev_ops = &ixgbe_eth_dev_ops;
763 eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
764 eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
767 * For secondary processes, we don't initialise any further as primary
768 * has already done this work. Only check we don't need a different
769 * RX and TX function.
771 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
772 struct ixgbe_tx_queue *txq;
773 /* TX queue function in primary, set by last queue initialized
774 * Tx queue may not initialized by primary process */
775 if (eth_dev->data->tx_queues) {
776 txq = eth_dev->data->tx_queues[eth_dev->data->nb_tx_queues-1];
777 ixgbe_set_tx_function(eth_dev, txq);
779 /* Use default TX function if we get here */
780 PMD_INIT_LOG(INFO, "No TX queues configured yet. "
781 "Using default TX function.");
784 ixgbe_set_rx_function(eth_dev);
788 pci_dev = eth_dev->pci_dev;
790 /* Vendor and Device ID need to be set before init of shared code */
791 hw->device_id = pci_dev->id.device_id;
792 hw->vendor_id = pci_dev->id.vendor_id;
793 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
794 hw->allow_unsupported_sfp = 1;
796 /* Initialize the shared code (base driver) */
797 #ifdef RTE_NIC_BYPASS
798 diag = ixgbe_bypass_init_shared_code(hw);
800 diag = ixgbe_init_shared_code(hw);
801 #endif /* RTE_NIC_BYPASS */
803 if (diag != IXGBE_SUCCESS) {
804 PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
808 /* pick up the PCI bus settings for reporting later */
809 ixgbe_get_bus_info(hw);
811 /* Unlock any pending hardware semaphore */
812 ixgbe_swfw_lock_reset(hw);
814 /* Initialize DCB configuration*/
815 memset(dcb_config, 0, sizeof(struct ixgbe_dcb_config));
816 ixgbe_dcb_init(hw,dcb_config);
817 /* Get Hardware Flow Control setting */
818 hw->fc.requested_mode = ixgbe_fc_full;
819 hw->fc.current_mode = ixgbe_fc_full;
820 hw->fc.pause_time = IXGBE_FC_PAUSE;
821 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
822 hw->fc.low_water[i] = IXGBE_FC_LO;
823 hw->fc.high_water[i] = IXGBE_FC_HI;
827 /* Make sure we have a good EEPROM before we read from it */
828 diag = ixgbe_validate_eeprom_checksum(hw, &csum);
829 if (diag != IXGBE_SUCCESS) {
830 PMD_INIT_LOG(ERR, "The EEPROM checksum is not valid: %d", diag);
834 #ifdef RTE_NIC_BYPASS
835 diag = ixgbe_bypass_init_hw(hw);
837 diag = ixgbe_init_hw(hw);
838 #endif /* RTE_NIC_BYPASS */
841 * Devices with copper phys will fail to initialise if ixgbe_init_hw()
842 * is called too soon after the kernel driver unbinding/binding occurs.
843 * The failure occurs in ixgbe_identify_phy_generic() for all devices,
844 * but for non-copper devies, ixgbe_identify_sfp_module_generic() is
845 * also called. See ixgbe_identify_phy_82599(). The reason for the
846 * failure is not known, and only occuts when virtualisation features
847 * are disabled in the bios. A delay of 100ms was found to be enough by
848 * trial-and-error, and is doubled to be safe.
850 if (diag && (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)) {
852 diag = ixgbe_init_hw(hw);
855 if (diag == IXGBE_ERR_EEPROM_VERSION) {
856 PMD_INIT_LOG(ERR, "This device is a pre-production adapter/"
857 "LOM. Please be aware there may be issues associated "
858 "with your hardware.");
859 PMD_INIT_LOG(ERR, "If you are experiencing problems "
860 "please contact your Intel or hardware representative "
861 "who provided you with this hardware.");
862 } else if (diag == IXGBE_ERR_SFP_NOT_SUPPORTED)
863 PMD_INIT_LOG(ERR, "Unsupported SFP+ Module");
865 PMD_INIT_LOG(ERR, "Hardware Initialization Failure: %d", diag);
869 /* Reset the hw statistics */
870 ixgbe_dev_stats_reset(eth_dev);
872 /* disable interrupt */
873 ixgbe_disable_intr(hw);
875 /* reset mappings for queue statistics hw counters*/
876 ixgbe_reset_qstat_mappings(hw);
878 /* Allocate memory for storing MAC addresses */
879 eth_dev->data->mac_addrs = rte_zmalloc("ixgbe", ETHER_ADDR_LEN *
880 hw->mac.num_rar_entries, 0);
881 if (eth_dev->data->mac_addrs == NULL) {
883 "Failed to allocate %u bytes needed to store "
885 ETHER_ADDR_LEN * hw->mac.num_rar_entries);
888 /* Copy the permanent MAC address */
889 ether_addr_copy((struct ether_addr *) hw->mac.perm_addr,
890 ð_dev->data->mac_addrs[0]);
892 /* Allocate memory for storing hash filter MAC addresses */
893 eth_dev->data->hash_mac_addrs = rte_zmalloc("ixgbe", ETHER_ADDR_LEN *
894 IXGBE_VMDQ_NUM_UC_MAC, 0);
895 if (eth_dev->data->hash_mac_addrs == NULL) {
897 "Failed to allocate %d bytes needed to store MAC addresses",
898 ETHER_ADDR_LEN * IXGBE_VMDQ_NUM_UC_MAC);
902 /* initialize the vfta */
903 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
905 /* initialize the hw strip bitmap*/
906 memset(hwstrip, 0, sizeof(*hwstrip));
908 /* initialize PF if max_vfs not zero */
909 ixgbe_pf_host_init(eth_dev);
911 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
912 /* let hardware know driver is loaded */
913 ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
914 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
915 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
916 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
917 IXGBE_WRITE_FLUSH(hw);
919 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
920 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d, SFP+: %d",
921 (int) hw->mac.type, (int) hw->phy.type,
922 (int) hw->phy.sfp_type);
924 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d",
925 (int) hw->mac.type, (int) hw->phy.type);
927 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
928 eth_dev->data->port_id, pci_dev->id.vendor_id,
929 pci_dev->id.device_id);
931 rte_intr_callback_register(&(pci_dev->intr_handle),
932 ixgbe_dev_interrupt_handler, (void *)eth_dev);
934 /* enable uio intr after callback register */
935 rte_intr_enable(&(pci_dev->intr_handle));
937 /* enable support intr */
938 ixgbe_enable_intr(eth_dev);
940 /* initialize 5tuple filter list */
941 TAILQ_INIT(&filter_info->fivetuple_list);
942 memset(filter_info->fivetuple_mask, 0,
943 sizeof(uint32_t) * IXGBE_5TUPLE_ARRAY_SIZE);
950 * Negotiate mailbox API version with the PF.
951 * After reset API version is always set to the basic one (ixgbe_mbox_api_10).
952 * Then we try to negotiate starting with the most recent one.
953 * If all negotiation attempts fail, then we will proceed with
954 * the default one (ixgbe_mbox_api_10).
957 ixgbevf_negotiate_api(struct ixgbe_hw *hw)
961 /* start with highest supported, proceed down */
962 static const enum ixgbe_pfvf_api_rev sup_ver[] = {
968 i != RTE_DIM(sup_ver) &&
969 ixgbevf_negotiate_api_version(hw, sup_ver[i]) != 0;
975 generate_random_mac_addr(struct ether_addr *mac_addr)
979 /* Set Organizationally Unique Identifier (OUI) prefix. */
980 mac_addr->addr_bytes[0] = 0x00;
981 mac_addr->addr_bytes[1] = 0x09;
982 mac_addr->addr_bytes[2] = 0xC0;
983 /* Force indication of locally assigned MAC address. */
984 mac_addr->addr_bytes[0] |= ETHER_LOCAL_ADMIN_ADDR;
985 /* Generate the last 3 bytes of the MAC address with a random number. */
987 memcpy(&mac_addr->addr_bytes[3], &random, 3);
991 * Virtual Function device init
994 eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
998 struct rte_pci_device *pci_dev;
999 struct ixgbe_hw *hw =
1000 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1001 struct ixgbe_vfta * shadow_vfta =
1002 IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
1003 struct ixgbe_hwstrip *hwstrip =
1004 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
1005 struct ether_addr *perm_addr = (struct ether_addr *) hw->mac.perm_addr;
1007 PMD_INIT_FUNC_TRACE();
1009 eth_dev->dev_ops = &ixgbevf_eth_dev_ops;
1010 eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
1011 eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
1013 /* for secondary processes, we don't initialise any further as primary
1014 * has already done this work. Only check we don't need a different
1016 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1017 if (eth_dev->data->scattered_rx)
1018 eth_dev->rx_pkt_burst = ixgbe_recv_pkts_lro_single_alloc;
1022 pci_dev = eth_dev->pci_dev;
1024 hw->device_id = pci_dev->id.device_id;
1025 hw->vendor_id = pci_dev->id.vendor_id;
1026 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1028 /* initialize the vfta */
1029 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
1031 /* initialize the hw strip bitmap*/
1032 memset(hwstrip, 0, sizeof(*hwstrip));
1034 /* Initialize the shared code (base driver) */
1035 diag = ixgbe_init_shared_code(hw);
1036 if (diag != IXGBE_SUCCESS) {
1037 PMD_INIT_LOG(ERR, "Shared code init failed for ixgbevf: %d", diag);
1041 /* init_mailbox_params */
1042 hw->mbx.ops.init_params(hw);
1044 /* Reset the hw statistics */
1045 ixgbevf_dev_stats_reset(eth_dev);
1047 /* Disable the interrupts for VF */
1048 ixgbevf_intr_disable(hw);
1050 hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
1051 diag = hw->mac.ops.reset_hw(hw);
1054 * The VF reset operation returns the IXGBE_ERR_INVALID_MAC_ADDR when
1055 * the underlying PF driver has not assigned a MAC address to the VF.
1056 * In this case, assign a random MAC address.
1058 if ((diag != IXGBE_SUCCESS) && (diag != IXGBE_ERR_INVALID_MAC_ADDR)) {
1059 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
1063 /* negotiate mailbox API version to use with the PF. */
1064 ixgbevf_negotiate_api(hw);
1066 /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
1067 ixgbevf_get_queues(hw, &tcs, &tc);
1069 /* Allocate memory for storing MAC addresses */
1070 eth_dev->data->mac_addrs = rte_zmalloc("ixgbevf", ETHER_ADDR_LEN *
1071 hw->mac.num_rar_entries, 0);
1072 if (eth_dev->data->mac_addrs == NULL) {
1074 "Failed to allocate %u bytes needed to store "
1076 ETHER_ADDR_LEN * hw->mac.num_rar_entries);
1080 /* Generate a random MAC address, if none was assigned by PF. */
1081 if (is_zero_ether_addr(perm_addr)) {
1082 generate_random_mac_addr(perm_addr);
1083 diag = ixgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
1085 rte_free(eth_dev->data->mac_addrs);
1086 eth_dev->data->mac_addrs = NULL;
1089 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1090 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1091 "%02x:%02x:%02x:%02x:%02x:%02x",
1092 perm_addr->addr_bytes[0],
1093 perm_addr->addr_bytes[1],
1094 perm_addr->addr_bytes[2],
1095 perm_addr->addr_bytes[3],
1096 perm_addr->addr_bytes[4],
1097 perm_addr->addr_bytes[5]);
1100 /* Copy the permanent MAC address */
1101 ether_addr_copy(perm_addr, ð_dev->data->mac_addrs[0]);
1103 /* reset the hardware with the new settings */
1104 diag = hw->mac.ops.start_hw(hw);
1110 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
1114 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
1115 eth_dev->data->port_id, pci_dev->id.vendor_id,
1116 pci_dev->id.device_id, "ixgbe_mac_82599_vf");
1121 static struct eth_driver rte_ixgbe_pmd = {
1123 .name = "rte_ixgbe_pmd",
1124 .id_table = pci_id_ixgbe_map,
1125 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1127 .eth_dev_init = eth_ixgbe_dev_init,
1128 .dev_private_size = sizeof(struct ixgbe_adapter),
1132 * virtual function driver struct
1134 static struct eth_driver rte_ixgbevf_pmd = {
1136 .name = "rte_ixgbevf_pmd",
1137 .id_table = pci_id_ixgbevf_map,
1138 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1140 .eth_dev_init = eth_ixgbevf_dev_init,
1141 .dev_private_size = sizeof(struct ixgbe_adapter),
1145 * Driver initialization routine.
1146 * Invoked once at EAL init time.
1147 * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
1150 rte_ixgbe_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
1152 PMD_INIT_FUNC_TRACE();
1154 rte_eth_driver_register(&rte_ixgbe_pmd);
1159 * VF Driver initialization routine.
1160 * Invoked one at EAL init time.
1161 * Register itself as the [Virtual Poll Mode] Driver of PCI niantic devices.
1164 rte_ixgbevf_pmd_init(const char *name __rte_unused, const char *param __rte_unused)
1166 PMD_INIT_FUNC_TRACE();
1168 rte_eth_driver_register(&rte_ixgbevf_pmd);
1173 ixgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1175 struct ixgbe_hw *hw =
1176 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1177 struct ixgbe_vfta * shadow_vfta =
1178 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1183 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
1184 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
1185 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(vid_idx));
1190 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vid_idx), vfta);
1192 /* update local VFTA copy */
1193 shadow_vfta->vfta[vid_idx] = vfta;
1199 ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
1202 ixgbe_vlan_hw_strip_enable(dev, queue);
1204 ixgbe_vlan_hw_strip_disable(dev, queue);
1208 ixgbe_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid)
1210 struct ixgbe_hw *hw =
1211 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1213 /* Only the high 16-bits is valid */
1214 IXGBE_WRITE_REG(hw, IXGBE_EXVET, tpid << 16);
1218 ixgbe_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1220 struct ixgbe_hw *hw =
1221 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1224 PMD_INIT_FUNC_TRACE();
1226 /* Filter Table Disable */
1227 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1228 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
1230 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1234 ixgbe_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1236 struct ixgbe_hw *hw =
1237 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1238 struct ixgbe_vfta * shadow_vfta =
1239 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1243 PMD_INIT_FUNC_TRACE();
1245 /* Filter Table Enable */
1246 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1247 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1248 vlnctrl |= IXGBE_VLNCTRL_VFE;
1250 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1252 /* write whatever is in local vfta copy */
1253 for (i = 0; i < IXGBE_VFTA_SIZE; i++)
1254 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), shadow_vfta->vfta[i]);
1258 ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev, uint16_t queue, bool on)
1260 struct ixgbe_hwstrip *hwstrip =
1261 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(dev->data->dev_private);
1263 if(queue >= IXGBE_MAX_RX_QUEUE_NUM)
1267 IXGBE_SET_HWSTRIP(hwstrip, queue);
1269 IXGBE_CLEAR_HWSTRIP(hwstrip, queue);
1273 ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue)
1275 struct ixgbe_hw *hw =
1276 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1279 PMD_INIT_FUNC_TRACE();
1281 if (hw->mac.type == ixgbe_mac_82598EB) {
1282 /* No queue level support */
1283 PMD_INIT_LOG(INFO, "82598EB not support queue level hw strip");
1287 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1288 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
1289 ctrl &= ~IXGBE_RXDCTL_VME;
1290 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
1292 /* record those setting for HW strip per queue */
1293 ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 0);
1297 ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue)
1299 struct ixgbe_hw *hw =
1300 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1303 PMD_INIT_FUNC_TRACE();
1305 if (hw->mac.type == ixgbe_mac_82598EB) {
1306 /* No queue level supported */
1307 PMD_INIT_LOG(INFO, "82598EB not support queue level hw strip");
1311 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1312 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
1313 ctrl |= IXGBE_RXDCTL_VME;
1314 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
1316 /* record those setting for HW strip per queue */
1317 ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 1);
1321 ixgbe_vlan_hw_strip_disable_all(struct rte_eth_dev *dev)
1323 struct ixgbe_hw *hw =
1324 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1328 PMD_INIT_FUNC_TRACE();
1330 if (hw->mac.type == ixgbe_mac_82598EB) {
1331 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1332 ctrl &= ~IXGBE_VLNCTRL_VME;
1333 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
1336 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1337 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1338 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1339 ctrl &= ~IXGBE_RXDCTL_VME;
1340 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), ctrl);
1342 /* record those setting for HW strip per queue */
1343 ixgbe_vlan_hw_strip_bitmap_set(dev, i, 0);
1349 ixgbe_vlan_hw_strip_enable_all(struct rte_eth_dev *dev)
1351 struct ixgbe_hw *hw =
1352 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1356 PMD_INIT_FUNC_TRACE();
1358 if (hw->mac.type == ixgbe_mac_82598EB) {
1359 ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1360 ctrl |= IXGBE_VLNCTRL_VME;
1361 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
1364 /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
1365 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1366 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1367 ctrl |= IXGBE_RXDCTL_VME;
1368 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), ctrl);
1370 /* record those setting for HW strip per queue */
1371 ixgbe_vlan_hw_strip_bitmap_set(dev, i, 1);
1377 ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev)
1379 struct ixgbe_hw *hw =
1380 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1383 PMD_INIT_FUNC_TRACE();
1385 /* DMATXCTRL: Geric Double VLAN Disable */
1386 ctrl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1387 ctrl &= ~IXGBE_DMATXCTL_GDV;
1388 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
1390 /* CTRL_EXT: Global Double VLAN Disable */
1391 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
1392 ctrl &= ~IXGBE_EXTENDED_VLAN;
1393 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
1398 ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev)
1400 struct ixgbe_hw *hw =
1401 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1404 PMD_INIT_FUNC_TRACE();
1406 /* DMATXCTRL: Geric Double VLAN Enable */
1407 ctrl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1408 ctrl |= IXGBE_DMATXCTL_GDV;
1409 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
1411 /* CTRL_EXT: Global Double VLAN Enable */
1412 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
1413 ctrl |= IXGBE_EXTENDED_VLAN;
1414 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
1417 * VET EXT field in the EXVET register = 0x8100 by default
1418 * So no need to change. Same to VT field of DMATXCTL register
1423 ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1425 if(mask & ETH_VLAN_STRIP_MASK){
1426 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1427 ixgbe_vlan_hw_strip_enable_all(dev);
1429 ixgbe_vlan_hw_strip_disable_all(dev);
1432 if(mask & ETH_VLAN_FILTER_MASK){
1433 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1434 ixgbe_vlan_hw_filter_enable(dev);
1436 ixgbe_vlan_hw_filter_disable(dev);
1439 if(mask & ETH_VLAN_EXTEND_MASK){
1440 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
1441 ixgbe_vlan_hw_extend_enable(dev);
1443 ixgbe_vlan_hw_extend_disable(dev);
1448 ixgbe_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1450 struct ixgbe_hw *hw =
1451 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1452 /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
1453 uint32_t vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1454 vlanctrl |= IXGBE_VLNCTRL_VFE ; /* enable vlan filters */
1455 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
1459 ixgbe_dev_configure(struct rte_eth_dev *dev)
1461 struct ixgbe_interrupt *intr =
1462 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1463 struct ixgbe_adapter *adapter =
1464 (struct ixgbe_adapter *)dev->data->dev_private;
1466 PMD_INIT_FUNC_TRACE();
1468 /* set flag to update link status after init */
1469 intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1472 * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
1473 * allocation or vector Rx preconditions we will reset it.
1475 adapter->rx_bulk_alloc_allowed = true;
1476 adapter->rx_vec_allowed = true;
1482 * Configure device link speed and setup link.
1483 * It returns 0 on success.
1486 ixgbe_dev_start(struct rte_eth_dev *dev)
1488 struct ixgbe_hw *hw =
1489 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1490 struct ixgbe_vf_info *vfinfo =
1491 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
1492 int err, link_up = 0, negotiate = 0;
1498 PMD_INIT_FUNC_TRACE();
1500 /* IXGBE devices don't support half duplex */
1501 if ((dev->data->dev_conf.link_duplex != ETH_LINK_AUTONEG_DUPLEX) &&
1502 (dev->data->dev_conf.link_duplex != ETH_LINK_FULL_DUPLEX)) {
1503 PMD_INIT_LOG(ERR, "Invalid link_duplex (%hu) for port %hhu",
1504 dev->data->dev_conf.link_duplex,
1505 dev->data->port_id);
1510 hw->adapter_stopped = FALSE;
1511 ixgbe_stop_adapter(hw);
1513 /* reinitialize adapter
1514 * this calls reset and start */
1515 status = ixgbe_pf_reset_hw(hw);
1518 hw->mac.ops.start_hw(hw);
1519 hw->mac.get_link_status = true;
1521 /* configure PF module if SRIOV enabled */
1522 ixgbe_pf_host_configure(dev);
1524 /* initialize transmission unit */
1525 ixgbe_dev_tx_init(dev);
1527 /* This can fail when allocating mbufs for descriptor rings */
1528 err = ixgbe_dev_rx_init(dev);
1530 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1534 err = ixgbe_dev_rxtx_start(dev);
1536 PMD_INIT_LOG(ERR, "Unable to start rxtx queues");
1540 /* Skip link setup if loopback mode is enabled for 82599. */
1541 if (hw->mac.type == ixgbe_mac_82599EB &&
1542 dev->data->dev_conf.lpbk_mode == IXGBE_LPBK_82599_TX_RX)
1543 goto skip_link_setup;
1545 if (ixgbe_is_sfp(hw) && hw->phy.multispeed_fiber) {
1546 err = hw->mac.ops.setup_sfp(hw);
1551 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
1552 /* Turn on the copper */
1553 ixgbe_set_phy_power(hw, true);
1555 /* Turn on the laser */
1556 ixgbe_enable_tx_laser(hw);
1559 err = ixgbe_check_link(hw, &speed, &link_up, 0);
1562 dev->data->dev_link.link_status = link_up;
1564 err = ixgbe_get_link_capabilities(hw, &speed, &negotiate);
1568 switch(dev->data->dev_conf.link_speed) {
1569 case ETH_LINK_SPEED_AUTONEG:
1570 speed = (hw->mac.type != ixgbe_mac_82598EB) ?
1571 IXGBE_LINK_SPEED_82599_AUTONEG :
1572 IXGBE_LINK_SPEED_82598_AUTONEG;
1574 case ETH_LINK_SPEED_100:
1576 * Invalid for 82598 but error will be detected by
1577 * ixgbe_setup_link()
1579 speed = IXGBE_LINK_SPEED_100_FULL;
1581 case ETH_LINK_SPEED_1000:
1582 speed = IXGBE_LINK_SPEED_1GB_FULL;
1584 case ETH_LINK_SPEED_10000:
1585 speed = IXGBE_LINK_SPEED_10GB_FULL;
1588 PMD_INIT_LOG(ERR, "Invalid link_speed (%hu) for port %hhu",
1589 dev->data->dev_conf.link_speed,
1590 dev->data->port_id);
1594 err = ixgbe_setup_link(hw, speed, link_up);
1600 /* check if lsc interrupt is enabled */
1601 if (dev->data->dev_conf.intr_conf.lsc != 0)
1602 ixgbe_dev_lsc_interrupt_setup(dev);
1604 /* resume enabled intr since hw reset */
1605 ixgbe_enable_intr(dev);
1607 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
1608 ETH_VLAN_EXTEND_MASK;
1609 ixgbe_vlan_offload_set(dev, mask);
1611 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_VMDQ_ONLY) {
1612 /* Enable vlan filtering for VMDq */
1613 ixgbe_vmdq_vlan_hw_filter_enable(dev);
1616 /* Configure DCB hw */
1617 ixgbe_configure_dcb(dev);
1619 if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_NONE) {
1620 err = ixgbe_fdir_configure(dev);
1625 /* Restore vf rate limit */
1626 if (vfinfo != NULL) {
1627 for (vf = 0; vf < dev->pci_dev->max_vfs; vf++)
1628 for (idx = 0; idx < IXGBE_MAX_QUEUE_NUM_PER_VF; idx++)
1629 if (vfinfo[vf].tx_rate[idx] != 0)
1630 ixgbe_set_vf_rate_limit(dev, vf,
1631 vfinfo[vf].tx_rate[idx],
1635 ixgbe_restore_statistics_mapping(dev);
1640 PMD_INIT_LOG(ERR, "failure in ixgbe_dev_start(): %d", err);
1641 ixgbe_dev_clear_queues(dev);
1646 * Stop device: disable rx and tx functions to allow for reconfiguring.
1649 ixgbe_dev_stop(struct rte_eth_dev *dev)
1651 struct rte_eth_link link;
1652 struct ixgbe_hw *hw =
1653 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1654 struct ixgbe_vf_info *vfinfo =
1655 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
1656 struct ixgbe_filter_info *filter_info =
1657 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1658 struct ixgbe_5tuple_filter *p_5tuple, *p_5tuple_next;
1661 PMD_INIT_FUNC_TRACE();
1663 /* disable interrupts */
1664 ixgbe_disable_intr(hw);
1667 ixgbe_pf_reset_hw(hw);
1668 hw->adapter_stopped = FALSE;
1671 ixgbe_stop_adapter(hw);
1673 for (vf = 0; vfinfo != NULL &&
1674 vf < dev->pci_dev->max_vfs; vf++)
1675 vfinfo[vf].clear_to_send = false;
1677 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
1678 /* Turn off the copper */
1679 ixgbe_set_phy_power(hw, false);
1681 /* Turn off the laser */
1682 ixgbe_disable_tx_laser(hw);
1685 ixgbe_dev_clear_queues(dev);
1687 /* Clear stored conf */
1688 dev->data->scattered_rx = 0;
1691 /* Clear recorded link status */
1692 memset(&link, 0, sizeof(link));
1693 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
1695 /* Remove all ntuple filters of the device */
1696 for (p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list);
1697 p_5tuple != NULL; p_5tuple = p_5tuple_next) {
1698 p_5tuple_next = TAILQ_NEXT(p_5tuple, entries);
1699 TAILQ_REMOVE(&filter_info->fivetuple_list,
1703 memset(filter_info->fivetuple_mask, 0,
1704 sizeof(uint32_t) * IXGBE_5TUPLE_ARRAY_SIZE);
1709 * Set device link up: enable tx.
1712 ixgbe_dev_set_link_up(struct rte_eth_dev *dev)
1714 struct ixgbe_hw *hw =
1715 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1716 if (hw->mac.type == ixgbe_mac_82599EB) {
1717 #ifdef RTE_NIC_BYPASS
1718 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
1719 /* Not suported in bypass mode */
1720 PMD_INIT_LOG(ERR, "Set link up is not supported "
1721 "by device id 0x%x", hw->device_id);
1727 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
1728 /* Turn on the copper */
1729 ixgbe_set_phy_power(hw, true);
1731 /* Turn on the laser */
1732 ixgbe_enable_tx_laser(hw);
1739 * Set device link down: disable tx.
1742 ixgbe_dev_set_link_down(struct rte_eth_dev *dev)
1744 struct ixgbe_hw *hw =
1745 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1746 if (hw->mac.type == ixgbe_mac_82599EB) {
1747 #ifdef RTE_NIC_BYPASS
1748 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
1749 /* Not suported in bypass mode */
1750 PMD_INIT_LOG(ERR, "Set link down is not supported "
1751 "by device id 0x%x", hw->device_id);
1757 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
1758 /* Turn off the copper */
1759 ixgbe_set_phy_power(hw, false);
1761 /* Turn off the laser */
1762 ixgbe_disable_tx_laser(hw);
1769 * Reest and stop device.
1772 ixgbe_dev_close(struct rte_eth_dev *dev)
1774 struct ixgbe_hw *hw =
1775 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1777 PMD_INIT_FUNC_TRACE();
1779 ixgbe_pf_reset_hw(hw);
1781 ixgbe_dev_stop(dev);
1782 hw->adapter_stopped = 1;
1784 ixgbe_disable_pcie_master(hw);
1786 /* reprogram the RAR[0] in case user changed it. */
1787 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
1791 * This function is based on ixgbe_update_stats_counters() in base/ixgbe.c
1794 ixgbe_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1796 struct ixgbe_hw *hw =
1797 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1798 struct ixgbe_hw_stats *hw_stats =
1799 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1800 uint32_t bprc, lxon, lxoff, total;
1801 uint64_t total_missed_rx, total_qbrc, total_qprc;
1804 total_missed_rx = 0;
1808 hw_stats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
1809 hw_stats->illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC);
1810 hw_stats->errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC);
1811 hw_stats->mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC);
1813 for (i = 0; i < 8; i++) {
1815 mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
1816 /* global total per queue */
1817 hw_stats->mpc[i] += mp;
1818 /* Running comprehensive total for stats display */
1819 total_missed_rx += hw_stats->mpc[i];
1820 if (hw->mac.type == ixgbe_mac_82598EB)
1821 hw_stats->rnbc[i] +=
1822 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
1823 hw_stats->pxontxc[i] +=
1824 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
1825 hw_stats->pxonrxc[i] +=
1826 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
1827 hw_stats->pxofftxc[i] +=
1828 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
1829 hw_stats->pxoffrxc[i] +=
1830 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
1831 hw_stats->pxon2offc[i] +=
1832 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
1834 for (i = 0; i < IXGBE_QUEUE_STAT_COUNTERS; i++) {
1835 hw_stats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
1836 hw_stats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
1837 hw_stats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
1838 hw_stats->qbrc[i] +=
1839 ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)) << 32);
1840 hw_stats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
1841 hw_stats->qbtc[i] +=
1842 ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)) << 32);
1843 hw_stats->qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
1845 total_qprc += hw_stats->qprc[i];
1846 total_qbrc += hw_stats->qbrc[i];
1848 hw_stats->mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC);
1849 hw_stats->mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC);
1850 hw_stats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
1852 /* Note that gprc counts missed packets */
1853 hw_stats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
1855 if (hw->mac.type != ixgbe_mac_82598EB) {
1856 hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
1857 hw_stats->gorc += ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32);
1858 hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
1859 hw_stats->gotc += ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32);
1860 hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
1861 hw_stats->tor += ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32);
1862 hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
1863 hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
1865 hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
1866 hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
1867 /* 82598 only has a counter in the high register */
1868 hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
1869 hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
1870 hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
1874 * Workaround: mprc hardware is incorrectly counting
1875 * broadcasts, so for now we subtract those.
1877 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
1878 hw_stats->bprc += bprc;
1879 hw_stats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
1880 if (hw->mac.type == ixgbe_mac_82598EB)
1881 hw_stats->mprc -= bprc;
1883 hw_stats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
1884 hw_stats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
1885 hw_stats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
1886 hw_stats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
1887 hw_stats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
1888 hw_stats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
1890 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
1891 hw_stats->lxontxc += lxon;
1892 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
1893 hw_stats->lxofftxc += lxoff;
1894 total = lxon + lxoff;
1896 hw_stats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
1897 hw_stats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
1898 hw_stats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
1899 hw_stats->gptc -= total;
1900 hw_stats->mptc -= total;
1901 hw_stats->ptc64 -= total;
1902 hw_stats->gotc -= total * ETHER_MIN_LEN;
1904 hw_stats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
1905 hw_stats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
1906 hw_stats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
1907 hw_stats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
1908 hw_stats->mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC);
1909 hw_stats->mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC);
1910 hw_stats->mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC);
1911 hw_stats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
1912 hw_stats->tpt += IXGBE_READ_REG(hw, IXGBE_TPT);
1913 hw_stats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
1914 hw_stats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
1915 hw_stats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
1916 hw_stats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
1917 hw_stats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
1918 hw_stats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
1919 hw_stats->xec += IXGBE_READ_REG(hw, IXGBE_XEC);
1920 hw_stats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
1921 hw_stats->fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
1922 /* Only read FCOE on 82599 */
1923 if (hw->mac.type != ixgbe_mac_82598EB) {
1924 hw_stats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
1925 hw_stats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
1926 hw_stats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
1927 hw_stats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
1928 hw_stats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
1934 /* Fill out the rte_eth_stats statistics structure */
1935 stats->ipackets = total_qprc;
1936 stats->ibytes = total_qbrc;
1937 stats->opackets = hw_stats->gptc;
1938 stats->obytes = hw_stats->gotc;
1939 stats->imcasts = hw_stats->mprc;
1941 for (i = 0; i < IXGBE_QUEUE_STAT_COUNTERS; i++) {
1942 stats->q_ipackets[i] = hw_stats->qprc[i];
1943 stats->q_opackets[i] = hw_stats->qptc[i];
1944 stats->q_ibytes[i] = hw_stats->qbrc[i];
1945 stats->q_obytes[i] = hw_stats->qbtc[i];
1946 stats->q_errors[i] = hw_stats->qprdc[i];
1950 stats->ibadcrc = hw_stats->crcerrs;
1951 stats->ibadlen = hw_stats->rlec + hw_stats->ruc + hw_stats->roc;
1952 stats->imissed = total_missed_rx;
1953 stats->ierrors = stats->ibadcrc +
1956 hw_stats->illerrc + hw_stats->errbc;
1961 /* XON/XOFF pause frames */
1962 stats->tx_pause_xon = hw_stats->lxontxc;
1963 stats->rx_pause_xon = hw_stats->lxonrxc;
1964 stats->tx_pause_xoff = hw_stats->lxofftxc;
1965 stats->rx_pause_xoff = hw_stats->lxoffrxc;
1967 /* Flow Director Stats registers */
1968 hw_stats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
1969 hw_stats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
1970 stats->fdirmatch = hw_stats->fdirmatch;
1971 stats->fdirmiss = hw_stats->fdirmiss;
1975 ixgbe_dev_stats_reset(struct rte_eth_dev *dev)
1977 struct ixgbe_hw_stats *stats =
1978 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1980 /* HW registers are cleared on read */
1981 ixgbe_dev_stats_get(dev, NULL);
1983 /* Reset software totals */
1984 memset(stats, 0, sizeof(*stats));
1988 ixgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1990 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1991 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats*)
1992 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1994 /* Good Rx packet, include VF loopback */
1995 UPDATE_VF_STAT(IXGBE_VFGPRC,
1996 hw_stats->last_vfgprc, hw_stats->vfgprc);
1998 /* Good Rx octets, include VF loopback */
1999 UPDATE_VF_STAT_36BIT(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
2000 hw_stats->last_vfgorc, hw_stats->vfgorc);
2002 /* Good Tx packet, include VF loopback */
2003 UPDATE_VF_STAT(IXGBE_VFGPTC,
2004 hw_stats->last_vfgptc, hw_stats->vfgptc);
2006 /* Good Tx octets, include VF loopback */
2007 UPDATE_VF_STAT_36BIT(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
2008 hw_stats->last_vfgotc, hw_stats->vfgotc);
2010 /* Rx Multicst Packet */
2011 UPDATE_VF_STAT(IXGBE_VFMPRC,
2012 hw_stats->last_vfmprc, hw_stats->vfmprc);
2017 stats->ipackets = hw_stats->vfgprc;
2018 stats->ibytes = hw_stats->vfgorc;
2019 stats->opackets = hw_stats->vfgptc;
2020 stats->obytes = hw_stats->vfgotc;
2021 stats->imcasts = hw_stats->vfmprc;
2025 ixgbevf_dev_stats_reset(struct rte_eth_dev *dev)
2027 struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats*)
2028 IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2030 /* Sync HW register to the last stats */
2031 ixgbevf_dev_stats_get(dev, NULL);
2033 /* reset HW current stats*/
2034 hw_stats->vfgprc = 0;
2035 hw_stats->vfgorc = 0;
2036 hw_stats->vfgptc = 0;
2037 hw_stats->vfgotc = 0;
2038 hw_stats->vfmprc = 0;
2043 ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2045 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2047 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
2048 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
2049 dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL register */
2050 dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS register */
2051 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
2052 dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
2053 dev_info->max_vfs = dev->pci_dev->max_vfs;
2054 if (hw->mac.type == ixgbe_mac_82598EB)
2055 dev_info->max_vmdq_pools = ETH_16_POOLS;
2057 dev_info->max_vmdq_pools = ETH_64_POOLS;
2058 dev_info->vmdq_queue_num = dev_info->max_rx_queues;
2059 dev_info->rx_offload_capa =
2060 DEV_RX_OFFLOAD_VLAN_STRIP |
2061 DEV_RX_OFFLOAD_IPV4_CKSUM |
2062 DEV_RX_OFFLOAD_UDP_CKSUM |
2063 DEV_RX_OFFLOAD_TCP_CKSUM;
2066 * RSC is only supported by 82599 and x540 PF devices in a non-SR-IOV
2069 if ((hw->mac.type == ixgbe_mac_82599EB ||
2070 hw->mac.type == ixgbe_mac_X540) &&
2071 !RTE_ETH_DEV_SRIOV(dev).active)
2072 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TCP_LRO;
2074 dev_info->tx_offload_capa =
2075 DEV_TX_OFFLOAD_VLAN_INSERT |
2076 DEV_TX_OFFLOAD_IPV4_CKSUM |
2077 DEV_TX_OFFLOAD_UDP_CKSUM |
2078 DEV_TX_OFFLOAD_TCP_CKSUM |
2079 DEV_TX_OFFLOAD_SCTP_CKSUM |
2080 DEV_TX_OFFLOAD_TCP_TSO;
2082 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2084 .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
2085 .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
2086 .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
2088 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
2092 dev_info->default_txconf = (struct rte_eth_txconf) {
2094 .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
2095 .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
2096 .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
2098 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
2099 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
2100 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
2101 ETH_TXQ_FLAGS_NOOFFLOADS,
2103 dev_info->hash_key_size = IXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
2104 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
2105 dev_info->flow_type_rss_offloads = IXGBE_RSS_OFFLOAD_ALL;
2109 ixgbevf_dev_info_get(struct rte_eth_dev *dev,
2110 struct rte_eth_dev_info *dev_info)
2112 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2114 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
2115 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
2116 dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL reg */
2117 dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS reg */
2118 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
2119 dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
2120 dev_info->max_vfs = dev->pci_dev->max_vfs;
2121 if (hw->mac.type == ixgbe_mac_82598EB)
2122 dev_info->max_vmdq_pools = ETH_16_POOLS;
2124 dev_info->max_vmdq_pools = ETH_64_POOLS;
2125 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
2126 DEV_RX_OFFLOAD_IPV4_CKSUM |
2127 DEV_RX_OFFLOAD_UDP_CKSUM |
2128 DEV_RX_OFFLOAD_TCP_CKSUM;
2129 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
2130 DEV_TX_OFFLOAD_IPV4_CKSUM |
2131 DEV_TX_OFFLOAD_UDP_CKSUM |
2132 DEV_TX_OFFLOAD_TCP_CKSUM |
2133 DEV_TX_OFFLOAD_SCTP_CKSUM;
2135 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2137 .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
2138 .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
2139 .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
2141 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
2145 dev_info->default_txconf = (struct rte_eth_txconf) {
2147 .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
2148 .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
2149 .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
2151 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
2152 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
2153 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
2154 ETH_TXQ_FLAGS_NOOFFLOADS,
2158 /* return 0 means link status changed, -1 means not changed */
2160 ixgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2162 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2163 struct rte_eth_link link, old;
2164 ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
2168 link.link_status = 0;
2169 link.link_speed = 0;
2170 link.link_duplex = 0;
2171 memset(&old, 0, sizeof(old));
2172 rte_ixgbe_dev_atomic_read_link_status(dev, &old);
2174 hw->mac.get_link_status = true;
2176 /* check if it needs to wait to complete, if lsc interrupt is enabled */
2177 if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
2178 diag = ixgbe_check_link(hw, &link_speed, &link_up, 0);
2180 diag = ixgbe_check_link(hw, &link_speed, &link_up, 1);
2183 link.link_speed = ETH_LINK_SPEED_100;
2184 link.link_duplex = ETH_LINK_HALF_DUPLEX;
2185 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
2186 if (link.link_status == old.link_status)
2192 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
2193 if (link.link_status == old.link_status)
2197 link.link_status = 1;
2198 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2200 switch (link_speed) {
2202 case IXGBE_LINK_SPEED_UNKNOWN:
2203 link.link_duplex = ETH_LINK_HALF_DUPLEX;
2204 link.link_speed = ETH_LINK_SPEED_100;
2207 case IXGBE_LINK_SPEED_100_FULL:
2208 link.link_speed = ETH_LINK_SPEED_100;
2211 case IXGBE_LINK_SPEED_1GB_FULL:
2212 link.link_speed = ETH_LINK_SPEED_1000;
2215 case IXGBE_LINK_SPEED_10GB_FULL:
2216 link.link_speed = ETH_LINK_SPEED_10000;
2219 rte_ixgbe_dev_atomic_write_link_status(dev, &link);
2221 if (link.link_status == old.link_status)
2228 ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
2230 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2233 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2234 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2235 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2239 ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
2241 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2244 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2245 fctrl &= (~IXGBE_FCTRL_UPE);
2246 if (dev->data->all_multicast == 1)
2247 fctrl |= IXGBE_FCTRL_MPE;
2249 fctrl &= (~IXGBE_FCTRL_MPE);
2250 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2254 ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
2256 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2259 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2260 fctrl |= IXGBE_FCTRL_MPE;
2261 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2265 ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
2267 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2270 if (dev->data->promiscuous == 1)
2271 return; /* must remain in all_multicast mode */
2273 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2274 fctrl &= (~IXGBE_FCTRL_MPE);
2275 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2279 * It clears the interrupt causes and enables the interrupt.
2280 * It will be called once only during nic initialized.
2283 * Pointer to struct rte_eth_dev.
2286 * - On success, zero.
2287 * - On failure, a negative value.
2290 ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev)
2292 struct ixgbe_interrupt *intr =
2293 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2295 ixgbe_dev_link_status_print(dev);
2296 intr->mask |= IXGBE_EICR_LSC;
2302 * It reads ICR and sets flag (IXGBE_EICR_LSC) for the link_update.
2305 * Pointer to struct rte_eth_dev.
2308 * - On success, zero.
2309 * - On failure, a negative value.
2312 ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
2315 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2316 struct ixgbe_interrupt *intr =
2317 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2319 /* clear all cause mask */
2320 ixgbe_disable_intr(hw);
2322 /* read-on-clear nic registers here */
2323 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2324 PMD_DRV_LOG(INFO, "eicr %x", eicr);
2327 if (eicr & IXGBE_EICR_LSC) {
2328 /* set flag for async link update */
2329 intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2332 if (eicr & IXGBE_EICR_MAILBOX)
2333 intr->flags |= IXGBE_FLAG_MAILBOX;
2339 * It gets and then prints the link status.
2342 * Pointer to struct rte_eth_dev.
2345 * - On success, zero.
2346 * - On failure, a negative value.
2349 ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
2351 struct rte_eth_link link;
2353 memset(&link, 0, sizeof(link));
2354 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
2355 if (link.link_status) {
2356 PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
2357 (int)(dev->data->port_id),
2358 (unsigned)link.link_speed,
2359 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2360 "full-duplex" : "half-duplex");
2362 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2363 (int)(dev->data->port_id));
2365 PMD_INIT_LOG(INFO, "PCI Address: %04d:%02d:%02d:%d",
2366 dev->pci_dev->addr.domain,
2367 dev->pci_dev->addr.bus,
2368 dev->pci_dev->addr.devid,
2369 dev->pci_dev->addr.function);
2373 * It executes link_update after knowing an interrupt occurred.
2376 * Pointer to struct rte_eth_dev.
2379 * - On success, zero.
2380 * - On failure, a negative value.
2383 ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
2385 struct ixgbe_interrupt *intr =
2386 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2388 struct rte_eth_link link;
2389 int intr_enable_delay = false;
2391 PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
2393 if (intr->flags & IXGBE_FLAG_MAILBOX) {
2394 ixgbe_pf_mbx_process(dev);
2395 intr->flags &= ~IXGBE_FLAG_MAILBOX;
2398 if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
2399 /* get the link status before link update, for predicting later */
2400 memset(&link, 0, sizeof(link));
2401 rte_ixgbe_dev_atomic_read_link_status(dev, &link);
2403 ixgbe_dev_link_update(dev, 0);
2406 if (!link.link_status)
2407 /* handle it 1 sec later, wait it being stable */
2408 timeout = IXGBE_LINK_UP_CHECK_TIMEOUT;
2409 /* likely to down */
2411 /* handle it 4 sec later, wait it being stable */
2412 timeout = IXGBE_LINK_DOWN_CHECK_TIMEOUT;
2414 ixgbe_dev_link_status_print(dev);
2416 intr_enable_delay = true;
2419 if (intr_enable_delay) {
2420 if (rte_eal_alarm_set(timeout * 1000,
2421 ixgbe_dev_interrupt_delayed_handler, (void*)dev) < 0)
2422 PMD_DRV_LOG(ERR, "Error setting alarm");
2424 PMD_DRV_LOG(DEBUG, "enable intr immediately");
2425 ixgbe_enable_intr(dev);
2426 rte_intr_enable(&(dev->pci_dev->intr_handle));
2434 * Interrupt handler which shall be registered for alarm callback for delayed
2435 * handling specific interrupt to wait for the stable nic state. As the
2436 * NIC interrupt state is not stable for ixgbe after link is just down,
2437 * it needs to wait 4 seconds to get the stable status.
2440 * Pointer to interrupt handle.
2442 * The address of parameter (struct rte_eth_dev *) regsitered before.
2448 ixgbe_dev_interrupt_delayed_handler(void *param)
2450 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2451 struct ixgbe_interrupt *intr =
2452 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2453 struct ixgbe_hw *hw =
2454 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2457 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
2458 if (eicr & IXGBE_EICR_MAILBOX)
2459 ixgbe_pf_mbx_process(dev);
2461 if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
2462 ixgbe_dev_link_update(dev, 0);
2463 intr->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
2464 ixgbe_dev_link_status_print(dev);
2465 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
2468 PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
2469 ixgbe_enable_intr(dev);
2470 rte_intr_enable(&(dev->pci_dev->intr_handle));
2474 * Interrupt handler triggered by NIC for handling
2475 * specific interrupt.
2478 * Pointer to interrupt handle.
2480 * The address of parameter (struct rte_eth_dev *) regsitered before.
2486 ixgbe_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
2489 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2490 ixgbe_dev_interrupt_get_status(dev);
2491 ixgbe_dev_interrupt_action(dev);
2495 ixgbe_dev_led_on(struct rte_eth_dev *dev)
2497 struct ixgbe_hw *hw;
2499 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2500 return (ixgbe_led_on(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP);
2504 ixgbe_dev_led_off(struct rte_eth_dev *dev)
2506 struct ixgbe_hw *hw;
2508 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2509 return (ixgbe_led_off(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP);
2513 ixgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2515 struct ixgbe_hw *hw;
2521 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2523 fc_conf->pause_time = hw->fc.pause_time;
2524 fc_conf->high_water = hw->fc.high_water[0];
2525 fc_conf->low_water = hw->fc.low_water[0];
2526 fc_conf->send_xon = hw->fc.send_xon;
2527 fc_conf->autoneg = !hw->fc.disable_fc_autoneg;
2530 * Return rx_pause status according to actual setting of
2533 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2534 if (mflcn_reg & (IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_RFCE))
2540 * Return tx_pause status according to actual setting of
2543 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
2544 if (fccfg_reg & (IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY))
2549 if (rx_pause && tx_pause)
2550 fc_conf->mode = RTE_FC_FULL;
2552 fc_conf->mode = RTE_FC_RX_PAUSE;
2554 fc_conf->mode = RTE_FC_TX_PAUSE;
2556 fc_conf->mode = RTE_FC_NONE;
2562 ixgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2564 struct ixgbe_hw *hw;
2566 uint32_t rx_buf_size;
2567 uint32_t max_high_water;
2569 enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
2576 PMD_INIT_FUNC_TRACE();
2578 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2579 rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0));
2580 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2583 * At least reserve one Ethernet frame for watermark
2584 * high_water/low_water in kilo bytes for ixgbe
2586 max_high_water = (rx_buf_size - ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
2587 if ((fc_conf->high_water > max_high_water) ||
2588 (fc_conf->high_water < fc_conf->low_water)) {
2589 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
2590 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
2594 hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[fc_conf->mode];
2595 hw->fc.pause_time = fc_conf->pause_time;
2596 hw->fc.high_water[0] = fc_conf->high_water;
2597 hw->fc.low_water[0] = fc_conf->low_water;
2598 hw->fc.send_xon = fc_conf->send_xon;
2599 hw->fc.disable_fc_autoneg = !fc_conf->autoneg;
2601 err = ixgbe_fc_enable(hw);
2603 /* Not negotiated is not an error case */
2604 if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED)) {
2606 /* check if we want to forward MAC frames - driver doesn't have native
2607 * capability to do that, so we'll write the registers ourselves */
2609 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2611 /* set or clear MFLCN.PMCF bit depending on configuration */
2612 if (fc_conf->mac_ctrl_frame_fwd != 0)
2613 mflcn |= IXGBE_MFLCN_PMCF;
2615 mflcn &= ~IXGBE_MFLCN_PMCF;
2617 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn);
2618 IXGBE_WRITE_FLUSH(hw);
2623 PMD_INIT_LOG(ERR, "ixgbe_fc_enable = 0x%x", err);
2628 * ixgbe_pfc_enable_generic - Enable flow control
2629 * @hw: pointer to hardware structure
2630 * @tc_num: traffic class number
2631 * Enable flow control according to the current settings.
2634 ixgbe_dcb_pfc_enable_generic(struct ixgbe_hw *hw,uint8_t tc_num)
2637 uint32_t mflcn_reg, fccfg_reg;
2639 uint32_t fcrtl, fcrth;
2643 /* Validate the water mark configuration */
2644 if (!hw->fc.pause_time) {
2645 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2649 /* Low water mark of zero causes XOFF floods */
2650 if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
2651 /* High/Low water can not be 0 */
2652 if( (!hw->fc.high_water[tc_num])|| (!hw->fc.low_water[tc_num])) {
2653 PMD_INIT_LOG(ERR, "Invalid water mark configuration");
2654 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2658 if(hw->fc.low_water[tc_num] >= hw->fc.high_water[tc_num]) {
2659 PMD_INIT_LOG(ERR, "Invalid water mark configuration");
2660 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2664 /* Negotiate the fc mode to use */
2665 ixgbe_fc_autoneg(hw);
2667 /* Disable any previous flow control settings */
2668 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2669 mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_SHIFT | IXGBE_MFLCN_RFCE|IXGBE_MFLCN_RPFCE);
2671 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
2672 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
2674 switch (hw->fc.current_mode) {
2677 * If the count of enabled RX Priority Flow control >1,
2678 * and the TX pause can not be disabled
2681 for (i =0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
2682 reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
2683 if (reg & IXGBE_FCRTH_FCEN)
2687 fccfg_reg |=IXGBE_FCCFG_TFCE_PRIORITY;
2689 case ixgbe_fc_rx_pause:
2691 * Rx Flow control is enabled and Tx Flow control is
2692 * disabled by software override. Since there really
2693 * isn't a way to advertise that we are capable of RX
2694 * Pause ONLY, we will advertise that we support both
2695 * symmetric and asymmetric Rx PAUSE. Later, we will
2696 * disable the adapter's ability to send PAUSE frames.
2698 mflcn_reg |= IXGBE_MFLCN_RPFCE;
2700 * If the count of enabled RX Priority Flow control >1,
2701 * and the TX pause can not be disabled
2704 for (i =0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
2705 reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
2706 if (reg & IXGBE_FCRTH_FCEN)
2710 fccfg_reg |=IXGBE_FCCFG_TFCE_PRIORITY;
2712 case ixgbe_fc_tx_pause:
2714 * Tx Flow control is enabled, and Rx Flow control is
2715 * disabled by software override.
2717 fccfg_reg |=IXGBE_FCCFG_TFCE_PRIORITY;
2720 /* Flow control (both Rx and Tx) is enabled by SW override. */
2721 mflcn_reg |= IXGBE_MFLCN_RPFCE;
2722 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
2725 PMD_DRV_LOG(DEBUG, "Flow control param set incorrectly");
2726 ret_val = IXGBE_ERR_CONFIG;
2731 /* Set 802.3x based flow control settings. */
2732 mflcn_reg |= IXGBE_MFLCN_DPF;
2733 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
2734 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
2736 /* Set up and enable Rx high/low water mark thresholds, enable XON. */
2737 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
2738 hw->fc.high_water[tc_num]) {
2739 fcrtl = (hw->fc.low_water[tc_num] << 10) | IXGBE_FCRTL_XONE;
2740 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), fcrtl);
2741 fcrth = (hw->fc.high_water[tc_num] << 10) | IXGBE_FCRTH_FCEN;
2743 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), 0);
2745 * In order to prevent Tx hangs when the internal Tx
2746 * switch is enabled we must set the high water mark
2747 * to the maximum FCRTH value. This allows the Tx
2748 * switch to function even under heavy Rx workloads.
2750 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num)) - 32;
2752 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(tc_num), fcrth);
2754 /* Configure pause time (2 TCs per register) */
2755 reg = hw->fc.pause_time * 0x00010001;
2756 for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
2757 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
2759 /* Configure flow control refresh threshold value */
2760 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
2767 ixgbe_dcb_pfc_enable(struct rte_eth_dev *dev,uint8_t tc_num)
2769 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2770 int32_t ret_val = IXGBE_NOT_IMPLEMENTED;
2772 if(hw->mac.type != ixgbe_mac_82598EB) {
2773 ret_val = ixgbe_dcb_pfc_enable_generic(hw,tc_num);
2779 ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
2782 uint32_t rx_buf_size;
2783 uint32_t max_high_water;
2785 uint8_t map[IXGBE_DCB_MAX_USER_PRIORITY] = { 0 };
2786 struct ixgbe_hw *hw =
2787 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2788 struct ixgbe_dcb_config *dcb_config =
2789 IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
2791 enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
2798 PMD_INIT_FUNC_TRACE();
2800 ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_RX_CONFIG, map);
2801 tc_num = map[pfc_conf->priority];
2802 rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num));
2803 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2805 * At least reserve one Ethernet frame for watermark
2806 * high_water/low_water in kilo bytes for ixgbe
2808 max_high_water = (rx_buf_size - ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
2809 if ((pfc_conf->fc.high_water > max_high_water) ||
2810 (pfc_conf->fc.high_water <= pfc_conf->fc.low_water)) {
2811 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
2812 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
2816 hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[pfc_conf->fc.mode];
2817 hw->fc.pause_time = pfc_conf->fc.pause_time;
2818 hw->fc.send_xon = pfc_conf->fc.send_xon;
2819 hw->fc.low_water[tc_num] = pfc_conf->fc.low_water;
2820 hw->fc.high_water[tc_num] = pfc_conf->fc.high_water;
2822 err = ixgbe_dcb_pfc_enable(dev,tc_num);
2824 /* Not negotiated is not an error case */
2825 if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED))
2828 PMD_INIT_LOG(ERR, "ixgbe_dcb_pfc_enable = 0x%x", err);
2833 ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
2834 struct rte_eth_rss_reta_entry64 *reta_conf,
2839 uint16_t idx, shift;
2840 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2842 PMD_INIT_FUNC_TRACE();
2843 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2844 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2845 "(%d) doesn't match the number hardware can supported "
2846 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2850 for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
2851 idx = i / RTE_RETA_GROUP_SIZE;
2852 shift = i % RTE_RETA_GROUP_SIZE;
2853 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2857 if (mask == IXGBE_4_BIT_MASK)
2860 r = IXGBE_READ_REG(hw, IXGBE_RETA(i >> 2));
2861 for (j = 0, reta = 0; j < IXGBE_4_BIT_WIDTH; j++) {
2862 if (mask & (0x1 << j))
2863 reta |= reta_conf[idx].reta[shift + j] <<
2866 reta |= r & (IXGBE_8_BIT_MASK <<
2869 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2876 ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
2877 struct rte_eth_rss_reta_entry64 *reta_conf,
2882 uint16_t idx, shift;
2883 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2885 PMD_INIT_FUNC_TRACE();
2886 if (reta_size != ETH_RSS_RETA_SIZE_128) {
2887 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2888 "(%d) doesn't match the number hardware can supported "
2889 "(%d)\n", reta_size, ETH_RSS_RETA_SIZE_128);
2893 for (i = 0; i < ETH_RSS_RETA_SIZE_128; i += IXGBE_4_BIT_WIDTH) {
2894 idx = i / RTE_RETA_GROUP_SIZE;
2895 shift = i % RTE_RETA_GROUP_SIZE;
2896 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2901 reta = IXGBE_READ_REG(hw, IXGBE_RETA(i >> 2));
2902 for (j = 0; j < IXGBE_4_BIT_WIDTH; j++) {
2903 if (mask & (0x1 << j))
2904 reta_conf[idx].reta[shift + j] =
2905 ((reta >> (CHAR_BIT * j)) &
2914 ixgbe_add_rar(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
2915 uint32_t index, uint32_t pool)
2917 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2918 uint32_t enable_addr = 1;
2920 ixgbe_set_rar(hw, index, mac_addr->addr_bytes, pool, enable_addr);
2924 ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index)
2926 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2928 ixgbe_clear_rar(hw, index);
2932 ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
2936 struct ixgbe_hw *hw;
2937 struct rte_eth_dev_info dev_info;
2938 uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
2940 ixgbe_dev_info_get(dev, &dev_info);
2942 /* check that mtu is within the allowed range */
2943 if ((mtu < ETHER_MIN_MTU) || (frame_size > dev_info.max_rx_pktlen))
2946 /* refuse mtu that requires the support of scattered packets when this
2947 * feature has not been enabled before. */
2948 if (!dev->data->scattered_rx &&
2949 (frame_size + 2 * IXGBE_VLAN_TAG_SIZE >
2950 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
2953 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2954 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2956 /* switch to jumbo mode if needed */
2957 if (frame_size > ETHER_MAX_LEN) {
2958 dev->data->dev_conf.rxmode.jumbo_frame = 1;
2959 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2961 dev->data->dev_conf.rxmode.jumbo_frame = 0;
2962 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
2964 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2966 /* update max frame size */
2967 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
2969 maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
2970 maxfrs &= 0x0000FFFF;
2971 maxfrs |= (dev->data->dev_conf.rxmode.max_rx_pkt_len << 16);
2972 IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, maxfrs);
2978 * Virtual Function operations
2981 ixgbevf_intr_disable(struct ixgbe_hw *hw)
2983 PMD_INIT_FUNC_TRACE();
2985 /* Clear interrupt mask to stop from interrupts being generated */
2986 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
2988 IXGBE_WRITE_FLUSH(hw);
2992 ixgbevf_dev_configure(struct rte_eth_dev *dev)
2994 struct rte_eth_conf* conf = &dev->data->dev_conf;
2995 struct ixgbe_adapter *adapter =
2996 (struct ixgbe_adapter *)dev->data->dev_private;
2998 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
2999 dev->data->port_id);
3002 * VF has no ability to enable/disable HW CRC
3003 * Keep the persistent behavior the same as Host PF
3005 #ifndef RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC
3006 if (!conf->rxmode.hw_strip_crc) {
3007 PMD_INIT_LOG(INFO, "VF can't disable HW CRC Strip");
3008 conf->rxmode.hw_strip_crc = 1;
3011 if (conf->rxmode.hw_strip_crc) {
3012 PMD_INIT_LOG(INFO, "VF can't enable HW CRC Strip");
3013 conf->rxmode.hw_strip_crc = 0;
3018 * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
3019 * allocation or vector Rx preconditions we will reset it.
3021 adapter->rx_bulk_alloc_allowed = true;
3022 adapter->rx_vec_allowed = true;
3028 ixgbevf_dev_start(struct rte_eth_dev *dev)
3030 struct ixgbe_hw *hw =
3031 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3034 PMD_INIT_FUNC_TRACE();
3036 hw->mac.ops.reset_hw(hw);
3037 hw->mac.get_link_status = true;
3039 /* negotiate mailbox API version to use with the PF. */
3040 ixgbevf_negotiate_api(hw);
3042 ixgbevf_dev_tx_init(dev);
3044 /* This can fail when allocating mbufs for descriptor rings */
3045 err = ixgbevf_dev_rx_init(dev);
3047 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
3048 ixgbe_dev_clear_queues(dev);
3053 ixgbevf_set_vfta_all(dev,1);
3056 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK | \
3057 ETH_VLAN_EXTEND_MASK;
3058 ixgbevf_vlan_offload_set(dev, mask);
3060 ixgbevf_dev_rxtx_start(dev);
3066 ixgbevf_dev_stop(struct rte_eth_dev *dev)
3068 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3070 PMD_INIT_FUNC_TRACE();
3072 hw->adapter_stopped = TRUE;
3073 ixgbe_stop_adapter(hw);
3076 * Clear what we set, but we still keep shadow_vfta to
3077 * restore after device starts
3079 ixgbevf_set_vfta_all(dev,0);
3081 /* Clear stored conf */
3082 dev->data->scattered_rx = 0;
3084 ixgbe_dev_clear_queues(dev);
3088 ixgbevf_dev_close(struct rte_eth_dev *dev)
3090 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3092 PMD_INIT_FUNC_TRACE();
3096 ixgbevf_dev_stop(dev);
3098 /* reprogram the RAR[0] in case user changed it. */
3099 ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
3102 static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
3104 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3105 struct ixgbe_vfta * shadow_vfta =
3106 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3107 int i = 0, j = 0, vfta = 0, mask = 1;
3109 for (i = 0; i < IXGBE_VFTA_SIZE; i++){
3110 vfta = shadow_vfta->vfta[i];
3113 for (j = 0; j < 32; j++){
3115 ixgbe_set_vfta(hw, (i<<5)+j, 0, on);
3124 ixgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3126 struct ixgbe_hw *hw =
3127 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3128 struct ixgbe_vfta * shadow_vfta =
3129 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3130 uint32_t vid_idx = 0;
3131 uint32_t vid_bit = 0;
3134 PMD_INIT_FUNC_TRACE();
3136 /* vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf */
3137 ret = ixgbe_set_vfta(hw, vlan_id, 0, !!on);
3139 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
3142 vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
3143 vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
3145 /* Save what we set and retore it after device reset */
3147 shadow_vfta->vfta[vid_idx] |= vid_bit;
3149 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
3155 ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
3157 struct ixgbe_hw *hw =
3158 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3161 PMD_INIT_FUNC_TRACE();
3163 if(queue >= hw->mac.max_rx_queues)
3166 ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
3168 ctrl |= IXGBE_RXDCTL_VME;
3170 ctrl &= ~IXGBE_RXDCTL_VME;
3171 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
3173 ixgbe_vlan_hw_strip_bitmap_set( dev, queue, on);
3177 ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
3179 struct ixgbe_hw *hw =
3180 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3184 /* VF function only support hw strip feature, others are not support */
3185 if(mask & ETH_VLAN_STRIP_MASK){
3186 on = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
3188 for(i=0; i < hw->mac.max_rx_queues; i++)
3189 ixgbevf_vlan_strip_queue_set(dev,i,on);
3194 ixgbe_vmdq_mode_check(struct ixgbe_hw *hw)
3198 /* we only need to do this if VMDq is enabled */
3199 reg_val = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3200 if (!(reg_val & IXGBE_VT_CTL_VT_ENABLE)) {
3201 PMD_INIT_LOG(ERR, "VMDq must be enabled for this setting");
3209 ixgbe_uta_vector(struct ixgbe_hw *hw, struct ether_addr* uc_addr)
3211 uint32_t vector = 0;
3212 switch (hw->mac.mc_filter_type) {
3213 case 0: /* use bits [47:36] of the address */
3214 vector = ((uc_addr->addr_bytes[4] >> 4) |
3215 (((uint16_t)uc_addr->addr_bytes[5]) << 4));
3217 case 1: /* use bits [46:35] of the address */
3218 vector = ((uc_addr->addr_bytes[4] >> 3) |
3219 (((uint16_t)uc_addr->addr_bytes[5]) << 5));
3221 case 2: /* use bits [45:34] of the address */
3222 vector = ((uc_addr->addr_bytes[4] >> 2) |
3223 (((uint16_t)uc_addr->addr_bytes[5]) << 6));
3225 case 3: /* use bits [43:32] of the address */
3226 vector = ((uc_addr->addr_bytes[4]) |
3227 (((uint16_t)uc_addr->addr_bytes[5]) << 8));
3229 default: /* Invalid mc_filter_type */
3233 /* vector can only be 12-bits or boundary will be exceeded */
3239 ixgbe_uc_hash_table_set(struct rte_eth_dev *dev,struct ether_addr* mac_addr,
3247 const uint32_t ixgbe_uta_idx_mask = 0x7F;
3248 const uint32_t ixgbe_uta_bit_shift = 5;
3249 const uint32_t ixgbe_uta_bit_mask = (0x1 << ixgbe_uta_bit_shift) - 1;
3250 const uint32_t bit1 = 0x1;
3252 struct ixgbe_hw *hw =
3253 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3254 struct ixgbe_uta_info *uta_info =
3255 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
3257 /* The UTA table only exists on 82599 hardware and newer */
3258 if (hw->mac.type < ixgbe_mac_82599EB)
3261 vector = ixgbe_uta_vector(hw,mac_addr);
3262 uta_idx = (vector >> ixgbe_uta_bit_shift) & ixgbe_uta_idx_mask;
3263 uta_shift = vector & ixgbe_uta_bit_mask;
3265 rc = ((uta_info->uta_shadow[uta_idx] >> uta_shift & bit1) != 0);
3269 reg_val = IXGBE_READ_REG(hw, IXGBE_UTA(uta_idx));
3271 uta_info->uta_in_use++;
3272 reg_val |= (bit1 << uta_shift);
3273 uta_info->uta_shadow[uta_idx] |= (bit1 << uta_shift);
3275 uta_info->uta_in_use--;
3276 reg_val &= ~(bit1 << uta_shift);
3277 uta_info->uta_shadow[uta_idx] &= ~(bit1 << uta_shift);
3280 IXGBE_WRITE_REG(hw, IXGBE_UTA(uta_idx), reg_val);
3282 if (uta_info->uta_in_use > 0)
3283 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
3284 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
3286 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,hw->mac.mc_filter_type);
3292 ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on)
3295 struct ixgbe_hw *hw =
3296 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3297 struct ixgbe_uta_info *uta_info =
3298 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
3300 /* The UTA table only exists on 82599 hardware and newer */
3301 if (hw->mac.type < ixgbe_mac_82599EB)
3305 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
3306 uta_info->uta_shadow[i] = ~0;
3307 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
3310 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
3311 uta_info->uta_shadow[i] = 0;
3312 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
3320 ixgbe_convert_vm_rx_mask_to_val(uint16_t rx_mask, uint32_t orig_val)
3322 uint32_t new_val = orig_val;
3324 if (rx_mask & ETH_VMDQ_ACCEPT_UNTAG)
3325 new_val |= IXGBE_VMOLR_AUPE;
3326 if (rx_mask & ETH_VMDQ_ACCEPT_HASH_MC)
3327 new_val |= IXGBE_VMOLR_ROMPE;
3328 if (rx_mask & ETH_VMDQ_ACCEPT_HASH_UC)
3329 new_val |= IXGBE_VMOLR_ROPE;
3330 if (rx_mask & ETH_VMDQ_ACCEPT_BROADCAST)
3331 new_val |= IXGBE_VMOLR_BAM;
3332 if (rx_mask & ETH_VMDQ_ACCEPT_MULTICAST)
3333 new_val |= IXGBE_VMOLR_MPE;
3339 ixgbe_set_pool_rx_mode(struct rte_eth_dev *dev, uint16_t pool,
3340 uint16_t rx_mask, uint8_t on)
3344 struct ixgbe_hw *hw =
3345 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3346 uint32_t vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
3348 if (hw->mac.type == ixgbe_mac_82598EB) {
3349 PMD_INIT_LOG(ERR, "setting VF receive mode set should be done"
3350 " on 82599 hardware and newer");
3353 if (ixgbe_vmdq_mode_check(hw) < 0)
3356 val = ixgbe_convert_vm_rx_mask_to_val(rx_mask, val);
3363 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
3369 ixgbe_set_pool_rx(struct rte_eth_dev *dev, uint16_t pool, uint8_t on)
3373 const uint8_t bit1 = 0x1;
3375 struct ixgbe_hw *hw =
3376 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3378 if (ixgbe_vmdq_mode_check(hw) < 0)
3381 addr = IXGBE_VFRE(pool >= ETH_64_POOLS/2);
3382 reg = IXGBE_READ_REG(hw, addr);
3390 IXGBE_WRITE_REG(hw, addr,reg);
3396 ixgbe_set_pool_tx(struct rte_eth_dev *dev, uint16_t pool, uint8_t on)
3400 const uint8_t bit1 = 0x1;
3402 struct ixgbe_hw *hw =
3403 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3405 if (ixgbe_vmdq_mode_check(hw) < 0)
3408 addr = IXGBE_VFTE(pool >= ETH_64_POOLS/2);
3409 reg = IXGBE_READ_REG(hw, addr);
3417 IXGBE_WRITE_REG(hw, addr,reg);
3423 ixgbe_set_pool_vlan_filter(struct rte_eth_dev *dev, uint16_t vlan,
3424 uint64_t pool_mask, uint8_t vlan_on)
3428 struct ixgbe_hw *hw =
3429 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3431 if (ixgbe_vmdq_mode_check(hw) < 0)
3433 for (pool_idx = 0; pool_idx < ETH_64_POOLS; pool_idx++) {
3434 if (pool_mask & ((uint64_t)(1ULL << pool_idx)))
3435 ret = hw->mac.ops.set_vfta(hw,vlan,pool_idx,vlan_on);
3443 #define IXGBE_MRCTL_VPME 0x01 /* Virtual Pool Mirroring. */
3444 #define IXGBE_MRCTL_UPME 0x02 /* Uplink Port Mirroring. */
3445 #define IXGBE_MRCTL_DPME 0x04 /* Downlink Port Mirroring. */
3446 #define IXGBE_MRCTL_VLME 0x08 /* VLAN Mirroring. */
3447 #define IXGBE_INVALID_MIRROR_TYPE(mirror_type) \
3448 ((mirror_type) & ~(uint8_t)(ETH_MIRROR_VIRTUAL_POOL_UP | \
3449 ETH_MIRROR_UPLINK_PORT | ETH_MIRROR_DOWNLINK_PORT | ETH_MIRROR_VLAN))
3452 ixgbe_mirror_rule_set(struct rte_eth_dev *dev,
3453 struct rte_eth_mirror_conf *mirror_conf,
3454 uint8_t rule_id, uint8_t on)
3456 uint32_t mr_ctl,vlvf;
3457 uint32_t mp_lsb = 0;
3458 uint32_t mv_msb = 0;
3459 uint32_t mv_lsb = 0;
3460 uint32_t mp_msb = 0;
3463 uint64_t vlan_mask = 0;
3465 const uint8_t pool_mask_offset = 32;
3466 const uint8_t vlan_mask_offset = 32;
3467 const uint8_t dst_pool_offset = 8;
3468 const uint8_t rule_mr_offset = 4;
3469 const uint8_t mirror_rule_mask= 0x0F;
3471 struct ixgbe_mirror_info *mr_info =
3472 (IXGBE_DEV_PRIVATE_TO_PFDATA(dev->data->dev_private));
3473 struct ixgbe_hw *hw =
3474 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3475 uint8_t mirror_type = 0;
3477 if (ixgbe_vmdq_mode_check(hw) < 0)
3480 if (rule_id >= IXGBE_MAX_MIRROR_RULES)
3483 if (IXGBE_INVALID_MIRROR_TYPE(mirror_conf->rule_type)) {
3484 PMD_DRV_LOG(ERR, "unsupported mirror type 0x%x.",
3485 mirror_conf->rule_type);
3489 if (mirror_conf->rule_type & ETH_MIRROR_VLAN) {
3490 mirror_type |= IXGBE_MRCTL_VLME;
3491 /* Check if vlan id is valid and find conresponding VLAN ID index in VLVF */
3492 for (i = 0;i < IXGBE_VLVF_ENTRIES; i++) {
3493 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
3494 /* search vlan id related pool vlan filter index */
3495 reg_index = ixgbe_find_vlvf_slot(hw,
3496 mirror_conf->vlan.vlan_id[i]);
3499 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(reg_index));
3500 if ((vlvf & IXGBE_VLVF_VIEN) &&
3501 ((vlvf & IXGBE_VLVF_VLANID_MASK) ==
3502 mirror_conf->vlan.vlan_id[i]))
3503 vlan_mask |= (1ULL << reg_index);
3510 mv_lsb = vlan_mask & 0xFFFFFFFF;
3511 mv_msb = vlan_mask >> vlan_mask_offset;
3513 mr_info->mr_conf[rule_id].vlan.vlan_mask =
3514 mirror_conf->vlan.vlan_mask;
3515 for(i = 0 ;i < ETH_VMDQ_MAX_VLAN_FILTERS; i++) {
3516 if(mirror_conf->vlan.vlan_mask & (1ULL << i))
3517 mr_info->mr_conf[rule_id].vlan.vlan_id[i] =
3518 mirror_conf->vlan.vlan_id[i];
3523 mr_info->mr_conf[rule_id].vlan.vlan_mask = 0;
3524 for(i = 0 ;i < ETH_VMDQ_MAX_VLAN_FILTERS; i++)
3525 mr_info->mr_conf[rule_id].vlan.vlan_id[i] = 0;
3530 * if enable pool mirror, write related pool mask register,if disable
3531 * pool mirror, clear PFMRVM register
3533 if (mirror_conf->rule_type & ETH_MIRROR_VIRTUAL_POOL_UP) {
3534 mirror_type |= IXGBE_MRCTL_VPME;
3536 mp_lsb = mirror_conf->pool_mask & 0xFFFFFFFF;
3537 mp_msb = mirror_conf->pool_mask >> pool_mask_offset;
3538 mr_info->mr_conf[rule_id].pool_mask =
3539 mirror_conf->pool_mask;
3544 mr_info->mr_conf[rule_id].pool_mask = 0;
3547 if (mirror_conf->rule_type & ETH_MIRROR_UPLINK_PORT)
3548 mirror_type |= IXGBE_MRCTL_UPME;
3549 if (mirror_conf->rule_type & ETH_MIRROR_DOWNLINK_PORT)
3550 mirror_type |= IXGBE_MRCTL_DPME;
3552 /* read mirror control register and recalculate it */
3553 mr_ctl = IXGBE_READ_REG(hw, IXGBE_MRCTL(rule_id));
3556 mr_ctl |= mirror_type;
3557 mr_ctl &= mirror_rule_mask;
3558 mr_ctl |= mirror_conf->dst_pool << dst_pool_offset;
3560 mr_ctl &= ~(mirror_conf->rule_type & mirror_rule_mask);
3562 mr_info->mr_conf[rule_id].rule_type = mirror_conf->rule_type;
3563 mr_info->mr_conf[rule_id].dst_pool = mirror_conf->dst_pool;
3565 /* write mirrror control register */
3566 IXGBE_WRITE_REG(hw, IXGBE_MRCTL(rule_id), mr_ctl);
3568 /* write pool mirrror control register */
3569 if (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) {
3570 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id), mp_lsb);
3571 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id + rule_mr_offset),
3574 /* write VLAN mirrror control register */
3575 if (mirror_conf->rule_type == ETH_MIRROR_VLAN) {
3576 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id), mv_lsb);
3577 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id + rule_mr_offset),
3585 ixgbe_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t rule_id)
3588 uint32_t lsb_val = 0;
3589 uint32_t msb_val = 0;
3590 const uint8_t rule_mr_offset = 4;
3592 struct ixgbe_hw *hw =
3593 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3594 struct ixgbe_mirror_info *mr_info =
3595 (IXGBE_DEV_PRIVATE_TO_PFDATA(dev->data->dev_private));
3597 if (ixgbe_vmdq_mode_check(hw) < 0)
3600 memset(&mr_info->mr_conf[rule_id], 0,
3601 sizeof(struct rte_eth_mirror_conf));
3603 /* clear PFVMCTL register */
3604 IXGBE_WRITE_REG(hw, IXGBE_MRCTL(rule_id), mr_ctl);
3606 /* clear pool mask register */
3607 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id), lsb_val);
3608 IXGBE_WRITE_REG(hw, IXGBE_VMRVM(rule_id + rule_mr_offset), msb_val);
3610 /* clear vlan mask register */
3611 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id), lsb_val);
3612 IXGBE_WRITE_REG(hw, IXGBE_VMRVLAN(rule_id + rule_mr_offset), msb_val);
3617 static int ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
3618 uint16_t queue_idx, uint16_t tx_rate)
3620 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3621 uint32_t rf_dec, rf_int;
3623 uint16_t link_speed = dev->data->dev_link.link_speed;
3625 if (queue_idx >= hw->mac.max_tx_queues)
3629 /* Calculate the rate factor values to set */
3630 rf_int = (uint32_t)link_speed / (uint32_t)tx_rate;
3631 rf_dec = (uint32_t)link_speed % (uint32_t)tx_rate;
3632 rf_dec = (rf_dec << IXGBE_RTTBCNRC_RF_INT_SHIFT) / tx_rate;
3634 bcnrc_val = IXGBE_RTTBCNRC_RS_ENA;
3635 bcnrc_val |= ((rf_int << IXGBE_RTTBCNRC_RF_INT_SHIFT) &
3636 IXGBE_RTTBCNRC_RF_INT_MASK_M);
3637 bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK);
3643 * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
3644 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported, otherwise
3647 if ((dev->data->dev_conf.rxmode.jumbo_frame == 1) &&
3648 (dev->data->dev_conf.rxmode.max_rx_pkt_len >=
3649 IXGBE_MAX_JUMBO_FRAME_SIZE))
3650 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM,
3651 IXGBE_MMW_SIZE_JUMBO_FRAME);
3653 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM,
3654 IXGBE_MMW_SIZE_DEFAULT);
3656 /* Set RTTBCNRC of queue X */
3657 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_idx);
3658 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
3659 IXGBE_WRITE_FLUSH(hw);
3664 static int ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
3665 uint16_t tx_rate, uint64_t q_msk)
3667 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3668 struct ixgbe_vf_info *vfinfo =
3669 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
3670 uint8_t nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
3671 uint32_t queue_stride =
3672 IXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
3673 uint32_t queue_idx = vf * queue_stride, idx = 0, vf_idx;
3674 uint32_t queue_end = queue_idx + nb_q_per_pool - 1;
3675 uint16_t total_rate = 0;
3677 if (queue_end >= hw->mac.max_tx_queues)
3680 if (vfinfo != NULL) {
3681 for (vf_idx = 0; vf_idx < dev->pci_dev->max_vfs; vf_idx++) {
3684 for (idx = 0; idx < RTE_DIM(vfinfo[vf_idx].tx_rate);
3686 total_rate += vfinfo[vf_idx].tx_rate[idx];
3691 /* Store tx_rate for this vf. */
3692 for (idx = 0; idx < nb_q_per_pool; idx++) {
3693 if (((uint64_t)0x1 << idx) & q_msk) {
3694 if (vfinfo[vf].tx_rate[idx] != tx_rate)
3695 vfinfo[vf].tx_rate[idx] = tx_rate;
3696 total_rate += tx_rate;
3700 if (total_rate > dev->data->dev_link.link_speed) {
3702 * Reset stored TX rate of the VF if it causes exceed
3705 memset(vfinfo[vf].tx_rate, 0, sizeof(vfinfo[vf].tx_rate));
3709 /* Set RTTBCNRC of each queue/pool for vf X */
3710 for (; queue_idx <= queue_end; queue_idx++) {
3712 ixgbe_set_queue_rate_limit(dev, queue_idx, tx_rate);
3720 ixgbevf_add_mac_addr(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
3721 __attribute__((unused)) uint32_t index,
3722 __attribute__((unused)) uint32_t pool)
3724 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3728 * On a 82599 VF, adding again the same MAC addr is not an idempotent
3729 * operation. Trap this case to avoid exhausting the [very limited]
3730 * set of PF resources used to store VF MAC addresses.
3732 if (memcmp(hw->mac.perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
3734 diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
3737 PMD_DRV_LOG(ERR, "Unable to add MAC address - diag=%d", diag);
3741 ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
3743 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3744 struct ether_addr *perm_addr = (struct ether_addr *) hw->mac.perm_addr;
3745 struct ether_addr *mac_addr;
3750 * The IXGBE_VF_SET_MACVLAN command of the ixgbe-pf driver does
3751 * not support the deletion of a given MAC address.
3752 * Instead, it imposes to delete all MAC addresses, then to add again
3753 * all MAC addresses with the exception of the one to be deleted.
3755 (void) ixgbevf_set_uc_addr_vf(hw, 0, NULL);
3758 * Add again all MAC addresses, with the exception of the deleted one
3759 * and of the permanent MAC address.
3761 for (i = 0, mac_addr = dev->data->mac_addrs;
3762 i < hw->mac.num_rar_entries; i++, mac_addr++) {
3763 /* Skip the deleted MAC address */
3766 /* Skip NULL MAC addresses */
3767 if (is_zero_ether_addr(mac_addr))
3769 /* Skip the permanent MAC address */
3770 if (memcmp(perm_addr, mac_addr, sizeof(struct ether_addr)) == 0)
3772 diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
3775 "Adding again MAC address "
3776 "%02x:%02x:%02x:%02x:%02x:%02x failed "
3778 mac_addr->addr_bytes[0],
3779 mac_addr->addr_bytes[1],
3780 mac_addr->addr_bytes[2],
3781 mac_addr->addr_bytes[3],
3782 mac_addr->addr_bytes[4],
3783 mac_addr->addr_bytes[5],
3788 #define MAC_TYPE_FILTER_SUP(type) do {\
3789 if ((type) != ixgbe_mac_82599EB && (type) != ixgbe_mac_X540 &&\
3790 (type) != ixgbe_mac_X550)\
3795 ixgbe_syn_filter_set(struct rte_eth_dev *dev,
3796 struct rte_eth_syn_filter *filter,
3799 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3802 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
3805 synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
3808 if (synqf & IXGBE_SYN_FILTER_ENABLE)
3810 synqf = (uint32_t)(((filter->queue << IXGBE_SYN_FILTER_QUEUE_SHIFT) &
3811 IXGBE_SYN_FILTER_QUEUE) | IXGBE_SYN_FILTER_ENABLE);
3813 if (filter->hig_pri)
3814 synqf |= IXGBE_SYN_FILTER_SYNQFP;
3816 synqf &= ~IXGBE_SYN_FILTER_SYNQFP;
3818 if (!(synqf & IXGBE_SYN_FILTER_ENABLE))
3820 synqf &= ~(IXGBE_SYN_FILTER_QUEUE | IXGBE_SYN_FILTER_ENABLE);
3822 IXGBE_WRITE_REG(hw, IXGBE_SYNQF, synqf);
3823 IXGBE_WRITE_FLUSH(hw);
3828 ixgbe_syn_filter_get(struct rte_eth_dev *dev,
3829 struct rte_eth_syn_filter *filter)
3831 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3832 uint32_t synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
3834 if (synqf & IXGBE_SYN_FILTER_ENABLE) {
3835 filter->hig_pri = (synqf & IXGBE_SYN_FILTER_SYNQFP) ? 1 : 0;
3836 filter->queue = (uint16_t)((synqf & IXGBE_SYN_FILTER_QUEUE) >> 1);
3843 ixgbe_syn_filter_handle(struct rte_eth_dev *dev,
3844 enum rte_filter_op filter_op,
3847 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3850 MAC_TYPE_FILTER_SUP(hw->mac.type);
3852 if (filter_op == RTE_ETH_FILTER_NOP)
3856 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
3861 switch (filter_op) {
3862 case RTE_ETH_FILTER_ADD:
3863 ret = ixgbe_syn_filter_set(dev,
3864 (struct rte_eth_syn_filter *)arg,
3867 case RTE_ETH_FILTER_DELETE:
3868 ret = ixgbe_syn_filter_set(dev,
3869 (struct rte_eth_syn_filter *)arg,
3872 case RTE_ETH_FILTER_GET:
3873 ret = ixgbe_syn_filter_get(dev,
3874 (struct rte_eth_syn_filter *)arg);
3877 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
3886 static inline enum ixgbe_5tuple_protocol
3887 convert_protocol_type(uint8_t protocol_value)
3889 if (protocol_value == IPPROTO_TCP)
3890 return IXGBE_FILTER_PROTOCOL_TCP;
3891 else if (protocol_value == IPPROTO_UDP)
3892 return IXGBE_FILTER_PROTOCOL_UDP;
3893 else if (protocol_value == IPPROTO_SCTP)
3894 return IXGBE_FILTER_PROTOCOL_SCTP;
3896 return IXGBE_FILTER_PROTOCOL_NONE;
3900 * add a 5tuple filter
3903 * dev: Pointer to struct rte_eth_dev.
3904 * index: the index the filter allocates.
3905 * filter: ponter to the filter that will be added.
3906 * rx_queue: the queue id the filter assigned to.
3909 * - On success, zero.
3910 * - On failure, a negative value.
3913 ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
3914 struct ixgbe_5tuple_filter *filter)
3916 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3917 struct ixgbe_filter_info *filter_info =
3918 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3920 uint32_t ftqf, sdpqf;
3921 uint32_t l34timir = 0;
3922 uint8_t mask = 0xff;
3925 * look for an unused 5tuple filter index,
3926 * and insert the filter to list.
3928 for (i = 0; i < IXGBE_MAX_FTQF_FILTERS; i++) {
3929 idx = i / (sizeof(uint32_t) * NBBY);
3930 shift = i % (sizeof(uint32_t) * NBBY);
3931 if (!(filter_info->fivetuple_mask[idx] & (1 << shift))) {
3932 filter_info->fivetuple_mask[idx] |= 1 << shift;
3934 TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
3940 if (i >= IXGBE_MAX_FTQF_FILTERS) {
3941 PMD_DRV_LOG(ERR, "5tuple filters are full.");
3945 sdpqf = (uint32_t)(filter->filter_info.dst_port <<
3946 IXGBE_SDPQF_DSTPORT_SHIFT);
3947 sdpqf = sdpqf | (filter->filter_info.src_port & IXGBE_SDPQF_SRCPORT);
3949 ftqf = (uint32_t)(filter->filter_info.proto &
3950 IXGBE_FTQF_PROTOCOL_MASK);
3951 ftqf |= (uint32_t)((filter->filter_info.priority &
3952 IXGBE_FTQF_PRIORITY_MASK) << IXGBE_FTQF_PRIORITY_SHIFT);
3953 if (filter->filter_info.src_ip_mask == 0) /* 0 means compare. */
3954 mask &= IXGBE_FTQF_SOURCE_ADDR_MASK;
3955 if (filter->filter_info.dst_ip_mask == 0)
3956 mask &= IXGBE_FTQF_DEST_ADDR_MASK;
3957 if (filter->filter_info.src_port_mask == 0)
3958 mask &= IXGBE_FTQF_SOURCE_PORT_MASK;
3959 if (filter->filter_info.dst_port_mask == 0)
3960 mask &= IXGBE_FTQF_DEST_PORT_MASK;
3961 if (filter->filter_info.proto_mask == 0)
3962 mask &= IXGBE_FTQF_PROTOCOL_COMP_MASK;
3963 ftqf |= mask << IXGBE_FTQF_5TUPLE_MASK_SHIFT;
3964 ftqf |= IXGBE_FTQF_POOL_MASK_EN;
3965 ftqf |= IXGBE_FTQF_QUEUE_ENABLE;
3967 IXGBE_WRITE_REG(hw, IXGBE_DAQF(i), filter->filter_info.dst_ip);
3968 IXGBE_WRITE_REG(hw, IXGBE_SAQF(i), filter->filter_info.src_ip);
3969 IXGBE_WRITE_REG(hw, IXGBE_SDPQF(i), sdpqf);
3970 IXGBE_WRITE_REG(hw, IXGBE_FTQF(i), ftqf);
3972 l34timir |= IXGBE_L34T_IMIR_RESERVE;
3973 l34timir |= (uint32_t)(filter->queue <<
3974 IXGBE_L34T_IMIR_QUEUE_SHIFT);
3975 IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(i), l34timir);
3980 * remove a 5tuple filter
3983 * dev: Pointer to struct rte_eth_dev.
3984 * filter: the pointer of the filter will be removed.
3987 ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
3988 struct ixgbe_5tuple_filter *filter)
3990 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3991 struct ixgbe_filter_info *filter_info =
3992 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3993 uint16_t index = filter->index;
3995 filter_info->fivetuple_mask[index / (sizeof(uint32_t) * NBBY)] &=
3996 ~(1 << (index % (sizeof(uint32_t) * NBBY)));
3997 TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
4000 IXGBE_WRITE_REG(hw, IXGBE_DAQF(index), 0);
4001 IXGBE_WRITE_REG(hw, IXGBE_SAQF(index), 0);
4002 IXGBE_WRITE_REG(hw, IXGBE_SDPQF(index), 0);
4003 IXGBE_WRITE_REG(hw, IXGBE_FTQF(index), 0);
4004 IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(index), 0);
4008 ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
4010 struct ixgbe_hw *hw;
4011 uint32_t max_frame = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
4013 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4015 if ((mtu < ETHER_MIN_MTU) || (max_frame > ETHER_MAX_JUMBO_FRAME_LEN))
4018 /* refuse mtu that requires the support of scattered packets when this
4019 * feature has not been enabled before. */
4020 if (!dev->data->scattered_rx &&
4021 (max_frame + 2 * IXGBE_VLAN_TAG_SIZE >
4022 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
4026 * When supported by the underlying PF driver, use the IXGBE_VF_SET_MTU
4027 * request of the version 2.0 of the mailbox API.
4028 * For now, use the IXGBE_VF_SET_LPE request of the version 1.0
4029 * of the mailbox API.
4030 * This call to IXGBE_SET_LPE action won't work with ixgbe pf drivers
4031 * prior to 3.11.33 which contains the following change:
4032 * "ixgbe: Enable jumbo frames support w/ SR-IOV"
4034 ixgbevf_rlpml_set_vf(hw, max_frame);
4036 /* update max frame size */
4037 dev->data->dev_conf.rxmode.max_rx_pkt_len = max_frame;
4041 #define MAC_TYPE_FILTER_SUP_EXT(type) do {\
4042 if ((type) != ixgbe_mac_82599EB && (type) != ixgbe_mac_X540)\
4046 static inline struct ixgbe_5tuple_filter *
4047 ixgbe_5tuple_filter_lookup(struct ixgbe_5tuple_filter_list *filter_list,
4048 struct ixgbe_5tuple_filter_info *key)
4050 struct ixgbe_5tuple_filter *it;
4052 TAILQ_FOREACH(it, filter_list, entries) {
4053 if (memcmp(key, &it->filter_info,
4054 sizeof(struct ixgbe_5tuple_filter_info)) == 0) {
4061 /* translate elements in struct rte_eth_ntuple_filter to struct ixgbe_5tuple_filter_info*/
4063 ntuple_filter_to_5tuple(struct rte_eth_ntuple_filter *filter,
4064 struct ixgbe_5tuple_filter_info *filter_info)
4066 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM ||
4067 filter->priority > IXGBE_5TUPLE_MAX_PRI ||
4068 filter->priority < IXGBE_5TUPLE_MIN_PRI)
4071 switch (filter->dst_ip_mask) {
4073 filter_info->dst_ip_mask = 0;
4074 filter_info->dst_ip = filter->dst_ip;
4077 filter_info->dst_ip_mask = 1;
4080 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
4084 switch (filter->src_ip_mask) {
4086 filter_info->src_ip_mask = 0;
4087 filter_info->src_ip = filter->src_ip;
4090 filter_info->src_ip_mask = 1;
4093 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
4097 switch (filter->dst_port_mask) {
4099 filter_info->dst_port_mask = 0;
4100 filter_info->dst_port = filter->dst_port;
4103 filter_info->dst_port_mask = 1;
4106 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
4110 switch (filter->src_port_mask) {
4112 filter_info->src_port_mask = 0;
4113 filter_info->src_port = filter->src_port;
4116 filter_info->src_port_mask = 1;
4119 PMD_DRV_LOG(ERR, "invalid src_port mask.");
4123 switch (filter->proto_mask) {
4125 filter_info->proto_mask = 0;
4126 filter_info->proto =
4127 convert_protocol_type(filter->proto);
4130 filter_info->proto_mask = 1;
4133 PMD_DRV_LOG(ERR, "invalid protocol mask.");
4137 filter_info->priority = (uint8_t)filter->priority;
4142 * add or delete a ntuple filter
4145 * dev: Pointer to struct rte_eth_dev.
4146 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4147 * add: if true, add filter, if false, remove filter
4150 * - On success, zero.
4151 * - On failure, a negative value.
4154 ixgbe_add_del_ntuple_filter(struct rte_eth_dev *dev,
4155 struct rte_eth_ntuple_filter *ntuple_filter,
4158 struct ixgbe_filter_info *filter_info =
4159 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4160 struct ixgbe_5tuple_filter_info filter_5tuple;
4161 struct ixgbe_5tuple_filter *filter;
4164 if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
4165 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
4169 memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
4170 ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
4174 filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
4176 if (filter != NULL && add) {
4177 PMD_DRV_LOG(ERR, "filter exists.");
4180 if (filter == NULL && !add) {
4181 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4186 filter = rte_zmalloc("ixgbe_5tuple_filter",
4187 sizeof(struct ixgbe_5tuple_filter), 0);
4190 (void)rte_memcpy(&filter->filter_info,
4192 sizeof(struct ixgbe_5tuple_filter_info));
4193 filter->queue = ntuple_filter->queue;
4194 ret = ixgbe_add_5tuple_filter(dev, filter);
4200 ixgbe_remove_5tuple_filter(dev, filter);
4206 * get a ntuple filter
4209 * dev: Pointer to struct rte_eth_dev.
4210 * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4213 * - On success, zero.
4214 * - On failure, a negative value.
4217 ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
4218 struct rte_eth_ntuple_filter *ntuple_filter)
4220 struct ixgbe_filter_info *filter_info =
4221 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4222 struct ixgbe_5tuple_filter_info filter_5tuple;
4223 struct ixgbe_5tuple_filter *filter;
4226 if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
4227 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
4231 memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
4232 ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
4236 filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
4238 if (filter == NULL) {
4239 PMD_DRV_LOG(ERR, "filter doesn't exist.");
4242 ntuple_filter->queue = filter->queue;
4247 * ixgbe_ntuple_filter_handle - Handle operations for ntuple filter.
4248 * @dev: pointer to rte_eth_dev structure
4249 * @filter_op:operation will be taken.
4250 * @arg: a pointer to specific structure corresponding to the filter_op
4253 * - On success, zero.
4254 * - On failure, a negative value.
4257 ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
4258 enum rte_filter_op filter_op,
4261 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4264 MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
4266 if (filter_op == RTE_ETH_FILTER_NOP)
4270 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4275 switch (filter_op) {
4276 case RTE_ETH_FILTER_ADD:
4277 ret = ixgbe_add_del_ntuple_filter(dev,
4278 (struct rte_eth_ntuple_filter *)arg,
4281 case RTE_ETH_FILTER_DELETE:
4282 ret = ixgbe_add_del_ntuple_filter(dev,
4283 (struct rte_eth_ntuple_filter *)arg,
4286 case RTE_ETH_FILTER_GET:
4287 ret = ixgbe_get_ntuple_filter(dev,
4288 (struct rte_eth_ntuple_filter *)arg);
4291 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4299 ixgbe_ethertype_filter_lookup(struct ixgbe_filter_info *filter_info,
4304 for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
4305 if (filter_info->ethertype_filters[i] == ethertype &&
4306 (filter_info->ethertype_mask & (1 << i)))
4313 ixgbe_ethertype_filter_insert(struct ixgbe_filter_info *filter_info,
4318 for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
4319 if (!(filter_info->ethertype_mask & (1 << i))) {
4320 filter_info->ethertype_mask |= 1 << i;
4321 filter_info->ethertype_filters[i] = ethertype;
4329 ixgbe_ethertype_filter_remove(struct ixgbe_filter_info *filter_info,
4332 if (idx >= IXGBE_MAX_ETQF_FILTERS)
4334 filter_info->ethertype_mask &= ~(1 << idx);
4335 filter_info->ethertype_filters[idx] = 0;
4340 ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
4341 struct rte_eth_ethertype_filter *filter,
4344 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4345 struct ixgbe_filter_info *filter_info =
4346 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4351 if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
4354 if (filter->ether_type == ETHER_TYPE_IPv4 ||
4355 filter->ether_type == ETHER_TYPE_IPv6) {
4356 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
4357 " ethertype filter.", filter->ether_type);
4361 if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
4362 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
4365 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
4366 PMD_DRV_LOG(ERR, "drop option is unsupported.");
4370 ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
4371 if (ret >= 0 && add) {
4372 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
4373 filter->ether_type);
4376 if (ret < 0 && !add) {
4377 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4378 filter->ether_type);
4383 ret = ixgbe_ethertype_filter_insert(filter_info,
4384 filter->ether_type);
4386 PMD_DRV_LOG(ERR, "ethertype filters are full.");
4389 etqf = IXGBE_ETQF_FILTER_EN;
4390 etqf |= (uint32_t)filter->ether_type;
4391 etqs |= (uint32_t)((filter->queue <<
4392 IXGBE_ETQS_RX_QUEUE_SHIFT) &
4393 IXGBE_ETQS_RX_QUEUE);
4394 etqs |= IXGBE_ETQS_QUEUE_EN;
4396 ret = ixgbe_ethertype_filter_remove(filter_info, (uint8_t)ret);
4400 IXGBE_WRITE_REG(hw, IXGBE_ETQF(ret), etqf);
4401 IXGBE_WRITE_REG(hw, IXGBE_ETQS(ret), etqs);
4402 IXGBE_WRITE_FLUSH(hw);
4408 ixgbe_get_ethertype_filter(struct rte_eth_dev *dev,
4409 struct rte_eth_ethertype_filter *filter)
4411 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4412 struct ixgbe_filter_info *filter_info =
4413 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4414 uint32_t etqf, etqs;
4417 ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
4419 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4420 filter->ether_type);
4424 etqf = IXGBE_READ_REG(hw, IXGBE_ETQF(ret));
4425 if (etqf & IXGBE_ETQF_FILTER_EN) {
4426 etqs = IXGBE_READ_REG(hw, IXGBE_ETQS(ret));
4427 filter->ether_type = etqf & IXGBE_ETQF_ETHERTYPE;
4429 filter->queue = (etqs & IXGBE_ETQS_RX_QUEUE) >>
4430 IXGBE_ETQS_RX_QUEUE_SHIFT;
4437 * ixgbe_ethertype_filter_handle - Handle operations for ethertype filter.
4438 * @dev: pointer to rte_eth_dev structure
4439 * @filter_op:operation will be taken.
4440 * @arg: a pointer to specific structure corresponding to the filter_op
4443 ixgbe_ethertype_filter_handle(struct rte_eth_dev *dev,
4444 enum rte_filter_op filter_op,
4447 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4450 MAC_TYPE_FILTER_SUP(hw->mac.type);
4452 if (filter_op == RTE_ETH_FILTER_NOP)
4456 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
4461 switch (filter_op) {
4462 case RTE_ETH_FILTER_ADD:
4463 ret = ixgbe_add_del_ethertype_filter(dev,
4464 (struct rte_eth_ethertype_filter *)arg,
4467 case RTE_ETH_FILTER_DELETE:
4468 ret = ixgbe_add_del_ethertype_filter(dev,
4469 (struct rte_eth_ethertype_filter *)arg,
4472 case RTE_ETH_FILTER_GET:
4473 ret = ixgbe_get_ethertype_filter(dev,
4474 (struct rte_eth_ethertype_filter *)arg);
4477 PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
4485 ixgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
4486 enum rte_filter_type filter_type,
4487 enum rte_filter_op filter_op,
4492 switch (filter_type) {
4493 case RTE_ETH_FILTER_NTUPLE:
4494 ret = ixgbe_ntuple_filter_handle(dev, filter_op, arg);
4496 case RTE_ETH_FILTER_ETHERTYPE:
4497 ret = ixgbe_ethertype_filter_handle(dev, filter_op, arg);
4499 case RTE_ETH_FILTER_SYN:
4500 ret = ixgbe_syn_filter_handle(dev, filter_op, arg);
4502 case RTE_ETH_FILTER_FDIR:
4503 ret = ixgbe_fdir_ctrl_func(dev, filter_op, arg);
4506 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
4515 ixgbe_dev_addr_list_itr(__attribute__((unused)) struct ixgbe_hw *hw,
4516 u8 **mc_addr_ptr, u32 *vmdq)
4521 mc_addr = *mc_addr_ptr;
4522 *mc_addr_ptr = (mc_addr + sizeof(struct ether_addr));
4527 ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
4528 struct ether_addr *mc_addr_set,
4529 uint32_t nb_mc_addr)
4531 struct ixgbe_hw *hw;
4534 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4535 mc_addr_list = (u8 *)mc_addr_set;
4536 return ixgbe_update_mc_addr_list(hw, mc_addr_list, nb_mc_addr,
4537 ixgbe_dev_addr_list_itr, TRUE);
4541 ixgbe_timesync_enable(struct rte_eth_dev *dev)
4543 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4547 /* Enable system time for platforms where it isn't on by default. */
4548 tsauxc = IXGBE_READ_REG(hw, IXGBE_TSAUXC);
4549 tsauxc &= ~IXGBE_TSAUXC_DISABLE_SYSTIME;
4550 IXGBE_WRITE_REG(hw, IXGBE_TSAUXC, tsauxc);
4552 /* Start incrementing the register used to timestamp PTP packets. */
4553 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, IXGBE_TIMINCA_INIT);
4555 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
4556 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588),
4558 IXGBE_ETQF_FILTER_EN |
4561 /* Enable timestamping of received PTP packets. */
4562 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
4563 tsync_ctl |= IXGBE_TSYNCRXCTL_ENABLED;
4564 IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
4566 /* Enable timestamping of transmitted PTP packets. */
4567 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
4568 tsync_ctl |= IXGBE_TSYNCTXCTL_ENABLED;
4569 IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
4575 ixgbe_timesync_disable(struct rte_eth_dev *dev)
4577 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4580 /* Disable timestamping of transmitted PTP packets. */
4581 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
4582 tsync_ctl &= ~IXGBE_TSYNCTXCTL_ENABLED;
4583 IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
4585 /* Disable timestamping of received PTP packets. */
4586 tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
4587 tsync_ctl &= ~IXGBE_TSYNCRXCTL_ENABLED;
4588 IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
4590 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
4591 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588), 0);
4593 /* Stop incrementating the System Time registers. */
4594 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0);
4600 ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
4601 struct timespec *timestamp,
4602 uint32_t flags __rte_unused)
4604 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4605 uint32_t tsync_rxctl;
4609 tsync_rxctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
4610 if ((tsync_rxctl & IXGBE_TSYNCRXCTL_VALID) == 0)
4613 rx_stmpl = IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
4614 rx_stmph = IXGBE_READ_REG(hw, IXGBE_RXSTMPH);
4616 timestamp->tv_sec = (uint64_t)(((uint64_t)rx_stmph << 32) | rx_stmpl);
4617 timestamp->tv_nsec = 0;
4623 ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
4624 struct timespec *timestamp)
4626 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4627 uint32_t tsync_txctl;
4631 tsync_txctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
4632 if ((tsync_txctl & IXGBE_TSYNCTXCTL_VALID) == 0)
4635 tx_stmpl = IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
4636 tx_stmph = IXGBE_READ_REG(hw, IXGBE_TXSTMPH);
4638 timestamp->tv_sec = (uint64_t)(((uint64_t)tx_stmph << 32) | tx_stmpl);
4639 timestamp->tv_nsec = 0;
4644 static struct rte_driver rte_ixgbe_driver = {
4646 .init = rte_ixgbe_pmd_init,
4649 static struct rte_driver rte_ixgbevf_driver = {
4651 .init = rte_ixgbevf_pmd_init,
4654 PMD_REGISTER_DRIVER(rte_ixgbe_driver);
4655 PMD_REGISTER_DRIVER(rte_ixgbevf_driver);