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 | ac668c6 | 2011-06-07 18:50:55 -0700 | [diff] [blame] | 55 | #include <linux/circ_buf.h> |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 56 | #include <linux/device.h> |
| 57 | #include <scsi/sas.h> |
| 58 | #include "host.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 59 | #include "isci.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 60 | #include "port.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 61 | #include "host.h" |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 62 | #include "probe_roms.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 63 | #include "remote_device.h" |
| 64 | #include "request.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 65 | #include "scu_completion_codes.h" |
| 66 | #include "scu_event_codes.h" |
Dan Williams | 63a3a15 | 2011-05-08 21:36:46 -0700 | [diff] [blame] | 67 | #include "registers.h" |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 68 | #include "scu_remote_node_context.h" |
| 69 | #include "scu_task_context.h" |
| 70 | #include "scu_unsolicited_frame.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 71 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 72 | #define SCU_CONTEXT_RAM_INIT_STALL_TIME 200 |
| 73 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 74 | #define smu_max_ports(dcc_value) \ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 75 | (\ |
| 76 | (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_LP_MASK) \ |
| 77 | >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_LP_SHIFT) + 1 \ |
| 78 | ) |
| 79 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 80 | #define smu_max_task_contexts(dcc_value) \ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 81 | (\ |
| 82 | (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_TC_MASK) \ |
| 83 | >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_TC_SHIFT) + 1 \ |
| 84 | ) |
| 85 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 86 | #define smu_max_rncs(dcc_value) \ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 87 | (\ |
| 88 | (((dcc_value) & SMU_DEVICE_CONTEXT_CAPACITY_MAX_RNC_MASK) \ |
| 89 | >> SMU_DEVICE_CONTEXT_CAPACITY_MAX_RNC_SHIFT) + 1 \ |
| 90 | ) |
| 91 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 92 | #define SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT 100 |
| 93 | |
| 94 | /** |
| 95 | * |
| 96 | * |
| 97 | * The number of milliseconds to wait while a given phy is consuming power |
| 98 | * before allowing another set of phys to consume power. Ultimately, this will |
| 99 | * be specified by OEM parameter. |
| 100 | */ |
| 101 | #define SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL 500 |
| 102 | |
| 103 | /** |
| 104 | * NORMALIZE_PUT_POINTER() - |
| 105 | * |
| 106 | * This macro will normalize the completion queue put pointer so its value can |
| 107 | * be used as an array inde |
| 108 | */ |
| 109 | #define NORMALIZE_PUT_POINTER(x) \ |
| 110 | ((x) & SMU_COMPLETION_QUEUE_PUT_POINTER_MASK) |
| 111 | |
| 112 | |
| 113 | /** |
| 114 | * NORMALIZE_EVENT_POINTER() - |
| 115 | * |
| 116 | * This macro will normalize the completion queue event entry so its value can |
| 117 | * be used as an index. |
| 118 | */ |
| 119 | #define NORMALIZE_EVENT_POINTER(x) \ |
| 120 | (\ |
| 121 | ((x) & SMU_COMPLETION_QUEUE_GET_EVENT_POINTER_MASK) \ |
| 122 | >> SMU_COMPLETION_QUEUE_GET_EVENT_POINTER_SHIFT \ |
| 123 | ) |
| 124 | |
| 125 | /** |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 126 | * NORMALIZE_GET_POINTER() - |
| 127 | * |
| 128 | * This macro will normalize the completion queue get pointer so its value can |
| 129 | * be used as an index into an array |
| 130 | */ |
| 131 | #define NORMALIZE_GET_POINTER(x) \ |
| 132 | ((x) & SMU_COMPLETION_QUEUE_GET_POINTER_MASK) |
| 133 | |
| 134 | /** |
| 135 | * NORMALIZE_GET_POINTER_CYCLE_BIT() - |
| 136 | * |
| 137 | * This macro will normalize the completion queue cycle pointer so it matches |
| 138 | * the completion queue cycle bit |
| 139 | */ |
| 140 | #define NORMALIZE_GET_POINTER_CYCLE_BIT(x) \ |
| 141 | ((SMU_CQGR_CYCLE_BIT & (x)) << (31 - SMU_COMPLETION_QUEUE_GET_CYCLE_BIT_SHIFT)) |
| 142 | |
| 143 | /** |
| 144 | * COMPLETION_QUEUE_CYCLE_BIT() - |
| 145 | * |
| 146 | * This macro will return the cycle bit of the completion queue entry |
| 147 | */ |
| 148 | #define COMPLETION_QUEUE_CYCLE_BIT(x) ((x) & 0x80000000) |
| 149 | |
Edmund Nadolski | 12ef654 | 2011-06-02 00:10:50 +0000 | [diff] [blame] | 150 | /* Init the state machine and call the state entry function (if any) */ |
| 151 | void sci_init_sm(struct sci_base_state_machine *sm, |
| 152 | const struct sci_base_state *state_table, u32 initial_state) |
| 153 | { |
| 154 | sci_state_transition_t handler; |
| 155 | |
| 156 | sm->initial_state_id = initial_state; |
| 157 | sm->previous_state_id = initial_state; |
| 158 | sm->current_state_id = initial_state; |
| 159 | sm->state_table = state_table; |
| 160 | |
| 161 | handler = sm->state_table[initial_state].enter_state; |
| 162 | if (handler) |
| 163 | handler(sm); |
| 164 | } |
| 165 | |
| 166 | /* Call the state exit fn, update the current state, call the state entry fn */ |
| 167 | void sci_change_state(struct sci_base_state_machine *sm, u32 next_state) |
| 168 | { |
| 169 | sci_state_transition_t handler; |
| 170 | |
| 171 | handler = sm->state_table[sm->current_state_id].exit_state; |
| 172 | if (handler) |
| 173 | handler(sm); |
| 174 | |
| 175 | sm->previous_state_id = sm->current_state_id; |
| 176 | sm->current_state_id = next_state; |
| 177 | |
| 178 | handler = sm->state_table[sm->current_state_id].enter_state; |
| 179 | if (handler) |
| 180 | handler(sm); |
| 181 | } |
| 182 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 183 | static bool sci_controller_completion_queue_has_entries(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 184 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 185 | u32 get_value = ihost->completion_queue_get; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 186 | u32 get_index = get_value & SMU_COMPLETION_QUEUE_GET_POINTER_MASK; |
| 187 | |
| 188 | if (NORMALIZE_GET_POINTER_CYCLE_BIT(get_value) == |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 189 | COMPLETION_QUEUE_CYCLE_BIT(ihost->completion_queue[get_index])) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 190 | return true; |
| 191 | |
| 192 | return false; |
| 193 | } |
| 194 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 195 | static bool sci_controller_isr(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 196 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 197 | if (sci_controller_completion_queue_has_entries(ihost)) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 198 | return true; |
| 199 | } else { |
| 200 | /* |
| 201 | * we have a spurious interrupt it could be that we have already |
| 202 | * emptied the completion queue from a previous interrupt */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 203 | writel(SMU_ISR_COMPLETION, &ihost->smu_registers->interrupt_status); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * There is a race in the hardware that could cause us not to be notified |
| 207 | * of an interrupt completion if we do not take this step. We will mask |
| 208 | * then unmask the interrupts so if there is another interrupt pending |
| 209 | * the clearing of the interrupt source we get the next interrupt message. */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 210 | writel(0xFF000000, &ihost->smu_registers->interrupt_mask); |
| 211 | writel(0, &ihost->smu_registers->interrupt_mask); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | return false; |
| 215 | } |
| 216 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 217 | irqreturn_t isci_msix_isr(int vec, void *data) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 218 | { |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 219 | struct isci_host *ihost = data; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 220 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 221 | if (sci_controller_isr(ihost)) |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 222 | tasklet_schedule(&ihost->completion_tasklet); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 223 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 224 | return IRQ_HANDLED; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 227 | static bool sci_controller_error_isr(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 228 | { |
| 229 | u32 interrupt_status; |
| 230 | |
| 231 | interrupt_status = |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 232 | readl(&ihost->smu_registers->interrupt_status); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 233 | interrupt_status &= (SMU_ISR_QUEUE_ERROR | SMU_ISR_QUEUE_SUSPEND); |
| 234 | |
| 235 | if (interrupt_status != 0) { |
| 236 | /* |
| 237 | * There is an error interrupt pending so let it through and handle |
| 238 | * in the callback */ |
| 239 | return true; |
| 240 | } |
| 241 | |
| 242 | /* |
| 243 | * There is a race in the hardware that could cause us not to be notified |
| 244 | * of an interrupt completion if we do not take this step. We will mask |
| 245 | * then unmask the error interrupts so if there was another interrupt |
| 246 | * pending we will be notified. |
| 247 | * Could we write the value of (SMU_ISR_QUEUE_ERROR | SMU_ISR_QUEUE_SUSPEND)? */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 248 | writel(0xff, &ihost->smu_registers->interrupt_mask); |
| 249 | writel(0, &ihost->smu_registers->interrupt_mask); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 250 | |
| 251 | return false; |
| 252 | } |
| 253 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 254 | static void sci_controller_task_completion(struct isci_host *ihost, u32 ent) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 255 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 256 | u32 index = SCU_GET_COMPLETION_INDEX(ent); |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 257 | struct isci_request *ireq = ihost->reqs[index]; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 258 | |
| 259 | /* Make sure that we really want to process this IO request */ |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 260 | if (test_bit(IREQ_ACTIVE, &ireq->flags) && |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 261 | ireq->io_tag != SCI_CONTROLLER_INVALID_IO_TAG && |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 262 | ISCI_TAG_SEQ(ireq->io_tag) == ihost->io_request_sequence[index]) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 263 | /* Yep this is a valid io request pass it along to the |
| 264 | * io request handler |
| 265 | */ |
| 266 | sci_io_request_tc_completion(ireq, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 269 | static void sci_controller_sdma_completion(struct isci_host *ihost, u32 ent) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 270 | { |
| 271 | u32 index; |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 272 | struct isci_request *ireq; |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 273 | struct isci_remote_device *idev; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 274 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 275 | index = SCU_GET_COMPLETION_INDEX(ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 276 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 277 | switch (scu_get_command_request_type(ent)) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 278 | case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC: |
| 279 | case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_TC: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 280 | ireq = ihost->reqs[index]; |
| 281 | dev_warn(&ihost->pdev->dev, "%s: %x for io request %p\n", |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 282 | __func__, ent, ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 283 | /* @todo For a post TC operation we need to fail the IO |
| 284 | * request |
| 285 | */ |
| 286 | break; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 287 | case SCU_CONTEXT_COMMAND_REQUEST_TYPE_DUMP_RNC: |
| 288 | case SCU_CONTEXT_COMMAND_REQUEST_TYPE_OTHER_RNC: |
| 289 | case SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_RNC: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 290 | idev = ihost->device_table[index]; |
| 291 | dev_warn(&ihost->pdev->dev, "%s: %x for device %p\n", |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 292 | __func__, ent, idev); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 293 | /* @todo For a port RNC operation we need to fail the |
| 294 | * device |
| 295 | */ |
| 296 | break; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 297 | default: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 298 | dev_warn(&ihost->pdev->dev, "%s: unknown completion type %x\n", |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 299 | __func__, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 300 | break; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 304 | static void sci_controller_unsolicited_frame(struct isci_host *ihost, u32 ent) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 305 | { |
| 306 | u32 index; |
| 307 | u32 frame_index; |
| 308 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 309 | struct scu_unsolicited_frame_header *frame_header; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 310 | struct isci_phy *iphy; |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 311 | struct isci_remote_device *idev; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 312 | |
| 313 | enum sci_status result = SCI_FAILURE; |
| 314 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 315 | frame_index = SCU_GET_FRAME_INDEX(ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 316 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 317 | frame_header = ihost->uf_control.buffers.array[frame_index].header; |
| 318 | ihost->uf_control.buffers.array[frame_index].state = UNSOLICITED_FRAME_IN_USE; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 319 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 320 | if (SCU_GET_FRAME_ERROR(ent)) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 321 | /* |
| 322 | * / @todo If the IAF frame or SIGNATURE FIS frame has an error will |
| 323 | * / this cause a problem? We expect the phy initialization will |
| 324 | * / fail if there is an error in the frame. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 325 | sci_controller_release_frame(ihost, frame_index); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 326 | return; |
| 327 | } |
| 328 | |
| 329 | if (frame_header->is_address_frame) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 330 | index = SCU_GET_PROTOCOL_ENGINE_INDEX(ent); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 331 | iphy = &ihost->phys[index]; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 332 | result = sci_phy_frame_handler(iphy, frame_index); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 333 | } else { |
| 334 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 335 | index = SCU_GET_COMPLETION_INDEX(ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 336 | |
| 337 | if (index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) { |
| 338 | /* |
| 339 | * This is a signature fis or a frame from a direct attached SATA |
| 340 | * device that has not yet been created. In either case forwared |
| 341 | * the frame to the PE and let it take care of the frame data. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 342 | index = SCU_GET_PROTOCOL_ENGINE_INDEX(ent); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 343 | iphy = &ihost->phys[index]; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 344 | result = sci_phy_frame_handler(iphy, frame_index); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 345 | } else { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 346 | if (index < ihost->remote_node_entries) |
| 347 | idev = ihost->device_table[index]; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 348 | else |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 349 | idev = NULL; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 350 | |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 351 | if (idev != NULL) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 352 | result = sci_remote_device_frame_handler(idev, frame_index); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 353 | else |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 354 | sci_controller_release_frame(ihost, frame_index); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | |
| 358 | if (result != SCI_SUCCESS) { |
| 359 | /* |
| 360 | * / @todo Is there any reason to report some additional error message |
| 361 | * / when we get this failure notifiction? */ |
| 362 | } |
| 363 | } |
| 364 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 365 | static void sci_controller_event_completion(struct isci_host *ihost, u32 ent) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 366 | { |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 367 | struct isci_remote_device *idev; |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 368 | struct isci_request *ireq; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 369 | struct isci_phy *iphy; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 370 | u32 index; |
| 371 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 372 | index = SCU_GET_COMPLETION_INDEX(ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 373 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 374 | switch (scu_get_event_type(ent)) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 375 | case SCU_EVENT_TYPE_SMU_COMMAND_ERROR: |
| 376 | /* / @todo The driver did something wrong and we need to fix the condtion. */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 377 | dev_err(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 378 | "%s: SCIC Controller 0x%p received SMU command error " |
| 379 | "0x%x\n", |
| 380 | __func__, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 381 | ihost, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 382 | ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 383 | break; |
| 384 | |
| 385 | case SCU_EVENT_TYPE_SMU_PCQ_ERROR: |
| 386 | case SCU_EVENT_TYPE_SMU_ERROR: |
| 387 | case SCU_EVENT_TYPE_FATAL_MEMORY_ERROR: |
| 388 | /* |
| 389 | * / @todo This is a hardware failure and its likely that we want to |
| 390 | * / reset the controller. */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 391 | dev_err(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 392 | "%s: SCIC Controller 0x%p received fatal controller " |
| 393 | "event 0x%x\n", |
| 394 | __func__, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 395 | ihost, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 396 | ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 397 | break; |
| 398 | |
| 399 | case SCU_EVENT_TYPE_TRANSPORT_ERROR: |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 400 | ireq = ihost->reqs[index]; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 401 | sci_io_request_event_handler(ireq, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 402 | break; |
| 403 | |
| 404 | case SCU_EVENT_TYPE_PTX_SCHEDULE_EVENT: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 405 | switch (scu_get_event_specifier(ent)) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 406 | case SCU_EVENT_SPECIFIC_SMP_RESPONSE_NO_PE: |
| 407 | case SCU_EVENT_SPECIFIC_TASK_TIMEOUT: |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 408 | ireq = ihost->reqs[index]; |
| 409 | if (ireq != NULL) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 410 | sci_io_request_event_handler(ireq, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 411 | else |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 412 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 413 | "%s: SCIC Controller 0x%p received " |
| 414 | "event 0x%x for io request object " |
| 415 | "that doesnt exist.\n", |
| 416 | __func__, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 417 | ihost, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 418 | ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 419 | |
| 420 | break; |
| 421 | |
| 422 | case SCU_EVENT_SPECIFIC_IT_NEXUS_TIMEOUT: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 423 | idev = ihost->device_table[index]; |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 424 | if (idev != NULL) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 425 | sci_remote_device_event_handler(idev, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 426 | else |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 427 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 428 | "%s: SCIC Controller 0x%p received " |
| 429 | "event 0x%x for remote device object " |
| 430 | "that doesnt exist.\n", |
| 431 | __func__, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 432 | ihost, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 433 | ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 434 | |
| 435 | break; |
| 436 | } |
| 437 | break; |
| 438 | |
| 439 | case SCU_EVENT_TYPE_BROADCAST_CHANGE: |
| 440 | /* |
| 441 | * direct the broadcast change event to the phy first and then let |
| 442 | * the phy redirect the broadcast change to the port object */ |
| 443 | case SCU_EVENT_TYPE_ERR_CNT_EVENT: |
| 444 | /* |
| 445 | * direct error counter event to the phy object since that is where |
| 446 | * we get the event notification. This is a type 4 event. */ |
| 447 | case SCU_EVENT_TYPE_OSSP_EVENT: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 448 | index = SCU_GET_PROTOCOL_ENGINE_INDEX(ent); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 449 | iphy = &ihost->phys[index]; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 450 | sci_phy_event_handler(iphy, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 451 | break; |
| 452 | |
| 453 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX: |
| 454 | case SCU_EVENT_TYPE_RNC_SUSPEND_TX_RX: |
| 455 | case SCU_EVENT_TYPE_RNC_OPS_MISC: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 456 | if (index < ihost->remote_node_entries) { |
| 457 | idev = ihost->device_table[index]; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 458 | |
Dan Williams | 78a6f06 | 2011-06-30 16:31:37 -0700 | [diff] [blame] | 459 | if (idev != NULL) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 460 | sci_remote_device_event_handler(idev, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 461 | } else |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 462 | dev_err(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 463 | "%s: SCIC Controller 0x%p received event 0x%x " |
| 464 | "for remote device object 0x%0x that doesnt " |
| 465 | "exist.\n", |
| 466 | __func__, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 467 | ihost, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 468 | ent, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 469 | index); |
| 470 | |
| 471 | break; |
| 472 | |
| 473 | default: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 474 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 475 | "%s: SCIC Controller received unknown event code %x\n", |
| 476 | __func__, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 477 | ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 478 | break; |
| 479 | } |
| 480 | } |
| 481 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 482 | static void sci_controller_process_completions(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 483 | { |
| 484 | u32 completion_count = 0; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 485 | u32 ent; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 486 | u32 get_index; |
| 487 | u32 get_cycle; |
Dan Williams | 994a930 | 2011-06-09 16:04:28 -0700 | [diff] [blame] | 488 | u32 event_get; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 489 | u32 event_cycle; |
| 490 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 491 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 492 | "%s: completion queue begining get:0x%08x\n", |
| 493 | __func__, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 494 | ihost->completion_queue_get); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 495 | |
| 496 | /* Get the component parts of the completion queue */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 497 | get_index = NORMALIZE_GET_POINTER(ihost->completion_queue_get); |
| 498 | get_cycle = SMU_CQGR_CYCLE_BIT & ihost->completion_queue_get; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 499 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 500 | event_get = NORMALIZE_EVENT_POINTER(ihost->completion_queue_get); |
| 501 | event_cycle = SMU_CQGR_EVENT_CYCLE_BIT & ihost->completion_queue_get; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 502 | |
| 503 | while ( |
| 504 | NORMALIZE_GET_POINTER_CYCLE_BIT(get_cycle) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 505 | == COMPLETION_QUEUE_CYCLE_BIT(ihost->completion_queue[get_index]) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 506 | ) { |
| 507 | completion_count++; |
| 508 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 509 | ent = ihost->completion_queue[get_index]; |
Dan Williams | 994a930 | 2011-06-09 16:04:28 -0700 | [diff] [blame] | 510 | |
| 511 | /* increment the get pointer and check for rollover to toggle the cycle bit */ |
| 512 | get_cycle ^= ((get_index+1) & SCU_MAX_COMPLETION_QUEUE_ENTRIES) << |
| 513 | (SMU_COMPLETION_QUEUE_GET_CYCLE_BIT_SHIFT - SCU_MAX_COMPLETION_QUEUE_SHIFT); |
| 514 | get_index = (get_index+1) & (SCU_MAX_COMPLETION_QUEUE_ENTRIES-1); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 515 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 516 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 517 | "%s: completion queue entry:0x%08x\n", |
| 518 | __func__, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 519 | ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 520 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 521 | switch (SCU_GET_COMPLETION_TYPE(ent)) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 522 | case SCU_COMPLETION_TYPE_TASK: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 523 | sci_controller_task_completion(ihost, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 524 | break; |
| 525 | |
| 526 | case SCU_COMPLETION_TYPE_SDMA: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 527 | sci_controller_sdma_completion(ihost, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 528 | break; |
| 529 | |
| 530 | case SCU_COMPLETION_TYPE_UFI: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 531 | sci_controller_unsolicited_frame(ihost, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 532 | break; |
| 533 | |
| 534 | case SCU_COMPLETION_TYPE_EVENT: |
Dan Williams | 994a930 | 2011-06-09 16:04:28 -0700 | [diff] [blame] | 535 | case SCU_COMPLETION_TYPE_NOTIFY: { |
| 536 | event_cycle ^= ((event_get+1) & SCU_MAX_EVENTS) << |
| 537 | (SMU_COMPLETION_QUEUE_GET_EVENT_CYCLE_BIT_SHIFT - SCU_MAX_EVENTS_SHIFT); |
| 538 | event_get = (event_get+1) & (SCU_MAX_EVENTS-1); |
| 539 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 540 | sci_controller_event_completion(ihost, ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 541 | break; |
Dan Williams | 994a930 | 2011-06-09 16:04:28 -0700 | [diff] [blame] | 542 | } |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 543 | default: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 544 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 545 | "%s: SCIC Controller received unknown " |
| 546 | "completion type %x\n", |
| 547 | __func__, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 548 | ent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 549 | break; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | /* Update the get register if we completed one or more entries */ |
| 554 | if (completion_count > 0) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 555 | ihost->completion_queue_get = |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 556 | SMU_CQGR_GEN_BIT(ENABLE) | |
| 557 | SMU_CQGR_GEN_BIT(EVENT_ENABLE) | |
| 558 | event_cycle | |
Dan Williams | 994a930 | 2011-06-09 16:04:28 -0700 | [diff] [blame] | 559 | SMU_CQGR_GEN_VAL(EVENT_POINTER, event_get) | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 560 | get_cycle | |
| 561 | SMU_CQGR_GEN_VAL(POINTER, get_index); |
| 562 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 563 | writel(ihost->completion_queue_get, |
| 564 | &ihost->smu_registers->completion_queue_get); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 565 | |
| 566 | } |
| 567 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 568 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 569 | "%s: completion queue ending get:0x%08x\n", |
| 570 | __func__, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 571 | ihost->completion_queue_get); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 572 | |
| 573 | } |
| 574 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 575 | static void sci_controller_error_handler(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 576 | { |
| 577 | u32 interrupt_status; |
| 578 | |
| 579 | interrupt_status = |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 580 | readl(&ihost->smu_registers->interrupt_status); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 581 | |
| 582 | if ((interrupt_status & SMU_ISR_QUEUE_SUSPEND) && |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 583 | sci_controller_completion_queue_has_entries(ihost)) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 584 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 585 | sci_controller_process_completions(ihost); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 586 | writel(SMU_ISR_QUEUE_SUSPEND, &ihost->smu_registers->interrupt_status); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 587 | } else { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 588 | dev_err(&ihost->pdev->dev, "%s: status: %#x\n", __func__, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 589 | interrupt_status); |
| 590 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 591 | sci_change_state(&ihost->sm, SCIC_FAILED); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 592 | |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | /* If we dont process any completions I am not sure that we want to do this. |
| 597 | * We are in the middle of a hardware fault and should probably be reset. |
| 598 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 599 | writel(0, &ihost->smu_registers->interrupt_mask); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 602 | irqreturn_t isci_intx_isr(int vec, void *data) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 603 | { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 604 | irqreturn_t ret = IRQ_NONE; |
Dan Williams | 31e824e | 2011-04-19 12:32:51 -0700 | [diff] [blame] | 605 | struct isci_host *ihost = data; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 606 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 607 | if (sci_controller_isr(ihost)) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 608 | writel(SMU_ISR_COMPLETION, &ihost->smu_registers->interrupt_status); |
Dan Williams | 31e824e | 2011-04-19 12:32:51 -0700 | [diff] [blame] | 609 | tasklet_schedule(&ihost->completion_tasklet); |
| 610 | ret = IRQ_HANDLED; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 611 | } else if (sci_controller_error_isr(ihost)) { |
Dan Williams | 31e824e | 2011-04-19 12:32:51 -0700 | [diff] [blame] | 612 | spin_lock(&ihost->scic_lock); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 613 | sci_controller_error_handler(ihost); |
Dan Williams | 31e824e | 2011-04-19 12:32:51 -0700 | [diff] [blame] | 614 | spin_unlock(&ihost->scic_lock); |
| 615 | ret = IRQ_HANDLED; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 616 | } |
Dan Williams | 92f4f0f | 2011-02-18 09:25:11 -0800 | [diff] [blame] | 617 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 618 | return ret; |
| 619 | } |
| 620 | |
Dan Williams | 92f4f0f | 2011-02-18 09:25:11 -0800 | [diff] [blame] | 621 | irqreturn_t isci_error_isr(int vec, void *data) |
| 622 | { |
| 623 | struct isci_host *ihost = data; |
Dan Williams | 92f4f0f | 2011-02-18 09:25:11 -0800 | [diff] [blame] | 624 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 625 | if (sci_controller_error_isr(ihost)) |
| 626 | sci_controller_error_handler(ihost); |
Dan Williams | 92f4f0f | 2011-02-18 09:25:11 -0800 | [diff] [blame] | 627 | |
| 628 | return IRQ_HANDLED; |
| 629 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 630 | |
| 631 | /** |
| 632 | * isci_host_start_complete() - This function is called by the core library, |
| 633 | * through the ISCI Module, to indicate controller start status. |
| 634 | * @isci_host: This parameter specifies the ISCI host object |
| 635 | * @completion_status: This parameter specifies the completion status from the |
| 636 | * core library. |
| 637 | * |
| 638 | */ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 639 | static void isci_host_start_complete(struct isci_host *ihost, enum sci_status completion_status) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 640 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 641 | if (completion_status != SCI_SUCCESS) |
| 642 | dev_info(&ihost->pdev->dev, |
| 643 | "controller start timed out, continuing...\n"); |
| 644 | isci_host_change_state(ihost, isci_ready); |
| 645 | clear_bit(IHOST_START_PENDING, &ihost->flags); |
| 646 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 649 | int isci_host_scan_finished(struct Scsi_Host *shost, unsigned long time) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 650 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 651 | struct isci_host *ihost = SHOST_TO_SAS_HA(shost)->lldd_ha; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 652 | |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 653 | if (test_bit(IHOST_START_PENDING, &ihost->flags)) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 654 | return 0; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 655 | |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 656 | /* todo: use sas_flush_discovery once it is upstream */ |
| 657 | scsi_flush_work(shost); |
| 658 | |
| 659 | scsi_flush_work(shost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 660 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 661 | dev_dbg(&ihost->pdev->dev, |
| 662 | "%s: ihost->status = %d, time = %ld\n", |
| 663 | __func__, isci_host_get_state(ihost), time); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 664 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 665 | return 1; |
| 666 | |
| 667 | } |
| 668 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 669 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 670 | * sci_controller_get_suggested_start_timeout() - This method returns the |
| 671 | * suggested sci_controller_start() timeout amount. The user is free to |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 672 | * use any timeout value, but this method provides the suggested minimum |
| 673 | * start timeout value. The returned value is based upon empirical |
| 674 | * information determined as a result of interoperability testing. |
| 675 | * @controller: the handle to the controller object for which to return the |
| 676 | * suggested start timeout. |
| 677 | * |
| 678 | * This method returns the number of milliseconds for the suggested start |
| 679 | * operation timeout. |
| 680 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 681 | static u32 sci_controller_get_suggested_start_timeout(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 682 | { |
| 683 | /* Validate the user supplied parameters. */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 684 | if (!ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 685 | return 0; |
| 686 | |
| 687 | /* |
| 688 | * The suggested minimum timeout value for a controller start operation: |
| 689 | * |
| 690 | * Signature FIS Timeout |
| 691 | * + Phy Start Timeout |
| 692 | * + Number of Phy Spin Up Intervals |
| 693 | * --------------------------------- |
| 694 | * Number of milliseconds for the controller start operation. |
| 695 | * |
| 696 | * NOTE: The number of phy spin up intervals will be equivalent |
| 697 | * to the number of phys divided by the number phys allowed |
| 698 | * per interval - 1 (once OEM parameters are supported). |
| 699 | * Currently we assume only 1 phy per interval. */ |
| 700 | |
| 701 | return SCIC_SDS_SIGNATURE_FIS_TIMEOUT |
| 702 | + SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT |
| 703 | + ((SCI_MAX_PHYS - 1) * SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL); |
| 704 | } |
| 705 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 706 | static void sci_controller_enable_interrupts(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 707 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 708 | BUG_ON(ihost->smu_registers == NULL); |
| 709 | writel(0, &ihost->smu_registers->interrupt_mask); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 712 | void sci_controller_disable_interrupts(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 713 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 714 | BUG_ON(ihost->smu_registers == NULL); |
| 715 | writel(0xffffffff, &ihost->smu_registers->interrupt_mask); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 718 | static void sci_controller_enable_port_task_scheduler(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 719 | { |
| 720 | u32 port_task_scheduler_value; |
| 721 | |
| 722 | port_task_scheduler_value = |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 723 | readl(&ihost->scu_registers->peg0.ptsg.control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 724 | port_task_scheduler_value |= |
| 725 | (SCU_PTSGCR_GEN_BIT(ETM_ENABLE) | |
| 726 | SCU_PTSGCR_GEN_BIT(PTSG_ENABLE)); |
| 727 | writel(port_task_scheduler_value, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 728 | &ihost->scu_registers->peg0.ptsg.control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 731 | static void sci_controller_assign_task_entries(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 732 | { |
| 733 | u32 task_assignment; |
| 734 | |
| 735 | /* |
| 736 | * Assign all the TCs to function 0 |
| 737 | * TODO: Do we actually need to read this register to write it back? |
| 738 | */ |
| 739 | |
| 740 | task_assignment = |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 741 | readl(&ihost->smu_registers->task_context_assignment[0]); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 742 | |
| 743 | task_assignment |= (SMU_TCA_GEN_VAL(STARTING, 0)) | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 744 | (SMU_TCA_GEN_VAL(ENDING, ihost->task_context_entries - 1)) | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 745 | (SMU_TCA_GEN_BIT(RANGE_CHECK_ENABLE)); |
| 746 | |
| 747 | writel(task_assignment, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 748 | &ihost->smu_registers->task_context_assignment[0]); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 749 | |
| 750 | } |
| 751 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 752 | static void sci_controller_initialize_completion_queue(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 753 | { |
| 754 | u32 index; |
| 755 | u32 completion_queue_control_value; |
| 756 | u32 completion_queue_get_value; |
| 757 | u32 completion_queue_put_value; |
| 758 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 759 | ihost->completion_queue_get = 0; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 760 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 761 | completion_queue_control_value = |
| 762 | (SMU_CQC_QUEUE_LIMIT_SET(SCU_MAX_COMPLETION_QUEUE_ENTRIES - 1) | |
| 763 | SMU_CQC_EVENT_LIMIT_SET(SCU_MAX_EVENTS - 1)); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 764 | |
| 765 | writel(completion_queue_control_value, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 766 | &ihost->smu_registers->completion_queue_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 767 | |
| 768 | |
| 769 | /* Set the completion queue get pointer and enable the queue */ |
| 770 | completion_queue_get_value = ( |
| 771 | (SMU_CQGR_GEN_VAL(POINTER, 0)) |
| 772 | | (SMU_CQGR_GEN_VAL(EVENT_POINTER, 0)) |
| 773 | | (SMU_CQGR_GEN_BIT(ENABLE)) |
| 774 | | (SMU_CQGR_GEN_BIT(EVENT_ENABLE)) |
| 775 | ); |
| 776 | |
| 777 | writel(completion_queue_get_value, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 778 | &ihost->smu_registers->completion_queue_get); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 779 | |
| 780 | /* Set the completion queue put pointer */ |
| 781 | completion_queue_put_value = ( |
| 782 | (SMU_CQPR_GEN_VAL(POINTER, 0)) |
| 783 | | (SMU_CQPR_GEN_VAL(EVENT_POINTER, 0)) |
| 784 | ); |
| 785 | |
| 786 | writel(completion_queue_put_value, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 787 | &ihost->smu_registers->completion_queue_put); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 788 | |
| 789 | /* Initialize the cycle bit of the completion queue entries */ |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 790 | for (index = 0; index < SCU_MAX_COMPLETION_QUEUE_ENTRIES; index++) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 791 | /* |
| 792 | * If get.cycle_bit != completion_queue.cycle_bit |
| 793 | * its not a valid completion queue entry |
| 794 | * so at system start all entries are invalid */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 795 | ihost->completion_queue[index] = 0x80000000; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 799 | static void sci_controller_initialize_unsolicited_frame_queue(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 800 | { |
| 801 | u32 frame_queue_control_value; |
| 802 | u32 frame_queue_get_value; |
| 803 | u32 frame_queue_put_value; |
| 804 | |
| 805 | /* Write the queue size */ |
| 806 | frame_queue_control_value = |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 807 | SCU_UFQC_GEN_VAL(QUEUE_SIZE, SCU_MAX_UNSOLICITED_FRAMES); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 808 | |
| 809 | writel(frame_queue_control_value, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 810 | &ihost->scu_registers->sdma.unsolicited_frame_queue_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 811 | |
| 812 | /* Setup the get pointer for the unsolicited frame queue */ |
| 813 | frame_queue_get_value = ( |
| 814 | SCU_UFQGP_GEN_VAL(POINTER, 0) |
| 815 | | SCU_UFQGP_GEN_BIT(ENABLE_BIT) |
| 816 | ); |
| 817 | |
| 818 | writel(frame_queue_get_value, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 819 | &ihost->scu_registers->sdma.unsolicited_frame_get_pointer); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 820 | /* Setup the put pointer for the unsolicited frame queue */ |
| 821 | frame_queue_put_value = SCU_UFQPP_GEN_VAL(POINTER, 0); |
| 822 | writel(frame_queue_put_value, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 823 | &ihost->scu_registers->sdma.unsolicited_frame_put_pointer); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 826 | static void sci_controller_transition_to_ready(struct isci_host *ihost, enum sci_status status) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 827 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 828 | if (ihost->sm.current_state_id == SCIC_STARTING) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 829 | /* |
| 830 | * We move into the ready state, because some of the phys/ports |
| 831 | * may be up and operational. |
| 832 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 833 | sci_change_state(&ihost->sm, SCIC_READY); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 834 | |
| 835 | isci_host_start_complete(ihost, status); |
| 836 | } |
| 837 | } |
| 838 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 839 | static bool is_phy_starting(struct isci_phy *iphy) |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 840 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 841 | enum sci_phy_states state; |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 842 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 843 | state = iphy->sm.current_state_id; |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 844 | switch (state) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 845 | case SCI_PHY_STARTING: |
| 846 | case SCI_PHY_SUB_INITIAL: |
| 847 | case SCI_PHY_SUB_AWAIT_SAS_SPEED_EN: |
| 848 | case SCI_PHY_SUB_AWAIT_IAF_UF: |
| 849 | case SCI_PHY_SUB_AWAIT_SAS_POWER: |
| 850 | case SCI_PHY_SUB_AWAIT_SATA_POWER: |
| 851 | case SCI_PHY_SUB_AWAIT_SATA_PHY_EN: |
| 852 | case SCI_PHY_SUB_AWAIT_SATA_SPEED_EN: |
| 853 | case SCI_PHY_SUB_AWAIT_SIG_FIS_UF: |
| 854 | case SCI_PHY_SUB_FINAL: |
Adam Gruchala | 4a33c52 | 2011-05-10 23:54:23 +0000 | [diff] [blame] | 855 | return true; |
| 856 | default: |
| 857 | return false; |
| 858 | } |
| 859 | } |
| 860 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 861 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 862 | * sci_controller_start_next_phy - start phy |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 863 | * @scic: controller |
| 864 | * |
| 865 | * If all the phys have been started, then attempt to transition the |
| 866 | * controller to the READY state and inform the user |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 867 | * (sci_cb_controller_start_complete()). |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 868 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 869 | static enum sci_status sci_controller_start_next_phy(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 870 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 871 | struct sci_oem_params *oem = &ihost->oem_parameters; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 872 | struct isci_phy *iphy; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 873 | enum sci_status status; |
| 874 | |
| 875 | status = SCI_SUCCESS; |
| 876 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 877 | if (ihost->phy_startup_timer_pending) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 878 | return status; |
| 879 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 880 | if (ihost->next_phy_to_start >= SCI_MAX_PHYS) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 881 | bool is_controller_start_complete = true; |
| 882 | u32 state; |
| 883 | u8 index; |
| 884 | |
| 885 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 886 | iphy = &ihost->phys[index]; |
| 887 | state = iphy->sm.current_state_id; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 888 | |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 889 | if (!phy_get_non_dummy_port(iphy)) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 890 | continue; |
| 891 | |
| 892 | /* The controller start operation is complete iff: |
| 893 | * - all links have been given an opportunity to start |
| 894 | * - have no indication of a connected device |
| 895 | * - have an indication of a connected device and it has |
| 896 | * finished the link training process. |
| 897 | */ |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 898 | if ((iphy->is_in_link_training == false && state == SCI_PHY_INITIAL) || |
| 899 | (iphy->is_in_link_training == false && state == SCI_PHY_STOPPED) || |
| 900 | (iphy->is_in_link_training == true && is_phy_starting(iphy))) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 901 | is_controller_start_complete = false; |
| 902 | break; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | /* |
| 907 | * The controller has successfully finished the start process. |
| 908 | * Inform the SCI Core user and transition to the READY state. */ |
| 909 | if (is_controller_start_complete == true) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 910 | sci_controller_transition_to_ready(ihost, SCI_SUCCESS); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 911 | sci_del_timer(&ihost->phy_timer); |
| 912 | ihost->phy_startup_timer_pending = false; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 913 | } |
| 914 | } else { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 915 | iphy = &ihost->phys[ihost->next_phy_to_start]; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 916 | |
| 917 | if (oem->controller.mode_type == SCIC_PORT_MANUAL_CONFIGURATION_MODE) { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 918 | if (phy_get_non_dummy_port(iphy) == NULL) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 919 | ihost->next_phy_to_start++; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 920 | |
| 921 | /* Caution recursion ahead be forwarned |
| 922 | * |
| 923 | * The PHY was never added to a PORT in MPC mode |
| 924 | * so start the next phy in sequence This phy |
| 925 | * will never go link up and will not draw power |
| 926 | * the OEM parameters either configured the phy |
| 927 | * incorrectly for the PORT or it was never |
| 928 | * assigned to a PORT |
| 929 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 930 | return sci_controller_start_next_phy(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 934 | status = sci_phy_start(iphy); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 935 | |
| 936 | if (status == SCI_SUCCESS) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 937 | sci_mod_timer(&ihost->phy_timer, |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 938 | SCIC_SDS_CONTROLLER_PHY_START_TIMEOUT); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 939 | ihost->phy_startup_timer_pending = true; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 940 | } else { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 941 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 942 | "%s: Controller stop operation failed " |
| 943 | "to stop phy %d because of status " |
| 944 | "%d.\n", |
| 945 | __func__, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 946 | ihost->phys[ihost->next_phy_to_start].phy_index, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 947 | status); |
| 948 | } |
| 949 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 950 | ihost->next_phy_to_start++; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | return status; |
| 954 | } |
| 955 | |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 956 | static void phy_startup_timeout(unsigned long data) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 957 | { |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 958 | struct sci_timer *tmr = (struct sci_timer *)data; |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 959 | struct isci_host *ihost = container_of(tmr, typeof(*ihost), phy_timer); |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 960 | unsigned long flags; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 961 | enum sci_status status; |
| 962 | |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 963 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 964 | |
| 965 | if (tmr->cancel) |
| 966 | goto done; |
| 967 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 968 | ihost->phy_startup_timer_pending = false; |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 969 | |
| 970 | do { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 971 | status = sci_controller_start_next_phy(ihost); |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 972 | } while (status != SCI_SUCCESS); |
| 973 | |
| 974 | done: |
| 975 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Dan Williams | ac668c6 | 2011-06-07 18:50:55 -0700 | [diff] [blame] | 978 | static u16 isci_tci_active(struct isci_host *ihost) |
| 979 | { |
| 980 | return CIRC_CNT(ihost->tci_head, ihost->tci_tail, SCI_MAX_IO_REQUESTS); |
| 981 | } |
| 982 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 983 | static enum sci_status sci_controller_start(struct isci_host *ihost, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 984 | u32 timeout) |
| 985 | { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 986 | enum sci_status result; |
| 987 | u16 index; |
| 988 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 989 | if (ihost->sm.current_state_id != SCIC_INITIALIZED) { |
| 990 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 991 | "SCIC Controller start operation requested in " |
| 992 | "invalid state\n"); |
| 993 | return SCI_FAILURE_INVALID_STATE; |
| 994 | } |
| 995 | |
| 996 | /* Build the TCi free pool */ |
Dan Williams | ac668c6 | 2011-06-07 18:50:55 -0700 | [diff] [blame] | 997 | BUILD_BUG_ON(SCI_MAX_IO_REQUESTS > 1 << sizeof(ihost->tci_pool[0]) * 8); |
| 998 | ihost->tci_head = 0; |
| 999 | ihost->tci_tail = 0; |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1000 | for (index = 0; index < ihost->task_context_entries; index++) |
Dan Williams | ac668c6 | 2011-06-07 18:50:55 -0700 | [diff] [blame] | 1001 | isci_tci_free(ihost, index); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1002 | |
| 1003 | /* Build the RNi free pool */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1004 | sci_remote_node_table_initialize(&ihost->available_remote_nodes, |
| 1005 | ihost->remote_node_entries); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1006 | |
| 1007 | /* |
| 1008 | * Before anything else lets make sure we will not be |
| 1009 | * interrupted by the hardware. |
| 1010 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1011 | sci_controller_disable_interrupts(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1012 | |
| 1013 | /* Enable the port task scheduler */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1014 | sci_controller_enable_port_task_scheduler(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1015 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1016 | /* Assign all the task entries to ihost physical function */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1017 | sci_controller_assign_task_entries(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1018 | |
| 1019 | /* Now initialize the completion queue */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1020 | sci_controller_initialize_completion_queue(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1021 | |
| 1022 | /* Initialize the unsolicited frame queue for use */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1023 | sci_controller_initialize_unsolicited_frame_queue(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1024 | |
| 1025 | /* Start all of the ports on this controller */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1026 | for (index = 0; index < ihost->logical_port_entries; index++) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1027 | struct isci_port *iport = &ihost->ports[index]; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1028 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1029 | result = sci_port_start(iport); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1030 | if (result) |
| 1031 | return result; |
| 1032 | } |
| 1033 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1034 | sci_controller_start_next_phy(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1035 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1036 | sci_mod_timer(&ihost->timer, timeout); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1037 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1038 | sci_change_state(&ihost->sm, SCIC_STARTING); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1039 | |
| 1040 | return SCI_SUCCESS; |
| 1041 | } |
| 1042 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1043 | void isci_host_scan_start(struct Scsi_Host *shost) |
| 1044 | { |
Dan Williams | 4393aa4 | 2011-03-31 13:10:44 -0700 | [diff] [blame] | 1045 | struct isci_host *ihost = SHOST_TO_SAS_HA(shost)->lldd_ha; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1046 | unsigned long tmo = sci_controller_get_suggested_start_timeout(ihost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1047 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 1048 | set_bit(IHOST_START_PENDING, &ihost->flags); |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 1049 | |
| 1050 | spin_lock_irq(&ihost->scic_lock); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1051 | sci_controller_start(ihost, tmo); |
| 1052 | sci_controller_enable_interrupts(ihost); |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 1053 | spin_unlock_irq(&ihost->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1056 | static void isci_host_stop_complete(struct isci_host *ihost, enum sci_status completion_status) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1057 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 1058 | isci_host_change_state(ihost, isci_stopped); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1059 | sci_controller_disable_interrupts(ihost); |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 1060 | clear_bit(IHOST_STOP_PENDING, &ihost->flags); |
| 1061 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1064 | static void sci_controller_completion_handler(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1065 | { |
| 1066 | /* Empty out the completion queue */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1067 | if (sci_controller_completion_queue_has_entries(ihost)) |
| 1068 | sci_controller_process_completions(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1069 | |
| 1070 | /* Clear the interrupt and enable all interrupts again */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1071 | writel(SMU_ISR_COMPLETION, &ihost->smu_registers->interrupt_status); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1072 | /* Could we write the value of SMU_ISR_COMPLETION? */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1073 | writel(0xFF000000, &ihost->smu_registers->interrupt_mask); |
| 1074 | writel(0, &ihost->smu_registers->interrupt_mask); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1077 | /** |
| 1078 | * isci_host_completion_routine() - This function is the delayed service |
| 1079 | * routine that calls the sci core library's completion handler. It's |
| 1080 | * scheduled as a tasklet from the interrupt service routine when interrupts |
| 1081 | * in use, or set as the timeout function in polled mode. |
| 1082 | * @data: This parameter specifies the ISCI host object |
| 1083 | * |
| 1084 | */ |
| 1085 | static void isci_host_completion_routine(unsigned long data) |
| 1086 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1087 | struct isci_host *ihost = (struct isci_host *)data; |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1088 | struct list_head completed_request_list; |
| 1089 | struct list_head errored_request_list; |
| 1090 | struct list_head *current_position; |
| 1091 | struct list_head *next_position; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1092 | struct isci_request *request; |
| 1093 | struct isci_request *next_request; |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1094 | struct sas_task *task; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1095 | |
| 1096 | INIT_LIST_HEAD(&completed_request_list); |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1097 | INIT_LIST_HEAD(&errored_request_list); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1098 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1099 | spin_lock_irq(&ihost->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1100 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1101 | sci_controller_completion_handler(ihost); |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 1102 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1103 | /* Take the lists of completed I/Os from the host. */ |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1104 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1105 | list_splice_init(&ihost->requests_to_complete, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1106 | &completed_request_list); |
| 1107 | |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1108 | /* Take the list of errored I/Os from the host. */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1109 | list_splice_init(&ihost->requests_to_errorback, |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1110 | &errored_request_list); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1111 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1112 | spin_unlock_irq(&ihost->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1113 | |
| 1114 | /* Process any completions in the lists. */ |
| 1115 | list_for_each_safe(current_position, next_position, |
| 1116 | &completed_request_list) { |
| 1117 | |
| 1118 | request = list_entry(current_position, struct isci_request, |
| 1119 | completed_node); |
| 1120 | task = isci_request_access_task(request); |
| 1121 | |
| 1122 | /* Normal notification (task_done) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1123 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1124 | "%s: Normal - request/task = %p/%p\n", |
| 1125 | __func__, |
| 1126 | request, |
| 1127 | task); |
| 1128 | |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1129 | /* Return the task to libsas */ |
| 1130 | if (task != NULL) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1131 | |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1132 | task->lldd_task = NULL; |
| 1133 | if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) { |
| 1134 | |
| 1135 | /* If the task is already in the abort path, |
| 1136 | * the task_done callback cannot be called. |
| 1137 | */ |
| 1138 | task->task_done(task); |
| 1139 | } |
| 1140 | } |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 1141 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1142 | spin_lock_irq(&ihost->scic_lock); |
| 1143 | isci_free_tag(ihost, request->io_tag); |
| 1144 | spin_unlock_irq(&ihost->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1145 | } |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1146 | list_for_each_entry_safe(request, next_request, &errored_request_list, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1147 | completed_node) { |
| 1148 | |
| 1149 | task = isci_request_access_task(request); |
| 1150 | |
| 1151 | /* Use sas_task_abort */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1152 | dev_warn(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1153 | "%s: Error - request/task = %p/%p\n", |
| 1154 | __func__, |
| 1155 | request, |
| 1156 | task); |
| 1157 | |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1158 | if (task != NULL) { |
| 1159 | |
| 1160 | /* Put the task into the abort path if it's not there |
| 1161 | * already. |
| 1162 | */ |
| 1163 | if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) |
| 1164 | sas_task_abort(task); |
| 1165 | |
| 1166 | } else { |
| 1167 | /* This is a case where the request has completed with a |
| 1168 | * status such that it needed further target servicing, |
| 1169 | * but the sas_task reference has already been removed |
| 1170 | * from the request. Since it was errored, it was not |
| 1171 | * being aborted, so there is nothing to do except free |
| 1172 | * it. |
| 1173 | */ |
| 1174 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1175 | spin_lock_irq(&ihost->scic_lock); |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1176 | /* Remove the request from the remote device's list |
| 1177 | * of pending requests. |
| 1178 | */ |
| 1179 | list_del_init(&request->dev_node); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1180 | isci_free_tag(ihost, request->io_tag); |
| 1181 | spin_unlock_irq(&ihost->scic_lock); |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 1182 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | } |
| 1186 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1187 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1188 | * sci_controller_stop() - This method will stop an individual controller |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1189 | * object.This method will invoke the associated user callback upon |
| 1190 | * completion. The completion callback is called when the following |
| 1191 | * conditions are met: -# the method return status is SCI_SUCCESS. -# the |
| 1192 | * controller has been quiesced. This method will ensure that all IO |
| 1193 | * requests are quiesced, phys are stopped, and all additional operation by |
| 1194 | * the hardware is halted. |
| 1195 | * @controller: the handle to the controller object to stop. |
| 1196 | * @timeout: This parameter specifies the number of milliseconds in which the |
| 1197 | * stop operation should complete. |
| 1198 | * |
| 1199 | * The controller must be in the STARTED or STOPPED state. Indicate if the |
| 1200 | * controller stop method succeeded or failed in some way. SCI_SUCCESS if the |
| 1201 | * stop operation successfully began. SCI_WARNING_ALREADY_IN_STATE if the |
| 1202 | * controller is already in the STOPPED state. SCI_FAILURE_INVALID_STATE if the |
| 1203 | * controller is not either in the STARTED or STOPPED states. |
| 1204 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1205 | static enum sci_status sci_controller_stop(struct isci_host *ihost, u32 timeout) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1206 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1207 | if (ihost->sm.current_state_id != SCIC_READY) { |
| 1208 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1209 | "SCIC Controller stop operation requested in " |
| 1210 | "invalid state\n"); |
| 1211 | return SCI_FAILURE_INVALID_STATE; |
| 1212 | } |
| 1213 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1214 | sci_mod_timer(&ihost->timer, timeout); |
| 1215 | sci_change_state(&ihost->sm, SCIC_STOPPING); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1216 | return SCI_SUCCESS; |
| 1217 | } |
| 1218 | |
| 1219 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1220 | * sci_controller_reset() - This method will reset the supplied core |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1221 | * controller regardless of the state of said controller. This operation is |
| 1222 | * considered destructive. In other words, all current operations are wiped |
| 1223 | * out. No IO completions for outstanding devices occur. Outstanding IO |
| 1224 | * requests are not aborted or completed at the actual remote device. |
| 1225 | * @controller: the handle to the controller object to reset. |
| 1226 | * |
| 1227 | * Indicate if the controller reset method succeeded or failed in some way. |
| 1228 | * SCI_SUCCESS if the reset operation successfully started. SCI_FATAL_ERROR if |
| 1229 | * the controller reset operation is unable to complete. |
| 1230 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1231 | static enum sci_status sci_controller_reset(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1232 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1233 | switch (ihost->sm.current_state_id) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1234 | case SCIC_RESET: |
| 1235 | case SCIC_READY: |
| 1236 | case SCIC_STOPPED: |
| 1237 | case SCIC_FAILED: |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1238 | /* |
| 1239 | * The reset operation is not a graceful cleanup, just |
| 1240 | * perform the state transition. |
| 1241 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1242 | sci_change_state(&ihost->sm, SCIC_RESETTING); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1243 | return SCI_SUCCESS; |
| 1244 | default: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1245 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1246 | "SCIC Controller reset operation requested in " |
| 1247 | "invalid state\n"); |
| 1248 | return SCI_FAILURE_INVALID_STATE; |
| 1249 | } |
| 1250 | } |
| 1251 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 1252 | void isci_host_deinit(struct isci_host *ihost) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1253 | { |
| 1254 | int i; |
| 1255 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 1256 | isci_host_change_state(ihost, isci_stopping); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1257 | for (i = 0; i < SCI_MAX_PORTS; i++) { |
Dan Williams | e531381 | 2011-05-07 10:11:43 -0700 | [diff] [blame] | 1258 | struct isci_port *iport = &ihost->ports[i]; |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 1259 | struct isci_remote_device *idev, *d; |
| 1260 | |
Dan Williams | e531381 | 2011-05-07 10:11:43 -0700 | [diff] [blame] | 1261 | list_for_each_entry_safe(idev, d, &iport->remote_dev_list, node) { |
Dan Williams | 209fae1 | 2011-06-13 17:39:44 -0700 | [diff] [blame] | 1262 | if (test_bit(IDEV_ALLOCATED, &idev->flags)) |
| 1263 | isci_remote_device_stop(ihost, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 1267 | set_bit(IHOST_STOP_PENDING, &ihost->flags); |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 1268 | |
| 1269 | spin_lock_irq(&ihost->scic_lock); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1270 | sci_controller_stop(ihost, SCIC_CONTROLLER_STOP_TIMEOUT); |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 1271 | spin_unlock_irq(&ihost->scic_lock); |
| 1272 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 1273 | wait_for_stop(ihost); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1274 | sci_controller_reset(ihost); |
Edmund Nadolski | 5553ba2 | 2011-05-19 11:59:10 +0000 | [diff] [blame] | 1275 | |
| 1276 | /* Cancel any/all outstanding port timers */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1277 | for (i = 0; i < ihost->logical_port_entries; i++) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1278 | struct isci_port *iport = &ihost->ports[i]; |
| 1279 | del_timer_sync(&iport->timer.timer); |
Edmund Nadolski | 5553ba2 | 2011-05-19 11:59:10 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Edmund Nadolski | a628d47 | 2011-05-19 11:59:36 +0000 | [diff] [blame] | 1282 | /* Cancel any/all outstanding phy timers */ |
| 1283 | for (i = 0; i < SCI_MAX_PHYS; i++) { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1284 | struct isci_phy *iphy = &ihost->phys[i]; |
| 1285 | del_timer_sync(&iphy->sata_timer.timer); |
Edmund Nadolski | a628d47 | 2011-05-19 11:59:36 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1288 | del_timer_sync(&ihost->port_agent.timer.timer); |
Edmund Nadolski | ac0eeb4 | 2011-05-19 20:00:51 -0700 | [diff] [blame] | 1289 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1290 | del_timer_sync(&ihost->power_control.timer.timer); |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1291 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1292 | del_timer_sync(&ihost->timer.timer); |
Edmund Nadolski | 6cb5853 | 2011-05-19 11:59:56 +0000 | [diff] [blame] | 1293 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1294 | del_timer_sync(&ihost->phy_timer.timer); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1297 | static void __iomem *scu_base(struct isci_host *isci_host) |
| 1298 | { |
| 1299 | struct pci_dev *pdev = isci_host->pdev; |
| 1300 | int id = isci_host->id; |
| 1301 | |
| 1302 | return pcim_iomap_table(pdev)[SCI_SCU_BAR * 2] + SCI_SCU_BAR_SIZE * id; |
| 1303 | } |
| 1304 | |
| 1305 | static void __iomem *smu_base(struct isci_host *isci_host) |
| 1306 | { |
| 1307 | struct pci_dev *pdev = isci_host->pdev; |
| 1308 | int id = isci_host->id; |
| 1309 | |
| 1310 | return pcim_iomap_table(pdev)[SCI_SMU_BAR * 2] + SCI_SMU_BAR_SIZE * id; |
| 1311 | } |
| 1312 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1313 | static void isci_user_parameters_get(struct sci_user_parameters *u) |
Dave Jiang | b5f18a2 | 2011-03-16 14:57:23 -0700 | [diff] [blame] | 1314 | { |
Dave Jiang | b5f18a2 | 2011-03-16 14:57:23 -0700 | [diff] [blame] | 1315 | int i; |
| 1316 | |
| 1317 | for (i = 0; i < SCI_MAX_PHYS; i++) { |
| 1318 | struct sci_phy_user_params *u_phy = &u->phys[i]; |
| 1319 | |
| 1320 | u_phy->max_speed_generation = phy_gen; |
| 1321 | |
| 1322 | /* we are not exporting these for now */ |
| 1323 | u_phy->align_insertion_frequency = 0x7f; |
| 1324 | u_phy->in_connection_align_insertion_frequency = 0xff; |
| 1325 | u_phy->notify_enable_spin_up_insertion_frequency = 0x33; |
| 1326 | } |
| 1327 | |
| 1328 | u->stp_inactivity_timeout = stp_inactive_to; |
| 1329 | u->ssp_inactivity_timeout = ssp_inactive_to; |
| 1330 | u->stp_max_occupancy_timeout = stp_max_occ_to; |
| 1331 | u->ssp_max_occupancy_timeout = ssp_max_occ_to; |
| 1332 | u->no_outbound_task_timeout = no_outbound_task_to; |
| 1333 | u->max_number_concurrent_device_spin_up = max_concurr_spinup; |
| 1334 | } |
| 1335 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1336 | static void sci_controller_initial_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1337 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1338 | struct isci_host *ihost = container_of(sm, typeof(*ihost), sm); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1339 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1340 | sci_change_state(&ihost->sm, SCIC_RESET); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1343 | static inline void sci_controller_starting_state_exit(struct sci_base_state_machine *sm) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1344 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1345 | struct isci_host *ihost = container_of(sm, typeof(*ihost), sm); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1346 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1347 | sci_del_timer(&ihost->timer); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS 853 |
| 1351 | #define INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS 1280 |
| 1352 | #define INTERRUPT_COALESCE_TIMEOUT_MAX_US 2700000 |
| 1353 | #define INTERRUPT_COALESCE_NUMBER_MAX 256 |
| 1354 | #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN 7 |
| 1355 | #define INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX 28 |
| 1356 | |
| 1357 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1358 | * sci_controller_set_interrupt_coalescence() - This method allows the user to |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1359 | * configure the interrupt coalescence. |
| 1360 | * @controller: This parameter represents the handle to the controller object |
| 1361 | * for which its interrupt coalesce register is overridden. |
| 1362 | * @coalesce_number: Used to control the number of entries in the Completion |
| 1363 | * Queue before an interrupt is generated. If the number of entries exceed |
| 1364 | * this number, an interrupt will be generated. The valid range of the input |
| 1365 | * is [0, 256]. A setting of 0 results in coalescing being disabled. |
| 1366 | * @coalesce_timeout: Timeout value in microseconds. The valid range of the |
| 1367 | * input is [0, 2700000] . A setting of 0 is allowed and results in no |
| 1368 | * interrupt coalescing timeout. |
| 1369 | * |
| 1370 | * Indicate if the user successfully set the interrupt coalesce parameters. |
| 1371 | * SCI_SUCCESS The user successfully updated the interrutp coalescence. |
| 1372 | * SCI_FAILURE_INVALID_PARAMETER_VALUE The user input value is out of range. |
| 1373 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1374 | static enum sci_status |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1375 | sci_controller_set_interrupt_coalescence(struct isci_host *ihost, |
| 1376 | u32 coalesce_number, |
| 1377 | u32 coalesce_timeout) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1378 | { |
| 1379 | u8 timeout_encode = 0; |
| 1380 | u32 min = 0; |
| 1381 | u32 max = 0; |
| 1382 | |
| 1383 | /* Check if the input parameters fall in the range. */ |
| 1384 | if (coalesce_number > INTERRUPT_COALESCE_NUMBER_MAX) |
| 1385 | return SCI_FAILURE_INVALID_PARAMETER_VALUE; |
| 1386 | |
| 1387 | /* |
| 1388 | * Defined encoding for interrupt coalescing timeout: |
| 1389 | * Value Min Max Units |
| 1390 | * ----- --- --- ----- |
| 1391 | * 0 - - Disabled |
| 1392 | * 1 13.3 20.0 ns |
| 1393 | * 2 26.7 40.0 |
| 1394 | * 3 53.3 80.0 |
| 1395 | * 4 106.7 160.0 |
| 1396 | * 5 213.3 320.0 |
| 1397 | * 6 426.7 640.0 |
| 1398 | * 7 853.3 1280.0 |
| 1399 | * 8 1.7 2.6 us |
| 1400 | * 9 3.4 5.1 |
| 1401 | * 10 6.8 10.2 |
| 1402 | * 11 13.7 20.5 |
| 1403 | * 12 27.3 41.0 |
| 1404 | * 13 54.6 81.9 |
| 1405 | * 14 109.2 163.8 |
| 1406 | * 15 218.5 327.7 |
| 1407 | * 16 436.9 655.4 |
| 1408 | * 17 873.8 1310.7 |
| 1409 | * 18 1.7 2.6 ms |
| 1410 | * 19 3.5 5.2 |
| 1411 | * 20 7.0 10.5 |
| 1412 | * 21 14.0 21.0 |
| 1413 | * 22 28.0 41.9 |
| 1414 | * 23 55.9 83.9 |
| 1415 | * 24 111.8 167.8 |
| 1416 | * 25 223.7 335.5 |
| 1417 | * 26 447.4 671.1 |
| 1418 | * 27 894.8 1342.2 |
| 1419 | * 28 1.8 2.7 s |
| 1420 | * Others Undefined */ |
| 1421 | |
| 1422 | /* |
| 1423 | * Use the table above to decide the encode of interrupt coalescing timeout |
| 1424 | * value for register writing. */ |
| 1425 | if (coalesce_timeout == 0) |
| 1426 | timeout_encode = 0; |
| 1427 | else{ |
| 1428 | /* make the timeout value in unit of (10 ns). */ |
| 1429 | coalesce_timeout = coalesce_timeout * 100; |
| 1430 | min = INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_LOWER_BOUND_NS / 10; |
| 1431 | max = INTERRUPT_COALESCE_TIMEOUT_BASE_RANGE_UPPER_BOUND_NS / 10; |
| 1432 | |
| 1433 | /* get the encode of timeout for register writing. */ |
| 1434 | for (timeout_encode = INTERRUPT_COALESCE_TIMEOUT_ENCODE_MIN; |
| 1435 | timeout_encode <= INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX; |
| 1436 | timeout_encode++) { |
| 1437 | if (min <= coalesce_timeout && max > coalesce_timeout) |
| 1438 | break; |
| 1439 | else if (coalesce_timeout >= max && coalesce_timeout < min * 2 |
| 1440 | && coalesce_timeout <= INTERRUPT_COALESCE_TIMEOUT_MAX_US * 100) { |
| 1441 | if ((coalesce_timeout - max) < (2 * min - coalesce_timeout)) |
| 1442 | break; |
| 1443 | else{ |
| 1444 | timeout_encode++; |
| 1445 | break; |
| 1446 | } |
| 1447 | } else { |
| 1448 | max = max * 2; |
| 1449 | min = min * 2; |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | if (timeout_encode == INTERRUPT_COALESCE_TIMEOUT_ENCODE_MAX + 1) |
| 1454 | /* the value is out of range. */ |
| 1455 | return SCI_FAILURE_INVALID_PARAMETER_VALUE; |
| 1456 | } |
| 1457 | |
| 1458 | writel(SMU_ICC_GEN_VAL(NUMBER, coalesce_number) | |
| 1459 | SMU_ICC_GEN_VAL(TIMER, timeout_encode), |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1460 | &ihost->smu_registers->interrupt_coalesce_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1461 | |
| 1462 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1463 | ihost->interrupt_coalesce_number = (u16)coalesce_number; |
| 1464 | ihost->interrupt_coalesce_timeout = coalesce_timeout / 100; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1465 | |
| 1466 | return SCI_SUCCESS; |
| 1467 | } |
| 1468 | |
| 1469 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1470 | static void sci_controller_ready_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1471 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1472 | struct isci_host *ihost = container_of(sm, typeof(*ihost), sm); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1473 | |
| 1474 | /* set the default interrupt coalescence number and timeout value. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1475 | sci_controller_set_interrupt_coalescence(ihost, 0x10, 250); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1478 | static void sci_controller_ready_state_exit(struct sci_base_state_machine *sm) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1479 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1480 | struct isci_host *ihost = container_of(sm, typeof(*ihost), sm); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1481 | |
| 1482 | /* disable interrupt coalescence. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1483 | sci_controller_set_interrupt_coalescence(ihost, 0, 0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1486 | static enum sci_status sci_controller_stop_phys(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1487 | { |
| 1488 | u32 index; |
| 1489 | enum sci_status status; |
| 1490 | enum sci_status phy_status; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1491 | |
| 1492 | status = SCI_SUCCESS; |
| 1493 | |
| 1494 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1495 | phy_status = sci_phy_stop(&ihost->phys[index]); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1496 | |
| 1497 | if (phy_status != SCI_SUCCESS && |
| 1498 | phy_status != SCI_FAILURE_INVALID_STATE) { |
| 1499 | status = SCI_FAILURE; |
| 1500 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1501 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1502 | "%s: Controller stop operation failed to stop " |
| 1503 | "phy %d because of status %d.\n", |
| 1504 | __func__, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1505 | ihost->phys[index].phy_index, phy_status); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | return status; |
| 1510 | } |
| 1511 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1512 | static enum sci_status sci_controller_stop_ports(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1513 | { |
| 1514 | u32 index; |
| 1515 | enum sci_status port_status; |
| 1516 | enum sci_status status = SCI_SUCCESS; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1517 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1518 | for (index = 0; index < ihost->logical_port_entries; index++) { |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1519 | struct isci_port *iport = &ihost->ports[index]; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1520 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1521 | port_status = sci_port_stop(iport); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1522 | |
| 1523 | if ((port_status != SCI_SUCCESS) && |
| 1524 | (port_status != SCI_FAILURE_INVALID_STATE)) { |
| 1525 | status = SCI_FAILURE; |
| 1526 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1527 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1528 | "%s: Controller stop operation failed to " |
| 1529 | "stop port %d because of status %d.\n", |
| 1530 | __func__, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 1531 | iport->logical_port_index, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1532 | port_status); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | return status; |
| 1537 | } |
| 1538 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1539 | static enum sci_status sci_controller_stop_devices(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1540 | { |
| 1541 | u32 index; |
| 1542 | enum sci_status status; |
| 1543 | enum sci_status device_status; |
| 1544 | |
| 1545 | status = SCI_SUCCESS; |
| 1546 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1547 | for (index = 0; index < ihost->remote_node_entries; index++) { |
| 1548 | if (ihost->device_table[index] != NULL) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1549 | /* / @todo What timeout value do we want to provide to this request? */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1550 | device_status = sci_remote_device_stop(ihost->device_table[index], 0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1551 | |
| 1552 | if ((device_status != SCI_SUCCESS) && |
| 1553 | (device_status != SCI_FAILURE_INVALID_STATE)) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1554 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1555 | "%s: Controller stop operation failed " |
| 1556 | "to stop device 0x%p because of " |
| 1557 | "status %d.\n", |
| 1558 | __func__, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1559 | ihost->device_table[index], device_status); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1560 | } |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | return status; |
| 1565 | } |
| 1566 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1567 | static void sci_controller_stopping_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1568 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1569 | struct isci_host *ihost = container_of(sm, typeof(*ihost), sm); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1570 | |
| 1571 | /* Stop all of the components for this controller */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1572 | sci_controller_stop_phys(ihost); |
| 1573 | sci_controller_stop_ports(ihost); |
| 1574 | sci_controller_stop_devices(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1577 | static void sci_controller_stopping_state_exit(struct sci_base_state_machine *sm) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1578 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1579 | struct isci_host *ihost = container_of(sm, typeof(*ihost), sm); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1580 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1581 | sci_del_timer(&ihost->timer); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1584 | static void sci_controller_reset_hardware(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1585 | { |
| 1586 | /* Disable interrupts so we dont take any spurious interrupts */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1587 | sci_controller_disable_interrupts(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1588 | |
| 1589 | /* Reset the SCU */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1590 | writel(0xFFFFFFFF, &ihost->smu_registers->soft_reset_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1591 | |
| 1592 | /* Delay for 1ms to before clearing the CQP and UFQPR. */ |
| 1593 | udelay(1000); |
| 1594 | |
| 1595 | /* The write to the CQGR clears the CQP */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1596 | writel(0x00000000, &ihost->smu_registers->completion_queue_get); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1597 | |
| 1598 | /* The write to the UFQGP clears the UFQPR */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1599 | writel(0, &ihost->scu_registers->sdma.unsolicited_frame_get_pointer); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1602 | static void sci_controller_resetting_state_enter(struct sci_base_state_machine *sm) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1603 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1604 | struct isci_host *ihost = container_of(sm, typeof(*ihost), sm); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1605 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1606 | sci_controller_reset_hardware(ihost); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1607 | sci_change_state(&ihost->sm, SCIC_RESET); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1610 | static const struct sci_base_state sci_controller_state_table[] = { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1611 | [SCIC_INITIAL] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1612 | .enter_state = sci_controller_initial_state_enter, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1613 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1614 | [SCIC_RESET] = {}, |
| 1615 | [SCIC_INITIALIZING] = {}, |
| 1616 | [SCIC_INITIALIZED] = {}, |
| 1617 | [SCIC_STARTING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1618 | .exit_state = sci_controller_starting_state_exit, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1619 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1620 | [SCIC_READY] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1621 | .enter_state = sci_controller_ready_state_enter, |
| 1622 | .exit_state = sci_controller_ready_state_exit, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1623 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1624 | [SCIC_RESETTING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1625 | .enter_state = sci_controller_resetting_state_enter, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1626 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1627 | [SCIC_STOPPING] = { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1628 | .enter_state = sci_controller_stopping_state_enter, |
| 1629 | .exit_state = sci_controller_stopping_state_exit, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1630 | }, |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1631 | [SCIC_STOPPED] = {}, |
| 1632 | [SCIC_FAILED] = {} |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1633 | }; |
| 1634 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1635 | static void sci_controller_set_default_config_parameters(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1636 | { |
| 1637 | /* these defaults are overridden by the platform / firmware */ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1638 | u16 index; |
| 1639 | |
| 1640 | /* Default to APC mode. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1641 | ihost->oem_parameters.controller.mode_type = SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1642 | |
| 1643 | /* Default to APC mode. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1644 | ihost->oem_parameters.controller.max_concurrent_dev_spin_up = 1; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1645 | |
| 1646 | /* Default to no SSC operation. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1647 | ihost->oem_parameters.controller.do_enable_ssc = false; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1648 | |
| 1649 | /* Initialize all of the port parameter information to narrow ports. */ |
| 1650 | for (index = 0; index < SCI_MAX_PORTS; index++) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1651 | ihost->oem_parameters.ports[index].phy_mask = 0; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | /* Initialize all of the phy parameter information. */ |
| 1655 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
| 1656 | /* Default to 6G (i.e. Gen 3) for now. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1657 | ihost->user_parameters.phys[index].max_speed_generation = 3; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1658 | |
| 1659 | /* the frequencies cannot be 0 */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1660 | ihost->user_parameters.phys[index].align_insertion_frequency = 0x7f; |
| 1661 | ihost->user_parameters.phys[index].in_connection_align_insertion_frequency = 0xff; |
| 1662 | ihost->user_parameters.phys[index].notify_enable_spin_up_insertion_frequency = 0x33; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1663 | |
| 1664 | /* |
| 1665 | * Previous Vitesse based expanders had a arbitration issue that |
| 1666 | * is worked around by having the upper 32-bits of SAS address |
| 1667 | * with a value greater then the Vitesse company identifier. |
| 1668 | * Hence, usage of 0x5FCFFFFF. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1669 | ihost->oem_parameters.phys[index].sas_address.low = 0x1 + ihost->id; |
| 1670 | ihost->oem_parameters.phys[index].sas_address.high = 0x5FCFFFFF; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1673 | ihost->user_parameters.stp_inactivity_timeout = 5; |
| 1674 | ihost->user_parameters.ssp_inactivity_timeout = 5; |
| 1675 | ihost->user_parameters.stp_max_occupancy_timeout = 5; |
| 1676 | ihost->user_parameters.ssp_max_occupancy_timeout = 20; |
| 1677 | ihost->user_parameters.no_outbound_task_timeout = 20; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
Edmund Nadolski | 6cb5853 | 2011-05-19 11:59:56 +0000 | [diff] [blame] | 1680 | static void controller_timeout(unsigned long data) |
| 1681 | { |
| 1682 | struct sci_timer *tmr = (struct sci_timer *)data; |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1683 | struct isci_host *ihost = container_of(tmr, typeof(*ihost), timer); |
| 1684 | struct sci_base_state_machine *sm = &ihost->sm; |
Edmund Nadolski | 6cb5853 | 2011-05-19 11:59:56 +0000 | [diff] [blame] | 1685 | unsigned long flags; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1686 | |
Edmund Nadolski | 6cb5853 | 2011-05-19 11:59:56 +0000 | [diff] [blame] | 1687 | spin_lock_irqsave(&ihost->scic_lock, flags); |
| 1688 | |
| 1689 | if (tmr->cancel) |
| 1690 | goto done; |
| 1691 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1692 | if (sm->current_state_id == SCIC_STARTING) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1693 | sci_controller_transition_to_ready(ihost, SCI_FAILURE_TIMEOUT); |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1694 | else if (sm->current_state_id == SCIC_STOPPING) { |
| 1695 | sci_change_state(sm, SCIC_FAILED); |
Edmund Nadolski | 6cb5853 | 2011-05-19 11:59:56 +0000 | [diff] [blame] | 1696 | isci_host_stop_complete(ihost, SCI_FAILURE_TIMEOUT); |
| 1697 | } else /* / @todo Now what do we want to do in this case? */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1698 | dev_err(&ihost->pdev->dev, |
Edmund Nadolski | 6cb5853 | 2011-05-19 11:59:56 +0000 | [diff] [blame] | 1699 | "%s: Controller timer fired when controller was not " |
| 1700 | "in a state being timed.\n", |
| 1701 | __func__); |
| 1702 | |
| 1703 | done: |
| 1704 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
| 1705 | } |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1706 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1707 | static enum sci_status sci_controller_construct(struct isci_host *ihost, |
| 1708 | void __iomem *scu_base, |
| 1709 | void __iomem *smu_base) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1710 | { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1711 | u8 i; |
| 1712 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1713 | sci_init_sm(&ihost->sm, sci_controller_state_table, SCIC_INITIAL); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1714 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1715 | ihost->scu_registers = scu_base; |
| 1716 | ihost->smu_registers = smu_base; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1717 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1718 | sci_port_configuration_agent_construct(&ihost->port_agent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1719 | |
| 1720 | /* Construct the ports for this controller */ |
| 1721 | for (i = 0; i < SCI_MAX_PORTS; i++) |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1722 | sci_port_construct(&ihost->ports[i], i, ihost); |
| 1723 | sci_port_construct(&ihost->ports[i], SCIC_SDS_DUMMY_PORT, ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1724 | |
| 1725 | /* Construct the phys for this controller */ |
| 1726 | for (i = 0; i < SCI_MAX_PHYS; i++) { |
| 1727 | /* Add all the PHYs to the dummy port */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1728 | sci_phy_construct(&ihost->phys[i], |
| 1729 | &ihost->ports[SCI_MAX_PORTS], i); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1732 | ihost->invalid_phy_mask = 0; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1733 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1734 | sci_init_timer(&ihost->timer, controller_timeout); |
Edmund Nadolski | 6cb5853 | 2011-05-19 11:59:56 +0000 | [diff] [blame] | 1735 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1736 | /* Initialize the User and OEM parameters to default values. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1737 | sci_controller_set_default_config_parameters(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1738 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1739 | return sci_controller_reset(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1742 | int sci_oem_parameters_validate(struct sci_oem_params *oem) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1743 | { |
| 1744 | int i; |
| 1745 | |
| 1746 | for (i = 0; i < SCI_MAX_PORTS; i++) |
| 1747 | if (oem->ports[i].phy_mask > SCIC_SDS_PARM_PHY_MASK_MAX) |
| 1748 | return -EINVAL; |
| 1749 | |
| 1750 | for (i = 0; i < SCI_MAX_PHYS; i++) |
| 1751 | if (oem->phys[i].sas_address.high == 0 && |
| 1752 | oem->phys[i].sas_address.low == 0) |
| 1753 | return -EINVAL; |
| 1754 | |
| 1755 | if (oem->controller.mode_type == SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE) { |
| 1756 | for (i = 0; i < SCI_MAX_PHYS; i++) |
| 1757 | if (oem->ports[i].phy_mask != 0) |
| 1758 | return -EINVAL; |
| 1759 | } else if (oem->controller.mode_type == SCIC_PORT_MANUAL_CONFIGURATION_MODE) { |
| 1760 | u8 phy_mask = 0; |
| 1761 | |
| 1762 | for (i = 0; i < SCI_MAX_PHYS; i++) |
| 1763 | phy_mask |= oem->ports[i].phy_mask; |
| 1764 | |
| 1765 | if (phy_mask == 0) |
| 1766 | return -EINVAL; |
| 1767 | } else |
| 1768 | return -EINVAL; |
| 1769 | |
| 1770 | if (oem->controller.max_concurrent_dev_spin_up > MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT) |
| 1771 | return -EINVAL; |
| 1772 | |
| 1773 | return 0; |
| 1774 | } |
| 1775 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1776 | static enum sci_status sci_oem_parameters_set(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1777 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1778 | u32 state = ihost->sm.current_state_id; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1779 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 1780 | if (state == SCIC_RESET || |
| 1781 | state == SCIC_INITIALIZING || |
| 1782 | state == SCIC_INITIALIZED) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1783 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1784 | if (sci_oem_parameters_validate(&ihost->oem_parameters)) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1785 | return SCI_FAILURE_INVALID_PARAMETER_VALUE; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1786 | |
| 1787 | return SCI_SUCCESS; |
| 1788 | } |
| 1789 | |
| 1790 | return SCI_FAILURE_INVALID_STATE; |
| 1791 | } |
| 1792 | |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1793 | static void power_control_timeout(unsigned long data) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1794 | { |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1795 | struct sci_timer *tmr = (struct sci_timer *)data; |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1796 | struct isci_host *ihost = container_of(tmr, typeof(*ihost), power_control.timer); |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1797 | struct isci_phy *iphy; |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1798 | unsigned long flags; |
| 1799 | u8 i; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1800 | |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1801 | spin_lock_irqsave(&ihost->scic_lock, flags); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1802 | |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1803 | if (tmr->cancel) |
| 1804 | goto done; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1805 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1806 | ihost->power_control.phys_granted_power = 0; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1807 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1808 | if (ihost->power_control.phys_waiting == 0) { |
| 1809 | ihost->power_control.timer_started = false; |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1810 | goto done; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1811 | } |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1812 | |
| 1813 | for (i = 0; i < SCI_MAX_PHYS; i++) { |
| 1814 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1815 | if (ihost->power_control.phys_waiting == 0) |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1816 | break; |
| 1817 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1818 | iphy = ihost->power_control.requesters[i]; |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1819 | if (iphy == NULL) |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1820 | continue; |
| 1821 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1822 | if (ihost->power_control.phys_granted_power >= |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1823 | ihost->oem_parameters.controller.max_concurrent_dev_spin_up) |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1824 | break; |
| 1825 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1826 | ihost->power_control.requesters[i] = NULL; |
| 1827 | ihost->power_control.phys_waiting--; |
| 1828 | ihost->power_control.phys_granted_power++; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1829 | sci_phy_consume_power_handler(iphy); |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | /* |
| 1833 | * It doesn't matter if the power list is empty, we need to start the |
| 1834 | * timer in case another phy becomes ready. |
| 1835 | */ |
| 1836 | sci_mod_timer(tmr, SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1837 | ihost->power_control.timer_started = true; |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1838 | |
| 1839 | done: |
| 1840 | spin_unlock_irqrestore(&ihost->scic_lock, flags); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1843 | void sci_controller_power_control_queue_insert(struct isci_host *ihost, |
| 1844 | struct isci_phy *iphy) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1845 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1846 | BUG_ON(iphy == NULL); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1847 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1848 | if (ihost->power_control.phys_granted_power < |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1849 | ihost->oem_parameters.controller.max_concurrent_dev_spin_up) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1850 | ihost->power_control.phys_granted_power++; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1851 | sci_phy_consume_power_handler(iphy); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1852 | |
| 1853 | /* |
| 1854 | * stop and start the power_control timer. When the timer fires, the |
| 1855 | * no_of_phys_granted_power will be set to 0 |
| 1856 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1857 | if (ihost->power_control.timer_started) |
| 1858 | sci_del_timer(&ihost->power_control.timer); |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1859 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1860 | sci_mod_timer(&ihost->power_control.timer, |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1861 | SCIC_SDS_CONTROLLER_POWER_CONTROL_INTERVAL); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1862 | ihost->power_control.timer_started = true; |
Edmund Nadolski | 0473661 | 2011-05-19 20:17:47 -0700 | [diff] [blame] | 1863 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1864 | } else { |
| 1865 | /* Add the phy in the waiting list */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1866 | ihost->power_control.requesters[iphy->phy_index] = iphy; |
| 1867 | ihost->power_control.phys_waiting++; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1871 | void sci_controller_power_control_queue_remove(struct isci_host *ihost, |
| 1872 | struct isci_phy *iphy) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1873 | { |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 1874 | BUG_ON(iphy == NULL); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1875 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1876 | if (ihost->power_control.requesters[iphy->phy_index]) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1877 | ihost->power_control.phys_waiting--; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1878 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1879 | ihost->power_control.requesters[iphy->phy_index] = NULL; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | #define AFE_REGISTER_WRITE_DELAY 10 |
| 1883 | |
| 1884 | /* Initialize the AFE for this phy index. We need to read the AFE setup from |
| 1885 | * the OEM parameters |
| 1886 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1887 | static void sci_controller_afe_initialization(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1888 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 1889 | const struct sci_oem_params *oem = &ihost->oem_parameters; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1890 | u32 afe_status; |
| 1891 | u32 phy_id; |
| 1892 | |
| 1893 | /* Clear DFX Status registers */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1894 | writel(0x0081000f, &ihost->scu_registers->afe.afe_dfx_master_control0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1895 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1896 | |
| 1897 | if (is_b0()) { |
| 1898 | /* PM Rx Equalization Save, PM SPhy Rx Acknowledgement |
| 1899 | * Timer, PM Stagger Timer */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1900 | writel(0x0007BFFF, &ihost->scu_registers->afe.afe_pmsn_master_control2); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1901 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1902 | } |
| 1903 | |
| 1904 | /* Configure bias currents to normal */ |
| 1905 | if (is_a0()) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1906 | writel(0x00005500, &ihost->scu_registers->afe.afe_bias_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1907 | else if (is_a2()) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1908 | writel(0x00005A00, &ihost->scu_registers->afe.afe_bias_control); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 1909 | else if (is_b0() || is_c0()) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1910 | writel(0x00005F00, &ihost->scu_registers->afe.afe_bias_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1911 | |
| 1912 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1913 | |
| 1914 | /* Enable PLL */ |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 1915 | if (is_b0() || is_c0()) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1916 | writel(0x80040A08, &ihost->scu_registers->afe.afe_pll_control0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1917 | else |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1918 | writel(0x80040908, &ihost->scu_registers->afe.afe_pll_control0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1919 | |
| 1920 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1921 | |
| 1922 | /* Wait for the PLL to lock */ |
| 1923 | do { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1924 | afe_status = readl(&ihost->scu_registers->afe.afe_common_block_status); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1925 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1926 | } while ((afe_status & 0x00001000) == 0); |
| 1927 | |
| 1928 | if (is_a0() || is_a2()) { |
| 1929 | /* Shorten SAS SNW lock time (RxLock timer value from 76 us to 50 us) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1930 | writel(0x7bcc96ad, &ihost->scu_registers->afe.afe_pmsn_master_control0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1931 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1932 | } |
| 1933 | |
| 1934 | for (phy_id = 0; phy_id < SCI_MAX_PHYS; phy_id++) { |
| 1935 | const struct sci_phy_oem_params *oem_phy = &oem->phys[phy_id]; |
| 1936 | |
| 1937 | if (is_b0()) { |
| 1938 | /* Configure transmitter SSC parameters */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1939 | writel(0x00030000, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_tx_ssc_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1940 | udelay(AFE_REGISTER_WRITE_DELAY); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 1941 | } else if (is_c0()) { |
| 1942 | /* Configure transmitter SSC parameters */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1943 | writel(0x0003000, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_tx_ssc_control); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 1944 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1945 | |
| 1946 | /* |
| 1947 | * All defaults, except the Receive Word Alignament/Comma Detect |
| 1948 | * Enable....(0xe800) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1949 | writel(0x00004500, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_xcvr_control0); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 1950 | udelay(AFE_REGISTER_WRITE_DELAY); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1951 | } else { |
| 1952 | /* |
| 1953 | * All defaults, except the Receive Word Alignament/Comma Detect |
| 1954 | * Enable....(0xe800) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1955 | writel(0x00004512, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_xcvr_control0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1956 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1957 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1958 | writel(0x0050100F, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_xcvr_control1); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1959 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1960 | } |
| 1961 | |
| 1962 | /* |
| 1963 | * Power up TX and RX out from power down (PWRDNTX and PWRDNRX) |
| 1964 | * & increase TX int & ext bias 20%....(0xe85c) */ |
| 1965 | if (is_a0()) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1966 | writel(0x000003D4, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_channel_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1967 | else if (is_a2()) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1968 | writel(0x000003F0, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_channel_control); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 1969 | else if (is_b0()) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1970 | /* Power down TX and RX (PWRDNTX and PWRDNRX) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1971 | writel(0x000003D7, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_channel_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1972 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1973 | |
| 1974 | /* |
| 1975 | * Power up TX and RX out from power down (PWRDNTX and PWRDNRX) |
| 1976 | * & increase TX int & ext bias 20%....(0xe85c) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1977 | writel(0x000003D4, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_channel_control); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 1978 | } else { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1979 | writel(0x000001E7, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_channel_control); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 1980 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1981 | |
| 1982 | /* |
| 1983 | * Power up TX and RX out from power down (PWRDNTX and PWRDNRX) |
| 1984 | * & increase TX int & ext bias 20%....(0xe85c) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1985 | writel(0x000001E4, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_channel_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1986 | } |
| 1987 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1988 | |
| 1989 | if (is_a0() || is_a2()) { |
| 1990 | /* Enable TX equalization (0xe824) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1991 | writel(0x00040000, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_tx_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1992 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 1993 | } |
| 1994 | |
| 1995 | /* |
| 1996 | * RDPI=0x0(RX Power On), RXOOBDETPDNC=0x0, TPD=0x0(TX Power On), |
| 1997 | * RDD=0x0(RX Detect Enabled) ....(0xe800) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 1998 | writel(0x00004100, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_xcvr_control0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 1999 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 2000 | |
| 2001 | /* Leave DFE/FFE on */ |
| 2002 | if (is_a0()) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2003 | writel(0x3F09983F, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_rx_ssc_control0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2004 | else if (is_a2()) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2005 | writel(0x3F11103F, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_rx_ssc_control0); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 2006 | else if (is_b0()) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2007 | writel(0x3F11103F, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_rx_ssc_control0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2008 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 2009 | /* Enable TX equalization (0xe824) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2010 | writel(0x00040000, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_tx_control); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 2011 | } else { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2012 | writel(0x0140DF0F, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_rx_ssc_control1); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 2013 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 2014 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2015 | writel(0x3F6F103F, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_rx_ssc_control0); |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 2016 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 2017 | |
| 2018 | /* Enable TX equalization (0xe824) */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2019 | writel(0x00040000, &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_tx_control); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2020 | } |
Adam Gruchala | dbb0743 | 2011-06-01 22:31:03 +0000 | [diff] [blame] | 2021 | |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2022 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 2023 | |
| 2024 | writel(oem_phy->afe_tx_amp_control0, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2025 | &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_tx_amp_control0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2026 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 2027 | |
| 2028 | writel(oem_phy->afe_tx_amp_control1, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2029 | &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_tx_amp_control1); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2030 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 2031 | |
| 2032 | writel(oem_phy->afe_tx_amp_control2, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2033 | &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_tx_amp_control2); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2034 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 2035 | |
| 2036 | writel(oem_phy->afe_tx_amp_control3, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2037 | &ihost->scu_registers->afe.scu_afe_xcvr[phy_id].afe_tx_amp_control3); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2038 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 2039 | } |
| 2040 | |
| 2041 | /* Transfer control to the PEs */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2042 | writel(0x00010f00, &ihost->scu_registers->afe.afe_dfx_master_control0); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2043 | udelay(AFE_REGISTER_WRITE_DELAY); |
| 2044 | } |
| 2045 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2046 | static void sci_controller_initialize_power_control(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2047 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2048 | sci_init_timer(&ihost->power_control.timer, power_control_timeout); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2049 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2050 | memset(ihost->power_control.requesters, 0, |
| 2051 | sizeof(ihost->power_control.requesters)); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2052 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2053 | ihost->power_control.phys_waiting = 0; |
| 2054 | ihost->power_control.phys_granted_power = 0; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2057 | static enum sci_status sci_controller_initialize(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2058 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2059 | struct sci_base_state_machine *sm = &ihost->sm; |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2060 | enum sci_status result = SCI_FAILURE; |
| 2061 | unsigned long i, state, val; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2062 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2063 | if (ihost->sm.current_state_id != SCIC_RESET) { |
| 2064 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2065 | "SCIC Controller initialize operation requested " |
| 2066 | "in invalid state\n"); |
| 2067 | return SCI_FAILURE_INVALID_STATE; |
| 2068 | } |
| 2069 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 2070 | sci_change_state(sm, SCIC_INITIALIZING); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2071 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2072 | sci_init_timer(&ihost->phy_timer, phy_startup_timeout); |
Edmund Nadolski | bb3dbdf | 2011-05-19 20:26:02 -0700 | [diff] [blame] | 2073 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2074 | ihost->next_phy_to_start = 0; |
| 2075 | ihost->phy_startup_timer_pending = false; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2076 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2077 | sci_controller_initialize_power_control(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2078 | |
| 2079 | /* |
| 2080 | * There is nothing to do here for B0 since we do not have to |
| 2081 | * program the AFE registers. |
| 2082 | * / @todo The AFE settings are supposed to be correct for the B0 but |
| 2083 | * / presently they seem to be wrong. */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2084 | sci_controller_afe_initialization(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2085 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2086 | |
| 2087 | /* Take the hardware out of reset */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2088 | writel(0, &ihost->smu_registers->soft_reset_control); |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2089 | |
| 2090 | /* |
| 2091 | * / @todo Provide meaningfull error code for hardware failure |
| 2092 | * result = SCI_FAILURE_CONTROLLER_HARDWARE; */ |
| 2093 | for (i = 100; i >= 1; i--) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2094 | u32 status; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2095 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2096 | /* Loop until the hardware reports success */ |
| 2097 | udelay(SCU_CONTEXT_RAM_INIT_STALL_TIME); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2098 | status = readl(&ihost->smu_registers->control_status); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2099 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2100 | if ((status & SCU_RAM_INIT_COMPLETED) == SCU_RAM_INIT_COMPLETED) |
| 2101 | break; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2102 | } |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2103 | if (i == 0) |
| 2104 | goto out; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2105 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2106 | /* |
| 2107 | * Determine what are the actaul device capacities that the |
| 2108 | * hardware will support */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2109 | val = readl(&ihost->smu_registers->device_context_capacity); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2110 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2111 | /* Record the smaller of the two capacity values */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2112 | ihost->logical_port_entries = min(smu_max_ports(val), SCI_MAX_PORTS); |
| 2113 | ihost->task_context_entries = min(smu_max_task_contexts(val), SCI_MAX_IO_REQUESTS); |
| 2114 | ihost->remote_node_entries = min(smu_max_rncs(val), SCI_MAX_REMOTE_DEVICES); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2115 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2116 | /* |
| 2117 | * Make all PEs that are unassigned match up with the |
| 2118 | * logical ports |
| 2119 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2120 | for (i = 0; i < ihost->logical_port_entries; i++) { |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2121 | struct scu_port_task_scheduler_group_registers __iomem |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2122 | *ptsg = &ihost->scu_registers->peg0.ptsg; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2123 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2124 | writel(i, &ptsg->protocol_engine[i]); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | /* Initialize hardware PCI Relaxed ordering in DMA engines */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2128 | val = readl(&ihost->scu_registers->sdma.pdma_configuration); |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2129 | val |= SCU_PDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2130 | writel(val, &ihost->scu_registers->sdma.pdma_configuration); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2131 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2132 | val = readl(&ihost->scu_registers->sdma.cdma_configuration); |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2133 | val |= SCU_CDMACR_GEN_BIT(PCI_RELAXED_ORDERING_ENABLE); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2134 | writel(val, &ihost->scu_registers->sdma.cdma_configuration); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2135 | |
| 2136 | /* |
| 2137 | * Initialize the PHYs before the PORTs because the PHY registers |
| 2138 | * are accessed during the port initialization. |
| 2139 | */ |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2140 | for (i = 0; i < SCI_MAX_PHYS; i++) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2141 | result = sci_phy_initialize(&ihost->phys[i], |
| 2142 | &ihost->scu_registers->peg0.pe[i].tl, |
| 2143 | &ihost->scu_registers->peg0.pe[i].ll); |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2144 | if (result != SCI_SUCCESS) |
| 2145 | goto out; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2148 | for (i = 0; i < ihost->logical_port_entries; i++) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2149 | struct isci_port *iport = &ihost->ports[i]; |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2150 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2151 | iport->port_task_scheduler_registers = &ihost->scu_registers->peg0.ptsg.port[i]; |
| 2152 | iport->port_pe_configuration_register = &ihost->scu_registers->peg0.ptsg.protocol_engine[0]; |
| 2153 | iport->viit_registers = &ihost->scu_registers->peg0.viit[i]; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2156 | result = sci_port_configuration_agent_initialize(ihost, &ihost->port_agent); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2157 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2158 | out: |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2159 | /* Advance the controller state machine */ |
| 2160 | if (result == SCI_SUCCESS) |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 2161 | state = SCIC_INITIALIZED; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2162 | else |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 2163 | state = SCIC_FAILED; |
| 2164 | sci_change_state(sm, state); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2165 | |
| 2166 | return result; |
| 2167 | } |
| 2168 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2169 | static enum sci_status sci_user_parameters_set(struct isci_host *ihost, |
| 2170 | struct sci_user_parameters *sci_parms) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2171 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2172 | u32 state = ihost->sm.current_state_id; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2173 | |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 2174 | if (state == SCIC_RESET || |
| 2175 | state == SCIC_INITIALIZING || |
| 2176 | state == SCIC_INITIALIZED) { |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2177 | u16 index; |
| 2178 | |
| 2179 | /* |
| 2180 | * Validate the user parameters. If they are not legal, then |
| 2181 | * return a failure. |
| 2182 | */ |
| 2183 | for (index = 0; index < SCI_MAX_PHYS; index++) { |
| 2184 | struct sci_phy_user_params *user_phy; |
| 2185 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2186 | user_phy = &sci_parms->phys[index]; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2187 | |
| 2188 | if (!((user_phy->max_speed_generation <= |
| 2189 | SCIC_SDS_PARM_MAX_SPEED) && |
| 2190 | (user_phy->max_speed_generation > |
| 2191 | SCIC_SDS_PARM_NO_SPEED))) |
| 2192 | return SCI_FAILURE_INVALID_PARAMETER_VALUE; |
| 2193 | |
| 2194 | if (user_phy->in_connection_align_insertion_frequency < |
| 2195 | 3) |
| 2196 | return SCI_FAILURE_INVALID_PARAMETER_VALUE; |
| 2197 | |
| 2198 | if ((user_phy->in_connection_align_insertion_frequency < |
| 2199 | 3) || |
| 2200 | (user_phy->align_insertion_frequency == 0) || |
| 2201 | (user_phy-> |
| 2202 | notify_enable_spin_up_insertion_frequency == |
| 2203 | 0)) |
| 2204 | return SCI_FAILURE_INVALID_PARAMETER_VALUE; |
| 2205 | } |
| 2206 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2207 | if ((sci_parms->stp_inactivity_timeout == 0) || |
| 2208 | (sci_parms->ssp_inactivity_timeout == 0) || |
| 2209 | (sci_parms->stp_max_occupancy_timeout == 0) || |
| 2210 | (sci_parms->ssp_max_occupancy_timeout == 0) || |
| 2211 | (sci_parms->no_outbound_task_timeout == 0)) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2212 | return SCI_FAILURE_INVALID_PARAMETER_VALUE; |
| 2213 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2214 | memcpy(&ihost->user_parameters, sci_parms, sizeof(*sci_parms)); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2215 | |
| 2216 | return SCI_SUCCESS; |
| 2217 | } |
| 2218 | |
| 2219 | return SCI_FAILURE_INVALID_STATE; |
| 2220 | } |
| 2221 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2222 | static int sci_controller_mem_init(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2223 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2224 | struct device *dev = &ihost->pdev->dev; |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2225 | dma_addr_t dma; |
| 2226 | size_t size; |
| 2227 | int err; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2228 | |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2229 | size = SCU_MAX_COMPLETION_QUEUE_ENTRIES * sizeof(u32); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2230 | ihost->completion_queue = dmam_alloc_coherent(dev, size, &dma, GFP_KERNEL); |
| 2231 | if (!ihost->completion_queue) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2232 | return -ENOMEM; |
| 2233 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2234 | writel(lower_32_bits(dma), &ihost->smu_registers->completion_queue_lower); |
| 2235 | writel(upper_32_bits(dma), &ihost->smu_registers->completion_queue_upper); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2236 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2237 | size = ihost->remote_node_entries * sizeof(union scu_remote_node_context); |
| 2238 | ihost->remote_node_context_table = dmam_alloc_coherent(dev, size, &dma, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2239 | GFP_KERNEL); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2240 | if (!ihost->remote_node_context_table) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2241 | return -ENOMEM; |
| 2242 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2243 | writel(lower_32_bits(dma), &ihost->smu_registers->remote_node_context_lower); |
| 2244 | writel(upper_32_bits(dma), &ihost->smu_registers->remote_node_context_upper); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2245 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2246 | size = ihost->task_context_entries * sizeof(struct scu_task_context), |
| 2247 | ihost->task_context_table = dmam_alloc_coherent(dev, size, &dma, GFP_KERNEL); |
| 2248 | if (!ihost->task_context_table) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2249 | return -ENOMEM; |
| 2250 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2251 | ihost->task_context_dma = dma; |
| 2252 | writel(lower_32_bits(dma), &ihost->smu_registers->host_task_table_lower); |
| 2253 | writel(upper_32_bits(dma), &ihost->smu_registers->host_task_table_upper); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2254 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2255 | err = sci_unsolicited_frame_control_construct(ihost); |
Dan Williams | 7c78da3 | 2011-06-01 16:00:01 -0700 | [diff] [blame] | 2256 | if (err) |
| 2257 | return err; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2258 | |
| 2259 | /* |
| 2260 | * Inform the silicon as to the location of the UF headers and |
| 2261 | * address table. |
| 2262 | */ |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2263 | writel(lower_32_bits(ihost->uf_control.headers.physical_address), |
| 2264 | &ihost->scu_registers->sdma.uf_header_base_address_lower); |
| 2265 | writel(upper_32_bits(ihost->uf_control.headers.physical_address), |
| 2266 | &ihost->scu_registers->sdma.uf_header_base_address_upper); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2267 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2268 | writel(lower_32_bits(ihost->uf_control.address_table.physical_address), |
| 2269 | &ihost->scu_registers->sdma.uf_address_table_lower); |
| 2270 | writel(upper_32_bits(ihost->uf_control.address_table.physical_address), |
| 2271 | &ihost->scu_registers->sdma.uf_address_table_upper); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2272 | |
| 2273 | return 0; |
| 2274 | } |
| 2275 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2276 | int isci_host_init(struct isci_host *ihost) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2277 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 2278 | int err = 0, i; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2279 | enum sci_status status; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2280 | struct sci_user_parameters sci_user_params; |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2281 | struct isci_pci_info *pci_info = to_pci_info(ihost->pdev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2282 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2283 | spin_lock_init(&ihost->state_lock); |
| 2284 | spin_lock_init(&ihost->scic_lock); |
| 2285 | init_waitqueue_head(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2286 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2287 | isci_host_change_state(ihost, isci_starting); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2288 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2289 | status = sci_controller_construct(ihost, scu_base(ihost), |
| 2290 | smu_base(ihost)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2291 | |
| 2292 | if (status != SCI_SUCCESS) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2293 | dev_err(&ihost->pdev->dev, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2294 | "%s: sci_controller_construct failed - status = %x\n", |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2295 | __func__, |
| 2296 | status); |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame] | 2297 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2300 | ihost->sas_ha.dev = &ihost->pdev->dev; |
| 2301 | ihost->sas_ha.lldd_ha = ihost; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2302 | |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 2303 | /* |
| 2304 | * grab initial values stored in the controller object for OEM and USER |
| 2305 | * parameters |
| 2306 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2307 | isci_user_parameters_get(&sci_user_params); |
| 2308 | status = sci_user_parameters_set(ihost, &sci_user_params); |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 2309 | if (status != SCI_SUCCESS) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2310 | dev_warn(&ihost->pdev->dev, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2311 | "%s: sci_user_parameters_set failed\n", |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 2312 | __func__); |
| 2313 | return -ENODEV; |
| 2314 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2315 | |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 2316 | /* grab any OEM parameters specified in orom */ |
| 2317 | if (pci_info->orom) { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2318 | status = isci_parse_oem_parameters(&ihost->oem_parameters, |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 2319 | pci_info->orom, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2320 | ihost->id); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2321 | if (status != SCI_SUCCESS) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2322 | dev_warn(&ihost->pdev->dev, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2323 | "parsing firmware oem parameters failed\n"); |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame] | 2324 | return -EINVAL; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2325 | } |
Dan Williams | 4711ba1 | 2011-03-11 10:43:57 -0800 | [diff] [blame] | 2326 | } |
| 2327 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2328 | status = sci_oem_parameters_set(ihost); |
Dan Williams | 4711ba1 | 2011-03-11 10:43:57 -0800 | [diff] [blame] | 2329 | if (status != SCI_SUCCESS) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2330 | dev_warn(&ihost->pdev->dev, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2331 | "%s: sci_oem_parameters_set failed\n", |
Dan Williams | 4711ba1 | 2011-03-11 10:43:57 -0800 | [diff] [blame] | 2332 | __func__); |
| 2333 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2336 | tasklet_init(&ihost->completion_tasklet, |
| 2337 | isci_host_completion_routine, (unsigned long)ihost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2338 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2339 | INIT_LIST_HEAD(&ihost->requests_to_complete); |
| 2340 | INIT_LIST_HEAD(&ihost->requests_to_errorback); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2341 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2342 | spin_lock_irq(&ihost->scic_lock); |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2343 | status = sci_controller_initialize(ihost); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2344 | spin_unlock_irq(&ihost->scic_lock); |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 2345 | if (status != SCI_SUCCESS) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2346 | dev_warn(&ihost->pdev->dev, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2347 | "%s: sci_controller_initialize failed -" |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 2348 | " status = 0x%x\n", |
| 2349 | __func__, status); |
| 2350 | return -ENODEV; |
| 2351 | } |
| 2352 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2353 | err = sci_controller_mem_init(ihost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2354 | if (err) |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame] | 2355 | return err; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2356 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 2357 | for (i = 0; i < SCI_MAX_PORTS; i++) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2358 | isci_port_init(&ihost->ports[i], ihost, i); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2359 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 2360 | for (i = 0; i < SCI_MAX_PHYS; i++) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2361 | isci_phy_init(&ihost->phys[i], ihost, i); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 2362 | |
| 2363 | for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2364 | struct isci_remote_device *idev = &ihost->devices[i]; |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 2365 | |
| 2366 | INIT_LIST_HEAD(&idev->reqs_in_process); |
| 2367 | INIT_LIST_HEAD(&idev->node); |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 2368 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2369 | |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 2370 | for (i = 0; i < SCI_MAX_IO_REQUESTS; i++) { |
| 2371 | struct isci_request *ireq; |
| 2372 | dma_addr_t dma; |
| 2373 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2374 | ireq = dmam_alloc_coherent(&ihost->pdev->dev, |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 2375 | sizeof(struct isci_request), &dma, |
| 2376 | GFP_KERNEL); |
| 2377 | if (!ireq) |
| 2378 | return -ENOMEM; |
| 2379 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2380 | ireq->tc = &ihost->task_context_table[i]; |
| 2381 | ireq->owning_controller = ihost; |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 2382 | spin_lock_init(&ireq->state_lock); |
| 2383 | ireq->request_daddr = dma; |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2384 | ireq->isci_host = ihost; |
| 2385 | ihost->reqs[i] = ireq; |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame] | 2388 | return 0; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 2389 | } |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2390 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2391 | void sci_controller_link_up(struct isci_host *ihost, struct isci_port *iport, |
| 2392 | struct isci_phy *iphy) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2393 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2394 | switch (ihost->sm.current_state_id) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 2395 | case SCIC_STARTING: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2396 | sci_del_timer(&ihost->phy_timer); |
| 2397 | ihost->phy_startup_timer_pending = false; |
| 2398 | ihost->port_agent.link_up_handler(ihost, &ihost->port_agent, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2399 | iport, iphy); |
| 2400 | sci_controller_start_next_phy(ihost); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2401 | break; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 2402 | case SCIC_READY: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2403 | ihost->port_agent.link_up_handler(ihost, &ihost->port_agent, |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2404 | iport, iphy); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2405 | break; |
| 2406 | default: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2407 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2408 | "%s: SCIC Controller linkup event from phy %d in " |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 2409 | "unexpected state %d\n", __func__, iphy->phy_index, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2410 | ihost->sm.current_state_id); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2411 | } |
| 2412 | } |
| 2413 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2414 | void sci_controller_link_down(struct isci_host *ihost, struct isci_port *iport, |
| 2415 | struct isci_phy *iphy) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2416 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2417 | switch (ihost->sm.current_state_id) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 2418 | case SCIC_STARTING: |
| 2419 | case SCIC_READY: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2420 | ihost->port_agent.link_down_handler(ihost, &ihost->port_agent, |
Dan Williams | ffe191c | 2011-06-29 13:09:25 -0700 | [diff] [blame] | 2421 | iport, iphy); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2422 | break; |
| 2423 | default: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2424 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2425 | "%s: SCIC Controller linkdown event from phy %d in " |
| 2426 | "unexpected state %d\n", |
| 2427 | __func__, |
Dan Williams | 8528095 | 2011-06-28 15:05:53 -0700 | [diff] [blame] | 2428 | iphy->phy_index, |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2429 | ihost->sm.current_state_id); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2430 | } |
| 2431 | } |
| 2432 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2433 | static bool sci_controller_has_remote_devices_stopping(struct isci_host *ihost) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2434 | { |
| 2435 | u32 index; |
| 2436 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2437 | for (index = 0; index < ihost->remote_node_entries; index++) { |
| 2438 | if ((ihost->device_table[index] != NULL) && |
| 2439 | (ihost->device_table[index]->sm.current_state_id == SCI_DEV_STOPPING)) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2440 | return true; |
| 2441 | } |
| 2442 | |
| 2443 | return false; |
| 2444 | } |
| 2445 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2446 | void sci_controller_remote_device_stopped(struct isci_host *ihost, |
| 2447 | struct isci_remote_device *idev) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2448 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2449 | if (ihost->sm.current_state_id != SCIC_STOPPING) { |
| 2450 | dev_dbg(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2451 | "SCIC Controller 0x%p remote device stopped event " |
| 2452 | "from device 0x%p in unexpected state %d\n", |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2453 | ihost, idev, |
| 2454 | ihost->sm.current_state_id); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2455 | return; |
| 2456 | } |
| 2457 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2458 | if (!sci_controller_has_remote_devices_stopping(ihost)) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2459 | sci_change_state(&ihost->sm, SCIC_STOPPED); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2462 | void sci_controller_post_request(struct isci_host *ihost, u32 request) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2463 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2464 | dev_dbg(&ihost->pdev->dev, "%s[%d]: %#x\n", |
| 2465 | __func__, ihost->id, request); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2466 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2467 | writel(request, &ihost->smu_registers->post_context_port); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2470 | struct isci_request *sci_request_by_tag(struct isci_host *ihost, u16 io_tag) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2471 | { |
| 2472 | u16 task_index; |
| 2473 | u16 task_sequence; |
| 2474 | |
Dan Williams | dd047c8 | 2011-06-09 11:06:58 -0700 | [diff] [blame] | 2475 | task_index = ISCI_TAG_TCI(io_tag); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2476 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2477 | if (task_index < ihost->task_context_entries) { |
| 2478 | struct isci_request *ireq = ihost->reqs[task_index]; |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 2479 | |
| 2480 | if (test_bit(IREQ_ACTIVE, &ireq->flags)) { |
Dan Williams | dd047c8 | 2011-06-09 11:06:58 -0700 | [diff] [blame] | 2481 | task_sequence = ISCI_TAG_SEQ(io_tag); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2482 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2483 | if (task_sequence == ihost->io_request_sequence[task_index]) |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 2484 | return ireq; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | return NULL; |
| 2489 | } |
| 2490 | |
| 2491 | /** |
| 2492 | * This method allocates remote node index and the reserves the remote node |
| 2493 | * context space for use. This method can fail if there are no more remote |
| 2494 | * node index available. |
| 2495 | * @scic: This is the controller object which contains the set of |
| 2496 | * free remote node ids |
| 2497 | * @sci_dev: This is the device object which is requesting the a remote node |
| 2498 | * id |
| 2499 | * @node_id: This is the remote node id that is assinged to the device if one |
| 2500 | * is available |
| 2501 | * |
| 2502 | * enum sci_status SCI_FAILURE_OUT_OF_RESOURCES if there are no available remote |
| 2503 | * node index available. |
| 2504 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2505 | enum sci_status sci_controller_allocate_remote_node_context(struct isci_host *ihost, |
| 2506 | struct isci_remote_device *idev, |
| 2507 | u16 *node_id) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2508 | { |
| 2509 | u16 node_index; |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2510 | u32 remote_node_count = sci_remote_device_node_count(idev); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2511 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2512 | node_index = sci_remote_node_table_allocate_remote_node( |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2513 | &ihost->available_remote_nodes, remote_node_count |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2514 | ); |
| 2515 | |
| 2516 | if (node_index != SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2517 | ihost->device_table[node_index] = idev; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2518 | |
| 2519 | *node_id = node_index; |
| 2520 | |
| 2521 | return SCI_SUCCESS; |
| 2522 | } |
| 2523 | |
| 2524 | return SCI_FAILURE_INSUFFICIENT_RESOURCES; |
| 2525 | } |
| 2526 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2527 | void sci_controller_free_remote_node_context(struct isci_host *ihost, |
| 2528 | struct isci_remote_device *idev, |
| 2529 | u16 node_id) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2530 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2531 | u32 remote_node_count = sci_remote_device_node_count(idev); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2532 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2533 | if (ihost->device_table[node_id] == idev) { |
| 2534 | ihost->device_table[node_id] = NULL; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2535 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2536 | sci_remote_node_table_release_remote_node_index( |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2537 | &ihost->available_remote_nodes, remote_node_count, node_id |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2538 | ); |
| 2539 | } |
| 2540 | } |
| 2541 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2542 | void sci_controller_copy_sata_response(void *response_buffer, |
| 2543 | void *frame_header, |
| 2544 | void *frame_buffer) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2545 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2546 | /* XXX type safety? */ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2547 | memcpy(response_buffer, frame_header, sizeof(u32)); |
| 2548 | |
| 2549 | memcpy(response_buffer + sizeof(u32), |
| 2550 | frame_buffer, |
| 2551 | sizeof(struct dev_to_host_fis) - sizeof(u32)); |
| 2552 | } |
| 2553 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2554 | void sci_controller_release_frame(struct isci_host *ihost, u32 frame_index) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2555 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2556 | if (sci_unsolicited_frame_control_release_frame(&ihost->uf_control, frame_index)) |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2557 | writel(ihost->uf_control.get, |
| 2558 | &ihost->scu_registers->sdma.unsolicited_frame_get_pointer); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 2561 | void isci_tci_free(struct isci_host *ihost, u16 tci) |
| 2562 | { |
| 2563 | u16 tail = ihost->tci_tail & (SCI_MAX_IO_REQUESTS-1); |
| 2564 | |
| 2565 | ihost->tci_pool[tail] = tci; |
| 2566 | ihost->tci_tail = tail + 1; |
| 2567 | } |
| 2568 | |
| 2569 | static u16 isci_tci_alloc(struct isci_host *ihost) |
| 2570 | { |
| 2571 | u16 head = ihost->tci_head & (SCI_MAX_IO_REQUESTS-1); |
| 2572 | u16 tci = ihost->tci_pool[head]; |
| 2573 | |
| 2574 | ihost->tci_head = head + 1; |
| 2575 | return tci; |
| 2576 | } |
| 2577 | |
| 2578 | static u16 isci_tci_space(struct isci_host *ihost) |
| 2579 | { |
| 2580 | return CIRC_SPACE(ihost->tci_head, ihost->tci_tail, SCI_MAX_IO_REQUESTS); |
| 2581 | } |
| 2582 | |
| 2583 | u16 isci_alloc_tag(struct isci_host *ihost) |
| 2584 | { |
| 2585 | if (isci_tci_space(ihost)) { |
| 2586 | u16 tci = isci_tci_alloc(ihost); |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2587 | u8 seq = ihost->io_request_sequence[tci]; |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 2588 | |
| 2589 | return ISCI_TAG(seq, tci); |
| 2590 | } |
| 2591 | |
| 2592 | return SCI_CONTROLLER_INVALID_IO_TAG; |
| 2593 | } |
| 2594 | |
| 2595 | enum sci_status isci_free_tag(struct isci_host *ihost, u16 io_tag) |
| 2596 | { |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 2597 | u16 tci = ISCI_TAG_TCI(io_tag); |
| 2598 | u16 seq = ISCI_TAG_SEQ(io_tag); |
| 2599 | |
| 2600 | /* prevent tail from passing head */ |
| 2601 | if (isci_tci_active(ihost) == 0) |
| 2602 | return SCI_FAILURE_INVALID_IO_TAG; |
| 2603 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2604 | if (seq == ihost->io_request_sequence[tci]) { |
| 2605 | ihost->io_request_sequence[tci] = (seq+1) & (SCI_MAX_SEQ-1); |
Dan Williams | 312e0c2 | 2011-06-28 13:47:09 -0700 | [diff] [blame] | 2606 | |
| 2607 | isci_tci_free(ihost, tci); |
| 2608 | |
| 2609 | return SCI_SUCCESS; |
| 2610 | } |
| 2611 | return SCI_FAILURE_INVALID_IO_TAG; |
| 2612 | } |
| 2613 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2614 | enum sci_status sci_controller_start_io(struct isci_host *ihost, |
| 2615 | struct isci_remote_device *idev, |
| 2616 | struct isci_request *ireq) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2617 | { |
| 2618 | enum sci_status status; |
| 2619 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2620 | if (ihost->sm.current_state_id != SCIC_READY) { |
| 2621 | dev_warn(&ihost->pdev->dev, "invalid state to start I/O"); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2622 | return SCI_FAILURE_INVALID_STATE; |
| 2623 | } |
| 2624 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2625 | status = sci_remote_device_start_io(ihost, idev, ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2626 | if (status != SCI_SUCCESS) |
| 2627 | return status; |
| 2628 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 2629 | set_bit(IREQ_ACTIVE, &ireq->flags); |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame^] | 2630 | sci_controller_post_request(ihost, ireq->post_context); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2631 | return SCI_SUCCESS; |
| 2632 | } |
| 2633 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2634 | enum sci_status sci_controller_terminate_request(struct isci_host *ihost, |
| 2635 | struct isci_remote_device *idev, |
| 2636 | struct isci_request *ireq) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2637 | { |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2638 | /* terminate an ongoing (i.e. started) core IO request. This does not |
| 2639 | * abort the IO request at the target, but rather removes the IO |
| 2640 | * request from the host controller. |
| 2641 | */ |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2642 | enum sci_status status; |
| 2643 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2644 | if (ihost->sm.current_state_id != SCIC_READY) { |
| 2645 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2646 | "invalid state to terminate request\n"); |
| 2647 | return SCI_FAILURE_INVALID_STATE; |
| 2648 | } |
| 2649 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2650 | status = sci_io_request_terminate(ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2651 | if (status != SCI_SUCCESS) |
| 2652 | return status; |
| 2653 | |
| 2654 | /* |
| 2655 | * Utilize the original post context command and or in the POST_TC_ABORT |
| 2656 | * request sub-type. |
| 2657 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2658 | sci_controller_post_request(ihost, |
| 2659 | ireq->post_context | SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2660 | return SCI_SUCCESS; |
| 2661 | } |
| 2662 | |
| 2663 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2664 | * sci_controller_complete_io() - This method will perform core specific |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2665 | * completion operations for an IO request. After this method is invoked, |
| 2666 | * the user should consider the IO request as invalid until it is properly |
| 2667 | * reused (i.e. re-constructed). |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2668 | * @ihost: The handle to the controller object for which to complete the |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2669 | * IO request. |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2670 | * @idev: The handle to the remote device object for which to complete |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2671 | * the IO request. |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2672 | * @ireq: the handle to the io request object to complete. |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2673 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2674 | enum sci_status sci_controller_complete_io(struct isci_host *ihost, |
| 2675 | struct isci_remote_device *idev, |
| 2676 | struct isci_request *ireq) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2677 | { |
| 2678 | enum sci_status status; |
| 2679 | u16 index; |
| 2680 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2681 | switch (ihost->sm.current_state_id) { |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 2682 | case SCIC_STOPPING: |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2683 | /* XXX: Implement this function */ |
| 2684 | return SCI_FAILURE; |
Edmund Nadolski | e301370 | 2011-06-02 00:10:43 +0000 | [diff] [blame] | 2685 | case SCIC_READY: |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2686 | status = sci_remote_device_complete_io(ihost, idev, ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2687 | if (status != SCI_SUCCESS) |
| 2688 | return status; |
| 2689 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 2690 | index = ISCI_TAG_TCI(ireq->io_tag); |
| 2691 | clear_bit(IREQ_ACTIVE, &ireq->flags); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2692 | return SCI_SUCCESS; |
| 2693 | default: |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2694 | dev_warn(&ihost->pdev->dev, "invalid state to complete I/O"); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2695 | return SCI_FAILURE_INVALID_STATE; |
| 2696 | } |
| 2697 | |
| 2698 | } |
| 2699 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2700 | enum sci_status sci_controller_continue_io(struct isci_request *ireq) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2701 | { |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2702 | struct isci_host *ihost = ireq->owning_controller; |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2703 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2704 | if (ihost->sm.current_state_id != SCIC_READY) { |
| 2705 | dev_warn(&ihost->pdev->dev, "invalid state to continue I/O"); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2706 | return SCI_FAILURE_INVALID_STATE; |
| 2707 | } |
| 2708 | |
Dan Williams | 5076a1a | 2011-06-27 14:57:03 -0700 | [diff] [blame] | 2709 | set_bit(IREQ_ACTIVE, &ireq->flags); |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame^] | 2710 | sci_controller_post_request(ihost, ireq->post_context); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2711 | return SCI_SUCCESS; |
| 2712 | } |
| 2713 | |
| 2714 | /** |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2715 | * sci_controller_start_task() - This method is called by the SCIC user to |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2716 | * send/start a framework task management request. |
| 2717 | * @controller: the handle to the controller object for which to start the task |
| 2718 | * management request. |
| 2719 | * @remote_device: the handle to the remote device object for which to start |
| 2720 | * the task management request. |
| 2721 | * @task_request: the handle to the task request object to start. |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2722 | */ |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2723 | enum sci_task_status sci_controller_start_task(struct isci_host *ihost, |
| 2724 | struct isci_remote_device *idev, |
| 2725 | struct isci_request *ireq) |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2726 | { |
| 2727 | enum sci_status status; |
| 2728 | |
Dan Williams | d9dcb4b | 2011-06-30 17:38:32 -0700 | [diff] [blame] | 2729 | if (ihost->sm.current_state_id != SCIC_READY) { |
| 2730 | dev_warn(&ihost->pdev->dev, |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2731 | "%s: SCIC Controller starting task from invalid " |
| 2732 | "state\n", |
| 2733 | __func__); |
| 2734 | return SCI_TASK_FAILURE_INVALID_STATE; |
| 2735 | } |
| 2736 | |
Dan Williams | 89a7301 | 2011-06-30 19:14:33 -0700 | [diff] [blame] | 2737 | status = sci_remote_device_start_task(ihost, idev, ireq); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2738 | switch (status) { |
| 2739 | case SCI_FAILURE_RESET_DEVICE_PARTIAL_SUCCESS: |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 2740 | set_bit(IREQ_ACTIVE, &ireq->flags); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2741 | |
| 2742 | /* |
| 2743 | * We will let framework know this task request started successfully, |
| 2744 | * although core is still woring on starting the request (to post tc when |
| 2745 | * RNC is resumed.) |
| 2746 | */ |
| 2747 | return SCI_SUCCESS; |
| 2748 | case SCI_SUCCESS: |
Dan Williams | db05625 | 2011-06-17 14:18:39 -0700 | [diff] [blame] | 2749 | set_bit(IREQ_ACTIVE, &ireq->flags); |
Dan Williams | 34a9915 | 2011-07-01 02:25:15 -0700 | [diff] [blame^] | 2750 | sci_controller_post_request(ihost, ireq->post_context); |
Dan Williams | cc9203b | 2011-05-08 17:34:44 -0700 | [diff] [blame] | 2751 | break; |
| 2752 | default: |
| 2753 | break; |
| 2754 | } |
| 2755 | |
| 2756 | return status; |
| 2757 | } |