sata_promise.c 30 KB

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