sata_promise.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. /*
  2. * sata_promise.c - Promise SATA
  3. *
  4. * Maintained by: Jeff Garzik <jgarzik@pobox.com>
  5. * Please ALWAYS copy linux-ide@vger.kernel.org
  6. * on emails.
  7. *
  8. * Copyright 2003-2004 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. * Hardware information only available under NDA.
  30. *
  31. */
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <linux/pci.h>
  35. #include <linux/init.h>
  36. #include <linux/blkdev.h>
  37. #include <linux/delay.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/sched.h>
  40. #include <linux/device.h>
  41. #include <scsi/scsi_host.h>
  42. #include <scsi/scsi_cmnd.h>
  43. #include <linux/libata.h>
  44. #include <asm/io.h>
  45. #include "sata_promise.h"
  46. #define DRV_NAME "sata_promise"
  47. #define DRV_VERSION "1.05"
  48. enum {
  49. PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
  50. PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
  51. PDC_FLASH_CTL = 0x44, /* Flash control register */
  52. PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */
  53. PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */
  54. PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */
  55. PDC2_SATA_PLUG_CSR = 0x60, /* SATAII Plug control/status reg */
  56. PDC_TBG_MODE = 0x41C, /* TBG mode (not SATAII) */
  57. PDC_SLEW_CTL = 0x470, /* slew rate control reg (not SATAII) */
  58. PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) |
  59. (1<<8) | (1<<9) | (1<<10),
  60. board_2037x = 0, /* FastTrak S150 TX2plus */
  61. board_20319 = 1, /* FastTrak S150 TX4 */
  62. board_20619 = 2, /* FastTrak TX4000 */
  63. board_2057x = 3, /* SATAII150 Tx2plus */
  64. board_40518 = 4, /* SATAII150 Tx4 */
  65. PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */
  66. /* PDC_CTLSTAT bit definitions */
  67. PDC_DMA_ENABLE = (1 << 7),
  68. PDC_IRQ_DISABLE = (1 << 10),
  69. PDC_RESET = (1 << 11), /* HDMA reset */
  70. PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY |
  71. ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI |
  72. ATA_FLAG_PIO_POLLING,
  73. /* hp->flags bits */
  74. PDC_FLAG_GEN_II = (1 << 0),
  75. };
  76. struct pdc_port_priv {
  77. u8 *pkt;
  78. dma_addr_t pkt_dma;
  79. };
  80. struct pdc_host_priv {
  81. unsigned long flags;
  82. };
  83. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
  84. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
  85. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
  86. static irqreturn_t pdc_interrupt (int irq, void *dev_instance);
  87. static void pdc_eng_timeout(struct ata_port *ap);
  88. static int pdc_port_start(struct ata_port *ap);
  89. static void pdc_port_stop(struct ata_port *ap);
  90. static void pdc_pata_phy_reset(struct ata_port *ap);
  91. static void pdc_qc_prep(struct ata_queued_cmd *qc);
  92. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  93. static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  94. static void pdc_irq_clear(struct ata_port *ap);
  95. static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
  96. static void pdc_host_stop(struct ata_host *host);
  97. static void pdc_freeze(struct ata_port *ap);
  98. static void pdc_thaw(struct ata_port *ap);
  99. static void pdc_error_handler(struct ata_port *ap);
  100. static void pdc_post_internal_cmd(struct ata_queued_cmd *qc);
  101. static struct scsi_host_template pdc_ata_sht = {
  102. .module = THIS_MODULE,
  103. .name = DRV_NAME,
  104. .ioctl = ata_scsi_ioctl,
  105. .queuecommand = ata_scsi_queuecmd,
  106. .can_queue = ATA_DEF_QUEUE,
  107. .this_id = ATA_SHT_THIS_ID,
  108. .sg_tablesize = LIBATA_MAX_PRD,
  109. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  110. .emulated = ATA_SHT_EMULATED,
  111. .use_clustering = ATA_SHT_USE_CLUSTERING,
  112. .proc_name = DRV_NAME,
  113. .dma_boundary = ATA_DMA_BOUNDARY,
  114. .slave_configure = ata_scsi_slave_config,
  115. .slave_destroy = ata_scsi_slave_destroy,
  116. .bios_param = ata_std_bios_param,
  117. };
  118. static const struct ata_port_operations pdc_sata_ops = {
  119. .port_disable = ata_port_disable,
  120. .tf_load = pdc_tf_load_mmio,
  121. .tf_read = ata_tf_read,
  122. .check_status = ata_check_status,
  123. .exec_command = pdc_exec_command_mmio,
  124. .dev_select = ata_std_dev_select,
  125. .qc_prep = pdc_qc_prep,
  126. .qc_issue = pdc_qc_issue_prot,
  127. .freeze = pdc_freeze,
  128. .thaw = pdc_thaw,
  129. .error_handler = pdc_error_handler,
  130. .post_internal_cmd = pdc_post_internal_cmd,
  131. .data_xfer = ata_mmio_data_xfer,
  132. .irq_handler = pdc_interrupt,
  133. .irq_clear = pdc_irq_clear,
  134. .scr_read = pdc_sata_scr_read,
  135. .scr_write = pdc_sata_scr_write,
  136. .port_start = pdc_port_start,
  137. .port_stop = pdc_port_stop,
  138. .host_stop = pdc_host_stop,
  139. };
  140. static const struct ata_port_operations pdc_pata_ops = {
  141. .port_disable = ata_port_disable,
  142. .tf_load = pdc_tf_load_mmio,
  143. .tf_read = ata_tf_read,
  144. .check_status = ata_check_status,
  145. .exec_command = pdc_exec_command_mmio,
  146. .dev_select = ata_std_dev_select,
  147. .phy_reset = pdc_pata_phy_reset,
  148. .qc_prep = pdc_qc_prep,
  149. .qc_issue = pdc_qc_issue_prot,
  150. .data_xfer = ata_mmio_data_xfer,
  151. .eng_timeout = pdc_eng_timeout,
  152. .irq_handler = pdc_interrupt,
  153. .irq_clear = pdc_irq_clear,
  154. .port_start = pdc_port_start,
  155. .port_stop = pdc_port_stop,
  156. .host_stop = pdc_host_stop,
  157. };
  158. static const struct ata_port_info pdc_port_info[] = {
  159. /* board_2037x */
  160. {
  161. .sht = &pdc_ata_sht,
  162. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
  163. .pio_mask = 0x1f, /* pio0-4 */
  164. .mwdma_mask = 0x07, /* mwdma0-2 */
  165. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  166. .port_ops = &pdc_sata_ops,
  167. },
  168. /* board_20319 */
  169. {
  170. .sht = &pdc_ata_sht,
  171. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
  172. .pio_mask = 0x1f, /* pio0-4 */
  173. .mwdma_mask = 0x07, /* mwdma0-2 */
  174. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  175. .port_ops = &pdc_sata_ops,
  176. },
  177. /* board_20619 */
  178. {
  179. .sht = &pdc_ata_sht,
  180. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SRST | ATA_FLAG_SLAVE_POSS,
  181. .pio_mask = 0x1f, /* pio0-4 */
  182. .mwdma_mask = 0x07, /* mwdma0-2 */
  183. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  184. .port_ops = &pdc_pata_ops,
  185. },
  186. /* board_2057x */
  187. {
  188. .sht = &pdc_ata_sht,
  189. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
  190. .pio_mask = 0x1f, /* pio0-4 */
  191. .mwdma_mask = 0x07, /* mwdma0-2 */
  192. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  193. .port_ops = &pdc_sata_ops,
  194. },
  195. /* board_40518 */
  196. {
  197. .sht = &pdc_ata_sht,
  198. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
  199. .pio_mask = 0x1f, /* pio0-4 */
  200. .mwdma_mask = 0x07, /* mwdma0-2 */
  201. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  202. .port_ops = &pdc_sata_ops,
  203. },
  204. };
  205. static const struct pci_device_id pdc_ata_pci_tbl[] = {
  206. { PCI_VDEVICE(PROMISE, 0x3371), board_2037x },
  207. { PCI_VDEVICE(PROMISE, 0x3373), board_2037x },
  208. { PCI_VDEVICE(PROMISE, 0x3375), board_2037x },
  209. { PCI_VDEVICE(PROMISE, 0x3376), board_2037x },
  210. { PCI_VDEVICE(PROMISE, 0x3570), board_2057x },
  211. { PCI_VDEVICE(PROMISE, 0x3571), board_2057x },
  212. { PCI_VDEVICE(PROMISE, 0x3574), board_2057x },
  213. { PCI_VDEVICE(PROMISE, 0x3577), board_2057x },
  214. { PCI_VDEVICE(PROMISE, 0x3d73), board_2057x },
  215. { PCI_VDEVICE(PROMISE, 0x3d75), board_2057x },
  216. { PCI_VDEVICE(PROMISE, 0x3318), board_20319 },
  217. { PCI_VDEVICE(PROMISE, 0x3319), board_20319 },
  218. { PCI_VDEVICE(PROMISE, 0x3515), board_20319 },
  219. { PCI_VDEVICE(PROMISE, 0x3519), board_20319 },
  220. { PCI_VDEVICE(PROMISE, 0x3d17), board_40518 },
  221. { PCI_VDEVICE(PROMISE, 0x3d18), board_40518 },
  222. { PCI_VDEVICE(PROMISE, 0x6629), board_20619 },
  223. { } /* terminate list */
  224. };
  225. static struct pci_driver pdc_ata_pci_driver = {
  226. .name = DRV_NAME,
  227. .id_table = pdc_ata_pci_tbl,
  228. .probe = pdc_ata_init_one,
  229. .remove = ata_pci_remove_one,
  230. };
  231. static int pdc_port_start(struct ata_port *ap)
  232. {
  233. struct device *dev = ap->host->dev;
  234. struct pdc_host_priv *hp = ap->host->private_data;
  235. struct pdc_port_priv *pp;
  236. int rc;
  237. rc = ata_port_start(ap);
  238. if (rc)
  239. return rc;
  240. pp = kzalloc(sizeof(*pp), GFP_KERNEL);
  241. if (!pp) {
  242. rc = -ENOMEM;
  243. goto err_out;
  244. }
  245. pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  246. if (!pp->pkt) {
  247. rc = -ENOMEM;
  248. goto err_out_kfree;
  249. }
  250. ap->private_data = pp;
  251. /* fix up PHYMODE4 align timing */
  252. if ((hp->flags & PDC_FLAG_GEN_II) && sata_scr_valid(ap)) {
  253. void __iomem *mmio = (void __iomem *) ap->ioaddr.scr_addr;
  254. unsigned int tmp;
  255. tmp = readl(mmio + 0x014);
  256. tmp = (tmp & ~3) | 1; /* set bits 1:0 = 0:1 */
  257. writel(tmp, mmio + 0x014);
  258. }
  259. return 0;
  260. err_out_kfree:
  261. kfree(pp);
  262. err_out:
  263. ata_port_stop(ap);
  264. return rc;
  265. }
  266. static void pdc_port_stop(struct ata_port *ap)
  267. {
  268. struct device *dev = ap->host->dev;
  269. struct pdc_port_priv *pp = ap->private_data;
  270. ap->private_data = NULL;
  271. dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
  272. kfree(pp);
  273. ata_port_stop(ap);
  274. }
  275. static void pdc_host_stop(struct ata_host *host)
  276. {
  277. struct pdc_host_priv *hp = host->private_data;
  278. ata_pci_host_stop(host);
  279. kfree(hp);
  280. }
  281. static void pdc_reset_port(struct ata_port *ap)
  282. {
  283. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
  284. unsigned int i;
  285. u32 tmp;
  286. for (i = 11; i > 0; i--) {
  287. tmp = readl(mmio);
  288. if (tmp & PDC_RESET)
  289. break;
  290. udelay(100);
  291. tmp |= PDC_RESET;
  292. writel(tmp, mmio);
  293. }
  294. tmp &= ~PDC_RESET;
  295. writel(tmp, mmio);
  296. readl(mmio); /* flush */
  297. }
  298. static void pdc_pata_cbl_detect(struct ata_port *ap)
  299. {
  300. u8 tmp;
  301. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT + 0x03;
  302. tmp = readb(mmio);
  303. if (tmp & 0x01) {
  304. ap->cbl = ATA_CBL_PATA40;
  305. ap->udma_mask &= ATA_UDMA_MASK_40C;
  306. } else
  307. ap->cbl = ATA_CBL_PATA80;
  308. }
  309. static void pdc_pata_phy_reset(struct ata_port *ap)
  310. {
  311. pdc_pata_cbl_detect(ap);
  312. pdc_reset_port(ap);
  313. ata_port_probe(ap);
  314. ata_bus_reset(ap);
  315. }
  316. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
  317. {
  318. if (sc_reg > SCR_CONTROL)
  319. return 0xffffffffU;
  320. return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
  321. }
  322. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
  323. u32 val)
  324. {
  325. if (sc_reg > SCR_CONTROL)
  326. return;
  327. writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
  328. }
  329. static void pdc_qc_prep(struct ata_queued_cmd *qc)
  330. {
  331. struct pdc_port_priv *pp = qc->ap->private_data;
  332. unsigned int i;
  333. VPRINTK("ENTER\n");
  334. switch (qc->tf.protocol) {
  335. case ATA_PROT_DMA:
  336. ata_qc_prep(qc);
  337. /* fall through */
  338. case ATA_PROT_NODATA:
  339. i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
  340. qc->dev->devno, pp->pkt);
  341. if (qc->tf.flags & ATA_TFLAG_LBA48)
  342. i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
  343. else
  344. i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
  345. pdc_pkt_footer(&qc->tf, pp->pkt, i);
  346. break;
  347. default:
  348. break;
  349. }
  350. }
  351. static void pdc_freeze(struct ata_port *ap)
  352. {
  353. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr;
  354. u32 tmp;
  355. tmp = readl(mmio + PDC_CTLSTAT);
  356. tmp |= PDC_IRQ_DISABLE;
  357. tmp &= ~PDC_DMA_ENABLE;
  358. writel(tmp, mmio + PDC_CTLSTAT);
  359. readl(mmio + PDC_CTLSTAT); /* flush */
  360. }
  361. static void pdc_thaw(struct ata_port *ap)
  362. {
  363. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr;
  364. u32 tmp;
  365. /* clear IRQ */
  366. readl(mmio + PDC_INT_SEQMASK);
  367. /* turn IRQ back on */
  368. tmp = readl(mmio + PDC_CTLSTAT);
  369. tmp &= ~PDC_IRQ_DISABLE;
  370. writel(tmp, mmio + PDC_CTLSTAT);
  371. readl(mmio + PDC_CTLSTAT); /* flush */
  372. }
  373. static void pdc_error_handler(struct ata_port *ap)
  374. {
  375. ata_reset_fn_t hardreset;
  376. if (!(ap->pflags & ATA_PFLAG_FROZEN))
  377. pdc_reset_port(ap);
  378. hardreset = NULL;
  379. if (sata_scr_valid(ap))
  380. hardreset = sata_std_hardreset;
  381. /* perform recovery */
  382. ata_do_eh(ap, ata_std_prereset, ata_std_softreset, hardreset,
  383. ata_std_postreset);
  384. }
  385. static void pdc_post_internal_cmd(struct ata_queued_cmd *qc)
  386. {
  387. struct ata_port *ap = qc->ap;
  388. if (qc->flags & ATA_QCFLAG_FAILED)
  389. qc->err_mask |= AC_ERR_OTHER;
  390. /* make DMA engine forget about the failed command */
  391. if (qc->err_mask)
  392. pdc_reset_port(ap);
  393. }
  394. static void pdc_eng_timeout(struct ata_port *ap)
  395. {
  396. struct ata_host *host = ap->host;
  397. u8 drv_stat;
  398. struct ata_queued_cmd *qc;
  399. unsigned long flags;
  400. DPRINTK("ENTER\n");
  401. spin_lock_irqsave(&host->lock, flags);
  402. qc = ata_qc_from_tag(ap, ap->active_tag);
  403. switch (qc->tf.protocol) {
  404. case ATA_PROT_DMA:
  405. case ATA_PROT_NODATA:
  406. ata_port_printk(ap, KERN_ERR, "command timeout\n");
  407. drv_stat = ata_wait_idle(ap);
  408. qc->err_mask |= __ac_err_mask(drv_stat);
  409. break;
  410. default:
  411. drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
  412. ata_port_printk(ap, KERN_ERR,
  413. "unknown timeout, cmd 0x%x stat 0x%x\n",
  414. qc->tf.command, drv_stat);
  415. qc->err_mask |= ac_err_mask(drv_stat);
  416. break;
  417. }
  418. spin_unlock_irqrestore(&host->lock, flags);
  419. ata_eh_qc_complete(qc);
  420. DPRINTK("EXIT\n");
  421. }
  422. static inline unsigned int pdc_host_intr( struct ata_port *ap,
  423. struct ata_queued_cmd *qc)
  424. {
  425. unsigned int handled = 0;
  426. u32 tmp;
  427. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
  428. tmp = readl(mmio);
  429. if (tmp & PDC_ERR_MASK) {
  430. qc->err_mask |= AC_ERR_DEV;
  431. pdc_reset_port(ap);
  432. }
  433. switch (qc->tf.protocol) {
  434. case ATA_PROT_DMA:
  435. case ATA_PROT_NODATA:
  436. qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
  437. ata_qc_complete(qc);
  438. handled = 1;
  439. break;
  440. default:
  441. ap->stats.idle_irq++;
  442. break;
  443. }
  444. return handled;
  445. }
  446. static void pdc_irq_clear(struct ata_port *ap)
  447. {
  448. struct ata_host *host = ap->host;
  449. void __iomem *mmio = host->mmio_base;
  450. readl(mmio + PDC_INT_SEQMASK);
  451. }
  452. static irqreturn_t pdc_interrupt (int irq, void *dev_instance)
  453. {
  454. struct ata_host *host = dev_instance;
  455. struct ata_port *ap;
  456. u32 mask = 0;
  457. unsigned int i, tmp;
  458. unsigned int handled = 0;
  459. void __iomem *mmio_base;
  460. VPRINTK("ENTER\n");
  461. if (!host || !host->mmio_base) {
  462. VPRINTK("QUICK EXIT\n");
  463. return IRQ_NONE;
  464. }
  465. mmio_base = host->mmio_base;
  466. /* reading should also clear interrupts */
  467. mask = readl(mmio_base + PDC_INT_SEQMASK);
  468. if (mask == 0xffffffff) {
  469. VPRINTK("QUICK EXIT 2\n");
  470. return IRQ_NONE;
  471. }
  472. spin_lock(&host->lock);
  473. mask &= 0xffff; /* only 16 tags possible */
  474. if (!mask) {
  475. VPRINTK("QUICK EXIT 3\n");
  476. goto done_irq;
  477. }
  478. writel(mask, mmio_base + PDC_INT_SEQMASK);
  479. for (i = 0; i < host->n_ports; i++) {
  480. VPRINTK("port %u\n", i);
  481. ap = host->ports[i];
  482. tmp = mask & (1 << (i + 1));
  483. if (tmp && ap &&
  484. !(ap->flags & ATA_FLAG_DISABLED)) {
  485. struct ata_queued_cmd *qc;
  486. qc = ata_qc_from_tag(ap, ap->active_tag);
  487. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
  488. handled += pdc_host_intr(ap, qc);
  489. }
  490. }
  491. VPRINTK("EXIT\n");
  492. done_irq:
  493. spin_unlock(&host->lock);
  494. return IRQ_RETVAL(handled);
  495. }
  496. static inline void pdc_packet_start(struct ata_queued_cmd *qc)
  497. {
  498. struct ata_port *ap = qc->ap;
  499. struct pdc_port_priv *pp = ap->private_data;
  500. unsigned int port_no = ap->port_no;
  501. u8 seq = (u8) (port_no + 1);
  502. VPRINTK("ENTER, ap %p\n", ap);
  503. writel(0x00000001, ap->host->mmio_base + (seq * 4));
  504. readl(ap->host->mmio_base + (seq * 4)); /* flush */
  505. pp->pkt[2] = seq;
  506. wmb(); /* flush PRD, pkt writes */
  507. writel(pp->pkt_dma, (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  508. readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
  509. }
  510. static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
  511. {
  512. switch (qc->tf.protocol) {
  513. case ATA_PROT_DMA:
  514. case ATA_PROT_NODATA:
  515. pdc_packet_start(qc);
  516. return 0;
  517. case ATA_PROT_ATAPI_DMA:
  518. BUG();
  519. break;
  520. default:
  521. break;
  522. }
  523. return ata_qc_issue_prot(qc);
  524. }
  525. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  526. {
  527. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  528. tf->protocol == ATA_PROT_NODATA);
  529. ata_tf_load(ap, tf);
  530. }
  531. static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  532. {
  533. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  534. tf->protocol == ATA_PROT_NODATA);
  535. ata_exec_command(ap, tf);
  536. }
  537. static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
  538. {
  539. port->cmd_addr = base;
  540. port->data_addr = base;
  541. port->feature_addr =
  542. port->error_addr = base + 0x4;
  543. port->nsect_addr = base + 0x8;
  544. port->lbal_addr = base + 0xc;
  545. port->lbam_addr = base + 0x10;
  546. port->lbah_addr = base + 0x14;
  547. port->device_addr = base + 0x18;
  548. port->command_addr =
  549. port->status_addr = base + 0x1c;
  550. port->altstatus_addr =
  551. port->ctl_addr = base + 0x38;
  552. }
  553. static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
  554. {
  555. void __iomem *mmio = pe->mmio_base;
  556. struct pdc_host_priv *hp = pe->private_data;
  557. int hotplug_offset;
  558. u32 tmp;
  559. if (hp->flags & PDC_FLAG_GEN_II)
  560. hotplug_offset = PDC2_SATA_PLUG_CSR;
  561. else
  562. hotplug_offset = PDC_SATA_PLUG_CSR;
  563. /*
  564. * Except for the hotplug stuff, this is voodoo from the
  565. * Promise driver. Label this entire section
  566. * "TODO: figure out why we do this"
  567. */
  568. /* enable BMR_BURST, maybe change FIFO_SHD to 8 dwords */
  569. tmp = readl(mmio + PDC_FLASH_CTL);
  570. tmp |= 0x02000; /* bit 13 (enable bmr burst) */
  571. if (!(hp->flags & PDC_FLAG_GEN_II))
  572. tmp |= 0x10000; /* bit 16 (fifo threshold at 8 dw) */
  573. writel(tmp, mmio + PDC_FLASH_CTL);
  574. /* clear plug/unplug flags for all ports */
  575. tmp = readl(mmio + hotplug_offset);
  576. writel(tmp | 0xff, mmio + hotplug_offset);
  577. /* mask plug/unplug ints */
  578. tmp = readl(mmio + hotplug_offset);
  579. writel(tmp | 0xff0000, mmio + hotplug_offset);
  580. /* don't initialise TBG or SLEW on 2nd generation chips */
  581. if (hp->flags & PDC_FLAG_GEN_II)
  582. return;
  583. /* reduce TBG clock to 133 Mhz. */
  584. tmp = readl(mmio + PDC_TBG_MODE);
  585. tmp &= ~0x30000; /* clear bit 17, 16*/
  586. tmp |= 0x10000; /* set bit 17:16 = 0:1 */
  587. writel(tmp, mmio + PDC_TBG_MODE);
  588. readl(mmio + PDC_TBG_MODE); /* flush */
  589. msleep(10);
  590. /* adjust slew rate control register. */
  591. tmp = readl(mmio + PDC_SLEW_CTL);
  592. tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
  593. tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
  594. writel(tmp, mmio + PDC_SLEW_CTL);
  595. }
  596. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  597. {
  598. static int printed_version;
  599. struct ata_probe_ent *probe_ent = NULL;
  600. struct pdc_host_priv *hp;
  601. unsigned long base;
  602. void __iomem *mmio_base;
  603. unsigned int board_idx = (unsigned int) ent->driver_data;
  604. int pci_dev_busy = 0;
  605. int rc;
  606. if (!printed_version++)
  607. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  608. rc = pci_enable_device(pdev);
  609. if (rc)
  610. return rc;
  611. rc = pci_request_regions(pdev, DRV_NAME);
  612. if (rc) {
  613. pci_dev_busy = 1;
  614. goto err_out;
  615. }
  616. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  617. if (rc)
  618. goto err_out_regions;
  619. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  620. if (rc)
  621. goto err_out_regions;
  622. probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
  623. if (probe_ent == NULL) {
  624. rc = -ENOMEM;
  625. goto err_out_regions;
  626. }
  627. probe_ent->dev = pci_dev_to_dev(pdev);
  628. INIT_LIST_HEAD(&probe_ent->node);
  629. mmio_base = pci_iomap(pdev, 3, 0);
  630. if (mmio_base == NULL) {
  631. rc = -ENOMEM;
  632. goto err_out_free_ent;
  633. }
  634. base = (unsigned long) mmio_base;
  635. hp = kzalloc(sizeof(*hp), GFP_KERNEL);
  636. if (hp == NULL) {
  637. rc = -ENOMEM;
  638. goto err_out_free_ent;
  639. }
  640. probe_ent->private_data = hp;
  641. probe_ent->sht = pdc_port_info[board_idx].sht;
  642. probe_ent->port_flags = pdc_port_info[board_idx].flags;
  643. probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
  644. probe_ent->mwdma_mask = pdc_port_info[board_idx].mwdma_mask;
  645. probe_ent->udma_mask = pdc_port_info[board_idx].udma_mask;
  646. probe_ent->port_ops = pdc_port_info[board_idx].port_ops;
  647. probe_ent->irq = pdev->irq;
  648. probe_ent->irq_flags = IRQF_SHARED;
  649. probe_ent->mmio_base = mmio_base;
  650. pdc_ata_setup_port(&probe_ent->port[0], base + 0x200);
  651. pdc_ata_setup_port(&probe_ent->port[1], base + 0x280);
  652. probe_ent->port[0].scr_addr = base + 0x400;
  653. probe_ent->port[1].scr_addr = base + 0x500;
  654. /* notice 4-port boards */
  655. switch (board_idx) {
  656. case board_40518:
  657. hp->flags |= PDC_FLAG_GEN_II;
  658. /* Fall through */
  659. case board_20319:
  660. probe_ent->n_ports = 4;
  661. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  662. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  663. probe_ent->port[2].scr_addr = base + 0x600;
  664. probe_ent->port[3].scr_addr = base + 0x700;
  665. break;
  666. case board_2057x:
  667. hp->flags |= PDC_FLAG_GEN_II;
  668. /* Fall through */
  669. case board_2037x:
  670. probe_ent->n_ports = 2;
  671. break;
  672. case board_20619:
  673. probe_ent->n_ports = 4;
  674. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  675. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  676. probe_ent->port[2].scr_addr = base + 0x600;
  677. probe_ent->port[3].scr_addr = base + 0x700;
  678. break;
  679. default:
  680. BUG();
  681. break;
  682. }
  683. pci_set_master(pdev);
  684. /* initialize adapter */
  685. pdc_host_init(board_idx, probe_ent);
  686. /* FIXME: Need any other frees than hp? */
  687. if (!ata_device_add(probe_ent))
  688. kfree(hp);
  689. kfree(probe_ent);
  690. return 0;
  691. err_out_free_ent:
  692. kfree(probe_ent);
  693. err_out_regions:
  694. pci_release_regions(pdev);
  695. err_out:
  696. if (!pci_dev_busy)
  697. pci_disable_device(pdev);
  698. return rc;
  699. }
  700. static int __init pdc_ata_init(void)
  701. {
  702. return pci_register_driver(&pdc_ata_pci_driver);
  703. }
  704. static void __exit pdc_ata_exit(void)
  705. {
  706. pci_unregister_driver(&pdc_ata_pci_driver);
  707. }
  708. MODULE_AUTHOR("Jeff Garzik");
  709. MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
  710. MODULE_LICENSE("GPL");
  711. MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
  712. MODULE_VERSION(DRV_VERSION);
  713. module_init(pdc_ata_init);
  714. module_exit(pdc_ata_exit);