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