sata_promise.c 29 KB

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