2018-01-26 13:22:04 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* CompactPCI Hot Plug Driver PCI functions
|
|
|
|
*
|
2005-05-27 14:48:52 -06:00
|
|
|
* Copyright (C) 2002,2005 by SOMA Networks, Inc.
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Send feedback to <scottm@somanetworks.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pci.h>
|
2006-10-13 21:05:19 -06:00
|
|
|
#include <linux/pci_hotplug.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include "../pci.h"
|
|
|
|
#include "cpci_hotplug.h"
|
|
|
|
|
|
|
|
#define MY_NAME "cpci_hotplug"
|
|
|
|
|
|
|
|
extern int cpci_debug;
|
|
|
|
|
|
|
|
#define dbg(format, arg...) \
|
|
|
|
do { \
|
2005-05-27 14:48:52 -06:00
|
|
|
if (cpci_debug) \
|
2015-12-27 14:21:11 -07:00
|
|
|
printk(KERN_DEBUG "%s: " format "\n", \
|
|
|
|
MY_NAME, ## arg); \
|
2005-05-27 14:48:52 -06:00
|
|
|
} while (0)
|
2015-12-27 14:21:11 -07:00
|
|
|
#define err(format, arg...) printk(KERN_ERR "%s: " format "\n", MY_NAME, ## arg)
|
|
|
|
#define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME, ## arg)
|
|
|
|
#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME, ## arg)
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
|
2014-04-18 18:13:49 -06:00
|
|
|
u8 cpci_get_attention_status(struct slot *slot)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int hs_cap;
|
|
|
|
u16 hs_csr;
|
|
|
|
|
|
|
|
hs_cap = pci_bus_find_capability(slot->bus,
|
|
|
|
slot->devfn,
|
|
|
|
PCI_CAP_ID_CHSWP);
|
2005-05-27 14:48:52 -06:00
|
|
|
if (!hs_cap)
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_read_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
&hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
2005-05-27 14:48:52 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
return hs_csr & 0x0008 ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:13:49 -06:00
|
|
|
int cpci_set_attention_status(struct slot *slot, int status)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int hs_cap;
|
|
|
|
u16 hs_csr;
|
|
|
|
|
|
|
|
hs_cap = pci_bus_find_capability(slot->bus,
|
|
|
|
slot->devfn,
|
|
|
|
PCI_CAP_ID_CHSWP);
|
2005-05-27 14:48:52 -06:00
|
|
|
if (!hs_cap)
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_read_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
&hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (status)
|
2005-04-16 16:20:36 -06:00
|
|
|
hs_csr |= HS_CSR_LOO;
|
2005-05-27 14:48:52 -06:00
|
|
|
else
|
2005-04-16 16:20:36 -06:00
|
|
|
hs_csr &= ~HS_CSR_LOO;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_write_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:13:49 -06:00
|
|
|
u16 cpci_get_hs_csr(struct slot *slot)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int hs_cap;
|
|
|
|
u16 hs_csr;
|
|
|
|
|
|
|
|
hs_cap = pci_bus_find_capability(slot->bus,
|
|
|
|
slot->devfn,
|
|
|
|
PCI_CAP_ID_CHSWP);
|
2005-05-27 14:48:52 -06:00
|
|
|
if (!hs_cap)
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0xFFFF;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_read_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
&hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0xFFFF;
|
|
|
|
return hs_csr;
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:13:49 -06:00
|
|
|
int cpci_check_and_clear_ins(struct slot *slot)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int hs_cap;
|
|
|
|
u16 hs_csr;
|
|
|
|
int ins = 0;
|
|
|
|
|
|
|
|
hs_cap = pci_bus_find_capability(slot->bus,
|
|
|
|
slot->devfn,
|
|
|
|
PCI_CAP_ID_CHSWP);
|
2005-05-27 14:48:52 -06:00
|
|
|
if (!hs_cap)
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_read_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
&hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (hs_csr & HS_CSR_INS) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Clear INS (by setting it) */
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_write_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
ins = 0;
|
2005-05-27 14:48:52 -06:00
|
|
|
else
|
|
|
|
ins = 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
return ins;
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:13:49 -06:00
|
|
|
int cpci_check_ext(struct slot *slot)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int hs_cap;
|
|
|
|
u16 hs_csr;
|
|
|
|
int ext = 0;
|
|
|
|
|
|
|
|
hs_cap = pci_bus_find_capability(slot->bus,
|
|
|
|
slot->devfn,
|
|
|
|
PCI_CAP_ID_CHSWP);
|
2005-05-27 14:48:52 -06:00
|
|
|
if (!hs_cap)
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_read_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
&hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (hs_csr & HS_CSR_EXT)
|
2005-04-16 16:20:36 -06:00
|
|
|
ext = 1;
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:13:49 -06:00
|
|
|
int cpci_clear_ext(struct slot *slot)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int hs_cap;
|
|
|
|
u16 hs_csr;
|
|
|
|
|
|
|
|
hs_cap = pci_bus_find_capability(slot->bus,
|
|
|
|
slot->devfn,
|
|
|
|
PCI_CAP_ID_CHSWP);
|
2005-05-27 14:48:52 -06:00
|
|
|
if (!hs_cap)
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_read_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
&hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (hs_csr & HS_CSR_EXT) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* Clear EXT (by setting it) */
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_write_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:13:49 -06:00
|
|
|
int cpci_led_on(struct slot *slot)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int hs_cap;
|
|
|
|
u16 hs_csr;
|
|
|
|
|
|
|
|
hs_cap = pci_bus_find_capability(slot->bus,
|
|
|
|
slot->devfn,
|
|
|
|
PCI_CAP_ID_CHSWP);
|
2005-05-27 14:48:52 -06:00
|
|
|
if (!hs_cap)
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_read_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
&hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
2005-05-27 14:48:52 -06:00
|
|
|
if ((hs_csr & HS_CSR_LOO) != HS_CSR_LOO) {
|
2005-04-16 16:20:36 -06:00
|
|
|
hs_csr |= HS_CSR_LOO;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_write_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
|
|
|
hs_csr)) {
|
|
|
|
err("Could not set LOO for slot %s",
|
2008-10-20 17:41:17 -06:00
|
|
|
hotplug_slot_name(slot->hotplug_slot));
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-18 18:13:49 -06:00
|
|
|
int cpci_led_off(struct slot *slot)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int hs_cap;
|
|
|
|
u16 hs_csr;
|
|
|
|
|
|
|
|
hs_cap = pci_bus_find_capability(slot->bus,
|
|
|
|
slot->devfn,
|
|
|
|
PCI_CAP_ID_CHSWP);
|
2005-05-27 14:48:52 -06:00
|
|
|
if (!hs_cap)
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_read_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
2005-05-27 14:48:52 -06:00
|
|
|
&hs_csr))
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (hs_csr & HS_CSR_LOO) {
|
2005-04-16 16:20:36 -06:00
|
|
|
hs_csr &= ~HS_CSR_LOO;
|
2005-05-27 14:48:52 -06:00
|
|
|
if (pci_bus_write_config_word(slot->bus,
|
2005-04-16 16:20:36 -06:00
|
|
|
slot->devfn,
|
|
|
|
hs_cap + 2,
|
|
|
|
hs_csr)) {
|
|
|
|
err("Could not clear LOO for slot %s",
|
2008-10-20 17:41:17 -06:00
|
|
|
hotplug_slot_name(slot->hotplug_slot));
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device configuration functions
|
|
|
|
*/
|
|
|
|
|
2014-04-14 16:11:40 -06:00
|
|
|
int cpci_configure_slot(struct slot *slot)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-01-14 20:12:20 -07:00
|
|
|
struct pci_dev *dev;
|
2006-08-22 17:55:57 -06:00
|
|
|
struct pci_bus *parent;
|
2014-01-14 12:03:14 -07:00
|
|
|
int ret = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-03-03 20:09:46 -07:00
|
|
|
dbg("%s - enter", __func__);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2014-01-14 12:03:14 -07:00
|
|
|
pci_lock_rescan_remove();
|
|
|
|
|
2005-05-27 14:48:52 -06:00
|
|
|
if (slot->dev == NULL) {
|
2005-04-16 16:20:36 -06:00
|
|
|
dbg("pci_dev null, finding %02x:%02x:%x",
|
|
|
|
slot->bus->number, PCI_SLOT(slot->devfn), PCI_FUNC(slot->devfn));
|
2005-05-27 14:48:52 -06:00
|
|
|
slot->dev = pci_get_slot(slot->bus, slot->devfn);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Still NULL? Well then scan for it! */
|
2005-05-27 14:48:52 -06:00
|
|
|
if (slot->dev == NULL) {
|
2005-04-16 16:20:36 -06:00
|
|
|
int n;
|
|
|
|
dbg("pci_dev still null");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This will generate pci_dev structures for all functions, but
|
|
|
|
* we will only call this case when lookup fails.
|
|
|
|
*/
|
|
|
|
n = pci_scan_slot(slot->bus, slot->devfn);
|
2008-03-03 20:09:46 -07:00
|
|
|
dbg("%s: pci_scan_slot returned %d", __func__, n);
|
2005-05-27 14:48:52 -06:00
|
|
|
slot->dev = pci_get_slot(slot->bus, slot->devfn);
|
|
|
|
if (slot->dev == NULL) {
|
2005-04-16 16:20:36 -06:00
|
|
|
err("Could not find PCI device for slot %02x", slot->number);
|
2014-01-14 12:03:14 -07:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
2006-08-22 17:55:57 -06:00
|
|
|
parent = slot->dev->bus;
|
|
|
|
|
2017-10-20 14:38:54 -06:00
|
|
|
for_each_pci_bridge(dev, parent) {
|
|
|
|
if (PCI_SLOT(dev->devfn) == PCI_SLOT(slot->devfn))
|
2012-05-17 19:58:41 -06:00
|
|
|
pci_hp_add_bridge(dev);
|
2015-02-25 06:23:22 -07:00
|
|
|
}
|
2013-01-14 20:12:20 -07:00
|
|
|
|
2012-05-17 19:58:41 -06:00
|
|
|
pci_assign_unassigned_bridge_resources(parent->self);
|
|
|
|
|
2006-08-22 17:55:57 -06:00
|
|
|
pci_bus_add_devices(parent);
|
2005-05-09 15:31:50 -06:00
|
|
|
|
2014-01-14 12:03:14 -07:00
|
|
|
out:
|
|
|
|
pci_unlock_rescan_remove();
|
2008-03-03 20:09:46 -07:00
|
|
|
dbg("%s - exit", __func__);
|
2014-01-14 12:03:14 -07:00
|
|
|
return ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2014-04-18 18:13:49 -06:00
|
|
|
int cpci_unconfigure_slot(struct slot *slot)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2013-01-14 20:12:20 -07:00
|
|
|
struct pci_dev *dev, *temp;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-03-03 20:09:46 -07:00
|
|
|
dbg("%s - enter", __func__);
|
2005-05-27 14:48:52 -06:00
|
|
|
if (!slot->dev) {
|
2005-04-16 16:20:36 -06:00
|
|
|
err("No device for slot %02x\n", slot->number);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2014-01-14 12:03:14 -07:00
|
|
|
pci_lock_rescan_remove();
|
|
|
|
|
2013-01-14 20:12:20 -07:00
|
|
|
list_for_each_entry_safe(dev, temp, &slot->bus->devices, bus_list) {
|
|
|
|
if (PCI_SLOT(dev->devfn) != PCI_SLOT(slot->devfn))
|
|
|
|
continue;
|
|
|
|
pci_dev_get(dev);
|
|
|
|
pci_stop_and_remove_bus_device(dev);
|
|
|
|
pci_dev_put(dev);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2005-06-06 13:48:04 -06:00
|
|
|
pci_dev_put(slot->dev);
|
|
|
|
slot->dev = NULL;
|
|
|
|
|
2014-01-14 12:03:14 -07:00
|
|
|
pci_unlock_rescan_remove();
|
|
|
|
|
2008-03-03 20:09:46 -07:00
|
|
|
dbg("%s - exit", __func__);
|
2005-05-09 15:31:50 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|