sata_promise.c 18 KB

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