All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Brady <alan.brady@intel.com>
To: intel-wired-lan@osuosl.org
Subject: [Intel-wired-lan] [PATCH v3 10/14 net-next] ethtool: add ethtool_intersect_link_masks
Date: Thu,  5 Oct 2017 14:53:40 -0700	[thread overview]
Message-ID: <20171005215344.2886-11-alan.brady@intel.com> (raw)
In-Reply-To: <20171005215344.2886-1-alan.brady@intel.com>

This function provides a way to intersect two link masks together to
find the common ground between them.  For example in i40e, the driver
first generates link masks for what is supported by the PHY type.  The
driver then gets the link masks for what the NVM supports.  The
resulting intersection between them yields what can truly be supported.

Signed-off-by: Alan Brady <alan.brady@intel.com>
---
 include/linux/ethtool.h | 10 ++++++++++
 net/core/ethtool.c      | 16 ++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 4587a4c36923..c77fa3529e15 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -163,6 +163,16 @@ extern int
 __ethtool_get_link_ksettings(struct net_device *dev,
 			     struct ethtool_link_ksettings *link_ksettings);
 
+/**
+ * ethtool_intersect_link_masks - Given two link masks, AND them together
+ * @dst: first mask and where result is stored
+ * @src: second mask to intersect with
+ *
+ * Given two link mode masks, AND them together and save the result in dst.
+ */
+void ethtool_intersect_link_masks(struct ethtool_link_ksettings *dst,
+				  struct ethtool_link_ksettings *src);
+
 void ethtool_convert_legacy_u32_to_link_mode(unsigned long *dst,
 					     u32 legacy_u32);
 
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 3228411ada0f..0c406306792a 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -403,6 +403,22 @@ static int __ethtool_set_flags(struct net_device *dev, u32 data)
 	return 0;
 }
 
+/* Given two link masks, AND them together and save the result in dst. */
+void ethtool_intersect_link_masks(struct ethtool_link_ksettings *dst,
+				  struct ethtool_link_ksettings *src)
+{
+	unsigned int size = BITS_TO_LONGS(__ETHTOOL_LINK_MODE_MASK_NBITS);
+	unsigned int idx = 0;
+
+	for (; idx < size; idx++) {
+		dst->link_modes.supported[idx] &=
+			src->link_modes.supported[idx];
+		dst->link_modes.advertising[idx] &=
+			src->link_modes.advertising[idx];
+	}
+}
+EXPORT_SYMBOL(ethtool_intersect_link_masks);
+
 void ethtool_convert_legacy_u32_to_link_mode(unsigned long *dst,
 					     u32 legacy_u32)
 {
-- 
2.14.1


  parent reply	other threads:[~2017-10-05 21:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-05 21:53 [Intel-wired-lan] [PATCH v3 00/14 net-next] i40e: refactor ethtool interface Alan Brady
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 01/14 net-next] i40e: rename 'cmd' variables in " Alan Brady
2017-10-10 17:38   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 02/14 net-next] i40e: remove ifdef SPEED_25000 Alan Brady
2017-10-10 17:39   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 03/14 net-next] i40e: add function header for i40e_get_rxfh Alan Brady
2017-10-10 17:39   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 04/14 net-next] i40e: fix clearing link masks in i40e_get_link_ksettings Alan Brady
2017-10-10 17:40   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 05/14 net-next] i40e: fix i40e_phy_type_to_ethtool function header Alan Brady
2017-10-10 17:41   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 06/14 net-next] i40e: fix comment typo Alan Brady
2017-10-10 17:41   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 07/14 net-next] i40e: fix whitespace issues in i40e_ethtool.c Alan Brady
2017-10-10 17:42   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 08/14 net-next] i40e: group autoneg PHY types together Alan Brady
2017-10-10 17:42   ` Bowers, AndrewX
2017-10-10 19:08   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 09/14 net-next] i40e: Add new phy types for 25G AOC and ACC support Alan Brady
2017-10-10 17:43   ` Bowers, AndrewX
2017-10-05 21:53 ` Alan Brady [this message]
2017-10-10 17:43   ` [Intel-wired-lan] [PATCH v3 10/14 net-next] ethtool: add ethtool_intersect_link_masks Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 11/14 net-next] i40e: convert i40e_phy_type_to_ethtool to new API Alan Brady
2017-10-10 17:44   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 12/14 net-next] i40e: convert i40e_get_settings_link_up " Alan Brady
2017-10-10 17:44   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 13/14 net-next] i40e: rename 'change' variable to 'autoneg_changed' Alan Brady
2017-10-10 17:45   ` Bowers, AndrewX
2017-10-05 21:53 ` [Intel-wired-lan] [PATCH v3 14/14 net-next] i40e: convert i40e_set_link_ksettings to new API Alan Brady
2017-10-10 17:45   ` Bowers, AndrewX

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=20171005215344.2886-11-alan.brady@intel.com \
    --to=alan.brady@intel.com \
    --cc=intel-wired-lan@osuosl.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 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.