request.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. #ifndef _ISCI_REQUEST_H_
  56. #define _ISCI_REQUEST_H_
  57. #include "isci.h"
  58. #include "host.h"
  59. #include "scu_task_context.h"
  60. /**
  61. * isci_stp_request - extra request infrastructure to handle pio/atapi protocol
  62. * @pio_len - number of bytes requested at PIO setup
  63. * @status - pio setup ending status value to tell us if we need
  64. * to wait for another fis or if the transfer is complete. Upon
  65. * receipt of a d2h fis this will be the status field of that fis.
  66. * @sgl - track pio transfer progress as we iterate through the sgl
  67. */
  68. struct isci_stp_request {
  69. u32 pio_len;
  70. u8 status;
  71. struct isci_stp_pio_sgl {
  72. int index;
  73. u8 set;
  74. u32 offset;
  75. } sgl;
  76. };
  77. struct isci_request {
  78. #define IREQ_COMPLETE_IN_TARGET 0
  79. #define IREQ_TERMINATED 1
  80. #define IREQ_TMF 2
  81. #define IREQ_ACTIVE 3
  82. #define IREQ_PENDING_ABORT 4 /* Set == device was not suspended yet */
  83. #define IREQ_TC_ABORT_POSTED 5
  84. #define IREQ_ABORT_PATH_ACTIVE 6
  85. unsigned long flags;
  86. /* XXX kill ttype and ttype_ptr, allocate full sas_task */
  87. union ttype_ptr_union {
  88. struct sas_task *io_task_ptr; /* When ttype==io_task */
  89. struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */
  90. } ttype_ptr;
  91. struct isci_host *isci_host;
  92. /* For use in the requests_to_{complete|abort} lists: */
  93. struct list_head completed_node;
  94. dma_addr_t request_daddr;
  95. dma_addr_t zero_scatter_daddr;
  96. unsigned int num_sg_entries;
  97. /* Note: "io_request_completion" is completed in two different ways
  98. * depending on whether this is a TMF or regular request.
  99. * - TMF requests are completed in the thread that started them;
  100. * - regular requests are completed in the request completion callback
  101. * function.
  102. * This difference in operation allows the aborter of a TMF request
  103. * to be sure that once the TMF request completes, the I/O that the
  104. * TMF was aborting is guaranteed to have completed.
  105. *
  106. * XXX kill io_request_completion
  107. */
  108. struct completion *io_request_completion;
  109. struct sci_base_state_machine sm;
  110. struct isci_host *owning_controller;
  111. struct isci_remote_device *target_device;
  112. u16 io_tag;
  113. enum sas_protocol protocol;
  114. u32 scu_status; /* hardware result */
  115. u32 sci_status; /* upper layer disposition */
  116. u32 post_context;
  117. struct scu_task_context *tc;
  118. /* could be larger with sg chaining */
  119. #define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2)
  120. struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32)));
  121. /* This field is a pointer to the stored rx frame data. It is used in
  122. * STP internal requests and SMP response frames. If this field is
  123. * non-NULL the saved frame must be released on IO request completion.
  124. */
  125. u32 saved_rx_frame_index;
  126. union {
  127. struct {
  128. union {
  129. struct ssp_cmd_iu cmd;
  130. struct ssp_task_iu tmf;
  131. };
  132. union {
  133. struct ssp_response_iu rsp;
  134. u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
  135. };
  136. } ssp;
  137. struct {
  138. struct isci_stp_request req;
  139. struct host_to_dev_fis cmd;
  140. struct dev_to_host_fis rsp;
  141. } stp;
  142. };
  143. };
  144. static inline struct isci_request *to_ireq(struct isci_stp_request *stp_req)
  145. {
  146. struct isci_request *ireq;
  147. ireq = container_of(stp_req, typeof(*ireq), stp.req);
  148. return ireq;
  149. }
  150. /**
  151. * enum sci_base_request_states - request state machine states
  152. *
  153. * @SCI_REQ_INIT: Simply the initial state for the base request state machine.
  154. *
  155. * @SCI_REQ_CONSTRUCTED: This state indicates that the request has been
  156. * constructed. This state is entered from the INITIAL state.
  157. *
  158. * @SCI_REQ_STARTED: This state indicates that the request has been started.
  159. * This state is entered from the CONSTRUCTED state.
  160. *
  161. * @SCI_REQ_STP_UDMA_WAIT_TC_COMP:
  162. * @SCI_REQ_STP_UDMA_WAIT_D2H:
  163. * @SCI_REQ_STP_NON_DATA_WAIT_H2D:
  164. * @SCI_REQ_STP_NON_DATA_WAIT_D2H:
  165. *
  166. * @SCI_REQ_STP_PIO_WAIT_H2D: While in this state the IO request object is
  167. * waiting for the TC completion notification for the H2D Register FIS
  168. *
  169. * @SCI_REQ_STP_PIO_WAIT_FRAME: While in this state the IO request object is
  170. * waiting for either a PIO Setup FIS or a D2H register FIS. The type of frame
  171. * received is based on the result of the prior frame and line conditions.
  172. *
  173. * @SCI_REQ_STP_PIO_DATA_IN: While in this state the IO request object is
  174. * waiting for a DATA frame from the device.
  175. *
  176. * @SCI_REQ_STP_PIO_DATA_OUT: While in this state the IO request object is
  177. * waiting to transmit the next data frame to the device.
  178. *
  179. * @SCI_REQ_ATAPI_WAIT_H2D: While in this state the IO request object is
  180. * waiting for the TC completion notification for the H2D Register FIS
  181. *
  182. * @SCI_REQ_ATAPI_WAIT_PIO_SETUP: While in this state the IO request object is
  183. * waiting for either a PIO Setup.
  184. *
  185. * @SCI_REQ_ATAPI_WAIT_D2H: The non-data IO transit to this state in this state
  186. * after receiving TC completion. While in this state IO request object is
  187. * waiting for D2H status frame as UF.
  188. *
  189. * @SCI_REQ_ATAPI_WAIT_TC_COMP: When transmitting raw frames hardware reports
  190. * task context completion after every frame submission, so in the
  191. * non-accelerated case we need to expect the completion for the "cdb" frame.
  192. *
  193. * @SCI_REQ_TASK_WAIT_TC_COMP: The AWAIT_TC_COMPLETION sub-state indicates that
  194. * the started raw task management request is waiting for the transmission of
  195. * the initial frame (i.e. command, task, etc.).
  196. *
  197. * @SCI_REQ_TASK_WAIT_TC_RESP: This sub-state indicates that the started task
  198. * management request is waiting for the reception of an unsolicited frame
  199. * (i.e. response IU).
  200. *
  201. * @SCI_REQ_SMP_WAIT_RESP: This sub-state indicates that the started task
  202. * management request is waiting for the reception of an unsolicited frame
  203. * (i.e. response IU).
  204. *
  205. * @SCI_REQ_SMP_WAIT_TC_COMP: The AWAIT_TC_COMPLETION sub-state indicates that
  206. * the started SMP request is waiting for the transmission of the initial frame
  207. * (i.e. command, task, etc.).
  208. *
  209. * @SCI_REQ_COMPLETED: This state indicates that the request has completed.
  210. * This state is entered from the STARTED state. This state is entered from the
  211. * ABORTING state.
  212. *
  213. * @SCI_REQ_ABORTING: This state indicates that the request is in the process
  214. * of being terminated/aborted. This state is entered from the CONSTRUCTED
  215. * state. This state is entered from the STARTED state.
  216. *
  217. * @SCI_REQ_FINAL: Simply the final state for the base request state machine.
  218. */
  219. #define REQUEST_STATES {\
  220. C(REQ_INIT),\
  221. C(REQ_CONSTRUCTED),\
  222. C(REQ_STARTED),\
  223. C(REQ_STP_UDMA_WAIT_TC_COMP),\
  224. C(REQ_STP_UDMA_WAIT_D2H),\
  225. C(REQ_STP_NON_DATA_WAIT_H2D),\
  226. C(REQ_STP_NON_DATA_WAIT_D2H),\
  227. C(REQ_STP_PIO_WAIT_H2D),\
  228. C(REQ_STP_PIO_WAIT_FRAME),\
  229. C(REQ_STP_PIO_DATA_IN),\
  230. C(REQ_STP_PIO_DATA_OUT),\
  231. C(REQ_ATAPI_WAIT_H2D),\
  232. C(REQ_ATAPI_WAIT_PIO_SETUP),\
  233. C(REQ_ATAPI_WAIT_D2H),\
  234. C(REQ_ATAPI_WAIT_TC_COMP),\
  235. C(REQ_TASK_WAIT_TC_COMP),\
  236. C(REQ_TASK_WAIT_TC_RESP),\
  237. C(REQ_SMP_WAIT_RESP),\
  238. C(REQ_SMP_WAIT_TC_COMP),\
  239. C(REQ_COMPLETED),\
  240. C(REQ_ABORTING),\
  241. C(REQ_FINAL),\
  242. }
  243. #undef C
  244. #define C(a) SCI_##a
  245. enum sci_base_request_states REQUEST_STATES;
  246. #undef C
  247. const char *req_state_name(enum sci_base_request_states state);
  248. enum sci_status sci_request_start(struct isci_request *ireq);
  249. enum sci_status sci_io_request_terminate(struct isci_request *ireq);
  250. enum sci_status
  251. sci_io_request_event_handler(struct isci_request *ireq,
  252. u32 event_code);
  253. enum sci_status
  254. sci_io_request_frame_handler(struct isci_request *ireq,
  255. u32 frame_index);
  256. enum sci_status
  257. sci_task_request_terminate(struct isci_request *ireq);
  258. extern enum sci_status
  259. sci_request_complete(struct isci_request *ireq);
  260. extern enum sci_status
  261. sci_io_request_tc_completion(struct isci_request *ireq, u32 code);
  262. /* XXX open code in caller */
  263. static inline dma_addr_t
  264. sci_io_request_get_dma_addr(struct isci_request *ireq, void *virt_addr)
  265. {
  266. char *requested_addr = (char *)virt_addr;
  267. char *base_addr = (char *)ireq;
  268. BUG_ON(requested_addr < base_addr);
  269. BUG_ON((requested_addr - base_addr) >= sizeof(*ireq));
  270. return ireq->request_daddr + (requested_addr - base_addr);
  271. }
  272. #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr)
  273. #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr)
  274. struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost,
  275. struct isci_tmf *isci_tmf,
  276. u16 tag);
  277. int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev,
  278. struct sas_task *task, u16 tag);
  279. enum sci_status
  280. sci_task_request_construct(struct isci_host *ihost,
  281. struct isci_remote_device *idev,
  282. u16 io_tag,
  283. struct isci_request *ireq);
  284. enum sci_status sci_task_request_construct_ssp(struct isci_request *ireq);
  285. void sci_smp_request_copy_response(struct isci_request *ireq);
  286. static inline int isci_task_is_ncq_recovery(struct sas_task *task)
  287. {
  288. return (sas_protocol_ata(task->task_proto) &&
  289. task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT &&
  290. task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ);
  291. }
  292. #endif /* !defined(_ISCI_REQUEST_H_) */