Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 3 | * redistributing this file, you may do so under either license. |
| 4 | * |
| 5 | * GPL LICENSE SUMMARY |
| 6 | * |
| 7 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | * |
| 24 | * BSD LICENSE |
| 25 | * |
| 26 | * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. |
| 27 | * All rights reserved. |
| 28 | * |
| 29 | * Redistribution and use in source and binary forms, with or without |
| 30 | * modification, are permitted provided that the following conditions |
| 31 | * are met: |
| 32 | * |
| 33 | * * Redistributions of source code must retain the above copyright |
| 34 | * notice, this list of conditions and the following disclaimer. |
| 35 | * * Redistributions in binary form must reproduce the above copyright |
| 36 | * notice, this list of conditions and the following disclaimer in |
| 37 | * the documentation and/or other materials provided with the |
| 38 | * distribution. |
| 39 | * * Neither the name of Intel Corporation nor the names of its |
| 40 | * contributors may be used to endorse or promote products derived |
| 41 | * from this software without specific prior written permission. |
| 42 | * |
| 43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 44 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 45 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 46 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 47 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 48 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 49 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 50 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 51 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 52 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 53 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 54 | */ |
| 55 | |
| 56 | #include "isci.h" |
| 57 | #include "scic_io_request.h" |
| 58 | #include "scic_remote_device.h" |
| 59 | #include "scic_port.h" |
| 60 | |
| 61 | #include "port.h" |
| 62 | #include "request.h" |
| 63 | #include "host.h" |
| 64 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 65 | irqreturn_t isci_msix_isr(int vec, void *data) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 66 | { |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 67 | struct isci_host *ihost = data; |
| 68 | struct scic_sds_controller *scic = ihost->core_controller; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 69 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 70 | if (scic_sds_controller_isr(scic)) |
| 71 | tasklet_schedule(&ihost->completion_tasklet); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 72 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 73 | return IRQ_HANDLED; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 76 | irqreturn_t isci_intx_isr(int vec, void *data) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 77 | { |
| 78 | struct pci_dev *pdev = data; |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 79 | struct isci_host *ihost; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 80 | irqreturn_t ret = IRQ_NONE; |
| 81 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 82 | for_each_isci_host(ihost, pdev) { |
| 83 | struct scic_sds_controller *scic = ihost->core_controller; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 84 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 85 | if (scic_sds_controller_isr(scic)) { |
| 86 | tasklet_schedule(&ihost->completion_tasklet); |
| 87 | ret = IRQ_HANDLED; |
Dan Williams | 92f4f0f | 2011-02-18 09:25:11 -0800 | [diff] [blame] | 88 | } else if (scic_sds_controller_error_isr(scic)) { |
| 89 | spin_lock(&ihost->scic_lock); |
| 90 | scic_sds_controller_error_handler(scic); |
| 91 | spin_unlock(&ihost->scic_lock); |
| 92 | ret = IRQ_HANDLED; |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 93 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 94 | } |
Dan Williams | 92f4f0f | 2011-02-18 09:25:11 -0800 | [diff] [blame] | 95 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 96 | return ret; |
| 97 | } |
| 98 | |
Dan Williams | 92f4f0f | 2011-02-18 09:25:11 -0800 | [diff] [blame] | 99 | irqreturn_t isci_error_isr(int vec, void *data) |
| 100 | { |
| 101 | struct isci_host *ihost = data; |
| 102 | struct scic_sds_controller *scic = ihost->core_controller; |
| 103 | |
| 104 | if (scic_sds_controller_error_isr(scic)) |
| 105 | scic_sds_controller_error_handler(scic); |
| 106 | |
| 107 | return IRQ_HANDLED; |
| 108 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * isci_host_start_complete() - This function is called by the core library, |
| 112 | * through the ISCI Module, to indicate controller start status. |
| 113 | * @isci_host: This parameter specifies the ISCI host object |
| 114 | * @completion_status: This parameter specifies the completion status from the |
| 115 | * core library. |
| 116 | * |
| 117 | */ |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 118 | 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] | 119 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 120 | if (completion_status != SCI_SUCCESS) |
| 121 | dev_info(&ihost->pdev->dev, |
| 122 | "controller start timed out, continuing...\n"); |
| 123 | isci_host_change_state(ihost, isci_ready); |
| 124 | clear_bit(IHOST_START_PENDING, &ihost->flags); |
| 125 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 128 | int isci_host_scan_finished(struct Scsi_Host *shost, unsigned long time) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 129 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 130 | struct isci_host *ihost = isci_host_from_sas_ha(SHOST_TO_SAS_HA(shost)); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 131 | |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 132 | if (test_bit(IHOST_START_PENDING, &ihost->flags)) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 133 | return 0; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 134 | |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 135 | /* todo: use sas_flush_discovery once it is upstream */ |
| 136 | scsi_flush_work(shost); |
| 137 | |
| 138 | scsi_flush_work(shost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 139 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 140 | dev_dbg(&ihost->pdev->dev, |
| 141 | "%s: ihost->status = %d, time = %ld\n", |
| 142 | __func__, isci_host_get_state(ihost), time); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 143 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 144 | return 1; |
| 145 | |
| 146 | } |
| 147 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 148 | void isci_host_scan_start(struct Scsi_Host *shost) |
| 149 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 150 | struct isci_host *ihost = isci_host_from_sas_ha(SHOST_TO_SAS_HA(shost)); |
| 151 | struct scic_sds_controller *scic = ihost->core_controller; |
| 152 | unsigned long tmo = scic_controller_get_suggested_start_timeout(scic); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 153 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 154 | set_bit(IHOST_START_PENDING, &ihost->flags); |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 155 | |
| 156 | spin_lock_irq(&ihost->scic_lock); |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 157 | scic_controller_start(scic, tmo); |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 158 | scic_controller_enable_interrupts(scic); |
| 159 | spin_unlock_irq(&ihost->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 162 | 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] | 163 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 164 | isci_host_change_state(ihost, isci_stopped); |
| 165 | scic_controller_disable_interrupts(ihost->core_controller); |
| 166 | clear_bit(IHOST_STOP_PENDING, &ihost->flags); |
| 167 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static struct coherent_memory_info *isci_host_alloc_mdl_struct( |
| 171 | struct isci_host *isci_host, |
| 172 | u32 size) |
| 173 | { |
| 174 | struct coherent_memory_info *mdl_struct; |
| 175 | void *uncached_address = NULL; |
| 176 | |
| 177 | |
| 178 | mdl_struct = devm_kzalloc(&isci_host->pdev->dev, |
| 179 | sizeof(*mdl_struct), |
| 180 | GFP_KERNEL); |
| 181 | if (!mdl_struct) |
| 182 | return NULL; |
| 183 | |
| 184 | INIT_LIST_HEAD(&mdl_struct->node); |
| 185 | |
| 186 | uncached_address = dmam_alloc_coherent(&isci_host->pdev->dev, |
| 187 | size, |
| 188 | &mdl_struct->dma_handle, |
| 189 | GFP_KERNEL); |
| 190 | if (!uncached_address) |
| 191 | return NULL; |
| 192 | |
| 193 | /* memset the whole memory area. */ |
| 194 | memset((char *)uncached_address, 0, size); |
| 195 | mdl_struct->vaddr = uncached_address; |
| 196 | mdl_struct->size = (size_t)size; |
| 197 | |
| 198 | return mdl_struct; |
| 199 | } |
| 200 | |
| 201 | static void isci_host_build_mde( |
| 202 | struct sci_physical_memory_descriptor *mde_struct, |
| 203 | struct coherent_memory_info *mdl_struct) |
| 204 | { |
| 205 | unsigned long address = 0; |
| 206 | dma_addr_t dma_addr = 0; |
| 207 | |
| 208 | address = (unsigned long)mdl_struct->vaddr; |
| 209 | dma_addr = mdl_struct->dma_handle; |
| 210 | |
| 211 | /* to satisfy the alignment. */ |
| 212 | if ((address % mde_struct->constant_memory_alignment) != 0) { |
| 213 | int align_offset |
| 214 | = (mde_struct->constant_memory_alignment |
| 215 | - (address % mde_struct->constant_memory_alignment)); |
| 216 | address += align_offset; |
| 217 | dma_addr += align_offset; |
| 218 | } |
| 219 | |
| 220 | mde_struct->virtual_address = (void *)address; |
| 221 | mde_struct->physical_address = dma_addr; |
| 222 | mdl_struct->mde = mde_struct; |
| 223 | } |
| 224 | |
| 225 | static int isci_host_mdl_allocate_coherent( |
| 226 | struct isci_host *isci_host) |
| 227 | { |
| 228 | struct sci_physical_memory_descriptor *current_mde; |
| 229 | struct coherent_memory_info *mdl_struct; |
| 230 | u32 size = 0; |
| 231 | |
| 232 | struct sci_base_memory_descriptor_list *mdl_handle |
| 233 | = sci_controller_get_memory_descriptor_list_handle( |
| 234 | isci_host->core_controller); |
| 235 | |
| 236 | sci_mdl_first_entry(mdl_handle); |
| 237 | |
| 238 | current_mde = sci_mdl_get_current_entry(mdl_handle); |
| 239 | |
| 240 | while (current_mde != NULL) { |
| 241 | |
| 242 | size = (current_mde->constant_memory_size |
| 243 | + current_mde->constant_memory_alignment); |
| 244 | |
| 245 | mdl_struct = isci_host_alloc_mdl_struct(isci_host, size); |
| 246 | if (!mdl_struct) |
| 247 | return -ENOMEM; |
| 248 | |
| 249 | list_add_tail(&mdl_struct->node, &isci_host->mdl_struct_list); |
| 250 | |
| 251 | isci_host_build_mde(current_mde, mdl_struct); |
| 252 | |
| 253 | sci_mdl_next_entry(mdl_handle); |
| 254 | current_mde = sci_mdl_get_current_entry(mdl_handle); |
| 255 | } |
| 256 | |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | |
| 261 | /** |
| 262 | * isci_host_completion_routine() - This function is the delayed service |
| 263 | * routine that calls the sci core library's completion handler. It's |
| 264 | * scheduled as a tasklet from the interrupt service routine when interrupts |
| 265 | * in use, or set as the timeout function in polled mode. |
| 266 | * @data: This parameter specifies the ISCI host object |
| 267 | * |
| 268 | */ |
| 269 | static void isci_host_completion_routine(unsigned long data) |
| 270 | { |
| 271 | struct isci_host *isci_host = (struct isci_host *)data; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 272 | struct list_head completed_request_list; |
| 273 | struct list_head aborted_request_list; |
| 274 | struct list_head *current_position; |
| 275 | struct list_head *next_position; |
| 276 | struct isci_request *request; |
| 277 | struct isci_request *next_request; |
| 278 | struct sas_task *task; |
| 279 | |
| 280 | INIT_LIST_HEAD(&completed_request_list); |
| 281 | INIT_LIST_HEAD(&aborted_request_list); |
| 282 | |
| 283 | spin_lock_irq(&isci_host->scic_lock); |
| 284 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 285 | scic_sds_controller_completion_handler(isci_host->core_controller); |
| 286 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 287 | /* Take the lists of completed I/Os from the host. */ |
| 288 | list_splice_init(&isci_host->requests_to_complete, |
| 289 | &completed_request_list); |
| 290 | |
| 291 | list_splice_init(&isci_host->requests_to_abort, |
| 292 | &aborted_request_list); |
| 293 | |
| 294 | spin_unlock_irq(&isci_host->scic_lock); |
| 295 | |
| 296 | /* Process any completions in the lists. */ |
| 297 | list_for_each_safe(current_position, next_position, |
| 298 | &completed_request_list) { |
| 299 | |
| 300 | request = list_entry(current_position, struct isci_request, |
| 301 | completed_node); |
| 302 | task = isci_request_access_task(request); |
| 303 | |
| 304 | /* Normal notification (task_done) */ |
| 305 | dev_dbg(&isci_host->pdev->dev, |
| 306 | "%s: Normal - request/task = %p/%p\n", |
| 307 | __func__, |
| 308 | request, |
| 309 | task); |
| 310 | |
| 311 | task->task_done(task); |
| 312 | task->lldd_task = NULL; |
| 313 | |
| 314 | /* Free the request object. */ |
| 315 | isci_request_free(isci_host, request); |
| 316 | } |
| 317 | list_for_each_entry_safe(request, next_request, &aborted_request_list, |
| 318 | completed_node) { |
| 319 | |
| 320 | task = isci_request_access_task(request); |
| 321 | |
| 322 | /* Use sas_task_abort */ |
| 323 | dev_warn(&isci_host->pdev->dev, |
| 324 | "%s: Error - request/task = %p/%p\n", |
| 325 | __func__, |
| 326 | request, |
| 327 | task); |
| 328 | |
| 329 | /* Put the task into the abort path. */ |
| 330 | sas_task_abort(task); |
| 331 | } |
| 332 | |
| 333 | } |
| 334 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 335 | void isci_host_deinit(struct isci_host *ihost) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 336 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 337 | struct scic_sds_controller *scic = ihost->core_controller; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 338 | int i; |
| 339 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 340 | isci_host_change_state(ihost, isci_stopping); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 341 | for (i = 0; i < SCI_MAX_PORTS; i++) { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 342 | struct isci_port *port = &ihost->isci_ports[i]; |
| 343 | struct isci_remote_device *idev, *d; |
| 344 | |
| 345 | list_for_each_entry_safe(idev, d, &port->remote_dev_list, node) { |
| 346 | isci_remote_device_change_state(idev, isci_stopping); |
| 347 | isci_remote_device_stop(idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 351 | set_bit(IHOST_STOP_PENDING, &ihost->flags); |
| 352 | scic_controller_stop(scic, SCIC_CONTROLLER_STOP_TIMEOUT); |
| 353 | wait_for_stop(ihost); |
| 354 | scic_controller_reset(scic); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 357 | static void __iomem *scu_base(struct isci_host *isci_host) |
| 358 | { |
| 359 | struct pci_dev *pdev = isci_host->pdev; |
| 360 | int id = isci_host->id; |
| 361 | |
| 362 | return pcim_iomap_table(pdev)[SCI_SCU_BAR * 2] + SCI_SCU_BAR_SIZE * id; |
| 363 | } |
| 364 | |
| 365 | static void __iomem *smu_base(struct isci_host *isci_host) |
| 366 | { |
| 367 | struct pci_dev *pdev = isci_host->pdev; |
| 368 | int id = isci_host->id; |
| 369 | |
| 370 | return pcim_iomap_table(pdev)[SCI_SMU_BAR * 2] + SCI_SMU_BAR_SIZE * id; |
| 371 | } |
| 372 | |
| 373 | #define SCI_MAX_TIMER_COUNT 25 |
| 374 | |
| 375 | int isci_host_init(struct isci_host *isci_host) |
| 376 | { |
| 377 | int err = 0; |
| 378 | int index = 0; |
| 379 | enum sci_status status; |
| 380 | struct scic_sds_controller *controller; |
| 381 | struct scic_sds_port *scic_port; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 382 | union scic_oem_parameters scic_oem_params; |
| 383 | union scic_user_parameters scic_user_params; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 384 | |
| 385 | INIT_LIST_HEAD(&isci_host->timer_list_struct.timers); |
| 386 | isci_timer_list_construct( |
| 387 | &isci_host->timer_list_struct, |
| 388 | SCI_MAX_TIMER_COUNT |
| 389 | ); |
| 390 | |
| 391 | controller = scic_controller_alloc(&isci_host->pdev->dev); |
| 392 | |
| 393 | if (!controller) { |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 394 | dev_err(&isci_host->pdev->dev, |
| 395 | "%s: failed (%d)\n", |
| 396 | __func__, |
| 397 | err); |
| 398 | return -ENOMEM; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | isci_host->core_controller = controller; |
| 402 | spin_lock_init(&isci_host->state_lock); |
| 403 | spin_lock_init(&isci_host->scic_lock); |
| 404 | spin_lock_init(&isci_host->queue_lock); |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 405 | init_waitqueue_head(&isci_host->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 406 | |
| 407 | isci_host_change_state(isci_host, isci_starting); |
| 408 | isci_host->can_queue = ISCI_CAN_QUEUE_VAL; |
| 409 | |
| 410 | status = scic_controller_construct(controller, scu_base(isci_host), |
| 411 | smu_base(isci_host)); |
| 412 | |
| 413 | if (status != SCI_SUCCESS) { |
| 414 | dev_err(&isci_host->pdev->dev, |
| 415 | "%s: scic_controller_construct failed - status = %x\n", |
| 416 | __func__, |
| 417 | status); |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 418 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | isci_host->sas_ha.dev = &isci_host->pdev->dev; |
| 422 | isci_host->sas_ha.lldd_ha = isci_host; |
| 423 | |
| 424 | /*----------- SCIC controller Initialization Stuff ------------------ |
| 425 | * set association host adapter struct in core controller. |
| 426 | */ |
| 427 | sci_object_set_association(isci_host->core_controller, |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 428 | (void *)isci_host); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 429 | |
| 430 | /* grab initial values stored in the controller object for OEM and USER |
| 431 | * parameters */ |
| 432 | scic_oem_parameters_get(controller, &scic_oem_params); |
| 433 | scic_user_parameters_get(controller, &scic_user_params); |
| 434 | |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 435 | if (isci_firmware) { |
| 436 | /* grab any OEM and USER parameters specified in binary blob */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 437 | status = isci_parse_oem_parameters(&scic_oem_params, |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 438 | isci_host->id, |
| 439 | isci_firmware); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 440 | if (status != SCI_SUCCESS) { |
| 441 | dev_warn(&isci_host->pdev->dev, |
| 442 | "parsing firmware oem parameters failed\n"); |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 443 | return -EINVAL; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | status = isci_parse_user_parameters(&scic_user_params, |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 447 | isci_host->id, |
| 448 | isci_firmware); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 449 | if (status != SCI_SUCCESS) { |
| 450 | dev_warn(&isci_host->pdev->dev, |
| 451 | "%s: isci_parse_user_parameters" |
| 452 | " failed\n", __func__); |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 453 | return -EINVAL; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 454 | } |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 455 | } else { |
| 456 | status = scic_oem_parameters_set(isci_host->core_controller, |
| 457 | &scic_oem_params); |
| 458 | if (status != SCI_SUCCESS) { |
| 459 | dev_warn(&isci_host->pdev->dev, |
| 460 | "%s: scic_oem_parameters_set failed\n", |
| 461 | __func__); |
| 462 | return -ENODEV; |
| 463 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 464 | |
| 465 | |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 466 | status = scic_user_parameters_set(isci_host->core_controller, |
| 467 | &scic_user_params); |
| 468 | if (status != SCI_SUCCESS) { |
| 469 | dev_warn(&isci_host->pdev->dev, |
| 470 | "%s: scic_user_parameters_set failed\n", |
| 471 | __func__); |
| 472 | return -ENODEV; |
| 473 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | status = scic_controller_initialize(isci_host->core_controller); |
| 477 | if (status != SCI_SUCCESS) { |
| 478 | dev_warn(&isci_host->pdev->dev, |
| 479 | "%s: scic_controller_initialize failed -" |
| 480 | " status = 0x%x\n", |
| 481 | __func__, status); |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 482 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 485 | tasklet_init(&isci_host->completion_tasklet, |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 486 | isci_host_completion_routine, (unsigned long)isci_host); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 487 | |
| 488 | INIT_LIST_HEAD(&(isci_host->mdl_struct_list)); |
| 489 | |
| 490 | INIT_LIST_HEAD(&isci_host->requests_to_complete); |
| 491 | INIT_LIST_HEAD(&isci_host->requests_to_abort); |
| 492 | |
| 493 | /* populate mdl with dma memory. scu_mdl_allocate_coherent() */ |
| 494 | err = isci_host_mdl_allocate_coherent(isci_host); |
| 495 | |
| 496 | if (err) |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 497 | return err; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 498 | |
| 499 | /* |
| 500 | * keep the pool alloc size around, will use it for a bounds checking |
| 501 | * when trying to convert virtual addresses to physical addresses |
| 502 | */ |
| 503 | isci_host->dma_pool_alloc_size = sizeof(struct isci_request) + |
| 504 | scic_io_request_get_object_size(); |
| 505 | isci_host->dma_pool = dmam_pool_create(DRV_NAME, &isci_host->pdev->dev, |
| 506 | isci_host->dma_pool_alloc_size, |
| 507 | SLAB_HWCACHE_ALIGN, 0); |
| 508 | |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 509 | if (!isci_host->dma_pool) |
| 510 | return -ENOMEM; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 511 | |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 512 | for (index = 0; index < SCI_MAX_PORTS; index++) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 513 | isci_port_init(&isci_host->isci_ports[index], |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 514 | isci_host, |
| 515 | index); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 516 | |
| 517 | for (index = 0; index < SCI_MAX_PHYS; index++) |
| 518 | isci_phy_init(&isci_host->phys[index], isci_host, index); |
| 519 | |
| 520 | /* Why are we doing this? Is this even necessary? */ |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 521 | memcpy(&isci_host->sas_addr[0], |
| 522 | &isci_host->phys[0].sas_addr[0], |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 523 | SAS_ADDR_SIZE); |
| 524 | |
| 525 | /* Start the ports */ |
| 526 | for (index = 0; index < SCI_MAX_PORTS; index++) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 527 | scic_controller_get_port_handle(controller, index, &scic_port); |
| 528 | scic_port_start(scic_port); |
| 529 | } |
| 530 | |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame^] | 531 | return 0; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 532 | } |