blob: 153f419f16186f638ec5c5bec94afb6a68e0e512 [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
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 Williamsc7ef4032011-02-18 09:25:05 -080065irqreturn_t isci_msix_isr(int vec, void *data)
Dan Williams6f231dd2011-07-02 22:56:22 -070066{
Dan Williamsc7ef4032011-02-18 09:25:05 -080067 struct isci_host *ihost = data;
68 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -070069
Dan Williams0cf89d12011-02-18 09:25:07 -080070 if (scic_sds_controller_isr(scic))
71 tasklet_schedule(&ihost->completion_tasklet);
Dan Williams6f231dd2011-07-02 22:56:22 -070072
Dan Williamsc7ef4032011-02-18 09:25:05 -080073 return IRQ_HANDLED;
Dan Williams6f231dd2011-07-02 22:56:22 -070074}
75
Dan Williamsc7ef4032011-02-18 09:25:05 -080076irqreturn_t isci_intx_isr(int vec, void *data)
Dan Williams6f231dd2011-07-02 22:56:22 -070077{
78 struct pci_dev *pdev = data;
Dan Williamsc7ef4032011-02-18 09:25:05 -080079 struct isci_host *ihost;
Dan Williams6f231dd2011-07-02 22:56:22 -070080 irqreturn_t ret = IRQ_NONE;
Dan Williamsb329aff2011-03-07 16:02:25 -080081 int i;
Dan Williams6f231dd2011-07-02 22:56:22 -070082
Dan Williamsb329aff2011-03-07 16:02:25 -080083 for_each_isci_host(i, ihost, pdev) {
Dan Williamsc7ef4032011-02-18 09:25:05 -080084 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -070085
Dan Williams0cf89d12011-02-18 09:25:07 -080086 if (scic_sds_controller_isr(scic)) {
87 tasklet_schedule(&ihost->completion_tasklet);
88 ret = IRQ_HANDLED;
Dan Williams92f4f0f2011-02-18 09:25:11 -080089 } else if (scic_sds_controller_error_isr(scic)) {
90 spin_lock(&ihost->scic_lock);
91 scic_sds_controller_error_handler(scic);
92 spin_unlock(&ihost->scic_lock);
93 ret = IRQ_HANDLED;
Dan Williams0cf89d12011-02-18 09:25:07 -080094 }
Dan Williams6f231dd2011-07-02 22:56:22 -070095 }
Dan Williams92f4f0f2011-02-18 09:25:11 -080096
Dan Williams6f231dd2011-07-02 22:56:22 -070097 return ret;
98}
99
Dan Williams92f4f0f2011-02-18 09:25:11 -0800100irqreturn_t isci_error_isr(int vec, void *data)
101{
102 struct isci_host *ihost = data;
103 struct scic_sds_controller *scic = ihost->core_controller;
104
105 if (scic_sds_controller_error_isr(scic))
106 scic_sds_controller_error_handler(scic);
107
108 return IRQ_HANDLED;
109}
Dan Williams6f231dd2011-07-02 22:56:22 -0700110
111/**
112 * isci_host_start_complete() - This function is called by the core library,
113 * through the ISCI Module, to indicate controller start status.
114 * @isci_host: This parameter specifies the ISCI host object
115 * @completion_status: This parameter specifies the completion status from the
116 * core library.
117 *
118 */
Dan Williams0cf89d12011-02-18 09:25:07 -0800119void isci_host_start_complete(struct isci_host *ihost, enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700120{
Dan Williams0cf89d12011-02-18 09:25:07 -0800121 if (completion_status != SCI_SUCCESS)
122 dev_info(&ihost->pdev->dev,
123 "controller start timed out, continuing...\n");
124 isci_host_change_state(ihost, isci_ready);
125 clear_bit(IHOST_START_PENDING, &ihost->flags);
126 wake_up(&ihost->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700127}
128
Dan Williamsc7ef4032011-02-18 09:25:05 -0800129int isci_host_scan_finished(struct Scsi_Host *shost, unsigned long time)
Dan Williams6f231dd2011-07-02 22:56:22 -0700130{
Dan Williams0cf89d12011-02-18 09:25:07 -0800131 struct isci_host *ihost = isci_host_from_sas_ha(SHOST_TO_SAS_HA(shost));
Dan Williams6f231dd2011-07-02 22:56:22 -0700132
Edmund Nadolski77950f52011-02-18 09:25:09 -0800133 if (test_bit(IHOST_START_PENDING, &ihost->flags))
Dan Williams6f231dd2011-07-02 22:56:22 -0700134 return 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700135
Edmund Nadolski77950f52011-02-18 09:25:09 -0800136 /* todo: use sas_flush_discovery once it is upstream */
137 scsi_flush_work(shost);
138
139 scsi_flush_work(shost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700140
Dan Williams0cf89d12011-02-18 09:25:07 -0800141 dev_dbg(&ihost->pdev->dev,
142 "%s: ihost->status = %d, time = %ld\n",
143 __func__, isci_host_get_state(ihost), time);
Dan Williams6f231dd2011-07-02 22:56:22 -0700144
Dan Williams6f231dd2011-07-02 22:56:22 -0700145 return 1;
146
147}
148
Dan Williams6f231dd2011-07-02 22:56:22 -0700149void isci_host_scan_start(struct Scsi_Host *shost)
150{
Dan Williams0cf89d12011-02-18 09:25:07 -0800151 struct isci_host *ihost = isci_host_from_sas_ha(SHOST_TO_SAS_HA(shost));
152 struct scic_sds_controller *scic = ihost->core_controller;
153 unsigned long tmo = scic_controller_get_suggested_start_timeout(scic);
Dan Williams6f231dd2011-07-02 22:56:22 -0700154
Dan Williams0cf89d12011-02-18 09:25:07 -0800155 set_bit(IHOST_START_PENDING, &ihost->flags);
Edmund Nadolski77950f52011-02-18 09:25:09 -0800156
157 spin_lock_irq(&ihost->scic_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800158 scic_controller_start(scic, tmo);
Edmund Nadolski77950f52011-02-18 09:25:09 -0800159 scic_controller_enable_interrupts(scic);
160 spin_unlock_irq(&ihost->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -0700161}
162
Dan Williams0cf89d12011-02-18 09:25:07 -0800163void isci_host_stop_complete(struct isci_host *ihost, enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700164{
Dan Williams0cf89d12011-02-18 09:25:07 -0800165 isci_host_change_state(ihost, isci_stopped);
166 scic_controller_disable_interrupts(ihost->core_controller);
167 clear_bit(IHOST_STOP_PENDING, &ihost->flags);
168 wake_up(&ihost->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700169}
170
171static struct coherent_memory_info *isci_host_alloc_mdl_struct(
172 struct isci_host *isci_host,
173 u32 size)
174{
175 struct coherent_memory_info *mdl_struct;
176 void *uncached_address = NULL;
177
178
179 mdl_struct = devm_kzalloc(&isci_host->pdev->dev,
180 sizeof(*mdl_struct),
181 GFP_KERNEL);
182 if (!mdl_struct)
183 return NULL;
184
185 INIT_LIST_HEAD(&mdl_struct->node);
186
187 uncached_address = dmam_alloc_coherent(&isci_host->pdev->dev,
188 size,
189 &mdl_struct->dma_handle,
190 GFP_KERNEL);
191 if (!uncached_address)
192 return NULL;
193
194 /* memset the whole memory area. */
195 memset((char *)uncached_address, 0, size);
196 mdl_struct->vaddr = uncached_address;
197 mdl_struct->size = (size_t)size;
198
199 return mdl_struct;
200}
201
202static void isci_host_build_mde(
203 struct sci_physical_memory_descriptor *mde_struct,
204 struct coherent_memory_info *mdl_struct)
205{
206 unsigned long address = 0;
207 dma_addr_t dma_addr = 0;
208
209 address = (unsigned long)mdl_struct->vaddr;
210 dma_addr = mdl_struct->dma_handle;
211
212 /* to satisfy the alignment. */
213 if ((address % mde_struct->constant_memory_alignment) != 0) {
214 int align_offset
215 = (mde_struct->constant_memory_alignment
216 - (address % mde_struct->constant_memory_alignment));
217 address += align_offset;
218 dma_addr += align_offset;
219 }
220
221 mde_struct->virtual_address = (void *)address;
222 mde_struct->physical_address = dma_addr;
223 mdl_struct->mde = mde_struct;
224}
225
226static int isci_host_mdl_allocate_coherent(
227 struct isci_host *isci_host)
228{
229 struct sci_physical_memory_descriptor *current_mde;
230 struct coherent_memory_info *mdl_struct;
231 u32 size = 0;
232
233 struct sci_base_memory_descriptor_list *mdl_handle
234 = sci_controller_get_memory_descriptor_list_handle(
235 isci_host->core_controller);
236
237 sci_mdl_first_entry(mdl_handle);
238
239 current_mde = sci_mdl_get_current_entry(mdl_handle);
240
241 while (current_mde != NULL) {
242
243 size = (current_mde->constant_memory_size
244 + current_mde->constant_memory_alignment);
245
246 mdl_struct = isci_host_alloc_mdl_struct(isci_host, size);
247 if (!mdl_struct)
248 return -ENOMEM;
249
250 list_add_tail(&mdl_struct->node, &isci_host->mdl_struct_list);
251
252 isci_host_build_mde(current_mde, mdl_struct);
253
254 sci_mdl_next_entry(mdl_handle);
255 current_mde = sci_mdl_get_current_entry(mdl_handle);
256 }
257
258 return 0;
259}
260
261
262/**
263 * isci_host_completion_routine() - This function is the delayed service
264 * routine that calls the sci core library's completion handler. It's
265 * scheduled as a tasklet from the interrupt service routine when interrupts
266 * in use, or set as the timeout function in polled mode.
267 * @data: This parameter specifies the ISCI host object
268 *
269 */
270static void isci_host_completion_routine(unsigned long data)
271{
272 struct isci_host *isci_host = (struct isci_host *)data;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800273 struct list_head completed_request_list;
274 struct list_head errored_request_list;
275 struct list_head *current_position;
276 struct list_head *next_position;
Dan Williams6f231dd2011-07-02 22:56:22 -0700277 struct isci_request *request;
278 struct isci_request *next_request;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800279 struct sas_task *task;
Dan Williams6f231dd2011-07-02 22:56:22 -0700280
281 INIT_LIST_HEAD(&completed_request_list);
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800282 INIT_LIST_HEAD(&errored_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700283
284 spin_lock_irq(&isci_host->scic_lock);
285
Dan Williamsc7ef4032011-02-18 09:25:05 -0800286 scic_sds_controller_completion_handler(isci_host->core_controller);
287
Dan Williams6f231dd2011-07-02 22:56:22 -0700288 /* Take the lists of completed I/Os from the host. */
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800289
Dan Williams6f231dd2011-07-02 22:56:22 -0700290 list_splice_init(&isci_host->requests_to_complete,
291 &completed_request_list);
292
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800293 /* While holding the scic_lock take all of the normally completed
294 * I/Os off of the device's pending lists.
295 */
296 list_for_each_entry(request, &completed_request_list, completed_node) {
297
298 /* Remove the request from the remote device's list
299 * of pending requests.
300 */
301 list_del_init(&request->dev_node);
302 }
303
304 /* Take the list of errored I/Os from the host. */
305 list_splice_init(&isci_host->requests_to_errorback,
306 &errored_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700307
308 spin_unlock_irq(&isci_host->scic_lock);
309
310 /* Process any completions in the lists. */
311 list_for_each_safe(current_position, next_position,
312 &completed_request_list) {
313
314 request = list_entry(current_position, struct isci_request,
315 completed_node);
316 task = isci_request_access_task(request);
317
318 /* Normal notification (task_done) */
319 dev_dbg(&isci_host->pdev->dev,
320 "%s: Normal - request/task = %p/%p\n",
321 __func__,
322 request,
323 task);
324
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800325 /* Return the task to libsas */
326 if (task != NULL) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700327
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800328 task->lldd_task = NULL;
329 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
330
331 /* If the task is already in the abort path,
332 * the task_done callback cannot be called.
333 */
334 task->task_done(task);
335 }
336 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700337 /* Free the request object. */
338 isci_request_free(isci_host, request);
339 }
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800340 list_for_each_entry_safe(request, next_request, &errored_request_list,
Dan Williams6f231dd2011-07-02 22:56:22 -0700341 completed_node) {
342
343 task = isci_request_access_task(request);
344
345 /* Use sas_task_abort */
346 dev_warn(&isci_host->pdev->dev,
347 "%s: Error - request/task = %p/%p\n",
348 __func__,
349 request,
350 task);
351
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800352 if (task != NULL) {
353
354 /* Put the task into the abort path if it's not there
355 * already.
356 */
357 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED))
358 sas_task_abort(task);
359
360 } else {
361 /* This is a case where the request has completed with a
362 * status such that it needed further target servicing,
363 * but the sas_task reference has already been removed
364 * from the request. Since it was errored, it was not
365 * being aborted, so there is nothing to do except free
366 * it.
367 */
368
369 spin_lock_irq(&isci_host->scic_lock);
370 /* Remove the request from the remote device's list
371 * of pending requests.
372 */
373 list_del_init(&request->dev_node);
374 spin_unlock_irq(&isci_host->scic_lock);
375
376 /* Free the request object. */
377 isci_request_free(isci_host, request);
378 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700379 }
380
381}
382
Dan Williams0cf89d12011-02-18 09:25:07 -0800383void isci_host_deinit(struct isci_host *ihost)
Dan Williams6f231dd2011-07-02 22:56:22 -0700384{
Dan Williams0cf89d12011-02-18 09:25:07 -0800385 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -0700386 int i;
387
Dan Williams0cf89d12011-02-18 09:25:07 -0800388 isci_host_change_state(ihost, isci_stopping);
Dan Williams6f231dd2011-07-02 22:56:22 -0700389 for (i = 0; i < SCI_MAX_PORTS; i++) {
Dan Williams0cf89d12011-02-18 09:25:07 -0800390 struct isci_port *port = &ihost->isci_ports[i];
391 struct isci_remote_device *idev, *d;
392
393 list_for_each_entry_safe(idev, d, &port->remote_dev_list, node) {
394 isci_remote_device_change_state(idev, isci_stopping);
Dan Williams6ad31fe2011-03-04 12:10:29 -0800395 isci_remote_device_stop(ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700396 }
397 }
398
Dan Williams0cf89d12011-02-18 09:25:07 -0800399 set_bit(IHOST_STOP_PENDING, &ihost->flags);
Dan Williams7c40a802011-03-02 11:49:26 -0800400
401 spin_lock_irq(&ihost->scic_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800402 scic_controller_stop(scic, SCIC_CONTROLLER_STOP_TIMEOUT);
Dan Williams7c40a802011-03-02 11:49:26 -0800403 spin_unlock_irq(&ihost->scic_lock);
404
Dan Williams0cf89d12011-02-18 09:25:07 -0800405 wait_for_stop(ihost);
406 scic_controller_reset(scic);
Dan Williams7c40a802011-03-02 11:49:26 -0800407 isci_timer_list_destroy(ihost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700408}
409
Dan Williams6f231dd2011-07-02 22:56:22 -0700410static void __iomem *scu_base(struct isci_host *isci_host)
411{
412 struct pci_dev *pdev = isci_host->pdev;
413 int id = isci_host->id;
414
415 return pcim_iomap_table(pdev)[SCI_SCU_BAR * 2] + SCI_SCU_BAR_SIZE * id;
416}
417
418static void __iomem *smu_base(struct isci_host *isci_host)
419{
420 struct pci_dev *pdev = isci_host->pdev;
421 int id = isci_host->id;
422
423 return pcim_iomap_table(pdev)[SCI_SMU_BAR * 2] + SCI_SMU_BAR_SIZE * id;
424}
425
Dan Williams6f231dd2011-07-02 22:56:22 -0700426int isci_host_init(struct isci_host *isci_host)
427{
Dan Williamsd9c37392011-03-03 17:59:32 -0800428 int err = 0, i;
Dan Williams6f231dd2011-07-02 22:56:22 -0700429 enum sci_status status;
430 struct scic_sds_controller *controller;
Dan Williams6f231dd2011-07-02 22:56:22 -0700431 union scic_oem_parameters scic_oem_params;
432 union scic_user_parameters scic_user_params;
Dan Williams6f231dd2011-07-02 22:56:22 -0700433
Dan Williams7c40a802011-03-02 11:49:26 -0800434 isci_timer_list_construct(isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700435
436 controller = scic_controller_alloc(&isci_host->pdev->dev);
437
438 if (!controller) {
Dave Jiang858d4aa2011-02-22 01:27:03 -0800439 dev_err(&isci_host->pdev->dev,
440 "%s: failed (%d)\n",
441 __func__,
442 err);
443 return -ENOMEM;
Dan Williams6f231dd2011-07-02 22:56:22 -0700444 }
445
446 isci_host->core_controller = controller;
447 spin_lock_init(&isci_host->state_lock);
448 spin_lock_init(&isci_host->scic_lock);
449 spin_lock_init(&isci_host->queue_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800450 init_waitqueue_head(&isci_host->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700451
452 isci_host_change_state(isci_host, isci_starting);
453 isci_host->can_queue = ISCI_CAN_QUEUE_VAL;
454
455 status = scic_controller_construct(controller, scu_base(isci_host),
456 smu_base(isci_host));
457
458 if (status != SCI_SUCCESS) {
459 dev_err(&isci_host->pdev->dev,
460 "%s: scic_controller_construct failed - status = %x\n",
461 __func__,
462 status);
Dave Jiang858d4aa2011-02-22 01:27:03 -0800463 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -0700464 }
465
466 isci_host->sas_ha.dev = &isci_host->pdev->dev;
467 isci_host->sas_ha.lldd_ha = isci_host;
468
469 /*----------- SCIC controller Initialization Stuff ------------------
470 * set association host adapter struct in core controller.
471 */
472 sci_object_set_association(isci_host->core_controller,
Dave Jiang858d4aa2011-02-22 01:27:03 -0800473 (void *)isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700474
475 /* grab initial values stored in the controller object for OEM and USER
476 * parameters */
477 scic_oem_parameters_get(controller, &scic_oem_params);
478 scic_user_parameters_get(controller, &scic_user_params);
479
Dave Jiang858d4aa2011-02-22 01:27:03 -0800480 if (isci_firmware) {
481 /* grab any OEM and USER parameters specified in binary blob */
Dan Williams6f231dd2011-07-02 22:56:22 -0700482 status = isci_parse_oem_parameters(&scic_oem_params,
Dave Jiang858d4aa2011-02-22 01:27:03 -0800483 isci_host->id,
484 isci_firmware);
Dan Williams6f231dd2011-07-02 22:56:22 -0700485 if (status != SCI_SUCCESS) {
486 dev_warn(&isci_host->pdev->dev,
487 "parsing firmware oem parameters failed\n");
Dave Jiang858d4aa2011-02-22 01:27:03 -0800488 return -EINVAL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700489 }
490
491 status = isci_parse_user_parameters(&scic_user_params,
Dave Jiang858d4aa2011-02-22 01:27:03 -0800492 isci_host->id,
493 isci_firmware);
Dan Williams6f231dd2011-07-02 22:56:22 -0700494 if (status != SCI_SUCCESS) {
495 dev_warn(&isci_host->pdev->dev,
496 "%s: isci_parse_user_parameters"
497 " failed\n", __func__);
Dave Jiang858d4aa2011-02-22 01:27:03 -0800498 return -EINVAL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700499 }
Dave Jiang858d4aa2011-02-22 01:27:03 -0800500 } else {
501 status = scic_oem_parameters_set(isci_host->core_controller,
502 &scic_oem_params);
503 if (status != SCI_SUCCESS) {
504 dev_warn(&isci_host->pdev->dev,
505 "%s: scic_oem_parameters_set failed\n",
506 __func__);
507 return -ENODEV;
508 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700509
510
Dave Jiang858d4aa2011-02-22 01:27:03 -0800511 status = scic_user_parameters_set(isci_host->core_controller,
512 &scic_user_params);
513 if (status != SCI_SUCCESS) {
514 dev_warn(&isci_host->pdev->dev,
515 "%s: scic_user_parameters_set failed\n",
516 __func__);
517 return -ENODEV;
518 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700519 }
520
Dan Williams6f231dd2011-07-02 22:56:22 -0700521 tasklet_init(&isci_host->completion_tasklet,
Dan Williamsc7ef4032011-02-18 09:25:05 -0800522 isci_host_completion_routine, (unsigned long)isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700523
524 INIT_LIST_HEAD(&(isci_host->mdl_struct_list));
525
526 INIT_LIST_HEAD(&isci_host->requests_to_complete);
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800527 INIT_LIST_HEAD(&isci_host->requests_to_errorback);
Dan Williams6f231dd2011-07-02 22:56:22 -0700528
Dan Williams7c40a802011-03-02 11:49:26 -0800529 spin_lock_irq(&isci_host->scic_lock);
530 status = scic_controller_initialize(isci_host->core_controller);
531 spin_unlock_irq(&isci_host->scic_lock);
532 if (status != SCI_SUCCESS) {
533 dev_warn(&isci_host->pdev->dev,
534 "%s: scic_controller_initialize failed -"
535 " status = 0x%x\n",
536 __func__, status);
537 return -ENODEV;
538 }
539
Dan Williams6f231dd2011-07-02 22:56:22 -0700540 /* populate mdl with dma memory. scu_mdl_allocate_coherent() */
541 err = isci_host_mdl_allocate_coherent(isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700542 if (err)
Dave Jiang858d4aa2011-02-22 01:27:03 -0800543 return err;
Dan Williams6f231dd2011-07-02 22:56:22 -0700544
545 /*
546 * keep the pool alloc size around, will use it for a bounds checking
547 * when trying to convert virtual addresses to physical addresses
548 */
549 isci_host->dma_pool_alloc_size = sizeof(struct isci_request) +
550 scic_io_request_get_object_size();
551 isci_host->dma_pool = dmam_pool_create(DRV_NAME, &isci_host->pdev->dev,
552 isci_host->dma_pool_alloc_size,
553 SLAB_HWCACHE_ALIGN, 0);
554
Dave Jiang858d4aa2011-02-22 01:27:03 -0800555 if (!isci_host->dma_pool)
556 return -ENOMEM;
Dan Williams6f231dd2011-07-02 22:56:22 -0700557
Dan Williamsd9c37392011-03-03 17:59:32 -0800558 for (i = 0; i < SCI_MAX_PORTS; i++)
559 isci_port_init(&isci_host->isci_ports[i], isci_host, i);
Dan Williams6f231dd2011-07-02 22:56:22 -0700560
Dan Williamsd9c37392011-03-03 17:59:32 -0800561 for (i = 0; i < SCI_MAX_PHYS; i++)
562 isci_phy_init(&isci_host->phys[i], isci_host, i);
563
564 for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
565 struct isci_remote_device *idev = idev_by_id(isci_host, i);
566
567 INIT_LIST_HEAD(&idev->reqs_in_process);
568 INIT_LIST_HEAD(&idev->node);
569 spin_lock_init(&idev->state_lock);
570 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700571
Dave Jiang858d4aa2011-02-22 01:27:03 -0800572 return 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700573}