isci: unify constants
[deliverable/linux.git] / drivers / scsi / isci / host.c
CommitLineData
6f231dda
DW
1/*
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"
6f231dda 58#include "scic_port.h"
6f231dda
DW
59#include "port.h"
60#include "request.h"
61#include "host.h"
d044af17 62#include "probe_roms.h"
ce2b3261 63#include "scic_controller.h"
88f3b62a 64#include "scic_sds_controller.h"
ce2b3261 65#include "timers.h"
6f231dda 66
c7ef4031 67irqreturn_t isci_msix_isr(int vec, void *data)
6f231dda 68{
c7ef4031 69 struct isci_host *ihost = data;
c7ef4031 70
cc3dbd0a 71 if (scic_sds_controller_isr(&ihost->sci))
0cf89d1d 72 tasklet_schedule(&ihost->completion_tasklet);
6f231dda 73
c7ef4031 74 return IRQ_HANDLED;
6f231dda
DW
75}
76
c7ef4031 77irqreturn_t isci_intx_isr(int vec, void *data)
6f231dda 78{
6f231dda 79 irqreturn_t ret = IRQ_NONE;
31e824ed 80 struct isci_host *ihost = data;
cc3dbd0a 81 struct scic_sds_controller *scic = &ihost->sci;
c7ef4031 82
31e824ed
DW
83 if (scic_sds_controller_isr(scic)) {
84 writel(SMU_ISR_COMPLETION, &scic->smu_registers->interrupt_status);
85 tasklet_schedule(&ihost->completion_tasklet);
86 ret = IRQ_HANDLED;
87 } else if (scic_sds_controller_error_isr(scic)) {
88 spin_lock(&ihost->scic_lock);
89 scic_sds_controller_error_handler(scic);
90 spin_unlock(&ihost->scic_lock);
91 ret = IRQ_HANDLED;
6f231dda 92 }
92f4f0f5 93
6f231dda
DW
94 return ret;
95}
96
92f4f0f5
DW
97irqreturn_t isci_error_isr(int vec, void *data)
98{
99 struct isci_host *ihost = data;
92f4f0f5 100
cc3dbd0a
AW
101 if (scic_sds_controller_error_isr(&ihost->sci))
102 scic_sds_controller_error_handler(&ihost->sci);
92f4f0f5
DW
103
104 return IRQ_HANDLED;
105}
6f231dda
DW
106
107/**
108 * isci_host_start_complete() - This function is called by the core library,
109 * through the ISCI Module, to indicate controller start status.
110 * @isci_host: This parameter specifies the ISCI host object
111 * @completion_status: This parameter specifies the completion status from the
112 * core library.
113 *
114 */
0cf89d1d 115void isci_host_start_complete(struct isci_host *ihost, enum sci_status completion_status)
6f231dda 116{
0cf89d1d
DW
117 if (completion_status != SCI_SUCCESS)
118 dev_info(&ihost->pdev->dev,
119 "controller start timed out, continuing...\n");
120 isci_host_change_state(ihost, isci_ready);
121 clear_bit(IHOST_START_PENDING, &ihost->flags);
122 wake_up(&ihost->eventq);
6f231dda
DW
123}
124
c7ef4031 125int isci_host_scan_finished(struct Scsi_Host *shost, unsigned long time)
6f231dda 126{
4393aa4e 127 struct isci_host *ihost = SHOST_TO_SAS_HA(shost)->lldd_ha;
6f231dda 128
77950f51 129 if (test_bit(IHOST_START_PENDING, &ihost->flags))
6f231dda 130 return 0;
6f231dda 131
77950f51
EN
132 /* todo: use sas_flush_discovery once it is upstream */
133 scsi_flush_work(shost);
134
135 scsi_flush_work(shost);
6f231dda 136
0cf89d1d
DW
137 dev_dbg(&ihost->pdev->dev,
138 "%s: ihost->status = %d, time = %ld\n",
139 __func__, isci_host_get_state(ihost), time);
6f231dda 140
6f231dda
DW
141 return 1;
142
143}
144
6f231dda
DW
145void isci_host_scan_start(struct Scsi_Host *shost)
146{
4393aa4e 147 struct isci_host *ihost = SHOST_TO_SAS_HA(shost)->lldd_ha;
cc3dbd0a 148 unsigned long tmo = scic_controller_get_suggested_start_timeout(&ihost->sci);
6f231dda 149
0cf89d1d 150 set_bit(IHOST_START_PENDING, &ihost->flags);
77950f51
EN
151
152 spin_lock_irq(&ihost->scic_lock);
cc3dbd0a
AW
153 scic_controller_start(&ihost->sci, tmo);
154 scic_controller_enable_interrupts(&ihost->sci);
77950f51 155 spin_unlock_irq(&ihost->scic_lock);
6f231dda
DW
156}
157
0cf89d1d 158void isci_host_stop_complete(struct isci_host *ihost, enum sci_status completion_status)
6f231dda 159{
0cf89d1d 160 isci_host_change_state(ihost, isci_stopped);
cc3dbd0a 161 scic_controller_disable_interrupts(&ihost->sci);
0cf89d1d
DW
162 clear_bit(IHOST_STOP_PENDING, &ihost->flags);
163 wake_up(&ihost->eventq);
6f231dda
DW
164}
165
6f231dda
DW
166/**
167 * isci_host_completion_routine() - This function is the delayed service
168 * routine that calls the sci core library's completion handler. It's
169 * scheduled as a tasklet from the interrupt service routine when interrupts
170 * in use, or set as the timeout function in polled mode.
171 * @data: This parameter specifies the ISCI host object
172 *
173 */
174static void isci_host_completion_routine(unsigned long data)
175{
176 struct isci_host *isci_host = (struct isci_host *)data;
11b00c19
JS
177 struct list_head completed_request_list;
178 struct list_head errored_request_list;
179 struct list_head *current_position;
180 struct list_head *next_position;
6f231dda
DW
181 struct isci_request *request;
182 struct isci_request *next_request;
11b00c19 183 struct sas_task *task;
6f231dda
DW
184
185 INIT_LIST_HEAD(&completed_request_list);
11b00c19 186 INIT_LIST_HEAD(&errored_request_list);
6f231dda
DW
187
188 spin_lock_irq(&isci_host->scic_lock);
189
cc3dbd0a 190 scic_sds_controller_completion_handler(&isci_host->sci);
c7ef4031 191
6f231dda 192 /* Take the lists of completed I/Os from the host. */
11b00c19 193
6f231dda
DW
194 list_splice_init(&isci_host->requests_to_complete,
195 &completed_request_list);
196
11b00c19
JS
197 /* Take the list of errored I/Os from the host. */
198 list_splice_init(&isci_host->requests_to_errorback,
199 &errored_request_list);
6f231dda
DW
200
201 spin_unlock_irq(&isci_host->scic_lock);
202
203 /* Process any completions in the lists. */
204 list_for_each_safe(current_position, next_position,
205 &completed_request_list) {
206
207 request = list_entry(current_position, struct isci_request,
208 completed_node);
209 task = isci_request_access_task(request);
210
211 /* Normal notification (task_done) */
212 dev_dbg(&isci_host->pdev->dev,
213 "%s: Normal - request/task = %p/%p\n",
214 __func__,
215 request,
216 task);
217
11b00c19
JS
218 /* Return the task to libsas */
219 if (task != NULL) {
220
221 task->lldd_task = NULL;
222 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
6f231dda 223
11b00c19
JS
224 /* If the task is already in the abort path,
225 * the task_done callback cannot be called.
226 */
227 task->task_done(task);
228 }
229 }
6f231dda
DW
230 /* Free the request object. */
231 isci_request_free(isci_host, request);
232 }
11b00c19 233 list_for_each_entry_safe(request, next_request, &errored_request_list,
6f231dda
DW
234 completed_node) {
235
236 task = isci_request_access_task(request);
237
238 /* Use sas_task_abort */
239 dev_warn(&isci_host->pdev->dev,
240 "%s: Error - request/task = %p/%p\n",
241 __func__,
242 request,
243 task);
244
11b00c19
JS
245 if (task != NULL) {
246
247 /* Put the task into the abort path if it's not there
248 * already.
249 */
250 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED))
251 sas_task_abort(task);
252
253 } else {
254 /* This is a case where the request has completed with a
255 * status such that it needed further target servicing,
256 * but the sas_task reference has already been removed
257 * from the request. Since it was errored, it was not
258 * being aborted, so there is nothing to do except free
259 * it.
260 */
261
262 spin_lock_irq(&isci_host->scic_lock);
263 /* Remove the request from the remote device's list
264 * of pending requests.
265 */
266 list_del_init(&request->dev_node);
267 spin_unlock_irq(&isci_host->scic_lock);
268
269 /* Free the request object. */
270 isci_request_free(isci_host, request);
271 }
6f231dda
DW
272 }
273
274}
275
0cf89d1d 276void isci_host_deinit(struct isci_host *ihost)
6f231dda
DW
277{
278 int i;
279
0cf89d1d 280 isci_host_change_state(ihost, isci_stopping);
6f231dda 281 for (i = 0; i < SCI_MAX_PORTS; i++) {
e531381e 282 struct isci_port *iport = &ihost->ports[i];
0cf89d1d
DW
283 struct isci_remote_device *idev, *d;
284
e531381e 285 list_for_each_entry_safe(idev, d, &iport->remote_dev_list, node) {
0cf89d1d 286 isci_remote_device_change_state(idev, isci_stopping);
6ad31fec 287 isci_remote_device_stop(ihost, idev);
6f231dda
DW
288 }
289 }
290
0cf89d1d 291 set_bit(IHOST_STOP_PENDING, &ihost->flags);
7c40a803
DW
292
293 spin_lock_irq(&ihost->scic_lock);
cc3dbd0a 294 scic_controller_stop(&ihost->sci, SCIC_CONTROLLER_STOP_TIMEOUT);
7c40a803
DW
295 spin_unlock_irq(&ihost->scic_lock);
296
0cf89d1d 297 wait_for_stop(ihost);
cc3dbd0a 298 scic_controller_reset(&ihost->sci);
7c40a803 299 isci_timer_list_destroy(ihost);
6f231dda
DW
300}
301
6f231dda
DW
302static void __iomem *scu_base(struct isci_host *isci_host)
303{
304 struct pci_dev *pdev = isci_host->pdev;
305 int id = isci_host->id;
306
307 return pcim_iomap_table(pdev)[SCI_SCU_BAR * 2] + SCI_SCU_BAR_SIZE * id;
308}
309
310static void __iomem *smu_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_SMU_BAR * 2] + SCI_SMU_BAR_SIZE * id;
316}
317
b5f18a20
DJ
318static void isci_user_parameters_get(
319 struct isci_host *isci_host,
320 union scic_user_parameters *scic_user_params)
321{
322 struct scic_sds_user_parameters *u = &scic_user_params->sds1;
323 int i;
324
325 for (i = 0; i < SCI_MAX_PHYS; i++) {
326 struct sci_phy_user_params *u_phy = &u->phys[i];
327
328 u_phy->max_speed_generation = phy_gen;
329
330 /* we are not exporting these for now */
331 u_phy->align_insertion_frequency = 0x7f;
332 u_phy->in_connection_align_insertion_frequency = 0xff;
333 u_phy->notify_enable_spin_up_insertion_frequency = 0x33;
334 }
335
336 u->stp_inactivity_timeout = stp_inactive_to;
337 u->ssp_inactivity_timeout = ssp_inactive_to;
338 u->stp_max_occupancy_timeout = stp_max_occ_to;
339 u->ssp_max_occupancy_timeout = ssp_max_occ_to;
340 u->no_outbound_task_timeout = no_outbound_task_to;
341 u->max_number_concurrent_device_spin_up = max_concurr_spinup;
342}
343
6f231dda
DW
344int isci_host_init(struct isci_host *isci_host)
345{
d9c37390 346 int err = 0, i;
6f231dda 347 enum sci_status status;
4711ba10 348 union scic_oem_parameters oem;
6f231dda 349 union scic_user_parameters scic_user_params;
d044af17 350 struct isci_pci_info *pci_info = to_pci_info(isci_host->pdev);
6f231dda 351
7c40a803 352 isci_timer_list_construct(isci_host);
6f231dda 353
6f231dda
DW
354 spin_lock_init(&isci_host->state_lock);
355 spin_lock_init(&isci_host->scic_lock);
356 spin_lock_init(&isci_host->queue_lock);
0cf89d1d 357 init_waitqueue_head(&isci_host->eventq);
6f231dda
DW
358
359 isci_host_change_state(isci_host, isci_starting);
360 isci_host->can_queue = ISCI_CAN_QUEUE_VAL;
361
cc3dbd0a 362 status = scic_controller_construct(&isci_host->sci, scu_base(isci_host),
6f231dda
DW
363 smu_base(isci_host));
364
365 if (status != SCI_SUCCESS) {
366 dev_err(&isci_host->pdev->dev,
367 "%s: scic_controller_construct failed - status = %x\n",
368 __func__,
369 status);
858d4aa7 370 return -ENODEV;
6f231dda
DW
371 }
372
373 isci_host->sas_ha.dev = &isci_host->pdev->dev;
374 isci_host->sas_ha.lldd_ha = isci_host;
375
d044af17
DW
376 /*
377 * grab initial values stored in the controller object for OEM and USER
378 * parameters
379 */
b5f18a20 380 isci_user_parameters_get(isci_host, &scic_user_params);
cc3dbd0a 381 status = scic_user_parameters_set(&isci_host->sci,
d044af17
DW
382 &scic_user_params);
383 if (status != SCI_SUCCESS) {
384 dev_warn(&isci_host->pdev->dev,
385 "%s: scic_user_parameters_set failed\n",
386 __func__);
387 return -ENODEV;
388 }
389
cc3dbd0a 390 scic_oem_parameters_get(&isci_host->sci, &oem);
6f231dda 391
d044af17
DW
392 /* grab any OEM parameters specified in orom */
393 if (pci_info->orom) {
4711ba10 394 status = isci_parse_oem_parameters(&oem,
d044af17
DW
395 pci_info->orom,
396 isci_host->id);
6f231dda
DW
397 if (status != SCI_SUCCESS) {
398 dev_warn(&isci_host->pdev->dev,
399 "parsing firmware oem parameters failed\n");
858d4aa7 400 return -EINVAL;
6f231dda 401 }
4711ba10
DW
402 }
403
cc3dbd0a 404 status = scic_oem_parameters_set(&isci_host->sci, &oem);
4711ba10
DW
405 if (status != SCI_SUCCESS) {
406 dev_warn(&isci_host->pdev->dev,
407 "%s: scic_oem_parameters_set failed\n",
408 __func__);
409 return -ENODEV;
6f231dda
DW
410 }
411
7c40a803
DW
412 tasklet_init(&isci_host->completion_tasklet,
413 isci_host_completion_routine, (unsigned long)isci_host);
414
7c40a803 415 INIT_LIST_HEAD(&isci_host->requests_to_complete);
11b00c19 416 INIT_LIST_HEAD(&isci_host->requests_to_errorback);
7c40a803
DW
417
418 spin_lock_irq(&isci_host->scic_lock);
cc3dbd0a 419 status = scic_controller_initialize(&isci_host->sci);
7c40a803 420 spin_unlock_irq(&isci_host->scic_lock);
6f231dda
DW
421 if (status != SCI_SUCCESS) {
422 dev_warn(&isci_host->pdev->dev,
423 "%s: scic_controller_initialize failed -"
424 " status = 0x%x\n",
425 __func__, status);
858d4aa7 426 return -ENODEV;
6f231dda
DW
427 }
428
cc3dbd0a 429 err = scic_controller_mem_init(&isci_host->sci);
6f231dda 430 if (err)
858d4aa7 431 return err;
6f231dda 432
6f231dda 433 isci_host->dma_pool = dmam_pool_create(DRV_NAME, &isci_host->pdev->dev,
67ea838d 434 sizeof(struct isci_request),
6f231dda
DW
435 SLAB_HWCACHE_ALIGN, 0);
436
858d4aa7
DJ
437 if (!isci_host->dma_pool)
438 return -ENOMEM;
6f231dda 439
d9c37390 440 for (i = 0; i < SCI_MAX_PORTS; i++)
e531381e 441 isci_port_init(&isci_host->ports[i], isci_host, i);
6f231dda 442
d9c37390
DW
443 for (i = 0; i < SCI_MAX_PHYS; i++)
444 isci_phy_init(&isci_host->phys[i], isci_host, i);
445
446 for (i = 0; i < SCI_MAX_REMOTE_DEVICES; i++) {
57f20f4e 447 struct isci_remote_device *idev = &isci_host->devices[i];
d9c37390
DW
448
449 INIT_LIST_HEAD(&idev->reqs_in_process);
450 INIT_LIST_HEAD(&idev->node);
451 spin_lock_init(&idev->state_lock);
452 }
6f231dda 453
858d4aa7 454 return 0;
6f231dda 455}
This page took 0.053794 seconds and 5 git commands to generate.