From: Joe Perches <joe@perches.com>
To: Francois Romieu <romieu@fr.zoreil.com>
Cc: cloud.ren@atheros.com, davem@davemloft.net,
Luis.Rodriguez@atheros.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [patch net-next]alx: Atheros AR8131/AR8151/AR8152/AR8161 Ethernet driver
Date: Fri, 28 Oct 2011 05:56:25 +0300 [thread overview]
Message-ID: <1319770585.2529.21.camel@Joe-Laptop> (raw)
In-Reply-To: <20111019222140.GA9937@electric-eye.fr.zoreil.com>
On Thu, 2011-10-20 at 00:21 +0200, Francois Romieu wrote:
> cloud.ren@atheros.com <cloud.ren@atheros.com> :
> > diff --git a/drivers/net/ethernet/atheros/alx/alf_hw.c b/drivers/net/ethernet/atheros/alx/alf_hw.c
[]
> > + if (en) { /* enable */
> > + MEM_W32(ctx, L1F_RXQ0, rxq | L1F_RXQ0_EN);
> > + MEM_W32(ctx, L1F_TXQ0, txq | L1F_TXQ0_EN);
> > + if (0 != (en_ctrl & LX_MACSPEED_1000)) {
> > + FIELD_SETL(mac, L1F_MAC_CTRL_SPEED,
> > + L1F_MAC_CTRL_SPEED_1000);
> > + } else {
> > + FIELD_SETL(mac, L1F_MAC_CTRL_SPEED,
> > + L1F_MAC_CTRL_SPEED_10_100);
> > + }
> > + if (0 != (en_ctrl & LX_MACDUPLEX_FULL)) {
> > + mac |= L1F_MAC_CTRL_FULLD;
> > + } else {
> > + mac &= ~L1F_MAC_CTRL_FULLD;
> > + }
> > + /* rx filter */
> > + if (0 != (en_ctrl & LX_FLT_PROMISC)) {
> > + mac |= L1F_MAC_CTRL_PROMISC_EN;
> > + } else {
> > + mac &= ~L1F_MAC_CTRL_PROMISC_EN;
> > + }
> > + if (0 != (en_ctrl & LX_FLT_MULTI_ALL)) {
> > + mac |= L1F_MAC_CTRL_MULTIALL_EN;
> > + } else {
> > + mac &= ~L1F_MAC_CTRL_MULTIALL_EN;
> > + }
> > + if (0 != (en_ctrl & LX_FLT_BROADCAST)) {
> > + mac |= L1F_MAC_CTRL_BRD_EN;
> > + } else {
> > + mac &= ~L1F_MAC_CTRL_BRD_EN;
> > + }
> Code duplication. Who cares ?
Maybe add a macro like:
#define mac_ctrl(mac, ctrl, flag, bit) \
do { \
if ((ctrl) & (flag)) \
mac |= (bit); \
else \
mac &= ~(bit); \
} while (0)
so these become
mac_ctrl(mac, en_ctrl, LX_MACDUPLEX_FULL, L1F_MAC_CTRL_FULLD);
mac_ctrl(mac, en_ctrl, LX_FLT_PROMISC, L1F_MAC_CTRL_PROMISC_EN);
mac_ctrl(mac, en_ctrl, LX_FLT_MULTI_ALL, L1F_MAC_CTRL_MULTIALL_EN);
mac_ctrl(mac, en_ctrl, LX_FLT_BROADCAST, L1F_MAC_CTRL_BRD_EN);
mac_ctrl(mac, en_ctrl, LX_FLT_DIRECT, L1F_MAC_CTRL_RX_EN);
mac_ctrl(mac, en_ctrl, LX_FC_TXEN, L1F_MAC_CTRL_TXFC_EN);
mac_ctrl(mac, en_ctrl, LX_FC_RXEN, L1F_MAC_CTRL_RXFC_EN);
etc.
Or maybe add mac, en_ctrl and L1F_MAC_CTRL_ to the macro if you
really want to shorten it up.
mac_ctrl(MACDUPLEX_FULL, FULLD);
mac_ctrl(FLT_PROMISC, PROMISC_EN);
mac_ctrl(FLT_MULTI_ALL, MULTIALL_EN);
etc.
> It may make some sense to move these ~60 loc in a xyz_enable_something
> method...
2 macros?
next prev parent reply other threads:[~2011-10-28 2:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-19 7:26 [patch net-next]alx: Atheros AR8131/AR8151/AR8152/AR8161 Ethernet driver cloud.ren
2011-10-19 7:33 ` David Miller
2011-10-19 7:44 ` Ren, Cloud
2011-10-19 7:50 ` David Miller
2011-10-19 7:53 ` Ren, Cloud
2011-10-19 7:56 ` Joe Perches
2011-10-19 22:21 ` Francois Romieu
2011-10-19 22:59 ` Joe Perches
2011-10-20 7:29 ` Ren, Cloud
2011-10-20 8:48 ` David Miller
2011-10-28 2:56 ` Joe Perches [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-10-20 6:46 cloud.ren
2011-10-20 8:45 ` David Miller
2011-10-20 9:00 ` Joe Perches
2011-10-20 9:23 ` Ren, Cloud
2011-10-20 9:25 ` David Miller
2011-10-20 9:48 ` Ren, Cloud
2011-10-20 20:33 ` Luis R. Rodriguez
2011-10-21 2:21 ` Ren, Cloud
2011-10-21 2:36 ` Luis R. Rodriguez
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=1319770585.2529.21.camel@Joe-Laptop \
--to=joe@perches.com \
--cc=Luis.Rodriguez@atheros.com \
--cc=cloud.ren@atheros.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=romieu@fr.zoreil.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