sata_promise.c 30 KB

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