1 /* Intel(R) Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2016 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
),
82 static const struct fm10k_stats fm10k_gstrings_pf_stats
[] = {
83 FM10K_STAT("timeout", stats
.timeout
.count
),
84 FM10K_STAT("ur", stats
.ur
.count
),
85 FM10K_STAT("ca", stats
.ca
.count
),
86 FM10K_STAT("um", stats
.um
.count
),
87 FM10K_STAT("xec", stats
.xec
.count
),
88 FM10K_STAT("vlan_drop", stats
.vlan_drop
.count
),
89 FM10K_STAT("loopback_drop", stats
.loopback_drop
.count
),
90 FM10K_STAT("nodesc_drop", stats
.nodesc_drop
.count
),
93 #define FM10K_MBX_STAT(_name, _stat) { \
94 .stat_string = _name, \
95 .sizeof_stat = FIELD_SIZEOF(struct fm10k_mbx_info, _stat), \
96 .stat_offset = offsetof(struct fm10k_mbx_info, _stat) \
99 static const struct fm10k_stats fm10k_gstrings_mbx_stats
[] = {
100 FM10K_MBX_STAT("mbx_tx_busy", tx_busy
),
101 FM10K_MBX_STAT("mbx_tx_dropped", tx_dropped
),
102 FM10K_MBX_STAT("mbx_tx_messages", tx_messages
),
103 FM10K_MBX_STAT("mbx_tx_dwords", tx_dwords
),
104 FM10K_MBX_STAT("mbx_tx_mbmem_pulled", tx_mbmem_pulled
),
105 FM10K_MBX_STAT("mbx_rx_messages", rx_messages
),
106 FM10K_MBX_STAT("mbx_rx_dwords", rx_dwords
),
107 FM10K_MBX_STAT("mbx_rx_parse_err", rx_parse_err
),
108 FM10K_MBX_STAT("mbx_rx_mbmem_pushed", rx_mbmem_pushed
),
111 #define FM10K_QUEUE_STAT(_name, _stat) { \
112 .stat_string = _name, \
113 .sizeof_stat = FIELD_SIZEOF(struct fm10k_ring, _stat), \
114 .stat_offset = offsetof(struct fm10k_ring, _stat) \
117 static const struct fm10k_stats fm10k_gstrings_queue_stats
[] = {
118 FM10K_QUEUE_STAT("packets", stats
.packets
),
119 FM10K_QUEUE_STAT("bytes", stats
.bytes
),
122 #define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats)
123 #define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats)
124 #define FM10K_MBX_STATS_LEN ARRAY_SIZE(fm10k_gstrings_mbx_stats)
125 #define FM10K_QUEUE_STATS_LEN ARRAY_SIZE(fm10k_gstrings_queue_stats)
127 #define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \
128 FM10K_NETDEV_STATS_LEN + \
131 static const char fm10k_gstrings_test
[][ETH_GSTRING_LEN
] = {
132 "Mailbox test (on/offline)"
135 #define FM10K_TEST_LEN (sizeof(fm10k_gstrings_test) / ETH_GSTRING_LEN)
137 enum fm10k_self_test_types
{
139 FM10K_TEST_MAX
= FM10K_TEST_LEN
146 static const char fm10k_prv_flags
[FM10K_PRV_FLAG_LEN
][ETH_GSTRING_LEN
] = {
149 static void fm10k_add_stat_strings(char **p
, const char *prefix
,
150 const struct fm10k_stats stats
[],
151 const unsigned int size
)
155 for (i
= 0; i
< size
; i
++) {
156 snprintf(*p
, ETH_GSTRING_LEN
, "%s%s",
157 prefix
, stats
[i
].stat_string
);
158 *p
+= ETH_GSTRING_LEN
;
162 static void fm10k_get_stat_strings(struct net_device
*dev
, u8
*data
)
164 struct fm10k_intfc
*interface
= netdev_priv(dev
);
165 char *p
= (char *)data
;
168 fm10k_add_stat_strings(&p
, "", fm10k_gstrings_net_stats
,
169 FM10K_NETDEV_STATS_LEN
);
171 fm10k_add_stat_strings(&p
, "", fm10k_gstrings_global_stats
,
172 FM10K_GLOBAL_STATS_LEN
);
174 fm10k_add_stat_strings(&p
, "", fm10k_gstrings_mbx_stats
,
175 FM10K_MBX_STATS_LEN
);
177 if (interface
->hw
.mac
.type
!= fm10k_mac_vf
)
178 fm10k_add_stat_strings(&p
, "", fm10k_gstrings_pf_stats
,
181 for (i
= 0; i
< interface
->hw
.mac
.max_queues
; i
++) {
182 char prefix
[ETH_GSTRING_LEN
];
184 snprintf(prefix
, ETH_GSTRING_LEN
, "tx_queue_%u_", i
);
185 fm10k_add_stat_strings(&p
, prefix
,
186 fm10k_gstrings_queue_stats
,
187 FM10K_QUEUE_STATS_LEN
);
189 snprintf(prefix
, ETH_GSTRING_LEN
, "rx_queue_%u_", i
);
190 fm10k_add_stat_strings(&p
, prefix
,
191 fm10k_gstrings_queue_stats
,
192 FM10K_QUEUE_STATS_LEN
);
196 static void fm10k_get_strings(struct net_device
*dev
,
197 u32 stringset
, u8
*data
)
199 char *p
= (char *)data
;
203 memcpy(data
, *fm10k_gstrings_test
,
204 FM10K_TEST_LEN
* ETH_GSTRING_LEN
);
207 fm10k_get_stat_strings(dev
, data
);
209 case ETH_SS_PRIV_FLAGS
:
210 memcpy(p
, fm10k_prv_flags
,
211 FM10K_PRV_FLAG_LEN
* ETH_GSTRING_LEN
);
216 static int fm10k_get_sset_count(struct net_device
*dev
, int sset
)
218 struct fm10k_intfc
*interface
= netdev_priv(dev
);
219 struct fm10k_hw
*hw
= &interface
->hw
;
220 int stats_len
= FM10K_STATIC_STATS_LEN
;
224 return FM10K_TEST_LEN
;
226 stats_len
+= hw
->mac
.max_queues
* 2 * FM10K_QUEUE_STATS_LEN
;
228 if (hw
->mac
.type
!= fm10k_mac_vf
)
229 stats_len
+= FM10K_PF_STATS_LEN
;
232 case ETH_SS_PRIV_FLAGS
:
233 return FM10K_PRV_FLAG_LEN
;
239 static void fm10k_add_ethtool_stats(u64
**data
, void *pointer
,
240 const struct fm10k_stats stats
[],
241 const unsigned int size
)
247 /* memory is not zero allocated so we have to clear it */
248 for (i
= 0; i
< size
; i
++)
253 for (i
= 0; i
< size
; i
++) {
254 p
= (char *)pointer
+ stats
[i
].stat_offset
;
256 switch (stats
[i
].sizeof_stat
) {
258 *((*data
)++) = *(u64
*)p
;
261 *((*data
)++) = *(u32
*)p
;
264 *((*data
)++) = *(u16
*)p
;
267 *((*data
)++) = *(u8
*)p
;
275 static void fm10k_get_ethtool_stats(struct net_device
*netdev
,
276 struct ethtool_stats __always_unused
*stats
,
279 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
280 struct net_device_stats
*net_stats
= &netdev
->stats
;
283 fm10k_update_stats(interface
);
285 fm10k_add_ethtool_stats(&data
, net_stats
, fm10k_gstrings_net_stats
,
286 FM10K_NETDEV_STATS_LEN
);
288 fm10k_add_ethtool_stats(&data
, interface
, fm10k_gstrings_global_stats
,
289 FM10K_GLOBAL_STATS_LEN
);
291 fm10k_add_ethtool_stats(&data
, &interface
->hw
.mbx
,
292 fm10k_gstrings_mbx_stats
,
293 FM10K_MBX_STATS_LEN
);
295 if (interface
->hw
.mac
.type
!= fm10k_mac_vf
) {
296 fm10k_add_ethtool_stats(&data
, interface
,
297 fm10k_gstrings_pf_stats
,
301 for (i
= 0; i
< interface
->hw
.mac
.max_queues
; i
++) {
302 struct fm10k_ring
*ring
;
304 ring
= interface
->tx_ring
[i
];
305 fm10k_add_ethtool_stats(&data
, ring
,
306 fm10k_gstrings_queue_stats
,
307 FM10K_QUEUE_STATS_LEN
);
309 ring
= interface
->rx_ring
[i
];
310 fm10k_add_ethtool_stats(&data
, ring
,
311 fm10k_gstrings_queue_stats
,
312 FM10K_QUEUE_STATS_LEN
);
316 /* If function below adds more registers this define needs to be updated */
317 #define FM10K_REGS_LEN_Q 29
319 static void fm10k_get_reg_q(struct fm10k_hw
*hw
, u32
*buff
, int i
)
323 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RDBAL(i
));
324 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RDBAH(i
));
325 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RDLEN(i
));
326 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TPH_RXCTRL(i
));
327 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RDH(i
));
328 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RDT(i
));
329 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RXQCTL(i
));
330 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RXDCTL(i
));
331 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RXINT(i
));
332 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_SRRCTL(i
));
333 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QPRC(i
));
334 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QPRDC(i
));
335 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QBRC_L(i
));
336 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QBRC_H(i
));
337 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TDBAL(i
));
338 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TDBAH(i
));
339 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TDLEN(i
));
340 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TPH_TXCTRL(i
));
341 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TDH(i
));
342 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TDT(i
));
343 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TXDCTL(i
));
344 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TXQCTL(i
));
345 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TXINT(i
));
346 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QPTC(i
));
347 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QBTC_L(i
));
348 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_QBTC_H(i
));
349 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TQDLOC(i
));
350 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_TX_SGLORT(i
));
351 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_PFVTCTL(i
));
353 BUG_ON(idx
!= FM10K_REGS_LEN_Q
);
356 /* If function above adds more registers this define needs to be updated */
357 #define FM10K_REGS_LEN_VSI 43
359 static void fm10k_get_reg_vsi(struct fm10k_hw
*hw
, u32
*buff
, int i
)
363 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_MRQC(i
));
364 for (j
= 0; j
< 10; j
++)
365 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RSSRK(i
, j
));
366 for (j
= 0; j
< 32; j
++)
367 buff
[idx
++] = fm10k_read_reg(hw
, FM10K_RETA(i
, j
));
369 BUG_ON(idx
!= FM10K_REGS_LEN_VSI
);
372 static void fm10k_get_regs(struct net_device
*netdev
,
373 struct ethtool_regs
*regs
, void *p
)
375 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
376 struct fm10k_hw
*hw
= &interface
->hw
;
380 regs
->version
= BIT(24) | (hw
->revision_id
<< 16) | hw
->device_id
;
382 switch (hw
->mac
.type
) {
384 /* General PF Registers */
385 *(buff
++) = fm10k_read_reg(hw
, FM10K_CTRL
);
386 *(buff
++) = fm10k_read_reg(hw
, FM10K_CTRL_EXT
);
387 *(buff
++) = fm10k_read_reg(hw
, FM10K_GCR
);
388 *(buff
++) = fm10k_read_reg(hw
, FM10K_GCR_EXT
);
390 for (i
= 0; i
< 8; i
++) {
391 *(buff
++) = fm10k_read_reg(hw
, FM10K_DGLORTMAP(i
));
392 *(buff
++) = fm10k_read_reg(hw
, FM10K_DGLORTDEC(i
));
395 for (i
= 0; i
< 65; i
++) {
396 fm10k_get_reg_vsi(hw
, buff
, i
);
397 buff
+= FM10K_REGS_LEN_VSI
;
400 *(buff
++) = fm10k_read_reg(hw
, FM10K_DMA_CTRL
);
401 *(buff
++) = fm10k_read_reg(hw
, FM10K_DMA_CTRL2
);
403 for (i
= 0; i
< FM10K_MAX_QUEUES_PF
; i
++) {
404 fm10k_get_reg_q(hw
, buff
, i
);
405 buff
+= FM10K_REGS_LEN_Q
;
408 *(buff
++) = fm10k_read_reg(hw
, FM10K_TPH_CTRL
);
410 for (i
= 0; i
< 8; i
++)
411 *(buff
++) = fm10k_read_reg(hw
, FM10K_INT_MAP(i
));
413 /* Interrupt Throttling Registers */
414 for (i
= 0; i
< 130; i
++)
415 *(buff
++) = fm10k_read_reg(hw
, FM10K_ITR(i
));
419 /* General VF registers */
420 *(buff
++) = fm10k_read_reg(hw
, FM10K_VFCTRL
);
421 *(buff
++) = fm10k_read_reg(hw
, FM10K_VFINT_MAP
);
422 *(buff
++) = fm10k_read_reg(hw
, FM10K_VFSYSTIME
);
424 /* Interrupt Throttling Registers */
425 for (i
= 0; i
< 8; i
++)
426 *(buff
++) = fm10k_read_reg(hw
, FM10K_VFITR(i
));
428 fm10k_get_reg_vsi(hw
, buff
, 0);
429 buff
+= FM10K_REGS_LEN_VSI
;
431 for (i
= 0; i
< FM10K_MAX_QUEUES_POOL
; i
++) {
432 if (i
< hw
->mac
.max_queues
)
433 fm10k_get_reg_q(hw
, buff
, i
);
435 memset(buff
, 0, sizeof(u32
) * FM10K_REGS_LEN_Q
);
436 buff
+= FM10K_REGS_LEN_Q
;
445 /* If function above adds more registers these define need to be updated */
446 #define FM10K_REGS_LEN_PF \
447 (162 + (65 * FM10K_REGS_LEN_VSI) + (FM10K_MAX_QUEUES_PF * FM10K_REGS_LEN_Q))
448 #define FM10K_REGS_LEN_VF \
449 (11 + FM10K_REGS_LEN_VSI + (FM10K_MAX_QUEUES_POOL * FM10K_REGS_LEN_Q))
451 static int fm10k_get_regs_len(struct net_device
*netdev
)
453 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
454 struct fm10k_hw
*hw
= &interface
->hw
;
456 switch (hw
->mac
.type
) {
458 return FM10K_REGS_LEN_PF
* sizeof(u32
);
460 return FM10K_REGS_LEN_VF
* sizeof(u32
);
466 static void fm10k_get_drvinfo(struct net_device
*dev
,
467 struct ethtool_drvinfo
*info
)
469 struct fm10k_intfc
*interface
= netdev_priv(dev
);
471 strncpy(info
->driver
, fm10k_driver_name
,
472 sizeof(info
->driver
) - 1);
473 strncpy(info
->version
, fm10k_driver_version
,
474 sizeof(info
->version
) - 1);
475 strncpy(info
->bus_info
, pci_name(interface
->pdev
),
476 sizeof(info
->bus_info
) - 1);
479 static void fm10k_get_pauseparam(struct net_device
*dev
,
480 struct ethtool_pauseparam
*pause
)
482 struct fm10k_intfc
*interface
= netdev_priv(dev
);
484 /* record fixed values for autoneg and tx pause */
488 pause
->rx_pause
= interface
->rx_pause
? 1 : 0;
491 static int fm10k_set_pauseparam(struct net_device
*dev
,
492 struct ethtool_pauseparam
*pause
)
494 struct fm10k_intfc
*interface
= netdev_priv(dev
);
495 struct fm10k_hw
*hw
= &interface
->hw
;
497 if (pause
->autoneg
|| !pause
->tx_pause
)
500 /* we can only support pause on the PF to avoid head-of-line blocking */
501 if (hw
->mac
.type
== fm10k_mac_pf
)
502 interface
->rx_pause
= pause
->rx_pause
? ~0 : 0;
503 else if (pause
->rx_pause
)
506 if (netif_running(dev
))
507 fm10k_update_rx_drop_en(interface
);
512 static u32
fm10k_get_msglevel(struct net_device
*netdev
)
514 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
516 return interface
->msg_enable
;
519 static void fm10k_set_msglevel(struct net_device
*netdev
, u32 data
)
521 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
523 interface
->msg_enable
= data
;
526 static void fm10k_get_ringparam(struct net_device
*netdev
,
527 struct ethtool_ringparam
*ring
)
529 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
531 ring
->rx_max_pending
= FM10K_MAX_RXD
;
532 ring
->tx_max_pending
= FM10K_MAX_TXD
;
533 ring
->rx_mini_max_pending
= 0;
534 ring
->rx_jumbo_max_pending
= 0;
535 ring
->rx_pending
= interface
->rx_ring_count
;
536 ring
->tx_pending
= interface
->tx_ring_count
;
537 ring
->rx_mini_pending
= 0;
538 ring
->rx_jumbo_pending
= 0;
541 static int fm10k_set_ringparam(struct net_device
*netdev
,
542 struct ethtool_ringparam
*ring
)
544 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
545 struct fm10k_ring
*temp_ring
;
547 u32 new_rx_count
, new_tx_count
;
549 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
552 new_tx_count
= clamp_t(u32
, ring
->tx_pending
,
553 FM10K_MIN_TXD
, FM10K_MAX_TXD
);
554 new_tx_count
= ALIGN(new_tx_count
, FM10K_REQ_TX_DESCRIPTOR_MULTIPLE
);
556 new_rx_count
= clamp_t(u32
, ring
->rx_pending
,
557 FM10K_MIN_RXD
, FM10K_MAX_RXD
);
558 new_rx_count
= ALIGN(new_rx_count
, FM10K_REQ_RX_DESCRIPTOR_MULTIPLE
);
560 if ((new_tx_count
== interface
->tx_ring_count
) &&
561 (new_rx_count
== interface
->rx_ring_count
)) {
566 while (test_and_set_bit(__FM10K_RESETTING
, &interface
->state
))
567 usleep_range(1000, 2000);
569 if (!netif_running(interface
->netdev
)) {
570 for (i
= 0; i
< interface
->num_tx_queues
; i
++)
571 interface
->tx_ring
[i
]->count
= new_tx_count
;
572 for (i
= 0; i
< interface
->num_rx_queues
; i
++)
573 interface
->rx_ring
[i
]->count
= new_rx_count
;
574 interface
->tx_ring_count
= new_tx_count
;
575 interface
->rx_ring_count
= new_rx_count
;
579 /* allocate temporary buffer to store rings in */
580 i
= max_t(int, interface
->num_tx_queues
, interface
->num_rx_queues
);
581 temp_ring
= vmalloc(i
* sizeof(struct fm10k_ring
));
588 fm10k_down(interface
);
590 /* Setup new Tx resources and free the old Tx resources in that order.
591 * We can then assign the new resources to the rings via a memcpy.
592 * The advantage to this approach is that we are guaranteed to still
593 * have resources even in the case of an allocation failure.
595 if (new_tx_count
!= interface
->tx_ring_count
) {
596 for (i
= 0; i
< interface
->num_tx_queues
; i
++) {
597 memcpy(&temp_ring
[i
], interface
->tx_ring
[i
],
598 sizeof(struct fm10k_ring
));
600 temp_ring
[i
].count
= new_tx_count
;
601 err
= fm10k_setup_tx_resources(&temp_ring
[i
]);
605 fm10k_free_tx_resources(&temp_ring
[i
]);
611 for (i
= 0; i
< interface
->num_tx_queues
; i
++) {
612 fm10k_free_tx_resources(interface
->tx_ring
[i
]);
614 memcpy(interface
->tx_ring
[i
], &temp_ring
[i
],
615 sizeof(struct fm10k_ring
));
618 interface
->tx_ring_count
= new_tx_count
;
621 /* Repeat the process for the Rx rings if needed */
622 if (new_rx_count
!= interface
->rx_ring_count
) {
623 for (i
= 0; i
< interface
->num_rx_queues
; i
++) {
624 memcpy(&temp_ring
[i
], interface
->rx_ring
[i
],
625 sizeof(struct fm10k_ring
));
627 temp_ring
[i
].count
= new_rx_count
;
628 err
= fm10k_setup_rx_resources(&temp_ring
[i
]);
632 fm10k_free_rx_resources(&temp_ring
[i
]);
638 for (i
= 0; i
< interface
->num_rx_queues
; i
++) {
639 fm10k_free_rx_resources(interface
->rx_ring
[i
]);
641 memcpy(interface
->rx_ring
[i
], &temp_ring
[i
],
642 sizeof(struct fm10k_ring
));
645 interface
->rx_ring_count
= new_rx_count
;
652 clear_bit(__FM10K_RESETTING
, &interface
->state
);
656 static int fm10k_get_coalesce(struct net_device
*dev
,
657 struct ethtool_coalesce
*ec
)
659 struct fm10k_intfc
*interface
= netdev_priv(dev
);
661 ec
->use_adaptive_tx_coalesce
= ITR_IS_ADAPTIVE(interface
->tx_itr
);
662 ec
->tx_coalesce_usecs
= interface
->tx_itr
& ~FM10K_ITR_ADAPTIVE
;
664 ec
->use_adaptive_rx_coalesce
= ITR_IS_ADAPTIVE(interface
->rx_itr
);
665 ec
->rx_coalesce_usecs
= interface
->rx_itr
& ~FM10K_ITR_ADAPTIVE
;
670 static int fm10k_set_coalesce(struct net_device
*dev
,
671 struct ethtool_coalesce
*ec
)
673 struct fm10k_intfc
*interface
= netdev_priv(dev
);
674 struct fm10k_q_vector
*qv
;
679 if ((ec
->rx_coalesce_usecs
> FM10K_ITR_MAX
) ||
680 (ec
->tx_coalesce_usecs
> FM10K_ITR_MAX
))
683 /* record settings */
684 tx_itr
= ec
->tx_coalesce_usecs
;
685 rx_itr
= ec
->rx_coalesce_usecs
;
687 /* set initial values for adaptive ITR */
688 if (ec
->use_adaptive_tx_coalesce
)
689 tx_itr
= FM10K_ITR_ADAPTIVE
| FM10K_TX_ITR_DEFAULT
;
691 if (ec
->use_adaptive_rx_coalesce
)
692 rx_itr
= FM10K_ITR_ADAPTIVE
| FM10K_RX_ITR_DEFAULT
;
694 /* update interface */
695 interface
->tx_itr
= tx_itr
;
696 interface
->rx_itr
= rx_itr
;
698 /* update q_vectors */
699 for (i
= 0; i
< interface
->num_q_vectors
; i
++) {
700 qv
= interface
->q_vector
[i
];
708 static int fm10k_get_rss_hash_opts(struct fm10k_intfc
*interface
,
709 struct ethtool_rxnfc
*cmd
)
713 /* Report default options for RSS on fm10k */
714 switch (cmd
->flow_type
) {
717 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
720 if (interface
->flags
& FM10K_FLAG_RSS_FIELD_IPV4_UDP
)
721 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
733 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
736 if (interface
->flags
& FM10K_FLAG_RSS_FIELD_IPV6_UDP
)
737 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
738 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
747 static int fm10k_get_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
,
748 u32 __always_unused
*rule_locs
)
750 struct fm10k_intfc
*interface
= netdev_priv(dev
);
751 int ret
= -EOPNOTSUPP
;
754 case ETHTOOL_GRXRINGS
:
755 cmd
->data
= interface
->num_rx_queues
;
759 ret
= fm10k_get_rss_hash_opts(interface
, cmd
);
768 #define UDP_RSS_FLAGS (FM10K_FLAG_RSS_FIELD_IPV4_UDP | \
769 FM10K_FLAG_RSS_FIELD_IPV6_UDP)
770 static int fm10k_set_rss_hash_opt(struct fm10k_intfc
*interface
,
771 struct ethtool_rxnfc
*nfc
)
773 u32 flags
= interface
->flags
;
775 /* RSS does not support anything other than hashing
776 * to queues on src and dst IPs and ports
778 if (nfc
->data
& ~(RXH_IP_SRC
| RXH_IP_DST
|
779 RXH_L4_B_0_1
| RXH_L4_B_2_3
))
782 switch (nfc
->flow_type
) {
785 if (!(nfc
->data
& RXH_IP_SRC
) ||
786 !(nfc
->data
& RXH_IP_DST
) ||
787 !(nfc
->data
& RXH_L4_B_0_1
) ||
788 !(nfc
->data
& RXH_L4_B_2_3
))
792 if (!(nfc
->data
& RXH_IP_SRC
) ||
793 !(nfc
->data
& RXH_IP_DST
))
795 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
797 flags
&= ~FM10K_FLAG_RSS_FIELD_IPV4_UDP
;
799 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
800 flags
|= FM10K_FLAG_RSS_FIELD_IPV4_UDP
;
807 if (!(nfc
->data
& RXH_IP_SRC
) ||
808 !(nfc
->data
& RXH_IP_DST
))
810 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
812 flags
&= ~FM10K_FLAG_RSS_FIELD_IPV6_UDP
;
814 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
815 flags
|= FM10K_FLAG_RSS_FIELD_IPV6_UDP
;
829 if (!(nfc
->data
& RXH_IP_SRC
) ||
830 !(nfc
->data
& RXH_IP_DST
) ||
831 (nfc
->data
& RXH_L4_B_0_1
) ||
832 (nfc
->data
& RXH_L4_B_2_3
))
839 /* if we changed something we need to update flags */
840 if (flags
!= interface
->flags
) {
841 struct fm10k_hw
*hw
= &interface
->hw
;
844 if ((flags
& UDP_RSS_FLAGS
) &&
845 !(interface
->flags
& UDP_RSS_FLAGS
))
846 netif_warn(interface
, drv
, interface
->netdev
,
847 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
849 interface
->flags
= flags
;
851 /* Perform hash on these packet types */
852 mrqc
= FM10K_MRQC_IPV4
|
853 FM10K_MRQC_TCP_IPV4
|
857 if (flags
& FM10K_FLAG_RSS_FIELD_IPV4_UDP
)
858 mrqc
|= FM10K_MRQC_UDP_IPV4
;
859 if (flags
& FM10K_FLAG_RSS_FIELD_IPV6_UDP
)
860 mrqc
|= FM10K_MRQC_UDP_IPV6
;
862 fm10k_write_reg(hw
, FM10K_MRQC(0), mrqc
);
868 static int fm10k_set_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
)
870 struct fm10k_intfc
*interface
= netdev_priv(dev
);
871 int ret
= -EOPNOTSUPP
;
875 ret
= fm10k_set_rss_hash_opt(interface
, cmd
);
884 static int fm10k_mbx_test(struct fm10k_intfc
*interface
, u64
*data
)
886 struct fm10k_hw
*hw
= &interface
->hw
;
887 struct fm10k_mbx_info
*mbx
= &hw
->mbx
;
888 u32 attr_flag
, test_msg
[6];
889 unsigned long timeout
;
892 /* For now this is a VF only feature */
893 if (hw
->mac
.type
!= fm10k_mac_vf
)
896 /* loop through both nested and unnested attribute types */
897 for (attr_flag
= BIT(FM10K_TEST_MSG_UNSET
);
898 attr_flag
< BIT(2 * FM10K_TEST_MSG_NESTED
);
899 attr_flag
+= attr_flag
) {
900 /* generate message to be tested */
901 fm10k_tlv_msg_test_create(test_msg
, attr_flag
);
903 fm10k_mbx_lock(interface
);
904 mbx
->test_result
= FM10K_NOT_IMPLEMENTED
;
905 err
= mbx
->ops
.enqueue_tx(hw
, mbx
, test_msg
);
906 fm10k_mbx_unlock(interface
);
908 /* wait up to 1 second for response */
909 timeout
= jiffies
+ HZ
;
914 usleep_range(500, 1000);
916 fm10k_mbx_lock(interface
);
917 mbx
->ops
.process(hw
, mbx
);
918 fm10k_mbx_unlock(interface
);
920 err
= mbx
->test_result
;
923 } while (time_is_after_jiffies(timeout
));
925 /* reporting errors */
931 *data
= err
< 0 ? (attr_flag
) : (err
> 0);
935 static void fm10k_self_test(struct net_device
*dev
,
936 struct ethtool_test
*eth_test
, u64
*data
)
938 struct fm10k_intfc
*interface
= netdev_priv(dev
);
939 struct fm10k_hw
*hw
= &interface
->hw
;
941 memset(data
, 0, sizeof(*data
) * FM10K_TEST_LEN
);
943 if (FM10K_REMOVED(hw
)) {
944 netif_err(interface
, drv
, dev
,
945 "Interface removed - test blocked\n");
946 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
950 if (fm10k_mbx_test(interface
, &data
[FM10K_TEST_MBX
]))
951 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
954 static u32
fm10k_get_priv_flags(struct net_device
*netdev
)
959 static int fm10k_set_priv_flags(struct net_device
*netdev
, u32 priv_flags
)
961 if (priv_flags
>= BIT(FM10K_PRV_FLAG_LEN
))
967 u32
fm10k_get_reta_size(struct net_device __always_unused
*netdev
)
969 return FM10K_RETA_SIZE
* FM10K_RETA_ENTRIES_PER_REG
;
972 void fm10k_write_reta(struct fm10k_intfc
*interface
, const u32
*indir
)
974 u16 rss_i
= interface
->ring_feature
[RING_F_RSS
].indices
;
975 struct fm10k_hw
*hw
= &interface
->hw
;
979 /* record entries to reta table */
980 for (i
= 0; i
< FM10K_RETA_SIZE
; i
++) {
983 /* generate a new table if we weren't given one */
984 for (j
= 0; j
< 4; j
++) {
986 n
= indir
[4 * i
+ j
];
988 n
= ethtool_rxfh_indir_default(4 * i
+ j
,
999 if (interface
->reta
[i
] == reta
)
1002 interface
->reta
[i
] = reta
;
1003 fm10k_write_reg(hw
, FM10K_RETA(0, i
), reta
);
1007 static int fm10k_get_reta(struct net_device
*netdev
, u32
*indir
)
1009 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1015 for (i
= 0; i
< FM10K_RETA_SIZE
; i
++, indir
+= 4) {
1016 u32 reta
= interface
->reta
[i
];
1018 indir
[0] = (reta
<< 24) >> 24;
1019 indir
[1] = (reta
<< 16) >> 24;
1020 indir
[2] = (reta
<< 8) >> 24;
1021 indir
[3] = (reta
) >> 24;
1027 static int fm10k_set_reta(struct net_device
*netdev
, const u32
*indir
)
1029 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1036 /* Verify user input. */
1037 rss_i
= interface
->ring_feature
[RING_F_RSS
].indices
;
1038 for (i
= fm10k_get_reta_size(netdev
); i
--;) {
1039 if (indir
[i
] < rss_i
)
1044 fm10k_write_reta(interface
, indir
);
1049 static u32
fm10k_get_rssrk_size(struct net_device __always_unused
*netdev
)
1051 return FM10K_RSSRK_SIZE
* FM10K_RSSRK_ENTRIES_PER_REG
;
1054 static int fm10k_get_rssh(struct net_device
*netdev
, u32
*indir
, u8
*key
,
1057 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1061 *hfunc
= ETH_RSS_HASH_TOP
;
1063 err
= fm10k_get_reta(netdev
, indir
);
1067 for (i
= 0; i
< FM10K_RSSRK_SIZE
; i
++, key
+= 4)
1068 *(__le32
*)key
= cpu_to_le32(interface
->rssrk
[i
]);
1073 static int fm10k_set_rssh(struct net_device
*netdev
, const u32
*indir
,
1074 const u8
*key
, const u8 hfunc
)
1076 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1077 struct fm10k_hw
*hw
= &interface
->hw
;
1080 /* We do not allow change in unsupported parameters */
1081 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
)
1084 err
= fm10k_set_reta(netdev
, indir
);
1088 for (i
= 0; i
< FM10K_RSSRK_SIZE
; i
++, key
+= 4) {
1089 u32 rssrk
= le32_to_cpu(*(__le32
*)key
);
1091 if (interface
->rssrk
[i
] == rssrk
)
1094 interface
->rssrk
[i
] = rssrk
;
1095 fm10k_write_reg(hw
, FM10K_RSSRK(0, i
), rssrk
);
1101 static unsigned int fm10k_max_channels(struct net_device
*dev
)
1103 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1104 unsigned int max_combined
= interface
->hw
.mac
.max_queues
;
1105 u8 tcs
= netdev_get_num_tc(dev
);
1107 /* For QoS report channels per traffic class */
1109 max_combined
= BIT((fls(max_combined
/ tcs
) - 1));
1111 return max_combined
;
1114 static void fm10k_get_channels(struct net_device
*dev
,
1115 struct ethtool_channels
*ch
)
1117 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1118 struct fm10k_hw
*hw
= &interface
->hw
;
1120 /* report maximum channels */
1121 ch
->max_combined
= fm10k_max_channels(dev
);
1123 /* report info for other vector */
1124 ch
->max_other
= NON_Q_VECTORS(hw
);
1125 ch
->other_count
= ch
->max_other
;
1127 /* record RSS queues */
1128 ch
->combined_count
= interface
->ring_feature
[RING_F_RSS
].indices
;
1131 static int fm10k_set_channels(struct net_device
*dev
,
1132 struct ethtool_channels
*ch
)
1134 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1135 unsigned int count
= ch
->combined_count
;
1136 struct fm10k_hw
*hw
= &interface
->hw
;
1138 /* verify they are not requesting separate vectors */
1139 if (!count
|| ch
->rx_count
|| ch
->tx_count
)
1142 /* verify other_count has not changed */
1143 if (ch
->other_count
!= NON_Q_VECTORS(hw
))
1146 /* verify the number of channels does not exceed hardware limits */
1147 if (count
> fm10k_max_channels(dev
))
1150 interface
->ring_feature
[RING_F_RSS
].limit
= count
;
1152 /* use setup TC to update any traffic class queue mapping */
1153 return fm10k_setup_tc(dev
, netdev_get_num_tc(dev
));
1156 static const struct ethtool_ops fm10k_ethtool_ops
= {
1157 .get_strings
= fm10k_get_strings
,
1158 .get_sset_count
= fm10k_get_sset_count
,
1159 .get_ethtool_stats
= fm10k_get_ethtool_stats
,
1160 .get_drvinfo
= fm10k_get_drvinfo
,
1161 .get_link
= ethtool_op_get_link
,
1162 .get_pauseparam
= fm10k_get_pauseparam
,
1163 .set_pauseparam
= fm10k_set_pauseparam
,
1164 .get_msglevel
= fm10k_get_msglevel
,
1165 .set_msglevel
= fm10k_set_msglevel
,
1166 .get_ringparam
= fm10k_get_ringparam
,
1167 .set_ringparam
= fm10k_set_ringparam
,
1168 .get_coalesce
= fm10k_get_coalesce
,
1169 .set_coalesce
= fm10k_set_coalesce
,
1170 .get_rxnfc
= fm10k_get_rxnfc
,
1171 .set_rxnfc
= fm10k_set_rxnfc
,
1172 .get_regs
= fm10k_get_regs
,
1173 .get_regs_len
= fm10k_get_regs_len
,
1174 .self_test
= fm10k_self_test
,
1175 .get_priv_flags
= fm10k_get_priv_flags
,
1176 .set_priv_flags
= fm10k_set_priv_flags
,
1177 .get_rxfh_indir_size
= fm10k_get_reta_size
,
1178 .get_rxfh_key_size
= fm10k_get_rssrk_size
,
1179 .get_rxfh
= fm10k_get_rssh
,
1180 .set_rxfh
= fm10k_set_rssh
,
1181 .get_channels
= fm10k_get_channels
,
1182 .set_channels
= fm10k_set_channels
,
1185 void fm10k_set_ethtool_ops(struct net_device
*dev
)
1187 dev
->ethtool_ops
= &fm10k_ethtool_ops
;