Skip to content

Commit 8441bb3

Browse files
Zach Browndavem330
authored andcommitted
net: macb: Add ethtool get_ringparam and set_ringparam functionality
Some applications want to tune the size of the macb rx/tx ring buffers. The ethtool set_ringparam function is the standard way of doing it. Signed-off-by: Zach Brown <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b410d13 commit 8441bb3

File tree

1 file changed

+59
-0
lines changed
  • drivers/net/ethernet/cadence

1 file changed

+59
-0
lines changed

drivers/net/ethernet/cadence/macb.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@
3737

3838
#define MACB_RX_BUFFER_SIZE 128
3939
#define RX_BUFFER_MULTIPLE 64 /* bytes */
40+
4041
#define DEFAULT_RX_RING_SIZE 512 /* must be power of 2 */
42+
#define MIN_RX_RING_SIZE 64
43+
#define MAX_RX_RING_SIZE 8192
4144
#define RX_RING_BYTES(bp) (sizeof(struct macb_dma_desc) \
4245
* (bp)->rx_ring_size)
4346

4447
#define DEFAULT_TX_RING_SIZE 512 /* must be power of 2 */
48+
#define MIN_TX_RING_SIZE 64
49+
#define MAX_TX_RING_SIZE 4096
4550
#define TX_RING_BYTES(bp) (sizeof(struct macb_dma_desc) \
4651
* (bp)->tx_ring_size)
4752

@@ -2211,6 +2216,56 @@ static int macb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
22112216
return 0;
22122217
}
22132218

2219+
static void macb_get_ringparam(struct net_device *netdev,
2220+
struct ethtool_ringparam *ring)
2221+
{
2222+
struct macb *bp = netdev_priv(netdev);
2223+
2224+
ring->rx_max_pending = MAX_RX_RING_SIZE;
2225+
ring->tx_max_pending = MAX_TX_RING_SIZE;
2226+
2227+
ring->rx_pending = bp->rx_ring_size;
2228+
ring->tx_pending = bp->tx_ring_size;
2229+
}
2230+
2231+
static int macb_set_ringparam(struct net_device *netdev,
2232+
struct ethtool_ringparam *ring)
2233+
{
2234+
struct macb *bp = netdev_priv(netdev);
2235+
u32 new_rx_size, new_tx_size;
2236+
unsigned int reset = 0;
2237+
2238+
if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
2239+
return -EINVAL;
2240+
2241+
new_rx_size = clamp_t(u32, ring->rx_pending,
2242+
MIN_RX_RING_SIZE, MAX_RX_RING_SIZE);
2243+
new_rx_size = roundup_pow_of_two(new_rx_size);
2244+
2245+
new_tx_size = clamp_t(u32, ring->tx_pending,
2246+
MIN_TX_RING_SIZE, MAX_TX_RING_SIZE);
2247+
new_tx_size = roundup_pow_of_two(new_tx_size);
2248+
2249+
if ((new_tx_size == bp->tx_ring_size) &&
2250+
(new_rx_size == bp->rx_ring_size)) {
2251+
/* nothing to do */
2252+
return 0;
2253+
}
2254+
2255+
if (netif_running(bp->dev)) {
2256+
reset = 1;
2257+
macb_close(bp->dev);
2258+
}
2259+
2260+
bp->rx_ring_size = new_rx_size;
2261+
bp->tx_ring_size = new_tx_size;
2262+
2263+
if (reset)
2264+
macb_open(bp->dev);
2265+
2266+
return 0;
2267+
}
2268+
22142269
static const struct ethtool_ops macb_ethtool_ops = {
22152270
.get_regs_len = macb_get_regs_len,
22162271
.get_regs = macb_get_regs,
@@ -2220,6 +2275,8 @@ static const struct ethtool_ops macb_ethtool_ops = {
22202275
.set_wol = macb_set_wol,
22212276
.get_link_ksettings = phy_ethtool_get_link_ksettings,
22222277
.set_link_ksettings = phy_ethtool_set_link_ksettings,
2278+
.get_ringparam = macb_get_ringparam,
2279+
.set_ringparam = macb_set_ringparam,
22232280
};
22242281

22252282
static const struct ethtool_ops gem_ethtool_ops = {
@@ -2232,6 +2289,8 @@ static const struct ethtool_ops gem_ethtool_ops = {
22322289
.get_sset_count = gem_get_sset_count,
22332290
.get_link_ksettings = phy_ethtool_get_link_ksettings,
22342291
.set_link_ksettings = phy_ethtool_set_link_ksettings,
2292+
.get_ringparam = macb_get_ringparam,
2293+
.set_ringparam = macb_set_ringparam,
22352294
};
22362295

22372296
static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)

0 commit comments

Comments
 (0)