18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* Copyright (c) 2018, Intel Corporation. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include "ice_common.h" 58c2ecf20Sopenharmony_ci#include "ice_adminq_cmd.h" 68c2ecf20Sopenharmony_ci#include "ice_sriov.h" 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/** 98c2ecf20Sopenharmony_ci * ice_aq_send_msg_to_vf 108c2ecf20Sopenharmony_ci * @hw: pointer to the hardware structure 118c2ecf20Sopenharmony_ci * @vfid: VF ID to send msg 128c2ecf20Sopenharmony_ci * @v_opcode: opcodes for VF-PF communication 138c2ecf20Sopenharmony_ci * @v_retval: return error code 148c2ecf20Sopenharmony_ci * @msg: pointer to the msg buffer 158c2ecf20Sopenharmony_ci * @msglen: msg length 168c2ecf20Sopenharmony_ci * @cd: pointer to command details 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * Send message to VF driver (0x0802) using mailbox 198c2ecf20Sopenharmony_ci * queue and asynchronously sending message via 208c2ecf20Sopenharmony_ci * ice_sq_send_cmd() function 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_cienum ice_status 238c2ecf20Sopenharmony_ciice_aq_send_msg_to_vf(struct ice_hw *hw, u16 vfid, u32 v_opcode, u32 v_retval, 248c2ecf20Sopenharmony_ci u8 *msg, u16 msglen, struct ice_sq_cd *cd) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci struct ice_aqc_pf_vf_msg *cmd; 278c2ecf20Sopenharmony_ci struct ice_aq_desc desc; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci ice_fill_dflt_direct_cmd_desc(&desc, ice_mbx_opc_send_msg_to_vf); 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci cmd = &desc.params.virt; 328c2ecf20Sopenharmony_ci cmd->id = cpu_to_le32(vfid); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci desc.cookie_high = cpu_to_le32(v_opcode); 358c2ecf20Sopenharmony_ci desc.cookie_low = cpu_to_le32(v_retval); 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci if (msglen) 388c2ecf20Sopenharmony_ci desc.flags |= cpu_to_le16(ICE_AQ_FLAG_RD); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci return ice_sq_send_cmd(hw, &hw->mailboxq, &desc, msg, msglen, cd); 418c2ecf20Sopenharmony_ci} 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/** 448c2ecf20Sopenharmony_ci * ice_conv_link_speed_to_virtchnl 458c2ecf20Sopenharmony_ci * @adv_link_support: determines the format of the returned link speed 468c2ecf20Sopenharmony_ci * @link_speed: variable containing the link_speed to be converted 478c2ecf20Sopenharmony_ci * 488c2ecf20Sopenharmony_ci * Convert link speed supported by HW to link speed supported by virtchnl. 498c2ecf20Sopenharmony_ci * If adv_link_support is true, then return link speed in Mbps. Else return 508c2ecf20Sopenharmony_ci * link speed as a VIRTCHNL_LINK_SPEED_* casted to a u32. Note that the caller 518c2ecf20Sopenharmony_ci * needs to cast back to an enum virtchnl_link_speed in the case where 528c2ecf20Sopenharmony_ci * adv_link_support is false, but when adv_link_support is true the caller can 538c2ecf20Sopenharmony_ci * expect the speed in Mbps. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ciu32 ice_conv_link_speed_to_virtchnl(bool adv_link_support, u16 link_speed) 568c2ecf20Sopenharmony_ci{ 578c2ecf20Sopenharmony_ci u32 speed; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci if (adv_link_support) 608c2ecf20Sopenharmony_ci switch (link_speed) { 618c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_10MB: 628c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_10MBPS; 638c2ecf20Sopenharmony_ci break; 648c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_100MB: 658c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_100MBPS; 668c2ecf20Sopenharmony_ci break; 678c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_1000MB: 688c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_1000MBPS; 698c2ecf20Sopenharmony_ci break; 708c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_2500MB: 718c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_2500MBPS; 728c2ecf20Sopenharmony_ci break; 738c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_5GB: 748c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_5000MBPS; 758c2ecf20Sopenharmony_ci break; 768c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_10GB: 778c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_10000MBPS; 788c2ecf20Sopenharmony_ci break; 798c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_20GB: 808c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_20000MBPS; 818c2ecf20Sopenharmony_ci break; 828c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_25GB: 838c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_25000MBPS; 848c2ecf20Sopenharmony_ci break; 858c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_40GB: 868c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_40000MBPS; 878c2ecf20Sopenharmony_ci break; 888c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_50GB: 898c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_50000MBPS; 908c2ecf20Sopenharmony_ci break; 918c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_100GB: 928c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_100000MBPS; 938c2ecf20Sopenharmony_ci break; 948c2ecf20Sopenharmony_ci default: 958c2ecf20Sopenharmony_ci speed = ICE_LINK_SPEED_UNKNOWN; 968c2ecf20Sopenharmony_ci break; 978c2ecf20Sopenharmony_ci } 988c2ecf20Sopenharmony_ci else 998c2ecf20Sopenharmony_ci /* Virtchnl speeds are not defined for every speed supported in 1008c2ecf20Sopenharmony_ci * the hardware. To maintain compatibility with older AVF 1018c2ecf20Sopenharmony_ci * drivers, while reporting the speed the new speed values are 1028c2ecf20Sopenharmony_ci * resolved to the closest known virtchnl speeds 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_ci switch (link_speed) { 1058c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_10MB: 1068c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_100MB: 1078c2ecf20Sopenharmony_ci speed = (u32)VIRTCHNL_LINK_SPEED_100MB; 1088c2ecf20Sopenharmony_ci break; 1098c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_1000MB: 1108c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_2500MB: 1118c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_5GB: 1128c2ecf20Sopenharmony_ci speed = (u32)VIRTCHNL_LINK_SPEED_1GB; 1138c2ecf20Sopenharmony_ci break; 1148c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_10GB: 1158c2ecf20Sopenharmony_ci speed = (u32)VIRTCHNL_LINK_SPEED_10GB; 1168c2ecf20Sopenharmony_ci break; 1178c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_20GB: 1188c2ecf20Sopenharmony_ci speed = (u32)VIRTCHNL_LINK_SPEED_20GB; 1198c2ecf20Sopenharmony_ci break; 1208c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_25GB: 1218c2ecf20Sopenharmony_ci speed = (u32)VIRTCHNL_LINK_SPEED_25GB; 1228c2ecf20Sopenharmony_ci break; 1238c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_40GB: 1248c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_50GB: 1258c2ecf20Sopenharmony_ci case ICE_AQ_LINK_SPEED_100GB: 1268c2ecf20Sopenharmony_ci speed = (u32)VIRTCHNL_LINK_SPEED_40GB; 1278c2ecf20Sopenharmony_ci break; 1288c2ecf20Sopenharmony_ci default: 1298c2ecf20Sopenharmony_ci speed = (u32)VIRTCHNL_LINK_SPEED_UNKNOWN; 1308c2ecf20Sopenharmony_ci break; 1318c2ecf20Sopenharmony_ci } 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci return speed; 1348c2ecf20Sopenharmony_ci} 135