pdc_adma.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * pdc_adma.c - Pacific Digital Corporation ADMA
  3. *
  4. * Maintained by: Mark Lord <mlord@pobox.com>
  5. *
  6. * Copyright 2005 Mark Lord
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; see the file COPYING. If not, write to
  20. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. *
  23. * libata documentation is available via 'make {ps|pdf}docs',
  24. * as Documentation/DocBook/libata.*
  25. *
  26. *
  27. * Supports ATA disks in single-packet ADMA mode.
  28. * Uses PIO for everything else.
  29. *
  30. * TODO: Use ADMA transfers for ATAPI devices, when possible.
  31. * This requires careful attention to a number of quirks of the chip.
  32. *
  33. */
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/gfp.h>
  37. #include <linux/pci.h>
  38. #include <linux/init.h>
  39. #include <linux/blkdev.h>
  40. #include <linux/delay.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/device.h>
  43. #include <scsi/scsi_host.h>
  44. #include <linux/libata.h>
  45. #define DRV_NAME "pdc_adma"
  46. #define DRV_VERSION "1.0"
  47. /* macro to calculate base address for ATA regs */
  48. #define ADMA_ATA_REGS(base, port_no) ((base) + ((port_no) * 0x40))
  49. /* macro to calculate base address for ADMA regs */
  50. #define ADMA_REGS(base, port_no) ((base) + 0x80 + ((port_no) * 0x20))
  51. /* macro to obtain addresses from ata_port */
  52. #define ADMA_PORT_REGS(ap) \
  53. ADMA_REGS((ap)->host->iomap[ADMA_MMIO_BAR], ap->port_no)
  54. enum {
  55. ADMA_MMIO_BAR = 4,
  56. ADMA_PORTS = 2,
  57. ADMA_CPB_BYTES = 40,
  58. ADMA_PRD_BYTES = LIBATA_MAX_PRD * 16,
  59. ADMA_PKT_BYTES = ADMA_CPB_BYTES + ADMA_PRD_BYTES,
  60. ADMA_DMA_BOUNDARY = 0xffffffff,
  61. /* global register offsets */
  62. ADMA_MODE_LOCK = 0x00c7,
  63. /* per-channel register offsets */
  64. ADMA_CONTROL = 0x0000, /* ADMA control */
  65. ADMA_STATUS = 0x0002, /* ADMA status */
  66. ADMA_CPB_COUNT = 0x0004, /* CPB count */
  67. ADMA_CPB_CURRENT = 0x000c, /* current CPB address */
  68. ADMA_CPB_NEXT = 0x000c, /* next CPB address */
  69. ADMA_CPB_LOOKUP = 0x0010, /* CPB lookup table */
  70. ADMA_FIFO_IN = 0x0014, /* input FIFO threshold */
  71. ADMA_FIFO_OUT = 0x0016, /* output FIFO threshold */
  72. /* ADMA_CONTROL register bits */
  73. aNIEN = (1 << 8), /* irq mask: 1==masked */
  74. aGO = (1 << 7), /* packet trigger ("Go!") */
  75. aRSTADM = (1 << 5), /* ADMA logic reset */
  76. aPIOMD4 = 0x0003, /* PIO mode 4 */
  77. /* ADMA_STATUS register bits */
  78. aPSD = (1 << 6),
  79. aUIRQ = (1 << 4),
  80. aPERR = (1 << 0),
  81. /* CPB bits */
  82. cDONE = (1 << 0),
  83. cATERR = (1 << 3),
  84. cVLD = (1 << 0),
  85. cDAT = (1 << 2),
  86. cIEN = (1 << 3),
  87. /* PRD bits */
  88. pORD = (1 << 4),
  89. pDIRO = (1 << 5),
  90. pEND = (1 << 7),
  91. /* ATA register flags */
  92. rIGN = (1 << 5),
  93. rEND = (1 << 7),
  94. /* ATA register addresses */
  95. ADMA_REGS_CONTROL = 0x0e,
  96. ADMA_REGS_SECTOR_COUNT = 0x12,
  97. ADMA_REGS_LBA_LOW = 0x13,
  98. ADMA_REGS_LBA_MID = 0x14,
  99. ADMA_REGS_LBA_HIGH = 0x15,
  100. ADMA_REGS_DEVICE = 0x16,
  101. ADMA_REGS_COMMAND = 0x17,
  102. /* PCI device IDs */
  103. board_1841_idx = 0, /* ADMA 2-port controller */
  104. };
  105. typedef enum { adma_state_idle, adma_state_pkt, adma_state_mmio } adma_state_t;
  106. struct adma_port_priv {
  107. u8 *pkt;
  108. dma_addr_t pkt_dma;
  109. adma_state_t state;
  110. };
  111. static int adma_ata_init_one(struct pci_dev *pdev,
  112. const struct pci_device_id *ent);
  113. static int adma_port_start(struct ata_port *ap);
  114. static void adma_port_stop(struct ata_port *ap);
  115. static void adma_qc_prep(struct ata_queued_cmd *qc);
  116. static unsigned int adma_qc_issue(struct ata_queued_cmd *qc);
  117. static int adma_check_atapi_dma(struct ata_queued_cmd *qc);
  118. static void adma_freeze(struct ata_port *ap);
  119. static void adma_thaw(struct ata_port *ap);
  120. static int adma_prereset(struct ata_link *link, unsigned long deadline);
  121. static struct scsi_host_template adma_ata_sht = {
  122. ATA_BASE_SHT(DRV_NAME),
  123. .sg_tablesize = LIBATA_MAX_PRD,
  124. .dma_boundary = ADMA_DMA_BOUNDARY,
  125. };
  126. static struct ata_port_operations adma_ata_ops = {
  127. .inherits = &ata_sff_port_ops,
  128. .lost_interrupt = ATA_OP_NULL,
  129. .check_atapi_dma = adma_check_atapi_dma,
  130. .qc_prep = adma_qc_prep,
  131. .qc_issue = adma_qc_issue,
  132. .freeze = adma_freeze,
  133. .thaw = adma_thaw,
  134. .prereset = adma_prereset,
  135. .port_start = adma_port_start,
  136. .port_stop = adma_port_stop,
  137. };
  138. static struct ata_port_info adma_port_info[] = {
  139. /* board_1841_idx */
  140. {
  141. .flags = ATA_FLAG_SLAVE_POSS |
  142. ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO |
  143. ATA_FLAG_PIO_POLLING,
  144. .pio_mask = ATA_PIO4_ONLY,
  145. .udma_mask = ATA_UDMA4,
  146. .port_ops = &adma_ata_ops,
  147. },
  148. };
  149. static const struct pci_device_id adma_ata_pci_tbl[] = {
  150. { PCI_VDEVICE(PDC, 0x1841), board_1841_idx },
  151. { } /* terminate list */
  152. };
  153. static struct pci_driver adma_ata_pci_driver = {
  154. .name = DRV_NAME,
  155. .id_table = adma_ata_pci_tbl,
  156. .probe = adma_ata_init_one,
  157. .remove = ata_pci_remove_one,
  158. };
  159. static int adma_check_atapi_dma(struct ata_queued_cmd *qc)
  160. {
  161. return 1; /* ATAPI DMA not yet supported */
  162. }
  163. static void adma_reset_engine(struct ata_port *ap)
  164. {
  165. void __iomem *chan = ADMA_PORT_REGS(ap);
  166. /* reset ADMA to idle state */
  167. writew(aPIOMD4 | aNIEN | aRSTADM, chan + ADMA_CONTROL);
  168. udelay(2);
  169. writew(aPIOMD4, chan + ADMA_CONTROL);
  170. udelay(2);
  171. }
  172. static void adma_reinit_engine(struct ata_port *ap)
  173. {
  174. struct adma_port_priv *pp = ap->private_data;
  175. void __iomem *chan = ADMA_PORT_REGS(ap);
  176. /* mask/clear ATA interrupts */
  177. writeb(ATA_NIEN, ap->ioaddr.ctl_addr);
  178. ata_sff_check_status(ap);
  179. /* reset the ADMA engine */
  180. adma_reset_engine(ap);
  181. /* set in-FIFO threshold to 0x100 */
  182. writew(0x100, chan + ADMA_FIFO_IN);
  183. /* set CPB pointer */
  184. writel((u32)pp->pkt_dma, chan + ADMA_CPB_NEXT);
  185. /* set out-FIFO threshold to 0x100 */
  186. writew(0x100, chan + ADMA_FIFO_OUT);
  187. /* set CPB count */
  188. writew(1, chan + ADMA_CPB_COUNT);
  189. /* read/discard ADMA status */
  190. readb(chan + ADMA_STATUS);
  191. }
  192. static inline void adma_enter_reg_mode(struct ata_port *ap)
  193. {
  194. void __iomem *chan = ADMA_PORT_REGS(ap);
  195. writew(aPIOMD4, chan + ADMA_CONTROL);
  196. readb(chan + ADMA_STATUS); /* flush */
  197. }
  198. static void adma_freeze(struct ata_port *ap)
  199. {
  200. void __iomem *chan = ADMA_PORT_REGS(ap);
  201. /* mask/clear ATA interrupts */
  202. writeb(ATA_NIEN, ap->ioaddr.ctl_addr);
  203. ata_sff_check_status(ap);
  204. /* reset ADMA to idle state */
  205. writew(aPIOMD4 | aNIEN | aRSTADM, chan + ADMA_CONTROL);
  206. udelay(2);
  207. writew(aPIOMD4 | aNIEN, chan + ADMA_CONTROL);
  208. udelay(2);
  209. }
  210. static void adma_thaw(struct ata_port *ap)
  211. {
  212. adma_reinit_engine(ap);
  213. }
  214. static int adma_prereset(struct ata_link *link, unsigned long deadline)
  215. {
  216. struct ata_port *ap = link->ap;
  217. struct adma_port_priv *pp = ap->private_data;
  218. if (pp->state != adma_state_idle) /* healthy paranoia */
  219. pp->state = adma_state_mmio;
  220. adma_reinit_engine(ap);
  221. return ata_sff_prereset(link, deadline);
  222. }
  223. static int adma_fill_sg(struct ata_queued_cmd *qc)
  224. {
  225. struct scatterlist *sg;
  226. struct ata_port *ap = qc->ap;
  227. struct adma_port_priv *pp = ap->private_data;
  228. u8 *buf = pp->pkt, *last_buf = NULL;
  229. int i = (2 + buf[3]) * 8;
  230. u8 pFLAGS = pORD | ((qc->tf.flags & ATA_TFLAG_WRITE) ? pDIRO : 0);
  231. unsigned int si;
  232. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  233. u32 addr;
  234. u32 len;
  235. addr = (u32)sg_dma_address(sg);
  236. *(__le32 *)(buf + i) = cpu_to_le32(addr);
  237. i += 4;
  238. len = sg_dma_len(sg) >> 3;
  239. *(__le32 *)(buf + i) = cpu_to_le32(len);
  240. i += 4;
  241. last_buf = &buf[i];
  242. buf[i++] = pFLAGS;
  243. buf[i++] = qc->dev->dma_mode & 0xf;
  244. buf[i++] = 0; /* pPKLW */
  245. buf[i++] = 0; /* reserved */
  246. *(__le32 *)(buf + i) =
  247. (pFLAGS & pEND) ? 0 : cpu_to_le32(pp->pkt_dma + i + 4);
  248. i += 4;
  249. VPRINTK("PRD[%u] = (0x%lX, 0x%X)\n", i/4,
  250. (unsigned long)addr, len);
  251. }
  252. if (likely(last_buf))
  253. *last_buf |= pEND;
  254. return i;
  255. }
  256. static void adma_qc_prep(struct ata_queued_cmd *qc)
  257. {
  258. struct adma_port_priv *pp = qc->ap->private_data;
  259. u8 *buf = pp->pkt;
  260. u32 pkt_dma = (u32)pp->pkt_dma;
  261. int i = 0;
  262. VPRINTK("ENTER\n");
  263. adma_enter_reg_mode(qc->ap);
  264. if (qc->tf.protocol != ATA_PROT_DMA) {
  265. ata_sff_qc_prep(qc);
  266. return;
  267. }
  268. buf[i++] = 0; /* Response flags */
  269. buf[i++] = 0; /* reserved */
  270. buf[i++] = cVLD | cDAT | cIEN;
  271. i++; /* cLEN, gets filled in below */
  272. *(__le32 *)(buf+i) = cpu_to_le32(pkt_dma); /* cNCPB */
  273. i += 4; /* cNCPB */
  274. i += 4; /* cPRD, gets filled in below */
  275. buf[i++] = 0; /* reserved */
  276. buf[i++] = 0; /* reserved */
  277. buf[i++] = 0; /* reserved */
  278. buf[i++] = 0; /* reserved */
  279. /* ATA registers; must be a multiple of 4 */
  280. buf[i++] = qc->tf.device;
  281. buf[i++] = ADMA_REGS_DEVICE;
  282. if ((qc->tf.flags & ATA_TFLAG_LBA48)) {
  283. buf[i++] = qc->tf.hob_nsect;
  284. buf[i++] = ADMA_REGS_SECTOR_COUNT;
  285. buf[i++] = qc->tf.hob_lbal;
  286. buf[i++] = ADMA_REGS_LBA_LOW;
  287. buf[i++] = qc->tf.hob_lbam;
  288. buf[i++] = ADMA_REGS_LBA_MID;
  289. buf[i++] = qc->tf.hob_lbah;
  290. buf[i++] = ADMA_REGS_LBA_HIGH;
  291. }
  292. buf[i++] = qc->tf.nsect;
  293. buf[i++] = ADMA_REGS_SECTOR_COUNT;
  294. buf[i++] = qc->tf.lbal;
  295. buf[i++] = ADMA_REGS_LBA_LOW;
  296. buf[i++] = qc->tf.lbam;
  297. buf[i++] = ADMA_REGS_LBA_MID;
  298. buf[i++] = qc->tf.lbah;
  299. buf[i++] = ADMA_REGS_LBA_HIGH;
  300. buf[i++] = 0;
  301. buf[i++] = ADMA_REGS_CONTROL;
  302. buf[i++] = rIGN;
  303. buf[i++] = 0;
  304. buf[i++] = qc->tf.command;
  305. buf[i++] = ADMA_REGS_COMMAND | rEND;
  306. buf[3] = (i >> 3) - 2; /* cLEN */
  307. *(__le32 *)(buf+8) = cpu_to_le32(pkt_dma + i); /* cPRD */
  308. i = adma_fill_sg(qc);
  309. wmb(); /* flush PRDs and pkt to memory */
  310. #if 0
  311. /* dump out CPB + PRDs for debug */
  312. {
  313. int j, len = 0;
  314. static char obuf[2048];
  315. for (j = 0; j < i; ++j) {
  316. len += sprintf(obuf+len, "%02x ", buf[j]);
  317. if ((j & 7) == 7) {
  318. printk("%s\n", obuf);
  319. len = 0;
  320. }
  321. }
  322. if (len)
  323. printk("%s\n", obuf);
  324. }
  325. #endif
  326. }
  327. static inline void adma_packet_start(struct ata_queued_cmd *qc)
  328. {
  329. struct ata_port *ap = qc->ap;
  330. void __iomem *chan = ADMA_PORT_REGS(ap);
  331. VPRINTK("ENTER, ap %p\n", ap);
  332. /* fire up the ADMA engine */
  333. writew(aPIOMD4 | aGO, chan + ADMA_CONTROL);
  334. }
  335. static unsigned int adma_qc_issue(struct ata_queued_cmd *qc)
  336. {
  337. struct adma_port_priv *pp = qc->ap->private_data;
  338. switch (qc->tf.protocol) {
  339. case ATA_PROT_DMA:
  340. pp->state = adma_state_pkt;
  341. adma_packet_start(qc);
  342. return 0;
  343. case ATAPI_PROT_DMA:
  344. BUG();
  345. break;
  346. default:
  347. break;
  348. }
  349. pp->state = adma_state_mmio;
  350. return ata_sff_qc_issue(qc);
  351. }
  352. static inline unsigned int adma_intr_pkt(struct ata_host *host)
  353. {
  354. unsigned int handled = 0, port_no;
  355. for (port_no = 0; port_no < host->n_ports; ++port_no) {
  356. struct ata_port *ap = host->ports[port_no];
  357. struct adma_port_priv *pp;
  358. struct ata_queued_cmd *qc;
  359. void __iomem *chan = ADMA_PORT_REGS(ap);
  360. u8 status = readb(chan + ADMA_STATUS);
  361. if (status == 0)
  362. continue;
  363. handled = 1;
  364. adma_enter_reg_mode(ap);
  365. if (ap->flags & ATA_FLAG_DISABLED)
  366. continue;
  367. pp = ap->private_data;
  368. if (!pp || pp->state != adma_state_pkt)
  369. continue;
  370. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  371. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
  372. if (status & aPERR)
  373. qc->err_mask |= AC_ERR_HOST_BUS;
  374. else if ((status & (aPSD | aUIRQ)))
  375. qc->err_mask |= AC_ERR_OTHER;
  376. if (pp->pkt[0] & cATERR)
  377. qc->err_mask |= AC_ERR_DEV;
  378. else if (pp->pkt[0] != cDONE)
  379. qc->err_mask |= AC_ERR_OTHER;
  380. if (!qc->err_mask)
  381. ata_qc_complete(qc);
  382. else {
  383. struct ata_eh_info *ehi = &ap->link.eh_info;
  384. ata_ehi_clear_desc(ehi);
  385. ata_ehi_push_desc(ehi,
  386. "ADMA-status 0x%02X", status);
  387. ata_ehi_push_desc(ehi,
  388. "pkt[0] 0x%02X", pp->pkt[0]);
  389. if (qc->err_mask == AC_ERR_DEV)
  390. ata_port_abort(ap);
  391. else
  392. ata_port_freeze(ap);
  393. }
  394. }
  395. }
  396. return handled;
  397. }
  398. static inline unsigned int adma_intr_mmio(struct ata_host *host)
  399. {
  400. unsigned int handled = 0, port_no;
  401. for (port_no = 0; port_no < host->n_ports; ++port_no) {
  402. struct ata_port *ap;
  403. ap = host->ports[port_no];
  404. if (ap && (!(ap->flags & ATA_FLAG_DISABLED))) {
  405. struct ata_queued_cmd *qc;
  406. struct adma_port_priv *pp = ap->private_data;
  407. if (!pp || pp->state != adma_state_mmio)
  408. continue;
  409. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  410. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
  411. /* check main status, clearing INTRQ */
  412. u8 status = ata_sff_check_status(ap);
  413. if ((status & ATA_BUSY))
  414. continue;
  415. DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
  416. ap->print_id, qc->tf.protocol, status);
  417. /* complete taskfile transaction */
  418. pp->state = adma_state_idle;
  419. qc->err_mask |= ac_err_mask(status);
  420. if (!qc->err_mask)
  421. ata_qc_complete(qc);
  422. else {
  423. struct ata_eh_info *ehi =
  424. &ap->link.eh_info;
  425. ata_ehi_clear_desc(ehi);
  426. ata_ehi_push_desc(ehi,
  427. "status 0x%02X", status);
  428. if (qc->err_mask == AC_ERR_DEV)
  429. ata_port_abort(ap);
  430. else
  431. ata_port_freeze(ap);
  432. }
  433. handled = 1;
  434. }
  435. }
  436. }
  437. return handled;
  438. }
  439. static irqreturn_t adma_intr(int irq, void *dev_instance)
  440. {
  441. struct ata_host *host = dev_instance;
  442. unsigned int handled = 0;
  443. VPRINTK("ENTER\n");
  444. spin_lock(&host->lock);
  445. handled = adma_intr_pkt(host) | adma_intr_mmio(host);
  446. spin_unlock(&host->lock);
  447. VPRINTK("EXIT\n");
  448. return IRQ_RETVAL(handled);
  449. }
  450. static void adma_ata_setup_port(struct ata_ioports *port, void __iomem *base)
  451. {
  452. port->cmd_addr =
  453. port->data_addr = base + 0x000;
  454. port->error_addr =
  455. port->feature_addr = base + 0x004;
  456. port->nsect_addr = base + 0x008;
  457. port->lbal_addr = base + 0x00c;
  458. port->lbam_addr = base + 0x010;
  459. port->lbah_addr = base + 0x014;
  460. port->device_addr = base + 0x018;
  461. port->status_addr =
  462. port->command_addr = base + 0x01c;
  463. port->altstatus_addr =
  464. port->ctl_addr = base + 0x038;
  465. }
  466. static int adma_port_start(struct ata_port *ap)
  467. {
  468. struct device *dev = ap->host->dev;
  469. struct adma_port_priv *pp;
  470. int rc;
  471. rc = ata_port_start(ap);
  472. if (rc)
  473. return rc;
  474. adma_enter_reg_mode(ap);
  475. pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
  476. if (!pp)
  477. return -ENOMEM;
  478. pp->pkt = dmam_alloc_coherent(dev, ADMA_PKT_BYTES, &pp->pkt_dma,
  479. GFP_KERNEL);
  480. if (!pp->pkt)
  481. return -ENOMEM;
  482. /* paranoia? */
  483. if ((pp->pkt_dma & 7) != 0) {
  484. printk(KERN_ERR "bad alignment for pp->pkt_dma: %08x\n",
  485. (u32)pp->pkt_dma);
  486. return -ENOMEM;
  487. }
  488. memset(pp->pkt, 0, ADMA_PKT_BYTES);
  489. ap->private_data = pp;
  490. adma_reinit_engine(ap);
  491. return 0;
  492. }
  493. static void adma_port_stop(struct ata_port *ap)
  494. {
  495. adma_reset_engine(ap);
  496. }
  497. static void adma_host_init(struct ata_host *host, unsigned int chip_id)
  498. {
  499. unsigned int port_no;
  500. /* enable/lock aGO operation */
  501. writeb(7, host->iomap[ADMA_MMIO_BAR] + ADMA_MODE_LOCK);
  502. /* reset the ADMA logic */
  503. for (port_no = 0; port_no < ADMA_PORTS; ++port_no)
  504. adma_reset_engine(host->ports[port_no]);
  505. }
  506. static int adma_set_dma_masks(struct pci_dev *pdev, void __iomem *mmio_base)
  507. {
  508. int rc;
  509. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  510. if (rc) {
  511. dev_printk(KERN_ERR, &pdev->dev,
  512. "32-bit DMA enable failed\n");
  513. return rc;
  514. }
  515. rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  516. if (rc) {
  517. dev_printk(KERN_ERR, &pdev->dev,
  518. "32-bit consistent DMA enable failed\n");
  519. return rc;
  520. }
  521. return 0;
  522. }
  523. static int adma_ata_init_one(struct pci_dev *pdev,
  524. const struct pci_device_id *ent)
  525. {
  526. static int printed_version;
  527. unsigned int board_idx = (unsigned int) ent->driver_data;
  528. const struct ata_port_info *ppi[] = { &adma_port_info[board_idx], NULL };
  529. struct ata_host *host;
  530. void __iomem *mmio_base;
  531. int rc, port_no;
  532. if (!printed_version++)
  533. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  534. /* alloc host */
  535. host = ata_host_alloc_pinfo(&pdev->dev, ppi, ADMA_PORTS);
  536. if (!host)
  537. return -ENOMEM;
  538. /* acquire resources and fill host */
  539. rc = pcim_enable_device(pdev);
  540. if (rc)
  541. return rc;
  542. if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) == 0)
  543. return -ENODEV;
  544. rc = pcim_iomap_regions(pdev, 1 << ADMA_MMIO_BAR, DRV_NAME);
  545. if (rc)
  546. return rc;
  547. host->iomap = pcim_iomap_table(pdev);
  548. mmio_base = host->iomap[ADMA_MMIO_BAR];
  549. rc = adma_set_dma_masks(pdev, mmio_base);
  550. if (rc)
  551. return rc;
  552. for (port_no = 0; port_no < ADMA_PORTS; ++port_no) {
  553. struct ata_port *ap = host->ports[port_no];
  554. void __iomem *port_base = ADMA_ATA_REGS(mmio_base, port_no);
  555. unsigned int offset = port_base - mmio_base;
  556. adma_ata_setup_port(&ap->ioaddr, port_base);
  557. ata_port_pbar_desc(ap, ADMA_MMIO_BAR, -1, "mmio");
  558. ata_port_pbar_desc(ap, ADMA_MMIO_BAR, offset, "port");
  559. }
  560. /* initialize adapter */
  561. adma_host_init(host, board_idx);
  562. pci_set_master(pdev);
  563. return ata_host_activate(host, pdev->irq, adma_intr, IRQF_SHARED,
  564. &adma_ata_sht);
  565. }
  566. static int __init adma_ata_init(void)
  567. {
  568. return pci_register_driver(&adma_ata_pci_driver);
  569. }
  570. static void __exit adma_ata_exit(void)
  571. {
  572. pci_unregister_driver(&adma_ata_pci_driver);
  573. }
  574. MODULE_AUTHOR("Mark Lord");
  575. MODULE_DESCRIPTION("Pacific Digital Corporation ADMA low-level driver");
  576. MODULE_LICENSE("GPL");
  577. MODULE_DEVICE_TABLE(pci, adma_ata_pci_tbl);
  578. MODULE_VERSION(DRV_VERSION);
  579. module_init(adma_ata_init);
  580. module_exit(adma_ata_exit);