sata_promise.c 20 KB

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