From patchwork Fri Oct 15 20:06:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barnes X-Patchwork-Id: 257561 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9FK6nH4027649 for ; Fri, 15 Oct 2010 20:06:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756796Ab0JOUGs (ORCPT ); Fri, 15 Oct 2010 16:06:48 -0400 Received: from cpoproxy1-pub.bluehost.com ([69.89.21.11]:41981 "HELO cpoproxy1-pub.bluehost.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1756608Ab0JOUGr convert rfc822-to-8bit (ORCPT ); Fri, 15 Oct 2010 16:06:47 -0400 Received: (qmail 30436 invoked by uid 0); 15 Oct 2010 20:06:47 -0000 Received: from unknown (HELO box514.bluehost.com) (74.220.219.114) by cpoproxy1.bluehost.com with SMTP; 15 Oct 2010 20:06:47 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=virtuousgeek.org; h=Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer:Mime-Version:Content-Type:Content-Transfer-Encoding:X-Identified-User; b=mFO9Vu+/kLNbrfdx64DAQDPWA8InAA271zUZbO9acmBaHYbzDp+nJFmWJZhaGl6V9TNjCR/iXynX/O33R0QUWVJPFHDKH3RWYV+xgptLRR/790NhjY4+U3Eu/K/s7nWJ; Received: from c-67-174-193-198.hsd1.ca.comcast.net ([67.174.193.198] helo=jbarnes-desktop) by box514.bluehost.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1P6qYA-0008MO-Vs; Fri, 15 Oct 2010 14:06:47 -0600 Date: Fri, 15 Oct 2010 13:06:29 -0700 From: Jesse Barnes To: Emil S Tantilov Cc: Ben Hutchings , Michael Chan , Matthew Wilcox , linux-pci@vger.kernel.org, NetDev , "Tantilov, Emil S" , Jesse Brandeburg , "Kirsher, Jeffrey T" Subject: Re: [PATCH] PCI: MSI: Remove unsafe and unnecessary hardware access Message-ID: <20101015130629.046d3357@jbarnes-desktop> In-Reply-To: References: <1276564403.19104.28.camel@HP1> <1276802196.2083.12.camel@achroite.uk.solarflarecom.com> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.18.9; x86_64-redhat-linux-gnu) Mime-Version: 1.0 X-Identified-User: {10642:box514.bluehost.com:virtuous:virtuousgeek.org} {sentby:smtp auth 67.174.193.198 authed with jbarnes@virtuousgeek.org} Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 15 Oct 2010 20:06:51 +0000 (UTC) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7fa3cbd..37facc1 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -994,6 +994,18 @@ static int __pci_enable_device_flags(struct pci_dev *dev, int err; int i, bars = 0; + /* + * Power state could be unknown at this point, either due to a fresh + * boot or a device removal call. So get the current power state + * so that things like MSI message writing will behave as expected + * (e.g. if the device really is in D0 at enable time). + */ + if (dev->pm_cap) { + u16 pmcsr; + pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); + dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); + } + if (atomic_add_return(1, &dev->enable_cnt) > 1) return 0; /* already enabled */