adf_isr.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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/kernel.h>
  42. #include <linux/init.h>
  43. #include <linux/types.h>
  44. #include <linux/pci.h>
  45. #include <linux/slab.h>
  46. #include <linux/errno.h>
  47. #include <linux/interrupt.h>
  48. #include <adf_accel_devices.h>
  49. #include <adf_common_drv.h>
  50. #include <adf_cfg.h>
  51. #include <adf_cfg_strings.h>
  52. #include <adf_cfg_common.h>
  53. #include <adf_transport_access_macros.h>
  54. #include <adf_transport_internal.h>
  55. #include <adf_pf2vf_msg.h>
  56. #include "adf_drv.h"
  57. #include "adf_dh895xccvf_hw_data.h"
  58. static int adf_enable_msi(struct adf_accel_dev *accel_dev)
  59. {
  60. struct adf_accel_pci *pci_dev_info = &accel_dev->accel_pci_dev;
  61. int stat = pci_enable_msi(pci_dev_info->pci_dev);
  62. if (stat) {
  63. dev_err(&GET_DEV(accel_dev),
  64. "Failed to enable MSI interrupts\n");
  65. return stat;
  66. }
  67. accel_dev->vf.irq_name = kzalloc(ADF_MAX_MSIX_VECTOR_NAME, GFP_KERNEL);
  68. if (!accel_dev->vf.irq_name)
  69. return -ENOMEM;
  70. return stat;
  71. }
  72. static void adf_disable_msi(struct adf_accel_dev *accel_dev)
  73. {
  74. struct pci_dev *pdev = accel_to_pci_dev(accel_dev);
  75. kfree(accel_dev->vf.irq_name);
  76. pci_disable_msi(pdev);
  77. }
  78. static void adf_pf2vf_bh_handler(void *data)
  79. {
  80. struct adf_accel_dev *accel_dev = data;
  81. void __iomem *pmisc_bar_addr =
  82. (&GET_BARS(accel_dev)[ADF_DH895XCCIOV_PMISC_BAR])->virt_addr;
  83. u32 msg;
  84. /* Read the message from PF */
  85. msg = ADF_CSR_RD(pmisc_bar_addr, ADF_DH895XCCIOV_PF2VF_OFFSET);
  86. if (!(msg & ADF_PF2VF_MSGORIGIN_SYSTEM))
  87. /* Ignore legacy non-system (non-kernel) PF2VF messages */
  88. goto err;
  89. switch ((msg & ADF_PF2VF_MSGTYPE_MASK) >> ADF_PF2VF_MSGTYPE_SHIFT) {
  90. case ADF_PF2VF_MSGTYPE_RESTARTING:
  91. dev_dbg(&GET_DEV(accel_dev),
  92. "Restarting msg received from PF 0x%x\n", msg);
  93. adf_dev_stop(accel_dev);
  94. break;
  95. case ADF_PF2VF_MSGTYPE_VERSION_RESP:
  96. dev_dbg(&GET_DEV(accel_dev),
  97. "Version resp received from PF 0x%x\n", msg);
  98. accel_dev->vf.pf_version =
  99. (msg & ADF_PF2VF_VERSION_RESP_VERS_MASK) >>
  100. ADF_PF2VF_VERSION_RESP_VERS_SHIFT;
  101. accel_dev->vf.compatible =
  102. (msg & ADF_PF2VF_VERSION_RESP_RESULT_MASK) >>
  103. ADF_PF2VF_VERSION_RESP_RESULT_SHIFT;
  104. complete(&accel_dev->vf.iov_msg_completion);
  105. break;
  106. default:
  107. goto err;
  108. }
  109. /* To ack, clear the PF2VFINT bit */
  110. msg &= ~ADF_DH895XCC_PF2VF_PF2VFINT;
  111. ADF_CSR_WR(pmisc_bar_addr, ADF_DH895XCCIOV_PF2VF_OFFSET, msg);
  112. /* Re-enable PF2VF interrupts */
  113. adf_enable_pf2vf_interrupts(accel_dev);
  114. return;
  115. err:
  116. dev_err(&GET_DEV(accel_dev),
  117. "Unknown message from PF (0x%x); leaving PF2VF ints disabled\n",
  118. msg);
  119. }
  120. static int adf_setup_pf2vf_bh(struct adf_accel_dev *accel_dev)
  121. {
  122. tasklet_init(&accel_dev->vf.pf2vf_bh_tasklet,
  123. (void *)adf_pf2vf_bh_handler, (unsigned long)accel_dev);
  124. mutex_init(&accel_dev->vf.vf2pf_lock);
  125. return 0;
  126. }
  127. static void adf_cleanup_pf2vf_bh(struct adf_accel_dev *accel_dev)
  128. {
  129. tasklet_disable(&accel_dev->vf.pf2vf_bh_tasklet);
  130. tasklet_kill(&accel_dev->vf.pf2vf_bh_tasklet);
  131. mutex_destroy(&accel_dev->vf.vf2pf_lock);
  132. }
  133. static irqreturn_t adf_isr(int irq, void *privdata)
  134. {
  135. struct adf_accel_dev *accel_dev = privdata;
  136. void __iomem *pmisc_bar_addr =
  137. (&GET_BARS(accel_dev)[ADF_DH895XCCIOV_PMISC_BAR])->virt_addr;
  138. u32 v_int;
  139. /* Read VF INT source CSR to determine the source of VF interrupt */
  140. v_int = ADF_CSR_RD(pmisc_bar_addr, ADF_DH895XCCIOV_VINTSOU_OFFSET);
  141. /* Check for PF2VF interrupt */
  142. if (v_int & ADF_DH895XCC_VINTSOU_PF2VF) {
  143. /* Disable PF to VF interrupt */
  144. adf_disable_pf2vf_interrupts(accel_dev);
  145. /* Schedule tasklet to handle interrupt BH */
  146. tasklet_hi_schedule(&accel_dev->vf.pf2vf_bh_tasklet);
  147. return IRQ_HANDLED;
  148. }
  149. /* Check bundle interrupt */
  150. if (v_int & ADF_DH895XCC_VINTSOU_BUN) {
  151. struct adf_etr_data *etr_data = accel_dev->transport;
  152. struct adf_etr_bank_data *bank = &etr_data->banks[0];
  153. /* Disable Flag and Coalesce Ring Interrupts */
  154. WRITE_CSR_INT_FLAG_AND_COL(bank->csr_addr, bank->bank_number,
  155. 0);
  156. tasklet_hi_schedule(&bank->resp_handler);
  157. return IRQ_HANDLED;
  158. }
  159. return IRQ_NONE;
  160. }
  161. static int adf_request_msi_irq(struct adf_accel_dev *accel_dev)
  162. {
  163. struct pci_dev *pdev = accel_to_pci_dev(accel_dev);
  164. unsigned int cpu;
  165. int ret;
  166. snprintf(accel_dev->vf.irq_name, ADF_MAX_MSIX_VECTOR_NAME,
  167. "qat_%02x:%02d.%02d", pdev->bus->number, PCI_SLOT(pdev->devfn),
  168. PCI_FUNC(pdev->devfn));
  169. ret = request_irq(pdev->irq, adf_isr, 0, accel_dev->vf.irq_name,
  170. (void *)accel_dev);
  171. if (ret) {
  172. dev_err(&GET_DEV(accel_dev), "failed to enable irq for %s\n",
  173. accel_dev->vf.irq_name);
  174. return ret;
  175. }
  176. cpu = accel_dev->accel_id % num_online_cpus();
  177. irq_set_affinity_hint(pdev->irq, get_cpu_mask(cpu));
  178. return ret;
  179. }
  180. static int adf_setup_bh(struct adf_accel_dev *accel_dev)
  181. {
  182. struct adf_etr_data *priv_data = accel_dev->transport;
  183. tasklet_init(&priv_data->banks[0].resp_handler, adf_response_handler,
  184. (unsigned long)priv_data->banks);
  185. return 0;
  186. }
  187. static void adf_cleanup_bh(struct adf_accel_dev *accel_dev)
  188. {
  189. struct adf_etr_data *priv_data = accel_dev->transport;
  190. tasklet_disable(&priv_data->banks[0].resp_handler);
  191. tasklet_kill(&priv_data->banks[0].resp_handler);
  192. }
  193. void adf_vf_isr_resource_free(struct adf_accel_dev *accel_dev)
  194. {
  195. struct pci_dev *pdev = accel_to_pci_dev(accel_dev);
  196. irq_set_affinity_hint(pdev->irq, NULL);
  197. free_irq(pdev->irq, (void *)accel_dev);
  198. adf_cleanup_bh(accel_dev);
  199. adf_cleanup_pf2vf_bh(accel_dev);
  200. adf_disable_msi(accel_dev);
  201. }
  202. int adf_vf_isr_resource_alloc(struct adf_accel_dev *accel_dev)
  203. {
  204. if (adf_enable_msi(accel_dev))
  205. goto err_out;
  206. if (adf_setup_pf2vf_bh(accel_dev))
  207. goto err_out;
  208. if (adf_setup_bh(accel_dev))
  209. goto err_out;
  210. if (adf_request_msi_irq(accel_dev))
  211. goto err_out;
  212. return 0;
  213. err_out:
  214. adf_vf_isr_resource_free(accel_dev);
  215. return -EFAULT;
  216. }