sata_promise.c 30 KB

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