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