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