blob: 927f08892ad6e8bdf864965e0159524556456de6 [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"
Christoph Hellwigca841f02011-03-28 09:21:04 -040065#include "core/scic_sds_controller.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070066
Dan Williamsc7ef4032011-02-18 09:25:05 -080067irqreturn_t isci_msix_isr(int vec, void *data)
Dan Williams6f231dd2011-07-02 22:56:22 -070068{
Dan Williamsc7ef4032011-02-18 09:25:05 -080069 struct isci_host *ihost = data;
70 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -070071
Dan Williams0cf89d12011-02-18 09:25:07 -080072 if (scic_sds_controller_isr(scic))
73 tasklet_schedule(&ihost->completion_tasklet);
Dan Williams6f231dd2011-07-02 22:56:22 -070074
Dan Williamsc7ef4032011-02-18 09:25:05 -080075 return IRQ_HANDLED;
Dan Williams6f231dd2011-07-02 22:56:22 -070076}
77
Dan Williamsc7ef4032011-02-18 09:25:05 -080078irqreturn_t isci_intx_isr(int vec, void *data)
Dan Williams6f231dd2011-07-02 22:56:22 -070079{
80 struct pci_dev *pdev = data;
Dan Williamsc7ef4032011-02-18 09:25:05 -080081 struct isci_host *ihost;
Dan Williams6f231dd2011-07-02 22:56:22 -070082 irqreturn_t ret = IRQ_NONE;
Dan Williamsb329aff2011-03-07 16:02:25 -080083 int i;
Dan Williams6f231dd2011-07-02 22:56:22 -070084
Dan Williamsb329aff2011-03-07 16:02:25 -080085 for_each_isci_host(i, ihost, pdev) {
Dan Williamsc7ef4032011-02-18 09:25:05 -080086 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -070087
Dan Williams0cf89d12011-02-18 09:25:07 -080088 if (scic_sds_controller_isr(scic)) {
89 tasklet_schedule(&ihost->completion_tasklet);
90 ret = IRQ_HANDLED;
Dan Williams92f4f0f2011-02-18 09:25:11 -080091 } else if (scic_sds_controller_error_isr(scic)) {
92 spin_lock(&ihost->scic_lock);
93 scic_sds_controller_error_handler(scic);
94 spin_unlock(&ihost->scic_lock);
95 ret = IRQ_HANDLED;
Dan Williams0cf89d12011-02-18 09:25:07 -080096 }
Dan Williams6f231dd2011-07-02 22:56:22 -070097 }
Dan Williams92f4f0f2011-02-18 09:25:11 -080098
Dan Williams6f231dd2011-07-02 22:56:22 -070099 return ret;
100}
101
Dan Williams92f4f0f2011-02-18 09:25:11 -0800102irqreturn_t isci_error_isr(int vec, void *data)
103{
104 struct isci_host *ihost = data;
105 struct scic_sds_controller *scic = ihost->core_controller;
106
107 if (scic_sds_controller_error_isr(scic))
108 scic_sds_controller_error_handler(scic);
109
110 return IRQ_HANDLED;
111}
Dan Williams6f231dd2011-07-02 22:56:22 -0700112
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 */
Dan Williams0cf89d12011-02-18 09:25:07 -0800121void isci_host_start_complete(struct isci_host *ihost, enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700122{
Dan Williams0cf89d12011-02-18 09:25:07 -0800123 if (completion_status != SCI_SUCCESS)
124 dev_info(&ihost->pdev->dev,
125 "controller start timed out, continuing...\n");
126 isci_host_change_state(ihost, isci_ready);
127 clear_bit(IHOST_START_PENDING, &ihost->flags);
128 wake_up(&ihost->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700129}
130
Dan Williamsc7ef4032011-02-18 09:25:05 -0800131int isci_host_scan_finished(struct Scsi_Host *shost, unsigned long time)
Dan Williams6f231dd2011-07-02 22:56:22 -0700132{
Dan Williams4393aa42011-03-31 13:10:44 -0700133 struct isci_host *ihost = SHOST_TO_SAS_HA(shost)->lldd_ha;
Dan Williams6f231dd2011-07-02 22:56:22 -0700134
Edmund Nadolski77950f52011-02-18 09:25:09 -0800135 if (test_bit(IHOST_START_PENDING, &ihost->flags))
Dan Williams6f231dd2011-07-02 22:56:22 -0700136 return 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700137
Edmund Nadolski77950f52011-02-18 09:25:09 -0800138 /* todo: use sas_flush_discovery once it is upstream */
139 scsi_flush_work(shost);
140
141 scsi_flush_work(shost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700142
Dan Williams0cf89d12011-02-18 09:25:07 -0800143 dev_dbg(&ihost->pdev->dev,
144 "%s: ihost->status = %d, time = %ld\n",
145 __func__, isci_host_get_state(ihost), time);
Dan Williams6f231dd2011-07-02 22:56:22 -0700146
Dan Williams6f231dd2011-07-02 22:56:22 -0700147 return 1;
148
149}
150
Dan Williams6f231dd2011-07-02 22:56:22 -0700151void isci_host_scan_start(struct Scsi_Host *shost)
152{
Dan Williams4393aa42011-03-31 13:10:44 -0700153 struct isci_host *ihost = SHOST_TO_SAS_HA(shost)->lldd_ha;
Dan Williams0cf89d12011-02-18 09:25:07 -0800154 struct scic_sds_controller *scic = ihost->core_controller;
155 unsigned long tmo = scic_controller_get_suggested_start_timeout(scic);
Dan Williams6f231dd2011-07-02 22:56:22 -0700156
Dan Williams0cf89d12011-02-18 09:25:07 -0800157 set_bit(IHOST_START_PENDING, &ihost->flags);
Edmund Nadolski77950f52011-02-18 09:25:09 -0800158
159 spin_lock_irq(&ihost->scic_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800160 scic_controller_start(scic, tmo);
Edmund Nadolski77950f52011-02-18 09:25:09 -0800161 scic_controller_enable_interrupts(scic);
162 spin_unlock_irq(&ihost->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -0700163}
164
Dan Williams0cf89d12011-02-18 09:25:07 -0800165void isci_host_stop_complete(struct isci_host *ihost, enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700166{
Dan Williams0cf89d12011-02-18 09:25:07 -0800167 isci_host_change_state(ihost, isci_stopped);
168 scic_controller_disable_interrupts(ihost->core_controller);
169 clear_bit(IHOST_STOP_PENDING, &ihost->flags);
170 wake_up(&ihost->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700171}
172
Dan Williams6f231dd2011-07-02 22:56:22 -0700173/**
174 * isci_host_completion_routine() - This function is the delayed service
175 * routine that calls the sci core library's completion handler. It's
176 * scheduled as a tasklet from the interrupt service routine when interrupts
177 * in use, or set as the timeout function in polled mode.
178 * @data: This parameter specifies the ISCI host object
179 *
180 */
181static void isci_host_completion_routine(unsigned long data)
182{
183 struct isci_host *isci_host = (struct isci_host *)data;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800184 struct list_head completed_request_list;
185 struct list_head errored_request_list;
186 struct list_head *current_position;
187 struct list_head *next_position;
Dan Williams6f231dd2011-07-02 22:56:22 -0700188 struct isci_request *request;
189 struct isci_request *next_request;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800190 struct sas_task *task;
Dan Williams6f231dd2011-07-02 22:56:22 -0700191
192 INIT_LIST_HEAD(&completed_request_list);
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800193 INIT_LIST_HEAD(&errored_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700194
195 spin_lock_irq(&isci_host->scic_lock);
196
Dan Williamsc7ef4032011-02-18 09:25:05 -0800197 scic_sds_controller_completion_handler(isci_host->core_controller);
198
Dan Williams6f231dd2011-07-02 22:56:22 -0700199 /* Take the lists of completed I/Os from the host. */
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800200
Dan Williams6f231dd2011-07-02 22:56:22 -0700201 list_splice_init(&isci_host->requests_to_complete,
202 &completed_request_list);
203
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800204 /* Take the list of errored I/Os from the host. */
205 list_splice_init(&isci_host->requests_to_errorback,
206 &errored_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700207
208 spin_unlock_irq(&isci_host->scic_lock);
209
210 /* Process any completions in the lists. */
211 list_for_each_safe(current_position, next_position,
212 &completed_request_list) {
213
214 request = list_entry(current_position, struct isci_request,
215 completed_node);
216 task = isci_request_access_task(request);
217
218 /* Normal notification (task_done) */
219 dev_dbg(&isci_host->pdev->dev,
220 "%s: Normal - request/task = %p/%p\n",
221 __func__,
222 request,
223 task);
224
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800225 /* Return the task to libsas */
226 if (task != NULL) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700227
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800228 task->lldd_task = NULL;
229 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
230
231 /* If the task is already in the abort path,
232 * the task_done callback cannot be called.
233 */
234 task->task_done(task);
235 }
236 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700237 /* Free the request object. */
238 isci_request_free(isci_host, request);
239 }
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800240 list_for_each_entry_safe(request, next_request, &errored_request_list,
Dan Williams6f231dd2011-07-02 22:56:22 -0700241 completed_node) {
242
243 task = isci_request_access_task(request);
244
245 /* Use sas_task_abort */
246 dev_warn(&isci_host->pdev->dev,
247 "%s: Error - request/task = %p/%p\n",
248 __func__,
249 request,
250 task);
251
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800252 if (task != NULL) {
253
254 /* Put the task into the abort path if it's not there
255 * already.
256 */
257 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED))
258 sas_task_abort(task);
259
260 } else {
261 /* This is a case where the request has completed with a
262 * status such that it needed further target servicing,
263 * but the sas_task reference has already been removed
264 * from the request. Since it was errored, it was not
265 * being aborted, so there is nothing to do except free
266 * it.
267 */
268
269 spin_lock_irq(&isci_host->scic_lock);
270 /* Remove the request from the remote device's list
271 * of pending requests.
272 */
273 list_del_init(&request->dev_node);
274 spin_unlock_irq(&isci_host->scic_lock);
275
276 /* Free the request object. */
277 isci_request_free(isci_host, request);
278 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700279 }
280
281}
282
Dan Williams0cf89d12011-02-18 09:25:07 -0800283void isci_host_deinit(struct isci_host *ihost)
Dan Williams6f231dd2011-07-02 22:56:22 -0700284{
Dan Williams0cf89d12011-02-18 09:25:07 -0800285 struct scic_sds_controller *scic = ihost->core_controller;
Dan Williams6f231dd2011-07-02 22:56:22 -0700286 int i;
287
Dan Williams0cf89d12011-02-18 09:25:07 -0800288 isci_host_change_state(ihost, isci_stopping);
Dan Williams6f231dd2011-07-02 22:56:22 -0700289 for (i = 0; i < SCI_MAX_PORTS; i++) {
Dan Williams0cf89d12011-02-18 09:25:07 -0800290 struct isci_port *port = &ihost->isci_ports[i];
291 struct isci_remote_device *idev, *d;
292
293 list_for_each_entry_safe(idev, d, &port->remote_dev_list, node) {
294 isci_remote_device_change_state(idev, isci_stopping);
Dan Williams6ad31fe2011-03-04 12:10:29 -0800295 isci_remote_device_stop(ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700296 }
297 }
298
Dan Williams0cf89d12011-02-18 09:25:07 -0800299 set_bit(IHOST_STOP_PENDING, &ihost->flags);
Dan Williams7c40a802011-03-02 11:49:26 -0800300
301 spin_lock_irq(&ihost->scic_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800302 scic_controller_stop(scic, SCIC_CONTROLLER_STOP_TIMEOUT);
Dan Williams7c40a802011-03-02 11:49:26 -0800303 spin_unlock_irq(&ihost->scic_lock);
304
Dan Williams0cf89d12011-02-18 09:25:07 -0800305 wait_for_stop(ihost);
306 scic_controller_reset(scic);
Dan Williams7c40a802011-03-02 11:49:26 -0800307 isci_timer_list_destroy(ihost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700308}
309
Dan Williams6f231dd2011-07-02 22:56:22 -0700310static void __iomem *scu_base(struct isci_host *isci_host)
311{
312 struct pci_dev *pdev = isci_host->pdev;
313 int id = isci_host->id;
314
315 return pcim_iomap_table(pdev)[SCI_SCU_BAR * 2] + SCI_SCU_BAR_SIZE * id;
316}
317
318static void __iomem *smu_base(struct isci_host *isci_host)
319{
320 struct pci_dev *pdev = isci_host->pdev;
321 int id = isci_host->id;
322
323 return pcim_iomap_table(pdev)[SCI_SMU_BAR * 2] + SCI_SMU_BAR_SIZE * id;
324}
325
Dave Jiangb5f18a22011-03-16 14:57:23 -0700326static void isci_user_parameters_get(
327 struct isci_host *isci_host,
328 union scic_user_parameters *scic_user_params)
329{
330 struct scic_sds_user_parameters *u = &scic_user_params->sds1;
331 int i;
332
333 for (i = 0; i < SCI_MAX_PHYS; i++) {
334 struct sci_phy_user_params *u_phy = &u->phys[i];
335
336 u_phy->max_speed_generation = phy_gen;
337
338 /* we are not exporting these for now */
339 u_phy->align_insertion_frequency = 0x7f;
340 u_phy->in_connection_align_insertion_frequency = 0xff;
341 u_phy->notify_enable_spin_up_insertion_frequency = 0x33;
342 }
343
344 u->stp_inactivity_timeout = stp_inactive_to;
345 u->ssp_inactivity_timeout = ssp_inactive_to;
346 u->stp_max_occupancy_timeout = stp_max_occ_to;
347 u->ssp_max_occupancy_timeout = ssp_max_occ_to;
348 u->no_outbound_task_timeout = no_outbound_task_to;
349 u->max_number_concurrent_device_spin_up = max_concurr_spinup;
350}
351
Dan Williams6f231dd2011-07-02 22:56:22 -0700352int isci_host_init(struct isci_host *isci_host)
353{
Dan Williamsd9c37392011-03-03 17:59:32 -0800354 int err = 0, i;
Dan Williams6f231dd2011-07-02 22:56:22 -0700355 enum sci_status status;
356 struct scic_sds_controller *controller;
Dan Williams4711ba12011-03-11 10:43:57 -0800357 union scic_oem_parameters oem;
Dan Williams6f231dd2011-07-02 22:56:22 -0700358 union scic_user_parameters scic_user_params;
Dan Williamsd044af12011-03-08 09:52:49 -0800359 struct isci_pci_info *pci_info = to_pci_info(isci_host->pdev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700360
Dan Williams7c40a802011-03-02 11:49:26 -0800361 isci_timer_list_construct(isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700362
363 controller = scic_controller_alloc(&isci_host->pdev->dev);
364
365 if (!controller) {
Dave Jiang858d4aa2011-02-22 01:27:03 -0800366 dev_err(&isci_host->pdev->dev,
367 "%s: failed (%d)\n",
368 __func__,
369 err);
370 return -ENOMEM;
Dan Williams6f231dd2011-07-02 22:56:22 -0700371 }
372
373 isci_host->core_controller = controller;
Dan Williams4711ba12011-03-11 10:43:57 -0800374 sci_object_set_association(isci_host->core_controller, isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700375 spin_lock_init(&isci_host->state_lock);
376 spin_lock_init(&isci_host->scic_lock);
377 spin_lock_init(&isci_host->queue_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800378 init_waitqueue_head(&isci_host->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700379
380 isci_host_change_state(isci_host, isci_starting);
381 isci_host->can_queue = ISCI_CAN_QUEUE_VAL;
382
383 status = scic_controller_construct(controller, scu_base(isci_host),
384 smu_base(isci_host));
385
386 if (status != SCI_SUCCESS) {
387 dev_err(&isci_host->pdev->dev,
388 "%s: scic_controller_construct failed - status = %x\n",
389 __func__,
390 status);
Dave Jiang858d4aa2011-02-22 01:27:03 -0800391 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -0700392 }
393
394 isci_host->sas_ha.dev = &isci_host->pdev->dev;
395 isci_host->sas_ha.lldd_ha = isci_host;
396
Dan Williamsd044af12011-03-08 09:52:49 -0800397 /*
398 * grab initial values stored in the controller object for OEM and USER
399 * parameters
400 */
Dave Jiangb5f18a22011-03-16 14:57:23 -0700401 isci_user_parameters_get(isci_host, &scic_user_params);
Dan Williamsd044af12011-03-08 09:52:49 -0800402 status = scic_user_parameters_set(isci_host->core_controller,
403 &scic_user_params);
404 if (status != SCI_SUCCESS) {
405 dev_warn(&isci_host->pdev->dev,
406 "%s: scic_user_parameters_set failed\n",
407 __func__);
408 return -ENODEV;
409 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700410
Dan Williams4711ba12011-03-11 10:43:57 -0800411 scic_oem_parameters_get(controller, &oem);
Dan Williamsd044af12011-03-08 09:52:49 -0800412
413 /* grab any OEM parameters specified in orom */
414 if (pci_info->orom) {
Dan Williams4711ba12011-03-11 10:43:57 -0800415 status = isci_parse_oem_parameters(&oem,
Dan Williamsd044af12011-03-08 09:52:49 -0800416 pci_info->orom,
417 isci_host->id);
Dan Williams6f231dd2011-07-02 22:56:22 -0700418 if (status != SCI_SUCCESS) {
419 dev_warn(&isci_host->pdev->dev,
420 "parsing firmware oem parameters failed\n");
Dave Jiang858d4aa2011-02-22 01:27:03 -0800421 return -EINVAL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700422 }
Dan Williams4711ba12011-03-11 10:43:57 -0800423 }
424
425 status = scic_oem_parameters_set(isci_host->core_controller, &oem);
426 if (status != SCI_SUCCESS) {
427 dev_warn(&isci_host->pdev->dev,
428 "%s: scic_oem_parameters_set failed\n",
429 __func__);
430 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -0700431 }
432
Dan Williams6f231dd2011-07-02 22:56:22 -0700433 tasklet_init(&isci_host->completion_tasklet,
Dan Williamsc7ef4032011-02-18 09:25:05 -0800434 isci_host_completion_routine, (unsigned long)isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700435
Dan Williams6f231dd2011-07-02 22:56:22 -0700436 INIT_LIST_HEAD(&isci_host->requests_to_complete);
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800437 INIT_LIST_HEAD(&isci_host->requests_to_errorback);
Dan Williams6f231dd2011-07-02 22:56:22 -0700438
Dan Williams7c40a802011-03-02 11:49:26 -0800439 spin_lock_irq(&isci_host->scic_lock);
440 status = scic_controller_initialize(isci_host->core_controller);
441 spin_unlock_irq(&isci_host->scic_lock);
442 if (status != SCI_SUCCESS) {
443 dev_warn(&isci_host->pdev->dev,
444 "%s: scic_controller_initialize failed -"
445 " status = 0x%x\n",
446 __func__, status);
447 return -ENODEV;
448 }
449
Christoph Hellwigbc5c9672011-04-02 08:15:04 -0400450 err = scic_controller_mem_init(isci_host->core_controller);
Dan Williams6f231dd2011-07-02 22:56:22 -0700451 if (err)
Dave Jiang858d4aa2011-02-22 01:27:03 -0800452 return err;
Dan Williams6f231dd2011-07-02 22:56:22 -0700453
454 /*
455 * keep the pool alloc size around, will use it for a bounds checking
456 * when trying to convert virtual addresses to physical addresses
457 */
458 isci_host->dma_pool_alloc_size = sizeof(struct isci_request) +
459 scic_io_request_get_object_size();
460 isci_host->dma_pool = dmam_pool_create(DRV_NAME, &isci_host->pdev->dev,
461 isci_host->dma_pool_alloc_size,
462 SLAB_HWCACHE_ALIGN, 0);
463
Dave Jiang858d4aa2011-02-22 01:27:03 -0800464 if (!isci_host->dma_pool)
465 return -ENOMEM;
Dan Williams6f231dd2011-07-02 22:56:22 -0700466
Dan Williamsd9c37392011-03-03 17:59:32 -0800467 for (i = 0; i < SCI_MAX_PORTS; i++)
468 isci_port_init(&isci_host->isci_ports[i], isci_host, i);
Dan Williams6f231dd2011-07-02 22:56:22 -0700469
Dan Williamsd9c37392011-03-03 17:59:32 -0800470 for (i = 0; i < SCI_MAX_PHYS; i++)
471 isci_phy_init(&isci_host->phys[i], isci_host, i);
472
473 for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
474 struct isci_remote_device *idev = idev_by_id(isci_host, i);
475
476 INIT_LIST_HEAD(&idev->reqs_in_process);
477 INIT_LIST_HEAD(&idev->node);
478 spin_lock_init(&idev->state_lock);
479 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700480
Dave Jiang858d4aa2011-02-22 01:27:03 -0800481 return 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700482}