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" |
Edmund Nadolski | 12ef654 | 2011-06-02 00:10:50 +0000 | [diff] [blame] | 60 | #include "isci.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 61 | #include "remote_node_table.h" |
Dan Williams | 63a3a15 | 2011-05-08 21:36:46 -0700 | [diff] [blame] | 62 | #include "registers.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 63 | #include "scu_unsolicited_frame.h" |
Dan Williams | 63a3a15 | 2011-05-08 21:36:46 -0700 | [diff] [blame] | 64 | #include "unsolicited_frame_control.h" |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 65 | #include "probe_roms.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 66 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 67 | struct isci_request; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 68 | struct scu_task_context; |
| 69 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 70 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 71 | /** |
| 72 | * struct scic_power_control - |
| 73 | * |
| 74 | * This structure defines the fields for managing power control for direct |
| 75 | * attached disk devices. |
| 76 | */ |
| 77 | struct scic_power_control { |
| 78 | /** |
| 79 | * This field is set when the power control timer is running and cleared when |
| 80 | * it is not. |
| 81 | */ |
| 82 | bool timer_started; |
| 83 | |
| 84 | /** |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 85 | * Timer to control when the directed attached disks can consume power. |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 86 | */ |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 87 | struct sci_timer timer; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * This field is used to keep track of how many phys are put into the |
| 91 | * requesters field. |
| 92 | */ |
| 93 | u8 phys_waiting; |
| 94 | |
| 95 | /** |
| 96 | * This field is used to keep track of how many phys have been granted to consume power |
| 97 | */ |
| 98 | u8 phys_granted_power; |
| 99 | |
| 100 | /** |
| 101 | * This field is an array of phys that we are waiting on. The phys are direct |
| 102 | * mapped into requesters via struct scic_sds_phy.phy_index |
| 103 | */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 104 | struct isci_phy *requesters[SCI_MAX_PHYS]; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 105 | |
| 106 | }; |
| 107 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 108 | struct scic_sds_port_configuration_agent; |
| 109 | typedef void (*port_config_fn)(struct scic_sds_controller *, |
| 110 | struct scic_sds_port_configuration_agent *, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame^] | 111 | struct isci_port *, struct isci_phy *); |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 112 | |
| 113 | struct scic_sds_port_configuration_agent { |
| 114 | u16 phy_configured_mask; |
| 115 | u16 phy_ready_mask; |
| 116 | struct { |
| 117 | u8 min_index; |
| 118 | u8 max_index; |
| 119 | } phy_valid_port_range[SCI_MAX_PHYS]; |
| 120 | bool timer_pending; |
| 121 | port_config_fn link_up_handler; |
| 122 | port_config_fn link_down_handler; |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 123 | struct sci_timer timer; |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 126 | /** |
| 127 | * struct scic_sds_controller - |
| 128 | * |
| 129 | * This structure represents the SCU controller object. |
| 130 | */ |
| 131 | struct scic_sds_controller { |
| 132 | /** |
| 133 | * This field contains the information for the base controller state |
| 134 | * machine. |
| 135 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 136 | struct sci_base_state_machine sm; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
Edmund Nadolski | 6cb5853 | 2011-05-19 11:59:56 +0000 | [diff] [blame] | 139 | * Timer for controller start/stop operations. |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 140 | */ |
Edmund Nadolski | 6cb5853 | 2011-05-19 11:59:56 +0000 | [diff] [blame] | 141 | struct sci_timer timer; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * This field contains the user parameters to be utilized for this |
| 145 | * core controller object. |
| 146 | */ |
| 147 | union scic_user_parameters user_parameters; |
| 148 | |
| 149 | /** |
| 150 | * This field contains the OEM parameters to be utilized for this |
| 151 | * core controller object. |
| 152 | */ |
| 153 | union scic_oem_parameters oem_parameters; |
| 154 | |
| 155 | /** |
| 156 | * This field contains the port configuration agent for this controller. |
| 157 | */ |
| 158 | struct scic_sds_port_configuration_agent port_agent; |
| 159 | |
| 160 | /** |
| 161 | * This field is the array of device objects that are currently constructed |
| 162 | * for this controller object. This table is used as a fast lookup of device |
| 163 | * objects that need to handle device completion notifications from the |
| 164 | * hardware. The table is RNi based. |
| 165 | */ |
| 166 | struct scic_sds_remote_device *device_table[SCI_MAX_REMOTE_DEVICES]; |
| 167 | |
| 168 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 169 | * This field is the free RNi data structure |
| 170 | */ |
| 171 | struct scic_remote_node_table available_remote_nodes; |
| 172 | |
| 173 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 174 | * This filed is the struct scic_power_control data used to controll when direct |
| 175 | * attached devices can consume power. |
| 176 | */ |
| 177 | struct scic_power_control power_control; |
| 178 | |
Dan Williams | dd047c8 | 2011-06-09 11:06:58 -0700 | [diff] [blame] | 179 | /* sequence number per tci */ |
| 180 | u8 io_request_sequence[SCI_MAX_IO_REQUESTS]; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 181 | |
| 182 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 183 | * This field is a pointer to the memory allocated by the driver for the task |
| 184 | * context table. This data is shared between the hardware and software. |
| 185 | */ |
| 186 | struct scu_task_context *task_context_table; |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 187 | dma_addr_t task_context_dma; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * This field is a pointer to the memory allocated by the driver for the |
| 191 | * remote node context table. This table is shared between the hardware and |
| 192 | * software. |
| 193 | */ |
| 194 | union scu_remote_node_context *remote_node_context_table; |
| 195 | |
| 196 | /** |
| 197 | * This field is a pointer to the completion queue. This memory is |
| 198 | * written to by the hardware and read by the software. |
| 199 | */ |
| 200 | u32 *completion_queue; |
| 201 | |
| 202 | /** |
| 203 | * This field is the software copy of the completion queue get pointer. The |
| 204 | * controller object writes this value to the hardware after processing the |
| 205 | * completion entries. |
| 206 | */ |
| 207 | u32 completion_queue_get; |
| 208 | |
| 209 | /** |
| 210 | * This field is the minimum of the number of hardware supported port entries |
| 211 | * and the software requested port entries. |
| 212 | */ |
| 213 | u32 logical_port_entries; |
| 214 | |
| 215 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 216 | * This field is the minimum number of devices supported by the hardware and |
| 217 | * the number of devices requested by the software. |
| 218 | */ |
| 219 | u32 remote_node_entries; |
| 220 | |
| 221 | /** |
| 222 | * This field is the minimum number of IO requests supported by the hardware |
| 223 | * and the number of IO requests requested by the software. |
| 224 | */ |
| 225 | u32 task_context_entries; |
| 226 | |
| 227 | /** |
| 228 | * This object contains all of the unsolicited frame specific |
| 229 | * data utilized by the core controller. |
| 230 | */ |
| 231 | struct scic_sds_unsolicited_frame_control uf_control; |
| 232 | |
| 233 | /* Phy Startup Data */ |
| 234 | /** |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 235 | * Timer for controller phy request startup. On controller start the |
| 236 | * controller will start each PHY individually in order of phy index. |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 237 | */ |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 238 | struct sci_timer phy_timer; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 239 | |
| 240 | /** |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 241 | * This field is set when the phy_timer is running and is cleared when |
| 242 | * the phy_timer is stopped. |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 243 | */ |
| 244 | bool phy_startup_timer_pending; |
| 245 | |
| 246 | /** |
| 247 | * This field is the index of the next phy start. It is initialized to 0 and |
| 248 | * increments for each phy index that is started. |
| 249 | */ |
| 250 | u32 next_phy_to_start; |
| 251 | |
| 252 | /** |
| 253 | * This field controlls the invalid link up notifications to the SCI_USER. If |
| 254 | * an invalid_link_up notification is reported a bit for the PHY index is set |
| 255 | * so further notifications are not made. Once the PHY object reports link up |
| 256 | * and is made part of a port then this bit for the PHY index is cleared. |
| 257 | */ |
| 258 | u8 invalid_phy_mask; |
| 259 | |
| 260 | /* |
| 261 | * This field saves the current interrupt coalescing number of the controller. |
| 262 | */ |
| 263 | u16 interrupt_coalesce_number; |
| 264 | |
| 265 | /* |
| 266 | * This field saves the current interrupt coalescing timeout value in microseconds. |
| 267 | */ |
| 268 | u32 interrupt_coalesce_timeout; |
| 269 | |
| 270 | /** |
| 271 | * This field is a pointer to the memory mapped register space for the |
| 272 | * struct smu_registers. |
| 273 | */ |
| 274 | struct smu_registers __iomem *smu_registers; |
| 275 | |
| 276 | /** |
| 277 | * This field is a pointer to the memory mapped register space for the |
| 278 | * struct scu_registers. |
| 279 | */ |
| 280 | struct scu_registers __iomem *scu_registers; |
| 281 | |
| 282 | }; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 283 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 284 | struct isci_host { |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 285 | struct scic_sds_controller sci; |
Dan Williams | ac668c6 | 2011-06-07 18:50:55 -0700 | [diff] [blame] | 286 | u16 tci_head; |
| 287 | u16 tci_tail; |
| 288 | u16 tci_pool[SCI_MAX_IO_REQUESTS]; |
| 289 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 290 | union scic_oem_parameters oem_parameters; |
| 291 | |
| 292 | int id; /* unique within a given pci device */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 293 | struct isci_phy phys[SCI_MAX_PHYS]; |
Dan Williams | e531381 | 2011-05-07 10:11:43 -0700 | [diff] [blame] | 294 | struct isci_port ports[SCI_MAX_PORTS + 1]; /* includes dummy port */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 295 | struct sas_ha_struct sas_ha; |
| 296 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 297 | spinlock_t state_lock; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 298 | struct pci_dev *pdev; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 299 | enum isci_status status; |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 300 | #define IHOST_START_PENDING 0 |
| 301 | #define IHOST_STOP_PENDING 1 |
| 302 | unsigned long flags; |
| 303 | wait_queue_head_t eventq; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 304 | struct Scsi_Host *shost; |
| 305 | struct tasklet_struct completion_tasklet; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 306 | struct list_head requests_to_complete; |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 307 | struct list_head requests_to_errorback; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 308 | spinlock_t scic_lock; |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 309 | struct isci_request *reqs[SCI_MAX_IO_REQUESTS]; |
Dan Williams | 57f20f4 | 2011-04-21 18:14:45 -0700 | [diff] [blame] | 310 | struct isci_remote_device devices[SCI_MAX_REMOTE_DEVICES]; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 313 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 314 | * enum scic_sds_controller_states - This enumeration depicts all the states |
| 315 | * for the common controller state machine. |
| 316 | */ |
| 317 | enum scic_sds_controller_states { |
| 318 | /** |
| 319 | * Simply the initial state for the base controller state machine. |
| 320 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 321 | SCIC_INITIAL = 0, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 322 | |
| 323 | /** |
| 324 | * This state indicates that the controller is reset. The memory for |
| 325 | * the controller is in it's initial state, but the controller requires |
| 326 | * initialization. |
| 327 | * This state is entered from the INITIAL state. |
| 328 | * This state is entered from the RESETTING state. |
| 329 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 330 | SCIC_RESET, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 331 | |
| 332 | /** |
| 333 | * This state is typically an action state that indicates the controller |
| 334 | * is in the process of initialization. In this state no new IO operations |
| 335 | * are permitted. |
| 336 | * This state is entered from the RESET state. |
| 337 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 338 | SCIC_INITIALIZING, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 339 | |
| 340 | /** |
| 341 | * This state indicates that the controller has been successfully |
| 342 | * initialized. In this state no new IO operations are permitted. |
| 343 | * This state is entered from the INITIALIZING state. |
| 344 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 345 | SCIC_INITIALIZED, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 346 | |
| 347 | /** |
| 348 | * This state indicates the the controller is in the process of becoming |
| 349 | * ready (i.e. starting). In this state no new IO operations are permitted. |
| 350 | * This state is entered from the INITIALIZED state. |
| 351 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 352 | SCIC_STARTING, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 353 | |
| 354 | /** |
| 355 | * This state indicates the controller is now ready. Thus, the user |
| 356 | * is able to perform IO operations on the controller. |
| 357 | * This state is entered from the STARTING state. |
| 358 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 359 | SCIC_READY, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 360 | |
| 361 | /** |
| 362 | * This state is typically an action state that indicates the controller |
| 363 | * is in the process of resetting. Thus, the user is unable to perform |
| 364 | * IO operations on the controller. A reset is considered destructive in |
| 365 | * most cases. |
| 366 | * This state is entered from the READY state. |
| 367 | * This state is entered from the FAILED state. |
| 368 | * This state is entered from the STOPPED state. |
| 369 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 370 | SCIC_RESETTING, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 371 | |
| 372 | /** |
| 373 | * This state indicates that the controller is in the process of stopping. |
| 374 | * In this state no new IO operations are permitted, but existing IO |
| 375 | * operations are allowed to complete. |
| 376 | * This state is entered from the READY state. |
| 377 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 378 | SCIC_STOPPING, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 379 | |
| 380 | /** |
| 381 | * This state indicates that the controller has successfully been stopped. |
| 382 | * In this state no new IO operations are permitted. |
| 383 | * This state is entered from the STOPPING state. |
| 384 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 385 | SCIC_STOPPED, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 386 | |
| 387 | /** |
| 388 | * This state indicates that the controller could not successfully be |
| 389 | * initialized. In this state no new IO operations are permitted. |
| 390 | * This state is entered from the INITIALIZING state. |
| 391 | * This state is entered from the STARTING state. |
| 392 | * This state is entered from the STOPPING state. |
| 393 | * This state is entered from the RESETTING state. |
| 394 | */ |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 395 | SCIC_FAILED, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 396 | }; |
| 397 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 398 | /** |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 399 | * struct isci_pci_info - This class represents the pci function containing the |
| 400 | * controllers. Depending on PCI SKU, there could be up to 2 controllers in |
| 401 | * the PCI function. |
| 402 | */ |
| 403 | #define SCI_MAX_MSIX_INT (SCI_NUM_MSI_X_INT*SCI_MAX_CONTROLLERS) |
| 404 | |
| 405 | struct isci_pci_info { |
| 406 | struct msix_entry msix_entries[SCI_MAX_MSIX_INT]; |
Dan Williams | b329aff | 2011-03-07 16:02:25 -0800 | [diff] [blame] | 407 | struct isci_host *hosts[SCI_MAX_CONTROLLERS]; |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 408 | struct isci_orom *orom; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 409 | }; |
| 410 | |
| 411 | static inline struct isci_pci_info *to_pci_info(struct pci_dev *pdev) |
| 412 | { |
| 413 | return pci_get_drvdata(pdev); |
| 414 | } |
| 415 | |
Dan Williams | b329aff | 2011-03-07 16:02:25 -0800 | [diff] [blame] | 416 | #define for_each_isci_host(id, ihost, pdev) \ |
| 417 | for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \ |
| 418 | id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \ |
| 419 | ihost = to_pci_info(pdev)->hosts[++id]) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 420 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 421 | 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] | 422 | { |
| 423 | return isci_host->status; |
| 424 | } |
| 425 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 426 | static inline void isci_host_change_state(struct isci_host *isci_host, |
| 427 | enum isci_status status) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 428 | { |
| 429 | unsigned long flags; |
| 430 | |
| 431 | dev_dbg(&isci_host->pdev->dev, |
| 432 | "%s: isci_host = %p, state = 0x%x", |
| 433 | __func__, |
| 434 | isci_host, |
| 435 | status); |
| 436 | spin_lock_irqsave(&isci_host->state_lock, flags); |
| 437 | isci_host->status = status; |
| 438 | spin_unlock_irqrestore(&isci_host->state_lock, flags); |
| 439 | |
| 440 | } |
| 441 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 442 | static inline void wait_for_start(struct isci_host *ihost) |
| 443 | { |
| 444 | wait_event(ihost->eventq, !test_bit(IHOST_START_PENDING, &ihost->flags)); |
| 445 | } |
| 446 | |
| 447 | static inline void wait_for_stop(struct isci_host *ihost) |
| 448 | { |
| 449 | wait_event(ihost->eventq, !test_bit(IHOST_STOP_PENDING, &ihost->flags)); |
| 450 | } |
| 451 | |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 452 | static inline void wait_for_device_start(struct isci_host *ihost, struct isci_remote_device *idev) |
| 453 | { |
| 454 | wait_event(ihost->eventq, !test_bit(IDEV_START_PENDING, &idev->flags)); |
| 455 | } |
| 456 | |
| 457 | static inline void wait_for_device_stop(struct isci_host *ihost, struct isci_remote_device *idev) |
| 458 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 459 | wait_event(ihost->eventq, !test_bit(IDEV_STOP_PENDING, &idev->flags)); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 460 | } |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 461 | |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 462 | static inline struct isci_host *dev_to_ihost(struct domain_device *dev) |
| 463 | { |
| 464 | return dev->port->ha->lldd_ha; |
| 465 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 466 | |
Artur Wojcik | cc3dbd0 | 2011-05-04 07:58:16 +0000 | [diff] [blame] | 467 | static inline struct isci_host *scic_to_ihost(struct scic_sds_controller *scic) |
| 468 | { |
| 469 | /* XXX delete after merging scic_sds_contoller and isci_host */ |
| 470 | struct isci_host *ihost = container_of(scic, typeof(*ihost), sci); |
| 471 | |
| 472 | return ihost; |
| 473 | } |
| 474 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 475 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 476 | * scic_sds_controller_get_protocol_engine_group() - |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 477 | * |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 478 | * This macro returns the protocol engine group for this controller object. |
| 479 | * Presently we only support protocol engine group 0 so just return that |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 480 | */ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 481 | #define scic_sds_controller_get_protocol_engine_group(controller) 0 |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 482 | |
Dan Williams | dd047c8 | 2011-06-09 11:06:58 -0700 | [diff] [blame] | 483 | /* see scic_controller_io_tag_allocate|free for how seq and tci are built */ |
| 484 | #define ISCI_TAG(seq, tci) (((u16) (seq)) << 12 | tci) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 485 | |
Dan Williams | dd047c8 | 2011-06-09 11:06:58 -0700 | [diff] [blame] | 486 | /* these are returned by the hardware, so sanitize them */ |
| 487 | #define ISCI_TAG_SEQ(tag) (((tag) >> 12) & (SCI_MAX_SEQ-1)) |
| 488 | #define ISCI_TAG_TCI(tag) ((tag) & (SCI_MAX_IO_REQUESTS-1)) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 489 | |
| 490 | /* expander attached sata devices require 3 rnc slots */ |
| 491 | static inline int scic_sds_remote_device_node_count(struct scic_sds_remote_device *sci_dev) |
| 492 | { |
| 493 | struct domain_device *dev = sci_dev_to_domain(sci_dev); |
| 494 | |
| 495 | if ((dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) && |
| 496 | !sci_dev->is_direct_attached) |
| 497 | return SCU_STP_REMOTE_NODE_COUNT; |
| 498 | return SCU_SSP_REMOTE_NODE_COUNT; |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * scic_sds_controller_set_invalid_phy() - |
| 503 | * |
| 504 | * This macro will set the bit in the invalid phy mask for this controller |
| 505 | * object. This is used to control messages reported for invalid link up |
| 506 | * notifications. |
| 507 | */ |
| 508 | #define scic_sds_controller_set_invalid_phy(controller, phy) \ |
| 509 | ((controller)->invalid_phy_mask |= (1 << (phy)->phy_index)) |
| 510 | |
| 511 | /** |
| 512 | * scic_sds_controller_clear_invalid_phy() - |
| 513 | * |
| 514 | * This macro will clear the bit in the invalid phy mask for this controller |
| 515 | * object. This is used to control messages reported for invalid link up |
| 516 | * notifications. |
| 517 | */ |
| 518 | #define scic_sds_controller_clear_invalid_phy(controller, phy) \ |
| 519 | ((controller)->invalid_phy_mask &= ~(1 << (phy)->phy_index)) |
| 520 | |
| 521 | static inline struct device *scic_to_dev(struct scic_sds_controller *scic) |
| 522 | { |
| 523 | return &scic_to_ihost(scic)->pdev->dev; |
| 524 | } |
| 525 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 526 | static inline struct device *sciphy_to_dev(struct isci_phy *iphy) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 527 | { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 528 | |
| 529 | if (!iphy || !iphy->isci_port || !iphy->isci_port->isci_host) |
| 530 | return NULL; |
| 531 | |
| 532 | return &iphy->isci_port->isci_host->pdev->dev; |
| 533 | } |
| 534 | |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame^] | 535 | static inline struct device *sciport_to_dev(struct isci_port *iport) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 536 | { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 537 | |
| 538 | if (!iport || !iport->isci_host) |
| 539 | return NULL; |
| 540 | |
| 541 | return &iport->isci_host->pdev->dev; |
| 542 | } |
| 543 | |
| 544 | static inline struct device *scirdev_to_dev(struct scic_sds_remote_device *sci_dev) |
| 545 | { |
| 546 | struct isci_remote_device *idev = |
| 547 | container_of(sci_dev, typeof(*idev), sci); |
| 548 | |
| 549 | if (!idev || !idev->isci_port || !idev->isci_port->isci_host) |
| 550 | return NULL; |
| 551 | |
| 552 | return &idev->isci_port->isci_host->pdev->dev; |
| 553 | } |
| 554 | |
| 555 | enum { |
| 556 | ISCI_SI_REVA0, |
| 557 | ISCI_SI_REVA2, |
| 558 | ISCI_SI_REVB0, |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 559 | ISCI_SI_REVC0 |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 560 | }; |
| 561 | |
| 562 | extern int isci_si_rev; |
| 563 | |
| 564 | static inline bool is_a0(void) |
| 565 | { |
| 566 | return isci_si_rev == ISCI_SI_REVA0; |
| 567 | } |
| 568 | |
| 569 | static inline bool is_a2(void) |
| 570 | { |
| 571 | return isci_si_rev == ISCI_SI_REVA2; |
| 572 | } |
| 573 | |
| 574 | static inline bool is_b0(void) |
| 575 | { |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 576 | return isci_si_rev == ISCI_SI_REVB0; |
| 577 | } |
| 578 | |
| 579 | static inline bool is_c0(void) |
| 580 | { |
| 581 | return isci_si_rev > ISCI_SI_REVB0; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | void scic_sds_controller_post_request(struct scic_sds_controller *scic, |
| 585 | u32 request); |
| 586 | void scic_sds_controller_release_frame(struct scic_sds_controller *scic, |
| 587 | u32 frame_index); |
| 588 | void scic_sds_controller_copy_sata_response(void *response_buffer, |
| 589 | void *frame_header, |
| 590 | void *frame_buffer); |
| 591 | enum sci_status scic_sds_controller_allocate_remote_node_context(struct scic_sds_controller *scic, |
| 592 | struct scic_sds_remote_device *sci_dev, |
| 593 | u16 *node_id); |
| 594 | void scic_sds_controller_free_remote_node_context( |
| 595 | struct scic_sds_controller *scic, |
| 596 | struct scic_sds_remote_device *sci_dev, |
| 597 | u16 node_id); |
| 598 | union scu_remote_node_context *scic_sds_controller_get_remote_node_context_buffer( |
| 599 | struct scic_sds_controller *scic, |
| 600 | u16 node_id); |
| 601 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 602 | struct isci_request *scic_request_by_tag(struct scic_sds_controller *scic, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 603 | u16 io_tag); |
| 604 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 605 | void scic_sds_controller_power_control_queue_insert( |
| 606 | struct scic_sds_controller *scic, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 607 | struct isci_phy *iphy); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 608 | |
| 609 | void scic_sds_controller_power_control_queue_remove( |
| 610 | struct scic_sds_controller *scic, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 611 | struct isci_phy *iphy); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 612 | |
| 613 | void scic_sds_controller_link_up( |
| 614 | struct scic_sds_controller *scic, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame^] | 615 | struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 616 | struct isci_phy *iphy); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 617 | |
| 618 | void scic_sds_controller_link_down( |
| 619 | struct scic_sds_controller *scic, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame^] | 620 | struct isci_port *iport, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 621 | struct isci_phy *iphy); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 622 | |
| 623 | void scic_sds_controller_remote_device_stopped( |
| 624 | struct scic_sds_controller *scic, |
| 625 | struct scic_sds_remote_device *sci_dev); |
| 626 | |
| 627 | void scic_sds_controller_copy_task_context( |
| 628 | struct scic_sds_controller *scic, |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 629 | struct isci_request *ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 630 | |
| 631 | void scic_sds_controller_register_setup(struct scic_sds_controller *scic); |
| 632 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 633 | enum sci_status scic_controller_continue_io(struct isci_request *ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 634 | int isci_host_scan_finished(struct Scsi_Host *, unsigned long); |
| 635 | void isci_host_scan_start(struct Scsi_Host *); |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 636 | u16 isci_alloc_tag(struct isci_host *ihost); |
| 637 | enum sci_status isci_free_tag(struct isci_host *ihost, u16 io_tag); |
| 638 | void isci_tci_free(struct isci_host *ihost, u16 tci); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 639 | |
| 640 | int isci_host_init(struct isci_host *); |
| 641 | |
| 642 | void isci_host_init_controller_names( |
| 643 | struct isci_host *isci_host, |
| 644 | unsigned int controller_idx); |
| 645 | |
| 646 | void isci_host_deinit( |
| 647 | struct isci_host *); |
| 648 | |
| 649 | void isci_host_port_link_up( |
| 650 | struct isci_host *, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame^] | 651 | struct isci_port *, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 652 | struct isci_phy *); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 653 | int isci_host_dev_found(struct domain_device *); |
| 654 | |
| 655 | void isci_host_remote_device_start_complete( |
| 656 | struct isci_host *, |
| 657 | struct isci_remote_device *, |
| 658 | enum sci_status); |
| 659 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 660 | void scic_controller_disable_interrupts( |
| 661 | struct scic_sds_controller *scic); |
| 662 | |
| 663 | enum sci_status scic_controller_start_io( |
| 664 | struct scic_sds_controller *scic, |
| 665 | struct scic_sds_remote_device *remote_device, |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 666 | struct isci_request *ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 667 | |
| 668 | enum sci_task_status scic_controller_start_task( |
| 669 | struct scic_sds_controller *scic, |
| 670 | struct scic_sds_remote_device *remote_device, |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 671 | struct isci_request *ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 672 | |
| 673 | enum sci_status scic_controller_terminate_request( |
| 674 | struct scic_sds_controller *scic, |
| 675 | struct scic_sds_remote_device *remote_device, |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 676 | struct isci_request *ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 677 | |
| 678 | enum sci_status scic_controller_complete_io( |
| 679 | struct scic_sds_controller *scic, |
| 680 | struct scic_sds_remote_device *remote_device, |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 681 | struct isci_request *ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 682 | |
Dan Williams | e2f8db5 | 2011-05-10 02:28:46 -0700 | [diff] [blame] | 683 | void scic_sds_port_configuration_agent_construct( |
| 684 | struct scic_sds_port_configuration_agent *port_agent); |
| 685 | |
| 686 | enum sci_status scic_sds_port_configuration_agent_initialize( |
| 687 | struct scic_sds_controller *controller, |
| 688 | struct scic_sds_port_configuration_agent *port_agent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 689 | #endif |