Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <string.h>
10 : : #include <unistd.h>
11 : : #include <stdarg.h>
12 : : #include <inttypes.h>
13 : : #include <rte_string_fns.h>
14 : : #include <rte_byteorder.h>
15 : : #include <rte_common.h>
16 : : #include <rte_cycles.h>
17 : :
18 : : #include <rte_interrupts.h>
19 : : #include <rte_log.h>
20 : : #include <rte_debug.h>
21 : : #include <rte_pci.h>
22 : : #include <bus_pci_driver.h>
23 : : #include <rte_branch_prediction.h>
24 : : #include <rte_memory.h>
25 : : #include <rte_kvargs.h>
26 : : #include <rte_eal.h>
27 : : #include <rte_alarm.h>
28 : : #include <rte_ether.h>
29 : : #include <ethdev_driver.h>
30 : : #include <ethdev_pci.h>
31 : : #include <rte_malloc.h>
32 : : #include <rte_random.h>
33 : : #include <dev_driver.h>
34 : : #include <rte_hash_crc.h>
35 : : #ifdef RTE_LIB_SECURITY
36 : : #include <rte_security_driver.h>
37 : : #endif
38 : : #include <rte_os_shim.h>
39 : :
40 : : #include "ixgbe_logs.h"
41 : : #include "base/ixgbe_api.h"
42 : : #include "base/ixgbe_vf.h"
43 : : #include "base/ixgbe_common.h"
44 : : #include "ixgbe_ethdev.h"
45 : : #include "ixgbe_bypass.h"
46 : : #include "ixgbe_rxtx.h"
47 : : #include "base/ixgbe_type.h"
48 : : #include "base/ixgbe_phy.h"
49 : : #include "base/ixgbe_osdep.h"
50 : : #include "ixgbe_regs.h"
51 : :
52 : : /*
53 : : * High threshold controlling when to start sending XOFF frames. Must be at
54 : : * least 8 bytes less than receive packet buffer size. This value is in units
55 : : * of 1024 bytes.
56 : : */
57 : : #define IXGBE_FC_HI 0x80
58 : :
59 : : /*
60 : : * Low threshold controlling when to start sending XON frames. This value is
61 : : * in units of 1024 bytes.
62 : : */
63 : : #define IXGBE_FC_LO 0x40
64 : :
65 : : /* Timer value included in XOFF frames. */
66 : : #define IXGBE_FC_PAUSE 0x680
67 : :
68 : : /*Default value of Max Rx Queue*/
69 : : #define IXGBE_MAX_RX_QUEUE_NUM 128
70 : :
71 : : #define IXGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
72 : : #define IXGBE_LINK_UP_CHECK_TIMEOUT 1000 /* ms */
73 : : #define IXGBE_VMDQ_NUM_UC_MAC 4096 /* Maximum nb. of UC MAC addr. */
74 : :
75 : : #define IXGBE_MMW_SIZE_DEFAULT 0x4
76 : : #define IXGBE_MMW_SIZE_JUMBO_FRAME 0x14
77 : : #define IXGBE_MAX_RING_DESC 8192 /* replicate define from rxtx */
78 : :
79 : : /*
80 : : * Default values for RX/TX configuration
81 : : */
82 : : #define IXGBE_DEFAULT_RX_FREE_THRESH 32
83 : : #define IXGBE_DEFAULT_RX_PTHRESH 8
84 : : #define IXGBE_DEFAULT_RX_HTHRESH 8
85 : : #define IXGBE_DEFAULT_RX_WTHRESH 0
86 : :
87 : : #define IXGBE_DEFAULT_TX_FREE_THRESH 32
88 : : #define IXGBE_DEFAULT_TX_PTHRESH 32
89 : : #define IXGBE_DEFAULT_TX_HTHRESH 0
90 : : #define IXGBE_DEFAULT_TX_WTHRESH 0
91 : : #define IXGBE_DEFAULT_TX_RSBIT_THRESH 32
92 : :
93 : : /* Bit shift and mask */
94 : : #define IXGBE_4_BIT_WIDTH (CHAR_BIT / 2)
95 : : #define IXGBE_4_BIT_MASK RTE_LEN2MASK(IXGBE_4_BIT_WIDTH, uint8_t)
96 : : #define IXGBE_8_BIT_WIDTH CHAR_BIT
97 : : #define IXGBE_8_BIT_MASK UINT8_MAX
98 : :
99 : : #define IXGBEVF_PMD_NAME "rte_ixgbevf_pmd" /* PMD name */
100 : :
101 : : #define IXGBE_QUEUE_STAT_COUNTERS (sizeof(hw_stats->qprc) / sizeof(hw_stats->qprc[0]))
102 : :
103 : : /* Additional timesync values. */
104 : : #define NSEC_PER_SEC 1000000000L
105 : : #define IXGBE_INCVAL_10GB 0x66666666
106 : : #define IXGBE_INCVAL_1GB 0x40000000
107 : : #define IXGBE_INCVAL_100 0x50000000
108 : : #define IXGBE_INCVAL_SHIFT_10GB 28
109 : : #define IXGBE_INCVAL_SHIFT_1GB 24
110 : : #define IXGBE_INCVAL_SHIFT_100 21
111 : : #define IXGBE_INCVAL_SHIFT_82599 7
112 : : #define IXGBE_INCPER_SHIFT_82599 24
113 : :
114 : : #define IXGBE_CYCLECOUNTER_MASK 0xffffffffffffffffULL
115 : :
116 : : #define IXGBE_VT_CTL_POOLING_MODE_MASK 0x00030000
117 : : #define IXGBE_VT_CTL_POOLING_MODE_ETAG 0x00010000
118 : : #define IXGBE_ETAG_ETYPE 0x00005084
119 : : #define IXGBE_ETAG_ETYPE_MASK 0x0000ffff
120 : : #define IXGBE_ETAG_ETYPE_VALID 0x80000000
121 : : #define IXGBE_RAH_ADTYPE 0x40000000
122 : : #define IXGBE_RAL_ETAG_FILTER_MASK 0x00003fff
123 : : #define IXGBE_VMVIR_TAGA_MASK 0x18000000
124 : : #define IXGBE_VMVIR_TAGA_ETAG_INSERT 0x08000000
125 : : #define IXGBE_VMTIR(_i) (0x00017000 + ((_i) * 4)) /* 64 of these (0-63) */
126 : : #define IXGBE_QDE_STRIP_TAG 0x00000004
127 : : #define IXGBE_VTEICR_MASK 0x07
128 : :
129 : : #define IXGBE_EXVET_VET_EXT_SHIFT 16
130 : : #define IXGBE_DMATXCTL_VT_MASK 0xFFFF0000
131 : :
132 : : #define IXGBE_DEVARG_FIBER_SDP3_NOT_TX_DISABLE "fiber_sdp3_no_tx_disable"
133 : :
134 : : static const char * const ixgbe_valid_arguments[] = {
135 : : IXGBE_DEVARG_FIBER_SDP3_NOT_TX_DISABLE,
136 : : NULL
137 : : };
138 : :
139 : : #define IXGBEVF_DEVARG_PFLINK_FULLCHK "pflink_fullchk"
140 : :
141 : : static const char * const ixgbevf_valid_arguments[] = {
142 : : IXGBEVF_DEVARG_PFLINK_FULLCHK,
143 : : NULL
144 : : };
145 : :
146 : : static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params);
147 : : static int eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev);
148 : : static int ixgbe_fdir_filter_init(struct rte_eth_dev *eth_dev);
149 : : static int ixgbe_fdir_filter_uninit(struct rte_eth_dev *eth_dev);
150 : : static int ixgbe_l2_tn_filter_init(struct rte_eth_dev *eth_dev);
151 : : static int ixgbe_l2_tn_filter_uninit(struct rte_eth_dev *eth_dev);
152 : : static int ixgbe_ntuple_filter_uninit(struct rte_eth_dev *eth_dev);
153 : : static int ixgbe_dev_configure(struct rte_eth_dev *dev);
154 : : static int ixgbe_dev_start(struct rte_eth_dev *dev);
155 : : static int ixgbe_dev_stop(struct rte_eth_dev *dev);
156 : : static int ixgbe_dev_set_link_up(struct rte_eth_dev *dev);
157 : : static int ixgbe_dev_set_link_down(struct rte_eth_dev *dev);
158 : : static int ixgbe_dev_close(struct rte_eth_dev *dev);
159 : : static int ixgbe_dev_reset(struct rte_eth_dev *dev);
160 : : static int ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
161 : : static int ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
162 : : static int ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
163 : : static int ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev);
164 : : static int ixgbe_dev_link_update(struct rte_eth_dev *dev,
165 : : int wait_to_complete);
166 : : static int ixgbe_dev_stats_get(struct rte_eth_dev *dev,
167 : : struct rte_eth_stats *stats);
168 : : static int ixgbe_dev_xstats_get(struct rte_eth_dev *dev,
169 : : struct rte_eth_xstat *xstats, unsigned n);
170 : : static int ixgbevf_dev_xstats_get(struct rte_eth_dev *dev,
171 : : struct rte_eth_xstat *xstats, unsigned n);
172 : : static int
173 : : ixgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
174 : : uint64_t *values, unsigned int n);
175 : : static int ixgbe_dev_stats_reset(struct rte_eth_dev *dev);
176 : : static int ixgbe_dev_xstats_reset(struct rte_eth_dev *dev);
177 : : static int ixgbe_dev_xstats_get_names(struct rte_eth_dev *dev,
178 : : struct rte_eth_xstat_name *xstats_names,
179 : : unsigned int size);
180 : : static int ixgbevf_dev_xstats_get_names(struct rte_eth_dev *dev,
181 : : struct rte_eth_xstat_name *xstats_names, unsigned limit);
182 : : static int ixgbe_dev_xstats_get_names_by_id(
183 : : struct rte_eth_dev *dev,
184 : : const uint64_t *ids,
185 : : struct rte_eth_xstat_name *xstats_names,
186 : : unsigned int limit);
187 : : static int ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
188 : : uint16_t queue_id,
189 : : uint8_t stat_idx,
190 : : uint8_t is_rx);
191 : : static int ixgbe_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
192 : : size_t fw_size);
193 : : static int ixgbe_dev_info_get(struct rte_eth_dev *dev,
194 : : struct rte_eth_dev_info *dev_info);
195 : : static const uint32_t *ixgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev,
196 : : size_t *no_of_elements);
197 : : static int ixgbevf_dev_info_get(struct rte_eth_dev *dev,
198 : : struct rte_eth_dev_info *dev_info);
199 : : static int ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
200 : :
201 : : static int ixgbe_vlan_filter_set(struct rte_eth_dev *dev,
202 : : uint16_t vlan_id, int on);
203 : : static int ixgbe_vlan_tpid_set(struct rte_eth_dev *dev,
204 : : enum rte_vlan_type vlan_type,
205 : : uint16_t tpid_id);
206 : : static void ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
207 : : uint16_t queue, bool on);
208 : : static void ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue,
209 : : int on);
210 : : static void ixgbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev,
211 : : int mask);
212 : : static int ixgbe_vlan_offload_config(struct rte_eth_dev *dev, int mask);
213 : : static int ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask);
214 : : static void ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue);
215 : : static void ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue);
216 : : static void ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev);
217 : : static void ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev);
218 : :
219 : : static int ixgbe_dev_led_on(struct rte_eth_dev *dev);
220 : : static int ixgbe_dev_led_off(struct rte_eth_dev *dev);
221 : : static int ixgbe_flow_ctrl_get(struct rte_eth_dev *dev,
222 : : struct rte_eth_fc_conf *fc_conf);
223 : : static int ixgbe_flow_ctrl_set(struct rte_eth_dev *dev,
224 : : struct rte_eth_fc_conf *fc_conf);
225 : : static int ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev,
226 : : struct rte_eth_pfc_conf *pfc_conf);
227 : : static int ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
228 : : struct rte_eth_rss_reta_entry64 *reta_conf,
229 : : uint16_t reta_size);
230 : : static int ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
231 : : struct rte_eth_rss_reta_entry64 *reta_conf,
232 : : uint16_t reta_size);
233 : : static void ixgbe_dev_link_status_print(struct rte_eth_dev *dev);
234 : : static int ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on);
235 : : static int ixgbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev);
236 : : static int ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
237 : : static int ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev);
238 : : static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev);
239 : : static void ixgbe_dev_interrupt_handler(void *param);
240 : : static void ixgbe_dev_interrupt_delayed_handler(void *param);
241 : : static uint32_t ixgbe_dev_setup_link_thread_handler(void *param);
242 : : static int ixgbe_dev_wait_setup_link_complete(struct rte_eth_dev *dev,
243 : : uint32_t timeout_ms);
244 : :
245 : : static int ixgbe_add_rar(struct rte_eth_dev *dev,
246 : : struct rte_ether_addr *mac_addr,
247 : : uint32_t index, uint32_t pool);
248 : : static void ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index);
249 : : static int ixgbe_set_default_mac_addr(struct rte_eth_dev *dev,
250 : : struct rte_ether_addr *mac_addr);
251 : : static void ixgbe_dcb_init(struct ixgbe_hw *hw, struct ixgbe_dcb_config *dcb_config);
252 : : static bool is_device_supported(struct rte_eth_dev *dev,
253 : : struct rte_pci_driver *drv);
254 : :
255 : : /* For Virtual Function support */
256 : : static int eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev);
257 : : static int eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev);
258 : : static int ixgbevf_dev_configure(struct rte_eth_dev *dev);
259 : : static int ixgbevf_dev_start(struct rte_eth_dev *dev);
260 : : static int ixgbevf_dev_link_update(struct rte_eth_dev *dev,
261 : : int wait_to_complete);
262 : : static int ixgbevf_dev_stop(struct rte_eth_dev *dev);
263 : : static int ixgbevf_dev_close(struct rte_eth_dev *dev);
264 : : static int ixgbevf_dev_reset(struct rte_eth_dev *dev);
265 : : static void ixgbevf_intr_disable(struct rte_eth_dev *dev);
266 : : static void ixgbevf_intr_enable(struct rte_eth_dev *dev);
267 : : static int ixgbevf_dev_stats_get(struct rte_eth_dev *dev,
268 : : struct rte_eth_stats *stats);
269 : : static int ixgbevf_dev_stats_reset(struct rte_eth_dev *dev);
270 : : static int ixgbevf_vlan_filter_set(struct rte_eth_dev *dev,
271 : : uint16_t vlan_id, int on);
272 : : static void ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev,
273 : : uint16_t queue, int on);
274 : : static int ixgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
275 : : static int ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
276 : : static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
277 : : static int ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
278 : : uint16_t queue_id);
279 : : static int ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
280 : : uint16_t queue_id);
281 : : static void ixgbevf_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
282 : : uint8_t queue, uint8_t msix_vector);
283 : : static void ixgbevf_configure_msix(struct rte_eth_dev *dev);
284 : : static int ixgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev);
285 : : static int ixgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev);
286 : : static int ixgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev);
287 : : static int ixgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev);
288 : :
289 : : /* For Eth VMDQ APIs support */
290 : : static int ixgbe_uc_hash_table_set(struct rte_eth_dev *dev, struct
291 : : rte_ether_addr * mac_addr, uint8_t on);
292 : : static int ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on);
293 : : static int ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
294 : : uint16_t queue_id);
295 : : static int ixgbe_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
296 : : uint16_t queue_id);
297 : : static void ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
298 : : uint8_t queue, uint8_t msix_vector);
299 : : static void ixgbe_configure_msix(struct rte_eth_dev *dev);
300 : :
301 : : static int ixgbevf_add_mac_addr(struct rte_eth_dev *dev,
302 : : struct rte_ether_addr *mac_addr,
303 : : uint32_t index, uint32_t pool);
304 : : static void ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
305 : : static int ixgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
306 : : struct rte_ether_addr *mac_addr);
307 : : static int ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
308 : : struct ixgbe_5tuple_filter *filter);
309 : : static void ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
310 : : struct ixgbe_5tuple_filter *filter);
311 : : static int ixgbe_dev_flow_ops_get(struct rte_eth_dev *dev,
312 : : const struct rte_flow_ops **ops);
313 : : static int ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
314 : :
315 : : static int ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
316 : : struct rte_ether_addr *mc_addr_set,
317 : : uint32_t nb_mc_addr);
318 : : static int ixgbe_dev_get_dcb_info(struct rte_eth_dev *dev,
319 : : struct rte_eth_dcb_info *dcb_info);
320 : :
321 : : static int ixgbe_get_reg_length(struct rte_eth_dev *dev);
322 : : static int ixgbe_get_regs(struct rte_eth_dev *dev,
323 : : struct rte_dev_reg_info *regs);
324 : : static int ixgbe_get_eeprom_length(struct rte_eth_dev *dev);
325 : : static int ixgbe_get_eeprom(struct rte_eth_dev *dev,
326 : : struct rte_dev_eeprom_info *eeprom);
327 : : static int ixgbe_set_eeprom(struct rte_eth_dev *dev,
328 : : struct rte_dev_eeprom_info *eeprom);
329 : :
330 : : static int ixgbe_get_module_info(struct rte_eth_dev *dev,
331 : : struct rte_eth_dev_module_info *modinfo);
332 : : static int ixgbe_get_module_eeprom(struct rte_eth_dev *dev,
333 : : struct rte_dev_eeprom_info *info);
334 : :
335 : : static int ixgbevf_get_reg_length(struct rte_eth_dev *dev);
336 : : static int ixgbevf_get_regs(struct rte_eth_dev *dev,
337 : : struct rte_dev_reg_info *regs);
338 : :
339 : : static int ixgbe_timesync_enable(struct rte_eth_dev *dev);
340 : : static int ixgbe_timesync_disable(struct rte_eth_dev *dev);
341 : : static int ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
342 : : struct timespec *timestamp,
343 : : uint32_t flags);
344 : : static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
345 : : struct timespec *timestamp);
346 : : static int ixgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
347 : : static int ixgbe_timesync_read_time(struct rte_eth_dev *dev,
348 : : struct timespec *timestamp);
349 : : static int ixgbe_timesync_write_time(struct rte_eth_dev *dev,
350 : : const struct timespec *timestamp);
351 : : static void ixgbevf_dev_interrupt_handler(void *param);
352 : :
353 : : static int ixgbe_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
354 : : struct rte_eth_udp_tunnel *udp_tunnel);
355 : : static int ixgbe_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
356 : : struct rte_eth_udp_tunnel *udp_tunnel);
357 : : static int ixgbe_filter_restore(struct rte_eth_dev *dev);
358 : : static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev);
359 : : static int ixgbe_wait_for_link_up(struct ixgbe_hw *hw);
360 : : static int devarg_handle_int(__rte_unused const char *key, const char *value,
361 : : void *extra_args);
362 : :
363 : : /*
364 : : * Define VF Stats MACRO for Non "cleared on read" register
365 : : */
366 : : #define UPDATE_VF_STAT(reg, last, cur) \
367 : : { \
368 : : uint32_t latest = IXGBE_READ_REG(hw, reg); \
369 : : cur += (latest - last) & UINT_MAX; \
370 : : last = latest; \
371 : : }
372 : :
373 : : #define UPDATE_VF_STAT_36BIT(lsb, msb, last, cur) \
374 : : { \
375 : : u64 new_lsb = IXGBE_READ_REG(hw, lsb); \
376 : : u64 new_msb = IXGBE_READ_REG(hw, msb); \
377 : : u64 latest = ((new_msb << 32) | new_lsb); \
378 : : cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \
379 : : last = latest; \
380 : : }
381 : :
382 : : #define IXGBE_SET_HWSTRIP(h, q) do {\
383 : : uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
384 : : uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
385 : : (h)->bitmap[idx] |= 1 << bit;\
386 : : } while (0)
387 : :
388 : : #define IXGBE_CLEAR_HWSTRIP(h, q) do {\
389 : : uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
390 : : uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
391 : : (h)->bitmap[idx] &= ~(1 << bit);\
392 : : } while (0)
393 : :
394 : : #define IXGBE_GET_HWSTRIP(h, q, r) do {\
395 : : uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
396 : : uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
397 : : (r) = (h)->bitmap[idx] >> bit & 1;\
398 : : } while (0)
399 : :
400 : : /*
401 : : * The set of PCI devices this driver supports
402 : : */
403 : : static const struct rte_pci_id pci_id_ixgbe_map[] = {
404 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598) },
405 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_BX) },
406 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_DUAL_PORT) },
407 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_SINGLE_PORT) },
408 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT) },
409 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT2) },
410 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_SFP_LOM) },
411 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_CX4) },
412 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_CX4_DUAL_PORT) },
413 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_DA_DUAL_PORT) },
414 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) },
415 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_XF_LR) },
416 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4) },
417 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4_MEZZ) },
418 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KR) },
419 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_COMBO_BACKPLANE) },
420 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_CX4) },
421 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP) },
422 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BACKPLANE_FCOE) },
423 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_FCOE) },
424 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_EM) },
425 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF2) },
426 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF_QP) },
427 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_QSFP_SF_QP) },
428 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599EN_SFP) },
429 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_XAUI_LOM) },
430 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_T3_LOM) },
431 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_LS) },
432 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T) },
433 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T1) },
434 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_SFP) },
435 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_10G_T) },
436 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_1G_T) },
437 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550T) },
438 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550T1) },
439 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_KR) },
440 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_KR_L) },
441 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SFP_N) },
442 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SGMII) },
443 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SGMII_L) },
444 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_10G_T) },
445 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_QSFP) },
446 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_QSFP_N) },
447 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SFP) },
448 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_1G_T) },
449 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_1G_T_L) },
450 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_KX4) },
451 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_KR) },
452 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_XFI) },
453 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_10G_T) },
454 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_2_5G_T) },
455 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_BACKPLANE) },
456 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_SFP) },
457 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_SGMII) },
458 : : #ifdef RTE_LIBRTE_IXGBE_BYPASS
459 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BYPASS) },
460 : : #endif
461 : : { .vendor_id = 0, /* sentinel */ },
462 : : };
463 : :
464 : : /*
465 : : * The set of PCI devices this driver supports (for 82599 VF)
466 : : */
467 : : static const struct rte_pci_id pci_id_ixgbevf_map[] = {
468 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF) },
469 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF_HV) },
470 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF) },
471 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF_HV) },
472 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550_VF_HV) },
473 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550_VF) },
474 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_VF) },
475 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_VF_HV) },
476 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_VF) },
477 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_VF_HV) },
478 : : { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_VF) },
479 : : { .vendor_id = 0, /* sentinel */ },
480 : : };
481 : :
482 : : static const struct rte_eth_desc_lim rx_desc_lim = {
483 : : .nb_max = IXGBE_MAX_RING_DESC,
484 : : .nb_min = IXGBE_MIN_RING_DESC,
485 : : .nb_align = IXGBE_RXD_ALIGN,
486 : : };
487 : :
488 : : static const struct rte_eth_desc_lim tx_desc_lim = {
489 : : .nb_max = IXGBE_MAX_RING_DESC,
490 : : .nb_min = IXGBE_MIN_RING_DESC,
491 : : .nb_align = IXGBE_TXD_ALIGN,
492 : : .nb_seg_max = IXGBE_TX_MAX_SEG,
493 : : .nb_mtu_seg_max = IXGBE_TX_MAX_SEG,
494 : : };
495 : :
496 : : static const struct eth_dev_ops ixgbe_eth_dev_ops = {
497 : : .dev_configure = ixgbe_dev_configure,
498 : : .dev_start = ixgbe_dev_start,
499 : : .dev_stop = ixgbe_dev_stop,
500 : : .dev_set_link_up = ixgbe_dev_set_link_up,
501 : : .dev_set_link_down = ixgbe_dev_set_link_down,
502 : : .dev_close = ixgbe_dev_close,
503 : : .dev_reset = ixgbe_dev_reset,
504 : : .promiscuous_enable = ixgbe_dev_promiscuous_enable,
505 : : .promiscuous_disable = ixgbe_dev_promiscuous_disable,
506 : : .allmulticast_enable = ixgbe_dev_allmulticast_enable,
507 : : .allmulticast_disable = ixgbe_dev_allmulticast_disable,
508 : : .link_update = ixgbe_dev_link_update,
509 : : .stats_get = ixgbe_dev_stats_get,
510 : : .xstats_get = ixgbe_dev_xstats_get,
511 : : .xstats_get_by_id = ixgbe_dev_xstats_get_by_id,
512 : : .stats_reset = ixgbe_dev_stats_reset,
513 : : .xstats_reset = ixgbe_dev_xstats_reset,
514 : : .xstats_get_names = ixgbe_dev_xstats_get_names,
515 : : .xstats_get_names_by_id = ixgbe_dev_xstats_get_names_by_id,
516 : : .queue_stats_mapping_set = ixgbe_dev_queue_stats_mapping_set,
517 : : .fw_version_get = ixgbe_fw_version_get,
518 : : .dev_infos_get = ixgbe_dev_info_get,
519 : : .dev_supported_ptypes_get = ixgbe_dev_supported_ptypes_get,
520 : : .mtu_set = ixgbe_dev_mtu_set,
521 : : .vlan_filter_set = ixgbe_vlan_filter_set,
522 : : .vlan_tpid_set = ixgbe_vlan_tpid_set,
523 : : .vlan_offload_set = ixgbe_vlan_offload_set,
524 : : .vlan_strip_queue_set = ixgbe_vlan_strip_queue_set,
525 : : .rx_queue_start = ixgbe_dev_rx_queue_start,
526 : : .rx_queue_stop = ixgbe_dev_rx_queue_stop,
527 : : .tx_queue_start = ixgbe_dev_tx_queue_start,
528 : : .tx_queue_stop = ixgbe_dev_tx_queue_stop,
529 : : .rx_queue_setup = ixgbe_dev_rx_queue_setup,
530 : : .rx_queue_intr_enable = ixgbe_dev_rx_queue_intr_enable,
531 : : .rx_queue_intr_disable = ixgbe_dev_rx_queue_intr_disable,
532 : : .rx_queue_release = ixgbe_dev_rx_queue_release,
533 : : .tx_queue_setup = ixgbe_dev_tx_queue_setup,
534 : : .tx_queue_release = ixgbe_dev_tx_queue_release,
535 : : .rx_burst_mode_get = ixgbe_rx_burst_mode_get,
536 : : .tx_burst_mode_get = ixgbe_tx_burst_mode_get,
537 : : .dev_led_on = ixgbe_dev_led_on,
538 : : .dev_led_off = ixgbe_dev_led_off,
539 : : .flow_ctrl_get = ixgbe_flow_ctrl_get,
540 : : .flow_ctrl_set = ixgbe_flow_ctrl_set,
541 : : .priority_flow_ctrl_set = ixgbe_priority_flow_ctrl_set,
542 : : .mac_addr_add = ixgbe_add_rar,
543 : : .mac_addr_remove = ixgbe_remove_rar,
544 : : .mac_addr_set = ixgbe_set_default_mac_addr,
545 : : .uc_hash_table_set = ixgbe_uc_hash_table_set,
546 : : .uc_all_hash_table_set = ixgbe_uc_all_hash_table_set,
547 : : .set_queue_rate_limit = ixgbe_set_queue_rate_limit,
548 : : .reta_update = ixgbe_dev_rss_reta_update,
549 : : .reta_query = ixgbe_dev_rss_reta_query,
550 : : .rss_hash_update = ixgbe_dev_rss_hash_update,
551 : : .rss_hash_conf_get = ixgbe_dev_rss_hash_conf_get,
552 : : .flow_ops_get = ixgbe_dev_flow_ops_get,
553 : : .set_mc_addr_list = ixgbe_dev_set_mc_addr_list,
554 : : .rxq_info_get = ixgbe_rxq_info_get,
555 : : .txq_info_get = ixgbe_txq_info_get,
556 : : .recycle_rxq_info_get = ixgbe_recycle_rxq_info_get,
557 : : .timesync_enable = ixgbe_timesync_enable,
558 : : .timesync_disable = ixgbe_timesync_disable,
559 : : .timesync_read_rx_timestamp = ixgbe_timesync_read_rx_timestamp,
560 : : .timesync_read_tx_timestamp = ixgbe_timesync_read_tx_timestamp,
561 : : .get_reg = ixgbe_get_regs,
562 : : .get_eeprom_length = ixgbe_get_eeprom_length,
563 : : .get_eeprom = ixgbe_get_eeprom,
564 : : .set_eeprom = ixgbe_set_eeprom,
565 : : .get_module_info = ixgbe_get_module_info,
566 : : .get_module_eeprom = ixgbe_get_module_eeprom,
567 : : .get_dcb_info = ixgbe_dev_get_dcb_info,
568 : : .timesync_adjust_time = ixgbe_timesync_adjust_time,
569 : : .timesync_read_time = ixgbe_timesync_read_time,
570 : : .timesync_write_time = ixgbe_timesync_write_time,
571 : : .udp_tunnel_port_add = ixgbe_dev_udp_tunnel_port_add,
572 : : .udp_tunnel_port_del = ixgbe_dev_udp_tunnel_port_del,
573 : : .tm_ops_get = ixgbe_tm_ops_get,
574 : : .tx_done_cleanup = ixgbe_dev_tx_done_cleanup,
575 : : .get_monitor_addr = ixgbe_get_monitor_addr,
576 : : };
577 : :
578 : : /*
579 : : * dev_ops for virtual function, bare necessities for basic vf
580 : : * operation have been implemented
581 : : */
582 : : static const struct eth_dev_ops ixgbevf_eth_dev_ops = {
583 : : .dev_configure = ixgbevf_dev_configure,
584 : : .dev_start = ixgbevf_dev_start,
585 : : .dev_stop = ixgbevf_dev_stop,
586 : : .link_update = ixgbevf_dev_link_update,
587 : : .stats_get = ixgbevf_dev_stats_get,
588 : : .xstats_get = ixgbevf_dev_xstats_get,
589 : : .stats_reset = ixgbevf_dev_stats_reset,
590 : : .xstats_reset = ixgbevf_dev_stats_reset,
591 : : .xstats_get_names = ixgbevf_dev_xstats_get_names,
592 : : .dev_close = ixgbevf_dev_close,
593 : : .dev_reset = ixgbevf_dev_reset,
594 : : .promiscuous_enable = ixgbevf_dev_promiscuous_enable,
595 : : .promiscuous_disable = ixgbevf_dev_promiscuous_disable,
596 : : .allmulticast_enable = ixgbevf_dev_allmulticast_enable,
597 : : .allmulticast_disable = ixgbevf_dev_allmulticast_disable,
598 : : .dev_infos_get = ixgbevf_dev_info_get,
599 : : .dev_supported_ptypes_get = ixgbe_dev_supported_ptypes_get,
600 : : .mtu_set = ixgbevf_dev_set_mtu,
601 : : .vlan_filter_set = ixgbevf_vlan_filter_set,
602 : : .vlan_strip_queue_set = ixgbevf_vlan_strip_queue_set,
603 : : .vlan_offload_set = ixgbevf_vlan_offload_set,
604 : : .rx_queue_setup = ixgbe_dev_rx_queue_setup,
605 : : .rx_queue_release = ixgbe_dev_rx_queue_release,
606 : : .tx_queue_setup = ixgbe_dev_tx_queue_setup,
607 : : .tx_queue_release = ixgbe_dev_tx_queue_release,
608 : : .rx_queue_intr_enable = ixgbevf_dev_rx_queue_intr_enable,
609 : : .rx_queue_intr_disable = ixgbevf_dev_rx_queue_intr_disable,
610 : : .rx_burst_mode_get = ixgbe_rx_burst_mode_get,
611 : : .tx_burst_mode_get = ixgbe_tx_burst_mode_get,
612 : : .mac_addr_add = ixgbevf_add_mac_addr,
613 : : .mac_addr_remove = ixgbevf_remove_mac_addr,
614 : : .set_mc_addr_list = ixgbe_dev_set_mc_addr_list,
615 : : .rxq_info_get = ixgbe_rxq_info_get,
616 : : .txq_info_get = ixgbe_txq_info_get,
617 : : .mac_addr_set = ixgbevf_set_default_mac_addr,
618 : : .get_reg = ixgbevf_get_regs,
619 : : .reta_update = ixgbe_dev_rss_reta_update,
620 : : .reta_query = ixgbe_dev_rss_reta_query,
621 : : .rss_hash_update = ixgbe_dev_rss_hash_update,
622 : : .rss_hash_conf_get = ixgbe_dev_rss_hash_conf_get,
623 : : .tx_done_cleanup = ixgbe_dev_tx_done_cleanup,
624 : : .get_monitor_addr = ixgbe_get_monitor_addr,
625 : : };
626 : :
627 : : /* store statistics names and its offset in stats structure */
628 : : struct rte_ixgbe_xstats_name_off {
629 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
630 : : unsigned offset;
631 : : };
632 : :
633 : : static const struct rte_ixgbe_xstats_name_off rte_ixgbe_stats_strings[] = {
634 : : {"rx_crc_errors", offsetof(struct ixgbe_hw_stats, crcerrs)},
635 : : {"rx_illegal_byte_errors", offsetof(struct ixgbe_hw_stats, illerrc)},
636 : : {"rx_error_bytes", offsetof(struct ixgbe_hw_stats, errbc)},
637 : : {"mac_local_errors", offsetof(struct ixgbe_hw_stats, mlfc)},
638 : : {"mac_remote_errors", offsetof(struct ixgbe_hw_stats, mrfc)},
639 : : {"rx_length_errors", offsetof(struct ixgbe_hw_stats, rlec)},
640 : : {"tx_xon_packets", offsetof(struct ixgbe_hw_stats, lxontxc)},
641 : : {"rx_xon_packets", offsetof(struct ixgbe_hw_stats, lxonrxc)},
642 : : {"tx_xoff_packets", offsetof(struct ixgbe_hw_stats, lxofftxc)},
643 : : {"rx_xoff_packets", offsetof(struct ixgbe_hw_stats, lxoffrxc)},
644 : : {"rx_size_64_packets", offsetof(struct ixgbe_hw_stats, prc64)},
645 : : {"rx_size_65_to_127_packets", offsetof(struct ixgbe_hw_stats, prc127)},
646 : : {"rx_size_128_to_255_packets", offsetof(struct ixgbe_hw_stats, prc255)},
647 : : {"rx_size_256_to_511_packets", offsetof(struct ixgbe_hw_stats, prc511)},
648 : : {"rx_size_512_to_1023_packets", offsetof(struct ixgbe_hw_stats,
649 : : prc1023)},
650 : : {"rx_size_1024_to_max_packets", offsetof(struct ixgbe_hw_stats,
651 : : prc1522)},
652 : : {"rx_broadcast_packets", offsetof(struct ixgbe_hw_stats, bprc)},
653 : : {"rx_multicast_packets", offsetof(struct ixgbe_hw_stats, mprc)},
654 : : {"rx_fragment_errors", offsetof(struct ixgbe_hw_stats, rfc)},
655 : : {"rx_undersize_errors", offsetof(struct ixgbe_hw_stats, ruc)},
656 : : {"rx_oversize_errors", offsetof(struct ixgbe_hw_stats, roc)},
657 : : {"rx_jabber_errors", offsetof(struct ixgbe_hw_stats, rjc)},
658 : : {"rx_management_packets", offsetof(struct ixgbe_hw_stats, mngprc)},
659 : : {"rx_management_dropped", offsetof(struct ixgbe_hw_stats, mngpdc)},
660 : : {"tx_management_packets", offsetof(struct ixgbe_hw_stats, mngptc)},
661 : : {"rx_total_packets", offsetof(struct ixgbe_hw_stats, tpr)},
662 : : {"rx_total_bytes", offsetof(struct ixgbe_hw_stats, tor)},
663 : : {"tx_total_packets", offsetof(struct ixgbe_hw_stats, tpt)},
664 : : {"tx_size_64_packets", offsetof(struct ixgbe_hw_stats, ptc64)},
665 : : {"tx_size_65_to_127_packets", offsetof(struct ixgbe_hw_stats, ptc127)},
666 : : {"tx_size_128_to_255_packets", offsetof(struct ixgbe_hw_stats, ptc255)},
667 : : {"tx_size_256_to_511_packets", offsetof(struct ixgbe_hw_stats, ptc511)},
668 : : {"tx_size_512_to_1023_packets", offsetof(struct ixgbe_hw_stats,
669 : : ptc1023)},
670 : : {"tx_size_1024_to_max_packets", offsetof(struct ixgbe_hw_stats,
671 : : ptc1522)},
672 : : {"tx_multicast_packets", offsetof(struct ixgbe_hw_stats, mptc)},
673 : : {"tx_broadcast_packets", offsetof(struct ixgbe_hw_stats, bptc)},
674 : : {"rx_mac_short_packet_dropped", offsetof(struct ixgbe_hw_stats, mspdc)},
675 : : {"rx_l3_l4_xsum_error", offsetof(struct ixgbe_hw_stats, xec)},
676 : :
677 : : {"flow_director_added_filters", offsetof(struct ixgbe_hw_stats,
678 : : fdirustat_add)},
679 : : {"flow_director_removed_filters", offsetof(struct ixgbe_hw_stats,
680 : : fdirustat_remove)},
681 : : {"flow_director_filter_add_errors", offsetof(struct ixgbe_hw_stats,
682 : : fdirfstat_fadd)},
683 : : {"flow_director_filter_remove_errors", offsetof(struct ixgbe_hw_stats,
684 : : fdirfstat_fremove)},
685 : : {"flow_director_matched_filters", offsetof(struct ixgbe_hw_stats,
686 : : fdirmatch)},
687 : : {"flow_director_missed_filters", offsetof(struct ixgbe_hw_stats,
688 : : fdirmiss)},
689 : :
690 : : {"rx_fcoe_crc_errors", offsetof(struct ixgbe_hw_stats, fccrc)},
691 : : {"rx_fcoe_dropped", offsetof(struct ixgbe_hw_stats, fcoerpdc)},
692 : : {"rx_fcoe_mbuf_allocation_errors", offsetof(struct ixgbe_hw_stats,
693 : : fclast)},
694 : : {"rx_fcoe_packets", offsetof(struct ixgbe_hw_stats, fcoeprc)},
695 : : {"tx_fcoe_packets", offsetof(struct ixgbe_hw_stats, fcoeptc)},
696 : : {"rx_fcoe_bytes", offsetof(struct ixgbe_hw_stats, fcoedwrc)},
697 : : {"tx_fcoe_bytes", offsetof(struct ixgbe_hw_stats, fcoedwtc)},
698 : : {"rx_fcoe_no_direct_data_placement", offsetof(struct ixgbe_hw_stats,
699 : : fcoe_noddp)},
700 : : {"rx_fcoe_no_direct_data_placement_ext_buff",
701 : : offsetof(struct ixgbe_hw_stats, fcoe_noddp_ext_buff)},
702 : :
703 : : {"tx_flow_control_xon_packets", offsetof(struct ixgbe_hw_stats,
704 : : lxontxc)},
705 : : {"rx_flow_control_xon_packets", offsetof(struct ixgbe_hw_stats,
706 : : lxonrxc)},
707 : : {"tx_flow_control_xoff_packets", offsetof(struct ixgbe_hw_stats,
708 : : lxofftxc)},
709 : : {"rx_flow_control_xoff_packets", offsetof(struct ixgbe_hw_stats,
710 : : lxoffrxc)},
711 : : {"rx_total_missed_packets", offsetof(struct ixgbe_hw_stats, mpctotal)},
712 : : };
713 : :
714 : : #define IXGBE_NB_HW_STATS (sizeof(rte_ixgbe_stats_strings) / \
715 : : sizeof(rte_ixgbe_stats_strings[0]))
716 : :
717 : : /* MACsec statistics */
718 : : static const struct rte_ixgbe_xstats_name_off rte_ixgbe_macsec_strings[] = {
719 : : {"out_pkts_untagged", offsetof(struct ixgbe_macsec_stats,
720 : : out_pkts_untagged)},
721 : : {"out_pkts_encrypted", offsetof(struct ixgbe_macsec_stats,
722 : : out_pkts_encrypted)},
723 : : {"out_pkts_protected", offsetof(struct ixgbe_macsec_stats,
724 : : out_pkts_protected)},
725 : : {"out_octets_encrypted", offsetof(struct ixgbe_macsec_stats,
726 : : out_octets_encrypted)},
727 : : {"out_octets_protected", offsetof(struct ixgbe_macsec_stats,
728 : : out_octets_protected)},
729 : : {"in_pkts_untagged", offsetof(struct ixgbe_macsec_stats,
730 : : in_pkts_untagged)},
731 : : {"in_pkts_badtag", offsetof(struct ixgbe_macsec_stats,
732 : : in_pkts_badtag)},
733 : : {"in_pkts_nosci", offsetof(struct ixgbe_macsec_stats,
734 : : in_pkts_nosci)},
735 : : {"in_pkts_unknownsci", offsetof(struct ixgbe_macsec_stats,
736 : : in_pkts_unknownsci)},
737 : : {"in_octets_decrypted", offsetof(struct ixgbe_macsec_stats,
738 : : in_octets_decrypted)},
739 : : {"in_octets_validated", offsetof(struct ixgbe_macsec_stats,
740 : : in_octets_validated)},
741 : : {"in_pkts_unchecked", offsetof(struct ixgbe_macsec_stats,
742 : : in_pkts_unchecked)},
743 : : {"in_pkts_delayed", offsetof(struct ixgbe_macsec_stats,
744 : : in_pkts_delayed)},
745 : : {"in_pkts_late", offsetof(struct ixgbe_macsec_stats,
746 : : in_pkts_late)},
747 : : {"in_pkts_ok", offsetof(struct ixgbe_macsec_stats,
748 : : in_pkts_ok)},
749 : : {"in_pkts_invalid", offsetof(struct ixgbe_macsec_stats,
750 : : in_pkts_invalid)},
751 : : {"in_pkts_notvalid", offsetof(struct ixgbe_macsec_stats,
752 : : in_pkts_notvalid)},
753 : : {"in_pkts_unusedsa", offsetof(struct ixgbe_macsec_stats,
754 : : in_pkts_unusedsa)},
755 : : {"in_pkts_notusingsa", offsetof(struct ixgbe_macsec_stats,
756 : : in_pkts_notusingsa)},
757 : : };
758 : :
759 : : #define IXGBE_NB_MACSEC_STATS (sizeof(rte_ixgbe_macsec_strings) / \
760 : : sizeof(rte_ixgbe_macsec_strings[0]))
761 : :
762 : : /* Per-queue statistics */
763 : : static const struct rte_ixgbe_xstats_name_off rte_ixgbe_rxq_strings[] = {
764 : : {"mbuf_allocation_errors", offsetof(struct ixgbe_hw_stats, rnbc)},
765 : : {"dropped", offsetof(struct ixgbe_hw_stats, mpc)},
766 : : {"xon_packets", offsetof(struct ixgbe_hw_stats, pxonrxc)},
767 : : {"xoff_packets", offsetof(struct ixgbe_hw_stats, pxoffrxc)},
768 : : };
769 : :
770 : : #define IXGBE_NB_RXQ_PRIO_STATS (sizeof(rte_ixgbe_rxq_strings) / \
771 : : sizeof(rte_ixgbe_rxq_strings[0]))
772 : : #define IXGBE_NB_RXQ_PRIO_VALUES 8
773 : :
774 : : static const struct rte_ixgbe_xstats_name_off rte_ixgbe_txq_strings[] = {
775 : : {"xon_packets", offsetof(struct ixgbe_hw_stats, pxontxc)},
776 : : {"xoff_packets", offsetof(struct ixgbe_hw_stats, pxofftxc)},
777 : : {"xon_to_xoff_packets", offsetof(struct ixgbe_hw_stats,
778 : : pxon2offc)},
779 : : };
780 : :
781 : : #define IXGBE_NB_TXQ_PRIO_STATS (sizeof(rte_ixgbe_txq_strings) / \
782 : : sizeof(rte_ixgbe_txq_strings[0]))
783 : : #define IXGBE_NB_TXQ_PRIO_VALUES 8
784 : :
785 : : static const struct rte_ixgbe_xstats_name_off rte_ixgbevf_stats_strings[] = {
786 : : {"rx_multicast_packets", offsetof(struct ixgbevf_hw_stats, vfmprc)},
787 : : };
788 : :
789 : : #define IXGBEVF_NB_XSTATS (sizeof(rte_ixgbevf_stats_strings) / \
790 : : sizeof(rte_ixgbevf_stats_strings[0]))
791 : :
792 : : /*
793 : : * This function is the same as ixgbe_is_sfp() in base/ixgbe.h.
794 : : */
795 : : static inline int
796 : 0 : ixgbe_is_sfp(struct ixgbe_hw *hw)
797 : : {
798 [ # # ]: 0 : switch (hw->phy.type) {
799 : : case ixgbe_phy_sfp_avago:
800 : : case ixgbe_phy_sfp_ftl:
801 : : case ixgbe_phy_sfp_intel:
802 : : case ixgbe_phy_sfp_unknown:
803 : : case ixgbe_phy_sfp_passive_tyco:
804 : : case ixgbe_phy_sfp_passive_unknown:
805 : : return 1;
806 : 0 : default:
807 : : /* x550em devices may be SFP, check media type */
808 [ # # ]: 0 : switch (hw->mac.type) {
809 : 0 : case ixgbe_mac_X550EM_x:
810 : : case ixgbe_mac_X550EM_a:
811 : 0 : switch (ixgbe_get_media_type(hw)) {
812 : : case ixgbe_media_type_fiber:
813 : : case ixgbe_media_type_fiber_qsfp:
814 : : return 1;
815 : : default:
816 : : break;
817 : : }
818 : : default:
819 : : break;
820 : : }
821 : : return 0;
822 : : }
823 : : }
824 : :
825 : : static inline int32_t
826 : 0 : ixgbe_pf_reset_hw(struct ixgbe_hw *hw)
827 : : {
828 : : uint32_t ctrl_ext;
829 : : int32_t status;
830 : :
831 : 0 : status = ixgbe_reset_hw(hw);
832 : :
833 : 0 : ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
834 : : /* Set PF Reset Done bit so PF/VF Mail Ops can work */
835 : 0 : ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
836 : 0 : IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
837 : 0 : IXGBE_WRITE_FLUSH(hw);
838 : :
839 [ # # ]: 0 : if (status == IXGBE_ERR_SFP_NOT_PRESENT)
840 : : status = IXGBE_SUCCESS;
841 : 0 : return status;
842 : : }
843 : :
844 : : static inline void
845 : : ixgbe_enable_intr(struct rte_eth_dev *dev)
846 : : {
847 : : struct ixgbe_interrupt *intr =
848 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
849 : : struct ixgbe_hw *hw =
850 : : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
851 : :
852 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIMS, intr->mask);
853 : 0 : IXGBE_WRITE_FLUSH(hw);
854 : 0 : }
855 : :
856 : : /*
857 : : * This function is based on ixgbe_disable_intr() in base/ixgbe.h.
858 : : */
859 : : static void
860 : 0 : ixgbe_disable_intr(struct ixgbe_hw *hw)
861 : : {
862 : 0 : PMD_INIT_FUNC_TRACE();
863 : :
864 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB) {
865 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIMC, ~0);
866 : : } else {
867 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIMC, 0xFFFF0000);
868 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), ~0);
869 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), ~0);
870 : : }
871 : 0 : IXGBE_WRITE_FLUSH(hw);
872 : 0 : }
873 : :
874 : : /*
875 : : * This function resets queue statistics mapping registers.
876 : : * From Niantic datasheet, Initialization of Statistics section:
877 : : * "...if software requires the queue counters, the RQSMR and TQSM registers
878 : : * must be re-programmed following a device reset.
879 : : */
880 : : static void
881 : : ixgbe_reset_qstat_mappings(struct ixgbe_hw *hw)
882 : : {
883 : : uint32_t i;
884 : :
885 [ # # ]: 0 : for (i = 0; i != IXGBE_NB_STAT_MAPPING_REGS; i++) {
886 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), 0);
887 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), 0);
888 : : }
889 : : }
890 : :
891 : :
892 : : static int
893 : 0 : ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
894 : : uint16_t queue_id,
895 : : uint8_t stat_idx,
896 : : uint8_t is_rx)
897 : : {
898 : : #define QSM_REG_NB_BITS_PER_QMAP_FIELD 8
899 : : #define NB_QMAP_FIELDS_PER_QSM_REG 4
900 : : #define QMAP_FIELD_RESERVED_BITS_MASK 0x0f
901 : :
902 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
903 : : struct ixgbe_stat_mapping_registers *stat_mappings =
904 : : IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(eth_dev->data->dev_private);
905 : : uint32_t qsmr_mask = 0;
906 : : uint32_t clearing_mask = QMAP_FIELD_RESERVED_BITS_MASK;
907 : : uint32_t q_map;
908 : : uint8_t n, offset;
909 : :
910 [ # # ]: 0 : if ((hw->mac.type != ixgbe_mac_82599EB) &&
911 [ # # ]: 0 : (hw->mac.type != ixgbe_mac_X540) &&
912 [ # # ]: 0 : (hw->mac.type != ixgbe_mac_X550) &&
913 [ # # ]: 0 : (hw->mac.type != ixgbe_mac_X550EM_x) &&
914 : : (hw->mac.type != ixgbe_mac_X550EM_a))
915 : : return -ENOSYS;
916 : :
917 [ # # ]: 0 : PMD_INIT_LOG(DEBUG, "Setting port %d, %s queue_id %d to stat index %d",
918 : : (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
919 : : queue_id, stat_idx);
920 : :
921 : 0 : n = (uint8_t)(queue_id / NB_QMAP_FIELDS_PER_QSM_REG);
922 [ # # ]: 0 : if (n >= IXGBE_NB_STAT_MAPPING_REGS) {
923 : 0 : PMD_INIT_LOG(ERR, "Nb of stat mapping registers exceeded");
924 : 0 : return -EIO;
925 : : }
926 : 0 : offset = (uint8_t)(queue_id % NB_QMAP_FIELDS_PER_QSM_REG);
927 : :
928 : : /* Now clear any previous stat_idx set */
929 : 0 : clearing_mask <<= (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
930 [ # # ]: 0 : if (!is_rx)
931 : 0 : stat_mappings->tqsm[n] &= ~clearing_mask;
932 : : else
933 : 0 : stat_mappings->rqsmr[n] &= ~clearing_mask;
934 : :
935 : : q_map = (uint32_t)stat_idx;
936 : 0 : q_map &= QMAP_FIELD_RESERVED_BITS_MASK;
937 : 0 : qsmr_mask = q_map << (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
938 [ # # ]: 0 : if (!is_rx)
939 : 0 : stat_mappings->tqsm[n] |= qsmr_mask;
940 : : else
941 : 0 : stat_mappings->rqsmr[n] |= qsmr_mask;
942 : :
943 : 0 : PMD_INIT_LOG(DEBUG, "Set port %d, %s queue_id %d to stat index %d",
944 : : (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
945 : : queue_id, stat_idx);
946 [ # # # # ]: 0 : PMD_INIT_LOG(DEBUG, "%s[%d] = 0x%08x", is_rx ? "RQSMR" : "TQSM", n,
947 : : is_rx ? stat_mappings->rqsmr[n] : stat_mappings->tqsm[n]);
948 : :
949 : : /* Now write the mapping in the appropriate register */
950 [ # # ]: 0 : if (is_rx) {
951 : 0 : PMD_INIT_LOG(DEBUG, "Write 0x%x to RX IXGBE stat mapping reg:%d",
952 : : stat_mappings->rqsmr[n], n);
953 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RQSMR(n), stat_mappings->rqsmr[n]);
954 : : } else {
955 : 0 : PMD_INIT_LOG(DEBUG, "Write 0x%x to TX IXGBE stat mapping reg:%d",
956 : : stat_mappings->tqsm[n], n);
957 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TQSM(n), stat_mappings->tqsm[n]);
958 : : }
959 : : return 0;
960 : : }
961 : :
962 : : static void
963 : 0 : ixgbe_restore_statistics_mapping(struct rte_eth_dev *dev)
964 : : {
965 : : struct ixgbe_stat_mapping_registers *stat_mappings =
966 : 0 : IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(dev->data->dev_private);
967 : : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
968 : : int i;
969 : :
970 : : /* write whatever was in stat mapping table to the NIC */
971 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_STAT_MAPPING_REGS; i++) {
972 : : /* rx */
973 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), stat_mappings->rqsmr[i]);
974 : :
975 : : /* tx */
976 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), stat_mappings->tqsm[i]);
977 : : }
978 : 0 : }
979 : :
980 : : static void
981 : 0 : ixgbe_dcb_init(struct ixgbe_hw *hw, struct ixgbe_dcb_config *dcb_config)
982 : : {
983 : : uint8_t i;
984 : : struct ixgbe_dcb_tc_config *tc;
985 : : uint8_t dcb_max_tc = IXGBE_DCB_MAX_TRAFFIC_CLASS;
986 : :
987 : 0 : dcb_config->num_tcs.pg_tcs = dcb_max_tc;
988 : 0 : dcb_config->num_tcs.pfc_tcs = dcb_max_tc;
989 [ # # ]: 0 : for (i = 0; i < dcb_max_tc; i++) {
990 : 0 : tc = &dcb_config->tc_config[i];
991 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_id = i;
992 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
993 : 0 : (uint8_t)(100/dcb_max_tc + (i & 1));
994 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_id = i;
995 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
996 : : (uint8_t)(100/dcb_max_tc + (i & 1));
997 : 0 : tc->pfc = ixgbe_dcb_pfc_disabled;
998 : : }
999 : :
1000 : : /* Initialize default user to priority mapping, UPx->TC0 */
1001 : : tc = &dcb_config->tc_config[0];
1002 : 0 : tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
1003 : 0 : tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
1004 [ # # ]: 0 : for (i = 0; i < IXGBE_DCB_MAX_BW_GROUP; i++) {
1005 : 0 : dcb_config->bw_percentage[IXGBE_DCB_TX_CONFIG][i] = 100;
1006 : 0 : dcb_config->bw_percentage[IXGBE_DCB_RX_CONFIG][i] = 100;
1007 : : }
1008 : 0 : dcb_config->rx_pba_cfg = ixgbe_dcb_pba_equal;
1009 : 0 : dcb_config->pfc_mode_enable = false;
1010 : 0 : dcb_config->vt_mode = true;
1011 : 0 : dcb_config->round_robin_enable = false;
1012 : : /* support all DCB capabilities in 82599 */
1013 : 0 : dcb_config->support.capabilities = 0xFF;
1014 : :
1015 : : /*we only support 4 Tcs for X540, X550 */
1016 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_X540 ||
1017 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
1018 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
1019 : : hw->mac.type == ixgbe_mac_X550EM_a) {
1020 : 0 : dcb_config->num_tcs.pg_tcs = 4;
1021 : 0 : dcb_config->num_tcs.pfc_tcs = 4;
1022 : : }
1023 : 0 : }
1024 : :
1025 : : /*
1026 : : * Ensure that all locks are released before first NVM or PHY access
1027 : : */
1028 : : static void
1029 : 0 : ixgbe_swfw_lock_reset(struct ixgbe_hw *hw)
1030 : : {
1031 : : uint16_t mask;
1032 : :
1033 : : /*
1034 : : * Phy lock should not fail in this early stage. If this is the case,
1035 : : * it is due to an improper exit of the application.
1036 : : * So force the release of the faulty lock. Release of common lock
1037 : : * is done automatically by swfw_sync function.
1038 : : */
1039 : 0 : mask = IXGBE_GSSR_PHY0_SM << hw->bus.func;
1040 [ # # ]: 0 : if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
1041 : 0 : PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released", hw->bus.func);
1042 : : }
1043 : 0 : ixgbe_release_swfw_semaphore(hw, mask);
1044 : :
1045 : : /*
1046 : : * These ones are more tricky since they are common to all ports; but
1047 : : * swfw_sync retries last long enough (1s) to be almost sure that if
1048 : : * lock can not be taken it is due to an improper lock of the
1049 : : * semaphore.
1050 : : */
1051 : : mask = IXGBE_GSSR_EEP_SM | IXGBE_GSSR_MAC_CSR_SM | IXGBE_GSSR_SW_MNG_SM;
1052 [ # # ]: 0 : if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
1053 : 0 : PMD_DRV_LOG(DEBUG, "SWFW common locks released");
1054 : : }
1055 : 0 : ixgbe_release_swfw_semaphore(hw, mask);
1056 : 0 : }
1057 : :
1058 : : static void
1059 : 0 : ixgbe_parse_devargs(struct ixgbe_adapter *adapter,
1060 : : struct rte_devargs *devargs)
1061 : : {
1062 : : struct rte_kvargs *kvlist;
1063 : : uint16_t sdp3_no_tx_disable;
1064 : :
1065 [ # # ]: 0 : if (devargs == NULL)
1066 : 0 : return;
1067 : :
1068 : 0 : kvlist = rte_kvargs_parse(devargs->args, ixgbe_valid_arguments);
1069 [ # # ]: 0 : if (kvlist == NULL)
1070 : : return;
1071 : :
1072 [ # # # # ]: 0 : if (rte_kvargs_count(kvlist, IXGBE_DEVARG_FIBER_SDP3_NOT_TX_DISABLE) == 1 &&
1073 : 0 : rte_kvargs_process(kvlist, IXGBE_DEVARG_FIBER_SDP3_NOT_TX_DISABLE,
1074 : 0 : devarg_handle_int, &sdp3_no_tx_disable) == 0 &&
1075 [ # # ]: 0 : sdp3_no_tx_disable == 1)
1076 : 0 : adapter->sdp3_no_tx_disable = 1;
1077 : :
1078 : 0 : rte_kvargs_free(kvlist);
1079 : : }
1080 : :
1081 : : /*
1082 : : * This function is based on code in ixgbe_attach() in base/ixgbe.c.
1083 : : * It returns 0 on success.
1084 : : */
1085 : : static int
1086 : 0 : eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
1087 : : {
1088 : 0 : struct ixgbe_adapter *ad = eth_dev->data->dev_private;
1089 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1090 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1091 : 0 : struct ixgbe_hw *hw =
1092 : : IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1093 : 0 : struct ixgbe_vfta *shadow_vfta =
1094 : : IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
1095 : 0 : struct ixgbe_hwstrip *hwstrip =
1096 : : IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
1097 : 0 : struct ixgbe_dcb_config *dcb_config =
1098 : : IXGBE_DEV_PRIVATE_TO_DCB_CFG(eth_dev->data->dev_private);
1099 : 0 : struct ixgbe_filter_info *filter_info =
1100 : : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
1101 : 0 : struct ixgbe_bw_conf *bw_conf =
1102 : : IXGBE_DEV_PRIVATE_TO_BW_CONF(eth_dev->data->dev_private);
1103 : : uint32_t ctrl_ext;
1104 : : uint16_t csum;
1105 : : int diag, i, ret;
1106 : :
1107 : 0 : PMD_INIT_FUNC_TRACE();
1108 : :
1109 : 0 : ixgbe_dev_macsec_setting_reset(eth_dev);
1110 : :
1111 : 0 : eth_dev->dev_ops = &ixgbe_eth_dev_ops;
1112 : 0 : eth_dev->rx_queue_count = ixgbe_dev_rx_queue_count;
1113 : 0 : eth_dev->rx_descriptor_status = ixgbe_dev_rx_descriptor_status;
1114 : 0 : eth_dev->tx_descriptor_status = ixgbe_dev_tx_descriptor_status;
1115 : 0 : eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
1116 : 0 : eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
1117 : 0 : eth_dev->tx_pkt_prepare = &ixgbe_prep_pkts;
1118 : :
1119 : : /*
1120 : : * For secondary processes, we don't initialise any further as primary
1121 : : * has already done this work. Only check we don't need a different
1122 : : * RX and TX function.
1123 : : */
1124 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1125 : : struct ci_tx_queue *txq;
1126 : : /* TX queue function in primary, set by last queue initialized
1127 : : * Tx queue may not initialized by primary process
1128 : : */
1129 [ # # ]: 0 : if (eth_dev->data->tx_queues) {
1130 : 0 : txq = eth_dev->data->tx_queues[eth_dev->data->nb_tx_queues-1];
1131 : 0 : ixgbe_set_tx_function(eth_dev, txq);
1132 : : } else {
1133 : : /* Use default TX function if we get here */
1134 : 0 : PMD_INIT_LOG(NOTICE, "No TX queues configured yet. "
1135 : : "Using default TX function.");
1136 : : }
1137 : :
1138 : 0 : ixgbe_set_rx_function(eth_dev);
1139 : :
1140 : 0 : return 0;
1141 : : }
1142 : :
1143 : : /* NOTE: review for potential ordering optimization */
1144 : 0 : rte_atomic_store_explicit(&ad->link_thread_running, 0, rte_memory_order_seq_cst);
1145 : 0 : ixgbe_parse_devargs(eth_dev->data->dev_private,
1146 : : pci_dev->device.devargs);
1147 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
1148 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1149 : :
1150 : : /* Vendor and Device ID need to be set before init of shared code */
1151 : 0 : hw->device_id = pci_dev->id.device_id;
1152 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
1153 : 0 : hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1154 : 0 : hw->allow_unsupported_sfp = 1;
1155 : :
1156 : : /* Initialize the shared code (base driver) */
1157 : : #ifdef RTE_LIBRTE_IXGBE_BYPASS
1158 : 0 : diag = ixgbe_bypass_init_shared_code(hw);
1159 : : #else
1160 : : diag = ixgbe_init_shared_code(hw);
1161 : : #endif /* RTE_LIBRTE_IXGBE_BYPASS */
1162 : :
1163 [ # # ]: 0 : if (diag != IXGBE_SUCCESS) {
1164 : 0 : PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
1165 : 0 : return -EIO;
1166 : : }
1167 : :
1168 [ # # # # ]: 0 : if (hw->mac.ops.fw_recovery_mode && hw->mac.ops.fw_recovery_mode(hw)) {
1169 : 0 : PMD_INIT_LOG(ERR, "ERROR: Firmware recovery mode detected. Limiting functionality.");
1170 : 0 : return -EIO;
1171 : : }
1172 : :
1173 : : /* pick up the PCI bus settings for reporting later */
1174 : 0 : ixgbe_get_bus_info(hw);
1175 : :
1176 : : /* Unlock any pending hardware semaphore */
1177 : 0 : ixgbe_swfw_lock_reset(hw);
1178 : :
1179 : : #ifdef RTE_LIB_SECURITY
1180 : : /* Initialize security_ctx only for primary process*/
1181 [ # # ]: 0 : if (ixgbe_ipsec_ctx_create(eth_dev))
1182 : : return -ENOMEM;
1183 : : #endif
1184 : :
1185 : : /* Initialize DCB configuration*/
1186 : : memset(dcb_config, 0, sizeof(struct ixgbe_dcb_config));
1187 : 0 : ixgbe_dcb_init(hw, dcb_config);
1188 : : /* Get Hardware Flow Control setting */
1189 : 0 : hw->fc.requested_mode = ixgbe_fc_none;
1190 : 0 : hw->fc.current_mode = ixgbe_fc_none;
1191 : 0 : hw->fc.pause_time = IXGBE_FC_PAUSE;
1192 [ # # ]: 0 : for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
1193 : 0 : hw->fc.low_water[i] = IXGBE_FC_LO;
1194 : 0 : hw->fc.high_water[i] = IXGBE_FC_HI;
1195 : : }
1196 : 0 : hw->fc.send_xon = 1;
1197 : :
1198 : : /* Make sure we have a good EEPROM before we read from it */
1199 : 0 : diag = ixgbe_validate_eeprom_checksum(hw, &csum);
1200 [ # # ]: 0 : if (diag != IXGBE_SUCCESS) {
1201 : 0 : PMD_INIT_LOG(ERR, "The EEPROM checksum is not valid: %d", diag);
1202 : : ret = -EIO;
1203 : 0 : goto err_exit;
1204 : : }
1205 : :
1206 : : #ifdef RTE_LIBRTE_IXGBE_BYPASS
1207 : 0 : diag = ixgbe_bypass_init_hw(hw);
1208 : : #else
1209 : : diag = ixgbe_init_hw(hw);
1210 : : #endif /* RTE_LIBRTE_IXGBE_BYPASS */
1211 : :
1212 : : /*
1213 : : * Devices with copper phys will fail to initialise if ixgbe_init_hw()
1214 : : * is called too soon after the kernel driver unbinding/binding occurs.
1215 : : * The failure occurs in ixgbe_identify_phy_generic() for all devices,
1216 : : * but for non-copper devies, ixgbe_identify_sfp_module_generic() is
1217 : : * also called. See ixgbe_identify_phy_82599(). The reason for the
1218 : : * failure is not known, and only occuts when virtualisation features
1219 : : * are disabled in the bios. A delay of 100ms was found to be enough by
1220 : : * trial-and-error, and is doubled to be safe.
1221 : : */
1222 [ # # # # ]: 0 : if (diag && (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)) {
1223 : : rte_delay_ms(200);
1224 : 0 : diag = ixgbe_init_hw(hw);
1225 : : }
1226 : :
1227 [ # # ]: 0 : if (diag == IXGBE_ERR_SFP_NOT_PRESENT)
1228 : : diag = IXGBE_SUCCESS;
1229 : :
1230 [ # # ]: 0 : if (diag == IXGBE_ERR_EEPROM_VERSION) {
1231 : 0 : PMD_INIT_LOG(ERR, "This device is a pre-production adapter/"
1232 : : "LOM. Please be aware there may be issues associated "
1233 : : "with your hardware.");
1234 : 0 : PMD_INIT_LOG(ERR, "If you are experiencing problems "
1235 : : "please contact your Intel or hardware representative "
1236 : : "who provided you with this hardware.");
1237 [ # # ]: 0 : } else if (diag == IXGBE_ERR_SFP_NOT_SUPPORTED)
1238 : 0 : PMD_INIT_LOG(ERR, "Unsupported SFP+ Module");
1239 [ # # ]: 0 : if (diag) {
1240 : 0 : PMD_INIT_LOG(ERR, "Hardware Initialization Failure: %d", diag);
1241 : : ret = -EIO;
1242 : 0 : goto err_exit;
1243 : : }
1244 : :
1245 : : /* Reset the hw statistics */
1246 : 0 : ixgbe_dev_stats_reset(eth_dev);
1247 : :
1248 : : /* disable interrupt */
1249 : 0 : ixgbe_disable_intr(hw);
1250 : :
1251 : : /* reset mappings for queue statistics hw counters*/
1252 : : ixgbe_reset_qstat_mappings(hw);
1253 : :
1254 : : /* Allocate memory for storing MAC addresses */
1255 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("ixgbe", RTE_ETHER_ADDR_LEN *
1256 : 0 : hw->mac.num_rar_entries, 0);
1257 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
1258 : 0 : PMD_INIT_LOG(ERR,
1259 : : "Failed to allocate %u bytes needed to store "
1260 : : "MAC addresses",
1261 : : RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
1262 : : ret = -ENOMEM;
1263 : 0 : goto err_exit;
1264 : : }
1265 : : /* Copy the permanent MAC address */
1266 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
1267 : : ð_dev->data->mac_addrs[0]);
1268 : :
1269 : : /* Allocate memory for storing hash filter MAC addresses */
1270 : 0 : eth_dev->data->hash_mac_addrs = rte_zmalloc(
1271 : : "ixgbe", RTE_ETHER_ADDR_LEN * IXGBE_VMDQ_NUM_UC_MAC, 0);
1272 [ # # ]: 0 : if (eth_dev->data->hash_mac_addrs == NULL) {
1273 : 0 : PMD_INIT_LOG(ERR,
1274 : : "Failed to allocate %d bytes needed to store MAC addresses",
1275 : : RTE_ETHER_ADDR_LEN * IXGBE_VMDQ_NUM_UC_MAC);
1276 : 0 : rte_free(eth_dev->data->mac_addrs);
1277 : 0 : eth_dev->data->mac_addrs = NULL;
1278 : : ret = -ENOMEM;
1279 : 0 : goto err_exit;
1280 : : }
1281 : :
1282 : : /* initialize the vfta */
1283 : : memset(shadow_vfta, 0, sizeof(*shadow_vfta));
1284 : :
1285 : : /* initialize the hw strip bitmap*/
1286 : : memset(hwstrip, 0, sizeof(*hwstrip));
1287 : :
1288 : : /* initialize PF if max_vfs not zero */
1289 : 0 : ret = ixgbe_pf_host_init(eth_dev);
1290 [ # # ]: 0 : if (ret)
1291 : 0 : goto err_pf_host_init;
1292 : :
1293 : 0 : ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
1294 : : /* let hardware know driver is loaded */
1295 : : ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
1296 : : /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1297 : 0 : ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
1298 : 0 : IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
1299 : 0 : IXGBE_WRITE_FLUSH(hw);
1300 : :
1301 [ # # # # ]: 0 : if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
1302 : 0 : PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d, SFP+: %d",
1303 : : (int) hw->mac.type, (int) hw->phy.type,
1304 : : (int) hw->phy.sfp_type);
1305 : : else
1306 : 0 : PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d",
1307 : : (int) hw->mac.type, (int) hw->phy.type);
1308 : :
1309 : 0 : PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
1310 : : eth_dev->data->port_id, pci_dev->id.vendor_id,
1311 : : pci_dev->id.device_id);
1312 : :
1313 : 0 : rte_intr_callback_register(intr_handle,
1314 : : ixgbe_dev_interrupt_handler, eth_dev);
1315 : :
1316 : : /* enable uio/vfio intr/eventfd mapping */
1317 : 0 : rte_intr_enable(intr_handle);
1318 : :
1319 : : /* enable support intr */
1320 : : ixgbe_enable_intr(eth_dev);
1321 : :
1322 : : /* initialize filter info */
1323 : : memset(filter_info, 0,
1324 : : sizeof(struct ixgbe_filter_info));
1325 : :
1326 : : /* initialize 5tuple filter list */
1327 : 0 : TAILQ_INIT(&filter_info->fivetuple_list);
1328 : :
1329 : : /* initialize flow director filter list & hash */
1330 : 0 : ret = ixgbe_fdir_filter_init(eth_dev);
1331 [ # # ]: 0 : if (ret)
1332 : 0 : goto err_fdir_filter_init;
1333 : :
1334 : : /* initialize l2 tunnel filter list & hash */
1335 : 0 : ret = ixgbe_l2_tn_filter_init(eth_dev);
1336 [ # # ]: 0 : if (ret)
1337 : 0 : goto err_l2_tn_filter_init;
1338 : :
1339 : : /* initialize flow filter lists */
1340 : 0 : ixgbe_filterlist_init();
1341 : :
1342 : : /* initialize bandwidth configuration info */
1343 : : memset(bw_conf, 0, sizeof(struct ixgbe_bw_conf));
1344 : :
1345 : : /* initialize Traffic Manager configuration */
1346 : 0 : ixgbe_tm_conf_init(eth_dev);
1347 : :
1348 : 0 : return 0;
1349 : :
1350 : : err_l2_tn_filter_init:
1351 : 0 : ixgbe_fdir_filter_uninit(eth_dev);
1352 : 0 : err_fdir_filter_init:
1353 : 0 : ixgbe_disable_intr(hw);
1354 : 0 : rte_intr_disable(intr_handle);
1355 : 0 : rte_intr_callback_unregister(intr_handle,
1356 : : ixgbe_dev_interrupt_handler, eth_dev);
1357 : 0 : ixgbe_pf_host_uninit(eth_dev);
1358 : 0 : err_pf_host_init:
1359 : 0 : rte_free(eth_dev->data->mac_addrs);
1360 : 0 : eth_dev->data->mac_addrs = NULL;
1361 : 0 : rte_free(eth_dev->data->hash_mac_addrs);
1362 : 0 : eth_dev->data->hash_mac_addrs = NULL;
1363 : 0 : err_exit:
1364 : : #ifdef RTE_LIB_SECURITY
1365 : 0 : rte_free(eth_dev->security_ctx);
1366 : 0 : eth_dev->security_ctx = NULL;
1367 : : #endif
1368 : 0 : return ret;
1369 : : }
1370 : :
1371 : : static int
1372 : 0 : eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
1373 : : {
1374 : 0 : PMD_INIT_FUNC_TRACE();
1375 : :
1376 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1377 : : return 0;
1378 : :
1379 : 0 : ixgbe_dev_close(eth_dev);
1380 : :
1381 : 0 : return 0;
1382 : : }
1383 : :
1384 : 0 : static int ixgbe_ntuple_filter_uninit(struct rte_eth_dev *eth_dev)
1385 : : {
1386 : : struct ixgbe_filter_info *filter_info =
1387 : 0 : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
1388 : : struct ixgbe_5tuple_filter *p_5tuple;
1389 : :
1390 [ # # ]: 0 : while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list))) {
1391 [ # # ]: 0 : TAILQ_REMOVE(&filter_info->fivetuple_list,
1392 : : p_5tuple,
1393 : : entries);
1394 : 0 : rte_free(p_5tuple);
1395 : : }
1396 : 0 : memset(filter_info->fivetuple_mask, 0,
1397 : : sizeof(uint32_t) * IXGBE_5TUPLE_ARRAY_SIZE);
1398 : :
1399 : 0 : return 0;
1400 : : }
1401 : :
1402 : 0 : static int ixgbe_fdir_filter_uninit(struct rte_eth_dev *eth_dev)
1403 : : {
1404 : : struct ixgbe_hw_fdir_info *fdir_info =
1405 : 0 : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(eth_dev->data->dev_private);
1406 : : struct ixgbe_fdir_filter *fdir_filter;
1407 : :
1408 : 0 : rte_free(fdir_info->hash_map);
1409 : 0 : rte_hash_free(fdir_info->hash_handle);
1410 : :
1411 [ # # ]: 0 : while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
1412 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list,
1413 : : fdir_filter,
1414 : : entries);
1415 : 0 : rte_free(fdir_filter);
1416 : : }
1417 : :
1418 : 0 : return 0;
1419 : : }
1420 : :
1421 : 0 : static int ixgbe_l2_tn_filter_uninit(struct rte_eth_dev *eth_dev)
1422 : : {
1423 : : struct ixgbe_l2_tn_info *l2_tn_info =
1424 : 0 : IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(eth_dev->data->dev_private);
1425 : : struct ixgbe_l2_tn_filter *l2_tn_filter;
1426 : :
1427 : 0 : rte_free(l2_tn_info->hash_map);
1428 : 0 : rte_hash_free(l2_tn_info->hash_handle);
1429 : :
1430 [ # # ]: 0 : while ((l2_tn_filter = TAILQ_FIRST(&l2_tn_info->l2_tn_list))) {
1431 [ # # ]: 0 : TAILQ_REMOVE(&l2_tn_info->l2_tn_list,
1432 : : l2_tn_filter,
1433 : : entries);
1434 : 0 : rte_free(l2_tn_filter);
1435 : : }
1436 : :
1437 : 0 : return 0;
1438 : : }
1439 : :
1440 : 0 : static int ixgbe_fdir_filter_init(struct rte_eth_dev *eth_dev)
1441 : : {
1442 : : struct ixgbe_hw_fdir_info *fdir_info =
1443 : 0 : IXGBE_DEV_PRIVATE_TO_FDIR_INFO(eth_dev->data->dev_private);
1444 : : char fdir_hash_name[RTE_HASH_NAMESIZE];
1445 : 0 : struct rte_hash_parameters fdir_hash_params = {
1446 : : .name = fdir_hash_name,
1447 : : .entries = IXGBE_MAX_FDIR_FILTER_NUM,
1448 : : .key_len = sizeof(union ixgbe_atr_input),
1449 : : .hash_func = rte_hash_crc,
1450 : : .hash_func_init_val = 0,
1451 : 0 : .socket_id = rte_socket_id(),
1452 : : };
1453 : :
1454 : 0 : TAILQ_INIT(&fdir_info->fdir_list);
1455 : 0 : snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
1456 : 0 : "fdir_%s", eth_dev->device->name);
1457 : 0 : fdir_info->hash_handle = rte_hash_create(&fdir_hash_params);
1458 [ # # ]: 0 : if (!fdir_info->hash_handle) {
1459 : 0 : PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
1460 : 0 : return -EINVAL;
1461 : : }
1462 : 0 : fdir_info->hash_map = rte_zmalloc("ixgbe",
1463 : : sizeof(struct ixgbe_fdir_filter *) *
1464 : : IXGBE_MAX_FDIR_FILTER_NUM,
1465 : : 0);
1466 [ # # ]: 0 : if (!fdir_info->hash_map) {
1467 : 0 : PMD_INIT_LOG(ERR,
1468 : : "Failed to allocate memory for fdir hash map!");
1469 : 0 : rte_hash_free(fdir_info->hash_handle);
1470 : 0 : return -ENOMEM;
1471 : : }
1472 : 0 : fdir_info->mask_added = FALSE;
1473 : :
1474 : 0 : return 0;
1475 : : }
1476 : :
1477 : 0 : static int ixgbe_l2_tn_filter_init(struct rte_eth_dev *eth_dev)
1478 : : {
1479 : : struct ixgbe_l2_tn_info *l2_tn_info =
1480 : 0 : IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(eth_dev->data->dev_private);
1481 : : char l2_tn_hash_name[RTE_HASH_NAMESIZE];
1482 : 0 : struct rte_hash_parameters l2_tn_hash_params = {
1483 : : .name = l2_tn_hash_name,
1484 : : .entries = IXGBE_MAX_L2_TN_FILTER_NUM,
1485 : : .key_len = sizeof(struct ixgbe_l2_tn_key),
1486 : : .hash_func = rte_hash_crc,
1487 : : .hash_func_init_val = 0,
1488 : 0 : .socket_id = rte_socket_id(),
1489 : : };
1490 : :
1491 : 0 : TAILQ_INIT(&l2_tn_info->l2_tn_list);
1492 : 0 : snprintf(l2_tn_hash_name, RTE_HASH_NAMESIZE,
1493 : 0 : "l2_tn_%s", eth_dev->device->name);
1494 : 0 : l2_tn_info->hash_handle = rte_hash_create(&l2_tn_hash_params);
1495 [ # # ]: 0 : if (!l2_tn_info->hash_handle) {
1496 : 0 : PMD_INIT_LOG(ERR, "Failed to create L2 TN hash table!");
1497 : 0 : return -EINVAL;
1498 : : }
1499 : 0 : l2_tn_info->hash_map = rte_zmalloc("ixgbe",
1500 : : sizeof(struct ixgbe_l2_tn_filter *) *
1501 : : IXGBE_MAX_L2_TN_FILTER_NUM,
1502 : : 0);
1503 [ # # ]: 0 : if (!l2_tn_info->hash_map) {
1504 : 0 : PMD_INIT_LOG(ERR,
1505 : : "Failed to allocate memory for L2 TN hash map!");
1506 : 0 : rte_hash_free(l2_tn_info->hash_handle);
1507 : 0 : return -ENOMEM;
1508 : : }
1509 : 0 : l2_tn_info->e_tag_en = FALSE;
1510 : 0 : l2_tn_info->e_tag_fwd_en = FALSE;
1511 : 0 : l2_tn_info->e_tag_ether_type = RTE_ETHER_TYPE_ETAG;
1512 : :
1513 : 0 : return 0;
1514 : : }
1515 : : /*
1516 : : * Negotiate mailbox API version with the PF.
1517 : : * After reset API version is always set to the basic one (ixgbe_mbox_api_10).
1518 : : * Then we try to negotiate starting with the most recent one.
1519 : : * If all negotiation attempts fail, then we will proceed with
1520 : : * the default one (ixgbe_mbox_api_10).
1521 : : */
1522 : : static void
1523 : 0 : ixgbevf_negotiate_api(struct ixgbe_hw *hw)
1524 : : {
1525 : : int32_t i;
1526 : :
1527 : : /* start with highest supported, proceed down */
1528 : : static const enum ixgbe_pfvf_api_rev sup_ver[] = {
1529 : : ixgbe_mbox_api_13,
1530 : : ixgbe_mbox_api_12,
1531 : : ixgbe_mbox_api_11,
1532 : : ixgbe_mbox_api_10,
1533 : : };
1534 : :
1535 : 0 : for (i = 0;
1536 [ # # # # ]: 0 : i != RTE_DIM(sup_ver) &&
1537 : 0 : ixgbevf_negotiate_api_version(hw, sup_ver[i]) != 0;
1538 : 0 : i++)
1539 : : ;
1540 : 0 : }
1541 : :
1542 : : static void
1543 : 0 : generate_random_mac_addr(struct rte_ether_addr *mac_addr)
1544 : : {
1545 : : uint64_t random;
1546 : :
1547 : : /* Set Organizationally Unique Identifier (OUI) prefix. */
1548 : : mac_addr->addr_bytes[0] = 0x00;
1549 : 0 : mac_addr->addr_bytes[1] = 0x09;
1550 : 0 : mac_addr->addr_bytes[2] = 0xC0;
1551 : : /* Force indication of locally assigned MAC address. */
1552 : 0 : mac_addr->addr_bytes[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;
1553 : : /* Generate the last 3 bytes of the MAC address with a random number. */
1554 : 0 : random = rte_rand();
1555 : 0 : memcpy(&mac_addr->addr_bytes[3], &random, 3);
1556 : 0 : }
1557 : :
1558 : : static int
1559 : 0 : devarg_handle_int(__rte_unused const char *key, const char *value,
1560 : : void *extra_args)
1561 : : {
1562 : : uint16_t *n = extra_args;
1563 : :
1564 [ # # ]: 0 : if (value == NULL || extra_args == NULL)
1565 : : return -EINVAL;
1566 : :
1567 : 0 : *n = (uint16_t)strtoul(value, NULL, 0);
1568 [ # # # # ]: 0 : if (*n == USHRT_MAX && errno == ERANGE)
1569 : 0 : return -1;
1570 : :
1571 : : return 0;
1572 : : }
1573 : :
1574 : : static void
1575 : 0 : ixgbevf_parse_devargs(struct ixgbe_adapter *adapter,
1576 : : struct rte_devargs *devargs)
1577 : : {
1578 : : struct rte_kvargs *kvlist;
1579 : : uint16_t pflink_fullchk;
1580 : :
1581 [ # # ]: 0 : if (devargs == NULL)
1582 : 0 : return;
1583 : :
1584 : 0 : kvlist = rte_kvargs_parse(devargs->args, ixgbevf_valid_arguments);
1585 [ # # ]: 0 : if (kvlist == NULL)
1586 : : return;
1587 : :
1588 [ # # # # ]: 0 : if (rte_kvargs_count(kvlist, IXGBEVF_DEVARG_PFLINK_FULLCHK) == 1 &&
1589 : 0 : rte_kvargs_process(kvlist, IXGBEVF_DEVARG_PFLINK_FULLCHK,
1590 : 0 : devarg_handle_int, &pflink_fullchk) == 0 &&
1591 [ # # ]: 0 : pflink_fullchk == 1)
1592 : 0 : adapter->pflink_fullchk = 1;
1593 : :
1594 : 0 : rte_kvargs_free(kvlist);
1595 : : }
1596 : :
1597 : : /*
1598 : : * Virtual Function device init
1599 : : */
1600 : : static int
1601 : 0 : eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
1602 : : {
1603 : : int diag;
1604 : : uint32_t tc, tcs;
1605 : 0 : struct ixgbe_adapter *ad = eth_dev->data->dev_private;
1606 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1607 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1608 : 0 : struct ixgbe_hw *hw =
1609 : : IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1610 : 0 : struct ixgbe_vfta *shadow_vfta =
1611 : : IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
1612 : 0 : struct ixgbe_hwstrip *hwstrip =
1613 : : IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
1614 : 0 : struct rte_ether_addr *perm_addr =
1615 : : (struct rte_ether_addr *)hw->mac.perm_addr;
1616 : :
1617 : 0 : PMD_INIT_FUNC_TRACE();
1618 : :
1619 : 0 : eth_dev->dev_ops = &ixgbevf_eth_dev_ops;
1620 : 0 : eth_dev->rx_descriptor_status = ixgbe_dev_rx_descriptor_status;
1621 : 0 : eth_dev->tx_descriptor_status = ixgbe_dev_tx_descriptor_status;
1622 : 0 : eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
1623 : 0 : eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
1624 : :
1625 : : /* for secondary processes, we don't initialise any further as primary
1626 : : * has already done this work. Only check we don't need a different
1627 : : * RX function
1628 : : */
1629 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1630 : : struct ci_tx_queue *txq;
1631 : : /* TX queue function in primary, set by last queue initialized
1632 : : * Tx queue may not initialized by primary process
1633 : : */
1634 [ # # ]: 0 : if (eth_dev->data->tx_queues) {
1635 : 0 : txq = eth_dev->data->tx_queues[eth_dev->data->nb_tx_queues - 1];
1636 : 0 : ixgbe_set_tx_function(eth_dev, txq);
1637 : : } else {
1638 : : /* Use default TX function if we get here */
1639 : 0 : PMD_INIT_LOG(NOTICE,
1640 : : "No TX queues configured yet. Using default TX function.");
1641 : : }
1642 : :
1643 : 0 : ixgbe_set_rx_function(eth_dev);
1644 : :
1645 : 0 : return 0;
1646 : : }
1647 : :
1648 : : /* NOTE: review for potential ordering optimization */
1649 : 0 : rte_atomic_store_explicit(&ad->link_thread_running, 0, rte_memory_order_seq_cst);
1650 : 0 : ixgbevf_parse_devargs(eth_dev->data->dev_private,
1651 : : pci_dev->device.devargs);
1652 : :
1653 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
1654 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1655 : :
1656 : 0 : hw->device_id = pci_dev->id.device_id;
1657 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
1658 : 0 : hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1659 : :
1660 : : /* initialize the vfta */
1661 : : memset(shadow_vfta, 0, sizeof(*shadow_vfta));
1662 : :
1663 : : /* initialize the hw strip bitmap*/
1664 : : memset(hwstrip, 0, sizeof(*hwstrip));
1665 : :
1666 : : /* Initialize the shared code (base driver) */
1667 : 0 : diag = ixgbe_init_shared_code(hw);
1668 [ # # ]: 0 : if (diag != IXGBE_SUCCESS) {
1669 : 0 : PMD_INIT_LOG(ERR, "Shared code init failed for ixgbevf: %d", diag);
1670 : 0 : return -EIO;
1671 : : }
1672 : :
1673 : : /* init_mailbox_params */
1674 : 0 : hw->mbx.ops[0].init_params(hw);
1675 : :
1676 : : /* Reset the hw statistics */
1677 : : ixgbevf_dev_stats_reset(eth_dev);
1678 : :
1679 : : /* Disable the interrupts for VF */
1680 : 0 : ixgbevf_intr_disable(eth_dev);
1681 : :
1682 : 0 : hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
1683 : 0 : diag = hw->mac.ops.reset_hw(hw);
1684 : :
1685 : : /*
1686 : : * The VF reset operation returns the IXGBE_ERR_INVALID_MAC_ADDR when
1687 : : * the underlying PF driver has not assigned a MAC address to the VF.
1688 : : * In this case, assign a random MAC address.
1689 : : */
1690 [ # # ]: 0 : if ((diag != IXGBE_SUCCESS) && (diag != IXGBE_ERR_INVALID_MAC_ADDR)) {
1691 : 0 : PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
1692 : : /*
1693 : : * This error code will be propagated to the app by
1694 : : * rte_eth_dev_reset, so use a public error code rather than
1695 : : * the internal-only IXGBE_ERR_RESET_FAILED
1696 : : */
1697 : 0 : return -EAGAIN;
1698 : : }
1699 : :
1700 : : /* negotiate mailbox API version to use with the PF. */
1701 : 0 : ixgbevf_negotiate_api(hw);
1702 : :
1703 : : /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
1704 : 0 : ixgbevf_get_queues(hw, &tcs, &tc);
1705 : :
1706 : : /* Allocate memory for storing MAC addresses */
1707 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("ixgbevf", RTE_ETHER_ADDR_LEN *
1708 : 0 : hw->mac.num_rar_entries, 0);
1709 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
1710 : 0 : PMD_INIT_LOG(ERR,
1711 : : "Failed to allocate %u bytes needed to store "
1712 : : "MAC addresses",
1713 : : RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
1714 : 0 : return -ENOMEM;
1715 : : }
1716 : :
1717 : : /* Generate a random MAC address, if none was assigned by PF. */
1718 [ # # ]: 0 : if (rte_is_zero_ether_addr(perm_addr)) {
1719 : 0 : generate_random_mac_addr(perm_addr);
1720 : 0 : diag = ixgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
1721 [ # # ]: 0 : if (diag) {
1722 : 0 : rte_free(eth_dev->data->mac_addrs);
1723 : 0 : eth_dev->data->mac_addrs = NULL;
1724 : 0 : return diag;
1725 : : }
1726 : 0 : PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1727 : 0 : PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1728 : : RTE_ETHER_ADDR_PRT_FMT,
1729 : : RTE_ETHER_ADDR_BYTES(perm_addr));
1730 : : }
1731 : :
1732 : : /* Copy the permanent MAC address */
1733 : 0 : rte_ether_addr_copy(perm_addr, ð_dev->data->mac_addrs[0]);
1734 : :
1735 : : /* reset the hardware with the new settings */
1736 : 0 : diag = hw->mac.ops.start_hw(hw);
1737 [ # # ]: 0 : switch (diag) {
1738 : : case 0:
1739 : : break;
1740 : :
1741 : 0 : default:
1742 : 0 : PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
1743 : 0 : rte_free(eth_dev->data->mac_addrs);
1744 : 0 : eth_dev->data->mac_addrs = NULL;
1745 : 0 : return -EIO;
1746 : : }
1747 : :
1748 : 0 : rte_intr_callback_register(intr_handle,
1749 : : ixgbevf_dev_interrupt_handler, eth_dev);
1750 : 0 : rte_intr_enable(intr_handle);
1751 : 0 : ixgbevf_intr_enable(eth_dev);
1752 : :
1753 : 0 : PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
1754 : : eth_dev->data->port_id, pci_dev->id.vendor_id,
1755 : : pci_dev->id.device_id, "ixgbe_mac_82599_vf");
1756 : :
1757 : 0 : return 0;
1758 : : }
1759 : :
1760 : : /* Virtual Function device uninit */
1761 : :
1762 : : static int
1763 : 0 : eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
1764 : : {
1765 : 0 : PMD_INIT_FUNC_TRACE();
1766 : :
1767 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1768 : : return 0;
1769 : :
1770 : 0 : ixgbevf_dev_close(eth_dev);
1771 : :
1772 : 0 : return 0;
1773 : : }
1774 : :
1775 : : static int
1776 : 0 : eth_ixgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1777 : : struct rte_pci_device *pci_dev)
1778 : : {
1779 : : char name[RTE_ETH_NAME_MAX_LEN];
1780 : : struct rte_eth_dev *pf_ethdev;
1781 : : struct rte_eth_devargs eth_da;
1782 : : int i, retval;
1783 : :
1784 [ # # ]: 0 : if (pci_dev->device.devargs) {
1785 : 0 : retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
1786 : : ð_da, 1);
1787 [ # # ]: 0 : if (retval < 0)
1788 : : return retval;
1789 : : } else
1790 : : memset(ð_da, 0, sizeof(eth_da));
1791 : :
1792 [ # # ]: 0 : if (eth_da.nb_representor_ports > 0 &&
1793 [ # # ]: 0 : eth_da.type != RTE_ETH_REPRESENTOR_VF) {
1794 : 0 : PMD_DRV_LOG(ERR, "unsupported representor type: %s",
1795 : : pci_dev->device.devargs->args);
1796 : 0 : return -ENOTSUP;
1797 : : }
1798 : :
1799 : 0 : retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
1800 : : sizeof(struct ixgbe_adapter),
1801 : : eth_dev_pci_specific_init, pci_dev,
1802 : : eth_ixgbe_dev_init, NULL);
1803 : :
1804 [ # # # # ]: 0 : if (retval || eth_da.nb_representor_ports < 1)
1805 : : return retval;
1806 : :
1807 : 0 : pf_ethdev = rte_eth_dev_allocated(pci_dev->device.name);
1808 [ # # ]: 0 : if (pf_ethdev == NULL)
1809 : : return -ENODEV;
1810 : :
1811 : : /* probe VF representor ports */
1812 [ # # ]: 0 : for (i = 0; i < eth_da.nb_representor_ports; i++) {
1813 : : struct ixgbe_vf_info *vfinfo;
1814 : : struct ixgbe_vf_representor representor;
1815 : :
1816 : 0 : vfinfo = *IXGBE_DEV_PRIVATE_TO_P_VFDATA(
1817 : : pf_ethdev->data->dev_private);
1818 [ # # ]: 0 : if (vfinfo == NULL) {
1819 : 0 : PMD_DRV_LOG(ERR,
1820 : : "no virtual functions supported by PF");
1821 : 0 : break;
1822 : : }
1823 : :
1824 : 0 : representor.vf_id = eth_da.representor_ports[i];
1825 : 0 : representor.switch_domain_id = vfinfo->switch_domain_id;
1826 : 0 : representor.pf_ethdev = pf_ethdev;
1827 : :
1828 : : /* representor port net_bdf_port */
1829 : 0 : snprintf(name, sizeof(name), "net_%s_representor_%d",
1830 : : pci_dev->device.name,
1831 : : eth_da.representor_ports[i]);
1832 : :
1833 : 0 : retval = rte_eth_dev_create(&pci_dev->device, name,
1834 : : sizeof(struct ixgbe_vf_representor), NULL, NULL,
1835 : : ixgbe_vf_representor_init, &representor);
1836 : :
1837 [ # # ]: 0 : if (retval)
1838 : 0 : PMD_DRV_LOG(ERR, "failed to create ixgbe vf "
1839 : : "representor %s.", name);
1840 : : }
1841 : :
1842 : : return 0;
1843 : : }
1844 : :
1845 : 0 : static int eth_ixgbe_pci_remove(struct rte_pci_device *pci_dev)
1846 : : {
1847 : : struct rte_eth_dev *ethdev;
1848 : :
1849 : 0 : ethdev = rte_eth_dev_allocated(pci_dev->device.name);
1850 [ # # ]: 0 : if (!ethdev)
1851 : : return 0;
1852 : :
1853 [ # # ]: 0 : if (rte_eth_dev_is_repr(ethdev))
1854 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
1855 : : ixgbe_vf_representor_uninit);
1856 : : else
1857 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
1858 : : eth_ixgbe_dev_uninit);
1859 : : }
1860 : :
1861 : : static struct rte_pci_driver rte_ixgbe_pmd = {
1862 : : .id_table = pci_id_ixgbe_map,
1863 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1864 : : .probe = eth_ixgbe_pci_probe,
1865 : : .remove = eth_ixgbe_pci_remove,
1866 : : };
1867 : :
1868 : 0 : static int eth_ixgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1869 : : struct rte_pci_device *pci_dev)
1870 : : {
1871 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
1872 : : sizeof(struct ixgbe_adapter), eth_ixgbevf_dev_init);
1873 : : }
1874 : :
1875 : 0 : static int eth_ixgbevf_pci_remove(struct rte_pci_device *pci_dev)
1876 : : {
1877 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_ixgbevf_dev_uninit);
1878 : : }
1879 : :
1880 : : /*
1881 : : * virtual function driver struct
1882 : : */
1883 : : static struct rte_pci_driver rte_ixgbevf_pmd = {
1884 : : .id_table = pci_id_ixgbevf_map,
1885 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1886 : : .probe = eth_ixgbevf_pci_probe,
1887 : : .remove = eth_ixgbevf_pci_remove,
1888 : : };
1889 : :
1890 : : static int
1891 : 0 : ixgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1892 : : {
1893 : : struct ixgbe_hw *hw =
1894 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1895 : : struct ixgbe_vfta *shadow_vfta =
1896 : : IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
1897 : : uint32_t vfta;
1898 : : uint32_t vid_idx;
1899 : : uint32_t vid_bit;
1900 : :
1901 : 0 : vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
1902 : 0 : vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
1903 : 0 : vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(vid_idx));
1904 [ # # ]: 0 : if (on)
1905 : 0 : vfta |= vid_bit;
1906 : : else
1907 : 0 : vfta &= ~vid_bit;
1908 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(vid_idx), vfta);
1909 : :
1910 : : /* update local VFTA copy */
1911 : 0 : shadow_vfta->vfta[vid_idx] = vfta;
1912 : :
1913 : 0 : return 0;
1914 : : }
1915 : :
1916 : : static void
1917 : 0 : ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
1918 : : {
1919 [ # # ]: 0 : if (on)
1920 : 0 : ixgbe_vlan_hw_strip_enable(dev, queue);
1921 : : else
1922 : 0 : ixgbe_vlan_hw_strip_disable(dev, queue);
1923 : 0 : }
1924 : :
1925 : : static int
1926 : 0 : ixgbe_vlan_tpid_set(struct rte_eth_dev *dev,
1927 : : enum rte_vlan_type vlan_type,
1928 : : uint16_t tpid)
1929 : : {
1930 : : struct ixgbe_hw *hw =
1931 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1932 : : int ret = 0;
1933 : : uint32_t reg;
1934 : : uint32_t qinq;
1935 : :
1936 : 0 : qinq = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1937 : 0 : qinq &= IXGBE_DMATXCTL_GDV;
1938 : :
1939 [ # # # ]: 0 : switch (vlan_type) {
1940 : 0 : case RTE_ETH_VLAN_TYPE_INNER:
1941 [ # # ]: 0 : if (qinq) {
1942 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1943 : 0 : reg = (reg & (~IXGBE_VLNCTRL_VET)) | (uint32_t)tpid;
1944 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, reg);
1945 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1946 : 0 : reg = (reg & (~IXGBE_DMATXCTL_VT_MASK))
1947 : 0 : | ((uint32_t)tpid << IXGBE_DMATXCTL_VT_SHIFT);
1948 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg);
1949 : : } else {
1950 : : ret = -ENOTSUP;
1951 : 0 : PMD_DRV_LOG(ERR, "Inner type is not supported"
1952 : : " by single VLAN");
1953 : : }
1954 : : break;
1955 : 0 : case RTE_ETH_VLAN_TYPE_OUTER:
1956 [ # # ]: 0 : if (qinq) {
1957 : : /* Only the high 16-bits is valid */
1958 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EXVET, (uint32_t)tpid <<
1959 : : IXGBE_EXVET_VET_EXT_SHIFT);
1960 : : } else {
1961 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1962 : 0 : reg = (reg & (~IXGBE_VLNCTRL_VET)) | (uint32_t)tpid;
1963 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, reg);
1964 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1965 : 0 : reg = (reg & (~IXGBE_DMATXCTL_VT_MASK))
1966 : 0 : | ((uint32_t)tpid << IXGBE_DMATXCTL_VT_SHIFT);
1967 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg);
1968 : : }
1969 : :
1970 : : break;
1971 : 0 : default:
1972 : : ret = -EINVAL;
1973 : 0 : PMD_DRV_LOG(ERR, "Unsupported VLAN type %d", vlan_type);
1974 : 0 : break;
1975 : : }
1976 : :
1977 : 0 : return ret;
1978 : : }
1979 : :
1980 : : void
1981 : 0 : ixgbe_vlan_hw_filter_disable(struct rte_eth_dev *dev)
1982 : : {
1983 : : struct ixgbe_hw *hw =
1984 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1985 : : uint32_t vlnctrl;
1986 : :
1987 : 0 : PMD_INIT_FUNC_TRACE();
1988 : :
1989 : : /* Filter Table Disable */
1990 : 0 : vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1991 : 0 : vlnctrl &= ~IXGBE_VLNCTRL_VFE;
1992 : :
1993 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1994 : 0 : }
1995 : :
1996 : : void
1997 : 0 : ixgbe_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1998 : : {
1999 : : struct ixgbe_hw *hw =
2000 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2001 : : struct ixgbe_vfta *shadow_vfta =
2002 : : IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2003 : : uint32_t vlnctrl;
2004 : : uint16_t i;
2005 : :
2006 : 0 : PMD_INIT_FUNC_TRACE();
2007 : :
2008 : : /* Filter Table Enable */
2009 : 0 : vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
2010 : 0 : vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2011 : 0 : vlnctrl |= IXGBE_VLNCTRL_VFE;
2012 : :
2013 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2014 : :
2015 : : /* write whatever is in local vfta copy */
2016 [ # # ]: 0 : for (i = 0; i < IXGBE_VFTA_SIZE; i++)
2017 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), shadow_vfta->vfta[i]);
2018 : 0 : }
2019 : :
2020 : : static void
2021 : 0 : ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev, uint16_t queue, bool on)
2022 : : {
2023 : : struct ixgbe_hwstrip *hwstrip =
2024 : 0 : IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(dev->data->dev_private);
2025 : : struct ixgbe_rx_queue *rxq;
2026 : :
2027 [ # # ]: 0 : if (queue >= IXGBE_MAX_RX_QUEUE_NUM)
2028 : : return;
2029 : :
2030 [ # # ]: 0 : if (on)
2031 : 0 : IXGBE_SET_HWSTRIP(hwstrip, queue);
2032 : : else
2033 : 0 : IXGBE_CLEAR_HWSTRIP(hwstrip, queue);
2034 : :
2035 [ # # ]: 0 : if (queue >= dev->data->nb_rx_queues)
2036 : : return;
2037 : :
2038 : 0 : rxq = dev->data->rx_queues[queue];
2039 : :
2040 [ # # ]: 0 : if (on) {
2041 : 0 : rxq->vlan_flags = RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
2042 : 0 : rxq->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2043 : : } else {
2044 : 0 : rxq->vlan_flags = RTE_MBUF_F_RX_VLAN;
2045 : 0 : rxq->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2046 : : }
2047 : : }
2048 : :
2049 : : static void
2050 : 0 : ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue)
2051 : : {
2052 : : struct ixgbe_hw *hw =
2053 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2054 : : uint32_t ctrl;
2055 : :
2056 : 0 : PMD_INIT_FUNC_TRACE();
2057 : :
2058 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB) {
2059 : : /* No queue level support */
2060 : 0 : PMD_INIT_LOG(NOTICE, "82598EB not support queue level hw strip");
2061 : 0 : return;
2062 : : }
2063 : :
2064 : : /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
2065 [ # # ]: 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
2066 : 0 : ctrl &= ~IXGBE_RXDCTL_VME;
2067 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
2068 : :
2069 : : /* record those setting for HW strip per queue */
2070 : 0 : ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 0);
2071 : : }
2072 : :
2073 : : static void
2074 : 0 : ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue)
2075 : : {
2076 : : struct ixgbe_hw *hw =
2077 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2078 : : uint32_t ctrl;
2079 : :
2080 : 0 : PMD_INIT_FUNC_TRACE();
2081 : :
2082 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB) {
2083 : : /* No queue level supported */
2084 : 0 : PMD_INIT_LOG(NOTICE, "82598EB not support queue level hw strip");
2085 : 0 : return;
2086 : : }
2087 : :
2088 : : /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
2089 [ # # ]: 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
2090 : 0 : ctrl |= IXGBE_RXDCTL_VME;
2091 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
2092 : :
2093 : : /* record those setting for HW strip per queue */
2094 : 0 : ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 1);
2095 : : }
2096 : :
2097 : : static void
2098 : 0 : ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2099 : : {
2100 : : struct ixgbe_hw *hw =
2101 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2102 : : uint32_t ctrl;
2103 : :
2104 : 0 : PMD_INIT_FUNC_TRACE();
2105 : :
2106 : : /* DMATXCTRL: Geric Double VLAN Disable */
2107 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2108 : 0 : ctrl &= ~IXGBE_DMATXCTL_GDV;
2109 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
2110 : :
2111 : : /* CTRL_EXT: Global Double VLAN Disable */
2112 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
2113 : 0 : ctrl &= ~IXGBE_EXTENDED_VLAN;
2114 : 0 : IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
2115 : :
2116 : 0 : }
2117 : :
2118 : : static void
2119 : 0 : ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2120 : : {
2121 : : struct ixgbe_hw *hw =
2122 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2123 : : uint32_t ctrl;
2124 : :
2125 : 0 : PMD_INIT_FUNC_TRACE();
2126 : :
2127 : : /* DMATXCTRL: Geric Double VLAN Enable */
2128 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2129 : 0 : ctrl |= IXGBE_DMATXCTL_GDV;
2130 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
2131 : :
2132 : : /* CTRL_EXT: Global Double VLAN Enable */
2133 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
2134 : 0 : ctrl |= IXGBE_EXTENDED_VLAN;
2135 : 0 : IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
2136 : :
2137 : : /* Clear pooling mode of PFVTCTL. It's required by X550. */
2138 : 0 : if (hw->mac.type == ixgbe_mac_X550 ||
2139 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550EM_x ||
2140 : : hw->mac.type == ixgbe_mac_X550EM_a) {
2141 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2142 : 0 : ctrl &= ~IXGBE_VT_CTL_POOLING_MODE_MASK;
2143 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, ctrl);
2144 : : }
2145 : :
2146 : : /*
2147 : : * VET EXT field in the EXVET register = 0x8100 by default
2148 : : * So no need to change. Same to VT field of DMATXCTL register
2149 : : */
2150 : 0 : }
2151 : :
2152 : : void
2153 : 0 : ixgbe_vlan_hw_strip_config(struct rte_eth_dev *dev)
2154 : : {
2155 : : struct ixgbe_hw *hw =
2156 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2157 : : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
2158 : : uint32_t ctrl;
2159 : : uint16_t i;
2160 : : struct ixgbe_rx_queue *rxq;
2161 : : bool on;
2162 : :
2163 : 0 : PMD_INIT_FUNC_TRACE();
2164 : :
2165 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB) {
2166 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
2167 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
2168 : 0 : ctrl |= IXGBE_VLNCTRL_VME;
2169 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
2170 : : } else {
2171 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
2172 : 0 : ctrl &= ~IXGBE_VLNCTRL_VME;
2173 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
2174 : : }
2175 : : } else {
2176 : : /*
2177 : : * Other 10G NIC, the VLAN strip can be setup
2178 : : * per queue in RXDCTL
2179 : : */
2180 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2181 : 0 : rxq = dev->data->rx_queues[i];
2182 [ # # ]: 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
2183 [ # # ]: 0 : if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
2184 : 0 : ctrl |= IXGBE_RXDCTL_VME;
2185 : : on = TRUE;
2186 : : } else {
2187 : 0 : ctrl &= ~IXGBE_RXDCTL_VME;
2188 : : on = FALSE;
2189 : : }
2190 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxq->reg_idx), ctrl);
2191 : :
2192 : : /* record those setting for HW strip per queue */
2193 : 0 : ixgbe_vlan_hw_strip_bitmap_set(dev, i, on);
2194 : : }
2195 : : }
2196 : 0 : }
2197 : :
2198 : : static void
2199 : 0 : ixgbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev, int mask)
2200 : : {
2201 : : uint16_t i;
2202 : : struct rte_eth_rxmode *rxmode;
2203 : : struct ixgbe_rx_queue *rxq;
2204 : :
2205 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
2206 : 0 : rxmode = &dev->data->dev_conf.rxmode;
2207 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
2208 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2209 : 0 : rxq = dev->data->rx_queues[i];
2210 : 0 : rxq->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2211 : : }
2212 : : else
2213 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2214 : 0 : rxq = dev->data->rx_queues[i];
2215 : 0 : rxq->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2216 : : }
2217 : : }
2218 : 0 : }
2219 : :
2220 : : static int
2221 : 0 : ixgbe_vlan_offload_config(struct rte_eth_dev *dev, int mask)
2222 : : {
2223 : : struct rte_eth_rxmode *rxmode;
2224 : 0 : rxmode = &dev->data->dev_conf.rxmode;
2225 : :
2226 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK)
2227 : 0 : ixgbe_vlan_hw_strip_config(dev);
2228 : :
2229 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
2230 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
2231 : 0 : ixgbe_vlan_hw_filter_enable(dev);
2232 : : else
2233 : 0 : ixgbe_vlan_hw_filter_disable(dev);
2234 : : }
2235 : :
2236 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
2237 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
2238 : 0 : ixgbe_vlan_hw_extend_enable(dev);
2239 : : else
2240 : 0 : ixgbe_vlan_hw_extend_disable(dev);
2241 : : }
2242 : :
2243 : 0 : return 0;
2244 : : }
2245 : :
2246 : : static int
2247 : 0 : ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2248 : : {
2249 : 0 : ixgbe_config_vlan_strip_on_all_queues(dev, mask);
2250 : :
2251 : 0 : ixgbe_vlan_offload_config(dev, mask);
2252 : :
2253 : 0 : return 0;
2254 : : }
2255 : :
2256 : : static void
2257 : : ixgbe_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2258 : : {
2259 : : struct ixgbe_hw *hw =
2260 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2261 : : /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
2262 : 0 : uint32_t vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
2263 : :
2264 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
2265 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
2266 : 0 : }
2267 : :
2268 : : static int
2269 : : ixgbe_check_vf_rss_rxq_num(struct rte_eth_dev *dev, uint16_t nb_rx_q)
2270 : : {
2271 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2272 : :
2273 [ # # # ]: 0 : switch (nb_rx_q) {
2274 : 0 : case 1:
2275 : : case 2:
2276 : 0 : RTE_ETH_DEV_SRIOV(dev).active = RTE_ETH_64_POOLS;
2277 : 0 : break;
2278 : 0 : case 4:
2279 : 0 : RTE_ETH_DEV_SRIOV(dev).active = RTE_ETH_32_POOLS;
2280 : 0 : break;
2281 : : default:
2282 : : return -EINVAL;
2283 : : }
2284 : :
2285 : 0 : RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool =
2286 : 0 : IXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
2287 : 0 : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
2288 : 0 : pci_dev->max_vfs * RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
2289 : : return 0;
2290 : : }
2291 : :
2292 : : static int
2293 : 0 : ixgbe_check_mq_mode(struct rte_eth_dev *dev)
2294 : : {
2295 : 0 : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
2296 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2297 : 0 : uint16_t nb_rx_q = dev->data->nb_rx_queues;
2298 : 0 : uint16_t nb_tx_q = dev->data->nb_tx_queues;
2299 : :
2300 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
2301 : : /* check multi-queue mode */
2302 [ # # # # : 0 : switch (dev_conf->rxmode.mq_mode) {
# ]
2303 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB:
2304 : 0 : PMD_INIT_LOG(INFO, "RTE_ETH_MQ_RX_VMDQ_DCB mode supported in SRIOV");
2305 : 0 : break;
2306 : 0 : case RTE_ETH_MQ_RX_VMDQ_DCB_RSS:
2307 : : /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
2308 : 0 : PMD_INIT_LOG(ERR, "SRIOV active,"
2309 : : " unsupported mq_mode rx %d.",
2310 : : dev_conf->rxmode.mq_mode);
2311 : 0 : return -EINVAL;
2312 : 0 : case RTE_ETH_MQ_RX_RSS:
2313 : : case RTE_ETH_MQ_RX_VMDQ_RSS:
2314 : 0 : dev->data->dev_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_VMDQ_RSS;
2315 [ # # ]: 0 : if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
2316 : : if (ixgbe_check_vf_rss_rxq_num(dev, nb_rx_q)) {
2317 : 0 : PMD_INIT_LOG(ERR, "SRIOV is active,"
2318 : : " invalid queue number"
2319 : : " for VMDQ RSS, allowed"
2320 : : " value are 1, 2 or 4.");
2321 : 0 : return -EINVAL;
2322 : : }
2323 : : break;
2324 : 0 : case RTE_ETH_MQ_RX_VMDQ_ONLY:
2325 : : case RTE_ETH_MQ_RX_NONE:
2326 : : /* if nothing mq mode configure, use default scheme */
2327 : 0 : dev->data->dev_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_VMDQ_ONLY;
2328 : 0 : break;
2329 : 0 : default: /* RTE_ETH_MQ_RX_DCB, RTE_ETH_MQ_RX_DCB_RSS or RTE_ETH_MQ_TX_DCB*/
2330 : : /* SRIOV only works in VMDq enable mode */
2331 : 0 : PMD_INIT_LOG(ERR, "SRIOV is active,"
2332 : : " wrong mq_mode rx %d.",
2333 : : dev_conf->rxmode.mq_mode);
2334 : 0 : return -EINVAL;
2335 : : }
2336 : :
2337 [ # # ]: 0 : switch (dev_conf->txmode.mq_mode) {
2338 : 0 : case RTE_ETH_MQ_TX_VMDQ_DCB:
2339 : 0 : PMD_INIT_LOG(INFO, "RTE_ETH_MQ_TX_VMDQ_DCB mode supported in SRIOV");
2340 : 0 : dev->data->dev_conf.txmode.mq_mode = RTE_ETH_MQ_TX_VMDQ_DCB;
2341 : 0 : break;
2342 : 0 : default: /* RTE_ETH_MQ_TX_VMDQ_ONLY or RTE_ETH_MQ_TX_NONE */
2343 : 0 : dev->data->dev_conf.txmode.mq_mode = RTE_ETH_MQ_TX_VMDQ_ONLY;
2344 : 0 : break;
2345 : : }
2346 : :
2347 : : /* check valid queue number */
2348 [ # # # # ]: 0 : if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
2349 : : (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
2350 : 0 : PMD_INIT_LOG(ERR, "SRIOV is active,"
2351 : : " nb_rx_q=%d nb_tx_q=%d queue number"
2352 : : " must be less than or equal to %d.",
2353 : : nb_rx_q, nb_tx_q,
2354 : : RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
2355 : 0 : return -EINVAL;
2356 : : }
2357 : : } else {
2358 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode == RTE_ETH_MQ_RX_VMDQ_DCB_RSS) {
2359 : 0 : PMD_INIT_LOG(ERR, "VMDQ+DCB+RSS mq_mode is"
2360 : : " not supported.");
2361 : 0 : return -EINVAL;
2362 : : }
2363 : : /* check configuration for vmdb+dcb mode */
2364 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode == RTE_ETH_MQ_RX_VMDQ_DCB) {
2365 : : const struct rte_eth_vmdq_dcb_conf *conf;
2366 : :
2367 [ # # ]: 0 : if (nb_rx_q != IXGBE_VMDQ_DCB_NB_QUEUES) {
2368 : 0 : PMD_INIT_LOG(ERR, "VMDQ+DCB, nb_rx_q != %d.",
2369 : : IXGBE_VMDQ_DCB_NB_QUEUES);
2370 : 0 : return -EINVAL;
2371 : : }
2372 : : conf = &dev_conf->rx_adv_conf.vmdq_dcb_conf;
2373 [ # # ]: 0 : if (!(conf->nb_queue_pools == RTE_ETH_16_POOLS ||
2374 : : conf->nb_queue_pools == RTE_ETH_32_POOLS)) {
2375 : 0 : PMD_INIT_LOG(ERR, "VMDQ+DCB selected,"
2376 : : " nb_queue_pools must be %d or %d.",
2377 : : RTE_ETH_16_POOLS, RTE_ETH_32_POOLS);
2378 : 0 : return -EINVAL;
2379 : : }
2380 : : }
2381 [ # # ]: 0 : if (dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_DCB) {
2382 : : const struct rte_eth_vmdq_dcb_tx_conf *conf;
2383 : :
2384 [ # # ]: 0 : if (nb_tx_q != IXGBE_VMDQ_DCB_NB_QUEUES) {
2385 : 0 : PMD_INIT_LOG(ERR, "VMDQ+DCB, nb_tx_q != %d",
2386 : : IXGBE_VMDQ_DCB_NB_QUEUES);
2387 : 0 : return -EINVAL;
2388 : : }
2389 : : conf = &dev_conf->tx_adv_conf.vmdq_dcb_tx_conf;
2390 [ # # ]: 0 : if (!(conf->nb_queue_pools == RTE_ETH_16_POOLS ||
2391 : : conf->nb_queue_pools == RTE_ETH_32_POOLS)) {
2392 : 0 : PMD_INIT_LOG(ERR, "VMDQ+DCB selected,"
2393 : : " nb_queue_pools != %d and"
2394 : : " nb_queue_pools != %d.",
2395 : : RTE_ETH_16_POOLS, RTE_ETH_32_POOLS);
2396 : 0 : return -EINVAL;
2397 : : }
2398 : : }
2399 : :
2400 : : /* For DCB mode check our configuration before we go further */
2401 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode == RTE_ETH_MQ_RX_DCB) {
2402 : : const struct rte_eth_dcb_rx_conf *conf;
2403 : :
2404 : : conf = &dev_conf->rx_adv_conf.dcb_rx_conf;
2405 [ # # ]: 0 : if (!(conf->nb_tcs == RTE_ETH_4_TCS ||
2406 : : conf->nb_tcs == RTE_ETH_8_TCS)) {
2407 : 0 : PMD_INIT_LOG(ERR, "DCB selected, nb_tcs != %d"
2408 : : " and nb_tcs != %d.",
2409 : : RTE_ETH_4_TCS, RTE_ETH_8_TCS);
2410 : 0 : return -EINVAL;
2411 : : }
2412 : : }
2413 : :
2414 [ # # ]: 0 : if (dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_DCB) {
2415 : : const struct rte_eth_dcb_tx_conf *conf;
2416 : :
2417 : : conf = &dev_conf->tx_adv_conf.dcb_tx_conf;
2418 [ # # ]: 0 : if (!(conf->nb_tcs == RTE_ETH_4_TCS ||
2419 : : conf->nb_tcs == RTE_ETH_8_TCS)) {
2420 : 0 : PMD_INIT_LOG(ERR, "DCB selected, nb_tcs != %d"
2421 : : " and nb_tcs != %d.",
2422 : : RTE_ETH_4_TCS, RTE_ETH_8_TCS);
2423 : 0 : return -EINVAL;
2424 : : }
2425 : : }
2426 : :
2427 : : /*
2428 : : * When DCB/VT is off, maximum number of queues changes,
2429 : : * except for 82598EB, which remains constant.
2430 : : */
2431 [ # # ]: 0 : if (dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_NONE &&
2432 [ # # ]: 0 : hw->mac.type != ixgbe_mac_82598EB) {
2433 [ # # ]: 0 : if (nb_tx_q > IXGBE_NONE_MODE_TX_NB_QUEUES) {
2434 : 0 : PMD_INIT_LOG(ERR,
2435 : : "Neither VT nor DCB are enabled, "
2436 : : "nb_tx_q > %d.",
2437 : : IXGBE_NONE_MODE_TX_NB_QUEUES);
2438 : 0 : return -EINVAL;
2439 : : }
2440 : : }
2441 : : }
2442 : : return 0;
2443 : : }
2444 : :
2445 : : static int
2446 : 0 : ixgbe_dev_configure(struct rte_eth_dev *dev)
2447 : : {
2448 : : struct ixgbe_interrupt *intr =
2449 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2450 : : struct ixgbe_adapter *adapter = dev->data->dev_private;
2451 : : int ret;
2452 : :
2453 : 0 : PMD_INIT_FUNC_TRACE();
2454 : :
2455 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
2456 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
2457 : :
2458 : : /* multiple queue mode checking */
2459 : 0 : ret = ixgbe_check_mq_mode(dev);
2460 [ # # ]: 0 : if (ret != 0) {
2461 : 0 : PMD_DRV_LOG(ERR, "ixgbe_check_mq_mode fails with %d.",
2462 : : ret);
2463 : 0 : return ret;
2464 : : }
2465 : :
2466 : : /* set flag to update link status after init */
2467 : 0 : intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2468 : :
2469 : : /*
2470 : : * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
2471 : : * allocation or vector Rx preconditions we will reset it.
2472 : : */
2473 : 0 : adapter->rx_bulk_alloc_allowed = true;
2474 : 0 : adapter->rx_vec_allowed = true;
2475 : :
2476 : 0 : return 0;
2477 : : }
2478 : :
2479 : : static void
2480 : 0 : ixgbe_dev_phy_intr_setup(struct rte_eth_dev *dev)
2481 : : {
2482 : : struct ixgbe_hw *hw =
2483 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2484 : : struct ixgbe_interrupt *intr =
2485 : : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2486 : : uint32_t gpie;
2487 : :
2488 : : /* only set up it on X550EM_X */
2489 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_X550EM_x) {
2490 : 0 : gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2491 : 0 : gpie |= IXGBE_SDP0_GPIEN_X550EM_x;
2492 : 0 : IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2493 [ # # ]: 0 : if (hw->phy.type == ixgbe_phy_x550em_ext_t)
2494 : 0 : intr->mask |= IXGBE_EICR_GPI_SDP0_X550EM_x;
2495 : : }
2496 : 0 : }
2497 : :
2498 : : int
2499 : 0 : ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
2500 : : uint32_t tx_rate, uint64_t q_msk)
2501 : : {
2502 : : struct ixgbe_hw *hw;
2503 : : struct ixgbe_vf_info *vfinfo;
2504 : : struct rte_eth_link link;
2505 : : uint8_t nb_q_per_pool;
2506 : : uint32_t queue_stride;
2507 : : uint32_t queue_idx, idx = 0, vf_idx;
2508 : : uint32_t queue_end;
2509 : : uint16_t total_rate = 0;
2510 : : struct rte_pci_device *pci_dev;
2511 : : int ret;
2512 : :
2513 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2514 : 0 : ret = rte_eth_link_get_nowait(dev->data->port_id, &link);
2515 [ # # ]: 0 : if (ret < 0)
2516 : : return ret;
2517 : :
2518 [ # # ]: 0 : if (vf >= pci_dev->max_vfs)
2519 : : return -EINVAL;
2520 : :
2521 [ # # ]: 0 : if (tx_rate > link.link_speed)
2522 : : return -EINVAL;
2523 : :
2524 [ # # ]: 0 : if (q_msk == 0)
2525 : : return 0;
2526 : :
2527 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2528 : 0 : vfinfo = *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
2529 : 0 : nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
2530 : 0 : queue_stride = IXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
2531 : 0 : queue_idx = vf * queue_stride;
2532 : 0 : queue_end = queue_idx + nb_q_per_pool - 1;
2533 [ # # ]: 0 : if (queue_end >= hw->mac.max_tx_queues)
2534 : : return -EINVAL;
2535 : :
2536 [ # # ]: 0 : if (vfinfo) {
2537 [ # # ]: 0 : for (vf_idx = 0; vf_idx < pci_dev->max_vfs; vf_idx++) {
2538 [ # # ]: 0 : if (vf_idx == vf)
2539 : 0 : continue;
2540 [ # # ]: 0 : for (idx = 0; idx < RTE_DIM(vfinfo[vf_idx].tx_rate);
2541 : 0 : idx++)
2542 : 0 : total_rate += vfinfo[vf_idx].tx_rate[idx];
2543 : : }
2544 : : } else {
2545 : : return -EINVAL;
2546 : : }
2547 : :
2548 : : /* Store tx_rate for this vf. */
2549 [ # # ]: 0 : for (idx = 0; idx < nb_q_per_pool; idx++) {
2550 [ # # ]: 0 : if (((uint64_t)0x1 << idx) & q_msk) {
2551 [ # # ]: 0 : if (vfinfo[vf].tx_rate[idx] != tx_rate)
2552 : 0 : vfinfo[vf].tx_rate[idx] = tx_rate;
2553 : 0 : total_rate += tx_rate;
2554 : : }
2555 : : }
2556 : :
2557 [ # # ]: 0 : if (total_rate > dev->data->dev_link.link_speed) {
2558 : : /* Reset stored TX rate of the VF if it causes exceed
2559 : : * link speed.
2560 : : */
2561 : 0 : memset(vfinfo[vf].tx_rate, 0, sizeof(vfinfo[vf].tx_rate));
2562 : 0 : return -EINVAL;
2563 : : }
2564 : :
2565 : : /* Set RTTBCNRC of each queue/pool for vf X */
2566 [ # # ]: 0 : for (; queue_idx <= queue_end; queue_idx++) {
2567 [ # # ]: 0 : if (0x1 & q_msk)
2568 : 0 : ixgbe_set_queue_rate_limit(dev, queue_idx, tx_rate);
2569 : 0 : q_msk = q_msk >> 1;
2570 : : }
2571 : :
2572 : : return 0;
2573 : : }
2574 : :
2575 : : static int
2576 : 0 : ixgbe_flow_ctrl_enable(struct rte_eth_dev *dev, struct ixgbe_hw *hw)
2577 : : {
2578 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
2579 : : int err;
2580 : : uint32_t mflcn;
2581 : :
2582 : 0 : ixgbe_setup_fc(hw);
2583 : :
2584 : 0 : err = ixgbe_fc_enable(hw);
2585 : :
2586 : : /* Not negotiated is not an error case */
2587 [ # # ]: 0 : if (err == IXGBE_SUCCESS || err == IXGBE_ERR_FC_NOT_NEGOTIATED) {
2588 : : /*
2589 : : *check if we want to forward MAC frames - driver doesn't
2590 : : *have native capability to do that,
2591 : : *so we'll write the registers ourselves
2592 : : */
2593 : :
2594 : 0 : mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2595 : :
2596 : : /* set or clear MFLCN.PMCF bit depending on configuration */
2597 [ # # ]: 0 : if (adapter->mac_ctrl_frame_fwd != 0)
2598 : 0 : mflcn |= IXGBE_MFLCN_PMCF;
2599 : : else
2600 : 0 : mflcn &= ~IXGBE_MFLCN_PMCF;
2601 : :
2602 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn);
2603 : 0 : IXGBE_WRITE_FLUSH(hw);
2604 : :
2605 : 0 : return 0;
2606 : : }
2607 : : return err;
2608 : : }
2609 : :
2610 : : /*
2611 : : * Configure device link speed and setup link.
2612 : : * It returns 0 on success.
2613 : : */
2614 : : static int
2615 : 0 : ixgbe_dev_start(struct rte_eth_dev *dev)
2616 : : {
2617 : 0 : struct ixgbe_hw *hw =
2618 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2619 : 0 : struct ixgbe_vf_info *vfinfo =
2620 : : *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
2621 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2622 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2623 : : uint32_t intr_vector = 0;
2624 : : int err;
2625 : 0 : bool link_up = false, negotiate = 0;
2626 : 0 : uint32_t speed = 0;
2627 : : uint32_t allowed_speeds = 0;
2628 : : int mask = 0;
2629 : : int status;
2630 : : uint16_t vf, idx;
2631 : : uint32_t *link_speeds;
2632 : : struct ixgbe_tm_conf *tm_conf =
2633 : : IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
2634 : 0 : struct ixgbe_macsec_setting *macsec_setting =
2635 : : IXGBE_DEV_PRIVATE_TO_MACSEC_SETTING(dev->data->dev_private);
2636 : :
2637 : : /*
2638 : : * This function calls into the base driver, which in turn will use
2639 : : * function pointers, which are not guaranteed to be valid in secondary
2640 : : * processes, so avoid using this function in secondary processes.
2641 : : */
2642 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2643 : : return -E_RTE_SECONDARY;
2644 : :
2645 : 0 : PMD_INIT_FUNC_TRACE();
2646 : :
2647 : : /* Stop the link setup handler before resetting the HW. */
2648 : 0 : ixgbe_dev_wait_setup_link_complete(dev, 0);
2649 : :
2650 : : /* disable uio/vfio intr/eventfd mapping */
2651 : 0 : rte_intr_disable(intr_handle);
2652 : :
2653 : : /* stop adapter */
2654 : 0 : hw->adapter_stopped = 0;
2655 : 0 : ixgbe_stop_adapter(hw);
2656 : :
2657 : : /* reinitialize adapter
2658 : : * this calls reset and start
2659 : : */
2660 : 0 : status = ixgbe_pf_reset_hw(hw);
2661 [ # # ]: 0 : if (status != 0)
2662 : : return -1;
2663 : 0 : hw->mac.ops.start_hw(hw);
2664 : 0 : hw->mac.get_link_status = true;
2665 : :
2666 : : /* configure PF module if SRIOV enabled */
2667 : 0 : ixgbe_pf_host_configure(dev);
2668 : :
2669 : 0 : ixgbe_dev_phy_intr_setup(dev);
2670 : :
2671 : : /* check and configure queue intr-vector mapping */
2672 [ # # ]: 0 : if ((rte_intr_cap_multiple(intr_handle) ||
2673 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active) &&
2674 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq != 0) {
2675 : 0 : intr_vector = dev->data->nb_rx_queues;
2676 [ # # ]: 0 : if (intr_vector > IXGBE_MAX_INTR_QUEUE_NUM) {
2677 : 0 : PMD_INIT_LOG(ERR, "At most %d intr queues supported",
2678 : : IXGBE_MAX_INTR_QUEUE_NUM);
2679 : 0 : return -ENOTSUP;
2680 : : }
2681 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector))
2682 : : return -1;
2683 : : }
2684 : :
2685 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2686 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
2687 : 0 : dev->data->nb_rx_queues)) {
2688 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
2689 : : " intr_vec", dev->data->nb_rx_queues);
2690 : 0 : return -ENOMEM;
2691 : : }
2692 : : }
2693 : :
2694 : : /* configure MSI-X for sleep until Rx interrupt */
2695 : 0 : ixgbe_configure_msix(dev);
2696 : :
2697 : : /* initialize transmission unit */
2698 : 0 : ixgbe_dev_tx_init(dev);
2699 : :
2700 : : /* This can fail when allocating mbufs for descriptor rings */
2701 : 0 : err = ixgbe_dev_rx_init(dev);
2702 [ # # ]: 0 : if (err) {
2703 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
2704 : 0 : goto error;
2705 : : }
2706 : :
2707 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
2708 : : RTE_ETH_VLAN_EXTEND_MASK;
2709 : 0 : err = ixgbe_vlan_offload_config(dev, mask);
2710 [ # # ]: 0 : if (err) {
2711 : 0 : PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
2712 : 0 : goto error;
2713 : : }
2714 : :
2715 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_VMDQ_ONLY) {
2716 : : /* Enable vlan filtering for VMDq */
2717 : : ixgbe_vmdq_vlan_hw_filter_enable(dev);
2718 : : }
2719 : :
2720 : : /* Configure DCB hw */
2721 : 0 : ixgbe_configure_dcb(dev);
2722 : :
2723 [ # # ]: 0 : if (IXGBE_DEV_FDIR_CONF(dev)->mode != RTE_FDIR_MODE_NONE) {
2724 : 0 : err = ixgbe_fdir_configure(dev);
2725 [ # # ]: 0 : if (err)
2726 : 0 : goto error;
2727 : : }
2728 : :
2729 : : /* Restore vf rate limit */
2730 [ # # ]: 0 : if (vfinfo != NULL) {
2731 [ # # ]: 0 : for (vf = 0; vf < pci_dev->max_vfs; vf++)
2732 [ # # ]: 0 : for (idx = 0; idx < IXGBE_MAX_QUEUE_NUM_PER_VF; idx++)
2733 [ # # ]: 0 : if (vfinfo[vf].tx_rate[idx] != 0)
2734 : 0 : ixgbe_set_vf_rate_limit(
2735 : : dev, vf,
2736 : : vfinfo[vf].tx_rate[idx],
2737 : : RTE_BIT64(idx));
2738 : : }
2739 : :
2740 : 0 : ixgbe_restore_statistics_mapping(dev);
2741 : :
2742 : 0 : err = ixgbe_flow_ctrl_enable(dev, hw);
2743 [ # # ]: 0 : if (err < 0) {
2744 : 0 : PMD_INIT_LOG(ERR, "enable flow ctrl err");
2745 : 0 : goto error;
2746 : : }
2747 : :
2748 : 0 : err = ixgbe_dev_rxtx_start(dev);
2749 [ # # ]: 0 : if (err < 0) {
2750 : 0 : PMD_INIT_LOG(ERR, "Unable to start rxtx queues");
2751 : 0 : goto error;
2752 : : }
2753 : :
2754 : : /* Skip link setup if loopback mode is enabled. */
2755 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode != 0) {
2756 : 0 : err = ixgbe_check_supported_loopback_mode(dev);
2757 [ # # ]: 0 : if (err < 0) {
2758 : 0 : PMD_INIT_LOG(ERR, "Unsupported loopback mode");
2759 : 0 : goto error;
2760 : : } else {
2761 : 0 : goto skip_link_setup;
2762 : : }
2763 : : }
2764 : :
2765 [ # # # # ]: 0 : if (ixgbe_is_sfp(hw) && hw->phy.multispeed_fiber) {
2766 : 0 : err = hw->mac.ops.setup_sfp(hw);
2767 [ # # ]: 0 : if (err)
2768 : 0 : goto error;
2769 : : }
2770 : :
2771 [ # # ]: 0 : if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
2772 : : /* Turn on the copper */
2773 : 0 : ixgbe_set_phy_power(hw, true);
2774 : : } else {
2775 : : /* Turn on the laser */
2776 : 0 : ixgbe_enable_tx_laser(hw);
2777 : : }
2778 : :
2779 : 0 : err = ixgbe_check_link(hw, &speed, &link_up, 0);
2780 [ # # ]: 0 : if (err)
2781 : 0 : goto error;
2782 : 0 : dev->data->dev_link.link_status = link_up;
2783 : :
2784 : 0 : err = ixgbe_get_link_capabilities(hw, &speed, &negotiate);
2785 [ # # ]: 0 : if (err)
2786 : 0 : goto error;
2787 : :
2788 [ # # ]: 0 : switch (hw->mac.type) {
2789 : 0 : case ixgbe_mac_X550:
2790 : : case ixgbe_mac_X550EM_x:
2791 : : case ixgbe_mac_X550EM_a:
2792 : : allowed_speeds = RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_1G |
2793 : : RTE_ETH_LINK_SPEED_2_5G | RTE_ETH_LINK_SPEED_5G |
2794 : : RTE_ETH_LINK_SPEED_10G;
2795 [ # # ]: 0 : if (hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T ||
2796 : : hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T_L)
2797 : : allowed_speeds = RTE_ETH_LINK_SPEED_10M |
2798 : : RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_1G;
2799 : : break;
2800 : : default:
2801 : : allowed_speeds = RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_1G |
2802 : : RTE_ETH_LINK_SPEED_10G;
2803 : : }
2804 : :
2805 : 0 : link_speeds = &dev->data->dev_conf.link_speeds;
2806 : :
2807 : : /* Ignore autoneg flag bit and check the validity ofÂ
2808 : : * link_speedÂ
2809 : : */
2810 [ # # ]: 0 : if (((*link_speeds) >> 1) & ~(allowed_speeds >> 1)) {
2811 : 0 : PMD_INIT_LOG(ERR, "Invalid link setting");
2812 : 0 : goto error;
2813 : : }
2814 : :
2815 : 0 : speed = 0x0;
2816 [ # # ]: 0 : if (*link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
2817 [ # # # # ]: 0 : switch (hw->mac.type) {
2818 : 0 : case ixgbe_mac_82598EB:
2819 : 0 : speed = IXGBE_LINK_SPEED_82598_AUTONEG;
2820 : 0 : break;
2821 : 0 : case ixgbe_mac_82599EB:
2822 : : case ixgbe_mac_X540:
2823 : 0 : speed = IXGBE_LINK_SPEED_82599_AUTONEG;
2824 : 0 : break;
2825 : 0 : case ixgbe_mac_X550:
2826 : : case ixgbe_mac_X550EM_x:
2827 : : case ixgbe_mac_X550EM_a:
2828 : 0 : speed = IXGBE_LINK_SPEED_X550_AUTONEG;
2829 : 0 : break;
2830 : 0 : default:
2831 : 0 : speed = IXGBE_LINK_SPEED_82599_AUTONEG;
2832 : : }
2833 : : } else {
2834 [ # # ]: 0 : if (*link_speeds & RTE_ETH_LINK_SPEED_10G)
2835 : 0 : speed |= IXGBE_LINK_SPEED_10GB_FULL;
2836 [ # # ]: 0 : if (*link_speeds & RTE_ETH_LINK_SPEED_5G)
2837 : 0 : speed |= IXGBE_LINK_SPEED_5GB_FULL;
2838 [ # # ]: 0 : if (*link_speeds & RTE_ETH_LINK_SPEED_2_5G)
2839 : 0 : speed |= IXGBE_LINK_SPEED_2_5GB_FULL;
2840 [ # # ]: 0 : if (*link_speeds & RTE_ETH_LINK_SPEED_1G)
2841 : 0 : speed |= IXGBE_LINK_SPEED_1GB_FULL;
2842 [ # # ]: 0 : if (*link_speeds & RTE_ETH_LINK_SPEED_100M)
2843 : 0 : speed |= IXGBE_LINK_SPEED_100_FULL;
2844 [ # # ]: 0 : if (*link_speeds & RTE_ETH_LINK_SPEED_10M)
2845 : 0 : speed |= IXGBE_LINK_SPEED_10_FULL;
2846 : : }
2847 : :
2848 : 0 : err = ixgbe_setup_link(hw, speed, link_up);
2849 [ # # ]: 0 : if (err)
2850 : 0 : goto error;
2851 : :
2852 : 0 : skip_link_setup:
2853 : :
2854 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
2855 : : /* check if lsc interrupt is enabled */
2856 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
2857 : : ixgbe_dev_lsc_interrupt_setup(dev, TRUE);
2858 : : else
2859 : : ixgbe_dev_lsc_interrupt_setup(dev, FALSE);
2860 : : ixgbe_dev_macsec_interrupt_setup(dev);
2861 : : } else {
2862 : 0 : rte_intr_callback_unregister(intr_handle,
2863 : : ixgbe_dev_interrupt_handler, dev);
2864 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
2865 : 0 : PMD_INIT_LOG(INFO, "lsc won't enable because of"
2866 : : " no intr multiplex");
2867 : : }
2868 : :
2869 : : /* check if rxq interrupt is enabled */
2870 [ # # # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq != 0 &&
2871 : 0 : rte_intr_dp_is_en(intr_handle))
2872 : : ixgbe_dev_rxq_interrupt_setup(dev);
2873 : :
2874 : : /* enable uio/vfio intr/eventfd mapping */
2875 : 0 : rte_intr_enable(intr_handle);
2876 : :
2877 : : /* resume enabled intr since hw reset */
2878 : : ixgbe_enable_intr(dev);
2879 : 0 : ixgbe_l2_tunnel_conf(dev);
2880 : 0 : ixgbe_filter_restore(dev);
2881 : :
2882 [ # # # # ]: 0 : if (tm_conf->root && !tm_conf->committed)
2883 : 0 : PMD_DRV_LOG(WARNING,
2884 : : "please call hierarchy_commit() "
2885 : : "before starting the port");
2886 : :
2887 : : /* wait for the controller to acquire link */
2888 : : err = ixgbe_wait_for_link_up(hw);
2889 : : if (err)
2890 : : goto error;
2891 : :
2892 : : /*
2893 : : * Update link status right before return, because it may
2894 : : * start link configuration process in a separate thread.
2895 : : */
2896 : : ixgbe_dev_link_update(dev, 0);
2897 : :
2898 : : /* setup the macsec setting register */
2899 [ # # ]: 0 : if (macsec_setting->offload_en)
2900 : 0 : ixgbe_dev_macsec_register_enable(dev, macsec_setting);
2901 : :
2902 : : return 0;
2903 : :
2904 : 0 : error:
2905 : 0 : PMD_INIT_LOG(ERR, "failure in ixgbe_dev_start(): %d", err);
2906 : 0 : ixgbe_dev_clear_queues(dev);
2907 : 0 : return -EIO;
2908 : : }
2909 : :
2910 : : /*
2911 : : * Stop device: disable rx and tx functions to allow for reconfiguring.
2912 : : */
2913 : : static int
2914 : 0 : ixgbe_dev_stop(struct rte_eth_dev *dev)
2915 : : {
2916 : : struct rte_eth_link link;
2917 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
2918 : 0 : struct ixgbe_hw *hw =
2919 : : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2920 : 0 : struct ixgbe_vf_info *vfinfo =
2921 : : *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
2922 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2923 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2924 : : int vf;
2925 : : struct ixgbe_tm_conf *tm_conf =
2926 : : IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
2927 : :
2928 [ # # ]: 0 : if (hw->adapter_stopped)
2929 : : return 0;
2930 : :
2931 : 0 : PMD_INIT_FUNC_TRACE();
2932 : :
2933 : : /*
2934 : : * This function calls into the base driver, which in turn will use
2935 : : * function pointers, which are not guaranteed to be valid in secondary
2936 : : * processes, so avoid using this function in secondary processes.
2937 : : */
2938 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2939 : : return -E_RTE_SECONDARY;
2940 : :
2941 : 0 : ixgbe_dev_wait_setup_link_complete(dev, 0);
2942 : :
2943 : : /* disable interrupts */
2944 : 0 : ixgbe_disable_intr(hw);
2945 : :
2946 : : /* reset the NIC */
2947 : 0 : ixgbe_pf_reset_hw(hw);
2948 : 0 : hw->adapter_stopped = 0;
2949 : :
2950 : : /* stop adapter */
2951 : 0 : ixgbe_stop_adapter(hw);
2952 : :
2953 [ # # # # ]: 0 : for (vf = 0; vfinfo != NULL && vf < pci_dev->max_vfs; vf++)
2954 : 0 : vfinfo[vf].clear_to_send = false;
2955 : :
2956 [ # # ]: 0 : if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
2957 : : /* Turn off the copper */
2958 : 0 : ixgbe_set_phy_power(hw, false);
2959 : : } else {
2960 : : /* Turn off the laser */
2961 : 0 : ixgbe_disable_tx_laser(hw);
2962 : : }
2963 : :
2964 : 0 : ixgbe_dev_clear_queues(dev);
2965 : :
2966 : : /* Clear stored conf */
2967 : 0 : dev->data->scattered_rx = 0;
2968 : 0 : dev->data->lro = 0;
2969 : :
2970 : : /* Clear recorded link status */
2971 : : memset(&link, 0, sizeof(link));
2972 : 0 : rte_eth_linkstatus_set(dev, &link);
2973 : :
2974 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2975 : : /* resume to the default handler */
2976 : 0 : rte_intr_callback_register(intr_handle,
2977 : : ixgbe_dev_interrupt_handler,
2978 : : (void *)dev);
2979 : :
2980 : : /* Clean datapath event and queue/vec mapping */
2981 : 0 : rte_intr_efd_disable(intr_handle);
2982 : 0 : rte_intr_vec_list_free(intr_handle);
2983 : :
2984 : : /* reset hierarchy commit */
2985 : 0 : tm_conf->committed = false;
2986 : :
2987 : 0 : adapter->rss_reta_updated = 0;
2988 : :
2989 : 0 : hw->adapter_stopped = true;
2990 : 0 : dev->data->dev_started = 0;
2991 : :
2992 : 0 : return 0;
2993 : : }
2994 : :
2995 : : /*
2996 : : * Set device link up: enable tx.
2997 : : */
2998 : : static int
2999 : 0 : ixgbe_dev_set_link_up(struct rte_eth_dev *dev)
3000 : : {
3001 : 0 : struct ixgbe_hw *hw =
3002 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3003 : :
3004 : : /*
3005 : : * This function calls into the base driver, which in turn will use
3006 : : * function pointers, which are not guaranteed to be valid in secondary
3007 : : * processes, so avoid using this function in secondary processes.
3008 : : */
3009 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3010 : : return -E_RTE_SECONDARY;
3011 : :
3012 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
3013 : : #ifdef RTE_LIBRTE_IXGBE_BYPASS
3014 [ # # ]: 0 : if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
3015 : : /* Not supported in bypass mode */
3016 : 0 : PMD_INIT_LOG(ERR, "Set link up is not supported "
3017 : : "by device id 0x%x", hw->device_id);
3018 : 0 : return -ENOTSUP;
3019 : : }
3020 : : #endif
3021 : : }
3022 : :
3023 [ # # ]: 0 : if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
3024 : : /* Turn on the copper */
3025 : 0 : ixgbe_set_phy_power(hw, true);
3026 : : } else {
3027 : : /* Turn on the laser */
3028 : 0 : ixgbe_enable_tx_laser(hw);
3029 : : ixgbe_dev_link_update(dev, 0);
3030 : : }
3031 : :
3032 : : return 0;
3033 : : }
3034 : :
3035 : : /*
3036 : : * Set device link down: disable tx.
3037 : : */
3038 : : static int
3039 : 0 : ixgbe_dev_set_link_down(struct rte_eth_dev *dev)
3040 : : {
3041 : 0 : struct ixgbe_hw *hw =
3042 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3043 : :
3044 : : /*
3045 : : * This function calls into the base driver, which in turn will use
3046 : : * function pointers, which are not guaranteed to be valid in secondary
3047 : : * processes, so avoid using this function in secondary processes.
3048 : : */
3049 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3050 : : return -E_RTE_SECONDARY;
3051 : :
3052 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82599EB) {
3053 : : #ifdef RTE_LIBRTE_IXGBE_BYPASS
3054 [ # # ]: 0 : if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
3055 : : /* Not supported in bypass mode */
3056 : 0 : PMD_INIT_LOG(ERR, "Set link down is not supported "
3057 : : "by device id 0x%x", hw->device_id);
3058 : 0 : return -ENOTSUP;
3059 : : }
3060 : : #endif
3061 : : }
3062 : :
3063 [ # # ]: 0 : if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
3064 : : /* Turn off the copper */
3065 : 0 : ixgbe_set_phy_power(hw, false);
3066 : : } else {
3067 : : /* Turn off the laser */
3068 : 0 : ixgbe_disable_tx_laser(hw);
3069 : : ixgbe_dev_link_update(dev, 0);
3070 : : }
3071 : :
3072 : : return 0;
3073 : : }
3074 : :
3075 : : /*
3076 : : * Reset and stop device.
3077 : : */
3078 : : static int
3079 : 0 : ixgbe_dev_close(struct rte_eth_dev *dev)
3080 : : {
3081 : 0 : struct ixgbe_hw *hw =
3082 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3083 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3084 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
3085 : : int retries = 0;
3086 : : int ret;
3087 : :
3088 : 0 : PMD_INIT_FUNC_TRACE();
3089 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3090 : : return 0;
3091 : :
3092 : 0 : ixgbe_pf_reset_hw(hw);
3093 : :
3094 : 0 : ret = ixgbe_dev_stop(dev);
3095 : :
3096 : 0 : ixgbe_dev_free_queues(dev);
3097 : :
3098 : 0 : ixgbe_disable_pcie_primary(hw);
3099 : :
3100 : : /* reprogram the RAR[0] in case user changed it. */
3101 : 0 : ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
3102 : :
3103 : : /* Unlock any pending hardware semaphore */
3104 : 0 : ixgbe_swfw_lock_reset(hw);
3105 : :
3106 : : /* disable uio intr before callback unregister */
3107 : 0 : rte_intr_disable(intr_handle);
3108 : :
3109 : : do {
3110 : 0 : ret = rte_intr_callback_unregister(intr_handle,
3111 : : ixgbe_dev_interrupt_handler, dev);
3112 [ # # ]: 0 : if (ret >= 0 || ret == -ENOENT) {
3113 : : break;
3114 [ # # ]: 0 : } else if (ret != -EAGAIN) {
3115 : 0 : PMD_INIT_LOG(ERR,
3116 : : "intr callback unregister failed: %d",
3117 : : ret);
3118 : : }
3119 : : rte_delay_ms(100);
3120 [ # # ]: 0 : } while (retries++ < (10 + IXGBE_LINK_UP_TIME));
3121 : :
3122 : : /* cancel the delay handler before remove dev */
3123 : 0 : rte_eal_alarm_cancel(ixgbe_dev_interrupt_delayed_handler, dev);
3124 : :
3125 : : /* uninitialize PF if max_vfs not zero */
3126 : 0 : ixgbe_pf_host_uninit(dev);
3127 : :
3128 : : /* remove all the fdir filters & hash */
3129 : 0 : ixgbe_fdir_filter_uninit(dev);
3130 : :
3131 : : /* remove all the L2 tunnel filters & hash */
3132 : 0 : ixgbe_l2_tn_filter_uninit(dev);
3133 : :
3134 : : /* Remove all ntuple filters of the device */
3135 : 0 : ixgbe_ntuple_filter_uninit(dev);
3136 : :
3137 : : /* clear all the filters list */
3138 : 0 : ixgbe_filterlist_flush();
3139 : :
3140 : : /* Remove all Traffic Manager configuration */
3141 : 0 : ixgbe_tm_conf_uninit(dev);
3142 : :
3143 : : #ifdef RTE_LIB_SECURITY
3144 : 0 : rte_free(dev->security_ctx);
3145 : 0 : dev->security_ctx = NULL;
3146 : : #endif
3147 : :
3148 : 0 : return ret;
3149 : : }
3150 : :
3151 : : /*
3152 : : * Reset PF device.
3153 : : */
3154 : : static int
3155 : 0 : ixgbe_dev_reset(struct rte_eth_dev *dev)
3156 : : {
3157 : : int ret;
3158 : :
3159 : : /* When a DPDK PMD PF begin to reset PF port, it should notify all
3160 : : * its VF to make them align with it. The detailed notification
3161 : : * mechanism is PMD specific. As to ixgbe PF, it is rather complex.
3162 : : * To avoid unexpected behavior in VF, currently reset of PF with
3163 : : * SR-IOV activation is not supported. It might be supported later.
3164 : : */
3165 [ # # ]: 0 : if (dev->data->sriov.active)
3166 : : return -ENOTSUP;
3167 : :
3168 : 0 : ret = eth_ixgbe_dev_uninit(dev);
3169 [ # # ]: 0 : if (ret)
3170 : : return ret;
3171 : :
3172 : 0 : ret = eth_ixgbe_dev_init(dev, NULL);
3173 : :
3174 : 0 : return ret;
3175 : : }
3176 : :
3177 : : static void
3178 : 0 : ixgbe_read_stats_registers(struct ixgbe_hw *hw,
3179 : : struct ixgbe_hw_stats *hw_stats,
3180 : : struct ixgbe_macsec_stats *macsec_stats,
3181 : : uint64_t *total_missed_rx, uint64_t *total_qbrc,
3182 : : uint64_t *total_qprc, uint64_t *total_qprdc)
3183 : : {
3184 : : uint32_t bprc, lxon, lxoff, total;
3185 : : uint32_t delta_gprc = 0;
3186 : : unsigned i;
3187 : : /* Workaround for RX byte count not including CRC bytes when CRC
3188 : : * strip is enabled. CRC bytes are removed from counters when crc_strip
3189 : : * is disabled.
3190 : : */
3191 : 0 : int crc_strip = (IXGBE_READ_REG(hw, IXGBE_HLREG0) &
3192 : : IXGBE_HLREG0_RXCRCSTRP);
3193 : :
3194 : 0 : hw_stats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
3195 : 0 : hw_stats->illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC);
3196 : 0 : hw_stats->errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC);
3197 : 0 : hw_stats->mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC);
3198 : :
3199 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3200 : 0 : uint32_t mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3201 : :
3202 : : /* global total per queue */
3203 : 0 : hw_stats->mpc[i] += mp;
3204 : : /* Running comprehensive total for stats display */
3205 : 0 : *total_missed_rx += hw_stats->mpc[i];
3206 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB) {
3207 : 0 : hw_stats->rnbc[i] +=
3208 : 0 : IXGBE_READ_REG(hw, IXGBE_RNBC(i));
3209 : 0 : hw_stats->pxonrxc[i] +=
3210 : 0 : IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
3211 : 0 : hw_stats->pxoffrxc[i] +=
3212 : 0 : IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
3213 : : } else {
3214 : 0 : hw_stats->pxonrxc[i] +=
3215 : 0 : IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
3216 : 0 : hw_stats->pxoffrxc[i] +=
3217 : 0 : IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
3218 : 0 : hw_stats->pxon2offc[i] +=
3219 : 0 : IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
3220 : : }
3221 : 0 : hw_stats->pxontxc[i] +=
3222 : 0 : IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
3223 : 0 : hw_stats->pxofftxc[i] +=
3224 : 0 : IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
3225 : : }
3226 [ # # ]: 0 : for (i = 0; i < IXGBE_QUEUE_STAT_COUNTERS; i++) {
3227 : 0 : uint32_t delta_qprc = IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3228 : 0 : uint32_t delta_qptc = IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3229 : 0 : uint32_t delta_qprdc = IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
3230 : :
3231 : 0 : delta_gprc += delta_qprc;
3232 : :
3233 : 0 : hw_stats->qprc[i] += delta_qprc;
3234 : 0 : hw_stats->qptc[i] += delta_qptc;
3235 : :
3236 : 0 : hw_stats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
3237 : 0 : hw_stats->qbrc[i] +=
3238 : 0 : ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)) << 32);
3239 [ # # ]: 0 : if (crc_strip == 0)
3240 : 0 : hw_stats->qbrc[i] -= delta_qprc * RTE_ETHER_CRC_LEN;
3241 : :
3242 : 0 : hw_stats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
3243 : 0 : hw_stats->qbtc[i] +=
3244 : 0 : ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)) << 32);
3245 : :
3246 : 0 : hw_stats->qprdc[i] += delta_qprdc;
3247 : 0 : *total_qprdc += hw_stats->qprdc[i];
3248 : :
3249 : 0 : *total_qprc += hw_stats->qprc[i];
3250 : 0 : *total_qbrc += hw_stats->qbrc[i];
3251 : : }
3252 : 0 : hw_stats->mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC);
3253 : 0 : hw_stats->mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC);
3254 : 0 : hw_stats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
3255 : :
3256 : : /*
3257 : : * An errata states that gprc actually counts good + missed packets:
3258 : : * Workaround to set gprc to summated queue packet receives
3259 : : */
3260 : 0 : hw_stats->gprc = *total_qprc;
3261 : :
3262 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
3263 : 0 : hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
3264 : 0 : hw_stats->gorc += ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32);
3265 : 0 : hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
3266 : 0 : hw_stats->gotc += ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32);
3267 : 0 : hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
3268 : 0 : hw_stats->tor += ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32);
3269 : 0 : hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
3270 : 0 : hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
3271 : : } else {
3272 : 0 : hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
3273 : 0 : hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
3274 : : /* 82598 only has a counter in the high register */
3275 : 0 : hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
3276 : 0 : hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3277 : 0 : hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
3278 : : }
3279 : 0 : uint64_t old_tpr = hw_stats->tpr;
3280 : :
3281 : 0 : hw_stats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3282 : 0 : hw_stats->tpt += IXGBE_READ_REG(hw, IXGBE_TPT);
3283 : :
3284 [ # # ]: 0 : if (crc_strip == 0)
3285 : 0 : hw_stats->gorc -= delta_gprc * RTE_ETHER_CRC_LEN;
3286 : :
3287 : 0 : uint64_t delta_gptc = IXGBE_READ_REG(hw, IXGBE_GPTC);
3288 : 0 : hw_stats->gptc += delta_gptc;
3289 : 0 : hw_stats->gotc -= delta_gptc * RTE_ETHER_CRC_LEN;
3290 : 0 : hw_stats->tor -= (hw_stats->tpr - old_tpr) * RTE_ETHER_CRC_LEN;
3291 : :
3292 : : /*
3293 : : * Workaround: mprc hardware is incorrectly counting
3294 : : * broadcasts, so for now we subtract those.
3295 : : */
3296 : 0 : bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3297 : 0 : hw_stats->bprc += bprc;
3298 : 0 : hw_stats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
3299 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
3300 : 0 : hw_stats->mprc -= bprc;
3301 : :
3302 : 0 : hw_stats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3303 : 0 : hw_stats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3304 : 0 : hw_stats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3305 : 0 : hw_stats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3306 : 0 : hw_stats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3307 : 0 : hw_stats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
3308 : :
3309 : 0 : lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3310 : 0 : hw_stats->lxontxc += lxon;
3311 : 0 : lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3312 : 0 : hw_stats->lxofftxc += lxoff;
3313 : 0 : total = lxon + lxoff;
3314 : :
3315 : 0 : hw_stats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3316 : 0 : hw_stats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
3317 : 0 : hw_stats->gptc -= total;
3318 : 0 : hw_stats->mptc -= total;
3319 : 0 : hw_stats->ptc64 -= total;
3320 : 0 : hw_stats->gotc -= total * RTE_ETHER_MIN_LEN;
3321 : :
3322 : 0 : hw_stats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3323 : 0 : hw_stats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3324 : 0 : hw_stats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3325 : 0 : hw_stats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
3326 : 0 : hw_stats->mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC);
3327 : 0 : hw_stats->mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC);
3328 : 0 : hw_stats->mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC);
3329 : 0 : hw_stats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3330 : 0 : hw_stats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3331 : 0 : hw_stats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3332 : 0 : hw_stats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3333 : 0 : hw_stats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
3334 : 0 : hw_stats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3335 : 0 : hw_stats->xec += IXGBE_READ_REG(hw, IXGBE_XEC);
3336 : 0 : hw_stats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
3337 : 0 : hw_stats->fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
3338 : : /* Only read FCOE on 82599 */
3339 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
3340 : 0 : hw_stats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
3341 : 0 : hw_stats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
3342 : 0 : hw_stats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
3343 : 0 : hw_stats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
3344 : 0 : hw_stats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
3345 : : }
3346 : :
3347 : : /* Flow Director Stats registers */
3348 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
3349 : 0 : hw_stats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
3350 : 0 : hw_stats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
3351 : 0 : hw_stats->fdirustat_add += IXGBE_READ_REG(hw,
3352 : 0 : IXGBE_FDIRUSTAT) & 0xFFFF;
3353 : 0 : hw_stats->fdirustat_remove += (IXGBE_READ_REG(hw,
3354 : 0 : IXGBE_FDIRUSTAT) >> 16) & 0xFFFF;
3355 : 0 : hw_stats->fdirfstat_fadd += IXGBE_READ_REG(hw,
3356 : 0 : IXGBE_FDIRFSTAT) & 0xFFFF;
3357 : 0 : hw_stats->fdirfstat_fremove += (IXGBE_READ_REG(hw,
3358 : 0 : IXGBE_FDIRFSTAT) >> 16) & 0xFFFF;
3359 : : }
3360 : : /* MACsec Stats registers */
3361 : 0 : macsec_stats->out_pkts_untagged += IXGBE_READ_REG(hw, IXGBE_LSECTXUT);
3362 : 0 : macsec_stats->out_pkts_encrypted +=
3363 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECTXPKTE);
3364 : 0 : macsec_stats->out_pkts_protected +=
3365 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECTXPKTP);
3366 : 0 : macsec_stats->out_octets_encrypted +=
3367 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECTXOCTE);
3368 : 0 : macsec_stats->out_octets_protected +=
3369 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECTXOCTP);
3370 : 0 : macsec_stats->in_pkts_untagged += IXGBE_READ_REG(hw, IXGBE_LSECRXUT);
3371 : 0 : macsec_stats->in_pkts_badtag += IXGBE_READ_REG(hw, IXGBE_LSECRXBAD);
3372 : 0 : macsec_stats->in_pkts_nosci += IXGBE_READ_REG(hw, IXGBE_LSECRXNOSCI);
3373 : 0 : macsec_stats->in_pkts_unknownsci +=
3374 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECRXUNSCI);
3375 : 0 : macsec_stats->in_octets_decrypted +=
3376 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECRXOCTD);
3377 : 0 : macsec_stats->in_octets_validated +=
3378 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECRXOCTV);
3379 : 0 : macsec_stats->in_pkts_unchecked += IXGBE_READ_REG(hw, IXGBE_LSECRXUNCH);
3380 : 0 : macsec_stats->in_pkts_delayed += IXGBE_READ_REG(hw, IXGBE_LSECRXDELAY);
3381 : 0 : macsec_stats->in_pkts_late += IXGBE_READ_REG(hw, IXGBE_LSECRXLATE);
3382 [ # # ]: 0 : for (i = 0; i < 2; i++) {
3383 : 0 : macsec_stats->in_pkts_ok +=
3384 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECRXOK(i));
3385 : 0 : macsec_stats->in_pkts_invalid +=
3386 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECRXINV(i));
3387 : 0 : macsec_stats->in_pkts_notvalid +=
3388 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECRXNV(i));
3389 : : }
3390 : 0 : macsec_stats->in_pkts_unusedsa += IXGBE_READ_REG(hw, IXGBE_LSECRXUNSA);
3391 : 0 : macsec_stats->in_pkts_notusingsa +=
3392 : 0 : IXGBE_READ_REG(hw, IXGBE_LSECRXNUSA);
3393 : 0 : }
3394 : :
3395 : : /*
3396 : : * This function is based on ixgbe_update_stats_counters() in ixgbe/ixgbe.c
3397 : : */
3398 : : static int
3399 : 0 : ixgbe_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
3400 : : {
3401 : 0 : struct ixgbe_hw *hw =
3402 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3403 : 0 : struct ixgbe_hw_stats *hw_stats =
3404 : : IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3405 : 0 : struct ixgbe_macsec_stats *macsec_stats =
3406 : : IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
3407 : : dev->data->dev_private);
3408 : : uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
3409 : : unsigned i;
3410 : :
3411 : 0 : total_missed_rx = 0;
3412 : 0 : total_qbrc = 0;
3413 : 0 : total_qprc = 0;
3414 : 0 : total_qprdc = 0;
3415 : :
3416 : 0 : ixgbe_read_stats_registers(hw, hw_stats, macsec_stats, &total_missed_rx,
3417 : : &total_qbrc, &total_qprc, &total_qprdc);
3418 : :
3419 [ # # ]: 0 : if (stats == NULL)
3420 : : return -EINVAL;
3421 : :
3422 : : /* Fill out the rte_eth_stats statistics structure */
3423 : 0 : stats->ipackets = total_qprc;
3424 : 0 : stats->ibytes = total_qbrc;
3425 : 0 : stats->opackets = hw_stats->gptc;
3426 : 0 : stats->obytes = hw_stats->gotc;
3427 : :
3428 [ # # ]: 0 : for (i = 0; i < RTE_MIN_T(IXGBE_QUEUE_STAT_COUNTERS,
3429 : 0 : RTE_ETHDEV_QUEUE_STAT_CNTRS, typeof(i)); i++) {
3430 : 0 : stats->q_ipackets[i] = hw_stats->qprc[i];
3431 : 0 : stats->q_opackets[i] = hw_stats->qptc[i];
3432 : 0 : stats->q_ibytes[i] = hw_stats->qbrc[i];
3433 : 0 : stats->q_obytes[i] = hw_stats->qbtc[i];
3434 : 0 : stats->q_errors[i] = hw_stats->qprdc[i];
3435 : : }
3436 : :
3437 : : /* Rx Errors */
3438 : 0 : stats->imissed = total_missed_rx;
3439 : 0 : stats->ierrors = hw_stats->crcerrs +
3440 : 0 : hw_stats->mspdc +
3441 : 0 : hw_stats->rlec +
3442 : 0 : hw_stats->ruc +
3443 : 0 : hw_stats->roc +
3444 : 0 : hw_stats->illerrc +
3445 : 0 : hw_stats->errbc +
3446 : 0 : hw_stats->rfc +
3447 : 0 : hw_stats->fccrc +
3448 : 0 : hw_stats->fclast;
3449 : :
3450 : : /*
3451 : : * 82599 errata, UDP frames with a 0 checksum can be marked as checksum
3452 : : * errors.
3453 : : */
3454 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82599EB)
3455 : 0 : stats->ierrors += hw_stats->xec;
3456 : :
3457 : : /* Tx Errors */
3458 : 0 : stats->oerrors = 0;
3459 : 0 : return 0;
3460 : : }
3461 : :
3462 : : static int
3463 : 0 : ixgbe_dev_stats_reset(struct rte_eth_dev *dev)
3464 : : {
3465 : 0 : struct ixgbe_hw_stats *stats =
3466 : 0 : IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3467 : :
3468 : : /* HW registers are cleared on read */
3469 : 0 : ixgbe_dev_stats_get(dev, NULL);
3470 : :
3471 : : /* Reset software totals */
3472 : : memset(stats, 0, sizeof(*stats));
3473 : :
3474 : 0 : return 0;
3475 : : }
3476 : :
3477 : : /* This function calculates the number of xstats based on the current config */
3478 : :
3479 : : #define IXGBE_XSTATS_CALC_NUM \
3480 : : (IXGBE_NB_HW_STATS + IXGBE_NB_MACSEC_STATS + \
3481 : : (IXGBE_NB_RXQ_PRIO_STATS * IXGBE_NB_RXQ_PRIO_VALUES) + \
3482 : : (IXGBE_NB_TXQ_PRIO_STATS * IXGBE_NB_TXQ_PRIO_VALUES))
3483 : :
3484 : : static unsigned
3485 : : ixgbe_xstats_calc_num(void)
3486 : : {
3487 : : return IXGBE_XSTATS_CALC_NUM;
3488 : : }
3489 : :
3490 : 0 : static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3491 : : struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned int size)
3492 : : {
3493 : : const unsigned cnt_stats = ixgbe_xstats_calc_num();
3494 : : unsigned stat, i, count;
3495 : :
3496 [ # # ]: 0 : if (xstats_names != NULL) {
3497 : : count = 0;
3498 : :
3499 : : /* Note: limit >= cnt_stats checked upstream
3500 : : * in rte_eth_xstats_names()
3501 : : */
3502 : :
3503 : : /* Extended stats from ixgbe_hw_stats */
3504 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
3505 : 0 : strlcpy(xstats_names[count].name,
3506 : : rte_ixgbe_stats_strings[i].name,
3507 : : sizeof(xstats_names[count].name));
3508 : 0 : count++;
3509 : : }
3510 : :
3511 : : /* MACsec Stats */
3512 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
3513 : 0 : strlcpy(xstats_names[count].name,
3514 : : rte_ixgbe_macsec_strings[i].name,
3515 : : sizeof(xstats_names[count].name));
3516 : 0 : count++;
3517 : : }
3518 : :
3519 : : /* RX Priority Stats */
3520 [ # # ]: 0 : for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
3521 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
3522 : 0 : snprintf(xstats_names[count].name,
3523 : : sizeof(xstats_names[count].name),
3524 : : "rx_priority%u_%s", i,
3525 : 0 : rte_ixgbe_rxq_strings[stat].name);
3526 : 0 : count++;
3527 : : }
3528 : : }
3529 : :
3530 : : /* TX Priority Stats */
3531 [ # # ]: 0 : for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
3532 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
3533 : 0 : snprintf(xstats_names[count].name,
3534 : : sizeof(xstats_names[count].name),
3535 : : "tx_priority%u_%s", i,
3536 : 0 : rte_ixgbe_txq_strings[stat].name);
3537 : 0 : count++;
3538 : : }
3539 : : }
3540 : : }
3541 : 0 : return cnt_stats;
3542 : : }
3543 : :
3544 : 0 : static int ixgbe_dev_xstats_get_names_by_id(
3545 : : struct rte_eth_dev *dev,
3546 : : const uint64_t *ids,
3547 : : struct rte_eth_xstat_name *xstats_names,
3548 : : unsigned int limit)
3549 : : {
3550 [ # # ]: 0 : if (!ids) {
3551 : : const unsigned int cnt_stats = ixgbe_xstats_calc_num();
3552 : : unsigned int stat, i, count;
3553 : :
3554 [ # # ]: 0 : if (xstats_names != NULL) {
3555 : : count = 0;
3556 : :
3557 : : /* Note: limit >= cnt_stats checked upstream
3558 : : * in rte_eth_xstats_names()
3559 : : */
3560 : :
3561 : : /* Extended stats from ixgbe_hw_stats */
3562 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
3563 : 0 : strlcpy(xstats_names[count].name,
3564 : : rte_ixgbe_stats_strings[i].name,
3565 : : sizeof(xstats_names[count].name));
3566 : 0 : count++;
3567 : : }
3568 : :
3569 : : /* MACsec Stats */
3570 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
3571 : 0 : strlcpy(xstats_names[count].name,
3572 : : rte_ixgbe_macsec_strings[i].name,
3573 : : sizeof(xstats_names[count].name));
3574 : 0 : count++;
3575 : : }
3576 : :
3577 : : /* RX Priority Stats */
3578 [ # # ]: 0 : for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
3579 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
3580 : 0 : snprintf(xstats_names[count].name,
3581 : : sizeof(xstats_names[count].name),
3582 : : "rx_priority%u_%s", i,
3583 : 0 : rte_ixgbe_rxq_strings[stat].name);
3584 : 0 : count++;
3585 : : }
3586 : : }
3587 : :
3588 : : /* TX Priority Stats */
3589 [ # # ]: 0 : for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
3590 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
3591 : 0 : snprintf(xstats_names[count].name,
3592 : : sizeof(xstats_names[count].name),
3593 : : "tx_priority%u_%s", i,
3594 : 0 : rte_ixgbe_txq_strings[stat].name);
3595 : 0 : count++;
3596 : : }
3597 : : }
3598 : : }
3599 : 0 : return cnt_stats;
3600 : : }
3601 : :
3602 : : uint16_t i;
3603 : : struct rte_eth_xstat_name xstats_names_copy[IXGBE_XSTATS_CALC_NUM];
3604 : : const uint16_t size = RTE_DIM(xstats_names_copy);
3605 : :
3606 : 0 : ixgbe_dev_xstats_get_names_by_id(dev, NULL, xstats_names_copy,
3607 : : size);
3608 : :
3609 [ # # ]: 0 : for (i = 0; i < limit; i++) {
3610 [ # # ]: 0 : if (ids[i] >= size) {
3611 : 0 : PMD_INIT_LOG(ERR, "id value isn't valid");
3612 : 0 : return -1;
3613 : : }
3614 : 0 : strcpy(xstats_names[i].name,
3615 : 0 : xstats_names_copy[ids[i]].name);
3616 : : }
3617 : 0 : return limit;
3618 : : }
3619 : :
3620 : 0 : static int ixgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3621 : : struct rte_eth_xstat_name *xstats_names, unsigned limit)
3622 : : {
3623 : : unsigned i;
3624 : :
3625 [ # # ]: 0 : if (limit < IXGBEVF_NB_XSTATS && xstats_names != NULL)
3626 : : return -ENOMEM;
3627 : :
3628 [ # # ]: 0 : if (xstats_names != NULL)
3629 [ # # ]: 0 : for (i = 0; i < IXGBEVF_NB_XSTATS; i++)
3630 : 0 : strlcpy(xstats_names[i].name,
3631 : : rte_ixgbevf_stats_strings[i].name,
3632 : : sizeof(xstats_names[i].name));
3633 : : return IXGBEVF_NB_XSTATS;
3634 : : }
3635 : :
3636 : : static int
3637 : 0 : ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3638 : : unsigned n)
3639 : : {
3640 : 0 : struct ixgbe_hw *hw =
3641 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3642 : 0 : struct ixgbe_hw_stats *hw_stats =
3643 : : IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3644 : 0 : struct ixgbe_macsec_stats *macsec_stats =
3645 : : IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
3646 : : dev->data->dev_private);
3647 : : uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
3648 : : unsigned i, stat, count = 0;
3649 : :
3650 : : count = ixgbe_xstats_calc_num();
3651 : :
3652 [ # # ]: 0 : if (n < count)
3653 : : return count;
3654 : :
3655 : 0 : total_missed_rx = 0;
3656 : 0 : total_qbrc = 0;
3657 : 0 : total_qprc = 0;
3658 : 0 : total_qprdc = 0;
3659 : :
3660 : 0 : ixgbe_read_stats_registers(hw, hw_stats, macsec_stats, &total_missed_rx,
3661 : : &total_qbrc, &total_qprc, &total_qprdc);
3662 : :
3663 : : /* If this is a reset xstats is NULL, and we have cleared the
3664 : : * registers by reading them.
3665 : : */
3666 [ # # ]: 0 : if (!xstats)
3667 : : return 0;
3668 : :
3669 : : /* Extended stats from ixgbe_hw_stats */
3670 : : count = 0;
3671 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
3672 : 0 : xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3673 : 0 : rte_ixgbe_stats_strings[i].offset);
3674 : 0 : xstats[count].id = count;
3675 : 0 : count++;
3676 : : }
3677 : :
3678 : : /* MACsec Stats */
3679 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
3680 : 0 : xstats[count].value = *(uint64_t *)(((char *)macsec_stats) +
3681 : 0 : rte_ixgbe_macsec_strings[i].offset);
3682 : 0 : xstats[count].id = count;
3683 : 0 : count++;
3684 : : }
3685 : :
3686 : : /* RX Priority Stats */
3687 [ # # ]: 0 : for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
3688 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
3689 : 0 : xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3690 : 0 : rte_ixgbe_rxq_strings[stat].offset +
3691 : 0 : (sizeof(uint64_t) * i));
3692 : 0 : xstats[count].id = count;
3693 : 0 : count++;
3694 : : }
3695 : : }
3696 : :
3697 : : /* TX Priority Stats */
3698 [ # # ]: 0 : for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
3699 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
3700 : 0 : xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3701 : 0 : rte_ixgbe_txq_strings[stat].offset +
3702 : 0 : (sizeof(uint64_t) * i));
3703 : 0 : xstats[count].id = count;
3704 : 0 : count++;
3705 : : }
3706 : : }
3707 : 0 : return count;
3708 : : }
3709 : :
3710 : : static int
3711 : 0 : ixgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
3712 : : uint64_t *values, unsigned int n)
3713 : : {
3714 [ # # ]: 0 : if (!ids) {
3715 : 0 : struct ixgbe_hw *hw =
3716 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3717 : 0 : struct ixgbe_hw_stats *hw_stats =
3718 : : IXGBE_DEV_PRIVATE_TO_STATS(
3719 : : dev->data->dev_private);
3720 : 0 : struct ixgbe_macsec_stats *macsec_stats =
3721 : : IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
3722 : : dev->data->dev_private);
3723 : : uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
3724 : : unsigned int i, stat, count = 0;
3725 : :
3726 : : count = ixgbe_xstats_calc_num();
3727 : :
3728 [ # # ]: 0 : if (!ids && n < count)
3729 : : return count;
3730 : :
3731 : 0 : total_missed_rx = 0;
3732 : 0 : total_qbrc = 0;
3733 : 0 : total_qprc = 0;
3734 : 0 : total_qprdc = 0;
3735 : :
3736 : 0 : ixgbe_read_stats_registers(hw, hw_stats, macsec_stats,
3737 : : &total_missed_rx, &total_qbrc, &total_qprc,
3738 : : &total_qprdc);
3739 : :
3740 : : /* If this is a reset xstats is NULL, and we have cleared the
3741 : : * registers by reading them.
3742 : : */
3743 [ # # ]: 0 : if (!ids && !values)
3744 : : return 0;
3745 : :
3746 : : /* Extended stats from ixgbe_hw_stats */
3747 : : count = 0;
3748 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
3749 : 0 : values[count] = *(uint64_t *)(((char *)hw_stats) +
3750 : 0 : rte_ixgbe_stats_strings[i].offset);
3751 : 0 : count++;
3752 : : }
3753 : :
3754 : : /* MACsec Stats */
3755 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
3756 : 0 : values[count] = *(uint64_t *)(((char *)macsec_stats) +
3757 : 0 : rte_ixgbe_macsec_strings[i].offset);
3758 : 0 : count++;
3759 : : }
3760 : :
3761 : : /* RX Priority Stats */
3762 [ # # ]: 0 : for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
3763 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
3764 : 0 : values[count] =
3765 : 0 : *(uint64_t *)(((char *)hw_stats) +
3766 : 0 : rte_ixgbe_rxq_strings[stat].offset +
3767 : 0 : (sizeof(uint64_t) * i));
3768 : 0 : count++;
3769 : : }
3770 : : }
3771 : :
3772 : : /* TX Priority Stats */
3773 [ # # ]: 0 : for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
3774 [ # # ]: 0 : for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
3775 : 0 : values[count] =
3776 : 0 : *(uint64_t *)(((char *)hw_stats) +
3777 : 0 : rte_ixgbe_txq_strings[stat].offset +
3778 : 0 : (sizeof(uint64_t) * i));
3779 : 0 : count++;
3780 : : }
3781 : : }
3782 : 0 : return count;
3783 : : }
3784 : :
3785 : : uint16_t i;
3786 : : uint64_t values_copy[IXGBE_XSTATS_CALC_NUM];
3787 : : const uint16_t size = RTE_DIM(values_copy);
3788 : :
3789 : 0 : ixgbe_dev_xstats_get_by_id(dev, NULL, values_copy, size);
3790 : :
3791 [ # # ]: 0 : for (i = 0; i < n; i++) {
3792 [ # # ]: 0 : if (ids[i] >= size) {
3793 : 0 : PMD_INIT_LOG(ERR, "id value isn't valid");
3794 : 0 : return -1;
3795 : : }
3796 : 0 : values[i] = values_copy[ids[i]];
3797 : : }
3798 : 0 : return n;
3799 : : }
3800 : :
3801 : : static int
3802 : 0 : ixgbe_dev_xstats_reset(struct rte_eth_dev *dev)
3803 : : {
3804 : 0 : struct ixgbe_hw_stats *stats =
3805 : 0 : IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3806 : 0 : struct ixgbe_macsec_stats *macsec_stats =
3807 : : IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
3808 : : dev->data->dev_private);
3809 : :
3810 : : unsigned count = ixgbe_xstats_calc_num();
3811 : :
3812 : : /* HW registers are cleared on read */
3813 : 0 : ixgbe_dev_xstats_get(dev, NULL, count);
3814 : :
3815 : : /* Reset software totals */
3816 : : memset(stats, 0, sizeof(*stats));
3817 : : memset(macsec_stats, 0, sizeof(*macsec_stats));
3818 : :
3819 : 0 : return 0;
3820 : : }
3821 : :
3822 : : static void
3823 : 0 : ixgbevf_update_stats(struct rte_eth_dev *dev)
3824 : : {
3825 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3826 : : struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
3827 : : IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3828 : :
3829 : : /* Good Rx packet, include VF loopback */
3830 : 0 : UPDATE_VF_STAT(IXGBE_VFGPRC,
3831 : : hw_stats->last_vfgprc, hw_stats->vfgprc);
3832 : :
3833 : : /* Good Rx octets, include VF loopback */
3834 : 0 : UPDATE_VF_STAT_36BIT(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
3835 : : hw_stats->last_vfgorc, hw_stats->vfgorc);
3836 : :
3837 : : /* Good Tx packet, include VF loopback */
3838 : 0 : UPDATE_VF_STAT(IXGBE_VFGPTC,
3839 : : hw_stats->last_vfgptc, hw_stats->vfgptc);
3840 : :
3841 : : /* Good Tx octets, include VF loopback */
3842 : 0 : UPDATE_VF_STAT_36BIT(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
3843 : : hw_stats->last_vfgotc, hw_stats->vfgotc);
3844 : :
3845 : : /* Rx Multicst Packet */
3846 : 0 : UPDATE_VF_STAT(IXGBE_VFMPRC,
3847 : : hw_stats->last_vfmprc, hw_stats->vfmprc);
3848 : 0 : }
3849 : :
3850 : : static int
3851 : 0 : ixgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3852 : : unsigned n)
3853 : : {
3854 : : struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
3855 : 0 : IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3856 : : unsigned i;
3857 : :
3858 [ # # ]: 0 : if (n < IXGBEVF_NB_XSTATS)
3859 : : return IXGBEVF_NB_XSTATS;
3860 : :
3861 : 0 : ixgbevf_update_stats(dev);
3862 : :
3863 [ # # ]: 0 : if (!xstats)
3864 : : return 0;
3865 : :
3866 : : /* Extended stats */
3867 [ # # ]: 0 : for (i = 0; i < IXGBEVF_NB_XSTATS; i++) {
3868 : 0 : xstats[i].id = i;
3869 : 0 : xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
3870 : : rte_ixgbevf_stats_strings[i].offset);
3871 : : }
3872 : :
3873 : : return IXGBEVF_NB_XSTATS;
3874 : : }
3875 : :
3876 : : static int
3877 : 0 : ixgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
3878 : : {
3879 : : struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
3880 : 0 : IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3881 : :
3882 : 0 : ixgbevf_update_stats(dev);
3883 : :
3884 [ # # ]: 0 : if (stats == NULL)
3885 : : return -EINVAL;
3886 : :
3887 : 0 : stats->ipackets = hw_stats->vfgprc;
3888 : 0 : stats->ibytes = hw_stats->vfgorc;
3889 : 0 : stats->opackets = hw_stats->vfgptc;
3890 : 0 : stats->obytes = hw_stats->vfgotc;
3891 : 0 : return 0;
3892 : : }
3893 : :
3894 : : static int
3895 : 0 : ixgbevf_dev_stats_reset(struct rte_eth_dev *dev)
3896 : : {
3897 : : struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
3898 : 0 : IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
3899 : :
3900 : : /* Sync HW register to the last stats */
3901 : : ixgbevf_dev_stats_get(dev, NULL);
3902 : :
3903 : : /* reset HW current stats*/
3904 : 0 : hw_stats->vfgprc = 0;
3905 : 0 : hw_stats->vfgorc = 0;
3906 : 0 : hw_stats->vfgptc = 0;
3907 : 0 : hw_stats->vfgotc = 0;
3908 : 0 : hw_stats->vfmprc = 0;
3909 : :
3910 : 0 : return 0;
3911 : : }
3912 : :
3913 : : static int
3914 : 0 : ixgbe_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3915 : : {
3916 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3917 : : struct ixgbe_nvm_version nvm_ver;
3918 : : int ret;
3919 : :
3920 : : /*
3921 : : * This function calls into the base driver, which in turn will use
3922 : : * function pointers, which are not guaranteed to be valid in secondary
3923 : : * processes, so avoid using this function in secondary processes.
3924 : : */
3925 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3926 : : return -E_RTE_SECONDARY;
3927 : :
3928 : 0 : ixgbe_get_oem_prod_version(hw, &nvm_ver);
3929 [ # # ]: 0 : if (nvm_ver.oem_valid) {
3930 : 0 : snprintf(fw_version, fw_size, "%x.%x.%x",
3931 : 0 : nvm_ver.oem_major, nvm_ver.oem_minor,
3932 : 0 : nvm_ver.oem_release);
3933 : 0 : return 0;
3934 : : }
3935 : :
3936 : 0 : ixgbe_get_etk_id(hw, &nvm_ver);
3937 : 0 : ixgbe_get_orom_version(hw, &nvm_ver);
3938 : :
3939 [ # # ]: 0 : if (nvm_ver.or_valid) {
3940 : 0 : snprintf(fw_version, fw_size, "0x%08x, %d.%d.%d",
3941 : 0 : nvm_ver.etk_id, nvm_ver.or_major,
3942 : 0 : nvm_ver.or_build, nvm_ver.or_patch);
3943 : 0 : return 0;
3944 : : }
3945 : :
3946 [ # # ]: 0 : ret = snprintf(fw_version, fw_size, "0x%08x", nvm_ver.etk_id);
3947 [ # # ]: 0 : if (ret < 0)
3948 : : return -EINVAL;
3949 : :
3950 [ # # ]: 0 : return (fw_size < (size_t)ret++) ? ret : 0;
3951 : : }
3952 : :
3953 : : static int
3954 : 0 : ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3955 : : {
3956 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3957 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3958 : : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
3959 : :
3960 : 0 : dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
3961 : 0 : dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
3962 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
3963 : : /*
3964 : : * When DCB/VT is off, maximum number of queues changes,
3965 : : * except for 82598EB, which remains constant.
3966 : : */
3967 [ # # ]: 0 : if (dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_NONE &&
3968 [ # # ]: 0 : hw->mac.type != ixgbe_mac_82598EB)
3969 : 0 : dev_info->max_tx_queues = IXGBE_NONE_MODE_TX_NB_QUEUES;
3970 : : }
3971 : 0 : dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL register */
3972 : 0 : dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS register */
3973 : 0 : dev_info->max_mac_addrs = hw->mac.num_rar_entries;
3974 : 0 : dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
3975 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
3976 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
3977 : 0 : dev_info->max_vmdq_pools = RTE_ETH_16_POOLS;
3978 : : else
3979 : 0 : dev_info->max_vmdq_pools = RTE_ETH_64_POOLS;
3980 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - IXGBE_ETH_OVERHEAD;
3981 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3982 : 0 : dev_info->vmdq_queue_num = dev_info->max_rx_queues;
3983 : 0 : dev_info->rx_queue_offload_capa = ixgbe_get_rx_queue_offloads(dev);
3984 : 0 : dev_info->rx_offload_capa = (ixgbe_get_rx_port_offloads(dev) |
3985 : 0 : dev_info->rx_queue_offload_capa);
3986 : 0 : dev_info->tx_queue_offload_capa = ixgbe_get_tx_queue_offloads(dev);
3987 : 0 : dev_info->tx_offload_capa = ixgbe_get_tx_port_offloads(dev);
3988 : :
3989 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
3990 : : .rx_thresh = {
3991 : : .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
3992 : : .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
3993 : : .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
3994 : : },
3995 : : .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
3996 : : .rx_drop_en = 0,
3997 : : .offloads = 0,
3998 : : };
3999 : :
4000 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
4001 : : .tx_thresh = {
4002 : : .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
4003 : : .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
4004 : : .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
4005 : : },
4006 : : .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
4007 : : .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
4008 : : .offloads = 0,
4009 : : };
4010 : :
4011 : 0 : dev_info->rx_desc_lim = rx_desc_lim;
4012 : 0 : dev_info->tx_desc_lim = tx_desc_lim;
4013 : :
4014 : 0 : dev_info->hash_key_size = IXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
4015 : 0 : dev_info->reta_size = ixgbe_reta_size_get(hw->mac.type);
4016 : 0 : dev_info->flow_type_rss_offloads = IXGBE_RSS_OFFLOAD_ALL;
4017 : :
4018 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
4019 [ # # ]: 0 : if (hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T ||
4020 : : hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T_L)
4021 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M |
4022 : : RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_1G;
4023 : :
4024 : 0 : if (hw->mac.type == ixgbe_mac_X540 ||
4025 : : hw->mac.type == ixgbe_mac_X540_vf ||
4026 [ # # ]: 0 : hw->mac.type == ixgbe_mac_X550 ||
4027 : : hw->mac.type == ixgbe_mac_X550_vf) {
4028 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_100M;
4029 : : }
4030 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_X550) {
4031 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_2_5G;
4032 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_5G;
4033 : : }
4034 : :
4035 : : /* Driver-preferred Rx/Tx parameters */
4036 : 0 : dev_info->default_rxportconf.burst_size = 32;
4037 : 0 : dev_info->default_txportconf.burst_size = 32;
4038 : 0 : dev_info->default_rxportconf.nb_queues = 1;
4039 : 0 : dev_info->default_txportconf.nb_queues = 1;
4040 : 0 : dev_info->default_rxportconf.ring_size = 256;
4041 : 0 : dev_info->default_txportconf.ring_size = 256;
4042 : :
4043 : 0 : return 0;
4044 : : }
4045 : :
4046 : : static const uint32_t *
4047 : 0 : ixgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
4048 : : {
4049 : : static const uint32_t ptypes[] = {
4050 : : /* For non-vec functions,
4051 : : * refers to ixgbe_rxd_pkt_info_to_pkt_type();
4052 : : * for vec functions,
4053 : : * refers to _recv_raw_pkts_vec().
4054 : : */
4055 : : RTE_PTYPE_L2_ETHER,
4056 : : RTE_PTYPE_L3_IPV4,
4057 : : RTE_PTYPE_L3_IPV4_EXT,
4058 : : RTE_PTYPE_L3_IPV6,
4059 : : RTE_PTYPE_L3_IPV6_EXT,
4060 : : RTE_PTYPE_L4_SCTP,
4061 : : RTE_PTYPE_L4_TCP,
4062 : : RTE_PTYPE_L4_UDP,
4063 : : RTE_PTYPE_TUNNEL_IP,
4064 : : RTE_PTYPE_INNER_L3_IPV6,
4065 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
4066 : : RTE_PTYPE_INNER_L4_TCP,
4067 : : RTE_PTYPE_INNER_L4_UDP,
4068 : : };
4069 : :
4070 [ # # # # ]: 0 : if (dev->rx_pkt_burst == ixgbe_recv_pkts ||
4071 [ # # ]: 0 : dev->rx_pkt_burst == ixgbe_recv_pkts_lro_single_alloc ||
4072 [ # # ]: 0 : dev->rx_pkt_burst == ixgbe_recv_pkts_lro_bulk_alloc ||
4073 : : dev->rx_pkt_burst == ixgbe_recv_pkts_bulk_alloc) {
4074 : 0 : *no_of_elements = RTE_DIM(ptypes);
4075 : 0 : return ptypes;
4076 : : }
4077 : :
4078 : : #if defined(RTE_ARCH_X86) || defined(__ARM_NEON)
4079 [ # # # # ]: 0 : if (dev->rx_pkt_burst == ixgbe_recv_pkts_vec ||
4080 : : dev->rx_pkt_burst == ixgbe_recv_scattered_pkts_vec) {
4081 : 0 : *no_of_elements = RTE_DIM(ptypes);
4082 : 0 : return ptypes;
4083 : : }
4084 : : #endif
4085 : : return NULL;
4086 : : }
4087 : :
4088 : : static int
4089 : 0 : ixgbevf_dev_info_get(struct rte_eth_dev *dev,
4090 : : struct rte_eth_dev_info *dev_info)
4091 : : {
4092 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4093 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4094 : :
4095 : 0 : dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
4096 : 0 : dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
4097 : 0 : dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL reg */
4098 : 0 : dev_info->max_rx_pktlen = 9728; /* includes CRC, cf MAXFRS reg */
4099 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - IXGBE_ETH_OVERHEAD;
4100 : 0 : dev_info->max_mac_addrs = hw->mac.num_rar_entries;
4101 : 0 : dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
4102 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
4103 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB)
4104 : 0 : dev_info->max_vmdq_pools = RTE_ETH_16_POOLS;
4105 : : else
4106 : 0 : dev_info->max_vmdq_pools = RTE_ETH_64_POOLS;
4107 : 0 : dev_info->rx_queue_offload_capa = ixgbe_get_rx_queue_offloads(dev);
4108 : 0 : dev_info->rx_offload_capa = (ixgbe_get_rx_port_offloads(dev) |
4109 : 0 : dev_info->rx_queue_offload_capa);
4110 : 0 : dev_info->tx_queue_offload_capa = ixgbe_get_tx_queue_offloads(dev);
4111 : 0 : dev_info->tx_offload_capa = ixgbe_get_tx_port_offloads(dev);
4112 : 0 : dev_info->hash_key_size = IXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
4113 : 0 : dev_info->reta_size = ixgbe_reta_size_get(hw->mac.type);
4114 : 0 : dev_info->flow_type_rss_offloads = IXGBE_RSS_OFFLOAD_ALL;
4115 : :
4116 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
4117 : : .rx_thresh = {
4118 : : .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
4119 : : .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
4120 : : .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
4121 : : },
4122 : : .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
4123 : : .rx_drop_en = 0,
4124 : : .offloads = 0,
4125 : : };
4126 : :
4127 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
4128 : : .tx_thresh = {
4129 : : .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
4130 : : .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
4131 : : .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
4132 : : },
4133 : : .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
4134 : : .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
4135 : : .offloads = 0,
4136 : : };
4137 : :
4138 : 0 : dev_info->rx_desc_lim = rx_desc_lim;
4139 : 0 : dev_info->tx_desc_lim = tx_desc_lim;
4140 : :
4141 : 0 : dev_info->err_handle_mode = RTE_ETH_ERROR_HANDLE_MODE_PASSIVE;
4142 : :
4143 : 0 : return 0;
4144 : : }
4145 : :
4146 : : static int
4147 : 0 : ixgbevf_check_link(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
4148 : : bool *link_up, int wait_to_complete)
4149 : : {
4150 : : struct ixgbe_adapter *adapter = container_of(hw,
4151 : : struct ixgbe_adapter, hw);
4152 : : struct ixgbe_mbx_info *mbx = &hw->mbx;
4153 : : struct ixgbe_mac_info *mac = &hw->mac;
4154 : : uint32_t links_reg, in_msg;
4155 : : int ret_val = 0;
4156 : :
4157 : : /* If we were hit with a reset drop the link */
4158 [ # # # # ]: 0 : if (!mbx->ops[0].check_for_rst(hw, 0) || !mbx->timeout)
4159 : 0 : mac->get_link_status = true;
4160 : :
4161 [ # # ]: 0 : if (!mac->get_link_status)
4162 : 0 : goto out;
4163 : :
4164 : : /* if link status is down no point in checking to see if pf is up */
4165 : 0 : links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
4166 [ # # ]: 0 : if (!(links_reg & IXGBE_LINKS_UP))
4167 : 0 : goto out;
4168 : :
4169 : : /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
4170 : : * before the link status is correct
4171 : : */
4172 [ # # # # ]: 0 : if (mac->type == ixgbe_mac_82599_vf && wait_to_complete) {
4173 : : int i;
4174 : :
4175 [ # # ]: 0 : for (i = 0; i < 5; i++) {
4176 : 0 : rte_delay_us(100);
4177 : 0 : links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
4178 : :
4179 [ # # ]: 0 : if (!(links_reg & IXGBE_LINKS_UP))
4180 : 0 : goto out;
4181 : : }
4182 : : }
4183 : :
4184 [ # # # # : 0 : switch (links_reg & IXGBE_LINKS_SPEED_82599) {
# ]
4185 : 0 : case IXGBE_LINKS_SPEED_10G_82599:
4186 : 0 : *speed = IXGBE_LINK_SPEED_10GB_FULL;
4187 [ # # ]: 0 : if (hw->mac.type >= ixgbe_mac_X550) {
4188 [ # # ]: 0 : if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
4189 : 0 : *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
4190 : : }
4191 : : break;
4192 : 0 : case IXGBE_LINKS_SPEED_1G_82599:
4193 : 0 : *speed = IXGBE_LINK_SPEED_1GB_FULL;
4194 : 0 : break;
4195 : 0 : case IXGBE_LINKS_SPEED_100_82599:
4196 : 0 : *speed = IXGBE_LINK_SPEED_100_FULL;
4197 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_X550) {
4198 [ # # ]: 0 : if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
4199 : 0 : *speed = IXGBE_LINK_SPEED_5GB_FULL;
4200 : : }
4201 : : break;
4202 : 0 : case IXGBE_LINKS_SPEED_10_X550EM_A:
4203 : 0 : *speed = IXGBE_LINK_SPEED_UNKNOWN;
4204 : : /* Since Reserved in older MAC's */
4205 [ # # ]: 0 : if (hw->mac.type >= ixgbe_mac_X550)
4206 : 0 : *speed = IXGBE_LINK_SPEED_10_FULL;
4207 : : break;
4208 : 0 : default:
4209 : 0 : *speed = IXGBE_LINK_SPEED_UNKNOWN;
4210 : : }
4211 : :
4212 [ # # # # ]: 0 : if (wait_to_complete == 0 && adapter->pflink_fullchk == 0) {
4213 [ # # ]: 0 : if (*speed == IXGBE_LINK_SPEED_UNKNOWN)
4214 : 0 : mac->get_link_status = true;
4215 : : else
4216 : 0 : mac->get_link_status = false;
4217 : :
4218 : 0 : goto out;
4219 : : }
4220 : :
4221 : : /* if the read failed it could just be a mailbox collision, best wait
4222 : : * until we are called again and don't report an error
4223 : : */
4224 : :
4225 : : /*
4226 : : * on MinGW, the read op call is interpreted as call into read() macro,
4227 : : * so avoid calling it directly.
4228 : : */
4229 [ # # ]: 0 : if ((mbx->ops[0].read)(hw, &in_msg, 1, 0))
4230 : 0 : goto out;
4231 : :
4232 [ # # ]: 0 : if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
4233 : : /* msg is not CTS and is FAILURE we must have lost CTS status */
4234 [ # # ]: 0 : if (in_msg & IXGBE_VT_MSGTYPE_FAILURE)
4235 : 0 : mac->get_link_status = false;
4236 : 0 : goto out;
4237 : : }
4238 : :
4239 : : /* the pf is talking, if we timed out in the past we reinit */
4240 [ # # ]: 0 : if (!mbx->timeout) {
4241 : : ret_val = -1;
4242 : 0 : goto out;
4243 : : }
4244 : :
4245 : : /* if we passed all the tests above then the link is up and we no
4246 : : * longer need to check for link
4247 : : */
4248 : 0 : mac->get_link_status = false;
4249 : :
4250 : 0 : out:
4251 : 0 : *link_up = !mac->get_link_status;
4252 : 0 : return ret_val;
4253 : : }
4254 : :
4255 : : /*
4256 : : * If @timeout_ms was 0, it means that it will not return until link complete.
4257 : : * It returns 1 on complete, return 0 on timeout.
4258 : : */
4259 : : static int
4260 : 0 : ixgbe_dev_wait_setup_link_complete(struct rte_eth_dev *dev, uint32_t timeout_ms)
4261 : : {
4262 : : #define WARNING_TIMEOUT 9000 /* 9s in total */
4263 : 0 : struct ixgbe_adapter *ad = dev->data->dev_private;
4264 [ # # ]: 0 : uint32_t timeout = timeout_ms ? timeout_ms : WARNING_TIMEOUT;
4265 : :
4266 : : /* NOTE: review for potential ordering optimization */
4267 [ # # ]: 0 : while (rte_atomic_load_explicit(&ad->link_thread_running, rte_memory_order_seq_cst)) {
4268 : 0 : msec_delay(1);
4269 : 0 : timeout--;
4270 : :
4271 [ # # ]: 0 : if (timeout_ms) {
4272 [ # # ]: 0 : if (!timeout)
4273 : : return 0;
4274 [ # # ]: 0 : } else if (!timeout) {
4275 : : /* It will not return until link complete */
4276 : : timeout = WARNING_TIMEOUT;
4277 : 0 : PMD_DRV_LOG(ERR, "IXGBE link thread not complete too long time!");
4278 : : }
4279 : : }
4280 : :
4281 : : return 1;
4282 : : }
4283 : :
4284 : : static uint32_t
4285 : 0 : ixgbe_dev_setup_link_thread_handler(void *param)
4286 : : {
4287 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
4288 : 0 : struct ixgbe_adapter *ad = dev->data->dev_private;
4289 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4290 : : struct ixgbe_interrupt *intr =
4291 : : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4292 : : u32 speed;
4293 : 0 : bool autoneg = false;
4294 : :
4295 : 0 : rte_thread_detach(rte_thread_self());
4296 : 0 : speed = hw->phy.autoneg_advertised;
4297 [ # # ]: 0 : if (!speed)
4298 : 0 : ixgbe_get_link_capabilities(hw, &speed, &autoneg);
4299 : :
4300 : 0 : ixgbe_setup_link(hw, speed, true);
4301 : :
4302 : 0 : intr->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4303 : : /* NOTE: review for potential ordering optimization */
4304 : 0 : rte_atomic_store_explicit(&ad->link_thread_running, 0, rte_memory_order_seq_cst);
4305 : 0 : return 0;
4306 : : }
4307 : :
4308 : : /*
4309 : : * In freebsd environment, nic_uio drivers do not support interrupts,
4310 : : * rte_intr_callback_register() will fail to register interrupts.
4311 : : * We can not make link status to change from down to up by interrupt
4312 : : * callback. So we need to wait for the controller to acquire link
4313 : : * when ports start.
4314 : : * It returns 0 on link up.
4315 : : */
4316 : : static int
4317 : : ixgbe_wait_for_link_up(struct ixgbe_hw *hw)
4318 : : {
4319 : : #ifdef RTE_EXEC_ENV_FREEBSD
4320 : : int err, i;
4321 : : bool link_up = false;
4322 : : uint32_t speed = 0;
4323 : : const int nb_iter = 25;
4324 : :
4325 : : for (i = 0; i < nb_iter; i++) {
4326 : : err = ixgbe_check_link(hw, &speed, &link_up, 0);
4327 : : if (err)
4328 : : return err;
4329 : : if (link_up)
4330 : : return 0;
4331 : : msec_delay(200);
4332 : : }
4333 : :
4334 : : return 0;
4335 : : #else
4336 : : RTE_SET_USED(hw);
4337 : : return 0;
4338 : : #endif
4339 : : }
4340 : :
4341 : : /* return 0 means link status changed, -1 means not changed */
4342 : : int
4343 : 0 : ixgbe_dev_link_update_share(struct rte_eth_dev *dev,
4344 : : int wait_to_complete, int vf)
4345 : : {
4346 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4347 : : struct ixgbe_adapter *ad = dev->data->dev_private;
4348 : : struct rte_eth_link link;
4349 : 0 : ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
4350 : : struct ixgbe_interrupt *intr =
4351 : : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4352 : : bool link_up;
4353 : : int diag;
4354 : : int wait = 1;
4355 : : u32 esdp_reg;
4356 : :
4357 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
4358 : : return -1;
4359 : :
4360 : : memset(&link, 0, sizeof(link));
4361 : : link.link_status = RTE_ETH_LINK_DOWN;
4362 : : link.link_speed = RTE_ETH_SPEED_NUM_NONE;
4363 : : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
4364 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
4365 : : RTE_ETH_LINK_SPEED_FIXED);
4366 : :
4367 : 0 : hw->mac.get_link_status = true;
4368 : :
4369 [ # # ]: 0 : if (intr->flags & IXGBE_FLAG_NEED_LINK_CONFIG)
4370 : 0 : return rte_eth_linkstatus_set(dev, &link);
4371 : :
4372 : : /* check if it needs to wait to complete, if lsc interrupt is enabled */
4373 [ # # # # ]: 0 : if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
4374 : : wait = 0;
4375 : :
4376 [ # # ]: 0 : if (vf)
4377 : 0 : diag = ixgbevf_check_link(hw, &link_speed, &link_up, wait);
4378 : : else
4379 : 0 : diag = ixgbe_check_link(hw, &link_speed, &link_up, wait);
4380 : :
4381 [ # # ]: 0 : if (diag != 0) {
4382 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100M;
4383 [ # # ]: 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
4384 : 0 : return rte_eth_linkstatus_set(dev, &link);
4385 : : }
4386 : :
4387 [ # # ]: 0 : if (ixgbe_get_media_type(hw) == ixgbe_media_type_fiber &&
4388 [ # # ]: 0 : !ad->sdp3_no_tx_disable) {
4389 : 0 : esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
4390 [ # # ]: 0 : if ((esdp_reg & IXGBE_ESDP_SDP3))
4391 : 0 : link_up = 0;
4392 : : }
4393 : :
4394 [ # # ]: 0 : if (link_up == 0) {
4395 [ # # ]: 0 : if (ixgbe_get_media_type(hw) == ixgbe_media_type_fiber) {
4396 : 0 : ixgbe_dev_wait_setup_link_complete(dev, 0);
4397 : : /* NOTE: review for potential ordering optimization */
4398 [ # # ]: 0 : if (!rte_atomic_exchange_explicit(&ad->link_thread_running, 1,
4399 : : rte_memory_order_seq_cst)) {
4400 : : /* To avoid race condition between threads, set
4401 : : * the IXGBE_FLAG_NEED_LINK_CONFIG flag only
4402 : : * when there is no link thread running.
4403 : : */
4404 : 0 : intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
4405 [ # # ]: 0 : if (rte_thread_create_internal_control(&ad->link_thread_tid,
4406 : : "ixgbe-link",
4407 : : ixgbe_dev_setup_link_thread_handler, dev) < 0) {
4408 : 0 : PMD_DRV_LOG(ERR,
4409 : : "Create link thread failed!");
4410 : : /* NOTE: review for potential ordering optimization */
4411 : 0 : rte_atomic_store_explicit(&ad->link_thread_running, 0,
4412 : : rte_memory_order_seq_cst);
4413 : : }
4414 : : } else {
4415 : 0 : PMD_DRV_LOG(ERR,
4416 : : "Other link thread is running now!");
4417 : : }
4418 : : }
4419 : 0 : return rte_eth_linkstatus_set(dev, &link);
4420 : : }
4421 : :
4422 : 0 : link.link_status = RTE_ETH_LINK_UP;
4423 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
4424 : :
4425 [ # # # # : 0 : switch (link_speed) {
# # # ]
4426 : 0 : default:
4427 : : case IXGBE_LINK_SPEED_UNKNOWN:
4428 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
4429 : 0 : break;
4430 : :
4431 : 0 : case IXGBE_LINK_SPEED_10_FULL:
4432 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_10M;
4433 : 0 : break;
4434 : :
4435 : 0 : case IXGBE_LINK_SPEED_100_FULL:
4436 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100M;
4437 : 0 : break;
4438 : :
4439 : 0 : case IXGBE_LINK_SPEED_1GB_FULL:
4440 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_1G;
4441 : 0 : break;
4442 : :
4443 : 0 : case IXGBE_LINK_SPEED_2_5GB_FULL:
4444 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_2_5G;
4445 : 0 : break;
4446 : :
4447 : 0 : case IXGBE_LINK_SPEED_5GB_FULL:
4448 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_5G;
4449 : 0 : break;
4450 : :
4451 : 0 : case IXGBE_LINK_SPEED_10GB_FULL:
4452 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_10G;
4453 : 0 : break;
4454 : : }
4455 : :
4456 : : return rte_eth_linkstatus_set(dev, &link);
4457 : : }
4458 : :
4459 : : static int
4460 : 0 : ixgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
4461 : : {
4462 : 0 : return ixgbe_dev_link_update_share(dev, wait_to_complete, 0);
4463 : : }
4464 : :
4465 : : static int
4466 : 0 : ixgbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
4467 : : {
4468 : 0 : return ixgbe_dev_link_update_share(dev, wait_to_complete, 1);
4469 : : }
4470 : :
4471 : : static int
4472 : 0 : ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
4473 : : {
4474 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4475 : : uint32_t fctrl;
4476 : :
4477 : 0 : fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4478 : 0 : fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
4479 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4480 : :
4481 : 0 : return 0;
4482 : : }
4483 : :
4484 : : static int
4485 : 0 : ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
4486 : : {
4487 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4488 : : uint32_t fctrl;
4489 : :
4490 : 0 : fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4491 : 0 : fctrl &= (~IXGBE_FCTRL_UPE);
4492 [ # # ]: 0 : if (dev->data->all_multicast == 1)
4493 : 0 : fctrl |= IXGBE_FCTRL_MPE;
4494 : : else
4495 : 0 : fctrl &= (~IXGBE_FCTRL_MPE);
4496 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4497 : :
4498 : 0 : return 0;
4499 : : }
4500 : :
4501 : : static int
4502 : 0 : ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
4503 : : {
4504 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4505 : : uint32_t fctrl;
4506 : :
4507 : 0 : fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4508 : 0 : fctrl |= IXGBE_FCTRL_MPE;
4509 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4510 : :
4511 : 0 : return 0;
4512 : : }
4513 : :
4514 : : static int
4515 : 0 : ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
4516 : : {
4517 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4518 : : uint32_t fctrl;
4519 : :
4520 [ # # ]: 0 : if (dev->data->promiscuous == 1)
4521 : : return 0; /* must remain in all_multicast mode */
4522 : :
4523 : 0 : fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4524 : 0 : fctrl &= (~IXGBE_FCTRL_MPE);
4525 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4526 : :
4527 : 0 : return 0;
4528 : : }
4529 : :
4530 : : /**
4531 : : * It clears the interrupt causes and enables the interrupt.
4532 : : * It will be called once only during nic initialized.
4533 : : *
4534 : : * @param dev
4535 : : * Pointer to struct rte_eth_dev.
4536 : : * @param on
4537 : : * Enable or Disable.
4538 : : *
4539 : : * @return
4540 : : * - On success, zero.
4541 : : * - On failure, a negative value.
4542 : : */
4543 : : static int
4544 : : ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
4545 : : {
4546 : : struct ixgbe_interrupt *intr =
4547 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4548 : :
4549 : 0 : ixgbe_dev_link_status_print(dev);
4550 : : if (on)
4551 : 0 : intr->mask |= IXGBE_EICR_LSC;
4552 : : else
4553 : 0 : intr->mask &= ~IXGBE_EICR_LSC;
4554 : :
4555 : : return 0;
4556 : : }
4557 : :
4558 : : /**
4559 : : * It clears the interrupt causes and enables the interrupt.
4560 : : * It will be called once only during nic initialized.
4561 : : *
4562 : : * @param dev
4563 : : * Pointer to struct rte_eth_dev.
4564 : : *
4565 : : * @return
4566 : : * - On success, zero.
4567 : : * - On failure, a negative value.
4568 : : */
4569 : : static int
4570 : : ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
4571 : : {
4572 : : struct ixgbe_interrupt *intr =
4573 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4574 : :
4575 : 0 : intr->mask |= IXGBE_EICR_RTX_QUEUE;
4576 : :
4577 : 0 : return 0;
4578 : : }
4579 : :
4580 : : /**
4581 : : * It clears the interrupt causes and enables the interrupt.
4582 : : * It will be called once only during nic initialized.
4583 : : *
4584 : : * @param dev
4585 : : * Pointer to struct rte_eth_dev.
4586 : : *
4587 : : * @return
4588 : : * - On success, zero.
4589 : : * - On failure, a negative value.
4590 : : */
4591 : : static int
4592 : : ixgbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev)
4593 : : {
4594 : : struct ixgbe_interrupt *intr =
4595 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4596 : :
4597 : 0 : intr->mask |= IXGBE_EICR_LINKSEC;
4598 : :
4599 : 0 : return 0;
4600 : : }
4601 : :
4602 : : /*
4603 : : * It reads ICR and sets flag (IXGBE_EICR_LSC) for the link_update.
4604 : : *
4605 : : * @param dev
4606 : : * Pointer to struct rte_eth_dev.
4607 : : *
4608 : : * @return
4609 : : * - On success, zero.
4610 : : * - On failure, a negative value.
4611 : : */
4612 : : static int
4613 : 0 : ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
4614 : : {
4615 : : uint32_t eicr;
4616 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4617 : : struct ixgbe_interrupt *intr =
4618 : : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4619 : :
4620 : : /* clear all cause mask */
4621 : 0 : ixgbe_disable_intr(hw);
4622 : :
4623 : : /* read-on-clear nic registers here */
4624 : 0 : eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
4625 : 0 : PMD_DRV_LOG(DEBUG, "eicr %x", eicr);
4626 : :
4627 : 0 : intr->flags = 0;
4628 : :
4629 : : /* set flag for async link update */
4630 [ # # ]: 0 : if (eicr & IXGBE_EICR_LSC)
4631 : 0 : intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4632 : :
4633 [ # # ]: 0 : if (eicr & IXGBE_EICR_MAILBOX)
4634 : 0 : intr->flags |= IXGBE_FLAG_MAILBOX;
4635 : :
4636 [ # # ]: 0 : if (eicr & IXGBE_EICR_LINKSEC)
4637 : 0 : intr->flags |= IXGBE_FLAG_MACSEC;
4638 : :
4639 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_X550EM_x &&
4640 [ # # ]: 0 : hw->phy.type == ixgbe_phy_x550em_ext_t &&
4641 [ # # ]: 0 : (eicr & IXGBE_EICR_GPI_SDP0_X550EM_x))
4642 : 0 : intr->flags |= IXGBE_FLAG_PHY_INTERRUPT;
4643 : :
4644 : 0 : return 0;
4645 : : }
4646 : :
4647 : : /**
4648 : : * It gets and then prints the link status.
4649 : : *
4650 : : * @param dev
4651 : : * Pointer to struct rte_eth_dev.
4652 : : *
4653 : : * @return
4654 : : * - On success, zero.
4655 : : * - On failure, a negative value.
4656 : : */
4657 : : static void
4658 : 0 : ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
4659 : : {
4660 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4661 : : struct rte_eth_link link;
4662 : :
4663 : 0 : rte_eth_linkstatus_get(dev, &link);
4664 : :
4665 [ # # ]: 0 : if (link.link_status) {
4666 [ # # ]: 0 : PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
4667 : : (int)(dev->data->port_id),
4668 : : (unsigned)link.link_speed,
4669 : : link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
4670 : : "full-duplex" : "half-duplex");
4671 : : } else {
4672 : 0 : PMD_INIT_LOG(INFO, " Port %d: Link Down",
4673 : : (int)(dev->data->port_id));
4674 : : }
4675 : 0 : PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
4676 : : pci_dev->addr.domain,
4677 : : pci_dev->addr.bus,
4678 : : pci_dev->addr.devid,
4679 : : pci_dev->addr.function);
4680 : 0 : }
4681 : :
4682 : : /*
4683 : : * It executes link_update after knowing an interrupt occurred.
4684 : : *
4685 : : * @param dev
4686 : : * Pointer to struct rte_eth_dev.
4687 : : *
4688 : : * @return
4689 : : * - On success, zero.
4690 : : * - On failure, a negative value.
4691 : : */
4692 : : static int
4693 : 0 : ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
4694 : : {
4695 : : struct ixgbe_interrupt *intr =
4696 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4697 : : int64_t timeout;
4698 : 0 : struct ixgbe_hw *hw =
4699 : : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4700 : :
4701 : 0 : PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
4702 : :
4703 [ # # ]: 0 : if (intr->flags & IXGBE_FLAG_MAILBOX) {
4704 : 0 : ixgbe_pf_mbx_process(dev);
4705 : 0 : intr->flags &= ~IXGBE_FLAG_MAILBOX;
4706 : : }
4707 : :
4708 [ # # ]: 0 : if (intr->flags & IXGBE_FLAG_PHY_INTERRUPT) {
4709 : 0 : ixgbe_handle_lasi(hw);
4710 : 0 : intr->flags &= ~IXGBE_FLAG_PHY_INTERRUPT;
4711 : : }
4712 : :
4713 [ # # ]: 0 : if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4714 : : struct rte_eth_link link;
4715 : :
4716 : : /* get the link status before link update, for predicting later */
4717 : 0 : rte_eth_linkstatus_get(dev, &link);
4718 : :
4719 : : ixgbe_dev_link_update(dev, 0);
4720 : :
4721 : : /* likely to up */
4722 [ # # ]: 0 : if (!link.link_status)
4723 : : /* handle it 1 sec later, wait it being stable */
4724 : : timeout = IXGBE_LINK_UP_CHECK_TIMEOUT;
4725 : : /* likely to down */
4726 : : else
4727 : : /* handle it 4 sec later, wait it being stable */
4728 : : timeout = IXGBE_LINK_DOWN_CHECK_TIMEOUT;
4729 : :
4730 : 0 : ixgbe_dev_link_status_print(dev);
4731 : :
4732 : : /* Don't program delayed handler if LSC interrupt is disabled.
4733 : : * It means one is already programmed.
4734 : : */
4735 [ # # ]: 0 : if (intr->mask & IXGBE_EIMS_LSC) {
4736 [ # # ]: 0 : if (rte_eal_alarm_set(timeout * 1000,
4737 : : ixgbe_dev_interrupt_delayed_handler, (void *)dev) < 0)
4738 : 0 : PMD_DRV_LOG(ERR, "Error setting alarm");
4739 : : else {
4740 : : /* remember original mask */
4741 : 0 : intr->mask_original = intr->mask;
4742 : : /* only disable lsc interrupt */
4743 : 0 : intr->mask &= ~IXGBE_EIMS_LSC;
4744 : : }
4745 : : }
4746 : : }
4747 : :
4748 : 0 : PMD_DRV_LOG(DEBUG, "enable intr immediately");
4749 : : ixgbe_enable_intr(dev);
4750 : :
4751 : 0 : return 0;
4752 : : }
4753 : :
4754 : : /**
4755 : : * Interrupt handler which shall be registered for alarm callback for delayed
4756 : : * handling specific interrupt to wait for the stable nic state. As the
4757 : : * NIC interrupt state is not stable for ixgbe after link is just down,
4758 : : * it needs to wait 4 seconds to get the stable status.
4759 : : *
4760 : : * @param handle
4761 : : * Pointer to interrupt handle.
4762 : : * @param param
4763 : : * The address of parameter (struct rte_eth_dev *) registered before.
4764 : : *
4765 : : * @return
4766 : : * void
4767 : : */
4768 : : static void
4769 : 0 : ixgbe_dev_interrupt_delayed_handler(void *param)
4770 : : {
4771 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
4772 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4773 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
4774 : : struct ixgbe_interrupt *intr =
4775 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
4776 : 0 : struct ixgbe_hw *hw =
4777 : : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4778 : : uint32_t eicr;
4779 : :
4780 : 0 : ixgbe_disable_intr(hw);
4781 : :
4782 : 0 : eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
4783 [ # # ]: 0 : if (eicr & IXGBE_EICR_MAILBOX)
4784 : 0 : ixgbe_pf_mbx_process(dev);
4785 : :
4786 [ # # ]: 0 : if (intr->flags & IXGBE_FLAG_PHY_INTERRUPT) {
4787 : 0 : ixgbe_handle_lasi(hw);
4788 : 0 : intr->flags &= ~IXGBE_FLAG_PHY_INTERRUPT;
4789 : : }
4790 : :
4791 [ # # ]: 0 : if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4792 : : ixgbe_dev_link_update(dev, 0);
4793 : 0 : intr->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4794 : 0 : ixgbe_dev_link_status_print(dev);
4795 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
4796 : : }
4797 : :
4798 [ # # ]: 0 : if (intr->flags & IXGBE_FLAG_MACSEC) {
4799 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_MACSEC, NULL);
4800 : 0 : intr->flags &= ~IXGBE_FLAG_MACSEC;
4801 : : }
4802 : :
4803 : : /* restore original mask */
4804 : 0 : intr->mask = intr->mask_original;
4805 : 0 : intr->mask_original = 0;
4806 : :
4807 : 0 : PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
4808 : : ixgbe_enable_intr(dev);
4809 : 0 : rte_intr_ack(intr_handle);
4810 : 0 : }
4811 : :
4812 : : /**
4813 : : * Interrupt handler triggered by NIC for handling
4814 : : * specific interrupt.
4815 : : *
4816 : : * @param handle
4817 : : * Pointer to interrupt handle.
4818 : : * @param param
4819 : : * The address of parameter (struct rte_eth_dev *) registered before.
4820 : : *
4821 : : * @return
4822 : : * void
4823 : : */
4824 : : static void
4825 : 0 : ixgbe_dev_interrupt_handler(void *param)
4826 : : {
4827 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
4828 : :
4829 : 0 : ixgbe_dev_interrupt_get_status(dev);
4830 : 0 : ixgbe_dev_interrupt_action(dev);
4831 : 0 : }
4832 : :
4833 : : static int
4834 : 0 : ixgbe_dev_led_on(struct rte_eth_dev *dev)
4835 : : {
4836 : : struct ixgbe_hw *hw;
4837 : :
4838 : : /*
4839 : : * This function calls into the base driver, which in turn will use
4840 : : * function pointers, which are not guaranteed to be valid in secondary
4841 : : * processes, so avoid using this function in secondary processes.
4842 : : */
4843 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
4844 : : return -E_RTE_SECONDARY;
4845 : :
4846 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4847 [ # # ]: 0 : return ixgbe_led_on(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP;
4848 : : }
4849 : :
4850 : : static int
4851 : 0 : ixgbe_dev_led_off(struct rte_eth_dev *dev)
4852 : : {
4853 : : struct ixgbe_hw *hw;
4854 : :
4855 : : /*
4856 : : * This function calls into the base driver, which in turn will use
4857 : : * function pointers, which are not guaranteed to be valid in secondary
4858 : : * processes, so avoid using this function in secondary processes.
4859 : : */
4860 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
4861 : : return -E_RTE_SECONDARY;
4862 : :
4863 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4864 [ # # ]: 0 : return ixgbe_led_off(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP;
4865 : : }
4866 : :
4867 : : static int
4868 : 0 : ixgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4869 : : {
4870 : : struct ixgbe_hw *hw;
4871 : : uint32_t mflcn_reg;
4872 : : uint32_t fccfg_reg;
4873 : : int rx_pause;
4874 : : int tx_pause;
4875 : :
4876 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4877 : :
4878 : 0 : fc_conf->pause_time = hw->fc.pause_time;
4879 : 0 : fc_conf->high_water = hw->fc.high_water[0];
4880 : 0 : fc_conf->low_water = hw->fc.low_water[0];
4881 : 0 : fc_conf->send_xon = hw->fc.send_xon;
4882 : 0 : fc_conf->autoneg = !hw->fc.disable_fc_autoneg;
4883 : :
4884 : : /*
4885 : : * Return rx_pause status according to actual setting of
4886 : : * MFLCN register.
4887 : : */
4888 : 0 : mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4889 [ # # ]: 0 : if (mflcn_reg & IXGBE_MFLCN_PMCF)
4890 : 0 : fc_conf->mac_ctrl_frame_fwd = 1;
4891 : : else
4892 : 0 : fc_conf->mac_ctrl_frame_fwd = 0;
4893 : :
4894 [ # # ]: 0 : if (mflcn_reg & (IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_RFCE))
4895 : : rx_pause = 1;
4896 : : else
4897 : : rx_pause = 0;
4898 : :
4899 : : /*
4900 : : * Return tx_pause status according to actual setting of
4901 : : * FCCFG register.
4902 : : */
4903 : 0 : fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
4904 [ # # ]: 0 : if (fccfg_reg & (IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY))
4905 : : tx_pause = 1;
4906 : : else
4907 : : tx_pause = 0;
4908 : :
4909 [ # # ]: 0 : if (rx_pause && tx_pause)
4910 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
4911 [ # # ]: 0 : else if (rx_pause)
4912 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
4913 [ # # ]: 0 : else if (tx_pause)
4914 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
4915 : : else
4916 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
4917 : :
4918 : 0 : return 0;
4919 : : }
4920 : :
4921 : : static int
4922 : 0 : ixgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4923 : : {
4924 : : struct ixgbe_hw *hw;
4925 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
4926 : : int err;
4927 : : uint32_t rx_buf_size;
4928 : : uint32_t max_high_water;
4929 : 0 : enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
4930 : : ixgbe_fc_none,
4931 : : ixgbe_fc_rx_pause,
4932 : : ixgbe_fc_tx_pause,
4933 : : ixgbe_fc_full
4934 : : };
4935 : :
4936 : : /*
4937 : : * This function calls into the base driver, which in turn will use
4938 : : * function pointers, which are not guaranteed to be valid in secondary
4939 : : * processes, so avoid using this function in secondary processes.
4940 : : */
4941 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
4942 : : return -E_RTE_SECONDARY;
4943 : :
4944 : 0 : PMD_INIT_FUNC_TRACE();
4945 : :
4946 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4947 : 0 : rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0));
4948 : 0 : PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
4949 : :
4950 : : /*
4951 : : * At least reserve one Ethernet frame for watermark
4952 : : * high_water/low_water in kilo bytes for ixgbe
4953 : : */
4954 : 0 : max_high_water = (rx_buf_size -
4955 : : RTE_ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
4956 [ # # ]: 0 : if ((fc_conf->high_water > max_high_water) ||
4957 [ # # ]: 0 : (fc_conf->high_water < fc_conf->low_water)) {
4958 : 0 : PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
4959 : 0 : PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
4960 : 0 : return -EINVAL;
4961 : : }
4962 : :
4963 : 0 : hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[fc_conf->mode];
4964 : 0 : hw->fc.pause_time = fc_conf->pause_time;
4965 : 0 : hw->fc.high_water[0] = fc_conf->high_water;
4966 : 0 : hw->fc.low_water[0] = fc_conf->low_water;
4967 : 0 : hw->fc.send_xon = fc_conf->send_xon;
4968 : 0 : hw->fc.disable_fc_autoneg = !fc_conf->autoneg;
4969 : 0 : adapter->mac_ctrl_frame_fwd = fc_conf->mac_ctrl_frame_fwd;
4970 : :
4971 : 0 : err = ixgbe_flow_ctrl_enable(dev, hw);
4972 [ # # ]: 0 : if (err < 0) {
4973 : 0 : PMD_INIT_LOG(ERR, "ixgbe_flow_ctrl_enable = 0x%x", err);
4974 : 0 : return -EIO;
4975 : : }
4976 : : return err;
4977 : : }
4978 : :
4979 : : /**
4980 : : * ixgbe_pfc_enable_generic - Enable flow control
4981 : : * @hw: pointer to hardware structure
4982 : : * @tc_num: traffic class number
4983 : : * Enable flow control according to the current settings.
4984 : : */
4985 : : static int
4986 : 0 : ixgbe_dcb_pfc_enable_generic(struct ixgbe_hw *hw, uint8_t tc_num)
4987 : : {
4988 : : int ret_val = 0;
4989 : : uint32_t mflcn_reg, fccfg_reg;
4990 : : uint32_t reg;
4991 : : uint32_t fcrtl, fcrth;
4992 : : uint8_t i;
4993 : : uint8_t nb_rx_en;
4994 : :
4995 : : /* Validate the water mark configuration */
4996 [ # # ]: 0 : if (!hw->fc.pause_time) {
4997 : : ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
4998 : 0 : goto out;
4999 : : }
5000 : :
5001 : : /* Low water mark of zero causes XOFF floods */
5002 [ # # ]: 0 : if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
5003 : : /* High/Low water can not be 0 */
5004 [ # # # # ]: 0 : if ((!hw->fc.high_water[tc_num]) || (!hw->fc.low_water[tc_num])) {
5005 : 0 : PMD_INIT_LOG(ERR, "Invalid water mark configuration");
5006 : : ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
5007 : 0 : goto out;
5008 : : }
5009 : :
5010 [ # # ]: 0 : if (hw->fc.low_water[tc_num] >= hw->fc.high_water[tc_num]) {
5011 : 0 : PMD_INIT_LOG(ERR, "Invalid water mark configuration");
5012 : : ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
5013 : 0 : goto out;
5014 : : }
5015 : : }
5016 : : /* Negotiate the fc mode to use */
5017 : 0 : ixgbe_fc_autoneg(hw);
5018 : :
5019 : : /* Disable any previous flow control settings */
5020 : 0 : mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5021 : 0 : mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_SHIFT | IXGBE_MFLCN_RFCE|IXGBE_MFLCN_RPFCE);
5022 : :
5023 : 0 : fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5024 : 0 : fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
5025 : :
5026 [ # # # # : 0 : switch (hw->fc.current_mode) {
# ]
5027 : : case ixgbe_fc_none:
5028 : : /*
5029 : : * If the count of enabled RX Priority Flow control >1,
5030 : : * and the TX pause can not be disabled
5031 : : */
5032 : : nb_rx_en = 0;
5033 [ # # ]: 0 : for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
5034 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
5035 [ # # ]: 0 : if (reg & IXGBE_FCRTH_FCEN)
5036 : 0 : nb_rx_en++;
5037 : : }
5038 [ # # ]: 0 : if (nb_rx_en > 1)
5039 : 0 : fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
5040 : : break;
5041 : 0 : case ixgbe_fc_rx_pause:
5042 : : /*
5043 : : * Rx Flow control is enabled and Tx Flow control is
5044 : : * disabled by software override. Since there really
5045 : : * isn't a way to advertise that we are capable of RX
5046 : : * Pause ONLY, we will advertise that we support both
5047 : : * symmetric and asymmetric Rx PAUSE. Later, we will
5048 : : * disable the adapter's ability to send PAUSE frames.
5049 : : */
5050 : 0 : mflcn_reg |= IXGBE_MFLCN_RPFCE;
5051 : : /*
5052 : : * If the count of enabled RX Priority Flow control >1,
5053 : : * and the TX pause can not be disabled
5054 : : */
5055 : : nb_rx_en = 0;
5056 [ # # ]: 0 : for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
5057 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
5058 [ # # ]: 0 : if (reg & IXGBE_FCRTH_FCEN)
5059 : 0 : nb_rx_en++;
5060 : : }
5061 [ # # ]: 0 : if (nb_rx_en > 1)
5062 : 0 : fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
5063 : : break;
5064 : 0 : case ixgbe_fc_tx_pause:
5065 : : /*
5066 : : * Tx Flow control is enabled, and Rx Flow control is
5067 : : * disabled by software override.
5068 : : */
5069 : 0 : fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
5070 : 0 : break;
5071 : 0 : case ixgbe_fc_full:
5072 : : /* Flow control (both Rx and Tx) is enabled by SW override. */
5073 : 0 : mflcn_reg |= IXGBE_MFLCN_RPFCE;
5074 : 0 : fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
5075 : 0 : break;
5076 : 0 : default:
5077 : 0 : PMD_DRV_LOG(DEBUG, "Flow control param set incorrectly");
5078 : : ret_val = IXGBE_ERR_CONFIG;
5079 : 0 : goto out;
5080 : : }
5081 : :
5082 : : /* Set 802.3x based flow control settings. */
5083 : 0 : mflcn_reg |= IXGBE_MFLCN_DPF;
5084 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
5085 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
5086 : :
5087 : : /* Set up and enable Rx high/low water mark thresholds, enable XON. */
5088 [ # # ]: 0 : if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
5089 [ # # ]: 0 : hw->fc.high_water[tc_num]) {
5090 : 0 : fcrtl = (hw->fc.low_water[tc_num] << 10) | IXGBE_FCRTL_XONE;
5091 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), fcrtl);
5092 : 0 : fcrth = (hw->fc.high_water[tc_num] << 10) | IXGBE_FCRTH_FCEN;
5093 : : } else {
5094 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), 0);
5095 : : /*
5096 : : * In order to prevent Tx hangs when the internal Tx
5097 : : * switch is enabled we must set the high water mark
5098 : : * to the maximum FCRTH value. This allows the Tx
5099 : : * switch to function even under heavy Rx workloads.
5100 : : */
5101 : 0 : fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num)) - 32;
5102 : : }
5103 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(tc_num), fcrth);
5104 : :
5105 : : /* Configure pause time (2 TCs per register) */
5106 : 0 : reg = hw->fc.pause_time * 0x00010001;
5107 [ # # ]: 0 : for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
5108 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
5109 : :
5110 : : /* Configure flow control refresh threshold value */
5111 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
5112 : :
5113 : 0 : out:
5114 : 0 : return ret_val;
5115 : : }
5116 : :
5117 : : static int
5118 : : ixgbe_dcb_pfc_enable(struct rte_eth_dev *dev, uint8_t tc_num)
5119 : : {
5120 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5121 : : int32_t ret_val = IXGBE_NOT_IMPLEMENTED;
5122 : :
5123 : 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
5124 : 0 : ret_val = ixgbe_dcb_pfc_enable_generic(hw, tc_num);
5125 : : }
5126 : : return ret_val;
5127 : : }
5128 : :
5129 : : static int
5130 : 0 : ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
5131 : : {
5132 : : int err;
5133 : : uint32_t rx_buf_size;
5134 : : uint32_t max_high_water;
5135 : : uint8_t tc_num;
5136 : 0 : uint8_t map[IXGBE_DCB_MAX_USER_PRIORITY] = { 0 };
5137 : : struct ixgbe_hw *hw =
5138 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5139 : 0 : struct ixgbe_dcb_config *dcb_config =
5140 : : IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
5141 : :
5142 : 0 : enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
5143 : : ixgbe_fc_none,
5144 : : ixgbe_fc_rx_pause,
5145 : : ixgbe_fc_tx_pause,
5146 : : ixgbe_fc_full
5147 : : };
5148 : :
5149 : : /*
5150 : : * This function calls into the base driver, which in turn will use
5151 : : * function pointers, which are not guaranteed to be valid in secondary
5152 : : * processes, so avoid using this function in secondary processes.
5153 : : */
5154 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5155 : : return -E_RTE_SECONDARY;
5156 : :
5157 : 0 : PMD_INIT_FUNC_TRACE();
5158 : :
5159 : 0 : ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_RX_CONFIG, map);
5160 : 0 : tc_num = map[pfc_conf->priority];
5161 : 0 : rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num));
5162 : 0 : PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
5163 : : /*
5164 : : * At least reserve one Ethernet frame for watermark
5165 : : * high_water/low_water in kilo bytes for ixgbe
5166 : : */
5167 : 0 : max_high_water = (rx_buf_size -
5168 : : RTE_ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
5169 [ # # ]: 0 : if ((pfc_conf->fc.high_water > max_high_water) ||
5170 [ # # ]: 0 : (pfc_conf->fc.high_water <= pfc_conf->fc.low_water)) {
5171 : 0 : PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
5172 : 0 : PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
5173 : 0 : return -EINVAL;
5174 : : }
5175 : :
5176 : 0 : hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[pfc_conf->fc.mode];
5177 : 0 : hw->fc.pause_time = pfc_conf->fc.pause_time;
5178 : 0 : hw->fc.send_xon = pfc_conf->fc.send_xon;
5179 : 0 : hw->fc.low_water[tc_num] = pfc_conf->fc.low_water;
5180 [ # # ]: 0 : hw->fc.high_water[tc_num] = pfc_conf->fc.high_water;
5181 : :
5182 : : err = ixgbe_dcb_pfc_enable(dev, tc_num);
5183 : :
5184 : : /* Not negotiated is not an error case */
5185 [ # # ]: 0 : if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED))
5186 : : return 0;
5187 : :
5188 : 0 : PMD_INIT_LOG(ERR, "ixgbe_dcb_pfc_enable = 0x%x", err);
5189 : 0 : return -EIO;
5190 : : }
5191 : :
5192 : : static int
5193 : 0 : ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
5194 : : struct rte_eth_rss_reta_entry64 *reta_conf,
5195 : : uint16_t reta_size)
5196 : : {
5197 : : uint16_t i, sp_reta_size;
5198 : : uint8_t j, mask;
5199 : : uint32_t reta, r;
5200 : : uint16_t idx, shift;
5201 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
5202 : : struct rte_eth_dev_data *dev_data = dev->data;
5203 : : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5204 : : uint32_t reta_reg;
5205 : :
5206 : 0 : PMD_INIT_FUNC_TRACE();
5207 : :
5208 [ # # ]: 0 : if (!dev_data->dev_started) {
5209 : 0 : PMD_DRV_LOG(ERR,
5210 : : "port %d must be started before rss reta update",
5211 : : dev_data->port_id);
5212 : 0 : return -EIO;
5213 : : }
5214 : :
5215 [ # # ]: 0 : if (!ixgbe_rss_update_sp(hw->mac.type)) {
5216 : 0 : PMD_DRV_LOG(ERR, "RSS reta update is not supported on this "
5217 : : "NIC.");
5218 : 0 : return -ENOTSUP;
5219 : : }
5220 : :
5221 : 0 : sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
5222 [ # # ]: 0 : if (reta_size != sp_reta_size) {
5223 : 0 : PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
5224 : : "(%d) doesn't match the number hardware can supported "
5225 : : "(%d)", reta_size, sp_reta_size);
5226 : 0 : return -EINVAL;
5227 : : }
5228 : :
5229 [ # # ]: 0 : for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
5230 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
5231 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
5232 : 0 : mask = (uint8_t)((reta_conf[idx].mask >> shift) &
5233 : : IXGBE_4_BIT_MASK);
5234 [ # # ]: 0 : if (!mask)
5235 : 0 : continue;
5236 : 0 : reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
5237 [ # # ]: 0 : if (mask == IXGBE_4_BIT_MASK)
5238 : : r = 0;
5239 : : else
5240 : 0 : r = IXGBE_READ_REG(hw, reta_reg);
5241 [ # # ]: 0 : for (j = 0, reta = 0; j < IXGBE_4_BIT_WIDTH; j++) {
5242 [ # # ]: 0 : if (mask & (0x1 << j))
5243 : 0 : reta |= reta_conf[idx].reta[shift + j] <<
5244 : 0 : (CHAR_BIT * j);
5245 : : else
5246 : 0 : reta |= r & (IXGBE_8_BIT_MASK <<
5247 : 0 : (CHAR_BIT * j));
5248 : : }
5249 : 0 : IXGBE_WRITE_REG(hw, reta_reg, reta);
5250 : : }
5251 : 0 : adapter->rss_reta_updated = 1;
5252 : :
5253 : 0 : return 0;
5254 : : }
5255 : :
5256 : : static int
5257 : 0 : ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
5258 : : struct rte_eth_rss_reta_entry64 *reta_conf,
5259 : : uint16_t reta_size)
5260 : : {
5261 : : uint16_t i, sp_reta_size;
5262 : : uint8_t j, mask;
5263 : : uint32_t reta;
5264 : : uint16_t idx, shift;
5265 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5266 : : uint32_t reta_reg;
5267 : :
5268 : 0 : PMD_INIT_FUNC_TRACE();
5269 : 0 : sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
5270 [ # # ]: 0 : if (reta_size != sp_reta_size) {
5271 : 0 : PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
5272 : : "(%d) doesn't match the number hardware can supported "
5273 : : "(%d)", reta_size, sp_reta_size);
5274 : 0 : return -EINVAL;
5275 : : }
5276 : :
5277 [ # # ]: 0 : for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
5278 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
5279 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
5280 : 0 : mask = (uint8_t)((reta_conf[idx].mask >> shift) &
5281 : : IXGBE_4_BIT_MASK);
5282 [ # # ]: 0 : if (!mask)
5283 : 0 : continue;
5284 : :
5285 : 0 : reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
5286 : 0 : reta = IXGBE_READ_REG(hw, reta_reg);
5287 [ # # ]: 0 : for (j = 0; j < IXGBE_4_BIT_WIDTH; j++) {
5288 [ # # ]: 0 : if (mask & (0x1 << j))
5289 : 0 : reta_conf[idx].reta[shift + j] =
5290 : 0 : ((reta >> (CHAR_BIT * j)) &
5291 : : IXGBE_8_BIT_MASK);
5292 : : }
5293 : : }
5294 : :
5295 : : return 0;
5296 : : }
5297 : :
5298 : : static int
5299 : 0 : ixgbe_add_rar(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
5300 : : uint32_t index, uint32_t pool)
5301 : : {
5302 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5303 : : uint32_t enable_addr = 1;
5304 : :
5305 : : /*
5306 : : * This function calls into the base driver, which in turn will use
5307 : : * function pointers, which are not guaranteed to be valid in secondary
5308 : : * processes, so avoid using this function in secondary processes.
5309 : : */
5310 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5311 : : return -E_RTE_SECONDARY;
5312 : :
5313 : 0 : return ixgbe_set_rar(hw, index, mac_addr->addr_bytes,
5314 : : pool, enable_addr);
5315 : : }
5316 : :
5317 : : static void
5318 : 0 : ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index)
5319 : : {
5320 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5321 : :
5322 : : /*
5323 : : * This function calls into the base driver, which in turn will use
5324 : : * function pointers, which are not guaranteed to be valid in secondary
5325 : : * processes, so avoid using this function in secondary processes.
5326 : : */
5327 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5328 : : return;
5329 : :
5330 : 0 : ixgbe_clear_rar(hw, index);
5331 : : }
5332 : :
5333 : : static int
5334 : 0 : ixgbe_set_default_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
5335 : : {
5336 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5337 : :
5338 : : /*
5339 : : * This function calls into the base driver, which in turn will use
5340 : : * function pointers, which are not guaranteed to be valid in secondary
5341 : : * processes, so avoid using this function in secondary processes.
5342 : : */
5343 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5344 : : return -E_RTE_SECONDARY;
5345 : :
5346 : 0 : ixgbe_remove_rar(dev, 0);
5347 : 0 : ixgbe_add_rar(dev, addr, 0, pci_dev->max_vfs);
5348 : :
5349 : 0 : return 0;
5350 : : }
5351 : :
5352 : : static bool
5353 : : is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
5354 : : {
5355 : 0 : if (strcmp(dev->device->driver->name, drv->driver.name))
5356 : 0 : return false;
5357 : :
5358 : : return true;
5359 : : }
5360 : :
5361 : : bool
5362 [ # # ]: 0 : is_ixgbe_supported(struct rte_eth_dev *dev)
5363 : : {
5364 : 0 : return is_device_supported(dev, &rte_ixgbe_pmd);
5365 : : }
5366 : :
5367 : : static int
5368 : 0 : ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
5369 : : {
5370 : : uint32_t hlreg0;
5371 : : uint32_t maxfrs;
5372 : : struct ixgbe_hw *hw;
5373 : : struct rte_eth_dev_info dev_info;
5374 : 0 : uint32_t frame_size = mtu + IXGBE_ETH_OVERHEAD;
5375 : : int ret;
5376 : :
5377 : 0 : ret = ixgbe_dev_info_get(dev, &dev_info);
5378 [ # # ]: 0 : if (ret != 0)
5379 : : return ret;
5380 : :
5381 : : /* check that mtu is within the allowed range */
5382 [ # # # # ]: 0 : if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen)
5383 : : return -EINVAL;
5384 : :
5385 : : /* If device is started, refuse mtu that requires the support of
5386 : : * scattered packets when this feature has not been enabled before.
5387 : : */
5388 [ # # ]: 0 : if (dev->data->dev_started && !dev->data->scattered_rx &&
5389 : 0 : frame_size + 2 * RTE_VLAN_HLEN >
5390 [ # # ]: 0 : dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
5391 : 0 : PMD_INIT_LOG(ERR, "Stop port first.");
5392 : 0 : return -EINVAL;
5393 : : }
5394 : :
5395 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5396 : 0 : hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
5397 : :
5398 : : /* switch to jumbo mode if needed */
5399 [ # # ]: 0 : if (mtu > RTE_ETHER_MTU)
5400 : 0 : hlreg0 |= IXGBE_HLREG0_JUMBOEN;
5401 : : else
5402 : 0 : hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
5403 : 0 : IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
5404 : :
5405 : 0 : maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
5406 : 0 : maxfrs &= 0x0000FFFF;
5407 : 0 : maxfrs |= (frame_size << 16);
5408 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, maxfrs);
5409 : :
5410 : 0 : return 0;
5411 : : }
5412 : :
5413 : : /*
5414 : : * Virtual Function operations
5415 : : */
5416 : : static void
5417 : 0 : ixgbevf_intr_disable(struct rte_eth_dev *dev)
5418 : : {
5419 : : struct ixgbe_interrupt *intr =
5420 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
5421 : : struct ixgbe_hw *hw =
5422 : : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5423 : :
5424 : 0 : PMD_INIT_FUNC_TRACE();
5425 : :
5426 : : /* Clear interrupt mask to stop from interrupts being generated */
5427 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
5428 : :
5429 : 0 : IXGBE_WRITE_FLUSH(hw);
5430 : :
5431 : : /* Clear mask value. */
5432 : 0 : intr->mask = 0;
5433 : 0 : }
5434 : :
5435 : : static void
5436 : 0 : ixgbevf_intr_enable(struct rte_eth_dev *dev)
5437 : : {
5438 : : struct ixgbe_interrupt *intr =
5439 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
5440 : : struct ixgbe_hw *hw =
5441 : : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5442 : :
5443 : 0 : PMD_INIT_FUNC_TRACE();
5444 : :
5445 : : /* VF enable interrupt autoclean */
5446 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, IXGBE_VF_IRQ_ENABLE_MASK);
5447 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, IXGBE_VF_IRQ_ENABLE_MASK);
5448 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, IXGBE_VF_IRQ_ENABLE_MASK);
5449 : :
5450 : 0 : IXGBE_WRITE_FLUSH(hw);
5451 : :
5452 : : /* Save IXGBE_VTEIMS value to mask. */
5453 : 0 : intr->mask = IXGBE_VF_IRQ_ENABLE_MASK;
5454 : 0 : }
5455 : :
5456 : : static int
5457 : 0 : ixgbevf_dev_configure(struct rte_eth_dev *dev)
5458 : : {
5459 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
5460 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
5461 : :
5462 : 0 : PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
5463 : : dev->data->port_id);
5464 : :
5465 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
5466 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
5467 : :
5468 : : /*
5469 : : * VF has no ability to enable/disable HW CRC
5470 : : * Keep the persistent behavior the same as Host PF
5471 : : */
5472 : : #ifndef RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC
5473 [ # # ]: 0 : if (conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
5474 : 0 : PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
5475 : 0 : conf->rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_KEEP_CRC;
5476 : : }
5477 : : #else
5478 : : if (!(conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)) {
5479 : : PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
5480 : : conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
5481 : : }
5482 : : #endif
5483 : :
5484 : : /*
5485 : : * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
5486 : : * allocation or vector Rx preconditions we will reset it.
5487 : : */
5488 : 0 : adapter->rx_bulk_alloc_allowed = true;
5489 : 0 : adapter->rx_vec_allowed = true;
5490 : :
5491 : 0 : return 0;
5492 : : }
5493 : :
5494 : : static int
5495 : 0 : ixgbevf_dev_start(struct rte_eth_dev *dev)
5496 : : {
5497 : 0 : struct ixgbe_hw *hw =
5498 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5499 : : uint32_t intr_vector = 0;
5500 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5501 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5502 : :
5503 : : int err, mask = 0;
5504 : :
5505 : : /*
5506 : : * This function calls into the base driver, which in turn will use
5507 : : * function pointers, which are not guaranteed to be valid in secondary
5508 : : * processes, so avoid using this function in secondary processes.
5509 : : */
5510 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5511 : : return -E_RTE_SECONDARY;
5512 : :
5513 : 0 : PMD_INIT_FUNC_TRACE();
5514 : :
5515 : : /* Stop the link setup handler before resetting the HW. */
5516 : 0 : ixgbe_dev_wait_setup_link_complete(dev, 0);
5517 : :
5518 : 0 : err = hw->mac.ops.reset_hw(hw);
5519 : :
5520 : : /**
5521 : : * In this case, reuses the MAC address assigned by VF
5522 : : * initialization.
5523 : : */
5524 [ # # ]: 0 : if (err != IXGBE_SUCCESS && err != IXGBE_ERR_INVALID_MAC_ADDR) {
5525 : 0 : PMD_INIT_LOG(ERR, "Unable to reset vf hardware (%d)", err);
5526 : 0 : return err;
5527 : : }
5528 : :
5529 : 0 : hw->mac.get_link_status = true;
5530 : :
5531 : : /* negotiate mailbox API version to use with the PF. */
5532 : 0 : ixgbevf_negotiate_api(hw);
5533 : :
5534 : 0 : ixgbevf_dev_tx_init(dev);
5535 : :
5536 : : /* This can fail when allocating mbufs for descriptor rings */
5537 : 0 : err = ixgbevf_dev_rx_init(dev);
5538 [ # # ]: 0 : if (err) {
5539 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
5540 : 0 : ixgbe_dev_clear_queues(dev);
5541 : 0 : return err;
5542 : : }
5543 : :
5544 : : /* Set vfta */
5545 : 0 : ixgbevf_set_vfta_all(dev, 1);
5546 : :
5547 : : /* Set HW strip */
5548 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
5549 : : RTE_ETH_VLAN_EXTEND_MASK;
5550 : 0 : err = ixgbevf_vlan_offload_config(dev, mask);
5551 [ # # ]: 0 : if (err) {
5552 : 0 : PMD_INIT_LOG(ERR, "Unable to set VLAN offload (%d)", err);
5553 : 0 : ixgbe_dev_clear_queues(dev);
5554 : 0 : return err;
5555 : : }
5556 : :
5557 : 0 : ixgbevf_dev_rxtx_start(dev);
5558 : :
5559 : : /* check and configure queue intr-vector mapping */
5560 [ # # ]: 0 : if (rte_intr_cap_multiple(intr_handle) &&
5561 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq) {
5562 : : /* According to datasheet, only vector 0/1/2 can be used,
5563 : : * now only one vector is used for Rx queue
5564 : : */
5565 : : intr_vector = 1;
5566 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector)) {
5567 : 0 : ixgbe_dev_clear_queues(dev);
5568 : 0 : return -1;
5569 : : }
5570 : : }
5571 : :
5572 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
5573 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
5574 : 0 : dev->data->nb_rx_queues)) {
5575 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
5576 : : " intr_vec", dev->data->nb_rx_queues);
5577 : 0 : ixgbe_dev_clear_queues(dev);
5578 : 0 : return -ENOMEM;
5579 : : }
5580 : : }
5581 : 0 : ixgbevf_configure_msix(dev);
5582 : :
5583 : : /* When a VF port is bound to VFIO-PCI, only miscellaneous interrupt
5584 : : * is mapped to VFIO vector 0 in eth_ixgbevf_dev_init( ).
5585 : : * If previous VFIO interrupt mapping setting in eth_ixgbevf_dev_init( )
5586 : : * is not cleared, it will fail when following rte_intr_enable( ) tries
5587 : : * to map Rx queue interrupt to other VFIO vectors.
5588 : : * So clear uio/vfio intr/evevnfd first to avoid failure.
5589 : : */
5590 : 0 : rte_intr_disable(intr_handle);
5591 : :
5592 : 0 : rte_intr_enable(intr_handle);
5593 : :
5594 : : /* Re-enable interrupt for VF */
5595 : 0 : ixgbevf_intr_enable(dev);
5596 : :
5597 : : /*
5598 : : * Update link status right before return, because it may
5599 : : * start link configuration process in a separate thread.
5600 : : */
5601 : : ixgbevf_dev_link_update(dev, 0);
5602 : :
5603 : 0 : hw->adapter_stopped = false;
5604 : :
5605 : 0 : return 0;
5606 : : }
5607 : :
5608 : : static int
5609 : 0 : ixgbevf_dev_stop(struct rte_eth_dev *dev)
5610 : : {
5611 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5612 : : struct ixgbe_adapter *adapter = dev->data->dev_private;
5613 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5614 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5615 : :
5616 : : /*
5617 : : * This function calls into the base driver, which in turn will use
5618 : : * function pointers, which are not guaranteed to be valid in secondary
5619 : : * processes, so avoid using this function in secondary processes.
5620 : : */
5621 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5622 : : return -E_RTE_SECONDARY;
5623 : :
5624 [ # # ]: 0 : if (hw->adapter_stopped)
5625 : : return 0;
5626 : :
5627 : 0 : PMD_INIT_FUNC_TRACE();
5628 : :
5629 : 0 : ixgbe_dev_wait_setup_link_complete(dev, 0);
5630 : :
5631 : 0 : ixgbevf_intr_disable(dev);
5632 : :
5633 : 0 : dev->data->dev_started = 0;
5634 : 0 : hw->adapter_stopped = 1;
5635 : 0 : ixgbe_stop_adapter(hw);
5636 : :
5637 : : /*
5638 : : * Clear what we set, but we still keep shadow_vfta to
5639 : : * restore after device starts
5640 : : */
5641 : 0 : ixgbevf_set_vfta_all(dev, 0);
5642 : :
5643 : : /* Clear stored conf */
5644 : 0 : dev->data->scattered_rx = 0;
5645 : :
5646 : 0 : ixgbe_dev_clear_queues(dev);
5647 : :
5648 : : /* Clean datapath event and queue/vec mapping */
5649 : 0 : rte_intr_efd_disable(intr_handle);
5650 : 0 : rte_intr_vec_list_free(intr_handle);
5651 : :
5652 : 0 : adapter->rss_reta_updated = 0;
5653 : :
5654 : 0 : return 0;
5655 : : }
5656 : :
5657 : : static int
5658 : 0 : ixgbevf_dev_close(struct rte_eth_dev *dev)
5659 : : {
5660 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5661 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5662 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5663 : : int ret;
5664 : :
5665 : 0 : PMD_INIT_FUNC_TRACE();
5666 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5667 : : return 0;
5668 : :
5669 : 0 : ixgbe_reset_hw(hw);
5670 : :
5671 : 0 : ret = ixgbevf_dev_stop(dev);
5672 : :
5673 : 0 : ixgbe_dev_free_queues(dev);
5674 : :
5675 : : /**
5676 : : * Remove the VF MAC address ro ensure
5677 : : * that the VF traffic goes to the PF
5678 : : * after stop, close and detach of the VF
5679 : : **/
5680 : 0 : ixgbevf_remove_mac_addr(dev, 0);
5681 : :
5682 : 0 : rte_intr_disable(intr_handle);
5683 : 0 : rte_intr_callback_unregister(intr_handle,
5684 : : ixgbevf_dev_interrupt_handler, dev);
5685 : :
5686 : 0 : return ret;
5687 : : }
5688 : :
5689 : : /*
5690 : : * Reset VF device
5691 : : */
5692 : : static int
5693 : 0 : ixgbevf_dev_reset(struct rte_eth_dev *dev)
5694 : : {
5695 : : int ret;
5696 : :
5697 : 0 : ret = eth_ixgbevf_dev_uninit(dev);
5698 [ # # ]: 0 : if (ret)
5699 : : return ret;
5700 : :
5701 : 0 : ret = eth_ixgbevf_dev_init(dev);
5702 : :
5703 : 0 : return ret;
5704 : : }
5705 : :
5706 : 0 : static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
5707 : : {
5708 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5709 : : struct ixgbe_vfta *shadow_vfta =
5710 : : IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
5711 : : int i = 0, j = 0, vfta = 0, mask = 1;
5712 : :
5713 [ # # ]: 0 : for (i = 0; i < IXGBE_VFTA_SIZE; i++) {
5714 : 0 : vfta = shadow_vfta->vfta[i];
5715 [ # # ]: 0 : if (vfta) {
5716 : : mask = 1;
5717 [ # # ]: 0 : for (j = 0; j < 32; j++) {
5718 [ # # ]: 0 : if (vfta & mask)
5719 : 0 : ixgbe_set_vfta(hw, (i<<5)+j, 0,
5720 : : on, false);
5721 : 0 : mask <<= 1;
5722 : : }
5723 : : }
5724 : : }
5725 : :
5726 : 0 : }
5727 : :
5728 : : static int
5729 : 0 : ixgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
5730 : : {
5731 : 0 : struct ixgbe_hw *hw =
5732 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5733 : : struct ixgbe_vfta *shadow_vfta =
5734 : : IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
5735 : : uint32_t vid_idx = 0;
5736 : : uint32_t vid_bit = 0;
5737 : : int ret = 0;
5738 : :
5739 : : /*
5740 : : * This function calls into the base driver, which in turn will use
5741 : : * function pointers, which are not guaranteed to be valid in secondary
5742 : : * processes, so avoid using this function in secondary processes.
5743 : : */
5744 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5745 : : return -E_RTE_SECONDARY;
5746 : :
5747 : 0 : PMD_INIT_FUNC_TRACE();
5748 : :
5749 : : /* vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf */
5750 : 0 : ret = ixgbe_set_vfta(hw, vlan_id, 0, !!on, false);
5751 [ # # ]: 0 : if (ret) {
5752 : 0 : PMD_INIT_LOG(ERR, "Unable to set VF vlan");
5753 : 0 : return ret;
5754 : : }
5755 : 0 : vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
5756 : 0 : vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
5757 : :
5758 : : /* Save what we set and retore it after device reset */
5759 [ # # ]: 0 : if (on)
5760 : 0 : shadow_vfta->vfta[vid_idx] |= vid_bit;
5761 : : else
5762 : 0 : shadow_vfta->vfta[vid_idx] &= ~vid_bit;
5763 : :
5764 : : return 0;
5765 : : }
5766 : :
5767 : : static void
5768 : 0 : ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
5769 : : {
5770 : : struct ixgbe_hw *hw =
5771 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5772 : : uint32_t ctrl;
5773 : :
5774 : 0 : PMD_INIT_FUNC_TRACE();
5775 : :
5776 [ # # ]: 0 : if (queue >= hw->mac.max_rx_queues)
5777 : : return;
5778 : :
5779 [ # # ]: 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
5780 [ # # ]: 0 : if (on)
5781 : 0 : ctrl |= IXGBE_RXDCTL_VME;
5782 : : else
5783 : 0 : ctrl &= ~IXGBE_RXDCTL_VME;
5784 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
5785 : :
5786 : 0 : ixgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
5787 : : }
5788 : :
5789 : : static int
5790 : 0 : ixgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
5791 : : {
5792 : : struct ixgbe_rx_queue *rxq;
5793 : : uint16_t i;
5794 : : int on = 0;
5795 : :
5796 : : /* VF function only support hw strip feature, others are not support */
5797 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
5798 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
5799 : 0 : rxq = dev->data->rx_queues[i];
5800 : 0 : on = !!(rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
5801 : 0 : ixgbevf_vlan_strip_queue_set(dev, i, on);
5802 : : }
5803 : : }
5804 : :
5805 : 0 : return 0;
5806 : : }
5807 : :
5808 : : static int
5809 : 0 : ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
5810 : : {
5811 : 0 : ixgbe_config_vlan_strip_on_all_queues(dev, mask);
5812 : :
5813 : 0 : ixgbevf_vlan_offload_config(dev, mask);
5814 : :
5815 : 0 : return 0;
5816 : : }
5817 : :
5818 : : int
5819 : 0 : ixgbe_vt_check(struct ixgbe_hw *hw)
5820 : : {
5821 : : uint32_t reg_val;
5822 : :
5823 : : /* if Virtualization Technology is enabled */
5824 : 0 : reg_val = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
5825 [ # # ]: 0 : if (!(reg_val & IXGBE_VT_CTL_VT_ENABLE)) {
5826 : 0 : PMD_INIT_LOG(ERR, "VT must be enabled for this setting");
5827 : 0 : return -1;
5828 : : }
5829 : :
5830 : : return 0;
5831 : : }
5832 : :
5833 : : static uint32_t
5834 : 0 : ixgbe_uta_vector(struct ixgbe_hw *hw, struct rte_ether_addr *uc_addr)
5835 : : {
5836 : : uint32_t vector = 0;
5837 : :
5838 [ # # # # : 0 : switch (hw->mac.mc_filter_type) {
# ]
5839 : 0 : case 0: /* use bits [47:36] of the address */
5840 : 0 : vector = ((uc_addr->addr_bytes[4] >> 4) |
5841 : 0 : (((uint16_t)uc_addr->addr_bytes[5]) << 4));
5842 : 0 : break;
5843 : 0 : case 1: /* use bits [46:35] of the address */
5844 : 0 : vector = ((uc_addr->addr_bytes[4] >> 3) |
5845 : 0 : (((uint16_t)uc_addr->addr_bytes[5]) << 5));
5846 : 0 : break;
5847 : 0 : case 2: /* use bits [45:34] of the address */
5848 : 0 : vector = ((uc_addr->addr_bytes[4] >> 2) |
5849 : 0 : (((uint16_t)uc_addr->addr_bytes[5]) << 6));
5850 : 0 : break;
5851 : 0 : case 3: /* use bits [43:32] of the address */
5852 : 0 : vector = ((uc_addr->addr_bytes[4]) |
5853 : 0 : (((uint16_t)uc_addr->addr_bytes[5]) << 8));
5854 : 0 : break;
5855 : : default: /* Invalid mc_filter_type */
5856 : : break;
5857 : : }
5858 : :
5859 : : /* vector can only be 12-bits or boundary will be exceeded */
5860 : 0 : vector &= 0xFFF;
5861 : 0 : return vector;
5862 : : }
5863 : :
5864 : : static int
5865 : 0 : ixgbe_uc_hash_table_set(struct rte_eth_dev *dev,
5866 : : struct rte_ether_addr *mac_addr, uint8_t on)
5867 : : {
5868 : : uint32_t vector;
5869 : : uint32_t uta_idx;
5870 : : uint32_t reg_val;
5871 : : uint32_t uta_shift;
5872 : : uint32_t rc;
5873 : : const uint32_t ixgbe_uta_idx_mask = 0x7F;
5874 : : const uint32_t ixgbe_uta_bit_shift = 5;
5875 : : const uint32_t ixgbe_uta_bit_mask = (0x1 << ixgbe_uta_bit_shift) - 1;
5876 : : const uint32_t bit1 = 0x1;
5877 : :
5878 : 0 : struct ixgbe_hw *hw =
5879 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5880 : : struct ixgbe_uta_info *uta_info =
5881 : : IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
5882 : :
5883 : : /* The UTA table only exists on 82599 hardware and newer */
5884 [ # # ]: 0 : if (hw->mac.type < ixgbe_mac_82599EB)
5885 : : return -ENOTSUP;
5886 : :
5887 : 0 : vector = ixgbe_uta_vector(hw, mac_addr);
5888 : 0 : uta_idx = (vector >> ixgbe_uta_bit_shift) & ixgbe_uta_idx_mask;
5889 : 0 : uta_shift = vector & ixgbe_uta_bit_mask;
5890 : :
5891 : 0 : rc = ((uta_info->uta_shadow[uta_idx] >> uta_shift & bit1) != 0);
5892 [ # # ]: 0 : if (rc == on)
5893 : : return 0;
5894 : :
5895 : 0 : reg_val = IXGBE_READ_REG(hw, IXGBE_UTA(uta_idx));
5896 [ # # ]: 0 : if (on) {
5897 : 0 : uta_info->uta_in_use++;
5898 : 0 : reg_val |= (bit1 << uta_shift);
5899 : 0 : uta_info->uta_shadow[uta_idx] |= (bit1 << uta_shift);
5900 : : } else {
5901 : 0 : uta_info->uta_in_use--;
5902 : 0 : reg_val &= ~(bit1 << uta_shift);
5903 : 0 : uta_info->uta_shadow[uta_idx] &= ~(bit1 << uta_shift);
5904 : : }
5905 : :
5906 : 0 : IXGBE_WRITE_REG(hw, IXGBE_UTA(uta_idx), reg_val);
5907 : :
5908 [ # # ]: 0 : if (uta_info->uta_in_use > 0)
5909 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
5910 : : IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
5911 : : else
5912 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
5913 : :
5914 : : return 0;
5915 : : }
5916 : :
5917 : : static int
5918 : 0 : ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on)
5919 : : {
5920 : : int i;
5921 : : struct ixgbe_hw *hw =
5922 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5923 : : struct ixgbe_uta_info *uta_info =
5924 : : IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
5925 : :
5926 : : /* The UTA table only exists on 82599 hardware and newer */
5927 [ # # ]: 0 : if (hw->mac.type < ixgbe_mac_82599EB)
5928 : : return -ENOTSUP;
5929 : :
5930 [ # # ]: 0 : if (on) {
5931 [ # # ]: 0 : for (i = 0; i < RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
5932 : 0 : uta_info->uta_shadow[i] = ~0;
5933 : 0 : IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
5934 : : }
5935 : : } else {
5936 [ # # ]: 0 : for (i = 0; i < RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
5937 : 0 : uta_info->uta_shadow[i] = 0;
5938 : 0 : IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
5939 : : }
5940 : : }
5941 : : return 0;
5942 : :
5943 : : }
5944 : :
5945 : : uint32_t
5946 : 0 : ixgbe_convert_vm_rx_mask_to_val(uint16_t rx_mask, uint32_t orig_val)
5947 : : {
5948 : : uint32_t new_val = orig_val;
5949 : :
5950 [ # # ]: 0 : if (rx_mask & RTE_ETH_VMDQ_ACCEPT_UNTAG)
5951 : 0 : new_val |= IXGBE_VMOLR_AUPE;
5952 [ # # ]: 0 : if (rx_mask & RTE_ETH_VMDQ_ACCEPT_HASH_MC)
5953 : 0 : new_val |= IXGBE_VMOLR_ROMPE;
5954 [ # # ]: 0 : if (rx_mask & RTE_ETH_VMDQ_ACCEPT_HASH_UC)
5955 : 0 : new_val |= IXGBE_VMOLR_ROPE;
5956 [ # # ]: 0 : if (rx_mask & RTE_ETH_VMDQ_ACCEPT_BROADCAST)
5957 : 0 : new_val |= IXGBE_VMOLR_BAM;
5958 [ # # ]: 0 : if (rx_mask & RTE_ETH_VMDQ_ACCEPT_MULTICAST)
5959 : 0 : new_val |= IXGBE_VMOLR_MPE;
5960 : :
5961 : 0 : return new_val;
5962 : : }
5963 : :
5964 : : static int
5965 : 0 : ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
5966 : : {
5967 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5968 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5969 : : struct ixgbe_interrupt *intr =
5970 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
5971 : : struct ixgbe_hw *hw =
5972 : : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5973 : : uint32_t vec = IXGBE_MISC_VEC_ID;
5974 : :
5975 : : /* device interrupts are only subscribed to in primary processes */
5976 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5977 : : return -E_RTE_SECONDARY;
5978 : :
5979 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
5980 : : vec = IXGBE_RX_VEC_START;
5981 : 0 : intr->mask |= (1 << vec);
5982 : : RTE_SET_USED(queue_id);
5983 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, intr->mask);
5984 : :
5985 : 0 : rte_intr_ack(intr_handle);
5986 : :
5987 : 0 : return 0;
5988 : : }
5989 : :
5990 : : static int
5991 : 0 : ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
5992 : : {
5993 : : struct ixgbe_interrupt *intr =
5994 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
5995 : : struct ixgbe_hw *hw =
5996 : : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5997 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5998 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5999 : : uint32_t vec = IXGBE_MISC_VEC_ID;
6000 : :
6001 : : /* device interrupts are only subscribed to in primary processes */
6002 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6003 : : return -E_RTE_SECONDARY;
6004 : :
6005 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
6006 : : vec = IXGBE_RX_VEC_START;
6007 : 0 : intr->mask &= ~(1 << vec);
6008 : : RTE_SET_USED(queue_id);
6009 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, intr->mask);
6010 : :
6011 : 0 : return 0;
6012 : : }
6013 : :
6014 : : static int
6015 : 0 : ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
6016 : : {
6017 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
6018 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
6019 : : uint32_t mask;
6020 : 0 : struct ixgbe_hw *hw =
6021 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6022 : : struct ixgbe_interrupt *intr =
6023 : : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
6024 : :
6025 : : /* device interrupts are only subscribed to in primary processes */
6026 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6027 : : return -E_RTE_SECONDARY;
6028 : :
6029 [ # # ]: 0 : if (queue_id < 16) {
6030 : 0 : ixgbe_disable_intr(hw);
6031 : 0 : intr->mask |= (1 << queue_id);
6032 : : ixgbe_enable_intr(dev);
6033 [ # # ]: 0 : } else if (queue_id < 32) {
6034 : 0 : mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(0));
6035 : 0 : mask &= (1 << queue_id);
6036 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
6037 [ # # ]: 0 : } else if (queue_id < 64) {
6038 : 0 : mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(1));
6039 : 0 : mask &= (1 << (queue_id - 32));
6040 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
6041 : : }
6042 : 0 : rte_intr_ack(intr_handle);
6043 : :
6044 : 0 : return 0;
6045 : : }
6046 : :
6047 : : static int
6048 : 0 : ixgbe_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
6049 : : {
6050 : : uint32_t mask;
6051 : 0 : struct ixgbe_hw *hw =
6052 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6053 : : struct ixgbe_interrupt *intr =
6054 : : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
6055 : :
6056 : : /* device interrupts are only subscribed to in primary processes */
6057 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6058 : : return -E_RTE_SECONDARY;
6059 : :
6060 [ # # ]: 0 : if (queue_id < 16) {
6061 : 0 : ixgbe_disable_intr(hw);
6062 : 0 : intr->mask &= ~(1 << queue_id);
6063 : : ixgbe_enable_intr(dev);
6064 [ # # ]: 0 : } else if (queue_id < 32) {
6065 : 0 : mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(0));
6066 : 0 : mask &= ~(1 << queue_id);
6067 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
6068 [ # # ]: 0 : } else if (queue_id < 64) {
6069 : 0 : mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(1));
6070 : 0 : mask &= ~(1 << (queue_id - 32));
6071 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
6072 : : }
6073 : :
6074 : : return 0;
6075 : : }
6076 : :
6077 : : static void
6078 : 0 : ixgbevf_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
6079 : : uint8_t queue, uint8_t msix_vector)
6080 : : {
6081 : : uint32_t tmp, idx;
6082 : :
6083 [ # # ]: 0 : if (direction == -1) {
6084 : : /* other causes */
6085 : 0 : msix_vector |= IXGBE_IVAR_ALLOC_VAL;
6086 : 0 : tmp = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
6087 : 0 : tmp &= ~0xFF;
6088 : 0 : tmp |= msix_vector;
6089 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, tmp);
6090 : : } else {
6091 : : /* rx or tx cause */
6092 : 0 : msix_vector |= IXGBE_IVAR_ALLOC_VAL;
6093 : 0 : idx = ((16 * (queue & 1)) + (8 * direction));
6094 : 0 : tmp = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1));
6095 : 0 : tmp &= ~(0xFF << idx);
6096 : 0 : tmp |= (msix_vector << idx);
6097 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), tmp);
6098 : : }
6099 : 0 : }
6100 : :
6101 : : /**
6102 : : * set the IVAR registers, mapping interrupt causes to vectors
6103 : : * @param hw
6104 : : * pointer to ixgbe_hw struct
6105 : : * @direction
6106 : : * 0 for Rx, 1 for Tx, -1 for other causes
6107 : : * @queue
6108 : : * queue to map the corresponding interrupt to
6109 : : * @msix_vector
6110 : : * the vector to map to the corresponding queue
6111 : : */
6112 : : static void
6113 : 0 : ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
6114 : : uint8_t queue, uint8_t msix_vector)
6115 : : {
6116 : : uint32_t tmp, idx;
6117 : :
6118 : 0 : msix_vector |= IXGBE_IVAR_ALLOC_VAL;
6119 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB) {
6120 [ # # ]: 0 : if (direction == -1)
6121 : : direction = 0;
6122 : 0 : idx = (((direction * 64) + queue) >> 2) & 0x1F;
6123 : 0 : tmp = IXGBE_READ_REG(hw, IXGBE_IVAR(idx));
6124 : 0 : tmp &= ~(0xFF << (8 * (queue & 0x3)));
6125 : 0 : tmp |= (msix_vector << (8 * (queue & 0x3)));
6126 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR(idx), tmp);
6127 [ # # ]: 0 : } else if ((hw->mac.type == ixgbe_mac_82599EB) ||
6128 : : (hw->mac.type == ixgbe_mac_X540) ||
6129 : : (hw->mac.type == ixgbe_mac_X550) ||
6130 : : (hw->mac.type == ixgbe_mac_X550EM_a) ||
6131 : : (hw->mac.type == ixgbe_mac_X550EM_x) ||
6132 : : (hw->mac.type == ixgbe_mac_E610)) {
6133 [ # # ]: 0 : if (direction == -1) {
6134 : : /* other causes */
6135 : 0 : idx = ((queue & 1) * 8);
6136 : 0 : tmp = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
6137 : 0 : tmp &= ~(0xFF << idx);
6138 : 0 : tmp |= (msix_vector << idx);
6139 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, tmp);
6140 : : } else {
6141 : : /* rx or tx causes */
6142 : 0 : idx = ((16 * (queue & 1)) + (8 * direction));
6143 : 0 : tmp = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
6144 : 0 : tmp &= ~(0xFF << idx);
6145 : 0 : tmp |= (msix_vector << idx);
6146 : 0 : IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), tmp);
6147 : : }
6148 : : }
6149 : 0 : }
6150 : :
6151 : : static void
6152 : 0 : ixgbevf_configure_msix(struct rte_eth_dev *dev)
6153 : : {
6154 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
6155 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
6156 : 0 : struct ixgbe_hw *hw =
6157 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6158 : : uint32_t q_idx;
6159 : : uint32_t vector_idx = IXGBE_MISC_VEC_ID;
6160 : : uint32_t base = IXGBE_MISC_VEC_ID;
6161 : :
6162 : : /* Configure VF other cause ivar */
6163 : : ixgbevf_set_ivar_map(hw, -1, 1, vector_idx);
6164 : :
6165 : : /* won't configure msix register if no mapping is done
6166 : : * between intr vector and event fd.
6167 : : */
6168 [ # # ]: 0 : if (!rte_intr_dp_is_en(intr_handle))
6169 : : return;
6170 : :
6171 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
6172 : : base = IXGBE_RX_VEC_START;
6173 : : vector_idx = IXGBE_RX_VEC_START;
6174 : : }
6175 : :
6176 : : /* Configure all RX queues of VF */
6177 [ # # ]: 0 : for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
6178 : : /* Force all queue use vector 0,
6179 : : * as IXGBE_VF_MAXMSIVECTOR = 1
6180 : : */
6181 : 0 : ixgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
6182 : 0 : rte_intr_vec_list_index_set(intr_handle, q_idx,
6183 : : vector_idx);
6184 : 0 : if (vector_idx < base + rte_intr_nb_efd_get(intr_handle)
6185 [ # # ]: 0 : - 1)
6186 : 0 : vector_idx++;
6187 : : }
6188 : :
6189 : : /* As RX queue setting above show, all queues use the vector 0.
6190 : : * Set only the ITR value of IXGBE_MISC_VEC_ID.
6191 : : */
6192 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VTEITR(IXGBE_MISC_VEC_ID),
6193 : : IXGBE_EITR_INTERVAL_US(IXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
6194 : : | IXGBE_EITR_CNT_WDIS);
6195 : : }
6196 : :
6197 : : /**
6198 : : * Sets up the hardware to properly generate MSI-X interrupts
6199 : : * @hw
6200 : : * board private structure
6201 : : */
6202 : : static void
6203 : 0 : ixgbe_configure_msix(struct rte_eth_dev *dev)
6204 : : {
6205 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
6206 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
6207 : 0 : struct ixgbe_hw *hw =
6208 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6209 : : uint32_t queue_id, base = IXGBE_MISC_VEC_ID;
6210 : : uint32_t vec = IXGBE_MISC_VEC_ID;
6211 : : uint32_t mask;
6212 : : uint32_t gpie;
6213 : :
6214 : : /* won't configure msix register if no mapping is done
6215 : : * between intr vector and event fd
6216 : : * but if misx has been enabled already, need to configure
6217 : : * auto clean, auto mask and throttling.
6218 : : */
6219 : 0 : gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
6220 [ # # ]: 0 : if (!rte_intr_dp_is_en(intr_handle) &&
6221 [ # # ]: 0 : !(gpie & (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT)))
6222 : : return;
6223 : :
6224 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
6225 : : vec = base = IXGBE_RX_VEC_START;
6226 : :
6227 : : /* setup GPIE for MSI-x mode */
6228 : 0 : gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
6229 : 0 : gpie |= IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
6230 : : IXGBE_GPIE_OCD | IXGBE_GPIE_EIAME;
6231 : : /* auto clearing and auto setting corresponding bits in EIMS
6232 : : * when MSI-X interrupt is triggered
6233 : : */
6234 [ # # ]: 0 : if (hw->mac.type == ixgbe_mac_82598EB) {
6235 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
6236 : : } else {
6237 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
6238 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
6239 : : }
6240 : 0 : IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
6241 : :
6242 : : /* Populate the IVAR table and set the ITR values to the
6243 : : * corresponding register.
6244 : : */
6245 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
6246 [ # # ]: 0 : for (queue_id = 0; queue_id < dev->data->nb_rx_queues;
6247 : 0 : queue_id++) {
6248 : : /* by default, 1:1 mapping */
6249 : 0 : ixgbe_set_ivar_map(hw, 0, queue_id, vec);
6250 : 0 : rte_intr_vec_list_index_set(intr_handle,
6251 : : queue_id, vec);
6252 : 0 : if (vec < base + rte_intr_nb_efd_get(intr_handle)
6253 [ # # ]: 0 : - 1)
6254 : 0 : vec++;
6255 : : }
6256 : :
6257 [ # # # ]: 0 : switch (hw->mac.type) {
6258 : 0 : case ixgbe_mac_82598EB:
6259 : 0 : ixgbe_set_ivar_map(hw, -1,
6260 : : IXGBE_IVAR_OTHER_CAUSES_INDEX,
6261 : : IXGBE_MISC_VEC_ID);
6262 : 0 : break;
6263 : 0 : case ixgbe_mac_82599EB:
6264 : : case ixgbe_mac_X540:
6265 : : case ixgbe_mac_X550:
6266 : : case ixgbe_mac_X550EM_x:
6267 : : case ixgbe_mac_E610:
6268 : 0 : ixgbe_set_ivar_map(hw, -1, 1, IXGBE_MISC_VEC_ID);
6269 : 0 : break;
6270 : : default:
6271 : : break;
6272 : : }
6273 : : }
6274 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EITR(IXGBE_MISC_VEC_ID),
6275 : : IXGBE_EITR_INTERVAL_US(IXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
6276 : : | IXGBE_EITR_CNT_WDIS);
6277 : :
6278 : : /* set up to autoclear timer, and the vectors */
6279 : : mask = IXGBE_EIMS_ENABLE_MASK;
6280 : : mask &= ~(IXGBE_EIMS_OTHER |
6281 : : IXGBE_EIMS_MAILBOX |
6282 : : IXGBE_EIMS_LSC);
6283 : :
6284 : 0 : IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask);
6285 : : }
6286 : :
6287 : : int
6288 : 0 : ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
6289 : : uint16_t queue_idx, uint32_t tx_rate)
6290 : : {
6291 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6292 : : uint32_t rf_dec, rf_int;
6293 : : uint32_t bcnrc_val;
6294 : 0 : uint16_t link_speed = dev->data->dev_link.link_speed;
6295 : :
6296 [ # # ]: 0 : if (queue_idx >= hw->mac.max_tx_queues)
6297 : : return -EINVAL;
6298 : :
6299 [ # # ]: 0 : if (tx_rate != 0) {
6300 : : /* Calculate the rate factor values to set */
6301 : 0 : rf_int = (uint32_t)link_speed / (uint32_t)tx_rate;
6302 : 0 : rf_dec = (uint32_t)link_speed % (uint32_t)tx_rate;
6303 : 0 : rf_dec = (rf_dec << IXGBE_RTTBCNRC_RF_INT_SHIFT) / tx_rate;
6304 : :
6305 : : bcnrc_val = IXGBE_RTTBCNRC_RS_ENA;
6306 : 0 : bcnrc_val |= ((rf_int << IXGBE_RTTBCNRC_RF_INT_SHIFT) &
6307 : : IXGBE_RTTBCNRC_RF_INT_MASK_M);
6308 : 0 : bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK);
6309 : : } else {
6310 : : bcnrc_val = 0;
6311 : : }
6312 : :
6313 : : /*
6314 : : * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
6315 : : * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported, otherwise
6316 : : * set as 0x4.
6317 : : */
6318 [ # # ]: 0 : if (dev->data->mtu + IXGBE_ETH_OVERHEAD >= IXGBE_MAX_JUMBO_FRAME_SIZE)
6319 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, IXGBE_MMW_SIZE_JUMBO_FRAME);
6320 : : else
6321 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, IXGBE_MMW_SIZE_DEFAULT);
6322 : :
6323 : : /* Set RTTBCNRC of queue X */
6324 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_idx);
6325 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
6326 : 0 : IXGBE_WRITE_FLUSH(hw);
6327 : :
6328 : 0 : return 0;
6329 : : }
6330 : :
6331 : : static int
6332 : 0 : ixgbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
6333 : : __rte_unused uint32_t index,
6334 : : __rte_unused uint32_t pool)
6335 : : {
6336 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6337 : : int diag;
6338 : :
6339 : : /*
6340 : : * This function calls into the base driver, which in turn will use
6341 : : * function pointers, which are not guaranteed to be valid in secondary
6342 : : * processes, so avoid using this function in secondary processes.
6343 : : */
6344 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6345 : : return -E_RTE_SECONDARY;
6346 : :
6347 : : /*
6348 : : * On a 82599 VF, adding again the same MAC addr is not an idempotent
6349 : : * operation. Trap this case to avoid exhausting the [very limited]
6350 : : * set of PF resources used to store VF MAC addresses.
6351 : : */
6352 [ # # ]: 0 : if (memcmp(hw->mac.perm_addr, mac_addr,
6353 : : sizeof(struct rte_ether_addr)) == 0)
6354 : : return -1;
6355 : 0 : diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
6356 [ # # ]: 0 : if (diag != 0)
6357 : 0 : PMD_DRV_LOG(ERR, "Unable to add MAC address "
6358 : : RTE_ETHER_ADDR_PRT_FMT " - diag=%d",
6359 : : RTE_ETHER_ADDR_BYTES(mac_addr), diag);
6360 : : return diag;
6361 : : }
6362 : :
6363 : : static void
6364 : 0 : ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
6365 : : {
6366 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6367 : 0 : struct rte_ether_addr *perm_addr =
6368 : : (struct rte_ether_addr *)hw->mac.perm_addr;
6369 : : struct rte_ether_addr *mac_addr;
6370 : : uint32_t i;
6371 : : int diag;
6372 : :
6373 : : /*
6374 : : * This function calls into the base driver, which in turn will use
6375 : : * function pointers, which are not guaranteed to be valid in secondary
6376 : : * processes, so avoid using this function in secondary processes.
6377 : : */
6378 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6379 : : return;
6380 : :
6381 : : /*
6382 : : * The IXGBE_VF_SET_MACVLAN command of the ixgbe-pf driver does
6383 : : * not support the deletion of a given MAC address.
6384 : : * Instead, it imposes to delete all MAC addresses, then to add again
6385 : : * all MAC addresses with the exception of the one to be deleted.
6386 : : */
6387 : 0 : (void) ixgbevf_set_uc_addr_vf(hw, 0, NULL);
6388 : :
6389 : : /*
6390 : : * Add again all MAC addresses, with the exception of the deleted one
6391 : : * and of the permanent MAC address.
6392 : : */
6393 : 0 : for (i = 0, mac_addr = dev->data->mac_addrs;
6394 [ # # ]: 0 : i < hw->mac.num_rar_entries; i++, mac_addr++) {
6395 : : /* Skip the deleted MAC address */
6396 [ # # ]: 0 : if (i == index)
6397 : 0 : continue;
6398 : : /* Skip NULL MAC addresses */
6399 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac_addr))
6400 : 0 : continue;
6401 : : /* Skip the permanent MAC address */
6402 [ # # ]: 0 : if (memcmp(perm_addr, mac_addr,
6403 : : sizeof(struct rte_ether_addr)) == 0)
6404 : 0 : continue;
6405 : 0 : diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
6406 [ # # ]: 0 : if (diag != 0)
6407 : 0 : PMD_DRV_LOG(ERR,
6408 : : "Adding again MAC address "
6409 : : RTE_ETHER_ADDR_PRT_FMT " failed "
6410 : : "diag=%d", RTE_ETHER_ADDR_BYTES(mac_addr),
6411 : : diag);
6412 : : }
6413 : : }
6414 : :
6415 : : static int
6416 : 0 : ixgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
6417 : : struct rte_ether_addr *addr)
6418 : : {
6419 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6420 : :
6421 : : /*
6422 : : * This function calls into the base driver, which in turn will use
6423 : : * function pointers, which are not guaranteed to be valid in secondary
6424 : : * processes, so avoid using this function in secondary processes.
6425 : : */
6426 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6427 : : return -E_RTE_SECONDARY;
6428 : :
6429 : 0 : hw->mac.ops.set_rar(hw, 0, (void *)addr, 0, 0);
6430 : :
6431 : 0 : return 0;
6432 : : }
6433 : :
6434 : : int
6435 : 0 : ixgbe_syn_filter_set(struct rte_eth_dev *dev,
6436 : : struct rte_eth_syn_filter *filter,
6437 : : bool add)
6438 : : {
6439 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6440 : : struct ixgbe_filter_info *filter_info =
6441 : : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6442 : : uint32_t syn_info;
6443 : : uint32_t synqf;
6444 : :
6445 [ # # ]: 0 : if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
6446 : : return -EINVAL;
6447 : :
6448 : 0 : syn_info = filter_info->syn_info;
6449 : :
6450 [ # # ]: 0 : if (add) {
6451 [ # # ]: 0 : if (syn_info & IXGBE_SYN_FILTER_ENABLE)
6452 : : return -EINVAL;
6453 : 0 : synqf = (uint32_t)(((filter->queue << IXGBE_SYN_FILTER_QUEUE_SHIFT) &
6454 : 0 : IXGBE_SYN_FILTER_QUEUE) | IXGBE_SYN_FILTER_ENABLE);
6455 : :
6456 [ # # ]: 0 : if (filter->hig_pri)
6457 : 0 : synqf |= IXGBE_SYN_FILTER_SYNQFP;
6458 : : else
6459 : : synqf &= ~IXGBE_SYN_FILTER_SYNQFP;
6460 : : } else {
6461 : 0 : synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
6462 [ # # ]: 0 : if (!(syn_info & IXGBE_SYN_FILTER_ENABLE))
6463 : : return -ENOENT;
6464 : 0 : synqf &= ~(IXGBE_SYN_FILTER_QUEUE | IXGBE_SYN_FILTER_ENABLE);
6465 : : }
6466 : :
6467 : 0 : filter_info->syn_info = synqf;
6468 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SYNQF, synqf);
6469 : 0 : IXGBE_WRITE_FLUSH(hw);
6470 : 0 : return 0;
6471 : : }
6472 : :
6473 : :
6474 : : static inline enum ixgbe_5tuple_protocol
6475 : : convert_protocol_type(uint8_t protocol_value)
6476 : : {
6477 : 0 : if (protocol_value == IPPROTO_TCP)
6478 : : return IXGBE_FILTER_PROTOCOL_TCP;
6479 [ # # ]: 0 : else if (protocol_value == IPPROTO_UDP)
6480 : : return IXGBE_FILTER_PROTOCOL_UDP;
6481 [ # # ]: 0 : else if (protocol_value == IPPROTO_SCTP)
6482 : : return IXGBE_FILTER_PROTOCOL_SCTP;
6483 : : else
6484 : 0 : return IXGBE_FILTER_PROTOCOL_NONE;
6485 : : }
6486 : :
6487 : : /* inject a 5-tuple filter to HW */
6488 : : static inline void
6489 : 0 : ixgbe_inject_5tuple_filter(struct rte_eth_dev *dev,
6490 : : struct ixgbe_5tuple_filter *filter)
6491 : : {
6492 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6493 : : int i;
6494 : : uint32_t ftqf, sdpqf;
6495 : : uint32_t l34timir = 0;
6496 : : uint8_t mask = 0xff;
6497 : :
6498 : 0 : i = filter->index;
6499 : :
6500 : 0 : sdpqf = (uint32_t)(filter->filter_info.dst_port <<
6501 : : IXGBE_SDPQF_DSTPORT_SHIFT);
6502 : 0 : sdpqf = sdpqf | (filter->filter_info.src_port & IXGBE_SDPQF_SRCPORT);
6503 : :
6504 : 0 : ftqf = (uint32_t)(filter->filter_info.proto &
6505 : : IXGBE_FTQF_PROTOCOL_MASK);
6506 : 0 : ftqf |= (uint32_t)((filter->filter_info.priority &
6507 : 0 : IXGBE_FTQF_PRIORITY_MASK) << IXGBE_FTQF_PRIORITY_SHIFT);
6508 [ # # ]: 0 : if (filter->filter_info.src_ip_mask == 0) /* 0 means compare. */
6509 : : mask &= IXGBE_FTQF_SOURCE_ADDR_MASK;
6510 [ # # ]: 0 : if (filter->filter_info.dst_ip_mask == 0)
6511 : 0 : mask &= IXGBE_FTQF_DEST_ADDR_MASK;
6512 [ # # ]: 0 : if (filter->filter_info.src_port_mask == 0)
6513 : 0 : mask &= IXGBE_FTQF_SOURCE_PORT_MASK;
6514 [ # # ]: 0 : if (filter->filter_info.dst_port_mask == 0)
6515 : 0 : mask &= IXGBE_FTQF_DEST_PORT_MASK;
6516 [ # # ]: 0 : if (filter->filter_info.proto_mask == 0)
6517 : 0 : mask &= IXGBE_FTQF_PROTOCOL_COMP_MASK;
6518 : 0 : ftqf |= mask << IXGBE_FTQF_5TUPLE_MASK_SHIFT;
6519 : : ftqf |= IXGBE_FTQF_POOL_MASK_EN;
6520 : 0 : ftqf |= IXGBE_FTQF_QUEUE_ENABLE;
6521 : :
6522 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DAQF(i), filter->filter_info.dst_ip);
6523 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SAQF(i), filter->filter_info.src_ip);
6524 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SDPQF(i), sdpqf);
6525 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FTQF(i), ftqf);
6526 : :
6527 : : l34timir |= IXGBE_L34T_IMIR_RESERVE;
6528 : 0 : l34timir |= (uint32_t)(filter->queue <<
6529 : : IXGBE_L34T_IMIR_QUEUE_SHIFT);
6530 : 0 : IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(i), l34timir);
6531 : 0 : }
6532 : :
6533 : : /*
6534 : : * add a 5tuple filter
6535 : : *
6536 : : * @param
6537 : : * dev: Pointer to struct rte_eth_dev.
6538 : : * index: the index the filter allocates.
6539 : : * filter: pointer to the filter that will be added.
6540 : : * rx_queue: the queue id the filter assigned to.
6541 : : *
6542 : : * @return
6543 : : * - On success, zero.
6544 : : * - On failure, a negative value.
6545 : : */
6546 : : static int
6547 : 0 : ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
6548 : : struct ixgbe_5tuple_filter *filter)
6549 : : {
6550 : : struct ixgbe_filter_info *filter_info =
6551 : 0 : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6552 : : int i, idx, shift;
6553 : :
6554 : : /*
6555 : : * look for an unused 5tuple filter index,
6556 : : * and insert the filter to list.
6557 : : */
6558 [ # # ]: 0 : for (i = 0; i < IXGBE_MAX_FTQF_FILTERS; i++) {
6559 : 0 : idx = i / (sizeof(uint32_t) * NBBY);
6560 : 0 : shift = i % (sizeof(uint32_t) * NBBY);
6561 [ # # ]: 0 : if (!(filter_info->fivetuple_mask[idx] & (1 << shift))) {
6562 : 0 : filter_info->fivetuple_mask[idx] |= 1 << shift;
6563 : 0 : filter->index = i;
6564 : 0 : TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
6565 : : filter,
6566 : : entries);
6567 : 0 : break;
6568 : : }
6569 : : }
6570 [ # # ]: 0 : if (i >= IXGBE_MAX_FTQF_FILTERS) {
6571 : 0 : PMD_DRV_LOG(ERR, "5tuple filters are full.");
6572 : 0 : return -ENOSYS;
6573 : : }
6574 : :
6575 : 0 : ixgbe_inject_5tuple_filter(dev, filter);
6576 : :
6577 : 0 : return 0;
6578 : : }
6579 : :
6580 : : /*
6581 : : * remove a 5tuple filter
6582 : : *
6583 : : * @param
6584 : : * dev: Pointer to struct rte_eth_dev.
6585 : : * filter: the pointer of the filter will be removed.
6586 : : */
6587 : : static void
6588 : 0 : ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
6589 : : struct ixgbe_5tuple_filter *filter)
6590 : : {
6591 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6592 : : struct ixgbe_filter_info *filter_info =
6593 : : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6594 : 0 : uint16_t index = filter->index;
6595 : :
6596 : 0 : filter_info->fivetuple_mask[index / (sizeof(uint32_t) * NBBY)] &=
6597 : 0 : ~(1 << (index % (sizeof(uint32_t) * NBBY)));
6598 [ # # ]: 0 : TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
6599 : 0 : rte_free(filter);
6600 : :
6601 : 0 : IXGBE_WRITE_REG(hw, IXGBE_DAQF(index), 0);
6602 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SAQF(index), 0);
6603 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SDPQF(index), 0);
6604 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FTQF(index), 0);
6605 : 0 : IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(index), 0);
6606 : 0 : }
6607 : :
6608 : : static int
6609 : 0 : ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
6610 : : {
6611 : : struct ixgbe_hw *hw;
6612 : 0 : uint32_t max_frame = mtu + IXGBE_ETH_OVERHEAD;
6613 : 0 : struct rte_eth_dev_data *dev_data = dev->data;
6614 : :
6615 : : /*
6616 : : * This function calls into the base driver, which in turn will use
6617 : : * function pointers, which are not guaranteed to be valid in secondary
6618 : : * processes, so avoid using this function in secondary processes.
6619 : : */
6620 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6621 : : return -E_RTE_SECONDARY;
6622 : :
6623 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6624 : :
6625 [ # # ]: 0 : if (mtu < RTE_ETHER_MIN_MTU || max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
6626 : : return -EINVAL;
6627 : :
6628 : : /* If device is started, refuse mtu that requires the support of
6629 : : * scattered packets when this feature has not been enabled before.
6630 : : */
6631 [ # # ]: 0 : if (dev_data->dev_started && !dev_data->scattered_rx &&
6632 : 0 : (max_frame + 2 * RTE_VLAN_HLEN >
6633 [ # # ]: 0 : dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
6634 : 0 : PMD_INIT_LOG(ERR, "Stop port first.");
6635 : 0 : return -EINVAL;
6636 : : }
6637 : :
6638 : : /*
6639 : : * When supported by the underlying PF driver, use the IXGBE_VF_SET_MTU
6640 : : * request of the version 2.0 of the mailbox API.
6641 : : * For now, use the IXGBE_VF_SET_LPE request of the version 1.0
6642 : : * of the mailbox API.
6643 : : * This call to IXGBE_SET_LPE action won't work with ixgbe pf drivers
6644 : : * prior to 3.11.33 which contains the following change:
6645 : : * "ixgbe: Enable jumbo frames support w/ SR-IOV"
6646 : : */
6647 [ # # ]: 0 : if (ixgbevf_rlpml_set_vf(hw, max_frame))
6648 : 0 : return -EINVAL;
6649 : :
6650 : : return 0;
6651 : : }
6652 : :
6653 : : static inline struct ixgbe_5tuple_filter *
6654 : : ixgbe_5tuple_filter_lookup(struct ixgbe_5tuple_filter_list *filter_list,
6655 : : struct ixgbe_5tuple_filter_info *key)
6656 : : {
6657 : : struct ixgbe_5tuple_filter *it;
6658 : :
6659 [ # # ]: 0 : TAILQ_FOREACH(it, filter_list, entries) {
6660 [ # # ]: 0 : if (memcmp(key, &it->filter_info,
6661 : : sizeof(struct ixgbe_5tuple_filter_info)) == 0) {
6662 : : return it;
6663 : : }
6664 : : }
6665 : : return NULL;
6666 : : }
6667 : :
6668 : : /* translate elements in struct rte_eth_ntuple_filter to struct ixgbe_5tuple_filter_info*/
6669 : : static inline int
6670 : 0 : ntuple_filter_to_5tuple(struct rte_eth_ntuple_filter *filter,
6671 : : struct ixgbe_5tuple_filter_info *filter_info)
6672 : : {
6673 [ # # ]: 0 : if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM ||
6674 [ # # # # ]: 0 : filter->priority > IXGBE_5TUPLE_MAX_PRI ||
6675 : : filter->priority < IXGBE_5TUPLE_MIN_PRI)
6676 : : return -EINVAL;
6677 : :
6678 [ # # # ]: 0 : switch (filter->dst_ip_mask) {
6679 : 0 : case UINT32_MAX:
6680 : 0 : filter_info->dst_ip_mask = 0;
6681 : 0 : filter_info->dst_ip = filter->dst_ip;
6682 : 0 : break;
6683 : 0 : case 0:
6684 : 0 : filter_info->dst_ip_mask = 1;
6685 : 0 : break;
6686 : 0 : default:
6687 : 0 : PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
6688 : 0 : return -EINVAL;
6689 : : }
6690 : :
6691 [ # # # ]: 0 : switch (filter->src_ip_mask) {
6692 : 0 : case UINT32_MAX:
6693 : 0 : filter_info->src_ip_mask = 0;
6694 : 0 : filter_info->src_ip = filter->src_ip;
6695 : 0 : break;
6696 : 0 : case 0:
6697 : 0 : filter_info->src_ip_mask = 1;
6698 : 0 : break;
6699 : 0 : default:
6700 : 0 : PMD_DRV_LOG(ERR, "invalid src_ip mask.");
6701 : 0 : return -EINVAL;
6702 : : }
6703 : :
6704 [ # # # ]: 0 : switch (filter->dst_port_mask) {
6705 : 0 : case UINT16_MAX:
6706 : 0 : filter_info->dst_port_mask = 0;
6707 : 0 : filter_info->dst_port = filter->dst_port;
6708 : 0 : break;
6709 : 0 : case 0:
6710 : 0 : filter_info->dst_port_mask = 1;
6711 : 0 : break;
6712 : 0 : default:
6713 : 0 : PMD_DRV_LOG(ERR, "invalid dst_port mask.");
6714 : 0 : return -EINVAL;
6715 : : }
6716 : :
6717 [ # # # ]: 0 : switch (filter->src_port_mask) {
6718 : 0 : case UINT16_MAX:
6719 : 0 : filter_info->src_port_mask = 0;
6720 : 0 : filter_info->src_port = filter->src_port;
6721 : 0 : break;
6722 : 0 : case 0:
6723 : 0 : filter_info->src_port_mask = 1;
6724 : 0 : break;
6725 : 0 : default:
6726 : 0 : PMD_DRV_LOG(ERR, "invalid src_port mask.");
6727 : 0 : return -EINVAL;
6728 : : }
6729 : :
6730 [ # # # ]: 0 : switch (filter->proto_mask) {
6731 : 0 : case UINT8_MAX:
6732 : 0 : filter_info->proto_mask = 0;
6733 : 0 : filter_info->proto =
6734 [ # # ]: 0 : convert_protocol_type(filter->proto);
6735 : 0 : break;
6736 : 0 : case 0:
6737 : 0 : filter_info->proto_mask = 1;
6738 : 0 : break;
6739 : 0 : default:
6740 : 0 : PMD_DRV_LOG(ERR, "invalid protocol mask.");
6741 : 0 : return -EINVAL;
6742 : : }
6743 : :
6744 : 0 : filter_info->priority = (uint8_t)filter->priority;
6745 : 0 : return 0;
6746 : : }
6747 : :
6748 : : /*
6749 : : * add or delete a ntuple filter
6750 : : *
6751 : : * @param
6752 : : * dev: Pointer to struct rte_eth_dev.
6753 : : * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
6754 : : * add: if true, add filter, if false, remove filter
6755 : : *
6756 : : * @return
6757 : : * - On success, zero.
6758 : : * - On failure, a negative value.
6759 : : */
6760 : : int
6761 : 0 : ixgbe_add_del_ntuple_filter(struct rte_eth_dev *dev,
6762 : : struct rte_eth_ntuple_filter *ntuple_filter,
6763 : : bool add)
6764 : : {
6765 : : struct ixgbe_filter_info *filter_info =
6766 : 0 : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6767 : : struct ixgbe_5tuple_filter_info filter_5tuple;
6768 : : struct ixgbe_5tuple_filter *filter;
6769 : : int ret;
6770 : :
6771 [ # # ]: 0 : if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
6772 : 0 : PMD_DRV_LOG(ERR, "only 5tuple is supported.");
6773 : 0 : return -EINVAL;
6774 : : }
6775 : :
6776 : : memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
6777 : 0 : ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
6778 [ # # ]: 0 : if (ret < 0)
6779 : : return ret;
6780 : :
6781 : : filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
6782 : : &filter_5tuple);
6783 [ # # ]: 0 : if (filter != NULL && add) {
6784 : 0 : PMD_DRV_LOG(ERR, "filter exists.");
6785 : 0 : return -EEXIST;
6786 : : }
6787 [ # # ]: 0 : if (filter == NULL && !add) {
6788 : 0 : PMD_DRV_LOG(ERR, "filter doesn't exist.");
6789 : 0 : return -ENOENT;
6790 : : }
6791 : :
6792 [ # # ]: 0 : if (add) {
6793 : 0 : filter = rte_zmalloc("ixgbe_5tuple_filter",
6794 : : sizeof(struct ixgbe_5tuple_filter), 0);
6795 [ # # ]: 0 : if (filter == NULL)
6796 : : return -ENOMEM;
6797 [ # # ]: 0 : rte_memcpy(&filter->filter_info,
6798 : : &filter_5tuple,
6799 : : sizeof(struct ixgbe_5tuple_filter_info));
6800 : 0 : filter->queue = ntuple_filter->queue;
6801 : 0 : ret = ixgbe_add_5tuple_filter(dev, filter);
6802 [ # # ]: 0 : if (ret < 0) {
6803 : 0 : rte_free(filter);
6804 : 0 : return ret;
6805 : : }
6806 : : } else
6807 : 0 : ixgbe_remove_5tuple_filter(dev, filter);
6808 : :
6809 : : return 0;
6810 : : }
6811 : :
6812 : : int
6813 : 0 : ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
6814 : : struct rte_eth_ethertype_filter *filter,
6815 : : bool add)
6816 : : {
6817 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6818 : : struct ixgbe_filter_info *filter_info =
6819 : : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
6820 : : uint32_t etqf = 0;
6821 : : uint32_t etqs = 0;
6822 : : int ret;
6823 : : struct ixgbe_ethertype_filter ethertype_filter;
6824 : :
6825 [ # # ]: 0 : if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
6826 : : return -EINVAL;
6827 : :
6828 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
6829 : : filter->ether_type == RTE_ETHER_TYPE_IPV6) {
6830 : 0 : PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
6831 : : " ethertype filter.", filter->ether_type);
6832 : 0 : return -EINVAL;
6833 : : }
6834 : :
6835 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
6836 : 0 : PMD_DRV_LOG(ERR, "mac compare is unsupported.");
6837 : 0 : return -EINVAL;
6838 : : }
6839 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
6840 : 0 : PMD_DRV_LOG(ERR, "drop option is unsupported.");
6841 : 0 : return -EINVAL;
6842 : : }
6843 : :
6844 : 0 : ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
6845 [ # # ]: 0 : if (ret >= 0 && add) {
6846 : 0 : PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
6847 : : filter->ether_type);
6848 : 0 : return -EEXIST;
6849 : : }
6850 [ # # ]: 0 : if (ret < 0 && !add) {
6851 : 0 : PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
6852 : : filter->ether_type);
6853 : 0 : return -ENOENT;
6854 : : }
6855 : :
6856 [ # # ]: 0 : if (add) {
6857 : : etqf = IXGBE_ETQF_FILTER_EN;
6858 : 0 : etqf |= (uint32_t)filter->ether_type;
6859 : 0 : etqs |= (uint32_t)((filter->queue <<
6860 : : IXGBE_ETQS_RX_QUEUE_SHIFT) &
6861 : : IXGBE_ETQS_RX_QUEUE);
6862 : 0 : etqs |= IXGBE_ETQS_QUEUE_EN;
6863 : :
6864 : : ethertype_filter.ethertype = filter->ether_type;
6865 : : ethertype_filter.etqf = etqf;
6866 : : ethertype_filter.etqs = etqs;
6867 : : ethertype_filter.conf = FALSE;
6868 : : ret = ixgbe_ethertype_filter_insert(filter_info,
6869 : : ðertype_filter);
6870 [ # # ]: 0 : if (ret < 0) {
6871 : 0 : PMD_DRV_LOG(ERR, "ethertype filters are full.");
6872 : 0 : return -ENOSPC;
6873 : : }
6874 : : } else {
6875 [ # # ]: 0 : ret = ixgbe_ethertype_filter_remove(filter_info, (uint8_t)ret);
6876 : : if (ret < 0)
6877 : : return -ENOSYS;
6878 : : }
6879 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETQF(ret), etqf);
6880 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETQS(ret), etqs);
6881 : 0 : IXGBE_WRITE_FLUSH(hw);
6882 : :
6883 : 0 : return 0;
6884 : : }
6885 : :
6886 : : static int
6887 : 0 : ixgbe_dev_flow_ops_get(__rte_unused struct rte_eth_dev *dev,
6888 : : const struct rte_flow_ops **ops)
6889 : : {
6890 : 0 : *ops = &ixgbe_flow_ops;
6891 : 0 : return 0;
6892 : : }
6893 : :
6894 : : static u8 *
6895 : 0 : ixgbe_dev_addr_list_itr(__rte_unused struct ixgbe_hw *hw,
6896 : : u8 **mc_addr_ptr, u32 *vmdq)
6897 : : {
6898 : : u8 *mc_addr;
6899 : :
6900 : 0 : *vmdq = 0;
6901 : 0 : mc_addr = *mc_addr_ptr;
6902 : 0 : *mc_addr_ptr = (mc_addr + sizeof(struct rte_ether_addr));
6903 : 0 : return mc_addr;
6904 : : }
6905 : :
6906 : : static int
6907 : 0 : ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
6908 : : struct rte_ether_addr *mc_addr_set,
6909 : : uint32_t nb_mc_addr)
6910 : : {
6911 : : struct ixgbe_hw *hw;
6912 : : u8 *mc_addr_list;
6913 : :
6914 : : /*
6915 : : * This function calls into the base driver, which in turn will use
6916 : : * function pointers, which are not guaranteed to be valid in secondary
6917 : : * processes, so avoid using this function in secondary processes.
6918 : : */
6919 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6920 : : return -E_RTE_SECONDARY;
6921 : :
6922 : 0 : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6923 : : mc_addr_list = (u8 *)mc_addr_set;
6924 : 0 : return ixgbe_update_mc_addr_list(hw, mc_addr_list, nb_mc_addr,
6925 : : ixgbe_dev_addr_list_itr, TRUE);
6926 : : }
6927 : :
6928 : : static uint64_t
6929 : 0 : ixgbe_read_systime_cyclecounter(struct rte_eth_dev *dev)
6930 : : {
6931 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6932 : : uint64_t systime_cycles;
6933 : :
6934 [ # # ]: 0 : switch (hw->mac.type) {
6935 : 0 : case ixgbe_mac_X550:
6936 : : case ixgbe_mac_X550EM_x:
6937 : : case ixgbe_mac_X550EM_a:
6938 : : case ixgbe_mac_E610:
6939 : : /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
6940 : 0 : systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
6941 : 0 : systime_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
6942 : 0 : * NSEC_PER_SEC;
6943 : 0 : break;
6944 : 0 : default:
6945 : 0 : systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
6946 : 0 : systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
6947 : 0 : << 32;
6948 : : }
6949 : :
6950 : 0 : return systime_cycles;
6951 : : }
6952 : :
6953 : : static uint64_t
6954 : 0 : ixgbe_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
6955 : : {
6956 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6957 : : uint64_t rx_tstamp_cycles;
6958 : :
6959 [ # # ]: 0 : switch (hw->mac.type) {
6960 : 0 : case ixgbe_mac_X550:
6961 : : case ixgbe_mac_X550EM_x:
6962 : : case ixgbe_mac_X550EM_a:
6963 : : case ixgbe_mac_E610:
6964 : : /* RXSTMPL stores ns and RXSTMPH stores seconds. */
6965 : 0 : rx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
6966 : 0 : rx_tstamp_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPH)
6967 : 0 : * NSEC_PER_SEC;
6968 : 0 : break;
6969 : 0 : default:
6970 : : /* RXSTMPL stores ns and RXSTMPH stores seconds. */
6971 : 0 : rx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
6972 : 0 : rx_tstamp_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPH)
6973 : 0 : << 32;
6974 : : }
6975 : :
6976 : 0 : return rx_tstamp_cycles;
6977 : : }
6978 : :
6979 : : static uint64_t
6980 : 0 : ixgbe_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
6981 : : {
6982 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6983 : : uint64_t tx_tstamp_cycles;
6984 : :
6985 [ # # ]: 0 : switch (hw->mac.type) {
6986 : 0 : case ixgbe_mac_X550:
6987 : : case ixgbe_mac_X550EM_x:
6988 : : case ixgbe_mac_X550EM_a:
6989 : : case ixgbe_mac_E610:
6990 : : /* TXSTMPL stores ns and TXSTMPH stores seconds. */
6991 : 0 : tx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
6992 : 0 : tx_tstamp_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPH)
6993 : 0 : * NSEC_PER_SEC;
6994 : 0 : break;
6995 : 0 : default:
6996 : : /* TXSTMPL stores ns and TXSTMPH stores seconds. */
6997 : 0 : tx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
6998 : 0 : tx_tstamp_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPH)
6999 : 0 : << 32;
7000 : : }
7001 : :
7002 : 0 : return tx_tstamp_cycles;
7003 : : }
7004 : :
7005 : : static void
7006 : 0 : ixgbe_start_timecounters(struct rte_eth_dev *dev)
7007 : : {
7008 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7009 : : struct ixgbe_adapter *adapter = dev->data->dev_private;
7010 : : struct rte_eth_link link;
7011 : : uint32_t incval = 0;
7012 : : uint32_t shift = 0;
7013 : :
7014 : : /* Get current link speed. */
7015 : : ixgbe_dev_link_update(dev, 1);
7016 : 0 : rte_eth_linkstatus_get(dev, &link);
7017 : :
7018 [ # # # ]: 0 : switch (link.link_speed) {
7019 : : case RTE_ETH_SPEED_NUM_100M:
7020 : : incval = IXGBE_INCVAL_100;
7021 : : shift = IXGBE_INCVAL_SHIFT_100;
7022 : : break;
7023 : 0 : case RTE_ETH_SPEED_NUM_1G:
7024 : : incval = IXGBE_INCVAL_1GB;
7025 : : shift = IXGBE_INCVAL_SHIFT_1GB;
7026 : 0 : break;
7027 : 0 : case RTE_ETH_SPEED_NUM_10G:
7028 : : default:
7029 : : incval = IXGBE_INCVAL_10GB;
7030 : : shift = IXGBE_INCVAL_SHIFT_10GB;
7031 : 0 : break;
7032 : : }
7033 : :
7034 [ # # # # ]: 0 : switch (hw->mac.type) {
7035 : 0 : case ixgbe_mac_X550:
7036 : : case ixgbe_mac_X550EM_x:
7037 : : case ixgbe_mac_X550EM_a:
7038 : : case ixgbe_mac_E610:
7039 : : /* Independent of link speed. */
7040 : : incval = 1;
7041 : : /* Cycles read will be interpreted as ns. */
7042 : : shift = 0;
7043 : : /* Fall-through */
7044 : 0 : case ixgbe_mac_X540:
7045 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, incval);
7046 : : break;
7047 : 0 : case ixgbe_mac_82599EB:
7048 : 0 : incval >>= IXGBE_INCVAL_SHIFT_82599;
7049 : 0 : shift -= IXGBE_INCVAL_SHIFT_82599;
7050 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TIMINCA,
7051 : : (1 << IXGBE_INCPER_SHIFT_82599) | incval);
7052 : : break;
7053 : : default:
7054 : : /* Not supported. */
7055 : 0 : return;
7056 : : }
7057 : :
7058 : 0 : memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
7059 : 0 : memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
7060 : 0 : memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
7061 : :
7062 : 0 : adapter->systime_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
7063 : 0 : adapter->systime_tc.cc_shift = shift;
7064 : 0 : adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
7065 : :
7066 : 0 : adapter->rx_tstamp_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
7067 : 0 : adapter->rx_tstamp_tc.cc_shift = shift;
7068 : 0 : adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
7069 : :
7070 : 0 : adapter->tx_tstamp_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
7071 : 0 : adapter->tx_tstamp_tc.cc_shift = shift;
7072 : 0 : adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
7073 : : }
7074 : :
7075 : : static int
7076 : 0 : ixgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
7077 : : {
7078 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
7079 : :
7080 : 0 : adapter->systime_tc.nsec += delta;
7081 : 0 : adapter->rx_tstamp_tc.nsec += delta;
7082 : 0 : adapter->tx_tstamp_tc.nsec += delta;
7083 : :
7084 : 0 : return 0;
7085 : : }
7086 : :
7087 : : static int
7088 : 0 : ixgbe_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
7089 : : {
7090 : : uint64_t ns;
7091 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
7092 : :
7093 : : ns = rte_timespec_to_ns(ts);
7094 : : /* Set the timecounters to a new value. */
7095 : 0 : adapter->systime_tc.nsec = ns;
7096 : 0 : adapter->rx_tstamp_tc.nsec = ns;
7097 : 0 : adapter->tx_tstamp_tc.nsec = ns;
7098 : :
7099 : 0 : return 0;
7100 : : }
7101 : :
7102 : : static int
7103 : 0 : ixgbe_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
7104 : : {
7105 : : uint64_t ns, systime_cycles;
7106 : 0 : struct ixgbe_adapter *adapter = dev->data->dev_private;
7107 : :
7108 : 0 : systime_cycles = ixgbe_read_systime_cyclecounter(dev);
7109 : : ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
7110 : 0 : *ts = rte_ns_to_timespec(ns);
7111 : :
7112 : 0 : return 0;
7113 : : }
7114 : :
7115 : : static int
7116 : 0 : ixgbe_timesync_enable(struct rte_eth_dev *dev)
7117 : : {
7118 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7119 : : uint32_t tsync_ctl;
7120 : : uint32_t tsauxc;
7121 : : struct timespec ts;
7122 : :
7123 : : memset(&ts, 0, sizeof(struct timespec));
7124 : :
7125 : : /* get current system time */
7126 : 0 : clock_gettime(CLOCK_REALTIME, &ts);
7127 : :
7128 : : /* Stop the timesync system time. */
7129 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0x0);
7130 : : /* Reset the timesync system time value. */
7131 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SYSTIML, 0x0);
7132 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SYSTIMH, 0x0);
7133 : :
7134 : : /* Enable system time for platforms where it isn't on by default. */
7135 : 0 : tsauxc = IXGBE_READ_REG(hw, IXGBE_TSAUXC);
7136 : 0 : tsauxc &= ~IXGBE_TSAUXC_DISABLE_SYSTIME;
7137 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TSAUXC, tsauxc);
7138 : :
7139 : 0 : ixgbe_start_timecounters(dev);
7140 : :
7141 : : /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
7142 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588),
7143 : : (RTE_ETHER_TYPE_1588 |
7144 : : IXGBE_ETQF_FILTER_EN |
7145 : : IXGBE_ETQF_1588));
7146 : :
7147 : : /* Enable timestamping of received PTP packets. */
7148 : 0 : tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
7149 : 0 : tsync_ctl |= IXGBE_TSYNCRXCTL_ENABLED;
7150 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
7151 : :
7152 : : /* Enable timestamping of transmitted PTP packets. */
7153 : 0 : tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
7154 : 0 : tsync_ctl |= IXGBE_TSYNCTXCTL_ENABLED;
7155 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
7156 : :
7157 : 0 : IXGBE_WRITE_FLUSH(hw);
7158 : :
7159 : : /* ixgbe uses zero-based timestamping so only adjust timecounter */
7160 : : ixgbe_timesync_write_time(dev, &ts);
7161 : :
7162 : 0 : return 0;
7163 : : }
7164 : :
7165 : : static int
7166 : 0 : ixgbe_timesync_disable(struct rte_eth_dev *dev)
7167 : : {
7168 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7169 : : uint32_t tsync_ctl;
7170 : :
7171 : : /* Disable timestamping of transmitted PTP packets. */
7172 : 0 : tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
7173 : 0 : tsync_ctl &= ~IXGBE_TSYNCTXCTL_ENABLED;
7174 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
7175 : :
7176 : : /* Disable timestamping of received PTP packets. */
7177 : 0 : tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
7178 : 0 : tsync_ctl &= ~IXGBE_TSYNCRXCTL_ENABLED;
7179 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
7180 : :
7181 : : /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
7182 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588), 0);
7183 : :
7184 : : /* Stop incrementing the System Time registers. */
7185 : 0 : IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0);
7186 : :
7187 : 0 : return 0;
7188 : : }
7189 : :
7190 : : static int
7191 : 0 : ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
7192 : : struct timespec *timestamp,
7193 : : uint32_t flags __rte_unused)
7194 : : {
7195 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7196 : : struct ixgbe_adapter *adapter = dev->data->dev_private;
7197 : : uint32_t tsync_rxctl;
7198 : : uint64_t rx_tstamp_cycles;
7199 : : uint64_t ns;
7200 : :
7201 : 0 : tsync_rxctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
7202 [ # # ]: 0 : if ((tsync_rxctl & IXGBE_TSYNCRXCTL_VALID) == 0)
7203 : : return -EINVAL;
7204 : :
7205 : 0 : rx_tstamp_cycles = ixgbe_read_rx_tstamp_cyclecounter(dev);
7206 : : ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
7207 : 0 : *timestamp = rte_ns_to_timespec(ns);
7208 : :
7209 : 0 : return 0;
7210 : : }
7211 : :
7212 : : static int
7213 : 0 : ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
7214 : : struct timespec *timestamp)
7215 : : {
7216 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7217 : : struct ixgbe_adapter *adapter = dev->data->dev_private;
7218 : : uint32_t tsync_txctl;
7219 : : uint64_t tx_tstamp_cycles;
7220 : : uint64_t ns;
7221 : :
7222 : 0 : tsync_txctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
7223 [ # # ]: 0 : if ((tsync_txctl & IXGBE_TSYNCTXCTL_VALID) == 0)
7224 : : return -EINVAL;
7225 : :
7226 : 0 : tx_tstamp_cycles = ixgbe_read_tx_tstamp_cyclecounter(dev);
7227 : : ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
7228 : 0 : *timestamp = rte_ns_to_timespec(ns);
7229 : :
7230 : 0 : return 0;
7231 : : }
7232 : :
7233 : : static int
7234 : 0 : ixgbe_get_reg_length(struct rte_eth_dev *dev)
7235 : : {
7236 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7237 : : int count = 0;
7238 : : int g_ind = 0;
7239 : : const struct reg_info *reg_group;
7240 : 0 : const struct reg_info **reg_set = (hw->mac.type == ixgbe_mac_82598EB) ?
7241 [ # # ]: 0 : ixgbe_regs_mac_82598EB : ixgbe_regs_others;
7242 : :
7243 [ # # ]: 0 : while ((reg_group = reg_set[g_ind++]))
7244 : 0 : count += ixgbe_regs_group_count(reg_group);
7245 : :
7246 : 0 : return count;
7247 : : }
7248 : :
7249 : : static int
7250 : : ixgbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
7251 : : {
7252 : : int count = 0;
7253 : : int g_ind = 0;
7254 : : const struct reg_info *reg_group;
7255 : :
7256 [ # # # # ]: 0 : while ((reg_group = ixgbevf_regs[g_ind++]))
7257 : 0 : count += ixgbe_regs_group_count(reg_group);
7258 : :
7259 : : return count;
7260 : : }
7261 : :
7262 : : static int
7263 : 0 : ixgbe_get_regs(struct rte_eth_dev *dev,
7264 : : struct rte_dev_reg_info *regs)
7265 : : {
7266 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7267 : 0 : uint32_t *data = regs->data;
7268 : : int g_ind = 0;
7269 : : int count = 0;
7270 : : const struct reg_info *reg_group;
7271 : 0 : const struct reg_info **reg_set = (hw->mac.type == ixgbe_mac_82598EB) ?
7272 [ # # ]: 0 : ixgbe_regs_mac_82598EB : ixgbe_regs_others;
7273 : :
7274 [ # # ]: 0 : if (data == NULL) {
7275 : 0 : regs->length = ixgbe_get_reg_length(dev);
7276 : 0 : regs->width = sizeof(uint32_t);
7277 : 0 : return 0;
7278 : : }
7279 : :
7280 : : /* Support only full register dump */
7281 [ # # ]: 0 : if ((regs->length == 0) ||
7282 [ # # ]: 0 : (regs->length == (uint32_t)ixgbe_get_reg_length(dev))) {
7283 : 0 : regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
7284 : 0 : hw->device_id;
7285 [ # # ]: 0 : while ((reg_group = reg_set[g_ind++]))
7286 : 0 : count += ixgbe_read_regs_group(dev, &data[count],
7287 : : reg_group);
7288 : : return 0;
7289 : : }
7290 : :
7291 : : return -ENOTSUP;
7292 : : }
7293 : :
7294 : : static int
7295 : 0 : ixgbevf_get_regs(struct rte_eth_dev *dev,
7296 : : struct rte_dev_reg_info *regs)
7297 : : {
7298 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7299 : 0 : uint32_t *data = regs->data;
7300 : : int g_ind = 0;
7301 : : int count = 0;
7302 : : const struct reg_info *reg_group;
7303 : :
7304 [ # # ]: 0 : if (data == NULL) {
7305 : 0 : regs->length = ixgbevf_get_reg_length(dev);
7306 : 0 : regs->width = sizeof(uint32_t);
7307 : 0 : return 0;
7308 : : }
7309 : :
7310 : : /* Support only full register dump */
7311 [ # # ]: 0 : if ((regs->length == 0) ||
7312 [ # # ]: 0 : (regs->length == (uint32_t)ixgbevf_get_reg_length(dev))) {
7313 : 0 : regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
7314 : 0 : hw->device_id;
7315 [ # # ]: 0 : while ((reg_group = ixgbevf_regs[g_ind++]))
7316 : 0 : count += ixgbe_read_regs_group(dev, &data[count],
7317 : : reg_group);
7318 : : return 0;
7319 : : }
7320 : :
7321 : : return -ENOTSUP;
7322 : : }
7323 : :
7324 : : static int
7325 : 0 : ixgbe_get_eeprom_length(struct rte_eth_dev *dev)
7326 : : {
7327 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7328 : :
7329 : : /* Return unit is byte count */
7330 : 0 : return hw->eeprom.word_size * 2;
7331 : : }
7332 : :
7333 : : static int
7334 : 0 : ixgbe_get_eeprom(struct rte_eth_dev *dev,
7335 : : struct rte_dev_eeprom_info *in_eeprom)
7336 : : {
7337 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7338 : : struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
7339 : 0 : uint16_t *data = in_eeprom->data;
7340 : : int first, length;
7341 : :
7342 : : /*
7343 : : * This function calls into the base driver, which in turn will use
7344 : : * function pointers, which are not guaranteed to be valid in secondary
7345 : : * processes, so avoid using this function in secondary processes.
7346 : : */
7347 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
7348 : : return -E_RTE_SECONDARY;
7349 : :
7350 : 0 : first = in_eeprom->offset >> 1;
7351 : 0 : length = in_eeprom->length >> 1;
7352 [ # # ]: 0 : if ((first > hw->eeprom.word_size) ||
7353 [ # # ]: 0 : ((first + length) > hw->eeprom.word_size))
7354 : : return -EINVAL;
7355 : :
7356 : 0 : in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
7357 : :
7358 : 0 : return eeprom->ops.read_buffer(hw, first, length, data);
7359 : : }
7360 : :
7361 : : static int
7362 : 0 : ixgbe_set_eeprom(struct rte_eth_dev *dev,
7363 : : struct rte_dev_eeprom_info *in_eeprom)
7364 : : {
7365 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7366 : : struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
7367 : 0 : uint16_t *data = in_eeprom->data;
7368 : : int first, length;
7369 : :
7370 : : /*
7371 : : * This function calls into the base driver, which in turn will use
7372 : : * function pointers, which are not guaranteed to be valid in secondary
7373 : : * processes, so avoid using this function in secondary processes.
7374 : : */
7375 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
7376 : : return -E_RTE_SECONDARY;
7377 : :
7378 : 0 : first = in_eeprom->offset >> 1;
7379 : 0 : length = in_eeprom->length >> 1;
7380 [ # # ]: 0 : if ((first > hw->eeprom.word_size) ||
7381 [ # # ]: 0 : ((first + length) > hw->eeprom.word_size))
7382 : : return -EINVAL;
7383 : :
7384 : 0 : in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
7385 : :
7386 : 0 : return eeprom->ops.write_buffer(hw, first, length, data);
7387 : : }
7388 : :
7389 : : static int
7390 : 0 : ixgbe_get_module_info(struct rte_eth_dev *dev,
7391 : : struct rte_eth_dev_module_info *modinfo)
7392 : : {
7393 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7394 : : uint32_t status;
7395 : : uint8_t sff8472_rev, addr_mode;
7396 : : bool page_swap = false;
7397 : :
7398 : : /*
7399 : : * This function calls into the base driver, which in turn will use
7400 : : * function pointers, which are not guaranteed to be valid in secondary
7401 : : * processes, so avoid using this function in secondary processes.
7402 : : */
7403 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
7404 : : return -E_RTE_SECONDARY;
7405 : :
7406 : : /* Check whether we support SFF-8472 or not */
7407 : 0 : status = hw->phy.ops.read_i2c_eeprom(hw,
7408 : : IXGBE_SFF_SFF_8472_COMP,
7409 : : &sff8472_rev);
7410 [ # # ]: 0 : if (status != 0)
7411 : : return -EIO;
7412 : :
7413 : : /* addressing mode is not supported */
7414 : 0 : status = hw->phy.ops.read_i2c_eeprom(hw,
7415 : : IXGBE_SFF_SFF_8472_SWAP,
7416 : : &addr_mode);
7417 [ # # ]: 0 : if (status != 0)
7418 : : return -EIO;
7419 : :
7420 [ # # ]: 0 : if (addr_mode & IXGBE_SFF_ADDRESSING_MODE) {
7421 : 0 : PMD_DRV_LOG(ERR,
7422 : : "Address change required to access page 0xA2, "
7423 : : "but not supported. Please report the module "
7424 : : "type to the driver maintainers.");
7425 : : page_swap = true;
7426 : : }
7427 : :
7428 [ # # # # ]: 0 : if (sff8472_rev == IXGBE_SFF_SFF_8472_UNSUP || page_swap) {
7429 : : /* We have a SFP, but it does not support SFF-8472 */
7430 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
7431 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
7432 : : } else {
7433 : : /* We have a SFP which supports a revision of SFF-8472. */
7434 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8472;
7435 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
7436 : : }
7437 : :
7438 : : return 0;
7439 : : }
7440 : :
7441 : : static int
7442 : 0 : ixgbe_get_module_eeprom(struct rte_eth_dev *dev,
7443 : : struct rte_dev_eeprom_info *info)
7444 : : {
7445 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7446 : : uint32_t status = IXGBE_ERR_PHY_ADDR_INVALID;
7447 : 0 : uint8_t databyte = 0xFF;
7448 : 0 : uint8_t *data = info->data;
7449 : : uint32_t i = 0;
7450 : :
7451 : : /*
7452 : : * This function calls into the base driver, which in turn will use
7453 : : * function pointers, which are not guaranteed to be valid in secondary
7454 : : * processes, so avoid using this function in secondary processes.
7455 : : */
7456 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
7457 : : return -E_RTE_SECONDARY;
7458 : :
7459 [ # # ]: 0 : for (i = info->offset; i < info->offset + info->length; i++) {
7460 [ # # ]: 0 : if (i < RTE_ETH_MODULE_SFF_8079_LEN)
7461 : 0 : status = hw->phy.ops.read_i2c_eeprom(hw, i, &databyte);
7462 : : else
7463 : 0 : status = hw->phy.ops.read_i2c_sff8472(hw, i, &databyte);
7464 : :
7465 [ # # ]: 0 : if (status != 0)
7466 : : return -EIO;
7467 : :
7468 : 0 : data[i - info->offset] = databyte;
7469 : : }
7470 : :
7471 : : return 0;
7472 : : }
7473 : :
7474 : : uint16_t
7475 : 0 : ixgbe_reta_size_get(enum ixgbe_mac_type mac_type) {
7476 [ # # # # ]: 0 : switch (mac_type) {
7477 : : case ixgbe_mac_X550:
7478 : : case ixgbe_mac_X550EM_x:
7479 : : case ixgbe_mac_X550EM_a:
7480 : : case ixgbe_mac_E610:
7481 : : return RTE_ETH_RSS_RETA_SIZE_512;
7482 : 0 : case ixgbe_mac_X550_vf:
7483 : : case ixgbe_mac_X550EM_x_vf:
7484 : : case ixgbe_mac_X550EM_a_vf:
7485 : : case ixgbe_mac_E610_vf:
7486 : 0 : return RTE_ETH_RSS_RETA_SIZE_64;
7487 : 0 : case ixgbe_mac_X540_vf:
7488 : : case ixgbe_mac_82599_vf:
7489 : 0 : return 0;
7490 : 0 : default:
7491 : 0 : return RTE_ETH_RSS_RETA_SIZE_128;
7492 : : }
7493 : : }
7494 : :
7495 : : uint32_t
7496 : 0 : ixgbe_reta_reg_get(enum ixgbe_mac_type mac_type, uint16_t reta_idx) {
7497 [ # # # ]: 0 : switch (mac_type) {
7498 : 0 : case ixgbe_mac_X550:
7499 : : case ixgbe_mac_X550EM_x:
7500 : : case ixgbe_mac_X550EM_a:
7501 : : case ixgbe_mac_E610:
7502 [ # # ]: 0 : if (reta_idx < RTE_ETH_RSS_RETA_SIZE_128)
7503 : 0 : return IXGBE_RETA(reta_idx >> 2);
7504 : : else
7505 : 0 : return IXGBE_ERETA((reta_idx - RTE_ETH_RSS_RETA_SIZE_128) >> 2);
7506 : 0 : case ixgbe_mac_X550_vf:
7507 : : case ixgbe_mac_X550EM_x_vf:
7508 : : case ixgbe_mac_X550EM_a_vf:
7509 : : case ixgbe_mac_E610_vf:
7510 : 0 : return IXGBE_VFRETA(reta_idx >> 2);
7511 : 0 : default:
7512 : 0 : return IXGBE_RETA(reta_idx >> 2);
7513 : : }
7514 : : }
7515 : :
7516 : : uint32_t
7517 : 0 : ixgbe_mrqc_reg_get(enum ixgbe_mac_type mac_type) {
7518 [ # # ]: 0 : switch (mac_type) {
7519 : : case ixgbe_mac_X550_vf:
7520 : : case ixgbe_mac_X550EM_x_vf:
7521 : : case ixgbe_mac_X550EM_a_vf:
7522 : : case ixgbe_mac_E610_vf:
7523 : : return IXGBE_VFMRQC;
7524 : 0 : default:
7525 : 0 : return IXGBE_MRQC;
7526 : : }
7527 : : }
7528 : :
7529 : : uint32_t
7530 : 0 : ixgbe_rssrk_reg_get(enum ixgbe_mac_type mac_type, uint8_t i) {
7531 [ # # ]: 0 : switch (mac_type) {
7532 : 0 : case ixgbe_mac_X550_vf:
7533 : : case ixgbe_mac_X550EM_x_vf:
7534 : : case ixgbe_mac_X550EM_a_vf:
7535 : : case ixgbe_mac_E610_vf:
7536 : 0 : return IXGBE_VFRSSRK(i);
7537 : 0 : default:
7538 : 0 : return IXGBE_RSSRK(i);
7539 : : }
7540 : : }
7541 : :
7542 : : bool
7543 : 0 : ixgbe_rss_update_sp(enum ixgbe_mac_type mac_type) {
7544 [ # # ]: 0 : switch (mac_type) {
7545 : : case ixgbe_mac_82599_vf:
7546 : : case ixgbe_mac_X540_vf:
7547 : : return 0;
7548 : 0 : default:
7549 : 0 : return 1;
7550 : : }
7551 : : }
7552 : :
7553 : : static int
7554 : 0 : ixgbe_dev_get_dcb_info(struct rte_eth_dev *dev,
7555 : : struct rte_eth_dcb_info *dcb_info)
7556 : : {
7557 : : struct ixgbe_dcb_config *dcb_config =
7558 : 0 : IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
7559 : : struct ixgbe_dcb_tc_config *tc;
7560 : : struct rte_eth_dcb_tc_queue_mapping *tc_queue;
7561 : : uint8_t nb_tcs;
7562 : : uint8_t i, j;
7563 : :
7564 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
7565 : 0 : dcb_info->nb_tcs = dcb_config->num_tcs.pg_tcs;
7566 : : else
7567 : 0 : dcb_info->nb_tcs = 1;
7568 : :
7569 : : tc_queue = &dcb_info->tc_queue;
7570 : 0 : nb_tcs = dcb_info->nb_tcs;
7571 : :
7572 [ # # ]: 0 : if (dcb_config->vt_mode) { /* vt is enabled*/
7573 : : struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
7574 : : &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
7575 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
7576 : 0 : dcb_info->prio_tc[i] = vmdq_rx_conf->dcb_tc[i];
7577 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active > 0) {
7578 [ # # ]: 0 : for (j = 0; j < nb_tcs; j++) {
7579 : 0 : tc_queue->tc_rxq[0][j].base = j;
7580 : 0 : tc_queue->tc_rxq[0][j].nb_queue = 1;
7581 : 0 : tc_queue->tc_txq[0][j].base = j;
7582 : 0 : tc_queue->tc_txq[0][j].nb_queue = 1;
7583 : : }
7584 : : } else {
7585 [ # # ]: 0 : for (i = 0; i < vmdq_rx_conf->nb_queue_pools; i++) {
7586 [ # # ]: 0 : for (j = 0; j < nb_tcs; j++) {
7587 : 0 : tc_queue->tc_rxq[i][j].base =
7588 : 0 : i * nb_tcs + j;
7589 : 0 : tc_queue->tc_rxq[i][j].nb_queue = 1;
7590 : 0 : tc_queue->tc_txq[i][j].base =
7591 : : i * nb_tcs + j;
7592 : 0 : tc_queue->tc_txq[i][j].nb_queue = 1;
7593 : : }
7594 : : }
7595 : : }
7596 : : } else { /* vt is disabled*/
7597 : : struct rte_eth_dcb_rx_conf *rx_conf =
7598 : : &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
7599 [ # # ]: 0 : for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
7600 : 0 : dcb_info->prio_tc[i] = rx_conf->dcb_tc[i];
7601 [ # # ]: 0 : if (dcb_info->nb_tcs == RTE_ETH_4_TCS) {
7602 [ # # ]: 0 : for (i = 0; i < dcb_info->nb_tcs; i++) {
7603 : 0 : dcb_info->tc_queue.tc_rxq[0][i].base = i * 32;
7604 : 0 : dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 16;
7605 : : }
7606 : 0 : dcb_info->tc_queue.tc_txq[0][0].base = 0;
7607 : 0 : dcb_info->tc_queue.tc_txq[0][1].base = 64;
7608 : 0 : dcb_info->tc_queue.tc_txq[0][2].base = 96;
7609 : 0 : dcb_info->tc_queue.tc_txq[0][3].base = 112;
7610 : 0 : dcb_info->tc_queue.tc_txq[0][0].nb_queue = 64;
7611 : 0 : dcb_info->tc_queue.tc_txq[0][1].nb_queue = 32;
7612 : 0 : dcb_info->tc_queue.tc_txq[0][2].nb_queue = 16;
7613 : 0 : dcb_info->tc_queue.tc_txq[0][3].nb_queue = 16;
7614 [ # # ]: 0 : } else if (dcb_info->nb_tcs == RTE_ETH_8_TCS) {
7615 [ # # ]: 0 : for (i = 0; i < dcb_info->nb_tcs; i++) {
7616 : 0 : dcb_info->tc_queue.tc_rxq[0][i].base = i * 16;
7617 : 0 : dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 16;
7618 : : }
7619 : 0 : dcb_info->tc_queue.tc_txq[0][0].base = 0;
7620 : 0 : dcb_info->tc_queue.tc_txq[0][1].base = 32;
7621 : 0 : dcb_info->tc_queue.tc_txq[0][2].base = 64;
7622 : 0 : dcb_info->tc_queue.tc_txq[0][3].base = 80;
7623 : 0 : dcb_info->tc_queue.tc_txq[0][4].base = 96;
7624 : 0 : dcb_info->tc_queue.tc_txq[0][5].base = 104;
7625 : 0 : dcb_info->tc_queue.tc_txq[0][6].base = 112;
7626 : 0 : dcb_info->tc_queue.tc_txq[0][7].base = 120;
7627 : 0 : dcb_info->tc_queue.tc_txq[0][0].nb_queue = 32;
7628 : 0 : dcb_info->tc_queue.tc_txq[0][1].nb_queue = 32;
7629 : 0 : dcb_info->tc_queue.tc_txq[0][2].nb_queue = 16;
7630 : 0 : dcb_info->tc_queue.tc_txq[0][3].nb_queue = 16;
7631 : 0 : dcb_info->tc_queue.tc_txq[0][4].nb_queue = 8;
7632 : 0 : dcb_info->tc_queue.tc_txq[0][5].nb_queue = 8;
7633 : 0 : dcb_info->tc_queue.tc_txq[0][6].nb_queue = 8;
7634 : 0 : dcb_info->tc_queue.tc_txq[0][7].nb_queue = 8;
7635 : : }
7636 : : }
7637 [ # # ]: 0 : for (i = 0; i < dcb_info->nb_tcs; i++) {
7638 : 0 : tc = &dcb_config->tc_config[i];
7639 : 0 : dcb_info->tc_bws[i] = tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent;
7640 : : }
7641 : 0 : return 0;
7642 : : }
7643 : :
7644 : : /* Update e-tag ether type */
7645 : : static int
7646 : : ixgbe_update_e_tag_eth_type(struct ixgbe_hw *hw,
7647 : : uint16_t ether_type)
7648 : : {
7649 : : uint32_t etag_etype;
7650 : :
7651 : 0 : if (hw->mac.type != ixgbe_mac_X550 &&
7652 : 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
7653 : : hw->mac.type != ixgbe_mac_X550EM_a) {
7654 : : return -ENOTSUP;
7655 : : }
7656 : :
7657 : 0 : etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
7658 : 0 : etag_etype &= ~IXGBE_ETAG_ETYPE_MASK;
7659 : 0 : etag_etype |= ether_type;
7660 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
7661 : 0 : IXGBE_WRITE_FLUSH(hw);
7662 : :
7663 : 0 : return 0;
7664 : : }
7665 : :
7666 : : /* Enable e-tag tunnel */
7667 : : static int
7668 : : ixgbe_e_tag_enable(struct ixgbe_hw *hw)
7669 : : {
7670 : : uint32_t etag_etype;
7671 : :
7672 : 0 : if (hw->mac.type != ixgbe_mac_X550 &&
7673 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
7674 : : hw->mac.type != ixgbe_mac_X550EM_a) {
7675 : : return -ENOTSUP;
7676 : : }
7677 : :
7678 : 0 : etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
7679 : 0 : etag_etype |= IXGBE_ETAG_ETYPE_VALID;
7680 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
7681 : 0 : IXGBE_WRITE_FLUSH(hw);
7682 : :
7683 : 0 : return 0;
7684 : : }
7685 : :
7686 : : static int
7687 : 0 : ixgbe_e_tag_filter_del(struct rte_eth_dev *dev,
7688 : : struct ixgbe_l2_tunnel_conf *l2_tunnel)
7689 : : {
7690 : : int ret = 0;
7691 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7692 : : uint32_t i, rar_entries;
7693 : : uint32_t rar_low, rar_high;
7694 : :
7695 : 0 : if (hw->mac.type != ixgbe_mac_X550 &&
7696 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
7697 : : hw->mac.type != ixgbe_mac_X550EM_a) {
7698 : : return -ENOTSUP;
7699 : : }
7700 : :
7701 : 0 : rar_entries = ixgbe_get_num_rx_addrs(hw);
7702 : :
7703 [ # # ]: 0 : for (i = 1; i < rar_entries; i++) {
7704 [ # # ]: 0 : rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(i));
7705 [ # # ]: 0 : rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(i));
7706 [ # # ]: 0 : if ((rar_high & IXGBE_RAH_AV) &&
7707 [ # # ]: 0 : (rar_high & IXGBE_RAH_ADTYPE) &&
7708 : 0 : ((rar_low & IXGBE_RAL_ETAG_FILTER_MASK) ==
7709 [ # # ]: 0 : l2_tunnel->tunnel_id)) {
7710 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
7711 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
7712 : :
7713 : 0 : ixgbe_clear_vmdq(hw, i, IXGBE_CLEAR_VMDQ_ALL);
7714 : :
7715 : 0 : return ret;
7716 : : }
7717 : : }
7718 : :
7719 : : return ret;
7720 : : }
7721 : :
7722 : : static int
7723 : 0 : ixgbe_e_tag_filter_add(struct rte_eth_dev *dev,
7724 : : struct ixgbe_l2_tunnel_conf *l2_tunnel)
7725 : : {
7726 : : int ret = 0;
7727 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7728 : : uint32_t i, rar_entries;
7729 : : uint32_t rar_low, rar_high;
7730 : :
7731 : 0 : if (hw->mac.type != ixgbe_mac_X550 &&
7732 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
7733 : : hw->mac.type != ixgbe_mac_X550EM_a) {
7734 : : return -ENOTSUP;
7735 : : }
7736 : :
7737 : : /* One entry for one tunnel. Try to remove potential existing entry. */
7738 : 0 : ixgbe_e_tag_filter_del(dev, l2_tunnel);
7739 : :
7740 : 0 : rar_entries = ixgbe_get_num_rx_addrs(hw);
7741 : :
7742 [ # # ]: 0 : for (i = 1; i < rar_entries; i++) {
7743 [ # # ]: 0 : rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(i));
7744 [ # # ]: 0 : if (rar_high & IXGBE_RAH_AV) {
7745 : : continue;
7746 : : } else {
7747 : 0 : ixgbe_set_vmdq(hw, i, l2_tunnel->pool);
7748 : : rar_high = IXGBE_RAH_AV | IXGBE_RAH_ADTYPE;
7749 : 0 : rar_low = l2_tunnel->tunnel_id;
7750 : :
7751 [ # # ]: 0 : IXGBE_WRITE_REG(hw, IXGBE_RAL(i), rar_low);
7752 : 0 : IXGBE_WRITE_REG(hw, IXGBE_RAH(i), rar_high);
7753 : :
7754 : 0 : return ret;
7755 : : }
7756 : : }
7757 : :
7758 : 0 : PMD_INIT_LOG(NOTICE, "The table of E-tag forwarding rule is full."
7759 : : " Please remove a rule before adding a new one.");
7760 : 0 : return -EINVAL;
7761 : : }
7762 : :
7763 : : static inline struct ixgbe_l2_tn_filter *
7764 : : ixgbe_l2_tn_filter_lookup(struct ixgbe_l2_tn_info *l2_tn_info,
7765 : : struct ixgbe_l2_tn_key *key)
7766 : : {
7767 : : int ret;
7768 : :
7769 : 0 : ret = rte_hash_lookup(l2_tn_info->hash_handle, (const void *)key);
7770 [ # # ]: 0 : if (ret < 0)
7771 : : return NULL;
7772 : :
7773 : 0 : return l2_tn_info->hash_map[ret];
7774 : : }
7775 : :
7776 : : static inline int
7777 : 0 : ixgbe_insert_l2_tn_filter(struct ixgbe_l2_tn_info *l2_tn_info,
7778 : : struct ixgbe_l2_tn_filter *l2_tn_filter)
7779 : : {
7780 : : int ret;
7781 : :
7782 : 0 : ret = rte_hash_add_key(l2_tn_info->hash_handle,
7783 : 0 : &l2_tn_filter->key);
7784 : :
7785 [ # # ]: 0 : if (ret < 0) {
7786 : 0 : PMD_DRV_LOG(ERR,
7787 : : "Failed to insert L2 tunnel filter"
7788 : : " to hash table %d!",
7789 : : ret);
7790 : 0 : return ret;
7791 : : }
7792 : :
7793 : 0 : l2_tn_info->hash_map[ret] = l2_tn_filter;
7794 : :
7795 : 0 : TAILQ_INSERT_TAIL(&l2_tn_info->l2_tn_list, l2_tn_filter, entries);
7796 : :
7797 : 0 : return 0;
7798 : : }
7799 : :
7800 : : static inline int
7801 : 0 : ixgbe_remove_l2_tn_filter(struct ixgbe_l2_tn_info *l2_tn_info,
7802 : : struct ixgbe_l2_tn_key *key)
7803 : : {
7804 : : int ret;
7805 : : struct ixgbe_l2_tn_filter *l2_tn_filter;
7806 : :
7807 : 0 : ret = rte_hash_del_key(l2_tn_info->hash_handle, key);
7808 : :
7809 [ # # ]: 0 : if (ret < 0) {
7810 : 0 : PMD_DRV_LOG(ERR,
7811 : : "No such L2 tunnel filter to delete %d!",
7812 : : ret);
7813 : 0 : return ret;
7814 : : }
7815 : :
7816 : 0 : l2_tn_filter = l2_tn_info->hash_map[ret];
7817 : 0 : l2_tn_info->hash_map[ret] = NULL;
7818 : :
7819 [ # # ]: 0 : TAILQ_REMOVE(&l2_tn_info->l2_tn_list, l2_tn_filter, entries);
7820 : 0 : rte_free(l2_tn_filter);
7821 : :
7822 : 0 : return 0;
7823 : : }
7824 : :
7825 : : /* Add l2 tunnel filter */
7826 : : int
7827 : 0 : ixgbe_dev_l2_tunnel_filter_add(struct rte_eth_dev *dev,
7828 : : struct ixgbe_l2_tunnel_conf *l2_tunnel,
7829 : : bool restore)
7830 : : {
7831 : : int ret;
7832 : 0 : struct ixgbe_l2_tn_info *l2_tn_info =
7833 : 0 : IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
7834 : : struct ixgbe_l2_tn_key key;
7835 : : struct ixgbe_l2_tn_filter *node;
7836 : :
7837 [ # # ]: 0 : if (!restore) {
7838 : 0 : key.l2_tn_type = l2_tunnel->l2_tunnel_type;
7839 : 0 : key.tn_id = l2_tunnel->tunnel_id;
7840 : :
7841 : : node = ixgbe_l2_tn_filter_lookup(l2_tn_info, &key);
7842 : :
7843 [ # # ]: 0 : if (node) {
7844 : 0 : PMD_DRV_LOG(ERR,
7845 : : "The L2 tunnel filter already exists!");
7846 : 0 : return -EINVAL;
7847 : : }
7848 : :
7849 : 0 : node = rte_zmalloc("ixgbe_l2_tn",
7850 : : sizeof(struct ixgbe_l2_tn_filter),
7851 : : 0);
7852 [ # # ]: 0 : if (!node)
7853 : : return -ENOMEM;
7854 : :
7855 [ # # ]: 0 : rte_memcpy(&node->key,
7856 : : &key,
7857 : : sizeof(struct ixgbe_l2_tn_key));
7858 : 0 : node->pool = l2_tunnel->pool;
7859 : 0 : ret = ixgbe_insert_l2_tn_filter(l2_tn_info, node);
7860 [ # # ]: 0 : if (ret < 0) {
7861 : 0 : rte_free(node);
7862 : 0 : return ret;
7863 : : }
7864 : : }
7865 : :
7866 [ # # ]: 0 : switch (l2_tunnel->l2_tunnel_type) {
7867 : 0 : case RTE_ETH_L2_TUNNEL_TYPE_E_TAG:
7868 : 0 : ret = ixgbe_e_tag_filter_add(dev, l2_tunnel);
7869 : 0 : break;
7870 : 0 : default:
7871 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
7872 : : ret = -EINVAL;
7873 : 0 : break;
7874 : : }
7875 : :
7876 [ # # ]: 0 : if ((!restore) && (ret < 0))
7877 : 0 : (void)ixgbe_remove_l2_tn_filter(l2_tn_info, &key);
7878 : :
7879 : : return ret;
7880 : : }
7881 : :
7882 : : /* Delete l2 tunnel filter */
7883 : : int
7884 : 0 : ixgbe_dev_l2_tunnel_filter_del(struct rte_eth_dev *dev,
7885 : : struct ixgbe_l2_tunnel_conf *l2_tunnel)
7886 : : {
7887 : : int ret;
7888 : 0 : struct ixgbe_l2_tn_info *l2_tn_info =
7889 : 0 : IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
7890 : : struct ixgbe_l2_tn_key key;
7891 : :
7892 : 0 : key.l2_tn_type = l2_tunnel->l2_tunnel_type;
7893 : 0 : key.tn_id = l2_tunnel->tunnel_id;
7894 : 0 : ret = ixgbe_remove_l2_tn_filter(l2_tn_info, &key);
7895 [ # # ]: 0 : if (ret < 0)
7896 : : return ret;
7897 : :
7898 [ # # ]: 0 : switch (l2_tunnel->l2_tunnel_type) {
7899 : 0 : case RTE_ETH_L2_TUNNEL_TYPE_E_TAG:
7900 : 0 : ret = ixgbe_e_tag_filter_del(dev, l2_tunnel);
7901 : 0 : break;
7902 : 0 : default:
7903 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
7904 : : ret = -EINVAL;
7905 : 0 : break;
7906 : : }
7907 : :
7908 : : return ret;
7909 : : }
7910 : :
7911 : : static int
7912 : : ixgbe_e_tag_forwarding_en_dis(struct rte_eth_dev *dev, bool en)
7913 : : {
7914 : : int ret = 0;
7915 : : uint32_t ctrl;
7916 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7917 : :
7918 : 0 : if (hw->mac.type != ixgbe_mac_X550 &&
7919 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
7920 : : hw->mac.type != ixgbe_mac_X550EM_a) {
7921 : : return -ENOTSUP;
7922 : : }
7923 : :
7924 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
7925 : 0 : ctrl &= ~IXGBE_VT_CTL_POOLING_MODE_MASK;
7926 : : if (en)
7927 : 0 : ctrl |= IXGBE_VT_CTL_POOLING_MODE_ETAG;
7928 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, ctrl);
7929 : :
7930 : 0 : return ret;
7931 : : }
7932 : :
7933 : : static int
7934 : : ixgbe_update_vxlan_port(struct ixgbe_hw *hw,
7935 : : uint16_t port)
7936 : : {
7937 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, port);
7938 : 0 : IXGBE_WRITE_FLUSH(hw);
7939 : :
7940 : : return 0;
7941 : : }
7942 : :
7943 : : /* There's only one register for VxLAN UDP port.
7944 : : * So, we cannot add several ports. Will update it.
7945 : : */
7946 : : static int
7947 : 0 : ixgbe_add_vxlan_port(struct ixgbe_hw *hw,
7948 : : uint16_t port)
7949 : : {
7950 [ # # ]: 0 : if (port == 0) {
7951 : 0 : PMD_DRV_LOG(ERR, "Add VxLAN port 0 is not allowed.");
7952 : 0 : return -EINVAL;
7953 : : }
7954 : :
7955 : 0 : return ixgbe_update_vxlan_port(hw, port);
7956 : : }
7957 : :
7958 : : /* We cannot delete the VxLAN port. For there's a register for VxLAN
7959 : : * UDP port, it must have a value.
7960 : : * So, will reset it to the original value 0.
7961 : : */
7962 : : static int
7963 : 0 : ixgbe_del_vxlan_port(struct ixgbe_hw *hw,
7964 : : uint16_t port)
7965 : : {
7966 : : uint16_t cur_port;
7967 : :
7968 : 0 : cur_port = (uint16_t)IXGBE_READ_REG(hw, IXGBE_VXLANCTRL);
7969 : :
7970 [ # # ]: 0 : if (cur_port != port) {
7971 : 0 : PMD_DRV_LOG(ERR, "Port %u does not exist.", port);
7972 : 0 : return -EINVAL;
7973 : : }
7974 : :
7975 : 0 : return ixgbe_update_vxlan_port(hw, 0);
7976 : : }
7977 : :
7978 : : /* Add UDP tunneling port */
7979 : : static int
7980 : 0 : ixgbe_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
7981 : : struct rte_eth_udp_tunnel *udp_tunnel)
7982 : : {
7983 : : int ret = 0;
7984 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7985 : :
7986 : 0 : if (hw->mac.type != ixgbe_mac_X550 &&
7987 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
7988 : : hw->mac.type != ixgbe_mac_X550EM_a) {
7989 : : return -ENOTSUP;
7990 : : }
7991 : :
7992 [ # # ]: 0 : if (udp_tunnel == NULL)
7993 : : return -EINVAL;
7994 : :
7995 [ # # # ]: 0 : switch (udp_tunnel->prot_type) {
7996 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
7997 : 0 : ret = ixgbe_add_vxlan_port(hw, udp_tunnel->udp_port);
7998 : 0 : break;
7999 : :
8000 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8001 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8002 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8003 : : ret = -EINVAL;
8004 : 0 : break;
8005 : :
8006 : 0 : default:
8007 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8008 : : ret = -EINVAL;
8009 : 0 : break;
8010 : : }
8011 : :
8012 : : return ret;
8013 : : }
8014 : :
8015 : : /* Remove UDP tunneling port */
8016 : : static int
8017 : 0 : ixgbe_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8018 : : struct rte_eth_udp_tunnel *udp_tunnel)
8019 : : {
8020 : : int ret = 0;
8021 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8022 : :
8023 : 0 : if (hw->mac.type != ixgbe_mac_X550 &&
8024 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
8025 : : hw->mac.type != ixgbe_mac_X550EM_a) {
8026 : : return -ENOTSUP;
8027 : : }
8028 : :
8029 [ # # ]: 0 : if (udp_tunnel == NULL)
8030 : : return -EINVAL;
8031 : :
8032 [ # # # ]: 0 : switch (udp_tunnel->prot_type) {
8033 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8034 : 0 : ret = ixgbe_del_vxlan_port(hw, udp_tunnel->udp_port);
8035 : 0 : break;
8036 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8037 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8038 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8039 : : ret = -EINVAL;
8040 : 0 : break;
8041 : 0 : default:
8042 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8043 : : ret = -EINVAL;
8044 : 0 : break;
8045 : : }
8046 : :
8047 : : return ret;
8048 : : }
8049 : :
8050 : : static int
8051 : 0 : ixgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev)
8052 : : {
8053 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8054 : : int ret;
8055 : :
8056 : : /*
8057 : : * This function calls into the base driver, which in turn will use
8058 : : * function pointers, which are not guaranteed to be valid in secondary
8059 : : * processes, so avoid using this function in secondary processes.
8060 : : */
8061 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
8062 : : return -E_RTE_SECONDARY;
8063 : :
8064 [ # # # ]: 0 : switch (hw->mac.ops.update_xcast_mode(hw, IXGBEVF_XCAST_MODE_PROMISC)) {
8065 : : case IXGBE_SUCCESS:
8066 : : ret = 0;
8067 : : break;
8068 : 0 : case IXGBE_ERR_FEATURE_NOT_SUPPORTED:
8069 : : ret = -ENOTSUP;
8070 : 0 : break;
8071 : 0 : default:
8072 : : ret = -EAGAIN;
8073 : 0 : break;
8074 : : }
8075 : :
8076 : : return ret;
8077 : : }
8078 : :
8079 : : static int
8080 : 0 : ixgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev)
8081 : : {
8082 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8083 : : int mode = IXGBEVF_XCAST_MODE_NONE;
8084 : : int ret;
8085 : :
8086 : : /*
8087 : : * This function calls into the base driver, which in turn will use
8088 : : * function pointers, which are not guaranteed to be valid in secondary
8089 : : * processes, so avoid using this function in secondary processes.
8090 : : */
8091 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
8092 : : return -E_RTE_SECONDARY;
8093 : :
8094 [ # # ]: 0 : if (dev->data->all_multicast)
8095 : : mode = IXGBEVF_XCAST_MODE_ALLMULTI;
8096 : :
8097 [ # # # ]: 0 : switch (hw->mac.ops.update_xcast_mode(hw, mode)) {
8098 : : case IXGBE_SUCCESS:
8099 : : ret = 0;
8100 : : break;
8101 : 0 : case IXGBE_ERR_FEATURE_NOT_SUPPORTED:
8102 : : ret = -ENOTSUP;
8103 : 0 : break;
8104 : 0 : default:
8105 : : ret = -EAGAIN;
8106 : 0 : break;
8107 : : }
8108 : :
8109 : : return ret;
8110 : : }
8111 : :
8112 : : static int
8113 : 0 : ixgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
8114 : : {
8115 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8116 : : int ret;
8117 : : int mode = IXGBEVF_XCAST_MODE_ALLMULTI;
8118 : :
8119 : : /*
8120 : : * This function calls into the base driver, which in turn will use
8121 : : * function pointers, which are not guaranteed to be valid in secondary
8122 : : * processes, so avoid using this function in secondary processes.
8123 : : */
8124 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
8125 : : return -E_RTE_SECONDARY;
8126 : :
8127 [ # # ]: 0 : if (dev->data->promiscuous)
8128 : : return 0;
8129 : :
8130 [ # # # ]: 0 : switch (hw->mac.ops.update_xcast_mode(hw, mode)) {
8131 : : case IXGBE_SUCCESS:
8132 : : ret = 0;
8133 : : break;
8134 : 0 : case IXGBE_ERR_FEATURE_NOT_SUPPORTED:
8135 : : ret = -ENOTSUP;
8136 : 0 : break;
8137 : 0 : default:
8138 : : ret = -EAGAIN;
8139 : 0 : break;
8140 : : }
8141 : :
8142 : : return ret;
8143 : : }
8144 : :
8145 : : static int
8146 : 0 : ixgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
8147 : : {
8148 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8149 : : int ret;
8150 : :
8151 : : /*
8152 : : * This function calls into the base driver, which in turn will use
8153 : : * function pointers, which are not guaranteed to be valid in secondary
8154 : : * processes, so avoid using this function in secondary processes.
8155 : : */
8156 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
8157 : : return -E_RTE_SECONDARY;
8158 : :
8159 [ # # ]: 0 : if (dev->data->promiscuous)
8160 : : return 0;
8161 : :
8162 [ # # # ]: 0 : switch (hw->mac.ops.update_xcast_mode(hw, IXGBEVF_XCAST_MODE_MULTI)) {
8163 : : case IXGBE_SUCCESS:
8164 : : ret = 0;
8165 : : break;
8166 : 0 : case IXGBE_ERR_FEATURE_NOT_SUPPORTED:
8167 : : ret = -ENOTSUP;
8168 : 0 : break;
8169 : 0 : default:
8170 : : ret = -EAGAIN;
8171 : 0 : break;
8172 : : }
8173 : :
8174 : : return ret;
8175 : : }
8176 : :
8177 : 0 : static void ixgbevf_mbx_process(struct rte_eth_dev *dev)
8178 : : {
8179 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8180 : 0 : u32 in_msg = 0;
8181 : :
8182 : : /* peek the message first */
8183 : 0 : in_msg = IXGBE_READ_REG(hw, IXGBE_VFMBMEM);
8184 : :
8185 : : /* PF reset VF event */
8186 [ # # ]: 0 : if (in_msg == IXGBE_PF_CONTROL_MSG) {
8187 : : /* dummy mbx read to ack pf */
8188 [ # # ]: 0 : if (ixgbe_read_mbx(hw, &in_msg, 1, 0))
8189 : 0 : return;
8190 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
8191 : : NULL);
8192 : : }
8193 : : }
8194 : :
8195 : : static int
8196 : 0 : ixgbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
8197 : : {
8198 : : uint32_t eicr;
8199 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8200 : : struct ixgbe_interrupt *intr =
8201 : : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
8202 : 0 : ixgbevf_intr_disable(dev);
8203 : :
8204 : : /* read-on-clear nic registers here */
8205 : 0 : eicr = IXGBE_READ_REG(hw, IXGBE_VTEICR);
8206 : 0 : intr->flags = 0;
8207 : :
8208 : : /* only one misc vector supported - mailbox */
8209 : 0 : eicr &= IXGBE_VTEICR_MASK;
8210 [ # # ]: 0 : if (eicr == IXGBE_MISC_VEC_ID)
8211 : 0 : intr->flags |= IXGBE_FLAG_MAILBOX;
8212 : :
8213 : 0 : return 0;
8214 : : }
8215 : :
8216 : : static int
8217 : 0 : ixgbevf_dev_interrupt_action(struct rte_eth_dev *dev)
8218 : : {
8219 : : struct ixgbe_interrupt *intr =
8220 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
8221 : :
8222 [ # # ]: 0 : if (intr->flags & IXGBE_FLAG_MAILBOX) {
8223 : 0 : ixgbevf_mbx_process(dev);
8224 : 0 : intr->flags &= ~IXGBE_FLAG_MAILBOX;
8225 : : }
8226 : :
8227 : 0 : ixgbevf_intr_enable(dev);
8228 : :
8229 : 0 : return 0;
8230 : : }
8231 : :
8232 : : static void
8233 : 0 : ixgbevf_dev_interrupt_handler(void *param)
8234 : : {
8235 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
8236 : :
8237 : 0 : ixgbevf_dev_interrupt_get_status(dev);
8238 : 0 : ixgbevf_dev_interrupt_action(dev);
8239 : 0 : }
8240 : :
8241 : : /**
8242 : : * ixgbe_disable_sec_tx_path_generic - Stops the transmit data path
8243 : : * @hw: pointer to hardware structure
8244 : : *
8245 : : * Stops the transmit data path and waits for the HW to internally empty
8246 : : * the Tx security block
8247 : : **/
8248 : 0 : int ixgbe_disable_sec_tx_path_generic(struct ixgbe_hw *hw)
8249 : : {
8250 : : #define IXGBE_MAX_SECTX_POLL 40
8251 : :
8252 : : int i;
8253 : : int sectxreg;
8254 : :
8255 : 0 : sectxreg = IXGBE_READ_REG(hw, IXGBE_SECTXCTRL);
8256 : 0 : sectxreg |= IXGBE_SECTXCTRL_TX_DIS;
8257 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SECTXCTRL, sectxreg);
8258 [ # # ]: 0 : for (i = 0; i < IXGBE_MAX_SECTX_POLL; i++) {
8259 : 0 : sectxreg = IXGBE_READ_REG(hw, IXGBE_SECTXSTAT);
8260 [ # # ]: 0 : if (sectxreg & IXGBE_SECTXSTAT_SECTX_RDY)
8261 : : break;
8262 : : /* Use interrupt-safe sleep just in case */
8263 : 0 : usec_delay(1000);
8264 : : }
8265 : :
8266 : : /* For informational purposes only */
8267 [ # # ]: 0 : if (i >= IXGBE_MAX_SECTX_POLL)
8268 : 0 : PMD_DRV_LOG(DEBUG, "Tx unit being enabled before security "
8269 : : "path fully disabled. Continuing with init.");
8270 : :
8271 : 0 : return IXGBE_SUCCESS;
8272 : : }
8273 : :
8274 : : /**
8275 : : * ixgbe_enable_sec_tx_path_generic - Enables the transmit data path
8276 : : * @hw: pointer to hardware structure
8277 : : *
8278 : : * Enables the transmit data path.
8279 : : **/
8280 : 0 : int ixgbe_enable_sec_tx_path_generic(struct ixgbe_hw *hw)
8281 : : {
8282 : : uint32_t sectxreg;
8283 : :
8284 : 0 : sectxreg = IXGBE_READ_REG(hw, IXGBE_SECTXCTRL);
8285 : 0 : sectxreg &= ~IXGBE_SECTXCTRL_TX_DIS;
8286 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SECTXCTRL, sectxreg);
8287 : 0 : IXGBE_WRITE_FLUSH(hw);
8288 : :
8289 : 0 : return IXGBE_SUCCESS;
8290 : : }
8291 : :
8292 : : /* restore n-tuple filter */
8293 : : static inline void
8294 : : ixgbe_ntuple_filter_restore(struct rte_eth_dev *dev)
8295 : : {
8296 : : struct ixgbe_filter_info *filter_info =
8297 : 0 : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8298 : : struct ixgbe_5tuple_filter *node;
8299 : :
8300 [ # # ]: 0 : TAILQ_FOREACH(node, &filter_info->fivetuple_list, entries) {
8301 : 0 : ixgbe_inject_5tuple_filter(dev, node);
8302 : : }
8303 : : }
8304 : :
8305 : : /* restore ethernet type filter */
8306 : : static inline void
8307 : 0 : ixgbe_ethertype_filter_restore(struct rte_eth_dev *dev)
8308 : : {
8309 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8310 : : struct ixgbe_filter_info *filter_info =
8311 : : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8312 : : int i;
8313 : :
8314 [ # # ]: 0 : for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
8315 [ # # ]: 0 : if (filter_info->ethertype_mask & (1 << i)) {
8316 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETQF(i),
8317 : : filter_info->ethertype_filters[i].etqf);
8318 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETQS(i),
8319 : : filter_info->ethertype_filters[i].etqs);
8320 : 0 : IXGBE_WRITE_FLUSH(hw);
8321 : : }
8322 : : }
8323 : 0 : }
8324 : :
8325 : : /* restore SYN filter */
8326 : : static inline void
8327 : : ixgbe_syn_filter_restore(struct rte_eth_dev *dev)
8328 : : {
8329 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8330 : : struct ixgbe_filter_info *filter_info =
8331 : : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8332 : : uint32_t synqf;
8333 : :
8334 : 0 : synqf = filter_info->syn_info;
8335 : :
8336 [ # # ]: 0 : if (synqf & IXGBE_SYN_FILTER_ENABLE) {
8337 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SYNQF, synqf);
8338 : 0 : IXGBE_WRITE_FLUSH(hw);
8339 : : }
8340 : : }
8341 : :
8342 : : /* restore L2 tunnel filter */
8343 : : static inline void
8344 : 0 : ixgbe_l2_tn_filter_restore(struct rte_eth_dev *dev)
8345 : : {
8346 : : struct ixgbe_l2_tn_info *l2_tn_info =
8347 : 0 : IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
8348 : : struct ixgbe_l2_tn_filter *node;
8349 : : struct ixgbe_l2_tunnel_conf l2_tn_conf;
8350 : :
8351 [ # # ]: 0 : TAILQ_FOREACH(node, &l2_tn_info->l2_tn_list, entries) {
8352 : 0 : l2_tn_conf.l2_tunnel_type = node->key.l2_tn_type;
8353 : 0 : l2_tn_conf.tunnel_id = node->key.tn_id;
8354 : 0 : l2_tn_conf.pool = node->pool;
8355 : 0 : (void)ixgbe_dev_l2_tunnel_filter_add(dev, &l2_tn_conf, TRUE);
8356 : : }
8357 : 0 : }
8358 : :
8359 : : /* restore rss filter */
8360 : : static inline void
8361 : : ixgbe_rss_filter_restore(struct rte_eth_dev *dev)
8362 : : {
8363 : : struct ixgbe_filter_info *filter_info =
8364 : 0 : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8365 : :
8366 [ # # ]: 0 : if (filter_info->rss_info.conf.queue_num)
8367 : 0 : ixgbe_config_rss_filter(dev,
8368 : : &filter_info->rss_info, TRUE);
8369 : : }
8370 : :
8371 : : static int
8372 : 0 : ixgbe_filter_restore(struct rte_eth_dev *dev)
8373 : : {
8374 : : ixgbe_ntuple_filter_restore(dev);
8375 : 0 : ixgbe_ethertype_filter_restore(dev);
8376 : : ixgbe_syn_filter_restore(dev);
8377 : 0 : ixgbe_fdir_filter_restore(dev);
8378 : 0 : ixgbe_l2_tn_filter_restore(dev);
8379 : : ixgbe_rss_filter_restore(dev);
8380 : :
8381 : 0 : return 0;
8382 : : }
8383 : :
8384 : : static void
8385 : 0 : ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev)
8386 : : {
8387 : : struct ixgbe_l2_tn_info *l2_tn_info =
8388 : 0 : IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
8389 : : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8390 : :
8391 [ # # ]: 0 : if (l2_tn_info->e_tag_en)
8392 : : (void)ixgbe_e_tag_enable(hw);
8393 : :
8394 [ # # ]: 0 : if (l2_tn_info->e_tag_fwd_en)
8395 : : (void)ixgbe_e_tag_forwarding_en_dis(dev, 1);
8396 : :
8397 [ # # ]: 0 : (void)ixgbe_update_e_tag_eth_type(hw, l2_tn_info->e_tag_ether_type);
8398 : 0 : }
8399 : :
8400 : : /* remove all the n-tuple filters */
8401 : : void
8402 : 0 : ixgbe_clear_all_ntuple_filter(struct rte_eth_dev *dev)
8403 : : {
8404 : : struct ixgbe_filter_info *filter_info =
8405 : 0 : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8406 : : struct ixgbe_5tuple_filter *p_5tuple;
8407 : :
8408 [ # # ]: 0 : while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list)))
8409 : 0 : ixgbe_remove_5tuple_filter(dev, p_5tuple);
8410 : 0 : }
8411 : :
8412 : : /* remove all the ether type filters */
8413 : : void
8414 : 0 : ixgbe_clear_all_ethertype_filter(struct rte_eth_dev *dev)
8415 : : {
8416 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8417 : : struct ixgbe_filter_info *filter_info =
8418 : : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8419 : : int i;
8420 : :
8421 [ # # ]: 0 : for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
8422 [ # # ]: 0 : if (filter_info->ethertype_mask & (1 << i) &&
8423 [ # # ]: 0 : !filter_info->ethertype_filters[i].conf) {
8424 : : (void)ixgbe_ethertype_filter_remove(filter_info,
8425 : : (uint8_t)i);
8426 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETQF(i), 0);
8427 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETQS(i), 0);
8428 : 0 : IXGBE_WRITE_FLUSH(hw);
8429 : : }
8430 : : }
8431 : 0 : }
8432 : :
8433 : : /* remove the SYN filter */
8434 : : void
8435 : 0 : ixgbe_clear_syn_filter(struct rte_eth_dev *dev)
8436 : : {
8437 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8438 : : struct ixgbe_filter_info *filter_info =
8439 : : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
8440 : :
8441 [ # # ]: 0 : if (filter_info->syn_info & IXGBE_SYN_FILTER_ENABLE) {
8442 : 0 : filter_info->syn_info = 0;
8443 : :
8444 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SYNQF, 0);
8445 : 0 : IXGBE_WRITE_FLUSH(hw);
8446 : : }
8447 : 0 : }
8448 : :
8449 : : /* remove all the L2 tunnel filters */
8450 : : int
8451 : 0 : ixgbe_clear_all_l2_tn_filter(struct rte_eth_dev *dev)
8452 : : {
8453 : : struct ixgbe_l2_tn_info *l2_tn_info =
8454 : 0 : IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
8455 : : struct ixgbe_l2_tn_filter *l2_tn_filter;
8456 : : struct ixgbe_l2_tunnel_conf l2_tn_conf;
8457 : : int ret = 0;
8458 : :
8459 [ # # ]: 0 : while ((l2_tn_filter = TAILQ_FIRST(&l2_tn_info->l2_tn_list))) {
8460 : 0 : l2_tn_conf.l2_tunnel_type = l2_tn_filter->key.l2_tn_type;
8461 : 0 : l2_tn_conf.tunnel_id = l2_tn_filter->key.tn_id;
8462 : 0 : l2_tn_conf.pool = l2_tn_filter->pool;
8463 : 0 : ret = ixgbe_dev_l2_tunnel_filter_del(dev, &l2_tn_conf);
8464 [ # # ]: 0 : if (ret < 0)
8465 : 0 : return ret;
8466 : : }
8467 : :
8468 : : return 0;
8469 : : }
8470 : :
8471 : : void
8472 : 0 : ixgbe_dev_macsec_setting_save(struct rte_eth_dev *dev,
8473 : : struct ixgbe_macsec_setting *macsec_setting)
8474 : : {
8475 : : struct ixgbe_macsec_setting *macsec =
8476 : 0 : IXGBE_DEV_PRIVATE_TO_MACSEC_SETTING(dev->data->dev_private);
8477 : :
8478 : 0 : macsec->offload_en = macsec_setting->offload_en;
8479 : 0 : macsec->encrypt_en = macsec_setting->encrypt_en;
8480 : 0 : macsec->replayprotect_en = macsec_setting->replayprotect_en;
8481 : 0 : }
8482 : :
8483 : : void
8484 : 0 : ixgbe_dev_macsec_setting_reset(struct rte_eth_dev *dev)
8485 : : {
8486 : : struct ixgbe_macsec_setting *macsec =
8487 : 0 : IXGBE_DEV_PRIVATE_TO_MACSEC_SETTING(dev->data->dev_private);
8488 : :
8489 : 0 : macsec->offload_en = 0;
8490 : 0 : macsec->encrypt_en = 0;
8491 : 0 : macsec->replayprotect_en = 0;
8492 : 0 : }
8493 : :
8494 : : void
8495 : 0 : ixgbe_dev_macsec_register_enable(struct rte_eth_dev *dev,
8496 : : struct ixgbe_macsec_setting *macsec_setting)
8497 : : {
8498 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8499 : : uint32_t ctrl;
8500 : 0 : uint8_t en = macsec_setting->encrypt_en;
8501 : 0 : uint8_t rp = macsec_setting->replayprotect_en;
8502 : :
8503 : : /**
8504 : : * Workaround:
8505 : : * As no ixgbe_disable_sec_rx_path equivalent is
8506 : : * implemented for tx in the base code, and we are
8507 : : * not allowed to modify the base code in DPDK, so
8508 : : * just call the hand-written one directly for now.
8509 : : * The hardware support has been checked by
8510 : : * ixgbe_disable_sec_rx_path().
8511 : : */
8512 : 0 : ixgbe_disable_sec_tx_path_generic(hw);
8513 : :
8514 : : /* Enable Ethernet CRC (required by MACsec offload) */
8515 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_HLREG0);
8516 : 0 : ctrl |= IXGBE_HLREG0_TXCRCEN | IXGBE_HLREG0_RXCRCSTRP;
8517 : 0 : IXGBE_WRITE_REG(hw, IXGBE_HLREG0, ctrl);
8518 : :
8519 : : /* Enable the TX and RX crypto engines */
8520 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_SECTXCTRL);
8521 : 0 : ctrl &= ~IXGBE_SECTXCTRL_SECTX_DIS;
8522 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SECTXCTRL, ctrl);
8523 : :
8524 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
8525 : 0 : ctrl &= ~IXGBE_SECRXCTRL_SECRX_DIS;
8526 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, ctrl);
8527 : :
8528 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
8529 : 0 : ctrl &= ~IXGBE_SECTX_MINSECIFG_MASK;
8530 : 0 : ctrl |= 0x3;
8531 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, ctrl);
8532 : :
8533 : : /* Enable SA lookup */
8534 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_LSECTXCTRL);
8535 : 0 : ctrl &= ~IXGBE_LSECTXCTRL_EN_MASK;
8536 [ # # ]: 0 : ctrl |= en ? IXGBE_LSECTXCTRL_AUTH_ENCRYPT :
8537 : : IXGBE_LSECTXCTRL_AUTH;
8538 : : ctrl |= IXGBE_LSECTXCTRL_AISCI;
8539 : : ctrl &= ~IXGBE_LSECTXCTRL_PNTHRSH_MASK;
8540 : 0 : ctrl |= IXGBE_MACSEC_PNTHRSH & IXGBE_LSECTXCTRL_PNTHRSH_MASK;
8541 : 0 : IXGBE_WRITE_REG(hw, IXGBE_LSECTXCTRL, ctrl);
8542 : :
8543 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_LSECRXCTRL);
8544 : : ctrl &= ~IXGBE_LSECRXCTRL_EN_MASK;
8545 : : ctrl |= IXGBE_LSECRXCTRL_STRICT << IXGBE_LSECRXCTRL_EN_SHIFT;
8546 : : ctrl &= ~IXGBE_LSECRXCTRL_PLSH;
8547 [ # # ]: 0 : if (rp)
8548 : 0 : ctrl |= IXGBE_LSECRXCTRL_RP;
8549 : : else
8550 : 0 : ctrl &= ~IXGBE_LSECRXCTRL_RP;
8551 : 0 : IXGBE_WRITE_REG(hw, IXGBE_LSECRXCTRL, ctrl);
8552 : :
8553 : : /* Start the data paths */
8554 : 0 : ixgbe_enable_sec_rx_path(hw);
8555 : : /**
8556 : : * Workaround:
8557 : : * As no ixgbe_enable_sec_rx_path equivalent is
8558 : : * implemented for tx in the base code, and we are
8559 : : * not allowed to modify the base code in DPDK, so
8560 : : * just call the hand-written one directly for now.
8561 : : */
8562 : 0 : ixgbe_enable_sec_tx_path_generic(hw);
8563 : 0 : }
8564 : :
8565 : : void
8566 : 0 : ixgbe_dev_macsec_register_disable(struct rte_eth_dev *dev)
8567 : : {
8568 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8569 : : uint32_t ctrl;
8570 : :
8571 : : /**
8572 : : * Workaround:
8573 : : * As no ixgbe_disable_sec_rx_path equivalent is
8574 : : * implemented for tx in the base code, and we are
8575 : : * not allowed to modify the base code in DPDK, so
8576 : : * just call the hand-written one directly for now.
8577 : : * The hardware support has been checked by
8578 : : * ixgbe_disable_sec_rx_path().
8579 : : */
8580 : 0 : ixgbe_disable_sec_tx_path_generic(hw);
8581 : :
8582 : : /* Disable the TX and RX crypto engines */
8583 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_SECTXCTRL);
8584 : 0 : ctrl |= IXGBE_SECTXCTRL_SECTX_DIS;
8585 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SECTXCTRL, ctrl);
8586 : :
8587 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
8588 : 0 : ctrl |= IXGBE_SECRXCTRL_SECRX_DIS;
8589 : 0 : IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, ctrl);
8590 : :
8591 : : /* Disable SA lookup */
8592 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_LSECTXCTRL);
8593 : 0 : ctrl &= ~IXGBE_LSECTXCTRL_EN_MASK;
8594 : : ctrl |= IXGBE_LSECTXCTRL_DISABLE;
8595 : 0 : IXGBE_WRITE_REG(hw, IXGBE_LSECTXCTRL, ctrl);
8596 : :
8597 : 0 : ctrl = IXGBE_READ_REG(hw, IXGBE_LSECRXCTRL);
8598 : 0 : ctrl &= ~IXGBE_LSECRXCTRL_EN_MASK;
8599 : : ctrl |= IXGBE_LSECRXCTRL_DISABLE << IXGBE_LSECRXCTRL_EN_SHIFT;
8600 : 0 : IXGBE_WRITE_REG(hw, IXGBE_LSECRXCTRL, ctrl);
8601 : :
8602 : : /* Start the data paths */
8603 : 0 : ixgbe_enable_sec_rx_path(hw);
8604 : : /**
8605 : : * Workaround:
8606 : : * As no ixgbe_enable_sec_rx_path equivalent is
8607 : : * implemented for tx in the base code, and we are
8608 : : * not allowed to modify the base code in DPDK, so
8609 : : * just call the hand-written one directly for now.
8610 : : */
8611 : 0 : ixgbe_enable_sec_tx_path_generic(hw);
8612 : 0 : }
8613 : :
8614 : 252 : RTE_PMD_REGISTER_PCI(net_ixgbe, rte_ixgbe_pmd);
8615 : : RTE_PMD_REGISTER_PCI_TABLE(net_ixgbe, pci_id_ixgbe_map);
8616 : : RTE_PMD_REGISTER_KMOD_DEP(net_ixgbe, "* igb_uio | uio_pci_generic | vfio-pci");
8617 : : RTE_PMD_REGISTER_PARAM_STRING(net_ixgbe,
8618 : : IXGBE_DEVARG_FIBER_SDP3_NOT_TX_DISABLE "=<0|1>");
8619 : 252 : RTE_PMD_REGISTER_PCI(net_ixgbe_vf, rte_ixgbevf_pmd);
8620 : : RTE_PMD_REGISTER_PCI_TABLE(net_ixgbe_vf, pci_id_ixgbevf_map);
8621 : : RTE_PMD_REGISTER_KMOD_DEP(net_ixgbe_vf, "* igb_uio | vfio-pci");
8622 : : RTE_PMD_REGISTER_PARAM_STRING(net_ixgbe_vf,
8623 : : IXGBEVF_DEVARG_PFLINK_FULLCHK "=<0|1>");
8624 : :
8625 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(ixgbe_logtype_init, init, NOTICE);
8626 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(ixgbe_logtype_driver, driver, NOTICE);
8627 : :
8628 : : #ifdef RTE_ETHDEV_DEBUG_RX
8629 : : RTE_LOG_REGISTER_SUFFIX(ixgbe_logtype_rx, rx, DEBUG);
8630 : : #endif
8631 : : #ifdef RTE_ETHDEV_DEBUG_TX
8632 : : RTE_LOG_REGISTER_SUFFIX(ixgbe_logtype_tx, tx, DEBUG);
8633 : : #endif
|