]> git.itanic.dy.fi Git - linux-stable/commitdiff
PCI: hotplug: Use FIELD_GET/PREP()
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Wed, 18 Oct 2023 11:32:50 +0000 (14:32 +0300)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 24 Oct 2023 15:54:04 +0000 (10:54 -0500)
Instead of handcrafted shifts to handle register fields, use
FIELD_GET/FIELD_PREP().

Link: https://lore.kernel.org/r/20231018113254.17616-4-ilpo.jarvinen@linux.intel.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/hotplug/pciehp_core.c
drivers/pci/hotplug/pciehp_hpc.c
drivers/pci/hotplug/pnv_php.c

index 4042d87d539dd485c3c03c55a0079f5d6ba740b1..ddd55ad97a58983ec11d9996e30d92bcdefdd6e0 100644 (file)
@@ -20,6 +20,7 @@
 #define pr_fmt(fmt) "pciehp: " fmt
 #define dev_fmt pr_fmt
 
+#include <linux/bitfield.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
@@ -103,7 +104,7 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
        struct pci_dev *pdev = ctrl->pcie->port;
 
        if (status)
-               status <<= PCI_EXP_SLTCTL_ATTN_IND_SHIFT;
+               status = FIELD_PREP(PCI_EXP_SLTCTL_AIC, status);
        else
                status = PCI_EXP_SLTCTL_ATTN_IND_OFF;
 
index fd713abdfb9f9625919aeb52d3aa8f68b26e0f6e..b1d0a1b3917d44b34985e89c541d63816605b703 100644 (file)
@@ -14,6 +14,7 @@
 
 #define dev_fmt(fmt) "pciehp: " fmt
 
+#include <linux/bitfield.h>
 #include <linux/dmi.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
@@ -484,7 +485,7 @@ int pciehp_set_raw_indicator_status(struct hotplug_slot *hotplug_slot,
        struct pci_dev *pdev = ctrl_dev(ctrl);
 
        pci_config_pm_runtime_get(pdev);
-       pcie_write_cmd_nowait(ctrl, status << 6,
+       pcie_write_cmd_nowait(ctrl, FIELD_PREP(PCI_EXP_SLTCTL_AIC, status),
                              PCI_EXP_SLTCTL_AIC | PCI_EXP_SLTCTL_PIC);
        pci_config_pm_runtime_put(pdev);
        return 0;
@@ -1028,7 +1029,7 @@ struct controller *pcie_init(struct pcie_device *dev)
                PCI_EXP_SLTSTA_DLLSC | PCI_EXP_SLTSTA_PDC);
 
        ctrl_info(ctrl, "Slot #%d AttnBtn%c PwrCtrl%c MRL%c AttnInd%c PwrInd%c HotPlug%c Surprise%c Interlock%c NoCompl%c IbPresDis%c LLActRep%c%s\n",
-               (slot_cap & PCI_EXP_SLTCAP_PSN) >> 19,
+               FIELD_GET(PCI_EXP_SLTCAP_PSN, slot_cap),
                FLAG(slot_cap, PCI_EXP_SLTCAP_ABP),
                FLAG(slot_cap, PCI_EXP_SLTCAP_PCP),
                FLAG(slot_cap, PCI_EXP_SLTCAP_MRLSP),
index 881d420637bf1ec9e1af1997ba615f78b8019887..694349be9d0aa284770c9e97823d5e6ba01ef799 100644 (file)
@@ -5,6 +5,7 @@
  * Copyright Gavin Shan, IBM Corporation 2016.
  */
 
+#include <linux/bitfield.h>
 #include <linux/libfdt.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -731,7 +732,7 @@ static int pnv_php_enable_msix(struct pnv_php_slot *php_slot)
 
        /* Check hotplug MSIx entry is in range */
        pcie_capability_read_word(pdev, PCI_EXP_FLAGS, &pcie_flag);
-       entry.entry = (pcie_flag & PCI_EXP_FLAGS_IRQ) >> 9;
+       entry.entry = FIELD_GET(PCI_EXP_FLAGS_IRQ, pcie_flag);
        if (entry.entry >= nr_entries)
                return -ERANGE;