sata_promise.c 20 KB

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