sata_promise.c 30 KB

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