ice_common.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. /**
  6. * ice_debug_cq
  7. * @hw: pointer to the hardware structure
  8. * @mask: debug mask
  9. * @desc: pointer to control queue descriptor
  10. * @buf: pointer to command buffer
  11. * @buf_len: max length of buf
  12. *
  13. * Dumps debug log about control command with descriptor contents.
  14. */
  15. void ice_debug_cq(struct ice_hw *hw, u32 __maybe_unused mask, void *desc,
  16. void *buf, u16 buf_len)
  17. {
  18. struct ice_aq_desc *cq_desc = (struct ice_aq_desc *)desc;
  19. u16 len;
  20. #ifndef CONFIG_DYNAMIC_DEBUG
  21. if (!(mask & hw->debug_mask))
  22. return;
  23. #endif
  24. if (!desc)
  25. return;
  26. len = le16_to_cpu(cq_desc->datalen);
  27. ice_debug(hw, mask,
  28. "CQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
  29. le16_to_cpu(cq_desc->opcode),
  30. le16_to_cpu(cq_desc->flags),
  31. le16_to_cpu(cq_desc->datalen), le16_to_cpu(cq_desc->retval));
  32. ice_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
  33. le32_to_cpu(cq_desc->cookie_high),
  34. le32_to_cpu(cq_desc->cookie_low));
  35. ice_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
  36. le32_to_cpu(cq_desc->params.generic.param0),
  37. le32_to_cpu(cq_desc->params.generic.param1));
  38. ice_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
  39. le32_to_cpu(cq_desc->params.generic.addr_high),
  40. le32_to_cpu(cq_desc->params.generic.addr_low));
  41. if (buf && cq_desc->datalen != 0) {
  42. ice_debug(hw, mask, "Buffer:\n");
  43. if (buf_len < len)
  44. len = buf_len;
  45. ice_debug_array(hw, mask, 16, 1, (u8 *)buf, len);
  46. }
  47. }
  48. /* FW Admin Queue command wrappers */
  49. /**
  50. * ice_aq_send_cmd - send FW Admin Queue command to FW Admin Queue
  51. * @hw: pointer to the hw struct
  52. * @desc: descriptor describing the command
  53. * @buf: buffer to use for indirect commands (NULL for direct commands)
  54. * @buf_size: size of buffer for indirect commands (0 for direct commands)
  55. * @cd: pointer to command details structure
  56. *
  57. * Helper function to send FW Admin Queue commands to the FW Admin Queue.
  58. */
  59. enum ice_status
  60. ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf,
  61. u16 buf_size, struct ice_sq_cd *cd)
  62. {
  63. return ice_sq_send_cmd(hw, &hw->adminq, desc, buf, buf_size, cd);
  64. }
  65. /**
  66. * ice_aq_get_fw_ver
  67. * @hw: pointer to the hw struct
  68. * @cd: pointer to command details structure or NULL
  69. *
  70. * Get the firmware version (0x0001) from the admin queue commands
  71. */
  72. enum ice_status ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd)
  73. {
  74. struct ice_aqc_get_ver *resp;
  75. struct ice_aq_desc desc;
  76. enum ice_status status;
  77. resp = &desc.params.get_ver;
  78. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_get_ver);
  79. status = ice_aq_send_cmd(hw, &desc, NULL, 0, cd);
  80. if (!status) {
  81. hw->fw_branch = resp->fw_branch;
  82. hw->fw_maj_ver = resp->fw_major;
  83. hw->fw_min_ver = resp->fw_minor;
  84. hw->fw_patch = resp->fw_patch;
  85. hw->fw_build = le32_to_cpu(resp->fw_build);
  86. hw->api_branch = resp->api_branch;
  87. hw->api_maj_ver = resp->api_major;
  88. hw->api_min_ver = resp->api_minor;
  89. hw->api_patch = resp->api_patch;
  90. }
  91. return status;
  92. }
  93. /**
  94. * ice_aq_q_shutdown
  95. * @hw: pointer to the hw struct
  96. * @unloading: is the driver unloading itself
  97. *
  98. * Tell the Firmware that we're shutting down the AdminQ and whether
  99. * or not the driver is unloading as well (0x0003).
  100. */
  101. enum ice_status ice_aq_q_shutdown(struct ice_hw *hw, bool unloading)
  102. {
  103. struct ice_aqc_q_shutdown *cmd;
  104. struct ice_aq_desc desc;
  105. cmd = &desc.params.q_shutdown;
  106. ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_q_shutdown);
  107. if (unloading)
  108. cmd->driver_unloading = cpu_to_le32(ICE_AQC_DRIVER_UNLOADING);
  109. return ice_aq_send_cmd(hw, &desc, NULL, 0, NULL);
  110. }