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 case ICE_AQ_LINK_SPEED_50GB: 89 speed = ICE_LINK_SPEED_50000MBPS; 90 break; 91 case ICE_AQ_LINK_SPEED_100GB: 92 speed = ICE_LINK_SPEED_100000MBPS; 93 break; 94 default: 95 speed = ICE_LINK_SPEED_UNKNOWN; 96 break; 97 } 98 else 99 /* Virtchnl speeds are not defined for every speed supported in 100 * the hardware. To maintain compatibility with older AVF 101 * drivers, while reporting the speed the new speed values are 102 * resolved to the closest known virtchnl speeds 103 */ 104 switch (link_speed) { 105 case ICE_AQ_LINK_SPEED_10MB: 106 case ICE_AQ_LINK_SPEED_100MB: 107 speed = (u32)VIRTCHNL_LINK_SPEED_100MB; 108 break; 109 case ICE_AQ_LINK_SPEED_1000MB: 110 case ICE_AQ_LINK_SPEED_2500MB: 111 case ICE_AQ_LINK_SPEED_5GB: 112 speed = (u32)VIRTCHNL_LINK_SPEED_1GB; 113 break; 114 case ICE_AQ_LINK_SPEED_10GB: 115 speed = (u32)VIRTCHNL_LINK_SPEED_10GB; 116 break; 117 case ICE_AQ_LINK_SPEED_20GB: 118 speed = (u32)VIRTCHNL_LINK_SPEED_20GB; 119 break; 120 case ICE_AQ_LINK_SPEED_25GB: 121 speed = (u32)VIRTCHNL_LINK_SPEED_25GB; 122 break; 123 case ICE_AQ_LINK_SPEED_40GB: 124 /* fall through */ 125 case ICE_AQ_LINK_SPEED_50GB: 126 /* fall through */ 127 case ICE_AQ_LINK_SPEED_100GB: 128 speed = (u32)VIRTCHNL_LINK_SPEED_40GB; 129 break; 130 default: 131 speed = (u32)VIRTCHNL_LINK_SPEED_UNKNOWN; 132 break; 133 } 134 135 return speed; 136 } 137