Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4 | Copyright(c) 1999 - 2016 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [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 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Jacob Keller | b89aae7 | 2014-02-22 01:23:50 +0000 | [diff] [blame] | 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | /* ethtool support for ixgbe */ |
| 30 | |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 31 | #include <linux/interrupt.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 32 | #include <linux/types.h> |
| 33 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 35 | #include <linux/pci.h> |
| 36 | #include <linux/netdevice.h> |
| 37 | #include <linux/ethtool.h> |
| 38 | #include <linux/vmalloc.h> |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 39 | #include <linux/highmem.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 40 | #include <linux/uaccess.h> |
| 41 | |
| 42 | #include "ixgbe.h" |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 43 | #include "ixgbe_phy.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 44 | |
| 45 | |
| 46 | #define IXGBE_ALL_RAR_ENTRIES 16 |
| 47 | |
Ajit Khaparde | 29c3a05 | 2009-10-13 01:47:33 +0000 | [diff] [blame] | 48 | enum {NETDEV_STATS, IXGBE_STATS}; |
| 49 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 50 | struct ixgbe_stats { |
| 51 | char stat_string[ETH_GSTRING_LEN]; |
Ajit Khaparde | 29c3a05 | 2009-10-13 01:47:33 +0000 | [diff] [blame] | 52 | int type; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 53 | int sizeof_stat; |
| 54 | int stat_offset; |
| 55 | }; |
| 56 | |
Ajit Khaparde | 29c3a05 | 2009-10-13 01:47:33 +0000 | [diff] [blame] | 57 | #define IXGBE_STAT(m) IXGBE_STATS, \ |
| 58 | sizeof(((struct ixgbe_adapter *)0)->m), \ |
| 59 | offsetof(struct ixgbe_adapter, m) |
| 60 | #define IXGBE_NETDEV_STAT(m) NETDEV_STATS, \ |
Eric Dumazet | 55bad82 | 2010-07-23 13:44:21 +0000 | [diff] [blame] | 61 | sizeof(((struct rtnl_link_stats64 *)0)->m), \ |
| 62 | offsetof(struct rtnl_link_stats64, m) |
Ajit Khaparde | 29c3a05 | 2009-10-13 01:47:33 +0000 | [diff] [blame] | 63 | |
Stephen Hemminger | 1bba2e8 | 2012-01-05 06:29:54 +0000 | [diff] [blame] | 64 | static const struct ixgbe_stats ixgbe_gstrings_stats[] = { |
Eric Dumazet | 55bad82 | 2010-07-23 13:44:21 +0000 | [diff] [blame] | 65 | {"rx_packets", IXGBE_NETDEV_STAT(rx_packets)}, |
| 66 | {"tx_packets", IXGBE_NETDEV_STAT(tx_packets)}, |
| 67 | {"rx_bytes", IXGBE_NETDEV_STAT(rx_bytes)}, |
| 68 | {"tx_bytes", IXGBE_NETDEV_STAT(tx_bytes)}, |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 69 | {"rx_pkts_nic", IXGBE_STAT(stats.gprc)}, |
| 70 | {"tx_pkts_nic", IXGBE_STAT(stats.gptc)}, |
| 71 | {"rx_bytes_nic", IXGBE_STAT(stats.gorc)}, |
| 72 | {"tx_bytes_nic", IXGBE_STAT(stats.gotc)}, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 73 | {"lsc_int", IXGBE_STAT(lsc_int)}, |
| 74 | {"tx_busy", IXGBE_STAT(tx_busy)}, |
| 75 | {"non_eop_descs", IXGBE_STAT(non_eop_descs)}, |
Eric Dumazet | 55bad82 | 2010-07-23 13:44:21 +0000 | [diff] [blame] | 76 | {"rx_errors", IXGBE_NETDEV_STAT(rx_errors)}, |
| 77 | {"tx_errors", IXGBE_NETDEV_STAT(tx_errors)}, |
| 78 | {"rx_dropped", IXGBE_NETDEV_STAT(rx_dropped)}, |
| 79 | {"tx_dropped", IXGBE_NETDEV_STAT(tx_dropped)}, |
| 80 | {"multicast", IXGBE_NETDEV_STAT(multicast)}, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 81 | {"broadcast", IXGBE_STAT(stats.bprc)}, |
| 82 | {"rx_no_buffer_count", IXGBE_STAT(stats.rnbc[0]) }, |
Eric Dumazet | 55bad82 | 2010-07-23 13:44:21 +0000 | [diff] [blame] | 83 | {"collisions", IXGBE_NETDEV_STAT(collisions)}, |
| 84 | {"rx_over_errors", IXGBE_NETDEV_STAT(rx_over_errors)}, |
| 85 | {"rx_crc_errors", IXGBE_NETDEV_STAT(rx_crc_errors)}, |
| 86 | {"rx_frame_errors", IXGBE_NETDEV_STAT(rx_frame_errors)}, |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 87 | {"hw_rsc_aggregated", IXGBE_STAT(rsc_total_count)}, |
| 88 | {"hw_rsc_flushed", IXGBE_STAT(rsc_total_flush)}, |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 89 | {"fdir_match", IXGBE_STAT(stats.fdirmatch)}, |
| 90 | {"fdir_miss", IXGBE_STAT(stats.fdirmiss)}, |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 91 | {"fdir_overflow", IXGBE_STAT(fdir_overflow)}, |
Eric Dumazet | 55bad82 | 2010-07-23 13:44:21 +0000 | [diff] [blame] | 92 | {"rx_fifo_errors", IXGBE_NETDEV_STAT(rx_fifo_errors)}, |
| 93 | {"rx_missed_errors", IXGBE_NETDEV_STAT(rx_missed_errors)}, |
| 94 | {"tx_aborted_errors", IXGBE_NETDEV_STAT(tx_aborted_errors)}, |
| 95 | {"tx_carrier_errors", IXGBE_NETDEV_STAT(tx_carrier_errors)}, |
| 96 | {"tx_fifo_errors", IXGBE_NETDEV_STAT(tx_fifo_errors)}, |
| 97 | {"tx_heartbeat_errors", IXGBE_NETDEV_STAT(tx_heartbeat_errors)}, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 98 | {"tx_timeout_count", IXGBE_STAT(tx_timeout_count)}, |
| 99 | {"tx_restart_queue", IXGBE_STAT(restart_queue)}, |
| 100 | {"rx_long_length_errors", IXGBE_STAT(stats.roc)}, |
| 101 | {"rx_short_length_errors", IXGBE_STAT(stats.ruc)}, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 102 | {"tx_flow_control_xon", IXGBE_STAT(stats.lxontxc)}, |
| 103 | {"rx_flow_control_xon", IXGBE_STAT(stats.lxonrxc)}, |
| 104 | {"tx_flow_control_xoff", IXGBE_STAT(stats.lxofftxc)}, |
| 105 | {"rx_flow_control_xoff", IXGBE_STAT(stats.lxoffrxc)}, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 106 | {"rx_csum_offload_errors", IXGBE_STAT(hw_csum_rx_error)}, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 107 | {"alloc_rx_page_failed", IXGBE_STAT(alloc_rx_page_failed)}, |
| 108 | {"alloc_rx_buff_failed", IXGBE_STAT(alloc_rx_buff_failed)}, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 109 | {"rx_no_dma_resources", IXGBE_STAT(hw_rx_no_dma_resources)}, |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 110 | {"os2bmc_rx_by_bmc", IXGBE_STAT(stats.o2bgptc)}, |
| 111 | {"os2bmc_tx_by_bmc", IXGBE_STAT(stats.b2ospc)}, |
| 112 | {"os2bmc_tx_by_host", IXGBE_STAT(stats.o2bspc)}, |
| 113 | {"os2bmc_rx_by_host", IXGBE_STAT(stats.b2ogprc)}, |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 114 | #ifdef IXGBE_FCOE |
| 115 | {"fcoe_bad_fccrc", IXGBE_STAT(stats.fccrc)}, |
| 116 | {"rx_fcoe_dropped", IXGBE_STAT(stats.fcoerpdc)}, |
| 117 | {"rx_fcoe_packets", IXGBE_STAT(stats.fcoeprc)}, |
| 118 | {"rx_fcoe_dwords", IXGBE_STAT(stats.fcoedwrc)}, |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 119 | {"fcoe_noddp", IXGBE_STAT(stats.fcoe_noddp)}, |
| 120 | {"fcoe_noddp_ext_buff", IXGBE_STAT(stats.fcoe_noddp_ext_buff)}, |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 121 | {"tx_fcoe_packets", IXGBE_STAT(stats.fcoeptc)}, |
| 122 | {"tx_fcoe_dwords", IXGBE_STAT(stats.fcoedwtc)}, |
| 123 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 126 | /* ixgbe allocates num_tx_queues and num_rx_queues symmetrically so |
| 127 | * we set the num_rx_queues to evaluate to num_tx_queues. This is |
| 128 | * used because we do not have a good way to get the max number of |
| 129 | * rx queues with CONFIG_RPS disabled. |
| 130 | */ |
| 131 | #define IXGBE_NUM_RX_QUEUES netdev->num_tx_queues |
| 132 | |
| 133 | #define IXGBE_QUEUE_STATS_LEN ( \ |
| 134 | (netdev->num_tx_queues + IXGBE_NUM_RX_QUEUES) * \ |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 135 | (sizeof(struct ixgbe_queue_stats) / sizeof(u64))) |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 136 | #define IXGBE_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbe_gstrings_stats) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 137 | #define IXGBE_PB_STATS_LEN ( \ |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 138 | (sizeof(((struct ixgbe_adapter *)0)->stats.pxonrxc) + \ |
| 139 | sizeof(((struct ixgbe_adapter *)0)->stats.pxontxc) + \ |
| 140 | sizeof(((struct ixgbe_adapter *)0)->stats.pxoffrxc) + \ |
| 141 | sizeof(((struct ixgbe_adapter *)0)->stats.pxofftxc)) \ |
| 142 | / sizeof(u64)) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 143 | #define IXGBE_STATS_LEN (IXGBE_GLOBAL_STATS_LEN + \ |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 144 | IXGBE_PB_STATS_LEN + \ |
| 145 | IXGBE_QUEUE_STATS_LEN) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 146 | |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 147 | static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = { |
| 148 | "Register test (offline)", "Eeprom test (offline)", |
| 149 | "Interrupt test (offline)", "Loopback test (offline)", |
| 150 | "Link test (on/offline)" |
| 151 | }; |
| 152 | #define IXGBE_TEST_LEN sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN |
| 153 | |
Veola Nazareth | 695b816 | 2015-11-11 16:22:59 -0700 | [diff] [blame] | 154 | /* currently supported speeds for 10G */ |
| 155 | #define ADVRTSD_MSK_10G (SUPPORTED_10000baseT_Full | \ |
| 156 | SUPPORTED_10000baseKX4_Full | \ |
| 157 | SUPPORTED_10000baseKR_Full) |
| 158 | |
| 159 | #define ixgbe_isbackplane(type) ((type) == ixgbe_media_type_backplane) |
| 160 | |
| 161 | static u32 ixgbe_get_supported_10gtypes(struct ixgbe_hw *hw) |
| 162 | { |
| 163 | if (!ixgbe_isbackplane(hw->phy.media_type)) |
| 164 | return SUPPORTED_10000baseT_Full; |
| 165 | |
| 166 | switch (hw->device_id) { |
| 167 | case IXGBE_DEV_ID_82598: |
| 168 | case IXGBE_DEV_ID_82599_KX4: |
| 169 | case IXGBE_DEV_ID_82599_KX4_MEZZ: |
| 170 | case IXGBE_DEV_ID_X550EM_X_KX4: |
| 171 | return SUPPORTED_10000baseKX4_Full; |
| 172 | case IXGBE_DEV_ID_82598_BX: |
| 173 | case IXGBE_DEV_ID_82599_KR: |
| 174 | case IXGBE_DEV_ID_X550EM_X_KR: |
| 175 | return SUPPORTED_10000baseKR_Full; |
| 176 | default: |
| 177 | return SUPPORTED_10000baseKX4_Full | |
| 178 | SUPPORTED_10000baseKR_Full; |
| 179 | } |
| 180 | } |
| 181 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 182 | static int ixgbe_get_settings(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 183 | struct ethtool_cmd *ecmd) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 184 | { |
| 185 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Ayyappan Veeraiyan | 735441f | 2008-02-01 15:58:54 -0800 | [diff] [blame] | 186 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 187 | ixgbe_link_speed supported_link; |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 188 | bool autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 189 | |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 190 | hw->mac.ops.get_link_capabilities(hw, &supported_link, &autoneg); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 191 | |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 192 | /* set the supported link speeds */ |
| 193 | if (supported_link & IXGBE_LINK_SPEED_10GB_FULL) |
Veola Nazareth | 695b816 | 2015-11-11 16:22:59 -0700 | [diff] [blame] | 194 | ecmd->supported |= ixgbe_get_supported_10gtypes(hw); |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 195 | if (supported_link & IXGBE_LINK_SPEED_1GB_FULL) |
Veola Nazareth | 27b23f9 | 2016-08-20 19:35:37 -0700 | [diff] [blame] | 196 | ecmd->supported |= (ixgbe_isbackplane(hw->phy.media_type)) ? |
| 197 | SUPPORTED_1000baseKX_Full : |
| 198 | SUPPORTED_1000baseT_Full; |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 199 | if (supported_link & IXGBE_LINK_SPEED_100_FULL) |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 200 | ecmd->supported |= SUPPORTED_100baseT_Full; |
| 201 | if (supported_link & IXGBE_LINK_SPEED_10_FULL) |
| 202 | ecmd->supported |= SUPPORTED_10baseT_Full; |
Atita Shirwaikar | 1b1c0a4 | 2011-01-05 02:00:55 +0000 | [diff] [blame] | 203 | |
Veola Nazareth | 695b816 | 2015-11-11 16:22:59 -0700 | [diff] [blame] | 204 | /* default advertised speed if phy.autoneg_advertised isn't set */ |
| 205 | ecmd->advertising = ecmd->supported; |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 206 | /* set the advertised speeds */ |
| 207 | if (hw->phy.autoneg_advertised) { |
Veola Nazareth | 695b816 | 2015-11-11 16:22:59 -0700 | [diff] [blame] | 208 | ecmd->advertising = 0; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 209 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10_FULL) |
| 210 | ecmd->advertising |= ADVERTISED_10baseT_Full; |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 211 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) |
| 212 | ecmd->advertising |= ADVERTISED_100baseT_Full; |
| 213 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) |
Veola Nazareth | 695b816 | 2015-11-11 16:22:59 -0700 | [diff] [blame] | 214 | ecmd->advertising |= ecmd->supported & ADVRTSD_MSK_10G; |
| 215 | if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) { |
| 216 | if (ecmd->supported & SUPPORTED_1000baseKX_Full) |
| 217 | ecmd->advertising |= ADVERTISED_1000baseKX_Full; |
| 218 | else |
| 219 | ecmd->advertising |= ADVERTISED_1000baseT_Full; |
| 220 | } |
Ayyappan Veeraiyan | 735441f | 2008-02-01 15:58:54 -0800 | [diff] [blame] | 221 | } else { |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 222 | if (hw->phy.multispeed_fiber && !autoneg) { |
| 223 | if (supported_link & IXGBE_LINK_SPEED_10GB_FULL) |
| 224 | ecmd->advertising = ADVERTISED_10000baseT_Full; |
| 225 | } |
Ayyappan Veeraiyan | 735441f | 2008-02-01 15:58:54 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 228 | if (autoneg) { |
| 229 | ecmd->supported |= SUPPORTED_Autoneg; |
| 230 | ecmd->advertising |= ADVERTISED_Autoneg; |
| 231 | ecmd->autoneg = AUTONEG_ENABLE; |
| 232 | } else |
| 233 | ecmd->autoneg = AUTONEG_DISABLE; |
| 234 | |
| 235 | ecmd->transceiver = XCVR_EXTERNAL; |
| 236 | |
| 237 | /* Determine the remaining settings based on the PHY type. */ |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 238 | switch (adapter->hw.phy.type) { |
| 239 | case ixgbe_phy_tn: |
Don Skidmore | fe15e8e1 | 2010-11-16 19:27:16 -0800 | [diff] [blame] | 240 | case ixgbe_phy_aq: |
Don Skidmore | c2c78d5 | 2015-06-09 16:04:59 -0700 | [diff] [blame] | 241 | case ixgbe_phy_x550em_ext_t: |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 242 | case ixgbe_phy_fw: |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 243 | case ixgbe_phy_cu_unknown: |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 244 | ecmd->supported |= SUPPORTED_TP; |
| 245 | ecmd->advertising |= ADVERTISED_TP; |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 246 | ecmd->port = PORT_TP; |
| 247 | break; |
| 248 | case ixgbe_phy_qt: |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 249 | ecmd->supported |= SUPPORTED_FIBRE; |
| 250 | ecmd->advertising |= ADVERTISED_FIBRE; |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 251 | ecmd->port = PORT_FIBRE; |
| 252 | break; |
| 253 | case ixgbe_phy_nl: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 254 | case ixgbe_phy_sfp_passive_tyco: |
| 255 | case ixgbe_phy_sfp_passive_unknown: |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 256 | case ixgbe_phy_sfp_ftl: |
| 257 | case ixgbe_phy_sfp_avago: |
| 258 | case ixgbe_phy_sfp_intel: |
| 259 | case ixgbe_phy_sfp_unknown: |
Emil Tantilov | af56b4d | 2015-11-09 15:07:12 -0800 | [diff] [blame] | 260 | case ixgbe_phy_qsfp_passive_unknown: |
| 261 | case ixgbe_phy_qsfp_active_unknown: |
| 262 | case ixgbe_phy_qsfp_intel: |
| 263 | case ixgbe_phy_qsfp_unknown: |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 264 | /* SFP+ devices, further checking needed */ |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 265 | switch (adapter->hw.phy.sfp_type) { |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 266 | case ixgbe_sfp_type_da_cu: |
| 267 | case ixgbe_sfp_type_da_cu_core0: |
| 268 | case ixgbe_sfp_type_da_cu_core1: |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 269 | ecmd->supported |= SUPPORTED_FIBRE; |
| 270 | ecmd->advertising |= ADVERTISED_FIBRE; |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 271 | ecmd->port = PORT_DA; |
| 272 | break; |
| 273 | case ixgbe_sfp_type_sr: |
| 274 | case ixgbe_sfp_type_lr: |
| 275 | case ixgbe_sfp_type_srlr_core0: |
| 276 | case ixgbe_sfp_type_srlr_core1: |
Don Skidmore | 345be20 | 2013-04-11 06:23:34 +0000 | [diff] [blame] | 277 | case ixgbe_sfp_type_1g_sx_core0: |
| 278 | case ixgbe_sfp_type_1g_sx_core1: |
| 279 | case ixgbe_sfp_type_1g_lx_core0: |
| 280 | case ixgbe_sfp_type_1g_lx_core1: |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 281 | ecmd->supported |= SUPPORTED_FIBRE; |
| 282 | ecmd->advertising |= ADVERTISED_FIBRE; |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 283 | ecmd->port = PORT_FIBRE; |
| 284 | break; |
| 285 | case ixgbe_sfp_type_not_present: |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 286 | ecmd->supported |= SUPPORTED_FIBRE; |
| 287 | ecmd->advertising |= ADVERTISED_FIBRE; |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 288 | ecmd->port = PORT_NONE; |
| 289 | break; |
Don Skidmore | cb836a9 | 2010-06-29 18:30:59 +0000 | [diff] [blame] | 290 | case ixgbe_sfp_type_1g_cu_core0: |
| 291 | case ixgbe_sfp_type_1g_cu_core1: |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 292 | ecmd->supported |= SUPPORTED_TP; |
| 293 | ecmd->advertising |= ADVERTISED_TP; |
Don Skidmore | cb836a9 | 2010-06-29 18:30:59 +0000 | [diff] [blame] | 294 | ecmd->port = PORT_TP; |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 295 | break; |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 296 | case ixgbe_sfp_type_unknown: |
| 297 | default: |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 298 | ecmd->supported |= SUPPORTED_FIBRE; |
| 299 | ecmd->advertising |= ADVERTISED_FIBRE; |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 300 | ecmd->port = PORT_OTHER; |
| 301 | break; |
| 302 | } |
| 303 | break; |
| 304 | case ixgbe_phy_xaui: |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 305 | ecmd->supported |= SUPPORTED_FIBRE; |
| 306 | ecmd->advertising |= ADVERTISED_FIBRE; |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 307 | ecmd->port = PORT_NONE; |
| 308 | break; |
| 309 | case ixgbe_phy_unknown: |
| 310 | case ixgbe_phy_generic: |
| 311 | case ixgbe_phy_sfp_unsupported: |
| 312 | default: |
Jacob Keller | db01896 | 2012-06-08 06:59:17 +0000 | [diff] [blame] | 313 | ecmd->supported |= SUPPORTED_FIBRE; |
| 314 | ecmd->advertising |= ADVERTISED_FIBRE; |
PJ Waskiewicz | 3b8626b | 2009-11-25 00:11:54 +0000 | [diff] [blame] | 315 | ecmd->port = PORT_OTHER; |
| 316 | break; |
| 317 | } |
| 318 | |
Mark Rustad | ade3ccf | 2016-08-26 14:48:33 -0700 | [diff] [blame] | 319 | /* Indicate pause support */ |
| 320 | ecmd->supported |= SUPPORTED_Pause; |
| 321 | |
| 322 | switch (hw->fc.requested_mode) { |
| 323 | case ixgbe_fc_full: |
| 324 | ecmd->advertising |= ADVERTISED_Pause; |
| 325 | break; |
| 326 | case ixgbe_fc_rx_pause: |
| 327 | ecmd->advertising |= ADVERTISED_Pause | |
| 328 | ADVERTISED_Asym_Pause; |
| 329 | break; |
| 330 | case ixgbe_fc_tx_pause: |
| 331 | ecmd->advertising |= ADVERTISED_Asym_Pause; |
| 332 | break; |
| 333 | default: |
| 334 | ecmd->advertising &= ~(ADVERTISED_Pause | |
| 335 | ADVERTISED_Asym_Pause); |
| 336 | } |
| 337 | |
Emil Tantilov | 0e4d422 | 2015-12-03 15:20:06 -0800 | [diff] [blame] | 338 | if (netif_carrier_ok(netdev)) { |
| 339 | switch (adapter->link_speed) { |
Atita Shirwaikar | 1b1c0a4 | 2011-01-05 02:00:55 +0000 | [diff] [blame] | 340 | case IXGBE_LINK_SPEED_10GB_FULL: |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 341 | ethtool_cmd_speed_set(ecmd, SPEED_10000); |
Atita Shirwaikar | 1b1c0a4 | 2011-01-05 02:00:55 +0000 | [diff] [blame] | 342 | break; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 343 | case IXGBE_LINK_SPEED_2_5GB_FULL: |
| 344 | ethtool_cmd_speed_set(ecmd, SPEED_2500); |
| 345 | break; |
Atita Shirwaikar | 1b1c0a4 | 2011-01-05 02:00:55 +0000 | [diff] [blame] | 346 | case IXGBE_LINK_SPEED_1GB_FULL: |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 347 | ethtool_cmd_speed_set(ecmd, SPEED_1000); |
Atita Shirwaikar | 1b1c0a4 | 2011-01-05 02:00:55 +0000 | [diff] [blame] | 348 | break; |
| 349 | case IXGBE_LINK_SPEED_100_FULL: |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 350 | ethtool_cmd_speed_set(ecmd, SPEED_100); |
Atita Shirwaikar | 1b1c0a4 | 2011-01-05 02:00:55 +0000 | [diff] [blame] | 351 | break; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 352 | case IXGBE_LINK_SPEED_10_FULL: |
| 353 | ethtool_cmd_speed_set(ecmd, SPEED_10); |
| 354 | break; |
Atita Shirwaikar | 1b1c0a4 | 2011-01-05 02:00:55 +0000 | [diff] [blame] | 355 | default: |
| 356 | break; |
| 357 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 358 | ecmd->duplex = DUPLEX_FULL; |
| 359 | } else { |
Jiri Pirko | 537fae0 | 2014-06-06 14:17:00 +0200 | [diff] [blame] | 360 | ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN); |
| 361 | ecmd->duplex = DUPLEX_UNKNOWN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static int ixgbe_set_settings(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 368 | struct ethtool_cmd *ecmd) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 369 | { |
| 370 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Ayyappan Veeraiyan | 735441f | 2008-02-01 15:58:54 -0800 | [diff] [blame] | 371 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 372 | u32 advertised, old; |
Mallikarjuna R Chilakala | 7476601 | 2009-06-04 11:11:34 +0000 | [diff] [blame] | 373 | s32 err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 374 | |
Mallikarjuna R Chilakala | 7476601 | 2009-06-04 11:11:34 +0000 | [diff] [blame] | 375 | if ((hw->phy.media_type == ixgbe_media_type_copper) || |
Mallikarjuna R Chilakala | a380137 | 2009-06-30 11:44:16 +0000 | [diff] [blame] | 376 | (hw->phy.multispeed_fiber)) { |
Emil Tantilov | abcc80d | 2011-07-29 06:46:10 +0000 | [diff] [blame] | 377 | /* |
| 378 | * this function does not support duplex forcing, but can |
| 379 | * limit the advertising of the adapter to the specified speed |
| 380 | */ |
Emil Tantilov | abcc80d | 2011-07-29 06:46:10 +0000 | [diff] [blame] | 381 | if (ecmd->advertising & ~ecmd->supported) |
| 382 | return -EINVAL; |
| 383 | |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 384 | /* only allow one speed at a time if no autoneg */ |
| 385 | if (!ecmd->autoneg && hw->phy.multispeed_fiber) { |
| 386 | if (ecmd->advertising == |
| 387 | (ADVERTISED_10000baseT_Full | |
| 388 | ADVERTISED_1000baseT_Full)) |
| 389 | return -EINVAL; |
| 390 | } |
| 391 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 392 | old = hw->phy.autoneg_advertised; |
| 393 | advertised = 0; |
| 394 | if (ecmd->advertising & ADVERTISED_10000baseT_Full) |
| 395 | advertised |= IXGBE_LINK_SPEED_10GB_FULL; |
| 396 | |
| 397 | if (ecmd->advertising & ADVERTISED_1000baseT_Full) |
| 398 | advertised |= IXGBE_LINK_SPEED_1GB_FULL; |
| 399 | |
Emil Tantilov | 2b642ca | 2011-03-04 09:06:10 +0000 | [diff] [blame] | 400 | if (ecmd->advertising & ADVERTISED_100baseT_Full) |
| 401 | advertised |= IXGBE_LINK_SPEED_100_FULL; |
| 402 | |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 403 | if (ecmd->advertising & ADVERTISED_10baseT_Full) |
| 404 | advertised |= IXGBE_LINK_SPEED_10_FULL; |
| 405 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 406 | if (old == advertised) |
Mallikarjuna R Chilakala | 7476601 | 2009-06-04 11:11:34 +0000 | [diff] [blame] | 407 | return err; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 408 | /* this sets the link speed and restarts auto-neg */ |
Emil Tantilov | e3215f0 | 2014-10-28 05:50:03 +0000 | [diff] [blame] | 409 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 410 | usleep_range(1000, 2000); |
| 411 | |
Mallikarjuna R Chilakala | 7476601 | 2009-06-04 11:11:34 +0000 | [diff] [blame] | 412 | hw->mac.autotry_restart = true; |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 413 | err = hw->mac.ops.setup_link(hw, advertised, true); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 414 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 415 | e_info(probe, "setup link failed with code %d\n", err); |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 416 | hw->mac.ops.setup_link(hw, old, true); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 417 | } |
Emil Tantilov | e3215f0 | 2014-10-28 05:50:03 +0000 | [diff] [blame] | 418 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
Mallikarjuna R Chilakala | 7476601 | 2009-06-04 11:11:34 +0000 | [diff] [blame] | 419 | } else { |
| 420 | /* in this case we currently only support 10Gb/FULL */ |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 421 | u32 speed = ethtool_cmd_speed(ecmd); |
Mallikarjuna R Chilakala | 7476601 | 2009-06-04 11:11:34 +0000 | [diff] [blame] | 422 | if ((ecmd->autoneg == AUTONEG_ENABLE) || |
Mallikarjuna R Chilakala | a380137 | 2009-06-30 11:44:16 +0000 | [diff] [blame] | 423 | (ecmd->advertising != ADVERTISED_10000baseT_Full) || |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 424 | (speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL)) |
Mallikarjuna R Chilakala | 7476601 | 2009-06-04 11:11:34 +0000 | [diff] [blame] | 425 | return -EINVAL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Mallikarjuna R Chilakala | 7476601 | 2009-06-04 11:11:34 +0000 | [diff] [blame] | 428 | return err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static void ixgbe_get_pauseparam(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 432 | struct ethtool_pauseparam *pause) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 433 | { |
| 434 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 435 | struct ixgbe_hw *hw = &adapter->hw; |
| 436 | |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 437 | if (ixgbe_device_supports_autoneg_fc(hw) && |
| 438 | !hw->fc.disable_fc_autoneg) |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 439 | pause->autoneg = 1; |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 440 | else |
| 441 | pause->autoneg = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 442 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 443 | if (hw->fc.current_mode == ixgbe_fc_rx_pause) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 444 | pause->rx_pause = 1; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 445 | } else if (hw->fc.current_mode == ixgbe_fc_tx_pause) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 446 | pause->tx_pause = 1; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 447 | } else if (hw->fc.current_mode == ixgbe_fc_full) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 448 | pause->rx_pause = 1; |
| 449 | pause->tx_pause = 1; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | static int ixgbe_set_pauseparam(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 454 | struct ethtool_pauseparam *pause) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 455 | { |
| 456 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 457 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 458 | struct ixgbe_fc_info fc = hw->fc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 459 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 460 | /* 82598 does no support link flow control with DCB enabled */ |
| 461 | if ((hw->mac.type == ixgbe_mac_82598EB) && |
| 462 | (adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 463 | return -EINVAL; |
| 464 | |
Jacob Keller | db2adc2 | 2012-10-24 07:26:02 +0000 | [diff] [blame] | 465 | /* some devices do not support autoneg of link flow control */ |
| 466 | if ((pause->autoneg == AUTONEG_ENABLE) && |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 467 | !ixgbe_device_supports_autoneg_fc(hw)) |
Jacob Keller | db2adc2 | 2012-10-24 07:26:02 +0000 | [diff] [blame] | 468 | return -EINVAL; |
| 469 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 470 | fc.disable_fc_autoneg = (pause->autoneg != AUTONEG_ENABLE); |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 471 | |
Don Skidmore | 1c4f0ef | 2010-04-27 11:31:06 +0000 | [diff] [blame] | 472 | if ((pause->rx_pause && pause->tx_pause) || pause->autoneg) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 473 | fc.requested_mode = ixgbe_fc_full; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 474 | else if (pause->rx_pause && !pause->tx_pause) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 475 | fc.requested_mode = ixgbe_fc_rx_pause; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 476 | else if (!pause->rx_pause && pause->tx_pause) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 477 | fc.requested_mode = ixgbe_fc_tx_pause; |
Ayyappan Veeraiyan | 9c83b070 | 2008-02-01 15:58:59 -0800 | [diff] [blame] | 478 | else |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 479 | fc.requested_mode = ixgbe_fc_none; |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 480 | |
| 481 | /* if the thing changed then we'll update and use new autoneg */ |
| 482 | if (memcmp(&fc, &hw->fc, sizeof(struct ixgbe_fc_info))) { |
| 483 | hw->fc = fc; |
| 484 | if (netif_running(netdev)) |
| 485 | ixgbe_reinit_locked(adapter); |
| 486 | else |
| 487 | ixgbe_reset(adapter); |
| 488 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 493 | static u32 ixgbe_get_msglevel(struct net_device *netdev) |
| 494 | { |
| 495 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 496 | return adapter->msg_enable; |
| 497 | } |
| 498 | |
| 499 | static void ixgbe_set_msglevel(struct net_device *netdev, u32 data) |
| 500 | { |
| 501 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 502 | adapter->msg_enable = data; |
| 503 | } |
| 504 | |
| 505 | static int ixgbe_get_regs_len(struct net_device *netdev) |
| 506 | { |
Leonardo Potenza | 51e409f | 2013-10-01 04:33:52 -0700 | [diff] [blame] | 507 | #define IXGBE_REGS_LEN 1139 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 508 | return IXGBE_REGS_LEN * sizeof(u32); |
| 509 | } |
| 510 | |
| 511 | #define IXGBE_GET_STAT(_A_, _R_) _A_->stats._R_ |
| 512 | |
| 513 | static void ixgbe_get_regs(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 514 | struct ethtool_regs *regs, void *p) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 515 | { |
| 516 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 517 | struct ixgbe_hw *hw = &adapter->hw; |
| 518 | u32 *regs_buff = p; |
| 519 | u8 i; |
| 520 | |
| 521 | memset(p, 0, IXGBE_REGS_LEN * sizeof(u32)); |
| 522 | |
Emil Tantilov | c4a56de | 2013-04-19 09:31:17 +0000 | [diff] [blame] | 523 | regs->version = hw->mac.type << 24 | hw->revision_id << 16 | |
| 524 | hw->device_id; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 525 | |
| 526 | /* General Registers */ |
| 527 | regs_buff[0] = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 528 | regs_buff[1] = IXGBE_READ_REG(hw, IXGBE_STATUS); |
| 529 | regs_buff[2] = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 530 | regs_buff[3] = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 531 | regs_buff[4] = IXGBE_READ_REG(hw, IXGBE_EODSDP); |
| 532 | regs_buff[5] = IXGBE_READ_REG(hw, IXGBE_LEDCTL); |
| 533 | regs_buff[6] = IXGBE_READ_REG(hw, IXGBE_FRTIMER); |
| 534 | regs_buff[7] = IXGBE_READ_REG(hw, IXGBE_TCPTIMER); |
| 535 | |
| 536 | /* NVM Register */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 537 | regs_buff[8] = IXGBE_READ_REG(hw, IXGBE_EEC(hw)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 538 | regs_buff[9] = IXGBE_READ_REG(hw, IXGBE_EERD); |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 539 | regs_buff[10] = IXGBE_READ_REG(hw, IXGBE_FLA(hw)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 540 | regs_buff[11] = IXGBE_READ_REG(hw, IXGBE_EEMNGCTL); |
| 541 | regs_buff[12] = IXGBE_READ_REG(hw, IXGBE_EEMNGDATA); |
| 542 | regs_buff[13] = IXGBE_READ_REG(hw, IXGBE_FLMNGCTL); |
| 543 | regs_buff[14] = IXGBE_READ_REG(hw, IXGBE_FLMNGDATA); |
| 544 | regs_buff[15] = IXGBE_READ_REG(hw, IXGBE_FLMNGCNT); |
| 545 | regs_buff[16] = IXGBE_READ_REG(hw, IXGBE_FLOP); |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 546 | regs_buff[17] = IXGBE_READ_REG(hw, IXGBE_GRC(hw)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 547 | |
| 548 | /* Interrupt */ |
Jesse Brandeburg | 98c00a1 | 2008-09-11 19:56:41 -0700 | [diff] [blame] | 549 | /* don't read EICR because it can clear interrupt causes, instead |
| 550 | * read EICS which is a shadow but doesn't clear EICR */ |
| 551 | regs_buff[18] = IXGBE_READ_REG(hw, IXGBE_EICS); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 552 | regs_buff[19] = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 553 | regs_buff[20] = IXGBE_READ_REG(hw, IXGBE_EIMS); |
| 554 | regs_buff[21] = IXGBE_READ_REG(hw, IXGBE_EIMC); |
| 555 | regs_buff[22] = IXGBE_READ_REG(hw, IXGBE_EIAC); |
| 556 | regs_buff[23] = IXGBE_READ_REG(hw, IXGBE_EIAM); |
| 557 | regs_buff[24] = IXGBE_READ_REG(hw, IXGBE_EITR(0)); |
| 558 | regs_buff[25] = IXGBE_READ_REG(hw, IXGBE_IVAR(0)); |
| 559 | regs_buff[26] = IXGBE_READ_REG(hw, IXGBE_MSIXT); |
| 560 | regs_buff[27] = IXGBE_READ_REG(hw, IXGBE_MSIXPBA); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 561 | regs_buff[28] = IXGBE_READ_REG(hw, IXGBE_PBACL(0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 562 | regs_buff[29] = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 563 | |
| 564 | /* Flow Control */ |
| 565 | regs_buff[30] = IXGBE_READ_REG(hw, IXGBE_PFCTOP); |
Preethi Banala | 45a88df | 2016-04-21 11:40:35 -0700 | [diff] [blame] | 566 | for (i = 0; i < 4; i++) |
| 567 | regs_buff[31 + i] = IXGBE_READ_REG(hw, IXGBE_FCTTV(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 568 | for (i = 0; i < 8; i++) { |
| 569 | switch (hw->mac.type) { |
| 570 | case ixgbe_mac_82598EB: |
| 571 | regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTL(i)); |
| 572 | regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTH(i)); |
| 573 | break; |
| 574 | case ixgbe_mac_82599EB: |
Emil Tantilov | 80bb25e | 2011-07-27 04:16:29 +0000 | [diff] [blame] | 575 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 576 | case ixgbe_mac_X550: |
| 577 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 578 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 579 | regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTL_82599(i)); |
| 580 | regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i)); |
| 581 | break; |
| 582 | default: |
| 583 | break; |
| 584 | } |
| 585 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 586 | regs_buff[51] = IXGBE_READ_REG(hw, IXGBE_FCRTV); |
| 587 | regs_buff[52] = IXGBE_READ_REG(hw, IXGBE_TFCS); |
| 588 | |
| 589 | /* Receive DMA */ |
| 590 | for (i = 0; i < 64; i++) |
| 591 | regs_buff[53 + i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 592 | for (i = 0; i < 64; i++) |
| 593 | regs_buff[117 + i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 594 | for (i = 0; i < 64; i++) |
| 595 | regs_buff[181 + i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 596 | for (i = 0; i < 64; i++) |
| 597 | regs_buff[245 + i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 598 | for (i = 0; i < 64; i++) |
| 599 | regs_buff[309 + i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 600 | for (i = 0; i < 64; i++) |
| 601 | regs_buff[373 + i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 602 | for (i = 0; i < 16; i++) |
| 603 | regs_buff[437 + i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 604 | for (i = 0; i < 16; i++) |
| 605 | regs_buff[453 + i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 606 | regs_buff[469] = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 607 | for (i = 0; i < 8; i++) |
| 608 | regs_buff[470 + i] = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)); |
| 609 | regs_buff[478] = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 610 | regs_buff[479] = IXGBE_READ_REG(hw, IXGBE_DROPEN); |
| 611 | |
| 612 | /* Receive */ |
| 613 | regs_buff[480] = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 614 | regs_buff[481] = IXGBE_READ_REG(hw, IXGBE_RFCTL); |
| 615 | for (i = 0; i < 16; i++) |
| 616 | regs_buff[482 + i] = IXGBE_READ_REG(hw, IXGBE_RAL(i)); |
| 617 | for (i = 0; i < 16; i++) |
| 618 | regs_buff[498 + i] = IXGBE_READ_REG(hw, IXGBE_RAH(i)); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 619 | regs_buff[514] = IXGBE_READ_REG(hw, IXGBE_PSRTYPE(0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 620 | regs_buff[515] = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 621 | regs_buff[516] = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 622 | regs_buff[517] = IXGBE_READ_REG(hw, IXGBE_MCSTCTRL); |
| 623 | regs_buff[518] = IXGBE_READ_REG(hw, IXGBE_MRQC); |
| 624 | regs_buff[519] = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 625 | for (i = 0; i < 8; i++) |
| 626 | regs_buff[520 + i] = IXGBE_READ_REG(hw, IXGBE_IMIR(i)); |
| 627 | for (i = 0; i < 8; i++) |
| 628 | regs_buff[528 + i] = IXGBE_READ_REG(hw, IXGBE_IMIREXT(i)); |
| 629 | regs_buff[536] = IXGBE_READ_REG(hw, IXGBE_IMIRVP); |
| 630 | |
| 631 | /* Transmit */ |
| 632 | for (i = 0; i < 32; i++) |
| 633 | regs_buff[537 + i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 634 | for (i = 0; i < 32; i++) |
| 635 | regs_buff[569 + i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 636 | for (i = 0; i < 32; i++) |
| 637 | regs_buff[601 + i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 638 | for (i = 0; i < 32; i++) |
| 639 | regs_buff[633 + i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 640 | for (i = 0; i < 32; i++) |
| 641 | regs_buff[665 + i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 642 | for (i = 0; i < 32; i++) |
| 643 | regs_buff[697 + i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 644 | for (i = 0; i < 32; i++) |
| 645 | regs_buff[729 + i] = IXGBE_READ_REG(hw, IXGBE_TDWBAL(i)); |
| 646 | for (i = 0; i < 32; i++) |
| 647 | regs_buff[761 + i] = IXGBE_READ_REG(hw, IXGBE_TDWBAH(i)); |
| 648 | regs_buff[793] = IXGBE_READ_REG(hw, IXGBE_DTXCTL); |
| 649 | for (i = 0; i < 16; i++) |
| 650 | regs_buff[794 + i] = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i)); |
| 651 | regs_buff[810] = IXGBE_READ_REG(hw, IXGBE_TIPG); |
| 652 | for (i = 0; i < 8; i++) |
| 653 | regs_buff[811 + i] = IXGBE_READ_REG(hw, IXGBE_TXPBSIZE(i)); |
| 654 | regs_buff[819] = IXGBE_READ_REG(hw, IXGBE_MNGTXMAP); |
| 655 | |
| 656 | /* Wake Up */ |
| 657 | regs_buff[820] = IXGBE_READ_REG(hw, IXGBE_WUC); |
| 658 | regs_buff[821] = IXGBE_READ_REG(hw, IXGBE_WUFC); |
| 659 | regs_buff[822] = IXGBE_READ_REG(hw, IXGBE_WUS); |
| 660 | regs_buff[823] = IXGBE_READ_REG(hw, IXGBE_IPAV); |
| 661 | regs_buff[824] = IXGBE_READ_REG(hw, IXGBE_IP4AT); |
| 662 | regs_buff[825] = IXGBE_READ_REG(hw, IXGBE_IP6AT); |
| 663 | regs_buff[826] = IXGBE_READ_REG(hw, IXGBE_WUPL); |
| 664 | regs_buff[827] = IXGBE_READ_REG(hw, IXGBE_WUPM); |
PJ Waskiewicz | 11afc1b | 2009-02-27 15:44:30 +0000 | [diff] [blame] | 665 | regs_buff[828] = IXGBE_READ_REG(hw, IXGBE_FHFT(0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 666 | |
Alexander Duyck | 673ac60 | 2010-11-16 19:27:05 -0800 | [diff] [blame] | 667 | /* DCB */ |
Leonardo Potenza | 51e409f | 2013-10-01 04:33:52 -0700 | [diff] [blame] | 668 | regs_buff[829] = IXGBE_READ_REG(hw, IXGBE_RMCS); /* same as FCCFG */ |
| 669 | regs_buff[831] = IXGBE_READ_REG(hw, IXGBE_PDPMCS); /* same as RTTPCS */ |
| 670 | |
| 671 | switch (hw->mac.type) { |
| 672 | case ixgbe_mac_82598EB: |
| 673 | regs_buff[830] = IXGBE_READ_REG(hw, IXGBE_DPMCS); |
| 674 | regs_buff[832] = IXGBE_READ_REG(hw, IXGBE_RUPPBMR); |
| 675 | for (i = 0; i < 8; i++) |
| 676 | regs_buff[833 + i] = |
| 677 | IXGBE_READ_REG(hw, IXGBE_RT2CR(i)); |
| 678 | for (i = 0; i < 8; i++) |
| 679 | regs_buff[841 + i] = |
| 680 | IXGBE_READ_REG(hw, IXGBE_RT2SR(i)); |
| 681 | for (i = 0; i < 8; i++) |
| 682 | regs_buff[849 + i] = |
| 683 | IXGBE_READ_REG(hw, IXGBE_TDTQ2TCCR(i)); |
| 684 | for (i = 0; i < 8; i++) |
| 685 | regs_buff[857 + i] = |
| 686 | IXGBE_READ_REG(hw, IXGBE_TDTQ2TCSR(i)); |
| 687 | break; |
| 688 | case ixgbe_mac_82599EB: |
| 689 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 690 | case ixgbe_mac_X550: |
| 691 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 692 | case ixgbe_mac_x550em_a: |
Leonardo Potenza | 51e409f | 2013-10-01 04:33:52 -0700 | [diff] [blame] | 693 | regs_buff[830] = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 694 | regs_buff[832] = IXGBE_READ_REG(hw, IXGBE_RTRPCS); |
| 695 | for (i = 0; i < 8; i++) |
| 696 | regs_buff[833 + i] = |
| 697 | IXGBE_READ_REG(hw, IXGBE_RTRPT4C(i)); |
| 698 | for (i = 0; i < 8; i++) |
| 699 | regs_buff[841 + i] = |
| 700 | IXGBE_READ_REG(hw, IXGBE_RTRPT4S(i)); |
| 701 | for (i = 0; i < 8; i++) |
| 702 | regs_buff[849 + i] = |
| 703 | IXGBE_READ_REG(hw, IXGBE_RTTDT2C(i)); |
| 704 | for (i = 0; i < 8; i++) |
| 705 | regs_buff[857 + i] = |
| 706 | IXGBE_READ_REG(hw, IXGBE_RTTDT2S(i)); |
| 707 | break; |
| 708 | default: |
| 709 | break; |
| 710 | } |
| 711 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 712 | for (i = 0; i < 8; i++) |
Leonardo Potenza | 51e409f | 2013-10-01 04:33:52 -0700 | [diff] [blame] | 713 | regs_buff[865 + i] = |
| 714 | IXGBE_READ_REG(hw, IXGBE_TDPT2TCCR(i)); /* same as RTTPT2C */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 715 | for (i = 0; i < 8; i++) |
Leonardo Potenza | 51e409f | 2013-10-01 04:33:52 -0700 | [diff] [blame] | 716 | regs_buff[873 + i] = |
| 717 | IXGBE_READ_REG(hw, IXGBE_TDPT2TCSR(i)); /* same as RTTPT2S */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 718 | |
| 719 | /* Statistics */ |
| 720 | regs_buff[881] = IXGBE_GET_STAT(adapter, crcerrs); |
| 721 | regs_buff[882] = IXGBE_GET_STAT(adapter, illerrc); |
| 722 | regs_buff[883] = IXGBE_GET_STAT(adapter, errbc); |
| 723 | regs_buff[884] = IXGBE_GET_STAT(adapter, mspdc); |
| 724 | for (i = 0; i < 8; i++) |
| 725 | regs_buff[885 + i] = IXGBE_GET_STAT(adapter, mpc[i]); |
| 726 | regs_buff[893] = IXGBE_GET_STAT(adapter, mlfc); |
| 727 | regs_buff[894] = IXGBE_GET_STAT(adapter, mrfc); |
| 728 | regs_buff[895] = IXGBE_GET_STAT(adapter, rlec); |
| 729 | regs_buff[896] = IXGBE_GET_STAT(adapter, lxontxc); |
| 730 | regs_buff[897] = IXGBE_GET_STAT(adapter, lxonrxc); |
| 731 | regs_buff[898] = IXGBE_GET_STAT(adapter, lxofftxc); |
| 732 | regs_buff[899] = IXGBE_GET_STAT(adapter, lxoffrxc); |
| 733 | for (i = 0; i < 8; i++) |
| 734 | regs_buff[900 + i] = IXGBE_GET_STAT(adapter, pxontxc[i]); |
| 735 | for (i = 0; i < 8; i++) |
| 736 | regs_buff[908 + i] = IXGBE_GET_STAT(adapter, pxonrxc[i]); |
| 737 | for (i = 0; i < 8; i++) |
| 738 | regs_buff[916 + i] = IXGBE_GET_STAT(adapter, pxofftxc[i]); |
| 739 | for (i = 0; i < 8; i++) |
| 740 | regs_buff[924 + i] = IXGBE_GET_STAT(adapter, pxoffrxc[i]); |
| 741 | regs_buff[932] = IXGBE_GET_STAT(adapter, prc64); |
| 742 | regs_buff[933] = IXGBE_GET_STAT(adapter, prc127); |
| 743 | regs_buff[934] = IXGBE_GET_STAT(adapter, prc255); |
| 744 | regs_buff[935] = IXGBE_GET_STAT(adapter, prc511); |
| 745 | regs_buff[936] = IXGBE_GET_STAT(adapter, prc1023); |
| 746 | regs_buff[937] = IXGBE_GET_STAT(adapter, prc1522); |
| 747 | regs_buff[938] = IXGBE_GET_STAT(adapter, gprc); |
| 748 | regs_buff[939] = IXGBE_GET_STAT(adapter, bprc); |
| 749 | regs_buff[940] = IXGBE_GET_STAT(adapter, mprc); |
| 750 | regs_buff[941] = IXGBE_GET_STAT(adapter, gptc); |
Preethi Banala | 4c4f802 | 2016-04-21 11:40:24 -0700 | [diff] [blame] | 751 | regs_buff[942] = (u32)IXGBE_GET_STAT(adapter, gorc); |
| 752 | regs_buff[943] = (u32)(IXGBE_GET_STAT(adapter, gorc) >> 32); |
| 753 | regs_buff[944] = (u32)IXGBE_GET_STAT(adapter, gotc); |
| 754 | regs_buff[945] = (u32)(IXGBE_GET_STAT(adapter, gotc) >> 32); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 755 | for (i = 0; i < 8; i++) |
| 756 | regs_buff[946 + i] = IXGBE_GET_STAT(adapter, rnbc[i]); |
| 757 | regs_buff[954] = IXGBE_GET_STAT(adapter, ruc); |
| 758 | regs_buff[955] = IXGBE_GET_STAT(adapter, rfc); |
| 759 | regs_buff[956] = IXGBE_GET_STAT(adapter, roc); |
| 760 | regs_buff[957] = IXGBE_GET_STAT(adapter, rjc); |
| 761 | regs_buff[958] = IXGBE_GET_STAT(adapter, mngprc); |
| 762 | regs_buff[959] = IXGBE_GET_STAT(adapter, mngpdc); |
| 763 | regs_buff[960] = IXGBE_GET_STAT(adapter, mngptc); |
Preethi Banala | 4c4f802 | 2016-04-21 11:40:24 -0700 | [diff] [blame] | 764 | regs_buff[961] = (u32)IXGBE_GET_STAT(adapter, tor); |
| 765 | regs_buff[962] = (u32)(IXGBE_GET_STAT(adapter, tor) >> 32); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 766 | regs_buff[963] = IXGBE_GET_STAT(adapter, tpr); |
| 767 | regs_buff[964] = IXGBE_GET_STAT(adapter, tpt); |
| 768 | regs_buff[965] = IXGBE_GET_STAT(adapter, ptc64); |
| 769 | regs_buff[966] = IXGBE_GET_STAT(adapter, ptc127); |
| 770 | regs_buff[967] = IXGBE_GET_STAT(adapter, ptc255); |
| 771 | regs_buff[968] = IXGBE_GET_STAT(adapter, ptc511); |
| 772 | regs_buff[969] = IXGBE_GET_STAT(adapter, ptc1023); |
| 773 | regs_buff[970] = IXGBE_GET_STAT(adapter, ptc1522); |
| 774 | regs_buff[971] = IXGBE_GET_STAT(adapter, mptc); |
| 775 | regs_buff[972] = IXGBE_GET_STAT(adapter, bptc); |
| 776 | regs_buff[973] = IXGBE_GET_STAT(adapter, xec); |
| 777 | for (i = 0; i < 16; i++) |
| 778 | regs_buff[974 + i] = IXGBE_GET_STAT(adapter, qprc[i]); |
| 779 | for (i = 0; i < 16; i++) |
| 780 | regs_buff[990 + i] = IXGBE_GET_STAT(adapter, qptc[i]); |
| 781 | for (i = 0; i < 16; i++) |
| 782 | regs_buff[1006 + i] = IXGBE_GET_STAT(adapter, qbrc[i]); |
| 783 | for (i = 0; i < 16; i++) |
| 784 | regs_buff[1022 + i] = IXGBE_GET_STAT(adapter, qbtc[i]); |
| 785 | |
| 786 | /* MAC */ |
| 787 | regs_buff[1038] = IXGBE_READ_REG(hw, IXGBE_PCS1GCFIG); |
| 788 | regs_buff[1039] = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL); |
| 789 | regs_buff[1040] = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA); |
| 790 | regs_buff[1041] = IXGBE_READ_REG(hw, IXGBE_PCS1GDBG0); |
| 791 | regs_buff[1042] = IXGBE_READ_REG(hw, IXGBE_PCS1GDBG1); |
| 792 | regs_buff[1043] = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); |
| 793 | regs_buff[1044] = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP); |
| 794 | regs_buff[1045] = IXGBE_READ_REG(hw, IXGBE_PCS1GANNP); |
| 795 | regs_buff[1046] = IXGBE_READ_REG(hw, IXGBE_PCS1GANLPNP); |
| 796 | regs_buff[1047] = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 797 | regs_buff[1048] = IXGBE_READ_REG(hw, IXGBE_HLREG1); |
| 798 | regs_buff[1049] = IXGBE_READ_REG(hw, IXGBE_PAP); |
| 799 | regs_buff[1050] = IXGBE_READ_REG(hw, IXGBE_MACA); |
| 800 | regs_buff[1051] = IXGBE_READ_REG(hw, IXGBE_APAE); |
| 801 | regs_buff[1052] = IXGBE_READ_REG(hw, IXGBE_ARD); |
| 802 | regs_buff[1053] = IXGBE_READ_REG(hw, IXGBE_AIS); |
| 803 | regs_buff[1054] = IXGBE_READ_REG(hw, IXGBE_MSCA); |
| 804 | regs_buff[1055] = IXGBE_READ_REG(hw, IXGBE_MSRWD); |
| 805 | regs_buff[1056] = IXGBE_READ_REG(hw, IXGBE_MLADD); |
| 806 | regs_buff[1057] = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 807 | regs_buff[1058] = IXGBE_READ_REG(hw, IXGBE_TREG); |
| 808 | regs_buff[1059] = IXGBE_READ_REG(hw, IXGBE_PCSS1); |
| 809 | regs_buff[1060] = IXGBE_READ_REG(hw, IXGBE_PCSS2); |
| 810 | regs_buff[1061] = IXGBE_READ_REG(hw, IXGBE_XPCSS); |
| 811 | regs_buff[1062] = IXGBE_READ_REG(hw, IXGBE_SERDESC); |
| 812 | regs_buff[1063] = IXGBE_READ_REG(hw, IXGBE_MACS); |
| 813 | regs_buff[1064] = IXGBE_READ_REG(hw, IXGBE_AUTOC); |
| 814 | regs_buff[1065] = IXGBE_READ_REG(hw, IXGBE_LINKS); |
| 815 | regs_buff[1066] = IXGBE_READ_REG(hw, IXGBE_AUTOC2); |
| 816 | regs_buff[1067] = IXGBE_READ_REG(hw, IXGBE_AUTOC3); |
| 817 | regs_buff[1068] = IXGBE_READ_REG(hw, IXGBE_ANLP1); |
| 818 | regs_buff[1069] = IXGBE_READ_REG(hw, IXGBE_ANLP2); |
| 819 | regs_buff[1070] = IXGBE_READ_REG(hw, IXGBE_ATLASCTL); |
| 820 | |
| 821 | /* Diagnostic */ |
| 822 | regs_buff[1071] = IXGBE_READ_REG(hw, IXGBE_RDSTATCTL); |
| 823 | for (i = 0; i < 8; i++) |
Jesse Brandeburg | 98c00a1 | 2008-09-11 19:56:41 -0700 | [diff] [blame] | 824 | regs_buff[1072 + i] = IXGBE_READ_REG(hw, IXGBE_RDSTAT(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 825 | regs_buff[1080] = IXGBE_READ_REG(hw, IXGBE_RDHMPN); |
Jesse Brandeburg | 98c00a1 | 2008-09-11 19:56:41 -0700 | [diff] [blame] | 826 | for (i = 0; i < 4; i++) |
| 827 | regs_buff[1081 + i] = IXGBE_READ_REG(hw, IXGBE_RIC_DW(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 828 | regs_buff[1085] = IXGBE_READ_REG(hw, IXGBE_RDPROBE); |
| 829 | regs_buff[1086] = IXGBE_READ_REG(hw, IXGBE_TDSTATCTL); |
| 830 | for (i = 0; i < 8; i++) |
Jesse Brandeburg | 98c00a1 | 2008-09-11 19:56:41 -0700 | [diff] [blame] | 831 | regs_buff[1087 + i] = IXGBE_READ_REG(hw, IXGBE_TDSTAT(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 832 | regs_buff[1095] = IXGBE_READ_REG(hw, IXGBE_TDHMPN); |
Jesse Brandeburg | 98c00a1 | 2008-09-11 19:56:41 -0700 | [diff] [blame] | 833 | for (i = 0; i < 4; i++) |
| 834 | regs_buff[1096 + i] = IXGBE_READ_REG(hw, IXGBE_TIC_DW(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 835 | regs_buff[1100] = IXGBE_READ_REG(hw, IXGBE_TDPROBE); |
| 836 | regs_buff[1101] = IXGBE_READ_REG(hw, IXGBE_TXBUFCTRL); |
Preethi Banala | 45a88df | 2016-04-21 11:40:35 -0700 | [diff] [blame] | 837 | for (i = 0; i < 4; i++) |
| 838 | regs_buff[1102 + i] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 839 | regs_buff[1106] = IXGBE_READ_REG(hw, IXGBE_RXBUFCTRL); |
Preethi Banala | 45a88df | 2016-04-21 11:40:35 -0700 | [diff] [blame] | 840 | for (i = 0; i < 4; i++) |
| 841 | regs_buff[1107 + i] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 842 | for (i = 0; i < 8; i++) |
Jesse Brandeburg | 98c00a1 | 2008-09-11 19:56:41 -0700 | [diff] [blame] | 843 | regs_buff[1111 + i] = IXGBE_READ_REG(hw, IXGBE_PCIE_DIAG(i)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 844 | regs_buff[1119] = IXGBE_READ_REG(hw, IXGBE_RFVAL); |
| 845 | regs_buff[1120] = IXGBE_READ_REG(hw, IXGBE_MDFTC1); |
| 846 | regs_buff[1121] = IXGBE_READ_REG(hw, IXGBE_MDFTC2); |
| 847 | regs_buff[1122] = IXGBE_READ_REG(hw, IXGBE_MDFTFIFO1); |
| 848 | regs_buff[1123] = IXGBE_READ_REG(hw, IXGBE_MDFTFIFO2); |
| 849 | regs_buff[1124] = IXGBE_READ_REG(hw, IXGBE_MDFTS); |
| 850 | regs_buff[1125] = IXGBE_READ_REG(hw, IXGBE_PCIEECCCTL); |
| 851 | regs_buff[1126] = IXGBE_READ_REG(hw, IXGBE_PBTXECC); |
| 852 | regs_buff[1127] = IXGBE_READ_REG(hw, IXGBE_PBRXECC); |
Emil Tantilov | 217995e | 2011-09-15 06:23:10 +0000 | [diff] [blame] | 853 | |
| 854 | /* 82599 X540 specific registers */ |
| 855 | regs_buff[1128] = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
Leonardo Potenza | 51e409f | 2013-10-01 04:33:52 -0700 | [diff] [blame] | 856 | |
| 857 | /* 82599 X540 specific DCB registers */ |
| 858 | regs_buff[1129] = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 859 | regs_buff[1130] = IXGBE_READ_REG(hw, IXGBE_RTTUP2TC); |
| 860 | for (i = 0; i < 4; i++) |
| 861 | regs_buff[1131 + i] = IXGBE_READ_REG(hw, IXGBE_TXLLQ(i)); |
| 862 | regs_buff[1135] = IXGBE_READ_REG(hw, IXGBE_RTTBCNRM); |
| 863 | /* same as RTTQCNRM */ |
| 864 | regs_buff[1136] = IXGBE_READ_REG(hw, IXGBE_RTTBCNRD); |
| 865 | /* same as RTTQCNRR */ |
| 866 | |
| 867 | /* X540 specific DCB registers */ |
| 868 | regs_buff[1137] = IXGBE_READ_REG(hw, IXGBE_RTTQCNCR); |
| 869 | regs_buff[1138] = IXGBE_READ_REG(hw, IXGBE_RTTQCNTG); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | static int ixgbe_get_eeprom_len(struct net_device *netdev) |
| 873 | { |
| 874 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 875 | return adapter->hw.eeprom.word_size * 2; |
| 876 | } |
| 877 | |
| 878 | static int ixgbe_get_eeprom(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 879 | struct ethtool_eeprom *eeprom, u8 *bytes) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 880 | { |
| 881 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 882 | struct ixgbe_hw *hw = &adapter->hw; |
| 883 | u16 *eeprom_buff; |
| 884 | int first_word, last_word, eeprom_len; |
| 885 | int ret_val = 0; |
| 886 | u16 i; |
| 887 | |
| 888 | if (eeprom->len == 0) |
| 889 | return -EINVAL; |
| 890 | |
| 891 | eeprom->magic = hw->vendor_id | (hw->device_id << 16); |
| 892 | |
| 893 | first_word = eeprom->offset >> 1; |
| 894 | last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
| 895 | eeprom_len = last_word - first_word + 1; |
| 896 | |
| 897 | eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL); |
| 898 | if (!eeprom_buff) |
| 899 | return -ENOMEM; |
| 900 | |
Emil Tantilov | 68c7005 | 2011-04-20 08:49:06 +0000 | [diff] [blame] | 901 | ret_val = hw->eeprom.ops.read_buffer(hw, first_word, eeprom_len, |
| 902 | eeprom_buff); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 903 | |
| 904 | /* Device's eeprom is always little-endian, word addressable */ |
| 905 | for (i = 0; i < eeprom_len; i++) |
| 906 | le16_to_cpus(&eeprom_buff[i]); |
| 907 | |
| 908 | memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len); |
| 909 | kfree(eeprom_buff); |
| 910 | |
| 911 | return ret_val; |
| 912 | } |
| 913 | |
Emil Tantilov | 2fa5eef | 2011-10-06 08:57:04 +0000 | [diff] [blame] | 914 | static int ixgbe_set_eeprom(struct net_device *netdev, |
| 915 | struct ethtool_eeprom *eeprom, u8 *bytes) |
| 916 | { |
| 917 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 918 | struct ixgbe_hw *hw = &adapter->hw; |
| 919 | u16 *eeprom_buff; |
| 920 | void *ptr; |
| 921 | int max_len, first_word, last_word, ret_val = 0; |
| 922 | u16 i; |
| 923 | |
| 924 | if (eeprom->len == 0) |
| 925 | return -EINVAL; |
| 926 | |
| 927 | if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16))) |
| 928 | return -EINVAL; |
| 929 | |
| 930 | max_len = hw->eeprom.word_size * 2; |
| 931 | |
| 932 | first_word = eeprom->offset >> 1; |
| 933 | last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
| 934 | eeprom_buff = kmalloc(max_len, GFP_KERNEL); |
| 935 | if (!eeprom_buff) |
| 936 | return -ENOMEM; |
| 937 | |
| 938 | ptr = eeprom_buff; |
| 939 | |
| 940 | if (eeprom->offset & 1) { |
| 941 | /* |
| 942 | * need read/modify/write of first changed EEPROM word |
| 943 | * only the second byte of the word is being modified |
| 944 | */ |
| 945 | ret_val = hw->eeprom.ops.read(hw, first_word, &eeprom_buff[0]); |
| 946 | if (ret_val) |
| 947 | goto err; |
| 948 | |
| 949 | ptr++; |
| 950 | } |
| 951 | if ((eeprom->offset + eeprom->len) & 1) { |
| 952 | /* |
| 953 | * need read/modify/write of last changed EEPROM word |
| 954 | * only the first byte of the word is being modified |
| 955 | */ |
| 956 | ret_val = hw->eeprom.ops.read(hw, last_word, |
| 957 | &eeprom_buff[last_word - first_word]); |
| 958 | if (ret_val) |
| 959 | goto err; |
| 960 | } |
| 961 | |
| 962 | /* Device's eeprom is always little-endian, word addressable */ |
| 963 | for (i = 0; i < last_word - first_word + 1; i++) |
| 964 | le16_to_cpus(&eeprom_buff[i]); |
| 965 | |
| 966 | memcpy(ptr, bytes, eeprom->len); |
| 967 | |
| 968 | for (i = 0; i < last_word - first_word + 1; i++) |
| 969 | cpu_to_le16s(&eeprom_buff[i]); |
| 970 | |
| 971 | ret_val = hw->eeprom.ops.write_buffer(hw, first_word, |
| 972 | last_word - first_word + 1, |
| 973 | eeprom_buff); |
| 974 | |
| 975 | /* Update the checksum */ |
| 976 | if (ret_val == 0) |
| 977 | hw->eeprom.ops.update_checksum(hw); |
| 978 | |
| 979 | err: |
| 980 | kfree(eeprom_buff); |
| 981 | return ret_val; |
| 982 | } |
| 983 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 984 | static void ixgbe_get_drvinfo(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 985 | struct ethtool_drvinfo *drvinfo) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 986 | { |
| 987 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 988 | u32 nvm_track_id; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 989 | |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 990 | strlcpy(drvinfo->driver, ixgbe_driver_name, sizeof(drvinfo->driver)); |
| 991 | strlcpy(drvinfo->version, ixgbe_driver_version, |
| 992 | sizeof(drvinfo->version)); |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 993 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 994 | nvm_track_id = (adapter->eeprom_verh << 16) | |
| 995 | adapter->eeprom_verl; |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 996 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "0x%08x", |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 997 | nvm_track_id); |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 998 | |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 999 | strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), |
| 1000 | sizeof(drvinfo->bus_info)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | static void ixgbe_get_ringparam(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1004 | struct ethtool_ringparam *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1005 | { |
| 1006 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1007 | struct ixgbe_ring *tx_ring = adapter->tx_ring[0]; |
| 1008 | struct ixgbe_ring *rx_ring = adapter->rx_ring[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1009 | |
| 1010 | ring->rx_max_pending = IXGBE_MAX_RXD; |
| 1011 | ring->tx_max_pending = IXGBE_MAX_TXD; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1012 | ring->rx_pending = rx_ring->count; |
| 1013 | ring->tx_pending = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | static int ixgbe_set_ringparam(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1017 | struct ethtool_ringparam *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1018 | { |
| 1019 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1020 | struct ixgbe_ring *temp_ring; |
Alexander Duyck | 759884b | 2009-10-26 11:32:05 +0000 | [diff] [blame] | 1021 | int i, err = 0; |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 1022 | u32 new_rx_count, new_tx_count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1023 | |
| 1024 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 1025 | return -EINVAL; |
| 1026 | |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1027 | new_tx_count = clamp_t(u32, ring->tx_pending, |
| 1028 | IXGBE_MIN_TXD, IXGBE_MAX_TXD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1029 | new_tx_count = ALIGN(new_tx_count, IXGBE_REQ_TX_DESCRIPTOR_MULTIPLE); |
| 1030 | |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1031 | new_rx_count = clamp_t(u32, ring->rx_pending, |
| 1032 | IXGBE_MIN_RXD, IXGBE_MAX_RXD); |
| 1033 | new_rx_count = ALIGN(new_rx_count, IXGBE_REQ_RX_DESCRIPTOR_MULTIPLE); |
| 1034 | |
| 1035 | if ((new_tx_count == adapter->tx_ring_count) && |
| 1036 | (new_rx_count == adapter->rx_ring_count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1037 | /* nothing to do */ |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1041 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 1042 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1043 | |
Alexander Duyck | 759884b | 2009-10-26 11:32:05 +0000 | [diff] [blame] | 1044 | if (!netif_running(adapter->netdev)) { |
| 1045 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1046 | adapter->tx_ring[i]->count = new_tx_count; |
Alexander Duyck | 759884b | 2009-10-26 11:32:05 +0000 | [diff] [blame] | 1047 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1048 | adapter->rx_ring[i]->count = new_rx_count; |
Alexander Duyck | 759884b | 2009-10-26 11:32:05 +0000 | [diff] [blame] | 1049 | adapter->tx_ring_count = new_tx_count; |
| 1050 | adapter->rx_ring_count = new_rx_count; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1051 | goto clear_reset; |
Alexander Duyck | 759884b | 2009-10-26 11:32:05 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1054 | /* allocate temporary buffer to store rings in */ |
| 1055 | i = max_t(int, adapter->num_tx_queues, adapter->num_rx_queues); |
| 1056 | temp_ring = vmalloc(i * sizeof(struct ixgbe_ring)); |
| 1057 | |
| 1058 | if (!temp_ring) { |
Mallikarjuna R Chilakala | f9ed885 | 2009-03-31 21:35:24 +0000 | [diff] [blame] | 1059 | err = -ENOMEM; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1060 | goto clear_reset; |
Mallikarjuna R Chilakala | f9ed885 | 2009-03-31 21:35:24 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1063 | ixgbe_down(adapter); |
| 1064 | |
| 1065 | /* |
| 1066 | * Setup new Tx resources and free the old Tx resources in that order. |
| 1067 | * We can then assign the new resources to the rings via a memcpy. |
| 1068 | * The advantage to this approach is that we are guaranteed to still |
| 1069 | * have resources even in the case of an allocation failure. |
| 1070 | */ |
Mallikarjuna R Chilakala | f9ed885 | 2009-03-31 21:35:24 +0000 | [diff] [blame] | 1071 | if (new_tx_count != adapter->tx_ring_count) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1072 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1073 | memcpy(&temp_ring[i], adapter->tx_ring[i], |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1074 | sizeof(struct ixgbe_ring)); |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1075 | |
| 1076 | temp_ring[i].count = new_tx_count; |
| 1077 | err = ixgbe_setup_tx_resources(&temp_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1078 | if (err) { |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 1079 | while (i) { |
| 1080 | i--; |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1081 | ixgbe_free_tx_resources(&temp_ring[i]); |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 1082 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1083 | goto err_setup; |
| 1084 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1085 | } |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 1086 | |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1087 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1088 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Mallikarjuna R Chilakala | f9ed885 | 2009-03-31 21:35:24 +0000 | [diff] [blame] | 1089 | |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1090 | memcpy(adapter->tx_ring[i], &temp_ring[i], |
| 1091 | sizeof(struct ixgbe_ring)); |
Mallikarjuna R Chilakala | f9ed885 | 2009-03-31 21:35:24 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1094 | adapter->tx_ring_count = new_tx_count; |
Alexander Duyck | 759884b | 2009-10-26 11:32:05 +0000 | [diff] [blame] | 1095 | } |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1096 | |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1097 | /* Repeat the process for the Rx rings if needed */ |
| 1098 | if (new_rx_count != adapter->rx_ring_count) { |
| 1099 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1100 | memcpy(&temp_ring[i], adapter->rx_ring[i], |
| 1101 | sizeof(struct ixgbe_ring)); |
| 1102 | |
| 1103 | temp_ring[i].count = new_rx_count; |
| 1104 | err = ixgbe_setup_rx_resources(&temp_ring[i]); |
| 1105 | if (err) { |
| 1106 | while (i) { |
| 1107 | i--; |
| 1108 | ixgbe_free_rx_resources(&temp_ring[i]); |
| 1109 | } |
| 1110 | goto err_setup; |
| 1111 | } |
| 1112 | |
| 1113 | } |
| 1114 | |
| 1115 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1116 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
| 1117 | |
| 1118 | memcpy(adapter->rx_ring[i], &temp_ring[i], |
| 1119 | sizeof(struct ixgbe_ring)); |
| 1120 | } |
| 1121 | |
| 1122 | adapter->rx_ring_count = new_rx_count; |
| 1123 | } |
| 1124 | |
Mallikarjuna R Chilakala | f9ed885 | 2009-03-31 21:35:24 +0000 | [diff] [blame] | 1125 | err_setup: |
Alexander Duyck | 1f4702a | 2012-09-12 07:09:51 +0000 | [diff] [blame] | 1126 | ixgbe_up(adapter); |
| 1127 | vfree(temp_ring); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1128 | clear_reset: |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1129 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1130 | return err; |
| 1131 | } |
| 1132 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1133 | static int ixgbe_get_sset_count(struct net_device *netdev, int sset) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1134 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1135 | switch (sset) { |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1136 | case ETH_SS_TEST: |
| 1137 | return IXGBE_TEST_LEN; |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1138 | case ETH_SS_STATS: |
| 1139 | return IXGBE_STATS_LEN; |
| 1140 | default: |
| 1141 | return -EOPNOTSUPP; |
| 1142 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | static void ixgbe_get_ethtool_stats(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1146 | struct ethtool_stats *stats, u64 *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1147 | { |
| 1148 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 1149 | struct rtnl_link_stats64 temp; |
| 1150 | const struct rtnl_link_stats64 *net_stats; |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 1151 | unsigned int start; |
| 1152 | struct ixgbe_ring *ring; |
| 1153 | int i, j; |
Ajit Khaparde | 29c3a05 | 2009-10-13 01:47:33 +0000 | [diff] [blame] | 1154 | char *p = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1155 | |
| 1156 | ixgbe_update_stats(adapter); |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 1157 | net_stats = dev_get_stats(netdev, &temp); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1158 | for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { |
Ajit Khaparde | 29c3a05 | 2009-10-13 01:47:33 +0000 | [diff] [blame] | 1159 | switch (ixgbe_gstrings_stats[i].type) { |
| 1160 | case NETDEV_STATS: |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 1161 | p = (char *) net_stats + |
Ajit Khaparde | 29c3a05 | 2009-10-13 01:47:33 +0000 | [diff] [blame] | 1162 | ixgbe_gstrings_stats[i].stat_offset; |
| 1163 | break; |
| 1164 | case IXGBE_STATS: |
| 1165 | p = (char *) adapter + |
| 1166 | ixgbe_gstrings_stats[i].stat_offset; |
| 1167 | break; |
Josh Hay | f752be9 | 2013-01-04 03:34:36 +0000 | [diff] [blame] | 1168 | default: |
| 1169 | data[i] = 0; |
| 1170 | continue; |
Ajit Khaparde | 29c3a05 | 2009-10-13 01:47:33 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1173 | data[i] = (ixgbe_gstrings_stats[i].sizeof_stat == |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1174 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1175 | } |
Don Skidmore | bd8a1b1 | 2013-06-28 05:35:50 +0000 | [diff] [blame] | 1176 | for (j = 0; j < netdev->num_tx_queues; j++) { |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 1177 | ring = adapter->tx_ring[j]; |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 1178 | if (!ring) { |
| 1179 | data[i] = 0; |
| 1180 | data[i+1] = 0; |
| 1181 | i += 2; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1182 | #ifdef BP_EXTENDED_STATS |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 1183 | data[i] = 0; |
| 1184 | data[i+1] = 0; |
| 1185 | data[i+2] = 0; |
| 1186 | i += 3; |
| 1187 | #endif |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 1188 | continue; |
| 1189 | } |
| 1190 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 1191 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1192 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 1193 | data[i] = ring->stats.packets; |
| 1194 | data[i+1] = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1195 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 1196 | i += 2; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1197 | #ifdef BP_EXTENDED_STATS |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 1198 | data[i] = ring->stats.yields; |
| 1199 | data[i+1] = ring->stats.misses; |
| 1200 | data[i+2] = ring->stats.cleaned; |
| 1201 | i += 3; |
| 1202 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1203 | } |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 1204 | for (j = 0; j < IXGBE_NUM_RX_QUEUES; j++) { |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 1205 | ring = adapter->rx_ring[j]; |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 1206 | if (!ring) { |
| 1207 | data[i] = 0; |
| 1208 | data[i+1] = 0; |
| 1209 | i += 2; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1210 | #ifdef BP_EXTENDED_STATS |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 1211 | data[i] = 0; |
| 1212 | data[i+1] = 0; |
| 1213 | data[i+2] = 0; |
| 1214 | i += 3; |
| 1215 | #endif |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 1216 | continue; |
| 1217 | } |
| 1218 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 1219 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1220 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 1221 | data[i] = ring->stats.packets; |
| 1222 | data[i+1] = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1223 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 1224 | i += 2; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1225 | #ifdef BP_EXTENDED_STATS |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 1226 | data[i] = ring->stats.yields; |
| 1227 | data[i+1] = ring->stats.misses; |
| 1228 | data[i+2] = ring->stats.cleaned; |
| 1229 | i += 3; |
| 1230 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1231 | } |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 1232 | |
| 1233 | for (j = 0; j < IXGBE_MAX_PACKET_BUFFERS; j++) { |
| 1234 | data[i++] = adapter->stats.pxontxc[j]; |
| 1235 | data[i++] = adapter->stats.pxofftxc[j]; |
| 1236 | } |
| 1237 | for (j = 0; j < IXGBE_MAX_PACKET_BUFFERS; j++) { |
| 1238 | data[i++] = adapter->stats.pxonrxc[j]; |
| 1239 | data[i++] = adapter->stats.pxoffrxc[j]; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1240 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | static void ixgbe_get_strings(struct net_device *netdev, u32 stringset, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1244 | u8 *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1245 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1246 | char *p = (char *)data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1247 | int i; |
| 1248 | |
| 1249 | switch (stringset) { |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1250 | case ETH_SS_TEST: |
Josh Hay | d2c47b6 | 2013-01-04 03:34:42 +0000 | [diff] [blame] | 1251 | for (i = 0; i < IXGBE_TEST_LEN; i++) { |
| 1252 | memcpy(data, ixgbe_gstrings_test[i], ETH_GSTRING_LEN); |
| 1253 | data += ETH_GSTRING_LEN; |
| 1254 | } |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1255 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1256 | case ETH_SS_STATS: |
| 1257 | for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { |
| 1258 | memcpy(p, ixgbe_gstrings_stats[i].stat_string, |
| 1259 | ETH_GSTRING_LEN); |
| 1260 | p += ETH_GSTRING_LEN; |
| 1261 | } |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 1262 | for (i = 0; i < netdev->num_tx_queues; i++) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1263 | sprintf(p, "tx_queue_%u_packets", i); |
| 1264 | p += ETH_GSTRING_LEN; |
| 1265 | sprintf(p, "tx_queue_%u_bytes", i); |
| 1266 | p += ETH_GSTRING_LEN; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1267 | #ifdef BP_EXTENDED_STATS |
| 1268 | sprintf(p, "tx_queue_%u_bp_napi_yield", i); |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 1269 | p += ETH_GSTRING_LEN; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1270 | sprintf(p, "tx_queue_%u_bp_misses", i); |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 1271 | p += ETH_GSTRING_LEN; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1272 | sprintf(p, "tx_queue_%u_bp_cleaned", i); |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 1273 | p += ETH_GSTRING_LEN; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1274 | #endif /* BP_EXTENDED_STATS */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1275 | } |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 1276 | for (i = 0; i < IXGBE_NUM_RX_QUEUES; i++) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1277 | sprintf(p, "rx_queue_%u_packets", i); |
| 1278 | p += ETH_GSTRING_LEN; |
| 1279 | sprintf(p, "rx_queue_%u_bytes", i); |
| 1280 | p += ETH_GSTRING_LEN; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1281 | #ifdef BP_EXTENDED_STATS |
| 1282 | sprintf(p, "rx_queue_%u_bp_poll_yield", i); |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 1283 | p += ETH_GSTRING_LEN; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1284 | sprintf(p, "rx_queue_%u_bp_misses", i); |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 1285 | p += ETH_GSTRING_LEN; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1286 | sprintf(p, "rx_queue_%u_bp_cleaned", i); |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 1287 | p += ETH_GSTRING_LEN; |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1288 | #endif /* BP_EXTENDED_STATS */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1289 | } |
John Fastabend | 9cc00b5 | 2012-01-28 03:32:17 +0000 | [diff] [blame] | 1290 | for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) { |
| 1291 | sprintf(p, "tx_pb_%u_pxon", i); |
| 1292 | p += ETH_GSTRING_LEN; |
| 1293 | sprintf(p, "tx_pb_%u_pxoff", i); |
| 1294 | p += ETH_GSTRING_LEN; |
| 1295 | } |
| 1296 | for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) { |
| 1297 | sprintf(p, "rx_pb_%u_pxon", i); |
| 1298 | p += ETH_GSTRING_LEN; |
| 1299 | sprintf(p, "rx_pb_%u_pxoff", i); |
| 1300 | p += ETH_GSTRING_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1301 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1302 | /* BUG_ON(p - data != IXGBE_STATS_LEN * ETH_GSTRING_LEN); */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1303 | break; |
| 1304 | } |
| 1305 | } |
| 1306 | |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1307 | static int ixgbe_link_test(struct ixgbe_adapter *adapter, u64 *data) |
| 1308 | { |
| 1309 | struct ixgbe_hw *hw = &adapter->hw; |
| 1310 | bool link_up; |
| 1311 | u32 link_speed = 0; |
Mark Rustad | 0edd2bd | 2014-02-28 15:48:56 -0800 | [diff] [blame] | 1312 | |
| 1313 | if (ixgbe_removed(hw->hw_addr)) { |
| 1314 | *data = 1; |
| 1315 | return 1; |
| 1316 | } |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1317 | *data = 0; |
| 1318 | |
| 1319 | hw->mac.ops.check_link(hw, &link_speed, &link_up, true); |
| 1320 | if (link_up) |
| 1321 | return *data; |
| 1322 | else |
| 1323 | *data = 1; |
| 1324 | return *data; |
| 1325 | } |
| 1326 | |
| 1327 | /* ethtool register test data */ |
| 1328 | struct ixgbe_reg_test { |
| 1329 | u16 reg; |
| 1330 | u8 array_len; |
| 1331 | u8 test_type; |
| 1332 | u32 mask; |
| 1333 | u32 write; |
| 1334 | }; |
| 1335 | |
| 1336 | /* In the hardware, registers are laid out either singly, in arrays |
| 1337 | * spaced 0x40 bytes apart, or in contiguous tables. We assume |
| 1338 | * most tests take place on arrays or single registers (handled |
| 1339 | * as a single-element array) and special-case the tables. |
| 1340 | * Table tests are always pattern tests. |
| 1341 | * |
| 1342 | * We also make provision for some required setup steps by specifying |
| 1343 | * registers to be written without any read-back testing. |
| 1344 | */ |
| 1345 | |
| 1346 | #define PATTERN_TEST 1 |
| 1347 | #define SET_READ_TEST 2 |
| 1348 | #define WRITE_NO_TEST 3 |
| 1349 | #define TABLE32_TEST 4 |
| 1350 | #define TABLE64_TEST_LO 5 |
| 1351 | #define TABLE64_TEST_HI 6 |
| 1352 | |
| 1353 | /* default 82599 register test */ |
Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 1354 | static const struct ixgbe_reg_test reg_test_82599[] = { |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1355 | { IXGBE_FCRTL_82599(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, |
| 1356 | { IXGBE_FCRTH_82599(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, |
| 1357 | { IXGBE_PFCTOP, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 1358 | { IXGBE_VLNCTRL, 1, PATTERN_TEST, 0x00000000, 0x00000000 }, |
| 1359 | { IXGBE_RDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFF80 }, |
| 1360 | { IXGBE_RDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 1361 | { IXGBE_RDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, |
| 1362 | { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE }, |
| 1363 | { IXGBE_RDT(0), 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, |
| 1364 | { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, 0 }, |
| 1365 | { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, |
| 1366 | { IXGBE_FCTTV(0), 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 1367 | { IXGBE_TDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, |
| 1368 | { IXGBE_TDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 1369 | { IXGBE_TDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFF80 }, |
| 1370 | { IXGBE_RXCTRL, 1, SET_READ_TEST, 0x00000001, 0x00000001 }, |
| 1371 | { IXGBE_RAL(0), 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 1372 | { IXGBE_RAL(0), 16, TABLE64_TEST_HI, 0x8001FFFF, 0x800CFFFF }, |
| 1373 | { IXGBE_MTA(0), 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 1374 | { .reg = 0 } |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1375 | }; |
| 1376 | |
| 1377 | /* default 82598 register test */ |
Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 1378 | static const struct ixgbe_reg_test reg_test_82598[] = { |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1379 | { IXGBE_FCRTL(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, |
| 1380 | { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, |
| 1381 | { IXGBE_PFCTOP, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 1382 | { IXGBE_VLNCTRL, 1, PATTERN_TEST, 0x00000000, 0x00000000 }, |
| 1383 | { IXGBE_RDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, |
| 1384 | { IXGBE_RDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 1385 | { IXGBE_RDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, |
| 1386 | /* Enable all four RX queues before testing. */ |
| 1387 | { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE }, |
| 1388 | /* RDH is read-only for 82598, only test RDT. */ |
| 1389 | { IXGBE_RDT(0), 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, |
| 1390 | { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, 0 }, |
| 1391 | { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 }, |
| 1392 | { IXGBE_FCTTV(0), 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 1393 | { IXGBE_TIPG, 1, PATTERN_TEST, 0x000000FF, 0x000000FF }, |
| 1394 | { IXGBE_TDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, |
| 1395 | { IXGBE_TDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 1396 | { IXGBE_TDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, |
| 1397 | { IXGBE_RXCTRL, 1, SET_READ_TEST, 0x00000003, 0x00000003 }, |
| 1398 | { IXGBE_DTXCTL, 1, SET_READ_TEST, 0x00000005, 0x00000005 }, |
| 1399 | { IXGBE_RAL(0), 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF }, |
| 1400 | { IXGBE_RAL(0), 16, TABLE64_TEST_HI, 0x800CFFFF, 0x800CFFFF }, |
| 1401 | { IXGBE_MTA(0), 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 1402 | { .reg = 0 } |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1403 | }; |
| 1404 | |
Emil Tantilov | 95a4601 | 2011-04-14 07:46:41 +0000 | [diff] [blame] | 1405 | static bool reg_pattern_test(struct ixgbe_adapter *adapter, u64 *data, int reg, |
| 1406 | u32 mask, u32 write) |
| 1407 | { |
| 1408 | u32 pat, val, before; |
| 1409 | static const u32 test_pattern[] = { |
| 1410 | 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; |
Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 1411 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 1412 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 1413 | *data = 1; |
Joe Perches | 4e833c5 | 2015-03-29 18:25:12 -0700 | [diff] [blame] | 1414 | return true; |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 1415 | } |
Emil Tantilov | 95a4601 | 2011-04-14 07:46:41 +0000 | [diff] [blame] | 1416 | for (pat = 0; pat < ARRAY_SIZE(test_pattern); pat++) { |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1417 | before = ixgbe_read_reg(&adapter->hw, reg); |
| 1418 | ixgbe_write_reg(&adapter->hw, reg, test_pattern[pat] & write); |
| 1419 | val = ixgbe_read_reg(&adapter->hw, reg); |
Emil Tantilov | 95a4601 | 2011-04-14 07:46:41 +0000 | [diff] [blame] | 1420 | if (val != (test_pattern[pat] & write & mask)) { |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 1421 | e_err(drv, "pattern test reg %04X failed: got 0x%08X expected 0x%08X\n", |
Emil Tantilov | 95a4601 | 2011-04-14 07:46:41 +0000 | [diff] [blame] | 1422 | reg, val, (test_pattern[pat] & write & mask)); |
| 1423 | *data = reg; |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1424 | ixgbe_write_reg(&adapter->hw, reg, before); |
| 1425 | return true; |
Emil Tantilov | 95a4601 | 2011-04-14 07:46:41 +0000 | [diff] [blame] | 1426 | } |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1427 | ixgbe_write_reg(&adapter->hw, reg, before); |
Emil Tantilov | 95a4601 | 2011-04-14 07:46:41 +0000 | [diff] [blame] | 1428 | } |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1429 | return false; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
Emil Tantilov | 95a4601 | 2011-04-14 07:46:41 +0000 | [diff] [blame] | 1432 | static bool reg_set_and_check(struct ixgbe_adapter *adapter, u64 *data, int reg, |
| 1433 | u32 mask, u32 write) |
| 1434 | { |
| 1435 | u32 val, before; |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1436 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 1437 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 1438 | *data = 1; |
Joe Perches | 4e833c5 | 2015-03-29 18:25:12 -0700 | [diff] [blame] | 1439 | return true; |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 1440 | } |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1441 | before = ixgbe_read_reg(&adapter->hw, reg); |
| 1442 | ixgbe_write_reg(&adapter->hw, reg, write & mask); |
| 1443 | val = ixgbe_read_reg(&adapter->hw, reg); |
Emil Tantilov | 95a4601 | 2011-04-14 07:46:41 +0000 | [diff] [blame] | 1444 | if ((write & mask) != (val & mask)) { |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 1445 | e_err(drv, "set/check reg %04X test failed: got 0x%08X expected 0x%08X\n", |
| 1446 | reg, (val & mask), (write & mask)); |
Emil Tantilov | 95a4601 | 2011-04-14 07:46:41 +0000 | [diff] [blame] | 1447 | *data = reg; |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1448 | ixgbe_write_reg(&adapter->hw, reg, before); |
| 1449 | return true; |
Emil Tantilov | 95a4601 | 2011-04-14 07:46:41 +0000 | [diff] [blame] | 1450 | } |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1451 | ixgbe_write_reg(&adapter->hw, reg, before); |
| 1452 | return false; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | static int ixgbe_reg_test(struct ixgbe_adapter *adapter, u64 *data) |
| 1456 | { |
Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 1457 | const struct ixgbe_reg_test *test; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1458 | u32 value, before, after; |
| 1459 | u32 i, toggle; |
| 1460 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 1461 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 1462 | e_err(drv, "Adapter removed - register test blocked\n"); |
| 1463 | *data = 1; |
| 1464 | return 1; |
| 1465 | } |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1466 | switch (adapter->hw.mac.type) { |
| 1467 | case ixgbe_mac_82598EB: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1468 | toggle = 0x7FFFF3FF; |
| 1469 | test = reg_test_82598; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1470 | break; |
| 1471 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1472 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 1473 | case ixgbe_mac_X550: |
| 1474 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 1475 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1476 | toggle = 0x7FFFF30F; |
| 1477 | test = reg_test_82599; |
| 1478 | break; |
| 1479 | default: |
| 1480 | *data = 1; |
| 1481 | return 1; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | /* |
| 1485 | * Because the status register is such a special case, |
| 1486 | * we handle it separately from the rest of the register |
| 1487 | * tests. Some bits are read-only, some toggle, and some |
| 1488 | * are writeable on newer MACs. |
| 1489 | */ |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1490 | before = ixgbe_read_reg(&adapter->hw, IXGBE_STATUS); |
| 1491 | value = (ixgbe_read_reg(&adapter->hw, IXGBE_STATUS) & toggle); |
| 1492 | ixgbe_write_reg(&adapter->hw, IXGBE_STATUS, toggle); |
| 1493 | after = ixgbe_read_reg(&adapter->hw, IXGBE_STATUS) & toggle; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1494 | if (value != after) { |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 1495 | e_err(drv, "failed STATUS register test got: 0x%08X expected: 0x%08X\n", |
| 1496 | after, value); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1497 | *data = 1; |
| 1498 | return 1; |
| 1499 | } |
| 1500 | /* restore previous status */ |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1501 | ixgbe_write_reg(&adapter->hw, IXGBE_STATUS, before); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1502 | |
| 1503 | /* |
| 1504 | * Perform the remainder of the register test, looping through |
| 1505 | * the test table until we either fail or reach the null entry. |
| 1506 | */ |
| 1507 | while (test->reg) { |
| 1508 | for (i = 0; i < test->array_len; i++) { |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1509 | bool b = false; |
| 1510 | |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1511 | switch (test->test_type) { |
| 1512 | case PATTERN_TEST: |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1513 | b = reg_pattern_test(adapter, data, |
| 1514 | test->reg + (i * 0x40), |
| 1515 | test->mask, |
| 1516 | test->write); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1517 | break; |
| 1518 | case SET_READ_TEST: |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1519 | b = reg_set_and_check(adapter, data, |
| 1520 | test->reg + (i * 0x40), |
| 1521 | test->mask, |
| 1522 | test->write); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1523 | break; |
| 1524 | case WRITE_NO_TEST: |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1525 | ixgbe_write_reg(&adapter->hw, |
| 1526 | test->reg + (i * 0x40), |
| 1527 | test->write); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1528 | break; |
| 1529 | case TABLE32_TEST: |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1530 | b = reg_pattern_test(adapter, data, |
| 1531 | test->reg + (i * 4), |
| 1532 | test->mask, |
| 1533 | test->write); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1534 | break; |
| 1535 | case TABLE64_TEST_LO: |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1536 | b = reg_pattern_test(adapter, data, |
| 1537 | test->reg + (i * 8), |
| 1538 | test->mask, |
| 1539 | test->write); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1540 | break; |
| 1541 | case TABLE64_TEST_HI: |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1542 | b = reg_pattern_test(adapter, data, |
| 1543 | (test->reg + 4) + (i * 8), |
| 1544 | test->mask, |
| 1545 | test->write); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1546 | break; |
| 1547 | } |
Mark Rustad | 49bde31 | 2014-01-14 18:53:14 -0800 | [diff] [blame] | 1548 | if (b) |
| 1549 | return 1; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1550 | } |
| 1551 | test++; |
| 1552 | } |
| 1553 | |
| 1554 | *data = 0; |
| 1555 | return 0; |
| 1556 | } |
| 1557 | |
| 1558 | static int ixgbe_eeprom_test(struct ixgbe_adapter *adapter, u64 *data) |
| 1559 | { |
| 1560 | struct ixgbe_hw *hw = &adapter->hw; |
| 1561 | if (hw->eeprom.ops.validate_checksum(hw, NULL)) |
| 1562 | *data = 1; |
| 1563 | else |
| 1564 | *data = 0; |
| 1565 | return *data; |
| 1566 | } |
| 1567 | |
| 1568 | static irqreturn_t ixgbe_test_intr(int irq, void *data) |
| 1569 | { |
| 1570 | struct net_device *netdev = (struct net_device *) data; |
| 1571 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1572 | |
| 1573 | adapter->test_icr |= IXGBE_READ_REG(&adapter->hw, IXGBE_EICR); |
| 1574 | |
| 1575 | return IRQ_HANDLED; |
| 1576 | } |
| 1577 | |
| 1578 | static int ixgbe_intr_test(struct ixgbe_adapter *adapter, u64 *data) |
| 1579 | { |
| 1580 | struct net_device *netdev = adapter->netdev; |
| 1581 | u32 mask, i = 0, shared_int = true; |
| 1582 | u32 irq = adapter->pdev->irq; |
| 1583 | |
| 1584 | *data = 0; |
| 1585 | |
| 1586 | /* Hook up test interrupt handler just for this test */ |
| 1587 | if (adapter->msix_entries) { |
| 1588 | /* NOTE: we don't test MSI-X interrupts here, yet */ |
| 1589 | return 0; |
| 1590 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 1591 | shared_int = false; |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1592 | if (request_irq(irq, ixgbe_test_intr, 0, netdev->name, |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1593 | netdev)) { |
| 1594 | *data = 1; |
| 1595 | return -1; |
| 1596 | } |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1597 | } else if (!request_irq(irq, ixgbe_test_intr, IRQF_PROBE_SHARED, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1598 | netdev->name, netdev)) { |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1599 | shared_int = false; |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1600 | } else if (request_irq(irq, ixgbe_test_intr, IRQF_SHARED, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1601 | netdev->name, netdev)) { |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1602 | *data = 1; |
| 1603 | return -1; |
| 1604 | } |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 1605 | e_info(hw, "testing %s interrupt\n", shared_int ? |
| 1606 | "shared" : "unshared"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1607 | |
| 1608 | /* Disable all the interrupts */ |
| 1609 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFFFFFF); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1610 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 1611 | usleep_range(10000, 20000); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1612 | |
| 1613 | /* Test each interrupt */ |
| 1614 | for (; i < 10; i++) { |
| 1615 | /* Interrupt to test */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 1616 | mask = BIT(i); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1617 | |
| 1618 | if (!shared_int) { |
| 1619 | /* |
| 1620 | * Disable the interrupts to be reported in |
| 1621 | * the cause register and then force the same |
| 1622 | * interrupt and see if one gets posted. If |
| 1623 | * an interrupt was posted to the bus, the |
| 1624 | * test failed. |
| 1625 | */ |
| 1626 | adapter->test_icr = 0; |
| 1627 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1628 | ~mask & 0x00007FFF); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1629 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1630 | ~mask & 0x00007FFF); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1631 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 1632 | usleep_range(10000, 20000); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1633 | |
| 1634 | if (adapter->test_icr & mask) { |
| 1635 | *data = 3; |
| 1636 | break; |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | /* |
| 1641 | * Enable the interrupt to be reported in the cause |
| 1642 | * register and then force the same interrupt and see |
| 1643 | * if one gets posted. If an interrupt was not posted |
| 1644 | * to the bus, the test failed. |
| 1645 | */ |
| 1646 | adapter->test_icr = 0; |
| 1647 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 1648 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1649 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 1650 | usleep_range(10000, 20000); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1651 | |
Jacob Keller | 8105ecd | 2014-04-09 06:03:16 +0000 | [diff] [blame] | 1652 | if (!(adapter->test_icr & mask)) { |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1653 | *data = 4; |
| 1654 | break; |
| 1655 | } |
| 1656 | |
| 1657 | if (!shared_int) { |
| 1658 | /* |
| 1659 | * Disable the other interrupts to be reported in |
| 1660 | * the cause register and then force the other |
| 1661 | * interrupts and see if any get posted. If |
| 1662 | * an interrupt was posted to the bus, the |
| 1663 | * test failed. |
| 1664 | */ |
| 1665 | adapter->test_icr = 0; |
| 1666 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1667 | ~mask & 0x00007FFF); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1668 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 1669 | ~mask & 0x00007FFF); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1670 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 1671 | usleep_range(10000, 20000); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1672 | |
| 1673 | if (adapter->test_icr) { |
| 1674 | *data = 5; |
| 1675 | break; |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | /* Disable all the interrupts */ |
| 1681 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFFFFFF); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1682 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 1683 | usleep_range(10000, 20000); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1684 | |
| 1685 | /* Unhook test interrupt handler */ |
| 1686 | free_irq(irq, netdev); |
| 1687 | |
| 1688 | return *data; |
| 1689 | } |
| 1690 | |
| 1691 | static void ixgbe_free_desc_rings(struct ixgbe_adapter *adapter) |
| 1692 | { |
| 1693 | struct ixgbe_ring *tx_ring = &adapter->test_tx_ring; |
| 1694 | struct ixgbe_ring *rx_ring = &adapter->test_rx_ring; |
| 1695 | struct ixgbe_hw *hw = &adapter->hw; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1696 | u32 reg_ctl; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1697 | |
| 1698 | /* shut down the DMA engines now so they can be reinitialized later */ |
| 1699 | |
| 1700 | /* first Rx */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 1701 | hw->mac.ops.disable_rx(hw); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 1702 | ixgbe_disable_rx_queue(adapter, rx_ring); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1703 | |
| 1704 | /* now Tx */ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1705 | reg_ctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(tx_ring->reg_idx)); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1706 | reg_ctl &= ~IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1707 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(tx_ring->reg_idx), reg_ctl); |
| 1708 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1709 | switch (hw->mac.type) { |
| 1710 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1711 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 1712 | case ixgbe_mac_X550: |
| 1713 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 1714 | case ixgbe_mac_x550em_a: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1715 | reg_ctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 1716 | reg_ctl &= ~IXGBE_DMATXCTL_TE; |
| 1717 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg_ctl); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1718 | break; |
| 1719 | default: |
| 1720 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | ixgbe_reset(adapter); |
| 1724 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1725 | ixgbe_free_tx_resources(&adapter->test_tx_ring); |
| 1726 | ixgbe_free_rx_resources(&adapter->test_rx_ring); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | static int ixgbe_setup_desc_rings(struct ixgbe_adapter *adapter) |
| 1730 | { |
| 1731 | struct ixgbe_ring *tx_ring = &adapter->test_tx_ring; |
| 1732 | struct ixgbe_ring *rx_ring = &adapter->test_rx_ring; |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 1733 | struct ixgbe_hw *hw = &adapter->hw; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1734 | u32 rctl, reg_data; |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1735 | int ret_val; |
| 1736 | int err; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1737 | |
| 1738 | /* Setup Tx descriptor ring and Tx buffers */ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1739 | tx_ring->count = IXGBE_DEFAULT_TXD; |
| 1740 | tx_ring->queue_index = 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1741 | tx_ring->dev = &adapter->pdev->dev; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1742 | tx_ring->netdev = adapter->netdev; |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1743 | tx_ring->reg_idx = adapter->tx_ring[0]->reg_idx; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1744 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1745 | err = ixgbe_setup_tx_resources(tx_ring); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1746 | if (err) |
| 1747 | return 1; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1748 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1749 | switch (adapter->hw.mac.type) { |
| 1750 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1751 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 1752 | case ixgbe_mac_X550: |
| 1753 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 1754 | case ixgbe_mac_x550em_a: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1755 | reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_DMATXCTL); |
| 1756 | reg_data |= IXGBE_DMATXCTL_TE; |
| 1757 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DMATXCTL, reg_data); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 1758 | break; |
| 1759 | default: |
| 1760 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1761 | } |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1762 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1763 | ixgbe_configure_tx_ring(adapter, tx_ring); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1764 | |
| 1765 | /* Setup Rx Descriptor ring and Rx buffers */ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1766 | rx_ring->count = IXGBE_DEFAULT_RXD; |
| 1767 | rx_ring->queue_index = 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1768 | rx_ring->dev = &adapter->pdev->dev; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1769 | rx_ring->netdev = adapter->netdev; |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1770 | rx_ring->reg_idx = adapter->rx_ring[0]->reg_idx; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1771 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1772 | err = ixgbe_setup_rx_resources(rx_ring); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1773 | if (err) { |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1774 | ret_val = 4; |
| 1775 | goto err_nomem; |
| 1776 | } |
| 1777 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 1778 | hw->mac.ops.disable_rx(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1779 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1780 | ixgbe_configure_rx_ring(adapter, rx_ring); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1781 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 1782 | rctl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXCTRL); |
| 1783 | rctl |= IXGBE_RXCTRL_DMBYPS; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1784 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXCTRL, rctl); |
| 1785 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 1786 | hw->mac.ops.enable_rx(hw); |
| 1787 | |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1788 | return 0; |
| 1789 | |
| 1790 | err_nomem: |
| 1791 | ixgbe_free_desc_rings(adapter); |
| 1792 | return ret_val; |
| 1793 | } |
| 1794 | |
| 1795 | static int ixgbe_setup_loopback_test(struct ixgbe_adapter *adapter) |
| 1796 | { |
| 1797 | struct ixgbe_hw *hw = &adapter->hw; |
| 1798 | u32 reg_data; |
| 1799 | |
Don Skidmore | e7fd925 | 2011-04-16 05:29:14 +0000 | [diff] [blame] | 1800 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1801 | /* Setup MAC loopback */ |
Emil Tantilov | 26b4742 | 2013-04-12 02:10:25 +0000 | [diff] [blame] | 1802 | reg_data = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1803 | reg_data |= IXGBE_HLREG0_LPBK; |
Alexander Duyck | 35c7f8a | 2011-07-15 03:06:01 +0000 | [diff] [blame] | 1804 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, reg_data); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1805 | |
Alexander Duyck | 35c7f8a | 2011-07-15 03:06:01 +0000 | [diff] [blame] | 1806 | reg_data = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1807 | reg_data |= IXGBE_FCTRL_BAM | IXGBE_FCTRL_SBP | IXGBE_FCTRL_MPE; |
Alexander Duyck | 35c7f8a | 2011-07-15 03:06:01 +0000 | [diff] [blame] | 1808 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg_data); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1809 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 1810 | /* X540 and X550 needs to set the MACC.FLU bit to force link up */ |
| 1811 | switch (adapter->hw.mac.type) { |
| 1812 | case ixgbe_mac_X540: |
| 1813 | case ixgbe_mac_X550: |
| 1814 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 1815 | case ixgbe_mac_x550em_a: |
Emil Tantilov | 26b4742 | 2013-04-12 02:10:25 +0000 | [diff] [blame] | 1816 | reg_data = IXGBE_READ_REG(hw, IXGBE_MACC); |
| 1817 | reg_data |= IXGBE_MACC_FLU; |
| 1818 | IXGBE_WRITE_REG(hw, IXGBE_MACC, reg_data); |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 1819 | break; |
| 1820 | default: |
Emil Tantilov | 26b4742 | 2013-04-12 02:10:25 +0000 | [diff] [blame] | 1821 | if (hw->mac.orig_autoc) { |
| 1822 | reg_data = hw->mac.orig_autoc | IXGBE_AUTOC_FLU; |
| 1823 | IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_data); |
| 1824 | } else { |
| 1825 | return 10; |
| 1826 | } |
| 1827 | } |
Alexander Duyck | 35c7f8a | 2011-07-15 03:06:01 +0000 | [diff] [blame] | 1828 | IXGBE_WRITE_FLUSH(hw); |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 1829 | usleep_range(10000, 20000); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1830 | |
| 1831 | /* Disable Atlas Tx lanes; re-enabled in reset path */ |
| 1832 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 1833 | u8 atlas; |
| 1834 | |
| 1835 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &atlas); |
| 1836 | atlas |= IXGBE_ATLAS_PDN_TX_REG_EN; |
| 1837 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, atlas); |
| 1838 | |
| 1839 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, &atlas); |
| 1840 | atlas |= IXGBE_ATLAS_PDN_TX_10G_QL_ALL; |
| 1841 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, atlas); |
| 1842 | |
| 1843 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, &atlas); |
| 1844 | atlas |= IXGBE_ATLAS_PDN_TX_1G_QL_ALL; |
| 1845 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, atlas); |
| 1846 | |
| 1847 | hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, &atlas); |
| 1848 | atlas |= IXGBE_ATLAS_PDN_TX_AN_QL_ALL; |
| 1849 | hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, atlas); |
| 1850 | } |
| 1851 | |
| 1852 | return 0; |
| 1853 | } |
| 1854 | |
| 1855 | static void ixgbe_loopback_cleanup(struct ixgbe_adapter *adapter) |
| 1856 | { |
| 1857 | u32 reg_data; |
| 1858 | |
| 1859 | reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_HLREG0); |
| 1860 | reg_data &= ~IXGBE_HLREG0_LPBK; |
| 1861 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_HLREG0, reg_data); |
| 1862 | } |
| 1863 | |
| 1864 | static void ixgbe_create_lbtest_frame(struct sk_buff *skb, |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1865 | unsigned int frame_size) |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1866 | { |
| 1867 | memset(skb->data, 0xFF, frame_size); |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1868 | frame_size >>= 1; |
| 1869 | memset(&skb->data[frame_size], 0xAA, frame_size / 2 - 1); |
| 1870 | memset(&skb->data[frame_size + 10], 0xBE, 1); |
| 1871 | memset(&skb->data[frame_size + 12], 0xAF, 1); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1874 | static bool ixgbe_check_lbtest_frame(struct ixgbe_rx_buffer *rx_buffer, |
| 1875 | unsigned int frame_size) |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1876 | { |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1877 | unsigned char *data; |
| 1878 | bool match = true; |
| 1879 | |
| 1880 | frame_size >>= 1; |
| 1881 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1882 | data = kmap(rx_buffer->page) + rx_buffer->page_offset; |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1883 | |
| 1884 | if (data[3] != 0xFF || |
| 1885 | data[frame_size + 10] != 0xBE || |
| 1886 | data[frame_size + 12] != 0xAF) |
| 1887 | match = false; |
| 1888 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1889 | kunmap(rx_buffer->page); |
| 1890 | |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1891 | return match; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1894 | static u16 ixgbe_clean_test_rings(struct ixgbe_ring *rx_ring, |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1895 | struct ixgbe_ring *tx_ring, |
| 1896 | unsigned int size) |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1897 | { |
| 1898 | union ixgbe_adv_rx_desc *rx_desc; |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1899 | struct ixgbe_rx_buffer *rx_buffer; |
| 1900 | struct ixgbe_tx_buffer *tx_buffer; |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1901 | u16 rx_ntc, tx_ntc, count = 0; |
| 1902 | |
| 1903 | /* initialize next to clean and descriptor values */ |
| 1904 | rx_ntc = rx_ring->next_to_clean; |
| 1905 | tx_ntc = tx_ring->next_to_clean; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1906 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ntc); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1907 | |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1908 | while (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) { |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1909 | /* check Rx buffer */ |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1910 | rx_buffer = &rx_ring->rx_buffer_info[rx_ntc]; |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1911 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1912 | /* sync Rx buffer for CPU read */ |
| 1913 | dma_sync_single_for_cpu(rx_ring->dev, |
| 1914 | rx_buffer->dma, |
| 1915 | ixgbe_rx_bufsz(rx_ring), |
| 1916 | DMA_FROM_DEVICE); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1917 | |
| 1918 | /* verify contents of skb */ |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1919 | if (ixgbe_check_lbtest_frame(rx_buffer, size)) |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1920 | count++; |
| 1921 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1922 | /* sync Rx buffer for device write */ |
| 1923 | dma_sync_single_for_device(rx_ring->dev, |
| 1924 | rx_buffer->dma, |
| 1925 | ixgbe_rx_bufsz(rx_ring), |
| 1926 | DMA_FROM_DEVICE); |
| 1927 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1928 | /* unmap buffer on Tx side */ |
Alexander Duyck | 3832b26 | 2012-02-08 07:50:09 +0000 | [diff] [blame] | 1929 | tx_buffer = &tx_ring->tx_buffer_info[tx_ntc]; |
| 1930 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1931 | |
| 1932 | /* increment Rx/Tx next to clean counters */ |
| 1933 | rx_ntc++; |
| 1934 | if (rx_ntc == rx_ring->count) |
| 1935 | rx_ntc = 0; |
| 1936 | tx_ntc++; |
| 1937 | if (tx_ntc == tx_ring->count) |
| 1938 | tx_ntc = 0; |
| 1939 | |
| 1940 | /* fetch next descriptor */ |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1941 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ntc); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 1944 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
| 1945 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1946 | /* re-map buffers to ring, store next to clean values */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1947 | ixgbe_alloc_rx_buffers(rx_ring, count); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1948 | rx_ring->next_to_clean = rx_ntc; |
| 1949 | tx_ring->next_to_clean = tx_ntc; |
| 1950 | |
| 1951 | return count; |
| 1952 | } |
| 1953 | |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1954 | static int ixgbe_run_loopback_test(struct ixgbe_adapter *adapter) |
| 1955 | { |
| 1956 | struct ixgbe_ring *tx_ring = &adapter->test_tx_ring; |
| 1957 | struct ixgbe_ring *rx_ring = &adapter->test_rx_ring; |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1958 | int i, j, lc, good_cnt, ret_val = 0; |
| 1959 | unsigned int size = 1024; |
| 1960 | netdev_tx_t tx_ret_val; |
| 1961 | struct sk_buff *skb; |
Emil Tantilov | 91ffdc8 | 2013-07-23 01:56:58 +0000 | [diff] [blame] | 1962 | u32 flags_orig = adapter->flags; |
| 1963 | |
| 1964 | /* DCB can modify the frames on Tx */ |
| 1965 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1966 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1967 | /* allocate test skb */ |
| 1968 | skb = alloc_skb(size, GFP_KERNEL); |
| 1969 | if (!skb) |
| 1970 | return 11; |
| 1971 | |
| 1972 | /* place data into test skb */ |
| 1973 | ixgbe_create_lbtest_frame(skb, size); |
| 1974 | skb_put(skb, size); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1975 | |
| 1976 | /* |
| 1977 | * Calculate the loop count based on the largest descriptor ring |
| 1978 | * The idea is to wrap the largest ring a number of times using 64 |
| 1979 | * send/receive pairs during each loop |
| 1980 | */ |
| 1981 | |
| 1982 | if (rx_ring->count <= tx_ring->count) |
| 1983 | lc = ((tx_ring->count / 64) * 2) + 1; |
| 1984 | else |
| 1985 | lc = ((rx_ring->count / 64) * 2) + 1; |
| 1986 | |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1987 | for (j = 0; j <= lc; j++) { |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1988 | /* reset count of good packets */ |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1989 | good_cnt = 0; |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1990 | |
| 1991 | /* place 64 packets on the transmit queue*/ |
| 1992 | for (i = 0; i < 64; i++) { |
| 1993 | skb_get(skb); |
| 1994 | tx_ret_val = ixgbe_xmit_frame_ring(skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1995 | adapter, |
| 1996 | tx_ring); |
| 1997 | if (tx_ret_val == NETDEV_TX_OK) |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 1998 | good_cnt++; |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2001 | if (good_cnt != 64) { |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2002 | ret_val = 12; |
| 2003 | break; |
| 2004 | } |
| 2005 | |
| 2006 | /* allow 200 milliseconds for packets to go from Tx to Rx */ |
| 2007 | msleep(200); |
| 2008 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 2009 | good_cnt = ixgbe_clean_test_rings(rx_ring, tx_ring, size); |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2010 | if (good_cnt != 64) { |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2011 | ret_val = 13; |
| 2012 | break; |
| 2013 | } |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2016 | /* free the original skb */ |
| 2017 | kfree_skb(skb); |
Emil Tantilov | 91ffdc8 | 2013-07-23 01:56:58 +0000 | [diff] [blame] | 2018 | adapter->flags = flags_orig; |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2019 | |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2020 | return ret_val; |
| 2021 | } |
| 2022 | |
| 2023 | static int ixgbe_loopback_test(struct ixgbe_adapter *adapter, u64 *data) |
| 2024 | { |
| 2025 | *data = ixgbe_setup_desc_rings(adapter); |
| 2026 | if (*data) |
| 2027 | goto out; |
| 2028 | *data = ixgbe_setup_loopback_test(adapter); |
| 2029 | if (*data) |
| 2030 | goto err_loopback; |
| 2031 | *data = ixgbe_run_loopback_test(adapter); |
| 2032 | ixgbe_loopback_cleanup(adapter); |
| 2033 | |
| 2034 | err_loopback: |
| 2035 | ixgbe_free_desc_rings(adapter); |
| 2036 | out: |
| 2037 | return *data; |
| 2038 | } |
| 2039 | |
| 2040 | static void ixgbe_diag_test(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 2041 | struct ethtool_test *eth_test, u64 *data) |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2042 | { |
| 2043 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2044 | bool if_running = netif_running(netdev); |
| 2045 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 2046 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 2047 | e_err(hw, "Adapter removed - test blocked\n"); |
| 2048 | data[0] = 1; |
| 2049 | data[1] = 1; |
| 2050 | data[2] = 1; |
| 2051 | data[3] = 1; |
Mark Rustad | 0edd2bd | 2014-02-28 15:48:56 -0800 | [diff] [blame] | 2052 | data[4] = 1; |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 2053 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 2054 | return; |
| 2055 | } |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2056 | set_bit(__IXGBE_TESTING, &adapter->state); |
| 2057 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { |
Emil Tantilov | 4ec375b | 2013-07-10 02:47:24 +0000 | [diff] [blame] | 2058 | struct ixgbe_hw *hw = &adapter->hw; |
| 2059 | |
Greg Rose | e7d481a | 2010-03-25 17:06:48 +0000 | [diff] [blame] | 2060 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 2061 | int i; |
| 2062 | for (i = 0; i < adapter->num_vfs; i++) { |
| 2063 | if (adapter->vfinfo[i].clear_to_send) { |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 2064 | netdev_warn(netdev, "offline diagnostic is not supported when VFs are present\n"); |
Greg Rose | e7d481a | 2010-03-25 17:06:48 +0000 | [diff] [blame] | 2065 | data[0] = 1; |
| 2066 | data[1] = 1; |
| 2067 | data[2] = 1; |
| 2068 | data[3] = 1; |
Mark Rustad | 0edd2bd | 2014-02-28 15:48:56 -0800 | [diff] [blame] | 2069 | data[4] = 1; |
Greg Rose | e7d481a | 2010-03-25 17:06:48 +0000 | [diff] [blame] | 2070 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 2071 | clear_bit(__IXGBE_TESTING, |
| 2072 | &adapter->state); |
| 2073 | goto skip_ol_tests; |
| 2074 | } |
| 2075 | } |
| 2076 | } |
| 2077 | |
Jacob Keller | dfcc461 | 2012-11-08 07:07:08 +0000 | [diff] [blame] | 2078 | /* Offline tests */ |
| 2079 | e_info(hw, "offline testing starting\n"); |
| 2080 | |
Jacob Keller | dfcc461 | 2012-11-08 07:07:08 +0000 | [diff] [blame] | 2081 | /* Link test performed before hardware reset so autoneg doesn't |
| 2082 | * interfere with test result |
| 2083 | */ |
| 2084 | if (ixgbe_link_test(adapter, &data[4])) |
| 2085 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 2086 | |
Emil Tantilov | 4ec375b | 2013-07-10 02:47:24 +0000 | [diff] [blame] | 2087 | if (if_running) |
| 2088 | /* indicate we're in test mode */ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 2089 | ixgbe_close(netdev); |
Emil Tantilov | 4ec375b | 2013-07-10 02:47:24 +0000 | [diff] [blame] | 2090 | else |
| 2091 | ixgbe_reset(adapter); |
| 2092 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2093 | e_info(hw, "register testing starting\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2094 | if (ixgbe_reg_test(adapter, &data[0])) |
| 2095 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 2096 | |
| 2097 | ixgbe_reset(adapter); |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2098 | e_info(hw, "eeprom testing starting\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2099 | if (ixgbe_eeprom_test(adapter, &data[1])) |
| 2100 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 2101 | |
| 2102 | ixgbe_reset(adapter); |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2103 | e_info(hw, "interrupt testing starting\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2104 | if (ixgbe_intr_test(adapter, &data[2])) |
| 2105 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 2106 | |
Greg Rose | bdbec4b | 2010-01-09 02:27:05 +0000 | [diff] [blame] | 2107 | /* If SRIOV or VMDq is enabled then skip MAC |
| 2108 | * loopback diagnostic. */ |
| 2109 | if (adapter->flags & (IXGBE_FLAG_SRIOV_ENABLED | |
| 2110 | IXGBE_FLAG_VMDQ_ENABLED)) { |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 2111 | e_info(hw, "Skip MAC loopback diagnostic in VT mode\n"); |
Greg Rose | bdbec4b | 2010-01-09 02:27:05 +0000 | [diff] [blame] | 2112 | data[3] = 0; |
| 2113 | goto skip_loopback; |
| 2114 | } |
| 2115 | |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2116 | ixgbe_reset(adapter); |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2117 | e_info(hw, "loopback testing starting\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2118 | if (ixgbe_loopback_test(adapter, &data[3])) |
| 2119 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 2120 | |
Greg Rose | bdbec4b | 2010-01-09 02:27:05 +0000 | [diff] [blame] | 2121 | skip_loopback: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2122 | ixgbe_reset(adapter); |
| 2123 | |
Jacob Keller | dfcc461 | 2012-11-08 07:07:08 +0000 | [diff] [blame] | 2124 | /* clear testing bit and return adapter to previous state */ |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2125 | clear_bit(__IXGBE_TESTING, &adapter->state); |
| 2126 | if (if_running) |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 2127 | ixgbe_open(netdev); |
Emil Tantilov | 4ec375b | 2013-07-10 02:47:24 +0000 | [diff] [blame] | 2128 | else if (hw->mac.ops.disable_tx_laser) |
| 2129 | hw->mac.ops.disable_tx_laser(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2130 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2131 | e_info(hw, "online testing starting\n"); |
Jacob Keller | dfcc461 | 2012-11-08 07:07:08 +0000 | [diff] [blame] | 2132 | |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2133 | /* Online tests */ |
| 2134 | if (ixgbe_link_test(adapter, &data[4])) |
| 2135 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 2136 | |
Jacob Keller | dfcc461 | 2012-11-08 07:07:08 +0000 | [diff] [blame] | 2137 | /* Offline tests aren't run; pass by default */ |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2138 | data[0] = 0; |
| 2139 | data[1] = 0; |
| 2140 | data[2] = 0; |
| 2141 | data[3] = 0; |
| 2142 | |
| 2143 | clear_bit(__IXGBE_TESTING, &adapter->state); |
| 2144 | } |
Jacob Keller | dfcc461 | 2012-11-08 07:07:08 +0000 | [diff] [blame] | 2145 | |
Greg Rose | e7d481a | 2010-03-25 17:06:48 +0000 | [diff] [blame] | 2146 | skip_ol_tests: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2147 | msleep_interruptible(4 * 1000); |
| 2148 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2149 | |
Alexander Duyck | d6c519e | 2009-04-08 13:20:50 +0000 | [diff] [blame] | 2150 | static int ixgbe_wol_exclusion(struct ixgbe_adapter *adapter, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 2151 | struct ethtool_wolinfo *wol) |
Alexander Duyck | d6c519e | 2009-04-08 13:20:50 +0000 | [diff] [blame] | 2152 | { |
| 2153 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 2154 | int retval = 0; |
Alexander Duyck | d6c519e | 2009-04-08 13:20:50 +0000 | [diff] [blame] | 2155 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 2156 | /* WOL not supported for all devices */ |
| 2157 | if (!ixgbe_wol_supported(adapter, hw->device_id, |
| 2158 | hw->subsystem_device_id)) { |
| 2159 | retval = 1; |
Alexander Duyck | d6c519e | 2009-04-08 13:20:50 +0000 | [diff] [blame] | 2160 | wol->supported = 0; |
Alexander Duyck | d6c519e | 2009-04-08 13:20:50 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | return retval; |
| 2164 | } |
| 2165 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2166 | static void ixgbe_get_wol(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 2167 | struct ethtool_wolinfo *wol) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2168 | { |
PJ Waskiewicz | e63d976 | 2009-03-19 01:23:46 +0000 | [diff] [blame] | 2169 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2170 | |
| 2171 | wol->supported = WAKE_UCAST | WAKE_MCAST | |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 2172 | WAKE_BCAST | WAKE_MAGIC; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2173 | wol->wolopts = 0; |
| 2174 | |
Alexander Duyck | d6c519e | 2009-04-08 13:20:50 +0000 | [diff] [blame] | 2175 | if (ixgbe_wol_exclusion(adapter, wol) || |
| 2176 | !device_can_wakeup(&adapter->pdev->dev)) |
PJ Waskiewicz | e63d976 | 2009-03-19 01:23:46 +0000 | [diff] [blame] | 2177 | return; |
| 2178 | |
| 2179 | if (adapter->wol & IXGBE_WUFC_EX) |
| 2180 | wol->wolopts |= WAKE_UCAST; |
| 2181 | if (adapter->wol & IXGBE_WUFC_MC) |
| 2182 | wol->wolopts |= WAKE_MCAST; |
| 2183 | if (adapter->wol & IXGBE_WUFC_BC) |
| 2184 | wol->wolopts |= WAKE_BCAST; |
| 2185 | if (adapter->wol & IXGBE_WUFC_MAG) |
| 2186 | wol->wolopts |= WAKE_MAGIC; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
PJ Waskiewicz | e63d976 | 2009-03-19 01:23:46 +0000 | [diff] [blame] | 2189 | static int ixgbe_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 2190 | { |
| 2191 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2192 | |
| 2193 | if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE)) |
| 2194 | return -EOPNOTSUPP; |
| 2195 | |
Alexander Duyck | d6c519e | 2009-04-08 13:20:50 +0000 | [diff] [blame] | 2196 | if (ixgbe_wol_exclusion(adapter, wol)) |
| 2197 | return wol->wolopts ? -EOPNOTSUPP : 0; |
| 2198 | |
PJ Waskiewicz | e63d976 | 2009-03-19 01:23:46 +0000 | [diff] [blame] | 2199 | adapter->wol = 0; |
| 2200 | |
| 2201 | if (wol->wolopts & WAKE_UCAST) |
| 2202 | adapter->wol |= IXGBE_WUFC_EX; |
| 2203 | if (wol->wolopts & WAKE_MCAST) |
| 2204 | adapter->wol |= IXGBE_WUFC_MC; |
| 2205 | if (wol->wolopts & WAKE_BCAST) |
| 2206 | adapter->wol |= IXGBE_WUFC_BC; |
| 2207 | if (wol->wolopts & WAKE_MAGIC) |
| 2208 | adapter->wol |= IXGBE_WUFC_MAG; |
| 2209 | |
| 2210 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 2211 | |
| 2212 | return 0; |
| 2213 | } |
| 2214 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2215 | static int ixgbe_nway_reset(struct net_device *netdev) |
| 2216 | { |
| 2217 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2218 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2219 | if (netif_running(netdev)) |
| 2220 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2221 | |
| 2222 | return 0; |
| 2223 | } |
| 2224 | |
Emil Tantilov | 66e6961 | 2011-04-16 06:12:51 +0000 | [diff] [blame] | 2225 | static int ixgbe_set_phys_id(struct net_device *netdev, |
| 2226 | enum ethtool_phys_id_state state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2227 | { |
| 2228 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2229 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2230 | |
Emil Tantilov | 66e6961 | 2011-04-16 06:12:51 +0000 | [diff] [blame] | 2231 | switch (state) { |
| 2232 | case ETHTOOL_ID_ACTIVE: |
| 2233 | adapter->led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); |
| 2234 | return 2; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2235 | |
Emil Tantilov | 66e6961 | 2011-04-16 06:12:51 +0000 | [diff] [blame] | 2236 | case ETHTOOL_ID_ON: |
Don Skidmore | 805cedd | 2016-10-20 21:42:00 -0400 | [diff] [blame] | 2237 | hw->mac.ops.led_on(hw, hw->mac.led_link_act); |
Emil Tantilov | 66e6961 | 2011-04-16 06:12:51 +0000 | [diff] [blame] | 2238 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2239 | |
Emil Tantilov | 66e6961 | 2011-04-16 06:12:51 +0000 | [diff] [blame] | 2240 | case ETHTOOL_ID_OFF: |
Don Skidmore | 805cedd | 2016-10-20 21:42:00 -0400 | [diff] [blame] | 2241 | hw->mac.ops.led_off(hw, hw->mac.led_link_act); |
Emil Tantilov | 66e6961 | 2011-04-16 06:12:51 +0000 | [diff] [blame] | 2242 | break; |
| 2243 | |
| 2244 | case ETHTOOL_ID_INACTIVE: |
| 2245 | /* Restore LED settings */ |
| 2246 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_LEDCTL, adapter->led_reg); |
| 2247 | break; |
| 2248 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2249 | |
| 2250 | return 0; |
| 2251 | } |
| 2252 | |
| 2253 | static int ixgbe_get_coalesce(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 2254 | struct ethtool_coalesce *ec) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2255 | { |
| 2256 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2257 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2258 | /* only valid if in constant ITR mode */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2259 | if (adapter->rx_itr_setting <= 1) |
| 2260 | ec->rx_coalesce_usecs = adapter->rx_itr_setting; |
| 2261 | else |
| 2262 | ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2263 | |
Shannon Nelson | cfb3f91 | 2009-11-24 18:51:06 +0000 | [diff] [blame] | 2264 | /* if in mixed tx/rx queues per vector mode, report only rx settings */ |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2265 | if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count) |
Shannon Nelson | cfb3f91 | 2009-11-24 18:51:06 +0000 | [diff] [blame] | 2266 | return 0; |
| 2267 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2268 | /* only valid if in constant ITR mode */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2269 | if (adapter->tx_itr_setting <= 1) |
| 2270 | ec->tx_coalesce_usecs = adapter->tx_itr_setting; |
| 2271 | else |
| 2272 | ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2273 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2274 | return 0; |
| 2275 | } |
| 2276 | |
Alexander Duyck | 80fba3f | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2277 | /* |
| 2278 | * this function must be called before setting the new value of |
| 2279 | * rx_itr_setting |
| 2280 | */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 2281 | static bool ixgbe_update_rsc(struct ixgbe_adapter *adapter) |
Alexander Duyck | 80fba3f | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2282 | { |
| 2283 | struct net_device *netdev = adapter->netdev; |
| 2284 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 2285 | /* nothing to do if LRO or RSC are not enabled */ |
| 2286 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) || |
| 2287 | !(netdev->features & NETIF_F_LRO)) |
Alexander Duyck | 80fba3f | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2288 | return false; |
| 2289 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 2290 | /* check the feature flag value and enable RSC if necessary */ |
| 2291 | if (adapter->rx_itr_setting == 1 || |
| 2292 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 2293 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
Alexander Duyck | 80fba3f | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2294 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 2295 | e_info(probe, "rx-usecs value high enough to re-enable RSC\n"); |
Alexander Duyck | 80fba3f | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2296 | return true; |
| 2297 | } |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 2298 | /* if interrupt rate is too high then disable RSC */ |
| 2299 | } else if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
| 2300 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 2301 | e_info(probe, "rx-usecs set too low, disabling RSC\n"); |
| 2302 | return true; |
Alexander Duyck | 80fba3f | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2303 | } |
| 2304 | return false; |
| 2305 | } |
| 2306 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2307 | static int ixgbe_set_coalesce(struct net_device *netdev, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 2308 | struct ethtool_coalesce *ec) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2309 | { |
| 2310 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Don Skidmore | 237057a | 2009-08-11 13:18:14 +0000 | [diff] [blame] | 2311 | struct ixgbe_q_vector *q_vector; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2312 | int i; |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2313 | u16 tx_itr_param, rx_itr_param, tx_itr_prev; |
Jesse Brandeburg | ef02119 | 2010-04-27 01:37:41 +0000 | [diff] [blame] | 2314 | bool need_reset = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2315 | |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2316 | if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count) { |
| 2317 | /* reject Tx specific changes in case of mixed RxTx vectors */ |
| 2318 | if (ec->tx_coalesce_usecs) |
| 2319 | return -EINVAL; |
| 2320 | tx_itr_prev = adapter->rx_itr_setting; |
| 2321 | } else { |
| 2322 | tx_itr_prev = adapter->tx_itr_setting; |
| 2323 | } |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2324 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2325 | if ((ec->rx_coalesce_usecs > (IXGBE_MAX_EITR >> 2)) || |
| 2326 | (ec->tx_coalesce_usecs > (IXGBE_MAX_EITR >> 2))) |
| 2327 | return -EINVAL; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2328 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2329 | if (ec->rx_coalesce_usecs > 1) |
| 2330 | adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2; |
| 2331 | else |
| 2332 | adapter->rx_itr_setting = ec->rx_coalesce_usecs; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2333 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2334 | if (adapter->rx_itr_setting == 1) |
| 2335 | rx_itr_param = IXGBE_20K_ITR; |
| 2336 | else |
| 2337 | rx_itr_param = adapter->rx_itr_setting; |
Alexander Duyck | 80fba3f | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2338 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2339 | if (ec->tx_coalesce_usecs > 1) |
| 2340 | adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2; |
| 2341 | else |
| 2342 | adapter->tx_itr_setting = ec->tx_coalesce_usecs; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2343 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2344 | if (adapter->tx_itr_setting == 1) |
Alexander Duyck | 8ac34f1 | 2015-07-30 15:19:28 -0700 | [diff] [blame] | 2345 | tx_itr_param = IXGBE_12K_ITR; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2346 | else |
| 2347 | tx_itr_param = adapter->tx_itr_setting; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2348 | |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2349 | /* mixed Rx/Tx */ |
| 2350 | if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count) |
| 2351 | adapter->tx_itr_setting = adapter->rx_itr_setting; |
| 2352 | |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2353 | /* detect ITR changes that require update of TXDCTL.WTHRESH */ |
Emil Tantilov | 2e01038 | 2013-10-22 08:21:04 +0000 | [diff] [blame] | 2354 | if ((adapter->tx_itr_setting != 1) && |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2355 | (adapter->tx_itr_setting < IXGBE_100K_ITR)) { |
| 2356 | if ((tx_itr_prev == 1) || |
Emil Tantilov | 2e01038 | 2013-10-22 08:21:04 +0000 | [diff] [blame] | 2357 | (tx_itr_prev >= IXGBE_100K_ITR)) |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2358 | need_reset = true; |
| 2359 | } else { |
Emil Tantilov | 2e01038 | 2013-10-22 08:21:04 +0000 | [diff] [blame] | 2360 | if ((tx_itr_prev != 1) && |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2361 | (tx_itr_prev < IXGBE_100K_ITR)) |
| 2362 | need_reset = true; |
| 2363 | } |
Emil Tantilov | ffefa9f | 2014-09-18 08:05:02 +0000 | [diff] [blame] | 2364 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 2365 | /* check the old value and enable RSC if necessary */ |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2366 | need_reset |= ixgbe_update_rsc(adapter); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 2367 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2368 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2369 | q_vector = adapter->q_vector[i]; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2370 | if (q_vector->tx.count && !q_vector->rx.count) |
| 2371 | /* tx only */ |
| 2372 | q_vector->itr = tx_itr_param; |
| 2373 | else |
| 2374 | /* rx only or mixed */ |
| 2375 | q_vector->itr = rx_itr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2376 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
Jesse Brandeburg | ef02119 | 2010-04-27 01:37:41 +0000 | [diff] [blame] | 2379 | /* |
| 2380 | * do reset here at the end to make sure EITR==0 case is handled |
| 2381 | * correctly w.r.t stopping tx, and changing TXDCTL.WTHRESH settings |
| 2382 | * also locks in RSC enable/disable which requires reset |
| 2383 | */ |
Emil Tantilov | c988ee8 | 2011-05-13 02:22:45 +0000 | [diff] [blame] | 2384 | if (need_reset) |
| 2385 | ixgbe_do_reset(netdev); |
Jesse Brandeburg | ef02119 | 2010-04-27 01:37:41 +0000 | [diff] [blame] | 2386 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2387 | return 0; |
| 2388 | } |
| 2389 | |
Alexander Duyck | 3e05334 | 2011-05-11 07:18:47 +0000 | [diff] [blame] | 2390 | static int ixgbe_get_ethtool_fdir_entry(struct ixgbe_adapter *adapter, |
| 2391 | struct ethtool_rxnfc *cmd) |
| 2392 | { |
| 2393 | union ixgbe_atr_input *mask = &adapter->fdir_mask; |
| 2394 | struct ethtool_rx_flow_spec *fsp = |
| 2395 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2396 | struct hlist_node *node2; |
Alexander Duyck | 3e05334 | 2011-05-11 07:18:47 +0000 | [diff] [blame] | 2397 | struct ixgbe_fdir_filter *rule = NULL; |
| 2398 | |
| 2399 | /* report total rule count */ |
| 2400 | cmd->data = (1024 << adapter->fdir_pballoc) - 2; |
| 2401 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2402 | hlist_for_each_entry_safe(rule, node2, |
Alexander Duyck | 3e05334 | 2011-05-11 07:18:47 +0000 | [diff] [blame] | 2403 | &adapter->fdir_filter_list, fdir_node) { |
| 2404 | if (fsp->location <= rule->sw_idx) |
| 2405 | break; |
| 2406 | } |
| 2407 | |
| 2408 | if (!rule || fsp->location != rule->sw_idx) |
| 2409 | return -EINVAL; |
| 2410 | |
| 2411 | /* fill out the flow spec entry */ |
| 2412 | |
| 2413 | /* set flow type field */ |
| 2414 | switch (rule->filter.formatted.flow_type) { |
| 2415 | case IXGBE_ATR_FLOW_TYPE_TCPV4: |
| 2416 | fsp->flow_type = TCP_V4_FLOW; |
| 2417 | break; |
| 2418 | case IXGBE_ATR_FLOW_TYPE_UDPV4: |
| 2419 | fsp->flow_type = UDP_V4_FLOW; |
| 2420 | break; |
| 2421 | case IXGBE_ATR_FLOW_TYPE_SCTPV4: |
| 2422 | fsp->flow_type = SCTP_V4_FLOW; |
| 2423 | break; |
| 2424 | case IXGBE_ATR_FLOW_TYPE_IPV4: |
| 2425 | fsp->flow_type = IP_USER_FLOW; |
| 2426 | fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; |
| 2427 | fsp->h_u.usr_ip4_spec.proto = 0; |
| 2428 | fsp->m_u.usr_ip4_spec.proto = 0; |
| 2429 | break; |
| 2430 | default: |
| 2431 | return -EINVAL; |
| 2432 | } |
| 2433 | |
| 2434 | fsp->h_u.tcp_ip4_spec.psrc = rule->filter.formatted.src_port; |
| 2435 | fsp->m_u.tcp_ip4_spec.psrc = mask->formatted.src_port; |
| 2436 | fsp->h_u.tcp_ip4_spec.pdst = rule->filter.formatted.dst_port; |
| 2437 | fsp->m_u.tcp_ip4_spec.pdst = mask->formatted.dst_port; |
| 2438 | fsp->h_u.tcp_ip4_spec.ip4src = rule->filter.formatted.src_ip[0]; |
| 2439 | fsp->m_u.tcp_ip4_spec.ip4src = mask->formatted.src_ip[0]; |
| 2440 | fsp->h_u.tcp_ip4_spec.ip4dst = rule->filter.formatted.dst_ip[0]; |
| 2441 | fsp->m_u.tcp_ip4_spec.ip4dst = mask->formatted.dst_ip[0]; |
| 2442 | fsp->h_ext.vlan_tci = rule->filter.formatted.vlan_id; |
| 2443 | fsp->m_ext.vlan_tci = mask->formatted.vlan_id; |
| 2444 | fsp->h_ext.vlan_etype = rule->filter.formatted.flex_bytes; |
| 2445 | fsp->m_ext.vlan_etype = mask->formatted.flex_bytes; |
| 2446 | fsp->h_ext.data[1] = htonl(rule->filter.formatted.vm_pool); |
| 2447 | fsp->m_ext.data[1] = htonl(mask->formatted.vm_pool); |
| 2448 | fsp->flow_type |= FLOW_EXT; |
| 2449 | |
| 2450 | /* record action */ |
| 2451 | if (rule->action == IXGBE_FDIR_DROP_QUEUE) |
| 2452 | fsp->ring_cookie = RX_CLS_FLOW_DISC; |
| 2453 | else |
| 2454 | fsp->ring_cookie = rule->action; |
| 2455 | |
| 2456 | return 0; |
| 2457 | } |
| 2458 | |
| 2459 | static int ixgbe_get_ethtool_fdir_all(struct ixgbe_adapter *adapter, |
| 2460 | struct ethtool_rxnfc *cmd, |
| 2461 | u32 *rule_locs) |
| 2462 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2463 | struct hlist_node *node2; |
Alexander Duyck | 3e05334 | 2011-05-11 07:18:47 +0000 | [diff] [blame] | 2464 | struct ixgbe_fdir_filter *rule; |
| 2465 | int cnt = 0; |
| 2466 | |
| 2467 | /* report total rule count */ |
| 2468 | cmd->data = (1024 << adapter->fdir_pballoc) - 2; |
| 2469 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2470 | hlist_for_each_entry_safe(rule, node2, |
Alexander Duyck | 3e05334 | 2011-05-11 07:18:47 +0000 | [diff] [blame] | 2471 | &adapter->fdir_filter_list, fdir_node) { |
| 2472 | if (cnt == cmd->rule_cnt) |
| 2473 | return -EMSGSIZE; |
| 2474 | rule_locs[cnt] = rule->sw_idx; |
| 2475 | cnt++; |
| 2476 | } |
| 2477 | |
Ben Hutchings | 473e64e | 2011-09-06 13:52:47 +0000 | [diff] [blame] | 2478 | cmd->rule_cnt = cnt; |
| 2479 | |
Alexander Duyck | 3e05334 | 2011-05-11 07:18:47 +0000 | [diff] [blame] | 2480 | return 0; |
| 2481 | } |
| 2482 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2483 | static int ixgbe_get_rss_hash_opts(struct ixgbe_adapter *adapter, |
| 2484 | struct ethtool_rxnfc *cmd) |
| 2485 | { |
| 2486 | cmd->data = 0; |
| 2487 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2488 | /* Report default options for RSS on ixgbe */ |
| 2489 | switch (cmd->flow_type) { |
| 2490 | case TCP_V4_FLOW: |
| 2491 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
Jacob Keller | 3bf2379 | 2014-04-09 06:03:17 +0000 | [diff] [blame] | 2492 | /* fallthrough */ |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2493 | case UDP_V4_FLOW: |
| 2494 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
| 2495 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
Jacob Keller | 3bf2379 | 2014-04-09 06:03:17 +0000 | [diff] [blame] | 2496 | /* fallthrough */ |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2497 | case SCTP_V4_FLOW: |
| 2498 | case AH_ESP_V4_FLOW: |
| 2499 | case AH_V4_FLOW: |
| 2500 | case ESP_V4_FLOW: |
| 2501 | case IPV4_FLOW: |
| 2502 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; |
| 2503 | break; |
| 2504 | case TCP_V6_FLOW: |
| 2505 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
Jacob Keller | 3bf2379 | 2014-04-09 06:03:17 +0000 | [diff] [blame] | 2506 | /* fallthrough */ |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2507 | case UDP_V6_FLOW: |
| 2508 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
| 2509 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
Jacob Keller | 3bf2379 | 2014-04-09 06:03:17 +0000 | [diff] [blame] | 2510 | /* fallthrough */ |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2511 | case SCTP_V6_FLOW: |
| 2512 | case AH_ESP_V6_FLOW: |
| 2513 | case AH_V6_FLOW: |
| 2514 | case ESP_V6_FLOW: |
| 2515 | case IPV6_FLOW: |
| 2516 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; |
| 2517 | break; |
| 2518 | default: |
| 2519 | return -EINVAL; |
| 2520 | } |
| 2521 | |
| 2522 | return 0; |
| 2523 | } |
| 2524 | |
Alexander Duyck | 91cd94b | 2011-05-11 07:18:41 +0000 | [diff] [blame] | 2525 | static int ixgbe_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, |
Ben Hutchings | 815c7db | 2011-09-06 13:49:12 +0000 | [diff] [blame] | 2526 | u32 *rule_locs) |
Alexander Duyck | 91cd94b | 2011-05-11 07:18:41 +0000 | [diff] [blame] | 2527 | { |
| 2528 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 2529 | int ret = -EOPNOTSUPP; |
| 2530 | |
| 2531 | switch (cmd->cmd) { |
| 2532 | case ETHTOOL_GRXRINGS: |
| 2533 | cmd->data = adapter->num_rx_queues; |
| 2534 | ret = 0; |
| 2535 | break; |
Alexander Duyck | 3e05334 | 2011-05-11 07:18:47 +0000 | [diff] [blame] | 2536 | case ETHTOOL_GRXCLSRLCNT: |
| 2537 | cmd->rule_cnt = adapter->fdir_filter_count; |
| 2538 | ret = 0; |
| 2539 | break; |
| 2540 | case ETHTOOL_GRXCLSRULE: |
| 2541 | ret = ixgbe_get_ethtool_fdir_entry(adapter, cmd); |
| 2542 | break; |
| 2543 | case ETHTOOL_GRXCLSRLALL: |
Ben Hutchings | 815c7db | 2011-09-06 13:49:12 +0000 | [diff] [blame] | 2544 | ret = ixgbe_get_ethtool_fdir_all(adapter, cmd, rule_locs); |
Alexander Duyck | 3e05334 | 2011-05-11 07:18:47 +0000 | [diff] [blame] | 2545 | break; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2546 | case ETHTOOL_GRXFH: |
| 2547 | ret = ixgbe_get_rss_hash_opts(adapter, cmd); |
| 2548 | break; |
Alexander Duyck | 91cd94b | 2011-05-11 07:18:41 +0000 | [diff] [blame] | 2549 | default: |
| 2550 | break; |
| 2551 | } |
| 2552 | |
| 2553 | return ret; |
| 2554 | } |
| 2555 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 2556 | int ixgbe_update_ethtool_fdir_entry(struct ixgbe_adapter *adapter, |
| 2557 | struct ixgbe_fdir_filter *input, |
| 2558 | u16 sw_idx) |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2559 | { |
| 2560 | struct ixgbe_hw *hw = &adapter->hw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2561 | struct hlist_node *node2; |
| 2562 | struct ixgbe_fdir_filter *rule, *parent; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2563 | int err = -EINVAL; |
| 2564 | |
| 2565 | parent = NULL; |
| 2566 | rule = NULL; |
| 2567 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2568 | hlist_for_each_entry_safe(rule, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2569 | &adapter->fdir_filter_list, fdir_node) { |
| 2570 | /* hash found, or no matching entry */ |
| 2571 | if (rule->sw_idx >= sw_idx) |
| 2572 | break; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2573 | parent = rule; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | /* if there is an old rule occupying our place remove it */ |
| 2577 | if (rule && (rule->sw_idx == sw_idx)) { |
| 2578 | if (!input || (rule->filter.formatted.bkt_hash != |
| 2579 | input->filter.formatted.bkt_hash)) { |
| 2580 | err = ixgbe_fdir_erase_perfect_filter_82599(hw, |
| 2581 | &rule->filter, |
| 2582 | sw_idx); |
| 2583 | } |
| 2584 | |
| 2585 | hlist_del(&rule->fdir_node); |
| 2586 | kfree(rule); |
| 2587 | adapter->fdir_filter_count--; |
| 2588 | } |
| 2589 | |
| 2590 | /* |
| 2591 | * If no input this was a delete, err should be 0 if a rule was |
| 2592 | * successfully found and removed from the list else -EINVAL |
| 2593 | */ |
| 2594 | if (!input) |
| 2595 | return err; |
| 2596 | |
| 2597 | /* initialize node and set software index */ |
| 2598 | INIT_HLIST_NODE(&input->fdir_node); |
| 2599 | |
| 2600 | /* add filter to the list */ |
| 2601 | if (parent) |
Ken Helias | 1d02328 | 2014-08-06 16:09:16 -0700 | [diff] [blame] | 2602 | hlist_add_behind(&input->fdir_node, &parent->fdir_node); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2603 | else |
| 2604 | hlist_add_head(&input->fdir_node, |
| 2605 | &adapter->fdir_filter_list); |
| 2606 | |
| 2607 | /* update counts */ |
| 2608 | adapter->fdir_filter_count++; |
| 2609 | |
| 2610 | return 0; |
| 2611 | } |
| 2612 | |
| 2613 | static int ixgbe_flowspec_to_flow_type(struct ethtool_rx_flow_spec *fsp, |
| 2614 | u8 *flow_type) |
| 2615 | { |
| 2616 | switch (fsp->flow_type & ~FLOW_EXT) { |
| 2617 | case TCP_V4_FLOW: |
| 2618 | *flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 2619 | break; |
| 2620 | case UDP_V4_FLOW: |
| 2621 | *flow_type = IXGBE_ATR_FLOW_TYPE_UDPV4; |
| 2622 | break; |
| 2623 | case SCTP_V4_FLOW: |
| 2624 | *flow_type = IXGBE_ATR_FLOW_TYPE_SCTPV4; |
| 2625 | break; |
| 2626 | case IP_USER_FLOW: |
| 2627 | switch (fsp->h_u.usr_ip4_spec.proto) { |
| 2628 | case IPPROTO_TCP: |
| 2629 | *flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 2630 | break; |
| 2631 | case IPPROTO_UDP: |
| 2632 | *flow_type = IXGBE_ATR_FLOW_TYPE_UDPV4; |
| 2633 | break; |
| 2634 | case IPPROTO_SCTP: |
| 2635 | *flow_type = IXGBE_ATR_FLOW_TYPE_SCTPV4; |
| 2636 | break; |
| 2637 | case 0: |
| 2638 | if (!fsp->m_u.usr_ip4_spec.proto) { |
| 2639 | *flow_type = IXGBE_ATR_FLOW_TYPE_IPV4; |
| 2640 | break; |
| 2641 | } |
| 2642 | default: |
| 2643 | return 0; |
| 2644 | } |
| 2645 | break; |
| 2646 | default: |
| 2647 | return 0; |
| 2648 | } |
| 2649 | |
| 2650 | return 1; |
| 2651 | } |
| 2652 | |
| 2653 | static int ixgbe_add_ethtool_fdir_entry(struct ixgbe_adapter *adapter, |
| 2654 | struct ethtool_rxnfc *cmd) |
| 2655 | { |
| 2656 | struct ethtool_rx_flow_spec *fsp = |
| 2657 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
| 2658 | struct ixgbe_hw *hw = &adapter->hw; |
| 2659 | struct ixgbe_fdir_filter *input; |
| 2660 | union ixgbe_atr_input mask; |
John Fastabend | 7aac842 | 2015-05-26 08:23:33 -0700 | [diff] [blame] | 2661 | u8 queue; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2662 | int err; |
| 2663 | |
| 2664 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 2665 | return -EOPNOTSUPP; |
| 2666 | |
John Fastabend | 7aac842 | 2015-05-26 08:23:33 -0700 | [diff] [blame] | 2667 | /* ring_cookie is a masked into a set of queues and ixgbe pools or |
| 2668 | * we use the drop index. |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2669 | */ |
John Fastabend | 7aac842 | 2015-05-26 08:23:33 -0700 | [diff] [blame] | 2670 | if (fsp->ring_cookie == RX_CLS_FLOW_DISC) { |
| 2671 | queue = IXGBE_FDIR_DROP_QUEUE; |
| 2672 | } else { |
| 2673 | u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie); |
| 2674 | u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie); |
| 2675 | |
| 2676 | if (!vf && (ring >= adapter->num_rx_queues)) |
| 2677 | return -EINVAL; |
| 2678 | else if (vf && |
| 2679 | ((vf > adapter->num_vfs) || |
| 2680 | ring >= adapter->num_rx_queues_per_pool)) |
| 2681 | return -EINVAL; |
| 2682 | |
| 2683 | /* Map the ring onto the absolute queue index */ |
| 2684 | if (!vf) |
| 2685 | queue = adapter->rx_ring[ring]->reg_idx; |
| 2686 | else |
| 2687 | queue = ((vf - 1) * |
| 2688 | adapter->num_rx_queues_per_pool) + ring; |
| 2689 | } |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2690 | |
| 2691 | /* Don't allow indexes to exist outside of available space */ |
| 2692 | if (fsp->location >= ((1024 << adapter->fdir_pballoc) - 2)) { |
| 2693 | e_err(drv, "Location out of range\n"); |
| 2694 | return -EINVAL; |
| 2695 | } |
| 2696 | |
| 2697 | input = kzalloc(sizeof(*input), GFP_ATOMIC); |
| 2698 | if (!input) |
| 2699 | return -ENOMEM; |
| 2700 | |
| 2701 | memset(&mask, 0, sizeof(union ixgbe_atr_input)); |
| 2702 | |
| 2703 | /* set SW index */ |
| 2704 | input->sw_idx = fsp->location; |
| 2705 | |
| 2706 | /* record flow type */ |
| 2707 | if (!ixgbe_flowspec_to_flow_type(fsp, |
| 2708 | &input->filter.formatted.flow_type)) { |
| 2709 | e_err(drv, "Unrecognized flow type\n"); |
| 2710 | goto err_out; |
| 2711 | } |
| 2712 | |
| 2713 | mask.formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK | |
| 2714 | IXGBE_ATR_L4TYPE_MASK; |
| 2715 | |
| 2716 | if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4) |
| 2717 | mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK; |
| 2718 | |
| 2719 | /* Copy input into formatted structures */ |
| 2720 | input->filter.formatted.src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src; |
| 2721 | mask.formatted.src_ip[0] = fsp->m_u.tcp_ip4_spec.ip4src; |
| 2722 | input->filter.formatted.dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst; |
| 2723 | mask.formatted.dst_ip[0] = fsp->m_u.tcp_ip4_spec.ip4dst; |
| 2724 | input->filter.formatted.src_port = fsp->h_u.tcp_ip4_spec.psrc; |
| 2725 | mask.formatted.src_port = fsp->m_u.tcp_ip4_spec.psrc; |
| 2726 | input->filter.formatted.dst_port = fsp->h_u.tcp_ip4_spec.pdst; |
| 2727 | mask.formatted.dst_port = fsp->m_u.tcp_ip4_spec.pdst; |
| 2728 | |
| 2729 | if (fsp->flow_type & FLOW_EXT) { |
| 2730 | input->filter.formatted.vm_pool = |
| 2731 | (unsigned char)ntohl(fsp->h_ext.data[1]); |
| 2732 | mask.formatted.vm_pool = |
| 2733 | (unsigned char)ntohl(fsp->m_ext.data[1]); |
| 2734 | input->filter.formatted.vlan_id = fsp->h_ext.vlan_tci; |
| 2735 | mask.formatted.vlan_id = fsp->m_ext.vlan_tci; |
| 2736 | input->filter.formatted.flex_bytes = |
| 2737 | fsp->h_ext.vlan_etype; |
| 2738 | mask.formatted.flex_bytes = fsp->m_ext.vlan_etype; |
| 2739 | } |
| 2740 | |
| 2741 | /* determine if we need to drop or route the packet */ |
| 2742 | if (fsp->ring_cookie == RX_CLS_FLOW_DISC) |
| 2743 | input->action = IXGBE_FDIR_DROP_QUEUE; |
| 2744 | else |
| 2745 | input->action = fsp->ring_cookie; |
| 2746 | |
| 2747 | spin_lock(&adapter->fdir_perfect_lock); |
| 2748 | |
| 2749 | if (hlist_empty(&adapter->fdir_filter_list)) { |
| 2750 | /* save mask and program input mask into HW */ |
| 2751 | memcpy(&adapter->fdir_mask, &mask, sizeof(mask)); |
| 2752 | err = ixgbe_fdir_set_input_mask_82599(hw, &mask); |
| 2753 | if (err) { |
| 2754 | e_err(drv, "Error writing mask\n"); |
| 2755 | goto err_out_w_lock; |
| 2756 | } |
| 2757 | } else if (memcmp(&adapter->fdir_mask, &mask, sizeof(mask))) { |
| 2758 | e_err(drv, "Only one mask supported per port\n"); |
| 2759 | goto err_out_w_lock; |
| 2760 | } |
| 2761 | |
| 2762 | /* apply mask and compute/store hash */ |
| 2763 | ixgbe_atr_compute_perfect_hash_82599(&input->filter, &mask); |
| 2764 | |
| 2765 | /* program filters to filter memory */ |
| 2766 | err = ixgbe_fdir_write_perfect_filter_82599(hw, |
John Fastabend | 7aac842 | 2015-05-26 08:23:33 -0700 | [diff] [blame] | 2767 | &input->filter, input->sw_idx, queue); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2768 | if (err) |
| 2769 | goto err_out_w_lock; |
| 2770 | |
| 2771 | ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx); |
| 2772 | |
| 2773 | spin_unlock(&adapter->fdir_perfect_lock); |
| 2774 | |
| 2775 | return err; |
| 2776 | err_out_w_lock: |
| 2777 | spin_unlock(&adapter->fdir_perfect_lock); |
| 2778 | err_out: |
| 2779 | kfree(input); |
| 2780 | return -EINVAL; |
| 2781 | } |
| 2782 | |
| 2783 | static int ixgbe_del_ethtool_fdir_entry(struct ixgbe_adapter *adapter, |
| 2784 | struct ethtool_rxnfc *cmd) |
| 2785 | { |
| 2786 | struct ethtool_rx_flow_spec *fsp = |
| 2787 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
| 2788 | int err; |
| 2789 | |
| 2790 | spin_lock(&adapter->fdir_perfect_lock); |
| 2791 | err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, fsp->location); |
| 2792 | spin_unlock(&adapter->fdir_perfect_lock); |
| 2793 | |
| 2794 | return err; |
| 2795 | } |
| 2796 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2797 | #define UDP_RSS_FLAGS (IXGBE_FLAG2_RSS_FIELD_IPV4_UDP | \ |
| 2798 | IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
| 2799 | static int ixgbe_set_rss_hash_opt(struct ixgbe_adapter *adapter, |
| 2800 | struct ethtool_rxnfc *nfc) |
| 2801 | { |
| 2802 | u32 flags2 = adapter->flags2; |
| 2803 | |
| 2804 | /* |
| 2805 | * RSS does not support anything other than hashing |
| 2806 | * to queues on src and dst IPs and ports |
| 2807 | */ |
| 2808 | if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | |
| 2809 | RXH_L4_B_0_1 | RXH_L4_B_2_3)) |
| 2810 | return -EINVAL; |
| 2811 | |
| 2812 | switch (nfc->flow_type) { |
| 2813 | case TCP_V4_FLOW: |
| 2814 | case TCP_V6_FLOW: |
| 2815 | if (!(nfc->data & RXH_IP_SRC) || |
| 2816 | !(nfc->data & RXH_IP_DST) || |
| 2817 | !(nfc->data & RXH_L4_B_0_1) || |
| 2818 | !(nfc->data & RXH_L4_B_2_3)) |
| 2819 | return -EINVAL; |
| 2820 | break; |
| 2821 | case UDP_V4_FLOW: |
| 2822 | if (!(nfc->data & RXH_IP_SRC) || |
| 2823 | !(nfc->data & RXH_IP_DST)) |
| 2824 | return -EINVAL; |
| 2825 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 2826 | case 0: |
| 2827 | flags2 &= ~IXGBE_FLAG2_RSS_FIELD_IPV4_UDP; |
| 2828 | break; |
| 2829 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 2830 | flags2 |= IXGBE_FLAG2_RSS_FIELD_IPV4_UDP; |
| 2831 | break; |
| 2832 | default: |
| 2833 | return -EINVAL; |
| 2834 | } |
| 2835 | break; |
| 2836 | case UDP_V6_FLOW: |
| 2837 | if (!(nfc->data & RXH_IP_SRC) || |
| 2838 | !(nfc->data & RXH_IP_DST)) |
| 2839 | return -EINVAL; |
| 2840 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 2841 | case 0: |
| 2842 | flags2 &= ~IXGBE_FLAG2_RSS_FIELD_IPV6_UDP; |
| 2843 | break; |
| 2844 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 2845 | flags2 |= IXGBE_FLAG2_RSS_FIELD_IPV6_UDP; |
| 2846 | break; |
| 2847 | default: |
| 2848 | return -EINVAL; |
| 2849 | } |
| 2850 | break; |
| 2851 | case AH_ESP_V4_FLOW: |
| 2852 | case AH_V4_FLOW: |
| 2853 | case ESP_V4_FLOW: |
| 2854 | case SCTP_V4_FLOW: |
| 2855 | case AH_ESP_V6_FLOW: |
| 2856 | case AH_V6_FLOW: |
| 2857 | case ESP_V6_FLOW: |
| 2858 | case SCTP_V6_FLOW: |
| 2859 | if (!(nfc->data & RXH_IP_SRC) || |
| 2860 | !(nfc->data & RXH_IP_DST) || |
| 2861 | (nfc->data & RXH_L4_B_0_1) || |
| 2862 | (nfc->data & RXH_L4_B_2_3)) |
| 2863 | return -EINVAL; |
| 2864 | break; |
| 2865 | default: |
| 2866 | return -EINVAL; |
| 2867 | } |
| 2868 | |
| 2869 | /* if we changed something we need to update flags */ |
| 2870 | if (flags2 != adapter->flags2) { |
| 2871 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2872 | u32 mrqc; |
| 2873 | unsigned int pf_pool = adapter->num_vfs; |
| 2874 | |
| 2875 | if ((hw->mac.type >= ixgbe_mac_X550) && |
| 2876 | (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2877 | mrqc = IXGBE_READ_REG(hw, IXGBE_PFVFMRQC(pf_pool)); |
| 2878 | else |
| 2879 | mrqc = IXGBE_READ_REG(hw, IXGBE_MRQC); |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2880 | |
| 2881 | if ((flags2 & UDP_RSS_FLAGS) && |
| 2882 | !(adapter->flags2 & UDP_RSS_FLAGS)) |
Jacob Keller | 6ec1b71 | 2014-04-09 06:03:13 +0000 | [diff] [blame] | 2883 | e_warn(drv, "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n"); |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2884 | |
| 2885 | adapter->flags2 = flags2; |
| 2886 | |
| 2887 | /* Perform hash on these packet types */ |
| 2888 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2889 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2890 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2891 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
| 2892 | |
| 2893 | mrqc &= ~(IXGBE_MRQC_RSS_FIELD_IPV4_UDP | |
| 2894 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP); |
| 2895 | |
| 2896 | if (flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
| 2897 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
| 2898 | |
| 2899 | if (flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
| 2900 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
| 2901 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2902 | if ((hw->mac.type >= ixgbe_mac_X550) && |
| 2903 | (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 2904 | IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), mrqc); |
| 2905 | else |
| 2906 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | return 0; |
| 2910 | } |
| 2911 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2912 | static int ixgbe_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) |
| 2913 | { |
| 2914 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 2915 | int ret = -EOPNOTSUPP; |
| 2916 | |
| 2917 | switch (cmd->cmd) { |
| 2918 | case ETHTOOL_SRXCLSRLINS: |
| 2919 | ret = ixgbe_add_ethtool_fdir_entry(adapter, cmd); |
| 2920 | break; |
| 2921 | case ETHTOOL_SRXCLSRLDEL: |
| 2922 | ret = ixgbe_del_ethtool_fdir_entry(adapter, cmd); |
| 2923 | break; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 2924 | case ETHTOOL_SRXFH: |
| 2925 | ret = ixgbe_set_rss_hash_opt(adapter, cmd); |
| 2926 | break; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 2927 | default: |
| 2928 | break; |
| 2929 | } |
| 2930 | |
| 2931 | return ret; |
| 2932 | } |
| 2933 | |
Tom Barbette | 1c7cf07 | 2015-06-26 15:40:18 +0200 | [diff] [blame] | 2934 | static int ixgbe_rss_indir_tbl_max(struct ixgbe_adapter *adapter) |
| 2935 | { |
| 2936 | if (adapter->hw.mac.type < ixgbe_mac_X550) |
| 2937 | return 16; |
| 2938 | else |
| 2939 | return 64; |
| 2940 | } |
| 2941 | |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 2942 | static u32 ixgbe_get_rxfh_key_size(struct net_device *netdev) |
| 2943 | { |
| 2944 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2945 | |
| 2946 | return sizeof(adapter->rss_key); |
| 2947 | } |
| 2948 | |
| 2949 | static u32 ixgbe_rss_indir_size(struct net_device *netdev) |
| 2950 | { |
| 2951 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2952 | |
| 2953 | return ixgbe_rss_indir_tbl_entries(adapter); |
| 2954 | } |
| 2955 | |
| 2956 | static void ixgbe_get_reta(struct ixgbe_adapter *adapter, u32 *indir) |
| 2957 | { |
| 2958 | int i, reta_size = ixgbe_rss_indir_tbl_entries(adapter); |
Alexander Duyck | fa81da7 | 2016-09-07 20:28:17 -0700 | [diff] [blame] | 2959 | u16 rss_m = adapter->ring_feature[RING_F_RSS].mask; |
| 2960 | |
| 2961 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 2962 | rss_m = adapter->ring_feature[RING_F_RSS].indices - 1; |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 2963 | |
| 2964 | for (i = 0; i < reta_size; i++) |
Alexander Duyck | fa81da7 | 2016-09-07 20:28:17 -0700 | [diff] [blame] | 2965 | indir[i] = adapter->rss_indir_tbl[i] & rss_m; |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | static int ixgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, |
| 2969 | u8 *hfunc) |
| 2970 | { |
| 2971 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2972 | |
| 2973 | if (hfunc) |
| 2974 | *hfunc = ETH_RSS_HASH_TOP; |
| 2975 | |
| 2976 | if (indir) |
| 2977 | ixgbe_get_reta(adapter, indir); |
| 2978 | |
| 2979 | if (key) |
| 2980 | memcpy(key, adapter->rss_key, ixgbe_get_rxfh_key_size(netdev)); |
| 2981 | |
| 2982 | return 0; |
| 2983 | } |
| 2984 | |
Tom Barbette | 1c7cf07 | 2015-06-26 15:40:18 +0200 | [diff] [blame] | 2985 | static int ixgbe_set_rxfh(struct net_device *netdev, const u32 *indir, |
| 2986 | const u8 *key, const u8 hfunc) |
| 2987 | { |
| 2988 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2989 | int i; |
| 2990 | u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 2991 | |
| 2992 | if (hfunc) |
| 2993 | return -EINVAL; |
| 2994 | |
| 2995 | /* Fill out the redirection table */ |
| 2996 | if (indir) { |
| 2997 | int max_queues = min_t(int, adapter->num_rx_queues, |
| 2998 | ixgbe_rss_indir_tbl_max(adapter)); |
| 2999 | |
| 3000 | /*Allow at least 2 queues w/ SR-IOV.*/ |
| 3001 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 3002 | (max_queues < 2)) |
| 3003 | max_queues = 2; |
| 3004 | |
| 3005 | /* Verify user input. */ |
| 3006 | for (i = 0; i < reta_entries; i++) |
| 3007 | if (indir[i] >= max_queues) |
| 3008 | return -EINVAL; |
| 3009 | |
| 3010 | for (i = 0; i < reta_entries; i++) |
| 3011 | adapter->rss_indir_tbl[i] = indir[i]; |
| 3012 | } |
| 3013 | |
| 3014 | /* Fill out the rss hash key */ |
| 3015 | if (key) |
| 3016 | memcpy(adapter->rss_key, key, ixgbe_get_rxfh_key_size(netdev)); |
| 3017 | |
| 3018 | ixgbe_store_reta(adapter); |
| 3019 | |
| 3020 | return 0; |
| 3021 | } |
| 3022 | |
Jacob Keller | e3aac88 | 2012-05-04 02:56:12 +0000 | [diff] [blame] | 3023 | static int ixgbe_get_ts_info(struct net_device *dev, |
| 3024 | struct ethtool_ts_info *info) |
| 3025 | { |
| 3026 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 3027 | |
Tony Nguyen | 918b89e | 2016-06-01 09:50:43 -0700 | [diff] [blame] | 3028 | /* we always support timestamping disabled */ |
| 3029 | info->rx_filters = BIT(HWTSTAMP_FILTER_NONE); |
| 3030 | |
Jacob Keller | e3aac88 | 2012-05-04 02:56:12 +0000 | [diff] [blame] | 3031 | switch (adapter->hw.mac.type) { |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3032 | case ixgbe_mac_X550: |
| 3033 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3034 | case ixgbe_mac_x550em_a: |
Tony Nguyen | 918b89e | 2016-06-01 09:50:43 -0700 | [diff] [blame] | 3035 | info->rx_filters |= BIT(HWTSTAMP_FILTER_ALL); |
| 3036 | /* fallthrough */ |
Jacob Keller | e3aac88 | 2012-05-04 02:56:12 +0000 | [diff] [blame] | 3037 | case ixgbe_mac_X540: |
| 3038 | case ixgbe_mac_82599EB: |
| 3039 | info->so_timestamping = |
Jacob Keller | 50f8d35 | 2012-10-31 22:30:54 +0000 | [diff] [blame] | 3040 | SOF_TIMESTAMPING_TX_SOFTWARE | |
| 3041 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 3042 | SOF_TIMESTAMPING_SOFTWARE | |
Jacob Keller | e3aac88 | 2012-05-04 02:56:12 +0000 | [diff] [blame] | 3043 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 3044 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 3045 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 3046 | |
| 3047 | if (adapter->ptp_clock) |
| 3048 | info->phc_index = ptp_clock_index(adapter->ptp_clock); |
| 3049 | else |
| 3050 | info->phc_index = -1; |
| 3051 | |
| 3052 | info->tx_types = |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3053 | BIT(HWTSTAMP_TX_OFF) | |
| 3054 | BIT(HWTSTAMP_TX_ON); |
Jacob Keller | e3aac88 | 2012-05-04 02:56:12 +0000 | [diff] [blame] | 3055 | |
Tony Nguyen | 918b89e | 2016-06-01 09:50:43 -0700 | [diff] [blame] | 3056 | info->rx_filters |= |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3057 | BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | |
| 3058 | BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | |
| 3059 | BIT(HWTSTAMP_FILTER_PTP_V2_EVENT); |
Jacob Keller | e3aac88 | 2012-05-04 02:56:12 +0000 | [diff] [blame] | 3060 | break; |
Jacob Keller | e3aac88 | 2012-05-04 02:56:12 +0000 | [diff] [blame] | 3061 | default: |
| 3062 | return ethtool_op_get_ts_info(dev, info); |
Jacob Keller | e3aac88 | 2012-05-04 02:56:12 +0000 | [diff] [blame] | 3063 | } |
| 3064 | return 0; |
| 3065 | } |
| 3066 | |
Alexander Duyck | 5348c9d | 2013-01-12 06:33:52 +0000 | [diff] [blame] | 3067 | static unsigned int ixgbe_max_channels(struct ixgbe_adapter *adapter) |
| 3068 | { |
| 3069 | unsigned int max_combined; |
| 3070 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
| 3071 | |
| 3072 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 3073 | /* We only support one q_vector without MSI-X */ |
| 3074 | max_combined = 1; |
| 3075 | } else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Alexander Duyck | 3b00da0 | 2016-09-07 20:28:11 -0700 | [diff] [blame] | 3076 | /* Limit value based on the queue mask */ |
| 3077 | max_combined = adapter->ring_feature[RING_F_RSS].mask + 1; |
Alexander Duyck | 5348c9d | 2013-01-12 06:33:52 +0000 | [diff] [blame] | 3078 | } else if (tcs > 1) { |
| 3079 | /* For DCB report channels per traffic class */ |
| 3080 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 3081 | /* 8 TC w/ 4 queues per TC */ |
| 3082 | max_combined = 4; |
| 3083 | } else if (tcs > 4) { |
| 3084 | /* 8 TC w/ 8 queues per TC */ |
| 3085 | max_combined = 8; |
| 3086 | } else { |
| 3087 | /* 4 TC w/ 16 queues per TC */ |
| 3088 | max_combined = 16; |
| 3089 | } |
| 3090 | } else if (adapter->atr_sample_rate) { |
| 3091 | /* support up to 64 queues with ATR */ |
| 3092 | max_combined = IXGBE_MAX_FDIR_INDICES; |
| 3093 | } else { |
| 3094 | /* support up to 16 queues with RSS */ |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3095 | max_combined = ixgbe_max_rss_indices(adapter); |
Alexander Duyck | 5348c9d | 2013-01-12 06:33:52 +0000 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | return max_combined; |
| 3099 | } |
| 3100 | |
| 3101 | static void ixgbe_get_channels(struct net_device *dev, |
| 3102 | struct ethtool_channels *ch) |
| 3103 | { |
| 3104 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 3105 | |
| 3106 | /* report maximum channels */ |
| 3107 | ch->max_combined = ixgbe_max_channels(adapter); |
| 3108 | |
| 3109 | /* report info for other vector */ |
| 3110 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3111 | ch->max_other = NON_Q_VECTORS; |
| 3112 | ch->other_count = NON_Q_VECTORS; |
| 3113 | } |
| 3114 | |
| 3115 | /* record RSS queues */ |
| 3116 | ch->combined_count = adapter->ring_feature[RING_F_RSS].indices; |
| 3117 | |
| 3118 | /* nothing else to report if RSS is disabled */ |
| 3119 | if (ch->combined_count == 1) |
| 3120 | return; |
| 3121 | |
| 3122 | /* we do not support ATR queueing if SR-IOV is enabled */ |
| 3123 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3124 | return; |
| 3125 | |
| 3126 | /* same thing goes for being DCB enabled */ |
| 3127 | if (netdev_get_num_tc(dev) > 1) |
| 3128 | return; |
| 3129 | |
| 3130 | /* if ATR is disabled we can exit */ |
| 3131 | if (!adapter->atr_sample_rate) |
| 3132 | return; |
| 3133 | |
| 3134 | /* report flow director queues as maximum channels */ |
| 3135 | ch->combined_count = adapter->ring_feature[RING_F_FDIR].indices; |
| 3136 | } |
| 3137 | |
Alexander Duyck | 4c696ca | 2013-01-17 08:39:33 +0000 | [diff] [blame] | 3138 | static int ixgbe_set_channels(struct net_device *dev, |
| 3139 | struct ethtool_channels *ch) |
| 3140 | { |
| 3141 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 3142 | unsigned int count = ch->combined_count; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3143 | u8 max_rss_indices = ixgbe_max_rss_indices(adapter); |
Alexander Duyck | 4c696ca | 2013-01-17 08:39:33 +0000 | [diff] [blame] | 3144 | |
| 3145 | /* verify they are not requesting separate vectors */ |
| 3146 | if (!count || ch->rx_count || ch->tx_count) |
| 3147 | return -EINVAL; |
| 3148 | |
| 3149 | /* verify other_count has not changed */ |
| 3150 | if (ch->other_count != NON_Q_VECTORS) |
| 3151 | return -EINVAL; |
| 3152 | |
| 3153 | /* verify the number of channels does not exceed hardware limits */ |
| 3154 | if (count > ixgbe_max_channels(adapter)) |
| 3155 | return -EINVAL; |
| 3156 | |
| 3157 | /* update feature limits from largest to smallest supported values */ |
| 3158 | adapter->ring_feature[RING_F_FDIR].limit = count; |
| 3159 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3160 | /* cap RSS limit */ |
| 3161 | if (count > max_rss_indices) |
| 3162 | count = max_rss_indices; |
Alexander Duyck | 4c696ca | 2013-01-17 08:39:33 +0000 | [diff] [blame] | 3163 | adapter->ring_feature[RING_F_RSS].limit = count; |
| 3164 | |
| 3165 | #ifdef IXGBE_FCOE |
| 3166 | /* cap FCoE limit at 8 */ |
| 3167 | if (count > IXGBE_FCRETA_SIZE) |
| 3168 | count = IXGBE_FCRETA_SIZE; |
| 3169 | adapter->ring_feature[RING_F_FCOE].limit = count; |
| 3170 | |
| 3171 | #endif |
| 3172 | /* use setup TC to update any traffic class queue mapping */ |
| 3173 | return ixgbe_setup_tc(dev, netdev_get_num_tc(dev)); |
| 3174 | } |
| 3175 | |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3176 | static int ixgbe_get_module_info(struct net_device *dev, |
| 3177 | struct ethtool_modinfo *modinfo) |
| 3178 | { |
| 3179 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 3180 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 3181 | s32 status; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3182 | u8 sff8472_rev, addr_mode; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3183 | bool page_swap = false; |
| 3184 | |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 3185 | if (hw->phy.type == ixgbe_phy_fw) |
| 3186 | return -ENXIO; |
| 3187 | |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3188 | /* Check whether we support SFF-8472 or not */ |
| 3189 | status = hw->phy.ops.read_i2c_eeprom(hw, |
| 3190 | IXGBE_SFF_SFF_8472_COMP, |
| 3191 | &sff8472_rev); |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 3192 | if (status) |
Emil Tantilov | a4b6fc6 | 2013-05-29 06:23:10 +0000 | [diff] [blame] | 3193 | return -EIO; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3194 | |
| 3195 | /* addressing mode is not supported */ |
| 3196 | status = hw->phy.ops.read_i2c_eeprom(hw, |
| 3197 | IXGBE_SFF_SFF_8472_SWAP, |
| 3198 | &addr_mode); |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 3199 | if (status) |
Emil Tantilov | a4b6fc6 | 2013-05-29 06:23:10 +0000 | [diff] [blame] | 3200 | return -EIO; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3201 | |
| 3202 | if (addr_mode & IXGBE_SFF_ADDRESSING_MODE) { |
| 3203 | e_err(drv, "Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n"); |
| 3204 | page_swap = true; |
| 3205 | } |
| 3206 | |
| 3207 | if (sff8472_rev == IXGBE_SFF_SFF_8472_UNSUP || page_swap) { |
| 3208 | /* We have a SFP, but it does not support SFF-8472 */ |
| 3209 | modinfo->type = ETH_MODULE_SFF_8079; |
| 3210 | modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; |
| 3211 | } else { |
| 3212 | /* We have a SFP which supports a revision of SFF-8472. */ |
| 3213 | modinfo->type = ETH_MODULE_SFF_8472; |
| 3214 | modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; |
| 3215 | } |
| 3216 | |
Emil Tantilov | a4b6fc6 | 2013-05-29 06:23:10 +0000 | [diff] [blame] | 3217 | return 0; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | static int ixgbe_get_module_eeprom(struct net_device *dev, |
| 3221 | struct ethtool_eeprom *ee, |
| 3222 | u8 *data) |
| 3223 | { |
| 3224 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 3225 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 3226 | s32 status = IXGBE_ERR_PHY_ADDR_INVALID; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3227 | u8 databyte = 0xFF; |
| 3228 | int i = 0; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3229 | |
Emil Tantilov | a4b6fc6 | 2013-05-29 06:23:10 +0000 | [diff] [blame] | 3230 | if (ee->len == 0) |
| 3231 | return -EINVAL; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3232 | |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 3233 | if (hw->phy.type == ixgbe_phy_fw) |
| 3234 | return -ENXIO; |
| 3235 | |
Emil Tantilov | 31c7d2b | 2013-08-13 04:59:29 +0000 | [diff] [blame] | 3236 | for (i = ee->offset; i < ee->offset + ee->len; i++) { |
Emil Tantilov | a4b6fc6 | 2013-05-29 06:23:10 +0000 | [diff] [blame] | 3237 | /* I2C reads can take long time */ |
| 3238 | if (test_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 3239 | return -EBUSY; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3240 | |
Emil Tantilov | a4b6fc6 | 2013-05-29 06:23:10 +0000 | [diff] [blame] | 3241 | if (i < ETH_MODULE_SFF_8079_LEN) |
Emil Tantilov | 31c7d2b | 2013-08-13 04:59:29 +0000 | [diff] [blame] | 3242 | status = hw->phy.ops.read_i2c_eeprom(hw, i, &databyte); |
Emil Tantilov | a4b6fc6 | 2013-05-29 06:23:10 +0000 | [diff] [blame] | 3243 | else |
| 3244 | status = hw->phy.ops.read_i2c_sff8472(hw, i, &databyte); |
| 3245 | |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 3246 | if (status) |
Emil Tantilov | 31c7d2b | 2013-08-13 04:59:29 +0000 | [diff] [blame] | 3247 | return -EIO; |
Emil Tantilov | a4b6fc6 | 2013-05-29 06:23:10 +0000 | [diff] [blame] | 3248 | |
| 3249 | data[i - ee->offset] = databyte; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
Emil Tantilov | 31c7d2b | 2013-08-13 04:59:29 +0000 | [diff] [blame] | 3252 | return 0; |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3253 | } |
| 3254 | |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 3255 | static const struct { |
| 3256 | ixgbe_link_speed mac_speed; |
| 3257 | u32 supported; |
| 3258 | } ixgbe_ls_map[] = { |
| 3259 | { IXGBE_LINK_SPEED_10_FULL, SUPPORTED_10baseT_Full }, |
| 3260 | { IXGBE_LINK_SPEED_100_FULL, SUPPORTED_100baseT_Full }, |
| 3261 | { IXGBE_LINK_SPEED_1GB_FULL, SUPPORTED_1000baseT_Full }, |
| 3262 | { IXGBE_LINK_SPEED_2_5GB_FULL, SUPPORTED_2500baseX_Full }, |
| 3263 | { IXGBE_LINK_SPEED_10GB_FULL, SUPPORTED_10000baseT_Full }, |
| 3264 | }; |
| 3265 | |
| 3266 | static const struct { |
| 3267 | u32 lp_advertised; |
| 3268 | u32 mac_speed; |
| 3269 | } ixgbe_lp_map[] = { |
| 3270 | { FW_PHY_ACT_UD_2_100M_TX_EEE, SUPPORTED_100baseT_Full }, |
| 3271 | { FW_PHY_ACT_UD_2_1G_T_EEE, SUPPORTED_1000baseT_Full }, |
| 3272 | { FW_PHY_ACT_UD_2_10G_T_EEE, SUPPORTED_10000baseT_Full }, |
| 3273 | { FW_PHY_ACT_UD_2_1G_KX_EEE, SUPPORTED_1000baseKX_Full }, |
| 3274 | { FW_PHY_ACT_UD_2_10G_KX4_EEE, SUPPORTED_10000baseKX4_Full }, |
| 3275 | { FW_PHY_ACT_UD_2_10G_KR_EEE, SUPPORTED_10000baseKR_Full}, |
| 3276 | }; |
| 3277 | |
| 3278 | static int |
| 3279 | ixgbe_get_eee_fw(struct ixgbe_adapter *adapter, struct ethtool_eee *edata) |
| 3280 | { |
| 3281 | u32 info[FW_PHY_ACT_DATA_COUNT] = { 0 }; |
| 3282 | struct ixgbe_hw *hw = &adapter->hw; |
| 3283 | s32 rc; |
| 3284 | u16 i; |
| 3285 | |
| 3286 | rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_UD_2, &info); |
| 3287 | if (rc) |
| 3288 | return rc; |
| 3289 | |
| 3290 | edata->lp_advertised = 0; |
| 3291 | for (i = 0; i < ARRAY_SIZE(ixgbe_lp_map); ++i) { |
| 3292 | if (info[0] & ixgbe_lp_map[i].lp_advertised) |
| 3293 | edata->lp_advertised |= ixgbe_lp_map[i].mac_speed; |
| 3294 | } |
| 3295 | |
| 3296 | edata->supported = 0; |
| 3297 | for (i = 0; i < ARRAY_SIZE(ixgbe_ls_map); ++i) { |
| 3298 | if (hw->phy.eee_speeds_supported & ixgbe_ls_map[i].mac_speed) |
| 3299 | edata->supported |= ixgbe_ls_map[i].supported; |
| 3300 | } |
| 3301 | |
| 3302 | edata->advertised = 0; |
| 3303 | for (i = 0; i < ARRAY_SIZE(ixgbe_ls_map); ++i) { |
| 3304 | if (hw->phy.eee_speeds_advertised & ixgbe_ls_map[i].mac_speed) |
| 3305 | edata->advertised |= ixgbe_ls_map[i].supported; |
| 3306 | } |
| 3307 | |
| 3308 | edata->eee_enabled = !!edata->advertised; |
| 3309 | edata->tx_lpi_enabled = edata->eee_enabled; |
| 3310 | if (edata->advertised & edata->lp_advertised) |
| 3311 | edata->eee_active = true; |
| 3312 | |
| 3313 | return 0; |
| 3314 | } |
| 3315 | |
| 3316 | static int ixgbe_get_eee(struct net_device *netdev, struct ethtool_eee *edata) |
| 3317 | { |
| 3318 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3319 | struct ixgbe_hw *hw = &adapter->hw; |
| 3320 | |
| 3321 | if (!(adapter->flags2 & IXGBE_FLAG2_EEE_CAPABLE)) |
| 3322 | return -EOPNOTSUPP; |
| 3323 | |
| 3324 | if (hw->phy.eee_speeds_supported && hw->phy.type == ixgbe_phy_fw) |
| 3325 | return ixgbe_get_eee_fw(adapter, edata); |
| 3326 | |
| 3327 | return -EOPNOTSUPP; |
| 3328 | } |
| 3329 | |
| 3330 | static int ixgbe_set_eee(struct net_device *netdev, struct ethtool_eee *edata) |
| 3331 | { |
| 3332 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3333 | struct ixgbe_hw *hw = &adapter->hw; |
| 3334 | struct ethtool_eee eee_data; |
| 3335 | s32 ret_val; |
| 3336 | |
| 3337 | if (!(adapter->flags2 & IXGBE_FLAG2_EEE_CAPABLE)) |
| 3338 | return -EOPNOTSUPP; |
| 3339 | |
| 3340 | memset(&eee_data, 0, sizeof(struct ethtool_eee)); |
| 3341 | |
| 3342 | ret_val = ixgbe_get_eee(netdev, &eee_data); |
| 3343 | if (ret_val) |
| 3344 | return ret_val; |
| 3345 | |
| 3346 | if (eee_data.eee_enabled && !edata->eee_enabled) { |
| 3347 | if (eee_data.tx_lpi_enabled != edata->tx_lpi_enabled) { |
| 3348 | e_err(drv, "Setting EEE tx-lpi is not supported\n"); |
| 3349 | return -EINVAL; |
| 3350 | } |
| 3351 | |
| 3352 | if (eee_data.tx_lpi_timer != edata->tx_lpi_timer) { |
| 3353 | e_err(drv, |
| 3354 | "Setting EEE Tx LPI timer is not supported\n"); |
| 3355 | return -EINVAL; |
| 3356 | } |
| 3357 | |
| 3358 | if (eee_data.advertised != edata->advertised) { |
| 3359 | e_err(drv, |
| 3360 | "Setting EEE advertised speeds is not supported\n"); |
| 3361 | return -EINVAL; |
| 3362 | } |
| 3363 | } |
| 3364 | |
| 3365 | if (eee_data.eee_enabled != edata->eee_enabled) { |
| 3366 | if (edata->eee_enabled) { |
| 3367 | adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED; |
| 3368 | hw->phy.eee_speeds_advertised = |
| 3369 | hw->phy.eee_speeds_supported; |
| 3370 | } else { |
| 3371 | adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED; |
| 3372 | hw->phy.eee_speeds_advertised = 0; |
| 3373 | } |
| 3374 | |
| 3375 | /* reset link */ |
| 3376 | if (netif_running(netdev)) |
| 3377 | ixgbe_reinit_locked(adapter); |
| 3378 | else |
| 3379 | ixgbe_reset(adapter); |
| 3380 | } |
| 3381 | |
| 3382 | return 0; |
| 3383 | } |
| 3384 | |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3385 | static const struct ethtool_ops ixgbe_ethtool_ops = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3386 | .get_settings = ixgbe_get_settings, |
| 3387 | .set_settings = ixgbe_set_settings, |
| 3388 | .get_drvinfo = ixgbe_get_drvinfo, |
| 3389 | .get_regs_len = ixgbe_get_regs_len, |
| 3390 | .get_regs = ixgbe_get_regs, |
| 3391 | .get_wol = ixgbe_get_wol, |
PJ Waskiewicz | e63d976 | 2009-03-19 01:23:46 +0000 | [diff] [blame] | 3392 | .set_wol = ixgbe_set_wol, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3393 | .nway_reset = ixgbe_nway_reset, |
| 3394 | .get_link = ethtool_op_get_link, |
| 3395 | .get_eeprom_len = ixgbe_get_eeprom_len, |
| 3396 | .get_eeprom = ixgbe_get_eeprom, |
Emil Tantilov | 2fa5eef | 2011-10-06 08:57:04 +0000 | [diff] [blame] | 3397 | .set_eeprom = ixgbe_set_eeprom, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3398 | .get_ringparam = ixgbe_get_ringparam, |
| 3399 | .set_ringparam = ixgbe_set_ringparam, |
| 3400 | .get_pauseparam = ixgbe_get_pauseparam, |
| 3401 | .set_pauseparam = ixgbe_set_pauseparam, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3402 | .get_msglevel = ixgbe_get_msglevel, |
| 3403 | .set_msglevel = ixgbe_set_msglevel, |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3404 | .self_test = ixgbe_diag_test, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3405 | .get_strings = ixgbe_get_strings, |
Emil Tantilov | 66e6961 | 2011-04-16 06:12:51 +0000 | [diff] [blame] | 3406 | .set_phys_id = ixgbe_set_phys_id, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3407 | .get_sset_count = ixgbe_get_sset_count, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3408 | .get_ethtool_stats = ixgbe_get_ethtool_stats, |
| 3409 | .get_coalesce = ixgbe_get_coalesce, |
| 3410 | .set_coalesce = ixgbe_set_coalesce, |
Alexander Duyck | 91cd94b | 2011-05-11 07:18:41 +0000 | [diff] [blame] | 3411 | .get_rxnfc = ixgbe_get_rxnfc, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 3412 | .set_rxnfc = ixgbe_set_rxnfc, |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 3413 | .get_rxfh_indir_size = ixgbe_rss_indir_size, |
| 3414 | .get_rxfh_key_size = ixgbe_get_rxfh_key_size, |
| 3415 | .get_rxfh = ixgbe_get_rxfh, |
Tom Barbette | 1c7cf07 | 2015-06-26 15:40:18 +0200 | [diff] [blame] | 3416 | .set_rxfh = ixgbe_set_rxfh, |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 3417 | .get_eee = ixgbe_get_eee, |
| 3418 | .set_eee = ixgbe_set_eee, |
Alexander Duyck | 5348c9d | 2013-01-12 06:33:52 +0000 | [diff] [blame] | 3419 | .get_channels = ixgbe_get_channels, |
Alexander Duyck | 4c696ca | 2013-01-17 08:39:33 +0000 | [diff] [blame] | 3420 | .set_channels = ixgbe_set_channels, |
Jacob Keller | e3aac88 | 2012-05-04 02:56:12 +0000 | [diff] [blame] | 3421 | .get_ts_info = ixgbe_get_ts_info, |
Aurélien Guillaume | 71858ac | 2013-01-17 06:55:24 +0000 | [diff] [blame] | 3422 | .get_module_info = ixgbe_get_module_info, |
| 3423 | .get_module_eeprom = ixgbe_get_module_eeprom, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3424 | }; |
| 3425 | |
| 3426 | void ixgbe_set_ethtool_ops(struct net_device *netdev) |
| 3427 | { |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 3428 | netdev->ethtool_ops = &ixgbe_ethtool_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3429 | } |