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