blob: 7f351a35e87b0c35cd8a4866052a09347fa656ba [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;
81
Dan Williamsc7ef4032011-02-18 09:25:05 -080082 for_each_isci_host(ihost, pdev) {
83 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -070084
Dan Williams0cf89d12011-02-18 09:25:07 -080085 if (scic_sds_controller_isr(scic)) {
86 tasklet_schedule(&ihost->completion_tasklet);
87 ret = IRQ_HANDLED;
88 }
Dan Williams6f231dd2011-07-02 22:56:22 -070089 }
90 return ret;
91}
92
93
94/**
95 * isci_host_start_complete() - This function is called by the core library,
96 * through the ISCI Module, to indicate controller start status.
97 * @isci_host: This parameter specifies the ISCI host object
98 * @completion_status: This parameter specifies the completion status from the
99 * core library.
100 *
101 */
Dan Williams0cf89d12011-02-18 09:25:07 -0800102void isci_host_start_complete(struct isci_host *ihost, enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700103{
Dan Williams0cf89d12011-02-18 09:25:07 -0800104 if (completion_status != SCI_SUCCESS)
105 dev_info(&ihost->pdev->dev,
106 "controller start timed out, continuing...\n");
107 isci_host_change_state(ihost, isci_ready);
108 clear_bit(IHOST_START_PENDING, &ihost->flags);
109 wake_up(&ihost->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700110}
111
Dan Williamsc7ef4032011-02-18 09:25:05 -0800112int isci_host_scan_finished(struct Scsi_Host *shost, unsigned long time)
Dan Williams6f231dd2011-07-02 22:56:22 -0700113{
Dan Williams0cf89d12011-02-18 09:25:07 -0800114 struct isci_host *ihost = isci_host_from_sas_ha(SHOST_TO_SAS_HA(shost));
Dan Williams6f231dd2011-07-02 22:56:22 -0700115
Edmund Nadolski77950f52011-02-18 09:25:09 -0800116 if (test_bit(IHOST_START_PENDING, &ihost->flags))
Dan Williams6f231dd2011-07-02 22:56:22 -0700117 return 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700118
Edmund Nadolski77950f52011-02-18 09:25:09 -0800119 /* todo: use sas_flush_discovery once it is upstream */
120 scsi_flush_work(shost);
121
122 scsi_flush_work(shost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700123
Dan Williams0cf89d12011-02-18 09:25:07 -0800124 dev_dbg(&ihost->pdev->dev,
125 "%s: ihost->status = %d, time = %ld\n",
126 __func__, isci_host_get_state(ihost), time);
Dan Williams6f231dd2011-07-02 22:56:22 -0700127
Dan Williams6f231dd2011-07-02 22:56:22 -0700128 return 1;
129
130}
131
Dan Williams6f231dd2011-07-02 22:56:22 -0700132void isci_host_scan_start(struct Scsi_Host *shost)
133{
Dan Williams0cf89d12011-02-18 09:25:07 -0800134 struct isci_host *ihost = isci_host_from_sas_ha(SHOST_TO_SAS_HA(shost));
135 struct scic_sds_controller *scic = ihost->core_controller;
136 unsigned long tmo = scic_controller_get_suggested_start_timeout(scic);
Dan Williams6f231dd2011-07-02 22:56:22 -0700137
Dan Williams0cf89d12011-02-18 09:25:07 -0800138 set_bit(IHOST_START_PENDING, &ihost->flags);
Edmund Nadolski77950f52011-02-18 09:25:09 -0800139
140 spin_lock_irq(&ihost->scic_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800141 scic_controller_start(scic, tmo);
Edmund Nadolski77950f52011-02-18 09:25:09 -0800142 scic_controller_enable_interrupts(scic);
143 spin_unlock_irq(&ihost->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -0700144}
145
Dan Williams0cf89d12011-02-18 09:25:07 -0800146void isci_host_stop_complete(struct isci_host *ihost, enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700147{
Dan Williams0cf89d12011-02-18 09:25:07 -0800148 isci_host_change_state(ihost, isci_stopped);
149 scic_controller_disable_interrupts(ihost->core_controller);
150 clear_bit(IHOST_STOP_PENDING, &ihost->flags);
151 wake_up(&ihost->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700152}
153
154static struct coherent_memory_info *isci_host_alloc_mdl_struct(
155 struct isci_host *isci_host,
156 u32 size)
157{
158 struct coherent_memory_info *mdl_struct;
159 void *uncached_address = NULL;
160
161
162 mdl_struct = devm_kzalloc(&isci_host->pdev->dev,
163 sizeof(*mdl_struct),
164 GFP_KERNEL);
165 if (!mdl_struct)
166 return NULL;
167
168 INIT_LIST_HEAD(&mdl_struct->node);
169
170 uncached_address = dmam_alloc_coherent(&isci_host->pdev->dev,
171 size,
172 &mdl_struct->dma_handle,
173 GFP_KERNEL);
174 if (!uncached_address)
175 return NULL;
176
177 /* memset the whole memory area. */
178 memset((char *)uncached_address, 0, size);
179 mdl_struct->vaddr = uncached_address;
180 mdl_struct->size = (size_t)size;
181
182 return mdl_struct;
183}
184
185static void isci_host_build_mde(
186 struct sci_physical_memory_descriptor *mde_struct,
187 struct coherent_memory_info *mdl_struct)
188{
189 unsigned long address = 0;
190 dma_addr_t dma_addr = 0;
191
192 address = (unsigned long)mdl_struct->vaddr;
193 dma_addr = mdl_struct->dma_handle;
194
195 /* to satisfy the alignment. */
196 if ((address % mde_struct->constant_memory_alignment) != 0) {
197 int align_offset
198 = (mde_struct->constant_memory_alignment
199 - (address % mde_struct->constant_memory_alignment));
200 address += align_offset;
201 dma_addr += align_offset;
202 }
203
204 mde_struct->virtual_address = (void *)address;
205 mde_struct->physical_address = dma_addr;
206 mdl_struct->mde = mde_struct;
207}
208
209static int isci_host_mdl_allocate_coherent(
210 struct isci_host *isci_host)
211{
212 struct sci_physical_memory_descriptor *current_mde;
213 struct coherent_memory_info *mdl_struct;
214 u32 size = 0;
215
216 struct sci_base_memory_descriptor_list *mdl_handle
217 = sci_controller_get_memory_descriptor_list_handle(
218 isci_host->core_controller);
219
220 sci_mdl_first_entry(mdl_handle);
221
222 current_mde = sci_mdl_get_current_entry(mdl_handle);
223
224 while (current_mde != NULL) {
225
226 size = (current_mde->constant_memory_size
227 + current_mde->constant_memory_alignment);
228
229 mdl_struct = isci_host_alloc_mdl_struct(isci_host, size);
230 if (!mdl_struct)
231 return -ENOMEM;
232
233 list_add_tail(&mdl_struct->node, &isci_host->mdl_struct_list);
234
235 isci_host_build_mde(current_mde, mdl_struct);
236
237 sci_mdl_next_entry(mdl_handle);
238 current_mde = sci_mdl_get_current_entry(mdl_handle);
239 }
240
241 return 0;
242}
243
244
245/**
246 * isci_host_completion_routine() - This function is the delayed service
247 * routine that calls the sci core library's completion handler. It's
248 * scheduled as a tasklet from the interrupt service routine when interrupts
249 * in use, or set as the timeout function in polled mode.
250 * @data: This parameter specifies the ISCI host object
251 *
252 */
253static void isci_host_completion_routine(unsigned long data)
254{
255 struct isci_host *isci_host = (struct isci_host *)data;
Dan Williams6f231dd2011-07-02 22:56:22 -0700256 struct list_head completed_request_list;
257 struct list_head aborted_request_list;
258 struct list_head *current_position;
259 struct list_head *next_position;
260 struct isci_request *request;
261 struct isci_request *next_request;
262 struct sas_task *task;
263
264 INIT_LIST_HEAD(&completed_request_list);
265 INIT_LIST_HEAD(&aborted_request_list);
266
267 spin_lock_irq(&isci_host->scic_lock);
268
Dan Williamsc7ef4032011-02-18 09:25:05 -0800269 scic_sds_controller_completion_handler(isci_host->core_controller);
270
Dan Williams6f231dd2011-07-02 22:56:22 -0700271 /* Take the lists of completed I/Os from the host. */
272 list_splice_init(&isci_host->requests_to_complete,
273 &completed_request_list);
274
275 list_splice_init(&isci_host->requests_to_abort,
276 &aborted_request_list);
277
278 spin_unlock_irq(&isci_host->scic_lock);
279
280 /* Process any completions in the lists. */
281 list_for_each_safe(current_position, next_position,
282 &completed_request_list) {
283
284 request = list_entry(current_position, struct isci_request,
285 completed_node);
286 task = isci_request_access_task(request);
287
288 /* Normal notification (task_done) */
289 dev_dbg(&isci_host->pdev->dev,
290 "%s: Normal - request/task = %p/%p\n",
291 __func__,
292 request,
293 task);
294
295 task->task_done(task);
296 task->lldd_task = NULL;
297
298 /* Free the request object. */
299 isci_request_free(isci_host, request);
300 }
301 list_for_each_entry_safe(request, next_request, &aborted_request_list,
302 completed_node) {
303
304 task = isci_request_access_task(request);
305
306 /* Use sas_task_abort */
307 dev_warn(&isci_host->pdev->dev,
308 "%s: Error - request/task = %p/%p\n",
309 __func__,
310 request,
311 task);
312
313 /* Put the task into the abort path. */
314 sas_task_abort(task);
315 }
316
317}
318
Dan Williams0cf89d12011-02-18 09:25:07 -0800319void isci_host_deinit(struct isci_host *ihost)
Dan Williams6f231dd2011-07-02 22:56:22 -0700320{
Dan Williams0cf89d12011-02-18 09:25:07 -0800321 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -0700322 int i;
323
Dan Williams0cf89d12011-02-18 09:25:07 -0800324 isci_host_change_state(ihost, isci_stopping);
Dan Williams6f231dd2011-07-02 22:56:22 -0700325 for (i = 0; i < SCI_MAX_PORTS; i++) {
Dan Williams0cf89d12011-02-18 09:25:07 -0800326 struct isci_port *port = &ihost->isci_ports[i];
327 struct isci_remote_device *idev, *d;
328
329 list_for_each_entry_safe(idev, d, &port->remote_dev_list, node) {
330 isci_remote_device_change_state(idev, isci_stopping);
331 isci_remote_device_stop(idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700332 }
333 }
334
Dan Williams0cf89d12011-02-18 09:25:07 -0800335 set_bit(IHOST_STOP_PENDING, &ihost->flags);
336 scic_controller_stop(scic, SCIC_CONTROLLER_STOP_TIMEOUT);
337 wait_for_stop(ihost);
338 scic_controller_reset(scic);
Dan Williams6f231dd2011-07-02 22:56:22 -0700339}
340
341static int isci_verify_firmware(const struct firmware *fw,
342 struct isci_firmware *isci_fw)
343{
344 const u8 *tmp;
345
346 if (fw->size < ISCI_FIRMWARE_MIN_SIZE)
347 return -EINVAL;
348
349 tmp = fw->data;
350
351 /* 12th char should be the NULL terminate for the ID string */
352 if (tmp[11] != '\0')
353 return -EINVAL;
354
355 if (strncmp("#SCU MAGIC#", tmp, 11) != 0)
356 return -EINVAL;
357
358 isci_fw->id = tmp;
359 isci_fw->version = fw->data[ISCI_FW_VER_OFS];
360 isci_fw->subversion = fw->data[ISCI_FW_SUBVER_OFS];
361
362 tmp = fw->data + ISCI_FW_DATA_OFS;
363
364 while (*tmp != ISCI_FW_HDR_EOF) {
365 switch (*tmp) {
366 case ISCI_FW_HDR_PHYMASK:
367 tmp++;
368 isci_fw->phy_masks_size = *tmp;
369 tmp++;
370 isci_fw->phy_masks = (const u32 *)tmp;
371 tmp += sizeof(u32) * isci_fw->phy_masks_size;
372 break;
373
374 case ISCI_FW_HDR_PHYGEN:
375 tmp++;
376 isci_fw->phy_gens_size = *tmp;
377 tmp++;
378 isci_fw->phy_gens = (const u32 *)tmp;
379 tmp += sizeof(u32) * isci_fw->phy_gens_size;
380 break;
381
382 case ISCI_FW_HDR_SASADDR:
383 tmp++;
384 isci_fw->sas_addrs_size = *tmp;
385 tmp++;
386 isci_fw->sas_addrs = (const u64 *)tmp;
387 tmp += sizeof(u64) * isci_fw->sas_addrs_size;
388 break;
389
390 default:
391 pr_err("bad field in firmware binary blob\n");
392 return -EINVAL;
393 }
394 }
395
396 pr_info("isci firmware v%u.%u loaded.\n",
397 isci_fw->version, isci_fw->subversion);
398
399 return SCI_SUCCESS;
400}
401
402static void __iomem *scu_base(struct isci_host *isci_host)
403{
404 struct pci_dev *pdev = isci_host->pdev;
405 int id = isci_host->id;
406
407 return pcim_iomap_table(pdev)[SCI_SCU_BAR * 2] + SCI_SCU_BAR_SIZE * id;
408}
409
410static void __iomem *smu_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_SMU_BAR * 2] + SCI_SMU_BAR_SIZE * id;
416}
417
418#define SCI_MAX_TIMER_COUNT 25
419
420int isci_host_init(struct isci_host *isci_host)
421{
422 int err = 0;
423 int index = 0;
424 enum sci_status status;
425 struct scic_sds_controller *controller;
426 struct scic_sds_port *scic_port;
Dan Williams6f231dd2011-07-02 22:56:22 -0700427 union scic_oem_parameters scic_oem_params;
428 union scic_user_parameters scic_user_params;
429 const struct firmware *fw = NULL;
430 struct isci_firmware *isci_fw = NULL;
431
432 INIT_LIST_HEAD(&isci_host->timer_list_struct.timers);
433 isci_timer_list_construct(
434 &isci_host->timer_list_struct,
435 SCI_MAX_TIMER_COUNT
436 );
437
438 controller = scic_controller_alloc(&isci_host->pdev->dev);
439
440 if (!controller) {
441 err = -ENOMEM;
442 dev_err(&isci_host->pdev->dev, "%s: failed (%d)\n", __func__, err);
443 goto out;
444 }
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);
463 err = -ENODEV;
464 goto out;
465 }
466
467 isci_host->sas_ha.dev = &isci_host->pdev->dev;
468 isci_host->sas_ha.lldd_ha = isci_host;
469
470 /*----------- SCIC controller Initialization Stuff ------------------
471 * set association host adapter struct in core controller.
472 */
473 sci_object_set_association(isci_host->core_controller,
474 (void *)isci_host
475 );
476
477 /* grab initial values stored in the controller object for OEM and USER
478 * parameters */
479 scic_oem_parameters_get(controller, &scic_oem_params);
480 scic_user_parameters_get(controller, &scic_user_params);
481
482 isci_fw = devm_kzalloc(&isci_host->pdev->dev,
483 sizeof(struct isci_firmware),
484 GFP_KERNEL);
485 if (!isci_fw) {
486 dev_warn(&isci_host->pdev->dev,
487 "allocating firmware struct failed\n");
488 dev_warn(&isci_host->pdev->dev,
489 "Default OEM configuration being used:"
490 " 4 narrow ports, and default SAS Addresses\n");
491 goto set_default_params;
492 }
493
494 status = request_firmware(&fw, ISCI_FW_NAME, &isci_host->pdev->dev);
495 if (status) {
496 dev_warn(&isci_host->pdev->dev,
497 "Loading firmware failed, using default values\n");
498 dev_warn(&isci_host->pdev->dev,
499 "Default OEM configuration being used:"
500 " 4 narrow ports, and default SAS Addresses\n");
501 goto set_default_params;
502 }
503 else {
504 status = isci_verify_firmware(fw, isci_fw);
505 if (status != SCI_SUCCESS) {
506 dev_warn(&isci_host->pdev->dev,
507 "firmware verification failed\n");
508 dev_warn(&isci_host->pdev->dev,
509 "Default OEM configuration being used:"
510 " 4 narrow ports, and default SAS "
511 "Addresses\n");
512 goto set_default_params;
513 }
514
515 /* grab any OEM and USER parameters specified at module load */
516 status = isci_parse_oem_parameters(&scic_oem_params,
517 isci_host->id, isci_fw);
518 if (status != SCI_SUCCESS) {
519 dev_warn(&isci_host->pdev->dev,
520 "parsing firmware oem parameters failed\n");
521 err = -EINVAL;
522 goto out;
523 }
524
525 status = isci_parse_user_parameters(&scic_user_params,
526 isci_host->id, isci_fw);
527 if (status != SCI_SUCCESS) {
528 dev_warn(&isci_host->pdev->dev,
529 "%s: isci_parse_user_parameters"
530 " failed\n", __func__);
531 err = -EINVAL;
532 goto out;
533 }
534 }
535
536 set_default_params:
537
538 status = scic_oem_parameters_set(isci_host->core_controller,
539 &scic_oem_params
540 );
541
542 if (status != SCI_SUCCESS) {
543 dev_warn(&isci_host->pdev->dev,
544 "%s: scic_oem_parameters_set failed\n",
545 __func__);
546 err = -ENODEV;
547 goto out;
548 }
549
550
551 status = scic_user_parameters_set(isci_host->core_controller,
552 &scic_user_params
553 );
554
555 if (status != SCI_SUCCESS) {
556 dev_warn(&isci_host->pdev->dev,
557 "%s: scic_user_parameters_set failed\n",
558 __func__);
559 err = -ENODEV;
560 goto out;
561 }
562
563 status = scic_controller_initialize(isci_host->core_controller);
564 if (status != SCI_SUCCESS) {
565 dev_warn(&isci_host->pdev->dev,
566 "%s: scic_controller_initialize failed -"
567 " status = 0x%x\n",
568 __func__, status);
569 err = -ENODEV;
570 goto out;
571 }
572
Dan Williams6f231dd2011-07-02 22:56:22 -0700573 tasklet_init(&isci_host->completion_tasklet,
Dan Williamsc7ef4032011-02-18 09:25:05 -0800574 isci_host_completion_routine, (unsigned long)isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700575
576 INIT_LIST_HEAD(&(isci_host->mdl_struct_list));
577
578 INIT_LIST_HEAD(&isci_host->requests_to_complete);
579 INIT_LIST_HEAD(&isci_host->requests_to_abort);
580
581 /* populate mdl with dma memory. scu_mdl_allocate_coherent() */
582 err = isci_host_mdl_allocate_coherent(isci_host);
583
584 if (err)
585 goto err_out;
586
587 /*
588 * keep the pool alloc size around, will use it for a bounds checking
589 * when trying to convert virtual addresses to physical addresses
590 */
591 isci_host->dma_pool_alloc_size = sizeof(struct isci_request) +
592 scic_io_request_get_object_size();
593 isci_host->dma_pool = dmam_pool_create(DRV_NAME, &isci_host->pdev->dev,
594 isci_host->dma_pool_alloc_size,
595 SLAB_HWCACHE_ALIGN, 0);
596
597 if (!isci_host->dma_pool) {
598 err = -ENOMEM;
599 goto req_obj_err_out;
600 }
601
602 for (index = 0; index < SCI_MAX_PORTS; index++) {
603 isci_port_init(&isci_host->isci_ports[index],
604 isci_host, index);
605 }
606
607 for (index = 0; index < SCI_MAX_PHYS; index++)
608 isci_phy_init(&isci_host->phys[index], isci_host, index);
609
610 /* Why are we doing this? Is this even necessary? */
611 memcpy(&isci_host->sas_addr[0], &isci_host->phys[0].sas_addr[0],
612 SAS_ADDR_SIZE);
613
614 /* Start the ports */
615 for (index = 0; index < SCI_MAX_PORTS; index++) {
616
617 scic_controller_get_port_handle(controller, index, &scic_port);
618 scic_port_start(scic_port);
619 }
620
621 goto out;
622
623/* SPB_Debug: destroy request object cache */
624 req_obj_err_out:
625/* SPB_Debug: destroy remote object cache */
626 err_out:
627/* SPB_Debug: undo controller init, construct and alloc, remove from parent
628 * controller list. */
629 out:
630 if (fw)
631 release_firmware(fw);
632 return err;
633}