adf_accel_engine.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. This file is provided under a dual BSD/GPLv2 license. When using or
  3. redistributing this file, you may do so under either license.
  4. GPL LICENSE SUMMARY
  5. Copyright(c) 2014 Intel Corporation.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License as
  8. published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. Contact Information:
  14. qat-linux@intel.com
  15. BSD LICENSE
  16. Copyright(c) 2014 Intel Corporation.
  17. Redistribution and use in source and binary forms, with or without
  18. modification, are permitted provided that the following conditions
  19. are met:
  20. * Redistributions of source code must retain the above copyright
  21. notice, this list of conditions and the following disclaimer.
  22. * Redistributions in binary form must reproduce the above copyright
  23. notice, this list of conditions and the following disclaimer in
  24. the documentation and/or other materials provided with the
  25. distribution.
  26. * Neither the name of Intel Corporation nor the names of its
  27. contributors may be used to endorse or promote products derived
  28. from this software without specific prior written permission.
  29. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. */
  41. #include <linux/firmware.h>
  42. #include <linux/pci.h>
  43. #include "adf_cfg.h"
  44. #include "adf_accel_devices.h"
  45. #include "adf_common_drv.h"
  46. #include "icp_qat_uclo.h"
  47. int adf_ae_fw_load(struct adf_accel_dev *accel_dev)
  48. {
  49. struct adf_fw_loader_data *loader_data = accel_dev->fw_loader;
  50. struct adf_hw_device_data *hw_device = accel_dev->hw_device;
  51. void *uof_addr, *mmp_addr;
  52. u32 uof_size, mmp_size;
  53. if (!hw_device->fw_name)
  54. return 0;
  55. if (request_firmware(&loader_data->mmp_fw, hw_device->fw_mmp_name,
  56. &accel_dev->accel_pci_dev.pci_dev->dev)) {
  57. dev_err(&GET_DEV(accel_dev), "Failed to load MMP firmware %s\n",
  58. hw_device->fw_mmp_name);
  59. return -EFAULT;
  60. }
  61. if (request_firmware(&loader_data->uof_fw, hw_device->fw_name,
  62. &accel_dev->accel_pci_dev.pci_dev->dev)) {
  63. dev_err(&GET_DEV(accel_dev), "Failed to load UOF firmware %s\n",
  64. hw_device->fw_name);
  65. goto out_err;
  66. }
  67. uof_size = loader_data->uof_fw->size;
  68. uof_addr = (void *)loader_data->uof_fw->data;
  69. mmp_size = loader_data->mmp_fw->size;
  70. mmp_addr = (void *)loader_data->mmp_fw->data;
  71. if (qat_uclo_wr_mimage(loader_data->fw_loader, mmp_addr, mmp_size)) {
  72. dev_err(&GET_DEV(accel_dev), "Failed to load MMP\n");
  73. goto out_err;
  74. }
  75. if (qat_uclo_map_obj(loader_data->fw_loader, uof_addr, uof_size)) {
  76. dev_err(&GET_DEV(accel_dev), "Failed to map FW\n");
  77. goto out_err;
  78. }
  79. if (qat_uclo_wr_all_uimage(loader_data->fw_loader)) {
  80. dev_err(&GET_DEV(accel_dev), "Failed to load UOF\n");
  81. goto out_err;
  82. }
  83. return 0;
  84. out_err:
  85. adf_ae_fw_release(accel_dev);
  86. return -EFAULT;
  87. }
  88. void adf_ae_fw_release(struct adf_accel_dev *accel_dev)
  89. {
  90. struct adf_fw_loader_data *loader_data = accel_dev->fw_loader;
  91. struct adf_hw_device_data *hw_device = accel_dev->hw_device;
  92. if (!hw_device->fw_name)
  93. return;
  94. qat_uclo_del_uof_obj(loader_data->fw_loader);
  95. qat_hal_deinit(loader_data->fw_loader);
  96. release_firmware(loader_data->uof_fw);
  97. release_firmware(loader_data->mmp_fw);
  98. loader_data->uof_fw = NULL;
  99. loader_data->mmp_fw = NULL;
  100. loader_data->fw_loader = NULL;
  101. }
  102. int adf_ae_start(struct adf_accel_dev *accel_dev)
  103. {
  104. struct adf_fw_loader_data *loader_data = accel_dev->fw_loader;
  105. struct adf_hw_device_data *hw_data = accel_dev->hw_device;
  106. uint32_t ae_ctr, ae, max_aes = GET_MAX_ACCELENGINES(accel_dev);
  107. if (!hw_data->fw_name)
  108. return 0;
  109. for (ae = 0, ae_ctr = 0; ae < max_aes; ae++) {
  110. if (hw_data->ae_mask & (1 << ae)) {
  111. qat_hal_start(loader_data->fw_loader, ae, 0xFF);
  112. ae_ctr++;
  113. }
  114. }
  115. dev_info(&GET_DEV(accel_dev),
  116. "qat_dev%d started %d acceleration engines\n",
  117. accel_dev->accel_id, ae_ctr);
  118. return 0;
  119. }
  120. int adf_ae_stop(struct adf_accel_dev *accel_dev)
  121. {
  122. struct adf_fw_loader_data *loader_data = accel_dev->fw_loader;
  123. struct adf_hw_device_data *hw_data = accel_dev->hw_device;
  124. uint32_t ae_ctr, ae, max_aes = GET_MAX_ACCELENGINES(accel_dev);
  125. if (!hw_data->fw_name)
  126. return 0;
  127. for (ae = 0, ae_ctr = 0; ae < max_aes; ae++) {
  128. if (hw_data->ae_mask & (1 << ae)) {
  129. qat_hal_stop(loader_data->fw_loader, ae, 0xFF);
  130. ae_ctr++;
  131. }
  132. }
  133. dev_info(&GET_DEV(accel_dev),
  134. "qat_dev%d stopped %d acceleration engines\n",
  135. accel_dev->accel_id, ae_ctr);
  136. return 0;
  137. }
  138. static int adf_ae_reset(struct adf_accel_dev *accel_dev, int ae)
  139. {
  140. struct adf_fw_loader_data *loader_data = accel_dev->fw_loader;
  141. qat_hal_reset(loader_data->fw_loader);
  142. if (qat_hal_clr_reset(loader_data->fw_loader))
  143. return -EFAULT;
  144. return 0;
  145. }
  146. int adf_ae_init(struct adf_accel_dev *accel_dev)
  147. {
  148. struct adf_fw_loader_data *loader_data;
  149. struct adf_hw_device_data *hw_device = accel_dev->hw_device;
  150. if (!hw_device->fw_name)
  151. return 0;
  152. loader_data = kzalloc(sizeof(*loader_data), GFP_KERNEL);
  153. if (!loader_data)
  154. return -ENOMEM;
  155. accel_dev->fw_loader = loader_data;
  156. if (qat_hal_init(accel_dev)) {
  157. dev_err(&GET_DEV(accel_dev), "Failed to init the AEs\n");
  158. kfree(loader_data);
  159. return -EFAULT;
  160. }
  161. if (adf_ae_reset(accel_dev, 0)) {
  162. dev_err(&GET_DEV(accel_dev), "Failed to reset the AEs\n");
  163. qat_hal_deinit(loader_data->fw_loader);
  164. kfree(loader_data);
  165. return -EFAULT;
  166. }
  167. return 0;
  168. }
  169. int adf_ae_shutdown(struct adf_accel_dev *accel_dev)
  170. {
  171. struct adf_fw_loader_data *loader_data = accel_dev->fw_loader;
  172. struct adf_hw_device_data *hw_device = accel_dev->hw_device;
  173. if (!hw_device->fw_name)
  174. return 0;
  175. qat_hal_deinit(loader_data->fw_loader);
  176. kfree(accel_dev->fw_loader);
  177. accel_dev->fw_loader = NULL;
  178. return 0;
  179. }