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 RESEND net-next 08/16] sfc: Fill out the set of MCDI accessors
Date: Thu, 22 Aug 2013 20:27:27 +0100	[thread overview]
Message-ID: <1377199647.1703.57.camel@bwh-desktop.uk.level5networks.com> (raw)
In-Reply-To: <1377199326.1703.49.camel@bwh-desktop.uk.level5networks.com>

We need to access arrays of 16-bit words and 32-bit dwords in MCDI
buffers based on the MCDI protocol definitions.

We should also be able to read and write fields within structures,
without specifying an array index each time.  So add MCDI_FIELD()
and make MCDI_ARRAY_FIELD() use it.  Also add MCDI_SET_FIELD().

Split MCDI_ARRAY_PTR() into MCDI_ARRAY_STRUCT_PTR() and
_MCDI_ARRAY_PTR(), which are currently identical but will diverge in
later changes.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
 drivers/net/ethernet/sfc/mcdi.h | 42 +++++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/sfc/mcdi.h b/drivers/net/ethernet/sfc/mcdi.h
index 03fb6c0..969ecc0 100644
--- a/drivers/net/ethernet/sfc/mcdi.h
+++ b/drivers/net/ethernet/sfc/mcdi.h
@@ -87,8 +87,10 @@ extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
 
 #define MCDI_DECLARE_BUF(_name, _len)					\
 	u8 _name[ALIGN(_len, 4)]
+#define _MCDI_PTR(_buf, _offset)					\
+	((u8 *)(_buf) + (_offset))
 #define MCDI_PTR(_buf, _field)						\
-	((u8 *)(_buf) + MC_CMD_ ## _field ## _OFST)
+	_MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST)
 #define _MCDI_DWORD(_buf, _field)					\
 	((efx_dword_t *)MCDI_PTR(_buf, _field))
 
@@ -102,18 +104,38 @@ extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
 #define MCDI_QWORD(_buf, _field)					\
 	(EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) |	\
 	(u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32)
+#define MCDI_FIELD(_ptr, _type, _field)					\
+	EFX_EXTRACT_DWORD(						\
+		*(efx_dword_t *)					\
+		_MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\
+		MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f,	\
+		(MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) +	\
+		MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1)
 
-#define MCDI_ARRAY_PTR(_buf, _field, _type, _index)			\
+#define _MCDI_ARRAY_PTR(_buf, _field, _index)				\
 	(MCDI_PTR(_buf, _field) +					\
-	 (_index) * MC_CMD_ ## _type ## _TYPEDEF_LEN)
+	 (_index) * MC_CMD_ ## _field ## _LEN)
+#define MCDI_DECLARE_STRUCT_PTR(_name)					\
+	u8 *_name
+#define MCDI_ARRAY_STRUCT_PTR _MCDI_ARRAY_PTR
+#define MCDI_VAR_ARRAY_LEN(_len, _field)				\
+	min_t(size_t, MC_CMD_ ## _field ## _MAXNUM,			\
+	      ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN)
+#define MCDI_ARRAY_WORD(_buf, _field, _index)				\
+	(BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) +		\
+	 le16_to_cpu(*(__force const __le16 *)				\
+		     _MCDI_ARRAY_PTR(_buf, _field, _index)))
+#define _MCDI_ARRAY_DWORD(_buf, _field, _index)				\
+	(BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) +		\
+	 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index))
+#define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value)		\
+	EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index),	\
+			    EFX_DWORD_0, _value)
+#define MCDI_ARRAY_DWORD(_buf, _field, _index)				\
+	EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0)
 #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2)		\
-	EFX_EXTRACT_DWORD(						\
-		*((efx_dword_t *)					\
-		  (MCDI_ARRAY_PTR(_buf, _field1, _type, _index) +	\
-		   (MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _OFST & ~3))), \
-		MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _LBN & 0x1f, \
-		(MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _LBN & 0x1f) + \
-		MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _WIDTH - 1)
+	MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index),	\
+		   _type ## _TYPEDEF, _field2)
 
 #define MCDI_EVENT_FIELD(_ev, _field)			\
 	EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)


-- 
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 19:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-22 19:22 Pull request: sfc-next 2013-08-22 v2 Ben Hutchings
2013-08-22 19:25 ` [PATCH RESEND net-next 01/16] sfc: Fix lookup of default RX MAC filters when steered using ethtool Ben Hutchings
2013-08-22 19:25 ` [PATCH RESEND net-next 02/16] sfc: const-qualify source pointers for MMIO write functions Ben Hutchings
2013-08-22 19:25 ` [PATCH RESEND net-next 03/16] sfc: Use efx_mcdi_mon() to find efx_mcdi_mon structure from efx_nic Ben Hutchings
2013-08-22 19:26 ` [PATCH RESEND net-next 04/16] sfc: Move details of a Falcon bug workaround out of ethtool.c Ben Hutchings
2013-08-22 19:26 ` [PATCH RESEND net-next 05/16] sfc: Move more Falcon-specific code and definitions into falcon.c Ben Hutchings
2013-08-22 19:26 ` [PATCH RESEND net-next 06/16] sfc: Introduce and use MCDI_DECLARE_BUF macro Ben Hutchings
2013-08-23  5:02   ` David Miller
2013-08-23 10:26     ` Ben Hutchings
2013-08-23 15:52       ` Ben Hutchings
2013-08-23 18:00       ` David Miller
2013-08-22 19:27 ` [PATCH RESEND net-next 07/16] sfc: Rationalise MCDI buffer accessors Ben Hutchings
2013-08-22 19:27 ` Ben Hutchings [this message]
2013-08-22 19:27 ` [PATCH RESEND net-next 09/16] sfc: Introduce and use MCDI_CTL_SDU_LEN_MAX_V1 macro for Siena-specific code Ben Hutchings
2013-08-22 19:28 ` [PATCH RESEND net-next 10/16] sfc: Use proper macros to declare and access MCDI arrays Ben Hutchings
2013-08-22 19:28 ` [PATCH RESEND net-next 11/16] sfc: Ensure MCDI buffers, but not lengths, are dword aligned Ben Hutchings
2013-08-22 19:28 ` [PATCH RESEND net-next 12/16] sfc: Add and use MCDI_SET_QWORD() and MCDI_SET_ARRAY_QWORD() Ben Hutchings
2013-08-22 19:29 ` [PATCH RESEND net-next 13/16] sfc: Move siena_reset_hw() and siena_map_reset_reason() into MCDI module Ben Hutchings
2013-08-22 19:29 ` [PATCH RESEND net-next 14/16] sfc: Move efx_mcdi_mac_reconfigure() to siena.c and rename Ben Hutchings
2013-08-22 19:29 ` [PATCH RESEND net-next 15/16] sfc: Collect all MCDI port functions into mcdi_port.c Ben Hutchings
2013-08-22 19:30 ` [PATCH RESEND net-next 16/16] sfc: Make efx_mcdi_init() call efx_mcdi_handle_assertion() 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=1377199647.1703.57.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