* [PATCH 1/9] bitmap: add bitmap_and_and() and bitmap_and_andnot()
2026-09-07 21:54 [PATCH 0/9] linkmode: better use bitmap API Yury Norov
@ 2026-09-07 21:54 ` Yury Norov
2026-09-07 21:54 ` [PATCH 2/9] linkmode: make linkmode_and() return boolean Yury Norov
` (7 subsequent siblings)
8 siblings, 0 replies; 24+ messages in thread
From: Yury Norov @ 2026-09-07 21:54 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, Andrew Morton
Add bitmap_and_and() and bitmap_and_andnot() to combine three bitmaps
in a single pass. Both helpers return whether the resulting bitmap is
non-empty.
Introduce BITMAP_OP() to share the word iteration with bitmap_and(),
and add tests for small constants, multiword bitmaps, aliases, tail
masking, empty results and zero-sized bitmaps.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
include/linux/bitmap.h | 32 +++++++++++++++++
lib/bitmap.c | 46 +++++++++++++++++++------
lib/test_bitmap.c | 78 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 146 insertions(+), 10 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 7df1573a409c..d524ef6b0300 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -44,6 +44,10 @@ struct device;
* bitmap_fill(dst, nbits) *dst = ~0UL
* bitmap_copy(dst, src, nbits) *dst = *src
* bitmap_and(dst, src1, src2, nbits) *dst = *src1 & *src2
+ * bitmap_and_and(dst, src1, src2, src3, nbits)
+ * *dst = *src1 & *src2 & *src3
+ * bitmap_and_andnot(dst, src1, src2, src3, nbits)
+ * *dst = *src1 & *src2 & ~(*src3)
* bitmap_or(dst, src1, src2, nbits) *dst = *src1 | *src2
* bitmap_weighted_or(dst, src1, src2, nbits) *dst = *src1 | *src2. Returns Hamming Weight of dst
* bitmap_weighted_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2. Returns Hamming Weight of dst
@@ -166,6 +170,12 @@ void bitmap_cut(unsigned long *dst, const unsigned long *src,
unsigned int first, unsigned int cut, unsigned int nbits);
bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
+bool __bitmap_and_and(unsigned long *dst, const unsigned long *bitmap1,
+ const unsigned long *bitmap2,
+ const unsigned long *bitmap3, unsigned int nbits);
+bool __bitmap_and_andnot(unsigned long *dst, const unsigned long *bitmap1,
+ const unsigned long *bitmap2,
+ const unsigned long *bitmap3, unsigned int nbits);
void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int nbits);
unsigned int __bitmap_weighted_or(unsigned long *dst, const unsigned long *bitmap1,
@@ -337,6 +347,28 @@ bool bitmap_and(unsigned long *dst, const unsigned long *src1,
return __bitmap_and(dst, src1, src2, nbits);
}
+static __always_inline
+bool bitmap_and_and(unsigned long *dst, const unsigned long *src1,
+ const unsigned long *src2, const unsigned long *src3,
+ unsigned int nbits)
+{
+ if (small_const_nbits(nbits))
+ return (*dst = *src1 & *src2 & *src3 &
+ BITMAP_LAST_WORD_MASK(nbits)) != 0;
+ return __bitmap_and_and(dst, src1, src2, src3, nbits);
+}
+
+static __always_inline
+bool bitmap_and_andnot(unsigned long *dst, const unsigned long *src1,
+ const unsigned long *src2, const unsigned long *src3,
+ unsigned int nbits)
+{
+ if (small_const_nbits(nbits))
+ return (*dst = *src1 & *src2 & ~(*src3) &
+ BITMAP_LAST_WORD_MASK(nbits)) != 0;
+ return __bitmap_and_andnot(dst, src1, src2, src3, nbits);
+}
+
static __always_inline
void bitmap_or(unsigned long *dst, const unsigned long *src1,
const unsigned long *src2, unsigned int nbits)
diff --git a/lib/bitmap.c b/lib/bitmap.c
index ed685127a107..85ce3cbaa9ab 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -34,6 +34,25 @@
* for the best explanations of this ordering.
*/
+/*
+ * Common helper for bitmap operations.
+ * @FETCH: The expression that fetches and combines each word of the bitmaps
+ * @bits: The bitmap size in bits
+ */
+#define BITMAP_OP(FETCH, bits) \
+({ \
+ unsigned long idx, val, sz = (bits), result = 0; \
+ \
+ for (idx = 0; idx * BITS_PER_LONG < sz; idx++) { \
+ val = (FETCH); \
+ if (sz - idx * BITS_PER_LONG < BITS_PER_LONG) \
+ val &= BITMAP_LAST_WORD_MASK(sz); \
+ result |= (dst[idx] = val); \
+ } \
+ \
+ result != 0; \
+})
+
bool __bitmap_equal(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
{
@@ -230,19 +249,26 @@ EXPORT_SYMBOL(bitmap_cut);
bool __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
{
- unsigned int k;
- unsigned int lim = bits/BITS_PER_LONG;
- unsigned long result = 0;
-
- for (k = 0; k < lim; k++)
- result |= (dst[k] = bitmap1[k] & bitmap2[k]);
- if (bits % BITS_PER_LONG)
- result |= (dst[k] = bitmap1[k] & bitmap2[k] &
- BITMAP_LAST_WORD_MASK(bits));
- return result != 0;
+ return BITMAP_OP(bitmap1[idx] & bitmap2[idx], bits);
}
EXPORT_SYMBOL(__bitmap_and);
+bool __bitmap_and_and(unsigned long *dst, const unsigned long *bitmap1,
+ const unsigned long *bitmap2,
+ const unsigned long *bitmap3, unsigned int bits)
+{
+ return BITMAP_OP(bitmap1[idx] & bitmap2[idx] & bitmap3[idx], bits);
+}
+EXPORT_SYMBOL(__bitmap_and_and);
+
+bool __bitmap_and_andnot(unsigned long *dst, const unsigned long *bitmap1,
+ const unsigned long *bitmap2,
+ const unsigned long *bitmap3, unsigned int bits)
+{
+ return BITMAP_OP(bitmap1[idx] & bitmap2[idx] & ~bitmap3[idx], bits);
+}
+EXPORT_SYMBOL(__bitmap_and_andnot);
+
void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
{
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 56bd23059b26..fbc46ed960a4 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -193,6 +193,81 @@ static void __init test_zero_clear(void)
expect_eq_pbl("", bmap, 1024);
}
+static void __init test_bitmap_and(void)
+{
+ enum { nbits = BITS_PER_LONG + 13 };
+ DECLARE_BITMAP(src1, nbits);
+ DECLARE_BITMAP(src2, nbits);
+ DECLARE_BITMAP(src3, nbits);
+ DECLARE_BITMAP(dst, nbits);
+ DECLARE_BITMAP(expected, nbits);
+ unsigned long small_src1 = ~0UL;
+ unsigned long small_src2 = ~0UL;
+ unsigned long small_src3 = BIT(2);
+ unsigned long small_dst;
+ bool ret;
+
+ ret = bitmap_and_and(&small_dst, &small_src1, &small_src2,
+ &small_src3, 4);
+ expect_eq_ulong(true, ret);
+ expect_eq_ulong(BIT(2), small_dst);
+
+ ret = bitmap_and_andnot(&small_dst, &small_src1, &small_src2,
+ &small_src3, 4);
+ expect_eq_ulong(true, ret);
+ expect_eq_ulong(GENMASK(3, 0) & ~BIT(2), small_dst);
+
+ bitmap_zero(src1, nbits);
+ bitmap_zero(src2, nbits);
+ bitmap_zero(src3, nbits);
+ bitmap_zero(expected, nbits);
+ __set_bit(1, src1);
+ __set_bit(2, src1);
+ __set_bit(BITS_PER_LONG + 1, src1);
+ __set_bit(BITS_PER_LONG + 12, src1);
+ __set_bit(BITS_PER_LONG + 13, src1);
+ __set_bit(1, src2);
+ __set_bit(BITS_PER_LONG + 1, src2);
+ __set_bit(BITS_PER_LONG + 12, src2);
+ __set_bit(BITS_PER_LONG + 13, src2);
+ __set_bit(BITS_PER_LONG + 1, src3);
+ __set_bit(1, expected);
+ __set_bit(BITS_PER_LONG + 1, expected);
+ __set_bit(BITS_PER_LONG + 12, expected);
+
+ ret = bitmap_and(dst, src1, src2, nbits);
+ expect_eq_ulong(true, ret);
+ expect_eq_bitmap(expected, dst, nbits);
+ expect_eq_ulong(BIT(1) | BIT(12), dst[1]);
+
+ bitmap_zero(expected, nbits);
+ __set_bit(BITS_PER_LONG + 1, expected);
+ ret = bitmap_and_and(dst, src1, src2, src3, nbits);
+ expect_eq_ulong(true, ret);
+ expect_eq_bitmap(expected, dst, nbits);
+ expect_eq_ulong(BIT(1), dst[1]);
+
+ bitmap_zero(expected, nbits);
+ __set_bit(1, expected);
+ __set_bit(2, expected);
+ __set_bit(BITS_PER_LONG + 12, expected);
+ ret = bitmap_andnot(dst, src1, src3, nbits);
+ expect_eq_ulong(true, ret);
+ expect_eq_bitmap(expected, dst, nbits);
+ expect_eq_ulong(BIT(12), dst[1]);
+
+ __clear_bit(2, expected);
+ ret = bitmap_and_andnot(src2, src1, src2, src3, nbits);
+ expect_eq_ulong(true, ret);
+ expect_eq_bitmap(expected, src2, nbits);
+ expect_eq_ulong(BIT(12), src2[1]);
+
+ bitmap_fill(src3, nbits);
+ ret = bitmap_and_andnot(src2, src1, src2, src3, nbits);
+ expect_eq_ulong(false, ret);
+ expect_eq_pbl("", src2, nbits);
+}
+
static void __init test_find_nth_bit(void)
{
unsigned long b, bit, cnt = 0;
@@ -1533,6 +1608,8 @@ static void __init test_zero_nbits(void)
bitmap_zero(NULL, 0);
ret = bitmap_and(NULL, NULL, NULL, 0);
+ ret = bitmap_and_and(NULL, NULL, NULL, NULL, 0);
+ ret = bitmap_and_andnot(NULL, NULL, NULL, NULL, 0);
ret = bitmap_empty(NULL, 0);
ret = bitmap_equal(NULL, NULL, 0);
ret = bitmap_full(NULL, 0);
@@ -1566,6 +1643,7 @@ static void __init test_zero_nbits(void)
static void __init selftest(void)
{
test_zero_clear();
+ test_bitmap_and();
test_fill_set();
test_copy();
test_bitmap_region();
--
2.53.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* [PATCH 2/9] linkmode: make linkmode_and() return boolean
2026-09-07 21:54 [PATCH 0/9] linkmode: better use bitmap API Yury Norov
2026-09-07 21:54 ` [PATCH 1/9] bitmap: add bitmap_and_and() and bitmap_and_andnot() Yury Norov
@ 2026-09-07 21:54 ` Yury Norov
2026-09-08 13:04 ` Loktionov, Aleksandr
2026-09-07 21:54 ` [PATCH 3/9] net: amd: xgbe: use linkmode_and() return value in xgbe_set_link_ksettings() Yury Norov
` (6 subsequent siblings)
8 siblings, 1 reply; 24+ messages in thread
From: Yury Norov @ 2026-09-07 21:54 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, Andrew Morton
bitmap_and() returns true if the resulting bitmap is not empty.
Propagate that return value through linkmode_and() so callers can use
it where applicable.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
include/linux/linkmode.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/linkmode.h b/include/linux/linkmode.h
index 3b9de09871f6..c08632c10c3d 100644
--- a/include/linux/linkmode.h
+++ b/include/linux/linkmode.h
@@ -20,10 +20,10 @@ static inline void linkmode_copy(unsigned long *dst, const unsigned long *src)
bitmap_copy(dst, src, __ETHTOOL_LINK_MODE_MASK_NBITS);
}
-static inline void linkmode_and(unsigned long *dst, const unsigned long *a,
+static inline bool linkmode_and(unsigned long *dst, const unsigned long *a,
const unsigned long *b)
{
- bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS);
+ return bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS);
}
static inline void linkmode_or(unsigned long *dst, const unsigned long *a,
--
2.53.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* RE: [PATCH 2/9] linkmode: make linkmode_and() return boolean
2026-09-07 21:54 ` [PATCH 2/9] linkmode: make linkmode_and() return boolean Yury Norov
@ 2026-09-08 13:04 ` Loktionov, Aleksandr
0 siblings, 0 replies; 24+ messages in thread
From: Loktionov, Aleksandr @ 2026-09-08 13:04 UTC (permalink / raw)
To: Yury Norov, Andrew Lunn, Heiner Kallweit, Russell King,
Raju Rangoju, Prashanth Kumar K R, Nguyen, Anthony L,
Kitszel, Przemyslaw, Jian Shen, Jijie Shao, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-usb@vger.kernel.org
Cc: Yury Norov, Rasmus Villemoes, Andrew Morton
> -----Original Message-----
> From: Yury Norov <yury.norov@gmail.com>
> Sent: Monday, September 7, 2026 11:55 PM
> To: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Raju
> Rangoju <Raju.Rangoju@amd.com>; Prashanth Kumar K R
> <PrashanthKumar.K.R@amd.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Jian Shen <shenjian15@huawei.com>;
> Jijie Shao <shaojijie@huawei.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; intel-wired-
> lan@lists.osuosl.org; linux-usb@vger.kernel.org
> Cc: Yury Norov <ynorov@nvidia.com>; Yury Norov <yury.norov@gmail.com>;
> Rasmus Villemoes <linux@rasmusvillemoes.dk>; Andrew Morton
> <akpm@linux-foundation.org>
> Subject: [PATCH 2/9] linkmode: make linkmode_and() return boolean
>
> bitmap_and() returns true if the resulting bitmap is not empty.
> Propagate that return value through linkmode_and() so callers can use
> it where applicable.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> include/linux/linkmode.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/linkmode.h b/include/linux/linkmode.h index
> 3b9de09871f6..c08632c10c3d 100644
> --- a/include/linux/linkmode.h
> +++ b/include/linux/linkmode.h
> @@ -20,10 +20,10 @@ static inline void linkmode_copy(unsigned long
> *dst, const unsigned long *src)
> bitmap_copy(dst, src, __ETHTOOL_LINK_MODE_MASK_NBITS); }
>
> -static inline void linkmode_and(unsigned long *dst, const unsigned
> long *a,
> +static inline bool linkmode_and(unsigned long *dst, const unsigned
> long
> +*a,
> const unsigned long *b)
> {
> - bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS);
> + return bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS);
> }
>
> static inline void linkmode_or(unsigned long *dst, const unsigned
> long *a,
> --
> 2.53.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 3/9] net: amd: xgbe: use linkmode_and() return value in xgbe_set_link_ksettings()
2026-09-07 21:54 [PATCH 0/9] linkmode: better use bitmap API Yury Norov
2026-09-07 21:54 ` [PATCH 1/9] bitmap: add bitmap_and_and() and bitmap_and_andnot() Yury Norov
2026-09-07 21:54 ` [PATCH 2/9] linkmode: make linkmode_and() return boolean Yury Norov
@ 2026-09-07 21:54 ` Yury Norov
2026-09-08 13:04 ` Loktionov, Aleksandr
2026-09-07 21:54 ` [PATCH 4/9] ixgbe: use linkmode_and() return value in ixgbe_get_eee_fw() Yury Norov
` (5 subsequent siblings)
8 siblings, 1 reply; 24+ messages in thread
From: Yury Norov @ 2026-09-07 21:54 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, Andrew Morton
bitmap_empty() is O(N).
Use the return value of linkmode_and() when validating the requested
advertisement instead of scanning the result bitmap separately.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
index a9f4fcc4daae..113a10855938 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
@@ -231,6 +231,7 @@ static int xgbe_set_link_ksettings(struct net_device *netdev,
struct xgbe_prv_data *pdata = netdev_priv(netdev);
struct ethtool_link_ksettings *lks = &pdata->phy.lks;
__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
+ bool has_advertising;
u32 speed;
int ret;
@@ -267,11 +268,11 @@ static int xgbe_set_link_ksettings(struct net_device *netdev,
__ETHTOOL_LINK_MODE_MASK_NBITS, cmd->link_modes.advertising,
__ETHTOOL_LINK_MODE_MASK_NBITS, lks->link_modes.supported);
- linkmode_and(advertising, cmd->link_modes.advertising,
- lks->link_modes.supported);
+ has_advertising = linkmode_and(advertising,
+ cmd->link_modes.advertising,
+ lks->link_modes.supported);
- if ((cmd->base.autoneg == AUTONEG_ENABLE) &&
- bitmap_empty(advertising, __ETHTOOL_LINK_MODE_MASK_NBITS)) {
+ if (!has_advertising && cmd->base.autoneg == AUTONEG_ENABLE) {
netdev_err(netdev,
"unsupported requested advertisement\n");
return -EINVAL;
--
2.53.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* RE: [PATCH 3/9] net: amd: xgbe: use linkmode_and() return value in xgbe_set_link_ksettings()
2026-09-07 21:54 ` [PATCH 3/9] net: amd: xgbe: use linkmode_and() return value in xgbe_set_link_ksettings() Yury Norov
@ 2026-09-08 13:04 ` Loktionov, Aleksandr
0 siblings, 0 replies; 24+ messages in thread
From: Loktionov, Aleksandr @ 2026-09-08 13:04 UTC (permalink / raw)
To: Yury Norov, Andrew Lunn, Heiner Kallweit, Russell King,
Raju Rangoju, Prashanth Kumar K R, Nguyen, Anthony L,
Kitszel, Przemyslaw, Jian Shen, Jijie Shao, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-usb@vger.kernel.org
Cc: Yury Norov, Rasmus Villemoes, Andrew Morton
> -----Original Message-----
> From: Yury Norov <yury.norov@gmail.com>
> Sent: Monday, September 7, 2026 11:55 PM
> To: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Raju
> Rangoju <Raju.Rangoju@amd.com>; Prashanth Kumar K R
> <PrashanthKumar.K.R@amd.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Jian Shen <shenjian15@huawei.com>;
> Jijie Shao <shaojijie@huawei.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; intel-wired-
> lan@lists.osuosl.org; linux-usb@vger.kernel.org
> Cc: Yury Norov <ynorov@nvidia.com>; Yury Norov <yury.norov@gmail.com>;
> Rasmus Villemoes <linux@rasmusvillemoes.dk>; Andrew Morton
> <akpm@linux-foundation.org>
> Subject: [PATCH 3/9] net: amd: xgbe: use linkmode_and() return value
> in xgbe_set_link_ksettings()
>
> bitmap_empty() is O(N).
>
> Use the return value of linkmode_and() when validating the requested
> advertisement instead of scanning the result bitmap separately.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
> b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
> index a9f4fcc4daae..113a10855938 100644
> --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
> +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
> @@ -231,6 +231,7 @@ static int xgbe_set_link_ksettings(struct
> net_device *netdev,
> struct xgbe_prv_data *pdata = netdev_priv(netdev);
> struct ethtool_link_ksettings *lks = &pdata->phy.lks;
> __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
> + bool has_advertising;
> u32 speed;
> int ret;
>
> @@ -267,11 +268,11 @@ static int xgbe_set_link_ksettings(struct
> net_device *netdev,
> __ETHTOOL_LINK_MODE_MASK_NBITS, cmd-
> >link_modes.advertising,
> __ETHTOOL_LINK_MODE_MASK_NBITS, lks-
> >link_modes.supported);
>
> - linkmode_and(advertising, cmd->link_modes.advertising,
> - lks->link_modes.supported);
> + has_advertising = linkmode_and(advertising,
> + cmd->link_modes.advertising,
> + lks->link_modes.supported);
>
> - if ((cmd->base.autoneg == AUTONEG_ENABLE) &&
> - bitmap_empty(advertising, __ETHTOOL_LINK_MODE_MASK_NBITS))
> {
> + if (!has_advertising && cmd->base.autoneg == AUTONEG_ENABLE) {
> netdev_err(netdev,
> "unsupported requested advertisement\n");
> return -EINVAL;
> --
> 2.53.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 4/9] ixgbe: use linkmode_and() return value in ixgbe_get_eee_fw()
2026-09-07 21:54 [PATCH 0/9] linkmode: better use bitmap API Yury Norov
` (2 preceding siblings ...)
2026-09-07 21:54 ` [PATCH 3/9] net: amd: xgbe: use linkmode_and() return value in xgbe_set_link_ksettings() Yury Norov
@ 2026-09-07 21:54 ` Yury Norov
2026-09-08 9:09 ` Temerkhanov, Sergey
2026-09-08 13:06 ` Loktionov, Aleksandr
2026-09-07 21:54 ` [PATCH 5/9] net: phy: use linkmode_and() return value in genphy_c45_eee_is_active() Yury Norov
` (4 subsequent siblings)
8 siblings, 2 replies; 24+ messages in thread
From: Yury Norov @ 2026-09-07 21:54 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, Andrew Morton
Use the return value of linkmode_and() to determine whether EEE is
active instead of scanning the common link mode bitmap separately.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
index 36e43b5e88d1..a7b7f89f29e4 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
@@ -3751,8 +3751,7 @@ ixgbe_get_eee_fw(struct ixgbe_adapter *adapter, struct ethtool_keee *edata)
edata->eee_enabled = !linkmode_empty(edata->advertised);
edata->tx_lpi_enabled = edata->eee_enabled;
- linkmode_and(common, edata->advertised, edata->lp_advertised);
- edata->eee_active = !linkmode_empty(common);
+ edata->eee_active = linkmode_and(common, edata->advertised, edata->lp_advertised);
return 0;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* RE: [PATCH 4/9] ixgbe: use linkmode_and() return value in ixgbe_get_eee_fw()
2026-09-07 21:54 ` [PATCH 4/9] ixgbe: use linkmode_and() return value in ixgbe_get_eee_fw() Yury Norov
@ 2026-09-08 9:09 ` Temerkhanov, Sergey
2026-09-08 13:06 ` Loktionov, Aleksandr
1 sibling, 0 replies; 24+ messages in thread
From: Temerkhanov, Sergey @ 2026-09-08 9:09 UTC (permalink / raw)
To: Yury Norov, Andrew Lunn, Heiner Kallweit, Russell King,
Raju Rangoju, Prashanth Kumar K R, Nguyen, Anthony L,
Kitszel, Przemyslaw, Jian Shen, Jijie Shao, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-usb@vger.kernel.org
Cc: Yury Norov, Rasmus Villemoes, Andrew Morton
> -----Original Message-----
> From: Yury Norov <yury.norov@gmail.com>
> Sent: Monday, September 7, 2026 11:55 PM
> To: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Raju Rangoju
> <Raju.Rangoju@amd.com>; Prashanth Kumar K R
> <PrashanthKumar.K.R@amd.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Jian Shen <shenjian15@huawei.com>; Jijie
> Shao <shaojijie@huawei.com>; David S. Miller <davem@davemloft.net>; Eric
> Dumazet <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo
> Abeni <pabeni@redhat.com>; linux-kernel@vger.kernel.org;
> netdev@vger.kernel.org; intel-wired-lan@lists.osuosl.org; linux-
> usb@vger.kernel.org
> Cc: Yury Norov <ynorov@nvidia.com>; Yury Norov <yury.norov@gmail.com>;
> Rasmus Villemoes <linux@rasmusvillemoes.dk>; Andrew Morton <akpm@linux-
> foundation.org>
> Subject: [PATCH 4/9] ixgbe: use linkmode_and() return value in
> ixgbe_get_eee_fw()
>
> Use the return value of linkmode_and() to determine whether EEE is active
> instead of scanning the common link mode bitmap separately.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> index 36e43b5e88d1..a7b7f89f29e4 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> @@ -3751,8 +3751,7 @@ ixgbe_get_eee_fw(struct ixgbe_adapter *adapter,
> struct ethtool_keee *edata)
> edata->eee_enabled = !linkmode_empty(edata->advertised);
> edata->tx_lpi_enabled = edata->eee_enabled;
>
> - linkmode_and(common, edata->advertised, edata->lp_advertised);
> - edata->eee_active = !linkmode_empty(common);
> + edata->eee_active = linkmode_and(common, edata->advertised,
> +edata->lp_advertised);
>
> return 0;
> }
> --
> 2.53.0
Reviewed-by: Sergey Temerkhanov <sergey.temerkhanov@intel.com>
^ permalink raw reply [flat|nested] 24+ messages in thread
* RE: [PATCH 4/9] ixgbe: use linkmode_and() return value in ixgbe_get_eee_fw()
2026-09-07 21:54 ` [PATCH 4/9] ixgbe: use linkmode_and() return value in ixgbe_get_eee_fw() Yury Norov
2026-09-08 9:09 ` Temerkhanov, Sergey
@ 2026-09-08 13:06 ` Loktionov, Aleksandr
1 sibling, 0 replies; 24+ messages in thread
From: Loktionov, Aleksandr @ 2026-09-08 13:06 UTC (permalink / raw)
To: Yury Norov, Andrew Lunn, Heiner Kallweit, Russell King,
Raju Rangoju, Prashanth Kumar K R, Nguyen, Anthony L,
Kitszel, Przemyslaw, Jian Shen, Jijie Shao, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-usb@vger.kernel.org
Cc: Yury Norov, Rasmus Villemoes, Andrew Morton
> -----Original Message-----
> From: Yury Norov <yury.norov@gmail.com>
> Sent: Monday, September 7, 2026 11:55 PM
> To: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Raju
> Rangoju <Raju.Rangoju@amd.com>; Prashanth Kumar K R
> <PrashanthKumar.K.R@amd.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Jian Shen <shenjian15@huawei.com>;
> Jijie Shao <shaojijie@huawei.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; intel-wired-
> lan@lists.osuosl.org; linux-usb@vger.kernel.org
> Cc: Yury Norov <ynorov@nvidia.com>; Yury Norov <yury.norov@gmail.com>;
> Rasmus Villemoes <linux@rasmusvillemoes.dk>; Andrew Morton
> <akpm@linux-foundation.org>
> Subject: [PATCH 4/9] ixgbe: use linkmode_and() return value in
> ixgbe_get_eee_fw()
>
> Use the return value of linkmode_and() to determine whether EEE is
> active instead of scanning the common link mode bitmap separately.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> index 36e43b5e88d1..a7b7f89f29e4 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> @@ -3751,8 +3751,7 @@ ixgbe_get_eee_fw(struct ixgbe_adapter *adapter,
> struct ethtool_keee *edata)
> edata->eee_enabled = !linkmode_empty(edata->advertised);
> edata->tx_lpi_enabled = edata->eee_enabled;
>
> - linkmode_and(common, edata->advertised, edata->lp_advertised);
> - edata->eee_active = !linkmode_empty(common);
> + edata->eee_active = linkmode_and(common, edata->advertised,
> +edata->lp_advertised);
>
> return 0;
> }
> --
> 2.53.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 5/9] net: phy: use linkmode_and() return value in genphy_c45_eee_is_active()
2026-09-07 21:54 [PATCH 0/9] linkmode: better use bitmap API Yury Norov
` (3 preceding siblings ...)
2026-09-07 21:54 ` [PATCH 4/9] ixgbe: use linkmode_and() return value in ixgbe_get_eee_fw() Yury Norov
@ 2026-09-07 21:54 ` Yury Norov
2026-09-08 13:06 ` Loktionov, Aleksandr
2026-09-07 21:54 ` [PATCH 6/9] net: avoid copies before linkmode_and() Yury Norov
` (3 subsequent siblings)
8 siblings, 1 reply; 24+ messages in thread
From: Yury Norov @ 2026-09-07 21:54 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, Andrew Morton
Use the return value of linkmode_and() to detect an empty set of
common EEE modes and get rid of a separate linkmode_empty() call.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/net/phy/phy-c45.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index 870920311f9a..27da1b9ddbc5 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -1623,8 +1623,7 @@ int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *lp)
if (lp)
linkmode_copy(lp, tmp_lp);
- linkmode_and(common, phydev->advertising_eee, tmp_lp);
- if (linkmode_empty(common))
+ if (!linkmode_and(common, phydev->advertising_eee, tmp_lp))
return 0;
return phy_check_valid(phydev->speed, phydev->duplex, common);
--
2.53.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* RE: [PATCH 5/9] net: phy: use linkmode_and() return value in genphy_c45_eee_is_active()
2026-09-07 21:54 ` [PATCH 5/9] net: phy: use linkmode_and() return value in genphy_c45_eee_is_active() Yury Norov
@ 2026-09-08 13:06 ` Loktionov, Aleksandr
0 siblings, 0 replies; 24+ messages in thread
From: Loktionov, Aleksandr @ 2026-09-08 13:06 UTC (permalink / raw)
To: Yury Norov, Andrew Lunn, Heiner Kallweit, Russell King,
Raju Rangoju, Prashanth Kumar K R, Nguyen, Anthony L,
Kitszel, Przemyslaw, Jian Shen, Jijie Shao, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-usb@vger.kernel.org
Cc: Yury Norov, Rasmus Villemoes, Andrew Morton
> -----Original Message-----
> From: Yury Norov <yury.norov@gmail.com>
> Sent: Monday, September 7, 2026 11:55 PM
> To: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Raju
> Rangoju <Raju.Rangoju@amd.com>; Prashanth Kumar K R
> <PrashanthKumar.K.R@amd.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Jian Shen <shenjian15@huawei.com>;
> Jijie Shao <shaojijie@huawei.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; intel-wired-
> lan@lists.osuosl.org; linux-usb@vger.kernel.org
> Cc: Yury Norov <ynorov@nvidia.com>; Yury Norov <yury.norov@gmail.com>;
> Rasmus Villemoes <linux@rasmusvillemoes.dk>; Andrew Morton
> <akpm@linux-foundation.org>
> Subject: [PATCH 5/9] net: phy: use linkmode_and() return value in
> genphy_c45_eee_is_active()
>
> Use the return value of linkmode_and() to detect an empty set of
> common EEE modes and get rid of a separate linkmode_empty() call.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> drivers/net/phy/phy-c45.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
> index 870920311f9a..27da1b9ddbc5 100644
> --- a/drivers/net/phy/phy-c45.c
> +++ b/drivers/net/phy/phy-c45.c
> @@ -1623,8 +1623,7 @@ int genphy_c45_eee_is_active(struct phy_device
> *phydev, unsigned long *lp)
> if (lp)
> linkmode_copy(lp, tmp_lp);
>
> - linkmode_and(common, phydev->advertising_eee, tmp_lp);
> - if (linkmode_empty(common))
> + if (!linkmode_and(common, phydev->advertising_eee, tmp_lp))
> return 0;
>
> return phy_check_valid(phydev->speed, phydev->duplex, common);
> --
> 2.53.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 6/9] net: avoid copies before linkmode_and()
2026-09-07 21:54 [PATCH 0/9] linkmode: better use bitmap API Yury Norov
` (4 preceding siblings ...)
2026-09-07 21:54 ` [PATCH 5/9] net: phy: use linkmode_and() return value in genphy_c45_eee_is_active() Yury Norov
@ 2026-09-07 21:54 ` Yury Norov
2026-09-08 13:07 ` Loktionov, Aleksandr
2026-09-09 11:06 ` Jijie Shao
2026-09-07 21:54 ` [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c Yury Norov
` (2 subsequent siblings)
8 siblings, 2 replies; 24+ messages in thread
From: Yury Norov @ 2026-09-07 21:54 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, Andrew Morton
Avoid separate linkmode_copy() calls by passing the original source
bitmap directly to linkmode_and().
In phy_ethtool_ksettings_set(), also use the return value of
linkmode_and() when validating that the requested advertisement
contains a supported link mode.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 5 ++---
drivers/net/phy/phy.c | 7 +++----
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index cf881108fa57..5801da6100b8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -205,7 +205,6 @@ int hclge_mac_connect_phy(struct hnae3_handle *handle)
struct hclge_dev *hdev = vport->back;
struct net_device *netdev = hdev->vport[0].nic.netdev;
struct phy_device *phydev = hdev->hw.mac.phydev;
- __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
int ret;
if (!phydev)
@@ -223,8 +222,8 @@ int hclge_mac_connect_phy(struct hnae3_handle *handle)
return ret;
}
- linkmode_copy(mask, hdev->hw.mac.supported);
- linkmode_and(phydev->supported, phydev->supported, mask);
+ linkmode_and(phydev->supported, phydev->supported,
+ hdev->hw.mac.supported);
linkmode_copy(phydev->advertising, phydev->supported);
/* supported flag is Pause and Asym Pause, but default advertising
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index fce9bc7be330..cd71186cd842 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1160,6 +1160,7 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
const struct ethtool_link_ksettings *cmd)
{
__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
+ bool has_advertising;
u8 autoneg = cmd->base.autoneg;
u8 duplex = cmd->base.duplex;
u32 speed = cmd->base.speed;
@@ -1167,17 +1168,15 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
if (cmd->base.phy_address != phydev->mdio.addr)
return -EINVAL;
- linkmode_copy(advertising, cmd->link_modes.advertising);
-
/* We make sure that we don't pass unsupported values in to the PHY */
- linkmode_and(advertising, advertising, phydev->supported);
+ has_advertising = linkmode_and(advertising, cmd->link_modes.advertising, phydev->supported);
/* Verify the settings we care about. */
if (autoneg != AUTONEG_ENABLE && autoneg != AUTONEG_DISABLE)
return -EINVAL;
if (autoneg == AUTONEG_ENABLE &&
- (linkmode_empty(advertising) ||
+ (!has_advertising ||
!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
phydev->supported)))
return -EINVAL;
--
2.53.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* RE: [PATCH 6/9] net: avoid copies before linkmode_and()
2026-09-07 21:54 ` [PATCH 6/9] net: avoid copies before linkmode_and() Yury Norov
@ 2026-09-08 13:07 ` Loktionov, Aleksandr
2026-09-09 11:06 ` Jijie Shao
1 sibling, 0 replies; 24+ messages in thread
From: Loktionov, Aleksandr @ 2026-09-08 13:07 UTC (permalink / raw)
To: Yury Norov, Andrew Lunn, Heiner Kallweit, Russell King,
Raju Rangoju, Prashanth Kumar K R, Nguyen, Anthony L,
Kitszel, Przemyslaw, Jian Shen, Jijie Shao, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-usb@vger.kernel.org
Cc: Yury Norov, Rasmus Villemoes, Andrew Morton
> -----Original Message-----
> From: Yury Norov <yury.norov@gmail.com>
> Sent: Monday, September 7, 2026 11:55 PM
> To: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Raju
> Rangoju <Raju.Rangoju@amd.com>; Prashanth Kumar K R
> <PrashanthKumar.K.R@amd.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Jian Shen <shenjian15@huawei.com>;
> Jijie Shao <shaojijie@huawei.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; intel-wired-
> lan@lists.osuosl.org; linux-usb@vger.kernel.org
> Cc: Yury Norov <ynorov@nvidia.com>; Yury Norov <yury.norov@gmail.com>;
> Rasmus Villemoes <linux@rasmusvillemoes.dk>; Andrew Morton
> <akpm@linux-foundation.org>
> Subject: [PATCH 6/9] net: avoid copies before linkmode_and()
>
> Avoid separate linkmode_copy() calls by passing the original source
> bitmap directly to linkmode_and().
>
> In phy_ethtool_ksettings_set(), also use the return value of
> linkmode_and() when validating that the requested advertisement
> contains a supported link mode.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 5 ++---
> drivers/net/phy/phy.c | 7 +++----
> 2 files changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> index cf881108fa57..5801da6100b8 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> @@ -205,7 +205,6 @@ int hclge_mac_connect_phy(struct hnae3_handle
> *handle)
> struct hclge_dev *hdev = vport->back;
> struct net_device *netdev = hdev->vport[0].nic.netdev;
> struct phy_device *phydev = hdev->hw.mac.phydev;
> - __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
> int ret;
>
> if (!phydev)
> @@ -223,8 +222,8 @@ int hclge_mac_connect_phy(struct hnae3_handle
> *handle)
> return ret;
> }
>
> - linkmode_copy(mask, hdev->hw.mac.supported);
> - linkmode_and(phydev->supported, phydev->supported, mask);
> + linkmode_and(phydev->supported, phydev->supported,
> + hdev->hw.mac.supported);
> linkmode_copy(phydev->advertising, phydev->supported);
>
> /* supported flag is Pause and Asym Pause, but default
> advertising diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index fce9bc7be330..cd71186cd842 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -1160,6 +1160,7 @@ int phy_ethtool_ksettings_set(struct phy_device
> *phydev,
> const struct ethtool_link_ksettings *cmd)
> {
> __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
> + bool has_advertising;
> u8 autoneg = cmd->base.autoneg;
> u8 duplex = cmd->base.duplex;
> u32 speed = cmd->base.speed;
> @@ -1167,17 +1168,15 @@ int phy_ethtool_ksettings_set(struct
> phy_device *phydev,
> if (cmd->base.phy_address != phydev->mdio.addr)
> return -EINVAL;
>
> - linkmode_copy(advertising, cmd->link_modes.advertising);
> -
> /* We make sure that we don't pass unsupported values in to the
> PHY */
> - linkmode_and(advertising, advertising, phydev->supported);
> + has_advertising = linkmode_and(advertising,
> +cmd->link_modes.advertising, phydev->supported);
>
> /* Verify the settings we care about. */
> if (autoneg != AUTONEG_ENABLE && autoneg != AUTONEG_DISABLE)
> return -EINVAL;
>
> if (autoneg == AUTONEG_ENABLE &&
> - (linkmode_empty(advertising) ||
> + (!has_advertising ||
> !linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
> phydev->supported)))
> return -EINVAL;
> --
> 2.53.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH 6/9] net: avoid copies before linkmode_and()
2026-09-07 21:54 ` [PATCH 6/9] net: avoid copies before linkmode_and() Yury Norov
2026-09-08 13:07 ` Loktionov, Aleksandr
@ 2026-09-09 11:06 ` Jijie Shao
1 sibling, 0 replies; 24+ messages in thread
From: Jijie Shao @ 2026-09-09 11:06 UTC (permalink / raw)
To: Yury Norov, Andrew Lunn, Heiner Kallweit, Russell King,
Raju Rangoju, Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel,
Jian Shen, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb
Cc: shaojijie, Yury Norov, Rasmus Villemoes, Andrew Morton
on 2026/9/8 5:54, Yury Norov wrote:
> Avoid separate linkmode_copy() calls by passing the original source
> bitmap directly to linkmode_and().
>
> In phy_ethtool_ksettings_set(), also use the return value of
> linkmode_and() when validating that the requested advertisement
> contains a supported link mode.
Please include "hns3" in the subject prefix (e.g., "net: hns3: ...")
so it's clear which driver this patch belongs to. I didn't immediately
find the hns3 driver modifications from the current title.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 5 ++---
> drivers/net/phy/phy.c | 7 +++----
> 2 files changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> index cf881108fa57..5801da6100b8 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
> @@ -205,7 +205,6 @@ int hclge_mac_connect_phy(struct hnae3_handle *handle)
> struct hclge_dev *hdev = vport->back;
> struct net_device *netdev = hdev->vport[0].nic.netdev;
> struct phy_device *phydev = hdev->hw.mac.phydev;
> - __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
> int ret;
>
> if (!phydev)
> @@ -223,8 +222,8 @@ int hclge_mac_connect_phy(struct hnae3_handle *handle)
> return ret;
> }
>
> - linkmode_copy(mask, hdev->hw.mac.supported);
> - linkmode_and(phydev->supported, phydev->supported, mask);
> + linkmode_and(phydev->supported, phydev->supported,
> + hdev->hw.mac.supported);
> linkmode_copy(phydev->advertising, phydev->supported);
>
> /* supported flag is Pause and Asym Pause, but default advertising
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index fce9bc7be330..cd71186cd842 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -1160,6 +1160,7 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
> const struct ethtool_link_ksettings *cmd)
> {
> __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
> + bool has_advertising;
> u8 autoneg = cmd->base.autoneg;
> u8 duplex = cmd->base.duplex;
> u32 speed = cmd->base.speed;
> @@ -1167,17 +1168,15 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
> if (cmd->base.phy_address != phydev->mdio.addr)
> return -EINVAL;
>
> - linkmode_copy(advertising, cmd->link_modes.advertising);
> -
> /* We make sure that we don't pass unsupported values in to the PHY */
> - linkmode_and(advertising, advertising, phydev->supported);
> + has_advertising = linkmode_and(advertising, cmd->link_modes.advertising, phydev->supported);
To keep the file clean, could you please update this part to match thesurrounding code style?
Specifically, we order local variables fromlongest to shortest (reverse Christmas tree) and
enforce an 80-characterline limit.
Thanks,
Jijie Shao
>
> /* Verify the settings we care about. */
> if (autoneg != AUTONEG_ENABLE && autoneg != AUTONEG_DISABLE)
> return -EINVAL;
>
> if (autoneg == AUTONEG_ENABLE &&
> - (linkmode_empty(advertising) ||
> + (!has_advertising ||
> !linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
> phydev->supported)))
> return -EINVAL;
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c
2026-09-07 21:54 [PATCH 0/9] linkmode: better use bitmap API Yury Norov
` (5 preceding siblings ...)
2026-09-07 21:54 ` [PATCH 6/9] net: avoid copies before linkmode_and() Yury Norov
@ 2026-09-07 21:54 ` Yury Norov
2026-09-08 13:07 ` Loktionov, Aleksandr
` (2 more replies)
2026-09-07 21:54 ` [PATCH 8/9] r8152: use linkmode_and_and() in EEE checks Yury Norov
2026-09-07 21:54 ` [PATCH 9/9] MAINTAINERS: co-maintain linkmode.h under BITMAP Yury Norov
8 siblings, 3 replies; 24+ messages in thread
From: Yury Norov @ 2026-09-07 21:54 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, Andrew Morton
Use the return value of linkmode_and() where the resulting mask was
previously scanned for emptiness. In phy_probe(), combine the AND and
AND-NOT operations and use the return value of linkmode_and_andnot().
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/net/phy/phy_device.c | 14 ++++++--------
include/linux/linkmode.h | 9 +++++++++
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 94b2e85e00a3..3430605695c5 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1565,8 +1565,7 @@ static int phy_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id)
caps = sfp_get_module_caps(phydev->sfp_bus);
- linkmode_and(sfp_support, port->supported, caps->link_modes);
- if (linkmode_empty(sfp_support)) {
+ if (!linkmode_and(sfp_support, port->supported, caps->link_modes)) {
dev_err(&phydev->mdio.dev, "incompatible SFP module inserted, no common linkmode\n");
return -EINVAL;
}
@@ -3761,15 +3760,14 @@ static int phy_probe(struct device *dev)
/* Some PHYs may advertise, by default, not support EEE modes. So,
* we need to clean them. In addition remove all disabled EEE modes.
*/
- linkmode_and(phydev->advertising_eee, phydev->supported_eee,
- phydev->advertising_eee);
- linkmode_andnot(phydev->advertising_eee, phydev->advertising_eee,
- phydev->eee_disabled_modes);
-
/* There is no "enabled" flag. If PHY is advertising, assume it is
* kind of enabled.
*/
- phydev->eee_cfg.eee_enabled = !linkmode_empty(phydev->advertising_eee);
+ phydev->eee_cfg.eee_enabled =
+ linkmode_and_andnot(phydev->advertising_eee,
+ phydev->advertising_eee,
+ phydev->supported_eee,
+ phydev->eee_disabled_modes);
/* Get master/slave strap overrides */
of_set_phy_timing_role(phydev);
diff --git a/include/linux/linkmode.h b/include/linux/linkmode.h
index c08632c10c3d..49587a2e0f69 100644
--- a/include/linux/linkmode.h
+++ b/include/linux/linkmode.h
@@ -26,6 +26,15 @@ static inline bool linkmode_and(unsigned long *dst, const unsigned long *a,
return bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS);
}
+static inline bool linkmode_and_andnot(unsigned long *dst,
+ const unsigned long *a,
+ const unsigned long *b,
+ const unsigned long *c)
+{
+ return bitmap_and_andnot(dst, a, b, c,
+ __ETHTOOL_LINK_MODE_MASK_NBITS);
+}
+
static inline void linkmode_or(unsigned long *dst, const unsigned long *a,
const unsigned long *b)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* RE: [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c
2026-09-07 21:54 ` [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c Yury Norov
@ 2026-09-08 13:07 ` Loktionov, Aleksandr
2026-09-08 13:52 ` Andrew Lunn
2026-09-09 8:09 ` Loktionov, Aleksandr
2 siblings, 0 replies; 24+ messages in thread
From: Loktionov, Aleksandr @ 2026-09-08 13:07 UTC (permalink / raw)
To: Yury Norov, Andrew Lunn, Heiner Kallweit, Russell King,
Raju Rangoju, Prashanth Kumar K R, Nguyen, Anthony L,
Kitszel, Przemyslaw, Jian Shen, Jijie Shao, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-usb@vger.kernel.org
Cc: Yury Norov, Rasmus Villemoes, Andrew Morton
> -----Original Message-----
> From: Yury Norov <yury.norov@gmail.com>
> Sent: Monday, September 7, 2026 11:55 PM
> To: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Raju
> Rangoju <Raju.Rangoju@amd.com>; Prashanth Kumar K R
> <PrashanthKumar.K.R@amd.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Jian Shen <shenjian15@huawei.com>;
> Jijie Shao <shaojijie@huawei.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; intel-wired-
> lan@lists.osuosl.org; linux-usb@vger.kernel.org
> Cc: Yury Norov <ynorov@nvidia.com>; Yury Norov <yury.norov@gmail.com>;
> Rasmus Villemoes <linux@rasmusvillemoes.dk>; Andrew Morton
> <akpm@linux-foundation.org>
> Subject: [PATCH 7/9] net: phy: use linkmode operation return values in
> phy_device.c
>
> Use the return value of linkmode_and() where the resulting mask was
> previously scanned for emptiness. In phy_probe(), combine the AND and
> AND-NOT operations and use the return value of linkmode_and_andnot().
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> drivers/net/phy/phy_device.c | 14 ++++++--------
> include/linux/linkmode.h | 9 +++++++++
> 2 files changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/phy/phy_device.c
> b/drivers/net/phy/phy_device.c index 94b2e85e00a3..3430605695c5 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -1565,8 +1565,7 @@ static int phy_sfp_module_insert(void *upstream,
> const struct sfp_eeprom_id *id)
>
> caps = sfp_get_module_caps(phydev->sfp_bus);
>
> - linkmode_and(sfp_support, port->supported, caps->link_modes);
> - if (linkmode_empty(sfp_support)) {
> + if (!linkmode_and(sfp_support, port->supported, caps-
> >link_modes)) {
> dev_err(&phydev->mdio.dev, "incompatible SFP module
> inserted, no common linkmode\n");
> return -EINVAL;
> }
> @@ -3761,15 +3760,14 @@ static int phy_probe(struct device *dev)
> /* Some PHYs may advertise, by default, not support EEE modes.
> So,
> * we need to clean them. In addition remove all disabled EEE
> modes.
> */
> - linkmode_and(phydev->advertising_eee, phydev->supported_eee,
> - phydev->advertising_eee);
> - linkmode_andnot(phydev->advertising_eee, phydev-
> >advertising_eee,
> - phydev->eee_disabled_modes);
> -
> /* There is no "enabled" flag. If PHY is advertising, assume it
> is
> * kind of enabled.
> */
> - phydev->eee_cfg.eee_enabled = !linkmode_empty(phydev-
> >advertising_eee);
> + phydev->eee_cfg.eee_enabled =
> + linkmode_and_andnot(phydev->advertising_eee,
> + phydev->advertising_eee,
> + phydev->supported_eee,
> + phydev->eee_disabled_modes);
>
> /* Get master/slave strap overrides */
> of_set_phy_timing_role(phydev);
> diff --git a/include/linux/linkmode.h b/include/linux/linkmode.h index
> c08632c10c3d..49587a2e0f69 100644
> --- a/include/linux/linkmode.h
> +++ b/include/linux/linkmode.h
> @@ -26,6 +26,15 @@ static inline bool linkmode_and(unsigned long *dst,
> const unsigned long *a,
> return bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS);
> }
>
> +static inline bool linkmode_and_andnot(unsigned long *dst,
> + const unsigned long *a,
> + const unsigned long *b,
> + const unsigned long *c)
> +{
> + return bitmap_and_andnot(dst, a, b, c,
> + __ETHTOOL_LINK_MODE_MASK_NBITS);
> +}
> +
> static inline void linkmode_or(unsigned long *dst, const unsigned
> long *a,
> const unsigned long *b)
> {
> --
> 2.53.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c
2026-09-07 21:54 ` [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c Yury Norov
2026-09-08 13:07 ` Loktionov, Aleksandr
@ 2026-09-08 13:52 ` Andrew Lunn
2026-09-08 15:19 ` Yury Norov
2026-09-09 8:09 ` Loktionov, Aleksandr
2 siblings, 1 reply; 24+ messages in thread
From: Andrew Lunn @ 2026-09-08 13:52 UTC (permalink / raw)
To: Yury Norov
Cc: Heiner Kallweit, Russell King, Raju Rangoju, Prashanth Kumar K R,
Tony Nguyen, Przemek Kitszel, Jian Shen, Jijie Shao,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel, netdev, intel-wired-lan, linux-usb, Yury Norov,
Rasmus Villemoes, Andrew Morton
> - linkmode_and(sfp_support, port->supported, caps->link_modes);
> - if (linkmode_empty(sfp_support)) {
> + if (!linkmode_and(sfp_support, port->supported, caps->link_modes)) {
> dev_err(&phydev->mdio.dev, "incompatible SFP module inserted, no common linkmode\n");
From a readability perspective, i like linkmode_empty(). It is more
obvious than !linkmode_and().
None of this code is in the hot path. So we should put readability
above performance.
> /* Some PHYs may advertise, by default, not support EEE modes. So,
> * we need to clean them. In addition remove all disabled EEE modes.
> */
> - linkmode_and(phydev->advertising_eee, phydev->supported_eee,
> - phydev->advertising_eee);
> - linkmode_andnot(phydev->advertising_eee, phydev->advertising_eee,
> - phydev->eee_disabled_modes);
> -
> /* There is no "enabled" flag. If PHY is advertising, assume it is
> * kind of enabled.
> */
> - phydev->eee_cfg.eee_enabled = !linkmode_empty(phydev->advertising_eee);
> + phydev->eee_cfg.eee_enabled =
> + linkmode_and_andnot(phydev->advertising_eee,
> + phydev->advertising_eee,
> + phydev->supported_eee,
> + phydev->eee_disabled_modes);
So, which is more readable, the original or this?
Andrew
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c
2026-09-08 13:52 ` Andrew Lunn
@ 2026-09-08 15:19 ` Yury Norov
2026-09-09 12:15 ` Andrew Lunn
0 siblings, 1 reply; 24+ messages in thread
From: Yury Norov @ 2026-09-08 15:19 UTC (permalink / raw)
To: Andrew Lunn
Cc: Yury Norov, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb,
Rasmus Villemoes, Andrew Morton
On Tue, Sep 08, 2026 at 03:52:09PM +0200, Andrew Lunn wrote:
> > - linkmode_and(sfp_support, port->supported, caps->link_modes);
> > - if (linkmode_empty(sfp_support)) {
> > + if (!linkmode_and(sfp_support, port->supported, caps->link_modes)) {
> > dev_err(&phydev->mdio.dev, "incompatible SFP module inserted, no common linkmode\n");
>
> From a readability perspective, i like linkmode_empty(). It is more
> obvious than !linkmode_and().
OK, a function returning 2 values is not something obvious in C. What
about this?
sfp_supported = linkmode_and(sfp_support, port->supported, caps->link_modes);
if (!sfp_supported)
dev_err(&phydev->mdio.dev, "incompatible SFP module inserted, no common linkmode\n");
> None of this code is in the hot path. So we should put readability
> above performance.
>
> > /* Some PHYs may advertise, by default, not support EEE modes. So,
> > * we need to clean them. In addition remove all disabled EEE modes.
> > */
> > - linkmode_and(phydev->advertising_eee, phydev->supported_eee,
> > - phydev->advertising_eee);
> > - linkmode_andnot(phydev->advertising_eee, phydev->advertising_eee,
> > - phydev->eee_disabled_modes);
> > -
> > /* There is no "enabled" flag. If PHY is advertising, assume it is
> > * kind of enabled.
> > */
> > - phydev->eee_cfg.eee_enabled = !linkmode_empty(phydev->advertising_eee);
> > + phydev->eee_cfg.eee_enabled =
> > + linkmode_and_andnot(phydev->advertising_eee,
> > + phydev->advertising_eee,
> > + phydev->supported_eee,
> > + phydev->eee_disabled_modes);
>
> So, which is more readable, the original or this?
The new version is more readable to me. What about this:
eee_advertised = linkmode_and_andnot(phydev->advertising_eee,
phydev->advertising_eee,
phydev->supported_eee,
phydev->eee_disabled_modes);
/* There is no "enabled" flag. If PHY is advertising, assume it is
* kind of enabled.
*/
phydev->eee_cfg.eee_enabled = eee_advertised;
Thanks,
Yury
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c
2026-09-08 15:19 ` Yury Norov
@ 2026-09-09 12:15 ` Andrew Lunn
0 siblings, 0 replies; 24+ messages in thread
From: Andrew Lunn @ 2026-09-09 12:15 UTC (permalink / raw)
To: Yury Norov
Cc: Heiner Kallweit, Russell King, Raju Rangoju, Prashanth Kumar K R,
Tony Nguyen, Przemek Kitszel, Jian Shen, Jijie Shao,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel, netdev, intel-wired-lan, linux-usb,
Rasmus Villemoes, Andrew Morton
On Tue, Sep 08, 2026 at 11:19:19AM -0400, Yury Norov wrote:
> On Tue, Sep 08, 2026 at 03:52:09PM +0200, Andrew Lunn wrote:
> > > - linkmode_and(sfp_support, port->supported, caps->link_modes);
> > > - if (linkmode_empty(sfp_support)) {
> > > + if (!linkmode_and(sfp_support, port->supported, caps->link_modes)) {
> > > dev_err(&phydev->mdio.dev, "incompatible SFP module inserted, no common linkmode\n");
> >
> > From a readability perspective, i like linkmode_empty(). It is more
> > obvious than !linkmode_and().
>
> OK, a function returning 2 values is not something obvious in C. What
> about this?
>
>
> sfp_supported = linkmode_and(sfp_support, port->supported, caps->link_modes);
> if (!sfp_supported)
> dev_err(&phydev->mdio.dev, "incompatible SFP module inserted, no common linkmode\n");
Why not keep it as it is? If the link mode is empty, we know we have a
problem.
>
> > None of this code is in the hot path. So we should put readability
> > above performance.
> >
> > > /* Some PHYs may advertise, by default, not support EEE modes. So,
> > > * we need to clean them. In addition remove all disabled EEE modes.
> > > */
> > > - linkmode_and(phydev->advertising_eee, phydev->supported_eee,
> > > - phydev->advertising_eee);
> > > - linkmode_andnot(phydev->advertising_eee, phydev->advertising_eee,
> > > - phydev->eee_disabled_modes);
> > > -
> > > /* There is no "enabled" flag. If PHY is advertising, assume it is
> > > * kind of enabled.
> > > */
> > > - phydev->eee_cfg.eee_enabled = !linkmode_empty(phydev->advertising_eee);
> > > + phydev->eee_cfg.eee_enabled =
> > > + linkmode_and_andnot(phydev->advertising_eee,
> > > + phydev->advertising_eee,
> > > + phydev->supported_eee,
> > > + phydev->eee_disabled_modes);
> >
> > So, which is more readable, the original or this?
>
> The new version is more readable to me. What about this:
>
> eee_advertised = linkmode_and_andnot(phydev->advertising_eee,
> phydev->advertising_eee,
> phydev->supported_eee,
> phydev->eee_disabled_modes);
I still prefer the original version.
Where do you stop with these functions? Why not add
linkmode_and_andnot_or()? linkmode_and_nand_xor_nor()?
If complex expressions were used on the fast path, every packet
needing some bitmap logic, i can see the benefit of such complex
functions, if they can be optimised. But this is slow path, probe
time, or when the link goes up. Human readability comes first.
Just out of interest, did you look at the disassembly for both
versions? Isn't it the inline linkmode_ wrapper function which drops
the return value, which you are adding back. But the
compiler/optimizer sees it and could make use of it? Is gcc/clang
clever enough to do that?
Andrew
^ permalink raw reply [flat|nested] 24+ messages in thread
* RE: [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c
2026-09-07 21:54 ` [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c Yury Norov
2026-09-08 13:07 ` Loktionov, Aleksandr
2026-09-08 13:52 ` Andrew Lunn
@ 2026-09-09 8:09 ` Loktionov, Aleksandr
2 siblings, 0 replies; 24+ messages in thread
From: Loktionov, Aleksandr @ 2026-09-09 8:09 UTC (permalink / raw)
To: Yury Norov, Andrew Lunn, Heiner Kallweit, Russell King,
Raju Rangoju, Prashanth Kumar K R, Nguyen, Anthony L,
Kitszel, Przemyslaw, Jian Shen, Jijie Shao, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-usb@vger.kernel.org
Cc: Yury Norov, Rasmus Villemoes, Andrew Morton
> -----Original Message-----
> From: Yury Norov <yury.norov@gmail.com>
> Sent: Monday, September 7, 2026 11:55 PM
> To: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Raju
> Rangoju <Raju.Rangoju@amd.com>; Prashanth Kumar K R
> <PrashanthKumar.K.R@amd.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Jian Shen <shenjian15@huawei.com>;
> Jijie Shao <shaojijie@huawei.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; intel-wired-
> lan@lists.osuosl.org; linux-usb@vger.kernel.org
> Cc: Yury Norov <ynorov@nvidia.com>; Yury Norov <yury.norov@gmail.com>;
> Rasmus Villemoes <linux@rasmusvillemoes.dk>; Andrew Morton
> <akpm@linux-foundation.org>
> Subject: [PATCH 7/9] net: phy: use linkmode operation return values in
> phy_device.c
>
> Use the return value of linkmode_and() where the resulting mask was
> previously scanned for emptiness. In phy_probe(), combine the AND and
> AND-NOT operations and use the return value of linkmode_and_andnot().
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> drivers/net/phy/phy_device.c | 14 ++++++--------
> include/linux/linkmode.h | 9 +++++++++
> 2 files changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/phy/phy_device.c
> b/drivers/net/phy/phy_device.c index 94b2e85e00a3..3430605695c5 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -1565,8 +1565,7 @@ static int phy_sfp_module_insert(void *upstream,
> const struct sfp_eeprom_id *id)
>
> caps = sfp_get_module_caps(phydev->sfp_bus);
>
> - linkmode_and(sfp_support, port->supported, caps->link_modes);
> - if (linkmode_empty(sfp_support)) {
> + if (!linkmode_and(sfp_support, port->supported, caps-
> >link_modes)) {
> dev_err(&phydev->mdio.dev, "incompatible SFP module
> inserted, no common linkmode\n");
> return -EINVAL;
> }
> @@ -3761,15 +3760,14 @@ static int phy_probe(struct device *dev)
> /* Some PHYs may advertise, by default, not support EEE modes.
> So,
> * we need to clean them. In addition remove all disabled EEE
> modes.
> */
> - linkmode_and(phydev->advertising_eee, phydev->supported_eee,
> - phydev->advertising_eee);
> - linkmode_andnot(phydev->advertising_eee, phydev-
> >advertising_eee,
> - phydev->eee_disabled_modes);
> -
> /* There is no "enabled" flag. If PHY is advertising, assume it
> is
> * kind of enabled.
> */
> - phydev->eee_cfg.eee_enabled = !linkmode_empty(phydev-
> >advertising_eee);
> + phydev->eee_cfg.eee_enabled =
> + linkmode_and_andnot(phydev->advertising_eee,
> + phydev->advertising_eee,
> + phydev->supported_eee,
> + phydev->eee_disabled_modes);
>
> /* Get master/slave strap overrides */
> of_set_phy_timing_role(phydev);
> diff --git a/include/linux/linkmode.h b/include/linux/linkmode.h index
> c08632c10c3d..49587a2e0f69 100644
> --- a/include/linux/linkmode.h
> +++ b/include/linux/linkmode.h
> @@ -26,6 +26,15 @@ static inline bool linkmode_and(unsigned long *dst,
> const unsigned long *a,
> return bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS);
> }
>
> +static inline bool linkmode_and_andnot(unsigned long *dst,
> + const unsigned long *a,
> + const unsigned long *b,
> + const unsigned long *c)
> +{
> + return bitmap_and_andnot(dst, a, b, c,
> + __ETHTOOL_LINK_MODE_MASK_NBITS);
> +}
> +
> static inline void linkmode_or(unsigned long *dst, const unsigned
> long *a,
> const unsigned long *b)
> {
> --
> 2.53.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 8/9] r8152: use linkmode_and_and() in EEE checks
2026-09-07 21:54 [PATCH 0/9] linkmode: better use bitmap API Yury Norov
` (6 preceding siblings ...)
2026-09-07 21:54 ` [PATCH 7/9] net: phy: use linkmode operation return values in phy_device.c Yury Norov
@ 2026-09-07 21:54 ` Yury Norov
2026-09-08 13:12 ` Loktionov, Aleksandr
2026-09-07 21:54 ` [PATCH 9/9] MAINTAINERS: co-maintain linkmode.h under BITMAP Yury Norov
8 siblings, 1 reply; 24+ messages in thread
From: Yury Norov @ 2026-09-07 21:54 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, Andrew Morton
Combine the three link mode masks in a single operation and use its
return value to determine whether EEE is active.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
drivers/net/usb/r8152.c | 10 ++++------
include/linux/linkmode.h | 8 ++++++++
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index f61686433031..75f0574fe1d4 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -9149,9 +9149,8 @@ static int r8152_get_eee(struct r8152 *tp, struct ethtool_keee *eee)
if (speed & _100bps)
linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, common);
- linkmode_and(common, common, eee->advertised);
- linkmode_and(common, common, eee->lp_advertised);
- eee->eee_active = !linkmode_empty(common);
+ eee->eee_active = linkmode_and_and(common, common, eee->advertised,
+ eee->lp_advertised);
return 0;
}
@@ -9222,9 +9221,8 @@ static int r8153_get_eee(struct r8152 *tp, struct ethtool_keee *eee)
if (speed & _100bps)
linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, common);
- linkmode_and(common, common, eee->advertised);
- linkmode_and(common, common, eee->lp_advertised);
- eee->eee_active = !linkmode_empty(common);
+ eee->eee_active = linkmode_and_and(common, common, eee->advertised,
+ eee->lp_advertised);
return 0;
}
diff --git a/include/linux/linkmode.h b/include/linux/linkmode.h
index 49587a2e0f69..efd392dc62ae 100644
--- a/include/linux/linkmode.h
+++ b/include/linux/linkmode.h
@@ -26,6 +26,14 @@ static inline bool linkmode_and(unsigned long *dst, const unsigned long *a,
return bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS);
}
+static inline bool linkmode_and_and(unsigned long *dst,
+ const unsigned long *a,
+ const unsigned long *b,
+ const unsigned long *c)
+{
+ return bitmap_and_and(dst, a, b, c, __ETHTOOL_LINK_MODE_MASK_NBITS);
+}
+
static inline bool linkmode_and_andnot(unsigned long *dst,
const unsigned long *a,
const unsigned long *b,
--
2.53.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* RE: [PATCH 8/9] r8152: use linkmode_and_and() in EEE checks
2026-09-07 21:54 ` [PATCH 8/9] r8152: use linkmode_and_and() in EEE checks Yury Norov
@ 2026-09-08 13:12 ` Loktionov, Aleksandr
0 siblings, 0 replies; 24+ messages in thread
From: Loktionov, Aleksandr @ 2026-09-08 13:12 UTC (permalink / raw)
To: Yury Norov, Andrew Lunn, Heiner Kallweit, Russell King,
Raju Rangoju, Prashanth Kumar K R, Nguyen, Anthony L,
Kitszel, Przemyslaw, Jian Shen, Jijie Shao, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-usb@vger.kernel.org
Cc: Yury Norov, Rasmus Villemoes, Andrew Morton
> -----Original Message-----
> From: Yury Norov <yury.norov@gmail.com>
> Sent: Monday, September 7, 2026 11:55 PM
> To: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Raju
> Rangoju <Raju.Rangoju@amd.com>; Prashanth Kumar K R
> <PrashanthKumar.K.R@amd.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Jian Shen <shenjian15@huawei.com>;
> Jijie Shao <shaojijie@huawei.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; intel-wired-
> lan@lists.osuosl.org; linux-usb@vger.kernel.org
> Cc: Yury Norov <ynorov@nvidia.com>; Yury Norov <yury.norov@gmail.com>;
> Rasmus Villemoes <linux@rasmusvillemoes.dk>; Andrew Morton
> <akpm@linux-foundation.org>
> Subject: [PATCH 8/9] r8152: use linkmode_and_and() in EEE checks
>
> Combine the three link mode masks in a single operation and use its
> return value to determine whether EEE is active.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> drivers/net/usb/r8152.c | 10 ++++------ include/linux/linkmode.h |
> 8 ++++++++
> 2 files changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index
> f61686433031..75f0574fe1d4 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -9149,9 +9149,8 @@ static int r8152_get_eee(struct r8152 *tp,
> struct ethtool_keee *eee)
> if (speed & _100bps)
> linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
> common);
>
> - linkmode_and(common, common, eee->advertised);
> - linkmode_and(common, common, eee->lp_advertised);
> - eee->eee_active = !linkmode_empty(common);
> + eee->eee_active = linkmode_and_and(common, common, eee-
> >advertised,
> + eee->lp_advertised);
>
> return 0;
> }
> @@ -9222,9 +9221,8 @@ static int r8153_get_eee(struct r8152 *tp,
> struct ethtool_keee *eee)
> if (speed & _100bps)
> linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
> common);
>
> - linkmode_and(common, common, eee->advertised);
> - linkmode_and(common, common, eee->lp_advertised);
> - eee->eee_active = !linkmode_empty(common);
> + eee->eee_active = linkmode_and_and(common, common, eee-
> >advertised,
> + eee->lp_advertised);
>
> return 0;
> }
> diff --git a/include/linux/linkmode.h b/include/linux/linkmode.h index
> 49587a2e0f69..efd392dc62ae 100644
> --- a/include/linux/linkmode.h
> +++ b/include/linux/linkmode.h
> @@ -26,6 +26,14 @@ static inline bool linkmode_and(unsigned long *dst,
> const unsigned long *a,
> return bitmap_and(dst, a, b, __ETHTOOL_LINK_MODE_MASK_NBITS);
> }
>
> +static inline bool linkmode_and_and(unsigned long *dst,
> + const unsigned long *a,
> + const unsigned long *b,
> + const unsigned long *c)
> +{
> + return bitmap_and_and(dst, a, b, c,
> __ETHTOOL_LINK_MODE_MASK_NBITS); }
> +
> static inline bool linkmode_and_andnot(unsigned long *dst,
> const unsigned long *a,
> const unsigned long *b,
> --
> 2.53.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 9/9] MAINTAINERS: co-maintain linkmode.h under BITMAP
2026-09-07 21:54 [PATCH 0/9] linkmode: better use bitmap API Yury Norov
` (7 preceding siblings ...)
2026-09-07 21:54 ` [PATCH 8/9] r8152: use linkmode_and_and() in EEE checks Yury Norov
@ 2026-09-07 21:54 ` Yury Norov
2026-09-08 20:44 ` Jakub Kicinski
8 siblings, 1 reply; 24+ messages in thread
From: Yury Norov @ 2026-09-07 21:54 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, netdev, intel-wired-lan, linux-usb
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, Andrew Morton
The file is largely a wrapper around bitmap.h. List it under BITMAP
section for co-maintenance.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
MAINTAINERS | 1 +
1 file changed, 1 insertion(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 3a19da74d00c..b78f0bccff54 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4646,6 +4646,7 @@ F: include/linux/cpumask.h
F: include/linux/cpumask_types.h
F: include/linux/find.h
F: include/linux/hw_bitfield.h
+F: include/linux/linkmode.h
F: include/linux/nodemask.h
F: include/linux/nodemask_types.h
F: include/uapi/linux/bits.h
--
2.53.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH 9/9] MAINTAINERS: co-maintain linkmode.h under BITMAP
2026-09-07 21:54 ` [PATCH 9/9] MAINTAINERS: co-maintain linkmode.h under BITMAP Yury Norov
@ 2026-09-08 20:44 ` Jakub Kicinski
0 siblings, 0 replies; 24+ messages in thread
From: Jakub Kicinski @ 2026-09-08 20:44 UTC (permalink / raw)
To: Yury Norov
Cc: Andrew Lunn, Heiner Kallweit, Russell King, Raju Rangoju,
Prashanth Kumar K R, Tony Nguyen, Przemek Kitszel, Jian Shen,
Jijie Shao, David S. Miller, Eric Dumazet, Paolo Abeni,
linux-kernel, netdev, intel-wired-lan, linux-usb, Yury Norov,
Rasmus Villemoes, Andrew Morton
On Mon, 7 Sep 2026 17:54:38 -0400 Yury Norov wrote:
> The file is largely a wrapper around bitmap.h. List it under BITMAP
> section for co-maintenance.
I don't think this is appropriate, configure lore+lei if you want
to see the changes.
^ permalink raw reply [flat|nested] 24+ messages in thread