task.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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_TASK_H_
  56. #define _ISCI_TASK_H_
  57. #include <scsi/sas_ata.h>
  58. #include "host.h"
  59. #define ISCI_TERMINATION_TIMEOUT_MSEC 500
  60. struct isci_request;
  61. /**
  62. * enum isci_tmf_cb_state - This enum defines the possible states in which the
  63. * TMF callback function is invoked during the TMF execution process.
  64. *
  65. *
  66. */
  67. enum isci_tmf_cb_state {
  68. isci_tmf_init_state = 0,
  69. isci_tmf_started,
  70. isci_tmf_timed_out
  71. };
  72. /**
  73. * enum isci_tmf_function_codes - This enum defines the possible preparations
  74. * of task management requests.
  75. *
  76. *
  77. */
  78. enum isci_tmf_function_codes {
  79. isci_tmf_func_none = 0,
  80. isci_tmf_ssp_task_abort = TMF_ABORT_TASK,
  81. isci_tmf_ssp_lun_reset = TMF_LU_RESET,
  82. };
  83. /**
  84. * struct isci_tmf - This class represents the task management object which
  85. * acts as an interface to libsas for processing task management requests
  86. *
  87. *
  88. */
  89. struct isci_tmf {
  90. struct completion *complete;
  91. enum sas_protocol proto;
  92. union {
  93. struct ssp_response_iu resp_iu;
  94. struct dev_to_host_fis d2h_fis;
  95. u8 rsp_buf[SSP_RESP_IU_MAX_SIZE];
  96. } resp;
  97. unsigned char lun[8];
  98. u16 io_tag;
  99. enum isci_tmf_function_codes tmf_code;
  100. int status;
  101. /* The optional callback function allows the user process to
  102. * track the TMF transmit / timeout conditions.
  103. */
  104. void (*cb_state_func)(
  105. enum isci_tmf_cb_state,
  106. struct isci_tmf *, void *);
  107. void *cb_data;
  108. };
  109. static inline void isci_print_tmf(struct isci_host *ihost, struct isci_tmf *tmf)
  110. {
  111. if (SAS_PROTOCOL_SATA == tmf->proto)
  112. dev_dbg(&ihost->pdev->dev,
  113. "%s: status = %x\n"
  114. "tmf->resp.d2h_fis.status = %x\n"
  115. "tmf->resp.d2h_fis.error = %x\n",
  116. __func__,
  117. tmf->status,
  118. tmf->resp.d2h_fis.status,
  119. tmf->resp.d2h_fis.error);
  120. else
  121. dev_dbg(&ihost->pdev->dev,
  122. "%s: status = %x\n"
  123. "tmf->resp.resp_iu.data_present = %x\n"
  124. "tmf->resp.resp_iu.status = %x\n"
  125. "tmf->resp.resp_iu.data_length = %x\n"
  126. "tmf->resp.resp_iu.data[0] = %x\n"
  127. "tmf->resp.resp_iu.data[1] = %x\n"
  128. "tmf->resp.resp_iu.data[2] = %x\n"
  129. "tmf->resp.resp_iu.data[3] = %x\n",
  130. __func__,
  131. tmf->status,
  132. tmf->resp.resp_iu.datapres,
  133. tmf->resp.resp_iu.status,
  134. be32_to_cpu(tmf->resp.resp_iu.response_data_len),
  135. tmf->resp.resp_iu.resp_data[0],
  136. tmf->resp.resp_iu.resp_data[1],
  137. tmf->resp.resp_iu.resp_data[2],
  138. tmf->resp.resp_iu.resp_data[3]);
  139. }
  140. int isci_task_execute_task(
  141. struct sas_task *task,
  142. int num,
  143. gfp_t gfp_flags);
  144. int isci_task_abort_task(
  145. struct sas_task *task);
  146. int isci_task_abort_task_set(
  147. struct domain_device *d_device,
  148. u8 *lun);
  149. int isci_task_clear_aca(
  150. struct domain_device *d_device,
  151. u8 *lun);
  152. int isci_task_clear_task_set(
  153. struct domain_device *d_device,
  154. u8 *lun);
  155. int isci_task_query_task(
  156. struct sas_task *task);
  157. int isci_task_lu_reset(
  158. struct domain_device *d_device,
  159. u8 *lun);
  160. int isci_task_clear_nexus_port(
  161. struct asd_sas_port *port);
  162. int isci_task_clear_nexus_ha(
  163. struct sas_ha_struct *ha);
  164. int isci_task_I_T_nexus_reset(
  165. struct domain_device *d_device);
  166. void isci_task_request_complete(
  167. struct isci_host *isci_host,
  168. struct isci_request *request,
  169. enum sci_task_status completion_status);
  170. u16 isci_task_ssp_request_get_io_tag_to_manage(
  171. struct isci_request *request);
  172. u8 isci_task_ssp_request_get_function(
  173. struct isci_request *request);
  174. void *isci_task_ssp_request_get_response_data_address(
  175. struct isci_request *request);
  176. u32 isci_task_ssp_request_get_response_data_length(
  177. struct isci_request *request);
  178. int isci_queuecommand(
  179. struct scsi_cmnd *scsi_cmd,
  180. void (*donefunc)(struct scsi_cmnd *));
  181. /**
  182. * enum isci_completion_selection - This enum defines the possible actions to
  183. * take with respect to a given request's notification back to libsas.
  184. *
  185. *
  186. */
  187. enum isci_completion_selection {
  188. isci_perform_normal_io_completion, /* Normal notify (task_done) */
  189. isci_perform_aborted_io_completion, /* No notification. */
  190. isci_perform_error_io_completion /* Use sas_task_abort */
  191. };
  192. /**
  193. * isci_task_set_completion_status() - This function sets the completion status
  194. * for the request.
  195. * @task: This parameter is the completed request.
  196. * @response: This parameter is the response code for the completed task.
  197. * @status: This parameter is the status code for the completed task.
  198. *
  199. * @return The new notification mode for the request.
  200. */
  201. static inline enum isci_completion_selection
  202. isci_task_set_completion_status(
  203. struct sas_task *task,
  204. enum service_response response,
  205. enum exec_status status,
  206. enum isci_completion_selection task_notification_selection)
  207. {
  208. unsigned long flags;
  209. spin_lock_irqsave(&task->task_state_lock, flags);
  210. /* If a device reset is being indicated, make sure the I/O
  211. * is in the error path.
  212. */
  213. if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET) {
  214. /* Fail the I/O to make sure it goes into the error path. */
  215. response = SAS_TASK_UNDELIVERED;
  216. status = SAM_STAT_TASK_ABORTED;
  217. task_notification_selection = isci_perform_error_io_completion;
  218. }
  219. task->task_status.resp = response;
  220. task->task_status.stat = status;
  221. switch (task->task_proto) {
  222. case SAS_PROTOCOL_SATA:
  223. case SAS_PROTOCOL_STP:
  224. case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
  225. if (task_notification_selection
  226. == isci_perform_error_io_completion) {
  227. /* SATA/STP I/O has it's own means of scheduling device
  228. * error handling on the normal path.
  229. */
  230. task_notification_selection
  231. = isci_perform_normal_io_completion;
  232. }
  233. break;
  234. default:
  235. break;
  236. }
  237. switch (task_notification_selection) {
  238. case isci_perform_error_io_completion:
  239. if (task->task_proto == SAS_PROTOCOL_SMP) {
  240. /* There is no error escalation in the SMP case.
  241. * Convert to a normal completion to avoid the
  242. * timeout in the discovery path and to let the
  243. * next action take place quickly.
  244. */
  245. task_notification_selection
  246. = isci_perform_normal_io_completion;
  247. /* Fall through to the normal case... */
  248. } else {
  249. /* Use sas_task_abort */
  250. /* Leave SAS_TASK_STATE_DONE clear
  251. * Leave SAS_TASK_AT_INITIATOR set.
  252. */
  253. break;
  254. }
  255. case isci_perform_aborted_io_completion:
  256. /* This path can occur with task-managed requests as well as
  257. * requests terminated because of LUN or device resets.
  258. */
  259. /* Fall through to the normal case... */
  260. case isci_perform_normal_io_completion:
  261. /* Normal notification (task_done) */
  262. task->task_state_flags |= SAS_TASK_STATE_DONE;
  263. task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR |
  264. SAS_TASK_STATE_PENDING);
  265. break;
  266. default:
  267. WARN_ONCE(1, "unknown task_notification_selection: %d\n",
  268. task_notification_selection);
  269. break;
  270. }
  271. spin_unlock_irqrestore(&task->task_state_lock, flags);
  272. return task_notification_selection;
  273. }
  274. #endif /* !defined(_SCI_TASK_H_) */