sata.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 <scsi/sas.h>
  56. #include "isci.h"
  57. #include "remote_device.h"
  58. #include "scic_io_request.h"
  59. #include "scic_task_request.h"
  60. #include "task.h"
  61. #include "request.h"
  62. #include "sata.h"
  63. /**
  64. * isci_sata_task_to_fis_copy() - This function gets the host_to_dev_fis from
  65. * the core and copies the fis from the task into it.
  66. * @task: This parameter is a pointer to the task struct from libsas.
  67. *
  68. * pointer to the host_to_dev_fis from the core request object.
  69. */
  70. struct host_to_dev_fis *isci_sata_task_to_fis_copy(struct sas_task *task)
  71. {
  72. struct isci_request *ireq = task->lldd_task;
  73. struct host_to_dev_fis *fis = &ireq->sci.stp.cmd;
  74. memcpy(fis, &task->ata_task.fis, sizeof(struct host_to_dev_fis));
  75. if (!task->ata_task.device_control_reg_update)
  76. fis->flags |= 0x80;
  77. fis->flags &= 0xF0;
  78. return fis;
  79. }
  80. /**
  81. * isci_sata_is_task_ncq() - This function determines if the given stp task is
  82. * a ncq request.
  83. * @task: This parameter is a pointer to the task struct from libsas.
  84. *
  85. * true if the task is ncq
  86. */
  87. bool isci_sata_is_task_ncq(struct sas_task *task)
  88. {
  89. struct ata_queued_cmd *qc = task->uldd_task;
  90. bool ret = (qc &&
  91. (qc->tf.command == ATA_CMD_FPDMA_WRITE ||
  92. qc->tf.command == ATA_CMD_FPDMA_READ));
  93. return ret;
  94. }
  95. /**
  96. * isci_sata_set_ncq_tag() - This function sets the ncq tag field in the
  97. * host_to_dev_fis equal to the tag in the queue command in the task.
  98. * @task: This parameter is a pointer to the task struct from libsas.
  99. * @register_fis: This parameter is a pointer to the host_to_dev_fis from the
  100. * core request object.
  101. *
  102. */
  103. void isci_sata_set_ncq_tag(
  104. struct host_to_dev_fis *register_fis,
  105. struct sas_task *task)
  106. {
  107. struct ata_queued_cmd *qc = task->uldd_task;
  108. struct isci_request *request = task->lldd_task;
  109. register_fis->sector_count = qc->tag << 3;
  110. scic_stp_io_request_set_ncq_tag(&request->sci, qc->tag);
  111. }
  112. /**
  113. * isci_request_process_stp_response() - This function sets the status and
  114. * response, in the task struct, from the request object for the upper layer
  115. * driver.
  116. * @sas_task: This parameter is the task struct from the upper layer driver.
  117. * @response_buffer: This parameter points to the response of the completed
  118. * request.
  119. *
  120. * none.
  121. */
  122. void isci_request_process_stp_response(struct sas_task *task,
  123. void *response_buffer)
  124. {
  125. struct dev_to_host_fis *d2h_reg_fis = response_buffer;
  126. struct task_status_struct *ts = &task->task_status;
  127. struct ata_task_resp *resp = (void *)&ts->buf[0];
  128. resp->frame_len = le16_to_cpu(*(__le16 *)(response_buffer + 6));
  129. memcpy(&resp->ending_fis[0], response_buffer + 16, 24);
  130. ts->buf_valid_size = sizeof(*resp);
  131. /**
  132. * If the device fault bit is set in the status register, then
  133. * set the sense data and return.
  134. */
  135. if (d2h_reg_fis->status & ATA_DF)
  136. ts->stat = SAS_PROTO_RESPONSE;
  137. else
  138. ts->stat = SAM_STAT_GOOD;
  139. ts->resp = SAS_TASK_COMPLETE;
  140. }
  141. enum sci_status isci_sata_management_task_request_build(struct isci_request *ireq)
  142. {
  143. struct scic_sds_request *sci_req = &ireq->sci;
  144. struct isci_tmf *isci_tmf;
  145. enum sci_status status;
  146. if (tmf_task != ireq->ttype)
  147. return SCI_FAILURE;
  148. isci_tmf = isci_request_access_tmf(ireq);
  149. switch (isci_tmf->tmf_code) {
  150. case isci_tmf_sata_srst_high:
  151. case isci_tmf_sata_srst_low: {
  152. struct host_to_dev_fis *fis = &sci_req->stp.cmd;
  153. memset(fis, 0, sizeof(*fis));
  154. fis->fis_type = 0x27;
  155. fis->flags &= ~0x80;
  156. fis->flags &= 0xF0;
  157. if (isci_tmf->tmf_code == isci_tmf_sata_srst_high)
  158. fis->control |= ATA_SRST;
  159. else
  160. fis->control &= ~ATA_SRST;
  161. break;
  162. }
  163. /* other management commnd go here... */
  164. default:
  165. return SCI_FAILURE;
  166. }
  167. /* core builds the protocol specific request
  168. * based on the h2d fis.
  169. */
  170. status = scic_task_request_construct_sata(&ireq->sci);
  171. return status;
  172. }
  173. /**
  174. * isci_task_send_lu_reset_sata() - This function is called by of the SAS
  175. * Domain Template functions. This is one of the Task Management functoins
  176. * called by libsas, to reset the given SAS lun. Note the assumption that
  177. * while this call is executing, no I/O will be sent by the host to the
  178. * device.
  179. * @lun: This parameter specifies the lun to be reset.
  180. *
  181. * status, zero indicates success.
  182. */
  183. int isci_task_send_lu_reset_sata(
  184. struct isci_host *isci_host,
  185. struct isci_remote_device *isci_device,
  186. u8 *lun)
  187. {
  188. struct isci_tmf tmf;
  189. int ret = TMF_RESP_FUNC_FAILED;
  190. /* Send the soft reset to the target */
  191. #define ISCI_SRST_TIMEOUT_MS 25000 /* 25 second timeout. */
  192. isci_task_build_tmf(&tmf, isci_device, isci_tmf_sata_srst_high,
  193. NULL, NULL
  194. );
  195. ret = isci_task_execute_tmf(isci_host, &tmf, ISCI_SRST_TIMEOUT_MS);
  196. if (ret != TMF_RESP_FUNC_COMPLETE) {
  197. dev_warn(&isci_host->pdev->dev,
  198. "%s: Assert SRST failed (%p) = %x",
  199. __func__,
  200. isci_device,
  201. ret);
  202. /* Return the failure so that the LUN reset is escalated
  203. * to a target reset.
  204. */
  205. }
  206. return ret;
  207. }