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