mirror of
https://github.com/torvalds/linux.git
synced 2024-11-11 06:31:49 +00:00
e2c5923c34
Pull core block layer updates from Jens Axboe: "This is the main pull request for block storage for 4.15-rc1. Nothing out of the ordinary in here, and no API changes or anything like that. Just various new features for drivers, core changes, etc. In particular, this pull request contains: - A patch series from Bart, closing the whole on blk/scsi-mq queue quescing. - A series from Christoph, building towards hidden gendisks (for multipath) and ability to move bio chains around. - NVMe - Support for native multipath for NVMe (Christoph). - Userspace notifications for AENs (Keith). - Command side-effects support (Keith). - SGL support (Chaitanya Kulkarni) - FC fixes and improvements (James Smart) - Lots of fixes and tweaks (Various) - bcache - New maintainer (Michael Lyle) - Writeback control improvements (Michael) - Various fixes (Coly, Elena, Eric, Liang, et al) - lightnvm updates, mostly centered around the pblk interface (Javier, Hans, and Rakesh). - Removal of unused bio/bvec kmap atomic interfaces (me, Christoph) - Writeback series that fix the much discussed hundreds of millions of sync-all units. This goes all the way, as discussed previously (me). - Fix for missing wakeup on writeback timer adjustments (Yafang Shao). - Fix laptop mode on blk-mq (me). - {mq,name} tupple lookup for IO schedulers, allowing us to have alias names. This means you can use 'deadline' on both !mq and on mq (where it's called mq-deadline). (me). - blktrace race fix, oopsing on sg load (me). - blk-mq optimizations (me). - Obscure waitqueue race fix for kyber (Omar). - NBD fixes (Josef). - Disable writeback throttling by default on bfq, like we do on cfq (Luca Miccio). - Series from Ming that enable us to treat flush requests on blk-mq like any other request. This is a really nice cleanup. - Series from Ming that improves merging on blk-mq with schedulers, getting us closer to flipping the switch on scsi-mq again. - BFQ updates (Paolo). - blk-mq atomic flags memory ordering fixes (Peter Z). - Loop cgroup support (Shaohua). - Lots of minor fixes from lots of different folks, both for core and driver code" * 'for-4.15/block' of git://git.kernel.dk/linux-block: (294 commits) nvme: fix visibility of "uuid" ns attribute blk-mq: fixup some comment typos and lengths ide: ide-atapi: fix compile error with defining macro DEBUG blk-mq: improve tag waiting setup for non-shared tags brd: remove unused brd_mutex blk-mq: only run the hardware queue if IO is pending block: avoid null pointer dereference on null disk fs: guard_bio_eod() needs to consider partitions xtensa/simdisk: fix compile error nvme: expose subsys attribute to sysfs nvme: create 'slaves' and 'holders' entries for hidden controllers block: create 'slaves' and 'holders' entries for hidden gendisks nvme: also expose the namespace identification sysfs files for mpath nodes nvme: implement multipath access to nvme subsystems nvme: track shared namespaces nvme: introduce a nvme_ns_ids structure nvme: track subsystems block, nvme: Introduce blk_mq_req_flags_t block, scsi: Make SCSI quiesce and resume work reliably block: Add the QUEUE_FLAG_PREEMPT_ONLY request queue flag ...
283 lines
7.3 KiB
C
283 lines
7.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/kernel.h>
|
|
#include <linux/gfp.h>
|
|
#include <linux/ide.h>
|
|
|
|
int generic_ide_suspend(struct device *dev, pm_message_t mesg)
|
|
{
|
|
ide_drive_t *drive = to_ide_device(dev);
|
|
ide_drive_t *pair = ide_get_pair_dev(drive);
|
|
ide_hwif_t *hwif = drive->hwif;
|
|
struct request *rq;
|
|
struct ide_pm_state rqpm;
|
|
int ret;
|
|
|
|
if (ide_port_acpi(hwif)) {
|
|
/* call ACPI _GTM only once */
|
|
if ((drive->dn & 1) == 0 || pair == NULL)
|
|
ide_acpi_get_timing(hwif);
|
|
}
|
|
|
|
memset(&rqpm, 0, sizeof(rqpm));
|
|
rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM);
|
|
ide_req(rq)->type = ATA_PRIV_PM_SUSPEND;
|
|
rq->special = &rqpm;
|
|
rqpm.pm_step = IDE_PM_START_SUSPEND;
|
|
if (mesg.event == PM_EVENT_PRETHAW)
|
|
mesg.event = PM_EVENT_FREEZE;
|
|
rqpm.pm_state = mesg.event;
|
|
|
|
blk_execute_rq(drive->queue, NULL, rq, 0);
|
|
ret = scsi_req(rq)->result ? -EIO : 0;
|
|
blk_put_request(rq);
|
|
|
|
if (ret == 0 && ide_port_acpi(hwif)) {
|
|
/* call ACPI _PS3 only after both devices are suspended */
|
|
if ((drive->dn & 1) || pair == NULL)
|
|
ide_acpi_set_state(hwif, 0);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void ide_end_sync_rq(struct request *rq, blk_status_t error)
|
|
{
|
|
complete(rq->end_io_data);
|
|
}
|
|
|
|
static int ide_pm_execute_rq(struct request *rq)
|
|
{
|
|
struct request_queue *q = rq->q;
|
|
DECLARE_COMPLETION_ONSTACK(wait);
|
|
|
|
rq->end_io_data = &wait;
|
|
rq->end_io = ide_end_sync_rq;
|
|
|
|
spin_lock_irq(q->queue_lock);
|
|
if (unlikely(blk_queue_dying(q))) {
|
|
rq->rq_flags |= RQF_QUIET;
|
|
scsi_req(rq)->result = -ENXIO;
|
|
__blk_end_request_all(rq, BLK_STS_OK);
|
|
spin_unlock_irq(q->queue_lock);
|
|
return -ENXIO;
|
|
}
|
|
__elv_add_request(q, rq, ELEVATOR_INSERT_FRONT);
|
|
__blk_run_queue_uncond(q);
|
|
spin_unlock_irq(q->queue_lock);
|
|
|
|
wait_for_completion_io(&wait);
|
|
|
|
return scsi_req(rq)->result ? -EIO : 0;
|
|
}
|
|
|
|
int generic_ide_resume(struct device *dev)
|
|
{
|
|
ide_drive_t *drive = to_ide_device(dev);
|
|
ide_drive_t *pair = ide_get_pair_dev(drive);
|
|
ide_hwif_t *hwif = drive->hwif;
|
|
struct request *rq;
|
|
struct ide_pm_state rqpm;
|
|
int err;
|
|
|
|
if (ide_port_acpi(hwif)) {
|
|
/* call ACPI _PS0 / _STM only once */
|
|
if ((drive->dn & 1) == 0 || pair == NULL) {
|
|
ide_acpi_set_state(hwif, 1);
|
|
ide_acpi_push_timing(hwif);
|
|
}
|
|
|
|
ide_acpi_exec_tfs(drive);
|
|
}
|
|
|
|
memset(&rqpm, 0, sizeof(rqpm));
|
|
rq = blk_get_request_flags(drive->queue, REQ_OP_DRV_IN,
|
|
BLK_MQ_REQ_PREEMPT);
|
|
ide_req(rq)->type = ATA_PRIV_PM_RESUME;
|
|
rq->special = &rqpm;
|
|
rqpm.pm_step = IDE_PM_START_RESUME;
|
|
rqpm.pm_state = PM_EVENT_ON;
|
|
|
|
err = ide_pm_execute_rq(rq);
|
|
blk_put_request(rq);
|
|
|
|
if (err == 0 && dev->driver) {
|
|
struct ide_driver *drv = to_ide_driver(dev->driver);
|
|
|
|
if (drv->resume)
|
|
drv->resume(drive);
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
|
|
{
|
|
struct ide_pm_state *pm = rq->special;
|
|
|
|
#ifdef DEBUG_PM
|
|
printk(KERN_INFO "%s: complete_power_step(step: %d)\n",
|
|
drive->name, pm->pm_step);
|
|
#endif
|
|
if (drive->media != ide_disk)
|
|
return;
|
|
|
|
switch (pm->pm_step) {
|
|
case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
|
|
if (pm->pm_state == PM_EVENT_FREEZE)
|
|
pm->pm_step = IDE_PM_COMPLETED;
|
|
else
|
|
pm->pm_step = IDE_PM_STANDBY;
|
|
break;
|
|
case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
|
|
pm->pm_step = IDE_PM_COMPLETED;
|
|
break;
|
|
case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
|
|
pm->pm_step = IDE_PM_IDLE;
|
|
break;
|
|
case IDE_PM_IDLE: /* Resume step 2 (idle)*/
|
|
pm->pm_step = IDE_PM_RESTORE_DMA;
|
|
break;
|
|
}
|
|
}
|
|
|
|
ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
|
|
{
|
|
struct ide_pm_state *pm = rq->special;
|
|
struct ide_cmd cmd = { };
|
|
|
|
switch (pm->pm_step) {
|
|
case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
|
|
if (drive->media != ide_disk)
|
|
break;
|
|
/* Not supported? Switch to next step now. */
|
|
if (ata_id_flush_enabled(drive->id) == 0 ||
|
|
(drive->dev_flags & IDE_DFLAG_WCACHE) == 0) {
|
|
ide_complete_power_step(drive, rq);
|
|
return ide_stopped;
|
|
}
|
|
if (ata_id_flush_ext_enabled(drive->id))
|
|
cmd.tf.command = ATA_CMD_FLUSH_EXT;
|
|
else
|
|
cmd.tf.command = ATA_CMD_FLUSH;
|
|
goto out_do_tf;
|
|
case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
|
|
cmd.tf.command = ATA_CMD_STANDBYNOW1;
|
|
goto out_do_tf;
|
|
case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
|
|
ide_set_max_pio(drive);
|
|
/*
|
|
* skip IDE_PM_IDLE for ATAPI devices
|
|
*/
|
|
if (drive->media != ide_disk)
|
|
pm->pm_step = IDE_PM_RESTORE_DMA;
|
|
else
|
|
ide_complete_power_step(drive, rq);
|
|
return ide_stopped;
|
|
case IDE_PM_IDLE: /* Resume step 2 (idle) */
|
|
cmd.tf.command = ATA_CMD_IDLEIMMEDIATE;
|
|
goto out_do_tf;
|
|
case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */
|
|
/*
|
|
* Right now, all we do is call ide_set_dma(drive),
|
|
* we could be smarter and check for current xfer_speed
|
|
* in struct drive etc...
|
|
*/
|
|
if (drive->hwif->dma_ops == NULL)
|
|
break;
|
|
/*
|
|
* TODO: respect IDE_DFLAG_USING_DMA
|
|
*/
|
|
ide_set_dma(drive);
|
|
break;
|
|
}
|
|
|
|
pm->pm_step = IDE_PM_COMPLETED;
|
|
|
|
return ide_stopped;
|
|
|
|
out_do_tf:
|
|
cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
|
|
cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
|
|
cmd.protocol = ATA_PROT_NODATA;
|
|
|
|
return do_rw_taskfile(drive, &cmd);
|
|
}
|
|
|
|
/**
|
|
* ide_complete_pm_rq - end the current Power Management request
|
|
* @drive: target drive
|
|
* @rq: request
|
|
*
|
|
* This function cleans up the current PM request and stops the queue
|
|
* if necessary.
|
|
*/
|
|
void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq)
|
|
{
|
|
struct request_queue *q = drive->queue;
|
|
struct ide_pm_state *pm = rq->special;
|
|
unsigned long flags;
|
|
|
|
ide_complete_power_step(drive, rq);
|
|
if (pm->pm_step != IDE_PM_COMPLETED)
|
|
return;
|
|
|
|
#ifdef DEBUG_PM
|
|
printk("%s: completing PM request, %s\n", drive->name,
|
|
(ide_req(rq)->type == ATA_PRIV_PM_SUSPEND) ? "suspend" : "resume");
|
|
#endif
|
|
spin_lock_irqsave(q->queue_lock, flags);
|
|
if (ide_req(rq)->type == ATA_PRIV_PM_SUSPEND)
|
|
blk_stop_queue(q);
|
|
else
|
|
drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
|
|
spin_unlock_irqrestore(q->queue_lock, flags);
|
|
|
|
drive->hwif->rq = NULL;
|
|
|
|
if (blk_end_request(rq, BLK_STS_OK, 0))
|
|
BUG();
|
|
}
|
|
|
|
void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
|
|
{
|
|
struct ide_pm_state *pm = rq->special;
|
|
|
|
if (blk_rq_is_private(rq) &&
|
|
ide_req(rq)->type == ATA_PRIV_PM_SUSPEND &&
|
|
pm->pm_step == IDE_PM_START_SUSPEND)
|
|
/* Mark drive blocked when starting the suspend sequence. */
|
|
drive->dev_flags |= IDE_DFLAG_BLOCKED;
|
|
else if (blk_rq_is_private(rq) &&
|
|
ide_req(rq)->type == ATA_PRIV_PM_RESUME &&
|
|
pm->pm_step == IDE_PM_START_RESUME) {
|
|
/*
|
|
* The first thing we do on wakeup is to wait for BSY bit to
|
|
* go away (with a looong timeout) as a drive on this hwif may
|
|
* just be POSTing itself.
|
|
* We do that before even selecting as the "other" device on
|
|
* the bus may be broken enough to walk on our toes at this
|
|
* point.
|
|
*/
|
|
ide_hwif_t *hwif = drive->hwif;
|
|
const struct ide_tp_ops *tp_ops = hwif->tp_ops;
|
|
struct request_queue *q = drive->queue;
|
|
unsigned long flags;
|
|
int rc;
|
|
#ifdef DEBUG_PM
|
|
printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name);
|
|
#endif
|
|
rc = ide_wait_not_busy(hwif, 35000);
|
|
if (rc)
|
|
printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);
|
|
tp_ops->dev_select(drive);
|
|
tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
|
|
rc = ide_wait_not_busy(hwif, 100000);
|
|
if (rc)
|
|
printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
|
|
|
|
spin_lock_irqsave(q->queue_lock, flags);
|
|
blk_start_queue(q);
|
|
spin_unlock_irqrestore(q->queue_lock, flags);
|
|
}
|
|
}
|