aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sata_sil.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/sata_sil.c')
-rw-r--r--drivers/scsi/sata_sil.c221
1 files changed, 184 insertions, 37 deletions
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index 106627299d55..bc9f918a7f28 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -46,7 +46,7 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "sata_sil" 48#define DRV_NAME "sata_sil"
49#define DRV_VERSION "0.9" 49#define DRV_VERSION "1.0"
50 50
51enum { 51enum {
52 /* 52 /*
@@ -54,8 +54,9 @@ enum {
54 */ 54 */
55 SIL_FLAG_RERR_ON_DMA_ACT = (1 << 29), 55 SIL_FLAG_RERR_ON_DMA_ACT = (1 << 29),
56 SIL_FLAG_MOD15WRITE = (1 << 30), 56 SIL_FLAG_MOD15WRITE = (1 << 30),
57
57 SIL_DFL_HOST_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 58 SIL_DFL_HOST_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
58 ATA_FLAG_MMIO, 59 ATA_FLAG_MMIO | ATA_FLAG_HRST_TO_RESUME,
59 60
60 /* 61 /*
61 * Controller IDs 62 * Controller IDs
@@ -84,6 +85,20 @@ enum {
84 /* BMDMA/BMDMA2 */ 85 /* BMDMA/BMDMA2 */
85 SIL_INTR_STEERING = (1 << 1), 86 SIL_INTR_STEERING = (1 << 1),
86 87
88 SIL_DMA_ENABLE = (1 << 0), /* DMA run switch */
89 SIL_DMA_RDWR = (1 << 3), /* DMA Rd-Wr */
90 SIL_DMA_SATA_IRQ = (1 << 4), /* OR of all SATA IRQs */
91 SIL_DMA_ACTIVE = (1 << 16), /* DMA running */
92 SIL_DMA_ERROR = (1 << 17), /* PCI bus error */
93 SIL_DMA_COMPLETE = (1 << 18), /* cmd complete / IRQ pending */
94 SIL_DMA_N_SATA_IRQ = (1 << 6), /* SATA_IRQ for the next channel */
95 SIL_DMA_N_ACTIVE = (1 << 24), /* ACTIVE for the next channel */
96 SIL_DMA_N_ERROR = (1 << 25), /* ERROR for the next channel */
97 SIL_DMA_N_COMPLETE = (1 << 26), /* COMPLETE for the next channel */
98
99 /* SIEN */
100 SIL_SIEN_N = (1 << 16), /* triggered by SError.N */
101
87 /* 102 /*
88 * Others 103 * Others
89 */ 104 */
@@ -96,6 +111,10 @@ static void sil_dev_config(struct ata_port *ap, struct ata_device *dev);
96static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg); 111static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg);
97static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 112static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
98static void sil_post_set_mode (struct ata_port *ap); 113static void sil_post_set_mode (struct ata_port *ap);
114static irqreturn_t sil_interrupt(int irq, void *dev_instance,
115 struct pt_regs *regs);
116static void sil_freeze(struct ata_port *ap);
117static void sil_thaw(struct ata_port *ap);
99 118
100 119
101static const struct pci_device_id sil_pci_tbl[] = { 120static const struct pci_device_id sil_pci_tbl[] = {
@@ -155,6 +174,7 @@ static struct scsi_host_template sil_sht = {
155 .proc_name = DRV_NAME, 174 .proc_name = DRV_NAME,
156 .dma_boundary = ATA_DMA_BOUNDARY, 175 .dma_boundary = ATA_DMA_BOUNDARY,
157 .slave_configure = ata_scsi_slave_config, 176 .slave_configure = ata_scsi_slave_config,
177 .slave_destroy = ata_scsi_slave_destroy,
158 .bios_param = ata_std_bios_param, 178 .bios_param = ata_std_bios_param,
159}; 179};
160 180
@@ -166,7 +186,6 @@ static const struct ata_port_operations sil_ops = {
166 .check_status = ata_check_status, 186 .check_status = ata_check_status,
167 .exec_command = ata_exec_command, 187 .exec_command = ata_exec_command,
168 .dev_select = ata_std_dev_select, 188 .dev_select = ata_std_dev_select,
169 .probe_reset = ata_std_probe_reset,
170 .post_set_mode = sil_post_set_mode, 189 .post_set_mode = sil_post_set_mode,
171 .bmdma_setup = ata_bmdma_setup, 190 .bmdma_setup = ata_bmdma_setup,
172 .bmdma_start = ata_bmdma_start, 191 .bmdma_start = ata_bmdma_start,
@@ -174,8 +193,12 @@ static const struct ata_port_operations sil_ops = {
174 .bmdma_status = ata_bmdma_status, 193 .bmdma_status = ata_bmdma_status,
175 .qc_prep = ata_qc_prep, 194 .qc_prep = ata_qc_prep,
176 .qc_issue = ata_qc_issue_prot, 195 .qc_issue = ata_qc_issue_prot,
177 .eng_timeout = ata_eng_timeout, 196 .data_xfer = ata_mmio_data_xfer,
178 .irq_handler = ata_interrupt, 197 .freeze = sil_freeze,
198 .thaw = sil_thaw,
199 .error_handler = ata_bmdma_error_handler,
200 .post_internal_cmd = ata_bmdma_post_internal_cmd,
201 .irq_handler = sil_interrupt,
179 .irq_clear = ata_bmdma_irq_clear, 202 .irq_clear = ata_bmdma_irq_clear,
180 .scr_read = sil_scr_read, 203 .scr_read = sil_scr_read,
181 .scr_write = sil_scr_write, 204 .scr_write = sil_scr_write,
@@ -220,6 +243,7 @@ static const struct {
220 unsigned long tf; /* ATA taskfile register block */ 243 unsigned long tf; /* ATA taskfile register block */
221 unsigned long ctl; /* ATA control/altstatus register block */ 244 unsigned long ctl; /* ATA control/altstatus register block */
222 unsigned long bmdma; /* DMA register block */ 245 unsigned long bmdma; /* DMA register block */
246 unsigned long bmdma2; /* DMA register block #2 */
223 unsigned long fifo_cfg; /* FIFO Valid Byte Count and Control */ 247 unsigned long fifo_cfg; /* FIFO Valid Byte Count and Control */
224 unsigned long scr; /* SATA control register block */ 248 unsigned long scr; /* SATA control register block */
225 unsigned long sien; /* SATA Interrupt Enable register */ 249 unsigned long sien; /* SATA Interrupt Enable register */
@@ -227,10 +251,10 @@ static const struct {
227 unsigned long sfis_cfg; /* SATA FIS reception config register */ 251 unsigned long sfis_cfg; /* SATA FIS reception config register */
228} sil_port[] = { 252} sil_port[] = {
229 /* port 0 ... */ 253 /* port 0 ... */
230 { 0x80, 0x8A, 0x00, 0x40, 0x100, 0x148, 0xb4, 0x14c }, 254 { 0x80, 0x8A, 0x00, 0x10, 0x40, 0x100, 0x148, 0xb4, 0x14c },
231 { 0xC0, 0xCA, 0x08, 0x44, 0x180, 0x1c8, 0xf4, 0x1cc }, 255 { 0xC0, 0xCA, 0x08, 0x18, 0x44, 0x180, 0x1c8, 0xf4, 0x1cc },
232 { 0x280, 0x28A, 0x200, 0x240, 0x300, 0x348, 0x2b4, 0x34c }, 256 { 0x280, 0x28A, 0x200, 0x210, 0x240, 0x300, 0x348, 0x2b4, 0x34c },
233 { 0x2C0, 0x2CA, 0x208, 0x244, 0x380, 0x3c8, 0x2f4, 0x3cc }, 257 { 0x2C0, 0x2CA, 0x208, 0x218, 0x244, 0x380, 0x3c8, 0x2f4, 0x3cc },
234 /* ... port 3 */ 258 /* ... port 3 */
235}; 259};
236 260
@@ -263,7 +287,7 @@ static void sil_post_set_mode (struct ata_port *ap)
263 287
264 for (i = 0; i < 2; i++) { 288 for (i = 0; i < 2; i++) {
265 dev = &ap->device[i]; 289 dev = &ap->device[i];
266 if (!ata_dev_present(dev)) 290 if (!ata_dev_enabled(dev))
267 dev_mode[i] = 0; /* PIO0/1/2 */ 291 dev_mode[i] = 0; /* PIO0/1/2 */
268 else if (dev->flags & ATA_DFLAG_PIO) 292 else if (dev->flags & ATA_DFLAG_PIO)
269 dev_mode[i] = 1; /* PIO3/4 */ 293 dev_mode[i] = 1; /* PIO3/4 */
@@ -314,6 +338,151 @@ static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
314 writel(val, mmio); 338 writel(val, mmio);
315} 339}
316 340
341static void sil_host_intr(struct ata_port *ap, u32 bmdma2)
342{
343 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
344 u8 status;
345
346 if (unlikely(bmdma2 & SIL_DMA_SATA_IRQ)) {
347 u32 serror;
348
349 /* SIEN doesn't mask SATA IRQs on some 3112s. Those
350 * controllers continue to assert IRQ as long as
351 * SError bits are pending. Clear SError immediately.
352 */
353 serror = sil_scr_read(ap, SCR_ERROR);
354 sil_scr_write(ap, SCR_ERROR, serror);
355
356 /* Trigger hotplug and accumulate SError only if the
357 * port isn't already frozen. Otherwise, PHY events
358 * during hardreset makes controllers with broken SIEN
359 * repeat probing needlessly.
360 */
361 if (!(ap->flags & ATA_FLAG_FROZEN)) {
362 ata_ehi_hotplugged(&ap->eh_info);
363 ap->eh_info.serror |= serror;
364 }
365
366 goto freeze;
367 }
368
369 if (unlikely(!qc || qc->tf.ctl & ATA_NIEN))
370 goto freeze;
371
372 /* Check whether we are expecting interrupt in this state */
373 switch (ap->hsm_task_state) {
374 case HSM_ST_FIRST:
375 /* Some pre-ATAPI-4 devices assert INTRQ
376 * at this state when ready to receive CDB.
377 */
378
379 /* Check the ATA_DFLAG_CDB_INTR flag is enough here.
380 * The flag was turned on only for atapi devices.
381 * No need to check is_atapi_taskfile(&qc->tf) again.
382 */
383 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
384 goto err_hsm;
385 break;
386 case HSM_ST_LAST:
387 if (qc->tf.protocol == ATA_PROT_DMA ||
388 qc->tf.protocol == ATA_PROT_ATAPI_DMA) {
389 /* clear DMA-Start bit */
390 ap->ops->bmdma_stop(qc);
391
392 if (bmdma2 & SIL_DMA_ERROR) {
393 qc->err_mask |= AC_ERR_HOST_BUS;
394 ap->hsm_task_state = HSM_ST_ERR;
395 }
396 }
397 break;
398 case HSM_ST:
399 break;
400 default:
401 goto err_hsm;
402 }
403
404 /* check main status, clearing INTRQ */
405 status = ata_chk_status(ap);
406 if (unlikely(status & ATA_BUSY))
407 goto err_hsm;
408
409 /* ack bmdma irq events */
410 ata_bmdma_irq_clear(ap);
411
412 /* kick HSM in the ass */
413 ata_hsm_move(ap, qc, status, 0);
414
415 return;
416
417 err_hsm:
418 qc->err_mask |= AC_ERR_HSM;
419 freeze:
420 ata_port_freeze(ap);
421}
422
423static irqreturn_t sil_interrupt(int irq, void *dev_instance,
424 struct pt_regs *regs)
425{
426 struct ata_host_set *host_set = dev_instance;
427 void __iomem *mmio_base = host_set->mmio_base;
428 int handled = 0;
429 int i;
430
431 spin_lock(&host_set->lock);
432
433 for (i = 0; i < host_set->n_ports; i++) {
434 struct ata_port *ap = host_set->ports[i];
435 u32 bmdma2 = readl(mmio_base + sil_port[ap->port_no].bmdma2);
436
437 if (unlikely(!ap || ap->flags & ATA_FLAG_DISABLED))
438 continue;
439
440 if (bmdma2 == 0xffffffff ||
441 !(bmdma2 & (SIL_DMA_COMPLETE | SIL_DMA_SATA_IRQ)))
442 continue;
443
444 sil_host_intr(ap, bmdma2);
445 handled = 1;
446 }
447
448 spin_unlock(&host_set->lock);
449
450 return IRQ_RETVAL(handled);
451}
452
453static void sil_freeze(struct ata_port *ap)
454{
455 void __iomem *mmio_base = ap->host_set->mmio_base;
456 u32 tmp;
457
458 /* global IRQ mask doesn't block SATA IRQ, turn off explicitly */
459 writel(0, mmio_base + sil_port[ap->port_no].sien);
460
461 /* plug IRQ */
462 tmp = readl(mmio_base + SIL_SYSCFG);
463 tmp |= SIL_MASK_IDE0_INT << ap->port_no;
464 writel(tmp, mmio_base + SIL_SYSCFG);
465 readl(mmio_base + SIL_SYSCFG); /* flush */
466}
467
468static void sil_thaw(struct ata_port *ap)
469{
470 void __iomem *mmio_base = ap->host_set->mmio_base;
471 u32 tmp;
472
473 /* clear IRQ */
474 ata_chk_status(ap);
475 ata_bmdma_irq_clear(ap);
476
477 /* turn on SATA IRQ */
478 writel(SIL_SIEN_N, mmio_base + sil_port[ap->port_no].sien);
479
480 /* turn on IRQ */
481 tmp = readl(mmio_base + SIL_SYSCFG);
482 tmp &= ~(SIL_MASK_IDE0_INT << ap->port_no);
483 writel(tmp, mmio_base + SIL_SYSCFG);
484}
485
317/** 486/**
318 * sil_dev_config - Apply device/host-specific errata fixups 487 * sil_dev_config - Apply device/host-specific errata fixups
319 * @ap: Port containing device to be examined 488 * @ap: Port containing device to be examined
@@ -360,16 +529,16 @@ static void sil_dev_config(struct ata_port *ap, struct ata_device *dev)
360 if (slow_down || 529 if (slow_down ||
361 ((ap->flags & SIL_FLAG_MOD15WRITE) && 530 ((ap->flags & SIL_FLAG_MOD15WRITE) &&
362 (quirks & SIL_QUIRK_MOD15WRITE))) { 531 (quirks & SIL_QUIRK_MOD15WRITE))) {
363 printk(KERN_INFO "ata%u(%u): applying Seagate errata fix (mod15write workaround)\n", 532 ata_dev_printk(dev, KERN_INFO, "applying Seagate errata fix "
364 ap->id, dev->devno); 533 "(mod15write workaround)\n");
365 dev->max_sectors = 15; 534 dev->max_sectors = 15;
366 return; 535 return;
367 } 536 }
368 537
369 /* limit to udma5 */ 538 /* limit to udma5 */
370 if (quirks & SIL_QUIRK_UDMA5MAX) { 539 if (quirks & SIL_QUIRK_UDMA5MAX) {
371 printk(KERN_INFO "ata%u(%u): applying Maxtor errata fix %s\n", 540 ata_dev_printk(dev, KERN_INFO,
372 ap->id, dev->devno, model_num); 541 "applying Maxtor errata fix %s\n", model_num);
373 dev->udma_mask &= ATA_UDMA5; 542 dev->udma_mask &= ATA_UDMA5;
374 return; 543 return;
375 } 544 }
@@ -384,16 +553,12 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
384 int rc; 553 int rc;
385 unsigned int i; 554 unsigned int i;
386 int pci_dev_busy = 0; 555 int pci_dev_busy = 0;
387 u32 tmp, irq_mask; 556 u32 tmp;
388 u8 cls; 557 u8 cls;
389 558
390 if (!printed_version++) 559 if (!printed_version++)
391 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 560 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
392 561
393 /*
394 * If this driver happens to only be useful on Apple's K2, then
395 * we should check that here as it has a normal Serverworks ID
396 */
397 rc = pci_enable_device(pdev); 562 rc = pci_enable_device(pdev);
398 if (rc) 563 if (rc)
399 return rc; 564 return rc;
@@ -478,31 +643,13 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
478 } 643 }
479 644
480 if (ent->driver_data == sil_3114) { 645 if (ent->driver_data == sil_3114) {
481 irq_mask = SIL_MASK_4PORT;
482
483 /* flip the magic "make 4 ports work" bit */ 646 /* flip the magic "make 4 ports work" bit */
484 tmp = readl(mmio_base + sil_port[2].bmdma); 647 tmp = readl(mmio_base + sil_port[2].bmdma);
485 if ((tmp & SIL_INTR_STEERING) == 0) 648 if ((tmp & SIL_INTR_STEERING) == 0)
486 writel(tmp | SIL_INTR_STEERING, 649 writel(tmp | SIL_INTR_STEERING,
487 mmio_base + sil_port[2].bmdma); 650 mmio_base + sil_port[2].bmdma);
488
489 } else {
490 irq_mask = SIL_MASK_2PORT;
491 }
492
493 /* make sure IDE0/1/2/3 interrupts are not masked */
494 tmp = readl(mmio_base + SIL_SYSCFG);
495 if (tmp & irq_mask) {
496 tmp &= ~irq_mask;
497 writel(tmp, mmio_base + SIL_SYSCFG);
498 readl(mmio_base + SIL_SYSCFG); /* flush */
499 } 651 }
500 652
501 /* mask all SATA phy-related interrupts */
502 /* TODO: unmask bit 6 (SError N bit) for hotplug */
503 for (i = 0; i < probe_ent->n_ports; i++)
504 writel(0, mmio_base + sil_port[i].sien);
505
506 pci_set_master(pdev); 653 pci_set_master(pdev);
507 654
508 /* FIXME: check ata_device_add return value */ 655 /* FIXME: check ata_device_add return value */