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