35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/pci.h>
43 #include <linux/device.h>
51 #define DRV_NAME "ahci"
52 #define DRV_VERSION "3.0"
83 static int ahci_vt8251_hardreset(
struct ata_link *
link,
unsigned int *
class,
84 unsigned long deadline);
85 static int ahci_p5wdh_hardreset(
struct ata_link *
link,
unsigned int *
class,
86 unsigned long deadline);
89 static int ahci_pci_device_resume(
struct pci_dev *pdev);
98 .hardreset = ahci_vt8251_hardreset,
103 .hardreset = ahci_p5wdh_hardreset,
187 .port_ops = &ahci_vt8251_ops,
393 .class_mask = 0xffffff,
423 .id_table = ahci_pci_tbl,
424 .probe = ahci_init_one,
425 .remove = ata_pci_remove_one,
427 .suspend = ahci_pci_device_suspend,
428 .resume = ahci_pci_device_resume,
432 #if defined(CONFIG_PATA_MARVELL) || defined(CONFIG_PATA_MARVELL_MODULE)
433 static int marvell_enable;
435 static int marvell_enable = 1;
441 static void ahci_pci_save_initial_config(
struct pci_dev *pdev,
444 unsigned int force_port_map = 0;
445 unsigned int mask_port_map = 0;
448 dev_info(&pdev->
dev,
"JMB361 has only one port\n");
458 if (pdev->
device == 0x6121)
463 "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
470 static int ahci_pci_reset_controller(
struct ata_host *
host)
481 pci_read_config_word(pdev, 0x92, &tmp16);
484 pci_write_config_word(pdev, 0x92, tmp16);
491 static void ahci_pci_init_controller(
struct ata_host *host)
500 if (pdev->
device == 0x6121)
504 port_mmio = __ahci_port_base(host, mv);
510 VPRINTK(
"PORT_IRQ_STAT 0x%x\n", tmp);
518 static int ahci_vt8251_hardreset(
struct ata_link *
link,
unsigned int *
class,
519 unsigned long deadline)
530 deadline, &online,
NULL);
534 DPRINTK(
"EXIT, rc=%d, class=%u\n", rc, *
class);
542 static int ahci_p5wdh_hardreset(
struct ata_link *link,
unsigned int *
class,
543 unsigned long deadline)
560 deadline, &online,
NULL);
597 "BIOS update required for suspend/resume\n");
612 return ata_pci_device_suspend(pdev, mesg);
615 static int ahci_pci_device_resume(
struct pci_dev *pdev)
620 rc = ata_pci_device_do_resume(pdev);
625 rc = ahci_pci_reset_controller(host);
629 ahci_pci_init_controller(host);
632 ata_host_resume(host);
638 static int ahci_configure_dma_masks(
struct pci_dev *pdev,
int using_dac)
651 rc = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64));
653 rc = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
656 "64-bit DMA enable failed\n");
663 dev_err(&pdev->
dev,
"32-bit DMA enable failed\n");
666 rc = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
669 "32-bit consistent DMA enable failed\n");
676 static void ahci_pci_print_info(
struct ata_host *host)
682 pci_read_config_word(pdev, 0x0a, &cc);
713 static void ahci_p5wdh_workaround(
struct ata_host *host)
717 .
ident =
"P5W DH Deluxe",
720 "ASUSTEK COMPUTER INC"),
733 "enabling ASUS P5W DH Deluxe on-board SIMG4726 workaround\n");
735 ap->
ops = &ahci_p5wdh_ops;
741 static bool ahci_sb600_enable_64bit(
struct pci_dev *pdev)
752 .
ident =
"ASUS M2A-VM",
755 "ASUSTeK Computer INC."),
758 .driver_data =
"20071026",
777 .ident =
"MSI K9A2 Platinum",
793 .ident =
"MSI K9AGM2",
808 "ASUSTeK Computer INC."),
823 if (!match->driver_data)
827 snprintf(buf,
sizeof(buf),
"%04d%02d%02d", year, month, date);
829 if (
strcmp(buf, match->driver_data) >= 0)
833 "%s: BIOS too old, forcing 32bit DMA, update BIOS\n",
843 static bool ahci_broken_system_poweroff(
struct pci_dev *pdev)
847 .
ident =
"HP Compaq nx6310",
853 .driver_data = (
void *)0x1FUL,
856 .ident =
"HP Compaq 6720s",
862 .driver_data = (
void *)0x1FUL,
870 unsigned long slot = (
unsigned long)dmi->driver_data;
878 static bool ahci_broken_suspend(
struct pci_dev *pdev)
899 "HP Pavilion dv4 Notebook PC"),
901 .driver_data =
"20090105",
908 "HP Pavilion dv5 Notebook PC"),
910 .driver_data =
"20090506",
917 "HP Pavilion dv6 Notebook PC"),
919 .driver_data =
"20090423",
926 "HP HDX18 Notebook PC"),
928 .driver_data =
"20090430",
945 .driver_data =
"20091216",
957 snprintf(buf,
sizeof(buf),
"%04d%02d%02d", year, month, date);
959 return strcmp(buf, dmi->driver_data) < 0;
962 static bool ahci_broken_online(
struct pci_dev *pdev)
964 #define ENCODE_BUSDEVFN(bus, slot, func) \
965 (void *)(unsigned long)(((bus) << 8) | PCI_DEVFN((slot), (func)))
984 "Gigabyte Technology Co., Ltd."),
993 "Gigabyte Technology Co., Ltd."),
1000 #undef ENCODE_BUSDEVFN
1007 val = (
unsigned long)dmi->driver_data;
1009 return pdev->
bus->number == (val >> 8) && pdev->
devfn == (val & 0xff);
1012 #ifdef CONFIG_ATA_ACPI
1013 static void ahci_gtf_filter_workaround(
struct ata_host *host)
1025 .
ident =
"Aspire 3810T",
1041 filter = (
unsigned long)dmi->driver_data;
1042 dev_info(host->
dev,
"applying extra ACPI _GTF filter 0x%x for %s\n",
1043 filter, dmi->
ident);
1045 for (i = 0; i < host->
n_ports; i++) {
1052 dev->gtf_filter |= filter;
1056 static inline void ahci_gtf_filter_workaround(
struct ata_host *host)
1099 "PDC42819 can only drive SATA devices with this driver\n");
1127 pci_read_config_byte(pdev,
ICH_MAP, &map);
1130 "controller is in combined mode, can't enable AHCI mode\n");
1150 if (ahci_sb600_enable_64bit(pdev))
1159 ahci_pci_save_initial_config(pdev, hpriv);
1179 if (ahci_broken_system_poweroff(pdev)) {
1182 "quirky BIOS, skipping spindown on poweroff\n");
1185 if (ahci_broken_suspend(pdev)) {
1188 "BIOS update required for suspend/resume\n");
1191 if (ahci_broken_online(pdev)) {
1194 "online status unreliable, applying workaround\n");
1217 for (i = 0; i < host->
n_ports; i++) {
1220 ata_port_pbar_desc(ap, ahci_pci_bar, -1,
"abar");
1221 ata_port_pbar_desc(ap, ahci_pci_bar,
1222 0x100 + ap->
port_no * 0x80,
"port");
1235 ahci_p5wdh_workaround(host);
1238 ahci_gtf_filter_workaround(host);
1245 rc = ahci_pci_reset_controller(host);
1249 ahci_pci_init_controller(host);
1250 ahci_pci_print_info(host);