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