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 925dec6f4eSDan Williams struct scic_sds_stp_request { 935dec6f4eSDan Williams union { 945dec6f4eSDan Williams u32 ncq; 955dec6f4eSDan Williams 965dec6f4eSDan Williams u32 udma; 975dec6f4eSDan Williams 985dec6f4eSDan Williams struct scic_sds_stp_pio_request { 99e301370aSEdmund Nadolski /* 100e301370aSEdmund Nadolski * Total transfer for the entire PIO request recorded 101e301370aSEdmund Nadolski * at request constuction time. 1025dec6f4eSDan Williams * 103e301370aSEdmund Nadolski * @todo Should we just decrement this value for each 104e301370aSEdmund Nadolski * byte of data transitted or received to elemenate 105e301370aSEdmund Nadolski * the current_transfer_bytes field? 1065dec6f4eSDan Williams */ 1075dec6f4eSDan Williams u32 total_transfer_bytes; 1085dec6f4eSDan Williams 109e301370aSEdmund Nadolski /* 110e301370aSEdmund Nadolski * Total number of bytes received/transmitted in data 111e301370aSEdmund Nadolski * frames since the start of the IO request. At the 112e301370aSEdmund Nadolski * end of the IO request this should equal the 1135dec6f4eSDan Williams * total_transfer_bytes. 1145dec6f4eSDan Williams */ 1155dec6f4eSDan Williams u32 current_transfer_bytes; 1165dec6f4eSDan Williams 117e301370aSEdmund Nadolski /* 118e301370aSEdmund Nadolski * The number of bytes requested in the in the PIO 119e301370aSEdmund Nadolski * setup. 1205dec6f4eSDan Williams */ 1215dec6f4eSDan Williams u32 pio_transfer_bytes; 1225dec6f4eSDan Williams 123e301370aSEdmund Nadolski /* 124e301370aSEdmund Nadolski * PIO Setup ending status value to tell us if we need 125e301370aSEdmund Nadolski * to wait for another FIS or if the transfer is 126e301370aSEdmund Nadolski * complete. On the receipt of a D2H FIS this will be 1275dec6f4eSDan Williams * the status field of that FIS. 1285dec6f4eSDan Williams */ 1295dec6f4eSDan Williams u8 ending_status; 1305dec6f4eSDan Williams 131e301370aSEdmund Nadolski /* 132e301370aSEdmund Nadolski * On receipt of a D2H FIS this will be the ending 133e301370aSEdmund Nadolski * error field if the ending_status has the 134e301370aSEdmund Nadolski * SATA_STATUS_ERR bit set. 1355dec6f4eSDan Williams */ 1365dec6f4eSDan Williams u8 ending_error; 1375dec6f4eSDan Williams 1385dec6f4eSDan Williams struct scic_sds_request_pio_sgl { 1395dec6f4eSDan Williams struct scu_sgl_element_pair *sgl_pair; 1405dec6f4eSDan Williams u8 sgl_set; 1415dec6f4eSDan Williams u32 sgl_offset; 1425dec6f4eSDan Williams } request_current; 1435dec6f4eSDan Williams } pio; 1445dec6f4eSDan Williams 1455dec6f4eSDan Williams struct { 146e301370aSEdmund Nadolski /* 147e301370aSEdmund Nadolski * The number of bytes requested in the PIO setup 148e301370aSEdmund Nadolski * before CDB data frame. 1495dec6f4eSDan Williams */ 1505dec6f4eSDan Williams u32 device_preferred_cdb_length; 1515dec6f4eSDan Williams } packet; 1525dec6f4eSDan Williams } type; 1535dec6f4eSDan Williams }; 1545dec6f4eSDan Williams 155f1f52e75SDan Williams struct scic_sds_request { 156e301370aSEdmund Nadolski /* 157e301370aSEdmund Nadolski * This field contains the information for the base request state 158e301370aSEdmund Nadolski * machine. 159f1f52e75SDan Williams */ 160e301370aSEdmund Nadolski struct sci_base_state_machine sm; 161f1f52e75SDan Williams 162e301370aSEdmund Nadolski /* 163f1f52e75SDan Williams * This field simply points to the controller to which this IO request 164f1f52e75SDan Williams * is associated. 165f1f52e75SDan Williams */ 166f1f52e75SDan Williams struct scic_sds_controller *owning_controller; 167f1f52e75SDan Williams 168e301370aSEdmund Nadolski /* 169e301370aSEdmund Nadolski * This field simply points to the remote device to which this IO 170e301370aSEdmund Nadolski * request is associated. 171f1f52e75SDan Williams */ 172f1f52e75SDan Williams struct scic_sds_remote_device *target_device; 173f1f52e75SDan Williams 174e301370aSEdmund Nadolski /* 175f1f52e75SDan Williams * This field is utilized to determine if the SCI user is managing 176f1f52e75SDan Williams * the IO tag for this request or if the core is managing it. 177f1f52e75SDan Williams */ 178f1f52e75SDan Williams bool was_tag_assigned_by_user; 179f1f52e75SDan Williams 180e301370aSEdmund Nadolski /* 181f1f52e75SDan Williams * This field indicates the IO tag for this request. The IO tag is 182f1f52e75SDan Williams * comprised of the task_index and a sequence count. The sequence count 183f1f52e75SDan Williams * is utilized to help identify tasks from one life to another. 184f1f52e75SDan Williams */ 185f1f52e75SDan Williams u16 io_tag; 186f1f52e75SDan Williams 187e301370aSEdmund Nadolski /* 188f1f52e75SDan Williams * This field specifies the protocol being utilized for this 189f1f52e75SDan Williams * IO request. 190f1f52e75SDan Williams */ 191f1f52e75SDan Williams enum sci_request_protocol protocol; 192f1f52e75SDan Williams 193e301370aSEdmund Nadolski /* 194f1f52e75SDan Williams * This field indicates the completion status taken from the SCUs 195e301370aSEdmund Nadolski * completion code. It indicates the completion result for the SCU 196e301370aSEdmund Nadolski * hardware. 197f1f52e75SDan Williams */ 198f1f52e75SDan Williams u32 scu_status; 199f1f52e75SDan Williams 200e301370aSEdmund Nadolski /* 201e301370aSEdmund Nadolski * This field indicates the completion status returned to the SCI user. 202e301370aSEdmund Nadolski * It indicates the users view of the io request completion. 203f1f52e75SDan Williams */ 204f1f52e75SDan Williams u32 sci_status; 205f1f52e75SDan Williams 206e301370aSEdmund Nadolski /* 207e301370aSEdmund Nadolski * This field contains the value to be utilized when posting 208e301370aSEdmund Nadolski * (e.g. Post_TC, * Post_TC_Abort) this request to the silicon. 209f1f52e75SDan Williams */ 210f1f52e75SDan Williams u32 post_context; 211f1f52e75SDan Williams 212f1f52e75SDan Williams struct scu_task_context *task_context_buffer; 213f1f52e75SDan Williams struct scu_task_context tc ____cacheline_aligned; 214f1f52e75SDan Williams 215f1f52e75SDan Williams /* could be larger with sg chaining */ 2167c78da31SDan Williams #define SCU_SGL_SIZE ((SCI_MAX_SCATTER_GATHER_ELEMENTS + 1) / 2) 217f1f52e75SDan Williams struct scu_sgl_element_pair sg_table[SCU_SGL_SIZE] __attribute__ ((aligned(32))); 218f1f52e75SDan Williams 219e301370aSEdmund Nadolski /* 220f1f52e75SDan Williams * This field indicates if this request is a task management request or 221f1f52e75SDan Williams * normal IO request. 222f1f52e75SDan Williams */ 223f1f52e75SDan Williams bool is_task_management_request; 224f1f52e75SDan Williams 225e301370aSEdmund Nadolski /* 226e301370aSEdmund Nadolski * This field is a pointer to the stored rx frame data. It is used in 227e301370aSEdmund Nadolski * STP internal requests and SMP response frames. If this field is 228e301370aSEdmund Nadolski * non-NULL the saved frame must be released on IO request completion. 229f1f52e75SDan Williams * 230f1f52e75SDan Williams * @todo In the future do we want to keep a list of RX frame buffers? 231f1f52e75SDan Williams */ 232f1f52e75SDan Williams u32 saved_rx_frame_index; 233f1f52e75SDan Williams 234f1f52e75SDan Williams union { 235f1f52e75SDan Williams struct { 236f1f52e75SDan Williams union { 237f1f52e75SDan Williams struct ssp_cmd_iu cmd; 238f1f52e75SDan Williams struct ssp_task_iu tmf; 239f1f52e75SDan Williams }; 240f1f52e75SDan Williams union { 241f1f52e75SDan Williams struct ssp_response_iu rsp; 242f1f52e75SDan Williams u8 rsp_buf[SSP_RESP_IU_MAX_SIZE]; 243f1f52e75SDan Williams }; 244f1f52e75SDan Williams } ssp; 245f1f52e75SDan Williams 246f1f52e75SDan Williams struct { 247f1f52e75SDan Williams struct smp_resp rsp; 248f1f52e75SDan Williams } smp; 249f1f52e75SDan Williams 250f1f52e75SDan Williams struct { 251f1f52e75SDan Williams struct scic_sds_stp_request req; 252f1f52e75SDan Williams struct host_to_dev_fis cmd; 253f1f52e75SDan Williams struct dev_to_host_fis rsp; 254f1f52e75SDan Williams } stp; 255f1f52e75SDan Williams }; 256f1f52e75SDan Williams }; 257f1f52e75SDan Williams 258f1f52e75SDan Williams static inline struct scic_sds_request *to_sci_req(struct scic_sds_stp_request *stp_req) 259f1f52e75SDan Williams { 260f1f52e75SDan Williams struct scic_sds_request *sci_req; 261f1f52e75SDan Williams 262f1f52e75SDan Williams sci_req = container_of(stp_req, typeof(*sci_req), stp.req); 263f1f52e75SDan Williams return sci_req; 264f1f52e75SDan Williams } 265f1f52e75SDan Williams 2666f231ddaSDan Williams struct isci_request { 2676f231ddaSDan Williams enum isci_request_status status; 2686f231ddaSDan Williams enum task_type ttype; 2696f231ddaSDan Williams unsigned short io_tag; 2706f231ddaSDan Williams bool complete_in_target; 27167ea838dSDan Williams bool terminated; 2726f231ddaSDan Williams 2736f231ddaSDan Williams union ttype_ptr_union { 2746f231ddaSDan Williams struct sas_task *io_task_ptr; /* When ttype==io_task */ 2756f231ddaSDan Williams struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */ 2766f231ddaSDan Williams } ttype_ptr; 2776f231ddaSDan Williams struct isci_host *isci_host; 2786f231ddaSDan Williams /* For use in the requests_to_{complete|abort} lists: */ 2796f231ddaSDan Williams struct list_head completed_node; 2806f231ddaSDan Williams /* For use in the reqs_in_process list: */ 2816f231ddaSDan Williams struct list_head dev_node; 2826f231ddaSDan Williams spinlock_t state_lock; 2836f231ddaSDan Williams dma_addr_t request_daddr; 2846f231ddaSDan Williams dma_addr_t zero_scatter_daddr; 2856f231ddaSDan Williams 2866f231ddaSDan Williams unsigned int num_sg_entries; /* returned by pci_alloc_sg */ 2876f231ddaSDan Williams 2886f231ddaSDan Williams /** Note: "io_request_completion" is completed in two different ways 2896f231ddaSDan Williams * depending on whether this is a TMF or regular request. 2906f231ddaSDan Williams * - TMF requests are completed in the thread that started them; 2916f231ddaSDan Williams * - regular requests are completed in the request completion callback 2926f231ddaSDan Williams * function. 2936f231ddaSDan Williams * This difference in operation allows the aborter of a TMF request 2946f231ddaSDan Williams * to be sure that once the TMF request completes, the I/O that the 2956f231ddaSDan Williams * TMF was aborting is guaranteed to have completed. 2966f231ddaSDan Williams */ 2976f231ddaSDan Williams struct completion *io_request_completion; 29867ea838dSDan Williams struct scic_sds_request sci; 2996f231ddaSDan Williams }; 3006f231ddaSDan Williams 30167ea838dSDan Williams static inline struct isci_request *sci_req_to_ireq(struct scic_sds_request *sci_req) 30267ea838dSDan Williams { 30367ea838dSDan Williams struct isci_request *ireq = container_of(sci_req, typeof(*ireq), sci); 30467ea838dSDan Williams 30567ea838dSDan Williams return ireq; 30667ea838dSDan Williams } 30767ea838dSDan Williams 3086f231ddaSDan Williams /** 309f1f52e75SDan Williams * enum sci_base_request_states - This enumeration depicts all the states for 310f1f52e75SDan Williams * the common request state machine. 311f1f52e75SDan Williams * 312f1f52e75SDan Williams * 313f1f52e75SDan Williams */ 314f1f52e75SDan Williams enum sci_base_request_states { 315e301370aSEdmund Nadolski /* 316f1f52e75SDan Williams * Simply the initial state for the base request state machine. 317f1f52e75SDan Williams */ 318e301370aSEdmund Nadolski SCI_REQ_INIT, 319f1f52e75SDan Williams 320e301370aSEdmund Nadolski /* 321e301370aSEdmund Nadolski * This state indicates that the request has been constructed. 322e301370aSEdmund Nadolski * This state is entered from the INITIAL state. 323f1f52e75SDan Williams */ 324e301370aSEdmund Nadolski SCI_REQ_CONSTRUCTED, 325f1f52e75SDan Williams 326e301370aSEdmund Nadolski /* 327e301370aSEdmund Nadolski * This state indicates that the request has been started. This state 328e301370aSEdmund Nadolski * is entered from the CONSTRUCTED state. 329f1f52e75SDan Williams */ 330e301370aSEdmund Nadolski SCI_REQ_STARTED, 331f1f52e75SDan Williams 332e301370aSEdmund Nadolski SCI_REQ_STP_UDMA_WAIT_TC_COMP, 333e301370aSEdmund Nadolski SCI_REQ_STP_UDMA_WAIT_D2H, 3345dec6f4eSDan Williams 335e301370aSEdmund Nadolski SCI_REQ_STP_NON_DATA_WAIT_H2D, 336e301370aSEdmund Nadolski SCI_REQ_STP_NON_DATA_WAIT_D2H, 3375dec6f4eSDan Williams 338e301370aSEdmund Nadolski SCI_REQ_STP_SOFT_RESET_WAIT_H2D_ASSERTED, 339e301370aSEdmund Nadolski SCI_REQ_STP_SOFT_RESET_WAIT_H2D_DIAG, 340e301370aSEdmund Nadolski SCI_REQ_STP_SOFT_RESET_WAIT_D2H, 3415dec6f4eSDan Williams 342e301370aSEdmund Nadolski /* 343e301370aSEdmund Nadolski * While in this state the IO request object is waiting for the TC 344e301370aSEdmund Nadolski * completion notification for the H2D Register FIS 3455dec6f4eSDan Williams */ 346e301370aSEdmund Nadolski SCI_REQ_STP_PIO_WAIT_H2D, 3475dec6f4eSDan Williams 348e301370aSEdmund Nadolski /* 349e301370aSEdmund Nadolski * While in this state the IO request object is waiting for either a 350e301370aSEdmund Nadolski * PIO Setup FIS or a D2H register FIS. The type of frame received is 351e301370aSEdmund Nadolski * based on the result of the prior frame and line conditions. 3525dec6f4eSDan Williams */ 353e301370aSEdmund Nadolski SCI_REQ_STP_PIO_WAIT_FRAME, 3545dec6f4eSDan Williams 355e301370aSEdmund Nadolski /* 356e301370aSEdmund Nadolski * While in this state the IO request object is waiting for a DATA 357e301370aSEdmund Nadolski * frame from the device. 3585dec6f4eSDan Williams */ 359e301370aSEdmund Nadolski SCI_REQ_STP_PIO_DATA_IN, 3605dec6f4eSDan Williams 361e301370aSEdmund Nadolski /* 362e301370aSEdmund Nadolski * While in this state the IO request object is waiting to transmit 363e301370aSEdmund Nadolski * the next data frame to the device. 3645dec6f4eSDan Williams */ 365e301370aSEdmund Nadolski SCI_REQ_STP_PIO_DATA_OUT, 3665dec6f4eSDan Williams 367e301370aSEdmund Nadolski /* 368f139303dSDan Williams * The AWAIT_TC_COMPLETION sub-state indicates that the started raw 369f139303dSDan Williams * task management request is waiting for the transmission of the 370f139303dSDan Williams * initial frame (i.e. command, task, etc.). 371f139303dSDan Williams */ 372e301370aSEdmund Nadolski SCI_REQ_TASK_WAIT_TC_COMP, 373f139303dSDan Williams 374e301370aSEdmund Nadolski /* 375f139303dSDan Williams * This sub-state indicates that the started task management request 376f139303dSDan Williams * is waiting for the reception of an unsolicited frame 377f139303dSDan Williams * (i.e. response IU). 378f139303dSDan Williams */ 379e301370aSEdmund Nadolski SCI_REQ_TASK_WAIT_TC_RESP, 380f139303dSDan Williams 381e301370aSEdmund Nadolski /* 382c72086e3SDan Williams * This sub-state indicates that the started task management request 383c72086e3SDan Williams * is waiting for the reception of an unsolicited frame 384c72086e3SDan Williams * (i.e. response IU). 385c72086e3SDan Williams */ 386e301370aSEdmund Nadolski SCI_REQ_SMP_WAIT_RESP, 387c72086e3SDan Williams 388e301370aSEdmund Nadolski /* 389e301370aSEdmund Nadolski * The AWAIT_TC_COMPLETION sub-state indicates that the started SMP 390e301370aSEdmund Nadolski * request is waiting for the transmission of the initial frame 391e301370aSEdmund Nadolski * (i.e. command, task, etc.). 392c72086e3SDan Williams */ 393e301370aSEdmund Nadolski SCI_REQ_SMP_WAIT_TC_COMP, 394c72086e3SDan Williams 395e301370aSEdmund Nadolski /* 396f1f52e75SDan Williams * This state indicates that the request has completed. 397e301370aSEdmund Nadolski * This state is entered from the STARTED state. This state is entered 398e301370aSEdmund Nadolski * from the ABORTING state. 399f1f52e75SDan Williams */ 400e301370aSEdmund Nadolski SCI_REQ_COMPLETED, 401f1f52e75SDan Williams 402e301370aSEdmund Nadolski /* 403f1f52e75SDan Williams * This state indicates that the request is in the process of being 404f1f52e75SDan Williams * terminated/aborted. 405f1f52e75SDan Williams * This state is entered from the CONSTRUCTED state. 406f1f52e75SDan Williams * This state is entered from the STARTED state. 407f1f52e75SDan Williams */ 408e301370aSEdmund Nadolski SCI_REQ_ABORTING, 409f1f52e75SDan Williams 410e301370aSEdmund Nadolski /* 411f1f52e75SDan Williams * Simply the final state for the base request state machine. 412f1f52e75SDan Williams */ 413e301370aSEdmund Nadolski SCI_REQ_FINAL, 414f1f52e75SDan Williams }; 415f1f52e75SDan Williams 416f1f52e75SDan Williams /** 417f1f52e75SDan Williams * scic_sds_request_get_controller() - 418f1f52e75SDan Williams * 419f1f52e75SDan Williams * This macro will return the controller for this io request object 420f1f52e75SDan Williams */ 421f1f52e75SDan Williams #define scic_sds_request_get_controller(sci_req) \ 422f1f52e75SDan Williams ((sci_req)->owning_controller) 423f1f52e75SDan Williams 424f1f52e75SDan Williams /** 425f1f52e75SDan Williams * scic_sds_request_get_device() - 426f1f52e75SDan Williams * 427f1f52e75SDan Williams * This macro will return the device for this io request object 428f1f52e75SDan Williams */ 429f1f52e75SDan Williams #define scic_sds_request_get_device(sci_req) \ 430f1f52e75SDan Williams ((sci_req)->target_device) 431f1f52e75SDan Williams 432f1f52e75SDan Williams /** 433f1f52e75SDan Williams * scic_sds_request_get_port() - 434f1f52e75SDan Williams * 435f1f52e75SDan Williams * This macro will return the port for this io request object 436f1f52e75SDan Williams */ 437f1f52e75SDan Williams #define scic_sds_request_get_port(sci_req) \ 438f1f52e75SDan Williams scic_sds_remote_device_get_port(scic_sds_request_get_device(sci_req)) 439f1f52e75SDan Williams 440f1f52e75SDan Williams /** 441f1f52e75SDan Williams * scic_sds_request_get_post_context() - 442f1f52e75SDan Williams * 443f1f52e75SDan Williams * This macro returns the constructed post context result for the io request. 444f1f52e75SDan Williams */ 445f1f52e75SDan Williams #define scic_sds_request_get_post_context(sci_req) \ 446f1f52e75SDan Williams ((sci_req)->post_context) 447f1f52e75SDan Williams 448f1f52e75SDan Williams /** 449f1f52e75SDan Williams * scic_sds_request_get_task_context() - 450f1f52e75SDan Williams * 451f1f52e75SDan Williams * This is a helper macro to return the os handle for this request object. 452f1f52e75SDan Williams */ 453f1f52e75SDan Williams #define scic_sds_request_get_task_context(request) \ 454f1f52e75SDan Williams ((request)->task_context_buffer) 455f1f52e75SDan Williams 456f1f52e75SDan Williams /** 457f1f52e75SDan Williams * scic_sds_request_set_status() - 458f1f52e75SDan Williams * 459f1f52e75SDan Williams * This macro will set the scu hardware status and sci request completion 460f1f52e75SDan Williams * status for an io request. 461f1f52e75SDan Williams */ 462f1f52e75SDan Williams #define scic_sds_request_set_status(request, scu_status_code, sci_status_code) \ 463f1f52e75SDan Williams { \ 464f1f52e75SDan Williams (request)->scu_status = (scu_status_code); \ 465f1f52e75SDan Williams (request)->sci_status = (sci_status_code); \ 466f1f52e75SDan Williams } 467f1f52e75SDan Williams 468f1f52e75SDan Williams /** 469f1f52e75SDan Williams * SCU_SGL_ZERO() - 470f1f52e75SDan Williams * 471f1f52e75SDan Williams * This macro zeros the hardware SGL element data 472f1f52e75SDan Williams */ 473f1f52e75SDan Williams #define SCU_SGL_ZERO(scu_sge) \ 474f1f52e75SDan Williams { \ 475f1f52e75SDan Williams (scu_sge).length = 0; \ 476f1f52e75SDan Williams (scu_sge).address_lower = 0; \ 477f1f52e75SDan Williams (scu_sge).address_upper = 0; \ 478f1f52e75SDan Williams (scu_sge).address_modifier = 0; \ 479f1f52e75SDan Williams } 480f1f52e75SDan Williams 481f1f52e75SDan Williams /** 482f1f52e75SDan Williams * SCU_SGL_COPY() - 483f1f52e75SDan Williams * 484f1f52e75SDan Williams * This macro copys the SGL Element data from the host os to the hardware SGL 485f1f52e75SDan Williams * elment data 486f1f52e75SDan Williams */ 487f1f52e75SDan Williams #define SCU_SGL_COPY(scu_sge, os_sge) \ 488f1f52e75SDan Williams { \ 489f1f52e75SDan Williams (scu_sge).length = sg_dma_len(sg); \ 490f1f52e75SDan Williams (scu_sge).address_upper = \ 491f1f52e75SDan Williams upper_32_bits(sg_dma_address(sg)); \ 492f1f52e75SDan Williams (scu_sge).address_lower = \ 493f1f52e75SDan Williams lower_32_bits(sg_dma_address(sg)); \ 494f1f52e75SDan Williams (scu_sge).address_modifier = 0; \ 495f1f52e75SDan Williams } 496f1f52e75SDan Williams 497f1f52e75SDan Williams enum sci_status scic_sds_request_start(struct scic_sds_request *sci_req); 498f1f52e75SDan Williams enum sci_status scic_sds_io_request_terminate(struct scic_sds_request *sci_req); 499e301370aSEdmund Nadolski enum sci_status 500e301370aSEdmund Nadolski scic_sds_io_request_event_handler(struct scic_sds_request *sci_req, 501f1f52e75SDan Williams u32 event_code); 502e301370aSEdmund Nadolski enum sci_status 503e301370aSEdmund Nadolski scic_sds_io_request_frame_handler(struct scic_sds_request *sci_req, 504f1f52e75SDan Williams u32 frame_index); 505e301370aSEdmund Nadolski enum sci_status 506e301370aSEdmund Nadolski scic_sds_task_request_terminate(struct scic_sds_request *sci_req); 507e301370aSEdmund Nadolski extern enum sci_status 508e301370aSEdmund Nadolski scic_sds_request_complete(struct scic_sds_request *sci_req); 509e301370aSEdmund Nadolski extern enum sci_status 510e301370aSEdmund Nadolski scic_sds_io_request_tc_completion(struct scic_sds_request *sci_req, u32 code); 511f1f52e75SDan Williams 512f1f52e75SDan Williams /* XXX open code in caller */ 513f1f52e75SDan Williams static inline void *scic_request_get_virt_addr(struct scic_sds_request *sci_req, 514f1f52e75SDan Williams dma_addr_t phys_addr) 515f1f52e75SDan Williams { 516f1f52e75SDan Williams struct isci_request *ireq = sci_req_to_ireq(sci_req); 517f1f52e75SDan Williams dma_addr_t offset; 518f1f52e75SDan Williams 519f1f52e75SDan Williams BUG_ON(phys_addr < ireq->request_daddr); 520f1f52e75SDan Williams 521f1f52e75SDan Williams offset = phys_addr - ireq->request_daddr; 522f1f52e75SDan Williams 523f1f52e75SDan Williams BUG_ON(offset >= sizeof(*ireq)); 524f1f52e75SDan Williams 525f1f52e75SDan Williams return (char *)ireq + offset; 526f1f52e75SDan Williams } 527f1f52e75SDan Williams 528f1f52e75SDan Williams /* XXX open code in caller */ 529e301370aSEdmund Nadolski static inline dma_addr_t 530e301370aSEdmund Nadolski scic_io_request_get_dma_addr(struct scic_sds_request *sci_req, void *virt_addr) 531f1f52e75SDan Williams { 532f1f52e75SDan Williams struct isci_request *ireq = sci_req_to_ireq(sci_req); 533f1f52e75SDan Williams 534f1f52e75SDan Williams char *requested_addr = (char *)virt_addr; 535f1f52e75SDan Williams char *base_addr = (char *)ireq; 536f1f52e75SDan Williams 537f1f52e75SDan Williams BUG_ON(requested_addr < base_addr); 538f1f52e75SDan Williams BUG_ON((requested_addr - base_addr) >= sizeof(*ireq)); 539f1f52e75SDan Williams 540f1f52e75SDan Williams return ireq->request_daddr + (requested_addr - base_addr); 541f1f52e75SDan Williams } 542f1f52e75SDan Williams 543f1f52e75SDan Williams /** 5446f231ddaSDan Williams * This function gets the status of the request object. 5456f231ddaSDan Williams * @request: This parameter points to the isci_request object 5466f231ddaSDan Williams * 5476f231ddaSDan Williams * status of the object as a isci_request_status enum. 5486f231ddaSDan Williams */ 549e301370aSEdmund Nadolski static inline enum isci_request_status 550e301370aSEdmund Nadolski isci_request_get_state(struct isci_request *isci_request) 5516f231ddaSDan Williams { 5526f231ddaSDan Williams BUG_ON(isci_request == NULL); 5536f231ddaSDan Williams 5546f231ddaSDan Williams /*probably a bad sign... */ 5556f231ddaSDan Williams if (isci_request->status == unallocated) 5566f231ddaSDan Williams dev_warn(&isci_request->isci_host->pdev->dev, 5576f231ddaSDan Williams "%s: isci_request->status == unallocated\n", 5586f231ddaSDan Williams __func__); 5596f231ddaSDan Williams 5606f231ddaSDan Williams return isci_request->status; 5616f231ddaSDan Williams } 5626f231ddaSDan Williams 5636f231ddaSDan Williams 5646f231ddaSDan Williams /** 5656f231ddaSDan Williams * isci_request_change_state() - This function sets the status of the request 5666f231ddaSDan Williams * object. 5676f231ddaSDan Williams * @request: This parameter points to the isci_request object 5686f231ddaSDan Williams * @status: This Parameter is the new status of the object 5696f231ddaSDan Williams * 5706f231ddaSDan Williams */ 571e301370aSEdmund Nadolski static inline enum isci_request_status 572e301370aSEdmund Nadolski isci_request_change_state(struct isci_request *isci_request, 5736f231ddaSDan Williams enum isci_request_status status) 5746f231ddaSDan Williams { 5756f231ddaSDan Williams enum isci_request_status old_state; 5766f231ddaSDan Williams unsigned long flags; 5776f231ddaSDan Williams 5786f231ddaSDan Williams dev_dbg(&isci_request->isci_host->pdev->dev, 5796f231ddaSDan Williams "%s: isci_request = %p, state = 0x%x\n", 5806f231ddaSDan Williams __func__, 5816f231ddaSDan Williams isci_request, 5826f231ddaSDan Williams status); 5836f231ddaSDan Williams 5846f231ddaSDan Williams BUG_ON(isci_request == NULL); 5856f231ddaSDan Williams 5866f231ddaSDan Williams spin_lock_irqsave(&isci_request->state_lock, flags); 5876f231ddaSDan Williams old_state = isci_request->status; 5886f231ddaSDan Williams isci_request->status = status; 5896f231ddaSDan Williams spin_unlock_irqrestore(&isci_request->state_lock, flags); 5906f231ddaSDan Williams 5916f231ddaSDan Williams return old_state; 5926f231ddaSDan Williams } 5936f231ddaSDan Williams 5946f231ddaSDan Williams /** 5956f231ddaSDan Williams * isci_request_change_started_to_newstate() - This function sets the status of 5966f231ddaSDan Williams * the request object. 5976f231ddaSDan Williams * @request: This parameter points to the isci_request object 5986f231ddaSDan Williams * @status: This Parameter is the new status of the object 5996f231ddaSDan Williams * 6006f231ddaSDan Williams * state previous to any change. 6016f231ddaSDan Williams */ 602e301370aSEdmund Nadolski static inline enum isci_request_status 603e301370aSEdmund Nadolski isci_request_change_started_to_newstate(struct isci_request *isci_request, 6046f231ddaSDan Williams struct completion *completion_ptr, 6056f231ddaSDan Williams enum isci_request_status newstate) 6066f231ddaSDan Williams { 6076f231ddaSDan Williams enum isci_request_status old_state; 6086f231ddaSDan Williams unsigned long flags; 6096f231ddaSDan Williams 6106f231ddaSDan Williams spin_lock_irqsave(&isci_request->state_lock, flags); 6116f231ddaSDan Williams 6126f231ddaSDan Williams old_state = isci_request->status; 6136f231ddaSDan Williams 614f219f010SJeff Skirvin if (old_state == started || old_state == aborting) { 6156f231ddaSDan Williams BUG_ON(isci_request->io_request_completion != NULL); 6166f231ddaSDan Williams 6176f231ddaSDan Williams isci_request->io_request_completion = completion_ptr; 6186f231ddaSDan Williams isci_request->status = newstate; 6196f231ddaSDan Williams } 620e301370aSEdmund Nadolski 6216f231ddaSDan Williams spin_unlock_irqrestore(&isci_request->state_lock, flags); 6226f231ddaSDan Williams 6236f231ddaSDan Williams dev_dbg(&isci_request->isci_host->pdev->dev, 6246f231ddaSDan Williams "%s: isci_request = %p, old_state = 0x%x\n", 6256f231ddaSDan Williams __func__, 6266f231ddaSDan Williams isci_request, 6276f231ddaSDan Williams old_state); 6286f231ddaSDan Williams 6296f231ddaSDan Williams return old_state; 6306f231ddaSDan Williams } 6316f231ddaSDan Williams 6326f231ddaSDan Williams /** 6336f231ddaSDan Williams * isci_request_change_started_to_aborted() - This function sets the status of 6346f231ddaSDan Williams * the request object. 6356f231ddaSDan Williams * @request: This parameter points to the isci_request object 6366f231ddaSDan Williams * @completion_ptr: This parameter is saved as the kernel completion structure 6376f231ddaSDan Williams * signalled when the old request completes. 6386f231ddaSDan Williams * 6396f231ddaSDan Williams * state previous to any change. 6406f231ddaSDan Williams */ 641e301370aSEdmund Nadolski static inline enum isci_request_status 642e301370aSEdmund Nadolski isci_request_change_started_to_aborted(struct isci_request *isci_request, 6436f231ddaSDan Williams struct completion *completion_ptr) 6446f231ddaSDan Williams { 645e301370aSEdmund Nadolski return isci_request_change_started_to_newstate(isci_request, 646e301370aSEdmund Nadolski completion_ptr, 647e301370aSEdmund Nadolski aborted); 6486f231ddaSDan Williams } 6496f231ddaSDan Williams /** 6506f231ddaSDan Williams * isci_request_free() - This function frees the request object. 6516f231ddaSDan Williams * @isci_host: This parameter specifies the ISCI host object 6526f231ddaSDan Williams * @isci_request: This parameter points to the isci_request object 6536f231ddaSDan Williams * 6546f231ddaSDan Williams */ 655e301370aSEdmund Nadolski static inline void isci_request_free(struct isci_host *isci_host, 6566f231ddaSDan Williams struct isci_request *isci_request) 6576f231ddaSDan Williams { 6586cb4d6b3SBartosz Barcinski if (!isci_request) 6596cb4d6b3SBartosz Barcinski return; 6606f231ddaSDan Williams 6616f231ddaSDan Williams /* release the dma memory if we fail. */ 662e301370aSEdmund Nadolski dma_pool_free(isci_host->dma_pool, 663e301370aSEdmund Nadolski isci_request, 6646f231ddaSDan Williams isci_request->request_daddr); 6656f231ddaSDan Williams } 6666f231ddaSDan Williams 667e301370aSEdmund Nadolski #define isci_request_access_task(req) ((req)->ttype_ptr.io_task_ptr) 6686f231ddaSDan Williams 669e301370aSEdmund Nadolski #define isci_request_access_tmf(req) ((req)->ttype_ptr.tmf_task_ptr) 6706f231ddaSDan Williams 6710d0cf14cSDan Williams struct isci_request *isci_request_alloc_tmf(struct isci_host *ihost, 6726f231ddaSDan Williams struct isci_tmf *isci_tmf, 6736f231ddaSDan Williams gfp_t gfp_flags); 674209fae14SDan Williams int isci_request_execute(struct isci_host *ihost, struct isci_remote_device *idev, 675209fae14SDan Williams struct sas_task *task, gfp_t gfp_flags); 676ddcc7e34SDan Williams void isci_terminate_pending_requests(struct isci_host *ihost, 677980d3aebSDan Williams struct isci_remote_device *idev); 678e301370aSEdmund Nadolski enum sci_status 679e301370aSEdmund Nadolski scic_task_request_construct(struct scic_sds_controller *scic, 680f1f52e75SDan Williams struct scic_sds_remote_device *sci_dev, 681f1f52e75SDan Williams u16 io_tag, 682f1f52e75SDan Williams struct scic_sds_request *sci_req); 683e301370aSEdmund Nadolski enum sci_status 684e301370aSEdmund Nadolski scic_task_request_construct_ssp(struct scic_sds_request *sci_req); 685e301370aSEdmund Nadolski enum sci_status 686e301370aSEdmund Nadolski scic_task_request_construct_sata(struct scic_sds_request *sci_req); 687e301370aSEdmund Nadolski void 688e301370aSEdmund Nadolski scic_stp_io_request_set_ncq_tag(struct scic_sds_request *sci_req, u16 ncq_tag); 689f1f52e75SDan Williams void scic_sds_smp_request_copy_response(struct scic_sds_request *sci_req); 690*9274f45eSJeff Skirvin 691*9274f45eSJeff Skirvin static inline int isci_task_is_ncq_recovery(struct sas_task *task) 692*9274f45eSJeff Skirvin { 693*9274f45eSJeff Skirvin return (sas_protocol_ata(task->task_proto) && 694*9274f45eSJeff Skirvin task->ata_task.fis.command == ATA_CMD_READ_LOG_EXT && 695*9274f45eSJeff Skirvin task->ata_task.fis.lbal == ATA_LOG_SATA_NCQ); 696*9274f45eSJeff Skirvin 697*9274f45eSJeff Skirvin } 698*9274f45eSJeff Skirvin 6996f231ddaSDan Williams #endif /* !defined(_ISCI_REQUEST_H_) */ 700