Skip to content

Commit 44a9b49

Browse files
Ondrej Zaryhtejun
authored andcommitted
sata_via: Apply WD workaround only when needed on VT6421
Currently, workaround for broken WD drives is applied always, slowing down all drives. And it has a bug - it's not applied after resume. Apply the workaround only if the error really appears (SErr == 0x1000500). This allows unaffected drives to run at full speed (provided that no affected drive is connected to the controller). Also make sure the workaround is re-applied on resume. Tested on VT6421. As SCR registers access is known to cause problems on VT6420 (and I don't have it to test), keep the workaround applied always on VT6420. Unaffected drive (Hitachi HDS721680PLA380): Before: $ hdparm -t --direct /dev/sdb /dev/sdb: Timing O_DIRECT disk reads: 160 MB in 3.01 seconds = 53.16 MB/sec After: $ hdparm -t --direct /dev/sdb /dev/sdb: Timing O_DIRECT disk reads: 200 MB in 3.01 seconds = 66.47 MB/sec Affected drive (WDC WD5003ABYX-18WERA0): Before: $ hdparm -t --direct /dev/sda /dev/sda: Timing O_DIRECT disk reads: 180 MB in 3.02 seconds = 59.51 MB/sec After: $ hdparm -t --direct /dev/sdb /dev/sdb: Timing O_DIRECT disk reads: 156 MB in 3.03 seconds = 51.48 MB/sec $ hdparm -t --direct /dev/sdb /dev/sdb: Timing O_DIRECT disk reads: 180 MB in 3.02 seconds = 59.64 MB/sec The first hdparm is slower because of the error: [ 50.408042] ata5: Incompatible drive: enabling workaround. This slows down transfer rate to ~60 MB/s [ 50.728052] ata5: SATA link up 1.5 Gbps (SStatus 113 SControl 310) [ 50.744834] ata5.00: configured for UDMA/133 Signed-off-by: Ondrej Zary <linux@rainbow-software.org> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 02e5329 commit 44a9b49

File tree

1 file changed

+74
-7
lines changed

1 file changed

+74
-7
lines changed

drivers/ata/sata_via.c

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ enum {
7373
SATA_EXT_PHY = (1 << 6), /* 0==use PATA, 1==ext phy */
7474
};
7575

76+
struct svia_priv {
77+
bool wd_workaround;
78+
};
79+
7680
static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
81+
#ifdef CONFIG_PM_SLEEP
82+
static int svia_pci_device_resume(struct pci_dev *pdev);
83+
#endif
7784
static int svia_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
7885
static int svia_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
7986
static int vt8251_scr_read(struct ata_link *link, unsigned int scr, u32 *val);
@@ -85,6 +92,7 @@ static void vt6420_bmdma_start(struct ata_queued_cmd *qc);
8592
static int vt6421_pata_cable_detect(struct ata_port *ap);
8693
static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev);
8794
static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev);
95+
static void vt6421_error_handler(struct ata_port *ap);
8896

8997
static const struct pci_device_id svia_pci_tbl[] = {
9098
{ PCI_VDEVICE(VIA, 0x5337), vt6420 },
@@ -105,7 +113,7 @@ static struct pci_driver svia_pci_driver = {
105113
.probe = svia_init_one,
106114
#ifdef CONFIG_PM_SLEEP
107115
.suspend = ata_pci_device_suspend,
108-
.resume = ata_pci_device_resume,
116+
.resume = svia_pci_device_resume,
109117
#endif
110118
.remove = ata_pci_remove_one,
111119
};
@@ -137,6 +145,7 @@ static struct ata_port_operations vt6421_sata_ops = {
137145
.inherits = &svia_base_ops,
138146
.scr_read = svia_scr_read,
139147
.scr_write = svia_scr_write,
148+
.error_handler = vt6421_error_handler,
140149
};
141150

142151
static struct ata_port_operations vt8251_ops = {
@@ -536,7 +545,36 @@ static int vt8251_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
536545
return 0;
537546
}
538547

539-
static void svia_configure(struct pci_dev *pdev, int board_id)
548+
static void svia_wd_fix(struct pci_dev *pdev)
549+
{
550+
u8 tmp8;
551+
552+
pci_read_config_byte(pdev, 0x52, &tmp8);
553+
pci_write_config_byte(pdev, 0x52, tmp8 | BIT(2));
554+
}
555+
556+
static void vt6421_error_handler(struct ata_port *ap)
557+
{
558+
struct svia_priv *hpriv = ap->host->private_data;
559+
struct pci_dev *pdev = to_pci_dev(ap->host->dev);
560+
u32 serror;
561+
562+
/* see svia_configure() for description */
563+
if (!hpriv->wd_workaround) {
564+
svia_scr_read(&ap->link, SCR_ERROR, &serror);
565+
if (serror == 0x1000500) {
566+
ata_port_warn(ap, "Incompatible drive: enabling workaround. This slows down transfer rate to ~60 MB/s");
567+
svia_wd_fix(pdev);
568+
hpriv->wd_workaround = true;
569+
ap->link.eh_context.i.flags |= ATA_EHI_QUIET;
570+
}
571+
}
572+
573+
ata_sff_error_handler(ap);
574+
}
575+
576+
static void svia_configure(struct pci_dev *pdev, int board_id,
577+
struct svia_priv *hpriv)
540578
{
541579
u8 tmp8;
542580

@@ -593,11 +631,15 @@ static void svia_configure(struct pci_dev *pdev, int board_id)
593631
* https://bugzilla.kernel.org/show_bug.cgi?id=15173
594632
* http://article.gmane.org/gmane.linux.ide/46352
595633
* http://thread.gmane.org/gmane.linux.kernel/1062139
634+
*
635+
* As the fix slows down data transfer, apply it only if the error
636+
* actually appears - see vt6421_error_handler()
637+
* Apply the fix always on vt6420 as we don't know if SCR_ERROR can be
638+
* read safely.
596639
*/
597-
if (board_id == vt6420 || board_id == vt6421) {
598-
pci_read_config_byte(pdev, 0x52, &tmp8);
599-
tmp8 |= 1 << 2;
600-
pci_write_config_byte(pdev, 0x52, tmp8);
640+
if (board_id == vt6420) {
641+
svia_wd_fix(pdev);
642+
hpriv->wd_workaround = true;
601643
}
602644
}
603645

@@ -608,6 +650,7 @@ static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
608650
struct ata_host *host = NULL;
609651
int board_id = (int) ent->driver_data;
610652
const unsigned *bar_sizes;
653+
struct svia_priv *hpriv;
611654

612655
ata_print_version_once(&pdev->dev, DRV_VERSION);
613656

@@ -647,11 +690,35 @@ static int svia_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
647690
if (rc)
648691
return rc;
649692

650-
svia_configure(pdev, board_id);
693+
hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
694+
if (!hpriv)
695+
return -ENOMEM;
696+
host->private_data = hpriv;
697+
698+
svia_configure(pdev, board_id, hpriv);
651699

652700
pci_set_master(pdev);
653701
return ata_host_activate(host, pdev->irq, ata_bmdma_interrupt,
654702
IRQF_SHARED, &svia_sht);
655703
}
656704

705+
#ifdef CONFIG_PM_SLEEP
706+
static int svia_pci_device_resume(struct pci_dev *pdev)
707+
{
708+
struct ata_host *host = pci_get_drvdata(pdev);
709+
struct svia_priv *hpriv = host->private_data;
710+
int rc;
711+
712+
rc = ata_pci_device_do_resume(pdev);
713+
if (rc)
714+
return rc;
715+
716+
if (hpriv->wd_workaround)
717+
svia_wd_fix(pdev);
718+
ata_host_resume(host);
719+
720+
return 0;
721+
}
722+
#endif
723+
657724
module_pci_driver(svia_pci_driver);

0 commit comments

Comments
 (0)