sata_promise.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. /*
  2. * sata_promise.c - Promise SATA
  3. *
  4. * Maintained by: Jeff Garzik <jgarzik@pobox.com>
  5. * Please ALWAYS copy linux-ide@vger.kernel.org
  6. * on emails.
  7. *
  8. * Copyright 2003-2004 Red Hat, Inc.
  9. *
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; see the file COPYING. If not, write to
  23. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. *
  26. * libata documentation is available via 'make {ps|pdf}docs',
  27. * as Documentation/DocBook/libata.*
  28. *
  29. * Hardware information only available under NDA.
  30. *
  31. */
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <linux/pci.h>
  35. #include <linux/init.h>
  36. #include <linux/blkdev.h>
  37. #include <linux/delay.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/sched.h>
  40. #include <linux/device.h>
  41. #include <scsi/scsi_host.h>
  42. #include <scsi/scsi_cmnd.h>
  43. #include <linux/libata.h>
  44. #include <asm/io.h>
  45. #include "sata_promise.h"
  46. #define DRV_NAME "sata_promise"
  47. #define DRV_VERSION "1.05"
  48. enum {
  49. PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
  50. PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
  51. PDC_FLASH_CTL = 0x44, /* Flash control register */
  52. PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */
  53. PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */
  54. PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */
  55. PDC2_SATA_PLUG_CSR = 0x60, /* SATAII Plug control/status reg */
  56. PDC_TBG_MODE = 0x41C, /* TBG mode (not SATAII) */
  57. PDC_SLEW_CTL = 0x470, /* slew rate control reg (not SATAII) */
  58. PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) |
  59. (1<<8) | (1<<9) | (1<<10),
  60. board_2037x = 0, /* FastTrak S150 TX2plus */
  61. board_20319 = 1, /* FastTrak S150 TX4 */
  62. board_20619 = 2, /* FastTrak TX4000 */
  63. board_20771 = 3, /* FastTrak TX2300 */
  64. board_2057x = 4, /* SATAII150 Tx2plus */
  65. board_40518 = 5, /* SATAII150 Tx4 */
  66. PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */
  67. PDC_RESET = (1 << 11), /* HDMA reset */
  68. PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
  69. ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI |
  70. ATA_FLAG_PIO_POLLING,
  71. /* hp->flags bits */
  72. PDC_FLAG_GEN_II = (1 << 0),
  73. };
  74. struct pdc_port_priv {
  75. u8 *pkt;
  76. dma_addr_t pkt_dma;
  77. };
  78. struct pdc_host_priv {
  79. unsigned long flags;
  80. int hotplug_offset;
  81. };
  82. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
  83. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
  84. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
  85. static irqreturn_t pdc_interrupt (int irq, void *dev_instance);
  86. static void pdc_eng_timeout(struct ata_port *ap);
  87. static int pdc_port_start(struct ata_port *ap);
  88. static void pdc_port_stop(struct ata_port *ap);
  89. static void pdc_pata_phy_reset(struct ata_port *ap);
  90. static void pdc_sata_phy_reset(struct ata_port *ap);
  91. static void pdc_qc_prep(struct ata_queued_cmd *qc);
  92. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  93. static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  94. static void pdc_irq_clear(struct ata_port *ap);
  95. static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
  96. static void pdc_host_stop(struct ata_host *host);
  97. static struct scsi_host_template pdc_ata_sht = {
  98. .module = THIS_MODULE,
  99. .name = DRV_NAME,
  100. .ioctl = ata_scsi_ioctl,
  101. .queuecommand = ata_scsi_queuecmd,
  102. .can_queue = ATA_DEF_QUEUE,
  103. .this_id = ATA_SHT_THIS_ID,
  104. .sg_tablesize = LIBATA_MAX_PRD,
  105. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  106. .emulated = ATA_SHT_EMULATED,
  107. .use_clustering = ATA_SHT_USE_CLUSTERING,
  108. .proc_name = DRV_NAME,
  109. .dma_boundary = ATA_DMA_BOUNDARY,
  110. .slave_configure = ata_scsi_slave_config,
  111. .slave_destroy = ata_scsi_slave_destroy,
  112. .bios_param = ata_std_bios_param,
  113. };
  114. static const struct ata_port_operations pdc_sata_ops = {
  115. .port_disable = ata_port_disable,
  116. .tf_load = pdc_tf_load_mmio,
  117. .tf_read = ata_tf_read,
  118. .check_status = ata_check_status,
  119. .exec_command = pdc_exec_command_mmio,
  120. .dev_select = ata_std_dev_select,
  121. .phy_reset = pdc_sata_phy_reset,
  122. .qc_prep = pdc_qc_prep,
  123. .qc_issue = pdc_qc_issue_prot,
  124. .eng_timeout = pdc_eng_timeout,
  125. .data_xfer = ata_mmio_data_xfer,
  126. .irq_handler = pdc_interrupt,
  127. .irq_clear = pdc_irq_clear,
  128. .scr_read = pdc_sata_scr_read,
  129. .scr_write = pdc_sata_scr_write,
  130. .port_start = pdc_port_start,
  131. .port_stop = pdc_port_stop,
  132. .host_stop = pdc_host_stop,
  133. };
  134. static const struct ata_port_operations pdc_pata_ops = {
  135. .port_disable = ata_port_disable,
  136. .tf_load = pdc_tf_load_mmio,
  137. .tf_read = ata_tf_read,
  138. .check_status = ata_check_status,
  139. .exec_command = pdc_exec_command_mmio,
  140. .dev_select = ata_std_dev_select,
  141. .phy_reset = pdc_pata_phy_reset,
  142. .qc_prep = pdc_qc_prep,
  143. .qc_issue = pdc_qc_issue_prot,
  144. .data_xfer = ata_mmio_data_xfer,
  145. .eng_timeout = pdc_eng_timeout,
  146. .irq_handler = pdc_interrupt,
  147. .irq_clear = pdc_irq_clear,
  148. .port_start = pdc_port_start,
  149. .port_stop = pdc_port_stop,
  150. .host_stop = pdc_host_stop,
  151. };
  152. static const struct ata_port_info pdc_port_info[] = {
  153. /* board_2037x */
  154. {
  155. .sht = &pdc_ata_sht,
  156. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
  157. .pio_mask = 0x1f, /* pio0-4 */
  158. .mwdma_mask = 0x07, /* mwdma0-2 */
  159. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  160. .port_ops = &pdc_sata_ops,
  161. },
  162. /* board_20319 */
  163. {
  164. .sht = &pdc_ata_sht,
  165. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
  166. .pio_mask = 0x1f, /* pio0-4 */
  167. .mwdma_mask = 0x07, /* mwdma0-2 */
  168. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  169. .port_ops = &pdc_sata_ops,
  170. },
  171. /* board_20619 */
  172. {
  173. .sht = &pdc_ata_sht,
  174. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS,
  175. .pio_mask = 0x1f, /* pio0-4 */
  176. .mwdma_mask = 0x07, /* mwdma0-2 */
  177. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  178. .port_ops = &pdc_pata_ops,
  179. },
  180. /* board_20771 */
  181. {
  182. .sht = &pdc_ata_sht,
  183. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
  184. .pio_mask = 0x1f, /* pio0-4 */
  185. .mwdma_mask = 0x07, /* mwdma0-2 */
  186. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  187. .port_ops = &pdc_sata_ops,
  188. },
  189. /* board_2057x */
  190. {
  191. .sht = &pdc_ata_sht,
  192. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
  193. .pio_mask = 0x1f, /* pio0-4 */
  194. .mwdma_mask = 0x07, /* mwdma0-2 */
  195. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  196. .port_ops = &pdc_sata_ops,
  197. },
  198. /* board_40518 */
  199. {
  200. .sht = &pdc_ata_sht,
  201. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA,
  202. .pio_mask = 0x1f, /* pio0-4 */
  203. .mwdma_mask = 0x07, /* mwdma0-2 */
  204. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  205. .port_ops = &pdc_sata_ops,
  206. },
  207. };
  208. static const struct pci_device_id pdc_ata_pci_tbl[] = {
  209. { PCI_VDEVICE(PROMISE, 0x3371), board_2037x },
  210. { PCI_VDEVICE(PROMISE, 0x3373), board_2037x },
  211. { PCI_VDEVICE(PROMISE, 0x3375), board_2037x },
  212. { PCI_VDEVICE(PROMISE, 0x3376), board_2037x },
  213. { PCI_VDEVICE(PROMISE, 0x3570), board_2057x },
  214. { PCI_VDEVICE(PROMISE, 0x3571), board_2057x },
  215. { PCI_VDEVICE(PROMISE, 0x3574), board_2057x },
  216. { PCI_VDEVICE(PROMISE, 0x3d73), board_2057x },
  217. { PCI_VDEVICE(PROMISE, 0x3d75), board_2057x },
  218. { PCI_VDEVICE(PROMISE, 0x3318), board_20319 },
  219. { PCI_VDEVICE(PROMISE, 0x3319), board_20319 },
  220. { PCI_VDEVICE(PROMISE, 0x3515), board_20319 },
  221. { PCI_VDEVICE(PROMISE, 0x3519), board_20319 },
  222. { PCI_VDEVICE(PROMISE, 0x3d17), board_40518 },
  223. { PCI_VDEVICE(PROMISE, 0x3d18), board_40518 },
  224. { PCI_VDEVICE(PROMISE, 0x6629), board_20619 },
  225. /* TODO: remove all associated board_20771 code, as it completely
  226. * duplicates board_2037x code, unless reason for separation can be
  227. * divined.
  228. */
  229. #if 0
  230. { PCI_VDEVICE(PROMISE, 0x3570), board_20771 },
  231. #endif
  232. { PCI_VDEVICE(PROMISE, 0x3577), board_20771 },
  233. { } /* terminate list */
  234. };
  235. static struct pci_driver pdc_ata_pci_driver = {
  236. .name = DRV_NAME,
  237. .id_table = pdc_ata_pci_tbl,
  238. .probe = pdc_ata_init_one,
  239. .remove = ata_pci_remove_one,
  240. };
  241. static int pdc_port_start(struct ata_port *ap)
  242. {
  243. struct device *dev = ap->host->dev;
  244. struct pdc_host_priv *hp = ap->host->private_data;
  245. struct pdc_port_priv *pp;
  246. int rc;
  247. rc = ata_port_start(ap);
  248. if (rc)
  249. return rc;
  250. pp = kzalloc(sizeof(*pp), GFP_KERNEL);
  251. if (!pp) {
  252. rc = -ENOMEM;
  253. goto err_out;
  254. }
  255. pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  256. if (!pp->pkt) {
  257. rc = -ENOMEM;
  258. goto err_out_kfree;
  259. }
  260. ap->private_data = pp;
  261. /* fix up PHYMODE4 align timing */
  262. if ((hp->flags & PDC_FLAG_GEN_II) && sata_scr_valid(ap)) {
  263. void __iomem *mmio = (void __iomem *) ap->ioaddr.scr_addr;
  264. unsigned int tmp;
  265. tmp = readl(mmio + 0x014);
  266. tmp = (tmp & ~3) | 1; /* set bits 1:0 = 0:1 */
  267. writel(tmp, mmio + 0x014);
  268. }
  269. return 0;
  270. err_out_kfree:
  271. kfree(pp);
  272. err_out:
  273. ata_port_stop(ap);
  274. return rc;
  275. }
  276. static void pdc_port_stop(struct ata_port *ap)
  277. {
  278. struct device *dev = ap->host->dev;
  279. struct pdc_port_priv *pp = ap->private_data;
  280. ap->private_data = NULL;
  281. dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
  282. kfree(pp);
  283. ata_port_stop(ap);
  284. }
  285. static void pdc_host_stop(struct ata_host *host)
  286. {
  287. struct pdc_host_priv *hp = host->private_data;
  288. ata_pci_host_stop(host);
  289. kfree(hp);
  290. }
  291. static void pdc_reset_port(struct ata_port *ap)
  292. {
  293. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
  294. unsigned int i;
  295. u32 tmp;
  296. for (i = 11; i > 0; i--) {
  297. tmp = readl(mmio);
  298. if (tmp & PDC_RESET)
  299. break;
  300. udelay(100);
  301. tmp |= PDC_RESET;
  302. writel(tmp, mmio);
  303. }
  304. tmp &= ~PDC_RESET;
  305. writel(tmp, mmio);
  306. readl(mmio); /* flush */
  307. }
  308. static void pdc_sata_phy_reset(struct ata_port *ap)
  309. {
  310. pdc_reset_port(ap);
  311. sata_phy_reset(ap);
  312. }
  313. static void pdc_pata_cbl_detect(struct ata_port *ap)
  314. {
  315. u8 tmp;
  316. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT + 0x03;
  317. tmp = readb(mmio);
  318. if (tmp & 0x01) {
  319. ap->cbl = ATA_CBL_PATA40;
  320. ap->udma_mask &= ATA_UDMA_MASK_40C;
  321. } else
  322. ap->cbl = ATA_CBL_PATA80;
  323. }
  324. static void pdc_pata_phy_reset(struct ata_port *ap)
  325. {
  326. pdc_pata_cbl_detect(ap);
  327. pdc_reset_port(ap);
  328. ata_port_probe(ap);
  329. ata_bus_reset(ap);
  330. }
  331. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
  332. {
  333. if (sc_reg > SCR_CONTROL)
  334. return 0xffffffffU;
  335. return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
  336. }
  337. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
  338. u32 val)
  339. {
  340. if (sc_reg > SCR_CONTROL)
  341. return;
  342. writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
  343. }
  344. static void pdc_qc_prep(struct ata_queued_cmd *qc)
  345. {
  346. struct pdc_port_priv *pp = qc->ap->private_data;
  347. unsigned int i;
  348. VPRINTK("ENTER\n");
  349. switch (qc->tf.protocol) {
  350. case ATA_PROT_DMA:
  351. ata_qc_prep(qc);
  352. /* fall through */
  353. case ATA_PROT_NODATA:
  354. i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
  355. qc->dev->devno, pp->pkt);
  356. if (qc->tf.flags & ATA_TFLAG_LBA48)
  357. i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
  358. else
  359. i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
  360. pdc_pkt_footer(&qc->tf, pp->pkt, i);
  361. break;
  362. default:
  363. break;
  364. }
  365. }
  366. static void pdc_eng_timeout(struct ata_port *ap)
  367. {
  368. struct ata_host *host = ap->host;
  369. u8 drv_stat;
  370. struct ata_queued_cmd *qc;
  371. unsigned long flags;
  372. DPRINTK("ENTER\n");
  373. spin_lock_irqsave(&host->lock, flags);
  374. qc = ata_qc_from_tag(ap, ap->active_tag);
  375. switch (qc->tf.protocol) {
  376. case ATA_PROT_DMA:
  377. case ATA_PROT_NODATA:
  378. ata_port_printk(ap, KERN_ERR, "command timeout\n");
  379. drv_stat = ata_wait_idle(ap);
  380. qc->err_mask |= __ac_err_mask(drv_stat);
  381. break;
  382. default:
  383. drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
  384. ata_port_printk(ap, KERN_ERR,
  385. "unknown timeout, cmd 0x%x stat 0x%x\n",
  386. qc->tf.command, drv_stat);
  387. qc->err_mask |= ac_err_mask(drv_stat);
  388. break;
  389. }
  390. spin_unlock_irqrestore(&host->lock, flags);
  391. ata_eh_qc_complete(qc);
  392. DPRINTK("EXIT\n");
  393. }
  394. static inline unsigned int pdc_host_intr( struct ata_port *ap,
  395. struct ata_queued_cmd *qc)
  396. {
  397. unsigned int handled = 0;
  398. u32 tmp;
  399. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
  400. tmp = readl(mmio);
  401. if (tmp & PDC_ERR_MASK) {
  402. qc->err_mask |= AC_ERR_DEV;
  403. pdc_reset_port(ap);
  404. }
  405. switch (qc->tf.protocol) {
  406. case ATA_PROT_DMA:
  407. case ATA_PROT_NODATA:
  408. qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
  409. ata_qc_complete(qc);
  410. handled = 1;
  411. break;
  412. default:
  413. ap->stats.idle_irq++;
  414. break;
  415. }
  416. return handled;
  417. }
  418. static void pdc_irq_clear(struct ata_port *ap)
  419. {
  420. struct ata_host *host = ap->host;
  421. void __iomem *mmio = host->mmio_base;
  422. readl(mmio + PDC_INT_SEQMASK);
  423. }
  424. static irqreturn_t pdc_interrupt (int irq, void *dev_instance)
  425. {
  426. struct ata_host *host = dev_instance;
  427. struct ata_port *ap;
  428. u32 mask = 0;
  429. unsigned int i, tmp;
  430. unsigned int handled = 0;
  431. void __iomem *mmio_base;
  432. VPRINTK("ENTER\n");
  433. if (!host || !host->mmio_base) {
  434. VPRINTK("QUICK EXIT\n");
  435. return IRQ_NONE;
  436. }
  437. mmio_base = host->mmio_base;
  438. /* reading should also clear interrupts */
  439. mask = readl(mmio_base + PDC_INT_SEQMASK);
  440. if (mask == 0xffffffff) {
  441. VPRINTK("QUICK EXIT 2\n");
  442. return IRQ_NONE;
  443. }
  444. spin_lock(&host->lock);
  445. mask &= 0xffff; /* only 16 tags possible */
  446. if (!mask) {
  447. VPRINTK("QUICK EXIT 3\n");
  448. goto done_irq;
  449. }
  450. writel(mask, mmio_base + PDC_INT_SEQMASK);
  451. for (i = 0; i < host->n_ports; i++) {
  452. VPRINTK("port %u\n", i);
  453. ap = host->ports[i];
  454. tmp = mask & (1 << (i + 1));
  455. if (tmp && ap &&
  456. !(ap->flags & ATA_FLAG_DISABLED)) {
  457. struct ata_queued_cmd *qc;
  458. qc = ata_qc_from_tag(ap, ap->active_tag);
  459. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
  460. handled += pdc_host_intr(ap, qc);
  461. }
  462. }
  463. VPRINTK("EXIT\n");
  464. done_irq:
  465. spin_unlock(&host->lock);
  466. return IRQ_RETVAL(handled);
  467. }
  468. static inline void pdc_packet_start(struct ata_queued_cmd *qc)
  469. {
  470. struct ata_port *ap = qc->ap;
  471. struct pdc_port_priv *pp = ap->private_data;
  472. unsigned int port_no = ap->port_no;
  473. u8 seq = (u8) (port_no + 1);
  474. VPRINTK("ENTER, ap %p\n", ap);
  475. writel(0x00000001, ap->host->mmio_base + (seq * 4));
  476. readl(ap->host->mmio_base + (seq * 4)); /* flush */
  477. pp->pkt[2] = seq;
  478. wmb(); /* flush PRD, pkt writes */
  479. writel(pp->pkt_dma, (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  480. readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
  481. }
  482. static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
  483. {
  484. switch (qc->tf.protocol) {
  485. case ATA_PROT_DMA:
  486. case ATA_PROT_NODATA:
  487. pdc_packet_start(qc);
  488. return 0;
  489. case ATA_PROT_ATAPI_DMA:
  490. BUG();
  491. break;
  492. default:
  493. break;
  494. }
  495. return ata_qc_issue_prot(qc);
  496. }
  497. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  498. {
  499. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  500. tf->protocol == ATA_PROT_NODATA);
  501. ata_tf_load(ap, tf);
  502. }
  503. static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  504. {
  505. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  506. tf->protocol == ATA_PROT_NODATA);
  507. ata_exec_command(ap, tf);
  508. }
  509. static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
  510. {
  511. port->cmd_addr = base;
  512. port->data_addr = base;
  513. port->feature_addr =
  514. port->error_addr = base + 0x4;
  515. port->nsect_addr = base + 0x8;
  516. port->lbal_addr = base + 0xc;
  517. port->lbam_addr = base + 0x10;
  518. port->lbah_addr = base + 0x14;
  519. port->device_addr = base + 0x18;
  520. port->command_addr =
  521. port->status_addr = base + 0x1c;
  522. port->altstatus_addr =
  523. port->ctl_addr = base + 0x38;
  524. }
  525. static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
  526. {
  527. void __iomem *mmio = pe->mmio_base;
  528. struct pdc_host_priv *hp = pe->private_data;
  529. int hotplug_offset = hp->hotplug_offset;
  530. u32 tmp;
  531. /*
  532. * Except for the hotplug stuff, this is voodoo from the
  533. * Promise driver. Label this entire section
  534. * "TODO: figure out why we do this"
  535. */
  536. /* enable BMR_BURST, maybe change FIFO_SHD to 8 dwords */
  537. tmp = readl(mmio + PDC_FLASH_CTL);
  538. tmp |= 0x02000; /* bit 13 (enable bmr burst) */
  539. if (!(hp->flags & PDC_FLAG_GEN_II))
  540. tmp |= 0x10000; /* bit 16 (fifo threshold at 8 dw) */
  541. writel(tmp, mmio + PDC_FLASH_CTL);
  542. /* clear plug/unplug flags for all ports */
  543. tmp = readl(mmio + hotplug_offset);
  544. writel(tmp | 0xff, mmio + hotplug_offset);
  545. /* mask plug/unplug ints */
  546. tmp = readl(mmio + hotplug_offset);
  547. writel(tmp | 0xff0000, mmio + hotplug_offset);
  548. /* don't initialise TBG or SLEW on 2nd generation chips */
  549. if (hp->flags & PDC_FLAG_GEN_II)
  550. return;
  551. /* reduce TBG clock to 133 Mhz. */
  552. tmp = readl(mmio + PDC_TBG_MODE);
  553. tmp &= ~0x30000; /* clear bit 17, 16*/
  554. tmp |= 0x10000; /* set bit 17:16 = 0:1 */
  555. writel(tmp, mmio + PDC_TBG_MODE);
  556. readl(mmio + PDC_TBG_MODE); /* flush */
  557. msleep(10);
  558. /* adjust slew rate control register. */
  559. tmp = readl(mmio + PDC_SLEW_CTL);
  560. tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
  561. tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
  562. writel(tmp, mmio + PDC_SLEW_CTL);
  563. }
  564. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  565. {
  566. static int printed_version;
  567. struct ata_probe_ent *probe_ent = NULL;
  568. struct pdc_host_priv *hp;
  569. unsigned long base;
  570. void __iomem *mmio_base;
  571. unsigned int board_idx = (unsigned int) ent->driver_data;
  572. int pci_dev_busy = 0;
  573. int rc;
  574. if (!printed_version++)
  575. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  576. rc = pci_enable_device(pdev);
  577. if (rc)
  578. return rc;
  579. rc = pci_request_regions(pdev, DRV_NAME);
  580. if (rc) {
  581. pci_dev_busy = 1;
  582. goto err_out;
  583. }
  584. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  585. if (rc)
  586. goto err_out_regions;
  587. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  588. if (rc)
  589. goto err_out_regions;
  590. probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
  591. if (probe_ent == NULL) {
  592. rc = -ENOMEM;
  593. goto err_out_regions;
  594. }
  595. probe_ent->dev = pci_dev_to_dev(pdev);
  596. INIT_LIST_HEAD(&probe_ent->node);
  597. mmio_base = pci_iomap(pdev, 3, 0);
  598. if (mmio_base == NULL) {
  599. rc = -ENOMEM;
  600. goto err_out_free_ent;
  601. }
  602. base = (unsigned long) mmio_base;
  603. hp = kzalloc(sizeof(*hp), GFP_KERNEL);
  604. if (hp == NULL) {
  605. rc = -ENOMEM;
  606. goto err_out_free_ent;
  607. }
  608. /* Set default hotplug offset */
  609. hp->hotplug_offset = PDC_SATA_PLUG_CSR;
  610. probe_ent->private_data = hp;
  611. probe_ent->sht = pdc_port_info[board_idx].sht;
  612. probe_ent->port_flags = pdc_port_info[board_idx].flags;
  613. probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
  614. probe_ent->mwdma_mask = pdc_port_info[board_idx].mwdma_mask;
  615. probe_ent->udma_mask = pdc_port_info[board_idx].udma_mask;
  616. probe_ent->port_ops = pdc_port_info[board_idx].port_ops;
  617. probe_ent->irq = pdev->irq;
  618. probe_ent->irq_flags = IRQF_SHARED;
  619. probe_ent->mmio_base = mmio_base;
  620. pdc_ata_setup_port(&probe_ent->port[0], base + 0x200);
  621. pdc_ata_setup_port(&probe_ent->port[1], base + 0x280);
  622. probe_ent->port[0].scr_addr = base + 0x400;
  623. probe_ent->port[1].scr_addr = base + 0x500;
  624. /* notice 4-port boards */
  625. switch (board_idx) {
  626. case board_40518:
  627. hp->flags |= PDC_FLAG_GEN_II;
  628. /* Override hotplug offset for SATAII150 */
  629. hp->hotplug_offset = PDC2_SATA_PLUG_CSR;
  630. /* Fall through */
  631. case board_20319:
  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. case board_2057x:
  639. case board_20771:
  640. hp->flags |= PDC_FLAG_GEN_II;
  641. /* Override hotplug offset for SATAII150 */
  642. hp->hotplug_offset = PDC2_SATA_PLUG_CSR;
  643. /* Fall through */
  644. case board_2037x:
  645. probe_ent->n_ports = 2;
  646. break;
  647. case board_20619:
  648. probe_ent->n_ports = 4;
  649. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  650. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  651. probe_ent->port[2].scr_addr = base + 0x600;
  652. probe_ent->port[3].scr_addr = base + 0x700;
  653. break;
  654. default:
  655. BUG();
  656. break;
  657. }
  658. pci_set_master(pdev);
  659. /* initialize adapter */
  660. pdc_host_init(board_idx, probe_ent);
  661. /* FIXME: Need any other frees than hp? */
  662. if (!ata_device_add(probe_ent))
  663. kfree(hp);
  664. kfree(probe_ent);
  665. return 0;
  666. err_out_free_ent:
  667. kfree(probe_ent);
  668. err_out_regions:
  669. pci_release_regions(pdev);
  670. err_out:
  671. if (!pci_dev_busy)
  672. pci_disable_device(pdev);
  673. return rc;
  674. }
  675. static int __init pdc_ata_init(void)
  676. {
  677. return pci_register_driver(&pdc_ata_pci_driver);
  678. }
  679. static void __exit pdc_ata_exit(void)
  680. {
  681. pci_unregister_driver(&pdc_ata_pci_driver);
  682. }
  683. MODULE_AUTHOR("Jeff Garzik");
  684. MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
  685. MODULE_LICENSE("GPL");
  686. MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
  687. MODULE_VERSION(DRV_VERSION);
  688. module_init(pdc_ata_init);
  689. module_exit(pdc_ata_exit);