blob: d6e2a73e797ad2be2d3aa48ae21f89a493f24cb6 [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"
Dan Williamsd044af12011-03-08 09:52:49 -080064#include "probe_roms.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070065
Dan Williamsc7ef4032011-02-18 09:25:05 -080066irqreturn_t isci_msix_isr(int vec, void *data)
Dan Williams6f231dd2011-07-02 22:56:22 -070067{
Dan Williamsc7ef4032011-02-18 09:25:05 -080068 struct isci_host *ihost = data;
69 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -070070
Dan Williams0cf89d12011-02-18 09:25:07 -080071 if (scic_sds_controller_isr(scic))
72 tasklet_schedule(&ihost->completion_tasklet);
Dan Williams6f231dd2011-07-02 22:56:22 -070073
Dan Williamsc7ef4032011-02-18 09:25:05 -080074 return IRQ_HANDLED;
Dan Williams6f231dd2011-07-02 22:56:22 -070075}
76
Dan Williamsc7ef4032011-02-18 09:25:05 -080077irqreturn_t isci_intx_isr(int vec, void *data)
Dan Williams6f231dd2011-07-02 22:56:22 -070078{
79 struct pci_dev *pdev = data;
Dan Williamsc7ef4032011-02-18 09:25:05 -080080 struct isci_host *ihost;
Dan Williams6f231dd2011-07-02 22:56:22 -070081 irqreturn_t ret = IRQ_NONE;
Dan Williamsb329aff2011-03-07 16:02:25 -080082 int i;
Dan Williams6f231dd2011-07-02 22:56:22 -070083
Dan Williamsb329aff2011-03-07 16:02:25 -080084 for_each_isci_host(i, ihost, pdev) {
Dan Williamsc7ef4032011-02-18 09:25:05 -080085 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -070086
Dan Williams0cf89d12011-02-18 09:25:07 -080087 if (scic_sds_controller_isr(scic)) {
88 tasklet_schedule(&ihost->completion_tasklet);
89 ret = IRQ_HANDLED;
Dan Williams92f4f0f2011-02-18 09:25:11 -080090 } 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 Williams0cf89d12011-02-18 09:25:07 -080095 }
Dan Williams6f231dd2011-07-02 22:56:22 -070096 }
Dan Williams92f4f0f2011-02-18 09:25:11 -080097
Dan Williams6f231dd2011-07-02 22:56:22 -070098 return ret;
99}
100
Dan Williams92f4f0f2011-02-18 09:25:11 -0800101irqreturn_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 Williams6f231dd2011-07-02 22:56:22 -0700111
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 Williams0cf89d12011-02-18 09:25:07 -0800120void isci_host_start_complete(struct isci_host *ihost, enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700121{
Dan Williams0cf89d12011-02-18 09:25:07 -0800122 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 Williams6f231dd2011-07-02 22:56:22 -0700128}
129
Dan Williamsc7ef4032011-02-18 09:25:05 -0800130int isci_host_scan_finished(struct Scsi_Host *shost, unsigned long time)
Dan Williams6f231dd2011-07-02 22:56:22 -0700131{
Dan Williams0cf89d12011-02-18 09:25:07 -0800132 struct isci_host *ihost = isci_host_from_sas_ha(SHOST_TO_SAS_HA(shost));
Dan Williams6f231dd2011-07-02 22:56:22 -0700133
Edmund Nadolski77950f52011-02-18 09:25:09 -0800134 if (test_bit(IHOST_START_PENDING, &ihost->flags))
Dan Williams6f231dd2011-07-02 22:56:22 -0700135 return 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700136
Edmund Nadolski77950f52011-02-18 09:25:09 -0800137 /* todo: use sas_flush_discovery once it is upstream */
138 scsi_flush_work(shost);
139
140 scsi_flush_work(shost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700141
Dan Williams0cf89d12011-02-18 09:25:07 -0800142 dev_dbg(&ihost->pdev->dev,
143 "%s: ihost->status = %d, time = %ld\n",
144 __func__, isci_host_get_state(ihost), time);
Dan Williams6f231dd2011-07-02 22:56:22 -0700145
Dan Williams6f231dd2011-07-02 22:56:22 -0700146 return 1;
147
148}
149
Dan Williams6f231dd2011-07-02 22:56:22 -0700150void isci_host_scan_start(struct Scsi_Host *shost)
151{
Dan Williams0cf89d12011-02-18 09:25:07 -0800152 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 Williams6f231dd2011-07-02 22:56:22 -0700155
Dan Williams0cf89d12011-02-18 09:25:07 -0800156 set_bit(IHOST_START_PENDING, &ihost->flags);
Edmund Nadolski77950f52011-02-18 09:25:09 -0800157
158 spin_lock_irq(&ihost->scic_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800159 scic_controller_start(scic, tmo);
Edmund Nadolski77950f52011-02-18 09:25:09 -0800160 scic_controller_enable_interrupts(scic);
161 spin_unlock_irq(&ihost->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -0700162}
163
Dan Williams0cf89d12011-02-18 09:25:07 -0800164void isci_host_stop_complete(struct isci_host *ihost, enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700165{
Dan Williams0cf89d12011-02-18 09:25:07 -0800166 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 Williams6f231dd2011-07-02 22:56:22 -0700170}
171
172static 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
203static 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
227static 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 */
271static void isci_host_completion_routine(unsigned long data)
272{
273 struct isci_host *isci_host = (struct isci_host *)data;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800274 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 Williams6f231dd2011-07-02 22:56:22 -0700278 struct isci_request *request;
279 struct isci_request *next_request;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800280 struct sas_task *task;
Dan Williams6f231dd2011-07-02 22:56:22 -0700281
282 INIT_LIST_HEAD(&completed_request_list);
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800283 INIT_LIST_HEAD(&errored_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700284
285 spin_lock_irq(&isci_host->scic_lock);
286
Dan Williamsc7ef4032011-02-18 09:25:05 -0800287 scic_sds_controller_completion_handler(isci_host->core_controller);
288
Dan Williams6f231dd2011-07-02 22:56:22 -0700289 /* Take the lists of completed I/Os from the host. */
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800290
Dan Williams6f231dd2011-07-02 22:56:22 -0700291 list_splice_init(&isci_host->requests_to_complete,
292 &completed_request_list);
293
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800294 /* Take the list of errored I/Os from the host. */
295 list_splice_init(&isci_host->requests_to_errorback,
296 &errored_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700297
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 Skirvin11b00c12011-03-04 14:06:40 -0800315 /* Return the task to libsas */
316 if (task != NULL) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700317
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800318 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 Williams6f231dd2011-07-02 22:56:22 -0700327 /* Free the request object. */
328 isci_request_free(isci_host, request);
329 }
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800330 list_for_each_entry_safe(request, next_request, &errored_request_list,
Dan Williams6f231dd2011-07-02 22:56:22 -0700331 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 Skirvin11b00c12011-03-04 14:06:40 -0800342 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 Williams6f231dd2011-07-02 22:56:22 -0700369 }
370
371}
372
Dan Williams0cf89d12011-02-18 09:25:07 -0800373void isci_host_deinit(struct isci_host *ihost)
Dan Williams6f231dd2011-07-02 22:56:22 -0700374{
Dan Williams0cf89d12011-02-18 09:25:07 -0800375 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -0700376 int i;
377
Dan Williams0cf89d12011-02-18 09:25:07 -0800378 isci_host_change_state(ihost, isci_stopping);
Dan Williams6f231dd2011-07-02 22:56:22 -0700379 for (i = 0; i < SCI_MAX_PORTS; i++) {
Dan Williams0cf89d12011-02-18 09:25:07 -0800380 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 Williams6ad31fe2011-03-04 12:10:29 -0800385 isci_remote_device_stop(ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700386 }
387 }
388
Dan Williams0cf89d12011-02-18 09:25:07 -0800389 set_bit(IHOST_STOP_PENDING, &ihost->flags);
Dan Williams7c40a802011-03-02 11:49:26 -0800390
391 spin_lock_irq(&ihost->scic_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800392 scic_controller_stop(scic, SCIC_CONTROLLER_STOP_TIMEOUT);
Dan Williams7c40a802011-03-02 11:49:26 -0800393 spin_unlock_irq(&ihost->scic_lock);
394
Dan Williams0cf89d12011-02-18 09:25:07 -0800395 wait_for_stop(ihost);
396 scic_controller_reset(scic);
Dan Williams7c40a802011-03-02 11:49:26 -0800397 isci_timer_list_destroy(ihost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700398}
399
Dan Williams6f231dd2011-07-02 22:56:22 -0700400static 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
408static 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 Williams6f231dd2011-07-02 22:56:22 -0700416int isci_host_init(struct isci_host *isci_host)
417{
Dan Williamsd9c37392011-03-03 17:59:32 -0800418 int err = 0, i;
Dan Williams6f231dd2011-07-02 22:56:22 -0700419 enum sci_status status;
420 struct scic_sds_controller *controller;
Dan Williams4711ba12011-03-11 10:43:57 -0800421 union scic_oem_parameters oem;
Dan Williams6f231dd2011-07-02 22:56:22 -0700422 union scic_user_parameters scic_user_params;
Dan Williamsd044af12011-03-08 09:52:49 -0800423 struct isci_pci_info *pci_info = to_pci_info(isci_host->pdev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700424
Dan Williams7c40a802011-03-02 11:49:26 -0800425 isci_timer_list_construct(isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700426
427 controller = scic_controller_alloc(&isci_host->pdev->dev);
428
429 if (!controller) {
Dave Jiang858d4aa2011-02-22 01:27:03 -0800430 dev_err(&isci_host->pdev->dev,
431 "%s: failed (%d)\n",
432 __func__,
433 err);
434 return -ENOMEM;
Dan Williams6f231dd2011-07-02 22:56:22 -0700435 }
436
437 isci_host->core_controller = controller;
Dan Williams4711ba12011-03-11 10:43:57 -0800438 sci_object_set_association(isci_host->core_controller, isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700439 spin_lock_init(&isci_host->state_lock);
440 spin_lock_init(&isci_host->scic_lock);
441 spin_lock_init(&isci_host->queue_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800442 init_waitqueue_head(&isci_host->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700443
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 Jiang858d4aa2011-02-22 01:27:03 -0800455 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -0700456 }
457
458 isci_host->sas_ha.dev = &isci_host->pdev->dev;
459 isci_host->sas_ha.lldd_ha = isci_host;
460
Dan Williamsd044af12011-03-08 09:52:49 -0800461 /*
462 * grab initial values stored in the controller object for OEM and USER
463 * parameters
464 */
Dan Williams6f231dd2011-07-02 22:56:22 -0700465 scic_user_parameters_get(controller, &scic_user_params);
Dan Williamsd044af12011-03-08 09:52:49 -0800466 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 Williams6f231dd2011-07-02 22:56:22 -0700474
Dan Williams4711ba12011-03-11 10:43:57 -0800475 scic_oem_parameters_get(controller, &oem);
Dan Williamsd044af12011-03-08 09:52:49 -0800476
477 /* grab any OEM parameters specified in orom */
478 if (pci_info->orom) {
Dan Williams4711ba12011-03-11 10:43:57 -0800479 status = isci_parse_oem_parameters(&oem,
Dan Williamsd044af12011-03-08 09:52:49 -0800480 pci_info->orom,
481 isci_host->id);
Dan Williams6f231dd2011-07-02 22:56:22 -0700482 if (status != SCI_SUCCESS) {
483 dev_warn(&isci_host->pdev->dev,
484 "parsing firmware oem parameters failed\n");
Dave Jiang858d4aa2011-02-22 01:27:03 -0800485 return -EINVAL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700486 }
Dan Williams4711ba12011-03-11 10:43:57 -0800487 }
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 Williams6f231dd2011-07-02 22:56:22 -0700495 }
496
Dan Williams6f231dd2011-07-02 22:56:22 -0700497 tasklet_init(&isci_host->completion_tasklet,
Dan Williamsc7ef4032011-02-18 09:25:05 -0800498 isci_host_completion_routine, (unsigned long)isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700499
500 INIT_LIST_HEAD(&(isci_host->mdl_struct_list));
501
502 INIT_LIST_HEAD(&isci_host->requests_to_complete);
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800503 INIT_LIST_HEAD(&isci_host->requests_to_errorback);
Dan Williams6f231dd2011-07-02 22:56:22 -0700504
Dan Williams7c40a802011-03-02 11:49:26 -0800505 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 Williams6f231dd2011-07-02 22:56:22 -0700516 /* populate mdl with dma memory. scu_mdl_allocate_coherent() */
517 err = isci_host_mdl_allocate_coherent(isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700518 if (err)
Dave Jiang858d4aa2011-02-22 01:27:03 -0800519 return err;
Dan Williams6f231dd2011-07-02 22:56:22 -0700520
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 Jiang858d4aa2011-02-22 01:27:03 -0800531 if (!isci_host->dma_pool)
532 return -ENOMEM;
Dan Williams6f231dd2011-07-02 22:56:22 -0700533
Dan Williamsd9c37392011-03-03 17:59:32 -0800534 for (i = 0; i < SCI_MAX_PORTS; i++)
535 isci_port_init(&isci_host->isci_ports[i], isci_host, i);
Dan Williams6f231dd2011-07-02 22:56:22 -0700536
Dan Williamsd9c37392011-03-03 17:59:32 -0800537 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 Williams6f231dd2011-07-02 22:56:22 -0700547
Dave Jiang858d4aa2011-02-22 01:27:03 -0800548 return 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700549}