1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
4 /* ethtool support for i40e */
10 char stat_string[ETH_GSTRING_LEN];
15 #define I40E_STAT(_type, _name, _stat) { \
16 .stat_string = _name, \
17 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
18 .stat_offset = offsetof(_type, _stat) \
21 #define I40E_NETDEV_STAT(_net_stat) \
22 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
23 #define I40E_PF_STAT(_name, _stat) \
24 I40E_STAT(struct i40e_pf, _name, _stat)
25 #define I40E_VSI_STAT(_name, _stat) \
26 I40E_STAT(struct i40e_vsi, _name, _stat)
27 #define I40E_VEB_STAT(_name, _stat) \
28 I40E_STAT(struct i40e_veb, _name, _stat)
30 static const struct i40e_stats i40e_gstrings_net_stats[] = {
31 I40E_NETDEV_STAT(rx_packets),
32 I40E_NETDEV_STAT(tx_packets),
33 I40E_NETDEV_STAT(rx_bytes),
34 I40E_NETDEV_STAT(tx_bytes),
35 I40E_NETDEV_STAT(rx_errors),
36 I40E_NETDEV_STAT(tx_errors),
37 I40E_NETDEV_STAT(rx_dropped),
38 I40E_NETDEV_STAT(tx_dropped),
39 I40E_NETDEV_STAT(collisions),
40 I40E_NETDEV_STAT(rx_length_errors),
41 I40E_NETDEV_STAT(rx_crc_errors),
44 static const struct i40e_stats i40e_gstrings_veb_stats[] = {
45 I40E_VEB_STAT("veb.rx_bytes", stats.rx_bytes),
46 I40E_VEB_STAT("veb.tx_bytes", stats.tx_bytes),
47 I40E_VEB_STAT("veb.rx_unicast", stats.rx_unicast),
48 I40E_VEB_STAT("veb.tx_unicast", stats.tx_unicast),
49 I40E_VEB_STAT("veb.rx_multicast", stats.rx_multicast),
50 I40E_VEB_STAT("veb.tx_multicast", stats.tx_multicast),
51 I40E_VEB_STAT("veb.rx_broadcast", stats.rx_broadcast),
52 I40E_VEB_STAT("veb.tx_broadcast", stats.tx_broadcast),
53 I40E_VEB_STAT("veb.rx_discards", stats.rx_discards),
54 I40E_VEB_STAT("veb.tx_discards", stats.tx_discards),
55 I40E_VEB_STAT("veb.tx_errors", stats.tx_errors),
56 I40E_VEB_STAT("veb.rx_unknown_protocol", stats.rx_unknown_protocol),
59 static const struct i40e_stats i40e_gstrings_misc_stats[] = {
60 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
61 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
62 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
63 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
64 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
65 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
66 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
67 I40E_VSI_STAT("tx_linearize", tx_linearize),
68 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
69 I40E_VSI_STAT("tx_busy", tx_busy),
70 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
71 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
74 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
75 * but they are separate. This device supports Virtualization, and
76 * as such might have several netdevs supporting VMDq and FCoE going
77 * through a single port. The NETDEV_STATs are for individual netdevs
78 * seen at the top of the stack, and the PF_STATs are for the physical
79 * function at the bottom of the stack hosting those netdevs.
81 * The PF_STATs are appended to the netdev stats only when ethtool -S
82 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
84 static const struct i40e_stats i40e_gstrings_stats[] = {
85 I40E_PF_STAT("port.rx_bytes", stats.eth.rx_bytes),
86 I40E_PF_STAT("port.tx_bytes", stats.eth.tx_bytes),
87 I40E_PF_STAT("port.rx_unicast", stats.eth.rx_unicast),
88 I40E_PF_STAT("port.tx_unicast", stats.eth.tx_unicast),
89 I40E_PF_STAT("port.rx_multicast", stats.eth.rx_multicast),
90 I40E_PF_STAT("port.tx_multicast", stats.eth.tx_multicast),
91 I40E_PF_STAT("port.rx_broadcast", stats.eth.rx_broadcast),
92 I40E_PF_STAT("port.tx_broadcast", stats.eth.tx_broadcast),
93 I40E_PF_STAT("port.tx_errors", stats.eth.tx_errors),
94 I40E_PF_STAT("port.rx_dropped", stats.eth.rx_discards),
95 I40E_PF_STAT("port.tx_dropped_link_down", stats.tx_dropped_link_down),
96 I40E_PF_STAT("port.rx_crc_errors", stats.crc_errors),
97 I40E_PF_STAT("port.illegal_bytes", stats.illegal_bytes),
98 I40E_PF_STAT("port.mac_local_faults", stats.mac_local_faults),
99 I40E_PF_STAT("port.mac_remote_faults", stats.mac_remote_faults),
100 I40E_PF_STAT("port.tx_timeout", tx_timeout_count),
101 I40E_PF_STAT("port.rx_csum_bad", hw_csum_rx_error),
102 I40E_PF_STAT("port.rx_length_errors", stats.rx_length_errors),
103 I40E_PF_STAT("port.link_xon_rx", stats.link_xon_rx),
104 I40E_PF_STAT("port.link_xoff_rx", stats.link_xoff_rx),
105 I40E_PF_STAT("port.link_xon_tx", stats.link_xon_tx),
106 I40E_PF_STAT("port.link_xoff_tx", stats.link_xoff_tx),
107 I40E_PF_STAT("port.rx_size_64", stats.rx_size_64),
108 I40E_PF_STAT("port.rx_size_127", stats.rx_size_127),
109 I40E_PF_STAT("port.rx_size_255", stats.rx_size_255),
110 I40E_PF_STAT("port.rx_size_511", stats.rx_size_511),
111 I40E_PF_STAT("port.rx_size_1023", stats.rx_size_1023),
112 I40E_PF_STAT("port.rx_size_1522", stats.rx_size_1522),
113 I40E_PF_STAT("port.rx_size_big", stats.rx_size_big),
114 I40E_PF_STAT("port.tx_size_64", stats.tx_size_64),
115 I40E_PF_STAT("port.tx_size_127", stats.tx_size_127),
116 I40E_PF_STAT("port.tx_size_255", stats.tx_size_255),
117 I40E_PF_STAT("port.tx_size_511", stats.tx_size_511),
118 I40E_PF_STAT("port.tx_size_1023", stats.tx_size_1023),
119 I40E_PF_STAT("port.tx_size_1522", stats.tx_size_1522),
120 I40E_PF_STAT("port.tx_size_big", stats.tx_size_big),
121 I40E_PF_STAT("port.rx_undersize", stats.rx_undersize),
122 I40E_PF_STAT("port.rx_fragments", stats.rx_fragments),
123 I40E_PF_STAT("port.rx_oversize", stats.rx_oversize),
124 I40E_PF_STAT("port.rx_jabber", stats.rx_jabber),
125 I40E_PF_STAT("port.VF_admin_queue_requests", vf_aq_requests),
126 I40E_PF_STAT("port.arq_overflows", arq_overflows),
127 I40E_PF_STAT("port.tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
128 I40E_PF_STAT("port.rx_hwtstamp_cleared", rx_hwtstamp_cleared),
129 I40E_PF_STAT("port.tx_hwtstamp_skipped", tx_hwtstamp_skipped),
130 I40E_PF_STAT("port.fdir_flush_cnt", fd_flush_cnt),
131 I40E_PF_STAT("port.fdir_atr_match", stats.fd_atr_match),
132 I40E_PF_STAT("port.fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
133 I40E_PF_STAT("port.fdir_atr_status", stats.fd_atr_status),
134 I40E_PF_STAT("port.fdir_sb_match", stats.fd_sb_match),
135 I40E_PF_STAT("port.fdir_sb_status", stats.fd_sb_status),
138 I40E_PF_STAT("port.tx_lpi_status", stats.tx_lpi_status),
139 I40E_PF_STAT("port.rx_lpi_status", stats.rx_lpi_status),
140 I40E_PF_STAT("port.tx_lpi_count", stats.tx_lpi_count),
141 I40E_PF_STAT("port.rx_lpi_count", stats.rx_lpi_count),
144 /* We use num_tx_queues here as a proxy for the maximum number of queues
145 * available because we always allocate queues symmetrically.
147 #define I40E_MAX_NUM_QUEUES(n) ((n)->num_tx_queues)
148 #define I40E_QUEUE_STATS_LEN(n) \
149 (I40E_MAX_NUM_QUEUES(n) \
150 * 2 /* Tx and Rx together */ \
151 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
152 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
153 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
154 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
155 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
156 I40E_MISC_STATS_LEN + \
157 I40E_QUEUE_STATS_LEN((n)))
158 #define I40E_PFC_STATS_LEN ( \
159 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
160 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
161 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
162 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
163 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
165 #define I40E_VEB_TC_STATS_LEN ( \
166 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
167 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
168 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
169 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
171 #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
172 #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
173 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
174 I40E_PFC_STATS_LEN + \
175 I40E_VSI_STATS_LEN((n)))
177 enum i40e_ethtool_test_id {
178 I40E_ETH_TEST_REG = 0,
179 I40E_ETH_TEST_EEPROM,
184 static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
185 "Register test (offline)",
186 "Eeprom test (offline)",
187 "Interrupt test (offline)",
188 "Link test (on/offline)"
191 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
193 struct i40e_priv_flags {
194 char flag_string[ETH_GSTRING_LEN];
199 #define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
200 .flag_string = _name, \
202 .read_only = _read_only, \
205 static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
206 /* NOTE: MFP setting cannot be changed */
207 I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
208 I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
209 I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
210 I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
211 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
212 I40E_PRIV_FLAG("link-down-on-close",
213 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED, 0),
214 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
215 I40E_PRIV_FLAG("disable-source-pruning",
216 I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),
217 I40E_PRIV_FLAG("disable-fw-lldp", I40E_FLAG_DISABLE_FW_LLDP, 0),
220 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
222 /* Private flags with a global effect, restricted to PF 0 */
223 static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
224 I40E_PRIV_FLAG("vf-true-promisc-support",
225 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
228 #define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
231 * i40e_partition_setting_complaint - generic complaint for MFP restriction
234 static void i40e_partition_setting_complaint(struct i40e_pf *pf)
236 dev_info(&pf->pdev->dev,
237 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
241 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
242 * @pf: PF struct with phy_types
243 * @ks: ethtool link ksettings struct to fill out
246 static void i40e_phy_type_to_ethtool(struct i40e_pf *pf,
247 struct ethtool_link_ksettings *ks)
249 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
250 u64 phy_types = pf->hw.phy.phy_types;
252 ethtool_link_ksettings_zero_link_mode(ks, supported);
253 ethtool_link_ksettings_zero_link_mode(ks, advertising);
255 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
256 ethtool_link_ksettings_add_link_mode(ks, supported,
258 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
259 ethtool_link_ksettings_add_link_mode(ks, advertising,
261 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
262 ethtool_link_ksettings_add_link_mode(ks, supported,
264 ethtool_link_ksettings_add_link_mode(ks, advertising,
268 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
269 phy_types & I40E_CAP_PHY_TYPE_XFI ||
270 phy_types & I40E_CAP_PHY_TYPE_SFI ||
271 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
272 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) {
273 ethtool_link_ksettings_add_link_mode(ks, supported,
275 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
276 ethtool_link_ksettings_add_link_mode(ks, advertising,
279 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_T) {
280 ethtool_link_ksettings_add_link_mode(ks, supported,
282 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
283 ethtool_link_ksettings_add_link_mode(ks, advertising,
286 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
287 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
288 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
289 ethtool_link_ksettings_add_link_mode(ks, supported,
291 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
292 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
293 ethtool_link_ksettings_add_link_mode(ks, supported,
295 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
296 ethtool_link_ksettings_add_link_mode(ks, advertising,
299 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
300 ethtool_link_ksettings_add_link_mode(ks, supported,
302 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
303 ethtool_link_ksettings_add_link_mode(ks, advertising,
306 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T) {
307 ethtool_link_ksettings_add_link_mode(ks, supported,
309 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
310 ethtool_link_ksettings_add_link_mode(ks, advertising,
313 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
314 ethtool_link_ksettings_add_link_mode(ks, supported,
316 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
317 ethtool_link_ksettings_add_link_mode(ks, supported,
319 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
320 ethtool_link_ksettings_add_link_mode(ks, supported,
322 ethtool_link_ksettings_add_link_mode(ks, advertising,
325 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
326 ethtool_link_ksettings_add_link_mode(ks, supported,
328 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
329 ethtool_link_ksettings_add_link_mode(ks, advertising,
332 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
333 ethtool_link_ksettings_add_link_mode(ks, supported,
335 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
336 ethtool_link_ksettings_add_link_mode(ks, advertising,
339 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR &&
340 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
341 ethtool_link_ksettings_add_link_mode(ks, supported,
343 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
344 ethtool_link_ksettings_add_link_mode(ks, advertising,
347 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX &&
348 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
349 ethtool_link_ksettings_add_link_mode(ks, supported,
351 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
352 ethtool_link_ksettings_add_link_mode(ks, advertising,
355 /* need to add 25G PHY types */
356 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR) {
357 ethtool_link_ksettings_add_link_mode(ks, supported,
359 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
360 ethtool_link_ksettings_add_link_mode(ks, advertising,
363 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR) {
364 ethtool_link_ksettings_add_link_mode(ks, supported,
366 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
367 ethtool_link_ksettings_add_link_mode(ks, advertising,
370 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
371 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
372 ethtool_link_ksettings_add_link_mode(ks, supported,
374 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
375 ethtool_link_ksettings_add_link_mode(ks, advertising,
378 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC ||
379 phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) {
380 ethtool_link_ksettings_add_link_mode(ks, supported,
382 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
383 ethtool_link_ksettings_add_link_mode(ks, advertising,
386 /* need to add new 10G PHY types */
387 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
388 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU) {
389 ethtool_link_ksettings_add_link_mode(ks, supported,
391 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
392 ethtool_link_ksettings_add_link_mode(ks, advertising,
395 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR) {
396 ethtool_link_ksettings_add_link_mode(ks, supported,
398 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
399 ethtool_link_ksettings_add_link_mode(ks, advertising,
402 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
403 ethtool_link_ksettings_add_link_mode(ks, supported,
405 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
406 ethtool_link_ksettings_add_link_mode(ks, advertising,
409 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
410 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
411 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
412 ethtool_link_ksettings_add_link_mode(ks, supported,
414 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
415 ethtool_link_ksettings_add_link_mode(ks, advertising,
418 /* Autoneg PHY types */
419 if (phy_types & I40E_CAP_PHY_TYPE_SGMII ||
420 phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 ||
421 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
422 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 ||
423 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
424 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR ||
425 phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
426 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
427 phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 ||
428 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
429 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
430 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR ||
431 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ||
432 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ||
433 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
434 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
435 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL ||
436 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
437 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
438 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
439 phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ||
440 phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
441 ethtool_link_ksettings_add_link_mode(ks, supported,
443 ethtool_link_ksettings_add_link_mode(ks, advertising,
449 * i40e_get_settings_link_up - Get the Link settings for when link is up
451 * @ks: ethtool ksettings to fill in
452 * @netdev: network interface device structure
453 * @pf: pointer to physical function struct
455 static void i40e_get_settings_link_up(struct i40e_hw *hw,
456 struct ethtool_link_ksettings *ks,
457 struct net_device *netdev,
460 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
461 struct ethtool_link_ksettings cap_ksettings;
462 u32 link_speed = hw_link_info->link_speed;
464 /* Initialize supported and advertised settings based on phy settings */
465 switch (hw_link_info->phy_type) {
466 case I40E_PHY_TYPE_40GBASE_CR4:
467 case I40E_PHY_TYPE_40GBASE_CR4_CU:
468 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
469 ethtool_link_ksettings_add_link_mode(ks, supported,
471 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
472 ethtool_link_ksettings_add_link_mode(ks, advertising,
475 case I40E_PHY_TYPE_XLAUI:
476 case I40E_PHY_TYPE_XLPPI:
477 case I40E_PHY_TYPE_40GBASE_AOC:
478 ethtool_link_ksettings_add_link_mode(ks, supported,
481 case I40E_PHY_TYPE_40GBASE_SR4:
482 ethtool_link_ksettings_add_link_mode(ks, supported,
485 case I40E_PHY_TYPE_40GBASE_LR4:
486 ethtool_link_ksettings_add_link_mode(ks, supported,
489 case I40E_PHY_TYPE_25GBASE_SR:
490 case I40E_PHY_TYPE_25GBASE_LR:
491 case I40E_PHY_TYPE_10GBASE_SR:
492 case I40E_PHY_TYPE_10GBASE_LR:
493 case I40E_PHY_TYPE_1000BASE_SX:
494 case I40E_PHY_TYPE_1000BASE_LX:
495 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
496 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
497 ethtool_link_ksettings_add_link_mode(ks, supported,
499 ethtool_link_ksettings_add_link_mode(ks, advertising,
501 ethtool_link_ksettings_add_link_mode(ks, supported,
503 ethtool_link_ksettings_add_link_mode(ks, advertising,
505 ethtool_link_ksettings_add_link_mode(ks, supported,
507 ethtool_link_ksettings_add_link_mode(ks, advertising,
509 ethtool_link_ksettings_add_link_mode(ks, supported,
511 ethtool_link_ksettings_add_link_mode(ks, advertising,
513 ethtool_link_ksettings_add_link_mode(ks, supported,
515 if (hw_link_info->module_type[2] &
516 I40E_MODULE_TYPE_1000BASE_SX ||
517 hw_link_info->module_type[2] &
518 I40E_MODULE_TYPE_1000BASE_LX) {
519 ethtool_link_ksettings_add_link_mode(ks, supported,
521 if (hw_link_info->requested_speeds &
523 ethtool_link_ksettings_add_link_mode(
524 ks, advertising, 1000baseT_Full);
526 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
527 ethtool_link_ksettings_add_link_mode(ks, advertising,
530 case I40E_PHY_TYPE_10GBASE_T:
531 case I40E_PHY_TYPE_1000BASE_T:
532 case I40E_PHY_TYPE_100BASE_TX:
533 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
534 ethtool_link_ksettings_add_link_mode(ks, supported,
536 ethtool_link_ksettings_add_link_mode(ks, supported,
538 ethtool_link_ksettings_add_link_mode(ks, supported,
540 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
541 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
542 ethtool_link_ksettings_add_link_mode(ks, advertising,
544 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
545 ethtool_link_ksettings_add_link_mode(ks, advertising,
547 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
548 ethtool_link_ksettings_add_link_mode(ks, advertising,
551 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
552 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
553 ethtool_link_ksettings_add_link_mode(ks, supported,
555 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
556 ethtool_link_ksettings_add_link_mode(ks, advertising,
559 case I40E_PHY_TYPE_10GBASE_CR1_CU:
560 case I40E_PHY_TYPE_10GBASE_CR1:
561 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
562 ethtool_link_ksettings_add_link_mode(ks, supported,
564 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
565 ethtool_link_ksettings_add_link_mode(ks, advertising,
568 case I40E_PHY_TYPE_XAUI:
569 case I40E_PHY_TYPE_XFI:
570 case I40E_PHY_TYPE_SFI:
571 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
572 case I40E_PHY_TYPE_10GBASE_AOC:
573 ethtool_link_ksettings_add_link_mode(ks, supported,
575 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
576 ethtool_link_ksettings_add_link_mode(ks, advertising,
579 case I40E_PHY_TYPE_SGMII:
580 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
581 ethtool_link_ksettings_add_link_mode(ks, supported,
583 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
584 ethtool_link_ksettings_add_link_mode(ks, advertising,
586 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
587 ethtool_link_ksettings_add_link_mode(ks, supported,
589 if (hw_link_info->requested_speeds &
590 I40E_LINK_SPEED_100MB)
591 ethtool_link_ksettings_add_link_mode(
592 ks, advertising, 100baseT_Full);
595 case I40E_PHY_TYPE_40GBASE_KR4:
596 case I40E_PHY_TYPE_25GBASE_KR:
597 case I40E_PHY_TYPE_20GBASE_KR2:
598 case I40E_PHY_TYPE_10GBASE_KR:
599 case I40E_PHY_TYPE_10GBASE_KX4:
600 case I40E_PHY_TYPE_1000BASE_KX:
601 ethtool_link_ksettings_add_link_mode(ks, supported,
603 ethtool_link_ksettings_add_link_mode(ks, supported,
605 ethtool_link_ksettings_add_link_mode(ks, supported,
607 ethtool_link_ksettings_add_link_mode(ks, supported,
609 ethtool_link_ksettings_add_link_mode(ks, supported,
611 ethtool_link_ksettings_add_link_mode(ks, supported,
613 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
614 ethtool_link_ksettings_add_link_mode(ks, advertising,
616 ethtool_link_ksettings_add_link_mode(ks, advertising,
618 ethtool_link_ksettings_add_link_mode(ks, advertising,
620 ethtool_link_ksettings_add_link_mode(ks, advertising,
622 ethtool_link_ksettings_add_link_mode(ks, advertising,
624 ethtool_link_ksettings_add_link_mode(ks, advertising,
626 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
628 case I40E_PHY_TYPE_25GBASE_CR:
629 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
630 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
631 ethtool_link_ksettings_add_link_mode(ks, supported,
633 ethtool_link_ksettings_add_link_mode(ks, advertising,
636 case I40E_PHY_TYPE_25GBASE_AOC:
637 case I40E_PHY_TYPE_25GBASE_ACC:
638 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
639 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
640 ethtool_link_ksettings_add_link_mode(ks, supported,
643 ethtool_link_ksettings_add_link_mode(ks, advertising,
645 ethtool_link_ksettings_add_link_mode(ks, supported,
647 ethtool_link_ksettings_add_link_mode(ks, advertising,
651 /* if we got here and link is up something bad is afoot */
653 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
654 hw_link_info->phy_type);
657 /* Now that we've worked out everything that could be supported by the
658 * current PHY type, get what is supported by the NVM and intersect
659 * them to get what is truly supported
661 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
662 i40e_phy_type_to_ethtool(pf, &cap_ksettings);
663 ethtool_intersect_link_masks(ks, &cap_ksettings);
665 /* Set speed and duplex */
666 switch (link_speed) {
667 case I40E_LINK_SPEED_40GB:
668 ks->base.speed = SPEED_40000;
670 case I40E_LINK_SPEED_25GB:
671 ks->base.speed = SPEED_25000;
673 case I40E_LINK_SPEED_20GB:
674 ks->base.speed = SPEED_20000;
676 case I40E_LINK_SPEED_10GB:
677 ks->base.speed = SPEED_10000;
679 case I40E_LINK_SPEED_1GB:
680 ks->base.speed = SPEED_1000;
682 case I40E_LINK_SPEED_100MB:
683 ks->base.speed = SPEED_100;
688 ks->base.duplex = DUPLEX_FULL;
692 * i40e_get_settings_link_down - Get the Link settings for when link is down
694 * @ks: ethtool ksettings to fill in
695 * @pf: pointer to physical function struct
697 * Reports link settings that can be determined when link is down
699 static void i40e_get_settings_link_down(struct i40e_hw *hw,
700 struct ethtool_link_ksettings *ks,
703 /* link is down and the driver needs to fall back on
704 * supported phy types to figure out what info to display
706 i40e_phy_type_to_ethtool(pf, ks);
708 /* With no link speed and duplex are unknown */
709 ks->base.speed = SPEED_UNKNOWN;
710 ks->base.duplex = DUPLEX_UNKNOWN;
714 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
715 * @netdev: network interface device structure
716 * @ks: ethtool ksettings
718 * Reports speed/duplex settings based on media_type
720 static int i40e_get_link_ksettings(struct net_device *netdev,
721 struct ethtool_link_ksettings *ks)
723 struct i40e_netdev_priv *np = netdev_priv(netdev);
724 struct i40e_pf *pf = np->vsi->back;
725 struct i40e_hw *hw = &pf->hw;
726 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
727 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
729 ethtool_link_ksettings_zero_link_mode(ks, supported);
730 ethtool_link_ksettings_zero_link_mode(ks, advertising);
733 i40e_get_settings_link_up(hw, ks, netdev, pf);
735 i40e_get_settings_link_down(hw, ks, pf);
737 /* Now set the settings that don't rely on link being up/down */
738 /* Set autoneg settings */
739 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
740 AUTONEG_ENABLE : AUTONEG_DISABLE);
742 /* Set media type settings */
743 switch (hw->phy.media_type) {
744 case I40E_MEDIA_TYPE_BACKPLANE:
745 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
746 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
747 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
748 ethtool_link_ksettings_add_link_mode(ks, advertising,
750 ks->base.port = PORT_NONE;
752 case I40E_MEDIA_TYPE_BASET:
753 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
754 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
755 ks->base.port = PORT_TP;
757 case I40E_MEDIA_TYPE_DA:
758 case I40E_MEDIA_TYPE_CX4:
759 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
760 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
761 ks->base.port = PORT_DA;
763 case I40E_MEDIA_TYPE_FIBER:
764 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
765 ks->base.port = PORT_FIBRE;
767 case I40E_MEDIA_TYPE_UNKNOWN:
769 ks->base.port = PORT_OTHER;
773 /* Set flow control settings */
774 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
776 switch (hw->fc.requested_mode) {
778 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
780 case I40E_FC_TX_PAUSE:
781 ethtool_link_ksettings_add_link_mode(ks, advertising,
784 case I40E_FC_RX_PAUSE:
785 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
786 ethtool_link_ksettings_add_link_mode(ks, advertising,
790 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
791 ethtool_link_ksettings_del_link_mode(ks, advertising,
800 * i40e_set_link_ksettings - Set Speed and Duplex
801 * @netdev: network interface device structure
802 * @ks: ethtool ksettings
804 * Set speed/duplex per media_types advertised/forced
806 static int i40e_set_link_ksettings(struct net_device *netdev,
807 const struct ethtool_link_ksettings *ks)
809 struct i40e_netdev_priv *np = netdev_priv(netdev);
810 struct i40e_aq_get_phy_abilities_resp abilities;
811 struct ethtool_link_ksettings safe_ks;
812 struct ethtool_link_ksettings copy_ks;
813 struct i40e_aq_set_phy_config config;
814 struct i40e_pf *pf = np->vsi->back;
815 struct i40e_vsi *vsi = np->vsi;
816 struct i40e_hw *hw = &pf->hw;
817 bool autoneg_changed = false;
818 i40e_status status = 0;
823 /* Changing port settings is not supported if this isn't the
824 * port's controlling PF
826 if (hw->partition_id != 1) {
827 i40e_partition_setting_complaint(pf);
830 if (vsi != pf->vsi[pf->lan_vsi])
832 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
833 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
834 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
835 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
836 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
838 if (hw->device_id == I40E_DEV_ID_KX_B ||
839 hw->device_id == I40E_DEV_ID_KX_C ||
840 hw->device_id == I40E_DEV_ID_20G_KR2 ||
841 hw->device_id == I40E_DEV_ID_20G_KR2_A ||
842 hw->device_id == I40E_DEV_ID_25G_B ||
843 hw->device_id == I40E_DEV_ID_KX_X722) {
844 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
848 /* copy the ksettings to copy_ks to avoid modifying the origin */
849 memcpy(©_ks, ks, sizeof(struct ethtool_link_ksettings));
851 /* save autoneg out of ksettings */
852 autoneg = copy_ks.base.autoneg;
854 /* get our own copy of the bits to check against */
855 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
856 safe_ks.base.cmd = copy_ks.base.cmd;
857 safe_ks.base.link_mode_masks_nwords =
858 copy_ks.base.link_mode_masks_nwords;
859 i40e_get_link_ksettings(netdev, &safe_ks);
861 /* Get link modes supported by hardware and check against modes
862 * requested by the user. Return an error if unsupported mode was set.
864 if (!bitmap_subset(copy_ks.link_modes.advertising,
865 safe_ks.link_modes.supported,
866 __ETHTOOL_LINK_MODE_MASK_NBITS))
869 /* set autoneg back to what it currently is */
870 copy_ks.base.autoneg = safe_ks.base.autoneg;
872 /* If copy_ks.base and safe_ks.base are not the same now, then they are
873 * trying to set something that we do not support.
875 if (memcmp(©_ks.base, &safe_ks.base,
876 sizeof(struct ethtool_link_settings)))
879 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
883 usleep_range(1000, 2000);
886 /* Get the current phy config */
887 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
894 /* Copy abilities to config in case autoneg is not
897 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
898 config.abilities = abilities.abilities;
901 if (autoneg == AUTONEG_ENABLE) {
902 /* If autoneg was not already enabled */
903 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
904 /* If autoneg is not supported, return error */
905 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
908 netdev_info(netdev, "Autoneg not supported on this phy\n");
912 /* Autoneg is allowed to change */
913 config.abilities = abilities.abilities |
914 I40E_AQ_PHY_ENABLE_AN;
915 autoneg_changed = true;
918 /* If autoneg is currently enabled */
919 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
920 /* If autoneg is supported 10GBASE_T is the only PHY
921 * that can disable it, so otherwise return error
923 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
926 hw->phy.link_info.phy_type !=
927 I40E_PHY_TYPE_10GBASE_T) {
928 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
932 /* Autoneg is allowed to change */
933 config.abilities = abilities.abilities &
934 ~I40E_AQ_PHY_ENABLE_AN;
935 autoneg_changed = true;
939 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
941 config.link_speed |= I40E_LINK_SPEED_100MB;
942 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
944 ethtool_link_ksettings_test_link_mode(ks, advertising,
946 ethtool_link_ksettings_test_link_mode(ks, advertising,
948 config.link_speed |= I40E_LINK_SPEED_1GB;
949 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
951 ethtool_link_ksettings_test_link_mode(ks, advertising,
952 10000baseKX4_Full) ||
953 ethtool_link_ksettings_test_link_mode(ks, advertising,
955 ethtool_link_ksettings_test_link_mode(ks, advertising,
957 ethtool_link_ksettings_test_link_mode(ks, advertising,
959 ethtool_link_ksettings_test_link_mode(ks, advertising,
961 config.link_speed |= I40E_LINK_SPEED_10GB;
962 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
964 config.link_speed |= I40E_LINK_SPEED_20GB;
965 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
967 ethtool_link_ksettings_test_link_mode(ks, advertising,
969 ethtool_link_ksettings_test_link_mode(ks, advertising,
971 config.link_speed |= I40E_LINK_SPEED_25GB;
972 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
973 40000baseKR4_Full) ||
974 ethtool_link_ksettings_test_link_mode(ks, advertising,
975 40000baseCR4_Full) ||
976 ethtool_link_ksettings_test_link_mode(ks, advertising,
977 40000baseSR4_Full) ||
978 ethtool_link_ksettings_test_link_mode(ks, advertising,
980 config.link_speed |= I40E_LINK_SPEED_40GB;
982 /* If speed didn't get set, set it to what it currently is.
983 * This is needed because if advertise is 0 (as it is when autoneg
984 * is disabled) then speed won't get set.
986 if (!config.link_speed)
987 config.link_speed = abilities.link_speed;
988 if (autoneg_changed || abilities.link_speed != config.link_speed) {
989 /* copy over the rest of the abilities */
990 config.phy_type = abilities.phy_type;
991 config.phy_type_ext = abilities.phy_type_ext;
992 config.eee_capability = abilities.eee_capability;
993 config.eeer = abilities.eeer_val;
994 config.low_power_ctrl = abilities.d3_lpan;
995 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
996 I40E_AQ_PHY_FEC_CONFIG_MASK;
998 /* save the requested speeds */
999 hw->phy.link_info.requested_speeds = config.link_speed;
1000 /* set link and auto negotiation so changes take effect */
1001 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1002 /* If link is up put link down */
1003 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
1004 /* Tell the OS link is going down, the link will go
1005 * back up when fw says it is ready asynchronously
1007 i40e_print_link_message(vsi, false);
1008 netif_carrier_off(netdev);
1009 netif_tx_stop_all_queues(netdev);
1012 /* make the aq call */
1013 status = i40e_aq_set_phy_config(hw, &config, NULL);
1016 "Set phy config failed, err %s aq_err %s\n",
1017 i40e_stat_str(hw, status),
1018 i40e_aq_str(hw, hw->aq.asq_last_status));
1023 status = i40e_update_link_info(hw);
1026 "Updating link info failed with err %s aq_err %s\n",
1027 i40e_stat_str(hw, status),
1028 i40e_aq_str(hw, hw->aq.asq_last_status));
1031 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1035 clear_bit(__I40E_CONFIG_BUSY, pf->state);
1040 static int i40e_nway_reset(struct net_device *netdev)
1042 /* restart autonegotiation */
1043 struct i40e_netdev_priv *np = netdev_priv(netdev);
1044 struct i40e_pf *pf = np->vsi->back;
1045 struct i40e_hw *hw = &pf->hw;
1046 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1047 i40e_status ret = 0;
1049 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
1051 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1052 i40e_stat_str(hw, ret),
1053 i40e_aq_str(hw, hw->aq.asq_last_status));
1061 * i40e_get_pauseparam - Get Flow Control status
1062 * @netdev: netdevice structure
1063 * @pause: buffer to return pause parameters
1065 * Return tx/rx-pause status
1067 static void i40e_get_pauseparam(struct net_device *netdev,
1068 struct ethtool_pauseparam *pause)
1070 struct i40e_netdev_priv *np = netdev_priv(netdev);
1071 struct i40e_pf *pf = np->vsi->back;
1072 struct i40e_hw *hw = &pf->hw;
1073 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1074 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
1077 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1078 AUTONEG_ENABLE : AUTONEG_DISABLE);
1080 /* PFC enabled so report LFC as off */
1081 if (dcbx_cfg->pfc.pfcenable) {
1082 pause->rx_pause = 0;
1083 pause->tx_pause = 0;
1087 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
1088 pause->rx_pause = 1;
1089 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
1090 pause->tx_pause = 1;
1091 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1092 pause->rx_pause = 1;
1093 pause->tx_pause = 1;
1098 * i40e_set_pauseparam - Set Flow Control parameter
1099 * @netdev: network interface device structure
1100 * @pause: return tx/rx flow control status
1102 static int i40e_set_pauseparam(struct net_device *netdev,
1103 struct ethtool_pauseparam *pause)
1105 struct i40e_netdev_priv *np = netdev_priv(netdev);
1106 struct i40e_pf *pf = np->vsi->back;
1107 struct i40e_vsi *vsi = np->vsi;
1108 struct i40e_hw *hw = &pf->hw;
1109 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1110 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
1111 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1116 /* Changing the port's flow control is not supported if this isn't the
1117 * port's controlling PF
1119 if (hw->partition_id != 1) {
1120 i40e_partition_setting_complaint(pf);
1124 if (vsi != pf->vsi[pf->lan_vsi])
1127 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1128 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
1129 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1133 /* If we have link and don't have autoneg */
1134 if (!test_bit(__I40E_DOWN, pf->state) &&
1135 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
1136 /* Send message that it might not necessarily work*/
1137 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1140 if (dcbx_cfg->pfc.pfcenable) {
1142 "Priority flow control enabled. Cannot set link flow control.\n");
1146 if (pause->rx_pause && pause->tx_pause)
1147 hw->fc.requested_mode = I40E_FC_FULL;
1148 else if (pause->rx_pause && !pause->tx_pause)
1149 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1150 else if (!pause->rx_pause && pause->tx_pause)
1151 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1152 else if (!pause->rx_pause && !pause->tx_pause)
1153 hw->fc.requested_mode = I40E_FC_NONE;
1157 /* Tell the OS link is going down, the link will go back up when fw
1158 * says it is ready asynchronously
1160 i40e_print_link_message(vsi, false);
1161 netif_carrier_off(netdev);
1162 netif_tx_stop_all_queues(netdev);
1164 /* Set the fc mode and only restart an if link is up*/
1165 status = i40e_set_fc(hw, &aq_failures, link_up);
1167 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
1168 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1169 i40e_stat_str(hw, status),
1170 i40e_aq_str(hw, hw->aq.asq_last_status));
1173 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
1174 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1175 i40e_stat_str(hw, status),
1176 i40e_aq_str(hw, hw->aq.asq_last_status));
1179 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
1180 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1181 i40e_stat_str(hw, status),
1182 i40e_aq_str(hw, hw->aq.asq_last_status));
1186 if (!test_bit(__I40E_DOWN, pf->state)) {
1187 /* Give it a little more time to try to come back */
1189 if (!test_bit(__I40E_DOWN, pf->state))
1190 return i40e_nway_reset(netdev);
1196 static u32 i40e_get_msglevel(struct net_device *netdev)
1198 struct i40e_netdev_priv *np = netdev_priv(netdev);
1199 struct i40e_pf *pf = np->vsi->back;
1200 u32 debug_mask = pf->hw.debug_mask;
1203 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
1205 return pf->msg_enable;
1208 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1210 struct i40e_netdev_priv *np = netdev_priv(netdev);
1211 struct i40e_pf *pf = np->vsi->back;
1213 if (I40E_DEBUG_USER & data)
1214 pf->hw.debug_mask = data;
1216 pf->msg_enable = data;
1219 static int i40e_get_regs_len(struct net_device *netdev)
1224 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1225 reg_count += i40e_reg_list[i].elements;
1227 return reg_count * sizeof(u32);
1230 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1233 struct i40e_netdev_priv *np = netdev_priv(netdev);
1234 struct i40e_pf *pf = np->vsi->back;
1235 struct i40e_hw *hw = &pf->hw;
1237 unsigned int i, j, ri;
1240 /* Tell ethtool which driver-version-specific regs output we have.
1242 * At some point, if we have ethtool doing special formatting of
1243 * this data, it will rely on this version number to know how to
1244 * interpret things. Hence, this needs to be updated if/when the
1245 * diags register table is changed.
1249 /* loop through the diags reg table for what to print */
1251 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1252 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1253 reg = i40e_reg_list[i].offset
1254 + (j * i40e_reg_list[i].stride);
1255 reg_buf[ri++] = rd32(hw, reg);
1261 static int i40e_get_eeprom(struct net_device *netdev,
1262 struct ethtool_eeprom *eeprom, u8 *bytes)
1264 struct i40e_netdev_priv *np = netdev_priv(netdev);
1265 struct i40e_hw *hw = &np->vsi->back->hw;
1266 struct i40e_pf *pf = np->vsi->back;
1267 int ret_val = 0, len, offset;
1273 #define I40E_NVM_SECTOR_SIZE 4096
1274 if (eeprom->len == 0)
1277 /* check for NVMUpdate access method */
1278 magic = hw->vendor_id | (hw->device_id << 16);
1279 if (eeprom->magic && eeprom->magic != magic) {
1280 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1283 /* make sure it is the right magic for NVMUpdate */
1284 if ((eeprom->magic >> 16) != hw->device_id)
1286 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1287 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
1290 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1292 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
1293 dev_info(&pf->pdev->dev,
1294 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1295 ret_val, hw->aq.asq_last_status, errno,
1296 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1297 cmd->offset, cmd->data_size);
1302 /* normal ethtool get_eeprom support */
1303 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1305 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
1309 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1311 dev_info(&pf->pdev->dev,
1312 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1313 ret_val, hw->aq.asq_last_status);
1317 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1318 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1319 len = I40E_NVM_SECTOR_SIZE;
1321 for (i = 0; i < sectors; i++) {
1322 if (i == (sectors - 1)) {
1323 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1326 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1327 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
1328 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
1330 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
1331 dev_info(&pf->pdev->dev,
1332 "read NVM failed, invalid offset 0x%x\n",
1335 } else if (ret_val &&
1336 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1337 dev_info(&pf->pdev->dev,
1338 "read NVM failed, access, offset 0x%x\n",
1341 } else if (ret_val) {
1342 dev_info(&pf->pdev->dev,
1343 "read NVM failed offset %d err=%d status=0x%x\n",
1344 offset, ret_val, hw->aq.asq_last_status);
1349 i40e_release_nvm(hw);
1350 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
1356 static int i40e_get_eeprom_len(struct net_device *netdev)
1358 struct i40e_netdev_priv *np = netdev_priv(netdev);
1359 struct i40e_hw *hw = &np->vsi->back->hw;
1362 #define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1363 if (hw->mac.type == I40E_MAC_X722) {
1364 val = X722_EEPROM_SCOPE_LIMIT + 1;
1367 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1368 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1369 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1370 /* register returns value in power of 2, 64Kbyte chunks. */
1371 val = (64 * 1024) * BIT(val);
1375 static int i40e_set_eeprom(struct net_device *netdev,
1376 struct ethtool_eeprom *eeprom, u8 *bytes)
1378 struct i40e_netdev_priv *np = netdev_priv(netdev);
1379 struct i40e_hw *hw = &np->vsi->back->hw;
1380 struct i40e_pf *pf = np->vsi->back;
1381 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1386 /* normal ethtool set_eeprom is not supported */
1387 magic = hw->vendor_id | (hw->device_id << 16);
1388 if (eeprom->magic == magic)
1389 errno = -EOPNOTSUPP;
1390 /* check for NVMUpdate access method */
1391 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1393 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1394 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
1397 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1399 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
1400 dev_info(&pf->pdev->dev,
1401 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1402 ret_val, hw->aq.asq_last_status, errno,
1403 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1404 cmd->offset, cmd->data_size);
1409 static void i40e_get_drvinfo(struct net_device *netdev,
1410 struct ethtool_drvinfo *drvinfo)
1412 struct i40e_netdev_priv *np = netdev_priv(netdev);
1413 struct i40e_vsi *vsi = np->vsi;
1414 struct i40e_pf *pf = vsi->back;
1416 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1417 strlcpy(drvinfo->version, i40e_driver_version_str,
1418 sizeof(drvinfo->version));
1419 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
1420 sizeof(drvinfo->fw_version));
1421 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1422 sizeof(drvinfo->bus_info));
1423 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
1424 if (pf->hw.pf_id == 0)
1425 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
1428 static void i40e_get_ringparam(struct net_device *netdev,
1429 struct ethtool_ringparam *ring)
1431 struct i40e_netdev_priv *np = netdev_priv(netdev);
1432 struct i40e_pf *pf = np->vsi->back;
1433 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1435 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1436 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1437 ring->rx_mini_max_pending = 0;
1438 ring->rx_jumbo_max_pending = 0;
1439 ring->rx_pending = vsi->rx_rings[0]->count;
1440 ring->tx_pending = vsi->tx_rings[0]->count;
1441 ring->rx_mini_pending = 0;
1442 ring->rx_jumbo_pending = 0;
1445 static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1447 if (i40e_enabled_xdp_vsi(vsi)) {
1448 return index < vsi->num_queue_pairs ||
1449 (index >= vsi->alloc_queue_pairs &&
1450 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1453 return index < vsi->num_queue_pairs;
1456 static int i40e_set_ringparam(struct net_device *netdev,
1457 struct ethtool_ringparam *ring)
1459 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1460 struct i40e_netdev_priv *np = netdev_priv(netdev);
1461 struct i40e_hw *hw = &np->vsi->back->hw;
1462 struct i40e_vsi *vsi = np->vsi;
1463 struct i40e_pf *pf = vsi->back;
1464 u32 new_rx_count, new_tx_count;
1465 u16 tx_alloc_queue_pairs;
1469 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1472 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1473 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1474 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1475 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1477 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1478 ring->tx_pending, ring->rx_pending,
1479 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1483 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1484 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1486 /* if nothing to do return success */
1487 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1488 (new_rx_count == vsi->rx_rings[0]->count))
1491 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
1495 usleep_range(1000, 2000);
1498 if (!netif_running(vsi->netdev)) {
1499 /* simple case - set for the next time the netdev is started */
1500 for (i = 0; i < vsi->num_queue_pairs; i++) {
1501 vsi->tx_rings[i]->count = new_tx_count;
1502 vsi->rx_rings[i]->count = new_rx_count;
1503 if (i40e_enabled_xdp_vsi(vsi))
1504 vsi->xdp_rings[i]->count = new_tx_count;
1509 /* We can't just free everything and then setup again,
1510 * because the ISRs in MSI-X mode get passed pointers
1511 * to the Tx and Rx ring structs.
1514 /* alloc updated Tx and XDP Tx resources */
1515 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1516 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
1517 if (new_tx_count != vsi->tx_rings[0]->count) {
1519 "Changing Tx descriptor count from %d to %d.\n",
1520 vsi->tx_rings[0]->count, new_tx_count);
1521 tx_rings = kcalloc(tx_alloc_queue_pairs,
1522 sizeof(struct i40e_ring), GFP_KERNEL);
1528 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1529 if (!i40e_active_tx_ring_index(vsi, i))
1532 tx_rings[i] = *vsi->tx_rings[i];
1533 tx_rings[i].count = new_tx_count;
1534 /* the desc and bi pointers will be reallocated in the
1537 tx_rings[i].desc = NULL;
1538 tx_rings[i].rx_bi = NULL;
1539 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1543 if (!i40e_active_tx_ring_index(vsi, i))
1545 i40e_free_tx_resources(&tx_rings[i]);
1555 /* alloc updated Rx resources */
1556 if (new_rx_count != vsi->rx_rings[0]->count) {
1558 "Changing Rx descriptor count from %d to %d\n",
1559 vsi->rx_rings[0]->count, new_rx_count);
1560 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1561 sizeof(struct i40e_ring), GFP_KERNEL);
1567 for (i = 0; i < vsi->num_queue_pairs; i++) {
1568 struct i40e_ring *ring;
1571 /* clone ring and setup updated count */
1572 rx_rings[i] = *vsi->rx_rings[i];
1573 rx_rings[i].count = new_rx_count;
1574 /* the desc and bi pointers will be reallocated in the
1577 rx_rings[i].desc = NULL;
1578 rx_rings[i].rx_bi = NULL;
1579 /* Clear cloned XDP RX-queue info before setup call */
1580 memset(&rx_rings[i].xdp_rxq, 0, sizeof(rx_rings[i].xdp_rxq));
1581 /* this is to allow wr32 to have something to write to
1582 * during early allocation of Rx buffers
1584 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
1585 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1589 /* now allocate the Rx buffers to make sure the OS
1590 * has enough memory, any failure here means abort
1592 ring = &rx_rings[i];
1593 unused = I40E_DESC_UNUSED(ring);
1594 err = i40e_alloc_rx_buffers(ring, unused);
1598 i40e_free_rx_resources(&rx_rings[i]);
1608 /* Bring interface down, copy in the new ring info,
1609 * then restore the interface
1614 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1615 if (i40e_active_tx_ring_index(vsi, i)) {
1616 i40e_free_tx_resources(vsi->tx_rings[i]);
1617 *vsi->tx_rings[i] = tx_rings[i];
1625 for (i = 0; i < vsi->num_queue_pairs; i++) {
1626 i40e_free_rx_resources(vsi->rx_rings[i]);
1627 /* get the real tail offset */
1628 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1629 /* this is to fake out the allocation routine
1630 * into thinking it has to realloc everything
1631 * but the recycling logic will let us re-use
1632 * the buffers allocated above
1634 rx_rings[i].next_to_use = 0;
1635 rx_rings[i].next_to_clean = 0;
1636 rx_rings[i].next_to_alloc = 0;
1637 /* do a struct copy */
1638 *vsi->rx_rings[i] = rx_rings[i];
1647 /* error cleanup if the Rx allocations failed after getting Tx */
1649 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1650 if (i40e_active_tx_ring_index(vsi, i))
1651 i40e_free_tx_resources(vsi->tx_rings[i]);
1658 clear_bit(__I40E_CONFIG_BUSY, pf->state);
1664 * i40e_get_stats_count - return the stats count for a device
1665 * @netdev: the netdev to return the count for
1667 * Returns the total number of statistics for this netdev. Note that even
1668 * though this is a function, it is required that the count for a specific
1669 * netdev must never change. Basing the count on static values such as the
1670 * maximum number of queues or the device type is ok. However, the API for
1671 * obtaining stats is *not* safe against changes based on non-static
1672 * values such as the *current* number of queues, or runtime flags.
1674 * If a statistic is not always enabled, return it as part of the count
1675 * anyways, always return its string, and report its value as zero.
1677 static int i40e_get_stats_count(struct net_device *netdev)
1679 struct i40e_netdev_priv *np = netdev_priv(netdev);
1680 struct i40e_vsi *vsi = np->vsi;
1681 struct i40e_pf *pf = vsi->back;
1683 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1)
1684 return I40E_PF_STATS_LEN(netdev) + I40E_VEB_STATS_TOTAL;
1686 return I40E_VSI_STATS_LEN(netdev);
1689 static int i40e_get_sset_count(struct net_device *netdev, int sset)
1691 struct i40e_netdev_priv *np = netdev_priv(netdev);
1692 struct i40e_vsi *vsi = np->vsi;
1693 struct i40e_pf *pf = vsi->back;
1697 return I40E_TEST_LEN;
1699 return i40e_get_stats_count(netdev);
1700 case ETH_SS_PRIV_FLAGS:
1701 return I40E_PRIV_FLAGS_STR_LEN +
1702 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
1709 * i40e_get_ethtool_stats - copy stat values into supplied buffer
1710 * @netdev: the netdev to collect stats for
1711 * @stats: ethtool stats command structure
1712 * @data: ethtool supplied buffer
1714 * Copy the stats values for this netdev into the buffer. Expects data to be
1715 * pre-allocated to the size returned by i40e_get_stats_count.. Note that all
1716 * statistics must be copied in a static order, and the count must not change
1717 * for a given netdev. See i40e_get_stats_count for more details.
1719 * If a statistic is not currently valid (such as a disabled queue), this
1720 * function reports its value as zero.
1722 static void i40e_get_ethtool_stats(struct net_device *netdev,
1723 struct ethtool_stats *stats, u64 *data)
1725 struct i40e_netdev_priv *np = netdev_priv(netdev);
1726 struct i40e_ring *tx_ring, *rx_ring;
1727 struct i40e_vsi *vsi = np->vsi;
1728 struct i40e_pf *pf = vsi->back;
1731 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
1734 i40e_update_stats(vsi);
1736 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1737 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1738 *(data++) = (i40e_gstrings_net_stats[j].sizeof_stat ==
1739 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1741 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1742 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1743 *(data++) = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1744 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1747 for (j = 0; j < I40E_MAX_NUM_QUEUES(netdev) ; j++) {
1748 tx_ring = READ_ONCE(vsi->tx_rings[j]);
1751 /* Bump the stat counter to skip these stats, and make
1752 * sure the memory is zero'd
1761 /* process Tx ring statistics */
1763 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
1764 data[0] = tx_ring->stats.packets;
1765 data[1] = tx_ring->stats.bytes;
1766 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
1769 /* Rx ring is the 2nd half of the queue pair */
1770 rx_ring = &tx_ring[1];
1772 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
1773 data[0] = rx_ring->stats.packets;
1774 data[1] = rx_ring->stats.bytes;
1775 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
1779 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1782 if ((pf->lan_veb != I40E_NO_VEB) &&
1783 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
1784 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1786 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1788 p += i40e_gstrings_veb_stats[j].stat_offset;
1789 *(data++) = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1790 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1792 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1793 *(data++) = veb->tc_stats.tc_tx_packets[j];
1794 *(data++) = veb->tc_stats.tc_tx_bytes[j];
1795 *(data++) = veb->tc_stats.tc_rx_packets[j];
1796 *(data++) = veb->tc_stats.tc_rx_bytes[j];
1799 data += I40E_VEB_STATS_TOTAL;
1801 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1802 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1803 *(data++) = (i40e_gstrings_stats[j].sizeof_stat ==
1804 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1806 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1807 *(data++) = pf->stats.priority_xon_tx[j];
1808 *(data++) = pf->stats.priority_xoff_tx[j];
1810 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1811 *(data++) = pf->stats.priority_xon_rx[j];
1812 *(data++) = pf->stats.priority_xoff_rx[j];
1814 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1815 *(data++) = pf->stats.priority_xon_2_xoff[j];
1819 * i40e_get_stat_strings - copy stat strings into supplied buffer
1820 * @netdev: the netdev to collect strings for
1821 * @data: supplied buffer to copy strings into
1823 * Copy the strings related to stats for this netdev. Expects data to be
1824 * pre-allocated with the size reported by i40e_get_stats_count. Note that the
1825 * strings must be copied in a static order and the total count must not
1826 * change for a given netdev. See i40e_get_stats_count for more details.
1828 static void i40e_get_stat_strings(struct net_device *netdev, u8 *data)
1830 struct i40e_netdev_priv *np = netdev_priv(netdev);
1831 struct i40e_vsi *vsi = np->vsi;
1832 struct i40e_pf *pf = vsi->back;
1836 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1837 snprintf(data, ETH_GSTRING_LEN, "%s",
1838 i40e_gstrings_net_stats[i].stat_string);
1839 data += ETH_GSTRING_LEN;
1841 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1842 snprintf(data, ETH_GSTRING_LEN, "%s",
1843 i40e_gstrings_misc_stats[i].stat_string);
1844 data += ETH_GSTRING_LEN;
1846 for (i = 0; i < I40E_MAX_NUM_QUEUES(netdev); i++) {
1847 snprintf(data, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1848 data += ETH_GSTRING_LEN;
1849 snprintf(data, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1850 data += ETH_GSTRING_LEN;
1851 snprintf(data, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1852 data += ETH_GSTRING_LEN;
1853 snprintf(data, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1854 data += ETH_GSTRING_LEN;
1856 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1859 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1860 snprintf(data, ETH_GSTRING_LEN, "%s",
1861 i40e_gstrings_veb_stats[i].stat_string);
1862 data += ETH_GSTRING_LEN;
1864 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1865 snprintf(data, ETH_GSTRING_LEN,
1866 "veb.tc_%u_tx_packets", i);
1867 data += ETH_GSTRING_LEN;
1868 snprintf(data, ETH_GSTRING_LEN,
1869 "veb.tc_%u_tx_bytes", i);
1870 data += ETH_GSTRING_LEN;
1871 snprintf(data, ETH_GSTRING_LEN,
1872 "veb.tc_%u_rx_packets", i);
1873 data += ETH_GSTRING_LEN;
1874 snprintf(data, ETH_GSTRING_LEN,
1875 "veb.tc_%u_rx_bytes", i);
1876 data += ETH_GSTRING_LEN;
1879 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1880 snprintf(data, ETH_GSTRING_LEN, "%s",
1881 i40e_gstrings_stats[i].stat_string);
1882 data += ETH_GSTRING_LEN;
1884 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1885 snprintf(data, ETH_GSTRING_LEN,
1886 "port.tx_priority_%u_xon", i);
1887 data += ETH_GSTRING_LEN;
1888 snprintf(data, ETH_GSTRING_LEN,
1889 "port.tx_priority_%u_xoff", i);
1890 data += ETH_GSTRING_LEN;
1892 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1893 snprintf(data, ETH_GSTRING_LEN,
1894 "port.rx_priority_%u_xon", i);
1895 data += ETH_GSTRING_LEN;
1896 snprintf(data, ETH_GSTRING_LEN,
1897 "port.rx_priority_%u_xoff", i);
1898 data += ETH_GSTRING_LEN;
1900 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1901 snprintf(data, ETH_GSTRING_LEN,
1902 "port.rx_priority_%u_xon_2_xoff", i);
1903 data += ETH_GSTRING_LEN;
1906 WARN_ONCE(p - data != i40e_get_stats_count(netdev) * ETH_GSTRING_LEN,
1907 "stat strings count mismatch!");
1910 static void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data)
1912 struct i40e_netdev_priv *np = netdev_priv(netdev);
1913 struct i40e_vsi *vsi = np->vsi;
1914 struct i40e_pf *pf = vsi->back;
1915 char *p = (char *)data;
1918 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1919 snprintf(p, ETH_GSTRING_LEN, "%s",
1920 i40e_gstrings_priv_flags[i].flag_string);
1921 p += ETH_GSTRING_LEN;
1923 if (pf->hw.pf_id != 0)
1925 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1926 snprintf(p, ETH_GSTRING_LEN, "%s",
1927 i40e_gl_gstrings_priv_flags[i].flag_string);
1928 p += ETH_GSTRING_LEN;
1932 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1935 switch (stringset) {
1937 memcpy(data, i40e_gstrings_test,
1938 I40E_TEST_LEN * ETH_GSTRING_LEN);
1941 i40e_get_stat_strings(netdev, data);
1943 case ETH_SS_PRIV_FLAGS:
1944 i40e_get_priv_flag_strings(netdev, data);
1951 static int i40e_get_ts_info(struct net_device *dev,
1952 struct ethtool_ts_info *info)
1954 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1956 /* only report HW timestamping if PTP is enabled */
1957 if (!(pf->flags & I40E_FLAG_PTP))
1958 return ethtool_op_get_ts_info(dev, info);
1960 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1961 SOF_TIMESTAMPING_RX_SOFTWARE |
1962 SOF_TIMESTAMPING_SOFTWARE |
1963 SOF_TIMESTAMPING_TX_HARDWARE |
1964 SOF_TIMESTAMPING_RX_HARDWARE |
1965 SOF_TIMESTAMPING_RAW_HARDWARE;
1968 info->phc_index = ptp_clock_index(pf->ptp_clock);
1970 info->phc_index = -1;
1972 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
1974 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1975 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1976 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1977 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1979 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
1980 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1981 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1982 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1983 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1984 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1985 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1986 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1987 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1992 static int i40e_link_test(struct net_device *netdev, u64 *data)
1994 struct i40e_netdev_priv *np = netdev_priv(netdev);
1995 struct i40e_pf *pf = np->vsi->back;
1997 bool link_up = false;
1999 netif_info(pf, hw, netdev, "link test\n");
2000 status = i40e_get_link_status(&pf->hw, &link_up);
2002 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
2015 static int i40e_reg_test(struct net_device *netdev, u64 *data)
2017 struct i40e_netdev_priv *np = netdev_priv(netdev);
2018 struct i40e_pf *pf = np->vsi->back;
2020 netif_info(pf, hw, netdev, "register test\n");
2021 *data = i40e_diag_reg_test(&pf->hw);
2026 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
2028 struct i40e_netdev_priv *np = netdev_priv(netdev);
2029 struct i40e_pf *pf = np->vsi->back;
2031 netif_info(pf, hw, netdev, "eeprom test\n");
2032 *data = i40e_diag_eeprom_test(&pf->hw);
2034 /* forcebly clear the NVM Update state machine */
2035 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
2040 static int i40e_intr_test(struct net_device *netdev, u64 *data)
2042 struct i40e_netdev_priv *np = netdev_priv(netdev);
2043 struct i40e_pf *pf = np->vsi->back;
2044 u16 swc_old = pf->sw_int_count;
2046 netif_info(pf, hw, netdev, "interrupt test\n");
2047 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
2048 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
2049 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
2050 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
2051 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
2052 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
2053 usleep_range(1000, 2000);
2054 *data = (swc_old == pf->sw_int_count);
2059 static inline bool i40e_active_vfs(struct i40e_pf *pf)
2061 struct i40e_vf *vfs = pf->vf;
2064 for (i = 0; i < pf->num_alloc_vfs; i++)
2065 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
2070 static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
2072 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
2075 static void i40e_diag_test(struct net_device *netdev,
2076 struct ethtool_test *eth_test, u64 *data)
2078 struct i40e_netdev_priv *np = netdev_priv(netdev);
2079 bool if_running = netif_running(netdev);
2080 struct i40e_pf *pf = np->vsi->back;
2082 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2084 netif_info(pf, drv, netdev, "offline testing starting\n");
2086 set_bit(__I40E_TESTING, pf->state);
2088 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
2089 dev_warn(&pf->pdev->dev,
2090 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
2091 data[I40E_ETH_TEST_REG] = 1;
2092 data[I40E_ETH_TEST_EEPROM] = 1;
2093 data[I40E_ETH_TEST_INTR] = 1;
2094 data[I40E_ETH_TEST_LINK] = 1;
2095 eth_test->flags |= ETH_TEST_FL_FAILED;
2096 clear_bit(__I40E_TESTING, pf->state);
2100 /* If the device is online then take it offline */
2102 /* indicate we're in test mode */
2105 /* This reset does not affect link - if it is
2106 * changed to a type of reset that does affect
2107 * link then the following link test would have
2108 * to be moved to before the reset
2110 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
2112 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
2113 eth_test->flags |= ETH_TEST_FL_FAILED;
2115 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
2116 eth_test->flags |= ETH_TEST_FL_FAILED;
2118 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
2119 eth_test->flags |= ETH_TEST_FL_FAILED;
2121 /* run reg test last, a reset is required after it */
2122 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
2123 eth_test->flags |= ETH_TEST_FL_FAILED;
2125 clear_bit(__I40E_TESTING, pf->state);
2126 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
2132 netif_info(pf, drv, netdev, "online testing starting\n");
2134 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
2135 eth_test->flags |= ETH_TEST_FL_FAILED;
2137 /* Offline only tests, not run in online; pass by default */
2138 data[I40E_ETH_TEST_REG] = 0;
2139 data[I40E_ETH_TEST_EEPROM] = 0;
2140 data[I40E_ETH_TEST_INTR] = 0;
2145 netif_info(pf, drv, netdev, "testing finished\n");
2148 static void i40e_get_wol(struct net_device *netdev,
2149 struct ethtool_wolinfo *wol)
2151 struct i40e_netdev_priv *np = netdev_priv(netdev);
2152 struct i40e_pf *pf = np->vsi->back;
2153 struct i40e_hw *hw = &pf->hw;
2156 /* NVM bit on means WoL disabled for the port */
2157 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
2158 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
2162 wol->supported = WAKE_MAGIC;
2163 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2168 * i40e_set_wol - set the WakeOnLAN configuration
2169 * @netdev: the netdev in question
2170 * @wol: the ethtool WoL setting data
2172 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2174 struct i40e_netdev_priv *np = netdev_priv(netdev);
2175 struct i40e_pf *pf = np->vsi->back;
2176 struct i40e_vsi *vsi = np->vsi;
2177 struct i40e_hw *hw = &pf->hw;
2180 /* WoL not supported if this isn't the controlling PF on the port */
2181 if (hw->partition_id != 1) {
2182 i40e_partition_setting_complaint(pf);
2186 if (vsi != pf->vsi[pf->lan_vsi])
2189 /* NVM bit on means WoL disabled for the port */
2190 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
2191 if (BIT(hw->port) & wol_nvm_bits)
2194 /* only magic packet is supported */
2195 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
2198 /* is this a new value? */
2199 if (pf->wol_en != !!wol->wolopts) {
2200 pf->wol_en = !!wol->wolopts;
2201 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2207 static int i40e_set_phys_id(struct net_device *netdev,
2208 enum ethtool_phys_id_state state)
2210 struct i40e_netdev_priv *np = netdev_priv(netdev);
2211 i40e_status ret = 0;
2212 struct i40e_pf *pf = np->vsi->back;
2213 struct i40e_hw *hw = &pf->hw;
2218 case ETHTOOL_ID_ACTIVE:
2219 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
2220 pf->led_status = i40e_led_get(hw);
2222 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2223 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2225 ret = i40e_led_get_phy(hw, &temp_status,
2227 pf->led_status = temp_status;
2231 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
2232 i40e_led_set(hw, 0xf, false);
2234 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
2236 case ETHTOOL_ID_OFF:
2237 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
2238 i40e_led_set(hw, 0x0, false);
2240 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
2242 case ETHTOOL_ID_INACTIVE:
2243 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
2244 i40e_led_set(hw, pf->led_status, false);
2246 ret = i40e_led_set_phy(hw, false, pf->led_status,
2248 I40E_PHY_LED_MODE_ORIG));
2249 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2250 i40e_aq_set_phy_debug(hw, 0, NULL);
2262 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2263 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2264 * 125us (8000 interrupts per second) == ITR(62)
2268 * __i40e_get_coalesce - get per-queue coalesce settings
2269 * @netdev: the netdev to check
2270 * @ec: ethtool coalesce data structure
2271 * @queue: which queue to pick
2273 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2274 * are per queue. If queue is <0 then we default to queue 0 as the
2275 * representative value.
2277 static int __i40e_get_coalesce(struct net_device *netdev,
2278 struct ethtool_coalesce *ec,
2281 struct i40e_netdev_priv *np = netdev_priv(netdev);
2282 struct i40e_ring *rx_ring, *tx_ring;
2283 struct i40e_vsi *vsi = np->vsi;
2285 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2286 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2288 /* rx and tx usecs has per queue value. If user doesn't specify the
2289 * queue, return queue 0's value to represent.
2293 else if (queue >= vsi->num_queue_pairs)
2296 rx_ring = vsi->rx_rings[queue];
2297 tx_ring = vsi->tx_rings[queue];
2299 if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
2300 ec->use_adaptive_rx_coalesce = 1;
2302 if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
2303 ec->use_adaptive_tx_coalesce = 1;
2305 ec->rx_coalesce_usecs = rx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
2306 ec->tx_coalesce_usecs = tx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
2308 /* we use the _usecs_high to store/set the interrupt rate limit
2309 * that the hardware supports, that almost but not quite
2310 * fits the original intent of the ethtool variable,
2311 * the rx_coalesce_usecs_high limits total interrupts
2312 * per second from both tx/rx sources.
2314 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2315 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
2321 * i40e_get_coalesce - get a netdev's coalesce settings
2322 * @netdev: the netdev to check
2323 * @ec: ethtool coalesce data structure
2325 * Gets the coalesce settings for a particular netdev. Note that if user has
2326 * modified per-queue settings, this only guarantees to represent queue 0. See
2327 * __i40e_get_coalesce for more details.
2329 static int i40e_get_coalesce(struct net_device *netdev,
2330 struct ethtool_coalesce *ec)
2332 return __i40e_get_coalesce(netdev, ec, -1);
2336 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2337 * @netdev: netdev structure
2338 * @ec: ethtool's coalesce settings
2339 * @queue: the particular queue to read
2341 * Will read a specific queue's coalesce settings
2343 static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2344 struct ethtool_coalesce *ec)
2346 return __i40e_get_coalesce(netdev, ec, queue);
2350 * i40e_set_itr_per_queue - set ITR values for specific queue
2351 * @vsi: the VSI to set values for
2352 * @ec: coalesce settings from ethtool
2353 * @queue: the queue to modify
2355 * Change the ITR settings for a specific queue.
2357 static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2358 struct ethtool_coalesce *ec,
2361 struct i40e_ring *rx_ring = vsi->rx_rings[queue];
2362 struct i40e_ring *tx_ring = vsi->tx_rings[queue];
2363 struct i40e_pf *pf = vsi->back;
2364 struct i40e_hw *hw = &pf->hw;
2365 struct i40e_q_vector *q_vector;
2368 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
2370 rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
2371 tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
2373 if (ec->use_adaptive_rx_coalesce)
2374 rx_ring->itr_setting |= I40E_ITR_DYNAMIC;
2376 rx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
2378 if (ec->use_adaptive_tx_coalesce)
2379 tx_ring->itr_setting |= I40E_ITR_DYNAMIC;
2381 tx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
2383 q_vector = rx_ring->q_vector;
2384 q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
2386 q_vector = tx_ring->q_vector;
2387 q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
2389 /* The interrupt handler itself will take care of programming
2390 * the Tx and Rx ITR values based on the values we have entered
2391 * into the q_vector, no need to write the values now.
2394 wr32(hw, I40E_PFINT_RATEN(q_vector->reg_idx), intrl);
2399 * __i40e_set_coalesce - set coalesce settings for particular queue
2400 * @netdev: the netdev to change
2401 * @ec: ethtool coalesce settings
2402 * @queue: the queue to change
2404 * Sets the coalesce settings for a particular queue.
2406 static int __i40e_set_coalesce(struct net_device *netdev,
2407 struct ethtool_coalesce *ec,
2410 struct i40e_netdev_priv *np = netdev_priv(netdev);
2411 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
2412 struct i40e_vsi *vsi = np->vsi;
2413 struct i40e_pf *pf = vsi->back;
2416 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2417 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2420 cur_rx_itr = vsi->rx_rings[0]->itr_setting;
2421 cur_tx_itr = vsi->tx_rings[0]->itr_setting;
2422 } else if (queue < vsi->num_queue_pairs) {
2423 cur_rx_itr = vsi->rx_rings[queue]->itr_setting;
2424 cur_tx_itr = vsi->tx_rings[queue]->itr_setting;
2426 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2427 vsi->num_queue_pairs - 1);
2431 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2432 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2434 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2435 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2436 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2440 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2441 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2442 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
2446 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2447 ec->use_adaptive_rx_coalesce) {
2448 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2452 if (ec->rx_coalesce_usecs > I40E_MAX_ITR) {
2453 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2457 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2458 ec->use_adaptive_tx_coalesce) {
2459 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2463 if (ec->tx_coalesce_usecs > I40E_MAX_ITR) {
2464 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2468 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
2469 ec->rx_coalesce_usecs = I40E_MIN_ITR;
2471 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
2472 ec->tx_coalesce_usecs = I40E_MIN_ITR;
2474 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2475 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2476 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2477 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2478 vsi->int_rate_limit);
2481 /* rx and tx usecs has per queue value. If user doesn't specify the
2482 * queue, apply to all queues.
2485 for (i = 0; i < vsi->num_queue_pairs; i++)
2486 i40e_set_itr_per_queue(vsi, ec, i);
2488 i40e_set_itr_per_queue(vsi, ec, queue);
2495 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2496 * @netdev: the netdev to change
2497 * @ec: ethtool coalesce settings
2499 * This will set each queue to the same coalesce settings.
2501 static int i40e_set_coalesce(struct net_device *netdev,
2502 struct ethtool_coalesce *ec)
2504 return __i40e_set_coalesce(netdev, ec, -1);
2508 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2509 * @netdev: the netdev to change
2510 * @ec: ethtool's coalesce settings
2511 * @queue: the queue to change
2513 * Sets the specified queue's coalesce settings.
2515 static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2516 struct ethtool_coalesce *ec)
2518 return __i40e_set_coalesce(netdev, ec, queue);
2522 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2523 * @pf: pointer to the physical function struct
2524 * @cmd: ethtool rxnfc command
2526 * Returns Success if the flow is supported, else Invalid Input.
2528 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2530 struct i40e_hw *hw = &pf->hw;
2536 switch (cmd->flow_type) {
2538 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2541 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2544 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2547 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2550 case AH_ESP_V4_FLOW:
2555 case AH_ESP_V6_FLOW:
2559 /* Default is src/dest for IP, no matter the L4 hashing */
2560 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2566 /* Read flow based hash input set register */
2568 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2570 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2571 flow_pctype)) << 32);
2574 /* Process bits of hash input set */
2576 if (i_set & I40E_L4_SRC_MASK)
2577 cmd->data |= RXH_L4_B_0_1;
2578 if (i_set & I40E_L4_DST_MASK)
2579 cmd->data |= RXH_L4_B_2_3;
2581 if (cmd->flow_type == TCP_V4_FLOW ||
2582 cmd->flow_type == UDP_V4_FLOW) {
2583 if (i_set & I40E_L3_SRC_MASK)
2584 cmd->data |= RXH_IP_SRC;
2585 if (i_set & I40E_L3_DST_MASK)
2586 cmd->data |= RXH_IP_DST;
2587 } else if (cmd->flow_type == TCP_V6_FLOW ||
2588 cmd->flow_type == UDP_V6_FLOW) {
2589 if (i_set & I40E_L3_V6_SRC_MASK)
2590 cmd->data |= RXH_IP_SRC;
2591 if (i_set & I40E_L3_V6_DST_MASK)
2592 cmd->data |= RXH_IP_DST;
2600 * i40e_check_mask - Check whether a mask field is set
2601 * @mask: the full mask value
2602 * @field: mask of the field to check
2604 * If the given mask is fully set, return positive value. If the mask for the
2605 * field is fully unset, return zero. Otherwise return a negative error code.
2607 static int i40e_check_mask(u64 mask, u64 field)
2609 u64 value = mask & field;
2620 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2621 * @fsp: pointer to rx flow specification
2622 * @data: pointer to userdef data structure for storage
2624 * Read the user-defined data and deconstruct the value into a structure. No
2625 * other code should read the user-defined data, so as to ensure that every
2626 * place consistently reads the value correctly.
2628 * The user-defined field is a 64bit Big Endian format value, which we
2629 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2630 * be defined starting from the highest bits, while small bit field values
2631 * shall be defined starting from the lowest bits.
2633 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2634 * and the filter should be rejected. The data structure will always be
2635 * modified even if FLOW_EXT is not set.
2638 static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2639 struct i40e_rx_flow_userdef *data)
2644 /* Zero memory first so it's always consistent. */
2645 memset(data, 0, sizeof(*data));
2647 if (!(fsp->flow_type & FLOW_EXT))
2650 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2651 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2653 #define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2654 #define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2655 #define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2657 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2661 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2663 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2664 data->flex_filter = true;
2671 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2672 * @fsp: pointer to rx_flow specification
2673 * @data: pointer to return userdef data
2675 * Reads the userdef data structure and properly fills in the user defined
2676 * fields of the rx_flow_spec.
2678 static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2679 struct i40e_rx_flow_userdef *data)
2681 u64 value = 0, mask = 0;
2683 if (data->flex_filter) {
2684 value |= data->flex_word;
2685 value |= (u64)data->flex_offset << 16;
2686 mask |= I40E_USERDEF_FLEX_FILTER;
2690 fsp->flow_type |= FLOW_EXT;
2692 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2693 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2697 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2698 * @pf: Pointer to the physical function struct
2699 * @cmd: The command to get or set Rx flow classification rules
2700 * @rule_locs: Array of used rule locations
2702 * This function populates both the total and actual rule count of
2703 * the ethtool flow classification command
2705 * Returns 0 on success or -EMSGSIZE if entry not found
2707 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2708 struct ethtool_rxnfc *cmd,
2711 struct i40e_fdir_filter *rule;
2712 struct hlist_node *node2;
2715 /* report total rule count */
2716 cmd->data = i40e_get_fd_cnt_all(pf);
2718 hlist_for_each_entry_safe(rule, node2,
2719 &pf->fdir_filter_list, fdir_node) {
2720 if (cnt == cmd->rule_cnt)
2723 rule_locs[cnt] = rule->fd_id;
2727 cmd->rule_cnt = cnt;
2733 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2734 * @pf: Pointer to the physical function struct
2735 * @cmd: The command to get or set Rx flow classification rules
2737 * This function looks up a filter based on the Rx flow classification
2738 * command and fills the flow spec info for it if found
2740 * Returns 0 on success or -EINVAL if filter not found
2742 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2743 struct ethtool_rxnfc *cmd)
2745 struct ethtool_rx_flow_spec *fsp =
2746 (struct ethtool_rx_flow_spec *)&cmd->fs;
2747 struct i40e_rx_flow_userdef userdef = {0};
2748 struct i40e_fdir_filter *rule = NULL;
2749 struct hlist_node *node2;
2753 hlist_for_each_entry_safe(rule, node2,
2754 &pf->fdir_filter_list, fdir_node) {
2755 if (fsp->location <= rule->fd_id)
2759 if (!rule || fsp->location != rule->fd_id)
2762 fsp->flow_type = rule->flow_type;
2763 if (fsp->flow_type == IP_USER_FLOW) {
2764 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2765 fsp->h_u.usr_ip4_spec.proto = 0;
2766 fsp->m_u.usr_ip4_spec.proto = 0;
2769 /* Reverse the src and dest notion, since the HW views them from
2770 * Tx perspective where as the user expects it from Rx filter view.
2772 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2773 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2774 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2775 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
2777 switch (rule->flow_type) {
2779 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2782 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2785 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2788 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2791 /* If we have stored a filter with a flow type not listed here
2792 * it is almost certainly a driver bug. WARN(), and then
2793 * assign the input_set as if all fields are enabled to avoid
2794 * reading unassigned memory.
2796 WARN(1, "Missing input set index for flow_type %d\n",
2798 input_set = 0xFFFFFFFFFFFFFFFFULL;
2802 input_set = i40e_read_fd_input_set(pf, index);
2805 if (input_set & I40E_L3_SRC_MASK)
2806 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFFFFFF);
2808 if (input_set & I40E_L3_DST_MASK)
2809 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFFFFFF);
2811 if (input_set & I40E_L4_SRC_MASK)
2812 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFF);
2814 if (input_set & I40E_L4_DST_MASK)
2815 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFF);
2817 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2818 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2820 fsp->ring_cookie = rule->q_index;
2822 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2823 struct i40e_vsi *vsi;
2825 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2826 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2827 /* VFs are zero-indexed by the driver, but ethtool
2828 * expects them to be one-indexed, so add one here
2830 u64 ring_vf = vsi->vf_id + 1;
2832 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2833 fsp->ring_cookie |= ring_vf;
2837 if (rule->flex_filter) {
2838 userdef.flex_filter = true;
2839 userdef.flex_word = be16_to_cpu(rule->flex_word);
2840 userdef.flex_offset = rule->flex_offset;
2843 i40e_fill_rx_flow_user_data(fsp, &userdef);
2849 * i40e_get_rxnfc - command to get RX flow classification rules
2850 * @netdev: network interface device structure
2851 * @cmd: ethtool rxnfc command
2852 * @rule_locs: pointer to store rule data
2854 * Returns Success if the command is supported.
2856 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2859 struct i40e_netdev_priv *np = netdev_priv(netdev);
2860 struct i40e_vsi *vsi = np->vsi;
2861 struct i40e_pf *pf = vsi->back;
2862 int ret = -EOPNOTSUPP;
2865 case ETHTOOL_GRXRINGS:
2866 cmd->data = vsi->rss_size;
2870 ret = i40e_get_rss_hash_opts(pf, cmd);
2872 case ETHTOOL_GRXCLSRLCNT:
2873 cmd->rule_cnt = pf->fdir_pf_active_filters;
2874 /* report total rule count */
2875 cmd->data = i40e_get_fd_cnt_all(pf);
2878 case ETHTOOL_GRXCLSRULE:
2879 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
2881 case ETHTOOL_GRXCLSRLALL:
2882 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2892 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2893 * @nfc: pointer to user request
2894 * @i_setc: bits currently set
2896 * Returns value of bits to be set per user request
2898 static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2901 u64 src_l3 = 0, dst_l3 = 0;
2903 if (nfc->data & RXH_L4_B_0_1)
2904 i_set |= I40E_L4_SRC_MASK;
2906 i_set &= ~I40E_L4_SRC_MASK;
2907 if (nfc->data & RXH_L4_B_2_3)
2908 i_set |= I40E_L4_DST_MASK;
2910 i_set &= ~I40E_L4_DST_MASK;
2912 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2913 src_l3 = I40E_L3_V6_SRC_MASK;
2914 dst_l3 = I40E_L3_V6_DST_MASK;
2915 } else if (nfc->flow_type == TCP_V4_FLOW ||
2916 nfc->flow_type == UDP_V4_FLOW) {
2917 src_l3 = I40E_L3_SRC_MASK;
2918 dst_l3 = I40E_L3_DST_MASK;
2920 /* Any other flow type are not supported here */
2924 if (nfc->data & RXH_IP_SRC)
2928 if (nfc->data & RXH_IP_DST)
2937 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2938 * @pf: pointer to the physical function struct
2939 * @nfc: ethtool rxnfc command
2941 * Returns Success if the flow input set is supported.
2943 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2945 struct i40e_hw *hw = &pf->hw;
2946 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2947 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
2951 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2952 dev_err(&pf->pdev->dev,
2953 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2957 /* RSS does not support anything other than hashing
2958 * to queues on src and dst IPs and ports
2960 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2961 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2964 switch (nfc->flow_type) {
2966 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2967 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2969 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2972 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2973 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2975 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2976 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2978 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2981 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2982 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2984 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2985 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2987 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
2990 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2991 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2993 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2994 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2996 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
2998 case AH_ESP_V4_FLOW:
3002 if ((nfc->data & RXH_L4_B_0_1) ||
3003 (nfc->data & RXH_L4_B_2_3))
3005 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
3007 case AH_ESP_V6_FLOW:
3011 if ((nfc->data & RXH_L4_B_0_1) ||
3012 (nfc->data & RXH_L4_B_2_3))
3014 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
3017 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
3018 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
3021 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
3022 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
3029 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
3031 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
3032 flow_pctype)) << 32);
3033 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
3034 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
3036 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
3037 (u32)(i_set >> 32));
3038 hena |= BIT_ULL(flow_pctype);
3041 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
3042 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
3049 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
3050 * @vsi: Pointer to the targeted VSI
3051 * @input: The filter to update or NULL to indicate deletion
3052 * @sw_idx: Software index to the filter
3053 * @cmd: The command to get or set Rx flow classification rules
3055 * This function updates (or deletes) a Flow Director entry from
3056 * the hlist of the corresponding PF
3058 * Returns 0 on success
3060 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
3061 struct i40e_fdir_filter *input,
3063 struct ethtool_rxnfc *cmd)
3065 struct i40e_fdir_filter *rule, *parent;
3066 struct i40e_pf *pf = vsi->back;
3067 struct hlist_node *node2;
3073 hlist_for_each_entry_safe(rule, node2,
3074 &pf->fdir_filter_list, fdir_node) {
3075 /* hash found, or no matching entry */
3076 if (rule->fd_id >= sw_idx)
3081 /* if there is an old rule occupying our place remove it */
3082 if (rule && (rule->fd_id == sw_idx)) {
3083 /* Remove this rule, since we're either deleting it, or
3086 err = i40e_add_del_fdir(vsi, rule, false);
3087 hlist_del(&rule->fdir_node);
3089 pf->fdir_pf_active_filters--;
3092 /* If we weren't given an input, this is a delete, so just return the
3093 * error code indicating if there was an entry at the requested slot
3098 /* Otherwise, install the new rule as requested */
3099 INIT_HLIST_NODE(&input->fdir_node);
3101 /* add filter to the list */
3103 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
3105 hlist_add_head(&input->fdir_node,
3106 &pf->fdir_filter_list);
3109 pf->fdir_pf_active_filters++;
3115 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
3116 * @pf: pointer to PF structure
3118 * This function searches the list of filters and determines which FLX_PIT
3119 * entries are still required. It will prune any entries which are no longer
3120 * in use after the deletion.
3122 static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
3124 struct i40e_flex_pit *entry, *tmp;
3125 struct i40e_fdir_filter *rule;
3127 /* First, we'll check the l3 table */
3128 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
3131 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3132 if (rule->flow_type != IP_USER_FLOW)
3134 if (rule->flex_filter &&
3135 rule->flex_offset == entry->src_offset) {
3141 /* If we didn't find the filter, then we can prune this entry
3145 list_del(&entry->list);
3150 /* Followed by the L4 table */
3151 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3154 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3155 /* Skip this filter if it's L3, since we already
3156 * checked those in the above loop
3158 if (rule->flow_type == IP_USER_FLOW)
3160 if (rule->flex_filter &&
3161 rule->flex_offset == entry->src_offset) {
3167 /* If we didn't find the filter, then we can prune this entry
3171 list_del(&entry->list);
3178 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3179 * @vsi: Pointer to the targeted VSI
3180 * @cmd: The command to get or set Rx flow classification rules
3182 * The function removes a Flow Director filter entry from the
3183 * hlist of the corresponding PF
3185 * Returns 0 on success
3187 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3188 struct ethtool_rxnfc *cmd)
3190 struct ethtool_rx_flow_spec *fsp =
3191 (struct ethtool_rx_flow_spec *)&cmd->fs;
3192 struct i40e_pf *pf = vsi->back;
3195 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3196 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
3199 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
3202 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
3204 i40e_prune_flex_pit_list(pf);
3206 i40e_fdir_check_and_reenable(pf);
3211 * i40e_unused_pit_index - Find an unused PIT index for given list
3212 * @pf: the PF data structure
3214 * Find the first unused flexible PIT index entry. We search both the L3 and
3215 * L4 flexible PIT lists so that the returned index is unique and unused by
3216 * either currently programmed L3 or L4 filters. We use a bit field as storage
3217 * to track which indexes are already used.
3219 static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3221 unsigned long available_index = 0xFF;
3222 struct i40e_flex_pit *entry;
3224 /* We need to make sure that the new index isn't in use by either L3
3225 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3226 * L4 to use the same index.
3229 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3230 clear_bit(entry->pit_index, &available_index);
3232 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3233 clear_bit(entry->pit_index, &available_index);
3235 return find_first_bit(&available_index, 8);
3239 * i40e_find_flex_offset - Find an existing flex src_offset
3240 * @flex_pit_list: L3 or L4 flex PIT list
3241 * @src_offset: new src_offset to find
3243 * Searches the flex_pit_list for an existing offset. If no offset is
3244 * currently programmed, then this will return an ERR_PTR if there is no space
3245 * to add a new offset, otherwise it returns NULL.
3248 struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3251 struct i40e_flex_pit *entry;
3254 /* Search for the src_offset first. If we find a matching entry
3255 * already programmed, we can simply re-use it.
3257 list_for_each_entry(entry, flex_pit_list, list) {
3259 if (entry->src_offset == src_offset)
3263 /* If we haven't found an entry yet, then the provided src offset has
3264 * not yet been programmed. We will program the src offset later on,
3265 * but we need to indicate whether there is enough space to do so
3266 * here. We'll make use of ERR_PTR for this purpose.
3268 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3269 return ERR_PTR(-ENOSPC);
3275 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3276 * @flex_pit_list: L3 or L4 flex PIT list
3277 * @src_offset: new src_offset to add
3278 * @pit_index: the PIT index to program
3280 * This function programs the new src_offset to the list. It is expected that
3281 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3282 * that this offset is not programmed, and that the list has enough space to
3283 * store another offset.
3285 * Returns 0 on success, and negative value on error.
3287 static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3291 struct i40e_flex_pit *new_pit, *entry;
3293 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3297 new_pit->src_offset = src_offset;
3298 new_pit->pit_index = pit_index;
3300 /* We need to insert this item such that the list is sorted by
3301 * src_offset in ascending order.
3303 list_for_each_entry(entry, flex_pit_list, list) {
3304 if (new_pit->src_offset < entry->src_offset) {
3305 list_add_tail(&new_pit->list, &entry->list);
3309 /* If we found an entry with our offset already programmed we
3310 * can simply return here, after freeing the memory. However,
3311 * if the pit_index does not match we need to report an error.
3313 if (new_pit->src_offset == entry->src_offset) {
3316 /* If the PIT index is not the same we can't re-use
3317 * the entry, so we must report an error.
3319 if (new_pit->pit_index != entry->pit_index)
3327 /* If we reached here, then we haven't yet added the item. This means
3328 * that we should add the item at the end of the list.
3330 list_add_tail(&new_pit->list, flex_pit_list);
3335 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3336 * @pf: Pointer to the PF structure
3337 * @flex_pit_list: list of flexible src offsets in use
3338 * @flex_pit_start: index to first entry for this section of the table
3340 * In order to handle flexible data, the hardware uses a table of values
3341 * called the FLX_PIT table. This table is used to indicate which sections of
3342 * the input correspond to what PIT index values. Unfortunately, hardware is
3343 * very restrictive about programming this table. Entries must be ordered by
3344 * src_offset in ascending order, without duplicates. Additionally, unused
3345 * entries must be set to the unused index value, and must have valid size and
3346 * length according to the src_offset ordering.
3348 * This function will reprogram the FLX_PIT register from a book-keeping
3349 * structure that we guarantee is already ordered correctly, and has no more
3352 * To make things easier, we only support flexible values of one word length,
3353 * rather than allowing variable length flexible values.
3355 static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3356 struct list_head *flex_pit_list,
3359 struct i40e_flex_pit *entry = NULL;
3360 u16 last_offset = 0;
3363 /* First, loop over the list of flex PIT entries, and reprogram the
3366 list_for_each_entry(entry, flex_pit_list, list) {
3367 /* We have to be careful when programming values for the
3368 * largest SRC_OFFSET value. It is possible that adding
3369 * additional empty values at the end would overflow the space
3370 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3371 * we check here and add the empty values prior to adding the
3374 * To determine this, we will use a loop from i+1 to 3, which
3375 * will determine whether the unused entries would have valid
3376 * SRC_OFFSET. Note that there cannot be extra entries past
3377 * this value, because the only valid values would have been
3378 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3379 * have been added to the list in the first place.
3381 for (j = i + 1; j < 3; j++) {
3382 u16 offset = entry->src_offset + j;
3383 int index = flex_pit_start + i;
3384 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3388 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3389 i40e_write_rx_ctl(&pf->hw,
3390 I40E_PRTQF_FLX_PIT(index),
3396 /* Now, we can program the actual value into the table */
3397 i40e_write_rx_ctl(&pf->hw,
3398 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3399 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3401 entry->src_offset));
3405 /* In order to program the last entries in the table, we need to
3406 * determine the valid offset. If the list is empty, we'll just start
3407 * with 0. Otherwise, we'll start with the last item offset and add 1.
3408 * This ensures that all entries have valid sizes. If we don't do this
3409 * correctly, the hardware will disable flexible field parsing.
3411 if (!list_empty(flex_pit_list))
3412 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3414 for (; i < 3; i++, last_offset++) {
3415 i40e_write_rx_ctl(&pf->hw,
3416 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3417 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3424 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3425 * @pf: pointer to the PF structure
3427 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3428 * internal helper function for implementation details.
3430 static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3432 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3433 I40E_FLEX_PIT_IDX_START_L3);
3435 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3436 I40E_FLEX_PIT_IDX_START_L4);
3438 /* We also need to program the L3 and L4 GLQF ORT register */
3439 i40e_write_rx_ctl(&pf->hw,
3440 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3441 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3444 i40e_write_rx_ctl(&pf->hw,
3445 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3446 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3451 * i40e_flow_str - Converts a flow_type into a human readable string
3452 * @fsp: the flow specification
3454 * Currently only flow types we support are included here, and the string
3455 * value attempts to match what ethtool would use to configure this flow type.
3457 static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3459 switch (fsp->flow_type & ~FLOW_EXT) {
3474 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3475 * @pit_index: PIT index to convert
3477 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3480 static u64 i40e_pit_index_to_mask(int pit_index)
3482 switch (pit_index) {
3484 return I40E_FLEX_50_MASK;
3486 return I40E_FLEX_51_MASK;
3488 return I40E_FLEX_52_MASK;
3490 return I40E_FLEX_53_MASK;
3492 return I40E_FLEX_54_MASK;
3494 return I40E_FLEX_55_MASK;
3496 return I40E_FLEX_56_MASK;
3498 return I40E_FLEX_57_MASK;
3505 * i40e_print_input_set - Show changes between two input sets
3506 * @vsi: the vsi being configured
3507 * @old: the old input set
3508 * @new: the new input set
3510 * Print the difference between old and new input sets by showing which series
3511 * of words are toggled on or off. Only displays the bits we actually support
3514 static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3516 struct i40e_pf *pf = vsi->back;
3517 bool old_value, new_value;
3520 old_value = !!(old & I40E_L3_SRC_MASK);
3521 new_value = !!(new & I40E_L3_SRC_MASK);
3522 if (old_value != new_value)
3523 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3524 old_value ? "ON" : "OFF",
3525 new_value ? "ON" : "OFF");
3527 old_value = !!(old & I40E_L3_DST_MASK);
3528 new_value = !!(new & I40E_L3_DST_MASK);
3529 if (old_value != new_value)
3530 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3531 old_value ? "ON" : "OFF",
3532 new_value ? "ON" : "OFF");
3534 old_value = !!(old & I40E_L4_SRC_MASK);
3535 new_value = !!(new & I40E_L4_SRC_MASK);
3536 if (old_value != new_value)
3537 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3538 old_value ? "ON" : "OFF",
3539 new_value ? "ON" : "OFF");
3541 old_value = !!(old & I40E_L4_DST_MASK);
3542 new_value = !!(new & I40E_L4_DST_MASK);
3543 if (old_value != new_value)
3544 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3545 old_value ? "ON" : "OFF",
3546 new_value ? "ON" : "OFF");
3548 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3549 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3550 if (old_value != new_value)
3551 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3552 old_value ? "ON" : "OFF",
3553 new_value ? "ON" : "OFF");
3555 /* Show change of flexible filter entries */
3556 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3557 u64 flex_mask = i40e_pit_index_to_mask(i);
3559 old_value = !!(old & flex_mask);
3560 new_value = !!(new & flex_mask);
3561 if (old_value != new_value)
3562 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3564 old_value ? "ON" : "OFF",
3565 new_value ? "ON" : "OFF");
3568 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3570 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3575 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
3576 * @vsi: pointer to the targeted VSI
3577 * @fsp: pointer to Rx flow specification
3578 * @userdef: userdefined data from flow specification
3580 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3581 * for partial matches exists with a few limitations. First, hardware only
3582 * supports masking by word boundary (2 bytes) and not per individual bit.
3583 * Second, hardware is limited to using one mask for a flow type and cannot
3584 * use a separate mask for each filter.
3586 * To support these limitations, if we already have a configured filter for
3587 * the specified type, this function enforces that new filters of the type
3588 * match the configured input set. Otherwise, if we do not have a filter of
3589 * the specified type, we allow the input set to be updated to match the
3592 * To help ensure that administrators understand why filters weren't displayed
3593 * as supported, we print a diagnostic message displaying how the input set
3594 * would change and warning to delete the preexisting filters if required.
3596 * Returns 0 on successful input set match, and a negative return code on
3599 static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
3600 struct ethtool_rx_flow_spec *fsp,
3601 struct i40e_rx_flow_userdef *userdef)
3603 struct i40e_pf *pf = vsi->back;
3604 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3605 struct ethtool_usrip4_spec *usr_ip4_spec;
3606 u64 current_mask, new_mask;
3607 bool new_flex_offset = false;
3608 bool flex_l3 = false;
3609 u16 *fdir_filter_count;
3610 u16 index, src_offset = 0;
3614 switch (fsp->flow_type & ~FLOW_EXT) {
3616 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3617 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3620 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
3621 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
3624 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
3625 fdir_filter_count = &pf->fd_udp4_filter_cnt;
3628 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
3629 fdir_filter_count = &pf->fd_ip4_filter_cnt;
3636 /* Read the current input set from register memory. */
3637 current_mask = i40e_read_fd_input_set(pf, index);
3638 new_mask = current_mask;
3640 /* Determine, if any, the required changes to the input set in order
3641 * to support the provided mask.
3643 * Hardware only supports masking at word (2 byte) granularity and does
3644 * not support full bitwise masking. This implementation simplifies
3645 * even further and only supports fully enabled or fully disabled
3646 * masks for each field, even though we could split the ip4src and
3649 switch (fsp->flow_type & ~FLOW_EXT) {
3651 new_mask &= ~I40E_VERIFY_TAG_MASK;
3655 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3657 /* IPv4 source address */
3658 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3659 new_mask |= I40E_L3_SRC_MASK;
3660 else if (!tcp_ip4_spec->ip4src)
3661 new_mask &= ~I40E_L3_SRC_MASK;
3665 /* IPv4 destination address */
3666 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3667 new_mask |= I40E_L3_DST_MASK;
3668 else if (!tcp_ip4_spec->ip4dst)
3669 new_mask &= ~I40E_L3_DST_MASK;
3673 /* L4 source port */
3674 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3675 new_mask |= I40E_L4_SRC_MASK;
3676 else if (!tcp_ip4_spec->psrc)
3677 new_mask &= ~I40E_L4_SRC_MASK;
3681 /* L4 destination port */
3682 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3683 new_mask |= I40E_L4_DST_MASK;
3684 else if (!tcp_ip4_spec->pdst)
3685 new_mask &= ~I40E_L4_DST_MASK;
3689 /* Filtering on Type of Service is not supported. */
3690 if (tcp_ip4_spec->tos)
3695 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3697 /* IPv4 source address */
3698 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3699 new_mask |= I40E_L3_SRC_MASK;
3700 else if (!usr_ip4_spec->ip4src)
3701 new_mask &= ~I40E_L3_SRC_MASK;
3705 /* IPv4 destination address */
3706 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3707 new_mask |= I40E_L3_DST_MASK;
3708 else if (!usr_ip4_spec->ip4dst)
3709 new_mask &= ~I40E_L3_DST_MASK;
3713 /* First 4 bytes of L4 header */
3714 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3715 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3716 else if (!usr_ip4_spec->l4_4_bytes)
3717 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3721 /* Filtering on Type of Service is not supported. */
3722 if (usr_ip4_spec->tos)
3725 /* Filtering on IP version is not supported */
3726 if (usr_ip4_spec->ip_ver)
3729 /* Filtering on L4 protocol is not supported */
3730 if (usr_ip4_spec->proto)
3738 /* First, clear all flexible filter entries */
3739 new_mask &= ~I40E_FLEX_INPUT_MASK;
3741 /* If we have a flexible filter, try to add this offset to the correct
3742 * flexible filter PIT list. Once finished, we can update the mask.
3743 * If the src_offset changed, we will get a new mask value which will
3744 * trigger an input set change.
3746 if (userdef->flex_filter) {
3747 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3749 /* Flexible offset must be even, since the flexible payload
3750 * must be aligned on 2-byte boundary.
3752 if (userdef->flex_offset & 0x1) {
3753 dev_warn(&pf->pdev->dev,
3754 "Flexible data offset must be 2-byte aligned\n");
3758 src_offset = userdef->flex_offset >> 1;
3760 /* FLX_PIT source offset value is only so large */
3761 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3762 dev_warn(&pf->pdev->dev,
3763 "Flexible data must reside within first 64 bytes of the packet payload\n");
3767 /* See if this offset has already been programmed. If we get
3768 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3769 * if we get a NULL pointer, this means we will need to add
3772 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3774 if (IS_ERR(flex_pit))
3775 return PTR_ERR(flex_pit);
3777 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3778 * packet types, and thus we need to program both L3 and L4
3779 * flexible values. These must have identical flexible index,
3780 * as otherwise we can't correctly program the input set. So
3781 * we'll find both an L3 and L4 index and make sure they are
3786 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3788 if (IS_ERR(l3_flex_pit))
3789 return PTR_ERR(l3_flex_pit);
3792 /* If we already had a matching L4 entry, we
3793 * need to make sure that the L3 entry we
3794 * obtained uses the same index.
3797 if (l3_flex_pit->pit_index !=
3798 flex_pit->pit_index) {
3802 new_flex_offset = true;
3805 flex_pit = l3_flex_pit;
3809 /* If we didn't find an existing flex offset, we need to
3810 * program a new one. However, we don't immediately program it
3811 * here because we will wait to program until after we check
3812 * that it is safe to change the input set.
3815 new_flex_offset = true;
3816 pit_index = i40e_unused_pit_index(pf);
3818 pit_index = flex_pit->pit_index;
3821 /* Update the mask with the new offset */
3822 new_mask |= i40e_pit_index_to_mask(pit_index);
3825 /* If the mask and flexible filter offsets for this filter match the
3826 * currently programmed values we don't need any input set change, so
3827 * this filter is safe to install.
3829 if (new_mask == current_mask && !new_flex_offset)
3832 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3833 i40e_flow_str(fsp));
3834 i40e_print_input_set(vsi, current_mask, new_mask);
3835 if (new_flex_offset) {
3836 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3837 pit_index, src_offset);
3840 /* Hardware input sets are global across multiple ports, so even the
3841 * main port cannot change them when in MFP mode as this would impact
3842 * any filters on the other ports.
3844 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3845 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
3849 /* This filter requires us to update the input set. However, hardware
3850 * only supports one input set per flow type, and does not support
3851 * separate masks for each filter. This means that we can only support
3852 * a single mask for all filters of a specific type.
3854 * If we have preexisting filters, they obviously depend on the
3855 * current programmed input set. Display a diagnostic message in this
3856 * case explaining why the filter could not be accepted.
3858 if (*fdir_filter_count) {
3859 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3861 *fdir_filter_count);
3865 i40e_write_fd_input_set(pf, index, new_mask);
3867 /* IP_USER_FLOW filters match both IPv4/Other and IPv4/Fragmented
3868 * frames. If we're programming the input set for IPv4/Other, we also
3869 * need to program the IPv4/Fragmented input set. Since we don't have
3870 * separate support, we'll always assume and enforce that the two flow
3871 * types must have matching input sets.
3873 if (index == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER)
3874 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
3877 /* Add the new offset and update table, if necessary */
3878 if (new_flex_offset) {
3879 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3885 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3892 i40e_reprogram_flex_pit(pf);
3899 * i40e_match_fdir_filter - Return true of two filters match
3900 * @a: pointer to filter struct
3901 * @b: pointer to filter struct
3903 * Returns true if the two filters match exactly the same criteria. I.e. they
3904 * match the same flow type and have the same parameters. We don't need to
3905 * check any input-set since all filters of the same flow type must use the
3908 static bool i40e_match_fdir_filter(struct i40e_fdir_filter *a,
3909 struct i40e_fdir_filter *b)
3911 /* The filters do not much if any of these criteria differ. */
3912 if (a->dst_ip != b->dst_ip ||
3913 a->src_ip != b->src_ip ||
3914 a->dst_port != b->dst_port ||
3915 a->src_port != b->src_port ||
3916 a->flow_type != b->flow_type ||
3917 a->ip4_proto != b->ip4_proto)
3924 * i40e_disallow_matching_filters - Check that new filters differ
3925 * @vsi: pointer to the targeted VSI
3926 * @input: new filter to check
3928 * Due to hardware limitations, it is not possible for two filters that match
3929 * similar criteria to be programmed at the same time. This is true for a few
3932 * (a) all filters matching a particular flow type must use the same input
3933 * set, that is they must match the same criteria.
3934 * (b) different flow types will never match the same packet, as the flow type
3935 * is decided by hardware before checking which rules apply.
3936 * (c) hardware has no way to distinguish which order filters apply in.
3938 * Due to this, we can't really support using the location data to order
3939 * filters in the hardware parsing. It is technically possible for the user to
3940 * request two filters matching the same criteria but which select different
3941 * queues. In this case, rather than keep both filters in the list, we reject
3942 * the 2nd filter when the user requests adding it.
3944 * This avoids needing to track location for programming the filter to
3945 * hardware, and ensures that we avoid some strange scenarios involving
3946 * deleting filters which match the same criteria.
3948 static int i40e_disallow_matching_filters(struct i40e_vsi *vsi,
3949 struct i40e_fdir_filter *input)
3951 struct i40e_pf *pf = vsi->back;
3952 struct i40e_fdir_filter *rule;
3953 struct hlist_node *node2;
3955 /* Loop through every filter, and check that it doesn't match */
3956 hlist_for_each_entry_safe(rule, node2,
3957 &pf->fdir_filter_list, fdir_node) {
3958 /* Don't check the filters match if they share the same fd_id,
3959 * since the new filter is actually just updating the target
3960 * of the old filter.
3962 if (rule->fd_id == input->fd_id)
3965 /* If any filters match, then print a warning message to the
3966 * kernel message buffer and bail out.
3968 if (i40e_match_fdir_filter(rule, input)) {
3969 dev_warn(&pf->pdev->dev,
3970 "Existing user defined filter %d already matches this flow.\n",
3980 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
3981 * @vsi: pointer to the targeted VSI
3982 * @cmd: command to get or set RX flow classification rules
3984 * Add Flow Director filters for a specific flow spec based on their
3985 * protocol. Returns 0 if the filters were successfully added.
3987 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3988 struct ethtool_rxnfc *cmd)
3990 struct i40e_rx_flow_userdef userdef;
3991 struct ethtool_rx_flow_spec *fsp;
3992 struct i40e_fdir_filter *input;
3993 u16 dest_vsi = 0, q_index = 0;
4002 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
4005 if (test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
4008 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
4009 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
4012 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
4015 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
4017 /* Parse the user-defined field */
4018 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
4021 /* Extended MAC field is not supported */
4022 if (fsp->flow_type & FLOW_MAC_EXT)
4025 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
4029 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
4030 pf->hw.func_caps.fd_filters_guaranteed)) {
4034 /* ring_cookie is either the drop index, or is a mask of the queue
4035 * index and VF id we wish to target.
4037 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
4038 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
4040 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
4041 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
4044 if (ring >= vsi->num_queue_pairs)
4048 /* VFs are zero-indexed, so we subtract one here */
4051 if (vf >= pf->num_alloc_vfs)
4053 if (ring >= pf->vf[vf].num_queue_pairs)
4055 dest_vsi = pf->vf[vf].lan_vsi_id;
4057 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
4061 input = kzalloc(sizeof(*input), GFP_KERNEL);
4066 input->fd_id = fsp->location;
4067 input->q_index = q_index;
4068 input->dest_vsi = dest_vsi;
4069 input->dest_ctl = dest_ctl;
4070 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
4071 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
4072 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4073 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
4074 input->flow_type = fsp->flow_type & ~FLOW_EXT;
4075 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
4077 /* Reverse the src and dest notion, since the HW expects them to be from
4078 * Tx perspective where as the input from user is from Rx filter view.
4080 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
4081 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
4082 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4083 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
4085 if (userdef.flex_filter) {
4086 input->flex_filter = true;
4087 input->flex_word = cpu_to_be16(userdef.flex_word);
4088 input->flex_offset = userdef.flex_offset;
4091 /* Avoid programming two filters with identical match criteria. */
4092 ret = i40e_disallow_matching_filters(vsi, input);
4094 goto free_filter_memory;
4096 /* Add the input filter to the fdir_input_list, possibly replacing
4097 * a previous filter. Do not free the input structure after adding it
4098 * to the list as this would cause a use-after-free bug.
4100 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
4101 ret = i40e_add_del_fdir(vsi, input, true);
4103 goto remove_sw_rule;
4107 hlist_del(&input->fdir_node);
4108 pf->fdir_pf_active_filters--;
4115 * i40e_set_rxnfc - command to set RX flow classification rules
4116 * @netdev: network interface device structure
4117 * @cmd: ethtool rxnfc command
4119 * Returns Success if the command is supported.
4121 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
4123 struct i40e_netdev_priv *np = netdev_priv(netdev);
4124 struct i40e_vsi *vsi = np->vsi;
4125 struct i40e_pf *pf = vsi->back;
4126 int ret = -EOPNOTSUPP;
4130 ret = i40e_set_rss_hash_opt(pf, cmd);
4132 case ETHTOOL_SRXCLSRLINS:
4133 ret = i40e_add_fdir_ethtool(vsi, cmd);
4135 case ETHTOOL_SRXCLSRLDEL:
4136 ret = i40e_del_fdir_entry(vsi, cmd);
4146 * i40e_max_channels - get Max number of combined channels supported
4149 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
4151 /* TODO: This code assumes DCB and FD is disabled for now. */
4152 return vsi->alloc_queue_pairs;
4156 * i40e_get_channels - Get the current channels enabled and max supported etc.
4157 * @dev: network interface device structure
4158 * @ch: ethtool channels structure
4160 * We don't support separate tx and rx queues as channels. The other count
4161 * represents how many queues are being used for control. max_combined counts
4162 * how many queue pairs we can support. They may not be mapped 1 to 1 with
4163 * q_vectors since we support a lot more queue pairs than q_vectors.
4165 static void i40e_get_channels(struct net_device *dev,
4166 struct ethtool_channels *ch)
4168 struct i40e_netdev_priv *np = netdev_priv(dev);
4169 struct i40e_vsi *vsi = np->vsi;
4170 struct i40e_pf *pf = vsi->back;
4172 /* report maximum channels */
4173 ch->max_combined = i40e_max_channels(vsi);
4175 /* report info for other vector */
4176 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
4177 ch->max_other = ch->other_count;
4179 /* Note: This code assumes DCB is disabled for now. */
4180 ch->combined_count = vsi->num_queue_pairs;
4184 * i40e_set_channels - Set the new channels count.
4185 * @dev: network interface device structure
4186 * @ch: ethtool channels structure
4188 * The new channels count may not be the same as requested by the user
4189 * since it gets rounded down to a power of 2 value.
4191 static int i40e_set_channels(struct net_device *dev,
4192 struct ethtool_channels *ch)
4194 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
4195 struct i40e_netdev_priv *np = netdev_priv(dev);
4196 unsigned int count = ch->combined_count;
4197 struct i40e_vsi *vsi = np->vsi;
4198 struct i40e_pf *pf = vsi->back;
4199 struct i40e_fdir_filter *rule;
4200 struct hlist_node *node2;
4204 /* We do not support setting channels for any other VSI at present */
4205 if (vsi->type != I40E_VSI_MAIN)
4208 /* We do not support setting channels via ethtool when TCs are
4209 * configured through mqprio
4211 if (pf->flags & I40E_FLAG_TC_MQPRIO)
4214 /* verify they are not requesting separate vectors */
4215 if (!count || ch->rx_count || ch->tx_count)
4218 /* verify other_count has not changed */
4219 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
4222 /* verify the number of channels does not exceed hardware limits */
4223 if (count > i40e_max_channels(vsi))
4226 /* verify that the number of channels does not invalidate any current
4227 * flow director rules
4229 hlist_for_each_entry_safe(rule, node2,
4230 &pf->fdir_filter_list, fdir_node) {
4231 if (rule->dest_ctl != drop && count <= rule->q_index) {
4232 dev_warn(&pf->pdev->dev,
4233 "Existing user defined filter %d assigns flow to queue %d\n",
4234 rule->fd_id, rule->q_index);
4240 dev_err(&pf->pdev->dev,
4241 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
4246 /* update feature limits from largest to smallest supported values */
4247 /* TODO: Flow director limit, DCB etc */
4249 /* use rss_reconfig to rebuild with new queue count and update traffic
4250 * class queue mapping
4252 new_count = i40e_reconfig_rss_queues(pf, count);
4260 * i40e_get_rxfh_key_size - get the RSS hash key size
4261 * @netdev: network interface device structure
4263 * Returns the table size.
4265 static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4267 return I40E_HKEY_ARRAY_SIZE;
4271 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4272 * @netdev: network interface device structure
4274 * Returns the table size.
4276 static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4278 return I40E_HLUT_ARRAY_SIZE;
4282 * i40e_get_rxfh - get the rx flow hash indirection table
4283 * @netdev: network interface device structure
4284 * @indir: indirection table
4286 * @hfunc: hash function
4288 * Reads the indirection table directly from the hardware. Returns 0 on
4291 static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4294 struct i40e_netdev_priv *np = netdev_priv(netdev);
4295 struct i40e_vsi *vsi = np->vsi;
4296 u8 *lut, *seed = NULL;
4301 *hfunc = ETH_RSS_HASH_TOP;
4307 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4310 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4313 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4314 indir[i] = (u32)(lut[i]);
4323 * i40e_set_rxfh - set the rx flow hash indirection table
4324 * @netdev: network interface device structure
4325 * @indir: indirection table
4327 * @hfunc: hash function to use
4329 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
4330 * returns 0 after programming the table.
4332 static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4333 const u8 *key, const u8 hfunc)
4335 struct i40e_netdev_priv *np = netdev_priv(netdev);
4336 struct i40e_vsi *vsi = np->vsi;
4337 struct i40e_pf *pf = vsi->back;
4341 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4345 if (!vsi->rss_hkey_user) {
4346 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4348 if (!vsi->rss_hkey_user)
4351 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4352 seed = vsi->rss_hkey_user;
4354 if (!vsi->rss_lut_user) {
4355 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4356 if (!vsi->rss_lut_user)
4360 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
4362 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4363 vsi->rss_lut_user[i] = (u8)(indir[i]);
4365 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4368 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4369 I40E_HLUT_ARRAY_SIZE);
4373 * i40e_get_priv_flags - report device private flags
4374 * @dev: network interface device structure
4376 * The get string set count and the string set should be matched for each
4377 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
4380 * Returns a u32 bitmap of flags.
4382 static u32 i40e_get_priv_flags(struct net_device *dev)
4384 struct i40e_netdev_priv *np = netdev_priv(dev);
4385 struct i40e_vsi *vsi = np->vsi;
4386 struct i40e_pf *pf = vsi->back;
4387 u32 i, j, ret_flags = 0;
4389 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4390 const struct i40e_priv_flags *priv_flags;
4392 priv_flags = &i40e_gstrings_priv_flags[i];
4394 if (priv_flags->flag & pf->flags)
4395 ret_flags |= BIT(i);
4398 if (pf->hw.pf_id != 0)
4401 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4402 const struct i40e_priv_flags *priv_flags;
4404 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4406 if (priv_flags->flag & pf->flags)
4407 ret_flags |= BIT(i + j);
4414 * i40e_set_priv_flags - set private flags
4415 * @dev: network interface device structure
4416 * @flags: bit flags to be set
4418 static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4420 struct i40e_netdev_priv *np = netdev_priv(dev);
4421 struct i40e_vsi *vsi = np->vsi;
4422 struct i40e_pf *pf = vsi->back;
4423 u64 orig_flags, new_flags, changed_flags;
4426 orig_flags = READ_ONCE(pf->flags);
4427 new_flags = orig_flags;
4429 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4430 const struct i40e_priv_flags *priv_flags;
4432 priv_flags = &i40e_gstrings_priv_flags[i];
4435 new_flags |= priv_flags->flag;
4437 new_flags &= ~(priv_flags->flag);
4439 /* If this is a read-only flag, it can't be changed */
4440 if (priv_flags->read_only &&
4441 ((orig_flags ^ new_flags) & ~BIT(i)))
4445 if (pf->hw.pf_id != 0)
4446 goto flags_complete;
4448 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4449 const struct i40e_priv_flags *priv_flags;
4451 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4453 if (flags & BIT(i + j))
4454 new_flags |= priv_flags->flag;
4456 new_flags &= ~(priv_flags->flag);
4458 /* If this is a read-only flag, it can't be changed */
4459 if (priv_flags->read_only &&
4460 ((orig_flags ^ new_flags) & ~BIT(i)))
4465 changed_flags = orig_flags ^ new_flags;
4467 /* Before we finalize any flag changes, we need to perform some
4468 * checks to ensure that the changes are supported and safe.
4471 /* ATR eviction is not supported on all devices */
4472 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4473 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4476 /* If the driver detected FW LLDP was disabled on init, this flag could
4477 * be set, however we do not support _changing_ the flag if NPAR is
4478 * enabled or FW API version < 1.7. There are situations where older
4479 * FW versions/NPAR enabled PFs could disable LLDP, however we _must_
4480 * not allow the user to enable/disable LLDP with this flag on
4481 * unsupported FW versions.
4483 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
4484 if (!(pf->hw_features & I40E_HW_STOPPABLE_FW_LLDP)) {
4485 dev_warn(&pf->pdev->dev,
4486 "Device does not support changing FW LLDP\n");
4491 /* Now that we've checked to ensure that the new flags are valid, load
4492 * them into place. Since we only modify flags either (a) during
4493 * initialization or (b) while holding the RTNL lock, we don't need
4494 * anything fancy here.
4496 pf->flags = new_flags;
4498 /* Process any additional changes needed as a result of flag changes.
4499 * The changed_flags value reflects the list of bits that were
4500 * changed in the code above.
4503 /* Flush current ATR settings if ATR was disabled */
4504 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4505 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
4506 set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
4507 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
4510 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4511 u16 sw_flags = 0, valid_flags = 0;
4514 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4515 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4516 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4517 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
4519 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4520 dev_info(&pf->pdev->dev,
4521 "couldn't set switch config bits, err %s aq_err %s\n",
4522 i40e_stat_str(&pf->hw, ret),
4523 i40e_aq_str(&pf->hw,
4524 pf->hw.aq.asq_last_status));
4525 /* not a fatal problem, just keep going */
4529 if ((changed_flags & pf->flags &
4530 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED) &&
4531 (pf->flags & I40E_FLAG_MFP_ENABLED))
4532 dev_warn(&pf->pdev->dev,
4533 "Turning on link-down-on-close flag may affect other partitions\n");
4535 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
4536 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) {
4537 struct i40e_dcbx_config *dcbcfg;
4540 i40e_aq_stop_lldp(&pf->hw, true, NULL);
4541 i40e_aq_set_dcb_parameters(&pf->hw, true, NULL);
4542 /* reset local_dcbx_config to default */
4543 dcbcfg = &pf->hw.local_dcbx_config;
4544 dcbcfg->etscfg.willing = 1;
4545 dcbcfg->etscfg.maxtcs = 0;
4546 dcbcfg->etscfg.tcbwtable[0] = 100;
4547 for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++)
4548 dcbcfg->etscfg.tcbwtable[i] = 0;
4549 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4550 dcbcfg->etscfg.prioritytable[i] = 0;
4551 dcbcfg->etscfg.tsatable[0] = I40E_IEEE_TSA_ETS;
4552 dcbcfg->pfc.willing = 1;
4553 dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
4555 i40e_aq_start_lldp(&pf->hw, NULL);
4559 /* Issue reset to cause things to take effect, as additional bits
4560 * are added we will need to create a mask of bits requiring reset
4562 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4563 I40E_FLAG_LEGACY_RX |
4564 I40E_FLAG_SOURCE_PRUNING_DISABLED |
4565 I40E_FLAG_DISABLE_FW_LLDP))
4566 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
4572 * i40e_get_module_info - get (Q)SFP+ module type info
4573 * @netdev: network interface device structure
4574 * @modinfo: module EEPROM size and layout information structure
4576 static int i40e_get_module_info(struct net_device *netdev,
4577 struct ethtool_modinfo *modinfo)
4579 struct i40e_netdev_priv *np = netdev_priv(netdev);
4580 struct i40e_vsi *vsi = np->vsi;
4581 struct i40e_pf *pf = vsi->back;
4582 struct i40e_hw *hw = &pf->hw;
4583 u32 sff8472_comp = 0;
4584 u32 sff8472_swap = 0;
4585 u32 sff8636_rev = 0;
4589 /* Check if firmware supports reading module EEPROM. */
4590 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4591 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4595 status = i40e_update_link_info(hw);
4599 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4600 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4604 type = hw->phy.link_info.module_type[0];
4607 case I40E_MODULE_TYPE_SFP:
4608 status = i40e_aq_get_phy_register(hw,
4609 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4610 I40E_I2C_EEPROM_DEV_ADDR,
4611 I40E_MODULE_SFF_8472_COMP,
4612 &sff8472_comp, NULL);
4616 status = i40e_aq_get_phy_register(hw,
4617 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4618 I40E_I2C_EEPROM_DEV_ADDR,
4619 I40E_MODULE_SFF_8472_SWAP,
4620 &sff8472_swap, NULL);
4624 /* Check if the module requires address swap to access
4625 * the other EEPROM memory page.
4627 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4628 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4629 modinfo->type = ETH_MODULE_SFF_8079;
4630 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4631 } else if (sff8472_comp == 0x00) {
4632 /* Module is not SFF-8472 compliant */
4633 modinfo->type = ETH_MODULE_SFF_8079;
4634 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4636 modinfo->type = ETH_MODULE_SFF_8472;
4637 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4640 case I40E_MODULE_TYPE_QSFP_PLUS:
4641 /* Read from memory page 0. */
4642 status = i40e_aq_get_phy_register(hw,
4643 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4645 I40E_MODULE_REVISION_ADDR,
4646 &sff8636_rev, NULL);
4649 /* Determine revision compliance byte */
4650 if (sff8636_rev > 0x02) {
4651 /* Module is SFF-8636 compliant */
4652 modinfo->type = ETH_MODULE_SFF_8636;
4653 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4655 modinfo->type = ETH_MODULE_SFF_8436;
4656 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4659 case I40E_MODULE_TYPE_QSFP28:
4660 modinfo->type = ETH_MODULE_SFF_8636;
4661 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4664 netdev_err(vsi->netdev, "Module type unrecognized\n");
4671 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4672 * @netdev: network interface device structure
4673 * @ee: EEPROM dump request structure
4674 * @data: buffer to be filled with EEPROM contents
4676 static int i40e_get_module_eeprom(struct net_device *netdev,
4677 struct ethtool_eeprom *ee,
4680 struct i40e_netdev_priv *np = netdev_priv(netdev);
4681 struct i40e_vsi *vsi = np->vsi;
4682 struct i40e_pf *pf = vsi->back;
4683 struct i40e_hw *hw = &pf->hw;
4684 bool is_sfp = false;
4689 if (!ee || !ee->len || !data)
4692 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4695 for (i = 0; i < ee->len; i++) {
4696 u32 offset = i + ee->offset;
4697 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4699 /* Check if we need to access the other memory page */
4701 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4702 offset -= ETH_MODULE_SFF_8079_LEN;
4703 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4706 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4707 /* Compute memory page number and offset. */
4708 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4713 status = i40e_aq_get_phy_register(hw,
4714 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4715 addr, offset, &value, NULL);
4723 static const struct ethtool_ops i40e_ethtool_ops = {
4724 .get_drvinfo = i40e_get_drvinfo,
4725 .get_regs_len = i40e_get_regs_len,
4726 .get_regs = i40e_get_regs,
4727 .nway_reset = i40e_nway_reset,
4728 .get_link = ethtool_op_get_link,
4729 .get_wol = i40e_get_wol,
4730 .set_wol = i40e_set_wol,
4731 .set_eeprom = i40e_set_eeprom,
4732 .get_eeprom_len = i40e_get_eeprom_len,
4733 .get_eeprom = i40e_get_eeprom,
4734 .get_ringparam = i40e_get_ringparam,
4735 .set_ringparam = i40e_set_ringparam,
4736 .get_pauseparam = i40e_get_pauseparam,
4737 .set_pauseparam = i40e_set_pauseparam,
4738 .get_msglevel = i40e_get_msglevel,
4739 .set_msglevel = i40e_set_msglevel,
4740 .get_rxnfc = i40e_get_rxnfc,
4741 .set_rxnfc = i40e_set_rxnfc,
4742 .self_test = i40e_diag_test,
4743 .get_strings = i40e_get_strings,
4744 .set_phys_id = i40e_set_phys_id,
4745 .get_sset_count = i40e_get_sset_count,
4746 .get_ethtool_stats = i40e_get_ethtool_stats,
4747 .get_coalesce = i40e_get_coalesce,
4748 .set_coalesce = i40e_set_coalesce,
4749 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4750 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4751 .get_rxfh = i40e_get_rxfh,
4752 .set_rxfh = i40e_set_rxfh,
4753 .get_channels = i40e_get_channels,
4754 .set_channels = i40e_set_channels,
4755 .get_module_info = i40e_get_module_info,
4756 .get_module_eeprom = i40e_get_module_eeprom,
4757 .get_ts_info = i40e_get_ts_info,
4758 .get_priv_flags = i40e_get_priv_flags,
4759 .set_priv_flags = i40e_set_priv_flags,
4760 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
4761 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
4762 .get_link_ksettings = i40e_get_link_ksettings,
4763 .set_link_ksettings = i40e_set_link_ksettings,
4766 void i40e_set_ethtool_ops(struct net_device *netdev)
4768 netdev->ethtool_ops = &i40e_ethtool_ops;