sata_promise.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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_port_priv *pp;
  245. int rc;
  246. rc = ata_port_start(ap);
  247. if (rc)
  248. return rc;
  249. pp = kzalloc(sizeof(*pp), GFP_KERNEL);
  250. if (!pp) {
  251. rc = -ENOMEM;
  252. goto err_out;
  253. }
  254. pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  255. if (!pp->pkt) {
  256. rc = -ENOMEM;
  257. goto err_out_kfree;
  258. }
  259. ap->private_data = pp;
  260. return 0;
  261. err_out_kfree:
  262. kfree(pp);
  263. err_out:
  264. ata_port_stop(ap);
  265. return rc;
  266. }
  267. static void pdc_port_stop(struct ata_port *ap)
  268. {
  269. struct device *dev = ap->host->dev;
  270. struct pdc_port_priv *pp = ap->private_data;
  271. ap->private_data = NULL;
  272. dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
  273. kfree(pp);
  274. ata_port_stop(ap);
  275. }
  276. static void pdc_host_stop(struct ata_host *host)
  277. {
  278. struct pdc_host_priv *hp = host->private_data;
  279. ata_pci_host_stop(host);
  280. kfree(hp);
  281. }
  282. static void pdc_reset_port(struct ata_port *ap)
  283. {
  284. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
  285. unsigned int i;
  286. u32 tmp;
  287. for (i = 11; i > 0; i--) {
  288. tmp = readl(mmio);
  289. if (tmp & PDC_RESET)
  290. break;
  291. udelay(100);
  292. tmp |= PDC_RESET;
  293. writel(tmp, mmio);
  294. }
  295. tmp &= ~PDC_RESET;
  296. writel(tmp, mmio);
  297. readl(mmio); /* flush */
  298. }
  299. static void pdc_sata_phy_reset(struct ata_port *ap)
  300. {
  301. pdc_reset_port(ap);
  302. sata_phy_reset(ap);
  303. }
  304. static void pdc_pata_cbl_detect(struct ata_port *ap)
  305. {
  306. u8 tmp;
  307. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT + 0x03;
  308. tmp = readb(mmio);
  309. if (tmp & 0x01) {
  310. ap->cbl = ATA_CBL_PATA40;
  311. ap->udma_mask &= ATA_UDMA_MASK_40C;
  312. } else
  313. ap->cbl = ATA_CBL_PATA80;
  314. }
  315. static void pdc_pata_phy_reset(struct ata_port *ap)
  316. {
  317. pdc_pata_cbl_detect(ap);
  318. pdc_reset_port(ap);
  319. ata_port_probe(ap);
  320. ata_bus_reset(ap);
  321. }
  322. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
  323. {
  324. if (sc_reg > SCR_CONTROL)
  325. return 0xffffffffU;
  326. return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
  327. }
  328. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
  329. u32 val)
  330. {
  331. if (sc_reg > SCR_CONTROL)
  332. return;
  333. writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
  334. }
  335. static void pdc_qc_prep(struct ata_queued_cmd *qc)
  336. {
  337. struct pdc_port_priv *pp = qc->ap->private_data;
  338. unsigned int i;
  339. VPRINTK("ENTER\n");
  340. switch (qc->tf.protocol) {
  341. case ATA_PROT_DMA:
  342. ata_qc_prep(qc);
  343. /* fall through */
  344. case ATA_PROT_NODATA:
  345. i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
  346. qc->dev->devno, pp->pkt);
  347. if (qc->tf.flags & ATA_TFLAG_LBA48)
  348. i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
  349. else
  350. i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
  351. pdc_pkt_footer(&qc->tf, pp->pkt, i);
  352. break;
  353. default:
  354. break;
  355. }
  356. }
  357. static void pdc_eng_timeout(struct ata_port *ap)
  358. {
  359. struct ata_host *host = ap->host;
  360. u8 drv_stat;
  361. struct ata_queued_cmd *qc;
  362. unsigned long flags;
  363. DPRINTK("ENTER\n");
  364. spin_lock_irqsave(&host->lock, flags);
  365. qc = ata_qc_from_tag(ap, ap->active_tag);
  366. switch (qc->tf.protocol) {
  367. case ATA_PROT_DMA:
  368. case ATA_PROT_NODATA:
  369. ata_port_printk(ap, KERN_ERR, "command timeout\n");
  370. drv_stat = ata_wait_idle(ap);
  371. qc->err_mask |= __ac_err_mask(drv_stat);
  372. break;
  373. default:
  374. drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
  375. ata_port_printk(ap, KERN_ERR,
  376. "unknown timeout, cmd 0x%x stat 0x%x\n",
  377. qc->tf.command, drv_stat);
  378. qc->err_mask |= ac_err_mask(drv_stat);
  379. break;
  380. }
  381. spin_unlock_irqrestore(&host->lock, flags);
  382. ata_eh_qc_complete(qc);
  383. DPRINTK("EXIT\n");
  384. }
  385. static inline unsigned int pdc_host_intr( struct ata_port *ap,
  386. struct ata_queued_cmd *qc)
  387. {
  388. unsigned int handled = 0;
  389. u32 tmp;
  390. void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
  391. tmp = readl(mmio);
  392. if (tmp & PDC_ERR_MASK) {
  393. qc->err_mask |= AC_ERR_DEV;
  394. pdc_reset_port(ap);
  395. }
  396. switch (qc->tf.protocol) {
  397. case ATA_PROT_DMA:
  398. case ATA_PROT_NODATA:
  399. qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
  400. ata_qc_complete(qc);
  401. handled = 1;
  402. break;
  403. default:
  404. ap->stats.idle_irq++;
  405. break;
  406. }
  407. return handled;
  408. }
  409. static void pdc_irq_clear(struct ata_port *ap)
  410. {
  411. struct ata_host *host = ap->host;
  412. void __iomem *mmio = host->mmio_base;
  413. readl(mmio + PDC_INT_SEQMASK);
  414. }
  415. static irqreturn_t pdc_interrupt (int irq, void *dev_instance)
  416. {
  417. struct ata_host *host = dev_instance;
  418. struct ata_port *ap;
  419. u32 mask = 0;
  420. unsigned int i, tmp;
  421. unsigned int handled = 0;
  422. void __iomem *mmio_base;
  423. VPRINTK("ENTER\n");
  424. if (!host || !host->mmio_base) {
  425. VPRINTK("QUICK EXIT\n");
  426. return IRQ_NONE;
  427. }
  428. mmio_base = host->mmio_base;
  429. /* reading should also clear interrupts */
  430. mask = readl(mmio_base + PDC_INT_SEQMASK);
  431. if (mask == 0xffffffff) {
  432. VPRINTK("QUICK EXIT 2\n");
  433. return IRQ_NONE;
  434. }
  435. spin_lock(&host->lock);
  436. mask &= 0xffff; /* only 16 tags possible */
  437. if (!mask) {
  438. VPRINTK("QUICK EXIT 3\n");
  439. goto done_irq;
  440. }
  441. writel(mask, mmio_base + PDC_INT_SEQMASK);
  442. for (i = 0; i < host->n_ports; i++) {
  443. VPRINTK("port %u\n", i);
  444. ap = host->ports[i];
  445. tmp = mask & (1 << (i + 1));
  446. if (tmp && ap &&
  447. !(ap->flags & ATA_FLAG_DISABLED)) {
  448. struct ata_queued_cmd *qc;
  449. qc = ata_qc_from_tag(ap, ap->active_tag);
  450. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
  451. handled += pdc_host_intr(ap, qc);
  452. }
  453. }
  454. VPRINTK("EXIT\n");
  455. done_irq:
  456. spin_unlock(&host->lock);
  457. return IRQ_RETVAL(handled);
  458. }
  459. static inline void pdc_packet_start(struct ata_queued_cmd *qc)
  460. {
  461. struct ata_port *ap = qc->ap;
  462. struct pdc_port_priv *pp = ap->private_data;
  463. unsigned int port_no = ap->port_no;
  464. u8 seq = (u8) (port_no + 1);
  465. VPRINTK("ENTER, ap %p\n", ap);
  466. writel(0x00000001, ap->host->mmio_base + (seq * 4));
  467. readl(ap->host->mmio_base + (seq * 4)); /* flush */
  468. pp->pkt[2] = seq;
  469. wmb(); /* flush PRD, pkt writes */
  470. writel(pp->pkt_dma, (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  471. readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
  472. }
  473. static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
  474. {
  475. switch (qc->tf.protocol) {
  476. case ATA_PROT_DMA:
  477. case ATA_PROT_NODATA:
  478. pdc_packet_start(qc);
  479. return 0;
  480. case ATA_PROT_ATAPI_DMA:
  481. BUG();
  482. break;
  483. default:
  484. break;
  485. }
  486. return ata_qc_issue_prot(qc);
  487. }
  488. static void pdc_tf_load_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_tf_load(ap, tf);
  493. }
  494. static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  495. {
  496. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  497. tf->protocol == ATA_PROT_NODATA);
  498. ata_exec_command(ap, tf);
  499. }
  500. static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
  501. {
  502. port->cmd_addr = base;
  503. port->data_addr = base;
  504. port->feature_addr =
  505. port->error_addr = base + 0x4;
  506. port->nsect_addr = base + 0x8;
  507. port->lbal_addr = base + 0xc;
  508. port->lbam_addr = base + 0x10;
  509. port->lbah_addr = base + 0x14;
  510. port->device_addr = base + 0x18;
  511. port->command_addr =
  512. port->status_addr = base + 0x1c;
  513. port->altstatus_addr =
  514. port->ctl_addr = base + 0x38;
  515. }
  516. static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
  517. {
  518. void __iomem *mmio = pe->mmio_base;
  519. struct pdc_host_priv *hp = pe->private_data;
  520. int hotplug_offset = hp->hotplug_offset;
  521. u32 tmp;
  522. /*
  523. * Except for the hotplug stuff, this is voodoo from the
  524. * Promise driver. Label this entire section
  525. * "TODO: figure out why we do this"
  526. */
  527. /* enable BMR_BURST, maybe change FIFO_SHD to 8 dwords */
  528. tmp = readl(mmio + PDC_FLASH_CTL);
  529. tmp |= 0x02000; /* bit 13 (enable bmr burst) */
  530. if (!(hp->flags & PDC_FLAG_GEN_II))
  531. tmp |= 0x10000; /* bit 16 (fifo threshold at 8 dw) */
  532. writel(tmp, mmio + PDC_FLASH_CTL);
  533. /* clear plug/unplug flags for all ports */
  534. tmp = readl(mmio + hotplug_offset);
  535. writel(tmp | 0xff, mmio + hotplug_offset);
  536. /* mask plug/unplug ints */
  537. tmp = readl(mmio + hotplug_offset);
  538. writel(tmp | 0xff0000, mmio + hotplug_offset);
  539. /* don't initialise TBG or SLEW on 2nd generation chips */
  540. if (hp->flags & PDC_FLAG_GEN_II)
  541. return;
  542. /* reduce TBG clock to 133 Mhz. */
  543. tmp = readl(mmio + PDC_TBG_MODE);
  544. tmp &= ~0x30000; /* clear bit 17, 16*/
  545. tmp |= 0x10000; /* set bit 17:16 = 0:1 */
  546. writel(tmp, mmio + PDC_TBG_MODE);
  547. readl(mmio + PDC_TBG_MODE); /* flush */
  548. msleep(10);
  549. /* adjust slew rate control register. */
  550. tmp = readl(mmio + PDC_SLEW_CTL);
  551. tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
  552. tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
  553. writel(tmp, mmio + PDC_SLEW_CTL);
  554. }
  555. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  556. {
  557. static int printed_version;
  558. struct ata_probe_ent *probe_ent = NULL;
  559. struct pdc_host_priv *hp;
  560. unsigned long base;
  561. void __iomem *mmio_base;
  562. unsigned int board_idx = (unsigned int) ent->driver_data;
  563. int pci_dev_busy = 0;
  564. int rc;
  565. if (!printed_version++)
  566. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  567. rc = pci_enable_device(pdev);
  568. if (rc)
  569. return rc;
  570. rc = pci_request_regions(pdev, DRV_NAME);
  571. if (rc) {
  572. pci_dev_busy = 1;
  573. goto err_out;
  574. }
  575. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  576. if (rc)
  577. goto err_out_regions;
  578. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  579. if (rc)
  580. goto err_out_regions;
  581. probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
  582. if (probe_ent == NULL) {
  583. rc = -ENOMEM;
  584. goto err_out_regions;
  585. }
  586. probe_ent->dev = pci_dev_to_dev(pdev);
  587. INIT_LIST_HEAD(&probe_ent->node);
  588. mmio_base = pci_iomap(pdev, 3, 0);
  589. if (mmio_base == NULL) {
  590. rc = -ENOMEM;
  591. goto err_out_free_ent;
  592. }
  593. base = (unsigned long) mmio_base;
  594. hp = kzalloc(sizeof(*hp), GFP_KERNEL);
  595. if (hp == NULL) {
  596. rc = -ENOMEM;
  597. goto err_out_free_ent;
  598. }
  599. /* Set default hotplug offset */
  600. hp->hotplug_offset = PDC_SATA_PLUG_CSR;
  601. probe_ent->private_data = hp;
  602. probe_ent->sht = pdc_port_info[board_idx].sht;
  603. probe_ent->port_flags = pdc_port_info[board_idx].flags;
  604. probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
  605. probe_ent->mwdma_mask = pdc_port_info[board_idx].mwdma_mask;
  606. probe_ent->udma_mask = pdc_port_info[board_idx].udma_mask;
  607. probe_ent->port_ops = pdc_port_info[board_idx].port_ops;
  608. probe_ent->irq = pdev->irq;
  609. probe_ent->irq_flags = IRQF_SHARED;
  610. probe_ent->mmio_base = mmio_base;
  611. pdc_ata_setup_port(&probe_ent->port[0], base + 0x200);
  612. pdc_ata_setup_port(&probe_ent->port[1], base + 0x280);
  613. probe_ent->port[0].scr_addr = base + 0x400;
  614. probe_ent->port[1].scr_addr = base + 0x500;
  615. /* notice 4-port boards */
  616. switch (board_idx) {
  617. case board_40518:
  618. hp->flags |= PDC_FLAG_GEN_II;
  619. /* Override hotplug offset for SATAII150 */
  620. hp->hotplug_offset = PDC2_SATA_PLUG_CSR;
  621. /* Fall through */
  622. case board_20319:
  623. probe_ent->n_ports = 4;
  624. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  625. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  626. probe_ent->port[2].scr_addr = base + 0x600;
  627. probe_ent->port[3].scr_addr = base + 0x700;
  628. break;
  629. case board_2057x:
  630. case board_20771:
  631. hp->flags |= PDC_FLAG_GEN_II;
  632. /* Override hotplug offset for SATAII150 */
  633. hp->hotplug_offset = PDC2_SATA_PLUG_CSR;
  634. /* Fall through */
  635. case board_2037x:
  636. probe_ent->n_ports = 2;
  637. break;
  638. case board_20619:
  639. probe_ent->n_ports = 4;
  640. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  641. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  642. probe_ent->port[2].scr_addr = base + 0x600;
  643. probe_ent->port[3].scr_addr = base + 0x700;
  644. break;
  645. default:
  646. BUG();
  647. break;
  648. }
  649. pci_set_master(pdev);
  650. /* initialize adapter */
  651. pdc_host_init(board_idx, probe_ent);
  652. /* FIXME: Need any other frees than hp? */
  653. if (!ata_device_add(probe_ent))
  654. kfree(hp);
  655. kfree(probe_ent);
  656. return 0;
  657. err_out_free_ent:
  658. kfree(probe_ent);
  659. err_out_regions:
  660. pci_release_regions(pdev);
  661. err_out:
  662. if (!pci_dev_busy)
  663. pci_disable_device(pdev);
  664. return rc;
  665. }
  666. static int __init pdc_ata_init(void)
  667. {
  668. return pci_register_driver(&pdc_ata_pci_driver);
  669. }
  670. static void __exit pdc_ata_exit(void)
  671. {
  672. pci_unregister_driver(&pdc_ata_pci_driver);
  673. }
  674. MODULE_AUTHOR("Jeff Garzik");
  675. MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
  676. MODULE_LICENSE("GPL");
  677. MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
  678. MODULE_VERSION(DRV_VERSION);
  679. module_init(pdc_ata_init);
  680. module_exit(pdc_ata_exit);