From patchwork Tue Jul 24 09:37:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 172813 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 78B812C0125 for ; Tue, 24 Jul 2012 19:41:16 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752791Ab2GXJjt (ORCPT ); Tue, 24 Jul 2012 05:39:49 -0400 Received: from co1ehsobe001.messaging.microsoft.com ([216.32.180.184]:35292 "EHLO co1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752622Ab2GXJjp (ORCPT ); Tue, 24 Jul 2012 05:39:45 -0400 Received: from mail21-co1-R.bigfish.com (10.243.78.248) by CO1EHSOBE011.bigfish.com (10.243.66.74) with Microsoft SMTP Server id 14.1.225.23; Tue, 24 Jul 2012 09:39:45 +0000 Received: from mail21-co1 (localhost [127.0.0.1]) by mail21-co1-R.bigfish.com (Postfix) with ESMTP id 2FFA3A40130; Tue, 24 Jul 2012 09:39:45 +0000 (UTC) X-Forefront-Antispam-Report: CIP:163.181.249.109; KIP:(null); UIP:(null); IPV:NLI; H:ausb3twp02.amd.com; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VPS0(zzzz1202hzz8275bhz2dh668h839hd24he5bhf0ah107ah) Received: from mail21-co1 (localhost.localdomain [127.0.0.1]) by mail21-co1 (MessageSwitch) id 1343122783523418_11666; Tue, 24 Jul 2012 09:39:43 +0000 (UTC) Received: from CO1EHSMHS009.bigfish.com (unknown [10.243.78.246]) by mail21-co1.bigfish.com (Postfix) with ESMTP id 7CEE314004C; Tue, 24 Jul 2012 09:39:43 +0000 (UTC) Received: from ausb3twp02.amd.com (163.181.249.109) by CO1EHSMHS009.bigfish.com (10.243.66.19) with Microsoft SMTP Server id 14.1.225.23; Tue, 24 Jul 2012 09:39:43 +0000 X-WSS-ID: 0M7NS64-02-1NJ-02 X-M-MSG: Received: from sausexedgep01.amd.com (sausexedgep01-ext.amd.com [163.181.249.72]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp02.amd.com (Axway MailGate 3.8.1) with ESMTP id 28D10FCC009; Tue, 24 Jul 2012 04:39:39 -0500 (CDT) Received: from sausexhtp02.amd.com (163.181.3.152) by sausexedgep01.amd.com (163.181.36.54) with Microsoft SMTP Server (TLS) id 8.3.192.1; Tue, 24 Jul 2012 04:39:48 -0500 Received: from sausexmb1.amd.com (163.181.3.156) by sausexhtp02.amd.com (163.181.3.152) with Microsoft SMTP Server id 8.3.213.0; Tue, 24 Jul 2012 04:39:40 -0500 Received: from storexbh1.amd.com ([10.1.1.17]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 24 Jul 2012 04:39:40 -0500 Received: from sshaexmb1.amd.com ([10.237.2.11]) by storexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 24 Jul 2012 05:39:38 -0400 Received: from srdclcs1.amd.com ([10.237.73.42]) by sshaexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 24 Jul 2012 17:39:30 +0800 From: Aaron Lu To: Jeff Garzik , Alan Stern , Lin Ming , James Bottomley , Jeff Wu CC: , , , , Aaron Lu , Aaron Lu Subject: [PATCH v2 6/7] scsi: pm: use runtime resume callback if available Date: Tue, 24 Jul 2012 17:37:44 +0800 Message-ID: <1343122665-18711-7-git-send-email-aaron.lu@amd.com> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <1343122665-18711-1-git-send-email-aaron.lu@amd.com> References: <1343122665-18711-1-git-send-email-aaron.lu@amd.com> X-OriginalArrivalTime: 24 Jul 2012 09:39:30.0742 (UTC) FILETIME=[39A46D60:01CD6980] MIME-Version: 1.0 X-OriginatorOrg: amd.com Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org When runtime resume a scsi device, if the device's driver has implemented runtime resume callback, use that instead of the resume callback. sr driver needs this to properly do different things for system resume and runtime resume. Signed-off-by: Aaron Lu --- V2: Check if the resume callback is NULL before calling it as pointed by Sergei Shtylyov. drivers/scsi/scsi_pm.c | 15 ++++++++++----- drivers/scsi/sr.c | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index a002fbf..717d2c1 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c @@ -34,14 +34,19 @@ static int scsi_dev_type_suspend(struct device *dev, pm_message_t msg) return err; } -static int scsi_dev_type_resume(struct device *dev) +static int scsi_dev_type_resume(struct device *dev, bool runtime) { struct device_driver *drv; int err = 0; + int (*resume)(struct device *); drv = dev->driver; - if (drv && drv->resume) - err = drv->resume(dev); + if (runtime && drv && drv->pm && drv->pm->runtime_resume) + resume = drv->pm->runtime_resume; + else + resume = drv ? drv->resume : NULL; + if (resume) + err = resume(dev); scsi_device_resume(to_scsi_device(dev)); dev_dbg(dev, "scsi resume: %d\n", err); return err; @@ -84,7 +89,7 @@ static int scsi_bus_resume_common(struct device *dev) * Resume it on behalf of child. */ pm_runtime_get_sync(dev->parent); - err = scsi_dev_type_resume(dev); + err = scsi_dev_type_resume(dev, false); pm_runtime_put_sync(dev->parent); } @@ -159,7 +164,7 @@ static int scsi_runtime_resume(struct device *dev) dev_dbg(dev, "scsi_runtime_resume\n"); if (scsi_is_sdev_device(dev)) - err = scsi_dev_type_resume(dev); + err = scsi_dev_type_resume(dev, true); /* Insert hooks here for targets, hosts, and transport classes */ diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index d6c0574..466ff8e 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -82,6 +82,11 @@ static int sr_remove(struct device *); static int sr_done(struct scsi_cmnd *); static int sr_suspend(struct device *dev, pm_message_t msg); static int sr_resume(struct device *dev); +static int sr_runtime_resume(struct device *dev); + +static struct dev_pm_ops sr_pm_ops = { + .runtime_resume = sr_runtime_resume, +}; static struct scsi_driver sr_template = { .owner = THIS_MODULE, @@ -91,6 +96,7 @@ static struct scsi_driver sr_template = { .remove = sr_remove, .suspend = sr_suspend, .resume = sr_resume, + .pm = &sr_pm_ops, }, .done = sr_done, }; @@ -211,6 +217,21 @@ static int sr_suspend(struct device *dev, pm_message_t msg) static int sr_resume(struct device *dev) { + struct scsi_cd *cd = dev_get_drvdata(dev); + + /* + * If ODD is runtime suspended before system pm, unblock disk + * events now since on system resume, we will fully resume it + * and set its rumtime status to active. + */ + if (pm_runtime_suspended(dev)) + disk_unblock_events(cd->disk); + + return 0; +} + +static int sr_runtime_resume(struct device *dev) +{ struct scsi_cd *cd; struct scsi_sense_hdr sshdr;