1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2015 Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
21 #include <linux/vmalloc.h>
26 char stat_string
[ETH_GSTRING_LEN
];
31 #define FM10K_NETDEV_STAT(_net_stat) { \
32 .stat_string = #_net_stat, \
33 .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
34 .stat_offset = offsetof(struct net_device_stats, _net_stat) \
37 static const struct fm10k_stats fm10k_gstrings_net_stats
[] = {
38 FM10K_NETDEV_STAT(tx_packets
),
39 FM10K_NETDEV_STAT(tx_bytes
),
40 FM10K_NETDEV_STAT(tx_errors
),
41 FM10K_NETDEV_STAT(rx_packets
),
42 FM10K_NETDEV_STAT(rx_bytes
),
43 FM10K_NETDEV_STAT(rx_errors
),
44 FM10K_NETDEV_STAT(rx_dropped
),
46 /* detailed Rx errors */
47 FM10K_NETDEV_STAT(rx_length_errors
),
48 FM10K_NETDEV_STAT(rx_crc_errors
),
49 FM10K_NETDEV_STAT(rx_fifo_errors
),
52 #define FM10K_NETDEV_STATS_LEN ARRAY_SIZE(fm10k_gstrings_net_stats)
54 #define FM10K_STAT(_name, _stat) { \
55 .stat_string = _name, \
56 .sizeof_stat = FIELD_SIZEOF(struct fm10k_intfc, _stat), \
57 .stat_offset = offsetof(struct fm10k_intfc, _stat) \
60 static const struct fm10k_stats fm10k_gstrings_global_stats
[] = {
61 FM10K_STAT("tx_restart_queue", restart_queue
),
62 FM10K_STAT("tx_busy", tx_busy
),
63 FM10K_STAT("tx_csum_errors", tx_csum_errors
),
64 FM10K_STAT("rx_alloc_failed", alloc_failed
),
65 FM10K_STAT("rx_csum_errors", rx_csum_errors
),
67 FM10K_STAT("tx_packets_nic", tx_packets_nic
),
68 FM10K_STAT("tx_bytes_nic", tx_bytes_nic
),
69 FM10K_STAT("rx_packets_nic", rx_packets_nic
),
70 FM10K_STAT("rx_bytes_nic", rx_bytes_nic
),
71 FM10K_STAT("rx_drops_nic", rx_drops_nic
),
72 FM10K_STAT("rx_overrun_pf", rx_overrun_pf
),
73 FM10K_STAT("rx_overrun_vf", rx_overrun_vf
),
75 FM10K_STAT("swapi_status", hw
.swapi
.status
),
76 FM10K_STAT("mac_rules_used", hw
.swapi
.mac
.used
),
77 FM10K_STAT("mac_rules_avail", hw
.swapi
.mac
.avail
),
79 FM10K_STAT("tx_hang_count", tx_timeout_count
),
81 FM10K_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts
),
84 static const struct fm10k_stats fm10k_gstrings_debug_stats
[] = {
85 FM10K_STAT("hw_sm_mbx_full", hw_sm_mbx_full
),
86 FM10K_STAT("hw_csum_tx_good", hw_csum_tx_good
),
87 FM10K_STAT("hw_csum_rx_good", hw_csum_rx_good
),
88 FM10K_STAT("rx_switch_errors", rx_switch_errors
),
89 FM10K_STAT("rx_drops", rx_drops
),
90 FM10K_STAT("rx_pp_errors", rx_pp_errors
),
91 FM10K_STAT("rx_link_errors", rx_link_errors
),
92 FM10K_STAT("rx_length_errors", rx_length_errors
),
95 static const struct fm10k_stats fm10k_gstrings_pf_stats
[] = {
96 FM10K_STAT("timeout", stats
.timeout
.count
),
97 FM10K_STAT("ur", stats
.ur
.count
),
98 FM10K_STAT("ca", stats
.ca
.count
),
99 FM10K_STAT("um", stats
.um
.count
),
100 FM10K_STAT("xec", stats
.xec
.count
),
101 FM10K_STAT("vlan_drop", stats
.vlan_drop
.count
),
102 FM10K_STAT("loopback_drop", stats
.loopback_drop
.count
),
103 FM10K_STAT("nodesc_drop", stats
.nodesc_drop
.count
),
106 #define FM10K_MBX_STAT(_name, _stat) { \
107 .stat_string = _name, \
108 .sizeof_stat = FIELD_SIZEOF(struct fm10k_mbx_info, _stat), \
109 .stat_offset = offsetof(struct fm10k_mbx_info, _stat) \
112 static const struct fm10k_stats fm10k_gstrings_mbx_stats
[] = {
113 FM10K_MBX_STAT("mbx_tx_busy", tx_busy
),
114 FM10K_MBX_STAT("mbx_tx_oversized", tx_dropped
),
115 FM10K_MBX_STAT("mbx_tx_messages", tx_messages
),
116 FM10K_MBX_STAT("mbx_tx_dwords", tx_dwords
),
117 FM10K_MBX_STAT("mbx_rx_messages", rx_messages
),
118 FM10K_MBX_STAT("mbx_rx_dwords", rx_dwords
),
119 FM10K_MBX_STAT("mbx_rx_parse_err", rx_parse_err
),
122 #define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats)
123 #define FM10K_DEBUG_STATS_LEN ARRAY_SIZE(fm10k_gstrings_debug_stats)
124 #define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats)
125 #define FM10K_MBX_STATS_LEN ARRAY_SIZE(fm10k_gstrings_mbx_stats)
127 #define FM10K_QUEUE_STATS_LEN(_n) \
128 ( (_n) * 2 * (sizeof(struct fm10k_queue_stats) / sizeof(u64)))
130 #define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \
131 FM10K_NETDEV_STATS_LEN + \
134 static const char fm10k_gstrings_test
[][ETH_GSTRING_LEN
] = {
135 "Mailbox test (on/offline)"
138 #define FM10K_TEST_LEN (sizeof(fm10k_gstrings_test) / ETH_GSTRING_LEN)
140 enum fm10k_self_test_types
{
142 FM10K_TEST_MAX
= FM10K_TEST_LEN
146 FM10K_PRV_FLAG_DEBUG_STATS
,
150 static const char fm10k_prv_flags
[FM10K_PRV_FLAG_LEN
][ETH_GSTRING_LEN
] = {
154 static void fm10k_get_stat_strings(struct net_device
*dev
, u8
*data
)
156 struct fm10k_intfc
*interface
= netdev_priv(dev
);
157 struct fm10k_iov_data
*iov_data
= interface
->iov_data
;
158 char *p
= (char *)data
;
162 for (i
= 0; i
< FM10K_NETDEV_STATS_LEN
; i
++) {
163 memcpy(p
, fm10k_gstrings_net_stats
[i
].stat_string
,
165 p
+= ETH_GSTRING_LEN
;
168 for (i
= 0; i
< FM10K_GLOBAL_STATS_LEN
; i
++) {
169 memcpy(p
, fm10k_gstrings_global_stats
[i
].stat_string
,
171 p
+= ETH_GSTRING_LEN
;
174 if (interface
->flags
& FM10K_FLAG_DEBUG_STATS
) {
175 for (i
= 0; i
< FM10K_DEBUG_STATS_LEN
; i
++) {
176 memcpy(p
, fm10k_gstrings_debug_stats
[i
].stat_string
,
178 p
+= ETH_GSTRING_LEN
;
182 for (i
= 0; i
< FM10K_MBX_STATS_LEN
; i
++) {
183 memcpy(p
, fm10k_gstrings_mbx_stats
[i
].stat_string
,
185 p
+= ETH_GSTRING_LEN
;
188 if (interface
->hw
.mac
.type
!= fm10k_mac_vf
) {
189 for (i
= 0; i
< FM10K_PF_STATS_LEN
; i
++) {
190 memcpy(p
, fm10k_gstrings_pf_stats
[i
].stat_string
,
192 p
+= ETH_GSTRING_LEN
;
196 if ((interface
->flags
& FM10K_FLAG_DEBUG_STATS
) && iov_data
) {
197 for (i
= 0; i
< iov_data
->num_vfs
; i
++) {
198 for (j
= 0; j
< FM10K_MBX_STATS_LEN
; j
++) {
202 fm10k_gstrings_mbx_stats
[j
].stat_string
);
203 p
+= ETH_GSTRING_LEN
;
208 for (i
= 0; i
< interface
->hw
.mac
.max_queues
; i
++) {
209 snprintf(p
, ETH_GSTRING_LEN
, "tx_queue_%u_packets", i
);
210 p
+= ETH_GSTRING_LEN
;
211 snprintf(p
, ETH_GSTRING_LEN
, "tx_queue_%u_bytes", i
);
212 p
+= ETH_GSTRING_LEN
;
213 snprintf(p
, ETH_GSTRING_LEN
, "rx_queue_%u_packets", i
);
214 p
+= ETH_GSTRING_LEN
;
215 snprintf(p
, ETH_GSTRING_LEN
, "rx_queue_%u_bytes", i
);
216 p
+= ETH_GSTRING_LEN
;
220 static void fm10k_get_strings(struct net_device
*dev
,
221 u32 stringset
, u8
*data
)
223 char *p
= (char *)data
;
227 memcpy(data
, *fm10k_gstrings_test
,
228 FM10K_TEST_LEN
* ETH_GSTRING_LEN
);
231 fm10k_get_stat_strings(dev
, data
);
233 case ETH_SS_PRIV_FLAGS
:
234 memcpy(p
, fm10k_prv_flags
,
235 FM10K_PRV_FLAG_LEN
* ETH_GSTRING_LEN
);
240 static int fm10k_get_sset_count(struct net_device
*dev
, int sset
)
242 struct fm10k_intfc
*interface
= netdev_priv(dev
);
243 struct fm10k_iov_data
*iov_data
= interface
->iov_data
;
244 struct fm10k_hw
*hw
= &interface
->hw
;
245 int stats_len
= FM10K_STATIC_STATS_LEN
;
249 return FM10K_TEST_LEN
;
251 stats_len
+= FM10K_QUEUE_STATS_LEN(hw
->mac
.max_queues
);
253 if (hw
->mac
.type
!= fm10k_mac_vf
)
254 stats_len
+= FM10K_PF_STATS_LEN
;
256 if (interface
->flags
& FM10K_FLAG_DEBUG_STATS
) {
257 stats_len
+= FM10K_DEBUG_STATS_LEN
;
260 stats_len
+= FM10K_MBX_STATS_LEN
* iov_data
->num_vfs
;
264 case ETH_SS_PRIV_FLAGS
:
265 return FM10K_PRV_FLAG_LEN
;
271 static void fm10k_get_ethtool_stats(struct net_device
*netdev
,
272 struct ethtool_stats __always_unused
*stats
,
275 const int stat_count
= sizeof(struct fm10k_queue_stats
) / sizeof(u64
);
276 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
277 struct fm10k_iov_data
*iov_data
= interface
->iov_data
;
278 struct net_device_stats
*net_stats
= &netdev
->stats
;
282 fm10k_update_stats(interface
);
284 for (i
= 0; i
< FM10K_NETDEV_STATS_LEN
; i
++) {
285 p
= (char *)net_stats
+ fm10k_gstrings_net_stats
[i
].stat_offset
;
286 *(data
++) = (fm10k_gstrings_net_stats
[i
].sizeof_stat
==
287 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
290 for (i
= 0; i
< FM10K_GLOBAL_STATS_LEN
; i
++) {
291 p
= (char *)interface
+
292 fm10k_gstrings_global_stats
[i
].stat_offset
;
293 *(data
++) = (fm10k_gstrings_global_stats
[i
].sizeof_stat
==
294 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
297 if (interface
->flags
& FM10K_FLAG_DEBUG_STATS
) {
298 for (i
= 0; i
< FM10K_DEBUG_STATS_LEN
; i
++) {
299 p
= (char *)interface
+ fm10k_gstrings_debug_stats
[i
].stat_offset
;
300 *(data
++) = (fm10k_gstrings_debug_stats
[i
].sizeof_stat
==
301 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
305 for (i
= 0; i
< FM10K_MBX_STATS_LEN
; i
++) {
306 p
= (char *)&interface
->hw
.mbx
+ fm10k_gstrings_mbx_stats
[i
].stat_offset
;
307 *(data
++) = (fm10k_gstrings_mbx_stats
[i
].sizeof_stat
==
308 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
311 if (interface
->hw
.mac
.type
!= fm10k_mac_vf
) {
312 for (i
= 0; i
< FM10K_PF_STATS_LEN
; i
++) {
313 p
= (char *)interface
+
314 fm10k_gstrings_pf_stats
[i
].stat_offset
;
315 *(data
++) = (fm10k_gstrings_pf_stats
[i
].sizeof_stat
==
316 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
320 if ((interface
->flags
& FM10K_FLAG_DEBUG_STATS
) && iov_data
) {
321 for (i
= 0; i
< iov_data
->num_vfs
; i
++) {
322 struct fm10k_vf_info
*vf_info
;
323 vf_info
= &iov_data
->vf_info
[i
];
325 /* skip stats if we don't have a vf info */
327 data
+= FM10K_MBX_STATS_LEN
;
331 for (j
= 0; j
< FM10K_MBX_STATS_LEN
; j
++) {
332 p
= (char *)&vf_info
->mbx
+ fm10k_gstrings_mbx_stats
[j
].stat_offset
;
333 *(data
++) = (fm10k_gstrings_mbx_stats
[j
].sizeof_stat
==
334 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
339 for (i
= 0; i
< interface
->hw
.mac
.max_queues
; i
++) {
340 struct fm10k_ring
*ring
;
343 ring
= interface
->tx_ring
[i
];
345 queue_stat
= (u64
*)&ring
->stats
;
346 for (j
= 0; j
< stat_count
; j
++)
347 *(data
++) = ring
? queue_stat
[j
] : 0;
349 ring
= interface
->rx_ring
[i
];
351 queue_stat
= (u64
*)&ring
->stats
;
352 for (j
= 0; j
< stat_count
; j
++)
353 *(data
++) = ring
? queue_stat
[j
] : 0;
357 /* If function below adds more registers this define needs to be updated */
358 #define FM10K_REGS_LEN_Q 29
360 static void fm10k_get_reg_q(struct fm10k_hw
*hw
, u32
*buff
, int i
)
364 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RDBAL(i
));
365 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RDBAH(i
));
366 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RDLEN(i
));
367 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TPH_RXCTRL(i
));
368 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RDH(i
));
369 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RDT(i
));
370 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RXQCTL(i
));
371 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RXDCTL(i
));
372 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RXINT(i
));
373 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_SRRCTL(i
));
374 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QPRC(i
));
375 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QPRDC(i
));
376 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QBRC_L(i
));
377 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QBRC_H(i
));
378 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TDBAL(i
));
379 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TDBAH(i
));
380 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TDLEN(i
));
381 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TPH_TXCTRL(i
));
382 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TDH(i
));
383 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TDT(i
));
384 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TXDCTL(i
));
385 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TXQCTL(i
));
386 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TXINT(i
));
387 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QPTC(i
));
388 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QBTC_L(i
));
389 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QBTC_H(i
));
390 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TQDLOC(i
));
391 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TX_SGLORT(i
));
392 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_PFVTCTL(i
));
394 BUG_ON(idx
!= FM10K_REGS_LEN_Q
);
397 /* If function above adds more registers this define needs to be updated */
398 #define FM10K_REGS_LEN_VSI 43
400 static void fm10k_get_reg_vsi(struct fm10k_hw
*hw
, u32
*buff
, int i
)
404 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_MRQC(i
));
405 for (j
= 0; j
< 10; j
++)
406 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RSSRK(i
, j
));
407 for (j
= 0; j
< 32; j
++)
408 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RETA(i
, j
));
410 BUG_ON(idx
!= FM10K_REGS_LEN_VSI
);
413 static void fm10k_get_regs(struct net_device
*netdev
,
414 struct ethtool_regs
*regs
, void *p
)
416 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
417 struct fm10k_hw
*hw
= &interface
->hw
;
421 regs
->version
= (1 << 24) | (hw
->revision_id
<< 16) | hw
->device_id
;
423 switch (hw
->mac
.type
) {
425 /* General PF Registers */
426 *(buff
++) = fm10k_read_reg(hw
, FM10K_CTRL
);
427 *(buff
++) = fm10k_read_reg(hw
, FM10K_CTRL_EXT
);
428 *(buff
++) = fm10k_read_reg(hw
, FM10K_GCR
);
429 *(buff
++) = fm10k_read_reg(hw
, FM10K_GCR_EXT
);
431 for (i
= 0; i
< 8; i
++) {
432 *(buff
++) = fm10k_read_reg(hw
, FM10K_DGLORTMAP(i
));
433 *(buff
++) = fm10k_read_reg(hw
, FM10K_DGLORTDEC(i
));
436 for (i
= 0; i
< 65; i
++) {
437 fm10k_get_reg_vsi(hw
, buff
, i
);
438 buff
+= FM10K_REGS_LEN_VSI
;
441 *(buff
++) = fm10k_read_reg(hw
, FM10K_DMA_CTRL
);
442 *(buff
++) = fm10k_read_reg(hw
, FM10K_DMA_CTRL2
);
444 for (i
= 0; i
< FM10K_MAX_QUEUES_PF
; i
++) {
445 fm10k_get_reg_q(hw
, buff
, i
);
446 buff
+= FM10K_REGS_LEN_Q
;
449 *(buff
++) = fm10k_read_reg(hw
, FM10K_TPH_CTRL
);
451 for (i
= 0; i
< 8; i
++)
452 *(buff
++) = fm10k_read_reg(hw
, FM10K_INT_MAP(i
));
454 /* Interrupt Throttling Registers */
455 for (i
= 0; i
< 130; i
++)
456 *(buff
++) = fm10k_read_reg(hw
, FM10K_ITR(i
));
460 /* General VF registers */
461 *(buff
++) = fm10k_read_reg(hw
, FM10K_VFCTRL
);
462 *(buff
++) = fm10k_read_reg(hw
, FM10K_VFINT_MAP
);
463 *(buff
++) = fm10k_read_reg(hw
, FM10K_VFSYSTIME
);
465 /* Interrupt Throttling Registers */
466 for (i
= 0; i
< 8; i
++)
467 *(buff
++) = fm10k_read_reg(hw
, FM10K_VFITR(i
));
469 fm10k_get_reg_vsi(hw
, buff
, 0);
470 buff
+= FM10K_REGS_LEN_VSI
;
472 for (i
= 0; i
< FM10K_MAX_QUEUES_POOL
; i
++) {
473 if (i
< hw
->mac
.max_queues
)
474 fm10k_get_reg_q(hw
, buff
, i
);
476 memset(buff
, 0, sizeof(u32
) * FM10K_REGS_LEN_Q
);
477 buff
+= FM10K_REGS_LEN_Q
;
486 /* If function above adds more registers these define need to be updated */
487 #define FM10K_REGS_LEN_PF \
488 (162 + (65 * FM10K_REGS_LEN_VSI) + (FM10K_MAX_QUEUES_PF * FM10K_REGS_LEN_Q))
489 #define FM10K_REGS_LEN_VF \
490 (11 + FM10K_REGS_LEN_VSI + (FM10K_MAX_QUEUES_POOL * FM10K_REGS_LEN_Q))
492 static int fm10k_get_regs_len(struct net_device
*netdev
)
494 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
495 struct fm10k_hw
*hw
= &interface
->hw
;
497 switch (hw
->mac
.type
) {
499 return FM10K_REGS_LEN_PF
* sizeof(u32
);
501 return FM10K_REGS_LEN_VF
* sizeof(u32
);
507 static void fm10k_get_drvinfo(struct net_device
*dev
,
508 struct ethtool_drvinfo
*info
)
510 struct fm10k_intfc
*interface
= netdev_priv(dev
);
512 strncpy(info
->driver
, fm10k_driver_name
,
513 sizeof(info
->driver
) - 1);
514 strncpy(info
->version
, fm10k_driver_version
,
515 sizeof(info
->version
) - 1);
516 strncpy(info
->bus_info
, pci_name(interface
->pdev
),
517 sizeof(info
->bus_info
) - 1);
520 static void fm10k_get_pauseparam(struct net_device
*dev
,
521 struct ethtool_pauseparam
*pause
)
523 struct fm10k_intfc
*interface
= netdev_priv(dev
);
525 /* record fixed values for autoneg and tx pause */
529 pause
->rx_pause
= interface
->rx_pause
? 1 : 0;
532 static int fm10k_set_pauseparam(struct net_device
*dev
,
533 struct ethtool_pauseparam
*pause
)
535 struct fm10k_intfc
*interface
= netdev_priv(dev
);
536 struct fm10k_hw
*hw
= &interface
->hw
;
538 if (pause
->autoneg
|| !pause
->tx_pause
)
541 /* we can only support pause on the PF to avoid head-of-line blocking */
542 if (hw
->mac
.type
== fm10k_mac_pf
)
543 interface
->rx_pause
= pause
->rx_pause
? ~0 : 0;
544 else if (pause
->rx_pause
)
547 if (netif_running(dev
))
548 fm10k_update_rx_drop_en(interface
);
553 static u32
fm10k_get_msglevel(struct net_device
*netdev
)
555 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
557 return interface
->msg_enable
;
560 static void fm10k_set_msglevel(struct net_device
*netdev
, u32 data
)
562 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
564 interface
->msg_enable
= data
;
567 static void fm10k_get_ringparam(struct net_device
*netdev
,
568 struct ethtool_ringparam
*ring
)
570 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
572 ring
->rx_max_pending
= FM10K_MAX_RXD
;
573 ring
->tx_max_pending
= FM10K_MAX_TXD
;
574 ring
->rx_mini_max_pending
= 0;
575 ring
->rx_jumbo_max_pending
= 0;
576 ring
->rx_pending
= interface
->rx_ring_count
;
577 ring
->tx_pending
= interface
->tx_ring_count
;
578 ring
->rx_mini_pending
= 0;
579 ring
->rx_jumbo_pending
= 0;
582 static int fm10k_set_ringparam(struct net_device
*netdev
,
583 struct ethtool_ringparam
*ring
)
585 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
586 struct fm10k_ring
*temp_ring
;
588 u32 new_rx_count
, new_tx_count
;
590 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
593 new_tx_count
= clamp_t(u32
, ring
->tx_pending
,
594 FM10K_MIN_TXD
, FM10K_MAX_TXD
);
595 new_tx_count
= ALIGN(new_tx_count
, FM10K_REQ_TX_DESCRIPTOR_MULTIPLE
);
597 new_rx_count
= clamp_t(u32
, ring
->rx_pending
,
598 FM10K_MIN_RXD
, FM10K_MAX_RXD
);
599 new_rx_count
= ALIGN(new_rx_count
, FM10K_REQ_RX_DESCRIPTOR_MULTIPLE
);
601 if ((new_tx_count
== interface
->tx_ring_count
) &&
602 (new_rx_count
== interface
->rx_ring_count
)) {
607 while (test_and_set_bit(__FM10K_RESETTING
, &interface
->state
))
608 usleep_range(1000, 2000);
610 if (!netif_running(interface
->netdev
)) {
611 for (i
= 0; i
< interface
->num_tx_queues
; i
++)
612 interface
->tx_ring
[i
]->count
= new_tx_count
;
613 for (i
= 0; i
< interface
->num_rx_queues
; i
++)
614 interface
->rx_ring
[i
]->count
= new_rx_count
;
615 interface
->tx_ring_count
= new_tx_count
;
616 interface
->rx_ring_count
= new_rx_count
;
620 /* allocate temporary buffer to store rings in */
621 i
= max_t(int, interface
->num_tx_queues
, interface
->num_rx_queues
);
622 temp_ring
= vmalloc(i
* sizeof(struct fm10k_ring
));
629 fm10k_down(interface
);
631 /* Setup new Tx resources and free the old Tx resources in that order.
632 * We can then assign the new resources to the rings via a memcpy.
633 * The advantage to this approach is that we are guaranteed to still
634 * have resources even in the case of an allocation failure.
636 if (new_tx_count
!= interface
->tx_ring_count
) {
637 for (i
= 0; i
< interface
->num_tx_queues
; i
++) {
638 memcpy(&temp_ring
[i
], interface
->tx_ring
[i
],
639 sizeof(struct fm10k_ring
));
641 temp_ring
[i
].count
= new_tx_count
;
642 err
= fm10k_setup_tx_resources(&temp_ring
[i
]);
646 fm10k_free_tx_resources(&temp_ring
[i
]);
652 for (i
= 0; i
< interface
->num_tx_queues
; i
++) {
653 fm10k_free_tx_resources(interface
->tx_ring
[i
]);
655 memcpy(interface
->tx_ring
[i
], &temp_ring
[i
],
656 sizeof(struct fm10k_ring
));
659 interface
->tx_ring_count
= new_tx_count
;
662 /* Repeat the process for the Rx rings if needed */
663 if (new_rx_count
!= interface
->rx_ring_count
) {
664 for (i
= 0; i
< interface
->num_rx_queues
; i
++) {
665 memcpy(&temp_ring
[i
], interface
->rx_ring
[i
],
666 sizeof(struct fm10k_ring
));
668 temp_ring
[i
].count
= new_rx_count
;
669 err
= fm10k_setup_rx_resources(&temp_ring
[i
]);
673 fm10k_free_rx_resources(&temp_ring
[i
]);
679 for (i
= 0; i
< interface
->num_rx_queues
; i
++) {
680 fm10k_free_rx_resources(interface
->rx_ring
[i
]);
682 memcpy(interface
->rx_ring
[i
], &temp_ring
[i
],
683 sizeof(struct fm10k_ring
));
686 interface
->rx_ring_count
= new_rx_count
;
693 clear_bit(__FM10K_RESETTING
, &interface
->state
);
697 static int fm10k_get_coalesce(struct net_device
*dev
,
698 struct ethtool_coalesce
*ec
)
700 struct fm10k_intfc
*interface
= netdev_priv(dev
);
702 ec
->use_adaptive_tx_coalesce
=
703 !!(interface
->tx_itr
& FM10K_ITR_ADAPTIVE
);
704 ec
->tx_coalesce_usecs
= interface
->tx_itr
& ~FM10K_ITR_ADAPTIVE
;
706 ec
->use_adaptive_rx_coalesce
=
707 !!(interface
->rx_itr
& FM10K_ITR_ADAPTIVE
);
708 ec
->rx_coalesce_usecs
= interface
->rx_itr
& ~FM10K_ITR_ADAPTIVE
;
713 static int fm10k_set_coalesce(struct net_device
*dev
,
714 struct ethtool_coalesce
*ec
)
716 struct fm10k_intfc
*interface
= netdev_priv(dev
);
717 struct fm10k_q_vector
*qv
;
722 if ((ec
->rx_coalesce_usecs
> FM10K_ITR_MAX
) ||
723 (ec
->tx_coalesce_usecs
> FM10K_ITR_MAX
))
726 /* record settings */
727 tx_itr
= ec
->tx_coalesce_usecs
;
728 rx_itr
= ec
->rx_coalesce_usecs
;
730 /* set initial values for adaptive ITR */
731 if (ec
->use_adaptive_tx_coalesce
)
732 tx_itr
= FM10K_ITR_ADAPTIVE
| FM10K_ITR_10K
;
734 if (ec
->use_adaptive_rx_coalesce
)
735 rx_itr
= FM10K_ITR_ADAPTIVE
| FM10K_ITR_20K
;
737 /* update interface */
738 interface
->tx_itr
= tx_itr
;
739 interface
->rx_itr
= rx_itr
;
741 /* update q_vectors */
742 for (i
= 0; i
< interface
->num_q_vectors
; i
++) {
743 qv
= interface
->q_vector
[i
];
751 static int fm10k_get_rss_hash_opts(struct fm10k_intfc
*interface
,
752 struct ethtool_rxnfc
*cmd
)
756 /* Report default options for RSS on fm10k */
757 switch (cmd
->flow_type
) {
760 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
763 if (interface
->flags
& FM10K_FLAG_RSS_FIELD_IPV4_UDP
)
764 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
776 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
779 if (interface
->flags
& FM10K_FLAG_RSS_FIELD_IPV6_UDP
)
780 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
781 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
790 static int fm10k_get_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
,
791 u32 __always_unused
*rule_locs
)
793 struct fm10k_intfc
*interface
= netdev_priv(dev
);
794 int ret
= -EOPNOTSUPP
;
797 case ETHTOOL_GRXRINGS
:
798 cmd
->data
= interface
->num_rx_queues
;
802 ret
= fm10k_get_rss_hash_opts(interface
, cmd
);
811 #define UDP_RSS_FLAGS (FM10K_FLAG_RSS_FIELD_IPV4_UDP | \
812 FM10K_FLAG_RSS_FIELD_IPV6_UDP)
813 static int fm10k_set_rss_hash_opt(struct fm10k_intfc
*interface
,
814 struct ethtool_rxnfc
*nfc
)
816 u32 flags
= interface
->flags
;
818 /* RSS does not support anything other than hashing
819 * to queues on src and dst IPs and ports
821 if (nfc
->data
& ~(RXH_IP_SRC
| RXH_IP_DST
|
822 RXH_L4_B_0_1
| RXH_L4_B_2_3
))
825 switch (nfc
->flow_type
) {
828 if (!(nfc
->data
& RXH_IP_SRC
) ||
829 !(nfc
->data
& RXH_IP_DST
) ||
830 !(nfc
->data
& RXH_L4_B_0_1
) ||
831 !(nfc
->data
& RXH_L4_B_2_3
))
835 if (!(nfc
->data
& RXH_IP_SRC
) ||
836 !(nfc
->data
& RXH_IP_DST
))
838 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
840 flags
&= ~FM10K_FLAG_RSS_FIELD_IPV4_UDP
;
842 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
843 flags
|= FM10K_FLAG_RSS_FIELD_IPV4_UDP
;
850 if (!(nfc
->data
& RXH_IP_SRC
) ||
851 !(nfc
->data
& RXH_IP_DST
))
853 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
855 flags
&= ~FM10K_FLAG_RSS_FIELD_IPV6_UDP
;
857 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
858 flags
|= FM10K_FLAG_RSS_FIELD_IPV6_UDP
;
872 if (!(nfc
->data
& RXH_IP_SRC
) ||
873 !(nfc
->data
& RXH_IP_DST
) ||
874 (nfc
->data
& RXH_L4_B_0_1
) ||
875 (nfc
->data
& RXH_L4_B_2_3
))
882 /* if we changed something we need to update flags */
883 if (flags
!= interface
->flags
) {
884 struct fm10k_hw
*hw
= &interface
->hw
;
887 if ((flags
& UDP_RSS_FLAGS
) &&
888 !(interface
->flags
& UDP_RSS_FLAGS
))
889 netif_warn(interface
, drv
, interface
->netdev
,
890 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
892 interface
->flags
= flags
;
894 /* Perform hash on these packet types */
895 mrqc
= FM10K_MRQC_IPV4
|
896 FM10K_MRQC_TCP_IPV4
|
900 if (flags
& FM10K_FLAG_RSS_FIELD_IPV4_UDP
)
901 mrqc
|= FM10K_MRQC_UDP_IPV4
;
902 if (flags
& FM10K_FLAG_RSS_FIELD_IPV6_UDP
)
903 mrqc
|= FM10K_MRQC_UDP_IPV6
;
905 fm10k_write_reg(hw
, FM10K_MRQC(0), mrqc
);
911 static int fm10k_set_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
)
913 struct fm10k_intfc
*interface
= netdev_priv(dev
);
914 int ret
= -EOPNOTSUPP
;
918 ret
= fm10k_set_rss_hash_opt(interface
, cmd
);
927 static int fm10k_mbx_test(struct fm10k_intfc
*interface
, u64
*data
)
929 struct fm10k_hw
*hw
= &interface
->hw
;
930 struct fm10k_mbx_info
*mbx
= &hw
->mbx
;
931 u32 attr_flag
, test_msg
[6];
932 unsigned long timeout
;
935 /* For now this is a VF only feature */
936 if (hw
->mac
.type
!= fm10k_mac_vf
)
939 /* loop through both nested and unnested attribute types */
940 for (attr_flag
= (1 << FM10K_TEST_MSG_UNSET
);
941 attr_flag
< (1 << (2 * FM10K_TEST_MSG_NESTED
));
942 attr_flag
+= attr_flag
) {
943 /* generate message to be tested */
944 fm10k_tlv_msg_test_create(test_msg
, attr_flag
);
946 fm10k_mbx_lock(interface
);
947 mbx
->test_result
= FM10K_NOT_IMPLEMENTED
;
948 err
= mbx
->ops
.enqueue_tx(hw
, mbx
, test_msg
);
949 fm10k_mbx_unlock(interface
);
951 /* wait up to 1 second for response */
952 timeout
= jiffies
+ HZ
;
957 usleep_range(500, 1000);
959 fm10k_mbx_lock(interface
);
960 mbx
->ops
.process(hw
, mbx
);
961 fm10k_mbx_unlock(interface
);
963 err
= mbx
->test_result
;
966 } while (time_is_after_jiffies(timeout
));
968 /* reporting errors */
974 *data
= err
< 0 ? (attr_flag
) : (err
> 0);
978 static void fm10k_self_test(struct net_device
*dev
,
979 struct ethtool_test
*eth_test
, u64
*data
)
981 struct fm10k_intfc
*interface
= netdev_priv(dev
);
982 struct fm10k_hw
*hw
= &interface
->hw
;
984 memset(data
, 0, sizeof(*data
) * FM10K_TEST_LEN
);
986 if (FM10K_REMOVED(hw
)) {
987 netif_err(interface
, drv
, dev
,
988 "Interface removed - test blocked\n");
989 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
993 if (fm10k_mbx_test(interface
, &data
[FM10K_TEST_MBX
]))
994 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
997 static u32
fm10k_get_priv_flags(struct net_device
*netdev
)
999 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1002 if (interface
->flags
& FM10K_FLAG_DEBUG_STATS
)
1003 priv_flags
|= 1 << FM10K_PRV_FLAG_DEBUG_STATS
;
1008 static int fm10k_set_priv_flags(struct net_device
*netdev
, u32 priv_flags
)
1010 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1012 if (priv_flags
>= (1 << FM10K_PRV_FLAG_LEN
))
1015 if (priv_flags
& (1 << FM10K_PRV_FLAG_DEBUG_STATS
))
1016 interface
->flags
|= FM10K_FLAG_DEBUG_STATS
;
1018 interface
->flags
&= ~FM10K_FLAG_DEBUG_STATS
;
1024 static u32
fm10k_get_reta_size(struct net_device __always_unused
*netdev
)
1026 return FM10K_RETA_SIZE
* FM10K_RETA_ENTRIES_PER_REG
;
1029 static int fm10k_get_reta(struct net_device
*netdev
, u32
*indir
)
1031 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1037 for (i
= 0; i
< FM10K_RETA_SIZE
; i
++, indir
+= 4) {
1038 u32 reta
= interface
->reta
[i
];
1040 indir
[0] = (reta
<< 24) >> 24;
1041 indir
[1] = (reta
<< 16) >> 24;
1042 indir
[2] = (reta
<< 8) >> 24;
1043 indir
[3] = (reta
) >> 24;
1049 static int fm10k_set_reta(struct net_device
*netdev
, const u32
*indir
)
1051 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1052 struct fm10k_hw
*hw
= &interface
->hw
;
1059 /* Verify user input. */
1060 rss_i
= interface
->ring_feature
[RING_F_RSS
].indices
;
1061 for (i
= fm10k_get_reta_size(netdev
); i
--;) {
1062 if (indir
[i
] < rss_i
)
1067 /* record entries to reta table */
1068 for (i
= 0; i
< FM10K_RETA_SIZE
; i
++, indir
+= 4) {
1069 u32 reta
= indir
[0] |
1074 if (interface
->reta
[i
] == reta
)
1077 interface
->reta
[i
] = reta
;
1078 fm10k_write_reg(hw
, FM10K_RETA(0, i
), reta
);
1084 static u32
fm10k_get_rssrk_size(struct net_device __always_unused
*netdev
)
1086 return FM10K_RSSRK_SIZE
* FM10K_RSSRK_ENTRIES_PER_REG
;
1089 static int fm10k_get_rssh(struct net_device
*netdev
, u32
*indir
, u8
*key
,
1092 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1096 *hfunc
= ETH_RSS_HASH_TOP
;
1098 err
= fm10k_get_reta(netdev
, indir
);
1102 for (i
= 0; i
< FM10K_RSSRK_SIZE
; i
++, key
+= 4)
1103 *(__le32
*)key
= cpu_to_le32(interface
->rssrk
[i
]);
1108 static int fm10k_set_rssh(struct net_device
*netdev
, const u32
*indir
,
1109 const u8
*key
, const u8 hfunc
)
1111 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1112 struct fm10k_hw
*hw
= &interface
->hw
;
1115 /* We do not allow change in unsupported parameters */
1116 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
)
1119 err
= fm10k_set_reta(netdev
, indir
);
1123 for (i
= 0; i
< FM10K_RSSRK_SIZE
; i
++, key
+= 4) {
1124 u32 rssrk
= le32_to_cpu(*(__le32
*)key
);
1126 if (interface
->rssrk
[i
] == rssrk
)
1129 interface
->rssrk
[i
] = rssrk
;
1130 fm10k_write_reg(hw
, FM10K_RSSRK(0, i
), rssrk
);
1136 static unsigned int fm10k_max_channels(struct net_device
*dev
)
1138 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1139 unsigned int max_combined
= interface
->hw
.mac
.max_queues
;
1140 u8 tcs
= netdev_get_num_tc(dev
);
1142 /* For QoS report channels per traffic class */
1144 max_combined
= 1 << (fls(max_combined
/ tcs
) - 1);
1146 return max_combined
;
1149 static void fm10k_get_channels(struct net_device
*dev
,
1150 struct ethtool_channels
*ch
)
1152 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1153 struct fm10k_hw
*hw
= &interface
->hw
;
1155 /* report maximum channels */
1156 ch
->max_combined
= fm10k_max_channels(dev
);
1158 /* report info for other vector */
1159 ch
->max_other
= NON_Q_VECTORS(hw
);
1160 ch
->other_count
= ch
->max_other
;
1162 /* record RSS queues */
1163 ch
->combined_count
= interface
->ring_feature
[RING_F_RSS
].indices
;
1166 static int fm10k_set_channels(struct net_device
*dev
,
1167 struct ethtool_channels
*ch
)
1169 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1170 unsigned int count
= ch
->combined_count
;
1171 struct fm10k_hw
*hw
= &interface
->hw
;
1173 /* verify they are not requesting separate vectors */
1174 if (!count
|| ch
->rx_count
|| ch
->tx_count
)
1177 /* verify other_count has not changed */
1178 if (ch
->other_count
!= NON_Q_VECTORS(hw
))
1181 /* verify the number of channels does not exceed hardware limits */
1182 if (count
> fm10k_max_channels(dev
))
1185 interface
->ring_feature
[RING_F_RSS
].limit
= count
;
1187 /* use setup TC to update any traffic class queue mapping */
1188 return fm10k_setup_tc(dev
, netdev_get_num_tc(dev
));
1191 static int fm10k_get_ts_info(struct net_device
*dev
,
1192 struct ethtool_ts_info
*info
)
1194 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1196 info
->so_timestamping
=
1197 SOF_TIMESTAMPING_TX_SOFTWARE
|
1198 SOF_TIMESTAMPING_RX_SOFTWARE
|
1199 SOF_TIMESTAMPING_SOFTWARE
|
1200 SOF_TIMESTAMPING_TX_HARDWARE
|
1201 SOF_TIMESTAMPING_RX_HARDWARE
|
1202 SOF_TIMESTAMPING_RAW_HARDWARE
;
1204 if (interface
->ptp_clock
)
1205 info
->phc_index
= ptp_clock_index(interface
->ptp_clock
);
1207 info
->phc_index
= -1;
1209 info
->tx_types
= (1 << HWTSTAMP_TX_OFF
) |
1210 (1 << HWTSTAMP_TX_ON
);
1212 info
->rx_filters
= (1 << HWTSTAMP_FILTER_NONE
) |
1213 (1 << HWTSTAMP_FILTER_ALL
);
1218 static const struct ethtool_ops fm10k_ethtool_ops
= {
1219 .get_strings
= fm10k_get_strings
,
1220 .get_sset_count
= fm10k_get_sset_count
,
1221 .get_ethtool_stats
= fm10k_get_ethtool_stats
,
1222 .get_drvinfo
= fm10k_get_drvinfo
,
1223 .get_link
= ethtool_op_get_link
,
1224 .get_pauseparam
= fm10k_get_pauseparam
,
1225 .set_pauseparam
= fm10k_set_pauseparam
,
1226 .get_msglevel
= fm10k_get_msglevel
,
1227 .set_msglevel
= fm10k_set_msglevel
,
1228 .get_ringparam
= fm10k_get_ringparam
,
1229 .set_ringparam
= fm10k_set_ringparam
,
1230 .get_coalesce
= fm10k_get_coalesce
,
1231 .set_coalesce
= fm10k_set_coalesce
,
1232 .get_rxnfc
= fm10k_get_rxnfc
,
1233 .set_rxnfc
= fm10k_set_rxnfc
,
1234 .get_regs
= fm10k_get_regs
,
1235 .get_regs_len
= fm10k_get_regs_len
,
1236 .self_test
= fm10k_self_test
,
1237 .get_priv_flags
= fm10k_get_priv_flags
,
1238 .set_priv_flags
= fm10k_set_priv_flags
,
1239 .get_rxfh_indir_size
= fm10k_get_reta_size
,
1240 .get_rxfh_key_size
= fm10k_get_rssrk_size
,
1241 .get_rxfh
= fm10k_get_rssh
,
1242 .set_rxfh
= fm10k_set_rssh
,
1243 .get_channels
= fm10k_get_channels
,
1244 .set_channels
= fm10k_set_channels
,
1245 .get_ts_info
= fm10k_get_ts_info
,
1248 void fm10k_set_ethtool_ops(struct net_device
*dev
)
1250 dev
->ethtool_ops
= &fm10k_ethtool_ops
;