blob: ae58a928d05c96dc08dae7151b1644b386889dd2 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore434c5e32013-01-08 05:02:28 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
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:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28/* ethtool support for ixgbe */
29
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000030#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070031#include <linux/types.h>
32#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070034#include <linux/pci.h>
35#include <linux/netdevice.h>
36#include <linux/ethtool.h>
37#include <linux/vmalloc.h>
Alexander Duyckf8003262012-03-03 02:35:52 +000038#include <linux/highmem.h>
Auke Kok9a799d72007-09-15 14:07:45 -070039#include <linux/uaccess.h>
40
41#include "ixgbe.h"
Aurélien Guillaume71858ac2013-01-17 06:55:24 +000042#include "ixgbe_phy.h"
Auke Kok9a799d72007-09-15 14:07:45 -070043
44
45#define IXGBE_ALL_RAR_ENTRIES 16
46
Ajit Khaparde29c3a052009-10-13 01:47:33 +000047enum {NETDEV_STATS, IXGBE_STATS};
48
Auke Kok9a799d72007-09-15 14:07:45 -070049struct ixgbe_stats {
50 char stat_string[ETH_GSTRING_LEN];
Ajit Khaparde29c3a052009-10-13 01:47:33 +000051 int type;
Auke Kok9a799d72007-09-15 14:07:45 -070052 int sizeof_stat;
53 int stat_offset;
54};
55
Ajit Khaparde29c3a052009-10-13 01:47:33 +000056#define IXGBE_STAT(m) IXGBE_STATS, \
57 sizeof(((struct ixgbe_adapter *)0)->m), \
58 offsetof(struct ixgbe_adapter, m)
59#define IXGBE_NETDEV_STAT(m) NETDEV_STATS, \
Eric Dumazet55bad822010-07-23 13:44:21 +000060 sizeof(((struct rtnl_link_stats64 *)0)->m), \
61 offsetof(struct rtnl_link_stats64, m)
Ajit Khaparde29c3a052009-10-13 01:47:33 +000062
Stephen Hemminger1bba2e82012-01-05 06:29:54 +000063static const struct ixgbe_stats ixgbe_gstrings_stats[] = {
Eric Dumazet55bad822010-07-23 13:44:21 +000064 {"rx_packets", IXGBE_NETDEV_STAT(rx_packets)},
65 {"tx_packets", IXGBE_NETDEV_STAT(tx_packets)},
66 {"rx_bytes", IXGBE_NETDEV_STAT(rx_bytes)},
67 {"tx_bytes", IXGBE_NETDEV_STAT(tx_bytes)},
Ben Greearaad71912009-09-30 12:08:16 +000068 {"rx_pkts_nic", IXGBE_STAT(stats.gprc)},
69 {"tx_pkts_nic", IXGBE_STAT(stats.gptc)},
70 {"rx_bytes_nic", IXGBE_STAT(stats.gorc)},
71 {"tx_bytes_nic", IXGBE_STAT(stats.gotc)},
Auke Kok9a799d72007-09-15 14:07:45 -070072 {"lsc_int", IXGBE_STAT(lsc_int)},
73 {"tx_busy", IXGBE_STAT(tx_busy)},
74 {"non_eop_descs", IXGBE_STAT(non_eop_descs)},
Eric Dumazet55bad822010-07-23 13:44:21 +000075 {"rx_errors", IXGBE_NETDEV_STAT(rx_errors)},
76 {"tx_errors", IXGBE_NETDEV_STAT(tx_errors)},
77 {"rx_dropped", IXGBE_NETDEV_STAT(rx_dropped)},
78 {"tx_dropped", IXGBE_NETDEV_STAT(tx_dropped)},
79 {"multicast", IXGBE_NETDEV_STAT(multicast)},
Auke Kok9a799d72007-09-15 14:07:45 -070080 {"broadcast", IXGBE_STAT(stats.bprc)},
81 {"rx_no_buffer_count", IXGBE_STAT(stats.rnbc[0]) },
Eric Dumazet55bad822010-07-23 13:44:21 +000082 {"collisions", IXGBE_NETDEV_STAT(collisions)},
83 {"rx_over_errors", IXGBE_NETDEV_STAT(rx_over_errors)},
84 {"rx_crc_errors", IXGBE_NETDEV_STAT(rx_crc_errors)},
85 {"rx_frame_errors", IXGBE_NETDEV_STAT(rx_frame_errors)},
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +000086 {"hw_rsc_aggregated", IXGBE_STAT(rsc_total_count)},
87 {"hw_rsc_flushed", IXGBE_STAT(rsc_total_flush)},
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +000088 {"fdir_match", IXGBE_STAT(stats.fdirmatch)},
89 {"fdir_miss", IXGBE_STAT(stats.fdirmiss)},
Alexander Duyckd034acf2011-04-27 09:25:34 +000090 {"fdir_overflow", IXGBE_STAT(fdir_overflow)},
Eric Dumazet55bad822010-07-23 13:44:21 +000091 {"rx_fifo_errors", IXGBE_NETDEV_STAT(rx_fifo_errors)},
92 {"rx_missed_errors", IXGBE_NETDEV_STAT(rx_missed_errors)},
93 {"tx_aborted_errors", IXGBE_NETDEV_STAT(tx_aborted_errors)},
94 {"tx_carrier_errors", IXGBE_NETDEV_STAT(tx_carrier_errors)},
95 {"tx_fifo_errors", IXGBE_NETDEV_STAT(tx_fifo_errors)},
96 {"tx_heartbeat_errors", IXGBE_NETDEV_STAT(tx_heartbeat_errors)},
Auke Kok9a799d72007-09-15 14:07:45 -070097 {"tx_timeout_count", IXGBE_STAT(tx_timeout_count)},
98 {"tx_restart_queue", IXGBE_STAT(restart_queue)},
99 {"rx_long_length_errors", IXGBE_STAT(stats.roc)},
100 {"rx_short_length_errors", IXGBE_STAT(stats.ruc)},
Auke Kok9a799d72007-09-15 14:07:45 -0700101 {"tx_flow_control_xon", IXGBE_STAT(stats.lxontxc)},
102 {"rx_flow_control_xon", IXGBE_STAT(stats.lxonrxc)},
103 {"tx_flow_control_xoff", IXGBE_STAT(stats.lxofftxc)},
104 {"rx_flow_control_xoff", IXGBE_STAT(stats.lxoffrxc)},
Auke Kok9a799d72007-09-15 14:07:45 -0700105 {"rx_csum_offload_errors", IXGBE_STAT(hw_csum_rx_error)},
Auke Kok9a799d72007-09-15 14:07:45 -0700106 {"alloc_rx_page_failed", IXGBE_STAT(alloc_rx_page_failed)},
107 {"alloc_rx_buff_failed", IXGBE_STAT(alloc_rx_buff_failed)},
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000108 {"rx_no_dma_resources", IXGBE_STAT(hw_rx_no_dma_resources)},
Emil Tantilov58f6bcf2011-04-21 08:43:43 +0000109 {"os2bmc_rx_by_bmc", IXGBE_STAT(stats.o2bgptc)},
110 {"os2bmc_tx_by_bmc", IXGBE_STAT(stats.b2ospc)},
111 {"os2bmc_tx_by_host", IXGBE_STAT(stats.o2bspc)},
112 {"os2bmc_rx_by_host", IXGBE_STAT(stats.b2ogprc)},
Yi Zou6d455222009-05-13 13:12:16 +0000113#ifdef IXGBE_FCOE
114 {"fcoe_bad_fccrc", IXGBE_STAT(stats.fccrc)},
115 {"rx_fcoe_dropped", IXGBE_STAT(stats.fcoerpdc)},
116 {"rx_fcoe_packets", IXGBE_STAT(stats.fcoeprc)},
117 {"rx_fcoe_dwords", IXGBE_STAT(stats.fcoedwrc)},
Amir Hanania7b859eb2011-08-31 02:07:55 +0000118 {"fcoe_noddp", IXGBE_STAT(stats.fcoe_noddp)},
119 {"fcoe_noddp_ext_buff", IXGBE_STAT(stats.fcoe_noddp_ext_buff)},
Yi Zou6d455222009-05-13 13:12:16 +0000120 {"tx_fcoe_packets", IXGBE_STAT(stats.fcoeptc)},
121 {"tx_fcoe_dwords", IXGBE_STAT(stats.fcoedwtc)},
122#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -0700123};
124
John Fastabend9cc00b52012-01-28 03:32:17 +0000125/* ixgbe allocates num_tx_queues and num_rx_queues symmetrically so
126 * we set the num_rx_queues to evaluate to num_tx_queues. This is
127 * used because we do not have a good way to get the max number of
128 * rx queues with CONFIG_RPS disabled.
129 */
130#define IXGBE_NUM_RX_QUEUES netdev->num_tx_queues
131
132#define IXGBE_QUEUE_STATS_LEN ( \
133 (netdev->num_tx_queues + IXGBE_NUM_RX_QUEUES) * \
Wang Chen454d7c92008-11-12 23:37:49 -0800134 (sizeof(struct ixgbe_queue_stats) / sizeof(u64)))
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700135#define IXGBE_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbe_gstrings_stats)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800136#define IXGBE_PB_STATS_LEN ( \
John Fastabend9cc00b52012-01-28 03:32:17 +0000137 (sizeof(((struct ixgbe_adapter *)0)->stats.pxonrxc) + \
138 sizeof(((struct ixgbe_adapter *)0)->stats.pxontxc) + \
139 sizeof(((struct ixgbe_adapter *)0)->stats.pxoffrxc) + \
140 sizeof(((struct ixgbe_adapter *)0)->stats.pxofftxc)) \
141 / sizeof(u64))
Alexander Duyck2f90b862008-11-20 20:52:10 -0800142#define IXGBE_STATS_LEN (IXGBE_GLOBAL_STATS_LEN + \
143 IXGBE_PB_STATS_LEN + \
144 IXGBE_QUEUE_STATS_LEN)
Auke Kok9a799d72007-09-15 14:07:45 -0700145
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +0000146static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = {
147 "Register test (offline)", "Eeprom test (offline)",
148 "Interrupt test (offline)", "Loopback test (offline)",
149 "Link test (on/offline)"
150};
151#define IXGBE_TEST_LEN sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN
152
Auke Kok9a799d72007-09-15 14:07:45 -0700153static int ixgbe_get_settings(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700154 struct ethtool_cmd *ecmd)
Auke Kok9a799d72007-09-15 14:07:45 -0700155{
156 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Ayyappan Veeraiyan735441f2008-02-01 15:58:54 -0800157 struct ixgbe_hw *hw = &adapter->hw;
Jacob Kellerdb018962012-06-08 06:59:17 +0000158 ixgbe_link_speed supported_link;
Ayyappan Veeraiyan735441f2008-02-01 15:58:54 -0800159 u32 link_speed = 0;
Josh Hayfd0326f2012-12-15 03:28:30 +0000160 bool autoneg = false;
Ayyappan Veeraiyan735441f2008-02-01 15:58:54 -0800161 bool link_up;
Auke Kok9a799d72007-09-15 14:07:45 -0700162
Jacob Kellerdb018962012-06-08 06:59:17 +0000163 hw->mac.ops.get_link_capabilities(hw, &supported_link, &autoneg);
Auke Kok9a799d72007-09-15 14:07:45 -0700164
Jacob Kellerdb018962012-06-08 06:59:17 +0000165 /* set the supported link speeds */
166 if (supported_link & IXGBE_LINK_SPEED_10GB_FULL)
167 ecmd->supported |= SUPPORTED_10000baseT_Full;
168 if (supported_link & IXGBE_LINK_SPEED_1GB_FULL)
169 ecmd->supported |= SUPPORTED_1000baseT_Full;
170 if (supported_link & IXGBE_LINK_SPEED_100_FULL)
171 ecmd->supported |= SUPPORTED_100baseT_Full;
Atita Shirwaikar1b1c0a42011-01-05 02:00:55 +0000172
Jacob Kellerdb018962012-06-08 06:59:17 +0000173 /* set the advertised speeds */
174 if (hw->phy.autoneg_advertised) {
175 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
176 ecmd->advertising |= ADVERTISED_100baseT_Full;
177 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
178 ecmd->advertising |= ADVERTISED_10000baseT_Full;
179 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
180 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Ayyappan Veeraiyan735441f2008-02-01 15:58:54 -0800181 } else {
Jacob Kellerdb018962012-06-08 06:59:17 +0000182 /* default modes in case phy.autoneg_advertised isn't set */
183 if (supported_link & IXGBE_LINK_SPEED_10GB_FULL)
184 ecmd->advertising |= ADVERTISED_10000baseT_Full;
185 if (supported_link & IXGBE_LINK_SPEED_1GB_FULL)
186 ecmd->advertising |= ADVERTISED_1000baseT_Full;
187 if (supported_link & IXGBE_LINK_SPEED_100_FULL)
188 ecmd->advertising |= ADVERTISED_100baseT_Full;
Ayyappan Veeraiyan735441f2008-02-01 15:58:54 -0800189 }
190
Jacob Kellerdb018962012-06-08 06:59:17 +0000191 if (autoneg) {
192 ecmd->supported |= SUPPORTED_Autoneg;
193 ecmd->advertising |= ADVERTISED_Autoneg;
194 ecmd->autoneg = AUTONEG_ENABLE;
195 } else
196 ecmd->autoneg = AUTONEG_DISABLE;
197
198 ecmd->transceiver = XCVR_EXTERNAL;
199
200 /* Determine the remaining settings based on the PHY type. */
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000201 switch (adapter->hw.phy.type) {
202 case ixgbe_phy_tn:
Don Skidmorefe15e8e2010-11-16 19:27:16 -0800203 case ixgbe_phy_aq:
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000204 case ixgbe_phy_cu_unknown:
Jacob Kellerdb018962012-06-08 06:59:17 +0000205 ecmd->supported |= SUPPORTED_TP;
206 ecmd->advertising |= ADVERTISED_TP;
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000207 ecmd->port = PORT_TP;
208 break;
209 case ixgbe_phy_qt:
Jacob Kellerdb018962012-06-08 06:59:17 +0000210 ecmd->supported |= SUPPORTED_FIBRE;
211 ecmd->advertising |= ADVERTISED_FIBRE;
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000212 ecmd->port = PORT_FIBRE;
213 break;
214 case ixgbe_phy_nl:
Don Skidmoreea0a04d2010-05-18 16:00:13 +0000215 case ixgbe_phy_sfp_passive_tyco:
216 case ixgbe_phy_sfp_passive_unknown:
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000217 case ixgbe_phy_sfp_ftl:
218 case ixgbe_phy_sfp_avago:
219 case ixgbe_phy_sfp_intel:
220 case ixgbe_phy_sfp_unknown:
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000221 /* SFP+ devices, further checking needed */
Jacob Kellerdb018962012-06-08 06:59:17 +0000222 switch (adapter->hw.phy.sfp_type) {
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000223 case ixgbe_sfp_type_da_cu:
224 case ixgbe_sfp_type_da_cu_core0:
225 case ixgbe_sfp_type_da_cu_core1:
Jacob Kellerdb018962012-06-08 06:59:17 +0000226 ecmd->supported |= SUPPORTED_FIBRE;
227 ecmd->advertising |= ADVERTISED_FIBRE;
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000228 ecmd->port = PORT_DA;
229 break;
230 case ixgbe_sfp_type_sr:
231 case ixgbe_sfp_type_lr:
232 case ixgbe_sfp_type_srlr_core0:
233 case ixgbe_sfp_type_srlr_core1:
Don Skidmore345be202013-04-11 06:23:34 +0000234 case ixgbe_sfp_type_1g_sx_core0:
235 case ixgbe_sfp_type_1g_sx_core1:
236 case ixgbe_sfp_type_1g_lx_core0:
237 case ixgbe_sfp_type_1g_lx_core1:
Jacob Kellerdb018962012-06-08 06:59:17 +0000238 ecmd->supported |= SUPPORTED_FIBRE;
239 ecmd->advertising |= ADVERTISED_FIBRE;
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000240 ecmd->port = PORT_FIBRE;
241 break;
242 case ixgbe_sfp_type_not_present:
Jacob Kellerdb018962012-06-08 06:59:17 +0000243 ecmd->supported |= SUPPORTED_FIBRE;
244 ecmd->advertising |= ADVERTISED_FIBRE;
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000245 ecmd->port = PORT_NONE;
246 break;
Don Skidmorecb836a92010-06-29 18:30:59 +0000247 case ixgbe_sfp_type_1g_cu_core0:
248 case ixgbe_sfp_type_1g_cu_core1:
Jacob Kellerdb018962012-06-08 06:59:17 +0000249 ecmd->supported |= SUPPORTED_TP;
250 ecmd->advertising |= ADVERTISED_TP;
Don Skidmorecb836a92010-06-29 18:30:59 +0000251 ecmd->port = PORT_TP;
Jacob Kellerdb018962012-06-08 06:59:17 +0000252 break;
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000253 case ixgbe_sfp_type_unknown:
254 default:
Jacob Kellerdb018962012-06-08 06:59:17 +0000255 ecmd->supported |= SUPPORTED_FIBRE;
256 ecmd->advertising |= ADVERTISED_FIBRE;
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000257 ecmd->port = PORT_OTHER;
258 break;
259 }
260 break;
261 case ixgbe_phy_xaui:
Jacob Kellerdb018962012-06-08 06:59:17 +0000262 ecmd->supported |= SUPPORTED_FIBRE;
263 ecmd->advertising |= ADVERTISED_FIBRE;
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000264 ecmd->port = PORT_NONE;
265 break;
266 case ixgbe_phy_unknown:
267 case ixgbe_phy_generic:
268 case ixgbe_phy_sfp_unsupported:
269 default:
Jacob Kellerdb018962012-06-08 06:59:17 +0000270 ecmd->supported |= SUPPORTED_FIBRE;
271 ecmd->advertising |= ADVERTISED_FIBRE;
PJ Waskiewicz3b8626b2009-11-25 00:11:54 +0000272 ecmd->port = PORT_OTHER;
273 break;
274 }
275
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700276 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Ayyappan Veeraiyan735441f2008-02-01 15:58:54 -0800277 if (link_up) {
Atita Shirwaikar1b1c0a42011-01-05 02:00:55 +0000278 switch (link_speed) {
279 case IXGBE_LINK_SPEED_10GB_FULL:
David Decotigny70739492011-04-27 18:32:40 +0000280 ethtool_cmd_speed_set(ecmd, SPEED_10000);
Atita Shirwaikar1b1c0a42011-01-05 02:00:55 +0000281 break;
282 case IXGBE_LINK_SPEED_1GB_FULL:
David Decotigny70739492011-04-27 18:32:40 +0000283 ethtool_cmd_speed_set(ecmd, SPEED_1000);
Atita Shirwaikar1b1c0a42011-01-05 02:00:55 +0000284 break;
285 case IXGBE_LINK_SPEED_100_FULL:
David Decotigny70739492011-04-27 18:32:40 +0000286 ethtool_cmd_speed_set(ecmd, SPEED_100);
Atita Shirwaikar1b1c0a42011-01-05 02:00:55 +0000287 break;
288 default:
289 break;
290 }
Auke Kok9a799d72007-09-15 14:07:45 -0700291 ecmd->duplex = DUPLEX_FULL;
292 } else {
David Decotigny70739492011-04-27 18:32:40 +0000293 ethtool_cmd_speed_set(ecmd, -1);
Auke Kok9a799d72007-09-15 14:07:45 -0700294 ecmd->duplex = -1;
295 }
296
Auke Kok9a799d72007-09-15 14:07:45 -0700297 return 0;
298}
299
300static int ixgbe_set_settings(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700301 struct ethtool_cmd *ecmd)
Auke Kok9a799d72007-09-15 14:07:45 -0700302{
303 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Ayyappan Veeraiyan735441f2008-02-01 15:58:54 -0800304 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700305 u32 advertised, old;
Mallikarjuna R Chilakala74766012009-06-04 11:11:34 +0000306 s32 err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700307
Mallikarjuna R Chilakala74766012009-06-04 11:11:34 +0000308 if ((hw->phy.media_type == ixgbe_media_type_copper) ||
Mallikarjuna R Chilakalaa3801372009-06-30 11:44:16 +0000309 (hw->phy.multispeed_fiber)) {
Emil Tantilovabcc80d2011-07-29 06:46:10 +0000310 /*
311 * this function does not support duplex forcing, but can
312 * limit the advertising of the adapter to the specified speed
313 */
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700314 if (ecmd->autoneg == AUTONEG_DISABLE)
315 return -EINVAL;
316
Emil Tantilovabcc80d2011-07-29 06:46:10 +0000317 if (ecmd->advertising & ~ecmd->supported)
318 return -EINVAL;
319
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700320 old = hw->phy.autoneg_advertised;
321 advertised = 0;
322 if (ecmd->advertising & ADVERTISED_10000baseT_Full)
323 advertised |= IXGBE_LINK_SPEED_10GB_FULL;
324
325 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
326 advertised |= IXGBE_LINK_SPEED_1GB_FULL;
327
Emil Tantilov2b642ca2011-03-04 09:06:10 +0000328 if (ecmd->advertising & ADVERTISED_100baseT_Full)
329 advertised |= IXGBE_LINK_SPEED_100_FULL;
330
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700331 if (old == advertised)
Mallikarjuna R Chilakala74766012009-06-04 11:11:34 +0000332 return err;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700333 /* this sets the link speed and restarts auto-neg */
Mallikarjuna R Chilakala74766012009-06-04 11:11:34 +0000334 hw->mac.autotry_restart = true;
Josh Hayfd0326f2012-12-15 03:28:30 +0000335 err = hw->mac.ops.setup_link(hw, advertised, true);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700336 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +0000337 e_info(probe, "setup link failed with code %d\n", err);
Josh Hayfd0326f2012-12-15 03:28:30 +0000338 hw->mac.ops.setup_link(hw, old, true);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700339 }
Mallikarjuna R Chilakala74766012009-06-04 11:11:34 +0000340 } else {
341 /* in this case we currently only support 10Gb/FULL */
David Decotigny25db0332011-04-27 18:32:39 +0000342 u32 speed = ethtool_cmd_speed(ecmd);
Mallikarjuna R Chilakala74766012009-06-04 11:11:34 +0000343 if ((ecmd->autoneg == AUTONEG_ENABLE) ||
Mallikarjuna R Chilakalaa3801372009-06-30 11:44:16 +0000344 (ecmd->advertising != ADVERTISED_10000baseT_Full) ||
David Decotigny25db0332011-04-27 18:32:39 +0000345 (speed + ecmd->duplex != SPEED_10000 + DUPLEX_FULL))
Mallikarjuna R Chilakala74766012009-06-04 11:11:34 +0000346 return -EINVAL;
Auke Kok9a799d72007-09-15 14:07:45 -0700347 }
348
Mallikarjuna R Chilakala74766012009-06-04 11:11:34 +0000349 return err;
Auke Kok9a799d72007-09-15 14:07:45 -0700350}
351
352static void ixgbe_get_pauseparam(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700353 struct ethtool_pauseparam *pause)
Auke Kok9a799d72007-09-15 14:07:45 -0700354{
355 struct ixgbe_adapter *adapter = netdev_priv(netdev);
356 struct ixgbe_hw *hw = &adapter->hw;
357
Don Skidmore73d80953d2013-07-31 02:19:24 +0000358 if (ixgbe_device_supports_autoneg_fc(hw) &&
359 !hw->fc.disable_fc_autoneg)
Don Skidmore71fd5702009-03-31 21:35:05 +0000360 pause->autoneg = 1;
Don Skidmore73d80953d2013-07-31 02:19:24 +0000361 else
362 pause->autoneg = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700363
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -0800364 if (hw->fc.current_mode == ixgbe_fc_rx_pause) {
Auke Kok9a799d72007-09-15 14:07:45 -0700365 pause->rx_pause = 1;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -0800366 } else if (hw->fc.current_mode == ixgbe_fc_tx_pause) {
Auke Kok9a799d72007-09-15 14:07:45 -0700367 pause->tx_pause = 1;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -0800368 } else if (hw->fc.current_mode == ixgbe_fc_full) {
Auke Kok9a799d72007-09-15 14:07:45 -0700369 pause->rx_pause = 1;
370 pause->tx_pause = 1;
371 }
372}
373
374static int ixgbe_set_pauseparam(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700375 struct ethtool_pauseparam *pause)
Auke Kok9a799d72007-09-15 14:07:45 -0700376{
377 struct ixgbe_adapter *adapter = netdev_priv(netdev);
378 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck943561d2012-05-09 22:14:44 -0700379 struct ixgbe_fc_info fc = hw->fc;
Auke Kok9a799d72007-09-15 14:07:45 -0700380
Alexander Duyck943561d2012-05-09 22:14:44 -0700381 /* 82598 does no support link flow control with DCB enabled */
382 if ((hw->mac.type == ixgbe_mac_82598EB) &&
383 (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +0000384 return -EINVAL;
385
Jacob Kellerdb2adc22012-10-24 07:26:02 +0000386 /* some devices do not support autoneg of link flow control */
387 if ((pause->autoneg == AUTONEG_ENABLE) &&
Don Skidmore73d80953d2013-07-31 02:19:24 +0000388 !ixgbe_device_supports_autoneg_fc(hw))
Jacob Kellerdb2adc22012-10-24 07:26:02 +0000389 return -EINVAL;
390
Alexander Duyck943561d2012-05-09 22:14:44 -0700391 fc.disable_fc_autoneg = (pause->autoneg != AUTONEG_ENABLE);
Don Skidmore71fd5702009-03-31 21:35:05 +0000392
Don Skidmore1c4f0ef2010-04-27 11:31:06 +0000393 if ((pause->rx_pause && pause->tx_pause) || pause->autoneg)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +0000394 fc.requested_mode = ixgbe_fc_full;
Auke Kok9a799d72007-09-15 14:07:45 -0700395 else if (pause->rx_pause && !pause->tx_pause)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +0000396 fc.requested_mode = ixgbe_fc_rx_pause;
Auke Kok9a799d72007-09-15 14:07:45 -0700397 else if (!pause->rx_pause && pause->tx_pause)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +0000398 fc.requested_mode = ixgbe_fc_tx_pause;
Ayyappan Veeraiyan9c83b0702008-02-01 15:58:59 -0800399 else
Alexander Duyck943561d2012-05-09 22:14:44 -0700400 fc.requested_mode = ixgbe_fc_none;
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +0000401
402 /* if the thing changed then we'll update and use new autoneg */
403 if (memcmp(&fc, &hw->fc, sizeof(struct ixgbe_fc_info))) {
404 hw->fc = fc;
405 if (netif_running(netdev))
406 ixgbe_reinit_locked(adapter);
407 else
408 ixgbe_reset(adapter);
409 }
Auke Kok9a799d72007-09-15 14:07:45 -0700410
411 return 0;
412}
413
Auke Kok9a799d72007-09-15 14:07:45 -0700414static u32 ixgbe_get_msglevel(struct net_device *netdev)
415{
416 struct ixgbe_adapter *adapter = netdev_priv(netdev);
417 return adapter->msg_enable;
418}
419
420static void ixgbe_set_msglevel(struct net_device *netdev, u32 data)
421{
422 struct ixgbe_adapter *adapter = netdev_priv(netdev);
423 adapter->msg_enable = data;
424}
425
426static int ixgbe_get_regs_len(struct net_device *netdev)
427{
Emil Tantilov217995e2011-09-15 06:23:10 +0000428#define IXGBE_REGS_LEN 1129
Auke Kok9a799d72007-09-15 14:07:45 -0700429 return IXGBE_REGS_LEN * sizeof(u32);
430}
431
432#define IXGBE_GET_STAT(_A_, _R_) _A_->stats._R_
433
434static void ixgbe_get_regs(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700435 struct ethtool_regs *regs, void *p)
Auke Kok9a799d72007-09-15 14:07:45 -0700436{
437 struct ixgbe_adapter *adapter = netdev_priv(netdev);
438 struct ixgbe_hw *hw = &adapter->hw;
439 u32 *regs_buff = p;
440 u8 i;
441
442 memset(p, 0, IXGBE_REGS_LEN * sizeof(u32));
443
Emil Tantilovc4a56de2013-04-19 09:31:17 +0000444 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
445 hw->device_id;
Auke Kok9a799d72007-09-15 14:07:45 -0700446
447 /* General Registers */
448 regs_buff[0] = IXGBE_READ_REG(hw, IXGBE_CTRL);
449 regs_buff[1] = IXGBE_READ_REG(hw, IXGBE_STATUS);
450 regs_buff[2] = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
451 regs_buff[3] = IXGBE_READ_REG(hw, IXGBE_ESDP);
452 regs_buff[4] = IXGBE_READ_REG(hw, IXGBE_EODSDP);
453 regs_buff[5] = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
454 regs_buff[6] = IXGBE_READ_REG(hw, IXGBE_FRTIMER);
455 regs_buff[7] = IXGBE_READ_REG(hw, IXGBE_TCPTIMER);
456
457 /* NVM Register */
458 regs_buff[8] = IXGBE_READ_REG(hw, IXGBE_EEC);
459 regs_buff[9] = IXGBE_READ_REG(hw, IXGBE_EERD);
460 regs_buff[10] = IXGBE_READ_REG(hw, IXGBE_FLA);
461 regs_buff[11] = IXGBE_READ_REG(hw, IXGBE_EEMNGCTL);
462 regs_buff[12] = IXGBE_READ_REG(hw, IXGBE_EEMNGDATA);
463 regs_buff[13] = IXGBE_READ_REG(hw, IXGBE_FLMNGCTL);
464 regs_buff[14] = IXGBE_READ_REG(hw, IXGBE_FLMNGDATA);
465 regs_buff[15] = IXGBE_READ_REG(hw, IXGBE_FLMNGCNT);
466 regs_buff[16] = IXGBE_READ_REG(hw, IXGBE_FLOP);
467 regs_buff[17] = IXGBE_READ_REG(hw, IXGBE_GRC);
468
469 /* Interrupt */
Jesse Brandeburg98c00a12008-09-11 19:56:41 -0700470 /* don't read EICR because it can clear interrupt causes, instead
471 * read EICS which is a shadow but doesn't clear EICR */
472 regs_buff[18] = IXGBE_READ_REG(hw, IXGBE_EICS);
Auke Kok9a799d72007-09-15 14:07:45 -0700473 regs_buff[19] = IXGBE_READ_REG(hw, IXGBE_EICS);
474 regs_buff[20] = IXGBE_READ_REG(hw, IXGBE_EIMS);
475 regs_buff[21] = IXGBE_READ_REG(hw, IXGBE_EIMC);
476 regs_buff[22] = IXGBE_READ_REG(hw, IXGBE_EIAC);
477 regs_buff[23] = IXGBE_READ_REG(hw, IXGBE_EIAM);
478 regs_buff[24] = IXGBE_READ_REG(hw, IXGBE_EITR(0));
479 regs_buff[25] = IXGBE_READ_REG(hw, IXGBE_IVAR(0));
480 regs_buff[26] = IXGBE_READ_REG(hw, IXGBE_MSIXT);
481 regs_buff[27] = IXGBE_READ_REG(hw, IXGBE_MSIXPBA);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700482 regs_buff[28] = IXGBE_READ_REG(hw, IXGBE_PBACL(0));
Auke Kok9a799d72007-09-15 14:07:45 -0700483 regs_buff[29] = IXGBE_READ_REG(hw, IXGBE_GPIE);
484
485 /* Flow Control */
486 regs_buff[30] = IXGBE_READ_REG(hw, IXGBE_PFCTOP);
487 regs_buff[31] = IXGBE_READ_REG(hw, IXGBE_FCTTV(0));
488 regs_buff[32] = IXGBE_READ_REG(hw, IXGBE_FCTTV(1));
489 regs_buff[33] = IXGBE_READ_REG(hw, IXGBE_FCTTV(2));
490 regs_buff[34] = IXGBE_READ_REG(hw, IXGBE_FCTTV(3));
Alexander Duyckbd508172010-11-16 19:27:03 -0800491 for (i = 0; i < 8; i++) {
492 switch (hw->mac.type) {
493 case ixgbe_mac_82598EB:
494 regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTL(i));
495 regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTH(i));
496 break;
497 case ixgbe_mac_82599EB:
Emil Tantilov80bb25e2011-07-27 04:16:29 +0000498 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -0800499 regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTL_82599(i));
500 regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
501 break;
502 default:
503 break;
504 }
505 }
Auke Kok9a799d72007-09-15 14:07:45 -0700506 regs_buff[51] = IXGBE_READ_REG(hw, IXGBE_FCRTV);
507 regs_buff[52] = IXGBE_READ_REG(hw, IXGBE_TFCS);
508
509 /* Receive DMA */
510 for (i = 0; i < 64; i++)
511 regs_buff[53 + i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
512 for (i = 0; i < 64; i++)
513 regs_buff[117 + i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
514 for (i = 0; i < 64; i++)
515 regs_buff[181 + i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
516 for (i = 0; i < 64; i++)
517 regs_buff[245 + i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
518 for (i = 0; i < 64; i++)
519 regs_buff[309 + i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
520 for (i = 0; i < 64; i++)
521 regs_buff[373 + i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
522 for (i = 0; i < 16; i++)
523 regs_buff[437 + i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
524 for (i = 0; i < 16; i++)
525 regs_buff[453 + i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
526 regs_buff[469] = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
527 for (i = 0; i < 8; i++)
528 regs_buff[470 + i] = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i));
529 regs_buff[478] = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
530 regs_buff[479] = IXGBE_READ_REG(hw, IXGBE_DROPEN);
531
532 /* Receive */
533 regs_buff[480] = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
534 regs_buff[481] = IXGBE_READ_REG(hw, IXGBE_RFCTL);
535 for (i = 0; i < 16; i++)
536 regs_buff[482 + i] = IXGBE_READ_REG(hw, IXGBE_RAL(i));
537 for (i = 0; i < 16; i++)
538 regs_buff[498 + i] = IXGBE_READ_REG(hw, IXGBE_RAH(i));
Jesse Brandeburgc44ade92008-09-11 19:59:59 -0700539 regs_buff[514] = IXGBE_READ_REG(hw, IXGBE_PSRTYPE(0));
Auke Kok9a799d72007-09-15 14:07:45 -0700540 regs_buff[515] = IXGBE_READ_REG(hw, IXGBE_FCTRL);
541 regs_buff[516] = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
542 regs_buff[517] = IXGBE_READ_REG(hw, IXGBE_MCSTCTRL);
543 regs_buff[518] = IXGBE_READ_REG(hw, IXGBE_MRQC);
544 regs_buff[519] = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
545 for (i = 0; i < 8; i++)
546 regs_buff[520 + i] = IXGBE_READ_REG(hw, IXGBE_IMIR(i));
547 for (i = 0; i < 8; i++)
548 regs_buff[528 + i] = IXGBE_READ_REG(hw, IXGBE_IMIREXT(i));
549 regs_buff[536] = IXGBE_READ_REG(hw, IXGBE_IMIRVP);
550
551 /* Transmit */
552 for (i = 0; i < 32; i++)
553 regs_buff[537 + i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
554 for (i = 0; i < 32; i++)
555 regs_buff[569 + i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
556 for (i = 0; i < 32; i++)
557 regs_buff[601 + i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
558 for (i = 0; i < 32; i++)
559 regs_buff[633 + i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
560 for (i = 0; i < 32; i++)
561 regs_buff[665 + i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
562 for (i = 0; i < 32; i++)
563 regs_buff[697 + i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
564 for (i = 0; i < 32; i++)
565 regs_buff[729 + i] = IXGBE_READ_REG(hw, IXGBE_TDWBAL(i));
566 for (i = 0; i < 32; i++)
567 regs_buff[761 + i] = IXGBE_READ_REG(hw, IXGBE_TDWBAH(i));
568 regs_buff[793] = IXGBE_READ_REG(hw, IXGBE_DTXCTL);
569 for (i = 0; i < 16; i++)
570 regs_buff[794 + i] = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
571 regs_buff[810] = IXGBE_READ_REG(hw, IXGBE_TIPG);
572 for (i = 0; i < 8; i++)
573 regs_buff[811 + i] = IXGBE_READ_REG(hw, IXGBE_TXPBSIZE(i));
574 regs_buff[819] = IXGBE_READ_REG(hw, IXGBE_MNGTXMAP);
575
576 /* Wake Up */
577 regs_buff[820] = IXGBE_READ_REG(hw, IXGBE_WUC);
578 regs_buff[821] = IXGBE_READ_REG(hw, IXGBE_WUFC);
579 regs_buff[822] = IXGBE_READ_REG(hw, IXGBE_WUS);
580 regs_buff[823] = IXGBE_READ_REG(hw, IXGBE_IPAV);
581 regs_buff[824] = IXGBE_READ_REG(hw, IXGBE_IP4AT);
582 regs_buff[825] = IXGBE_READ_REG(hw, IXGBE_IP6AT);
583 regs_buff[826] = IXGBE_READ_REG(hw, IXGBE_WUPL);
584 regs_buff[827] = IXGBE_READ_REG(hw, IXGBE_WUPM);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000585 regs_buff[828] = IXGBE_READ_REG(hw, IXGBE_FHFT(0));
Auke Kok9a799d72007-09-15 14:07:45 -0700586
Alexander Duyck673ac602010-11-16 19:27:05 -0800587 /* DCB */
Auke Kok9a799d72007-09-15 14:07:45 -0700588 regs_buff[829] = IXGBE_READ_REG(hw, IXGBE_RMCS);
589 regs_buff[830] = IXGBE_READ_REG(hw, IXGBE_DPMCS);
590 regs_buff[831] = IXGBE_READ_REG(hw, IXGBE_PDPMCS);
591 regs_buff[832] = IXGBE_READ_REG(hw, IXGBE_RUPPBMR);
592 for (i = 0; i < 8; i++)
593 regs_buff[833 + i] = IXGBE_READ_REG(hw, IXGBE_RT2CR(i));
594 for (i = 0; i < 8; i++)
595 regs_buff[841 + i] = IXGBE_READ_REG(hw, IXGBE_RT2SR(i));
596 for (i = 0; i < 8; i++)
597 regs_buff[849 + i] = IXGBE_READ_REG(hw, IXGBE_TDTQ2TCCR(i));
598 for (i = 0; i < 8; i++)
599 regs_buff[857 + i] = IXGBE_READ_REG(hw, IXGBE_TDTQ2TCSR(i));
600 for (i = 0; i < 8; i++)
601 regs_buff[865 + i] = IXGBE_READ_REG(hw, IXGBE_TDPT2TCCR(i));
602 for (i = 0; i < 8; i++)
603 regs_buff[873 + i] = IXGBE_READ_REG(hw, IXGBE_TDPT2TCSR(i));
604
605 /* Statistics */
606 regs_buff[881] = IXGBE_GET_STAT(adapter, crcerrs);
607 regs_buff[882] = IXGBE_GET_STAT(adapter, illerrc);
608 regs_buff[883] = IXGBE_GET_STAT(adapter, errbc);
609 regs_buff[884] = IXGBE_GET_STAT(adapter, mspdc);
610 for (i = 0; i < 8; i++)
611 regs_buff[885 + i] = IXGBE_GET_STAT(adapter, mpc[i]);
612 regs_buff[893] = IXGBE_GET_STAT(adapter, mlfc);
613 regs_buff[894] = IXGBE_GET_STAT(adapter, mrfc);
614 regs_buff[895] = IXGBE_GET_STAT(adapter, rlec);
615 regs_buff[896] = IXGBE_GET_STAT(adapter, lxontxc);
616 regs_buff[897] = IXGBE_GET_STAT(adapter, lxonrxc);
617 regs_buff[898] = IXGBE_GET_STAT(adapter, lxofftxc);
618 regs_buff[899] = IXGBE_GET_STAT(adapter, lxoffrxc);
619 for (i = 0; i < 8; i++)
620 regs_buff[900 + i] = IXGBE_GET_STAT(adapter, pxontxc[i]);
621 for (i = 0; i < 8; i++)
622 regs_buff[908 + i] = IXGBE_GET_STAT(adapter, pxonrxc[i]);
623 for (i = 0; i < 8; i++)
624 regs_buff[916 + i] = IXGBE_GET_STAT(adapter, pxofftxc[i]);
625 for (i = 0; i < 8; i++)
626 regs_buff[924 + i] = IXGBE_GET_STAT(adapter, pxoffrxc[i]);
627 regs_buff[932] = IXGBE_GET_STAT(adapter, prc64);
628 regs_buff[933] = IXGBE_GET_STAT(adapter, prc127);
629 regs_buff[934] = IXGBE_GET_STAT(adapter, prc255);
630 regs_buff[935] = IXGBE_GET_STAT(adapter, prc511);
631 regs_buff[936] = IXGBE_GET_STAT(adapter, prc1023);
632 regs_buff[937] = IXGBE_GET_STAT(adapter, prc1522);
633 regs_buff[938] = IXGBE_GET_STAT(adapter, gprc);
634 regs_buff[939] = IXGBE_GET_STAT(adapter, bprc);
635 regs_buff[940] = IXGBE_GET_STAT(adapter, mprc);
636 regs_buff[941] = IXGBE_GET_STAT(adapter, gptc);
637 regs_buff[942] = IXGBE_GET_STAT(adapter, gorc);
638 regs_buff[944] = IXGBE_GET_STAT(adapter, gotc);
639 for (i = 0; i < 8; i++)
640 regs_buff[946 + i] = IXGBE_GET_STAT(adapter, rnbc[i]);
641 regs_buff[954] = IXGBE_GET_STAT(adapter, ruc);
642 regs_buff[955] = IXGBE_GET_STAT(adapter, rfc);
643 regs_buff[956] = IXGBE_GET_STAT(adapter, roc);
644 regs_buff[957] = IXGBE_GET_STAT(adapter, rjc);
645 regs_buff[958] = IXGBE_GET_STAT(adapter, mngprc);
646 regs_buff[959] = IXGBE_GET_STAT(adapter, mngpdc);
647 regs_buff[960] = IXGBE_GET_STAT(adapter, mngptc);
648 regs_buff[961] = IXGBE_GET_STAT(adapter, tor);
649 regs_buff[963] = IXGBE_GET_STAT(adapter, tpr);
650 regs_buff[964] = IXGBE_GET_STAT(adapter, tpt);
651 regs_buff[965] = IXGBE_GET_STAT(adapter, ptc64);
652 regs_buff[966] = IXGBE_GET_STAT(adapter, ptc127);
653 regs_buff[967] = IXGBE_GET_STAT(adapter, ptc255);
654 regs_buff[968] = IXGBE_GET_STAT(adapter, ptc511);
655 regs_buff[969] = IXGBE_GET_STAT(adapter, ptc1023);
656 regs_buff[970] = IXGBE_GET_STAT(adapter, ptc1522);
657 regs_buff[971] = IXGBE_GET_STAT(adapter, mptc);
658 regs_buff[972] = IXGBE_GET_STAT(adapter, bptc);
659 regs_buff[973] = IXGBE_GET_STAT(adapter, xec);
660 for (i = 0; i < 16; i++)
661 regs_buff[974 + i] = IXGBE_GET_STAT(adapter, qprc[i]);
662 for (i = 0; i < 16; i++)
663 regs_buff[990 + i] = IXGBE_GET_STAT(adapter, qptc[i]);
664 for (i = 0; i < 16; i++)
665 regs_buff[1006 + i] = IXGBE_GET_STAT(adapter, qbrc[i]);
666 for (i = 0; i < 16; i++)
667 regs_buff[1022 + i] = IXGBE_GET_STAT(adapter, qbtc[i]);
668
669 /* MAC */
670 regs_buff[1038] = IXGBE_READ_REG(hw, IXGBE_PCS1GCFIG);
671 regs_buff[1039] = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
672 regs_buff[1040] = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
673 regs_buff[1041] = IXGBE_READ_REG(hw, IXGBE_PCS1GDBG0);
674 regs_buff[1042] = IXGBE_READ_REG(hw, IXGBE_PCS1GDBG1);
675 regs_buff[1043] = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
676 regs_buff[1044] = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
677 regs_buff[1045] = IXGBE_READ_REG(hw, IXGBE_PCS1GANNP);
678 regs_buff[1046] = IXGBE_READ_REG(hw, IXGBE_PCS1GANLPNP);
679 regs_buff[1047] = IXGBE_READ_REG(hw, IXGBE_HLREG0);
680 regs_buff[1048] = IXGBE_READ_REG(hw, IXGBE_HLREG1);
681 regs_buff[1049] = IXGBE_READ_REG(hw, IXGBE_PAP);
682 regs_buff[1050] = IXGBE_READ_REG(hw, IXGBE_MACA);
683 regs_buff[1051] = IXGBE_READ_REG(hw, IXGBE_APAE);
684 regs_buff[1052] = IXGBE_READ_REG(hw, IXGBE_ARD);
685 regs_buff[1053] = IXGBE_READ_REG(hw, IXGBE_AIS);
686 regs_buff[1054] = IXGBE_READ_REG(hw, IXGBE_MSCA);
687 regs_buff[1055] = IXGBE_READ_REG(hw, IXGBE_MSRWD);
688 regs_buff[1056] = IXGBE_READ_REG(hw, IXGBE_MLADD);
689 regs_buff[1057] = IXGBE_READ_REG(hw, IXGBE_MHADD);
690 regs_buff[1058] = IXGBE_READ_REG(hw, IXGBE_TREG);
691 regs_buff[1059] = IXGBE_READ_REG(hw, IXGBE_PCSS1);
692 regs_buff[1060] = IXGBE_READ_REG(hw, IXGBE_PCSS2);
693 regs_buff[1061] = IXGBE_READ_REG(hw, IXGBE_XPCSS);
694 regs_buff[1062] = IXGBE_READ_REG(hw, IXGBE_SERDESC);
695 regs_buff[1063] = IXGBE_READ_REG(hw, IXGBE_MACS);
696 regs_buff[1064] = IXGBE_READ_REG(hw, IXGBE_AUTOC);
697 regs_buff[1065] = IXGBE_READ_REG(hw, IXGBE_LINKS);
698 regs_buff[1066] = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
699 regs_buff[1067] = IXGBE_READ_REG(hw, IXGBE_AUTOC3);
700 regs_buff[1068] = IXGBE_READ_REG(hw, IXGBE_ANLP1);
701 regs_buff[1069] = IXGBE_READ_REG(hw, IXGBE_ANLP2);
702 regs_buff[1070] = IXGBE_READ_REG(hw, IXGBE_ATLASCTL);
703
704 /* Diagnostic */
705 regs_buff[1071] = IXGBE_READ_REG(hw, IXGBE_RDSTATCTL);
706 for (i = 0; i < 8; i++)
Jesse Brandeburg98c00a12008-09-11 19:56:41 -0700707 regs_buff[1072 + i] = IXGBE_READ_REG(hw, IXGBE_RDSTAT(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700708 regs_buff[1080] = IXGBE_READ_REG(hw, IXGBE_RDHMPN);
Jesse Brandeburg98c00a12008-09-11 19:56:41 -0700709 for (i = 0; i < 4; i++)
710 regs_buff[1081 + i] = IXGBE_READ_REG(hw, IXGBE_RIC_DW(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700711 regs_buff[1085] = IXGBE_READ_REG(hw, IXGBE_RDPROBE);
712 regs_buff[1086] = IXGBE_READ_REG(hw, IXGBE_TDSTATCTL);
713 for (i = 0; i < 8; i++)
Jesse Brandeburg98c00a12008-09-11 19:56:41 -0700714 regs_buff[1087 + i] = IXGBE_READ_REG(hw, IXGBE_TDSTAT(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700715 regs_buff[1095] = IXGBE_READ_REG(hw, IXGBE_TDHMPN);
Jesse Brandeburg98c00a12008-09-11 19:56:41 -0700716 for (i = 0; i < 4; i++)
717 regs_buff[1096 + i] = IXGBE_READ_REG(hw, IXGBE_TIC_DW(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700718 regs_buff[1100] = IXGBE_READ_REG(hw, IXGBE_TDPROBE);
719 regs_buff[1101] = IXGBE_READ_REG(hw, IXGBE_TXBUFCTRL);
720 regs_buff[1102] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA0);
721 regs_buff[1103] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA1);
722 regs_buff[1104] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA2);
723 regs_buff[1105] = IXGBE_READ_REG(hw, IXGBE_TXBUFDATA3);
724 regs_buff[1106] = IXGBE_READ_REG(hw, IXGBE_RXBUFCTRL);
725 regs_buff[1107] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA0);
726 regs_buff[1108] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA1);
727 regs_buff[1109] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA2);
728 regs_buff[1110] = IXGBE_READ_REG(hw, IXGBE_RXBUFDATA3);
729 for (i = 0; i < 8; i++)
Jesse Brandeburg98c00a12008-09-11 19:56:41 -0700730 regs_buff[1111 + i] = IXGBE_READ_REG(hw, IXGBE_PCIE_DIAG(i));
Auke Kok9a799d72007-09-15 14:07:45 -0700731 regs_buff[1119] = IXGBE_READ_REG(hw, IXGBE_RFVAL);
732 regs_buff[1120] = IXGBE_READ_REG(hw, IXGBE_MDFTC1);
733 regs_buff[1121] = IXGBE_READ_REG(hw, IXGBE_MDFTC2);
734 regs_buff[1122] = IXGBE_READ_REG(hw, IXGBE_MDFTFIFO1);
735 regs_buff[1123] = IXGBE_READ_REG(hw, IXGBE_MDFTFIFO2);
736 regs_buff[1124] = IXGBE_READ_REG(hw, IXGBE_MDFTS);
737 regs_buff[1125] = IXGBE_READ_REG(hw, IXGBE_PCIEECCCTL);
738 regs_buff[1126] = IXGBE_READ_REG(hw, IXGBE_PBTXECC);
739 regs_buff[1127] = IXGBE_READ_REG(hw, IXGBE_PBRXECC);
Emil Tantilov217995e2011-09-15 06:23:10 +0000740
741 /* 82599 X540 specific registers */
742 regs_buff[1128] = IXGBE_READ_REG(hw, IXGBE_MFLCN);
Auke Kok9a799d72007-09-15 14:07:45 -0700743}
744
745static int ixgbe_get_eeprom_len(struct net_device *netdev)
746{
747 struct ixgbe_adapter *adapter = netdev_priv(netdev);
748 return adapter->hw.eeprom.word_size * 2;
749}
750
751static int ixgbe_get_eeprom(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700752 struct ethtool_eeprom *eeprom, u8 *bytes)
Auke Kok9a799d72007-09-15 14:07:45 -0700753{
754 struct ixgbe_adapter *adapter = netdev_priv(netdev);
755 struct ixgbe_hw *hw = &adapter->hw;
756 u16 *eeprom_buff;
757 int first_word, last_word, eeprom_len;
758 int ret_val = 0;
759 u16 i;
760
761 if (eeprom->len == 0)
762 return -EINVAL;
763
764 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
765
766 first_word = eeprom->offset >> 1;
767 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
768 eeprom_len = last_word - first_word + 1;
769
770 eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL);
771 if (!eeprom_buff)
772 return -ENOMEM;
773
Emil Tantilov68c70052011-04-20 08:49:06 +0000774 ret_val = hw->eeprom.ops.read_buffer(hw, first_word, eeprom_len,
775 eeprom_buff);
Auke Kok9a799d72007-09-15 14:07:45 -0700776
777 /* Device's eeprom is always little-endian, word addressable */
778 for (i = 0; i < eeprom_len; i++)
779 le16_to_cpus(&eeprom_buff[i]);
780
781 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
782 kfree(eeprom_buff);
783
784 return ret_val;
785}
786
Emil Tantilov2fa5eef2011-10-06 08:57:04 +0000787static int ixgbe_set_eeprom(struct net_device *netdev,
788 struct ethtool_eeprom *eeprom, u8 *bytes)
789{
790 struct ixgbe_adapter *adapter = netdev_priv(netdev);
791 struct ixgbe_hw *hw = &adapter->hw;
792 u16 *eeprom_buff;
793 void *ptr;
794 int max_len, first_word, last_word, ret_val = 0;
795 u16 i;
796
797 if (eeprom->len == 0)
798 return -EINVAL;
799
800 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
801 return -EINVAL;
802
803 max_len = hw->eeprom.word_size * 2;
804
805 first_word = eeprom->offset >> 1;
806 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
807 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
808 if (!eeprom_buff)
809 return -ENOMEM;
810
811 ptr = eeprom_buff;
812
813 if (eeprom->offset & 1) {
814 /*
815 * need read/modify/write of first changed EEPROM word
816 * only the second byte of the word is being modified
817 */
818 ret_val = hw->eeprom.ops.read(hw, first_word, &eeprom_buff[0]);
819 if (ret_val)
820 goto err;
821
822 ptr++;
823 }
824 if ((eeprom->offset + eeprom->len) & 1) {
825 /*
826 * need read/modify/write of last changed EEPROM word
827 * only the first byte of the word is being modified
828 */
829 ret_val = hw->eeprom.ops.read(hw, last_word,
830 &eeprom_buff[last_word - first_word]);
831 if (ret_val)
832 goto err;
833 }
834
835 /* Device's eeprom is always little-endian, word addressable */
836 for (i = 0; i < last_word - first_word + 1; i++)
837 le16_to_cpus(&eeprom_buff[i]);
838
839 memcpy(ptr, bytes, eeprom->len);
840
841 for (i = 0; i < last_word - first_word + 1; i++)
842 cpu_to_le16s(&eeprom_buff[i]);
843
844 ret_val = hw->eeprom.ops.write_buffer(hw, first_word,
845 last_word - first_word + 1,
846 eeprom_buff);
847
848 /* Update the checksum */
849 if (ret_val == 0)
850 hw->eeprom.ops.update_checksum(hw);
851
852err:
853 kfree(eeprom_buff);
854 return ret_val;
855}
856
Auke Kok9a799d72007-09-15 14:07:45 -0700857static void ixgbe_get_drvinfo(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700858 struct ethtool_drvinfo *drvinfo)
Auke Kok9a799d72007-09-15 14:07:45 -0700859{
860 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Emil Tantilov15e52092011-09-29 05:01:29 +0000861 u32 nvm_track_id;
Auke Kok9a799d72007-09-15 14:07:45 -0700862
Rick Jones612a94d2011-11-14 08:13:25 +0000863 strlcpy(drvinfo->driver, ixgbe_driver_name, sizeof(drvinfo->driver));
864 strlcpy(drvinfo->version, ixgbe_driver_version,
865 sizeof(drvinfo->version));
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -0800866
Emil Tantilov15e52092011-09-29 05:01:29 +0000867 nvm_track_id = (adapter->eeprom_verh << 16) |
868 adapter->eeprom_verl;
Rick Jones612a94d2011-11-14 08:13:25 +0000869 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "0x%08x",
Emil Tantilov15e52092011-09-29 05:01:29 +0000870 nvm_track_id);
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -0800871
Rick Jones612a94d2011-11-14 08:13:25 +0000872 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
873 sizeof(drvinfo->bus_info));
Auke Kok9a799d72007-09-15 14:07:45 -0700874 drvinfo->n_stats = IXGBE_STATS_LEN;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +0000875 drvinfo->testinfo_len = IXGBE_TEST_LEN;
Auke Kok9a799d72007-09-15 14:07:45 -0700876 drvinfo->regdump_len = ixgbe_get_regs_len(netdev);
877}
878
879static void ixgbe_get_ringparam(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700880 struct ethtool_ringparam *ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700881{
882 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +0000883 struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
884 struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
Auke Kok9a799d72007-09-15 14:07:45 -0700885
886 ring->rx_max_pending = IXGBE_MAX_RXD;
887 ring->tx_max_pending = IXGBE_MAX_TXD;
Auke Kok9a799d72007-09-15 14:07:45 -0700888 ring->rx_pending = rx_ring->count;
889 ring->tx_pending = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700890}
891
892static int ixgbe_set_ringparam(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700893 struct ethtool_ringparam *ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700894{
895 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000896 struct ixgbe_ring *temp_ring;
Alexander Duyck759884b2009-10-26 11:32:05 +0000897 int i, err = 0;
Jesse Brandeburgc431f972008-09-11 19:59:16 -0700898 u32 new_rx_count, new_tx_count;
Auke Kok9a799d72007-09-15 14:07:45 -0700899
900 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
901 return -EINVAL;
902
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000903 new_tx_count = clamp_t(u32, ring->tx_pending,
904 IXGBE_MIN_TXD, IXGBE_MAX_TXD);
Auke Kok9a799d72007-09-15 14:07:45 -0700905 new_tx_count = ALIGN(new_tx_count, IXGBE_REQ_TX_DESCRIPTOR_MULTIPLE);
906
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000907 new_rx_count = clamp_t(u32, ring->rx_pending,
908 IXGBE_MIN_RXD, IXGBE_MAX_RXD);
909 new_rx_count = ALIGN(new_rx_count, IXGBE_REQ_RX_DESCRIPTOR_MULTIPLE);
910
911 if ((new_tx_count == adapter->tx_ring_count) &&
912 (new_rx_count == adapter->rx_ring_count)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700913 /* nothing to do */
914 return 0;
915 }
916
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -0800917 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +0000918 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -0800919
Alexander Duyck759884b2009-10-26 11:32:05 +0000920 if (!netif_running(adapter->netdev)) {
921 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +0000922 adapter->tx_ring[i]->count = new_tx_count;
Alexander Duyck759884b2009-10-26 11:32:05 +0000923 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +0000924 adapter->rx_ring[i]->count = new_rx_count;
Alexander Duyck759884b2009-10-26 11:32:05 +0000925 adapter->tx_ring_count = new_tx_count;
926 adapter->rx_ring_count = new_rx_count;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +0000927 goto clear_reset;
Alexander Duyck759884b2009-10-26 11:32:05 +0000928 }
929
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000930 /* allocate temporary buffer to store rings in */
931 i = max_t(int, adapter->num_tx_queues, adapter->num_rx_queues);
932 temp_ring = vmalloc(i * sizeof(struct ixgbe_ring));
933
934 if (!temp_ring) {
Mallikarjuna R Chilakalaf9ed8852009-03-31 21:35:24 +0000935 err = -ENOMEM;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +0000936 goto clear_reset;
Mallikarjuna R Chilakalaf9ed8852009-03-31 21:35:24 +0000937 }
938
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000939 ixgbe_down(adapter);
940
941 /*
942 * Setup new Tx resources and free the old Tx resources in that order.
943 * We can then assign the new resources to the rings via a memcpy.
944 * The advantage to this approach is that we are guaranteed to still
945 * have resources even in the case of an allocation failure.
946 */
Mallikarjuna R Chilakalaf9ed8852009-03-31 21:35:24 +0000947 if (new_tx_count != adapter->tx_ring_count) {
Auke Kok9a799d72007-09-15 14:07:45 -0700948 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000949 memcpy(&temp_ring[i], adapter->tx_ring[i],
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +0000950 sizeof(struct ixgbe_ring));
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000951
952 temp_ring[i].count = new_tx_count;
953 err = ixgbe_setup_tx_resources(&temp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -0700954 if (err) {
Jesse Brandeburgc431f972008-09-11 19:59:16 -0700955 while (i) {
956 i--;
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000957 ixgbe_free_tx_resources(&temp_ring[i]);
Jesse Brandeburgc431f972008-09-11 19:59:16 -0700958 }
Auke Kok9a799d72007-09-15 14:07:45 -0700959 goto err_setup;
960 }
Auke Kok9a799d72007-09-15 14:07:45 -0700961 }
Jesse Brandeburgc431f972008-09-11 19:59:16 -0700962
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000963 for (i = 0; i < adapter->num_tx_queues; i++) {
964 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Mallikarjuna R Chilakalaf9ed8852009-03-31 21:35:24 +0000965
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000966 memcpy(adapter->tx_ring[i], &temp_ring[i],
967 sizeof(struct ixgbe_ring));
Mallikarjuna R Chilakalaf9ed8852009-03-31 21:35:24 +0000968 }
969
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000970 adapter->tx_ring_count = new_tx_count;
Alexander Duyck759884b2009-10-26 11:32:05 +0000971 }
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +0000972
Alexander Duyck1f4702a2012-09-12 07:09:51 +0000973 /* Repeat the process for the Rx rings if needed */
974 if (new_rx_count != adapter->rx_ring_count) {
975 for (i = 0; i < adapter->num_rx_queues; i++) {
976 memcpy(&temp_ring[i], adapter->rx_ring[i],
977 sizeof(struct ixgbe_ring));
978
979 temp_ring[i].count = new_rx_count;
980 err = ixgbe_setup_rx_resources(&temp_ring[i]);
981 if (err) {
982 while (i) {
983 i--;
984 ixgbe_free_rx_resources(&temp_ring[i]);
985 }
986 goto err_setup;
987 }
988
989 }
990
991 for (i = 0; i < adapter->num_rx_queues; i++) {
992 ixgbe_free_rx_resources(adapter->rx_ring[i]);
993
994 memcpy(adapter->rx_ring[i], &temp_ring[i],
995 sizeof(struct ixgbe_ring));
996 }
997
998 adapter->rx_ring_count = new_rx_count;
999 }
1000
Mallikarjuna R Chilakalaf9ed8852009-03-31 21:35:24 +00001001err_setup:
Alexander Duyck1f4702a2012-09-12 07:09:51 +00001002 ixgbe_up(adapter);
1003 vfree(temp_ring);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00001004clear_reset:
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001005 clear_bit(__IXGBE_RESETTING, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07001006 return err;
1007}
1008
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001009static int ixgbe_get_sset_count(struct net_device *netdev, int sset)
Auke Kok9a799d72007-09-15 14:07:45 -07001010{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001011 switch (sset) {
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001012 case ETH_SS_TEST:
1013 return IXGBE_TEST_LEN;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001014 case ETH_SS_STATS:
1015 return IXGBE_STATS_LEN;
1016 default:
1017 return -EOPNOTSUPP;
1018 }
Auke Kok9a799d72007-09-15 14:07:45 -07001019}
1020
1021static void ixgbe_get_ethtool_stats(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001022 struct ethtool_stats *stats, u64 *data)
Auke Kok9a799d72007-09-15 14:07:45 -07001023{
1024 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Eric Dumazet28172732010-07-07 14:58:56 -07001025 struct rtnl_link_stats64 temp;
1026 const struct rtnl_link_stats64 *net_stats;
Eric Dumazetde1036b2010-10-20 23:00:04 +00001027 unsigned int start;
1028 struct ixgbe_ring *ring;
1029 int i, j;
Ajit Khaparde29c3a052009-10-13 01:47:33 +00001030 char *p = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001031
1032 ixgbe_update_stats(adapter);
Eric Dumazet28172732010-07-07 14:58:56 -07001033 net_stats = dev_get_stats(netdev, &temp);
Auke Kok9a799d72007-09-15 14:07:45 -07001034 for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) {
Ajit Khaparde29c3a052009-10-13 01:47:33 +00001035 switch (ixgbe_gstrings_stats[i].type) {
1036 case NETDEV_STATS:
Eric Dumazet28172732010-07-07 14:58:56 -07001037 p = (char *) net_stats +
Ajit Khaparde29c3a052009-10-13 01:47:33 +00001038 ixgbe_gstrings_stats[i].stat_offset;
1039 break;
1040 case IXGBE_STATS:
1041 p = (char *) adapter +
1042 ixgbe_gstrings_stats[i].stat_offset;
1043 break;
Josh Hayf752be92013-01-04 03:34:36 +00001044 default:
1045 data[i] = 0;
1046 continue;
Ajit Khaparde29c3a052009-10-13 01:47:33 +00001047 }
1048
Auke Kok9a799d72007-09-15 14:07:45 -07001049 data[i] = (ixgbe_gstrings_stats[i].sizeof_stat ==
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001050 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Auke Kok9a799d72007-09-15 14:07:45 -07001051 }
John Fastabend9cc00b52012-01-28 03:32:17 +00001052 for (j = 0; j < IXGBE_NUM_RX_QUEUES; j++) {
Eric Dumazetde1036b2010-10-20 23:00:04 +00001053 ring = adapter->tx_ring[j];
John Fastabend9cc00b52012-01-28 03:32:17 +00001054 if (!ring) {
1055 data[i] = 0;
1056 data[i+1] = 0;
1057 i += 2;
Eliezer Tamir7e15b902013-06-10 11:40:31 +03001058#ifdef LL_EXTENDED_STATS
1059 data[i] = 0;
1060 data[i+1] = 0;
1061 data[i+2] = 0;
1062 i += 3;
1063#endif
John Fastabend9cc00b52012-01-28 03:32:17 +00001064 continue;
1065 }
1066
Eric Dumazetde1036b2010-10-20 23:00:04 +00001067 do {
1068 start = u64_stats_fetch_begin_bh(&ring->syncp);
1069 data[i] = ring->stats.packets;
1070 data[i+1] = ring->stats.bytes;
1071 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
1072 i += 2;
Eliezer Tamir7e15b902013-06-10 11:40:31 +03001073#ifdef LL_EXTENDED_STATS
1074 data[i] = ring->stats.yields;
1075 data[i+1] = ring->stats.misses;
1076 data[i+2] = ring->stats.cleaned;
1077 i += 3;
1078#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001079 }
John Fastabend9cc00b52012-01-28 03:32:17 +00001080 for (j = 0; j < IXGBE_NUM_RX_QUEUES; j++) {
Eric Dumazetde1036b2010-10-20 23:00:04 +00001081 ring = adapter->rx_ring[j];
John Fastabend9cc00b52012-01-28 03:32:17 +00001082 if (!ring) {
1083 data[i] = 0;
1084 data[i+1] = 0;
1085 i += 2;
Eliezer Tamir7e15b902013-06-10 11:40:31 +03001086#ifdef LL_EXTENDED_STATS
1087 data[i] = 0;
1088 data[i+1] = 0;
1089 data[i+2] = 0;
1090 i += 3;
1091#endif
John Fastabend9cc00b52012-01-28 03:32:17 +00001092 continue;
1093 }
1094
Eric Dumazetde1036b2010-10-20 23:00:04 +00001095 do {
1096 start = u64_stats_fetch_begin_bh(&ring->syncp);
1097 data[i] = ring->stats.packets;
1098 data[i+1] = ring->stats.bytes;
1099 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
1100 i += 2;
Eliezer Tamir7e15b902013-06-10 11:40:31 +03001101#ifdef LL_EXTENDED_STATS
1102 data[i] = ring->stats.yields;
1103 data[i+1] = ring->stats.misses;
1104 data[i+2] = ring->stats.cleaned;
1105 i += 3;
1106#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001107 }
John Fastabend9cc00b52012-01-28 03:32:17 +00001108
1109 for (j = 0; j < IXGBE_MAX_PACKET_BUFFERS; j++) {
1110 data[i++] = adapter->stats.pxontxc[j];
1111 data[i++] = adapter->stats.pxofftxc[j];
1112 }
1113 for (j = 0; j < IXGBE_MAX_PACKET_BUFFERS; j++) {
1114 data[i++] = adapter->stats.pxonrxc[j];
1115 data[i++] = adapter->stats.pxoffrxc[j];
Alexander Duyck2f90b862008-11-20 20:52:10 -08001116 }
Auke Kok9a799d72007-09-15 14:07:45 -07001117}
1118
1119static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001120 u8 *data)
Auke Kok9a799d72007-09-15 14:07:45 -07001121{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001122 char *p = (char *)data;
Auke Kok9a799d72007-09-15 14:07:45 -07001123 int i;
1124
1125 switch (stringset) {
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001126 case ETH_SS_TEST:
Josh Hayd2c47b62013-01-04 03:34:42 +00001127 for (i = 0; i < IXGBE_TEST_LEN; i++) {
1128 memcpy(data, ixgbe_gstrings_test[i], ETH_GSTRING_LEN);
1129 data += ETH_GSTRING_LEN;
1130 }
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001131 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001132 case ETH_SS_STATS:
1133 for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) {
1134 memcpy(p, ixgbe_gstrings_stats[i].stat_string,
1135 ETH_GSTRING_LEN);
1136 p += ETH_GSTRING_LEN;
1137 }
John Fastabend9cc00b52012-01-28 03:32:17 +00001138 for (i = 0; i < netdev->num_tx_queues; i++) {
Auke Kok9a799d72007-09-15 14:07:45 -07001139 sprintf(p, "tx_queue_%u_packets", i);
1140 p += ETH_GSTRING_LEN;
1141 sprintf(p, "tx_queue_%u_bytes", i);
1142 p += ETH_GSTRING_LEN;
Eliezer Tamir7e15b902013-06-10 11:40:31 +03001143#ifdef LL_EXTENDED_STATS
1144 sprintf(p, "tx_q_%u_napi_yield", i);
1145 p += ETH_GSTRING_LEN;
1146 sprintf(p, "tx_q_%u_misses", i);
1147 p += ETH_GSTRING_LEN;
1148 sprintf(p, "tx_q_%u_cleaned", i);
1149 p += ETH_GSTRING_LEN;
1150#endif /* LL_EXTENDED_STATS */
Auke Kok9a799d72007-09-15 14:07:45 -07001151 }
John Fastabend9cc00b52012-01-28 03:32:17 +00001152 for (i = 0; i < IXGBE_NUM_RX_QUEUES; i++) {
Auke Kok9a799d72007-09-15 14:07:45 -07001153 sprintf(p, "rx_queue_%u_packets", i);
1154 p += ETH_GSTRING_LEN;
1155 sprintf(p, "rx_queue_%u_bytes", i);
1156 p += ETH_GSTRING_LEN;
Eliezer Tamir7e15b902013-06-10 11:40:31 +03001157#ifdef LL_EXTENDED_STATS
1158 sprintf(p, "rx_q_%u_ll_poll_yield", i);
1159 p += ETH_GSTRING_LEN;
1160 sprintf(p, "rx_q_%u_misses", i);
1161 p += ETH_GSTRING_LEN;
1162 sprintf(p, "rx_q_%u_cleaned", i);
1163 p += ETH_GSTRING_LEN;
1164#endif /* LL_EXTENDED_STATS */
Auke Kok9a799d72007-09-15 14:07:45 -07001165 }
John Fastabend9cc00b52012-01-28 03:32:17 +00001166 for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
1167 sprintf(p, "tx_pb_%u_pxon", i);
1168 p += ETH_GSTRING_LEN;
1169 sprintf(p, "tx_pb_%u_pxoff", i);
1170 p += ETH_GSTRING_LEN;
1171 }
1172 for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
1173 sprintf(p, "rx_pb_%u_pxon", i);
1174 p += ETH_GSTRING_LEN;
1175 sprintf(p, "rx_pb_%u_pxoff", i);
1176 p += ETH_GSTRING_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08001177 }
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001178 /* BUG_ON(p - data != IXGBE_STATS_LEN * ETH_GSTRING_LEN); */
Auke Kok9a799d72007-09-15 14:07:45 -07001179 break;
1180 }
1181}
1182
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001183static int ixgbe_link_test(struct ixgbe_adapter *adapter, u64 *data)
1184{
1185 struct ixgbe_hw *hw = &adapter->hw;
1186 bool link_up;
1187 u32 link_speed = 0;
1188 *data = 0;
1189
1190 hw->mac.ops.check_link(hw, &link_speed, &link_up, true);
1191 if (link_up)
1192 return *data;
1193 else
1194 *data = 1;
1195 return *data;
1196}
1197
1198/* ethtool register test data */
1199struct ixgbe_reg_test {
1200 u16 reg;
1201 u8 array_len;
1202 u8 test_type;
1203 u32 mask;
1204 u32 write;
1205};
1206
1207/* In the hardware, registers are laid out either singly, in arrays
1208 * spaced 0x40 bytes apart, or in contiguous tables. We assume
1209 * most tests take place on arrays or single registers (handled
1210 * as a single-element array) and special-case the tables.
1211 * Table tests are always pattern tests.
1212 *
1213 * We also make provision for some required setup steps by specifying
1214 * registers to be written without any read-back testing.
1215 */
1216
1217#define PATTERN_TEST 1
1218#define SET_READ_TEST 2
1219#define WRITE_NO_TEST 3
1220#define TABLE32_TEST 4
1221#define TABLE64_TEST_LO 5
1222#define TABLE64_TEST_HI 6
1223
1224/* default 82599 register test */
Jeff Kirsher66744502010-12-01 19:59:50 +00001225static const struct ixgbe_reg_test reg_test_82599[] = {
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001226 { IXGBE_FCRTL_82599(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
1227 { IXGBE_FCRTH_82599(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
1228 { IXGBE_PFCTOP, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1229 { IXGBE_VLNCTRL, 1, PATTERN_TEST, 0x00000000, 0x00000000 },
1230 { IXGBE_RDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFF80 },
1231 { IXGBE_RDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1232 { IXGBE_RDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1233 { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE },
1234 { IXGBE_RDT(0), 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1235 { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, 0 },
1236 { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
1237 { IXGBE_FCTTV(0), 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1238 { IXGBE_TDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1239 { IXGBE_TDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1240 { IXGBE_TDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFF80 },
1241 { IXGBE_RXCTRL, 1, SET_READ_TEST, 0x00000001, 0x00000001 },
1242 { IXGBE_RAL(0), 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
1243 { IXGBE_RAL(0), 16, TABLE64_TEST_HI, 0x8001FFFF, 0x800CFFFF },
1244 { IXGBE_MTA(0), 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1245 { 0, 0, 0, 0 }
1246};
1247
1248/* default 82598 register test */
Jeff Kirsher66744502010-12-01 19:59:50 +00001249static const struct ixgbe_reg_test reg_test_82598[] = {
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001250 { IXGBE_FCRTL(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
1251 { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
1252 { IXGBE_PFCTOP, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1253 { IXGBE_VLNCTRL, 1, PATTERN_TEST, 0x00000000, 0x00000000 },
1254 { IXGBE_RDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1255 { IXGBE_RDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1256 { IXGBE_RDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1257 /* Enable all four RX queues before testing. */
1258 { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE },
1259 /* RDH is read-only for 82598, only test RDT. */
1260 { IXGBE_RDT(0), 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
1261 { IXGBE_RXDCTL(0), 4, WRITE_NO_TEST, 0, 0 },
1262 { IXGBE_FCRTH(0), 1, PATTERN_TEST, 0x8007FFF0, 0x8007FFF0 },
1263 { IXGBE_FCTTV(0), 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1264 { IXGBE_TIPG, 1, PATTERN_TEST, 0x000000FF, 0x000000FF },
1265 { IXGBE_TDBAL(0), 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
1266 { IXGBE_TDBAH(0), 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1267 { IXGBE_TDLEN(0), 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
1268 { IXGBE_RXCTRL, 1, SET_READ_TEST, 0x00000003, 0x00000003 },
1269 { IXGBE_DTXCTL, 1, SET_READ_TEST, 0x00000005, 0x00000005 },
1270 { IXGBE_RAL(0), 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF },
1271 { IXGBE_RAL(0), 16, TABLE64_TEST_HI, 0x800CFFFF, 0x800CFFFF },
1272 { IXGBE_MTA(0), 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
1273 { 0, 0, 0, 0 }
1274};
1275
Emil Tantilov95a46012011-04-14 07:46:41 +00001276static bool reg_pattern_test(struct ixgbe_adapter *adapter, u64 *data, int reg,
1277 u32 mask, u32 write)
1278{
1279 u32 pat, val, before;
1280 static const u32 test_pattern[] = {
1281 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Jeff Kirsher66744502010-12-01 19:59:50 +00001282
Emil Tantilov95a46012011-04-14 07:46:41 +00001283 for (pat = 0; pat < ARRAY_SIZE(test_pattern); pat++) {
1284 before = readl(adapter->hw.hw_addr + reg);
1285 writel((test_pattern[pat] & write),
1286 (adapter->hw.hw_addr + reg));
1287 val = readl(adapter->hw.hw_addr + reg);
1288 if (val != (test_pattern[pat] & write & mask)) {
1289 e_err(drv, "pattern test reg %04X failed: got "
1290 "0x%08X expected 0x%08X\n",
1291 reg, val, (test_pattern[pat] & write & mask));
1292 *data = reg;
1293 writel(before, adapter->hw.hw_addr + reg);
1294 return 1;
1295 }
1296 writel(before, adapter->hw.hw_addr + reg);
1297 }
1298 return 0;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001299}
1300
Emil Tantilov95a46012011-04-14 07:46:41 +00001301static bool reg_set_and_check(struct ixgbe_adapter *adapter, u64 *data, int reg,
1302 u32 mask, u32 write)
1303{
1304 u32 val, before;
1305 before = readl(adapter->hw.hw_addr + reg);
1306 writel((write & mask), (adapter->hw.hw_addr + reg));
1307 val = readl(adapter->hw.hw_addr + reg);
1308 if ((write & mask) != (val & mask)) {
1309 e_err(drv, "set/check reg %04X test failed: got 0x%08X "
1310 "expected 0x%08X\n", reg, (val & mask), (write & mask));
1311 *data = reg;
1312 writel(before, (adapter->hw.hw_addr + reg));
1313 return 1;
1314 }
1315 writel(before, (adapter->hw.hw_addr + reg));
1316 return 0;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001317}
1318
Emil Tantilov95a46012011-04-14 07:46:41 +00001319#define REG_PATTERN_TEST(reg, mask, write) \
1320 do { \
1321 if (reg_pattern_test(adapter, data, reg, mask, write)) \
1322 return 1; \
1323 } while (0) \
1324
1325
1326#define REG_SET_AND_CHECK(reg, mask, write) \
1327 do { \
1328 if (reg_set_and_check(adapter, data, reg, mask, write)) \
1329 return 1; \
1330 } while (0) \
1331
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001332static int ixgbe_reg_test(struct ixgbe_adapter *adapter, u64 *data)
1333{
Jeff Kirsher66744502010-12-01 19:59:50 +00001334 const struct ixgbe_reg_test *test;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001335 u32 value, before, after;
1336 u32 i, toggle;
1337
Alexander Duyckbd508172010-11-16 19:27:03 -08001338 switch (adapter->hw.mac.type) {
1339 case ixgbe_mac_82598EB:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001340 toggle = 0x7FFFF3FF;
1341 test = reg_test_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08001342 break;
1343 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001344 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08001345 toggle = 0x7FFFF30F;
1346 test = reg_test_82599;
1347 break;
1348 default:
1349 *data = 1;
1350 return 1;
1351 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001352 }
1353
1354 /*
1355 * Because the status register is such a special case,
1356 * we handle it separately from the rest of the register
1357 * tests. Some bits are read-only, some toggle, and some
1358 * are writeable on newer MACs.
1359 */
1360 before = IXGBE_READ_REG(&adapter->hw, IXGBE_STATUS);
1361 value = (IXGBE_READ_REG(&adapter->hw, IXGBE_STATUS) & toggle);
1362 IXGBE_WRITE_REG(&adapter->hw, IXGBE_STATUS, toggle);
1363 after = IXGBE_READ_REG(&adapter->hw, IXGBE_STATUS) & toggle;
1364 if (value != after) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001365 e_err(drv, "failed STATUS register test got: 0x%08X "
1366 "expected: 0x%08X\n", after, value);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001367 *data = 1;
1368 return 1;
1369 }
1370 /* restore previous status */
1371 IXGBE_WRITE_REG(&adapter->hw, IXGBE_STATUS, before);
1372
1373 /*
1374 * Perform the remainder of the register test, looping through
1375 * the test table until we either fail or reach the null entry.
1376 */
1377 while (test->reg) {
1378 for (i = 0; i < test->array_len; i++) {
1379 switch (test->test_type) {
1380 case PATTERN_TEST:
1381 REG_PATTERN_TEST(test->reg + (i * 0x40),
Emil Tantilov95a46012011-04-14 07:46:41 +00001382 test->mask,
1383 test->write);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001384 break;
1385 case SET_READ_TEST:
1386 REG_SET_AND_CHECK(test->reg + (i * 0x40),
Emil Tantilov95a46012011-04-14 07:46:41 +00001387 test->mask,
1388 test->write);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001389 break;
1390 case WRITE_NO_TEST:
1391 writel(test->write,
1392 (adapter->hw.hw_addr + test->reg)
1393 + (i * 0x40));
1394 break;
1395 case TABLE32_TEST:
1396 REG_PATTERN_TEST(test->reg + (i * 4),
Emil Tantilov95a46012011-04-14 07:46:41 +00001397 test->mask,
1398 test->write);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001399 break;
1400 case TABLE64_TEST_LO:
1401 REG_PATTERN_TEST(test->reg + (i * 8),
Emil Tantilov95a46012011-04-14 07:46:41 +00001402 test->mask,
1403 test->write);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001404 break;
1405 case TABLE64_TEST_HI:
1406 REG_PATTERN_TEST((test->reg + 4) + (i * 8),
Emil Tantilov95a46012011-04-14 07:46:41 +00001407 test->mask,
1408 test->write);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001409 break;
1410 }
1411 }
1412 test++;
1413 }
1414
1415 *data = 0;
1416 return 0;
1417}
1418
1419static int ixgbe_eeprom_test(struct ixgbe_adapter *adapter, u64 *data)
1420{
1421 struct ixgbe_hw *hw = &adapter->hw;
1422 if (hw->eeprom.ops.validate_checksum(hw, NULL))
1423 *data = 1;
1424 else
1425 *data = 0;
1426 return *data;
1427}
1428
1429static irqreturn_t ixgbe_test_intr(int irq, void *data)
1430{
1431 struct net_device *netdev = (struct net_device *) data;
1432 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1433
1434 adapter->test_icr |= IXGBE_READ_REG(&adapter->hw, IXGBE_EICR);
1435
1436 return IRQ_HANDLED;
1437}
1438
1439static int ixgbe_intr_test(struct ixgbe_adapter *adapter, u64 *data)
1440{
1441 struct net_device *netdev = adapter->netdev;
1442 u32 mask, i = 0, shared_int = true;
1443 u32 irq = adapter->pdev->irq;
1444
1445 *data = 0;
1446
1447 /* Hook up test interrupt handler just for this test */
1448 if (adapter->msix_entries) {
1449 /* NOTE: we don't test MSI-X interrupts here, yet */
1450 return 0;
1451 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1452 shared_int = false;
Joe Perchesa0607fd2009-11-18 23:29:17 -08001453 if (request_irq(irq, ixgbe_test_intr, 0, netdev->name,
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001454 netdev)) {
1455 *data = 1;
1456 return -1;
1457 }
Joe Perchesa0607fd2009-11-18 23:29:17 -08001458 } else if (!request_irq(irq, ixgbe_test_intr, IRQF_PROBE_SHARED,
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001459 netdev->name, netdev)) {
1460 shared_int = false;
Joe Perchesa0607fd2009-11-18 23:29:17 -08001461 } else if (request_irq(irq, ixgbe_test_intr, IRQF_SHARED,
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001462 netdev->name, netdev)) {
1463 *data = 1;
1464 return -1;
1465 }
Emil Tantilov396e7992010-07-01 20:05:12 +00001466 e_info(hw, "testing %s interrupt\n", shared_int ?
1467 "shared" : "unshared");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001468
1469 /* Disable all the interrupts */
1470 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001471 IXGBE_WRITE_FLUSH(&adapter->hw);
Don Skidmore032b4322011-03-18 09:32:53 +00001472 usleep_range(10000, 20000);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001473
1474 /* Test each interrupt */
1475 for (; i < 10; i++) {
1476 /* Interrupt to test */
1477 mask = 1 << i;
1478
1479 if (!shared_int) {
1480 /*
1481 * Disable the interrupts to be reported in
1482 * the cause register and then force the same
1483 * interrupt and see if one gets posted. If
1484 * an interrupt was posted to the bus, the
1485 * test failed.
1486 */
1487 adapter->test_icr = 0;
1488 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
1489 ~mask & 0x00007FFF);
1490 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS,
1491 ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001492 IXGBE_WRITE_FLUSH(&adapter->hw);
Don Skidmore032b4322011-03-18 09:32:53 +00001493 usleep_range(10000, 20000);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001494
1495 if (adapter->test_icr & mask) {
1496 *data = 3;
1497 break;
1498 }
1499 }
1500
1501 /*
1502 * Enable the interrupt to be reported in the cause
1503 * register and then force the same interrupt and see
1504 * if one gets posted. If an interrupt was not posted
1505 * to the bus, the test failed.
1506 */
1507 adapter->test_icr = 0;
1508 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1509 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001510 IXGBE_WRITE_FLUSH(&adapter->hw);
Don Skidmore032b4322011-03-18 09:32:53 +00001511 usleep_range(10000, 20000);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001512
1513 if (!(adapter->test_icr &mask)) {
1514 *data = 4;
1515 break;
1516 }
1517
1518 if (!shared_int) {
1519 /*
1520 * Disable the other interrupts to be reported in
1521 * the cause register and then force the other
1522 * interrupts and see if any get posted. If
1523 * an interrupt was posted to the bus, the
1524 * test failed.
1525 */
1526 adapter->test_icr = 0;
1527 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
1528 ~mask & 0x00007FFF);
1529 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS,
1530 ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001531 IXGBE_WRITE_FLUSH(&adapter->hw);
Don Skidmore032b4322011-03-18 09:32:53 +00001532 usleep_range(10000, 20000);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001533
1534 if (adapter->test_icr) {
1535 *data = 5;
1536 break;
1537 }
1538 }
1539 }
1540
1541 /* Disable all the interrupts */
1542 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001543 IXGBE_WRITE_FLUSH(&adapter->hw);
Don Skidmore032b4322011-03-18 09:32:53 +00001544 usleep_range(10000, 20000);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001545
1546 /* Unhook test interrupt handler */
1547 free_irq(irq, netdev);
1548
1549 return *data;
1550}
1551
1552static void ixgbe_free_desc_rings(struct ixgbe_adapter *adapter)
1553{
1554 struct ixgbe_ring *tx_ring = &adapter->test_tx_ring;
1555 struct ixgbe_ring *rx_ring = &adapter->test_rx_ring;
1556 struct ixgbe_hw *hw = &adapter->hw;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001557 u32 reg_ctl;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001558
1559 /* shut down the DMA engines now so they can be reinitialized later */
1560
1561 /* first Rx */
1562 reg_ctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1563 reg_ctl &= ~IXGBE_RXCTRL_RXEN;
1564 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_ctl);
Yi Zou2d39d572011-01-06 14:29:56 +00001565 ixgbe_disable_rx_queue(adapter, rx_ring);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001566
1567 /* now Tx */
Alexander Duyck84418e32010-08-19 13:40:54 +00001568 reg_ctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(tx_ring->reg_idx));
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001569 reg_ctl &= ~IXGBE_TXDCTL_ENABLE;
Alexander Duyck84418e32010-08-19 13:40:54 +00001570 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(tx_ring->reg_idx), reg_ctl);
1571
Alexander Duyckbd508172010-11-16 19:27:03 -08001572 switch (hw->mac.type) {
1573 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001574 case ixgbe_mac_X540:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001575 reg_ctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
1576 reg_ctl &= ~IXGBE_DMATXCTL_TE;
1577 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg_ctl);
Alexander Duyckbd508172010-11-16 19:27:03 -08001578 break;
1579 default:
1580 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001581 }
1582
1583 ixgbe_reset(adapter);
1584
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001585 ixgbe_free_tx_resources(&adapter->test_tx_ring);
1586 ixgbe_free_rx_resources(&adapter->test_rx_ring);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001587}
1588
1589static int ixgbe_setup_desc_rings(struct ixgbe_adapter *adapter)
1590{
1591 struct ixgbe_ring *tx_ring = &adapter->test_tx_ring;
1592 struct ixgbe_ring *rx_ring = &adapter->test_rx_ring;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001593 u32 rctl, reg_data;
Alexander Duyck84418e32010-08-19 13:40:54 +00001594 int ret_val;
1595 int err;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001596
1597 /* Setup Tx descriptor ring and Tx buffers */
Alexander Duyck84418e32010-08-19 13:40:54 +00001598 tx_ring->count = IXGBE_DEFAULT_TXD;
1599 tx_ring->queue_index = 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001600 tx_ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001601 tx_ring->netdev = adapter->netdev;
Alexander Duyck84418e32010-08-19 13:40:54 +00001602 tx_ring->reg_idx = adapter->tx_ring[0]->reg_idx;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001603
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001604 err = ixgbe_setup_tx_resources(tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00001605 if (err)
1606 return 1;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001607
Alexander Duyckbd508172010-11-16 19:27:03 -08001608 switch (adapter->hw.mac.type) {
1609 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001610 case ixgbe_mac_X540:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001611 reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_DMATXCTL);
1612 reg_data |= IXGBE_DMATXCTL_TE;
1613 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DMATXCTL, reg_data);
Alexander Duyckbd508172010-11-16 19:27:03 -08001614 break;
1615 default:
1616 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001617 }
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001618
Alexander Duyck84418e32010-08-19 13:40:54 +00001619 ixgbe_configure_tx_ring(adapter, tx_ring);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001620
1621 /* Setup Rx Descriptor ring and Rx buffers */
Alexander Duyck84418e32010-08-19 13:40:54 +00001622 rx_ring->count = IXGBE_DEFAULT_RXD;
1623 rx_ring->queue_index = 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001624 rx_ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001625 rx_ring->netdev = adapter->netdev;
Alexander Duyck84418e32010-08-19 13:40:54 +00001626 rx_ring->reg_idx = adapter->rx_ring[0]->reg_idx;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001627
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001628 err = ixgbe_setup_rx_resources(rx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00001629 if (err) {
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001630 ret_val = 4;
1631 goto err_nomem;
1632 }
1633
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001634 rctl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXCTRL);
1635 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXCTRL, rctl & ~IXGBE_RXCTRL_RXEN);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001636
Alexander Duyck84418e32010-08-19 13:40:54 +00001637 ixgbe_configure_rx_ring(adapter, rx_ring);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001638
1639 rctl |= IXGBE_RXCTRL_RXEN | IXGBE_RXCTRL_DMBYPS;
1640 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXCTRL, rctl);
1641
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001642 return 0;
1643
1644err_nomem:
1645 ixgbe_free_desc_rings(adapter);
1646 return ret_val;
1647}
1648
1649static int ixgbe_setup_loopback_test(struct ixgbe_adapter *adapter)
1650{
1651 struct ixgbe_hw *hw = &adapter->hw;
1652 u32 reg_data;
1653
Don Skidmoree7fd9252011-04-16 05:29:14 +00001654
Alexander Duyck84418e32010-08-19 13:40:54 +00001655 /* Setup MAC loopback */
Emil Tantilov26b47422013-04-12 02:10:25 +00001656 reg_data = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001657 reg_data |= IXGBE_HLREG0_LPBK;
Alexander Duyck35c7f8a2011-07-15 03:06:01 +00001658 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, reg_data);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001659
Alexander Duyck35c7f8a2011-07-15 03:06:01 +00001660 reg_data = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck84418e32010-08-19 13:40:54 +00001661 reg_data |= IXGBE_FCTRL_BAM | IXGBE_FCTRL_SBP | IXGBE_FCTRL_MPE;
Alexander Duyck35c7f8a2011-07-15 03:06:01 +00001662 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg_data);
Alexander Duyck84418e32010-08-19 13:40:54 +00001663
Emil Tantilov26b47422013-04-12 02:10:25 +00001664 /* X540 needs to set the MACC.FLU bit to force link up */
1665 if (adapter->hw.mac.type == ixgbe_mac_X540) {
1666 reg_data = IXGBE_READ_REG(hw, IXGBE_MACC);
1667 reg_data |= IXGBE_MACC_FLU;
1668 IXGBE_WRITE_REG(hw, IXGBE_MACC, reg_data);
1669 } else {
1670 if (hw->mac.orig_autoc) {
1671 reg_data = hw->mac.orig_autoc | IXGBE_AUTOC_FLU;
1672 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_data);
1673 } else {
1674 return 10;
1675 }
1676 }
Alexander Duyck35c7f8a2011-07-15 03:06:01 +00001677 IXGBE_WRITE_FLUSH(hw);
Don Skidmore032b4322011-03-18 09:32:53 +00001678 usleep_range(10000, 20000);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001679
1680 /* Disable Atlas Tx lanes; re-enabled in reset path */
1681 if (hw->mac.type == ixgbe_mac_82598EB) {
1682 u8 atlas;
1683
1684 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &atlas);
1685 atlas |= IXGBE_ATLAS_PDN_TX_REG_EN;
1686 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, atlas);
1687
1688 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, &atlas);
1689 atlas |= IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
1690 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, atlas);
1691
1692 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, &atlas);
1693 atlas |= IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
1694 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, atlas);
1695
1696 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, &atlas);
1697 atlas |= IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
1698 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, atlas);
1699 }
1700
1701 return 0;
1702}
1703
1704static void ixgbe_loopback_cleanup(struct ixgbe_adapter *adapter)
1705{
1706 u32 reg_data;
1707
1708 reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_HLREG0);
1709 reg_data &= ~IXGBE_HLREG0_LPBK;
1710 IXGBE_WRITE_REG(&adapter->hw, IXGBE_HLREG0, reg_data);
1711}
1712
1713static void ixgbe_create_lbtest_frame(struct sk_buff *skb,
Alexander Duyck3832b262012-02-08 07:50:09 +00001714 unsigned int frame_size)
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001715{
1716 memset(skb->data, 0xFF, frame_size);
Alexander Duyck3832b262012-02-08 07:50:09 +00001717 frame_size >>= 1;
1718 memset(&skb->data[frame_size], 0xAA, frame_size / 2 - 1);
1719 memset(&skb->data[frame_size + 10], 0xBE, 1);
1720 memset(&skb->data[frame_size + 12], 0xAF, 1);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001721}
1722
Alexander Duyck3832b262012-02-08 07:50:09 +00001723static bool ixgbe_check_lbtest_frame(struct ixgbe_rx_buffer *rx_buffer,
1724 unsigned int frame_size)
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001725{
Alexander Duyck3832b262012-02-08 07:50:09 +00001726 unsigned char *data;
1727 bool match = true;
1728
1729 frame_size >>= 1;
1730
Alexander Duyckf8003262012-03-03 02:35:52 +00001731 data = kmap(rx_buffer->page) + rx_buffer->page_offset;
Alexander Duyck3832b262012-02-08 07:50:09 +00001732
1733 if (data[3] != 0xFF ||
1734 data[frame_size + 10] != 0xBE ||
1735 data[frame_size + 12] != 0xAF)
1736 match = false;
1737
Alexander Duyckf8003262012-03-03 02:35:52 +00001738 kunmap(rx_buffer->page);
1739
Alexander Duyck3832b262012-02-08 07:50:09 +00001740 return match;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001741}
1742
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001743static u16 ixgbe_clean_test_rings(struct ixgbe_ring *rx_ring,
Alexander Duyck3832b262012-02-08 07:50:09 +00001744 struct ixgbe_ring *tx_ring,
1745 unsigned int size)
Alexander Duyck84418e32010-08-19 13:40:54 +00001746{
1747 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyck3832b262012-02-08 07:50:09 +00001748 struct ixgbe_rx_buffer *rx_buffer;
1749 struct ixgbe_tx_buffer *tx_buffer;
Alexander Duyck84418e32010-08-19 13:40:54 +00001750 u16 rx_ntc, tx_ntc, count = 0;
1751
1752 /* initialize next to clean and descriptor values */
1753 rx_ntc = rx_ring->next_to_clean;
1754 tx_ntc = tx_ring->next_to_clean;
Alexander Duycke4f74022012-01-31 02:59:44 +00001755 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ntc);
Alexander Duyck84418e32010-08-19 13:40:54 +00001756
Alexander Duyck3832b262012-02-08 07:50:09 +00001757 while (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) {
Alexander Duyck84418e32010-08-19 13:40:54 +00001758 /* check Rx buffer */
Alexander Duyck3832b262012-02-08 07:50:09 +00001759 rx_buffer = &rx_ring->rx_buffer_info[rx_ntc];
Alexander Duyck84418e32010-08-19 13:40:54 +00001760
Alexander Duyckf8003262012-03-03 02:35:52 +00001761 /* sync Rx buffer for CPU read */
1762 dma_sync_single_for_cpu(rx_ring->dev,
1763 rx_buffer->dma,
1764 ixgbe_rx_bufsz(rx_ring),
1765 DMA_FROM_DEVICE);
Alexander Duyck84418e32010-08-19 13:40:54 +00001766
1767 /* verify contents of skb */
Alexander Duyck3832b262012-02-08 07:50:09 +00001768 if (ixgbe_check_lbtest_frame(rx_buffer, size))
Alexander Duyck84418e32010-08-19 13:40:54 +00001769 count++;
1770
Alexander Duyckf8003262012-03-03 02:35:52 +00001771 /* sync Rx buffer for device write */
1772 dma_sync_single_for_device(rx_ring->dev,
1773 rx_buffer->dma,
1774 ixgbe_rx_bufsz(rx_ring),
1775 DMA_FROM_DEVICE);
1776
Alexander Duyck84418e32010-08-19 13:40:54 +00001777 /* unmap buffer on Tx side */
Alexander Duyck3832b262012-02-08 07:50:09 +00001778 tx_buffer = &tx_ring->tx_buffer_info[tx_ntc];
1779 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
Alexander Duyck84418e32010-08-19 13:40:54 +00001780
1781 /* increment Rx/Tx next to clean counters */
1782 rx_ntc++;
1783 if (rx_ntc == rx_ring->count)
1784 rx_ntc = 0;
1785 tx_ntc++;
1786 if (tx_ntc == tx_ring->count)
1787 tx_ntc = 0;
1788
1789 /* fetch next descriptor */
Alexander Duycke4f74022012-01-31 02:59:44 +00001790 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ntc);
Alexander Duyck84418e32010-08-19 13:40:54 +00001791 }
1792
John Fastabenddad8a3b2012-04-23 12:22:39 +00001793 netdev_tx_reset_queue(txring_txq(tx_ring));
1794
Alexander Duyck84418e32010-08-19 13:40:54 +00001795 /* re-map buffers to ring, store next to clean values */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001796 ixgbe_alloc_rx_buffers(rx_ring, count);
Alexander Duyck84418e32010-08-19 13:40:54 +00001797 rx_ring->next_to_clean = rx_ntc;
1798 tx_ring->next_to_clean = tx_ntc;
1799
1800 return count;
1801}
1802
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001803static int ixgbe_run_loopback_test(struct ixgbe_adapter *adapter)
1804{
1805 struct ixgbe_ring *tx_ring = &adapter->test_tx_ring;
1806 struct ixgbe_ring *rx_ring = &adapter->test_rx_ring;
Alexander Duyck84418e32010-08-19 13:40:54 +00001807 int i, j, lc, good_cnt, ret_val = 0;
1808 unsigned int size = 1024;
1809 netdev_tx_t tx_ret_val;
1810 struct sk_buff *skb;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001811
Alexander Duyck84418e32010-08-19 13:40:54 +00001812 /* allocate test skb */
1813 skb = alloc_skb(size, GFP_KERNEL);
1814 if (!skb)
1815 return 11;
1816
1817 /* place data into test skb */
1818 ixgbe_create_lbtest_frame(skb, size);
1819 skb_put(skb, size);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001820
1821 /*
1822 * Calculate the loop count based on the largest descriptor ring
1823 * The idea is to wrap the largest ring a number of times using 64
1824 * send/receive pairs during each loop
1825 */
1826
1827 if (rx_ring->count <= tx_ring->count)
1828 lc = ((tx_ring->count / 64) * 2) + 1;
1829 else
1830 lc = ((rx_ring->count / 64) * 2) + 1;
1831
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001832 for (j = 0; j <= lc; j++) {
Alexander Duyck84418e32010-08-19 13:40:54 +00001833 /* reset count of good packets */
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001834 good_cnt = 0;
Alexander Duyck84418e32010-08-19 13:40:54 +00001835
1836 /* place 64 packets on the transmit queue*/
1837 for (i = 0; i < 64; i++) {
1838 skb_get(skb);
1839 tx_ret_val = ixgbe_xmit_frame_ring(skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00001840 adapter,
1841 tx_ring);
1842 if (tx_ret_val == NETDEV_TX_OK)
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001843 good_cnt++;
Alexander Duyck84418e32010-08-19 13:40:54 +00001844 }
1845
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001846 if (good_cnt != 64) {
Alexander Duyck84418e32010-08-19 13:40:54 +00001847 ret_val = 12;
1848 break;
1849 }
1850
1851 /* allow 200 milliseconds for packets to go from Tx to Rx */
1852 msleep(200);
1853
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001854 good_cnt = ixgbe_clean_test_rings(rx_ring, tx_ring, size);
Alexander Duyck84418e32010-08-19 13:40:54 +00001855 if (good_cnt != 64) {
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001856 ret_val = 13;
1857 break;
1858 }
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001859 }
1860
Alexander Duyck84418e32010-08-19 13:40:54 +00001861 /* free the original skb */
1862 kfree_skb(skb);
1863
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001864 return ret_val;
1865}
1866
1867static int ixgbe_loopback_test(struct ixgbe_adapter *adapter, u64 *data)
1868{
1869 *data = ixgbe_setup_desc_rings(adapter);
1870 if (*data)
1871 goto out;
1872 *data = ixgbe_setup_loopback_test(adapter);
1873 if (*data)
1874 goto err_loopback;
1875 *data = ixgbe_run_loopback_test(adapter);
1876 ixgbe_loopback_cleanup(adapter);
1877
1878err_loopback:
1879 ixgbe_free_desc_rings(adapter);
1880out:
1881 return *data;
1882}
1883
1884static void ixgbe_diag_test(struct net_device *netdev,
1885 struct ethtool_test *eth_test, u64 *data)
1886{
1887 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jacob Kellerdfcc4612012-11-08 07:07:08 +00001888 struct ixgbe_hw *hw = &adapter->hw;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001889 bool if_running = netif_running(netdev);
1890
1891 set_bit(__IXGBE_TESTING, &adapter->state);
1892 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
Greg Rosee7d481a2010-03-25 17:06:48 +00001893 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
1894 int i;
1895 for (i = 0; i < adapter->num_vfs; i++) {
1896 if (adapter->vfinfo[i].clear_to_send) {
1897 netdev_warn(netdev, "%s",
1898 "offline diagnostic is not "
1899 "supported when VFs are "
1900 "present\n");
1901 data[0] = 1;
1902 data[1] = 1;
1903 data[2] = 1;
1904 data[3] = 1;
1905 eth_test->flags |= ETH_TEST_FL_FAILED;
1906 clear_bit(__IXGBE_TESTING,
1907 &adapter->state);
1908 goto skip_ol_tests;
1909 }
1910 }
1911 }
1912
Jacob Kellerdfcc4612012-11-08 07:07:08 +00001913 /* Offline tests */
1914 e_info(hw, "offline testing starting\n");
1915
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001916 if (if_running)
1917 /* indicate we're in test mode */
1918 dev_close(netdev);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001919
Jacob Kellerdfcc4612012-11-08 07:07:08 +00001920 /* bringing adapter down disables SFP+ optics */
1921 if (hw->mac.ops.enable_tx_laser)
1922 hw->mac.ops.enable_tx_laser(hw);
1923
1924 /* Link test performed before hardware reset so autoneg doesn't
1925 * interfere with test result
1926 */
1927 if (ixgbe_link_test(adapter, &data[4]))
1928 eth_test->flags |= ETH_TEST_FL_FAILED;
1929
1930 ixgbe_reset(adapter);
Emil Tantilov396e7992010-07-01 20:05:12 +00001931 e_info(hw, "register testing starting\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001932 if (ixgbe_reg_test(adapter, &data[0]))
1933 eth_test->flags |= ETH_TEST_FL_FAILED;
1934
1935 ixgbe_reset(adapter);
Emil Tantilov396e7992010-07-01 20:05:12 +00001936 e_info(hw, "eeprom testing starting\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001937 if (ixgbe_eeprom_test(adapter, &data[1]))
1938 eth_test->flags |= ETH_TEST_FL_FAILED;
1939
1940 ixgbe_reset(adapter);
Emil Tantilov396e7992010-07-01 20:05:12 +00001941 e_info(hw, "interrupt testing starting\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001942 if (ixgbe_intr_test(adapter, &data[2]))
1943 eth_test->flags |= ETH_TEST_FL_FAILED;
1944
Greg Rosebdbec4b2010-01-09 02:27:05 +00001945 /* If SRIOV or VMDq is enabled then skip MAC
1946 * loopback diagnostic. */
1947 if (adapter->flags & (IXGBE_FLAG_SRIOV_ENABLED |
1948 IXGBE_FLAG_VMDQ_ENABLED)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001949 e_info(hw, "Skip MAC loopback diagnostic in VT "
1950 "mode\n");
Greg Rosebdbec4b2010-01-09 02:27:05 +00001951 data[3] = 0;
1952 goto skip_loopback;
1953 }
1954
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001955 ixgbe_reset(adapter);
Emil Tantilov396e7992010-07-01 20:05:12 +00001956 e_info(hw, "loopback testing starting\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001957 if (ixgbe_loopback_test(adapter, &data[3]))
1958 eth_test->flags |= ETH_TEST_FL_FAILED;
1959
Greg Rosebdbec4b2010-01-09 02:27:05 +00001960skip_loopback:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001961 ixgbe_reset(adapter);
1962
Jacob Kellerdfcc4612012-11-08 07:07:08 +00001963 /* clear testing bit and return adapter to previous state */
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001964 clear_bit(__IXGBE_TESTING, &adapter->state);
1965 if (if_running)
1966 dev_open(netdev);
1967 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00001968 e_info(hw, "online testing starting\n");
Jacob Kellerdfcc4612012-11-08 07:07:08 +00001969
1970 /* if adapter is down, SFP+ optics will be disabled */
1971 if (!if_running && hw->mac.ops.enable_tx_laser)
1972 hw->mac.ops.enable_tx_laser(hw);
1973
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001974 /* Online tests */
1975 if (ixgbe_link_test(adapter, &data[4]))
1976 eth_test->flags |= ETH_TEST_FL_FAILED;
1977
Jacob Kellerdfcc4612012-11-08 07:07:08 +00001978 /* Offline tests aren't run; pass by default */
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001979 data[0] = 0;
1980 data[1] = 0;
1981 data[2] = 0;
1982 data[3] = 0;
1983
1984 clear_bit(__IXGBE_TESTING, &adapter->state);
1985 }
Jacob Kellerdfcc4612012-11-08 07:07:08 +00001986
1987 /* if adapter was down, ensure SFP+ optics are disabled again */
1988 if (!if_running && hw->mac.ops.disable_tx_laser)
1989 hw->mac.ops.disable_tx_laser(hw);
Greg Rosee7d481a2010-03-25 17:06:48 +00001990skip_ol_tests:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00001991 msleep_interruptible(4 * 1000);
1992}
Auke Kok9a799d72007-09-15 14:07:45 -07001993
Alexander Duyckd6c519e2009-04-08 13:20:50 +00001994static int ixgbe_wol_exclusion(struct ixgbe_adapter *adapter,
1995 struct ethtool_wolinfo *wol)
1996{
1997 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller8e2813f2012-04-21 06:05:40 +00001998 int retval = 0;
Alexander Duyckd6c519e2009-04-08 13:20:50 +00001999
Jacob Keller8e2813f2012-04-21 06:05:40 +00002000 /* WOL not supported for all devices */
2001 if (!ixgbe_wol_supported(adapter, hw->device_id,
2002 hw->subsystem_device_id)) {
2003 retval = 1;
Alexander Duyckd6c519e2009-04-08 13:20:50 +00002004 wol->supported = 0;
Alexander Duyckd6c519e2009-04-08 13:20:50 +00002005 }
2006
2007 return retval;
2008}
2009
Auke Kok9a799d72007-09-15 14:07:45 -07002010static void ixgbe_get_wol(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002011 struct ethtool_wolinfo *wol)
Auke Kok9a799d72007-09-15 14:07:45 -07002012{
PJ Waskiewicze63d9762009-03-19 01:23:46 +00002013 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2014
2015 wol->supported = WAKE_UCAST | WAKE_MCAST |
2016 WAKE_BCAST | WAKE_MAGIC;
Auke Kok9a799d72007-09-15 14:07:45 -07002017 wol->wolopts = 0;
2018
Alexander Duyckd6c519e2009-04-08 13:20:50 +00002019 if (ixgbe_wol_exclusion(adapter, wol) ||
2020 !device_can_wakeup(&adapter->pdev->dev))
PJ Waskiewicze63d9762009-03-19 01:23:46 +00002021 return;
2022
2023 if (adapter->wol & IXGBE_WUFC_EX)
2024 wol->wolopts |= WAKE_UCAST;
2025 if (adapter->wol & IXGBE_WUFC_MC)
2026 wol->wolopts |= WAKE_MCAST;
2027 if (adapter->wol & IXGBE_WUFC_BC)
2028 wol->wolopts |= WAKE_BCAST;
2029 if (adapter->wol & IXGBE_WUFC_MAG)
2030 wol->wolopts |= WAKE_MAGIC;
Auke Kok9a799d72007-09-15 14:07:45 -07002031}
2032
PJ Waskiewicze63d9762009-03-19 01:23:46 +00002033static int ixgbe_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2034{
2035 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2036
2037 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
2038 return -EOPNOTSUPP;
2039
Alexander Duyckd6c519e2009-04-08 13:20:50 +00002040 if (ixgbe_wol_exclusion(adapter, wol))
2041 return wol->wolopts ? -EOPNOTSUPP : 0;
2042
PJ Waskiewicze63d9762009-03-19 01:23:46 +00002043 adapter->wol = 0;
2044
2045 if (wol->wolopts & WAKE_UCAST)
2046 adapter->wol |= IXGBE_WUFC_EX;
2047 if (wol->wolopts & WAKE_MCAST)
2048 adapter->wol |= IXGBE_WUFC_MC;
2049 if (wol->wolopts & WAKE_BCAST)
2050 adapter->wol |= IXGBE_WUFC_BC;
2051 if (wol->wolopts & WAKE_MAGIC)
2052 adapter->wol |= IXGBE_WUFC_MAG;
2053
2054 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
2055
2056 return 0;
2057}
2058
Auke Kok9a799d72007-09-15 14:07:45 -07002059static int ixgbe_nway_reset(struct net_device *netdev)
2060{
2061 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2062
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002063 if (netif_running(netdev))
2064 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002065
2066 return 0;
2067}
2068
Emil Tantilov66e69612011-04-16 06:12:51 +00002069static int ixgbe_set_phys_id(struct net_device *netdev,
2070 enum ethtool_phys_id_state state)
Auke Kok9a799d72007-09-15 14:07:45 -07002071{
2072 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002073 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002074
Emil Tantilov66e69612011-04-16 06:12:51 +00002075 switch (state) {
2076 case ETHTOOL_ID_ACTIVE:
2077 adapter->led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2078 return 2;
Auke Kok9a799d72007-09-15 14:07:45 -07002079
Emil Tantilov66e69612011-04-16 06:12:51 +00002080 case ETHTOOL_ID_ON:
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002081 hw->mac.ops.led_on(hw, IXGBE_LED_ON);
Emil Tantilov66e69612011-04-16 06:12:51 +00002082 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002083
Emil Tantilov66e69612011-04-16 06:12:51 +00002084 case ETHTOOL_ID_OFF:
2085 hw->mac.ops.led_off(hw, IXGBE_LED_ON);
2086 break;
2087
2088 case ETHTOOL_ID_INACTIVE:
2089 /* Restore LED settings */
2090 IXGBE_WRITE_REG(&adapter->hw, IXGBE_LEDCTL, adapter->led_reg);
2091 break;
2092 }
Auke Kok9a799d72007-09-15 14:07:45 -07002093
2094 return 0;
2095}
2096
2097static int ixgbe_get_coalesce(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002098 struct ethtool_coalesce *ec)
Auke Kok9a799d72007-09-15 14:07:45 -07002099{
2100 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2101
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002102 /* only valid if in constant ITR mode */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002103 if (adapter->rx_itr_setting <= 1)
2104 ec->rx_coalesce_usecs = adapter->rx_itr_setting;
2105 else
2106 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002107
Shannon Nelsoncfb3f912009-11-24 18:51:06 +00002108 /* if in mixed tx/rx queues per vector mode, report only rx settings */
Alexander Duyck08c88332011-06-11 01:45:03 +00002109 if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count)
Shannon Nelsoncfb3f912009-11-24 18:51:06 +00002110 return 0;
2111
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002112 /* only valid if in constant ITR mode */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002113 if (adapter->tx_itr_setting <= 1)
2114 ec->tx_coalesce_usecs = adapter->tx_itr_setting;
2115 else
2116 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002117
Auke Kok9a799d72007-09-15 14:07:45 -07002118 return 0;
2119}
2120
Alexander Duyck80fba3f2010-11-16 19:26:57 -08002121/*
2122 * this function must be called before setting the new value of
2123 * rx_itr_setting
2124 */
Alexander Duyck567d2de2012-02-11 07:18:57 +00002125static bool ixgbe_update_rsc(struct ixgbe_adapter *adapter)
Alexander Duyck80fba3f2010-11-16 19:26:57 -08002126{
2127 struct net_device *netdev = adapter->netdev;
2128
Alexander Duyck567d2de2012-02-11 07:18:57 +00002129 /* nothing to do if LRO or RSC are not enabled */
2130 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) ||
2131 !(netdev->features & NETIF_F_LRO))
Alexander Duyck80fba3f2010-11-16 19:26:57 -08002132 return false;
2133
Alexander Duyck567d2de2012-02-11 07:18:57 +00002134 /* check the feature flag value and enable RSC if necessary */
2135 if (adapter->rx_itr_setting == 1 ||
2136 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
2137 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
Alexander Duyck80fba3f2010-11-16 19:26:57 -08002138 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Alexander Duyck567d2de2012-02-11 07:18:57 +00002139 e_info(probe, "rx-usecs value high enough "
2140 "to re-enable RSC\n");
Alexander Duyck80fba3f2010-11-16 19:26:57 -08002141 return true;
2142 }
Alexander Duyck567d2de2012-02-11 07:18:57 +00002143 /* if interrupt rate is too high then disable RSC */
2144 } else if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
2145 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
2146 e_info(probe, "rx-usecs set too low, disabling RSC\n");
2147 return true;
Alexander Duyck80fba3f2010-11-16 19:26:57 -08002148 }
2149 return false;
2150}
2151
Auke Kok9a799d72007-09-15 14:07:45 -07002152static int ixgbe_set_coalesce(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002153 struct ethtool_coalesce *ec)
Auke Kok9a799d72007-09-15 14:07:45 -07002154{
2155 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore237057a2009-08-11 13:18:14 +00002156 struct ixgbe_q_vector *q_vector;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002157 int i;
Emil Tantilov67da0972013-01-25 06:19:20 +00002158 u16 tx_itr_param, rx_itr_param, tx_itr_prev;
Jesse Brandeburgef021192010-04-27 01:37:41 +00002159 bool need_reset = false;
Auke Kok9a799d72007-09-15 14:07:45 -07002160
Emil Tantilov67da0972013-01-25 06:19:20 +00002161 if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count) {
2162 /* reject Tx specific changes in case of mixed RxTx vectors */
2163 if (ec->tx_coalesce_usecs)
2164 return -EINVAL;
2165 tx_itr_prev = adapter->rx_itr_setting;
2166 } else {
2167 tx_itr_prev = adapter->tx_itr_setting;
2168 }
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002169
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002170 if ((ec->rx_coalesce_usecs > (IXGBE_MAX_EITR >> 2)) ||
2171 (ec->tx_coalesce_usecs > (IXGBE_MAX_EITR >> 2)))
2172 return -EINVAL;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002173
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002174 if (ec->rx_coalesce_usecs > 1)
2175 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
2176 else
2177 adapter->rx_itr_setting = ec->rx_coalesce_usecs;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002178
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002179 if (adapter->rx_itr_setting == 1)
2180 rx_itr_param = IXGBE_20K_ITR;
2181 else
2182 rx_itr_param = adapter->rx_itr_setting;
Alexander Duyck80fba3f2010-11-16 19:26:57 -08002183
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002184 if (ec->tx_coalesce_usecs > 1)
2185 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
2186 else
2187 adapter->tx_itr_setting = ec->tx_coalesce_usecs;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002188
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002189 if (adapter->tx_itr_setting == 1)
2190 tx_itr_param = IXGBE_10K_ITR;
2191 else
2192 tx_itr_param = adapter->tx_itr_setting;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002193
Emil Tantilov67da0972013-01-25 06:19:20 +00002194 /* mixed Rx/Tx */
2195 if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count)
2196 adapter->tx_itr_setting = adapter->rx_itr_setting;
2197
2198#if IS_ENABLED(CONFIG_BQL)
2199 /* detect ITR changes that require update of TXDCTL.WTHRESH */
2200 if ((adapter->tx_itr_setting > 1) &&
2201 (adapter->tx_itr_setting < IXGBE_100K_ITR)) {
2202 if ((tx_itr_prev == 1) ||
2203 (tx_itr_prev > IXGBE_100K_ITR))
2204 need_reset = true;
2205 } else {
2206 if ((tx_itr_prev > 1) &&
2207 (tx_itr_prev < IXGBE_100K_ITR))
2208 need_reset = true;
2209 }
2210#endif
Alexander Duyck567d2de2012-02-11 07:18:57 +00002211 /* check the old value and enable RSC if necessary */
Emil Tantilov67da0972013-01-25 06:19:20 +00002212 need_reset |= ixgbe_update_rsc(adapter);
Alexander Duyck567d2de2012-02-11 07:18:57 +00002213
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002214 for (i = 0; i < adapter->num_q_vectors; i++) {
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002215 q_vector = adapter->q_vector[i];
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002216 if (q_vector->tx.count && !q_vector->rx.count)
2217 /* tx only */
2218 q_vector->itr = tx_itr_param;
2219 else
2220 /* rx only or mixed */
2221 q_vector->itr = rx_itr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002222 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002223 }
2224
Jesse Brandeburgef021192010-04-27 01:37:41 +00002225 /*
2226 * do reset here at the end to make sure EITR==0 case is handled
2227 * correctly w.r.t stopping tx, and changing TXDCTL.WTHRESH settings
2228 * also locks in RSC enable/disable which requires reset
2229 */
Emil Tantilovc988ee82011-05-13 02:22:45 +00002230 if (need_reset)
2231 ixgbe_do_reset(netdev);
Jesse Brandeburgef021192010-04-27 01:37:41 +00002232
Auke Kok9a799d72007-09-15 14:07:45 -07002233 return 0;
2234}
2235
Alexander Duyck3e053342011-05-11 07:18:47 +00002236static int ixgbe_get_ethtool_fdir_entry(struct ixgbe_adapter *adapter,
2237 struct ethtool_rxnfc *cmd)
2238{
2239 union ixgbe_atr_input *mask = &adapter->fdir_mask;
2240 struct ethtool_rx_flow_spec *fsp =
2241 (struct ethtool_rx_flow_spec *)&cmd->fs;
Sasha Levinb67bfe02013-02-27 17:06:00 -08002242 struct hlist_node *node2;
Alexander Duyck3e053342011-05-11 07:18:47 +00002243 struct ixgbe_fdir_filter *rule = NULL;
2244
2245 /* report total rule count */
2246 cmd->data = (1024 << adapter->fdir_pballoc) - 2;
2247
Sasha Levinb67bfe02013-02-27 17:06:00 -08002248 hlist_for_each_entry_safe(rule, node2,
Alexander Duyck3e053342011-05-11 07:18:47 +00002249 &adapter->fdir_filter_list, fdir_node) {
2250 if (fsp->location <= rule->sw_idx)
2251 break;
2252 }
2253
2254 if (!rule || fsp->location != rule->sw_idx)
2255 return -EINVAL;
2256
2257 /* fill out the flow spec entry */
2258
2259 /* set flow type field */
2260 switch (rule->filter.formatted.flow_type) {
2261 case IXGBE_ATR_FLOW_TYPE_TCPV4:
2262 fsp->flow_type = TCP_V4_FLOW;
2263 break;
2264 case IXGBE_ATR_FLOW_TYPE_UDPV4:
2265 fsp->flow_type = UDP_V4_FLOW;
2266 break;
2267 case IXGBE_ATR_FLOW_TYPE_SCTPV4:
2268 fsp->flow_type = SCTP_V4_FLOW;
2269 break;
2270 case IXGBE_ATR_FLOW_TYPE_IPV4:
2271 fsp->flow_type = IP_USER_FLOW;
2272 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2273 fsp->h_u.usr_ip4_spec.proto = 0;
2274 fsp->m_u.usr_ip4_spec.proto = 0;
2275 break;
2276 default:
2277 return -EINVAL;
2278 }
2279
2280 fsp->h_u.tcp_ip4_spec.psrc = rule->filter.formatted.src_port;
2281 fsp->m_u.tcp_ip4_spec.psrc = mask->formatted.src_port;
2282 fsp->h_u.tcp_ip4_spec.pdst = rule->filter.formatted.dst_port;
2283 fsp->m_u.tcp_ip4_spec.pdst = mask->formatted.dst_port;
2284 fsp->h_u.tcp_ip4_spec.ip4src = rule->filter.formatted.src_ip[0];
2285 fsp->m_u.tcp_ip4_spec.ip4src = mask->formatted.src_ip[0];
2286 fsp->h_u.tcp_ip4_spec.ip4dst = rule->filter.formatted.dst_ip[0];
2287 fsp->m_u.tcp_ip4_spec.ip4dst = mask->formatted.dst_ip[0];
2288 fsp->h_ext.vlan_tci = rule->filter.formatted.vlan_id;
2289 fsp->m_ext.vlan_tci = mask->formatted.vlan_id;
2290 fsp->h_ext.vlan_etype = rule->filter.formatted.flex_bytes;
2291 fsp->m_ext.vlan_etype = mask->formatted.flex_bytes;
2292 fsp->h_ext.data[1] = htonl(rule->filter.formatted.vm_pool);
2293 fsp->m_ext.data[1] = htonl(mask->formatted.vm_pool);
2294 fsp->flow_type |= FLOW_EXT;
2295
2296 /* record action */
2297 if (rule->action == IXGBE_FDIR_DROP_QUEUE)
2298 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2299 else
2300 fsp->ring_cookie = rule->action;
2301
2302 return 0;
2303}
2304
2305static int ixgbe_get_ethtool_fdir_all(struct ixgbe_adapter *adapter,
2306 struct ethtool_rxnfc *cmd,
2307 u32 *rule_locs)
2308{
Sasha Levinb67bfe02013-02-27 17:06:00 -08002309 struct hlist_node *node2;
Alexander Duyck3e053342011-05-11 07:18:47 +00002310 struct ixgbe_fdir_filter *rule;
2311 int cnt = 0;
2312
2313 /* report total rule count */
2314 cmd->data = (1024 << adapter->fdir_pballoc) - 2;
2315
Sasha Levinb67bfe02013-02-27 17:06:00 -08002316 hlist_for_each_entry_safe(rule, node2,
Alexander Duyck3e053342011-05-11 07:18:47 +00002317 &adapter->fdir_filter_list, fdir_node) {
2318 if (cnt == cmd->rule_cnt)
2319 return -EMSGSIZE;
2320 rule_locs[cnt] = rule->sw_idx;
2321 cnt++;
2322 }
2323
Ben Hutchings473e64e2011-09-06 13:52:47 +00002324 cmd->rule_cnt = cnt;
2325
Alexander Duyck3e053342011-05-11 07:18:47 +00002326 return 0;
2327}
2328
Alexander Duyckef6afc02012-02-08 07:51:53 +00002329static int ixgbe_get_rss_hash_opts(struct ixgbe_adapter *adapter,
2330 struct ethtool_rxnfc *cmd)
2331{
2332 cmd->data = 0;
2333
Alexander Duyckef6afc02012-02-08 07:51:53 +00002334 /* Report default options for RSS on ixgbe */
2335 switch (cmd->flow_type) {
2336 case TCP_V4_FLOW:
2337 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2338 case UDP_V4_FLOW:
2339 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
2340 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2341 case SCTP_V4_FLOW:
2342 case AH_ESP_V4_FLOW:
2343 case AH_V4_FLOW:
2344 case ESP_V4_FLOW:
2345 case IPV4_FLOW:
2346 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2347 break;
2348 case TCP_V6_FLOW:
2349 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2350 case UDP_V6_FLOW:
2351 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
2352 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2353 case SCTP_V6_FLOW:
2354 case AH_ESP_V6_FLOW:
2355 case AH_V6_FLOW:
2356 case ESP_V6_FLOW:
2357 case IPV6_FLOW:
2358 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2359 break;
2360 default:
2361 return -EINVAL;
2362 }
2363
2364 return 0;
2365}
2366
Alexander Duyck91cd94b2011-05-11 07:18:41 +00002367static int ixgbe_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
Ben Hutchings815c7db2011-09-06 13:49:12 +00002368 u32 *rule_locs)
Alexander Duyck91cd94b2011-05-11 07:18:41 +00002369{
2370 struct ixgbe_adapter *adapter = netdev_priv(dev);
2371 int ret = -EOPNOTSUPP;
2372
2373 switch (cmd->cmd) {
2374 case ETHTOOL_GRXRINGS:
2375 cmd->data = adapter->num_rx_queues;
2376 ret = 0;
2377 break;
Alexander Duyck3e053342011-05-11 07:18:47 +00002378 case ETHTOOL_GRXCLSRLCNT:
2379 cmd->rule_cnt = adapter->fdir_filter_count;
2380 ret = 0;
2381 break;
2382 case ETHTOOL_GRXCLSRULE:
2383 ret = ixgbe_get_ethtool_fdir_entry(adapter, cmd);
2384 break;
2385 case ETHTOOL_GRXCLSRLALL:
Ben Hutchings815c7db2011-09-06 13:49:12 +00002386 ret = ixgbe_get_ethtool_fdir_all(adapter, cmd, rule_locs);
Alexander Duyck3e053342011-05-11 07:18:47 +00002387 break;
Alexander Duyckef6afc02012-02-08 07:51:53 +00002388 case ETHTOOL_GRXFH:
2389 ret = ixgbe_get_rss_hash_opts(adapter, cmd);
2390 break;
Alexander Duyck91cd94b2011-05-11 07:18:41 +00002391 default:
2392 break;
2393 }
2394
2395 return ret;
2396}
2397
Alexander Duycke4911d52011-05-11 07:18:52 +00002398static int ixgbe_update_ethtool_fdir_entry(struct ixgbe_adapter *adapter,
2399 struct ixgbe_fdir_filter *input,
2400 u16 sw_idx)
2401{
2402 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08002403 struct hlist_node *node2;
2404 struct ixgbe_fdir_filter *rule, *parent;
Alexander Duycke4911d52011-05-11 07:18:52 +00002405 int err = -EINVAL;
2406
2407 parent = NULL;
2408 rule = NULL;
2409
Sasha Levinb67bfe02013-02-27 17:06:00 -08002410 hlist_for_each_entry_safe(rule, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00002411 &adapter->fdir_filter_list, fdir_node) {
2412 /* hash found, or no matching entry */
2413 if (rule->sw_idx >= sw_idx)
2414 break;
Sasha Levinb67bfe02013-02-27 17:06:00 -08002415 parent = rule;
Alexander Duycke4911d52011-05-11 07:18:52 +00002416 }
2417
2418 /* if there is an old rule occupying our place remove it */
2419 if (rule && (rule->sw_idx == sw_idx)) {
2420 if (!input || (rule->filter.formatted.bkt_hash !=
2421 input->filter.formatted.bkt_hash)) {
2422 err = ixgbe_fdir_erase_perfect_filter_82599(hw,
2423 &rule->filter,
2424 sw_idx);
2425 }
2426
2427 hlist_del(&rule->fdir_node);
2428 kfree(rule);
2429 adapter->fdir_filter_count--;
2430 }
2431
2432 /*
2433 * If no input this was a delete, err should be 0 if a rule was
2434 * successfully found and removed from the list else -EINVAL
2435 */
2436 if (!input)
2437 return err;
2438
2439 /* initialize node and set software index */
2440 INIT_HLIST_NODE(&input->fdir_node);
2441
2442 /* add filter to the list */
2443 if (parent)
Sasha Levinb67bfe02013-02-27 17:06:00 -08002444 hlist_add_after(&parent->fdir_node, &input->fdir_node);
Alexander Duycke4911d52011-05-11 07:18:52 +00002445 else
2446 hlist_add_head(&input->fdir_node,
2447 &adapter->fdir_filter_list);
2448
2449 /* update counts */
2450 adapter->fdir_filter_count++;
2451
2452 return 0;
2453}
2454
2455static int ixgbe_flowspec_to_flow_type(struct ethtool_rx_flow_spec *fsp,
2456 u8 *flow_type)
2457{
2458 switch (fsp->flow_type & ~FLOW_EXT) {
2459 case TCP_V4_FLOW:
2460 *flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
2461 break;
2462 case UDP_V4_FLOW:
2463 *flow_type = IXGBE_ATR_FLOW_TYPE_UDPV4;
2464 break;
2465 case SCTP_V4_FLOW:
2466 *flow_type = IXGBE_ATR_FLOW_TYPE_SCTPV4;
2467 break;
2468 case IP_USER_FLOW:
2469 switch (fsp->h_u.usr_ip4_spec.proto) {
2470 case IPPROTO_TCP:
2471 *flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
2472 break;
2473 case IPPROTO_UDP:
2474 *flow_type = IXGBE_ATR_FLOW_TYPE_UDPV4;
2475 break;
2476 case IPPROTO_SCTP:
2477 *flow_type = IXGBE_ATR_FLOW_TYPE_SCTPV4;
2478 break;
2479 case 0:
2480 if (!fsp->m_u.usr_ip4_spec.proto) {
2481 *flow_type = IXGBE_ATR_FLOW_TYPE_IPV4;
2482 break;
2483 }
2484 default:
2485 return 0;
2486 }
2487 break;
2488 default:
2489 return 0;
2490 }
2491
2492 return 1;
2493}
2494
2495static int ixgbe_add_ethtool_fdir_entry(struct ixgbe_adapter *adapter,
2496 struct ethtool_rxnfc *cmd)
2497{
2498 struct ethtool_rx_flow_spec *fsp =
2499 (struct ethtool_rx_flow_spec *)&cmd->fs;
2500 struct ixgbe_hw *hw = &adapter->hw;
2501 struct ixgbe_fdir_filter *input;
2502 union ixgbe_atr_input mask;
2503 int err;
2504
2505 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
2506 return -EOPNOTSUPP;
2507
2508 /*
2509 * Don't allow programming if the action is a queue greater than
2510 * the number of online Rx queues.
2511 */
2512 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2513 (fsp->ring_cookie >= adapter->num_rx_queues))
2514 return -EINVAL;
2515
2516 /* Don't allow indexes to exist outside of available space */
2517 if (fsp->location >= ((1024 << adapter->fdir_pballoc) - 2)) {
2518 e_err(drv, "Location out of range\n");
2519 return -EINVAL;
2520 }
2521
2522 input = kzalloc(sizeof(*input), GFP_ATOMIC);
2523 if (!input)
2524 return -ENOMEM;
2525
2526 memset(&mask, 0, sizeof(union ixgbe_atr_input));
2527
2528 /* set SW index */
2529 input->sw_idx = fsp->location;
2530
2531 /* record flow type */
2532 if (!ixgbe_flowspec_to_flow_type(fsp,
2533 &input->filter.formatted.flow_type)) {
2534 e_err(drv, "Unrecognized flow type\n");
2535 goto err_out;
2536 }
2537
2538 mask.formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
2539 IXGBE_ATR_L4TYPE_MASK;
2540
2541 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
2542 mask.formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
2543
2544 /* Copy input into formatted structures */
2545 input->filter.formatted.src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2546 mask.formatted.src_ip[0] = fsp->m_u.tcp_ip4_spec.ip4src;
2547 input->filter.formatted.dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
2548 mask.formatted.dst_ip[0] = fsp->m_u.tcp_ip4_spec.ip4dst;
2549 input->filter.formatted.src_port = fsp->h_u.tcp_ip4_spec.psrc;
2550 mask.formatted.src_port = fsp->m_u.tcp_ip4_spec.psrc;
2551 input->filter.formatted.dst_port = fsp->h_u.tcp_ip4_spec.pdst;
2552 mask.formatted.dst_port = fsp->m_u.tcp_ip4_spec.pdst;
2553
2554 if (fsp->flow_type & FLOW_EXT) {
2555 input->filter.formatted.vm_pool =
2556 (unsigned char)ntohl(fsp->h_ext.data[1]);
2557 mask.formatted.vm_pool =
2558 (unsigned char)ntohl(fsp->m_ext.data[1]);
2559 input->filter.formatted.vlan_id = fsp->h_ext.vlan_tci;
2560 mask.formatted.vlan_id = fsp->m_ext.vlan_tci;
2561 input->filter.formatted.flex_bytes =
2562 fsp->h_ext.vlan_etype;
2563 mask.formatted.flex_bytes = fsp->m_ext.vlan_etype;
2564 }
2565
2566 /* determine if we need to drop or route the packet */
2567 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2568 input->action = IXGBE_FDIR_DROP_QUEUE;
2569 else
2570 input->action = fsp->ring_cookie;
2571
2572 spin_lock(&adapter->fdir_perfect_lock);
2573
2574 if (hlist_empty(&adapter->fdir_filter_list)) {
2575 /* save mask and program input mask into HW */
2576 memcpy(&adapter->fdir_mask, &mask, sizeof(mask));
2577 err = ixgbe_fdir_set_input_mask_82599(hw, &mask);
2578 if (err) {
2579 e_err(drv, "Error writing mask\n");
2580 goto err_out_w_lock;
2581 }
2582 } else if (memcmp(&adapter->fdir_mask, &mask, sizeof(mask))) {
2583 e_err(drv, "Only one mask supported per port\n");
2584 goto err_out_w_lock;
2585 }
2586
2587 /* apply mask and compute/store hash */
2588 ixgbe_atr_compute_perfect_hash_82599(&input->filter, &mask);
2589
2590 /* program filters to filter memory */
2591 err = ixgbe_fdir_write_perfect_filter_82599(hw,
2592 &input->filter, input->sw_idx,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00002593 (input->action == IXGBE_FDIR_DROP_QUEUE) ?
2594 IXGBE_FDIR_DROP_QUEUE :
Alexander Duycke4911d52011-05-11 07:18:52 +00002595 adapter->rx_ring[input->action]->reg_idx);
2596 if (err)
2597 goto err_out_w_lock;
2598
2599 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
2600
2601 spin_unlock(&adapter->fdir_perfect_lock);
2602
2603 return err;
2604err_out_w_lock:
2605 spin_unlock(&adapter->fdir_perfect_lock);
2606err_out:
2607 kfree(input);
2608 return -EINVAL;
2609}
2610
2611static int ixgbe_del_ethtool_fdir_entry(struct ixgbe_adapter *adapter,
2612 struct ethtool_rxnfc *cmd)
2613{
2614 struct ethtool_rx_flow_spec *fsp =
2615 (struct ethtool_rx_flow_spec *)&cmd->fs;
2616 int err;
2617
2618 spin_lock(&adapter->fdir_perfect_lock);
2619 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, fsp->location);
2620 spin_unlock(&adapter->fdir_perfect_lock);
2621
2622 return err;
2623}
2624
Alexander Duyckef6afc02012-02-08 07:51:53 +00002625#define UDP_RSS_FLAGS (IXGBE_FLAG2_RSS_FIELD_IPV4_UDP | \
2626 IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
2627static int ixgbe_set_rss_hash_opt(struct ixgbe_adapter *adapter,
2628 struct ethtool_rxnfc *nfc)
2629{
2630 u32 flags2 = adapter->flags2;
2631
2632 /*
2633 * RSS does not support anything other than hashing
2634 * to queues on src and dst IPs and ports
2635 */
2636 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2637 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2638 return -EINVAL;
2639
2640 switch (nfc->flow_type) {
2641 case TCP_V4_FLOW:
2642 case TCP_V6_FLOW:
2643 if (!(nfc->data & RXH_IP_SRC) ||
2644 !(nfc->data & RXH_IP_DST) ||
2645 !(nfc->data & RXH_L4_B_0_1) ||
2646 !(nfc->data & RXH_L4_B_2_3))
2647 return -EINVAL;
2648 break;
2649 case UDP_V4_FLOW:
2650 if (!(nfc->data & RXH_IP_SRC) ||
2651 !(nfc->data & RXH_IP_DST))
2652 return -EINVAL;
2653 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2654 case 0:
2655 flags2 &= ~IXGBE_FLAG2_RSS_FIELD_IPV4_UDP;
2656 break;
2657 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2658 flags2 |= IXGBE_FLAG2_RSS_FIELD_IPV4_UDP;
2659 break;
2660 default:
2661 return -EINVAL;
2662 }
2663 break;
2664 case UDP_V6_FLOW:
2665 if (!(nfc->data & RXH_IP_SRC) ||
2666 !(nfc->data & RXH_IP_DST))
2667 return -EINVAL;
2668 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2669 case 0:
2670 flags2 &= ~IXGBE_FLAG2_RSS_FIELD_IPV6_UDP;
2671 break;
2672 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2673 flags2 |= IXGBE_FLAG2_RSS_FIELD_IPV6_UDP;
2674 break;
2675 default:
2676 return -EINVAL;
2677 }
2678 break;
2679 case AH_ESP_V4_FLOW:
2680 case AH_V4_FLOW:
2681 case ESP_V4_FLOW:
2682 case SCTP_V4_FLOW:
2683 case AH_ESP_V6_FLOW:
2684 case AH_V6_FLOW:
2685 case ESP_V6_FLOW:
2686 case SCTP_V6_FLOW:
2687 if (!(nfc->data & RXH_IP_SRC) ||
2688 !(nfc->data & RXH_IP_DST) ||
2689 (nfc->data & RXH_L4_B_0_1) ||
2690 (nfc->data & RXH_L4_B_2_3))
2691 return -EINVAL;
2692 break;
2693 default:
2694 return -EINVAL;
2695 }
2696
2697 /* if we changed something we need to update flags */
2698 if (flags2 != adapter->flags2) {
2699 struct ixgbe_hw *hw = &adapter->hw;
2700 u32 mrqc = IXGBE_READ_REG(hw, IXGBE_MRQC);
2701
2702 if ((flags2 & UDP_RSS_FLAGS) &&
2703 !(adapter->flags2 & UDP_RSS_FLAGS))
2704 e_warn(drv, "enabling UDP RSS: fragmented packets"
2705 " may arrive out of order to the stack above\n");
2706
2707 adapter->flags2 = flags2;
2708
2709 /* Perform hash on these packet types */
2710 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2711 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2712 | IXGBE_MRQC_RSS_FIELD_IPV6
2713 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2714
2715 mrqc &= ~(IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
2716 IXGBE_MRQC_RSS_FIELD_IPV6_UDP);
2717
2718 if (flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
2719 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
2720
2721 if (flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
2722 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
2723
2724 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
2725 }
2726
2727 return 0;
2728}
2729
Alexander Duycke4911d52011-05-11 07:18:52 +00002730static int ixgbe_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
2731{
2732 struct ixgbe_adapter *adapter = netdev_priv(dev);
2733 int ret = -EOPNOTSUPP;
2734
2735 switch (cmd->cmd) {
2736 case ETHTOOL_SRXCLSRLINS:
2737 ret = ixgbe_add_ethtool_fdir_entry(adapter, cmd);
2738 break;
2739 case ETHTOOL_SRXCLSRLDEL:
2740 ret = ixgbe_del_ethtool_fdir_entry(adapter, cmd);
2741 break;
Alexander Duyckef6afc02012-02-08 07:51:53 +00002742 case ETHTOOL_SRXFH:
2743 ret = ixgbe_set_rss_hash_opt(adapter, cmd);
2744 break;
Alexander Duycke4911d52011-05-11 07:18:52 +00002745 default:
2746 break;
2747 }
2748
2749 return ret;
2750}
2751
Jacob Kellere3aac882012-05-04 02:56:12 +00002752static int ixgbe_get_ts_info(struct net_device *dev,
2753 struct ethtool_ts_info *info)
2754{
2755 struct ixgbe_adapter *adapter = netdev_priv(dev);
2756
2757 switch (adapter->hw.mac.type) {
Jacob Kellere3aac882012-05-04 02:56:12 +00002758 case ixgbe_mac_X540:
2759 case ixgbe_mac_82599EB:
2760 info->so_timestamping =
Jacob Keller50f8d352012-10-31 22:30:54 +00002761 SOF_TIMESTAMPING_TX_SOFTWARE |
2762 SOF_TIMESTAMPING_RX_SOFTWARE |
2763 SOF_TIMESTAMPING_SOFTWARE |
Jacob Kellere3aac882012-05-04 02:56:12 +00002764 SOF_TIMESTAMPING_TX_HARDWARE |
2765 SOF_TIMESTAMPING_RX_HARDWARE |
2766 SOF_TIMESTAMPING_RAW_HARDWARE;
2767
2768 if (adapter->ptp_clock)
2769 info->phc_index = ptp_clock_index(adapter->ptp_clock);
2770 else
2771 info->phc_index = -1;
2772
2773 info->tx_types =
2774 (1 << HWTSTAMP_TX_OFF) |
2775 (1 << HWTSTAMP_TX_ON);
2776
2777 info->rx_filters =
2778 (1 << HWTSTAMP_FILTER_NONE) |
2779 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2780 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
Jacob Kelleraeb82642012-11-15 01:10:37 +00002781 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
2782 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
2783 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
2784 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
2785 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
2786 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
2787 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
2788 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
Jacob Keller1cc92eb2012-09-21 07:23:20 +00002789 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellere3aac882012-05-04 02:56:12 +00002790 break;
Jacob Kellere3aac882012-05-04 02:56:12 +00002791 default:
2792 return ethtool_op_get_ts_info(dev, info);
2793 break;
2794 }
2795 return 0;
2796}
2797
Alexander Duyck5348c9d2013-01-12 06:33:52 +00002798static unsigned int ixgbe_max_channels(struct ixgbe_adapter *adapter)
2799{
2800 unsigned int max_combined;
2801 u8 tcs = netdev_get_num_tc(adapter->netdev);
2802
2803 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2804 /* We only support one q_vector without MSI-X */
2805 max_combined = 1;
2806 } else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2807 /* SR-IOV currently only allows one queue on the PF */
2808 max_combined = 1;
2809 } else if (tcs > 1) {
2810 /* For DCB report channels per traffic class */
2811 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2812 /* 8 TC w/ 4 queues per TC */
2813 max_combined = 4;
2814 } else if (tcs > 4) {
2815 /* 8 TC w/ 8 queues per TC */
2816 max_combined = 8;
2817 } else {
2818 /* 4 TC w/ 16 queues per TC */
2819 max_combined = 16;
2820 }
2821 } else if (adapter->atr_sample_rate) {
2822 /* support up to 64 queues with ATR */
2823 max_combined = IXGBE_MAX_FDIR_INDICES;
2824 } else {
2825 /* support up to 16 queues with RSS */
2826 max_combined = IXGBE_MAX_RSS_INDICES;
2827 }
2828
2829 return max_combined;
2830}
2831
2832static void ixgbe_get_channels(struct net_device *dev,
2833 struct ethtool_channels *ch)
2834{
2835 struct ixgbe_adapter *adapter = netdev_priv(dev);
2836
2837 /* report maximum channels */
2838 ch->max_combined = ixgbe_max_channels(adapter);
2839
2840 /* report info for other vector */
2841 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2842 ch->max_other = NON_Q_VECTORS;
2843 ch->other_count = NON_Q_VECTORS;
2844 }
2845
2846 /* record RSS queues */
2847 ch->combined_count = adapter->ring_feature[RING_F_RSS].indices;
2848
2849 /* nothing else to report if RSS is disabled */
2850 if (ch->combined_count == 1)
2851 return;
2852
2853 /* we do not support ATR queueing if SR-IOV is enabled */
2854 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
2855 return;
2856
2857 /* same thing goes for being DCB enabled */
2858 if (netdev_get_num_tc(dev) > 1)
2859 return;
2860
2861 /* if ATR is disabled we can exit */
2862 if (!adapter->atr_sample_rate)
2863 return;
2864
2865 /* report flow director queues as maximum channels */
2866 ch->combined_count = adapter->ring_feature[RING_F_FDIR].indices;
2867}
2868
Alexander Duyck4c696ca2013-01-17 08:39:33 +00002869static int ixgbe_set_channels(struct net_device *dev,
2870 struct ethtool_channels *ch)
2871{
2872 struct ixgbe_adapter *adapter = netdev_priv(dev);
2873 unsigned int count = ch->combined_count;
2874
2875 /* verify they are not requesting separate vectors */
2876 if (!count || ch->rx_count || ch->tx_count)
2877 return -EINVAL;
2878
2879 /* verify other_count has not changed */
2880 if (ch->other_count != NON_Q_VECTORS)
2881 return -EINVAL;
2882
2883 /* verify the number of channels does not exceed hardware limits */
2884 if (count > ixgbe_max_channels(adapter))
2885 return -EINVAL;
2886
2887 /* update feature limits from largest to smallest supported values */
2888 adapter->ring_feature[RING_F_FDIR].limit = count;
2889
2890 /* cap RSS limit at 16 */
2891 if (count > IXGBE_MAX_RSS_INDICES)
2892 count = IXGBE_MAX_RSS_INDICES;
2893 adapter->ring_feature[RING_F_RSS].limit = count;
2894
2895#ifdef IXGBE_FCOE
2896 /* cap FCoE limit at 8 */
2897 if (count > IXGBE_FCRETA_SIZE)
2898 count = IXGBE_FCRETA_SIZE;
2899 adapter->ring_feature[RING_F_FCOE].limit = count;
2900
2901#endif
2902 /* use setup TC to update any traffic class queue mapping */
2903 return ixgbe_setup_tc(dev, netdev_get_num_tc(dev));
2904}
2905
Aurélien Guillaume71858ac2013-01-17 06:55:24 +00002906static int ixgbe_get_module_info(struct net_device *dev,
2907 struct ethtool_modinfo *modinfo)
2908{
2909 struct ixgbe_adapter *adapter = netdev_priv(dev);
2910 struct ixgbe_hw *hw = &adapter->hw;
2911 u32 status;
2912 u8 sff8472_rev, addr_mode;
2913 int ret_val = 0;
2914 bool page_swap = false;
2915
2916 /* avoid concurent i2c reads */
2917 while (test_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
2918 msleep(100);
2919
2920 /* used by the service task */
2921 set_bit(__IXGBE_READ_I2C, &adapter->state);
2922
2923 /* Check whether we support SFF-8472 or not */
2924 status = hw->phy.ops.read_i2c_eeprom(hw,
2925 IXGBE_SFF_SFF_8472_COMP,
2926 &sff8472_rev);
2927 if (status != 0) {
2928 ret_val = -EIO;
2929 goto err_out;
2930 }
2931
2932 /* addressing mode is not supported */
2933 status = hw->phy.ops.read_i2c_eeprom(hw,
2934 IXGBE_SFF_SFF_8472_SWAP,
2935 &addr_mode);
2936 if (status != 0) {
2937 ret_val = -EIO;
2938 goto err_out;
2939 }
2940
2941 if (addr_mode & IXGBE_SFF_ADDRESSING_MODE) {
2942 e_err(drv, "Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n");
2943 page_swap = true;
2944 }
2945
2946 if (sff8472_rev == IXGBE_SFF_SFF_8472_UNSUP || page_swap) {
2947 /* We have a SFP, but it does not support SFF-8472 */
2948 modinfo->type = ETH_MODULE_SFF_8079;
2949 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
2950 } else {
2951 /* We have a SFP which supports a revision of SFF-8472. */
2952 modinfo->type = ETH_MODULE_SFF_8472;
2953 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
2954 }
2955
2956err_out:
2957 clear_bit(__IXGBE_READ_I2C, &adapter->state);
2958 return ret_val;
2959}
2960
2961static int ixgbe_get_module_eeprom(struct net_device *dev,
2962 struct ethtool_eeprom *ee,
2963 u8 *data)
2964{
2965 struct ixgbe_adapter *adapter = netdev_priv(dev);
2966 struct ixgbe_hw *hw = &adapter->hw;
2967 u32 status = IXGBE_ERR_PHY_ADDR_INVALID;
2968 u8 databyte = 0xFF;
2969 int i = 0;
2970 int ret_val = 0;
2971
2972 /* ixgbe_get_module_info is called before this function in all
2973 * cases, so we do not need any checks we already do above,
2974 * and can trust ee->len to be a known value.
2975 */
2976
2977 while (test_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
2978 msleep(100);
2979 set_bit(__IXGBE_READ_I2C, &adapter->state);
2980
2981 /* Read the first block, SFF-8079 */
2982 for (i = 0; i < ETH_MODULE_SFF_8079_LEN; i++) {
2983 status = hw->phy.ops.read_i2c_eeprom(hw, i, &databyte);
2984 if (status != 0) {
2985 /* Error occured while reading module */
2986 ret_val = -EIO;
2987 goto err_out;
2988 }
2989 data[i] = databyte;
2990 }
2991
2992 /* If the second block is requested, check if SFF-8472 is supported. */
2993 if (ee->len == ETH_MODULE_SFF_8472_LEN) {
2994 if (data[IXGBE_SFF_SFF_8472_COMP] == IXGBE_SFF_SFF_8472_UNSUP)
2995 return -EOPNOTSUPP;
2996
2997 /* Read the second block, SFF-8472 */
2998 for (i = ETH_MODULE_SFF_8079_LEN;
2999 i < ETH_MODULE_SFF_8472_LEN; i++) {
3000 status = hw->phy.ops.read_i2c_sff8472(hw,
3001 i - ETH_MODULE_SFF_8079_LEN, &databyte);
3002 if (status != 0) {
3003 /* Error occured while reading module */
3004 ret_val = -EIO;
3005 goto err_out;
3006 }
3007 data[i] = databyte;
3008 }
3009 }
3010
3011err_out:
3012 clear_bit(__IXGBE_READ_I2C, &adapter->state);
3013
3014 return ret_val;
3015}
3016
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003017static const struct ethtool_ops ixgbe_ethtool_ops = {
Auke Kok9a799d72007-09-15 14:07:45 -07003018 .get_settings = ixgbe_get_settings,
3019 .set_settings = ixgbe_set_settings,
3020 .get_drvinfo = ixgbe_get_drvinfo,
3021 .get_regs_len = ixgbe_get_regs_len,
3022 .get_regs = ixgbe_get_regs,
3023 .get_wol = ixgbe_get_wol,
PJ Waskiewicze63d9762009-03-19 01:23:46 +00003024 .set_wol = ixgbe_set_wol,
Auke Kok9a799d72007-09-15 14:07:45 -07003025 .nway_reset = ixgbe_nway_reset,
3026 .get_link = ethtool_op_get_link,
3027 .get_eeprom_len = ixgbe_get_eeprom_len,
3028 .get_eeprom = ixgbe_get_eeprom,
Emil Tantilov2fa5eef2011-10-06 08:57:04 +00003029 .set_eeprom = ixgbe_set_eeprom,
Auke Kok9a799d72007-09-15 14:07:45 -07003030 .get_ringparam = ixgbe_get_ringparam,
3031 .set_ringparam = ixgbe_set_ringparam,
3032 .get_pauseparam = ixgbe_get_pauseparam,
3033 .set_pauseparam = ixgbe_set_pauseparam,
Auke Kok9a799d72007-09-15 14:07:45 -07003034 .get_msglevel = ixgbe_get_msglevel,
3035 .set_msglevel = ixgbe_set_msglevel,
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003036 .self_test = ixgbe_diag_test,
Auke Kok9a799d72007-09-15 14:07:45 -07003037 .get_strings = ixgbe_get_strings,
Emil Tantilov66e69612011-04-16 06:12:51 +00003038 .set_phys_id = ixgbe_set_phys_id,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003039 .get_sset_count = ixgbe_get_sset_count,
Auke Kok9a799d72007-09-15 14:07:45 -07003040 .get_ethtool_stats = ixgbe_get_ethtool_stats,
3041 .get_coalesce = ixgbe_get_coalesce,
3042 .set_coalesce = ixgbe_set_coalesce,
Alexander Duyck91cd94b2011-05-11 07:18:41 +00003043 .get_rxnfc = ixgbe_get_rxnfc,
Alexander Duycke4911d52011-05-11 07:18:52 +00003044 .set_rxnfc = ixgbe_set_rxnfc,
Alexander Duyck5348c9d2013-01-12 06:33:52 +00003045 .get_channels = ixgbe_get_channels,
Alexander Duyck4c696ca2013-01-17 08:39:33 +00003046 .set_channels = ixgbe_set_channels,
Jacob Kellere3aac882012-05-04 02:56:12 +00003047 .get_ts_info = ixgbe_get_ts_info,
Aurélien Guillaume71858ac2013-01-17 06:55:24 +00003048 .get_module_info = ixgbe_get_module_info,
3049 .get_module_eeprom = ixgbe_get_module_eeprom,
Auke Kok9a799d72007-09-15 14:07:45 -07003050};
3051
3052void ixgbe_set_ethtool_ops(struct net_device *netdev)
3053{
3054 SET_ETHTOOL_OPS(netdev, &ixgbe_ethtool_ops);
3055}