ctxt-info-gen3.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2018 Intel Corporation
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * BSD LICENSE
  20. *
  21. * Copyright(c) 2018 Intel Corporation
  22. * All rights reserved.
  23. *
  24. * Redistribution and use in source and binary forms, with or without
  25. * modification, are permitted provided that the following conditions
  26. * are met:
  27. *
  28. * * Redistributions of source code must retain the above copyright
  29. * notice, this list of conditions and the following disclaimer.
  30. * * Redistributions in binary form must reproduce the above copyright
  31. * notice, this list of conditions and the following disclaimer in
  32. * the documentation and/or other materials provided with the
  33. * distribution.
  34. * * Neither the name Intel Corporation nor the names of its
  35. * contributors may be used to endorse or promote products derived
  36. * from this software without specific prior written permission.
  37. *
  38. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  39. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  41. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  42. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  43. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  44. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  45. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  46. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  47. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  48. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. *
  50. *****************************************************************************/
  51. #include "iwl-trans.h"
  52. #include "iwl-fh.h"
  53. #include "iwl-context-info-gen3.h"
  54. #include "internal.h"
  55. #include "iwl-prph.h"
  56. int iwl_pcie_ctxt_info_gen3_init(struct iwl_trans *trans,
  57. const struct fw_img *fw)
  58. {
  59. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  60. struct iwl_context_info_gen3 *ctxt_info_gen3;
  61. struct iwl_prph_scratch *prph_scratch;
  62. struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl;
  63. struct iwl_prph_info *prph_info;
  64. void *iml_img;
  65. u32 control_flags = 0;
  66. int ret;
  67. /* Allocate prph scratch */
  68. prph_scratch = dma_alloc_coherent(trans->dev, sizeof(*prph_scratch),
  69. &trans_pcie->prph_scratch_dma_addr,
  70. GFP_KERNEL);
  71. if (!prph_scratch)
  72. return -ENOMEM;
  73. prph_sc_ctrl = &prph_scratch->ctrl_cfg;
  74. prph_sc_ctrl->version.version = 0;
  75. prph_sc_ctrl->version.mac_id =
  76. cpu_to_le16((u16)iwl_read32(trans, CSR_HW_REV));
  77. prph_sc_ctrl->version.size = cpu_to_le16(sizeof(*prph_scratch) / 4);
  78. control_flags = IWL_PRPH_SCRATCH_RB_SIZE_4K |
  79. IWL_PRPH_SCRATCH_MTR_MODE |
  80. (IWL_PRPH_MTR_FORMAT_256B &
  81. IWL_PRPH_SCRATCH_MTR_FORMAT) |
  82. IWL_PRPH_SCRATCH_EARLY_DEBUG_EN |
  83. IWL_PRPH_SCRATCH_EDBG_DEST_DRAM;
  84. prph_sc_ctrl->control.control_flags = cpu_to_le32(control_flags);
  85. /* initialize RX default queue */
  86. prph_sc_ctrl->rbd_cfg.free_rbd_addr =
  87. cpu_to_le64(trans_pcie->rxq->bd_dma);
  88. /* Configure debug, for integration */
  89. iwl_pcie_alloc_fw_monitor(trans, 0);
  90. prph_sc_ctrl->hwm_cfg.hwm_base_addr =
  91. cpu_to_le64(trans_pcie->fw_mon_phys);
  92. prph_sc_ctrl->hwm_cfg.hwm_size =
  93. cpu_to_le32(trans_pcie->fw_mon_size);
  94. /* allocate ucode sections in dram and set addresses */
  95. ret = iwl_pcie_init_fw_sec(trans, fw, &prph_scratch->dram);
  96. if (ret) {
  97. dma_free_coherent(trans->dev,
  98. sizeof(*prph_scratch),
  99. prph_scratch,
  100. trans_pcie->prph_scratch_dma_addr);
  101. return ret;
  102. }
  103. /* Allocate prph information
  104. * currently we don't assign to the prph info anything, but it would get
  105. * assigned later */
  106. prph_info = dma_alloc_coherent(trans->dev, sizeof(*prph_info),
  107. &trans_pcie->prph_info_dma_addr,
  108. GFP_KERNEL);
  109. if (!prph_info)
  110. return -ENOMEM;
  111. /* Allocate context info */
  112. ctxt_info_gen3 = dma_alloc_coherent(trans->dev,
  113. sizeof(*ctxt_info_gen3),
  114. &trans_pcie->ctxt_info_dma_addr,
  115. GFP_KERNEL);
  116. if (!ctxt_info_gen3)
  117. return -ENOMEM;
  118. ctxt_info_gen3->prph_info_base_addr =
  119. cpu_to_le64(trans_pcie->prph_info_dma_addr);
  120. ctxt_info_gen3->prph_scratch_base_addr =
  121. cpu_to_le64(trans_pcie->prph_scratch_dma_addr);
  122. ctxt_info_gen3->prph_scratch_size =
  123. cpu_to_le32(sizeof(*prph_scratch));
  124. ctxt_info_gen3->cr_head_idx_arr_base_addr =
  125. cpu_to_le64(trans_pcie->rxq->rb_stts_dma);
  126. ctxt_info_gen3->tr_tail_idx_arr_base_addr =
  127. cpu_to_le64(trans_pcie->rxq->tr_tail_dma);
  128. ctxt_info_gen3->cr_tail_idx_arr_base_addr =
  129. cpu_to_le64(trans_pcie->rxq->cr_tail_dma);
  130. ctxt_info_gen3->cr_idx_arr_size =
  131. cpu_to_le16(IWL_NUM_OF_COMPLETION_RINGS);
  132. ctxt_info_gen3->tr_idx_arr_size =
  133. cpu_to_le16(IWL_NUM_OF_TRANSFER_RINGS);
  134. ctxt_info_gen3->mtr_base_addr =
  135. cpu_to_le64(trans_pcie->txq[trans_pcie->cmd_queue]->dma_addr);
  136. ctxt_info_gen3->mcr_base_addr =
  137. cpu_to_le64(trans_pcie->rxq->used_bd_dma);
  138. ctxt_info_gen3->mtr_size =
  139. cpu_to_le16(TFD_QUEUE_CB_SIZE(TFD_CMD_SLOTS));
  140. ctxt_info_gen3->mcr_size =
  141. cpu_to_le16(RX_QUEUE_CB_SIZE(MQ_RX_TABLE_SIZE));
  142. trans_pcie->ctxt_info_gen3 = ctxt_info_gen3;
  143. trans_pcie->prph_info = prph_info;
  144. trans_pcie->prph_scratch = prph_scratch;
  145. /* Allocate IML */
  146. iml_img = dma_alloc_coherent(trans->dev, trans->iml_len,
  147. &trans_pcie->iml_dma_addr, GFP_KERNEL);
  148. if (!iml_img)
  149. return -ENOMEM;
  150. memcpy(iml_img, trans->iml, trans->iml_len);
  151. iwl_enable_interrupts(trans);
  152. /* kick FW self load */
  153. iwl_write64(trans, CSR_CTXT_INFO_ADDR,
  154. trans_pcie->ctxt_info_dma_addr);
  155. iwl_write64(trans, CSR_IML_DATA_ADDR,
  156. trans_pcie->iml_dma_addr);
  157. iwl_write32(trans, CSR_IML_SIZE_ADDR, trans->iml_len);
  158. iwl_set_bit(trans, CSR_CTXT_INFO_BOOT_CTRL, CSR_AUTO_FUNC_BOOT_ENA);
  159. iwl_set_bit(trans, CSR_GP_CNTRL, CSR_AUTO_FUNC_INIT);
  160. return 0;
  161. }
  162. void iwl_pcie_ctxt_info_gen3_free(struct iwl_trans *trans)
  163. {
  164. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  165. if (!trans_pcie->ctxt_info_gen3)
  166. return;
  167. dma_free_coherent(trans->dev, sizeof(*trans_pcie->ctxt_info_gen3),
  168. trans_pcie->ctxt_info_gen3,
  169. trans_pcie->ctxt_info_dma_addr);
  170. trans_pcie->ctxt_info_dma_addr = 0;
  171. trans_pcie->ctxt_info_gen3 = NULL;
  172. iwl_pcie_ctxt_info_free_fw_img(trans);
  173. dma_free_coherent(trans->dev, sizeof(*trans_pcie->prph_scratch),
  174. trans_pcie->prph_scratch,
  175. trans_pcie->prph_scratch_dma_addr);
  176. trans_pcie->prph_scratch_dma_addr = 0;
  177. trans_pcie->prph_scratch = NULL;
  178. dma_free_coherent(trans->dev, sizeof(*trans_pcie->prph_info),
  179. trans_pcie->prph_info,
  180. trans_pcie->prph_info_dma_addr);
  181. trans_pcie->prph_info_dma_addr = 0;
  182. trans_pcie->prph_info = NULL;
  183. }