net/i40e/base: add link speed convert function
authorQi Zhang <qi.z.zhang@intel.com>
Tue, 9 Jan 2018 20:30:07 +0000 (15:30 -0500)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 16 Jan 2018 17:47:49 +0000 (18:47 +0100)
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.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
Acked-by: Beilei Xing <beilei.xing@intel.com>
drivers/net/i40e/base/i40e_prototype.h

index acb2023..9097097 100644 (file)
@@ -496,6 +496,38 @@ STATIC INLINE struct i40e_rx_ptype_decoded decode_rx_desc_ptype(u8 ptype)
        return i40e_ptype_lookup[ptype];
 }
 
+#ifdef PF_DRIVER
+/**
+ * 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;
+       }
+}
+#endif /* PF_DRIVER */
 /* prototype for functions used for SW spinlocks */
 void i40e_init_spinlock(struct i40e_spinlock *sp);
 void i40e_acquire_spinlock(struct i40e_spinlock *sp);