pdc_adma.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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/pci.h>
  37. #include <linux/init.h>
  38. #include <linux/blkdev.h>
  39. #include <linux/delay.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/device.h>
  42. #include <scsi/scsi_host.h>
  43. #include <linux/libata.h>
  44. #define DRV_NAME "pdc_adma"
  45. #define DRV_VERSION "0.05"
  46. /* macro to calculate base address for ATA regs */
  47. #define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40))
  48. /* macro to calculate base address for ADMA regs */
  49. #define ADMA_REGS(base,port_no) ((base) + 0x80 + ((port_no) * 0x20))
  50. /* macro to obtain addresses from ata_host */
  51. #define ADMA_HOST_REGS(host,port_no) \
  52. ADMA_REGS((host)->iomap[ADMA_MMIO_BAR], port_no)
  53. enum {
  54. ADMA_MMIO_BAR = 4,
  55. ADMA_PORTS = 2,
  56. ADMA_CPB_BYTES = 40,
  57. ADMA_PRD_BYTES = LIBATA_MAX_PRD * 16,
  58. ADMA_PKT_BYTES = ADMA_CPB_BYTES + ADMA_PRD_BYTES,
  59. ADMA_DMA_BOUNDARY = 0xffffffff,
  60. /* global register offsets */
  61. ADMA_MODE_LOCK = 0x00c7,
  62. /* per-channel register offsets */
  63. ADMA_CONTROL = 0x0000, /* ADMA control */
  64. ADMA_STATUS = 0x0002, /* ADMA status */
  65. ADMA_CPB_COUNT = 0x0004, /* CPB count */
  66. ADMA_CPB_CURRENT = 0x000c, /* current CPB address */
  67. ADMA_CPB_NEXT = 0x000c, /* next CPB address */
  68. ADMA_CPB_LOOKUP = 0x0010, /* CPB lookup table */
  69. ADMA_FIFO_IN = 0x0014, /* input FIFO threshold */
  70. ADMA_FIFO_OUT = 0x0016, /* output FIFO threshold */
  71. /* ADMA_CONTROL register bits */
  72. aNIEN = (1 << 8), /* irq mask: 1==masked */
  73. aGO = (1 << 7), /* packet trigger ("Go!") */
  74. aRSTADM = (1 << 5), /* ADMA logic reset */
  75. aPIOMD4 = 0x0003, /* PIO mode 4 */
  76. /* ADMA_STATUS register bits */
  77. aPSD = (1 << 6),
  78. aUIRQ = (1 << 4),
  79. aPERR = (1 << 0),
  80. /* CPB bits */
  81. cDONE = (1 << 0),
  82. cVLD = (1 << 0),
  83. cDAT = (1 << 2),
  84. cIEN = (1 << 3),
  85. /* PRD bits */
  86. pORD = (1 << 4),
  87. pDIRO = (1 << 5),
  88. pEND = (1 << 7),
  89. /* ATA register flags */
  90. rIGN = (1 << 5),
  91. rEND = (1 << 7),
  92. /* ATA register addresses */
  93. ADMA_REGS_CONTROL = 0x0e,
  94. ADMA_REGS_SECTOR_COUNT = 0x12,
  95. ADMA_REGS_LBA_LOW = 0x13,
  96. ADMA_REGS_LBA_MID = 0x14,
  97. ADMA_REGS_LBA_HIGH = 0x15,
  98. ADMA_REGS_DEVICE = 0x16,
  99. ADMA_REGS_COMMAND = 0x17,
  100. /* PCI device IDs */
  101. board_1841_idx = 0, /* ADMA 2-port controller */
  102. };
  103. typedef enum { adma_state_idle, adma_state_pkt, adma_state_mmio } adma_state_t;
  104. struct adma_port_priv {
  105. u8 *pkt;
  106. dma_addr_t pkt_dma;
  107. adma_state_t state;
  108. };
  109. static int adma_ata_init_one (struct pci_dev *pdev,
  110. const struct pci_device_id *ent);
  111. static irqreturn_t adma_intr (int irq, void *dev_instance);
  112. static int adma_port_start(struct ata_port *ap);
  113. static void adma_host_stop(struct ata_host *host);
  114. static void adma_port_stop(struct ata_port *ap);
  115. static void adma_phy_reset(struct ata_port *ap);
  116. static void adma_qc_prep(struct ata_queued_cmd *qc);
  117. static unsigned int adma_qc_issue(struct ata_queued_cmd *qc);
  118. static int adma_check_atapi_dma(struct ata_queued_cmd *qc);
  119. static void adma_bmdma_stop(struct ata_queued_cmd *qc);
  120. static u8 adma_bmdma_status(struct ata_port *ap);
  121. static void adma_irq_clear(struct ata_port *ap);
  122. static void adma_eng_timeout(struct ata_port *ap);
  123. static struct scsi_host_template adma_ata_sht = {
  124. .module = THIS_MODULE,
  125. .name = DRV_NAME,
  126. .ioctl = ata_scsi_ioctl,
  127. .queuecommand = ata_scsi_queuecmd,
  128. .can_queue = ATA_DEF_QUEUE,
  129. .this_id = ATA_SHT_THIS_ID,
  130. .sg_tablesize = LIBATA_MAX_PRD,
  131. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  132. .emulated = ATA_SHT_EMULATED,
  133. .use_clustering = ENABLE_CLUSTERING,
  134. .proc_name = DRV_NAME,
  135. .dma_boundary = ADMA_DMA_BOUNDARY,
  136. .slave_configure = ata_scsi_slave_config,
  137. .slave_destroy = ata_scsi_slave_destroy,
  138. .bios_param = ata_std_bios_param,
  139. };
  140. static const struct ata_port_operations adma_ata_ops = {
  141. .port_disable = ata_port_disable,
  142. .tf_load = ata_tf_load,
  143. .tf_read = ata_tf_read,
  144. .check_status = ata_check_status,
  145. .check_atapi_dma = adma_check_atapi_dma,
  146. .exec_command = ata_exec_command,
  147. .dev_select = ata_std_dev_select,
  148. .phy_reset = adma_phy_reset,
  149. .qc_prep = adma_qc_prep,
  150. .qc_issue = adma_qc_issue,
  151. .eng_timeout = adma_eng_timeout,
  152. .data_xfer = ata_data_xfer,
  153. .irq_handler = adma_intr,
  154. .irq_clear = adma_irq_clear,
  155. .irq_on = ata_irq_on,
  156. .irq_ack = ata_irq_ack,
  157. .port_start = adma_port_start,
  158. .port_stop = adma_port_stop,
  159. .host_stop = adma_host_stop,
  160. .bmdma_stop = adma_bmdma_stop,
  161. .bmdma_status = adma_bmdma_status,
  162. };
  163. static struct ata_port_info adma_port_info[] = {
  164. /* board_1841_idx */
  165. {
  166. .sht = &adma_ata_sht,
  167. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST |
  168. ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO |
  169. ATA_FLAG_PIO_POLLING,
  170. .pio_mask = 0x10, /* pio4 */
  171. .udma_mask = 0x1f, /* udma0-4 */
  172. .port_ops = &adma_ata_ops,
  173. },
  174. };
  175. static const struct pci_device_id adma_ata_pci_tbl[] = {
  176. { PCI_VDEVICE(PDC, 0x1841), board_1841_idx },
  177. { } /* terminate list */
  178. };
  179. static struct pci_driver adma_ata_pci_driver = {
  180. .name = DRV_NAME,
  181. .id_table = adma_ata_pci_tbl,
  182. .probe = adma_ata_init_one,
  183. .remove = ata_pci_remove_one,
  184. };
  185. static int adma_check_atapi_dma(struct ata_queued_cmd *qc)
  186. {
  187. return 1; /* ATAPI DMA not yet supported */
  188. }
  189. static void adma_bmdma_stop(struct ata_queued_cmd *qc)
  190. {
  191. /* nothing */
  192. }
  193. static u8 adma_bmdma_status(struct ata_port *ap)
  194. {
  195. return 0;
  196. }
  197. static void adma_irq_clear(struct ata_port *ap)
  198. {
  199. /* nothing */
  200. }
  201. static void adma_reset_engine(void __iomem *chan)
  202. {
  203. /* reset ADMA to idle state */
  204. writew(aPIOMD4 | aNIEN | aRSTADM, chan + ADMA_CONTROL);
  205. udelay(2);
  206. writew(aPIOMD4, chan + ADMA_CONTROL);
  207. udelay(2);
  208. }
  209. static void adma_reinit_engine(struct ata_port *ap)
  210. {
  211. struct adma_port_priv *pp = ap->private_data;
  212. void __iomem *chan = ADMA_HOST_REGS(ap->host, ap->port_no);
  213. /* mask/clear ATA interrupts */
  214. writeb(ATA_NIEN, ap->ioaddr.ctl_addr);
  215. ata_check_status(ap);
  216. /* reset the ADMA engine */
  217. adma_reset_engine(chan);
  218. /* set in-FIFO threshold to 0x100 */
  219. writew(0x100, chan + ADMA_FIFO_IN);
  220. /* set CPB pointer */
  221. writel((u32)pp->pkt_dma, chan + ADMA_CPB_NEXT);
  222. /* set out-FIFO threshold to 0x100 */
  223. writew(0x100, chan + ADMA_FIFO_OUT);
  224. /* set CPB count */
  225. writew(1, chan + ADMA_CPB_COUNT);
  226. /* read/discard ADMA status */
  227. readb(chan + ADMA_STATUS);
  228. }
  229. static inline void adma_enter_reg_mode(struct ata_port *ap)
  230. {
  231. void __iomem *chan = ADMA_HOST_REGS(ap->host, ap->port_no);
  232. writew(aPIOMD4, chan + ADMA_CONTROL);
  233. readb(chan + ADMA_STATUS); /* flush */
  234. }
  235. static void adma_phy_reset(struct ata_port *ap)
  236. {
  237. struct adma_port_priv *pp = ap->private_data;
  238. pp->state = adma_state_idle;
  239. adma_reinit_engine(ap);
  240. ata_port_probe(ap);
  241. ata_bus_reset(ap);
  242. }
  243. static void adma_eng_timeout(struct ata_port *ap)
  244. {
  245. struct adma_port_priv *pp = ap->private_data;
  246. if (pp->state != adma_state_idle) /* healthy paranoia */
  247. pp->state = adma_state_mmio;
  248. adma_reinit_engine(ap);
  249. ata_eng_timeout(ap);
  250. }
  251. static int adma_fill_sg(struct ata_queued_cmd *qc)
  252. {
  253. struct scatterlist *sg;
  254. struct ata_port *ap = qc->ap;
  255. struct adma_port_priv *pp = ap->private_data;
  256. u8 *buf = pp->pkt;
  257. int i = (2 + buf[3]) * 8;
  258. u8 pFLAGS = pORD | ((qc->tf.flags & ATA_TFLAG_WRITE) ? pDIRO : 0);
  259. ata_for_each_sg(sg, qc) {
  260. u32 addr;
  261. u32 len;
  262. addr = (u32)sg_dma_address(sg);
  263. *(__le32 *)(buf + i) = cpu_to_le32(addr);
  264. i += 4;
  265. len = sg_dma_len(sg) >> 3;
  266. *(__le32 *)(buf + i) = cpu_to_le32(len);
  267. i += 4;
  268. if (ata_sg_is_last(sg, qc))
  269. pFLAGS |= pEND;
  270. buf[i++] = pFLAGS;
  271. buf[i++] = qc->dev->dma_mode & 0xf;
  272. buf[i++] = 0; /* pPKLW */
  273. buf[i++] = 0; /* reserved */
  274. *(__le32 *)(buf + i)
  275. = (pFLAGS & pEND) ? 0 : cpu_to_le32(pp->pkt_dma + i + 4);
  276. i += 4;
  277. VPRINTK("PRD[%u] = (0x%lX, 0x%X)\n", i/4,
  278. (unsigned long)addr, len);
  279. }
  280. return i;
  281. }
  282. static void adma_qc_prep(struct ata_queued_cmd *qc)
  283. {
  284. struct adma_port_priv *pp = qc->ap->private_data;
  285. u8 *buf = pp->pkt;
  286. u32 pkt_dma = (u32)pp->pkt_dma;
  287. int i = 0;
  288. VPRINTK("ENTER\n");
  289. adma_enter_reg_mode(qc->ap);
  290. if (qc->tf.protocol != ATA_PROT_DMA) {
  291. ata_qc_prep(qc);
  292. return;
  293. }
  294. buf[i++] = 0; /* Response flags */
  295. buf[i++] = 0; /* reserved */
  296. buf[i++] = cVLD | cDAT | cIEN;
  297. i++; /* cLEN, gets filled in below */
  298. *(__le32 *)(buf+i) = cpu_to_le32(pkt_dma); /* cNCPB */
  299. i += 4; /* cNCPB */
  300. i += 4; /* cPRD, gets filled in below */
  301. buf[i++] = 0; /* reserved */
  302. buf[i++] = 0; /* reserved */
  303. buf[i++] = 0; /* reserved */
  304. buf[i++] = 0; /* reserved */
  305. /* ATA registers; must be a multiple of 4 */
  306. buf[i++] = qc->tf.device;
  307. buf[i++] = ADMA_REGS_DEVICE;
  308. if ((qc->tf.flags & ATA_TFLAG_LBA48)) {
  309. buf[i++] = qc->tf.hob_nsect;
  310. buf[i++] = ADMA_REGS_SECTOR_COUNT;
  311. buf[i++] = qc->tf.hob_lbal;
  312. buf[i++] = ADMA_REGS_LBA_LOW;
  313. buf[i++] = qc->tf.hob_lbam;
  314. buf[i++] = ADMA_REGS_LBA_MID;
  315. buf[i++] = qc->tf.hob_lbah;
  316. buf[i++] = ADMA_REGS_LBA_HIGH;
  317. }
  318. buf[i++] = qc->tf.nsect;
  319. buf[i++] = ADMA_REGS_SECTOR_COUNT;
  320. buf[i++] = qc->tf.lbal;
  321. buf[i++] = ADMA_REGS_LBA_LOW;
  322. buf[i++] = qc->tf.lbam;
  323. buf[i++] = ADMA_REGS_LBA_MID;
  324. buf[i++] = qc->tf.lbah;
  325. buf[i++] = ADMA_REGS_LBA_HIGH;
  326. buf[i++] = 0;
  327. buf[i++] = ADMA_REGS_CONTROL;
  328. buf[i++] = rIGN;
  329. buf[i++] = 0;
  330. buf[i++] = qc->tf.command;
  331. buf[i++] = ADMA_REGS_COMMAND | rEND;
  332. buf[3] = (i >> 3) - 2; /* cLEN */
  333. *(__le32 *)(buf+8) = cpu_to_le32(pkt_dma + i); /* cPRD */
  334. i = adma_fill_sg(qc);
  335. wmb(); /* flush PRDs and pkt to memory */
  336. #if 0
  337. /* dump out CPB + PRDs for debug */
  338. {
  339. int j, len = 0;
  340. static char obuf[2048];
  341. for (j = 0; j < i; ++j) {
  342. len += sprintf(obuf+len, "%02x ", buf[j]);
  343. if ((j & 7) == 7) {
  344. printk("%s\n", obuf);
  345. len = 0;
  346. }
  347. }
  348. if (len)
  349. printk("%s\n", obuf);
  350. }
  351. #endif
  352. }
  353. static inline void adma_packet_start(struct ata_queued_cmd *qc)
  354. {
  355. struct ata_port *ap = qc->ap;
  356. void __iomem *chan = ADMA_HOST_REGS(ap->host, ap->port_no);
  357. VPRINTK("ENTER, ap %p\n", ap);
  358. /* fire up the ADMA engine */
  359. writew(aPIOMD4 | aGO, chan + ADMA_CONTROL);
  360. }
  361. static unsigned int adma_qc_issue(struct ata_queued_cmd *qc)
  362. {
  363. struct adma_port_priv *pp = qc->ap->private_data;
  364. switch (qc->tf.protocol) {
  365. case ATA_PROT_DMA:
  366. pp->state = adma_state_pkt;
  367. adma_packet_start(qc);
  368. return 0;
  369. case ATA_PROT_ATAPI_DMA:
  370. BUG();
  371. break;
  372. default:
  373. break;
  374. }
  375. pp->state = adma_state_mmio;
  376. return ata_qc_issue_prot(qc);
  377. }
  378. static inline unsigned int adma_intr_pkt(struct ata_host *host)
  379. {
  380. unsigned int handled = 0, port_no;
  381. for (port_no = 0; port_no < host->n_ports; ++port_no) {
  382. struct ata_port *ap = host->ports[port_no];
  383. struct adma_port_priv *pp;
  384. struct ata_queued_cmd *qc;
  385. void __iomem *chan = ADMA_HOST_REGS(host, port_no);
  386. u8 status = readb(chan + ADMA_STATUS);
  387. if (status == 0)
  388. continue;
  389. handled = 1;
  390. adma_enter_reg_mode(ap);
  391. if (ap->flags & ATA_FLAG_DISABLED)
  392. continue;
  393. pp = ap->private_data;
  394. if (!pp || pp->state != adma_state_pkt)
  395. continue;
  396. qc = ata_qc_from_tag(ap, ap->active_tag);
  397. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
  398. if ((status & (aPERR | aPSD | aUIRQ)))
  399. qc->err_mask |= AC_ERR_OTHER;
  400. else if (pp->pkt[0] != cDONE)
  401. qc->err_mask |= AC_ERR_OTHER;
  402. ata_qc_complete(qc);
  403. }
  404. }
  405. return handled;
  406. }
  407. static inline unsigned int adma_intr_mmio(struct ata_host *host)
  408. {
  409. unsigned int handled = 0, port_no;
  410. for (port_no = 0; port_no < host->n_ports; ++port_no) {
  411. struct ata_port *ap;
  412. ap = host->ports[port_no];
  413. if (ap && (!(ap->flags & ATA_FLAG_DISABLED))) {
  414. struct ata_queued_cmd *qc;
  415. struct adma_port_priv *pp = ap->private_data;
  416. if (!pp || pp->state != adma_state_mmio)
  417. continue;
  418. qc = ata_qc_from_tag(ap, ap->active_tag);
  419. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
  420. /* check main status, clearing INTRQ */
  421. u8 status = ata_check_status(ap);
  422. if ((status & ATA_BUSY))
  423. continue;
  424. DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
  425. ap->print_id, qc->tf.protocol, status);
  426. /* complete taskfile transaction */
  427. pp->state = adma_state_idle;
  428. qc->err_mask |= ac_err_mask(status);
  429. ata_qc_complete(qc);
  430. handled = 1;
  431. }
  432. }
  433. }
  434. return handled;
  435. }
  436. static irqreturn_t adma_intr(int irq, void *dev_instance)
  437. {
  438. struct ata_host *host = dev_instance;
  439. unsigned int handled = 0;
  440. VPRINTK("ENTER\n");
  441. spin_lock(&host->lock);
  442. handled = adma_intr_pkt(host) | adma_intr_mmio(host);
  443. spin_unlock(&host->lock);
  444. VPRINTK("EXIT\n");
  445. return IRQ_RETVAL(handled);
  446. }
  447. static void adma_ata_setup_port(struct ata_ioports *port, void __iomem *base)
  448. {
  449. port->cmd_addr =
  450. port->data_addr = base + 0x000;
  451. port->error_addr =
  452. port->feature_addr = base + 0x004;
  453. port->nsect_addr = base + 0x008;
  454. port->lbal_addr = base + 0x00c;
  455. port->lbam_addr = base + 0x010;
  456. port->lbah_addr = base + 0x014;
  457. port->device_addr = base + 0x018;
  458. port->status_addr =
  459. port->command_addr = base + 0x01c;
  460. port->altstatus_addr =
  461. port->ctl_addr = base + 0x038;
  462. }
  463. static int adma_port_start(struct ata_port *ap)
  464. {
  465. struct device *dev = ap->host->dev;
  466. struct adma_port_priv *pp;
  467. int rc;
  468. rc = ata_port_start(ap);
  469. if (rc)
  470. return rc;
  471. adma_enter_reg_mode(ap);
  472. pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
  473. if (!pp)
  474. return -ENOMEM;
  475. pp->pkt = dmam_alloc_coherent(dev, ADMA_PKT_BYTES, &pp->pkt_dma,
  476. GFP_KERNEL);
  477. if (!pp->pkt)
  478. return -ENOMEM;
  479. /* paranoia? */
  480. if ((pp->pkt_dma & 7) != 0) {
  481. printk("bad alignment for pp->pkt_dma: %08x\n",
  482. (u32)pp->pkt_dma);
  483. return -ENOMEM;
  484. }
  485. memset(pp->pkt, 0, ADMA_PKT_BYTES);
  486. ap->private_data = pp;
  487. adma_reinit_engine(ap);
  488. return 0;
  489. }
  490. static void adma_port_stop(struct ata_port *ap)
  491. {
  492. adma_reset_engine(ADMA_HOST_REGS(ap->host, ap->port_no));
  493. }
  494. static void adma_host_stop(struct ata_host *host)
  495. {
  496. unsigned int port_no;
  497. for (port_no = 0; port_no < ADMA_PORTS; ++port_no)
  498. adma_reset_engine(ADMA_HOST_REGS(host, port_no));
  499. }
  500. static void adma_host_init(unsigned int chip_id,
  501. struct ata_probe_ent *probe_ent)
  502. {
  503. unsigned int port_no;
  504. void __iomem *mmio_base = probe_ent->iomap[ADMA_MMIO_BAR];
  505. /* enable/lock aGO operation */
  506. writeb(7, mmio_base + ADMA_MODE_LOCK);
  507. /* reset the ADMA logic */
  508. for (port_no = 0; port_no < ADMA_PORTS; ++port_no)
  509. adma_reset_engine(ADMA_REGS(mmio_base, port_no));
  510. }
  511. static int adma_set_dma_masks(struct pci_dev *pdev, void __iomem *mmio_base)
  512. {
  513. int rc;
  514. rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  515. if (rc) {
  516. dev_printk(KERN_ERR, &pdev->dev,
  517. "32-bit DMA enable failed\n");
  518. return rc;
  519. }
  520. rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  521. if (rc) {
  522. dev_printk(KERN_ERR, &pdev->dev,
  523. "32-bit consistent DMA enable failed\n");
  524. return rc;
  525. }
  526. return 0;
  527. }
  528. static int adma_ata_init_one(struct pci_dev *pdev,
  529. const struct pci_device_id *ent)
  530. {
  531. static int printed_version;
  532. struct ata_probe_ent *probe_ent = NULL;
  533. void __iomem *mmio_base;
  534. unsigned int board_idx = (unsigned int) ent->driver_data;
  535. int rc, port_no;
  536. if (!printed_version++)
  537. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  538. rc = pcim_enable_device(pdev);
  539. if (rc)
  540. return rc;
  541. if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) == 0)
  542. return -ENODEV;
  543. rc = pcim_iomap_regions(pdev, 1 << ADMA_MMIO_BAR, DRV_NAME);
  544. if (rc)
  545. return rc;
  546. mmio_base = pcim_iomap_table(pdev)[ADMA_MMIO_BAR];
  547. rc = adma_set_dma_masks(pdev, mmio_base);
  548. if (rc)
  549. return rc;
  550. probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
  551. if (probe_ent == NULL)
  552. return -ENOMEM;
  553. probe_ent->dev = pci_dev_to_dev(pdev);
  554. INIT_LIST_HEAD(&probe_ent->node);
  555. probe_ent->sht = adma_port_info[board_idx].sht;
  556. probe_ent->port_flags = adma_port_info[board_idx].flags;
  557. probe_ent->pio_mask = adma_port_info[board_idx].pio_mask;
  558. probe_ent->mwdma_mask = adma_port_info[board_idx].mwdma_mask;
  559. probe_ent->udma_mask = adma_port_info[board_idx].udma_mask;
  560. probe_ent->port_ops = adma_port_info[board_idx].port_ops;
  561. probe_ent->irq = pdev->irq;
  562. probe_ent->irq_flags = IRQF_SHARED;
  563. probe_ent->n_ports = ADMA_PORTS;
  564. probe_ent->iomap = pcim_iomap_table(pdev);
  565. for (port_no = 0; port_no < probe_ent->n_ports; ++port_no) {
  566. adma_ata_setup_port(&probe_ent->port[port_no],
  567. ADMA_ATA_REGS(mmio_base, port_no));
  568. }
  569. pci_set_master(pdev);
  570. /* initialize adapter */
  571. adma_host_init(board_idx, probe_ent);
  572. if (!ata_device_add(probe_ent))
  573. return -ENODEV;
  574. devm_kfree(&pdev->dev, probe_ent);
  575. return 0;
  576. }
  577. static int __init adma_ata_init(void)
  578. {
  579. return pci_register_driver(&adma_ata_pci_driver);
  580. }
  581. static void __exit adma_ata_exit(void)
  582. {
  583. pci_unregister_driver(&adma_ata_pci_driver);
  584. }
  585. MODULE_AUTHOR("Mark Lord");
  586. MODULE_DESCRIPTION("Pacific Digital Corporation ADMA low-level driver");
  587. MODULE_LICENSE("GPL");
  588. MODULE_DEVICE_TABLE(pci, adma_ata_pci_tbl);
  589. MODULE_VERSION(DRV_VERSION);
  590. module_init(adma_ata_init);
  591. module_exit(adma_ata_exit);