Netdev List
 help / color / mirror / Atom feed
From: Ben Hutchings <bhutchings@solarflare.com>
To: David Miller <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-net-drivers@solarflare.com>
Subject: [PATCH net-next 28/32] sfc: Translate MCDI error numbers received in events
Date: Thu, 22 Aug 2013 14:05:46 +0100	[thread overview]
Message-ID: <1377176746.1703.35.camel@bwh-desktop.uk.level5networks.com> (raw)
In-Reply-To: <1377175392.1703.5.camel@bwh-desktop.uk.level5networks.com>

Currently we only translate error codes in efx_mcdi_poll(), but we
also need to do so in efx_mcdi_ev_cpl().

The reason we didn't notice before is that the MC firmware error codes
are mostly taken from Unix/Linux and no translation is necessary on
most architectures.  Make sure we notice any future failure by
changing the sign of resprc (matching the kernel convention) and BUG
if it's ever positive at command completion.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
 drivers/net/ethernet/sfc/mcdi.c | 62 +++++++++++++++++++++++------------------
 drivers/net/ethernet/sfc/mcdi.h |  4 +--
 2 files changed, 37 insertions(+), 29 deletions(-)

diff --git a/drivers/net/ethernet/sfc/mcdi.c b/drivers/net/ethernet/sfc/mcdi.c
index dffadb2..4f3301d 100644
--- a/drivers/net/ethernet/sfc/mcdi.c
+++ b/drivers/net/ethernet/sfc/mcdi.c
@@ -105,16 +105,39 @@ efx_mcdi_copyout(struct efx_nic *efx, efx_dword_t *outbuf, size_t outlen)
 	efx->type->mcdi_read_response(efx, outbuf, 4, outlen);
 }
 
+static int efx_mcdi_errno(unsigned int mcdi_err)
+{
+	switch (mcdi_err) {
+	case 0:
+		return 0;
+#define TRANSLATE_ERROR(name)					\
+	case MC_CMD_ERR_ ## name:				\
+		return -name;
+	TRANSLATE_ERROR(ENOENT);
+	TRANSLATE_ERROR(EINTR);
+	TRANSLATE_ERROR(EACCES);
+	TRANSLATE_ERROR(EBUSY);
+	TRANSLATE_ERROR(EINVAL);
+	TRANSLATE_ERROR(EDEADLK);
+	TRANSLATE_ERROR(ENOSYS);
+	TRANSLATE_ERROR(ETIME);
+#undef TRANSLATE_ERROR
+	default:
+		return -EIO;
+	}
+}
+
 static int efx_mcdi_poll(struct efx_nic *efx)
 {
 	struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
 	unsigned long time, finish;
 	unsigned int respseq, respcmd, error;
-	unsigned int rc, spins;
+	unsigned int spins;
 	efx_dword_t reg;
+	int rc;
 
 	/* Check for a reboot atomically with respect to efx_mcdi_copyout() */
-	rc = -efx_mcdi_poll_reboot(efx);
+	rc = efx_mcdi_poll_reboot(efx);
 	if (rc)
 		goto out;
 
@@ -151,32 +174,15 @@ static int efx_mcdi_poll(struct efx_nic *efx)
 
 	if (error && mcdi->resplen == 0) {
 		netif_err(efx, hw, efx->net_dev, "MC rebooted\n");
-		rc = EIO;
+		rc = -EIO;
 	} else if ((respseq ^ mcdi->seqno) & SEQ_MASK) {
 		netif_err(efx, hw, efx->net_dev,
 			  "MC response mismatch tx seq 0x%x rx seq 0x%x\n",
 			  respseq, mcdi->seqno);
-		rc = EIO;
+		rc = -EIO;
 	} else if (error) {
 		efx->type->mcdi_read_response(efx, &reg, 4, 4);
-		switch (EFX_DWORD_FIELD(reg, EFX_DWORD_0)) {
-#define TRANSLATE_ERROR(name)					\
-		case MC_CMD_ERR_ ## name:			\
-			rc = name;				\
-			break
-			TRANSLATE_ERROR(ENOENT);
-			TRANSLATE_ERROR(EINTR);
-			TRANSLATE_ERROR(EACCES);
-			TRANSLATE_ERROR(EBUSY);
-			TRANSLATE_ERROR(EINVAL);
-			TRANSLATE_ERROR(EDEADLK);
-			TRANSLATE_ERROR(ENOSYS);
-			TRANSLATE_ERROR(ETIME);
-#undef TRANSLATE_ERROR
-		default:
-			rc = EIO;
-			break;
-		}
+		rc = efx_mcdi_errno(EFX_DWORD_FIELD(reg, EFX_DWORD_0));
 	} else
 		rc = 0;
 
@@ -271,7 +277,7 @@ static void efx_mcdi_release(struct efx_mcdi_iface *mcdi)
 }
 
 static void efx_mcdi_ev_cpl(struct efx_nic *efx, unsigned int seqno,
-			    unsigned int datalen, unsigned int errno)
+			    unsigned int datalen, unsigned int mcdi_err)
 {
 	struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
 	bool wake = false;
@@ -287,7 +293,7 @@ static void efx_mcdi_ev_cpl(struct efx_nic *efx, unsigned int seqno,
 				  "MC response mismatch tx seq 0x%x rx "
 				  "seq 0x%x\n", seqno, mcdi->seqno);
 	} else {
-		mcdi->resprc = errno;
+		mcdi->resprc = efx_mcdi_errno(mcdi_err);
 		mcdi->resplen = datalen;
 
 		wake = true;
@@ -357,10 +363,12 @@ int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen,
 		 * a spurious efx_mcdi_ev_cpl() running concurrently by
 		 * acquiring the iface_lock. */
 		spin_lock_bh(&mcdi->iface_lock);
-		rc = -mcdi->resprc;
+		rc = mcdi->resprc;
 		resplen = mcdi->resplen;
 		spin_unlock_bh(&mcdi->iface_lock);
 
+		BUG_ON(rc > 0);
+
 		if (rc == 0) {
 			efx_mcdi_copyout(efx, outbuf,
 					 min(outlen, mcdi->resplen));
@@ -491,7 +499,7 @@ void efx_mcdi_process_event(struct efx_channel *channel,
 	case MCDI_EVENT_CODE_BADSSERT:
 		netif_err(efx, hw, efx->net_dev,
 			  "MC watchdog or assertion failure at 0x%x\n", data);
-		efx_mcdi_ev_death(efx, EINTR);
+		efx_mcdi_ev_death(efx, -EINTR);
 		break;
 
 	case MCDI_EVENT_CODE_PMNOTICE:
@@ -517,7 +525,7 @@ void efx_mcdi_process_event(struct efx_channel *channel,
 		break;
 	case MCDI_EVENT_CODE_REBOOT:
 		netif_info(efx, hw, efx->net_dev, "MC Reboot\n");
-		efx_mcdi_ev_death(efx, EIO);
+		efx_mcdi_ev_death(efx, -EIO);
 		break;
 	case MCDI_EVENT_CODE_MAC_STATS_DMA:
 		/* MAC stats are gather lazily.  We can ignore this. */
diff --git a/drivers/net/ethernet/sfc/mcdi.h b/drivers/net/ethernet/sfc/mcdi.h
index 0bfed2a..9b536d0 100644
--- a/drivers/net/ethernet/sfc/mcdi.h
+++ b/drivers/net/ethernet/sfc/mcdi.h
@@ -42,7 +42,7 @@ enum efx_mcdi_mode {
  *	Serialised by @lock
  * @credits: Number of spurious MCDI completion events allowed before we
  *	trigger a fatal error. Protected by @lock
- * @resprc: Returned MCDI completion
+ * @resprc: Response error/success code (Linux numbering)
  * @resplen: Returned payload length
  */
 struct efx_mcdi_iface {
@@ -52,7 +52,7 @@ struct efx_mcdi_iface {
 	enum efx_mcdi_mode mode;
 	unsigned int credits;
 	unsigned int seqno;
-	unsigned int resprc;
+	int resprc;
 	size_t resplen;
 };
 


-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

  parent reply	other threads:[~2013-08-22 13:05 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-22 12:43 Pull request: sfc-next 2013-08-22 Ben Hutchings
2013-08-22 12:44 ` [PATCH net-next 01/32] sfc: Fix lookup of default RX MAC filters when steered using ethtool Ben Hutchings
2013-08-22 12:44 ` [PATCH net-next 02/32] sfc: const-qualify source pointers for MMIO write functions Ben Hutchings
2013-08-22 12:45 ` [PATCH net-next 03/32] sfc: Use efx_mcdi_mon() to find efx_mcdi_mon structure from efx_nic Ben Hutchings
2013-08-22 12:45 ` [PATCH net-next 04/32] sfc: Move details of a Falcon bug workaround out of ethtool.c Ben Hutchings
2013-08-22 12:46 ` [PATCH net-next 05/32] sfc: Move more Falcon-specific code and definitions into falcon.c Ben Hutchings
2013-08-22 12:46 ` [PATCH net-next 06/32] sfc: Introduce and use MCDI_DECLARE_BUF macro Ben Hutchings
2013-08-22 12:47 ` [PATCH net-next 07/32] sfc: Rationalise MCDI buffer accessors Ben Hutchings
2013-08-22 12:48 ` [PATCH net-next 08/32] sfc: Fill out the set of MCDI accessors Ben Hutchings
2013-08-22 12:48 ` [PATCH net-next 09/32] sfc: Introduce and use MCDI_CTL_SDU_LEN_MAX_V1 macro for Siena-specific code Ben Hutchings
2013-08-22 12:49 ` [PATCH net-next 10/32] sfc: Use proper macros to declare and access MCDI arrays Ben Hutchings
2013-08-22 12:49 ` [PATCH net-next 11/32] sfc: Ensure MCDI buffers, but not lengths, are dword aligned Ben Hutchings
2013-08-22 12:50 ` [PATCH net-next 12/32] sfc: Add and use MCDI_SET_QWORD() and MCDI_SET_ARRAY_QWORD() Ben Hutchings
2013-08-22 12:50 ` [PATCH net-next 13/32] sfc: Move siena_reset_hw() and siena_map_reset_reason() into MCDI module Ben Hutchings
2013-08-22 12:50 ` [PATCH net-next 14/32] sfc: Move efx_mcdi_mac_reconfigure() to siena.c and rename Ben Hutchings
2013-08-22 12:52 ` [PATCH net-next 15/32] sfc: Collect all MCDI port functions into mcdi_port.c Ben Hutchings
2013-08-22 12:53 ` [PATCH net-next 16/32] sfc: Make efx_mcdi_init() call efx_mcdi_handle_assertion() Ben Hutchings
2013-08-22 12:54 ` [PATCH net-next 17/32] sfc: Make MCDI independent of Siena Ben Hutchings
2013-08-22 12:54 ` [PATCH net-next 18/32] sfc: Add GFP flags to efx_nic_alloc_buffer() and make most callers allow blocking Ben Hutchings
2013-08-22 12:55 ` [PATCH net-next 19/32] sfc: Make struct efx_special_buffer less special Ben Hutchings
2013-08-22 12:55 ` [PATCH net-next 20/32] sfc: Rename Falcon-architecture register definitions Ben Hutchings
2013-08-22 12:56 ` [PATCH net-next 21/32] sfc: Remove efx_process_channel_now() Ben Hutchings
2013-08-22 12:57 ` [PATCH net-next 22/32] sfc: Rework IRQ enable/disable Ben Hutchings
2013-08-22 12:59 ` [PATCH net-next 23/32] sfc: Limit scope of a Falcon A1 IRQ workaround Ben Hutchings
2013-08-22 13:00 ` [PATCH net-next 24/32] sfc: Stop RX refill before flushing RX queues Ben Hutchings
2013-08-22 13:00 ` [PATCH net-next 25/32] sfc: Remove bogus call to efx_release_tx_buffers() Ben Hutchings
2013-08-22 13:02 ` [PATCH net-next 26/32] sfc: Refactor queue teardown sequence to allow for EF10 flush behaviour Ben Hutchings
2013-08-22 13:05 ` [PATCH net-next 27/32] sfc: Move and rename Falcon/Siena common NIC operations Ben Hutchings
2013-08-22 13:05 ` Ben Hutchings [this message]
2013-08-22 13:07 ` [PATCH net-next 29/32] sfc: Update MCDI protocol definitions for EF10 Ben Hutchings
2013-08-22 13:09 ` [PATCH net-next 30/32] sfc: Add support for MCDI v2 Ben Hutchings
2013-08-22 13:10 ` [PATCH net-next 31/32] sfc: Fix race in completion handling Ben Hutchings
2013-08-22 13:10 ` [PATCH net-next 32/32] sfc: Update and improve kernel-doc for efx_mcdi_state & efx_mcdi_iface Ben Hutchings
2013-08-22 19:09 ` Pull request: sfc-next 2013-08-22 David Miller
2013-08-22 19:16   ` Ben Hutchings

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=1377176746.1703.35.camel@bwh-desktop.uk.level5networks.com \
    --to=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=linux-net-drivers@solarflare.com \
    --cc=netdev@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