sata_promise.c 30 KB

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