linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Gordeev <agordeev@redhat.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>,
	linux-ide@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH 3/7] ahci: Use new interfaces for MSI/MSI-X enablement
Date: Tue, 14 Jan 2014 09:50:40 +0100	[thread overview]
Message-ID: <20140114085040.GA6873@dhcp-26-207.brq.redhat.com> (raw)
In-Reply-To: <20140113191220.GA6525@google.com>

On Mon, Jan 13, 2014 at 12:12:20PM -0700, Bjorn Helgaas wrote:
> > -	nvec = rc;
> > -	rc = pci_enable_msi_block(pdev, nvec);
> > -	if (rc)
> > +	if (pci_enable_msi_range(pdev, nvec, nvec) < 0)
> >  		goto intx;
> >  
> >  	return nvec;
> >  
> >  single_msi:
> > -	rc = pci_enable_msi(pdev);
> > -	if (rc)
> > +	if (pci_enable_msi_range(pdev, 1, 1) < 0)
> 
> This part doesn't seem like an improvement.  There are a hundred or so
> callers of pci_enable_msi() that only want a single MSI.  Is there any
> benefit in changing them to use pci_enable_msi_range()?

In this particular case it reads better to me as one sees on the screen
pci_enable_msi_range(pdev, nvec, nvec) and pci_enable_msi_range(pdev, 1, 1)
calls. That allows to avoid switching in mind between negative-or-positive
return in the former call and negative-or-zero return from pci_enable_msi()
if we had it.

But in most cases when single MSI is enabled we do cause complication
with the patterns below (which I expect I am going be hated for ;) ):


-	rc = pci_enable_msi(pdev);
-	if (rc)
+	rc = pci_enable_msi_range(pdev, 1, 1);
+	if (rc < 0)
		...


-	rc = pci_enable_msi(pdev);
-	if (!rc)
+	rc = pci_enable_msi_range(pdev, 1, 1);
+	if (rc > 0)
		...

 
I think we have a tradeoff between the interface simplicity and code clarity.
What if we try to address both goals by making pci_enable_msi() a helper over
pci_enable_msi_range(pdev, 1, 1)? In this case the return value will match
negative-or-positive binary semantics while reads almost as good as it used to:


-	rc = pci_enable_msi(pdev);
-	if (rc)
+	rc = pci_enable_msi(pdev);
+	if (rc < 0)
		...


-	rc = pci_enable_msi(pdev);
-	if (!rc)
+	rc = pci_enable_msi(pdev);
+	if (rc > 0)
		...


The whole interface would not be inflated as well, with just:

diff --git a/Documentation/PCI/MSI-HOWTO.txt b/Documentation/PCI/MSI-HOWTO.txt
index a8d0100..fa0b27d 100644
--- a/Documentation/PCI/MSI-HOWTO.txt
+++ b/Documentation/PCI/MSI-HOWTO.txt
@@ -158,6 +158,9 @@ static int foo_driver_enable_single_msi(struct pci_dev *pdev)
 	return pci_enable_msi_range(pdev, 1, 1);
 }
 
+A helper function pci_enable_msi() could be used instead. Note, as just
+one MSI is requested it could return either a negative errno or 1.
+
 4.2.2 pci_disable_msi
 
 void pci_disable_msi(struct pci_dev *dev)


-- 
Regards,
Alexander Gordeev
agordeev@redhat.com

  reply	other threads:[~2014-01-14  8:48 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-07 18:05 [PATCH 0/7] Phase out pci_enable_msi_block() Alexander Gordeev
2014-01-07 18:05 ` [PATCH 1/7] ipr: Do not call pci_disable_msi/msix() if pci_enable_msi/msix() failed Alexander Gordeev
2014-01-07 18:05 ` [PATCH 2/7] ipr: Use new interfaces for MSI/MSI-X enablement Alexander Gordeev
2014-01-07 18:05 ` [PATCH 3/7] ahci: " Alexander Gordeev
2014-01-13 19:12   ` Bjorn Helgaas
2014-01-14  8:50     ` Alexander Gordeev [this message]
2014-01-14  8:54       ` Alexander Gordeev
2014-01-14 17:31       ` Bjorn Helgaas
2014-01-07 18:05 ` [PATCH 4/7] nvme: " Alexander Gordeev
2014-01-07 18:05 ` [PATCH 5/7] vfio: " Alexander Gordeev
2014-01-07 18:34   ` Alex Williamson
2014-01-08  7:42     ` Alexander Gordeev
2014-01-08  7:57       ` [PATCH v2 " Alexander Gordeev
2014-01-08 13:45         ` Alex Williamson
2014-01-10  7:42           ` [PATCH v3 " Alexander Gordeev
2014-01-10 15:45             ` Alex Williamson
2014-01-07 18:05 ` [PATCH 6/7] ath10k: Use new interfaces for MSI enablement Alexander Gordeev
2014-01-08  8:23   ` Kalle Valo
2014-01-08  9:04     ` Alexander Gordeev
2014-01-08 12:44       ` Kalle Valo
2014-01-07 18:05 ` [PATCH 7/7] wil6210: " Alexander Gordeev
2014-01-08 11:30   ` Vladimir Kondratiev
2014-01-08 11:54     ` Alexander Gordeev
2014-01-08 12:19       ` Vladimir Kondratiev
2014-01-08 12:34         ` Alexander Gordeev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140114085040.GA6873@dhcp-26-207.brq.redhat.com \
    --to=agordeev@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).