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