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 768574586F; Tue, 27 Aug 2024 07:33:10 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFB8D402DD; Tue, 27 Aug 2024 07:33:09 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 11F2F4027F for ; Tue, 27 Aug 2024 07:33:08 +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 47QN0QJu021844 for ; Mon, 26 Aug 2024 22:33:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=pfpt0220; bh=YEgX+PsKfrr/j0LmRuGZvv6 eRsdGF6IcgWoxPuOHgyE=; b=atnRtsCkzOKlMvk951x8W2fnJ/L6g4iJ3eHAXQE 19/+JbWqpBRuTEFZlbVlrmpztGSAWM5U/xhnt9d1mPZRKHAecpzjvJZyE1vhR0ua fq/UJWzjckRdMKrtCpqsgeeVztPdZ10JeI3qXSmP9gNOEbv1T0xllfmVMOIdpc76 a5+HC9I36e/TXsgF8dhiPm4atx9mHYEMqLNhhwtLin5yNqTA5DoPlB4wZuV3Je0Q y2rbc8hTXr+op8g4VEUaXwZ1ho9vp1JNMpD6rdO/V+Pbyw/3NXchZaTGmICcloxq Nhr1r1MYcjZddE6glxMzZ6Hz7o6rzgkFohiCsxC8iq5v20A== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 418sy43gnh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 26 Aug 2024 22:33:08 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 26 Aug 2024 22:33:06 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 26 Aug 2024 22:33:06 -0700 Received: from cavium-VAMSI-BM.. (unknown [10.28.36.156]) by maili.marvell.com (Postfix) with ESMTP id 3F42E5C68E4; Mon, 26 Aug 2024 22:33:04 -0700 (PDT) From: Vamsi Krishna To: CC: , Subject: [PATCH] net/octeon_ep: add device removal event callback Date: Tue, 27 Aug 2024 11:02:59 +0530 Message-ID: <20240827053259.12033-1-vattunuru@marvell.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: LLuZX0k4BEP6czeRFeHJrs1-PAK2bjLD X-Proofpoint-GUID: LLuZX0k4BEP6czeRFeHJrs1-PAK2bjLD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-27_04,2024-08-26_01,2024-05-17_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 Patch 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. Patch also moves 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 --- Depends-on: patch-142958 ("net/octeon_ep: extend mailbox functionality") 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 + 5 files changed, 59 insertions(+), 16 deletions(-) diff --git a/drivers/net/octeon_ep/cnxk_ep_vf.c b/drivers/net/octeon_ep/cnxk_ep_vf.c index 39b28de2d0..68b89fce4f 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_t)-1) + 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..34f7d59b19 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_t)-1) + 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..ad8e21c75f 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_t)-1) + 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_t)-1) + 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_t)-1) + 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..935f63e917 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_t)-1) + 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