16f231ddaSDan Williams /* 26f231ddaSDan Williams * This file is provided under a dual BSD/GPLv2 license. When using or 36f231ddaSDan Williams * redistributing this file, you may do so under either license. 46f231ddaSDan Williams * 56f231ddaSDan Williams * GPL LICENSE SUMMARY 66f231ddaSDan Williams * 76f231ddaSDan Williams * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 86f231ddaSDan Williams * 96f231ddaSDan Williams * This program is free software; you can redistribute it and/or modify 106f231ddaSDan Williams * it under the terms of version 2 of the GNU General Public License as 116f231ddaSDan Williams * published by the Free Software Foundation. 126f231ddaSDan Williams * 136f231ddaSDan Williams * This program is distributed in the hope that it will be useful, but 146f231ddaSDan Williams * WITHOUT ANY WARRANTY; without even the implied warranty of 156f231ddaSDan Williams * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 166f231ddaSDan Williams * General Public License for more details. 176f231ddaSDan Williams * 186f231ddaSDan Williams * You should have received a copy of the GNU General Public License 196f231ddaSDan Williams * along with this program; if not, write to the Free Software 206f231ddaSDan Williams * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 216f231ddaSDan Williams * The full GNU General Public License is included in this distribution 226f231ddaSDan Williams * in the file called LICENSE.GPL. 236f231ddaSDan Williams * 246f231ddaSDan Williams * BSD LICENSE 256f231ddaSDan Williams * 266f231ddaSDan Williams * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. 276f231ddaSDan Williams * All rights reserved. 286f231ddaSDan Williams * 296f231ddaSDan Williams * Redistribution and use in source and binary forms, with or without 306f231ddaSDan Williams * modification, are permitted provided that the following conditions 316f231ddaSDan Williams * are met: 326f231ddaSDan Williams * 336f231ddaSDan Williams * * Redistributions of source code must retain the above copyright 346f231ddaSDan Williams * notice, this list of conditions and the following disclaimer. 356f231ddaSDan Williams * * Redistributions in binary form must reproduce the above copyright 366f231ddaSDan Williams * notice, this list of conditions and the following disclaimer in 376f231ddaSDan Williams * the documentation and/or other materials provided with the 386f231ddaSDan Williams * distribution. 396f231ddaSDan Williams * * Neither the name of Intel Corporation nor the names of its 406f231ddaSDan Williams * contributors may be used to endorse or promote products derived 416f231ddaSDan Williams * from this software without specific prior written permission. 426f231ddaSDan Williams * 436f231ddaSDan Williams * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 446f231ddaSDan Williams * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 456f231ddaSDan Williams * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 466f231ddaSDan Williams * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 476f231ddaSDan Williams * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 486f231ddaSDan Williams * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 496f231ddaSDan Williams * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 506f231ddaSDan Williams * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 516f231ddaSDan Williams * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 526f231ddaSDan Williams * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 536f231ddaSDan Williams * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 546f231ddaSDan Williams */ 556f231ddaSDan Williams 560d84366fSDan Williams #ifndef _ISCI_REQUEST_H_ 576f231ddaSDan Williams #define _ISCI_REQUEST_H_ 586f231ddaSDan Williams 596f231ddaSDan Williams #include "isci.h" 60ce2b3261SDan Williams #include "host.h" 61f1f52e75SDan Williams #include "scu_task_context.h" 626f231ddaSDan Williams 636f231ddaSDan Williams /** 646f231ddaSDan Williams * struct isci_request_status - This enum defines the possible states of an I/O 656f231ddaSDan Williams * request. 666f231ddaSDan Williams * 676f231ddaSDan Williams * 686f231ddaSDan Williams */ 696f231ddaSDan Williams enum isci_request_status { 706f231ddaSDan Williams unallocated = 0x00, 716f231ddaSDan Williams allocated = 0x01, 726f231ddaSDan Williams started = 0x02, 736f231ddaSDan Williams completed = 0x03, 746f231ddaSDan Williams aborting = 0x04, 756f231ddaSDan Williams aborted = 0x05, 764dc043c4SJeff Skirvin terminating = 0x06, 774dc043c4SJeff Skirvin dead = 0x07 786f231ddaSDan Williams }; 796f231ddaSDan Williams 806f231ddaSDan Williams enum task_type { 816f231ddaSDan Williams io_task = 0, 826f231ddaSDan Williams tmf_task = 1 836f231ddaSDan Williams }; 846f231ddaSDan Williams 85f1f52e75SDan Williams enum sci_request_protocol { 86f1f52e75SDan Williams SCIC_NO_PROTOCOL, 87f1f52e75SDan Williams SCIC_SMP_PROTOCOL, 88f1f52e75SDan Williams SCIC_SSP_PROTOCOL, 89f1f52e75SDan Williams SCIC_STP_PROTOCOL 90c72086e3SDan Williams }; /* XXX remove me, use sas_task.{dev|task_proto} instead */; 91f1f52e75SDan Williams 92*ba7cb223SDan Williams /** 93*ba7cb223SDan Williams * isci_stp_request - extra request infrastructure to handle pio/atapi protocol 94*ba7cb223SDan Williams * @pio_len - number of bytes requested at PIO setup 95*ba7cb223SDan Williams * @status - pio setup ending status value to tell us if we need 96*ba7cb223SDan Williams * to wait for another fis or if the transfer is complete. Upon 97*ba7cb223SDan Williams * receipt of a d2h fis this will be the status field of that fis. 98*ba7cb223SDan Williams * @sgl - track pio transfer progress as we iterate through the sgl 99*ba7cb223SDan Williams * @device_cdb_len - atapi device advertises it's transfer constraints at setup 1005dec6f4eSDan Williams */ 101*ba7cb223SDan Williams struct isci_stp_request { 102*ba7cb223SDan Williams u32 pio_len; 103*ba7cb223SDan Williams u8 status; 1045dec6f4eSDan Williams 105*ba7cb223SDan Williams struct isci_stp_pio_sgl { 106*ba7cb223SDan Williams int index; 107*ba7cb223SDan Williams u8 set; 108*ba7cb223SDan Williams u32 offset; 109*ba7cb223SDan Williams } sgl; 110*ba7cb223SDan Williams u32 device_cdb_len; 1115dec6f4eSDan Williams }; 1125dec6f4eSDan Williams 113f1f52e75SDan Williams struct scic_sds_request { 114e301370aSEdmund Nadolski /* 115e301370aSEdmund Nadolski * This field contains the information for the base request state 116e301370aSEdmund Nadolski * machine. 117f1f52e75SDan Williams */ 118e301370aSEdmund Nadolski struct sci_base_state_machine sm; 119f1f52e75SDan Williams 120e301370aSEdmund Nadolski /* 121f1f52e75SDan Williams * This field simply points to the controller to which this IO request 122f1f52e75SDan Williams * is associated. 123f1f52e75SDan Williams */ 124f1f52e75SDan Williams struct scic_sds_controller *owning_controller; 125f1f52e75SDan Williams 126e301370aSEdmund Nadolski /* 127e301370aSEdmund Nadolski * This field simply points to the remote device to which this IO 128e301370aSEdmund Nadolski * request is associated. 129f1f52e75SDan Williams */ 130f1f52e75SDan Williams struct scic_sds_remote_device *target_device; 131f1f52e75SDan Williams 132e301370aSEdmund Nadolski /* 133f1f52e75SDan Williams * This field indicates the IO tag for this request. The IO tag is 134f1f52e75SDan Williams * comprised of the task_index and a sequence count. The sequence count 135f1f52e75SDan Williams * is utilized to help identify tasks from one life to another. 136f1f52e75SDan Williams */ 137f1f52e75SDan Williams u16 io_tag; 138f1f52e75SDan Williams 139e301370aSEdmund Nadolski /* 140f1f52e75SDan Williams * This field specifies the protocol being utilized for this 141f1f52e75SDan Williams * IO request. 142f1f52e75SDan Williams */ 143f1f52e75SDan Williams enum sci_request_protocol protocol; 144f1f52e75SDan Williams 145e301370aSEdmund Nadolski /* 146f1f52e75SDan Williams * This field indicates the completion status taken from the SCUs 147e301370aSEdmund Nadolski * completion code. It indicates the completion result for the SCU 148e301370aSEdmund Nadolski * hardware. 149f1f52e75SDan Williams */ 150f1f52e75SDan Williams u32 scu_status; 151f1f52e75SDan Williams 152e301370aSEdmund Nadolski /* 153e301370aSEdmund Nadolski * This field indicates the completion status returned to the SCI user. 154e301370aSEdmund Nadolski * It indicates the users view of the io request completion. 155f1f52e75SDan Williams */ 156f1f52e75SDan Williams u32 sci_status; 157f1f52e75SDan Williams 158e301370aSEdmund Nadolski /* 159e301370aSEdmund Nadolski * This field contains the value to be utilized when posting 160e301370aSEdmund Nadolski * (e.g. Post_TC, * Post_TC_Abort) this request to the silicon. 161f1f52e75SDan Williams */ 162f1f52e75SDan Williams u32 post_context; 163f1f52e75SDan Williams 164312e0c24SDan Williams struct scu_task_context *tc; 165f1f52e75SDan Williams 166f1f52e75SDan Williams /* could be larger with sg chaining */ 1677c78da31SDan Williams #define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2) 168f1f52e75SDan Williams struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32))); 169f1f52e75SDan Williams 170e301370aSEdmund Nadolski /* 171e301370aSEdmund Nadolski * This field is a pointer to the stored rx frame data. It is used in 172e301370aSEdmund Nadolski * STP internal requests and SMP response frames. If this field is 173e301370aSEdmund Nadolski * non-NULL the saved frame must be released on IO request completion. 174f1f52e75SDan Williams * 175f1f52e75SDan Williams * @todo In the future do we want to keep a list of RX frame buffers? 176f1f52e75SDan Williams */ 177f1f52e75SDan Williams u32 saved_rx_frame_index; 178f1f52e75SDan Williams 179f1f52e75SDan Williams union { 180f1f52e75SDan Williams struct { 181f1f52e75SDan Williams union { 182f1f52e75SDan Williams struct ssp_cmd_iu cmd; 183f1f52e75SDan Williams struct ssp_task_iu tmf; 184f1f52e75SDan Williams }; 185f1f52e75SDan Williams union { 186f1f52e75SDan Williams struct ssp_response_iu rsp; 187f1f52e75SDan Williams u8 rsp_buf[SSP_RESP_IU_MAX_SIZE]; 188f1f52e75SDan Williams }; 189f1f52e75SDan Williams } ssp; 190f1f52e75SDan Williams 191f1f52e75SDan Williams struct { 192f1f52e75SDan Williams struct smp_resp rsp; 193f1f52e75SDan Williams } smp; 194f1f52e75SDan Williams 195f1f52e75SDan Williams struct { 196*ba7cb223SDan Williams struct isci_stp_request req; 197f1f52e75SDan Williams struct host_to_dev_fis cmd; 198f1f52e75SDan Williams struct dev_to_host_fis rsp; 199f1f52e75SDan Williams } stp; 200f1f52e75SDan Williams }; 201f1f52e75SDan Williams }; 202f1f52e75SDan Williams 203*ba7cb223SDan Williams static inline struct scic_sds_request *to_sci_req(struct isci_stp_request *stp_req) 204f1f52e75SDan Williams { 205f1f52e75SDan Williams struct scic_sds_request *sci_req; 206f1f52e75SDan Williams 207f1f52e75SDan Williams sci_req = container_of(stp_req, typeof(*sci_req), stp.req); 208f1f52e75SDan Williams return sci_req; 209f1f52e75SDan Williams } 210f1f52e75SDan Williams 2116f231ddaSDan Williams struct isci_request { 2126f231ddaSDan Williams enum isci_request_status status; 2136f231ddaSDan Williams enum task_type ttype; 2146f231ddaSDan Williams unsigned short io_tag; 21538d8879bSDan Williams #define IREQ_COMPLETE_IN_TARGET 0 21638d8879bSDan Williams #define IREQ_TERMINATED 1 21738d8879bSDan Williams #define IREQ_TMF 2 218db056250SDan Williams #define IREQ_ACTIVE 3 21938d8879bSDan Williams unsigned long flags; 2206f231ddaSDan Williams 2216f231ddaSDan Williams union ttype_ptr_union { 2226f231ddaSDan Williams struct sas_task *io_task_ptr; /* When ttype==io_task */ 2236f231ddaSDan Williams struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */ 2246f231ddaSDan Williams } ttype_ptr; 2256f231ddaSDan Williams struct isci_host *isci_host; 2266f231ddaSDan Williams /* For use in the requests_to_{complete|abort} lists: */ 2276f231ddaSDan Williams struct list_head completed_node; 2286f231ddaSDan Williams /* For use in the reqs_in_process list: */ 2296f231ddaSDan Williams struct list_head dev_node; 2306f231ddaSDan Williams spinlock_t state_lock; 2316f231ddaSDan Williams dma_addr_t request_daddr; 2326f231ddaSDan Williams dma_addr_t zero_scatter_daddr; 2336f231ddaSDan Williams 2346f231ddaSDan Williams unsigned int num_sg_entries; /* returned by pci_alloc_sg */ 2356f231ddaSDan Williams 2366f231ddaSDan Williams /** Note: "io_request_completion" is completed in two different ways 2376f231ddaSDan Williams * depending on whether this is a TMF or regular request. 2386f231ddaSDan Williams * - TMF requests are completed in the thread that started them; 2396f231ddaSDan Williams * - regular requests are completed in the request completion callback 2406f231ddaSDan Williams * function. 2416f231ddaSDan Williams * This difference in operation allows the aborter of a TMF request 2426f231ddaSDan Williams * to be sure that once the TMF request completes, the I/O that the 2436f231ddaSDan Williams * TMF was aborting is guaranteed to have completed. 2446f231ddaSDan Williams */ 2456f231ddaSDan Williams struct completion *io_request_completion; 24667ea838dSDan Williams struct scic_sds_request sci; 2476f231ddaSDan Williams }; 2486f231ddaSDan Williams 24967ea838dSDan Williams static inline struct isci_request *sci_req_to_ireq(struct scic_sds_request *sci_req) 25067ea838dSDan Williams { 25167ea838dSDan Williams struct isci_request *ireq = container_of(sci_req, typeof(*ireq), sci); 25267ea838dSDan Williams 25367ea838dSDan Williams return ireq; 25467ea838dSDan Williams } 25567ea838dSDan Williams 2566f231ddaSDan Williams /** 257f1f52e75SDan Williams * enum sci_base_request_states - This enumeration depicts all the states for 258f1f52e75SDan Williams * the common request state machine. 259f1f52e75SDan Williams * 260f1f52e75SDan Williams * 261f1f52e75SDan Williams */ 262f1f52e75SDan Williams enum sci_base_request_states { 263e301370aSEdmund Nadolski /* 264f1f52e75SDan Williams * Simply the initial state for the base request state machine. 265f1f52e75SDan Williams */ 266e301370aSEdmund Nadolski SCI_REQ_INIT, 267f1f52e75SDan Williams 268e301370aSEdmund Nadolski /* 269e301370aSEdmund Nadolski * This state indicates that the request has been constructed. 270e301370aSEdmund Nadolski * This state is entered from the INITIAL state. 271f1f52e75SDan Williams */ 272e301370aSEdmund Nadolski SCI_REQ_CONSTRUCTED, 273f1f52e75SDan Williams 274e301370aSEdmund Nadolski /* 275e301370aSEdmund Nadolski * This state indicates that the request has been started. This state 276e301370aSEdmund Nadolski * is entered from the CONSTRUCTED state. 277f1f52e75SDan Williams */ 278e301370aSEdmund Nadolski SCI_REQ_STARTED, 279f1f52e75SDan Williams 280e301370aSEdmund Nadolski SCI_REQ_STP_UDMA_WAIT_TC_COMP, 281e301370aSEdmund Nadolski SCI_REQ_STP_UDMA_WAIT_D2H, 2825dec6f4eSDan Williams 283e301370aSEdmund Nadolski SCI_REQ_STP_NON_DATA_WAIT_H2D, 284e301370aSEdmund Nadolski SCI_REQ_STP_NON_DATA_WAIT_D2H, 2855dec6f4eSDan Williams 286e301370aSEdmund Nadolski SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED, 287e301370aSEdmund Nadolski SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG, 288e301370aSEdmund Nadolski SCI_REQ_STP_SOFT_RESET_WAIT_D2H, 2895dec6f4eSDan Williams 290e301370aSEdmund Nadolski /* 291e301370aSEdmund Nadolski * While in this state the IO request object is waiting for the TC 292e301370aSEdmund Nadolski * completion notification for the H2D Register FIS 2935dec6f4eSDan Williams */ 294e301370aSEdmund Nadolski SCI_REQ_STP_PIO_WAIT_H2D, 2955dec6f4eSDan Williams 296e301370aSEdmund Nadolski /* 297e301370aSEdmund Nadolski * While in this state the IO request object is waiting for either a 298e301370aSEdmund Nadolski * PIO Setup FIS or a D2H register FIS. The type of frame received is 299e301370aSEdmund Nadolski * based on the result of the prior frame and line conditions. 3005dec6f4eSDan Williams */ 301e301370aSEdmund Nadolski SCI_REQ_STP_PIO_WAIT_FRAME, 3025dec6f4eSDan Williams 303e301370aSEdmund Nadolski /* 304e301370aSEdmund Nadolski * While in this state the IO request object is waiting for a DATA 305e301370aSEdmund Nadolski * frame from the device. 3065dec6f4eSDan Williams */ 307e301370aSEdmund Nadolski SCI_REQ_STP_PIO_DATA_IN, 3085dec6f4eSDan Williams 309e301370aSEdmund Nadolski /* 310e301370aSEdmund Nadolski * While in this state the IO request object is waiting to transmit 311e301370aSEdmund Nadolski * the next data frame to the device. 3125dec6f4eSDan Williams */ 313e301370aSEdmund Nadolski SCI_REQ_STP_PIO_DATA_OUT, 3145dec6f4eSDan Williams 315e301370aSEdmund Nadolski /* 316f139303dSDan Williams * The AWAIT_TC_COMPLETION sub-state indicates that the started raw 317f139303dSDan Williams * task management request is waiting for the transmission of the 318f139303dSDan Williams * initial frame (i.e. command, task, etc.). 319f139303dSDan Williams */ 320e301370aSEdmund Nadolski SCI_REQ_TASK_WAIT_TC_COMP, 321f139303dSDan Williams 322e301370aSEdmund Nadolski /* 323f139303dSDan Williams * This sub-state indicates that the started task management request 324f139303dSDan Williams * is waiting for the reception of an unsolicited frame 325f139303dSDan Williams * (i.e. response IU). 326f139303dSDan Williams */ 327e301370aSEdmund Nadolski SCI_REQ_TASK_WAIT_TC_RESP, 328f139303dSDan Williams 329e301370aSEdmund Nadolski /* 330c72086e3SDan Williams * This sub-state indicates that the started task management request 331c72086e3SDan Williams * is waiting for the reception of an unsolicited frame 332c72086e3SDan Williams * (i.e. response IU). 333c72086e3SDan Williams */ 334e301370aSEdmund Nadolski SCI_REQ_SMP_WAIT_RESP, 335c72086e3SDan Williams 336e301370aSEdmund Nadolski /* 337e301370aSEdmund Nadolski * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP 338e301370aSEdmund Nadolski * request is waiting for the transmission of the initial frame 339e301370aSEdmund Nadolski * (i.e. command, task, etc.). 340c72086e3SDan Williams */ 341e301370aSEdmund Nadolski SCI_REQ_SMP_WAIT_TC_COMP, 342c72086e3SDan Williams 343e301370aSEdmund Nadolski /* 344f1f52e75SDan Williams * This state indicates that the request has completed. 345e301370aSEdmund Nadolski * This state is entered from the STARTED state. This state is entered 346e301370aSEdmund Nadolski * from the ABORTING state. 347f1f52e75SDan Williams */ 348e301370aSEdmund Nadolski SCI_REQ_COMPLETED, 349f1f52e75SDan Williams 350e301370aSEdmund Nadolski /* 351f1f52e75SDan Williams * This state indicates that the request is in the process of being 352f1f52e75SDan Williams * terminated/aborted. 353f1f52e75SDan Williams * This state is entered from the CONSTRUCTED state. 354f1f52e75SDan Williams * This state is entered from the STARTED state. 355f1f52e75SDan Williams */ 356e301370aSEdmund Nadolski SCI_REQ_ABORTING, 357f1f52e75SDan Williams 358e301370aSEdmund Nadolski /* 359f1f52e75SDan Williams * Simply the final state for the base request state machine. 360f1f52e75SDan Williams */ 361e301370aSEdmund Nadolski SCI_REQ_FINAL, 362f1f52e75SDan Williams }; 363f1f52e75SDan Williams 364f1f52e75SDan Williams /** 365f1f52e75SDan Williams * scic_sds_request_get_controller() - 366f1f52e75SDan Williams * 367f1f52e75SDan Williams * This macro will return the controller for this io request object 368f1f52e75SDan Williams */ 369f1f52e75SDan Williams #define scic_sds_request_get_controller(sci_req) \ 370f1f52e75SDan Williams ((sci_req)->owning_controller) 371f1f52e75SDan Williams 372f1f52e75SDan Williams /** 373f1f52e75SDan Williams * scic_sds_request_get_device() - 374f1f52e75SDan Williams * 375f1f52e75SDan Williams * This macro will return the device for this io request object 376f1f52e75SDan Williams */ 377f1f52e75SDan Williams #define scic_sds_request_get_device(sci_req) \ 378f1f52e75SDan Williams ((sci_req)->target_device) 379f1f52e75SDan Williams 380f1f52e75SDan Williams /** 381f1f52e75SDan Williams * scic_sds_request_get_port() - 382f1f52e75SDan Williams * 383f1f52e75SDan Williams * This macro will return the port for this io request object 384f1f52e75SDan Williams */ 385f1f52e75SDan Williams #define scic_sds_request_get_port(sci_req) \ 386f1f52e75SDan Williams scic_sds_remote_device_get_port(scic_sds_request_get_device(sci_req)) 387f1f52e75SDan Williams 388f1f52e75SDan Williams /** 389f1f52e75SDan Williams * scic_sds_request_get_post_context() - 390f1f52e75SDan Williams * 391f1f52e75SDan Williams * This macro returns the constructed post context result for the io request. 392f1f52e75SDan Williams */ 393f1f52e75SDan Williams #define scic_sds_request_get_post_context(sci_req) \ 394f1f52e75SDan Williams ((sci_req)->post_context) 395f1f52e75SDan Williams 396f1f52e75SDan Williams /** 397f1f52e75SDan Williams * scic_sds_request_get_task_context() - 398f1f52e75SDan Williams * 399f1f52e75SDan Williams * This is a helper macro to return the os handle for this request object. 400f1f52e75SDan Williams */ 401f1f52e75SDan Williams #define scic_sds_request_get_task_context(request) \ 402f1f52e75SDan Williams ((request)->task_context_buffer) 403f1f52e75SDan Williams 404f1f52e75SDan Williams /** 405f1f52e75SDan Williams * scic_sds_request_set_status() - 406f1f52e75SDan Williams * 407f1f52e75SDan Williams * This macro will set the scu hardware status and sci request completion 408f1f52e75SDan Williams * status for an io request. 409f1f52e75SDan Williams */ 410f1f52e75SDan Williams #define scic_sds_request_set_status(request, scu_status_code, sci_status_code) \ 411f1f52e75SDan Williams { \ 412f1f52e75SDan Williams (request)->scu_status = (scu_status_code); \ 413f1f52e75SDan Williams (request)->sci_status = (sci_status_code); \ 414f1f52e75SDan Williams } 415f1f52e75SDan Williams 416f1f52e75SDan Williams enum sci_status scic_sds_request_start(struct scic_sds_request *sci_req); 417f1f52e75SDan Williams enum sci_status scic_sds_io_request_terminate(struct scic_sds_request *sci_req); 418e301370aSEdmund Nadolski enum sci_status 419e301370aSEdmund Nadolski scic_sds_io_request_event_handler(struct scic_sds_request *sci_req, 420f1f52e75SDan Williams u32 event_code); 421e301370aSEdmund Nadolski enum sci_status 422e301370aSEdmund Nadolski scic_sds_io_request_frame_handler(struct scic_sds_request *sci_req, 423f1f52e75SDan Williams u32 frame_index); 424e301370aSEdmund Nadolski enum sci_status 425e301370aSEdmund Nadolski scic_sds_task_request_terminate(struct scic_sds_request *sci_req); 426e301370aSEdmund Nadolski extern enum sci_status 427e301370aSEdmund Nadolski scic_sds_request_complete(struct scic_sds_request *sci_req); 428e301370aSEdmund Nadolski extern enum sci_status 429e301370aSEdmund Nadolski scic_sds_io_request_tc_completion(struct scic_sds_request *sci_req, u32 code); 430f1f52e75SDan Williams 431f1f52e75SDan Williams /* XXX open code in caller */ 432e301370aSEdmund Nadolski static inline dma_addr_t 433e301370aSEdmund Nadolski scic_io_request_get_dma_addr(struct scic_sds_request *sci_req, void *virt_addr) 434f1f52e75SDan Williams { 435f1f52e75SDan Williams struct isci_request *ireq = sci_req_to_ireq(sci_req); 436f1f52e75SDan Williams 437f1f52e75SDan Williams char *requested_addr = (char *)virt_addr; 438f1f52e75SDan Williams char *base_addr = (char *)ireq; 439f1f52e75SDan Williams 440f1f52e75SDan Williams BUG_ON(requested_addr < base_addr); 441f1f52e75SDan Williams BUG_ON((requested_addr - base_addr) >= sizeof(*ireq)); 442f1f52e75SDan Williams 443f1f52e75SDan Williams return ireq->request_daddr + (requested_addr - base_addr); 444f1f52e75SDan Williams } 445f1f52e75SDan Williams 446f1f52e75SDan Williams /** 4476f231ddaSDan Williams * This function gets the status of the request object. 4486f231ddaSDan Williams * @request: This parameter points to the isci_request object 4496f231ddaSDan Williams * 4506f231ddaSDan Williams * status of the object as a isci_request_status enum. 4516f231ddaSDan Williams */ 452e301370aSEdmund Nadolski static inline enum isci_request_status 453e301370aSEdmund Nadolski isci_request_get_state(struct isci_request *isci_request) 4546f231ddaSDan Williams { 4556f231ddaSDan Williams BUG_ON(isci_request == NULL); 4566f231ddaSDan Williams 4576f231ddaSDan Williams /*probably a bad sign... */ 4586f231ddaSDan Williams if (isci_request->status == unallocated) 4596f231ddaSDan Williams dev_warn(&isci_request->isci_host->pdev->dev, 4606f231ddaSDan Williams "%s: isci_request->status == unallocated\n", 4616f231ddaSDan Williams __func__); 4626f231ddaSDan Williams 4636f231ddaSDan Williams return isci_request->status; 4646f231ddaSDan Williams } 4656f231ddaSDan Williams 4666f231ddaSDan Williams 4676f231ddaSDan Williams /** 4686f231ddaSDan Williams * isci_request_change_state() - This function sets the status of the request 4696f231ddaSDan Williams * object. 4706f231ddaSDan Williams * @request: This parameter points to the isci_request object 4716f231ddaSDan Williams * @status: This Parameter is the new status of the object 4726f231ddaSDan Williams * 4736f231ddaSDan Williams */ 474e301370aSEdmund Nadolski static inline enum isci_request_status 475e301370aSEdmund Nadolski isci_request_change_state(struct isci_request *isci_request, 4766f231ddaSDan Williams enum isci_request_status status) 4776f231ddaSDan Williams { 4786f231ddaSDan Williams enum isci_request_status old_state; 4796f231ddaSDan Williams unsigned long flags; 4806f231ddaSDan Williams 4816f231ddaSDan Williams dev_dbg(&isci_request->isci_host->pdev->dev, 4826f231ddaSDan Williams "%s: isci_request = %p, state = 0x%x\n", 4836f231ddaSDan Williams __func__, 4846f231ddaSDan Williams isci_request, 4856f231ddaSDan Williams status); 4866f231ddaSDan Williams 4876f231ddaSDan Williams BUG_ON(isci_request == NULL); 4886f231ddaSDan Williams 4896f231ddaSDan Williams spin_lock_irqsave(&isci_request->state_lock, flags); 4906f231ddaSDan Williams old_state = isci_request->status; 4916f231ddaSDan Williams isci_request->status = status; 4926f231ddaSDan Williams spin_unlock_irqrestore(&isci_request->state_lock, flags); 4936f231ddaSDan Williams 4946f231ddaSDan Williams return old_state; 4956f231ddaSDan Williams } 4966f231ddaSDan Williams 4976f231ddaSDan Williams /** 4986f231ddaSDan Williams * isci_request_change_started_to_newstate() - This function sets the status of 4996f231ddaSDan Williams * the request object. 5006f231ddaSDan Williams * @request: This parameter points to the isci_request object 5016f231ddaSDan Williams * @status: This Parameter is the new status of the object 5026f231ddaSDan Williams * 5036f231ddaSDan Williams * state previous to any change. 5046f231ddaSDan Williams */ 505e301370aSEdmund Nadolski static inline enum isci_request_status 506e301370aSEdmund Nadolski isci_request_change_started_to_newstate(struct isci_request *isci_request, 5076f231ddaSDan Williams struct completion *completion_ptr, 5086f231ddaSDan Williams enum isci_request_status newstate) 5096f231ddaSDan Williams { 5106f231ddaSDan Williams enum isci_request_status old_state; 5116f231ddaSDan Williams unsigned long flags; 5126f231ddaSDan Williams 5136f231ddaSDan Williams spin_lock_irqsave(&isci_request->state_lock, flags); 5146f231ddaSDan Williams 5156f231ddaSDan Williams old_state = isci_request->status; 5166f231ddaSDan Williams 517f219f010SJeff Skirvin if (old_state == started || old_state == aborting) { 5186f231ddaSDan Williams BUG_ON(isci_request->io_request_completion != NULL); 5196f231ddaSDan Williams 5206f231ddaSDan Williams isci_request->io_request_completion = completion_ptr; 5216f231ddaSDan Williams isci_request->status = newstate; 5226f231ddaSDan Williams } 523e301370aSEdmund Nadolski 5246f231ddaSDan Williams spin_unlock_irqrestore(&isci_request->state_lock, flags); 5256f231ddaSDan Williams 5266f231ddaSDan Williams dev_dbg(&isci_request->isci_host->pdev->dev, 5276f231ddaSDan Williams "%s: isci_request = %p, old_state = 0x%x\n", 5286f231ddaSDan Williams __func__, 5296f231ddaSDan Williams isci_request, 5306f231ddaSDan Williams old_state); 5316f231ddaSDan Williams 5326f231ddaSDan Williams return old_state; 5336f231ddaSDan Williams } 5346f231ddaSDan Williams 5356f231ddaSDan Williams /** 5366f231ddaSDan Williams * isci_request_change_started_to_aborted() - This function sets the status of 5376f231ddaSDan Williams * the request object. 5386f231ddaSDan Williams * @request: This parameter points to the isci_request object 5396f231ddaSDan Williams * @completion_ptr: This parameter is saved as the kernel completion structure 5406f231ddaSDan Williams * signalled when the old request completes. 5416f231ddaSDan Williams * 5426f231ddaSDan Williams * state previous to any change. 5436f231ddaSDan Williams */ 544e301370aSEdmund Nadolski static inline enum isci_request_status 545e301370aSEdmund Nadolski isci_request_change_started_to_aborted(struct isci_request *isci_request, 5466f231ddaSDan Williams struct completion *completion_ptr) 5476f231ddaSDan Williams { 548e301370aSEdmund Nadolski return isci_request_change_started_to_newstate(isci_request, 549e301370aSEdmund Nadolski completion_ptr, 550e301370aSEdmund Nadolski aborted); 5516f231ddaSDan Williams } 5526f231ddaSDan Williams 553e301370aSEdmund Nadolski #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr) 5546f231ddaSDan Williams 555e301370aSEdmund Nadolski #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr) 5566f231ddaSDan Williams 557db056250SDan Williams struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost, 5586f231ddaSDan Williams struct isci_tmf *isci_tmf, 559db056250SDan Williams u16 tag); 560209fae14SDan Williams int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev, 561db056250SDan Williams struct sas_task *task, u16 tag); 562ddcc7e34SDan Williams void isci_terminate_pending_requests(struct isci_host *ihost, 563980d3aebSDan Williams struct isci_remote_device *idev); 564e301370aSEdmund Nadolski enum sci_status 565e301370aSEdmund Nadolski scic_task_request_construct(struct scic_sds_controller *scic, 566f1f52e75SDan Williams struct scic_sds_remote_device *sci_dev, 567f1f52e75SDan Williams u16 io_tag, 568f1f52e75SDan Williams struct scic_sds_request *sci_req); 569e301370aSEdmund Nadolski enum sci_status 570e301370aSEdmund Nadolski scic_task_request_construct_ssp(struct scic_sds_request *sci_req); 571e301370aSEdmund Nadolski enum sci_status 572e301370aSEdmund Nadolski scic_task_request_construct_sata(struct scic_sds_request *sci_req); 573e301370aSEdmund Nadolski void 574e301370aSEdmund Nadolski scic_stp_io_request_set_ncq_tag(struct scic_sds_request *sci_req, u16 ncq_tag); 575f1f52e75SDan Williams void scic_sds_smp_request_copy_response(struct scic_sds_request *sci_req); 5769274f45eSJeff Skirvin 5779274f45eSJeff Skirvin static inline int isci_task_is_ncq_recovery(struct sas_task *task) 5789274f45eSJeff Skirvin { 5799274f45eSJeff Skirvin return (sas_protocol_ata(task->task_proto) && 5809274f45eSJeff Skirvin task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT && 5819274f45eSJeff Skirvin task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ); 5829274f45eSJeff Skirvin 5839274f45eSJeff Skirvin } 5849274f45eSJeff Skirvin 5856f231ddaSDan Williams #endif /* !defined(_ISCI_REQUEST_H_) */ 586