Skip to content

Commit 65245d8

Browse files
committed
Merge branch 'r8169-further-improvements'
Heiner Kallweit says: ==================== r8169: further improvements w/o functional change This series aims at further improving and simplifying the code w/o any intended functional changes. Series was tested on: RTL8169sb, RTL8168d, RTL8168e-vl ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 76c2a96 + 4fd48c4 commit 65245d8

File tree

1 file changed

+42
-142
lines changed
  • drivers/net/ethernet/realtek

1 file changed

+42
-142
lines changed

drivers/net/ethernet/realtek/r8169.c

Lines changed: 42 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ enum rtl_register_content {
599599
RxChkSum = (1 << 5),
600600
PCIDAC = (1 << 4),
601601
PCIMulRW = (1 << 3),
602+
#define INTT_MASK GENMASK(1, 0)
602603
INTT_0 = 0x0000, // 8168
603604
INTT_1 = 0x0001, // 8168
604605
INTT_2 = 0x0002, // 8168
@@ -689,6 +690,7 @@ enum rtl_rx_desc_bit {
689690
};
690691

691692
#define RsvdMask 0x3fffc000
693+
#define CPCMD_QUIRK_MASK (Normal_mode | RxVlan | RxChkSum | INTT_MASK)
692694

693695
struct TxDesc {
694696
__le32 opts1;
@@ -1935,12 +1937,14 @@ static netdev_features_t rtl8169_fix_features(struct net_device *dev,
19351937
return features;
19361938
}
19371939

1938-
static void __rtl8169_set_features(struct net_device *dev,
1939-
netdev_features_t features)
1940+
static int rtl8169_set_features(struct net_device *dev,
1941+
netdev_features_t features)
19401942
{
19411943
struct rtl8169_private *tp = netdev_priv(dev);
19421944
u32 rx_config;
19431945

1946+
rtl_lock_work(tp);
1947+
19441948
rx_config = RTL_R32(tp, RxConfig);
19451949
if (features & NETIF_F_RXALL)
19461950
rx_config |= (AcceptErr | AcceptRunt);
@@ -1959,28 +1963,14 @@ static void __rtl8169_set_features(struct net_device *dev,
19591963
else
19601964
tp->cp_cmd &= ~RxVlan;
19611965

1962-
tp->cp_cmd |= RTL_R16(tp, CPlusCmd) & ~(RxVlan | RxChkSum);
1963-
19641966
RTL_W16(tp, CPlusCmd, tp->cp_cmd);
19651967
RTL_R16(tp, CPlusCmd);
1966-
}
19671968

1968-
static int rtl8169_set_features(struct net_device *dev,
1969-
netdev_features_t features)
1970-
{
1971-
struct rtl8169_private *tp = netdev_priv(dev);
1972-
1973-
features &= NETIF_F_RXALL | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_RX;
1974-
1975-
rtl_lock_work(tp);
1976-
if (features ^ dev->features)
1977-
__rtl8169_set_features(dev, features);
19781969
rtl_unlock_work(tp);
19791970

19801971
return 0;
19811972
}
19821973

1983-
19841974
static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb)
19851975
{
19861976
return (skb_vlan_tag_present(skb)) ?
@@ -2354,7 +2344,7 @@ static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
23542344
if (IS_ERR(ci))
23552345
return PTR_ERR(ci);
23562346

2357-
scale = &ci->scalev[RTL_R16(tp, CPlusCmd) & 3];
2347+
scale = &ci->scalev[tp->cp_cmd & INTT_MASK];
23582348

23592349
/* read IntrMitigate and adjust according to scale */
23602350
for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) {
@@ -2453,7 +2443,7 @@ static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
24532443

24542444
RTL_W16(tp, IntrMitigate, swab16(w));
24552445

2456-
tp->cp_cmd = (tp->cp_cmd & ~3) | cp01;
2446+
tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01;
24572447
RTL_W16(tp, CPlusCmd, tp->cp_cmd);
24582448
RTL_R16(tp, CPlusCmd);
24592449

@@ -4850,7 +4840,7 @@ static void r8168_pll_power_down(struct rtl8169_private *tp)
48504840

48514841
if ((tp->mac_version == RTL_GIGA_MAC_VER_23 ||
48524842
tp->mac_version == RTL_GIGA_MAC_VER_24) &&
4853-
(RTL_R16(tp, CPlusCmd) & ASF)) {
4843+
(tp->cp_cmd & ASF)) {
48544844
return;
48554845
}
48564846

@@ -5311,10 +5301,10 @@ static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp)
53115301
(InterFrameGap << TxInterFrameGapShift));
53125302
}
53135303

5314-
static void rtl_hw_start(struct rtl8169_private *tp)
5304+
static void rtl_set_rx_max_size(struct rtl8169_private *tp)
53155305
{
5316-
tp->hw_start(tp);
5317-
rtl_irq_enable_all(tp);
5306+
/* Low hurts. Let's disable the filtering. */
5307+
RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1);
53185308
}
53195309

53205310
static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp)
@@ -5330,19 +5320,23 @@ static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp)
53305320
RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32));
53315321
}
53325322

5333-
static u16 rtl_rw_cpluscmd(struct rtl8169_private *tp)
5323+
static void rtl_hw_start(struct rtl8169_private *tp)
53345324
{
5335-
u16 cmd;
5325+
RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
53365326

5337-
cmd = RTL_R16(tp, CPlusCmd);
5338-
RTL_W16(tp, CPlusCmd, cmd);
5339-
return cmd;
5340-
}
5327+
tp->hw_start(tp);
53415328

5342-
static void rtl_set_rx_max_size(struct rtl8169_private *tp)
5343-
{
5344-
/* Low hurts. Let's disable the filtering. */
5345-
RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1);
5329+
rtl_set_rx_max_size(tp);
5330+
rtl_set_rx_tx_desc_registers(tp);
5331+
rtl_set_rx_tx_config_registers(tp);
5332+
RTL_W8(tp, Cfg9346, Cfg9346_Lock);
5333+
5334+
/* Initially a 10 us delay. Turned it into a PCI commit. - FR */
5335+
RTL_R8(tp, IntrMask);
5336+
RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
5337+
/* no early-rx interrupts */
5338+
RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
5339+
rtl_irq_enable_all(tp);
53465340
}
53475341

53485342
static void rtl8169_set_magic_reg(struct rtl8169_private *tp, unsigned mac_version)
@@ -5424,31 +5418,12 @@ static void rtl_set_rx_mode(struct net_device *dev)
54245418

54255419
static void rtl_hw_start_8169(struct rtl8169_private *tp)
54265420
{
5427-
if (tp->mac_version == RTL_GIGA_MAC_VER_05) {
5428-
RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) | PCIMulRW);
5421+
if (tp->mac_version == RTL_GIGA_MAC_VER_05)
54295422
pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08);
5430-
}
5431-
5432-
RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
5433-
if (tp->mac_version == RTL_GIGA_MAC_VER_01 ||
5434-
tp->mac_version == RTL_GIGA_MAC_VER_02 ||
5435-
tp->mac_version == RTL_GIGA_MAC_VER_03 ||
5436-
tp->mac_version == RTL_GIGA_MAC_VER_04)
5437-
RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
5438-
5439-
rtl_init_rxcfg(tp);
54405423

54415424
RTL_W8(tp, EarlyTxThres, NoEarlyTx);
54425425

5443-
rtl_set_rx_max_size(tp);
5444-
5445-
if (tp->mac_version == RTL_GIGA_MAC_VER_01 ||
5446-
tp->mac_version == RTL_GIGA_MAC_VER_02 ||
5447-
tp->mac_version == RTL_GIGA_MAC_VER_03 ||
5448-
tp->mac_version == RTL_GIGA_MAC_VER_04)
5449-
rtl_set_rx_tx_config_registers(tp);
5450-
5451-
tp->cp_cmd |= rtl_rw_cpluscmd(tp) | PCIMulRW;
5426+
tp->cp_cmd |= PCIMulRW;
54525427

54535428
if (tp->mac_version == RTL_GIGA_MAC_VER_02 ||
54545429
tp->mac_version == RTL_GIGA_MAC_VER_03) {
@@ -5467,27 +5442,7 @@ static void rtl_hw_start_8169(struct rtl8169_private *tp)
54675442
*/
54685443
RTL_W16(tp, IntrMitigate, 0x0000);
54695444

5470-
rtl_set_rx_tx_desc_registers(tp);
5471-
5472-
if (tp->mac_version != RTL_GIGA_MAC_VER_01 &&
5473-
tp->mac_version != RTL_GIGA_MAC_VER_02 &&
5474-
tp->mac_version != RTL_GIGA_MAC_VER_03 &&
5475-
tp->mac_version != RTL_GIGA_MAC_VER_04) {
5476-
RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
5477-
rtl_set_rx_tx_config_registers(tp);
5478-
}
5479-
5480-
RTL_W8(tp, Cfg9346, Cfg9346_Lock);
5481-
5482-
/* Initially a 10 us delay. Turned it into a PCI commit. - FR */
5483-
RTL_R8(tp, IntrMask);
5484-
54855445
RTL_W32(tp, RxMissed, 0);
5486-
5487-
rtl_set_rx_mode(tp->dev);
5488-
5489-
/* no early-rx interrupts */
5490-
RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
54915446
}
54925447

54935448
static void rtl_csi_write(struct rtl8169_private *tp, int addr, int value)
@@ -5665,22 +5620,12 @@ static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable)
56655620
RTL_W8(tp, Config3, data);
56665621
}
56675622

5668-
#define R8168_CPCMD_QUIRK_MASK (\
5669-
EnableBist | \
5670-
Mac_dbgo_oe | \
5671-
Force_half_dup | \
5672-
Force_rxflow_en | \
5673-
Force_txflow_en | \
5674-
Cxpl_dbg_sel | \
5675-
ASF | \
5676-
PktCntrDisable | \
5677-
Mac_dbgo_sel)
5678-
56795623
static void rtl_hw_start_8168bb(struct rtl8169_private *tp)
56805624
{
56815625
RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
56825626

5683-
RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
5627+
tp->cp_cmd &= CPCMD_QUIRK_MASK;
5628+
RTL_W16(tp, CPlusCmd, tp->cp_cmd);
56845629

56855630
if (tp->dev->mtu <= ETH_DATA_LEN) {
56865631
rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B |
@@ -5708,7 +5653,8 @@ static void __rtl_hw_start_8168cp(struct rtl8169_private *tp)
57085653

57095654
rtl_disable_clock_request(tp);
57105655

5711-
RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
5656+
tp->cp_cmd &= CPCMD_QUIRK_MASK;
5657+
RTL_W16(tp, CPlusCmd, tp->cp_cmd);
57125658
}
57135659

57145660
static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp)
@@ -5737,7 +5683,8 @@ static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp)
57375683
if (tp->dev->mtu <= ETH_DATA_LEN)
57385684
rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
57395685

5740-
RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
5686+
tp->cp_cmd &= CPCMD_QUIRK_MASK;
5687+
RTL_W16(tp, CPlusCmd, tp->cp_cmd);
57415688
}
57425689

57435690
static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp)
@@ -5754,7 +5701,8 @@ static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp)
57545701
if (tp->dev->mtu <= ETH_DATA_LEN)
57555702
rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
57565703

5757-
RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
5704+
tp->cp_cmd &= CPCMD_QUIRK_MASK;
5705+
RTL_W16(tp, CPlusCmd, tp->cp_cmd);
57585706
}
57595707

57605708
static void rtl_hw_start_8168c_1(struct rtl8169_private *tp)
@@ -5811,7 +5759,8 @@ static void rtl_hw_start_8168d(struct rtl8169_private *tp)
58115759
if (tp->dev->mtu <= ETH_DATA_LEN)
58125760
rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
58135761

5814-
RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
5762+
tp->cp_cmd &= CPCMD_QUIRK_MASK;
5763+
RTL_W16(tp, CPlusCmd, tp->cp_cmd);
58155764
}
58165765

58175766
static void rtl_hw_start_8168dp(struct rtl8169_private *tp)
@@ -6274,14 +6223,10 @@ static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp)
62746223

62756224
static void rtl_hw_start_8168(struct rtl8169_private *tp)
62766225
{
6277-
RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
6278-
62796226
RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
62806227

6281-
rtl_set_rx_max_size(tp);
6282-
6283-
tp->cp_cmd |= RTL_R16(tp, CPlusCmd) | PktCntrDisable | INTT_1;
6284-
6228+
tp->cp_cmd &= ~INTT_MASK;
6229+
tp->cp_cmd |= PktCntrDisable | INTT_1;
62856230
RTL_W16(tp, CPlusCmd, tp->cp_cmd);
62866231

62876232
RTL_W16(tp, IntrMitigate, 0x5151);
@@ -6292,12 +6237,6 @@ static void rtl_hw_start_8168(struct rtl8169_private *tp)
62926237
tp->event_slow &= ~RxOverflow;
62936238
}
62946239

6295-
rtl_set_rx_tx_desc_registers(tp);
6296-
6297-
rtl_set_rx_tx_config_registers(tp);
6298-
6299-
RTL_R8(tp, IntrMask);
6300-
63016240
switch (tp->mac_version) {
63026241
case RTL_GIGA_MAC_VER_11:
63036242
rtl_hw_start_8168bb(tp);
@@ -6401,27 +6340,8 @@ static void rtl_hw_start_8168(struct rtl8169_private *tp)
64016340
tp->dev->name, tp->mac_version);
64026341
break;
64036342
}
6404-
6405-
RTL_W8(tp, Cfg9346, Cfg9346_Lock);
6406-
6407-
RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
6408-
6409-
rtl_set_rx_mode(tp->dev);
6410-
6411-
RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
64126343
}
64136344

6414-
#define R810X_CPCMD_QUIRK_MASK (\
6415-
EnableBist | \
6416-
Mac_dbgo_oe | \
6417-
Force_half_dup | \
6418-
Force_rxflow_en | \
6419-
Force_txflow_en | \
6420-
Cxpl_dbg_sel | \
6421-
ASF | \
6422-
PktCntrDisable | \
6423-
Mac_dbgo_sel)
6424-
64256345
static void rtl_hw_start_8102e_1(struct rtl8169_private *tp)
64266346
{
64276347
static const struct ephy_info e_info_8102e_1[] = {
@@ -6555,19 +6475,11 @@ static void rtl_hw_start_8101(struct rtl8169_private *tp)
65556475
pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL,
65566476
PCI_EXP_DEVCTL_NOSNOOP_EN);
65576477

6558-
RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
6559-
65606478
RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
65616479

6562-
rtl_set_rx_max_size(tp);
6563-
6564-
tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK;
6480+
tp->cp_cmd &= CPCMD_QUIRK_MASK;
65656481
RTL_W16(tp, CPlusCmd, tp->cp_cmd);
65666482

6567-
rtl_set_rx_tx_desc_registers(tp);
6568-
6569-
rtl_set_rx_tx_config_registers(tp);
6570-
65716483
switch (tp->mac_version) {
65726484
case RTL_GIGA_MAC_VER_07:
65736485
rtl_hw_start_8102e_1(tp);
@@ -6604,17 +6516,7 @@ static void rtl_hw_start_8101(struct rtl8169_private *tp)
66046516
break;
66056517
}
66066518

6607-
RTL_W8(tp, Cfg9346, Cfg9346_Lock);
6608-
66096519
RTL_W16(tp, IntrMitigate, 0x0000);
6610-
6611-
RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
6612-
6613-
rtl_set_rx_mode(tp->dev);
6614-
6615-
RTL_R8(tp, IntrMask);
6616-
6617-
RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
66186520
}
66196521

66206522
static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
@@ -7637,8 +7539,6 @@ static int rtl_open(struct net_device *dev)
76377539

76387540
rtl8169_init_phy(dev, tp);
76397541

7640-
__rtl8169_set_features(dev, dev->features);
7641-
76427542
rtl_pll_power_up(tp);
76437543

76447544
rtl_hw_start(tp);
@@ -8141,7 +8041,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
81418041
/* Identify chip attached to board */
81428042
rtl8169_get_mac_version(tp, cfg->default_ver);
81438043

8144-
tp->cp_cmd = 0;
8044+
tp->cp_cmd = RTL_R16(tp, CPlusCmd);
81458045

81468046
if ((sizeof(dma_addr_t) > 4) &&
81478047
(use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) &&

0 commit comments

Comments
 (0)