From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 49449A0093 for ; Fri, 11 Mar 2022 08:18:28 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3E3C040042; Fri, 11 Mar 2022 08:18:28 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 0B9CE40042 for ; Fri, 11 Mar 2022 08:18:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646983106; x=1678519106; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+xa1RGjAtBCLf2VX1G1AMb8XjI3M5i/eKCpiEI1jwlE=; b=BU4dZfIuBz+CA2+iElsJI7b7qVS4rrsvgSSCUtLkUDrpEbq1m4xQn6kB 55fJ5eudh1oOg1HW55IgWfAX38sRXRgKHp/yJASHJze843NNtsR8APZxT B+9bnWCR/236x+7N89mS3vqnBC3zk6l+oI0WjKcX/nMJlKbGmZcXpb799 ANaJzDfv79IPPGEqcU5eTJkgReHZEU+exag84gcrj0ub5BkiPpgx/CExq cMGChxrjbThI/HLo40Z2MBeaVYXYcCALHHI9ft070C16hGjzboqMzfmAL gpcWQ4L4NdQI99HaFNdMZbIn7Y27q/hYep0J98uMOhSc9neq6yBOKbOuS g==; X-IronPort-AV: E=McAfee;i="6200,9189,10282"; a="318741582" X-IronPort-AV: E=Sophos;i="5.90,173,1643702400"; d="scan'208";a="318741582" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2022 23:18:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,173,1643702400"; d="scan'208";a="633325968" Received: from unknown (HELO localhost.localdomain.sh.intel.com) ([10.238.175.107]) by FMSMGA003.fm.intel.com with ESMTP; 10 Mar 2022 23:18:23 -0800 From: Wei Huang To: stable@dpdk.org, christian.ehrhardt@canonical.com Cc: rosen.xu@intel.com, tianfei.zhang@intel.com, Wei Huang Subject: [PATCH 19.11 1/2] raw/ifpga: fix interrupt handle allocation Date: Fri, 11 Mar 2022 02:15:04 -0500 Message-Id: <20220311071505.1507945-2-wei.huang@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220311071505.1507945-1-wei.huang@intel.com> References: <20220311071505.1507945-1-wei.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org [ upstream commit 20659eb38099033b9aa4f7476a7ba7b5d3258569 ] Allocate FPGA interrupt handle instance for each card. Fixes: e0a1aaf ("raw/ifpga: introduce IRQ functions") Cc: stable@dpdk.org Signed-off-by: Wei Huang Acked-by: Tianfei Zhang --- drivers/raw/ifpga/ifpga_rawdev.c | 88 ++++++++++++++++++++++++++++------------ drivers/raw/ifpga/ifpga_rawdev.h | 7 +++- 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index 7380433..dfebb7e 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -79,10 +79,6 @@ static int ifpga_monitor_start; static pthread_t ifpga_monitor_start_thread; -#define IFPGA_MAX_IRQ 12 -/* 0 for FME interrupt, others are reserved for AFU irq */ -static struct rte_intr_handle ifpga_irq_handle[IFPGA_MAX_IRQ]; - static struct ifpga_rawdev * ifpga_rawdev_allocate(struct rte_rawdev *rawdev); static int set_surprise_link_check_aer( @@ -126,6 +122,7 @@ struct ifpga_rawdev * { struct ifpga_rawdev *dev; uint16_t dev_id; + int i = 0; dev = ifpga_rawdev_get(rawdev); if (dev != NULL) { @@ -142,6 +139,8 @@ struct ifpga_rawdev * dev = &ifpga_rawdevices[dev_id]; dev->rawdev = rawdev; dev->dev_id = dev_id; + for (i = 0; i < IFPGA_MAX_IRQ; i++) + dev->intr_handle[i] = NULL; return dev; } @@ -1335,36 +1334,63 @@ static int fme_clean_fme_error(struct opae_manager *mgr) } int -ifpga_unregister_msix_irq(enum ifpga_irq_type type, +ifpga_unregister_msix_irq(struct ifpga_rawdev *dev, enum ifpga_irq_type type, int vec_start, rte_intr_callback_fn handler, void *arg) { - struct rte_intr_handle *intr_handle; + struct rte_intr_handle **intr_handle; + int rc = 0; + int i = vec_start + 1; + + if (!dev) + return -ENODEV; if (type == IFPGA_FME_IRQ) - intr_handle = &ifpga_irq_handle[0]; + intr_handle = (struct rte_intr_handle **)&dev->intr_handle[0]; else if (type == IFPGA_AFU_IRQ) - intr_handle = &ifpga_irq_handle[vec_start + 1]; + intr_handle = (struct rte_intr_handle **)&dev->intr_handle[i]; else - return 0; + return -EINVAL; - rte_intr_efd_disable(intr_handle); + if ((*intr_handle) == NULL) { + IFPGA_RAWDEV_PMD_ERR("%s interrupt %d not registered\n", + type == IFPGA_FME_IRQ ? "FME" : "AFU", + type == IFPGA_FME_IRQ ? 0 : vec_start); + return -ENOENT; + } + + rte_intr_efd_disable(*intr_handle); + + + rc = rte_intr_callback_unregister(*intr_handle, handler, arg); + if (rc < 0) { + IFPGA_RAWDEV_PMD_ERR("Failed to unregister %s interrupt %d\n", + type == IFPGA_FME_IRQ ? "FME" : "AFU", + type == IFPGA_FME_IRQ ? 0 : vec_start); + } else { + rte_free(*intr_handle); + *intr_handle = NULL; + } - return rte_intr_callback_unregister(intr_handle, handler, arg); + return rc; } int -ifpga_register_msix_irq(struct rte_rawdev *dev, int port_id, +ifpga_register_msix_irq(struct ifpga_rawdev *dev, int port_id, enum ifpga_irq_type type, int vec_start, int count, rte_intr_callback_fn handler, const char *name, void *arg) { int ret; - struct rte_intr_handle *intr_handle; + struct rte_intr_handle **intr_handle; struct opae_adapter *adapter; struct opae_manager *mgr; struct opae_accelerator *acc; + int i; - adapter = ifpga_rawdev_get_priv(dev); + if (!dev || !dev->rawdev) + return -ENODEV; + + adapter = ifpga_rawdev_get_priv(dev->rawdev); if (!adapter) return -ENODEV; @@ -1373,29 +1399,37 @@ static int fme_clean_fme_error(struct opae_manager *mgr) return -ENODEV; if (type == IFPGA_FME_IRQ) { - intr_handle = &ifpga_irq_handle[0]; + intr_handle = (struct rte_intr_handle **)&dev->intr_handle[0]; count = 1; } else if (type == IFPGA_AFU_IRQ) { - intr_handle = &ifpga_irq_handle[vec_start + 1]; + i = vec_start + 1; + intr_handle = (struct rte_intr_handle **)&dev->intr_handle[i]; } else { return -EINVAL; } - intr_handle->type = RTE_INTR_HANDLE_VFIO_MSIX; + if (*intr_handle) + return -EBUSY; - ret = rte_intr_efd_enable(intr_handle, count); + *intr_handle = rte_zmalloc(NULL, sizeof(struct rte_intr_handle), 0); + if (!(*intr_handle)) + return -ENOMEM; + + (*intr_handle)->type = RTE_INTR_HANDLE_VFIO_MSIX; + + ret = rte_intr_efd_enable(*intr_handle, count); if (ret) return -ENODEV; - intr_handle->fd = intr_handle->efds[0]; + (*intr_handle)->fd = (*intr_handle)->efds[0]; IFPGA_RAWDEV_PMD_DEBUG("register %s irq, vfio_fd=%d, fd=%d\n", - name, intr_handle->vfio_dev_fd, - intr_handle->fd); + name, (*intr_handle)->vfio_dev_fd, + (*intr_handle)->fd); if (type == IFPGA_FME_IRQ) { struct fpga_fme_err_irq_set err_irq_set; - err_irq_set.evtfd = intr_handle->efds[0]; + err_irq_set.evtfd = (*intr_handle)->efds[0]; ret = opae_manager_ifpga_set_err_irq(mgr, &err_irq_set); if (ret) @@ -1406,13 +1440,13 @@ static int fme_clean_fme_error(struct opae_manager *mgr) return -EINVAL; ret = opae_acc_set_irq(acc, vec_start, count, - intr_handle->efds); + (*intr_handle)->efds); if (ret) return -EINVAL; } /* register interrupt handler using DPDK API */ - ret = rte_intr_callback_register(intr_handle, + ret = rte_intr_callback_register(*intr_handle, handler, (void *)arg); if (ret) return -EINVAL; @@ -1511,7 +1545,7 @@ static int fme_clean_fme_error(struct opae_manager *mgr) IFPGA_RAWDEV_PMD_INFO("this is a PF function"); } - ret = ifpga_register_msix_irq(rawdev, 0, IFPGA_FME_IRQ, 0, 0, + ret = ifpga_register_msix_irq(dev, 0, IFPGA_FME_IRQ, 0, 0, fme_interrupt_handler, "fme_irq", mgr); if (ret) goto free_adapter_data; @@ -1536,6 +1570,7 @@ static int fme_clean_fme_error(struct opae_manager *mgr) char name[RTE_RAWDEV_NAME_MAX_LEN]; struct opae_adapter *adapter; struct opae_manager *mgr; + struct ifpga_rawdev *dev; if (!pci_dev) { IFPGA_RAWDEV_PMD_ERR("Invalid pci_dev of the device!"); @@ -1555,6 +1590,7 @@ static int fme_clean_fme_error(struct opae_manager *mgr) IFPGA_RAWDEV_PMD_ERR("Invalid device name (%s)", name); return -EINVAL; } + dev = ifpga_rawdev_get(rawdev); adapter = ifpga_rawdev_get_priv(rawdev); if (!adapter) @@ -1564,7 +1600,7 @@ static int fme_clean_fme_error(struct opae_manager *mgr) if (!mgr) return -ENODEV; - if (ifpga_unregister_msix_irq(IFPGA_FME_IRQ, 0, + if (ifpga_unregister_msix_irq(dev, IFPGA_FME_IRQ, 0, fme_interrupt_handler, mgr) < 0) return -EINVAL; diff --git a/drivers/raw/ifpga/ifpga_rawdev.h b/drivers/raw/ifpga/ifpga_rawdev.h index 7754beb..d82b887 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.h +++ b/drivers/raw/ifpga/ifpga_rawdev.h @@ -48,6 +48,7 @@ enum ifpga_rawdev_device_state { #define IFPGA_RAWDEV_MSIX_IRQ_NUM 7 #define IFPGA_RAWDEV_NUM 32 +#define IFPGA_MAX_IRQ 12 struct ifpga_rawdev { int dev_id; @@ -57,6 +58,8 @@ struct ifpga_rawdev { uint32_t aer_old[2]; char fvl_bdf[8][16]; char parent_bdf[16]; + /* 0 for FME interrupt, others are reserved for AFU irq */ + void *intr_handle[IFPGA_MAX_IRQ]; }; struct ifpga_rawdev * @@ -68,12 +71,12 @@ enum ifpga_irq_type { }; int -ifpga_register_msix_irq(struct rte_rawdev *dev, int port_id, +ifpga_register_msix_irq(struct ifpga_rawdev *dev, int port_id, enum ifpga_irq_type type, int vec_start, int count, rte_intr_callback_fn handler, const char *name, void *arg); int -ifpga_unregister_msix_irq(enum ifpga_irq_type type, +ifpga_unregister_msix_irq(struct ifpga_rawdev *dev, enum ifpga_irq_type type, int vec_start, rte_intr_callback_fn handler, void *arg); #endif /* _IFPGA_RAWDEV_H_ */ -- 1.8.3.1