Commit 1bf83e55 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki Committed by Jesse Barnes

PCI: PCIe portdrv: Use driver data to simplify code

PCI Express port driver extension, as defined by struct
pcie_port_device_ext in portdrv.h, is allocated and initialized, but
never used (it also is never freed).  Extend it to hold the PCI Express
port type as well as the port interrupt mode, change its name and use it
to simplify the code in portdrv_core.c .

Additionally, remove the redundant interrupt_mode member of struct
pcie_device defined in include/linux/pcieport_if.h .
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent e496b617
...@@ -28,8 +28,9 @@ ...@@ -28,8 +28,9 @@
#define get_descriptor_id(type, service) (((type - 4) << 4) | service) #define get_descriptor_id(type, service) (((type - 4) << 4) | service)
struct pcie_port_device_ext { struct pcie_port_data {
int interrupt_mode; /* [0:INTx | 1:MSI | 2:MSI-X] */ int port_type; /* Type of the port */
int port_irq_mode; /* [0:INTx | 1:MSI | 2:MSI-X] */
}; };
extern struct bus_type pcie_port_bus_type; extern struct bus_type pcie_port_bus_type;
......
...@@ -15,10 +15,9 @@ ...@@ -15,10 +15,9 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/pcieport_if.h> #include <linux/pcieport_if.h>
#include "../pci.h"
#include "portdrv.h" #include "portdrv.h"
extern int pcie_mch_quirk; /* MSI-quirk Indicator */
/** /**
* release_pcie_device - free PCI Express port service device structure * release_pcie_device - free PCI Express port service device structure
* @dev: Port service device to release * @dev: Port service device to release
...@@ -31,28 +30,6 @@ static void release_pcie_device(struct device *dev) ...@@ -31,28 +30,6 @@ static void release_pcie_device(struct device *dev)
kfree(to_pcie_device(dev)); kfree(to_pcie_device(dev));
} }
static int is_msi_quirked(struct pci_dev *dev)
{
int port_type, quirk = 0;
u16 reg16;
pci_read_config_word(dev,
pci_find_capability(dev, PCI_CAP_ID_EXP) +
PCIE_CAPABILITIES_REG, &reg16);
port_type = (reg16 >> 4) & PORT_TYPE_MASK;
switch(port_type) {
case PCIE_RC_PORT:
if (pcie_mch_quirk == 1)
quirk = 1;
break;
case PCIE_SW_UPSTREAM_PORT:
case PCIE_SW_DOWNSTREAM_PORT:
default:
break;
}
return quirk;
}
/** /**
* assign_interrupt_mode - choose interrupt mode for PCI Express port services * assign_interrupt_mode - choose interrupt mode for PCI Express port services
* (INTx, MSI-X, MSI) and set up vectors * (INTx, MSI-X, MSI) and set up vectors
...@@ -64,6 +41,7 @@ static int is_msi_quirked(struct pci_dev *dev) ...@@ -64,6 +41,7 @@ static int is_msi_quirked(struct pci_dev *dev)
*/ */
static int assign_interrupt_mode(struct pci_dev *dev, int *vectors, int mask) static int assign_interrupt_mode(struct pci_dev *dev, int *vectors, int mask)
{ {
struct pcie_port_data *port_data = pci_get_drvdata(dev);
int i, pos, nvec, status = -EINVAL; int i, pos, nvec, status = -EINVAL;
int interrupt_mode = PCIE_PORT_INTx_MODE; int interrupt_mode = PCIE_PORT_INTx_MODE;
...@@ -75,7 +53,7 @@ static int assign_interrupt_mode(struct pci_dev *dev, int *vectors, int mask) ...@@ -75,7 +53,7 @@ static int assign_interrupt_mode(struct pci_dev *dev, int *vectors, int mask)
} }
/* Check MSI quirk */ /* Check MSI quirk */
if (is_msi_quirked(dev)) if (port_data->port_type == PCIE_RC_PORT && pcie_mch_quirk)
return interrupt_mode; return interrupt_mode;
/* Select MSI-X over MSI if supported */ /* Select MSI-X over MSI if supported */
...@@ -132,13 +110,11 @@ static int get_port_device_capability(struct pci_dev *dev) ...@@ -132,13 +110,11 @@ static int get_port_device_capability(struct pci_dev *dev)
pos + PCIE_SLOT_CAPABILITIES_REG, &reg32); pos + PCIE_SLOT_CAPABILITIES_REG, &reg32);
if (reg32 & SLOT_HP_CAPABLE_MASK) if (reg32 & SLOT_HP_CAPABLE_MASK)
services |= PCIE_PORT_SERVICE_HP; services |= PCIE_PORT_SERVICE_HP;
} }
/* PME Capable - root port capability */ /* AER capable */
if (((reg16 >> 4) & PORT_TYPE_MASK) == PCIE_RC_PORT)
services |= PCIE_PORT_SERVICE_PME;
if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR)) if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR))
services |= PCIE_PORT_SERVICE_AER; services |= PCIE_PORT_SERVICE_AER;
/* VC support */
if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_VC)) if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_VC))
services |= PCIE_PORT_SERVICE_VC; services |= PCIE_PORT_SERVICE_VC;
...@@ -152,15 +128,15 @@ static int get_port_device_capability(struct pci_dev *dev) ...@@ -152,15 +128,15 @@ static int get_port_device_capability(struct pci_dev *dev)
* @port_type: Type of the port * @port_type: Type of the port
* @service_type: Type of service to associate with the service device * @service_type: Type of service to associate with the service device
* @irq: Interrupt vector to associate with the service device * @irq: Interrupt vector to associate with the service device
* @irq_mode: Interrupt mode of the service (INTx, MSI-X, MSI)
*/ */
static void pcie_device_init(struct pci_dev *parent, struct pcie_device *dev, static void pcie_device_init(struct pci_dev *parent, struct pcie_device *dev,
int port_type, int service_type, int irq, int irq_mode) int service_type, int irq)
{ {
struct pcie_port_data *port_data = pci_get_drvdata(parent);
struct device *device; struct device *device;
int port_type = port_data->port_type;
dev->port = parent; dev->port = parent;
dev->interrupt_mode = irq_mode;
dev->irq = irq; dev->irq = irq;
dev->id.vendor = parent->vendor; dev->id.vendor = parent->vendor;
dev->id.device = parent->device; dev->id.device = parent->device;
...@@ -185,10 +161,9 @@ static void pcie_device_init(struct pci_dev *parent, struct pcie_device *dev, ...@@ -185,10 +161,9 @@ static void pcie_device_init(struct pci_dev *parent, struct pcie_device *dev,
* @port_type: Type of the port * @port_type: Type of the port
* @service_type: Type of service to associate with the service device * @service_type: Type of service to associate with the service device
* @irq: Interrupt vector to associate with the service device * @irq: Interrupt vector to associate with the service device
* @irq_mode: Interrupt mode of the service (INTx, MSI-X, MSI)
*/ */
static struct pcie_device* alloc_pcie_device(struct pci_dev *parent, static struct pcie_device* alloc_pcie_device(struct pci_dev *parent,
int port_type, int service_type, int irq, int irq_mode) int service_type, int irq)
{ {
struct pcie_device *device; struct pcie_device *device;
...@@ -196,7 +171,7 @@ static struct pcie_device* alloc_pcie_device(struct pci_dev *parent, ...@@ -196,7 +171,7 @@ static struct pcie_device* alloc_pcie_device(struct pci_dev *parent,
if (!device) if (!device)
return NULL; return NULL;
pcie_device_init(parent, device, port_type, service_type, irq,irq_mode); pcie_device_init(parent, device, service_type, irq);
return device; return device;
} }
...@@ -230,39 +205,36 @@ int pcie_port_device_probe(struct pci_dev *dev) ...@@ -230,39 +205,36 @@ int pcie_port_device_probe(struct pci_dev *dev)
*/ */
int pcie_port_device_register(struct pci_dev *dev) int pcie_port_device_register(struct pci_dev *dev)
{ {
struct pcie_port_device_ext *p_ext; struct pcie_port_data *port_data;
int status, type, capabilities, irq_mode, i; int status, capabilities, irq_mode, i;
int vectors[PCIE_PORT_DEVICE_MAXSERVICES]; int vectors[PCIE_PORT_DEVICE_MAXSERVICES];
u16 reg16; u16 reg16;
/* Allocate port device extension */ port_data = kzalloc(sizeof(*port_data), GFP_KERNEL);
if (!(p_ext = kmalloc(sizeof(struct pcie_port_device_ext), GFP_KERNEL))) if (!port_data)
return -ENOMEM; return -ENOMEM;
pci_set_drvdata(dev, port_data);
pci_set_drvdata(dev, p_ext);
/* Get port type */ /* Get port type */
pci_read_config_word(dev, pci_read_config_word(dev,
pci_find_capability(dev, PCI_CAP_ID_EXP) + pci_find_capability(dev, PCI_CAP_ID_EXP) +
PCIE_CAPABILITIES_REG, &reg16); PCIE_CAPABILITIES_REG, &reg16);
type = (reg16 >> 4) & PORT_TYPE_MASK; port_data->port_type = (reg16 >> 4) & PORT_TYPE_MASK;
/* Now get port services */
capabilities = get_port_device_capability(dev); capabilities = get_port_device_capability(dev);
/* Root ports are capable of generating PME too */
if (port_data->port_type == PCIE_RC_PORT)
capabilities |= PCIE_PORT_SERVICE_PME;
irq_mode = assign_interrupt_mode(dev, vectors, capabilities); irq_mode = assign_interrupt_mode(dev, vectors, capabilities);
p_ext->interrupt_mode = irq_mode; port_data->port_irq_mode = irq_mode;
/* Allocate child services if any */ /* Allocate child services if any */
for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++) { for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++) {
struct pcie_device *child; struct pcie_device *child;
if (capabilities & (1 << i)) { if (capabilities & (1 << i)) {
child = alloc_pcie_device( child = alloc_pcie_device(dev, i, vectors[i]);
dev, /* parent */
type, /* port type */
i, /* service type */
vectors[i], /* irq */
irq_mode /* interrupt mode */);
if (child) { if (child) {
status = device_register(&child->device); status = device_register(&child->device);
if (status) { if (status) {
...@@ -349,25 +321,30 @@ static int remove_iter(struct device *dev, void *data) ...@@ -349,25 +321,30 @@ static int remove_iter(struct device *dev, void *data)
*/ */
void pcie_port_device_remove(struct pci_dev *dev) void pcie_port_device_remove(struct pci_dev *dev)
{ {
struct device *device; struct pcie_port_data *port_data = pci_get_drvdata(dev);
unsigned long device_addr;
int interrupt_mode = PCIE_PORT_INTx_MODE;
int status; int status;
do { do {
unsigned long device_addr;
status = device_for_each_child(&dev->dev, &device_addr, remove_iter); status = device_for_each_child(&dev->dev, &device_addr, remove_iter);
if (status) { if (status) {
device = (struct device*)device_addr; struct device *device = (struct device*)device_addr;
interrupt_mode = (to_pcie_device(device))->interrupt_mode;
put_device(device); put_device(device);
device_unregister(device); device_unregister(device);
} }
} while (status); } while (status);
/* Switch to INTx by default if MSI enabled */
if (interrupt_mode == PCIE_PORT_MSIX_MODE) switch (port_data->port_irq_mode) {
case PCIE_PORT_MSIX_MODE:
pci_disable_msix(dev); pci_disable_msix(dev);
else if (interrupt_mode == PCIE_PORT_MSI_MODE) break;
case PCIE_PORT_MSI_MODE:
pci_disable_msi(dev); pci_disable_msi(dev);
break;
}
kfree(port_data);
} }
/** /**
......
...@@ -36,7 +36,6 @@ struct pcie_port_service_id { ...@@ -36,7 +36,6 @@ struct pcie_port_service_id {
struct pcie_device { struct pcie_device {
int irq; /* Service IRQ/MSI/MSI-X Vector */ int irq; /* Service IRQ/MSI/MSI-X Vector */
int interrupt_mode; /* [0:INTx | 1:MSI | 2:MSI-X] */
struct pcie_port_service_id id; /* Service ID */ struct pcie_port_service_id id; /* Service ID */
struct pci_dev *port; /* Root/Upstream/Downstream Port */ struct pci_dev *port; /* Root/Upstream/Downstream Port */
void *priv_data; /* Service Private Data */ void *priv_data; /* Service Private Data */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment