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