From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
To: davem@davemloft.net
Cc: Jacob Keller <jacob.e.keller@intel.com>,
netdev@vger.kernel.org, nhorman@redhat.com, sassmann@redhat.com,
jogreene@redhat.com, Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Subject: [net-next v2 07/15] i40e: add helper conversion function for link_speed
Date: Tue, 9 Jan 2018 08:19:22 -0800 [thread overview]
Message-ID: <20180109161930.75657-8-jeffrey.t.kirsher@intel.com> (raw)
In-Reply-To: <20180109161930.75657-1-jeffrey.t.kirsher@intel.com>
From: Jacob Keller <jacob.e.keller@intel.com>
We introduced the virtchnl interface in order to have an interface for
talking to a virtual device driver which was host-driver agnostic. This
interface has its own definitions, including one for link speed.
The host driver has to talk to the virtchnl interface using these new
definitions in order to remain compatible. Today, the i40e link_speed
enumerations are value-exact matches for the virtchnl interface, so it
was originally decided to simply use a typecast.
However, this is unsafe, and makes it easier for future drivers to
continue this unsafe practice. There is nothing guaranteeing these
values are exact, and the type-cast would hide any compiler warning
which indicates the problem.
Rather than rely on this type cast, introduce a helper function which
can convert the AdminQ link speed definition into a virtchnl
definition. This can then be used by host driver implementations in
order to safely convert to the interface recognized by the virtual
functions.
If the link speed is not able to be represented by the virtchnl
definitions we'll report UNKNOWN which is the safest result.
This will ensure that should the driver specific link_speeds actual bit
definitions change, we do not report them incorrectly according to the
VF.
Additionally, this provides a better pattern for future drivers to copy,
as it is more likely a future device may not use the exact same bit-wise
definition as the current virtchnl interface.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
drivers/net/ethernet/intel/i40e/i40e_prototype.h | 31 ++++++++++++++++++++++
drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 4 +--
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/intel/i40e/i40e_prototype.h b/drivers/net/ethernet/intel/i40e/i40e_prototype.h
index 3bb6659db822..e70bebc4d2a3 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_prototype.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_prototype.h
@@ -343,6 +343,37 @@ static inline struct i40e_rx_ptype_decoded decode_rx_desc_ptype(u8 ptype)
return i40e_ptype_lookup[ptype];
}
+/**
+ * i40e_virtchnl_link_speed - Convert AdminQ link_speed to virtchnl definition
+ * @link_speed: the speed to convert
+ *
+ * Returns the link_speed in terms of the virtchnl interface, for use in
+ * converting link_speed as reported by the AdminQ into the format used for
+ * talking to virtchnl devices. If we can't represent the link speed properly,
+ * report LINK_SPEED_UNKNOWN.
+ **/
+static inline enum virtchnl_link_speed
+i40e_virtchnl_link_speed(enum i40e_aq_link_speed link_speed)
+{
+ switch (link_speed) {
+ case I40E_LINK_SPEED_100MB:
+ return VIRTCHNL_LINK_SPEED_100MB;
+ case I40E_LINK_SPEED_1GB:
+ return VIRTCHNL_LINK_SPEED_1GB;
+ case I40E_LINK_SPEED_10GB:
+ return VIRTCHNL_LINK_SPEED_10GB;
+ case I40E_LINK_SPEED_40GB:
+ return VIRTCHNL_LINK_SPEED_40GB;
+ case I40E_LINK_SPEED_20GB:
+ return VIRTCHNL_LINK_SPEED_20GB;
+ case I40E_LINK_SPEED_25GB:
+ return VIRTCHNL_LINK_SPEED_25GB;
+ case I40E_LINK_SPEED_UNKNOWN:
+ default:
+ return VIRTCHNL_LINK_SPEED_UNKNOWN;
+ }
+}
+
/* prototype for functions used for SW locks */
/* i40e_common for VF drivers*/
diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
index 74e9e5eb2351..e9309fb9084b 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
@@ -81,12 +81,12 @@ static void i40e_vc_notify_vf_link_state(struct i40e_vf *vf)
if (vf->link_forced) {
pfe.event_data.link_event.link_status = vf->link_up;
pfe.event_data.link_event.link_speed =
- (vf->link_up ? I40E_LINK_SPEED_40GB : 0);
+ (vf->link_up ? VIRTCHNL_LINK_SPEED_40GB : 0);
} else {
pfe.event_data.link_event.link_status =
ls->link_info & I40E_AQ_LINK_UP;
pfe.event_data.link_event.link_speed =
- (enum virtchnl_link_speed)ls->link_speed;
+ i40e_virtchnl_link_speed(ls->link_speed);
}
i40e_aq_send_msg_to_vf(hw, abs_vf_id, VIRTCHNL_OP_EVENT,
0, (u8 *)&pfe, sizeof(pfe), NULL);
--
2.15.1
next prev parent reply other threads:[~2018-01-09 16:19 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-09 16:19 [net-next v2 00/15][pull request] 40GbE Intel Wired LAN Driver Updates 2018-01-09 Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 01/15] i40e: display priority_xon and priority_xoff stats Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 02/15] i40evf: don't rely on netif_running() outside rtnl_lock() Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 03/15] i40evf: use spinlock to protect (mac|vlan)_filter_list Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 04/15] i40evf: release bit locks in reverse order Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 05/15] i40evf: hold the critical task bit lock while opening Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 06/15] i40e: update VFs of link state after GET_VF_RESOURCES Jeff Kirsher
2018-01-09 16:19 ` Jeff Kirsher [this message]
2018-01-09 16:19 ` [net-next v2 08/15] i40e/i40evf: Bump driver versions Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 09/15] i40e: remove redundant initialization of read_size Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 10/15] i40evf: Do not clear MSI-X PBA manually Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 11/15] i40evf: Clean-up flags for promisc mode to avoid high polling rate Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 12/15] i40evf: Drop i40evf_fire_sw_int as it is prone to races Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 13/15] i40e: change ppp name to ddp Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 14/15] i40e: track id can be 0 Jeff Kirsher
2018-01-09 16:19 ` [net-next v2 15/15] i40e: link_down_on_close private flag support Jeff Kirsher
2018-01-10 6:40 ` Jakub Kicinski
2018-01-10 9:33 ` Stachura, Mariusz
2018-01-23 10:55 ` Stachura, Mariusz
2018-01-23 19:38 ` Jakub Kicinski
2018-01-24 13:54 ` Stachura, Mariusz
2018-01-24 21:01 ` Jakub Kicinski
2018-01-10 19:45 ` [net-next v2 00/15][pull request] 40GbE Intel Wired LAN Driver Updates 2018-01-09 David Miller
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=20180109161930.75657-8-jeffrey.t.kirsher@intel.com \
--to=jeffrey.t.kirsher@intel.com \
--cc=davem@davemloft.net \
--cc=jacob.e.keller@intel.com \
--cc=jogreene@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=nhorman@redhat.com \
--cc=sassmann@redhat.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 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).