blob: f7ca9e8d9146b7047f5ef8eada6a2b35ad3cc56d [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 <linux/kernel.h>
57#include <linux/init.h>
58#include <linux/module.h>
Dan Williamsd044af12011-03-08 09:52:49 -080059#include <linux/firmware.h>
60#include <linux/efi.h>
Dan Williams6f231dd2011-07-02 22:56:22 -070061#include <asm/string.h>
62#include "isci.h"
63#include "task.h"
64#include "sci_controller_constants.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070065#include "sci_environment.h"
Dan Williamsd044af12011-03-08 09:52:49 -080066#include "probe_roms.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070067
68static struct scsi_transport_template *isci_transport_template;
Dan Williams6f231dd2011-07-02 22:56:22 -070069
70static DEFINE_PCI_DEVICE_TABLE(isci_id_table) = {
71 { PCI_VDEVICE(INTEL, 0x1D61),},
72 { PCI_VDEVICE(INTEL, 0x1D63),},
73 { PCI_VDEVICE(INTEL, 0x1D65),},
74 { PCI_VDEVICE(INTEL, 0x1D67),},
75 { PCI_VDEVICE(INTEL, 0x1D69),},
76 { PCI_VDEVICE(INTEL, 0x1D6B),},
77 { PCI_VDEVICE(INTEL, 0x1D60),},
78 { PCI_VDEVICE(INTEL, 0x1D62),},
79 { PCI_VDEVICE(INTEL, 0x1D64),},
80 { PCI_VDEVICE(INTEL, 0x1D66),},
81 { PCI_VDEVICE(INTEL, 0x1D68),},
82 { PCI_VDEVICE(INTEL, 0x1D6A),},
83 {}
84};
85
Dan Williams6f231dd2011-07-02 22:56:22 -070086MODULE_DEVICE_TABLE(pci, isci_id_table);
87
Dan Williams6f231dd2011-07-02 22:56:22 -070088/* linux isci specific settings */
Dan Williams6f231dd2011-07-02 22:56:22 -070089
90#if defined(CONFIG_PBG_HBA_A0)
91int isci_si_rev = ISCI_SI_REVA0;
92#elif defined(CONFIG_PBG_HBA_A2)
93int isci_si_rev = ISCI_SI_REVA2;
94#else
95int isci_si_rev = ISCI_SI_REVB0;
96#endif
Dave Jiangb5f18a22011-03-16 14:57:23 -070097module_param(isci_si_rev, int, 0);
Dan Williams6f231dd2011-07-02 22:56:22 -070098MODULE_PARM_DESC(isci_si_rev, "override default si rev (0: A0 1: A2 2: B0)");
99
Dave Jiangb5f18a22011-03-16 14:57:23 -0700100unsigned char no_outbound_task_to = 20;
101module_param(no_outbound_task_to, byte, 0);
102MODULE_PARM_DESC(no_outbound_task_to, "No Outbound Task Timeout (1us incr)");
103
104u16 ssp_max_occ_to = 20;
105module_param(ssp_max_occ_to, ushort, 0);
106MODULE_PARM_DESC(ssp_max_occ_to, "SSP Max occupancy timeout (100us incr)");
107
108u16 stp_max_occ_to = 5;
109module_param(stp_max_occ_to, ushort, 0);
110MODULE_PARM_DESC(stp_max_occ_to, "STP Max occupancy timeout (100us incr)");
111
112u16 ssp_inactive_to = 5;
113module_param(ssp_inactive_to, ushort, 0);
114MODULE_PARM_DESC(ssp_inactive_to, "SSP inactivity timeout (100us incr)");
115
116u16 stp_inactive_to = 5;
117module_param(stp_inactive_to, ushort, 0);
118MODULE_PARM_DESC(stp_inactive_to, "STP inactivity timeout (100us incr)");
119
120unsigned char phy_gen = 3;
121module_param(phy_gen, byte, 0);
122MODULE_PARM_DESC(phy_gen, "PHY generation (1: 1.5Gbps 2: 3.0Gbps 3: 6.0Gbps)");
123
124unsigned char max_concurr_spinup = 1;
125module_param(max_concurr_spinup, byte, 0);
126MODULE_PARM_DESC(max_concurr_spinup, "Max concurrent device spinup");
127
Dan Williams6f231dd2011-07-02 22:56:22 -0700128static struct scsi_host_template isci_sht = {
129
130 .module = THIS_MODULE,
131 .name = DRV_NAME,
Havard Skinnemoen92cd5112011-02-18 18:32:08 -0800132 .proc_name = DRV_NAME,
Dan Williams6f231dd2011-07-02 22:56:22 -0700133 .queuecommand = sas_queuecommand,
134 .target_alloc = sas_target_alloc,
135 .slave_configure = sas_slave_configure,
136 .slave_destroy = sas_slave_destroy,
137 .scan_finished = isci_host_scan_finished,
138 .scan_start = isci_host_scan_start,
139 .change_queue_depth = sas_change_queue_depth,
140 .change_queue_type = sas_change_queue_type,
141 .bios_param = sas_bios_param,
142 .can_queue = ISCI_CAN_QUEUE_VAL,
143 .cmd_per_lun = 1,
144 .this_id = -1,
145 .sg_tablesize = SG_ALL,
146 .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
147 .use_clustering = ENABLE_CLUSTERING,
148 .eh_device_reset_handler = sas_eh_device_reset_handler,
149 .eh_bus_reset_handler = isci_bus_reset_handler,
150 .slave_alloc = sas_slave_alloc,
151 .target_destroy = sas_target_destroy,
152 .ioctl = sas_ioctl,
153};
154
155static struct sas_domain_function_template isci_transport_ops = {
156
157 /* The class calls these to notify the LLDD of an event. */
158 .lldd_port_formed = isci_port_formed,
159 .lldd_port_deformed = isci_port_deformed,
160
161 /* The class calls these when a device is found or gone. */
162 .lldd_dev_found = isci_remote_device_found,
163 .lldd_dev_gone = isci_remote_device_gone,
164
165 .lldd_execute_task = isci_task_execute_task,
166 /* Task Management Functions. Must be called from process context. */
167 .lldd_abort_task = isci_task_abort_task,
168 .lldd_abort_task_set = isci_task_abort_task_set,
169 .lldd_clear_aca = isci_task_clear_aca,
170 .lldd_clear_task_set = isci_task_clear_task_set,
171 .lldd_I_T_nexus_reset = isci_task_I_T_nexus_reset,
172 .lldd_lu_reset = isci_task_lu_reset,
173 .lldd_query_task = isci_task_query_task,
174
175 /* Port and Adapter management */
176 .lldd_clear_nexus_port = isci_task_clear_nexus_port,
177 .lldd_clear_nexus_ha = isci_task_clear_nexus_ha,
178
179 /* Phy management */
180 .lldd_control_phy = isci_phy_control,
181};
182
183
184/******************************************************************************
185* P R O T E C T E D M E T H O D S
186******************************************************************************/
187
188
189
190/**
191 * isci_register_sas_ha() - This method initializes various lldd
192 * specific members of the sas_ha struct and calls the libsas
193 * sas_register_ha() function.
194 * @isci_host: This parameter specifies the lldd specific wrapper for the
195 * libsas sas_ha struct.
196 *
197 * This method returns an error code indicating sucess or failure. The user
198 * should check for possible memory allocation error return otherwise, a zero
199 * indicates success.
200 */
201static int isci_register_sas_ha(struct isci_host *isci_host)
202{
203 int i;
204 struct sas_ha_struct *sas_ha = &(isci_host->sas_ha);
205 struct asd_sas_phy **sas_phys;
206 struct asd_sas_port **sas_ports;
207
208 sas_phys = devm_kzalloc(&isci_host->pdev->dev,
209 SCI_MAX_PHYS * sizeof(void *),
210 GFP_KERNEL);
211 if (!sas_phys)
212 return -ENOMEM;
213
214 sas_ports = devm_kzalloc(&isci_host->pdev->dev,
215 SCI_MAX_PORTS * sizeof(void *),
216 GFP_KERNEL);
217 if (!sas_ports)
218 return -ENOMEM;
219
220 /*----------------- Libsas Initialization Stuff----------------------
221 * Set various fields in the sas_ha struct:
222 */
223
224 sas_ha->sas_ha_name = DRV_NAME;
225 sas_ha->lldd_module = THIS_MODULE;
Dan Williams150fc6f2011-02-25 10:25:21 -0800226 sas_ha->sas_addr = &isci_host->phys[0].sas_addr[0];
Dan Williams6f231dd2011-07-02 22:56:22 -0700227
228 /* set the array of phy and port structs. */
229 for (i = 0; i < SCI_MAX_PHYS; i++) {
230 sas_phys[i] = &(isci_host->phys[i].sas_phy);
231 sas_ports[i] = &(isci_host->sas_ports[i]);
232 }
233
234 sas_ha->sas_phy = sas_phys;
235 sas_ha->sas_port = sas_ports;
236 sas_ha->num_phys = SCI_MAX_PHYS;
237
238 sas_ha->lldd_queue_size = ISCI_CAN_QUEUE_VAL;
239 sas_ha->lldd_max_execute_num = 1;
240 sas_ha->strict_wide_ports = 1;
241
242 sas_register_ha(sas_ha);
243
244 return 0;
245}
246
Dan Williams34cad852011-03-10 00:01:43 -0800247static ssize_t isci_show_id(struct device *dev, struct device_attribute *attr, char *buf)
Dan Williams6f231dd2011-07-02 22:56:22 -0700248{
Dan Williams34cad852011-03-10 00:01:43 -0800249 struct Scsi_Host *shost = container_of(dev, typeof(*shost), shost_dev);
250 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
251 struct isci_host *ihost = container_of(sas_ha, typeof(*ihost), sas_ha);
252
253 return snprintf(buf, PAGE_SIZE, "%d\n", ihost->id);
254}
255
256static DEVICE_ATTR(isci_id, S_IRUGO, isci_show_id, NULL);
257
258static void isci_unregister(struct isci_host *isci_host)
259{
260 struct Scsi_Host *shost;
261
Dan Williams6f231dd2011-07-02 22:56:22 -0700262 if (!isci_host)
263 return;
264
Dan Williams34cad852011-03-10 00:01:43 -0800265 shost = isci_host->shost;
266 device_remove_file(&shost->shost_dev, &dev_attr_isci_id);
267
268 sas_unregister_ha(&isci_host->sas_ha);
Dan Williams6f231dd2011-07-02 22:56:22 -0700269
270 sas_remove_host(isci_host->shost);
271 scsi_remove_host(isci_host->shost);
272 scsi_host_put(isci_host->shost);
273}
274
275static int __devinit isci_pci_init(struct pci_dev *pdev)
276{
277 int err, bar_num, bar_mask;
278 void __iomem * const *iomap;
279
280 err = pcim_enable_device(pdev);
281 if (err) {
282 dev_err(&pdev->dev,
283 "failed enable PCI device %s!\n",
284 pci_name(pdev));
285 return err;
286 }
287
288 for (bar_num = 0; bar_num < SCI_PCI_BAR_COUNT; bar_num++)
289 bar_mask |= 1 << (bar_num * 2);
290
291 err = pcim_iomap_regions(pdev, bar_mask, DRV_NAME);
292 if (err)
293 return err;
294
295 iomap = pcim_iomap_table(pdev);
296 if (!iomap)
297 return -ENOMEM;
298
299 pci_set_master(pdev);
300
301 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
302 if (err) {
303 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
304 if (err)
305 return err;
306 }
307
308 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
309 if (err) {
310 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
311 if (err)
312 return err;
313 }
314
315 return 0;
316}
317
Dan Williams6f231dd2011-07-02 22:56:22 -0700318static int num_controllers(struct pci_dev *pdev)
319{
320 /* bar size alone can tell us if we are running with a dual controller
321 * part, no need to trust revision ids that might be under broken firmware
322 * control
323 */
324 resource_size_t scu_bar_size = pci_resource_len(pdev, SCI_SCU_BAR*2);
325 resource_size_t smu_bar_size = pci_resource_len(pdev, SCI_SMU_BAR*2);
Dan Williamsf942f322011-03-26 16:30:06 -0700326
Dan Williams6f231dd2011-07-02 22:56:22 -0700327 if (scu_bar_size >= SCI_SCU_BAR_SIZE*SCI_MAX_CONTROLLERS &&
328 smu_bar_size >= SCI_SMU_BAR_SIZE*SCI_MAX_CONTROLLERS)
329 return SCI_MAX_CONTROLLERS;
330 else
331 return 1;
332}
333
334static int isci_setup_interrupts(struct pci_dev *pdev)
335{
336 int err, i, num_msix;
Dan Williams31e824e2011-04-19 12:32:51 -0700337 struct isci_host *ihost;
Dan Williams6f231dd2011-07-02 22:56:22 -0700338 struct isci_pci_info *pci_info = to_pci_info(pdev);
339
340 /*
341 * Determine the number of vectors associated with this
342 * PCI function.
343 */
344 num_msix = num_controllers(pdev) * SCI_NUM_MSI_X_INT;
345
346 for (i = 0; i < num_msix; i++)
347 pci_info->msix_entries[i].entry = i;
348
349 err = pci_enable_msix(pdev, pci_info->msix_entries, num_msix);
350 if (err)
351 goto intx;
352
353 for (i = 0; i < num_msix; i++) {
354 int id = i / SCI_NUM_MSI_X_INT;
355 struct msix_entry *msix = &pci_info->msix_entries[i];
Dan Williams92f4f0f2011-02-18 09:25:11 -0800356 irq_handler_t isr;
357
Dan Williams31e824e2011-04-19 12:32:51 -0700358 ihost = pci_info->hosts[id];
Dan Williams92f4f0f2011-02-18 09:25:11 -0800359 /* odd numbered vectors are error interrupts */
360 if (i & 1)
361 isr = isci_error_isr;
362 else
363 isr = isci_msix_isr;
Dan Williams6f231dd2011-07-02 22:56:22 -0700364
Dan Williams92f4f0f2011-02-18 09:25:11 -0800365 err = devm_request_irq(&pdev->dev, msix->vector, isr, 0,
Dan Williams31e824e2011-04-19 12:32:51 -0700366 DRV_NAME"-msix", ihost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700367 if (!err)
368 continue;
369
370 dev_info(&pdev->dev, "msix setup failed falling back to intx\n");
371 while (i--) {
372 id = i / SCI_NUM_MSI_X_INT;
Dan Williams31e824e2011-04-19 12:32:51 -0700373 ihost = pci_info->hosts[id];
Dan Williams6f231dd2011-07-02 22:56:22 -0700374 msix = &pci_info->msix_entries[i];
Dan Williams31e824e2011-04-19 12:32:51 -0700375 devm_free_irq(&pdev->dev, msix->vector, ihost);
Dan Williams6f231dd2011-07-02 22:56:22 -0700376 }
377 pci_disable_msix(pdev);
378 goto intx;
379 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700380 return 0;
381
382 intx:
Dan Williams31e824e2011-04-19 12:32:51 -0700383 for_each_isci_host(i, ihost, pdev) {
384 err = devm_request_irq(&pdev->dev, pdev->irq, isci_intx_isr,
385 IRQF_SHARED, DRV_NAME"-intx", ihost);
386 if (err)
387 break;
388 }
Dan Williams6f231dd2011-07-02 22:56:22 -0700389 return err;
390}
391
Dan Williams6f231dd2011-07-02 22:56:22 -0700392static struct isci_host *isci_host_alloc(struct pci_dev *pdev, int id)
393{
394 struct isci_host *isci_host;
395 struct Scsi_Host *shost;
396 int err;
397
Dan Williams57f20f42011-04-21 18:14:45 -0700398 isci_host = devm_kzalloc(&pdev->dev, sizeof(*isci_host), GFP_KERNEL);
Dan Williams6f231dd2011-07-02 22:56:22 -0700399 if (!isci_host)
400 return NULL;
401
402 isci_host->pdev = pdev;
403 isci_host->id = id;
404
405 shost = scsi_host_alloc(&isci_sht, sizeof(void *));
406 if (!shost)
407 return NULL;
408 isci_host->shost = shost;
409
410 err = isci_host_init(isci_host);
411 if (err)
412 goto err_shost;
413
414 SHOST_TO_SAS_HA(shost) = &isci_host->sas_ha;
415 isci_host->sas_ha.core.shost = shost;
416 shost->transportt = isci_transport_template;
417
418 shost->max_id = ~0;
419 shost->max_lun = ~0;
420 shost->max_cmd_len = MAX_COMMAND_SIZE;
421
422 err = scsi_add_host(shost, &pdev->dev);
423 if (err)
424 goto err_shost;
425
426 err = isci_register_sas_ha(isci_host);
427 if (err)
428 goto err_shost_remove;
429
Dan Williams34cad852011-03-10 00:01:43 -0800430 err = device_create_file(&shost->shost_dev, &dev_attr_isci_id);
431 if (err)
432 goto err_unregister_ha;
433
Dan Williams6f231dd2011-07-02 22:56:22 -0700434 return isci_host;
435
Dan Williams34cad852011-03-10 00:01:43 -0800436 err_unregister_ha:
437 sas_unregister_ha(&(isci_host->sas_ha));
Dan Williams6f231dd2011-07-02 22:56:22 -0700438 err_shost_remove:
439 scsi_remove_host(shost);
440 err_shost:
441 scsi_host_put(shost);
442
443 return NULL;
444}
445
446static void check_si_rev(struct pci_dev *pdev)
447{
448 if (num_controllers(pdev) > 1)
449 isci_si_rev = ISCI_SI_REVB0;
450 else {
451 switch (pdev->revision) {
452 case 0:
453 case 1:
454 /* if the id is ambiguous don't update isci_si_rev */
455 break;
456 case 3:
457 isci_si_rev = ISCI_SI_REVA2;
458 break;
459 default:
460 case 4:
461 isci_si_rev = ISCI_SI_REVB0;
462 break;
463 }
464 }
465
466 dev_info(&pdev->dev, "driver configured for %s silicon (rev: %d)\n",
467 isci_si_rev == ISCI_SI_REVA0 ? "A0" :
468 isci_si_rev == ISCI_SI_REVA2 ? "A2" : "B0", pdev->revision);
Dan Williamsf942f322011-03-26 16:30:06 -0700469
Dan Williams6f231dd2011-07-02 22:56:22 -0700470}
471
472static int __devinit isci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
473{
474 struct isci_pci_info *pci_info;
475 int err, i;
476 struct isci_host *isci_host;
Dave Jiang858d4aa2011-02-22 01:27:03 -0800477 const struct firmware *fw = NULL;
Dan Williamsd044af12011-03-08 09:52:49 -0800478 struct isci_orom *orom;
Dan Williams4711ba12011-03-11 10:43:57 -0800479 char *source = "(platform)";
Dan Williams6f231dd2011-07-02 22:56:22 -0700480
481 check_si_rev(pdev);
482
483 pci_info = devm_kzalloc(&pdev->dev, sizeof(*pci_info), GFP_KERNEL);
484 if (!pci_info)
485 return -ENOMEM;
486 pci_set_drvdata(pdev, pci_info);
487
Dave Jiang8db37aa2011-02-23 00:02:24 -0800488 if (efi_enabled)
489 orom = isci_get_efi_var(pdev);
490 else
Dan Williamsd044af12011-03-08 09:52:49 -0800491 orom = isci_request_oprom(pdev);
492
Dan Williams2d70de52011-04-20 12:57:08 -0700493 for (i = 0; orom && i < ARRAY_SIZE(orom->ctrl); i++) {
494 if (scic_oem_parameters_validate(&orom->ctrl[i])) {
495 dev_warn(&pdev->dev,
496 "[%d]: invalid oem parameters detected, falling back to firmware\n", i);
497 devm_kfree(&pdev->dev, orom);
498 orom = NULL;
499 break;
500 }
501 }
502
Dan Williamsd044af12011-03-08 09:52:49 -0800503 if (!orom) {
Dan Williams4711ba12011-03-11 10:43:57 -0800504 source = "(firmware)";
Dan Williamsd044af12011-03-08 09:52:49 -0800505 orom = isci_request_firmware(pdev, fw);
506 if (!orom) {
507 /* TODO convert this to WARN_TAINT_ONCE once the
508 * orom/efi parameter support is widely available
509 */
510 dev_warn(&pdev->dev,
511 "Loading user firmware failed, using default "
512 "values\n");
513 dev_warn(&pdev->dev,
514 "Default OEM configuration being used: 4 "
515 "narrow ports, and default SAS Addresses\n");
Dave Jiang858d4aa2011-02-22 01:27:03 -0800516 }
Dave Jiang858d4aa2011-02-22 01:27:03 -0800517 }
518
Dan Williamsd044af12011-03-08 09:52:49 -0800519 if (orom)
Dan Williams3b67c1f2011-03-08 09:53:51 -0800520 dev_info(&pdev->dev,
Dan Williams4711ba12011-03-11 10:43:57 -0800521 "OEM SAS parameters (version: %u.%u) loaded %s\n",
Dan Williams3b67c1f2011-03-08 09:53:51 -0800522 (orom->hdr.version & 0xf0) >> 4,
Dan Williams4711ba12011-03-11 10:43:57 -0800523 (orom->hdr.version & 0xf), source);
Dan Williams3b67c1f2011-03-08 09:53:51 -0800524
Dan Williamsd044af12011-03-08 09:52:49 -0800525 pci_info->orom = orom;
526
Dan Williams6f231dd2011-07-02 22:56:22 -0700527 err = isci_pci_init(pdev);
528 if (err)
529 return err;
530
531 for (i = 0; i < num_controllers(pdev); i++) {
532 struct isci_host *h = isci_host_alloc(pdev, i);
533
534 if (!h) {
535 err = -ENOMEM;
536 goto err_host_alloc;
537 }
Dan Williamsb329aff2011-03-07 16:02:25 -0800538 pci_info->hosts[i] = h;
Dan Williams6f231dd2011-07-02 22:56:22 -0700539 }
540
541 err = isci_setup_interrupts(pdev);
542 if (err)
543 goto err_host_alloc;
544
Dan Williamsb329aff2011-03-07 16:02:25 -0800545 for_each_isci_host(i, isci_host, pdev)
Dan Williams6f231dd2011-07-02 22:56:22 -0700546 scsi_scan_host(isci_host->shost);
547
548 return 0;
549
550 err_host_alloc:
Dan Williamsb329aff2011-03-07 16:02:25 -0800551 for_each_isci_host(i, isci_host, pdev)
Dan Williams34cad852011-03-10 00:01:43 -0800552 isci_unregister(isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700553 return err;
554}
555
556static void __devexit isci_pci_remove(struct pci_dev *pdev)
557{
558 struct isci_host *isci_host;
Dan Williamsb329aff2011-03-07 16:02:25 -0800559 int i;
Dan Williams6f231dd2011-07-02 22:56:22 -0700560
Dan Williamsb329aff2011-03-07 16:02:25 -0800561 for_each_isci_host(i, isci_host, pdev) {
Dan Williams34cad852011-03-10 00:01:43 -0800562 isci_unregister(isci_host);
Dan Williams6f231dd2011-07-02 22:56:22 -0700563 isci_host_deinit(isci_host);
564 scic_controller_disable_interrupts(isci_host->core_controller);
565 }
566}
567
Dan Williamsf942f322011-03-26 16:30:06 -0700568static struct pci_driver isci_pci_driver = {
569 .name = DRV_NAME,
570 .id_table = isci_id_table,
571 .probe = isci_pci_probe,
572 .remove = __devexit_p(isci_pci_remove),
573};
574
Dan Williams6f231dd2011-07-02 22:56:22 -0700575static __init int isci_init(void)
576{
Dan Williamsd9c37392011-03-03 17:59:32 -0800577 int err;
Dan Williams6f231dd2011-07-02 22:56:22 -0700578
579 pr_info("%s: Intel(R) C600 SAS Controller Driver\n", DRV_NAME);
580
Dan Williams6f231dd2011-07-02 22:56:22 -0700581 isci_transport_template = sas_domain_attach_transport(&isci_transport_ops);
582 if (!isci_transport_template)
Dan Williamsd9c37392011-03-03 17:59:32 -0800583 return -ENOMEM;
Dan Williams6f231dd2011-07-02 22:56:22 -0700584
585 err = pci_register_driver(&isci_pci_driver);
586 if (err)
Dan Williamsd9c37392011-03-03 17:59:32 -0800587 sas_release_transport(isci_transport_template);
Dan Williams6f231dd2011-07-02 22:56:22 -0700588
589 return err;
590}
591
592static __exit void isci_exit(void)
593{
594 pci_unregister_driver(&isci_pci_driver);
595 sas_release_transport(isci_transport_template);
Dan Williams6f231dd2011-07-02 22:56:22 -0700596}
597
598MODULE_LICENSE("Dual BSD/GPL");
599MODULE_FIRMWARE(ISCI_FW_NAME);
600module_init(isci_init);
601module_exit(isci_exit);