DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: "Liang, Cunming" <cunming.liang@intel.com>
Cc: dev@dpdk.org, cumming.lian@intel.com
Subject: Re: [dpdk-dev] [PATCH 4/5] uio: new driver with MSI-X support
Date: Mon, 25 May 2015 10:41:37 -0700	[thread overview]
Message-ID: <20150525104137.166e8dd1@urahara> (raw)
In-Reply-To: <5562BAAA.5050301@intel.com>

On Mon, 25 May 2015 14:01:14 +0800
"Liang, Cunming" <cunming.liang@intel.com> wrote:

> 
> 
> On 5/19/2015 1:40 AM, Stephen Hemminger wrote:
> > +
> > +/* set the mapping between vector # and existing eventfd. */
> > +static int set_irq_eventfd(struct uio_msi_pci_dev *udev, u32 vec, int fd)
> > +{
> > +	struct uio_msi_irq_ctx *ctx;
> > +	struct eventfd_ctx *trigger;
> > +	int irq, err;
> > +
> > +	if (vec >= udev->num_vectors) {
> > +		dev_notice(&udev->pdev->dev, "vec %u >= num_vec %u\n",
> > +			   vec, udev->num_vectors);
> > +		return -ERANGE;
> > +	}
> > +
> > +	irq = udev->msix[vec].vector;
> > +
> > +	/* Clearup existing irq mapping */
> > +	ctx = &udev->ctx[vec];
> > +	if (ctx->trigger) {
> > +		free_irq(irq, ctx->trigger);
> > +		eventfd_ctx_put(ctx->trigger);
> > +		ctx->trigger = NULL;
> > +	}
> > +
> > +	/* Passing -1 is used to disable interrupt */
> > +	if (fd < 0)
> > +		return 0;
> > +
> > +
> One unnecessary blank line here.
> > +	trigger = eventfd_ctx_fdget(fd);
> > +	if (IS_ERR(trigger)) {
> > +		err = PTR_ERR(trigger);
> > +		dev_notice(&udev->pdev->dev,
> > +			   "eventfd ctx get failed: %d\n", err);
> > +		return err;
> > +	}
> > +
> > +	err = request_irq(irq, uio_msi_irqhandler, 0, ctx->name, trigger);
> > +	if (err) {
> > +		dev_notice(&udev->pdev->dev,
> > +			   "request irq failed: %d\n", err);
> > +		eventfd_ctx_put(trigger);
> > +		return err;
> > +	}
> > +
> > +	dev_dbg(&udev->pdev->dev, "map vector %u to fd %d trigger %p\n",
> > +		  vec, fd, trigger);
> > +	ctx->trigger = trigger;
> > +	return 0;
> > +}
> > +
> > +static int
> > +uio_msi_ioctl(struct uio_info *info, unsigned int cmd, unsigned long arg)
> > +{
> > +	struct uio_msi_pci_dev *udev
> > +		= container_of(info, struct uio_msi_pci_dev, info);
> > +	struct uio_msi_irq_set hdr;
> > +	int err;
> > +
> > +	switch (cmd) {
> > +	case UIO_MSI_IRQ_SET:
> > +		if (copy_from_user(&hdr, (void __user *)arg, sizeof(hdr)))
> > +			return -EFAULT;
> > +
> > +		mutex_lock(&udev->mutex);
> > +		err = set_irq_eventfd(udev, hdr.vec, hdr.fd);
> > +		mutex_unlock(&udev->mutex);
> > +		break;
> > +	default:
> > +		err = -EOPNOTSUPP;
> > +	}
> > +	return err;
> > +}
> "uio_msi_irq_set" defines in single pattern. Compare with the bulk set 
> in "vfio_irq_set", it requires additional syscall during uio_msix_enable().

The bulk operation is VFIO is actually a bad design,
It forces too many updates when manipulating individual vectors.
Personally, the whole VFIO API has some questionable design choices
that I did not want to repeat.

> > +static int uio_msi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> > +{
> > +	struct uio_msi_pci_dev *udev;
> > +	int i, err, vectors;
> > +
> > +	udev = kzalloc(sizeof(struct uio_msi_pci_dev), GFP_KERNEL);
> > +	if (!udev)
> > +		return -ENOMEM;
> > +
> > +	err = pci_enable_device(pdev);
> > +	if (err != 0) {
> > +		dev_err(&pdev->dev, "cannot enable PCI device\n");
> > +		goto fail_free;
> > +	}
> > +
> > +	vectors = pci_msix_vec_count(pdev);
> > +	if (vectors < 0) {
> > +		dev_err(&pdev->dev, "device does not support MSI-X\n");
> > +		err = -EINVAL;
> > +		goto fail_disable;
> > +	}
> pci_msix_vec_count() is available since v3.14,  it requires a compatible 
> check.
> In order to support older version, probably a function 
> 'uio_msix_vec_count()' is necessary.
> 
> I've one overall question, is there a special reason not enhance igb_uio 
> but define a new uio_msi?  And the looks like the piece could be add 
> into igb_uio or uio_pci_generic as well. Do you have plan for the 
> latter? Thanks.

I wanted something that could go upstream. igb_uio has some other things
which make it unlikely to get accepted in current form, so seemed best to start
fresh.

Also, intentionally did not want to address any kernel version earlier
than the version where VFIO was added.

  reply	other threads:[~2015-05-25 17:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-18 17:40 [dpdk-dev] [PATCH 0/5] receive IRQ related patches Stephen Hemminger
2015-05-18 17:40 ` [dpdk-dev] [PATCH 1/5] ethdev: check for rxq interrupt support Stephen Hemminger
2015-05-18 17:40 ` [dpdk-dev] [PATCH 2/5] ethdev: remove unnecessary checks Stephen Hemminger
2015-05-18 17:40 ` [dpdk-dev] [PATCH 3/5] ethdev: fix errors if RTE_ETHDEV_DEBUG enabled Stephen Hemminger
2015-05-18 17:40 ` [dpdk-dev] [PATCH 4/5] uio: new driver with MSI-X support Stephen Hemminger
2015-05-25  6:01   ` Liang, Cunming
2015-05-25 17:41     ` Stephen Hemminger [this message]
2015-05-18 17:40 ` [dpdk-dev] [PATCH 5/5] uio: integrate " Stephen Hemminger
2015-05-25  8:55   ` Liang, Cunming
2015-05-25 17:42     ` Stephen Hemminger
2015-07-09  0:28 ` [dpdk-dev] [PATCH 0/5] receive IRQ related patches Thomas Monjalon

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=20150525104137.166e8dd1@urahara \
    --to=stephen@networkplumber.org \
    --cc=cumming.lian@intel.com \
    --cc=cunming.liang@intel.com \
    --cc=dev@dpdk.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).