backport: add some ethtool conversion functions
authorJohannes Berg <johannes.berg@intel.com>
Fri, 8 Sep 2017 14:40:43 +0000 (16:40 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 8 Sep 2017 14:40:43 +0000 (16:40 +0200)
These weren't always exported, so we need them on some kernels.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
backport/compat/backport-4.10.c

index b4d7edea5e1b463f9b661d97b0ae2d81f86cca09..4c8125fb7a9a9e6e8d9b023a40ea83620ad2f1ff 100644 (file)
 #include <linux/mii.h>
 
 #if LINUX_VERSION_IS_GEQ(4,6,0)
+#if LINUX_VERSION_IS_LESS(4,7,0)
+static bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
+                                                   const unsigned long *src)
+{
+       bool retval = true;
+
+       /* TODO: following test will soon always be true */
+       if (__ETHTOOL_LINK_MODE_MASK_NBITS > 32) {
+               __ETHTOOL_DECLARE_LINK_MODE_MASK(ext);
+
+               bitmap_zero(ext, __ETHTOOL_LINK_MODE_MASK_NBITS);
+               bitmap_fill(ext, 32);
+               bitmap_complement(ext, ext, __ETHTOOL_LINK_MODE_MASK_NBITS);
+               if (bitmap_intersects(ext, src,
+                                     __ETHTOOL_LINK_MODE_MASK_NBITS)) {
+                       /* src mask goes beyond bit 31 */
+                       retval = false;
+               }
+       }
+       *legacy_u32 = src[0];
+       return retval;
+}
+#endif
+
 static u32 mii_get_an(struct mii_if_info *mii, u16 addr)
 {
        int advert;