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 98A64459DD; Fri, 20 Sep 2024 06:44:03 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2630740669; Fri, 20 Sep 2024 06:44:03 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 28F2D400EF for ; Fri, 20 Sep 2024 06:44:01 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48K0Pc55015862 for ; Thu, 19 Sep 2024 21:44:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pfpt0220; bh=2 XHt71m0NW9dJx/s1FVZvx0Dg74Cihp43TUI91sgbH4=; b=BeXzl10KbBXzXQAzT 0VE7tjfyYOk5kTnp++Phrg1bKX/rrdgByo4h6iQoV8SDuhLwPwZfqJveRQ9ScfEx ikJwL2KYSQw1FE0uRpeGpJKaNb/BtbUceVg4zKVroLzViVlNMktrBMKtiEdvmGjC o1E8J0LX0Jzpbd6ote97OXvAbCURCE66gUt/ObeEDBPPp6a1Rp021kJ2JmfijXGb 7yiCsrn9GHac6wRf1eexQJeBPsdmfmmLVKYQBrIz2F9ddlhj04kfJrdyl3hcDxuE fCgRplLZuW1Dlgs6P8rk3SkdubOwN6SxYwLNm8f9rr//QdNRTcGmSVaPm4GisGUl ZMRQg== Received: from dc6wp-exch02.marvell.com ([4.21.29.225]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 41rh5mmkwe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 19 Sep 2024 21:44:00 -0700 (PDT) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 19 Sep 2024 21:43:59 -0700 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 19 Sep 2024 21:43:59 -0700 Received: from cavium-VAMSI-BM.. (unknown [10.28.36.156]) by maili.marvell.com (Postfix) with ESMTP id 841945B6923; Thu, 19 Sep 2024 21:43:57 -0700 (PDT) From: Vamsi Krishna To: CC: , Vamsi Attunuru Subject: [PATCH v2 1/1] net/octeon_ep: add device removal event callback Date: Fri, 20 Sep 2024 10:13:47 +0530 Message-ID: <20240920044347.1211530-1-vattunuru@marvell.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827053259.12033-1-vattunuru@marvell.com> References: <20240827053259.12033-1-vattunuru@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: DHOFGYDMnMY_G_hgAbHpi18H2Eb5aUGW X-Proofpoint-GUID: DHOFGYDMnMY_G_hgAbHpi18H2Eb5aUGW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Vamsi Attunuru Adds an event callback to catch any device removal event occurred during driver probe. This callback helps in terminating the execution if there is any device removal event during the driver probe. Also moved global register configuration into dev_configure() routine and also validates register reads for any invalid return values from hardware during driver probe. Signed-off-by: Vamsi Attunuru --- V2 changes: * Corrected commit message * Updated release notes * Used UINT64_MAX macro. doc/guides/rel_notes/release_24_11.rst | 5 +++ drivers/net/octeon_ep/cnxk_ep_vf.c | 2 + drivers/net/octeon_ep/otx2_ep_vf.c | 2 + drivers/net/octeon_ep/otx_ep_ethdev.c | 58 +++++++++++++++++++------- drivers/net/octeon_ep/otx_ep_mbox.c | 11 +++++ drivers/net/octeon_ep/otx_ep_vf.c | 2 + 6 files changed, 64 insertions(+), 16 deletions(-) diff --git a/doc/guides/rel_notes/release_24_11.rst b/doc/guides/rel_notes/release_24_11.rst index 0ff70d9057..ffb2d13a76 100644 --- a/doc/guides/rel_notes/release_24_11.rst +++ b/doc/guides/rel_notes/release_24_11.rst @@ -68,6 +68,11 @@ Removed Items Also, make sure to start the actual text at the margin. ======================================================= +* **Added device removal event callback in octeon_ep driver.** + + Added an event callback to catch any device removal event would occur during + driver probe. This callback helps in terminating the execution if there is + any device removal event during the driver probe. API Changes ----------- diff --git a/drivers/net/octeon_ep/cnxk_ep_vf.c b/drivers/net/octeon_ep/cnxk_ep_vf.c index 39b28de2d0..08058060d1 100644 --- a/drivers/net/octeon_ep/cnxk_ep_vf.c +++ b/drivers/net/octeon_ep/cnxk_ep_vf.c @@ -408,6 +408,8 @@ cnxk_ep_vf_setup_device(struct otx_ep_device *otx_ep) /* Get IOQs (RPVF] count */ reg_val = oct_ep_read64(otx_ep->hw_addr + CNXK_EP_R_IN_CONTROL(0)); + if (reg_val == UINT64_MAX) + return -ENODEV; otx_ep->sriov_info.rings_per_vf = ((reg_val >> CNXK_EP_R_IN_CTL_RPVF_POS) & CNXK_EP_R_IN_CTL_RPVF_MASK); diff --git a/drivers/net/octeon_ep/otx2_ep_vf.c b/drivers/net/octeon_ep/otx2_ep_vf.c index 2aeebb4675..480b032405 100644 --- a/drivers/net/octeon_ep/otx2_ep_vf.c +++ b/drivers/net/octeon_ep/otx2_ep_vf.c @@ -587,6 +587,8 @@ otx2_ep_vf_setup_device(struct otx_ep_device *otx_ep) /* Get IOQs (RPVF] count */ reg_val = oct_ep_read64(otx_ep->hw_addr + SDP_VF_R_IN_CONTROL(0)); + if (reg_val == UINT64_MAX) + return -ENODEV; otx_ep->sriov_info.rings_per_vf = ((reg_val >> SDP_VF_R_IN_CTL_RPVF_POS) & SDP_VF_R_IN_CTL_RPVF_MASK); diff --git a/drivers/net/octeon_ep/otx_ep_ethdev.c b/drivers/net/octeon_ep/otx_ep_ethdev.c index 196ed69123..3cf0aa4be5 100644 --- a/drivers/net/octeon_ep/otx_ep_ethdev.c +++ b/drivers/net/octeon_ep/otx_ep_ethdev.c @@ -319,7 +319,6 @@ otx_ep_chip_specific_setup(struct otx_ep_device *otx_epvf) case PCI_DEVID_OCTEONTX_EP_VF: otx_epvf->chip_id = dev_id; ret = otx_ep_vf_setup_device(otx_epvf); - otx_epvf->fn_list.disable_io_queues(otx_epvf); break; case PCI_DEVID_CN9K_EP_NET_VF: case PCI_DEVID_CN98XX_EP_NET_VF: @@ -327,9 +326,6 @@ otx_ep_chip_specific_setup(struct otx_ep_device *otx_epvf) case PCI_DEVID_CNF95O_EP_NET_VF: otx_epvf->chip_id = dev_id; ret = otx2_ep_vf_setup_device(otx_epvf); - otx_epvf->fn_list.disable_io_queues(otx_epvf); - if (otx_ep_ism_setup(otx_epvf)) - ret = -EINVAL; break; case PCI_DEVID_CN10KA_EP_NET_VF: case PCI_DEVID_CN10KB_EP_NET_VF: @@ -337,9 +333,6 @@ otx_ep_chip_specific_setup(struct otx_ep_device *otx_epvf) case PCI_DEVID_CNF10KB_EP_NET_VF: otx_epvf->chip_id = dev_id; ret = cnxk_ep_vf_setup_device(otx_epvf); - otx_epvf->fn_list.disable_io_queues(otx_epvf); - if (otx_ep_ism_setup(otx_epvf)) - ret = -EINVAL; break; default: otx_ep_err("Unsupported device\n"); @@ -348,6 +341,11 @@ otx_ep_chip_specific_setup(struct otx_ep_device *otx_epvf) if (!ret) otx_ep_info("OTX_EP dev_id[%d]\n", dev_id); + else + return ret; + + if (dev_id != PCI_DEVID_OCTEONTX_EP_VF) + ret = otx_ep_ism_setup(otx_epvf); return ret; } @@ -365,8 +363,6 @@ otx_epdev_init(struct otx_ep_device *otx_epvf) goto setup_fail; } - otx_epvf->fn_list.setup_device_regs(otx_epvf); - otx_epvf->eth_dev->tx_pkt_burst = &cnxk_ep_xmit_pkts; otx_epvf->eth_dev->rx_pkt_burst = &otx_ep_recv_pkts; if (otx_epvf->chip_id == PCI_DEVID_OCTEONTX_EP_VF) { @@ -416,6 +412,10 @@ otx_ep_dev_configure(struct rte_eth_dev *eth_dev) otx_ep_err("invalid num queues\n"); return -EINVAL; } + + otx_epvf->fn_list.setup_device_regs(otx_epvf); + otx_epvf->fn_list.disable_io_queues(otx_epvf); + otx_ep_info("OTX_EP Device is configured with num_txq %d num_rxq %d\n", eth_dev->data->nb_rx_queues, eth_dev->data->nb_tx_queues); @@ -734,6 +734,16 @@ otx_ep_eth_dev_uninit(struct rte_eth_dev *eth_dev) return 0; } +static void +otx_epdev_event_callback(const char *device_name, enum rte_dev_event_type type, + __rte_unused void *arg) +{ + if (type == RTE_DEV_EVENT_REMOVE) + otx_ep_info("Octeon epdev: %s has been removed!\n", device_name); + + RTE_VERIFY(type != RTE_DEV_EVENT_REMOVE); +} + static int otx_ep_eth_dev_query_set_vf_mac(struct rte_eth_dev *eth_dev, struct rte_ether_addr *mac_addr) { @@ -771,6 +781,7 @@ otx_ep_eth_dev_init(struct rte_eth_dev *eth_dev) struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(eth_dev); struct otx_ep_device *otx_epvf = OTX_EP_DEV(eth_dev); struct rte_ether_addr vf_mac_addr; + int ret = 0; /* Single process support */ if (rte_eal_process_type() != RTE_PROC_PRIMARY) { @@ -808,8 +819,16 @@ otx_ep_eth_dev_init(struct rte_eth_dev *eth_dev) otx_epvf->hw_addr = pdev->mem_resource[0].addr; otx_epvf->pdev = pdev; - if (otx_epdev_init(otx_epvf)) - return -ENOMEM; + if (rte_dev_event_callback_register(pdev->name, otx_epdev_event_callback, NULL)) { + otx_ep_err("Failed to register a device event callback\n"); + return -EINVAL; + } + + if (otx_epdev_init(otx_epvf)) { + ret = -ENOMEM; + goto exit; + } + if (otx_epvf->chip_id == PCI_DEVID_CN9K_EP_NET_VF || otx_epvf->chip_id == PCI_DEVID_CN98XX_EP_NET_VF || otx_epvf->chip_id == PCI_DEVID_CNF95N_EP_NET_VF || @@ -825,20 +844,27 @@ otx_ep_eth_dev_init(struct rte_eth_dev *eth_dev) otx_ep_info("Using pkind %d.\n", otx_epvf->pkind); } else { otx_ep_err("Invalid chip id\n"); - return -EINVAL; + ret = -EINVAL; + goto exit; } - if (otx_ep_mbox_init(eth_dev)) - return -EINVAL; + if (otx_ep_mbox_init(eth_dev)) { + ret = -EINVAL; + goto exit; + } if (otx_ep_eth_dev_query_set_vf_mac(eth_dev, (struct rte_ether_addr *)&vf_mac_addr)) { otx_ep_err("set mac addr failed\n"); - return -ENODEV; + ret = -ENODEV; + goto exit; } rte_ether_addr_copy(&vf_mac_addr, eth_dev->data->mac_addrs); - return 0; +exit: + rte_dev_event_callback_unregister(pdev->name, otx_epdev_event_callback, NULL); + + return ret; } static int diff --git a/drivers/net/octeon_ep/otx_ep_mbox.c b/drivers/net/octeon_ep/otx_ep_mbox.c index 0474419599..314a2bc6b4 100644 --- a/drivers/net/octeon_ep/otx_ep_mbox.c +++ b/drivers/net/octeon_ep/otx_ep_mbox.c @@ -31,6 +31,10 @@ __otx_ep_send_mbox_cmd(struct otx_ep_device *otx_ep, volatile uint64_t reg_val = 0ull; int count = 0; + reg_val = otx2_read64(otx_ep->hw_addr + CNXK_EP_R_MBOX_VF_PF_DATA(0)); + if (reg_val == UINT64_MAX) + return -ENODEV; + cmd.s.type = OTX_EP_MBOX_TYPE_CMD; otx2_write64(cmd.u64, otx_ep->hw_addr + CNXK_EP_R_MBOX_VF_PF_DATA(0)); @@ -41,6 +45,8 @@ __otx_ep_send_mbox_cmd(struct otx_ep_device *otx_ep, for (count = 0; count < OTX_EP_MBOX_TIMEOUT_MS; count++) { rte_delay_ms(1); reg_val = otx2_read64(otx_ep->hw_addr + CNXK_EP_R_MBOX_VF_PF_DATA(0)); + if (reg_val == UINT64_MAX) + return -ENODEV; if (reg_val != cmd.u64) { rsp->u64 = reg_val; break; @@ -351,6 +357,7 @@ otx_ep_mbox_init(struct rte_eth_dev *eth_dev) { struct otx_ep_device *otx_ep = (struct otx_ep_device *)eth_dev->data->dev_private; struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(eth_dev); + uint64_t reg_val; otx_ep_mbox_version_check(otx_ep); @@ -361,6 +368,10 @@ otx_ep_mbox_init(struct rte_eth_dev *eth_dev) return -1; } + reg_val = otx2_read64(otx_ep->hw_addr + CNXK_EP_R_MBOX_PF_VF_INT(0)); + if (reg_val == UINT64_MAX) + return -ENODEV; + /* Enable pf-vf mbox interrupt & clear the status */ otx2_write64(CNXK_EP_MBOX_ENAB | CNXK_EP_MBOX_INTR, otx_ep->hw_addr + CNXK_EP_R_MBOX_PF_VF_INT(0)); diff --git a/drivers/net/octeon_ep/otx_ep_vf.c b/drivers/net/octeon_ep/otx_ep_vf.c index 236b7a874c..d57f994af4 100644 --- a/drivers/net/octeon_ep/otx_ep_vf.c +++ b/drivers/net/octeon_ep/otx_ep_vf.c @@ -410,6 +410,8 @@ otx_ep_vf_setup_device(struct otx_ep_device *otx_ep) /* Get IOQs (RPVF] count */ reg_val = rte_read64(otx_ep->hw_addr + OTX_EP_R_IN_CONTROL(0)); + if (reg_val == UINT64_MAX) + return -ENODEV; otx_ep->sriov_info.rings_per_vf = ((reg_val >> OTX_EP_R_IN_CTL_RPVF_POS) & OTX_EP_R_IN_CTL_RPVF_MASK); -- 2.34.1