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