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 | |
Dan Williams | 0d84366 | 2011-05-08 01:56:57 -0700 | [diff] [blame] | 56 | #ifndef _ISCI_REQUEST_H_ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 57 | #define _ISCI_REQUEST_H_ |
| 58 | |
| 59 | #include "isci.h" |
Dan Williams | ce2b326 | 2011-05-08 15:49:15 -0700 | [diff] [blame] | 60 | #include "host.h" |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 61 | #include "scu_task_context.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * struct isci_request_status - This enum defines the possible states of an I/O |
| 65 | * request. |
| 66 | * |
| 67 | * |
| 68 | */ |
| 69 | enum isci_request_status { |
| 70 | unallocated = 0x00, |
| 71 | allocated = 0x01, |
| 72 | started = 0x02, |
| 73 | completed = 0x03, |
| 74 | aborting = 0x04, |
| 75 | aborted = 0x05, |
Jeff Skirvin | 4dc043c | 2011-03-04 14:06:52 -0800 | [diff] [blame] | 76 | terminating = 0x06, |
| 77 | dead = 0x07 |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 80 | enum sci_request_protocol { |
| 81 | SCIC_NO_PROTOCOL, |
| 82 | SCIC_SMP_PROTOCOL, |
| 83 | SCIC_SSP_PROTOCOL, |
| 84 | SCIC_STP_PROTOCOL |
Dan Williams | c72086e | 2011-05-10 02:28:48 -0700 | [diff] [blame] | 85 | }; /* XXX remove me, use sas_task.{dev|task_proto} instead */; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 86 | |
Dan Williams | ba7cb22 | 2011-06-27 11:56:41 -0700 | [diff] [blame] | 87 | /** |
| 88 | * isci_stp_request - extra request infrastructure to handle pio/atapi protocol |
| 89 | * @pio_len - number of bytes requested at PIO setup |
| 90 | * @status - pio setup ending status value to tell us if we need |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 91 | * to wait for another fis or if the transfer is complete. Upon |
Dan Williams | ba7cb22 | 2011-06-27 11:56:41 -0700 | [diff] [blame] | 92 | * receipt of a d2h fis this will be the status field of that fis. |
| 93 | * @sgl - track pio transfer progress as we iterate through the sgl |
Dan Williams | ba7cb22 | 2011-06-27 11:56:41 -0700 | [diff] [blame] | 94 | */ |
| 95 | struct isci_stp_request { |
| 96 | u32 pio_len; |
| 97 | u8 status; |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 98 | |
Dan Williams | ba7cb22 | 2011-06-27 11:56:41 -0700 | [diff] [blame] | 99 | struct isci_stp_pio_sgl { |
| 100 | int index; |
| 101 | u8 set; |
| 102 | u32 offset; |
| 103 | } sgl; |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 106 | struct isci_request { |
| 107 | enum isci_request_status status; |
| 108 | #define IREQ_COMPLETE_IN_TARGET 0 |
| 109 | #define IREQ_TERMINATED 1 |
| 110 | #define IREQ_TMF 2 |
| 111 | #define IREQ_ACTIVE 3 |
| 112 | unsigned long flags; |
| 113 | /* XXX kill ttype and ttype_ptr, allocate full sas_task */ |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 114 | union ttype_ptr_union { |
| 115 | struct sas_task *io_task_ptr; /* When ttype==io_task */ |
| 116 | struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */ |
| 117 | } ttype_ptr; |
| 118 | struct isci_host *isci_host; |
| 119 | /* For use in the requests_to_{complete|abort} lists: */ |
| 120 | struct list_head completed_node; |
| 121 | /* For use in the reqs_in_process list: */ |
| 122 | struct list_head dev_node; |
| 123 | spinlock_t state_lock; |
| 124 | dma_addr_t request_daddr; |
| 125 | dma_addr_t zero_scatter_daddr; |
| 126 | unsigned int num_sg_entries; |
| 127 | /* Note: "io_request_completion" is completed in two different ways |
| 128 | * depending on whether this is a TMF or regular request. |
| 129 | * - TMF requests are completed in the thread that started them; |
| 130 | * - regular requests are completed in the request completion callback |
| 131 | * function. |
| 132 | * This difference in operation allows the aborter of a TMF request |
| 133 | * to be sure that once the TMF request completes, the I/O that the |
| 134 | * TMF was aborting is guaranteed to have completed. |
| 135 | * |
| 136 | * XXX kill io_request_completion |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 137 | */ |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 138 | struct completion *io_request_completion; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 139 | struct sci_base_state_machine sm; |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 140 | struct isci_host *owning_controller; |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 141 | struct isci_remote_device *target_device; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 142 | u16 io_tag; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 143 | enum sci_request_protocol protocol; |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 144 | u32 scu_status; /* hardware result */ |
| 145 | u32 sci_status; /* upper layer disposition */ |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 146 | u32 post_context; |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 147 | struct scu_task_context *tc; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 148 | /* could be larger with sg chaining */ |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 149 | #define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2) |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 150 | struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32))); |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 151 | /* This field is a pointer to the stored rx frame data. It is used in |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 152 | * STP internal requests and SMP response frames. If this field is |
| 153 | * non-NULL the saved frame must be released on IO request completion. |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 154 | */ |
| 155 | u32 saved_rx_frame_index; |
| 156 | |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 157 | union { |
| 158 | struct { |
| 159 | union { |
| 160 | struct ssp_cmd_iu cmd; |
| 161 | struct ssp_task_iu tmf; |
| 162 | }; |
| 163 | union { |
| 164 | struct ssp_response_iu rsp; |
| 165 | u8 rsp_buf[SSP_RESP_IU_MAX_SIZE]; |
| 166 | }; |
| 167 | } ssp; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 168 | struct { |
Dan Williams | ba7cb22 | 2011-06-27 11:56:41 -0700 | [diff] [blame] | 169 | struct isci_stp_request req; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 170 | struct host_to_dev_fis cmd; |
| 171 | struct dev_to_host_fis rsp; |
| 172 | } stp; |
| 173 | }; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 176 | static inline struct isci_request *to_ireq(struct isci_stp_request *stp_req) |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 177 | { |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 178 | struct isci_request *ireq; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 179 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 180 | ireq = container_of(stp_req, typeof(*ireq), stp.req); |
Dan Williams | 67ea838 | 2011-05-08 11:47:15 -0700 | [diff] [blame] | 181 | return ireq; |
| 182 | } |
| 183 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 184 | /** |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 185 | * enum sci_base_request_states - This enumeration depicts all the states for |
| 186 | * the common request state machine. |
| 187 | * |
| 188 | * |
| 189 | */ |
| 190 | enum sci_base_request_states { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 191 | /* |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 192 | * Simply the initial state for the base request state machine. |
| 193 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 194 | SCI_REQ_INIT, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 195 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 196 | /* |
| 197 | * This state indicates that the request has been constructed. |
| 198 | * This state is entered from the INITIAL state. |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 199 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 200 | SCI_REQ_CONSTRUCTED, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 201 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 202 | /* |
| 203 | * This state indicates that the request has been started. This state |
| 204 | * is entered from the CONSTRUCTED state. |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 205 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 206 | SCI_REQ_STARTED, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 207 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 208 | SCI_REQ_STP_UDMA_WAIT_TC_COMP, |
| 209 | SCI_REQ_STP_UDMA_WAIT_D2H, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 210 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 211 | SCI_REQ_STP_NON_DATA_WAIT_H2D, |
| 212 | SCI_REQ_STP_NON_DATA_WAIT_D2H, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 213 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 214 | SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED, |
| 215 | SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG, |
| 216 | SCI_REQ_STP_SOFT_RESET_WAIT_D2H, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 217 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 218 | /* |
| 219 | * While in this state the IO request object is waiting for the TC |
| 220 | * completion notification for the H2D Register FIS |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 221 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 222 | SCI_REQ_STP_PIO_WAIT_H2D, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 223 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 224 | /* |
| 225 | * While in this state the IO request object is waiting for either a |
| 226 | * PIO Setup FIS or a D2H register FIS. The type of frame received is |
| 227 | * based on the result of the prior frame and line conditions. |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 228 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 229 | SCI_REQ_STP_PIO_WAIT_FRAME, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 230 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 231 | /* |
| 232 | * While in this state the IO request object is waiting for a DATA |
| 233 | * frame from the device. |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 234 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 235 | SCI_REQ_STP_PIO_DATA_IN, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 236 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 237 | /* |
| 238 | * While in this state the IO request object is waiting to transmit |
| 239 | * the next data frame to the device. |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 240 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 241 | SCI_REQ_STP_PIO_DATA_OUT, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 242 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 243 | /* |
Dan Williams | b50102d | 2011-09-30 18:52:19 -0700 | [diff] [blame] | 244 | * While in this state the IO request object is waiting for the TC |
| 245 | * completion notification for the H2D Register FIS |
| 246 | */ |
| 247 | SCI_REQ_ATAPI_WAIT_H2D, |
| 248 | |
| 249 | /* |
| 250 | * While in this state the IO request object is waiting for either a |
| 251 | * PIO Setup. |
| 252 | */ |
| 253 | SCI_REQ_ATAPI_WAIT_PIO_SETUP, |
| 254 | |
| 255 | /* |
| 256 | * The non-data IO transit to this state in this state after receiving |
| 257 | * TC completion. While in this state IO request object is waiting for |
| 258 | * D2H status frame as UF. |
| 259 | */ |
| 260 | SCI_REQ_ATAPI_WAIT_D2H, |
| 261 | |
| 262 | /* |
| 263 | * When transmitting raw frames hardware reports task context completion |
| 264 | * after every frame submission, so in the non-accelerated case we need |
| 265 | * to expect the completion for the "cdb" frame. |
| 266 | */ |
| 267 | SCI_REQ_ATAPI_WAIT_TC_COMP, |
| 268 | |
| 269 | /* |
Dan Williams | f139303 | 2011-05-10 02:28:47 -0700 | [diff] [blame] | 270 | * The AWAIT_TC_COMPLETION sub-state indicates that the started raw |
| 271 | * task management request is waiting for the transmission of the |
| 272 | * initial frame (i.e. command, task, etc.). |
| 273 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 274 | SCI_REQ_TASK_WAIT_TC_COMP, |
Dan Williams | f139303 | 2011-05-10 02:28:47 -0700 | [diff] [blame] | 275 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 276 | /* |
Dan Williams | f139303 | 2011-05-10 02:28:47 -0700 | [diff] [blame] | 277 | * This sub-state indicates that the started task management request |
| 278 | * is waiting for the reception of an unsolicited frame |
| 279 | * (i.e. response IU). |
| 280 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 281 | SCI_REQ_TASK_WAIT_TC_RESP, |
Dan Williams | f139303 | 2011-05-10 02:28:47 -0700 | [diff] [blame] | 282 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 283 | /* |
Dan Williams | c72086e | 2011-05-10 02:28:48 -0700 | [diff] [blame] | 284 | * This sub-state indicates that the started task management request |
| 285 | * is waiting for the reception of an unsolicited frame |
| 286 | * (i.e. response IU). |
| 287 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 288 | SCI_REQ_SMP_WAIT_RESP, |
Dan Williams | c72086e | 2011-05-10 02:28:48 -0700 | [diff] [blame] | 289 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 290 | /* |
| 291 | * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP |
| 292 | * request is waiting for the transmission of the initial frame |
| 293 | * (i.e. command, task, etc.). |
Dan Williams | c72086e | 2011-05-10 02:28:48 -0700 | [diff] [blame] | 294 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 295 | SCI_REQ_SMP_WAIT_TC_COMP, |
Dan Williams | c72086e | 2011-05-10 02:28:48 -0700 | [diff] [blame] | 296 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 297 | /* |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 298 | * This state indicates that the request has completed. |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 299 | * This state is entered from the STARTED state. This state is entered |
| 300 | * from the ABORTING state. |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 301 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 302 | SCI_REQ_COMPLETED, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 303 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 304 | /* |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 305 | * This state indicates that the request is in the process of being |
| 306 | * terminated/aborted. |
| 307 | * This state is entered from the CONSTRUCTED state. |
| 308 | * This state is entered from the STARTED state. |
| 309 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 310 | SCI_REQ_ABORTING, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 311 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 312 | /* |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 313 | * Simply the final state for the base request state machine. |
| 314 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 315 | SCI_REQ_FINAL, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 316 | }; |
| 317 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 318 | enum sci_status sci_request_start(struct isci_request *ireq); |
| 319 | enum sci_status sci_io_request_terminate(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 320 | enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 321 | sci_io_request_event_handler(struct isci_request *ireq, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 322 | u32 event_code); |
| 323 | enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 324 | sci_io_request_frame_handler(struct isci_request *ireq, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 325 | u32 frame_index); |
| 326 | enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 327 | sci_task_request_terminate(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 328 | extern enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 329 | sci_request_complete(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 330 | extern enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 331 | sci_io_request_tc_completion(struct isci_request *ireq, u32 code); |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 332 | |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 333 | /* XXX open code in caller */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 334 | static inline dma_addr_t |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 335 | sci_io_request_get_dma_addr(struct isci_request *ireq, void *virt_addr) |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 336 | { |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 337 | |
| 338 | char *requested_addr = (char *)virt_addr; |
| 339 | char *base_addr = (char *)ireq; |
| 340 | |
| 341 | BUG_ON(requested_addr < base_addr); |
| 342 | BUG_ON((requested_addr - base_addr) >= sizeof(*ireq)); |
| 343 | |
| 344 | return ireq->request_daddr + (requested_addr - base_addr); |
| 345 | } |
| 346 | |
| 347 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 348 | * isci_request_change_state() - This function sets the status of the request |
| 349 | * object. |
| 350 | * @request: This parameter points to the isci_request object |
| 351 | * @status: This Parameter is the new status of the object |
| 352 | * |
| 353 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 354 | static inline enum isci_request_status |
| 355 | isci_request_change_state(struct isci_request *isci_request, |
| 356 | enum isci_request_status status) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 357 | { |
| 358 | enum isci_request_status old_state; |
| 359 | unsigned long flags; |
| 360 | |
| 361 | dev_dbg(&isci_request->isci_host->pdev->dev, |
| 362 | "%s: isci_request = %p, state = 0x%x\n", |
| 363 | __func__, |
| 364 | isci_request, |
| 365 | status); |
| 366 | |
| 367 | BUG_ON(isci_request == NULL); |
| 368 | |
| 369 | spin_lock_irqsave(&isci_request->state_lock, flags); |
| 370 | old_state = isci_request->status; |
| 371 | isci_request->status = status; |
| 372 | spin_unlock_irqrestore(&isci_request->state_lock, flags); |
| 373 | |
| 374 | return old_state; |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * isci_request_change_started_to_newstate() - This function sets the status of |
| 379 | * the request object. |
| 380 | * @request: This parameter points to the isci_request object |
| 381 | * @status: This Parameter is the new status of the object |
| 382 | * |
| 383 | * state previous to any change. |
| 384 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 385 | static inline enum isci_request_status |
| 386 | isci_request_change_started_to_newstate(struct isci_request *isci_request, |
| 387 | struct completion *completion_ptr, |
| 388 | enum isci_request_status newstate) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 389 | { |
| 390 | enum isci_request_status old_state; |
| 391 | unsigned long flags; |
| 392 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 393 | spin_lock_irqsave(&isci_request->state_lock, flags); |
| 394 | |
| 395 | old_state = isci_request->status; |
| 396 | |
Jeff Skirvin | f219f01 | 2011-03-31 13:10:34 -0700 | [diff] [blame] | 397 | if (old_state == started || old_state == aborting) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 398 | BUG_ON(isci_request->io_request_completion != NULL); |
| 399 | |
| 400 | isci_request->io_request_completion = completion_ptr; |
| 401 | isci_request->status = newstate; |
| 402 | } |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 403 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 404 | spin_unlock_irqrestore(&isci_request->state_lock, flags); |
| 405 | |
| 406 | dev_dbg(&isci_request->isci_host->pdev->dev, |
| 407 | "%s: isci_request = %p, old_state = 0x%x\n", |
| 408 | __func__, |
| 409 | isci_request, |
| 410 | old_state); |
| 411 | |
| 412 | return old_state; |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * isci_request_change_started_to_aborted() - This function sets the status of |
| 417 | * the request object. |
| 418 | * @request: This parameter points to the isci_request object |
| 419 | * @completion_ptr: This parameter is saved as the kernel completion structure |
| 420 | * signalled when the old request completes. |
| 421 | * |
| 422 | * state previous to any change. |
| 423 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 424 | static inline enum isci_request_status |
| 425 | isci_request_change_started_to_aborted(struct isci_request *isci_request, |
| 426 | struct completion *completion_ptr) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 427 | { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 428 | return isci_request_change_started_to_newstate(isci_request, |
| 429 | completion_ptr, |
| 430 | aborted); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 431 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 432 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 433 | #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 434 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 435 | #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 436 | |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 437 | struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost, |
| 438 | struct isci_tmf *isci_tmf, |
| 439 | u16 tag); |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 440 | int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev, |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 441 | struct sas_task *task, u16 tag); |
Dan Williams | ddcc7e3 | 2011-06-17 10:40:43 -0700 | [diff] [blame] | 442 | void isci_terminate_pending_requests(struct isci_host *ihost, |
| 443 | struct isci_remote_device *idev); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 444 | enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 445 | sci_task_request_construct(struct isci_host *ihost, |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 446 | struct isci_remote_device *idev, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 447 | u16 io_tag, |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 448 | struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 449 | enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 450 | sci_task_request_construct_ssp(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 451 | enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 452 | sci_task_request_construct_sata(struct isci_request *ireq); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 453 | void sci_smp_request_copy_response(struct isci_request *ireq); |
Jeff Skirvin | 9274f45 | 2011-06-23 17:09:02 -0700 | [diff] [blame] | 454 | |
| 455 | static inline int isci_task_is_ncq_recovery(struct sas_task *task) |
| 456 | { |
| 457 | return (sas_protocol_ata(task->task_proto) && |
James Bottomley | a5ec7f86 | 2011-07-03 14:14:45 -0500 | [diff] [blame] | 458 | task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT && |
| 459 | task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ); |
Jeff Skirvin | 9274f45 | 2011-06-23 17:09:02 -0700 | [diff] [blame] | 460 | |
| 461 | } |
| 462 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 463 | #endif /* !defined(_ISCI_REQUEST_H_) */ |