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 | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 185 | * enum sci_base_request_states - request state machine states |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 186 | * |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 187 | * @SCI_REQ_INIT: Simply the initial state for the base request state machine. |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 188 | * |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 189 | * @SCI_REQ_CONSTRUCTED: This state indicates that the request has been |
| 190 | * constructed. This state is entered from the INITIAL state. |
| 191 | * |
| 192 | * @SCI_REQ_STARTED: This state indicates that the request has been started. |
| 193 | * This state is entered from the CONSTRUCTED state. |
| 194 | * |
| 195 | * @SCI_REQ_STP_UDMA_WAIT_TC_COMP: |
| 196 | * @SCI_REQ_STP_UDMA_WAIT_D2H: |
| 197 | * @SCI_REQ_STP_NON_DATA_WAIT_H2D: |
| 198 | * @SCI_REQ_STP_NON_DATA_WAIT_D2H: |
| 199 | * |
| 200 | * @SCI_REQ_STP_PIO_WAIT_H2D: While in this state the IO request object is |
| 201 | * waiting for the TC completion notification for the H2D Register FIS |
| 202 | * |
| 203 | * @SCI_REQ_STP_PIO_WAIT_FRAME: While in this state the IO request object is |
| 204 | * waiting for either a PIO Setup FIS or a D2H register FIS. The type of frame |
| 205 | * received is based on the result of the prior frame and line conditions. |
| 206 | * |
| 207 | * @SCI_REQ_STP_PIO_DATA_IN: While in this state the IO request object is |
| 208 | * waiting for a DATA frame from the device. |
| 209 | * |
| 210 | * @SCI_REQ_STP_PIO_DATA_OUT: While in this state the IO request object is |
| 211 | * waiting to transmit the next data frame to the device. |
| 212 | * |
| 213 | * @SCI_REQ_ATAPI_WAIT_H2D: While in this state the IO request object is |
| 214 | * waiting for the TC completion notification for the H2D Register FIS |
| 215 | * |
| 216 | * @SCI_REQ_ATAPI_WAIT_PIO_SETUP: While in this state the IO request object is |
| 217 | * waiting for either a PIO Setup. |
| 218 | * |
| 219 | * @SCI_REQ_ATAPI_WAIT_D2H: The non-data IO transit to this state in this state |
| 220 | * after receiving TC completion. While in this state IO request object is |
| 221 | * waiting for D2H status frame as UF. |
| 222 | * |
| 223 | * @SCI_REQ_ATAPI_WAIT_TC_COMP: When transmitting raw frames hardware reports |
| 224 | * task context completion after every frame submission, so in the |
| 225 | * non-accelerated case we need to expect the completion for the "cdb" frame. |
| 226 | * |
| 227 | * @SCI_REQ_TASK_WAIT_TC_COMP: The AWAIT_TC_COMPLETION sub-state indicates that |
| 228 | * the started raw task management request is waiting for the transmission of |
| 229 | * the initial frame (i.e. command, task, etc.). |
| 230 | * |
| 231 | * @SCI_REQ_TASK_WAIT_TC_RESP: This sub-state indicates that the started task |
| 232 | * management request is waiting for the reception of an unsolicited frame |
| 233 | * (i.e. response IU). |
| 234 | * |
| 235 | * @SCI_REQ_SMP_WAIT_RESP: This sub-state indicates that the started task |
| 236 | * management request is waiting for the reception of an unsolicited frame |
| 237 | * (i.e. response IU). |
| 238 | * |
| 239 | * @SCI_REQ_SMP_WAIT_TC_COMP: The AWAIT_TC_COMPLETION sub-state indicates that |
| 240 | * the started SMP request is waiting for the transmission of the initial frame |
| 241 | * (i.e. command, task, etc.). |
| 242 | * |
| 243 | * @SCI_REQ_COMPLETED: This state indicates that the request has completed. |
| 244 | * This state is entered from the STARTED state. This state is entered from the |
| 245 | * ABORTING state. |
| 246 | * |
| 247 | * @SCI_REQ_ABORTING: This state indicates that the request is in the process |
| 248 | * of being terminated/aborted. This state is entered from the CONSTRUCTED |
| 249 | * state. This state is entered from the STARTED state. |
| 250 | * |
| 251 | * @SCI_REQ_FINAL: Simply the final state for the base request state machine. |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 252 | */ |
Dan Williams | d7a0ccd | 2012-02-10 01:18:44 -0800 | [diff] [blame] | 253 | #define REQUEST_STATES {\ |
| 254 | C(REQ_INIT),\ |
| 255 | C(REQ_CONSTRUCTED),\ |
| 256 | C(REQ_STARTED),\ |
| 257 | C(REQ_STP_UDMA_WAIT_TC_COMP),\ |
| 258 | C(REQ_STP_UDMA_WAIT_D2H),\ |
| 259 | C(REQ_STP_NON_DATA_WAIT_H2D),\ |
| 260 | C(REQ_STP_NON_DATA_WAIT_D2H),\ |
| 261 | C(REQ_STP_PIO_WAIT_H2D),\ |
| 262 | C(REQ_STP_PIO_WAIT_FRAME),\ |
| 263 | C(REQ_STP_PIO_DATA_IN),\ |
| 264 | C(REQ_STP_PIO_DATA_OUT),\ |
| 265 | C(REQ_ATAPI_WAIT_H2D),\ |
| 266 | C(REQ_ATAPI_WAIT_PIO_SETUP),\ |
| 267 | C(REQ_ATAPI_WAIT_D2H),\ |
| 268 | C(REQ_ATAPI_WAIT_TC_COMP),\ |
| 269 | C(REQ_TASK_WAIT_TC_COMP),\ |
| 270 | C(REQ_TASK_WAIT_TC_RESP),\ |
| 271 | C(REQ_SMP_WAIT_RESP),\ |
| 272 | C(REQ_SMP_WAIT_TC_COMP),\ |
| 273 | C(REQ_COMPLETED),\ |
| 274 | C(REQ_ABORTING),\ |
| 275 | C(REQ_FINAL),\ |
| 276 | } |
| 277 | #undef C |
| 278 | #define C(a) SCI_##a |
| 279 | enum sci_base_request_states REQUEST_STATES; |
| 280 | #undef C |
| 281 | const char *req_state_name(enum sci_base_request_states state); |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 282 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 283 | enum sci_status sci_request_start(struct isci_request *ireq); |
| 284 | enum sci_status sci_io_request_terminate(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 285 | enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 286 | sci_io_request_event_handler(struct isci_request *ireq, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 287 | u32 event_code); |
| 288 | enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 289 | sci_io_request_frame_handler(struct isci_request *ireq, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 290 | u32 frame_index); |
| 291 | enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 292 | sci_task_request_terminate(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 293 | extern enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 294 | sci_request_complete(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 295 | extern enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 296 | sci_io_request_tc_completion(struct isci_request *ireq, u32 code); |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 297 | |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 298 | /* XXX open code in caller */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 299 | static inline dma_addr_t |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 300 | 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] | 301 | { |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 302 | |
| 303 | char *requested_addr = (char *)virt_addr; |
| 304 | char *base_addr = (char *)ireq; |
| 305 | |
| 306 | BUG_ON(requested_addr < base_addr); |
| 307 | BUG_ON((requested_addr - base_addr) >= sizeof(*ireq)); |
| 308 | |
| 309 | return ireq->request_daddr + (requested_addr - base_addr); |
| 310 | } |
| 311 | |
| 312 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 313 | * isci_request_change_state() - This function sets the status of the request |
| 314 | * object. |
| 315 | * @request: This parameter points to the isci_request object |
| 316 | * @status: This Parameter is the new status of the object |
| 317 | * |
| 318 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 319 | static inline enum isci_request_status |
| 320 | isci_request_change_state(struct isci_request *isci_request, |
| 321 | enum isci_request_status status) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 322 | { |
| 323 | enum isci_request_status old_state; |
| 324 | unsigned long flags; |
| 325 | |
| 326 | dev_dbg(&isci_request->isci_host->pdev->dev, |
| 327 | "%s: isci_request = %p, state = 0x%x\n", |
| 328 | __func__, |
| 329 | isci_request, |
| 330 | status); |
| 331 | |
| 332 | BUG_ON(isci_request == NULL); |
| 333 | |
| 334 | spin_lock_irqsave(&isci_request->state_lock, flags); |
| 335 | old_state = isci_request->status; |
| 336 | isci_request->status = status; |
| 337 | spin_unlock_irqrestore(&isci_request->state_lock, flags); |
| 338 | |
| 339 | return old_state; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * isci_request_change_started_to_newstate() - This function sets the status of |
| 344 | * the request object. |
| 345 | * @request: This parameter points to the isci_request object |
| 346 | * @status: This Parameter is the new status of the object |
| 347 | * |
| 348 | * state previous to any change. |
| 349 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 350 | static inline enum isci_request_status |
| 351 | isci_request_change_started_to_newstate(struct isci_request *isci_request, |
| 352 | struct completion *completion_ptr, |
| 353 | enum isci_request_status newstate) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 354 | { |
| 355 | enum isci_request_status old_state; |
| 356 | unsigned long flags; |
| 357 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 358 | spin_lock_irqsave(&isci_request->state_lock, flags); |
| 359 | |
| 360 | old_state = isci_request->status; |
| 361 | |
Jeff Skirvin | f219f01 | 2011-03-31 13:10:34 -0700 | [diff] [blame] | 362 | if (old_state == started || old_state == aborting) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 363 | BUG_ON(isci_request->io_request_completion != NULL); |
| 364 | |
| 365 | isci_request->io_request_completion = completion_ptr; |
| 366 | isci_request->status = newstate; |
| 367 | } |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 368 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 369 | spin_unlock_irqrestore(&isci_request->state_lock, flags); |
| 370 | |
| 371 | dev_dbg(&isci_request->isci_host->pdev->dev, |
| 372 | "%s: isci_request = %p, old_state = 0x%x\n", |
| 373 | __func__, |
| 374 | isci_request, |
| 375 | old_state); |
| 376 | |
| 377 | return old_state; |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * isci_request_change_started_to_aborted() - This function sets the status of |
| 382 | * the request object. |
| 383 | * @request: This parameter points to the isci_request object |
| 384 | * @completion_ptr: This parameter is saved as the kernel completion structure |
| 385 | * signalled when the old request completes. |
| 386 | * |
| 387 | * state previous to any change. |
| 388 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 389 | static inline enum isci_request_status |
| 390 | isci_request_change_started_to_aborted(struct isci_request *isci_request, |
| 391 | struct completion *completion_ptr) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 392 | { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 393 | return isci_request_change_started_to_newstate(isci_request, |
| 394 | completion_ptr, |
| 395 | aborted); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 396 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 397 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 398 | #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 399 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 400 | #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 401 | |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 402 | struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost, |
| 403 | struct isci_tmf *isci_tmf, |
| 404 | u16 tag); |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 405 | 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] | 406 | struct sas_task *task, u16 tag); |
Dan Williams | ddcc7e3 | 2011-06-17 10:40:43 -0700 | [diff] [blame] | 407 | void isci_terminate_pending_requests(struct isci_host *ihost, |
| 408 | struct isci_remote_device *idev); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 409 | enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 410 | sci_task_request_construct(struct isci_host *ihost, |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 411 | struct isci_remote_device *idev, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 412 | u16 io_tag, |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 413 | struct isci_request *ireq); |
Dan Williams | 43a5ab1 | 2011-12-08 23:20:44 -0800 | [diff] [blame] | 414 | enum sci_status sci_task_request_construct_ssp(struct isci_request *ireq); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 415 | void sci_smp_request_copy_response(struct isci_request *ireq); |
Jeff Skirvin | 9274f45 | 2011-06-23 17:09:02 -0700 | [diff] [blame] | 416 | |
| 417 | static inline int isci_task_is_ncq_recovery(struct sas_task *task) |
| 418 | { |
| 419 | return (sas_protocol_ata(task->task_proto) && |
James Bottomley | a5ec7f86 | 2011-07-03 14:14:45 -0500 | [diff] [blame] | 420 | task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT && |
| 421 | task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ); |
Jeff Skirvin | 9274f45 | 2011-06-23 17:09:02 -0700 | [diff] [blame] | 422 | |
| 423 | } |
| 424 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 425 | #endif /* !defined(_ISCI_REQUEST_H_) */ |