blob: 75321f1ceba523e1632ed5e12eb3ccef59d990e8 [file] [log] [blame]
Thomas Gleixnerc82ee6d2019-05-19 15:51:48 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sata_sil.c - Silicon Image SATA
4 *
Tejun Heo8c3d3d42013-05-14 11:09:50 -07005 * Maintained by: Tejun Heo <tj@kernel.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Please ALWAYS copy linux-ide@vger.kernel.org
7 * on emails.
8 *
Jeff Garzikaf36d7f2005-08-28 20:18:39 -04009 * Copyright 2003-2005 Red Hat, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * Copyright 2003 Benjamin Herrenschmidt
11 *
Jeff Garzikaf36d7f2005-08-28 20:18:39 -040012 * libata documentation is available via 'make {ps|pdf}docs',
Mauro Carvalho Chehab19285f32017-05-14 11:52:56 -030013 * as Documentation/driver-api/libata.rst
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 *
Jeff Garzik953d1132005-08-26 19:46:24 -040015 * Documentation for SiI 3112:
16 * http://gkernel.sourceforge.net/specs/sii/3112A_SiI-DS-0095-B2.pdf.bz2
17 *
18 * Other errata and documentation available under NDA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/blkdev.h>
25#include <linux/delay.h>
26#include <linux/interrupt.h>
Jeff Garzika9524a72005-10-30 14:39:11 -050027#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <scsi/scsi_host.h>
29#include <linux/libata.h>
Alexander Beregalov1737ef72009-01-29 02:30:56 +030030#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#define DRV_NAME "sata_sil"
Robert Hancockc7e324f2008-12-24 19:06:06 -060033#define DRV_VERSION "2.4"
34
35#define SIL_DMA_BOUNDARY 0x7fffffffUL
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37enum {
Tejun Heo0d5ff562007-02-01 15:06:36 +090038 SIL_MMIO_BAR = 5,
39
Tejun Heoe653a1e2006-03-05 16:03:52 +090040 /*
41 * host flags
42 */
Tejun Heo201ce852006-06-26 21:23:52 +090043 SIL_FLAG_NO_SATA_IRQ = (1 << 28),
Tejun Heoe4e10e32006-02-25 13:52:30 +090044 SIL_FLAG_RERR_ON_DMA_ACT = (1 << 29),
Tejun Heoe4deec62005-08-23 07:27:25 +090045 SIL_FLAG_MOD15WRITE = (1 << 30),
Tejun Heo20888d82006-05-31 18:27:53 +090046
Sergei Shtylyov9cbe0562011-02-04 22:05:48 +030047 SIL_DFL_PORT_FLAGS = ATA_FLAG_SATA,
Tejun Heoe4deec62005-08-23 07:27:25 +090048
Tejun Heoe653a1e2006-03-05 16:03:52 +090049 /*
50 * Controller IDs
51 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 sil_3112 = 0,
Tejun Heo201ce852006-06-26 21:23:52 +090053 sil_3112_no_sata_irq = 1,
54 sil_3512 = 2,
55 sil_3114 = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Tejun Heoe653a1e2006-03-05 16:03:52 +090057 /*
58 * Register offsets
59 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 SIL_SYSCFG = 0x48,
Tejun Heoe653a1e2006-03-05 16:03:52 +090061
62 /*
63 * Register bits
64 */
65 /* SYSCFG */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 SIL_MASK_IDE0_INT = (1 << 22),
67 SIL_MASK_IDE1_INT = (1 << 23),
68 SIL_MASK_IDE2_INT = (1 << 24),
69 SIL_MASK_IDE3_INT = (1 << 25),
70 SIL_MASK_2PORT = SIL_MASK_IDE0_INT | SIL_MASK_IDE1_INT,
71 SIL_MASK_4PORT = SIL_MASK_2PORT |
72 SIL_MASK_IDE2_INT | SIL_MASK_IDE3_INT,
73
Tejun Heoe653a1e2006-03-05 16:03:52 +090074 /* BMDMA/BMDMA2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 SIL_INTR_STEERING = (1 << 1),
Tejun Heoe653a1e2006-03-05 16:03:52 +090076
Tejun Heo20888d82006-05-31 18:27:53 +090077 SIL_DMA_ENABLE = (1 << 0), /* DMA run switch */
78 SIL_DMA_RDWR = (1 << 3), /* DMA Rd-Wr */
79 SIL_DMA_SATA_IRQ = (1 << 4), /* OR of all SATA IRQs */
80 SIL_DMA_ACTIVE = (1 << 16), /* DMA running */
81 SIL_DMA_ERROR = (1 << 17), /* PCI bus error */
82 SIL_DMA_COMPLETE = (1 << 18), /* cmd complete / IRQ pending */
83 SIL_DMA_N_SATA_IRQ = (1 << 6), /* SATA_IRQ for the next channel */
84 SIL_DMA_N_ACTIVE = (1 << 24), /* ACTIVE for the next channel */
85 SIL_DMA_N_ERROR = (1 << 25), /* ERROR for the next channel */
86 SIL_DMA_N_COMPLETE = (1 << 26), /* COMPLETE for the next channel */
87
88 /* SIEN */
89 SIL_SIEN_N = (1 << 16), /* triggered by SError.N */
90
Tejun Heoe653a1e2006-03-05 16:03:52 +090091 /*
92 * Others
93 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 SIL_QUIRK_MOD15WRITE = (1 << 0),
95 SIL_QUIRK_UDMA5MAX = (1 << 1),
96};
97
Jeff Garzik5796d1c2007-10-26 00:03:37 -040098static int sil_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
Bartlomiej Zolnierkiewicz58eb8cd2014-05-07 17:17:44 +020099#ifdef CONFIG_PM_SLEEP
Tejun Heoafb5a7c2006-07-03 16:07:27 +0900100static int sil_pci_device_resume(struct pci_dev *pdev);
Alexey Dobriyan281d4262006-08-14 22:49:30 -0700101#endif
Alancd0d3bb2007-03-02 00:56:15 +0000102static void sil_dev_config(struct ata_device *dev);
Tejun Heo82ef04f2008-07-31 17:02:40 +0900103static int sil_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
104static int sil_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
Tejun Heo02607312007-08-06 18:36:23 +0900105static int sil_set_mode(struct ata_link *link, struct ata_device **r_failed);
Jiri Slaby95364f32019-10-31 10:59:45 +0100106static enum ata_completion_errors sil_qc_prep(struct ata_queued_cmd *qc);
Robert Hancockc7e324f2008-12-24 19:06:06 -0600107static void sil_bmdma_setup(struct ata_queued_cmd *qc);
108static void sil_bmdma_start(struct ata_queued_cmd *qc);
109static void sil_bmdma_stop(struct ata_queued_cmd *qc);
Tejun Heof6aae272006-05-15 20:58:27 +0900110static void sil_freeze(struct ata_port *ap);
111static void sil_thaw(struct ata_port *ap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Jeff Garzik374b1872005-08-30 05:42:52 -0400113
Jeff Garzik3b7d6972005-11-10 11:04:11 -0500114static const struct pci_device_id sil_pci_tbl[] = {
Jeff Garzik54bb3a942006-09-27 22:20:11 -0400115 { PCI_VDEVICE(CMD, 0x3112), sil_3112 },
116 { PCI_VDEVICE(CMD, 0x0240), sil_3112 },
117 { PCI_VDEVICE(CMD, 0x3512), sil_3512 },
118 { PCI_VDEVICE(CMD, 0x3114), sil_3114 },
119 { PCI_VDEVICE(ATI, 0x436e), sil_3112 },
120 { PCI_VDEVICE(ATI, 0x4379), sil_3112_no_sata_irq },
121 { PCI_VDEVICE(ATI, 0x437a), sil_3112_no_sata_irq },
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 { } /* terminate list */
124};
125
126
127/* TODO firmware versions should be added - eric */
128static const struct sil_drivelist {
Jeff Garzik5796d1c2007-10-26 00:03:37 -0400129 const char *product;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 unsigned int quirk;
131} sil_blacklist [] = {
132 { "ST320012AS", SIL_QUIRK_MOD15WRITE },
133 { "ST330013AS", SIL_QUIRK_MOD15WRITE },
134 { "ST340017AS", SIL_QUIRK_MOD15WRITE },
135 { "ST360015AS", SIL_QUIRK_MOD15WRITE },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 { "ST380023AS", SIL_QUIRK_MOD15WRITE },
137 { "ST3120023AS", SIL_QUIRK_MOD15WRITE },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 { "ST340014ASL", SIL_QUIRK_MOD15WRITE },
139 { "ST360014ASL", SIL_QUIRK_MOD15WRITE },
140 { "ST380011ASL", SIL_QUIRK_MOD15WRITE },
141 { "ST3120022ASL", SIL_QUIRK_MOD15WRITE },
142 { "ST3160021ASL", SIL_QUIRK_MOD15WRITE },
Tejun Heo9f9c47f2014-02-03 10:42:07 -0500143 { "TOSHIBA MK2561GSYN", SIL_QUIRK_MOD15WRITE },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 { "Maxtor 4D060H3", SIL_QUIRK_UDMA5MAX },
145 { }
146};
147
148static struct pci_driver sil_pci_driver = {
149 .name = DRV_NAME,
150 .id_table = sil_pci_tbl,
151 .probe = sil_init_one,
152 .remove = ata_pci_remove_one,
Bartlomiej Zolnierkiewicz58eb8cd2014-05-07 17:17:44 +0200153#ifdef CONFIG_PM_SLEEP
Tejun Heoafb5a7c2006-07-03 16:07:27 +0900154 .suspend = ata_pci_device_suspend,
155 .resume = sil_pci_device_resume,
Alexey Dobriyan281d4262006-08-14 22:49:30 -0700156#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157};
158
Jeff Garzik193515d2005-11-07 00:59:37 -0500159static struct scsi_host_template sil_sht = {
Robert Hancockc7e324f2008-12-24 19:06:06 -0600160 ATA_BASE_SHT(DRV_NAME),
161 /** These controllers support Large Block Transfer which allows
162 transfer chunks up to 2GB and which cross 64KB boundaries,
163 therefore the DMA limits are more relaxed than standard ATA SFF. */
164 .dma_boundary = SIL_DMA_BOUNDARY,
165 .sg_tablesize = ATA_MAX_PRD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166};
167
Tejun Heo029cfd62008-03-25 12:22:49 +0900168static struct ata_port_operations sil_ops = {
Robert Hancock31f80112009-04-13 22:57:28 -0600169 .inherits = &ata_bmdma32_port_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 .dev_config = sil_dev_config,
Alan Cox9d2c7c72007-03-08 23:09:12 +0000171 .set_mode = sil_set_mode,
Robert Hancockc7e324f2008-12-24 19:06:06 -0600172 .bmdma_setup = sil_bmdma_setup,
173 .bmdma_start = sil_bmdma_start,
174 .bmdma_stop = sil_bmdma_stop,
175 .qc_prep = sil_qc_prep,
Tejun Heof6aae272006-05-15 20:58:27 +0900176 .freeze = sil_freeze,
177 .thaw = sil_thaw,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 .scr_read = sil_scr_read,
179 .scr_write = sil_scr_write,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180};
181
Arjan van de Ven98ac62d2005-11-28 10:06:23 +0100182static const struct ata_port_info sil_port_info[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 /* sil_3112 */
184 {
Jeff Garzikcca39742006-08-24 03:19:22 -0400185 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE,
Erik Inge Bolsø14bdef92009-03-14 21:38:24 +0100186 .pio_mask = ATA_PIO4,
187 .mwdma_mask = ATA_MWDMA2,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400188 .udma_mask = ATA_UDMA5,
Tejun Heoe4deec62005-08-23 07:27:25 +0900189 .port_ops = &sil_ops,
Tejun Heo0ee304d2006-02-25 13:52:30 +0900190 },
Tejun Heo201ce852006-06-26 21:23:52 +0900191 /* sil_3112_no_sata_irq */
192 {
Jeff Garzikcca39742006-08-24 03:19:22 -0400193 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE |
Tejun Heo201ce852006-06-26 21:23:52 +0900194 SIL_FLAG_NO_SATA_IRQ,
Erik Inge Bolsø14bdef92009-03-14 21:38:24 +0100195 .pio_mask = ATA_PIO4,
196 .mwdma_mask = ATA_MWDMA2,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400197 .udma_mask = ATA_UDMA5,
Tejun Heo201ce852006-06-26 21:23:52 +0900198 .port_ops = &sil_ops,
199 },
Tejun Heo0ee304d2006-02-25 13:52:30 +0900200 /* sil_3512 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 {
Jeff Garzikcca39742006-08-24 03:19:22 -0400202 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT,
Erik Inge Bolsø14bdef92009-03-14 21:38:24 +0100203 .pio_mask = ATA_PIO4,
204 .mwdma_mask = ATA_MWDMA2,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400205 .udma_mask = ATA_UDMA5,
Tejun Heo0ee304d2006-02-25 13:52:30 +0900206 .port_ops = &sil_ops,
207 },
208 /* sil_3114 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 {
Jeff Garzikcca39742006-08-24 03:19:22 -0400210 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT,
Erik Inge Bolsø14bdef92009-03-14 21:38:24 +0100211 .pio_mask = ATA_PIO4,
212 .mwdma_mask = ATA_MWDMA2,
Jeff Garzikbf6263a2007-07-09 12:16:50 -0400213 .udma_mask = ATA_UDMA5,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .port_ops = &sil_ops,
215 },
216};
217
218/* per-port register offsets */
219/* TODO: we can probably calculate rather than use a table */
220static const struct {
221 unsigned long tf; /* ATA taskfile register block */
222 unsigned long ctl; /* ATA control/altstatus register block */
223 unsigned long bmdma; /* DMA register block */
Tejun Heo20888d82006-05-31 18:27:53 +0900224 unsigned long bmdma2; /* DMA register block #2 */
Tejun Heo48d4ef22006-03-05 16:03:52 +0900225 unsigned long fifo_cfg; /* FIFO Valid Byte Count and Control */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 unsigned long scr; /* SATA control register block */
227 unsigned long sien; /* SATA Interrupt Enable register */
228 unsigned long xfer_mode;/* data transfer mode register */
Tejun Heoe4e10e32006-02-25 13:52:30 +0900229 unsigned long sfis_cfg; /* SATA FIS reception config register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230} sil_port[] = {
231 /* port 0 ... */
Jeff Garzik5bcd7a002007-05-26 16:35:42 -0400232 /* tf ctl bmdma bmdma2 fifo scr sien mode sfis */
233 { 0x80, 0x8A, 0x0, 0x10, 0x40, 0x100, 0x148, 0xb4, 0x14c },
234 { 0xC0, 0xCA, 0x8, 0x18, 0x44, 0x180, 0x1c8, 0xf4, 0x1cc },
Tejun Heo20888d82006-05-31 18:27:53 +0900235 { 0x280, 0x28A, 0x200, 0x210, 0x240, 0x300, 0x348, 0x2b4, 0x34c },
236 { 0x2C0, 0x2CA, 0x208, 0x218, 0x244, 0x380, 0x3c8, 0x2f4, 0x3cc },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 /* ... port 3 */
238};
239
240MODULE_AUTHOR("Jeff Garzik");
241MODULE_DESCRIPTION("low-level driver for Silicon Image SATA controller");
242MODULE_LICENSE("GPL");
243MODULE_DEVICE_TABLE(pci, sil_pci_tbl);
244MODULE_VERSION(DRV_VERSION);
245
Jeff Garzik5796d1c2007-10-26 00:03:37 -0400246static int slow_down;
Jeff Garzik51e9f2f2006-01-27 16:50:27 -0500247module_param(slow_down, int, 0444);
248MODULE_PARM_DESC(slow_down, "Sledgehammer used to work around random problems, by limiting commands to 15 sectors (0=off, 1=on)");
249
Jeff Garzik374b1872005-08-30 05:42:52 -0400250
Robert Hancockc7e324f2008-12-24 19:06:06 -0600251static void sil_bmdma_stop(struct ata_queued_cmd *qc)
252{
253 struct ata_port *ap = qc->ap;
254 void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR];
255 void __iomem *bmdma2 = mmio_base + sil_port[ap->port_no].bmdma2;
256
257 /* clear start/stop bit - can safely always write 0 */
258 iowrite8(0, bmdma2);
259
260 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
261 ata_sff_dma_pause(ap);
262}
263
264static void sil_bmdma_setup(struct ata_queued_cmd *qc)
265{
266 struct ata_port *ap = qc->ap;
267 void __iomem *bmdma = ap->ioaddr.bmdma_addr;
268
269 /* load PRD table addr. */
Tejun Heof60d7012010-05-10 21:41:41 +0200270 iowrite32(ap->bmdma_prd_dma, bmdma + ATA_DMA_TABLE_OFS);
Robert Hancockc7e324f2008-12-24 19:06:06 -0600271
272 /* issue r/w command */
273 ap->ops->sff_exec_command(ap, &qc->tf);
274}
275
276static void sil_bmdma_start(struct ata_queued_cmd *qc)
277{
278 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
279 struct ata_port *ap = qc->ap;
280 void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR];
281 void __iomem *bmdma2 = mmio_base + sil_port[ap->port_no].bmdma2;
282 u8 dmactl = ATA_DMA_START;
283
284 /* set transfer direction, start host DMA transaction
285 Note: For Large Block Transfer to work, the DMA must be started
286 using the bmdma2 register. */
287 if (!rw)
288 dmactl |= ATA_DMA_WR;
289 iowrite8(dmactl, bmdma2);
290}
291
292/* The way God intended PCI IDE scatter/gather lists to look and behave... */
293static void sil_fill_sg(struct ata_queued_cmd *qc)
294{
295 struct scatterlist *sg;
296 struct ata_port *ap = qc->ap;
Tejun Heof60d7012010-05-10 21:41:41 +0200297 struct ata_bmdma_prd *prd, *last_prd = NULL;
Robert Hancockc7e324f2008-12-24 19:06:06 -0600298 unsigned int si;
299
Tejun Heof60d7012010-05-10 21:41:41 +0200300 prd = &ap->bmdma_prd[0];
Robert Hancockc7e324f2008-12-24 19:06:06 -0600301 for_each_sg(qc->sg, sg, qc->n_elem, si) {
302 /* Note h/w doesn't support 64-bit, so we unconditionally
303 * truncate dma_addr_t to u32.
304 */
305 u32 addr = (u32) sg_dma_address(sg);
306 u32 sg_len = sg_dma_len(sg);
307
308 prd->addr = cpu_to_le32(addr);
309 prd->flags_len = cpu_to_le32(sg_len);
Pasi Kärkkäinen41137aa2009-02-02 21:47:14 +0200310 VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", si, addr, sg_len);
Robert Hancockc7e324f2008-12-24 19:06:06 -0600311
312 last_prd = prd;
313 prd++;
314 }
315
316 if (likely(last_prd))
317 last_prd->flags_len |= cpu_to_le32(ATA_PRD_EOT);
318}
319
Jiri Slaby95364f32019-10-31 10:59:45 +0100320static enum ata_completion_errors sil_qc_prep(struct ata_queued_cmd *qc)
Robert Hancockc7e324f2008-12-24 19:06:06 -0600321{
322 if (!(qc->flags & ATA_QCFLAG_DMAMAP))
Jiri Slaby95364f32019-10-31 10:59:45 +0100323 return AC_ERR_OK;
Robert Hancockc7e324f2008-12-24 19:06:06 -0600324
325 sil_fill_sg(qc);
Jiri Slaby95364f32019-10-31 10:59:45 +0100326
327 return AC_ERR_OK;
Robert Hancockc7e324f2008-12-24 19:06:06 -0600328}
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330static unsigned char sil_get_device_cache_line(struct pci_dev *pdev)
331{
332 u8 cache_line = 0;
333 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache_line);
334 return cache_line;
335}
336
Alan Cox9d2c7c72007-03-08 23:09:12 +0000337/**
338 * sil_set_mode - wrap set_mode functions
Tejun Heo02607312007-08-06 18:36:23 +0900339 * @link: link to set up
Alan Cox9d2c7c72007-03-08 23:09:12 +0000340 * @r_failed: returned device when we fail
341 *
342 * Wrap the libata method for device setup as after the setup we need
343 * to inspect the results and do some configuration work
344 */
345
Tejun Heo02607312007-08-06 18:36:23 +0900346static int sil_set_mode(struct ata_link *link, struct ata_device **r_failed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Tejun Heo02607312007-08-06 18:36:23 +0900348 struct ata_port *ap = link->ap;
349 void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR];
Tejun Heo0d5ff562007-02-01 15:06:36 +0900350 void __iomem *addr = mmio_base + sil_port[ap->port_no].xfer_mode;
Tejun Heo02607312007-08-06 18:36:23 +0900351 struct ata_device *dev;
Tejun Heof58229f2007-08-06 18:36:23 +0900352 u32 tmp, dev_mode[2] = { };
Alan Cox9d2c7c72007-03-08 23:09:12 +0000353 int rc;
Jeff Garzika617c092007-05-21 20:14:23 -0400354
Tejun Heo02607312007-08-06 18:36:23 +0900355 rc = ata_do_set_mode(link, r_failed);
Alan Cox9d2c7c72007-03-08 23:09:12 +0000356 if (rc)
357 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Tejun Heo1eca4362008-11-03 20:03:17 +0900359 ata_for_each_dev(dev, link, ALL) {
Tejun Heoe1211e32006-04-01 01:38:18 +0900360 if (!ata_dev_enabled(dev))
Tejun Heof58229f2007-08-06 18:36:23 +0900361 dev_mode[dev->devno] = 0; /* PIO0/1/2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 else if (dev->flags & ATA_DFLAG_PIO)
Tejun Heof58229f2007-08-06 18:36:23 +0900363 dev_mode[dev->devno] = 1; /* PIO3/4 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 else
Tejun Heof58229f2007-08-06 18:36:23 +0900365 dev_mode[dev->devno] = 3; /* UDMA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 /* value 2 indicates MDMA */
367 }
368
369 tmp = readl(addr);
370 tmp &= ~((1<<5) | (1<<4) | (1<<1) | (1<<0));
371 tmp |= dev_mode[0];
372 tmp |= (dev_mode[1] << 4);
373 writel(tmp, addr);
374 readl(addr); /* flush */
Alan Cox9d2c7c72007-03-08 23:09:12 +0000375 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
Jeff Garzik5796d1c2007-10-26 00:03:37 -0400378static inline void __iomem *sil_scr_addr(struct ata_port *ap,
379 unsigned int sc_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
Tejun Heo0d5ff562007-02-01 15:06:36 +0900381 void __iomem *offset = ap->ioaddr.scr_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 switch (sc_reg) {
384 case SCR_STATUS:
385 return offset + 4;
386 case SCR_ERROR:
387 return offset + 8;
388 case SCR_CONTROL:
389 return offset;
390 default:
391 /* do nothing */
392 break;
393 }
394
Randy Dunlap8d9db2d2007-02-16 01:40:06 -0800395 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}
397
Tejun Heo82ef04f2008-07-31 17:02:40 +0900398static int sil_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Tejun Heo82ef04f2008-07-31 17:02:40 +0900400 void __iomem *mmio = sil_scr_addr(link->ap, sc_reg);
Tejun Heoda3dbb12007-07-16 14:29:40 +0900401
402 if (mmio) {
403 *val = readl(mmio);
404 return 0;
405 }
406 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
Tejun Heo82ef04f2008-07-31 17:02:40 +0900409static int sil_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Tejun Heo82ef04f2008-07-31 17:02:40 +0900411 void __iomem *mmio = sil_scr_addr(link->ap, sc_reg);
Tejun Heoda3dbb12007-07-16 14:29:40 +0900412
413 if (mmio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 writel(val, mmio);
Tejun Heoda3dbb12007-07-16 14:29:40 +0900415 return 0;
416 }
417 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
Tejun Heocbe88fb2006-05-31 18:27:55 +0900420static void sil_host_intr(struct ata_port *ap, u32 bmdma2)
421{
Tejun Heo9af5c9c2007-08-06 18:36:22 +0900422 struct ata_eh_info *ehi = &ap->link.eh_info;
423 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->link.active_tag);
Tejun Heocbe88fb2006-05-31 18:27:55 +0900424 u8 status;
425
Tejun Heoe5738902006-05-31 18:28:16 +0900426 if (unlikely(bmdma2 & SIL_DMA_SATA_IRQ)) {
Jeff Garzikebd16992011-08-18 23:52:36 -0400427 u32 serror = 0xffffffff;
Tejun Heod4c85322006-06-12 18:45:55 +0900428
429 /* SIEN doesn't mask SATA IRQs on some 3112s. Those
430 * controllers continue to assert IRQ as long as
431 * SError bits are pending. Clear SError immediately.
432 */
Tejun Heo82ef04f2008-07-31 17:02:40 +0900433 sil_scr_read(&ap->link, SCR_ERROR, &serror);
434 sil_scr_write(&ap->link, SCR_ERROR, serror);
Tejun Heod4c85322006-06-12 18:45:55 +0900435
Tejun Heo8cf32ac62007-12-08 08:45:27 +0900436 /* Sometimes spurious interrupts occur, double check
437 * it's PHYRDY CHG.
Tejun Heod4c85322006-06-12 18:45:55 +0900438 */
Tejun Heo8cf32ac62007-12-08 08:45:27 +0900439 if (serror & SERR_PHYRDY_CHG) {
Tejun Heof7fe7ad2007-12-08 08:47:01 +0900440 ap->link.eh_info.serror |= serror;
Tejun Heo8cf32ac62007-12-08 08:45:27 +0900441 goto freeze;
Tejun Heod4c85322006-06-12 18:45:55 +0900442 }
443
Tejun Heo8cf32ac62007-12-08 08:45:27 +0900444 if (!(bmdma2 & SIL_DMA_COMPLETE))
445 return;
Tejun Heoe5738902006-05-31 18:28:16 +0900446 }
447
Tejun Heo8cf32ac62007-12-08 08:45:27 +0900448 if (unlikely(!qc || (qc->tf.flags & ATA_TFLAG_POLLING))) {
Tejun Heoe2f8fb72007-02-24 22:30:36 +0900449 /* this sometimes happens, just clear IRQ */
Tejun Heo5682ed32008-04-07 22:47:16 +0900450 ap->ops->sff_check_status(ap);
Tejun Heoe2f8fb72007-02-24 22:30:36 +0900451 return;
452 }
453
Tejun Heocbe88fb2006-05-31 18:27:55 +0900454 /* Check whether we are expecting interrupt in this state */
455 switch (ap->hsm_task_state) {
456 case HSM_ST_FIRST:
457 /* Some pre-ATAPI-4 devices assert INTRQ
458 * at this state when ready to receive CDB.
459 */
460
461 /* Check the ATA_DFLAG_CDB_INTR flag is enough here.
Tejun Heo405e66b2007-11-27 19:28:53 +0900462 * The flag was turned on only for atapi devices. No
463 * need to check ata_is_atapi(qc->tf.protocol) again.
Tejun Heocbe88fb2006-05-31 18:27:55 +0900464 */
465 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
466 goto err_hsm;
467 break;
468 case HSM_ST_LAST:
Tejun Heo405e66b2007-11-27 19:28:53 +0900469 if (ata_is_dma(qc->tf.protocol)) {
Tejun Heocbe88fb2006-05-31 18:27:55 +0900470 /* clear DMA-Start bit */
471 ap->ops->bmdma_stop(qc);
472
473 if (bmdma2 & SIL_DMA_ERROR) {
474 qc->err_mask |= AC_ERR_HOST_BUS;
475 ap->hsm_task_state = HSM_ST_ERR;
476 }
477 }
478 break;
479 case HSM_ST:
480 break;
481 default:
482 goto err_hsm;
483 }
484
485 /* check main status, clearing INTRQ */
Tejun Heo5682ed32008-04-07 22:47:16 +0900486 status = ap->ops->sff_check_status(ap);
Tejun Heocbe88fb2006-05-31 18:27:55 +0900487 if (unlikely(status & ATA_BUSY))
488 goto err_hsm;
489
490 /* ack bmdma irq events */
Tejun Heo37f65b82010-05-19 22:10:20 +0200491 ata_bmdma_irq_clear(ap);
Tejun Heocbe88fb2006-05-31 18:27:55 +0900492
493 /* kick HSM in the ass */
Tejun Heo9363c382008-04-07 22:47:16 +0900494 ata_sff_hsm_move(ap, qc, status, 0);
Tejun Heocbe88fb2006-05-31 18:27:55 +0900495
Tejun Heo405e66b2007-11-27 19:28:53 +0900496 if (unlikely(qc->err_mask) && ata_is_dma(qc->tf.protocol))
Tejun Heoea547632006-11-17 12:06:21 +0900497 ata_ehi_push_desc(ehi, "BMDMA2 stat 0x%x", bmdma2);
498
Tejun Heocbe88fb2006-05-31 18:27:55 +0900499 return;
500
501 err_hsm:
502 qc->err_mask |= AC_ERR_HSM;
503 freeze:
504 ata_port_freeze(ap);
505}
506
David Howells7d12e782006-10-05 14:55:46 +0100507static irqreturn_t sil_interrupt(int irq, void *dev_instance)
Tejun Heocbe88fb2006-05-31 18:27:55 +0900508{
Jeff Garzikcca39742006-08-24 03:19:22 -0400509 struct ata_host *host = dev_instance;
Tejun Heo0d5ff562007-02-01 15:06:36 +0900510 void __iomem *mmio_base = host->iomap[SIL_MMIO_BAR];
Tejun Heocbe88fb2006-05-31 18:27:55 +0900511 int handled = 0;
512 int i;
513
Jeff Garzikcca39742006-08-24 03:19:22 -0400514 spin_lock(&host->lock);
Tejun Heocbe88fb2006-05-31 18:27:55 +0900515
Jeff Garzikcca39742006-08-24 03:19:22 -0400516 for (i = 0; i < host->n_ports; i++) {
517 struct ata_port *ap = host->ports[i];
Tejun Heocbe88fb2006-05-31 18:27:55 +0900518 u32 bmdma2 = readl(mmio_base + sil_port[ap->port_no].bmdma2);
519
Tejun Heo201ce852006-06-26 21:23:52 +0900520 /* turn off SATA_IRQ if not supported */
521 if (ap->flags & SIL_FLAG_NO_SATA_IRQ)
522 bmdma2 &= ~SIL_DMA_SATA_IRQ;
523
Tejun Heo23fa9612006-06-12 14:18:51 +0900524 if (bmdma2 == 0xffffffff ||
525 !(bmdma2 & (SIL_DMA_COMPLETE | SIL_DMA_SATA_IRQ)))
Tejun Heocbe88fb2006-05-31 18:27:55 +0900526 continue;
527
528 sil_host_intr(ap, bmdma2);
529 handled = 1;
530 }
531
Jeff Garzikcca39742006-08-24 03:19:22 -0400532 spin_unlock(&host->lock);
Tejun Heocbe88fb2006-05-31 18:27:55 +0900533
534 return IRQ_RETVAL(handled);
535}
536
Tejun Heof6aae272006-05-15 20:58:27 +0900537static void sil_freeze(struct ata_port *ap)
538{
Tejun Heo0d5ff562007-02-01 15:06:36 +0900539 void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR];
Tejun Heof6aae272006-05-15 20:58:27 +0900540 u32 tmp;
541
Tejun Heoe5738902006-05-31 18:28:16 +0900542 /* global IRQ mask doesn't block SATA IRQ, turn off explicitly */
543 writel(0, mmio_base + sil_port[ap->port_no].sien);
544
Tejun Heof6aae272006-05-15 20:58:27 +0900545 /* plug IRQ */
546 tmp = readl(mmio_base + SIL_SYSCFG);
547 tmp |= SIL_MASK_IDE0_INT << ap->port_no;
548 writel(tmp, mmio_base + SIL_SYSCFG);
549 readl(mmio_base + SIL_SYSCFG); /* flush */
Jeff Garzik2fc37ad2009-04-07 19:18:32 -0400550
551 /* Ensure DMA_ENABLE is off.
552 *
553 * This is because the controller will not give us access to the
554 * taskfile registers while a DMA is in progress
555 */
556 iowrite8(ioread8(ap->ioaddr.bmdma_addr) & ~SIL_DMA_ENABLE,
557 ap->ioaddr.bmdma_addr);
558
559 /* According to ata_bmdma_stop, an HDMA transition requires
560 * on PIO cycle. But we can't read a taskfile register.
561 */
562 ioread8(ap->ioaddr.bmdma_addr);
Tejun Heof6aae272006-05-15 20:58:27 +0900563}
564
565static void sil_thaw(struct ata_port *ap)
566{
Tejun Heo0d5ff562007-02-01 15:06:36 +0900567 void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR];
Tejun Heof6aae272006-05-15 20:58:27 +0900568 u32 tmp;
569
570 /* clear IRQ */
Tejun Heo5682ed32008-04-07 22:47:16 +0900571 ap->ops->sff_check_status(ap);
Tejun Heo37f65b82010-05-19 22:10:20 +0200572 ata_bmdma_irq_clear(ap);
Tejun Heof6aae272006-05-15 20:58:27 +0900573
Tejun Heo201ce852006-06-26 21:23:52 +0900574 /* turn on SATA IRQ if supported */
575 if (!(ap->flags & SIL_FLAG_NO_SATA_IRQ))
576 writel(SIL_SIEN_N, mmio_base + sil_port[ap->port_no].sien);
Tejun Heoe5738902006-05-31 18:28:16 +0900577
Tejun Heof6aae272006-05-15 20:58:27 +0900578 /* turn on IRQ */
579 tmp = readl(mmio_base + SIL_SYSCFG);
580 tmp &= ~(SIL_MASK_IDE0_INT << ap->port_no);
581 writel(tmp, mmio_base + SIL_SYSCFG);
582}
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584/**
585 * sil_dev_config - Apply device/host-specific errata fixups
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 * @dev: Device to be examined
587 *
588 * After the IDENTIFY [PACKET] DEVICE step is complete, and a
589 * device is known to be present, this function is called.
590 * We apply two errata fixups which are specific to Silicon Image,
591 * a Seagate and a Maxtor fixup.
592 *
593 * For certain Seagate devices, we must limit the maximum sectors
594 * to under 8K.
595 *
596 * For certain Maxtor devices, we must not program the drive
597 * beyond udma5.
598 *
599 * Both fixups are unfairly pessimistic. As soon as I get more
600 * information on these errata, I will create a more exhaustive
601 * list, and apply the fixups to only the specific
602 * devices/hosts/firmwares that need it.
603 *
604 * 20040111 - Seagate drives affected by the Mod15Write bug are blacklisted
605 * The Maxtor quirk is in the blacklist, but I'm keeping the original
606 * pessimistic fix for the following reasons...
607 * - There seems to be less info on it, only one device gleaned off the
608 * Windows driver, maybe only one is affected. More info would be greatly
609 * appreciated.
610 * - But then again UDMA5 is hardly anything to complain about
611 */
Alancd0d3bb2007-03-02 00:56:15 +0000612static void sil_dev_config(struct ata_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Tejun Heo9af5c9c2007-08-06 18:36:22 +0900614 struct ata_port *ap = dev->link->ap;
615 int print_info = ap->link.eh_context.i.flags & ATA_EHI_PRINTINFO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 unsigned int n, quirks = 0;
Tejun Heoa0cf7332007-01-02 20:18:49 +0900617 unsigned char model_num[ATA_ID_PROD_LEN + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Mikulas Patockad98f1cd2015-11-26 12:00:59 -0500619 /* This controller doesn't support trim */
620 dev->horkage |= ATA_HORKAGE_NOTRIM;
621
Tejun Heoa0cf7332007-01-02 20:18:49 +0900622 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Jeff Garzik8a60a072005-07-31 13:13:24 -0400624 for (n = 0; sil_blacklist[n].product; n++)
Tejun Heo2e026712006-02-12 22:47:04 +0900625 if (!strcmp(sil_blacklist[n].product, model_num)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 quirks = sil_blacklist[n].quirk;
627 break;
628 }
Jeff Garzik8a60a072005-07-31 13:13:24 -0400629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 /* limit requests to 15 sectors */
Jeff Garzik51e9f2f2006-01-27 16:50:27 -0500631 if (slow_down ||
632 ((ap->flags & SIL_FLAG_MOD15WRITE) &&
633 (quirks & SIL_QUIRK_MOD15WRITE))) {
Tejun Heoefdaedc2006-11-01 18:38:52 +0900634 if (print_info)
Joe Perchesa9a79df2011-04-15 15:51:59 -0700635 ata_dev_info(dev,
636 "applying Seagate errata fix (mod15write workaround)\n");
Tejun Heob00eec12006-02-12 23:32:59 +0900637 dev->max_sectors = 15;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 return;
639 }
640
641 /* limit to udma5 */
642 if (quirks & SIL_QUIRK_UDMA5MAX) {
Tejun Heoefdaedc2006-11-01 18:38:52 +0900643 if (print_info)
Joe Perchesa9a79df2011-04-15 15:51:59 -0700644 ata_dev_info(dev, "applying Maxtor errata fix %s\n",
645 model_num);
Tejun Heo5a529132006-03-24 14:07:50 +0900646 dev->udma_mask &= ATA_UDMA5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 return;
648 }
649}
650
Tejun Heo4447d352007-04-17 23:44:08 +0900651static void sil_init_controller(struct ata_host *host)
Tejun Heo3d8ec912006-07-03 16:07:27 +0900652{
Tejun Heo4447d352007-04-17 23:44:08 +0900653 struct pci_dev *pdev = to_pci_dev(host->dev);
654 void __iomem *mmio_base = host->iomap[SIL_MMIO_BAR];
Tejun Heo3d8ec912006-07-03 16:07:27 +0900655 u8 cls;
656 u32 tmp;
657 int i;
658
659 /* Initialize FIFO PCI bus arbitration */
660 cls = sil_get_device_cache_line(pdev);
661 if (cls) {
662 cls >>= 3;
663 cls++; /* cls = (line_size/8)+1 */
Tejun Heo4447d352007-04-17 23:44:08 +0900664 for (i = 0; i < host->n_ports; i++)
Tejun Heo3d8ec912006-07-03 16:07:27 +0900665 writew(cls << 8 | cls,
666 mmio_base + sil_port[i].fifo_cfg);
667 } else
Joe Perchesa44fec12011-04-15 15:51:58 -0700668 dev_warn(&pdev->dev,
669 "cache line size not set. Driver may not function\n");
Tejun Heo3d8ec912006-07-03 16:07:27 +0900670
671 /* Apply R_ERR on DMA activate FIS errata workaround */
Tejun Heo4447d352007-04-17 23:44:08 +0900672 if (host->ports[0]->flags & SIL_FLAG_RERR_ON_DMA_ACT) {
Tejun Heo3d8ec912006-07-03 16:07:27 +0900673 int cnt;
674
Tejun Heo4447d352007-04-17 23:44:08 +0900675 for (i = 0, cnt = 0; i < host->n_ports; i++) {
Tejun Heo3d8ec912006-07-03 16:07:27 +0900676 tmp = readl(mmio_base + sil_port[i].sfis_cfg);
677 if ((tmp & 0x3) != 0x01)
678 continue;
679 if (!cnt)
Joe Perchesa44fec12011-04-15 15:51:58 -0700680 dev_info(&pdev->dev,
681 "Applying R_ERR on DMA activate FIS errata fix\n");
Tejun Heo3d8ec912006-07-03 16:07:27 +0900682 writel(tmp & ~0x3, mmio_base + sil_port[i].sfis_cfg);
683 cnt++;
684 }
685 }
686
Tejun Heo4447d352007-04-17 23:44:08 +0900687 if (host->n_ports == 4) {
Tejun Heo3d8ec912006-07-03 16:07:27 +0900688 /* flip the magic "make 4 ports work" bit */
689 tmp = readl(mmio_base + sil_port[2].bmdma);
690 if ((tmp & SIL_INTR_STEERING) == 0)
691 writel(tmp | SIL_INTR_STEERING,
692 mmio_base + sil_port[2].bmdma);
693 }
694}
695
Rafael J. Wysockie57db7b2009-01-19 20:58:29 +0100696static bool sil_broken_system_poweroff(struct pci_dev *pdev)
697{
698 static const struct dmi_system_id broken_systems[] = {
699 {
700 .ident = "HP Compaq nx6325",
701 .matches = {
702 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
703 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
704 },
705 /* PCI slot number of the controller */
706 .driver_data = (void *)0x12UL,
707 },
708
709 { } /* terminate list */
710 };
711 const struct dmi_system_id *dmi = dmi_first_match(broken_systems);
712
713 if (dmi) {
714 unsigned long slot = (unsigned long)dmi->driver_data;
715 /* apply the quirk only to on-board controllers */
716 return slot == PCI_SLOT(pdev->devfn);
717 }
718
719 return false;
720}
721
Jeff Garzik5796d1c2007-10-26 00:03:37 -0400722static int sil_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Tejun Heo4447d352007-04-17 23:44:08 +0900724 int board_id = ent->driver_data;
Rafael J. Wysockie57db7b2009-01-19 20:58:29 +0100725 struct ata_port_info pi = sil_port_info[board_id];
726 const struct ata_port_info *ppi[] = { &pi, NULL };
Tejun Heo4447d352007-04-17 23:44:08 +0900727 struct ata_host *host;
Jeff Garzikea6ba102005-08-30 05:18:18 -0400728 void __iomem *mmio_base;
Tejun Heo4447d352007-04-17 23:44:08 +0900729 int n_ports, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Joe Perches06296a12011-04-15 15:52:00 -0700732 ata_print_version_once(&pdev->dev, DRV_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Tejun Heo4447d352007-04-17 23:44:08 +0900734 /* allocate host */
735 n_ports = 2;
736 if (board_id == sil_3114)
737 n_ports = 4;
738
Rafael J. Wysockie57db7b2009-01-19 20:58:29 +0100739 if (sil_broken_system_poweroff(pdev)) {
740 pi.flags |= ATA_FLAG_NO_POWEROFF_SPINDOWN |
741 ATA_FLAG_NO_HIBERNATE_SPINDOWN;
742 dev_info(&pdev->dev, "quirky BIOS, skipping spindown "
743 "on poweroff and hibernation\n");
744 }
745
Tejun Heo4447d352007-04-17 23:44:08 +0900746 host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
747 if (!host)
748 return -ENOMEM;
749
750 /* acquire resources and fill host */
Tejun Heo24dc5f32007-01-20 16:00:28 +0900751 rc = pcim_enable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 if (rc)
753 return rc;
754
Tejun Heo0d5ff562007-02-01 15:06:36 +0900755 rc = pcim_iomap_regions(pdev, 1 << SIL_MMIO_BAR, DRV_NAME);
756 if (rc == -EBUSY)
Tejun Heo24dc5f32007-01-20 16:00:28 +0900757 pcim_pin_device(pdev);
Tejun Heo0d5ff562007-02-01 15:06:36 +0900758 if (rc)
Tejun Heo24dc5f32007-01-20 16:00:28 +0900759 return rc;
Tejun Heo4447d352007-04-17 23:44:08 +0900760 host->iomap = pcim_iomap_table(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Christoph Hellwigb5e55552019-08-26 12:57:25 +0200762 rc = dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 if (rc)
Tejun Heo24dc5f32007-01-20 16:00:28 +0900764 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Tejun Heo4447d352007-04-17 23:44:08 +0900766 mmio_base = host->iomap[SIL_MMIO_BAR];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Tejun Heo4447d352007-04-17 23:44:08 +0900768 for (i = 0; i < host->n_ports; i++) {
Tejun Heocbcdd872007-08-18 13:14:55 +0900769 struct ata_port *ap = host->ports[i];
770 struct ata_ioports *ioaddr = &ap->ioaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Tejun Heo4447d352007-04-17 23:44:08 +0900772 ioaddr->cmd_addr = mmio_base + sil_port[i].tf;
773 ioaddr->altstatus_addr =
774 ioaddr->ctl_addr = mmio_base + sil_port[i].ctl;
775 ioaddr->bmdma_addr = mmio_base + sil_port[i].bmdma;
776 ioaddr->scr_addr = mmio_base + sil_port[i].scr;
Tejun Heo9363c382008-04-07 22:47:16 +0900777 ata_sff_std_ports(ioaddr);
Tejun Heocbcdd872007-08-18 13:14:55 +0900778
779 ata_port_pbar_desc(ap, SIL_MMIO_BAR, -1, "mmio");
780 ata_port_pbar_desc(ap, SIL_MMIO_BAR, sil_port[i].tf, "tf");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 }
782
Tejun Heo4447d352007-04-17 23:44:08 +0900783 /* initialize and activate */
784 sil_init_controller(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 pci_set_master(pdev);
Tejun Heo4447d352007-04-17 23:44:08 +0900787 return ata_host_activate(host, pdev->irq, sil_interrupt, IRQF_SHARED,
788 &sil_sht);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789}
790
Bartlomiej Zolnierkiewicz58eb8cd2014-05-07 17:17:44 +0200791#ifdef CONFIG_PM_SLEEP
Tejun Heoafb5a7c2006-07-03 16:07:27 +0900792static int sil_pci_device_resume(struct pci_dev *pdev)
793{
Jingoo Han0a86e1c2013-06-03 14:05:36 +0900794 struct ata_host *host = pci_get_drvdata(pdev);
Tejun Heo553c4aa2006-12-26 19:39:50 +0900795 int rc;
Tejun Heoafb5a7c2006-07-03 16:07:27 +0900796
Tejun Heo553c4aa2006-12-26 19:39:50 +0900797 rc = ata_pci_device_do_resume(pdev);
798 if (rc)
799 return rc;
800
Tejun Heo4447d352007-04-17 23:44:08 +0900801 sil_init_controller(host);
Jeff Garzikcca39742006-08-24 03:19:22 -0400802 ata_host_resume(host);
Tejun Heoafb5a7c2006-07-03 16:07:27 +0900803
804 return 0;
805}
Alexey Dobriyan281d4262006-08-14 22:49:30 -0700806#endif
Tejun Heoafb5a7c2006-07-03 16:07:27 +0900807
Axel Lin2fc75da2012-04-19 13:43:05 +0800808module_pci_driver(sil_pci_driver);