sata_promise.c 19 KB

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