27 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/pci.h>
33 #include <linux/slab.h>
44 #define ASD_DRIVER_VERSION "1.0.3"
46 static int use_msi = 0;
49 "\tEnable(1) or disable(0) using PCI MSI.\n"
52 static int lldd_max_execute_num = 0;
55 "\tIf greater than one, tells the SAS Layer to run in Task Collector\n"
56 "\tMode. If 1 or 0, tells the SAS Layer to run in Direct Mode.\n"
57 "\tThe aic94xx SAS LLDD supports both modes.\n"
58 "\tDefault: 0 (Direct Mode).\n");
61 static int asd_scan_finished(
struct Scsi_Host *,
unsigned long);
62 static void asd_scan_start(
struct Scsi_Host *);
71 .scan_finished = asd_scan_finished,
72 .scan_start = asd_scan_start,
94 for (i = 0; i < 3; i += 2) {
100 if (!io_handle->
start || !io_handle->
len) {
101 asd_printk(
"MBAR%d start or length for %s is 0.\n",
102 i==0?0:1, pci_name(asd_ha->
pcidev));
107 asd_printk(
"couldn't reserve memory region for %s\n",
108 pci_name(asd_ha->
pcidev));
117 if (!io_handle->
addr) {
118 asd_printk(
"couldn't map MBAR%d of %s\n", i==0?0:1,
119 pci_name(asd_ha->
pcidev));
161 pci_name(asd_ha->
pcidev));
166 asd_printk(
"couldn't reserve io space for %s\n",
167 pci_name(asd_ha->
pcidev));
185 asd_printk(
"couldn't read command register of %s\n",
186 pci_name(asd_ha->
pcidev));
192 if ((err = asd_map_memio(asd_ha)))
195 if ((err = asd_map_ioport(asd_ha)))
197 asd_printk(
"%s ioport mapped -- upgrade your hardware\n",
198 pci_name(asd_ha->
pcidev));
201 pci_name(asd_ha->
pcidev));
213 asd_unmap_ioport(asd_ha);
215 asd_unmap_memio(asd_ha);
218 static const char *asd_dev_rev[30] = {
232 asd_printk(
"%s is revision %s (%X), which is not supported\n",
239 asd_ha->
hw_prof.max_scbs = 512;
243 asd_ha->
hw_prof.enabled_phys = 0xFF;
245 asd_ha->
hw_prof.phy_desc[
i].max_sas_lrate =
247 asd_ha->
hw_prof.phy_desc[
i].min_sas_lrate =
249 asd_ha->
hw_prof.phy_desc[
i].max_sata_lrate =
251 asd_ha->
hw_prof.phy_desc[
i].min_sata_lrate =
262 int err = asd_common_setup(asd_ha);
267 asd_ha->
hw_prof.addr_range = 8;
268 asd_ha->
hw_prof.port_name_base = 0;
269 asd_ha->
hw_prof.dev_name_base = 8;
270 asd_ha->
hw_prof.sata_name_base = 16;
277 int err = asd_common_setup(asd_ha);
282 asd_ha->
hw_prof.addr_range = 4;
283 asd_ha->
hw_prof.port_name_base = 0;
284 asd_ha->
hw_prof.dev_name_base = 4;
285 asd_ha->
hw_prof.sata_name_base = 8;
315 #define FLASH_CMD_NONE 0x00
316 #define FLASH_CMD_UPDATE 0x01
317 #define FLASH_CMD_VERIFY 0x02
336 static struct error_bios flash_error_table[] =
359 char *cmd_ptr, *filename_ptr;
373 filename_ptr = cmd_ptr +
count;
374 res =
sscanf(buf,
"%s %s", cmd_ptr, filename_ptr);
382 cmd_ptr,
strlen(cmd_ptr))) {
383 flash_command = flash_command_table[
i].
code;
400 asd_printk(
"Failed to load bios image file %s, error %d\n",
413 ASD_DPRINTK(
"The PCI vendor or device id does not match\n");
414 ASD_DPRINTK(
"vendor=%x dev=%x sub_vendor=%x sub_dev=%x"
415 " pci vendor=%x pci dev=%x\n",
432 for (i = 0; i < hdr_ptr->
filelen; i++)
435 if ((csum & 0x0000ffff) != hdr_ptr->
checksum) {
444 0, hdr_ptr->
filelen-
sizeof(*hdr_ptr));
448 0, hdr_ptr->
filelen-
sizeof(*hdr_ptr));
475 for (i = 0; flash_error_table[
i].
err_code != 0; i++) {
484 flash_error_table[i].
reason);
488 asd_show_update_bios, asd_store_update_bios);
490 static int asd_create_dev_attrs(
struct asd_ha_struct *asd_ha)
507 goto err_update_bios;
520 static void asd_remove_dev_attrs(
struct asd_ha_struct *asd_ha)
531 static const struct asd_pcidev_struct {
536 { .name =
"Adaptec AIC-94xx SAS/SATA Host Adapter",
537 .setup = asd_aic9410_setup
539 { .name =
"Adaptec AIC-9410W SAS/SATA Host Adapter",
540 .setup = asd_aic9410_setup
542 { .name =
"Adaptec AIC-9405W SAS/SATA Host Adapter",
543 .setup = asd_aic9405_setup
547 static int asd_create_ha_caches(
struct asd_ha_struct *asd_ha)
571 asd_free_coherent(asd_ha, seq->
edb_arr[i]);
582 if (!list_empty(&seq->
escb_arr[i]->list))
583 list_del_init(&seq->
escb_arr[i]->list);
591 static void asd_destroy_ha_caches(
struct asd_ha_struct *asd_ha)
596 asd_free_coherent(asd_ha, asd_ha->
hw_prof.ddb_ext);
598 asd_free_coherent(asd_ha, asd_ha->
hw_prof.scb_ext);
600 if (asd_ha->
hw_prof.ddb_bitmap)
609 if (asd_ha->
seq.escb_arr)
610 asd_free_escbs(asd_ha);
611 if (asd_ha->
seq.edb_arr)
612 asd_free_edbs(asd_ha);
617 if (asd_ha->
seq.tc_index_array) {
620 asd_ha->
seq.tc_index_array =
NULL;
621 asd_ha->
seq.tc_index_bitmap =
NULL;
623 if (asd_ha->
seq.actual_dl) {
624 asd_free_coherent(asd_ha, asd_ha->
seq.actual_dl);
628 if (asd_ha->
seq.next_scb.vaddr) {
630 asd_ha->
seq.next_scb.dma_handle);
631 asd_ha->
seq.next_scb.vaddr =
NULL;
640 static int asd_create_global_caches(
void)
642 if (!asd_dma_token_cache) {
649 if (!asd_dma_token_cache) {
650 asd_printk(
"couldn't create dma token cache\n");
655 if (!asd_ascb_cache) {
661 if (!asd_ascb_cache) {
670 asd_dma_token_cache =
NULL;
674 static void asd_destroy_global_caches(
void)
676 if (asd_dma_token_cache)
678 asd_dma_token_cache =
NULL;
682 asd_ascb_cache =
NULL;
689 kcalloc(ASD_MAX_PHYS,
sizeof(*sas_phys),
GFP_KERNEL);
691 kcalloc(ASD_MAX_PHYS,
sizeof(*sas_ports),
GFP_KERNEL);
693 if (!sas_phys || !sas_ports) {
699 asd_ha->
sas_ha.sas_ha_name = (
char *) asd_ha->
name;
704 sas_phys[
i] = &asd_ha->
phys[
i].sas_phy;
705 sas_ports[
i] = &asd_ha->
ports[
i];
708 asd_ha->
sas_ha.sas_phy = sas_phys;
709 asd_ha->
sas_ha.sas_port= sas_ports;
712 asd_ha->
sas_ha.lldd_queue_size = asd_ha->
seq.can_queue;
713 asd_ha->
sas_ha.lldd_max_execute_num = lldd_max_execute_num;
718 static int asd_unregister_sas_ha(
struct asd_ha_struct *asd_ha)
737 const struct asd_pcidev_struct *asd_dev;
744 asd_printk(
"wrong driver_data in PCI table\n");
749 asd_printk(
"couldn't enable device %s\n", pci_name(dev));
761 asd_dev = &asd_pcidev_data[asd_id];
763 asd_ha = kzalloc(
sizeof(*asd_ha),
GFP_KERNEL);
770 asd_ha->
sas_ha.lldd_ha = asd_ha;
773 asd_ha->
name = asd_dev->name;
778 shost->transportt = aic94xx_transport_template;
781 shost->max_cmd_len = 16;
783 err = scsi_add_host(
shost, &dev->
dev);
787 err = asd_dev->setup(asd_ha);
799 asd_printk(
"no suitable DMA mask for %s\n", pci_name(dev));
803 pci_set_drvdata(dev, asd_ha);
805 err = asd_map_ha(asd_ha);
809 err = asd_create_ha_caches(asd_ha);
817 asd_printk(
"device %s: SAS addr %llx, PCBA SN %s, %d phys, %d enabled "
818 "phys, flash %s, BIOS %s%d\n",
822 asd_ha->
hw_prof.flash.present ?
"present" :
"not present",
823 asd_ha->
hw_prof.bios.present ?
"build " :
"not present",
826 shost->can_queue = asd_ha->
seq.can_queue;
829 pci_enable_msi(asd_ha->
pcidev);
838 asd_enable_ints(asd_ha);
843 pci_name(asd_ha->
pcidev));
848 err = asd_create_dev_attrs(asd_ha);
852 err = asd_register_sas_ha(asd_ha);
861 asd_remove_dev_attrs(asd_ha);
864 asd_disable_ints(asd_ha);
871 asd_destroy_ha_caches(asd_ha);
873 asd_unmap_ha(asd_ha);
892 asd_ha->
seq.pending = 0;
893 list_splice_init(&asd_ha->
seq.pend_q, &pending);
894 spin_unlock_irqrestore(&asd_ha->
seq.pend_q_lock, flags);
896 if (!list_empty(&pending))
934 asd_unregister_sas_ha(asd_ha);
936 asd_disable_ints(asd_ha);
938 asd_remove_dev_attrs(asd_ha);
945 asd_turn_off_leds(asd_ha);
947 asd_free_queues(asd_ha);
948 asd_destroy_ha_caches(asd_ha);
949 asd_unmap_ha(asd_ha);
963 asd_printk(
"Couldn't enable phys, err:%d\n", err);
966 static int asd_scan_finished(
struct Scsi_Host *shost,
unsigned long time)
1015 static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
1030 static struct pci_driver aic94xx_pci_driver = {
1032 .id_table = aic94xx_pci_table,
1033 .probe = asd_pci_probe,
1037 static int __init aic94xx_init(
void)
1045 err = asd_create_global_caches();
1049 aic94xx_transport_template =
1051 if (!aic94xx_transport_template)
1052 goto out_destroy_caches;
1054 err = pci_register_driver(&aic94xx_pci_driver);
1056 goto out_release_transport;
1058 err = asd_create_driver_attrs(&aic94xx_pci_driver.
driver);
1060 goto out_unregister_pcidrv;
1064 out_unregister_pcidrv:
1066 out_release_transport:
1069 asd_destroy_global_caches();
1074 static void __exit aic94xx_exit(
void)
1076 asd_remove_driver_attrs(&aic94xx_pci_driver.
driver);
1080 asd_destroy_global_caches();