unsolicited_frame_control.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * BSD LICENSE
  25. *
  26. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions
  31. * are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * * Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in
  37. * the documentation and/or other materials provided with the
  38. * distribution.
  39. * * Neither the name of Intel Corporation nor the names of its
  40. * contributors may be used to endorse or promote products derived
  41. * from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  44. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  46. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  47. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  49. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  50. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  51. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  52. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  53. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #include "host.h"
  56. #include "unsolicited_frame_control.h"
  57. #include "registers.h"
  58. void sci_unsolicited_frame_control_construct(struct isci_host *ihost)
  59. {
  60. struct sci_unsolicited_frame_control *uf_control = &ihost->uf_control;
  61. struct sci_unsolicited_frame *uf;
  62. dma_addr_t dma = ihost->ufi_dma;
  63. void *virt = ihost->ufi_buf;
  64. int i;
  65. /*
  66. * The Unsolicited Frame buffers are set at the start of the UF
  67. * memory descriptor entry. The headers and address table will be
  68. * placed after the buffers.
  69. */
  70. /*
  71. * Program the location of the UF header table into the SCU.
  72. * Notes:
  73. * - The address must align on a 64-byte boundary. Guaranteed to be
  74. * on 64-byte boundary already 1KB boundary for unsolicited frames.
  75. * - Program unused header entries to overlap with the last
  76. * unsolicited frame. The silicon will never DMA to these unused
  77. * headers, since we program the UF address table pointers to
  78. * NULL.
  79. */
  80. uf_control->headers.physical_address = dma + SCI_UFI_BUF_SIZE;
  81. uf_control->headers.array = virt + SCI_UFI_BUF_SIZE;
  82. /*
  83. * Program the location of the UF address table into the SCU.
  84. * Notes:
  85. * - The address must align on a 64-bit boundary. Guaranteed to be on 64
  86. * byte boundary already due to above programming headers being on a
  87. * 64-bit boundary and headers are on a 64-bytes in size.
  88. */
  89. uf_control->address_table.physical_address = dma + SCI_UFI_BUF_SIZE + SCI_UFI_HDR_SIZE;
  90. uf_control->address_table.array = virt + SCI_UFI_BUF_SIZE + SCI_UFI_HDR_SIZE;
  91. uf_control->get = 0;
  92. /*
  93. * UF buffer requirements are:
  94. * - The last entry in the UF queue is not NULL.
  95. * - There is a power of 2 number of entries (NULL or not-NULL)
  96. * programmed into the queue.
  97. * - Aligned on a 1KB boundary. */
  98. /*
  99. * Program the actual used UF buffers into the UF address table and
  100. * the controller's array of UFs.
  101. */
  102. for (i = 0; i < SCU_MAX_UNSOLICITED_FRAMES; i++) {
  103. uf = &uf_control->buffers.array[i];
  104. uf_control->address_table.array[i] = dma;
  105. uf->buffer = virt;
  106. uf->header = &uf_control->headers.array[i];
  107. uf->state = UNSOLICITED_FRAME_EMPTY;
  108. /*
  109. * Increment the address of the physical and virtual memory
  110. * pointers. Everything is aligned on 1k boundary with an
  111. * increment of 1k.
  112. */
  113. virt += SCU_UNSOLICITED_FRAME_BUFFER_SIZE;
  114. dma += SCU_UNSOLICITED_FRAME_BUFFER_SIZE;
  115. }
  116. }
  117. enum sci_status sci_unsolicited_frame_control_get_header(struct sci_unsolicited_frame_control *uf_control,
  118. u32 frame_index,
  119. void **frame_header)
  120. {
  121. if (frame_index < SCU_MAX_UNSOLICITED_FRAMES) {
  122. /* Skip the first word in the frame since this is a controll word used
  123. * by the hardware.
  124. */
  125. *frame_header = &uf_control->buffers.array[frame_index].header->data;
  126. return SCI_SUCCESS;
  127. }
  128. return SCI_FAILURE_INVALID_PARAMETER_VALUE;
  129. }
  130. enum sci_status sci_unsolicited_frame_control_get_buffer(struct sci_unsolicited_frame_control *uf_control,
  131. u32 frame_index,
  132. void **frame_buffer)
  133. {
  134. if (frame_index < SCU_MAX_UNSOLICITED_FRAMES) {
  135. *frame_buffer = uf_control->buffers.array[frame_index].buffer;
  136. return SCI_SUCCESS;
  137. }
  138. return SCI_FAILURE_INVALID_PARAMETER_VALUE;
  139. }
  140. bool sci_unsolicited_frame_control_release_frame(struct sci_unsolicited_frame_control *uf_control,
  141. u32 frame_index)
  142. {
  143. u32 frame_get;
  144. u32 frame_cycle;
  145. frame_get = uf_control->get & (SCU_MAX_UNSOLICITED_FRAMES - 1);
  146. frame_cycle = uf_control->get & SCU_MAX_UNSOLICITED_FRAMES;
  147. /*
  148. * In the event there are NULL entries in the UF table, we need to
  149. * advance the get pointer in order to find out if this frame should
  150. * be released (i.e. update the get pointer)
  151. */
  152. while (lower_32_bits(uf_control->address_table.array[frame_get]) == 0 &&
  153. upper_32_bits(uf_control->address_table.array[frame_get]) == 0 &&
  154. frame_get < SCU_MAX_UNSOLICITED_FRAMES)
  155. frame_get++;
  156. /*
  157. * The table has a NULL entry as it's last element. This is
  158. * illegal.
  159. */
  160. BUG_ON(frame_get >= SCU_MAX_UNSOLICITED_FRAMES);
  161. if (frame_index >= SCU_MAX_UNSOLICITED_FRAMES)
  162. return false;
  163. uf_control->buffers.array[frame_index].state = UNSOLICITED_FRAME_RELEASED;
  164. if (frame_get != frame_index) {
  165. /*
  166. * Frames remain in use until we advance the get pointer
  167. * so there is nothing we can do here
  168. */
  169. return false;
  170. }
  171. /*
  172. * The frame index is equal to the current get pointer so we
  173. * can now free up all of the frame entries that
  174. */
  175. while (uf_control->buffers.array[frame_get].state == UNSOLICITED_FRAME_RELEASED) {
  176. uf_control->buffers.array[frame_get].state = UNSOLICITED_FRAME_EMPTY;
  177. if (frame_get+1 == SCU_MAX_UNSOLICITED_FRAMES-1) {
  178. frame_cycle ^= SCU_MAX_UNSOLICITED_FRAMES;
  179. frame_get = 0;
  180. } else
  181. frame_get++;
  182. }
  183. uf_control->get = SCU_UFQGP_GEN_BIT(ENABLE_BIT) | frame_cycle | frame_get;
  184. return true;
  185. }