• Jacob Keller's avatar
    i40e: add helper conversion function for link_speed · 5b643479
    Jacob Keller authored
    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: default avatarJacob Keller <jacob.e.keller@intel.com>
    Tested-by: default avatarAndrew Bowers <andrewx.bowers@intel.com>
    Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
    5b643479
i40e_virtchnl_pf.c 89.9 KB