ahci.c 39 KB

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