ahci.c 70 KB

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