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 91BCEA0C46; Fri, 18 Jun 2021 12:41:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 46DB841166; Fri, 18 Jun 2021 12:39:56 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 710474113A for ; Fri, 18 Jun 2021 12:39:55 +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 15IAZv9O004568 for ; Fri, 18 Jun 2021 03:39:54 -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-type; s=pfpt0220; bh=WtJXUm+0OtrYN9C3y57UADA2MZNCBs05qZNeLP5Zx/E=; b=OAm1Y/8VmuB1NImWTCEbZJz5W34830SQPiRFeIo+qJMdC2YctrHEdRY+gl4HDuXujI5J EGFtgz3Qt0GGcSk3gVWn2iWxwwQxzvVQcDrXGAZW6wc+4rqfbB2UZO0XMaxs66BYZytD jN9/hqLbEI26ta+aq3upS/dny3xzoTBBiDF32w5HpxPn6roK2T3KsFweftcbj4g8r2Ux 8WTAHpD9u2en1goHFAUUrPFeVP94MrxhsArHAYSWDN84FXoMJvcYnbm2YxlnPbCkht2z 1BwCN603I5zrZokZSga9lw1NyG83aWqQsjwXlvxJwuKwJtD2viD540Qt2GDYXN5IbdUL iw== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 397udry7em-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 18 Jun 2021 03:39:54 -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.18; Fri, 18 Jun 2021 03:39:52 -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.18 via Frontend Transport; Fri, 18 Jun 2021 03:39:52 -0700 Received: from hyd1588t430.marvell.com (unknown [10.29.52.204]) by maili.marvell.com (Postfix) with ESMTP id 118685B6BBF; Fri, 18 Jun 2021 03:39:12 -0700 (PDT) From: Nithin Dabilpuram To: CC: , , , , , , , , "Nithin Dabilpuram" Date: Fri, 18 Jun 2021 16:06:53 +0530 Message-ID: <20210618103741.26526-15-ndabilpuram@marvell.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20210618103741.26526-1-ndabilpuram@marvell.com> References: <20210306153404.10781-1-ndabilpuram@marvell.com> <20210618103741.26526-1-ndabilpuram@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-ORIG-GUID: UqCaLjOTqLSRQkJf2PwrP-e8pU4hS_v5 X-Proofpoint-GUID: UqCaLjOTqLSRQkJf2PwrP-e8pU4hS_v5 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-06-18_04:2021-06-18, 2021-06-18 signatures=0 Subject: [dpdk-dev] [PATCH v3 14/62] net/cnxk: add link status update support 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 link status update callback to get current link status. Signed-off-by: Nithin Dabilpuram --- doc/guides/nics/cnxk.rst | 1 + doc/guides/nics/features/cnxk.ini | 2 + doc/guides/nics/features/cnxk_vec.ini | 2 + doc/guides/nics/features/cnxk_vf.ini | 2 + drivers/net/cnxk/cnxk_ethdev.c | 7 +++ drivers/net/cnxk/cnxk_ethdev.h | 8 +++ drivers/net/cnxk/cnxk_link.c | 102 ++++++++++++++++++++++++++++++++++ drivers/net/cnxk/meson.build | 3 +- 8 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 drivers/net/cnxk/cnxk_link.c diff --git a/doc/guides/nics/cnxk.rst b/doc/guides/nics/cnxk.rst index 0c2ea89..7bf6cf5 100644 --- a/doc/guides/nics/cnxk.rst +++ b/doc/guides/nics/cnxk.rst @@ -20,6 +20,7 @@ Features of the CNXK Ethdev PMD are: - Lock-free Tx queue - Multiple queues for TX and RX - Receiver Side Scaling (RSS) +- Link state information Prerequisites ------------- diff --git a/doc/guides/nics/features/cnxk.ini b/doc/guides/nics/features/cnxk.ini index 96dba2a..affbbd9 100644 --- a/doc/guides/nics/features/cnxk.ini +++ b/doc/guides/nics/features/cnxk.ini @@ -8,6 +8,8 @@ Speed capabilities = Y Lock-free Tx queue = Y SR-IOV = Y Multiprocess aware = Y +Link status = Y +Link status event = Y RSS hash = Y Inner RSS = Y Linux = Y diff --git a/doc/guides/nics/features/cnxk_vec.ini b/doc/guides/nics/features/cnxk_vec.ini index 616991c..836cc9f 100644 --- a/doc/guides/nics/features/cnxk_vec.ini +++ b/doc/guides/nics/features/cnxk_vec.ini @@ -8,6 +8,8 @@ Speed capabilities = Y Lock-free Tx queue = Y SR-IOV = Y Multiprocess aware = Y +Link status = Y +Link status event = Y RSS hash = Y Inner RSS = Y Linux = Y diff --git a/doc/guides/nics/features/cnxk_vf.ini b/doc/guides/nics/features/cnxk_vf.ini index a0bd2f1..29bb24f 100644 --- a/doc/guides/nics/features/cnxk_vf.ini +++ b/doc/guides/nics/features/cnxk_vf.ini @@ -7,6 +7,8 @@ Speed capabilities = Y Lock-free Tx queue = Y Multiprocess aware = Y +Link status = Y +Link status event = Y RSS hash = Y Inner RSS = Y Linux = Y diff --git a/drivers/net/cnxk/cnxk_ethdev.c b/drivers/net/cnxk/cnxk_ethdev.c index 14e28fe..002afdc 100644 --- a/drivers/net/cnxk/cnxk_ethdev.c +++ b/drivers/net/cnxk/cnxk_ethdev.c @@ -589,6 +589,7 @@ cnxk_nix_configure(struct rte_eth_dev *eth_dev) /* CNXK platform independent eth dev ops */ struct eth_dev_ops cnxk_eth_dev_ops = { .dev_infos_get = cnxk_nix_info_get, + .link_update = cnxk_nix_link_update, }; static int @@ -623,6 +624,9 @@ cnxk_eth_dev_init(struct rte_eth_dev *eth_dev) goto error; } + /* Register up msg callbacks */ + roc_nix_mac_link_cb_register(nix, cnxk_eth_dev_link_status_cb); + dev->eth_dev = eth_dev; dev->configured = 0; @@ -711,6 +715,9 @@ cnxk_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool mbox_close) roc_nix_npc_rx_ena_dis(nix, false); + /* Disable link status events */ + roc_nix_mac_link_event_start_stop(nix, false); + /* Free up SQs */ for (i = 0; i < eth_dev->data->nb_tx_queues; i++) { dev_ops->tx_queue_release(eth_dev->data->tx_queues[i]); diff --git a/drivers/net/cnxk/cnxk_ethdev.h b/drivers/net/cnxk/cnxk_ethdev.h index 291f5f9..daa87af 100644 --- a/drivers/net/cnxk/cnxk_ethdev.h +++ b/drivers/net/cnxk/cnxk_ethdev.h @@ -15,6 +15,9 @@ #define CNXK_ETH_DEV_PMD_VERSION "1.0" +/* Used for struct cnxk_eth_dev::flags */ +#define CNXK_LINK_CFG_IN_PROGRESS_F BIT_ULL(0) + /* VLAN tag inserted by NIX_TX_VTAG_ACTION. * In Tx space is always reserved for this in FRS. */ @@ -196,6 +199,11 @@ int cnxk_nix_configure(struct rte_eth_dev *eth_dev); uint32_t cnxk_rss_ethdev_to_nix(struct cnxk_eth_dev *dev, uint64_t ethdev_rss, uint8_t rss_level); +/* Link */ +void cnxk_eth_dev_link_status_cb(struct roc_nix *nix, + struct roc_nix_link_info *link); +int cnxk_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete); + /* Devargs */ int cnxk_ethdev_parse_devargs(struct rte_devargs *devargs, struct cnxk_eth_dev *dev); diff --git a/drivers/net/cnxk/cnxk_link.c b/drivers/net/cnxk/cnxk_link.c new file mode 100644 index 0000000..b0273e7 --- /dev/null +++ b/drivers/net/cnxk/cnxk_link.c @@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2021 Marvell. + */ + +#include "cnxk_ethdev.h" + +static inline int +nix_wait_for_link_cfg(struct cnxk_eth_dev *dev) +{ + uint16_t wait = 1000; + + do { + rte_atomic_thread_fence(__ATOMIC_ACQUIRE); + if (!(dev->flags & CNXK_LINK_CFG_IN_PROGRESS_F)) + break; + wait--; + rte_delay_ms(1); + } while (wait); + + return wait ? 0 : -1; +} + +static void +nix_link_status_print(struct rte_eth_dev *eth_dev, struct rte_eth_link *link) +{ + if (link && link->link_status) + plt_info("Port %d: Link Up - speed %u Mbps - %s", + (int)(eth_dev->data->port_id), + (uint32_t)link->link_speed, + link->link_duplex == ETH_LINK_FULL_DUPLEX + ? "full-duplex" + : "half-duplex"); + else + plt_info("Port %d: Link Down", (int)(eth_dev->data->port_id)); +} + +void +cnxk_eth_dev_link_status_cb(struct roc_nix *nix, struct roc_nix_link_info *link) +{ + struct cnxk_eth_dev *dev = (struct cnxk_eth_dev *)nix; + struct rte_eth_link eth_link; + struct rte_eth_dev *eth_dev; + + if (!link || !nix) + return; + + eth_dev = dev->eth_dev; + if (!eth_dev || !eth_dev->data->dev_conf.intr_conf.lsc) + return; + + if (nix_wait_for_link_cfg(dev)) { + plt_err("Timeout waiting for link_cfg to complete"); + return; + } + + eth_link.link_status = link->status; + eth_link.link_speed = link->speed; + eth_link.link_autoneg = ETH_LINK_AUTONEG; + eth_link.link_duplex = link->full_duplex; + + /* Print link info */ + nix_link_status_print(eth_dev, ð_link); + + /* Update link info */ + rte_eth_linkstatus_set(eth_dev, ð_link); + + /* Set the flag and execute application callbacks */ + rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL); +} + +int +cnxk_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct roc_nix_link_info info; + struct rte_eth_link link; + int rc; + + RTE_SET_USED(wait_to_complete); + memset(&link, 0, sizeof(struct rte_eth_link)); + + if (roc_nix_is_sdp(&dev->nix)) + return 0; + + if (roc_nix_is_lbk(&dev->nix)) { + link.link_status = ETH_LINK_UP; + link.link_speed = ETH_SPEED_NUM_100G; + link.link_autoneg = ETH_LINK_FIXED; + link.link_duplex = ETH_LINK_FULL_DUPLEX; + } else { + rc = roc_nix_mac_link_info_get(&dev->nix, &info); + if (rc) + return rc; + link.link_status = info.status; + link.link_speed = info.speed; + link.link_autoneg = ETH_LINK_AUTONEG; + if (info.full_duplex) + link.link_duplex = info.full_duplex; + } + + return rte_eth_linkstatus_set(eth_dev, &link); +} diff --git a/drivers/net/cnxk/meson.build b/drivers/net/cnxk/meson.build index 8495732..1ac3d08 100644 --- a/drivers/net/cnxk/meson.build +++ b/drivers/net/cnxk/meson.build @@ -10,7 +10,8 @@ endif sources = files('cnxk_ethdev.c', 'cnxk_ethdev_ops.c', - 'cnxk_ethdev_devargs.c') + 'cnxk_ethdev_devargs.c', + 'cnxk_link.c') # CN9K sources += files('cn9k_ethdev.c') -- 2.8.4