sata_promise.c 30 KB

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