Skip to content

Commit 682f531

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI/MSI: Use FIELD_GET/PREP()
Instead of custom masking and shifting, use FIELD_GET/PREP() with register fields. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 74f0b5f commit 682f531

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/pci/msi/msi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Copyright (C) Tom Long Nguyen ([email protected])
77
* Copyright (C) 2016 Christoph Hellwig.
88
*/
9+
#include <linux/bitfield.h>
910
#include <linux/err.h>
1011
#include <linux/export.h>
1112
#include <linux/irq.h>
@@ -188,7 +189,7 @@ static inline void pci_write_msg_msi(struct pci_dev *dev, struct msi_desc *desc,
188189

189190
pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl);
190191
msgctl &= ~PCI_MSI_FLAGS_QSIZE;
191-
msgctl |= desc->pci.msi_attrib.multiple << 4;
192+
msgctl |= FIELD_PREP(PCI_MSI_FLAGS_QSIZE, desc->pci.msi_attrib.multiple);
192193
pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl);
193194

194195
pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, msg->address_lo);
@@ -299,7 +300,7 @@ static int msi_setup_msi_desc(struct pci_dev *dev, int nvec,
299300
desc.pci.msi_attrib.is_64 = !!(control & PCI_MSI_FLAGS_64BIT);
300301
desc.pci.msi_attrib.can_mask = !!(control & PCI_MSI_FLAGS_MASKBIT);
301302
desc.pci.msi_attrib.default_irq = dev->irq;
302-
desc.pci.msi_attrib.multi_cap = (control & PCI_MSI_FLAGS_QMASK) >> 1;
303+
desc.pci.msi_attrib.multi_cap = FIELD_GET(PCI_MSI_FLAGS_QMASK, control);
303304
desc.pci.msi_attrib.multiple = ilog2(__roundup_pow_of_two(nvec));
304305
desc.affinity = masks;
305306

@@ -478,7 +479,7 @@ int pci_msi_vec_count(struct pci_dev *dev)
478479
return -EINVAL;
479480

480481
pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
481-
ret = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1);
482+
ret = 1 << FIELD_GET(PCI_MSI_FLAGS_QMASK, msgctl);
482483

483484
return ret;
484485
}
@@ -511,7 +512,8 @@ void __pci_restore_msi_state(struct pci_dev *dev)
511512
pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
512513
pci_msi_update_mask(entry, 0, 0);
513514
control &= ~PCI_MSI_FLAGS_QSIZE;
514-
control |= (entry->pci.msi_attrib.multiple << 4) | PCI_MSI_FLAGS_ENABLE;
515+
control |= PCI_MSI_FLAGS_ENABLE |
516+
FIELD_PREP(PCI_MSI_FLAGS_QSIZE, entry->pci.msi_attrib.multiple);
515517
pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
516518
}
517519

0 commit comments

Comments
 (0)