Skip to content

Commit 89a0c7a

Browse files
committed
Sync drivers/net/ethernet/realtek with upstream
1 parent ea4103d commit 89a0c7a

File tree

8 files changed

+2452
-2772
lines changed

8 files changed

+2452
-2772
lines changed

drivers/net/ethernet/realtek/8139cp.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,10 +2054,9 @@ static void cp_remove_one (struct pci_dev *pdev)
20542054
free_netdev(dev);
20552055
}
20562056

2057-
#ifdef CONFIG_PM
2058-
static int cp_suspend (struct pci_dev *pdev, pm_message_t state)
2057+
static int __maybe_unused cp_suspend(struct device *device)
20592058
{
2060-
struct net_device *dev = pci_get_drvdata(pdev);
2059+
struct net_device *dev = dev_get_drvdata(device);
20612060
struct cp_private *cp = netdev_priv(dev);
20622061
unsigned long flags;
20632062

@@ -2075,16 +2074,14 @@ static int cp_suspend (struct pci_dev *pdev, pm_message_t state)
20752074

20762075
spin_unlock_irqrestore (&cp->lock, flags);
20772076

2078-
pci_save_state(pdev);
2079-
pci_enable_wake(pdev, pci_choose_state(pdev, state), cp->wol_enabled);
2080-
pci_set_power_state(pdev, pci_choose_state(pdev, state));
2077+
device_set_wakeup_enable(device, cp->wol_enabled);
20812078

20822079
return 0;
20832080
}
20842081

2085-
static int cp_resume (struct pci_dev *pdev)
2082+
static int __maybe_unused cp_resume(struct device *device)
20862083
{
2087-
struct net_device *dev = pci_get_drvdata (pdev);
2084+
struct net_device *dev = dev_get_drvdata(device);
20882085
struct cp_private *cp = netdev_priv(dev);
20892086
unsigned long flags;
20902087

@@ -2093,10 +2090,6 @@ static int cp_resume (struct pci_dev *pdev)
20932090

20942091
netif_device_attach (dev);
20952092

2096-
pci_set_power_state(pdev, PCI_D0);
2097-
pci_restore_state(pdev);
2098-
pci_enable_wake(pdev, PCI_D0, 0);
2099-
21002093
/* FIXME: sh*t may happen if the Rx ring buffer is depleted */
21012094
cp_init_rings_index (cp);
21022095
cp_init_hw (cp);
@@ -2111,7 +2104,6 @@ static int cp_resume (struct pci_dev *pdev)
21112104

21122105
return 0;
21132106
}
2114-
#endif /* CONFIG_PM */
21152107

21162108
static const struct pci_device_id cp_pci_tbl[] = {
21172109
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, PCI_DEVICE_ID_REALTEK_8139), },
@@ -2120,15 +2112,14 @@ static const struct pci_device_id cp_pci_tbl[] = {
21202112
};
21212113
MODULE_DEVICE_TABLE(pci, cp_pci_tbl);
21222114

2115+
static SIMPLE_DEV_PM_OPS(cp_pm_ops, cp_suspend, cp_resume);
2116+
21232117
static struct pci_driver cp_driver = {
21242118
.name = DRV_NAME,
21252119
.id_table = cp_pci_tbl,
21262120
.probe = cp_init_one,
21272121
.remove = cp_remove_one,
2128-
#ifdef CONFIG_PM
2129-
.resume = cp_resume,
2130-
.suspend = cp_suspend,
2131-
#endif
2122+
.driver.pm = &cp_pm_ops,
21322123
};
21332124

21342125
module_pci_driver(cp_driver);

drivers/net/ethernet/realtek/8139too.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,17 +2603,13 @@ static void rtl8139_set_rx_mode (struct net_device *dev)
26032603
spin_unlock_irqrestore (&tp->lock, flags);
26042604
}
26052605

2606-
#ifdef CONFIG_PM
2607-
2608-
static int rtl8139_suspend (struct pci_dev *pdev, pm_message_t state)
2606+
static int __maybe_unused rtl8139_suspend(struct device *device)
26092607
{
2610-
struct net_device *dev = pci_get_drvdata (pdev);
2608+
struct net_device *dev = dev_get_drvdata(device);
26112609
struct rtl8139_private *tp = netdev_priv(dev);
26122610
void __iomem *ioaddr = tp->mmio_addr;
26132611
unsigned long flags;
26142612

2615-
pci_save_state (pdev);
2616-
26172613
if (!netif_running (dev))
26182614
return 0;
26192615

@@ -2631,38 +2627,30 @@ static int rtl8139_suspend (struct pci_dev *pdev, pm_message_t state)
26312627

26322628
spin_unlock_irqrestore (&tp->lock, flags);
26332629

2634-
pci_set_power_state (pdev, PCI_D3hot);
2635-
26362630
return 0;
26372631
}
26382632

2639-
2640-
static int rtl8139_resume (struct pci_dev *pdev)
2633+
static int __maybe_unused rtl8139_resume(struct device *device)
26412634
{
2642-
struct net_device *dev = pci_get_drvdata (pdev);
2635+
struct net_device *dev = dev_get_drvdata(device);
26432636

2644-
pci_restore_state (pdev);
26452637
if (!netif_running (dev))
26462638
return 0;
2647-
pci_set_power_state (pdev, PCI_D0);
2639+
26482640
rtl8139_init_ring (dev);
26492641
rtl8139_hw_start (dev);
26502642
netif_device_attach (dev);
26512643
return 0;
26522644
}
26532645

2654-
#endif /* CONFIG_PM */
2655-
2646+
static SIMPLE_DEV_PM_OPS(rtl8139_pm_ops, rtl8139_suspend, rtl8139_resume);
26562647

26572648
static struct pci_driver rtl8139_pci_driver = {
26582649
.name = DRV_NAME,
26592650
.id_table = rtl8139_pci_tbl,
26602651
.probe = rtl8139_init_one,
26612652
.remove = rtl8139_remove_one,
2662-
#ifdef CONFIG_PM
2663-
.suspend = rtl8139_suspend,
2664-
.resume = rtl8139_resume,
2665-
#endif /* CONFIG_PM */
2653+
.driver.pm = &rtl8139_pm_ops,
26662654
};
26672655

26682656

drivers/net/ethernet/realtek/Kconfig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ config NET_VENDOR_REALTEK
77
bool "Realtek devices"
88
default y
99
depends on PCI || (PARPORT && X86)
10-
---help---
10+
help
1111
If you have a network (Ethernet) card belonging to this class, say Y.
1212

1313
Note that the answer to this question doesn't directly affect the
@@ -21,7 +21,7 @@ config ATP
2121
tristate "AT-LAN-TEC/RealTek pocket adapter support"
2222
depends on PARPORT && X86
2323
select CRC32
24-
---help---
24+
help
2525
This is a network (Ethernet) device which attaches to your parallel
2626
port. Read the file <file:drivers/net/ethernet/realtek/atp.c>
2727
if you want to use this. If you intend to use this driver, you
@@ -36,7 +36,7 @@ config 8139CP
3636
depends on PCI
3737
select CRC32
3838
select MII
39-
---help---
39+
help
4040
This is a driver for the Fast Ethernet PCI network cards based on
4141
the RTL8139C+ chips. If you have one of those, say Y here.
4242

@@ -48,7 +48,7 @@ config 8139TOO
4848
depends on PCI
4949
select CRC32
5050
select MII
51-
---help---
51+
help
5252
This is a driver for the Fast Ethernet PCI network cards based on
5353
the RTL 8129/8130/8139 chips. If you have one of those, say Y here.
5454

@@ -59,7 +59,7 @@ config 8139TOO_PIO
5959
bool "Use PIO instead of MMIO"
6060
default y
6161
depends on 8139TOO
62-
---help---
62+
help
6363
This instructs the driver to use programmed I/O ports (PIO) instead
6464
of PCI shared memory (MMIO). This can possibly solve some problems
6565
in case your mainboard has memory consistency issues. If unsure,
@@ -68,7 +68,7 @@ config 8139TOO_PIO
6868
config 8139TOO_TUNE_TWISTER
6969
bool "Support for uncommon RTL-8139 rev. K (automatic channel equalization)"
7070
depends on 8139TOO
71-
---help---
71+
help
7272
This implements a function which might come in handy in case you
7373
are using low quality on long cabling. It is required for RealTek
7474
RTL-8139 revision K boards, and totally unused otherwise. It tries
@@ -79,7 +79,7 @@ config 8139TOO_TUNE_TWISTER
7979
config 8139TOO_8129
8080
bool "Support for older RTL-8129/8130 boards"
8181
depends on 8139TOO
82-
---help---
82+
help
8383
This enables support for the older and uncommon RTL-8129 and
8484
RTL-8130 chips, which support MII via an external transceiver,
8585
instead of an internal one. Disabling this option will save some
@@ -88,7 +88,7 @@ config 8139TOO_8129
8888
config 8139_OLD_RX_RESET
8989
bool "Use older RX-reset method"
9090
depends on 8139TOO
91-
---help---
91+
help
9292
The 8139too driver was recently updated to contain a more rapid
9393
reset sequence, in the face of severe receive errors. This "new"
9494
RX-reset method should be adequate for all boards. But if you
@@ -102,7 +102,7 @@ config R8169
102102
select CRC32
103103
select PHYLIB
104104
select REALTEK_PHY
105-
---help---
105+
help
106106
Say Y here if you have a Realtek Ethernet adapter belonging to
107107
the following families:
108108
RTL8169 Gigabit Ethernet

drivers/net/ethernet/realtek/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
obj-$(CONFIG_8139CP) += 8139cp.o
77
obj-$(CONFIG_8139TOO) += 8139too.o
88
obj-$(CONFIG_ATP) += atp.o
9-
r8169-objs += r8169_main.o r8169_firmware.o
9+
r8169-objs += r8169_main.o r8169_firmware.o r8169_phy_config.o
1010
obj-$(CONFIG_R8169) += r8169.o
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/* r8169.h: RealTek 8169/8168/8101 ethernet driver.
3+
*
4+
* Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
5+
* Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
6+
* Copyright (c) a lot of people too. Please respect their work.
7+
*
8+
* See MAINTAINERS file for support contact information.
9+
*/
10+
11+
#include <linux/types.h>
12+
#include <linux/phy.h>
13+
14+
enum mac_version {
15+
/* support for ancient RTL_GIGA_MAC_VER_01 has been removed */
16+
RTL_GIGA_MAC_VER_02,
17+
RTL_GIGA_MAC_VER_03,
18+
RTL_GIGA_MAC_VER_04,
19+
RTL_GIGA_MAC_VER_05,
20+
RTL_GIGA_MAC_VER_06,
21+
RTL_GIGA_MAC_VER_07,
22+
RTL_GIGA_MAC_VER_08,
23+
RTL_GIGA_MAC_VER_09,
24+
RTL_GIGA_MAC_VER_10,
25+
RTL_GIGA_MAC_VER_11,
26+
RTL_GIGA_MAC_VER_12,
27+
RTL_GIGA_MAC_VER_13,
28+
RTL_GIGA_MAC_VER_14,
29+
RTL_GIGA_MAC_VER_16,
30+
RTL_GIGA_MAC_VER_17,
31+
RTL_GIGA_MAC_VER_18,
32+
RTL_GIGA_MAC_VER_19,
33+
RTL_GIGA_MAC_VER_20,
34+
RTL_GIGA_MAC_VER_21,
35+
RTL_GIGA_MAC_VER_22,
36+
RTL_GIGA_MAC_VER_23,
37+
RTL_GIGA_MAC_VER_24,
38+
RTL_GIGA_MAC_VER_25,
39+
RTL_GIGA_MAC_VER_26,
40+
RTL_GIGA_MAC_VER_27,
41+
RTL_GIGA_MAC_VER_28,
42+
RTL_GIGA_MAC_VER_29,
43+
RTL_GIGA_MAC_VER_30,
44+
RTL_GIGA_MAC_VER_31,
45+
RTL_GIGA_MAC_VER_32,
46+
RTL_GIGA_MAC_VER_33,
47+
RTL_GIGA_MAC_VER_34,
48+
RTL_GIGA_MAC_VER_35,
49+
RTL_GIGA_MAC_VER_36,
50+
RTL_GIGA_MAC_VER_37,
51+
RTL_GIGA_MAC_VER_38,
52+
RTL_GIGA_MAC_VER_39,
53+
RTL_GIGA_MAC_VER_40,
54+
RTL_GIGA_MAC_VER_41,
55+
RTL_GIGA_MAC_VER_42,
56+
RTL_GIGA_MAC_VER_43,
57+
RTL_GIGA_MAC_VER_44,
58+
RTL_GIGA_MAC_VER_45,
59+
RTL_GIGA_MAC_VER_46,
60+
RTL_GIGA_MAC_VER_47,
61+
RTL_GIGA_MAC_VER_48,
62+
RTL_GIGA_MAC_VER_49,
63+
RTL_GIGA_MAC_VER_50,
64+
RTL_GIGA_MAC_VER_51,
65+
RTL_GIGA_MAC_VER_52,
66+
RTL_GIGA_MAC_VER_60,
67+
RTL_GIGA_MAC_VER_61,
68+
RTL_GIGA_MAC_VER_63,
69+
RTL_GIGA_MAC_NONE
70+
};
71+
72+
struct rtl8169_private;
73+
74+
void r8169_apply_firmware(struct rtl8169_private *tp);
75+
u16 rtl8168h_2_get_adc_bias_ioffset(struct rtl8169_private *tp);
76+
u8 rtl8168d_efuse_read(struct rtl8169_private *tp, int reg_addr);
77+
void r8169_hw_phy_config(struct rtl8169_private *tp, struct phy_device *phydev,
78+
enum mac_version ver);

drivers/net/ethernet/realtek/r8169_firmware.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct fw_info {
3737
u8 chksum;
3838
} __packed;
3939

40-
#define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code))
40+
#define FW_OPCODE_SIZE sizeof_field(struct rtl_fw_phy_action, code[0])
4141

4242
static bool rtl_fw_format_ok(struct rtl_fw *rtl_fw)
4343
{
@@ -92,19 +92,24 @@ static bool rtl_fw_data_ok(struct rtl_fw *rtl_fw)
9292

9393
for (index = 0; index < pa->size; index++) {
9494
u32 action = le32_to_cpu(pa->code[index]);
95+
u32 val = action & 0x0000ffff;
9596
u32 regno = (action & 0x0fff0000) >> 16;
9697

9798
switch (action >> 28) {
9899
case PHY_READ:
99100
case PHY_DATA_OR:
100101
case PHY_DATA_AND:
101-
case PHY_MDIO_CHG:
102102
case PHY_CLEAR_READCOUNT:
103103
case PHY_WRITE:
104104
case PHY_WRITE_PREVIOUS:
105105
case PHY_DELAY_MS:
106106
break;
107107

108+
case PHY_MDIO_CHG:
109+
if (val > 1)
110+
goto out;
111+
break;
112+
108113
case PHY_BJMPN:
109114
if (regno > index)
110115
goto out;
@@ -164,12 +169,12 @@ void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
164169
index -= (regno + 1);
165170
break;
166171
case PHY_MDIO_CHG:
167-
if (data == 0) {
168-
fw_write = rtl_fw->phy_write;
169-
fw_read = rtl_fw->phy_read;
170-
} else if (data == 1) {
172+
if (data) {
171173
fw_write = rtl_fw->mac_mcu_write;
172174
fw_read = rtl_fw->mac_mcu_read;
175+
} else {
176+
fw_write = rtl_fw->phy_write;
177+
fw_read = rtl_fw->phy_read;
173178
}
174179

175180
break;
@@ -198,7 +203,7 @@ void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
198203
index += regno;
199204
break;
200205
case PHY_DELAY_MS:
201-
mdelay(data);
206+
msleep(data);
202207
break;
203208
}
204209
}

0 commit comments

Comments
 (0)