Add WAIT_PDS_TIMEOUT_MS and POLL_CMD_TIMEOUT_MS macros for hotplug
operation delays to improve code readability.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/pci/hotplug/pciehp_hpc.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index bcc51b26d03d..15b09c6a8d6b 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -28,6 +28,9 @@
#include "../pci.h"
#include "pciehp.h"
+#define WAIT_PDS_TIMEOUT_MS 10
+#define POLL_CMD_TIMEOUT_MS 10
+
static const struct dmi_system_id inband_presence_disabled_dmi_table[] = {
/*
* Match all Dell systems, as some Dell systems have inband
@@ -103,7 +106,7 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout)
smp_mb();
return 1;
}
- msleep(10);
+ msleep(POLL_CMD_TIMEOUT_MS);
timeout -= 10;
} while (timeout >= 0);
return 0; /* timeout */
@@ -283,7 +286,7 @@ static void pcie_wait_for_presence(struct pci_dev *pdev)
pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
if (slot_status & PCI_EXP_SLTSTA_PDS)
return;
- msleep(10);
+ msleep(WAIT_PDS_TIMEOUT_MS);
timeout -= 10;
} while (timeout > 0);
}
--
2.34.1
[+cc Lukas]
On Sun, Nov 02, 2025 at 12:05:37AM +0800, Hans Zhang wrote:
> Add WAIT_PDS_TIMEOUT_MS and POLL_CMD_TIMEOUT_MS macros for hotplug
> operation delays to improve code readability.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
> drivers/pci/hotplug/pciehp_hpc.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
> index bcc51b26d03d..15b09c6a8d6b 100644
> --- a/drivers/pci/hotplug/pciehp_hpc.c
> +++ b/drivers/pci/hotplug/pciehp_hpc.c
> @@ -28,6 +28,9 @@
> #include "../pci.h"
> #include "pciehp.h"
>
> +#define WAIT_PDS_TIMEOUT_MS 10
> +#define POLL_CMD_TIMEOUT_MS 10
> +
> static const struct dmi_system_id inband_presence_disabled_dmi_table[] = {
> /*
> * Match all Dell systems, as some Dell systems have inband
> @@ -103,7 +106,7 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout)
> smp_mb();
> return 1;
> }
> - msleep(10);
> + msleep(POLL_CMD_TIMEOUT_MS);
Lukas might have different opinions and I would defer to him here.
But IMO (a) these aren't timeouts, they are poll intervals, (b) the
values are arbitrary with no connection to a spec, so less reason for
a #define, and (c) the #defines don't improve readability because now
I have to look at two places to understand the poll loops.
> timeout -= 10;
> } while (timeout >= 0);
> return 0; /* timeout */
> @@ -283,7 +286,7 @@ static void pcie_wait_for_presence(struct pci_dev *pdev)
> pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
> if (slot_status & PCI_EXP_SLTSTA_PDS)
> return;
> - msleep(10);
> + msleep(WAIT_PDS_TIMEOUT_MS);
> timeout -= 10;
> } while (timeout > 0);
> }
> --
> 2.34.1
>
On Mon, Nov 03, 2025 at 09:37:34AM -0600, Bjorn Helgaas wrote:
> On Sun, Nov 02, 2025 at 12:05:37AM +0800, Hans Zhang wrote:
> > Add WAIT_PDS_TIMEOUT_MS and POLL_CMD_TIMEOUT_MS macros for hotplug
> > operation delays to improve code readability.
[...]
> > +++ b/drivers/pci/hotplug/pciehp_hpc.c
> > @@ -28,6 +28,9 @@
> > #include "../pci.h"
> > #include "pciehp.h"
> >
> > +#define WAIT_PDS_TIMEOUT_MS 10
> > +#define POLL_CMD_TIMEOUT_MS 10
> > +
> > static const struct dmi_system_id inband_presence_disabled_dmi_table[] = {
> > /*
> > * Match all Dell systems, as some Dell systems have inband
> > @@ -103,7 +106,7 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout)
> > smp_mb();
> > return 1;
> > }
> > - msleep(10);
> > + msleep(POLL_CMD_TIMEOUT_MS);
>
> Lukas might have different opinions and I would defer to him here.
>
> But IMO (a) these aren't timeouts, they are poll intervals, (b) the
> values are arbitrary with no connection to a spec, so less reason for
> a #define, and (c) the #defines don't improve readability because now
> I have to look at two places to understand the poll loops.
I agree on all counts.
Thanks,
Lukas
On 2025/11/4 01:24, Lukas Wunner wrote:
> On Mon, Nov 03, 2025 at 09:37:34AM -0600, Bjorn Helgaas wrote:
>> On Sun, Nov 02, 2025 at 12:05:37AM +0800, Hans Zhang wrote:
>>> Add WAIT_PDS_TIMEOUT_MS and POLL_CMD_TIMEOUT_MS macros for hotplug
>>> operation delays to improve code readability.
> [...]
>>> +++ b/drivers/pci/hotplug/pciehp_hpc.c
>>> @@ -28,6 +28,9 @@
>>> #include "../pci.h"
>>> #include "pciehp.h"
>>>
>>> +#define WAIT_PDS_TIMEOUT_MS 10
>>> +#define POLL_CMD_TIMEOUT_MS 10
>>> +
>>> static const struct dmi_system_id inband_presence_disabled_dmi_table[] = {
>>> /*
>>> * Match all Dell systems, as some Dell systems have inband
>>> @@ -103,7 +106,7 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout)
>>> smp_mb();
>>> return 1;
>>> }
>>> - msleep(10);
>>> + msleep(POLL_CMD_TIMEOUT_MS);
>>
>> Lukas might have different opinions and I would defer to him here.
>>
>> But IMO (a) these aren't timeouts, they are poll intervals, (b) the
>> values are arbitrary with no connection to a spec, so less reason for
>> a #define, and (c) the #defines don't improve readability because now
>> I have to look at two places to understand the poll loops.
>
> I agree on all counts.
>
Hi Bjorn,
Please drop this patch.
Best regards,
Hans
> Thanks,
>
> Lukas
Le 01/11/2025 à 17:05, Hans Zhang a écrit :
> Add WAIT_PDS_TIMEOUT_MS and POLL_CMD_TIMEOUT_MS macros for hotplug
> operation delays to improve code readability.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
> drivers/pci/hotplug/pciehp_hpc.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
> index bcc51b26d03d..15b09c6a8d6b 100644
> --- a/drivers/pci/hotplug/pciehp_hpc.c
> +++ b/drivers/pci/hotplug/pciehp_hpc.c
> @@ -28,6 +28,9 @@
> #include "../pci.h"
> #include "pciehp.h"
>
> +#define WAIT_PDS_TIMEOUT_MS 10
> +#define POLL_CMD_TIMEOUT_MS 10
> +
> static const struct dmi_system_id inband_presence_disabled_dmi_table[] = {
> /*
> * Match all Dell systems, as some Dell systems have inband
> @@ -103,7 +106,7 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout)
> smp_mb();
> return 1;
> }
> - msleep(10);
> + msleep(POLL_CMD_TIMEOUT_MS);
> timeout -= 10;
Should we have: timeout -= POLL_CMD_TIMEOUT_MS;
?
> } while (timeout >= 0);
> return 0; /* timeout */
> @@ -283,7 +286,7 @@ static void pcie_wait_for_presence(struct pci_dev *pdev)
> pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
> if (slot_status & PCI_EXP_SLTSTA_PDS)
> return;
> - msleep(10);
> + msleep(WAIT_PDS_TIMEOUT_MS);
Same with WAIT_PDS_TIMEOUT_MS.
CJ
> timeout -= 10;
> } while (timeout > 0);
> }
On 2025/11/2 00:13, Christophe JAILLET wrote:
> Le 01/11/2025 à 17:05, Hans Zhang a écrit :
>> Add WAIT_PDS_TIMEOUT_MS and POLL_CMD_TIMEOUT_MS macros for hotplug
>> operation delays to improve code readability.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
>> ---
>> drivers/pci/hotplug/pciehp_hpc.c | 7 +++++--
>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/
>> pciehp_hpc.c
>> index bcc51b26d03d..15b09c6a8d6b 100644
>> --- a/drivers/pci/hotplug/pciehp_hpc.c
>> +++ b/drivers/pci/hotplug/pciehp_hpc.c
>> @@ -28,6 +28,9 @@
>> #include "../pci.h"
>> #include "pciehp.h"
>> +#define WAIT_PDS_TIMEOUT_MS 10
>> +#define POLL_CMD_TIMEOUT_MS 10
>> +
>> static const struct dmi_system_id
>> inband_presence_disabled_dmi_table[] = {
>> /*
>> * Match all Dell systems, as some Dell systems have inband
>> @@ -103,7 +106,7 @@ static int pcie_poll_cmd(struct controller *ctrl,
>> int timeout)
>> smp_mb();
>> return 1;
>> }
>> - msleep(10);
>> + msleep(POLL_CMD_TIMEOUT_MS);
>> timeout -= 10;
>
> Should we have: timeout -= POLL_CMD_TIMEOUT_MS;
>
> ?
Hi Christophe,
Thank you very much for your reply and reminder.
If Bjorn finds it meaningful, I will fix it in the next version.
>
>> } while (timeout >= 0);
>> return 0; /* timeout */
>> @@ -283,7 +286,7 @@ static void pcie_wait_for_presence(struct pci_dev
>> *pdev)
>> pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
>> if (slot_status & PCI_EXP_SLTSTA_PDS)
>> return;
>> - msleep(10);
>> + msleep(WAIT_PDS_TIMEOUT_MS);
>
> Same with WAIT_PDS_TIMEOUT_MS.
>
Will change.
Best regards,
Hans
> CJ
>
>> timeout -= 10;
>> } while (timeout > 0);
>> }
© 2016 - 2026 Red Hat, Inc.