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 | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 56 | #ifndef _ISCI_REMOTE_DEVICE_H_ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 57 | #define _ISCI_REMOTE_DEVICE_H_ |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 58 | #include <scsi/libsas.h> |
| 59 | #include "sci_status.h" |
| 60 | #include "intel_sas.h" |
| 61 | #include "scu_remote_node_context.h" |
| 62 | #include "remote_node_context.h" |
| 63 | #include "port.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 64 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 65 | enum scic_remote_device_not_ready_reason_code { |
| 66 | SCIC_REMOTE_DEVICE_NOT_READY_START_REQUESTED, |
| 67 | SCIC_REMOTE_DEVICE_NOT_READY_STOP_REQUESTED, |
| 68 | SCIC_REMOTE_DEVICE_NOT_READY_SATA_REQUEST_STARTED, |
| 69 | SCIC_REMOTE_DEVICE_NOT_READY_SATA_SDB_ERROR_FIS_RECEIVED, |
| 70 | SCIC_REMOTE_DEVICE_NOT_READY_SMP_REQUEST_STARTED, |
| 71 | |
| 72 | SCIC_REMOTE_DEVICE_NOT_READY_REASON_CODE_MAX |
| 73 | |
| 74 | }; |
| 75 | |
| 76 | struct scic_sds_remote_device { |
| 77 | /** |
| 78 | * The field specifies that the parent object for the base remote |
| 79 | * device is the base object itself. |
| 80 | */ |
| 81 | struct sci_base_object parent; |
| 82 | |
| 83 | /** |
| 84 | * This field contains the information for the base remote device state |
| 85 | * machine. |
| 86 | */ |
| 87 | struct sci_base_state_machine state_machine; |
| 88 | |
| 89 | /** |
| 90 | * This field is the programmed device port width. This value is |
| 91 | * written to the RCN data structure to tell the SCU how many open |
| 92 | * connections this device can have. |
| 93 | */ |
| 94 | u32 device_port_width; |
| 95 | |
| 96 | /** |
| 97 | * This field is the programmed connection rate for this remote device. It is |
| 98 | * used to program the TC with the maximum allowed connection rate. |
| 99 | */ |
| 100 | enum sas_linkrate connection_rate; |
| 101 | |
| 102 | /** |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 103 | * This field contains the device SAS address. |
| 104 | */ |
| 105 | struct sci_sas_address device_address; |
| 106 | |
| 107 | /** |
| 108 | * This filed is assinged the value of true if the device is directly |
| 109 | * attached to the port. |
| 110 | */ |
| 111 | bool is_direct_attached; |
| 112 | |
| 113 | #if !defined(DISABLE_ATAPI) |
| 114 | /** |
| 115 | * This filed is assinged the value of true if the device is an ATAPI |
| 116 | * device. |
| 117 | */ |
| 118 | bool is_atapi; |
| 119 | #endif |
| 120 | |
| 121 | /** |
| 122 | * This filed contains a pointer back to the port to which this device |
| 123 | * is assigned. |
| 124 | */ |
| 125 | struct scic_sds_port *owning_port; |
| 126 | |
| 127 | /** |
| 128 | * This field contains the SCU silicon remote node context specific |
| 129 | * information. |
| 130 | */ |
| 131 | struct scic_sds_remote_node_context rnc; |
| 132 | |
| 133 | /** |
| 134 | * This field contains the stated request count for the remote device. The |
| 135 | * device can not reach the SCI_BASE_REMOTE_DEVICE_STATE_STOPPED until all |
| 136 | * requests are complete and the rnc_posted value is false. |
| 137 | */ |
| 138 | u32 started_request_count; |
| 139 | |
| 140 | /** |
| 141 | * This field contains a pointer to the working request object. It is only |
| 142 | * used only for SATA requests since the unsolicited frames we get from the |
| 143 | * hardware have no Tag value to look up the io request object. |
| 144 | */ |
| 145 | struct scic_sds_request *working_request; |
| 146 | |
| 147 | /** |
| 148 | * This field contains the reason for the remote device going not_ready. It is |
| 149 | * assigned in the state handlers and used in the state transition. |
| 150 | */ |
| 151 | u32 not_ready_reason; |
| 152 | |
| 153 | /** |
| 154 | * This field is true if this remote device has an initialzied ready substate |
| 155 | * machine. SSP devices do not have a ready substate machine and STP devices |
| 156 | * have a ready substate machine. |
| 157 | */ |
| 158 | bool has_ready_substate_machine; |
| 159 | |
| 160 | /** |
| 161 | * This field contains the state machine for the ready substate machine for |
| 162 | * this struct scic_sds_remote_device object. |
| 163 | */ |
| 164 | struct sci_base_state_machine ready_substate_machine; |
| 165 | |
| 166 | /** |
| 167 | * This field maintains the set of state handlers for the remote device |
| 168 | * object. These are changed each time the remote device enters a new state. |
| 169 | */ |
| 170 | const struct scic_sds_remote_device_state_handler *state_handlers; |
| 171 | }; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 172 | |
| 173 | struct isci_remote_device { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 174 | enum isci_status status; |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 175 | #define IDEV_START_PENDING 0 |
| 176 | #define IDEV_STOP_PENDING 1 |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 177 | #define IDEV_ALLOCATED 2 |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 178 | unsigned long flags; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 179 | struct isci_port *isci_port; |
| 180 | struct domain_device *domain_dev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 181 | struct list_head node; |
| 182 | struct list_head reqs_in_process; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 183 | spinlock_t state_lock; |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 184 | struct scic_sds_remote_device sci; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 187 | #define ISCI_REMOTE_DEVICE_START_TIMEOUT 5000 |
| 188 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 189 | enum sci_status isci_remote_device_stop(struct isci_host *ihost, |
| 190 | struct isci_remote_device *idev); |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 191 | void isci_remote_device_nuke_requests(struct isci_host *ihost, |
| 192 | struct isci_remote_device *idev); |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 193 | void isci_remote_device_ready(struct isci_host *ihost, |
| 194 | struct isci_remote_device *idev); |
Dan Williams | 037afc7 | 2011-03-31 13:10:42 -0700 | [diff] [blame] | 195 | void isci_remote_device_not_ready(struct isci_host *ihost, |
| 196 | struct isci_remote_device *idev, u32 reason); |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 197 | void isci_remote_device_gone(struct domain_device *domain_dev); |
| 198 | int isci_remote_device_found(struct domain_device *domain_dev); |
| 199 | bool isci_device_is_reset_pending(struct isci_host *ihost, |
| 200 | struct isci_remote_device *idev); |
| 201 | void isci_device_clear_reset_pending(struct isci_host *ihost, |
| 202 | struct isci_remote_device *idev); |
| 203 | void isci_remote_device_change_state(struct isci_remote_device *idev, |
| 204 | enum isci_status status); |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 205 | /** |
| 206 | * scic_remote_device_stop() - This method will stop both transmission and |
| 207 | * reception of link activity for the supplied remote device. This method |
| 208 | * disables normal IO requests from flowing through to the remote device. |
| 209 | * @remote_device: This parameter specifies the device to be stopped. |
| 210 | * @timeout: This parameter specifies the number of milliseconds in which the |
| 211 | * stop operation should complete. |
| 212 | * |
| 213 | * An indication of whether the device was successfully stopped. SCI_SUCCESS |
| 214 | * This value is returned if the transmission and reception for the device was |
| 215 | * successfully stopped. |
| 216 | */ |
| 217 | enum sci_status scic_remote_device_stop( |
| 218 | struct scic_sds_remote_device *remote_device, |
| 219 | u32 timeout); |
| 220 | |
| 221 | /** |
| 222 | * scic_remote_device_reset() - This method will reset the device making it |
| 223 | * ready for operation. This method must be called anytime the device is |
| 224 | * reset either through a SMP phy control or a port hard reset request. |
| 225 | * @remote_device: This parameter specifies the device to be reset. |
| 226 | * |
| 227 | * This method does not actually cause the device hardware to be reset. This |
| 228 | * method resets the software object so that it will be operational after a |
| 229 | * device hardware reset completes. An indication of whether the device reset |
| 230 | * was accepted. SCI_SUCCESS This value is returned if the device reset is |
| 231 | * started. |
| 232 | */ |
| 233 | enum sci_status scic_remote_device_reset( |
| 234 | struct scic_sds_remote_device *remote_device); |
| 235 | |
| 236 | /** |
| 237 | * scic_remote_device_reset_complete() - This method informs the device object |
| 238 | * that the reset operation is complete and the device can resume operation |
| 239 | * again. |
| 240 | * @remote_device: This parameter specifies the device which is to be informed |
| 241 | * of the reset complete operation. |
| 242 | * |
| 243 | * An indication that the device is resuming operation. SCI_SUCCESS the device |
| 244 | * is resuming operation. |
| 245 | */ |
| 246 | enum sci_status scic_remote_device_reset_complete( |
| 247 | struct scic_sds_remote_device *remote_device); |
| 248 | |
| 249 | |
| 250 | |
| 251 | /** |
| 252 | * scic_remote_device_get_connection_rate() - This method simply returns the |
| 253 | * link rate at which communications to the remote device occur. |
| 254 | * @remote_device: This parameter specifies the device for which to get the |
| 255 | * connection rate. |
| 256 | * |
| 257 | * Return the link rate at which we transfer for the supplied remote device. |
| 258 | */ |
| 259 | enum sas_linkrate scic_remote_device_get_connection_rate( |
| 260 | struct scic_sds_remote_device *remote_device); |
| 261 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 262 | #if !defined(DISABLE_ATAPI) |
| 263 | /** |
| 264 | * scic_remote_device_is_atapi() - |
| 265 | * @this_device: The device whose type is to be decided. |
| 266 | * |
| 267 | * This method first decide whether a device is a stp target, then decode the |
| 268 | * signature fis of a DA STP device to tell whether it is a standard end disk |
| 269 | * or an ATAPI device. bool Indicate a device is ATAPI device or not. |
| 270 | */ |
| 271 | bool scic_remote_device_is_atapi( |
| 272 | struct scic_sds_remote_device *device_handle); |
| 273 | #else /* !defined(DISABLE_ATAPI) */ |
| 274 | #define scic_remote_device_is_atapi(device_handle) false |
| 275 | #endif /* !defined(DISABLE_ATAPI) */ |
| 276 | |
| 277 | |
| 278 | |
| 279 | /** |
| 280 | * enum scic_sds_remote_device_states - This enumeration depicts all the states |
| 281 | * for the common remote device state machine. |
| 282 | * |
| 283 | * |
| 284 | */ |
| 285 | enum scic_sds_remote_device_states { |
| 286 | /** |
| 287 | * Simply the initial state for the base remote device state machine. |
| 288 | */ |
| 289 | SCI_BASE_REMOTE_DEVICE_STATE_INITIAL, |
| 290 | |
| 291 | /** |
| 292 | * This state indicates that the remote device has successfully been |
| 293 | * stopped. In this state no new IO operations are permitted. |
| 294 | * This state is entered from the INITIAL state. |
| 295 | * This state is entered from the STOPPING state. |
| 296 | */ |
| 297 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPED, |
| 298 | |
| 299 | /** |
| 300 | * This state indicates the the remote device is in the process of |
| 301 | * becoming ready (i.e. starting). In this state no new IO operations |
| 302 | * are permitted. |
| 303 | * This state is entered from the STOPPED state. |
| 304 | */ |
| 305 | SCI_BASE_REMOTE_DEVICE_STATE_STARTING, |
| 306 | |
| 307 | /** |
| 308 | * This state indicates the remote device is now ready. Thus, the user |
| 309 | * is able to perform IO operations on the remote device. |
| 310 | * This state is entered from the STARTING state. |
| 311 | */ |
| 312 | SCI_BASE_REMOTE_DEVICE_STATE_READY, |
| 313 | |
| 314 | /** |
| 315 | * This state indicates that the remote device is in the process of |
| 316 | * stopping. In this state no new IO operations are permitted, but |
| 317 | * existing IO operations are allowed to complete. |
| 318 | * This state is entered from the READY state. |
| 319 | * This state is entered from the FAILED state. |
| 320 | */ |
| 321 | SCI_BASE_REMOTE_DEVICE_STATE_STOPPING, |
| 322 | |
| 323 | /** |
| 324 | * This state indicates that the remote device has failed. |
| 325 | * In this state no new IO operations are permitted. |
| 326 | * This state is entered from the INITIALIZING state. |
| 327 | * This state is entered from the READY state. |
| 328 | */ |
| 329 | SCI_BASE_REMOTE_DEVICE_STATE_FAILED, |
| 330 | |
| 331 | /** |
| 332 | * This state indicates the device is being reset. |
| 333 | * In this state no new IO operations are permitted. |
| 334 | * This state is entered from the READY state. |
| 335 | */ |
| 336 | SCI_BASE_REMOTE_DEVICE_STATE_RESETTING, |
| 337 | |
| 338 | /** |
| 339 | * Simply the final state for the base remote device state machine. |
| 340 | */ |
| 341 | SCI_BASE_REMOTE_DEVICE_STATE_FINAL, |
| 342 | }; |
| 343 | |
| 344 | /** |
| 345 | * enum scic_sds_ssp_remote_device_ready_substates - |
| 346 | * |
| 347 | * This is the enumeration of the ready substates for the |
| 348 | * struct scic_sds_remote_device. |
| 349 | */ |
| 350 | enum scic_sds_ssp_remote_device_ready_substates { |
| 351 | /** |
| 352 | * This is the initial state for the remote device ready substate. |
| 353 | */ |
| 354 | SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_INITIAL, |
| 355 | |
| 356 | /** |
| 357 | * This is the ready operational substate for the remote device. |
| 358 | * This is the normal operational state for a remote device. |
| 359 | */ |
| 360 | SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_OPERATIONAL, |
| 361 | |
| 362 | /** |
| 363 | * This is the suspended state for the remote device. This is the state |
| 364 | * that the device is placed in when a RNC suspend is received by |
| 365 | * the SCU hardware. |
| 366 | */ |
| 367 | SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_SUSPENDED, |
| 368 | |
| 369 | /** |
| 370 | * This is the final state that the device is placed in before a change |
| 371 | * to the base state machine. |
| 372 | */ |
| 373 | SCIC_SDS_SSP_REMOTE_DEVICE_READY_SUBSTATE_FINAL, |
| 374 | |
| 375 | SCIC_SDS_SSP_REMOTE_DEVICE_READY_MAX_SUBSTATES |
| 376 | }; |
| 377 | |
| 378 | /** |
| 379 | * enum scic_sds_stp_remote_device_ready_substates - |
| 380 | * |
| 381 | * This is the enumeration for the struct scic_sds_remote_device ready substates |
| 382 | * for the STP remote device. |
| 383 | */ |
| 384 | enum scic_sds_stp_remote_device_ready_substates { |
| 385 | /** |
| 386 | * This is the idle substate for the stp remote device. When there are no |
| 387 | * active IO for the device it is is in this state. |
| 388 | */ |
| 389 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_IDLE, |
| 390 | |
| 391 | /** |
| 392 | * This is the command state for for the STP remote device. This state is |
| 393 | * entered when the device is processing a non-NCQ command. The device object |
| 394 | * will fail any new start IO requests until this command is complete. |
| 395 | */ |
| 396 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_CMD, |
| 397 | |
| 398 | /** |
| 399 | * This is the NCQ state for the STP remote device. This state is entered |
| 400 | * when the device is processing an NCQ reuqest. It will remain in this state |
| 401 | * so long as there is one or more NCQ requests being processed. |
| 402 | */ |
| 403 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ, |
| 404 | |
| 405 | /** |
| 406 | * This is the NCQ error state for the STP remote device. This state is |
| 407 | * entered when an SDB error FIS is received by the device object while in the |
| 408 | * NCQ state. The device object will only accept a READ LOG command while in |
| 409 | * this state. |
| 410 | */ |
| 411 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_NCQ_ERROR, |
| 412 | |
| 413 | #if !defined(DISABLE_ATAPI) |
| 414 | /** |
| 415 | * This is the ATAPI error state for the STP ATAPI remote device. This state is |
| 416 | * entered when ATAPI device sends error status FIS without data while the device |
| 417 | * object is in CMD state. A suspension event is expected in this state. The device |
| 418 | * object will resume right away. |
| 419 | */ |
| 420 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_ATAPI_ERROR, |
| 421 | #endif |
| 422 | |
| 423 | /** |
| 424 | * This is the READY substate indicates the device is waiting for the RESET task |
| 425 | * coming to be recovered from certain hardware specific error. |
| 426 | */ |
| 427 | SCIC_SDS_STP_REMOTE_DEVICE_READY_SUBSTATE_AWAIT_RESET, |
| 428 | }; |
| 429 | |
| 430 | /** |
| 431 | * enum scic_sds_smp_remote_device_ready_substates - |
| 432 | * |
| 433 | * This is the enumeration of the ready substates for the SMP REMOTE DEVICE. |
| 434 | */ |
| 435 | enum scic_sds_smp_remote_device_ready_substates { |
| 436 | /** |
| 437 | * This is the ready operational substate for the remote device. This is the |
| 438 | * normal operational state for a remote device. |
| 439 | */ |
| 440 | SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_IDLE, |
| 441 | |
| 442 | /** |
| 443 | * This is the suspended state for the remote device. This is the state that |
| 444 | * the device is placed in when a RNC suspend is received by the SCU hardware. |
| 445 | */ |
| 446 | SCIC_SDS_SMP_REMOTE_DEVICE_READY_SUBSTATE_CMD, |
| 447 | }; |
| 448 | |
| 449 | static inline struct scic_sds_remote_device *rnc_to_dev(struct scic_sds_remote_node_context *rnc) |
| 450 | { |
| 451 | struct scic_sds_remote_device *sci_dev; |
| 452 | |
| 453 | sci_dev = container_of(rnc, typeof(*sci_dev), rnc); |
| 454 | |
| 455 | return sci_dev; |
| 456 | } |
| 457 | |
Dan Williams | a1a113b | 2011-04-21 18:44:45 -0700 | [diff] [blame^] | 458 | static inline struct domain_device *sci_dev_to_domain(struct scic_sds_remote_device *sci_dev) |
| 459 | { |
| 460 | struct isci_remote_device *idev = container_of(sci_dev, typeof(*idev), sci); |
| 461 | |
| 462 | return idev->domain_dev; |
| 463 | } |
| 464 | |
| 465 | static inline bool dev_is_expander(struct domain_device *dev) |
| 466 | { |
| 467 | return dev->dev_type == EDGE_DEV || dev->dev_type == FANOUT_DEV; |
| 468 | } |
| 469 | |
Dan Williams | 88f3b62 | 2011-04-22 19:18:03 -0700 | [diff] [blame] | 470 | typedef enum sci_status (*scic_sds_remote_device_request_handler_t)( |
| 471 | struct scic_sds_remote_device *device, |
| 472 | struct scic_sds_request *request); |
| 473 | |
| 474 | typedef enum sci_status (*scic_sds_remote_device_high_priority_request_complete_handler_t)( |
| 475 | struct scic_sds_remote_device *device, |
| 476 | struct scic_sds_request *request, |
| 477 | void *, |
| 478 | enum sci_io_status); |
| 479 | |
| 480 | typedef enum sci_status (*scic_sds_remote_device_handler_t)( |
| 481 | struct scic_sds_remote_device *sci_dev); |
| 482 | |
| 483 | typedef enum sci_status (*scic_sds_remote_device_suspend_handler_t)( |
| 484 | struct scic_sds_remote_device *sci_dev, |
| 485 | u32 suspend_type); |
| 486 | |
| 487 | typedef enum sci_status (*scic_sds_remote_device_resume_handler_t)( |
| 488 | struct scic_sds_remote_device *sci_dev); |
| 489 | |
| 490 | typedef enum sci_status (*scic_sds_remote_device_frame_handler_t)( |
| 491 | struct scic_sds_remote_device *sci_dev, |
| 492 | u32 frame_index); |
| 493 | |
| 494 | typedef enum sci_status (*scic_sds_remote_device_event_handler_t)( |
| 495 | struct scic_sds_remote_device *sci_dev, |
| 496 | u32 event_code); |
| 497 | |
| 498 | typedef void (*scic_sds_remote_device_ready_not_ready_handler_t)( |
| 499 | struct scic_sds_remote_device *sci_dev); |
| 500 | |
| 501 | /** |
| 502 | * struct scic_sds_remote_device_state_handler - This structure conains the |
| 503 | * state handlers that are needed to process requests for the SCU remote |
| 504 | * device objects. |
| 505 | * |
| 506 | * |
| 507 | */ |
| 508 | struct scic_sds_remote_device_state_handler { |
| 509 | /** |
| 510 | * The start_handler specifies the method invoked when a user |
| 511 | * attempts to start a remote device. |
| 512 | */ |
| 513 | scic_sds_remote_device_handler_t start_handler; |
| 514 | |
| 515 | /** |
| 516 | * The stop_handler specifies the method invoked when a user attempts to |
| 517 | * stop a remote device. |
| 518 | */ |
| 519 | scic_sds_remote_device_handler_t stop_handler; |
| 520 | |
| 521 | /** |
| 522 | * The fail_handler specifies the method invoked when a remote device |
| 523 | * failure has occurred. A failure may be due to an inability to |
| 524 | * initialize/configure the device. |
| 525 | */ |
| 526 | scic_sds_remote_device_handler_t fail_handler; |
| 527 | |
| 528 | /** |
| 529 | * The destruct_handler specifies the method invoked when attempting to |
| 530 | * destruct a remote device. |
| 531 | */ |
| 532 | scic_sds_remote_device_handler_t destruct_handler; |
| 533 | |
| 534 | /** |
| 535 | * The reset handler specifies the method invloked when requesting to |
| 536 | * reset a remote device. |
| 537 | */ |
| 538 | scic_sds_remote_device_handler_t reset_handler; |
| 539 | |
| 540 | /** |
| 541 | * The reset complete handler specifies the method invloked when |
| 542 | * reporting that a reset has completed to the remote device. |
| 543 | */ |
| 544 | scic_sds_remote_device_handler_t reset_complete_handler; |
| 545 | |
| 546 | /** |
| 547 | * The start_io_handler specifies the method invoked when a user |
| 548 | * attempts to start an IO request for a remote device. |
| 549 | */ |
| 550 | scic_sds_remote_device_request_handler_t start_io_handler; |
| 551 | |
| 552 | /** |
| 553 | * The complete_io_handler specifies the method invoked when a user |
| 554 | * attempts to complete an IO request for a remote device. |
| 555 | */ |
| 556 | scic_sds_remote_device_request_handler_t complete_io_handler; |
| 557 | |
| 558 | /** |
| 559 | * The continue_io_handler specifies the method invoked when a user |
| 560 | * attempts to continue an IO request for a remote device. |
| 561 | */ |
| 562 | scic_sds_remote_device_request_handler_t continue_io_handler; |
| 563 | |
| 564 | /** |
| 565 | * The start_task_handler specifies the method invoked when a user |
| 566 | * attempts to start a task management request for a remote device. |
| 567 | */ |
| 568 | scic_sds_remote_device_request_handler_t start_task_handler; |
| 569 | |
| 570 | /** |
| 571 | * The complete_task_handler specifies the method invoked when a user |
| 572 | * attempts to complete a task management request for a remote device. |
| 573 | */ |
| 574 | scic_sds_remote_device_request_handler_t complete_task_handler; |
| 575 | |
| 576 | |
| 577 | scic_sds_remote_device_suspend_handler_t suspend_handler; |
| 578 | scic_sds_remote_device_resume_handler_t resume_handler; |
| 579 | scic_sds_remote_device_event_handler_t event_handler; |
| 580 | scic_sds_remote_device_frame_handler_t frame_handler; |
| 581 | }; |
| 582 | |
| 583 | extern const struct sci_base_state scic_sds_ssp_remote_device_ready_substate_table[]; |
| 584 | extern const struct sci_base_state scic_sds_stp_remote_device_ready_substate_table[]; |
| 585 | extern const struct sci_base_state scic_sds_smp_remote_device_ready_substate_table[]; |
| 586 | |
| 587 | /** |
| 588 | * scic_sds_remote_device_increment_request_count() - |
| 589 | * |
| 590 | * This macro incrments the request count for this device |
| 591 | */ |
| 592 | #define scic_sds_remote_device_increment_request_count(sci_dev) \ |
| 593 | ((sci_dev)->started_request_count++) |
| 594 | |
| 595 | /** |
| 596 | * scic_sds_remote_device_decrement_request_count() - |
| 597 | * |
| 598 | * This macro decrements the request count for this device. This count will |
| 599 | * never decrment past 0. |
| 600 | */ |
| 601 | #define scic_sds_remote_device_decrement_request_count(sci_dev) \ |
| 602 | ((sci_dev)->started_request_count > 0 ? \ |
| 603 | (sci_dev)->started_request_count-- : 0) |
| 604 | |
| 605 | /** |
| 606 | * scic_sds_remote_device_get_request_count() - |
| 607 | * |
| 608 | * This is a helper macro to return the current device request count. |
| 609 | */ |
| 610 | #define scic_sds_remote_device_get_request_count(sci_dev) \ |
| 611 | ((sci_dev)->started_request_count) |
| 612 | |
| 613 | /** |
| 614 | * scic_sds_remote_device_get_port() - |
| 615 | * |
| 616 | * This macro returns the owning port of this remote device obejct. |
| 617 | */ |
| 618 | #define scic_sds_remote_device_get_port(sci_dev) \ |
| 619 | ((sci_dev)->owning_port) |
| 620 | |
| 621 | /** |
| 622 | * scic_sds_remote_device_get_controller() - |
| 623 | * |
| 624 | * This macro returns the controller object that contains this device object |
| 625 | */ |
| 626 | #define scic_sds_remote_device_get_controller(sci_dev) \ |
| 627 | scic_sds_port_get_controller(scic_sds_remote_device_get_port(sci_dev)) |
| 628 | |
| 629 | /** |
| 630 | * scic_sds_remote_device_set_state_handlers() - |
| 631 | * |
| 632 | * This macro sets the remote device state handlers pointer and is set on entry |
| 633 | * to each device state. |
| 634 | */ |
| 635 | #define scic_sds_remote_device_set_state_handlers(sci_dev, handlers) \ |
| 636 | ((sci_dev)->state_handlers = (handlers)) |
| 637 | |
| 638 | /** |
| 639 | * scic_sds_remote_device_get_port() - |
| 640 | * |
| 641 | * This macro returns the owning port of this device |
| 642 | */ |
| 643 | #define scic_sds_remote_device_get_port(sci_dev) \ |
| 644 | ((sci_dev)->owning_port) |
| 645 | |
| 646 | /** |
| 647 | * scic_sds_remote_device_get_sequence() - |
| 648 | * |
| 649 | * This macro returns the remote device sequence value |
| 650 | */ |
| 651 | #define scic_sds_remote_device_get_sequence(sci_dev) \ |
| 652 | (\ |
| 653 | scic_sds_remote_device_get_controller(sci_dev)-> \ |
| 654 | remote_device_sequence[(sci_dev)->rnc.remote_node_index] \ |
| 655 | ) |
| 656 | |
| 657 | /** |
| 658 | * scic_sds_remote_device_get_controller_peg() - |
| 659 | * |
| 660 | * This macro returns the controllers protocol engine group |
| 661 | */ |
| 662 | #define scic_sds_remote_device_get_controller_peg(sci_dev) \ |
| 663 | (\ |
| 664 | scic_sds_controller_get_protocol_engine_group(\ |
| 665 | scic_sds_port_get_controller(\ |
| 666 | scic_sds_remote_device_get_port(sci_dev) \ |
| 667 | ) \ |
| 668 | ) \ |
| 669 | ) |
| 670 | |
| 671 | /** |
| 672 | * scic_sds_remote_device_get_port_index() - |
| 673 | * |
| 674 | * This macro returns the port index for the devices owning port |
| 675 | */ |
| 676 | #define scic_sds_remote_device_get_port_index(sci_dev) \ |
| 677 | (scic_sds_port_get_index(scic_sds_remote_device_get_port(sci_dev))) |
| 678 | |
| 679 | /** |
| 680 | * scic_sds_remote_device_get_index() - |
| 681 | * |
| 682 | * This macro returns the remote node index for this device object |
| 683 | */ |
| 684 | #define scic_sds_remote_device_get_index(sci_dev) \ |
| 685 | ((sci_dev)->rnc.remote_node_index) |
| 686 | |
| 687 | /** |
| 688 | * scic_sds_remote_device_build_command_context() - |
| 689 | * |
| 690 | * This macro builds a remote device context for the SCU post request operation |
| 691 | */ |
| 692 | #define scic_sds_remote_device_build_command_context(device, command) \ |
| 693 | ((command) \ |
| 694 | | (scic_sds_remote_device_get_controller_peg((device)) << SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) \ |
| 695 | | (scic_sds_remote_device_get_port_index((device)) << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) \ |
| 696 | | (scic_sds_remote_device_get_index((device))) \ |
| 697 | ) |
| 698 | |
| 699 | /** |
| 700 | * scic_sds_remote_device_set_working_request() - |
| 701 | * |
| 702 | * This macro makes the working request assingment for the remote device |
| 703 | * object. To clear the working request use this macro with a NULL request |
| 704 | * object. |
| 705 | */ |
| 706 | #define scic_sds_remote_device_set_working_request(device, request) \ |
| 707 | ((device)->working_request = (request)) |
| 708 | |
| 709 | enum sci_status scic_sds_remote_device_frame_handler( |
| 710 | struct scic_sds_remote_device *sci_dev, |
| 711 | u32 frame_index); |
| 712 | |
| 713 | enum sci_status scic_sds_remote_device_event_handler( |
| 714 | struct scic_sds_remote_device *sci_dev, |
| 715 | u32 event_code); |
| 716 | |
| 717 | enum sci_status scic_sds_remote_device_start_io( |
| 718 | struct scic_sds_controller *controller, |
| 719 | struct scic_sds_remote_device *sci_dev, |
| 720 | struct scic_sds_request *io_request); |
| 721 | |
| 722 | enum sci_status scic_sds_remote_device_complete_io( |
| 723 | struct scic_sds_controller *controller, |
| 724 | struct scic_sds_remote_device *sci_dev, |
| 725 | struct scic_sds_request *io_request); |
| 726 | |
| 727 | enum sci_status scic_sds_remote_device_resume( |
| 728 | struct scic_sds_remote_device *sci_dev); |
| 729 | |
| 730 | enum sci_status scic_sds_remote_device_suspend( |
| 731 | struct scic_sds_remote_device *sci_dev, |
| 732 | u32 suspend_type); |
| 733 | |
| 734 | enum sci_status scic_sds_remote_device_start_task( |
| 735 | struct scic_sds_controller *controller, |
| 736 | struct scic_sds_remote_device *sci_dev, |
| 737 | struct scic_sds_request *io_request); |
| 738 | |
| 739 | void scic_sds_remote_device_post_request( |
| 740 | struct scic_sds_remote_device *sci_dev, |
| 741 | u32 request); |
| 742 | |
| 743 | #if !defined(DISABLE_ATAPI) |
| 744 | bool scic_sds_remote_device_is_atapi( |
| 745 | struct scic_sds_remote_device *sci_dev); |
| 746 | #else /* !defined(DISABLE_ATAPI) */ |
| 747 | #define scic_sds_remote_device_is_atapi(sci_dev) false |
| 748 | #endif /* !defined(DISABLE_ATAPI) */ |
| 749 | |
| 750 | void scic_sds_remote_device_start_request( |
| 751 | struct scic_sds_remote_device *sci_dev, |
| 752 | struct scic_sds_request *sci_req, |
| 753 | enum sci_status status); |
| 754 | |
| 755 | void scic_sds_remote_device_continue_request(void *sci_dev); |
| 756 | |
| 757 | enum sci_status scic_sds_remote_device_default_start_handler( |
| 758 | struct scic_sds_remote_device *sci_dev); |
| 759 | |
| 760 | enum sci_status scic_sds_remote_device_default_fail_handler( |
| 761 | struct scic_sds_remote_device *sci_dev); |
| 762 | |
| 763 | enum sci_status scic_sds_remote_device_default_destruct_handler( |
| 764 | struct scic_sds_remote_device *sci_dev); |
| 765 | |
| 766 | enum sci_status scic_sds_remote_device_default_reset_handler( |
| 767 | struct scic_sds_remote_device *device); |
| 768 | |
| 769 | enum sci_status scic_sds_remote_device_default_reset_complete_handler( |
| 770 | struct scic_sds_remote_device *device); |
| 771 | |
| 772 | enum sci_status scic_sds_remote_device_default_start_request_handler( |
| 773 | struct scic_sds_remote_device *device, |
| 774 | struct scic_sds_request *request); |
| 775 | |
| 776 | enum sci_status scic_sds_remote_device_default_complete_request_handler( |
| 777 | struct scic_sds_remote_device *device, |
| 778 | struct scic_sds_request *request); |
| 779 | |
| 780 | enum sci_status scic_sds_remote_device_default_continue_request_handler( |
| 781 | struct scic_sds_remote_device *device, |
| 782 | struct scic_sds_request *request); |
| 783 | |
| 784 | enum sci_status scic_sds_remote_device_default_suspend_handler( |
| 785 | struct scic_sds_remote_device *sci_dev, |
| 786 | u32 suspend_type); |
| 787 | |
| 788 | enum sci_status scic_sds_remote_device_default_resume_handler( |
| 789 | struct scic_sds_remote_device *sci_dev); |
| 790 | |
| 791 | |
| 792 | enum sci_status scic_sds_remote_device_default_frame_handler( |
| 793 | struct scic_sds_remote_device *sci_dev, |
| 794 | u32 frame_index); |
| 795 | |
| 796 | enum sci_status scic_sds_remote_device_ready_state_stop_handler( |
| 797 | struct scic_sds_remote_device *device); |
| 798 | |
| 799 | enum sci_status scic_sds_remote_device_ready_state_reset_handler( |
| 800 | struct scic_sds_remote_device *device); |
| 801 | |
| 802 | enum sci_status scic_sds_remote_device_general_frame_handler( |
| 803 | struct scic_sds_remote_device *sci_dev, |
| 804 | u32 frame_index); |
| 805 | |
| 806 | enum sci_status scic_sds_remote_device_general_event_handler( |
| 807 | struct scic_sds_remote_device *sci_dev, |
| 808 | u32 event_code); |
| 809 | |
| 810 | enum sci_status scic_sds_ssp_remote_device_ready_suspended_substate_resume_handler( |
| 811 | struct scic_sds_remote_device *sci_dev); |
| 812 | |
| 813 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 814 | |
| 815 | #endif /* !defined(_ISCI_REMOTE_DEVICE_H_) */ |