blob: df89b6c3db41336f04fa5434635c7cd64ea34321 [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;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001030 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001031 i40e_status ret = 0;
1032
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001033 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001034 if (ret) {
1035 netdev_info(netdev, "link restart failed, aq_err=%d\n",
1036 pf->hw.aq.asq_last_status);
1037 return -EIO;
1038 }
1039
1040 return 0;
1041}
1042
1043static int i40e_set_phys_id(struct net_device *netdev,
1044 enum ethtool_phys_id_state state)
1045{
1046 struct i40e_netdev_priv *np = netdev_priv(netdev);
1047 struct i40e_pf *pf = np->vsi->back;
1048 struct i40e_hw *hw = &pf->hw;
1049 int blink_freq = 2;
1050
1051 switch (state) {
1052 case ETHTOOL_ID_ACTIVE:
1053 pf->led_status = i40e_led_get(hw);
1054 return blink_freq;
1055 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001056 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001057 break;
1058 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001059 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001060 break;
1061 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001062 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001063 break;
1064 }
1065
1066 return 0;
1067}
1068
1069/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1070 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1071 * 125us (8000 interrupts per second) == ITR(62)
1072 */
1073
1074static int i40e_get_coalesce(struct net_device *netdev,
1075 struct ethtool_coalesce *ec)
1076{
1077 struct i40e_netdev_priv *np = netdev_priv(netdev);
1078 struct i40e_vsi *vsi = np->vsi;
1079
1080 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1081 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1082
1083 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001084 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001085
1086 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001087 ec->use_adaptive_tx_coalesce = 1;
1088
1089 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1090 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001091
1092 return 0;
1093}
1094
1095static int i40e_set_coalesce(struct net_device *netdev,
1096 struct ethtool_coalesce *ec)
1097{
1098 struct i40e_netdev_priv *np = netdev_priv(netdev);
1099 struct i40e_q_vector *q_vector;
1100 struct i40e_vsi *vsi = np->vsi;
1101 struct i40e_pf *pf = vsi->back;
1102 struct i40e_hw *hw = &pf->hw;
1103 u16 vector;
1104 int i;
1105
1106 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1107 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1108
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001109 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001110 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001111 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001112 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001113 } else if (ec->rx_coalesce_usecs == 0) {
1114 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1115 i40e_irq_dynamic_disable(vsi, vector);
1116 if (ec->use_adaptive_rx_coalesce)
1117 netif_info(pf, drv, netdev,
1118 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1119 } else {
1120 netif_info(pf, drv, netdev,
1121 "Invalid value, Rx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001122 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001123 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001124
Mitch Williams32f5f542014-04-04 04:43:10 +00001125 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001126 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001127 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001128 } else if (ec->tx_coalesce_usecs == 0) {
1129 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1130 i40e_irq_dynamic_disable(vsi, vector);
1131 if (ec->use_adaptive_tx_coalesce)
1132 netif_info(pf, drv, netdev,
1133 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1134 } else {
1135 netif_info(pf, drv, netdev,
1136 "Invalid value, Tx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001137 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001138 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001139
1140 if (ec->use_adaptive_rx_coalesce)
1141 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1142 else
1143 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1144
1145 if (ec->use_adaptive_tx_coalesce)
1146 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1147 else
1148 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001149
Alexander Duyck493fb302013-09-28 07:01:44 +00001150 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1151 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001152 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1153 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1154 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1155 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1156 i40e_flush(hw);
1157 }
1158
1159 return 0;
1160}
1161
1162/**
1163 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1164 * @pf: pointer to the physical function struct
1165 * @cmd: ethtool rxnfc command
1166 *
1167 * Returns Success if the flow is supported, else Invalid Input.
1168 **/
1169static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1170{
1171 cmd->data = 0;
1172
1173 /* Report default options for RSS on i40e */
1174 switch (cmd->flow_type) {
1175 case TCP_V4_FLOW:
1176 case UDP_V4_FLOW:
1177 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1178 /* fall through to add IP fields */
1179 case SCTP_V4_FLOW:
1180 case AH_ESP_V4_FLOW:
1181 case AH_V4_FLOW:
1182 case ESP_V4_FLOW:
1183 case IPV4_FLOW:
1184 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1185 break;
1186 case TCP_V6_FLOW:
1187 case UDP_V6_FLOW:
1188 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1189 /* fall through to add IP fields */
1190 case SCTP_V6_FLOW:
1191 case AH_ESP_V6_FLOW:
1192 case AH_V6_FLOW:
1193 case ESP_V6_FLOW:
1194 case IPV6_FLOW:
1195 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1196 break;
1197 default:
1198 return -EINVAL;
1199 }
1200
1201 return 0;
1202}
1203
1204/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001205 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1206 * @pf: Pointer to the physical function struct
1207 * @cmd: The command to get or set Rx flow classification rules
1208 * @rule_locs: Array of used rule locations
1209 *
1210 * This function populates both the total and actual rule count of
1211 * the ethtool flow classification command
1212 *
1213 * Returns 0 on success or -EMSGSIZE if entry not found
1214 **/
1215static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1216 struct ethtool_rxnfc *cmd,
1217 u32 *rule_locs)
1218{
1219 struct i40e_fdir_filter *rule;
1220 struct hlist_node *node2;
1221 int cnt = 0;
1222
1223 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001224 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001225
1226 hlist_for_each_entry_safe(rule, node2,
1227 &pf->fdir_filter_list, fdir_node) {
1228 if (cnt == cmd->rule_cnt)
1229 return -EMSGSIZE;
1230
1231 rule_locs[cnt] = rule->fd_id;
1232 cnt++;
1233 }
1234
1235 cmd->rule_cnt = cnt;
1236
1237 return 0;
1238}
1239
1240/**
1241 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1242 * @pf: Pointer to the physical function struct
1243 * @cmd: The command to get or set Rx flow classification rules
1244 *
1245 * This function looks up a filter based on the Rx flow classification
1246 * command and fills the flow spec info for it if found
1247 *
1248 * Returns 0 on success or -EINVAL if filter not found
1249 **/
1250static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1251 struct ethtool_rxnfc *cmd)
1252{
1253 struct ethtool_rx_flow_spec *fsp =
1254 (struct ethtool_rx_flow_spec *)&cmd->fs;
1255 struct i40e_fdir_filter *rule = NULL;
1256 struct hlist_node *node2;
1257
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001258 hlist_for_each_entry_safe(rule, node2,
1259 &pf->fdir_filter_list, fdir_node) {
1260 if (fsp->location <= rule->fd_id)
1261 break;
1262 }
1263
1264 if (!rule || fsp->location != rule->fd_id)
1265 return -EINVAL;
1266
1267 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001268 if (fsp->flow_type == IP_USER_FLOW) {
1269 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1270 fsp->h_u.usr_ip4_spec.proto = 0;
1271 fsp->m_u.usr_ip4_spec.proto = 0;
1272 }
1273
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001274 /* Reverse the src and dest notion, since the HW views them from
1275 * Tx perspective where as the user expects it from Rx filter view.
1276 */
1277 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1278 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1279 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1280 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001281
1282 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1283 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1284 else
1285 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001286
1287 return 0;
1288}
1289
1290/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001291 * i40e_get_rxnfc - command to get RX flow classification rules
1292 * @netdev: network interface device structure
1293 * @cmd: ethtool rxnfc command
1294 *
1295 * Returns Success if the command is supported.
1296 **/
1297static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1298 u32 *rule_locs)
1299{
1300 struct i40e_netdev_priv *np = netdev_priv(netdev);
1301 struct i40e_vsi *vsi = np->vsi;
1302 struct i40e_pf *pf = vsi->back;
1303 int ret = -EOPNOTSUPP;
1304
1305 switch (cmd->cmd) {
1306 case ETHTOOL_GRXRINGS:
1307 cmd->data = vsi->alloc_queue_pairs;
1308 ret = 0;
1309 break;
1310 case ETHTOOL_GRXFH:
1311 ret = i40e_get_rss_hash_opts(pf, cmd);
1312 break;
1313 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001314 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001315 /* report total rule count */
1316 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001317 ret = 0;
1318 break;
1319 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001320 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001321 break;
1322 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001323 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1324 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001325 default:
1326 break;
1327 }
1328
1329 return ret;
1330}
1331
1332/**
1333 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1334 * @pf: pointer to the physical function struct
1335 * @cmd: ethtool rxnfc command
1336 *
1337 * Returns Success if the flow input set is supported.
1338 **/
1339static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1340{
1341 struct i40e_hw *hw = &pf->hw;
1342 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1343 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1344
1345 /* RSS does not support anything other than hashing
1346 * to queues on src and dst IPs and ports
1347 */
1348 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1349 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1350 return -EINVAL;
1351
1352 /* We need at least the IP SRC and DEST fields for hashing */
1353 if (!(nfc->data & RXH_IP_SRC) ||
1354 !(nfc->data & RXH_IP_DST))
1355 return -EINVAL;
1356
1357 switch (nfc->flow_type) {
1358 case TCP_V4_FLOW:
1359 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1360 case 0:
1361 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1362 break;
1363 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1364 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1365 break;
1366 default:
1367 return -EINVAL;
1368 }
1369 break;
1370 case TCP_V6_FLOW:
1371 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1372 case 0:
1373 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1374 break;
1375 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1376 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1377 break;
1378 default:
1379 return -EINVAL;
1380 }
1381 break;
1382 case UDP_V4_FLOW:
1383 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1384 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001385 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1386 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001387 break;
1388 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001389 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1390 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001391 break;
1392 default:
1393 return -EINVAL;
1394 }
1395 break;
1396 case UDP_V6_FLOW:
1397 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1398 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001399 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1400 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001401 break;
1402 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001403 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1404 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001405 break;
1406 default:
1407 return -EINVAL;
1408 }
1409 break;
1410 case AH_ESP_V4_FLOW:
1411 case AH_V4_FLOW:
1412 case ESP_V4_FLOW:
1413 case SCTP_V4_FLOW:
1414 if ((nfc->data & RXH_L4_B_0_1) ||
1415 (nfc->data & RXH_L4_B_2_3))
1416 return -EINVAL;
1417 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1418 break;
1419 case AH_ESP_V6_FLOW:
1420 case AH_V6_FLOW:
1421 case ESP_V6_FLOW:
1422 case SCTP_V6_FLOW:
1423 if ((nfc->data & RXH_L4_B_0_1) ||
1424 (nfc->data & RXH_L4_B_2_3))
1425 return -EINVAL;
1426 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1427 break;
1428 case IPV4_FLOW:
1429 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1430 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1431 break;
1432 case IPV6_FLOW:
1433 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1434 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1435 break;
1436 default:
1437 return -EINVAL;
1438 }
1439
1440 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1441 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1442 i40e_flush(hw);
1443
1444 return 0;
1445}
1446
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001447/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001448 * i40e_match_fdir_input_set - Match a new filter against an existing one
1449 * @rule: The filter already added
1450 * @input: The new filter to comapre against
1451 *
1452 * Returns true if the two input set match
1453 **/
1454static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1455 struct i40e_fdir_filter *input)
1456{
1457 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1458 (rule->src_ip[0] != input->src_ip[0]) ||
1459 (rule->dst_port != input->dst_port) ||
1460 (rule->src_port != input->src_port))
1461 return false;
1462 return true;
1463}
1464
1465/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001466 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1467 * @vsi: Pointer to the targeted VSI
1468 * @input: The filter to update or NULL to indicate deletion
1469 * @sw_idx: Software index to the filter
1470 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001471 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001472 * This function updates (or deletes) a Flow Director entry from
1473 * the hlist of the corresponding PF
1474 *
1475 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001476 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001477static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1478 struct i40e_fdir_filter *input,
1479 u16 sw_idx,
1480 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001481{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001482 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001484 struct hlist_node *node2;
1485 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001486
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001487 parent = NULL;
1488 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001489
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001490 hlist_for_each_entry_safe(rule, node2,
1491 &pf->fdir_filter_list, fdir_node) {
1492 /* hash found, or no matching entry */
1493 if (rule->fd_id >= sw_idx)
1494 break;
1495 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001496 }
1497
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001498 /* if there is an old rule occupying our place remove it */
1499 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001500 if (input && !i40e_match_fdir_input_set(rule, input))
1501 err = i40e_add_del_fdir(vsi, rule, false);
1502 else if (!input)
1503 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001504 hlist_del(&rule->fdir_node);
1505 kfree(rule);
1506 pf->fdir_pf_active_filters--;
1507 }
1508
1509 /* If no input this was a delete, err should be 0 if a rule was
1510 * successfully found and removed from the list else -EINVAL
1511 */
1512 if (!input)
1513 return err;
1514
1515 /* initialize node and set software index */
1516 INIT_HLIST_NODE(&input->fdir_node);
1517
1518 /* add filter to the list */
1519 if (parent)
1520 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1521 else
1522 hlist_add_head(&input->fdir_node,
1523 &pf->fdir_filter_list);
1524
1525 /* update counts */
1526 pf->fdir_pf_active_filters++;
1527
1528 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001529}
1530
1531/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001532 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1533 * @vsi: Pointer to the targeted VSI
1534 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001535 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001536 * The function removes a Flow Director filter entry from the
1537 * hlist of the corresponding PF
1538 *
1539 * Returns 0 on success
1540 */
1541static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1542 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001543{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001544 struct ethtool_rx_flow_spec *fsp =
1545 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001546 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001547 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001548
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001549 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001550
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001551 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001552 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001553}
1554
1555/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001556 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001557 * @vsi: pointer to the targeted VSI
1558 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001559 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001560 * Add Flow Director filters for a specific flow spec based on their
1561 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001562 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001563static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1564 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001565{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001566 struct ethtool_rx_flow_spec *fsp;
1567 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001568 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001569 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001570
1571 if (!vsi)
1572 return -EINVAL;
1573
1574 pf = vsi->back;
1575
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001576 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1577 return -EOPNOTSUPP;
1578
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001579 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001580 return -ENOSPC;
1581
1582 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1583
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001584 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1585 pf->hw.func_caps.fd_filters_guaranteed)) {
1586 return -EINVAL;
1587 }
1588
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001589 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1590 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001591 return -EINVAL;
1592
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001593 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001594
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001595 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001597
1598 input->fd_id = fsp->location;
1599
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00001600 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
1601 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1602 else
1603 input->dest_ctl =
1604 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1605
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001606 input->q_index = fsp->ring_cookie;
1607 input->flex_off = 0;
1608 input->pctype = 0;
1609 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001610 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001611 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001612 input->flow_type = fsp->flow_type;
1613 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001614
1615 /* Reverse the src and dest notion, since the HW expects them to be from
1616 * Tx perspective where as the input from user is from Rx filter view.
1617 */
1618 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
1619 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
1620 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1621 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001622
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001623 ret = i40e_add_del_fdir(vsi, input, true);
1624 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001625 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001626 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001627 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001628
1629 return ret;
1630}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001631
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001632/**
1633 * i40e_set_rxnfc - command to set RX flow classification rules
1634 * @netdev: network interface device structure
1635 * @cmd: ethtool rxnfc command
1636 *
1637 * Returns Success if the command is supported.
1638 **/
1639static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1640{
1641 struct i40e_netdev_priv *np = netdev_priv(netdev);
1642 struct i40e_vsi *vsi = np->vsi;
1643 struct i40e_pf *pf = vsi->back;
1644 int ret = -EOPNOTSUPP;
1645
1646 switch (cmd->cmd) {
1647 case ETHTOOL_SRXFH:
1648 ret = i40e_set_rss_hash_opt(pf, cmd);
1649 break;
1650 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001651 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001652 break;
1653 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001654 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001655 break;
1656 default:
1657 break;
1658 }
1659
1660 return ret;
1661}
1662
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001663/**
1664 * i40e_max_channels - get Max number of combined channels supported
1665 * @vsi: vsi pointer
1666 **/
1667static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1668{
1669 /* TODO: This code assumes DCB and FD is disabled for now. */
1670 return vsi->alloc_queue_pairs;
1671}
1672
1673/**
1674 * i40e_get_channels - Get the current channels enabled and max supported etc.
1675 * @netdev: network interface device structure
1676 * @ch: ethtool channels structure
1677 *
1678 * We don't support separate tx and rx queues as channels. The other count
1679 * represents how many queues are being used for control. max_combined counts
1680 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1681 * q_vectors since we support a lot more queue pairs than q_vectors.
1682 **/
1683static void i40e_get_channels(struct net_device *dev,
1684 struct ethtool_channels *ch)
1685{
1686 struct i40e_netdev_priv *np = netdev_priv(dev);
1687 struct i40e_vsi *vsi = np->vsi;
1688 struct i40e_pf *pf = vsi->back;
1689
1690 /* report maximum channels */
1691 ch->max_combined = i40e_max_channels(vsi);
1692
1693 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001694 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001695 ch->max_other = ch->other_count;
1696
1697 /* Note: This code assumes DCB is disabled for now. */
1698 ch->combined_count = vsi->num_queue_pairs;
1699}
1700
1701/**
1702 * i40e_set_channels - Set the new channels count.
1703 * @netdev: network interface device structure
1704 * @ch: ethtool channels structure
1705 *
1706 * The new channels count may not be the same as requested by the user
1707 * since it gets rounded down to a power of 2 value.
1708 **/
1709static int i40e_set_channels(struct net_device *dev,
1710 struct ethtool_channels *ch)
1711{
1712 struct i40e_netdev_priv *np = netdev_priv(dev);
1713 unsigned int count = ch->combined_count;
1714 struct i40e_vsi *vsi = np->vsi;
1715 struct i40e_pf *pf = vsi->back;
1716 int new_count;
1717
1718 /* We do not support setting channels for any other VSI at present */
1719 if (vsi->type != I40E_VSI_MAIN)
1720 return -EINVAL;
1721
1722 /* verify they are not requesting separate vectors */
1723 if (!count || ch->rx_count || ch->tx_count)
1724 return -EINVAL;
1725
1726 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001727 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001728 return -EINVAL;
1729
1730 /* verify the number of channels does not exceed hardware limits */
1731 if (count > i40e_max_channels(vsi))
1732 return -EINVAL;
1733
1734 /* update feature limits from largest to smallest supported values */
1735 /* TODO: Flow director limit, DCB etc */
1736
1737 /* cap RSS limit */
1738 if (count > pf->rss_size_max)
1739 count = pf->rss_size_max;
1740
1741 /* use rss_reconfig to rebuild with new queue count and update traffic
1742 * class queue mapping
1743 */
1744 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00001745 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001746 return 0;
1747 else
1748 return -EINVAL;
1749}
1750
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001751static const struct ethtool_ops i40e_ethtool_ops = {
1752 .get_settings = i40e_get_settings,
1753 .get_drvinfo = i40e_get_drvinfo,
1754 .get_regs_len = i40e_get_regs_len,
1755 .get_regs = i40e_get_regs,
1756 .nway_reset = i40e_nway_reset,
1757 .get_link = ethtool_op_get_link,
1758 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001759 .set_wol = i40e_set_wol,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001760 .get_eeprom_len = i40e_get_eeprom_len,
1761 .get_eeprom = i40e_get_eeprom,
1762 .get_ringparam = i40e_get_ringparam,
1763 .set_ringparam = i40e_set_ringparam,
1764 .get_pauseparam = i40e_get_pauseparam,
1765 .get_msglevel = i40e_get_msglevel,
1766 .set_msglevel = i40e_set_msglevel,
1767 .get_rxnfc = i40e_get_rxnfc,
1768 .set_rxnfc = i40e_set_rxnfc,
1769 .self_test = i40e_diag_test,
1770 .get_strings = i40e_get_strings,
1771 .set_phys_id = i40e_set_phys_id,
1772 .get_sset_count = i40e_get_sset_count,
1773 .get_ethtool_stats = i40e_get_ethtool_stats,
1774 .get_coalesce = i40e_get_coalesce,
1775 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001776 .get_channels = i40e_get_channels,
1777 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001778 .get_ts_info = i40e_get_ts_info,
1779};
1780
1781void i40e_set_ethtool_ops(struct net_device *netdev)
1782{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00001783 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001784}