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