blob: b66e62027247faf4d86287ab07a19f2f1f669cb1 [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 Williamsc7ef4032011-02-18 09:25:05 -080070 if (isci_host_get_state(ihost) != isci_starting) {
71 if (scic_sds_controller_isr(scic)) {
72 if (isci_host_get_state(ihost) != isci_stopped)
73 tasklet_schedule(&ihost->completion_tasklet);
74 else
75 dev_dbg(&ihost->pdev->dev,
76 "%s: controller stopped\n", __func__);
Dan Williams6f231dd2011-07-02 22:56:22 -070077 }
Dan Williamsc7ef4032011-02-18 09:25:05 -080078 }
Dan Williams6f231dd2011-07-02 22:56:22 -070079
Dan Williamsc7ef4032011-02-18 09:25:05 -080080 return IRQ_HANDLED;
Dan Williams6f231dd2011-07-02 22:56:22 -070081}
82
Dan Williamsc7ef4032011-02-18 09:25:05 -080083irqreturn_t isci_intx_isr(int vec, void *data)
Dan Williams6f231dd2011-07-02 22:56:22 -070084{
85 struct pci_dev *pdev = data;
Dan Williamsc7ef4032011-02-18 09:25:05 -080086 struct isci_host *ihost;
Dan Williams6f231dd2011-07-02 22:56:22 -070087 irqreturn_t ret = IRQ_NONE;
88
Dan Williamsc7ef4032011-02-18 09:25:05 -080089 for_each_isci_host(ihost, pdev) {
90 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -070091
Dan Williamsc7ef4032011-02-18 09:25:05 -080092 if (isci_host_get_state(ihost) != isci_starting) {
93 if (scic_sds_controller_isr(scic)) {
94 if (isci_host_get_state(ihost) != isci_stopped)
95 tasklet_schedule(&ihost->completion_tasklet);
96 else
97 dev_dbg(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -070098 "%s: controller stopped\n",
99 __func__);
100 ret = IRQ_HANDLED;
101 }
102 } else
Dan Williamsc7ef4032011-02-18 09:25:05 -0800103 dev_warn(&ihost->pdev->dev,
Dan Williams6f231dd2011-07-02 22:56:22 -0700104 "%s: get_handler_methods failed, "
Dan Williamsc7ef4032011-02-18 09:25:05 -0800105 "ihost->status = 0x%x\n",
Dan Williams6f231dd2011-07-02 22:56:22 -0700106 __func__,
Dan Williamsc7ef4032011-02-18 09:25:05 -0800107 isci_host_get_state(ihost));
Dan Williams6f231dd2011-07-02 22:56:22 -0700108 }
109 return ret;
110}
111
112
113/**
114 * isci_host_start_complete() - This function is called by the core library,
115 * through the ISCI Module, to indicate controller start status.
116 * @isci_host: This parameter specifies the ISCI host object
117 * @completion_status: This parameter specifies the completion status from the
118 * core library.
119 *
120 */
121void isci_host_start_complete(
122 struct isci_host *isci_host,
123 enum sci_status completion_status)
124{
125 if (completion_status == SCI_SUCCESS) {
126 dev_dbg(&isci_host->pdev->dev,
127 "%s: completion_status: SCI_SUCCESS\n", __func__);
128 isci_host_change_state(isci_host, isci_ready);
129 complete_all(&isci_host->start_complete);
130 } else
131 dev_err(&isci_host->pdev->dev,
132 "controller start failed with "
133 "completion_status = 0x%x;",
134 completion_status);
135
136}
137
Dan Williamsc7ef4032011-02-18 09:25:05 -0800138int isci_host_scan_finished(struct Scsi_Host *shost, unsigned long time)
Dan Williams6f231dd2011-07-02 22:56:22 -0700139{
Dan Williamsc7ef4032011-02-18 09:25:05 -0800140 struct isci_host *isci_host = isci_host_from_sas_ha(SHOST_TO_SAS_HA(shost));
Dan Williams6f231dd2011-07-02 22:56:22 -0700141
142 /**
143 * check interrupt_handler's status and call completion_handler if true,
144 * link_up events should be coming from the scu core lib, as phy's come
145 * online. for each link_up from the core, call
146 * get_received_identify_address_frame, copy the frame into the
147 * sas_phy object and call libsas notify_port_event(PORTE_BYTES_DMAED).
148 * continue to return zero from thee scan_finished routine until
149 * the scic_cb_controller_start_complete() call comes from the core.
150 **/
Dan Williamsc7ef4032011-02-18 09:25:05 -0800151 if (scic_sds_controller_isr(isci_host->core_controller))
152 scic_sds_controller_completion_handler(isci_host->core_controller);
Dan Williams6f231dd2011-07-02 22:56:22 -0700153
154 if (isci_starting == isci_host_get_state(isci_host)
155 && time < (HZ * 10)) {
156 dev_dbg(&isci_host->pdev->dev,
157 "%s: isci_host->status = %d, time = %ld\n",
158 __func__, isci_host_get_state(isci_host), time);
159 return 0;
160 }
161
162
163 dev_dbg(&isci_host->pdev->dev,
164 "%s: isci_host->status = %d, time = %ld\n",
165 __func__, isci_host_get_state(isci_host), time);
166
167 scic_controller_enable_interrupts(isci_host->core_controller);
168
169 return 1;
170
171}
172
173
174/**
175 * isci_host_scan_start() - This function is one of the SCSI Host Template
176 * function, called by the SCSI mid layer berfore a target scan begins. The
177 * core library controller start routine is called from here.
178 * @shost: This parameter specifies the SCSI host to be scanned
179 *
180 */
181void isci_host_scan_start(struct Scsi_Host *shost)
182{
183 struct isci_host *isci_host;
184
185 isci_host = isci_host_from_sas_ha(SHOST_TO_SAS_HA(shost));
186 isci_host_change_state(isci_host, isci_starting);
187
188 scic_controller_disable_interrupts(isci_host->core_controller);
189 init_completion(&isci_host->start_complete);
190 scic_controller_start(
191 isci_host->core_controller,
192 scic_controller_get_suggested_start_timeout(
193 isci_host->core_controller)
194 );
195}
196
197void isci_host_stop_complete(
198 struct isci_host *isci_host,
199 enum sci_status completion_status)
200{
201 isci_host_change_state(isci_host, isci_stopped);
202 scic_controller_disable_interrupts(
203 isci_host->core_controller
204 );
205 complete(&isci_host->stop_complete);
206}
207
208static struct coherent_memory_info *isci_host_alloc_mdl_struct(
209 struct isci_host *isci_host,
210 u32 size)
211{
212 struct coherent_memory_info *mdl_struct;
213 void *uncached_address = NULL;
214
215
216 mdl_struct = devm_kzalloc(&isci_host->pdev->dev,
217 sizeof(*mdl_struct),
218 GFP_KERNEL);
219 if (!mdl_struct)
220 return NULL;
221
222 INIT_LIST_HEAD(&mdl_struct->node);
223
224 uncached_address = dmam_alloc_coherent(&isci_host->pdev->dev,
225 size,
226 &mdl_struct->dma_handle,
227 GFP_KERNEL);
228 if (!uncached_address)
229 return NULL;
230
231 /* memset the whole memory area. */
232 memset((char *)uncached_address, 0, size);
233 mdl_struct->vaddr = uncached_address;
234 mdl_struct->size = (size_t)size;
235
236 return mdl_struct;
237}
238
239static void isci_host_build_mde(
240 struct sci_physical_memory_descriptor *mde_struct,
241 struct coherent_memory_info *mdl_struct)
242{
243 unsigned long address = 0;
244 dma_addr_t dma_addr = 0;
245
246 address = (unsigned long)mdl_struct->vaddr;
247 dma_addr = mdl_struct->dma_handle;
248
249 /* to satisfy the alignment. */
250 if ((address % mde_struct->constant_memory_alignment) != 0) {
251 int align_offset
252 = (mde_struct->constant_memory_alignment
253 - (address % mde_struct->constant_memory_alignment));
254 address += align_offset;
255 dma_addr += align_offset;
256 }
257
258 mde_struct->virtual_address = (void *)address;
259 mde_struct->physical_address = dma_addr;
260 mdl_struct->mde = mde_struct;
261}
262
263static int isci_host_mdl_allocate_coherent(
264 struct isci_host *isci_host)
265{
266 struct sci_physical_memory_descriptor *current_mde;
267 struct coherent_memory_info *mdl_struct;
268 u32 size = 0;
269
270 struct sci_base_memory_descriptor_list *mdl_handle
271 = sci_controller_get_memory_descriptor_list_handle(
272 isci_host->core_controller);
273
274 sci_mdl_first_entry(mdl_handle);
275
276 current_mde = sci_mdl_get_current_entry(mdl_handle);
277
278 while (current_mde != NULL) {
279
280 size = (current_mde->constant_memory_size
281 + current_mde->constant_memory_alignment);
282
283 mdl_struct = isci_host_alloc_mdl_struct(isci_host, size);
284 if (!mdl_struct)
285 return -ENOMEM;
286
287 list_add_tail(&mdl_struct->node, &isci_host->mdl_struct_list);
288
289 isci_host_build_mde(current_mde, mdl_struct);
290
291 sci_mdl_next_entry(mdl_handle);
292 current_mde = sci_mdl_get_current_entry(mdl_handle);
293 }
294
295 return 0;
296}
297
298
299/**
300 * isci_host_completion_routine() - This function is the delayed service
301 * routine that calls the sci core library's completion handler. It's
302 * scheduled as a tasklet from the interrupt service routine when interrupts
303 * in use, or set as the timeout function in polled mode.
304 * @data: This parameter specifies the ISCI host object
305 *
306 */
307static void isci_host_completion_routine(unsigned long data)
308{
309 struct isci_host *isci_host = (struct isci_host *)data;
Dan Williams6f231dd2011-07-02 22:56:22 -0700310 struct list_head completed_request_list;
311 struct list_head aborted_request_list;
312 struct list_head *current_position;
313 struct list_head *next_position;
314 struct isci_request *request;
315 struct isci_request *next_request;
316 struct sas_task *task;
317
318 INIT_LIST_HEAD(&completed_request_list);
319 INIT_LIST_HEAD(&aborted_request_list);
320
321 spin_lock_irq(&isci_host->scic_lock);
322
Dan Williamsc7ef4032011-02-18 09:25:05 -0800323 scic_sds_controller_completion_handler(isci_host->core_controller);
324
Dan Williams6f231dd2011-07-02 22:56:22 -0700325 /* Take the lists of completed I/Os from the host. */
326 list_splice_init(&isci_host->requests_to_complete,
327 &completed_request_list);
328
329 list_splice_init(&isci_host->requests_to_abort,
330 &aborted_request_list);
331
332 spin_unlock_irq(&isci_host->scic_lock);
333
334 /* Process any completions in the lists. */
335 list_for_each_safe(current_position, next_position,
336 &completed_request_list) {
337
338 request = list_entry(current_position, struct isci_request,
339 completed_node);
340 task = isci_request_access_task(request);
341
342 /* Normal notification (task_done) */
343 dev_dbg(&isci_host->pdev->dev,
344 "%s: Normal - request/task = %p/%p\n",
345 __func__,
346 request,
347 task);
348
349 task->task_done(task);
350 task->lldd_task = NULL;
351
352 /* Free the request object. */
353 isci_request_free(isci_host, request);
354 }
355 list_for_each_entry_safe(request, next_request, &aborted_request_list,
356 completed_node) {
357
358 task = isci_request_access_task(request);
359
360 /* Use sas_task_abort */
361 dev_warn(&isci_host->pdev->dev,
362 "%s: Error - request/task = %p/%p\n",
363 __func__,
364 request,
365 task);
366
367 /* Put the task into the abort path. */
368 sas_task_abort(task);
369 }
370
371}
372
373void isci_host_deinit(
374 struct isci_host *isci_host)
375{
376 int i;
377
378 isci_host_change_state(isci_host, isci_stopping);
379 for (i = 0; i < SCI_MAX_PORTS; i++) {
380 struct isci_port *port = &isci_host->isci_ports[i];
381 struct isci_remote_device *device, *tmpdev;
382 list_for_each_entry_safe(device, tmpdev,
383 &port->remote_dev_list, node) {
384 isci_remote_device_change_state(device, isci_stopping);
385 isci_remote_device_stop(device);
386 }
387 }
388
389 /* stop the comtroller and wait for completion. */
390 init_completion(&isci_host->stop_complete);
391 scic_controller_stop(
392 isci_host->core_controller,
393 SCIC_CONTROLLER_STOP_TIMEOUT
394 );
395 wait_for_completion(&isci_host->stop_complete);
396 /* next, reset the controller. */
397 scic_controller_reset(isci_host->core_controller);
398}
399
400static int isci_verify_firmware(const struct firmware *fw,
401 struct isci_firmware *isci_fw)
402{
403 const u8 *tmp;
404
405 if (fw->size < ISCI_FIRMWARE_MIN_SIZE)
406 return -EINVAL;
407
408 tmp = fw->data;
409
410 /* 12th char should be the NULL terminate for the ID string */
411 if (tmp[11] != '\0')
412 return -EINVAL;
413
414 if (strncmp("#SCU MAGIC#", tmp, 11) != 0)
415 return -EINVAL;
416
417 isci_fw->id = tmp;
418 isci_fw->version = fw->data[ISCI_FW_VER_OFS];
419 isci_fw->subversion = fw->data[ISCI_FW_SUBVER_OFS];
420
421 tmp = fw->data + ISCI_FW_DATA_OFS;
422
423 while (*tmp != ISCI_FW_HDR_EOF) {
424 switch (*tmp) {
425 case ISCI_FW_HDR_PHYMASK:
426 tmp++;
427 isci_fw->phy_masks_size = *tmp;
428 tmp++;
429 isci_fw->phy_masks = (const u32 *)tmp;
430 tmp += sizeof(u32) * isci_fw->phy_masks_size;
431 break;
432
433 case ISCI_FW_HDR_PHYGEN:
434 tmp++;
435 isci_fw->phy_gens_size = *tmp;
436 tmp++;
437 isci_fw->phy_gens = (const u32 *)tmp;
438 tmp += sizeof(u32) * isci_fw->phy_gens_size;
439 break;
440
441 case ISCI_FW_HDR_SASADDR:
442 tmp++;
443 isci_fw->sas_addrs_size = *tmp;
444 tmp++;
445 isci_fw->sas_addrs = (const u64 *)tmp;
446 tmp += sizeof(u64) * isci_fw->sas_addrs_size;
447 break;
448
449 default:
450 pr_err("bad field in firmware binary blob\n");
451 return -EINVAL;
452 }
453 }
454
455 pr_info("isci firmware v%u.%u loaded.\n",
456 isci_fw->version, isci_fw->subversion);
457
458 return SCI_SUCCESS;
459}
460
461static void __iomem *scu_base(struct isci_host *isci_host)
462{
463 struct pci_dev *pdev = isci_host->pdev;
464 int id = isci_host->id;
465
466 return pcim_iomap_table(pdev)[SCI_SCU_BAR * 2] + SCI_SCU_BAR_SIZE * id;
467}
468
469static void __iomem *smu_base(struct isci_host *isci_host)
470{
471 struct pci_dev *pdev = isci_host->pdev;
472 int id = isci_host->id;
473
474 return pcim_iomap_table(pdev)[SCI_SMU_BAR * 2] + SCI_SMU_BAR_SIZE * id;
475}
476
477#define SCI_MAX_TIMER_COUNT 25
478
479int isci_host_init(struct isci_host *isci_host)
480{
481 int err = 0;
482 int index = 0;
483 enum sci_status status;
484 struct scic_sds_controller *controller;
485 struct scic_sds_port *scic_port;
Dan Williams6f231dd2011-07-02 22:56:22 -0700486 union scic_oem_parameters scic_oem_params;
487 union scic_user_parameters scic_user_params;
488 const struct firmware *fw = NULL;
489 struct isci_firmware *isci_fw = NULL;
490
491 INIT_LIST_HEAD(&isci_host->timer_list_struct.timers);
492 isci_timer_list_construct(
493 &isci_host->timer_list_struct,
494 SCI_MAX_TIMER_COUNT
495 );
496
497 controller = scic_controller_alloc(&isci_host->pdev->dev);
498
499 if (!controller) {
500 err = -ENOMEM;
501 dev_err(&isci_host->pdev->dev, "%s: failed (%d)\n", __func__, err);
502 goto out;
503 }
504
505 isci_host->core_controller = controller;
506 spin_lock_init(&isci_host->state_lock);
507 spin_lock_init(&isci_host->scic_lock);
508 spin_lock_init(&isci_host->queue_lock);
509
510 isci_host_change_state(isci_host, isci_starting);
511 isci_host->can_queue = ISCI_CAN_QUEUE_VAL;
512
513 status = scic_controller_construct(controller, scu_base(isci_host),
514 smu_base(isci_host));
515
516 if (status != SCI_SUCCESS) {
517 dev_err(&isci_host->pdev->dev,
518 "%s: scic_controller_construct failed - status = %x\n",
519 __func__,
520 status);
521 err = -ENODEV;
522 goto out;
523 }
524
525 isci_host->sas_ha.dev = &isci_host->pdev->dev;
526 isci_host->sas_ha.lldd_ha = isci_host;
527
528 /*----------- SCIC controller Initialization Stuff ------------------
529 * set association host adapter struct in core controller.
530 */
531 sci_object_set_association(isci_host->core_controller,
532 (void *)isci_host
533 );
534
535 /* grab initial values stored in the controller object for OEM and USER
536 * parameters */
537 scic_oem_parameters_get(controller, &scic_oem_params);
538 scic_user_parameters_get(controller, &scic_user_params);
539
540 isci_fw = devm_kzalloc(&isci_host->pdev->dev,
541 sizeof(struct isci_firmware),
542 GFP_KERNEL);
543 if (!isci_fw) {
544 dev_warn(&isci_host->pdev->dev,
545 "allocating firmware struct failed\n");
546 dev_warn(&isci_host->pdev->dev,
547 "Default OEM configuration being used:"
548 " 4 narrow ports, and default SAS Addresses\n");
549 goto set_default_params;
550 }
551
552 status = request_firmware(&fw, ISCI_FW_NAME, &isci_host->pdev->dev);
553 if (status) {
554 dev_warn(&isci_host->pdev->dev,
555 "Loading firmware failed, using default values\n");
556 dev_warn(&isci_host->pdev->dev,
557 "Default OEM configuration being used:"
558 " 4 narrow ports, and default SAS Addresses\n");
559 goto set_default_params;
560 }
561 else {
562 status = isci_verify_firmware(fw, isci_fw);
563 if (status != SCI_SUCCESS) {
564 dev_warn(&isci_host->pdev->dev,
565 "firmware verification failed\n");
566 dev_warn(&isci_host->pdev->dev,
567 "Default OEM configuration being used:"
568 " 4 narrow ports, and default SAS "
569 "Addresses\n");
570 goto set_default_params;
571 }
572
573 /* grab any OEM and USER parameters specified at module load */
574 status = isci_parse_oem_parameters(&scic_oem_params,
575 isci_host->id, isci_fw);
576 if (status != SCI_SUCCESS) {
577 dev_warn(&isci_host->pdev->dev,
578 "parsing firmware oem parameters failed\n");
579 err = -EINVAL;
580 goto out;
581 }
582
583 status = isci_parse_user_parameters(&scic_user_params,
584 isci_host->id, isci_fw);
585 if (status != SCI_SUCCESS) {
586 dev_warn(&isci_host->pdev->dev,
587 "%s: isci_parse_user_parameters"
588 " failed\n", __func__);
589 err = -EINVAL;
590 goto out;
591 }
592 }
593
594 set_default_params:
595
596 status = scic_oem_parameters_set(isci_host->core_controller,
597 &scic_oem_params
598 );
599
600 if (status != SCI_SUCCESS) {
601 dev_warn(&isci_host->pdev->dev,
602 "%s: scic_oem_parameters_set failed\n",
603 __func__);
604 err = -ENODEV;
605 goto out;
606 }
607
608
609 status = scic_user_parameters_set(isci_host->core_controller,
610 &scic_user_params
611 );
612
613 if (status != SCI_SUCCESS) {
614 dev_warn(&isci_host->pdev->dev,
615 "%s: scic_user_parameters_set failed\n",
616 __func__);
617 err = -ENODEV;
618 goto out;
619 }
620
621 status = scic_controller_initialize(isci_host->core_controller);
622 if (status != SCI_SUCCESS) {
623 dev_warn(&isci_host->pdev->dev,
624 "%s: scic_controller_initialize failed -"
625 " status = 0x%x\n",
626 __func__, status);
627 err = -ENODEV;
628 goto out;
629 }
630
Dan Williams6f231dd2011-07-02 22:56:22 -0700631 tasklet_init(&isci_host->completion_tasklet,
Dan Williamsc7ef4032011-02-18 09:25:05 -0800632 isci_host_completion_routine, (unsigned long)isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700633
634 INIT_LIST_HEAD(&(isci_host->mdl_struct_list));
635
636 INIT_LIST_HEAD(&isci_host->requests_to_complete);
637 INIT_LIST_HEAD(&isci_host->requests_to_abort);
638
639 /* populate mdl with dma memory. scu_mdl_allocate_coherent() */
640 err = isci_host_mdl_allocate_coherent(isci_host);
641
642 if (err)
643 goto err_out;
644
645 /*
646 * keep the pool alloc size around, will use it for a bounds checking
647 * when trying to convert virtual addresses to physical addresses
648 */
649 isci_host->dma_pool_alloc_size = sizeof(struct isci_request) +
650 scic_io_request_get_object_size();
651 isci_host->dma_pool = dmam_pool_create(DRV_NAME, &isci_host->pdev->dev,
652 isci_host->dma_pool_alloc_size,
653 SLAB_HWCACHE_ALIGN, 0);
654
655 if (!isci_host->dma_pool) {
656 err = -ENOMEM;
657 goto req_obj_err_out;
658 }
659
660 for (index = 0; index < SCI_MAX_PORTS; index++) {
661 isci_port_init(&isci_host->isci_ports[index],
662 isci_host, index);
663 }
664
665 for (index = 0; index < SCI_MAX_PHYS; index++)
666 isci_phy_init(&isci_host->phys[index], isci_host, index);
667
668 /* Why are we doing this? Is this even necessary? */
669 memcpy(&isci_host->sas_addr[0], &isci_host->phys[0].sas_addr[0],
670 SAS_ADDR_SIZE);
671
672 /* Start the ports */
673 for (index = 0; index < SCI_MAX_PORTS; index++) {
674
675 scic_controller_get_port_handle(controller, index, &scic_port);
676 scic_port_start(scic_port);
677 }
678
679 goto out;
680
681/* SPB_Debug: destroy request object cache */
682 req_obj_err_out:
683/* SPB_Debug: destroy remote object cache */
684 err_out:
685/* SPB_Debug: undo controller init, construct and alloc, remove from parent
686 * controller list. */
687 out:
688 if (fw)
689 release_firmware(fw);
690 return err;
691}