linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Gavin Shan <gwshan@linux.vnet.ibm.com>
To: linux-pci@vger.kernel.org
Cc: bhelgaas@google.com, linuxppc-dev@lists.ozlabs.org,
	cascardo@linux.vnet.ibm.com,
	Gavin Shan <gwshan@linux.vnet.ibm.com>
Subject: [PATCH 3/4] PCI: Allow registering reset method
Date: Fri, 13 Feb 2015 15:54:58 +1100	[thread overview]
Message-ID: <1423803299-22356-4-git-send-email-gwshan@linux.vnet.ibm.com> (raw)
In-Reply-To: <1423803299-22356-1-git-send-email-gwshan@linux.vnet.ibm.com>

The patch exposes function pci_dev_add_specific_reset() to allow
registering PCI device specific reset methods.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 drivers/pci/quirks.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pci.h  |  9 ++++++++
 2 files changed, 73 insertions(+)

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 37f4c5d..ef811ec 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -3534,6 +3534,70 @@ static struct pci_dev_reset_method pci_dev_reset_methods[] = {
 	}
 };
 
+static bool pci_dev_reset_match(struct pci_dev_reset_method *m,
+				u16 vendor, u16 device,
+				int (*reset)(struct pci_dev *, int))
+{
+	if (m->vendor != (u16)PCI_ANY_ID &&
+	    vendor != (u16)PCI_ANY_ID &&
+	    m->vendor != vendor)
+		return false;
+
+	if (m->device != (u16)PCI_ANY_ID &&
+	    device != (u16)PCI_ANY_ID &&
+	    m->device != device)
+		return false;
+
+	if (m->reset != reset)
+		return false;
+
+	return true;
+}
+
+int pci_dev_add_specific_reset(u16 vendor, u16 device,
+			       int (*reset)(struct pci_dev *, int))
+{
+	struct pci_dev_reset_method *m, *method;
+	int i;
+
+	/* Always expect valid handler */
+	if (!reset)
+		return -EINVAL;
+
+	method = kzalloc(sizeof(*method), GFP_KERNEL);
+	if (!method)
+		return -ENOMEM;
+
+	/* Check if we have conflicting method */
+	mutex_lock(&pci_dev_reset_mutex);
+	if (!pci_dev_reset_populated) {
+		for (i = 0; i < ARRAY_SIZE(pci_dev_reset_methods); i++) {
+			m = &pci_dev_reset_methods[i];
+			if (pci_dev_reset_match(m, vendor, device, reset))
+				goto found;
+		}
+	} else {
+		list_for_each_entry(m, &pci_dev_reset_list, node) {
+			if (pci_dev_reset_match(m, vendor, device, reset))
+				goto found;
+		}
+	}
+
+	/* Populate it */
+	method->vendor = vendor;
+	method->device = device;
+	method->reset  = reset;
+	INIT_LIST_HEAD(&method->node);
+	list_add_tail(&method->node, &pci_dev_reset_list);
+	mutex_unlock(&pci_dev_reset_mutex);
+	return 0;
+found:
+	mutex_unlock(&pci_dev_reset_mutex);
+	kfree(method);
+	return -EEXIST;
+}
+EXPORT_SYMBOL(pci_dev_add_specific_reset);
+
 static void pci_dev_populate_reset(void)
 {
 	struct pci_dev_reset_method *m;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 211e9da..b98be1a 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1605,6 +1605,8 @@ enum pci_fixup_pass {
 
 #ifdef CONFIG_PCI_QUIRKS
 void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
+int pci_dev_add_specific_reset(u16 vendor, u16 device,
+			       int (*reset)(struct pci_dev *, int));
 int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
 void pci_dev_specific_enable_acs(struct pci_dev *dev);
 #else
@@ -1615,6 +1617,13 @@ static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
 {
 	return -ENOTTY;
 }
+
+int pci_dev_add_specific_reset(u16 vendor, u16 device,
+			       int (*reset)(struct pci_dev *, int))
+{
+	return -ENOTTY;
+}
+
 static inline void pci_dev_specific_enable_acs(struct pci_dev *dev) { }
 #endif
 
-- 
1.8.3.2

  parent reply	other threads:[~2015-02-13  4:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-13  4:54 [PATCH 0/4] Support registering specific reset handler Gavin Shan
2015-02-13  4:54 ` [PATCH 1/4] PCI: Rename struct pci_dev_reset_methods Gavin Shan
2015-02-13  4:54 ` [PATCH 2/4] PCI: Introduce list for device reset methods Gavin Shan
2015-02-13  4:54 ` Gavin Shan [this message]
2015-02-13  4:54 ` [PATCH 4/4] powerpc/powernv: Register PCI dev specific reset handlers Gavin Shan
2015-02-16 13:14 ` [PATCH 0/4] Support registering specific reset handler cascardo
2015-02-16 22:36   ` Gavin Shan
2015-02-19 18:57     ` cascardo
2015-02-20  5:53       ` Gavin Shan
2015-03-06 18:38         ` Bjorn Helgaas
2015-03-10  6:31           ` Gavin Shan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1423803299-22356-4-git-send-email-gwshan@linux.vnet.ibm.com \
    --to=gwshan@linux.vnet.ibm.com \
    --cc=bhelgaas@google.com \
    --cc=cascardo@linux.vnet.ibm.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).