From patchwork Tue Aug 1 16:54:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Mazarguil X-Patchwork-Id: 27333 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id C8862A2A8; Tue, 1 Aug 2017 18:56:12 +0200 (CEST) Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) by dpdk.org (Postfix) with ESMTP id 8F08FA1A6 for ; Tue, 1 Aug 2017 18:55:45 +0200 (CEST) Received: by mail-wr0-f180.google.com with SMTP id y43so9246580wrd.3 for ; Tue, 01 Aug 2017 09:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=d5/UlV9M5mriVPWS2Es99FgF1TO41uSVS0aXI32664o=; b=mVileZeaAMf2RUB/4zglIWQaxHwRvQes1Xs7QqSFst6Yalfq++yhxZ4YFR95oQ1M80 PqSr4FR2b629NSi/i0UfB11+j2/THNiuMGgKVQLos4Q2Emc2kD0m+p+IGRoXt77agelN 2lTrghFfMHw37AfSLgfyBZSF1TaouJ37KPdfYme7qct4apmiKMQnkYXU239NCDVFa7MY 15qj6LmKQ0RotGiK8z/IaIdVamzTbDYtR6NJPK0nbO8WCn8R0v4zkAUg62GhgKQFawRS 6JfqlhbwbBDwe6dLGTEHnRuYOa6zrBcPW8cG0JtnYADUSLWAYXPhmKng2yMEeG6A3olZ UZAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=d5/UlV9M5mriVPWS2Es99FgF1TO41uSVS0aXI32664o=; b=eU1BmBR5kQ7k8kUWG56aKx9tBrIRl/zXtFr1GtZigrXjtjFBJIwsAm1DL0zCw3bMGU 7HiH2trNQ38h5LR7JpohxgeDdWzJO8YDT1nSvZCzDc7fu2jwLMuoQmb31Nh7OcmsQyHz crAbvsfMhjGDaFIzWYdKW6RvAeZJJYHrBmaGn9JMdFS4SFGWCXvl7bxia/SLbMHcD0Nw u3/JNcp+yXa8jb11qwsL7CFxFcIp7/o7taKDeB3aGKEBFast0TxXuKN7KgR4HtV66txC dIEL5dp0zPsrkiOHaQRErU6mbJ+jgDIfxfVjOwMprniamP3sD5vZMd/K5f1/FG82NX0x gGkg== X-Gm-Message-State: AIVw1137Xg0MXU4gvXLvLViO9/DVlearQqmkdBwHZSFwfMuc4CAOoRTF WlgElfM9uaNxvFO3cZo= X-Received: by 10.223.160.99 with SMTP id l32mr17724993wrl.31.1501606544838; Tue, 01 Aug 2017 09:55:44 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id k46sm15429758wre.1.2017.08.01.09.55.43 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 01 Aug 2017 09:55:43 -0700 (PDT) From: Adrien Mazarguil To: dev@dpdk.org Date: Tue, 1 Aug 2017 18:54:25 +0200 Message-Id: <9429450c9594f5f37ae33f99f316a7d2fcd3408c.1501598384.git.adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v1 38/48] net/mlx4: compact interrupt functions 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Link status (LSC) and removal (RMV) interrupts share a common handler and are toggled simultaneously from common install/uninstall functions. Four additional wrapper functions (two for each interrupt type) are currently necessary because the PMD maintains an internal configuration state for interrupts (priv->intr_conf). This complexity can be avoided entirely since the PMD does not disable interrupts configuration parameters in case of error anymore. With this commit, only two functions are necessary to toggle interrupts (including Rx) during start/stop cycles. Signed-off-by: Adrien Mazarguil --- drivers/net/mlx4/mlx4.c | 199 +++++++++---------------------------------- drivers/net/mlx4/mlx4.h | 1 - 2 files changed, 41 insertions(+), 159 deletions(-) diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index 50e0687..c99f040 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -2048,9 +2048,8 @@ mlx4_rx_queue_release(void *dpdk_rxq) rte_free(rxq); } -static int priv_interrupt_handler_install(struct priv *priv); -static int priv_removal_interrupt_handler_install(struct priv *priv); -static int priv_link_interrupt_handler_install(struct priv *priv); +static int priv_intr_uninstall(struct priv *priv); +static int priv_intr_install(struct priv *priv); /** * DPDK callback to start the device. @@ -2076,24 +2075,12 @@ mlx4_dev_start(struct rte_eth_dev *dev) ret = priv_mac_addr_add(priv); if (ret) goto err; - ret = priv_link_interrupt_handler_install(priv); + ret = priv_intr_install(priv); if (ret) { - ERROR("%p: LSC handler install failed", + ERROR("%p: interrupt handler installation failed", (void *)dev); goto err; } - ret = priv_removal_interrupt_handler_install(priv); - if (ret) { - ERROR("%p: RMV handler install failed", - (void *)dev); - goto err; - } - ret = priv_rx_intr_vec_enable(priv); - if (ret) { - ERROR("%p: Rx interrupt vector creation failed", - (void *)dev); - goto err; - } ret = mlx4_priv_flow_start(priv); if (ret) { ERROR("%p: flow start failed: %s", @@ -2126,6 +2113,7 @@ mlx4_dev_stop(struct rte_eth_dev *dev) DEBUG("%p: detaching flows from all RX queues", (void *)dev); priv->started = 0; mlx4_priv_flow_stop(priv); + priv_intr_uninstall(priv); priv_mac_addr_del(priv); } @@ -2179,10 +2167,6 @@ removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) return 0; } -static int priv_interrupt_handler_uninstall(struct priv *priv); -static int priv_removal_interrupt_handler_uninstall(struct priv *priv); -static int priv_link_interrupt_handler_uninstall(struct priv *priv); - /** * DPDK callback to close the device. * @@ -2245,9 +2229,7 @@ mlx4_dev_close(struct rte_eth_dev *dev) claim_zero(ibv_close_device(priv->ctx)); } else assert(priv->ctx == NULL); - priv_removal_interrupt_handler_uninstall(priv); - priv_link_interrupt_handler_uninstall(priv); - priv_rx_intr_vec_disable(priv); + priv_intr_uninstall(priv); memset(priv, 0, sizeof(*priv)); } @@ -2753,6 +2735,8 @@ priv_collect_interrupt_events(struct priv *priv, uint32_t *events) struct ibv_async_event event; int port_change = 0; struct rte_eth_link *link = &priv->dev->data->dev_link; + const struct rte_intr_conf *const intr_conf = + &priv->dev->data->dev_conf.intr_conf; int ret = 0; *events = 0; @@ -2762,11 +2746,11 @@ priv_collect_interrupt_events(struct priv *priv, uint32_t *events) break; if ((event.event_type == IBV_EVENT_PORT_ACTIVE || event.event_type == IBV_EVENT_PORT_ERR) && - (priv->intr_conf.lsc == 1)) { + intr_conf->lsc) { port_change = 1; ret++; } else if (event.event_type == IBV_EVENT_DEVICE_FATAL && - priv->intr_conf.rmv == 1) { + intr_conf->rmv) { *events |= (1 << RTE_ETH_EVENT_INTR_RMV); ret++; } else @@ -2855,24 +2839,22 @@ mlx4_interrupt_handler(struct priv *priv) * 0 on success, negative errno value otherwise and rte_errno is set. */ static int -priv_interrupt_handler_uninstall(struct priv *priv) +priv_intr_uninstall(struct priv *priv) { - int ret; + int err = rte_errno; /* Make sure rte_errno remains unchanged. */ - if (priv->intr_conf.lsc || - priv->intr_conf.rmv) - return 0; - ret = rte_intr_callback_unregister(&priv->intr_handle, - (void (*)(void *)) - mlx4_interrupt_handler, - priv); - if (ret < 0) { - rte_errno = ret; - ERROR("rte_intr_callback_unregister failed with %d %s", - ret, strerror(rte_errno)); + if (priv->intr_handle.fd != -1) { + rte_intr_callback_unregister(&priv->intr_handle, + (void (*)(void *)) + mlx4_interrupt_handler, + priv); + priv->intr_handle.fd = -1; } - priv->intr_handle.fd = -1; - return ret; + rte_eal_alarm_cancel((void (*)(void *))mlx4_link_status_alarm, priv); + priv->intr_alarm = 0; + priv_rx_intr_vec_disable(priv); + rte_errno = err; + return 0; } /** @@ -2885,127 +2867,30 @@ priv_interrupt_handler_uninstall(struct priv *priv) * 0 on success, negative errno value otherwise and rte_errno is set. */ static int -priv_interrupt_handler_install(struct priv *priv) +priv_intr_install(struct priv *priv) { + const struct rte_intr_conf *const intr_conf = + &priv->dev->data->dev_conf.intr_conf; int rc; - /* - * Check whether the interrupt handler has already been installed - * for either type of interrupt. - */ - if (priv->intr_conf.lsc && - priv->intr_conf.rmv && - priv->intr_handle.fd) - return 0; - priv->intr_handle.fd = priv->ctx->async_fd; - rc = rte_intr_callback_register(&priv->intr_handle, - (void (*)(void *)) - mlx4_interrupt_handler, - priv); - if (!rc) - return 0; - rte_errno = -rc; - ERROR("rte_intr_callback_register failed (rte_errno: %s)", - strerror(rte_errno)); - priv->intr_handle.fd = -1; - return -rte_errno; -} - -/** - * Uninstall interrupt handler. - * - * @param priv - * Pointer to private structure. - * - * @return - * 0 on success, negative errno value otherwise and rte_errno is set. - */ -static int -priv_removal_interrupt_handler_uninstall(struct priv *priv) -{ - if (priv->dev->data->dev_conf.intr_conf.rmv) { - priv->intr_conf.rmv = 0; - return priv_interrupt_handler_uninstall(priv); - } - return 0; -} - -/** - * Uninstall interrupt handler. - * - * @param priv - * Pointer to private structure. - * - * @return - * 0 on success, negative errno value otherwise and rte_errno is set. - */ -static int -priv_link_interrupt_handler_uninstall(struct priv *priv) -{ - int ret = 0; - - if (priv->dev->data->dev_conf.intr_conf.lsc) { - priv->intr_conf.lsc = 0; - ret = priv_interrupt_handler_uninstall(priv); - if (ret) - return ret; - } - if (priv->intr_alarm) - if (rte_eal_alarm_cancel((void (*)(void *)) - mlx4_link_status_alarm, - priv)) { - ERROR("rte_eal_alarm_cancel failed " - " (rte_errno: %s)", strerror(rte_errno)); - return -rte_errno; + priv_intr_uninstall(priv); + if (intr_conf->rxq && priv_rx_intr_vec_enable(priv) < 0) + goto error; + if (intr_conf->lsc | intr_conf->rmv) { + priv->intr_handle.fd = priv->ctx->async_fd; + rc = rte_intr_callback_register(&priv->intr_handle, + (void (*)(void *)) + mlx4_interrupt_handler, + priv); + if (rc < 0) { + rte_errno = -rc; + goto error; } - priv->intr_alarm = 0; - return 0; -} - -/** - * Install link interrupt handler. - * - * @param priv - * Pointer to private structure. - * - * @return - * 0 on success, negative errno value otherwise and rte_errno is set. - */ -static int -priv_link_interrupt_handler_install(struct priv *priv) -{ - int ret; - - if (priv->dev->data->dev_conf.intr_conf.lsc) { - ret = priv_interrupt_handler_install(priv); - if (ret) - return ret; - priv->intr_conf.lsc = 1; - } - return 0; -} - -/** - * Install removal interrupt handler. - * - * @param priv - * Pointer to private structure. - * - * @return - * 0 on success, negative errno value otherwise and rte_errno is set. - */ -static int -priv_removal_interrupt_handler_install(struct priv *priv) -{ - int ret; - - if (priv->dev->data->dev_conf.intr_conf.rmv) { - ret = priv_interrupt_handler_install(priv); - if (ret) - return ret; - priv->intr_conf.rmv = 1; } return 0; +error: + priv_intr_uninstall(priv); + return -rte_errno; } /** @@ -3026,8 +2911,6 @@ priv_rx_intr_vec_enable(struct priv *priv) unsigned int count = 0; struct rte_intr_handle *intr_handle = &priv->intr_handle; - if (!priv->dev->data->dev_conf.intr_conf.rxq) - return 0; priv_rx_intr_vec_disable(priv); intr_handle->intr_vec = malloc(sizeof(intr_handle->intr_vec[rxqs_n])); if (intr_handle->intr_vec == NULL) { diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h index 6104842..528607c 100644 --- a/drivers/net/mlx4/mlx4.h +++ b/drivers/net/mlx4/mlx4.h @@ -176,7 +176,6 @@ struct priv { struct rte_intr_handle intr_handle; /* Port interrupt handle. */ struct rte_flow_drop *flow_drop_queue; /* Flow drop queue. */ LIST_HEAD(mlx4_flows, rte_flow) flows; - struct rte_intr_conf intr_conf; /* Active interrupt configuration. */ }; #endif /* RTE_PMD_MLX4_H_ */