ice_sriov.c 3.5 KB

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