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