From patchwork Mon Jul 23 06:49:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 172552 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 A0F682C0347 for ; Mon, 23 Jul 2012 16:52:00 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753289Ab2GWGvY (ORCPT ); Mon, 23 Jul 2012 02:51:24 -0400 Received: from co1ehsobe004.messaging.microsoft.com ([216.32.180.187]:36729 "EHLO co1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753050Ab2GWGu7 (ORCPT ); Mon, 23 Jul 2012 02:50:59 -0400 Received: from mail91-co1-R.bigfish.com (10.243.78.228) by CO1EHSOBE010.bigfish.com (10.243.66.73) with Microsoft SMTP Server id 14.1.225.23; Mon, 23 Jul 2012 06:50:58 +0000 Received: from mail91-co1 (localhost [127.0.0.1]) by mail91-co1-R.bigfish.com (Postfix) with ESMTP id 0FA909801C3; Mon, 23 Jul 2012 06:50:58 +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 mail91-co1 (localhost.localdomain [127.0.0.1]) by mail91-co1 (MessageSwitch) id 1343026256167376_14155; Mon, 23 Jul 2012 06:50:56 +0000 (UTC) Received: from CO1EHSMHS014.bigfish.com (unknown [10.243.78.238]) by mail91-co1.bigfish.com (Postfix) with ESMTP id 265CC2004A; Mon, 23 Jul 2012 06:50:56 +0000 (UTC) Received: from ausb3twp02.amd.com (163.181.249.109) by CO1EHSMHS014.bigfish.com (10.243.66.24) with Microsoft SMTP Server id 14.1.225.23; Mon, 23 Jul 2012 06:50:56 +0000 X-WSS-ID: 0M7LPOT-02-5HT-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 22993C8147; Mon, 23 Jul 2012 01:50:53 -0500 (CDT) Received: from sausexhtp01.amd.com (163.181.3.165) by sausexedgep01.amd.com (163.181.36.54) with Microsoft SMTP Server (TLS) id 8.3.192.1; Mon, 23 Jul 2012 01:50:57 -0500 Received: from sausexmb1.amd.com (163.181.3.156) by sausexhtp01.amd.com (163.181.3.165) with Microsoft SMTP Server id 8.3.213.0; Mon, 23 Jul 2012 01:50:52 -0500 Received: from storexbh1.amd.com ([10.1.1.17]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 23 Jul 2012 01:50:53 -0500 Received: from sshaexmb1.amd.com ([10.237.2.11]) by storexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 23 Jul 2012 02:50:51 -0400 Received: from srdclcs1.amd.com ([10.237.73.42]) by sshaexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 23 Jul 2012 14:50:39 +0800 From: Aaron Lu To: Jeff Garzik , Alan Stern , Lin Ming CC: , , , , Aaron Lu , Aaron Lu Subject: [PATCH 4/5] scsi: pm: use runtime resume callback if available Date: Mon, 23 Jul 2012 14:49:39 +0800 Message-ID: <1343026180-22236-5-git-send-email-aaron.lu@amd.com> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <1343026180-22236-1-git-send-email-aaron.lu@amd.com> References: <1343026180-22236-1-git-send-email-aaron.lu@amd.com> X-OriginalArrivalTime: 23 Jul 2012 06:50:39.0342 (UTC) FILETIME=[7871B8E0:01CD689F] 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 --- drivers/scsi/scsi_pm.c | 14 +++++++++----- drivers/scsi/sr.c | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index d4201de..19bba47 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c @@ -34,14 +34,18 @@ 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; + err = resume(dev); scsi_device_resume(to_scsi_device(dev)); dev_dbg(dev, "scsi resume: %d\n", err); return err; @@ -84,7 +88,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 +163,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 69c9e22..2f159aa 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, }; @@ -215,6 +221,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;