task.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. #if !defined(_ISCI_TASK_H_)
  56. #define _ISCI_TASK_H_
  57. struct isci_request;
  58. struct isci_host;
  59. /**
  60. * enum isci_tmf_cb_state - This enum defines the possible states in which the
  61. * TMF callback function is invoked during the TMF execution process.
  62. *
  63. *
  64. */
  65. enum isci_tmf_cb_state {
  66. isci_tmf_init_state = 0,
  67. isci_tmf_started,
  68. isci_tmf_timed_out
  69. };
  70. /**
  71. * enum isci_tmf_function_codes - This enum defines the possible preparations
  72. * of task management requests.
  73. *
  74. *
  75. */
  76. enum isci_tmf_function_codes {
  77. isci_tmf_func_none = 0,
  78. isci_tmf_ssp_task_abort = TMF_ABORT_TASK,
  79. isci_tmf_ssp_lun_reset = TMF_LU_RESET,
  80. isci_tmf_sata_srst_high = TMF_LU_RESET + 0x100, /* Non SCSI */
  81. isci_tmf_sata_srst_low = TMF_LU_RESET + 0x101 /* Non SCSI */
  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 sci_ssp_response_iu resp_iu;
  94. struct dev_to_host_fis d2h_fis;
  95. } resp;
  96. unsigned char lun[8];
  97. u16 io_tag;
  98. struct isci_remote_device *device;
  99. enum isci_tmf_function_codes tmf_code;
  100. int status;
  101. struct isci_timer *timeout_timer;
  102. /* The optional callback function allows the user process to
  103. * track the TMF transmit / timeout conditions.
  104. */
  105. void (*cb_state_func)(
  106. enum isci_tmf_cb_state,
  107. struct isci_tmf *, void *);
  108. void *cb_data;
  109. };
  110. static inline void isci_print_tmf(
  111. struct isci_tmf *tmf)
  112. {
  113. if (SAS_PROTOCOL_SATA == tmf->proto)
  114. dev_dbg(&tmf->device->isci_port->isci_host->pdev->dev,
  115. "%s: status = %x\n"
  116. "tmf->resp.d2h_fis.status = %x\n"
  117. "tmf->resp.d2h_fis.error = %x\n",
  118. __func__,
  119. tmf->status,
  120. tmf->resp.d2h_fis.status,
  121. tmf->resp.d2h_fis.error);
  122. else
  123. dev_dbg(&tmf->device->isci_port->isci_host->pdev->dev,
  124. "%s: status = %x\n"
  125. "tmf->resp.resp_iu.data_present = %x\n"
  126. "tmf->resp.resp_iu.status = %x\n"
  127. "tmf->resp.resp_iu.data_length = %x\n"
  128. "tmf->resp.resp_iu.data[0] = %x\n"
  129. "tmf->resp.resp_iu.data[1] = %x\n"
  130. "tmf->resp.resp_iu.data[2] = %x\n"
  131. "tmf->resp.resp_iu.data[3] = %x\n",
  132. __func__,
  133. tmf->status,
  134. tmf->resp.resp_iu.data_present,
  135. tmf->resp.resp_iu.status,
  136. (tmf->resp.resp_iu.response_data_length[0] << 24) +
  137. (tmf->resp.resp_iu.response_data_length[1] << 16) +
  138. (tmf->resp.resp_iu.response_data_length[2] << 8) +
  139. tmf->resp.resp_iu.response_data_length[3],
  140. tmf->resp.resp_iu.data[0],
  141. tmf->resp.resp_iu.data[1],
  142. tmf->resp.resp_iu.data[2],
  143. tmf->resp.resp_iu.data[3]);
  144. }
  145. int isci_task_execute_task(
  146. struct sas_task *task,
  147. int num,
  148. gfp_t gfp_flags);
  149. int isci_task_abort_task(
  150. struct sas_task *task);
  151. int isci_task_abort_task_set(
  152. struct domain_device *d_device,
  153. u8 *lun);
  154. int isci_task_clear_aca(
  155. struct domain_device *d_device,
  156. u8 *lun);
  157. int isci_task_clear_task_set(
  158. struct domain_device *d_device,
  159. u8 *lun);
  160. int isci_task_query_task(
  161. struct sas_task *task);
  162. int isci_task_lu_reset(
  163. struct domain_device *d_device,
  164. u8 *lun);
  165. int isci_task_clear_nexus_port(
  166. struct asd_sas_port *port);
  167. int isci_task_clear_nexus_ha(
  168. struct sas_ha_struct *ha);
  169. int isci_task_I_T_nexus_reset(
  170. struct domain_device *d_device);
  171. void isci_task_request_complete(
  172. struct isci_host *isci_host,
  173. struct isci_request *request,
  174. enum sci_task_status completion_status);
  175. u16 isci_task_ssp_request_get_io_tag_to_manage(
  176. struct isci_request *request);
  177. u8 isci_task_ssp_request_get_function(
  178. struct isci_request *request);
  179. u32 isci_task_ssp_request_get_lun(
  180. struct isci_request *request);
  181. void *isci_task_ssp_request_get_response_data_address(
  182. struct isci_request *request);
  183. u32 isci_task_ssp_request_get_response_data_length(
  184. struct isci_request *request);
  185. int isci_queuecommand(
  186. struct scsi_cmnd *scsi_cmd,
  187. void (*donefunc)(struct scsi_cmnd *));
  188. int isci_bus_reset_handler(struct scsi_cmnd *cmd);
  189. void isci_task_build_tmf(
  190. struct isci_tmf *tmf,
  191. struct isci_remote_device *isci_device,
  192. enum isci_tmf_function_codes code,
  193. void (*tmf_sent_cb)(
  194. enum isci_tmf_cb_state,
  195. struct isci_tmf *, void *),
  196. struct isci_request *old_request);
  197. int isci_task_execute_tmf(
  198. struct isci_host *isci_host,
  199. struct isci_tmf *tmf,
  200. unsigned long timeout_ms);
  201. /**
  202. * enum isci_completion_selection - This enum defines the possible actions to
  203. * take with respect to a given request's notification back to libsas.
  204. *
  205. *
  206. */
  207. enum isci_completion_selection {
  208. isci_perform_normal_io_completion, /* Normal notify (task_done) */
  209. isci_perform_aborted_io_completion, /* No notification. */
  210. isci_perform_error_io_completion /* Use sas_task_abort */
  211. };
  212. static inline void isci_set_task_doneflags(
  213. struct sas_task *task)
  214. {
  215. /* Since no futher action will be taken on this task,
  216. * make sure to mark it complete from the lldd perspective.
  217. */
  218. task->task_state_flags |= SAS_TASK_STATE_DONE;
  219. task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
  220. task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
  221. }
  222. /**
  223. * isci_task_all_done() - This function clears the task bits to indicate the
  224. * LLDD is done with the task.
  225. *
  226. *
  227. */
  228. static inline void isci_task_all_done(
  229. struct sas_task *task)
  230. {
  231. unsigned long flags;
  232. /* Since no futher action will be taken on this task,
  233. * make sure to mark it complete from the lldd perspective.
  234. */
  235. spin_lock_irqsave(&task->task_state_lock, flags);
  236. isci_set_task_doneflags(task);
  237. spin_unlock_irqrestore(&task->task_state_lock, flags);
  238. }
  239. /**
  240. * isci_task_set_completion_status() - This function sets the completion status
  241. * for the request.
  242. * @task: This parameter is the completed request.
  243. * @response: This parameter is the response code for the completed task.
  244. * @status: This parameter is the status code for the completed task.
  245. *
  246. * @return The new notification mode for the request.
  247. */
  248. static inline enum isci_completion_selection
  249. isci_task_set_completion_status(
  250. struct sas_task *task,
  251. enum service_response response,
  252. enum exec_status status,
  253. enum isci_completion_selection task_notification_selection)
  254. {
  255. unsigned long flags;
  256. spin_lock_irqsave(&task->task_state_lock, flags);
  257. task->task_status.resp = response;
  258. task->task_status.stat = status;
  259. /* If a device reset is being indicated, make sure the I/O
  260. * is in the error path.
  261. */
  262. if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
  263. task_notification_selection = isci_perform_error_io_completion;
  264. switch (task_notification_selection) {
  265. case isci_perform_aborted_io_completion:
  266. /* This path can occur with task-managed requests as well as
  267. * requests terminated because of LUN or device resets.
  268. */
  269. /* Fall through to the normal case... */
  270. case isci_perform_normal_io_completion:
  271. /* Normal notification (task_done) */
  272. isci_set_task_doneflags(task);
  273. break;
  274. default:
  275. WARN_ON(FALSE);
  276. /* Fall through to the error case... */
  277. case isci_perform_error_io_completion:
  278. /* Use sas_task_abort */
  279. /* Leave SAS_TASK_STATE_DONE clear
  280. * Leave SAS_TASK_AT_INITIATOR set.
  281. */
  282. break;
  283. }
  284. spin_unlock_irqrestore(&task->task_state_lock, flags);
  285. return task_notification_selection;
  286. }
  287. /**
  288. * isci_task_complete_for_upper_layer() - This function completes the request
  289. * to the upper layer driver.
  290. * @host: This parameter is a pointer to the host on which the the request
  291. * should be queued (either as an error or success).
  292. * @request: This parameter is the completed request.
  293. * @response: This parameter is the response code for the completed task.
  294. * @status: This parameter is the status code for the completed task.
  295. *
  296. * none.
  297. */
  298. static inline void isci_task_complete_for_upper_layer(
  299. struct sas_task *task,
  300. enum service_response response,
  301. enum exec_status status,
  302. enum isci_completion_selection task_notification_selection)
  303. {
  304. task_notification_selection
  305. = isci_task_set_completion_status(task, response, status,
  306. task_notification_selection);
  307. /* Tasks aborted specifically by a call to the lldd_abort_task
  308. * function should not be completed to the host in the regular path.
  309. */
  310. switch (task_notification_selection) {
  311. case isci_perform_normal_io_completion:
  312. /* Normal notification (task_done) */
  313. dev_dbg(task->dev->port->ha->dev,
  314. "%s: Normal - task = %p, response=%d, status=%d\n",
  315. __func__, task, response, status);
  316. task->task_done(task);
  317. task->lldd_task = NULL;
  318. break;
  319. case isci_perform_aborted_io_completion:
  320. /* No notification because this request is already in the
  321. * abort path.
  322. */
  323. dev_warn(task->dev->port->ha->dev,
  324. "%s: Aborted - task = %p, response=%d, status=%d\n",
  325. __func__, task, response, status);
  326. break;
  327. case isci_perform_error_io_completion:
  328. /* Use sas_task_abort */
  329. dev_warn(task->dev->port->ha->dev,
  330. "%s: Error - task = %p, response=%d, status=%d\n",
  331. __func__, task, response, status);
  332. sas_task_abort(task);
  333. break;
  334. default:
  335. dev_warn(task->dev->port->ha->dev,
  336. "%s: isci task notification default case!",
  337. __func__);
  338. sas_task_abort(task);
  339. break;
  340. }
  341. }
  342. #endif /* !defined(_SCI_TASK_H_) */