blob: cdd99304c363aab29d0c95566a7805f7f5eba6a6 [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"
Dan Williams6f231dd2011-07-02 22:56:22 -070058#include "scic_port.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070059#include "port.h"
60#include "request.h"
61#include "host.h"
Dan Williamsd044af12011-03-08 09:52:49 -080062#include "probe_roms.h"
Dan Williams88f3b622011-04-22 19:18:03 -070063#include "scic_sds_controller.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070064
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;
Dan Williams6f231dd2011-07-02 22:56:22 -070068
Artur Wojcikcc3dbd02011-05-04 07:58:16 +000069 if (scic_sds_controller_isr(&ihost->sci))
Dan Williams0cf89d12011-02-18 09:25:07 -080070 tasklet_schedule(&ihost->completion_tasklet);
Dan Williams6f231dd2011-07-02 22:56:22 -070071
Dan Williamsc7ef4032011-02-18 09:25:05 -080072 return IRQ_HANDLED;
Dan Williams6f231dd2011-07-02 22:56:22 -070073}
74
Dan Williamsc7ef4032011-02-18 09:25:05 -080075irqreturn_t isci_intx_isr(int vec, void *data)
Dan Williams6f231dd2011-07-02 22:56:22 -070076{
Dan Williams6f231dd2011-07-02 22:56:22 -070077 irqreturn_t ret = IRQ_NONE;
Dan Williams31e824e2011-04-19 12:32:51 -070078 struct isci_host *ihost = data;
Artur Wojcikcc3dbd02011-05-04 07:58:16 +000079 struct scic_sds_controller *scic = &ihost->sci;
Dan Williams6f231dd2011-07-02 22:56:22 -070080
Dan Williams31e824e2011-04-19 12:32:51 -070081 if (scic_sds_controller_isr(scic)) {
82 writel(SMU_ISR_COMPLETION, &scic->smu_registers->interrupt_status);
83 tasklet_schedule(&ihost->completion_tasklet);
84 ret = IRQ_HANDLED;
85 } else if (scic_sds_controller_error_isr(scic)) {
86 spin_lock(&ihost->scic_lock);
87 scic_sds_controller_error_handler(scic);
88 spin_unlock(&ihost->scic_lock);
89 ret = IRQ_HANDLED;
Dan Williams6f231dd2011-07-02 22:56:22 -070090 }
Dan Williams92f4f0f2011-02-18 09:25:11 -080091
Dan Williams6f231dd2011-07-02 22:56:22 -070092 return ret;
93}
94
Dan Williams92f4f0f2011-02-18 09:25:11 -080095irqreturn_t isci_error_isr(int vec, void *data)
96{
97 struct isci_host *ihost = data;
Dan Williams92f4f0f2011-02-18 09:25:11 -080098
Artur Wojcikcc3dbd02011-05-04 07:58:16 +000099 if (scic_sds_controller_error_isr(&ihost->sci))
100 scic_sds_controller_error_handler(&ihost->sci);
Dan Williams92f4f0f2011-02-18 09:25:11 -0800101
102 return IRQ_HANDLED;
103}
Dan Williams6f231dd2011-07-02 22:56:22 -0700104
105/**
106 * isci_host_start_complete() - This function is called by the core library,
107 * through the ISCI Module, to indicate controller start status.
108 * @isci_host: This parameter specifies the ISCI host object
109 * @completion_status: This parameter specifies the completion status from the
110 * core library.
111 *
112 */
Dan Williams0cf89d12011-02-18 09:25:07 -0800113void isci_host_start_complete(struct isci_host *ihost, enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700114{
Dan Williams0cf89d12011-02-18 09:25:07 -0800115 if (completion_status != SCI_SUCCESS)
116 dev_info(&ihost->pdev->dev,
117 "controller start timed out, continuing...\n");
118 isci_host_change_state(ihost, isci_ready);
119 clear_bit(IHOST_START_PENDING, &ihost->flags);
120 wake_up(&ihost->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700121}
122
Dan Williamsc7ef4032011-02-18 09:25:05 -0800123int isci_host_scan_finished(struct Scsi_Host *shost, unsigned long time)
Dan Williams6f231dd2011-07-02 22:56:22 -0700124{
Dan Williams4393aa42011-03-31 13:10:44 -0700125 struct isci_host *ihost = SHOST_TO_SAS_HA(shost)->lldd_ha;
Dan Williams6f231dd2011-07-02 22:56:22 -0700126
Edmund Nadolski77950f52011-02-18 09:25:09 -0800127 if (test_bit(IHOST_START_PENDING, &ihost->flags))
Dan Williams6f231dd2011-07-02 22:56:22 -0700128 return 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700129
Edmund Nadolski77950f52011-02-18 09:25:09 -0800130 /* todo: use sas_flush_discovery once it is upstream */
131 scsi_flush_work(shost);
132
133 scsi_flush_work(shost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700134
Dan Williams0cf89d12011-02-18 09:25:07 -0800135 dev_dbg(&ihost->pdev->dev,
136 "%s: ihost->status = %d, time = %ld\n",
137 __func__, isci_host_get_state(ihost), time);
Dan Williams6f231dd2011-07-02 22:56:22 -0700138
Dan Williams6f231dd2011-07-02 22:56:22 -0700139 return 1;
140
141}
142
Dan Williams6f231dd2011-07-02 22:56:22 -0700143void isci_host_scan_start(struct Scsi_Host *shost)
144{
Dan Williams4393aa42011-03-31 13:10:44 -0700145 struct isci_host *ihost = SHOST_TO_SAS_HA(shost)->lldd_ha;
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000146 unsigned long tmo = scic_controller_get_suggested_start_timeout(&ihost->sci);
Dan Williams6f231dd2011-07-02 22:56:22 -0700147
Dan Williams0cf89d12011-02-18 09:25:07 -0800148 set_bit(IHOST_START_PENDING, &ihost->flags);
Edmund Nadolski77950f52011-02-18 09:25:09 -0800149
150 spin_lock_irq(&ihost->scic_lock);
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000151 scic_controller_start(&ihost->sci, tmo);
152 scic_controller_enable_interrupts(&ihost->sci);
Edmund Nadolski77950f52011-02-18 09:25:09 -0800153 spin_unlock_irq(&ihost->scic_lock);
Dan Williams6f231dd2011-07-02 22:56:22 -0700154}
155
Dan Williams0cf89d12011-02-18 09:25:07 -0800156void isci_host_stop_complete(struct isci_host *ihost, enum sci_status completion_status)
Dan Williams6f231dd2011-07-02 22:56:22 -0700157{
Dan Williams0cf89d12011-02-18 09:25:07 -0800158 isci_host_change_state(ihost, isci_stopped);
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000159 scic_controller_disable_interrupts(&ihost->sci);
Dan Williams0cf89d12011-02-18 09:25:07 -0800160 clear_bit(IHOST_STOP_PENDING, &ihost->flags);
161 wake_up(&ihost->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700162}
163
Dan Williams6f231dd2011-07-02 22:56:22 -0700164/**
165 * isci_host_completion_routine() - This function is the delayed service
166 * routine that calls the sci core library's completion handler. It's
167 * scheduled as a tasklet from the interrupt service routine when interrupts
168 * in use, or set as the timeout function in polled mode.
169 * @data: This parameter specifies the ISCI host object
170 *
171 */
172static void isci_host_completion_routine(unsigned long data)
173{
174 struct isci_host *isci_host = (struct isci_host *)data;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800175 struct list_head completed_request_list;
176 struct list_head errored_request_list;
177 struct list_head *current_position;
178 struct list_head *next_position;
Dan Williams6f231dd2011-07-02 22:56:22 -0700179 struct isci_request *request;
180 struct isci_request *next_request;
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800181 struct sas_task *task;
Dan Williams6f231dd2011-07-02 22:56:22 -0700182
183 INIT_LIST_HEAD(&completed_request_list);
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800184 INIT_LIST_HEAD(&errored_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700185
186 spin_lock_irq(&isci_host->scic_lock);
187
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000188 scic_sds_controller_completion_handler(&isci_host->sci);
Dan Williamsc7ef4032011-02-18 09:25:05 -0800189
Dan Williams6f231dd2011-07-02 22:56:22 -0700190 /* Take the lists of completed I/Os from the host. */
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800191
Dan Williams6f231dd2011-07-02 22:56:22 -0700192 list_splice_init(&isci_host->requests_to_complete,
193 &completed_request_list);
194
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800195 /* Take the list of errored I/Os from the host. */
196 list_splice_init(&isci_host->requests_to_errorback,
197 &errored_request_list);
Dan Williams6f231dd2011-07-02 22:56:22 -0700198
199 spin_unlock_irq(&isci_host->scic_lock);
200
201 /* Process any completions in the lists. */
202 list_for_each_safe(current_position, next_position,
203 &completed_request_list) {
204
205 request = list_entry(current_position, struct isci_request,
206 completed_node);
207 task = isci_request_access_task(request);
208
209 /* Normal notification (task_done) */
210 dev_dbg(&isci_host->pdev->dev,
211 "%s: Normal - request/task = %p/%p\n",
212 __func__,
213 request,
214 task);
215
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800216 /* Return the task to libsas */
217 if (task != NULL) {
Dan Williams6f231dd2011-07-02 22:56:22 -0700218
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800219 task->lldd_task = NULL;
220 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
221
222 /* If the task is already in the abort path,
223 * the task_done callback cannot be called.
224 */
225 task->task_done(task);
226 }
227 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700228 /* Free the request object. */
229 isci_request_free(isci_host, request);
230 }
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800231 list_for_each_entry_safe(request, next_request, &errored_request_list,
Dan Williams6f231dd2011-07-02 22:56:22 -0700232 completed_node) {
233
234 task = isci_request_access_task(request);
235
236 /* Use sas_task_abort */
237 dev_warn(&isci_host->pdev->dev,
238 "%s: Error - request/task = %p/%p\n",
239 __func__,
240 request,
241 task);
242
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800243 if (task != NULL) {
244
245 /* Put the task into the abort path if it's not there
246 * already.
247 */
248 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED))
249 sas_task_abort(task);
250
251 } else {
252 /* This is a case where the request has completed with a
253 * status such that it needed further target servicing,
254 * but the sas_task reference has already been removed
255 * from the request. Since it was errored, it was not
256 * being aborted, so there is nothing to do except free
257 * it.
258 */
259
260 spin_lock_irq(&isci_host->scic_lock);
261 /* Remove the request from the remote device's list
262 * of pending requests.
263 */
264 list_del_init(&request->dev_node);
265 spin_unlock_irq(&isci_host->scic_lock);
266
267 /* Free the request object. */
268 isci_request_free(isci_host, request);
269 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700270 }
271
272}
273
Dan Williams0cf89d12011-02-18 09:25:07 -0800274void isci_host_deinit(struct isci_host *ihost)
Dan Williams6f231dd2011-07-02 22:56:22 -0700275{
276 int i;
277
Dan Williams0cf89d12011-02-18 09:25:07 -0800278 isci_host_change_state(ihost, isci_stopping);
Dan Williams6f231dd2011-07-02 22:56:22 -0700279 for (i = 0; i < SCI_MAX_PORTS; i++) {
Dan Williamse5313812011-05-07 10:11:43 -0700280 struct isci_port *iport = &ihost->ports[i];
Dan Williams0cf89d12011-02-18 09:25:07 -0800281 struct isci_remote_device *idev, *d;
282
Dan Williamse5313812011-05-07 10:11:43 -0700283 list_for_each_entry_safe(idev, d, &iport->remote_dev_list, node) {
Dan Williams0cf89d12011-02-18 09:25:07 -0800284 isci_remote_device_change_state(idev, isci_stopping);
Dan Williams6ad31fe2011-03-04 12:10:29 -0800285 isci_remote_device_stop(ihost, idev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700286 }
287 }
288
Dan Williams0cf89d12011-02-18 09:25:07 -0800289 set_bit(IHOST_STOP_PENDING, &ihost->flags);
Dan Williams7c40a802011-03-02 11:49:26 -0800290
291 spin_lock_irq(&ihost->scic_lock);
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000292 scic_controller_stop(&ihost->sci, SCIC_CONTROLLER_STOP_TIMEOUT);
Dan Williams7c40a802011-03-02 11:49:26 -0800293 spin_unlock_irq(&ihost->scic_lock);
294
Dan Williams0cf89d12011-02-18 09:25:07 -0800295 wait_for_stop(ihost);
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000296 scic_controller_reset(&ihost->sci);
Dan Williams7c40a802011-03-02 11:49:26 -0800297 isci_timer_list_destroy(ihost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700298}
299
Dan Williams6f231dd2011-07-02 22:56:22 -0700300static void __iomem *scu_base(struct isci_host *isci_host)
301{
302 struct pci_dev *pdev = isci_host->pdev;
303 int id = isci_host->id;
304
305 return pcim_iomap_table(pdev)[SCI_SCU_BAR * 2] + SCI_SCU_BAR_SIZE * id;
306}
307
308static void __iomem *smu_base(struct isci_host *isci_host)
309{
310 struct pci_dev *pdev = isci_host->pdev;
311 int id = isci_host->id;
312
313 return pcim_iomap_table(pdev)[SCI_SMU_BAR * 2] + SCI_SMU_BAR_SIZE * id;
314}
315
Dave Jiangb5f18a22011-03-16 14:57:23 -0700316static void isci_user_parameters_get(
317 struct isci_host *isci_host,
318 union scic_user_parameters *scic_user_params)
319{
320 struct scic_sds_user_parameters *u = &scic_user_params->sds1;
321 int i;
322
323 for (i = 0; i < SCI_MAX_PHYS; i++) {
324 struct sci_phy_user_params *u_phy = &u->phys[i];
325
326 u_phy->max_speed_generation = phy_gen;
327
328 /* we are not exporting these for now */
329 u_phy->align_insertion_frequency = 0x7f;
330 u_phy->in_connection_align_insertion_frequency = 0xff;
331 u_phy->notify_enable_spin_up_insertion_frequency = 0x33;
332 }
333
334 u->stp_inactivity_timeout = stp_inactive_to;
335 u->ssp_inactivity_timeout = ssp_inactive_to;
336 u->stp_max_occupancy_timeout = stp_max_occ_to;
337 u->ssp_max_occupancy_timeout = ssp_max_occ_to;
338 u->no_outbound_task_timeout = no_outbound_task_to;
339 u->max_number_concurrent_device_spin_up = max_concurr_spinup;
340}
341
Dan Williams6f231dd2011-07-02 22:56:22 -0700342int isci_host_init(struct isci_host *isci_host)
343{
Dan Williamsd9c37392011-03-03 17:59:32 -0800344 int err = 0, i;
Dan Williams6f231dd2011-07-02 22:56:22 -0700345 enum sci_status status;
Dan Williams4711ba12011-03-11 10:43:57 -0800346 union scic_oem_parameters oem;
Dan Williams6f231dd2011-07-02 22:56:22 -0700347 union scic_user_parameters scic_user_params;
Dan Williamsd044af12011-03-08 09:52:49 -0800348 struct isci_pci_info *pci_info = to_pci_info(isci_host->pdev);
Dan Williams6f231dd2011-07-02 22:56:22 -0700349
Dan Williams7c40a802011-03-02 11:49:26 -0800350 isci_timer_list_construct(isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700351
Dan Williams6f231dd2011-07-02 22:56:22 -0700352 spin_lock_init(&isci_host->state_lock);
353 spin_lock_init(&isci_host->scic_lock);
354 spin_lock_init(&isci_host->queue_lock);
Dan Williams0cf89d12011-02-18 09:25:07 -0800355 init_waitqueue_head(&isci_host->eventq);
Dan Williams6f231dd2011-07-02 22:56:22 -0700356
357 isci_host_change_state(isci_host, isci_starting);
358 isci_host->can_queue = ISCI_CAN_QUEUE_VAL;
359
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000360 status = scic_controller_construct(&isci_host->sci, scu_base(isci_host),
Dan Williams6f231dd2011-07-02 22:56:22 -0700361 smu_base(isci_host));
362
363 if (status != SCI_SUCCESS) {
364 dev_err(&isci_host->pdev->dev,
365 "%s: scic_controller_construct failed - status = %x\n",
366 __func__,
367 status);
Dave Jiang858d4aa2011-02-22 01:27:03 -0800368 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -0700369 }
370
371 isci_host->sas_ha.dev = &isci_host->pdev->dev;
372 isci_host->sas_ha.lldd_ha = isci_host;
373
Dan Williamsd044af12011-03-08 09:52:49 -0800374 /*
375 * grab initial values stored in the controller object for OEM and USER
376 * parameters
377 */
Dave Jiangb5f18a22011-03-16 14:57:23 -0700378 isci_user_parameters_get(isci_host, &scic_user_params);
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000379 status = scic_user_parameters_set(&isci_host->sci,
Dan Williamsd044af12011-03-08 09:52:49 -0800380 &scic_user_params);
381 if (status != SCI_SUCCESS) {
382 dev_warn(&isci_host->pdev->dev,
383 "%s: scic_user_parameters_set failed\n",
384 __func__);
385 return -ENODEV;
386 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700387
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000388 scic_oem_parameters_get(&isci_host->sci, &oem);
Dan Williamsd044af12011-03-08 09:52:49 -0800389
390 /* grab any OEM parameters specified in orom */
391 if (pci_info->orom) {
Dan Williams4711ba12011-03-11 10:43:57 -0800392 status = isci_parse_oem_parameters(&oem,
Dan Williamsd044af12011-03-08 09:52:49 -0800393 pci_info->orom,
394 isci_host->id);
Dan Williams6f231dd2011-07-02 22:56:22 -0700395 if (status != SCI_SUCCESS) {
396 dev_warn(&isci_host->pdev->dev,
397 "parsing firmware oem parameters failed\n");
Dave Jiang858d4aa2011-02-22 01:27:03 -0800398 return -EINVAL;
Dan Williams6f231dd2011-07-02 22:56:22 -0700399 }
Dan Williams4711ba12011-03-11 10:43:57 -0800400 }
401
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000402 status = scic_oem_parameters_set(&isci_host->sci, &oem);
Dan Williams4711ba12011-03-11 10:43:57 -0800403 if (status != SCI_SUCCESS) {
404 dev_warn(&isci_host->pdev->dev,
405 "%s: scic_oem_parameters_set failed\n",
406 __func__);
407 return -ENODEV;
Dan Williams6f231dd2011-07-02 22:56:22 -0700408 }
409
Dan Williams6f231dd2011-07-02 22:56:22 -0700410 tasklet_init(&isci_host->completion_tasklet,
Dan Williamsc7ef4032011-02-18 09:25:05 -0800411 isci_host_completion_routine, (unsigned long)isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700412
Dan Williams6f231dd2011-07-02 22:56:22 -0700413 INIT_LIST_HEAD(&isci_host->requests_to_complete);
Jeff Skirvin11b00c12011-03-04 14:06:40 -0800414 INIT_LIST_HEAD(&isci_host->requests_to_errorback);
Dan Williams6f231dd2011-07-02 22:56:22 -0700415
Dan Williams7c40a802011-03-02 11:49:26 -0800416 spin_lock_irq(&isci_host->scic_lock);
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000417 status = scic_controller_initialize(&isci_host->sci);
Dan Williams7c40a802011-03-02 11:49:26 -0800418 spin_unlock_irq(&isci_host->scic_lock);
419 if (status != SCI_SUCCESS) {
420 dev_warn(&isci_host->pdev->dev,
421 "%s: scic_controller_initialize failed -"
422 " status = 0x%x\n",
423 __func__, status);
424 return -ENODEV;
425 }
426
Artur Wojcikcc3dbd02011-05-04 07:58:16 +0000427 err = scic_controller_mem_init(&isci_host->sci);
Dan Williams6f231dd2011-07-02 22:56:22 -0700428 if (err)
Dave Jiang858d4aa2011-02-22 01:27:03 -0800429 return err;
Dan Williams6f231dd2011-07-02 22:56:22 -0700430
431 /*
432 * keep the pool alloc size around, will use it for a bounds checking
433 * when trying to convert virtual addresses to physical addresses
434 */
435 isci_host->dma_pool_alloc_size = sizeof(struct isci_request) +
436 scic_io_request_get_object_size();
437 isci_host->dma_pool = dmam_pool_create(DRV_NAME, &isci_host->pdev->dev,
438 isci_host->dma_pool_alloc_size,
439 SLAB_HWCACHE_ALIGN, 0);
440
Dave Jiang858d4aa2011-02-22 01:27:03 -0800441 if (!isci_host->dma_pool)
442 return -ENOMEM;
Dan Williams6f231dd2011-07-02 22:56:22 -0700443
Dan Williamsd9c37392011-03-03 17:59:32 -0800444 for (i = 0; i < SCI_MAX_PORTS; i++)
Dan Williamse5313812011-05-07 10:11:43 -0700445 isci_port_init(&isci_host->ports[i], isci_host, i);
Dan Williams6f231dd2011-07-02 22:56:22 -0700446
Dan Williamsd9c37392011-03-03 17:59:32 -0800447 for (i = 0; i < SCI_MAX_PHYS; i++)
448 isci_phy_init(&isci_host->phys[i], isci_host, i);
449
450 for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
Dan Williams57f20f42011-04-21 18:14:45 -0700451 struct isci_remote_device *idev = &isci_host->devices[i];
Dan Williamsd9c37392011-03-03 17:59:32 -0800452
453 INIT_LIST_HEAD(&idev->reqs_in_process);
454 INIT_LIST_HEAD(&idev->node);
455 spin_lock_init(&idev->state_lock);
456 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700457
Dave Jiang858d4aa2011-02-22 01:27:03 -0800458 return 0;
Dan Williams6f231dd2011-07-02 22:56:22 -0700459}