sata_promise.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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_RESET = (1 << 11), /* HDMA reset */
  67. PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
  68. ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI |
  69. ATA_FLAG_PIO_POLLING,
  70. /* hp->flags bits */
  71. PDC_FLAG_GEN_II = (1 << 0),
  72. };
  73. struct pdc_port_priv {
  74. u8 *pkt;
  75. dma_addr_t pkt_dma;
  76. };
  77. struct pdc_host_priv {
  78. unsigned long flags;
  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_2057x */
  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_40518 */
  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. };
  197. static const struct pci_device_id pdc_ata_pci_tbl[] = {
  198. { PCI_VDEVICE(PROMISE, 0x3371), board_2037x },
  199. { PCI_VDEVICE(PROMISE, 0x3373), board_2037x },
  200. { PCI_VDEVICE(PROMISE, 0x3375), board_2037x },
  201. { PCI_VDEVICE(PROMISE, 0x3376), board_2037x },
  202. { PCI_VDEVICE(PROMISE, 0x3570), board_2057x },
  203. { PCI_VDEVICE(PROMISE, 0x3571), board_2057x },
  204. { PCI_VDEVICE(PROMISE, 0x3574), board_2057x },
  205. { PCI_VDEVICE(PROMISE, 0x3577), board_2057x },
  206. { PCI_VDEVICE(PROMISE, 0x3d73), board_2057x },
  207. { PCI_VDEVICE(PROMISE, 0x3d75), board_2057x },
  208. { PCI_VDEVICE(PROMISE, 0x3318), board_20319 },
  209. { PCI_VDEVICE(PROMISE, 0x3319), board_20319 },
  210. { PCI_VDEVICE(PROMISE, 0x3515), board_20319 },
  211. { PCI_VDEVICE(PROMISE, 0x3519), board_20319 },
  212. { PCI_VDEVICE(PROMISE, 0x3d17), board_40518 },
  213. { PCI_VDEVICE(PROMISE, 0x3d18), board_40518 },
  214. { PCI_VDEVICE(PROMISE, 0x6629), board_20619 },
  215. { } /* terminate list */
  216. };
  217. static struct pci_driver pdc_ata_pci_driver = {
  218. .name = DRV_NAME,
  219. .id_table = pdc_ata_pci_tbl,
  220. .probe = pdc_ata_init_one,
  221. .remove = ata_pci_remove_one,
  222. };
  223. static int pdc_port_start(struct ata_port *ap)
  224. {
  225. struct device *dev = ap->host->dev;
  226. struct pdc_host_priv *hp = ap->host->private_data;
  227. struct pdc_port_priv *pp;
  228. int rc;
  229. rc = ata_port_start(ap);
  230. if (rc)
  231. return rc;
  232. pp = kzalloc(sizeof(*pp), GFP_KERNEL);
  233. if (!pp) {
  234. rc = -ENOMEM;
  235. goto err_out;
  236. }
  237. pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  238. if (!pp->pkt) {
  239. rc = -ENOMEM;
  240. goto err_out_kfree;
  241. }
  242. ap->private_data = pp;
  243. /* fix up PHYMODE4 align timing */
  244. if ((hp->flags & PDC_FLAG_GEN_II) && sata_scr_valid(ap)) {
  245. void __iomem *mmio = (void __iomem *) ap->ioaddr.scr_addr;
  246. unsigned int tmp;
  247. tmp = readl(mmio + 0x014);
  248. tmp = (tmp & ~3) | 1; /* set bits 1:0 = 0:1 */
  249. writel(tmp, mmio + 0x014);
  250. }
  251. return 0;
  252. err_out_kfree:
  253. kfree(pp);
  254. err_out:
  255. ata_port_stop(ap);
  256. return rc;
  257. }
  258. static void pdc_port_stop(struct ata_port *ap)
  259. {
  260. struct device *dev = ap->host->dev;
  261. struct pdc_port_priv *pp = ap->private_data;
  262. ap->private_data = NULL;
  263. dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
  264. kfree(pp);
  265. ata_port_stop(ap);
  266. }
  267. static void pdc_host_stop(struct ata_host *host)
  268. {
  269. struct pdc_host_priv *hp = host->private_data;
  270. ata_pci_host_stop(host);
  271. kfree(hp);
  272. }
  273. static void pdc_reset_port(struct ata_port *ap)
  274. {
  275. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
  276. unsigned int i;
  277. u32 tmp;
  278. for (i = 11; i > 0; i--) {
  279. tmp = readl(mmio);
  280. if (tmp & PDC_RESET)
  281. break;
  282. udelay(100);
  283. tmp |= PDC_RESET;
  284. writel(tmp, mmio);
  285. }
  286. tmp &= ~PDC_RESET;
  287. writel(tmp, mmio);
  288. readl(mmio); /* flush */
  289. }
  290. static void pdc_sata_phy_reset(struct ata_port *ap)
  291. {
  292. pdc_reset_port(ap);
  293. sata_phy_reset(ap);
  294. }
  295. static void pdc_pata_cbl_detect(struct ata_port *ap)
  296. {
  297. u8 tmp;
  298. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT + 0x03;
  299. tmp = readb(mmio);
  300. if (tmp & 0x01) {
  301. ap->cbl = ATA_CBL_PATA40;
  302. ap->udma_mask &= ATA_UDMA_MASK_40C;
  303. } else
  304. ap->cbl = ATA_CBL_PATA80;
  305. }
  306. static void pdc_pata_phy_reset(struct ata_port *ap)
  307. {
  308. pdc_pata_cbl_detect(ap);
  309. pdc_reset_port(ap);
  310. ata_port_probe(ap);
  311. ata_bus_reset(ap);
  312. }
  313. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
  314. {
  315. if (sc_reg > SCR_CONTROL)
  316. return 0xffffffffU;
  317. return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
  318. }
  319. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
  320. u32 val)
  321. {
  322. if (sc_reg > SCR_CONTROL)
  323. return;
  324. writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
  325. }
  326. static void pdc_qc_prep(struct ata_queued_cmd *qc)
  327. {
  328. struct pdc_port_priv *pp = qc->ap->private_data;
  329. unsigned int i;
  330. VPRINTK("ENTER\n");
  331. switch (qc->tf.protocol) {
  332. case ATA_PROT_DMA:
  333. ata_qc_prep(qc);
  334. /* fall through */
  335. case ATA_PROT_NODATA:
  336. i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
  337. qc->dev->devno, pp->pkt);
  338. if (qc->tf.flags & ATA_TFLAG_LBA48)
  339. i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
  340. else
  341. i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
  342. pdc_pkt_footer(&qc->tf, pp->pkt, i);
  343. break;
  344. default:
  345. break;
  346. }
  347. }
  348. static void pdc_eng_timeout(struct ata_port *ap)
  349. {
  350. struct ata_host *host = ap->host;
  351. u8 drv_stat;
  352. struct ata_queued_cmd *qc;
  353. unsigned long flags;
  354. DPRINTK("ENTER\n");
  355. spin_lock_irqsave(&host->lock, flags);
  356. qc = ata_qc_from_tag(ap, ap->active_tag);
  357. switch (qc->tf.protocol) {
  358. case ATA_PROT_DMA:
  359. case ATA_PROT_NODATA:
  360. ata_port_printk(ap, KERN_ERR, "command timeout\n");
  361. drv_stat = ata_wait_idle(ap);
  362. qc->err_mask |= __ac_err_mask(drv_stat);
  363. break;
  364. default:
  365. drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
  366. ata_port_printk(ap, KERN_ERR,
  367. "unknown timeout, cmd 0x%x stat 0x%x\n",
  368. qc->tf.command, drv_stat);
  369. qc->err_mask |= ac_err_mask(drv_stat);
  370. break;
  371. }
  372. spin_unlock_irqrestore(&host->lock, flags);
  373. ata_eh_qc_complete(qc);
  374. DPRINTK("EXIT\n");
  375. }
  376. static inline unsigned int pdc_host_intr( struct ata_port *ap,
  377. struct ata_queued_cmd *qc)
  378. {
  379. unsigned int handled = 0;
  380. u32 tmp;
  381. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
  382. tmp = readl(mmio);
  383. if (tmp & PDC_ERR_MASK) {
  384. qc->err_mask |= AC_ERR_DEV;
  385. pdc_reset_port(ap);
  386. }
  387. switch (qc->tf.protocol) {
  388. case ATA_PROT_DMA:
  389. case ATA_PROT_NODATA:
  390. qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
  391. ata_qc_complete(qc);
  392. handled = 1;
  393. break;
  394. default:
  395. ap->stats.idle_irq++;
  396. break;
  397. }
  398. return handled;
  399. }
  400. static void pdc_irq_clear(struct ata_port *ap)
  401. {
  402. struct ata_host *host = ap->host;
  403. void __iomem *mmio = host->mmio_base;
  404. readl(mmio + PDC_INT_SEQMASK);
  405. }
  406. static irqreturn_t pdc_interrupt (int irq, void *dev_instance)
  407. {
  408. struct ata_host *host = dev_instance;
  409. struct ata_port *ap;
  410. u32 mask = 0;
  411. unsigned int i, tmp;
  412. unsigned int handled = 0;
  413. void __iomem *mmio_base;
  414. VPRINTK("ENTER\n");
  415. if (!host || !host->mmio_base) {
  416. VPRINTK("QUICK EXIT\n");
  417. return IRQ_NONE;
  418. }
  419. mmio_base = host->mmio_base;
  420. /* reading should also clear interrupts */
  421. mask = readl(mmio_base + PDC_INT_SEQMASK);
  422. if (mask == 0xffffffff) {
  423. VPRINTK("QUICK EXIT 2\n");
  424. return IRQ_NONE;
  425. }
  426. spin_lock(&host->lock);
  427. mask &= 0xffff; /* only 16 tags possible */
  428. if (!mask) {
  429. VPRINTK("QUICK EXIT 3\n");
  430. goto done_irq;
  431. }
  432. writel(mask, mmio_base + PDC_INT_SEQMASK);
  433. for (i = 0; i < host->n_ports; i++) {
  434. VPRINTK("port %u\n", i);
  435. ap = host->ports[i];
  436. tmp = mask & (1 << (i + 1));
  437. if (tmp && ap &&
  438. !(ap->flags & ATA_FLAG_DISABLED)) {
  439. struct ata_queued_cmd *qc;
  440. qc = ata_qc_from_tag(ap, ap->active_tag);
  441. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
  442. handled += pdc_host_intr(ap, qc);
  443. }
  444. }
  445. VPRINTK("EXIT\n");
  446. done_irq:
  447. spin_unlock(&host->lock);
  448. return IRQ_RETVAL(handled);
  449. }
  450. static inline void pdc_packet_start(struct ata_queued_cmd *qc)
  451. {
  452. struct ata_port *ap = qc->ap;
  453. struct pdc_port_priv *pp = ap->private_data;
  454. unsigned int port_no = ap->port_no;
  455. u8 seq = (u8) (port_no + 1);
  456. VPRINTK("ENTER, ap %p\n", ap);
  457. writel(0x00000001, ap->host->mmio_base + (seq * 4));
  458. readl(ap->host->mmio_base + (seq * 4)); /* flush */
  459. pp->pkt[2] = seq;
  460. wmb(); /* flush PRD, pkt writes */
  461. writel(pp->pkt_dma, (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  462. readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
  463. }
  464. static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
  465. {
  466. switch (qc->tf.protocol) {
  467. case ATA_PROT_DMA:
  468. case ATA_PROT_NODATA:
  469. pdc_packet_start(qc);
  470. return 0;
  471. case ATA_PROT_ATAPI_DMA:
  472. BUG();
  473. break;
  474. default:
  475. break;
  476. }
  477. return ata_qc_issue_prot(qc);
  478. }
  479. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  480. {
  481. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  482. tf->protocol == ATA_PROT_NODATA);
  483. ata_tf_load(ap, tf);
  484. }
  485. static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  486. {
  487. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  488. tf->protocol == ATA_PROT_NODATA);
  489. ata_exec_command(ap, tf);
  490. }
  491. static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
  492. {
  493. port->cmd_addr = base;
  494. port->data_addr = base;
  495. port->feature_addr =
  496. port->error_addr = base + 0x4;
  497. port->nsect_addr = base + 0x8;
  498. port->lbal_addr = base + 0xc;
  499. port->lbam_addr = base + 0x10;
  500. port->lbah_addr = base + 0x14;
  501. port->device_addr = base + 0x18;
  502. port->command_addr =
  503. port->status_addr = base + 0x1c;
  504. port->altstatus_addr =
  505. port->ctl_addr = base + 0x38;
  506. }
  507. static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
  508. {
  509. void __iomem *mmio = pe->mmio_base;
  510. struct pdc_host_priv *hp = pe->private_data;
  511. int hotplug_offset;
  512. u32 tmp;
  513. if (hp->flags & PDC_FLAG_GEN_II)
  514. hotplug_offset = PDC2_SATA_PLUG_CSR;
  515. else
  516. hotplug_offset = PDC_SATA_PLUG_CSR;
  517. /*
  518. * Except for the hotplug stuff, this is voodoo from the
  519. * Promise driver. Label this entire section
  520. * "TODO: figure out why we do this"
  521. */
  522. /* enable BMR_BURST, maybe change FIFO_SHD to 8 dwords */
  523. tmp = readl(mmio + PDC_FLASH_CTL);
  524. tmp |= 0x02000; /* bit 13 (enable bmr burst) */
  525. if (!(hp->flags & PDC_FLAG_GEN_II))
  526. tmp |= 0x10000; /* bit 16 (fifo threshold at 8 dw) */
  527. writel(tmp, mmio + PDC_FLASH_CTL);
  528. /* clear plug/unplug flags for all ports */
  529. tmp = readl(mmio + hotplug_offset);
  530. writel(tmp | 0xff, mmio + hotplug_offset);
  531. /* mask plug/unplug ints */
  532. tmp = readl(mmio + hotplug_offset);
  533. writel(tmp | 0xff0000, mmio + hotplug_offset);
  534. /* don't initialise TBG or SLEW on 2nd generation chips */
  535. if (hp->flags & PDC_FLAG_GEN_II)
  536. return;
  537. /* reduce TBG clock to 133 Mhz. */
  538. tmp = readl(mmio + PDC_TBG_MODE);
  539. tmp &= ~0x30000; /* clear bit 17, 16*/
  540. tmp |= 0x10000; /* set bit 17:16 = 0:1 */
  541. writel(tmp, mmio + PDC_TBG_MODE);
  542. readl(mmio + PDC_TBG_MODE); /* flush */
  543. msleep(10);
  544. /* adjust slew rate control register. */
  545. tmp = readl(mmio + PDC_SLEW_CTL);
  546. tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
  547. tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
  548. writel(tmp, mmio + PDC_SLEW_CTL);
  549. }
  550. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  551. {
  552. static int printed_version;
  553. struct ata_probe_ent *probe_ent = NULL;
  554. struct pdc_host_priv *hp;
  555. unsigned long base;
  556. void __iomem *mmio_base;
  557. unsigned int board_idx = (unsigned int) ent->driver_data;
  558. int pci_dev_busy = 0;
  559. int rc;
  560. if (!printed_version++)
  561. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  562. rc = pci_enable_device(pdev);
  563. if (rc)
  564. return rc;
  565. rc = pci_request_regions(pdev, DRV_NAME);
  566. if (rc) {
  567. pci_dev_busy = 1;
  568. goto err_out;
  569. }
  570. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  571. if (rc)
  572. goto err_out_regions;
  573. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  574. if (rc)
  575. goto err_out_regions;
  576. probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
  577. if (probe_ent == NULL) {
  578. rc = -ENOMEM;
  579. goto err_out_regions;
  580. }
  581. probe_ent->dev = pci_dev_to_dev(pdev);
  582. INIT_LIST_HEAD(&probe_ent->node);
  583. mmio_base = pci_iomap(pdev, 3, 0);
  584. if (mmio_base == NULL) {
  585. rc = -ENOMEM;
  586. goto err_out_free_ent;
  587. }
  588. base = (unsigned long) mmio_base;
  589. hp = kzalloc(sizeof(*hp), GFP_KERNEL);
  590. if (hp == NULL) {
  591. rc = -ENOMEM;
  592. goto err_out_free_ent;
  593. }
  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. hp->flags |= PDC_FLAG_GEN_II;
  612. /* Fall through */
  613. case board_20319:
  614. probe_ent->n_ports = 4;
  615. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  616. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  617. probe_ent->port[2].scr_addr = base + 0x600;
  618. probe_ent->port[3].scr_addr = base + 0x700;
  619. break;
  620. case board_2057x:
  621. hp->flags |= PDC_FLAG_GEN_II;
  622. /* Fall through */
  623. case board_2037x:
  624. probe_ent->n_ports = 2;
  625. break;
  626. case board_20619:
  627. probe_ent->n_ports = 4;
  628. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  629. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  630. probe_ent->port[2].scr_addr = base + 0x600;
  631. probe_ent->port[3].scr_addr = base + 0x700;
  632. break;
  633. default:
  634. BUG();
  635. break;
  636. }
  637. pci_set_master(pdev);
  638. /* initialize adapter */
  639. pdc_host_init(board_idx, probe_ent);
  640. /* FIXME: Need any other frees than hp? */
  641. if (!ata_device_add(probe_ent))
  642. kfree(hp);
  643. kfree(probe_ent);
  644. return 0;
  645. err_out_free_ent:
  646. kfree(probe_ent);
  647. err_out_regions:
  648. pci_release_regions(pdev);
  649. err_out:
  650. if (!pci_dev_busy)
  651. pci_disable_device(pdev);
  652. return rc;
  653. }
  654. static int __init pdc_ata_init(void)
  655. {
  656. return pci_register_driver(&pdc_ata_pci_driver);
  657. }
  658. static void __exit pdc_ata_exit(void)
  659. {
  660. pci_unregister_driver(&pdc_ata_pci_driver);
  661. }
  662. MODULE_AUTHOR("Jeff Garzik");
  663. MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
  664. MODULE_LICENSE("GPL");
  665. MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
  666. MODULE_VERSION(DRV_VERSION);
  667. module_init(pdc_ata_init);
  668. module_exit(pdc_ata_exit);