sata_promise.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. /*
  2. * sata_promise.c - Promise SATA
  3. *
  4. * Maintained by: Jeff Garzik <jgarzik@pobox.com>
  5. * Mikael Pettersson <mikpe@it.uu.se>
  6. * Please ALWAYS copy linux-ide@vger.kernel.org
  7. * on emails.
  8. *
  9. * Copyright 2003-2004 Red Hat, Inc.
  10. *
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2, or (at your option)
  15. * any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; see the file COPYING. If not, write to
  24. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25. *
  26. *
  27. * libata documentation is available via 'make {ps|pdf}docs',
  28. * as Documentation/DocBook/libata.*
  29. *
  30. * Hardware information only available under NDA.
  31. *
  32. */
  33. #include <linux/kernel.h>
  34. #include <linux/module.h>
  35. #include <linux/pci.h>
  36. #include <linux/init.h>
  37. #include <linux/blkdev.h>
  38. #include <linux/delay.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/device.h>
  41. #include <scsi/scsi.h>
  42. #include <scsi/scsi_host.h>
  43. #include <scsi/scsi_cmnd.h>
  44. #include <linux/libata.h>
  45. #include "sata_promise.h"
  46. #define DRV_NAME "sata_promise"
  47. #define DRV_VERSION "2.12"
  48. enum {
  49. PDC_MAX_PORTS = 4,
  50. PDC_MMIO_BAR = 3,
  51. PDC_MAX_PRD = LIBATA_MAX_PRD - 1, /* -1 for ASIC PRD bug workaround */
  52. /* host register offsets (from host->iomap[PDC_MMIO_BAR]) */
  53. PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
  54. PDC_FLASH_CTL = 0x44, /* Flash control register */
  55. PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */
  56. PDC2_SATA_PLUG_CSR = 0x60, /* SATAII Plug control/status reg */
  57. PDC_TBG_MODE = 0x41C, /* TBG mode (not SATAII) */
  58. PDC_SLEW_CTL = 0x470, /* slew rate control reg (not SATAII) */
  59. /* per-port ATA register offsets (from ap->ioaddr.cmd_addr) */
  60. PDC_FEATURE = 0x04, /* Feature/Error reg (per port) */
  61. PDC_SECTOR_COUNT = 0x08, /* Sector count reg (per port) */
  62. PDC_SECTOR_NUMBER = 0x0C, /* Sector number reg (per port) */
  63. PDC_CYLINDER_LOW = 0x10, /* Cylinder low reg (per port) */
  64. PDC_CYLINDER_HIGH = 0x14, /* Cylinder high reg (per port) */
  65. PDC_DEVICE = 0x18, /* Device/Head reg (per port) */
  66. PDC_COMMAND = 0x1C, /* Command/status reg (per port) */
  67. PDC_ALTSTATUS = 0x38, /* Alternate-status/device-control reg (per port) */
  68. PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
  69. PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */
  70. PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */
  71. /* per-port SATA register offsets (from ap->ioaddr.scr_addr) */
  72. PDC_PHYMODE4 = 0x14,
  73. /* PDC_GLOBAL_CTL bit definitions */
  74. PDC_PH_ERR = (1 << 8), /* PCI error while loading packet */
  75. PDC_SH_ERR = (1 << 9), /* PCI error while loading S/G table */
  76. PDC_DH_ERR = (1 << 10), /* PCI error while loading data */
  77. PDC2_HTO_ERR = (1 << 12), /* host bus timeout */
  78. PDC2_ATA_HBA_ERR = (1 << 13), /* error during SATA DATA FIS transmission */
  79. PDC2_ATA_DMA_CNT_ERR = (1 << 14), /* DMA DATA FIS size differs from S/G count */
  80. PDC_OVERRUN_ERR = (1 << 19), /* S/G byte count larger than HD requires */
  81. PDC_UNDERRUN_ERR = (1 << 20), /* S/G byte count less than HD requires */
  82. PDC_DRIVE_ERR = (1 << 21), /* drive error */
  83. PDC_PCI_SYS_ERR = (1 << 22), /* PCI system error */
  84. PDC1_PCI_PARITY_ERR = (1 << 23), /* PCI parity error (from SATA150 driver) */
  85. PDC1_ERR_MASK = PDC1_PCI_PARITY_ERR,
  86. PDC2_ERR_MASK = PDC2_HTO_ERR | PDC2_ATA_HBA_ERR |
  87. PDC2_ATA_DMA_CNT_ERR,
  88. PDC_ERR_MASK = PDC_PH_ERR | PDC_SH_ERR | PDC_DH_ERR |
  89. PDC_OVERRUN_ERR | PDC_UNDERRUN_ERR |
  90. PDC_DRIVE_ERR | PDC_PCI_SYS_ERR |
  91. PDC1_ERR_MASK | PDC2_ERR_MASK,
  92. board_2037x = 0, /* FastTrak S150 TX2plus */
  93. board_2037x_pata = 1, /* FastTrak S150 TX2plus PATA port */
  94. board_20319 = 2, /* FastTrak S150 TX4 */
  95. board_20619 = 3, /* FastTrak TX4000 */
  96. board_2057x = 4, /* SATAII150 Tx2plus */
  97. board_2057x_pata = 5, /* SATAII150 Tx2plus PATA port */
  98. board_40518 = 6, /* SATAII150 Tx4 */
  99. PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */
  100. /* Sequence counter control registers bit definitions */
  101. PDC_SEQCNTRL_INT_MASK = (1 << 5), /* Sequence Interrupt Mask */
  102. /* Feature register values */
  103. PDC_FEATURE_ATAPI_PIO = 0x00, /* ATAPI data xfer by PIO */
  104. PDC_FEATURE_ATAPI_DMA = 0x01, /* ATAPI data xfer by DMA */
  105. /* Device/Head register values */
  106. PDC_DEVICE_SATA = 0xE0, /* Device/Head value for SATA devices */
  107. /* PDC_CTLSTAT bit definitions */
  108. PDC_DMA_ENABLE = (1 << 7),
  109. PDC_IRQ_DISABLE = (1 << 10),
  110. PDC_RESET = (1 << 11), /* HDMA reset */
  111. PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY |
  112. ATA_FLAG_MMIO |
  113. ATA_FLAG_PIO_POLLING,
  114. /* ap->flags bits */
  115. PDC_FLAG_GEN_II = (1 << 24),
  116. PDC_FLAG_SATA_PATA = (1 << 25), /* supports SATA + PATA */
  117. PDC_FLAG_4_PORTS = (1 << 26), /* 4 ports */
  118. };
  119. struct pdc_port_priv {
  120. u8 *pkt;
  121. dma_addr_t pkt_dma;
  122. };
  123. static int pdc_sata_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
  124. static int pdc_sata_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
  125. static int pdc_ata_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
  126. static int pdc_common_port_start(struct ata_port *ap);
  127. static int pdc_sata_port_start(struct ata_port *ap);
  128. static void pdc_qc_prep(struct ata_queued_cmd *qc);
  129. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  130. static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  131. static int pdc_check_atapi_dma(struct ata_queued_cmd *qc);
  132. static int pdc_old_sata_check_atapi_dma(struct ata_queued_cmd *qc);
  133. static void pdc_irq_clear(struct ata_port *ap);
  134. static unsigned int pdc_qc_issue(struct ata_queued_cmd *qc);
  135. static void pdc_freeze(struct ata_port *ap);
  136. static void pdc_sata_freeze(struct ata_port *ap);
  137. static void pdc_thaw(struct ata_port *ap);
  138. static void pdc_sata_thaw(struct ata_port *ap);
  139. static int pdc_pata_softreset(struct ata_link *link, unsigned int *class,
  140. unsigned long deadline);
  141. static int pdc_sata_hardreset(struct ata_link *link, unsigned int *class,
  142. unsigned long deadline);
  143. static void pdc_error_handler(struct ata_port *ap);
  144. static void pdc_post_internal_cmd(struct ata_queued_cmd *qc);
  145. static int pdc_pata_cable_detect(struct ata_port *ap);
  146. static int pdc_sata_cable_detect(struct ata_port *ap);
  147. static struct scsi_host_template pdc_ata_sht = {
  148. ATA_BASE_SHT(DRV_NAME),
  149. .sg_tablesize = PDC_MAX_PRD,
  150. .dma_boundary = ATA_DMA_BOUNDARY,
  151. };
  152. static const struct ata_port_operations pdc_common_ops = {
  153. .inherits = &ata_sff_port_ops,
  154. .sff_tf_load = pdc_tf_load_mmio,
  155. .sff_exec_command = pdc_exec_command_mmio,
  156. .check_atapi_dma = pdc_check_atapi_dma,
  157. .qc_prep = pdc_qc_prep,
  158. .qc_issue = pdc_qc_issue,
  159. .sff_irq_clear = pdc_irq_clear,
  160. .lost_interrupt = ATA_OP_NULL,
  161. .post_internal_cmd = pdc_post_internal_cmd,
  162. .error_handler = pdc_error_handler,
  163. };
  164. static struct ata_port_operations pdc_sata_ops = {
  165. .inherits = &pdc_common_ops,
  166. .cable_detect = pdc_sata_cable_detect,
  167. .freeze = pdc_sata_freeze,
  168. .thaw = pdc_sata_thaw,
  169. .scr_read = pdc_sata_scr_read,
  170. .scr_write = pdc_sata_scr_write,
  171. .port_start = pdc_sata_port_start,
  172. .hardreset = pdc_sata_hardreset,
  173. };
  174. /* First-generation chips need a more restrictive ->check_atapi_dma op */
  175. static struct ata_port_operations pdc_old_sata_ops = {
  176. .inherits = &pdc_sata_ops,
  177. .check_atapi_dma = pdc_old_sata_check_atapi_dma,
  178. };
  179. static struct ata_port_operations pdc_pata_ops = {
  180. .inherits = &pdc_common_ops,
  181. .cable_detect = pdc_pata_cable_detect,
  182. .freeze = pdc_freeze,
  183. .thaw = pdc_thaw,
  184. .port_start = pdc_common_port_start,
  185. .softreset = pdc_pata_softreset,
  186. };
  187. static const struct ata_port_info pdc_port_info[] = {
  188. [board_2037x] =
  189. {
  190. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  191. PDC_FLAG_SATA_PATA,
  192. .pio_mask = ATA_PIO4,
  193. .mwdma_mask = ATA_MWDMA2,
  194. .udma_mask = ATA_UDMA6,
  195. .port_ops = &pdc_old_sata_ops,
  196. },
  197. [board_2037x_pata] =
  198. {
  199. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS,
  200. .pio_mask = ATA_PIO4,
  201. .mwdma_mask = ATA_MWDMA2,
  202. .udma_mask = ATA_UDMA6,
  203. .port_ops = &pdc_pata_ops,
  204. },
  205. [board_20319] =
  206. {
  207. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  208. PDC_FLAG_4_PORTS,
  209. .pio_mask = ATA_PIO4,
  210. .mwdma_mask = ATA_MWDMA2,
  211. .udma_mask = ATA_UDMA6,
  212. .port_ops = &pdc_old_sata_ops,
  213. },
  214. [board_20619] =
  215. {
  216. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS |
  217. PDC_FLAG_4_PORTS,
  218. .pio_mask = ATA_PIO4,
  219. .mwdma_mask = ATA_MWDMA2,
  220. .udma_mask = ATA_UDMA6,
  221. .port_ops = &pdc_pata_ops,
  222. },
  223. [board_2057x] =
  224. {
  225. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  226. PDC_FLAG_GEN_II | PDC_FLAG_SATA_PATA,
  227. .pio_mask = ATA_PIO4,
  228. .mwdma_mask = ATA_MWDMA2,
  229. .udma_mask = ATA_UDMA6,
  230. .port_ops = &pdc_sata_ops,
  231. },
  232. [board_2057x_pata] =
  233. {
  234. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS |
  235. PDC_FLAG_GEN_II,
  236. .pio_mask = ATA_PIO4,
  237. .mwdma_mask = ATA_MWDMA2,
  238. .udma_mask = ATA_UDMA6,
  239. .port_ops = &pdc_pata_ops,
  240. },
  241. [board_40518] =
  242. {
  243. .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  244. PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS,
  245. .pio_mask = ATA_PIO4,
  246. .mwdma_mask = ATA_MWDMA2,
  247. .udma_mask = ATA_UDMA6,
  248. .port_ops = &pdc_sata_ops,
  249. },
  250. };
  251. static const struct pci_device_id pdc_ata_pci_tbl[] = {
  252. { PCI_VDEVICE(PROMISE, 0x3371), board_2037x },
  253. { PCI_VDEVICE(PROMISE, 0x3373), board_2037x },
  254. { PCI_VDEVICE(PROMISE, 0x3375), board_2037x },
  255. { PCI_VDEVICE(PROMISE, 0x3376), board_2037x },
  256. { PCI_VDEVICE(PROMISE, 0x3570), board_2057x },
  257. { PCI_VDEVICE(PROMISE, 0x3571), board_2057x },
  258. { PCI_VDEVICE(PROMISE, 0x3574), board_2057x },
  259. { PCI_VDEVICE(PROMISE, 0x3577), board_2057x },
  260. { PCI_VDEVICE(PROMISE, 0x3d73), board_2057x },
  261. { PCI_VDEVICE(PROMISE, 0x3d75), board_2057x },
  262. { PCI_VDEVICE(PROMISE, 0x3318), board_20319 },
  263. { PCI_VDEVICE(PROMISE, 0x3319), board_20319 },
  264. { PCI_VDEVICE(PROMISE, 0x3515), board_40518 },
  265. { PCI_VDEVICE(PROMISE, 0x3519), board_40518 },
  266. { PCI_VDEVICE(PROMISE, 0x3d17), board_40518 },
  267. { PCI_VDEVICE(PROMISE, 0x3d18), board_40518 },
  268. { PCI_VDEVICE(PROMISE, 0x6629), board_20619 },
  269. { } /* terminate list */
  270. };
  271. static struct pci_driver pdc_ata_pci_driver = {
  272. .name = DRV_NAME,
  273. .id_table = pdc_ata_pci_tbl,
  274. .probe = pdc_ata_init_one,
  275. .remove = ata_pci_remove_one,
  276. };
  277. static int pdc_common_port_start(struct ata_port *ap)
  278. {
  279. struct device *dev = ap->host->dev;
  280. struct pdc_port_priv *pp;
  281. int rc;
  282. rc = ata_port_start(ap);
  283. if (rc)
  284. return rc;
  285. pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
  286. if (!pp)
  287. return -ENOMEM;
  288. pp->pkt = dmam_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  289. if (!pp->pkt)
  290. return -ENOMEM;
  291. ap->private_data = pp;
  292. return 0;
  293. }
  294. static int pdc_sata_port_start(struct ata_port *ap)
  295. {
  296. int rc;
  297. rc = pdc_common_port_start(ap);
  298. if (rc)
  299. return rc;
  300. /* fix up PHYMODE4 align timing */
  301. if (ap->flags & PDC_FLAG_GEN_II) {
  302. void __iomem *sata_mmio = ap->ioaddr.scr_addr;
  303. unsigned int tmp;
  304. tmp = readl(sata_mmio + PDC_PHYMODE4);
  305. tmp = (tmp & ~3) | 1; /* set bits 1:0 = 0:1 */
  306. writel(tmp, sata_mmio + PDC_PHYMODE4);
  307. }
  308. return 0;
  309. }
  310. static void pdc_reset_port(struct ata_port *ap)
  311. {
  312. void __iomem *ata_ctlstat_mmio = ap->ioaddr.cmd_addr + PDC_CTLSTAT;
  313. unsigned int i;
  314. u32 tmp;
  315. for (i = 11; i > 0; i--) {
  316. tmp = readl(ata_ctlstat_mmio);
  317. if (tmp & PDC_RESET)
  318. break;
  319. udelay(100);
  320. tmp |= PDC_RESET;
  321. writel(tmp, ata_ctlstat_mmio);
  322. }
  323. tmp &= ~PDC_RESET;
  324. writel(tmp, ata_ctlstat_mmio);
  325. readl(ata_ctlstat_mmio); /* flush */
  326. }
  327. static int pdc_pata_cable_detect(struct ata_port *ap)
  328. {
  329. u8 tmp;
  330. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  331. tmp = readb(ata_mmio + PDC_CTLSTAT + 3);
  332. if (tmp & 0x01)
  333. return ATA_CBL_PATA40;
  334. return ATA_CBL_PATA80;
  335. }
  336. static int pdc_sata_cable_detect(struct ata_port *ap)
  337. {
  338. return ATA_CBL_SATA;
  339. }
  340. static int pdc_sata_scr_read(struct ata_link *link,
  341. unsigned int sc_reg, u32 *val)
  342. {
  343. if (sc_reg > SCR_CONTROL)
  344. return -EINVAL;
  345. *val = readl(link->ap->ioaddr.scr_addr + (sc_reg * 4));
  346. return 0;
  347. }
  348. static int pdc_sata_scr_write(struct ata_link *link,
  349. unsigned int sc_reg, u32 val)
  350. {
  351. if (sc_reg > SCR_CONTROL)
  352. return -EINVAL;
  353. writel(val, link->ap->ioaddr.scr_addr + (sc_reg * 4));
  354. return 0;
  355. }
  356. static void pdc_atapi_pkt(struct ata_queued_cmd *qc)
  357. {
  358. struct ata_port *ap = qc->ap;
  359. dma_addr_t sg_table = ap->prd_dma;
  360. unsigned int cdb_len = qc->dev->cdb_len;
  361. u8 *cdb = qc->cdb;
  362. struct pdc_port_priv *pp = ap->private_data;
  363. u8 *buf = pp->pkt;
  364. __le32 *buf32 = (__le32 *) buf;
  365. unsigned int dev_sel, feature;
  366. /* set control bits (byte 0), zero delay seq id (byte 3),
  367. * and seq id (byte 2)
  368. */
  369. switch (qc->tf.protocol) {
  370. case ATAPI_PROT_DMA:
  371. if (!(qc->tf.flags & ATA_TFLAG_WRITE))
  372. buf32[0] = cpu_to_le32(PDC_PKT_READ);
  373. else
  374. buf32[0] = 0;
  375. break;
  376. case ATAPI_PROT_NODATA:
  377. buf32[0] = cpu_to_le32(PDC_PKT_NODATA);
  378. break;
  379. default:
  380. BUG();
  381. break;
  382. }
  383. buf32[1] = cpu_to_le32(sg_table); /* S/G table addr */
  384. buf32[2] = 0; /* no next-packet */
  385. /* select drive */
  386. if (sata_scr_valid(&ap->link))
  387. dev_sel = PDC_DEVICE_SATA;
  388. else
  389. dev_sel = qc->tf.device;
  390. buf[12] = (1 << 5) | ATA_REG_DEVICE;
  391. buf[13] = dev_sel;
  392. buf[14] = (1 << 5) | ATA_REG_DEVICE | PDC_PKT_CLEAR_BSY;
  393. buf[15] = dev_sel; /* once more, waiting for BSY to clear */
  394. buf[16] = (1 << 5) | ATA_REG_NSECT;
  395. buf[17] = qc->tf.nsect;
  396. buf[18] = (1 << 5) | ATA_REG_LBAL;
  397. buf[19] = qc->tf.lbal;
  398. /* set feature and byte counter registers */
  399. if (qc->tf.protocol != ATAPI_PROT_DMA)
  400. feature = PDC_FEATURE_ATAPI_PIO;
  401. else
  402. feature = PDC_FEATURE_ATAPI_DMA;
  403. buf[20] = (1 << 5) | ATA_REG_FEATURE;
  404. buf[21] = feature;
  405. buf[22] = (1 << 5) | ATA_REG_BYTEL;
  406. buf[23] = qc->tf.lbam;
  407. buf[24] = (1 << 5) | ATA_REG_BYTEH;
  408. buf[25] = qc->tf.lbah;
  409. /* send ATAPI packet command 0xA0 */
  410. buf[26] = (1 << 5) | ATA_REG_CMD;
  411. buf[27] = qc->tf.command;
  412. /* select drive and check DRQ */
  413. buf[28] = (1 << 5) | ATA_REG_DEVICE | PDC_PKT_WAIT_DRDY;
  414. buf[29] = dev_sel;
  415. /* we can represent cdb lengths 2/4/6/8/10/12/14/16 */
  416. BUG_ON(cdb_len & ~0x1E);
  417. /* append the CDB as the final part */
  418. buf[30] = (((cdb_len >> 1) & 7) << 5) | ATA_REG_DATA | PDC_LAST_REG;
  419. memcpy(buf+31, cdb, cdb_len);
  420. }
  421. /**
  422. * pdc_fill_sg - Fill PCI IDE PRD table
  423. * @qc: Metadata associated with taskfile to be transferred
  424. *
  425. * Fill PCI IDE PRD (scatter-gather) table with segments
  426. * associated with the current disk command.
  427. * Make sure hardware does not choke on it.
  428. *
  429. * LOCKING:
  430. * spin_lock_irqsave(host lock)
  431. *
  432. */
  433. static void pdc_fill_sg(struct ata_queued_cmd *qc)
  434. {
  435. struct ata_port *ap = qc->ap;
  436. struct scatterlist *sg;
  437. const u32 SG_COUNT_ASIC_BUG = 41*4;
  438. unsigned int si, idx;
  439. u32 len;
  440. if (!(qc->flags & ATA_QCFLAG_DMAMAP))
  441. return;
  442. idx = 0;
  443. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  444. u32 addr, offset;
  445. u32 sg_len;
  446. /* determine if physical DMA addr spans 64K boundary.
  447. * Note h/w doesn't support 64-bit, so we unconditionally
  448. * truncate dma_addr_t to u32.
  449. */
  450. addr = (u32) sg_dma_address(sg);
  451. sg_len = sg_dma_len(sg);
  452. while (sg_len) {
  453. offset = addr & 0xffff;
  454. len = sg_len;
  455. if ((offset + sg_len) > 0x10000)
  456. len = 0x10000 - offset;
  457. ap->prd[idx].addr = cpu_to_le32(addr);
  458. ap->prd[idx].flags_len = cpu_to_le32(len & 0xffff);
  459. VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len);
  460. idx++;
  461. sg_len -= len;
  462. addr += len;
  463. }
  464. }
  465. len = le32_to_cpu(ap->prd[idx - 1].flags_len);
  466. if (len > SG_COUNT_ASIC_BUG) {
  467. u32 addr;
  468. VPRINTK("Splitting last PRD.\n");
  469. addr = le32_to_cpu(ap->prd[idx - 1].addr);
  470. ap->prd[idx - 1].flags_len = cpu_to_le32(len - SG_COUNT_ASIC_BUG);
  471. VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx - 1, addr, SG_COUNT_ASIC_BUG);
  472. addr = addr + len - SG_COUNT_ASIC_BUG;
  473. len = SG_COUNT_ASIC_BUG;
  474. ap->prd[idx].addr = cpu_to_le32(addr);
  475. ap->prd[idx].flags_len = cpu_to_le32(len);
  476. VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len);
  477. idx++;
  478. }
  479. ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
  480. }
  481. static void pdc_qc_prep(struct ata_queued_cmd *qc)
  482. {
  483. struct pdc_port_priv *pp = qc->ap->private_data;
  484. unsigned int i;
  485. VPRINTK("ENTER\n");
  486. switch (qc->tf.protocol) {
  487. case ATA_PROT_DMA:
  488. pdc_fill_sg(qc);
  489. /*FALLTHROUGH*/
  490. case ATA_PROT_NODATA:
  491. i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
  492. qc->dev->devno, pp->pkt);
  493. if (qc->tf.flags & ATA_TFLAG_LBA48)
  494. i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
  495. else
  496. i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
  497. pdc_pkt_footer(&qc->tf, pp->pkt, i);
  498. break;
  499. case ATAPI_PROT_PIO:
  500. pdc_fill_sg(qc);
  501. break;
  502. case ATAPI_PROT_DMA:
  503. pdc_fill_sg(qc);
  504. /*FALLTHROUGH*/
  505. case ATAPI_PROT_NODATA:
  506. pdc_atapi_pkt(qc);
  507. break;
  508. default:
  509. break;
  510. }
  511. }
  512. static int pdc_is_sataii_tx4(unsigned long flags)
  513. {
  514. const unsigned long mask = PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS;
  515. return (flags & mask) == mask;
  516. }
  517. static unsigned int pdc_port_no_to_ata_no(unsigned int port_no,
  518. int is_sataii_tx4)
  519. {
  520. static const unsigned char sataii_tx4_port_remap[4] = { 3, 1, 0, 2};
  521. return is_sataii_tx4 ? sataii_tx4_port_remap[port_no] : port_no;
  522. }
  523. static unsigned int pdc_sata_nr_ports(const struct ata_port *ap)
  524. {
  525. return (ap->flags & PDC_FLAG_4_PORTS) ? 4 : 2;
  526. }
  527. static unsigned int pdc_sata_ata_port_to_ata_no(const struct ata_port *ap)
  528. {
  529. const struct ata_host *host = ap->host;
  530. unsigned int nr_ports = pdc_sata_nr_ports(ap);
  531. unsigned int i;
  532. for (i = 0; i < nr_ports && host->ports[i] != ap; ++i)
  533. ;
  534. BUG_ON(i >= nr_ports);
  535. return pdc_port_no_to_ata_no(i, pdc_is_sataii_tx4(ap->flags));
  536. }
  537. static unsigned int pdc_sata_hotplug_offset(const struct ata_port *ap)
  538. {
  539. return (ap->flags & PDC_FLAG_GEN_II) ? PDC2_SATA_PLUG_CSR : PDC_SATA_PLUG_CSR;
  540. }
  541. static void pdc_freeze(struct ata_port *ap)
  542. {
  543. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  544. u32 tmp;
  545. tmp = readl(ata_mmio + PDC_CTLSTAT);
  546. tmp |= PDC_IRQ_DISABLE;
  547. tmp &= ~PDC_DMA_ENABLE;
  548. writel(tmp, ata_mmio + PDC_CTLSTAT);
  549. readl(ata_mmio + PDC_CTLSTAT); /* flush */
  550. }
  551. static void pdc_sata_freeze(struct ata_port *ap)
  552. {
  553. struct ata_host *host = ap->host;
  554. void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR];
  555. unsigned int hotplug_offset = pdc_sata_hotplug_offset(ap);
  556. unsigned int ata_no = pdc_sata_ata_port_to_ata_no(ap);
  557. u32 hotplug_status;
  558. /* Disable hotplug events on this port.
  559. *
  560. * Locking:
  561. * 1) hotplug register accesses must be serialised via host->lock
  562. * 2) ap->lock == &ap->host->lock
  563. * 3) ->freeze() and ->thaw() are called with ap->lock held
  564. */
  565. hotplug_status = readl(host_mmio + hotplug_offset);
  566. hotplug_status |= 0x11 << (ata_no + 16);
  567. writel(hotplug_status, host_mmio + hotplug_offset);
  568. readl(host_mmio + hotplug_offset); /* flush */
  569. pdc_freeze(ap);
  570. }
  571. static void pdc_thaw(struct ata_port *ap)
  572. {
  573. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  574. u32 tmp;
  575. /* clear IRQ */
  576. readl(ata_mmio + PDC_COMMAND);
  577. /* turn IRQ back on */
  578. tmp = readl(ata_mmio + PDC_CTLSTAT);
  579. tmp &= ~PDC_IRQ_DISABLE;
  580. writel(tmp, ata_mmio + PDC_CTLSTAT);
  581. readl(ata_mmio + PDC_CTLSTAT); /* flush */
  582. }
  583. static void pdc_sata_thaw(struct ata_port *ap)
  584. {
  585. struct ata_host *host = ap->host;
  586. void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR];
  587. unsigned int hotplug_offset = pdc_sata_hotplug_offset(ap);
  588. unsigned int ata_no = pdc_sata_ata_port_to_ata_no(ap);
  589. u32 hotplug_status;
  590. pdc_thaw(ap);
  591. /* Enable hotplug events on this port.
  592. * Locking: see pdc_sata_freeze().
  593. */
  594. hotplug_status = readl(host_mmio + hotplug_offset);
  595. hotplug_status |= 0x11 << ata_no;
  596. hotplug_status &= ~(0x11 << (ata_no + 16));
  597. writel(hotplug_status, host_mmio + hotplug_offset);
  598. readl(host_mmio + hotplug_offset); /* flush */
  599. }
  600. static int pdc_pata_softreset(struct ata_link *link, unsigned int *class,
  601. unsigned long deadline)
  602. {
  603. pdc_reset_port(link->ap);
  604. return ata_sff_softreset(link, class, deadline);
  605. }
  606. static int pdc_sata_hardreset(struct ata_link *link, unsigned int *class,
  607. unsigned long deadline)
  608. {
  609. pdc_reset_port(link->ap);
  610. return sata_sff_hardreset(link, class, deadline);
  611. }
  612. static void pdc_error_handler(struct ata_port *ap)
  613. {
  614. if (!(ap->pflags & ATA_PFLAG_FROZEN))
  615. pdc_reset_port(ap);
  616. ata_std_error_handler(ap);
  617. }
  618. static void pdc_post_internal_cmd(struct ata_queued_cmd *qc)
  619. {
  620. struct ata_port *ap = qc->ap;
  621. /* make DMA engine forget about the failed command */
  622. if (qc->flags & ATA_QCFLAG_FAILED)
  623. pdc_reset_port(ap);
  624. }
  625. static void pdc_error_intr(struct ata_port *ap, struct ata_queued_cmd *qc,
  626. u32 port_status, u32 err_mask)
  627. {
  628. struct ata_eh_info *ehi = &ap->link.eh_info;
  629. unsigned int ac_err_mask = 0;
  630. ata_ehi_clear_desc(ehi);
  631. ata_ehi_push_desc(ehi, "port_status 0x%08x", port_status);
  632. port_status &= err_mask;
  633. if (port_status & PDC_DRIVE_ERR)
  634. ac_err_mask |= AC_ERR_DEV;
  635. if (port_status & (PDC_OVERRUN_ERR | PDC_UNDERRUN_ERR))
  636. ac_err_mask |= AC_ERR_HSM;
  637. if (port_status & (PDC2_ATA_HBA_ERR | PDC2_ATA_DMA_CNT_ERR))
  638. ac_err_mask |= AC_ERR_ATA_BUS;
  639. if (port_status & (PDC_PH_ERR | PDC_SH_ERR | PDC_DH_ERR | PDC2_HTO_ERR
  640. | PDC_PCI_SYS_ERR | PDC1_PCI_PARITY_ERR))
  641. ac_err_mask |= AC_ERR_HOST_BUS;
  642. if (sata_scr_valid(&ap->link)) {
  643. u32 serror;
  644. pdc_sata_scr_read(&ap->link, SCR_ERROR, &serror);
  645. ehi->serror |= serror;
  646. }
  647. qc->err_mask |= ac_err_mask;
  648. pdc_reset_port(ap);
  649. ata_port_abort(ap);
  650. }
  651. static unsigned int pdc_host_intr(struct ata_port *ap,
  652. struct ata_queued_cmd *qc)
  653. {
  654. unsigned int handled = 0;
  655. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  656. u32 port_status, err_mask;
  657. err_mask = PDC_ERR_MASK;
  658. if (ap->flags & PDC_FLAG_GEN_II)
  659. err_mask &= ~PDC1_ERR_MASK;
  660. else
  661. err_mask &= ~PDC2_ERR_MASK;
  662. port_status = readl(ata_mmio + PDC_GLOBAL_CTL);
  663. if (unlikely(port_status & err_mask)) {
  664. pdc_error_intr(ap, qc, port_status, err_mask);
  665. return 1;
  666. }
  667. switch (qc->tf.protocol) {
  668. case ATA_PROT_DMA:
  669. case ATA_PROT_NODATA:
  670. case ATAPI_PROT_DMA:
  671. case ATAPI_PROT_NODATA:
  672. qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
  673. ata_qc_complete(qc);
  674. handled = 1;
  675. break;
  676. default:
  677. ap->stats.idle_irq++;
  678. break;
  679. }
  680. return handled;
  681. }
  682. static void pdc_irq_clear(struct ata_port *ap)
  683. {
  684. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  685. readl(ata_mmio + PDC_COMMAND);
  686. }
  687. static irqreturn_t pdc_interrupt(int irq, void *dev_instance)
  688. {
  689. struct ata_host *host = dev_instance;
  690. struct ata_port *ap;
  691. u32 mask = 0;
  692. unsigned int i, tmp;
  693. unsigned int handled = 0;
  694. void __iomem *host_mmio;
  695. unsigned int hotplug_offset, ata_no;
  696. u32 hotplug_status;
  697. int is_sataii_tx4;
  698. VPRINTK("ENTER\n");
  699. if (!host || !host->iomap[PDC_MMIO_BAR]) {
  700. VPRINTK("QUICK EXIT\n");
  701. return IRQ_NONE;
  702. }
  703. host_mmio = host->iomap[PDC_MMIO_BAR];
  704. spin_lock(&host->lock);
  705. /* read and clear hotplug flags for all ports */
  706. if (host->ports[0]->flags & PDC_FLAG_GEN_II)
  707. hotplug_offset = PDC2_SATA_PLUG_CSR;
  708. else
  709. hotplug_offset = PDC_SATA_PLUG_CSR;
  710. hotplug_status = readl(host_mmio + hotplug_offset);
  711. if (hotplug_status & 0xff)
  712. writel(hotplug_status | 0xff, host_mmio + hotplug_offset);
  713. hotplug_status &= 0xff; /* clear uninteresting bits */
  714. /* reading should also clear interrupts */
  715. mask = readl(host_mmio + PDC_INT_SEQMASK);
  716. if (mask == 0xffffffff && hotplug_status == 0) {
  717. VPRINTK("QUICK EXIT 2\n");
  718. goto done_irq;
  719. }
  720. mask &= 0xffff; /* only 16 SEQIDs possible */
  721. if (mask == 0 && hotplug_status == 0) {
  722. VPRINTK("QUICK EXIT 3\n");
  723. goto done_irq;
  724. }
  725. writel(mask, host_mmio + PDC_INT_SEQMASK);
  726. is_sataii_tx4 = pdc_is_sataii_tx4(host->ports[0]->flags);
  727. for (i = 0; i < host->n_ports; i++) {
  728. VPRINTK("port %u\n", i);
  729. ap = host->ports[i];
  730. /* check for a plug or unplug event */
  731. ata_no = pdc_port_no_to_ata_no(i, is_sataii_tx4);
  732. tmp = hotplug_status & (0x11 << ata_no);
  733. if (tmp && ap &&
  734. !(ap->flags & ATA_FLAG_DISABLED)) {
  735. struct ata_eh_info *ehi = &ap->link.eh_info;
  736. ata_ehi_clear_desc(ehi);
  737. ata_ehi_hotplugged(ehi);
  738. ata_ehi_push_desc(ehi, "hotplug_status %#x", tmp);
  739. ata_port_freeze(ap);
  740. ++handled;
  741. continue;
  742. }
  743. /* check for a packet interrupt */
  744. tmp = mask & (1 << (i + 1));
  745. if (tmp && ap &&
  746. !(ap->flags & ATA_FLAG_DISABLED)) {
  747. struct ata_queued_cmd *qc;
  748. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  749. if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
  750. handled += pdc_host_intr(ap, qc);
  751. }
  752. }
  753. VPRINTK("EXIT\n");
  754. done_irq:
  755. spin_unlock(&host->lock);
  756. return IRQ_RETVAL(handled);
  757. }
  758. static void pdc_packet_start(struct ata_queued_cmd *qc)
  759. {
  760. struct ata_port *ap = qc->ap;
  761. struct pdc_port_priv *pp = ap->private_data;
  762. void __iomem *host_mmio = ap->host->iomap[PDC_MMIO_BAR];
  763. void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
  764. unsigned int port_no = ap->port_no;
  765. u8 seq = (u8) (port_no + 1);
  766. VPRINTK("ENTER, ap %p\n", ap);
  767. writel(0x00000001, host_mmio + (seq * 4));
  768. readl(host_mmio + (seq * 4)); /* flush */
  769. pp->pkt[2] = seq;
  770. wmb(); /* flush PRD, pkt writes */
  771. writel(pp->pkt_dma, ata_mmio + PDC_PKT_SUBMIT);
  772. readl(ata_mmio + PDC_PKT_SUBMIT); /* flush */
  773. }
  774. static unsigned int pdc_qc_issue(struct ata_queued_cmd *qc)
  775. {
  776. switch (qc->tf.protocol) {
  777. case ATAPI_PROT_NODATA:
  778. if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
  779. break;
  780. /*FALLTHROUGH*/
  781. case ATA_PROT_NODATA:
  782. if (qc->tf.flags & ATA_TFLAG_POLLING)
  783. break;
  784. /*FALLTHROUGH*/
  785. case ATAPI_PROT_DMA:
  786. case ATA_PROT_DMA:
  787. pdc_packet_start(qc);
  788. return 0;
  789. default:
  790. break;
  791. }
  792. return ata_sff_qc_issue(qc);
  793. }
  794. static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
  795. {
  796. WARN_ON(tf->protocol == ATA_PROT_DMA || tf->protocol == ATAPI_PROT_DMA);
  797. ata_sff_tf_load(ap, tf);
  798. }
  799. static void pdc_exec_command_mmio(struct ata_port *ap,
  800. const struct ata_taskfile *tf)
  801. {
  802. WARN_ON(tf->protocol == ATA_PROT_DMA || tf->protocol == ATAPI_PROT_DMA);
  803. ata_sff_exec_command(ap, tf);
  804. }
  805. static int pdc_check_atapi_dma(struct ata_queued_cmd *qc)
  806. {
  807. u8 *scsicmd = qc->scsicmd->cmnd;
  808. int pio = 1; /* atapi dma off by default */
  809. /* Whitelist commands that may use DMA. */
  810. switch (scsicmd[0]) {
  811. case WRITE_12:
  812. case WRITE_10:
  813. case WRITE_6:
  814. case READ_12:
  815. case READ_10:
  816. case READ_6:
  817. case 0xad: /* READ_DVD_STRUCTURE */
  818. case 0xbe: /* READ_CD */
  819. pio = 0;
  820. }
  821. /* -45150 (FFFF4FA2) to -1 (FFFFFFFF) shall use PIO mode */
  822. if (scsicmd[0] == WRITE_10) {
  823. unsigned int lba =
  824. (scsicmd[2] << 24) |
  825. (scsicmd[3] << 16) |
  826. (scsicmd[4] << 8) |
  827. scsicmd[5];
  828. if (lba >= 0xFFFF4FA2)
  829. pio = 1;
  830. }
  831. return pio;
  832. }
  833. static int pdc_old_sata_check_atapi_dma(struct ata_queued_cmd *qc)
  834. {
  835. /* First generation chips cannot use ATAPI DMA on SATA ports */
  836. return 1;
  837. }
  838. static void pdc_ata_setup_port(struct ata_port *ap,
  839. void __iomem *base, void __iomem *scr_addr)
  840. {
  841. ap->ioaddr.cmd_addr = base;
  842. ap->ioaddr.data_addr = base;
  843. ap->ioaddr.feature_addr =
  844. ap->ioaddr.error_addr = base + 0x4;
  845. ap->ioaddr.nsect_addr = base + 0x8;
  846. ap->ioaddr.lbal_addr = base + 0xc;
  847. ap->ioaddr.lbam_addr = base + 0x10;
  848. ap->ioaddr.lbah_addr = base + 0x14;
  849. ap->ioaddr.device_addr = base + 0x18;
  850. ap->ioaddr.command_addr =
  851. ap->ioaddr.status_addr = base + 0x1c;
  852. ap->ioaddr.altstatus_addr =
  853. ap->ioaddr.ctl_addr = base + 0x38;
  854. ap->ioaddr.scr_addr = scr_addr;
  855. }
  856. static void pdc_host_init(struct ata_host *host)
  857. {
  858. void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR];
  859. int is_gen2 = host->ports[0]->flags & PDC_FLAG_GEN_II;
  860. int hotplug_offset;
  861. u32 tmp;
  862. if (is_gen2)
  863. hotplug_offset = PDC2_SATA_PLUG_CSR;
  864. else
  865. hotplug_offset = PDC_SATA_PLUG_CSR;
  866. /*
  867. * Except for the hotplug stuff, this is voodoo from the
  868. * Promise driver. Label this entire section
  869. * "TODO: figure out why we do this"
  870. */
  871. /* enable BMR_BURST, maybe change FIFO_SHD to 8 dwords */
  872. tmp = readl(host_mmio + PDC_FLASH_CTL);
  873. tmp |= 0x02000; /* bit 13 (enable bmr burst) */
  874. if (!is_gen2)
  875. tmp |= 0x10000; /* bit 16 (fifo threshold at 8 dw) */
  876. writel(tmp, host_mmio + PDC_FLASH_CTL);
  877. /* clear plug/unplug flags for all ports */
  878. tmp = readl(host_mmio + hotplug_offset);
  879. writel(tmp | 0xff, host_mmio + hotplug_offset);
  880. /* unmask plug/unplug ints */
  881. tmp = readl(host_mmio + hotplug_offset);
  882. writel(tmp & ~0xff0000, host_mmio + hotplug_offset);
  883. /* don't initialise TBG or SLEW on 2nd generation chips */
  884. if (is_gen2)
  885. return;
  886. /* reduce TBG clock to 133 Mhz. */
  887. tmp = readl(host_mmio + PDC_TBG_MODE);
  888. tmp &= ~0x30000; /* clear bit 17, 16*/
  889. tmp |= 0x10000; /* set bit 17:16 = 0:1 */
  890. writel(tmp, host_mmio + PDC_TBG_MODE);
  891. readl(host_mmio + PDC_TBG_MODE); /* flush */
  892. msleep(10);
  893. /* adjust slew rate control register. */
  894. tmp = readl(host_mmio + PDC_SLEW_CTL);
  895. tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
  896. tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
  897. writel(tmp, host_mmio + PDC_SLEW_CTL);
  898. }
  899. static int pdc_ata_init_one(struct pci_dev *pdev,
  900. const struct pci_device_id *ent)
  901. {
  902. static int printed_version;
  903. const struct ata_port_info *pi = &pdc_port_info[ent->driver_data];
  904. const struct ata_port_info *ppi[PDC_MAX_PORTS];
  905. struct ata_host *host;
  906. void __iomem *host_mmio;
  907. int n_ports, i, rc;
  908. int is_sataii_tx4;
  909. if (!printed_version++)
  910. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  911. /* enable and acquire resources */
  912. rc = pcim_enable_device(pdev);
  913. if (rc)
  914. return rc;
  915. rc = pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME);
  916. if (rc == -EBUSY)
  917. pcim_pin_device(pdev);
  918. if (rc)
  919. return rc;
  920. host_mmio = pcim_iomap_table(pdev)[PDC_MMIO_BAR];
  921. /* determine port configuration and setup host */
  922. n_ports = 2;
  923. if (pi->flags & PDC_FLAG_4_PORTS)
  924. n_ports = 4;
  925. for (i = 0; i < n_ports; i++)
  926. ppi[i] = pi;
  927. if (pi->flags & PDC_FLAG_SATA_PATA) {
  928. u8 tmp = readb(host_mmio + PDC_FLASH_CTL + 1);
  929. if (!(tmp & 0x80))
  930. ppi[n_ports++] = pi + 1;
  931. }
  932. host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
  933. if (!host) {
  934. dev_printk(KERN_ERR, &pdev->dev, "failed to allocate host\n");
  935. return -ENOMEM;
  936. }
  937. host->iomap = pcim_iomap_table(pdev);
  938. is_sataii_tx4 = pdc_is_sataii_tx4(pi->flags);
  939. for (i = 0; i < host->n_ports; i++) {
  940. struct ata_port *ap = host->ports[i];
  941. unsigned int ata_no = pdc_port_no_to_ata_no(i, is_sataii_tx4);
  942. unsigned int ata_offset = 0x200 + ata_no * 0x80;
  943. unsigned int scr_offset = 0x400 + ata_no * 0x100;
  944. pdc_ata_setup_port(ap, host_mmio + ata_offset, host_mmio + scr_offset);
  945. ata_port_pbar_desc(ap, PDC_MMIO_BAR, -1, "mmio");
  946. ata_port_pbar_desc(ap, PDC_MMIO_BAR, ata_offset, "ata");
  947. }
  948. /* initialize adapter */
  949. pdc_host_init(host);
  950. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  951. if (rc)
  952. return rc;
  953. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  954. if (rc)
  955. return rc;
  956. /* start host, request IRQ and attach */
  957. pci_set_master(pdev);
  958. return ata_host_activate(host, pdev->irq, pdc_interrupt, IRQF_SHARED,
  959. &pdc_ata_sht);
  960. }
  961. static int __init pdc_ata_init(void)
  962. {
  963. return pci_register_driver(&pdc_ata_pci_driver);
  964. }
  965. static void __exit pdc_ata_exit(void)
  966. {
  967. pci_unregister_driver(&pdc_ata_pci_driver);
  968. }
  969. MODULE_AUTHOR("Jeff Garzik");
  970. MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
  971. MODULE_LICENSE("GPL");
  972. MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
  973. MODULE_VERSION(DRV_VERSION);
  974. module_init(pdc_ata_init);
  975. module_exit(pdc_ata_exit);