ahci.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846
  1. /*
  2. * ahci.c - AHCI SATA support
  3. *
  4. * Maintained by: Tejun Heo <tj@kernel.org>
  5. * Please ALWAYS copy linux-ide@vger.kernel.org
  6. * on emails.
  7. *
  8. * Copyright 2004-2005 Red Hat, Inc.
  9. *
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; see the file COPYING. If not, write to
  23. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. *
  26. * libata documentation is available via 'make {ps|pdf}docs',
  27. * as Documentation/driver-api/libata.rst
  28. *
  29. * AHCI hardware documentation:
  30. * http://www.intel.com/technology/serialata/pdf/rev1_0.pdf
  31. * http://www.intel.com/technology/serialata/pdf/rev1_1.pdf
  32. *
  33. */
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/pci.h>
  37. #include <linux/blkdev.h>
  38. #include <linux/delay.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/dma-mapping.h>
  41. #include <linux/device.h>
  42. #include <linux/dmi.h>
  43. #include <linux/gfp.h>
  44. #include <linux/msi.h>
  45. #include <scsi/scsi_host.h>
  46. #include <scsi/scsi_cmnd.h>
  47. #include <linux/libata.h>
  48. #include <linux/ahci-remap.h>
  49. #include <linux/io-64-nonatomic-lo-hi.h>
  50. #include "ahci.h"
  51. #define DRV_NAME "ahci"
  52. #define DRV_VERSION "3.0"
  53. enum {
  54. AHCI_PCI_BAR_STA2X11 = 0,
  55. AHCI_PCI_BAR_CAVIUM = 0,
  56. AHCI_PCI_BAR_ENMOTUS = 2,
  57. AHCI_PCI_BAR_STANDARD = 5,
  58. };
  59. enum board_ids {
  60. /* board IDs by feature in alphabetical order */
  61. board_ahci,
  62. board_ahci_ign_iferr,
  63. board_ahci_nomsi,
  64. board_ahci_noncq,
  65. board_ahci_nosntf,
  66. board_ahci_yes_fbs,
  67. /* board IDs for specific chipsets in alphabetical order */
  68. board_ahci_avn,
  69. board_ahci_mcp65,
  70. board_ahci_mcp77,
  71. board_ahci_mcp89,
  72. board_ahci_mv,
  73. board_ahci_sb600,
  74. board_ahci_sb700, /* for SB700 and SB800 */
  75. board_ahci_vt8251,
  76. /* aliases */
  77. board_ahci_mcp_linux = board_ahci_mcp65,
  78. board_ahci_mcp67 = board_ahci_mcp65,
  79. board_ahci_mcp73 = board_ahci_mcp65,
  80. board_ahci_mcp79 = board_ahci_mcp77,
  81. };
  82. static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
  83. static void ahci_remove_one(struct pci_dev *dev);
  84. static void ahci_shutdown_one(struct pci_dev *dev);
  85. static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
  86. unsigned long deadline);
  87. static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
  88. unsigned long deadline);
  89. static void ahci_mcp89_apple_enable(struct pci_dev *pdev);
  90. static bool is_mcp89_apple(struct pci_dev *pdev);
  91. static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
  92. unsigned long deadline);
  93. #ifdef CONFIG_PM
  94. static int ahci_pci_device_runtime_suspend(struct device *dev);
  95. static int ahci_pci_device_runtime_resume(struct device *dev);
  96. #ifdef CONFIG_PM_SLEEP
  97. static int ahci_pci_device_suspend(struct device *dev);
  98. static int ahci_pci_device_resume(struct device *dev);
  99. #endif
  100. #endif /* CONFIG_PM */
  101. static struct scsi_host_template ahci_sht = {
  102. AHCI_SHT("ahci"),
  103. };
  104. static struct ata_port_operations ahci_vt8251_ops = {
  105. .inherits = &ahci_ops,
  106. .hardreset = ahci_vt8251_hardreset,
  107. };
  108. static struct ata_port_operations ahci_p5wdh_ops = {
  109. .inherits = &ahci_ops,
  110. .hardreset = ahci_p5wdh_hardreset,
  111. };
  112. static struct ata_port_operations ahci_avn_ops = {
  113. .inherits = &ahci_ops,
  114. .hardreset = ahci_avn_hardreset,
  115. };
  116. static const struct ata_port_info ahci_port_info[] = {
  117. /* by features */
  118. [board_ahci] = {
  119. .flags = AHCI_FLAG_COMMON,
  120. .pio_mask = ATA_PIO4,
  121. .udma_mask = ATA_UDMA6,
  122. .port_ops = &ahci_ops,
  123. },
  124. [board_ahci_ign_iferr] = {
  125. AHCI_HFLAGS (AHCI_HFLAG_IGN_IRQ_IF_ERR),
  126. .flags = AHCI_FLAG_COMMON,
  127. .pio_mask = ATA_PIO4,
  128. .udma_mask = ATA_UDMA6,
  129. .port_ops = &ahci_ops,
  130. },
  131. [board_ahci_nomsi] = {
  132. AHCI_HFLAGS (AHCI_HFLAG_NO_MSI),
  133. .flags = AHCI_FLAG_COMMON,
  134. .pio_mask = ATA_PIO4,
  135. .udma_mask = ATA_UDMA6,
  136. .port_ops = &ahci_ops,
  137. },
  138. [board_ahci_noncq] = {
  139. AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ),
  140. .flags = AHCI_FLAG_COMMON,
  141. .pio_mask = ATA_PIO4,
  142. .udma_mask = ATA_UDMA6,
  143. .port_ops = &ahci_ops,
  144. },
  145. [board_ahci_nosntf] = {
  146. AHCI_HFLAGS (AHCI_HFLAG_NO_SNTF),
  147. .flags = AHCI_FLAG_COMMON,
  148. .pio_mask = ATA_PIO4,
  149. .udma_mask = ATA_UDMA6,
  150. .port_ops = &ahci_ops,
  151. },
  152. [board_ahci_yes_fbs] = {
  153. AHCI_HFLAGS (AHCI_HFLAG_YES_FBS),
  154. .flags = AHCI_FLAG_COMMON,
  155. .pio_mask = ATA_PIO4,
  156. .udma_mask = ATA_UDMA6,
  157. .port_ops = &ahci_ops,
  158. },
  159. /* by chipsets */
  160. [board_ahci_avn] = {
  161. .flags = AHCI_FLAG_COMMON,
  162. .pio_mask = ATA_PIO4,
  163. .udma_mask = ATA_UDMA6,
  164. .port_ops = &ahci_avn_ops,
  165. },
  166. [board_ahci_mcp65] = {
  167. AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA | AHCI_HFLAG_NO_PMP |
  168. AHCI_HFLAG_YES_NCQ),
  169. .flags = AHCI_FLAG_COMMON | ATA_FLAG_NO_DIPM,
  170. .pio_mask = ATA_PIO4,
  171. .udma_mask = ATA_UDMA6,
  172. .port_ops = &ahci_ops,
  173. },
  174. [board_ahci_mcp77] = {
  175. AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA | AHCI_HFLAG_NO_PMP),
  176. .flags = AHCI_FLAG_COMMON,
  177. .pio_mask = ATA_PIO4,
  178. .udma_mask = ATA_UDMA6,
  179. .port_ops = &ahci_ops,
  180. },
  181. [board_ahci_mcp89] = {
  182. AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA),
  183. .flags = AHCI_FLAG_COMMON,
  184. .pio_mask = ATA_PIO4,
  185. .udma_mask = ATA_UDMA6,
  186. .port_ops = &ahci_ops,
  187. },
  188. [board_ahci_mv] = {
  189. AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_MSI |
  190. AHCI_HFLAG_MV_PATA | AHCI_HFLAG_NO_PMP),
  191. .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA,
  192. .pio_mask = ATA_PIO4,
  193. .udma_mask = ATA_UDMA6,
  194. .port_ops = &ahci_ops,
  195. },
  196. [board_ahci_sb600] = {
  197. AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL |
  198. AHCI_HFLAG_NO_MSI | AHCI_HFLAG_SECT255 |
  199. AHCI_HFLAG_32BIT_ONLY),
  200. .flags = AHCI_FLAG_COMMON,
  201. .pio_mask = ATA_PIO4,
  202. .udma_mask = ATA_UDMA6,
  203. .port_ops = &ahci_pmp_retry_srst_ops,
  204. },
  205. [board_ahci_sb700] = { /* for SB700 and SB800 */
  206. AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL),
  207. .flags = AHCI_FLAG_COMMON,
  208. .pio_mask = ATA_PIO4,
  209. .udma_mask = ATA_UDMA6,
  210. .port_ops = &ahci_pmp_retry_srst_ops,
  211. },
  212. [board_ahci_vt8251] = {
  213. AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_PMP),
  214. .flags = AHCI_FLAG_COMMON,
  215. .pio_mask = ATA_PIO4,
  216. .udma_mask = ATA_UDMA6,
  217. .port_ops = &ahci_vt8251_ops,
  218. },
  219. };
  220. static const struct pci_device_id ahci_pci_tbl[] = {
  221. /* Intel */
  222. { PCI_VDEVICE(INTEL, 0x2652), board_ahci }, /* ICH6 */
  223. { PCI_VDEVICE(INTEL, 0x2653), board_ahci }, /* ICH6M */
  224. { PCI_VDEVICE(INTEL, 0x27c1), board_ahci }, /* ICH7 */
  225. { PCI_VDEVICE(INTEL, 0x27c5), board_ahci }, /* ICH7M */
  226. { PCI_VDEVICE(INTEL, 0x27c3), board_ahci }, /* ICH7R */
  227. { PCI_VDEVICE(AL, 0x5288), board_ahci_ign_iferr }, /* ULi M5288 */
  228. { PCI_VDEVICE(INTEL, 0x2681), board_ahci }, /* ESB2 */
  229. { PCI_VDEVICE(INTEL, 0x2682), board_ahci }, /* ESB2 */
  230. { PCI_VDEVICE(INTEL, 0x2683), board_ahci }, /* ESB2 */
  231. { PCI_VDEVICE(INTEL, 0x27c6), board_ahci }, /* ICH7-M DH */
  232. { PCI_VDEVICE(INTEL, 0x2821), board_ahci }, /* ICH8 */
  233. { PCI_VDEVICE(INTEL, 0x2822), board_ahci_nosntf }, /* ICH8 */
  234. { PCI_VDEVICE(INTEL, 0x2824), board_ahci }, /* ICH8 */
  235. { PCI_VDEVICE(INTEL, 0x2829), board_ahci }, /* ICH8M */
  236. { PCI_VDEVICE(INTEL, 0x282a), board_ahci }, /* ICH8M */
  237. { PCI_VDEVICE(INTEL, 0x2922), board_ahci }, /* ICH9 */
  238. { PCI_VDEVICE(INTEL, 0x2923), board_ahci }, /* ICH9 */
  239. { PCI_VDEVICE(INTEL, 0x2924), board_ahci }, /* ICH9 */
  240. { PCI_VDEVICE(INTEL, 0x2925), board_ahci }, /* ICH9 */
  241. { PCI_VDEVICE(INTEL, 0x2927), board_ahci }, /* ICH9 */
  242. { PCI_VDEVICE(INTEL, 0x2929), board_ahci }, /* ICH9M */
  243. { PCI_VDEVICE(INTEL, 0x292a), board_ahci }, /* ICH9M */
  244. { PCI_VDEVICE(INTEL, 0x292b), board_ahci }, /* ICH9M */
  245. { PCI_VDEVICE(INTEL, 0x292c), board_ahci }, /* ICH9M */
  246. { PCI_VDEVICE(INTEL, 0x292f), board_ahci }, /* ICH9M */
  247. { PCI_VDEVICE(INTEL, 0x294d), board_ahci }, /* ICH9 */
  248. { PCI_VDEVICE(INTEL, 0x294e), board_ahci }, /* ICH9M */
  249. { PCI_VDEVICE(INTEL, 0x502a), board_ahci }, /* Tolapai */
  250. { PCI_VDEVICE(INTEL, 0x502b), board_ahci }, /* Tolapai */
  251. { PCI_VDEVICE(INTEL, 0x3a05), board_ahci }, /* ICH10 */
  252. { PCI_VDEVICE(INTEL, 0x3a22), board_ahci }, /* ICH10 */
  253. { PCI_VDEVICE(INTEL, 0x3a25), board_ahci }, /* ICH10 */
  254. { PCI_VDEVICE(INTEL, 0x3b22), board_ahci }, /* PCH AHCI */
  255. { PCI_VDEVICE(INTEL, 0x3b23), board_ahci }, /* PCH AHCI */
  256. { PCI_VDEVICE(INTEL, 0x3b24), board_ahci }, /* PCH RAID */
  257. { PCI_VDEVICE(INTEL, 0x3b25), board_ahci }, /* PCH RAID */
  258. { PCI_VDEVICE(INTEL, 0x3b29), board_ahci }, /* PCH M AHCI */
  259. { PCI_VDEVICE(INTEL, 0x3b2b), board_ahci }, /* PCH RAID */
  260. { PCI_VDEVICE(INTEL, 0x3b2c), board_ahci }, /* PCH M RAID */
  261. { PCI_VDEVICE(INTEL, 0x3b2f), board_ahci }, /* PCH AHCI */
  262. { PCI_VDEVICE(INTEL, 0x19b0), board_ahci }, /* DNV AHCI */
  263. { PCI_VDEVICE(INTEL, 0x19b1), board_ahci }, /* DNV AHCI */
  264. { PCI_VDEVICE(INTEL, 0x19b2), board_ahci }, /* DNV AHCI */
  265. { PCI_VDEVICE(INTEL, 0x19b3), board_ahci }, /* DNV AHCI */
  266. { PCI_VDEVICE(INTEL, 0x19b4), board_ahci }, /* DNV AHCI */
  267. { PCI_VDEVICE(INTEL, 0x19b5), board_ahci }, /* DNV AHCI */
  268. { PCI_VDEVICE(INTEL, 0x19b6), board_ahci }, /* DNV AHCI */
  269. { PCI_VDEVICE(INTEL, 0x19b7), board_ahci }, /* DNV AHCI */
  270. { PCI_VDEVICE(INTEL, 0x19bE), board_ahci }, /* DNV AHCI */
  271. { PCI_VDEVICE(INTEL, 0x19bF), board_ahci }, /* DNV AHCI */
  272. { PCI_VDEVICE(INTEL, 0x19c0), board_ahci }, /* DNV AHCI */
  273. { PCI_VDEVICE(INTEL, 0x19c1), board_ahci }, /* DNV AHCI */
  274. { PCI_VDEVICE(INTEL, 0x19c2), board_ahci }, /* DNV AHCI */
  275. { PCI_VDEVICE(INTEL, 0x19c3), board_ahci }, /* DNV AHCI */
  276. { PCI_VDEVICE(INTEL, 0x19c4), board_ahci }, /* DNV AHCI */
  277. { PCI_VDEVICE(INTEL, 0x19c5), board_ahci }, /* DNV AHCI */
  278. { PCI_VDEVICE(INTEL, 0x19c6), board_ahci }, /* DNV AHCI */
  279. { PCI_VDEVICE(INTEL, 0x19c7), board_ahci }, /* DNV AHCI */
  280. { PCI_VDEVICE(INTEL, 0x19cE), board_ahci }, /* DNV AHCI */
  281. { PCI_VDEVICE(INTEL, 0x19cF), board_ahci }, /* DNV AHCI */
  282. { PCI_VDEVICE(INTEL, 0x1c02), board_ahci }, /* CPT AHCI */
  283. { PCI_VDEVICE(INTEL, 0x1c03), board_ahci }, /* CPT M AHCI */
  284. { PCI_VDEVICE(INTEL, 0x1c04), board_ahci }, /* CPT RAID */
  285. { PCI_VDEVICE(INTEL, 0x1c05), board_ahci }, /* CPT M RAID */
  286. { PCI_VDEVICE(INTEL, 0x1c06), board_ahci }, /* CPT RAID */
  287. { PCI_VDEVICE(INTEL, 0x1c07), board_ahci }, /* CPT RAID */
  288. { PCI_VDEVICE(INTEL, 0x1d02), board_ahci }, /* PBG AHCI */
  289. { PCI_VDEVICE(INTEL, 0x1d04), board_ahci }, /* PBG RAID */
  290. { PCI_VDEVICE(INTEL, 0x1d06), board_ahci }, /* PBG RAID */
  291. { PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* PBG RAID */
  292. { PCI_VDEVICE(INTEL, 0x2323), board_ahci }, /* DH89xxCC AHCI */
  293. { PCI_VDEVICE(INTEL, 0x1e02), board_ahci }, /* Panther Point AHCI */
  294. { PCI_VDEVICE(INTEL, 0x1e03), board_ahci }, /* Panther Point M AHCI */
  295. { PCI_VDEVICE(INTEL, 0x1e04), board_ahci }, /* Panther Point RAID */
  296. { PCI_VDEVICE(INTEL, 0x1e05), board_ahci }, /* Panther Point RAID */
  297. { PCI_VDEVICE(INTEL, 0x1e06), board_ahci }, /* Panther Point RAID */
  298. { PCI_VDEVICE(INTEL, 0x1e07), board_ahci }, /* Panther Point M RAID */
  299. { PCI_VDEVICE(INTEL, 0x1e0e), board_ahci }, /* Panther Point RAID */
  300. { PCI_VDEVICE(INTEL, 0x8c02), board_ahci }, /* Lynx Point AHCI */
  301. { PCI_VDEVICE(INTEL, 0x8c03), board_ahci }, /* Lynx Point M AHCI */
  302. { PCI_VDEVICE(INTEL, 0x8c04), board_ahci }, /* Lynx Point RAID */
  303. { PCI_VDEVICE(INTEL, 0x8c05), board_ahci }, /* Lynx Point M RAID */
  304. { PCI_VDEVICE(INTEL, 0x8c06), board_ahci }, /* Lynx Point RAID */
  305. { PCI_VDEVICE(INTEL, 0x8c07), board_ahci }, /* Lynx Point M RAID */
  306. { PCI_VDEVICE(INTEL, 0x8c0e), board_ahci }, /* Lynx Point RAID */
  307. { PCI_VDEVICE(INTEL, 0x8c0f), board_ahci }, /* Lynx Point M RAID */
  308. { PCI_VDEVICE(INTEL, 0x9c02), board_ahci }, /* Lynx Point-LP AHCI */
  309. { PCI_VDEVICE(INTEL, 0x9c03), board_ahci }, /* Lynx Point-LP AHCI */
  310. { PCI_VDEVICE(INTEL, 0x9c04), board_ahci }, /* Lynx Point-LP RAID */
  311. { PCI_VDEVICE(INTEL, 0x9c05), board_ahci }, /* Lynx Point-LP RAID */
  312. { PCI_VDEVICE(INTEL, 0x9c06), board_ahci }, /* Lynx Point-LP RAID */
  313. { PCI_VDEVICE(INTEL, 0x9c07), board_ahci }, /* Lynx Point-LP RAID */
  314. { PCI_VDEVICE(INTEL, 0x9c0e), board_ahci }, /* Lynx Point-LP RAID */
  315. { PCI_VDEVICE(INTEL, 0x9c0f), board_ahci }, /* Lynx Point-LP RAID */
  316. { PCI_VDEVICE(INTEL, 0x1f22), board_ahci }, /* Avoton AHCI */
  317. { PCI_VDEVICE(INTEL, 0x1f23), board_ahci }, /* Avoton AHCI */
  318. { PCI_VDEVICE(INTEL, 0x1f24), board_ahci }, /* Avoton RAID */
  319. { PCI_VDEVICE(INTEL, 0x1f25), board_ahci }, /* Avoton RAID */
  320. { PCI_VDEVICE(INTEL, 0x1f26), board_ahci }, /* Avoton RAID */
  321. { PCI_VDEVICE(INTEL, 0x1f27), board_ahci }, /* Avoton RAID */
  322. { PCI_VDEVICE(INTEL, 0x1f2e), board_ahci }, /* Avoton RAID */
  323. { PCI_VDEVICE(INTEL, 0x1f2f), board_ahci }, /* Avoton RAID */
  324. { PCI_VDEVICE(INTEL, 0x1f32), board_ahci_avn }, /* Avoton AHCI */
  325. { PCI_VDEVICE(INTEL, 0x1f33), board_ahci_avn }, /* Avoton AHCI */
  326. { PCI_VDEVICE(INTEL, 0x1f34), board_ahci_avn }, /* Avoton RAID */
  327. { PCI_VDEVICE(INTEL, 0x1f35), board_ahci_avn }, /* Avoton RAID */
  328. { PCI_VDEVICE(INTEL, 0x1f36), board_ahci_avn }, /* Avoton RAID */
  329. { PCI_VDEVICE(INTEL, 0x1f37), board_ahci_avn }, /* Avoton RAID */
  330. { PCI_VDEVICE(INTEL, 0x1f3e), board_ahci_avn }, /* Avoton RAID */
  331. { PCI_VDEVICE(INTEL, 0x1f3f), board_ahci_avn }, /* Avoton RAID */
  332. { PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Wellsburg RAID */
  333. { PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Wellsburg RAID */
  334. { PCI_VDEVICE(INTEL, 0x8d02), board_ahci }, /* Wellsburg AHCI */
  335. { PCI_VDEVICE(INTEL, 0x8d04), board_ahci }, /* Wellsburg RAID */
  336. { PCI_VDEVICE(INTEL, 0x8d06), board_ahci }, /* Wellsburg RAID */
  337. { PCI_VDEVICE(INTEL, 0x8d0e), board_ahci }, /* Wellsburg RAID */
  338. { PCI_VDEVICE(INTEL, 0x8d62), board_ahci }, /* Wellsburg AHCI */
  339. { PCI_VDEVICE(INTEL, 0x8d64), board_ahci }, /* Wellsburg RAID */
  340. { PCI_VDEVICE(INTEL, 0x8d66), board_ahci }, /* Wellsburg RAID */
  341. { PCI_VDEVICE(INTEL, 0x8d6e), board_ahci }, /* Wellsburg RAID */
  342. { PCI_VDEVICE(INTEL, 0x23a3), board_ahci }, /* Coleto Creek AHCI */
  343. { PCI_VDEVICE(INTEL, 0x9c83), board_ahci }, /* Wildcat Point-LP AHCI */
  344. { PCI_VDEVICE(INTEL, 0x9c85), board_ahci }, /* Wildcat Point-LP RAID */
  345. { PCI_VDEVICE(INTEL, 0x9c87), board_ahci }, /* Wildcat Point-LP RAID */
  346. { PCI_VDEVICE(INTEL, 0x9c8f), board_ahci }, /* Wildcat Point-LP RAID */
  347. { PCI_VDEVICE(INTEL, 0x8c82), board_ahci }, /* 9 Series AHCI */
  348. { PCI_VDEVICE(INTEL, 0x8c83), board_ahci }, /* 9 Series M AHCI */
  349. { PCI_VDEVICE(INTEL, 0x8c84), board_ahci }, /* 9 Series RAID */
  350. { PCI_VDEVICE(INTEL, 0x8c85), board_ahci }, /* 9 Series M RAID */
  351. { PCI_VDEVICE(INTEL, 0x8c86), board_ahci }, /* 9 Series RAID */
  352. { PCI_VDEVICE(INTEL, 0x8c87), board_ahci }, /* 9 Series M RAID */
  353. { PCI_VDEVICE(INTEL, 0x8c8e), board_ahci }, /* 9 Series RAID */
  354. { PCI_VDEVICE(INTEL, 0x8c8f), board_ahci }, /* 9 Series M RAID */
  355. { PCI_VDEVICE(INTEL, 0x9d03), board_ahci }, /* Sunrise Point-LP AHCI */
  356. { PCI_VDEVICE(INTEL, 0x9d05), board_ahci }, /* Sunrise Point-LP RAID */
  357. { PCI_VDEVICE(INTEL, 0x9d07), board_ahci }, /* Sunrise Point-LP RAID */
  358. { PCI_VDEVICE(INTEL, 0xa102), board_ahci }, /* Sunrise Point-H AHCI */
  359. { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H M AHCI */
  360. { PCI_VDEVICE(INTEL, 0xa105), board_ahci }, /* Sunrise Point-H RAID */
  361. { PCI_VDEVICE(INTEL, 0xa106), board_ahci }, /* Sunrise Point-H RAID */
  362. { PCI_VDEVICE(INTEL, 0xa107), board_ahci }, /* Sunrise Point-H M RAID */
  363. { PCI_VDEVICE(INTEL, 0xa10f), board_ahci }, /* Sunrise Point-H RAID */
  364. { PCI_VDEVICE(INTEL, 0x2822), board_ahci }, /* Lewisburg RAID*/
  365. { PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Lewisburg AHCI*/
  366. { PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* Lewisburg RAID*/
  367. { PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Lewisburg RAID*/
  368. { PCI_VDEVICE(INTEL, 0xa182), board_ahci }, /* Lewisburg AHCI*/
  369. { PCI_VDEVICE(INTEL, 0xa186), board_ahci }, /* Lewisburg RAID*/
  370. { PCI_VDEVICE(INTEL, 0xa1d2), board_ahci }, /* Lewisburg RAID*/
  371. { PCI_VDEVICE(INTEL, 0xa1d6), board_ahci }, /* Lewisburg RAID*/
  372. { PCI_VDEVICE(INTEL, 0xa202), board_ahci }, /* Lewisburg AHCI*/
  373. { PCI_VDEVICE(INTEL, 0xa206), board_ahci }, /* Lewisburg RAID*/
  374. { PCI_VDEVICE(INTEL, 0xa252), board_ahci }, /* Lewisburg RAID*/
  375. { PCI_VDEVICE(INTEL, 0xa256), board_ahci }, /* Lewisburg RAID*/
  376. { PCI_VDEVICE(INTEL, 0xa356), board_ahci }, /* Cannon Lake PCH-H RAID */
  377. { PCI_VDEVICE(INTEL, 0x0f22), board_ahci }, /* Bay Trail AHCI */
  378. { PCI_VDEVICE(INTEL, 0x0f23), board_ahci }, /* Bay Trail AHCI */
  379. { PCI_VDEVICE(INTEL, 0x22a3), board_ahci }, /* Cherry Trail AHCI */
  380. { PCI_VDEVICE(INTEL, 0x5ae3), board_ahci }, /* Apollo Lake AHCI */
  381. /* JMicron 360/1/3/5/6, match class to avoid IDE function */
  382. { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  383. PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci_ign_iferr },
  384. /* JMicron 362B and 362C have an AHCI function with IDE class code */
  385. { PCI_VDEVICE(JMICRON, 0x2362), board_ahci_ign_iferr },
  386. { PCI_VDEVICE(JMICRON, 0x236f), board_ahci_ign_iferr },
  387. /* May need to update quirk_jmicron_async_suspend() for additions */
  388. /* ATI */
  389. { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */
  390. { PCI_VDEVICE(ATI, 0x4390), board_ahci_sb700 }, /* ATI SB700/800 */
  391. { PCI_VDEVICE(ATI, 0x4391), board_ahci_sb700 }, /* ATI SB700/800 */
  392. { PCI_VDEVICE(ATI, 0x4392), board_ahci_sb700 }, /* ATI SB700/800 */
  393. { PCI_VDEVICE(ATI, 0x4393), board_ahci_sb700 }, /* ATI SB700/800 */
  394. { PCI_VDEVICE(ATI, 0x4394), board_ahci_sb700 }, /* ATI SB700/800 */
  395. { PCI_VDEVICE(ATI, 0x4395), board_ahci_sb700 }, /* ATI SB700/800 */
  396. /* AMD */
  397. { PCI_VDEVICE(AMD, 0x7800), board_ahci }, /* AMD Hudson-2 */
  398. { PCI_VDEVICE(AMD, 0x7900), board_ahci }, /* AMD CZ */
  399. /* AMD is using RAID class only for ahci controllers */
  400. { PCI_VENDOR_ID_AMD, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  401. PCI_CLASS_STORAGE_RAID << 8, 0xffffff, board_ahci },
  402. /* VIA */
  403. { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */
  404. { PCI_VDEVICE(VIA, 0x6287), board_ahci_vt8251 }, /* VIA VT8251 */
  405. /* NVIDIA */
  406. { PCI_VDEVICE(NVIDIA, 0x044c), board_ahci_mcp65 }, /* MCP65 */
  407. { PCI_VDEVICE(NVIDIA, 0x044d), board_ahci_mcp65 }, /* MCP65 */
  408. { PCI_VDEVICE(NVIDIA, 0x044e), board_ahci_mcp65 }, /* MCP65 */
  409. { PCI_VDEVICE(NVIDIA, 0x044f), board_ahci_mcp65 }, /* MCP65 */
  410. { PCI_VDEVICE(NVIDIA, 0x045c), board_ahci_mcp65 }, /* MCP65 */
  411. { PCI_VDEVICE(NVIDIA, 0x045d), board_ahci_mcp65 }, /* MCP65 */
  412. { PCI_VDEVICE(NVIDIA, 0x045e), board_ahci_mcp65 }, /* MCP65 */
  413. { PCI_VDEVICE(NVIDIA, 0x045f), board_ahci_mcp65 }, /* MCP65 */
  414. { PCI_VDEVICE(NVIDIA, 0x0550), board_ahci_mcp67 }, /* MCP67 */
  415. { PCI_VDEVICE(NVIDIA, 0x0551), board_ahci_mcp67 }, /* MCP67 */
  416. { PCI_VDEVICE(NVIDIA, 0x0552), board_ahci_mcp67 }, /* MCP67 */
  417. { PCI_VDEVICE(NVIDIA, 0x0553), board_ahci_mcp67 }, /* MCP67 */
  418. { PCI_VDEVICE(NVIDIA, 0x0554), board_ahci_mcp67 }, /* MCP67 */
  419. { PCI_VDEVICE(NVIDIA, 0x0555), board_ahci_mcp67 }, /* MCP67 */
  420. { PCI_VDEVICE(NVIDIA, 0x0556), board_ahci_mcp67 }, /* MCP67 */
  421. { PCI_VDEVICE(NVIDIA, 0x0557), board_ahci_mcp67 }, /* MCP67 */
  422. { PCI_VDEVICE(NVIDIA, 0x0558), board_ahci_mcp67 }, /* MCP67 */
  423. { PCI_VDEVICE(NVIDIA, 0x0559), board_ahci_mcp67 }, /* MCP67 */
  424. { PCI_VDEVICE(NVIDIA, 0x055a), board_ahci_mcp67 }, /* MCP67 */
  425. { PCI_VDEVICE(NVIDIA, 0x055b), board_ahci_mcp67 }, /* MCP67 */
  426. { PCI_VDEVICE(NVIDIA, 0x0580), board_ahci_mcp_linux }, /* Linux ID */
  427. { PCI_VDEVICE(NVIDIA, 0x0581), board_ahci_mcp_linux }, /* Linux ID */
  428. { PCI_VDEVICE(NVIDIA, 0x0582), board_ahci_mcp_linux }, /* Linux ID */
  429. { PCI_VDEVICE(NVIDIA, 0x0583), board_ahci_mcp_linux }, /* Linux ID */
  430. { PCI_VDEVICE(NVIDIA, 0x0584), board_ahci_mcp_linux }, /* Linux ID */
  431. { PCI_VDEVICE(NVIDIA, 0x0585), board_ahci_mcp_linux }, /* Linux ID */
  432. { PCI_VDEVICE(NVIDIA, 0x0586), board_ahci_mcp_linux }, /* Linux ID */
  433. { PCI_VDEVICE(NVIDIA, 0x0587), board_ahci_mcp_linux }, /* Linux ID */
  434. { PCI_VDEVICE(NVIDIA, 0x0588), board_ahci_mcp_linux }, /* Linux ID */
  435. { PCI_VDEVICE(NVIDIA, 0x0589), board_ahci_mcp_linux }, /* Linux ID */
  436. { PCI_VDEVICE(NVIDIA, 0x058a), board_ahci_mcp_linux }, /* Linux ID */
  437. { PCI_VDEVICE(NVIDIA, 0x058b), board_ahci_mcp_linux }, /* Linux ID */
  438. { PCI_VDEVICE(NVIDIA, 0x058c), board_ahci_mcp_linux }, /* Linux ID */
  439. { PCI_VDEVICE(NVIDIA, 0x058d), board_ahci_mcp_linux }, /* Linux ID */
  440. { PCI_VDEVICE(NVIDIA, 0x058e), board_ahci_mcp_linux }, /* Linux ID */
  441. { PCI_VDEVICE(NVIDIA, 0x058f), board_ahci_mcp_linux }, /* Linux ID */
  442. { PCI_VDEVICE(NVIDIA, 0x07f0), board_ahci_mcp73 }, /* MCP73 */
  443. { PCI_VDEVICE(NVIDIA, 0x07f1), board_ahci_mcp73 }, /* MCP73 */
  444. { PCI_VDEVICE(NVIDIA, 0x07f2), board_ahci_mcp73 }, /* MCP73 */
  445. { PCI_VDEVICE(NVIDIA, 0x07f3), board_ahci_mcp73 }, /* MCP73 */
  446. { PCI_VDEVICE(NVIDIA, 0x07f4), board_ahci_mcp73 }, /* MCP73 */
  447. { PCI_VDEVICE(NVIDIA, 0x07f5), board_ahci_mcp73 }, /* MCP73 */
  448. { PCI_VDEVICE(NVIDIA, 0x07f6), board_ahci_mcp73 }, /* MCP73 */
  449. { PCI_VDEVICE(NVIDIA, 0x07f7), board_ahci_mcp73 }, /* MCP73 */
  450. { PCI_VDEVICE(NVIDIA, 0x07f8), board_ahci_mcp73 }, /* MCP73 */
  451. { PCI_VDEVICE(NVIDIA, 0x07f9), board_ahci_mcp73 }, /* MCP73 */
  452. { PCI_VDEVICE(NVIDIA, 0x07fa), board_ahci_mcp73 }, /* MCP73 */
  453. { PCI_VDEVICE(NVIDIA, 0x07fb), board_ahci_mcp73 }, /* MCP73 */
  454. { PCI_VDEVICE(NVIDIA, 0x0ad0), board_ahci_mcp77 }, /* MCP77 */
  455. { PCI_VDEVICE(NVIDIA, 0x0ad1), board_ahci_mcp77 }, /* MCP77 */
  456. { PCI_VDEVICE(NVIDIA, 0x0ad2), board_ahci_mcp77 }, /* MCP77 */
  457. { PCI_VDEVICE(NVIDIA, 0x0ad3), board_ahci_mcp77 }, /* MCP77 */
  458. { PCI_VDEVICE(NVIDIA, 0x0ad4), board_ahci_mcp77 }, /* MCP77 */
  459. { PCI_VDEVICE(NVIDIA, 0x0ad5), board_ahci_mcp77 }, /* MCP77 */
  460. { PCI_VDEVICE(NVIDIA, 0x0ad6), board_ahci_mcp77 }, /* MCP77 */
  461. { PCI_VDEVICE(NVIDIA, 0x0ad7), board_ahci_mcp77 }, /* MCP77 */
  462. { PCI_VDEVICE(NVIDIA, 0x0ad8), board_ahci_mcp77 }, /* MCP77 */
  463. { PCI_VDEVICE(NVIDIA, 0x0ad9), board_ahci_mcp77 }, /* MCP77 */
  464. { PCI_VDEVICE(NVIDIA, 0x0ada), board_ahci_mcp77 }, /* MCP77 */
  465. { PCI_VDEVICE(NVIDIA, 0x0adb), board_ahci_mcp77 }, /* MCP77 */
  466. { PCI_VDEVICE(NVIDIA, 0x0ab4), board_ahci_mcp79 }, /* MCP79 */
  467. { PCI_VDEVICE(NVIDIA, 0x0ab5), board_ahci_mcp79 }, /* MCP79 */
  468. { PCI_VDEVICE(NVIDIA, 0x0ab6), board_ahci_mcp79 }, /* MCP79 */
  469. { PCI_VDEVICE(NVIDIA, 0x0ab7), board_ahci_mcp79 }, /* MCP79 */
  470. { PCI_VDEVICE(NVIDIA, 0x0ab8), board_ahci_mcp79 }, /* MCP79 */
  471. { PCI_VDEVICE(NVIDIA, 0x0ab9), board_ahci_mcp79 }, /* MCP79 */
  472. { PCI_VDEVICE(NVIDIA, 0x0aba), board_ahci_mcp79 }, /* MCP79 */
  473. { PCI_VDEVICE(NVIDIA, 0x0abb), board_ahci_mcp79 }, /* MCP79 */
  474. { PCI_VDEVICE(NVIDIA, 0x0abc), board_ahci_mcp79 }, /* MCP79 */
  475. { PCI_VDEVICE(NVIDIA, 0x0abd), board_ahci_mcp79 }, /* MCP79 */
  476. { PCI_VDEVICE(NVIDIA, 0x0abe), board_ahci_mcp79 }, /* MCP79 */
  477. { PCI_VDEVICE(NVIDIA, 0x0abf), board_ahci_mcp79 }, /* MCP79 */
  478. { PCI_VDEVICE(NVIDIA, 0x0d84), board_ahci_mcp89 }, /* MCP89 */
  479. { PCI_VDEVICE(NVIDIA, 0x0d85), board_ahci_mcp89 }, /* MCP89 */
  480. { PCI_VDEVICE(NVIDIA, 0x0d86), board_ahci_mcp89 }, /* MCP89 */
  481. { PCI_VDEVICE(NVIDIA, 0x0d87), board_ahci_mcp89 }, /* MCP89 */
  482. { PCI_VDEVICE(NVIDIA, 0x0d88), board_ahci_mcp89 }, /* MCP89 */
  483. { PCI_VDEVICE(NVIDIA, 0x0d89), board_ahci_mcp89 }, /* MCP89 */
  484. { PCI_VDEVICE(NVIDIA, 0x0d8a), board_ahci_mcp89 }, /* MCP89 */
  485. { PCI_VDEVICE(NVIDIA, 0x0d8b), board_ahci_mcp89 }, /* MCP89 */
  486. { PCI_VDEVICE(NVIDIA, 0x0d8c), board_ahci_mcp89 }, /* MCP89 */
  487. { PCI_VDEVICE(NVIDIA, 0x0d8d), board_ahci_mcp89 }, /* MCP89 */
  488. { PCI_VDEVICE(NVIDIA, 0x0d8e), board_ahci_mcp89 }, /* MCP89 */
  489. { PCI_VDEVICE(NVIDIA, 0x0d8f), board_ahci_mcp89 }, /* MCP89 */
  490. /* SiS */
  491. { PCI_VDEVICE(SI, 0x1184), board_ahci }, /* SiS 966 */
  492. { PCI_VDEVICE(SI, 0x1185), board_ahci }, /* SiS 968 */
  493. { PCI_VDEVICE(SI, 0x0186), board_ahci }, /* SiS 968 */
  494. /* ST Microelectronics */
  495. { PCI_VDEVICE(STMICRO, 0xCC06), board_ahci }, /* ST ConneXt */
  496. /* Marvell */
  497. { PCI_VDEVICE(MARVELL, 0x6145), board_ahci_mv }, /* 6145 */
  498. { PCI_VDEVICE(MARVELL, 0x6121), board_ahci_mv }, /* 6121 */
  499. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9123),
  500. .class = PCI_CLASS_STORAGE_SATA_AHCI,
  501. .class_mask = 0xffffff,
  502. .driver_data = board_ahci_yes_fbs }, /* 88se9128 */
  503. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9125),
  504. .driver_data = board_ahci_yes_fbs }, /* 88se9125 */
  505. { PCI_DEVICE_SUB(PCI_VENDOR_ID_MARVELL_EXT, 0x9178,
  506. PCI_VENDOR_ID_MARVELL_EXT, 0x9170),
  507. .driver_data = board_ahci_yes_fbs }, /* 88se9170 */
  508. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x917a),
  509. .driver_data = board_ahci_yes_fbs }, /* 88se9172 */
  510. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9172),
  511. .driver_data = board_ahci_yes_fbs }, /* 88se9182 */
  512. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9182),
  513. .driver_data = board_ahci_yes_fbs }, /* 88se9172 */
  514. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9192),
  515. .driver_data = board_ahci_yes_fbs }, /* 88se9172 on some Gigabyte */
  516. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x91a0),
  517. .driver_data = board_ahci_yes_fbs },
  518. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x91a2), /* 88se91a2 */
  519. .driver_data = board_ahci_yes_fbs },
  520. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x91a3),
  521. .driver_data = board_ahci_yes_fbs },
  522. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 0x9230),
  523. .driver_data = board_ahci_yes_fbs },
  524. { PCI_DEVICE(PCI_VENDOR_ID_TTI, 0x0642), /* highpoint rocketraid 642L */
  525. .driver_data = board_ahci_yes_fbs },
  526. { PCI_DEVICE(PCI_VENDOR_ID_TTI, 0x0645), /* highpoint rocketraid 644L */
  527. .driver_data = board_ahci_yes_fbs },
  528. /* Promise */
  529. { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci }, /* PDC42819 */
  530. { PCI_VDEVICE(PROMISE, 0x3781), board_ahci }, /* FastTrak TX8660 ahci-mode */
  531. /* Asmedia */
  532. { PCI_VDEVICE(ASMEDIA, 0x0601), board_ahci }, /* ASM1060 */
  533. { PCI_VDEVICE(ASMEDIA, 0x0602), board_ahci }, /* ASM1060 */
  534. { PCI_VDEVICE(ASMEDIA, 0x0611), board_ahci }, /* ASM1061 */
  535. { PCI_VDEVICE(ASMEDIA, 0x0612), board_ahci }, /* ASM1062 */
  536. { PCI_VDEVICE(ASMEDIA, 0x0621), board_ahci }, /* ASM1061R */
  537. { PCI_VDEVICE(ASMEDIA, 0x0622), board_ahci }, /* ASM1062R */
  538. /*
  539. * Samsung SSDs found on some macbooks. NCQ times out if MSI is
  540. * enabled. https://bugzilla.kernel.org/show_bug.cgi?id=60731
  541. */
  542. { PCI_VDEVICE(SAMSUNG, 0x1600), board_ahci_nomsi },
  543. { PCI_VDEVICE(SAMSUNG, 0xa800), board_ahci_nomsi },
  544. /* Enmotus */
  545. { PCI_DEVICE(0x1c44, 0x8000), board_ahci },
  546. /* Generic, PCI class code for AHCI */
  547. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  548. PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
  549. { } /* terminate list */
  550. };
  551. static const struct dev_pm_ops ahci_pci_pm_ops = {
  552. SET_SYSTEM_SLEEP_PM_OPS(ahci_pci_device_suspend, ahci_pci_device_resume)
  553. SET_RUNTIME_PM_OPS(ahci_pci_device_runtime_suspend,
  554. ahci_pci_device_runtime_resume, NULL)
  555. };
  556. static struct pci_driver ahci_pci_driver = {
  557. .name = DRV_NAME,
  558. .id_table = ahci_pci_tbl,
  559. .probe = ahci_init_one,
  560. .remove = ahci_remove_one,
  561. .shutdown = ahci_shutdown_one,
  562. .driver = {
  563. .pm = &ahci_pci_pm_ops,
  564. },
  565. };
  566. #if IS_ENABLED(CONFIG_PATA_MARVELL)
  567. static int marvell_enable;
  568. #else
  569. static int marvell_enable = 1;
  570. #endif
  571. module_param(marvell_enable, int, 0644);
  572. MODULE_PARM_DESC(marvell_enable, "Marvell SATA via AHCI (1 = enabled)");
  573. static void ahci_pci_save_initial_config(struct pci_dev *pdev,
  574. struct ahci_host_priv *hpriv)
  575. {
  576. if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) {
  577. dev_info(&pdev->dev, "JMB361 has only one port\n");
  578. hpriv->force_port_map = 1;
  579. }
  580. /*
  581. * Temporary Marvell 6145 hack: PATA port presence
  582. * is asserted through the standard AHCI port
  583. * presence register, as bit 4 (counting from 0)
  584. */
  585. if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
  586. if (pdev->device == 0x6121)
  587. hpriv->mask_port_map = 0x3;
  588. else
  589. hpriv->mask_port_map = 0xf;
  590. dev_info(&pdev->dev,
  591. "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
  592. }
  593. ahci_save_initial_config(&pdev->dev, hpriv);
  594. }
  595. static int ahci_pci_reset_controller(struct ata_host *host)
  596. {
  597. struct pci_dev *pdev = to_pci_dev(host->dev);
  598. int rc;
  599. rc = ahci_reset_controller(host);
  600. if (rc)
  601. return rc;
  602. if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
  603. struct ahci_host_priv *hpriv = host->private_data;
  604. u16 tmp16;
  605. /* configure PCS */
  606. pci_read_config_word(pdev, 0x92, &tmp16);
  607. if ((tmp16 & hpriv->port_map) != hpriv->port_map) {
  608. tmp16 |= hpriv->port_map;
  609. pci_write_config_word(pdev, 0x92, tmp16);
  610. }
  611. }
  612. return 0;
  613. }
  614. static void ahci_pci_init_controller(struct ata_host *host)
  615. {
  616. struct ahci_host_priv *hpriv = host->private_data;
  617. struct pci_dev *pdev = to_pci_dev(host->dev);
  618. void __iomem *port_mmio;
  619. u32 tmp;
  620. int mv;
  621. if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
  622. if (pdev->device == 0x6121)
  623. mv = 2;
  624. else
  625. mv = 4;
  626. port_mmio = __ahci_port_base(host, mv);
  627. writel(0, port_mmio + PORT_IRQ_MASK);
  628. /* clear port IRQ */
  629. tmp = readl(port_mmio + PORT_IRQ_STAT);
  630. VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp);
  631. if (tmp)
  632. writel(tmp, port_mmio + PORT_IRQ_STAT);
  633. }
  634. ahci_init_controller(host);
  635. }
  636. static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
  637. unsigned long deadline)
  638. {
  639. struct ata_port *ap = link->ap;
  640. struct ahci_host_priv *hpriv = ap->host->private_data;
  641. bool online;
  642. int rc;
  643. DPRINTK("ENTER\n");
  644. hpriv->stop_engine(ap);
  645. rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
  646. deadline, &online, NULL);
  647. hpriv->start_engine(ap);
  648. DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
  649. /* vt8251 doesn't clear BSY on signature FIS reception,
  650. * request follow-up softreset.
  651. */
  652. return online ? -EAGAIN : rc;
  653. }
  654. static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
  655. unsigned long deadline)
  656. {
  657. struct ata_port *ap = link->ap;
  658. struct ahci_port_priv *pp = ap->private_data;
  659. struct ahci_host_priv *hpriv = ap->host->private_data;
  660. u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
  661. struct ata_taskfile tf;
  662. bool online;
  663. int rc;
  664. hpriv->stop_engine(ap);
  665. /* clear D2H reception area to properly wait for D2H FIS */
  666. ata_tf_init(link->device, &tf);
  667. tf.command = ATA_BUSY;
  668. ata_tf_to_fis(&tf, 0, 0, d2h_fis);
  669. rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
  670. deadline, &online, NULL);
  671. hpriv->start_engine(ap);
  672. /* The pseudo configuration device on SIMG4726 attached to
  673. * ASUS P5W-DH Deluxe doesn't send signature FIS after
  674. * hardreset if no device is attached to the first downstream
  675. * port && the pseudo device locks up on SRST w/ PMP==0. To
  676. * work around this, wait for !BSY only briefly. If BSY isn't
  677. * cleared, perform CLO and proceed to IDENTIFY (achieved by
  678. * ATA_LFLAG_NO_SRST and ATA_LFLAG_ASSUME_ATA).
  679. *
  680. * Wait for two seconds. Devices attached to downstream port
  681. * which can't process the following IDENTIFY after this will
  682. * have to be reset again. For most cases, this should
  683. * suffice while making probing snappish enough.
  684. */
  685. if (online) {
  686. rc = ata_wait_after_reset(link, jiffies + 2 * HZ,
  687. ahci_check_ready);
  688. if (rc)
  689. ahci_kick_engine(ap);
  690. }
  691. return rc;
  692. }
  693. /*
  694. * ahci_avn_hardreset - attempt more aggressive recovery of Avoton ports.
  695. *
  696. * It has been observed with some SSDs that the timing of events in the
  697. * link synchronization phase can leave the port in a state that can not
  698. * be recovered by a SATA-hard-reset alone. The failing signature is
  699. * SStatus.DET stuck at 1 ("Device presence detected but Phy
  700. * communication not established"). It was found that unloading and
  701. * reloading the driver when this problem occurs allows the drive
  702. * connection to be recovered (DET advanced to 0x3). The critical
  703. * component of reloading the driver is that the port state machines are
  704. * reset by bouncing "port enable" in the AHCI PCS configuration
  705. * register. So, reproduce that effect by bouncing a port whenever we
  706. * see DET==1 after a reset.
  707. */
  708. static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
  709. unsigned long deadline)
  710. {
  711. const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
  712. struct ata_port *ap = link->ap;
  713. struct ahci_port_priv *pp = ap->private_data;
  714. struct ahci_host_priv *hpriv = ap->host->private_data;
  715. u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
  716. unsigned long tmo = deadline - jiffies;
  717. struct ata_taskfile tf;
  718. bool online;
  719. int rc, i;
  720. DPRINTK("ENTER\n");
  721. hpriv->stop_engine(ap);
  722. for (i = 0; i < 2; i++) {
  723. u16 val;
  724. u32 sstatus;
  725. int port = ap->port_no;
  726. struct ata_host *host = ap->host;
  727. struct pci_dev *pdev = to_pci_dev(host->dev);
  728. /* clear D2H reception area to properly wait for D2H FIS */
  729. ata_tf_init(link->device, &tf);
  730. tf.command = ATA_BUSY;
  731. ata_tf_to_fis(&tf, 0, 0, d2h_fis);
  732. rc = sata_link_hardreset(link, timing, deadline, &online,
  733. ahci_check_ready);
  734. if (sata_scr_read(link, SCR_STATUS, &sstatus) != 0 ||
  735. (sstatus & 0xf) != 1)
  736. break;
  737. ata_link_printk(link, KERN_INFO, "avn bounce port%d\n",
  738. port);
  739. pci_read_config_word(pdev, 0x92, &val);
  740. val &= ~(1 << port);
  741. pci_write_config_word(pdev, 0x92, val);
  742. ata_msleep(ap, 1000);
  743. val |= 1 << port;
  744. pci_write_config_word(pdev, 0x92, val);
  745. deadline += tmo;
  746. }
  747. hpriv->start_engine(ap);
  748. if (online)
  749. *class = ahci_dev_classify(ap);
  750. DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
  751. return rc;
  752. }
  753. #ifdef CONFIG_PM
  754. static void ahci_pci_disable_interrupts(struct ata_host *host)
  755. {
  756. struct ahci_host_priv *hpriv = host->private_data;
  757. void __iomem *mmio = hpriv->mmio;
  758. u32 ctl;
  759. /* AHCI spec rev1.1 section 8.3.3:
  760. * Software must disable interrupts prior to requesting a
  761. * transition of the HBA to D3 state.
  762. */
  763. ctl = readl(mmio + HOST_CTL);
  764. ctl &= ~HOST_IRQ_EN;
  765. writel(ctl, mmio + HOST_CTL);
  766. readl(mmio + HOST_CTL); /* flush */
  767. }
  768. static int ahci_pci_device_runtime_suspend(struct device *dev)
  769. {
  770. struct pci_dev *pdev = to_pci_dev(dev);
  771. struct ata_host *host = pci_get_drvdata(pdev);
  772. ahci_pci_disable_interrupts(host);
  773. return 0;
  774. }
  775. static int ahci_pci_device_runtime_resume(struct device *dev)
  776. {
  777. struct pci_dev *pdev = to_pci_dev(dev);
  778. struct ata_host *host = pci_get_drvdata(pdev);
  779. int rc;
  780. rc = ahci_pci_reset_controller(host);
  781. if (rc)
  782. return rc;
  783. ahci_pci_init_controller(host);
  784. return 0;
  785. }
  786. #ifdef CONFIG_PM_SLEEP
  787. static int ahci_pci_device_suspend(struct device *dev)
  788. {
  789. struct pci_dev *pdev = to_pci_dev(dev);
  790. struct ata_host *host = pci_get_drvdata(pdev);
  791. struct ahci_host_priv *hpriv = host->private_data;
  792. if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
  793. dev_err(&pdev->dev,
  794. "BIOS update required for suspend/resume\n");
  795. return -EIO;
  796. }
  797. ahci_pci_disable_interrupts(host);
  798. return ata_host_suspend(host, PMSG_SUSPEND);
  799. }
  800. static int ahci_pci_device_resume(struct device *dev)
  801. {
  802. struct pci_dev *pdev = to_pci_dev(dev);
  803. struct ata_host *host = pci_get_drvdata(pdev);
  804. int rc;
  805. /* Apple BIOS helpfully mangles the registers on resume */
  806. if (is_mcp89_apple(pdev))
  807. ahci_mcp89_apple_enable(pdev);
  808. if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
  809. rc = ahci_pci_reset_controller(host);
  810. if (rc)
  811. return rc;
  812. ahci_pci_init_controller(host);
  813. }
  814. ata_host_resume(host);
  815. return 0;
  816. }
  817. #endif
  818. #endif /* CONFIG_PM */
  819. static int ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac)
  820. {
  821. int rc;
  822. /*
  823. * If the device fixup already set the dma_mask to some non-standard
  824. * value, don't extend it here. This happens on STA2X11, for example.
  825. */
  826. if (pdev->dma_mask && pdev->dma_mask < DMA_BIT_MASK(32))
  827. return 0;
  828. if (using_dac &&
  829. !dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
  830. rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
  831. if (rc) {
  832. rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  833. if (rc) {
  834. dev_err(&pdev->dev,
  835. "64-bit DMA enable failed\n");
  836. return rc;
  837. }
  838. }
  839. } else {
  840. rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  841. if (rc) {
  842. dev_err(&pdev->dev, "32-bit DMA enable failed\n");
  843. return rc;
  844. }
  845. rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  846. if (rc) {
  847. dev_err(&pdev->dev,
  848. "32-bit consistent DMA enable failed\n");
  849. return rc;
  850. }
  851. }
  852. return 0;
  853. }
  854. static void ahci_pci_print_info(struct ata_host *host)
  855. {
  856. struct pci_dev *pdev = to_pci_dev(host->dev);
  857. u16 cc;
  858. const char *scc_s;
  859. pci_read_config_word(pdev, 0x0a, &cc);
  860. if (cc == PCI_CLASS_STORAGE_IDE)
  861. scc_s = "IDE";
  862. else if (cc == PCI_CLASS_STORAGE_SATA)
  863. scc_s = "SATA";
  864. else if (cc == PCI_CLASS_STORAGE_RAID)
  865. scc_s = "RAID";
  866. else
  867. scc_s = "unknown";
  868. ahci_print_info(host, scc_s);
  869. }
  870. /* On ASUS P5W DH Deluxe, the second port of PCI device 00:1f.2 is
  871. * hardwired to on-board SIMG 4726. The chipset is ICH8 and doesn't
  872. * support PMP and the 4726 either directly exports the device
  873. * attached to the first downstream port or acts as a hardware storage
  874. * controller and emulate a single ATA device (can be RAID 0/1 or some
  875. * other configuration).
  876. *
  877. * When there's no device attached to the first downstream port of the
  878. * 4726, "Config Disk" appears, which is a pseudo ATA device to
  879. * configure the 4726. However, ATA emulation of the device is very
  880. * lame. It doesn't send signature D2H Reg FIS after the initial
  881. * hardreset, pukes on SRST w/ PMP==0 and has bunch of other issues.
  882. *
  883. * The following function works around the problem by always using
  884. * hardreset on the port and not depending on receiving signature FIS
  885. * afterward. If signature FIS isn't received soon, ATA class is
  886. * assumed without follow-up softreset.
  887. */
  888. static void ahci_p5wdh_workaround(struct ata_host *host)
  889. {
  890. static const struct dmi_system_id sysids[] = {
  891. {
  892. .ident = "P5W DH Deluxe",
  893. .matches = {
  894. DMI_MATCH(DMI_SYS_VENDOR,
  895. "ASUSTEK COMPUTER INC"),
  896. DMI_MATCH(DMI_PRODUCT_NAME, "P5W DH Deluxe"),
  897. },
  898. },
  899. { }
  900. };
  901. struct pci_dev *pdev = to_pci_dev(host->dev);
  902. if (pdev->bus->number == 0 && pdev->devfn == PCI_DEVFN(0x1f, 2) &&
  903. dmi_check_system(sysids)) {
  904. struct ata_port *ap = host->ports[1];
  905. dev_info(&pdev->dev,
  906. "enabling ASUS P5W DH Deluxe on-board SIMG4726 workaround\n");
  907. ap->ops = &ahci_p5wdh_ops;
  908. ap->link.flags |= ATA_LFLAG_NO_SRST | ATA_LFLAG_ASSUME_ATA;
  909. }
  910. }
  911. /*
  912. * Macbook7,1 firmware forcibly disables MCP89 AHCI and changes PCI ID when
  913. * booting in BIOS compatibility mode. We restore the registers but not ID.
  914. */
  915. static void ahci_mcp89_apple_enable(struct pci_dev *pdev)
  916. {
  917. u32 val;
  918. printk(KERN_INFO "ahci: enabling MCP89 AHCI mode\n");
  919. pci_read_config_dword(pdev, 0xf8, &val);
  920. val |= 1 << 0x1b;
  921. /* the following changes the device ID, but appears not to affect function */
  922. /* val = (val & ~0xf0000000) | 0x80000000; */
  923. pci_write_config_dword(pdev, 0xf8, val);
  924. pci_read_config_dword(pdev, 0x54c, &val);
  925. val |= 1 << 0xc;
  926. pci_write_config_dword(pdev, 0x54c, val);
  927. pci_read_config_dword(pdev, 0x4a4, &val);
  928. val &= 0xff;
  929. val |= 0x01060100;
  930. pci_write_config_dword(pdev, 0x4a4, val);
  931. pci_read_config_dword(pdev, 0x54c, &val);
  932. val &= ~(1 << 0xc);
  933. pci_write_config_dword(pdev, 0x54c, val);
  934. pci_read_config_dword(pdev, 0xf8, &val);
  935. val &= ~(1 << 0x1b);
  936. pci_write_config_dword(pdev, 0xf8, val);
  937. }
  938. static bool is_mcp89_apple(struct pci_dev *pdev)
  939. {
  940. return pdev->vendor == PCI_VENDOR_ID_NVIDIA &&
  941. pdev->device == PCI_DEVICE_ID_NVIDIA_NFORCE_MCP89_SATA &&
  942. pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
  943. pdev->subsystem_device == 0xcb89;
  944. }
  945. /* only some SB600 ahci controllers can do 64bit DMA */
  946. static bool ahci_sb600_enable_64bit(struct pci_dev *pdev)
  947. {
  948. static const struct dmi_system_id sysids[] = {
  949. /*
  950. * The oldest version known to be broken is 0901 and
  951. * working is 1501 which was released on 2007-10-26.
  952. * Enable 64bit DMA on 1501 and anything newer.
  953. *
  954. * Please read bko#9412 for more info.
  955. */
  956. {
  957. .ident = "ASUS M2A-VM",
  958. .matches = {
  959. DMI_MATCH(DMI_BOARD_VENDOR,
  960. "ASUSTeK Computer INC."),
  961. DMI_MATCH(DMI_BOARD_NAME, "M2A-VM"),
  962. },
  963. .driver_data = "20071026", /* yyyymmdd */
  964. },
  965. /*
  966. * All BIOS versions for the MSI K9A2 Platinum (MS-7376)
  967. * support 64bit DMA.
  968. *
  969. * BIOS versions earlier than 1.5 had the Manufacturer DMI
  970. * fields as "MICRO-STAR INTERANTIONAL CO.,LTD".
  971. * This spelling mistake was fixed in BIOS version 1.5, so
  972. * 1.5 and later have the Manufacturer as
  973. * "MICRO-STAR INTERNATIONAL CO.,LTD".
  974. * So try to match on DMI_BOARD_VENDOR of "MICRO-STAR INTER".
  975. *
  976. * BIOS versions earlier than 1.9 had a Board Product Name
  977. * DMI field of "MS-7376". This was changed to be
  978. * "K9A2 Platinum (MS-7376)" in version 1.9, but we can still
  979. * match on DMI_BOARD_NAME of "MS-7376".
  980. */
  981. {
  982. .ident = "MSI K9A2 Platinum",
  983. .matches = {
  984. DMI_MATCH(DMI_BOARD_VENDOR,
  985. "MICRO-STAR INTER"),
  986. DMI_MATCH(DMI_BOARD_NAME, "MS-7376"),
  987. },
  988. },
  989. /*
  990. * All BIOS versions for the MSI K9AGM2 (MS-7327) support
  991. * 64bit DMA.
  992. *
  993. * This board also had the typo mentioned above in the
  994. * Manufacturer DMI field (fixed in BIOS version 1.5), so
  995. * match on DMI_BOARD_VENDOR of "MICRO-STAR INTER" again.
  996. */
  997. {
  998. .ident = "MSI K9AGM2",
  999. .matches = {
  1000. DMI_MATCH(DMI_BOARD_VENDOR,
  1001. "MICRO-STAR INTER"),
  1002. DMI_MATCH(DMI_BOARD_NAME, "MS-7327"),
  1003. },
  1004. },
  1005. /*
  1006. * All BIOS versions for the Asus M3A support 64bit DMA.
  1007. * (all release versions from 0301 to 1206 were tested)
  1008. */
  1009. {
  1010. .ident = "ASUS M3A",
  1011. .matches = {
  1012. DMI_MATCH(DMI_BOARD_VENDOR,
  1013. "ASUSTeK Computer INC."),
  1014. DMI_MATCH(DMI_BOARD_NAME, "M3A"),
  1015. },
  1016. },
  1017. { }
  1018. };
  1019. const struct dmi_system_id *match;
  1020. int year, month, date;
  1021. char buf[9];
  1022. match = dmi_first_match(sysids);
  1023. if (pdev->bus->number != 0 || pdev->devfn != PCI_DEVFN(0x12, 0) ||
  1024. !match)
  1025. return false;
  1026. if (!match->driver_data)
  1027. goto enable_64bit;
  1028. dmi_get_date(DMI_BIOS_DATE, &year, &month, &date);
  1029. snprintf(buf, sizeof(buf), "%04d%02d%02d", year, month, date);
  1030. if (strcmp(buf, match->driver_data) >= 0)
  1031. goto enable_64bit;
  1032. else {
  1033. dev_warn(&pdev->dev,
  1034. "%s: BIOS too old, forcing 32bit DMA, update BIOS\n",
  1035. match->ident);
  1036. return false;
  1037. }
  1038. enable_64bit:
  1039. dev_warn(&pdev->dev, "%s: enabling 64bit DMA\n", match->ident);
  1040. return true;
  1041. }
  1042. static bool ahci_broken_system_poweroff(struct pci_dev *pdev)
  1043. {
  1044. static const struct dmi_system_id broken_systems[] = {
  1045. {
  1046. .ident = "HP Compaq nx6310",
  1047. .matches = {
  1048. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1049. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6310"),
  1050. },
  1051. /* PCI slot number of the controller */
  1052. .driver_data = (void *)0x1FUL,
  1053. },
  1054. {
  1055. .ident = "HP Compaq 6720s",
  1056. .matches = {
  1057. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1058. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6720s"),
  1059. },
  1060. /* PCI slot number of the controller */
  1061. .driver_data = (void *)0x1FUL,
  1062. },
  1063. { } /* terminate list */
  1064. };
  1065. const struct dmi_system_id *dmi = dmi_first_match(broken_systems);
  1066. if (dmi) {
  1067. unsigned long slot = (unsigned long)dmi->driver_data;
  1068. /* apply the quirk only to on-board controllers */
  1069. return slot == PCI_SLOT(pdev->devfn);
  1070. }
  1071. return false;
  1072. }
  1073. static bool ahci_broken_suspend(struct pci_dev *pdev)
  1074. {
  1075. static const struct dmi_system_id sysids[] = {
  1076. /*
  1077. * On HP dv[4-6] and HDX18 with earlier BIOSen, link
  1078. * to the harddisk doesn't become online after
  1079. * resuming from STR. Warn and fail suspend.
  1080. *
  1081. * http://bugzilla.kernel.org/show_bug.cgi?id=12276
  1082. *
  1083. * Use dates instead of versions to match as HP is
  1084. * apparently recycling both product and version
  1085. * strings.
  1086. *
  1087. * http://bugzilla.kernel.org/show_bug.cgi?id=15462
  1088. */
  1089. {
  1090. .ident = "dv4",
  1091. .matches = {
  1092. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1093. DMI_MATCH(DMI_PRODUCT_NAME,
  1094. "HP Pavilion dv4 Notebook PC"),
  1095. },
  1096. .driver_data = "20090105", /* F.30 */
  1097. },
  1098. {
  1099. .ident = "dv5",
  1100. .matches = {
  1101. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1102. DMI_MATCH(DMI_PRODUCT_NAME,
  1103. "HP Pavilion dv5 Notebook PC"),
  1104. },
  1105. .driver_data = "20090506", /* F.16 */
  1106. },
  1107. {
  1108. .ident = "dv6",
  1109. .matches = {
  1110. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1111. DMI_MATCH(DMI_PRODUCT_NAME,
  1112. "HP Pavilion dv6 Notebook PC"),
  1113. },
  1114. .driver_data = "20090423", /* F.21 */
  1115. },
  1116. {
  1117. .ident = "HDX18",
  1118. .matches = {
  1119. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1120. DMI_MATCH(DMI_PRODUCT_NAME,
  1121. "HP HDX18 Notebook PC"),
  1122. },
  1123. .driver_data = "20090430", /* F.23 */
  1124. },
  1125. /*
  1126. * Acer eMachines G725 has the same problem. BIOS
  1127. * V1.03 is known to be broken. V3.04 is known to
  1128. * work. Between, there are V1.06, V2.06 and V3.03
  1129. * that we don't have much idea about. For now,
  1130. * blacklist anything older than V3.04.
  1131. *
  1132. * http://bugzilla.kernel.org/show_bug.cgi?id=15104
  1133. */
  1134. {
  1135. .ident = "G725",
  1136. .matches = {
  1137. DMI_MATCH(DMI_SYS_VENDOR, "eMachines"),
  1138. DMI_MATCH(DMI_PRODUCT_NAME, "eMachines G725"),
  1139. },
  1140. .driver_data = "20091216", /* V3.04 */
  1141. },
  1142. { } /* terminate list */
  1143. };
  1144. const struct dmi_system_id *dmi = dmi_first_match(sysids);
  1145. int year, month, date;
  1146. char buf[9];
  1147. if (!dmi || pdev->bus->number || pdev->devfn != PCI_DEVFN(0x1f, 2))
  1148. return false;
  1149. dmi_get_date(DMI_BIOS_DATE, &year, &month, &date);
  1150. snprintf(buf, sizeof(buf), "%04d%02d%02d", year, month, date);
  1151. return strcmp(buf, dmi->driver_data) < 0;
  1152. }
  1153. static bool ahci_broken_lpm(struct pci_dev *pdev)
  1154. {
  1155. static const struct dmi_system_id sysids[] = {
  1156. /* Various Lenovo 50 series have LPM issues with older BIOSen */
  1157. {
  1158. .matches = {
  1159. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  1160. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X250"),
  1161. },
  1162. .driver_data = "20180406", /* 1.31 */
  1163. },
  1164. {
  1165. .matches = {
  1166. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  1167. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad L450"),
  1168. },
  1169. .driver_data = "20180420", /* 1.28 */
  1170. },
  1171. {
  1172. .matches = {
  1173. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  1174. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T450s"),
  1175. },
  1176. .driver_data = "20180315", /* 1.33 */
  1177. },
  1178. {
  1179. .matches = {
  1180. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  1181. DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad W541"),
  1182. },
  1183. /*
  1184. * Note date based on release notes, 2.35 has been
  1185. * reported to be good, but I've been unable to get
  1186. * a hold of the reporter to get the DMI BIOS date.
  1187. * TODO: fix this.
  1188. */
  1189. .driver_data = "20180310", /* 2.35 */
  1190. },
  1191. { } /* terminate list */
  1192. };
  1193. const struct dmi_system_id *dmi = dmi_first_match(sysids);
  1194. int year, month, date;
  1195. char buf[9];
  1196. if (!dmi)
  1197. return false;
  1198. dmi_get_date(DMI_BIOS_DATE, &year, &month, &date);
  1199. snprintf(buf, sizeof(buf), "%04d%02d%02d", year, month, date);
  1200. return strcmp(buf, dmi->driver_data) < 0;
  1201. }
  1202. static bool ahci_broken_online(struct pci_dev *pdev)
  1203. {
  1204. #define ENCODE_BUSDEVFN(bus, slot, func) \
  1205. (void *)(unsigned long)(((bus) << 8) | PCI_DEVFN((slot), (func)))
  1206. static const struct dmi_system_id sysids[] = {
  1207. /*
  1208. * There are several gigabyte boards which use
  1209. * SIMG5723s configured as hardware RAID. Certain
  1210. * 5723 firmware revisions shipped there keep the link
  1211. * online but fail to answer properly to SRST or
  1212. * IDENTIFY when no device is attached downstream
  1213. * causing libata to retry quite a few times leading
  1214. * to excessive detection delay.
  1215. *
  1216. * As these firmwares respond to the second reset try
  1217. * with invalid device signature, considering unknown
  1218. * sig as offline works around the problem acceptably.
  1219. */
  1220. {
  1221. .ident = "EP45-DQ6",
  1222. .matches = {
  1223. DMI_MATCH(DMI_BOARD_VENDOR,
  1224. "Gigabyte Technology Co., Ltd."),
  1225. DMI_MATCH(DMI_BOARD_NAME, "EP45-DQ6"),
  1226. },
  1227. .driver_data = ENCODE_BUSDEVFN(0x0a, 0x00, 0),
  1228. },
  1229. {
  1230. .ident = "EP45-DS5",
  1231. .matches = {
  1232. DMI_MATCH(DMI_BOARD_VENDOR,
  1233. "Gigabyte Technology Co., Ltd."),
  1234. DMI_MATCH(DMI_BOARD_NAME, "EP45-DS5"),
  1235. },
  1236. .driver_data = ENCODE_BUSDEVFN(0x03, 0x00, 0),
  1237. },
  1238. { } /* terminate list */
  1239. };
  1240. #undef ENCODE_BUSDEVFN
  1241. const struct dmi_system_id *dmi = dmi_first_match(sysids);
  1242. unsigned int val;
  1243. if (!dmi)
  1244. return false;
  1245. val = (unsigned long)dmi->driver_data;
  1246. return pdev->bus->number == (val >> 8) && pdev->devfn == (val & 0xff);
  1247. }
  1248. static bool ahci_broken_devslp(struct pci_dev *pdev)
  1249. {
  1250. /* device with broken DEVSLP but still showing SDS capability */
  1251. static const struct pci_device_id ids[] = {
  1252. { PCI_VDEVICE(INTEL, 0x0f23)}, /* Valleyview SoC */
  1253. {}
  1254. };
  1255. return pci_match_id(ids, pdev);
  1256. }
  1257. #ifdef CONFIG_ATA_ACPI
  1258. static void ahci_gtf_filter_workaround(struct ata_host *host)
  1259. {
  1260. static const struct dmi_system_id sysids[] = {
  1261. /*
  1262. * Aspire 3810T issues a bunch of SATA enable commands
  1263. * via _GTF including an invalid one and one which is
  1264. * rejected by the device. Among the successful ones
  1265. * is FPDMA non-zero offset enable which when enabled
  1266. * only on the drive side leads to NCQ command
  1267. * failures. Filter it out.
  1268. */
  1269. {
  1270. .ident = "Aspire 3810T",
  1271. .matches = {
  1272. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  1273. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3810T"),
  1274. },
  1275. .driver_data = (void *)ATA_ACPI_FILTER_FPDMA_OFFSET,
  1276. },
  1277. { }
  1278. };
  1279. const struct dmi_system_id *dmi = dmi_first_match(sysids);
  1280. unsigned int filter;
  1281. int i;
  1282. if (!dmi)
  1283. return;
  1284. filter = (unsigned long)dmi->driver_data;
  1285. dev_info(host->dev, "applying extra ACPI _GTF filter 0x%x for %s\n",
  1286. filter, dmi->ident);
  1287. for (i = 0; i < host->n_ports; i++) {
  1288. struct ata_port *ap = host->ports[i];
  1289. struct ata_link *link;
  1290. struct ata_device *dev;
  1291. ata_for_each_link(link, ap, EDGE)
  1292. ata_for_each_dev(dev, link, ALL)
  1293. dev->gtf_filter |= filter;
  1294. }
  1295. }
  1296. #else
  1297. static inline void ahci_gtf_filter_workaround(struct ata_host *host)
  1298. {}
  1299. #endif
  1300. /*
  1301. * On the Acer Aspire Switch Alpha 12, sometimes all SATA ports are detected
  1302. * as DUMMY, or detected but eventually get a "link down" and never get up
  1303. * again. When this happens, CAP.NP may hold a value of 0x00 or 0x01, and the
  1304. * port_map may hold a value of 0x00.
  1305. *
  1306. * Overriding CAP.NP to 0x02 and the port_map to 0x7 will reveal all 3 ports
  1307. * and can significantly reduce the occurrence of the problem.
  1308. *
  1309. * https://bugzilla.kernel.org/show_bug.cgi?id=189471
  1310. */
  1311. static void acer_sa5_271_workaround(struct ahci_host_priv *hpriv,
  1312. struct pci_dev *pdev)
  1313. {
  1314. static const struct dmi_system_id sysids[] = {
  1315. {
  1316. .ident = "Acer Switch Alpha 12",
  1317. .matches = {
  1318. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  1319. DMI_MATCH(DMI_PRODUCT_NAME, "Switch SA5-271")
  1320. },
  1321. },
  1322. { }
  1323. };
  1324. if (dmi_check_system(sysids)) {
  1325. dev_info(&pdev->dev, "enabling Acer Switch Alpha 12 workaround\n");
  1326. if ((hpriv->saved_cap & 0xC734FF00) == 0xC734FF00) {
  1327. hpriv->port_map = 0x7;
  1328. hpriv->cap = 0xC734FF02;
  1329. }
  1330. }
  1331. }
  1332. #ifdef CONFIG_ARM64
  1333. /*
  1334. * Due to ERRATA#22536, ThunderX needs to handle HOST_IRQ_STAT differently.
  1335. * Workaround is to make sure all pending IRQs are served before leaving
  1336. * handler.
  1337. */
  1338. static irqreturn_t ahci_thunderx_irq_handler(int irq, void *dev_instance)
  1339. {
  1340. struct ata_host *host = dev_instance;
  1341. struct ahci_host_priv *hpriv;
  1342. unsigned int rc = 0;
  1343. void __iomem *mmio;
  1344. u32 irq_stat, irq_masked;
  1345. unsigned int handled = 1;
  1346. VPRINTK("ENTER\n");
  1347. hpriv = host->private_data;
  1348. mmio = hpriv->mmio;
  1349. irq_stat = readl(mmio + HOST_IRQ_STAT);
  1350. if (!irq_stat)
  1351. return IRQ_NONE;
  1352. do {
  1353. irq_masked = irq_stat & hpriv->port_map;
  1354. spin_lock(&host->lock);
  1355. rc = ahci_handle_port_intr(host, irq_masked);
  1356. if (!rc)
  1357. handled = 0;
  1358. writel(irq_stat, mmio + HOST_IRQ_STAT);
  1359. irq_stat = readl(mmio + HOST_IRQ_STAT);
  1360. spin_unlock(&host->lock);
  1361. } while (irq_stat);
  1362. VPRINTK("EXIT\n");
  1363. return IRQ_RETVAL(handled);
  1364. }
  1365. #endif
  1366. static void ahci_remap_check(struct pci_dev *pdev, int bar,
  1367. struct ahci_host_priv *hpriv)
  1368. {
  1369. int i, count = 0;
  1370. u32 cap;
  1371. /*
  1372. * Check if this device might have remapped nvme devices.
  1373. */
  1374. if (pdev->vendor != PCI_VENDOR_ID_INTEL ||
  1375. pci_resource_len(pdev, bar) < SZ_512K ||
  1376. bar != AHCI_PCI_BAR_STANDARD ||
  1377. !(readl(hpriv->mmio + AHCI_VSCAP) & 1))
  1378. return;
  1379. cap = readq(hpriv->mmio + AHCI_REMAP_CAP);
  1380. for (i = 0; i < AHCI_MAX_REMAP; i++) {
  1381. if ((cap & (1 << i)) == 0)
  1382. continue;
  1383. if (readl(hpriv->mmio + ahci_remap_dcc(i))
  1384. != PCI_CLASS_STORAGE_EXPRESS)
  1385. continue;
  1386. /* We've found a remapped device */
  1387. count++;
  1388. }
  1389. if (!count)
  1390. return;
  1391. dev_warn(&pdev->dev, "Found %d remapped NVMe devices.\n", count);
  1392. dev_warn(&pdev->dev,
  1393. "Switch your BIOS from RAID to AHCI mode to use them.\n");
  1394. /*
  1395. * Don't rely on the msi-x capability in the remap case,
  1396. * share the legacy interrupt across ahci and remapped devices.
  1397. */
  1398. hpriv->flags |= AHCI_HFLAG_NO_MSI;
  1399. }
  1400. static int ahci_get_irq_vector(struct ata_host *host, int port)
  1401. {
  1402. return pci_irq_vector(to_pci_dev(host->dev), port);
  1403. }
  1404. static int ahci_init_msi(struct pci_dev *pdev, unsigned int n_ports,
  1405. struct ahci_host_priv *hpriv)
  1406. {
  1407. int nvec;
  1408. if (hpriv->flags & AHCI_HFLAG_NO_MSI)
  1409. return -ENODEV;
  1410. /*
  1411. * If number of MSIs is less than number of ports then Sharing Last
  1412. * Message mode could be enforced. In this case assume that advantage
  1413. * of multipe MSIs is negated and use single MSI mode instead.
  1414. */
  1415. if (n_ports > 1) {
  1416. nvec = pci_alloc_irq_vectors(pdev, n_ports, INT_MAX,
  1417. PCI_IRQ_MSIX | PCI_IRQ_MSI);
  1418. if (nvec > 0) {
  1419. if (!(readl(hpriv->mmio + HOST_CTL) & HOST_MRSM)) {
  1420. hpriv->get_irq_vector = ahci_get_irq_vector;
  1421. hpriv->flags |= AHCI_HFLAG_MULTI_MSI;
  1422. return nvec;
  1423. }
  1424. /*
  1425. * Fallback to single MSI mode if the controller
  1426. * enforced MRSM mode.
  1427. */
  1428. printk(KERN_INFO
  1429. "ahci: MRSM is on, fallback to single MSI\n");
  1430. pci_free_irq_vectors(pdev);
  1431. }
  1432. }
  1433. /*
  1434. * If the host is not capable of supporting per-port vectors, fall
  1435. * back to single MSI before finally attempting single MSI-X.
  1436. */
  1437. nvec = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI);
  1438. if (nvec == 1)
  1439. return nvec;
  1440. return pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSIX);
  1441. }
  1442. static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  1443. {
  1444. unsigned int board_id = ent->driver_data;
  1445. struct ata_port_info pi = ahci_port_info[board_id];
  1446. const struct ata_port_info *ppi[] = { &pi, NULL };
  1447. struct device *dev = &pdev->dev;
  1448. struct ahci_host_priv *hpriv;
  1449. struct ata_host *host;
  1450. int n_ports, i, rc;
  1451. int ahci_pci_bar = AHCI_PCI_BAR_STANDARD;
  1452. VPRINTK("ENTER\n");
  1453. WARN_ON((int)ATA_MAX_QUEUE > AHCI_MAX_CMDS);
  1454. ata_print_version_once(&pdev->dev, DRV_VERSION);
  1455. /* The AHCI driver can only drive the SATA ports, the PATA driver
  1456. can drive them all so if both drivers are selected make sure
  1457. AHCI stays out of the way */
  1458. if (pdev->vendor == PCI_VENDOR_ID_MARVELL && !marvell_enable)
  1459. return -ENODEV;
  1460. /* Apple BIOS on MCP89 prevents us using AHCI */
  1461. if (is_mcp89_apple(pdev))
  1462. ahci_mcp89_apple_enable(pdev);
  1463. /* Promise's PDC42819 is a SAS/SATA controller that has an AHCI mode.
  1464. * At the moment, we can only use the AHCI mode. Let the users know
  1465. * that for SAS drives they're out of luck.
  1466. */
  1467. if (pdev->vendor == PCI_VENDOR_ID_PROMISE)
  1468. dev_info(&pdev->dev,
  1469. "PDC42819 can only drive SATA devices with this driver\n");
  1470. /* Some devices use non-standard BARs */
  1471. if (pdev->vendor == PCI_VENDOR_ID_STMICRO && pdev->device == 0xCC06)
  1472. ahci_pci_bar = AHCI_PCI_BAR_STA2X11;
  1473. else if (pdev->vendor == 0x1c44 && pdev->device == 0x8000)
  1474. ahci_pci_bar = AHCI_PCI_BAR_ENMOTUS;
  1475. else if (pdev->vendor == 0x177d && pdev->device == 0xa01c)
  1476. ahci_pci_bar = AHCI_PCI_BAR_CAVIUM;
  1477. /* acquire resources */
  1478. rc = pcim_enable_device(pdev);
  1479. if (rc)
  1480. return rc;
  1481. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  1482. (pdev->device == 0x2652 || pdev->device == 0x2653)) {
  1483. u8 map;
  1484. /* ICH6s share the same PCI ID for both piix and ahci
  1485. * modes. Enabling ahci mode while MAP indicates
  1486. * combined mode is a bad idea. Yield to ata_piix.
  1487. */
  1488. pci_read_config_byte(pdev, ICH_MAP, &map);
  1489. if (map & 0x3) {
  1490. dev_info(&pdev->dev,
  1491. "controller is in combined mode, can't enable AHCI mode\n");
  1492. return -ENODEV;
  1493. }
  1494. }
  1495. /* AHCI controllers often implement SFF compatible interface.
  1496. * Grab all PCI BARs just in case.
  1497. */
  1498. rc = pcim_iomap_regions_request_all(pdev, 1 << ahci_pci_bar, DRV_NAME);
  1499. if (rc == -EBUSY)
  1500. pcim_pin_device(pdev);
  1501. if (rc)
  1502. return rc;
  1503. hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
  1504. if (!hpriv)
  1505. return -ENOMEM;
  1506. hpriv->flags |= (unsigned long)pi.private_data;
  1507. /* MCP65 revision A1 and A2 can't do MSI */
  1508. if (board_id == board_ahci_mcp65 &&
  1509. (pdev->revision == 0xa1 || pdev->revision == 0xa2))
  1510. hpriv->flags |= AHCI_HFLAG_NO_MSI;
  1511. /* SB800 does NOT need the workaround to ignore SERR_INTERNAL */
  1512. if (board_id == board_ahci_sb700 && pdev->revision >= 0x40)
  1513. hpriv->flags &= ~AHCI_HFLAG_IGN_SERR_INTERNAL;
  1514. /* only some SB600s can do 64bit DMA */
  1515. if (ahci_sb600_enable_64bit(pdev))
  1516. hpriv->flags &= ~AHCI_HFLAG_32BIT_ONLY;
  1517. hpriv->mmio = pcim_iomap_table(pdev)[ahci_pci_bar];
  1518. /* detect remapped nvme devices */
  1519. ahci_remap_check(pdev, ahci_pci_bar, hpriv);
  1520. /* must set flag prior to save config in order to take effect */
  1521. if (ahci_broken_devslp(pdev))
  1522. hpriv->flags |= AHCI_HFLAG_NO_DEVSLP;
  1523. #ifdef CONFIG_ARM64
  1524. if (pdev->vendor == 0x177d && pdev->device == 0xa01c)
  1525. hpriv->irq_handler = ahci_thunderx_irq_handler;
  1526. #endif
  1527. /* save initial config */
  1528. ahci_pci_save_initial_config(pdev, hpriv);
  1529. /* prepare host */
  1530. if (hpriv->cap & HOST_CAP_NCQ) {
  1531. pi.flags |= ATA_FLAG_NCQ;
  1532. /*
  1533. * Auto-activate optimization is supposed to be
  1534. * supported on all AHCI controllers indicating NCQ
  1535. * capability, but it seems to be broken on some
  1536. * chipsets including NVIDIAs.
  1537. */
  1538. if (!(hpriv->flags & AHCI_HFLAG_NO_FPDMA_AA))
  1539. pi.flags |= ATA_FLAG_FPDMA_AA;
  1540. /*
  1541. * All AHCI controllers should be forward-compatible
  1542. * with the new auxiliary field. This code should be
  1543. * conditionalized if any buggy AHCI controllers are
  1544. * encountered.
  1545. */
  1546. pi.flags |= ATA_FLAG_FPDMA_AUX;
  1547. }
  1548. if (hpriv->cap & HOST_CAP_PMP)
  1549. pi.flags |= ATA_FLAG_PMP;
  1550. ahci_set_em_messages(hpriv, &pi);
  1551. if (ahci_broken_system_poweroff(pdev)) {
  1552. pi.flags |= ATA_FLAG_NO_POWEROFF_SPINDOWN;
  1553. dev_info(&pdev->dev,
  1554. "quirky BIOS, skipping spindown on poweroff\n");
  1555. }
  1556. if (ahci_broken_lpm(pdev)) {
  1557. pi.flags |= ATA_FLAG_NO_LPM;
  1558. dev_warn(&pdev->dev,
  1559. "BIOS update required for Link Power Management support\n");
  1560. }
  1561. if (ahci_broken_suspend(pdev)) {
  1562. hpriv->flags |= AHCI_HFLAG_NO_SUSPEND;
  1563. dev_warn(&pdev->dev,
  1564. "BIOS update required for suspend/resume\n");
  1565. }
  1566. if (ahci_broken_online(pdev)) {
  1567. hpriv->flags |= AHCI_HFLAG_SRST_TOUT_IS_OFFLINE;
  1568. dev_info(&pdev->dev,
  1569. "online status unreliable, applying workaround\n");
  1570. }
  1571. /* Acer SA5-271 workaround modifies private_data */
  1572. acer_sa5_271_workaround(hpriv, pdev);
  1573. /* CAP.NP sometimes indicate the index of the last enabled
  1574. * port, at other times, that of the last possible port, so
  1575. * determining the maximum port number requires looking at
  1576. * both CAP.NP and port_map.
  1577. */
  1578. n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
  1579. host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
  1580. if (!host)
  1581. return -ENOMEM;
  1582. host->private_data = hpriv;
  1583. if (ahci_init_msi(pdev, n_ports, hpriv) < 0) {
  1584. /* legacy intx interrupts */
  1585. pci_intx(pdev, 1);
  1586. }
  1587. hpriv->irq = pci_irq_vector(pdev, 0);
  1588. if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
  1589. host->flags |= ATA_HOST_PARALLEL_SCAN;
  1590. else
  1591. dev_info(&pdev->dev, "SSS flag set, parallel bus scan disabled\n");
  1592. if (pi.flags & ATA_FLAG_EM)
  1593. ahci_reset_em(host);
  1594. for (i = 0; i < host->n_ports; i++) {
  1595. struct ata_port *ap = host->ports[i];
  1596. ata_port_pbar_desc(ap, ahci_pci_bar, -1, "abar");
  1597. ata_port_pbar_desc(ap, ahci_pci_bar,
  1598. 0x100 + ap->port_no * 0x80, "port");
  1599. /* set enclosure management message type */
  1600. if (ap->flags & ATA_FLAG_EM)
  1601. ap->em_message_type = hpriv->em_msg_type;
  1602. /* disabled/not-implemented port */
  1603. if (!(hpriv->port_map & (1 << i)))
  1604. ap->ops = &ata_dummy_port_ops;
  1605. }
  1606. /* apply workaround for ASUS P5W DH Deluxe mainboard */
  1607. ahci_p5wdh_workaround(host);
  1608. /* apply gtf filter quirk */
  1609. ahci_gtf_filter_workaround(host);
  1610. /* initialize adapter */
  1611. rc = ahci_configure_dma_masks(pdev, hpriv->cap & HOST_CAP_64);
  1612. if (rc)
  1613. return rc;
  1614. rc = ahci_pci_reset_controller(host);
  1615. if (rc)
  1616. return rc;
  1617. ahci_pci_init_controller(host);
  1618. ahci_pci_print_info(host);
  1619. pci_set_master(pdev);
  1620. rc = ahci_host_activate(host, &ahci_sht);
  1621. if (rc)
  1622. return rc;
  1623. pm_runtime_put_noidle(&pdev->dev);
  1624. return 0;
  1625. }
  1626. static void ahci_shutdown_one(struct pci_dev *pdev)
  1627. {
  1628. ata_pci_shutdown_one(pdev);
  1629. }
  1630. static void ahci_remove_one(struct pci_dev *pdev)
  1631. {
  1632. pm_runtime_get_noresume(&pdev->dev);
  1633. ata_pci_remove_one(pdev);
  1634. }
  1635. module_pci_driver(ahci_pci_driver);
  1636. MODULE_AUTHOR("Jeff Garzik");
  1637. MODULE_DESCRIPTION("AHCI SATA low-level driver");
  1638. MODULE_LICENSE("GPL");
  1639. MODULE_DEVICE_TABLE(pci, ahci_pci_tbl);
  1640. MODULE_VERSION(DRV_VERSION);