Skip to content

Commit e4a5017

Browse files
hayesorzJakub Kicinski
authored andcommitted
r8152: change rx_copybreak and rx_pending through ethtool
Let the rx_copybreak and rx_pending could be modified by ethtool. Signed-off-by: Hayes Wang <hayeswang@realtek.com> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
1 parent 47922fc commit e4a5017

1 file changed

Lines changed: 86 additions & 5 deletions

File tree

‎drivers/net/usb/r8152.c‎

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <linux/acpi.h>
2727

2828
/* Information for net-next */
29-
#define NETNEXT_VERSION "09"
29+
#define NETNEXT_VERSION "10"
3030

3131
/* Information for net */
3232
#define NET_VERSION "10"
@@ -584,7 +584,7 @@ enum rtl_register_content {
584584
#define TX_ALIGN 4
585585
#define RX_ALIGN 8
586586

587-
#define RTL8152_MAX_RX_AGG (10 * RTL8152_MAX_RX)
587+
#define RTL8152_RX_MAX_PENDING 4096
588588
#define RTL8152_RXFG_HEADSZ 256
589589

590590
#define INTR_LINK 0x0004
@@ -756,6 +756,9 @@ struct r8152 {
756756
u32 tx_qlen;
757757
u32 coalesce;
758758
u32 rx_buf_sz;
759+
u32 rx_copybreak;
760+
u32 rx_pending;
761+
759762
u16 ocp_base;
760763
u16 speed;
761764
u8 *intr_buff;
@@ -1984,7 +1987,7 @@ static struct rx_agg *rtl_get_free_rx(struct r8152 *tp, gfp_t mflags)
19841987

19851988
spin_unlock_irqrestore(&tp->rx_lock, flags);
19861989

1987-
if (!agg_free && atomic_read(&tp->rx_count) < RTL8152_MAX_RX_AGG)
1990+
if (!agg_free && atomic_read(&tp->rx_count) < tp->rx_pending)
19881991
agg_free = alloc_rx_agg(tp, mflags);
19891992

19901993
return agg_free;
@@ -2064,10 +2067,10 @@ static int rx_bottom(struct r8152 *tp, int budget)
20642067
pkt_len -= ETH_FCS_LEN;
20652068
rx_data += sizeof(struct rx_desc);
20662069

2067-
if (!agg_free || RTL8152_RXFG_HEADSZ > pkt_len)
2070+
if (!agg_free || tp->rx_copybreak > pkt_len)
20682071
rx_frag_head_sz = pkt_len;
20692072
else
2070-
rx_frag_head_sz = RTL8152_RXFG_HEADSZ;
2073+
rx_frag_head_sz = tp->rx_copybreak;
20712074

20722075
skb = napi_alloc_skb(napi, rx_frag_head_sz);
20732076
if (!skb) {
@@ -5104,6 +5107,77 @@ static int rtl8152_set_coalesce(struct net_device *netdev,
51045107
return ret;
51055108
}
51065109

5110+
static int rtl8152_get_tunable(struct net_device *netdev,
5111+
const struct ethtool_tunable *tunable, void *d)
5112+
{
5113+
struct r8152 *tp = netdev_priv(netdev);
5114+
5115+
switch (tunable->id) {
5116+
case ETHTOOL_RX_COPYBREAK:
5117+
*(u32 *)d = tp->rx_copybreak;
5118+
break;
5119+
default:
5120+
return -EOPNOTSUPP;
5121+
}
5122+
5123+
return 0;
5124+
}
5125+
5126+
static int rtl8152_set_tunable(struct net_device *netdev,
5127+
const struct ethtool_tunable *tunable,
5128+
const void *d)
5129+
{
5130+
struct r8152 *tp = netdev_priv(netdev);
5131+
u32 val;
5132+
5133+
switch (tunable->id) {
5134+
case ETHTOOL_RX_COPYBREAK:
5135+
val = *(u32 *)d;
5136+
if (val < ETH_ZLEN) {
5137+
netif_err(tp, rx_err, netdev,
5138+
"Invalid rx copy break value\n");
5139+
return -EINVAL;
5140+
}
5141+
5142+
if (tp->rx_copybreak != val) {
5143+
napi_disable(&tp->napi);
5144+
tp->rx_copybreak = val;
5145+
napi_enable(&tp->napi);
5146+
}
5147+
break;
5148+
default:
5149+
return -EOPNOTSUPP;
5150+
}
5151+
5152+
return 0;
5153+
}
5154+
5155+
static void rtl8152_get_ringparam(struct net_device *netdev,
5156+
struct ethtool_ringparam *ring)
5157+
{
5158+
struct r8152 *tp = netdev_priv(netdev);
5159+
5160+
ring->rx_max_pending = RTL8152_RX_MAX_PENDING;
5161+
ring->rx_pending = tp->rx_pending;
5162+
}
5163+
5164+
static int rtl8152_set_ringparam(struct net_device *netdev,
5165+
struct ethtool_ringparam *ring)
5166+
{
5167+
struct r8152 *tp = netdev_priv(netdev);
5168+
5169+
if (ring->rx_pending < (RTL8152_MAX_RX * 2))
5170+
return -EINVAL;
5171+
5172+
if (tp->rx_pending != ring->rx_pending) {
5173+
napi_disable(&tp->napi);
5174+
tp->rx_pending = ring->rx_pending;
5175+
napi_enable(&tp->napi);
5176+
}
5177+
5178+
return 0;
5179+
}
5180+
51075181
static const struct ethtool_ops ops = {
51085182
.get_drvinfo = rtl8152_get_drvinfo,
51095183
.get_link = ethtool_op_get_link,
@@ -5121,6 +5195,10 @@ static const struct ethtool_ops ops = {
51215195
.set_eee = rtl_ethtool_set_eee,
51225196
.get_link_ksettings = rtl8152_get_link_ksettings,
51235197
.set_link_ksettings = rtl8152_set_link_ksettings,
5198+
.get_tunable = rtl8152_get_tunable,
5199+
.set_tunable = rtl8152_set_tunable,
5200+
.get_ringparam = rtl8152_get_ringparam,
5201+
.set_ringparam = rtl8152_set_ringparam,
51245202
};
51255203

51265204
static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
@@ -5474,6 +5552,9 @@ static int rtl8152_probe(struct usb_interface *intf,
54745552
tp->speed = tp->mii.supports_gmii ? SPEED_1000 : SPEED_100;
54755553
tp->duplex = DUPLEX_FULL;
54765554

5555+
tp->rx_copybreak = RTL8152_RXFG_HEADSZ;
5556+
tp->rx_pending = 10 * RTL8152_MAX_RX;
5557+
54775558
intf->needs_remote_wakeup = 1;
54785559

54795560
tp->rtl_ops.init(tp);

0 commit comments

Comments
 (0)