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