sata_promise.c 22 KB

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