sata_promise.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. /*
  2. * sata_promise.c - Promise SATA
  3. *
  4. * Maintained by: Jeff Garzik <jgarzik@pobox.com>
  5. * Mikael Pettersson <mikpe@it.uu.se>
  6. * Please ALWAYS copy linux-ide@vger.kernel.org
  7. * on emails.
  8. *
  9. * Copyright 2003-2004 Red Hat, Inc.
  10. *
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2, or (at your option)
  15. * any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; see the file COPYING. If not, write to
  24. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25. *
  26. *
  27. * libata documentation is available via 'make {ps|pdf}docs',
  28. * as Documentation/DocBook/libata.*
  29. *
  30. * Hardware information only available under NDA.
  31. *
  32. */
  33. #include <linux/kernel.h>
  34. #include <linux/module.h>
  35. #include <linux/pci.h>
  36. #include <linux/init.h>
  37. #include <linux/blkdev.h>
  38. #include <linux/delay.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/device.h>
  41. #include <scsi/scsi.h>
  42. #include <scsi/scsi_host.h>
  43. #include <scsi/scsi_cmnd.h>
  44. #include <linux/libata.h>
  45. #include "sata_promise.h"
  46. #define DRV_NAME "sata_promise"
  47. #define DRV_VERSION "2.12"
  48. enum {
  49. PDC_MAX_PORTS = 4,
  50. PDC_MMIO_BAR = 3,
  51. PDC_MAX_PRD = LIBATA_MAX_PRD - 1, /* -1 for ASIC PRD bug workaround */
  52. /* host register offsets (from host->iomap[PDC_MMIO_BAR]) */
  53. PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
  54. PDC_FLASH_CTL = 0x44, /* Flash control register */
  55. PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */
  56. PDC2_SATA_PLUG_CSR = 0x60, /* SATAII Plug control/status reg */
  57. PDC_TBG_MODE = 0x41C, /* TBG mode (not SATAII) */
  58. PDC_SLEW_CTL = 0x470, /* slew rate control reg (not SATAII) */
  59. /* per-port ATA register offsets (from ap->ioaddr.cmd_addr) */
  60. PDC_FEATURE = 0x04, /* Feature/Error reg (per port) */
  61. PDC_SECTOR_COUNT = 0x08, /* Sector count reg (per port) */
  62. PDC_SECTOR_NUMBER = 0x0C, /* Sector number reg (per port) */
  63. PDC_CYLINDER_LOW = 0x10, /* Cylinder low reg (per port) */
  64. PDC_CYLINDER_HIGH = 0x14, /* Cylinder high reg (per port) */
  65. PDC_DEVICE = 0x18, /* Device/Head reg (per port) */
  66. PDC_COMMAND = 0x1C, /* Command/status reg (per port) */
  67. PDC_ALTSTATUS = 0x38, /* Alternate-status/device-control reg (per port) */
  68. PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
  69. PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */
  70. PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */
  71. /* per-port SATA register offsets (from ap->ioaddr.scr_addr) */
  72. PDC_PHYMODE4 = 0x14,
  73. /* PDC_GLOBAL_CTL bit definitions */
  74. PDC_PH_ERR = (1 << 8), /* PCI error while loading packet */
  75. PDC_SH_ERR = (1 << 9), /* PCI error while loading S/G table */
  76. PDC_DH_ERR = (1 << 10), /* PCI error while loading data */
  77. PDC2_HTO_ERR = (1 << 12), /* host bus timeout */
  78. PDC2_ATA_HBA_ERR = (1 << 13), /* error during SATA DATA FIS transmission */
  79. PDC2_ATA_DMA_CNT_ERR = (1 << 14), /* DMA DATA FIS size differs from S/G count */
  80. PDC_OVERRUN_ERR = (1 << 19), /* S/G byte count larger than HD requires */
  81. PDC_UNDERRUN_ERR = (1 << 20), /* S/G byte count less than HD requires */
  82. PDC_DRIVE_ERR = (1 << 21), /* drive error */
  83. PDC_PCI_SYS_ERR = (1 << 22), /* PCI system error */
  84. PDC1_PCI_PARITY_ERR = (1 << 23), /* PCI parity error (from SATA150 driver) */
  85. PDC1_ERR_MASK = PDC1_PCI_PARITY_ERR,
  86. PDC2_ERR_MASK = PDC2_HTO_ERR | PDC2_ATA_HBA_ERR |
  87. PDC2_ATA_DMA_CNT_ERR,
  88. PDC_ERR_MASK = PDC_PH_ERR | PDC_SH_ERR | PDC_DH_ERR |
  89. PDC_OVERRUN_ERR | PDC_UNDERRUN_ERR |
  90. PDC_DRIVE_ERR | PDC_PCI_SYS_ERR |
  91. PDC1_ERR_MASK | PDC2_ERR_MASK,
  92. board_2037x = 0, /* FastTrak S150 TX2plus */
  93. board_2037x_pata = 1, /* FastTrak S150 TX2plus PATA port */
  94. board_20319 = 2, /* FastTrak S150 TX4 */
  95. board_20619 = 3, /* FastTrak TX4000 */
  96. board_2057x = 4, /* SATAII150 Tx2plus */
  97. board_2057x_pata = 5, /* SATAII150 Tx2plus PATA port */
  98. board_40518 = 6, /* SATAII150 Tx4 */
  99. PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */
  100. /* Sequence counter control registers bit definitions */
  101. PDC_SEQCNTRL_INT_MASK = (1 << 5), /* Sequence Interrupt Mask */
  102. /* Feature register values */
  103. PDC_FEATURE_ATAPI_PIO = 0x00, /* ATAPI data xfer by PIO */
  104. PDC_FEATURE_ATAPI_DMA = 0x01, /* ATAPI data xfer by DMA */
  105. /* Device/Head register values */
  106. PDC_DEVICE_SATA = 0xE0, /* Device/Head value for SATA devices */
  107. /* PDC_CTLSTAT bit definitions */
  108. PDC_DMA_ENABLE = (1 << 7),
  109. PDC_IRQ_DISABLE = (1 << 10),
  110. PDC_RESET = (1 << 11), /* HDMA reset */
  111. PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY |
  112. ATA_FLAG_MMIO |
  113. ATA_FLAG_PIO_POLLING,
  114. /* ap->flags bits */
  115. PDC_FLAG_GEN_II = (1 << 24),
  116. PDC_FLAG_SATA_PATA = (1 << 25), /* supports SATA + PATA */
  117. PDC_FLAG_4_PORTS = (1 << 26), /* 4 ports */
  118. };
  119. struct pdc_port_priv {
  120. u8 *pkt;
  121. dma_addr_t pkt_dma;
  122. };
  123. static int pdc_sata_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
  124. static int pdc_sata_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
  125. static int pdc_ata_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
  126. static int pdc_common_port_start(struct ata_port *ap);
  127. static int pdc_sata_port_start(struct ata_port *ap);
  128. static void pdc_qc_prep(struct ata_queued_cmd *qc);
  129. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  130. static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  131. static int pdc_check_atapi_dma(struct ata_queued_cmd *qc);
  132. static int pdc_old_sata_check_atapi_dma(struct ata_queued_cmd *qc);
  133. static void pdc_irq_clear(struct ata_port *ap);
  134. static unsigned int pdc_qc_issue(struct ata_queued_cmd *qc);
  135. static void pdc_freeze(struct ata_port *ap);
  136. static void pdc_sata_freeze(struct ata_port *ap);
  137. static void pdc_thaw(struct ata_port *ap);
  138. static void pdc_sata_thaw(struct ata_port *ap);
  139. static int pdc_pata_softreset(struct ata_link *link, unsigned int *class,
  140. unsigned long deadline);
  141. static int pdc_sata_hardreset(struct ata_link *link, unsigned int *class,
  142. unsigned long deadline);
  143. static void pdc_error_handler(struct ata_port *ap);
  144. static void pdc_post_internal_cmd(struct ata_queued_cmd *qc);
  145. static int pdc_pata_cable_detect(struct ata_port *ap);
  146. static int pdc_sata_cable_detect(struct ata_port *ap);
  147. static struct scsi_host_template pdc_ata_sht = {
  148. ATA_BASE_SHT(DRV_NAME),
  149. .sg_tablesize = PDC_MAX_PRD,
  150. .dma_boundary = ATA_DMA_BOUNDARY,
  151. };
  152. static const struct ata_port_operations pdc_common_ops = {
  153. .inherits = &ata_sff_port_ops,
  154. .sff_tf_load = pdc_tf_load_mmio,
  155. .sff_exec_command = pdc_exec_command_mmio,
  156. .check_atapi_dma = pdc_check_atapi_dma,
  157. .qc_prep = pdc_qc_prep,
  158. .qc_issue = pdc_qc_issue,
  159. .sff_irq_clear = pdc_irq_clear,
  160. .post_internal_cmd = pdc_post_internal_cmd,
  161. .error_handler = pdc_error_handler,
  162. };
  163. static struct ata_port_operations pdc_sata_ops = {
  164. .inherits = &pdc_common_ops,
  165. .cable_detect = pdc_sata_cable_detect,
  166. .freeze = pdc_sata_freeze,
  167. .thaw = pdc_sata_thaw,
  168. .scr_read = pdc_sata_scr_read,
  169. .scr_write = pdc_sata_scr_write,
  170. .port_start = pdc_sata_port_start,
  171. .hardreset = pdc_sata_hardreset,
  172. };
  173. /* First-generation chips need a more restrictive ->check_atapi_dma op */
  174. static struct ata_port_operations pdc_old_sata_ops = {
  175. .inherits = &pdc_sata_ops,
  176. .check_atapi_dma = pdc_old_sata_check_atapi_dma,
  177. };
  178. static struct ata_port_operations pdc_pata_ops = {
  179. .inherits = &pdc_common_ops,
  180. .cable_detect = pdc_pata_cable_detect,
  181. .freeze = pdc_freeze,
  182. .thaw = pdc_thaw,
  183. .port_start = pdc_common_port_start,
  184. .softreset = pdc_pata_softreset,
  185. };
  186. static const struct ata_port_info pdc_port_info[] = {
  187. [board_2037x] =
  188. {
  189. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  190. PDC_FLAG_SATA_PATA,
  191. .pio_mask = 0x1f, /* pio0-4 */
  192. .mwdma_mask = 0x07, /* mwdma0-2 */
  193. .udma_mask = ATA_UDMA6,
  194. .port_ops = &pdc_old_sata_ops,
  195. },
  196. [board_2037x_pata] =
  197. {
  198. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS,
  199. .pio_mask = 0x1f, /* pio0-4 */
  200. .mwdma_mask = 0x07, /* mwdma0-2 */
  201. .udma_mask = ATA_UDMA6,
  202. .port_ops = &pdc_pata_ops,
  203. },
  204. [board_20319] =
  205. {
  206. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  207. PDC_FLAG_4_PORTS,
  208. .pio_mask = 0x1f, /* pio0-4 */
  209. .mwdma_mask = 0x07, /* mwdma0-2 */
  210. .udma_mask = ATA_UDMA6,
  211. .port_ops = &pdc_old_sata_ops,
  212. },
  213. [board_20619] =
  214. {
  215. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS |
  216. PDC_FLAG_4_PORTS,
  217. .pio_mask = 0x1f, /* pio0-4 */
  218. .mwdma_mask = 0x07, /* mwdma0-2 */
  219. .udma_mask = ATA_UDMA6,
  220. .port_ops = &pdc_pata_ops,
  221. },
  222. [board_2057x] =
  223. {
  224. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  225. PDC_FLAG_GEN_II | PDC_FLAG_SATA_PATA,
  226. .pio_mask = 0x1f, /* pio0-4 */
  227. .mwdma_mask = 0x07, /* mwdma0-2 */
  228. .udma_mask = ATA_UDMA6,
  229. .port_ops = &pdc_sata_ops,
  230. },
  231. [board_2057x_pata] =
  232. {
  233. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS |
  234. PDC_FLAG_GEN_II,
  235. .pio_mask = 0x1f, /* pio0-4 */
  236. .mwdma_mask = 0x07, /* mwdma0-2 */
  237. .udma_mask = ATA_UDMA6,
  238. .port_ops = &pdc_pata_ops,
  239. },
  240. [board_40518] =
  241. {
  242. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  243. PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS,
  244. .pio_mask = 0x1f, /* pio0-4 */
  245. .mwdma_mask = 0x07, /* mwdma0-2 */
  246. .udma_mask = ATA_UDMA6,
  247. .port_ops = &pdc_sata_ops,
  248. },
  249. };
  250. static const struct pci_device_id pdc_ata_pci_tbl[] = {
  251. { PCI_VDEVICE(PROMISE, 0x3371), board_2037x },
  252. { PCI_VDEVICE(PROMISE, 0x3373), board_2037x },
  253. { PCI_VDEVICE(PROMISE, 0x3375), board_2037x },
  254. { PCI_VDEVICE(PROMISE, 0x3376), board_2037x },
  255. { PCI_VDEVICE(PROMISE, 0x3570), board_2057x },
  256. { PCI_VDEVICE(PROMISE, 0x3571), board_2057x },
  257. { PCI_VDEVICE(PROMISE, 0x3574), board_2057x },
  258. { PCI_VDEVICE(PROMISE, 0x3577), board_2057x },
  259. { PCI_VDEVICE(PROMISE, 0x3d73), board_2057x },
  260. { PCI_VDEVICE(PROMISE, 0x3d75), board_2057x },
  261. { PCI_VDEVICE(PROMISE, 0x3318), board_20319 },
  262. { PCI_VDEVICE(PROMISE, 0x3319), board_20319 },
  263. { PCI_VDEVICE(PROMISE, 0x3515), board_40518 },
  264. { PCI_VDEVICE(PROMISE, 0x3519), board_40518 },
  265. { PCI_VDEVICE(PROMISE, 0x3d17), board_40518 },
  266. { PCI_VDEVICE(PROMISE, 0x3d18), board_40518 },
  267. { PCI_VDEVICE(PROMISE, 0x6629), board_20619 },
  268. { } /* terminate list */
  269. };
  270. static struct pci_driver pdc_ata_pci_driver = {
  271. .name = DRV_NAME,
  272. .id_table = pdc_ata_pci_tbl,
  273. .probe = pdc_ata_init_one,
  274. .remove = ata_pci_remove_one,
  275. };
  276. static int pdc_common_port_start(struct ata_port *ap)
  277. {
  278. struct device *dev = ap->host->dev;
  279. struct pdc_port_priv *pp;
  280. int rc;
  281. rc = ata_port_start(ap);
  282. if (rc)
  283. return rc;
  284. pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
  285. if (!pp)
  286. return -ENOMEM;
  287. pp->pkt = dmam_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  288. if (!pp->pkt)
  289. return -ENOMEM;
  290. ap->private_data = pp;
  291. return 0;
  292. }
  293. static int pdc_sata_port_start(struct ata_port *ap)
  294. {
  295. int rc;
  296. rc = pdc_common_port_start(ap);
  297. if (rc)
  298. return rc;
  299. /* fix up PHYMODE4 align timing */
  300. if (ap->flags & PDC_FLAG_GEN_II) {
  301. void __iomem *sata_mmio = ap->ioaddr.scr_addr;
  302. unsigned int tmp;
  303. tmp = readl(sata_mmio + PDC_PHYMODE4);
  304. tmp = (tmp & ~3) | 1; /* set bits 1:0 = 0:1 */
  305. writel(tmp, sata_mmio + PDC_PHYMODE4);
  306. }
  307. return 0;
  308. }
  309. static void pdc_reset_port(struct ata_port *ap)
  310. {
  311. void __iomem *ata_ctlstat_mmio = ap->ioaddr.cmd_addr + PDC_CTLSTAT;
  312. unsigned int i;
  313. u32 tmp;
  314. for (i = 11; i > 0; i--) {
  315. tmp = readl(ata_ctlstat_mmio);
  316. if (tmp & PDC_RESET)
  317. break;
  318. udelay(100);
  319. tmp |= PDC_RESET;
  320. writel(tmp, ata_ctlstat_mmio);
  321. }
  322. tmp &= ~PDC_RESET;
  323. writel(tmp, ata_ctlstat_mmio);
  324. readl(ata_ctlstat_mmio); /* flush */
  325. }
  326. static int pdc_pata_cable_detect(struct ata_port *ap)
  327. {
  328. u8 tmp;
  329. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  330. tmp = readb(ata_mmio + PDC_CTLSTAT + 3);
  331. if (tmp & 0x01)
  332. return ATA_CBL_PATA40;
  333. return ATA_CBL_PATA80;
  334. }
  335. static int pdc_sata_cable_detect(struct ata_port *ap)
  336. {
  337. return ATA_CBL_SATA;
  338. }
  339. static int pdc_sata_scr_read(struct ata_link *link,
  340. unsigned int sc_reg, u32 *val)
  341. {
  342. if (sc_reg > SCR_CONTROL)
  343. return -EINVAL;
  344. *val = readl(link->ap->ioaddr.scr_addr + (sc_reg * 4));
  345. return 0;
  346. }
  347. static int pdc_sata_scr_write(struct ata_link *link,
  348. unsigned int sc_reg, u32 val)
  349. {
  350. if (sc_reg > SCR_CONTROL)
  351. return -EINVAL;
  352. writel(val, link->ap->ioaddr.scr_addr + (sc_reg * 4));
  353. return 0;
  354. }
  355. static void pdc_atapi_pkt(struct ata_queued_cmd *qc)
  356. {
  357. struct ata_port *ap = qc->ap;
  358. dma_addr_t sg_table = ap->prd_dma;
  359. unsigned int cdb_len = qc->dev->cdb_len;
  360. u8 *cdb = qc->cdb;
  361. struct pdc_port_priv *pp = ap->private_data;
  362. u8 *buf = pp->pkt;
  363. __le32 *buf32 = (__le32 *) buf;
  364. unsigned int dev_sel, feature;
  365. /* set control bits (byte 0), zero delay seq id (byte 3),
  366. * and seq id (byte 2)
  367. */
  368. switch (qc->tf.protocol) {
  369. case ATAPI_PROT_DMA:
  370. if (!(qc->tf.flags & ATA_TFLAG_WRITE))
  371. buf32[0] = cpu_to_le32(PDC_PKT_READ);
  372. else
  373. buf32[0] = 0;
  374. break;
  375. case ATAPI_PROT_NODATA:
  376. buf32[0] = cpu_to_le32(PDC_PKT_NODATA);
  377. break;
  378. default:
  379. BUG();
  380. break;
  381. }
  382. buf32[1] = cpu_to_le32(sg_table); /* S/G table addr */
  383. buf32[2] = 0; /* no next-packet */
  384. /* select drive */
  385. if (sata_scr_valid(&ap->link))
  386. dev_sel = PDC_DEVICE_SATA;
  387. else
  388. dev_sel = qc->tf.device;
  389. buf[12] = (1 << 5) | ATA_REG_DEVICE;
  390. buf[13] = dev_sel;
  391. buf[14] = (1 << 5) | ATA_REG_DEVICE | PDC_PKT_CLEAR_BSY;
  392. buf[15] = dev_sel; /* once more, waiting for BSY to clear */
  393. buf[16] = (1 << 5) | ATA_REG_NSECT;
  394. buf[17] = qc->tf.nsect;
  395. buf[18] = (1 << 5) | ATA_REG_LBAL;
  396. buf[19] = qc->tf.lbal;
  397. /* set feature and byte counter registers */
  398. if (qc->tf.protocol != ATAPI_PROT_DMA)
  399. feature = PDC_FEATURE_ATAPI_PIO;
  400. else
  401. feature = PDC_FEATURE_ATAPI_DMA;
  402. buf[20] = (1 << 5) | ATA_REG_FEATURE;
  403. buf[21] = feature;
  404. buf[22] = (1 << 5) | ATA_REG_BYTEL;
  405. buf[23] = qc->tf.lbam;
  406. buf[24] = (1 << 5) | ATA_REG_BYTEH;
  407. buf[25] = qc->tf.lbah;
  408. /* send ATAPI packet command 0xA0 */
  409. buf[26] = (1 << 5) | ATA_REG_CMD;
  410. buf[27] = qc->tf.command;
  411. /* select drive and check DRQ */
  412. buf[28] = (1 << 5) | ATA_REG_DEVICE | PDC_PKT_WAIT_DRDY;
  413. buf[29] = dev_sel;
  414. /* we can represent cdb lengths 2/4/6/8/10/12/14/16 */
  415. BUG_ON(cdb_len & ~0x1E);
  416. /* append the CDB as the final part */
  417. buf[30] = (((cdb_len >> 1) & 7) << 5) | ATA_REG_DATA | PDC_LAST_REG;
  418. memcpy(buf+31, cdb, cdb_len);
  419. }
  420. /**
  421. * pdc_fill_sg - Fill PCI IDE PRD table
  422. * @qc: Metadata associated with taskfile to be transferred
  423. *
  424. * Fill PCI IDE PRD (scatter-gather) table with segments
  425. * associated with the current disk command.
  426. * Make sure hardware does not choke on it.
  427. *
  428. * LOCKING:
  429. * spin_lock_irqsave(host lock)
  430. *
  431. */
  432. static void pdc_fill_sg(struct ata_queued_cmd *qc)
  433. {
  434. struct ata_port *ap = qc->ap;
  435. struct scatterlist *sg;
  436. const u32 SG_COUNT_ASIC_BUG = 41*4;
  437. unsigned int si, idx;
  438. u32 len;
  439. if (!(qc->flags & ATA_QCFLAG_DMAMAP))
  440. return;
  441. idx = 0;
  442. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  443. u32 addr, offset;
  444. u32 sg_len;
  445. /* determine if physical DMA addr spans 64K boundary.
  446. * Note h/w doesn't support 64-bit, so we unconditionally
  447. * truncate dma_addr_t to u32.
  448. */
  449. addr = (u32) sg_dma_address(sg);
  450. sg_len = sg_dma_len(sg);
  451. while (sg_len) {
  452. offset = addr & 0xffff;
  453. len = sg_len;
  454. if ((offset + sg_len) > 0x10000)
  455. len = 0x10000 - offset;
  456. ap->prd[idx].addr = cpu_to_le32(addr);
  457. ap->prd[idx].flags_len = cpu_to_le32(len & 0xffff);
  458. VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len);
  459. idx++;
  460. sg_len -= len;
  461. addr += len;
  462. }
  463. }
  464. len = le32_to_cpu(ap->prd[idx - 1].flags_len);
  465. if (len > SG_COUNT_ASIC_BUG) {
  466. u32 addr;
  467. VPRINTK("Splitting last PRD.\n");
  468. addr = le32_to_cpu(ap->prd[idx - 1].addr);
  469. ap->prd[idx - 1].flags_len = cpu_to_le32(len - SG_COUNT_ASIC_BUG);
  470. VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx - 1, addr, SG_COUNT_ASIC_BUG);
  471. addr = addr + len - SG_COUNT_ASIC_BUG;
  472. len = SG_COUNT_ASIC_BUG;
  473. ap->prd[idx].addr = cpu_to_le32(addr);
  474. ap->prd[idx].flags_len = cpu_to_le32(len);
  475. VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len);
  476. idx++;
  477. }
  478. ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
  479. }
  480. static void pdc_qc_prep(struct ata_queued_cmd *qc)
  481. {
  482. struct pdc_port_priv *pp = qc->ap->private_data;
  483. unsigned int i;
  484. VPRINTK("ENTER\n");
  485. switch (qc->tf.protocol) {
  486. case ATA_PROT_DMA:
  487. pdc_fill_sg(qc);
  488. /*FALLTHROUGH*/
  489. case ATA_PROT_NODATA:
  490. i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
  491. qc->dev->devno, pp->pkt);
  492. if (qc->tf.flags & ATA_TFLAG_LBA48)
  493. i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
  494. else
  495. i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
  496. pdc_pkt_footer(&qc->tf, pp->pkt, i);
  497. break;
  498. case ATAPI_PROT_PIO:
  499. pdc_fill_sg(qc);
  500. break;
  501. case ATAPI_PROT_DMA:
  502. pdc_fill_sg(qc);
  503. /*FALLTHROUGH*/
  504. case ATAPI_PROT_NODATA:
  505. pdc_atapi_pkt(qc);
  506. break;
  507. default:
  508. break;
  509. }
  510. }
  511. static int pdc_is_sataii_tx4(unsigned long flags)
  512. {
  513. const unsigned long mask = PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS;
  514. return (flags & mask) == mask;
  515. }
  516. static unsigned int pdc_port_no_to_ata_no(unsigned int port_no,
  517. int is_sataii_tx4)
  518. {
  519. static const unsigned char sataii_tx4_port_remap[4] = { 3, 1, 0, 2};
  520. return is_sataii_tx4 ? sataii_tx4_port_remap[port_no] : port_no;
  521. }
  522. static unsigned int pdc_sata_nr_ports(const struct ata_port *ap)
  523. {
  524. return (ap->flags & PDC_FLAG_4_PORTS) ? 4 : 2;
  525. }
  526. static unsigned int pdc_sata_ata_port_to_ata_no(const struct ata_port *ap)
  527. {
  528. const struct ata_host *host = ap->host;
  529. unsigned int nr_ports = pdc_sata_nr_ports(ap);
  530. unsigned int i;
  531. for (i = 0; i < nr_ports && host->ports[i] != ap; ++i)
  532. ;
  533. BUG_ON(i >= nr_ports);
  534. return pdc_port_no_to_ata_no(i, pdc_is_sataii_tx4(ap->flags));
  535. }
  536. static unsigned int pdc_sata_hotplug_offset(const struct ata_port *ap)
  537. {
  538. return (ap->flags & PDC_FLAG_GEN_II) ? PDC2_SATA_PLUG_CSR : PDC_SATA_PLUG_CSR;
  539. }
  540. static void pdc_freeze(struct ata_port *ap)
  541. {
  542. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  543. u32 tmp;
  544. tmp = readl(ata_mmio + PDC_CTLSTAT);
  545. tmp |= PDC_IRQ_DISABLE;
  546. tmp &= ~PDC_DMA_ENABLE;
  547. writel(tmp, ata_mmio + PDC_CTLSTAT);
  548. readl(ata_mmio + PDC_CTLSTAT); /* flush */
  549. }
  550. static void pdc_sata_freeze(struct ata_port *ap)
  551. {
  552. struct ata_host *host = ap->host;
  553. void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR];
  554. unsigned int hotplug_offset = pdc_sata_hotplug_offset(ap);
  555. unsigned int ata_no = pdc_sata_ata_port_to_ata_no(ap);
  556. u32 hotplug_status;
  557. /* Disable hotplug events on this port.
  558. *
  559. * Locking:
  560. * 1) hotplug register accesses must be serialised via host->lock
  561. * 2) ap->lock == &ap->host->lock
  562. * 3) ->freeze() and ->thaw() are called with ap->lock held
  563. */
  564. hotplug_status = readl(host_mmio + hotplug_offset);
  565. hotplug_status |= 0x11 << (ata_no + 16);
  566. writel(hotplug_status, host_mmio + hotplug_offset);
  567. readl(host_mmio + hotplug_offset); /* flush */
  568. pdc_freeze(ap);
  569. }
  570. static void pdc_thaw(struct ata_port *ap)
  571. {
  572. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  573. u32 tmp;
  574. /* clear IRQ */
  575. readl(ata_mmio + PDC_COMMAND);
  576. /* turn IRQ back on */
  577. tmp = readl(ata_mmio + PDC_CTLSTAT);
  578. tmp &= ~PDC_IRQ_DISABLE;
  579. writel(tmp, ata_mmio + PDC_CTLSTAT);
  580. readl(ata_mmio + PDC_CTLSTAT); /* flush */
  581. }
  582. static void pdc_sata_thaw(struct ata_port *ap)
  583. {
  584. struct ata_host *host = ap->host;
  585. void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR];
  586. unsigned int hotplug_offset = pdc_sata_hotplug_offset(ap);
  587. unsigned int ata_no = pdc_sata_ata_port_to_ata_no(ap);
  588. u32 hotplug_status;
  589. pdc_thaw(ap);
  590. /* Enable hotplug events on this port.
  591. * Locking: see pdc_sata_freeze().
  592. */
  593. hotplug_status = readl(host_mmio + hotplug_offset);
  594. hotplug_status |= 0x11 << ata_no;
  595. hotplug_status &= ~(0x11 << (ata_no + 16));
  596. writel(hotplug_status, host_mmio + hotplug_offset);
  597. readl(host_mmio + hotplug_offset); /* flush */
  598. }
  599. static int pdc_pata_softreset(struct ata_link *link, unsigned int *class,
  600. unsigned long deadline)
  601. {
  602. pdc_reset_port(link->ap);
  603. return ata_sff_softreset(link, class, deadline);
  604. }
  605. static int pdc_sata_hardreset(struct ata_link *link, unsigned int *class,
  606. unsigned long deadline)
  607. {
  608. pdc_reset_port(link->ap);
  609. return sata_sff_hardreset(link, class, deadline);
  610. }
  611. static void pdc_error_handler(struct ata_port *ap)
  612. {
  613. if (!(ap->pflags & ATA_PFLAG_FROZEN))
  614. pdc_reset_port(ap);
  615. ata_std_error_handler(ap);
  616. }
  617. static void pdc_post_internal_cmd(struct ata_queued_cmd *qc)
  618. {
  619. struct ata_port *ap = qc->ap;
  620. /* make DMA engine forget about the failed command */
  621. if (qc->flags & ATA_QCFLAG_FAILED)
  622. pdc_reset_port(ap);
  623. }
  624. static void pdc_error_intr(struct ata_port *ap, struct ata_queued_cmd *qc,
  625. u32 port_status, u32 err_mask)
  626. {
  627. struct ata_eh_info *ehi = &ap->link.eh_info;
  628. unsigned int ac_err_mask = 0;
  629. ata_ehi_clear_desc(ehi);
  630. ata_ehi_push_desc(ehi, "port_status 0x%08x", port_status);
  631. port_status &= err_mask;
  632. if (port_status & PDC_DRIVE_ERR)
  633. ac_err_mask |= AC_ERR_DEV;
  634. if (port_status & (PDC_OVERRUN_ERR | PDC_UNDERRUN_ERR))
  635. ac_err_mask |= AC_ERR_HSM;
  636. if (port_status & (PDC2_ATA_HBA_ERR | PDC2_ATA_DMA_CNT_ERR))
  637. ac_err_mask |= AC_ERR_ATA_BUS;
  638. if (port_status & (PDC_PH_ERR | PDC_SH_ERR | PDC_DH_ERR | PDC2_HTO_ERR
  639. | PDC_PCI_SYS_ERR | PDC1_PCI_PARITY_ERR))
  640. ac_err_mask |= AC_ERR_HOST_BUS;
  641. if (sata_scr_valid(&ap->link)) {
  642. u32 serror;
  643. pdc_sata_scr_read(&ap->link, SCR_ERROR, &serror);
  644. ehi->serror |= serror;
  645. }
  646. qc->err_mask |= ac_err_mask;
  647. pdc_reset_port(ap);
  648. ata_port_abort(ap);
  649. }
  650. static unsigned int pdc_host_intr(struct ata_port *ap,
  651. struct ata_queued_cmd *qc)
  652. {
  653. unsigned int handled = 0;
  654. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  655. u32 port_status, err_mask;
  656. err_mask = PDC_ERR_MASK;
  657. if (ap->flags & PDC_FLAG_GEN_II)
  658. err_mask &= ~PDC1_ERR_MASK;
  659. else
  660. err_mask &= ~PDC2_ERR_MASK;
  661. port_status = readl(ata_mmio + PDC_GLOBAL_CTL);
  662. if (unlikely(port_status & err_mask)) {
  663. pdc_error_intr(ap, qc, port_status, err_mask);
  664. return 1;
  665. }
  666. switch (qc->tf.protocol) {
  667. case ATA_PROT_DMA:
  668. case ATA_PROT_NODATA:
  669. case ATAPI_PROT_DMA:
  670. case ATAPI_PROT_NODATA:
  671. qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
  672. ata_qc_complete(qc);
  673. handled = 1;
  674. break;
  675. default:
  676. ap->stats.idle_irq++;
  677. break;
  678. }
  679. return handled;
  680. }
  681. static void pdc_irq_clear(struct ata_port *ap)
  682. {
  683. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  684. readl(ata_mmio + PDC_COMMAND);
  685. }
  686. static irqreturn_t pdc_interrupt(int irq, void *dev_instance)
  687. {
  688. struct ata_host *host = dev_instance;
  689. struct ata_port *ap;
  690. u32 mask = 0;
  691. unsigned int i, tmp;
  692. unsigned int handled = 0;
  693. void __iomem *host_mmio;
  694. unsigned int hotplug_offset, ata_no;
  695. u32 hotplug_status;
  696. int is_sataii_tx4;
  697. VPRINTK("ENTER\n");
  698. if (!host || !host->iomap[PDC_MMIO_BAR]) {
  699. VPRINTK("QUICK EXIT\n");
  700. return IRQ_NONE;
  701. }
  702. host_mmio = host->iomap[PDC_MMIO_BAR];
  703. spin_lock(&host->lock);
  704. /* read and clear hotplug flags for all ports */
  705. if (host->ports[0]->flags & PDC_FLAG_GEN_II)
  706. hotplug_offset = PDC2_SATA_PLUG_CSR;
  707. else
  708. hotplug_offset = PDC_SATA_PLUG_CSR;
  709. hotplug_status = readl(host_mmio + hotplug_offset);
  710. if (hotplug_status & 0xff)
  711. writel(hotplug_status | 0xff, host_mmio + hotplug_offset);
  712. hotplug_status &= 0xff; /* clear uninteresting bits */
  713. /* reading should also clear interrupts */
  714. mask = readl(host_mmio + PDC_INT_SEQMASK);
  715. if (mask == 0xffffffff && hotplug_status == 0) {
  716. VPRINTK("QUICK EXIT 2\n");
  717. goto done_irq;
  718. }
  719. mask &= 0xffff; /* only 16 SEQIDs possible */
  720. if (mask == 0 && hotplug_status == 0) {
  721. VPRINTK("QUICK EXIT 3\n");
  722. goto done_irq;
  723. }
  724. writel(mask, host_mmio + PDC_INT_SEQMASK);
  725. is_sataii_tx4 = pdc_is_sataii_tx4(host->ports[0]->flags);
  726. for (i = 0; i < host->n_ports; i++) {
  727. VPRINTK("port %u\n", i);
  728. ap = host->ports[i];
  729. /* check for a plug or unplug event */
  730. ata_no = pdc_port_no_to_ata_no(i, is_sataii_tx4);
  731. tmp = hotplug_status & (0x11 << ata_no);
  732. if (tmp && ap &&
  733. !(ap->flags & ATA_FLAG_DISABLED)) {
  734. struct ata_eh_info *ehi = &ap->link.eh_info;
  735. ata_ehi_clear_desc(ehi);
  736. ata_ehi_hotplugged(ehi);
  737. ata_ehi_push_desc(ehi, "hotplug_status %#x", tmp);
  738. ata_port_freeze(ap);
  739. ++handled;
  740. continue;
  741. }
  742. /* check for a packet interrupt */
  743. tmp = mask & (1 << (i + 1));
  744. if (tmp && ap &&
  745. !(ap->flags & ATA_FLAG_DISABLED)) {
  746. struct ata_queued_cmd *qc;
  747. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  748. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
  749. handled += pdc_host_intr(ap, qc);
  750. }
  751. }
  752. VPRINTK("EXIT\n");
  753. done_irq:
  754. spin_unlock(&host->lock);
  755. return IRQ_RETVAL(handled);
  756. }
  757. static void pdc_packet_start(struct ata_queued_cmd *qc)
  758. {
  759. struct ata_port *ap = qc->ap;
  760. struct pdc_port_priv *pp = ap->private_data;
  761. void __iomem *host_mmio = ap->host->iomap[PDC_MMIO_BAR];
  762. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  763. unsigned int port_no = ap->port_no;
  764. u8 seq = (u8) (port_no + 1);
  765. VPRINTK("ENTER, ap %p\n", ap);
  766. writel(0x00000001, host_mmio + (seq * 4));
  767. readl(host_mmio + (seq * 4)); /* flush */
  768. pp->pkt[2] = seq;
  769. wmb(); /* flush PRD, pkt writes */
  770. writel(pp->pkt_dma, ata_mmio + PDC_PKT_SUBMIT);
  771. readl(ata_mmio + PDC_PKT_SUBMIT); /* flush */
  772. }
  773. static unsigned int pdc_qc_issue(struct ata_queued_cmd *qc)
  774. {
  775. switch (qc->tf.protocol) {
  776. case ATAPI_PROT_NODATA:
  777. if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
  778. break;
  779. /*FALLTHROUGH*/
  780. case ATA_PROT_NODATA:
  781. if (qc->tf.flags & ATA_TFLAG_POLLING)
  782. break;
  783. /*FALLTHROUGH*/
  784. case ATAPI_PROT_DMA:
  785. case ATA_PROT_DMA:
  786. pdc_packet_start(qc);
  787. return 0;
  788. default:
  789. break;
  790. }
  791. return ata_sff_qc_issue(qc);
  792. }
  793. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  794. {
  795. WARN_ON(tf->protocol == ATA_PROT_DMA || tf->protocol == ATAPI_PROT_DMA);
  796. ata_sff_tf_load(ap, tf);
  797. }
  798. static void pdc_exec_command_mmio(struct ata_port *ap,
  799. const struct ata_taskfile *tf)
  800. {
  801. WARN_ON(tf->protocol == ATA_PROT_DMA || tf->protocol == ATAPI_PROT_DMA);
  802. ata_sff_exec_command(ap, tf);
  803. }
  804. static int pdc_check_atapi_dma(struct ata_queued_cmd *qc)
  805. {
  806. u8 *scsicmd = qc->scsicmd->cmnd;
  807. int pio = 1; /* atapi dma off by default */
  808. /* Whitelist commands that may use DMA. */
  809. switch (scsicmd[0]) {
  810. case WRITE_12:
  811. case WRITE_10:
  812. case WRITE_6:
  813. case READ_12:
  814. case READ_10:
  815. case READ_6:
  816. case 0xad: /* READ_DVD_STRUCTURE */
  817. case 0xbe: /* READ_CD */
  818. pio = 0;
  819. }
  820. /* -45150 (FFFF4FA2) to -1 (FFFFFFFF) shall use PIO mode */
  821. if (scsicmd[0] == WRITE_10) {
  822. unsigned int lba =
  823. (scsicmd[2] << 24) |
  824. (scsicmd[3] << 16) |
  825. (scsicmd[4] << 8) |
  826. scsicmd[5];
  827. if (lba >= 0xFFFF4FA2)
  828. pio = 1;
  829. }
  830. return pio;
  831. }
  832. static int pdc_old_sata_check_atapi_dma(struct ata_queued_cmd *qc)
  833. {
  834. /* First generation chips cannot use ATAPI DMA on SATA ports */
  835. return 1;
  836. }
  837. static void pdc_ata_setup_port(struct ata_port *ap,
  838. void __iomem *base, void __iomem *scr_addr)
  839. {
  840. ap->ioaddr.cmd_addr = base;
  841. ap->ioaddr.data_addr = base;
  842. ap->ioaddr.feature_addr =
  843. ap->ioaddr.error_addr = base + 0x4;
  844. ap->ioaddr.nsect_addr = base + 0x8;
  845. ap->ioaddr.lbal_addr = base + 0xc;
  846. ap->ioaddr.lbam_addr = base + 0x10;
  847. ap->ioaddr.lbah_addr = base + 0x14;
  848. ap->ioaddr.device_addr = base + 0x18;
  849. ap->ioaddr.command_addr =
  850. ap->ioaddr.status_addr = base + 0x1c;
  851. ap->ioaddr.altstatus_addr =
  852. ap->ioaddr.ctl_addr = base + 0x38;
  853. ap->ioaddr.scr_addr = scr_addr;
  854. }
  855. static void pdc_host_init(struct ata_host *host)
  856. {
  857. void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR];
  858. int is_gen2 = host->ports[0]->flags & PDC_FLAG_GEN_II;
  859. int hotplug_offset;
  860. u32 tmp;
  861. if (is_gen2)
  862. hotplug_offset = PDC2_SATA_PLUG_CSR;
  863. else
  864. hotplug_offset = PDC_SATA_PLUG_CSR;
  865. /*
  866. * Except for the hotplug stuff, this is voodoo from the
  867. * Promise driver. Label this entire section
  868. * "TODO: figure out why we do this"
  869. */
  870. /* enable BMR_BURST, maybe change FIFO_SHD to 8 dwords */
  871. tmp = readl(host_mmio + PDC_FLASH_CTL);
  872. tmp |= 0x02000; /* bit 13 (enable bmr burst) */
  873. if (!is_gen2)
  874. tmp |= 0x10000; /* bit 16 (fifo threshold at 8 dw) */
  875. writel(tmp, host_mmio + PDC_FLASH_CTL);
  876. /* clear plug/unplug flags for all ports */
  877. tmp = readl(host_mmio + hotplug_offset);
  878. writel(tmp | 0xff, host_mmio + hotplug_offset);
  879. /* unmask plug/unplug ints */
  880. tmp = readl(host_mmio + hotplug_offset);
  881. writel(tmp & ~0xff0000, host_mmio + hotplug_offset);
  882. /* don't initialise TBG or SLEW on 2nd generation chips */
  883. if (is_gen2)
  884. return;
  885. /* reduce TBG clock to 133 Mhz. */
  886. tmp = readl(host_mmio + PDC_TBG_MODE);
  887. tmp &= ~0x30000; /* clear bit 17, 16*/
  888. tmp |= 0x10000; /* set bit 17:16 = 0:1 */
  889. writel(tmp, host_mmio + PDC_TBG_MODE);
  890. readl(host_mmio + PDC_TBG_MODE); /* flush */
  891. msleep(10);
  892. /* adjust slew rate control register. */
  893. tmp = readl(host_mmio + PDC_SLEW_CTL);
  894. tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
  895. tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
  896. writel(tmp, host_mmio + PDC_SLEW_CTL);
  897. }
  898. static int pdc_ata_init_one(struct pci_dev *pdev,
  899. const struct pci_device_id *ent)
  900. {
  901. static int printed_version;
  902. const struct ata_port_info *pi = &pdc_port_info[ent->driver_data];
  903. const struct ata_port_info *ppi[PDC_MAX_PORTS];
  904. struct ata_host *host;
  905. void __iomem *host_mmio;
  906. int n_ports, i, rc;
  907. int is_sataii_tx4;
  908. if (!printed_version++)
  909. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  910. /* enable and acquire resources */
  911. rc = pcim_enable_device(pdev);
  912. if (rc)
  913. return rc;
  914. rc = pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME);
  915. if (rc == -EBUSY)
  916. pcim_pin_device(pdev);
  917. if (rc)
  918. return rc;
  919. host_mmio = pcim_iomap_table(pdev)[PDC_MMIO_BAR];
  920. /* determine port configuration and setup host */
  921. n_ports = 2;
  922. if (pi->flags & PDC_FLAG_4_PORTS)
  923. n_ports = 4;
  924. for (i = 0; i < n_ports; i++)
  925. ppi[i] = pi;
  926. if (pi->flags & PDC_FLAG_SATA_PATA) {
  927. u8 tmp = readb(host_mmio + PDC_FLASH_CTL + 1);
  928. if (!(tmp & 0x80))
  929. ppi[n_ports++] = pi + 1;
  930. }
  931. host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
  932. if (!host) {
  933. dev_printk(KERN_ERR, &pdev->dev, "failed to allocate host\n");
  934. return -ENOMEM;
  935. }
  936. host->iomap = pcim_iomap_table(pdev);
  937. is_sataii_tx4 = pdc_is_sataii_tx4(pi->flags);
  938. for (i = 0; i < host->n_ports; i++) {
  939. struct ata_port *ap = host->ports[i];
  940. unsigned int ata_no = pdc_port_no_to_ata_no(i, is_sataii_tx4);
  941. unsigned int ata_offset = 0x200 + ata_no * 0x80;
  942. unsigned int scr_offset = 0x400 + ata_no * 0x100;
  943. pdc_ata_setup_port(ap, host_mmio + ata_offset, host_mmio + scr_offset);
  944. ata_port_pbar_desc(ap, PDC_MMIO_BAR, -1, "mmio");
  945. ata_port_pbar_desc(ap, PDC_MMIO_BAR, ata_offset, "ata");
  946. }
  947. /* initialize adapter */
  948. pdc_host_init(host);
  949. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  950. if (rc)
  951. return rc;
  952. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  953. if (rc)
  954. return rc;
  955. /* start host, request IRQ and attach */
  956. pci_set_master(pdev);
  957. return ata_host_activate(host, pdev->irq, pdc_interrupt, IRQF_SHARED,
  958. &pdc_ata_sht);
  959. }
  960. static int __init pdc_ata_init(void)
  961. {
  962. return pci_register_driver(&pdc_ata_pci_driver);
  963. }
  964. static void __exit pdc_ata_exit(void)
  965. {
  966. pci_unregister_driver(&pdc_ata_pci_driver);
  967. }
  968. MODULE_AUTHOR("Jeff Garzik");
  969. MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
  970. MODULE_LICENSE("GPL");
  971. MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
  972. MODULE_VERSION(DRV_VERSION);
  973. module_init(pdc_ata_init);
  974. module_exit(pdc_ata_exit);