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" |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 64 | #include "probe_roms.h" |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 65 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 66 | irqreturn_t isci_msix_isr(int vec, void *data) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 67 | { |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 68 | struct isci_host *ihost = data; |
| 69 | struct scic_sds_controller *scic = ihost->core_controller; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 70 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 71 | if (scic_sds_controller_isr(scic)) |
| 72 | tasklet_schedule(&ihost->completion_tasklet); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 73 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 74 | return IRQ_HANDLED; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 77 | irqreturn_t isci_intx_isr(int vec, void *data) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 78 | { |
| 79 | struct pci_dev *pdev = data; |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 80 | struct isci_host *ihost; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 81 | irqreturn_t ret = IRQ_NONE; |
Dan Williams | b329aff | 2011-03-07 16:02:25 -0800 | [diff] [blame] | 82 | int i; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 83 | |
Dan Williams | b329aff | 2011-03-07 16:02:25 -0800 | [diff] [blame] | 84 | for_each_isci_host(i, ihost, pdev) { |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 85 | struct scic_sds_controller *scic = ihost->core_controller; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 86 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 87 | if (scic_sds_controller_isr(scic)) { |
| 88 | tasklet_schedule(&ihost->completion_tasklet); |
| 89 | ret = IRQ_HANDLED; |
Dan Williams | 92f4f0f | 2011-02-18 09:25:11 -0800 | [diff] [blame] | 90 | } else if (scic_sds_controller_error_isr(scic)) { |
| 91 | spin_lock(&ihost->scic_lock); |
| 92 | scic_sds_controller_error_handler(scic); |
| 93 | spin_unlock(&ihost->scic_lock); |
| 94 | ret = IRQ_HANDLED; |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 95 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 96 | } |
Dan Williams | 92f4f0f | 2011-02-18 09:25:11 -0800 | [diff] [blame] | 97 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 98 | return ret; |
| 99 | } |
| 100 | |
Dan Williams | 92f4f0f | 2011-02-18 09:25:11 -0800 | [diff] [blame] | 101 | irqreturn_t isci_error_isr(int vec, void *data) |
| 102 | { |
| 103 | struct isci_host *ihost = data; |
| 104 | struct scic_sds_controller *scic = ihost->core_controller; |
| 105 | |
| 106 | if (scic_sds_controller_error_isr(scic)) |
| 107 | scic_sds_controller_error_handler(scic); |
| 108 | |
| 109 | return IRQ_HANDLED; |
| 110 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * isci_host_start_complete() - This function is called by the core library, |
| 114 | * through the ISCI Module, to indicate controller start status. |
| 115 | * @isci_host: This parameter specifies the ISCI host object |
| 116 | * @completion_status: This parameter specifies the completion status from the |
| 117 | * core library. |
| 118 | * |
| 119 | */ |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 120 | 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] | 121 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 122 | if (completion_status != SCI_SUCCESS) |
| 123 | dev_info(&ihost->pdev->dev, |
| 124 | "controller start timed out, continuing...\n"); |
| 125 | isci_host_change_state(ihost, isci_ready); |
| 126 | clear_bit(IHOST_START_PENDING, &ihost->flags); |
| 127 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 130 | int isci_host_scan_finished(struct Scsi_Host *shost, unsigned long time) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 131 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 132 | 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] | 133 | |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 134 | if (test_bit(IHOST_START_PENDING, &ihost->flags)) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 135 | return 0; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 136 | |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 137 | /* todo: use sas_flush_discovery once it is upstream */ |
| 138 | scsi_flush_work(shost); |
| 139 | |
| 140 | scsi_flush_work(shost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 141 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 142 | dev_dbg(&ihost->pdev->dev, |
| 143 | "%s: ihost->status = %d, time = %ld\n", |
| 144 | __func__, isci_host_get_state(ihost), time); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 145 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 146 | return 1; |
| 147 | |
| 148 | } |
| 149 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 150 | void isci_host_scan_start(struct Scsi_Host *shost) |
| 151 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 152 | struct isci_host *ihost = isci_host_from_sas_ha(SHOST_TO_SAS_HA(shost)); |
| 153 | struct scic_sds_controller *scic = ihost->core_controller; |
| 154 | unsigned long tmo = scic_controller_get_suggested_start_timeout(scic); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 155 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 156 | set_bit(IHOST_START_PENDING, &ihost->flags); |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 157 | |
| 158 | spin_lock_irq(&ihost->scic_lock); |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 159 | scic_controller_start(scic, tmo); |
Edmund Nadolski | 77950f5 | 2011-02-18 09:25:09 -0800 | [diff] [blame] | 160 | scic_controller_enable_interrupts(scic); |
| 161 | spin_unlock_irq(&ihost->scic_lock); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 164 | 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] | 165 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 166 | isci_host_change_state(ihost, isci_stopped); |
| 167 | scic_controller_disable_interrupts(ihost->core_controller); |
| 168 | clear_bit(IHOST_STOP_PENDING, &ihost->flags); |
| 169 | wake_up(&ihost->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static struct coherent_memory_info *isci_host_alloc_mdl_struct( |
| 173 | struct isci_host *isci_host, |
| 174 | u32 size) |
| 175 | { |
| 176 | struct coherent_memory_info *mdl_struct; |
| 177 | void *uncached_address = NULL; |
| 178 | |
| 179 | |
| 180 | mdl_struct = devm_kzalloc(&isci_host->pdev->dev, |
| 181 | sizeof(*mdl_struct), |
| 182 | GFP_KERNEL); |
| 183 | if (!mdl_struct) |
| 184 | return NULL; |
| 185 | |
| 186 | INIT_LIST_HEAD(&mdl_struct->node); |
| 187 | |
| 188 | uncached_address = dmam_alloc_coherent(&isci_host->pdev->dev, |
| 189 | size, |
| 190 | &mdl_struct->dma_handle, |
| 191 | GFP_KERNEL); |
| 192 | if (!uncached_address) |
| 193 | return NULL; |
| 194 | |
| 195 | /* memset the whole memory area. */ |
| 196 | memset((char *)uncached_address, 0, size); |
| 197 | mdl_struct->vaddr = uncached_address; |
| 198 | mdl_struct->size = (size_t)size; |
| 199 | |
| 200 | return mdl_struct; |
| 201 | } |
| 202 | |
| 203 | static void isci_host_build_mde( |
| 204 | struct sci_physical_memory_descriptor *mde_struct, |
| 205 | struct coherent_memory_info *mdl_struct) |
| 206 | { |
| 207 | unsigned long address = 0; |
| 208 | dma_addr_t dma_addr = 0; |
| 209 | |
| 210 | address = (unsigned long)mdl_struct->vaddr; |
| 211 | dma_addr = mdl_struct->dma_handle; |
| 212 | |
| 213 | /* to satisfy the alignment. */ |
| 214 | if ((address % mde_struct->constant_memory_alignment) != 0) { |
| 215 | int align_offset |
| 216 | = (mde_struct->constant_memory_alignment |
| 217 | - (address % mde_struct->constant_memory_alignment)); |
| 218 | address += align_offset; |
| 219 | dma_addr += align_offset; |
| 220 | } |
| 221 | |
| 222 | mde_struct->virtual_address = (void *)address; |
| 223 | mde_struct->physical_address = dma_addr; |
| 224 | mdl_struct->mde = mde_struct; |
| 225 | } |
| 226 | |
| 227 | static int isci_host_mdl_allocate_coherent( |
| 228 | struct isci_host *isci_host) |
| 229 | { |
| 230 | struct sci_physical_memory_descriptor *current_mde; |
| 231 | struct coherent_memory_info *mdl_struct; |
| 232 | u32 size = 0; |
| 233 | |
| 234 | struct sci_base_memory_descriptor_list *mdl_handle |
| 235 | = sci_controller_get_memory_descriptor_list_handle( |
| 236 | isci_host->core_controller); |
| 237 | |
| 238 | sci_mdl_first_entry(mdl_handle); |
| 239 | |
| 240 | current_mde = sci_mdl_get_current_entry(mdl_handle); |
| 241 | |
| 242 | while (current_mde != NULL) { |
| 243 | |
| 244 | size = (current_mde->constant_memory_size |
| 245 | + current_mde->constant_memory_alignment); |
| 246 | |
| 247 | mdl_struct = isci_host_alloc_mdl_struct(isci_host, size); |
| 248 | if (!mdl_struct) |
| 249 | return -ENOMEM; |
| 250 | |
| 251 | list_add_tail(&mdl_struct->node, &isci_host->mdl_struct_list); |
| 252 | |
| 253 | isci_host_build_mde(current_mde, mdl_struct); |
| 254 | |
| 255 | sci_mdl_next_entry(mdl_handle); |
| 256 | current_mde = sci_mdl_get_current_entry(mdl_handle); |
| 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | |
| 263 | /** |
| 264 | * isci_host_completion_routine() - This function is the delayed service |
| 265 | * routine that calls the sci core library's completion handler. It's |
| 266 | * scheduled as a tasklet from the interrupt service routine when interrupts |
| 267 | * in use, or set as the timeout function in polled mode. |
| 268 | * @data: This parameter specifies the ISCI host object |
| 269 | * |
| 270 | */ |
| 271 | static void isci_host_completion_routine(unsigned long data) |
| 272 | { |
| 273 | struct isci_host *isci_host = (struct isci_host *)data; |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 274 | struct list_head completed_request_list; |
| 275 | struct list_head errored_request_list; |
| 276 | struct list_head *current_position; |
| 277 | struct list_head *next_position; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 278 | struct isci_request *request; |
| 279 | struct isci_request *next_request; |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 280 | struct sas_task *task; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 281 | |
| 282 | INIT_LIST_HEAD(&completed_request_list); |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 283 | INIT_LIST_HEAD(&errored_request_list); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 284 | |
| 285 | spin_lock_irq(&isci_host->scic_lock); |
| 286 | |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 287 | scic_sds_controller_completion_handler(isci_host->core_controller); |
| 288 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 289 | /* Take the lists of completed I/Os from the host. */ |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 290 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 291 | list_splice_init(&isci_host->requests_to_complete, |
| 292 | &completed_request_list); |
| 293 | |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 294 | /* Take the list of errored I/Os from the host. */ |
| 295 | list_splice_init(&isci_host->requests_to_errorback, |
| 296 | &errored_request_list); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 297 | |
| 298 | spin_unlock_irq(&isci_host->scic_lock); |
| 299 | |
| 300 | /* Process any completions in the lists. */ |
| 301 | list_for_each_safe(current_position, next_position, |
| 302 | &completed_request_list) { |
| 303 | |
| 304 | request = list_entry(current_position, struct isci_request, |
| 305 | completed_node); |
| 306 | task = isci_request_access_task(request); |
| 307 | |
| 308 | /* Normal notification (task_done) */ |
| 309 | dev_dbg(&isci_host->pdev->dev, |
| 310 | "%s: Normal - request/task = %p/%p\n", |
| 311 | __func__, |
| 312 | request, |
| 313 | task); |
| 314 | |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 315 | /* Return the task to libsas */ |
| 316 | if (task != NULL) { |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 317 | |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 318 | task->lldd_task = NULL; |
| 319 | if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) { |
| 320 | |
| 321 | /* If the task is already in the abort path, |
| 322 | * the task_done callback cannot be called. |
| 323 | */ |
| 324 | task->task_done(task); |
| 325 | } |
| 326 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 327 | /* Free the request object. */ |
| 328 | isci_request_free(isci_host, request); |
| 329 | } |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 330 | list_for_each_entry_safe(request, next_request, &errored_request_list, |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 331 | completed_node) { |
| 332 | |
| 333 | task = isci_request_access_task(request); |
| 334 | |
| 335 | /* Use sas_task_abort */ |
| 336 | dev_warn(&isci_host->pdev->dev, |
| 337 | "%s: Error - request/task = %p/%p\n", |
| 338 | __func__, |
| 339 | request, |
| 340 | task); |
| 341 | |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 342 | if (task != NULL) { |
| 343 | |
| 344 | /* Put the task into the abort path if it's not there |
| 345 | * already. |
| 346 | */ |
| 347 | if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) |
| 348 | sas_task_abort(task); |
| 349 | |
| 350 | } else { |
| 351 | /* This is a case where the request has completed with a |
| 352 | * status such that it needed further target servicing, |
| 353 | * but the sas_task reference has already been removed |
| 354 | * from the request. Since it was errored, it was not |
| 355 | * being aborted, so there is nothing to do except free |
| 356 | * it. |
| 357 | */ |
| 358 | |
| 359 | spin_lock_irq(&isci_host->scic_lock); |
| 360 | /* Remove the request from the remote device's list |
| 361 | * of pending requests. |
| 362 | */ |
| 363 | list_del_init(&request->dev_node); |
| 364 | spin_unlock_irq(&isci_host->scic_lock); |
| 365 | |
| 366 | /* Free the request object. */ |
| 367 | isci_request_free(isci_host, request); |
| 368 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | } |
| 372 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 373 | void isci_host_deinit(struct isci_host *ihost) |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 374 | { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 375 | struct scic_sds_controller *scic = ihost->core_controller; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 376 | int i; |
| 377 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 378 | isci_host_change_state(ihost, isci_stopping); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 379 | for (i = 0; i < SCI_MAX_PORTS; i++) { |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 380 | struct isci_port *port = &ihost->isci_ports[i]; |
| 381 | struct isci_remote_device *idev, *d; |
| 382 | |
| 383 | list_for_each_entry_safe(idev, d, &port->remote_dev_list, node) { |
| 384 | isci_remote_device_change_state(idev, isci_stopping); |
Dan Williams | 6ad31fe | 2011-03-04 12:10:29 -0800 | [diff] [blame] | 385 | isci_remote_device_stop(ihost, idev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 389 | set_bit(IHOST_STOP_PENDING, &ihost->flags); |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 390 | |
| 391 | spin_lock_irq(&ihost->scic_lock); |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 392 | scic_controller_stop(scic, SCIC_CONTROLLER_STOP_TIMEOUT); |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 393 | spin_unlock_irq(&ihost->scic_lock); |
| 394 | |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 395 | wait_for_stop(ihost); |
| 396 | scic_controller_reset(scic); |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 397 | isci_timer_list_destroy(ihost); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 400 | static void __iomem *scu_base(struct isci_host *isci_host) |
| 401 | { |
| 402 | struct pci_dev *pdev = isci_host->pdev; |
| 403 | int id = isci_host->id; |
| 404 | |
| 405 | return pcim_iomap_table(pdev)[SCI_SCU_BAR * 2] + SCI_SCU_BAR_SIZE * id; |
| 406 | } |
| 407 | |
| 408 | static void __iomem *smu_base(struct isci_host *isci_host) |
| 409 | { |
| 410 | struct pci_dev *pdev = isci_host->pdev; |
| 411 | int id = isci_host->id; |
| 412 | |
| 413 | return pcim_iomap_table(pdev)[SCI_SMU_BAR * 2] + SCI_SMU_BAR_SIZE * id; |
| 414 | } |
| 415 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 416 | int isci_host_init(struct isci_host *isci_host) |
| 417 | { |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 418 | int err = 0, i; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 419 | enum sci_status status; |
| 420 | struct scic_sds_controller *controller; |
Dan Williams | 4711ba1 | 2011-03-11 10:43:57 -0800 | [diff] [blame^] | 421 | union scic_oem_parameters oem; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 422 | union scic_user_parameters scic_user_params; |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 423 | struct isci_pci_info *pci_info = to_pci_info(isci_host->pdev); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 424 | |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 425 | isci_timer_list_construct(isci_host); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 426 | |
| 427 | controller = scic_controller_alloc(&isci_host->pdev->dev); |
| 428 | |
| 429 | if (!controller) { |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame] | 430 | dev_err(&isci_host->pdev->dev, |
| 431 | "%s: failed (%d)\n", |
| 432 | __func__, |
| 433 | err); |
| 434 | return -ENOMEM; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | isci_host->core_controller = controller; |
Dan Williams | 4711ba1 | 2011-03-11 10:43:57 -0800 | [diff] [blame^] | 438 | sci_object_set_association(isci_host->core_controller, isci_host); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 439 | spin_lock_init(&isci_host->state_lock); |
| 440 | spin_lock_init(&isci_host->scic_lock); |
| 441 | spin_lock_init(&isci_host->queue_lock); |
Dan Williams | 0cf89d1 | 2011-02-18 09:25:07 -0800 | [diff] [blame] | 442 | init_waitqueue_head(&isci_host->eventq); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 443 | |
| 444 | isci_host_change_state(isci_host, isci_starting); |
| 445 | isci_host->can_queue = ISCI_CAN_QUEUE_VAL; |
| 446 | |
| 447 | status = scic_controller_construct(controller, scu_base(isci_host), |
| 448 | smu_base(isci_host)); |
| 449 | |
| 450 | if (status != SCI_SUCCESS) { |
| 451 | dev_err(&isci_host->pdev->dev, |
| 452 | "%s: scic_controller_construct failed - status = %x\n", |
| 453 | __func__, |
| 454 | status); |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame] | 455 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | isci_host->sas_ha.dev = &isci_host->pdev->dev; |
| 459 | isci_host->sas_ha.lldd_ha = isci_host; |
| 460 | |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 461 | /* |
| 462 | * grab initial values stored in the controller object for OEM and USER |
| 463 | * parameters |
| 464 | */ |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 465 | scic_user_parameters_get(controller, &scic_user_params); |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -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 | |
Dan Williams | 4711ba1 | 2011-03-11 10:43:57 -0800 | [diff] [blame^] | 475 | scic_oem_parameters_get(controller, &oem); |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 476 | |
| 477 | /* grab any OEM parameters specified in orom */ |
| 478 | if (pci_info->orom) { |
Dan Williams | 4711ba1 | 2011-03-11 10:43:57 -0800 | [diff] [blame^] | 479 | status = isci_parse_oem_parameters(&oem, |
Dan Williams | d044af1 | 2011-03-08 09:52:49 -0800 | [diff] [blame] | 480 | pci_info->orom, |
| 481 | isci_host->id); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 482 | if (status != SCI_SUCCESS) { |
| 483 | dev_warn(&isci_host->pdev->dev, |
| 484 | "parsing firmware oem parameters failed\n"); |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame] | 485 | return -EINVAL; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 486 | } |
Dan Williams | 4711ba1 | 2011-03-11 10:43:57 -0800 | [diff] [blame^] | 487 | } |
| 488 | |
| 489 | status = scic_oem_parameters_set(isci_host->core_controller, &oem); |
| 490 | if (status != SCI_SUCCESS) { |
| 491 | dev_warn(&isci_host->pdev->dev, |
| 492 | "%s: scic_oem_parameters_set failed\n", |
| 493 | __func__); |
| 494 | return -ENODEV; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 497 | tasklet_init(&isci_host->completion_tasklet, |
Dan Williams | c7ef403 | 2011-02-18 09:25:05 -0800 | [diff] [blame] | 498 | isci_host_completion_routine, (unsigned long)isci_host); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 499 | |
| 500 | INIT_LIST_HEAD(&(isci_host->mdl_struct_list)); |
| 501 | |
| 502 | INIT_LIST_HEAD(&isci_host->requests_to_complete); |
Jeff Skirvin | 11b00c1 | 2011-03-04 14:06:40 -0800 | [diff] [blame] | 503 | INIT_LIST_HEAD(&isci_host->requests_to_errorback); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 504 | |
Dan Williams | 7c40a80 | 2011-03-02 11:49:26 -0800 | [diff] [blame] | 505 | spin_lock_irq(&isci_host->scic_lock); |
| 506 | status = scic_controller_initialize(isci_host->core_controller); |
| 507 | spin_unlock_irq(&isci_host->scic_lock); |
| 508 | if (status != SCI_SUCCESS) { |
| 509 | dev_warn(&isci_host->pdev->dev, |
| 510 | "%s: scic_controller_initialize failed -" |
| 511 | " status = 0x%x\n", |
| 512 | __func__, status); |
| 513 | return -ENODEV; |
| 514 | } |
| 515 | |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 516 | /* populate mdl with dma memory. scu_mdl_allocate_coherent() */ |
| 517 | err = isci_host_mdl_allocate_coherent(isci_host); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 518 | if (err) |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame] | 519 | return err; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 520 | |
| 521 | /* |
| 522 | * keep the pool alloc size around, will use it for a bounds checking |
| 523 | * when trying to convert virtual addresses to physical addresses |
| 524 | */ |
| 525 | isci_host->dma_pool_alloc_size = sizeof(struct isci_request) + |
| 526 | scic_io_request_get_object_size(); |
| 527 | isci_host->dma_pool = dmam_pool_create(DRV_NAME, &isci_host->pdev->dev, |
| 528 | isci_host->dma_pool_alloc_size, |
| 529 | SLAB_HWCACHE_ALIGN, 0); |
| 530 | |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame] | 531 | if (!isci_host->dma_pool) |
| 532 | return -ENOMEM; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 533 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 534 | for (i = 0; i < SCI_MAX_PORTS; i++) |
| 535 | isci_port_init(&isci_host->isci_ports[i], isci_host, i); |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 536 | |
Dan Williams | d9c3739 | 2011-03-03 17:59:32 -0800 | [diff] [blame] | 537 | for (i = 0; i < SCI_MAX_PHYS; i++) |
| 538 | isci_phy_init(&isci_host->phys[i], isci_host, i); |
| 539 | |
| 540 | for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) { |
| 541 | struct isci_remote_device *idev = idev_by_id(isci_host, i); |
| 542 | |
| 543 | INIT_LIST_HEAD(&idev->reqs_in_process); |
| 544 | INIT_LIST_HEAD(&idev->node); |
| 545 | spin_lock_init(&idev->state_lock); |
| 546 | } |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 547 | |
Dave Jiang | 858d4aa | 2011-02-22 01:27:03 -0800 | [diff] [blame] | 548 | return 0; |
Dan Williams | 6f231dd | 2011-07-02 22:56:22 -0700 | [diff] [blame] | 549 | } |