ahci.c 38 KB

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