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 00B43A0524; Mon, 31 May 2021 23:43:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B99EA4114A; Mon, 31 May 2021 23:42:27 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id E1018410E8 for ; Mon, 31 May 2021 23:42:25 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14VLeJBH002825 for ; Mon, 31 May 2021 14:42:25 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=YjGu4J17HN8RysSh+i4WQuh75C4cEL8HTmf5ZEh1IUs=; b=aV2+xJ0+qnxX/YT/uNZWYO32yGrdNNnSlPYf3Eq9t4TPFBBOYLzSm95uBjk52HHoHVVm f/+0MtOZTZci3y9Iz+ce47v+/z8JWevte2NVqfWwpm7vk2g9OPLJGuRzKzezNU2TqK7x dX12rOeN40dRHqQy9Izft1KoqyFvE2MK26tZ/GYcNmpcsTdsQmBuwCDac+ThccwiafwO RORDw4SzeipEQ0l24ovS/ESWycarj5jVTacbMqMxcwy0HQDSjZU5wgiVSkdCyEl7LQX4 aOnXO/IAZCgTaWUtk/BCZMp9IJ/uQy6wqTfj2dfmCOLSsXKa7rnFGMSMCOoo/We3mN5S 3w== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 38vtnja12v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 31 May 2021 14:42:25 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 31 May 2021 14:42:23 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 31 May 2021 14:42:23 -0700 Received: from EH-LT0048.marvell.com (unknown [10.193.32.52]) by maili.marvell.com (Postfix) with ESMTP id 3278E3F7040; Mon, 31 May 2021 14:42:22 -0700 (PDT) From: Tomasz Duszynski To: CC: , , Tomasz Duszynski Date: Mon, 31 May 2021 23:41:28 +0200 Message-ID: <20210531214142.30167-15-tduszynski@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210531214142.30167-1-tduszynski@marvell.com> References: <20210531214142.30167-1-tduszynski@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: msJ_9t7DyT5DRqrtXn1xUD7OmgcTnagS X-Proofpoint-ORIG-GUID: msJ_9t7DyT5DRqrtXn1xUD7OmgcTnagS X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-31_15:2021-05-31, 2021-05-31 signatures=0 Subject: [dpdk-dev] [PATCH 14/28] raw/cnxk_bphy: add support for performing selftest 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 Sender: "dev" Add support for performing selftest operation. Signed-off-by: Tomasz Duszynski Signed-off-by: Jakub Palider --- drivers/raw/cnxk_bphy/cnxk_bphy_cgx.c | 2 + drivers/raw/cnxk_bphy/cnxk_bphy_cgx.h | 10 + drivers/raw/cnxk_bphy/cnxk_bphy_cgx_test.c | 206 +++++++++++++++++++++ drivers/raw/cnxk_bphy/meson.build | 1 + 4 files changed, 219 insertions(+) create mode 100644 drivers/raw/cnxk_bphy/cnxk_bphy_cgx.h create mode 100644 drivers/raw/cnxk_bphy/cnxk_bphy_cgx_test.c diff --git a/drivers/raw/cnxk_bphy/cnxk_bphy_cgx.c b/drivers/raw/cnxk_bphy/cnxk_bphy_cgx.c index a8eafae1b..3da224414 100644 --- a/drivers/raw/cnxk_bphy/cnxk_bphy_cgx.c +++ b/drivers/raw/cnxk_bphy/cnxk_bphy_cgx.c @@ -9,6 +9,7 @@ #include +#include "cnxk_bphy_cgx.h" #include "rte_pmd_bphy.h" struct cnxk_bphy_cgx_queue { @@ -196,6 +197,7 @@ static const struct rte_rawdev_ops cnxk_bphy_cgx_rawdev_ops = { .enqueue_bufs = cnxk_bphy_cgx_enqueue_bufs, .dequeue_bufs = cnxk_bphy_cgx_dequeue_bufs, .queue_count = cnxk_bphy_cgx_queue_count, + .dev_selftest = cnxk_bphy_cgx_dev_selftest, }; static void diff --git a/drivers/raw/cnxk_bphy/cnxk_bphy_cgx.h b/drivers/raw/cnxk_bphy/cnxk_bphy_cgx.h new file mode 100644 index 000000000..cd14a3850 --- /dev/null +++ b/drivers/raw/cnxk_bphy/cnxk_bphy_cgx.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2021 Marvell International Ltd. + */ + +#ifndef _CNXK_BPHY_CGX_H_ +#define _CNXK_BPHY_CGX_H_ + +int cnxk_bphy_cgx_dev_selftest(uint16_t dev_id); + +#endif /* _CNXK_BPHY_CGX_H_ */ diff --git a/drivers/raw/cnxk_bphy/cnxk_bphy_cgx_test.c b/drivers/raw/cnxk_bphy/cnxk_bphy_cgx_test.c new file mode 100644 index 000000000..cb4dd4b22 --- /dev/null +++ b/drivers/raw/cnxk_bphy/cnxk_bphy_cgx_test.c @@ -0,0 +1,206 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2021 Marvell. + */ +#include + +#include +#include +#include +#include + +#include "cnxk_bphy_cgx.h" +#include "rte_pmd_bphy.h" + +static int +cnxk_bphy_cgx_enq_msg(uint16_t dev_id, unsigned int queue, void *msg) +{ + struct rte_rawdev_buf *bufs[1]; + struct rte_rawdev_buf buf; + void *q; + int ret; + + q = (void *)(size_t)queue; + buf.buf_addr = msg; + bufs[0] = &buf; + + ret = rte_rawdev_enqueue_buffers(dev_id, bufs, 1, q); + if (ret < 0) + return ret; + if (ret != 1) + return -EIO; + + return 0; +} + +static int +cnxk_bphy_cgx_deq_msg(uint16_t dev_id, unsigned int queue, void **msg) +{ + struct rte_rawdev_buf *bufs[1]; + struct rte_rawdev_buf buf; + void *q; + int ret; + + q = (void *)(size_t)queue; + bufs[0] = &buf; + + ret = rte_rawdev_dequeue_buffers(dev_id, bufs, 1, q); + if (ret < 0) + return ret; + if (ret != 1) + return -EIO; + + *msg = buf.buf_addr; + + return 0; +} + +static int +cnxk_bphy_cgx_link_cond(uint16_t dev_id, unsigned int queue, int cond) +{ + int tries = 10, ret; + + do { + struct cnxk_bphy_cgx_msg_link_info *link_info = NULL; + struct cnxk_bphy_cgx_msg msg; + + msg.type = CNXK_BPHY_CGX_MSG_TYPE_GET_LINKINFO; + ret = cnxk_bphy_cgx_enq_msg(dev_id, queue, &msg); + if (ret) + return ret; + + ret = cnxk_bphy_cgx_deq_msg(dev_id, queue, (void **)&link_info); + if (ret) + return ret; + + if (link_info->link_up == cond) { + rte_free(link_info); + break; + } + + rte_free(link_info); + rte_delay_ms(500); + } while (--tries); + + if (tries) + return !!cond; + + return -ETIMEDOUT; +} + +int +cnxk_bphy_cgx_dev_selftest(uint16_t dev_id) +{ + unsigned int queues, i; + int ret; + + queues = rte_rawdev_queue_count(dev_id); + if (queues == 0) + return -ENODEV; + + ret = rte_rawdev_start(dev_id); + if (ret) + return ret; + + for (i = 0; i < queues; i++) { + struct cnxk_bphy_cgx_msg_set_link_state link_state; + struct cnxk_bphy_cgx_msg msg; + unsigned int descs; + + ret = rte_rawdev_queue_conf_get(dev_id, i, &descs, + sizeof(descs)); + if (ret) + break; + if (descs != 1) { + RTE_LOG(ERR, PMD, "Wrong number of descs reported\n"); + ret = -ENODEV; + break; + } + + RTE_LOG(INFO, PMD, "Testing queue %d\n", i); + + /* stop rx/tx */ + msg.type = CNXK_BPHY_CGX_MSG_TYPE_STOP_RXTX; + ret = cnxk_bphy_cgx_enq_msg(dev_id, i, &msg); + if (ret) { + RTE_LOG(ERR, PMD, "Failed to stop rx/tx\n"); + break; + } + + /* start rx/tx */ + msg.type = CNXK_BPHY_CGX_MSG_TYPE_START_RXTX; + ret = cnxk_bphy_cgx_enq_msg(dev_id, i, &msg); + if (ret) { + RTE_LOG(ERR, PMD, "Failed to start rx/tx\n"); + break; + } + + /* set link down */ + link_state.state = false; + msg.type = CNXK_BPHY_CGX_MSG_TYPE_SET_LINK_STATE; + msg.data = &link_state; + ret = cnxk_bphy_cgx_enq_msg(dev_id, i, &msg); + if (ret) { + RTE_LOG(ERR, PMD, "Failed to set link down\n"); + break; + } + + ret = cnxk_bphy_cgx_link_cond(dev_id, i, 0); + if (ret != 0) + RTE_LOG(ERR, PMD, + "Timed out waiting for a link down\n"); + + /* set link up */ + link_state.state = true; + msg.type = CNXK_BPHY_CGX_MSG_TYPE_SET_LINK_STATE; + msg.data = &link_state; + ret = cnxk_bphy_cgx_enq_msg(dev_id, i, &msg); + if (ret) { + RTE_LOG(ERR, PMD, "Failed to set link up\n"); + break; + } + + ret = cnxk_bphy_cgx_link_cond(dev_id, i, 1); + if (ret != 1) + RTE_LOG(ERR, PMD, "Timed out waiting for a link up\n"); + + /* enable internal loopback */ + msg.type = CNXK_BPHY_CGX_MSG_TYPE_INTLBK_ENABLE; + ret = cnxk_bphy_cgx_enq_msg(dev_id, i, &msg); + if (ret) { + RTE_LOG(ERR, PMD, "Failed to enable internal lbk\n"); + break; + } + + /* disable internal loopback */ + msg.type = CNXK_BPHY_CGX_MSG_TYPE_INTLBK_DISABLE; + ret = cnxk_bphy_cgx_enq_msg(dev_id, i, &msg); + if (ret) { + RTE_LOG(ERR, PMD, "Failed to disable internal lbk\n"); + break; + } + + /* enable ptp */ + msg.type = CNXK_BPHY_CGX_MSG_TYPE_PTP_RX_ENABLE; + ret = cnxk_bphy_cgx_enq_msg(dev_id, i, &msg); + /* ptp not available on RPM */ + if (ret < 0 && ret != -ENOTSUP) { + RTE_LOG(ERR, PMD, "Failed to enable ptp\n"); + break; + } + ret = 0; + + /* disable ptp */ + msg.type = CNXK_BPHY_CGX_MSG_TYPE_PTP_RX_DISABLE; + ret = cnxk_bphy_cgx_enq_msg(dev_id, i, &msg); + /* ptp not available on RPM */ + if (ret < 0 && ret != -ENOTSUP) { + RTE_LOG(ERR, PMD, "Failed to disable ptp\n"); + break; + } + ret = 0; + } + + rte_rawdev_stop(dev_id); + + return ret; +} diff --git a/drivers/raw/cnxk_bphy/meson.build b/drivers/raw/cnxk_bphy/meson.build index c47ba2449..2fab7c0ec 100644 --- a/drivers/raw/cnxk_bphy/meson.build +++ b/drivers/raw/cnxk_bphy/meson.build @@ -5,5 +5,6 @@ deps += ['bus_pci', 'common_cnxk', 'rawdev'] sources = files( 'cnxk_bphy_cgx.c', + 'cnxk_bphy_cgx_test.c' ) headers = files('rte_pmd_bphy.h') -- 2.25.1