Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <stdarg.h>
10 : :
11 : : #include <rte_string_fns.h>
12 : : #include <rte_common.h>
13 : : #include <rte_interrupts.h>
14 : : #include <rte_byteorder.h>
15 : : #include <rte_log.h>
16 : : #include <rte_debug.h>
17 : : #include <rte_pci.h>
18 : : #include <bus_pci_driver.h>
19 : : #include <rte_ether.h>
20 : : #include <ethdev_driver.h>
21 : : #include <ethdev_pci.h>
22 : : #include <rte_memory.h>
23 : : #include <rte_eal.h>
24 : : #include <rte_malloc.h>
25 : : #include <dev_driver.h>
26 : :
27 : : #include "e1000_logs.h"
28 : : #include "base/e1000_api.h"
29 : : #include "e1000_ethdev.h"
30 : : #include "igb_regs.h"
31 : :
32 : : /*
33 : : * Default values for port configuration
34 : : */
35 : : #define IGB_DEFAULT_RX_FREE_THRESH 32
36 : :
37 : : #define IGB_DEFAULT_RX_PTHRESH ((hw->mac.type == e1000_i354) ? 12 : 8)
38 : : #define IGB_DEFAULT_RX_HTHRESH 8
39 : : #define IGB_DEFAULT_RX_WTHRESH ((hw->mac.type == e1000_82576) ? 1 : 4)
40 : :
41 : : #define IGB_DEFAULT_TX_PTHRESH ((hw->mac.type == e1000_i354) ? 20 : 8)
42 : : #define IGB_DEFAULT_TX_HTHRESH 1
43 : : #define IGB_DEFAULT_TX_WTHRESH ((hw->mac.type == e1000_82576) ? 1 : 16)
44 : :
45 : : /* Bit shift and mask */
46 : : #define IGB_4_BIT_WIDTH (CHAR_BIT / 2)
47 : : #define IGB_4_BIT_MASK RTE_LEN2MASK(IGB_4_BIT_WIDTH, uint8_t)
48 : : #define IGB_8_BIT_WIDTH CHAR_BIT
49 : : #define IGB_8_BIT_MASK UINT8_MAX
50 : :
51 : : /* Additional timesync values. */
52 : : #define E1000_CYCLECOUNTER_MASK 0xffffffffffffffffULL
53 : : #define E1000_ETQF_FILTER_1588 3
54 : : #define IGB_82576_TSYNC_SHIFT 16
55 : : #define E1000_INCPERIOD_82576 (1 << E1000_TIMINCA_16NS_SHIFT)
56 : : #define E1000_INCVALUE_82576 (16 << IGB_82576_TSYNC_SHIFT)
57 : : #define E1000_TSAUXC_DISABLE_SYSTIME 0x80000000
58 : :
59 : : #define E1000_VTIVAR_MISC 0x01740
60 : : #define E1000_VTIVAR_MISC_MASK 0xFF
61 : : #define E1000_VTIVAR_VALID 0x80
62 : : #define E1000_VTIVAR_MISC_MAILBOX 0
63 : : #define E1000_VTIVAR_MISC_INTR_MASK 0x3
64 : :
65 : : /* External VLAN Enable bit mask */
66 : : #define E1000_CTRL_EXT_EXT_VLAN (1 << 26)
67 : :
68 : : /* External VLAN Ether Type bit mask and shift */
69 : : #define E1000_VET_VET_EXT 0xFFFF0000
70 : : #define E1000_VET_VET_EXT_SHIFT 16
71 : :
72 : : /* MSI-X other interrupt vector */
73 : : #define IGB_MSIX_OTHER_INTR_VEC 0
74 : :
75 : : static int eth_igb_configure(struct rte_eth_dev *dev);
76 : : static int eth_igb_start(struct rte_eth_dev *dev);
77 : : static int eth_igb_stop(struct rte_eth_dev *dev);
78 : : static int eth_igb_dev_set_link_up(struct rte_eth_dev *dev);
79 : : static int eth_igb_dev_set_link_down(struct rte_eth_dev *dev);
80 : : static int eth_igb_close(struct rte_eth_dev *dev);
81 : : static int eth_igb_reset(struct rte_eth_dev *dev);
82 : : static int eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
83 : : static int eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
84 : : static int eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
85 : : static int eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
86 : : static int eth_igb_link_update(struct rte_eth_dev *dev,
87 : : int wait_to_complete);
88 : : static int eth_igb_stats_get(struct rte_eth_dev *dev,
89 : : struct rte_eth_stats *rte_stats);
90 : : static int eth_igb_xstats_get(struct rte_eth_dev *dev,
91 : : struct rte_eth_xstat *xstats, unsigned n);
92 : : static int eth_igb_xstats_get_by_id(struct rte_eth_dev *dev,
93 : : const uint64_t *ids,
94 : : uint64_t *values, unsigned int n);
95 : : static int eth_igb_xstats_get_names(struct rte_eth_dev *dev,
96 : : struct rte_eth_xstat_name *xstats_names,
97 : : unsigned int size);
98 : : static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
99 : : const uint64_t *ids, struct rte_eth_xstat_name *xstats_names,
100 : : unsigned int limit);
101 : : static int eth_igb_stats_reset(struct rte_eth_dev *dev);
102 : : static int eth_igb_xstats_reset(struct rte_eth_dev *dev);
103 : : static int eth_igb_fw_version_get(struct rte_eth_dev *dev,
104 : : char *fw_version, size_t fw_size);
105 : : static int eth_igb_infos_get(struct rte_eth_dev *dev,
106 : : struct rte_eth_dev_info *dev_info);
107 : : static const uint32_t *eth_igb_supported_ptypes_get(struct rte_eth_dev *dev,
108 : : size_t *no_of_elements);
109 : : static int eth_igbvf_infos_get(struct rte_eth_dev *dev,
110 : : struct rte_eth_dev_info *dev_info);
111 : : static int eth_igb_flow_ctrl_get(struct rte_eth_dev *dev,
112 : : struct rte_eth_fc_conf *fc_conf);
113 : : static int eth_igb_flow_ctrl_set(struct rte_eth_dev *dev,
114 : : struct rte_eth_fc_conf *fc_conf);
115 : : static int eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on);
116 : : static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev);
117 : : static int eth_igb_interrupt_get_status(struct rte_eth_dev *dev);
118 : : static int eth_igb_interrupt_action(struct rte_eth_dev *dev,
119 : : struct rte_intr_handle *handle);
120 : : static void eth_igb_interrupt_handler(void *param);
121 : : static int igb_hardware_init(struct e1000_hw *hw);
122 : : static void igb_hw_control_acquire(struct e1000_hw *hw);
123 : : static void igb_hw_control_release(struct e1000_hw *hw);
124 : : static void igb_init_manageability(struct e1000_hw *hw);
125 : : static void igb_release_manageability(struct e1000_hw *hw);
126 : :
127 : : static int eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
128 : :
129 : : static int eth_igb_vlan_filter_set(struct rte_eth_dev *dev,
130 : : uint16_t vlan_id, int on);
131 : : static int eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
132 : : enum rte_vlan_type vlan_type,
133 : : uint16_t tpid_id);
134 : : static int eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask);
135 : :
136 : : static void igb_vlan_hw_filter_enable(struct rte_eth_dev *dev);
137 : : static void igb_vlan_hw_filter_disable(struct rte_eth_dev *dev);
138 : : static void igb_vlan_hw_strip_enable(struct rte_eth_dev *dev);
139 : : static void igb_vlan_hw_strip_disable(struct rte_eth_dev *dev);
140 : : static void igb_vlan_hw_extend_enable(struct rte_eth_dev *dev);
141 : : static void igb_vlan_hw_extend_disable(struct rte_eth_dev *dev);
142 : :
143 : : static int eth_igb_led_on(struct rte_eth_dev *dev);
144 : : static int eth_igb_led_off(struct rte_eth_dev *dev);
145 : :
146 : : static void igb_intr_disable(struct rte_eth_dev *dev);
147 : : static int igb_get_rx_buffer_size(struct e1000_hw *hw);
148 : : static int eth_igb_rar_set(struct rte_eth_dev *dev,
149 : : struct rte_ether_addr *mac_addr,
150 : : uint32_t index, uint32_t pool);
151 : : static void eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index);
152 : : static int eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
153 : : struct rte_ether_addr *addr);
154 : :
155 : : static void igbvf_intr_disable(struct e1000_hw *hw);
156 : : static int igbvf_dev_configure(struct rte_eth_dev *dev);
157 : : static int igbvf_dev_start(struct rte_eth_dev *dev);
158 : : static int igbvf_dev_stop(struct rte_eth_dev *dev);
159 : : static int igbvf_dev_close(struct rte_eth_dev *dev);
160 : : static int igbvf_promiscuous_enable(struct rte_eth_dev *dev);
161 : : static int igbvf_promiscuous_disable(struct rte_eth_dev *dev);
162 : : static int igbvf_allmulticast_enable(struct rte_eth_dev *dev);
163 : : static int igbvf_allmulticast_disable(struct rte_eth_dev *dev);
164 : : static int eth_igbvf_link_update(struct e1000_hw *hw);
165 : : static int eth_igbvf_stats_get(struct rte_eth_dev *dev,
166 : : struct rte_eth_stats *rte_stats);
167 : : static int eth_igbvf_xstats_get(struct rte_eth_dev *dev,
168 : : struct rte_eth_xstat *xstats, unsigned n);
169 : : static int eth_igbvf_xstats_get_names(struct rte_eth_dev *dev,
170 : : struct rte_eth_xstat_name *xstats_names,
171 : : unsigned limit);
172 : : static int eth_igbvf_stats_reset(struct rte_eth_dev *dev);
173 : : static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
174 : : uint16_t vlan_id, int on);
175 : : static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
176 : : static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on);
177 : : static int igbvf_default_mac_addr_set(struct rte_eth_dev *dev,
178 : : struct rte_ether_addr *addr);
179 : : static int igbvf_get_reg_length(struct rte_eth_dev *dev);
180 : : static int igbvf_get_regs(struct rte_eth_dev *dev,
181 : : struct rte_dev_reg_info *regs);
182 : :
183 : : static int eth_igb_rss_reta_update(struct rte_eth_dev *dev,
184 : : struct rte_eth_rss_reta_entry64 *reta_conf,
185 : : uint16_t reta_size);
186 : : static int eth_igb_rss_reta_query(struct rte_eth_dev *dev,
187 : : struct rte_eth_rss_reta_entry64 *reta_conf,
188 : : uint16_t reta_size);
189 : :
190 : : static int igb_add_2tuple_filter(struct rte_eth_dev *dev,
191 : : struct rte_eth_ntuple_filter *ntuple_filter);
192 : : static int igb_remove_2tuple_filter(struct rte_eth_dev *dev,
193 : : struct rte_eth_ntuple_filter *ntuple_filter);
194 : : static int igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
195 : : struct rte_eth_ntuple_filter *ntuple_filter);
196 : : static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
197 : : struct rte_eth_ntuple_filter *ntuple_filter);
198 : : static int eth_igb_flow_ops_get(struct rte_eth_dev *dev,
199 : : const struct rte_flow_ops **ops);
200 : : static int eth_igb_get_reg_length(struct rte_eth_dev *dev);
201 : : static int eth_igb_get_regs(struct rte_eth_dev *dev,
202 : : struct rte_dev_reg_info *regs);
203 : : static int eth_igb_get_eeprom_length(struct rte_eth_dev *dev);
204 : : static int eth_igb_get_eeprom(struct rte_eth_dev *dev,
205 : : struct rte_dev_eeprom_info *eeprom);
206 : : static int eth_igb_set_eeprom(struct rte_eth_dev *dev,
207 : : struct rte_dev_eeprom_info *eeprom);
208 : : static int eth_igb_get_module_info(struct rte_eth_dev *dev,
209 : : struct rte_eth_dev_module_info *modinfo);
210 : : static int eth_igb_get_module_eeprom(struct rte_eth_dev *dev,
211 : : struct rte_dev_eeprom_info *info);
212 : : static int eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
213 : : struct rte_ether_addr *mc_addr_set,
214 : : uint32_t nb_mc_addr);
215 : : static int igb_timesync_enable(struct rte_eth_dev *dev);
216 : : static int igb_timesync_disable(struct rte_eth_dev *dev);
217 : : static int igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
218 : : struct timespec *timestamp,
219 : : uint32_t flags);
220 : : static int igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
221 : : struct timespec *timestamp);
222 : : static int igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
223 : : static int igb_timesync_read_time(struct rte_eth_dev *dev,
224 : : struct timespec *timestamp);
225 : : static int igb_timesync_write_time(struct rte_eth_dev *dev,
226 : : const struct timespec *timestamp);
227 : : static int eth_igb_read_clock(struct rte_eth_dev *dev, uint64_t *clock);
228 : : static int eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev,
229 : : uint16_t queue_id);
230 : : static int eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev,
231 : : uint16_t queue_id);
232 : : static void eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
233 : : uint8_t queue, uint8_t msix_vector);
234 : : static void eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
235 : : uint8_t index, uint8_t offset);
236 : : static void eth_igb_configure_msix_intr(struct rte_eth_dev *dev);
237 : : static void eth_igbvf_interrupt_handler(void *param);
238 : : static void igbvf_mbx_process(struct rte_eth_dev *dev);
239 : : static int igb_filter_restore(struct rte_eth_dev *dev);
240 : : static int igb_tx_burst_mode_get(struct rte_eth_dev *dev,
241 : : __rte_unused uint16_t queue_id, struct rte_eth_burst_mode *mode);
242 : : static int igb_rx_burst_mode_get(struct rte_eth_dev *dev,
243 : : __rte_unused uint16_t queue_id, struct rte_eth_burst_mode *mode);
244 : :
245 : : /*
246 : : * Define VF Stats MACRO for Non "cleared on read" register
247 : : */
248 : : #define UPDATE_VF_STAT(reg, last, cur) \
249 : : { \
250 : : u32 latest = E1000_READ_REG(hw, reg); \
251 : : cur += (latest - last) & UINT_MAX; \
252 : : last = latest; \
253 : : }
254 : :
255 : : #define IGB_FC_PAUSE_TIME 0x0680
256 : : #define IGB_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
257 : : #define IGB_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
258 : :
259 : : #define IGBVF_PMD_NAME "rte_igbvf_pmd" /* PMD name */
260 : :
261 : : static enum e1000_fc_mode igb_fc_setting = e1000_fc_full;
262 : :
263 : : /*
264 : : * The set of PCI devices this driver supports
265 : : */
266 : : static const struct rte_pci_id pci_id_igb_map[] = {
267 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576) },
268 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_FIBER) },
269 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES) },
270 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER) },
271 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_QUAD_COPPER_ET2) },
272 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS) },
273 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_NS_SERDES) },
274 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_SERDES_QUAD) },
275 : :
276 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_COPPER) },
277 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575EB_FIBER_SERDES) },
278 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82575GB_QUAD_COPPER) },
279 : :
280 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER) },
281 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_FIBER) },
282 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SERDES) },
283 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_SGMII) },
284 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_COPPER_DUAL) },
285 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82580_QUAD_FIBER) },
286 : :
287 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_COPPER) },
288 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_FIBER) },
289 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SERDES) },
290 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_SGMII) },
291 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_DA4) },
292 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER) },
293 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_OEM1) },
294 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_IT) },
295 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_FIBER) },
296 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES) },
297 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SGMII) },
298 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_COPPER_FLASHLESS) },
299 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SERDES_FLASHLESS) },
300 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I210_SGMII_FLASHLESS) },
301 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I211_COPPER) },
302 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_1GBPS) },
303 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_SGMII) },
304 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I354_BACKPLANE_2_5GBPS) },
305 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SGMII) },
306 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SERDES) },
307 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_BACKPLANE) },
308 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_DH89XXCC_SFP) },
309 : : { .vendor_id = 0, /* sentinel */ },
310 : : };
311 : :
312 : : /*
313 : : * The set of PCI devices this driver supports (for 82576&I350 VF)
314 : : */
315 : : static const struct rte_pci_id pci_id_igbvf_map[] = {
316 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF) },
317 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82576_VF_HV) },
318 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF) },
319 : : { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_I350_VF_HV) },
320 : : { .vendor_id = 0, /* sentinel */ },
321 : : };
322 : :
323 : : uint64_t igb_tx_timestamp_dynflag;
324 : : int igb_tx_timestamp_dynfield_offset = -1;
325 : :
326 : : static const struct rte_eth_desc_lim rx_desc_lim = {
327 : : .nb_max = E1000_MAX_RING_DESC,
328 : : .nb_min = E1000_MIN_RING_DESC,
329 : : .nb_align = IGB_RXD_ALIGN,
330 : : };
331 : :
332 : : static const struct rte_eth_desc_lim tx_desc_lim = {
333 : : .nb_max = E1000_MAX_RING_DESC,
334 : : .nb_min = E1000_MIN_RING_DESC,
335 : : .nb_align = IGB_RXD_ALIGN,
336 : : .nb_seg_max = IGB_TX_MAX_SEG,
337 : : .nb_mtu_seg_max = IGB_TX_MAX_MTU_SEG,
338 : : };
339 : :
340 : : static const struct eth_dev_ops eth_igb_ops = {
341 : : .dev_configure = eth_igb_configure,
342 : : .dev_start = eth_igb_start,
343 : : .dev_stop = eth_igb_stop,
344 : : .dev_set_link_up = eth_igb_dev_set_link_up,
345 : : .dev_set_link_down = eth_igb_dev_set_link_down,
346 : : .dev_close = eth_igb_close,
347 : : .dev_reset = eth_igb_reset,
348 : : .promiscuous_enable = eth_igb_promiscuous_enable,
349 : : .promiscuous_disable = eth_igb_promiscuous_disable,
350 : : .allmulticast_enable = eth_igb_allmulticast_enable,
351 : : .allmulticast_disable = eth_igb_allmulticast_disable,
352 : : .link_update = eth_igb_link_update,
353 : : .stats_get = eth_igb_stats_get,
354 : : .xstats_get = eth_igb_xstats_get,
355 : : .xstats_get_by_id = eth_igb_xstats_get_by_id,
356 : : .xstats_get_names_by_id = eth_igb_xstats_get_names_by_id,
357 : : .xstats_get_names = eth_igb_xstats_get_names,
358 : : .stats_reset = eth_igb_stats_reset,
359 : : .xstats_reset = eth_igb_xstats_reset,
360 : : .fw_version_get = eth_igb_fw_version_get,
361 : : .dev_infos_get = eth_igb_infos_get,
362 : : .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
363 : : .mtu_set = eth_igb_mtu_set,
364 : : .vlan_filter_set = eth_igb_vlan_filter_set,
365 : : .vlan_tpid_set = eth_igb_vlan_tpid_set,
366 : : .vlan_offload_set = eth_igb_vlan_offload_set,
367 : : .rx_queue_setup = eth_igb_rx_queue_setup,
368 : : .rx_queue_intr_enable = eth_igb_rx_queue_intr_enable,
369 : : .rx_queue_intr_disable = eth_igb_rx_queue_intr_disable,
370 : : .rx_queue_release = eth_igb_rx_queue_release,
371 : : .tx_queue_setup = eth_igb_tx_queue_setup,
372 : : .tx_queue_release = eth_igb_tx_queue_release,
373 : : .tx_done_cleanup = eth_igb_tx_done_cleanup,
374 : : .rx_burst_mode_get = igb_rx_burst_mode_get,
375 : : .tx_burst_mode_get = igb_tx_burst_mode_get,
376 : : .dev_led_on = eth_igb_led_on,
377 : : .dev_led_off = eth_igb_led_off,
378 : : .flow_ctrl_get = eth_igb_flow_ctrl_get,
379 : : .flow_ctrl_set = eth_igb_flow_ctrl_set,
380 : : .mac_addr_add = eth_igb_rar_set,
381 : : .mac_addr_remove = eth_igb_rar_clear,
382 : : .mac_addr_set = eth_igb_default_mac_addr_set,
383 : : .reta_update = eth_igb_rss_reta_update,
384 : : .reta_query = eth_igb_rss_reta_query,
385 : : .rss_hash_update = eth_igb_rss_hash_update,
386 : : .rss_hash_conf_get = eth_igb_rss_hash_conf_get,
387 : : .flow_ops_get = eth_igb_flow_ops_get,
388 : : .set_mc_addr_list = eth_igb_set_mc_addr_list,
389 : : .rxq_info_get = igb_rxq_info_get,
390 : : .txq_info_get = igb_txq_info_get,
391 : : .timesync_enable = igb_timesync_enable,
392 : : .timesync_disable = igb_timesync_disable,
393 : : .timesync_read_rx_timestamp = igb_timesync_read_rx_timestamp,
394 : : .timesync_read_tx_timestamp = igb_timesync_read_tx_timestamp,
395 : : .get_reg = eth_igb_get_regs,
396 : : .get_eeprom_length = eth_igb_get_eeprom_length,
397 : : .get_eeprom = eth_igb_get_eeprom,
398 : : .set_eeprom = eth_igb_set_eeprom,
399 : : .get_module_info = eth_igb_get_module_info,
400 : : .get_module_eeprom = eth_igb_get_module_eeprom,
401 : : .timesync_adjust_time = igb_timesync_adjust_time,
402 : : .timesync_read_time = igb_timesync_read_time,
403 : : .timesync_write_time = igb_timesync_write_time,
404 : : .read_clock = eth_igb_read_clock,
405 : : };
406 : :
407 : : /*
408 : : * dev_ops for virtual function, bare necessities for basic vf
409 : : * operation have been implemented
410 : : */
411 : : static const struct eth_dev_ops igbvf_eth_dev_ops = {
412 : : .dev_configure = igbvf_dev_configure,
413 : : .dev_start = igbvf_dev_start,
414 : : .dev_stop = igbvf_dev_stop,
415 : : .dev_close = igbvf_dev_close,
416 : : .promiscuous_enable = igbvf_promiscuous_enable,
417 : : .promiscuous_disable = igbvf_promiscuous_disable,
418 : : .allmulticast_enable = igbvf_allmulticast_enable,
419 : : .allmulticast_disable = igbvf_allmulticast_disable,
420 : : .link_update = eth_igb_link_update,
421 : : .stats_get = eth_igbvf_stats_get,
422 : : .xstats_get = eth_igbvf_xstats_get,
423 : : .xstats_get_names = eth_igbvf_xstats_get_names,
424 : : .stats_reset = eth_igbvf_stats_reset,
425 : : .xstats_reset = eth_igbvf_stats_reset,
426 : : .vlan_filter_set = igbvf_vlan_filter_set,
427 : : .dev_infos_get = eth_igbvf_infos_get,
428 : : .dev_supported_ptypes_get = eth_igb_supported_ptypes_get,
429 : : .rx_queue_setup = eth_igb_rx_queue_setup,
430 : : .rx_queue_release = eth_igb_rx_queue_release,
431 : : .tx_queue_setup = eth_igb_tx_queue_setup,
432 : : .tx_queue_release = eth_igb_tx_queue_release,
433 : : .tx_done_cleanup = eth_igb_tx_done_cleanup,
434 : : .rx_burst_mode_get = igb_rx_burst_mode_get,
435 : : .tx_burst_mode_get = igb_tx_burst_mode_get,
436 : : .set_mc_addr_list = eth_igb_set_mc_addr_list,
437 : : .rxq_info_get = igb_rxq_info_get,
438 : : .txq_info_get = igb_txq_info_get,
439 : : .mac_addr_set = igbvf_default_mac_addr_set,
440 : : .get_reg = igbvf_get_regs,
441 : : };
442 : :
443 : : /* store statistics names and its offset in stats structure */
444 : : struct rte_igb_xstats_name_off {
445 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
446 : : unsigned offset;
447 : : };
448 : :
449 : : static const struct rte_igb_xstats_name_off rte_igb_stats_strings[] = {
450 : : {"rx_crc_errors", offsetof(struct e1000_hw_stats, crcerrs)},
451 : : {"rx_align_errors", offsetof(struct e1000_hw_stats, algnerrc)},
452 : : {"rx_symbol_errors", offsetof(struct e1000_hw_stats, symerrs)},
453 : : {"rx_missed_packets", offsetof(struct e1000_hw_stats, mpc)},
454 : : {"tx_single_collision_packets", offsetof(struct e1000_hw_stats, scc)},
455 : : {"tx_multiple_collision_packets", offsetof(struct e1000_hw_stats, mcc)},
456 : : {"tx_excessive_collision_packets", offsetof(struct e1000_hw_stats,
457 : : ecol)},
458 : : {"tx_late_collisions", offsetof(struct e1000_hw_stats, latecol)},
459 : : {"tx_total_collisions", offsetof(struct e1000_hw_stats, colc)},
460 : : {"tx_deferred_packets", offsetof(struct e1000_hw_stats, dc)},
461 : : {"tx_no_carrier_sense_packets", offsetof(struct e1000_hw_stats, tncrs)},
462 : : {"rx_carrier_ext_errors", offsetof(struct e1000_hw_stats, cexterr)},
463 : : {"rx_length_errors", offsetof(struct e1000_hw_stats, rlec)},
464 : : {"rx_xon_packets", offsetof(struct e1000_hw_stats, xonrxc)},
465 : : {"tx_xon_packets", offsetof(struct e1000_hw_stats, xontxc)},
466 : : {"rx_xoff_packets", offsetof(struct e1000_hw_stats, xoffrxc)},
467 : : {"tx_xoff_packets", offsetof(struct e1000_hw_stats, xofftxc)},
468 : : {"rx_flow_control_unsupported_packets", offsetof(struct e1000_hw_stats,
469 : : fcruc)},
470 : : {"rx_size_64_packets", offsetof(struct e1000_hw_stats, prc64)},
471 : : {"rx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, prc127)},
472 : : {"rx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, prc255)},
473 : : {"rx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, prc511)},
474 : : {"rx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
475 : : prc1023)},
476 : : {"rx_size_1024_to_max_packets", offsetof(struct e1000_hw_stats,
477 : : prc1522)},
478 : : {"rx_broadcast_packets", offsetof(struct e1000_hw_stats, bprc)},
479 : : {"rx_multicast_packets", offsetof(struct e1000_hw_stats, mprc)},
480 : : {"rx_undersize_errors", offsetof(struct e1000_hw_stats, ruc)},
481 : : {"rx_fragment_errors", offsetof(struct e1000_hw_stats, rfc)},
482 : : {"rx_oversize_errors", offsetof(struct e1000_hw_stats, roc)},
483 : : {"rx_jabber_errors", offsetof(struct e1000_hw_stats, rjc)},
484 : : {"rx_management_packets", offsetof(struct e1000_hw_stats, mgprc)},
485 : : {"rx_management_dropped", offsetof(struct e1000_hw_stats, mgpdc)},
486 : : {"tx_management_packets", offsetof(struct e1000_hw_stats, mgptc)},
487 : : {"rx_total_packets", offsetof(struct e1000_hw_stats, tpr)},
488 : : {"tx_total_packets", offsetof(struct e1000_hw_stats, tpt)},
489 : : {"rx_total_bytes", offsetof(struct e1000_hw_stats, tor)},
490 : : {"tx_total_bytes", offsetof(struct e1000_hw_stats, tot)},
491 : : {"tx_size_64_packets", offsetof(struct e1000_hw_stats, ptc64)},
492 : : {"tx_size_65_to_127_packets", offsetof(struct e1000_hw_stats, ptc127)},
493 : : {"tx_size_128_to_255_packets", offsetof(struct e1000_hw_stats, ptc255)},
494 : : {"tx_size_256_to_511_packets", offsetof(struct e1000_hw_stats, ptc511)},
495 : : {"tx_size_512_to_1023_packets", offsetof(struct e1000_hw_stats,
496 : : ptc1023)},
497 : : {"tx_size_1024_to_max_packets", offsetof(struct e1000_hw_stats,
498 : : ptc1522)},
499 : : {"tx_multicast_packets", offsetof(struct e1000_hw_stats, mptc)},
500 : : {"tx_broadcast_packets", offsetof(struct e1000_hw_stats, bptc)},
501 : : {"tx_tso_packets", offsetof(struct e1000_hw_stats, tsctc)},
502 : : {"tx_tso_errors", offsetof(struct e1000_hw_stats, tsctfc)},
503 : : {"rx_sent_to_host_packets", offsetof(struct e1000_hw_stats, rpthc)},
504 : : {"tx_sent_by_host_packets", offsetof(struct e1000_hw_stats, hgptc)},
505 : : {"rx_code_violation_packets", offsetof(struct e1000_hw_stats, scvpc)},
506 : :
507 : : {"interrupt_assert_count", offsetof(struct e1000_hw_stats, iac)},
508 : : };
509 : :
510 : : #define IGB_NB_XSTATS (sizeof(rte_igb_stats_strings) / \
511 : : sizeof(rte_igb_stats_strings[0]))
512 : :
513 : : static const struct rte_igb_xstats_name_off rte_igbvf_stats_strings[] = {
514 : : {"rx_multicast_packets", offsetof(struct e1000_vf_stats, mprc)},
515 : : {"rx_good_loopback_packets", offsetof(struct e1000_vf_stats, gprlbc)},
516 : : {"tx_good_loopback_packets", offsetof(struct e1000_vf_stats, gptlbc)},
517 : : {"rx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gorlbc)},
518 : : {"tx_good_loopback_bytes", offsetof(struct e1000_vf_stats, gotlbc)},
519 : : };
520 : :
521 : : #define IGBVF_NB_XSTATS (sizeof(rte_igbvf_stats_strings) / \
522 : : sizeof(rte_igbvf_stats_strings[0]))
523 : :
524 : :
525 : : static inline void
526 : 0 : igb_intr_enable(struct rte_eth_dev *dev)
527 : : {
528 : : struct e1000_interrupt *intr =
529 : 0 : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
530 : : struct e1000_hw *hw =
531 : : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
532 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
533 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
534 : :
535 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle) &&
536 [ # # ]: 0 : dev->data->dev_conf.intr_conf.lsc != 0) {
537 : 0 : E1000_WRITE_REG(hw, E1000_EIMS, 1 << IGB_MSIX_OTHER_INTR_VEC);
538 : : }
539 : :
540 : 0 : E1000_WRITE_REG(hw, E1000_IMS, intr->mask);
541 : 0 : E1000_WRITE_FLUSH(hw);
542 : 0 : }
543 : :
544 : : static void
545 : 0 : igb_intr_disable(struct rte_eth_dev *dev)
546 : : {
547 : : struct e1000_hw *hw =
548 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
549 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
550 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
551 : :
552 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle) &&
553 [ # # ]: 0 : dev->data->dev_conf.intr_conf.lsc != 0) {
554 : 0 : E1000_WRITE_REG(hw, E1000_EIMC, 1 << IGB_MSIX_OTHER_INTR_VEC);
555 : : }
556 : :
557 : 0 : E1000_WRITE_REG(hw, E1000_IMC, ~0);
558 : 0 : E1000_WRITE_FLUSH(hw);
559 : 0 : }
560 : :
561 : : static inline void
562 : : igbvf_intr_enable(struct rte_eth_dev *dev)
563 : : {
564 : : struct e1000_hw *hw =
565 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
566 : :
567 : : /* only for mailbox */
568 : 0 : E1000_WRITE_REG(hw, E1000_EIAM, 1 << E1000_VTIVAR_MISC_MAILBOX);
569 : 0 : E1000_WRITE_REG(hw, E1000_EIAC, 1 << E1000_VTIVAR_MISC_MAILBOX);
570 : 0 : E1000_WRITE_REG(hw, E1000_EIMS, 1 << E1000_VTIVAR_MISC_MAILBOX);
571 : 0 : E1000_WRITE_FLUSH(hw);
572 : : }
573 : :
574 : : /* only for mailbox now. If RX/TX needed, should extend this function. */
575 : : static void
576 : : igbvf_set_ivar_map(struct e1000_hw *hw, uint8_t msix_vector)
577 : : {
578 : : uint32_t tmp = 0;
579 : :
580 : : /* mailbox */
581 : : tmp |= (msix_vector & E1000_VTIVAR_MISC_INTR_MASK);
582 : : tmp |= E1000_VTIVAR_VALID;
583 : 0 : E1000_WRITE_REG(hw, E1000_VTIVAR_MISC, tmp);
584 : : }
585 : :
586 : : static void
587 : : eth_igbvf_configure_msix_intr(struct rte_eth_dev *dev)
588 : : {
589 : : struct e1000_hw *hw =
590 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
591 : :
592 : : /* Configure VF other cause ivar */
593 : : igbvf_set_ivar_map(hw, E1000_VTIVAR_MISC_MAILBOX);
594 : : }
595 : :
596 : : static inline int32_t
597 : 0 : igb_pf_reset_hw(struct e1000_hw *hw)
598 : : {
599 : : uint32_t ctrl_ext;
600 : : int32_t status;
601 : :
602 : 0 : status = e1000_reset_hw(hw);
603 : :
604 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
605 : : /* Set PF Reset Done bit so PF/VF Mail Ops can work */
606 : 0 : ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
607 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
608 : 0 : E1000_WRITE_FLUSH(hw);
609 : :
610 : 0 : return status;
611 : : }
612 : :
613 : : static void
614 : : igb_identify_hardware(struct rte_eth_dev *dev, struct rte_pci_device *pci_dev)
615 : : {
616 : 0 : struct e1000_hw *hw =
617 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
618 : :
619 : :
620 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
621 : 0 : hw->device_id = pci_dev->id.device_id;
622 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
623 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
624 : :
625 : 0 : e1000_set_mac_type(hw);
626 : :
627 : : /* need to check if it is a vf device below */
628 : : }
629 : :
630 : : static int
631 : 0 : igb_reset_swfw_lock(struct e1000_hw *hw)
632 : : {
633 : : int ret_val;
634 : :
635 : : /*
636 : : * Do mac ops initialization manually here, since we will need
637 : : * some function pointers set by this call.
638 : : */
639 : 0 : ret_val = e1000_init_mac_params(hw);
640 [ # # ]: 0 : if (ret_val)
641 : : return ret_val;
642 : :
643 : : /*
644 : : * SMBI lock should not fail in this early stage. If this is the case,
645 : : * it is due to an improper exit of the application.
646 : : * So force the release of the faulty lock.
647 : : */
648 [ # # ]: 0 : if (e1000_get_hw_semaphore_generic(hw) < 0) {
649 : 0 : PMD_DRV_LOG(DEBUG, "SMBI lock released");
650 : : }
651 : 0 : e1000_put_hw_semaphore_generic(hw);
652 : :
653 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync != NULL) {
654 : : uint16_t mask;
655 : :
656 : : /*
657 : : * Phy lock should not fail in this early stage. If this is the case,
658 : : * it is due to an improper exit of the application.
659 : : * So force the release of the faulty lock.
660 : : */
661 : 0 : mask = E1000_SWFW_PHY0_SM << hw->bus.func;
662 [ # # ]: 0 : if (hw->bus.func > E1000_FUNC_1)
663 : 0 : mask <<= 2;
664 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
665 : 0 : PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
666 : : hw->bus.func);
667 : : }
668 : 0 : hw->mac.ops.release_swfw_sync(hw, mask);
669 : :
670 : : /*
671 : : * This one is more tricky since it is common to all ports; but
672 : : * swfw_sync retries last long enough (1s) to be almost sure that if
673 : : * lock can not be taken it is due to an improper lock of the
674 : : * semaphore.
675 : : */
676 : : mask = E1000_SWFW_EEP_SM;
677 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
678 : 0 : PMD_DRV_LOG(DEBUG, "SWFW common locks released");
679 : : }
680 : 0 : hw->mac.ops.release_swfw_sync(hw, mask);
681 : : }
682 : :
683 : : return E1000_SUCCESS;
684 : : }
685 : :
686 : : /* Remove all ntuple filters of the device */
687 : 0 : static int igb_ntuple_filter_uninit(struct rte_eth_dev *eth_dev)
688 : : {
689 : : struct e1000_filter_info *filter_info =
690 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
691 : : struct e1000_5tuple_filter *p_5tuple;
692 : : struct e1000_2tuple_filter *p_2tuple;
693 : :
694 [ # # ]: 0 : while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list))) {
695 [ # # ]: 0 : TAILQ_REMOVE(&filter_info->fivetuple_list,
696 : : p_5tuple, entries);
697 : 0 : rte_free(p_5tuple);
698 : : }
699 : 0 : filter_info->fivetuple_mask = 0;
700 [ # # ]: 0 : while ((p_2tuple = TAILQ_FIRST(&filter_info->twotuple_list))) {
701 [ # # ]: 0 : TAILQ_REMOVE(&filter_info->twotuple_list,
702 : : p_2tuple, entries);
703 : 0 : rte_free(p_2tuple);
704 : : }
705 : 0 : filter_info->twotuple_mask = 0;
706 : :
707 : 0 : return 0;
708 : : }
709 : :
710 : : /* Remove all flex filters of the device */
711 : 0 : static int igb_flex_filter_uninit(struct rte_eth_dev *eth_dev)
712 : : {
713 : : struct e1000_filter_info *filter_info =
714 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
715 : : struct e1000_flex_filter *p_flex;
716 : :
717 [ # # ]: 0 : while ((p_flex = TAILQ_FIRST(&filter_info->flex_list))) {
718 [ # # ]: 0 : TAILQ_REMOVE(&filter_info->flex_list, p_flex, entries);
719 : 0 : rte_free(p_flex);
720 : : }
721 : 0 : filter_info->flex_mask = 0;
722 : :
723 : 0 : return 0;
724 : : }
725 : :
726 : : static const struct {
727 : : eth_tx_burst_t pkt_burst;
728 : : const char *info;
729 : : } igb_tx_burst_info[] = {
730 : : { eth_igb_xmit_pkts, "Scalar igb"},
731 : : { eth_em_xmit_pkts, "Scalar em"},
732 : : };
733 : :
734 : : int
735 : 0 : igb_tx_burst_mode_get(struct rte_eth_dev *dev,
736 : : __rte_unused uint16_t queue_id,
737 : : struct rte_eth_burst_mode *mode)
738 : : {
739 : 0 : eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
740 : : size_t i;
741 : :
742 [ # # ]: 0 : for (i = 0; i < RTE_DIM(igb_tx_burst_info); i++) {
743 [ # # ]: 0 : if (pkt_burst == igb_tx_burst_info[i].pkt_burst) {
744 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
745 : 0 : igb_tx_burst_info[i].info);
746 : 0 : return 0;
747 : : }
748 : : }
749 : :
750 : : return -EINVAL;
751 : : }
752 : :
753 : : static const struct {
754 : : eth_rx_burst_t pkt_burst;
755 : : const char *info;
756 : : } igb_rx_burst_info[] = {
757 : : { eth_igb_recv_pkts, "Scalar igb"},
758 : : { eth_igb_recv_scattered_pkts, "Scalar igb scattered"},
759 : : { eth_em_recv_pkts, "Scalar em"},
760 : : { eth_em_recv_scattered_pkts, "Scalar em scattered"},
761 : : };
762 : :
763 : : int
764 : 0 : igb_rx_burst_mode_get(struct rte_eth_dev *dev,
765 : : __rte_unused uint16_t queue_id,
766 : : struct rte_eth_burst_mode *mode)
767 : : {
768 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
769 : : size_t i;
770 : :
771 [ # # ]: 0 : for (i = 0; i < RTE_DIM(igb_rx_burst_info); i++) {
772 [ # # ]: 0 : if (pkt_burst == igb_rx_burst_info[i].pkt_burst) {
773 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
774 : 0 : igb_rx_burst_info[i].info);
775 : 0 : return 0;
776 : : }
777 : : }
778 : :
779 : : return -EINVAL;
780 : : }
781 : :
782 : : static int
783 : 0 : eth_igb_dev_init(struct rte_eth_dev *eth_dev)
784 : : {
785 : : int error = 0;
786 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
787 : 0 : struct e1000_hw *hw =
788 : 0 : E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
789 : 0 : struct e1000_vfta * shadow_vfta =
790 : : E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
791 : 0 : struct e1000_filter_info *filter_info =
792 : : E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
793 : : struct e1000_adapter *adapter =
794 : : E1000_DEV_PRIVATE(eth_dev->data->dev_private);
795 : :
796 : : uint32_t ctrl_ext;
797 : :
798 : 0 : eth_dev->dev_ops = ð_igb_ops;
799 : 0 : eth_dev->rx_queue_count = eth_igb_rx_queue_count;
800 : 0 : eth_dev->rx_descriptor_status = eth_igb_rx_descriptor_status;
801 : 0 : eth_dev->tx_descriptor_status = eth_igb_tx_descriptor_status;
802 : 0 : eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
803 : 0 : eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
804 : 0 : eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
805 : :
806 : : /* for secondary processes, we don't initialise any further as primary
807 : : * has already done this work. Only check we don't need a different
808 : : * RX function */
809 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY){
810 [ # # ]: 0 : if (eth_dev->data->scattered_rx)
811 : 0 : eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
812 : 0 : return 0;
813 : : }
814 : :
815 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
816 : :
817 : 0 : hw->hw_addr= (void *)pci_dev->mem_resource[0].addr;
818 : :
819 : : igb_identify_hardware(eth_dev, pci_dev);
820 [ # # ]: 0 : if (e1000_setup_init_funcs(hw, FALSE) != E1000_SUCCESS) {
821 : : error = -EIO;
822 : 0 : goto err_late;
823 : : }
824 : :
825 : 0 : e1000_get_bus_info(hw);
826 : :
827 : : /* Reset any pending lock */
828 [ # # ]: 0 : if (igb_reset_swfw_lock(hw) != E1000_SUCCESS) {
829 : : error = -EIO;
830 : 0 : goto err_late;
831 : : }
832 : :
833 : : /* Finish initialization */
834 [ # # ]: 0 : if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS) {
835 : : error = -EIO;
836 : 0 : goto err_late;
837 : : }
838 : :
839 : 0 : hw->mac.autoneg = 1;
840 : 0 : hw->phy.autoneg_wait_to_complete = 0;
841 : 0 : hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
842 : :
843 : : /* Copper options */
844 [ # # ]: 0 : if (hw->phy.media_type == e1000_media_type_copper) {
845 : 0 : hw->phy.mdix = 0; /* AUTO_ALL_MODES */
846 : 0 : hw->phy.disable_polarity_correction = 0;
847 : 0 : hw->phy.ms_type = e1000_ms_hw_default;
848 : : }
849 : :
850 : : /*
851 : : * Start from a known state, this is important in reading the nvm
852 : : * and mac from that.
853 : : */
854 : 0 : igb_pf_reset_hw(hw);
855 : :
856 : : /* Make sure we have a good EEPROM before we read from it */
857 [ # # ]: 0 : if (e1000_validate_nvm_checksum(hw) < 0) {
858 : : /*
859 : : * Some PCI-E parts fail the first check due to
860 : : * the link being in sleep state, call it again,
861 : : * if it fails a second time its a real issue.
862 : : */
863 [ # # ]: 0 : if (e1000_validate_nvm_checksum(hw) < 0) {
864 : 0 : PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
865 : : error = -EIO;
866 : 0 : goto err_late;
867 : : }
868 : : }
869 : :
870 : : /* Read the permanent MAC address out of the EEPROM */
871 [ # # ]: 0 : if (e1000_read_mac_addr(hw) != 0) {
872 : 0 : PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
873 : : error = -EIO;
874 : 0 : goto err_late;
875 : : }
876 : :
877 : : /* Allocate memory for storing MAC addresses */
878 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("e1000",
879 : 0 : RTE_ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
880 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
881 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
882 : : "store MAC addresses",
883 : : RTE_ETHER_ADDR_LEN * hw->mac.rar_entry_count);
884 : : error = -ENOMEM;
885 : 0 : goto err_late;
886 : : }
887 : :
888 : : /* Copy the permanent MAC address */
889 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
890 : : ð_dev->data->mac_addrs[0]);
891 : :
892 : : /* initialize the vfta */
893 : : memset(shadow_vfta, 0, sizeof(*shadow_vfta));
894 : :
895 : : /* Now initialize the hardware */
896 [ # # ]: 0 : if (igb_hardware_init(hw) != 0) {
897 : 0 : PMD_INIT_LOG(ERR, "Hardware initialization failed");
898 : 0 : rte_free(eth_dev->data->mac_addrs);
899 : 0 : eth_dev->data->mac_addrs = NULL;
900 : : error = -ENODEV;
901 : 0 : goto err_late;
902 : : }
903 : 0 : hw->mac.get_link_status = 1;
904 : 0 : adapter->stopped = 0;
905 : :
906 : : /* Indicate SOL/IDER usage */
907 [ # # ]: 0 : if (e1000_check_reset_block(hw) < 0) {
908 : 0 : PMD_INIT_LOG(ERR, "PHY reset is blocked due to"
909 : : "SOL/IDER session");
910 : : }
911 : :
912 : : /* initialize PF if max_vfs not zero */
913 : 0 : igb_pf_host_init(eth_dev);
914 : :
915 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
916 : : /* Set PF Reset Done bit so PF/VF Mail Ops can work */
917 : 0 : ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
918 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
919 : 0 : E1000_WRITE_FLUSH(hw);
920 : :
921 : 0 : PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
922 : : eth_dev->data->port_id, pci_dev->id.vendor_id,
923 : : pci_dev->id.device_id);
924 : :
925 : 0 : rte_intr_callback_register(pci_dev->intr_handle,
926 : : eth_igb_interrupt_handler,
927 : : (void *)eth_dev);
928 : :
929 : : /* enable uio/vfio intr/eventfd mapping */
930 : 0 : rte_intr_enable(pci_dev->intr_handle);
931 : :
932 : : /* enable support intr */
933 : 0 : igb_intr_enable(eth_dev);
934 : :
935 : 0 : eth_igb_dev_set_link_down(eth_dev);
936 : :
937 : : /* initialize filter info */
938 : : memset(filter_info, 0,
939 : : sizeof(struct e1000_filter_info));
940 : :
941 : 0 : TAILQ_INIT(&filter_info->flex_list);
942 : 0 : TAILQ_INIT(&filter_info->twotuple_list);
943 : 0 : TAILQ_INIT(&filter_info->fivetuple_list);
944 : :
945 : 0 : TAILQ_INIT(&igb_filter_ntuple_list);
946 : 0 : TAILQ_INIT(&igb_filter_ethertype_list);
947 : 0 : TAILQ_INIT(&igb_filter_syn_list);
948 : 0 : TAILQ_INIT(&igb_filter_flex_list);
949 : 0 : TAILQ_INIT(&igb_filter_rss_list);
950 : 0 : TAILQ_INIT(&igb_flow_list);
951 : :
952 : 0 : return 0;
953 : :
954 : 0 : err_late:
955 : : igb_hw_control_release(hw);
956 : :
957 : 0 : return error;
958 : : }
959 : :
960 : : static int
961 : 0 : eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
962 : : {
963 : 0 : PMD_INIT_FUNC_TRACE();
964 : :
965 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
966 : : return 0;
967 : :
968 : 0 : eth_igb_close(eth_dev);
969 : :
970 : 0 : return 0;
971 : : }
972 : :
973 : : /*
974 : : * Virtual Function device init
975 : : */
976 : : static int
977 : 0 : eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
978 : : {
979 : : struct rte_pci_device *pci_dev;
980 : : struct rte_intr_handle *intr_handle;
981 : 0 : struct e1000_adapter *adapter =
982 : 0 : E1000_DEV_PRIVATE(eth_dev->data->dev_private);
983 : 0 : struct e1000_hw *hw =
984 : : E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
985 : : int diag;
986 : : struct rte_ether_addr *perm_addr =
987 : : (struct rte_ether_addr *)hw->mac.perm_addr;
988 : :
989 : 0 : PMD_INIT_FUNC_TRACE();
990 : :
991 : 0 : eth_dev->dev_ops = &igbvf_eth_dev_ops;
992 : 0 : eth_dev->rx_descriptor_status = eth_igb_rx_descriptor_status;
993 : 0 : eth_dev->tx_descriptor_status = eth_igb_tx_descriptor_status;
994 : 0 : eth_dev->rx_pkt_burst = ð_igb_recv_pkts;
995 : 0 : eth_dev->tx_pkt_burst = ð_igb_xmit_pkts;
996 : 0 : eth_dev->tx_pkt_prepare = ð_igb_prep_pkts;
997 : :
998 : : /* for secondary processes, we don't initialise any further as primary
999 : : * has already done this work. Only check we don't need a different
1000 : : * RX function */
1001 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1002 [ # # ]: 0 : if (eth_dev->data->scattered_rx)
1003 : 0 : eth_dev->rx_pkt_burst = ð_igb_recv_scattered_pkts;
1004 : 0 : return 0;
1005 : : }
1006 : :
1007 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1008 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
1009 : :
1010 : 0 : hw->device_id = pci_dev->id.device_id;
1011 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
1012 : 0 : hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1013 : 0 : adapter->stopped = 0;
1014 : :
1015 : : /* Initialize the shared code (base driver) */
1016 : 0 : diag = e1000_setup_init_funcs(hw, TRUE);
1017 [ # # ]: 0 : if (diag != 0) {
1018 : 0 : PMD_INIT_LOG(ERR, "Shared code init failed for igbvf: %d",
1019 : : diag);
1020 : 0 : return -EIO;
1021 : : }
1022 : :
1023 : : /* init_mailbox_params */
1024 : 0 : hw->mbx.ops.init_params(hw);
1025 : :
1026 : : /* Disable the interrupts for VF */
1027 : 0 : igbvf_intr_disable(hw);
1028 : :
1029 : 0 : diag = hw->mac.ops.reset_hw(hw);
1030 : :
1031 : : /* Allocate memory for storing MAC addresses */
1032 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("igbvf", RTE_ETHER_ADDR_LEN *
1033 : 0 : hw->mac.rar_entry_count, 0);
1034 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
1035 : 0 : PMD_INIT_LOG(ERR,
1036 : : "Failed to allocate %d bytes needed to store MAC "
1037 : : "addresses",
1038 : : RTE_ETHER_ADDR_LEN * hw->mac.rar_entry_count);
1039 : 0 : return -ENOMEM;
1040 : : }
1041 : :
1042 : : /* Generate a random MAC address, if none was assigned by PF. */
1043 [ # # ]: 0 : if (rte_is_zero_ether_addr(perm_addr)) {
1044 : 0 : rte_eth_random_addr(perm_addr->addr_bytes);
1045 : 0 : PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
1046 : 0 : PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
1047 : : RTE_ETHER_ADDR_PRT_FMT,
1048 : : RTE_ETHER_ADDR_BYTES(perm_addr));
1049 : : }
1050 : :
1051 : 0 : diag = e1000_rar_set(hw, perm_addr->addr_bytes, 0);
1052 [ # # ]: 0 : if (diag) {
1053 : 0 : rte_free(eth_dev->data->mac_addrs);
1054 : 0 : eth_dev->data->mac_addrs = NULL;
1055 : 0 : return diag;
1056 : : }
1057 : : /* Copy the permanent MAC address */
1058 : 0 : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
1059 : 0 : ð_dev->data->mac_addrs[0]);
1060 : :
1061 : 0 : PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x "
1062 : : "mac.type=%s",
1063 : : eth_dev->data->port_id, pci_dev->id.vendor_id,
1064 : : pci_dev->id.device_id, "igb_mac_82576_vf");
1065 : :
1066 : 0 : intr_handle = pci_dev->intr_handle;
1067 : 0 : rte_intr_callback_register(intr_handle,
1068 : : eth_igbvf_interrupt_handler, eth_dev);
1069 : :
1070 : 0 : return 0;
1071 : : }
1072 : :
1073 : : static int
1074 : 0 : eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
1075 : : {
1076 : 0 : PMD_INIT_FUNC_TRACE();
1077 : :
1078 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1079 : : return 0;
1080 : :
1081 : 0 : igbvf_dev_close(eth_dev);
1082 : :
1083 : 0 : return 0;
1084 : : }
1085 : :
1086 : 0 : static int eth_igb_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1087 : : struct rte_pci_device *pci_dev)
1088 : : {
1089 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
1090 : : sizeof(struct e1000_adapter), eth_igb_dev_init);
1091 : : }
1092 : :
1093 : 0 : static int eth_igb_pci_remove(struct rte_pci_device *pci_dev)
1094 : : {
1095 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_igb_dev_uninit);
1096 : : }
1097 : :
1098 : : static struct rte_pci_driver rte_igb_pmd = {
1099 : : .id_table = pci_id_igb_map,
1100 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1101 : : .probe = eth_igb_pci_probe,
1102 : : .remove = eth_igb_pci_remove,
1103 : : };
1104 : :
1105 : :
1106 : 0 : static int eth_igbvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1107 : : struct rte_pci_device *pci_dev)
1108 : : {
1109 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
1110 : : sizeof(struct e1000_adapter), eth_igbvf_dev_init);
1111 : : }
1112 : :
1113 : 0 : static int eth_igbvf_pci_remove(struct rte_pci_device *pci_dev)
1114 : : {
1115 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_igbvf_dev_uninit);
1116 : : }
1117 : :
1118 : : /*
1119 : : * virtual function driver struct
1120 : : */
1121 : : static struct rte_pci_driver rte_igbvf_pmd = {
1122 : : .id_table = pci_id_igbvf_map,
1123 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1124 : : .probe = eth_igbvf_pci_probe,
1125 : : .remove = eth_igbvf_pci_remove,
1126 : : };
1127 : :
1128 : : static void
1129 : : igb_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
1130 : : {
1131 : : struct e1000_hw *hw =
1132 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1133 : : /* RCTL: enable VLAN filter since VMDq always use VLAN filter */
1134 : 0 : uint32_t rctl = E1000_READ_REG(hw, E1000_RCTL);
1135 : 0 : rctl |= E1000_RCTL_VFE;
1136 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1137 : 0 : }
1138 : :
1139 : : static int
1140 : 0 : igb_check_mq_mode(struct rte_eth_dev *dev)
1141 : : {
1142 : 0 : enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1143 : 0 : enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
1144 : 0 : uint16_t nb_rx_q = dev->data->nb_rx_queues;
1145 : 0 : uint16_t nb_tx_q = dev->data->nb_tx_queues;
1146 : :
1147 [ # # ]: 0 : if ((rx_mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) ||
1148 [ # # ]: 0 : tx_mq_mode == RTE_ETH_MQ_TX_DCB ||
1149 : : tx_mq_mode == RTE_ETH_MQ_TX_VMDQ_DCB) {
1150 : 0 : PMD_INIT_LOG(ERR, "DCB mode is not supported.");
1151 : 0 : return -EINVAL;
1152 : : }
1153 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
1154 : : /* Check multi-queue mode.
1155 : : * To no break software we accept RTE_ETH_MQ_RX_NONE as this might
1156 : : * be used to turn off VLAN filter.
1157 : : */
1158 : :
1159 : 0 : if (rx_mq_mode == RTE_ETH_MQ_RX_NONE ||
1160 [ # # ]: 0 : rx_mq_mode == RTE_ETH_MQ_RX_VMDQ_ONLY) {
1161 : 0 : dev->data->dev_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_VMDQ_ONLY;
1162 : 0 : RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
1163 : : } else {
1164 : : /* Only support one queue on VFs.
1165 : : * RSS together with SRIOV is not supported.
1166 : : */
1167 : 0 : PMD_INIT_LOG(ERR, "SRIOV is active,"
1168 : : " wrong mq_mode rx %d.",
1169 : : rx_mq_mode);
1170 : 0 : return -EINVAL;
1171 : : }
1172 : : /* TX mode is not used here, so mode might be ignored.*/
1173 [ # # ]: 0 : if (tx_mq_mode != RTE_ETH_MQ_TX_VMDQ_ONLY) {
1174 : : /* SRIOV only works in VMDq enable mode */
1175 : 0 : PMD_INIT_LOG(WARNING, "SRIOV is active,"
1176 : : " TX mode %d is not supported. "
1177 : : " Driver will behave as %d mode.",
1178 : : tx_mq_mode, RTE_ETH_MQ_TX_VMDQ_ONLY);
1179 : : }
1180 : :
1181 : : /* check valid queue number */
1182 [ # # ]: 0 : if ((nb_rx_q > 1) || (nb_tx_q > 1)) {
1183 : 0 : PMD_INIT_LOG(ERR, "SRIOV is active,"
1184 : : " only support one queue on VFs.");
1185 : 0 : return -EINVAL;
1186 : : }
1187 : : } else {
1188 : : /* To no break software that set invalid mode, only display
1189 : : * warning if invalid mode is used.
1190 : : */
1191 : 0 : if (rx_mq_mode != RTE_ETH_MQ_RX_NONE &&
1192 [ # # # # ]: 0 : rx_mq_mode != RTE_ETH_MQ_RX_VMDQ_ONLY &&
1193 : : rx_mq_mode != RTE_ETH_MQ_RX_RSS) {
1194 : : /* RSS together with VMDq not supported*/
1195 : 0 : PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
1196 : : rx_mq_mode);
1197 : 0 : return -EINVAL;
1198 : : }
1199 : :
1200 : 0 : if (tx_mq_mode != RTE_ETH_MQ_TX_NONE &&
1201 [ # # ]: 0 : tx_mq_mode != RTE_ETH_MQ_TX_VMDQ_ONLY) {
1202 : 0 : PMD_INIT_LOG(WARNING, "TX mode %d is not supported."
1203 : : " Due to txmode is meaningless in this"
1204 : : " driver, just ignore.",
1205 : : tx_mq_mode);
1206 : : }
1207 : : }
1208 : : return 0;
1209 : : }
1210 : :
1211 : : static int
1212 : 0 : eth_igb_configure(struct rte_eth_dev *dev)
1213 : : {
1214 : : struct e1000_interrupt *intr =
1215 : 0 : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
1216 : : int ret;
1217 : :
1218 : 0 : PMD_INIT_FUNC_TRACE();
1219 : :
1220 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
1221 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
1222 : :
1223 : : /* multiple queue mode checking */
1224 : 0 : ret = igb_check_mq_mode(dev);
1225 [ # # ]: 0 : if (ret != 0) {
1226 : 0 : PMD_DRV_LOG(ERR, "igb_check_mq_mode fails with %d.",
1227 : : ret);
1228 : 0 : return ret;
1229 : : }
1230 : :
1231 : 0 : intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
1232 : 0 : PMD_INIT_FUNC_TRACE();
1233 : :
1234 : 0 : return 0;
1235 : : }
1236 : :
1237 : : static void
1238 : 0 : eth_igb_rxtx_control(struct rte_eth_dev *dev,
1239 : : bool enable)
1240 : : {
1241 : : struct e1000_hw *hw =
1242 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1243 : : uint32_t tctl, rctl;
1244 : :
1245 : 0 : tctl = E1000_READ_REG(hw, E1000_TCTL);
1246 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
1247 : :
1248 [ # # ]: 0 : if (enable) {
1249 : : /* enable Tx/Rx */
1250 : 0 : tctl |= E1000_TCTL_EN;
1251 : 0 : rctl |= E1000_RCTL_EN;
1252 : : } else {
1253 : : /* disable Tx/Rx */
1254 : 0 : tctl &= ~E1000_TCTL_EN;
1255 : 0 : rctl &= ~E1000_RCTL_EN;
1256 : : }
1257 : 0 : E1000_WRITE_REG(hw, E1000_TCTL, tctl);
1258 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
1259 : 0 : E1000_WRITE_FLUSH(hw);
1260 : 0 : }
1261 : :
1262 : :
1263 : 0 : static uint32_t igb_tx_offset(struct rte_eth_dev *dev)
1264 : : {
1265 : 0 : struct e1000_hw *hw =
1266 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1267 : :
1268 : : uint16_t duplex, speed;
1269 : 0 : hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
1270 : :
1271 : 0 : uint32_t launch_os0 = E1000_READ_REG(hw, E1000_I210_LAUNCH_OS0);
1272 [ # # ]: 0 : if (hw->mac.type != e1000_i210) {
1273 : : /* Set launch offset to base, no compensation */
1274 : 0 : launch_os0 |= IGB_I210_TX_OFFSET_BASE;
1275 : : } else {
1276 : : /* Set launch offset depend on link speeds */
1277 [ # # # # ]: 0 : switch (speed) {
1278 : 0 : case SPEED_10:
1279 : 0 : launch_os0 |= IGB_I210_TX_OFFSET_SPEED_10;
1280 : 0 : break;
1281 : 0 : case SPEED_100:
1282 : 0 : launch_os0 |= IGB_I210_TX_OFFSET_SPEED_100;
1283 : 0 : break;
1284 : 0 : case SPEED_1000:
1285 : 0 : launch_os0 |= IGB_I210_TX_OFFSET_SPEED_1000;
1286 : 0 : break;
1287 : 0 : default:
1288 : 0 : launch_os0 |= IGB_I210_TX_OFFSET_BASE;
1289 : 0 : break;
1290 : : }
1291 : : }
1292 : :
1293 : 0 : return launch_os0;
1294 : : }
1295 : :
1296 : : static int
1297 : 0 : eth_igb_start(struct rte_eth_dev *dev)
1298 : : {
1299 : 0 : struct e1000_hw *hw =
1300 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1301 : : struct e1000_adapter *adapter =
1302 : : E1000_DEV_PRIVATE(dev->data->dev_private);
1303 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1304 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1305 : : int ret, mask;
1306 : : uint32_t tqavctrl;
1307 : : uint32_t intr_vector = 0;
1308 : : uint32_t ctrl_ext;
1309 : : uint32_t *speeds;
1310 : : int num_speeds;
1311 : : bool autoneg;
1312 : :
1313 : 0 : PMD_INIT_FUNC_TRACE();
1314 : :
1315 : : /*
1316 : : * This function calls into the base driver, which in turn will use
1317 : : * function pointers, which are not guaranteed to be valid in secondary
1318 : : * processes, so avoid using this function in secondary processes.
1319 : : */
1320 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1321 : : return -E_RTE_SECONDARY;
1322 : :
1323 : : /* disable uio/vfio intr/eventfd mapping */
1324 : 0 : rte_intr_disable(intr_handle);
1325 : :
1326 : : /* Power up the phy. Needed to make the link go Up */
1327 : 0 : eth_igb_dev_set_link_up(dev);
1328 : :
1329 : : /*
1330 : : * Packet Buffer Allocation (PBA)
1331 : : * Writing PBA sets the receive portion of the buffer
1332 : : * the remainder is used for the transmit buffer.
1333 : : */
1334 [ # # ]: 0 : if (hw->mac.type == e1000_82575) {
1335 : : uint32_t pba;
1336 : :
1337 : : pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
1338 : 0 : E1000_WRITE_REG(hw, E1000_PBA, pba);
1339 : : }
1340 : :
1341 : : /* Put the address into the Receive Address Array */
1342 : 0 : e1000_rar_set(hw, hw->mac.addr, 0);
1343 : :
1344 : : /* Initialize the hardware */
1345 [ # # ]: 0 : if (igb_hardware_init(hw)) {
1346 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
1347 : 0 : return -EIO;
1348 : : }
1349 : 0 : adapter->stopped = 0;
1350 : :
1351 : 0 : E1000_WRITE_REG(hw, E1000_VET,
1352 : : RTE_ETHER_TYPE_VLAN << 16 | RTE_ETHER_TYPE_VLAN);
1353 : :
1354 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1355 : : /* Set PF Reset Done bit so PF/VF Mail Ops can work */
1356 : 0 : ctrl_ext |= E1000_CTRL_EXT_PFRSTD;
1357 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1358 : 0 : E1000_WRITE_FLUSH(hw);
1359 : :
1360 : : /* configure PF module if SRIOV enabled */
1361 : 0 : igb_pf_host_configure(dev);
1362 : :
1363 : : /* check and configure queue intr-vector mapping */
1364 [ # # ]: 0 : if ((rte_intr_cap_multiple(intr_handle) ||
1365 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active) &&
1366 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq != 0) {
1367 : 0 : intr_vector = dev->data->nb_rx_queues;
1368 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector))
1369 : : return -1;
1370 : : }
1371 : :
1372 : : /* Allocate the vector list */
1373 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
1374 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
1375 : 0 : dev->data->nb_rx_queues)) {
1376 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1377 : : " intr_vec", dev->data->nb_rx_queues);
1378 : 0 : return -ENOMEM;
1379 : : }
1380 : : }
1381 : :
1382 : : /* configure MSI-X for Rx interrupt */
1383 : 0 : eth_igb_configure_msix_intr(dev);
1384 : :
1385 : : /* Configure for OS presence */
1386 : 0 : igb_init_manageability(hw);
1387 : :
1388 : 0 : eth_igb_tx_init(dev);
1389 : :
1390 [ # # ]: 0 : if (igb_tx_timestamp_dynflag > 0) {
1391 : 0 : tqavctrl = E1000_READ_REG(hw, E1000_I210_TQAVCTRL);
1392 : : tqavctrl |= E1000_TQAVCTRL_MODE; /* Enable Qav mode */
1393 : : tqavctrl |= E1000_TQAVCTRL_FETCH_ARB; /* ARB fetch, no Round Robin*/
1394 : 0 : tqavctrl |= E1000_TQAVCTRL_LAUNCH_TIMER_ENABLE; /* Enable Tx launch time*/
1395 : 0 : E1000_WRITE_REG(hw, E1000_I210_TQAVCTRL, tqavctrl);
1396 : 0 : E1000_WRITE_REG(hw, E1000_I210_LAUNCH_OS0, igb_tx_offset(dev));
1397 : : }
1398 : :
1399 : : /* This can fail when allocating mbufs for descriptor rings */
1400 : 0 : ret = eth_igb_rx_init(dev);
1401 [ # # ]: 0 : if (ret) {
1402 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1403 : 0 : igb_dev_clear_queues(dev);
1404 : 0 : return ret;
1405 : : }
1406 : :
1407 : 0 : e1000_clear_hw_cntrs_base_generic(hw);
1408 : :
1409 : : /*
1410 : : * VLAN Offload Settings
1411 : : */
1412 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
1413 : : RTE_ETH_VLAN_EXTEND_MASK;
1414 : 0 : ret = eth_igb_vlan_offload_set(dev, mask);
1415 [ # # ]: 0 : if (ret) {
1416 : 0 : PMD_INIT_LOG(ERR, "Unable to set vlan offload");
1417 : 0 : igb_dev_clear_queues(dev);
1418 : 0 : return ret;
1419 : : }
1420 : :
1421 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_VMDQ_ONLY) {
1422 : : /* Enable VLAN filter since VMDq always use VLAN filter */
1423 : : igb_vmdq_vlan_hw_filter_enable(dev);
1424 : : }
1425 : :
1426 : 0 : if ((hw->mac.type == e1000_82576) || (hw->mac.type == e1000_82580) ||
1427 [ # # # # ]: 0 : (hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i210) ||
1428 : : (hw->mac.type == e1000_i211)) {
1429 : : /* Configure EITR with the maximum possible value (0xFFFF) */
1430 : 0 : E1000_WRITE_REG(hw, E1000_EITR(0), 0xFFFF);
1431 : : }
1432 : :
1433 : : /* Setup link speed and duplex */
1434 : 0 : speeds = &dev->data->dev_conf.link_speeds;
1435 [ # # ]: 0 : if (*speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
1436 : 0 : hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
1437 : 0 : hw->mac.autoneg = 1;
1438 : : } else {
1439 : : num_speeds = 0;
1440 : 0 : autoneg = (*speeds & RTE_ETH_LINK_SPEED_FIXED) == 0;
1441 : :
1442 : : /* Reset */
1443 : 0 : hw->phy.autoneg_advertised = 0;
1444 : :
1445 [ # # ]: 0 : if (*speeds & ~(RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
1446 : : RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
1447 : : RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_FIXED)) {
1448 : : num_speeds = -1;
1449 : 0 : goto error_invalid_config;
1450 : : }
1451 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_10M_HD) {
1452 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
1453 : : num_speeds++;
1454 : : }
1455 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_10M) {
1456 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
1457 : 0 : num_speeds++;
1458 : : }
1459 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_100M_HD) {
1460 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
1461 : 0 : num_speeds++;
1462 : : }
1463 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_100M) {
1464 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
1465 : 0 : num_speeds++;
1466 : : }
1467 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_1G) {
1468 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
1469 : 0 : num_speeds++;
1470 : : }
1471 [ # # # # ]: 0 : if (num_speeds == 0 || (!autoneg && (num_speeds > 1)))
1472 : 0 : goto error_invalid_config;
1473 : :
1474 : : /* Set/reset the mac.autoneg based on the link speed,
1475 : : * fixed or not
1476 : : */
1477 [ # # ]: 0 : if (!autoneg) {
1478 : 0 : hw->mac.autoneg = 0;
1479 : 0 : hw->mac.forced_speed_duplex =
1480 : 0 : hw->phy.autoneg_advertised;
1481 : : } else {
1482 : 0 : hw->mac.autoneg = 1;
1483 : : }
1484 : : }
1485 : :
1486 : 0 : e1000_setup_link(hw);
1487 : :
1488 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
1489 : : /* check if lsc interrupt is enabled */
1490 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
1491 : : eth_igb_lsc_interrupt_setup(dev, TRUE);
1492 : : else
1493 : : eth_igb_lsc_interrupt_setup(dev, FALSE);
1494 : : } else {
1495 : 0 : rte_intr_callback_unregister(intr_handle,
1496 : : eth_igb_interrupt_handler,
1497 : : (void *)dev);
1498 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
1499 : 0 : PMD_INIT_LOG(INFO, "lsc won't enable because of"
1500 : : " no intr multiplex");
1501 : : }
1502 : :
1503 : : /* check if rxq interrupt is enabled */
1504 [ # # # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1505 : 0 : rte_intr_dp_is_en(intr_handle))
1506 : 0 : eth_igb_rxq_interrupt_setup(dev);
1507 : :
1508 : : /* enable uio/vfio intr/eventfd mapping */
1509 : 0 : rte_intr_enable(intr_handle);
1510 : :
1511 : : /* resume enabled intr since hw reset */
1512 : 0 : igb_intr_enable(dev);
1513 : :
1514 : : /* restore all types filter */
1515 : 0 : igb_filter_restore(dev);
1516 : :
1517 : 0 : eth_igb_rxtx_control(dev, true);
1518 : 0 : eth_igb_link_update(dev, 0);
1519 : 0 : PMD_INIT_LOG(DEBUG, "<<");
1520 : :
1521 : 0 : return 0;
1522 : :
1523 : 0 : error_invalid_config:
1524 : 0 : PMD_INIT_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
1525 : : dev->data->dev_conf.link_speeds, dev->data->port_id);
1526 : 0 : igb_dev_clear_queues(dev);
1527 : 0 : return -EINVAL;
1528 : : }
1529 : :
1530 : : /*********************************************************************
1531 : : *
1532 : : * This routine disables all traffic on the adapter by issuing a
1533 : : * global reset on the MAC.
1534 : : *
1535 : : **********************************************************************/
1536 : : static int
1537 : 0 : eth_igb_stop(struct rte_eth_dev *dev)
1538 : : {
1539 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1540 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1541 : : struct rte_eth_link link;
1542 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1543 : : struct e1000_adapter *adapter =
1544 : : E1000_DEV_PRIVATE(dev->data->dev_private);
1545 : :
1546 : : /*
1547 : : * This function calls into the base driver, which in turn will use
1548 : : * function pointers, which are not guaranteed to be valid in secondary
1549 : : * processes, so avoid using this function in secondary processes.
1550 : : */
1551 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1552 : : return -E_RTE_SECONDARY;
1553 : :
1554 [ # # ]: 0 : if (adapter->stopped)
1555 : : return 0;
1556 : :
1557 : 0 : eth_igb_rxtx_control(dev, false);
1558 : :
1559 : 0 : igb_intr_disable(dev);
1560 : :
1561 : : /* disable intr eventfd mapping */
1562 : 0 : rte_intr_disable(intr_handle);
1563 : :
1564 : 0 : igb_pf_reset_hw(hw);
1565 : 0 : E1000_WRITE_REG(hw, E1000_WUC, 0);
1566 : :
1567 : : /* Set bit for Go Link disconnect if PHY reset is not blocked */
1568 [ # # # # ]: 0 : if (hw->mac.type >= e1000_82580 &&
1569 : 0 : (e1000_check_reset_block(hw) != E1000_BLK_PHY_RESET)) {
1570 : : uint32_t phpm_reg;
1571 : :
1572 : 0 : phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1573 : 0 : phpm_reg |= E1000_82580_PM_GO_LINKD;
1574 : 0 : E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1575 : : }
1576 : :
1577 : : /* Power down the phy. Needed to make the link go Down */
1578 : 0 : eth_igb_dev_set_link_down(dev);
1579 : :
1580 : 0 : igb_dev_clear_queues(dev);
1581 : :
1582 : : /* clear the recorded link status */
1583 : : memset(&link, 0, sizeof(link));
1584 : 0 : rte_eth_linkstatus_set(dev, &link);
1585 : :
1586 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
1587 : : /* resume to the default handler */
1588 : 0 : rte_intr_callback_register(intr_handle,
1589 : : eth_igb_interrupt_handler,
1590 : : (void *)dev);
1591 : :
1592 : : /* Clean datapath event and queue/vec mapping */
1593 : 0 : rte_intr_efd_disable(intr_handle);
1594 : 0 : rte_intr_vec_list_free(intr_handle);
1595 : :
1596 : 0 : adapter->stopped = true;
1597 : 0 : dev->data->dev_started = 0;
1598 : :
1599 : 0 : return 0;
1600 : : }
1601 : :
1602 : : static int
1603 : 0 : eth_igb_dev_set_link_up(struct rte_eth_dev *dev)
1604 : : {
1605 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1606 : :
1607 : : /*
1608 : : * This function calls into the base driver, which in turn will use
1609 : : * function pointers, which are not guaranteed to be valid in secondary
1610 : : * processes, so avoid using this function in secondary processes.
1611 : : */
1612 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1613 : : return -E_RTE_SECONDARY;
1614 : :
1615 [ # # ]: 0 : if (hw->phy.media_type == e1000_media_type_copper)
1616 : 0 : e1000_power_up_phy(hw);
1617 : : else
1618 : 0 : e1000_power_up_fiber_serdes_link(hw);
1619 : :
1620 : : return 0;
1621 : : }
1622 : :
1623 : : static int
1624 : 0 : eth_igb_dev_set_link_down(struct rte_eth_dev *dev)
1625 : : {
1626 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1627 : :
1628 : : /*
1629 : : * This function calls into the base driver, which in turn will use
1630 : : * function pointers, which are not guaranteed to be valid in secondary
1631 : : * processes, so avoid using this function in secondary processes.
1632 : : */
1633 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1634 : : return -E_RTE_SECONDARY;
1635 : :
1636 [ # # ]: 0 : if (hw->phy.media_type == e1000_media_type_copper)
1637 : 0 : e1000_power_down_phy(hw);
1638 : : else
1639 : 0 : e1000_shutdown_fiber_serdes_link(hw);
1640 : :
1641 : : return 0;
1642 : : }
1643 : :
1644 : : static int
1645 : 0 : eth_igb_close(struct rte_eth_dev *dev)
1646 : : {
1647 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1648 : : struct rte_eth_link link;
1649 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1650 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1651 : : struct e1000_filter_info *filter_info =
1652 : : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
1653 : : int ret;
1654 : :
1655 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1656 : : return 0;
1657 : :
1658 : 0 : ret = eth_igb_stop(dev);
1659 : :
1660 : 0 : e1000_phy_hw_reset(hw);
1661 : 0 : igb_release_manageability(hw);
1662 : : igb_hw_control_release(hw);
1663 : :
1664 : : /* Clear bit for Go Link disconnect if PHY reset is not blocked */
1665 [ # # # # ]: 0 : if (hw->mac.type >= e1000_82580 &&
1666 : 0 : (e1000_check_reset_block(hw) != E1000_BLK_PHY_RESET)) {
1667 : : uint32_t phpm_reg;
1668 : :
1669 : 0 : phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
1670 : 0 : phpm_reg &= ~E1000_82580_PM_GO_LINKD;
1671 : 0 : E1000_WRITE_REG(hw, E1000_82580_PHY_POWER_MGMT, phpm_reg);
1672 : : }
1673 : :
1674 : 0 : igb_dev_free_queues(dev);
1675 : :
1676 : : /* Cleanup vector list */
1677 : 0 : rte_intr_vec_list_free(intr_handle);
1678 : :
1679 : : memset(&link, 0, sizeof(link));
1680 : 0 : rte_eth_linkstatus_set(dev, &link);
1681 : :
1682 : : /* Reset any pending lock */
1683 : 0 : igb_reset_swfw_lock(hw);
1684 : :
1685 : : /* uninitialize PF if max_vfs not zero */
1686 : 0 : igb_pf_host_uninit(dev);
1687 : :
1688 : 0 : rte_intr_callback_unregister(intr_handle,
1689 : : eth_igb_interrupt_handler, dev);
1690 : :
1691 : : /* clear the SYN filter info */
1692 : 0 : filter_info->syn_info = 0;
1693 : :
1694 : : /* clear the ethertype filters info */
1695 : 0 : filter_info->ethertype_mask = 0;
1696 : 0 : memset(filter_info->ethertype_filters, 0,
1697 : : E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
1698 : :
1699 : : /* clear the rss filter info */
1700 : 0 : memset(&filter_info->rss_info, 0,
1701 : : sizeof(struct igb_rte_flow_rss_conf));
1702 : :
1703 : : /* remove all ntuple filters of the device */
1704 : 0 : igb_ntuple_filter_uninit(dev);
1705 : :
1706 : : /* remove all flex filters of the device */
1707 : 0 : igb_flex_filter_uninit(dev);
1708 : :
1709 : : /* clear all the filters list */
1710 : 0 : igb_filterlist_flush(dev);
1711 : :
1712 : 0 : return ret;
1713 : : }
1714 : :
1715 : : /*
1716 : : * Reset PF device.
1717 : : */
1718 : : static int
1719 : 0 : eth_igb_reset(struct rte_eth_dev *dev)
1720 : : {
1721 : : int ret;
1722 : :
1723 : : /* When a DPDK PMD PF begin to reset PF port, it should notify all
1724 : : * its VF to make them align with it. The detailed notification
1725 : : * mechanism is PMD specific and is currently not implemented.
1726 : : * To avoid unexpected behavior in VF, currently reset of PF with
1727 : : * SR-IOV activation is not supported. It might be supported later.
1728 : : */
1729 [ # # ]: 0 : if (dev->data->sriov.active)
1730 : : return -ENOTSUP;
1731 : :
1732 : 0 : ret = eth_igb_dev_uninit(dev);
1733 [ # # ]: 0 : if (ret)
1734 : : return ret;
1735 : :
1736 : 0 : ret = eth_igb_dev_init(dev);
1737 : :
1738 : 0 : return ret;
1739 : : }
1740 : :
1741 : :
1742 : : static int
1743 : 0 : igb_get_rx_buffer_size(struct e1000_hw *hw)
1744 : : {
1745 : : uint32_t rx_buf_size;
1746 [ # # ]: 0 : if (hw->mac.type == e1000_82576) {
1747 : 0 : rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xffff) << 10;
1748 [ # # ]: 0 : } else if (hw->mac.type == e1000_82580 || hw->mac.type == e1000_i350) {
1749 : : /* PBS needs to be translated according to a lookup table */
1750 : 0 : rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0xf);
1751 : 0 : rx_buf_size = (uint32_t) e1000_rxpbs_adjust_82580(rx_buf_size);
1752 : 0 : rx_buf_size = (rx_buf_size << 10);
1753 [ # # ]: 0 : } else if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) {
1754 : 0 : rx_buf_size = (E1000_READ_REG(hw, E1000_RXPBS) & 0x3f) << 10;
1755 : : } else {
1756 : 0 : rx_buf_size = (E1000_READ_REG(hw, E1000_PBA) & 0xffff) << 10;
1757 : : }
1758 : :
1759 : 0 : return rx_buf_size;
1760 : : }
1761 : :
1762 : : /*********************************************************************
1763 : : *
1764 : : * Initialize the hardware
1765 : : *
1766 : : **********************************************************************/
1767 : : static int
1768 : 0 : igb_hardware_init(struct e1000_hw *hw)
1769 : : {
1770 : : uint32_t rx_buf_size;
1771 : : int diag;
1772 : :
1773 : : /* Let the firmware know the OS is in control */
1774 : : igb_hw_control_acquire(hw);
1775 : :
1776 : : /*
1777 : : * These parameters control the automatic generation (Tx) and
1778 : : * response (Rx) to Ethernet PAUSE frames.
1779 : : * - High water mark should allow for at least two standard size (1518)
1780 : : * frames to be received after sending an XOFF.
1781 : : * - Low water mark works best when it is very near the high water mark.
1782 : : * This allows the receiver to restart by sending XON when it has
1783 : : * drained a bit. Here we use an arbitrary value of 1500 which will
1784 : : * restart after one full frame is pulled from the buffer. There
1785 : : * could be several smaller frames in the buffer and if so they will
1786 : : * not trigger the XON until their total number reduces the buffer
1787 : : * by 1500.
1788 : : * - The pause time is fairly large at 1000 x 512ns = 512 usec.
1789 : : */
1790 : 0 : rx_buf_size = igb_get_rx_buffer_size(hw);
1791 : :
1792 : 0 : hw->fc.high_water = rx_buf_size - (RTE_ETHER_MAX_LEN * 2);
1793 : 0 : hw->fc.low_water = hw->fc.high_water - 1500;
1794 : 0 : hw->fc.pause_time = IGB_FC_PAUSE_TIME;
1795 : 0 : hw->fc.send_xon = 1;
1796 : :
1797 : : /* Set Flow control, use the tunable location if sane */
1798 [ # # ]: 0 : if ((igb_fc_setting != e1000_fc_none) && (igb_fc_setting < 4))
1799 : 0 : hw->fc.requested_mode = igb_fc_setting;
1800 : : else
1801 : 0 : hw->fc.requested_mode = e1000_fc_none;
1802 : :
1803 : : /* Issue a global reset */
1804 : 0 : igb_pf_reset_hw(hw);
1805 : 0 : E1000_WRITE_REG(hw, E1000_WUC, 0);
1806 : :
1807 : 0 : diag = e1000_init_hw(hw);
1808 [ # # ]: 0 : if (diag < 0)
1809 : : return diag;
1810 : :
1811 : 0 : E1000_WRITE_REG(hw, E1000_VET,
1812 : : RTE_ETHER_TYPE_VLAN << 16 | RTE_ETHER_TYPE_VLAN);
1813 : 0 : e1000_get_phy_info(hw);
1814 : 0 : e1000_check_for_link(hw);
1815 : :
1816 : 0 : return 0;
1817 : : }
1818 : :
1819 : : /* This function is based on igb_update_stats_counters() in igb/if_igb.c */
1820 : : static void
1821 : 0 : igb_read_stats_registers(struct e1000_hw *hw, struct e1000_hw_stats *stats)
1822 : : {
1823 : : int pause_frames;
1824 : :
1825 : 0 : uint64_t old_gprc = stats->gprc;
1826 : 0 : uint64_t old_gptc = stats->gptc;
1827 : 0 : uint64_t old_tpr = stats->tpr;
1828 : 0 : uint64_t old_tpt = stats->tpt;
1829 : 0 : uint64_t old_rpthc = stats->rpthc;
1830 : 0 : uint64_t old_hgptc = stats->hgptc;
1831 : :
1832 [ # # ]: 0 : if(hw->phy.media_type == e1000_media_type_copper ||
1833 [ # # ]: 0 : (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
1834 : 0 : stats->symerrs +=
1835 : 0 : E1000_READ_REG(hw,E1000_SYMERRS);
1836 : 0 : stats->sec += E1000_READ_REG(hw, E1000_SEC);
1837 : : }
1838 : :
1839 : 0 : stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
1840 : 0 : stats->mpc += E1000_READ_REG(hw, E1000_MPC);
1841 : 0 : stats->scc += E1000_READ_REG(hw, E1000_SCC);
1842 : 0 : stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
1843 : :
1844 : 0 : stats->mcc += E1000_READ_REG(hw, E1000_MCC);
1845 : 0 : stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
1846 : 0 : stats->colc += E1000_READ_REG(hw, E1000_COLC);
1847 : 0 : stats->dc += E1000_READ_REG(hw, E1000_DC);
1848 : 0 : stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
1849 : 0 : stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
1850 : 0 : stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
1851 : : /*
1852 : : ** For watchdog management we need to know if we have been
1853 : : ** paused during the last interval, so capture that here.
1854 : : */
1855 : 0 : pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
1856 : 0 : stats->xoffrxc += pause_frames;
1857 : 0 : stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
1858 : 0 : stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
1859 : 0 : stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
1860 : 0 : stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
1861 : 0 : stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
1862 : 0 : stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
1863 : 0 : stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
1864 : 0 : stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
1865 : 0 : stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
1866 : 0 : stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
1867 : 0 : stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
1868 : 0 : stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
1869 : :
1870 : : /* For the 64-bit byte counters the low dword must be read first. */
1871 : : /* Both registers clear on the read of the high dword */
1872 : :
1873 : : /* Workaround CRC bytes included in size, take away 4 bytes/packet */
1874 : 0 : stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
1875 : 0 : stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
1876 : 0 : stats->gorc -= (stats->gprc - old_gprc) * RTE_ETHER_CRC_LEN;
1877 : 0 : stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
1878 : 0 : stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
1879 : 0 : stats->gotc -= (stats->gptc - old_gptc) * RTE_ETHER_CRC_LEN;
1880 : :
1881 : 0 : stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
1882 : 0 : stats->ruc += E1000_READ_REG(hw, E1000_RUC);
1883 : 0 : stats->rfc += E1000_READ_REG(hw, E1000_RFC);
1884 : 0 : stats->roc += E1000_READ_REG(hw, E1000_ROC);
1885 : 0 : stats->rjc += E1000_READ_REG(hw, E1000_RJC);
1886 : :
1887 : 0 : stats->tpr += E1000_READ_REG(hw, E1000_TPR);
1888 : 0 : stats->tpt += E1000_READ_REG(hw, E1000_TPT);
1889 : :
1890 : 0 : stats->tor += E1000_READ_REG(hw, E1000_TORL);
1891 : 0 : stats->tor += ((uint64_t)E1000_READ_REG(hw, E1000_TORH) << 32);
1892 : 0 : stats->tor -= (stats->tpr - old_tpr) * RTE_ETHER_CRC_LEN;
1893 : 0 : stats->tot += E1000_READ_REG(hw, E1000_TOTL);
1894 : 0 : stats->tot += ((uint64_t)E1000_READ_REG(hw, E1000_TOTH) << 32);
1895 : 0 : stats->tot -= (stats->tpt - old_tpt) * RTE_ETHER_CRC_LEN;
1896 : :
1897 : 0 : stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
1898 : 0 : stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
1899 : 0 : stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
1900 : 0 : stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
1901 : 0 : stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
1902 : 0 : stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
1903 : 0 : stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
1904 : 0 : stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
1905 : :
1906 : : /* Interrupt Counts */
1907 : :
1908 : 0 : stats->iac += E1000_READ_REG(hw, E1000_IAC);
1909 : 0 : stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
1910 : 0 : stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
1911 : 0 : stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
1912 : 0 : stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
1913 : 0 : stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
1914 : 0 : stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
1915 : 0 : stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
1916 : 0 : stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
1917 : :
1918 : : /* Host to Card Statistics */
1919 : :
1920 : 0 : stats->cbtmpc += E1000_READ_REG(hw, E1000_CBTMPC);
1921 : 0 : stats->htdpmc += E1000_READ_REG(hw, E1000_HTDPMC);
1922 : 0 : stats->cbrdpc += E1000_READ_REG(hw, E1000_CBRDPC);
1923 : 0 : stats->cbrmpc += E1000_READ_REG(hw, E1000_CBRMPC);
1924 : 0 : stats->rpthc += E1000_READ_REG(hw, E1000_RPTHC);
1925 : 0 : stats->hgptc += E1000_READ_REG(hw, E1000_HGPTC);
1926 : 0 : stats->htcbdpc += E1000_READ_REG(hw, E1000_HTCBDPC);
1927 : 0 : stats->hgorc += E1000_READ_REG(hw, E1000_HGORCL);
1928 : 0 : stats->hgorc += ((uint64_t)E1000_READ_REG(hw, E1000_HGORCH) << 32);
1929 : 0 : stats->hgorc -= (stats->rpthc - old_rpthc) * RTE_ETHER_CRC_LEN;
1930 : 0 : stats->hgotc += E1000_READ_REG(hw, E1000_HGOTCL);
1931 : 0 : stats->hgotc += ((uint64_t)E1000_READ_REG(hw, E1000_HGOTCH) << 32);
1932 : 0 : stats->hgotc -= (stats->hgptc - old_hgptc) * RTE_ETHER_CRC_LEN;
1933 : 0 : stats->lenerrs += E1000_READ_REG(hw, E1000_LENERRS);
1934 : 0 : stats->scvpc += E1000_READ_REG(hw, E1000_SCVPC);
1935 : 0 : stats->hrmpc += E1000_READ_REG(hw, E1000_HRMPC);
1936 : :
1937 : 0 : stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
1938 : 0 : stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
1939 : 0 : stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
1940 : 0 : stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
1941 : 0 : stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
1942 : 0 : stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
1943 : 0 : }
1944 : :
1945 : : static int
1946 : 0 : eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1947 : : {
1948 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1949 : 0 : struct e1000_hw_stats *stats =
1950 : : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1951 : :
1952 : 0 : igb_read_stats_registers(hw, stats);
1953 : :
1954 [ # # ]: 0 : if (rte_stats == NULL)
1955 : : return -EINVAL;
1956 : :
1957 : : /* Rx Errors */
1958 : 0 : rte_stats->imissed = stats->mpc;
1959 : 0 : rte_stats->ierrors = stats->crcerrs + stats->rlec +
1960 : 0 : stats->rxerrc + stats->algnerrc + stats->cexterr;
1961 : :
1962 : : /* Tx Errors */
1963 : 0 : rte_stats->oerrors = stats->ecol + stats->latecol;
1964 : :
1965 : 0 : rte_stats->ipackets = stats->gprc;
1966 : 0 : rte_stats->opackets = stats->gptc;
1967 : 0 : rte_stats->ibytes = stats->gorc;
1968 : 0 : rte_stats->obytes = stats->gotc;
1969 : 0 : return 0;
1970 : : }
1971 : :
1972 : : static int
1973 : 0 : eth_igb_stats_reset(struct rte_eth_dev *dev)
1974 : : {
1975 : 0 : struct e1000_hw_stats *hw_stats =
1976 : 0 : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1977 : :
1978 : : /* HW registers are cleared on read */
1979 : : eth_igb_stats_get(dev, NULL);
1980 : :
1981 : : /* Reset software totals */
1982 : : memset(hw_stats, 0, sizeof(*hw_stats));
1983 : :
1984 : 0 : return 0;
1985 : : }
1986 : :
1987 : : static int
1988 : 0 : eth_igb_xstats_reset(struct rte_eth_dev *dev)
1989 : : {
1990 : 0 : struct e1000_hw_stats *stats =
1991 : 0 : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1992 : :
1993 : : /* HW registers are cleared on read */
1994 : : eth_igb_xstats_get(dev, NULL, IGB_NB_XSTATS);
1995 : :
1996 : : /* Reset software totals */
1997 : : memset(stats, 0, sizeof(*stats));
1998 : :
1999 : 0 : return 0;
2000 : : }
2001 : :
2002 : 0 : static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2003 : : struct rte_eth_xstat_name *xstats_names,
2004 : : __rte_unused unsigned int size)
2005 : : {
2006 : : unsigned i;
2007 : :
2008 [ # # ]: 0 : if (xstats_names == NULL)
2009 : : return IGB_NB_XSTATS;
2010 : :
2011 : : /* Note: limit checked in rte_eth_xstats_names() */
2012 : :
2013 [ # # ]: 0 : for (i = 0; i < IGB_NB_XSTATS; i++) {
2014 : 0 : strlcpy(xstats_names[i].name, rte_igb_stats_strings[i].name,
2015 : : sizeof(xstats_names[i].name));
2016 : : }
2017 : :
2018 : : return IGB_NB_XSTATS;
2019 : : }
2020 : :
2021 : 0 : static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
2022 : : const uint64_t *ids, struct rte_eth_xstat_name *xstats_names,
2023 : : unsigned int limit)
2024 : : {
2025 : : unsigned int i;
2026 : :
2027 [ # # ]: 0 : if (!ids) {
2028 [ # # ]: 0 : if (xstats_names == NULL)
2029 : : return IGB_NB_XSTATS;
2030 : :
2031 [ # # ]: 0 : for (i = 0; i < IGB_NB_XSTATS; i++)
2032 : 0 : strlcpy(xstats_names[i].name,
2033 : : rte_igb_stats_strings[i].name,
2034 : : sizeof(xstats_names[i].name));
2035 : :
2036 : : return IGB_NB_XSTATS;
2037 : :
2038 : : } else {
2039 : : struct rte_eth_xstat_name xstats_names_copy[IGB_NB_XSTATS];
2040 : :
2041 : 0 : eth_igb_xstats_get_names_by_id(dev, NULL, xstats_names_copy,
2042 : : IGB_NB_XSTATS);
2043 : :
2044 [ # # ]: 0 : for (i = 0; i < limit; i++) {
2045 [ # # ]: 0 : if (ids[i] >= IGB_NB_XSTATS) {
2046 : 0 : PMD_INIT_LOG(ERR, "id value isn't valid");
2047 : 0 : return -1;
2048 : : }
2049 : 0 : strcpy(xstats_names[i].name,
2050 : 0 : xstats_names_copy[ids[i]].name);
2051 : : }
2052 : 0 : return limit;
2053 : : }
2054 : : }
2055 : :
2056 : : static int
2057 : 0 : eth_igb_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2058 : : unsigned n)
2059 : : {
2060 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2061 : 0 : struct e1000_hw_stats *hw_stats =
2062 : : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2063 : : unsigned i;
2064 : :
2065 [ # # ]: 0 : if (n < IGB_NB_XSTATS)
2066 : : return IGB_NB_XSTATS;
2067 : :
2068 : 0 : igb_read_stats_registers(hw, hw_stats);
2069 : :
2070 : : /* If this is a reset xstats is NULL, and we have cleared the
2071 : : * registers by reading them.
2072 : : */
2073 [ # # ]: 0 : if (!xstats)
2074 : : return 0;
2075 : :
2076 : : /* Extended stats */
2077 [ # # ]: 0 : for (i = 0; i < IGB_NB_XSTATS; i++) {
2078 : 0 : xstats[i].id = i;
2079 : 0 : xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
2080 : 0 : rte_igb_stats_strings[i].offset);
2081 : : }
2082 : :
2083 : : return IGB_NB_XSTATS;
2084 : : }
2085 : :
2086 : : static int
2087 : 0 : eth_igb_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
2088 : : uint64_t *values, unsigned int n)
2089 : : {
2090 : : unsigned int i;
2091 : :
2092 [ # # ]: 0 : if (!ids) {
2093 : 0 : struct e1000_hw *hw =
2094 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2095 : 0 : struct e1000_hw_stats *hw_stats =
2096 : : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2097 : :
2098 [ # # ]: 0 : if (n < IGB_NB_XSTATS)
2099 : : return IGB_NB_XSTATS;
2100 : :
2101 : 0 : igb_read_stats_registers(hw, hw_stats);
2102 : :
2103 : : /* If this is a reset xstats is NULL, and we have cleared the
2104 : : * registers by reading them.
2105 : : */
2106 [ # # ]: 0 : if (!values)
2107 : : return 0;
2108 : :
2109 : : /* Extended stats */
2110 [ # # ]: 0 : for (i = 0; i < IGB_NB_XSTATS; i++)
2111 : 0 : values[i] = *(uint64_t *)(((char *)hw_stats) +
2112 : 0 : rte_igb_stats_strings[i].offset);
2113 : :
2114 : : return IGB_NB_XSTATS;
2115 : :
2116 : : } else {
2117 : : uint64_t values_copy[IGB_NB_XSTATS];
2118 : :
2119 : 0 : eth_igb_xstats_get_by_id(dev, NULL, values_copy,
2120 : : IGB_NB_XSTATS);
2121 : :
2122 [ # # ]: 0 : for (i = 0; i < n; i++) {
2123 [ # # ]: 0 : if (ids[i] >= IGB_NB_XSTATS) {
2124 : 0 : PMD_INIT_LOG(ERR, "id value isn't valid");
2125 : 0 : return -1;
2126 : : }
2127 : 0 : values[i] = values_copy[ids[i]];
2128 : : }
2129 : 0 : return n;
2130 : : }
2131 : : }
2132 : :
2133 : : static void
2134 : 0 : igbvf_read_stats_registers(struct e1000_hw *hw, struct e1000_vf_stats *hw_stats)
2135 : : {
2136 : : /* Good Rx packets, include VF loopback */
2137 : 0 : UPDATE_VF_STAT(E1000_VFGPRC,
2138 : : hw_stats->last_gprc, hw_stats->gprc);
2139 : :
2140 : : /* Good Rx octets, include VF loopback */
2141 : 0 : UPDATE_VF_STAT(E1000_VFGORC,
2142 : : hw_stats->last_gorc, hw_stats->gorc);
2143 : :
2144 : : /* Good Tx packets, include VF loopback */
2145 : 0 : UPDATE_VF_STAT(E1000_VFGPTC,
2146 : : hw_stats->last_gptc, hw_stats->gptc);
2147 : :
2148 : : /* Good Tx octets, include VF loopback */
2149 : 0 : UPDATE_VF_STAT(E1000_VFGOTC,
2150 : : hw_stats->last_gotc, hw_stats->gotc);
2151 : :
2152 : : /* Rx Multicst packets */
2153 : 0 : UPDATE_VF_STAT(E1000_VFMPRC,
2154 : : hw_stats->last_mprc, hw_stats->mprc);
2155 : :
2156 : : /* Good Rx loopback packets */
2157 : 0 : UPDATE_VF_STAT(E1000_VFGPRLBC,
2158 : : hw_stats->last_gprlbc, hw_stats->gprlbc);
2159 : :
2160 : : /* Good Rx loopback octets */
2161 : 0 : UPDATE_VF_STAT(E1000_VFGORLBC,
2162 : : hw_stats->last_gorlbc, hw_stats->gorlbc);
2163 : :
2164 : : /* Good Tx loopback packets */
2165 : 0 : UPDATE_VF_STAT(E1000_VFGPTLBC,
2166 : : hw_stats->last_gptlbc, hw_stats->gptlbc);
2167 : :
2168 : : /* Good Tx loopback octets */
2169 : 0 : UPDATE_VF_STAT(E1000_VFGOTLBC,
2170 : : hw_stats->last_gotlbc, hw_stats->gotlbc);
2171 : 0 : }
2172 : :
2173 : 0 : static int eth_igbvf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2174 : : struct rte_eth_xstat_name *xstats_names,
2175 : : __rte_unused unsigned limit)
2176 : : {
2177 : : unsigned i;
2178 : :
2179 [ # # ]: 0 : if (xstats_names != NULL)
2180 [ # # ]: 0 : for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2181 : 0 : strlcpy(xstats_names[i].name,
2182 : : rte_igbvf_stats_strings[i].name,
2183 : : sizeof(xstats_names[i].name));
2184 : : }
2185 : 0 : return IGBVF_NB_XSTATS;
2186 : : }
2187 : :
2188 : : static int
2189 : 0 : eth_igbvf_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2190 : : unsigned n)
2191 : : {
2192 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2193 : 0 : struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2194 : : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2195 : : unsigned i;
2196 : :
2197 [ # # ]: 0 : if (n < IGBVF_NB_XSTATS)
2198 : : return IGBVF_NB_XSTATS;
2199 : :
2200 : 0 : igbvf_read_stats_registers(hw, hw_stats);
2201 : :
2202 [ # # ]: 0 : if (!xstats)
2203 : : return 0;
2204 : :
2205 [ # # ]: 0 : for (i = 0; i < IGBVF_NB_XSTATS; i++) {
2206 : 0 : xstats[i].id = i;
2207 : 0 : xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
2208 : 0 : rte_igbvf_stats_strings[i].offset);
2209 : : }
2210 : :
2211 : : return IGBVF_NB_XSTATS;
2212 : : }
2213 : :
2214 : : static int
2215 : 0 : eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
2216 : : {
2217 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2218 : 0 : struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats *)
2219 : : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2220 : :
2221 : 0 : igbvf_read_stats_registers(hw, hw_stats);
2222 : :
2223 [ # # ]: 0 : if (rte_stats == NULL)
2224 : : return -EINVAL;
2225 : :
2226 : 0 : rte_stats->ipackets = hw_stats->gprc;
2227 : 0 : rte_stats->ibytes = hw_stats->gorc;
2228 : 0 : rte_stats->opackets = hw_stats->gptc;
2229 : 0 : rte_stats->obytes = hw_stats->gotc;
2230 : 0 : return 0;
2231 : : }
2232 : :
2233 : : static int
2234 : 0 : eth_igbvf_stats_reset(struct rte_eth_dev *dev)
2235 : : {
2236 : : struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
2237 : 0 : E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
2238 : :
2239 : : /* Sync HW register to the last stats */
2240 : : eth_igbvf_stats_get(dev, NULL);
2241 : :
2242 : : /* reset HW current stats*/
2243 : 0 : memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
2244 : : offsetof(struct e1000_vf_stats, gprc));
2245 : :
2246 : 0 : return 0;
2247 : : }
2248 : :
2249 : : static int
2250 : 0 : eth_igb_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
2251 : : size_t fw_size)
2252 : : {
2253 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2254 : : struct e1000_fw_version fw;
2255 : : int ret;
2256 : :
2257 : : /*
2258 : : * This function calls into the base driver, which in turn will use
2259 : : * function pointers, which are not guaranteed to be valid in secondary
2260 : : * processes, so avoid using this function in secondary processes.
2261 : : */
2262 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2263 : : return -E_RTE_SECONDARY;
2264 : :
2265 : 0 : e1000_get_fw_version(hw, &fw);
2266 : :
2267 [ # # ]: 0 : switch (hw->mac.type) {
2268 : 0 : case e1000_i210:
2269 : : case e1000_i211:
2270 [ # # ]: 0 : if (!(e1000_get_flash_presence_i210(hw))) {
2271 : 0 : ret = snprintf(fw_version, fw_size,
2272 : : "%2d.%2d-%d",
2273 : 0 : fw.invm_major, fw.invm_minor,
2274 : 0 : fw.invm_img_type);
2275 : 0 : break;
2276 : : }
2277 : : /* fall through */
2278 : : default:
2279 : : /* if option rom is valid, display its version too */
2280 [ # # ]: 0 : if (fw.or_valid) {
2281 : 0 : ret = snprintf(fw_version, fw_size,
2282 : : "%d.%d, 0x%08x, %d.%d.%d",
2283 : 0 : fw.eep_major, fw.eep_minor, fw.etrack_id,
2284 : 0 : fw.or_major, fw.or_build, fw.or_patch);
2285 : : /* no option rom */
2286 : : } else {
2287 [ # # ]: 0 : if (fw.etrack_id != 0X0000) {
2288 : 0 : ret = snprintf(fw_version, fw_size,
2289 : : "%d.%d, 0x%08x",
2290 : 0 : fw.eep_major, fw.eep_minor,
2291 : : fw.etrack_id);
2292 : : } else {
2293 : 0 : ret = snprintf(fw_version, fw_size,
2294 : : "%d.%d.%d",
2295 : 0 : fw.eep_major, fw.eep_minor,
2296 : 0 : fw.eep_build);
2297 : : }
2298 : : }
2299 : : break;
2300 : : }
2301 [ # # ]: 0 : if (ret < 0)
2302 : : return -EINVAL;
2303 : :
2304 : 0 : ret += 1; /* add the size of '\0' */
2305 [ # # ]: 0 : if (fw_size < (size_t)ret)
2306 : : return ret;
2307 : : else
2308 : 0 : return 0;
2309 : : }
2310 : :
2311 : : static int
2312 : 0 : eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2313 : : {
2314 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2315 : :
2316 : 0 : dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2317 : 0 : dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2318 : 0 : dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2319 : 0 : dev_info->rx_queue_offload_capa = igb_get_rx_queue_offloads_capa(dev);
2320 : 0 : dev_info->rx_offload_capa = igb_get_rx_port_offloads_capa(dev) |
2321 : 0 : dev_info->rx_queue_offload_capa;
2322 : 0 : dev_info->tx_queue_offload_capa = igb_get_tx_queue_offloads_capa(dev);
2323 : 0 : dev_info->tx_offload_capa = igb_get_tx_port_offloads_capa(dev) |
2324 : 0 : dev_info->tx_queue_offload_capa;
2325 : 0 : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
2326 : :
2327 [ # # # # : 0 : switch (hw->mac.type) {
# # # # ]
2328 : 0 : case e1000_82575:
2329 : 0 : dev_info->max_rx_queues = 4;
2330 : 0 : dev_info->max_tx_queues = 4;
2331 : 0 : dev_info->max_vmdq_pools = 0;
2332 : 0 : break;
2333 : :
2334 : 0 : case e1000_82576:
2335 : 0 : dev_info->max_rx_queues = 16;
2336 : 0 : dev_info->max_tx_queues = 16;
2337 : 0 : dev_info->max_vmdq_pools = RTE_ETH_8_POOLS;
2338 : 0 : dev_info->vmdq_queue_num = 16;
2339 : 0 : break;
2340 : :
2341 : 0 : case e1000_82580:
2342 : 0 : dev_info->max_rx_queues = 8;
2343 : 0 : dev_info->max_tx_queues = 8;
2344 : 0 : dev_info->max_vmdq_pools = RTE_ETH_8_POOLS;
2345 : 0 : dev_info->vmdq_queue_num = 8;
2346 : 0 : break;
2347 : :
2348 : 0 : case e1000_i350:
2349 : 0 : dev_info->max_rx_queues = 8;
2350 : 0 : dev_info->max_tx_queues = 8;
2351 : 0 : dev_info->max_vmdq_pools = RTE_ETH_8_POOLS;
2352 : 0 : dev_info->vmdq_queue_num = 8;
2353 : 0 : break;
2354 : :
2355 : 0 : case e1000_i354:
2356 : 0 : dev_info->max_rx_queues = 8;
2357 : 0 : dev_info->max_tx_queues = 8;
2358 : 0 : break;
2359 : :
2360 : 0 : case e1000_i210:
2361 : 0 : dev_info->max_rx_queues = 4;
2362 : 0 : dev_info->max_tx_queues = 4;
2363 : 0 : dev_info->max_vmdq_pools = 0;
2364 : 0 : break;
2365 : :
2366 : 0 : case e1000_i211:
2367 : 0 : dev_info->max_rx_queues = 2;
2368 : 0 : dev_info->max_tx_queues = 2;
2369 : 0 : dev_info->max_vmdq_pools = 0;
2370 : 0 : break;
2371 : :
2372 : : default:
2373 : : /* Should not happen */
2374 : : return -EINVAL;
2375 : : }
2376 : 0 : dev_info->hash_key_size = IGB_HKEY_MAX_INDEX * sizeof(uint32_t);
2377 : 0 : dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_128;
2378 : 0 : dev_info->flow_type_rss_offloads = IGB_RSS_OFFLOAD_ALL;
2379 : :
2380 [ # # # # ]: 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
2381 : : .rx_thresh = {
2382 : : .pthresh = IGB_DEFAULT_RX_PTHRESH,
2383 : : .hthresh = IGB_DEFAULT_RX_HTHRESH,
2384 : : .wthresh = IGB_DEFAULT_RX_WTHRESH,
2385 : : },
2386 : : .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2387 : : .rx_drop_en = 0,
2388 : : .offloads = 0,
2389 : : };
2390 : :
2391 [ # # # # ]: 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
2392 : : .tx_thresh = {
2393 : : .pthresh = IGB_DEFAULT_TX_PTHRESH,
2394 : : .hthresh = IGB_DEFAULT_TX_HTHRESH,
2395 : : .wthresh = IGB_DEFAULT_TX_WTHRESH,
2396 : : },
2397 : : .offloads = 0,
2398 : : };
2399 : :
2400 : 0 : dev_info->rx_desc_lim = rx_desc_lim;
2401 : 0 : dev_info->tx_desc_lim = tx_desc_lim;
2402 : :
2403 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
2404 : : RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
2405 : : RTE_ETH_LINK_SPEED_1G;
2406 : :
2407 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - E1000_ETH_OVERHEAD;
2408 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
2409 : :
2410 : 0 : return 0;
2411 : : }
2412 : :
2413 : : static const uint32_t *
2414 : 0 : eth_igb_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
2415 : : {
2416 : : static const uint32_t ptypes[] = {
2417 : : /* refers to igb_rxd_pkt_info_to_pkt_type() */
2418 : : RTE_PTYPE_L2_ETHER,
2419 : : RTE_PTYPE_L3_IPV4,
2420 : : RTE_PTYPE_L3_IPV4_EXT,
2421 : : RTE_PTYPE_L3_IPV6,
2422 : : RTE_PTYPE_L3_IPV6_EXT,
2423 : : RTE_PTYPE_L4_TCP,
2424 : : RTE_PTYPE_L4_UDP,
2425 : : RTE_PTYPE_L4_SCTP,
2426 : : RTE_PTYPE_TUNNEL_IP,
2427 : : RTE_PTYPE_INNER_L3_IPV6,
2428 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
2429 : : RTE_PTYPE_INNER_L4_TCP,
2430 : : RTE_PTYPE_INNER_L4_UDP,
2431 : : };
2432 : :
2433 [ # # # # ]: 0 : if (dev->rx_pkt_burst == eth_igb_recv_pkts ||
2434 : : dev->rx_pkt_burst == eth_igb_recv_scattered_pkts) {
2435 : 0 : *no_of_elements = RTE_DIM(ptypes);
2436 : 0 : return ptypes;
2437 : : }
2438 : : return NULL;
2439 : : }
2440 : :
2441 : : static int
2442 : 0 : eth_igbvf_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2443 : : {
2444 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2445 : :
2446 : 0 : dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
2447 : 0 : dev_info->max_rx_pktlen = 0x3FFF; /* See RLPML register. */
2448 : 0 : dev_info->max_mac_addrs = hw->mac.rar_entry_count;
2449 : 0 : dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
2450 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
2451 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
2452 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
2453 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
2454 : : RTE_ETH_TX_OFFLOAD_TCP_TSO;
2455 [ # # # ]: 0 : switch (hw->mac.type) {
2456 : 0 : case e1000_vfadapt:
2457 : 0 : dev_info->max_rx_queues = 2;
2458 : 0 : dev_info->max_tx_queues = 2;
2459 : 0 : break;
2460 : 0 : case e1000_vfadapt_i350:
2461 : 0 : dev_info->max_rx_queues = 1;
2462 : 0 : dev_info->max_tx_queues = 1;
2463 : 0 : break;
2464 : : default:
2465 : : /* Should not happen */
2466 : : return -EINVAL;
2467 : : }
2468 : :
2469 : 0 : dev_info->rx_queue_offload_capa = igb_get_rx_queue_offloads_capa(dev);
2470 : 0 : dev_info->rx_offload_capa = igb_get_rx_port_offloads_capa(dev) |
2471 : 0 : dev_info->rx_queue_offload_capa;
2472 : 0 : dev_info->tx_queue_offload_capa = igb_get_tx_queue_offloads_capa(dev);
2473 : 0 : dev_info->tx_offload_capa = igb_get_tx_port_offloads_capa(dev) |
2474 : 0 : dev_info->tx_queue_offload_capa;
2475 : :
2476 [ # # ]: 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
2477 : : .rx_thresh = {
2478 [ # # ]: 0 : .pthresh = IGB_DEFAULT_RX_PTHRESH,
2479 : : .hthresh = IGB_DEFAULT_RX_HTHRESH,
2480 : : .wthresh = IGB_DEFAULT_RX_WTHRESH,
2481 : : },
2482 : : .rx_free_thresh = IGB_DEFAULT_RX_FREE_THRESH,
2483 : : .rx_drop_en = 0,
2484 : : .offloads = 0,
2485 : : };
2486 : :
2487 [ # # # # ]: 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
2488 : : .tx_thresh = {
2489 : : .pthresh = IGB_DEFAULT_TX_PTHRESH,
2490 : : .hthresh = IGB_DEFAULT_TX_HTHRESH,
2491 : : .wthresh = IGB_DEFAULT_TX_WTHRESH,
2492 : : },
2493 : : .offloads = 0,
2494 : : };
2495 : :
2496 : 0 : dev_info->rx_desc_lim = rx_desc_lim;
2497 : 0 : dev_info->tx_desc_lim = tx_desc_lim;
2498 : :
2499 : 0 : dev_info->err_handle_mode = RTE_ETH_ERROR_HANDLE_MODE_PASSIVE;
2500 : :
2501 : 0 : return 0;
2502 : : }
2503 : :
2504 : : /* return 0 means link status changed, -1 means not changed */
2505 : : static int
2506 : 0 : eth_igb_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2507 : : {
2508 : 0 : struct e1000_hw *hw =
2509 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2510 : : struct rte_eth_link link;
2511 : : int link_check, count;
2512 : :
2513 : : /*
2514 : : * This function calls into the base driver, which in turn will use
2515 : : * function pointers, which are not guaranteed to be valid in secondary
2516 : : * processes, so avoid using this function in secondary processes.
2517 : : */
2518 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2519 : : return -E_RTE_SECONDARY;
2520 : :
2521 : : link_check = 0;
2522 : 0 : hw->mac.get_link_status = 1;
2523 : :
2524 : : /* possible wait-to-complete in up to 9 seconds */
2525 [ # # ]: 0 : for (count = 0; count < IGB_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
2526 : : /* Read the real link status */
2527 [ # # # # : 0 : switch (hw->phy.media_type) {
# ]
2528 : 0 : case e1000_media_type_copper:
2529 : : /* Do the work to read phy */
2530 : 0 : e1000_check_for_link(hw);
2531 : 0 : link_check = !hw->mac.get_link_status;
2532 : 0 : break;
2533 : :
2534 : 0 : case e1000_media_type_fiber:
2535 : 0 : e1000_check_for_link(hw);
2536 : 0 : link_check = (E1000_READ_REG(hw, E1000_STATUS) &
2537 : : E1000_STATUS_LU);
2538 : 0 : break;
2539 : :
2540 : 0 : case e1000_media_type_internal_serdes:
2541 : 0 : e1000_check_for_link(hw);
2542 : 0 : link_check = hw->mac.serdes_has_link;
2543 : 0 : break;
2544 : :
2545 : : /* VF device is type_unknown */
2546 : 0 : case e1000_media_type_unknown:
2547 : 0 : eth_igbvf_link_update(hw);
2548 : 0 : link_check = !hw->mac.get_link_status;
2549 : 0 : break;
2550 : :
2551 : : default:
2552 : : break;
2553 : : }
2554 [ # # ]: 0 : if (link_check || wait_to_complete == 0)
2555 : : break;
2556 : : rte_delay_ms(IGB_LINK_UPDATE_CHECK_INTERVAL);
2557 : : }
2558 : : memset(&link, 0, sizeof(link));
2559 : :
2560 : : /* Now we check if a transition has happened */
2561 [ # # ]: 0 : if (link_check) {
2562 : : uint16_t duplex, speed;
2563 : 0 : hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
2564 : 0 : link.link_duplex = (duplex == FULL_DUPLEX) ?
2565 : 0 : RTE_ETH_LINK_FULL_DUPLEX :
2566 : : RTE_ETH_LINK_HALF_DUPLEX;
2567 : 0 : link.link_speed = speed;
2568 : 0 : link.link_status = RTE_ETH_LINK_UP;
2569 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2570 : : RTE_ETH_LINK_SPEED_FIXED);
2571 : : } else if (!link_check) {
2572 : : link.link_speed = 0;
2573 : : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
2574 : : link.link_status = RTE_ETH_LINK_DOWN;
2575 : : link.link_autoneg = RTE_ETH_LINK_FIXED;
2576 : : }
2577 : :
2578 : : return rte_eth_linkstatus_set(dev, &link);
2579 : : }
2580 : :
2581 : : /*
2582 : : * igb_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
2583 : : * For ASF and Pass Through versions of f/w this means
2584 : : * that the driver is loaded.
2585 : : */
2586 : : static void
2587 : : igb_hw_control_acquire(struct e1000_hw *hw)
2588 : : {
2589 : : uint32_t ctrl_ext;
2590 : :
2591 : : /* Let firmware know the driver has taken over */
2592 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2593 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
2594 : : }
2595 : :
2596 : : /*
2597 : : * igb_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
2598 : : * For ASF and Pass Through versions of f/w this means that the
2599 : : * driver is no longer loaded.
2600 : : */
2601 : : static void
2602 : : igb_hw_control_release(struct e1000_hw *hw)
2603 : : {
2604 : : uint32_t ctrl_ext;
2605 : :
2606 : : /* Let firmware taken over control of h/w */
2607 : 0 : ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
2608 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT,
2609 : : ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
2610 : : }
2611 : :
2612 : : /*
2613 : : * Bit of a misnomer, what this really means is
2614 : : * to enable OS management of the system... aka
2615 : : * to disable special hardware management features.
2616 : : */
2617 : : static void
2618 : 0 : igb_init_manageability(struct e1000_hw *hw)
2619 : : {
2620 [ # # ]: 0 : if (e1000_enable_mng_pass_thru(hw)) {
2621 : 0 : uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
2622 : 0 : uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2623 : :
2624 : : /* disable hardware interception of ARP */
2625 : 0 : manc &= ~(E1000_MANC_ARP_EN);
2626 : :
2627 : : /* enable receiving management packets to the host */
2628 : 0 : manc |= E1000_MANC_EN_MNG2HOST;
2629 : : manc2h |= 1 << 5; /* Mng Port 623 */
2630 : 0 : manc2h |= 1 << 6; /* Mng Port 664 */
2631 : 0 : E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
2632 : 0 : E1000_WRITE_REG(hw, E1000_MANC, manc);
2633 : : }
2634 : 0 : }
2635 : :
2636 : : static void
2637 : 0 : igb_release_manageability(struct e1000_hw *hw)
2638 : : {
2639 [ # # ]: 0 : if (e1000_enable_mng_pass_thru(hw)) {
2640 : 0 : uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
2641 : :
2642 : : manc |= E1000_MANC_ARP_EN;
2643 : 0 : manc &= ~E1000_MANC_EN_MNG2HOST;
2644 : :
2645 : 0 : E1000_WRITE_REG(hw, E1000_MANC, manc);
2646 : : }
2647 : 0 : }
2648 : :
2649 : : static int
2650 : 0 : eth_igb_promiscuous_enable(struct rte_eth_dev *dev)
2651 : : {
2652 : : struct e1000_hw *hw =
2653 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2654 : : uint32_t rctl;
2655 : :
2656 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
2657 : 0 : rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2658 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2659 : :
2660 : 0 : return 0;
2661 : : }
2662 : :
2663 : : static int
2664 : 0 : eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
2665 : : {
2666 : : struct e1000_hw *hw =
2667 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2668 : : uint32_t rctl;
2669 : :
2670 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
2671 : 0 : rctl &= (~E1000_RCTL_UPE);
2672 [ # # ]: 0 : if (dev->data->all_multicast == 1)
2673 : 0 : rctl |= E1000_RCTL_MPE;
2674 : : else
2675 : 0 : rctl &= (~E1000_RCTL_MPE);
2676 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2677 : :
2678 : 0 : return 0;
2679 : : }
2680 : :
2681 : : static int
2682 : 0 : eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
2683 : : {
2684 : : struct e1000_hw *hw =
2685 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2686 : : uint32_t rctl;
2687 : :
2688 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
2689 : 0 : rctl |= E1000_RCTL_MPE;
2690 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2691 : :
2692 : 0 : return 0;
2693 : : }
2694 : :
2695 : : static int
2696 : 0 : eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
2697 : : {
2698 : : struct e1000_hw *hw =
2699 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2700 : : uint32_t rctl;
2701 : :
2702 [ # # ]: 0 : if (dev->data->promiscuous == 1)
2703 : : return 0; /* must remain in all_multicast mode */
2704 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
2705 : 0 : rctl &= (~E1000_RCTL_MPE);
2706 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
2707 : :
2708 : 0 : return 0;
2709 : : }
2710 : :
2711 : : static int
2712 : 0 : eth_igb_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2713 : : {
2714 : : struct e1000_hw *hw =
2715 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2716 : : struct e1000_vfta * shadow_vfta =
2717 : : E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2718 : : uint32_t vfta;
2719 : : uint32_t vid_idx;
2720 : : uint32_t vid_bit;
2721 : :
2722 : 0 : vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
2723 : : E1000_VFTA_ENTRY_MASK);
2724 : 0 : vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
2725 : 0 : vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
2726 [ # # ]: 0 : if (on)
2727 : 0 : vfta |= vid_bit;
2728 : : else
2729 : 0 : vfta &= ~vid_bit;
2730 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
2731 : :
2732 : : /* update local VFTA copy */
2733 : 0 : shadow_vfta->vfta[vid_idx] = vfta;
2734 : :
2735 : 0 : return 0;
2736 : : }
2737 : :
2738 : : static int
2739 : 0 : eth_igb_vlan_tpid_set(struct rte_eth_dev *dev,
2740 : : enum rte_vlan_type vlan_type,
2741 : : uint16_t tpid)
2742 : : {
2743 : : struct e1000_hw *hw =
2744 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2745 : : uint32_t reg, qinq;
2746 : :
2747 : 0 : qinq = E1000_READ_REG(hw, E1000_CTRL_EXT);
2748 : 0 : qinq &= E1000_CTRL_EXT_EXT_VLAN;
2749 : :
2750 : : /* only outer TPID of double VLAN can be configured*/
2751 [ # # ]: 0 : if (qinq && vlan_type == RTE_ETH_VLAN_TYPE_OUTER) {
2752 : 0 : reg = E1000_READ_REG(hw, E1000_VET);
2753 : 0 : reg = (reg & (~E1000_VET_VET_EXT)) |
2754 : 0 : ((uint32_t)tpid << E1000_VET_VET_EXT_SHIFT);
2755 : 0 : E1000_WRITE_REG(hw, E1000_VET, reg);
2756 : :
2757 : 0 : return 0;
2758 : : }
2759 : :
2760 : : /* all other TPID values are read-only*/
2761 : 0 : PMD_DRV_LOG(ERR, "Not supported");
2762 : :
2763 : 0 : return -ENOTSUP;
2764 : : }
2765 : :
2766 : : static void
2767 : : igb_vlan_hw_filter_disable(struct rte_eth_dev *dev)
2768 : : {
2769 : : struct e1000_hw *hw =
2770 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2771 : : uint32_t reg;
2772 : :
2773 : : /* Filter Table Disable */
2774 : 0 : reg = E1000_READ_REG(hw, E1000_RCTL);
2775 : : reg &= ~E1000_RCTL_CFIEN;
2776 : 0 : reg &= ~E1000_RCTL_VFE;
2777 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, reg);
2778 : 0 : }
2779 : :
2780 : : static void
2781 : 0 : igb_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2782 : : {
2783 : : struct e1000_hw *hw =
2784 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2785 : : struct e1000_vfta * shadow_vfta =
2786 : : E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
2787 : : uint32_t reg;
2788 : : int i;
2789 : :
2790 : : /* Filter Table Enable, CFI not used for packet acceptance */
2791 : 0 : reg = E1000_READ_REG(hw, E1000_RCTL);
2792 : 0 : reg &= ~E1000_RCTL_CFIEN;
2793 : 0 : reg |= E1000_RCTL_VFE;
2794 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, reg);
2795 : :
2796 : : /* restore VFTA table */
2797 [ # # ]: 0 : for (i = 0; i < IGB_VFTA_SIZE; i++)
2798 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
2799 : 0 : }
2800 : :
2801 : : static void
2802 : : igb_vlan_hw_strip_disable(struct rte_eth_dev *dev)
2803 : : {
2804 : : struct e1000_hw *hw =
2805 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2806 : : uint32_t reg;
2807 : :
2808 : : /* VLAN Mode Disable */
2809 : 0 : reg = E1000_READ_REG(hw, E1000_CTRL);
2810 : 0 : reg &= ~E1000_CTRL_VME;
2811 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, reg);
2812 : 0 : }
2813 : :
2814 : : static void
2815 : : igb_vlan_hw_strip_enable(struct rte_eth_dev *dev)
2816 : : {
2817 : : struct e1000_hw *hw =
2818 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2819 : : uint32_t reg;
2820 : :
2821 : : /* VLAN Mode Enable */
2822 : 0 : reg = E1000_READ_REG(hw, E1000_CTRL);
2823 : 0 : reg |= E1000_CTRL_VME;
2824 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, reg);
2825 : 0 : }
2826 : :
2827 : : static void
2828 : : igb_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2829 : : {
2830 : : struct e1000_hw *hw =
2831 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2832 : : uint32_t reg;
2833 : :
2834 : : /* CTRL_EXT: Extended VLAN */
2835 : 0 : reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2836 : 0 : reg &= ~E1000_CTRL_EXT_EXTEND_VLAN;
2837 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2838 : :
2839 : : /* Update maximum packet length */
2840 : 0 : E1000_WRITE_REG(hw, E1000_RLPML, dev->data->mtu + E1000_ETH_OVERHEAD);
2841 : 0 : }
2842 : :
2843 : : static void
2844 : : igb_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2845 : : {
2846 : : struct e1000_hw *hw =
2847 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2848 : : uint32_t reg;
2849 : :
2850 : : /* CTRL_EXT: Extended VLAN */
2851 : 0 : reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
2852 : 0 : reg |= E1000_CTRL_EXT_EXTEND_VLAN;
2853 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
2854 : :
2855 : : /* Update maximum packet length */
2856 : 0 : E1000_WRITE_REG(hw, E1000_RLPML,
2857 : : dev->data->mtu + E1000_ETH_OVERHEAD + VLAN_TAG_SIZE);
2858 : 0 : }
2859 : :
2860 : : static int
2861 : 0 : eth_igb_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2862 : : {
2863 : : struct rte_eth_rxmode *rxmode;
2864 : :
2865 : 0 : rxmode = &dev->data->dev_conf.rxmode;
2866 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
2867 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
2868 : : igb_vlan_hw_strip_enable(dev);
2869 : : else
2870 : : igb_vlan_hw_strip_disable(dev);
2871 : : }
2872 : :
2873 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
2874 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
2875 : 0 : igb_vlan_hw_filter_enable(dev);
2876 : : else
2877 : : igb_vlan_hw_filter_disable(dev);
2878 : : }
2879 : :
2880 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
2881 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
2882 : : igb_vlan_hw_extend_enable(dev);
2883 : : else
2884 : : igb_vlan_hw_extend_disable(dev);
2885 : : }
2886 : :
2887 : 0 : return 0;
2888 : : }
2889 : :
2890 : :
2891 : : /**
2892 : : * It enables the interrupt mask and then enable the interrupt.
2893 : : *
2894 : : * @param dev
2895 : : * Pointer to struct rte_eth_dev.
2896 : : * @param on
2897 : : * Enable or Disable
2898 : : *
2899 : : * @return
2900 : : * - On success, zero.
2901 : : * - On failure, a negative value.
2902 : : */
2903 : : static int
2904 : : eth_igb_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
2905 : : {
2906 : : struct e1000_interrupt *intr =
2907 : 0 : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2908 : :
2909 : : if (on)
2910 : 0 : intr->mask |= E1000_ICR_LSC;
2911 : : else
2912 : 0 : intr->mask &= ~E1000_ICR_LSC;
2913 : :
2914 : : return 0;
2915 : : }
2916 : :
2917 : : /* It clears the interrupt causes and enables the interrupt.
2918 : : * It will be called once only during nic initialized.
2919 : : *
2920 : : * @param dev
2921 : : * Pointer to struct rte_eth_dev.
2922 : : *
2923 : : * @return
2924 : : * - On success, zero.
2925 : : * - On failure, a negative value.
2926 : : */
2927 : 0 : static int eth_igb_rxq_interrupt_setup(struct rte_eth_dev *dev)
2928 : : {
2929 : : uint32_t mask, regval;
2930 : : int ret;
2931 : : struct e1000_hw *hw =
2932 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2933 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2934 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2935 : 0 : int misc_shift = rte_intr_allow_others(intr_handle) ? 1 : 0;
2936 : : struct rte_eth_dev_info dev_info;
2937 : :
2938 : : memset(&dev_info, 0, sizeof(dev_info));
2939 : 0 : ret = eth_igb_infos_get(dev, &dev_info);
2940 [ # # ]: 0 : if (ret != 0)
2941 : : return ret;
2942 : :
2943 : 0 : mask = (0xFFFFFFFF >> (32 - dev_info.max_rx_queues)) << misc_shift;
2944 : 0 : regval = E1000_READ_REG(hw, E1000_EIMS);
2945 : 0 : E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
2946 : :
2947 : 0 : return 0;
2948 : : }
2949 : :
2950 : : /*
2951 : : * It reads ICR and gets interrupt causes, check it and set a bit flag
2952 : : * to update link status.
2953 : : *
2954 : : * @param dev
2955 : : * Pointer to struct rte_eth_dev.
2956 : : *
2957 : : * @return
2958 : : * - On success, zero.
2959 : : * - On failure, a negative value.
2960 : : */
2961 : : static int
2962 : 0 : eth_igb_interrupt_get_status(struct rte_eth_dev *dev)
2963 : : {
2964 : : uint32_t icr;
2965 : : struct e1000_hw *hw =
2966 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2967 : : struct e1000_interrupt *intr =
2968 : : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
2969 : :
2970 : 0 : igb_intr_disable(dev);
2971 : :
2972 : : /* read-on-clear nic registers here */
2973 : 0 : icr = E1000_READ_REG(hw, E1000_ICR);
2974 : :
2975 : 0 : intr->flags = 0;
2976 [ # # ]: 0 : if (icr & E1000_ICR_LSC) {
2977 : 0 : intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
2978 : : }
2979 : :
2980 [ # # ]: 0 : if (icr & E1000_ICR_VMMB)
2981 : 0 : intr->flags |= E1000_FLAG_MAILBOX;
2982 : :
2983 : 0 : return 0;
2984 : : }
2985 : :
2986 : : /*
2987 : : * It executes link_update after knowing an interrupt is present.
2988 : : *
2989 : : * @param dev
2990 : : * Pointer to struct rte_eth_dev.
2991 : : *
2992 : : * @return
2993 : : * - On success, zero.
2994 : : * - On failure, a negative value.
2995 : : */
2996 : : static int
2997 : 0 : eth_igb_interrupt_action(struct rte_eth_dev *dev,
2998 : : struct rte_intr_handle *intr_handle)
2999 : : {
3000 : : struct e1000_hw *hw =
3001 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3002 : : struct e1000_interrupt *intr =
3003 : : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3004 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3005 : : struct rte_eth_link link;
3006 : : int ret;
3007 : :
3008 [ # # ]: 0 : if (intr->flags & E1000_FLAG_MAILBOX) {
3009 : 0 : igb_pf_mbx_process(dev);
3010 : 0 : intr->flags &= ~E1000_FLAG_MAILBOX;
3011 : : }
3012 : :
3013 : 0 : igb_intr_enable(dev);
3014 : 0 : rte_intr_ack(intr_handle);
3015 : :
3016 [ # # ]: 0 : if (intr->flags & E1000_FLAG_NEED_LINK_UPDATE) {
3017 : 0 : intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
3018 : :
3019 : : /* set get_link_status to check register later */
3020 : 0 : hw->mac.get_link_status = 1;
3021 : 0 : ret = eth_igb_link_update(dev, 0);
3022 : :
3023 : : /* check if link has changed */
3024 [ # # ]: 0 : if (ret < 0)
3025 : : return 0;
3026 : :
3027 : 0 : rte_eth_linkstatus_get(dev, &link);
3028 [ # # ]: 0 : if (link.link_status) {
3029 [ # # ]: 0 : PMD_INIT_LOG(INFO,
3030 : : " Port %d: Link Up - speed %u Mbps - %s",
3031 : : dev->data->port_id,
3032 : : (unsigned)link.link_speed,
3033 : : link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
3034 : : "full-duplex" : "half-duplex");
3035 : : } else {
3036 : 0 : PMD_INIT_LOG(INFO, " Port %d: Link Down",
3037 : : dev->data->port_id);
3038 : : }
3039 : :
3040 : 0 : PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
3041 : : pci_dev->addr.domain,
3042 : : pci_dev->addr.bus,
3043 : : pci_dev->addr.devid,
3044 : : pci_dev->addr.function);
3045 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
3046 : : }
3047 : :
3048 : : return 0;
3049 : : }
3050 : :
3051 : : /**
3052 : : * Interrupt handler which shall be registered at first.
3053 : : *
3054 : : * @param handle
3055 : : * Pointer to interrupt handle.
3056 : : * @param param
3057 : : * The address of parameter (struct rte_eth_dev *) registered before.
3058 : : *
3059 : : * @return
3060 : : * void
3061 : : */
3062 : : static void
3063 : 0 : eth_igb_interrupt_handler(void *param)
3064 : : {
3065 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
3066 : :
3067 : 0 : eth_igb_interrupt_get_status(dev);
3068 : 0 : eth_igb_interrupt_action(dev, dev->intr_handle);
3069 : 0 : }
3070 : :
3071 : : static int
3072 : 0 : eth_igbvf_interrupt_get_status(struct rte_eth_dev *dev)
3073 : : {
3074 : : uint32_t eicr;
3075 : 0 : struct e1000_hw *hw =
3076 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3077 : : struct e1000_interrupt *intr =
3078 : : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3079 : :
3080 : 0 : igbvf_intr_disable(hw);
3081 : :
3082 : : /* read-on-clear nic registers here */
3083 : 0 : eicr = E1000_READ_REG(hw, E1000_EICR);
3084 : 0 : intr->flags = 0;
3085 : :
3086 [ # # ]: 0 : if (eicr == E1000_VTIVAR_MISC_MAILBOX)
3087 : 0 : intr->flags |= E1000_FLAG_MAILBOX;
3088 : :
3089 : 0 : return 0;
3090 : : }
3091 : :
3092 : 0 : void igbvf_mbx_process(struct rte_eth_dev *dev)
3093 : : {
3094 : 0 : struct e1000_hw *hw =
3095 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3096 : : struct e1000_mbx_info *mbx = &hw->mbx;
3097 : 0 : u32 in_msg = 0;
3098 : :
3099 : : /* peek the message first */
3100 : 0 : in_msg = E1000_READ_REG(hw, E1000_VMBMEM(0));
3101 : :
3102 : : /* PF reset VF event */
3103 [ # # ]: 0 : if (in_msg == E1000_PF_CONTROL_MSG) {
3104 : : /* dummy mbx read to ack pf */
3105 [ # # ]: 0 : if (mbx->ops.read(hw, &in_msg, 1, 0))
3106 : 0 : return;
3107 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
3108 : : NULL);
3109 : : }
3110 : : }
3111 : :
3112 : : static int
3113 : 0 : eth_igbvf_interrupt_action(struct rte_eth_dev *dev, struct rte_intr_handle *intr_handle)
3114 : : {
3115 : : struct e1000_interrupt *intr =
3116 : 0 : E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
3117 : :
3118 [ # # ]: 0 : if (intr->flags & E1000_FLAG_MAILBOX) {
3119 : 0 : igbvf_mbx_process(dev);
3120 : 0 : intr->flags &= ~E1000_FLAG_MAILBOX;
3121 : : }
3122 : :
3123 : : igbvf_intr_enable(dev);
3124 : 0 : rte_intr_ack(intr_handle);
3125 : :
3126 : 0 : return 0;
3127 : : }
3128 : :
3129 : : static void
3130 : 0 : eth_igbvf_interrupt_handler(void *param)
3131 : : {
3132 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
3133 : :
3134 : 0 : eth_igbvf_interrupt_get_status(dev);
3135 : 0 : eth_igbvf_interrupt_action(dev, dev->intr_handle);
3136 : 0 : }
3137 : :
3138 : : static int
3139 : 0 : eth_igb_led_on(struct rte_eth_dev *dev)
3140 : : {
3141 : : struct e1000_hw *hw;
3142 : :
3143 : : /*
3144 : : * This function calls into the base driver, which in turn will use
3145 : : * function pointers, which are not guaranteed to be valid in secondary
3146 : : * processes, so avoid using this function in secondary processes.
3147 : : */
3148 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3149 : : return -E_RTE_SECONDARY;
3150 : :
3151 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3152 [ # # ]: 0 : return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
3153 : : }
3154 : :
3155 : : static int
3156 : 0 : eth_igb_led_off(struct rte_eth_dev *dev)
3157 : : {
3158 : : struct e1000_hw *hw;
3159 : :
3160 : : /*
3161 : : * This function calls into the base driver, which in turn will use
3162 : : * function pointers, which are not guaranteed to be valid in secondary
3163 : : * processes, so avoid using this function in secondary processes.
3164 : : */
3165 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3166 : : return -E_RTE_SECONDARY;
3167 : :
3168 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3169 [ # # ]: 0 : return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
3170 : : }
3171 : :
3172 : : static int
3173 : 0 : eth_igb_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3174 : : {
3175 : : struct e1000_hw *hw;
3176 : : uint32_t ctrl;
3177 : : int tx_pause;
3178 : : int rx_pause;
3179 : :
3180 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3181 : 0 : fc_conf->pause_time = hw->fc.pause_time;
3182 : 0 : fc_conf->high_water = hw->fc.high_water;
3183 : 0 : fc_conf->low_water = hw->fc.low_water;
3184 : 0 : fc_conf->send_xon = hw->fc.send_xon;
3185 : 0 : fc_conf->autoneg = hw->mac.autoneg;
3186 : :
3187 : : /*
3188 : : * Return rx_pause and tx_pause status according to actual setting of
3189 : : * the TFCE and RFCE bits in the CTRL register.
3190 : : */
3191 : 0 : ctrl = E1000_READ_REG(hw, E1000_CTRL);
3192 [ # # ]: 0 : if (ctrl & E1000_CTRL_TFCE)
3193 : : tx_pause = 1;
3194 : : else
3195 : : tx_pause = 0;
3196 : :
3197 [ # # ]: 0 : if (ctrl & E1000_CTRL_RFCE)
3198 : : rx_pause = 1;
3199 : : else
3200 : : rx_pause = 0;
3201 : :
3202 [ # # ]: 0 : if (rx_pause && tx_pause)
3203 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
3204 [ # # ]: 0 : else if (rx_pause)
3205 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
3206 [ # # ]: 0 : else if (tx_pause)
3207 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
3208 : : else
3209 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
3210 : :
3211 : 0 : return 0;
3212 : : }
3213 : :
3214 : : static int
3215 : 0 : eth_igb_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3216 : : {
3217 : : struct e1000_hw *hw;
3218 : : int err;
3219 : 0 : enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
3220 : : e1000_fc_none,
3221 : : e1000_fc_rx_pause,
3222 : : e1000_fc_tx_pause,
3223 : : e1000_fc_full
3224 : : };
3225 : : uint32_t rx_buf_size;
3226 : : uint32_t max_high_water;
3227 : : uint32_t rctl;
3228 : : uint32_t ctrl;
3229 : :
3230 : : /*
3231 : : * This function calls into the base driver, which in turn will use
3232 : : * function pointers, which are not guaranteed to be valid in secondary
3233 : : * processes, so avoid using this function in secondary processes.
3234 : : */
3235 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3236 : : return -E_RTE_SECONDARY;
3237 : :
3238 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3239 [ # # ]: 0 : if (fc_conf->autoneg != hw->mac.autoneg)
3240 : : return -ENOTSUP;
3241 : 0 : rx_buf_size = igb_get_rx_buffer_size(hw);
3242 : 0 : PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
3243 : :
3244 : : /* At least reserve one Ethernet frame for watermark */
3245 : 0 : max_high_water = rx_buf_size - RTE_ETHER_MAX_LEN;
3246 [ # # ]: 0 : if ((fc_conf->high_water > max_high_water) ||
3247 [ # # ]: 0 : (fc_conf->high_water < fc_conf->low_water)) {
3248 : 0 : PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
3249 : 0 : PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
3250 : 0 : return -EINVAL;
3251 : : }
3252 : :
3253 : 0 : hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
3254 : 0 : hw->fc.pause_time = fc_conf->pause_time;
3255 : 0 : hw->fc.high_water = fc_conf->high_water;
3256 : 0 : hw->fc.low_water = fc_conf->low_water;
3257 : 0 : hw->fc.send_xon = fc_conf->send_xon;
3258 : :
3259 : 0 : err = e1000_setup_link_generic(hw);
3260 [ # # ]: 0 : if (err == E1000_SUCCESS) {
3261 : :
3262 : : /* check if we want to forward MAC frames - driver doesn't have native
3263 : : * capability to do that, so we'll write the registers ourselves */
3264 : :
3265 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
3266 : :
3267 : : /* set or clear MFLCN.PMCF bit depending on configuration */
3268 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0)
3269 : 0 : rctl |= E1000_RCTL_PMCF;
3270 : : else
3271 : 0 : rctl &= ~E1000_RCTL_PMCF;
3272 : :
3273 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
3274 : :
3275 : : /*
3276 : : * check if we want to change flow control mode - driver doesn't have native
3277 : : * capability to do that, so we'll write the registers ourselves
3278 : : */
3279 : 0 : ctrl = E1000_READ_REG(hw, E1000_CTRL);
3280 : :
3281 : : /*
3282 : : * set or clear E1000_CTRL_RFCE and E1000_CTRL_TFCE bits depending
3283 : : * on configuration
3284 : : */
3285 [ # # # # : 0 : switch (fc_conf->mode) {
# ]
3286 : 0 : case RTE_ETH_FC_NONE:
3287 : 0 : ctrl &= ~E1000_CTRL_RFCE & ~E1000_CTRL_TFCE;
3288 : 0 : break;
3289 : 0 : case RTE_ETH_FC_RX_PAUSE:
3290 : : ctrl |= E1000_CTRL_RFCE;
3291 : 0 : ctrl &= ~E1000_CTRL_TFCE;
3292 : 0 : break;
3293 : 0 : case RTE_ETH_FC_TX_PAUSE:
3294 : : ctrl |= E1000_CTRL_TFCE;
3295 : 0 : ctrl &= ~E1000_CTRL_RFCE;
3296 : 0 : break;
3297 : 0 : case RTE_ETH_FC_FULL:
3298 : 0 : ctrl |= E1000_CTRL_RFCE | E1000_CTRL_TFCE;
3299 : 0 : break;
3300 : 0 : default:
3301 : 0 : PMD_INIT_LOG(ERR, "invalid flow control mode");
3302 : 0 : return -EINVAL;
3303 : : }
3304 : :
3305 : 0 : E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
3306 : :
3307 : 0 : E1000_WRITE_FLUSH(hw);
3308 : :
3309 : 0 : return 0;
3310 : : }
3311 : :
3312 : 0 : PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
3313 : 0 : return -EIO;
3314 : : }
3315 : :
3316 : : #define E1000_RAH_POOLSEL_SHIFT (18)
3317 : : static int
3318 : 0 : eth_igb_rar_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
3319 : : uint32_t index, uint32_t pool)
3320 : : {
3321 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3322 : : uint32_t rah;
3323 : :
3324 : : /*
3325 : : * This function calls into the base driver, which in turn will use
3326 : : * function pointers, which are not guaranteed to be valid in secondary
3327 : : * processes, so avoid using this function in secondary processes.
3328 : : */
3329 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3330 : : return -E_RTE_SECONDARY;
3331 : :
3332 : 0 : e1000_rar_set(hw, mac_addr->addr_bytes, index);
3333 [ # # ]: 0 : rah = E1000_READ_REG(hw, E1000_RAH(index));
3334 : 0 : rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + pool));
3335 : 0 : E1000_WRITE_REG(hw, E1000_RAH(index), rah);
3336 : 0 : return 0;
3337 : : }
3338 : :
3339 : : static void
3340 : 0 : eth_igb_rar_clear(struct rte_eth_dev *dev, uint32_t index)
3341 : : {
3342 : : uint8_t addr[RTE_ETHER_ADDR_LEN];
3343 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3344 : :
3345 : : /*
3346 : : * This function calls into the base driver, which in turn will use
3347 : : * function pointers, which are not guaranteed to be valid in secondary
3348 : : * processes, so avoid using this function in secondary processes.
3349 : : */
3350 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3351 : 0 : return;
3352 : :
3353 : : memset(addr, 0, sizeof(addr));
3354 : :
3355 : 0 : e1000_rar_set(hw, addr, index);
3356 : : }
3357 : :
3358 : : static int
3359 : 0 : eth_igb_default_mac_addr_set(struct rte_eth_dev *dev,
3360 : : struct rte_ether_addr *addr)
3361 : : {
3362 : : /*
3363 : : * This function calls into the base driver, which in turn will use
3364 : : * function pointers, which are not guaranteed to be valid in secondary
3365 : : * processes, so avoid using this function in secondary processes.
3366 : : */
3367 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3368 : : return -E_RTE_SECONDARY;
3369 : :
3370 : 0 : eth_igb_rar_clear(dev, 0);
3371 : 0 : eth_igb_rar_set(dev, (void *)addr, 0, 0);
3372 : :
3373 : 0 : return 0;
3374 : : }
3375 : : /*
3376 : : * Virtual Function operations
3377 : : */
3378 : : static void
3379 : 0 : igbvf_intr_disable(struct e1000_hw *hw)
3380 : : {
3381 : 0 : PMD_INIT_FUNC_TRACE();
3382 : :
3383 : : /* Clear interrupt mask to stop from interrupts being generated */
3384 : 0 : E1000_WRITE_REG(hw, E1000_EIMC, 0xFFFF);
3385 : :
3386 : 0 : E1000_WRITE_FLUSH(hw);
3387 : 0 : }
3388 : :
3389 : : static void
3390 : 0 : igbvf_stop_adapter(struct rte_eth_dev *dev)
3391 : : {
3392 : : u32 reg_val;
3393 : : u16 i;
3394 : : struct rte_eth_dev_info dev_info;
3395 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3396 : : int ret;
3397 : :
3398 : : memset(&dev_info, 0, sizeof(dev_info));
3399 : 0 : ret = eth_igbvf_infos_get(dev, &dev_info);
3400 [ # # ]: 0 : if (ret != 0)
3401 : 0 : return;
3402 : :
3403 : : /* Clear interrupt mask to stop from interrupts being generated */
3404 : 0 : igbvf_intr_disable(hw);
3405 : :
3406 : : /* Clear any pending interrupts, flush previous writes */
3407 : 0 : E1000_READ_REG(hw, E1000_EICR);
3408 : :
3409 : : /* Disable the transmit unit. Each queue must be disabled. */
3410 [ # # ]: 0 : for (i = 0; i < dev_info.max_tx_queues; i++)
3411 [ # # ]: 0 : E1000_WRITE_REG(hw, E1000_TXDCTL(i), E1000_TXDCTL_SWFLSH);
3412 : :
3413 : : /* Disable the receive unit by stopping each queue */
3414 [ # # ]: 0 : for (i = 0; i < dev_info.max_rx_queues; i++) {
3415 [ # # ]: 0 : reg_val = E1000_READ_REG(hw, E1000_RXDCTL(i));
3416 : 0 : reg_val &= ~E1000_RXDCTL_QUEUE_ENABLE;
3417 : 0 : E1000_WRITE_REG(hw, E1000_RXDCTL(i), reg_val);
3418 [ # # ]: 0 : while (E1000_READ_REG(hw, E1000_RXDCTL(i)) & E1000_RXDCTL_QUEUE_ENABLE)
3419 : : ;
3420 : : }
3421 : :
3422 : : /* flush all queues disables */
3423 : 0 : E1000_WRITE_FLUSH(hw);
3424 : 0 : msec_delay(2);
3425 : : }
3426 : :
3427 : 0 : static int eth_igbvf_link_update(struct e1000_hw *hw)
3428 : : {
3429 : : struct e1000_mbx_info *mbx = &hw->mbx;
3430 : : struct e1000_mac_info *mac = &hw->mac;
3431 : : int ret_val = E1000_SUCCESS;
3432 : :
3433 : 0 : PMD_INIT_LOG(DEBUG, "e1000_check_for_link_vf");
3434 : :
3435 : : /*
3436 : : * We only want to run this if there has been a rst asserted.
3437 : : * in this case that could mean a link change, device reset,
3438 : : * or a virtual function reset
3439 : : */
3440 : :
3441 : : /* If we were hit with a reset or timeout drop the link */
3442 [ # # # # ]: 0 : if (!e1000_check_for_rst(hw, 0) || !mbx->timeout)
3443 : 0 : mac->get_link_status = TRUE;
3444 : :
3445 [ # # ]: 0 : if (!mac->get_link_status)
3446 : 0 : goto out;
3447 : :
3448 : : /* if link status is down no point in checking to see if pf is up */
3449 [ # # ]: 0 : if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
3450 : 0 : goto out;
3451 : :
3452 : : /* if we passed all the tests above then the link is up and we no
3453 : : * longer need to check for link */
3454 : 0 : mac->get_link_status = FALSE;
3455 : :
3456 : 0 : out:
3457 : 0 : return ret_val;
3458 : : }
3459 : :
3460 : :
3461 : : static int
3462 : 0 : igbvf_dev_configure(struct rte_eth_dev *dev)
3463 : : {
3464 : 0 : struct rte_eth_conf* conf = &dev->data->dev_conf;
3465 : :
3466 : 0 : PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
3467 : : dev->data->port_id);
3468 : :
3469 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
3470 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
3471 : :
3472 : : /*
3473 : : * VF has no ability to enable/disable HW CRC
3474 : : * Keep the persistent behavior the same as Host PF
3475 : : */
3476 : : #ifndef RTE_LIBRTE_E1000_PF_DISABLE_STRIP_CRC
3477 [ # # ]: 0 : if (conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
3478 : 0 : PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
3479 : 0 : conf->rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_KEEP_CRC;
3480 : : }
3481 : : #else
3482 : : if (!(conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)) {
3483 : : PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
3484 : : conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
3485 : : }
3486 : : #endif
3487 : :
3488 : 0 : return 0;
3489 : : }
3490 : :
3491 : : static int
3492 : 0 : igbvf_dev_start(struct rte_eth_dev *dev)
3493 : : {
3494 : 0 : struct e1000_hw *hw =
3495 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3496 : : struct e1000_adapter *adapter =
3497 : : E1000_DEV_PRIVATE(dev->data->dev_private);
3498 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3499 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
3500 : : int ret;
3501 : : uint32_t intr_vector = 0;
3502 : :
3503 : : /*
3504 : : * This function calls into the base driver, which in turn will use
3505 : : * function pointers, which are not guaranteed to be valid in secondary
3506 : : * processes, so avoid using this function in secondary processes.
3507 : : */
3508 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3509 : : return -E_RTE_SECONDARY;
3510 : :
3511 : 0 : PMD_INIT_FUNC_TRACE();
3512 : :
3513 : 0 : hw->mac.ops.reset_hw(hw);
3514 : 0 : adapter->stopped = 0;
3515 : :
3516 : : /* Set all vfta */
3517 : 0 : igbvf_set_vfta_all(dev,1);
3518 : :
3519 : 0 : eth_igbvf_tx_init(dev);
3520 : :
3521 : : /* This can fail when allocating mbufs for descriptor rings */
3522 : 0 : ret = eth_igbvf_rx_init(dev);
3523 [ # # ]: 0 : if (ret) {
3524 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
3525 : 0 : igb_dev_clear_queues(dev);
3526 : 0 : return ret;
3527 : : }
3528 : :
3529 : : /* check and configure queue intr-vector mapping */
3530 [ # # ]: 0 : if (rte_intr_cap_multiple(intr_handle) &&
3531 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq) {
3532 : 0 : intr_vector = dev->data->nb_rx_queues;
3533 : 0 : ret = rte_intr_efd_enable(intr_handle, intr_vector);
3534 [ # # ]: 0 : if (ret)
3535 : : return ret;
3536 : : }
3537 : :
3538 : : /* Allocate the vector list */
3539 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
3540 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
3541 : 0 : dev->data->nb_rx_queues)) {
3542 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
3543 : : " intr_vec", dev->data->nb_rx_queues);
3544 : 0 : return -ENOMEM;
3545 : : }
3546 : : }
3547 : :
3548 : : eth_igbvf_configure_msix_intr(dev);
3549 : :
3550 : : /* enable uio/vfio intr/eventfd mapping */
3551 : 0 : rte_intr_enable(intr_handle);
3552 : :
3553 : : /* resume enabled intr since hw reset */
3554 : : igbvf_intr_enable(dev);
3555 : :
3556 : 0 : return 0;
3557 : : }
3558 : :
3559 : : static int
3560 : 0 : igbvf_dev_stop(struct rte_eth_dev *dev)
3561 : : {
3562 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3563 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
3564 : 0 : struct e1000_adapter *adapter =
3565 : 0 : E1000_DEV_PRIVATE(dev->data->dev_private);
3566 : :
3567 : : /*
3568 : : * This function calls into the base driver, which in turn will use
3569 : : * function pointers, which are not guaranteed to be valid in secondary
3570 : : * processes, so avoid using this function in secondary processes.
3571 : : */
3572 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3573 : : return -E_RTE_SECONDARY;
3574 : :
3575 [ # # ]: 0 : if (adapter->stopped)
3576 : : return 0;
3577 : :
3578 : 0 : PMD_INIT_FUNC_TRACE();
3579 : :
3580 : 0 : igbvf_stop_adapter(dev);
3581 : :
3582 : : /*
3583 : : * Clear what we set, but we still keep shadow_vfta to
3584 : : * restore after device starts
3585 : : */
3586 : 0 : igbvf_set_vfta_all(dev,0);
3587 : :
3588 : 0 : igb_dev_clear_queues(dev);
3589 : :
3590 : : /* disable intr eventfd mapping */
3591 : 0 : rte_intr_disable(intr_handle);
3592 : :
3593 : : /* Clean datapath event and queue/vec mapping */
3594 : 0 : rte_intr_efd_disable(intr_handle);
3595 : :
3596 : : /* Clean vector list */
3597 : 0 : rte_intr_vec_list_free(intr_handle);
3598 : :
3599 : 0 : adapter->stopped = true;
3600 : 0 : dev->data->dev_started = 0;
3601 : :
3602 : 0 : return 0;
3603 : : }
3604 : :
3605 : : static int
3606 : 0 : igbvf_dev_close(struct rte_eth_dev *dev)
3607 : : {
3608 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3609 : : struct rte_ether_addr addr;
3610 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3611 : : int ret;
3612 : :
3613 : 0 : PMD_INIT_FUNC_TRACE();
3614 : :
3615 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3616 : : return 0;
3617 : :
3618 : 0 : e1000_reset_hw(hw);
3619 : :
3620 : 0 : ret = igbvf_dev_stop(dev);
3621 [ # # ]: 0 : if (ret != 0)
3622 : : return ret;
3623 : :
3624 : 0 : igb_dev_free_queues(dev);
3625 : :
3626 : : /**
3627 : : * reprogram the RAR with a zero mac address,
3628 : : * to ensure that the VF traffic goes to the PF
3629 : : * after stop, close and detach of the VF.
3630 : : **/
3631 : :
3632 : : memset(&addr, 0, sizeof(addr));
3633 : : igbvf_default_mac_addr_set(dev, &addr);
3634 : :
3635 : 0 : rte_intr_callback_unregister(pci_dev->intr_handle,
3636 : : eth_igbvf_interrupt_handler,
3637 : : (void *)dev);
3638 : :
3639 : 0 : return 0;
3640 : : }
3641 : :
3642 : : static int
3643 : 0 : igbvf_promiscuous_enable(struct rte_eth_dev *dev)
3644 : : {
3645 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3646 : :
3647 : : /*
3648 : : * This function calls into the base driver, which in turn will use
3649 : : * function pointers, which are not guaranteed to be valid in secondary
3650 : : * processes, so avoid using this function in secondary processes.
3651 : : */
3652 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3653 : : return -E_RTE_SECONDARY;
3654 : :
3655 : : /* Set both unicast and multicast promisc */
3656 : 0 : e1000_promisc_set_vf(hw, e1000_promisc_enabled);
3657 : :
3658 : 0 : return 0;
3659 : : }
3660 : :
3661 : : static int
3662 : 0 : igbvf_promiscuous_disable(struct rte_eth_dev *dev)
3663 : : {
3664 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3665 : :
3666 : : /*
3667 : : * This function calls into the base driver, which in turn will use
3668 : : * function pointers, which are not guaranteed to be valid in secondary
3669 : : * processes, so avoid using this function in secondary processes.
3670 : : */
3671 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3672 : : return -E_RTE_SECONDARY;
3673 : :
3674 : : /* If in allmulticast mode leave multicast promisc */
3675 [ # # ]: 0 : if (dev->data->all_multicast == 1)
3676 : 0 : e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3677 : : else
3678 : 0 : e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3679 : :
3680 : : return 0;
3681 : : }
3682 : :
3683 : : static int
3684 : 0 : igbvf_allmulticast_enable(struct rte_eth_dev *dev)
3685 : : {
3686 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3687 : :
3688 : : /*
3689 : : * This function calls into the base driver, which in turn will use
3690 : : * function pointers, which are not guaranteed to be valid in secondary
3691 : : * processes, so avoid using this function in secondary processes.
3692 : : */
3693 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3694 : : return -E_RTE_SECONDARY;
3695 : :
3696 : : /* In promiscuous mode multicast promisc already set */
3697 [ # # ]: 0 : if (dev->data->promiscuous == 0)
3698 : 0 : e1000_promisc_set_vf(hw, e1000_promisc_multicast);
3699 : :
3700 : : return 0;
3701 : : }
3702 : :
3703 : : static int
3704 : 0 : igbvf_allmulticast_disable(struct rte_eth_dev *dev)
3705 : : {
3706 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3707 : :
3708 : : /*
3709 : : * This function calls into the base driver, which in turn will use
3710 : : * function pointers, which are not guaranteed to be valid in secondary
3711 : : * processes, so avoid using this function in secondary processes.
3712 : : */
3713 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3714 : : return -E_RTE_SECONDARY;
3715 : :
3716 : : /* In promiscuous mode leave multicast promisc enabled */
3717 [ # # ]: 0 : if (dev->data->promiscuous == 0)
3718 : 0 : e1000_promisc_set_vf(hw, e1000_promisc_disabled);
3719 : :
3720 : : return 0;
3721 : : }
3722 : :
3723 : 0 : static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)
3724 : : {
3725 : : struct e1000_mbx_info *mbx = &hw->mbx;
3726 : : uint32_t msgbuf[2];
3727 : : s32 err;
3728 : :
3729 : : /* After set vlan, vlan strip will also be enabled in igb driver*/
3730 : 0 : msgbuf[0] = E1000_VF_SET_VLAN;
3731 : 0 : msgbuf[1] = vid;
3732 : : /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
3733 [ # # ]: 0 : if (on)
3734 : 0 : msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
3735 : :
3736 : 0 : err = mbx->ops.write_posted(hw, msgbuf, 2, 0);
3737 [ # # ]: 0 : if (err)
3738 : 0 : goto mbx_err;
3739 : :
3740 : 0 : err = mbx->ops.read_posted(hw, msgbuf, 2, 0);
3741 [ # # ]: 0 : if (err)
3742 : 0 : goto mbx_err;
3743 : :
3744 : 0 : msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
3745 [ # # ]: 0 : if (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK))
3746 : : err = -EINVAL;
3747 : :
3748 : 0 : mbx_err:
3749 : 0 : return err;
3750 : : }
3751 : :
3752 : 0 : static void igbvf_set_vfta_all(struct rte_eth_dev *dev, bool on)
3753 : : {
3754 : 0 : struct e1000_hw *hw =
3755 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3756 : : struct e1000_vfta * shadow_vfta =
3757 : : E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3758 : : int i = 0, j = 0, vfta = 0, mask = 1;
3759 : :
3760 [ # # ]: 0 : for (i = 0; i < IGB_VFTA_SIZE; i++){
3761 : 0 : vfta = shadow_vfta->vfta[i];
3762 [ # # ]: 0 : if(vfta){
3763 : : mask = 1;
3764 [ # # ]: 0 : for (j = 0; j < 32; j++){
3765 [ # # ]: 0 : if(vfta & mask)
3766 : 0 : igbvf_set_vfta(hw,
3767 : 0 : (uint16_t)((i<<5)+j), on);
3768 : 0 : mask<<=1;
3769 : : }
3770 : : }
3771 : : }
3772 : :
3773 : 0 : }
3774 : :
3775 : : static int
3776 : 0 : igbvf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3777 : : {
3778 : 0 : struct e1000_hw *hw =
3779 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3780 : : struct e1000_vfta * shadow_vfta =
3781 : : E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
3782 : : uint32_t vid_idx = 0;
3783 : : uint32_t vid_bit = 0;
3784 : : int ret = 0;
3785 : :
3786 : 0 : PMD_INIT_FUNC_TRACE();
3787 : :
3788 : : /*vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf*/
3789 : 0 : ret = igbvf_set_vfta(hw, vlan_id, !!on);
3790 [ # # ]: 0 : if(ret){
3791 : 0 : PMD_INIT_LOG(ERR, "Unable to set VF vlan");
3792 : 0 : return ret;
3793 : : }
3794 : 0 : vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
3795 : 0 : vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
3796 : :
3797 : : /*Save what we set and retore it after device reset*/
3798 [ # # ]: 0 : if (on)
3799 : 0 : shadow_vfta->vfta[vid_idx] |= vid_bit;
3800 : : else
3801 : 0 : shadow_vfta->vfta[vid_idx] &= ~vid_bit;
3802 : :
3803 : : return 0;
3804 : : }
3805 : :
3806 : : static int
3807 : 0 : igbvf_default_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
3808 : : {
3809 : 0 : struct e1000_hw *hw =
3810 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3811 : :
3812 : : /* index is not used by rar_set() */
3813 : 0 : hw->mac.ops.rar_set(hw, (void *)addr, 0);
3814 : 0 : return 0;
3815 : : }
3816 : :
3817 : :
3818 : : static int
3819 : 0 : eth_igb_rss_reta_update(struct rte_eth_dev *dev,
3820 : : struct rte_eth_rss_reta_entry64 *reta_conf,
3821 : : uint16_t reta_size)
3822 : : {
3823 : : uint8_t i, j, mask;
3824 : : uint32_t reta, r;
3825 : : uint16_t idx, shift;
3826 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3827 : :
3828 [ # # ]: 0 : if (reta_size != RTE_ETH_RSS_RETA_SIZE_128) {
3829 : 0 : PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3830 : : "(%d) doesn't match the number hardware can supported "
3831 : : "(%d)", reta_size, RTE_ETH_RSS_RETA_SIZE_128);
3832 : 0 : return -EINVAL;
3833 : : }
3834 : :
3835 [ # # ]: 0 : for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3836 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
3837 : : shift = i % RTE_ETH_RETA_GROUP_SIZE;
3838 : 0 : mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3839 : : IGB_4_BIT_MASK);
3840 [ # # ]: 0 : if (!mask)
3841 : 0 : continue;
3842 [ # # ]: 0 : if (mask == IGB_4_BIT_MASK)
3843 : : r = 0;
3844 : : else
3845 : 0 : r = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3846 [ # # ]: 0 : for (j = 0, reta = 0; j < IGB_4_BIT_WIDTH; j++) {
3847 [ # # ]: 0 : if (mask & (0x1 << j))
3848 : 0 : reta |= reta_conf[idx].reta[shift + j] <<
3849 : 0 : (CHAR_BIT * j);
3850 : : else
3851 : 0 : reta |= r & (IGB_8_BIT_MASK << (CHAR_BIT * j));
3852 : : }
3853 : 0 : E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta);
3854 : : }
3855 : :
3856 : : return 0;
3857 : : }
3858 : :
3859 : : static int
3860 : 0 : eth_igb_rss_reta_query(struct rte_eth_dev *dev,
3861 : : struct rte_eth_rss_reta_entry64 *reta_conf,
3862 : : uint16_t reta_size)
3863 : : {
3864 : : uint8_t i, j, mask;
3865 : : uint32_t reta;
3866 : : uint16_t idx, shift;
3867 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3868 : :
3869 [ # # ]: 0 : if (reta_size != RTE_ETH_RSS_RETA_SIZE_128) {
3870 : 0 : PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3871 : : "(%d) doesn't match the number hardware can supported "
3872 : : "(%d)", reta_size, RTE_ETH_RSS_RETA_SIZE_128);
3873 : 0 : return -EINVAL;
3874 : : }
3875 : :
3876 [ # # ]: 0 : for (i = 0; i < reta_size; i += IGB_4_BIT_WIDTH) {
3877 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
3878 : : shift = i % RTE_ETH_RETA_GROUP_SIZE;
3879 : 0 : mask = (uint8_t)((reta_conf[idx].mask >> shift) &
3880 : : IGB_4_BIT_MASK);
3881 [ # # ]: 0 : if (!mask)
3882 : 0 : continue;
3883 : 0 : reta = E1000_READ_REG(hw, E1000_RETA(i >> 2));
3884 [ # # ]: 0 : for (j = 0; j < IGB_4_BIT_WIDTH; j++) {
3885 [ # # ]: 0 : if (mask & (0x1 << j))
3886 : 0 : reta_conf[idx].reta[shift + j] =
3887 : 0 : ((reta >> (CHAR_BIT * j)) &
3888 : : IGB_8_BIT_MASK);
3889 : : }
3890 : : }
3891 : :
3892 : : return 0;
3893 : : }
3894 : :
3895 : : int
3896 : 0 : eth_igb_syn_filter_set(struct rte_eth_dev *dev,
3897 : : struct rte_eth_syn_filter *filter,
3898 : : bool add)
3899 : : {
3900 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3901 : : struct e1000_filter_info *filter_info =
3902 : : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
3903 : : uint32_t synqf, rfctl;
3904 : :
3905 [ # # ]: 0 : if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3906 : : return -EINVAL;
3907 : :
3908 : 0 : synqf = E1000_READ_REG(hw, E1000_SYNQF(0));
3909 : :
3910 [ # # ]: 0 : if (add) {
3911 [ # # ]: 0 : if (synqf & E1000_SYN_FILTER_ENABLE)
3912 : : return -EINVAL;
3913 : :
3914 : 0 : synqf = (uint32_t)(((filter->queue << E1000_SYN_FILTER_QUEUE_SHIFT) &
3915 : 0 : E1000_SYN_FILTER_QUEUE) | E1000_SYN_FILTER_ENABLE);
3916 : :
3917 : 0 : rfctl = E1000_READ_REG(hw, E1000_RFCTL);
3918 [ # # ]: 0 : if (filter->hig_pri)
3919 : 0 : rfctl |= E1000_RFCTL_SYNQFP;
3920 : : else
3921 : 0 : rfctl &= ~E1000_RFCTL_SYNQFP;
3922 : :
3923 : 0 : E1000_WRITE_REG(hw, E1000_RFCTL, rfctl);
3924 : : } else {
3925 [ # # ]: 0 : if (!(synqf & E1000_SYN_FILTER_ENABLE))
3926 : : return -ENOENT;
3927 : : synqf = 0;
3928 : : }
3929 : :
3930 : 0 : filter_info->syn_info = synqf;
3931 : 0 : E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
3932 : 0 : E1000_WRITE_FLUSH(hw);
3933 : 0 : return 0;
3934 : : }
3935 : :
3936 : : /* translate elements in struct rte_eth_ntuple_filter to struct e1000_2tuple_filter_info*/
3937 : : static inline int
3938 : 0 : ntuple_filter_to_2tuple(struct rte_eth_ntuple_filter *filter,
3939 : : struct e1000_2tuple_filter_info *filter_info)
3940 : : {
3941 [ # # ]: 0 : if (filter->queue >= IGB_MAX_RX_QUEUE_NUM)
3942 : : return -EINVAL;
3943 [ # # ]: 0 : if (filter->priority > E1000_2TUPLE_MAX_PRI)
3944 : : return -EINVAL; /* filter index is out of range. */
3945 [ # # ]: 0 : if (filter->tcp_flags > RTE_NTUPLE_TCP_FLAGS_MASK)
3946 : : return -EINVAL; /* flags is invalid. */
3947 : :
3948 [ # # # ]: 0 : switch (filter->dst_port_mask) {
3949 : 0 : case UINT16_MAX:
3950 : 0 : filter_info->dst_port_mask = 0;
3951 : 0 : filter_info->dst_port = filter->dst_port;
3952 : 0 : break;
3953 : 0 : case 0:
3954 : 0 : filter_info->dst_port_mask = 1;
3955 : 0 : break;
3956 : 0 : default:
3957 : 0 : PMD_DRV_LOG(ERR, "invalid dst_port mask.");
3958 : 0 : return -EINVAL;
3959 : : }
3960 : :
3961 [ # # # ]: 0 : switch (filter->proto_mask) {
3962 : 0 : case UINT8_MAX:
3963 : 0 : filter_info->proto_mask = 0;
3964 : 0 : filter_info->proto = filter->proto;
3965 : 0 : break;
3966 : 0 : case 0:
3967 : 0 : filter_info->proto_mask = 1;
3968 : 0 : break;
3969 : 0 : default:
3970 : 0 : PMD_DRV_LOG(ERR, "invalid protocol mask.");
3971 : 0 : return -EINVAL;
3972 : : }
3973 : :
3974 : 0 : filter_info->priority = (uint8_t)filter->priority;
3975 [ # # ]: 0 : if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
3976 : 0 : filter_info->tcp_flags = filter->tcp_flags;
3977 : : else
3978 : 0 : filter_info->tcp_flags = 0;
3979 : :
3980 : : return 0;
3981 : : }
3982 : :
3983 : : static inline struct e1000_2tuple_filter *
3984 : : igb_2tuple_filter_lookup(struct e1000_2tuple_filter_list *filter_list,
3985 : : struct e1000_2tuple_filter_info *key)
3986 : : {
3987 : : struct e1000_2tuple_filter *it;
3988 : :
3989 [ # # # # ]: 0 : TAILQ_FOREACH(it, filter_list, entries) {
3990 [ # # # # ]: 0 : if (memcmp(key, &it->filter_info,
3991 : : sizeof(struct e1000_2tuple_filter_info)) == 0) {
3992 : : return it;
3993 : : }
3994 : : }
3995 : : return NULL;
3996 : : }
3997 : :
3998 : : /* inject a igb 2tuple filter to HW */
3999 : : static inline void
4000 : 0 : igb_inject_2uple_filter(struct rte_eth_dev *dev,
4001 : : struct e1000_2tuple_filter *filter)
4002 : : {
4003 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4004 : : uint32_t ttqf = E1000_TTQF_DISABLE_MASK;
4005 : : uint32_t imir, imir_ext = E1000_IMIREXT_SIZE_BP;
4006 : : int i;
4007 : :
4008 : 0 : i = filter->index;
4009 : 0 : imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
4010 [ # # ]: 0 : if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
4011 : 0 : imir |= E1000_IMIR_PORT_BP;
4012 : : else
4013 : : imir &= ~E1000_IMIR_PORT_BP;
4014 : :
4015 : 0 : imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
4016 : :
4017 : : ttqf |= E1000_TTQF_QUEUE_ENABLE;
4018 : 0 : ttqf |= (uint32_t)(filter->queue << E1000_TTQF_QUEUE_SHIFT);
4019 : 0 : ttqf |= (uint32_t)(filter->filter_info.proto &
4020 : : E1000_TTQF_PROTOCOL_MASK);
4021 [ # # ]: 0 : if (filter->filter_info.proto_mask == 0)
4022 : 0 : ttqf &= ~E1000_TTQF_MASK_ENABLE;
4023 : :
4024 : : /* tcp flags bits setting. */
4025 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_NTUPLE_TCP_FLAGS_MASK) {
4026 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_URG_FLAG)
4027 : : imir_ext |= E1000_IMIREXT_CTRL_URG;
4028 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_ACK_FLAG)
4029 : 0 : imir_ext |= E1000_IMIREXT_CTRL_ACK;
4030 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_PSH_FLAG)
4031 : 0 : imir_ext |= E1000_IMIREXT_CTRL_PSH;
4032 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_RST_FLAG)
4033 : 0 : imir_ext |= E1000_IMIREXT_CTRL_RST;
4034 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_SYN_FLAG)
4035 : 0 : imir_ext |= E1000_IMIREXT_CTRL_SYN;
4036 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_FIN_FLAG)
4037 : 0 : imir_ext |= E1000_IMIREXT_CTRL_FIN;
4038 : : } else {
4039 : : imir_ext |= E1000_IMIREXT_CTRL_BP;
4040 : : }
4041 : 0 : E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
4042 : 0 : E1000_WRITE_REG(hw, E1000_TTQF(i), ttqf);
4043 : 0 : E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
4044 : 0 : }
4045 : :
4046 : : /*
4047 : : * igb_add_2tuple_filter - add a 2tuple filter
4048 : : *
4049 : : * @param
4050 : : * dev: Pointer to struct rte_eth_dev.
4051 : : * ntuple_filter: pointer to the filter that will be added.
4052 : : *
4053 : : * @return
4054 : : * - On success, zero.
4055 : : * - On failure, a negative value.
4056 : : */
4057 : : static int
4058 : 0 : igb_add_2tuple_filter(struct rte_eth_dev *dev,
4059 : : struct rte_eth_ntuple_filter *ntuple_filter)
4060 : : {
4061 : : struct e1000_filter_info *filter_info =
4062 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4063 : : struct e1000_2tuple_filter *filter;
4064 : : int i, ret;
4065 : :
4066 : 0 : filter = rte_zmalloc("e1000_2tuple_filter",
4067 : : sizeof(struct e1000_2tuple_filter), 0);
4068 [ # # ]: 0 : if (filter == NULL)
4069 : : return -ENOMEM;
4070 : :
4071 : 0 : ret = ntuple_filter_to_2tuple(ntuple_filter,
4072 : : &filter->filter_info);
4073 [ # # ]: 0 : if (ret < 0) {
4074 : 0 : rte_free(filter);
4075 : 0 : return ret;
4076 : : }
4077 [ # # ]: 0 : if (igb_2tuple_filter_lookup(&filter_info->twotuple_list,
4078 : : &filter->filter_info) != NULL) {
4079 : 0 : PMD_DRV_LOG(ERR, "filter exists.");
4080 : 0 : rte_free(filter);
4081 : 0 : return -EEXIST;
4082 : : }
4083 : 0 : filter->queue = ntuple_filter->queue;
4084 : :
4085 : : /*
4086 : : * look for an unused 2tuple filter index,
4087 : : * and insert the filter to list.
4088 : : */
4089 [ # # ]: 0 : for (i = 0; i < E1000_MAX_TTQF_FILTERS; i++) {
4090 [ # # ]: 0 : if (!(filter_info->twotuple_mask & (1 << i))) {
4091 : 0 : filter_info->twotuple_mask |= 1 << i;
4092 : 0 : filter->index = i;
4093 : 0 : TAILQ_INSERT_TAIL(&filter_info->twotuple_list,
4094 : : filter,
4095 : : entries);
4096 : 0 : break;
4097 : : }
4098 : : }
4099 [ # # ]: 0 : if (i >= E1000_MAX_TTQF_FILTERS) {
4100 : 0 : PMD_DRV_LOG(ERR, "2tuple filters are full.");
4101 : 0 : rte_free(filter);
4102 : 0 : return -ENOSYS;
4103 : : }
4104 : :
4105 : 0 : igb_inject_2uple_filter(dev, filter);
4106 : 0 : return 0;
4107 : : }
4108 : :
4109 : : int
4110 : 0 : igb_delete_2tuple_filter(struct rte_eth_dev *dev,
4111 : : struct e1000_2tuple_filter *filter)
4112 : : {
4113 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4114 : : struct e1000_filter_info *filter_info =
4115 : : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4116 : :
4117 : 0 : filter_info->twotuple_mask &= ~(1 << filter->index);
4118 [ # # ]: 0 : TAILQ_REMOVE(&filter_info->twotuple_list, filter, entries);
4119 : :
4120 : 0 : E1000_WRITE_REG(hw, E1000_TTQF(filter->index), E1000_TTQF_DISABLE_MASK);
4121 : 0 : E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
4122 : 0 : E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
4123 : 0 : rte_free(filter);
4124 : 0 : return 0;
4125 : : }
4126 : :
4127 : : /*
4128 : : * igb_remove_2tuple_filter - remove a 2tuple filter
4129 : : *
4130 : : * @param
4131 : : * dev: Pointer to struct rte_eth_dev.
4132 : : * ntuple_filter: pointer to the filter that will be removed.
4133 : : *
4134 : : * @return
4135 : : * - On success, zero.
4136 : : * - On failure, a negative value.
4137 : : */
4138 : : static int
4139 : 0 : igb_remove_2tuple_filter(struct rte_eth_dev *dev,
4140 : : struct rte_eth_ntuple_filter *ntuple_filter)
4141 : : {
4142 : : struct e1000_filter_info *filter_info =
4143 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4144 : : struct e1000_2tuple_filter_info filter_2tuple;
4145 : : struct e1000_2tuple_filter *filter;
4146 : : int ret;
4147 : :
4148 : : memset(&filter_2tuple, 0, sizeof(struct e1000_2tuple_filter_info));
4149 : 0 : ret = ntuple_filter_to_2tuple(ntuple_filter,
4150 : : &filter_2tuple);
4151 [ # # ]: 0 : if (ret < 0)
4152 : : return ret;
4153 : :
4154 : : filter = igb_2tuple_filter_lookup(&filter_info->twotuple_list,
4155 : : &filter_2tuple);
4156 [ # # ]: 0 : if (filter == NULL) {
4157 : 0 : PMD_DRV_LOG(ERR, "filter doesn't exist.");
4158 : 0 : return -ENOENT;
4159 : : }
4160 : :
4161 : 0 : igb_delete_2tuple_filter(dev, filter);
4162 : :
4163 : 0 : return 0;
4164 : : }
4165 : :
4166 : : /* inject a igb flex filter to HW */
4167 : : static inline void
4168 : 0 : igb_inject_flex_filter(struct rte_eth_dev *dev,
4169 : : struct e1000_flex_filter *filter)
4170 : : {
4171 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4172 : : uint32_t wufc, queueing;
4173 : : uint32_t reg_off;
4174 : : uint8_t i, j = 0;
4175 : :
4176 : 0 : wufc = E1000_READ_REG(hw, E1000_WUFC);
4177 [ # # ]: 0 : if (filter->index < E1000_MAX_FHFT)
4178 : 0 : reg_off = E1000_FHFT(filter->index);
4179 : : else
4180 : 0 : reg_off = E1000_FHFT_EXT(filter->index - E1000_MAX_FHFT);
4181 : :
4182 : 0 : E1000_WRITE_REG(hw, E1000_WUFC, wufc | E1000_WUFC_FLEX_HQ |
4183 : : (E1000_WUFC_FLX0 << filter->index));
4184 : 0 : queueing = filter->filter_info.len |
4185 : 0 : (filter->queue << E1000_FHFT_QUEUEING_QUEUE_SHIFT) |
4186 : 0 : (filter->filter_info.priority <<
4187 : : E1000_FHFT_QUEUEING_PRIO_SHIFT);
4188 : 0 : E1000_WRITE_REG(hw, reg_off + E1000_FHFT_QUEUEING_OFFSET,
4189 : : queueing);
4190 : :
4191 [ # # ]: 0 : for (i = 0; i < E1000_FLEX_FILTERS_MASK_SIZE; i++) {
4192 : 0 : E1000_WRITE_REG(hw, reg_off,
4193 : : filter->filter_info.dwords[j]);
4194 : 0 : reg_off += sizeof(uint32_t);
4195 : 0 : E1000_WRITE_REG(hw, reg_off,
4196 : : filter->filter_info.dwords[++j]);
4197 : 0 : reg_off += sizeof(uint32_t);
4198 : 0 : E1000_WRITE_REG(hw, reg_off,
4199 : : (uint32_t)filter->filter_info.mask[i]);
4200 : 0 : reg_off += sizeof(uint32_t) * 2;
4201 : 0 : ++j;
4202 : : }
4203 : 0 : }
4204 : :
4205 : : static inline struct e1000_flex_filter *
4206 : : eth_igb_flex_filter_lookup(struct e1000_flex_filter_list *filter_list,
4207 : : struct e1000_flex_filter_info *key)
4208 : : {
4209 : : struct e1000_flex_filter *it;
4210 : :
4211 [ # # ]: 0 : TAILQ_FOREACH(it, filter_list, entries) {
4212 [ # # ]: 0 : if (memcmp(key, &it->filter_info,
4213 : : sizeof(struct e1000_flex_filter_info)) == 0)
4214 : : return it;
4215 : : }
4216 : :
4217 : : return NULL;
4218 : : }
4219 : :
4220 : : /* remove a flex byte filter
4221 : : * @param
4222 : : * dev: Pointer to struct rte_eth_dev.
4223 : : * filter: the pointer of the filter will be removed.
4224 : : */
4225 : : void
4226 : 0 : igb_remove_flex_filter(struct rte_eth_dev *dev,
4227 : : struct e1000_flex_filter *filter)
4228 : : {
4229 : : struct e1000_filter_info *filter_info =
4230 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4231 : : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4232 : : uint32_t wufc, i;
4233 : : uint32_t reg_off;
4234 : :
4235 : 0 : wufc = E1000_READ_REG(hw, E1000_WUFC);
4236 [ # # ]: 0 : if (filter->index < E1000_MAX_FHFT)
4237 : 0 : reg_off = E1000_FHFT(filter->index);
4238 : : else
4239 : 0 : reg_off = E1000_FHFT_EXT(filter->index - E1000_MAX_FHFT);
4240 : :
4241 [ # # ]: 0 : for (i = 0; i < E1000_FHFT_SIZE_IN_DWD; i++)
4242 : 0 : E1000_WRITE_REG(hw, reg_off + i * sizeof(uint32_t), 0);
4243 : :
4244 : 0 : E1000_WRITE_REG(hw, E1000_WUFC, wufc &
4245 : : (~(E1000_WUFC_FLX0 << filter->index)));
4246 : :
4247 : 0 : filter_info->flex_mask &= ~(1 << filter->index);
4248 [ # # ]: 0 : TAILQ_REMOVE(&filter_info->flex_list, filter, entries);
4249 : 0 : rte_free(filter);
4250 : 0 : }
4251 : :
4252 : : int
4253 : 0 : eth_igb_add_del_flex_filter(struct rte_eth_dev *dev,
4254 : : struct igb_flex_filter *filter,
4255 : : bool add)
4256 : : {
4257 : : struct e1000_filter_info *filter_info =
4258 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4259 : : struct e1000_flex_filter *flex_filter, *it;
4260 : : uint32_t mask;
4261 : : uint8_t shift, i;
4262 : :
4263 : 0 : flex_filter = rte_zmalloc("e1000_flex_filter",
4264 : : sizeof(struct e1000_flex_filter), 0);
4265 [ # # ]: 0 : if (flex_filter == NULL)
4266 : : return -ENOMEM;
4267 : :
4268 : 0 : flex_filter->filter_info.len = filter->len;
4269 : 0 : flex_filter->filter_info.priority = filter->priority;
4270 : 0 : memcpy(flex_filter->filter_info.dwords, filter->bytes, filter->len);
4271 [ # # ]: 0 : for (i = 0; i < RTE_ALIGN(filter->len, CHAR_BIT) / CHAR_BIT; i++) {
4272 : : mask = 0;
4273 : : /* reverse bits in flex filter's mask*/
4274 [ # # ]: 0 : for (shift = 0; shift < CHAR_BIT; shift++) {
4275 [ # # ]: 0 : if (filter->mask[i] & (0x01 << shift))
4276 : 0 : mask |= (0x80 >> shift);
4277 : : }
4278 : 0 : flex_filter->filter_info.mask[i] = mask;
4279 : : }
4280 : :
4281 : 0 : it = eth_igb_flex_filter_lookup(&filter_info->flex_list,
4282 : : &flex_filter->filter_info);
4283 [ # # ]: 0 : if (it == NULL && !add) {
4284 : 0 : PMD_DRV_LOG(ERR, "filter doesn't exist.");
4285 : 0 : rte_free(flex_filter);
4286 : 0 : return -ENOENT;
4287 : : }
4288 [ # # ]: 0 : if (it != NULL && add) {
4289 : 0 : PMD_DRV_LOG(ERR, "filter exists.");
4290 : 0 : rte_free(flex_filter);
4291 : 0 : return -EEXIST;
4292 : : }
4293 : :
4294 [ # # ]: 0 : if (add) {
4295 : 0 : flex_filter->queue = filter->queue;
4296 : : /*
4297 : : * look for an unused flex filter index
4298 : : * and insert the filter into the list.
4299 : : */
4300 [ # # ]: 0 : for (i = 0; i < E1000_MAX_FLEX_FILTERS; i++) {
4301 [ # # ]: 0 : if (!(filter_info->flex_mask & (1 << i))) {
4302 : 0 : filter_info->flex_mask |= 1 << i;
4303 : 0 : flex_filter->index = i;
4304 : 0 : TAILQ_INSERT_TAIL(&filter_info->flex_list,
4305 : : flex_filter,
4306 : : entries);
4307 : 0 : break;
4308 : : }
4309 : : }
4310 [ # # ]: 0 : if (i >= E1000_MAX_FLEX_FILTERS) {
4311 : 0 : PMD_DRV_LOG(ERR, "flex filters are full.");
4312 : 0 : rte_free(flex_filter);
4313 : 0 : return -ENOSYS;
4314 : : }
4315 : :
4316 : 0 : igb_inject_flex_filter(dev, flex_filter);
4317 : :
4318 : : } else {
4319 : 0 : igb_remove_flex_filter(dev, it);
4320 : 0 : rte_free(flex_filter);
4321 : : }
4322 : :
4323 : : return 0;
4324 : : }
4325 : :
4326 : : /* translate elements in struct rte_eth_ntuple_filter to struct e1000_5tuple_filter_info*/
4327 : : static inline int
4328 : 0 : ntuple_filter_to_5tuple_82576(struct rte_eth_ntuple_filter *filter,
4329 : : struct e1000_5tuple_filter_info *filter_info)
4330 : : {
4331 [ # # ]: 0 : if (filter->queue >= IGB_MAX_RX_QUEUE_NUM_82576)
4332 : : return -EINVAL;
4333 [ # # ]: 0 : if (filter->priority > E1000_2TUPLE_MAX_PRI)
4334 : : return -EINVAL; /* filter index is out of range. */
4335 [ # # ]: 0 : if (filter->tcp_flags > RTE_NTUPLE_TCP_FLAGS_MASK)
4336 : : return -EINVAL; /* flags is invalid. */
4337 : :
4338 [ # # # ]: 0 : switch (filter->dst_ip_mask) {
4339 : 0 : case UINT32_MAX:
4340 : 0 : filter_info->dst_ip_mask = 0;
4341 : 0 : filter_info->dst_ip = filter->dst_ip;
4342 : 0 : break;
4343 : 0 : case 0:
4344 : 0 : filter_info->dst_ip_mask = 1;
4345 : 0 : break;
4346 : 0 : default:
4347 : 0 : PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
4348 : 0 : return -EINVAL;
4349 : : }
4350 : :
4351 [ # # # ]: 0 : switch (filter->src_ip_mask) {
4352 : 0 : case UINT32_MAX:
4353 : 0 : filter_info->src_ip_mask = 0;
4354 : 0 : filter_info->src_ip = filter->src_ip;
4355 : 0 : break;
4356 : 0 : case 0:
4357 : 0 : filter_info->src_ip_mask = 1;
4358 : 0 : break;
4359 : 0 : default:
4360 : 0 : PMD_DRV_LOG(ERR, "invalid src_ip mask.");
4361 : 0 : return -EINVAL;
4362 : : }
4363 : :
4364 [ # # # ]: 0 : switch (filter->dst_port_mask) {
4365 : 0 : case UINT16_MAX:
4366 : 0 : filter_info->dst_port_mask = 0;
4367 : 0 : filter_info->dst_port = filter->dst_port;
4368 : 0 : break;
4369 : 0 : case 0:
4370 : 0 : filter_info->dst_port_mask = 1;
4371 : 0 : break;
4372 : 0 : default:
4373 : 0 : PMD_DRV_LOG(ERR, "invalid dst_port mask.");
4374 : 0 : return -EINVAL;
4375 : : }
4376 : :
4377 [ # # # ]: 0 : switch (filter->src_port_mask) {
4378 : 0 : case UINT16_MAX:
4379 : 0 : filter_info->src_port_mask = 0;
4380 : 0 : filter_info->src_port = filter->src_port;
4381 : 0 : break;
4382 : 0 : case 0:
4383 : 0 : filter_info->src_port_mask = 1;
4384 : 0 : break;
4385 : 0 : default:
4386 : 0 : PMD_DRV_LOG(ERR, "invalid src_port mask.");
4387 : 0 : return -EINVAL;
4388 : : }
4389 : :
4390 [ # # # ]: 0 : switch (filter->proto_mask) {
4391 : 0 : case UINT8_MAX:
4392 : 0 : filter_info->proto_mask = 0;
4393 : 0 : filter_info->proto = filter->proto;
4394 : 0 : break;
4395 : 0 : case 0:
4396 : 0 : filter_info->proto_mask = 1;
4397 : 0 : break;
4398 : 0 : default:
4399 : 0 : PMD_DRV_LOG(ERR, "invalid protocol mask.");
4400 : 0 : return -EINVAL;
4401 : : }
4402 : :
4403 : 0 : filter_info->priority = (uint8_t)filter->priority;
4404 [ # # ]: 0 : if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG)
4405 : 0 : filter_info->tcp_flags = filter->tcp_flags;
4406 : : else
4407 : 0 : filter_info->tcp_flags = 0;
4408 : :
4409 : : return 0;
4410 : : }
4411 : :
4412 : : static inline struct e1000_5tuple_filter *
4413 : : igb_5tuple_filter_lookup_82576(struct e1000_5tuple_filter_list *filter_list,
4414 : : struct e1000_5tuple_filter_info *key)
4415 : : {
4416 : : struct e1000_5tuple_filter *it;
4417 : :
4418 [ # # # # ]: 0 : TAILQ_FOREACH(it, filter_list, entries) {
4419 [ # # # # ]: 0 : if (memcmp(key, &it->filter_info,
4420 : : sizeof(struct e1000_5tuple_filter_info)) == 0) {
4421 : : return it;
4422 : : }
4423 : : }
4424 : : return NULL;
4425 : : }
4426 : :
4427 : : /* inject a igb 5-tuple filter to HW */
4428 : : static inline void
4429 : 0 : igb_inject_5tuple_filter_82576(struct rte_eth_dev *dev,
4430 : : struct e1000_5tuple_filter *filter)
4431 : : {
4432 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4433 : : uint32_t ftqf = E1000_FTQF_VF_BP | E1000_FTQF_MASK;
4434 : : uint32_t spqf, imir, imir_ext = E1000_IMIREXT_SIZE_BP;
4435 : : uint8_t i;
4436 : :
4437 : 0 : i = filter->index;
4438 : 0 : ftqf |= filter->filter_info.proto & E1000_FTQF_PROTOCOL_MASK;
4439 [ # # ]: 0 : if (filter->filter_info.src_ip_mask == 0) /* 0b means compare. */
4440 : 0 : ftqf &= ~E1000_FTQF_MASK_SOURCE_ADDR_BP;
4441 [ # # ]: 0 : if (filter->filter_info.dst_ip_mask == 0)
4442 : 0 : ftqf &= ~E1000_FTQF_MASK_DEST_ADDR_BP;
4443 [ # # ]: 0 : if (filter->filter_info.src_port_mask == 0)
4444 : 0 : ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
4445 [ # # ]: 0 : if (filter->filter_info.proto_mask == 0)
4446 : 0 : ftqf &= ~E1000_FTQF_MASK_PROTO_BP;
4447 : 0 : ftqf |= (filter->queue << E1000_FTQF_QUEUE_SHIFT) &
4448 : : E1000_FTQF_QUEUE_MASK;
4449 : 0 : ftqf |= E1000_FTQF_QUEUE_ENABLE;
4450 : 0 : E1000_WRITE_REG(hw, E1000_FTQF(i), ftqf);
4451 : 0 : E1000_WRITE_REG(hw, E1000_DAQF(i), filter->filter_info.dst_ip);
4452 : 0 : E1000_WRITE_REG(hw, E1000_SAQF(i), filter->filter_info.src_ip);
4453 : :
4454 : 0 : spqf = filter->filter_info.src_port & E1000_SPQF_SRCPORT;
4455 : 0 : E1000_WRITE_REG(hw, E1000_SPQF(i), spqf);
4456 : :
4457 : 0 : imir = (uint32_t)(filter->filter_info.dst_port & E1000_IMIR_DSTPORT);
4458 [ # # ]: 0 : if (filter->filter_info.dst_port_mask == 1) /* 1b means not compare. */
4459 : 0 : imir |= E1000_IMIR_PORT_BP;
4460 : : else
4461 : : imir &= ~E1000_IMIR_PORT_BP;
4462 : 0 : imir |= filter->filter_info.priority << E1000_IMIR_PRIORITY_SHIFT;
4463 : :
4464 : : /* tcp flags bits setting. */
4465 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_NTUPLE_TCP_FLAGS_MASK) {
4466 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_URG_FLAG)
4467 : : imir_ext |= E1000_IMIREXT_CTRL_URG;
4468 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_ACK_FLAG)
4469 : 0 : imir_ext |= E1000_IMIREXT_CTRL_ACK;
4470 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_PSH_FLAG)
4471 : 0 : imir_ext |= E1000_IMIREXT_CTRL_PSH;
4472 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_RST_FLAG)
4473 : 0 : imir_ext |= E1000_IMIREXT_CTRL_RST;
4474 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_SYN_FLAG)
4475 : 0 : imir_ext |= E1000_IMIREXT_CTRL_SYN;
4476 [ # # ]: 0 : if (filter->filter_info.tcp_flags & RTE_TCP_FIN_FLAG)
4477 : 0 : imir_ext |= E1000_IMIREXT_CTRL_FIN;
4478 : : } else {
4479 : : imir_ext |= E1000_IMIREXT_CTRL_BP;
4480 : : }
4481 : 0 : E1000_WRITE_REG(hw, E1000_IMIR(i), imir);
4482 : 0 : E1000_WRITE_REG(hw, E1000_IMIREXT(i), imir_ext);
4483 : 0 : }
4484 : :
4485 : : /*
4486 : : * igb_add_5tuple_filter_82576 - add a 5tuple filter
4487 : : *
4488 : : * @param
4489 : : * dev: Pointer to struct rte_eth_dev.
4490 : : * ntuple_filter: pointer to the filter that will be added.
4491 : : *
4492 : : * @return
4493 : : * - On success, zero.
4494 : : * - On failure, a negative value.
4495 : : */
4496 : : static int
4497 : 0 : igb_add_5tuple_filter_82576(struct rte_eth_dev *dev,
4498 : : struct rte_eth_ntuple_filter *ntuple_filter)
4499 : : {
4500 : : struct e1000_filter_info *filter_info =
4501 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4502 : : struct e1000_5tuple_filter *filter;
4503 : : uint8_t i;
4504 : : int ret;
4505 : :
4506 : 0 : filter = rte_zmalloc("e1000_5tuple_filter",
4507 : : sizeof(struct e1000_5tuple_filter), 0);
4508 [ # # ]: 0 : if (filter == NULL)
4509 : : return -ENOMEM;
4510 : :
4511 : 0 : ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4512 : : &filter->filter_info);
4513 [ # # ]: 0 : if (ret < 0) {
4514 : 0 : rte_free(filter);
4515 : 0 : return ret;
4516 : : }
4517 : :
4518 [ # # ]: 0 : if (igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4519 : : &filter->filter_info) != NULL) {
4520 : 0 : PMD_DRV_LOG(ERR, "filter exists.");
4521 : 0 : rte_free(filter);
4522 : 0 : return -EEXIST;
4523 : : }
4524 : 0 : filter->queue = ntuple_filter->queue;
4525 : :
4526 : : /*
4527 : : * look for an unused 5tuple filter index,
4528 : : * and insert the filter to list.
4529 : : */
4530 [ # # ]: 0 : for (i = 0; i < E1000_MAX_FTQF_FILTERS; i++) {
4531 [ # # ]: 0 : if (!(filter_info->fivetuple_mask & (1 << i))) {
4532 : 0 : filter_info->fivetuple_mask |= 1 << i;
4533 : 0 : filter->index = i;
4534 : 0 : TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
4535 : : filter,
4536 : : entries);
4537 : 0 : break;
4538 : : }
4539 : : }
4540 [ # # ]: 0 : if (i >= E1000_MAX_FTQF_FILTERS) {
4541 : 0 : PMD_DRV_LOG(ERR, "5tuple filters are full.");
4542 : 0 : rte_free(filter);
4543 : 0 : return -ENOSYS;
4544 : : }
4545 : :
4546 : 0 : igb_inject_5tuple_filter_82576(dev, filter);
4547 : 0 : return 0;
4548 : : }
4549 : :
4550 : : int
4551 : 0 : igb_delete_5tuple_filter_82576(struct rte_eth_dev *dev,
4552 : : struct e1000_5tuple_filter *filter)
4553 : : {
4554 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4555 : : struct e1000_filter_info *filter_info =
4556 : : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4557 : :
4558 : 0 : filter_info->fivetuple_mask &= ~(1 << filter->index);
4559 [ # # ]: 0 : TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
4560 : :
4561 : 0 : E1000_WRITE_REG(hw, E1000_FTQF(filter->index),
4562 : : E1000_FTQF_VF_BP | E1000_FTQF_MASK);
4563 : 0 : E1000_WRITE_REG(hw, E1000_DAQF(filter->index), 0);
4564 : 0 : E1000_WRITE_REG(hw, E1000_SAQF(filter->index), 0);
4565 : 0 : E1000_WRITE_REG(hw, E1000_SPQF(filter->index), 0);
4566 : 0 : E1000_WRITE_REG(hw, E1000_IMIR(filter->index), 0);
4567 : 0 : E1000_WRITE_REG(hw, E1000_IMIREXT(filter->index), 0);
4568 : 0 : rte_free(filter);
4569 : 0 : return 0;
4570 : : }
4571 : :
4572 : : /*
4573 : : * igb_remove_5tuple_filter_82576 - remove a 5tuple filter
4574 : : *
4575 : : * @param
4576 : : * dev: Pointer to struct rte_eth_dev.
4577 : : * ntuple_filter: pointer to the filter that will be removed.
4578 : : *
4579 : : * @return
4580 : : * - On success, zero.
4581 : : * - On failure, a negative value.
4582 : : */
4583 : : static int
4584 : 0 : igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
4585 : : struct rte_eth_ntuple_filter *ntuple_filter)
4586 : : {
4587 : : struct e1000_filter_info *filter_info =
4588 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4589 : : struct e1000_5tuple_filter_info filter_5tuple;
4590 : : struct e1000_5tuple_filter *filter;
4591 : : int ret;
4592 : :
4593 : : memset(&filter_5tuple, 0, sizeof(struct e1000_5tuple_filter_info));
4594 : 0 : ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
4595 : : &filter_5tuple);
4596 [ # # ]: 0 : if (ret < 0)
4597 : : return ret;
4598 : :
4599 : : filter = igb_5tuple_filter_lookup_82576(&filter_info->fivetuple_list,
4600 : : &filter_5tuple);
4601 [ # # ]: 0 : if (filter == NULL) {
4602 : 0 : PMD_DRV_LOG(ERR, "filter doesn't exist.");
4603 : 0 : return -ENOENT;
4604 : : }
4605 : :
4606 : 0 : igb_delete_5tuple_filter_82576(dev, filter);
4607 : :
4608 : 0 : return 0;
4609 : : }
4610 : :
4611 : : static int
4612 : 0 : eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
4613 : : {
4614 : : uint32_t rctl;
4615 : : struct e1000_hw *hw;
4616 : 0 : uint32_t frame_size = mtu + E1000_ETH_OVERHEAD;
4617 : :
4618 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4619 : :
4620 : : #ifdef RTE_LIBRTE_82571_SUPPORT
4621 : : /* XXX: not bigger than max_rx_pktlen */
4622 : : if (hw->mac.type == e1000_82571)
4623 : : return -ENOTSUP;
4624 : : #endif
4625 : : /*
4626 : : * If device is started, refuse mtu that requires the support of
4627 : : * scattered packets when this feature has not been enabled before.
4628 : : */
4629 [ # # ]: 0 : if (dev->data->dev_started && !dev->data->scattered_rx &&
4630 [ # # ]: 0 : frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
4631 : 0 : PMD_INIT_LOG(ERR, "Stop port first.");
4632 : 0 : return -EINVAL;
4633 : : }
4634 : :
4635 : 0 : rctl = E1000_READ_REG(hw, E1000_RCTL);
4636 : :
4637 : : /* switch to jumbo mode if needed */
4638 [ # # ]: 0 : if (mtu > RTE_ETHER_MTU)
4639 : 0 : rctl |= E1000_RCTL_LPE;
4640 : : else
4641 : 0 : rctl &= ~E1000_RCTL_LPE;
4642 : 0 : E1000_WRITE_REG(hw, E1000_RCTL, rctl);
4643 : :
4644 : 0 : E1000_WRITE_REG(hw, E1000_RLPML, frame_size);
4645 : :
4646 : 0 : return 0;
4647 : : }
4648 : :
4649 : : /*
4650 : : * igb_add_del_ntuple_filter - add or delete a ntuple filter
4651 : : *
4652 : : * @param
4653 : : * dev: Pointer to struct rte_eth_dev.
4654 : : * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
4655 : : * add: if true, add filter, if false, remove filter
4656 : : *
4657 : : * @return
4658 : : * - On success, zero.
4659 : : * - On failure, a negative value.
4660 : : */
4661 : : int
4662 : 0 : igb_add_del_ntuple_filter(struct rte_eth_dev *dev,
4663 : : struct rte_eth_ntuple_filter *ntuple_filter,
4664 : : bool add)
4665 : : {
4666 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4667 : : int ret;
4668 : :
4669 [ # # # ]: 0 : switch (ntuple_filter->flags) {
4670 : 0 : case RTE_5TUPLE_FLAGS:
4671 : : case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4672 [ # # ]: 0 : if (hw->mac.type != e1000_82576)
4673 : : return -ENOTSUP;
4674 [ # # ]: 0 : if (add)
4675 : 0 : ret = igb_add_5tuple_filter_82576(dev,
4676 : : ntuple_filter);
4677 : : else
4678 : 0 : ret = igb_remove_5tuple_filter_82576(dev,
4679 : : ntuple_filter);
4680 : : break;
4681 : 0 : case RTE_2TUPLE_FLAGS:
4682 : : case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
4683 [ # # ]: 0 : if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350 &&
4684 [ # # ]: 0 : hw->mac.type != e1000_i210 &&
4685 : : hw->mac.type != e1000_i211)
4686 : : return -ENOTSUP;
4687 [ # # ]: 0 : if (add)
4688 : 0 : ret = igb_add_2tuple_filter(dev, ntuple_filter);
4689 : : else
4690 : 0 : ret = igb_remove_2tuple_filter(dev, ntuple_filter);
4691 : : break;
4692 : : default:
4693 : : ret = -EINVAL;
4694 : : break;
4695 : : }
4696 : :
4697 : : return ret;
4698 : : }
4699 : :
4700 : : static inline int
4701 : : igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
4702 : : uint16_t ethertype)
4703 : : {
4704 : : int i;
4705 : :
4706 [ # # ]: 0 : for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4707 [ # # ]: 0 : if (filter_info->ethertype_filters[i].ethertype == ethertype &&
4708 [ # # ]: 0 : (filter_info->ethertype_mask & (1 << i)))
4709 : : return i;
4710 : : }
4711 : : return -1;
4712 : : }
4713 : :
4714 : : static inline int
4715 : : igb_ethertype_filter_insert(struct e1000_filter_info *filter_info,
4716 : : uint16_t ethertype, uint32_t etqf)
4717 : : {
4718 : : int i;
4719 : :
4720 [ # # ]: 0 : for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
4721 [ # # ]: 0 : if (!(filter_info->ethertype_mask & (1 << i))) {
4722 : 0 : filter_info->ethertype_mask |= 1 << i;
4723 : 0 : filter_info->ethertype_filters[i].ethertype = ethertype;
4724 : 0 : filter_info->ethertype_filters[i].etqf = etqf;
4725 : 0 : return i;
4726 : : }
4727 : : }
4728 : : return -1;
4729 : : }
4730 : :
4731 : : int
4732 : 0 : igb_ethertype_filter_remove(struct e1000_filter_info *filter_info,
4733 : : uint8_t idx)
4734 : : {
4735 [ # # ]: 0 : if (idx >= E1000_MAX_ETQF_FILTERS)
4736 : : return -1;
4737 : 0 : filter_info->ethertype_mask &= ~(1 << idx);
4738 : 0 : filter_info->ethertype_filters[idx].ethertype = 0;
4739 : 0 : filter_info->ethertype_filters[idx].etqf = 0;
4740 : 0 : return idx;
4741 : : }
4742 : :
4743 : :
4744 : : int
4745 : 0 : igb_add_del_ethertype_filter(struct rte_eth_dev *dev,
4746 : : struct rte_eth_ethertype_filter *filter,
4747 : : bool add)
4748 : : {
4749 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4750 : 0 : struct e1000_filter_info *filter_info =
4751 : : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
4752 : : uint32_t etqf = 0;
4753 : : int ret;
4754 : :
4755 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
4756 : : filter->ether_type == RTE_ETHER_TYPE_IPV6) {
4757 : 0 : PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
4758 : : " ethertype filter.", filter->ether_type);
4759 : 0 : return -EINVAL;
4760 : : }
4761 : :
4762 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
4763 : 0 : PMD_DRV_LOG(ERR, "mac compare is unsupported.");
4764 : 0 : return -EINVAL;
4765 : : }
4766 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
4767 : 0 : PMD_DRV_LOG(ERR, "drop option is unsupported.");
4768 : 0 : return -EINVAL;
4769 : : }
4770 : :
4771 : 0 : ret = igb_ethertype_filter_lookup(filter_info, filter->ether_type);
4772 [ # # ]: 0 : if (ret >= 0 && add) {
4773 : 0 : PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
4774 : : filter->ether_type);
4775 : 0 : return -EEXIST;
4776 : : }
4777 [ # # ]: 0 : if (ret < 0 && !add) {
4778 : 0 : PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
4779 : : filter->ether_type);
4780 : 0 : return -ENOENT;
4781 : : }
4782 : :
4783 [ # # ]: 0 : if (add) {
4784 : : etqf |= E1000_ETQF_FILTER_ENABLE | E1000_ETQF_QUEUE_ENABLE;
4785 : 0 : etqf |= (uint32_t)(filter->ether_type & E1000_ETQF_ETHERTYPE);
4786 : 0 : etqf |= filter->queue << E1000_ETQF_QUEUE_SHIFT;
4787 : : ret = igb_ethertype_filter_insert(filter_info,
4788 : : filter->ether_type, etqf);
4789 [ # # ]: 0 : if (ret < 0) {
4790 : 0 : PMD_DRV_LOG(ERR, "ethertype filters are full.");
4791 : 0 : return -ENOSYS;
4792 : : }
4793 : : } else {
4794 : 0 : ret = igb_ethertype_filter_remove(filter_info, (uint8_t)ret);
4795 [ # # ]: 0 : if (ret < 0)
4796 : : return -ENOSYS;
4797 : : }
4798 : 0 : E1000_WRITE_REG(hw, E1000_ETQF(ret), etqf);
4799 : 0 : E1000_WRITE_FLUSH(hw);
4800 : :
4801 : 0 : return 0;
4802 : : }
4803 : :
4804 : : static int
4805 : 0 : eth_igb_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
4806 : : const struct rte_flow_ops **ops)
4807 : : {
4808 : 0 : *ops = &igb_flow_ops;
4809 : 0 : return 0;
4810 : : }
4811 : :
4812 : : static int
4813 : 0 : eth_igb_set_mc_addr_list(struct rte_eth_dev *dev,
4814 : : struct rte_ether_addr *mc_addr_set,
4815 : : uint32_t nb_mc_addr)
4816 : : {
4817 : : struct e1000_hw *hw;
4818 : :
4819 : : /*
4820 : : * This function calls into the base driver, which in turn will use
4821 : : * function pointers, which are not guaranteed to be valid in secondary
4822 : : * processes, so avoid using this function in secondary processes.
4823 : : */
4824 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
4825 : : return -E_RTE_SECONDARY;
4826 : :
4827 : 0 : hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4828 : 0 : e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
4829 : 0 : return 0;
4830 : : }
4831 : :
4832 : : static uint64_t
4833 : 0 : igb_read_systime_cyclecounter(struct rte_eth_dev *dev)
4834 : : {
4835 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4836 : : uint64_t systime_cycles;
4837 : :
4838 [ # # # ]: 0 : switch (hw->mac.type) {
4839 : 0 : case e1000_i210:
4840 : : case e1000_i211:
4841 : : /*
4842 : : * Need to read System Time Residue Register to be able
4843 : : * to read the other two registers.
4844 : : */
4845 : 0 : E1000_READ_REG(hw, E1000_SYSTIMR);
4846 : : /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
4847 : 0 : systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4848 : 0 : systime_cycles += (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4849 : 0 : * NSEC_PER_SEC;
4850 : 0 : break;
4851 : 0 : case e1000_82580:
4852 : : case e1000_i350:
4853 : : case e1000_i354:
4854 : : /*
4855 : : * Need to read System Time Residue Register to be able
4856 : : * to read the other two registers.
4857 : : */
4858 : 0 : E1000_READ_REG(hw, E1000_SYSTIMR);
4859 : 0 : systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4860 : : /* Only the 8 LSB are valid. */
4861 : 0 : systime_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_SYSTIMH)
4862 : 0 : & 0xff) << 32;
4863 : 0 : break;
4864 : 0 : default:
4865 : 0 : systime_cycles = (uint64_t)E1000_READ_REG(hw, E1000_SYSTIML);
4866 : 0 : systime_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_SYSTIMH)
4867 : 0 : << 32;
4868 : 0 : break;
4869 : : }
4870 : :
4871 : 0 : return systime_cycles;
4872 : : }
4873 : :
4874 : : static uint64_t
4875 : 0 : igb_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4876 : : {
4877 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4878 : : uint64_t rx_tstamp_cycles;
4879 : :
4880 [ # # # ]: 0 : switch (hw->mac.type) {
4881 : 0 : case e1000_i210:
4882 : : case e1000_i211:
4883 : : /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4884 : 0 : rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4885 : 0 : rx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4886 : 0 : * NSEC_PER_SEC;
4887 : 0 : break;
4888 : 0 : case e1000_82580:
4889 : : case e1000_i350:
4890 : : case e1000_i354:
4891 : 0 : rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4892 : : /* Only the 8 LSB are valid. */
4893 : 0 : rx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_RXSTMPH)
4894 : 0 : & 0xff) << 32;
4895 : 0 : break;
4896 : 0 : default:
4897 : 0 : rx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPL);
4898 : 0 : rx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_RXSTMPH)
4899 : 0 : << 32;
4900 : 0 : break;
4901 : : }
4902 : :
4903 : 0 : return rx_tstamp_cycles;
4904 : : }
4905 : :
4906 : : static uint64_t
4907 : 0 : igb_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
4908 : : {
4909 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4910 : : uint64_t tx_tstamp_cycles;
4911 : :
4912 [ # # # ]: 0 : switch (hw->mac.type) {
4913 : 0 : case e1000_i210:
4914 : : case e1000_i211:
4915 : : /* RXSTMPL stores ns and RXSTMPH stores seconds. */
4916 : 0 : tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4917 : 0 : tx_tstamp_cycles += (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4918 : 0 : * NSEC_PER_SEC;
4919 : 0 : break;
4920 : 0 : case e1000_82580:
4921 : : case e1000_i350:
4922 : : case e1000_i354:
4923 : 0 : tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4924 : : /* Only the 8 LSB are valid. */
4925 : 0 : tx_tstamp_cycles |= (uint64_t)(E1000_READ_REG(hw, E1000_TXSTMPH)
4926 : 0 : & 0xff) << 32;
4927 : 0 : break;
4928 : 0 : default:
4929 : 0 : tx_tstamp_cycles = (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPL);
4930 : 0 : tx_tstamp_cycles |= (uint64_t)E1000_READ_REG(hw, E1000_TXSTMPH)
4931 : 0 : << 32;
4932 : 0 : break;
4933 : : }
4934 : :
4935 : 0 : return tx_tstamp_cycles;
4936 : : }
4937 : :
4938 : : static void
4939 : 0 : igb_start_timecounters(struct rte_eth_dev *dev)
4940 : : {
4941 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4942 : : struct e1000_adapter *adapter = dev->data->dev_private;
4943 : : uint32_t incval = 1;
4944 : : uint32_t shift = 0;
4945 : : uint64_t mask = E1000_CYCLECOUNTER_MASK;
4946 : :
4947 [ # # # # ]: 0 : switch (hw->mac.type) {
4948 : 0 : case e1000_82580:
4949 : : case e1000_i350:
4950 : : case e1000_i354:
4951 : : /* 32 LSB bits + 8 MSB bits = 40 bits */
4952 : : mask = (1ULL << 40) - 1;
4953 : : /* fall-through */
4954 : 0 : case e1000_i210:
4955 : : case e1000_i211:
4956 : : /*
4957 : : * Start incrementing the register
4958 : : * used to timestamp PTP packets.
4959 : : */
4960 : 0 : E1000_WRITE_REG(hw, E1000_TIMINCA, incval);
4961 : : break;
4962 : 0 : case e1000_82576:
4963 : : incval = E1000_INCVALUE_82576;
4964 : : shift = IGB_82576_TSYNC_SHIFT;
4965 : 0 : E1000_WRITE_REG(hw, E1000_TIMINCA,
4966 : : E1000_INCPERIOD_82576 | incval);
4967 : : break;
4968 : : default:
4969 : : /* Not supported */
4970 : : return;
4971 : : }
4972 : :
4973 : 0 : memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
4974 : 0 : memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4975 : 0 : memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
4976 : :
4977 : 0 : adapter->systime_tc.cc_mask = mask;
4978 : 0 : adapter->systime_tc.cc_shift = shift;
4979 : 0 : adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
4980 : :
4981 : 0 : adapter->rx_tstamp_tc.cc_mask = mask;
4982 : 0 : adapter->rx_tstamp_tc.cc_shift = shift;
4983 : 0 : adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4984 : :
4985 : 0 : adapter->tx_tstamp_tc.cc_mask = mask;
4986 : 0 : adapter->tx_tstamp_tc.cc_shift = shift;
4987 : 0 : adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
4988 : : }
4989 : :
4990 : : static int
4991 : 0 : igb_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
4992 : : {
4993 : 0 : struct e1000_adapter *adapter = dev->data->dev_private;
4994 : :
4995 : 0 : adapter->systime_tc.nsec += delta;
4996 : 0 : adapter->rx_tstamp_tc.nsec += delta;
4997 : 0 : adapter->tx_tstamp_tc.nsec += delta;
4998 : :
4999 : 0 : return 0;
5000 : : }
5001 : :
5002 : : static int
5003 : 0 : igb_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
5004 : : {
5005 : : uint64_t ns;
5006 : 0 : struct e1000_adapter *adapter = dev->data->dev_private;
5007 : :
5008 : : ns = rte_timespec_to_ns(ts);
5009 : :
5010 : : /* Set the timecounters to a new value. */
5011 : 0 : adapter->systime_tc.nsec = ns;
5012 : 0 : adapter->rx_tstamp_tc.nsec = ns;
5013 : 0 : adapter->tx_tstamp_tc.nsec = ns;
5014 : :
5015 : 0 : return 0;
5016 : : }
5017 : :
5018 : : static int
5019 : 0 : igb_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
5020 : : {
5021 : : uint64_t ns, systime_cycles;
5022 : 0 : struct e1000_adapter *adapter = dev->data->dev_private;
5023 : :
5024 : 0 : systime_cycles = igb_read_systime_cyclecounter(dev);
5025 : : ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
5026 : 0 : *ts = rte_ns_to_timespec(ns);
5027 : :
5028 : 0 : return 0;
5029 : : }
5030 : :
5031 : : static int
5032 : 0 : igb_timesync_enable(struct rte_eth_dev *dev)
5033 : : {
5034 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5035 : : uint32_t tsync_ctl;
5036 : : uint32_t tsauxc;
5037 : : struct timespec ts;
5038 : :
5039 : : memset(&ts, 0, sizeof(struct timespec));
5040 : :
5041 : : /* Stop the timesync system time. */
5042 : 0 : E1000_WRITE_REG(hw, E1000_TIMINCA, 0x0);
5043 : : /* Reset the timesync system time value. */
5044 [ # # # ]: 0 : switch (hw->mac.type) {
5045 : 0 : case e1000_82580:
5046 : : case e1000_i350:
5047 : : case e1000_i354:
5048 : : case e1000_i210:
5049 : : case e1000_i211:
5050 : 0 : E1000_WRITE_REG(hw, E1000_SYSTIMR, 0x0);
5051 : : /* fall-through */
5052 : 0 : case e1000_82576:
5053 : 0 : E1000_WRITE_REG(hw, E1000_SYSTIML, 0x0);
5054 : 0 : E1000_WRITE_REG(hw, E1000_SYSTIMH, 0x0);
5055 : : break;
5056 : : default:
5057 : : /* Not supported. */
5058 : : return -ENOTSUP;
5059 : : }
5060 : :
5061 : : /* Enable system time for it isn't on by default. */
5062 : 0 : tsauxc = E1000_READ_REG(hw, E1000_TSAUXC);
5063 : 0 : tsauxc &= ~E1000_TSAUXC_DISABLE_SYSTIME;
5064 : 0 : E1000_WRITE_REG(hw, E1000_TSAUXC, tsauxc);
5065 : :
5066 : 0 : igb_start_timecounters(dev);
5067 : :
5068 : : /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
5069 : 0 : E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588),
5070 : : (RTE_ETHER_TYPE_1588 |
5071 : : E1000_ETQF_FILTER_ENABLE |
5072 : : E1000_ETQF_1588));
5073 : :
5074 : : /* Enable timestamping of received PTP packets. */
5075 : 0 : tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5076 : 0 : tsync_ctl |= E1000_TSYNCRXCTL_ENABLED;
5077 : 0 : E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
5078 : :
5079 : : /* Enable Timestamping of transmitted PTP packets. */
5080 : 0 : tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5081 : 0 : tsync_ctl |= E1000_TSYNCTXCTL_ENABLED;
5082 : 0 : E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
5083 : :
5084 : : /* e1000 uses zero-based timestamping so only adjust timecounter */
5085 : : igb_timesync_write_time(dev, &ts);
5086 : :
5087 : 0 : return 0;
5088 : : }
5089 : :
5090 : : static int
5091 : 0 : igb_timesync_disable(struct rte_eth_dev *dev)
5092 : : {
5093 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5094 : : uint32_t tsync_ctl;
5095 : :
5096 : : /* Disable timestamping of transmitted PTP packets. */
5097 : 0 : tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5098 : 0 : tsync_ctl &= ~E1000_TSYNCTXCTL_ENABLED;
5099 : 0 : E1000_WRITE_REG(hw, E1000_TSYNCTXCTL, tsync_ctl);
5100 : :
5101 : : /* Disable timestamping of received PTP packets. */
5102 : 0 : tsync_ctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5103 : 0 : tsync_ctl &= ~E1000_TSYNCRXCTL_ENABLED;
5104 : 0 : E1000_WRITE_REG(hw, E1000_TSYNCRXCTL, tsync_ctl);
5105 : :
5106 : : /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
5107 : 0 : E1000_WRITE_REG(hw, E1000_ETQF(E1000_ETQF_FILTER_1588), 0);
5108 : :
5109 : : /* Stop incrementing the System Time registers. */
5110 : 0 : E1000_WRITE_REG(hw, E1000_TIMINCA, 0);
5111 : :
5112 : 0 : return 0;
5113 : : }
5114 : :
5115 : : static int
5116 : 0 : igb_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
5117 : : struct timespec *timestamp,
5118 : : uint32_t flags __rte_unused)
5119 : : {
5120 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5121 : : struct e1000_adapter *adapter = dev->data->dev_private;
5122 : : uint32_t tsync_rxctl;
5123 : : uint64_t rx_tstamp_cycles;
5124 : : uint64_t ns;
5125 : :
5126 : 0 : tsync_rxctl = E1000_READ_REG(hw, E1000_TSYNCRXCTL);
5127 [ # # ]: 0 : if ((tsync_rxctl & E1000_TSYNCRXCTL_VALID) == 0)
5128 : : return -EINVAL;
5129 : :
5130 : 0 : rx_tstamp_cycles = igb_read_rx_tstamp_cyclecounter(dev);
5131 : : ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
5132 : 0 : *timestamp = rte_ns_to_timespec(ns);
5133 : :
5134 : 0 : return 0;
5135 : : }
5136 : :
5137 : : static int
5138 : 0 : igb_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
5139 : : struct timespec *timestamp)
5140 : : {
5141 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5142 : : struct e1000_adapter *adapter = dev->data->dev_private;
5143 : : uint32_t tsync_txctl;
5144 : : uint64_t tx_tstamp_cycles;
5145 : : uint64_t ns;
5146 : :
5147 : 0 : tsync_txctl = E1000_READ_REG(hw, E1000_TSYNCTXCTL);
5148 [ # # ]: 0 : if ((tsync_txctl & E1000_TSYNCTXCTL_VALID) == 0)
5149 : : return -EINVAL;
5150 : :
5151 : 0 : tx_tstamp_cycles = igb_read_tx_tstamp_cyclecounter(dev);
5152 : : ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
5153 : 0 : *timestamp = rte_ns_to_timespec(ns);
5154 : :
5155 : 0 : return 0;
5156 : : }
5157 : :
5158 : : static int
5159 : 0 : eth_igb_read_clock(struct rte_eth_dev *dev, uint64_t *clock)
5160 : : {
5161 : 0 : struct e1000_adapter *adapter = dev->data->dev_private;
5162 : : struct rte_timecounter *tc = &adapter->systime_tc;
5163 : : uint64_t cycles;
5164 : :
5165 : 0 : cycles = igb_read_systime_cyclecounter(dev);
5166 : 0 : *clock = rte_timecounter_update(tc, cycles);
5167 : :
5168 : 0 : return 0;
5169 : : }
5170 : :
5171 : : static int
5172 : : eth_igb_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5173 : : {
5174 : : int count = 0;
5175 : : int g_ind = 0;
5176 : : const struct reg_info *reg_group;
5177 : :
5178 [ # # # # ]: 0 : while ((reg_group = igb_regs[g_ind++]))
5179 : 0 : count += igb_reg_group_count(reg_group);
5180 : :
5181 : : return count;
5182 : : }
5183 : :
5184 : : static int
5185 : : igbvf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
5186 : : {
5187 : : int count = 0;
5188 : : int g_ind = 0;
5189 : : const struct reg_info *reg_group;
5190 : :
5191 [ # # # # ]: 0 : while ((reg_group = igbvf_regs[g_ind++]))
5192 : 0 : count += igb_reg_group_count(reg_group);
5193 : :
5194 : : return count;
5195 : : }
5196 : :
5197 : : static int
5198 : 0 : eth_igb_get_regs(struct rte_eth_dev *dev,
5199 : : struct rte_dev_reg_info *regs)
5200 : : {
5201 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5202 : 0 : uint32_t *data = regs->data;
5203 : : int g_ind = 0;
5204 : : int count = 0;
5205 : : const struct reg_info *reg_group;
5206 : :
5207 [ # # ]: 0 : if (data == NULL) {
5208 : 0 : regs->length = eth_igb_get_reg_length(dev);
5209 : 0 : regs->width = sizeof(uint32_t);
5210 : 0 : return 0;
5211 : : }
5212 : :
5213 : : /* Support only full register dump */
5214 [ # # ]: 0 : if ((regs->length == 0) ||
5215 [ # # ]: 0 : (regs->length == (uint32_t)eth_igb_get_reg_length(dev))) {
5216 : 0 : regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5217 : 0 : hw->device_id;
5218 [ # # ]: 0 : while ((reg_group = igb_regs[g_ind++]))
5219 : 0 : count += igb_read_regs_group(dev, &data[count],
5220 : : reg_group);
5221 : : return 0;
5222 : : }
5223 : :
5224 : : return -ENOTSUP;
5225 : : }
5226 : :
5227 : : static int
5228 : 0 : igbvf_get_regs(struct rte_eth_dev *dev,
5229 : : struct rte_dev_reg_info *regs)
5230 : : {
5231 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5232 : 0 : uint32_t *data = regs->data;
5233 : : int g_ind = 0;
5234 : : int count = 0;
5235 : : const struct reg_info *reg_group;
5236 : :
5237 [ # # ]: 0 : if (data == NULL) {
5238 : 0 : regs->length = igbvf_get_reg_length(dev);
5239 : 0 : regs->width = sizeof(uint32_t);
5240 : 0 : return 0;
5241 : : }
5242 : :
5243 : : /* Support only full register dump */
5244 [ # # ]: 0 : if ((regs->length == 0) ||
5245 [ # # ]: 0 : (regs->length == (uint32_t)igbvf_get_reg_length(dev))) {
5246 : 0 : regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
5247 : 0 : hw->device_id;
5248 [ # # ]: 0 : while ((reg_group = igbvf_regs[g_ind++]))
5249 : 0 : count += igb_read_regs_group(dev, &data[count],
5250 : : reg_group);
5251 : : return 0;
5252 : : }
5253 : :
5254 : : return -ENOTSUP;
5255 : : }
5256 : :
5257 : : static int
5258 : 0 : eth_igb_get_eeprom_length(struct rte_eth_dev *dev)
5259 : : {
5260 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5261 : :
5262 : : /* Return unit is byte count */
5263 : 0 : return hw->nvm.word_size * 2;
5264 : : }
5265 : :
5266 : : static int
5267 : 0 : eth_igb_get_eeprom(struct rte_eth_dev *dev,
5268 : : struct rte_dev_eeprom_info *in_eeprom)
5269 : : {
5270 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5271 : : struct e1000_nvm_info *nvm = &hw->nvm;
5272 : 0 : uint16_t *data = in_eeprom->data;
5273 : : int first, length;
5274 : :
5275 : : /*
5276 : : * This function calls into the base driver, which in turn will use
5277 : : * function pointers, which are not guaranteed to be valid in secondary
5278 : : * processes, so avoid using this function in secondary processes.
5279 : : */
5280 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5281 : : return -E_RTE_SECONDARY;
5282 : :
5283 : 0 : first = in_eeprom->offset >> 1;
5284 : 0 : length = in_eeprom->length >> 1;
5285 [ # # ]: 0 : if ((first >= hw->nvm.word_size) ||
5286 [ # # ]: 0 : ((first + length) > hw->nvm.word_size))
5287 : : return -EINVAL;
5288 : :
5289 : 0 : in_eeprom->magic = hw->vendor_id |
5290 : 0 : ((uint32_t)hw->device_id << 16);
5291 : :
5292 [ # # ]: 0 : if ((nvm->ops.read) == NULL)
5293 : : return -ENOTSUP;
5294 : :
5295 : 0 : return nvm->ops.read(hw, first, length, data);
5296 : : }
5297 : :
5298 : : static int
5299 : 0 : eth_igb_set_eeprom(struct rte_eth_dev *dev,
5300 : : struct rte_dev_eeprom_info *in_eeprom)
5301 : : {
5302 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5303 : : struct e1000_nvm_info *nvm = &hw->nvm;
5304 : 0 : uint16_t *data = in_eeprom->data;
5305 : : int first, length;
5306 : :
5307 : : /*
5308 : : * This function calls into the base driver, which in turn will use
5309 : : * function pointers, which are not guaranteed to be valid in secondary
5310 : : * processes, so avoid using this function in secondary processes.
5311 : : */
5312 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5313 : : return -E_RTE_SECONDARY;
5314 : :
5315 : 0 : first = in_eeprom->offset >> 1;
5316 : 0 : length = in_eeprom->length >> 1;
5317 [ # # ]: 0 : if ((first >= hw->nvm.word_size) ||
5318 [ # # ]: 0 : ((first + length) >= hw->nvm.word_size))
5319 : : return -EINVAL;
5320 : :
5321 : 0 : in_eeprom->magic = (uint32_t)hw->vendor_id |
5322 : 0 : ((uint32_t)hw->device_id << 16);
5323 : :
5324 [ # # ]: 0 : if ((nvm->ops.write) == NULL)
5325 : : return -ENOTSUP;
5326 : 0 : return nvm->ops.write(hw, first, length, data);
5327 : : }
5328 : :
5329 : : static int
5330 : 0 : eth_igb_get_module_info(struct rte_eth_dev *dev,
5331 : : struct rte_eth_dev_module_info *modinfo)
5332 : : {
5333 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5334 : :
5335 : : uint32_t status = 0;
5336 : : uint16_t sff8472_rev, addr_mode;
5337 : : bool page_swap = false;
5338 : :
5339 [ # # ]: 0 : if (hw->phy.media_type == e1000_media_type_copper ||
5340 : : hw->phy.media_type == e1000_media_type_unknown)
5341 : : return -EOPNOTSUPP;
5342 : :
5343 : : /* Check whether we support SFF-8472 or not */
5344 : 0 : status = e1000_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev);
5345 [ # # ]: 0 : if (status)
5346 : : return -EIO;
5347 : :
5348 : : /* addressing mode is not supported */
5349 : 0 : status = e1000_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode);
5350 [ # # ]: 0 : if (status)
5351 : : return -EIO;
5352 : :
5353 : : /* addressing mode is not supported */
5354 [ # # ]: 0 : if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) {
5355 : 0 : PMD_DRV_LOG(ERR,
5356 : : "Address change required to access page 0xA2, "
5357 : : "but not supported. Please report the module "
5358 : : "type to the driver maintainers.");
5359 : : page_swap = true;
5360 : : }
5361 : :
5362 [ # # # # ]: 0 : if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) {
5363 : : /* We have an SFP, but it does not support SFF-8472 */
5364 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
5365 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
5366 : : } else {
5367 : : /* We have an SFP which supports a revision of SFF-8472 */
5368 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8472;
5369 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
5370 : : }
5371 : :
5372 : : return 0;
5373 : : }
5374 : :
5375 : : static int
5376 : 0 : eth_igb_get_module_eeprom(struct rte_eth_dev *dev,
5377 : : struct rte_dev_eeprom_info *info)
5378 : : {
5379 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5380 : :
5381 : : uint32_t status = 0;
5382 : : uint16_t dataword[RTE_ETH_MODULE_SFF_8472_LEN / 2 + 1];
5383 : : u16 first_word, last_word;
5384 : : int i = 0;
5385 : :
5386 : 0 : first_word = info->offset >> 1;
5387 : 0 : last_word = (info->offset + info->length - 1) >> 1;
5388 : :
5389 : : /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */
5390 [ # # ]: 0 : for (i = 0; i < last_word - first_word + 1; i++) {
5391 : 0 : status = e1000_read_phy_reg_i2c(hw, (first_word + i) * 2,
5392 : 0 : &dataword[i]);
5393 [ # # ]: 0 : if (status) {
5394 : : /* Error occurred while reading module */
5395 : : return -EIO;
5396 : : }
5397 : :
5398 [ # # ]: 0 : dataword[i] = rte_be_to_cpu_16(dataword[i]);
5399 : : }
5400 : :
5401 : 0 : memcpy(info->data, (u8 *)dataword + (info->offset & 1), info->length);
5402 : :
5403 : 0 : return 0;
5404 : : }
5405 : :
5406 : : static int
5407 : 0 : eth_igb_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
5408 : : {
5409 : : struct e1000_hw *hw =
5410 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5411 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5412 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5413 : : uint32_t vec = E1000_MISC_VEC_ID;
5414 : :
5415 : : /* device interrupts are only subscribed to in primary processes */
5416 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5417 : : return -E_RTE_SECONDARY;
5418 : :
5419 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
5420 : : vec = E1000_RX_VEC_START;
5421 : :
5422 : 0 : uint32_t mask = 1 << (queue_id + vec);
5423 : :
5424 : 0 : E1000_WRITE_REG(hw, E1000_EIMC, mask);
5425 : 0 : E1000_WRITE_FLUSH(hw);
5426 : :
5427 : 0 : return 0;
5428 : : }
5429 : :
5430 : : static int
5431 : 0 : eth_igb_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
5432 : : {
5433 : : struct e1000_hw *hw =
5434 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5435 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5436 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5437 : : uint32_t vec = E1000_MISC_VEC_ID;
5438 : :
5439 : : /* device interrupts are only subscribed to in primary processes */
5440 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
5441 : : return -E_RTE_SECONDARY;
5442 : :
5443 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
5444 : : vec = E1000_RX_VEC_START;
5445 : :
5446 : 0 : uint32_t mask = 1 << (queue_id + vec);
5447 : : uint32_t regval;
5448 : :
5449 : 0 : regval = E1000_READ_REG(hw, E1000_EIMS);
5450 : 0 : E1000_WRITE_REG(hw, E1000_EIMS, regval | mask);
5451 : 0 : E1000_WRITE_FLUSH(hw);
5452 : :
5453 : 0 : rte_intr_ack(intr_handle);
5454 : :
5455 : 0 : return 0;
5456 : : }
5457 : :
5458 : : static void
5459 : : eth_igb_write_ivar(struct e1000_hw *hw, uint8_t msix_vector,
5460 : : uint8_t index, uint8_t offset)
5461 : : {
5462 : 0 : uint32_t val = E1000_READ_REG_ARRAY(hw, E1000_IVAR0, index);
5463 : :
5464 : : /* clear bits */
5465 : 0 : val &= ~((uint32_t)0xFF << offset);
5466 : :
5467 : : /* write vector and valid bit */
5468 : 0 : val |= (msix_vector | E1000_IVAR_VALID) << offset;
5469 : :
5470 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_IVAR0, index, val);
5471 : 0 : }
5472 : :
5473 : : static void
5474 : 0 : eth_igb_assign_msix_vector(struct e1000_hw *hw, int8_t direction,
5475 : : uint8_t queue, uint8_t msix_vector)
5476 : : {
5477 : : uint32_t tmp = 0;
5478 : :
5479 [ # # ]: 0 : if (hw->mac.type == e1000_82575) {
5480 [ # # ]: 0 : if (direction == 0)
5481 : 0 : tmp = E1000_EICR_RX_QUEUE0 << queue;
5482 [ # # ]: 0 : else if (direction == 1)
5483 : 0 : tmp = E1000_EICR_TX_QUEUE0 << queue;
5484 : 0 : E1000_WRITE_REG(hw, E1000_MSIXBM(msix_vector), tmp);
5485 [ # # ]: 0 : } else if (hw->mac.type == e1000_82576) {
5486 [ # # ]: 0 : if ((direction == 0) || (direction == 1))
5487 : 0 : eth_igb_write_ivar(hw, msix_vector, queue & 0x7,
5488 : 0 : ((queue & 0x8) << 1) +
5489 : 0 : 8 * direction);
5490 : 0 : } else if ((hw->mac.type == e1000_82580) ||
5491 : : (hw->mac.type == e1000_i350) ||
5492 : : (hw->mac.type == e1000_i354) ||
5493 [ # # ]: 0 : (hw->mac.type == e1000_i210) ||
5494 : : (hw->mac.type == e1000_i211)) {
5495 [ # # ]: 0 : if ((direction == 0) || (direction == 1))
5496 : 0 : eth_igb_write_ivar(hw, msix_vector,
5497 : : queue >> 1,
5498 : 0 : ((queue & 0x1) << 4) +
5499 : 0 : 8 * direction);
5500 : : }
5501 : 0 : }
5502 : :
5503 : : /* Sets up the hardware to generate MSI-X interrupts properly
5504 : : * @hw
5505 : : * board private structure
5506 : : */
5507 : : static void
5508 : 0 : eth_igb_configure_msix_intr(struct rte_eth_dev *dev)
5509 : : {
5510 : : int queue_id, nb_efd;
5511 : : uint32_t tmpval, regval, intr_mask;
5512 : 0 : struct e1000_hw *hw =
5513 : 0 : E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5514 : : uint32_t vec = E1000_MISC_VEC_ID;
5515 : : uint32_t base = E1000_MISC_VEC_ID;
5516 : : uint32_t misc_shift = 0;
5517 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
5518 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
5519 : :
5520 : : /* won't configure msix register if no mapping is done
5521 : : * between intr vector and event fd
5522 : : */
5523 [ # # ]: 0 : if (!rte_intr_dp_is_en(intr_handle))
5524 : : return;
5525 : :
5526 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
5527 : : vec = base = E1000_RX_VEC_START;
5528 : : misc_shift = 1;
5529 : : }
5530 : :
5531 : : /* set interrupt vector for other causes */
5532 [ # # ]: 0 : if (hw->mac.type == e1000_82575) {
5533 : 0 : tmpval = E1000_READ_REG(hw, E1000_CTRL_EXT);
5534 : : /* enable MSI-X PBA support */
5535 : : tmpval |= E1000_CTRL_EXT_PBA_CLR;
5536 : :
5537 : : /* Auto-Mask interrupts upon ICR read */
5538 : : tmpval |= E1000_CTRL_EXT_EIAME;
5539 : 0 : tmpval |= E1000_CTRL_EXT_IRCA;
5540 : :
5541 : 0 : E1000_WRITE_REG(hw, E1000_CTRL_EXT, tmpval);
5542 : :
5543 : : /* enable msix_other interrupt */
5544 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_MSIXBM(0), 0, E1000_EIMS_OTHER);
5545 : 0 : regval = E1000_READ_REG(hw, E1000_EIAC);
5546 : 0 : E1000_WRITE_REG(hw, E1000_EIAC, regval | E1000_EIMS_OTHER);
5547 : 0 : regval = E1000_READ_REG(hw, E1000_EIAM);
5548 : 0 : E1000_WRITE_REG(hw, E1000_EIMS, regval | E1000_EIMS_OTHER);
5549 : 0 : } else if ((hw->mac.type == e1000_82576) ||
5550 : : (hw->mac.type == e1000_82580) ||
5551 : : (hw->mac.type == e1000_i350) ||
5552 : : (hw->mac.type == e1000_i354) ||
5553 [ # # ]: 0 : (hw->mac.type == e1000_i210) ||
5554 : : (hw->mac.type == e1000_i211)) {
5555 : : /* turn on MSI-X capability first */
5556 : 0 : E1000_WRITE_REG(hw, E1000_GPIE, E1000_GPIE_MSIX_MODE |
5557 : : E1000_GPIE_PBA | E1000_GPIE_EIAME |
5558 : : E1000_GPIE_NSICR);
5559 : 0 : nb_efd = rte_intr_nb_efd_get(intr_handle);
5560 [ # # ]: 0 : if (nb_efd < 0)
5561 : : return;
5562 : :
5563 : 0 : intr_mask = RTE_LEN2MASK(nb_efd, uint32_t) << misc_shift;
5564 : :
5565 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
5566 : 0 : intr_mask |= (1 << IGB_MSIX_OTHER_INTR_VEC);
5567 : :
5568 : 0 : regval = E1000_READ_REG(hw, E1000_EIAC);
5569 : 0 : E1000_WRITE_REG(hw, E1000_EIAC, regval | intr_mask);
5570 : :
5571 : : /* enable msix_other interrupt */
5572 : 0 : regval = E1000_READ_REG(hw, E1000_EIMS);
5573 : 0 : E1000_WRITE_REG(hw, E1000_EIMS, regval | intr_mask);
5574 : : tmpval = (IGB_MSIX_OTHER_INTR_VEC | E1000_IVAR_VALID) << 8;
5575 : 0 : E1000_WRITE_REG(hw, E1000_IVAR_MISC, tmpval);
5576 : : }
5577 : :
5578 : : /* use EIAM to auto-mask when MSI-X interrupt
5579 : : * is asserted, this saves a register write for every interrupt
5580 : : */
5581 : 0 : nb_efd = rte_intr_nb_efd_get(intr_handle);
5582 [ # # ]: 0 : if (nb_efd < 0)
5583 : : return;
5584 : :
5585 : 0 : intr_mask = RTE_LEN2MASK(nb_efd, uint32_t) << misc_shift;
5586 : :
5587 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
5588 : 0 : intr_mask |= (1 << IGB_MSIX_OTHER_INTR_VEC);
5589 : :
5590 : 0 : regval = E1000_READ_REG(hw, E1000_EIAM);
5591 : 0 : E1000_WRITE_REG(hw, E1000_EIAM, regval | intr_mask);
5592 : :
5593 [ # # ]: 0 : for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
5594 : 0 : eth_igb_assign_msix_vector(hw, 0, queue_id, vec);
5595 : 0 : rte_intr_vec_list_index_set(intr_handle, queue_id, vec);
5596 [ # # ]: 0 : if (vec < base + rte_intr_nb_efd_get(intr_handle) - 1)
5597 : 0 : vec++;
5598 : : }
5599 : :
5600 : 0 : E1000_WRITE_FLUSH(hw);
5601 : : }
5602 : :
5603 : : /* restore n-tuple filter */
5604 : : static inline void
5605 : 0 : igb_ntuple_filter_restore(struct rte_eth_dev *dev)
5606 : : {
5607 : : struct e1000_filter_info *filter_info =
5608 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5609 : : struct e1000_5tuple_filter *p_5tuple;
5610 : : struct e1000_2tuple_filter *p_2tuple;
5611 : :
5612 [ # # ]: 0 : TAILQ_FOREACH(p_5tuple, &filter_info->fivetuple_list, entries) {
5613 : 0 : igb_inject_5tuple_filter_82576(dev, p_5tuple);
5614 : : }
5615 : :
5616 [ # # ]: 0 : TAILQ_FOREACH(p_2tuple, &filter_info->twotuple_list, entries) {
5617 : 0 : igb_inject_2uple_filter(dev, p_2tuple);
5618 : : }
5619 : 0 : }
5620 : :
5621 : : /* restore SYN filter */
5622 : : static inline void
5623 : : igb_syn_filter_restore(struct rte_eth_dev *dev)
5624 : : {
5625 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5626 : : struct e1000_filter_info *filter_info =
5627 : : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5628 : : uint32_t synqf;
5629 : :
5630 : 0 : synqf = filter_info->syn_info;
5631 : :
5632 [ # # ]: 0 : if (synqf & E1000_SYN_FILTER_ENABLE) {
5633 : 0 : E1000_WRITE_REG(hw, E1000_SYNQF(0), synqf);
5634 : 0 : E1000_WRITE_FLUSH(hw);
5635 : : }
5636 : : }
5637 : :
5638 : : /* restore ethernet type filter */
5639 : : static inline void
5640 : 0 : igb_ethertype_filter_restore(struct rte_eth_dev *dev)
5641 : : {
5642 : 0 : struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5643 : : struct e1000_filter_info *filter_info =
5644 : : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5645 : : int i;
5646 : :
5647 [ # # ]: 0 : for (i = 0; i < E1000_MAX_ETQF_FILTERS; i++) {
5648 [ # # ]: 0 : if (filter_info->ethertype_mask & (1 << i)) {
5649 : 0 : E1000_WRITE_REG(hw, E1000_ETQF(i),
5650 : : filter_info->ethertype_filters[i].etqf);
5651 : 0 : E1000_WRITE_FLUSH(hw);
5652 : : }
5653 : : }
5654 : 0 : }
5655 : :
5656 : : /* restore flex byte filter */
5657 : : static inline void
5658 : : igb_flex_filter_restore(struct rte_eth_dev *dev)
5659 : : {
5660 : : struct e1000_filter_info *filter_info =
5661 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5662 : : struct e1000_flex_filter *flex_filter;
5663 : :
5664 [ # # ]: 0 : TAILQ_FOREACH(flex_filter, &filter_info->flex_list, entries) {
5665 : 0 : igb_inject_flex_filter(dev, flex_filter);
5666 : : }
5667 : : }
5668 : :
5669 : : /* restore rss filter */
5670 : : static inline void
5671 : : igb_rss_filter_restore(struct rte_eth_dev *dev)
5672 : : {
5673 : : struct e1000_filter_info *filter_info =
5674 : 0 : E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
5675 : :
5676 [ # # ]: 0 : if (filter_info->rss_info.conf.queue_num)
5677 : 0 : igb_config_rss_filter(dev, &filter_info->rss_info, TRUE);
5678 : : }
5679 : :
5680 : : /* restore all types filter */
5681 : : static int
5682 : 0 : igb_filter_restore(struct rte_eth_dev *dev)
5683 : : {
5684 : 0 : igb_ntuple_filter_restore(dev);
5685 : 0 : igb_ethertype_filter_restore(dev);
5686 : : igb_syn_filter_restore(dev);
5687 : : igb_flex_filter_restore(dev);
5688 : : igb_rss_filter_restore(dev);
5689 : :
5690 : 0 : return 0;
5691 : : }
5692 : :
5693 : 252 : RTE_PMD_REGISTER_PCI(net_e1000_igb, rte_igb_pmd);
5694 : : RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb, pci_id_igb_map);
5695 : : RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb, "* igb_uio | uio_pci_generic | vfio-pci");
5696 : 252 : RTE_PMD_REGISTER_PCI(net_e1000_igb_vf, rte_igbvf_pmd);
5697 : : RTE_PMD_REGISTER_PCI_TABLE(net_e1000_igb_vf, pci_id_igbvf_map);
5698 : : RTE_PMD_REGISTER_KMOD_DEP(net_e1000_igb_vf, "* igb_uio | vfio-pci");
|