sata_promise.c 30 KB

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