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