Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2019-2020 Intel Corporation
3 : : */
4 : :
5 : : #include <stdint.h>
6 : : #include <string.h>
7 : :
8 : : #include <rte_string_fns.h>
9 : : #include <rte_pci.h>
10 : : #include <bus_pci_driver.h>
11 : : #include <ethdev_driver.h>
12 : : #include <ethdev_pci.h>
13 : : #include <rte_malloc.h>
14 : : #include <rte_alarm.h>
15 : :
16 : : #include "igc_logs.h"
17 : : #include "igc_txrx.h"
18 : : #include "igc_filter.h"
19 : : #include "igc_flow.h"
20 : :
21 : : #define IGC_INTEL_VENDOR_ID 0x8086
22 : :
23 : : #define IGC_FC_PAUSE_TIME 0x0680
24 : : #define IGC_LINK_UPDATE_CHECK_TIMEOUT 90 /* 9s */
25 : : #define IGC_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
26 : :
27 : : #define IGC_MISC_VEC_ID RTE_INTR_VEC_ZERO_OFFSET
28 : : #define IGC_RX_VEC_START RTE_INTR_VEC_RXTX_OFFSET
29 : : #define IGC_MSIX_OTHER_INTR_VEC 0 /* MSI-X other interrupt vector */
30 : : #define IGC_FLAG_NEED_LINK_UPDATE (1u << 0) /* need update link */
31 : :
32 : : #define IGC_DEFAULT_RX_FREE_THRESH 32
33 : :
34 : : #define IGC_DEFAULT_RX_PTHRESH 8
35 : : #define IGC_DEFAULT_RX_HTHRESH 8
36 : : #define IGC_DEFAULT_RX_WTHRESH 4
37 : :
38 : : #define IGC_DEFAULT_TX_PTHRESH 8
39 : : #define IGC_DEFAULT_TX_HTHRESH 1
40 : : #define IGC_DEFAULT_TX_WTHRESH 16
41 : :
42 : : /* MSI-X other interrupt vector */
43 : : #define IGC_MSIX_OTHER_INTR_VEC 0
44 : :
45 : : /* External VLAN Enable bit mask */
46 : : #define IGC_CTRL_EXT_EXT_VLAN (1u << 26)
47 : :
48 : : /* Speed select */
49 : : #define IGC_CTRL_SPEED_MASK (7u << 8)
50 : : #define IGC_CTRL_SPEED_2500 (6u << 8)
51 : :
52 : : /* External VLAN Ether Type bit mask and shift */
53 : : #define IGC_VET_EXT 0xFFFF0000
54 : : #define IGC_VET_EXT_SHIFT 16
55 : :
56 : : /* Force EEE Auto-negotiation */
57 : : #define IGC_EEER_EEE_FRC_AN (1u << 28)
58 : :
59 : : /* Per Queue Good Packets Received Count */
60 : : #define IGC_PQGPRC(idx) (0x10010 + 0x100 * (idx))
61 : : /* Per Queue Good Octets Received Count */
62 : : #define IGC_PQGORC(idx) (0x10018 + 0x100 * (idx))
63 : : /* Per Queue Good Octets Transmitted Count */
64 : : #define IGC_PQGOTC(idx) (0x10034 + 0x100 * (idx))
65 : : /* Per Queue Multicast Packets Received Count */
66 : : #define IGC_PQMPRC(idx) (0x10038 + 0x100 * (idx))
67 : : /* Transmit Queue Drop Packet Count */
68 : : #define IGC_TQDPC(idx) (0xe030 + 0x40 * (idx))
69 : :
70 : : #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
71 : : #define U32_0_IN_U64 0 /* lower bytes of u64 */
72 : : #define U32_1_IN_U64 1 /* higher bytes of u64 */
73 : : #else
74 : : #define U32_0_IN_U64 1
75 : : #define U32_1_IN_U64 0
76 : : #endif
77 : :
78 : : #define IGC_ALARM_INTERVAL 8000000u
79 : : /* us, about 13.6s some per-queue registers will wrap around back to 0. */
80 : :
81 : : /* Transmit and receive latency (for PTP timestamps) */
82 : : #define IGC_I225_TX_LATENCY_10 240
83 : : #define IGC_I225_TX_LATENCY_100 58
84 : : #define IGC_I225_TX_LATENCY_1000 80
85 : : #define IGC_I225_TX_LATENCY_2500 1325
86 : : #define IGC_I225_RX_LATENCY_10 6450
87 : : #define IGC_I225_RX_LATENCY_100 185
88 : : #define IGC_I225_RX_LATENCY_1000 300
89 : : #define IGC_I225_RX_LATENCY_2500 1485
90 : :
91 : : uint64_t igc_tx_timestamp_dynflag;
92 : : int igc_tx_timestamp_dynfield_offset = -1;
93 : :
94 : : static const struct rte_eth_desc_lim rx_desc_lim = {
95 : : .nb_max = IGC_MAX_RXD,
96 : : .nb_min = IGC_MIN_RXD,
97 : : .nb_align = IGC_RXD_ALIGN,
98 : : };
99 : :
100 : : static const struct rte_eth_desc_lim tx_desc_lim = {
101 : : .nb_max = IGC_MAX_TXD,
102 : : .nb_min = IGC_MIN_TXD,
103 : : .nb_align = IGC_TXD_ALIGN,
104 : : .nb_seg_max = IGC_TX_MAX_SEG,
105 : : .nb_mtu_seg_max = IGC_TX_MAX_MTU_SEG,
106 : : };
107 : :
108 : : static const struct rte_pci_id pci_id_igc_map[] = {
109 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I225_LM) },
110 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I225_LMVP) },
111 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I225_V) },
112 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I225_I) },
113 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I225_IT) },
114 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I225_K) },
115 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I226_K) },
116 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I226_LMVP) },
117 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I226_LM) },
118 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I226_V) },
119 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I226_IT) },
120 : : { RTE_PCI_DEVICE(IGC_INTEL_VENDOR_ID, IGC_DEV_ID_I226_BLANK_NVM) },
121 : : { .vendor_id = 0, /* sentinel */ },
122 : : };
123 : :
124 : : /* store statistics names and its offset in stats structure */
125 : : struct rte_igc_xstats_name_off {
126 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
127 : : unsigned int offset;
128 : : };
129 : :
130 : : static const struct rte_igc_xstats_name_off rte_igc_stats_strings[] = {
131 : : {"rx_crc_errors", offsetof(struct igc_hw_stats, crcerrs)},
132 : : {"rx_align_errors", offsetof(struct igc_hw_stats, algnerrc)},
133 : : {"rx_errors", offsetof(struct igc_hw_stats, rxerrc)},
134 : : {"rx_missed_packets", offsetof(struct igc_hw_stats, mpc)},
135 : : {"tx_single_collision_packets", offsetof(struct igc_hw_stats, scc)},
136 : : {"tx_multiple_collision_packets", offsetof(struct igc_hw_stats, mcc)},
137 : : {"tx_excessive_collision_packets", offsetof(struct igc_hw_stats,
138 : : ecol)},
139 : : {"tx_late_collisions", offsetof(struct igc_hw_stats, latecol)},
140 : : {"tx_total_collisions", offsetof(struct igc_hw_stats, colc)},
141 : : {"tx_deferred_packets", offsetof(struct igc_hw_stats, dc)},
142 : : {"tx_no_carrier_sense_packets", offsetof(struct igc_hw_stats, tncrs)},
143 : : {"tx_discarded_packets", offsetof(struct igc_hw_stats, htdpmc)},
144 : : {"rx_length_errors", offsetof(struct igc_hw_stats, rlec)},
145 : : {"rx_xon_packets", offsetof(struct igc_hw_stats, xonrxc)},
146 : : {"tx_xon_packets", offsetof(struct igc_hw_stats, xontxc)},
147 : : {"rx_xoff_packets", offsetof(struct igc_hw_stats, xoffrxc)},
148 : : {"tx_xoff_packets", offsetof(struct igc_hw_stats, xofftxc)},
149 : : {"rx_flow_control_unsupported_packets", offsetof(struct igc_hw_stats,
150 : : fcruc)},
151 : : {"rx_size_64_packets", offsetof(struct igc_hw_stats, prc64)},
152 : : {"rx_size_65_to_127_packets", offsetof(struct igc_hw_stats, prc127)},
153 : : {"rx_size_128_to_255_packets", offsetof(struct igc_hw_stats, prc255)},
154 : : {"rx_size_256_to_511_packets", offsetof(struct igc_hw_stats, prc511)},
155 : : {"rx_size_512_to_1023_packets", offsetof(struct igc_hw_stats,
156 : : prc1023)},
157 : : {"rx_size_1024_to_max_packets", offsetof(struct igc_hw_stats,
158 : : prc1522)},
159 : : {"rx_broadcast_packets", offsetof(struct igc_hw_stats, bprc)},
160 : : {"rx_multicast_packets", offsetof(struct igc_hw_stats, mprc)},
161 : : {"rx_undersize_errors", offsetof(struct igc_hw_stats, ruc)},
162 : : {"rx_fragment_errors", offsetof(struct igc_hw_stats, rfc)},
163 : : {"rx_oversize_errors", offsetof(struct igc_hw_stats, roc)},
164 : : {"rx_jabber_errors", offsetof(struct igc_hw_stats, rjc)},
165 : : {"rx_no_buffers", offsetof(struct igc_hw_stats, rnbc)},
166 : : {"rx_management_packets", offsetof(struct igc_hw_stats, mgprc)},
167 : : {"rx_management_dropped", offsetof(struct igc_hw_stats, mgpdc)},
168 : : {"tx_management_packets", offsetof(struct igc_hw_stats, mgptc)},
169 : : {"rx_total_packets", offsetof(struct igc_hw_stats, tpr)},
170 : : {"tx_total_packets", offsetof(struct igc_hw_stats, tpt)},
171 : : {"rx_total_bytes", offsetof(struct igc_hw_stats, tor)},
172 : : {"tx_total_bytes", offsetof(struct igc_hw_stats, tot)},
173 : : {"tx_size_64_packets", offsetof(struct igc_hw_stats, ptc64)},
174 : : {"tx_size_65_to_127_packets", offsetof(struct igc_hw_stats, ptc127)},
175 : : {"tx_size_128_to_255_packets", offsetof(struct igc_hw_stats, ptc255)},
176 : : {"tx_size_256_to_511_packets", offsetof(struct igc_hw_stats, ptc511)},
177 : : {"tx_size_512_to_1023_packets", offsetof(struct igc_hw_stats,
178 : : ptc1023)},
179 : : {"tx_size_1023_to_max_packets", offsetof(struct igc_hw_stats,
180 : : ptc1522)},
181 : : {"tx_multicast_packets", offsetof(struct igc_hw_stats, mptc)},
182 : : {"tx_broadcast_packets", offsetof(struct igc_hw_stats, bptc)},
183 : : {"tx_tso_packets", offsetof(struct igc_hw_stats, tsctc)},
184 : : {"rx_sent_to_host_packets", offsetof(struct igc_hw_stats, rpthc)},
185 : : {"tx_sent_by_host_packets", offsetof(struct igc_hw_stats, hgptc)},
186 : : {"interrupt_assert_count", offsetof(struct igc_hw_stats, iac)},
187 : : {"rx_descriptor_lower_threshold",
188 : : offsetof(struct igc_hw_stats, icrxdmtc)},
189 : : };
190 : :
191 : : #define IGC_NB_XSTATS (sizeof(rte_igc_stats_strings) / \
192 : : sizeof(rte_igc_stats_strings[0]))
193 : :
194 : : static int eth_igc_configure(struct rte_eth_dev *dev);
195 : : static int eth_igc_link_update(struct rte_eth_dev *dev, int wait_to_complete);
196 : : static int eth_igc_stop(struct rte_eth_dev *dev);
197 : : static int eth_igc_start(struct rte_eth_dev *dev);
198 : : static int eth_igc_set_link_up(struct rte_eth_dev *dev);
199 : : static int eth_igc_set_link_down(struct rte_eth_dev *dev);
200 : : static int eth_igc_close(struct rte_eth_dev *dev);
201 : : static int eth_igc_reset(struct rte_eth_dev *dev);
202 : : static int eth_igc_promiscuous_enable(struct rte_eth_dev *dev);
203 : : static int eth_igc_promiscuous_disable(struct rte_eth_dev *dev);
204 : : static int eth_igc_fw_version_get(struct rte_eth_dev *dev,
205 : : char *fw_version, size_t fw_size);
206 : : static int eth_igc_infos_get(struct rte_eth_dev *dev,
207 : : struct rte_eth_dev_info *dev_info);
208 : : static int eth_igc_led_on(struct rte_eth_dev *dev);
209 : : static int eth_igc_led_off(struct rte_eth_dev *dev);
210 : : static const uint32_t *eth_igc_supported_ptypes_get(struct rte_eth_dev *dev,
211 : : size_t *no_of_elements);
212 : : static int eth_igc_rar_set(struct rte_eth_dev *dev,
213 : : struct rte_ether_addr *mac_addr, uint32_t index, uint32_t pool);
214 : : static void eth_igc_rar_clear(struct rte_eth_dev *dev, uint32_t index);
215 : : static int eth_igc_default_mac_addr_set(struct rte_eth_dev *dev,
216 : : struct rte_ether_addr *addr);
217 : : static int eth_igc_set_mc_addr_list(struct rte_eth_dev *dev,
218 : : struct rte_ether_addr *mc_addr_set,
219 : : uint32_t nb_mc_addr);
220 : : static int eth_igc_allmulticast_enable(struct rte_eth_dev *dev);
221 : : static int eth_igc_allmulticast_disable(struct rte_eth_dev *dev);
222 : : static int eth_igc_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
223 : : static int eth_igc_stats_get(struct rte_eth_dev *dev,
224 : : struct rte_eth_stats *rte_stats);
225 : : static int eth_igc_xstats_get(struct rte_eth_dev *dev,
226 : : struct rte_eth_xstat *xstats, unsigned int n);
227 : : static int eth_igc_xstats_get_by_id(struct rte_eth_dev *dev,
228 : : const uint64_t *ids,
229 : : uint64_t *values, unsigned int n);
230 : : static int eth_igc_xstats_get_names(struct rte_eth_dev *dev,
231 : : struct rte_eth_xstat_name *xstats_names,
232 : : unsigned int size);
233 : : static int eth_igc_xstats_get_names_by_id(struct rte_eth_dev *dev,
234 : : const uint64_t *ids, struct rte_eth_xstat_name *xstats_names,
235 : : unsigned int limit);
236 : : static int eth_igc_xstats_reset(struct rte_eth_dev *dev);
237 : : static int
238 : : eth_igc_queue_stats_mapping_set(struct rte_eth_dev *dev,
239 : : uint16_t queue_id, uint8_t stat_idx, uint8_t is_rx);
240 : : static int
241 : : eth_igc_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id);
242 : : static int
243 : : eth_igc_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
244 : : static int
245 : : eth_igc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf);
246 : : static int
247 : : eth_igc_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf);
248 : : static int eth_igc_rss_reta_update(struct rte_eth_dev *dev,
249 : : struct rte_eth_rss_reta_entry64 *reta_conf,
250 : : uint16_t reta_size);
251 : : static int eth_igc_rss_reta_query(struct rte_eth_dev *dev,
252 : : struct rte_eth_rss_reta_entry64 *reta_conf,
253 : : uint16_t reta_size);
254 : : static int eth_igc_rss_hash_update(struct rte_eth_dev *dev,
255 : : struct rte_eth_rss_conf *rss_conf);
256 : : static int eth_igc_rss_hash_conf_get(struct rte_eth_dev *dev,
257 : : struct rte_eth_rss_conf *rss_conf);
258 : : static int
259 : : eth_igc_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
260 : : static int eth_igc_vlan_offload_set(struct rte_eth_dev *dev, int mask);
261 : : static int eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
262 : : enum rte_vlan_type vlan_type, uint16_t tpid);
263 : : static int eth_igc_timesync_enable(struct rte_eth_dev *dev);
264 : : static int eth_igc_timesync_disable(struct rte_eth_dev *dev);
265 : : static int eth_igc_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
266 : : struct timespec *timestamp,
267 : : uint32_t flags);
268 : : static int eth_igc_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
269 : : struct timespec *timestamp);
270 : : static int eth_igc_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
271 : : static int eth_igc_timesync_read_time(struct rte_eth_dev *dev,
272 : : struct timespec *timestamp);
273 : : static int eth_igc_timesync_write_time(struct rte_eth_dev *dev,
274 : : const struct timespec *timestamp);
275 : : static int eth_igc_read_clock(struct rte_eth_dev *dev, uint64_t *clock);
276 : :
277 : : static const struct eth_dev_ops eth_igc_ops = {
278 : : .dev_configure = eth_igc_configure,
279 : : .link_update = eth_igc_link_update,
280 : : .dev_stop = eth_igc_stop,
281 : : .dev_start = eth_igc_start,
282 : : .dev_close = eth_igc_close,
283 : : .dev_reset = eth_igc_reset,
284 : : .dev_set_link_up = eth_igc_set_link_up,
285 : : .dev_set_link_down = eth_igc_set_link_down,
286 : : .promiscuous_enable = eth_igc_promiscuous_enable,
287 : : .promiscuous_disable = eth_igc_promiscuous_disable,
288 : : .allmulticast_enable = eth_igc_allmulticast_enable,
289 : : .allmulticast_disable = eth_igc_allmulticast_disable,
290 : : .fw_version_get = eth_igc_fw_version_get,
291 : : .dev_infos_get = eth_igc_infos_get,
292 : : .dev_led_on = eth_igc_led_on,
293 : : .dev_led_off = eth_igc_led_off,
294 : : .dev_supported_ptypes_get = eth_igc_supported_ptypes_get,
295 : : .mtu_set = eth_igc_mtu_set,
296 : : .mac_addr_add = eth_igc_rar_set,
297 : : .mac_addr_remove = eth_igc_rar_clear,
298 : : .mac_addr_set = eth_igc_default_mac_addr_set,
299 : : .set_mc_addr_list = eth_igc_set_mc_addr_list,
300 : :
301 : : .rx_queue_setup = eth_igc_rx_queue_setup,
302 : : .rx_queue_release = eth_igc_rx_queue_release,
303 : : .tx_queue_setup = eth_igc_tx_queue_setup,
304 : : .tx_queue_release = eth_igc_tx_queue_release,
305 : : .tx_done_cleanup = eth_igc_tx_done_cleanup,
306 : : .rxq_info_get = eth_igc_rxq_info_get,
307 : : .txq_info_get = eth_igc_txq_info_get,
308 : : .stats_get = eth_igc_stats_get,
309 : : .xstats_get = eth_igc_xstats_get,
310 : : .xstats_get_by_id = eth_igc_xstats_get_by_id,
311 : : .xstats_get_names_by_id = eth_igc_xstats_get_names_by_id,
312 : : .xstats_get_names = eth_igc_xstats_get_names,
313 : : .stats_reset = eth_igc_xstats_reset,
314 : : .xstats_reset = eth_igc_xstats_reset,
315 : : .queue_stats_mapping_set = eth_igc_queue_stats_mapping_set,
316 : : .rx_queue_intr_enable = eth_igc_rx_queue_intr_enable,
317 : : .rx_queue_intr_disable = eth_igc_rx_queue_intr_disable,
318 : : .flow_ctrl_get = eth_igc_flow_ctrl_get,
319 : : .flow_ctrl_set = eth_igc_flow_ctrl_set,
320 : : .reta_update = eth_igc_rss_reta_update,
321 : : .reta_query = eth_igc_rss_reta_query,
322 : : .rss_hash_update = eth_igc_rss_hash_update,
323 : : .rss_hash_conf_get = eth_igc_rss_hash_conf_get,
324 : : .vlan_filter_set = eth_igc_vlan_filter_set,
325 : : .vlan_offload_set = eth_igc_vlan_offload_set,
326 : : .vlan_tpid_set = eth_igc_vlan_tpid_set,
327 : : .vlan_strip_queue_set = eth_igc_vlan_strip_queue_set,
328 : : .flow_ops_get = eth_igc_flow_ops_get,
329 : : .timesync_enable = eth_igc_timesync_enable,
330 : : .timesync_disable = eth_igc_timesync_disable,
331 : : .timesync_read_rx_timestamp = eth_igc_timesync_read_rx_timestamp,
332 : : .timesync_read_tx_timestamp = eth_igc_timesync_read_tx_timestamp,
333 : : .timesync_adjust_time = eth_igc_timesync_adjust_time,
334 : : .timesync_read_time = eth_igc_timesync_read_time,
335 : : .timesync_write_time = eth_igc_timesync_write_time,
336 : : .read_clock = eth_igc_read_clock,
337 : : };
338 : :
339 : : /*
340 : : * multiple queue mode checking
341 : : */
342 : : static int
343 : 0 : igc_check_mq_mode(struct rte_eth_dev *dev)
344 : : {
345 : 0 : enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
346 : 0 : enum rte_eth_tx_mq_mode tx_mq_mode = dev->data->dev_conf.txmode.mq_mode;
347 : :
348 [ # # ]: 0 : if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
349 : 0 : PMD_INIT_LOG(ERR, "SRIOV is not supported.");
350 : 0 : return -EINVAL;
351 : : }
352 : :
353 [ # # ]: 0 : if (rx_mq_mode != RTE_ETH_MQ_RX_NONE &&
354 : : rx_mq_mode != RTE_ETH_MQ_RX_RSS) {
355 : : /* RSS together with VMDq not supported*/
356 : 0 : PMD_INIT_LOG(ERR, "RX mode %d is not supported.",
357 : : rx_mq_mode);
358 : 0 : return -EINVAL;
359 : : }
360 : :
361 : : /* To no break software that set invalid mode, only display
362 : : * warning if invalid mode is used.
363 : : */
364 [ # # ]: 0 : if (tx_mq_mode != RTE_ETH_MQ_TX_NONE)
365 : 0 : PMD_INIT_LOG(WARNING,
366 : : "TX mode %d is not supported. Due to meaningless in this driver, just ignore",
367 : : tx_mq_mode);
368 : :
369 : : return 0;
370 : : }
371 : :
372 : : static int
373 : 0 : eth_igc_configure(struct rte_eth_dev *dev)
374 : : {
375 : 0 : struct igc_interrupt *intr = IGC_DEV_PRIVATE_INTR(dev);
376 : : int ret;
377 : :
378 : 0 : PMD_INIT_FUNC_TRACE();
379 : :
380 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
381 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
382 : :
383 : 0 : ret = igc_check_mq_mode(dev);
384 [ # # ]: 0 : if (ret != 0)
385 : : return ret;
386 : :
387 : 0 : intr->flags |= IGC_FLAG_NEED_LINK_UPDATE;
388 : 0 : return 0;
389 : : }
390 : :
391 : : static int
392 : 0 : eth_igc_set_link_up(struct rte_eth_dev *dev)
393 : : {
394 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
395 : :
396 [ # # ]: 0 : if (hw->phy.media_type == igc_media_type_copper)
397 : 0 : igc_power_up_phy(hw);
398 : : else
399 : 0 : igc_power_up_fiber_serdes_link(hw);
400 : 0 : return 0;
401 : : }
402 : :
403 : : static int
404 : 0 : eth_igc_set_link_down(struct rte_eth_dev *dev)
405 : : {
406 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
407 : :
408 [ # # ]: 0 : if (hw->phy.media_type == igc_media_type_copper)
409 : 0 : igc_power_down_phy(hw);
410 : : else
411 : 0 : igc_shutdown_fiber_serdes_link(hw);
412 : 0 : return 0;
413 : : }
414 : :
415 : : /*
416 : : * disable other interrupt
417 : : */
418 : : static void
419 : 0 : igc_intr_other_disable(struct rte_eth_dev *dev)
420 : : {
421 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
422 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
423 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
424 : :
425 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle) &&
426 [ # # ]: 0 : dev->data->dev_conf.intr_conf.lsc) {
427 : 0 : IGC_WRITE_REG(hw, IGC_EIMC, 1u << IGC_MSIX_OTHER_INTR_VEC);
428 : : }
429 : :
430 : 0 : IGC_WRITE_REG(hw, IGC_IMC, ~0);
431 : 0 : IGC_WRITE_FLUSH(hw);
432 : 0 : }
433 : :
434 : : /*
435 : : * enable other interrupt
436 : : */
437 : : static inline void
438 : 0 : igc_intr_other_enable(struct rte_eth_dev *dev)
439 : : {
440 : 0 : struct igc_interrupt *intr = IGC_DEV_PRIVATE_INTR(dev);
441 : : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
442 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
443 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
444 : :
445 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle) &&
446 [ # # ]: 0 : dev->data->dev_conf.intr_conf.lsc) {
447 : 0 : IGC_WRITE_REG(hw, IGC_EIMS, 1u << IGC_MSIX_OTHER_INTR_VEC);
448 : : }
449 : :
450 : 0 : IGC_WRITE_REG(hw, IGC_IMS, intr->mask);
451 : 0 : IGC_WRITE_FLUSH(hw);
452 : 0 : }
453 : :
454 : : /*
455 : : * It reads ICR and gets interrupt causes, check it and set a bit flag
456 : : * to update link status.
457 : : */
458 : : static void
459 : : eth_igc_interrupt_get_status(struct rte_eth_dev *dev)
460 : : {
461 : : uint32_t icr;
462 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
463 : : struct igc_interrupt *intr = IGC_DEV_PRIVATE_INTR(dev);
464 : :
465 : : /* read-on-clear nic registers here */
466 : 0 : icr = IGC_READ_REG(hw, IGC_ICR);
467 : :
468 : 0 : intr->flags = 0;
469 [ # # ]: 0 : if (icr & IGC_ICR_LSC)
470 : 0 : intr->flags |= IGC_FLAG_NEED_LINK_UPDATE;
471 : : }
472 : :
473 : : /* return 0 means link status changed, -1 means not changed */
474 : : static int
475 : 0 : eth_igc_link_update(struct rte_eth_dev *dev, int wait_to_complete)
476 : : {
477 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
478 : : struct rte_eth_link link;
479 : : int link_check, count;
480 : :
481 : : link_check = 0;
482 : 0 : hw->mac.get_link_status = 1;
483 : :
484 : : /* possible wait-to-complete in up to 9 seconds */
485 [ # # ]: 0 : for (count = 0; count < IGC_LINK_UPDATE_CHECK_TIMEOUT; count++) {
486 : : /* Read the real link status */
487 [ # # # # ]: 0 : switch (hw->phy.media_type) {
488 : 0 : case igc_media_type_copper:
489 : : /* Do the work to read phy */
490 : 0 : igc_check_for_link(hw);
491 : 0 : link_check = !hw->mac.get_link_status;
492 : 0 : break;
493 : :
494 : 0 : case igc_media_type_fiber:
495 : 0 : igc_check_for_link(hw);
496 : 0 : link_check = (IGC_READ_REG(hw, IGC_STATUS) &
497 : : IGC_STATUS_LU);
498 : 0 : break;
499 : :
500 : 0 : case igc_media_type_internal_serdes:
501 : 0 : igc_check_for_link(hw);
502 : 0 : link_check = hw->mac.serdes_has_link;
503 : 0 : break;
504 : :
505 : : default:
506 : : break;
507 : : }
508 [ # # ]: 0 : if (link_check || wait_to_complete == 0)
509 : : break;
510 : : rte_delay_ms(IGC_LINK_UPDATE_CHECK_INTERVAL);
511 : : }
512 : : memset(&link, 0, sizeof(link));
513 : :
514 : : /* Now we check if a transition has happened */
515 [ # # ]: 0 : if (link_check) {
516 : : uint16_t duplex, speed;
517 : 0 : hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
518 : 0 : link.link_duplex = (duplex == FULL_DUPLEX) ?
519 : 0 : RTE_ETH_LINK_FULL_DUPLEX :
520 : : RTE_ETH_LINK_HALF_DUPLEX;
521 : 0 : link.link_speed = speed;
522 : 0 : link.link_status = RTE_ETH_LINK_UP;
523 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
524 : : RTE_ETH_LINK_SPEED_FIXED);
525 : :
526 [ # # ]: 0 : if (speed == SPEED_2500) {
527 : 0 : uint32_t tipg = IGC_READ_REG(hw, IGC_TIPG);
528 [ # # ]: 0 : if ((tipg & IGC_TIPG_IPGT_MASK) != 0x0b) {
529 : 0 : tipg &= ~IGC_TIPG_IPGT_MASK;
530 : 0 : tipg |= 0x0b;
531 : 0 : IGC_WRITE_REG(hw, IGC_TIPG, tipg);
532 : : }
533 : : }
534 : : } else {
535 : : link.link_speed = 0;
536 : : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
537 : : link.link_status = RTE_ETH_LINK_DOWN;
538 : : link.link_autoneg = RTE_ETH_LINK_FIXED;
539 : : }
540 : :
541 : 0 : return rte_eth_linkstatus_set(dev, &link);
542 : : }
543 : :
544 : : /*
545 : : * It executes link_update after knowing an interrupt is present.
546 : : */
547 : : static void
548 : 0 : eth_igc_interrupt_action(struct rte_eth_dev *dev)
549 : : {
550 : 0 : struct igc_interrupt *intr = IGC_DEV_PRIVATE_INTR(dev);
551 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
552 : : struct rte_eth_link link;
553 : : int ret;
554 : :
555 [ # # ]: 0 : if (intr->flags & IGC_FLAG_NEED_LINK_UPDATE) {
556 : 0 : intr->flags &= ~IGC_FLAG_NEED_LINK_UPDATE;
557 : :
558 : : /* set get_link_status to check register later */
559 : 0 : ret = eth_igc_link_update(dev, 0);
560 : :
561 : : /* check if link has changed */
562 [ # # ]: 0 : if (ret < 0)
563 : 0 : return;
564 : :
565 : 0 : rte_eth_linkstatus_get(dev, &link);
566 [ # # ]: 0 : if (link.link_status)
567 [ # # ]: 0 : PMD_DRV_LOG(INFO,
568 : : " Port %d: Link Up - speed %u Mbps - %s",
569 : : dev->data->port_id,
570 : : (unsigned int)link.link_speed,
571 : : link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
572 : : "full-duplex" : "half-duplex");
573 : : else
574 : 0 : PMD_DRV_LOG(INFO, " Port %d: Link Down",
575 : : dev->data->port_id);
576 : :
577 : 0 : PMD_DRV_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
578 : : pci_dev->addr.domain,
579 : : pci_dev->addr.bus,
580 : : pci_dev->addr.devid,
581 : : pci_dev->addr.function);
582 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
583 : : }
584 : : }
585 : :
586 : : /*
587 : : * Interrupt handler which shall be registered at first.
588 : : *
589 : : * @handle
590 : : * Pointer to interrupt handle.
591 : : * @param
592 : : * The address of parameter (struct rte_eth_dev *) registered before.
593 : : */
594 : : static void
595 : 0 : eth_igc_interrupt_handler(void *param)
596 : : {
597 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
598 : :
599 : : eth_igc_interrupt_get_status(dev);
600 : 0 : eth_igc_interrupt_action(dev);
601 : 0 : }
602 : :
603 : : static void igc_read_queue_stats_register(struct rte_eth_dev *dev);
604 : :
605 : : /*
606 : : * Update the queue status every IGC_ALARM_INTERVAL time.
607 : : * @param
608 : : * The address of parameter (struct rte_eth_dev *) registered before.
609 : : */
610 : : static void
611 : 0 : igc_update_queue_stats_handler(void *param)
612 : : {
613 : : struct rte_eth_dev *dev = param;
614 : 0 : igc_read_queue_stats_register(dev);
615 : 0 : rte_eal_alarm_set(IGC_ALARM_INTERVAL,
616 : : igc_update_queue_stats_handler, dev);
617 : 0 : }
618 : :
619 : : /*
620 : : * rx,tx enable/disable
621 : : */
622 : : static void
623 : 0 : eth_igc_rxtx_control(struct rte_eth_dev *dev, bool enable)
624 : : {
625 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
626 : : uint32_t tctl, rctl;
627 : :
628 : 0 : tctl = IGC_READ_REG(hw, IGC_TCTL);
629 : 0 : rctl = IGC_READ_REG(hw, IGC_RCTL);
630 : :
631 [ # # ]: 0 : if (enable) {
632 : : /* enable Tx/Rx */
633 : 0 : tctl |= IGC_TCTL_EN;
634 : 0 : rctl |= IGC_RCTL_EN;
635 : : } else {
636 : : /* disable Tx/Rx */
637 : 0 : tctl &= ~IGC_TCTL_EN;
638 : 0 : rctl &= ~IGC_RCTL_EN;
639 : : }
640 : 0 : IGC_WRITE_REG(hw, IGC_TCTL, tctl);
641 : 0 : IGC_WRITE_REG(hw, IGC_RCTL, rctl);
642 : 0 : IGC_WRITE_FLUSH(hw);
643 : 0 : }
644 : :
645 : : /*
646 : : * This routine disables all traffic on the adapter by issuing a
647 : : * global reset on the MAC.
648 : : */
649 : : static int
650 : 0 : eth_igc_stop(struct rte_eth_dev *dev)
651 : : {
652 : 0 : struct igc_adapter *adapter = IGC_DEV_PRIVATE(dev);
653 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
654 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
655 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
656 : : struct rte_eth_link link;
657 : :
658 : 0 : dev->data->dev_started = 0;
659 : 0 : adapter->stopped = 1;
660 : :
661 : : /* disable receive and transmit */
662 : 0 : eth_igc_rxtx_control(dev, false);
663 : :
664 : : /* disable all MSI-X interrupts */
665 : 0 : IGC_WRITE_REG(hw, IGC_EIMC, 0x1f);
666 : 0 : IGC_WRITE_FLUSH(hw);
667 : :
668 : : /* clear all MSI-X interrupts */
669 : 0 : IGC_WRITE_REG(hw, IGC_EICR, 0x1f);
670 : :
671 : 0 : igc_intr_other_disable(dev);
672 : :
673 : 0 : rte_eal_alarm_cancel(igc_update_queue_stats_handler, dev);
674 : :
675 : : /* disable intr eventfd mapping */
676 : 0 : rte_intr_disable(intr_handle);
677 : :
678 : 0 : igc_reset_hw(hw);
679 : :
680 : : /* disable all wake up */
681 : 0 : IGC_WRITE_REG(hw, IGC_WUC, 0);
682 : :
683 : : /* disable checking EEE operation in MAC loopback mode */
684 : : igc_read_reg_check_clear_bits(hw, IGC_EEER, IGC_EEER_EEE_FRC_AN);
685 : :
686 : : /* Set bit for Go Link disconnect */
687 : : igc_read_reg_check_set_bits(hw, IGC_82580_PHY_POWER_MGMT,
688 : : IGC_82580_PM_GO_LINKD);
689 : :
690 : : /* Power down the phy. Needed to make the link go Down */
691 : 0 : eth_igc_set_link_down(dev);
692 : :
693 : 0 : igc_dev_clear_queues(dev);
694 : :
695 : : /* clear the recorded link status */
696 : : memset(&link, 0, sizeof(link));
697 : 0 : rte_eth_linkstatus_set(dev, &link);
698 : :
699 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
700 : : /* resume to the default handler */
701 : 0 : rte_intr_callback_register(intr_handle,
702 : : eth_igc_interrupt_handler,
703 : : (void *)dev);
704 : :
705 : : /* Clean datapath event and queue/vec mapping */
706 : 0 : rte_intr_efd_disable(intr_handle);
707 : 0 : rte_intr_vec_list_free(intr_handle);
708 : :
709 : 0 : return 0;
710 : : }
711 : :
712 : : /*
713 : : * write interrupt vector allocation register
714 : : * @hw
715 : : * board private structure
716 : : * @queue_index
717 : : * queue index, valid 0,1,2,3
718 : : * @tx
719 : : * tx:1, rx:0
720 : : * @msix_vector
721 : : * msix-vector, valid 0,1,2,3,4
722 : : */
723 : : static void
724 : : igc_write_ivar(struct igc_hw *hw, uint8_t queue_index,
725 : : bool tx, uint8_t msix_vector)
726 : : {
727 : : uint8_t offset = 0;
728 : 0 : uint8_t reg_index = queue_index >> 1;
729 : : uint32_t val;
730 : :
731 : : /*
732 : : * IVAR(0)
733 : : * bit31...24 bit23...16 bit15...8 bit7...0
734 : : * TX1 RX1 TX0 RX0
735 : : *
736 : : * IVAR(1)
737 : : * bit31...24 bit23...16 bit15...8 bit7...0
738 : : * TX3 RX3 TX2 RX2
739 : : */
740 : :
741 : : if (tx)
742 : : offset = 8;
743 : :
744 : 0 : if (queue_index & 1)
745 : : offset += 16;
746 : :
747 : 0 : val = IGC_READ_REG_ARRAY(hw, IGC_IVAR0, reg_index);
748 : :
749 : : /* clear bits */
750 : 0 : val &= ~((uint32_t)0xFF << offset);
751 : :
752 : : /* write vector and valid bit */
753 : 0 : val |= (uint32_t)(msix_vector | IGC_IVAR_VALID) << offset;
754 : :
755 : 0 : IGC_WRITE_REG_ARRAY(hw, IGC_IVAR0, reg_index, val);
756 : : }
757 : :
758 : : /* Sets up the hardware to generate MSI-X interrupts properly
759 : : * @hw
760 : : * board private structure
761 : : */
762 : : static void
763 : 0 : igc_configure_msix_intr(struct rte_eth_dev *dev)
764 : : {
765 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
766 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
767 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
768 : :
769 : : uint32_t intr_mask;
770 : : uint32_t vec = IGC_MISC_VEC_ID;
771 : : uint32_t base = IGC_MISC_VEC_ID;
772 : : uint32_t misc_shift = 0;
773 : : int i, nb_efd;
774 : :
775 : : /* won't configure msix register if no mapping is done
776 : : * between intr vector and event fd
777 : : */
778 [ # # ]: 0 : if (!rte_intr_dp_is_en(intr_handle))
779 : : return;
780 : :
781 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
782 : : base = IGC_RX_VEC_START;
783 : : vec = base;
784 : : misc_shift = 1;
785 : : }
786 : :
787 : : /* turn on MSI-X capability first */
788 : 0 : IGC_WRITE_REG(hw, IGC_GPIE, IGC_GPIE_MSIX_MODE |
789 : : IGC_GPIE_PBA | IGC_GPIE_EIAME |
790 : : IGC_GPIE_NSICR);
791 : :
792 : 0 : nb_efd = rte_intr_nb_efd_get(intr_handle);
793 [ # # ]: 0 : if (nb_efd < 0)
794 : : return;
795 : :
796 : 0 : intr_mask = RTE_LEN2MASK(nb_efd, uint32_t) << misc_shift;
797 : :
798 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc)
799 : 0 : intr_mask |= (1u << IGC_MSIX_OTHER_INTR_VEC);
800 : :
801 : : /* enable msix auto-clear */
802 : : igc_read_reg_check_set_bits(hw, IGC_EIAC, intr_mask);
803 : :
804 : : /* set other cause interrupt vector */
805 : : igc_read_reg_check_set_bits(hw, IGC_IVAR_MISC,
806 : : (uint32_t)(IGC_MSIX_OTHER_INTR_VEC | IGC_IVAR_VALID) << 8);
807 : :
808 : : /* enable auto-mask */
809 : : igc_read_reg_check_set_bits(hw, IGC_EIAM, intr_mask);
810 : :
811 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
812 [ # # ]: 0 : igc_write_ivar(hw, i, 0, vec);
813 : 0 : rte_intr_vec_list_index_set(intr_handle, i, vec);
814 [ # # ]: 0 : if (vec < base + rte_intr_nb_efd_get(intr_handle) - 1)
815 : 0 : vec++;
816 : : }
817 : :
818 : 0 : IGC_WRITE_FLUSH(hw);
819 : : }
820 : :
821 : : /**
822 : : * It enables the interrupt mask and then enable the interrupt.
823 : : *
824 : : * @dev
825 : : * Pointer to struct rte_eth_dev.
826 : : * @on
827 : : * Enable or Disable
828 : : */
829 : : static void
830 : : igc_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
831 : : {
832 : 0 : struct igc_interrupt *intr = IGC_DEV_PRIVATE_INTR(dev);
833 : :
834 : : if (on)
835 : 0 : intr->mask |= IGC_ICR_LSC;
836 : : else
837 : 0 : intr->mask &= ~IGC_ICR_LSC;
838 : : }
839 : :
840 : : /*
841 : : * It enables the interrupt.
842 : : * It will be called once only during nic initialized.
843 : : */
844 : : static void
845 : 0 : igc_rxq_interrupt_setup(struct rte_eth_dev *dev)
846 : : {
847 : : uint32_t mask;
848 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
849 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
850 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
851 : 0 : int misc_shift = rte_intr_allow_others(intr_handle) ? 1 : 0;
852 : : int nb_efd;
853 : :
854 : : /* won't configure msix register if no mapping is done
855 : : * between intr vector and event fd
856 : : */
857 [ # # ]: 0 : if (!rte_intr_dp_is_en(intr_handle))
858 : : return;
859 : :
860 : 0 : nb_efd = rte_intr_nb_efd_get(intr_handle);
861 [ # # ]: 0 : if (nb_efd < 0)
862 : : return;
863 : :
864 : 0 : mask = RTE_LEN2MASK(nb_efd, uint32_t) << misc_shift;
865 : 0 : IGC_WRITE_REG(hw, IGC_EIMS, mask);
866 : : }
867 : :
868 : : /*
869 : : * Get hardware rx-buffer size.
870 : : */
871 : : static inline int
872 : : igc_get_rx_buffer_size(struct igc_hw *hw)
873 : : {
874 : 0 : return (IGC_READ_REG(hw, IGC_RXPBS) & 0x3f) << 10;
875 : : }
876 : :
877 : : /*
878 : : * igc_hw_control_acquire sets CTRL_EXT:DRV_LOAD bit.
879 : : * For ASF and Pass Through versions of f/w this means
880 : : * that the driver is loaded.
881 : : */
882 : : static void
883 : : igc_hw_control_acquire(struct igc_hw *hw)
884 : : {
885 : : uint32_t ctrl_ext;
886 : :
887 : : /* Let firmware know the driver has taken over */
888 : 0 : ctrl_ext = IGC_READ_REG(hw, IGC_CTRL_EXT);
889 : 0 : IGC_WRITE_REG(hw, IGC_CTRL_EXT, ctrl_ext | IGC_CTRL_EXT_DRV_LOAD);
890 : : }
891 : :
892 : : /*
893 : : * igc_hw_control_release resets CTRL_EXT:DRV_LOAD bit.
894 : : * For ASF and Pass Through versions of f/w this means that the
895 : : * driver is no longer loaded.
896 : : */
897 : : static void
898 : : igc_hw_control_release(struct igc_hw *hw)
899 : : {
900 : : uint32_t ctrl_ext;
901 : :
902 : : /* Let firmware taken over control of h/w */
903 : 0 : ctrl_ext = IGC_READ_REG(hw, IGC_CTRL_EXT);
904 : 0 : IGC_WRITE_REG(hw, IGC_CTRL_EXT,
905 : : ctrl_ext & ~IGC_CTRL_EXT_DRV_LOAD);
906 : : }
907 : :
908 : : static int
909 : 0 : igc_hardware_init(struct igc_hw *hw)
910 : : {
911 : : uint32_t rx_buf_size;
912 : : int diag;
913 : :
914 : : /* Let the firmware know the OS is in control */
915 : : igc_hw_control_acquire(hw);
916 : :
917 : : /* Issue a global reset */
918 : 0 : igc_reset_hw(hw);
919 : :
920 : : /* disable all wake up */
921 : 0 : IGC_WRITE_REG(hw, IGC_WUC, 0);
922 : :
923 : : /*
924 : : * Hardware flow control
925 : : * - High water mark should allow for at least two standard size (1518)
926 : : * frames to be received after sending an XOFF.
927 : : * - Low water mark works best when it is very near the high water mark.
928 : : * This allows the receiver to restart by sending XON when it has
929 : : * drained a bit. Here we use an arbitrary value of 1500 which will
930 : : * restart after one full frame is pulled from the buffer. There
931 : : * could be several smaller frames in the buffer and if so they will
932 : : * not trigger the XON until their total number reduces the buffer
933 : : * by 1500.
934 : : */
935 : 0 : rx_buf_size = igc_get_rx_buffer_size(hw);
936 : 0 : hw->fc.high_water = rx_buf_size - (RTE_ETHER_MAX_LEN * 2);
937 : 0 : hw->fc.low_water = hw->fc.high_water - 1500;
938 : 0 : hw->fc.pause_time = IGC_FC_PAUSE_TIME;
939 : 0 : hw->fc.send_xon = 1;
940 : 0 : hw->fc.requested_mode = igc_fc_full;
941 : :
942 : 0 : diag = igc_init_hw(hw);
943 [ # # ]: 0 : if (diag < 0)
944 : : return diag;
945 : :
946 : 0 : igc_get_phy_info(hw);
947 : 0 : igc_check_for_link(hw);
948 : :
949 : 0 : return 0;
950 : : }
951 : :
952 : : static int
953 : 0 : eth_igc_start(struct rte_eth_dev *dev)
954 : : {
955 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
956 : : struct igc_adapter *adapter = IGC_DEV_PRIVATE(dev);
957 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
958 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
959 : : uint32_t nsec, sec, baset_l, baset_h, tqavctrl;
960 : : struct timespec system_time;
961 : : int64_t n, systime;
962 : : uint32_t txqctl = 0;
963 : : uint32_t *speeds;
964 : : uint16_t i;
965 : : int ret;
966 : :
967 : 0 : PMD_INIT_FUNC_TRACE();
968 : :
969 : : /* disable all MSI-X interrupts */
970 : 0 : IGC_WRITE_REG(hw, IGC_EIMC, 0x1f);
971 : 0 : IGC_WRITE_FLUSH(hw);
972 : :
973 : : /* clear all MSI-X interrupts */
974 : 0 : IGC_WRITE_REG(hw, IGC_EICR, 0x1f);
975 : :
976 : : /* disable uio/vfio intr/eventfd mapping */
977 [ # # ]: 0 : if (!adapter->stopped)
978 : 0 : rte_intr_disable(intr_handle);
979 : :
980 : : /* Power up the phy. Needed to make the link go Up */
981 : 0 : eth_igc_set_link_up(dev);
982 : :
983 : : /* Put the address into the Receive Address Array */
984 : 0 : igc_rar_set(hw, hw->mac.addr, 0);
985 : :
986 : : /* Initialize the hardware */
987 [ # # ]: 0 : if (igc_hardware_init(hw)) {
988 : 0 : PMD_DRV_LOG(ERR, "Unable to initialize the hardware");
989 : 0 : return -EIO;
990 : : }
991 : 0 : adapter->stopped = 0;
992 : :
993 : : /* check and configure queue intr-vector mapping */
994 [ # # ]: 0 : if (rte_intr_cap_multiple(intr_handle) &&
995 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq) {
996 : 0 : uint32_t intr_vector = dev->data->nb_rx_queues;
997 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector))
998 : : return -1;
999 : : }
1000 : :
1001 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
1002 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
1003 : 0 : dev->data->nb_rx_queues)) {
1004 : 0 : PMD_DRV_LOG(ERR,
1005 : : "Failed to allocate %d rx_queues intr_vec",
1006 : : dev->data->nb_rx_queues);
1007 : 0 : return -ENOMEM;
1008 : : }
1009 : : }
1010 : :
1011 : : /* configure msix for rx interrupt */
1012 : 0 : igc_configure_msix_intr(dev);
1013 : :
1014 : 0 : igc_tx_init(dev);
1015 : :
1016 : : /* This can fail when allocating mbufs for descriptor rings */
1017 : 0 : ret = igc_rx_init(dev);
1018 [ # # ]: 0 : if (ret) {
1019 : 0 : PMD_DRV_LOG(ERR, "Unable to initialize RX hardware");
1020 : 0 : igc_dev_clear_queues(dev);
1021 : 0 : return ret;
1022 : : }
1023 : :
1024 [ # # ]: 0 : if (igc_tx_timestamp_dynflag > 0) {
1025 : 0 : adapter->base_time = 0;
1026 : 0 : adapter->cycle_time = NSEC_PER_SEC;
1027 : :
1028 : 0 : IGC_WRITE_REG(hw, IGC_TSSDP, 0);
1029 : 0 : IGC_WRITE_REG(hw, IGC_TSIM, TSINTR_TXTS);
1030 : 0 : IGC_WRITE_REG(hw, IGC_IMS, IGC_ICR_TS);
1031 : :
1032 : 0 : IGC_WRITE_REG(hw, IGC_TSAUXC, 0);
1033 : 0 : IGC_WRITE_REG(hw, IGC_I350_DTXMXPKTSZ, IGC_DTXMXPKTSZ_TSN);
1034 : 0 : IGC_WRITE_REG(hw, IGC_TXPBS, IGC_TXPBSIZE_TSN);
1035 : :
1036 : 0 : tqavctrl = IGC_READ_REG(hw, IGC_I210_TQAVCTRL);
1037 : 0 : tqavctrl |= IGC_TQAVCTRL_TRANSMIT_MODE_TSN |
1038 : : IGC_TQAVCTRL_ENHANCED_QAV;
1039 : 0 : IGC_WRITE_REG(hw, IGC_I210_TQAVCTRL, tqavctrl);
1040 : :
1041 : 0 : IGC_WRITE_REG(hw, IGC_QBVCYCLET_S, adapter->cycle_time);
1042 : 0 : IGC_WRITE_REG(hw, IGC_QBVCYCLET, adapter->cycle_time);
1043 : :
1044 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1045 : 0 : IGC_WRITE_REG(hw, IGC_STQT(i), 0);
1046 : 0 : IGC_WRITE_REG(hw, IGC_ENDQT(i), NSEC_PER_SEC);
1047 : :
1048 : : txqctl |= IGC_TXQCTL_QUEUE_MODE_LAUNCHT;
1049 : 0 : IGC_WRITE_REG(hw, IGC_TXQCTL(i), txqctl);
1050 : : }
1051 : :
1052 : 0 : clock_gettime(CLOCK_REALTIME, &system_time);
1053 : 0 : IGC_WRITE_REG(hw, IGC_SYSTIML, system_time.tv_nsec);
1054 : 0 : IGC_WRITE_REG(hw, IGC_SYSTIMH, system_time.tv_sec);
1055 : :
1056 : 0 : nsec = IGC_READ_REG(hw, IGC_SYSTIML);
1057 : 0 : sec = IGC_READ_REG(hw, IGC_SYSTIMH);
1058 : 0 : systime = (int64_t)sec * NSEC_PER_SEC + (int64_t)nsec;
1059 : :
1060 [ # # ]: 0 : if (systime > adapter->base_time) {
1061 : 0 : n = (systime - adapter->base_time) /
1062 : 0 : adapter->cycle_time;
1063 : 0 : adapter->base_time = adapter->base_time +
1064 : 0 : (n + 1) * adapter->cycle_time;
1065 : : }
1066 : :
1067 : 0 : baset_h = adapter->base_time / NSEC_PER_SEC;
1068 : 0 : baset_l = adapter->base_time % NSEC_PER_SEC;
1069 : 0 : IGC_WRITE_REG(hw, IGC_BASET_H, baset_h);
1070 : 0 : IGC_WRITE_REG(hw, IGC_BASET_L, baset_l);
1071 : : }
1072 : :
1073 : 0 : igc_clear_hw_cntrs_base_generic(hw);
1074 : :
1075 : : /* VLAN Offload Settings */
1076 : 0 : eth_igc_vlan_offload_set(dev,
1077 : : RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
1078 : : RTE_ETH_VLAN_EXTEND_MASK);
1079 : :
1080 : : /* Setup link speed and duplex */
1081 : 0 : speeds = &dev->data->dev_conf.link_speeds;
1082 [ # # ]: 0 : if (*speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
1083 : 0 : hw->phy.autoneg_advertised = IGC_ALL_SPEED_DUPLEX_2500;
1084 : 0 : hw->mac.autoneg = 1;
1085 : : } else {
1086 : : int num_speeds = 0;
1087 : :
1088 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_FIXED) {
1089 : 0 : PMD_DRV_LOG(ERR,
1090 : : "Force speed mode currently not supported");
1091 : 0 : igc_dev_clear_queues(dev);
1092 : 0 : return -EINVAL;
1093 : : }
1094 : :
1095 : 0 : hw->phy.autoneg_advertised = 0;
1096 : 0 : hw->mac.autoneg = 1;
1097 : :
1098 [ # # ]: 0 : if (*speeds & ~(RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
1099 : : RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
1100 : : RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_2_5G)) {
1101 : : num_speeds = -1;
1102 : 0 : goto error_invalid_config;
1103 : : }
1104 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_10M_HD) {
1105 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
1106 : : num_speeds++;
1107 : : }
1108 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_10M) {
1109 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
1110 : 0 : num_speeds++;
1111 : : }
1112 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_100M_HD) {
1113 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
1114 : 0 : num_speeds++;
1115 : : }
1116 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_100M) {
1117 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
1118 : 0 : num_speeds++;
1119 : : }
1120 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_1G) {
1121 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
1122 : 0 : num_speeds++;
1123 : : }
1124 [ # # ]: 0 : if (*speeds & RTE_ETH_LINK_SPEED_2_5G) {
1125 : 0 : hw->phy.autoneg_advertised |= ADVERTISE_2500_FULL;
1126 : 0 : num_speeds++;
1127 : : }
1128 [ # # ]: 0 : if (num_speeds == 0)
1129 : 0 : goto error_invalid_config;
1130 : : }
1131 : :
1132 : 0 : igc_setup_link(hw);
1133 : :
1134 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
1135 : : /* check if lsc interrupt is enabled */
1136 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc)
1137 : : igc_lsc_interrupt_setup(dev, 1);
1138 : : else
1139 : : igc_lsc_interrupt_setup(dev, 0);
1140 : : } else {
1141 : 0 : rte_intr_callback_unregister(intr_handle,
1142 : : eth_igc_interrupt_handler,
1143 : : (void *)dev);
1144 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc)
1145 : 0 : PMD_DRV_LOG(INFO,
1146 : : "LSC won't enable because of no intr multiplex");
1147 : : }
1148 : :
1149 : : /* enable uio/vfio intr/eventfd mapping */
1150 : 0 : rte_intr_enable(intr_handle);
1151 : :
1152 : 0 : rte_eal_alarm_set(IGC_ALARM_INTERVAL,
1153 : : igc_update_queue_stats_handler, dev);
1154 : :
1155 : : /* check if rxq interrupt is enabled */
1156 [ # # # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq &&
1157 : 0 : rte_intr_dp_is_en(intr_handle))
1158 : 0 : igc_rxq_interrupt_setup(dev);
1159 : :
1160 : : /* resume enabled intr since hw reset */
1161 : 0 : igc_intr_other_enable(dev);
1162 : :
1163 : 0 : eth_igc_rxtx_control(dev, true);
1164 : 0 : eth_igc_link_update(dev, 0);
1165 : :
1166 : : /* configure MAC-loopback mode */
1167 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == 1) {
1168 : : uint32_t reg_val;
1169 : :
1170 : 0 : reg_val = IGC_READ_REG(hw, IGC_CTRL);
1171 : 0 : reg_val &= ~IGC_CTRL_SPEED_MASK;
1172 : 0 : reg_val |= IGC_CTRL_SLU | IGC_CTRL_FRCSPD |
1173 : : IGC_CTRL_FRCDPX | IGC_CTRL_FD | IGC_CTRL_SPEED_2500;
1174 : 0 : IGC_WRITE_REG(hw, IGC_CTRL, reg_val);
1175 : :
1176 : : igc_read_reg_check_set_bits(hw, IGC_EEER, IGC_EEER_EEE_FRC_AN);
1177 : : }
1178 : :
1179 : : return 0;
1180 : :
1181 : 0 : error_invalid_config:
1182 : 0 : PMD_DRV_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
1183 : : dev->data->dev_conf.link_speeds, dev->data->port_id);
1184 : 0 : igc_dev_clear_queues(dev);
1185 : 0 : return -EINVAL;
1186 : : }
1187 : :
1188 : : static int
1189 : 0 : igc_reset_swfw_lock(struct igc_hw *hw)
1190 : : {
1191 : : int ret_val;
1192 : :
1193 : : /*
1194 : : * Do mac ops initialization manually here, since we will need
1195 : : * some function pointers set by this call.
1196 : : */
1197 : 0 : ret_val = igc_init_mac_params(hw);
1198 [ # # ]: 0 : if (ret_val)
1199 : : return ret_val;
1200 : :
1201 : : /*
1202 : : * SMBI lock should not fail in this early stage. If this is the case,
1203 : : * it is due to an improper exit of the application.
1204 : : * So force the release of the faulty lock.
1205 : : */
1206 [ # # ]: 0 : if (igc_get_hw_semaphore_generic(hw) < 0)
1207 : 0 : PMD_DRV_LOG(DEBUG, "SMBI lock released");
1208 : :
1209 : 0 : igc_put_hw_semaphore_generic(hw);
1210 : :
1211 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync != NULL) {
1212 : : uint16_t mask;
1213 : :
1214 : : /*
1215 : : * Phy lock should not fail in this early stage.
1216 : : * If this is the case, it is due to an improper exit of the
1217 : : * application. So force the release of the faulty lock.
1218 : : */
1219 : : mask = IGC_SWFW_PHY0_SM;
1220 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0) {
1221 : 0 : PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released",
1222 : : hw->bus.func);
1223 : : }
1224 : 0 : hw->mac.ops.release_swfw_sync(hw, mask);
1225 : :
1226 : : /*
1227 : : * This one is more tricky since it is common to all ports; but
1228 : : * swfw_sync retries last long enough (1s) to be almost sure
1229 : : * that if lock can not be taken it is due to an improper lock
1230 : : * of the semaphore.
1231 : : */
1232 : : mask = IGC_SWFW_EEP_SM;
1233 [ # # ]: 0 : if (hw->mac.ops.acquire_swfw_sync(hw, mask) < 0)
1234 : 0 : PMD_DRV_LOG(DEBUG, "SWFW common locks released");
1235 : :
1236 : 0 : hw->mac.ops.release_swfw_sync(hw, mask);
1237 : : }
1238 : :
1239 : : return IGC_SUCCESS;
1240 : : }
1241 : :
1242 : : /*
1243 : : * free all rx/tx queues.
1244 : : */
1245 : : static void
1246 : 0 : igc_dev_free_queues(struct rte_eth_dev *dev)
1247 : : {
1248 : : uint16_t i;
1249 : :
1250 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1251 : 0 : eth_igc_rx_queue_release(dev, i);
1252 : 0 : dev->data->rx_queues[i] = NULL;
1253 : : }
1254 : 0 : dev->data->nb_rx_queues = 0;
1255 : :
1256 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1257 : 0 : eth_igc_tx_queue_release(dev, i);
1258 : 0 : dev->data->tx_queues[i] = NULL;
1259 : : }
1260 : 0 : dev->data->nb_tx_queues = 0;
1261 : 0 : }
1262 : :
1263 : : static int
1264 : 0 : eth_igc_close(struct rte_eth_dev *dev)
1265 : : {
1266 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1267 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1268 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1269 : : struct igc_adapter *adapter = IGC_DEV_PRIVATE(dev);
1270 : : int retry = 0;
1271 : : int ret = 0;
1272 : :
1273 : 0 : PMD_INIT_FUNC_TRACE();
1274 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1275 : : return 0;
1276 : :
1277 [ # # ]: 0 : if (!adapter->stopped)
1278 : 0 : ret = eth_igc_stop(dev);
1279 : :
1280 : 0 : igc_flow_flush(dev, NULL);
1281 : 0 : igc_clear_all_filter(dev);
1282 : :
1283 : 0 : igc_intr_other_disable(dev);
1284 : : do {
1285 : 0 : int ret = rte_intr_callback_unregister(intr_handle,
1286 : : eth_igc_interrupt_handler, dev);
1287 [ # # # # ]: 0 : if (ret >= 0 || ret == -ENOENT || ret == -EINVAL)
1288 : : break;
1289 : :
1290 : 0 : PMD_DRV_LOG(ERR, "intr callback unregister failed: %d", ret);
1291 : 0 : DELAY(200 * 1000); /* delay 200ms */
1292 [ # # ]: 0 : } while (retry++ < 5);
1293 : :
1294 : 0 : igc_phy_hw_reset(hw);
1295 : : igc_hw_control_release(hw);
1296 : 0 : igc_dev_free_queues(dev);
1297 : :
1298 : : /* Reset any pending lock */
1299 : 0 : igc_reset_swfw_lock(hw);
1300 : :
1301 : 0 : return ret;
1302 : : }
1303 : :
1304 : : static void
1305 : : igc_identify_hardware(struct rte_eth_dev *dev, struct rte_pci_device *pci_dev)
1306 : : {
1307 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1308 : :
1309 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
1310 : 0 : hw->device_id = pci_dev->id.device_id;
1311 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1312 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1313 : : }
1314 : :
1315 : : static int
1316 : 0 : eth_igc_dev_init(struct rte_eth_dev *dev)
1317 : : {
1318 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1319 : 0 : struct igc_adapter *igc = IGC_DEV_PRIVATE(dev);
1320 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1321 : : int i, error = 0;
1322 : :
1323 : 0 : PMD_INIT_FUNC_TRACE();
1324 : 0 : dev->dev_ops = ð_igc_ops;
1325 : 0 : dev->rx_queue_count = eth_igc_rx_queue_count;
1326 : 0 : dev->rx_descriptor_status = eth_igc_rx_descriptor_status;
1327 : 0 : dev->tx_descriptor_status = eth_igc_tx_descriptor_status;
1328 : :
1329 : : /*
1330 : : * for secondary processes, we don't initialize any further as primary
1331 : : * has already done this work. Only check we don't need a different
1332 : : * RX function.
1333 : : */
1334 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1335 : 0 : dev->rx_pkt_burst = igc_recv_pkts;
1336 [ # # ]: 0 : if (dev->data->scattered_rx)
1337 : 0 : dev->rx_pkt_burst = igc_recv_scattered_pkts;
1338 : :
1339 : 0 : dev->tx_pkt_burst = igc_xmit_pkts;
1340 : 0 : dev->tx_pkt_prepare = eth_igc_prep_pkts;
1341 : 0 : return 0;
1342 : : }
1343 : :
1344 : 0 : rte_eth_copy_pci_info(dev, pci_dev);
1345 : 0 : dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1346 : :
1347 : 0 : hw->back = pci_dev;
1348 : 0 : hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
1349 : :
1350 : : igc_identify_hardware(dev, pci_dev);
1351 [ # # ]: 0 : if (igc_setup_init_funcs(hw, false) != IGC_SUCCESS) {
1352 : : error = -EIO;
1353 : 0 : goto err_late;
1354 : : }
1355 : :
1356 : 0 : igc_get_bus_info(hw);
1357 : :
1358 : : /* Reset any pending lock */
1359 [ # # ]: 0 : if (igc_reset_swfw_lock(hw) != IGC_SUCCESS) {
1360 : : error = -EIO;
1361 : 0 : goto err_late;
1362 : : }
1363 : :
1364 : : /* Finish initialization */
1365 [ # # ]: 0 : if (igc_setup_init_funcs(hw, true) != IGC_SUCCESS) {
1366 : : error = -EIO;
1367 : 0 : goto err_late;
1368 : : }
1369 : :
1370 : 0 : hw->mac.autoneg = 1;
1371 : 0 : hw->phy.autoneg_wait_to_complete = 0;
1372 : 0 : hw->phy.autoneg_advertised = IGC_ALL_SPEED_DUPLEX_2500;
1373 : :
1374 : : /* Copper options */
1375 [ # # ]: 0 : if (hw->phy.media_type == igc_media_type_copper) {
1376 : 0 : hw->phy.mdix = 0; /* AUTO_ALL_MODES */
1377 : 0 : hw->phy.disable_polarity_correction = 0;
1378 : 0 : hw->phy.ms_type = igc_ms_hw_default;
1379 : : }
1380 : :
1381 : : /*
1382 : : * Start from a known state, this is important in reading the nvm
1383 : : * and mac from that.
1384 : : */
1385 : 0 : igc_reset_hw(hw);
1386 : :
1387 : : /* Make sure we have a good EEPROM before we read from it */
1388 [ # # ]: 0 : if (igc_validate_nvm_checksum(hw) < 0) {
1389 : : /*
1390 : : * Some PCI-E parts fail the first check due to
1391 : : * the link being in sleep state, call it again,
1392 : : * if it fails a second time its a real issue.
1393 : : */
1394 [ # # ]: 0 : if (igc_validate_nvm_checksum(hw) < 0) {
1395 : 0 : PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
1396 : : error = -EIO;
1397 : 0 : goto err_late;
1398 : : }
1399 : : }
1400 : :
1401 : : /* Read the permanent MAC address out of the EEPROM */
1402 [ # # ]: 0 : if (igc_read_mac_addr(hw) != 0) {
1403 : 0 : PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
1404 : : error = -EIO;
1405 : 0 : goto err_late;
1406 : : }
1407 : :
1408 : : /* Allocate memory for storing MAC addresses */
1409 : 0 : dev->data->mac_addrs = rte_zmalloc("igc",
1410 : 0 : RTE_ETHER_ADDR_LEN * hw->mac.rar_entry_count, 0);
1411 [ # # ]: 0 : if (dev->data->mac_addrs == NULL) {
1412 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d bytes for storing MAC",
1413 : : RTE_ETHER_ADDR_LEN * hw->mac.rar_entry_count);
1414 : : error = -ENOMEM;
1415 : 0 : goto err_late;
1416 : : }
1417 : :
1418 : : /* Copy the permanent MAC address */
1419 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1420 : : &dev->data->mac_addrs[0]);
1421 : :
1422 : : /* Now initialize the hardware */
1423 [ # # ]: 0 : if (igc_hardware_init(hw) != 0) {
1424 : 0 : PMD_INIT_LOG(ERR, "Hardware initialization failed");
1425 : 0 : rte_free(dev->data->mac_addrs);
1426 : 0 : dev->data->mac_addrs = NULL;
1427 : : error = -ENODEV;
1428 : 0 : goto err_late;
1429 : : }
1430 : :
1431 : 0 : hw->mac.get_link_status = 1;
1432 : 0 : igc->stopped = 0;
1433 : :
1434 : : /* Indicate SOL/IDER usage */
1435 [ # # ]: 0 : if (igc_check_reset_block(hw) < 0)
1436 : 0 : PMD_INIT_LOG(ERR,
1437 : : "PHY reset is blocked due to SOL/IDER session.");
1438 : :
1439 : 0 : PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
1440 : : dev->data->port_id, pci_dev->id.vendor_id,
1441 : : pci_dev->id.device_id);
1442 : :
1443 : 0 : rte_intr_callback_register(pci_dev->intr_handle,
1444 : : eth_igc_interrupt_handler, (void *)dev);
1445 : :
1446 : : /* enable uio/vfio intr/eventfd mapping */
1447 : 0 : rte_intr_enable(pci_dev->intr_handle);
1448 : :
1449 : : /* enable support intr */
1450 : 0 : igc_intr_other_enable(dev);
1451 : :
1452 : : /* initiate queue status */
1453 [ # # ]: 0 : for (i = 0; i < IGC_QUEUE_PAIRS_NUM; i++) {
1454 : 0 : igc->txq_stats_map[i] = -1;
1455 : 0 : igc->rxq_stats_map[i] = -1;
1456 : : }
1457 : :
1458 : 0 : igc_flow_init(dev);
1459 : 0 : igc_clear_all_filter(dev);
1460 : 0 : return 0;
1461 : :
1462 : 0 : err_late:
1463 : : igc_hw_control_release(hw);
1464 : 0 : return error;
1465 : : }
1466 : :
1467 : : static int
1468 : 0 : eth_igc_dev_uninit(__rte_unused struct rte_eth_dev *eth_dev)
1469 : : {
1470 : 0 : PMD_INIT_FUNC_TRACE();
1471 : 0 : eth_igc_close(eth_dev);
1472 : 0 : return 0;
1473 : : }
1474 : :
1475 : : static int
1476 : 0 : eth_igc_reset(struct rte_eth_dev *dev)
1477 : : {
1478 : : int ret;
1479 : :
1480 : 0 : PMD_INIT_FUNC_TRACE();
1481 : :
1482 : 0 : ret = eth_igc_dev_uninit(dev);
1483 [ # # ]: 0 : if (ret)
1484 : : return ret;
1485 : :
1486 : 0 : return eth_igc_dev_init(dev);
1487 : : }
1488 : :
1489 : : static int
1490 : 0 : eth_igc_promiscuous_enable(struct rte_eth_dev *dev)
1491 : : {
1492 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1493 : : uint32_t rctl;
1494 : :
1495 : 0 : rctl = IGC_READ_REG(hw, IGC_RCTL);
1496 : 0 : rctl |= (IGC_RCTL_UPE | IGC_RCTL_MPE);
1497 : 0 : IGC_WRITE_REG(hw, IGC_RCTL, rctl);
1498 : 0 : return 0;
1499 : : }
1500 : :
1501 : : static int
1502 : 0 : eth_igc_promiscuous_disable(struct rte_eth_dev *dev)
1503 : : {
1504 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1505 : : uint32_t rctl;
1506 : :
1507 : 0 : rctl = IGC_READ_REG(hw, IGC_RCTL);
1508 : 0 : rctl &= (~IGC_RCTL_UPE);
1509 [ # # ]: 0 : if (dev->data->all_multicast == 1)
1510 : 0 : rctl |= IGC_RCTL_MPE;
1511 : : else
1512 : 0 : rctl &= (~IGC_RCTL_MPE);
1513 : 0 : IGC_WRITE_REG(hw, IGC_RCTL, rctl);
1514 : 0 : return 0;
1515 : : }
1516 : :
1517 : : static int
1518 : 0 : eth_igc_allmulticast_enable(struct rte_eth_dev *dev)
1519 : : {
1520 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1521 : : uint32_t rctl;
1522 : :
1523 : 0 : rctl = IGC_READ_REG(hw, IGC_RCTL);
1524 : 0 : rctl |= IGC_RCTL_MPE;
1525 : 0 : IGC_WRITE_REG(hw, IGC_RCTL, rctl);
1526 : 0 : return 0;
1527 : : }
1528 : :
1529 : : static int
1530 : 0 : eth_igc_allmulticast_disable(struct rte_eth_dev *dev)
1531 : : {
1532 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1533 : : uint32_t rctl;
1534 : :
1535 [ # # ]: 0 : if (dev->data->promiscuous == 1)
1536 : : return 0; /* must remain in all_multicast mode */
1537 : :
1538 : 0 : rctl = IGC_READ_REG(hw, IGC_RCTL);
1539 : 0 : rctl &= (~IGC_RCTL_MPE);
1540 : 0 : IGC_WRITE_REG(hw, IGC_RCTL, rctl);
1541 : 0 : return 0;
1542 : : }
1543 : :
1544 : : static int
1545 : 0 : eth_igc_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
1546 : : size_t fw_size)
1547 : : {
1548 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1549 : : struct igc_fw_version fw;
1550 : : int ret;
1551 : :
1552 : 0 : igc_get_fw_version(hw, &fw);
1553 : :
1554 : : /* if option rom is valid, display its version too */
1555 [ # # ]: 0 : if (fw.or_valid) {
1556 : 0 : ret = snprintf(fw_version, fw_size,
1557 : : "%d.%d, 0x%08x, %d.%d.%d",
1558 : 0 : fw.eep_major, fw.eep_minor, fw.etrack_id,
1559 : 0 : fw.or_major, fw.or_build, fw.or_patch);
1560 : : /* no option rom */
1561 : : } else {
1562 [ # # ]: 0 : if (fw.etrack_id != 0X0000) {
1563 : 0 : ret = snprintf(fw_version, fw_size,
1564 : : "%d.%d, 0x%08x",
1565 : 0 : fw.eep_major, fw.eep_minor,
1566 : : fw.etrack_id);
1567 : : } else {
1568 : 0 : ret = snprintf(fw_version, fw_size,
1569 : : "%d.%d.%d",
1570 : 0 : fw.eep_major, fw.eep_minor,
1571 : 0 : fw.eep_build);
1572 : : }
1573 : : }
1574 [ # # ]: 0 : if (ret < 0)
1575 : : return -EINVAL;
1576 : :
1577 : 0 : ret += 1; /* add the size of '\0' */
1578 [ # # ]: 0 : if (fw_size < (size_t)ret)
1579 : : return ret;
1580 : : else
1581 : 0 : return 0;
1582 : : }
1583 : :
1584 : : static int
1585 : 0 : eth_igc_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1586 : : {
1587 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1588 : :
1589 : 0 : dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
1590 : 0 : dev_info->max_rx_pktlen = MAX_RX_JUMBO_FRAME_SIZE;
1591 : 0 : dev_info->max_mac_addrs = hw->mac.rar_entry_count;
1592 : 0 : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
1593 : 0 : dev_info->rx_offload_capa = IGC_RX_OFFLOAD_ALL;
1594 : 0 : dev_info->tx_offload_capa = IGC_TX_OFFLOAD_ALL;
1595 : 0 : dev_info->rx_queue_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
1596 : :
1597 : 0 : dev_info->max_rx_queues = IGC_QUEUE_PAIRS_NUM;
1598 : 0 : dev_info->max_tx_queues = IGC_QUEUE_PAIRS_NUM;
1599 : 0 : dev_info->max_vmdq_pools = 0;
1600 : :
1601 : 0 : dev_info->hash_key_size = IGC_HKEY_MAX_INDEX * sizeof(uint32_t);
1602 : 0 : dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_128;
1603 : 0 : dev_info->flow_type_rss_offloads = IGC_RSS_OFFLOAD_ALL;
1604 : :
1605 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
1606 : : .rx_thresh = {
1607 : : .pthresh = IGC_DEFAULT_RX_PTHRESH,
1608 : : .hthresh = IGC_DEFAULT_RX_HTHRESH,
1609 : : .wthresh = IGC_DEFAULT_RX_WTHRESH,
1610 : : },
1611 : : .rx_free_thresh = IGC_DEFAULT_RX_FREE_THRESH,
1612 : : .rx_drop_en = 0,
1613 : : .offloads = 0,
1614 : : };
1615 : :
1616 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
1617 : : .tx_thresh = {
1618 : : .pthresh = IGC_DEFAULT_TX_PTHRESH,
1619 : : .hthresh = IGC_DEFAULT_TX_HTHRESH,
1620 : : .wthresh = IGC_DEFAULT_TX_WTHRESH,
1621 : : },
1622 : : .offloads = 0,
1623 : : };
1624 : :
1625 : 0 : dev_info->rx_desc_lim = rx_desc_lim;
1626 : 0 : dev_info->tx_desc_lim = tx_desc_lim;
1627 : :
1628 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
1629 : : RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
1630 : : RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_2_5G;
1631 : :
1632 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - IGC_ETH_OVERHEAD;
1633 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
1634 : 0 : return 0;
1635 : : }
1636 : :
1637 : : static int
1638 : 0 : eth_igc_led_on(struct rte_eth_dev *dev)
1639 : : {
1640 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1641 : :
1642 [ # # ]: 0 : return igc_led_on(hw) == IGC_SUCCESS ? 0 : -ENOTSUP;
1643 : : }
1644 : :
1645 : : static int
1646 : 0 : eth_igc_led_off(struct rte_eth_dev *dev)
1647 : : {
1648 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1649 : :
1650 [ # # ]: 0 : return igc_led_off(hw) == IGC_SUCCESS ? 0 : -ENOTSUP;
1651 : : }
1652 : :
1653 : : static const uint32_t *
1654 : 0 : eth_igc_supported_ptypes_get(__rte_unused struct rte_eth_dev *dev,
1655 : : size_t *no_of_elements)
1656 : : {
1657 : : static const uint32_t ptypes[] = {
1658 : : /* refers to rx_desc_pkt_info_to_pkt_type() */
1659 : : RTE_PTYPE_L2_ETHER,
1660 : : RTE_PTYPE_L3_IPV4,
1661 : : RTE_PTYPE_L3_IPV4_EXT,
1662 : : RTE_PTYPE_L3_IPV6,
1663 : : RTE_PTYPE_L3_IPV6_EXT,
1664 : : RTE_PTYPE_L4_TCP,
1665 : : RTE_PTYPE_L4_UDP,
1666 : : RTE_PTYPE_L4_SCTP,
1667 : : RTE_PTYPE_TUNNEL_IP,
1668 : : RTE_PTYPE_INNER_L3_IPV6,
1669 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
1670 : : RTE_PTYPE_INNER_L4_TCP,
1671 : : RTE_PTYPE_INNER_L4_UDP,
1672 : : };
1673 : :
1674 : 0 : *no_of_elements = RTE_DIM(ptypes);
1675 : 0 : return ptypes;
1676 : : }
1677 : :
1678 : : static int
1679 : 0 : eth_igc_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1680 : : {
1681 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1682 : 0 : uint32_t frame_size = mtu + IGC_ETH_OVERHEAD;
1683 : : uint32_t rctl;
1684 : :
1685 : : /* if extend vlan has been enabled */
1686 [ # # ]: 0 : if (IGC_READ_REG(hw, IGC_CTRL_EXT) & IGC_CTRL_EXT_EXT_VLAN)
1687 : 0 : frame_size += VLAN_TAG_SIZE;
1688 : :
1689 : : /*
1690 : : * If device is started, refuse mtu that requires the support of
1691 : : * scattered packets when this feature has not been enabled before.
1692 : : */
1693 [ # # ]: 0 : if (dev->data->dev_started && !dev->data->scattered_rx &&
1694 [ # # ]: 0 : frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
1695 : 0 : PMD_INIT_LOG(ERR, "Stop port first.");
1696 : 0 : return -EINVAL;
1697 : : }
1698 : :
1699 : 0 : rctl = IGC_READ_REG(hw, IGC_RCTL);
1700 [ # # ]: 0 : if (mtu > RTE_ETHER_MTU)
1701 : 0 : rctl |= IGC_RCTL_LPE;
1702 : : else
1703 : 0 : rctl &= ~IGC_RCTL_LPE;
1704 : 0 : IGC_WRITE_REG(hw, IGC_RCTL, rctl);
1705 : :
1706 : 0 : IGC_WRITE_REG(hw, IGC_RLPML, frame_size);
1707 : :
1708 : 0 : return 0;
1709 : : }
1710 : :
1711 : : static int
1712 : 0 : eth_igc_rar_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1713 : : uint32_t index, uint32_t pool)
1714 : : {
1715 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1716 : :
1717 : 0 : igc_rar_set(hw, mac_addr->addr_bytes, index);
1718 : : RTE_SET_USED(pool);
1719 : 0 : return 0;
1720 : : }
1721 : :
1722 : : static void
1723 : 0 : eth_igc_rar_clear(struct rte_eth_dev *dev, uint32_t index)
1724 : : {
1725 : : uint8_t addr[RTE_ETHER_ADDR_LEN];
1726 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1727 : :
1728 : : memset(addr, 0, sizeof(addr));
1729 : 0 : igc_rar_set(hw, addr, index);
1730 : 0 : }
1731 : :
1732 : : static int
1733 : 0 : eth_igc_default_mac_addr_set(struct rte_eth_dev *dev,
1734 : : struct rte_ether_addr *addr)
1735 : : {
1736 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1737 : 0 : igc_rar_set(hw, addr->addr_bytes, 0);
1738 : 0 : return 0;
1739 : : }
1740 : :
1741 : : static int
1742 : 0 : eth_igc_set_mc_addr_list(struct rte_eth_dev *dev,
1743 : : struct rte_ether_addr *mc_addr_set,
1744 : : uint32_t nb_mc_addr)
1745 : : {
1746 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1747 : 0 : igc_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
1748 : 0 : return 0;
1749 : : }
1750 : :
1751 : : /*
1752 : : * Read hardware registers
1753 : : */
1754 : : static void
1755 : 0 : igc_read_stats_registers(struct igc_hw *hw, struct igc_hw_stats *stats)
1756 : : {
1757 : : int pause_frames;
1758 : :
1759 : 0 : uint64_t old_gprc = stats->gprc;
1760 : 0 : uint64_t old_gptc = stats->gptc;
1761 : 0 : uint64_t old_tpr = stats->tpr;
1762 : 0 : uint64_t old_tpt = stats->tpt;
1763 : 0 : uint64_t old_rpthc = stats->rpthc;
1764 : 0 : uint64_t old_hgptc = stats->hgptc;
1765 : :
1766 : 0 : stats->crcerrs += IGC_READ_REG(hw, IGC_CRCERRS);
1767 : 0 : stats->algnerrc += IGC_READ_REG(hw, IGC_ALGNERRC);
1768 : 0 : stats->rxerrc += IGC_READ_REG(hw, IGC_RXERRC);
1769 : 0 : stats->mpc += IGC_READ_REG(hw, IGC_MPC);
1770 : 0 : stats->scc += IGC_READ_REG(hw, IGC_SCC);
1771 : 0 : stats->ecol += IGC_READ_REG(hw, IGC_ECOL);
1772 : :
1773 : 0 : stats->mcc += IGC_READ_REG(hw, IGC_MCC);
1774 : 0 : stats->latecol += IGC_READ_REG(hw, IGC_LATECOL);
1775 : 0 : stats->colc += IGC_READ_REG(hw, IGC_COLC);
1776 : :
1777 : 0 : stats->dc += IGC_READ_REG(hw, IGC_DC);
1778 : 0 : stats->tncrs += IGC_READ_REG(hw, IGC_TNCRS);
1779 : 0 : stats->htdpmc += IGC_READ_REG(hw, IGC_HTDPMC);
1780 : 0 : stats->rlec += IGC_READ_REG(hw, IGC_RLEC);
1781 : 0 : stats->xonrxc += IGC_READ_REG(hw, IGC_XONRXC);
1782 : 0 : stats->xontxc += IGC_READ_REG(hw, IGC_XONTXC);
1783 : :
1784 : : /*
1785 : : * For watchdog management we need to know if we have been
1786 : : * paused during the last interval, so capture that here.
1787 : : */
1788 : 0 : pause_frames = IGC_READ_REG(hw, IGC_XOFFRXC);
1789 : 0 : stats->xoffrxc += pause_frames;
1790 : 0 : stats->xofftxc += IGC_READ_REG(hw, IGC_XOFFTXC);
1791 : 0 : stats->fcruc += IGC_READ_REG(hw, IGC_FCRUC);
1792 : 0 : stats->prc64 += IGC_READ_REG(hw, IGC_PRC64);
1793 : 0 : stats->prc127 += IGC_READ_REG(hw, IGC_PRC127);
1794 : 0 : stats->prc255 += IGC_READ_REG(hw, IGC_PRC255);
1795 : 0 : stats->prc511 += IGC_READ_REG(hw, IGC_PRC511);
1796 : 0 : stats->prc1023 += IGC_READ_REG(hw, IGC_PRC1023);
1797 : 0 : stats->prc1522 += IGC_READ_REG(hw, IGC_PRC1522);
1798 : 0 : stats->gprc += IGC_READ_REG(hw, IGC_GPRC);
1799 : 0 : stats->bprc += IGC_READ_REG(hw, IGC_BPRC);
1800 : 0 : stats->mprc += IGC_READ_REG(hw, IGC_MPRC);
1801 : 0 : stats->gptc += IGC_READ_REG(hw, IGC_GPTC);
1802 : :
1803 : : /* For the 64-bit byte counters the low dword must be read first. */
1804 : : /* Both registers clear on the read of the high dword */
1805 : :
1806 : : /* Workaround CRC bytes included in size, take away 4 bytes/packet */
1807 : 0 : stats->gorc += IGC_READ_REG(hw, IGC_GORCL);
1808 : 0 : stats->gorc += ((uint64_t)IGC_READ_REG(hw, IGC_GORCH) << 32);
1809 : 0 : stats->gorc -= (stats->gprc - old_gprc) * RTE_ETHER_CRC_LEN;
1810 : 0 : stats->gotc += IGC_READ_REG(hw, IGC_GOTCL);
1811 : 0 : stats->gotc += ((uint64_t)IGC_READ_REG(hw, IGC_GOTCH) << 32);
1812 : 0 : stats->gotc -= (stats->gptc - old_gptc) * RTE_ETHER_CRC_LEN;
1813 : :
1814 : 0 : stats->rnbc += IGC_READ_REG(hw, IGC_RNBC);
1815 : 0 : stats->ruc += IGC_READ_REG(hw, IGC_RUC);
1816 : 0 : stats->rfc += IGC_READ_REG(hw, IGC_RFC);
1817 : 0 : stats->roc += IGC_READ_REG(hw, IGC_ROC);
1818 : 0 : stats->rjc += IGC_READ_REG(hw, IGC_RJC);
1819 : :
1820 : 0 : stats->mgprc += IGC_READ_REG(hw, IGC_MGTPRC);
1821 : 0 : stats->mgpdc += IGC_READ_REG(hw, IGC_MGTPDC);
1822 : 0 : stats->mgptc += IGC_READ_REG(hw, IGC_MGTPTC);
1823 : 0 : stats->b2ospc += IGC_READ_REG(hw, IGC_B2OSPC);
1824 : 0 : stats->b2ogprc += IGC_READ_REG(hw, IGC_B2OGPRC);
1825 : 0 : stats->o2bgptc += IGC_READ_REG(hw, IGC_O2BGPTC);
1826 : 0 : stats->o2bspc += IGC_READ_REG(hw, IGC_O2BSPC);
1827 : :
1828 : 0 : stats->tpr += IGC_READ_REG(hw, IGC_TPR);
1829 : 0 : stats->tpt += IGC_READ_REG(hw, IGC_TPT);
1830 : :
1831 : 0 : stats->tor += IGC_READ_REG(hw, IGC_TORL);
1832 : 0 : stats->tor += ((uint64_t)IGC_READ_REG(hw, IGC_TORH) << 32);
1833 : 0 : stats->tor -= (stats->tpr - old_tpr) * RTE_ETHER_CRC_LEN;
1834 : 0 : stats->tot += IGC_READ_REG(hw, IGC_TOTL);
1835 : 0 : stats->tot += ((uint64_t)IGC_READ_REG(hw, IGC_TOTH) << 32);
1836 : 0 : stats->tot -= (stats->tpt - old_tpt) * RTE_ETHER_CRC_LEN;
1837 : :
1838 : 0 : stats->ptc64 += IGC_READ_REG(hw, IGC_PTC64);
1839 : 0 : stats->ptc127 += IGC_READ_REG(hw, IGC_PTC127);
1840 : 0 : stats->ptc255 += IGC_READ_REG(hw, IGC_PTC255);
1841 : 0 : stats->ptc511 += IGC_READ_REG(hw, IGC_PTC511);
1842 : 0 : stats->ptc1023 += IGC_READ_REG(hw, IGC_PTC1023);
1843 : 0 : stats->ptc1522 += IGC_READ_REG(hw, IGC_PTC1522);
1844 : 0 : stats->mptc += IGC_READ_REG(hw, IGC_MPTC);
1845 : 0 : stats->bptc += IGC_READ_REG(hw, IGC_BPTC);
1846 : 0 : stats->tsctc += IGC_READ_REG(hw, IGC_TSCTC);
1847 : :
1848 : 0 : stats->iac += IGC_READ_REG(hw, IGC_IAC);
1849 : 0 : stats->rpthc += IGC_READ_REG(hw, IGC_RPTHC);
1850 : 0 : stats->hgptc += IGC_READ_REG(hw, IGC_HGPTC);
1851 : 0 : stats->icrxdmtc += IGC_READ_REG(hw, IGC_ICRXDMTC);
1852 : :
1853 : : /* Host to Card Statistics */
1854 : 0 : stats->hgorc += IGC_READ_REG(hw, IGC_HGORCL);
1855 : 0 : stats->hgorc += ((uint64_t)IGC_READ_REG(hw, IGC_HGORCH) << 32);
1856 : 0 : stats->hgorc -= (stats->rpthc - old_rpthc) * RTE_ETHER_CRC_LEN;
1857 : 0 : stats->hgotc += IGC_READ_REG(hw, IGC_HGOTCL);
1858 : 0 : stats->hgotc += ((uint64_t)IGC_READ_REG(hw, IGC_HGOTCH) << 32);
1859 : 0 : stats->hgotc -= (stats->hgptc - old_hgptc) * RTE_ETHER_CRC_LEN;
1860 : 0 : stats->lenerrs += IGC_READ_REG(hw, IGC_LENERRS);
1861 : 0 : }
1862 : :
1863 : : /*
1864 : : * Write 0 to all queue status registers
1865 : : */
1866 : : static void
1867 : 0 : igc_reset_queue_stats_register(struct igc_hw *hw)
1868 : : {
1869 : : int i;
1870 : :
1871 [ # # ]: 0 : for (i = 0; i < IGC_QUEUE_PAIRS_NUM; i++) {
1872 : 0 : IGC_WRITE_REG(hw, IGC_PQGPRC(i), 0);
1873 : 0 : IGC_WRITE_REG(hw, IGC_PQGPTC(i), 0);
1874 : 0 : IGC_WRITE_REG(hw, IGC_PQGORC(i), 0);
1875 : 0 : IGC_WRITE_REG(hw, IGC_PQGOTC(i), 0);
1876 : 0 : IGC_WRITE_REG(hw, IGC_PQMPRC(i), 0);
1877 : 0 : IGC_WRITE_REG(hw, IGC_RQDPC(i), 0);
1878 : 0 : IGC_WRITE_REG(hw, IGC_TQDPC(i), 0);
1879 : : }
1880 : 0 : }
1881 : :
1882 : : /*
1883 : : * Read all hardware queue status registers
1884 : : */
1885 : : static void
1886 : 0 : igc_read_queue_stats_register(struct rte_eth_dev *dev)
1887 : : {
1888 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1889 : : struct igc_hw_queue_stats *queue_stats =
1890 : : IGC_DEV_PRIVATE_QUEUE_STATS(dev);
1891 : : int i;
1892 : :
1893 : : /*
1894 : : * This register is not cleared on read. Furthermore, the register wraps
1895 : : * around back to 0x00000000 on the next increment when reaching a value
1896 : : * of 0xFFFFFFFF and then continues normal count operation.
1897 : : */
1898 [ # # ]: 0 : for (i = 0; i < IGC_QUEUE_PAIRS_NUM; i++) {
1899 : : union {
1900 : : u64 ddword;
1901 : : u32 dword[2];
1902 : : } value;
1903 : : u32 tmp;
1904 : :
1905 : : /*
1906 : : * Read the register first, if the value is smaller than that
1907 : : * previous read, that mean the register has been overflowed,
1908 : : * then we add the high 4 bytes by 1 and replace the low 4
1909 : : * bytes by the new value.
1910 : : */
1911 : 0 : tmp = IGC_READ_REG(hw, IGC_PQGPRC(i));
1912 : 0 : value.ddword = queue_stats->pqgprc[i];
1913 [ # # ]: 0 : if (value.dword[U32_0_IN_U64] > tmp)
1914 : 0 : value.dword[U32_1_IN_U64]++;
1915 : 0 : value.dword[U32_0_IN_U64] = tmp;
1916 : 0 : queue_stats->pqgprc[i] = value.ddword;
1917 : :
1918 : 0 : tmp = IGC_READ_REG(hw, IGC_PQGPTC(i));
1919 : 0 : value.ddword = queue_stats->pqgptc[i];
1920 [ # # ]: 0 : if (value.dword[U32_0_IN_U64] > tmp)
1921 : 0 : value.dword[U32_1_IN_U64]++;
1922 : 0 : value.dword[U32_0_IN_U64] = tmp;
1923 : 0 : queue_stats->pqgptc[i] = value.ddword;
1924 : :
1925 : 0 : tmp = IGC_READ_REG(hw, IGC_PQGORC(i));
1926 : 0 : value.ddword = queue_stats->pqgorc[i];
1927 [ # # ]: 0 : if (value.dword[U32_0_IN_U64] > tmp)
1928 : 0 : value.dword[U32_1_IN_U64]++;
1929 : 0 : value.dword[U32_0_IN_U64] = tmp;
1930 : 0 : queue_stats->pqgorc[i] = value.ddword;
1931 : :
1932 : 0 : tmp = IGC_READ_REG(hw, IGC_PQGOTC(i));
1933 : 0 : value.ddword = queue_stats->pqgotc[i];
1934 [ # # ]: 0 : if (value.dword[U32_0_IN_U64] > tmp)
1935 : 0 : value.dword[U32_1_IN_U64]++;
1936 : 0 : value.dword[U32_0_IN_U64] = tmp;
1937 : 0 : queue_stats->pqgotc[i] = value.ddword;
1938 : :
1939 : 0 : tmp = IGC_READ_REG(hw, IGC_PQMPRC(i));
1940 : 0 : value.ddword = queue_stats->pqmprc[i];
1941 [ # # ]: 0 : if (value.dword[U32_0_IN_U64] > tmp)
1942 : 0 : value.dword[U32_1_IN_U64]++;
1943 : 0 : value.dword[U32_0_IN_U64] = tmp;
1944 : 0 : queue_stats->pqmprc[i] = value.ddword;
1945 : :
1946 : 0 : tmp = IGC_READ_REG(hw, IGC_RQDPC(i));
1947 : 0 : value.ddword = queue_stats->rqdpc[i];
1948 [ # # ]: 0 : if (value.dword[U32_0_IN_U64] > tmp)
1949 : 0 : value.dword[U32_1_IN_U64]++;
1950 : 0 : value.dword[U32_0_IN_U64] = tmp;
1951 : 0 : queue_stats->rqdpc[i] = value.ddword;
1952 : :
1953 : 0 : tmp = IGC_READ_REG(hw, IGC_TQDPC(i));
1954 : 0 : value.ddword = queue_stats->tqdpc[i];
1955 [ # # ]: 0 : if (value.dword[U32_0_IN_U64] > tmp)
1956 : 0 : value.dword[U32_1_IN_U64]++;
1957 : 0 : value.dword[U32_0_IN_U64] = tmp;
1958 : 0 : queue_stats->tqdpc[i] = value.ddword;
1959 : : }
1960 : 0 : }
1961 : :
1962 : : static int
1963 : 0 : eth_igc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
1964 : : {
1965 : 0 : struct igc_adapter *igc = IGC_DEV_PRIVATE(dev);
1966 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
1967 : 0 : struct igc_hw_stats *stats = IGC_DEV_PRIVATE_STATS(dev);
1968 : : struct igc_hw_queue_stats *queue_stats =
1969 : : IGC_DEV_PRIVATE_QUEUE_STATS(dev);
1970 : : int i;
1971 : :
1972 : : /*
1973 : : * Cancel status handler since it will read the queue status registers
1974 : : */
1975 : 0 : rte_eal_alarm_cancel(igc_update_queue_stats_handler, dev);
1976 : :
1977 : : /* Read status register */
1978 : 0 : igc_read_queue_stats_register(dev);
1979 : 0 : igc_read_stats_registers(hw, stats);
1980 : :
1981 [ # # ]: 0 : if (rte_stats == NULL) {
1982 : : /* Restart queue status handler */
1983 : 0 : rte_eal_alarm_set(IGC_ALARM_INTERVAL,
1984 : : igc_update_queue_stats_handler, dev);
1985 : 0 : return -EINVAL;
1986 : : }
1987 : :
1988 : : /* Rx Errors */
1989 : 0 : rte_stats->imissed = stats->mpc;
1990 : 0 : rte_stats->ierrors = stats->crcerrs + stats->rlec +
1991 : 0 : stats->rxerrc + stats->algnerrc;
1992 : :
1993 : : /* Tx Errors */
1994 : 0 : rte_stats->oerrors = stats->ecol + stats->latecol;
1995 : :
1996 : 0 : rte_stats->ipackets = stats->gprc;
1997 : 0 : rte_stats->opackets = stats->gptc;
1998 : 0 : rte_stats->ibytes = stats->gorc;
1999 : 0 : rte_stats->obytes = stats->gotc;
2000 : :
2001 : : /* Get per-queue statuses */
2002 [ # # ]: 0 : for (i = 0; i < IGC_QUEUE_PAIRS_NUM; i++) {
2003 : : /* GET TX queue statuses */
2004 : 0 : int map_id = igc->txq_stats_map[i];
2005 [ # # ]: 0 : if (map_id >= 0) {
2006 : 0 : rte_stats->q_opackets[map_id] += queue_stats->pqgptc[i];
2007 : 0 : rte_stats->q_obytes[map_id] += queue_stats->pqgotc[i];
2008 : : }
2009 : : /* Get RX queue statuses */
2010 : 0 : map_id = igc->rxq_stats_map[i];
2011 [ # # ]: 0 : if (map_id >= 0) {
2012 : 0 : rte_stats->q_ipackets[map_id] += queue_stats->pqgprc[i];
2013 : 0 : rte_stats->q_ibytes[map_id] += queue_stats->pqgorc[i];
2014 : 0 : rte_stats->q_errors[map_id] += queue_stats->rqdpc[i];
2015 : : }
2016 : : }
2017 : :
2018 : : /* Restart queue status handler */
2019 : 0 : rte_eal_alarm_set(IGC_ALARM_INTERVAL,
2020 : : igc_update_queue_stats_handler, dev);
2021 : 0 : return 0;
2022 : : }
2023 : :
2024 : : static int
2025 : 0 : eth_igc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2026 : : unsigned int n)
2027 : : {
2028 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2029 : 0 : struct igc_hw_stats *hw_stats =
2030 : : IGC_DEV_PRIVATE_STATS(dev);
2031 : : unsigned int i;
2032 : :
2033 : 0 : igc_read_stats_registers(hw, hw_stats);
2034 : :
2035 [ # # ]: 0 : if (n < IGC_NB_XSTATS)
2036 : : return IGC_NB_XSTATS;
2037 : :
2038 : : /* If this is a reset xstats is NULL, and we have cleared the
2039 : : * registers by reading them.
2040 : : */
2041 [ # # ]: 0 : if (!xstats)
2042 : : return 0;
2043 : :
2044 : : /* Extended stats */
2045 [ # # ]: 0 : for (i = 0; i < IGC_NB_XSTATS; i++) {
2046 : 0 : xstats[i].id = i;
2047 : 0 : xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
2048 : 0 : rte_igc_stats_strings[i].offset);
2049 : : }
2050 : :
2051 : : return IGC_NB_XSTATS;
2052 : : }
2053 : :
2054 : : static int
2055 : 0 : eth_igc_xstats_reset(struct rte_eth_dev *dev)
2056 : : {
2057 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2058 : 0 : struct igc_hw_stats *hw_stats = IGC_DEV_PRIVATE_STATS(dev);
2059 : 0 : struct igc_hw_queue_stats *queue_stats =
2060 : : IGC_DEV_PRIVATE_QUEUE_STATS(dev);
2061 : :
2062 : : /* Cancel queue status handler for avoid conflict */
2063 : 0 : rte_eal_alarm_cancel(igc_update_queue_stats_handler, dev);
2064 : :
2065 : : /* HW registers are cleared on read */
2066 : 0 : igc_reset_queue_stats_register(hw);
2067 : 0 : igc_read_stats_registers(hw, hw_stats);
2068 : :
2069 : : /* Reset software totals */
2070 : : memset(hw_stats, 0, sizeof(*hw_stats));
2071 : : memset(queue_stats, 0, sizeof(*queue_stats));
2072 : :
2073 : : /* Restart the queue status handler */
2074 : 0 : rte_eal_alarm_set(IGC_ALARM_INTERVAL, igc_update_queue_stats_handler,
2075 : : dev);
2076 : :
2077 : 0 : return 0;
2078 : : }
2079 : :
2080 : : static int
2081 : 0 : eth_igc_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2082 : : struct rte_eth_xstat_name *xstats_names, unsigned int size)
2083 : : {
2084 : : unsigned int i;
2085 : :
2086 [ # # ]: 0 : if (xstats_names == NULL)
2087 : : return IGC_NB_XSTATS;
2088 : :
2089 [ # # ]: 0 : if (size < IGC_NB_XSTATS) {
2090 : 0 : PMD_DRV_LOG(ERR, "not enough buffers!");
2091 : 0 : return IGC_NB_XSTATS;
2092 : : }
2093 : :
2094 [ # # ]: 0 : for (i = 0; i < IGC_NB_XSTATS; i++)
2095 : 0 : strlcpy(xstats_names[i].name, rte_igc_stats_strings[i].name,
2096 : : sizeof(xstats_names[i].name));
2097 : :
2098 : : return IGC_NB_XSTATS;
2099 : : }
2100 : :
2101 : : static int
2102 : 0 : eth_igc_xstats_get_names_by_id(struct rte_eth_dev *dev,
2103 : : const uint64_t *ids, struct rte_eth_xstat_name *xstats_names,
2104 : : unsigned int limit)
2105 : : {
2106 : : unsigned int i;
2107 : :
2108 [ # # ]: 0 : if (!ids)
2109 : 0 : return eth_igc_xstats_get_names(dev, xstats_names, limit);
2110 : :
2111 [ # # ]: 0 : for (i = 0; i < limit; i++) {
2112 [ # # ]: 0 : if (ids[i] >= IGC_NB_XSTATS) {
2113 : 0 : PMD_DRV_LOG(ERR, "id value isn't valid");
2114 : 0 : return -EINVAL;
2115 : : }
2116 : 0 : strlcpy(xstats_names[i].name,
2117 : : rte_igc_stats_strings[ids[i]].name,
2118 : : sizeof(xstats_names[i].name));
2119 : : }
2120 : 0 : return limit;
2121 : : }
2122 : :
2123 : : static int
2124 : 0 : eth_igc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
2125 : : uint64_t *values, unsigned int n)
2126 : : {
2127 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2128 : 0 : struct igc_hw_stats *hw_stats = IGC_DEV_PRIVATE_STATS(dev);
2129 : : unsigned int i;
2130 : :
2131 : 0 : igc_read_stats_registers(hw, hw_stats);
2132 : :
2133 [ # # ]: 0 : if (!ids) {
2134 [ # # ]: 0 : if (n < IGC_NB_XSTATS)
2135 : : return IGC_NB_XSTATS;
2136 : :
2137 : : /* If this is a reset xstats is NULL, and we have cleared the
2138 : : * registers by reading them.
2139 : : */
2140 [ # # ]: 0 : if (!values)
2141 : : return 0;
2142 : :
2143 : : /* Extended stats */
2144 [ # # ]: 0 : for (i = 0; i < IGC_NB_XSTATS; i++)
2145 : 0 : values[i] = *(uint64_t *)(((char *)hw_stats) +
2146 : 0 : rte_igc_stats_strings[i].offset);
2147 : :
2148 : : return IGC_NB_XSTATS;
2149 : :
2150 : : } else {
2151 [ # # ]: 0 : for (i = 0; i < n; i++) {
2152 [ # # ]: 0 : if (ids[i] >= IGC_NB_XSTATS) {
2153 : 0 : PMD_DRV_LOG(ERR, "id value isn't valid");
2154 : 0 : return -EINVAL;
2155 : : }
2156 : 0 : values[i] = *(uint64_t *)(((char *)hw_stats) +
2157 : 0 : rte_igc_stats_strings[ids[i]].offset);
2158 : : }
2159 : 0 : return n;
2160 : : }
2161 : : }
2162 : :
2163 : : static int
2164 : 0 : eth_igc_queue_stats_mapping_set(struct rte_eth_dev *dev,
2165 : : uint16_t queue_id, uint8_t stat_idx, uint8_t is_rx)
2166 : : {
2167 : 0 : struct igc_adapter *igc = IGC_DEV_PRIVATE(dev);
2168 : :
2169 : : /* check queue id is valid */
2170 [ # # ]: 0 : if (queue_id >= IGC_QUEUE_PAIRS_NUM) {
2171 : 0 : PMD_DRV_LOG(ERR, "queue id(%u) error, max is %u",
2172 : : queue_id, IGC_QUEUE_PAIRS_NUM - 1);
2173 : 0 : return -EINVAL;
2174 : : }
2175 : :
2176 : : /* store the mapping status id */
2177 [ # # ]: 0 : if (is_rx)
2178 : 0 : igc->rxq_stats_map[queue_id] = stat_idx;
2179 : : else
2180 : 0 : igc->txq_stats_map[queue_id] = stat_idx;
2181 : :
2182 : : return 0;
2183 : : }
2184 : :
2185 : : static int
2186 : 0 : eth_igc_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
2187 : : {
2188 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2189 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2190 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2191 : : uint32_t vec = IGC_MISC_VEC_ID;
2192 : :
2193 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
2194 : : vec = IGC_RX_VEC_START;
2195 : :
2196 : 0 : uint32_t mask = 1u << (queue_id + vec);
2197 : :
2198 : 0 : IGC_WRITE_REG(hw, IGC_EIMC, mask);
2199 : 0 : IGC_WRITE_FLUSH(hw);
2200 : :
2201 : 0 : return 0;
2202 : : }
2203 : :
2204 : : static int
2205 : 0 : eth_igc_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
2206 : : {
2207 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2208 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2209 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2210 : : uint32_t vec = IGC_MISC_VEC_ID;
2211 : :
2212 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
2213 : : vec = IGC_RX_VEC_START;
2214 : :
2215 : 0 : uint32_t mask = 1u << (queue_id + vec);
2216 : :
2217 : 0 : IGC_WRITE_REG(hw, IGC_EIMS, mask);
2218 : 0 : IGC_WRITE_FLUSH(hw);
2219 : :
2220 : 0 : rte_intr_enable(intr_handle);
2221 : :
2222 : 0 : return 0;
2223 : : }
2224 : :
2225 : : static int
2226 : 0 : eth_igc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2227 : : {
2228 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2229 : : uint32_t ctrl;
2230 : : int tx_pause;
2231 : : int rx_pause;
2232 : :
2233 : 0 : fc_conf->pause_time = hw->fc.pause_time;
2234 : 0 : fc_conf->high_water = hw->fc.high_water;
2235 : 0 : fc_conf->low_water = hw->fc.low_water;
2236 : 0 : fc_conf->send_xon = hw->fc.send_xon;
2237 : 0 : fc_conf->autoneg = hw->mac.autoneg;
2238 : :
2239 : : /*
2240 : : * Return rx_pause and tx_pause status according to actual setting of
2241 : : * the TFCE and RFCE bits in the CTRL register.
2242 : : */
2243 : 0 : ctrl = IGC_READ_REG(hw, IGC_CTRL);
2244 [ # # ]: 0 : if (ctrl & IGC_CTRL_TFCE)
2245 : : tx_pause = 1;
2246 : : else
2247 : : tx_pause = 0;
2248 : :
2249 [ # # ]: 0 : if (ctrl & IGC_CTRL_RFCE)
2250 : : rx_pause = 1;
2251 : : else
2252 : : rx_pause = 0;
2253 : :
2254 [ # # ]: 0 : if (rx_pause && tx_pause)
2255 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
2256 [ # # ]: 0 : else if (rx_pause)
2257 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
2258 [ # # ]: 0 : else if (tx_pause)
2259 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
2260 : : else
2261 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
2262 : :
2263 : 0 : return 0;
2264 : : }
2265 : :
2266 : : static int
2267 : 0 : eth_igc_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2268 : : {
2269 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2270 : : uint32_t rx_buf_size;
2271 : : uint32_t max_high_water;
2272 : : uint32_t rctl;
2273 : : int err;
2274 : :
2275 [ # # ]: 0 : if (fc_conf->autoneg != hw->mac.autoneg)
2276 : : return -ENOTSUP;
2277 : :
2278 : 0 : rx_buf_size = igc_get_rx_buffer_size(hw);
2279 : 0 : PMD_DRV_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2280 : :
2281 : : /* At least reserve one Ethernet frame for watermark */
2282 : 0 : max_high_water = rx_buf_size - RTE_ETHER_MAX_LEN;
2283 [ # # ]: 0 : if (fc_conf->high_water > max_high_water ||
2284 [ # # ]: 0 : fc_conf->high_water < fc_conf->low_water) {
2285 : 0 : PMD_DRV_LOG(ERR,
2286 : : "Incorrect high(%u)/low(%u) water value, max is %u",
2287 : : fc_conf->high_water, fc_conf->low_water,
2288 : : max_high_water);
2289 : 0 : return -EINVAL;
2290 : : }
2291 : :
2292 [ # # # # : 0 : switch (fc_conf->mode) {
# ]
2293 : 0 : case RTE_ETH_FC_NONE:
2294 : 0 : hw->fc.requested_mode = igc_fc_none;
2295 : 0 : break;
2296 : 0 : case RTE_ETH_FC_RX_PAUSE:
2297 : 0 : hw->fc.requested_mode = igc_fc_rx_pause;
2298 : 0 : break;
2299 : 0 : case RTE_ETH_FC_TX_PAUSE:
2300 : 0 : hw->fc.requested_mode = igc_fc_tx_pause;
2301 : 0 : break;
2302 : 0 : case RTE_ETH_FC_FULL:
2303 : 0 : hw->fc.requested_mode = igc_fc_full;
2304 : 0 : break;
2305 : 0 : default:
2306 : 0 : PMD_DRV_LOG(ERR, "unsupported fc mode: %u", fc_conf->mode);
2307 : 0 : return -EINVAL;
2308 : : }
2309 : :
2310 : 0 : hw->fc.pause_time = fc_conf->pause_time;
2311 : 0 : hw->fc.high_water = fc_conf->high_water;
2312 : 0 : hw->fc.low_water = fc_conf->low_water;
2313 : 0 : hw->fc.send_xon = fc_conf->send_xon;
2314 : :
2315 : 0 : err = igc_setup_link_generic(hw);
2316 [ # # ]: 0 : if (err == IGC_SUCCESS) {
2317 : : /**
2318 : : * check if we want to forward MAC frames - driver doesn't have
2319 : : * native capability to do that, so we'll write the registers
2320 : : * ourselves
2321 : : **/
2322 : 0 : rctl = IGC_READ_REG(hw, IGC_RCTL);
2323 : :
2324 : : /* set or clear MFLCN.PMCF bit depending on configuration */
2325 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0)
2326 : 0 : rctl |= IGC_RCTL_PMCF;
2327 : : else
2328 : 0 : rctl &= ~IGC_RCTL_PMCF;
2329 : :
2330 : 0 : IGC_WRITE_REG(hw, IGC_RCTL, rctl);
2331 : 0 : IGC_WRITE_FLUSH(hw);
2332 : :
2333 : 0 : return 0;
2334 : : }
2335 : :
2336 : 0 : PMD_DRV_LOG(ERR, "igc_setup_link_generic = 0x%x", err);
2337 : 0 : return -EIO;
2338 : : }
2339 : :
2340 : : static int
2341 : 0 : eth_igc_rss_reta_update(struct rte_eth_dev *dev,
2342 : : struct rte_eth_rss_reta_entry64 *reta_conf,
2343 : : uint16_t reta_size)
2344 : : {
2345 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2346 : : uint16_t i;
2347 : :
2348 [ # # ]: 0 : if (reta_size != RTE_ETH_RSS_RETA_SIZE_128) {
2349 : 0 : PMD_DRV_LOG(ERR,
2350 : : "The size of RSS redirection table configured(%d) doesn't match the number hardware can supported(%d)",
2351 : : reta_size, RTE_ETH_RSS_RETA_SIZE_128);
2352 : 0 : return -EINVAL;
2353 : : }
2354 : :
2355 : : RTE_BUILD_BUG_ON(RTE_ETH_RSS_RETA_SIZE_128 % IGC_RSS_RDT_REG_SIZE);
2356 : :
2357 : : /* set redirection table */
2358 [ # # ]: 0 : for (i = 0; i < RTE_ETH_RSS_RETA_SIZE_128; i += IGC_RSS_RDT_REG_SIZE) {
2359 : : union igc_rss_reta_reg reta, reg;
2360 : : uint16_t idx, shift;
2361 : : uint8_t j, mask;
2362 : :
2363 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
2364 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
2365 : 0 : mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2366 : : IGC_RSS_RDT_REG_SIZE_MASK);
2367 : :
2368 : : /* if no need to update the register */
2369 : 0 : if (!mask ||
2370 [ # # ]: 0 : shift > (RTE_ETH_RETA_GROUP_SIZE - IGC_RSS_RDT_REG_SIZE))
2371 : 0 : continue;
2372 : :
2373 : : /* check mask whether need to read the register value first */
2374 [ # # ]: 0 : if (mask == IGC_RSS_RDT_REG_SIZE_MASK)
2375 : 0 : reg.dword = 0;
2376 : : else
2377 : 0 : reg.dword = IGC_READ_REG_LE_VALUE(hw,
2378 : : IGC_RETA(i / IGC_RSS_RDT_REG_SIZE));
2379 : :
2380 : : /* update the register */
2381 : : RTE_BUILD_BUG_ON(sizeof(reta.bytes) != IGC_RSS_RDT_REG_SIZE);
2382 [ # # ]: 0 : for (j = 0; j < IGC_RSS_RDT_REG_SIZE; j++) {
2383 [ # # ]: 0 : if (mask & (1u << j))
2384 : 0 : reta.bytes[j] =
2385 : 0 : (uint8_t)reta_conf[idx].reta[shift + j];
2386 : : else
2387 : 0 : reta.bytes[j] = reg.bytes[j];
2388 : : }
2389 : 0 : IGC_WRITE_REG_LE_VALUE(hw,
2390 : : IGC_RETA(i / IGC_RSS_RDT_REG_SIZE), reta.dword);
2391 : : }
2392 : :
2393 : : return 0;
2394 : : }
2395 : :
2396 : : static int
2397 : 0 : eth_igc_rss_reta_query(struct rte_eth_dev *dev,
2398 : : struct rte_eth_rss_reta_entry64 *reta_conf,
2399 : : uint16_t reta_size)
2400 : : {
2401 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2402 : : uint16_t i;
2403 : :
2404 [ # # ]: 0 : if (reta_size != RTE_ETH_RSS_RETA_SIZE_128) {
2405 : 0 : PMD_DRV_LOG(ERR,
2406 : : "The size of RSS redirection table configured(%d) doesn't match the number hardware can supported(%d)",
2407 : : reta_size, RTE_ETH_RSS_RETA_SIZE_128);
2408 : 0 : return -EINVAL;
2409 : : }
2410 : :
2411 : : RTE_BUILD_BUG_ON(RTE_ETH_RSS_RETA_SIZE_128 % IGC_RSS_RDT_REG_SIZE);
2412 : :
2413 : : /* read redirection table */
2414 [ # # ]: 0 : for (i = 0; i < RTE_ETH_RSS_RETA_SIZE_128; i += IGC_RSS_RDT_REG_SIZE) {
2415 : : union igc_rss_reta_reg reta;
2416 : : uint16_t idx, shift;
2417 : : uint8_t j, mask;
2418 : :
2419 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
2420 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
2421 : 0 : mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2422 : : IGC_RSS_RDT_REG_SIZE_MASK);
2423 : :
2424 : : /* if no need to read register */
2425 : 0 : if (!mask ||
2426 [ # # ]: 0 : shift > (RTE_ETH_RETA_GROUP_SIZE - IGC_RSS_RDT_REG_SIZE))
2427 : 0 : continue;
2428 : :
2429 : : /* read register and get the queue index */
2430 : : RTE_BUILD_BUG_ON(sizeof(reta.bytes) != IGC_RSS_RDT_REG_SIZE);
2431 : 0 : reta.dword = IGC_READ_REG_LE_VALUE(hw,
2432 : : IGC_RETA(i / IGC_RSS_RDT_REG_SIZE));
2433 [ # # ]: 0 : for (j = 0; j < IGC_RSS_RDT_REG_SIZE; j++) {
2434 [ # # ]: 0 : if (mask & (1u << j))
2435 : 0 : reta_conf[idx].reta[shift + j] = reta.bytes[j];
2436 : : }
2437 : : }
2438 : :
2439 : : return 0;
2440 : : }
2441 : :
2442 : : static int
2443 : 0 : eth_igc_rss_hash_update(struct rte_eth_dev *dev,
2444 : : struct rte_eth_rss_conf *rss_conf)
2445 : : {
2446 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2447 : 0 : igc_hw_rss_hash_set(hw, rss_conf);
2448 : 0 : return 0;
2449 : : }
2450 : :
2451 : : static int
2452 : 0 : eth_igc_rss_hash_conf_get(struct rte_eth_dev *dev,
2453 : : struct rte_eth_rss_conf *rss_conf)
2454 : : {
2455 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2456 : 0 : uint32_t *hash_key = (uint32_t *)rss_conf->rss_key;
2457 : : uint32_t mrqc;
2458 : : uint64_t rss_hf;
2459 : :
2460 [ # # ]: 0 : if (hash_key != NULL) {
2461 : : int i;
2462 : :
2463 : : /* if not enough space for store hash key */
2464 [ # # ]: 0 : if (rss_conf->rss_key_len != IGC_HKEY_SIZE) {
2465 : 0 : PMD_DRV_LOG(ERR,
2466 : : "RSS hash key size %u in parameter doesn't match the hardware hash key size %u",
2467 : : rss_conf->rss_key_len, IGC_HKEY_SIZE);
2468 : 0 : return -EINVAL;
2469 : : }
2470 : :
2471 : : /* read RSS key from register */
2472 [ # # ]: 0 : for (i = 0; i < IGC_HKEY_MAX_INDEX; i++)
2473 : 0 : hash_key[i] = IGC_READ_REG_LE_VALUE(hw, IGC_RSSRK(i));
2474 : : }
2475 : :
2476 : : /* get RSS functions configured in MRQC register */
2477 : 0 : mrqc = IGC_READ_REG(hw, IGC_MRQC);
2478 [ # # ]: 0 : if ((mrqc & IGC_MRQC_ENABLE_RSS_4Q) == 0)
2479 : : return 0;
2480 : :
2481 : : rss_hf = 0;
2482 [ # # ]: 0 : if (mrqc & IGC_MRQC_RSS_FIELD_IPV4)
2483 : : rss_hf |= RTE_ETH_RSS_IPV4;
2484 [ # # ]: 0 : if (mrqc & IGC_MRQC_RSS_FIELD_IPV4_TCP)
2485 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
2486 [ # # ]: 0 : if (mrqc & IGC_MRQC_RSS_FIELD_IPV6)
2487 : 0 : rss_hf |= RTE_ETH_RSS_IPV6;
2488 [ # # ]: 0 : if (mrqc & IGC_MRQC_RSS_FIELD_IPV6_EX)
2489 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_EX;
2490 [ # # ]: 0 : if (mrqc & IGC_MRQC_RSS_FIELD_IPV6_TCP)
2491 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP;
2492 [ # # ]: 0 : if (mrqc & IGC_MRQC_RSS_FIELD_IPV6_TCP_EX)
2493 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_TCP_EX;
2494 [ # # ]: 0 : if (mrqc & IGC_MRQC_RSS_FIELD_IPV4_UDP)
2495 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
2496 [ # # ]: 0 : if (mrqc & IGC_MRQC_RSS_FIELD_IPV6_UDP)
2497 : 0 : rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP;
2498 [ # # ]: 0 : if (mrqc & IGC_MRQC_RSS_FIELD_IPV6_UDP_EX)
2499 : 0 : rss_hf |= RTE_ETH_RSS_IPV6_UDP_EX;
2500 : :
2501 : 0 : rss_conf->rss_hf |= rss_hf;
2502 : 0 : return 0;
2503 : : }
2504 : :
2505 : : static int
2506 : 0 : eth_igc_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2507 : : {
2508 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2509 : : struct igc_vfta *shadow_vfta = IGC_DEV_PRIVATE_VFTA(dev);
2510 : : uint32_t vfta;
2511 : : uint32_t vid_idx;
2512 : : uint32_t vid_bit;
2513 : :
2514 : 0 : vid_idx = (vlan_id >> IGC_VFTA_ENTRY_SHIFT) & IGC_VFTA_ENTRY_MASK;
2515 : 0 : vid_bit = 1u << (vlan_id & IGC_VFTA_ENTRY_BIT_SHIFT_MASK);
2516 : 0 : vfta = shadow_vfta->vfta[vid_idx];
2517 [ # # ]: 0 : if (on)
2518 : 0 : vfta |= vid_bit;
2519 : : else
2520 : 0 : vfta &= ~vid_bit;
2521 : 0 : IGC_WRITE_REG_ARRAY(hw, IGC_VFTA, vid_idx, vfta);
2522 : :
2523 : : /* update local VFTA copy */
2524 : 0 : shadow_vfta->vfta[vid_idx] = vfta;
2525 : :
2526 : 0 : return 0;
2527 : : }
2528 : :
2529 : : static void
2530 : : igc_vlan_hw_filter_disable(struct rte_eth_dev *dev)
2531 : : {
2532 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2533 : : igc_read_reg_check_clear_bits(hw, IGC_RCTL,
2534 : : IGC_RCTL_CFIEN | IGC_RCTL_VFE);
2535 : : }
2536 : :
2537 : : static void
2538 : 0 : igc_vlan_hw_filter_enable(struct rte_eth_dev *dev)
2539 : : {
2540 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2541 : : struct igc_vfta *shadow_vfta = IGC_DEV_PRIVATE_VFTA(dev);
2542 : : uint32_t reg_val;
2543 : : int i;
2544 : :
2545 : : /* Filter Table Enable, CFI not used for packet acceptance */
2546 : 0 : reg_val = IGC_READ_REG(hw, IGC_RCTL);
2547 : 0 : reg_val &= ~IGC_RCTL_CFIEN;
2548 : 0 : reg_val |= IGC_RCTL_VFE;
2549 : 0 : IGC_WRITE_REG(hw, IGC_RCTL, reg_val);
2550 : :
2551 : : /* restore VFTA table */
2552 [ # # ]: 0 : for (i = 0; i < IGC_VFTA_SIZE; i++)
2553 : 0 : IGC_WRITE_REG_ARRAY(hw, IGC_VFTA, i, shadow_vfta->vfta[i]);
2554 : 0 : }
2555 : :
2556 : : static void
2557 : : igc_vlan_hw_strip_disable(struct rte_eth_dev *dev)
2558 : : {
2559 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2560 : :
2561 : : igc_read_reg_check_clear_bits(hw, IGC_CTRL, IGC_CTRL_VME);
2562 : : }
2563 : :
2564 : : static void
2565 : : igc_vlan_hw_strip_enable(struct rte_eth_dev *dev)
2566 : : {
2567 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2568 : :
2569 : : igc_read_reg_check_set_bits(hw, IGC_CTRL, IGC_CTRL_VME);
2570 : : }
2571 : :
2572 : : static int
2573 : 0 : igc_vlan_hw_extend_disable(struct rte_eth_dev *dev)
2574 : : {
2575 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2576 : 0 : uint32_t frame_size = dev->data->mtu + IGC_ETH_OVERHEAD;
2577 : : uint32_t ctrl_ext;
2578 : :
2579 : 0 : ctrl_ext = IGC_READ_REG(hw, IGC_CTRL_EXT);
2580 : :
2581 : : /* if extend vlan hasn't been enabled */
2582 [ # # ]: 0 : if ((ctrl_ext & IGC_CTRL_EXT_EXT_VLAN) == 0)
2583 : : return 0;
2584 : :
2585 : : /* Update maximum packet length */
2586 [ # # ]: 0 : if (frame_size < RTE_ETHER_MIN_MTU + VLAN_TAG_SIZE) {
2587 : 0 : PMD_DRV_LOG(ERR, "Maximum packet length %u error, min is %u",
2588 : : frame_size, VLAN_TAG_SIZE + RTE_ETHER_MIN_MTU);
2589 : 0 : return -EINVAL;
2590 : : }
2591 : 0 : IGC_WRITE_REG(hw, IGC_RLPML, frame_size - VLAN_TAG_SIZE);
2592 : :
2593 : 0 : IGC_WRITE_REG(hw, IGC_CTRL_EXT, ctrl_ext & ~IGC_CTRL_EXT_EXT_VLAN);
2594 : 0 : return 0;
2595 : : }
2596 : :
2597 : : static int
2598 : 0 : igc_vlan_hw_extend_enable(struct rte_eth_dev *dev)
2599 : : {
2600 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2601 : 0 : uint32_t frame_size = dev->data->mtu + IGC_ETH_OVERHEAD;
2602 : : uint32_t ctrl_ext;
2603 : :
2604 : 0 : ctrl_ext = IGC_READ_REG(hw, IGC_CTRL_EXT);
2605 : :
2606 : : /* if extend vlan has been enabled */
2607 [ # # ]: 0 : if (ctrl_ext & IGC_CTRL_EXT_EXT_VLAN)
2608 : : return 0;
2609 : :
2610 : : /* Update maximum packet length */
2611 [ # # ]: 0 : if (frame_size > MAX_RX_JUMBO_FRAME_SIZE) {
2612 : 0 : PMD_DRV_LOG(ERR, "Maximum packet length %u error, max is %u",
2613 : : frame_size, MAX_RX_JUMBO_FRAME_SIZE);
2614 : 0 : return -EINVAL;
2615 : : }
2616 : 0 : IGC_WRITE_REG(hw, IGC_RLPML, frame_size);
2617 : :
2618 : 0 : IGC_WRITE_REG(hw, IGC_CTRL_EXT, ctrl_ext | IGC_CTRL_EXT_EXT_VLAN);
2619 : 0 : return 0;
2620 : : }
2621 : :
2622 : : static int
2623 : 0 : eth_igc_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2624 : : {
2625 : : struct rte_eth_rxmode *rxmode;
2626 : :
2627 : 0 : rxmode = &dev->data->dev_conf.rxmode;
2628 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
2629 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
2630 : : igc_vlan_hw_strip_enable(dev);
2631 : : else
2632 : : igc_vlan_hw_strip_disable(dev);
2633 : : }
2634 : :
2635 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
2636 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
2637 : 0 : igc_vlan_hw_filter_enable(dev);
2638 : : else
2639 : : igc_vlan_hw_filter_disable(dev);
2640 : : }
2641 : :
2642 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
2643 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
2644 : 0 : return igc_vlan_hw_extend_enable(dev);
2645 : : else
2646 : 0 : return igc_vlan_hw_extend_disable(dev);
2647 : : }
2648 : :
2649 : : return 0;
2650 : : }
2651 : :
2652 : : static int
2653 : 0 : eth_igc_vlan_tpid_set(struct rte_eth_dev *dev,
2654 : : enum rte_vlan_type vlan_type,
2655 : : uint16_t tpid)
2656 : : {
2657 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2658 : : uint32_t reg_val;
2659 : :
2660 : : /* only outer TPID of double VLAN can be configured*/
2661 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER) {
2662 : 0 : reg_val = IGC_READ_REG(hw, IGC_VET);
2663 : 0 : reg_val = (reg_val & (~IGC_VET_EXT)) |
2664 : 0 : ((uint32_t)tpid << IGC_VET_EXT_SHIFT);
2665 : 0 : IGC_WRITE_REG(hw, IGC_VET, reg_val);
2666 : :
2667 : 0 : return 0;
2668 : : }
2669 : :
2670 : : /* all other TPID values are read-only*/
2671 : 0 : PMD_DRV_LOG(ERR, "Not supported");
2672 : 0 : return -ENOTSUP;
2673 : : }
2674 : :
2675 : : static int
2676 : 0 : eth_igc_timesync_enable(struct rte_eth_dev *dev)
2677 : : {
2678 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2679 : : struct timespec system_time;
2680 : : struct igc_rx_queue *rxq;
2681 : : uint32_t val;
2682 : : uint16_t i;
2683 : :
2684 : 0 : IGC_WRITE_REG(hw, IGC_TSAUXC, 0x0);
2685 : :
2686 : 0 : clock_gettime(CLOCK_REALTIME, &system_time);
2687 : 0 : IGC_WRITE_REG(hw, IGC_SYSTIML, system_time.tv_nsec);
2688 : 0 : IGC_WRITE_REG(hw, IGC_SYSTIMH, system_time.tv_sec);
2689 : :
2690 : : /* Enable timestamping of received PTP packets. */
2691 : 0 : val = IGC_READ_REG(hw, IGC_RXPBS);
2692 : 0 : val |= IGC_RXPBS_CFG_TS_EN;
2693 : 0 : IGC_WRITE_REG(hw, IGC_RXPBS, val);
2694 : :
2695 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2696 [ # # ]: 0 : val = IGC_READ_REG(hw, IGC_SRRCTL(i));
2697 : : /* For now, only support retrieving Rx timestamp from timer0. */
2698 : 0 : val |= IGC_SRRCTL_TIMER1SEL(0) | IGC_SRRCTL_TIMER0SEL(0) |
2699 : : IGC_SRRCTL_TIMESTAMP;
2700 : 0 : IGC_WRITE_REG(hw, IGC_SRRCTL(i), val);
2701 : : }
2702 : :
2703 : : val = IGC_TSYNCRXCTL_ENABLED | IGC_TSYNCRXCTL_TYPE_ALL |
2704 : : IGC_TSYNCRXCTL_RXSYNSIG;
2705 : 0 : IGC_WRITE_REG(hw, IGC_TSYNCRXCTL, val);
2706 : :
2707 : : /* Enable Timestamping of transmitted PTP packets. */
2708 : 0 : IGC_WRITE_REG(hw, IGC_TSYNCTXCTL, IGC_TSYNCTXCTL_ENABLED |
2709 : : IGC_TSYNCTXCTL_TXSYNSIG);
2710 : :
2711 : : /* Read TXSTMP registers to discard any timestamp previously stored. */
2712 : 0 : IGC_READ_REG(hw, IGC_TXSTMPL);
2713 : 0 : IGC_READ_REG(hw, IGC_TXSTMPH);
2714 : :
2715 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
2716 : 0 : rxq = dev->data->rx_queues[i];
2717 : 0 : rxq->offloads |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
2718 : : }
2719 : :
2720 : 0 : return 0;
2721 : : }
2722 : :
2723 : : static int
2724 : 0 : eth_igc_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
2725 : : {
2726 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2727 : :
2728 : 0 : ts->tv_nsec = IGC_READ_REG(hw, IGC_SYSTIML);
2729 : 0 : ts->tv_sec = IGC_READ_REG(hw, IGC_SYSTIMH);
2730 : :
2731 : 0 : return 0;
2732 : : }
2733 : :
2734 : : static int
2735 : 0 : eth_igc_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
2736 : : {
2737 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2738 : :
2739 : 0 : IGC_WRITE_REG(hw, IGC_SYSTIML, ts->tv_nsec);
2740 : 0 : IGC_WRITE_REG(hw, IGC_SYSTIMH, ts->tv_sec);
2741 : :
2742 : 0 : return 0;
2743 : : }
2744 : :
2745 : : static int
2746 : 0 : eth_igc_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
2747 : : {
2748 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2749 : : uint32_t nsec, sec;
2750 : : uint64_t systime, ns;
2751 : : struct timespec ts;
2752 : :
2753 : 0 : nsec = (uint64_t)IGC_READ_REG(hw, IGC_SYSTIML);
2754 : 0 : sec = (uint64_t)IGC_READ_REG(hw, IGC_SYSTIMH);
2755 : 0 : systime = sec * NSEC_PER_SEC + nsec;
2756 : :
2757 [ # # ]: 0 : ns = systime + delta;
2758 : : ts = rte_ns_to_timespec(ns);
2759 : :
2760 : 0 : IGC_WRITE_REG(hw, IGC_SYSTIML, ts.tv_nsec);
2761 : 0 : IGC_WRITE_REG(hw, IGC_SYSTIMH, ts.tv_sec);
2762 : :
2763 : 0 : return 0;
2764 : : }
2765 : :
2766 : : static int
2767 : 0 : eth_igc_timesync_read_rx_timestamp(__rte_unused struct rte_eth_dev *dev,
2768 : : struct timespec *timestamp,
2769 : : uint32_t flags)
2770 : : {
2771 : : struct rte_eth_link link;
2772 : : int adjust = 0;
2773 : : struct igc_rx_queue *rxq;
2774 : : uint64_t rx_timestamp;
2775 : :
2776 : : /* Get current link speed. */
2777 : 0 : eth_igc_link_update(dev, 1);
2778 : 0 : rte_eth_linkstatus_get(dev, &link);
2779 : :
2780 [ # # # # : 0 : switch (link.link_speed) {
# ]
2781 : 0 : case SPEED_10:
2782 : : adjust = IGC_I225_RX_LATENCY_10;
2783 : 0 : break;
2784 : 0 : case SPEED_100:
2785 : : adjust = IGC_I225_RX_LATENCY_100;
2786 : 0 : break;
2787 : 0 : case SPEED_1000:
2788 : : adjust = IGC_I225_RX_LATENCY_1000;
2789 : 0 : break;
2790 : 0 : case SPEED_2500:
2791 : : adjust = IGC_I225_RX_LATENCY_2500;
2792 : 0 : break;
2793 : : }
2794 : :
2795 : 0 : rxq = dev->data->rx_queues[flags];
2796 [ # # ]: 0 : rx_timestamp = rxq->rx_timestamp - adjust;
2797 : 0 : *timestamp = rte_ns_to_timespec(rx_timestamp);
2798 : :
2799 : 0 : return 0;
2800 : : }
2801 : :
2802 : : static int
2803 : 0 : eth_igc_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
2804 : : struct timespec *timestamp)
2805 : : {
2806 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2807 : : struct rte_eth_link link;
2808 : : uint32_t val, nsec, sec;
2809 : : uint64_t tx_timestamp;
2810 : : int adjust = 0;
2811 : :
2812 : 0 : val = IGC_READ_REG(hw, IGC_TSYNCTXCTL);
2813 [ # # ]: 0 : if (!(val & IGC_TSYNCTXCTL_VALID))
2814 : : return -EINVAL;
2815 : :
2816 : 0 : nsec = (uint64_t)IGC_READ_REG(hw, IGC_TXSTMPL);
2817 : 0 : sec = (uint64_t)IGC_READ_REG(hw, IGC_TXSTMPH);
2818 : 0 : tx_timestamp = sec * NSEC_PER_SEC + nsec;
2819 : :
2820 : : /* Get current link speed. */
2821 : 0 : eth_igc_link_update(dev, 1);
2822 : 0 : rte_eth_linkstatus_get(dev, &link);
2823 : :
2824 [ # # # # : 0 : switch (link.link_speed) {
# ]
2825 : 0 : case SPEED_10:
2826 : : adjust = IGC_I225_TX_LATENCY_10;
2827 : 0 : break;
2828 : 0 : case SPEED_100:
2829 : : adjust = IGC_I225_TX_LATENCY_100;
2830 : 0 : break;
2831 : 0 : case SPEED_1000:
2832 : : adjust = IGC_I225_TX_LATENCY_1000;
2833 : 0 : break;
2834 : 0 : case SPEED_2500:
2835 : : adjust = IGC_I225_TX_LATENCY_2500;
2836 : 0 : break;
2837 : : }
2838 : :
2839 [ # # ]: 0 : tx_timestamp += adjust;
2840 : 0 : *timestamp = rte_ns_to_timespec(tx_timestamp);
2841 : :
2842 : 0 : return 0;
2843 : : }
2844 : :
2845 : : static int
2846 : 0 : eth_igc_timesync_disable(struct rte_eth_dev *dev)
2847 : : {
2848 : 0 : struct igc_hw *hw = IGC_DEV_PRIVATE_HW(dev);
2849 : : uint32_t val;
2850 : :
2851 : : /* Disable timestamping of transmitted PTP packets. */
2852 : 0 : IGC_WRITE_REG(hw, IGC_TSYNCTXCTL, 0);
2853 : :
2854 : : /* Disable timestamping of received PTP packets. */
2855 : 0 : IGC_WRITE_REG(hw, IGC_TSYNCRXCTL, 0);
2856 : :
2857 : 0 : val = IGC_READ_REG(hw, IGC_RXPBS);
2858 : 0 : val &= ~IGC_RXPBS_CFG_TS_EN;
2859 : 0 : IGC_WRITE_REG(hw, IGC_RXPBS, val);
2860 : :
2861 : 0 : val = IGC_READ_REG(hw, IGC_SRRCTL(0));
2862 : 0 : val &= ~IGC_SRRCTL_TIMESTAMP;
2863 : 0 : IGC_WRITE_REG(hw, IGC_SRRCTL(0), val);
2864 : :
2865 : 0 : return 0;
2866 : : }
2867 : :
2868 : : static int
2869 : 0 : eth_igc_read_clock(__rte_unused struct rte_eth_dev *dev, uint64_t *clock)
2870 : : {
2871 : : struct timespec system_time;
2872 : :
2873 : 0 : clock_gettime(CLOCK_REALTIME, &system_time);
2874 : 0 : *clock = system_time.tv_sec * NSEC_PER_SEC + system_time.tv_nsec;
2875 : :
2876 : 0 : return 0;
2877 : : }
2878 : :
2879 : : static int
2880 : 0 : eth_igc_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2881 : : struct rte_pci_device *pci_dev)
2882 : : {
2883 : 0 : PMD_INIT_FUNC_TRACE();
2884 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
2885 : : sizeof(struct igc_adapter), eth_igc_dev_init);
2886 : : }
2887 : :
2888 : : static int
2889 : 0 : eth_igc_pci_remove(struct rte_pci_device *pci_dev)
2890 : : {
2891 : 0 : PMD_INIT_FUNC_TRACE();
2892 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_igc_dev_uninit);
2893 : : }
2894 : :
2895 : : static struct rte_pci_driver rte_igc_pmd = {
2896 : : .id_table = pci_id_igc_map,
2897 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
2898 : : .probe = eth_igc_pci_probe,
2899 : : .remove = eth_igc_pci_remove,
2900 : : };
2901 : :
2902 : 251 : RTE_PMD_REGISTER_PCI(net_igc, rte_igc_pmd);
2903 : : RTE_PMD_REGISTER_PCI_TABLE(net_igc, pci_id_igc_map);
2904 : : RTE_PMD_REGISTER_KMOD_DEP(net_igc, "* igb_uio | uio_pci_generic | vfio-pci");
|