Skip to content

Commit

Permalink
Sync drivers/net/ethernet/realtek with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Aug 14, 2020
1 parent 47aab50 commit 3d085fc
Show file tree
Hide file tree
Showing 8 changed files with 2,452 additions and 2,772 deletions.
25 changes: 8 additions & 17 deletions drivers/net/ethernet/realtek/8139cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2054,10 +2054,9 @@ static void cp_remove_one (struct pci_dev *pdev)
free_netdev(dev);
}

#ifdef CONFIG_PM
static int cp_suspend (struct pci_dev *pdev, pm_message_t state)
static int __maybe_unused cp_suspend(struct device *device)
{
struct net_device *dev = pci_get_drvdata(pdev);
struct net_device *dev = dev_get_drvdata(device);
struct cp_private *cp = netdev_priv(dev);
unsigned long flags;

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

spin_unlock_irqrestore (&cp->lock, flags);

pci_save_state(pdev);
pci_enable_wake(pdev, pci_choose_state(pdev, state), cp->wol_enabled);
pci_set_power_state(pdev, pci_choose_state(pdev, state));
device_set_wakeup_enable(device, cp->wol_enabled);

return 0;
}

static int cp_resume (struct pci_dev *pdev)
static int __maybe_unused cp_resume(struct device *device)
{
struct net_device *dev = pci_get_drvdata (pdev);
struct net_device *dev = dev_get_drvdata(device);
struct cp_private *cp = netdev_priv(dev);
unsigned long flags;

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

netif_device_attach (dev);

pci_set_power_state(pdev, PCI_D0);
pci_restore_state(pdev);
pci_enable_wake(pdev, PCI_D0, 0);

/* FIXME: sh*t may happen if the Rx ring buffer is depleted */
cp_init_rings_index (cp);
cp_init_hw (cp);
Expand All @@ -2111,7 +2104,6 @@ static int cp_resume (struct pci_dev *pdev)

return 0;
}
#endif /* CONFIG_PM */

static const struct pci_device_id cp_pci_tbl[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, PCI_DEVICE_ID_REALTEK_8139), },
Expand All @@ -2120,15 +2112,14 @@ static const struct pci_device_id cp_pci_tbl[] = {
};
MODULE_DEVICE_TABLE(pci, cp_pci_tbl);

static SIMPLE_DEV_PM_OPS(cp_pm_ops, cp_suspend, cp_resume);

static struct pci_driver cp_driver = {
.name = DRV_NAME,
.id_table = cp_pci_tbl,
.probe = cp_init_one,
.remove = cp_remove_one,
#ifdef CONFIG_PM
.resume = cp_resume,
.suspend = cp_suspend,
#endif
.driver.pm = &cp_pm_ops,
};

module_pci_driver(cp_driver);
26 changes: 7 additions & 19 deletions drivers/net/ethernet/realtek/8139too.c
Original file line number Diff line number Diff line change
Expand Up @@ -2603,17 +2603,13 @@ static void rtl8139_set_rx_mode (struct net_device *dev)
spin_unlock_irqrestore (&tp->lock, flags);
}

#ifdef CONFIG_PM

static int rtl8139_suspend (struct pci_dev *pdev, pm_message_t state)
static int __maybe_unused rtl8139_suspend(struct device *device)
{
struct net_device *dev = pci_get_drvdata (pdev);
struct net_device *dev = dev_get_drvdata(device);
struct rtl8139_private *tp = netdev_priv(dev);
void __iomem *ioaddr = tp->mmio_addr;
unsigned long flags;

pci_save_state (pdev);

if (!netif_running (dev))
return 0;

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

spin_unlock_irqrestore (&tp->lock, flags);

pci_set_power_state (pdev, PCI_D3hot);

return 0;
}


static int rtl8139_resume (struct pci_dev *pdev)
static int __maybe_unused rtl8139_resume(struct device *device)
{
struct net_device *dev = pci_get_drvdata (pdev);
struct net_device *dev = dev_get_drvdata(device);

pci_restore_state (pdev);
if (!netif_running (dev))
return 0;
pci_set_power_state (pdev, PCI_D0);

rtl8139_init_ring (dev);
rtl8139_hw_start (dev);
netif_device_attach (dev);
return 0;
}

#endif /* CONFIG_PM */

static SIMPLE_DEV_PM_OPS(rtl8139_pm_ops, rtl8139_suspend, rtl8139_resume);

static struct pci_driver rtl8139_pci_driver = {
.name = DRV_NAME,
.id_table = rtl8139_pci_tbl,
.probe = rtl8139_init_one,
.remove = rtl8139_remove_one,
#ifdef CONFIG_PM
.suspend = rtl8139_suspend,
.resume = rtl8139_resume,
#endif /* CONFIG_PM */
.driver.pm = &rtl8139_pm_ops,
};


Expand Down
18 changes: 9 additions & 9 deletions drivers/net/ethernet/realtek/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ config NET_VENDOR_REALTEK
bool "Realtek devices"
default y
depends on PCI || (PARPORT && X86)
---help---
help
If you have a network (Ethernet) card belonging to this class, say Y.

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

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

Expand All @@ -59,7 +59,7 @@ config 8139TOO_PIO
bool "Use PIO instead of MMIO"
default y
depends on 8139TOO
---help---
help
This instructs the driver to use programmed I/O ports (PIO) instead
of PCI shared memory (MMIO). This can possibly solve some problems
in case your mainboard has memory consistency issues. If unsure,
Expand All @@ -68,7 +68,7 @@ config 8139TOO_PIO
config 8139TOO_TUNE_TWISTER
bool "Support for uncommon RTL-8139 rev. K (automatic channel equalization)"
depends on 8139TOO
---help---
help
This implements a function which might come in handy in case you
are using low quality on long cabling. It is required for RealTek
RTL-8139 revision K boards, and totally unused otherwise. It tries
Expand All @@ -79,7 +79,7 @@ config 8139TOO_TUNE_TWISTER
config 8139TOO_8129
bool "Support for older RTL-8129/8130 boards"
depends on 8139TOO
---help---
help
This enables support for the older and uncommon RTL-8129 and
RTL-8130 chips, which support MII via an external transceiver,
instead of an internal one. Disabling this option will save some
Expand All @@ -88,7 +88,7 @@ config 8139TOO_8129
config 8139_OLD_RX_RESET
bool "Use older RX-reset method"
depends on 8139TOO
---help---
help
The 8139too driver was recently updated to contain a more rapid
reset sequence, in the face of severe receive errors. This "new"
RX-reset method should be adequate for all boards. But if you
Expand All @@ -102,7 +102,7 @@ config R8169
select CRC32
select PHYLIB
select REALTEK_PHY
---help---
help
Say Y here if you have a Realtek Ethernet adapter belonging to
the following families:
RTL8169 Gigabit Ethernet
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/realtek/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
obj-$(CONFIG_8139CP) += 8139cp.o
obj-$(CONFIG_8139TOO) += 8139too.o
obj-$(CONFIG_ATP) += atp.o
r8169-objs += r8169_main.o r8169_firmware.o
r8169-objs += r8169_main.o r8169_firmware.o r8169_phy_config.o
obj-$(CONFIG_R8169) += r8169.o
78 changes: 78 additions & 0 deletions drivers/net/ethernet/realtek/r8169.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/* r8169.h: RealTek 8169/8168/8101 ethernet driver.
*
* Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
* Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
* Copyright (c) a lot of people too. Please respect their work.
*
* See MAINTAINERS file for support contact information.
*/

#include <linux/types.h>
#include <linux/phy.h>

enum mac_version {
/* support for ancient RTL_GIGA_MAC_VER_01 has been removed */
RTL_GIGA_MAC_VER_02,
RTL_GIGA_MAC_VER_03,
RTL_GIGA_MAC_VER_04,
RTL_GIGA_MAC_VER_05,
RTL_GIGA_MAC_VER_06,
RTL_GIGA_MAC_VER_07,
RTL_GIGA_MAC_VER_08,
RTL_GIGA_MAC_VER_09,
RTL_GIGA_MAC_VER_10,
RTL_GIGA_MAC_VER_11,
RTL_GIGA_MAC_VER_12,
RTL_GIGA_MAC_VER_13,
RTL_GIGA_MAC_VER_14,
RTL_GIGA_MAC_VER_16,
RTL_GIGA_MAC_VER_17,
RTL_GIGA_MAC_VER_18,
RTL_GIGA_MAC_VER_19,
RTL_GIGA_MAC_VER_20,
RTL_GIGA_MAC_VER_21,
RTL_GIGA_MAC_VER_22,
RTL_GIGA_MAC_VER_23,
RTL_GIGA_MAC_VER_24,
RTL_GIGA_MAC_VER_25,
RTL_GIGA_MAC_VER_26,
RTL_GIGA_MAC_VER_27,
RTL_GIGA_MAC_VER_28,
RTL_GIGA_MAC_VER_29,
RTL_GIGA_MAC_VER_30,
RTL_GIGA_MAC_VER_31,
RTL_GIGA_MAC_VER_32,
RTL_GIGA_MAC_VER_33,
RTL_GIGA_MAC_VER_34,
RTL_GIGA_MAC_VER_35,
RTL_GIGA_MAC_VER_36,
RTL_GIGA_MAC_VER_37,
RTL_GIGA_MAC_VER_38,
RTL_GIGA_MAC_VER_39,
RTL_GIGA_MAC_VER_40,
RTL_GIGA_MAC_VER_41,
RTL_GIGA_MAC_VER_42,
RTL_GIGA_MAC_VER_43,
RTL_GIGA_MAC_VER_44,
RTL_GIGA_MAC_VER_45,
RTL_GIGA_MAC_VER_46,
RTL_GIGA_MAC_VER_47,
RTL_GIGA_MAC_VER_48,
RTL_GIGA_MAC_VER_49,
RTL_GIGA_MAC_VER_50,
RTL_GIGA_MAC_VER_51,
RTL_GIGA_MAC_VER_52,
RTL_GIGA_MAC_VER_60,
RTL_GIGA_MAC_VER_61,
RTL_GIGA_MAC_VER_63,
RTL_GIGA_MAC_NONE
};

struct rtl8169_private;

void r8169_apply_firmware(struct rtl8169_private *tp);
u16 rtl8168h_2_get_adc_bias_ioffset(struct rtl8169_private *tp);
u8 rtl8168d_efuse_read(struct rtl8169_private *tp, int reg_addr);
void r8169_hw_phy_config(struct rtl8169_private *tp, struct phy_device *phydev,
enum mac_version ver);
19 changes: 12 additions & 7 deletions drivers/net/ethernet/realtek/r8169_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct fw_info {
u8 chksum;
} __packed;

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

static bool rtl_fw_format_ok(struct rtl_fw *rtl_fw)
{
Expand Down Expand Up @@ -92,19 +92,24 @@ static bool rtl_fw_data_ok(struct rtl_fw *rtl_fw)

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

switch (action >> 28) {
case PHY_READ:
case PHY_DATA_OR:
case PHY_DATA_AND:
case PHY_MDIO_CHG:
case PHY_CLEAR_READCOUNT:
case PHY_WRITE:
case PHY_WRITE_PREVIOUS:
case PHY_DELAY_MS:
break;

case PHY_MDIO_CHG:
if (val > 1)
goto out;
break;

case PHY_BJMPN:
if (regno > index)
goto out;
Expand Down Expand Up @@ -164,12 +169,12 @@ void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
index -= (regno + 1);
break;
case PHY_MDIO_CHG:
if (data == 0) {
fw_write = rtl_fw->phy_write;
fw_read = rtl_fw->phy_read;
} else if (data == 1) {
if (data) {
fw_write = rtl_fw->mac_mcu_write;
fw_read = rtl_fw->mac_mcu_read;
} else {
fw_write = rtl_fw->phy_write;
fw_read = rtl_fw->phy_read;
}

break;
Expand Down Expand Up @@ -198,7 +203,7 @@ void rtl_fw_write_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
index += regno;
break;
case PHY_DELAY_MS:
mdelay(data);
msleep(data);
break;
}
}
Expand Down
Loading

0 comments on commit 3d085fc

Please sign in to comment.