blob: 7da37581bc02184d11e16695873f2f97051fa47e [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Greg Rosedc641b72013-12-18 13:45:51 +00004 * Copyright(c) 2013 - 2014 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
43#define I40E_NETDEV_STAT(_net_stat) \
44 I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
45#define I40E_PF_STAT(_name, _stat) \
46 I40E_STAT(struct i40e_pf, _name, _stat)
47#define I40E_VSI_STAT(_name, _stat) \
48 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000049#define I40E_VEB_STAT(_name, _stat) \
50 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000051
52static const struct i40e_stats i40e_gstrings_net_stats[] = {
53 I40E_NETDEV_STAT(rx_packets),
54 I40E_NETDEV_STAT(tx_packets),
55 I40E_NETDEV_STAT(rx_bytes),
56 I40E_NETDEV_STAT(tx_bytes),
57 I40E_NETDEV_STAT(rx_errors),
58 I40E_NETDEV_STAT(tx_errors),
59 I40E_NETDEV_STAT(rx_dropped),
60 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000061 I40E_NETDEV_STAT(collisions),
62 I40E_NETDEV_STAT(rx_length_errors),
63 I40E_NETDEV_STAT(rx_crc_errors),
64};
65
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000066static const struct i40e_stats i40e_gstrings_veb_stats[] = {
67 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
68 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
69 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
70 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
71 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
72 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
73 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
74 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
75 I40E_VEB_STAT("rx_discards", stats.rx_discards),
76 I40E_VEB_STAT("tx_discards", stats.tx_discards),
77 I40E_VEB_STAT("tx_errors", stats.tx_errors),
78 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
79};
80
Shannon Nelson41a9e552014-04-23 04:50:20 +000081static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000082 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
83 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
84 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
85 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000086 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
87 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000088 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Shannon Nelson41a9e552014-04-23 04:50:20 +000089};
90
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000091static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
92 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000093
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000094/* These PF_STATs might look like duplicates of some NETDEV_STATs,
95 * but they are separate. This device supports Virtualization, and
96 * as such might have several netdevs supporting VMDq and FCoE going
97 * through a single port. The NETDEV_STATs are for individual netdevs
98 * seen at the top of the stack, and the PF_STATs are for the physical
99 * function at the bottom of the stack hosting those netdevs.
100 *
101 * The PF_STATs are appended to the netdev stats only when ethtool -S
102 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
103 */
104static struct i40e_stats i40e_gstrings_stats[] = {
105 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
106 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000107 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
108 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
109 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
110 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
111 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
112 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000113 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
114 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
115 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
116 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
117 I40E_PF_STAT("crc_errors", stats.crc_errors),
118 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
119 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
120 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000121 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000122 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000123 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
124 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
125 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
126 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
127 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
128 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
129 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
130 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
131 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
132 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
133 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
134 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
135 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
136 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
137 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
138 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
139 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
140 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
141 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
142 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
143 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
144 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
145 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
146 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000148 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
149 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
150
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000151 /* LPI stats */
152 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
153 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
154 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
155 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000156};
157
158#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000159 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
160 * 2 /* Tx and Rx together */ \
161 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000162#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
163#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000164#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000165#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000166 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000167 I40E_QUEUE_STATS_LEN((n)))
168#define I40E_PFC_STATS_LEN ( \
169 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
170 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
171 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
172 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
173 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
174 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000175#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
177 I40E_PFC_STATS_LEN + \
178 I40E_VSI_STATS_LEN((n)))
179
180enum i40e_ethtool_test_id {
181 I40E_ETH_TEST_REG = 0,
182 I40E_ETH_TEST_EEPROM,
183 I40E_ETH_TEST_INTR,
184 I40E_ETH_TEST_LOOPBACK,
185 I40E_ETH_TEST_LINK,
186};
187
188static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
189 "Register test (offline)",
190 "Eeprom test (offline)",
191 "Interrupt test (offline)",
192 "Loopback test (offline)",
193 "Link test (on/offline)"
194};
195
196#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
197
198/**
199 * i40e_get_settings - Get Link Speed and Duplex settings
200 * @netdev: network interface device structure
201 * @ecmd: ethtool command
202 *
203 * Reports speed/duplex settings based on media_type
204 **/
205static int i40e_get_settings(struct net_device *netdev,
206 struct ethtool_cmd *ecmd)
207{
208 struct i40e_netdev_priv *np = netdev_priv(netdev);
209 struct i40e_pf *pf = np->vsi->back;
210 struct i40e_hw *hw = &pf->hw;
211 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
212 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
213 u32 link_speed = hw_link_info->link_speed;
214
215 /* hardware is either in 40G mode or 10G mode
216 * NOTE: this section initializes supported and advertising
217 */
218 switch (hw_link_info->phy_type) {
219 case I40E_PHY_TYPE_40GBASE_CR4:
220 case I40E_PHY_TYPE_40GBASE_CR4_CU:
221 ecmd->supported = SUPPORTED_40000baseCR4_Full;
222 ecmd->advertising = ADVERTISED_40000baseCR4_Full;
223 break;
224 case I40E_PHY_TYPE_40GBASE_KR4:
225 ecmd->supported = SUPPORTED_40000baseKR4_Full;
226 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
227 break;
228 case I40E_PHY_TYPE_40GBASE_SR4:
229 ecmd->supported = SUPPORTED_40000baseSR4_Full;
230 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
231 break;
232 case I40E_PHY_TYPE_40GBASE_LR4:
233 ecmd->supported = SUPPORTED_40000baseLR4_Full;
234 ecmd->advertising = ADVERTISED_40000baseLR4_Full;
235 break;
236 case I40E_PHY_TYPE_10GBASE_KX4:
237 ecmd->supported = SUPPORTED_10000baseKX4_Full;
238 ecmd->advertising = ADVERTISED_10000baseKX4_Full;
239 break;
240 case I40E_PHY_TYPE_10GBASE_KR:
241 ecmd->supported = SUPPORTED_10000baseKR_Full;
242 ecmd->advertising = ADVERTISED_10000baseKR_Full;
243 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000244 default:
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000245 if (i40e_is_40G_device(hw->device_id)) {
246 ecmd->supported = SUPPORTED_40000baseSR4_Full;
247 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
248 } else {
249 ecmd->supported = SUPPORTED_10000baseT_Full;
250 ecmd->advertising = ADVERTISED_10000baseT_Full;
251 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 break;
253 }
254
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000255 ecmd->supported |= SUPPORTED_Autoneg;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000256 ecmd->advertising |= ADVERTISED_Autoneg;
257 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
258 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000260 switch (hw->phy.media_type) {
261 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000262 ecmd->supported |= SUPPORTED_Backplane;
263 ecmd->advertising |= ADVERTISED_Backplane;
264 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000265 break;
266 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000267 ecmd->supported |= SUPPORTED_TP;
268 ecmd->advertising |= ADVERTISED_TP;
269 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000270 break;
271 case I40E_MEDIA_TYPE_DA:
272 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000273 ecmd->supported |= SUPPORTED_FIBRE;
274 ecmd->advertising |= ADVERTISED_FIBRE;
275 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000276 break;
277 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000278 ecmd->supported |= SUPPORTED_FIBRE;
279 ecmd->advertising |= ADVERTISED_FIBRE;
280 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000281 break;
282 case I40E_MEDIA_TYPE_UNKNOWN:
283 default:
284 ecmd->port = PORT_OTHER;
285 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000286 }
287
288 ecmd->transceiver = XCVR_EXTERNAL;
289
290 if (link_up) {
291 switch (link_speed) {
292 case I40E_LINK_SPEED_40GB:
293 /* need a SPEED_40000 in ethtool.h */
294 ethtool_cmd_speed_set(ecmd, 40000);
295 break;
296 case I40E_LINK_SPEED_10GB:
297 ethtool_cmd_speed_set(ecmd, SPEED_10000);
298 break;
299 default:
300 break;
301 }
302 ecmd->duplex = DUPLEX_FULL;
303 } else {
304 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
305 ecmd->duplex = DUPLEX_UNKNOWN;
306 }
307
308 return 0;
309}
310
311/**
312 * i40e_get_pauseparam - Get Flow Control status
313 * Return tx/rx-pause status
314 **/
315static void i40e_get_pauseparam(struct net_device *netdev,
316 struct ethtool_pauseparam *pause)
317{
318 struct i40e_netdev_priv *np = netdev_priv(netdev);
319 struct i40e_pf *pf = np->vsi->back;
320 struct i40e_hw *hw = &pf->hw;
321 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
322
323 pause->autoneg =
324 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
325 AUTONEG_ENABLE : AUTONEG_DISABLE);
326
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000327 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000328 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000329 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000330 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000331 } else if (hw->fc.current_mode == I40E_FC_FULL) {
332 pause->rx_pause = 1;
333 pause->tx_pause = 1;
334 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000335}
336
337static u32 i40e_get_msglevel(struct net_device *netdev)
338{
339 struct i40e_netdev_priv *np = netdev_priv(netdev);
340 struct i40e_pf *pf = np->vsi->back;
341
342 return pf->msg_enable;
343}
344
345static void i40e_set_msglevel(struct net_device *netdev, u32 data)
346{
347 struct i40e_netdev_priv *np = netdev_priv(netdev);
348 struct i40e_pf *pf = np->vsi->back;
349
350 if (I40E_DEBUG_USER & data)
351 pf->hw.debug_mask = data;
352 pf->msg_enable = data;
353}
354
355static int i40e_get_regs_len(struct net_device *netdev)
356{
357 int reg_count = 0;
358 int i;
359
360 for (i = 0; i40e_reg_list[i].offset != 0; i++)
361 reg_count += i40e_reg_list[i].elements;
362
363 return reg_count * sizeof(u32);
364}
365
366static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
367 void *p)
368{
369 struct i40e_netdev_priv *np = netdev_priv(netdev);
370 struct i40e_pf *pf = np->vsi->back;
371 struct i40e_hw *hw = &pf->hw;
372 u32 *reg_buf = p;
373 int i, j, ri;
374 u32 reg;
375
376 /* Tell ethtool which driver-version-specific regs output we have.
377 *
378 * At some point, if we have ethtool doing special formatting of
379 * this data, it will rely on this version number to know how to
380 * interpret things. Hence, this needs to be updated if/when the
381 * diags register table is changed.
382 */
383 regs->version = 1;
384
385 /* loop through the diags reg table for what to print */
386 ri = 0;
387 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
388 for (j = 0; j < i40e_reg_list[i].elements; j++) {
389 reg = i40e_reg_list[i].offset
390 + (j * i40e_reg_list[i].stride);
391 reg_buf[ri++] = rd32(hw, reg);
392 }
393 }
394
395}
396
397static int i40e_get_eeprom(struct net_device *netdev,
398 struct ethtool_eeprom *eeprom, u8 *bytes)
399{
400 struct i40e_netdev_priv *np = netdev_priv(netdev);
401 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000402 struct i40e_pf *pf = np->vsi->back;
403 int ret_val = 0, len;
404 u8 *eeprom_buff;
405 u16 i, sectors;
406 bool last;
407#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000408 if (eeprom->len == 0)
409 return -EINVAL;
410
411 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
412
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000413 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000414 if (!eeprom_buff)
415 return -ENOMEM;
416
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000417 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
418 if (ret_val) {
419 dev_info(&pf->pdev->dev,
420 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
421 ret_val, hw->aq.asq_last_status);
422 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000423 }
424
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000425 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
426 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
427 len = I40E_NVM_SECTOR_SIZE;
428 last = false;
429 for (i = 0; i < sectors; i++) {
430 if (i == (sectors - 1)) {
431 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
432 last = true;
433 }
434 ret_val = i40e_aq_read_nvm(hw, 0x0,
435 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
436 len,
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000437 eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000438 last, NULL);
439 if (ret_val) {
440 dev_info(&pf->pdev->dev,
441 "read NVM failed err=%d status=0x%x\n",
442 ret_val, hw->aq.asq_last_status);
443 goto release_nvm;
444 }
445 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000446
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000447release_nvm:
448 i40e_release_nvm(hw);
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000449 memcpy(bytes, eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000450free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000451 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000452 return ret_val;
453}
454
455static int i40e_get_eeprom_len(struct net_device *netdev)
456{
457 struct i40e_netdev_priv *np = netdev_priv(netdev);
458 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000459 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000460
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000461 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
462 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
463 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
464 /* register returns value in power of 2, 64Kbyte chunks. */
465 val = (64 * 1024) * (1 << val);
466 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000467}
468
469static void i40e_get_drvinfo(struct net_device *netdev,
470 struct ethtool_drvinfo *drvinfo)
471{
472 struct i40e_netdev_priv *np = netdev_priv(netdev);
473 struct i40e_vsi *vsi = np->vsi;
474 struct i40e_pf *pf = vsi->back;
475
476 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
477 strlcpy(drvinfo->version, i40e_driver_version_str,
478 sizeof(drvinfo->version));
479 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
480 sizeof(drvinfo->fw_version));
481 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
482 sizeof(drvinfo->bus_info));
483}
484
485static void i40e_get_ringparam(struct net_device *netdev,
486 struct ethtool_ringparam *ring)
487{
488 struct i40e_netdev_priv *np = netdev_priv(netdev);
489 struct i40e_pf *pf = np->vsi->back;
490 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
491
492 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
493 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
494 ring->rx_mini_max_pending = 0;
495 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000496 ring->rx_pending = vsi->rx_rings[0]->count;
497 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000498 ring->rx_mini_pending = 0;
499 ring->rx_jumbo_pending = 0;
500}
501
502static int i40e_set_ringparam(struct net_device *netdev,
503 struct ethtool_ringparam *ring)
504{
505 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
506 struct i40e_netdev_priv *np = netdev_priv(netdev);
507 struct i40e_vsi *vsi = np->vsi;
508 struct i40e_pf *pf = vsi->back;
509 u32 new_rx_count, new_tx_count;
510 int i, err = 0;
511
512 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
513 return -EINVAL;
514
Shannon Nelson1fa18372013-11-20 10:03:08 +0000515 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
516 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
517 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
518 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
519 netdev_info(netdev,
520 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
521 ring->tx_pending, ring->rx_pending,
522 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
523 return -EINVAL;
524 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000525
Shannon Nelson1fa18372013-11-20 10:03:08 +0000526 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
527 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000528
529 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000530 if ((new_tx_count == vsi->tx_rings[0]->count) &&
531 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000532 return 0;
533
534 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
535 usleep_range(1000, 2000);
536
537 if (!netif_running(vsi->netdev)) {
538 /* simple case - set for the next time the netdev is started */
539 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000540 vsi->tx_rings[i]->count = new_tx_count;
541 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000542 }
543 goto done;
544 }
545
546 /* We can't just free everything and then setup again,
547 * because the ISRs in MSI-X mode get passed pointers
548 * to the Tx and Rx ring structs.
549 */
550
551 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000552 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000553 netdev_info(netdev,
554 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000555 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000556 tx_rings = kcalloc(vsi->alloc_queue_pairs,
557 sizeof(struct i40e_ring), GFP_KERNEL);
558 if (!tx_rings) {
559 err = -ENOMEM;
560 goto done;
561 }
562
563 for (i = 0; i < vsi->num_queue_pairs; i++) {
564 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000565 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000566 tx_rings[i].count = new_tx_count;
567 err = i40e_setup_tx_descriptors(&tx_rings[i]);
568 if (err) {
569 while (i) {
570 i--;
571 i40e_free_tx_resources(&tx_rings[i]);
572 }
573 kfree(tx_rings);
574 tx_rings = NULL;
575
576 goto done;
577 }
578 }
579 }
580
581 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000582 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000583 netdev_info(netdev,
584 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000585 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000586 rx_rings = kcalloc(vsi->alloc_queue_pairs,
587 sizeof(struct i40e_ring), GFP_KERNEL);
588 if (!rx_rings) {
589 err = -ENOMEM;
590 goto free_tx;
591 }
592
593 for (i = 0; i < vsi->num_queue_pairs; i++) {
594 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000595 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000596 rx_rings[i].count = new_rx_count;
597 err = i40e_setup_rx_descriptors(&rx_rings[i]);
598 if (err) {
599 while (i) {
600 i--;
601 i40e_free_rx_resources(&rx_rings[i]);
602 }
603 kfree(rx_rings);
604 rx_rings = NULL;
605
606 goto free_tx;
607 }
608 }
609 }
610
611 /* Bring interface down, copy in the new ring info,
612 * then restore the interface
613 */
614 i40e_down(vsi);
615
616 if (tx_rings) {
617 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000618 i40e_free_tx_resources(vsi->tx_rings[i]);
619 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000620 }
621 kfree(tx_rings);
622 tx_rings = NULL;
623 }
624
625 if (rx_rings) {
626 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000627 i40e_free_rx_resources(vsi->rx_rings[i]);
628 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000629 }
630 kfree(rx_rings);
631 rx_rings = NULL;
632 }
633
634 i40e_up(vsi);
635
636free_tx:
637 /* error cleanup if the Rx allocations failed after getting Tx */
638 if (tx_rings) {
639 for (i = 0; i < vsi->num_queue_pairs; i++)
640 i40e_free_tx_resources(&tx_rings[i]);
641 kfree(tx_rings);
642 tx_rings = NULL;
643 }
644
645done:
646 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
647
648 return err;
649}
650
651static int i40e_get_sset_count(struct net_device *netdev, int sset)
652{
653 struct i40e_netdev_priv *np = netdev_priv(netdev);
654 struct i40e_vsi *vsi = np->vsi;
655 struct i40e_pf *pf = vsi->back;
656
657 switch (sset) {
658 case ETH_SS_TEST:
659 return I40E_TEST_LEN;
660 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000661 if (vsi == pf->vsi[pf->lan_vsi]) {
662 int len = I40E_PF_STATS_LEN(netdev);
663
664 if (pf->lan_veb != I40E_NO_VEB)
665 len += I40E_VEB_STATS_LEN;
666 return len;
667 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000668 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000669 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000670 default:
671 return -EOPNOTSUPP;
672 }
673}
674
675static void i40e_get_ethtool_stats(struct net_device *netdev,
676 struct ethtool_stats *stats, u64 *data)
677{
678 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000679 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000680 struct i40e_vsi *vsi = np->vsi;
681 struct i40e_pf *pf = vsi->back;
682 int i = 0;
683 char *p;
684 int j;
685 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000686 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000687
688 i40e_update_stats(vsi);
689
690 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
691 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
692 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
693 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
694 }
Shannon Nelson41a9e552014-04-23 04:50:20 +0000695 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
696 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
697 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
698 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
699 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000700 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000701 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000702 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000703
704 if (!tx_ring)
705 continue;
706
707 /* process Tx ring statistics */
708 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700709 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000710 data[i] = tx_ring->stats.packets;
711 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700712 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000713 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000714
715 /* Rx ring is the 2nd half of the queue pair */
716 rx_ring = &tx_ring[1];
717 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700718 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000719 data[i] = rx_ring->stats.packets;
720 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700721 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000722 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000723 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000724 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000725 if (vsi != pf->vsi[pf->lan_vsi])
726 return;
727
728 if (pf->lan_veb != I40E_NO_VEB) {
729 struct i40e_veb *veb = pf->veb[pf->lan_veb];
730 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
731 p = (char *)veb;
732 p += i40e_gstrings_veb_stats[j].stat_offset;
733 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
734 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000735 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000736 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000737 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
738 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
739 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
740 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
741 }
742 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
743 data[i++] = pf->stats.priority_xon_tx[j];
744 data[i++] = pf->stats.priority_xoff_tx[j];
745 }
746 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
747 data[i++] = pf->stats.priority_xon_rx[j];
748 data[i++] = pf->stats.priority_xoff_rx[j];
749 }
750 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
751 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000752}
753
754static void i40e_get_strings(struct net_device *netdev, u32 stringset,
755 u8 *data)
756{
757 struct i40e_netdev_priv *np = netdev_priv(netdev);
758 struct i40e_vsi *vsi = np->vsi;
759 struct i40e_pf *pf = vsi->back;
760 char *p = (char *)data;
761 int i;
762
763 switch (stringset) {
764 case ETH_SS_TEST:
765 for (i = 0; i < I40E_TEST_LEN; i++) {
766 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
767 data += ETH_GSTRING_LEN;
768 }
769 break;
770 case ETH_SS_STATS:
771 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
772 snprintf(p, ETH_GSTRING_LEN, "%s",
773 i40e_gstrings_net_stats[i].stat_string);
774 p += ETH_GSTRING_LEN;
775 }
Shannon Nelson41a9e552014-04-23 04:50:20 +0000776 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
777 snprintf(p, ETH_GSTRING_LEN, "%s",
778 i40e_gstrings_misc_stats[i].stat_string);
779 p += ETH_GSTRING_LEN;
780 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000781 for (i = 0; i < vsi->num_queue_pairs; i++) {
782 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
783 p += ETH_GSTRING_LEN;
784 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
785 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000786 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
787 p += ETH_GSTRING_LEN;
788 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
789 p += ETH_GSTRING_LEN;
790 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000791 if (vsi != pf->vsi[pf->lan_vsi])
792 return;
793
794 if (pf->lan_veb != I40E_NO_VEB) {
795 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
796 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
797 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000798 p += ETH_GSTRING_LEN;
799 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000800 }
801 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
802 snprintf(p, ETH_GSTRING_LEN, "port.%s",
803 i40e_gstrings_stats[i].stat_string);
804 p += ETH_GSTRING_LEN;
805 }
806 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
807 snprintf(p, ETH_GSTRING_LEN,
808 "port.tx_priority_%u_xon", i);
809 p += ETH_GSTRING_LEN;
810 snprintf(p, ETH_GSTRING_LEN,
811 "port.tx_priority_%u_xoff", i);
812 p += ETH_GSTRING_LEN;
813 }
814 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
815 snprintf(p, ETH_GSTRING_LEN,
816 "port.rx_priority_%u_xon", i);
817 p += ETH_GSTRING_LEN;
818 snprintf(p, ETH_GSTRING_LEN,
819 "port.rx_priority_%u_xoff", i);
820 p += ETH_GSTRING_LEN;
821 }
822 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
823 snprintf(p, ETH_GSTRING_LEN,
824 "port.rx_priority_%u_xon_2_xoff", i);
825 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000826 }
827 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
828 break;
829 }
830}
831
832static int i40e_get_ts_info(struct net_device *dev,
833 struct ethtool_ts_info *info)
834{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000835 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
836
837 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
838 SOF_TIMESTAMPING_RX_SOFTWARE |
839 SOF_TIMESTAMPING_SOFTWARE |
840 SOF_TIMESTAMPING_TX_HARDWARE |
841 SOF_TIMESTAMPING_RX_HARDWARE |
842 SOF_TIMESTAMPING_RAW_HARDWARE;
843
844 if (pf->ptp_clock)
845 info->phc_index = ptp_clock_index(pf->ptp_clock);
846 else
847 info->phc_index = -1;
848
849 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
850
851 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
852 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
853 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
854 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
855 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
856 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
857 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
858 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
859 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
860 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
861 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
862 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
863
864 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000865}
866
Shannon Nelson7b086392013-11-20 10:02:59 +0000867static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000868{
Shannon Nelson7b086392013-11-20 10:02:59 +0000869 struct i40e_netdev_priv *np = netdev_priv(netdev);
870 struct i40e_pf *pf = np->vsi->back;
871
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000872 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000873 if (i40e_get_link_status(&pf->hw))
874 *data = 0;
875 else
876 *data = 1;
877
878 return *data;
879}
880
Shannon Nelson7b086392013-11-20 10:02:59 +0000881static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000882{
Shannon Nelson7b086392013-11-20 10:02:59 +0000883 struct i40e_netdev_priv *np = netdev_priv(netdev);
884 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000885
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000886 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000887 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000888
Shannon Nelson7b086392013-11-20 10:02:59 +0000889 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000890}
891
Shannon Nelson7b086392013-11-20 10:02:59 +0000892static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000893{
Shannon Nelson7b086392013-11-20 10:02:59 +0000894 struct i40e_netdev_priv *np = netdev_priv(netdev);
895 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000896
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000897 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000898 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000899
Shannon Nelson7b086392013-11-20 10:02:59 +0000900 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000901}
902
Shannon Nelson7b086392013-11-20 10:02:59 +0000903static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000904{
Shannon Nelson7b086392013-11-20 10:02:59 +0000905 struct i40e_netdev_priv *np = netdev_priv(netdev);
906 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000907 u16 swc_old = pf->sw_int_count;
908
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000909 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000910 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
911 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
912 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
913 usleep_range(1000, 2000);
914 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000915
916 return *data;
917}
918
Shannon Nelson7b086392013-11-20 10:02:59 +0000919static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000920{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000921 struct i40e_netdev_priv *np = netdev_priv(netdev);
922 struct i40e_pf *pf = np->vsi->back;
923
924 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000925 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000926
927 return *data;
928}
929
930static void i40e_diag_test(struct net_device *netdev,
931 struct ethtool_test *eth_test, u64 *data)
932{
933 struct i40e_netdev_priv *np = netdev_priv(netdev);
934 struct i40e_pf *pf = np->vsi->back;
935
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000936 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
937 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000938 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000939
Shannon Nelsonf551b432013-11-26 10:49:12 +0000940 set_bit(__I40E_TESTING, &pf->state);
941
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000942 /* Link test performed before hardware reset
943 * so autoneg doesn't interfere with test result
944 */
Shannon Nelson7b086392013-11-20 10:02:59 +0000945 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000946 eth_test->flags |= ETH_TEST_FL_FAILED;
947
Shannon Nelson7b086392013-11-20 10:02:59 +0000948 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000949 eth_test->flags |= ETH_TEST_FL_FAILED;
950
Shannon Nelson7b086392013-11-20 10:02:59 +0000951 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000952 eth_test->flags |= ETH_TEST_FL_FAILED;
953
Shannon Nelson7b086392013-11-20 10:02:59 +0000954 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000955 eth_test->flags |= ETH_TEST_FL_FAILED;
956
Shannon Nelsonf551b432013-11-26 10:49:12 +0000957 /* run reg test last, a reset is required after it */
958 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
959 eth_test->flags |= ETH_TEST_FL_FAILED;
960
961 clear_bit(__I40E_TESTING, &pf->state);
962 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000963 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000964 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000965 netif_info(pf, drv, netdev, "online testing starting\n");
966
Shannon Nelson7b086392013-11-20 10:02:59 +0000967 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000968 eth_test->flags |= ETH_TEST_FL_FAILED;
969
970 /* Offline only tests, not run in online; pass by default */
971 data[I40E_ETH_TEST_REG] = 0;
972 data[I40E_ETH_TEST_EEPROM] = 0;
973 data[I40E_ETH_TEST_INTR] = 0;
974 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000975 }
Shannon Nelsonc140c172013-11-20 10:02:58 +0000976
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000977 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000978}
979
980static void i40e_get_wol(struct net_device *netdev,
981 struct ethtool_wolinfo *wol)
982{
Shannon Nelson8e2773a2013-11-28 06:39:22 +0000983 struct i40e_netdev_priv *np = netdev_priv(netdev);
984 struct i40e_pf *pf = np->vsi->back;
985 struct i40e_hw *hw = &pf->hw;
986 u16 wol_nvm_bits;
987
988 /* NVM bit on means WoL disabled for the port */
989 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
990 if ((1 << hw->port) & wol_nvm_bits) {
991 wol->supported = 0;
992 wol->wolopts = 0;
993 } else {
994 wol->supported = WAKE_MAGIC;
995 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
996 }
997}
998
999static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1000{
1001 struct i40e_netdev_priv *np = netdev_priv(netdev);
1002 struct i40e_pf *pf = np->vsi->back;
1003 struct i40e_hw *hw = &pf->hw;
1004 u16 wol_nvm_bits;
1005
1006 /* NVM bit on means WoL disabled for the port */
1007 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1008 if (((1 << hw->port) & wol_nvm_bits))
1009 return -EOPNOTSUPP;
1010
1011 /* only magic packet is supported */
1012 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1013 return -EOPNOTSUPP;
1014
1015 /* is this a new value? */
1016 if (pf->wol_en != !!wol->wolopts) {
1017 pf->wol_en = !!wol->wolopts;
1018 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1019 }
1020
1021 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001022}
1023
1024static int i40e_nway_reset(struct net_device *netdev)
1025{
1026 /* restart autonegotiation */
1027 struct i40e_netdev_priv *np = netdev_priv(netdev);
1028 struct i40e_pf *pf = np->vsi->back;
1029 struct i40e_hw *hw = &pf->hw;
1030 i40e_status ret = 0;
1031
1032 ret = i40e_aq_set_link_restart_an(hw, NULL);
1033 if (ret) {
1034 netdev_info(netdev, "link restart failed, aq_err=%d\n",
1035 pf->hw.aq.asq_last_status);
1036 return -EIO;
1037 }
1038
1039 return 0;
1040}
1041
1042static int i40e_set_phys_id(struct net_device *netdev,
1043 enum ethtool_phys_id_state state)
1044{
1045 struct i40e_netdev_priv *np = netdev_priv(netdev);
1046 struct i40e_pf *pf = np->vsi->back;
1047 struct i40e_hw *hw = &pf->hw;
1048 int blink_freq = 2;
1049
1050 switch (state) {
1051 case ETHTOOL_ID_ACTIVE:
1052 pf->led_status = i40e_led_get(hw);
1053 return blink_freq;
1054 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001055 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001056 break;
1057 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001058 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001059 break;
1060 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001061 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001062 break;
1063 }
1064
1065 return 0;
1066}
1067
1068/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1069 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1070 * 125us (8000 interrupts per second) == ITR(62)
1071 */
1072
1073static int i40e_get_coalesce(struct net_device *netdev,
1074 struct ethtool_coalesce *ec)
1075{
1076 struct i40e_netdev_priv *np = netdev_priv(netdev);
1077 struct i40e_vsi *vsi = np->vsi;
1078
1079 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1080 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1081
1082 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001083 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001084
1085 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001086 ec->use_adaptive_tx_coalesce = 1;
1087
1088 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1089 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001090
1091 return 0;
1092}
1093
1094static int i40e_set_coalesce(struct net_device *netdev,
1095 struct ethtool_coalesce *ec)
1096{
1097 struct i40e_netdev_priv *np = netdev_priv(netdev);
1098 struct i40e_q_vector *q_vector;
1099 struct i40e_vsi *vsi = np->vsi;
1100 struct i40e_pf *pf = vsi->back;
1101 struct i40e_hw *hw = &pf->hw;
1102 u16 vector;
1103 int i;
1104
1105 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1106 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1107
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001108 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001109 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001110 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001111 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001112 } else if (ec->rx_coalesce_usecs == 0) {
1113 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1114 i40e_irq_dynamic_disable(vsi, vector);
1115 if (ec->use_adaptive_rx_coalesce)
1116 netif_info(pf, drv, netdev,
1117 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1118 } else {
1119 netif_info(pf, drv, netdev,
1120 "Invalid value, Rx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001121 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001122 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001123
Mitch Williams32f5f542014-04-04 04:43:10 +00001124 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001125 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001126 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001127 } else if (ec->tx_coalesce_usecs == 0) {
1128 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1129 i40e_irq_dynamic_disable(vsi, vector);
1130 if (ec->use_adaptive_tx_coalesce)
1131 netif_info(pf, drv, netdev,
1132 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1133 } else {
1134 netif_info(pf, drv, netdev,
1135 "Invalid value, Tx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001136 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001137 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001138
1139 if (ec->use_adaptive_rx_coalesce)
1140 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1141 else
1142 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1143
1144 if (ec->use_adaptive_tx_coalesce)
1145 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1146 else
1147 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001148
Alexander Duyck493fb302013-09-28 07:01:44 +00001149 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1150 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001151 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1152 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1153 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1154 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1155 i40e_flush(hw);
1156 }
1157
1158 return 0;
1159}
1160
1161/**
1162 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1163 * @pf: pointer to the physical function struct
1164 * @cmd: ethtool rxnfc command
1165 *
1166 * Returns Success if the flow is supported, else Invalid Input.
1167 **/
1168static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1169{
1170 cmd->data = 0;
1171
1172 /* Report default options for RSS on i40e */
1173 switch (cmd->flow_type) {
1174 case TCP_V4_FLOW:
1175 case UDP_V4_FLOW:
1176 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1177 /* fall through to add IP fields */
1178 case SCTP_V4_FLOW:
1179 case AH_ESP_V4_FLOW:
1180 case AH_V4_FLOW:
1181 case ESP_V4_FLOW:
1182 case IPV4_FLOW:
1183 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1184 break;
1185 case TCP_V6_FLOW:
1186 case UDP_V6_FLOW:
1187 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1188 /* fall through to add IP fields */
1189 case SCTP_V6_FLOW:
1190 case AH_ESP_V6_FLOW:
1191 case AH_V6_FLOW:
1192 case ESP_V6_FLOW:
1193 case IPV6_FLOW:
1194 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1195 break;
1196 default:
1197 return -EINVAL;
1198 }
1199
1200 return 0;
1201}
1202
1203/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001204 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1205 * @pf: Pointer to the physical function struct
1206 * @cmd: The command to get or set Rx flow classification rules
1207 * @rule_locs: Array of used rule locations
1208 *
1209 * This function populates both the total and actual rule count of
1210 * the ethtool flow classification command
1211 *
1212 * Returns 0 on success or -EMSGSIZE if entry not found
1213 **/
1214static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1215 struct ethtool_rxnfc *cmd,
1216 u32 *rule_locs)
1217{
1218 struct i40e_fdir_filter *rule;
1219 struct hlist_node *node2;
1220 int cnt = 0;
1221
1222 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001223 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001224
1225 hlist_for_each_entry_safe(rule, node2,
1226 &pf->fdir_filter_list, fdir_node) {
1227 if (cnt == cmd->rule_cnt)
1228 return -EMSGSIZE;
1229
1230 rule_locs[cnt] = rule->fd_id;
1231 cnt++;
1232 }
1233
1234 cmd->rule_cnt = cnt;
1235
1236 return 0;
1237}
1238
1239/**
1240 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1241 * @pf: Pointer to the physical function struct
1242 * @cmd: The command to get or set Rx flow classification rules
1243 *
1244 * This function looks up a filter based on the Rx flow classification
1245 * command and fills the flow spec info for it if found
1246 *
1247 * Returns 0 on success or -EINVAL if filter not found
1248 **/
1249static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1250 struct ethtool_rxnfc *cmd)
1251{
1252 struct ethtool_rx_flow_spec *fsp =
1253 (struct ethtool_rx_flow_spec *)&cmd->fs;
1254 struct i40e_fdir_filter *rule = NULL;
1255 struct hlist_node *node2;
1256
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001257 hlist_for_each_entry_safe(rule, node2,
1258 &pf->fdir_filter_list, fdir_node) {
1259 if (fsp->location <= rule->fd_id)
1260 break;
1261 }
1262
1263 if (!rule || fsp->location != rule->fd_id)
1264 return -EINVAL;
1265
1266 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001267 if (fsp->flow_type == IP_USER_FLOW) {
1268 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1269 fsp->h_u.usr_ip4_spec.proto = 0;
1270 fsp->m_u.usr_ip4_spec.proto = 0;
1271 }
1272
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001273 /* Reverse the src and dest notion, since the HW views them from
1274 * Tx perspective where as the user expects it from Rx filter view.
1275 */
1276 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1277 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1278 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1279 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001280
1281 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1282 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1283 else
1284 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001285
1286 return 0;
1287}
1288
1289/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001290 * i40e_get_rxnfc - command to get RX flow classification rules
1291 * @netdev: network interface device structure
1292 * @cmd: ethtool rxnfc command
1293 *
1294 * Returns Success if the command is supported.
1295 **/
1296static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1297 u32 *rule_locs)
1298{
1299 struct i40e_netdev_priv *np = netdev_priv(netdev);
1300 struct i40e_vsi *vsi = np->vsi;
1301 struct i40e_pf *pf = vsi->back;
1302 int ret = -EOPNOTSUPP;
1303
1304 switch (cmd->cmd) {
1305 case ETHTOOL_GRXRINGS:
1306 cmd->data = vsi->alloc_queue_pairs;
1307 ret = 0;
1308 break;
1309 case ETHTOOL_GRXFH:
1310 ret = i40e_get_rss_hash_opts(pf, cmd);
1311 break;
1312 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001313 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001314 /* report total rule count */
1315 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001316 ret = 0;
1317 break;
1318 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001319 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001320 break;
1321 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001322 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1323 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001324 default:
1325 break;
1326 }
1327
1328 return ret;
1329}
1330
1331/**
1332 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1333 * @pf: pointer to the physical function struct
1334 * @cmd: ethtool rxnfc command
1335 *
1336 * Returns Success if the flow input set is supported.
1337 **/
1338static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1339{
1340 struct i40e_hw *hw = &pf->hw;
1341 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1342 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1343
1344 /* RSS does not support anything other than hashing
1345 * to queues on src and dst IPs and ports
1346 */
1347 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1348 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1349 return -EINVAL;
1350
1351 /* We need at least the IP SRC and DEST fields for hashing */
1352 if (!(nfc->data & RXH_IP_SRC) ||
1353 !(nfc->data & RXH_IP_DST))
1354 return -EINVAL;
1355
1356 switch (nfc->flow_type) {
1357 case TCP_V4_FLOW:
1358 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1359 case 0:
1360 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1361 break;
1362 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1363 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1364 break;
1365 default:
1366 return -EINVAL;
1367 }
1368 break;
1369 case TCP_V6_FLOW:
1370 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1371 case 0:
1372 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1373 break;
1374 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1375 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1376 break;
1377 default:
1378 return -EINVAL;
1379 }
1380 break;
1381 case UDP_V4_FLOW:
1382 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1383 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001384 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1385 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001386 break;
1387 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001388 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1389 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001390 break;
1391 default:
1392 return -EINVAL;
1393 }
1394 break;
1395 case UDP_V6_FLOW:
1396 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1397 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001398 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1399 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001400 break;
1401 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001402 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1403 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001404 break;
1405 default:
1406 return -EINVAL;
1407 }
1408 break;
1409 case AH_ESP_V4_FLOW:
1410 case AH_V4_FLOW:
1411 case ESP_V4_FLOW:
1412 case SCTP_V4_FLOW:
1413 if ((nfc->data & RXH_L4_B_0_1) ||
1414 (nfc->data & RXH_L4_B_2_3))
1415 return -EINVAL;
1416 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1417 break;
1418 case AH_ESP_V6_FLOW:
1419 case AH_V6_FLOW:
1420 case ESP_V6_FLOW:
1421 case SCTP_V6_FLOW:
1422 if ((nfc->data & RXH_L4_B_0_1) ||
1423 (nfc->data & RXH_L4_B_2_3))
1424 return -EINVAL;
1425 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1426 break;
1427 case IPV4_FLOW:
1428 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1429 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1430 break;
1431 case IPV6_FLOW:
1432 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1433 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1434 break;
1435 default:
1436 return -EINVAL;
1437 }
1438
1439 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1440 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1441 i40e_flush(hw);
1442
1443 return 0;
1444}
1445
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001446/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001447 * i40e_match_fdir_input_set - Match a new filter against an existing one
1448 * @rule: The filter already added
1449 * @input: The new filter to comapre against
1450 *
1451 * Returns true if the two input set match
1452 **/
1453static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1454 struct i40e_fdir_filter *input)
1455{
1456 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1457 (rule->src_ip[0] != input->src_ip[0]) ||
1458 (rule->dst_port != input->dst_port) ||
1459 (rule->src_port != input->src_port))
1460 return false;
1461 return true;
1462}
1463
1464/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001465 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1466 * @vsi: Pointer to the targeted VSI
1467 * @input: The filter to update or NULL to indicate deletion
1468 * @sw_idx: Software index to the filter
1469 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001470 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001471 * This function updates (or deletes) a Flow Director entry from
1472 * the hlist of the corresponding PF
1473 *
1474 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001475 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001476static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1477 struct i40e_fdir_filter *input,
1478 u16 sw_idx,
1479 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001481 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001482 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001483 struct hlist_node *node2;
1484 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001485
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001486 parent = NULL;
1487 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001488
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001489 hlist_for_each_entry_safe(rule, node2,
1490 &pf->fdir_filter_list, fdir_node) {
1491 /* hash found, or no matching entry */
1492 if (rule->fd_id >= sw_idx)
1493 break;
1494 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001495 }
1496
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001497 /* if there is an old rule occupying our place remove it */
1498 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001499 if (input && !i40e_match_fdir_input_set(rule, input))
1500 err = i40e_add_del_fdir(vsi, rule, false);
1501 else if (!input)
1502 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001503 hlist_del(&rule->fdir_node);
1504 kfree(rule);
1505 pf->fdir_pf_active_filters--;
1506 }
1507
1508 /* If no input this was a delete, err should be 0 if a rule was
1509 * successfully found and removed from the list else -EINVAL
1510 */
1511 if (!input)
1512 return err;
1513
1514 /* initialize node and set software index */
1515 INIT_HLIST_NODE(&input->fdir_node);
1516
1517 /* add filter to the list */
1518 if (parent)
1519 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1520 else
1521 hlist_add_head(&input->fdir_node,
1522 &pf->fdir_filter_list);
1523
1524 /* update counts */
1525 pf->fdir_pf_active_filters++;
1526
1527 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001528}
1529
1530/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001531 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1532 * @vsi: Pointer to the targeted VSI
1533 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001534 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001535 * The function removes a Flow Director filter entry from the
1536 * hlist of the corresponding PF
1537 *
1538 * Returns 0 on success
1539 */
1540static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1541 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001542{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001543 struct ethtool_rx_flow_spec *fsp =
1544 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001545 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001546 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001547
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001548 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001549
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001550 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001551 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001552}
1553
1554/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001555 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001556 * @vsi: pointer to the targeted VSI
1557 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001559 * Add Flow Director filters for a specific flow spec based on their
1560 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001561 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001562static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1563 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001564{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001565 struct ethtool_rx_flow_spec *fsp;
1566 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001567 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001568 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001569
1570 if (!vsi)
1571 return -EINVAL;
1572
1573 pf = vsi->back;
1574
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001575 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1576 return -EOPNOTSUPP;
1577
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001578 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001579 return -ENOSPC;
1580
1581 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1582
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001583 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1584 pf->hw.func_caps.fd_filters_guaranteed)) {
1585 return -EINVAL;
1586 }
1587
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001588 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1589 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001590 return -EINVAL;
1591
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001592 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001593
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001594 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001596
1597 input->fd_id = fsp->location;
1598
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00001599 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
1600 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1601 else
1602 input->dest_ctl =
1603 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1604
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001605 input->q_index = fsp->ring_cookie;
1606 input->flex_off = 0;
1607 input->pctype = 0;
1608 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001609 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001610 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001611 input->flow_type = fsp->flow_type;
1612 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001613
1614 /* Reverse the src and dest notion, since the HW expects them to be from
1615 * Tx perspective where as the input from user is from Rx filter view.
1616 */
1617 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
1618 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
1619 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1620 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001621
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001622 ret = i40e_add_del_fdir(vsi, input, true);
1623 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001624 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001625 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001626 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001627
1628 return ret;
1629}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001630
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001631/**
1632 * i40e_set_rxnfc - command to set RX flow classification rules
1633 * @netdev: network interface device structure
1634 * @cmd: ethtool rxnfc command
1635 *
1636 * Returns Success if the command is supported.
1637 **/
1638static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1639{
1640 struct i40e_netdev_priv *np = netdev_priv(netdev);
1641 struct i40e_vsi *vsi = np->vsi;
1642 struct i40e_pf *pf = vsi->back;
1643 int ret = -EOPNOTSUPP;
1644
1645 switch (cmd->cmd) {
1646 case ETHTOOL_SRXFH:
1647 ret = i40e_set_rss_hash_opt(pf, cmd);
1648 break;
1649 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001650 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001651 break;
1652 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001653 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001654 break;
1655 default:
1656 break;
1657 }
1658
1659 return ret;
1660}
1661
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001662/**
1663 * i40e_max_channels - get Max number of combined channels supported
1664 * @vsi: vsi pointer
1665 **/
1666static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1667{
1668 /* TODO: This code assumes DCB and FD is disabled for now. */
1669 return vsi->alloc_queue_pairs;
1670}
1671
1672/**
1673 * i40e_get_channels - Get the current channels enabled and max supported etc.
1674 * @netdev: network interface device structure
1675 * @ch: ethtool channels structure
1676 *
1677 * We don't support separate tx and rx queues as channels. The other count
1678 * represents how many queues are being used for control. max_combined counts
1679 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1680 * q_vectors since we support a lot more queue pairs than q_vectors.
1681 **/
1682static void i40e_get_channels(struct net_device *dev,
1683 struct ethtool_channels *ch)
1684{
1685 struct i40e_netdev_priv *np = netdev_priv(dev);
1686 struct i40e_vsi *vsi = np->vsi;
1687 struct i40e_pf *pf = vsi->back;
1688
1689 /* report maximum channels */
1690 ch->max_combined = i40e_max_channels(vsi);
1691
1692 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001693 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001694 ch->max_other = ch->other_count;
1695
1696 /* Note: This code assumes DCB is disabled for now. */
1697 ch->combined_count = vsi->num_queue_pairs;
1698}
1699
1700/**
1701 * i40e_set_channels - Set the new channels count.
1702 * @netdev: network interface device structure
1703 * @ch: ethtool channels structure
1704 *
1705 * The new channels count may not be the same as requested by the user
1706 * since it gets rounded down to a power of 2 value.
1707 **/
1708static int i40e_set_channels(struct net_device *dev,
1709 struct ethtool_channels *ch)
1710{
1711 struct i40e_netdev_priv *np = netdev_priv(dev);
1712 unsigned int count = ch->combined_count;
1713 struct i40e_vsi *vsi = np->vsi;
1714 struct i40e_pf *pf = vsi->back;
1715 int new_count;
1716
1717 /* We do not support setting channels for any other VSI at present */
1718 if (vsi->type != I40E_VSI_MAIN)
1719 return -EINVAL;
1720
1721 /* verify they are not requesting separate vectors */
1722 if (!count || ch->rx_count || ch->tx_count)
1723 return -EINVAL;
1724
1725 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001726 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001727 return -EINVAL;
1728
1729 /* verify the number of channels does not exceed hardware limits */
1730 if (count > i40e_max_channels(vsi))
1731 return -EINVAL;
1732
1733 /* update feature limits from largest to smallest supported values */
1734 /* TODO: Flow director limit, DCB etc */
1735
1736 /* cap RSS limit */
1737 if (count > pf->rss_size_max)
1738 count = pf->rss_size_max;
1739
1740 /* use rss_reconfig to rebuild with new queue count and update traffic
1741 * class queue mapping
1742 */
1743 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00001744 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001745 return 0;
1746 else
1747 return -EINVAL;
1748}
1749
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001750static const struct ethtool_ops i40e_ethtool_ops = {
1751 .get_settings = i40e_get_settings,
1752 .get_drvinfo = i40e_get_drvinfo,
1753 .get_regs_len = i40e_get_regs_len,
1754 .get_regs = i40e_get_regs,
1755 .nway_reset = i40e_nway_reset,
1756 .get_link = ethtool_op_get_link,
1757 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001758 .set_wol = i40e_set_wol,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001759 .get_eeprom_len = i40e_get_eeprom_len,
1760 .get_eeprom = i40e_get_eeprom,
1761 .get_ringparam = i40e_get_ringparam,
1762 .set_ringparam = i40e_set_ringparam,
1763 .get_pauseparam = i40e_get_pauseparam,
1764 .get_msglevel = i40e_get_msglevel,
1765 .set_msglevel = i40e_set_msglevel,
1766 .get_rxnfc = i40e_get_rxnfc,
1767 .set_rxnfc = i40e_set_rxnfc,
1768 .self_test = i40e_diag_test,
1769 .get_strings = i40e_get_strings,
1770 .set_phys_id = i40e_set_phys_id,
1771 .get_sset_count = i40e_get_sset_count,
1772 .get_ethtool_stats = i40e_get_ethtool_stats,
1773 .get_coalesce = i40e_get_coalesce,
1774 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001775 .get_channels = i40e_get_channels,
1776 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001777 .get_ts_info = i40e_get_ts_info,
1778};
1779
1780void i40e_set_ethtool_ops(struct net_device *netdev)
1781{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00001782 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001783}