* [PATCH v2] bitfield.h: add FIELD_MAX() and field_max() @ 2020-03-06 4:23 Alex Elder 2020-03-10 21:29 ` Nathan Chancellor 0 siblings, 1 reply; 5+ messages in thread From: Alex Elder @ 2020-03-06 4:23 UTC (permalink / raw) To: David Miller, Jakub Kicinski, Al Viro Cc: Johannes Berg, Arnd Bergmann, Masahiro Yamada, Bjorn Andersson, lkml Define FIELD_MAX(), which supplies the maximum value that can be represented by a bitfield. Define field_max() as well, to go along with the lower-case forms of the field mask functions. Signed-off-by: Alex Elder <elder@linaro.org> Acked-by: Jakub Kicinski <kuba@kernel.org> --- v2: Added Acked-by from Jakub. David, I added you to this because it's probably easiest to take this change in through your tree with the rest of the IPA code (which uses field_max(), defined here). -Alex include/linux/bitfield.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 4bbb5f1c8b5b..48ea093ff04c 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -55,6 +55,19 @@ (1ULL << __bf_shf(_mask))); \ }) +/** + * FIELD_MAX() - produce the maximum value representable by a field + * @_mask: shifted mask defining the field's length and position + * + * FIELD_MAX() returns the maximum value that can be held in the field + * specified by @_mask. + */ +#define FIELD_MAX(_mask) \ + ({ \ + __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_MAX: "); \ + (typeof(_mask))((_mask) >> __bf_shf(_mask)); \ + }) + /** * FIELD_FIT() - check if value fits in the field * @_mask: shifted mask defining the field's length and position @@ -110,6 +123,7 @@ static __always_inline u64 field_mask(u64 field) { return field / field_multiplier(field); } +#define field_max(field) ((typeof(field))field_mask(field)) #define ____MAKE_OP(type,base,to,from) \ static __always_inline __##type type##_encode_bits(base v, base field) \ { \ -- 2.20.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] bitfield.h: add FIELD_MAX() and field_max() 2020-03-06 4:23 [PATCH v2] bitfield.h: add FIELD_MAX() and field_max() Alex Elder @ 2020-03-10 21:29 ` Nathan Chancellor 2020-03-10 21:58 ` Jakub Kicinski 0 siblings, 1 reply; 5+ messages in thread From: Nathan Chancellor @ 2020-03-10 21:29 UTC (permalink / raw) To: Alex Elder Cc: David Miller, Jakub Kicinski, Al Viro, Johannes Berg, Arnd Bergmann, Masahiro Yamada, Bjorn Andersson, lkml On Thu, Mar 05, 2020 at 10:23:02PM -0600, Alex Elder wrote: > Define FIELD_MAX(), which supplies the maximum value that can be > represented by a bitfield. Define field_max() as well, to go > along with the lower-case forms of the field mask functions. > > Signed-off-by: Alex Elder <elder@linaro.org> > Acked-by: Jakub Kicinski <kuba@kernel.org> > --- > v2: Added Acked-by from Jakub. > > David, I added you to this because it's probably easiest to take > this change in through your tree with the rest of the IPA code > (which uses field_max(), defined here). > > -Alex > > include/linux/bitfield.h | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h > index 4bbb5f1c8b5b..48ea093ff04c 100644 > --- a/include/linux/bitfield.h > +++ b/include/linux/bitfield.h > @@ -55,6 +55,19 @@ > (1ULL << __bf_shf(_mask))); \ > }) > > +/** > + * FIELD_MAX() - produce the maximum value representable by a field > + * @_mask: shifted mask defining the field's length and position > + * > + * FIELD_MAX() returns the maximum value that can be held in the field > + * specified by @_mask. > + */ > +#define FIELD_MAX(_mask) \ > + ({ \ > + __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_MAX: "); \ > + (typeof(_mask))((_mask) >> __bf_shf(_mask)); \ > + }) > + > /** > * FIELD_FIT() - check if value fits in the field > * @_mask: shifted mask defining the field's length and position > @@ -110,6 +123,7 @@ static __always_inline u64 field_mask(u64 field) > { > return field / field_multiplier(field); > } > +#define field_max(field) ((typeof(field))field_mask(field)) > #define ____MAKE_OP(type,base,to,from) \ > static __always_inline __##type type##_encode_bits(base v, base field) \ > { \ > -- > 2.20.1 > Without this patch, the IPA driver that was picked up a couple of days ago does not build... $ make -j$(nproc) -s ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-gnu- O=out.arm32 distclean allyesconfig drivers/net/ipa/ ../drivers/net/ipa/ipa_cmd.c:182:28: error: implicit declaration of function 'field_max' [-Werror,-Wimplicit-function-declaration] BUILD_BUG_ON(TABLE_SIZE > field_max(IP_FLTRT_FLAGS_HASH_SIZE_FMASK)); ^ ../drivers/net/ipa/ipa_cmd.c:182:28: note: did you mean 'field_mask'? ../include/linux/bitfield.h:109:28: note: 'field_mask' declared here static __always_inline u64 field_mask(u64 field) ^ ../drivers/net/ipa/ipa_cmd.c:183:28: error: implicit declaration of function 'field_max' [-Werror,-Wimplicit-function-declaration] BUILD_BUG_ON(TABLE_SIZE > field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK)); ^ ../drivers/net/ipa/gsi.c:220:39: error: implicit declaration of function 'field_max' [-Werror,-Wimplicit-function-declaration] BUILD_BUG_ON(GSI_RING_ELEMENT_SIZE > field_max(ELEMENT_SIZE_FMASK)); ^ 2 errors generated. ../drivers/net/ipa/gsi.c:220:39: note: did you mean 'field_mask'? ../include/linux/bitfield.h:109:28: note: 'field_mask' declared here static __always_inline u64 field_mask(u64 field) ^ ../drivers/net/ipa/gsi.c:223:39: error: implicit declaration of function 'field_max' [-Werror,-Wimplicit-function-declaration] BUILD_BUG_ON(GSI_RING_ELEMENT_SIZE > field_max(EV_ELEMENT_SIZE_FMASK)); ^ make[5]: *** [../scripts/Makefile.build:267: drivers/net/ipa/ipa_cmd.o] Error 1 make[5]: *** Waiting for unfinished jobs.... ../drivers/net/ipa/gsi.c:710:16: error: implicit declaration of function 'field_max' [-Werror,-Wimplicit-function-declaration] wrr_weight = field_max(WRR_WEIGHT_FMASK); ^ 3 errors generated. make[5]: *** [../scripts/Makefile.build:267: drivers/net/ipa/gsi.o] Error 1 ../drivers/net/ipa/ipa_endpoint.c:584:14: error: implicit declaration of function 'field_max' [-Werror,-Wimplicit-function-declaration] if (scale > field_max(SCALE_FMASK)) ^ ../drivers/net/ipa/ipa_endpoint.c:584:14: note: did you mean 'field_mask'? ../include/linux/bitfield.h:109:28: note: 'field_mask' declared here static __always_inline u64 field_mask(u64 field) ^ ../drivers/net/ipa/ipa_endpoint.c:965:16: error: implicit declaration of function 'field_max' [-Werror,-Wimplicit-function-declaration] return val == field_max(IPA_STATUS_FLAGS1_RT_RULE_ID_FMASK); ^ 2 errors generated. This probably should go through the net-next tree to avoid that build breakage. Cheers, Nathan ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] bitfield.h: add FIELD_MAX() and field_max() 2020-03-10 21:29 ` Nathan Chancellor @ 2020-03-10 21:58 ` Jakub Kicinski 2020-03-11 1:48 ` Alex Elder 0 siblings, 1 reply; 5+ messages in thread From: Jakub Kicinski @ 2020-03-10 21:58 UTC (permalink / raw) To: Nathan Chancellor Cc: Alex Elder, David Miller, Al Viro, Johannes Berg, Arnd Bergmann, Masahiro Yamada, Bjorn Andersson, lkml On Tue, 10 Mar 2020 14:29:38 -0700 Nathan Chancellor wrote: > Without this patch, the IPA driver that was picked up a couple of days > ago does not build... 😳 Yes please, Alex could you repost ASAP with [PATCH net-next] subject and CC netdev to get it into the netdev patchwork? Please also make IPA: depends on (ARCH_QCOM || COMPILE_TEST) && 64BIT && NET Otherwise it's really hard to make sure the code builds. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] bitfield.h: add FIELD_MAX() and field_max() 2020-03-10 21:58 ` Jakub Kicinski @ 2020-03-11 1:48 ` Alex Elder 2020-03-11 2:45 ` Alex Elder 0 siblings, 1 reply; 5+ messages in thread From: Alex Elder @ 2020-03-11 1:48 UTC (permalink / raw) To: Jakub Kicinski, Nathan Chancellor Cc: David Miller, Al Viro, Johannes Berg, Arnd Bergmann, Masahiro Yamada, Bjorn Andersson, lkml On 3/10/20 4:58 PM, Jakub Kicinski wrote: > On Tue, 10 Mar 2020 14:29:38 -0700 Nathan Chancellor wrote: >> Without this patch, the IPA driver that was picked up a couple of days >> ago does not build... > > 😳 > > Yes please, Alex could you repost ASAP with [PATCH net-next] subject > and CC netdev to get it into the netdev patchwork? > > Please also make IPA: > > depends on (ARCH_QCOM || COMPILE_TEST) && 64BIT && NET > > Otherwise it's really hard to make sure the code builds. Sorry all. I have been on vacation the last few days and only now saw this. I will put this together shortly. -Alex ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] bitfield.h: add FIELD_MAX() and field_max() 2020-03-11 1:48 ` Alex Elder @ 2020-03-11 2:45 ` Alex Elder 0 siblings, 0 replies; 5+ messages in thread From: Alex Elder @ 2020-03-11 2:45 UTC (permalink / raw) To: Jakub Kicinski, Nathan Chancellor Cc: David Miller, Al Viro, Johannes Berg, Arnd Bergmann, Masahiro Yamada, Bjorn Andersson, lkml On 3/10/20 8:48 PM, Alex Elder wrote: > On 3/10/20 4:58 PM, Jakub Kicinski wrote: >> On Tue, 10 Mar 2020 14:29:38 -0700 Nathan Chancellor wrote: >>> Without this patch, the IPA driver that was picked up a couple of days >>> ago does not build... >> >> 😳 >> >> Yes please, Alex could you repost ASAP with [PATCH net-next] subject >> and CC netdev to get it into the netdev patchwork? >> >> Please also make IPA: >> >> depends on (ARCH_QCOM || COMPILE_TEST) && 64BIT && NET >> >> Otherwise it's really hard to make sure the code builds. > > Sorry all. I have been on vacation the last few days and only now > saw this. > > I will put this together shortly. I just sent an updated version of the field_max() patch. I will do the COMPILE_TEST change separately (and not today). -Alex > -Alex > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-03-11 2:45 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-03-06 4:23 [PATCH v2] bitfield.h: add FIELD_MAX() and field_max() Alex Elder 2020-03-10 21:29 ` Nathan Chancellor 2020-03-10 21:58 ` Jakub Kicinski 2020-03-11 1:48 ` Alex Elder 2020-03-11 2:45 ` Alex Elder
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).