From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id 3825C10CAF for ; Wed, 21 Dec 2016 16:10:03 +0100 (CET) Received: by mail-wm0-f67.google.com with SMTP id l2so5470659wml.2 for ; Wed, 21 Dec 2016 07:10:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qnzZoF8TJG7UBbB+fqGTNvMzq9HkYCVZ6xXwetmPpOw=; b=qxOFzCPtnUtWm3zNl1qrvBW97rwh74GbnaeA+AQS/xRnztkYsLaXMOUyZ3SQpEOmBj zWaKIX/K2MG1ahV5X7jXQ1F7uOofzw0LMmXplFrf+yHTRIA5OGs0u9+VUaGsBfbL6oDM Bo6ByF5ooSI6CuItxCVwFJfCZmdyjSdYnNJWFJVdxAzn/CyHqpa+VPhhC0J/Bxj0Rov7 0EMX5nVEfyyn1Dl4f+HTfUWgmH3/lf9Bw8Xuew0AzVYPnhk/vGDAySDiyGSSSt8x4Juo 4FNZzOViKTnfeo5X6h8whcw5hxALGfDZG+B/3acB0IGxehsjymcMqyDL4gD9IBBB6FOZ j4zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=qnzZoF8TJG7UBbB+fqGTNvMzq9HkYCVZ6xXwetmPpOw=; b=oARjw6xn7V5wBjMvYESp+1q1e0KEsWLKBoRlRduNjdHlZrXxdZUvqF7Y2pteYlgngw NG+Vm896DPSN3v8AY6WRIiqqvC8ZR8u4d0gU1BJ8MI/EUtvwPNqhnrstR7F25t85IQFa MvP+0+4QwS5/Jm/oE0gzEnRQQ7LsN2BLaBGzMUtx6X+cJhgC+fnOL+1JON7Eg5zx+O2I KkSV2AtKAcS8aXoiFrHuLdkiLMB3o3qFTjRDpIXIUGp+SEnToLiNqOSlW1YyBCN69Tbe 6mpK3fQ83pNsbNel09tT5N7zWns9E724iWgDm8dVZenLeRgvwFB/drttR56gSbbPPKtu SRww== X-Gm-Message-State: AIkVDXKhrKayOokLHJImzbLYvE4yyJkTa3sF9zwisScKevnQS9ghaQBR7G5F1cHQKyDHog== X-Received: by 10.28.153.10 with SMTP id b10mr7100143wme.103.1482333002783; Wed, 21 Dec 2016 07:10:02 -0800 (PST) Received: from weierstrass.local.net ([91.200.109.169]) by smtp.gmail.com with ESMTPSA id 135sm27627375wmh.14.2016.12.21.07.10.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Dec 2016 07:10:01 -0800 (PST) Sender: Jan Blunck From: Jan Blunck To: dev@dpdk.org Cc: shreyansh.jain@nxp.com, david.marchand@6wind.com, stephen@networkplumber.org Date: Wed, 21 Dec 2016 16:09:25 +0100 Message-Id: <1482332986-7599-3-git-send-email-jblunck@infradead.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482332986-7599-1-git-send-email-jblunck@infradead.org> References: <1482332986-7599-1-git-send-email-jblunck@infradead.org> Subject: [dpdk-dev] [PATCH v4 02/23] eal: Allow passing const rte_intr_handle X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Dec 2016 15:10:03 -0000 Both register/unregister and enable/disable don't necessarily require the rte_intr_handle to be modifiable. Therefore lets constify it. Signed-off-by: Jan Blunck --- lib/librte_eal/common/include/rte_interrupts.h | 8 ++-- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 62 ++++++++++++++++++-------- 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/lib/librte_eal/common/include/rte_interrupts.h b/lib/librte_eal/common/include/rte_interrupts.h index fd3c6ef..6cade01 100644 --- a/lib/librte_eal/common/include/rte_interrupts.h +++ b/lib/librte_eal/common/include/rte_interrupts.h @@ -70,7 +70,7 @@ typedef void (*rte_intr_callback_fn)(struct rte_intr_handle *intr_handle, * - On success, zero. * - On failure, a negative value. */ -int rte_intr_callback_register(struct rte_intr_handle *intr_handle, +int rte_intr_callback_register(const struct rte_intr_handle *intr_handle, rte_intr_callback_fn cb, void *cb_arg); /** @@ -88,7 +88,7 @@ int rte_intr_callback_register(struct rte_intr_handle *intr_handle, * - On success, return the number of callback entities removed. * - On failure, a negative value. */ -int rte_intr_callback_unregister(struct rte_intr_handle *intr_handle, +int rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle, rte_intr_callback_fn cb, void *cb_arg); /** @@ -101,7 +101,7 @@ int rte_intr_callback_unregister(struct rte_intr_handle *intr_handle, * - On success, zero. * - On failure, a negative value. */ -int rte_intr_enable(struct rte_intr_handle *intr_handle); +int rte_intr_enable(const struct rte_intr_handle *intr_handle); /** * It disables the interrupt for the specified handle. @@ -113,7 +113,7 @@ int rte_intr_enable(struct rte_intr_handle *intr_handle); * - On success, zero. * - On failure, a negative value. */ -int rte_intr_disable(struct rte_intr_handle *intr_handle); +int rte_intr_disable(const struct rte_intr_handle *intr_handle); #ifdef __cplusplus } diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c index 47a3b20..cb55751 100644 --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c @@ -136,7 +136,7 @@ static pthread_t intr_thread; /* enable legacy (INTx) interrupts */ static int -vfio_enable_intx(struct rte_intr_handle *intr_handle) { +vfio_enable_intx(const struct rte_intr_handle *intr_handle) { struct vfio_irq_set *irq_set; char irq_set_buf[IRQ_SET_BUF_LEN]; int len, ret; @@ -183,7 +183,7 @@ vfio_enable_intx(struct rte_intr_handle *intr_handle) { /* disable legacy (INTx) interrupts */ static int -vfio_disable_intx(struct rte_intr_handle *intr_handle) { +vfio_disable_intx(const struct rte_intr_handle *intr_handle) { struct vfio_irq_set *irq_set; char irq_set_buf[IRQ_SET_BUF_LEN]; int len, ret; @@ -226,7 +226,7 @@ vfio_disable_intx(struct rte_intr_handle *intr_handle) { /* enable MSI interrupts */ static int -vfio_enable_msi(struct rte_intr_handle *intr_handle) { +vfio_enable_msi(const struct rte_intr_handle *intr_handle) { int len, ret; char irq_set_buf[IRQ_SET_BUF_LEN]; struct vfio_irq_set *irq_set; @@ -255,7 +255,7 @@ vfio_enable_msi(struct rte_intr_handle *intr_handle) { /* disable MSI interrupts */ static int -vfio_disable_msi(struct rte_intr_handle *intr_handle) { +vfio_disable_msi(const struct rte_intr_handle *intr_handle) { struct vfio_irq_set *irq_set; char irq_set_buf[IRQ_SET_BUF_LEN]; int len, ret; @@ -278,9 +278,30 @@ vfio_disable_msi(struct rte_intr_handle *intr_handle) { return ret; } +static int +get_max_intr(const struct rte_intr_handle *intr_handle) +{ + struct rte_intr_source *src; + + TAILQ_FOREACH(src, &intr_sources, next) { + if (src->intr_handle.fd != intr_handle->fd) + continue; + + if (!src->intr_handle.max_intr) + src->intr_handle.max_intr = 1; + else if (src->intr_handle.max_intr > RTE_MAX_RXTX_INTR_VEC_ID) + src->intr_handle.max_intr + = RTE_MAX_RXTX_INTR_VEC_ID + 1; + + return src->intr_handle.max_intr; + } + + return -1; +} + /* enable MSI-X interrupts */ static int -vfio_enable_msix(struct rte_intr_handle *intr_handle) { +vfio_enable_msix(const struct rte_intr_handle *intr_handle) { int len, ret; char irq_set_buf[MSIX_IRQ_SET_BUF_LEN]; struct vfio_irq_set *irq_set; @@ -290,12 +311,15 @@ vfio_enable_msix(struct rte_intr_handle *intr_handle) { irq_set = (struct vfio_irq_set *) irq_set_buf; irq_set->argsz = len; - if (!intr_handle->max_intr) - intr_handle->max_intr = 1; - else if (intr_handle->max_intr > RTE_MAX_RXTX_INTR_VEC_ID) - intr_handle->max_intr = RTE_MAX_RXTX_INTR_VEC_ID + 1; - irq_set->count = intr_handle->max_intr; + ret = get_max_intr(intr_handle); + if (ret < 0) { + RTE_LOG(ERR, EAL, "Invalid number of MSI-X irqs for fd %d\n", + intr_handle->fd); + return -1; + } + + irq_set->count = ret; irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER; irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX; irq_set->start = 0; @@ -318,7 +342,7 @@ vfio_enable_msix(struct rte_intr_handle *intr_handle) { /* disable MSI-X interrupts */ static int -vfio_disable_msix(struct rte_intr_handle *intr_handle) { +vfio_disable_msix(const struct rte_intr_handle *intr_handle) { struct vfio_irq_set *irq_set; char irq_set_buf[MSIX_IRQ_SET_BUF_LEN]; int len, ret; @@ -343,7 +367,7 @@ vfio_disable_msix(struct rte_intr_handle *intr_handle) { #endif static int -uio_intx_intr_disable(struct rte_intr_handle *intr_handle) +uio_intx_intr_disable(const struct rte_intr_handle *intr_handle) { unsigned char command_high; @@ -367,7 +391,7 @@ uio_intx_intr_disable(struct rte_intr_handle *intr_handle) } static int -uio_intx_intr_enable(struct rte_intr_handle *intr_handle) +uio_intx_intr_enable(const struct rte_intr_handle *intr_handle) { unsigned char command_high; @@ -391,7 +415,7 @@ uio_intx_intr_enable(struct rte_intr_handle *intr_handle) } static int -uio_intr_disable(struct rte_intr_handle *intr_handle) +uio_intr_disable(const struct rte_intr_handle *intr_handle) { const int value = 0; @@ -405,7 +429,7 @@ uio_intr_disable(struct rte_intr_handle *intr_handle) } static int -uio_intr_enable(struct rte_intr_handle *intr_handle) +uio_intr_enable(const struct rte_intr_handle *intr_handle) { const int value = 1; @@ -419,7 +443,7 @@ uio_intr_enable(struct rte_intr_handle *intr_handle) } int -rte_intr_callback_register(struct rte_intr_handle *intr_handle, +rte_intr_callback_register(const struct rte_intr_handle *intr_handle, rte_intr_callback_fn cb, void *cb_arg) { int ret, wake_thread; @@ -491,7 +515,7 @@ rte_intr_callback_register(struct rte_intr_handle *intr_handle, } int -rte_intr_callback_unregister(struct rte_intr_handle *intr_handle, +rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle, rte_intr_callback_fn cb_fn, void *cb_arg) { int ret; @@ -555,7 +579,7 @@ rte_intr_callback_unregister(struct rte_intr_handle *intr_handle, } int -rte_intr_enable(struct rte_intr_handle *intr_handle) +rte_intr_enable(const struct rte_intr_handle *intr_handle) { if (!intr_handle || intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0) return -1; @@ -599,7 +623,7 @@ rte_intr_enable(struct rte_intr_handle *intr_handle) } int -rte_intr_disable(struct rte_intr_handle *intr_handle) +rte_intr_disable(const struct rte_intr_handle *intr_handle) { if (!intr_handle || intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0) return -1; -- 2.7.4