sata_promise.c 19 KB

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