sata_promise.c 20 KB

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