sata_promise.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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. * The contents of this file are subject to the Open
  11. * Software License version 1.1 that can be found at
  12. * http://www.opensource.org/licenses/osl-1.1.txt and is included herein
  13. * by reference.
  14. *
  15. * Alternatively, the contents of this file may be used under the terms
  16. * of the GNU General Public License version 2 (the "GPL") as distributed
  17. * in the kernel source COPYING file, in which case the provisions of
  18. * the GPL are applicable instead of the above. If you wish to allow
  19. * the use of your version of this file only under the terms of the
  20. * GPL and not to allow others to use your version of this file under
  21. * the OSL, indicate your decision by deleting the provisions above and
  22. * replace them with the notice and other provisions required by the GPL.
  23. * If you do not delete the provisions above, a recipient may use your
  24. * version of this file under either the OSL or the GPL.
  25. *
  26. */
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/pci.h>
  30. #include <linux/init.h>
  31. #include <linux/blkdev.h>
  32. #include <linux/delay.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/sched.h>
  35. #include "scsi.h"
  36. #include <scsi/scsi_host.h>
  37. #include <linux/libata.h>
  38. #include <asm/io.h>
  39. #include "sata_promise.h"
  40. #define DRV_NAME "sata_promise"
  41. #define DRV_VERSION "1.01"
  42. enum {
  43. PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
  44. PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
  45. PDC_TBG_MODE = 0x41, /* TBG mode */
  46. PDC_FLASH_CTL = 0x44, /* Flash control register */
  47. PDC_PCI_CTL = 0x48, /* PCI control and status register */
  48. PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */
  49. PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */
  50. PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */
  51. PDC_SLEW_CTL = 0x470, /* slew rate control reg */
  52. PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) |
  53. (1<<8) | (1<<9) | (1<<10),
  54. board_2037x = 0, /* FastTrak S150 TX2plus */
  55. board_20319 = 1, /* FastTrak S150 TX4 */
  56. PDC_HAS_PATA = (1 << 1), /* PDC20375 has PATA */
  57. PDC_RESET = (1 << 11), /* HDMA reset */
  58. };
  59. struct pdc_port_priv {
  60. u8 *pkt;
  61. dma_addr_t pkt_dma;
  62. };
  63. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
  64. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
  65. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
  66. static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
  67. static void pdc_eng_timeout(struct ata_port *ap);
  68. static int pdc_port_start(struct ata_port *ap);
  69. static void pdc_port_stop(struct ata_port *ap);
  70. static void pdc_phy_reset(struct ata_port *ap);
  71. static void pdc_qc_prep(struct ata_queued_cmd *qc);
  72. static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf);
  73. static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf);
  74. static void pdc_irq_clear(struct ata_port *ap);
  75. static int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
  76. static Scsi_Host_Template pdc_ata_sht = {
  77. .module = THIS_MODULE,
  78. .name = DRV_NAME,
  79. .ioctl = ata_scsi_ioctl,
  80. .queuecommand = ata_scsi_queuecmd,
  81. .eh_strategy_handler = ata_scsi_error,
  82. .can_queue = ATA_DEF_QUEUE,
  83. .this_id = ATA_SHT_THIS_ID,
  84. .sg_tablesize = LIBATA_MAX_PRD,
  85. .max_sectors = ATA_MAX_SECTORS,
  86. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  87. .emulated = ATA_SHT_EMULATED,
  88. .use_clustering = ATA_SHT_USE_CLUSTERING,
  89. .proc_name = DRV_NAME,
  90. .dma_boundary = ATA_DMA_BOUNDARY,
  91. .slave_configure = ata_scsi_slave_config,
  92. .bios_param = ata_std_bios_param,
  93. .ordered_flush = 1,
  94. };
  95. static struct ata_port_operations pdc_ata_ops = {
  96. .port_disable = ata_port_disable,
  97. .tf_load = pdc_tf_load_mmio,
  98. .tf_read = ata_tf_read,
  99. .check_status = ata_check_status,
  100. .exec_command = pdc_exec_command_mmio,
  101. .dev_select = ata_std_dev_select,
  102. .phy_reset = pdc_phy_reset,
  103. .qc_prep = pdc_qc_prep,
  104. .qc_issue = pdc_qc_issue_prot,
  105. .eng_timeout = pdc_eng_timeout,
  106. .irq_handler = pdc_interrupt,
  107. .irq_clear = pdc_irq_clear,
  108. .scr_read = pdc_sata_scr_read,
  109. .scr_write = pdc_sata_scr_write,
  110. .port_start = pdc_port_start,
  111. .port_stop = pdc_port_stop,
  112. };
  113. static struct ata_port_info pdc_port_info[] = {
  114. /* board_2037x */
  115. {
  116. .sht = &pdc_ata_sht,
  117. .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
  118. ATA_FLAG_SRST | ATA_FLAG_MMIO,
  119. .pio_mask = 0x1f, /* pio0-4 */
  120. .mwdma_mask = 0x07, /* mwdma0-2 */
  121. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  122. .port_ops = &pdc_ata_ops,
  123. },
  124. /* board_20319 */
  125. {
  126. .sht = &pdc_ata_sht,
  127. .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
  128. ATA_FLAG_SRST | ATA_FLAG_MMIO,
  129. .pio_mask = 0x1f, /* pio0-4 */
  130. .mwdma_mask = 0x07, /* mwdma0-2 */
  131. .udma_mask = 0x7f, /* udma0-6 ; FIXME */
  132. .port_ops = &pdc_ata_ops,
  133. },
  134. };
  135. static struct pci_device_id pdc_ata_pci_tbl[] = {
  136. { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  137. board_2037x },
  138. { PCI_VENDOR_ID_PROMISE, 0x3571, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  139. board_2037x },
  140. { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  141. board_2037x },
  142. { PCI_VENDOR_ID_PROMISE, 0x3375, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  143. board_2037x },
  144. { PCI_VENDOR_ID_PROMISE, 0x3376, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  145. board_2037x },
  146. { PCI_VENDOR_ID_PROMISE, 0x3574, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  147. board_2037x },
  148. { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  149. board_2037x },
  150. { PCI_VENDOR_ID_PROMISE, 0x3318, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  151. board_20319 },
  152. { PCI_VENDOR_ID_PROMISE, 0x3319, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  153. board_20319 },
  154. { PCI_VENDOR_ID_PROMISE, 0x3d18, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  155. board_20319 },
  156. { } /* terminate list */
  157. };
  158. static struct pci_driver pdc_ata_pci_driver = {
  159. .name = DRV_NAME,
  160. .id_table = pdc_ata_pci_tbl,
  161. .probe = pdc_ata_init_one,
  162. .remove = ata_pci_remove_one,
  163. };
  164. static int pdc_port_start(struct ata_port *ap)
  165. {
  166. struct device *dev = ap->host_set->dev;
  167. struct pdc_port_priv *pp;
  168. int rc;
  169. rc = ata_port_start(ap);
  170. if (rc)
  171. return rc;
  172. pp = kmalloc(sizeof(*pp), GFP_KERNEL);
  173. if (!pp) {
  174. rc = -ENOMEM;
  175. goto err_out;
  176. }
  177. memset(pp, 0, sizeof(*pp));
  178. pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  179. if (!pp->pkt) {
  180. rc = -ENOMEM;
  181. goto err_out_kfree;
  182. }
  183. ap->private_data = pp;
  184. return 0;
  185. err_out_kfree:
  186. kfree(pp);
  187. err_out:
  188. ata_port_stop(ap);
  189. return rc;
  190. }
  191. static void pdc_port_stop(struct ata_port *ap)
  192. {
  193. struct device *dev = ap->host_set->dev;
  194. struct pdc_port_priv *pp = ap->private_data;
  195. ap->private_data = NULL;
  196. dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
  197. kfree(pp);
  198. ata_port_stop(ap);
  199. }
  200. static void pdc_reset_port(struct ata_port *ap)
  201. {
  202. void *mmio = (void *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
  203. unsigned int i;
  204. u32 tmp;
  205. for (i = 11; i > 0; i--) {
  206. tmp = readl(mmio);
  207. if (tmp & PDC_RESET)
  208. break;
  209. udelay(100);
  210. tmp |= PDC_RESET;
  211. writel(tmp, mmio);
  212. }
  213. tmp &= ~PDC_RESET;
  214. writel(tmp, mmio);
  215. readl(mmio); /* flush */
  216. }
  217. static void pdc_phy_reset(struct ata_port *ap)
  218. {
  219. pdc_reset_port(ap);
  220. sata_phy_reset(ap);
  221. }
  222. static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
  223. {
  224. if (sc_reg > SCR_CONTROL)
  225. return 0xffffffffU;
  226. return readl((void *) ap->ioaddr.scr_addr + (sc_reg * 4));
  227. }
  228. static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
  229. u32 val)
  230. {
  231. if (sc_reg > SCR_CONTROL)
  232. return;
  233. writel(val, (void *) ap->ioaddr.scr_addr + (sc_reg * 4));
  234. }
  235. static void pdc_qc_prep(struct ata_queued_cmd *qc)
  236. {
  237. struct pdc_port_priv *pp = qc->ap->private_data;
  238. unsigned int i;
  239. VPRINTK("ENTER\n");
  240. switch (qc->tf.protocol) {
  241. case ATA_PROT_DMA:
  242. ata_qc_prep(qc);
  243. /* fall through */
  244. case ATA_PROT_NODATA:
  245. i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
  246. qc->dev->devno, pp->pkt);
  247. if (qc->tf.flags & ATA_TFLAG_LBA48)
  248. i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
  249. else
  250. i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
  251. pdc_pkt_footer(&qc->tf, pp->pkt, i);
  252. break;
  253. default:
  254. break;
  255. }
  256. }
  257. static void pdc_eng_timeout(struct ata_port *ap)
  258. {
  259. u8 drv_stat;
  260. struct ata_queued_cmd *qc;
  261. DPRINTK("ENTER\n");
  262. qc = ata_qc_from_tag(ap, ap->active_tag);
  263. if (!qc) {
  264. printk(KERN_ERR "ata%u: BUG: timeout without command\n",
  265. ap->id);
  266. goto out;
  267. }
  268. /* hack alert! We cannot use the supplied completion
  269. * function from inside the ->eh_strategy_handler() thread.
  270. * libata is the only user of ->eh_strategy_handler() in
  271. * any kernel, so the default scsi_done() assumes it is
  272. * not being called from the SCSI EH.
  273. */
  274. qc->scsidone = scsi_finish_command;
  275. switch (qc->tf.protocol) {
  276. case ATA_PROT_DMA:
  277. case ATA_PROT_NODATA:
  278. printk(KERN_ERR "ata%u: command timeout\n", ap->id);
  279. ata_qc_complete(qc, ata_wait_idle(ap) | ATA_ERR);
  280. break;
  281. default:
  282. drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
  283. printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n",
  284. ap->id, qc->tf.command, drv_stat);
  285. ata_qc_complete(qc, drv_stat);
  286. break;
  287. }
  288. out:
  289. DPRINTK("EXIT\n");
  290. }
  291. static inline unsigned int pdc_host_intr( struct ata_port *ap,
  292. struct ata_queued_cmd *qc)
  293. {
  294. u8 status;
  295. unsigned int handled = 0, have_err = 0;
  296. u32 tmp;
  297. void *mmio = (void *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
  298. tmp = readl(mmio);
  299. if (tmp & PDC_ERR_MASK) {
  300. have_err = 1;
  301. pdc_reset_port(ap);
  302. }
  303. switch (qc->tf.protocol) {
  304. case ATA_PROT_DMA:
  305. case ATA_PROT_NODATA:
  306. status = ata_wait_idle(ap);
  307. if (have_err)
  308. status |= ATA_ERR;
  309. ata_qc_complete(qc, status);
  310. handled = 1;
  311. break;
  312. default:
  313. ap->stats.idle_irq++;
  314. break;
  315. }
  316. return handled;
  317. }
  318. static void pdc_irq_clear(struct ata_port *ap)
  319. {
  320. struct ata_host_set *host_set = ap->host_set;
  321. void *mmio = host_set->mmio_base;
  322. readl(mmio + PDC_INT_SEQMASK);
  323. }
  324. static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
  325. {
  326. struct ata_host_set *host_set = dev_instance;
  327. struct ata_port *ap;
  328. u32 mask = 0;
  329. unsigned int i, tmp;
  330. unsigned int handled = 0;
  331. void *mmio_base;
  332. VPRINTK("ENTER\n");
  333. if (!host_set || !host_set->mmio_base) {
  334. VPRINTK("QUICK EXIT\n");
  335. return IRQ_NONE;
  336. }
  337. mmio_base = host_set->mmio_base;
  338. /* reading should also clear interrupts */
  339. mask = readl(mmio_base + PDC_INT_SEQMASK);
  340. if (mask == 0xffffffff) {
  341. VPRINTK("QUICK EXIT 2\n");
  342. return IRQ_NONE;
  343. }
  344. mask &= 0xffff; /* only 16 tags possible */
  345. if (!mask) {
  346. VPRINTK("QUICK EXIT 3\n");
  347. return IRQ_NONE;
  348. }
  349. spin_lock(&host_set->lock);
  350. writel(mask, mmio_base + PDC_INT_SEQMASK);
  351. for (i = 0; i < host_set->n_ports; i++) {
  352. VPRINTK("port %u\n", i);
  353. ap = host_set->ports[i];
  354. tmp = mask & (1 << (i + 1));
  355. if (tmp && ap && (!(ap->flags & ATA_FLAG_PORT_DISABLED))) {
  356. struct ata_queued_cmd *qc;
  357. qc = ata_qc_from_tag(ap, ap->active_tag);
  358. if (qc && (!(qc->tf.ctl & ATA_NIEN)))
  359. handled += pdc_host_intr(ap, qc);
  360. }
  361. }
  362. spin_unlock(&host_set->lock);
  363. VPRINTK("EXIT\n");
  364. return IRQ_RETVAL(handled);
  365. }
  366. static inline void pdc_packet_start(struct ata_queued_cmd *qc)
  367. {
  368. struct ata_port *ap = qc->ap;
  369. struct pdc_port_priv *pp = ap->private_data;
  370. unsigned int port_no = ap->port_no;
  371. u8 seq = (u8) (port_no + 1);
  372. VPRINTK("ENTER, ap %p\n", ap);
  373. writel(0x00000001, ap->host_set->mmio_base + (seq * 4));
  374. readl(ap->host_set->mmio_base + (seq * 4)); /* flush */
  375. pp->pkt[2] = seq;
  376. wmb(); /* flush PRD, pkt writes */
  377. writel(pp->pkt_dma, (void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
  378. readl((void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
  379. }
  380. static int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
  381. {
  382. switch (qc->tf.protocol) {
  383. case ATA_PROT_DMA:
  384. case ATA_PROT_NODATA:
  385. pdc_packet_start(qc);
  386. return 0;
  387. case ATA_PROT_ATAPI_DMA:
  388. BUG();
  389. break;
  390. default:
  391. break;
  392. }
  393. return ata_qc_issue_prot(qc);
  394. }
  395. static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf)
  396. {
  397. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  398. tf->protocol == ATA_PROT_NODATA);
  399. ata_tf_load(ap, tf);
  400. }
  401. static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf)
  402. {
  403. WARN_ON (tf->protocol == ATA_PROT_DMA ||
  404. tf->protocol == ATA_PROT_NODATA);
  405. ata_exec_command(ap, tf);
  406. }
  407. static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
  408. {
  409. port->cmd_addr = base;
  410. port->data_addr = base;
  411. port->feature_addr =
  412. port->error_addr = base + 0x4;
  413. port->nsect_addr = base + 0x8;
  414. port->lbal_addr = base + 0xc;
  415. port->lbam_addr = base + 0x10;
  416. port->lbah_addr = base + 0x14;
  417. port->device_addr = base + 0x18;
  418. port->command_addr =
  419. port->status_addr = base + 0x1c;
  420. port->altstatus_addr =
  421. port->ctl_addr = base + 0x38;
  422. }
  423. static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
  424. {
  425. void *mmio = pe->mmio_base;
  426. u32 tmp;
  427. /*
  428. * Except for the hotplug stuff, this is voodoo from the
  429. * Promise driver. Label this entire section
  430. * "TODO: figure out why we do this"
  431. */
  432. /* change FIFO_SHD to 8 dwords, enable BMR_BURST */
  433. tmp = readl(mmio + PDC_FLASH_CTL);
  434. tmp |= 0x12000; /* bit 16 (fifo 8 dw) and 13 (bmr burst?) */
  435. writel(tmp, mmio + PDC_FLASH_CTL);
  436. /* clear plug/unplug flags for all ports */
  437. tmp = readl(mmio + PDC_SATA_PLUG_CSR);
  438. writel(tmp | 0xff, mmio + PDC_SATA_PLUG_CSR);
  439. /* mask plug/unplug ints */
  440. tmp = readl(mmio + PDC_SATA_PLUG_CSR);
  441. writel(tmp | 0xff0000, mmio + PDC_SATA_PLUG_CSR);
  442. /* reduce TBG clock to 133 Mhz. */
  443. tmp = readl(mmio + PDC_TBG_MODE);
  444. tmp &= ~0x30000; /* clear bit 17, 16*/
  445. tmp |= 0x10000; /* set bit 17:16 = 0:1 */
  446. writel(tmp, mmio + PDC_TBG_MODE);
  447. readl(mmio + PDC_TBG_MODE); /* flush */
  448. msleep(10);
  449. /* adjust slew rate control register. */
  450. tmp = readl(mmio + PDC_SLEW_CTL);
  451. tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
  452. tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
  453. writel(tmp, mmio + PDC_SLEW_CTL);
  454. }
  455. static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  456. {
  457. static int printed_version;
  458. struct ata_probe_ent *probe_ent = NULL;
  459. unsigned long base;
  460. void *mmio_base;
  461. unsigned int board_idx = (unsigned int) ent->driver_data;
  462. int pci_dev_busy = 0;
  463. int rc;
  464. if (!printed_version++)
  465. printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
  466. /*
  467. * If this driver happens to only be useful on Apple's K2, then
  468. * we should check that here as it has a normal Serverworks ID
  469. */
  470. rc = pci_enable_device(pdev);
  471. if (rc)
  472. return rc;
  473. rc = pci_request_regions(pdev, DRV_NAME);
  474. if (rc) {
  475. pci_dev_busy = 1;
  476. goto err_out;
  477. }
  478. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  479. if (rc)
  480. goto err_out_regions;
  481. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  482. if (rc)
  483. goto err_out_regions;
  484. probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
  485. if (probe_ent == NULL) {
  486. rc = -ENOMEM;
  487. goto err_out_regions;
  488. }
  489. memset(probe_ent, 0, sizeof(*probe_ent));
  490. probe_ent->dev = pci_dev_to_dev(pdev);
  491. INIT_LIST_HEAD(&probe_ent->node);
  492. mmio_base = ioremap(pci_resource_start(pdev, 3),
  493. pci_resource_len(pdev, 3));
  494. if (mmio_base == NULL) {
  495. rc = -ENOMEM;
  496. goto err_out_free_ent;
  497. }
  498. base = (unsigned long) mmio_base;
  499. probe_ent->sht = pdc_port_info[board_idx].sht;
  500. probe_ent->host_flags = pdc_port_info[board_idx].host_flags;
  501. probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
  502. probe_ent->mwdma_mask = pdc_port_info[board_idx].mwdma_mask;
  503. probe_ent->udma_mask = pdc_port_info[board_idx].udma_mask;
  504. probe_ent->port_ops = pdc_port_info[board_idx].port_ops;
  505. probe_ent->irq = pdev->irq;
  506. probe_ent->irq_flags = SA_SHIRQ;
  507. probe_ent->mmio_base = mmio_base;
  508. pdc_ata_setup_port(&probe_ent->port[0], base + 0x200);
  509. pdc_ata_setup_port(&probe_ent->port[1], base + 0x280);
  510. probe_ent->port[0].scr_addr = base + 0x400;
  511. probe_ent->port[1].scr_addr = base + 0x500;
  512. /* notice 4-port boards */
  513. switch (board_idx) {
  514. case board_20319:
  515. probe_ent->n_ports = 4;
  516. pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
  517. pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
  518. probe_ent->port[2].scr_addr = base + 0x600;
  519. probe_ent->port[3].scr_addr = base + 0x700;
  520. break;
  521. case board_2037x:
  522. probe_ent->n_ports = 2;
  523. break;
  524. default:
  525. BUG();
  526. break;
  527. }
  528. pci_set_master(pdev);
  529. /* initialize adapter */
  530. pdc_host_init(board_idx, probe_ent);
  531. /* FIXME: check ata_device_add return value */
  532. ata_device_add(probe_ent);
  533. kfree(probe_ent);
  534. return 0;
  535. err_out_free_ent:
  536. kfree(probe_ent);
  537. err_out_regions:
  538. pci_release_regions(pdev);
  539. err_out:
  540. if (!pci_dev_busy)
  541. pci_disable_device(pdev);
  542. return rc;
  543. }
  544. static int __init pdc_ata_init(void)
  545. {
  546. return pci_module_init(&pdc_ata_pci_driver);
  547. }
  548. static void __exit pdc_ata_exit(void)
  549. {
  550. pci_unregister_driver(&pdc_ata_pci_driver);
  551. }
  552. MODULE_AUTHOR("Jeff Garzik");
  553. MODULE_DESCRIPTION("Promise SATA TX2/TX4 low-level driver");
  554. MODULE_LICENSE("GPL");
  555. MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
  556. MODULE_VERSION(DRV_VERSION);
  557. module_init(pdc_ata_init);
  558. module_exit(pdc_ata_exit);