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