Skip to content

Commit b2cd641

Browse files
author
Linus Torvalds
committed
Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik/libata-dev
* 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik/libata-dev: libata: track spindown status and skip spindown_compat if possible libata: fix shutdown warning message printing libata-acpi: add ATA_FLAG_ACPI_SATA port flag libata: during revalidation, check n_sectors after device is configured libata: separate out ata_dev_reread_id() pata_scc had been missed by ata_std_prereset() switch
2 parents b17bfca + 13b8d09 commit b2cd641

8 files changed

Lines changed: 100 additions & 50 deletions

File tree

‎drivers/ata/ahci.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ enum {
173173

174174
AHCI_FLAG_COMMON = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
175175
ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
176-
ATA_FLAG_SKIP_D2H_BSY,
176+
ATA_FLAG_SKIP_D2H_BSY |
177+
ATA_FLAG_ACPI_SATA,
177178
};
178179

179180
struct ahci_cmd_hdr {

‎drivers/ata/libata-acpi.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static int do_drive_get_GTF(struct ata_device *dev, unsigned int *gtf_length,
321321

322322
/* Don't continue if device has no _ADR method.
323323
* _GTF is intended for known motherboard devices. */
324-
if (!(ap->cbl == ATA_CBL_SATA)) {
324+
if (!(ap->flags & ATA_FLAG_ACPI_SATA)) {
325325
err = pata_get_dev_handle(gdev, &dev_handle, &pcidevfn);
326326
if (err < 0) {
327327
if (ata_msg_probe(ap))
@@ -343,7 +343,7 @@ static int do_drive_get_GTF(struct ata_device *dev, unsigned int *gtf_length,
343343

344344
/* Get this drive's _ADR info. if not already known. */
345345
if (!dev->obj_handle) {
346-
if (!(ap->cbl == ATA_CBL_SATA)) {
346+
if (!(ap->flags & ATA_FLAG_ACPI_SATA)) {
347347
/* get child objects of dev_handle == channel objects,
348348
* + _their_ children == drive objects */
349349
/* channel is ap->port_no */
@@ -528,7 +528,7 @@ static int do_drive_set_taskfiles(struct ata_device *dev,
528528
ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
529529
__FUNCTION__, ap->port_no);
530530

531-
if (libata_noacpi || !(ap->cbl == ATA_CBL_SATA))
531+
if (libata_noacpi || !(ap->flags & ATA_FLAG_ACPI_SATA))
532532
return 0;
533533

534534
if (!ata_dev_enabled(dev) || (ap->flags & ATA_FLAG_DISABLED))
@@ -578,7 +578,7 @@ int ata_acpi_exec_tfs(struct ata_port *ap)
578578
* we should not run GTF on PATA devices since some
579579
* PATA require execution of GTM/STM before GTF.
580580
*/
581-
if (!(ap->cbl == ATA_CBL_SATA))
581+
if (!(ap->flags & ATA_FLAG_ACPI_SATA))
582582
return 0;
583583

584584
for (ix = 0; ix < ATA_MAX_DEVICES; ix++) {
@@ -641,7 +641,7 @@ int ata_acpi_push_id(struct ata_device *dev)
641641
__FUNCTION__, dev->devno, ap->port_no);
642642

643643
/* Don't continue if not a SATA device. */
644-
if (!(ap->cbl == ATA_CBL_SATA)) {
644+
if (!(ap->flags & ATA_FLAG_ACPI_SATA)) {
645645
if (ata_msg_probe(ap))
646646
ata_dev_printk(dev, KERN_DEBUG,
647647
"%s: Not a SATA device\n", __FUNCTION__);

‎drivers/ata/libata-core.c‎

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,6 @@ int ata_dev_configure(struct ata_device *dev)
19191919
snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id));
19201920

19211921
dev->n_sectors = ata_id_n_sectors(id);
1922-
dev->n_sectors_boot = dev->n_sectors;
19231922

19241923
/* SCSI only uses 4-char revisions, dump full 8 chars from ATA */
19251924
ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV,
@@ -3632,7 +3631,6 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
36323631
const u16 *old_id = dev->id;
36333632
unsigned char model[2][ATA_ID_PROD_LEN + 1];
36343633
unsigned char serial[2][ATA_ID_SERNO_LEN + 1];
3635-
u64 new_n_sectors;
36363634

36373635
if (dev->class != new_class) {
36383636
ata_dev_printk(dev, KERN_INFO, "class mismatch %d != %d\n",
@@ -3644,7 +3642,6 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
36443642
ata_id_c_string(new_id, model[1], ATA_ID_PROD, sizeof(model[1]));
36453643
ata_id_c_string(old_id, serial[0], ATA_ID_SERNO, sizeof(serial[0]));
36463644
ata_id_c_string(new_id, serial[1], ATA_ID_SERNO, sizeof(serial[1]));
3647-
new_n_sectors = ata_id_n_sectors(new_id);
36483645

36493646
if (strcmp(model[0], model[1])) {
36503647
ata_dev_printk(dev, KERN_INFO, "model number mismatch "
@@ -3658,25 +3655,12 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
36583655
return 0;
36593656
}
36603657

3661-
if (dev->class == ATA_DEV_ATA && dev->n_sectors != new_n_sectors) {
3662-
ata_dev_printk(dev, KERN_INFO, "n_sectors mismatch "
3663-
"%llu != %llu\n",
3664-
(unsigned long long)dev->n_sectors,
3665-
(unsigned long long)new_n_sectors);
3666-
/* Are we the boot time size - if so we appear to be the
3667-
same disk at this point and our HPA got reapplied */
3668-
if (ata_ignore_hpa && dev->n_sectors_boot == new_n_sectors
3669-
&& ata_id_hpa_enabled(new_id))
3670-
return 1;
3671-
return 0;
3672-
}
3673-
36743658
return 1;
36753659
}
36763660

36773661
/**
3678-
* ata_dev_revalidate - Revalidate ATA device
3679-
* @dev: device to revalidate
3662+
* ata_dev_reread_id - Re-read IDENTIFY data
3663+
* @adev: target ATA device
36803664
* @readid_flags: read ID flags
36813665
*
36823666
* Re-read IDENTIFY page and make sure @dev is still attached to
@@ -3688,34 +3672,68 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
36883672
* RETURNS:
36893673
* 0 on success, negative errno otherwise
36903674
*/
3691-
int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags)
3675+
int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags)
36923676
{
36933677
unsigned int class = dev->class;
36943678
u16 *id = (void *)dev->ap->sector_buf;
36953679
int rc;
36963680

3697-
if (!ata_dev_enabled(dev)) {
3698-
rc = -ENODEV;
3699-
goto fail;
3700-
}
3701-
37023681
/* read ID data */
37033682
rc = ata_dev_read_id(dev, &class, readid_flags, id);
37043683
if (rc)
3705-
goto fail;
3684+
return rc;
37063685

37073686
/* is the device still there? */
3708-
if (!ata_dev_same_device(dev, class, id)) {
3709-
rc = -ENODEV;
3710-
goto fail;
3711-
}
3687+
if (!ata_dev_same_device(dev, class, id))
3688+
return -ENODEV;
37123689

37133690
memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS);
3691+
return 0;
3692+
}
3693+
3694+
/**
3695+
* ata_dev_revalidate - Revalidate ATA device
3696+
* @dev: device to revalidate
3697+
* @readid_flags: read ID flags
3698+
*
3699+
* Re-read IDENTIFY page, make sure @dev is still attached to the
3700+
* port and reconfigure it according to the new IDENTIFY page.
3701+
*
3702+
* LOCKING:
3703+
* Kernel thread context (may sleep)
3704+
*
3705+
* RETURNS:
3706+
* 0 on success, negative errno otherwise
3707+
*/
3708+
int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags)
3709+
{
3710+
u64 n_sectors = dev->n_sectors;
3711+
int rc;
3712+
3713+
if (!ata_dev_enabled(dev))
3714+
return -ENODEV;
3715+
3716+
/* re-read ID */
3717+
rc = ata_dev_reread_id(dev, readid_flags);
3718+
if (rc)
3719+
goto fail;
37143720

37153721
/* configure device according to the new ID */
37163722
rc = ata_dev_configure(dev);
3717-
if (rc == 0)
3718-
return 0;
3723+
if (rc)
3724+
goto fail;
3725+
3726+
/* verify n_sectors hasn't changed */
3727+
if (dev->class == ATA_DEV_ATA && dev->n_sectors != n_sectors) {
3728+
ata_dev_printk(dev, KERN_INFO, "n_sectors mismatch "
3729+
"%llu != %llu\n",
3730+
(unsigned long long)n_sectors,
3731+
(unsigned long long)dev->n_sectors);
3732+
rc = -ENODEV;
3733+
goto fail;
3734+
}
3735+
3736+
return 0;
37193737

37203738
fail:
37213739
ata_dev_printk(dev, KERN_ERR, "revalidation failed (errno=%d)\n", rc);

‎drivers/ata/libata-scsi.c‎

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,23 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
893893
return queue_depth;
894894
}
895895

896+
/* XXX: for ata_spindown_compat */
897+
static void ata_delayed_done_timerfn(unsigned long arg)
898+
{
899+
struct scsi_cmnd *scmd = (void *)arg;
900+
901+
scmd->scsi_done(scmd);
902+
}
903+
904+
/* XXX: for ata_spindown_compat */
905+
static void ata_delayed_done(struct scsi_cmnd *scmd)
906+
{
907+
static struct timer_list timer;
908+
909+
setup_timer(&timer, ata_delayed_done_timerfn, (unsigned long)scmd);
910+
mod_timer(&timer, jiffies + 5 * HZ);
911+
}
912+
896913
/**
897914
* ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
898915
* @qc: Storage for translated ATA taskfile
@@ -950,21 +967,24 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc)
950967
* for more info.
951968
*/
952969
if (ata_spindown_compat &&
970+
(qc->dev->flags & ATA_DFLAG_SPUNDOWN) &&
953971
(system_state == SYSTEM_HALT ||
954972
system_state == SYSTEM_POWER_OFF)) {
955-
static int warned = 0;
973+
static unsigned long warned = 0;
956974

957-
if (!warned) {
958-
spin_unlock_irq(qc->ap->lock);
975+
if (!test_and_set_bit(0, &warned)) {
959976
ata_dev_printk(qc->dev, KERN_WARNING,
960977
"DISK MIGHT NOT BE SPUN DOWN PROPERLY. "
961978
"UPDATE SHUTDOWN UTILITY\n");
962979
ata_dev_printk(qc->dev, KERN_WARNING,
963980
"For more info, visit "
964981
"http://linux-ata.org/shutdown.html\n");
965-
warned = 1;
966-
ssleep(5);
967-
spin_lock_irq(qc->ap->lock);
982+
983+
/* ->scsi_done is not used, use it for
984+
* delayed completion.
985+
*/
986+
scmd->scsi_done = qc->scsidone;
987+
qc->scsidone = ata_delayed_done;
968988
}
969989
scmd->result = SAM_STAT_GOOD;
970990
return 1;
@@ -1375,6 +1395,14 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
13751395
}
13761396
}
13771397

1398+
/* XXX: track spindown state for spindown_compat */
1399+
if (unlikely(qc->tf.command == ATA_CMD_STANDBY ||
1400+
qc->tf.command == ATA_CMD_STANDBYNOW1))
1401+
qc->dev->flags |= ATA_DFLAG_SPUNDOWN;
1402+
else if (likely(system_state != SYSTEM_HALT &&
1403+
system_state != SYSTEM_POWER_OFF))
1404+
qc->dev->flags &= ~ATA_DFLAG_SPUNDOWN;
1405+
13781406
if (need_sense && !ap->ops->error_handler)
13791407
ata_dump_status(ap->print_id, &qc->result_tf);
13801408

@@ -1488,14 +1516,14 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
14881516

14891517
early_finish:
14901518
ata_qc_free(qc);
1491-
done(cmd);
1519+
qc->scsidone(cmd);
14921520
DPRINTK("EXIT - early finish (good or error)\n");
14931521
return 0;
14941522

14951523
err_did:
14961524
ata_qc_free(qc);
14971525
cmd->result = (DID_ERROR << 16);
1498-
done(cmd);
1526+
qc->scsidone(cmd);
14991527
err_mem:
15001528
DPRINTK("EXIT - internal\n");
15011529
return 0;

‎drivers/ata/libata.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ extern unsigned ata_exec_internal_sg(struct ata_device *dev,
7676
extern unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd);
7777
extern int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
7878
unsigned int flags, u16 *id);
79-
extern int ata_dev_revalidate(struct ata_device *dev, unsigned int flags);
79+
extern int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags);
80+
extern int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags);
8081
extern int ata_dev_configure(struct ata_device *dev);
8182
extern int sata_down_spd_limit(struct ata_port *ap);
8283
extern int sata_set_spd_needed(struct ata_port *ap);

‎drivers/ata/pata_scc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,10 +864,10 @@ static void scc_bmdma_freeze (struct ata_port *ap)
864864
* @ap: ATA port to be reset
865865
*/
866866

867-
static int scc_pata_prereset (struct ata_port *ap)
867+
static int scc_pata_prereset (struct ata_port *ap, unsigned long deadline)
868868
{
869869
ap->cbl = ATA_CBL_PATA80;
870-
return ata_std_prereset(ap);
870+
return ata_std_prereset(ap, deadline);
871871
}
872872

873873
/**

‎drivers/ata/sata_sil24.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ enum {
237237
/* host flags */
238238
SIL24_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
239239
ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
240-
ATA_FLAG_NCQ | ATA_FLAG_SKIP_D2H_BSY,
240+
ATA_FLAG_NCQ | ATA_FLAG_SKIP_D2H_BSY |
241+
ATA_FLAG_ACPI_SATA,
241242
SIL24_FLAG_PCIX_IRQ_WOC = (1 << 24), /* IRQ loss errata on PCI-X */
242243

243244
IRQ_STAT_4PORTS = 0xf,

‎include/linux/libata.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ enum {
140140

141141
ATA_DFLAG_PIO = (1 << 8), /* device limited to PIO mode */
142142
ATA_DFLAG_NCQ_OFF = (1 << 9), /* device limited to non-NCQ mode */
143+
ATA_DFLAG_SPUNDOWN = (1 << 10), /* XXX: for spindown_compat */
143144
ATA_DFLAG_INIT_MASK = (1 << 16) - 1,
144145

145146
ATA_DFLAG_DETACH = (1 << 16),
@@ -173,6 +174,7 @@ enum {
173174
ATA_FLAG_SETXFER_POLLING= (1 << 14), /* use polling for SETXFER */
174175
ATA_FLAG_IGN_SIMPLEX = (1 << 15), /* ignore SIMPLEX */
175176
ATA_FLAG_NO_IORDY = (1 << 16), /* controller lacks iordy */
177+
ATA_FLAG_ACPI_SATA = (1 << 17), /* need native SATA ACPI layout */
176178

177179
/* The following flag belongs to ap->pflags but is kept in
178180
* ap->flags because it's referenced in many LLDs and will be
@@ -431,7 +433,6 @@ struct ata_device {
431433
struct scsi_device *sdev; /* attached SCSI device */
432434
/* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */
433435
u64 n_sectors; /* size of device, if ATA */
434-
u64 n_sectors_boot; /* size of ATA device at startup */
435436
unsigned int class; /* ATA_DEV_xxx */
436437
u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
437438
u8 pio_mode;

0 commit comments

Comments
 (0)