Skip to content

Commit 4ac2d9d

Browse files
Jiawen Wudavem330
authored andcommitted
net: wangxun: add coalesce options support
Support to show RX/TX coalesce with ethtool -c and set RX/TX coalesce with ethtool -C. Signed-off-by: Jiawen Wu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 883b598 commit 4ac2d9d

File tree

7 files changed

+120
-1
lines changed

7 files changed

+120
-1
lines changed

drivers/net/ethernet/wangxun/libwx/wx_ethtool.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "wx_type.h"
99
#include "wx_ethtool.h"
1010
#include "wx_hw.h"
11+
#include "wx_lib.h"
1112

1213
struct wx_stats {
1314
char stat_string[ETH_GSTRING_LEN];
@@ -247,3 +248,103 @@ void wx_get_ringparam(struct net_device *netdev,
247248
ring->rx_jumbo_pending = 0;
248249
}
249250
EXPORT_SYMBOL(wx_get_ringparam);
251+
252+
int wx_get_coalesce(struct net_device *netdev,
253+
struct ethtool_coalesce *ec,
254+
struct kernel_ethtool_coalesce *kernel_coal,
255+
struct netlink_ext_ack *extack)
256+
{
257+
struct wx *wx = netdev_priv(netdev);
258+
259+
ec->tx_max_coalesced_frames_irq = wx->tx_work_limit;
260+
/* only valid if in constant ITR mode */
261+
if (wx->rx_itr_setting <= 1)
262+
ec->rx_coalesce_usecs = wx->rx_itr_setting;
263+
else
264+
ec->rx_coalesce_usecs = wx->rx_itr_setting >> 2;
265+
266+
/* if in mixed tx/rx queues per vector mode, report only rx settings */
267+
if (wx->q_vector[0]->tx.count && wx->q_vector[0]->rx.count)
268+
return 0;
269+
270+
/* only valid if in constant ITR mode */
271+
if (wx->tx_itr_setting <= 1)
272+
ec->tx_coalesce_usecs = wx->tx_itr_setting;
273+
else
274+
ec->tx_coalesce_usecs = wx->tx_itr_setting >> 2;
275+
276+
return 0;
277+
}
278+
EXPORT_SYMBOL(wx_get_coalesce);
279+
280+
int wx_set_coalesce(struct net_device *netdev,
281+
struct ethtool_coalesce *ec,
282+
struct kernel_ethtool_coalesce *kernel_coal,
283+
struct netlink_ext_ack *extack)
284+
{
285+
struct wx *wx = netdev_priv(netdev);
286+
u16 tx_itr_param, rx_itr_param;
287+
struct wx_q_vector *q_vector;
288+
u16 max_eitr;
289+
int i;
290+
291+
if (wx->q_vector[0]->tx.count && wx->q_vector[0]->rx.count) {
292+
/* reject Tx specific changes in case of mixed RxTx vectors */
293+
if (ec->tx_coalesce_usecs)
294+
return -EOPNOTSUPP;
295+
}
296+
297+
if (ec->tx_max_coalesced_frames_irq)
298+
wx->tx_work_limit = ec->tx_max_coalesced_frames_irq;
299+
300+
if (wx->mac.type == wx_mac_sp)
301+
max_eitr = WX_SP_MAX_EITR;
302+
else
303+
max_eitr = WX_EM_MAX_EITR;
304+
305+
if ((ec->rx_coalesce_usecs > (max_eitr >> 2)) ||
306+
(ec->tx_coalesce_usecs > (max_eitr >> 2)))
307+
return -EINVAL;
308+
309+
if (ec->rx_coalesce_usecs > 1)
310+
wx->rx_itr_setting = ec->rx_coalesce_usecs << 2;
311+
else
312+
wx->rx_itr_setting = ec->rx_coalesce_usecs;
313+
314+
if (wx->rx_itr_setting == 1)
315+
rx_itr_param = WX_20K_ITR;
316+
else
317+
rx_itr_param = wx->rx_itr_setting;
318+
319+
if (ec->tx_coalesce_usecs > 1)
320+
wx->tx_itr_setting = ec->tx_coalesce_usecs << 2;
321+
else
322+
wx->tx_itr_setting = ec->tx_coalesce_usecs;
323+
324+
if (wx->tx_itr_setting == 1) {
325+
if (wx->mac.type == wx_mac_sp)
326+
tx_itr_param = WX_12K_ITR;
327+
else
328+
tx_itr_param = WX_20K_ITR;
329+
} else {
330+
tx_itr_param = wx->tx_itr_setting;
331+
}
332+
333+
/* mixed Rx/Tx */
334+
if (wx->q_vector[0]->tx.count && wx->q_vector[0]->rx.count)
335+
wx->tx_itr_setting = wx->rx_itr_setting;
336+
337+
for (i = 0; i < wx->num_q_vectors; i++) {
338+
q_vector = wx->q_vector[i];
339+
if (q_vector->tx.count && !q_vector->rx.count)
340+
/* tx only */
341+
q_vector->itr = tx_itr_param;
342+
else
343+
/* rx only or mixed */
344+
q_vector->itr = rx_itr_param;
345+
wx_write_eitr(q_vector);
346+
}
347+
348+
return 0;
349+
}
350+
EXPORT_SYMBOL(wx_set_coalesce);

drivers/net/ethernet/wangxun/libwx/wx_ethtool.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@ void wx_get_ringparam(struct net_device *netdev,
2626
struct ethtool_ringparam *ring,
2727
struct kernel_ethtool_ringparam *kernel_ring,
2828
struct netlink_ext_ack *extack);
29+
int wx_get_coalesce(struct net_device *netdev,
30+
struct ethtool_coalesce *ec,
31+
struct kernel_ethtool_coalesce *kernel_coal,
32+
struct netlink_ext_ack *extack);
33+
int wx_set_coalesce(struct net_device *netdev,
34+
struct ethtool_coalesce *ec,
35+
struct kernel_ethtool_coalesce *kernel_coal,
36+
struct netlink_ext_ack *extack);
2937
#endif /* _WX_ETHTOOL_H_ */

drivers/net/ethernet/wangxun/libwx/wx_lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ static void wx_set_ivar(struct wx *wx, s8 direction,
20822082
* when it needs to update EITR registers at runtime. Hardware
20832083
* specific quirks/differences are taken care of here.
20842084
*/
2085-
static void wx_write_eitr(struct wx_q_vector *q_vector)
2085+
void wx_write_eitr(struct wx_q_vector *q_vector)
20862086
{
20872087
struct wx *wx = q_vector->wx;
20882088
int v_idx = q_vector->v_idx;

drivers/net/ethernet/wangxun/libwx/wx_lib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void wx_free_irq(struct wx *wx);
2121
int wx_setup_isb_resources(struct wx *wx);
2222
void wx_free_isb_resources(struct wx *wx);
2323
u32 wx_misc_isb(struct wx *wx, enum wx_isb_idx idx);
24+
void wx_write_eitr(struct wx_q_vector *q_vector);
2425
void wx_configure_vectors(struct wx *wx);
2526
void wx_clean_all_rx_rings(struct wx *wx);
2627
void wx_clean_all_tx_rings(struct wx *wx);

drivers/net/ethernet/wangxun/libwx/wx_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ enum WX_MSCA_CMD_value {
315315
#define WX_PX_IVAR_ALLOC_VAL 0x80 /* Interrupt Allocation valid */
316316
#define WX_7K_ITR 595
317317
#define WX_12K_ITR 336
318+
#define WX_20K_ITR 200
318319
#define WX_SP_MAX_EITR 0x00000FF8U
319320
#define WX_EM_MAX_EITR 0x00007FFCU
320321

drivers/net/ethernet/wangxun/ngbe/ngbe_ethtool.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ static int ngbe_set_ringparam(struct net_device *netdev,
9393
}
9494

9595
static const struct ethtool_ops ngbe_ethtool_ops = {
96+
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
97+
ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ,
9698
.get_drvinfo = wx_get_drvinfo,
9799
.get_link = ethtool_op_get_link,
98100
.get_link_ksettings = wx_get_link_ksettings,
@@ -109,6 +111,8 @@ static const struct ethtool_ops ngbe_ethtool_ops = {
109111
.set_pauseparam = wx_set_pauseparam,
110112
.get_ringparam = wx_get_ringparam,
111113
.set_ringparam = ngbe_set_ringparam,
114+
.get_coalesce = wx_get_coalesce,
115+
.set_coalesce = wx_set_coalesce,
112116
};
113117

114118
void ngbe_set_ethtool_ops(struct net_device *netdev)

drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ static int txgbe_set_ringparam(struct net_device *netdev,
5959
}
6060

6161
static const struct ethtool_ops txgbe_ethtool_ops = {
62+
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
63+
ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ,
6264
.get_drvinfo = wx_get_drvinfo,
6365
.nway_reset = wx_nway_reset,
6466
.get_link = ethtool_op_get_link,
@@ -73,6 +75,8 @@ static const struct ethtool_ops txgbe_ethtool_ops = {
7375
.set_pauseparam = wx_set_pauseparam,
7476
.get_ringparam = wx_get_ringparam,
7577
.set_ringparam = txgbe_set_ringparam,
78+
.get_coalesce = wx_get_coalesce,
79+
.set_coalesce = wx_set_coalesce,
7680
};
7781

7882
void txgbe_set_ethtool_ops(struct net_device *netdev)

0 commit comments

Comments
 (0)