adf_hw_arbiter.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 "adf_accel_devices.h"
  42. #include "adf_transport_internal.h"
  43. #define ADF_ARB_NUM 4
  44. #define ADF_ARB_REQ_RING_NUM 8
  45. #define ADF_ARB_REG_SIZE 0x4
  46. #define ADF_ARB_WTR_SIZE 0x20
  47. #define ADF_ARB_OFFSET 0x30000
  48. #define ADF_ARB_REG_SLOT 0x1000
  49. #define ADF_ARB_WTR_OFFSET 0x010
  50. #define ADF_ARB_RO_EN_OFFSET 0x090
  51. #define ADF_ARB_WQCFG_OFFSET 0x100
  52. #define ADF_ARB_WRK_2_SER_MAP_OFFSET 0x180
  53. #define ADF_ARB_RINGSRVARBEN_OFFSET 0x19C
  54. #define WRITE_CSR_ARB_RINGSRVARBEN(csr_addr, index, value) \
  55. ADF_CSR_WR(csr_addr, ADF_ARB_RINGSRVARBEN_OFFSET + \
  56. (ADF_ARB_REG_SLOT * index), value)
  57. #define WRITE_CSR_ARB_RESPORDERING(csr_addr, index, value) \
  58. ADF_CSR_WR(csr_addr, (ADF_ARB_OFFSET + \
  59. ADF_ARB_RO_EN_OFFSET) + (ADF_ARB_REG_SIZE * index), value)
  60. #define WRITE_CSR_ARB_WEIGHT(csr_addr, arb, index, value) \
  61. ADF_CSR_WR(csr_addr, (ADF_ARB_OFFSET + \
  62. ADF_ARB_WTR_OFFSET) + (ADF_ARB_WTR_SIZE * arb) + \
  63. (ADF_ARB_REG_SIZE * index), value)
  64. #define WRITE_CSR_ARB_SARCONFIG(csr_addr, index, value) \
  65. ADF_CSR_WR(csr_addr, ADF_ARB_OFFSET + \
  66. (ADF_ARB_REG_SIZE * index), value)
  67. #define WRITE_CSR_ARB_WRK_2_SER_MAP(csr_addr, index, value) \
  68. ADF_CSR_WR(csr_addr, (ADF_ARB_OFFSET + \
  69. ADF_ARB_WRK_2_SER_MAP_OFFSET) + \
  70. (ADF_ARB_REG_SIZE * index), value)
  71. #define WRITE_CSR_ARB_WQCFG(csr_addr, index, value) \
  72. ADF_CSR_WR(csr_addr, (ADF_ARB_OFFSET + \
  73. ADF_ARB_WQCFG_OFFSET) + (ADF_ARB_REG_SIZE * index), value)
  74. int adf_init_arb(struct adf_accel_dev *accel_dev)
  75. {
  76. struct adf_hw_device_data *hw_data = accel_dev->hw_device;
  77. void __iomem *csr = accel_dev->transport->banks[0].csr_addr;
  78. u32 arb_cfg = 0x1 << 31 | 0x4 << 4 | 0x1;
  79. u32 arb, i;
  80. const u32 *thd_2_arb_cfg;
  81. /* Service arb configured for 32 bytes responses and
  82. * ring flow control check enabled. */
  83. for (arb = 0; arb < ADF_ARB_NUM; arb++)
  84. WRITE_CSR_ARB_SARCONFIG(csr, arb, arb_cfg);
  85. /* Setup service weighting */
  86. for (arb = 0; arb < ADF_ARB_NUM; arb++)
  87. for (i = 0; i < ADF_ARB_REQ_RING_NUM; i++)
  88. WRITE_CSR_ARB_WEIGHT(csr, arb, i, 0xFFFFFFFF);
  89. /* Setup ring response ordering */
  90. for (i = 0; i < ADF_ARB_REQ_RING_NUM; i++)
  91. WRITE_CSR_ARB_RESPORDERING(csr, i, 0xFFFFFFFF);
  92. /* Setup worker queue registers */
  93. for (i = 0; i < hw_data->num_engines; i++)
  94. WRITE_CSR_ARB_WQCFG(csr, i, i);
  95. /* Map worker threads to service arbiters */
  96. hw_data->get_arb_mapping(accel_dev, &thd_2_arb_cfg);
  97. if (!thd_2_arb_cfg)
  98. return -EFAULT;
  99. for (i = 0; i < hw_data->num_engines; i++)
  100. WRITE_CSR_ARB_WRK_2_SER_MAP(csr, i, *(thd_2_arb_cfg + i));
  101. return 0;
  102. }
  103. EXPORT_SYMBOL_GPL(adf_init_arb);
  104. /**
  105. * adf_update_ring_arb() - update ring arbitration rgister
  106. * @accel_dev: Pointer to ring data.
  107. *
  108. * Function enables or disables rings for/from arbitration.
  109. */
  110. void adf_update_ring_arb(struct adf_etr_ring_data *ring)
  111. {
  112. WRITE_CSR_ARB_RINGSRVARBEN(ring->bank->csr_addr,
  113. ring->bank->bank_number,
  114. ring->bank->ring_mask & 0xFF);
  115. }
  116. EXPORT_SYMBOL_GPL(adf_update_ring_arb);
  117. void adf_exit_arb(struct adf_accel_dev *accel_dev)
  118. {
  119. struct adf_hw_device_data *hw_data = accel_dev->hw_device;
  120. void __iomem *csr;
  121. unsigned int i;
  122. if (!accel_dev->transport)
  123. return;
  124. csr = accel_dev->transport->banks[0].csr_addr;
  125. /* Reset arbiter configuration */
  126. for (i = 0; i < ADF_ARB_NUM; i++)
  127. WRITE_CSR_ARB_SARCONFIG(csr, i, 0);
  128. /* Shutdown work queue */
  129. for (i = 0; i < hw_data->num_engines; i++)
  130. WRITE_CSR_ARB_WQCFG(csr, i, 0);
  131. /* Unmap worker threads to service arbiters */
  132. for (i = 0; i < hw_data->num_engines; i++)
  133. WRITE_CSR_ARB_WRK_2_SER_MAP(csr, i, 0);
  134. /* Disable arbitration on all rings */
  135. for (i = 0; i < GET_MAX_BANKS(accel_dev); i++)
  136. WRITE_CSR_ARB_RINGSRVARBEN(csr, i, 0);
  137. }
  138. EXPORT_SYMBOL_GPL(adf_exit_arb);