ia64/linux-2.6.18-xen.hg

changeset 811:36d8c23b7574

Backport: PCI: support PCIe ARI capability

commit 58c3a727cb73b75a9104d295f096cca12959a5a5
Author: Yu Zhao <yu.zhao@intel.com>
Date: Tue Oct 14 14:02:53 2008 +0800

PCI: support PCIe ARI capability

This patch adds support for PCI Express Alternative Routing-ID
Interpretation (ARI) capability.

The ARI capability extends the Function Number field of the PCI
Express
Endpoint by reusing the Device Number which is otherwise hardwired
to 0.
With ARI, an Endpoint can have up to 256 functions.

Signed-off-by: Yu Zhao <yu.zhao@intel.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>

Signed-off-by: Yu Zhao <yu.zhao@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Mar 13 07:40:54 2009 +0000 (2009-03-13)
parents ea67a65cec17
children 44fd32e157f2
files drivers/pci/pci.c drivers/pci/pci.h drivers/pci/probe.c include/linux/pci.h include/linux/pci_regs.h
line diff
     1.1 --- a/drivers/pci/pci.c	Fri Mar 13 07:40:36 2009 +0000
     1.2 +++ b/drivers/pci/pci.c	Fri Mar 13 07:40:54 2009 +0000
     1.3 @@ -629,6 +629,38 @@ int pci_enable_wake(struct pci_dev *dev,
     1.4  	return 0;
     1.5  }
     1.6  
     1.7 +/**
     1.8 + * pci_enable_ari - enable ARI forwarding if hardware support it
     1.9 + * @dev: the PCI device
    1.10 + */
    1.11 +void pci_enable_ari(struct pci_dev *dev)
    1.12 +{
    1.13 +	int pos;
    1.14 +	u32 cap;
    1.15 +	u16 ctrl;
    1.16 +
    1.17 +	if (!dev->is_pcie)
    1.18 +		return;
    1.19 +
    1.20 +	if (dev->pcie_type != PCI_EXP_TYPE_ROOT_PORT &&
    1.21 +	    dev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)
    1.22 +		return;
    1.23 +
    1.24 +	pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
    1.25 +	if (!pos)
    1.26 +		return;
    1.27 +
    1.28 +	pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP2, &cap);
    1.29 +	if (!(cap & PCI_EXP_DEVCAP2_ARI))
    1.30 +		return;
    1.31 +
    1.32 +	pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl);
    1.33 +	ctrl |= PCI_EXP_DEVCTL2_ARI;
    1.34 +	pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl);
    1.35 +
    1.36 +	dev->ari_enabled = 1;
    1.37 +}
    1.38 +
    1.39  int
    1.40  pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge)
    1.41  {
     2.1 --- a/drivers/pci/pci.h	Fri Mar 13 07:40:36 2009 +0000
     2.2 +++ b/drivers/pci/pci.h	Fri Mar 13 07:40:54 2009 +0000
     2.3 @@ -119,3 +119,14 @@ enum pci_bar_type {
     2.4  
     2.5  extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
     2.6  				struct resource *res, unsigned int reg);
     2.7 +extern void pci_enable_ari(struct pci_dev *dev);
     2.8 +/**
     2.9 + * pci_ari_enabled - query ARI forwarding status
    2.10 + * @dev: the PCI device
    2.11 + *
    2.12 + * Returns 1 if ARI forwarding is enabled, or 0 if not enabled;
    2.13 + */
    2.14 +static inline int pci_ari_enabled(struct pci_dev *dev)
    2.15 +{
    2.16 +	return dev->ari_enabled;
    2.17 +}
     3.1 --- a/drivers/pci/probe.c	Fri Mar 13 07:40:36 2009 +0000
     3.2 +++ b/drivers/pci/probe.c	Fri Mar 13 07:40:54 2009 +0000
     3.3 @@ -885,6 +885,9 @@ void __devinit pci_device_add(struct pci
     3.4  	/* Fix up broken headers */
     3.5  	pci_fixup_device(pci_fixup_header, dev);
     3.6  
     3.7 +	/* Alternative Routing-ID Forwarding */
     3.8 +	pci_enable_ari(dev);
     3.9 +
    3.10  	/*
    3.11  	 * Add the device to our list of discovered devices
    3.12  	 * and the bus list for fixup functions, etc.
     4.1 --- a/include/linux/pci.h	Fri Mar 13 07:40:36 2009 +0000
     4.2 +++ b/include/linux/pci.h	Fri Mar 13 07:40:54 2009 +0000
     4.3 @@ -172,6 +172,7 @@ struct pci_dev {
     4.4  	struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */
     4.5  	int rom_attr_enabled;		/* has display of the rom attribute been enabled? */
     4.6  	struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */
     4.7 +	unsigned int	ari_enabled:1;	/* ARI forwarding */
     4.8  };
     4.9  
    4.10  #define pci_dev_g(n) list_entry(n, struct pci_dev, global_list)
     5.1 --- a/include/linux/pci_regs.h	Fri Mar 13 07:40:36 2009 +0000
     5.2 +++ b/include/linux/pci_regs.h	Fri Mar 13 07:40:54 2009 +0000
     5.3 @@ -378,6 +378,10 @@
     5.4  #define  PCI_EXP_RTCTL_CRSSVE	0x10	/* CRS Software Visibility Enable */
     5.5  #define PCI_EXP_RTCAP		30	/* Root Capabilities */
     5.6  #define PCI_EXP_RTSTA		32	/* Root Status */
     5.7 +#define PCI_EXP_DEVCAP2		36	/* Device Capabilities 2 */
     5.8 +#define  PCI_EXP_DEVCAP2_ARI	0x20	/* Alternative Routing-ID */
     5.9 +#define PCI_EXP_DEVCTL2		40	/* Device Control 2 */
    5.10 +#define  PCI_EXP_DEVCTL2_ARI	0x20	/* Alternative Routing-ID */
    5.11  
    5.12  /* Extended Capabilities (PCI-X 2.0 and Express) */
    5.13  #define PCI_EXT_CAP_ID(header)		(header & 0x0000ffff)
    5.14 @@ -388,6 +392,7 @@
    5.15  #define PCI_EXT_CAP_ID_VC	2
    5.16  #define PCI_EXT_CAP_ID_DSN	3
    5.17  #define PCI_EXT_CAP_ID_PWR	4
    5.18 +#define PCI_EXT_CAP_ID_ARI	14
    5.19  
    5.20  /* Advanced Error Reporting */
    5.21  #define PCI_ERR_UNCOR_STATUS	4	/* Uncorrectable Error Status */
    5.22 @@ -463,4 +468,14 @@
    5.23  #define PCI_PWR_CAP		12	/* Capability */
    5.24  #define  PCI_PWR_CAP_BUDGET(x)	((x) & 1)	/* Included in system budget */
    5.25  
    5.26 +/* Alternative Routing-ID Interpretation */
    5.27 +#define PCI_ARI_CAP		0x04	/* ARI Capability Register */
    5.28 +#define  PCI_ARI_CAP_MFVC	0x0001	/* MFVC Function Groups Capability */
    5.29 +#define  PCI_ARI_CAP_ACS	0x0002	/* ACS Function Groups Capability */
    5.30 +#define  PCI_ARI_CAP_NFN(x)	(((x) >> 8) & 0xff) /* Next Function Number */
    5.31 +#define PCI_ARI_CTRL		0x06	/* ARI Control Register */
    5.32 +#define  PCI_ARI_CTRL_MFVC	0x0001	/* MFVC Function Groups Enable */
    5.33 +#define  PCI_ARI_CTRL_ACS	0x0002	/* ACS Function Groups Enable */
    5.34 +#define  PCI_ARI_CTRL_FG(x)	(((x) >> 4) & 7) /* Function Group */
    5.35 +
    5.36  #endif /* LINUX_PCI_REGS_H */