Skip to content

Commit 67ce1a8

Browse files
hayesorzdavem330
authored andcommitted
r8152: add help function to change mtu
The different chips may have different requests when changing mtu. Therefore, add a new help function of rtl_ops to change mtu. Besides, reset the tx/rx after changing mtu. Additionally, add mtu_to_size() and size_to_mtu() macros to simplify the code. Signed-off-by: Hayes Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a8a7be1 commit 67ce1a8

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

drivers/net/usb/r8152.c

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -657,15 +657,13 @@ enum rtl_register_content {
657657

658658
#define INTR_LINK 0x0004
659659

660-
#define RTL8153_MAX_PACKET 9216 /* 9K */
661-
#define RTL8153_MAX_MTU (RTL8153_MAX_PACKET - VLAN_ETH_HLEN - \
662-
ETH_FCS_LEN)
663660
#define RTL8152_RMS (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
664661
#define RTL8153_RMS RTL8153_MAX_PACKET
665662
#define RTL8152_TX_TIMEOUT (5 * HZ)
666663
#define RTL8152_NAPI_WEIGHT 64
667-
#define rx_reserved_size(x) ((x) + VLAN_ETH_HLEN + ETH_FCS_LEN + \
668-
sizeof(struct rx_desc) + RX_ALIGN)
664+
#define mtu_to_size(m) ((m) + VLAN_ETH_HLEN + ETH_FCS_LEN)
665+
#define size_to_mtu(s) ((s) - VLAN_ETH_HLEN - ETH_FCS_LEN)
666+
#define rx_reserved_size(x) (mtu_to_size(x) + sizeof(struct rx_desc) + RX_ALIGN)
669667

670668
/* rtl8152 flags */
671669
enum rtl8152_flags {
@@ -795,6 +793,7 @@ struct r8152 {
795793
bool (*in_nway)(struct r8152 *tp);
796794
void (*hw_phy_cfg)(struct r8152 *tp);
797795
void (*autosuspend_en)(struct r8152 *tp, bool enable);
796+
void (*change_mtu)(struct r8152 *tp);
798797
} rtl_ops;
799798

800799
struct ups_info {
@@ -1021,8 +1020,7 @@ enum tx_csum_stat {
10211020
static const int multicast_filter_limit = 32;
10221021
static unsigned int agg_buf_sz = 16384;
10231022

1024-
#define RTL_LIMITED_TSO_SIZE (agg_buf_sz - sizeof(struct tx_desc) - \
1025-
VLAN_ETH_HLEN - ETH_FCS_LEN)
1023+
#define RTL_LIMITED_TSO_SIZE (size_to_mtu(agg_buf_sz) - sizeof(struct tx_desc))
10261024

10271025
static
10281026
int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
@@ -2632,10 +2630,7 @@ static void rtl8152_nic_reset(struct r8152 *tp)
26322630

26332631
static void set_tx_qlen(struct r8152 *tp)
26342632
{
2635-
struct net_device *netdev = tp->netdev;
2636-
2637-
tp->tx_qlen = agg_buf_sz / (netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN +
2638-
sizeof(struct tx_desc));
2633+
tp->tx_qlen = agg_buf_sz / (mtu_to_size(tp->netdev->mtu) + sizeof(struct tx_desc));
26392634
}
26402635

26412636
static inline u8 rtl8152_get_speed(struct r8152 *tp)
@@ -4724,6 +4719,12 @@ static void r8153b_hw_phy_cfg(struct r8152 *tp)
47244719
set_bit(PHY_RESET, &tp->flags);
47254720
}
47264721

4722+
static void rtl8153_change_mtu(struct r8152 *tp)
4723+
{
4724+
ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, mtu_to_size(tp->netdev->mtu));
4725+
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_JUMBO);
4726+
}
4727+
47274728
static void r8153_first_init(struct r8152 *tp)
47284729
{
47294730
u32 ocp_data;
@@ -4756,9 +4757,7 @@ static void r8153_first_init(struct r8152 *tp)
47564757

47574758
rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX);
47584759

4759-
ocp_data = tp->netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
4760-
ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, ocp_data);
4761-
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_JUMBO);
4760+
rtl8153_change_mtu(tp);
47624761

47634762
ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0);
47644763
ocp_data |= TCR0_AUTO_FIFO;
@@ -4793,8 +4792,7 @@ static void r8153_enter_oob(struct r8152 *tp)
47934792

47944793
wait_oob_link_list_ready(tp);
47954794

4796-
ocp_data = tp->netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
4797-
ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, ocp_data);
4795+
ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, mtu_to_size(tp->netdev->mtu));
47984796

47994797
switch (tp->version) {
48004798
case RTL_VER_03:
@@ -6494,12 +6492,21 @@ static int rtl8152_change_mtu(struct net_device *dev, int new_mtu)
64946492
dev->mtu = new_mtu;
64956493

64966494
if (netif_running(dev)) {
6497-
u32 rms = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
6498-
6499-
ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, rms);
6495+
if (tp->rtl_ops.change_mtu)
6496+
tp->rtl_ops.change_mtu(tp);
65006497

6501-
if (netif_carrier_ok(dev))
6502-
r8153_set_rx_early_size(tp);
6498+
if (netif_carrier_ok(dev)) {
6499+
netif_stop_queue(dev);
6500+
napi_disable(&tp->napi);
6501+
tasklet_disable(&tp->tx_tl);
6502+
tp->rtl_ops.disable(tp);
6503+
tp->rtl_ops.enable(tp);
6504+
rtl_start_rx(tp);
6505+
tasklet_enable(&tp->tx_tl);
6506+
napi_enable(&tp->napi);
6507+
rtl8152_set_rx_mode(dev);
6508+
netif_wake_queue(dev);
6509+
}
65036510
}
65046511

65056512
mutex_unlock(&tp->control);
@@ -6588,6 +6595,7 @@ static int rtl_ops_init(struct r8152 *tp)
65886595
ops->in_nway = rtl8153_in_nway;
65896596
ops->hw_phy_cfg = r8153_hw_phy_cfg;
65906597
ops->autosuspend_en = rtl8153_runtime_enable;
6598+
ops->change_mtu = rtl8153_change_mtu;
65916599
if (tp->udev->speed < USB_SPEED_SUPER)
65926600
tp->rx_buf_sz = 16 * 1024;
65936601
else
@@ -6609,6 +6617,7 @@ static int rtl_ops_init(struct r8152 *tp)
66096617
ops->in_nway = rtl8153_in_nway;
66106618
ops->hw_phy_cfg = r8153b_hw_phy_cfg;
66116619
ops->autosuspend_en = rtl8153b_runtime_enable;
6620+
ops->change_mtu = rtl8153_change_mtu;
66126621
tp->rx_buf_sz = 32 * 1024;
66136622
tp->eee_en = true;
66146623
tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX;
@@ -6829,7 +6838,7 @@ static int rtl8152_probe(struct usb_interface *intf,
68296838
netdev->max_mtu = ETH_DATA_LEN;
68306839
break;
68316840
default:
6832-
netdev->max_mtu = RTL8153_MAX_MTU;
6841+
netdev->max_mtu = size_to_mtu(9 * 1024);
68336842
break;
68346843
}
68356844

0 commit comments

Comments
 (0)