Re: [PATCH 5/5] PCI: Extend pci_reset_function() to support PCI Advanced Feature

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sheng Yang wrote:
Some PCI device implemented PCI Advanced Feature, which is also support
Function Level Reset(FLR).

Signed-off-by: Sheng Yang <sheng@xxxxxxxxxxxxxxx>
---
 drivers/pci/pci.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index ad89c74..36421ee 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1752,6 +1752,7 @@ EXPORT_SYMBOL(pci_set_dma_seg_boundary);
 #endif
#define PCI_RESET_FUNC_CAP_PCIE_FLR 0
+#define PCI_RESET_FUNC_CAP_PCI_AF_FLR	    1
 static int __pci_check_reset_function_cap(struct pci_dev *dev)
 {
 	int cappos;
@@ -1764,6 +1765,13 @@ static int __pci_check_reset_function_cap(struct pci_dev *dev)
 			return PCI_RESET_FUNC_CAP_PCIE_FLR;
 	}
+ cappos = pci_find_capability(dev, PCI_CAP_ID_AF);
+	if (cappos) {
+		pci_read_config_byte(dev, cappos + PCI_AF_CAP, (u8 *)&cap);
+		if ((cap & PCI_AF_CAP_TP) && (cap & PCI_AF_CAP_FLR))
+			return PCI_RESET_FUNC_CAP_PCI_AF_FLR;
+	}
+
 	return -ENOTTY;
 }

Looks this could be 'if (!cappos) return ...'

@@ -1798,6 +1806,36 @@ static int __pcie_flr(struct pci_dev *dev)
 	return 0;
 }
+static int __pci_af_flr(struct pci_dev *dev)
+{
+	int cappos = pci_find_capability(dev, PCI_CAP_ID_AF);
+	u16 status;
+	u32 cap;
+
+	if (!cappos)
+		return -ENOTTY;
+	pci_read_config_byte(dev, cappos + PCI_AF_CAP, (u8 *)&cap);
+	if (!(cap & PCI_AF_CAP_TP) || !(cap & PCI_AF_CAP_FLR))
+		return -ENOTTY;
+
+	/* Wait for Transaction Pending bit clean */
+	msleep(100);
+	pci_read_config_byte(dev, cappos + PCI_AF_STATUS, (u8 *)&status);
+	if (status & PCI_AF_STATUS_TP) {
+		dev_info(&dev->dev, "Busy after 100ms while trying to"
+				" reset; sleeping for 1 second\n");
+		ssleep(1);
+		pci_read_config_byte(dev,
+				cappos + PCI_AF_STATUS, (u8 *)&status);
+		if (status & PCI_AF_STATUS_TP)
+			dev_info(&dev->dev, "Still busy after 1s; "
+					"proceeding with reset anyway\n");
+	}
+	pci_write_config_byte(dev, cappos + PCI_AF_CTRL, PCI_AF_CTRL_FLR);
+	mdelay(100);
+	return 0;
+}

Looks like the 'status' could be 'u8'?

Thanks,
Yu
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux