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