* [PATCH net-next 0/6] r8169: patch set with further smaller improvements
@ 2018-03-24 22:11 Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 1/6] r8169: change argument type of callback hw_start in struct rtl8169_private Heiner Kallweit
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Heiner Kallweit @ 2018-03-24 22:11 UTC (permalink / raw)
To: Realtek linux nic maintainers, David Miller; +Cc: netdev@vger.kernel.org
Patch set with further changes w/o functional change aiming at
streamlining and simplifying the code.
Heiner Kallweit (6):
r8169: change argument type of callback hw_start in struct rtl8169_private
r8169: change argument type of counter functions
r8169: change argument type of PHY-related functions
r8169: change argument type of interrupt handler
r8169: change type of driver_data
r8169: change argument type of rtl8169_net_suspend and __rtl8169_resume
drivers/net/ethernet/realtek/r8169.c | 170 ++++++++++++++---------------------
1 file changed, 68 insertions(+), 102 deletions(-)
--
2.16.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next 1/6] r8169: change argument type of callback hw_start in struct rtl8169_private
2018-03-24 22:11 [PATCH net-next 0/6] r8169: patch set with further smaller improvements Heiner Kallweit
@ 2018-03-24 22:18 ` Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 2/6] r8169: change argument type of counter functions Heiner Kallweit
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2018-03-24 22:18 UTC (permalink / raw)
To: Realtek linux nic maintainers, David Miller; +Cc: netdev@vger.kernel.org
Change argument type of callback hw_start to be more in line with the
other callbacks and to simplify the code.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/ethernet/realtek/r8169.c | 41 +++++++++++++-----------------------
1 file changed, 15 insertions(+), 26 deletions(-)
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 630409e0..74435ba9 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -821,7 +821,7 @@ struct rtl8169_private {
int (*get_link_ksettings)(struct net_device *,
struct ethtool_link_ksettings *);
void (*phy_reset_enable)(struct rtl8169_private *tp);
- void (*hw_start)(struct net_device *);
+ void (*hw_start)(struct rtl8169_private *tp);
unsigned int (*phy_reset_pending)(struct rtl8169_private *tp);
unsigned int (*link_ok)(struct rtl8169_private *tp);
int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd);
@@ -5358,12 +5358,9 @@ static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp)
(InterFrameGap << TxInterFrameGapShift));
}
-static void rtl_hw_start(struct net_device *dev)
+static void rtl_hw_start(struct rtl8169_private *tp)
{
- struct rtl8169_private *tp = netdev_priv(dev);
-
- tp->hw_start(dev);
-
+ tp->hw_start(tp);
rtl_irq_enable_all(tp);
}
@@ -5472,14 +5469,11 @@ static void rtl_set_rx_mode(struct net_device *dev)
RTL_W32(tp, RxConfig, tmp);
}
-static void rtl_hw_start_8169(struct net_device *dev)
+static void rtl_hw_start_8169(struct rtl8169_private *tp)
{
- struct rtl8169_private *tp = netdev_priv(dev);
- struct pci_dev *pdev = tp->pci_dev;
-
if (tp->mac_version == RTL_GIGA_MAC_VER_05) {
RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) | PCIMulRW);
- pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08);
+ pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08);
}
RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
@@ -5537,7 +5531,7 @@ static void rtl_hw_start_8169(struct net_device *dev)
RTL_W32(tp, RxMissed, 0);
- rtl_set_rx_mode(dev);
+ rtl_set_rx_mode(tp->dev);
/* no early-rx interrupts */
RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
@@ -6325,10 +6319,8 @@ static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp)
r8168_mac_ocp_write(tp, 0xe860, data);
}
-static void rtl_hw_start_8168(struct net_device *dev)
+static void rtl_hw_start_8168(struct rtl8169_private *tp)
{
- struct rtl8169_private *tp = netdev_priv(dev);
-
RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
@@ -6453,7 +6445,7 @@ static void rtl_hw_start_8168(struct net_device *dev)
default:
printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n",
- dev->name, tp->mac_version);
+ tp->dev->name, tp->mac_version);
break;
}
@@ -6461,7 +6453,7 @@ static void rtl_hw_start_8168(struct net_device *dev)
RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
- rtl_set_rx_mode(dev);
+ rtl_set_rx_mode(tp->dev);
RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
}
@@ -6600,17 +6592,14 @@ static void rtl_hw_start_8106(struct rtl8169_private *tp)
rtl_pcie_state_l2l3_enable(tp, false);
}
-static void rtl_hw_start_8101(struct net_device *dev)
+static void rtl_hw_start_8101(struct rtl8169_private *tp)
{
- struct rtl8169_private *tp = netdev_priv(dev);
- struct pci_dev *pdev = tp->pci_dev;
-
if (tp->mac_version >= RTL_GIGA_MAC_VER_30)
tp->event_slow &= ~RxFIFOOver;
if (tp->mac_version == RTL_GIGA_MAC_VER_13 ||
tp->mac_version == RTL_GIGA_MAC_VER_16)
- pcie_capability_set_word(pdev, PCI_EXP_DEVCTL,
+ pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL,
PCI_EXP_DEVCTL_NOSNOOP_EN);
RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
@@ -6668,7 +6657,7 @@ static void rtl_hw_start_8101(struct net_device *dev)
RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
- rtl_set_rx_mode(dev);
+ rtl_set_rx_mode(tp->dev);
RTL_R8(tp, IntrMask);
@@ -6880,7 +6869,7 @@ static void rtl_reset_work(struct rtl8169_private *tp)
rtl8169_init_ring_indexes(tp);
napi_enable(&tp->napi);
- rtl_hw_start(dev);
+ rtl_hw_start(tp);
netif_wake_queue(dev);
rtl8169_check_link_status(dev, tp);
}
@@ -7710,7 +7699,7 @@ static int rtl_open(struct net_device *dev)
rtl_pll_power_up(tp);
- rtl_hw_start(dev);
+ rtl_hw_start(tp);
if (!rtl8169_init_counter_offsets(dev))
netif_warn(tp, hw, dev, "counter reset/update failed\n");
@@ -8017,7 +8006,7 @@ static const struct net_device_ops rtl_netdev_ops = {
};
static const struct rtl_cfg_info {
- void (*hw_start)(struct net_device *);
+ void (*hw_start)(struct rtl8169_private *);
unsigned int region;
unsigned int align;
u16 event_slow;
--
2.16.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next 2/6] r8169: change argument type of counter functions
2018-03-24 22:11 [PATCH net-next 0/6] r8169: patch set with further smaller improvements Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 1/6] r8169: change argument type of callback hw_start in struct rtl8169_private Heiner Kallweit
@ 2018-03-24 22:18 ` Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 3/6] r8169: change argument type of PHY-related functions Heiner Kallweit
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2018-03-24 22:18 UTC (permalink / raw)
To: Realtek linux nic maintainers, David Miller; +Cc: netdev@vger.kernel.org
These counter functions don't deal with the net_device, so change the
argument type to struct rtl8169_private *.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/ethernet/realtek/r8169.c | 32 +++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 74435ba9..0f1c19e8 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -2155,9 +2155,8 @@ DECLARE_RTL_COND(rtl_counters_cond)
return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump);
}
-static bool rtl8169_do_counters(struct net_device *dev, u32 counter_cmd)
+static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd)
{
- struct rtl8169_private *tp = netdev_priv(dev);
dma_addr_t paddr = tp->counters_phys_addr;
u32 cmd;
@@ -2170,10 +2169,8 @@ static bool rtl8169_do_counters(struct net_device *dev, u32 counter_cmd)
return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000);
}
-static bool rtl8169_reset_counters(struct net_device *dev)
+static bool rtl8169_reset_counters(struct rtl8169_private *tp)
{
- struct rtl8169_private *tp = netdev_priv(dev);
-
/*
* Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the
* tally counters.
@@ -2181,13 +2178,11 @@ static bool rtl8169_reset_counters(struct net_device *dev)
if (tp->mac_version < RTL_GIGA_MAC_VER_19)
return true;
- return rtl8169_do_counters(dev, CounterReset);
+ return rtl8169_do_counters(tp, CounterReset);
}
-static bool rtl8169_update_counters(struct net_device *dev)
+static bool rtl8169_update_counters(struct rtl8169_private *tp)
{
- struct rtl8169_private *tp = netdev_priv(dev);
-
/*
* Some chips are unable to dump tally counters when the receiver
* is disabled.
@@ -2195,12 +2190,11 @@ static bool rtl8169_update_counters(struct net_device *dev)
if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0)
return true;
- return rtl8169_do_counters(dev, CounterDump);
+ return rtl8169_do_counters(tp, CounterDump);
}
-static bool rtl8169_init_counter_offsets(struct net_device *dev)
+static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp)
{
- struct rtl8169_private *tp = netdev_priv(dev);
struct rtl8169_counters *counters = tp->counters;
bool ret = false;
@@ -2223,10 +2217,10 @@ static bool rtl8169_init_counter_offsets(struct net_device *dev)
return true;
/* If both, reset and update fail, propagate to caller. */
- if (rtl8169_reset_counters(dev))
+ if (rtl8169_reset_counters(tp))
ret = true;
- if (rtl8169_update_counters(dev))
+ if (rtl8169_update_counters(tp))
ret = true;
tp->tc_offset.tx_errors = counters->tx_errors;
@@ -2249,7 +2243,7 @@ static void rtl8169_get_ethtool_stats(struct net_device *dev,
pm_runtime_get_noresume(d);
if (pm_runtime_active(d))
- rtl8169_update_counters(dev);
+ rtl8169_update_counters(tp);
pm_runtime_put_noidle(d);
@@ -7617,7 +7611,7 @@ static int rtl8169_close(struct net_device *dev)
pm_runtime_get_sync(&pdev->dev);
/* Update counters before going down */
- rtl8169_update_counters(dev);
+ rtl8169_update_counters(tp);
rtl_lock_work(tp);
clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
@@ -7701,7 +7695,7 @@ static int rtl_open(struct net_device *dev)
rtl_hw_start(tp);
- if (!rtl8169_init_counter_offsets(dev))
+ if (!rtl8169_init_counter_offsets(tp))
netif_warn(tp, hw, dev, "counter reset/update failed\n");
netif_start_queue(dev);
@@ -7770,7 +7764,7 @@ rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
* from tally counters.
*/
if (pm_runtime_active(&pdev->dev))
- rtl8169_update_counters(dev);
+ rtl8169_update_counters(tp);
/*
* Subtract values fetched during initalization.
@@ -7866,7 +7860,7 @@ static int rtl8169_runtime_suspend(struct device *device)
/* Update counters before going runtime suspend */
rtl8169_rx_missed(dev);
- rtl8169_update_counters(dev);
+ rtl8169_update_counters(tp);
return 0;
}
--
2.16.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next 3/6] r8169: change argument type of PHY-related functions
2018-03-24 22:11 [PATCH net-next 0/6] r8169: patch set with further smaller improvements Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 1/6] r8169: change argument type of callback hw_start in struct rtl8169_private Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 2/6] r8169: change argument type of counter functions Heiner Kallweit
@ 2018-03-24 22:18 ` Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 4/6] r8169: change argument type of interrupt handler Heiner Kallweit
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2018-03-24 22:18 UTC (permalink / raw)
To: Realtek linux nic maintainers, David Miller; +Cc: netdev@vger.kernel.org
Some PHY-related functions functions can be a little streamlined and
simplified by taking a struct rtl8169_private * argument.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/ethernet/realtek/r8169.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 0f1c19e8..a0e32557 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -4370,10 +4370,8 @@ static void rtl8106e_hw_phy_config(struct rtl8169_private *tp)
rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
}
-static void rtl_hw_phy_config(struct net_device *dev)
+static void rtl_hw_phy_config(struct rtl8169_private *tp)
{
- struct rtl8169_private *tp = netdev_priv(dev);
-
rtl8169_print_mac_version(tp);
switch (tp->mac_version) {
@@ -4546,8 +4544,7 @@ DECLARE_RTL_COND(rtl_phy_reset_cond)
return tp->phy_reset_pending(tp);
}
-static void rtl8169_phy_reset(struct net_device *dev,
- struct rtl8169_private *tp)
+static void rtl8169_phy_reset(struct rtl8169_private *tp)
{
tp->phy_reset_enable(tp);
rtl_msleep_loop_wait_low(tp, &rtl_phy_reset_cond, 1, 100);
@@ -4559,9 +4556,9 @@ static bool rtl_tbi_enabled(struct rtl8169_private *tp)
(RTL_R8(tp, PHYstatus) & TBI_Enable);
}
-static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
+static void rtl8169_init_phy(struct rtl8169_private *tp)
{
- rtl_hw_phy_config(dev);
+ rtl_hw_phy_config(tp);
if (tp->mac_version <= RTL_GIGA_MAC_VER_06) {
dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
@@ -4580,9 +4577,9 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0
}
- rtl8169_phy_reset(dev, tp);
+ rtl8169_phy_reset(tp);
- rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL,
+ rtl8169_set_speed(tp->dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL,
ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
(tp->mii.supports_gmii ?
@@ -4590,7 +4587,7 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
ADVERTISED_1000baseT_Full : 0));
if (rtl_tbi_enabled(tp))
- netif_info(tp, link, dev, "TBI auto-negotiating\n");
+ netif_info(tp, link, tp->dev, "TBI auto-negotiating\n");
}
static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr)
@@ -7687,7 +7684,7 @@ static int rtl_open(struct net_device *dev)
napi_enable(&tp->napi);
- rtl8169_init_phy(dev, tp);
+ rtl8169_init_phy(tp);
__rtl8169_set_features(dev, dev->features);
@@ -7832,7 +7829,7 @@ static int rtl8169_resume(struct device *device)
struct net_device *dev = pci_get_drvdata(pdev);
struct rtl8169_private *tp = netdev_priv(dev);
- rtl8169_init_phy(dev, tp);
+ rtl8169_init_phy(tp);
if (netif_running(dev))
__rtl8169_resume(dev);
@@ -7880,7 +7877,7 @@ static int rtl8169_runtime_resume(struct device *device)
tp->saved_wolopts = 0;
rtl_unlock_work(tp);
- rtl8169_init_phy(dev, tp);
+ rtl8169_init_phy(tp);
__rtl8169_resume(dev);
--
2.16.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next 4/6] r8169: change argument type of interrupt handler
2018-03-24 22:11 [PATCH net-next 0/6] r8169: patch set with further smaller improvements Heiner Kallweit
` (2 preceding siblings ...)
2018-03-24 22:18 ` [PATCH net-next 3/6] r8169: change argument type of PHY-related functions Heiner Kallweit
@ 2018-03-24 22:18 ` Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 5/6] r8169: change type of driver_data Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 6/6] r8169: change argument type of rtl8169_net_suspend and __rtl8169_resume Heiner Kallweit
5 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2018-03-24 22:18 UTC (permalink / raw)
To: Realtek linux nic maintainers, David Miller; +Cc: netdev@vger.kernel.org
The interrupt handler doesn't need the net_device, therefore change the
argument type to struct rtl8169_private *.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/ethernet/realtek/r8169.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index a0e32557..2d68306e 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7445,8 +7445,7 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, u32 budget
static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
{
- struct net_device *dev = dev_instance;
- struct rtl8169_private *tp = netdev_priv(dev);
+ struct rtl8169_private *tp = dev_instance;
int handled = 0;
u16 status;
@@ -7618,7 +7617,7 @@ static int rtl8169_close(struct net_device *dev)
cancel_work_sync(&tp->wk.work);
- pci_free_irq(pdev, 0, dev);
+ pci_free_irq(pdev, 0, tp);
dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
tp->RxPhyAddr);
@@ -7673,7 +7672,7 @@ static int rtl_open(struct net_device *dev)
rtl_request_firmware(tp);
- retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, dev,
+ retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp,
dev->name);
if (retval < 0)
goto err_release_fw_2;
--
2.16.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next 5/6] r8169: change type of driver_data
2018-03-24 22:11 [PATCH net-next 0/6] r8169: patch set with further smaller improvements Heiner Kallweit
` (3 preceding siblings ...)
2018-03-24 22:18 ` [PATCH net-next 4/6] r8169: change argument type of interrupt handler Heiner Kallweit
@ 2018-03-24 22:18 ` Heiner Kallweit
2018-03-25 20:43 ` David Miller
2018-03-24 22:18 ` [PATCH net-next 6/6] r8169: change argument type of rtl8169_net_suspend and __rtl8169_resume Heiner Kallweit
5 siblings, 1 reply; 9+ messages in thread
From: Heiner Kallweit @ 2018-03-24 22:18 UTC (permalink / raw)
To: Realtek linux nic maintainers, David Miller; +Cc: netdev@vger.kernel.org
Several functions accessing the device driver_data field don't need the
net_device. All needed parameters can be accessed via struct
rtl8169_private, therefore change type of driver_data accordingly.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/ethernet/realtek/r8169.c | 51 +++++++++++++++---------------------
1 file changed, 21 insertions(+), 30 deletions(-)
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 2d68306e..dd84cc3a 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7798,10 +7798,9 @@ static void rtl8169_net_suspend(struct net_device *dev)
static int rtl8169_suspend(struct device *device)
{
- struct pci_dev *pdev = to_pci_dev(device);
- struct net_device *dev = pci_get_drvdata(pdev);
+ struct rtl8169_private *tp = dev_get_drvdata(device);
- rtl8169_net_suspend(dev);
+ rtl8169_net_suspend(tp->dev);
return 0;
}
@@ -7824,23 +7823,19 @@ static void __rtl8169_resume(struct net_device *dev)
static int rtl8169_resume(struct device *device)
{
- struct pci_dev *pdev = to_pci_dev(device);
- struct net_device *dev = pci_get_drvdata(pdev);
- struct rtl8169_private *tp = netdev_priv(dev);
+ struct rtl8169_private *tp = dev_get_drvdata(device);
rtl8169_init_phy(tp);
- if (netif_running(dev))
- __rtl8169_resume(dev);
+ if (netif_running(tp->dev))
+ __rtl8169_resume(tp->dev);
return 0;
}
static int rtl8169_runtime_suspend(struct device *device)
{
- struct pci_dev *pdev = to_pci_dev(device);
- struct net_device *dev = pci_get_drvdata(pdev);
- struct rtl8169_private *tp = netdev_priv(dev);
+ struct rtl8169_private *tp = dev_get_drvdata(device);
if (!tp->TxDescArray) {
rtl_pll_power_down(tp);
@@ -7852,10 +7847,10 @@ static int rtl8169_runtime_suspend(struct device *device)
__rtl8169_set_wol(tp, WAKE_ANY);
rtl_unlock_work(tp);
- rtl8169_net_suspend(dev);
+ rtl8169_net_suspend(tp->dev);
/* Update counters before going runtime suspend */
- rtl8169_rx_missed(dev);
+ rtl8169_rx_missed(tp->dev);
rtl8169_update_counters(tp);
return 0;
@@ -7863,10 +7858,9 @@ static int rtl8169_runtime_suspend(struct device *device)
static int rtl8169_runtime_resume(struct device *device)
{
- struct pci_dev *pdev = to_pci_dev(device);
- struct net_device *dev = pci_get_drvdata(pdev);
- struct rtl8169_private *tp = netdev_priv(dev);
- rtl_rar_set(tp, dev->dev_addr);
+ struct rtl8169_private *tp = dev_get_drvdata(device);
+
+ rtl_rar_set(tp, tp->dev->dev_addr);
if (!tp->TxDescArray)
return 0;
@@ -7878,17 +7872,16 @@ static int rtl8169_runtime_resume(struct device *device)
rtl8169_init_phy(tp);
- __rtl8169_resume(dev);
+ __rtl8169_resume(tp->dev);
return 0;
}
static int rtl8169_runtime_idle(struct device *device)
{
- struct pci_dev *pdev = to_pci_dev(device);
- struct net_device *dev = pci_get_drvdata(pdev);
+ struct rtl8169_private *tp = dev_get_drvdata(device);
- if (!netif_running(dev) || !netif_carrier_ok(dev))
+ if (!netif_running(tp->dev) || !netif_carrier_ok(tp->dev))
pm_schedule_suspend(device, 10000);
return -EBUSY;
@@ -7934,13 +7927,12 @@ static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp)
static void rtl_shutdown(struct pci_dev *pdev)
{
- struct net_device *dev = pci_get_drvdata(pdev);
- struct rtl8169_private *tp = netdev_priv(dev);
+ struct rtl8169_private *tp = pci_get_drvdata(pdev);
- rtl8169_net_suspend(dev);
+ rtl8169_net_suspend(tp->dev);
/* Restore original MAC address */
- rtl_rar_set(tp, dev->perm_addr);
+ rtl_rar_set(tp, tp->dev->perm_addr);
rtl8169_hw_reset(tp);
@@ -7957,15 +7949,14 @@ static void rtl_shutdown(struct pci_dev *pdev)
static void rtl_remove_one(struct pci_dev *pdev)
{
- struct net_device *dev = pci_get_drvdata(pdev);
- struct rtl8169_private *tp = netdev_priv(dev);
+ struct rtl8169_private *tp = pci_get_drvdata(pdev);
if (r8168_check_dash(tp))
rtl8168_driver_stop(tp);
netif_napi_del(&tp->napi);
- unregister_netdev(dev);
+ unregister_netdev(tp->dev);
rtl_release_firmware(tp);
@@ -7973,7 +7964,7 @@ static void rtl_remove_one(struct pci_dev *pdev)
pm_runtime_get_noresume(&pdev->dev);
/* restore original MAC address */
- rtl_rar_set(tp, dev->perm_addr);
+ rtl_rar_set(tp, tp->dev->perm_addr);
}
static const struct net_device_ops rtl_netdev_ops = {
@@ -8361,7 +8352,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
if (rc < 0)
return rc;
- pci_set_drvdata(pdev, dev);
+ pci_set_drvdata(pdev, tp);
netif_info(tp, probe, dev, "%s at 0x%p, %pM, XID %08x IRQ %d\n",
rtl_chip_infos[chipset].name, tp->mmio_addr, dev->dev_addr,
--
2.16.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next 6/6] r8169: change argument type of rtl8169_net_suspend and __rtl8169_resume
2018-03-24 22:11 [PATCH net-next 0/6] r8169: patch set with further smaller improvements Heiner Kallweit
` (4 preceding siblings ...)
2018-03-24 22:18 ` [PATCH net-next 5/6] r8169: change type of driver_data Heiner Kallweit
@ 2018-03-24 22:18 ` Heiner Kallweit
5 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2018-03-24 22:18 UTC (permalink / raw)
To: Realtek linux nic maintainers, David Miller; +Cc: netdev@vger.kernel.org
Both functions can be simplified by changing the argument type to
struct rtl8169_private *.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/ethernet/realtek/r8169.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index dd84cc3a..58d84e48 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -7776,15 +7776,13 @@ rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
pm_runtime_put_noidle(&pdev->dev);
}
-static void rtl8169_net_suspend(struct net_device *dev)
+static void rtl8169_net_suspend(struct rtl8169_private *tp)
{
- struct rtl8169_private *tp = netdev_priv(dev);
-
- if (!netif_running(dev))
+ if (!netif_running(tp->dev))
return;
- netif_device_detach(dev);
- netif_stop_queue(dev);
+ netif_device_detach(tp->dev);
+ netif_stop_queue(tp->dev);
rtl_lock_work(tp);
napi_disable(&tp->napi);
@@ -7800,16 +7798,14 @@ static int rtl8169_suspend(struct device *device)
{
struct rtl8169_private *tp = dev_get_drvdata(device);
- rtl8169_net_suspend(tp->dev);
+ rtl8169_net_suspend(tp);
return 0;
}
-static void __rtl8169_resume(struct net_device *dev)
+static void __rtl8169_resume(struct rtl8169_private *tp)
{
- struct rtl8169_private *tp = netdev_priv(dev);
-
- netif_device_attach(dev);
+ netif_device_attach(tp->dev);
rtl_pll_power_up(tp);
@@ -7828,7 +7824,7 @@ static int rtl8169_resume(struct device *device)
rtl8169_init_phy(tp);
if (netif_running(tp->dev))
- __rtl8169_resume(tp->dev);
+ __rtl8169_resume(tp);
return 0;
}
@@ -7847,7 +7843,7 @@ static int rtl8169_runtime_suspend(struct device *device)
__rtl8169_set_wol(tp, WAKE_ANY);
rtl_unlock_work(tp);
- rtl8169_net_suspend(tp->dev);
+ rtl8169_net_suspend(tp);
/* Update counters before going runtime suspend */
rtl8169_rx_missed(tp->dev);
@@ -7872,7 +7868,7 @@ static int rtl8169_runtime_resume(struct device *device)
rtl8169_init_phy(tp);
- __rtl8169_resume(tp->dev);
+ __rtl8169_resume(tp);
return 0;
}
@@ -7929,7 +7925,7 @@ static void rtl_shutdown(struct pci_dev *pdev)
{
struct rtl8169_private *tp = pci_get_drvdata(pdev);
- rtl8169_net_suspend(tp->dev);
+ rtl8169_net_suspend(tp);
/* Restore original MAC address */
rtl_rar_set(tp, tp->dev->perm_addr);
--
2.16.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 5/6] r8169: change type of driver_data
2018-03-24 22:18 ` [PATCH net-next 5/6] r8169: change type of driver_data Heiner Kallweit
@ 2018-03-25 20:43 ` David Miller
2018-03-25 21:29 ` Heiner Kallweit
0 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2018-03-25 20:43 UTC (permalink / raw)
To: hkallweit1; +Cc: nic_swsd, netdev
From: Heiner Kallweit <hkallweit1@gmail.com>
Date: Sat, 24 Mar 2018 23:18:25 +0100
> Several functions accessing the device driver_data field don't need the
> net_device. All needed parameters can be accessed via struct
> rtl8169_private, therefore change type of driver_data accordingly.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
This doesn't work.
The pci_set_drvdata() call happens after register_netdevice().
At the exact moment register_netdevice() is called, any part of the
driver can be invoked before it returns.
Therefore this change will result in crashes because the drvdata won't
be initialized early enough.
I really think you're taking things too far with the cleanups of this
driver. It is a reasonably old driver used by a lot of people, and I
think avoiding regressions is 1000 times more important than
"streamlining" control plane functions that have not effect whatsoever
on real driver performance.
Thank you.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next 5/6] r8169: change type of driver_data
2018-03-25 20:43 ` David Miller
@ 2018-03-25 21:29 ` Heiner Kallweit
0 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2018-03-25 21:29 UTC (permalink / raw)
To: David Miller; +Cc: nic_swsd, netdev
Am 25.03.2018 um 22:43 schrieb David Miller:
> From: Heiner Kallweit <hkallweit1@gmail.com>
> Date: Sat, 24 Mar 2018 23:18:25 +0100
>
>> Several functions accessing the device driver_data field don't need the
>> net_device. All needed parameters can be accessed via struct
>> rtl8169_private, therefore change type of driver_data accordingly.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>
> This doesn't work.
>
> The pci_set_drvdata() call happens after register_netdevice().
>
> At the exact moment register_netdevice() is called, any part of the
> driver can be invoked before it returns.
>
> Therefore this change will result in crashes because the drvdata won't
> be initialized early enough.
>
Thanks for catching this. The patch however just changes the parameter
of pci_set_drvdata, not the position of this call.
This means the potential crash scenario we have already w/o the patch
and it's a long-standing bug.
Having said that I'd submit a fix for this bug first and then a
rebased version of the cleanup patch set (if fine with you).
> I really think you're taking things too far with the cleanups of this
> driver. It is a reasonably old driver used by a lot of people, and I
> think avoiding regressions is 1000 times more important than
> "streamlining" control plane functions that have not effect whatsoever
> on real driver performance.
>
> Thank you.
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-03-25 21:29 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-24 22:11 [PATCH net-next 0/6] r8169: patch set with further smaller improvements Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 1/6] r8169: change argument type of callback hw_start in struct rtl8169_private Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 2/6] r8169: change argument type of counter functions Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 3/6] r8169: change argument type of PHY-related functions Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 4/6] r8169: change argument type of interrupt handler Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 5/6] r8169: change type of driver_data Heiner Kallweit
2018-03-25 20:43 ` David Miller
2018-03-25 21:29 ` Heiner Kallweit
2018-03-24 22:18 ` [PATCH net-next 6/6] r8169: change argument type of rtl8169_net_suspend and __rtl8169_resume Heiner Kallweit
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).