Linux wireless drivers development
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: Arend Van Spriel <arend.vanspriel@broadcom.com>
Cc: Kalle Valo <kvalo@codeaurora.org>,
	Linux Wireless List <linux-wireless@vger.kernel.org>
Subject: Re: [PATCHv7 4/4] mt7601u: use linux/bitfield.h
Date: Mon, 22 Aug 2016 21:59:34 +0100	[thread overview]
Message-ID: <20160822215934.03d51ba5@jkicinski-Precision-T1700> (raw)
In-Reply-To: <8958bdba-d01d-026c-a018-f2a94bff3e52@broadcom.com>

On Mon, 22 Aug 2016 21:19:41 +0200, Arend Van Spriel wrote:
> On 22-8-2016 12:52, Jakub Kicinski wrote:
> > On Fri, 19 Aug 2016 21:02:02 +0200, Arend Van Spriel wrote:  
> >> On 19-8-2016 18:44, Jakub Kicinski wrote:  
> >>> Use the newly added linux/bitfield.h.
> >>>
> >>> Reviewed-by: Dinan Gunawardena <dinan.gunawardena@netronome.com>
> >>> Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
> >>> ---  
> 
> [snip]
> 
> >>> diff --git a/drivers/net/wireless/mediatek/mt7601u/eeprom.c b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
> >>> index 8d8ee0344f7b..da6faea092d6 100644
> >>> --- a/drivers/net/wireless/mediatek/mt7601u/eeprom.c
> >>> +++ b/drivers/net/wireless/mediatek/mt7601u/eeprom.c
> >>> @@ -45,8 +45,8 @@ mt7601u_efuse_read(struct mt7601u_dev *dev, u16 addr, u8 *data,
> >>>  	val = mt76_rr(dev, MT_EFUSE_CTRL);
> >>>  	val &= ~(MT_EFUSE_CTRL_AIN |
> >>>  		 MT_EFUSE_CTRL_MODE);
> >>> -	val |= MT76_SET(MT_EFUSE_CTRL_AIN, addr & ~0xf) |
> >>> -	       MT76_SET(MT_EFUSE_CTRL_MODE, mode) |
> >>> +	val |= FIELD_PREP(MT_EFUSE_CTRL_AIN, addr & ~0xf) |
> >>> +	       FIELD_PREP(MT_EFUSE_CTRL_MODE, mode) |
> >>>  	       MT_EFUSE_CTRL_KICK;    
> >>
> >> MT_EFUSE_CTRL_KICK is probably a 1-bit field in MT_EFUSE_CTRL register.
> >> It looks like you did not want to go all the way although you do give an
> >> example in bitfield.h, ie. + *  #define REG_FIELD_B  BIT(7).  
> > 
> > True, I just wanted to show in the examples that BIT() is OK to use.
> > My feeling is that ORing in always set flags is acceptable, or at least
> > it was my feeling when I wrote this code ;)  
> 
> I find it tricky to have the user do the field clearing separately.
> Especially if you allow the calling function to pass additional opaque
> "flags". In my experience this is more error prone than anything else
> when dealing with bit fields and as such it is unfortunate this aspect
> is not addressed in your patches.

I don't think anything in this set prevents people from adding a
FIELD_SET() wrapper.  Quite the opposite and I'd encourage it.

> I would rather see:
> 
> 	val = mt76_rr(dev, MT_EFUSE_CTRL);
> 	FIELD_SET(val, MT_EFUSE_CTRL_AIN, addr & ~0xf);
> 	FIELD_SET(val, MT_EFUSE_CTRL_MODE, mode);
> 	FIELD_SET(val, MT_EFUSE_CTRL_KICK, 1);
>  	mt76_wr(dev, MT_EFUSE_CTRL, val);
> 
> in which FIELD_SET takes care of clearing the indicated field.

Yes, I agree this is a good solution as well.  The reason I didn't go
with this approach (apart from modifying an argument of a macro ;)) is
the experience with rt2x00 which followed this design and I wasn't
particularly fond of the resulting code.

I find PREP macro easier to read (less parameters).  It's also
often convenient to not have to zero the variable for pure write
and be able to combine the values in a parameter list:

+	mt7601u_wr(dev, MT_TXOP_CTRL_CFG,
+		   FIELD_PREP(MT_TXOP_TRUN_EN, 0x3f) |
+		   FIELD_PREP(MT_TXOP_EXT_CCA_DLY, 0x58));
or:
+	reg = cpu_to_le32(FIELD_PREP(MT_TXD_INFO_TYPE, DMA_PACKET) |
+			  FIELD_PREP(MT_TXD_INFO_D_PORT, CPU_TX_PORT) |
+			  FIELD_PREP(MT_TXD_INFO_LEN, len));

So each approach has it's advantages and I think they complement each
other.

Please note that I'm just using mt7601u as an example, I really don't
need SET in the new code I'm trying to use these macros for now [1].

[1] https://patchwork.ozlabs.org/patch/628779/

  reply	other threads:[~2016-08-22 20:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19 16:44 [PATCHv7 0/4] register-field manipulation macros Jakub Kicinski
2016-08-19 16:44 ` [PATCHv7 1/4] add basic " Jakub Kicinski
2016-08-19 16:44 ` [PATCHv7 2/4] mt7601u: remove redefinition of GENMASK Jakub Kicinski
2016-08-19 16:44 ` [PATCHv7 3/4] mt7601u: remove unnecessary include Jakub Kicinski
2016-08-19 16:44 ` [PATCHv7 4/4] mt7601u: use linux/bitfield.h Jakub Kicinski
2016-08-19 19:02   ` Arend Van Spriel
2016-08-22 10:52     ` Jakub Kicinski
2016-08-22 19:19       ` Arend Van Spriel
2016-08-22 20:59         ` Jakub Kicinski [this message]
2016-08-31 11:46 ` [PATCHv8 0/4] register-field manipulation macros Jakub Kicinski
2016-08-31 11:46   ` [PATCHv8 1/4] add basic " Jakub Kicinski
2016-09-09  9:11     ` [PATCHv8,1/4] " Kalle Valo
2016-08-31 11:46   ` [PATCHv8 2/4] mt7601u: remove redefinition of GENMASK Jakub Kicinski
2016-08-31 11:46   ` [PATCHv8 3/4] mt7601u: remove unnecessary include Jakub Kicinski
2016-08-31 11:46   ` [PATCHv8 4/4] mt7601u: use linux/bitfield.h Jakub Kicinski
2016-09-03 11:05   ` [PATCHv8 0/4] register-field manipulation macros Kalle Valo

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=20160822215934.03d51ba5@jkicinski-Precision-T1700 \
    --to=jakub.kicinski@netronome.com \
    --cc=arend.vanspriel@broadcom.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-wireless@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