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