|
6 | 6 | * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com) |
7 | 7 | * Copyright (C) 2016 Christoph Hellwig. |
8 | 8 | */ |
| 9 | +#include <linux/bitfield.h> |
9 | 10 | #include <linux/err.h> |
10 | 11 | #include <linux/export.h> |
11 | 12 | #include <linux/irq.h> |
@@ -188,7 +189,7 @@ static inline void pci_write_msg_msi(struct pci_dev *dev, struct msi_desc *desc, |
188 | 189 |
|
189 | 190 | pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); |
190 | 191 | 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); |
192 | 193 | pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl); |
193 | 194 |
|
194 | 195 | 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, |
299 | 300 | desc.pci.msi_attrib.is_64 = !!(control & PCI_MSI_FLAGS_64BIT); |
300 | 301 | desc.pci.msi_attrib.can_mask = !!(control & PCI_MSI_FLAGS_MASKBIT); |
301 | 302 | 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); |
303 | 304 | desc.pci.msi_attrib.multiple = ilog2(__roundup_pow_of_two(nvec)); |
304 | 305 | desc.affinity = masks; |
305 | 306 |
|
@@ -478,7 +479,7 @@ int pci_msi_vec_count(struct pci_dev *dev) |
478 | 479 | return -EINVAL; |
479 | 480 |
|
480 | 481 | 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); |
482 | 483 |
|
483 | 484 | return ret; |
484 | 485 | } |
@@ -511,7 +512,8 @@ void __pci_restore_msi_state(struct pci_dev *dev) |
511 | 512 | pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control); |
512 | 513 | pci_msi_update_mask(entry, 0, 0); |
513 | 514 | 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); |
515 | 517 | pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control); |
516 | 518 | } |
517 | 519 |
|
|
0 commit comments