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