sata_promise.c 20 KB

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