From: Matthias Kaehlcke <mka@chromium.org>
To: Jakub Kicinski <jakub.kicinski@netronome.com>
Cc: Manoj Gupta <manojgupta@chromium.org>,
"David S . Miller" <davem@davemloft.net>,
Simon Horman <simon.horman@netronome.com>,
Dirk van der Merwe <dirk.vandermerwe@netronome.com>,
oss-drivers@netronome.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Renato Golin <renato.golin@linaro.org>,
Guenter Roeck <groeck@chromium.org>,
Doug Anderson <dianders@chromium.org>
Subject: Re: [PATCH] nfp: convert nfp_eth_set_bit_config() into a macro
Date: Tue, 24 Oct 2017 09:56:03 -0700 [thread overview]
Message-ID: <20171024165603.GA96615@google.com> (raw)
In-Reply-To: <20171004111724.29a4d7ff@cakuba.netronome.com>
Hi Jakub,
El Wed, Oct 04, 2017 at 11:17:24AM -0700 Jakub Kicinski ha dit:
> On Wed, 4 Oct 2017 10:42:42 -0700, Manoj Gupta wrote:
> > Hi Jakub,
> >
> > I had discussed about supporting this code with some clang developers.
> > However, the consensus was this code relies on a specific GCC optimizer
> > behavior and Clang does not share the same behavior by design.
>
> Hm. I find surprising that constant propagation to inlined functions
> is considered something GCC-specific rather than obvious/basic.
>
> > Note that even GCC can't compile this code at -O0.
>
> Yes, that makes me feel uncomfortable... Could you try this?
>
> -------8<-------
>
> diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c
> index f6f7c085f8e0..47251396fcae 100644
> --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c
> +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp_eth.c
> @@ -469,10 +469,10 @@ int nfp_eth_set_configured(struct nfp_cpp *cpp, unsigned int idx, bool configed)
> return nfp_eth_config_commit_end(nsp);
> }
>
> -/* Force inline, FIELD_* macroes require masks to be compilation-time known */
> -static __always_inline int
> +static int
> nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx,
> - const u64 mask, unsigned int val, const u64 ctrl_bit)
> + const u64 mask, const unsigned int shift,
> + unsigned int val, const u64 ctrl_bit)
> {
> union eth_table_entry *entries = nfp_nsp_config_entries(nsp);
> unsigned int idx = nfp_nsp_config_idx(nsp);
> @@ -489,11 +489,11 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx,
>
> /* Check if we are already in requested state */
> reg = le64_to_cpu(entries[idx].raw[raw_idx]);
> - if (val == FIELD_GET(mask, reg))
> + if (val == (reg & mask) >> shift)
> return 0;
>
> reg &= ~mask;
> - reg |= FIELD_PREP(mask, val);
> + reg |= (val << shift) & mask;
> entries[idx].raw[raw_idx] = cpu_to_le64(reg);
>
> entries[idx].control |= cpu_to_le64(ctrl_bit);
> @@ -503,6 +503,13 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx,
> return 0;
> }
>
> +#define NFP_ETH_SET_BIT_CONFIG(nsp, raw_idx, mask, val, ctrl_bit) \
> + ({ \
> + __BF_FIELD_CHECK(mask, 0ULL, val, "NFP_ETH_SET_BIT_CONFIG: "); \
> + nfp_eth_set_bit_config(nsp, raw_idx, mask, __bf_shf(mask), \
> + val, ctrl_bit); \
> + })
> +
> /**
> * __nfp_eth_set_aneg() - set PHY autonegotiation control bit
> * @nsp: NFP NSP handle returned from nfp_eth_config_start()
> @@ -515,7 +522,7 @@ nfp_eth_set_bit_config(struct nfp_nsp *nsp, unsigned int raw_idx,
> */
> int __nfp_eth_set_aneg(struct nfp_nsp *nsp, enum nfp_eth_aneg mode)
> {
> - return nfp_eth_set_bit_config(nsp, NSP_ETH_RAW_STATE,
> + return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE,
> NSP_ETH_STATE_ANEG, mode,
> NSP_ETH_CTRL_SET_ANEG);
> }
> @@ -544,7 +551,7 @@ int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed)
> return -EINVAL;
> }
>
> - return nfp_eth_set_bit_config(nsp, NSP_ETH_RAW_STATE,
> + return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE,
> NSP_ETH_STATE_RATE, rate,
> NSP_ETH_CTRL_SET_RATE);
> }
> @@ -561,6 +568,6 @@ int __nfp_eth_set_speed(struct nfp_nsp *nsp, unsigned int speed)
> */
> int __nfp_eth_set_split(struct nfp_nsp *nsp, unsigned int lanes)
> {
> - return nfp_eth_set_bit_config(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES,
> + return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_PORT, NSP_ETH_PORT_LANES,
> lanes, NSP_ETH_CTRL_SET_LANES);
> }
Do you plan to send this as an official patch?
Thanks
Matthias
next prev parent reply other threads:[~2017-10-24 16:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-03 20:05 [PATCH] nfp: convert nfp_eth_set_bit_config() into a macro Matthias Kaehlcke
2017-10-03 21:50 ` Jakub Kicinski
2017-10-04 17:42 ` Matthias Kaehlcke
2017-10-04 17:44 ` David Miller
[not found] ` <CAAMbb05G=HBQweiWqYva_9zTnQqAcwMhJ0yYBUi26T04YA4CxQ@mail.gmail.com>
2017-10-04 18:17 ` Jakub Kicinski
2017-10-04 18:44 ` Matthias Kaehlcke
2017-10-24 16:56 ` Matthias Kaehlcke [this message]
2017-10-24 17:03 ` Jakub Kicinski
2017-10-24 17:13 ` Matthias Kaehlcke
2017-10-04 18:07 ` Joe Perches
2017-10-04 18:49 ` Matthias Kaehlcke
2017-10-04 22:22 ` Jakub Kicinski
2017-10-04 23:16 ` Matthias Kaehlcke
2017-10-04 23:25 ` Jakub Kicinski
2017-10-05 0:38 ` Manoj Gupta
2017-10-05 0:56 ` Jakub Kicinski
2017-10-05 1:50 ` Manoj Gupta
2017-10-05 2:06 ` Jakub Kicinski
2017-10-05 2:13 ` Manoj Gupta
2017-10-09 17:29 ` Matthias Kaehlcke
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=20171024165603.GA96615@google.com \
--to=mka@chromium.org \
--cc=davem@davemloft.net \
--cc=dianders@chromium.org \
--cc=dirk.vandermerwe@netronome.com \
--cc=groeck@chromium.org \
--cc=jakub.kicinski@netronome.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manojgupta@chromium.org \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.com \
--cc=renato.golin@linaro.org \
--cc=simon.horman@netronome.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.