aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sata_sil24.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/sata_sil24.c')
-rw-r--r--drivers/scsi/sata_sil24.c646
1 files changed, 395 insertions, 251 deletions
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c
index cb9082fd7e2f..c8b477c67247 100644
--- a/drivers/scsi/sata_sil24.c
+++ b/drivers/scsi/sata_sil24.c
@@ -31,15 +31,15 @@
31#include <asm/io.h> 31#include <asm/io.h>
32 32
33#define DRV_NAME "sata_sil24" 33#define DRV_NAME "sata_sil24"
34#define DRV_VERSION "0.23" 34#define DRV_VERSION "0.24"
35 35
36/* 36/*
37 * Port request block (PRB) 32 bytes 37 * Port request block (PRB) 32 bytes
38 */ 38 */
39struct sil24_prb { 39struct sil24_prb {
40 u16 ctrl; 40 __le16 ctrl;
41 u16 prot; 41 __le16 prot;
42 u32 rx_cnt; 42 __le32 rx_cnt;
43 u8 fis[6 * 4]; 43 u8 fis[6 * 4];
44}; 44};
45 45
@@ -47,17 +47,17 @@ struct sil24_prb {
47 * Scatter gather entry (SGE) 16 bytes 47 * Scatter gather entry (SGE) 16 bytes
48 */ 48 */
49struct sil24_sge { 49struct sil24_sge {
50 u64 addr; 50 __le64 addr;
51 u32 cnt; 51 __le32 cnt;
52 u32 flags; 52 __le32 flags;
53}; 53};
54 54
55/* 55/*
56 * Port multiplier 56 * Port multiplier
57 */ 57 */
58struct sil24_port_multiplier { 58struct sil24_port_multiplier {
59 u32 diag; 59 __le32 diag;
60 u32 sactive; 60 __le32 sactive;
61}; 61};
62 62
63enum { 63enum {
@@ -86,12 +86,21 @@ enum {
86 /* HOST_SLOT_STAT bits */ 86 /* HOST_SLOT_STAT bits */
87 HOST_SSTAT_ATTN = (1 << 31), 87 HOST_SSTAT_ATTN = (1 << 31),
88 88
89 /* HOST_CTRL bits */
90 HOST_CTRL_M66EN = (1 << 16), /* M66EN PCI bus signal */
91 HOST_CTRL_TRDY = (1 << 17), /* latched PCI TRDY */
92 HOST_CTRL_STOP = (1 << 18), /* latched PCI STOP */
93 HOST_CTRL_DEVSEL = (1 << 19), /* latched PCI DEVSEL */
94 HOST_CTRL_REQ64 = (1 << 20), /* latched PCI REQ64 */
95
89 /* 96 /*
90 * Port registers 97 * Port registers
91 * (8192 bytes @ +0x0000, +0x2000, +0x4000 and +0x6000 @ BAR2) 98 * (8192 bytes @ +0x0000, +0x2000, +0x4000 and +0x6000 @ BAR2)
92 */ 99 */
93 PORT_REGS_SIZE = 0x2000, 100 PORT_REGS_SIZE = 0x2000,
94 PORT_PRB = 0x0000, /* (32 bytes PRB + 16 bytes SGEs * 6) * 31 (3968 bytes) */ 101
102 PORT_LRAM = 0x0000, /* 31 LRAM slots and PM regs */
103 PORT_LRAM_SLOT_SZ = 0x0080, /* 32 bytes PRB + 2 SGE, ACT... */
95 104
96 PORT_PM = 0x0f80, /* 8 bytes PM * 16 (128 bytes) */ 105 PORT_PM = 0x0f80, /* 8 bytes PM * 16 (128 bytes) */
97 /* 32 bit regs */ 106 /* 32 bit regs */
@@ -142,8 +151,16 @@ enum {
142 PORT_IRQ_PWR_CHG = (1 << 3), /* power management change */ 151 PORT_IRQ_PWR_CHG = (1 << 3), /* power management change */
143 PORT_IRQ_PHYRDY_CHG = (1 << 4), /* PHY ready change */ 152 PORT_IRQ_PHYRDY_CHG = (1 << 4), /* PHY ready change */
144 PORT_IRQ_COMWAKE = (1 << 5), /* COMWAKE received */ 153 PORT_IRQ_COMWAKE = (1 << 5), /* COMWAKE received */
145 PORT_IRQ_UNK_FIS = (1 << 6), /* Unknown FIS received */ 154 PORT_IRQ_UNK_FIS = (1 << 6), /* unknown FIS received */
146 PORT_IRQ_SDB_FIS = (1 << 11), /* SDB FIS received */ 155 PORT_IRQ_DEV_XCHG = (1 << 7), /* device exchanged */
156 PORT_IRQ_8B10B = (1 << 8), /* 8b/10b decode error threshold */
157 PORT_IRQ_CRC = (1 << 9), /* CRC error threshold */
158 PORT_IRQ_HANDSHAKE = (1 << 10), /* handshake error threshold */
159 PORT_IRQ_SDB_NOTIFY = (1 << 11), /* SDB notify received */
160
161 DEF_PORT_IRQ = PORT_IRQ_COMPLETE | PORT_IRQ_ERROR |
162 PORT_IRQ_PHYRDY_CHG | PORT_IRQ_DEV_XCHG |
163 PORT_IRQ_UNK_FIS,
147 164
148 /* bits[27:16] are unmasked (raw) */ 165 /* bits[27:16] are unmasked (raw) */
149 PORT_IRQ_RAW_SHIFT = 16, 166 PORT_IRQ_RAW_SHIFT = 16,
@@ -174,7 +191,7 @@ enum {
174 PORT_CERR_CMD_PCIPERR = 27, /* ctrl[15:13] 110 - PCI parity err while fetching PRB */ 191 PORT_CERR_CMD_PCIPERR = 27, /* ctrl[15:13] 110 - PCI parity err while fetching PRB */
175 PORT_CERR_XFR_UNDEF = 32, /* PSD ecode 00 - undefined */ 192 PORT_CERR_XFR_UNDEF = 32, /* PSD ecode 00 - undefined */
176 PORT_CERR_XFR_TGTABRT = 33, /* PSD ecode 01 - target abort */ 193 PORT_CERR_XFR_TGTABRT = 33, /* PSD ecode 01 - target abort */
177 PORT_CERR_XFR_MSGABRT = 34, /* PSD ecode 10 - master abort */ 194 PORT_CERR_XFR_MSTABRT = 34, /* PSD ecode 10 - master abort */
178 PORT_CERR_XFR_PCIPERR = 35, /* PSD ecode 11 - PCI prity err during transfer */ 195 PORT_CERR_XFR_PCIPERR = 35, /* PSD ecode 11 - PCI prity err during transfer */
179 PORT_CERR_SENDSERVICE = 36, /* FIS received while sending service */ 196 PORT_CERR_SENDSERVICE = 36, /* FIS received while sending service */
180 197
@@ -202,11 +219,19 @@ enum {
202 SGE_DRD = (1 << 29), /* discard data read (/dev/null) 219 SGE_DRD = (1 << 29), /* discard data read (/dev/null)
203 data address ignored */ 220 data address ignored */
204 221
222 SIL24_MAX_CMDS = 31,
223
205 /* board id */ 224 /* board id */
206 BID_SIL3124 = 0, 225 BID_SIL3124 = 0,
207 BID_SIL3132 = 1, 226 BID_SIL3132 = 1,
208 BID_SIL3131 = 2, 227 BID_SIL3131 = 2,
209 228
229 /* host flags */
230 SIL24_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
231 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
232 ATA_FLAG_NCQ | ATA_FLAG_SKIP_D2H_BSY,
233 SIL24_FLAG_PCIX_IRQ_WOC = (1 << 24), /* IRQ loss errata on PCI-X */
234
210 IRQ_STAT_4PORTS = 0xf, 235 IRQ_STAT_4PORTS = 0xf,
211}; 236};
212 237
@@ -226,6 +251,58 @@ union sil24_cmd_block {
226 struct sil24_atapi_block atapi; 251 struct sil24_atapi_block atapi;
227}; 252};
228 253
254static struct sil24_cerr_info {
255 unsigned int err_mask, action;
256 const char *desc;
257} sil24_cerr_db[] = {
258 [0] = { AC_ERR_DEV, ATA_EH_REVALIDATE,
259 "device error" },
260 [PORT_CERR_DEV] = { AC_ERR_DEV, ATA_EH_REVALIDATE,
261 "device error via D2H FIS" },
262 [PORT_CERR_SDB] = { AC_ERR_DEV, ATA_EH_REVALIDATE,
263 "device error via SDB FIS" },
264 [PORT_CERR_DATA] = { AC_ERR_ATA_BUS, ATA_EH_SOFTRESET,
265 "error in data FIS" },
266 [PORT_CERR_SEND] = { AC_ERR_ATA_BUS, ATA_EH_SOFTRESET,
267 "failed to transmit command FIS" },
268 [PORT_CERR_INCONSISTENT] = { AC_ERR_HSM, ATA_EH_SOFTRESET,
269 "protocol mismatch" },
270 [PORT_CERR_DIRECTION] = { AC_ERR_HSM, ATA_EH_SOFTRESET,
271 "data directon mismatch" },
272 [PORT_CERR_UNDERRUN] = { AC_ERR_HSM, ATA_EH_SOFTRESET,
273 "ran out of SGEs while writing" },
274 [PORT_CERR_OVERRUN] = { AC_ERR_HSM, ATA_EH_SOFTRESET,
275 "ran out of SGEs while reading" },
276 [PORT_CERR_PKT_PROT] = { AC_ERR_HSM, ATA_EH_SOFTRESET,
277 "invalid data directon for ATAPI CDB" },
278 [PORT_CERR_SGT_BOUNDARY] = { AC_ERR_SYSTEM, ATA_EH_SOFTRESET,
279 "SGT no on qword boundary" },
280 [PORT_CERR_SGT_TGTABRT] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
281 "PCI target abort while fetching SGT" },
282 [PORT_CERR_SGT_MSTABRT] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
283 "PCI master abort while fetching SGT" },
284 [PORT_CERR_SGT_PCIPERR] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
285 "PCI parity error while fetching SGT" },
286 [PORT_CERR_CMD_BOUNDARY] = { AC_ERR_SYSTEM, ATA_EH_SOFTRESET,
287 "PRB not on qword boundary" },
288 [PORT_CERR_CMD_TGTABRT] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
289 "PCI target abort while fetching PRB" },
290 [PORT_CERR_CMD_MSTABRT] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
291 "PCI master abort while fetching PRB" },
292 [PORT_CERR_CMD_PCIPERR] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
293 "PCI parity error while fetching PRB" },
294 [PORT_CERR_XFR_UNDEF] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
295 "undefined error while transferring data" },
296 [PORT_CERR_XFR_TGTABRT] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
297 "PCI target abort while transferring data" },
298 [PORT_CERR_XFR_MSTABRT] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
299 "PCI master abort while transferring data" },
300 [PORT_CERR_XFR_PCIPERR] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
301 "PCI parity error while transferring data" },
302 [PORT_CERR_SENDSERVICE] = { AC_ERR_HSM, ATA_EH_SOFTRESET,
303 "FIS received while sending service FIS" },
304};
305
229/* 306/*
230 * ap->private_data 307 * ap->private_data
231 * 308 *
@@ -249,12 +326,14 @@ static u8 sil24_check_status(struct ata_port *ap);
249static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg); 326static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg);
250static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val); 327static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val);
251static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf); 328static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
252static int sil24_probe_reset(struct ata_port *ap, unsigned int *classes);
253static void sil24_qc_prep(struct ata_queued_cmd *qc); 329static void sil24_qc_prep(struct ata_queued_cmd *qc);
254static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc); 330static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc);
255static void sil24_irq_clear(struct ata_port *ap); 331static void sil24_irq_clear(struct ata_port *ap);
256static void sil24_eng_timeout(struct ata_port *ap);
257static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs); 332static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
333static void sil24_freeze(struct ata_port *ap);
334static void sil24_thaw(struct ata_port *ap);
335static void sil24_error_handler(struct ata_port *ap);
336static void sil24_post_internal_cmd(struct ata_queued_cmd *qc);
258static int sil24_port_start(struct ata_port *ap); 337static int sil24_port_start(struct ata_port *ap);
259static void sil24_port_stop(struct ata_port *ap); 338static void sil24_port_stop(struct ata_port *ap);
260static void sil24_host_stop(struct ata_host_set *host_set); 339static void sil24_host_stop(struct ata_host_set *host_set);
@@ -281,7 +360,8 @@ static struct scsi_host_template sil24_sht = {
281 .name = DRV_NAME, 360 .name = DRV_NAME,
282 .ioctl = ata_scsi_ioctl, 361 .ioctl = ata_scsi_ioctl,
283 .queuecommand = ata_scsi_queuecmd, 362 .queuecommand = ata_scsi_queuecmd,
284 .can_queue = ATA_DEF_QUEUE, 363 .change_queue_depth = ata_scsi_change_queue_depth,
364 .can_queue = SIL24_MAX_CMDS,
285 .this_id = ATA_SHT_THIS_ID, 365 .this_id = ATA_SHT_THIS_ID,
286 .sg_tablesize = LIBATA_MAX_PRD, 366 .sg_tablesize = LIBATA_MAX_PRD,
287 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 367 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
@@ -290,6 +370,7 @@ static struct scsi_host_template sil24_sht = {
290 .proc_name = DRV_NAME, 370 .proc_name = DRV_NAME,
291 .dma_boundary = ATA_DMA_BOUNDARY, 371 .dma_boundary = ATA_DMA_BOUNDARY,
292 .slave_configure = ata_scsi_slave_config, 372 .slave_configure = ata_scsi_slave_config,
373 .slave_destroy = ata_scsi_slave_destroy,
293 .bios_param = ata_std_bios_param, 374 .bios_param = ata_std_bios_param,
294}; 375};
295 376
@@ -304,19 +385,20 @@ static const struct ata_port_operations sil24_ops = {
304 385
305 .tf_read = sil24_tf_read, 386 .tf_read = sil24_tf_read,
306 387
307 .probe_reset = sil24_probe_reset,
308
309 .qc_prep = sil24_qc_prep, 388 .qc_prep = sil24_qc_prep,
310 .qc_issue = sil24_qc_issue, 389 .qc_issue = sil24_qc_issue,
311 390
312 .eng_timeout = sil24_eng_timeout,
313
314 .irq_handler = sil24_interrupt, 391 .irq_handler = sil24_interrupt,
315 .irq_clear = sil24_irq_clear, 392 .irq_clear = sil24_irq_clear,
316 393
317 .scr_read = sil24_scr_read, 394 .scr_read = sil24_scr_read,
318 .scr_write = sil24_scr_write, 395 .scr_write = sil24_scr_write,
319 396
397 .freeze = sil24_freeze,
398 .thaw = sil24_thaw,
399 .error_handler = sil24_error_handler,
400 .post_internal_cmd = sil24_post_internal_cmd,
401
320 .port_start = sil24_port_start, 402 .port_start = sil24_port_start,
321 .port_stop = sil24_port_stop, 403 .port_stop = sil24_port_stop,
322 .host_stop = sil24_host_stop, 404 .host_stop = sil24_host_stop,
@@ -333,9 +415,8 @@ static struct ata_port_info sil24_port_info[] = {
333 /* sil_3124 */ 415 /* sil_3124 */
334 { 416 {
335 .sht = &sil24_sht, 417 .sht = &sil24_sht,
336 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 418 .host_flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(4) |
337 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | 419 SIL24_FLAG_PCIX_IRQ_WOC,
338 SIL24_NPORTS2FLAG(4),
339 .pio_mask = 0x1f, /* pio0-4 */ 420 .pio_mask = 0x1f, /* pio0-4 */
340 .mwdma_mask = 0x07, /* mwdma0-2 */ 421 .mwdma_mask = 0x07, /* mwdma0-2 */
341 .udma_mask = 0x3f, /* udma0-5 */ 422 .udma_mask = 0x3f, /* udma0-5 */
@@ -344,9 +425,7 @@ static struct ata_port_info sil24_port_info[] = {
344 /* sil_3132 */ 425 /* sil_3132 */
345 { 426 {
346 .sht = &sil24_sht, 427 .sht = &sil24_sht,
347 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 428 .host_flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(2),
348 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
349 SIL24_NPORTS2FLAG(2),
350 .pio_mask = 0x1f, /* pio0-4 */ 429 .pio_mask = 0x1f, /* pio0-4 */
351 .mwdma_mask = 0x07, /* mwdma0-2 */ 430 .mwdma_mask = 0x07, /* mwdma0-2 */
352 .udma_mask = 0x3f, /* udma0-5 */ 431 .udma_mask = 0x3f, /* udma0-5 */
@@ -355,9 +434,7 @@ static struct ata_port_info sil24_port_info[] = {
355 /* sil_3131/sil_3531 */ 434 /* sil_3131/sil_3531 */
356 { 435 {
357 .sht = &sil24_sht, 436 .sht = &sil24_sht,
358 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 437 .host_flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(1),
359 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
360 SIL24_NPORTS2FLAG(1),
361 .pio_mask = 0x1f, /* pio0-4 */ 438 .pio_mask = 0x1f, /* pio0-4 */
362 .mwdma_mask = 0x07, /* mwdma0-2 */ 439 .mwdma_mask = 0x07, /* mwdma0-2 */
363 .udma_mask = 0x3f, /* udma0-5 */ 440 .udma_mask = 0x3f, /* udma0-5 */
@@ -365,6 +442,13 @@ static struct ata_port_info sil24_port_info[] = {
365 }, 442 },
366}; 443};
367 444
445static int sil24_tag(int tag)
446{
447 if (unlikely(ata_tag_internal(tag)))
448 return 0;
449 return tag;
450}
451
368static void sil24_dev_config(struct ata_port *ap, struct ata_device *dev) 452static void sil24_dev_config(struct ata_port *ap, struct ata_device *dev)
369{ 453{
370 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 454 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
@@ -426,56 +510,65 @@ static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
426 *tf = pp->tf; 510 *tf = pp->tf;
427} 511}
428 512
429static int sil24_softreset(struct ata_port *ap, int verbose, 513static int sil24_init_port(struct ata_port *ap)
430 unsigned int *class) 514{
515 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
516 u32 tmp;
517
518 writel(PORT_CS_INIT, port + PORT_CTRL_STAT);
519 ata_wait_register(port + PORT_CTRL_STAT,
520 PORT_CS_INIT, PORT_CS_INIT, 10, 100);
521 tmp = ata_wait_register(port + PORT_CTRL_STAT,
522 PORT_CS_RDY, 0, 10, 100);
523
524 if ((tmp & (PORT_CS_INIT | PORT_CS_RDY)) != PORT_CS_RDY)
525 return -EIO;
526 return 0;
527}
528
529static int sil24_softreset(struct ata_port *ap, unsigned int *class)
431{ 530{
432 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 531 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
433 struct sil24_port_priv *pp = ap->private_data; 532 struct sil24_port_priv *pp = ap->private_data;
434 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb; 533 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb;
435 dma_addr_t paddr = pp->cmd_block_dma; 534 dma_addr_t paddr = pp->cmd_block_dma;
436 unsigned long timeout = jiffies + ATA_TMOUT_BOOT * HZ; 535 u32 mask, irq_stat;
437 u32 irq_enable, irq_stat; 536 const char *reason;
438 537
439 DPRINTK("ENTER\n"); 538 DPRINTK("ENTER\n");
440 539
441 if (!sata_dev_present(ap)) { 540 if (ata_port_offline(ap)) {
442 DPRINTK("PHY reports no device\n"); 541 DPRINTK("PHY reports no device\n");
443 *class = ATA_DEV_NONE; 542 *class = ATA_DEV_NONE;
444 goto out; 543 goto out;
445 } 544 }
446 545
447 /* temporarily turn off IRQs during SRST */ 546 /* put the port into known state */
448 irq_enable = readl(port + PORT_IRQ_ENABLE_SET); 547 if (sil24_init_port(ap)) {
449 writel(irq_enable, port + PORT_IRQ_ENABLE_CLR); 548 reason ="port not ready";
450 549 goto err;
451 /* 550 }
452 * XXX: Not sure whether the following sleep is needed or not.
453 * The original driver had it. So....
454 */
455 msleep(10);
456 551
552 /* do SRST */
457 prb->ctrl = cpu_to_le16(PRB_CTRL_SRST); 553 prb->ctrl = cpu_to_le16(PRB_CTRL_SRST);
458 prb->fis[1] = 0; /* no PM yet */ 554 prb->fis[1] = 0; /* no PM yet */
459 555
460 writel((u32)paddr, port + PORT_CMD_ACTIVATE); 556 writel((u32)paddr, port + PORT_CMD_ACTIVATE);
557 writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4);
461 558
462 do { 559 mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT;
463 irq_stat = readl(port + PORT_IRQ_STAT); 560 irq_stat = ata_wait_register(port + PORT_IRQ_STAT, mask, 0x0,
464 writel(irq_stat, port + PORT_IRQ_STAT); /* clear irq */ 561 100, ATA_TMOUT_BOOT / HZ * 1000);
465
466 irq_stat >>= PORT_IRQ_RAW_SHIFT;
467 if (irq_stat & (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR))
468 break;
469 562
470 msleep(100); 563 writel(irq_stat, port + PORT_IRQ_STAT); /* clear IRQs */
471 } while (time_before(jiffies, timeout)); 564 irq_stat >>= PORT_IRQ_RAW_SHIFT;
472
473 /* restore IRQs */
474 writel(irq_enable, port + PORT_IRQ_ENABLE_SET);
475 565
476 if (!(irq_stat & PORT_IRQ_COMPLETE)) { 566 if (!(irq_stat & PORT_IRQ_COMPLETE)) {
477 DPRINTK("EXIT, srst failed\n"); 567 if (irq_stat & PORT_IRQ_ERROR)
478 return -EIO; 568 reason = "SRST command error";
569 else
570 reason = "timeout";
571 goto err;
479 } 572 }
480 573
481 sil24_update_tf(ap); 574 sil24_update_tf(ap);
@@ -487,22 +580,57 @@ static int sil24_softreset(struct ata_port *ap, int verbose,
487 out: 580 out:
488 DPRINTK("EXIT, class=%u\n", *class); 581 DPRINTK("EXIT, class=%u\n", *class);
489 return 0; 582 return 0;
583
584 err:
585 ata_port_printk(ap, KERN_ERR, "softreset failed (%s)\n", reason);
586 return -EIO;
490} 587}
491 588
492static int sil24_hardreset(struct ata_port *ap, int verbose, 589static int sil24_hardreset(struct ata_port *ap, unsigned int *class)
493 unsigned int *class)
494{ 590{
495 unsigned int dummy_class; 591 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
592 const char *reason;
593 int tout_msec, rc;
594 u32 tmp;
496 595
497 /* sil24 doesn't report device signature after hard reset */ 596 /* sil24 does the right thing(tm) without any protection */
498 return sata_std_hardreset(ap, verbose, &dummy_class); 597 sata_set_spd(ap);
499}
500 598
501static int sil24_probe_reset(struct ata_port *ap, unsigned int *classes) 599 tout_msec = 100;
502{ 600 if (ata_port_online(ap))
503 return ata_drive_probe_reset(ap, ata_std_probeinit, 601 tout_msec = 5000;
504 sil24_softreset, sil24_hardreset, 602
505 ata_std_postreset, classes); 603 writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT);
604 tmp = ata_wait_register(port + PORT_CTRL_STAT,
605 PORT_CS_DEV_RST, PORT_CS_DEV_RST, 10, tout_msec);
606
607 /* SStatus oscillates between zero and valid status after
608 * DEV_RST, debounce it.
609 */
610 rc = sata_phy_debounce(ap, sata_deb_timing_before_fsrst);
611 if (rc) {
612 reason = "PHY debouncing failed";
613 goto err;
614 }
615
616 if (tmp & PORT_CS_DEV_RST) {
617 if (ata_port_offline(ap))
618 return 0;
619 reason = "link not ready";
620 goto err;
621 }
622
623 /* Sil24 doesn't store signature FIS after hardreset, so we
624 * can't wait for BSY to clear. Some devices take a long time
625 * to get ready and those devices will choke if we don't wait
626 * for BSY clearance here. Tell libata to perform follow-up
627 * softreset.
628 */
629 return -EAGAIN;
630
631 err:
632 ata_port_printk(ap, KERN_ERR, "hardreset failed (%s)\n", reason);
633 return -EIO;
506} 634}
507 635
508static inline void sil24_fill_sg(struct ata_queued_cmd *qc, 636static inline void sil24_fill_sg(struct ata_queued_cmd *qc,
@@ -528,17 +656,20 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
528{ 656{
529 struct ata_port *ap = qc->ap; 657 struct ata_port *ap = qc->ap;
530 struct sil24_port_priv *pp = ap->private_data; 658 struct sil24_port_priv *pp = ap->private_data;
531 union sil24_cmd_block *cb = pp->cmd_block + qc->tag; 659 union sil24_cmd_block *cb;
532 struct sil24_prb *prb; 660 struct sil24_prb *prb;
533 struct sil24_sge *sge; 661 struct sil24_sge *sge;
662 u16 ctrl = 0;
663
664 cb = &pp->cmd_block[sil24_tag(qc->tag)];
534 665
535 switch (qc->tf.protocol) { 666 switch (qc->tf.protocol) {
536 case ATA_PROT_PIO: 667 case ATA_PROT_PIO:
537 case ATA_PROT_DMA: 668 case ATA_PROT_DMA:
669 case ATA_PROT_NCQ:
538 case ATA_PROT_NODATA: 670 case ATA_PROT_NODATA:
539 prb = &cb->ata.prb; 671 prb = &cb->ata.prb;
540 sge = cb->ata.sge; 672 sge = cb->ata.sge;
541 prb->ctrl = 0;
542 break; 673 break;
543 674
544 case ATA_PROT_ATAPI: 675 case ATA_PROT_ATAPI:
@@ -551,12 +682,10 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
551 682
552 if (qc->tf.protocol != ATA_PROT_ATAPI_NODATA) { 683 if (qc->tf.protocol != ATA_PROT_ATAPI_NODATA) {
553 if (qc->tf.flags & ATA_TFLAG_WRITE) 684 if (qc->tf.flags & ATA_TFLAG_WRITE)
554 prb->ctrl = cpu_to_le16(PRB_CTRL_PACKET_WRITE); 685 ctrl = PRB_CTRL_PACKET_WRITE;
555 else 686 else
556 prb->ctrl = cpu_to_le16(PRB_CTRL_PACKET_READ); 687 ctrl = PRB_CTRL_PACKET_READ;
557 } else 688 }
558 prb->ctrl = 0;
559
560 break; 689 break;
561 690
562 default: 691 default:
@@ -565,6 +694,7 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
565 BUG(); 694 BUG();
566 } 695 }
567 696
697 prb->ctrl = cpu_to_le16(ctrl);
568 ata_tf_to_fis(&qc->tf, prb->fis, 0); 698 ata_tf_to_fis(&qc->tf, prb->fis, 0);
569 699
570 if (qc->flags & ATA_QCFLAG_DMAMAP) 700 if (qc->flags & ATA_QCFLAG_DMAMAP)
@@ -574,11 +704,18 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
574static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc) 704static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc)
575{ 705{
576 struct ata_port *ap = qc->ap; 706 struct ata_port *ap = qc->ap;
577 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
578 struct sil24_port_priv *pp = ap->private_data; 707 struct sil24_port_priv *pp = ap->private_data;
579 dma_addr_t paddr = pp->cmd_block_dma + qc->tag * sizeof(*pp->cmd_block); 708 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
709 unsigned int tag = sil24_tag(qc->tag);
710 dma_addr_t paddr;
711 void __iomem *activate;
712
713 paddr = pp->cmd_block_dma + tag * sizeof(*pp->cmd_block);
714 activate = port + PORT_CMD_ACTIVATE + tag * 8;
715
716 writel((u32)paddr, activate);
717 writel((u64)paddr >> 32, activate + 4);
580 718
581 writel((u32)paddr, port + PORT_CMD_ACTIVATE);
582 return 0; 719 return 0;
583} 720}
584 721
@@ -587,162 +724,139 @@ static void sil24_irq_clear(struct ata_port *ap)
587 /* unused */ 724 /* unused */
588} 725}
589 726
590static int __sil24_restart_controller(void __iomem *port) 727static void sil24_freeze(struct ata_port *ap)
591{ 728{
592 u32 tmp; 729 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
593 int cnt;
594
595 writel(PORT_CS_INIT, port + PORT_CTRL_STAT);
596
597 /* Max ~10ms */
598 for (cnt = 0; cnt < 10000; cnt++) {
599 tmp = readl(port + PORT_CTRL_STAT);
600 if (tmp & PORT_CS_RDY)
601 return 0;
602 udelay(1);
603 }
604 730
605 return -1; 731 /* Port-wide IRQ mask in HOST_CTRL doesn't really work, clear
732 * PORT_IRQ_ENABLE instead.
733 */
734 writel(0xffff, port + PORT_IRQ_ENABLE_CLR);
606} 735}
607 736
608static void sil24_restart_controller(struct ata_port *ap) 737static void sil24_thaw(struct ata_port *ap)
609{ 738{
610 if (__sil24_restart_controller((void __iomem *)ap->ioaddr.cmd_addr)) 739 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
611 printk(KERN_ERR DRV_NAME 740 u32 tmp;
612 " ata%u: failed to restart controller\n", ap->id); 741
742 /* clear IRQ */
743 tmp = readl(port + PORT_IRQ_STAT);
744 writel(tmp, port + PORT_IRQ_STAT);
745
746 /* turn IRQ back on */
747 writel(DEF_PORT_IRQ, port + PORT_IRQ_ENABLE_SET);
613} 748}
614 749
615static int __sil24_reset_controller(void __iomem *port) 750static void sil24_error_intr(struct ata_port *ap)
616{ 751{
617 int cnt; 752 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
618 u32 tmp; 753 struct ata_eh_info *ehi = &ap->eh_info;
754 int freeze = 0;
755 u32 irq_stat;
619 756
620 /* Reset controller state. Is this correct? */ 757 /* on error, we need to clear IRQ explicitly */
621 writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT); 758 irq_stat = readl(port + PORT_IRQ_STAT);
622 readl(port + PORT_CTRL_STAT); /* sync */ 759 writel(irq_stat, port + PORT_IRQ_STAT);
623 760
624 /* Max ~100ms */ 761 /* first, analyze and record host port events */
625 for (cnt = 0; cnt < 1000; cnt++) { 762 ata_ehi_clear_desc(ehi);
626 udelay(100);
627 tmp = readl(port + PORT_CTRL_STAT);
628 if (!(tmp & PORT_CS_DEV_RST))
629 break;
630 }
631 763
632 if (tmp & PORT_CS_DEV_RST) 764 ata_ehi_push_desc(ehi, "irq_stat 0x%08x", irq_stat);
633 return -1;
634 765
635 if (tmp & PORT_CS_RDY) 766 if (irq_stat & (PORT_IRQ_PHYRDY_CHG | PORT_IRQ_DEV_XCHG)) {
636 return 0; 767 ata_ehi_hotplugged(ehi);
768 ata_ehi_push_desc(ehi, ", %s",
769 irq_stat & PORT_IRQ_PHYRDY_CHG ?
770 "PHY RDY changed" : "device exchanged");
771 freeze = 1;
772 }
637 773
638 return __sil24_restart_controller(port); 774 if (irq_stat & PORT_IRQ_UNK_FIS) {
639} 775 ehi->err_mask |= AC_ERR_HSM;
776 ehi->action |= ATA_EH_SOFTRESET;
777 ata_ehi_push_desc(ehi , ", unknown FIS");
778 freeze = 1;
779 }
640 780
641static void sil24_reset_controller(struct ata_port *ap) 781 /* deal with command error */
642{ 782 if (irq_stat & PORT_IRQ_ERROR) {
643 printk(KERN_NOTICE DRV_NAME 783 struct sil24_cerr_info *ci = NULL;
644 " ata%u: resetting controller...\n", ap->id); 784 unsigned int err_mask = 0, action = 0;
645 if (__sil24_reset_controller((void __iomem *)ap->ioaddr.cmd_addr)) 785 struct ata_queued_cmd *qc;
646 printk(KERN_ERR DRV_NAME 786 u32 cerr;
647 " ata%u: failed to reset controller\n", ap->id); 787
648} 788 /* analyze CMD_ERR */
789 cerr = readl(port + PORT_CMD_ERR);
790 if (cerr < ARRAY_SIZE(sil24_cerr_db))
791 ci = &sil24_cerr_db[cerr];
792
793 if (ci && ci->desc) {
794 err_mask |= ci->err_mask;
795 action |= ci->action;
796 ata_ehi_push_desc(ehi, ", %s", ci->desc);
797 } else {
798 err_mask |= AC_ERR_OTHER;
799 action |= ATA_EH_SOFTRESET;
800 ata_ehi_push_desc(ehi, ", unknown command error %d",
801 cerr);
802 }
649 803
650static void sil24_eng_timeout(struct ata_port *ap) 804 /* record error info */
651{ 805 qc = ata_qc_from_tag(ap, ap->active_tag);
652 struct ata_queued_cmd *qc; 806 if (qc) {
807 sil24_update_tf(ap);
808 qc->err_mask |= err_mask;
809 } else
810 ehi->err_mask |= err_mask;
653 811
654 qc = ata_qc_from_tag(ap, ap->active_tag); 812 ehi->action |= action;
813 }
655 814
656 printk(KERN_ERR "ata%u: command timeout\n", ap->id); 815 /* freeze or abort */
657 qc->err_mask |= AC_ERR_TIMEOUT; 816 if (freeze)
658 ata_eh_qc_complete(qc); 817 ata_port_freeze(ap);
818 else
819 ata_port_abort(ap);
820}
659 821
660 sil24_reset_controller(ap); 822static void sil24_finish_qc(struct ata_queued_cmd *qc)
823{
824 if (qc->flags & ATA_QCFLAG_RESULT_TF)
825 sil24_update_tf(qc->ap);
661} 826}
662 827
663static void sil24_error_intr(struct ata_port *ap, u32 slot_stat) 828static inline void sil24_host_intr(struct ata_port *ap)
664{ 829{
665 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
666 struct sil24_port_priv *pp = ap->private_data;
667 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 830 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
668 u32 irq_stat, cmd_err, sstatus, serror; 831 u32 slot_stat, qc_active;
669 unsigned int err_mask; 832 int rc;
670 833
671 irq_stat = readl(port + PORT_IRQ_STAT); 834 slot_stat = readl(port + PORT_SLOT_STAT);
672 writel(irq_stat, port + PORT_IRQ_STAT); /* clear irq */
673 835
674 if (!(irq_stat & PORT_IRQ_ERROR)) { 836 if (unlikely(slot_stat & HOST_SSTAT_ATTN)) {
675 /* ignore non-completion, non-error irqs for now */ 837 sil24_error_intr(ap);
676 printk(KERN_WARNING DRV_NAME
677 "ata%u: non-error exception irq (irq_stat %x)\n",
678 ap->id, irq_stat);
679 return; 838 return;
680 } 839 }
681 840
682 cmd_err = readl(port + PORT_CMD_ERR); 841 if (ap->flags & SIL24_FLAG_PCIX_IRQ_WOC)
683 sstatus = readl(port + PORT_SSTATUS); 842 writel(PORT_IRQ_COMPLETE, port + PORT_IRQ_STAT);
684 serror = readl(port + PORT_SERROR);
685 if (serror)
686 writel(serror, port + PORT_SERROR);
687 843
688 /* 844 qc_active = slot_stat & ~HOST_SSTAT_ATTN;
689 * Don't log ATAPI device errors. They're supposed to happen 845 rc = ata_qc_complete_multiple(ap, qc_active, sil24_finish_qc);
690 * and any serious errors will be logged using sense data by 846 if (rc > 0)
691 * the SCSI layer. 847 return;
692 */ 848 if (rc < 0) {
693 if (ap->device[0].class != ATA_DEV_ATAPI || cmd_err > PORT_CERR_SDB) 849 struct ata_eh_info *ehi = &ap->eh_info;
694 printk("ata%u: error interrupt on port%d\n" 850 ehi->err_mask |= AC_ERR_HSM;
695 " stat=0x%x irq=0x%x cmd_err=%d sstatus=0x%x serror=0x%x\n", 851 ehi->action |= ATA_EH_SOFTRESET;
696 ap->id, ap->port_no, slot_stat, irq_stat, cmd_err, sstatus, serror); 852 ata_port_freeze(ap);
697 853 return;
698 if (cmd_err == PORT_CERR_DEV || cmd_err == PORT_CERR_SDB) {
699 /*
700 * Device is reporting error, tf registers are valid.
701 */
702 sil24_update_tf(ap);
703 err_mask = ac_err_mask(pp->tf.command);
704 sil24_restart_controller(ap);
705 } else {
706 /*
707 * Other errors. libata currently doesn't have any
708 * mechanism to report these errors. Just turn on
709 * ATA_ERR.
710 */
711 err_mask = AC_ERR_OTHER;
712 sil24_reset_controller(ap);
713 } 854 }
714 855
715 if (qc) { 856 if (ata_ratelimit())
716 qc->err_mask |= err_mask; 857 ata_port_printk(ap, KERN_INFO, "spurious interrupt "
717 ata_qc_complete(qc); 858 "(slot_stat 0x%x active_tag %d sactive 0x%x)\n",
718 } 859 slot_stat, ap->active_tag, ap->sactive);
719}
720
721static inline void sil24_host_intr(struct ata_port *ap)
722{
723 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
724 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
725 u32 slot_stat;
726
727 slot_stat = readl(port + PORT_SLOT_STAT);
728 if (!(slot_stat & HOST_SSTAT_ATTN)) {
729 struct sil24_port_priv *pp = ap->private_data;
730 /*
731 * !HOST_SSAT_ATTN guarantees successful completion,
732 * so reading back tf registers is unnecessary for
733 * most commands. TODO: read tf registers for
734 * commands which require these values on successful
735 * completion (EXECUTE DEVICE DIAGNOSTIC, CHECK POWER,
736 * DEVICE RESET and READ PORT MULTIPLIER (any more?).
737 */
738 sil24_update_tf(ap);
739
740 if (qc) {
741 qc->err_mask |= ac_err_mask(pp->tf.command);
742 ata_qc_complete(qc);
743 }
744 } else
745 sil24_error_intr(ap, slot_stat);
746} 860}
747 861
748static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs) 862static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
@@ -769,7 +883,7 @@ static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *
769 for (i = 0; i < host_set->n_ports; i++) 883 for (i = 0; i < host_set->n_ports; i++)
770 if (status & (1 << i)) { 884 if (status & (1 << i)) {
771 struct ata_port *ap = host_set->ports[i]; 885 struct ata_port *ap = host_set->ports[i];
772 if (ap && !(ap->flags & ATA_FLAG_PORT_DISABLED)) { 886 if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
773 sil24_host_intr(host_set->ports[i]); 887 sil24_host_intr(host_set->ports[i]);
774 handled++; 888 handled++;
775 } else 889 } else
@@ -782,9 +896,35 @@ static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *
782 return IRQ_RETVAL(handled); 896 return IRQ_RETVAL(handled);
783} 897}
784 898
899static void sil24_error_handler(struct ata_port *ap)
900{
901 struct ata_eh_context *ehc = &ap->eh_context;
902
903 if (sil24_init_port(ap)) {
904 ata_eh_freeze_port(ap);
905 ehc->i.action |= ATA_EH_HARDRESET;
906 }
907
908 /* perform recovery */
909 ata_do_eh(ap, ata_std_prereset, sil24_softreset, sil24_hardreset,
910 ata_std_postreset);
911}
912
913static void sil24_post_internal_cmd(struct ata_queued_cmd *qc)
914{
915 struct ata_port *ap = qc->ap;
916
917 if (qc->flags & ATA_QCFLAG_FAILED)
918 qc->err_mask |= AC_ERR_OTHER;
919
920 /* make DMA engine forget about the failed command */
921 if (qc->err_mask)
922 sil24_init_port(ap);
923}
924
785static inline void sil24_cblk_free(struct sil24_port_priv *pp, struct device *dev) 925static inline void sil24_cblk_free(struct sil24_port_priv *pp, struct device *dev)
786{ 926{
787 const size_t cb_size = sizeof(*pp->cmd_block); 927 const size_t cb_size = sizeof(*pp->cmd_block) * SIL24_MAX_CMDS;
788 928
789 dma_free_coherent(dev, cb_size, pp->cmd_block, pp->cmd_block_dma); 929 dma_free_coherent(dev, cb_size, pp->cmd_block, pp->cmd_block_dma);
790} 930}
@@ -794,7 +934,7 @@ static int sil24_port_start(struct ata_port *ap)
794 struct device *dev = ap->host_set->dev; 934 struct device *dev = ap->host_set->dev;
795 struct sil24_port_priv *pp; 935 struct sil24_port_priv *pp;
796 union sil24_cmd_block *cb; 936 union sil24_cmd_block *cb;
797 size_t cb_size = sizeof(*cb); 937 size_t cb_size = sizeof(*cb) * SIL24_MAX_CMDS;
798 dma_addr_t cb_dma; 938 dma_addr_t cb_dma;
799 int rc = -ENOMEM; 939 int rc = -ENOMEM;
800 940
@@ -858,6 +998,7 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
858 void __iomem *host_base = NULL; 998 void __iomem *host_base = NULL;
859 void __iomem *port_base = NULL; 999 void __iomem *port_base = NULL;
860 int i, rc; 1000 int i, rc;
1001 u32 tmp;
861 1002
862 if (!printed_version++) 1003 if (!printed_version++)
863 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1004 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
@@ -910,37 +1051,53 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
910 /* 1051 /*
911 * Configure the device 1052 * Configure the device
912 */ 1053 */
913 /* 1054 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
914 * FIXME: This device is certainly 64-bit capable. We just 1055 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
915 * don't know how to use it. After fixing 32bit activation in 1056 if (rc) {
916 * this function, enable 64bit masks here. 1057 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
917 */ 1058 if (rc) {
918 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 1059 dev_printk(KERN_ERR, &pdev->dev,
919 if (rc) { 1060 "64-bit DMA enable failed\n");
920 dev_printk(KERN_ERR, &pdev->dev, 1061 goto out_free;
921 "32-bit DMA enable failed\n"); 1062 }
922 goto out_free; 1063 }
923 } 1064 } else {
924 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 1065 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
925 if (rc) { 1066 if (rc) {
926 dev_printk(KERN_ERR, &pdev->dev, 1067 dev_printk(KERN_ERR, &pdev->dev,
927 "32-bit consistent DMA enable failed\n"); 1068 "32-bit DMA enable failed\n");
928 goto out_free; 1069 goto out_free;
1070 }
1071 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1072 if (rc) {
1073 dev_printk(KERN_ERR, &pdev->dev,
1074 "32-bit consistent DMA enable failed\n");
1075 goto out_free;
1076 }
929 } 1077 }
930 1078
931 /* GPIO off */ 1079 /* GPIO off */
932 writel(0, host_base + HOST_FLASH_CMD); 1080 writel(0, host_base + HOST_FLASH_CMD);
933 1081
934 /* Mask interrupts during initialization */ 1082 /* Apply workaround for completion IRQ loss on PCI-X errata */
1083 if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC) {
1084 tmp = readl(host_base + HOST_CTRL);
1085 if (tmp & (HOST_CTRL_TRDY | HOST_CTRL_STOP | HOST_CTRL_DEVSEL))
1086 dev_printk(KERN_INFO, &pdev->dev,
1087 "Applying completion IRQ loss on PCI-X "
1088 "errata fix\n");
1089 else
1090 probe_ent->host_flags &= ~SIL24_FLAG_PCIX_IRQ_WOC;
1091 }
1092
1093 /* clear global reset & mask interrupts during initialization */
935 writel(0, host_base + HOST_CTRL); 1094 writel(0, host_base + HOST_CTRL);
936 1095
937 for (i = 0; i < probe_ent->n_ports; i++) { 1096 for (i = 0; i < probe_ent->n_ports; i++) {
938 void __iomem *port = port_base + i * PORT_REGS_SIZE; 1097 void __iomem *port = port_base + i * PORT_REGS_SIZE;
939 unsigned long portu = (unsigned long)port; 1098 unsigned long portu = (unsigned long)port;
940 u32 tmp;
941 int cnt;
942 1099
943 probe_ent->port[i].cmd_addr = portu + PORT_PRB; 1100 probe_ent->port[i].cmd_addr = portu;
944 probe_ent->port[i].scr_addr = portu + PORT_SCONTROL; 1101 probe_ent->port[i].scr_addr = portu + PORT_SCONTROL;
945 1102
946 ata_std_ports(&probe_ent->port[i]); 1103 ata_std_ports(&probe_ent->port[i]);
@@ -952,18 +1109,20 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
952 tmp = readl(port + PORT_CTRL_STAT); 1109 tmp = readl(port + PORT_CTRL_STAT);
953 if (tmp & PORT_CS_PORT_RST) { 1110 if (tmp & PORT_CS_PORT_RST) {
954 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR); 1111 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
955 readl(port + PORT_CTRL_STAT); /* sync */ 1112 tmp = ata_wait_register(port + PORT_CTRL_STAT,
956 for (cnt = 0; cnt < 10; cnt++) { 1113 PORT_CS_PORT_RST,
957 msleep(10); 1114 PORT_CS_PORT_RST, 10, 100);
958 tmp = readl(port + PORT_CTRL_STAT);
959 if (!(tmp & PORT_CS_PORT_RST))
960 break;
961 }
962 if (tmp & PORT_CS_PORT_RST) 1115 if (tmp & PORT_CS_PORT_RST)
963 dev_printk(KERN_ERR, &pdev->dev, 1116 dev_printk(KERN_ERR, &pdev->dev,
964 "failed to clear port RST\n"); 1117 "failed to clear port RST\n");
965 } 1118 }
966 1119
1120 /* Configure IRQ WoC */
1121 if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC)
1122 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
1123 else
1124 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
1125
967 /* Zero error counters. */ 1126 /* Zero error counters. */
968 writel(0x8000, port + PORT_DECODE_ERR_THRESH); 1127 writel(0x8000, port + PORT_DECODE_ERR_THRESH);
969 writel(0x8000, port + PORT_CRC_ERR_THRESH); 1128 writel(0x8000, port + PORT_CRC_ERR_THRESH);
@@ -972,26 +1131,11 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
972 writel(0x0000, port + PORT_CRC_ERR_CNT); 1131 writel(0x0000, port + PORT_CRC_ERR_CNT);
973 writel(0x0000, port + PORT_HSHK_ERR_CNT); 1132 writel(0x0000, port + PORT_HSHK_ERR_CNT);
974 1133
975 /* FIXME: 32bit activation? */ 1134 /* Always use 64bit activation */
976 writel(0, port + PORT_ACTIVATE_UPPER_ADDR); 1135 writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_CLR);
977 writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_STAT);
978
979 /* Configure interrupts */
980 writel(0xffff, port + PORT_IRQ_ENABLE_CLR);
981 writel(PORT_IRQ_COMPLETE | PORT_IRQ_ERROR | PORT_IRQ_SDB_FIS,
982 port + PORT_IRQ_ENABLE_SET);
983
984 /* Clear interrupts */
985 writel(0x0fff0fff, port + PORT_IRQ_STAT);
986 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
987 1136
988 /* Clear port multiplier enable and resume bits */ 1137 /* Clear port multiplier enable and resume bits */
989 writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR); 1138 writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR);
990
991 /* Reset itself */
992 if (__sil24_reset_controller(port))
993 dev_printk(KERN_ERR, &pdev->dev,
994 "failed to reset controller\n");
995 } 1139 }
996 1140
997 /* Turn on interrupts */ 1141 /* Turn on interrupts */