diff options
Diffstat (limited to 'drivers/net/ethernet/intel/ice/ice_sriov.c')
| -rw-r--r-- | drivers/net/ethernet/intel/ice/ice_sriov.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/drivers/net/ethernet/intel/ice/ice_sriov.c b/drivers/net/ethernet/intel/ice/ice_sriov.c new file mode 100644 index 000000000000..027eba4e13f8 --- /dev/null +++ b/drivers/net/ethernet/intel/ice/ice_sriov.c | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* Copyright (c) 2018, Intel Corporation. */ | ||
| 3 | |||
| 4 | #include "ice_common.h" | ||
| 5 | #include "ice_adminq_cmd.h" | ||
| 6 | #include "ice_sriov.h" | ||
| 7 | |||
| 8 | /** | ||
| 9 | * ice_aq_send_msg_to_vf | ||
| 10 | * @hw: pointer to the hardware structure | ||
| 11 | * @vfid: VF ID to send msg | ||
| 12 | * @v_opcode: opcodes for VF-PF communication | ||
| 13 | * @v_retval: return error code | ||
| 14 | * @msg: pointer to the msg buffer | ||
| 15 | * @msglen: msg length | ||
| 16 | * @cd: pointer to command details | ||
| 17 | * | ||
| 18 | * Send message to VF driver (0x0802) using mailbox | ||
| 19 | * queue and asynchronously sending message via | ||
| 20 | * ice_sq_send_cmd() function | ||
| 21 | */ | ||
| 22 | enum ice_status | ||
| 23 | ice_aq_send_msg_to_vf(struct ice_hw *hw, u16 vfid, u32 v_opcode, u32 v_retval, | ||
| 24 | u8 *msg, u16 msglen, struct ice_sq_cd *cd) | ||
| 25 | { | ||
| 26 | struct ice_aqc_pf_vf_msg *cmd; | ||
| 27 | struct ice_aq_desc desc; | ||
| 28 | |||
| 29 | ice_fill_dflt_direct_cmd_desc(&desc, ice_mbx_opc_send_msg_to_vf); | ||
| 30 | |||
| 31 | cmd = &desc.params.virt; | ||
| 32 | cmd->id = cpu_to_le32(vfid); | ||
| 33 | |||
| 34 | desc.cookie_high = cpu_to_le32(v_opcode); | ||
| 35 | desc.cookie_low = cpu_to_le32(v_retval); | ||
| 36 | |||
| 37 | if (msglen) | ||
| 38 | desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD); | ||
| 39 | |||
| 40 | return ice_sq_send_cmd(hw, &hw->mailboxq, &desc, msg, msglen, cd); | ||
| 41 | } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * ice_conv_link_speed_to_virtchnl | ||
| 45 | * @adv_link_support: determines the format of the returned link speed | ||
| 46 | * @link_speed: variable containing the link_speed to be converted | ||
| 47 | * | ||
| 48 | * Convert link speed supported by HW to link speed supported by virtchnl. | ||
| 49 | * If adv_link_support is true, then return link speed in Mbps. Else return | ||
| 50 | * link speed as a VIRTCHNL_LINK_SPEED_* casted to a u32. Note that the caller | ||
| 51 | * needs to cast back to an enum virtchnl_link_speed in the case where | ||
| 52 | * adv_link_support is false, but when adv_link_support is true the caller can | ||
| 53 | * expect the speed in Mbps. | ||
| 54 | */ | ||
| 55 | u32 ice_conv_link_speed_to_virtchnl(bool adv_link_support, u16 link_speed) | ||
| 56 | { | ||
| 57 | u32 speed; | ||
| 58 | |||
| 59 | if (adv_link_support) | ||
| 60 | switch (link_speed) { | ||
| 61 | case ICE_AQ_LINK_SPEED_10MB: | ||
| 62 | speed = ICE_LINK_SPEED_10MBPS; | ||
| 63 | break; | ||
| 64 | case ICE_AQ_LINK_SPEED_100MB: | ||
| 65 | speed = ICE_LINK_SPEED_100MBPS; | ||
| 66 | break; | ||
| 67 | case ICE_AQ_LINK_SPEED_1000MB: | ||
| 68 | speed = ICE_LINK_SPEED_1000MBPS; | ||
| 69 | break; | ||
| 70 | case ICE_AQ_LINK_SPEED_2500MB: | ||
| 71 | speed = ICE_LINK_SPEED_2500MBPS; | ||
| 72 | break; | ||
| 73 | case ICE_AQ_LINK_SPEED_5GB: | ||
| 74 | speed = ICE_LINK_SPEED_5000MBPS; | ||
| 75 | break; | ||
| 76 | case ICE_AQ_LINK_SPEED_10GB: | ||
| 77 | speed = ICE_LINK_SPEED_10000MBPS; | ||
| 78 | break; | ||
| 79 | case ICE_AQ_LINK_SPEED_20GB: | ||
| 80 | speed = ICE_LINK_SPEED_20000MBPS; | ||
| 81 | break; | ||
| 82 | case ICE_AQ_LINK_SPEED_25GB: | ||
| 83 | speed = ICE_LINK_SPEED_25000MBPS; | ||
| 84 | break; | ||
| 85 | case ICE_AQ_LINK_SPEED_40GB: | ||
| 86 | speed = ICE_LINK_SPEED_40000MBPS; | ||
| 87 | break; | ||
| 88 | default: | ||
| 89 | speed = ICE_LINK_SPEED_UNKNOWN; | ||
| 90 | break; | ||
| 91 | } | ||
| 92 | else | ||
| 93 | /* Virtchnl speeds are not defined for every speed supported in | ||
| 94 | * the hardware. To maintain compatibility with older AVF | ||
| 95 | * drivers, while reporting the speed the new speed values are | ||
| 96 | * resolved to the closest known virtchnl speeds | ||
| 97 | */ | ||
| 98 | switch (link_speed) { | ||
| 99 | case ICE_AQ_LINK_SPEED_10MB: | ||
| 100 | case ICE_AQ_LINK_SPEED_100MB: | ||
| 101 | speed = (u32)VIRTCHNL_LINK_SPEED_100MB; | ||
| 102 | break; | ||
| 103 | case ICE_AQ_LINK_SPEED_1000MB: | ||
| 104 | case ICE_AQ_LINK_SPEED_2500MB: | ||
| 105 | case ICE_AQ_LINK_SPEED_5GB: | ||
| 106 | speed = (u32)VIRTCHNL_LINK_SPEED_1GB; | ||
| 107 | break; | ||
| 108 | case ICE_AQ_LINK_SPEED_10GB: | ||
| 109 | speed = (u32)VIRTCHNL_LINK_SPEED_10GB; | ||
| 110 | break; | ||
| 111 | case ICE_AQ_LINK_SPEED_20GB: | ||
| 112 | speed = (u32)VIRTCHNL_LINK_SPEED_20GB; | ||
| 113 | break; | ||
| 114 | case ICE_AQ_LINK_SPEED_25GB: | ||
| 115 | speed = (u32)VIRTCHNL_LINK_SPEED_25GB; | ||
| 116 | break; | ||
| 117 | case ICE_AQ_LINK_SPEED_40GB: | ||
| 118 | /* fall through */ | ||
| 119 | speed = (u32)VIRTCHNL_LINK_SPEED_40GB; | ||
| 120 | break; | ||
| 121 | default: | ||
| 122 | speed = (u32)VIRTCHNL_LINK_SPEED_UNKNOWN; | ||
| 123 | break; | ||
| 124 | } | ||
| 125 | |||
| 126 | return speed; | ||
| 127 | } | ||
