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