* [PATCH 07/17] e1000e: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
[not found] <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com>
@ 2023-05-11 13:14 ` Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 08/17] net/mlx5: " Ilpo Järvinen
` (7 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2023-05-11 13:14 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczyński, Lukas Wunner, Jesse Brandeburg,
Tony Nguyen, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, intel-wired-lan, netdev, linux-kernel
Cc: Ilpo Järvinen
Don't assume that only the driver would be accessing LNKCTL. ASPM
policy changes can trigger write to LNKCTL outside of driver's control.
And in the case of upstream (parent), the driver does not even own the
device it's changing LNKCTL for.
Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
losing concurrent updates to the register value.
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/ethernet/intel/e1000e/netdev.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c
index bd7ef59b1f2e..29d50aeb2c3e 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -6829,11 +6829,9 @@ static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state, int locked)
/* Both device and parent should have the same ASPM setting.
* Disable ASPM in downstream component first and then upstream.
*/
- pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
-
+ pcie_lnkctl_clear_and_set(pdev, aspm_dis_mask, 0);
if (parent)
- pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
- aspm_dis_mask);
+ pcie_lnkctl_clear_and_set(parent, aspm_dis_mask, 0);
}
/**
--
2.30.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH 08/17] net/mlx5: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
[not found] <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com>
2023-05-11 13:14 ` [PATCH 07/17] e1000e: Use pcie_lnkctl_clear_and_set() for changing LNKCTL Ilpo Järvinen
@ 2023-05-11 13:14 ` Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 09/17] wifi: ath9k: " Ilpo Järvinen
` (6 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2023-05-11 13:14 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczyński, Lukas Wunner, Saeed Mahameed,
Leon Romanovsky, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-rdma, linux-kernel
Cc: Ilpo Järvinen
Don't assume that only the driver would be accessing LNKCTL of the
upstream (bridge). ASPM policy changes can trigger write to LNKCTL
outside of driver's control.
Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
losing concurrent updates to the register value.
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c b/drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c
index 50022e7565f1..2c3d69f3a107 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c
@@ -332,16 +332,11 @@ static int mlx5_pci_link_toggle(struct mlx5_core_dev *dev)
pci_cfg_access_lock(sdev);
}
/* PCI link toggle */
- err = pci_read_config_word(bridge, cap + PCI_EXP_LNKCTL, ®16);
- if (err)
- return err;
- reg16 |= PCI_EXP_LNKCTL_LD;
- err = pci_write_config_word(bridge, cap + PCI_EXP_LNKCTL, reg16);
+ err = pcie_lnkctl_clear_and_set(bridge, 0, PCI_EXP_LNKCTL_LD);
if (err)
return err;
msleep(500);
- reg16 &= ~PCI_EXP_LNKCTL_LD;
- err = pci_write_config_word(bridge, cap + PCI_EXP_LNKCTL, reg16);
+ err = pcie_lnkctl_clear_and_set(bridge, PCI_EXP_LNKCTL_LD, 0);
if (err)
return err;
--
2.30.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH 09/17] wifi: ath9k: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
[not found] <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com>
2023-05-11 13:14 ` [PATCH 07/17] e1000e: Use pcie_lnkctl_clear_and_set() for changing LNKCTL Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 08/17] net/mlx5: " Ilpo Järvinen
@ 2023-05-11 13:14 ` Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 10/17] mt76: " Ilpo Järvinen
` (5 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2023-05-11 13:14 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczyński, Lukas Wunner,
Toke Høiland-Jørgensen, Kalle Valo, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-wireless, netdev,
linux-kernel
Cc: Ilpo Järvinen
Don't assume that only the driver would be accessing LNKCTL. ASPM
policy changes can trigger write to LNKCTL outside of driver's control.
And in the case of upstream (parent), the driver does not even own the
device it's changing LNKCTL for.
Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
losing concurrent updates to the register value.
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/wireless/ath/ath9k/pci.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index a09f9d223f3d..c2130fe6c9e6 100644
--- a/drivers/net/wireless/ath/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
@@ -837,15 +837,16 @@ static void ath_pci_aspm_init(struct ath_common *common)
if ((ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_NONE) &&
(AR_SREV_9285(ah))) {
/* Bluetooth coexistence requires disabling ASPM. */
- pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL,
- PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1);
+ pcie_lnkctl_clear_and_set(pdev, PCI_EXP_LNKCTL_ASPM_L0S |
+ PCI_EXP_LNKCTL_ASPM_L1, 0);
/*
* Both upstream and downstream PCIe components should
* have the same ASPM settings.
*/
- pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
- PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1);
+ pcie_lnkctl_clear_and_set(parent,
+ PCI_EXP_LNKCTL_ASPM_L0S |
+ PCI_EXP_LNKCTL_ASPM_L1, 0);
ath_info(common, "Disabling ASPM since BTCOEX is enabled\n");
return;
--
2.30.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH 10/17] mt76: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
[not found] <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com>
` (2 preceding siblings ...)
2023-05-11 13:14 ` [PATCH 09/17] wifi: ath9k: " Ilpo Järvinen
@ 2023-05-11 13:14 ` Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 13/17] net/tg3: " Ilpo Järvinen
` (4 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2023-05-11 13:14 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczyński, Lukas Wunner, Felix Fietkau,
Lorenzo Bianconi, Ryder Lee, Shayne Chen, Sean Wang, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Matthias Brugger, AngeloGioacchino Del Regno, linux-wireless,
netdev, linux-kernel, linux-arm-kernel, linux-mediatek
Cc: Ilpo Järvinen
Don't assume that only the driver would be accessing LNKCTL. ASPM
policy changes can trigger write to LNKCTL outside of driver's control.
And in the case of upstream (parent), the driver does not even own the
device it's changing LNKCTL for.
Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
losing concurrent updates to the register value.
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/wireless/mediatek/mt76/pci.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/pci.c b/drivers/net/wireless/mediatek/mt76/pci.c
index 4c1c159fbb62..8c6444f5fac3 100644
--- a/drivers/net/wireless/mediatek/mt76/pci.c
+++ b/drivers/net/wireless/mediatek/mt76/pci.c
@@ -39,9 +39,8 @@ void mt76_pci_disable_aspm(struct pci_dev *pdev)
/* both device and parent should have the same ASPM setting.
* disable ASPM in downstream component first and then upstream.
*/
- pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_conf);
+ pcie_lnkctl_clear_and_set(pdev, aspm_conf, 0);
if (parent)
- pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
- aspm_conf);
+ pcie_lnkctl_clear_and_set(parent, aspm_conf, 0);
}
EXPORT_SYMBOL_GPL(mt76_pci_disable_aspm);
--
2.30.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH 13/17] net/tg3: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
[not found] <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com>
` (3 preceding siblings ...)
2023-05-11 13:14 ` [PATCH 10/17] mt76: " Ilpo Järvinen
@ 2023-05-11 13:14 ` Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 14/17] r8169: " Ilpo Järvinen
` (3 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2023-05-11 13:14 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczyński, Lukas Wunner, Siva Reddy Kallam,
Prashant Sreedharan, Michael Chan, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
Cc: Ilpo Järvinen
Don't assume that only the driver would be accessing LNKCTL. ASPM
policy changes can trigger write to LNKCTL outside of driver's control.
Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
losing concurrent updates to the register value.
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/ethernet/broadcom/tg3.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 58747292521d..f3b30e7af25d 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -4027,8 +4027,7 @@ static int tg3_power_down_prepare(struct tg3 *tp)
/* Restore the CLKREQ setting. */
if (tg3_flag(tp, CLKREQ_BUG))
- pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL,
- PCI_EXP_LNKCTL_CLKREQ_EN);
+ pcie_lnkctl_clear_and_set(tp->pdev, 0, PCI_EXP_LNKCTL_CLKREQ_EN);
misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL);
tw32(TG3PCI_MISC_HOST_CTRL,
@@ -5069,13 +5068,14 @@ static int tg3_setup_copper_phy(struct tg3 *tp, bool force_reset)
/* Prevent send BD corruption. */
if (tg3_flag(tp, CLKREQ_BUG)) {
+ u16 clkreq = 0;
+
if (tp->link_config.active_speed == SPEED_100 ||
tp->link_config.active_speed == SPEED_10)
- pcie_capability_clear_word(tp->pdev, PCI_EXP_LNKCTL,
- PCI_EXP_LNKCTL_CLKREQ_EN);
- else
- pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL,
- PCI_EXP_LNKCTL_CLKREQ_EN);
+ clkreq = PCI_EXP_LNKCTL_CLKREQ_EN;
+
+ pcie_lnkctl_clear_and_set(tp->pdev, PCI_EXP_LNKCTL_CLKREQ_EN,
+ clkreq);
}
tg3_test_and_report_link_chg(tp, current_link_up);
--
2.30.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH 14/17] r8169: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
[not found] <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com>
` (4 preceding siblings ...)
2023-05-11 13:14 ` [PATCH 13/17] net/tg3: " Ilpo Järvinen
@ 2023-05-11 13:14 ` Ilpo Järvinen
2023-05-11 19:49 ` Heiner Kallweit
2023-05-11 13:14 ` [PATCH 15/17] wifi: ath11k: " Ilpo Järvinen
` (2 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Ilpo Järvinen @ 2023-05-11 13:14 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczyński, Lukas Wunner, Heiner Kallweit,
nic_swsd, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
Cc: Ilpo Järvinen
Don't assume that only the driver would be accessing LNKCTL. ASPM
policy changes can trigger write to LNKCTL outside of driver's control.
Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
losing concurrent updates to the register value.
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/ethernet/realtek/r8169_main.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index a7e376e7e689..c0294a833681 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -2686,14 +2686,12 @@ static void __rtl_ephy_init(struct rtl8169_private *tp,
static void rtl_disable_clock_request(struct rtl8169_private *tp)
{
- pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL,
- PCI_EXP_LNKCTL_CLKREQ_EN);
+ pcie_lnkctl_clear_and_set(tp->pci_dev, PCI_EXP_LNKCTL_CLKREQ_EN, 0);
}
static void rtl_enable_clock_request(struct rtl8169_private *tp)
{
- pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL,
- PCI_EXP_LNKCTL_CLKREQ_EN);
+ pcie_lnkctl_clear_and_set(tp->pci_dev, 0, PCI_EXP_LNKCTL_CLKREQ_EN);
}
static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp)
--
2.30.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH 14/17] r8169: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
2023-05-11 13:14 ` [PATCH 14/17] r8169: " Ilpo Järvinen
@ 2023-05-11 19:49 ` Heiner Kallweit
2023-05-11 20:00 ` Ilpo Järvinen
2023-05-11 20:02 ` Lukas Wunner
0 siblings, 2 replies; 15+ messages in thread
From: Heiner Kallweit @ 2023-05-11 19:49 UTC (permalink / raw)
To: Ilpo Järvinen, linux-pci, Bjorn Helgaas, Rob Herring,
Lorenzo Pieralisi, Krzysztof Wilczyński, Lukas Wunner,
nic_swsd, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev, linux-kernel
On 11.05.2023 15:14, Ilpo Järvinen wrote:
> Don't assume that only the driver would be accessing LNKCTL. ASPM
> policy changes can trigger write to LNKCTL outside of driver's control.
>
> Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
> losing concurrent updates to the register value.
>
Wouldn't it be more appropriate to add proper locking to the
underlying pcie_capability_clear_and_set_word()?
> Suggested-by: Lukas Wunner <lukas@wunner.de>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
> drivers/net/ethernet/realtek/r8169_main.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index a7e376e7e689..c0294a833681 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -2686,14 +2686,12 @@ static void __rtl_ephy_init(struct rtl8169_private *tp,
>
> static void rtl_disable_clock_request(struct rtl8169_private *tp)
> {
> - pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL,
> - PCI_EXP_LNKCTL_CLKREQ_EN);
> + pcie_lnkctl_clear_and_set(tp->pci_dev, PCI_EXP_LNKCTL_CLKREQ_EN, 0);
> }
>
> static void rtl_enable_clock_request(struct rtl8169_private *tp)
> {
> - pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL,
> - PCI_EXP_LNKCTL_CLKREQ_EN);
> + pcie_lnkctl_clear_and_set(tp->pci_dev, 0, PCI_EXP_LNKCTL_CLKREQ_EN);
> }
>
> static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp)
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH 14/17] r8169: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
2023-05-11 19:49 ` Heiner Kallweit
@ 2023-05-11 20:00 ` Ilpo Järvinen
2023-05-11 20:10 ` Lukas Wunner
2023-05-11 20:02 ` Lukas Wunner
1 sibling, 1 reply; 15+ messages in thread
From: Ilpo Järvinen @ 2023-05-11 20:00 UTC (permalink / raw)
To: Heiner Kallweit
Cc: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczyński, Lukas Wunner, nic_swsd,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Netdev, LKML
[-- Attachment #1: Type: text/plain, Size: 586 bytes --]
On Thu, 11 May 2023, Heiner Kallweit wrote:
> On 11.05.2023 15:14, Ilpo Järvinen wrote:
> > Don't assume that only the driver would be accessing LNKCTL. ASPM
> > policy changes can trigger write to LNKCTL outside of driver's control.
> >
> > Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
> > losing concurrent updates to the register value.
> >
>
> Wouldn't it be more appropriate to add proper locking to the
> underlying pcie_capability_clear_and_set_word()?
As per discussion for the other patch, that's where this series is now
aiming to in v2.
--
i.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 14/17] r8169: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
2023-05-11 20:00 ` Ilpo Järvinen
@ 2023-05-11 20:10 ` Lukas Wunner
2023-05-11 20:11 ` Heiner Kallweit
0 siblings, 1 reply; 15+ messages in thread
From: Lukas Wunner @ 2023-05-11 20:10 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Heiner Kallweit, linux-pci, Bjorn Helgaas, Rob Herring,
Lorenzo Pieralisi, Krzysztof Wilczy?ski, nic_swsd,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Netdev, LKML
On Thu, May 11, 2023 at 11:00:02PM +0300, Ilpo Järvinen wrote:
> On Thu, 11 May 2023, Heiner Kallweit wrote:
> > On 11.05.2023 15:14, Ilpo Järvinen wrote:
> > > Don't assume that only the driver would be accessing LNKCTL. ASPM
> > > policy changes can trigger write to LNKCTL outside of driver's control.
> > >
> > > Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
> > > losing concurrent updates to the register value.
> > >
> >
> > Wouldn't it be more appropriate to add proper locking to the
> > underlying pcie_capability_clear_and_set_word()?
>
> As per discussion for the other patch, that's where this series is now
> aiming to in v2.
That discussion wasn't cc'ed to Heiner. For reference, this is the
message Ilpo is referring to:
https://lore.kernel.org/linux-pci/ZF1AjOKDVlbNFJPK@bhelgaas/
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 14/17] r8169: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
2023-05-11 20:10 ` Lukas Wunner
@ 2023-05-11 20:11 ` Heiner Kallweit
0 siblings, 0 replies; 15+ messages in thread
From: Heiner Kallweit @ 2023-05-11 20:11 UTC (permalink / raw)
To: Lukas Wunner, Ilpo Järvinen
Cc: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczy?ski, nic_swsd, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Netdev, LKML
On 11.05.2023 22:10, Lukas Wunner wrote:
> On Thu, May 11, 2023 at 11:00:02PM +0300, Ilpo Järvinen wrote:
>> On Thu, 11 May 2023, Heiner Kallweit wrote:
>>> On 11.05.2023 15:14, Ilpo Järvinen wrote:
>>>> Don't assume that only the driver would be accessing LNKCTL. ASPM
>>>> policy changes can trigger write to LNKCTL outside of driver's control.
>>>>
>>>> Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
>>>> losing concurrent updates to the register value.
>>>>
>>>
>>> Wouldn't it be more appropriate to add proper locking to the
>>> underlying pcie_capability_clear_and_set_word()?
>>
>> As per discussion for the other patch, that's where this series is now
>> aiming to in v2.
>
> That discussion wasn't cc'ed to Heiner. For reference, this is the
> message Ilpo is referring to:
>
> https://lore.kernel.org/linux-pci/ZF1AjOKDVlbNFJPK@bhelgaas/
Thanks for the link!
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 14/17] r8169: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
2023-05-11 19:49 ` Heiner Kallweit
2023-05-11 20:00 ` Ilpo Järvinen
@ 2023-05-11 20:02 ` Lukas Wunner
2023-05-11 20:17 ` Heiner Kallweit
1 sibling, 1 reply; 15+ messages in thread
From: Lukas Wunner @ 2023-05-11 20:02 UTC (permalink / raw)
To: Heiner Kallweit
Cc: Ilpo Järvinen, linux-pci, Bjorn Helgaas, Rob Herring,
Lorenzo Pieralisi, Krzysztof Wilczy??ski, nic_swsd,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
On Thu, May 11, 2023 at 09:49:52PM +0200, Heiner Kallweit wrote:
> On 11.05.2023 15:14, Ilpo Järvinen wrote:
> > Don't assume that only the driver would be accessing LNKCTL. ASPM
> > policy changes can trigger write to LNKCTL outside of driver's control.
> >
> > Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
> > losing concurrent updates to the register value.
>
> Wouldn't it be more appropriate to add proper locking to the
> underlying pcie_capability_clear_and_set_word()?
PCI config space accessors such as this one are also used in hot paths
(e.g. interrupt handlers). They should be kept lean (and lockless)
by default. We only need locking for specific PCIe Extended Capabilities
which are concurrently accessed by PCI core code and drivers.
Thanks,
Lukas
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 14/17] r8169: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
2023-05-11 20:02 ` Lukas Wunner
@ 2023-05-11 20:17 ` Heiner Kallweit
0 siblings, 0 replies; 15+ messages in thread
From: Heiner Kallweit @ 2023-05-11 20:17 UTC (permalink / raw)
To: Lukas Wunner
Cc: Ilpo Järvinen, linux-pci, Bjorn Helgaas, Rob Herring,
Lorenzo Pieralisi, Krzysztof Wilczy??ski, nic_swsd,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
On 11.05.2023 22:02, Lukas Wunner wrote:
> On Thu, May 11, 2023 at 09:49:52PM +0200, Heiner Kallweit wrote:
>> On 11.05.2023 15:14, Ilpo Järvinen wrote:
>>> Don't assume that only the driver would be accessing LNKCTL. ASPM
>>> policy changes can trigger write to LNKCTL outside of driver's control.
>>>
>>> Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
>>> losing concurrent updates to the register value.
>>
>> Wouldn't it be more appropriate to add proper locking to the
>> underlying pcie_capability_clear_and_set_word()?
>
> PCI config space accessors such as this one are also used in hot paths
> (e.g. interrupt handlers). They should be kept lean (and lockless)
I *think* in case the system uses threaded interrupts you may need locking
also in interrupt handlers.
> by default. We only need locking for specific PCIe Extended Capabilities
> which are concurrently accessed by PCI core code and drivers.
>
> Thanks,
>
> Lukas
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 15/17] wifi: ath11k: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
[not found] <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com>
` (5 preceding siblings ...)
2023-05-11 13:14 ` [PATCH 14/17] r8169: " Ilpo Järvinen
@ 2023-05-11 13:14 ` Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 16/17] wifi: ath12k: " Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 17/17] wifi: ath10k: " Ilpo Järvinen
8 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2023-05-11 13:14 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczyński, Lukas Wunner, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
ath11k, linux-wireless, netdev, linux-kernel
Cc: Ilpo Järvinen
Don't assume that only the driver would be accessing LNKCTL. ASPM
policy changes can trigger write to LNKCTL outside of driver's control.
Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
losing concurrent updates to the register value.
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/wireless/ath/ath11k/pci.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/ath/ath11k/pci.c b/drivers/net/wireless/ath/ath11k/pci.c
index 7b33731a50ee..d0885d30dcbc 100644
--- a/drivers/net/wireless/ath/ath11k/pci.c
+++ b/drivers/net/wireless/ath/ath11k/pci.c
@@ -581,8 +581,8 @@ static void ath11k_pci_aspm_disable(struct ath11k_pci *ab_pci)
u16_get_bits(ab_pci->link_ctl, PCI_EXP_LNKCTL_ASPM_L1));
/* disable L0s and L1 */
- pcie_capability_write_word(ab_pci->pdev, PCI_EXP_LNKCTL,
- ab_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC);
+ pcie_lnkctl_clear_and_set(ab_pci->pdev,
+ ab_pci->link_ctl & PCI_EXP_LNKCTL_ASPMC, 0);
set_bit(ATH11K_PCI_ASPM_RESTORE, &ab_pci->flags);
}
@@ -590,8 +590,8 @@ static void ath11k_pci_aspm_disable(struct ath11k_pci *ab_pci)
static void ath11k_pci_aspm_restore(struct ath11k_pci *ab_pci)
{
if (test_and_clear_bit(ATH11K_PCI_ASPM_RESTORE, &ab_pci->flags))
- pcie_capability_write_word(ab_pci->pdev, PCI_EXP_LNKCTL,
- ab_pci->link_ctl);
+ pcie_lnkctl_clear_and_set(ab_pci->pdev, 0,
+ ab_pci->link_ctl & PCI_EXP_LNKCTL_ASPMC);
}
static int ath11k_pci_power_up(struct ath11k_base *ab)
--
2.30.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH 16/17] wifi: ath12k: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
[not found] <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com>
` (6 preceding siblings ...)
2023-05-11 13:14 ` [PATCH 15/17] wifi: ath11k: " Ilpo Järvinen
@ 2023-05-11 13:14 ` Ilpo Järvinen
2023-05-11 13:14 ` [PATCH 17/17] wifi: ath10k: " Ilpo Järvinen
8 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2023-05-11 13:14 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczyński, Lukas Wunner, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
ath12k, linux-wireless, netdev, linux-kernel
Cc: Ilpo Järvinen
Don't assume that only the driver would be accessing LNKCTL. ASPM
policy changes can trigger write to LNKCTL outside of driver's control.
Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
losing concurrent updates to the register value.
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/wireless/ath/ath12k/pci.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/ath/ath12k/pci.c b/drivers/net/wireless/ath/ath12k/pci.c
index 9f174daf324c..fa88a0b88520 100644
--- a/drivers/net/wireless/ath/ath12k/pci.c
+++ b/drivers/net/wireless/ath/ath12k/pci.c
@@ -794,8 +794,8 @@ static void ath12k_pci_aspm_disable(struct ath12k_pci *ab_pci)
u16_get_bits(ab_pci->link_ctl, PCI_EXP_LNKCTL_ASPM_L1));
/* disable L0s and L1 */
- pcie_capability_write_word(ab_pci->pdev, PCI_EXP_LNKCTL,
- ab_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC);
+ pcie_lnkctl_clear_and_set(ab_pci->pdev,
+ ab_pci->link_ctl & PCI_EXP_LNKCTL_ASPMC, 0);
set_bit(ATH12K_PCI_ASPM_RESTORE, &ab_pci->flags);
}
@@ -803,8 +803,8 @@ static void ath12k_pci_aspm_disable(struct ath12k_pci *ab_pci)
static void ath12k_pci_aspm_restore(struct ath12k_pci *ab_pci)
{
if (test_and_clear_bit(ATH12K_PCI_ASPM_RESTORE, &ab_pci->flags))
- pcie_capability_write_word(ab_pci->pdev, PCI_EXP_LNKCTL,
- ab_pci->link_ctl);
+ pcie_lnkctl_clear_and_set(ab_pci->pdev, 0,
+ ab_pci->link_ctl & PCI_EXP_LNKCTL_ASPMC);
}
static void ath12k_pci_kill_tasklets(struct ath12k_base *ab)
--
2.30.2
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH 17/17] wifi: ath10k: Use pcie_lnkctl_clear_and_set() for changing LNKCTL
[not found] <20230511131441.45704-1-ilpo.jarvinen@linux.intel.com>
` (7 preceding siblings ...)
2023-05-11 13:14 ` [PATCH 16/17] wifi: ath12k: " Ilpo Järvinen
@ 2023-05-11 13:14 ` Ilpo Järvinen
8 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2023-05-11 13:14 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
Krzysztof Wilczyński, Lukas Wunner, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
ath10k, linux-wireless, netdev, linux-kernel
Cc: Ilpo Järvinen
Don't assume that only the driver would be accessing LNKCTL. ASPM
policy changes can trigger write to LNKCTL outside of driver's control.
Use pcie_lnkctl_clear_and_set() which does proper locking to avoid
losing concurrent updates to the register value. Convert one of the
writes to only touch PCI_EXP_LNKCTL_ASPMC field which the driver itself
has been changing, leave the other fields untouched.
Suggested-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/net/wireless/ath/ath10k/pci.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c
index a7f44f6335fb..d18dfb495194 100644
--- a/drivers/net/wireless/ath/ath10k/pci.c
+++ b/drivers/net/wireless/ath/ath10k/pci.c
@@ -1963,8 +1963,8 @@ static int ath10k_pci_hif_start(struct ath10k *ar)
ath10k_pci_irq_enable(ar);
ath10k_pci_rx_post(ar);
- pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
- ar_pci->link_ctl);
+ pcie_lnkctl_clear_and_set(ar_pci->pdev, 0,
+ ar_pci->link_ctl & PCI_EXP_LNKCTL_ASPMC);
return 0;
}
@@ -2821,8 +2821,8 @@ static int ath10k_pci_hif_power_up(struct ath10k *ar,
pcie_capability_read_word(ar_pci->pdev, PCI_EXP_LNKCTL,
&ar_pci->link_ctl);
- pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
- ar_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC);
+ pcie_lnkctl_clear_and_set(ar_pci->pdev,
+ ar_pci->link_ctl & PCI_EXP_LNKCTL_ASPMC, 0);
/*
* Bring the target up cleanly.
--
2.30.2
^ permalink raw reply related [flat|nested] 15+ messages in thread