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