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 | */ |
Dan Williams | ce2b326 | 2011-05-08 15:49:15 -0700 | [diff] [blame] | 55 | #ifndef _SCI_HOST_H_ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 56 | #define _SCI_HOST_H_ |
| 57 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 58 | #include "remote_device.h" |
Dan Williams | ce2b326 | 2011-05-08 15:49:15 -0700 | [diff] [blame] | 59 | #include "phy.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 60 | #include "pool.h" |
Dan Williams | 3bff9d5 | 2011-05-08 22:15:10 -0700 | [diff] [blame] | 61 | #include "state_machine.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 62 | #include "remote_node_table.h" |
Dan Williams | 63a3a15 | 2011-05-08 21:36:46 -0700 | [diff] [blame] | 63 | #include "registers.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 64 | #include "scu_unsolicited_frame.h" |
Dan Williams | 63a3a15 | 2011-05-08 21:36:46 -0700 | [diff] [blame] | 65 | #include "unsolicited_frame_control.h" |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 66 | #include "probe_roms.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 67 | |
| 68 | struct scic_sds_request; |
| 69 | struct scu_task_context; |
| 70 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 71 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 72 | /** |
| 73 | * struct scic_power_control - |
| 74 | * |
| 75 | * This structure defines the fields for managing power control for direct |
| 76 | * attached disk devices. |
| 77 | */ |
| 78 | struct scic_power_control { |
| 79 | /** |
| 80 | * This field is set when the power control timer is running and cleared when |
| 81 | * it is not. |
| 82 | */ |
| 83 | bool timer_started; |
| 84 | |
| 85 | /** |
| 86 | * This field is the handle to the driver timer object. This timer is used to |
| 87 | * control when the directed attached disks can consume power. |
| 88 | */ |
| 89 | void *timer; |
| 90 | |
| 91 | /** |
| 92 | * This field is used to keep track of how many phys are put into the |
| 93 | * requesters field. |
| 94 | */ |
| 95 | u8 phys_waiting; |
| 96 | |
| 97 | /** |
| 98 | * This field is used to keep track of how many phys have been granted to consume power |
| 99 | */ |
| 100 | u8 phys_granted_power; |
| 101 | |
| 102 | /** |
| 103 | * This field is an array of phys that we are waiting on. The phys are direct |
| 104 | * mapped into requesters via struct scic_sds_phy.phy_index |
| 105 | */ |
| 106 | struct scic_sds_phy *requesters[SCI_MAX_PHYS]; |
| 107 | |
| 108 | }; |
| 109 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 110 | struct scic_sds_port_configuration_agent; |
| 111 | typedef void (*port_config_fn)(struct scic_sds_controller *, |
| 112 | struct scic_sds_port_configuration_agent *, |
| 113 | struct scic_sds_port *, struct scic_sds_phy *); |
| 114 | |
| 115 | struct scic_sds_port_configuration_agent { |
| 116 | u16 phy_configured_mask; |
| 117 | u16 phy_ready_mask; |
| 118 | struct { |
| 119 | u8 min_index; |
| 120 | u8 max_index; |
| 121 | } phy_valid_port_range[SCI_MAX_PHYS]; |
| 122 | bool timer_pending; |
| 123 | port_config_fn link_up_handler; |
| 124 | port_config_fn link_down_handler; |
| 125 | void *timer; |
| 126 | }; |
| 127 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 128 | /** |
| 129 | * struct scic_sds_controller - |
| 130 | * |
| 131 | * This structure represents the SCU controller object. |
| 132 | */ |
| 133 | struct scic_sds_controller { |
| 134 | /** |
| 135 | * This field contains the information for the base controller state |
| 136 | * machine. |
| 137 | */ |
| 138 | struct sci_base_state_machine state_machine; |
| 139 | |
| 140 | /** |
| 141 | * This field is the driver timer object handler used to time the controller |
| 142 | * object start and stop requests. |
| 143 | */ |
| 144 | void *timeout_timer; |
| 145 | |
| 146 | /** |
| 147 | * This field contains the user parameters to be utilized for this |
| 148 | * core controller object. |
| 149 | */ |
| 150 | union scic_user_parameters user_parameters; |
| 151 | |
| 152 | /** |
| 153 | * This field contains the OEM parameters to be utilized for this |
| 154 | * core controller object. |
| 155 | */ |
| 156 | union scic_oem_parameters oem_parameters; |
| 157 | |
| 158 | /** |
| 159 | * This field contains the port configuration agent for this controller. |
| 160 | */ |
| 161 | struct scic_sds_port_configuration_agent port_agent; |
| 162 | |
| 163 | /** |
| 164 | * This field is the array of device objects that are currently constructed |
| 165 | * for this controller object. This table is used as a fast lookup of device |
| 166 | * objects that need to handle device completion notifications from the |
| 167 | * hardware. The table is RNi based. |
| 168 | */ |
| 169 | struct scic_sds_remote_device *device_table[SCI_MAX_REMOTE_DEVICES]; |
| 170 | |
| 171 | /** |
| 172 | * This field is the array of IO request objects that are currently active for |
| 173 | * this controller object. This table is used as a fast lookup of the io |
| 174 | * request object that need to handle completion queue notifications. The |
| 175 | * table is TCi based. |
| 176 | */ |
| 177 | struct scic_sds_request *io_request_table[SCI_MAX_IO_REQUESTS]; |
| 178 | |
| 179 | /** |
| 180 | * This field is the free RNi data structure |
| 181 | */ |
| 182 | struct scic_remote_node_table available_remote_nodes; |
| 183 | |
| 184 | /** |
| 185 | * This field is the TCi pool used to manage the task context index. |
| 186 | */ |
| 187 | SCI_POOL_CREATE(tci_pool, u16, SCI_MAX_IO_REQUESTS); |
| 188 | |
| 189 | /** |
| 190 | * This filed is the struct scic_power_control data used to controll when direct |
| 191 | * attached devices can consume power. |
| 192 | */ |
| 193 | struct scic_power_control power_control; |
| 194 | |
| 195 | /** |
| 196 | * This field is the array of sequence values for the IO Tag fields. Even |
| 197 | * though only 4 bits of the field is used for the sequence the sequence is 16 |
| 198 | * bits in size so the sequence can be bitwise or'd with the TCi to build the |
| 199 | * IO Tag value. |
| 200 | */ |
| 201 | u16 io_request_sequence[SCI_MAX_IO_REQUESTS]; |
| 202 | |
| 203 | /** |
| 204 | * This field in the array of sequence values for the RNi. These are used |
| 205 | * to control io request build to io request start operations. The sequence |
| 206 | * value is recorded into an io request when it is built and is checked on |
| 207 | * the io request start operation to make sure that there was not a device |
| 208 | * hot plug between the build and start operation. |
| 209 | */ |
| 210 | u8 remote_device_sequence[SCI_MAX_REMOTE_DEVICES]; |
| 211 | |
| 212 | /** |
| 213 | * This field is a pointer to the memory allocated by the driver for the task |
| 214 | * context table. This data is shared between the hardware and software. |
| 215 | */ |
| 216 | struct scu_task_context *task_context_table; |
| 217 | |
| 218 | /** |
| 219 | * This field is a pointer to the memory allocated by the driver for the |
| 220 | * remote node context table. This table is shared between the hardware and |
| 221 | * software. |
| 222 | */ |
| 223 | union scu_remote_node_context *remote_node_context_table; |
| 224 | |
| 225 | /** |
| 226 | * This field is a pointer to the completion queue. This memory is |
| 227 | * written to by the hardware and read by the software. |
| 228 | */ |
| 229 | u32 *completion_queue; |
| 230 | |
| 231 | /** |
| 232 | * This field is the software copy of the completion queue get pointer. The |
| 233 | * controller object writes this value to the hardware after processing the |
| 234 | * completion entries. |
| 235 | */ |
| 236 | u32 completion_queue_get; |
| 237 | |
| 238 | /** |
| 239 | * This field is the minimum of the number of hardware supported port entries |
| 240 | * and the software requested port entries. |
| 241 | */ |
| 242 | u32 logical_port_entries; |
| 243 | |
| 244 | /** |
| 245 | * This field is the minimum number of hardware supported completion queue |
| 246 | * entries and the software requested completion queue entries. |
| 247 | */ |
| 248 | u32 completion_queue_entries; |
| 249 | |
| 250 | /** |
| 251 | * This field is the minimum number of hardware supported event entries and |
| 252 | * the software requested event entries. |
| 253 | */ |
| 254 | u32 completion_event_entries; |
| 255 | |
| 256 | /** |
| 257 | * This field is the minimum number of devices supported by the hardware and |
| 258 | * the number of devices requested by the software. |
| 259 | */ |
| 260 | u32 remote_node_entries; |
| 261 | |
| 262 | /** |
| 263 | * This field is the minimum number of IO requests supported by the hardware |
| 264 | * and the number of IO requests requested by the software. |
| 265 | */ |
| 266 | u32 task_context_entries; |
| 267 | |
| 268 | /** |
| 269 | * This object contains all of the unsolicited frame specific |
| 270 | * data utilized by the core controller. |
| 271 | */ |
| 272 | struct scic_sds_unsolicited_frame_control uf_control; |
| 273 | |
| 274 | /* Phy Startup Data */ |
| 275 | /** |
| 276 | * This field is the driver timer handle for controller phy request startup. |
| 277 | * On controller start the controller will start each PHY individually in |
| 278 | * order of phy index. |
| 279 | */ |
| 280 | void *phy_startup_timer; |
| 281 | |
| 282 | /** |
| 283 | * This field is set when the phy_startup_timer is running and is cleared when |
| 284 | * the phy_startup_timer is stopped. |
| 285 | */ |
| 286 | bool phy_startup_timer_pending; |
| 287 | |
| 288 | /** |
| 289 | * This field is the index of the next phy start. It is initialized to 0 and |
| 290 | * increments for each phy index that is started. |
| 291 | */ |
| 292 | u32 next_phy_to_start; |
| 293 | |
| 294 | /** |
| 295 | * This field controlls the invalid link up notifications to the SCI_USER. If |
| 296 | * an invalid_link_up notification is reported a bit for the PHY index is set |
| 297 | * so further notifications are not made. Once the PHY object reports link up |
| 298 | * and is made part of a port then this bit for the PHY index is cleared. |
| 299 | */ |
| 300 | u8 invalid_phy_mask; |
| 301 | |
| 302 | /* |
| 303 | * This field saves the current interrupt coalescing number of the controller. |
| 304 | */ |
| 305 | u16 interrupt_coalesce_number; |
| 306 | |
| 307 | /* |
| 308 | * This field saves the current interrupt coalescing timeout value in microseconds. |
| 309 | */ |
| 310 | u32 interrupt_coalesce_timeout; |
| 311 | |
| 312 | /** |
| 313 | * This field is a pointer to the memory mapped register space for the |
| 314 | * struct smu_registers. |
| 315 | */ |
| 316 | struct smu_registers __iomem *smu_registers; |
| 317 | |
| 318 | /** |
| 319 | * This field is a pointer to the memory mapped register space for the |
| 320 | * struct scu_registers. |
| 321 | */ |
| 322 | struct scu_registers __iomem *scu_registers; |
| 323 | |
| 324 | }; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 325 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 326 | struct isci_host { |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 327 | struct scic_sds_controller sci; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 328 | union scic_oem_parameters oem_parameters; |
| 329 | |
| 330 | int id; /* unique within a given pci device */ |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 331 | struct list_head timers; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 332 | void *core_ctrl_memory; |
| 333 | struct dma_pool *dma_pool; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 334 | struct isci_phy phys[SCI_MAX_PHYS]; |
Dan Williams | e531381 | 2011-05-07 10:11:43 -0700 | [diff] [blame] | 335 | struct isci_port ports[SCI_MAX_PORTS + 1]; /* includes dummy port */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 336 | struct sas_ha_struct sas_ha; |
| 337 | |
| 338 | int can_queue; |
| 339 | spinlock_t queue_lock; |
| 340 | spinlock_t state_lock; |
| 341 | |
| 342 | struct pci_dev *pdev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 343 | |
| 344 | enum isci_status status; |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 345 | #define IHOST_START_PENDING 0 |
| 346 | #define IHOST_STOP_PENDING 1 |
| 347 | unsigned long flags; |
| 348 | wait_queue_head_t eventq; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 349 | struct Scsi_Host *shost; |
| 350 | struct tasklet_struct completion_tasklet; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 351 | struct list_head requests_to_complete; |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 352 | struct list_head requests_to_errorback; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 353 | spinlock_t scic_lock; |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 354 | |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 355 | struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES]; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 356 | }; |
| 357 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 358 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 359 | * enum scic_sds_controller_states - This enumeration depicts all the states |
| 360 | * for the common controller state machine. |
| 361 | */ |
| 362 | enum scic_sds_controller_states { |
| 363 | /** |
| 364 | * Simply the initial state for the base controller state machine. |
| 365 | */ |
| 366 | SCI_BASE_CONTROLLER_STATE_INITIAL = 0, |
| 367 | |
| 368 | /** |
| 369 | * This state indicates that the controller is reset. The memory for |
| 370 | * the controller is in it's initial state, but the controller requires |
| 371 | * initialization. |
| 372 | * This state is entered from the INITIAL state. |
| 373 | * This state is entered from the RESETTING state. |
| 374 | */ |
| 375 | SCI_BASE_CONTROLLER_STATE_RESET, |
| 376 | |
| 377 | /** |
| 378 | * This state is typically an action state that indicates the controller |
| 379 | * is in the process of initialization. In this state no new IO operations |
| 380 | * are permitted. |
| 381 | * This state is entered from the RESET state. |
| 382 | */ |
| 383 | SCI_BASE_CONTROLLER_STATE_INITIALIZING, |
| 384 | |
| 385 | /** |
| 386 | * This state indicates that the controller has been successfully |
| 387 | * initialized. In this state no new IO operations are permitted. |
| 388 | * This state is entered from the INITIALIZING state. |
| 389 | */ |
| 390 | SCI_BASE_CONTROLLER_STATE_INITIALIZED, |
| 391 | |
| 392 | /** |
| 393 | * This state indicates the the controller is in the process of becoming |
| 394 | * ready (i.e. starting). In this state no new IO operations are permitted. |
| 395 | * This state is entered from the INITIALIZED state. |
| 396 | */ |
| 397 | SCI_BASE_CONTROLLER_STATE_STARTING, |
| 398 | |
| 399 | /** |
| 400 | * This state indicates the controller is now ready. Thus, the user |
| 401 | * is able to perform IO operations on the controller. |
| 402 | * This state is entered from the STARTING state. |
| 403 | */ |
| 404 | SCI_BASE_CONTROLLER_STATE_READY, |
| 405 | |
| 406 | /** |
| 407 | * This state is typically an action state that indicates the controller |
| 408 | * is in the process of resetting. Thus, the user is unable to perform |
| 409 | * IO operations on the controller. A reset is considered destructive in |
| 410 | * most cases. |
| 411 | * This state is entered from the READY state. |
| 412 | * This state is entered from the FAILED state. |
| 413 | * This state is entered from the STOPPED state. |
| 414 | */ |
| 415 | SCI_BASE_CONTROLLER_STATE_RESETTING, |
| 416 | |
| 417 | /** |
| 418 | * This state indicates that the controller is in the process of stopping. |
| 419 | * In this state no new IO operations are permitted, but existing IO |
| 420 | * operations are allowed to complete. |
| 421 | * This state is entered from the READY state. |
| 422 | */ |
| 423 | SCI_BASE_CONTROLLER_STATE_STOPPING, |
| 424 | |
| 425 | /** |
| 426 | * This state indicates that the controller has successfully been stopped. |
| 427 | * In this state no new IO operations are permitted. |
| 428 | * This state is entered from the STOPPING state. |
| 429 | */ |
| 430 | SCI_BASE_CONTROLLER_STATE_STOPPED, |
| 431 | |
| 432 | /** |
| 433 | * This state indicates that the controller could not successfully be |
| 434 | * initialized. In this state no new IO operations are permitted. |
| 435 | * This state is entered from the INITIALIZING state. |
| 436 | * This state is entered from the STARTING state. |
| 437 | * This state is entered from the STOPPING state. |
| 438 | * This state is entered from the RESETTING state. |
| 439 | */ |
| 440 | SCI_BASE_CONTROLLER_STATE_FAILED, |
| 441 | |
| 442 | SCI_BASE_CONTROLLER_MAX_STATES |
| 443 | |
| 444 | }; |
| 445 | |
| 446 | |
| 447 | |
| 448 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 449 | * struct isci_pci_info - This class represents the pci function containing the |
| 450 | * controllers. Depending on PCI SKU, there could be up to 2 controllers in |
| 451 | * the PCI function. |
| 452 | */ |
| 453 | #define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS) |
| 454 | |
| 455 | struct isci_pci_info { |
| 456 | struct msix_entry msix_entries[SCI_MAX_MSIX_INT]; |
Dan Williams | b329aff | 2011-03-07 16:02:25 -0800 | [diff] [blame] | 457 | struct isci_host *hosts[SCI_MAX_CONTROLLERS]; |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 458 | struct isci_orom *orom; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 459 | }; |
| 460 | |
| 461 | static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev) |
| 462 | { |
| 463 | return pci_get_drvdata(pdev); |
| 464 | } |
| 465 | |
Dan Williams | b329aff | 2011-03-07 16:02:25 -0800 | [diff] [blame] | 466 | #define for_each_isci_host(id, ihost, pdev) \ |
| 467 | for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \ |
| 468 | id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \ |
| 469 | ihost = to_pci_info(pdev)->hosts[++id]) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 470 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 471 | static inline enum isci_status isci_host_get_state(struct isci_host *isci_host) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 472 | { |
| 473 | return isci_host->status; |
| 474 | } |
| 475 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 476 | static inline void isci_host_change_state(struct isci_host *isci_host, |
| 477 | enum isci_status status) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 478 | { |
| 479 | unsigned long flags; |
| 480 | |
| 481 | dev_dbg(&isci_host->pdev->dev, |
| 482 | "%s: isci_host = %p, state = 0x%x", |
| 483 | __func__, |
| 484 | isci_host, |
| 485 | status); |
| 486 | spin_lock_irqsave(&isci_host->state_lock, flags); |
| 487 | isci_host->status = status; |
| 488 | spin_unlock_irqrestore(&isci_host->state_lock, flags); |
| 489 | |
| 490 | } |
| 491 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 492 | static inline int isci_host_can_queue(struct isci_host *isci_host, int num) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 493 | { |
| 494 | int ret = 0; |
| 495 | unsigned long flags; |
| 496 | |
| 497 | spin_lock_irqsave(&isci_host->queue_lock, flags); |
| 498 | if ((isci_host->can_queue - num) < 0) { |
| 499 | dev_dbg(&isci_host->pdev->dev, |
| 500 | "%s: isci_host->can_queue = %d\n", |
| 501 | __func__, |
| 502 | isci_host->can_queue); |
| 503 | ret = -SAS_QUEUE_FULL; |
| 504 | |
| 505 | } else |
| 506 | isci_host->can_queue -= num; |
| 507 | |
| 508 | spin_unlock_irqrestore(&isci_host->queue_lock, flags); |
| 509 | |
| 510 | return ret; |
| 511 | } |
| 512 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 513 | static inline void isci_host_can_dequeue(struct isci_host *isci_host, int num) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 514 | { |
| 515 | unsigned long flags; |
| 516 | |
| 517 | spin_lock_irqsave(&isci_host->queue_lock, flags); |
| 518 | isci_host->can_queue += num; |
| 519 | spin_unlock_irqrestore(&isci_host->queue_lock, flags); |
| 520 | } |
| 521 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 522 | static inline void wait_for_start(struct isci_host *ihost) |
| 523 | { |
| 524 | wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags)); |
| 525 | } |
| 526 | |
| 527 | static inline void wait_for_stop(struct isci_host *ihost) |
| 528 | { |
| 529 | wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags)); |
| 530 | } |
| 531 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 532 | static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev) |
| 533 | { |
| 534 | wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags)); |
| 535 | } |
| 536 | |
| 537 | static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev) |
| 538 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 539 | wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags)); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 540 | } |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 541 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 542 | static inline struct isci_host *dev_to_ihost(struct domain_device *dev) |
| 543 | { |
| 544 | return dev->port->ha->lldd_ha; |
| 545 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 546 | |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 547 | static inline struct isci_host *scic_to_ihost(struct scic_sds_controller *scic) |
| 548 | { |
| 549 | /* XXX delete after merging scic_sds_contoller and isci_host */ |
| 550 | struct isci_host *ihost = container_of(scic, typeof(*ihost), sci); |
| 551 | |
| 552 | return ihost; |
| 553 | } |
| 554 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 555 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 556 | * INCREMENT_QUEUE_GET() - |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 557 | * |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 558 | * This macro will increment the specified index to and if the index wraps to 0 |
| 559 | * it will toggel the cycle bit. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 560 | */ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 561 | #define INCREMENT_QUEUE_GET(index, cycle, entry_count, bit_toggle) \ |
| 562 | { \ |
| 563 | if ((index) + 1 == entry_count) { \ |
| 564 | (index) = 0; \ |
| 565 | (cycle) = (cycle) ^ (bit_toggle); \ |
| 566 | } else { \ |
| 567 | index = index + 1; \ |
| 568 | } \ |
| 569 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 570 | |
| 571 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 572 | * scic_sds_controller_get_port_configuration_agent() - |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 573 | * |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 574 | * This is a helper macro to get the port configuration agent from the |
| 575 | * controller object. |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 576 | */ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 577 | #define scic_sds_controller_get_port_configuration_agent(controller) \ |
| 578 | (&(controller)->port_agent) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 579 | |
| 580 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 581 | * scic_sds_controller_get_protocol_engine_group() - |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 582 | * |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 583 | * This macro returns the protocol engine group for this controller object. |
| 584 | * Presently we only support protocol engine group 0 so just return that |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 585 | */ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 586 | #define scic_sds_controller_get_protocol_engine_group(controller) 0 |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 587 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 588 | /** |
| 589 | * scic_sds_io_tag_construct() - |
| 590 | * |
| 591 | * This macro constructs an IO tag from the sequence and index values. |
| 592 | */ |
| 593 | #define scic_sds_io_tag_construct(sequence, task_index) \ |
| 594 | ((sequence) << 12 | (task_index)) |
| 595 | |
| 596 | /** |
| 597 | * scic_sds_io_tag_get_sequence() - |
| 598 | * |
| 599 | * This macro returns the IO sequence from the IO tag value. |
| 600 | */ |
| 601 | #define scic_sds_io_tag_get_sequence(io_tag) \ |
| 602 | (((io_tag) & 0xF000) >> 12) |
| 603 | |
| 604 | /** |
| 605 | * scic_sds_io_tag_get_index() - |
| 606 | * |
| 607 | * This macro returns the TCi from the io tag value |
| 608 | */ |
| 609 | #define scic_sds_io_tag_get_index(io_tag) \ |
| 610 | ((io_tag) & 0x0FFF) |
| 611 | |
| 612 | /** |
| 613 | * scic_sds_io_sequence_increment() - |
| 614 | * |
| 615 | * This is a helper macro to increment the io sequence count. We may find in |
| 616 | * the future that it will be faster to store the sequence count in such a way |
| 617 | * as we dont perform the shift operation to build io tag values so therefore |
| 618 | * need a way to incrment them correctly |
| 619 | */ |
| 620 | #define scic_sds_io_sequence_increment(value) \ |
| 621 | ((value) = (((value) + 1) & 0x000F)) |
| 622 | |
| 623 | /* expander attached sata devices require 3 rnc slots */ |
| 624 | static inline int scic_sds_remote_device_node_count(struct scic_sds_remote_device *sci_dev) |
| 625 | { |
| 626 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
| 627 | |
| 628 | if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) && |
| 629 | !sci_dev->is_direct_attached) |
| 630 | return SCU_STP_REMOTE_NODE_COUNT; |
| 631 | return SCU_SSP_REMOTE_NODE_COUNT; |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * scic_sds_controller_set_invalid_phy() - |
| 636 | * |
| 637 | * This macro will set the bit in the invalid phy mask for this controller |
| 638 | * object. This is used to control messages reported for invalid link up |
| 639 | * notifications. |
| 640 | */ |
| 641 | #define scic_sds_controller_set_invalid_phy(controller, phy) \ |
| 642 | ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index)) |
| 643 | |
| 644 | /** |
| 645 | * scic_sds_controller_clear_invalid_phy() - |
| 646 | * |
| 647 | * This macro will clear the bit in the invalid phy mask for this controller |
| 648 | * object. This is used to control messages reported for invalid link up |
| 649 | * notifications. |
| 650 | */ |
| 651 | #define scic_sds_controller_clear_invalid_phy(controller, phy) \ |
| 652 | ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index)) |
| 653 | |
| 654 | static inline struct device *scic_to_dev(struct scic_sds_controller *scic) |
| 655 | { |
| 656 | return &scic_to_ihost(scic)->pdev->dev; |
| 657 | } |
| 658 | |
| 659 | static inline struct device *sciphy_to_dev(struct scic_sds_phy *sci_phy) |
| 660 | { |
| 661 | struct isci_phy *iphy = sci_phy_to_iphy(sci_phy); |
| 662 | |
| 663 | if (!iphy || !iphy->isci_port || !iphy->isci_port->isci_host) |
| 664 | return NULL; |
| 665 | |
| 666 | return &iphy->isci_port->isci_host->pdev->dev; |
| 667 | } |
| 668 | |
| 669 | static inline struct device *sciport_to_dev(struct scic_sds_port *sci_port) |
| 670 | { |
| 671 | struct isci_port *iport = sci_port_to_iport(sci_port); |
| 672 | |
| 673 | if (!iport || !iport->isci_host) |
| 674 | return NULL; |
| 675 | |
| 676 | return &iport->isci_host->pdev->dev; |
| 677 | } |
| 678 | |
| 679 | static inline struct device *scirdev_to_dev(struct scic_sds_remote_device *sci_dev) |
| 680 | { |
| 681 | struct isci_remote_device *idev = |
| 682 | container_of(sci_dev, typeof(*idev), sci); |
| 683 | |
| 684 | if (!idev || !idev->isci_port || !idev->isci_port->isci_host) |
| 685 | return NULL; |
| 686 | |
| 687 | return &idev->isci_port->isci_host->pdev->dev; |
| 688 | } |
| 689 | |
| 690 | enum { |
| 691 | ISCI_SI_REVA0, |
| 692 | ISCI_SI_REVA2, |
| 693 | ISCI_SI_REVB0, |
| 694 | }; |
| 695 | |
| 696 | extern int isci_si_rev; |
| 697 | |
| 698 | static inline bool is_a0(void) |
| 699 | { |
| 700 | return isci_si_rev == ISCI_SI_REVA0; |
| 701 | } |
| 702 | |
| 703 | static inline bool is_a2(void) |
| 704 | { |
| 705 | return isci_si_rev == ISCI_SI_REVA2; |
| 706 | } |
| 707 | |
| 708 | static inline bool is_b0(void) |
| 709 | { |
| 710 | return isci_si_rev > ISCI_SI_REVA2; |
| 711 | } |
| 712 | |
| 713 | void scic_sds_controller_post_request(struct scic_sds_controller *scic, |
| 714 | u32 request); |
| 715 | void scic_sds_controller_release_frame(struct scic_sds_controller *scic, |
| 716 | u32 frame_index); |
| 717 | void scic_sds_controller_copy_sata_response(void *response_buffer, |
| 718 | void *frame_header, |
| 719 | void *frame_buffer); |
| 720 | enum sci_status scic_sds_controller_allocate_remote_node_context(struct scic_sds_controller *scic, |
| 721 | struct scic_sds_remote_device *sci_dev, |
| 722 | u16 *node_id); |
| 723 | void scic_sds_controller_free_remote_node_context( |
| 724 | struct scic_sds_controller *scic, |
| 725 | struct scic_sds_remote_device *sci_dev, |
| 726 | u16 node_id); |
| 727 | union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer( |
| 728 | struct scic_sds_controller *scic, |
| 729 | u16 node_id); |
| 730 | |
| 731 | struct scic_sds_request *scic_request_by_tag(struct scic_sds_controller *scic, |
| 732 | u16 io_tag); |
| 733 | |
| 734 | struct scu_task_context *scic_sds_controller_get_task_context_buffer( |
| 735 | struct scic_sds_controller *scic, |
| 736 | u16 io_tag); |
| 737 | |
| 738 | void scic_sds_controller_power_control_queue_insert( |
| 739 | struct scic_sds_controller *scic, |
| 740 | struct scic_sds_phy *sci_phy); |
| 741 | |
| 742 | void scic_sds_controller_power_control_queue_remove( |
| 743 | struct scic_sds_controller *scic, |
| 744 | struct scic_sds_phy *sci_phy); |
| 745 | |
| 746 | void scic_sds_controller_link_up( |
| 747 | struct scic_sds_controller *scic, |
| 748 | struct scic_sds_port *sci_port, |
| 749 | struct scic_sds_phy *sci_phy); |
| 750 | |
| 751 | void scic_sds_controller_link_down( |
| 752 | struct scic_sds_controller *scic, |
| 753 | struct scic_sds_port *sci_port, |
| 754 | struct scic_sds_phy *sci_phy); |
| 755 | |
| 756 | void scic_sds_controller_remote_device_stopped( |
| 757 | struct scic_sds_controller *scic, |
| 758 | struct scic_sds_remote_device *sci_dev); |
| 759 | |
| 760 | void scic_sds_controller_copy_task_context( |
| 761 | struct scic_sds_controller *scic, |
| 762 | struct scic_sds_request *this_request); |
| 763 | |
| 764 | void scic_sds_controller_register_setup(struct scic_sds_controller *scic); |
| 765 | |
| 766 | enum sci_status scic_controller_continue_io(struct scic_sds_request *sci_req); |
| 767 | int isci_host_scan_finished(struct Scsi_Host *, unsigned long); |
| 768 | void isci_host_scan_start(struct Scsi_Host *); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 769 | |
| 770 | int isci_host_init(struct isci_host *); |
| 771 | |
| 772 | void isci_host_init_controller_names( |
| 773 | struct isci_host *isci_host, |
| 774 | unsigned int controller_idx); |
| 775 | |
| 776 | void isci_host_deinit( |
| 777 | struct isci_host *); |
| 778 | |
| 779 | void isci_host_port_link_up( |
| 780 | struct isci_host *, |
| 781 | struct scic_sds_port *, |
| 782 | struct scic_sds_phy *); |
| 783 | int isci_host_dev_found(struct domain_device *); |
| 784 | |
| 785 | void isci_host_remote_device_start_complete( |
| 786 | struct isci_host *, |
| 787 | struct isci_remote_device *, |
| 788 | enum sci_status); |
| 789 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 790 | void scic_controller_disable_interrupts( |
| 791 | struct scic_sds_controller *scic); |
| 792 | |
| 793 | enum sci_status scic_controller_start_io( |
| 794 | struct scic_sds_controller *scic, |
| 795 | struct scic_sds_remote_device *remote_device, |
| 796 | struct scic_sds_request *io_request, |
| 797 | u16 io_tag); |
| 798 | |
| 799 | enum sci_task_status scic_controller_start_task( |
| 800 | struct scic_sds_controller *scic, |
| 801 | struct scic_sds_remote_device *remote_device, |
| 802 | struct scic_sds_request *task_request, |
| 803 | u16 io_tag); |
| 804 | |
| 805 | enum sci_status scic_controller_terminate_request( |
| 806 | struct scic_sds_controller *scic, |
| 807 | struct scic_sds_remote_device *remote_device, |
| 808 | struct scic_sds_request *request); |
| 809 | |
| 810 | enum sci_status scic_controller_complete_io( |
| 811 | struct scic_sds_controller *scic, |
| 812 | struct scic_sds_remote_device *remote_device, |
| 813 | struct scic_sds_request *io_request); |
| 814 | |
| 815 | u16 scic_controller_allocate_io_tag( |
| 816 | struct scic_sds_controller *scic); |
| 817 | |
| 818 | enum sci_status scic_controller_free_io_tag( |
| 819 | struct scic_sds_controller *scic, |
| 820 | u16 io_tag); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 821 | |
| 822 | void scic_sds_port_configuration_agent_construct( |
| 823 | struct scic_sds_port_configuration_agent *port_agent); |
| 824 | |
| 825 | enum sci_status scic_sds_port_configuration_agent_initialize( |
| 826 | struct scic_sds_controller *controller, |
| 827 | struct scic_sds_port_configuration_agent *port_agent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 828 | #endif |