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