Skip to content

Commit b48d442

Browse files
committed
PCI: add ID-based ordering enable/disable support
Add support to allow drivers to enable/disable ID-based ordering. Where supported, ID-based ordering can significantly improve the latency of individual requests by preventing them from queueing up behind unrelated traffic. Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent 69643e4 commit b48d442

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

‎drivers/pci/pci.c‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,59 @@ void pci_enable_ari(struct pci_dev *dev)
18341834
bridge->ari_enabled = 1;
18351835
}
18361836

1837+
/**
1838+
* pci_enable_ido - enable ID-based ordering on a device
1839+
* @dev: the PCI device
1840+
* @type: which types of IDO to enable
1841+
*
1842+
* Enable ID-based ordering on @dev. @type can contain the bits
1843+
* %PCI_EXP_IDO_REQUEST and/or %PCI_EXP_IDO_COMPLETION to indicate
1844+
* which types of transactions are allowed to be re-ordered.
1845+
*/
1846+
void pci_enable_ido(struct pci_dev *dev, unsigned long type)
1847+
{
1848+
int pos;
1849+
u16 ctrl;
1850+
1851+
pos = pci_pcie_cap(dev);
1852+
if (!pos)
1853+
return;
1854+
1855+
pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl);
1856+
if (type & PCI_EXP_IDO_REQUEST)
1857+
ctrl |= PCI_EXP_IDO_REQ_EN;
1858+
if (type & PCI_EXP_IDO_COMPLETION)
1859+
ctrl |= PCI_EXP_IDO_CMP_EN;
1860+
pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl);
1861+
}
1862+
EXPORT_SYMBOL(pci_enable_ido);
1863+
1864+
/**
1865+
* pci_disable_ido - disable ID-based ordering on a device
1866+
* @dev: the PCI device
1867+
* @type: which types of IDO to disable
1868+
*/
1869+
void pci_disable_ido(struct pci_dev *dev, unsigned long type)
1870+
{
1871+
int pos;
1872+
u16 ctrl;
1873+
1874+
if (!pci_is_pcie(dev))
1875+
return;
1876+
1877+
pos = pci_pcie_cap(dev);
1878+
if (!pos)
1879+
return;
1880+
1881+
pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl);
1882+
if (type & PCI_EXP_IDO_REQUEST)
1883+
ctrl &= ~PCI_EXP_IDO_REQ_EN;
1884+
if (type & PCI_EXP_IDO_COMPLETION)
1885+
ctrl &= ~PCI_EXP_IDO_CMP_EN;
1886+
pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl);
1887+
}
1888+
EXPORT_SYMBOL(pci_disable_ido);
1889+
18371890
static int pci_acs_enable;
18381891

18391892
/**

‎include/linux/pci.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,11 @@ static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state,
828828
return __pci_enable_wake(dev, state, false, enable);
829829
}
830830

831+
#define PCI_EXP_IDO_REQUEST (1<<0)
832+
#define PCI_EXP_IDO_COMPLETION (1<<1)
833+
void pci_enable_ido(struct pci_dev *dev, unsigned long type);
834+
void pci_disable_ido(struct pci_dev *dev, unsigned long type);
835+
831836
/* For use by arch with custom probe code */
832837
void set_pcie_port_type(struct pci_dev *pdev);
833838
void set_pcie_hotplug_bridge(struct pci_dev *pdev);
@@ -1207,6 +1212,14 @@ static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state,
12071212
return 0;
12081213
}
12091214

1215+
static inline void pci_enable_ido(struct pci_dev *dev, unsigned long type)
1216+
{
1217+
}
1218+
1219+
static inline void pci_disable_ido(struct pci_dev *dev, unsigned long type)
1220+
{
1221+
}
1222+
12101223
static inline int pci_request_regions(struct pci_dev *dev, const char *res_name)
12111224
{
12121225
return -EIO;

‎include/linux/pci_regs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@
510510
#define PCI_EXP_DEVCAP2_ARI 0x20 /* Alternative Routing-ID */
511511
#define PCI_EXP_DEVCTL2 40 /* Device Control 2 */
512512
#define PCI_EXP_DEVCTL2_ARI 0x20 /* Alternative Routing-ID */
513+
#define PCI_EXP_IDO_REQ_EN 0x100 /* ID-based ordering request enable */
514+
#define PCI_EXP_IDO_CMP_EN 0x200 /* ID-based ordering completion enable */
513515
#define PCI_EXP_LNKCTL2 48 /* Link Control 2 */
514516
#define PCI_EXP_SLTCTL2 56 /* Slot Control 2 */
515517

0 commit comments

Comments
 (0)