linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: willy@linux.intel.com (Matthew Wilcox)
Subject: [PATCH] NVMe: handle ioremap failure
Date: Mon, 1 Jul 2013 17:00:16 -0400	[thread overview]
Message-ID: <20130701210016.GB30142@linux.intel.com> (raw)
In-Reply-To: <1372695820-30841-1-git-send-email-keith.busch@intel.com>

On Mon, Jul 01, 2013@10:23:40AM -0600, Keith Busch wrote:
> Decrement the number of queues required for doorbell remapping until
> the memory is successfully mapped for that size.

Cool, thanks!

> -		dev->bar = ioremap(pci_resource_start(pdev, 0), db_bar_size);
> +		while (nr_io_queues > 0) {
> +			dev->bar = ioremap(pci_resource_start(pdev, 0), db_bar_size);
*cough* *checkpatch* *line length*
> +			if (!dev->bar)
> +				nr_io_queues--;
> +			else
> +				break;

I think this might more naturally be written as:

			dev->bar = ioremap(pci_resource_start(pdev, 0),
								db_bar_size);
			if (dev->bar)
				break;

			nr_io_queues--;
> +			db_bar_size = 4096 + ((nr_io_queues + 1) << (dev->db_stride + 3));
> +		}
> +		if (!dev->bar)
> +			return -ENOMEM;
> +

Although maybe we should instead redo the entire thing as ...

static size_t db_bar_size(struct nvme_dev *dev, unsigned nr_io_queues)
{
	return 4096 + ((nr_io_queues + 1) << (dev->db_stride + 3));
}

	size = db_bar_size(dev, nr_io_queues);
	if (size > 8192) {
		iounmap(dev->bar);
		do {
			dev->bar = ioremap(pci_resource_start(pdev, 0), size);
			if (dev->bar)
				break;
			if (!--nr_io_queues)
				return -ENOMEM;
			size = db_bar_size(dev, --nr_io_queues);
		} while (1);
		dev->dbs = ((void __iomem *)dev->bar) + 4096;
		dev->queues[0]->q_db = dev->dbs;
	}

Although, now I'm wondering whether we free_irq() the admin queue exactly
the right number of times.  We might need to set ->queue_count to -1
while we've called free_irq() on the admin queue ... but then we'll need
to handle the queue memory freeing correctly.  Awkward ...

      reply	other threads:[~2013-07-01 21:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-01 16:23 [PATCH] NVMe: handle ioremap failure Keith Busch
2013-07-01 21:00 ` Matthew Wilcox [this message]

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=20130701210016.GB30142@linux.intel.com \
    --to=willy@linux.intel.com \
    /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).