linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ley Foon Tan <lftan@altera.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: <linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Ley Foon Tan <lftan@altera.com>, <lftan.linux@gmail.com>
Subject: [PATCH 2/3] PCI: altera: check TLP completion status
Date: Thu, 3 Dec 2015 17:54:48 +0800	[thread overview]
Message-ID: <1449136489-2559-3-git-send-email-lftan@altera.com> (raw)
In-Reply-To: <1449136489-2559-1-git-send-email-lftan@altera.com>

Check TLP packet successful completion status. This fix the issue when
accessing multi-function devices in enumeration process, TLP will return
error when accessing non-exist function number. Returns PCI error code
instead of generic errno.

Tested on Ethernet adapter card with multi-functions.

Signed-off-by: Ley Foon Tan <lftan@altera.com>
---
 drivers/pci/host/pcie-altera.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/host/pcie-altera.c b/drivers/pci/host/pcie-altera.c
index f05180f..e4176b3 100644
--- a/drivers/pci/host/pcie-altera.c
+++ b/drivers/pci/host/pcie-altera.c
@@ -55,6 +55,7 @@
 #define TLP_CFG_DW2(bus, devfn, offset)	\
 				(((bus) << 24) | ((devfn) << 16) | (offset))
 #define TLP_REQ_ID(bus, devfn)		(((bus) << 8) | (devfn))
+#define TLP_COMP_STATUS(s)		(((s) >> 12) & 7)
 #define TLP_HDR_SIZE			3
 #define TLP_LOOP			500
 #define RP_DEVFN			0
@@ -171,6 +172,7 @@ static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
 	bool sop = 0;
 	u32 ctrl;
 	u32 reg0, reg1;
+	u32 comp_status = 1;
 
 	/*
 	 * Minimum 2 loops to read TLP headers and 1 loop to read data
@@ -182,19 +184,25 @@ static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
 			reg0 = cra_readl(pcie, RP_RXCPL_REG0);
 			reg1 = cra_readl(pcie, RP_RXCPL_REG1);
 
-			if (ctrl & RP_RXCPL_SOP)
+			if (ctrl & RP_RXCPL_SOP) {
 				sop = true;
+				comp_status = TLP_COMP_STATUS(reg1);
+			}
 
 			if (ctrl & RP_RXCPL_EOP) {
-				if (value)
-					*value = reg0;
-				return PCIBIOS_SUCCESSFUL;
+				if (!comp_status) {
+					if (value)
+						*value = reg0;
+					return PCIBIOS_SUCCESSFUL;
+				} else {
+					return PCIBIOS_DEVICE_NOT_FOUND;
+				}
 			}
 		}
 		udelay(5);
 	}
 
-	return -ENOENT;
+	return PCIBIOS_DEVICE_NOT_FOUND;
 }
 
 static void tlp_write_packet(struct altera_pcie *pcie, u32 *headers,
-- 
1.8.2.1


  parent reply	other threads:[~2015-12-03  9:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-03  9:54 [PATCH 0/3] fixes to support multi-functions device Ley Foon Tan
2015-12-03  9:54 ` [PATCH 1/3] PCI: altera: fix incorrect devfn for requester ID Ley Foon Tan
2015-12-03  9:54 ` Ley Foon Tan [this message]
2015-12-03  9:54 ` [PATCH 3/3] PCI: altera: fix error when INTX is 4 Ley Foon Tan
2015-12-03 10:48 ` [PATCH 0/3] fixes to support multi-functions device Ley Foon Tan
  -- strict thread matches above, loose matches on Subject: below --
2015-12-03 11:17 Ley Foon Tan
2015-12-03 11:17 ` [PATCH 2/3] PCI: altera: check TLP completion status Ley Foon Tan

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=1449136489-2559-3-git-send-email-lftan@altera.com \
    --to=lftan@altera.com \
    --cc=bhelgaas@google.com \
    --cc=lftan.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.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).