ahci.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436
  1. /*
  2. * ahci.c - AHCI SATA support
  3. *
  4. * Maintained by: Jeff Garzik <jgarzik@pobox.com>
  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/DocBook/libata.*
  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/init.h>
  38. #include <linux/blkdev.h>
  39. #include <linux/delay.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/dma-mapping.h>
  42. #include <linux/device.h>
  43. #include <linux/dmi.h>
  44. #include <linux/gfp.h>
  45. #include <scsi/scsi_host.h>
  46. #include <scsi/scsi_cmnd.h>
  47. #include <linux/libata.h>
  48. #include "ahci.h"
  49. #define DRV_NAME "ahci"
  50. #define DRV_VERSION "3.0"
  51. enum {
  52. AHCI_PCI_BAR_STA2X11 = 0,
  53. AHCI_PCI_BAR_ENMOTUS = 2,
  54. AHCI_PCI_BAR_STANDARD = 5,
  55. };
  56. enum board_ids {
  57. /* board IDs by feature in alphabetical order */
  58. board_ahci,
  59. board_ahci_ign_iferr,
  60. board_ahci_nomsi,
  61. board_ahci_noncq,
  62. board_ahci_nosntf,
  63. board_ahci_yes_fbs,
  64. /* board IDs for specific chipsets in alphabetical order */
  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 int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
  81. unsigned long deadline);
  82. static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
  83. unsigned long deadline);
  84. static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
  85. unsigned long deadline);
  86. #ifdef CONFIG_PM
  87. static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
  88. static int ahci_pci_device_resume(struct pci_dev *pdev);
  89. #endif
  90. static struct scsi_host_template ahci_sht = {
  91. AHCI_SHT("ahci"),
  92. };
  93. static struct ata_port_operations ahci_vt8251_ops = {
  94. .inherits = &ahci_ops,
  95. .hardreset = ahci_vt8251_hardreset,
  96. };
  97. static struct ata_port_operations ahci_p5wdh_ops = {
  98. .inherits = &ahci_ops,
  99. .hardreset = ahci_p5wdh_hardreset,
  100. };
  101. static struct ata_port_operations ahci_avn_ops = {
  102. .inherits = &ahci_ops,
  103. .hardreset = ahci_avn_hardreset,
  104. };
  105. static const struct ata_port_info ahci_port_info[] = {
  106. /* by features */
  107. [board_ahci] =
  108. {
  109. .flags = AHCI_FLAG_COMMON,
  110. .pio_mask = ATA_PIO4,
  111. .udma_mask = ATA_UDMA6,
  112. .port_ops = &ahci_ops,
  113. },
  114. [board_ahci_ign_iferr] =
  115. {
  116. AHCI_HFLAGS (AHCI_HFLAG_IGN_IRQ_IF_ERR),
  117. .flags = AHCI_FLAG_COMMON,
  118. .pio_mask = ATA_PIO4,
  119. .udma_mask = ATA_UDMA6,
  120. .port_ops = &ahci_ops,
  121. },
  122. [board_ahci_nomsi] = {
  123. AHCI_HFLAGS (AHCI_HFLAG_NO_MSI),
  124. .flags = AHCI_FLAG_COMMON,
  125. .pio_mask = ATA_PIO4,
  126. .udma_mask = ATA_UDMA6,
  127. .port_ops = &ahci_ops,
  128. },
  129. [board_ahci_noncq] = {
  130. AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ),
  131. .flags = AHCI_FLAG_COMMON,
  132. .pio_mask = ATA_PIO4,
  133. .udma_mask = ATA_UDMA6,
  134. .port_ops = &ahci_ops,
  135. },
  136. [board_ahci_nosntf] =
  137. {
  138. AHCI_HFLAGS (AHCI_HFLAG_NO_SNTF),
  139. .flags = AHCI_FLAG_COMMON,
  140. .pio_mask = ATA_PIO4,
  141. .udma_mask = ATA_UDMA6,
  142. .port_ops = &ahci_ops,
  143. },
  144. [board_ahci_yes_fbs] =
  145. {
  146. AHCI_HFLAGS (AHCI_HFLAG_YES_FBS),
  147. .flags = AHCI_FLAG_COMMON,
  148. .pio_mask = ATA_PIO4,
  149. .udma_mask = ATA_UDMA6,
  150. .port_ops = &ahci_ops,
  151. },
  152. /* by chipsets */
  153. [board_ahci_avn] = {
  154. .flags = AHCI_FLAG_COMMON,
  155. .pio_mask = ATA_PIO4,
  156. .udma_mask = ATA_UDMA6,
  157. .port_ops = &ahci_avn_ops,
  158. },
  159. [board_ahci_mcp65] =
  160. {
  161. AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA | AHCI_HFLAG_NO_PMP |
  162. AHCI_HFLAG_YES_NCQ),
  163. .flags = AHCI_FLAG_COMMON | ATA_FLAG_NO_DIPM,
  164. .pio_mask = ATA_PIO4,
  165. .udma_mask = ATA_UDMA6,
  166. .port_ops = &ahci_ops,
  167. },
  168. [board_ahci_mcp77] =
  169. {
  170. AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA | AHCI_HFLAG_NO_PMP),
  171. .flags = AHCI_FLAG_COMMON,
  172. .pio_mask = ATA_PIO4,
  173. .udma_mask = ATA_UDMA6,
  174. .port_ops = &ahci_ops,
  175. },
  176. [board_ahci_mcp89] =
  177. {
  178. AHCI_HFLAGS (AHCI_HFLAG_NO_FPDMA_AA),
  179. .flags = AHCI_FLAG_COMMON,
  180. .pio_mask = ATA_PIO4,
  181. .udma_mask = ATA_UDMA6,
  182. .port_ops = &ahci_ops,
  183. },
  184. [board_ahci_mv] =
  185. {
  186. AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_MSI |
  187. AHCI_HFLAG_MV_PATA | AHCI_HFLAG_NO_PMP),
  188. .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA,
  189. .pio_mask = ATA_PIO4,
  190. .udma_mask = ATA_UDMA6,
  191. .port_ops = &ahci_ops,
  192. },
  193. [board_ahci_sb600] =
  194. {
  195. AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL |
  196. AHCI_HFLAG_NO_MSI | AHCI_HFLAG_SECT255 |
  197. AHCI_HFLAG_32BIT_ONLY),
  198. .flags = AHCI_FLAG_COMMON,
  199. .pio_mask = ATA_PIO4,
  200. .udma_mask = ATA_UDMA6,
  201. .port_ops = &ahci_pmp_retry_srst_ops,
  202. },
  203. [board_ahci_sb700] = /* for SB700 and SB800 */
  204. {
  205. AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL),
  206. .flags = AHCI_FLAG_COMMON,
  207. .pio_mask = ATA_PIO4,
  208. .udma_mask = ATA_UDMA6,
  209. .port_ops = &ahci_pmp_retry_srst_ops,
  210. },
  211. [board_ahci_vt8251] =
  212. {
  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 AHCI */
  259. { PCI_VDEVICE(INTEL, 0x3b2b), board_ahci }, /* PCH RAID */
  260. { PCI_VDEVICE(INTEL, 0x3b2c), board_ahci }, /* PCH RAID */
  261. { PCI_VDEVICE(INTEL, 0x3b2f), board_ahci }, /* PCH AHCI */
  262. { PCI_VDEVICE(INTEL, 0x1c02), board_ahci }, /* CPT AHCI */
  263. { PCI_VDEVICE(INTEL, 0x1c03), board_ahci }, /* CPT AHCI */
  264. { PCI_VDEVICE(INTEL, 0x1c04), board_ahci }, /* CPT RAID */
  265. { PCI_VDEVICE(INTEL, 0x1c05), board_ahci }, /* CPT RAID */
  266. { PCI_VDEVICE(INTEL, 0x1c06), board_ahci }, /* CPT RAID */
  267. { PCI_VDEVICE(INTEL, 0x1c07), board_ahci }, /* CPT RAID */
  268. { PCI_VDEVICE(INTEL, 0x1d02), board_ahci }, /* PBG AHCI */
  269. { PCI_VDEVICE(INTEL, 0x1d04), board_ahci }, /* PBG RAID */
  270. { PCI_VDEVICE(INTEL, 0x1d06), board_ahci }, /* PBG RAID */
  271. { PCI_VDEVICE(INTEL, 0x2826), board_ahci }, /* PBG RAID */
  272. { PCI_VDEVICE(INTEL, 0x2323), board_ahci }, /* DH89xxCC AHCI */
  273. { PCI_VDEVICE(INTEL, 0x1e02), board_ahci }, /* Panther Point AHCI */
  274. { PCI_VDEVICE(INTEL, 0x1e03), board_ahci }, /* Panther Point AHCI */
  275. { PCI_VDEVICE(INTEL, 0x1e04), board_ahci }, /* Panther Point RAID */
  276. { PCI_VDEVICE(INTEL, 0x1e05), board_ahci }, /* Panther Point RAID */
  277. { PCI_VDEVICE(INTEL, 0x1e06), board_ahci }, /* Panther Point RAID */
  278. { PCI_VDEVICE(INTEL, 0x1e07), board_ahci }, /* Panther Point RAID */
  279. { PCI_VDEVICE(INTEL, 0x1e0e), board_ahci }, /* Panther Point RAID */
  280. { PCI_VDEVICE(INTEL, 0x8c02), board_ahci }, /* Lynx Point AHCI */
  281. { PCI_VDEVICE(INTEL, 0x8c03), board_ahci }, /* Lynx Point AHCI */
  282. { PCI_VDEVICE(INTEL, 0x8c04), board_ahci }, /* Lynx Point RAID */
  283. { PCI_VDEVICE(INTEL, 0x8c05), board_ahci }, /* Lynx Point RAID */
  284. { PCI_VDEVICE(INTEL, 0x8c06), board_ahci }, /* Lynx Point RAID */
  285. { PCI_VDEVICE(INTEL, 0x8c07), board_ahci }, /* Lynx Point RAID */
  286. { PCI_VDEVICE(INTEL, 0x8c0e), board_ahci }, /* Lynx Point RAID */
  287. { PCI_VDEVICE(INTEL, 0x8c0f), board_ahci }, /* Lynx Point RAID */
  288. { PCI_VDEVICE(INTEL, 0x9c02), board_ahci }, /* Lynx Point-LP AHCI */
  289. { PCI_VDEVICE(INTEL, 0x9c03), board_ahci }, /* Lynx Point-LP AHCI */
  290. { PCI_VDEVICE(INTEL, 0x9c04), board_ahci }, /* Lynx Point-LP RAID */
  291. { PCI_VDEVICE(INTEL, 0x9c05), board_ahci }, /* Lynx Point-LP RAID */
  292. { PCI_VDEVICE(INTEL, 0x9c06), board_ahci }, /* Lynx Point-LP RAID */
  293. { PCI_VDEVICE(INTEL, 0x9c07), board_ahci }, /* Lynx Point-LP RAID */
  294. { PCI_VDEVICE(INTEL, 0x9c0e), board_ahci }, /* Lynx Point-LP RAID */
  295. { PCI_VDEVICE(INTEL, 0x9c0f), board_ahci }, /* Lynx Point-LP RAID */
  296. { PCI_VDEVICE(INTEL, 0x1f22), board_ahci }, /* Avoton AHCI */
  297. { PCI_VDEVICE(INTEL, 0x1f23), board_ahci }, /* Avoton AHCI */
  298. { PCI_VDEVICE(INTEL, 0x1f24), board_ahci }, /* Avoton RAID */
  299. { PCI_VDEVICE(INTEL, 0x1f25), board_ahci }, /* Avoton RAID */
  300. { PCI_VDEVICE(INTEL, 0x1f26), board_ahci }, /* Avoton RAID */
  301. { PCI_VDEVICE(INTEL, 0x1f27), board_ahci }, /* Avoton RAID */
  302. { PCI_VDEVICE(INTEL, 0x1f2e), board_ahci }, /* Avoton RAID */
  303. { PCI_VDEVICE(INTEL, 0x1f2f), board_ahci }, /* Avoton RAID */
  304. { PCI_VDEVICE(INTEL, 0x1f32), board_ahci_avn }, /* Avoton AHCI */
  305. { PCI_VDEVICE(INTEL, 0x1f33), board_ahci_avn }, /* Avoton AHCI */
  306. { PCI_VDEVICE(INTEL, 0x1f34), board_ahci_avn }, /* Avoton RAID */
  307. { PCI_VDEVICE(INTEL, 0x1f35), board_ahci_avn }, /* Avoton RAID */
  308. { PCI_VDEVICE(INTEL, 0x1f36), board_ahci_avn }, /* Avoton RAID */
  309. { PCI_VDEVICE(INTEL, 0x1f37), board_ahci_avn }, /* Avoton RAID */
  310. { PCI_VDEVICE(INTEL, 0x1f3e), board_ahci_avn }, /* Avoton RAID */
  311. { PCI_VDEVICE(INTEL, 0x1f3f), board_ahci_avn }, /* Avoton RAID */
  312. { PCI_VDEVICE(INTEL, 0x8d02), board_ahci }, /* Wellsburg AHCI */
  313. { PCI_VDEVICE(INTEL, 0x8d04), board_ahci }, /* Wellsburg RAID */
  314. { PCI_VDEVICE(INTEL, 0x8d06), board_ahci }, /* Wellsburg RAID */
  315. { PCI_VDEVICE(INTEL, 0x8d0e), board_ahci }, /* Wellsburg RAID */
  316. { PCI_VDEVICE(INTEL, 0x8d62), board_ahci }, /* Wellsburg AHCI */
  317. { PCI_VDEVICE(INTEL, 0x8d64), board_ahci }, /* Wellsburg RAID */
  318. { PCI_VDEVICE(INTEL, 0x8d66), board_ahci }, /* Wellsburg RAID */
  319. { PCI_VDEVICE(INTEL, 0x8d6e), board_ahci }, /* Wellsburg RAID */
  320. { PCI_VDEVICE(INTEL, 0x23a3), board_ahci }, /* Coleto Creek AHCI */
  321. { PCI_VDEVICE(INTEL, 0x9c83), board_ahci }, /* Wildcat Point-LP AHCI */
  322. { PCI_VDEVICE(INTEL, 0x9c85), board_ahci }, /* Wildcat Point-LP RAID */
  323. { PCI_VDEVICE(INTEL, 0x9c87), board_ahci }, /* Wildcat Point-LP RAID */
  324. { PCI_VDEVICE(INTEL, 0x9c8f), board_ahci }, /* Wildcat Point-LP RAID */
  325. { PCI_VDEVICE(INTEL, 0x8c82), board_ahci }, /* 9 Series AHCI */
  326. { PCI_VDEVICE(INTEL, 0x8c83), board_ahci }, /* 9 Series AHCI */
  327. { PCI_VDEVICE(INTEL, 0x8c84), board_ahci }, /* 9 Series RAID */
  328. { PCI_VDEVICE(INTEL, 0x8c85), board_ahci }, /* 9 Series RAID */
  329. { PCI_VDEVICE(INTEL, 0x8c86), board_ahci }, /* 9 Series RAID */
  330. { PCI_VDEVICE(INTEL, 0x8c87), board_ahci }, /* 9 Series RAID */
  331. { PCI_VDEVICE(INTEL, 0x8c8e), board_ahci }, /* 9 Series RAID */
  332. { PCI_VDEVICE(INTEL, 0x8c8f), board_ahci }, /* 9 Series RAID */
  333. { PCI_VDEVICE(INTEL, 0x9d03), board_ahci }, /* Sunrise Point-LP AHCI */
  334. { PCI_VDEVICE(INTEL, 0x9d05), board_ahci }, /* Sunrise Point-LP RAID */
  335. { PCI_VDEVICE(INTEL, 0x9d07), board_ahci }, /* Sunrise Point-LP RAID */
  336. { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H AHCI */
  337. { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H RAID */
  338. { PCI_VDEVICE(INTEL, 0xa105), board_ahci }, /* Sunrise Point-H RAID */
  339. { PCI_VDEVICE(INTEL, 0xa107), board_ahci }, /* Sunrise Point-H RAID */
  340. { PCI_VDEVICE(INTEL, 0xa10f), board_ahci }, /* Sunrise Point-H RAID */
  341. /* JMicron 360/1/3/5/6, match class to avoid IDE function */
  342. { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  343. PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci_ign_iferr },
  344. /* ATI */
  345. { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */
  346. { PCI_VDEVICE(ATI, 0x4390), board_ahci_sb700 }, /* ATI SB700/800 */
  347. { PCI_VDEVICE(ATI, 0x4391), board_ahci_sb700 }, /* ATI SB700/800 */
  348. { PCI_VDEVICE(ATI, 0x4392), board_ahci_sb700 }, /* ATI SB700/800 */
  349. { PCI_VDEVICE(ATI, 0x4393), board_ahci_sb700 }, /* ATI SB700/800 */
  350. { PCI_VDEVICE(ATI, 0x4394), board_ahci_sb700 }, /* ATI SB700/800 */
  351. { PCI_VDEVICE(ATI, 0x4395), board_ahci_sb700 }, /* ATI SB700/800 */
  352. /* AMD */
  353. { PCI_VDEVICE(AMD, 0x7800), board_ahci }, /* AMD Hudson-2 */
  354. { PCI_VDEVICE(AMD, 0x7900), board_ahci }, /* AMD CZ */
  355. /* AMD is using RAID class only for ahci controllers */
  356. { PCI_VENDOR_ID_AMD, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  357. PCI_CLASS_STORAGE_RAID << 8, 0xffffff, board_ahci },
  358. /* VIA */
  359. { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */
  360. { PCI_VDEVICE(VIA, 0x6287), board_ahci_vt8251 }, /* VIA VT8251 */
  361. /* NVIDIA */
  362. { PCI_VDEVICE(NVIDIA, 0x044c), board_ahci_mcp65 }, /* MCP65 */
  363. { PCI_VDEVICE(NVIDIA, 0x044d), board_ahci_mcp65 }, /* MCP65 */
  364. { PCI_VDEVICE(NVIDIA, 0x044e), board_ahci_mcp65 }, /* MCP65 */
  365. { PCI_VDEVICE(NVIDIA, 0x044f), board_ahci_mcp65 }, /* MCP65 */
  366. { PCI_VDEVICE(NVIDIA, 0x045c), board_ahci_mcp65 }, /* MCP65 */
  367. { PCI_VDEVICE(NVIDIA, 0x045d), board_ahci_mcp65 }, /* MCP65 */
  368. { PCI_VDEVICE(NVIDIA, 0x045e), board_ahci_mcp65 }, /* MCP65 */
  369. { PCI_VDEVICE(NVIDIA, 0x045f), board_ahci_mcp65 }, /* MCP65 */
  370. { PCI_VDEVICE(NVIDIA, 0x0550), board_ahci_mcp67 }, /* MCP67 */
  371. { PCI_VDEVICE(NVIDIA, 0x0551), board_ahci_mcp67 }, /* MCP67 */
  372. { PCI_VDEVICE(NVIDIA, 0x0552), board_ahci_mcp67 }, /* MCP67 */
  373. { PCI_VDEVICE(NVIDIA, 0x0553), board_ahci_mcp67 }, /* MCP67 */
  374. { PCI_VDEVICE(NVIDIA, 0x0554), board_ahci_mcp67 }, /* MCP67 */
  375. { PCI_VDEVICE(NVIDIA, 0x0555), board_ahci_mcp67 }, /* MCP67 */
  376. { PCI_VDEVICE(NVIDIA, 0x0556), board_ahci_mcp67 }, /* MCP67 */
  377. { PCI_VDEVICE(NVIDIA, 0x0557), board_ahci_mcp67 }, /* MCP67 */
  378. { PCI_VDEVICE(NVIDIA, 0x0558), board_ahci_mcp67 }, /* MCP67 */
  379. { PCI_VDEVICE(NVIDIA, 0x0559), board_ahci_mcp67 }, /* MCP67 */
  380. { PCI_VDEVICE(NVIDIA, 0x055a), board_ahci_mcp67 }, /* MCP67 */
  381. { PCI_VDEVICE(NVIDIA, 0x055b), board_ahci_mcp67 }, /* MCP67 */
  382. { PCI_VDEVICE(NVIDIA, 0x0580), board_ahci_mcp_linux }, /* Linux ID */
  383. { PCI_VDEVICE(NVIDIA, 0x0581), board_ahci_mcp_linux }, /* Linux ID */
  384. { PCI_VDEVICE(NVIDIA, 0x0582), board_ahci_mcp_linux }, /* Linux ID */
  385. { PCI_VDEVICE(NVIDIA, 0x0583), board_ahci_mcp_linux }, /* Linux ID */
  386. { PCI_VDEVICE(NVIDIA, 0x0584), board_ahci_mcp_linux }, /* Linux ID */
  387. { PCI_VDEVICE(NVIDIA, 0x0585), board_ahci_mcp_linux }, /* Linux ID */
  388. { PCI_VDEVICE(NVIDIA, 0x0586), board_ahci_mcp_linux }, /* Linux ID */
  389. { PCI_VDEVICE(NVIDIA, 0x0587), board_ahci_mcp_linux }, /* Linux ID */
  390. { PCI_VDEVICE(NVIDIA, 0x0588), board_ahci_mcp_linux }, /* Linux ID */
  391. { PCI_VDEVICE(NVIDIA, 0x0589), board_ahci_mcp_linux }, /* Linux ID */
  392. { PCI_VDEVICE(NVIDIA, 0x058a), board_ahci_mcp_linux }, /* Linux ID */
  393. { PCI_VDEVICE(NVIDIA, 0x058b), board_ahci_mcp_linux }, /* Linux ID */
  394. { PCI_VDEVICE(NVIDIA, 0x058c), board_ahci_mcp_linux }, /* Linux ID */
  395. { PCI_VDEVICE(NVIDIA, 0x058d), board_ahci_mcp_linux }, /* Linux ID */
  396. { PCI_VDEVICE(NVIDIA, 0x058e), board_ahci_mcp_linux }, /* Linux ID */
  397. { PCI_VDEVICE(NVIDIA, 0x058f), board_ahci_mcp_linux }, /* Linux ID */
  398. { PCI_VDEVICE(NVIDIA, 0x07f0), board_ahci_mcp73 }, /* MCP73 */
  399. { PCI_VDEVICE(NVIDIA, 0x07f1), board_ahci_mcp73 }, /* MCP73 */
  400. { PCI_VDEVICE(NVIDIA, 0x07f2), board_ahci_mcp73 }, /* MCP73 */
  401. { PCI_VDEVICE(NVIDIA, 0x07f3), board_ahci_mcp73 }, /* MCP73 */
  402. { PCI_VDEVICE(NVIDIA, 0x07f4), board_ahci_mcp73 }, /* MCP73 */
  403. { PCI_VDEVICE(NVIDIA, 0x07f5), board_ahci_mcp73 }, /* MCP73 */
  404. { PCI_VDEVICE(NVIDIA, 0x07f6), board_ahci_mcp73 }, /* MCP73 */
  405. { PCI_VDEVICE(NVIDIA, 0x07f7), board_ahci_mcp73 }, /* MCP73 */
  406. { PCI_VDEVICE(NVIDIA, 0x07f8), board_ahci_mcp73 }, /* MCP73 */
  407. { PCI_VDEVICE(NVIDIA, 0x07f9), board_ahci_mcp73 }, /* MCP73 */
  408. { PCI_VDEVICE(NVIDIA, 0x07fa), board_ahci_mcp73 }, /* MCP73 */
  409. { PCI_VDEVICE(NVIDIA, 0x07fb), board_ahci_mcp73 }, /* MCP73 */
  410. { PCI_VDEVICE(NVIDIA, 0x0ad0), board_ahci_mcp77 }, /* MCP77 */
  411. { PCI_VDEVICE(NVIDIA, 0x0ad1), board_ahci_mcp77 }, /* MCP77 */
  412. { PCI_VDEVICE(NVIDIA, 0x0ad2), board_ahci_mcp77 }, /* MCP77 */
  413. { PCI_VDEVICE(NVIDIA, 0x0ad3), board_ahci_mcp77 }, /* MCP77 */
  414. { PCI_VDEVICE(NVIDIA, 0x0ad4), board_ahci_mcp77 }, /* MCP77 */
  415. { PCI_VDEVICE(NVIDIA, 0x0ad5), board_ahci_mcp77 }, /* MCP77 */
  416. { PCI_VDEVICE(NVIDIA, 0x0ad6), board_ahci_mcp77 }, /* MCP77 */
  417. { PCI_VDEVICE(NVIDIA, 0x0ad7), board_ahci_mcp77 }, /* MCP77 */
  418. { PCI_VDEVICE(NVIDIA, 0x0ad8), board_ahci_mcp77 }, /* MCP77 */
  419. { PCI_VDEVICE(NVIDIA, 0x0ad9), board_ahci_mcp77 }, /* MCP77 */
  420. { PCI_VDEVICE(NVIDIA, 0x0ada), board_ahci_mcp77 }, /* MCP77 */
  421. { PCI_VDEVICE(NVIDIA, 0x0adb), board_ahci_mcp77 }, /* MCP77 */
  422. { PCI_VDEVICE(NVIDIA, 0x0ab4), board_ahci_mcp79 }, /* MCP79 */
  423. { PCI_VDEVICE(NVIDIA, 0x0ab5), board_ahci_mcp79 }, /* MCP79 */
  424. { PCI_VDEVICE(NVIDIA, 0x0ab6), board_ahci_mcp79 }, /* MCP79 */
  425. { PCI_VDEVICE(NVIDIA, 0x0ab7), board_ahci_mcp79 }, /* MCP79 */
  426. { PCI_VDEVICE(NVIDIA, 0x0ab8), board_ahci_mcp79 }, /* MCP79 */
  427. { PCI_VDEVICE(NVIDIA, 0x0ab9), board_ahci_mcp79 }, /* MCP79 */
  428. { PCI_VDEVICE(NVIDIA, 0x0aba), board_ahci_mcp79 }, /* MCP79 */
  429. { PCI_VDEVICE(NVIDIA, 0x0abb), board_ahci_mcp79 }, /* MCP79 */
  430. { PCI_VDEVICE(NVIDIA, 0x0abc), board_ahci_mcp79 }, /* MCP79 */
  431. { PCI_VDEVICE(NVIDIA, 0x0abd), board_ahci_mcp79 }, /* MCP79 */
  432. { PCI_VDEVICE(NVIDIA, 0x0abe), board_ahci_mcp79 }, /* MCP79 */
  433. { PCI_VDEVICE(NVIDIA, 0x0abf), board_ahci_mcp79 }, /* MCP79 */
  434. { PCI_VDEVICE(NVIDIA, 0x0d84), board_ahci_mcp89 }, /* MCP89 */
  435. { PCI_VDEVICE(NVIDIA, 0x0d85), board_ahci_mcp89 }, /* MCP89 */
  436. { PCI_VDEVICE(NVIDIA, 0x0d86), board_ahci_mcp89 }, /* MCP89 */
  437. { PCI_VDEVICE(NVIDIA, 0x0d87), board_ahci_mcp89 }, /* MCP89 */
  438. { PCI_VDEVICE(NVIDIA, 0x0d88), board_ahci_mcp89 }, /* MCP89 */
  439. { PCI_VDEVICE(NVIDIA, 0x0d89), board_ahci_mcp89 }, /* MCP89 */
  440. { PCI_VDEVICE(NVIDIA, 0x0d8a), board_ahci_mcp89 }, /* MCP89 */
  441. { PCI_VDEVICE(NVIDIA, 0x0d8b), board_ahci_mcp89 }, /* MCP89 */
  442. { PCI_VDEVICE(NVIDIA, 0x0d8c), board_ahci_mcp89 }, /* MCP89 */
  443. { PCI_VDEVICE(NVIDIA, 0x0d8d), board_ahci_mcp89 }, /* MCP89 */
  444. { PCI_VDEVICE(NVIDIA, 0x0d8e), board_ahci_mcp89 }, /* MCP89 */
  445. { PCI_VDEVICE(NVIDIA, 0x0d8f), board_ahci_mcp89 }, /* MCP89 */
  446. /* SiS */
  447. { PCI_VDEVICE(SI, 0x1184), board_ahci }, /* SiS 966 */
  448. { PCI_VDEVICE(SI, 0x1185), board_ahci }, /* SiS 968 */
  449. { PCI_VDEVICE(SI, 0x0186), board_ahci }, /* SiS 968 */
  450. /* ST Microelectronics */
  451. { PCI_VDEVICE(STMICRO, 0xCC06), board_ahci }, /* ST ConneXt */
  452. /* Marvell */
  453. { PCI_VDEVICE(MARVELL, 0x6145), board_ahci_mv }, /* 6145 */
  454. { PCI_VDEVICE(MARVELL, 0x6121), board_ahci_mv }, /* 6121 */
  455. { PCI_DEVICE(0x1b4b, 0x9123),
  456. .class = PCI_CLASS_STORAGE_SATA_AHCI,
  457. .class_mask = 0xffffff,
  458. .driver_data = board_ahci_yes_fbs }, /* 88se9128 */
  459. { PCI_DEVICE(0x1b4b, 0x9125),
  460. .driver_data = board_ahci_yes_fbs }, /* 88se9125 */
  461. { PCI_DEVICE(0x1b4b, 0x917a),
  462. .driver_data = board_ahci_yes_fbs }, /* 88se9172 */
  463. { PCI_DEVICE(0x1b4b, 0x9182),
  464. .driver_data = board_ahci_yes_fbs }, /* 88se9182 */
  465. { PCI_DEVICE(0x1b4b, 0x9192),
  466. .driver_data = board_ahci_yes_fbs }, /* 88se9172 on some Gigabyte */
  467. { PCI_DEVICE(0x1b4b, 0x91a3),
  468. .driver_data = board_ahci_yes_fbs },
  469. { PCI_DEVICE(0x1b4b, 0x9230),
  470. .driver_data = board_ahci_yes_fbs },
  471. { PCI_DEVICE(PCI_VENDOR_ID_TTI, 0x0642),
  472. .driver_data = board_ahci_yes_fbs },
  473. /* Promise */
  474. { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci }, /* PDC42819 */
  475. { PCI_VDEVICE(PROMISE, 0x3781), board_ahci }, /* FastTrak TX8660 ahci-mode */
  476. /* Asmedia */
  477. { PCI_VDEVICE(ASMEDIA, 0x0601), board_ahci }, /* ASM1060 */
  478. { PCI_VDEVICE(ASMEDIA, 0x0602), board_ahci }, /* ASM1060 */
  479. { PCI_VDEVICE(ASMEDIA, 0x0611), board_ahci }, /* ASM1061 */
  480. { PCI_VDEVICE(ASMEDIA, 0x0612), board_ahci }, /* ASM1062 */
  481. /*
  482. * Samsung SSDs found on some macbooks. NCQ times out if MSI is
  483. * enabled. https://bugzilla.kernel.org/show_bug.cgi?id=60731
  484. */
  485. { PCI_VDEVICE(SAMSUNG, 0x1600), board_ahci_nomsi },
  486. { PCI_VDEVICE(SAMSUNG, 0xa800), board_ahci_nomsi },
  487. /* Enmotus */
  488. { PCI_DEVICE(0x1c44, 0x8000), board_ahci },
  489. /* Generic, PCI class code for AHCI */
  490. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  491. PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
  492. { } /* terminate list */
  493. };
  494. static struct pci_driver ahci_pci_driver = {
  495. .name = DRV_NAME,
  496. .id_table = ahci_pci_tbl,
  497. .probe = ahci_init_one,
  498. .remove = ata_pci_remove_one,
  499. #ifdef CONFIG_PM
  500. .suspend = ahci_pci_device_suspend,
  501. .resume = ahci_pci_device_resume,
  502. #endif
  503. };
  504. #if defined(CONFIG_PATA_MARVELL) || defined(CONFIG_PATA_MARVELL_MODULE)
  505. static int marvell_enable;
  506. #else
  507. static int marvell_enable = 1;
  508. #endif
  509. module_param(marvell_enable, int, 0644);
  510. MODULE_PARM_DESC(marvell_enable, "Marvell SATA via AHCI (1 = enabled)");
  511. static void ahci_pci_save_initial_config(struct pci_dev *pdev,
  512. struct ahci_host_priv *hpriv)
  513. {
  514. unsigned int force_port_map = 0;
  515. unsigned int mask_port_map = 0;
  516. if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) {
  517. dev_info(&pdev->dev, "JMB361 has only one port\n");
  518. force_port_map = 1;
  519. }
  520. /*
  521. * Temporary Marvell 6145 hack: PATA port presence
  522. * is asserted through the standard AHCI port
  523. * presence register, as bit 4 (counting from 0)
  524. */
  525. if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
  526. if (pdev->device == 0x6121)
  527. mask_port_map = 0x3;
  528. else
  529. mask_port_map = 0xf;
  530. dev_info(&pdev->dev,
  531. "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
  532. }
  533. ahci_save_initial_config(&pdev->dev, hpriv, force_port_map,
  534. mask_port_map);
  535. }
  536. static int ahci_pci_reset_controller(struct ata_host *host)
  537. {
  538. struct pci_dev *pdev = to_pci_dev(host->dev);
  539. ahci_reset_controller(host);
  540. if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
  541. struct ahci_host_priv *hpriv = host->private_data;
  542. u16 tmp16;
  543. /* configure PCS */
  544. pci_read_config_word(pdev, 0x92, &tmp16);
  545. if ((tmp16 & hpriv->port_map) != hpriv->port_map) {
  546. tmp16 |= hpriv->port_map;
  547. pci_write_config_word(pdev, 0x92, tmp16);
  548. }
  549. }
  550. return 0;
  551. }
  552. static void ahci_pci_init_controller(struct ata_host *host)
  553. {
  554. struct ahci_host_priv *hpriv = host->private_data;
  555. struct pci_dev *pdev = to_pci_dev(host->dev);
  556. void __iomem *port_mmio;
  557. u32 tmp;
  558. int mv;
  559. if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
  560. if (pdev->device == 0x6121)
  561. mv = 2;
  562. else
  563. mv = 4;
  564. port_mmio = __ahci_port_base(host, mv);
  565. writel(0, port_mmio + PORT_IRQ_MASK);
  566. /* clear port IRQ */
  567. tmp = readl(port_mmio + PORT_IRQ_STAT);
  568. VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp);
  569. if (tmp)
  570. writel(tmp, port_mmio + PORT_IRQ_STAT);
  571. }
  572. ahci_init_controller(host);
  573. }
  574. static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
  575. unsigned long deadline)
  576. {
  577. struct ata_port *ap = link->ap;
  578. bool online;
  579. int rc;
  580. DPRINTK("ENTER\n");
  581. ahci_stop_engine(ap);
  582. rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
  583. deadline, &online, NULL);
  584. ahci_start_engine(ap);
  585. DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
  586. /* vt8251 doesn't clear BSY on signature FIS reception,
  587. * request follow-up softreset.
  588. */
  589. return online ? -EAGAIN : rc;
  590. }
  591. static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
  592. unsigned long deadline)
  593. {
  594. struct ata_port *ap = link->ap;
  595. struct ahci_port_priv *pp = ap->private_data;
  596. u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
  597. struct ata_taskfile tf;
  598. bool online;
  599. int rc;
  600. ahci_stop_engine(ap);
  601. /* clear D2H reception area to properly wait for D2H FIS */
  602. ata_tf_init(link->device, &tf);
  603. tf.command = 0x80;
  604. ata_tf_to_fis(&tf, 0, 0, d2h_fis);
  605. rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
  606. deadline, &online, NULL);
  607. ahci_start_engine(ap);
  608. /* The pseudo configuration device on SIMG4726 attached to
  609. * ASUS P5W-DH Deluxe doesn't send signature FIS after
  610. * hardreset if no device is attached to the first downstream
  611. * port && the pseudo device locks up on SRST w/ PMP==0. To
  612. * work around this, wait for !BSY only briefly. If BSY isn't
  613. * cleared, perform CLO and proceed to IDENTIFY (achieved by
  614. * ATA_LFLAG_NO_SRST and ATA_LFLAG_ASSUME_ATA).
  615. *
  616. * Wait for two seconds. Devices attached to downstream port
  617. * which can't process the following IDENTIFY after this will
  618. * have to be reset again. For most cases, this should
  619. * suffice while making probing snappish enough.
  620. */
  621. if (online) {
  622. rc = ata_wait_after_reset(link, jiffies + 2 * HZ,
  623. ahci_check_ready);
  624. if (rc)
  625. ahci_kick_engine(ap);
  626. }
  627. return rc;
  628. }
  629. /*
  630. * ahci_avn_hardreset - attempt more aggressive recovery of Avoton ports.
  631. *
  632. * It has been observed with some SSDs that the timing of events in the
  633. * link synchronization phase can leave the port in a state that can not
  634. * be recovered by a SATA-hard-reset alone. The failing signature is
  635. * SStatus.DET stuck at 1 ("Device presence detected but Phy
  636. * communication not established"). It was found that unloading and
  637. * reloading the driver when this problem occurs allows the drive
  638. * connection to be recovered (DET advanced to 0x3). The critical
  639. * component of reloading the driver is that the port state machines are
  640. * reset by bouncing "port enable" in the AHCI PCS configuration
  641. * register. So, reproduce that effect by bouncing a port whenever we
  642. * see DET==1 after a reset.
  643. */
  644. static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
  645. unsigned long deadline)
  646. {
  647. const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
  648. struct ata_port *ap = link->ap;
  649. struct ahci_port_priv *pp = ap->private_data;
  650. u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
  651. unsigned long tmo = deadline - jiffies;
  652. struct ata_taskfile tf;
  653. bool online;
  654. int rc, i;
  655. DPRINTK("ENTER\n");
  656. ahci_stop_engine(ap);
  657. for (i = 0; i < 2; i++) {
  658. u16 val;
  659. u32 sstatus;
  660. int port = ap->port_no;
  661. struct ata_host *host = ap->host;
  662. struct pci_dev *pdev = to_pci_dev(host->dev);
  663. /* clear D2H reception area to properly wait for D2H FIS */
  664. ata_tf_init(link->device, &tf);
  665. tf.command = ATA_BUSY;
  666. ata_tf_to_fis(&tf, 0, 0, d2h_fis);
  667. rc = sata_link_hardreset(link, timing, deadline, &online,
  668. ahci_check_ready);
  669. if (sata_scr_read(link, SCR_STATUS, &sstatus) != 0 ||
  670. (sstatus & 0xf) != 1)
  671. break;
  672. ata_link_printk(link, KERN_INFO, "avn bounce port%d\n",
  673. port);
  674. pci_read_config_word(pdev, 0x92, &val);
  675. val &= ~(1 << port);
  676. pci_write_config_word(pdev, 0x92, val);
  677. ata_msleep(ap, 1000);
  678. val |= 1 << port;
  679. pci_write_config_word(pdev, 0x92, val);
  680. deadline += tmo;
  681. }
  682. ahci_start_engine(ap);
  683. if (online)
  684. *class = ahci_dev_classify(ap);
  685. DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
  686. return rc;
  687. }
  688. #ifdef CONFIG_PM
  689. static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
  690. {
  691. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  692. struct ahci_host_priv *hpriv = host->private_data;
  693. void __iomem *mmio = hpriv->mmio;
  694. u32 ctl;
  695. if (mesg.event & PM_EVENT_SUSPEND &&
  696. hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
  697. dev_err(&pdev->dev,
  698. "BIOS update required for suspend/resume\n");
  699. return -EIO;
  700. }
  701. if (mesg.event & PM_EVENT_SLEEP) {
  702. /* AHCI spec rev1.1 section 8.3.3:
  703. * Software must disable interrupts prior to requesting a
  704. * transition of the HBA to D3 state.
  705. */
  706. ctl = readl(mmio + HOST_CTL);
  707. ctl &= ~HOST_IRQ_EN;
  708. writel(ctl, mmio + HOST_CTL);
  709. readl(mmio + HOST_CTL); /* flush */
  710. }
  711. return ata_pci_device_suspend(pdev, mesg);
  712. }
  713. static int ahci_pci_device_resume(struct pci_dev *pdev)
  714. {
  715. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  716. int rc;
  717. rc = ata_pci_device_do_resume(pdev);
  718. if (rc)
  719. return rc;
  720. if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
  721. rc = ahci_pci_reset_controller(host);
  722. if (rc)
  723. return rc;
  724. ahci_pci_init_controller(host);
  725. }
  726. ata_host_resume(host);
  727. return 0;
  728. }
  729. #endif
  730. static int ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac)
  731. {
  732. int rc;
  733. /*
  734. * If the device fixup already set the dma_mask to some non-standard
  735. * value, don't extend it here. This happens on STA2X11, for example.
  736. */
  737. if (pdev->dma_mask && pdev->dma_mask < DMA_BIT_MASK(32))
  738. return 0;
  739. if (using_dac &&
  740. !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  741. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  742. if (rc) {
  743. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  744. if (rc) {
  745. dev_err(&pdev->dev,
  746. "64-bit DMA enable failed\n");
  747. return rc;
  748. }
  749. }
  750. } else {
  751. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  752. if (rc) {
  753. dev_err(&pdev->dev, "32-bit DMA enable failed\n");
  754. return rc;
  755. }
  756. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  757. if (rc) {
  758. dev_err(&pdev->dev,
  759. "32-bit consistent DMA enable failed\n");
  760. return rc;
  761. }
  762. }
  763. return 0;
  764. }
  765. static void ahci_pci_print_info(struct ata_host *host)
  766. {
  767. struct pci_dev *pdev = to_pci_dev(host->dev);
  768. u16 cc;
  769. const char *scc_s;
  770. pci_read_config_word(pdev, 0x0a, &cc);
  771. if (cc == PCI_CLASS_STORAGE_IDE)
  772. scc_s = "IDE";
  773. else if (cc == PCI_CLASS_STORAGE_SATA)
  774. scc_s = "SATA";
  775. else if (cc == PCI_CLASS_STORAGE_RAID)
  776. scc_s = "RAID";
  777. else
  778. scc_s = "unknown";
  779. ahci_print_info(host, scc_s);
  780. }
  781. /* On ASUS P5W DH Deluxe, the second port of PCI device 00:1f.2 is
  782. * hardwired to on-board SIMG 4726. The chipset is ICH8 and doesn't
  783. * support PMP and the 4726 either directly exports the device
  784. * attached to the first downstream port or acts as a hardware storage
  785. * controller and emulate a single ATA device (can be RAID 0/1 or some
  786. * other configuration).
  787. *
  788. * When there's no device attached to the first downstream port of the
  789. * 4726, "Config Disk" appears, which is a pseudo ATA device to
  790. * configure the 4726. However, ATA emulation of the device is very
  791. * lame. It doesn't send signature D2H Reg FIS after the initial
  792. * hardreset, pukes on SRST w/ PMP==0 and has bunch of other issues.
  793. *
  794. * The following function works around the problem by always using
  795. * hardreset on the port and not depending on receiving signature FIS
  796. * afterward. If signature FIS isn't received soon, ATA class is
  797. * assumed without follow-up softreset.
  798. */
  799. static void ahci_p5wdh_workaround(struct ata_host *host)
  800. {
  801. static struct dmi_system_id sysids[] = {
  802. {
  803. .ident = "P5W DH Deluxe",
  804. .matches = {
  805. DMI_MATCH(DMI_SYS_VENDOR,
  806. "ASUSTEK COMPUTER INC"),
  807. DMI_MATCH(DMI_PRODUCT_NAME, "P5W DH Deluxe"),
  808. },
  809. },
  810. { }
  811. };
  812. struct pci_dev *pdev = to_pci_dev(host->dev);
  813. if (pdev->bus->number == 0 && pdev->devfn == PCI_DEVFN(0x1f, 2) &&
  814. dmi_check_system(sysids)) {
  815. struct ata_port *ap = host->ports[1];
  816. dev_info(&pdev->dev,
  817. "enabling ASUS P5W DH Deluxe on-board SIMG4726 workaround\n");
  818. ap->ops = &ahci_p5wdh_ops;
  819. ap->link.flags |= ATA_LFLAG_NO_SRST | ATA_LFLAG_ASSUME_ATA;
  820. }
  821. }
  822. /* only some SB600 ahci controllers can do 64bit DMA */
  823. static bool ahci_sb600_enable_64bit(struct pci_dev *pdev)
  824. {
  825. static const struct dmi_system_id sysids[] = {
  826. /*
  827. * The oldest version known to be broken is 0901 and
  828. * working is 1501 which was released on 2007-10-26.
  829. * Enable 64bit DMA on 1501 and anything newer.
  830. *
  831. * Please read bko#9412 for more info.
  832. */
  833. {
  834. .ident = "ASUS M2A-VM",
  835. .matches = {
  836. DMI_MATCH(DMI_BOARD_VENDOR,
  837. "ASUSTeK Computer INC."),
  838. DMI_MATCH(DMI_BOARD_NAME, "M2A-VM"),
  839. },
  840. .driver_data = "20071026", /* yyyymmdd */
  841. },
  842. /*
  843. * All BIOS versions for the MSI K9A2 Platinum (MS-7376)
  844. * support 64bit DMA.
  845. *
  846. * BIOS versions earlier than 1.5 had the Manufacturer DMI
  847. * fields as "MICRO-STAR INTERANTIONAL CO.,LTD".
  848. * This spelling mistake was fixed in BIOS version 1.5, so
  849. * 1.5 and later have the Manufacturer as
  850. * "MICRO-STAR INTERNATIONAL CO.,LTD".
  851. * So try to match on DMI_BOARD_VENDOR of "MICRO-STAR INTER".
  852. *
  853. * BIOS versions earlier than 1.9 had a Board Product Name
  854. * DMI field of "MS-7376". This was changed to be
  855. * "K9A2 Platinum (MS-7376)" in version 1.9, but we can still
  856. * match on DMI_BOARD_NAME of "MS-7376".
  857. */
  858. {
  859. .ident = "MSI K9A2 Platinum",
  860. .matches = {
  861. DMI_MATCH(DMI_BOARD_VENDOR,
  862. "MICRO-STAR INTER"),
  863. DMI_MATCH(DMI_BOARD_NAME, "MS-7376"),
  864. },
  865. },
  866. /*
  867. * All BIOS versions for the Asus M3A support 64bit DMA.
  868. * (all release versions from 0301 to 1206 were tested)
  869. */
  870. {
  871. .ident = "ASUS M3A",
  872. .matches = {
  873. DMI_MATCH(DMI_BOARD_VENDOR,
  874. "ASUSTeK Computer INC."),
  875. DMI_MATCH(DMI_BOARD_NAME, "M3A"),
  876. },
  877. },
  878. { }
  879. };
  880. const struct dmi_system_id *match;
  881. int year, month, date;
  882. char buf[9];
  883. match = dmi_first_match(sysids);
  884. if (pdev->bus->number != 0 || pdev->devfn != PCI_DEVFN(0x12, 0) ||
  885. !match)
  886. return false;
  887. if (!match->driver_data)
  888. goto enable_64bit;
  889. dmi_get_date(DMI_BIOS_DATE, &year, &month, &date);
  890. snprintf(buf, sizeof(buf), "%04d%02d%02d", year, month, date);
  891. if (strcmp(buf, match->driver_data) >= 0)
  892. goto enable_64bit;
  893. else {
  894. dev_warn(&pdev->dev,
  895. "%s: BIOS too old, forcing 32bit DMA, update BIOS\n",
  896. match->ident);
  897. return false;
  898. }
  899. enable_64bit:
  900. dev_warn(&pdev->dev, "%s: enabling 64bit DMA\n", match->ident);
  901. return true;
  902. }
  903. static bool ahci_broken_system_poweroff(struct pci_dev *pdev)
  904. {
  905. static const struct dmi_system_id broken_systems[] = {
  906. {
  907. .ident = "HP Compaq nx6310",
  908. .matches = {
  909. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  910. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6310"),
  911. },
  912. /* PCI slot number of the controller */
  913. .driver_data = (void *)0x1FUL,
  914. },
  915. {
  916. .ident = "HP Compaq 6720s",
  917. .matches = {
  918. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  919. DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6720s"),
  920. },
  921. /* PCI slot number of the controller */
  922. .driver_data = (void *)0x1FUL,
  923. },
  924. { } /* terminate list */
  925. };
  926. const struct dmi_system_id *dmi = dmi_first_match(broken_systems);
  927. if (dmi) {
  928. unsigned long slot = (unsigned long)dmi->driver_data;
  929. /* apply the quirk only to on-board controllers */
  930. return slot == PCI_SLOT(pdev->devfn);
  931. }
  932. return false;
  933. }
  934. static bool ahci_broken_suspend(struct pci_dev *pdev)
  935. {
  936. static const struct dmi_system_id sysids[] = {
  937. /*
  938. * On HP dv[4-6] and HDX18 with earlier BIOSen, link
  939. * to the harddisk doesn't become online after
  940. * resuming from STR. Warn and fail suspend.
  941. *
  942. * http://bugzilla.kernel.org/show_bug.cgi?id=12276
  943. *
  944. * Use dates instead of versions to match as HP is
  945. * apparently recycling both product and version
  946. * strings.
  947. *
  948. * http://bugzilla.kernel.org/show_bug.cgi?id=15462
  949. */
  950. {
  951. .ident = "dv4",
  952. .matches = {
  953. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  954. DMI_MATCH(DMI_PRODUCT_NAME,
  955. "HP Pavilion dv4 Notebook PC"),
  956. },
  957. .driver_data = "20090105", /* F.30 */
  958. },
  959. {
  960. .ident = "dv5",
  961. .matches = {
  962. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  963. DMI_MATCH(DMI_PRODUCT_NAME,
  964. "HP Pavilion dv5 Notebook PC"),
  965. },
  966. .driver_data = "20090506", /* F.16 */
  967. },
  968. {
  969. .ident = "dv6",
  970. .matches = {
  971. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  972. DMI_MATCH(DMI_PRODUCT_NAME,
  973. "HP Pavilion dv6 Notebook PC"),
  974. },
  975. .driver_data = "20090423", /* F.21 */
  976. },
  977. {
  978. .ident = "HDX18",
  979. .matches = {
  980. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  981. DMI_MATCH(DMI_PRODUCT_NAME,
  982. "HP HDX18 Notebook PC"),
  983. },
  984. .driver_data = "20090430", /* F.23 */
  985. },
  986. /*
  987. * Acer eMachines G725 has the same problem. BIOS
  988. * V1.03 is known to be broken. V3.04 is known to
  989. * work. Between, there are V1.06, V2.06 and V3.03
  990. * that we don't have much idea about. For now,
  991. * blacklist anything older than V3.04.
  992. *
  993. * http://bugzilla.kernel.org/show_bug.cgi?id=15104
  994. */
  995. {
  996. .ident = "G725",
  997. .matches = {
  998. DMI_MATCH(DMI_SYS_VENDOR, "eMachines"),
  999. DMI_MATCH(DMI_PRODUCT_NAME, "eMachines G725"),
  1000. },
  1001. .driver_data = "20091216", /* V3.04 */
  1002. },
  1003. { } /* terminate list */
  1004. };
  1005. const struct dmi_system_id *dmi = dmi_first_match(sysids);
  1006. int year, month, date;
  1007. char buf[9];
  1008. if (!dmi || pdev->bus->number || pdev->devfn != PCI_DEVFN(0x1f, 2))
  1009. return false;
  1010. dmi_get_date(DMI_BIOS_DATE, &year, &month, &date);
  1011. snprintf(buf, sizeof(buf), "%04d%02d%02d", year, month, date);
  1012. return strcmp(buf, dmi->driver_data) < 0;
  1013. }
  1014. static bool ahci_broken_online(struct pci_dev *pdev)
  1015. {
  1016. #define ENCODE_BUSDEVFN(bus, slot, func) \
  1017. (void *)(unsigned long)(((bus) << 8) | PCI_DEVFN((slot), (func)))
  1018. static const struct dmi_system_id sysids[] = {
  1019. /*
  1020. * There are several gigabyte boards which use
  1021. * SIMG5723s configured as hardware RAID. Certain
  1022. * 5723 firmware revisions shipped there keep the link
  1023. * online but fail to answer properly to SRST or
  1024. * IDENTIFY when no device is attached downstream
  1025. * causing libata to retry quite a few times leading
  1026. * to excessive detection delay.
  1027. *
  1028. * As these firmwares respond to the second reset try
  1029. * with invalid device signature, considering unknown
  1030. * sig as offline works around the problem acceptably.
  1031. */
  1032. {
  1033. .ident = "EP45-DQ6",
  1034. .matches = {
  1035. DMI_MATCH(DMI_BOARD_VENDOR,
  1036. "Gigabyte Technology Co., Ltd."),
  1037. DMI_MATCH(DMI_BOARD_NAME, "EP45-DQ6"),
  1038. },
  1039. .driver_data = ENCODE_BUSDEVFN(0x0a, 0x00, 0),
  1040. },
  1041. {
  1042. .ident = "EP45-DS5",
  1043. .matches = {
  1044. DMI_MATCH(DMI_BOARD_VENDOR,
  1045. "Gigabyte Technology Co., Ltd."),
  1046. DMI_MATCH(DMI_BOARD_NAME, "EP45-DS5"),
  1047. },
  1048. .driver_data = ENCODE_BUSDEVFN(0x03, 0x00, 0),
  1049. },
  1050. { } /* terminate list */
  1051. };
  1052. #undef ENCODE_BUSDEVFN
  1053. const struct dmi_system_id *dmi = dmi_first_match(sysids);
  1054. unsigned int val;
  1055. if (!dmi)
  1056. return false;
  1057. val = (unsigned long)dmi->driver_data;
  1058. return pdev->bus->number == (val >> 8) && pdev->devfn == (val & 0xff);
  1059. }
  1060. #ifdef CONFIG_ATA_ACPI
  1061. static void ahci_gtf_filter_workaround(struct ata_host *host)
  1062. {
  1063. static const struct dmi_system_id sysids[] = {
  1064. /*
  1065. * Aspire 3810T issues a bunch of SATA enable commands
  1066. * via _GTF including an invalid one and one which is
  1067. * rejected by the device. Among the successful ones
  1068. * is FPDMA non-zero offset enable which when enabled
  1069. * only on the drive side leads to NCQ command
  1070. * failures. Filter it out.
  1071. */
  1072. {
  1073. .ident = "Aspire 3810T",
  1074. .matches = {
  1075. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  1076. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3810T"),
  1077. },
  1078. .driver_data = (void *)ATA_ACPI_FILTER_FPDMA_OFFSET,
  1079. },
  1080. { }
  1081. };
  1082. const struct dmi_system_id *dmi = dmi_first_match(sysids);
  1083. unsigned int filter;
  1084. int i;
  1085. if (!dmi)
  1086. return;
  1087. filter = (unsigned long)dmi->driver_data;
  1088. dev_info(host->dev, "applying extra ACPI _GTF filter 0x%x for %s\n",
  1089. filter, dmi->ident);
  1090. for (i = 0; i < host->n_ports; i++) {
  1091. struct ata_port *ap = host->ports[i];
  1092. struct ata_link *link;
  1093. struct ata_device *dev;
  1094. ata_for_each_link(link, ap, EDGE)
  1095. ata_for_each_dev(dev, link, ALL)
  1096. dev->gtf_filter |= filter;
  1097. }
  1098. }
  1099. #else
  1100. static inline void ahci_gtf_filter_workaround(struct ata_host *host)
  1101. {}
  1102. #endif
  1103. static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  1104. {
  1105. unsigned int board_id = ent->driver_data;
  1106. struct ata_port_info pi = ahci_port_info[board_id];
  1107. const struct ata_port_info *ppi[] = { &pi, NULL };
  1108. struct device *dev = &pdev->dev;
  1109. struct ahci_host_priv *hpriv;
  1110. struct ata_host *host;
  1111. int n_ports, i, rc;
  1112. int ahci_pci_bar = AHCI_PCI_BAR_STANDARD;
  1113. VPRINTK("ENTER\n");
  1114. WARN_ON((int)ATA_MAX_QUEUE > AHCI_MAX_CMDS);
  1115. ata_print_version_once(&pdev->dev, DRV_VERSION);
  1116. /* The AHCI driver can only drive the SATA ports, the PATA driver
  1117. can drive them all so if both drivers are selected make sure
  1118. AHCI stays out of the way */
  1119. if (pdev->vendor == PCI_VENDOR_ID_MARVELL && !marvell_enable)
  1120. return -ENODEV;
  1121. /*
  1122. * For some reason, MCP89 on MacBook 7,1 doesn't work with
  1123. * ahci, use ata_generic instead.
  1124. */
  1125. if (pdev->vendor == PCI_VENDOR_ID_NVIDIA &&
  1126. pdev->device == PCI_DEVICE_ID_NVIDIA_NFORCE_MCP89_SATA &&
  1127. pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
  1128. pdev->subsystem_device == 0xcb89)
  1129. return -ENODEV;
  1130. /* Promise's PDC42819 is a SAS/SATA controller that has an AHCI mode.
  1131. * At the moment, we can only use the AHCI mode. Let the users know
  1132. * that for SAS drives they're out of luck.
  1133. */
  1134. if (pdev->vendor == PCI_VENDOR_ID_PROMISE)
  1135. dev_info(&pdev->dev,
  1136. "PDC42819 can only drive SATA devices with this driver\n");
  1137. /* Both Connext and Enmotus devices use non-standard BARs */
  1138. if (pdev->vendor == PCI_VENDOR_ID_STMICRO && pdev->device == 0xCC06)
  1139. ahci_pci_bar = AHCI_PCI_BAR_STA2X11;
  1140. else if (pdev->vendor == 0x1c44 && pdev->device == 0x8000)
  1141. ahci_pci_bar = AHCI_PCI_BAR_ENMOTUS;
  1142. /* acquire resources */
  1143. rc = pcim_enable_device(pdev);
  1144. if (rc)
  1145. return rc;
  1146. /* AHCI controllers often implement SFF compatible interface.
  1147. * Grab all PCI BARs just in case.
  1148. */
  1149. rc = pcim_iomap_regions_request_all(pdev, 1 << ahci_pci_bar, DRV_NAME);
  1150. if (rc == -EBUSY)
  1151. pcim_pin_device(pdev);
  1152. if (rc)
  1153. return rc;
  1154. if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
  1155. (pdev->device == 0x2652 || pdev->device == 0x2653)) {
  1156. u8 map;
  1157. /* ICH6s share the same PCI ID for both piix and ahci
  1158. * modes. Enabling ahci mode while MAP indicates
  1159. * combined mode is a bad idea. Yield to ata_piix.
  1160. */
  1161. pci_read_config_byte(pdev, ICH_MAP, &map);
  1162. if (map & 0x3) {
  1163. dev_info(&pdev->dev,
  1164. "controller is in combined mode, can't enable AHCI mode\n");
  1165. return -ENODEV;
  1166. }
  1167. }
  1168. hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
  1169. if (!hpriv)
  1170. return -ENOMEM;
  1171. hpriv->flags |= (unsigned long)pi.private_data;
  1172. /* MCP65 revision A1 and A2 can't do MSI */
  1173. if (board_id == board_ahci_mcp65 &&
  1174. (pdev->revision == 0xa1 || pdev->revision == 0xa2))
  1175. hpriv->flags |= AHCI_HFLAG_NO_MSI;
  1176. /* SB800 does NOT need the workaround to ignore SERR_INTERNAL */
  1177. if (board_id == board_ahci_sb700 && pdev->revision >= 0x40)
  1178. hpriv->flags &= ~AHCI_HFLAG_IGN_SERR_INTERNAL;
  1179. /* only some SB600s can do 64bit DMA */
  1180. if (ahci_sb600_enable_64bit(pdev))
  1181. hpriv->flags &= ~AHCI_HFLAG_32BIT_ONLY;
  1182. if ((hpriv->flags & AHCI_HFLAG_NO_MSI) || pci_enable_msi(pdev))
  1183. pci_intx(pdev, 1);
  1184. hpriv->mmio = pcim_iomap_table(pdev)[ahci_pci_bar];
  1185. /* save initial config */
  1186. ahci_pci_save_initial_config(pdev, hpriv);
  1187. /* prepare host */
  1188. if (hpriv->cap & HOST_CAP_NCQ) {
  1189. pi.flags |= ATA_FLAG_NCQ;
  1190. /*
  1191. * Auto-activate optimization is supposed to be
  1192. * supported on all AHCI controllers indicating NCQ
  1193. * capability, but it seems to be broken on some
  1194. * chipsets including NVIDIAs.
  1195. */
  1196. if (!(hpriv->flags & AHCI_HFLAG_NO_FPDMA_AA))
  1197. pi.flags |= ATA_FLAG_FPDMA_AA;
  1198. }
  1199. if (hpriv->cap & HOST_CAP_PMP)
  1200. pi.flags |= ATA_FLAG_PMP;
  1201. ahci_set_em_messages(hpriv, &pi);
  1202. if (ahci_broken_system_poweroff(pdev)) {
  1203. pi.flags |= ATA_FLAG_NO_POWEROFF_SPINDOWN;
  1204. dev_info(&pdev->dev,
  1205. "quirky BIOS, skipping spindown on poweroff\n");
  1206. }
  1207. if (ahci_broken_suspend(pdev)) {
  1208. hpriv->flags |= AHCI_HFLAG_NO_SUSPEND;
  1209. dev_warn(&pdev->dev,
  1210. "BIOS update required for suspend/resume\n");
  1211. }
  1212. if (ahci_broken_online(pdev)) {
  1213. hpriv->flags |= AHCI_HFLAG_SRST_TOUT_IS_OFFLINE;
  1214. dev_info(&pdev->dev,
  1215. "online status unreliable, applying workaround\n");
  1216. }
  1217. /* CAP.NP sometimes indicate the index of the last enabled
  1218. * port, at other times, that of the last possible port, so
  1219. * determining the maximum port number requires looking at
  1220. * both CAP.NP and port_map.
  1221. */
  1222. n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
  1223. host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
  1224. if (!host)
  1225. return -ENOMEM;
  1226. host->private_data = hpriv;
  1227. if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
  1228. host->flags |= ATA_HOST_PARALLEL_SCAN;
  1229. else
  1230. printk(KERN_INFO "ahci: SSS flag set, parallel bus scan disabled\n");
  1231. if (pi.flags & ATA_FLAG_EM)
  1232. ahci_reset_em(host);
  1233. for (i = 0; i < host->n_ports; i++) {
  1234. struct ata_port *ap = host->ports[i];
  1235. ata_port_pbar_desc(ap, ahci_pci_bar, -1, "abar");
  1236. ata_port_pbar_desc(ap, ahci_pci_bar,
  1237. 0x100 + ap->port_no * 0x80, "port");
  1238. /* set enclosure management message type */
  1239. if (ap->flags & ATA_FLAG_EM)
  1240. ap->em_message_type = hpriv->em_msg_type;
  1241. /* disabled/not-implemented port */
  1242. if (!(hpriv->port_map & (1 << i)))
  1243. ap->ops = &ata_dummy_port_ops;
  1244. }
  1245. /* apply workaround for ASUS P5W DH Deluxe mainboard */
  1246. ahci_p5wdh_workaround(host);
  1247. /* apply gtf filter quirk */
  1248. ahci_gtf_filter_workaround(host);
  1249. /* initialize adapter */
  1250. rc = ahci_configure_dma_masks(pdev, hpriv->cap & HOST_CAP_64);
  1251. if (rc)
  1252. return rc;
  1253. rc = ahci_pci_reset_controller(host);
  1254. if (rc)
  1255. return rc;
  1256. ahci_pci_init_controller(host);
  1257. ahci_pci_print_info(host);
  1258. pci_set_master(pdev);
  1259. return ata_host_activate(host, pdev->irq, ahci_interrupt, IRQF_SHARED,
  1260. &ahci_sht);
  1261. }
  1262. static int __init ahci_init(void)
  1263. {
  1264. return pci_register_driver(&ahci_pci_driver);
  1265. }
  1266. static void __exit ahci_exit(void)
  1267. {
  1268. pci_unregister_driver(&ahci_pci_driver);
  1269. }
  1270. MODULE_AUTHOR("Jeff Garzik");
  1271. MODULE_DESCRIPTION("AHCI SATA low-level driver");
  1272. MODULE_LICENSE("GPL");
  1273. MODULE_DEVICE_TABLE(pci, ahci_pci_tbl);
  1274. MODULE_VERSION(DRV_VERSION);
  1275. module_init(ahci_init);
  1276. module_exit(ahci_exit);