From: "Arend van Spriel" <arend@broadcom.com>
To: gregkh@suse.de
Cc: "Roland Vossen" <rvossen@broadcom.com>,
devel@linuxdriverproject.org, linux-wireless@vger.kernel.org,
"Arend van Spriel" <arend@broadcom.com>
Subject: [PATCH 12/29] staging: brcm80211: simplified register access macro's in softmac
Date: Fri, 22 Jul 2011 20:56:59 +0200 [thread overview]
Message-ID: <1311361036-3175-13-git-send-email-arend@broadcom.com> (raw)
In-Reply-To: <1311361036-3175-1-git-send-email-arend@broadcom.com>
From: Roland Vossen <rvossen@broadcom.com>
Code cleanup. Removed MIPS specific 'sync' instruction since this is not
required for the chips that this driver supports. MIPS specific macro's
were now the same as non-MIPS register access macro's and thus have been
deleted. Also added comment that makes clearer what the benefit of these
macro's is. Unified big and little end register access macro's.
Cc: devel@linuxdriverproject.org
Cc: linux-wireless@vger.kernel.org
Reported-by: Dan Carpenter <error27@gmail.com>
Reported-by: Julian Calaby <julian.calaby@gmail.com>
Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
---
drivers/staging/brcm80211/brcmsmac/types.h | 81 ++++++++++------------------
1 files changed, 29 insertions(+), 52 deletions(-)
diff --git a/drivers/staging/brcm80211/brcmsmac/types.h b/drivers/staging/brcm80211/brcmsmac/types.h
index fcfa2ca..7c07cfd 100644
--- a/drivers/staging/brcm80211/brcmsmac/types.h
+++ b/drivers/staging/brcm80211/brcmsmac/types.h
@@ -319,60 +319,38 @@ do { \
#define WL_ERROR_ON() (brcm_msg_level & LOG_ERROR_VAL)
-/* register access macros */
+/*
+ * Register access macros.
+ *
+ * These macro's take a pointer to the address to read as one of their
+ * arguments. The macro itself deduces the size of the IO transaction (u8, u16
+ * or u32). Advantage of this approach in combination with using a struct to
+ * define the registers in a register block, is that access size and access
+ * location are defined in only one spot. This reduces the risk of the
+ * programmer trying to use an unsupported transaction size on a register.
+ *
+ * For big endian operation, a byte swap has to be done. Eg, when attempting
+ * to read byte address 0, byte 3 should be read. This is accomplished
+ * using an xor ('^') operator.
+ */
+
#ifndef __BIG_ENDIAN
-#ifndef __mips__
-#define R_REG(r) \
- ({\
- sizeof(*(r)) == sizeof(u8) ? \
- readb((u8 *)(r)) : \
- sizeof(*(r)) == sizeof(u16) ? readw((u16 *)(r)) : \
- readl((u32 *)(r)); \
- })
-#else /* __mips__ */
-#define R_REG(r) \
- ({ \
- __typeof(*(r)) __osl_v; \
- __asm__ __volatile__("sync"); \
- switch (sizeof(*(r))) { \
- case sizeof(u8): \
- __osl_v = readb((u8 *)(r)); \
- break; \
- case sizeof(u16): \
- __osl_v = readw((u16 *)(r)); \
- break; \
- case sizeof(u32): \
- __osl_v = \
- readl((u32 *)(r)); \
- break; \
- } \
- __asm__ __volatile__("sync"); \
- __osl_v; \
- })
-#endif /* __mips__ */
+#define SWP2(r) (r)
+#define SWP3(r) (r)
+#else
+#define SWP2(r) ((unsigned long)(r)^2)
+#define SWP3(r) ((unsigned long)(r)^3)
+#endif /* __BIG_ENDIAN */
-#define W_REG(r, v) do { \
- switch (sizeof(*(r))) { \
- case sizeof(u8): \
- writeb((u8)(v), (u8 *)(r)); break; \
- case sizeof(u16): \
- writew((u16)(v), (u16 *)(r)); break; \
- case sizeof(u32): \
- writel((u32)(v), (u32 *)(r)); break; \
- }; \
- } while (0)
-#else /* __BIG_ENDIAN */
#define R_REG(r) \
({ \
__typeof(*(r)) __osl_v; \
switch (sizeof(*(r))) { \
case sizeof(u8): \
- __osl_v = \
- readb((u8 *)((unsigned long)(r)^3)); \
+ __osl_v = readb((u8 *)(SWP3(r))); \
break; \
case sizeof(u16): \
- __osl_v = \
- readw((u16 *)((unsigned long)(r)^2)); \
+ __osl_v = readw((u16 *)(SWP2(r))); \
break; \
case sizeof(u32): \
__osl_v = readl((u32 *)(r)); \
@@ -384,17 +362,16 @@ do { \
#define W_REG(r, v) do { \
switch (sizeof(*(r))) { \
case sizeof(u8): \
- writeb((u8)(v), \
- (u8 *)((unsigned long)(r)^3)); break; \
+ writeb((u8)(v), (u8 *)(SWP3(r))); \
+ break; \
case sizeof(u16): \
- writew((u16)(v), \
- (u16 *)((unsigned long)(r)^2)); break; \
+ writew((u16)(v), (u16 *)(SWP2(r))); \
+ break; \
case sizeof(u32): \
- writel((u32)(v), \
- (u32 *)(r)); break; \
+ writel((u32)(v), (u32 *)(r)); \
+ break; \
} \
} while (0)
-#endif /* __BIG_ENDIAN */
#ifdef __mips__
/*
--
1.7.4.1
next prev parent reply other threads:[~2011-07-22 18:57 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-22 18:56 [PATCH 00/29] staging: brcm80211: cleanup checkpatch warnings Arend van Spriel
2011-07-22 18:56 ` [PATCH 01/29] staging: brcm80211: fixed checkpatch warnings for fullmac Arend van Spriel
2011-07-22 18:56 ` [PATCH 02/29] staging: brcm80211: fixed checkpatch warnings for brcmutil dir Arend van Spriel
2011-07-22 18:56 ` [PATCH 03/29] staging: brcm80211: fixed checkpatch warnings for 'include' dir Arend van Spriel
2011-07-22 18:56 ` [PATCH 04/29] staging: brcm80211: use PCI_DEVICE() macro in device table Arend van Spriel
2011-07-22 18:56 ` [PATCH 05/29] staging: brcm80211: remove unused rx status definitions Arend van Spriel
2011-07-22 18:56 ` [PATCH 06/29] staging: brcm80211: reformat long lines in brcmsmac to 80 columns Arend van Spriel
2011-07-22 18:56 ` [PATCH 07/29] staging: brcm80211: remove wl_alloc_dma_resources() function Arend van Spriel
2011-07-22 18:56 ` [PATCH 09/29] staging: brcm80211: remove code for unsupported chip Arend van Spriel
2011-07-26 8:12 ` Dan Carpenter
2011-07-22 18:56 ` [PATCH 10/29] staging: brcm80211: cleaned up softmac DMA layer Arend van Spriel
2011-07-22 18:56 ` [PATCH 11/29] staging: brcm80211: removed void * from softmac phy Arend van Spriel
2011-07-22 18:56 ` Arend van Spriel [this message]
2011-07-22 18:57 ` [PATCH 13/29] staging: brcm80211: revisited END_FOREACH_BSS macro Arend van Spriel
2011-07-26 8:26 ` Dan Carpenter
2011-07-26 16:34 ` Joe Perches
2011-07-22 18:57 ` [PATCH 14/29] staging: brcm80211: placed suspend flag in gInstance in brcmfmac Arend van Spriel
2011-07-22 18:57 ` [PATCH 15/29] staging: brcm80211: remove struct brcmf_sdioh_driver from brcmfmac Arend van Spriel
2011-07-22 18:57 ` [PATCH 16/29] staging: brcm80211: remove vendor and device id check " Arend van Spriel
2011-07-22 18:57 ` [PATCH 17/29] staging: brcm80211: remove struct brcmf_sdio_card " Arend van Spriel
2011-07-22 18:57 ` [PATCH 18/29] staging: brcm80211: remove dead code " Arend van Spriel
2011-07-22 18:57 ` [PATCH 19/29] staging: brcm80211: remove dead client interrupt " Arend van Spriel
2011-07-22 18:57 ` [PATCH 20/29] staging: brcm80211: remove function pointer of interrupt isr in brcmfmac Arend van Spriel
2011-07-22 18:57 ` [PATCH 21/29] staging: brcm80211: cleanup to get rid of 'over 80 character' line Arend van Spriel
2011-07-22 18:57 ` [PATCH 22/29] staging: brcm80211: removed unused bus code from softmac Arend van Spriel
2011-07-22 18:57 ` [PATCH 23/29] staging: brcm80211: replaced void *btparam into struct pci_dev *btparam Arend van Spriel
2011-07-22 18:57 ` [PATCH 24/29] staging: brcm80211: removed void * from ai_ functions Arend van Spriel
2011-07-22 18:57 ` [PATCH 25/29] staging: brcm80211: removed brcms_c_module_unregister() call in ampdu.c Arend van Spriel
2011-07-22 18:57 ` [PATCH 26/29] staging: brcm80211: removed watchdog function from softmac Arend van Spriel
2011-07-22 18:57 ` [PATCH 27/29] staging: brcm80211: SPARC build error fix Arend van Spriel
2011-07-22 18:57 ` [PATCH 28/29] staging: brcm80211: remove target platform limitations for drivers Arend van Spriel
2011-07-22 18:57 ` [PATCH 29/29] staging: brcm80211: updated TODO file Arend van Spriel
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=1311361036-3175-13-git-send-email-arend@broadcom.com \
--to=arend@broadcom.com \
--cc=devel@linuxdriverproject.org \
--cc=gregkh@suse.de \
--cc=linux-wireless@vger.kernel.org \
--cc=rvossen@broadcom.com \
/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).