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 2CCACA04FF; Tue, 24 May 2022 10:43:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8F65D42B79; Tue, 24 May 2022 10:43:13 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id C720542B71 for ; Tue, 24 May 2022 10:43:11 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24O7iwf4017461 for ; Tue, 24 May 2022 01:43:11 -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=8/2bqHwY8EGrM26rA6CVUV82ELB9LBeglWZp62HHGvQ=; b=NerKKfgRR8OHvcVLsXwBZ/mJuQ636N0+kyZLd53GQc4EIlyUGnB20u230AKe/Y5WBO0V JknkYYaiFXgVB4ZTt175aI9XgU3f2hc9APMd/1mH+hNVFZvqzq2mDxSfbBG/rEtQfOos Ip1+FdN2xQosd88DP5nTobYhV0IN4UYFYxpgULvVoZwx8kXocNM0yAMpWUXvsKEJAIM7 Y3jRdKoNP7spwkMwb9+5hV8eBDhsDMEc2/6eqnVPwzkzPM6fInDI29LCQIsji/xcFOo2 hYp/Hs+DtOwgRvvUXdDMQqEKXUr0XWBFKohrb4MjefmIZlc0LI/8Njl3oA+uFiYn5+H9 aQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3g6ykm1r5q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 24 May 2022 01:43:10 -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; Tue, 24 May 2022 01:43:08 -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; Tue, 24 May 2022 01:43:08 -0700 Received: from localhost.localdomain (unknown [10.29.52.211]) by maili.marvell.com (Postfix) with ESMTP id D64AA3F709B; Tue, 24 May 2022 01:43:06 -0700 (PDT) From: Harman Kalra To: , Jerin Jacob , Maciej Czekaj CC: Harman Kalra Subject: [PATCH v3 07/11] net/thunderx: setting link attributes Date: Tue, 24 May 2022 14:12:31 +0530 Message-ID: <20220524084235.17796-7-hkalra@marvell.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220524084235.17796-1-hkalra@marvell.com> References: <20220517173941.189330-2-hkalra@marvell.com> <20220524084235.17796-1-hkalra@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: ZjIHxfUzWXasYd41VXiTtSFKer0cfDMR X-Proofpoint-ORIG-GUID: ZjIHxfUzWXasYd41VXiTtSFKer0cfDMR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-24_05,2022-05-23_01,2022-02-23_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 Adding support to configure link attributes like speed, duplex, negotiation. Signed-off-by: Harman Kalra --- drivers/net/thunderx/base/nicvf_mbox.c | 16 +++++ drivers/net/thunderx/base/nicvf_mbox.h | 14 ++++ drivers/net/thunderx/nicvf_ethdev.c | 88 ++++++++++++++++++++++++-- drivers/net/thunderx/nicvf_struct.h | 9 +++ 4 files changed, 122 insertions(+), 5 deletions(-) diff --git a/drivers/net/thunderx/base/nicvf_mbox.c b/drivers/net/thunderx/base/nicvf_mbox.c index 275e593286..352b85d9e2 100644 --- a/drivers/net/thunderx/base/nicvf_mbox.c +++ b/drivers/net/thunderx/base/nicvf_mbox.c @@ -423,6 +423,22 @@ nicvf_mbox_set_link_up_down(struct nicvf *nic, bool enable) mbx.lbk.enable = enable; return nicvf_mbox_send_msg_to_pf(nic, &mbx); } + + +int +nicvf_mbox_change_mode(struct nicvf *nic, struct change_link_mode *cfg) +{ + struct nic_mbx mbx = { .msg = { 0 } }; + + mbx.mode.msg = NIC_MBOX_MSG_CHANGE_MODE; + mbx.mode.vf_id = nic->vf_id; + mbx.mode.speed = cfg->speed; + mbx.mode.duplex = cfg->duplex; + mbx.mode.autoneg = cfg->autoneg; + mbx.mode.qlm_mode = cfg->qlm_mode; + return nicvf_mbox_send_msg_to_pf(nic, &mbx); +} + void nicvf_mbox_shutdown(struct nicvf *nic) { diff --git a/drivers/net/thunderx/base/nicvf_mbox.h b/drivers/net/thunderx/base/nicvf_mbox.h index 044220a2cd..322c8159cb 100644 --- a/drivers/net/thunderx/base/nicvf_mbox.h +++ b/drivers/net/thunderx/base/nicvf_mbox.h @@ -41,6 +41,7 @@ #define NIC_MBOX_MSG_LOOPBACK 0x16 /* Set interface in loopback */ #define NIC_MBOX_MSG_RESET_STAT_COUNTER 0x17 /* Reset statistics counters */ #define NIC_MBOX_MSG_SET_LINK 0x21 /* Set link up/down */ +#define NIC_MBOX_MSG_CHANGE_MODE 0x22 /* Change mode */ #define NIC_MBOX_MSG_CFG_DONE 0xF0 /* VF configuration done */ #define NIC_MBOX_MSG_SHUTDOWN 0xF1 /* VF is being shutdown */ #define NIC_MBOX_MSG_RESET_XCAST 0xF2 /* Reset DCAM filtering mode */ @@ -178,6 +179,17 @@ struct set_link_state { bool enable; }; +/* Change link mode */ +struct change_link_mode_msg { + uint8_t msg; + uint8_t vf_id; + uint8_t qlm_mode; + bool autoneg; + uint8_t duplex; + uint32_t speed; + +}; + struct nic_mbx { /* 128 bit shared memory between PF and each VF */ union { @@ -196,6 +208,7 @@ union { struct set_loopback lbk; struct reset_stat_cfg reset_stat; struct set_link_state set_link; + struct change_link_mode_msg mode; }; }; @@ -225,5 +238,6 @@ void nicvf_mbox_shutdown(struct nicvf *nic); void nicvf_mbox_cfg_done(struct nicvf *nic); void nicvf_mbox_link_change(struct nicvf *nic); void nicvf_mbox_reset_xcast(struct nicvf *nic); +int nicvf_mbox_change_mode(struct nicvf *nic, struct change_link_mode *cfg); #endif /* __THUNDERX_NICVF_MBOX__ */ diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c index 1e268d9b0f..0f79b02172 100644 --- a/drivers/net/thunderx/nicvf_ethdev.c +++ b/drivers/net/thunderx/nicvf_ethdev.c @@ -55,6 +55,82 @@ RTE_LOG_REGISTER_SUFFIX(nicvf_logtype_mbox, mbox, NOTICE); RTE_LOG_REGISTER_SUFFIX(nicvf_logtype_init, init, NOTICE); RTE_LOG_REGISTER_SUFFIX(nicvf_logtype_driver, driver, NOTICE); +#define NICVF_QLM_MODE_SGMII 7 +#define NICVF_QLM_MODE_XFI 12 + +enum nicvf_link_speed { + NICVF_LINK_SPEED_SGMII, + NICVF_LINK_SPEED_XAUI, + NICVF_LINK_SPEED_RXAUI, + NICVF_LINK_SPEED_10G_R, + NICVF_LINK_SPEED_40G_R, + NICVF_LINK_SPEED_RESERVE1, + NICVF_LINK_SPEED_QSGMII, + NICVF_LINK_SPEED_RESERVE2, + NICVF_LINK_SPEED_UNKNOWN = 255 +}; + +static inline uint32_t +nicvf_parse_link_speeds(uint32_t link_speeds) +{ + uint32_t link_speed = NICVF_LINK_SPEED_UNKNOWN; + + if (link_speeds & RTE_ETH_LINK_SPEED_40G) + link_speed = NICVF_LINK_SPEED_40G_R; + + if (link_speeds & RTE_ETH_LINK_SPEED_10G) { + link_speed = NICVF_LINK_SPEED_XAUI; + link_speed |= NICVF_LINK_SPEED_RXAUI; + link_speed |= NICVF_LINK_SPEED_10G_R; + } + + if (link_speeds & RTE_ETH_LINK_SPEED_5G) + link_speed = NICVF_LINK_SPEED_QSGMII; + + if (link_speeds & RTE_ETH_LINK_SPEED_1G) + link_speed = NICVF_LINK_SPEED_SGMII; + + return link_speed; +} + +static inline uint8_t +nicvf_parse_eth_link_duplex(uint32_t link_speeds) +{ + if ((link_speeds & RTE_ETH_LINK_SPEED_10M_HD) || + (link_speeds & RTE_ETH_LINK_SPEED_100M_HD)) + return RTE_ETH_LINK_HALF_DUPLEX; + else + return RTE_ETH_LINK_FULL_DUPLEX; +} + +static int +nicvf_apply_link_speed(struct rte_eth_dev *dev) +{ + struct nicvf *nic = nicvf_pmd_priv(dev); + struct rte_eth_conf *conf = &dev->data->dev_conf; + struct change_link_mode cfg; + if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) + /* TODO: Handle this case */ + return 0; + + cfg.speed = nicvf_parse_link_speeds(conf->link_speeds); + cfg.autoneg = (conf->link_speeds & RTE_ETH_LINK_SPEED_FIXED) ? 1 : 0; + cfg.duplex = nicvf_parse_eth_link_duplex(conf->link_speeds); + cfg.qlm_mode = ((conf->link_speeds & RTE_ETH_LINK_SPEED_1G) ? + NICVF_QLM_MODE_SGMII : + (conf->link_speeds & RTE_ETH_LINK_SPEED_10G) ? + NICVF_QLM_MODE_XFI : 0); + + if (cfg.speed != NICVF_LINK_SPEED_UNKNOWN && + (cfg.speed != nic->speed || cfg.duplex != nic->duplex)) { + nic->speed = cfg.speed; + nic->duplex = cfg.duplex; + return nicvf_mbox_change_mode(nic, &cfg); + } else { + return 0; + } +} + static void nicvf_link_status_update(struct nicvf *nic, struct rte_eth_link *link) @@ -1728,6 +1804,13 @@ nicvf_dev_start(struct rte_eth_dev *dev) return -EBUSY; } + /* Apply new link configurations if changed */ + ret = nicvf_apply_link_speed(dev); + if (ret) { + PMD_INIT_LOG(ERR, "Failed to set link configuration\n"); + return ret; + } + ret = nicvf_vf_start(dev, nic, rbdrsz); if (ret != 0) return ret; @@ -1921,11 +2004,6 @@ nicvf_dev_configure(struct rte_eth_dev *dev) return -EINVAL; } - if (conf->link_speeds & RTE_ETH_LINK_SPEED_FIXED) { - PMD_INIT_LOG(INFO, "Setting link speed/duplex not supported"); - return -EINVAL; - } - if (conf->dcb_capability_en) { PMD_INIT_LOG(INFO, "DCB enable not supported"); return -EINVAL; diff --git a/drivers/net/thunderx/nicvf_struct.h b/drivers/net/thunderx/nicvf_struct.h index c7ea13313e..13cf8feeb1 100644 --- a/drivers/net/thunderx/nicvf_struct.h +++ b/drivers/net/thunderx/nicvf_struct.h @@ -113,4 +113,13 @@ struct nicvf { struct nicvf *snicvf[MAX_SQS_PER_VF]; } __rte_cache_aligned; +struct change_link_mode { + bool enable; + uint8_t qlm_mode; + bool autoneg; + uint8_t duplex; + uint32_t speed; + +}; + #endif /* _THUNDERX_NICVF_STRUCT_H */ -- 2.18.0