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 | |
| 80 | enum task_type { |
| 81 | io_task = 0, |
| 82 | tmf_task = 1 |
| 83 | }; |
| 84 | |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 85 | enum sci_request_protocol { |
| 86 | SCIC_NO_PROTOCOL, |
| 87 | SCIC_SMP_PROTOCOL, |
| 88 | SCIC_SSP_PROTOCOL, |
| 89 | SCIC_STP_PROTOCOL |
Dan Williams | c72086e | 2011-05-10 02:28:48 -0700 | [diff] [blame] | 90 | }; /* XXX remove me, use sas_task.{dev|task_proto} instead */; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 91 | |
Dan Williams | ba7cb22 | 2011-06-27 11:56:41 -0700 | [diff] [blame] | 92 | /** |
| 93 | * isci_stp_request - extra request infrastructure to handle pio/atapi protocol |
| 94 | * @pio_len - number of bytes requested at PIO setup |
| 95 | * @status - pio setup ending status value to tell us if we need |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 96 | * to wait for another fis or if the transfer is complete. Upon |
Dan Williams | ba7cb22 | 2011-06-27 11:56:41 -0700 | [diff] [blame] | 97 | * receipt of a d2h fis this will be the status field of that fis. |
| 98 | * @sgl - track pio transfer progress as we iterate through the sgl |
| 99 | * @device_cdb_len - atapi device advertises it's transfer constraints at setup |
| 100 | */ |
| 101 | struct isci_stp_request { |
| 102 | u32 pio_len; |
| 103 | u8 status; |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 104 | |
Dan Williams | ba7cb22 | 2011-06-27 11:56:41 -0700 | [diff] [blame] | 105 | struct isci_stp_pio_sgl { |
| 106 | int index; |
| 107 | u8 set; |
| 108 | u32 offset; |
| 109 | } sgl; |
| 110 | u32 device_cdb_len; |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 113 | struct isci_request { |
| 114 | enum isci_request_status status; |
| 115 | #define IREQ_COMPLETE_IN_TARGET 0 |
| 116 | #define IREQ_TERMINATED 1 |
| 117 | #define IREQ_TMF 2 |
| 118 | #define IREQ_ACTIVE 3 |
| 119 | unsigned long flags; |
| 120 | /* XXX kill ttype and ttype_ptr, allocate full sas_task */ |
| 121 | enum task_type ttype; |
| 122 | union ttype_ptr_union { |
| 123 | struct sas_task *io_task_ptr; /* When ttype==io_task */ |
| 124 | struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */ |
| 125 | } ttype_ptr; |
| 126 | struct isci_host *isci_host; |
| 127 | /* For use in the requests_to_{complete|abort} lists: */ |
| 128 | struct list_head completed_node; |
| 129 | /* For use in the reqs_in_process list: */ |
| 130 | struct list_head dev_node; |
| 131 | spinlock_t state_lock; |
| 132 | dma_addr_t request_daddr; |
| 133 | dma_addr_t zero_scatter_daddr; |
| 134 | unsigned int num_sg_entries; |
| 135 | /* Note: "io_request_completion" is completed in two different ways |
| 136 | * depending on whether this is a TMF or regular request. |
| 137 | * - TMF requests are completed in the thread that started them; |
| 138 | * - regular requests are completed in the request completion callback |
| 139 | * function. |
| 140 | * This difference in operation allows the aborter of a TMF request |
| 141 | * to be sure that once the TMF request completes, the I/O that the |
| 142 | * TMF was aborting is guaranteed to have completed. |
| 143 | * |
| 144 | * XXX kill io_request_completion |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 145 | */ |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 146 | struct completion *io_request_completion; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 147 | struct sci_base_state_machine sm; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 148 | struct scic_sds_controller *owning_controller; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 149 | struct scic_sds_remote_device *target_device; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 150 | u16 io_tag; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 151 | enum sci_request_protocol protocol; |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 152 | u32 scu_status; /* hardware result */ |
| 153 | u32 sci_status; /* upper layer disposition */ |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 154 | u32 post_context; |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 155 | struct scu_task_context *tc; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 156 | /* could be larger with sg chaining */ |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 157 | #define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2) |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 158 | 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^] | 159 | /* 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] | 160 | * STP internal requests and SMP response frames. If this field is |
| 161 | * non-NULL the saved frame must be released on IO request completion. |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 162 | */ |
| 163 | u32 saved_rx_frame_index; |
| 164 | |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 165 | union { |
| 166 | struct { |
| 167 | union { |
| 168 | struct ssp_cmd_iu cmd; |
| 169 | struct ssp_task_iu tmf; |
| 170 | }; |
| 171 | union { |
| 172 | struct ssp_response_iu rsp; |
| 173 | u8 rsp_buf[SSP_RESP_IU_MAX_SIZE]; |
| 174 | }; |
| 175 | } ssp; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 176 | struct { |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 177 | struct smp_resp rsp; |
| 178 | } smp; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 179 | struct { |
Dan Williams | ba7cb22 | 2011-06-27 11:56:41 -0700 | [diff] [blame] | 180 | struct isci_stp_request req; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 181 | struct host_to_dev_fis cmd; |
| 182 | struct dev_to_host_fis rsp; |
| 183 | } stp; |
| 184 | }; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 187 | 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] | 188 | { |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 189 | struct isci_request *ireq; |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 190 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 191 | ireq = container_of(stp_req, typeof(*ireq), stp.req); |
Dan Williams | 67ea838 | 2011-05-08 11:47:15 -0700 | [diff] [blame] | 192 | return ireq; |
| 193 | } |
| 194 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 195 | /** |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 196 | * enum sci_base_request_states - This enumeration depicts all the states for |
| 197 | * the common request state machine. |
| 198 | * |
| 199 | * |
| 200 | */ |
| 201 | enum sci_base_request_states { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 202 | /* |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 203 | * Simply the initial state for the base request state machine. |
| 204 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 205 | SCI_REQ_INIT, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 206 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 207 | /* |
| 208 | * This state indicates that the request has been constructed. |
| 209 | * This state is entered from the INITIAL state. |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 210 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 211 | SCI_REQ_CONSTRUCTED, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 212 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 213 | /* |
| 214 | * This state indicates that the request has been started. This state |
| 215 | * is entered from the CONSTRUCTED state. |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 216 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 217 | SCI_REQ_STARTED, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 218 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 219 | SCI_REQ_STP_UDMA_WAIT_TC_COMP, |
| 220 | SCI_REQ_STP_UDMA_WAIT_D2H, |
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_NON_DATA_WAIT_H2D, |
| 223 | SCI_REQ_STP_NON_DATA_WAIT_D2H, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 224 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 225 | SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED, |
| 226 | SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG, |
| 227 | SCI_REQ_STP_SOFT_RESET_WAIT_D2H, |
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 | /* |
| 230 | * While in this state the IO request object is waiting for the TC |
| 231 | * completion notification for the H2D Register FIS |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 232 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 233 | SCI_REQ_STP_PIO_WAIT_H2D, |
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 | /* |
| 236 | * While in this state the IO request object is waiting for either a |
| 237 | * PIO Setup FIS or a D2H register FIS. The type of frame received is |
| 238 | * based on the result of the prior frame and line conditions. |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 239 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 240 | SCI_REQ_STP_PIO_WAIT_FRAME, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 241 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 242 | /* |
| 243 | * While in this state the IO request object is waiting for a DATA |
| 244 | * frame from the device. |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 245 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 246 | SCI_REQ_STP_PIO_DATA_IN, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 247 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 248 | /* |
| 249 | * While in this state the IO request object is waiting to transmit |
| 250 | * the next data frame to the device. |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 251 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 252 | SCI_REQ_STP_PIO_DATA_OUT, |
Dan Williams | 5dec6f4 | 2011-05-10 02:28:49 -0700 | [diff] [blame] | 253 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 254 | /* |
Dan Williams | f139303 | 2011-05-10 02:28:47 -0700 | [diff] [blame] | 255 | * The AWAIT_TC_COMPLETION sub-state indicates that the started raw |
| 256 | * task management request is waiting for the transmission of the |
| 257 | * initial frame (i.e. command, task, etc.). |
| 258 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 259 | SCI_REQ_TASK_WAIT_TC_COMP, |
Dan Williams | f139303 | 2011-05-10 02:28:47 -0700 | [diff] [blame] | 260 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 261 | /* |
Dan Williams | f139303 | 2011-05-10 02:28:47 -0700 | [diff] [blame] | 262 | * This sub-state indicates that the started task management request |
| 263 | * is waiting for the reception of an unsolicited frame |
| 264 | * (i.e. response IU). |
| 265 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 266 | SCI_REQ_TASK_WAIT_TC_RESP, |
Dan Williams | f139303 | 2011-05-10 02:28:47 -0700 | [diff] [blame] | 267 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 268 | /* |
Dan Williams | c72086e | 2011-05-10 02:28:48 -0700 | [diff] [blame] | 269 | * This sub-state indicates that the started task management request |
| 270 | * is waiting for the reception of an unsolicited frame |
| 271 | * (i.e. response IU). |
| 272 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 273 | SCI_REQ_SMP_WAIT_RESP, |
Dan Williams | c72086e | 2011-05-10 02:28:48 -0700 | [diff] [blame] | 274 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 275 | /* |
| 276 | * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP |
| 277 | * request is waiting for the transmission of the initial frame |
| 278 | * (i.e. command, task, etc.). |
Dan Williams | c72086e | 2011-05-10 02:28:48 -0700 | [diff] [blame] | 279 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 280 | SCI_REQ_SMP_WAIT_TC_COMP, |
Dan Williams | c72086e | 2011-05-10 02:28:48 -0700 | [diff] [blame] | 281 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 282 | /* |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 283 | * This state indicates that the request has completed. |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 284 | * This state is entered from the STARTED state. This state is entered |
| 285 | * from the ABORTING state. |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 286 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 287 | SCI_REQ_COMPLETED, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 288 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 289 | /* |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 290 | * This state indicates that the request is in the process of being |
| 291 | * terminated/aborted. |
| 292 | * This state is entered from the CONSTRUCTED state. |
| 293 | * This state is entered from the STARTED state. |
| 294 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 295 | SCI_REQ_ABORTING, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -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 | * Simply the final state for the base request state machine. |
| 299 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 300 | SCI_REQ_FINAL, |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 301 | }; |
| 302 | |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 303 | /** |
| 304 | * scic_sds_request_get_controller() - |
| 305 | * |
| 306 | * This macro will return the controller for this io request object |
| 307 | */ |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 308 | #define scic_sds_request_get_controller(ireq) \ |
| 309 | ((ireq)->owning_controller) |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 310 | |
| 311 | /** |
| 312 | * scic_sds_request_get_device() - |
| 313 | * |
| 314 | * This macro will return the device for this io request object |
| 315 | */ |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 316 | #define scic_sds_request_get_device(ireq) \ |
| 317 | ((ireq)->target_device) |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 318 | |
| 319 | /** |
| 320 | * scic_sds_request_get_port() - |
| 321 | * |
| 322 | * This macro will return the port for this io request object |
| 323 | */ |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 324 | #define scic_sds_request_get_port(ireq) \ |
| 325 | scic_sds_remote_device_get_port(scic_sds_request_get_device(ireq)) |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 326 | |
| 327 | /** |
| 328 | * scic_sds_request_get_post_context() - |
| 329 | * |
| 330 | * This macro returns the constructed post context result for the io request. |
| 331 | */ |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 332 | #define scic_sds_request_get_post_context(ireq) \ |
| 333 | ((ireq)->post_context) |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 334 | |
| 335 | /** |
| 336 | * scic_sds_request_get_task_context() - |
| 337 | * |
| 338 | * This is a helper macro to return the os handle for this request object. |
| 339 | */ |
| 340 | #define scic_sds_request_get_task_context(request) \ |
| 341 | ((request)->task_context_buffer) |
| 342 | |
| 343 | /** |
| 344 | * scic_sds_request_set_status() - |
| 345 | * |
| 346 | * This macro will set the scu hardware status and sci request completion |
| 347 | * status for an io request. |
| 348 | */ |
| 349 | #define scic_sds_request_set_status(request, scu_status_code, sci_status_code) \ |
| 350 | { \ |
| 351 | (request)->scu_status = (scu_status_code); \ |
| 352 | (request)->sci_status = (sci_status_code); \ |
| 353 | } |
| 354 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 355 | enum sci_status scic_sds_request_start(struct isci_request *ireq); |
| 356 | enum sci_status scic_sds_io_request_terminate(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 357 | enum sci_status |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 358 | scic_sds_io_request_event_handler(struct isci_request *ireq, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 359 | u32 event_code); |
| 360 | enum sci_status |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 361 | scic_sds_io_request_frame_handler(struct isci_request *ireq, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 362 | u32 frame_index); |
| 363 | enum sci_status |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 364 | scic_sds_task_request_terminate(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 365 | extern enum sci_status |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 366 | scic_sds_request_complete(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 367 | extern enum sci_status |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 368 | scic_sds_io_request_tc_completion(struct isci_request *ireq, u32 code); |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 369 | |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 370 | /* XXX open code in caller */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 371 | static inline dma_addr_t |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 372 | scic_io_request_get_dma_addr(struct isci_request *ireq, void *virt_addr) |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 373 | { |
Dan Williams | f1f52e7 | 2011-05-10 02:28:45 -0700 | [diff] [blame] | 374 | |
| 375 | char *requested_addr = (char *)virt_addr; |
| 376 | char *base_addr = (char *)ireq; |
| 377 | |
| 378 | BUG_ON(requested_addr < base_addr); |
| 379 | BUG_ON((requested_addr - base_addr) >= sizeof(*ireq)); |
| 380 | |
| 381 | return ireq->request_daddr + (requested_addr - base_addr); |
| 382 | } |
| 383 | |
| 384 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 385 | * This function gets the status of the request object. |
| 386 | * @request: This parameter points to the isci_request object |
| 387 | * |
| 388 | * status of the object as a isci_request_status enum. |
| 389 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 390 | static inline enum isci_request_status |
| 391 | isci_request_get_state(struct isci_request *isci_request) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 392 | { |
| 393 | BUG_ON(isci_request == NULL); |
| 394 | |
| 395 | /*probably a bad sign... */ |
| 396 | if (isci_request->status == unallocated) |
| 397 | dev_warn(&isci_request->isci_host->pdev->dev, |
| 398 | "%s: isci_request->status == unallocated\n", |
| 399 | __func__); |
| 400 | |
| 401 | return isci_request->status; |
| 402 | } |
| 403 | |
| 404 | |
| 405 | /** |
| 406 | * isci_request_change_state() - This function sets the status of the request |
| 407 | * object. |
| 408 | * @request: This parameter points to the isci_request object |
| 409 | * @status: This Parameter is the new status of the object |
| 410 | * |
| 411 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 412 | static inline enum isci_request_status |
| 413 | isci_request_change_state(struct isci_request *isci_request, |
| 414 | enum isci_request_status status) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 415 | { |
| 416 | enum isci_request_status old_state; |
| 417 | unsigned long flags; |
| 418 | |
| 419 | dev_dbg(&isci_request->isci_host->pdev->dev, |
| 420 | "%s: isci_request = %p, state = 0x%x\n", |
| 421 | __func__, |
| 422 | isci_request, |
| 423 | status); |
| 424 | |
| 425 | BUG_ON(isci_request == NULL); |
| 426 | |
| 427 | spin_lock_irqsave(&isci_request->state_lock, flags); |
| 428 | old_state = isci_request->status; |
| 429 | isci_request->status = status; |
| 430 | spin_unlock_irqrestore(&isci_request->state_lock, flags); |
| 431 | |
| 432 | return old_state; |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * isci_request_change_started_to_newstate() - This function sets the status of |
| 437 | * the request object. |
| 438 | * @request: This parameter points to the isci_request object |
| 439 | * @status: This Parameter is the new status of the object |
| 440 | * |
| 441 | * state previous to any change. |
| 442 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 443 | static inline enum isci_request_status |
| 444 | isci_request_change_started_to_newstate(struct isci_request *isci_request, |
| 445 | struct completion *completion_ptr, |
| 446 | enum isci_request_status newstate) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 447 | { |
| 448 | enum isci_request_status old_state; |
| 449 | unsigned long flags; |
| 450 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 451 | spin_lock_irqsave(&isci_request->state_lock, flags); |
| 452 | |
| 453 | old_state = isci_request->status; |
| 454 | |
Jeff Skirvin | f219f01 | 2011-03-31 13:10:34 -0700 | [diff] [blame] | 455 | if (old_state == started || old_state == aborting) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 456 | BUG_ON(isci_request->io_request_completion != NULL); |
| 457 | |
| 458 | isci_request->io_request_completion = completion_ptr; |
| 459 | isci_request->status = newstate; |
| 460 | } |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 461 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 462 | spin_unlock_irqrestore(&isci_request->state_lock, flags); |
| 463 | |
| 464 | dev_dbg(&isci_request->isci_host->pdev->dev, |
| 465 | "%s: isci_request = %p, old_state = 0x%x\n", |
| 466 | __func__, |
| 467 | isci_request, |
| 468 | old_state); |
| 469 | |
| 470 | return old_state; |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * isci_request_change_started_to_aborted() - This function sets the status of |
| 475 | * the request object. |
| 476 | * @request: This parameter points to the isci_request object |
| 477 | * @completion_ptr: This parameter is saved as the kernel completion structure |
| 478 | * signalled when the old request completes. |
| 479 | * |
| 480 | * state previous to any change. |
| 481 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 482 | static inline enum isci_request_status |
| 483 | isci_request_change_started_to_aborted(struct isci_request *isci_request, |
| 484 | struct completion *completion_ptr) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 485 | { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 486 | return isci_request_change_started_to_newstate(isci_request, |
| 487 | completion_ptr, |
| 488 | aborted); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 489 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 490 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 491 | #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 492 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 493 | #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 494 | |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 495 | struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost, |
| 496 | struct isci_tmf *isci_tmf, |
| 497 | u16 tag); |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 498 | 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] | 499 | struct sas_task *task, u16 tag); |
Dan Williams | ddcc7e3 | 2011-06-17 10:40:43 -0700 | [diff] [blame] | 500 | void isci_terminate_pending_requests(struct isci_host *ihost, |
| 501 | struct isci_remote_device *idev); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 502 | enum sci_status |
| 503 | scic_task_request_construct(struct scic_sds_controller *scic, |
| 504 | struct scic_sds_remote_device *sci_dev, |
| 505 | u16 io_tag, |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 506 | struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 507 | enum sci_status |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 508 | scic_task_request_construct_ssp(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 509 | enum sci_status |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 510 | scic_task_request_construct_sata(struct isci_request *ireq); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 511 | void |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame^] | 512 | scic_stp_io_request_set_ncq_tag(struct isci_request *ireq, u16 ncq_tag); |
| 513 | void scic_sds_smp_request_copy_response(struct isci_request *ireq); |
Jeff Skirvin | 9274f45 | 2011-06-23 17:09:02 -0700 | [diff] [blame] | 514 | |
| 515 | static inline int isci_task_is_ncq_recovery(struct sas_task *task) |
| 516 | { |
| 517 | return (sas_protocol_ata(task->task_proto) && |
| 518 | task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT && |
| 519 | task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ); |
| 520 | |
| 521 | } |
| 522 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 523 | #endif /* !defined(_ISCI_REQUEST_H_) */ |