adf_hw_arbiter.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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_common_drv.h"
  43. #include "adf_transport_internal.h"
  44. #define ADF_ARB_NUM 4
  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_SARCONFIG(csr_addr, index, value) \
  58. ADF_CSR_WR(csr_addr, ADF_ARB_OFFSET + \
  59. (ADF_ARB_REG_SIZE * index), value)
  60. #define WRITE_CSR_ARB_WRK_2_SER_MAP(csr_addr, index, value) \
  61. ADF_CSR_WR(csr_addr, (ADF_ARB_OFFSET + \
  62. ADF_ARB_WRK_2_SER_MAP_OFFSET) + \
  63. (ADF_ARB_REG_SIZE * index), value)
  64. #define WRITE_CSR_ARB_WQCFG(csr_addr, index, value) \
  65. ADF_CSR_WR(csr_addr, (ADF_ARB_OFFSET + \
  66. ADF_ARB_WQCFG_OFFSET) + (ADF_ARB_REG_SIZE * index), value)
  67. int adf_init_arb(struct adf_accel_dev *accel_dev)
  68. {
  69. struct adf_hw_device_data *hw_data = accel_dev->hw_device;
  70. void __iomem *csr = accel_dev->transport->banks[0].csr_addr;
  71. u32 arb_cfg = 0x1 << 31 | 0x4 << 4 | 0x1;
  72. u32 arb, i;
  73. const u32 *thd_2_arb_cfg;
  74. /* Service arb configured for 32 bytes responses and
  75. * ring flow control check enabled. */
  76. for (arb = 0; arb < ADF_ARB_NUM; arb++)
  77. WRITE_CSR_ARB_SARCONFIG(csr, arb, arb_cfg);
  78. /* Setup worker queue registers */
  79. for (i = 0; i < hw_data->num_engines; i++)
  80. WRITE_CSR_ARB_WQCFG(csr, i, i);
  81. /* Map worker threads to service arbiters */
  82. hw_data->get_arb_mapping(accel_dev, &thd_2_arb_cfg);
  83. if (!thd_2_arb_cfg)
  84. return -EFAULT;
  85. for (i = 0; i < hw_data->num_engines; i++)
  86. WRITE_CSR_ARB_WRK_2_SER_MAP(csr, i, *(thd_2_arb_cfg + i));
  87. return 0;
  88. }
  89. EXPORT_SYMBOL_GPL(adf_init_arb);
  90. void adf_update_ring_arb(struct adf_etr_ring_data *ring)
  91. {
  92. WRITE_CSR_ARB_RINGSRVARBEN(ring->bank->csr_addr,
  93. ring->bank->bank_number,
  94. ring->bank->ring_mask & 0xFF);
  95. }
  96. void adf_exit_arb(struct adf_accel_dev *accel_dev)
  97. {
  98. struct adf_hw_device_data *hw_data = accel_dev->hw_device;
  99. void __iomem *csr;
  100. unsigned int i;
  101. if (!accel_dev->transport)
  102. return;
  103. csr = accel_dev->transport->banks[0].csr_addr;
  104. /* Reset arbiter configuration */
  105. for (i = 0; i < ADF_ARB_NUM; i++)
  106. WRITE_CSR_ARB_SARCONFIG(csr, i, 0);
  107. /* Shutdown work queue */
  108. for (i = 0; i < hw_data->num_engines; i++)
  109. WRITE_CSR_ARB_WQCFG(csr, i, 0);
  110. /* Unmap worker threads to service arbiters */
  111. for (i = 0; i < hw_data->num_engines; i++)
  112. WRITE_CSR_ARB_WRK_2_SER_MAP(csr, i, 0);
  113. /* Disable arbitration on all rings */
  114. for (i = 0; i < GET_MAX_BANKS(accel_dev); i++)
  115. WRITE_CSR_ARB_RINGSRVARBEN(csr, i, 0);
  116. }
  117. EXPORT_SYMBOL_GPL(adf_exit_arb);