Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2016 Intel Corporation. |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
| 27 | /* ethtool support for i40e */ |
| 28 | |
| 29 | #include "i40e.h" |
| 30 | #include "i40e_diag.h" |
| 31 | |
| 32 | struct i40e_stats { |
| 33 | char stat_string[ETH_GSTRING_LEN]; |
| 34 | int sizeof_stat; |
| 35 | int stat_offset; |
| 36 | }; |
| 37 | |
| 38 | #define I40E_STAT(_type, _name, _stat) { \ |
| 39 | .stat_string = _name, \ |
| 40 | .sizeof_stat = FIELD_SIZEOF(_type, _stat), \ |
| 41 | .stat_offset = offsetof(_type, _stat) \ |
| 42 | } |
Shannon Nelson | fad177d | 2014-11-11 20:07:27 +0000 | [diff] [blame] | 43 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 44 | #define I40E_NETDEV_STAT(_net_stat) \ |
Shannon Nelson | fad177d | 2014-11-11 20:07:27 +0000 | [diff] [blame] | 45 | I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 46 | #define I40E_PF_STAT(_name, _stat) \ |
| 47 | I40E_STAT(struct i40e_pf, _name, _stat) |
| 48 | #define I40E_VSI_STAT(_name, _stat) \ |
| 49 | I40E_STAT(struct i40e_vsi, _name, _stat) |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 50 | #define I40E_VEB_STAT(_name, _stat) \ |
| 51 | I40E_STAT(struct i40e_veb, _name, _stat) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 52 | |
| 53 | static const struct i40e_stats i40e_gstrings_net_stats[] = { |
| 54 | I40E_NETDEV_STAT(rx_packets), |
| 55 | I40E_NETDEV_STAT(tx_packets), |
| 56 | I40E_NETDEV_STAT(rx_bytes), |
| 57 | I40E_NETDEV_STAT(tx_bytes), |
| 58 | I40E_NETDEV_STAT(rx_errors), |
| 59 | I40E_NETDEV_STAT(tx_errors), |
| 60 | I40E_NETDEV_STAT(rx_dropped), |
| 61 | I40E_NETDEV_STAT(tx_dropped), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 62 | I40E_NETDEV_STAT(collisions), |
| 63 | I40E_NETDEV_STAT(rx_length_errors), |
| 64 | I40E_NETDEV_STAT(rx_crc_errors), |
| 65 | }; |
| 66 | |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 67 | static const struct i40e_stats i40e_gstrings_veb_stats[] = { |
| 68 | I40E_VEB_STAT("rx_bytes", stats.rx_bytes), |
| 69 | I40E_VEB_STAT("tx_bytes", stats.tx_bytes), |
| 70 | I40E_VEB_STAT("rx_unicast", stats.rx_unicast), |
| 71 | I40E_VEB_STAT("tx_unicast", stats.tx_unicast), |
| 72 | I40E_VEB_STAT("rx_multicast", stats.rx_multicast), |
| 73 | I40E_VEB_STAT("tx_multicast", stats.tx_multicast), |
| 74 | I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast), |
| 75 | I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast), |
| 76 | I40E_VEB_STAT("rx_discards", stats.rx_discards), |
| 77 | I40E_VEB_STAT("tx_discards", stats.tx_discards), |
| 78 | I40E_VEB_STAT("tx_errors", stats.tx_errors), |
| 79 | I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol), |
| 80 | }; |
| 81 | |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 82 | static const struct i40e_stats i40e_gstrings_misc_stats[] = { |
Shannon Nelson | 418631d | 2014-04-23 04:50:07 +0000 | [diff] [blame] | 83 | I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast), |
| 84 | I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast), |
| 85 | I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast), |
| 86 | I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast), |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 87 | I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast), |
| 88 | I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast), |
Shannon Nelson | 418631d | 2014-04-23 04:50:07 +0000 | [diff] [blame] | 89 | I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol), |
Anjali Singhai Jain | 2fc3d71 | 2015-08-27 11:42:29 -0400 | [diff] [blame] | 90 | I40E_VSI_STAT("tx_linearize", tx_linearize), |
Anjali Singhai Jain | 164c9f5 | 2015-10-21 19:47:08 -0400 | [diff] [blame] | 91 | I40E_VSI_STAT("tx_force_wb", tx_force_wb), |
Anjali Singhai Jain | dd35310 | 2016-01-15 14:33:12 -0800 | [diff] [blame] | 92 | I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt), |
Jesse Brandeburg | c40918c | 2016-01-04 10:33:10 -0800 | [diff] [blame] | 93 | I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed), |
| 94 | I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed), |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 97 | /* These PF_STATs might look like duplicates of some NETDEV_STATs, |
| 98 | * but they are separate. This device supports Virtualization, and |
| 99 | * as such might have several netdevs supporting VMDq and FCoE going |
| 100 | * through a single port. The NETDEV_STATs are for individual netdevs |
| 101 | * seen at the top of the stack, and the PF_STATs are for the physical |
| 102 | * function at the bottom of the stack hosting those netdevs. |
| 103 | * |
| 104 | * The PF_STATs are appended to the netdev stats only when ethtool -S |
| 105 | * is queried on the base PF netdev, not on the VMDq or FCoE netdev. |
| 106 | */ |
Joe Perches | fe180a5 | 2016-09-26 20:17:01 -0700 | [diff] [blame] | 107 | static const struct i40e_stats i40e_gstrings_stats[] = { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 108 | I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes), |
| 109 | I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes), |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 110 | I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast), |
| 111 | I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast), |
| 112 | I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast), |
| 113 | I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast), |
| 114 | I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast), |
| 115 | I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 116 | I40E_PF_STAT("tx_errors", stats.eth.tx_errors), |
| 117 | I40E_PF_STAT("rx_dropped", stats.eth.rx_discards), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 118 | I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down), |
Shannon Nelson | 9f7c944 | 2015-07-10 19:35:57 -0400 | [diff] [blame] | 119 | I40E_PF_STAT("rx_crc_errors", stats.crc_errors), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 120 | I40E_PF_STAT("illegal_bytes", stats.illegal_bytes), |
| 121 | I40E_PF_STAT("mac_local_faults", stats.mac_local_faults), |
| 122 | I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults), |
Jesse Brandeburg | a47a15f | 2014-02-06 05:51:09 +0000 | [diff] [blame] | 123 | I40E_PF_STAT("tx_timeout", tx_timeout_count), |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 124 | I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 125 | I40E_PF_STAT("rx_length_errors", stats.rx_length_errors), |
| 126 | I40E_PF_STAT("link_xon_rx", stats.link_xon_rx), |
| 127 | I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx), |
| 128 | I40E_PF_STAT("link_xon_tx", stats.link_xon_tx), |
| 129 | I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx), |
| 130 | I40E_PF_STAT("rx_size_64", stats.rx_size_64), |
| 131 | I40E_PF_STAT("rx_size_127", stats.rx_size_127), |
| 132 | I40E_PF_STAT("rx_size_255", stats.rx_size_255), |
| 133 | I40E_PF_STAT("rx_size_511", stats.rx_size_511), |
| 134 | I40E_PF_STAT("rx_size_1023", stats.rx_size_1023), |
| 135 | I40E_PF_STAT("rx_size_1522", stats.rx_size_1522), |
| 136 | I40E_PF_STAT("rx_size_big", stats.rx_size_big), |
| 137 | I40E_PF_STAT("tx_size_64", stats.tx_size_64), |
| 138 | I40E_PF_STAT("tx_size_127", stats.tx_size_127), |
| 139 | I40E_PF_STAT("tx_size_255", stats.tx_size_255), |
| 140 | I40E_PF_STAT("tx_size_511", stats.tx_size_511), |
| 141 | I40E_PF_STAT("tx_size_1023", stats.tx_size_1023), |
| 142 | I40E_PF_STAT("tx_size_1522", stats.tx_size_1522), |
| 143 | I40E_PF_STAT("tx_size_big", stats.tx_size_big), |
| 144 | I40E_PF_STAT("rx_undersize", stats.rx_undersize), |
| 145 | I40E_PF_STAT("rx_fragments", stats.rx_fragments), |
| 146 | I40E_PF_STAT("rx_oversize", stats.rx_oversize), |
| 147 | I40E_PF_STAT("rx_jabber", stats.rx_jabber), |
| 148 | I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests), |
Mitch Williams | 1d0a4ad | 2015-12-23 12:05:48 -0800 | [diff] [blame] | 149 | I40E_PF_STAT("arq_overflows", arq_overflows), |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 150 | I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared), |
Anjali Singhai Jain | 60793f4a | 2014-07-09 07:46:23 +0000 | [diff] [blame] | 151 | I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 152 | I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match), |
Anjali Singhai Jain | 60ccd45 | 2015-04-16 20:06:01 -0400 | [diff] [blame] | 153 | I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match), |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 154 | I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 155 | I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match), |
Anjali Singhai Jain | d0389e5 | 2015-04-22 19:34:05 -0400 | [diff] [blame] | 156 | I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 157 | |
Anjali Singhai Jain | bee5af7 | 2014-03-06 08:59:50 +0000 | [diff] [blame] | 158 | /* LPI stats */ |
| 159 | I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status), |
| 160 | I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status), |
| 161 | I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count), |
| 162 | I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 165 | #ifdef I40E_FCOE |
| 166 | static const struct i40e_stats i40e_gstrings_fcoe_stats[] = { |
| 167 | I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc), |
| 168 | I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped), |
| 169 | I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets), |
| 170 | I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords), |
| 171 | I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count), |
| 172 | I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error), |
| 173 | I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets), |
| 174 | I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords), |
| 175 | }; |
| 176 | |
| 177 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 178 | #define I40E_QUEUE_STATS_LEN(n) \ |
Shannon Nelson | 31cd840 | 2014-04-04 04:43:12 +0000 | [diff] [blame] | 179 | (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \ |
| 180 | * 2 /* Tx and Rx together */ \ |
| 181 | * (sizeof(struct i40e_queue_stats) / sizeof(u64))) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 182 | #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats) |
| 183 | #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats) |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 184 | #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 185 | #ifdef I40E_FCOE |
| 186 | #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats) |
| 187 | #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \ |
| 188 | I40E_FCOE_STATS_LEN + \ |
| 189 | I40E_MISC_STATS_LEN + \ |
| 190 | I40E_QUEUE_STATS_LEN((n))) |
| 191 | #else |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 192 | #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \ |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 193 | I40E_MISC_STATS_LEN + \ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 194 | I40E_QUEUE_STATS_LEN((n))) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 195 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 196 | #define I40E_PFC_STATS_LEN ( \ |
| 197 | (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \ |
| 198 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \ |
| 199 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \ |
| 200 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \ |
| 201 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \ |
| 202 | / sizeof(u64)) |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 203 | #define I40E_VEB_TC_STATS_LEN ( \ |
| 204 | (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \ |
| 205 | FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \ |
| 206 | FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \ |
| 207 | FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \ |
| 208 | / sizeof(u64)) |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 209 | #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats) |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 210 | #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 211 | #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \ |
| 212 | I40E_PFC_STATS_LEN + \ |
| 213 | I40E_VSI_STATS_LEN((n))) |
| 214 | |
| 215 | enum i40e_ethtool_test_id { |
| 216 | I40E_ETH_TEST_REG = 0, |
| 217 | I40E_ETH_TEST_EEPROM, |
| 218 | I40E_ETH_TEST_INTR, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 219 | I40E_ETH_TEST_LINK, |
| 220 | }; |
| 221 | |
| 222 | static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = { |
| 223 | "Register test (offline)", |
| 224 | "Eeprom test (offline)", |
| 225 | "Interrupt test (offline)", |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 226 | "Link test (on/offline)" |
| 227 | }; |
| 228 | |
| 229 | #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN) |
| 230 | |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 231 | static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = { |
Jacob Keller | d182a5c | 2016-10-25 16:08:50 -0700 | [diff] [blame] | 232 | "MFP", |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 233 | "LinkPolling", |
Jesse Brandeburg | ef17178 | 2015-09-03 17:18:49 -0400 | [diff] [blame] | 234 | "flow-director-atr", |
Shannon Nelson | 1cdfd88 | 2015-09-28 14:12:34 -0400 | [diff] [blame] | 235 | "veb-stats", |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 236 | "hw-atr-eviction", |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 237 | }; |
| 238 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 239 | #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings) |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 240 | |
Jacob Keller | d182a5c | 2016-10-25 16:08:50 -0700 | [diff] [blame] | 241 | /* Private flags with a global effect, restricted to PF 0 */ |
| 242 | static const char i40e_gl_priv_flags_strings[][ETH_GSTRING_LEN] = { |
| 243 | "vf-true-promisc-support", |
| 244 | }; |
| 245 | |
| 246 | #define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_priv_flags_strings) |
| 247 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 248 | /** |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 249 | * i40e_partition_setting_complaint - generic complaint for MFP restriction |
| 250 | * @pf: the PF struct |
| 251 | **/ |
| 252 | static void i40e_partition_setting_complaint(struct i40e_pf *pf) |
| 253 | { |
| 254 | dev_info(&pf->pdev->dev, |
| 255 | "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"); |
| 256 | } |
| 257 | |
| 258 | /** |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 259 | * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes |
| 260 | * @phy_types: PHY types to convert |
| 261 | * @supported: pointer to the ethtool supported variable to fill in |
| 262 | * @advertising: pointer to the ethtool advertising variable to fill in |
| 263 | * |
| 264 | **/ |
| 265 | static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported, |
| 266 | u32 *advertising) |
| 267 | { |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 268 | struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 269 | u64 phy_types = pf->hw.phy.phy_types; |
| 270 | |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 271 | *supported = 0x0; |
| 272 | *advertising = 0x0; |
| 273 | |
| 274 | if (phy_types & I40E_CAP_PHY_TYPE_SGMII) { |
| 275 | *supported |= SUPPORTED_Autoneg | |
| 276 | SUPPORTED_1000baseT_Full; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 277 | *advertising |= ADVERTISED_Autoneg; |
| 278 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) |
| 279 | *advertising |= ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 280 | if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) { |
| 281 | *supported |= SUPPORTED_100baseT_Full; |
| 282 | *advertising |= ADVERTISED_100baseT_Full; |
| 283 | } |
| 284 | } |
| 285 | if (phy_types & I40E_CAP_PHY_TYPE_XAUI || |
| 286 | phy_types & I40E_CAP_PHY_TYPE_XFI || |
| 287 | phy_types & I40E_CAP_PHY_TYPE_SFI || |
| 288 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU || |
| 289 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) |
| 290 | *supported |= SUPPORTED_10000baseT_Full; |
| 291 | if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU || |
| 292 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 || |
| 293 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_T || |
| 294 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR || |
| 295 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) { |
| 296 | *supported |= SUPPORTED_Autoneg | |
| 297 | SUPPORTED_10000baseT_Full; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 298 | *advertising |= ADVERTISED_Autoneg; |
| 299 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) |
| 300 | *advertising |= ADVERTISED_10000baseT_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 301 | } |
| 302 | if (phy_types & I40E_CAP_PHY_TYPE_XLAUI || |
| 303 | phy_types & I40E_CAP_PHY_TYPE_XLPPI || |
| 304 | phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC) |
| 305 | *supported |= SUPPORTED_40000baseCR4_Full; |
| 306 | if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU || |
| 307 | phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) { |
| 308 | *supported |= SUPPORTED_Autoneg | |
| 309 | SUPPORTED_40000baseCR4_Full; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 310 | *advertising |= ADVERTISED_Autoneg; |
| 311 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB) |
| 312 | *advertising |= ADVERTISED_40000baseCR4_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 313 | } |
Avinash Dayanand | 01a7a9f | 2016-05-16 10:26:40 -0700 | [diff] [blame] | 314 | if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) { |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 315 | *supported |= SUPPORTED_Autoneg | |
| 316 | SUPPORTED_100baseT_Full; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 317 | *advertising |= ADVERTISED_Autoneg; |
| 318 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB) |
| 319 | *advertising |= ADVERTISED_100baseT_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 320 | } |
| 321 | if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T || |
| 322 | phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX || |
| 323 | phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX || |
| 324 | phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) { |
| 325 | *supported |= SUPPORTED_Autoneg | |
| 326 | SUPPORTED_1000baseT_Full; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 327 | *advertising |= ADVERTISED_Autoneg; |
| 328 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) |
| 329 | *advertising |= ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 330 | } |
| 331 | if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4) |
| 332 | *supported |= SUPPORTED_40000baseSR4_Full; |
| 333 | if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4) |
| 334 | *supported |= SUPPORTED_40000baseLR4_Full; |
| 335 | if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) { |
| 336 | *supported |= SUPPORTED_40000baseKR4_Full | |
| 337 | SUPPORTED_Autoneg; |
| 338 | *advertising |= ADVERTISED_40000baseKR4_Full | |
| 339 | ADVERTISED_Autoneg; |
| 340 | } |
| 341 | if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) { |
| 342 | *supported |= SUPPORTED_20000baseKR2_Full | |
| 343 | SUPPORTED_Autoneg; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 344 | *advertising |= ADVERTISED_Autoneg; |
| 345 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB) |
| 346 | *advertising |= ADVERTISED_20000baseKR2_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 347 | } |
| 348 | if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) { |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 349 | if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER)) |
| 350 | *supported |= SUPPORTED_10000baseKR_Full | |
| 351 | SUPPORTED_Autoneg; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 352 | *advertising |= ADVERTISED_Autoneg; |
| 353 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 354 | if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER)) |
| 355 | *advertising |= ADVERTISED_10000baseKR_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 356 | } |
| 357 | if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) { |
| 358 | *supported |= SUPPORTED_10000baseKX4_Full | |
| 359 | SUPPORTED_Autoneg; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 360 | *advertising |= ADVERTISED_Autoneg; |
| 361 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) |
| 362 | *advertising |= ADVERTISED_10000baseKX4_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 363 | } |
| 364 | if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) { |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 365 | if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER)) |
| 366 | *supported |= SUPPORTED_1000baseKX_Full | |
| 367 | SUPPORTED_Autoneg; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 368 | *advertising |= ADVERTISED_Autoneg; |
| 369 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 370 | if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER)) |
| 371 | *advertising |= ADVERTISED_1000baseKX_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 372 | } |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 373 | if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR || |
| 374 | phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR || |
| 375 | phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR || |
| 376 | phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) { |
| 377 | *supported |= SUPPORTED_Autoneg; |
| 378 | *advertising |= ADVERTISED_Autoneg; |
| 379 | } |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /** |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 383 | * i40e_get_settings_link_up - Get the Link settings for when link is up |
| 384 | * @hw: hw structure |
| 385 | * @ecmd: ethtool command to fill in |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 386 | * @netdev: network interface device structure |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 387 | * |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 388 | **/ |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 389 | static void i40e_get_settings_link_up(struct i40e_hw *hw, |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 390 | struct ethtool_link_ksettings *cmd, |
Catherine Sullivan | 3b6c217 | 2015-09-03 17:18:52 -0400 | [diff] [blame] | 391 | struct net_device *netdev, |
| 392 | struct i40e_pf *pf) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 393 | { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 394 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 395 | u32 link_speed = hw_link_info->link_speed; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 396 | u32 e_advertising = 0x0; |
| 397 | u32 e_supported = 0x0; |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 398 | u32 supported, advertising; |
| 399 | |
| 400 | ethtool_convert_link_mode_to_legacy_u32(&supported, |
| 401 | cmd->link_modes.supported); |
| 402 | ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 403 | cmd->link_modes.advertising); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 404 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 405 | /* Initialize supported and advertised settings based on phy settings */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 406 | switch (hw_link_info->phy_type) { |
| 407 | case I40E_PHY_TYPE_40GBASE_CR4: |
| 408 | case I40E_PHY_TYPE_40GBASE_CR4_CU: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 409 | supported = SUPPORTED_Autoneg | |
| 410 | SUPPORTED_40000baseCR4_Full; |
| 411 | advertising = ADVERTISED_Autoneg | |
| 412 | ADVERTISED_40000baseCR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 413 | break; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 414 | case I40E_PHY_TYPE_XLAUI: |
| 415 | case I40E_PHY_TYPE_XLPPI: |
Catherine Sullivan | 180204c | 2015-02-26 16:14:58 +0000 | [diff] [blame] | 416 | case I40E_PHY_TYPE_40GBASE_AOC: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 417 | supported = SUPPORTED_40000baseCR4_Full; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 418 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 419 | case I40E_PHY_TYPE_40GBASE_SR4: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 420 | supported = SUPPORTED_40000baseSR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 421 | break; |
| 422 | case I40E_PHY_TYPE_40GBASE_LR4: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 423 | supported = SUPPORTED_40000baseLR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 424 | break; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 425 | case I40E_PHY_TYPE_10GBASE_SR: |
| 426 | case I40E_PHY_TYPE_10GBASE_LR: |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 427 | case I40E_PHY_TYPE_1000BASE_SX: |
| 428 | case I40E_PHY_TYPE_1000BASE_LX: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 429 | supported = SUPPORTED_10000baseT_Full; |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 430 | if (hw_link_info->module_type[2] & |
| 431 | I40E_MODULE_TYPE_1000BASE_SX || |
| 432 | hw_link_info->module_type[2] & |
| 433 | I40E_MODULE_TYPE_1000BASE_LX) { |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 434 | supported |= SUPPORTED_1000baseT_Full; |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 435 | if (hw_link_info->requested_speeds & |
| 436 | I40E_LINK_SPEED_1GB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 437 | advertising |= ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 438 | } |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 439 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 440 | advertising |= ADVERTISED_10000baseT_Full; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 441 | break; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 442 | case I40E_PHY_TYPE_10GBASE_T: |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 443 | case I40E_PHY_TYPE_1000BASE_T: |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 444 | case I40E_PHY_TYPE_100BASE_TX: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 445 | supported = SUPPORTED_Autoneg | |
| 446 | SUPPORTED_10000baseT_Full | |
| 447 | SUPPORTED_1000baseT_Full | |
| 448 | SUPPORTED_100baseT_Full; |
| 449 | advertising = ADVERTISED_Autoneg; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 450 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 451 | advertising |= ADVERTISED_10000baseT_Full; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 452 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 453 | advertising |= ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 454 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 455 | advertising |= ADVERTISED_100baseT_Full; |
Catherine Sullivan | 3b6c217 | 2015-09-03 17:18:52 -0400 | [diff] [blame] | 456 | break; |
Catherine Sullivan | 48becae | 2015-09-28 14:12:41 -0400 | [diff] [blame] | 457 | case I40E_PHY_TYPE_1000BASE_T_OPTICAL: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 458 | supported = SUPPORTED_Autoneg | |
| 459 | SUPPORTED_1000baseT_Full; |
| 460 | advertising = ADVERTISED_Autoneg | |
| 461 | ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 48becae | 2015-09-28 14:12:41 -0400 | [diff] [blame] | 462 | break; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 463 | case I40E_PHY_TYPE_10GBASE_CR1_CU: |
| 464 | case I40E_PHY_TYPE_10GBASE_CR1: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 465 | supported = SUPPORTED_Autoneg | |
| 466 | SUPPORTED_10000baseT_Full; |
| 467 | advertising = ADVERTISED_Autoneg | |
| 468 | ADVERTISED_10000baseT_Full; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 469 | break; |
| 470 | case I40E_PHY_TYPE_XAUI: |
| 471 | case I40E_PHY_TYPE_XFI: |
| 472 | case I40E_PHY_TYPE_SFI: |
| 473 | case I40E_PHY_TYPE_10GBASE_SFPP_CU: |
Catherine Sullivan | 180204c | 2015-02-26 16:14:58 +0000 | [diff] [blame] | 474 | case I40E_PHY_TYPE_10GBASE_AOC: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 475 | supported = SUPPORTED_10000baseT_Full; |
| 476 | advertising = SUPPORTED_10000baseT_Full; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 477 | break; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 478 | case I40E_PHY_TYPE_SGMII: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 479 | supported = SUPPORTED_Autoneg | |
| 480 | SUPPORTED_1000baseT_Full; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 481 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 482 | advertising |= ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 48b1804 | 2015-12-09 15:50:25 -0800 | [diff] [blame] | 483 | if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) { |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 484 | supported |= SUPPORTED_100baseT_Full; |
Catherine Sullivan | 3b6c217 | 2015-09-03 17:18:52 -0400 | [diff] [blame] | 485 | if (hw_link_info->requested_speeds & |
| 486 | I40E_LINK_SPEED_100MB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 487 | advertising |= ADVERTISED_100baseT_Full; |
Catherine Sullivan | 3b6c217 | 2015-09-03 17:18:52 -0400 | [diff] [blame] | 488 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 489 | break; |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 490 | case I40E_PHY_TYPE_40GBASE_KR4: |
| 491 | case I40E_PHY_TYPE_20GBASE_KR2: |
| 492 | case I40E_PHY_TYPE_10GBASE_KR: |
| 493 | case I40E_PHY_TYPE_10GBASE_KX4: |
| 494 | case I40E_PHY_TYPE_1000BASE_KX: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 495 | supported |= SUPPORTED_40000baseKR4_Full | |
| 496 | SUPPORTED_20000baseKR2_Full | |
| 497 | SUPPORTED_10000baseKR_Full | |
| 498 | SUPPORTED_10000baseKX4_Full | |
| 499 | SUPPORTED_1000baseKX_Full | |
| 500 | SUPPORTED_Autoneg; |
| 501 | advertising |= ADVERTISED_40000baseKR4_Full | |
| 502 | ADVERTISED_20000baseKR2_Full | |
| 503 | ADVERTISED_10000baseKR_Full | |
| 504 | ADVERTISED_10000baseKX4_Full | |
| 505 | ADVERTISED_1000baseKX_Full | |
| 506 | ADVERTISED_Autoneg; |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 507 | break; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 508 | case I40E_PHY_TYPE_25GBASE_KR: |
| 509 | case I40E_PHY_TYPE_25GBASE_CR: |
| 510 | case I40E_PHY_TYPE_25GBASE_SR: |
| 511 | case I40E_PHY_TYPE_25GBASE_LR: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 512 | supported = SUPPORTED_Autoneg; |
| 513 | advertising = ADVERTISED_Autoneg; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 514 | /* TODO: add speeds when ethtool is ready to support*/ |
| 515 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 516 | default: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 517 | /* if we got here and link is up something bad is afoot */ |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 518 | netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n", |
| 519 | hw_link_info->phy_type); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 522 | /* Now that we've worked out everything that could be supported by the |
| 523 | * current PHY type, get what is supported by the NVM and them to |
| 524 | * get what is truly supported |
| 525 | */ |
| 526 | i40e_phy_type_to_ethtool(pf, &e_supported, |
| 527 | &e_advertising); |
| 528 | |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 529 | supported = supported & e_supported; |
| 530 | advertising = advertising & e_advertising; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 531 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 532 | /* Set speed and duplex */ |
| 533 | switch (link_speed) { |
| 534 | case I40E_LINK_SPEED_40GB: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 535 | cmd->base.speed = SPEED_40000; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 536 | break; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 537 | case I40E_LINK_SPEED_25GB: |
| 538 | #ifdef SPEED_25000 |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 539 | cmd->base.speed = SPEED_25000; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 540 | #else |
| 541 | netdev_info(netdev, |
| 542 | "Speed is 25G, display not supported by this version of ethtool.\n"); |
| 543 | #endif |
| 544 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 545 | case I40E_LINK_SPEED_20GB: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 546 | cmd->base.speed = SPEED_20000; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 547 | break; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 548 | case I40E_LINK_SPEED_10GB: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 549 | cmd->base.speed = SPEED_10000; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 550 | break; |
| 551 | case I40E_LINK_SPEED_1GB: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 552 | cmd->base.speed = SPEED_1000; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 553 | break; |
| 554 | case I40E_LINK_SPEED_100MB: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 555 | cmd->base.speed = SPEED_100; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 556 | break; |
| 557 | default: |
| 558 | break; |
| 559 | } |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 560 | cmd->base.duplex = DUPLEX_FULL; |
| 561 | |
| 562 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 563 | supported); |
| 564 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 565 | advertising); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /** |
| 569 | * i40e_get_settings_link_down - Get the Link settings for when link is down |
| 570 | * @hw: hw structure |
| 571 | * @ecmd: ethtool command to fill in |
| 572 | * |
| 573 | * Reports link settings that can be determined when link is down |
| 574 | **/ |
| 575 | static void i40e_get_settings_link_down(struct i40e_hw *hw, |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 576 | struct ethtool_link_ksettings *cmd, |
Catherine Sullivan | 3b6c217 | 2015-09-03 17:18:52 -0400 | [diff] [blame] | 577 | struct i40e_pf *pf) |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 578 | { |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 579 | u32 supported, advertising; |
| 580 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 581 | /* link is down and the driver needs to fall back on |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 582 | * supported phy types to figure out what info to display |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 583 | */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 584 | i40e_phy_type_to_ethtool(pf, &supported, &advertising); |
| 585 | |
| 586 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 587 | supported); |
| 588 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 589 | advertising); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 590 | |
| 591 | /* With no link speed and duplex are unknown */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 592 | cmd->base.speed = SPEED_UNKNOWN; |
| 593 | cmd->base.duplex = DUPLEX_UNKNOWN; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /** |
| 597 | * i40e_get_settings - Get Link Speed and Duplex settings |
| 598 | * @netdev: network interface device structure |
| 599 | * @ecmd: ethtool command |
| 600 | * |
| 601 | * Reports speed/duplex settings based on media_type |
| 602 | **/ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 603 | static int i40e_get_link_ksettings(struct net_device *netdev, |
| 604 | struct ethtool_link_ksettings *cmd) |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 605 | { |
| 606 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 607 | struct i40e_pf *pf = np->vsi->back; |
| 608 | struct i40e_hw *hw = &pf->hw; |
| 609 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
| 610 | bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 611 | u32 advertising; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 612 | |
| 613 | if (link_up) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 614 | i40e_get_settings_link_up(hw, cmd, netdev, pf); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 615 | else |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 616 | i40e_get_settings_link_down(hw, cmd, pf); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 617 | |
| 618 | /* Now set the settings that don't rely on link being up/down */ |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 619 | /* Set autoneg settings */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 620 | cmd->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 621 | AUTONEG_ENABLE : AUTONEG_DISABLE); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 622 | |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 623 | switch (hw->phy.media_type) { |
| 624 | case I40E_MEDIA_TYPE_BACKPLANE: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 625 | ethtool_link_ksettings_add_link_mode(cmd, supported, |
| 626 | Autoneg); |
| 627 | ethtool_link_ksettings_add_link_mode(cmd, supported, |
| 628 | Backplane); |
| 629 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 630 | Autoneg); |
| 631 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 632 | Backplane); |
| 633 | cmd->base.port = PORT_NONE; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 634 | break; |
| 635 | case I40E_MEDIA_TYPE_BASET: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 636 | ethtool_link_ksettings_add_link_mode(cmd, supported, TP); |
| 637 | ethtool_link_ksettings_add_link_mode(cmd, advertising, TP); |
| 638 | cmd->base.port = PORT_TP; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 639 | break; |
| 640 | case I40E_MEDIA_TYPE_DA: |
| 641 | case I40E_MEDIA_TYPE_CX4: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 642 | ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE); |
| 643 | ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE); |
| 644 | cmd->base.port = PORT_DA; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 645 | break; |
| 646 | case I40E_MEDIA_TYPE_FIBER: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 647 | ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE); |
| 648 | cmd->base.port = PORT_FIBRE; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 649 | break; |
| 650 | case I40E_MEDIA_TYPE_UNKNOWN: |
| 651 | default: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 652 | cmd->base.port = PORT_OTHER; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 653 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 656 | /* Set flow control settings */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 657 | ethtool_link_ksettings_add_link_mode(cmd, supported, Pause); |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 658 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 659 | switch (hw->fc.requested_mode) { |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 660 | case I40E_FC_FULL: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 661 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 662 | Pause); |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 663 | break; |
| 664 | case I40E_FC_TX_PAUSE: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 665 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 666 | Asym_Pause); |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 667 | break; |
| 668 | case I40E_FC_RX_PAUSE: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 669 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 670 | Pause); |
| 671 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 672 | Asym_Pause); |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 673 | break; |
| 674 | default: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 675 | ethtool_convert_link_mode_to_legacy_u32( |
| 676 | &advertising, cmd->link_modes.advertising); |
| 677 | |
| 678 | advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 679 | |
| 680 | ethtool_convert_legacy_u32_to_link_mode( |
| 681 | cmd->link_modes.advertising, advertising); |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 682 | break; |
| 683 | } |
| 684 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 685 | return 0; |
| 686 | } |
| 687 | |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 688 | /** |
| 689 | * i40e_set_settings - Set Speed and Duplex |
| 690 | * @netdev: network interface device structure |
| 691 | * @ecmd: ethtool command |
| 692 | * |
| 693 | * Set speed/duplex per media_types advertised/forced |
| 694 | **/ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 695 | static int i40e_set_link_ksettings(struct net_device *netdev, |
| 696 | const struct ethtool_link_ksettings *cmd) |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 697 | { |
| 698 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 699 | struct i40e_aq_get_phy_abilities_resp abilities; |
| 700 | struct i40e_aq_set_phy_config config; |
| 701 | struct i40e_pf *pf = np->vsi->back; |
| 702 | struct i40e_vsi *vsi = np->vsi; |
| 703 | struct i40e_hw *hw = &pf->hw; |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 704 | struct ethtool_link_ksettings safe_cmd; |
| 705 | struct ethtool_link_ksettings copy_cmd; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 706 | i40e_status status = 0; |
| 707 | bool change = false; |
| 708 | int err = 0; |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 709 | u32 autoneg; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 710 | u32 advertise; |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 711 | u32 tmp; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 712 | |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 713 | /* Changing port settings is not supported if this isn't the |
| 714 | * port's controlling PF |
| 715 | */ |
| 716 | if (hw->partition_id != 1) { |
| 717 | i40e_partition_setting_complaint(pf); |
| 718 | return -EOPNOTSUPP; |
| 719 | } |
| 720 | |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 721 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 722 | return -EOPNOTSUPP; |
| 723 | |
| 724 | if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET && |
| 725 | hw->phy.media_type != I40E_MEDIA_TYPE_FIBER && |
Catherine Sullivan | c57e9f1 | 2014-07-12 07:28:13 +0000 | [diff] [blame] | 726 | hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE && |
Serey Kong | 6536227 | 2016-05-16 10:26:39 -0700 | [diff] [blame] | 727 | hw->phy.media_type != I40E_MEDIA_TYPE_DA && |
Catherine Sullivan | c57e9f1 | 2014-07-12 07:28:13 +0000 | [diff] [blame] | 728 | hw->phy.link_info.link_info & I40E_AQ_LINK_UP) |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 729 | return -EOPNOTSUPP; |
| 730 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 731 | if (hw->device_id == I40E_DEV_ID_KX_B || |
| 732 | hw->device_id == I40E_DEV_ID_KX_C || |
| 733 | hw->device_id == I40E_DEV_ID_20G_KR2 || |
| 734 | hw->device_id == I40E_DEV_ID_20G_KR2_A) { |
| 735 | netdev_info(netdev, "Changing settings is not supported on backplane.\n"); |
| 736 | return -EOPNOTSUPP; |
| 737 | } |
| 738 | |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 739 | /* copy the cmd to copy_cmd to avoid modifying the origin */ |
| 740 | memcpy(©_cmd, cmd, sizeof(struct ethtool_link_ksettings)); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 741 | |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 742 | /* get our own copy of the bits to check against */ |
| 743 | memset(&safe_cmd, 0, sizeof(struct ethtool_link_ksettings)); |
| 744 | i40e_get_link_ksettings(netdev, &safe_cmd); |
| 745 | |
| 746 | /* save autoneg and speed out of cmd */ |
| 747 | autoneg = cmd->base.autoneg; |
| 748 | ethtool_convert_link_mode_to_legacy_u32(&advertise, |
| 749 | cmd->link_modes.advertising); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 750 | |
| 751 | /* set autoneg and speed back to what they currently are */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 752 | copy_cmd.base.autoneg = safe_cmd.base.autoneg; |
| 753 | ethtool_convert_link_mode_to_legacy_u32( |
| 754 | &tmp, safe_cmd.link_modes.advertising); |
| 755 | ethtool_convert_legacy_u32_to_link_mode( |
| 756 | copy_cmd.link_modes.advertising, tmp); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 757 | |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 758 | copy_cmd.base.cmd = safe_cmd.base.cmd; |
| 759 | |
| 760 | /* If copy_cmd and safe_cmd are not the same now, then they are |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 761 | * trying to set something that we do not support |
| 762 | */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 763 | if (memcmp(©_cmd, &safe_cmd, sizeof(struct ethtool_link_ksettings))) |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 764 | return -EOPNOTSUPP; |
| 765 | |
| 766 | while (test_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 767 | usleep_range(1000, 2000); |
| 768 | |
| 769 | /* Get the current phy config */ |
| 770 | status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, |
| 771 | NULL); |
| 772 | if (status) |
| 773 | return -EAGAIN; |
| 774 | |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 775 | /* Copy abilities to config in case autoneg is not |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 776 | * set below |
| 777 | */ |
| 778 | memset(&config, 0, sizeof(struct i40e_aq_set_phy_config)); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 779 | config.abilities = abilities.abilities; |
| 780 | |
| 781 | /* Check autoneg */ |
| 782 | if (autoneg == AUTONEG_ENABLE) { |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 783 | /* If autoneg was not already enabled */ |
| 784 | if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) { |
Catherine Sullivan | 3ce12ee | 2015-09-28 14:16:58 -0400 | [diff] [blame] | 785 | /* If autoneg is not supported, return error */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 786 | if (!ethtool_link_ksettings_test_link_mode( |
| 787 | &safe_cmd, supported, Autoneg)) { |
Catherine Sullivan | 3ce12ee | 2015-09-28 14:16:58 -0400 | [diff] [blame] | 788 | netdev_info(netdev, "Autoneg not supported on this phy\n"); |
| 789 | return -EINVAL; |
| 790 | } |
| 791 | /* Autoneg is allowed to change */ |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 792 | config.abilities = abilities.abilities | |
| 793 | I40E_AQ_PHY_ENABLE_AN; |
| 794 | change = true; |
| 795 | } |
| 796 | } else { |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 797 | /* If autoneg is currently enabled */ |
| 798 | if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) { |
Catherine Sullivan | 3ce12ee | 2015-09-28 14:16:58 -0400 | [diff] [blame] | 799 | /* If autoneg is supported 10GBASE_T is the only PHY |
| 800 | * that can disable it, so otherwise return error |
| 801 | */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 802 | if (ethtool_link_ksettings_test_link_mode( |
| 803 | &safe_cmd, supported, Autoneg) && |
Catherine Sullivan | 3ce12ee | 2015-09-28 14:16:58 -0400 | [diff] [blame] | 804 | hw->phy.link_info.phy_type != |
| 805 | I40E_PHY_TYPE_10GBASE_T) { |
| 806 | netdev_info(netdev, "Autoneg cannot be disabled on this phy\n"); |
| 807 | return -EINVAL; |
| 808 | } |
| 809 | /* Autoneg is allowed to change */ |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 810 | config.abilities = abilities.abilities & |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 811 | ~I40E_AQ_PHY_ENABLE_AN; |
| 812 | change = true; |
| 813 | } |
| 814 | } |
| 815 | |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 816 | ethtool_convert_link_mode_to_legacy_u32(&tmp, |
| 817 | safe_cmd.link_modes.supported); |
| 818 | if (advertise & ~tmp) |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 819 | return -EINVAL; |
| 820 | |
| 821 | if (advertise & ADVERTISED_100baseT_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 822 | config.link_speed |= I40E_LINK_SPEED_100MB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 823 | if (advertise & ADVERTISED_1000baseT_Full || |
| 824 | advertise & ADVERTISED_1000baseKX_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 825 | config.link_speed |= I40E_LINK_SPEED_1GB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 826 | if (advertise & ADVERTISED_10000baseT_Full || |
| 827 | advertise & ADVERTISED_10000baseKX4_Full || |
| 828 | advertise & ADVERTISED_10000baseKR_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 829 | config.link_speed |= I40E_LINK_SPEED_10GB; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 830 | if (advertise & ADVERTISED_20000baseKR2_Full) |
| 831 | config.link_speed |= I40E_LINK_SPEED_20GB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 832 | if (advertise & ADVERTISED_40000baseKR4_Full || |
| 833 | advertise & ADVERTISED_40000baseCR4_Full || |
| 834 | advertise & ADVERTISED_40000baseSR4_Full || |
| 835 | advertise & ADVERTISED_40000baseLR4_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 836 | config.link_speed |= I40E_LINK_SPEED_40GB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 837 | |
Catherine Sullivan | 0002e11 | 2015-08-26 15:14:16 -0400 | [diff] [blame] | 838 | /* If speed didn't get set, set it to what it currently is. |
| 839 | * This is needed because if advertise is 0 (as it is when autoneg |
| 840 | * is disabled) then speed won't get set. |
| 841 | */ |
| 842 | if (!config.link_speed) |
| 843 | config.link_speed = abilities.link_speed; |
| 844 | |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 845 | if (change || (abilities.link_speed != config.link_speed)) { |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 846 | /* copy over the rest of the abilities */ |
| 847 | config.phy_type = abilities.phy_type; |
Henry Tieman | b7eaf8f | 2016-12-02 12:33:01 -0800 | [diff] [blame] | 848 | config.phy_type_ext = abilities.phy_type_ext; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 849 | config.eee_capability = abilities.eee_capability; |
| 850 | config.eeer = abilities.eeer_val; |
| 851 | config.low_power_ctrl = abilities.d3_lpan; |
Henry Tieman | b7eaf8f | 2016-12-02 12:33:01 -0800 | [diff] [blame] | 852 | config.fec_config = abilities.fec_cfg_curr_mod_ext_info & |
| 853 | I40E_AQ_PHY_FEC_CONFIG_MASK; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 854 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 855 | /* save the requested speeds */ |
| 856 | hw->phy.link_info.requested_speeds = config.link_speed; |
Catherine Sullivan | 9412851 | 2014-07-12 07:28:16 +0000 | [diff] [blame] | 857 | /* set link and auto negotiation so changes take effect */ |
| 858 | config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK; |
| 859 | /* If link is up put link down */ |
| 860 | if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) { |
| 861 | /* Tell the OS link is going down, the link will go |
| 862 | * back up when fw says it is ready asynchronously |
| 863 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 864 | i40e_print_link_message(vsi, false); |
Catherine Sullivan | 9412851 | 2014-07-12 07:28:16 +0000 | [diff] [blame] | 865 | netif_carrier_off(netdev); |
| 866 | netif_tx_stop_all_queues(netdev); |
| 867 | } |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 868 | |
| 869 | /* make the aq call */ |
| 870 | status = i40e_aq_set_phy_config(hw, &config, NULL); |
| 871 | if (status) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 872 | netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n", |
| 873 | i40e_stat_str(hw, status), |
| 874 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 875 | return -EAGAIN; |
| 876 | } |
| 877 | |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 878 | status = i40e_update_link_info(hw); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 879 | if (status) |
Catherine Sullivan | 52e9689 | 2015-09-28 14:16:59 -0400 | [diff] [blame] | 880 | netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n", |
| 881 | i40e_stat_str(hw, status), |
| 882 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 883 | |
| 884 | } else { |
| 885 | netdev_info(netdev, "Nothing changed, exiting without setting anything.\n"); |
| 886 | } |
| 887 | |
| 888 | return err; |
| 889 | } |
| 890 | |
Jesse Brandeburg | a659972 | 2014-06-04 08:45:25 +0000 | [diff] [blame] | 891 | static int i40e_nway_reset(struct net_device *netdev) |
| 892 | { |
| 893 | /* restart autonegotiation */ |
| 894 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 895 | struct i40e_pf *pf = np->vsi->back; |
| 896 | struct i40e_hw *hw = &pf->hw; |
| 897 | bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP; |
| 898 | i40e_status ret = 0; |
| 899 | |
| 900 | ret = i40e_aq_set_link_restart_an(hw, link_up, NULL); |
| 901 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 902 | netdev_info(netdev, "link restart failed, err %s aq_err %s\n", |
| 903 | i40e_stat_str(hw, ret), |
| 904 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | a659972 | 2014-06-04 08:45:25 +0000 | [diff] [blame] | 905 | return -EIO; |
| 906 | } |
| 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 911 | /** |
| 912 | * i40e_get_pauseparam - Get Flow Control status |
| 913 | * Return tx/rx-pause status |
| 914 | **/ |
| 915 | static void i40e_get_pauseparam(struct net_device *netdev, |
| 916 | struct ethtool_pauseparam *pause) |
| 917 | { |
| 918 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 919 | struct i40e_pf *pf = np->vsi->back; |
| 920 | struct i40e_hw *hw = &pf->hw; |
| 921 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
Neerav Parikh | 4b7698c | 2014-11-12 00:18:57 +0000 | [diff] [blame] | 922 | struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 923 | |
| 924 | pause->autoneg = |
| 925 | ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
| 926 | AUTONEG_ENABLE : AUTONEG_DISABLE); |
| 927 | |
Neerav Parikh | 4b7698c | 2014-11-12 00:18:57 +0000 | [diff] [blame] | 928 | /* PFC enabled so report LFC as off */ |
| 929 | if (dcbx_cfg->pfc.pfcenable) { |
| 930 | pause->rx_pause = 0; |
| 931 | pause->tx_pause = 0; |
| 932 | return; |
| 933 | } |
| 934 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 935 | if (hw->fc.current_mode == I40E_FC_RX_PAUSE) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 936 | pause->rx_pause = 1; |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 937 | } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 938 | pause->tx_pause = 1; |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 939 | } else if (hw->fc.current_mode == I40E_FC_FULL) { |
| 940 | pause->rx_pause = 1; |
| 941 | pause->tx_pause = 1; |
| 942 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 943 | } |
| 944 | |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 945 | /** |
| 946 | * i40e_set_pauseparam - Set Flow Control parameter |
| 947 | * @netdev: network interface device structure |
| 948 | * @pause: return tx/rx flow control status |
| 949 | **/ |
| 950 | static int i40e_set_pauseparam(struct net_device *netdev, |
| 951 | struct ethtool_pauseparam *pause) |
| 952 | { |
| 953 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 954 | struct i40e_pf *pf = np->vsi->back; |
| 955 | struct i40e_vsi *vsi = np->vsi; |
| 956 | struct i40e_hw *hw = &pf->hw; |
| 957 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
Neerav Parikh | 4b7698c | 2014-11-12 00:18:57 +0000 | [diff] [blame] | 958 | struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config; |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 959 | bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; |
| 960 | i40e_status status; |
| 961 | u8 aq_failures; |
Catherine Sullivan | 7d62dac | 2014-07-09 07:46:18 +0000 | [diff] [blame] | 962 | int err = 0; |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 963 | |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 964 | /* Changing the port's flow control is not supported if this isn't the |
| 965 | * port's controlling PF |
| 966 | */ |
| 967 | if (hw->partition_id != 1) { |
| 968 | i40e_partition_setting_complaint(pf); |
| 969 | return -EOPNOTSUPP; |
| 970 | } |
| 971 | |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 972 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 973 | return -EOPNOTSUPP; |
| 974 | |
| 975 | if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
| 976 | AUTONEG_ENABLE : AUTONEG_DISABLE)) { |
| 977 | netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n"); |
| 978 | return -EOPNOTSUPP; |
| 979 | } |
| 980 | |
| 981 | /* If we have link and don't have autoneg */ |
| 982 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 983 | !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) { |
| 984 | /* Send message that it might not necessarily work*/ |
| 985 | netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n"); |
| 986 | } |
| 987 | |
Neerav Parikh | 4b7698c | 2014-11-12 00:18:57 +0000 | [diff] [blame] | 988 | if (dcbx_cfg->pfc.pfcenable) { |
| 989 | netdev_info(netdev, |
| 990 | "Priority flow control enabled. Cannot set link flow control.\n"); |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 991 | return -EOPNOTSUPP; |
| 992 | } |
| 993 | |
| 994 | if (pause->rx_pause && pause->tx_pause) |
| 995 | hw->fc.requested_mode = I40E_FC_FULL; |
| 996 | else if (pause->rx_pause && !pause->tx_pause) |
| 997 | hw->fc.requested_mode = I40E_FC_RX_PAUSE; |
| 998 | else if (!pause->rx_pause && pause->tx_pause) |
| 999 | hw->fc.requested_mode = I40E_FC_TX_PAUSE; |
| 1000 | else if (!pause->rx_pause && !pause->tx_pause) |
| 1001 | hw->fc.requested_mode = I40E_FC_NONE; |
| 1002 | else |
| 1003 | return -EINVAL; |
| 1004 | |
Catherine Sullivan | 9412851 | 2014-07-12 07:28:16 +0000 | [diff] [blame] | 1005 | /* Tell the OS link is going down, the link will go back up when fw |
| 1006 | * says it is ready asynchronously |
| 1007 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 1008 | i40e_print_link_message(vsi, false); |
Catherine Sullivan | 9412851 | 2014-07-12 07:28:16 +0000 | [diff] [blame] | 1009 | netif_carrier_off(netdev); |
| 1010 | netif_tx_stop_all_queues(netdev); |
| 1011 | |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 1012 | /* Set the fc mode and only restart an if link is up*/ |
| 1013 | status = i40e_set_fc(hw, &aq_failures, link_up); |
| 1014 | |
| 1015 | if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1016 | netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n", |
| 1017 | i40e_stat_str(hw, status), |
| 1018 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 1019 | err = -EAGAIN; |
| 1020 | } |
| 1021 | if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1022 | netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n", |
| 1023 | i40e_stat_str(hw, status), |
| 1024 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 1025 | err = -EAGAIN; |
| 1026 | } |
| 1027 | if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1028 | netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n", |
| 1029 | i40e_stat_str(hw, status), |
| 1030 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 1031 | err = -EAGAIN; |
| 1032 | } |
| 1033 | |
Catherine Sullivan | 7d62dac | 2014-07-09 07:46:18 +0000 | [diff] [blame] | 1034 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 1035 | /* Give it a little more time to try to come back */ |
| 1036 | msleep(75); |
| 1037 | if (!test_bit(__I40E_DOWN, &pf->state)) |
| 1038 | return i40e_nway_reset(netdev); |
| 1039 | } |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 1040 | |
| 1041 | return err; |
| 1042 | } |
| 1043 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1044 | static u32 i40e_get_msglevel(struct net_device *netdev) |
| 1045 | { |
| 1046 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1047 | struct i40e_pf *pf = np->vsi->back; |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 1048 | u32 debug_mask = pf->hw.debug_mask; |
| 1049 | |
| 1050 | if (debug_mask) |
| 1051 | netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1052 | |
| 1053 | return pf->msg_enable; |
| 1054 | } |
| 1055 | |
| 1056 | static void i40e_set_msglevel(struct net_device *netdev, u32 data) |
| 1057 | { |
| 1058 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1059 | struct i40e_pf *pf = np->vsi->back; |
| 1060 | |
| 1061 | if (I40E_DEBUG_USER & data) |
| 1062 | pf->hw.debug_mask = data; |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 1063 | else |
| 1064 | pf->msg_enable = data; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | static int i40e_get_regs_len(struct net_device *netdev) |
| 1068 | { |
| 1069 | int reg_count = 0; |
| 1070 | int i; |
| 1071 | |
| 1072 | for (i = 0; i40e_reg_list[i].offset != 0; i++) |
| 1073 | reg_count += i40e_reg_list[i].elements; |
| 1074 | |
| 1075 | return reg_count * sizeof(u32); |
| 1076 | } |
| 1077 | |
| 1078 | static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs, |
| 1079 | void *p) |
| 1080 | { |
| 1081 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1082 | struct i40e_pf *pf = np->vsi->back; |
| 1083 | struct i40e_hw *hw = &pf->hw; |
| 1084 | u32 *reg_buf = p; |
| 1085 | int i, j, ri; |
| 1086 | u32 reg; |
| 1087 | |
| 1088 | /* Tell ethtool which driver-version-specific regs output we have. |
| 1089 | * |
| 1090 | * At some point, if we have ethtool doing special formatting of |
| 1091 | * this data, it will rely on this version number to know how to |
| 1092 | * interpret things. Hence, this needs to be updated if/when the |
| 1093 | * diags register table is changed. |
| 1094 | */ |
| 1095 | regs->version = 1; |
| 1096 | |
| 1097 | /* loop through the diags reg table for what to print */ |
| 1098 | ri = 0; |
| 1099 | for (i = 0; i40e_reg_list[i].offset != 0; i++) { |
| 1100 | for (j = 0; j < i40e_reg_list[i].elements; j++) { |
| 1101 | reg = i40e_reg_list[i].offset |
| 1102 | + (j * i40e_reg_list[i].stride); |
| 1103 | reg_buf[ri++] = rd32(hw, reg); |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | } |
| 1108 | |
| 1109 | static int i40e_get_eeprom(struct net_device *netdev, |
| 1110 | struct ethtool_eeprom *eeprom, u8 *bytes) |
| 1111 | { |
| 1112 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1113 | struct i40e_hw *hw = &np->vsi->back->hw; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1114 | struct i40e_pf *pf = np->vsi->back; |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1115 | int ret_val = 0, len, offset; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1116 | u8 *eeprom_buff; |
| 1117 | u16 i, sectors; |
| 1118 | bool last; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1119 | u32 magic; |
| 1120 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1121 | #define I40E_NVM_SECTOR_SIZE 4096 |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1122 | if (eeprom->len == 0) |
| 1123 | return -EINVAL; |
| 1124 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1125 | /* check for NVMUpdate access method */ |
| 1126 | magic = hw->vendor_id | (hw->device_id << 16); |
| 1127 | if (eeprom->magic && eeprom->magic != magic) { |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1128 | struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom; |
| 1129 | int errno = 0; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1130 | |
| 1131 | /* make sure it is the right magic for NVMUpdate */ |
| 1132 | if ((eeprom->magic >> 16) != hw->device_id) |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1133 | errno = -EINVAL; |
| 1134 | else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 1135 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 1136 | errno = -EBUSY; |
| 1137 | else |
| 1138 | ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1139 | |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1140 | if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM)) |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1141 | dev_info(&pf->pdev->dev, |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1142 | "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n", |
| 1143 | ret_val, hw->aq.asq_last_status, errno, |
| 1144 | (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK), |
| 1145 | cmd->offset, cmd->data_size); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1146 | |
| 1147 | return errno; |
| 1148 | } |
| 1149 | |
| 1150 | /* normal ethtool get_eeprom support */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1151 | eeprom->magic = hw->vendor_id | (hw->device_id << 16); |
| 1152 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1153 | eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1154 | if (!eeprom_buff) |
| 1155 | return -ENOMEM; |
| 1156 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1157 | ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ); |
| 1158 | if (ret_val) { |
| 1159 | dev_info(&pf->pdev->dev, |
| 1160 | "Failed Acquiring NVM resource for read err=%d status=0x%x\n", |
| 1161 | ret_val, hw->aq.asq_last_status); |
| 1162 | goto free_buff; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1165 | sectors = eeprom->len / I40E_NVM_SECTOR_SIZE; |
| 1166 | sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0; |
| 1167 | len = I40E_NVM_SECTOR_SIZE; |
| 1168 | last = false; |
| 1169 | for (i = 0; i < sectors; i++) { |
| 1170 | if (i == (sectors - 1)) { |
| 1171 | len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i); |
| 1172 | last = true; |
| 1173 | } |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1174 | offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i), |
| 1175 | ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len, |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1176 | (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i), |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1177 | last, NULL); |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1178 | if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) { |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1179 | dev_info(&pf->pdev->dev, |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1180 | "read NVM failed, invalid offset 0x%x\n", |
| 1181 | offset); |
| 1182 | break; |
| 1183 | } else if (ret_val && |
| 1184 | hw->aq.asq_last_status == I40E_AQ_RC_EACCES) { |
| 1185 | dev_info(&pf->pdev->dev, |
| 1186 | "read NVM failed, access, offset 0x%x\n", |
| 1187 | offset); |
| 1188 | break; |
| 1189 | } else if (ret_val) { |
| 1190 | dev_info(&pf->pdev->dev, |
| 1191 | "read NVM failed offset %d err=%d status=0x%x\n", |
| 1192 | offset, ret_val, hw->aq.asq_last_status); |
| 1193 | break; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1194 | } |
| 1195 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1196 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1197 | i40e_release_nvm(hw); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1198 | memcpy(bytes, (u8 *)eeprom_buff, eeprom->len); |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1199 | free_buff: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1200 | kfree(eeprom_buff); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1201 | return ret_val; |
| 1202 | } |
| 1203 | |
| 1204 | static int i40e_get_eeprom_len(struct net_device *netdev) |
| 1205 | { |
| 1206 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1207 | struct i40e_hw *hw = &np->vsi->back->hw; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1208 | u32 val; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1209 | |
Lihong Yang | c271dd6 | 2017-01-30 12:29:32 -0800 | [diff] [blame] | 1210 | #define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF |
| 1211 | if (hw->mac.type == I40E_MAC_X722) { |
| 1212 | val = X722_EEPROM_SCOPE_LIMIT + 1; |
| 1213 | return val; |
| 1214 | } |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1215 | val = (rd32(hw, I40E_GLPCI_LBARCTRL) |
| 1216 | & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK) |
| 1217 | >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT; |
| 1218 | /* register returns value in power of 2, 64Kbyte chunks. */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1219 | val = (64 * 1024) * BIT(val); |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1220 | return val; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1223 | static int i40e_set_eeprom(struct net_device *netdev, |
| 1224 | struct ethtool_eeprom *eeprom, u8 *bytes) |
| 1225 | { |
| 1226 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1227 | struct i40e_hw *hw = &np->vsi->back->hw; |
| 1228 | struct i40e_pf *pf = np->vsi->back; |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1229 | struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1230 | int ret_val = 0; |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1231 | int errno = 0; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1232 | u32 magic; |
| 1233 | |
| 1234 | /* normal ethtool set_eeprom is not supported */ |
| 1235 | magic = hw->vendor_id | (hw->device_id << 16); |
| 1236 | if (eeprom->magic == magic) |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1237 | errno = -EOPNOTSUPP; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1238 | /* check for NVMUpdate access method */ |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1239 | else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id) |
| 1240 | errno = -EINVAL; |
| 1241 | else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 1242 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 1243 | errno = -EBUSY; |
| 1244 | else |
| 1245 | ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1246 | |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1247 | if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM)) |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1248 | dev_info(&pf->pdev->dev, |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1249 | "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n", |
| 1250 | ret_val, hw->aq.asq_last_status, errno, |
| 1251 | (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK), |
| 1252 | cmd->offset, cmd->data_size); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1253 | |
| 1254 | return errno; |
| 1255 | } |
| 1256 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1257 | static void i40e_get_drvinfo(struct net_device *netdev, |
| 1258 | struct ethtool_drvinfo *drvinfo) |
| 1259 | { |
| 1260 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1261 | struct i40e_vsi *vsi = np->vsi; |
| 1262 | struct i40e_pf *pf = vsi->back; |
| 1263 | |
| 1264 | strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver)); |
| 1265 | strlcpy(drvinfo->version, i40e_driver_version_str, |
| 1266 | sizeof(drvinfo->version)); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 1267 | strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1268 | sizeof(drvinfo->fw_version)); |
| 1269 | strlcpy(drvinfo->bus_info, pci_name(pf->pdev), |
| 1270 | sizeof(drvinfo->bus_info)); |
Jacob Keller | d182a5c | 2016-10-25 16:08:50 -0700 | [diff] [blame] | 1271 | drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN; |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 1272 | if (pf->hw.pf_id == 0) |
Jacob Keller | d182a5c | 2016-10-25 16:08:50 -0700 | [diff] [blame] | 1273 | drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | static void i40e_get_ringparam(struct net_device *netdev, |
| 1277 | struct ethtool_ringparam *ring) |
| 1278 | { |
| 1279 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1280 | struct i40e_pf *pf = np->vsi->back; |
| 1281 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 1282 | |
| 1283 | ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS; |
| 1284 | ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS; |
| 1285 | ring->rx_mini_max_pending = 0; |
| 1286 | ring->rx_jumbo_max_pending = 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1287 | ring->rx_pending = vsi->rx_rings[0]->count; |
| 1288 | ring->tx_pending = vsi->tx_rings[0]->count; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1289 | ring->rx_mini_pending = 0; |
| 1290 | ring->rx_jumbo_pending = 0; |
| 1291 | } |
| 1292 | |
| 1293 | static int i40e_set_ringparam(struct net_device *netdev, |
| 1294 | struct ethtool_ringparam *ring) |
| 1295 | { |
| 1296 | struct i40e_ring *tx_rings = NULL, *rx_rings = NULL; |
| 1297 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Tushar Dave | 2f7679e | 2016-10-26 10:49:27 -0700 | [diff] [blame] | 1298 | struct i40e_hw *hw = &np->vsi->back->hw; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1299 | struct i40e_vsi *vsi = np->vsi; |
| 1300 | struct i40e_pf *pf = vsi->back; |
| 1301 | u32 new_rx_count, new_tx_count; |
| 1302 | int i, err = 0; |
| 1303 | |
| 1304 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 1305 | return -EINVAL; |
| 1306 | |
Shannon Nelson | 1fa1837 | 2013-11-20 10:03:08 +0000 | [diff] [blame] | 1307 | if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS || |
| 1308 | ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS || |
| 1309 | ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS || |
| 1310 | ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) { |
| 1311 | netdev_info(netdev, |
| 1312 | "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n", |
| 1313 | ring->tx_pending, ring->rx_pending, |
| 1314 | I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS); |
| 1315 | return -EINVAL; |
| 1316 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1317 | |
Shannon Nelson | 1fa1837 | 2013-11-20 10:03:08 +0000 | [diff] [blame] | 1318 | new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 1319 | new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1320 | |
| 1321 | /* if nothing to do return success */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1322 | if ((new_tx_count == vsi->tx_rings[0]->count) && |
| 1323 | (new_rx_count == vsi->rx_rings[0]->count)) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1324 | return 0; |
| 1325 | |
| 1326 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 1327 | usleep_range(1000, 2000); |
| 1328 | |
| 1329 | if (!netif_running(vsi->netdev)) { |
| 1330 | /* simple case - set for the next time the netdev is started */ |
| 1331 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1332 | vsi->tx_rings[i]->count = new_tx_count; |
| 1333 | vsi->rx_rings[i]->count = new_rx_count; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1334 | } |
| 1335 | goto done; |
| 1336 | } |
| 1337 | |
| 1338 | /* We can't just free everything and then setup again, |
| 1339 | * because the ISRs in MSI-X mode get passed pointers |
| 1340 | * to the Tx and Rx ring structs. |
| 1341 | */ |
| 1342 | |
| 1343 | /* alloc updated Tx resources */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1344 | if (new_tx_count != vsi->tx_rings[0]->count) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1345 | netdev_info(netdev, |
| 1346 | "Changing Tx descriptor count from %d to %d.\n", |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1347 | vsi->tx_rings[0]->count, new_tx_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1348 | tx_rings = kcalloc(vsi->alloc_queue_pairs, |
| 1349 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 1350 | if (!tx_rings) { |
| 1351 | err = -ENOMEM; |
| 1352 | goto done; |
| 1353 | } |
| 1354 | |
| 1355 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 1356 | /* clone ring and setup updated count */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1357 | tx_rings[i] = *vsi->tx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1358 | tx_rings[i].count = new_tx_count; |
Jesse Brandeburg | 1e8efb4 | 2015-08-27 11:42:33 -0400 | [diff] [blame] | 1359 | /* the desc and bi pointers will be reallocated in the |
| 1360 | * setup call |
| 1361 | */ |
| 1362 | tx_rings[i].desc = NULL; |
| 1363 | tx_rings[i].rx_bi = NULL; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1364 | err = i40e_setup_tx_descriptors(&tx_rings[i]); |
| 1365 | if (err) { |
| 1366 | while (i) { |
| 1367 | i--; |
| 1368 | i40e_free_tx_resources(&tx_rings[i]); |
| 1369 | } |
| 1370 | kfree(tx_rings); |
| 1371 | tx_rings = NULL; |
| 1372 | |
| 1373 | goto done; |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | /* alloc updated Rx resources */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1379 | if (new_rx_count != vsi->rx_rings[0]->count) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1380 | netdev_info(netdev, |
| 1381 | "Changing Rx descriptor count from %d to %d\n", |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1382 | vsi->rx_rings[0]->count, new_rx_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1383 | rx_rings = kcalloc(vsi->alloc_queue_pairs, |
| 1384 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 1385 | if (!rx_rings) { |
| 1386 | err = -ENOMEM; |
| 1387 | goto free_tx; |
| 1388 | } |
| 1389 | |
| 1390 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 147e81e | 2016-04-18 11:33:49 -0700 | [diff] [blame] | 1391 | struct i40e_ring *ring; |
| 1392 | u16 unused; |
| 1393 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1394 | /* clone ring and setup updated count */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1395 | rx_rings[i] = *vsi->rx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1396 | rx_rings[i].count = new_rx_count; |
Jesse Brandeburg | 1e8efb4 | 2015-08-27 11:42:33 -0400 | [diff] [blame] | 1397 | /* the desc and bi pointers will be reallocated in the |
| 1398 | * setup call |
| 1399 | */ |
| 1400 | rx_rings[i].desc = NULL; |
| 1401 | rx_rings[i].rx_bi = NULL; |
Tushar Dave | 2f7679e | 2016-10-26 10:49:27 -0700 | [diff] [blame] | 1402 | /* this is to allow wr32 to have something to write to |
| 1403 | * during early allocation of Rx buffers |
| 1404 | */ |
| 1405 | rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1406 | err = i40e_setup_rx_descriptors(&rx_rings[i]); |
Jesse Brandeburg | 147e81e | 2016-04-18 11:33:49 -0700 | [diff] [blame] | 1407 | if (err) |
| 1408 | goto rx_unwind; |
| 1409 | |
| 1410 | /* now allocate the Rx buffers to make sure the OS |
| 1411 | * has enough memory, any failure here means abort |
| 1412 | */ |
| 1413 | ring = &rx_rings[i]; |
| 1414 | unused = I40E_DESC_UNUSED(ring); |
| 1415 | err = i40e_alloc_rx_buffers(ring, unused); |
| 1416 | rx_unwind: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1417 | if (err) { |
Jesse Brandeburg | 147e81e | 2016-04-18 11:33:49 -0700 | [diff] [blame] | 1418 | do { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1419 | i40e_free_rx_resources(&rx_rings[i]); |
Jesse Brandeburg | 147e81e | 2016-04-18 11:33:49 -0700 | [diff] [blame] | 1420 | } while (i--); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1421 | kfree(rx_rings); |
| 1422 | rx_rings = NULL; |
| 1423 | |
| 1424 | goto free_tx; |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | /* Bring interface down, copy in the new ring info, |
| 1430 | * then restore the interface |
| 1431 | */ |
| 1432 | i40e_down(vsi); |
| 1433 | |
| 1434 | if (tx_rings) { |
| 1435 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1436 | i40e_free_tx_resources(vsi->tx_rings[i]); |
| 1437 | *vsi->tx_rings[i] = tx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1438 | } |
| 1439 | kfree(tx_rings); |
| 1440 | tx_rings = NULL; |
| 1441 | } |
| 1442 | |
| 1443 | if (rx_rings) { |
| 1444 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1445 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Jesse Brandeburg | 147e81e | 2016-04-18 11:33:49 -0700 | [diff] [blame] | 1446 | /* get the real tail offset */ |
| 1447 | rx_rings[i].tail = vsi->rx_rings[i]->tail; |
| 1448 | /* this is to fake out the allocation routine |
| 1449 | * into thinking it has to realloc everything |
| 1450 | * but the recycling logic will let us re-use |
| 1451 | * the buffers allocated above |
| 1452 | */ |
| 1453 | rx_rings[i].next_to_use = 0; |
| 1454 | rx_rings[i].next_to_clean = 0; |
| 1455 | rx_rings[i].next_to_alloc = 0; |
| 1456 | /* do a struct copy */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1457 | *vsi->rx_rings[i] = rx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1458 | } |
| 1459 | kfree(rx_rings); |
| 1460 | rx_rings = NULL; |
| 1461 | } |
| 1462 | |
| 1463 | i40e_up(vsi); |
| 1464 | |
| 1465 | free_tx: |
| 1466 | /* error cleanup if the Rx allocations failed after getting Tx */ |
| 1467 | if (tx_rings) { |
| 1468 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1469 | i40e_free_tx_resources(&tx_rings[i]); |
| 1470 | kfree(tx_rings); |
| 1471 | tx_rings = NULL; |
| 1472 | } |
| 1473 | |
| 1474 | done: |
| 1475 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 1476 | |
| 1477 | return err; |
| 1478 | } |
| 1479 | |
| 1480 | static int i40e_get_sset_count(struct net_device *netdev, int sset) |
| 1481 | { |
| 1482 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1483 | struct i40e_vsi *vsi = np->vsi; |
| 1484 | struct i40e_pf *pf = vsi->back; |
| 1485 | |
| 1486 | switch (sset) { |
| 1487 | case ETH_SS_TEST: |
| 1488 | return I40E_TEST_LEN; |
| 1489 | case ETH_SS_STATS: |
Shannon Nelson | 58ce517 | 2015-02-27 09:15:26 +0000 | [diff] [blame] | 1490 | if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) { |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1491 | int len = I40E_PF_STATS_LEN(netdev); |
| 1492 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 1493 | if ((pf->lan_veb != I40E_NO_VEB) && |
| 1494 | (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1495 | len += I40E_VEB_STATS_TOTAL; |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1496 | return len; |
| 1497 | } else { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1498 | return I40E_VSI_STATS_LEN(netdev); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1499 | } |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 1500 | case ETH_SS_PRIV_FLAGS: |
Jacob Keller | d182a5c | 2016-10-25 16:08:50 -0700 | [diff] [blame] | 1501 | return I40E_PRIV_FLAGS_STR_LEN + |
| 1502 | (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1503 | default: |
| 1504 | return -EOPNOTSUPP; |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | static void i40e_get_ethtool_stats(struct net_device *netdev, |
| 1509 | struct ethtool_stats *stats, u64 *data) |
| 1510 | { |
| 1511 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 1512 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1513 | struct i40e_vsi *vsi = np->vsi; |
| 1514 | struct i40e_pf *pf = vsi->back; |
| 1515 | int i = 0; |
| 1516 | char *p; |
| 1517 | int j; |
| 1518 | struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1519 | unsigned int start; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1520 | |
| 1521 | i40e_update_stats(vsi); |
| 1522 | |
| 1523 | for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) { |
| 1524 | p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset; |
| 1525 | data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat == |
| 1526 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1527 | } |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 1528 | for (j = 0; j < I40E_MISC_STATS_LEN; j++) { |
| 1529 | p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset; |
| 1530 | data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat == |
| 1531 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1532 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1533 | #ifdef I40E_FCOE |
| 1534 | for (j = 0; j < I40E_FCOE_STATS_LEN; j++) { |
| 1535 | p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset; |
| 1536 | data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat == |
| 1537 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1538 | } |
| 1539 | #endif |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1540 | rcu_read_lock(); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1541 | for (j = 0; j < vsi->num_queue_pairs; j++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 1542 | tx_ring = ACCESS_ONCE(vsi->tx_rings[j]); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1543 | |
| 1544 | if (!tx_ring) |
| 1545 | continue; |
| 1546 | |
| 1547 | /* process Tx ring statistics */ |
| 1548 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1549 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1550 | data[i] = tx_ring->stats.packets; |
| 1551 | data[i + 1] = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1552 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1553 | i += 2; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1554 | |
| 1555 | /* Rx ring is the 2nd half of the queue pair */ |
| 1556 | rx_ring = &tx_ring[1]; |
| 1557 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1558 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1559 | data[i] = rx_ring->stats.packets; |
| 1560 | data[i + 1] = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1561 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1562 | i += 2; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1563 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1564 | rcu_read_unlock(); |
Shannon Nelson | 58ce517 | 2015-02-27 09:15:26 +0000 | [diff] [blame] | 1565 | if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1) |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1566 | return; |
| 1567 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 1568 | if ((pf->lan_veb != I40E_NO_VEB) && |
| 1569 | (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1570 | struct i40e_veb *veb = pf->veb[pf->lan_veb]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1571 | |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1572 | for (j = 0; j < I40E_VEB_STATS_LEN; j++) { |
| 1573 | p = (char *)veb; |
| 1574 | p += i40e_gstrings_veb_stats[j].stat_offset; |
| 1575 | data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat == |
| 1576 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1577 | } |
Jesse Brandeburg | 74a6c66 | 2015-10-02 19:09:34 -0700 | [diff] [blame] | 1578 | for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) { |
| 1579 | data[i++] = veb->tc_stats.tc_tx_packets[j]; |
| 1580 | data[i++] = veb->tc_stats.tc_tx_bytes[j]; |
| 1581 | data[i++] = veb->tc_stats.tc_rx_packets[j]; |
| 1582 | data[i++] = veb->tc_stats.tc_rx_bytes[j]; |
| 1583 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1584 | } |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1585 | for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) { |
| 1586 | p = (char *)pf + i40e_gstrings_stats[j].stat_offset; |
| 1587 | data[i++] = (i40e_gstrings_stats[j].sizeof_stat == |
| 1588 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1589 | } |
| 1590 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { |
| 1591 | data[i++] = pf->stats.priority_xon_tx[j]; |
| 1592 | data[i++] = pf->stats.priority_xoff_tx[j]; |
| 1593 | } |
| 1594 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { |
| 1595 | data[i++] = pf->stats.priority_xon_rx[j]; |
| 1596 | data[i++] = pf->stats.priority_xoff_rx[j]; |
| 1597 | } |
| 1598 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) |
| 1599 | data[i++] = pf->stats.priority_xon_2_xoff[j]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | static void i40e_get_strings(struct net_device *netdev, u32 stringset, |
| 1603 | u8 *data) |
| 1604 | { |
| 1605 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1606 | struct i40e_vsi *vsi = np->vsi; |
| 1607 | struct i40e_pf *pf = vsi->back; |
| 1608 | char *p = (char *)data; |
| 1609 | int i; |
| 1610 | |
| 1611 | switch (stringset) { |
| 1612 | case ETH_SS_TEST: |
Jacob Keller | e5d3220 | 2016-11-08 13:05:11 -0800 | [diff] [blame] | 1613 | memcpy(data, i40e_gstrings_test, |
| 1614 | I40E_TEST_LEN * ETH_GSTRING_LEN); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1615 | break; |
| 1616 | case ETH_SS_STATS: |
| 1617 | for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) { |
| 1618 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 1619 | i40e_gstrings_net_stats[i].stat_string); |
| 1620 | p += ETH_GSTRING_LEN; |
| 1621 | } |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 1622 | for (i = 0; i < I40E_MISC_STATS_LEN; i++) { |
| 1623 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 1624 | i40e_gstrings_misc_stats[i].stat_string); |
| 1625 | p += ETH_GSTRING_LEN; |
| 1626 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1627 | #ifdef I40E_FCOE |
| 1628 | for (i = 0; i < I40E_FCOE_STATS_LEN; i++) { |
| 1629 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 1630 | i40e_gstrings_fcoe_stats[i].stat_string); |
| 1631 | p += ETH_GSTRING_LEN; |
| 1632 | } |
| 1633 | #endif |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1634 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1635 | snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1636 | p += ETH_GSTRING_LEN; |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1637 | snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1638 | p += ETH_GSTRING_LEN; |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1639 | snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1640 | p += ETH_GSTRING_LEN; |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1641 | snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1642 | p += ETH_GSTRING_LEN; |
| 1643 | } |
Shannon Nelson | 58ce517 | 2015-02-27 09:15:26 +0000 | [diff] [blame] | 1644 | if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1) |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1645 | return; |
| 1646 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 1647 | if ((pf->lan_veb != I40E_NO_VEB) && |
| 1648 | (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1649 | for (i = 0; i < I40E_VEB_STATS_LEN; i++) { |
| 1650 | snprintf(p, ETH_GSTRING_LEN, "veb.%s", |
| 1651 | i40e_gstrings_veb_stats[i].stat_string); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1652 | p += ETH_GSTRING_LEN; |
| 1653 | } |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1654 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1655 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1656 | "veb.tc_%d_tx_packets", i); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1657 | p += ETH_GSTRING_LEN; |
| 1658 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1659 | "veb.tc_%d_tx_bytes", i); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1660 | p += ETH_GSTRING_LEN; |
| 1661 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1662 | "veb.tc_%d_rx_packets", i); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1663 | p += ETH_GSTRING_LEN; |
| 1664 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1665 | "veb.tc_%d_rx_bytes", i); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1666 | p += ETH_GSTRING_LEN; |
| 1667 | } |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1668 | } |
| 1669 | for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) { |
| 1670 | snprintf(p, ETH_GSTRING_LEN, "port.%s", |
| 1671 | i40e_gstrings_stats[i].stat_string); |
| 1672 | p += ETH_GSTRING_LEN; |
| 1673 | } |
| 1674 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 1675 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1676 | "port.tx_priority_%d_xon", i); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1677 | p += ETH_GSTRING_LEN; |
| 1678 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1679 | "port.tx_priority_%d_xoff", i); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1680 | p += ETH_GSTRING_LEN; |
| 1681 | } |
| 1682 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 1683 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1684 | "port.rx_priority_%d_xon", i); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1685 | p += ETH_GSTRING_LEN; |
| 1686 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1687 | "port.rx_priority_%d_xoff", i); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1688 | p += ETH_GSTRING_LEN; |
| 1689 | } |
| 1690 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 1691 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1692 | "port.rx_priority_%d_xon_2_xoff", i); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1693 | p += ETH_GSTRING_LEN; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1694 | } |
| 1695 | /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */ |
| 1696 | break; |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 1697 | case ETH_SS_PRIV_FLAGS: |
Jacob Keller | e5d3220 | 2016-11-08 13:05:11 -0800 | [diff] [blame] | 1698 | memcpy(data, i40e_priv_flags_strings, |
| 1699 | I40E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN); |
| 1700 | data += I40E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN; |
| 1701 | if (pf->hw.pf_id == 0) |
| 1702 | memcpy(data, i40e_gl_priv_flags_strings, |
| 1703 | I40E_GL_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN); |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 1704 | break; |
Akeem G Abodunrin | 579b23d | 2015-02-24 06:58:42 +0000 | [diff] [blame] | 1705 | default: |
| 1706 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | static int i40e_get_ts_info(struct net_device *dev, |
| 1711 | struct ethtool_ts_info *info) |
| 1712 | { |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1713 | struct i40e_pf *pf = i40e_netdev_to_pf(dev); |
| 1714 | |
Jacob Keller | fe88bda | 2014-11-11 20:05:58 +0000 | [diff] [blame] | 1715 | /* only report HW timestamping if PTP is enabled */ |
| 1716 | if (!(pf->flags & I40E_FLAG_PTP)) |
| 1717 | return ethtool_op_get_ts_info(dev, info); |
| 1718 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1719 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | |
| 1720 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1721 | SOF_TIMESTAMPING_SOFTWARE | |
| 1722 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 1723 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 1724 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 1725 | |
| 1726 | if (pf->ptp_clock) |
| 1727 | info->phc_index = ptp_clock_index(pf->ptp_clock); |
| 1728 | else |
| 1729 | info->phc_index = -1; |
| 1730 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1731 | info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1732 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1733 | info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | |
Jacob Keller | 1e28e86 | 2016-11-11 12:39:25 -0800 | [diff] [blame] | 1734 | BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | |
| 1735 | BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) | |
| 1736 | BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ); |
| 1737 | |
| 1738 | if (pf->flags & I40E_FLAG_PTP_L4_CAPABLE) |
| 1739 | info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | |
| 1740 | BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | |
| 1741 | BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) | |
| 1742 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | |
| 1743 | BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) | |
| 1744 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | |
| 1745 | BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | |
| 1746 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1747 | |
| 1748 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1751 | static int i40e_link_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1752 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1753 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1754 | struct i40e_pf *pf = np->vsi->back; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 1755 | i40e_status status; |
| 1756 | bool link_up = false; |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1757 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1758 | netif_info(pf, hw, netdev, "link test\n"); |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 1759 | status = i40e_get_link_status(&pf->hw, &link_up); |
| 1760 | if (status) { |
| 1761 | netif_err(pf, drv, netdev, "link query timed out, please retry test\n"); |
| 1762 | *data = 1; |
| 1763 | return *data; |
| 1764 | } |
| 1765 | |
| 1766 | if (link_up) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1767 | *data = 0; |
| 1768 | else |
| 1769 | *data = 1; |
| 1770 | |
| 1771 | return *data; |
| 1772 | } |
| 1773 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1774 | static int i40e_reg_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1775 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1776 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1777 | struct i40e_pf *pf = np->vsi->back; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1778 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1779 | netif_info(pf, hw, netdev, "register test\n"); |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1780 | *data = i40e_diag_reg_test(&pf->hw); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1781 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1782 | return *data; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1785 | static int i40e_eeprom_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1786 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1787 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1788 | struct i40e_pf *pf = np->vsi->back; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1789 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1790 | netif_info(pf, hw, netdev, "eeprom test\n"); |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1791 | *data = i40e_diag_eeprom_test(&pf->hw); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1792 | |
Shannon Nelson | 4443ec9 | 2014-11-13 08:23:12 +0000 | [diff] [blame] | 1793 | /* forcebly clear the NVM Update state machine */ |
| 1794 | pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT; |
| 1795 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1796 | return *data; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1799 | static int i40e_intr_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1800 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1801 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1802 | struct i40e_pf *pf = np->vsi->back; |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1803 | u16 swc_old = pf->sw_int_count; |
| 1804 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1805 | netif_info(pf, hw, netdev, "interrupt test\n"); |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1806 | wr32(&pf->hw, I40E_PFINT_DYN_CTL0, |
| 1807 | (I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Shannon Nelson | 5d1ff106 | 2014-11-11 20:04:35 +0000 | [diff] [blame] | 1808 | I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK | |
| 1809 | I40E_PFINT_DYN_CTL0_ITR_INDX_MASK | |
| 1810 | I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK | |
| 1811 | I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK)); |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1812 | usleep_range(1000, 2000); |
| 1813 | *data = (swc_old == pf->sw_int_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1814 | |
| 1815 | return *data; |
| 1816 | } |
| 1817 | |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1818 | static inline bool i40e_active_vfs(struct i40e_pf *pf) |
| 1819 | { |
| 1820 | struct i40e_vf *vfs = pf->vf; |
| 1821 | int i; |
| 1822 | |
| 1823 | for (i = 0; i < pf->num_alloc_vfs; i++) |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1824 | if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states)) |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1825 | return true; |
| 1826 | return false; |
| 1827 | } |
| 1828 | |
Greg Rose | 510efb2 | 2015-07-10 19:36:01 -0400 | [diff] [blame] | 1829 | static inline bool i40e_active_vmdqs(struct i40e_pf *pf) |
| 1830 | { |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 1831 | return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2); |
Greg Rose | 510efb2 | 2015-07-10 19:36:01 -0400 | [diff] [blame] | 1832 | } |
| 1833 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1834 | static void i40e_diag_test(struct net_device *netdev, |
| 1835 | struct ethtool_test *eth_test, u64 *data) |
| 1836 | { |
| 1837 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Greg Rose | 5b86c5c | 2015-02-26 16:14:35 +0000 | [diff] [blame] | 1838 | bool if_running = netif_running(netdev); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1839 | struct i40e_pf *pf = np->vsi->back; |
| 1840 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1841 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { |
| 1842 | /* Offline tests */ |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1843 | netif_info(pf, drv, netdev, "offline testing starting\n"); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1844 | |
Shannon Nelson | f551b43 | 2013-11-26 10:49:12 +0000 | [diff] [blame] | 1845 | set_bit(__I40E_TESTING, &pf->state); |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1846 | |
Greg Rose | 510efb2 | 2015-07-10 19:36:01 -0400 | [diff] [blame] | 1847 | if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) { |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1848 | dev_warn(&pf->pdev->dev, |
Greg Rose | 510efb2 | 2015-07-10 19:36:01 -0400 | [diff] [blame] | 1849 | "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n"); |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1850 | data[I40E_ETH_TEST_REG] = 1; |
| 1851 | data[I40E_ETH_TEST_EEPROM] = 1; |
| 1852 | data[I40E_ETH_TEST_INTR] = 1; |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1853 | data[I40E_ETH_TEST_LINK] = 1; |
| 1854 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1855 | clear_bit(__I40E_TESTING, &pf->state); |
| 1856 | goto skip_ol_tests; |
| 1857 | } |
| 1858 | |
Greg Rose | 5b86c5c | 2015-02-26 16:14:35 +0000 | [diff] [blame] | 1859 | /* If the device is online then take it offline */ |
| 1860 | if (if_running) |
| 1861 | /* indicate we're in test mode */ |
Stefan Assmann | 08ca387 | 2016-02-03 09:20:47 +0100 | [diff] [blame] | 1862 | i40e_close(netdev); |
Greg Rose | 5b86c5c | 2015-02-26 16:14:35 +0000 | [diff] [blame] | 1863 | else |
Greg Rose | b4e53f0 | 2015-07-10 19:36:03 -0400 | [diff] [blame] | 1864 | /* This reset does not affect link - if it is |
| 1865 | * changed to a type of reset that does affect |
| 1866 | * link then the following link test would have |
| 1867 | * to be moved to before the reset |
| 1868 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1869 | i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED)); |
Shannon Nelson | f551b43 | 2013-11-26 10:49:12 +0000 | [diff] [blame] | 1870 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1871 | if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1872 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1873 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1874 | if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1875 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1876 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1877 | if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1878 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1879 | |
Shannon Nelson | f551b43 | 2013-11-26 10:49:12 +0000 | [diff] [blame] | 1880 | /* run reg test last, a reset is required after it */ |
| 1881 | if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG])) |
| 1882 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1883 | |
| 1884 | clear_bit(__I40E_TESTING, &pf->state); |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1885 | i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED)); |
Greg Rose | 5b86c5c | 2015-02-26 16:14:35 +0000 | [diff] [blame] | 1886 | |
| 1887 | if (if_running) |
Stefan Assmann | 08ca387 | 2016-02-03 09:20:47 +0100 | [diff] [blame] | 1888 | i40e_open(netdev); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1889 | } else { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1890 | /* Online tests */ |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1891 | netif_info(pf, drv, netdev, "online testing starting\n"); |
| 1892 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1893 | if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1894 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1895 | |
| 1896 | /* Offline only tests, not run in online; pass by default */ |
| 1897 | data[I40E_ETH_TEST_REG] = 0; |
| 1898 | data[I40E_ETH_TEST_EEPROM] = 0; |
| 1899 | data[I40E_ETH_TEST_INTR] = 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1900 | } |
Shannon Nelson | c140c17 | 2013-11-20 10:02:58 +0000 | [diff] [blame] | 1901 | |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1902 | skip_ol_tests: |
| 1903 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1904 | netif_info(pf, drv, netdev, "testing finished\n"); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | static void i40e_get_wol(struct net_device *netdev, |
| 1908 | struct ethtool_wolinfo *wol) |
| 1909 | { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1910 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1911 | struct i40e_pf *pf = np->vsi->back; |
| 1912 | struct i40e_hw *hw = &pf->hw; |
| 1913 | u16 wol_nvm_bits; |
| 1914 | |
| 1915 | /* NVM bit on means WoL disabled for the port */ |
| 1916 | i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1917 | if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1918 | wol->supported = 0; |
| 1919 | wol->wolopts = 0; |
| 1920 | } else { |
| 1921 | wol->supported = WAKE_MAGIC; |
| 1922 | wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0); |
| 1923 | } |
| 1924 | } |
| 1925 | |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 1926 | /** |
| 1927 | * i40e_set_wol - set the WakeOnLAN configuration |
| 1928 | * @netdev: the netdev in question |
| 1929 | * @wol: the ethtool WoL setting data |
| 1930 | **/ |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1931 | static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 1932 | { |
| 1933 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1934 | struct i40e_pf *pf = np->vsi->back; |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 1935 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1936 | struct i40e_hw *hw = &pf->hw; |
| 1937 | u16 wol_nvm_bits; |
| 1938 | |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 1939 | /* WoL not supported if this isn't the controlling PF on the port */ |
| 1940 | if (hw->partition_id != 1) { |
| 1941 | i40e_partition_setting_complaint(pf); |
| 1942 | return -EOPNOTSUPP; |
| 1943 | } |
| 1944 | |
| 1945 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 1946 | return -EOPNOTSUPP; |
| 1947 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1948 | /* NVM bit on means WoL disabled for the port */ |
| 1949 | i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1950 | if (BIT(hw->port) & wol_nvm_bits) |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1951 | return -EOPNOTSUPP; |
| 1952 | |
| 1953 | /* only magic packet is supported */ |
| 1954 | if (wol->wolopts && (wol->wolopts != WAKE_MAGIC)) |
| 1955 | return -EOPNOTSUPP; |
| 1956 | |
| 1957 | /* is this a new value? */ |
| 1958 | if (pf->wol_en != !!wol->wolopts) { |
| 1959 | pf->wol_en = !!wol->wolopts; |
| 1960 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 1961 | } |
| 1962 | |
| 1963 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1966 | static int i40e_set_phys_id(struct net_device *netdev, |
| 1967 | enum ethtool_phys_id_state state) |
| 1968 | { |
| 1969 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1970 | i40e_status ret = 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1971 | struct i40e_pf *pf = np->vsi->back; |
| 1972 | struct i40e_hw *hw = &pf->hw; |
| 1973 | int blink_freq = 2; |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1974 | u16 temp_status; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1975 | |
| 1976 | switch (state) { |
| 1977 | case ETHTOOL_ID_ACTIVE: |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 1978 | if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) { |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1979 | pf->led_status = i40e_led_get(hw); |
| 1980 | } else { |
Kevin Scott | 06c0e39 | 2016-05-03 15:13:09 -0700 | [diff] [blame] | 1981 | i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL); |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1982 | ret = i40e_led_get_phy(hw, &temp_status, |
| 1983 | &pf->phy_led_val); |
| 1984 | pf->led_status = temp_status; |
| 1985 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1986 | return blink_freq; |
| 1987 | case ETHTOOL_ID_ON: |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 1988 | if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1989 | i40e_led_set(hw, 0xf, false); |
| 1990 | else |
| 1991 | ret = i40e_led_set_phy(hw, true, pf->led_status, 0); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1992 | break; |
| 1993 | case ETHTOOL_ID_OFF: |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 1994 | if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1995 | i40e_led_set(hw, 0x0, false); |
| 1996 | else |
| 1997 | ret = i40e_led_set_phy(hw, false, pf->led_status, 0); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1998 | break; |
| 1999 | case ETHTOOL_ID_INACTIVE: |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 2000 | if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) { |
| 2001 | i40e_led_set(hw, pf->led_status, false); |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 2002 | } else { |
| 2003 | ret = i40e_led_set_phy(hw, false, pf->led_status, |
| 2004 | (pf->phy_led_val | |
| 2005 | I40E_PHY_LED_MODE_ORIG)); |
| 2006 | i40e_aq_set_phy_debug(hw, 0, NULL); |
| 2007 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2008 | break; |
Akeem G Abodunrin | 579b23d | 2015-02-24 06:58:42 +0000 | [diff] [blame] | 2009 | default: |
| 2010 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2011 | } |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 2012 | if (ret) |
| 2013 | return -ENOENT; |
| 2014 | else |
| 2015 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt |
| 2019 | * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also |
| 2020 | * 125us (8000 interrupts per second) == ITR(62) |
| 2021 | */ |
| 2022 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2023 | /** |
| 2024 | * __i40e_get_coalesce - get per-queue coalesce settings |
| 2025 | * @netdev: the netdev to check |
| 2026 | * @ec: ethtool coalesce data structure |
| 2027 | * @queue: which queue to pick |
| 2028 | * |
| 2029 | * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs |
| 2030 | * are per queue. If queue is <0 then we default to queue 0 as the |
| 2031 | * representative value. |
| 2032 | **/ |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2033 | static int __i40e_get_coalesce(struct net_device *netdev, |
| 2034 | struct ethtool_coalesce *ec, |
| 2035 | int queue) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2036 | { |
| 2037 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2038 | struct i40e_ring *rx_ring, *tx_ring; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2039 | struct i40e_vsi *vsi = np->vsi; |
| 2040 | |
| 2041 | ec->tx_max_coalesced_frames_irq = vsi->work_limit; |
| 2042 | ec->rx_max_coalesced_frames_irq = vsi->work_limit; |
| 2043 | |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2044 | /* rx and tx usecs has per queue value. If user doesn't specify the queue, |
| 2045 | * return queue 0's value to represent. |
| 2046 | */ |
| 2047 | if (queue < 0) { |
| 2048 | queue = 0; |
| 2049 | } else if (queue >= vsi->num_queue_pairs) { |
| 2050 | return -EINVAL; |
| 2051 | } |
| 2052 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2053 | rx_ring = vsi->rx_rings[queue]; |
| 2054 | tx_ring = vsi->tx_rings[queue]; |
| 2055 | |
| 2056 | if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting)) |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 2057 | ec->use_adaptive_rx_coalesce = 1; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2058 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2059 | if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting)) |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 2060 | ec->use_adaptive_tx_coalesce = 1; |
| 2061 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2062 | ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC; |
| 2063 | ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC; |
| 2064 | |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2065 | |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 2066 | /* we use the _usecs_high to store/set the interrupt rate limit |
| 2067 | * that the hardware supports, that almost but not quite |
| 2068 | * fits the original intent of the ethtool variable, |
| 2069 | * the rx_coalesce_usecs_high limits total interrupts |
| 2070 | * per second from both tx/rx sources. |
| 2071 | */ |
| 2072 | ec->rx_coalesce_usecs_high = vsi->int_rate_limit; |
| 2073 | ec->tx_coalesce_usecs_high = vsi->int_rate_limit; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2074 | |
| 2075 | return 0; |
| 2076 | } |
| 2077 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2078 | /** |
| 2079 | * i40e_get_coalesce - get a netdev's coalesce settings |
| 2080 | * @netdev: the netdev to check |
| 2081 | * @ec: ethtool coalesce data structure |
| 2082 | * |
| 2083 | * Gets the coalesce settings for a particular netdev. Note that if user has |
| 2084 | * modified per-queue settings, this only guarantees to represent queue 0. See |
| 2085 | * __i40e_get_coalesce for more details. |
| 2086 | **/ |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2087 | static int i40e_get_coalesce(struct net_device *netdev, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2088 | struct ethtool_coalesce *ec) |
| 2089 | { |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2090 | return __i40e_get_coalesce(netdev, ec, -1); |
| 2091 | } |
| 2092 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2093 | /** |
| 2094 | * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue |
| 2095 | * @netdev: netdev structure |
| 2096 | * @ec: ethtool's coalesce settings |
| 2097 | * @queue: the particular queue to read |
| 2098 | * |
| 2099 | * Will read a specific queue's coalesce settings |
| 2100 | **/ |
Kan Liang | be280ba | 2016-02-19 09:24:05 -0500 | [diff] [blame] | 2101 | static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue, |
| 2102 | struct ethtool_coalesce *ec) |
| 2103 | { |
| 2104 | return __i40e_get_coalesce(netdev, ec, queue); |
| 2105 | } |
| 2106 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2107 | /** |
| 2108 | * i40e_set_itr_per_queue - set ITR values for specific queue |
| 2109 | * @vsi: the VSI to set values for |
| 2110 | * @ec: coalesce settings from ethtool |
| 2111 | * @queue: the queue to modify |
| 2112 | * |
| 2113 | * Change the ITR settings for a specific queue. |
| 2114 | **/ |
| 2115 | |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2116 | static void i40e_set_itr_per_queue(struct i40e_vsi *vsi, |
| 2117 | struct ethtool_coalesce *ec, |
| 2118 | int queue) |
| 2119 | { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2120 | struct i40e_pf *pf = vsi->back; |
| 2121 | struct i40e_hw *hw = &pf->hw; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2122 | struct i40e_q_vector *q_vector; |
| 2123 | u16 vector, intrl; |
| 2124 | |
Alan Brady | 1c0e6a3 | 2016-11-28 16:06:02 -0800 | [diff] [blame] | 2125 | intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2126 | |
| 2127 | vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs; |
| 2128 | vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs; |
| 2129 | |
| 2130 | if (ec->use_adaptive_rx_coalesce) |
| 2131 | vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC; |
| 2132 | else |
| 2133 | vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC; |
| 2134 | |
| 2135 | if (ec->use_adaptive_tx_coalesce) |
| 2136 | vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC; |
| 2137 | else |
| 2138 | vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC; |
| 2139 | |
| 2140 | q_vector = vsi->rx_rings[queue]->q_vector; |
| 2141 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting); |
| 2142 | vector = vsi->base_vector + q_vector->v_idx; |
| 2143 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr); |
| 2144 | |
| 2145 | q_vector = vsi->tx_rings[queue]->q_vector; |
| 2146 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting); |
| 2147 | vector = vsi->base_vector + q_vector->v_idx; |
| 2148 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr); |
| 2149 | |
| 2150 | wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl); |
| 2151 | i40e_flush(hw); |
| 2152 | } |
| 2153 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2154 | /** |
| 2155 | * __i40e_set_coalesce - set coalesce settings for particular queue |
| 2156 | * @netdev: the netdev to change |
| 2157 | * @ec: ethtool coalesce settings |
| 2158 | * @queue: the queue to change |
| 2159 | * |
| 2160 | * Sets the coalesce settings for a particular queue. |
| 2161 | **/ |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2162 | static int __i40e_set_coalesce(struct net_device *netdev, |
| 2163 | struct ethtool_coalesce *ec, |
| 2164 | int queue) |
| 2165 | { |
| 2166 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2167 | struct i40e_vsi *vsi = np->vsi; |
| 2168 | struct i40e_pf *pf = vsi->back; |
Alan Brady | 3308406 | 2016-11-28 16:06:03 -0800 | [diff] [blame] | 2169 | u16 intrl_reg; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2170 | int i; |
| 2171 | |
| 2172 | if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq) |
| 2173 | vsi->work_limit = ec->tx_max_coalesced_frames_irq; |
| 2174 | |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 2175 | /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */ |
| 2176 | if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) { |
| 2177 | netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n"); |
| 2178 | return -EINVAL; |
| 2179 | } |
| 2180 | |
Alan Brady | 3308406 | 2016-11-28 16:06:03 -0800 | [diff] [blame] | 2181 | if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) { |
| 2182 | netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n", |
| 2183 | INTRL_REG_TO_USEC(I40E_MAX_INTRL)); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 2184 | return -EINVAL; |
| 2185 | } |
| 2186 | |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2187 | if (ec->rx_coalesce_usecs == 0) { |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2188 | if (ec->use_adaptive_rx_coalesce) |
Jesse Brandeburg | 79442d3 | 2014-10-25 03:24:32 +0000 | [diff] [blame] | 2189 | netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n"); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2190 | } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) || |
| 2191 | (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) { |
| 2192 | netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n"); |
| 2193 | return -EINVAL; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2194 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2195 | |
Alan Brady | 3308406 | 2016-11-28 16:06:03 -0800 | [diff] [blame] | 2196 | intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high); |
| 2197 | vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg); |
| 2198 | if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) { |
| 2199 | netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n", |
| 2200 | vsi->int_rate_limit); |
| 2201 | } |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 2202 | |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2203 | if (ec->tx_coalesce_usecs == 0) { |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2204 | if (ec->use_adaptive_tx_coalesce) |
Jesse Brandeburg | 79442d3 | 2014-10-25 03:24:32 +0000 | [diff] [blame] | 2205 | netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n"); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2206 | } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) || |
| 2207 | (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) { |
| 2208 | netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n"); |
| 2209 | return -EINVAL; |
| 2210 | } |
| 2211 | |
| 2212 | /* rx and tx usecs has per queue value. If user doesn't specify the queue, |
| 2213 | * apply to all queues. |
| 2214 | */ |
| 2215 | if (queue < 0) { |
| 2216 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 2217 | i40e_set_itr_per_queue(vsi, ec, i); |
| 2218 | } else if (queue < vsi->num_queue_pairs) { |
| 2219 | i40e_set_itr_per_queue(vsi, ec, queue); |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2220 | } else { |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2221 | netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n", |
| 2222 | vsi->num_queue_pairs - 1); |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 2223 | return -EINVAL; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2224 | } |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 2225 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2226 | return 0; |
| 2227 | } |
| 2228 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2229 | /** |
| 2230 | * i40e_set_coalesce - set coalesce settings for every queue on the netdev |
| 2231 | * @netdev: the netdev to change |
| 2232 | * @ec: ethtool coalesce settings |
| 2233 | * |
| 2234 | * This will set each queue to the same coalesce settings. |
| 2235 | **/ |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2236 | static int i40e_set_coalesce(struct net_device *netdev, |
| 2237 | struct ethtool_coalesce *ec) |
| 2238 | { |
| 2239 | return __i40e_set_coalesce(netdev, ec, -1); |
| 2240 | } |
| 2241 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2242 | /** |
| 2243 | * i40e_set_per_queue_coalesce - set specific queue's coalesce settings |
| 2244 | * @netdev: the netdev to change |
| 2245 | * @ec: ethtool's coalesce settings |
| 2246 | * @queue: the queue to change |
| 2247 | * |
| 2248 | * Sets the specified queue's coalesce settings. |
| 2249 | **/ |
Kan Liang | f3757a4 | 2016-02-19 09:24:06 -0500 | [diff] [blame] | 2250 | static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue, |
| 2251 | struct ethtool_coalesce *ec) |
| 2252 | { |
| 2253 | return __i40e_set_coalesce(netdev, ec, queue); |
| 2254 | } |
| 2255 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2256 | /** |
| 2257 | * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type |
| 2258 | * @pf: pointer to the physical function struct |
| 2259 | * @cmd: ethtool rxnfc command |
| 2260 | * |
| 2261 | * Returns Success if the flow is supported, else Invalid Input. |
| 2262 | **/ |
| 2263 | static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd) |
| 2264 | { |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2265 | struct i40e_hw *hw = &pf->hw; |
| 2266 | u8 flow_pctype = 0; |
| 2267 | u64 i_set = 0; |
| 2268 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2269 | cmd->data = 0; |
| 2270 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2271 | switch (cmd->flow_type) { |
| 2272 | case TCP_V4_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2273 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP; |
| 2274 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2275 | case UDP_V4_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2276 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP; |
| 2277 | break; |
| 2278 | case TCP_V6_FLOW: |
| 2279 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP; |
| 2280 | break; |
| 2281 | case UDP_V6_FLOW: |
| 2282 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP; |
| 2283 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2284 | case SCTP_V4_FLOW: |
| 2285 | case AH_ESP_V4_FLOW: |
| 2286 | case AH_V4_FLOW: |
| 2287 | case ESP_V4_FLOW: |
| 2288 | case IPV4_FLOW: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2289 | case SCTP_V6_FLOW: |
| 2290 | case AH_ESP_V6_FLOW: |
| 2291 | case AH_V6_FLOW: |
| 2292 | case ESP_V6_FLOW: |
| 2293 | case IPV6_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2294 | /* Default is src/dest for IP, no matter the L4 hashing */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2295 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; |
| 2296 | break; |
| 2297 | default: |
| 2298 | return -EINVAL; |
| 2299 | } |
| 2300 | |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2301 | /* Read flow based hash input set register */ |
| 2302 | if (flow_pctype) { |
| 2303 | i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, |
| 2304 | flow_pctype)) | |
| 2305 | ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, |
| 2306 | flow_pctype)) << 32); |
| 2307 | } |
| 2308 | |
| 2309 | /* Process bits of hash input set */ |
| 2310 | if (i_set) { |
| 2311 | if (i_set & I40E_L4_SRC_MASK) |
| 2312 | cmd->data |= RXH_L4_B_0_1; |
| 2313 | if (i_set & I40E_L4_DST_MASK) |
| 2314 | cmd->data |= RXH_L4_B_2_3; |
| 2315 | |
| 2316 | if (cmd->flow_type == TCP_V4_FLOW || |
| 2317 | cmd->flow_type == UDP_V4_FLOW) { |
| 2318 | if (i_set & I40E_L3_SRC_MASK) |
| 2319 | cmd->data |= RXH_IP_SRC; |
| 2320 | if (i_set & I40E_L3_DST_MASK) |
| 2321 | cmd->data |= RXH_IP_DST; |
| 2322 | } else if (cmd->flow_type == TCP_V6_FLOW || |
| 2323 | cmd->flow_type == UDP_V6_FLOW) { |
| 2324 | if (i_set & I40E_L3_V6_SRC_MASK) |
| 2325 | cmd->data |= RXH_IP_SRC; |
| 2326 | if (i_set & I40E_L3_V6_DST_MASK) |
| 2327 | cmd->data |= RXH_IP_DST; |
| 2328 | } |
| 2329 | } |
| 2330 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2331 | return 0; |
| 2332 | } |
| 2333 | |
| 2334 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2335 | * i40e_get_ethtool_fdir_all - Populates the rule count of a command |
| 2336 | * @pf: Pointer to the physical function struct |
| 2337 | * @cmd: The command to get or set Rx flow classification rules |
| 2338 | * @rule_locs: Array of used rule locations |
| 2339 | * |
| 2340 | * This function populates both the total and actual rule count of |
| 2341 | * the ethtool flow classification command |
| 2342 | * |
| 2343 | * Returns 0 on success or -EMSGSIZE if entry not found |
| 2344 | **/ |
| 2345 | static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf, |
| 2346 | struct ethtool_rxnfc *cmd, |
| 2347 | u32 *rule_locs) |
| 2348 | { |
| 2349 | struct i40e_fdir_filter *rule; |
| 2350 | struct hlist_node *node2; |
| 2351 | int cnt = 0; |
| 2352 | |
| 2353 | /* report total rule count */ |
Anjali Singhai Jain | 082def1 | 2014-04-09 05:59:00 +0000 | [diff] [blame] | 2354 | cmd->data = i40e_get_fd_cnt_all(pf); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2355 | |
| 2356 | hlist_for_each_entry_safe(rule, node2, |
| 2357 | &pf->fdir_filter_list, fdir_node) { |
| 2358 | if (cnt == cmd->rule_cnt) |
| 2359 | return -EMSGSIZE; |
| 2360 | |
| 2361 | rule_locs[cnt] = rule->fd_id; |
| 2362 | cnt++; |
| 2363 | } |
| 2364 | |
| 2365 | cmd->rule_cnt = cnt; |
| 2366 | |
| 2367 | return 0; |
| 2368 | } |
| 2369 | |
| 2370 | /** |
| 2371 | * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow |
| 2372 | * @pf: Pointer to the physical function struct |
| 2373 | * @cmd: The command to get or set Rx flow classification rules |
| 2374 | * |
| 2375 | * This function looks up a filter based on the Rx flow classification |
| 2376 | * command and fills the flow spec info for it if found |
| 2377 | * |
| 2378 | * Returns 0 on success or -EINVAL if filter not found |
| 2379 | **/ |
| 2380 | static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf, |
| 2381 | struct ethtool_rxnfc *cmd) |
| 2382 | { |
| 2383 | struct ethtool_rx_flow_spec *fsp = |
| 2384 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
| 2385 | struct i40e_fdir_filter *rule = NULL; |
| 2386 | struct hlist_node *node2; |
| 2387 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2388 | hlist_for_each_entry_safe(rule, node2, |
| 2389 | &pf->fdir_filter_list, fdir_node) { |
| 2390 | if (fsp->location <= rule->fd_id) |
| 2391 | break; |
| 2392 | } |
| 2393 | |
| 2394 | if (!rule || fsp->location != rule->fd_id) |
| 2395 | return -EINVAL; |
| 2396 | |
| 2397 | fsp->flow_type = rule->flow_type; |
Anjali Singhai Jain | 7d54eb2 | 2014-03-14 07:32:21 +0000 | [diff] [blame] | 2398 | if (fsp->flow_type == IP_USER_FLOW) { |
| 2399 | fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; |
| 2400 | fsp->h_u.usr_ip4_spec.proto = 0; |
| 2401 | fsp->m_u.usr_ip4_spec.proto = 0; |
| 2402 | } |
| 2403 | |
Anjali Singhai Jain | 04b73bd | 2014-05-22 06:31:41 +0000 | [diff] [blame] | 2404 | /* Reverse the src and dest notion, since the HW views them from |
| 2405 | * Tx perspective where as the user expects it from Rx filter view. |
| 2406 | */ |
| 2407 | fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port; |
| 2408 | fsp->h_u.tcp_ip4_spec.pdst = rule->src_port; |
Jacob Keller | 8ce43dc | 2017-02-06 14:38:39 -0800 | [diff] [blame] | 2409 | fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip; |
| 2410 | fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip; |
Anjali Singhai Jain | 387ce1a | 2014-05-22 06:32:23 +0000 | [diff] [blame] | 2411 | |
| 2412 | if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET) |
| 2413 | fsp->ring_cookie = RX_CLS_FLOW_DISC; |
| 2414 | else |
| 2415 | fsp->ring_cookie = rule->q_index; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2416 | |
Anjali Singhai Jain | e7c8c60 | 2015-04-07 19:45:31 -0400 | [diff] [blame] | 2417 | if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) { |
| 2418 | struct i40e_vsi *vsi; |
| 2419 | |
| 2420 | vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi); |
| 2421 | if (vsi && vsi->type == I40E_VSI_SRIOV) { |
| 2422 | fsp->h_ext.data[1] = htonl(vsi->vf_id); |
| 2423 | fsp->m_ext.data[1] = htonl(0x1); |
| 2424 | } |
| 2425 | } |
| 2426 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2427 | return 0; |
| 2428 | } |
| 2429 | |
| 2430 | /** |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2431 | * i40e_get_rxnfc - command to get RX flow classification rules |
| 2432 | * @netdev: network interface device structure |
| 2433 | * @cmd: ethtool rxnfc command |
| 2434 | * |
| 2435 | * Returns Success if the command is supported. |
| 2436 | **/ |
| 2437 | static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, |
| 2438 | u32 *rule_locs) |
| 2439 | { |
| 2440 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2441 | struct i40e_vsi *vsi = np->vsi; |
| 2442 | struct i40e_pf *pf = vsi->back; |
| 2443 | int ret = -EOPNOTSUPP; |
| 2444 | |
| 2445 | switch (cmd->cmd) { |
| 2446 | case ETHTOOL_GRXRINGS: |
Helin Zhang | 3e3aa21 | 2015-10-21 19:47:13 -0400 | [diff] [blame] | 2447 | cmd->data = vsi->num_queue_pairs; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2448 | ret = 0; |
| 2449 | break; |
| 2450 | case ETHTOOL_GRXFH: |
| 2451 | ret = i40e_get_rss_hash_opts(pf, cmd); |
| 2452 | break; |
| 2453 | case ETHTOOL_GRXCLSRLCNT: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2454 | cmd->rule_cnt = pf->fdir_pf_active_filters; |
Anjali Singhai Jain | 082def1 | 2014-04-09 05:59:00 +0000 | [diff] [blame] | 2455 | /* report total rule count */ |
| 2456 | cmd->data = i40e_get_fd_cnt_all(pf); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2457 | ret = 0; |
| 2458 | break; |
| 2459 | case ETHTOOL_GRXCLSRULE: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2460 | ret = i40e_get_ethtool_fdir_entry(pf, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2461 | break; |
| 2462 | case ETHTOOL_GRXCLSRLALL: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2463 | ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs); |
| 2464 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2465 | default: |
| 2466 | break; |
| 2467 | } |
| 2468 | |
| 2469 | return ret; |
| 2470 | } |
| 2471 | |
| 2472 | /** |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2473 | * i40e_get_rss_hash_bits - Read RSS Hash bits from register |
| 2474 | * @nfc: pointer to user request |
| 2475 | * @i_setc bits currently set |
| 2476 | * |
| 2477 | * Returns value of bits to be set per user request |
| 2478 | **/ |
| 2479 | static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc) |
| 2480 | { |
| 2481 | u64 i_set = i_setc; |
| 2482 | u64 src_l3 = 0, dst_l3 = 0; |
| 2483 | |
| 2484 | if (nfc->data & RXH_L4_B_0_1) |
| 2485 | i_set |= I40E_L4_SRC_MASK; |
| 2486 | else |
| 2487 | i_set &= ~I40E_L4_SRC_MASK; |
| 2488 | if (nfc->data & RXH_L4_B_2_3) |
| 2489 | i_set |= I40E_L4_DST_MASK; |
| 2490 | else |
| 2491 | i_set &= ~I40E_L4_DST_MASK; |
| 2492 | |
| 2493 | if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) { |
| 2494 | src_l3 = I40E_L3_V6_SRC_MASK; |
| 2495 | dst_l3 = I40E_L3_V6_DST_MASK; |
| 2496 | } else if (nfc->flow_type == TCP_V4_FLOW || |
| 2497 | nfc->flow_type == UDP_V4_FLOW) { |
| 2498 | src_l3 = I40E_L3_SRC_MASK; |
| 2499 | dst_l3 = I40E_L3_DST_MASK; |
| 2500 | } else { |
| 2501 | /* Any other flow type are not supported here */ |
| 2502 | return i_set; |
| 2503 | } |
| 2504 | |
| 2505 | if (nfc->data & RXH_IP_SRC) |
| 2506 | i_set |= src_l3; |
| 2507 | else |
| 2508 | i_set &= ~src_l3; |
| 2509 | if (nfc->data & RXH_IP_DST) |
| 2510 | i_set |= dst_l3; |
| 2511 | else |
| 2512 | i_set &= ~dst_l3; |
| 2513 | |
| 2514 | return i_set; |
| 2515 | } |
| 2516 | |
| 2517 | /** |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2518 | * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash |
| 2519 | * @pf: pointer to the physical function struct |
| 2520 | * @cmd: ethtool rxnfc command |
| 2521 | * |
| 2522 | * Returns Success if the flow input set is supported. |
| 2523 | **/ |
| 2524 | static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc) |
| 2525 | { |
| 2526 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 2527 | u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 2528 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2529 | u8 flow_pctype = 0; |
| 2530 | u64 i_set, i_setc; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2531 | |
| 2532 | /* RSS does not support anything other than hashing |
| 2533 | * to queues on src and dst IPs and ports |
| 2534 | */ |
| 2535 | if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | |
| 2536 | RXH_L4_B_0_1 | RXH_L4_B_2_3)) |
| 2537 | return -EINVAL; |
| 2538 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2539 | switch (nfc->flow_type) { |
| 2540 | case TCP_V4_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2541 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP; |
| 2542 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) |
| 2543 | hena |= |
| 2544 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2545 | break; |
| 2546 | case TCP_V6_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2547 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP; |
| 2548 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) |
| 2549 | hena |= |
| 2550 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK); |
| 2551 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) |
| 2552 | hena |= |
| 2553 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2554 | break; |
| 2555 | case UDP_V4_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2556 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP; |
| 2557 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) |
| 2558 | hena |= |
| 2559 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | |
| 2560 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP); |
Anjali Singhai Jain | 3d0da5b | 2015-12-22 14:25:05 -0800 | [diff] [blame] | 2561 | |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2562 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2563 | break; |
| 2564 | case UDP_V6_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2565 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP; |
| 2566 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) |
| 2567 | hena |= |
| 2568 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | |
| 2569 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP); |
Anjali Singhai Jain | 3d0da5b | 2015-12-22 14:25:05 -0800 | [diff] [blame] | 2570 | |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2571 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2572 | break; |
| 2573 | case AH_ESP_V4_FLOW: |
| 2574 | case AH_V4_FLOW: |
| 2575 | case ESP_V4_FLOW: |
| 2576 | case SCTP_V4_FLOW: |
| 2577 | if ((nfc->data & RXH_L4_B_0_1) || |
| 2578 | (nfc->data & RXH_L4_B_2_3)) |
| 2579 | return -EINVAL; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2580 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2581 | break; |
| 2582 | case AH_ESP_V6_FLOW: |
| 2583 | case AH_V6_FLOW: |
| 2584 | case ESP_V6_FLOW: |
| 2585 | case SCTP_V6_FLOW: |
| 2586 | if ((nfc->data & RXH_L4_B_0_1) || |
| 2587 | (nfc->data & RXH_L4_B_2_3)) |
| 2588 | return -EINVAL; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2589 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2590 | break; |
| 2591 | case IPV4_FLOW: |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2592 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | |
| 2593 | BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2594 | break; |
| 2595 | case IPV6_FLOW: |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2596 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | |
| 2597 | BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2598 | break; |
| 2599 | default: |
| 2600 | return -EINVAL; |
| 2601 | } |
| 2602 | |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2603 | if (flow_pctype) { |
| 2604 | i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, |
| 2605 | flow_pctype)) | |
| 2606 | ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, |
| 2607 | flow_pctype)) << 32); |
| 2608 | i_set = i40e_get_rss_hash_bits(nfc, i_setc); |
| 2609 | i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype), |
| 2610 | (u32)i_set); |
| 2611 | i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype), |
| 2612 | (u32)(i_set >> 32)); |
| 2613 | hena |= BIT_ULL(flow_pctype); |
| 2614 | } |
| 2615 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 2616 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 2617 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2618 | i40e_flush(hw); |
| 2619 | |
| 2620 | return 0; |
| 2621 | } |
| 2622 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2623 | /** |
Anjali Singhai Jain | 43fddb7 | 2014-02-11 08:24:09 +0000 | [diff] [blame] | 2624 | * i40e_match_fdir_input_set - Match a new filter against an existing one |
| 2625 | * @rule: The filter already added |
| 2626 | * @input: The new filter to comapre against |
| 2627 | * |
| 2628 | * Returns true if the two input set match |
| 2629 | **/ |
| 2630 | static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule, |
| 2631 | struct i40e_fdir_filter *input) |
| 2632 | { |
Jacob Keller | 8ce43dc | 2017-02-06 14:38:39 -0800 | [diff] [blame] | 2633 | if ((rule->dst_ip != input->dst_ip) || |
| 2634 | (rule->src_ip != input->src_ip) || |
Anjali Singhai Jain | 43fddb7 | 2014-02-11 08:24:09 +0000 | [diff] [blame] | 2635 | (rule->dst_port != input->dst_port) || |
| 2636 | (rule->src_port != input->src_port)) |
| 2637 | return false; |
| 2638 | return true; |
| 2639 | } |
| 2640 | |
| 2641 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2642 | * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry |
| 2643 | * @vsi: Pointer to the targeted VSI |
| 2644 | * @input: The filter to update or NULL to indicate deletion |
| 2645 | * @sw_idx: Software index to the filter |
| 2646 | * @cmd: The command to get or set Rx flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2647 | * |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2648 | * This function updates (or deletes) a Flow Director entry from |
| 2649 | * the hlist of the corresponding PF |
| 2650 | * |
| 2651 | * Returns 0 on success |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2652 | **/ |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2653 | static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi, |
| 2654 | struct i40e_fdir_filter *input, |
| 2655 | u16 sw_idx, |
| 2656 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2657 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2658 | struct i40e_fdir_filter *rule, *parent; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2659 | struct i40e_pf *pf = vsi->back; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2660 | struct hlist_node *node2; |
| 2661 | int err = -EINVAL; |
Jesse Brandeburg | c35a1d7 | 2013-12-18 13:46:02 +0000 | [diff] [blame] | 2662 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2663 | parent = NULL; |
| 2664 | rule = NULL; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2665 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2666 | hlist_for_each_entry_safe(rule, node2, |
| 2667 | &pf->fdir_filter_list, fdir_node) { |
| 2668 | /* hash found, or no matching entry */ |
| 2669 | if (rule->fd_id >= sw_idx) |
| 2670 | break; |
| 2671 | parent = rule; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2674 | /* if there is an old rule occupying our place remove it */ |
| 2675 | if (rule && (rule->fd_id == sw_idx)) { |
Anjali Singhai Jain | 43fddb7 | 2014-02-11 08:24:09 +0000 | [diff] [blame] | 2676 | if (input && !i40e_match_fdir_input_set(rule, input)) |
| 2677 | err = i40e_add_del_fdir(vsi, rule, false); |
| 2678 | else if (!input) |
| 2679 | err = i40e_add_del_fdir(vsi, rule, false); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2680 | hlist_del(&rule->fdir_node); |
| 2681 | kfree(rule); |
| 2682 | pf->fdir_pf_active_filters--; |
| 2683 | } |
| 2684 | |
| 2685 | /* If no input this was a delete, err should be 0 if a rule was |
| 2686 | * successfully found and removed from the list else -EINVAL |
| 2687 | */ |
| 2688 | if (!input) |
| 2689 | return err; |
| 2690 | |
| 2691 | /* initialize node and set software index */ |
| 2692 | INIT_HLIST_NODE(&input->fdir_node); |
| 2693 | |
| 2694 | /* add filter to the list */ |
| 2695 | if (parent) |
Ken Helias | 1d02328 | 2014-08-06 16:09:16 -0700 | [diff] [blame] | 2696 | hlist_add_behind(&input->fdir_node, &parent->fdir_node); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2697 | else |
| 2698 | hlist_add_head(&input->fdir_node, |
| 2699 | &pf->fdir_filter_list); |
| 2700 | |
| 2701 | /* update counts */ |
| 2702 | pf->fdir_pf_active_filters++; |
| 2703 | |
| 2704 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2708 | * i40e_del_fdir_entry - Deletes a Flow Director filter entry |
| 2709 | * @vsi: Pointer to the targeted VSI |
| 2710 | * @cmd: The command to get or set Rx flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2711 | * |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2712 | * The function removes a Flow Director filter entry from the |
| 2713 | * hlist of the corresponding PF |
| 2714 | * |
| 2715 | * Returns 0 on success |
| 2716 | */ |
| 2717 | static int i40e_del_fdir_entry(struct i40e_vsi *vsi, |
| 2718 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2719 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2720 | struct ethtool_rx_flow_spec *fsp = |
| 2721 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2722 | struct i40e_pf *pf = vsi->back; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2723 | int ret = 0; |
Jesse Brandeburg | c35a1d7 | 2013-12-18 13:46:02 +0000 | [diff] [blame] | 2724 | |
Anjali Singhai Jain | 60793f4a | 2014-07-09 07:46:23 +0000 | [diff] [blame] | 2725 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 2726 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 2727 | return -EBUSY; |
| 2728 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 2729 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 2730 | return -EBUSY; |
| 2731 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2732 | ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2733 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2734 | i40e_fdir_check_and_reenable(pf); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2735 | return ret; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | /** |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 2739 | * i40e_add_fdir_ethtool - Add/Remove Flow Director filters |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2740 | * @vsi: pointer to the targeted VSI |
| 2741 | * @cmd: command to get or set RX flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2742 | * |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 2743 | * Add Flow Director filters for a specific flow spec based on their |
| 2744 | * protocol. Returns 0 if the filters were successfully added. |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2745 | **/ |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 2746 | static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi, |
| 2747 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2748 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2749 | struct ethtool_rx_flow_spec *fsp; |
| 2750 | struct i40e_fdir_filter *input; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2751 | struct i40e_pf *pf; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2752 | int ret = -EINVAL; |
Anjali Singhai Jain | e7c8c60 | 2015-04-07 19:45:31 -0400 | [diff] [blame] | 2753 | u16 vf_id; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2754 | |
| 2755 | if (!vsi) |
| 2756 | return -EINVAL; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2757 | pf = vsi->back; |
| 2758 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2759 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 2760 | return -EOPNOTSUPP; |
| 2761 | |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 2762 | if (pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2763 | return -ENOSPC; |
| 2764 | |
Anjali Singhai Jain | 60793f4a | 2014-07-09 07:46:23 +0000 | [diff] [blame] | 2765 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 2766 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 2767 | return -EBUSY; |
| 2768 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 2769 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 2770 | return -EBUSY; |
| 2771 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2772 | fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; |
| 2773 | |
Jacob Keller | 1ec8dea | 2017-02-06 14:39:12 -0800 | [diff] [blame^] | 2774 | /* Extended MAC field is not supported */ |
| 2775 | if (fsp->flow_type & FLOW_MAC_EXT) |
| 2776 | return -EINVAL; |
| 2777 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2778 | if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort + |
| 2779 | pf->hw.func_caps.fd_filters_guaranteed)) { |
| 2780 | return -EINVAL; |
| 2781 | } |
| 2782 | |
Anjali Singhai Jain | 387ce1a | 2014-05-22 06:32:23 +0000 | [diff] [blame] | 2783 | if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) && |
| 2784 | (fsp->ring_cookie >= vsi->num_queue_pairs)) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2785 | return -EINVAL; |
| 2786 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2787 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2788 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2789 | if (!input) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2790 | return -ENOMEM; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2791 | |
| 2792 | input->fd_id = fsp->location; |
| 2793 | |
Anjali Singhai Jain | 35a91fd | 2014-03-06 09:00:00 +0000 | [diff] [blame] | 2794 | if (fsp->ring_cookie == RX_CLS_FLOW_DISC) |
| 2795 | input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET; |
| 2796 | else |
| 2797 | input->dest_ctl = |
| 2798 | I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX; |
| 2799 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2800 | input->q_index = fsp->ring_cookie; |
| 2801 | input->flex_off = 0; |
| 2802 | input->pctype = 0; |
| 2803 | input->dest_vsi = vsi->id; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2804 | input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID; |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 2805 | input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2806 | input->flow_type = fsp->flow_type; |
| 2807 | input->ip4_proto = fsp->h_u.usr_ip4_spec.proto; |
Anjali Singhai Jain | 04b73bd | 2014-05-22 06:31:41 +0000 | [diff] [blame] | 2808 | |
| 2809 | /* Reverse the src and dest notion, since the HW expects them to be from |
| 2810 | * Tx perspective where as the input from user is from Rx filter view. |
| 2811 | */ |
| 2812 | input->dst_port = fsp->h_u.tcp_ip4_spec.psrc; |
| 2813 | input->src_port = fsp->h_u.tcp_ip4_spec.pdst; |
Jacob Keller | 8ce43dc | 2017-02-06 14:38:39 -0800 | [diff] [blame] | 2814 | input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src; |
| 2815 | input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2816 | |
Anjali Singhai Jain | e7c8c60 | 2015-04-07 19:45:31 -0400 | [diff] [blame] | 2817 | if (ntohl(fsp->m_ext.data[1])) { |
Shannon Nelson | bab3a34 | 2016-04-12 08:30:42 -0700 | [diff] [blame] | 2818 | vf_id = ntohl(fsp->h_ext.data[1]); |
| 2819 | if (vf_id >= pf->num_alloc_vfs) { |
| 2820 | netif_info(pf, drv, vsi->netdev, |
| 2821 | "Invalid VF id %d\n", vf_id); |
Anjali Singhai Jain | e7c8c60 | 2015-04-07 19:45:31 -0400 | [diff] [blame] | 2822 | goto free_input; |
| 2823 | } |
Anjali Singhai Jain | e7c8c60 | 2015-04-07 19:45:31 -0400 | [diff] [blame] | 2824 | /* Find vsi id from vf id and override dest vsi */ |
| 2825 | input->dest_vsi = pf->vf[vf_id].lan_vsi_id; |
| 2826 | if (input->q_index >= pf->vf[vf_id].num_queue_pairs) { |
Shannon Nelson | bab3a34 | 2016-04-12 08:30:42 -0700 | [diff] [blame] | 2827 | netif_info(pf, drv, vsi->netdev, |
| 2828 | "Invalid queue id %d for VF %d\n", |
| 2829 | input->q_index, vf_id); |
Anjali Singhai Jain | e7c8c60 | 2015-04-07 19:45:31 -0400 | [diff] [blame] | 2830 | goto free_input; |
| 2831 | } |
| 2832 | } |
| 2833 | |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 2834 | ret = i40e_add_del_fdir(vsi, input, true); |
| 2835 | if (ret) |
Jacob Keller | 01016da | 2017-02-06 14:38:40 -0800 | [diff] [blame] | 2836 | goto free_input; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2837 | |
Jacob Keller | 01016da | 2017-02-06 14:38:40 -0800 | [diff] [blame] | 2838 | /* Add the input filter to the fdir_input_list, possibly replacing |
| 2839 | * a previous filter. Do not free the input structure after adding it |
| 2840 | * to the list as this would cause a use-after-free bug. |
| 2841 | */ |
| 2842 | i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL); |
| 2843 | |
| 2844 | return 0; |
| 2845 | |
| 2846 | free_input: |
| 2847 | kfree(input); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2848 | return ret; |
| 2849 | } |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 2850 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2851 | /** |
| 2852 | * i40e_set_rxnfc - command to set RX flow classification rules |
| 2853 | * @netdev: network interface device structure |
| 2854 | * @cmd: ethtool rxnfc command |
| 2855 | * |
| 2856 | * Returns Success if the command is supported. |
| 2857 | **/ |
| 2858 | static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) |
| 2859 | { |
| 2860 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2861 | struct i40e_vsi *vsi = np->vsi; |
| 2862 | struct i40e_pf *pf = vsi->back; |
| 2863 | int ret = -EOPNOTSUPP; |
| 2864 | |
| 2865 | switch (cmd->cmd) { |
| 2866 | case ETHTOOL_SRXFH: |
| 2867 | ret = i40e_set_rss_hash_opt(pf, cmd); |
| 2868 | break; |
| 2869 | case ETHTOOL_SRXCLSRLINS: |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 2870 | ret = i40e_add_fdir_ethtool(vsi, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2871 | break; |
| 2872 | case ETHTOOL_SRXCLSRLDEL: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2873 | ret = i40e_del_fdir_entry(vsi, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2874 | break; |
| 2875 | default: |
| 2876 | break; |
| 2877 | } |
| 2878 | |
| 2879 | return ret; |
| 2880 | } |
| 2881 | |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2882 | /** |
| 2883 | * i40e_max_channels - get Max number of combined channels supported |
| 2884 | * @vsi: vsi pointer |
| 2885 | **/ |
| 2886 | static unsigned int i40e_max_channels(struct i40e_vsi *vsi) |
| 2887 | { |
| 2888 | /* TODO: This code assumes DCB and FD is disabled for now. */ |
| 2889 | return vsi->alloc_queue_pairs; |
| 2890 | } |
| 2891 | |
| 2892 | /** |
| 2893 | * i40e_get_channels - Get the current channels enabled and max supported etc. |
| 2894 | * @netdev: network interface device structure |
| 2895 | * @ch: ethtool channels structure |
| 2896 | * |
| 2897 | * We don't support separate tx and rx queues as channels. The other count |
| 2898 | * represents how many queues are being used for control. max_combined counts |
| 2899 | * how many queue pairs we can support. They may not be mapped 1 to 1 with |
| 2900 | * q_vectors since we support a lot more queue pairs than q_vectors. |
| 2901 | **/ |
| 2902 | static void i40e_get_channels(struct net_device *dev, |
| 2903 | struct ethtool_channels *ch) |
| 2904 | { |
| 2905 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 2906 | struct i40e_vsi *vsi = np->vsi; |
| 2907 | struct i40e_pf *pf = vsi->back; |
| 2908 | |
| 2909 | /* report maximum channels */ |
| 2910 | ch->max_combined = i40e_max_channels(vsi); |
| 2911 | |
| 2912 | /* report info for other vector */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2913 | ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0; |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2914 | ch->max_other = ch->other_count; |
| 2915 | |
| 2916 | /* Note: This code assumes DCB is disabled for now. */ |
| 2917 | ch->combined_count = vsi->num_queue_pairs; |
| 2918 | } |
| 2919 | |
| 2920 | /** |
| 2921 | * i40e_set_channels - Set the new channels count. |
| 2922 | * @netdev: network interface device structure |
| 2923 | * @ch: ethtool channels structure |
| 2924 | * |
| 2925 | * The new channels count may not be the same as requested by the user |
| 2926 | * since it gets rounded down to a power of 2 value. |
| 2927 | **/ |
| 2928 | static int i40e_set_channels(struct net_device *dev, |
| 2929 | struct ethtool_channels *ch) |
| 2930 | { |
Jacob Keller | 59826d9 | 2016-07-27 12:02:35 -0700 | [diff] [blame] | 2931 | const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET; |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2932 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 2933 | unsigned int count = ch->combined_count; |
| 2934 | struct i40e_vsi *vsi = np->vsi; |
| 2935 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | 59826d9 | 2016-07-27 12:02:35 -0700 | [diff] [blame] | 2936 | struct i40e_fdir_filter *rule; |
| 2937 | struct hlist_node *node2; |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2938 | int new_count; |
Jacob Keller | 59826d9 | 2016-07-27 12:02:35 -0700 | [diff] [blame] | 2939 | int err = 0; |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2940 | |
| 2941 | /* We do not support setting channels for any other VSI at present */ |
| 2942 | if (vsi->type != I40E_VSI_MAIN) |
| 2943 | return -EINVAL; |
| 2944 | |
| 2945 | /* verify they are not requesting separate vectors */ |
| 2946 | if (!count || ch->rx_count || ch->tx_count) |
| 2947 | return -EINVAL; |
| 2948 | |
| 2949 | /* verify other_count has not changed */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2950 | if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0)) |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2951 | return -EINVAL; |
| 2952 | |
| 2953 | /* verify the number of channels does not exceed hardware limits */ |
| 2954 | if (count > i40e_max_channels(vsi)) |
| 2955 | return -EINVAL; |
| 2956 | |
Jacob Keller | 59826d9 | 2016-07-27 12:02:35 -0700 | [diff] [blame] | 2957 | /* verify that the number of channels does not invalidate any current |
| 2958 | * flow director rules |
| 2959 | */ |
| 2960 | hlist_for_each_entry_safe(rule, node2, |
| 2961 | &pf->fdir_filter_list, fdir_node) { |
| 2962 | if (rule->dest_ctl != drop && count <= rule->q_index) { |
| 2963 | dev_warn(&pf->pdev->dev, |
| 2964 | "Existing user defined filter %d assigns flow to queue %d\n", |
| 2965 | rule->fd_id, rule->q_index); |
| 2966 | err = -EINVAL; |
| 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | if (err) { |
| 2971 | dev_err(&pf->pdev->dev, |
| 2972 | "Existing filter rules must be deleted to reduce combined channel count to %d\n", |
| 2973 | count); |
| 2974 | return err; |
| 2975 | } |
| 2976 | |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2977 | /* update feature limits from largest to smallest supported values */ |
| 2978 | /* TODO: Flow director limit, DCB etc */ |
| 2979 | |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2980 | /* use rss_reconfig to rebuild with new queue count and update traffic |
| 2981 | * class queue mapping |
| 2982 | */ |
| 2983 | new_count = i40e_reconfig_rss_queues(pf, count); |
Anjali Singhai Jain | 5f90f42 | 2013-12-21 05:44:43 +0000 | [diff] [blame] | 2984 | if (new_count > 0) |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2985 | return 0; |
| 2986 | else |
| 2987 | return -EINVAL; |
| 2988 | } |
| 2989 | |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 2990 | /** |
| 2991 | * i40e_get_rxfh_key_size - get the RSS hash key size |
| 2992 | * @netdev: network interface device structure |
| 2993 | * |
| 2994 | * Returns the table size. |
| 2995 | **/ |
| 2996 | static u32 i40e_get_rxfh_key_size(struct net_device *netdev) |
| 2997 | { |
| 2998 | return I40E_HKEY_ARRAY_SIZE; |
| 2999 | } |
| 3000 | |
| 3001 | /** |
| 3002 | * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size |
| 3003 | * @netdev: network interface device structure |
| 3004 | * |
| 3005 | * Returns the table size. |
| 3006 | **/ |
| 3007 | static u32 i40e_get_rxfh_indir_size(struct net_device *netdev) |
| 3008 | { |
| 3009 | return I40E_HLUT_ARRAY_SIZE; |
| 3010 | } |
| 3011 | |
| 3012 | static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, |
| 3013 | u8 *hfunc) |
| 3014 | { |
| 3015 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3016 | struct i40e_vsi *vsi = np->vsi; |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 3017 | u8 *lut, *seed = NULL; |
| 3018 | int ret; |
| 3019 | u16 i; |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3020 | |
| 3021 | if (hfunc) |
| 3022 | *hfunc = ETH_RSS_HASH_TOP; |
| 3023 | |
| 3024 | if (!indir) |
| 3025 | return 0; |
| 3026 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 3027 | seed = key; |
| 3028 | lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL); |
| 3029 | if (!lut) |
| 3030 | return -ENOMEM; |
| 3031 | ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE); |
| 3032 | if (ret) |
| 3033 | goto out; |
| 3034 | for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++) |
| 3035 | indir[i] = (u32)(lut[i]); |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3036 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 3037 | out: |
| 3038 | kfree(lut); |
| 3039 | |
| 3040 | return ret; |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | /** |
| 3044 | * i40e_set_rxfh - set the rx flow hash indirection table |
| 3045 | * @netdev: network interface device structure |
| 3046 | * @indir: indirection table |
| 3047 | * @key: hash key |
| 3048 | * |
Mitch Williams | cd494fb | 2015-07-10 19:36:04 -0400 | [diff] [blame] | 3049 | * Returns -EINVAL if the table specifies an invalid queue id, otherwise |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3050 | * returns 0 after programming the table. |
| 3051 | **/ |
| 3052 | static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir, |
| 3053 | const u8 *key, const u8 hfunc) |
| 3054 | { |
| 3055 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3056 | struct i40e_vsi *vsi = np->vsi; |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 3057 | struct i40e_pf *pf = vsi->back; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 3058 | u8 *seed = NULL; |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 3059 | u16 i; |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3060 | |
| 3061 | if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) |
| 3062 | return -EOPNOTSUPP; |
| 3063 | |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3064 | if (key) { |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 3065 | if (!vsi->rss_hkey_user) { |
| 3066 | vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE, |
| 3067 | GFP_KERNEL); |
| 3068 | if (!vsi->rss_hkey_user) |
| 3069 | return -ENOMEM; |
| 3070 | } |
| 3071 | memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE); |
| 3072 | seed = vsi->rss_hkey_user; |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3073 | } |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 3074 | if (!vsi->rss_lut_user) { |
| 3075 | vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL); |
| 3076 | if (!vsi->rss_lut_user) |
| 3077 | return -ENOMEM; |
| 3078 | } |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 3079 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 3080 | /* Each 32 bits pointed by 'indir' is stored with a lut entry */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 3081 | if (indir) |
| 3082 | for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++) |
| 3083 | vsi->rss_lut_user[i] = (u8)(indir[i]); |
| 3084 | else |
| 3085 | i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE, |
| 3086 | vsi->rss_size); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 3087 | |
| 3088 | return i40e_config_rss(vsi, seed, vsi->rss_lut_user, |
| 3089 | I40E_HLUT_ARRAY_SIZE); |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3090 | } |
| 3091 | |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 3092 | /** |
| 3093 | * i40e_get_priv_flags - report device private flags |
| 3094 | * @dev: network interface device structure |
| 3095 | * |
| 3096 | * The get string set count and the string set should be matched for each |
| 3097 | * flag returned. Add new strings for each flag to the i40e_priv_flags_strings |
| 3098 | * array. |
| 3099 | * |
| 3100 | * Returns a u32 bitmap of flags. |
| 3101 | **/ |
Jesse Brandeburg | 5bbc330 | 2015-02-26 16:15:20 +0000 | [diff] [blame] | 3102 | static u32 i40e_get_priv_flags(struct net_device *dev) |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 3103 | { |
| 3104 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 3105 | struct i40e_vsi *vsi = np->vsi; |
| 3106 | struct i40e_pf *pf = vsi->back; |
| 3107 | u32 ret_flags = 0; |
| 3108 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 3109 | ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ? |
| 3110 | I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0; |
Jesse Brandeburg | ef17178 | 2015-09-03 17:18:49 -0400 | [diff] [blame] | 3111 | ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ? |
| 3112 | I40E_PRIV_FLAGS_FD_ATR : 0; |
Shannon Nelson | 1cdfd88 | 2015-09-28 14:12:34 -0400 | [diff] [blame] | 3113 | ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ? |
| 3114 | I40E_PRIV_FLAGS_VEB_STATS : 0; |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 3115 | ret_flags |= pf->hw_disabled_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ? |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 3116 | 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT; |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 3117 | if (pf->hw.pf_id == 0) { |
| 3118 | ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ? |
| 3119 | I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0; |
| 3120 | } |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 3121 | |
| 3122 | return ret_flags; |
| 3123 | } |
| 3124 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 3125 | /** |
| 3126 | * i40e_set_priv_flags - set private flags |
| 3127 | * @dev: network interface device structure |
| 3128 | * @flags: bit flags to be set |
| 3129 | **/ |
| 3130 | static int i40e_set_priv_flags(struct net_device *dev, u32 flags) |
| 3131 | { |
| 3132 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 3133 | struct i40e_vsi *vsi = np->vsi; |
| 3134 | struct i40e_pf *pf = vsi->back; |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 3135 | u16 sw_flags = 0, valid_flags = 0; |
Jesse Brandeburg | 827de39 | 2015-11-06 15:26:07 -0800 | [diff] [blame] | 3136 | bool reset_required = false; |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 3137 | bool promisc_change = false; |
| 3138 | int ret; |
Jesse Brandeburg | 827de39 | 2015-11-06 15:26:07 -0800 | [diff] [blame] | 3139 | |
| 3140 | /* NOTE: MFP is not settable */ |
| 3141 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 3142 | if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG) |
| 3143 | pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED; |
| 3144 | else |
| 3145 | pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED; |
| 3146 | |
Jesse Brandeburg | ef17178 | 2015-09-03 17:18:49 -0400 | [diff] [blame] | 3147 | /* allow the user to control the state of the Flow |
| 3148 | * Director ATR (Application Targeted Routing) feature |
| 3149 | * of the driver |
| 3150 | */ |
| 3151 | if (flags & I40E_PRIV_FLAGS_FD_ATR) { |
| 3152 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 3153 | } else { |
| 3154 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 3155 | pf->hw_disabled_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 3156 | |
| 3157 | /* flush current ATR settings */ |
| 3158 | set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
Jesse Brandeburg | ef17178 | 2015-09-03 17:18:49 -0400 | [diff] [blame] | 3159 | } |
| 3160 | |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 3161 | if ((flags & I40E_PRIV_FLAGS_VEB_STATS) && |
| 3162 | !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { |
Shannon Nelson | 1cdfd88 | 2015-09-28 14:12:34 -0400 | [diff] [blame] | 3163 | pf->flags |= I40E_FLAG_VEB_STATS_ENABLED; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 3164 | reset_required = true; |
| 3165 | } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) && |
| 3166 | (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { |
Shannon Nelson | 1cdfd88 | 2015-09-28 14:12:34 -0400 | [diff] [blame] | 3167 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 3168 | reset_required = true; |
| 3169 | } |
Shannon Nelson | 1cdfd88 | 2015-09-28 14:12:34 -0400 | [diff] [blame] | 3170 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 3171 | if (pf->hw.pf_id == 0) { |
| 3172 | if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) && |
| 3173 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) { |
| 3174 | pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT; |
| 3175 | promisc_change = true; |
| 3176 | } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) && |
| 3177 | (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) { |
| 3178 | pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT; |
| 3179 | promisc_change = true; |
| 3180 | } |
| 3181 | } |
| 3182 | if (promisc_change) { |
| 3183 | if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 3184 | sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 3185 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 3186 | ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags, |
| 3187 | NULL); |
| 3188 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 3189 | dev_info(&pf->pdev->dev, |
| 3190 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 3191 | i40e_stat_str(&pf->hw, ret), |
| 3192 | i40e_aq_str(&pf->hw, |
| 3193 | pf->hw.aq.asq_last_status)); |
| 3194 | /* not a fatal problem, just keep going */ |
| 3195 | } |
| 3196 | } |
| 3197 | |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 3198 | if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) && |
| 3199 | (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE)) |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 3200 | pf->hw_disabled_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 3201 | else |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 3202 | pf->hw_disabled_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 3203 | |
Jesse Brandeburg | 827de39 | 2015-11-06 15:26:07 -0800 | [diff] [blame] | 3204 | /* if needed, issue reset to cause things to take effect */ |
| 3205 | if (reset_required) |
| 3206 | i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED)); |
| 3207 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 3208 | return 0; |
| 3209 | } |
| 3210 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3211 | static const struct ethtool_ops i40e_ethtool_ops = { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3212 | .get_drvinfo = i40e_get_drvinfo, |
| 3213 | .get_regs_len = i40e_get_regs_len, |
| 3214 | .get_regs = i40e_get_regs, |
| 3215 | .nway_reset = i40e_nway_reset, |
| 3216 | .get_link = ethtool_op_get_link, |
| 3217 | .get_wol = i40e_get_wol, |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 3218 | .set_wol = i40e_set_wol, |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 3219 | .set_eeprom = i40e_set_eeprom, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3220 | .get_eeprom_len = i40e_get_eeprom_len, |
| 3221 | .get_eeprom = i40e_get_eeprom, |
| 3222 | .get_ringparam = i40e_get_ringparam, |
| 3223 | .set_ringparam = i40e_set_ringparam, |
| 3224 | .get_pauseparam = i40e_get_pauseparam, |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 3225 | .set_pauseparam = i40e_set_pauseparam, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3226 | .get_msglevel = i40e_get_msglevel, |
| 3227 | .set_msglevel = i40e_set_msglevel, |
| 3228 | .get_rxnfc = i40e_get_rxnfc, |
| 3229 | .set_rxnfc = i40e_set_rxnfc, |
| 3230 | .self_test = i40e_diag_test, |
| 3231 | .get_strings = i40e_get_strings, |
| 3232 | .set_phys_id = i40e_set_phys_id, |
| 3233 | .get_sset_count = i40e_get_sset_count, |
| 3234 | .get_ethtool_stats = i40e_get_ethtool_stats, |
| 3235 | .get_coalesce = i40e_get_coalesce, |
| 3236 | .set_coalesce = i40e_set_coalesce, |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3237 | .get_rxfh_key_size = i40e_get_rxfh_key_size, |
| 3238 | .get_rxfh_indir_size = i40e_get_rxfh_indir_size, |
| 3239 | .get_rxfh = i40e_get_rxfh, |
| 3240 | .set_rxfh = i40e_set_rxfh, |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 3241 | .get_channels = i40e_get_channels, |
| 3242 | .set_channels = i40e_set_channels, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3243 | .get_ts_info = i40e_get_ts_info, |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 3244 | .get_priv_flags = i40e_get_priv_flags, |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 3245 | .set_priv_flags = i40e_set_priv_flags, |
Kan Liang | be280ba | 2016-02-19 09:24:05 -0500 | [diff] [blame] | 3246 | .get_per_queue_coalesce = i40e_get_per_queue_coalesce, |
Kan Liang | f3757a4 | 2016-02-19 09:24:06 -0500 | [diff] [blame] | 3247 | .set_per_queue_coalesce = i40e_set_per_queue_coalesce, |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 3248 | .get_link_ksettings = i40e_get_link_ksettings, |
| 3249 | .set_link_ksettings = i40e_set_link_ksettings, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3250 | }; |
| 3251 | |
| 3252 | void i40e_set_ethtool_ops(struct net_device *netdev) |
| 3253 | { |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 3254 | netdev->ethtool_ops = &i40e_ethtool_ops; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3255 | } |