| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* Copyright (c) 2015 - 2023 Beijing WangXun Technology Co., Ltd. */ |
| 3 |
|
| 4 |
#include <linux/pci.h> |
| 5 |
#include <linux/phy.h> |
| 6 |
#include <linux/netdevice.h> |
| 7 |
|
| 8 |
#include "../libwx/wx_ethtool.h" |
| 9 |
#include "../libwx/wx_type.h" |
| 10 |
#include "../libwx/wx_lib.h" |
| 11 |
#include "../libwx/wx_hw.h" |
| 12 |
#include "ngbe_ethtool.h" |
| 13 |
#include "ngbe_type.h" |
| 14 |
|
| 15 |
static void ngbe_get_wol(struct net_device *netdev, |
| 16 |
struct ethtool_wolinfo *wol) |
| 17 |
{ |
| 18 |
struct wx *wx = netdev_priv(netdev); |
| 19 |
|
| 20 |
if (!wx->wol_hw_supported) |
| 21 |
return; |
| 22 |
wol->supported = WAKE_MAGIC; |
| 23 |
wol->wolopts = 0; |
| 24 |
if (wx->wol & WX_PSR_WKUP_CTL_MAG) |
| 25 |
wol->wolopts |= WAKE_MAGIC; |
| 26 |
} |
| 27 |
|
| 28 |
static int ngbe_set_wol(struct net_device *netdev, |
| 29 |
struct ethtool_wolinfo *wol) |
| 30 |
{ |
| 31 |
struct wx *wx = netdev_priv(netdev); |
| 32 |
struct pci_dev *pdev = wx->pdev; |
| 33 |
|
| 34 |
if (!wx->wol_hw_supported) |
| 35 |
return -EOPNOTSUPP; |
| 36 |
|
| 37 |
wx->wol = 0; |
| 38 |
if (wol->wolopts & WAKE_MAGIC) |
| 39 |
wx->wol = WX_PSR_WKUP_CTL_MAG; |
| 40 |
netdev->ethtool->wol_enabled = !!(wx->wol); |
| 41 |
wr32(wx, WX_PSR_WKUP_CTL, wx->wol); |
| 42 |
device_set_wakeup_enable(&pdev->dev, netdev->ethtool->wol_enabled); |
| 43 |
|
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
static int ngbe_set_ringparam(struct net_device *netdev, |
| 48 |
struct ethtool_ringparam *ring, |
| 49 |
struct kernel_ethtool_ringparam *kernel_ring, |
| 50 |
struct netlink_ext_ack *extack) |
| 51 |
{ |
| 52 |
struct wx *wx = netdev_priv(netdev); |
| 53 |
u32 new_rx_count, new_tx_count; |
| 54 |
struct wx_ring *temp_ring; |
| 55 |
int i, err = 0; |
| 56 |
|
| 57 |
new_tx_count = clamp_t(u32, ring->tx_pending, WX_MIN_TXD, WX_MAX_TXD); |
| 58 |
new_tx_count = ALIGN(new_tx_count, WX_REQ_TX_DESCRIPTOR_MULTIPLE); |
| 59 |
|
| 60 |
new_rx_count = clamp_t(u32, ring->rx_pending, WX_MIN_RXD, WX_MAX_RXD); |
| 61 |
new_rx_count = ALIGN(new_rx_count, WX_REQ_RX_DESCRIPTOR_MULTIPLE); |
| 62 |
|
| 63 |
if (new_tx_count == wx->tx_ring_count && |
| 64 |
new_rx_count == wx->rx_ring_count) |
| 65 |
return 0; |
| 66 |
|
| 67 |
err = wx_set_state_reset(wx); |
| 68 |
if (err) |
| 69 |
return err; |
| 70 |
|
| 71 |
if (!netif_running(wx->netdev)) { |
| 72 |
for (i = 0; i < wx->num_tx_queues; i++) |
| 73 |
wx->tx_ring[i]->count = new_tx_count; |
| 74 |
for (i = 0; i < wx->num_rx_queues; i++) |
| 75 |
wx->rx_ring[i]->count = new_rx_count; |
| 76 |
wx->tx_ring_count = new_tx_count; |
| 77 |
wx->rx_ring_count = new_rx_count; |
| 78 |
|
| 79 |
goto clear_reset; |
| 80 |
} |
| 81 |
|
| 82 |
/* allocate temporary buffer to store rings in */ |
| 83 |
i = max_t(int, wx->num_tx_queues, wx->num_rx_queues); |
| 84 |
temp_ring = kvmalloc_objs(struct wx_ring, i); |
| 85 |
if (!temp_ring) { |
| 86 |
err = -ENOMEM; |
| 87 |
goto clear_reset; |
| 88 |
} |
| 89 |
|
| 90 |
ngbe_down(wx); |
| 91 |
|
| 92 |
wx_set_ring(wx, new_tx_count, new_rx_count, temp_ring); |
| 93 |
kvfree(temp_ring); |
| 94 |
|
| 95 |
wx_configure(wx); |
| 96 |
ngbe_up(wx); |
| 97 |
|
| 98 |
clear_reset: |
| 99 |
clear_bit(WX_STATE_RESETTING, wx->state); |
| 100 |
return err; |
| 101 |
} |
| 102 |
|
| 103 |
static int ngbe_set_channels(struct net_device *dev, |
| 104 |
struct ethtool_channels *ch) |
| 105 |
{ |
| 106 |
int err; |
| 107 |
|
| 108 |
err = wx_set_channels(dev, ch); |
| 109 |
if (err < 0) |
| 110 |
return err; |
| 111 |
|
| 112 |
/* use setup TC to update any traffic class queue mapping */ |
| 113 |
return ngbe_setup_tc(dev, netdev_get_num_tc(dev)); |
| 114 |
} |
| 115 |
|
| 116 |
static const struct ethtool_ops ngbe_ethtool_ops = { |
| 117 |
.supported_coalesce_params = ETHTOOL_COALESCE_USECS | |
| 118 |
ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ | |
| 119 |
ETHTOOL_COALESCE_USE_ADAPTIVE, |
| 120 |
.get_drvinfo = wx_get_drvinfo, |
| 121 |
.get_link = ethtool_op_get_link, |
| 122 |
.get_link_ksettings = wx_get_link_ksettings, |
| 123 |
.set_link_ksettings = wx_set_link_ksettings, |
| 124 |
.nway_reset = wx_nway_reset, |
| 125 |
.get_wol = ngbe_get_wol, |
| 126 |
.set_wol = ngbe_set_wol, |
| 127 |
.get_sset_count = wx_get_sset_count, |
| 128 |
.get_strings = wx_get_strings, |
| 129 |
.get_ethtool_stats = wx_get_ethtool_stats, |
| 130 |
.get_eth_mac_stats = wx_get_mac_stats, |
| 131 |
.get_pause_stats = wx_get_pause_stats, |
| 132 |
.get_pauseparam = wx_get_pauseparam, |
| 133 |
.set_pauseparam = wx_set_pauseparam, |
| 134 |
.get_ringparam = wx_get_ringparam, |
| 135 |
.set_ringparam = ngbe_set_ringparam, |
| 136 |
.get_coalesce = wx_get_coalesce, |
| 137 |
.set_coalesce = wx_set_coalesce, |
| 138 |
.get_channels = wx_get_channels, |
| 139 |
.set_channels = ngbe_set_channels, |
| 140 |
.get_rxfh_fields = wx_get_rxfh_fields, |
| 141 |
.set_rxfh_fields = wx_set_rxfh_fields, |
| 142 |
.get_rxfh_indir_size = wx_rss_indir_size, |
| 143 |
.get_rxfh_key_size = wx_get_rxfh_key_size, |
| 144 |
.get_rxfh = wx_get_rxfh, |
| 145 |
.set_rxfh = wx_set_rxfh, |
| 146 |
.get_msglevel = wx_get_msglevel, |
| 147 |
.set_msglevel = wx_set_msglevel, |
| 148 |
.get_ts_info = wx_get_ts_info, |
| 149 |
.get_ts_stats = wx_get_ptp_stats, |
| 150 |
}; |
| 151 |
|
| 152 |
void ngbe_set_ethtool_ops(struct net_device *netdev) |
| 153 |
{ |
| 154 |
netdev->ethtool_ops = &ngbe_ethtool_ops; |
| 155 |
} |