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