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 AC60FA0547; Fri, 5 Mar 2021 14:43:30 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 558F322A372; Fri, 5 Mar 2021 14:40:36 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id C90ED22A3CB for ; Fri, 5 Mar 2021 14:40:34 +0100 (CET) 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 125DdkA0008295 for ; Fri, 5 Mar 2021 05:40:34 -0800 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=gfUKr2VWXmnQYNbjxP9NKnI7f0W6rQ4EBmsBquL9weA=; b=fZjj3eDNi3iVFrlQyzNyBpOnsgM2naTpC2ZJbz/ZffUFWoEtycJ4h0u51ts3UqDTSo48 G9s+pUt9LdAAbM7AajJS4ykdSmEKBpJRREHozqIXYjePrnuZ6NGPlmN/Zt4cyThJ83JC 0llq357DZuSQRi45I8oRZD5l4FrQU2Az/F3azOe0uUmBnWbb1hWY9wfuFvZyRyPGCJib fbjFyOlDa+ATQ29wb4lFKiFD3Nx3YNIGyTrCUPWwaNpMiMI1U9y+EBFY1ciQXmWKKQZe AvQgaUK7jcR4/dzqnD3eU9SP1vaj9Hw6ZBETkQNJKZRFFpftgz2Nc6U5cy4HO4TYTZmx vw== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 370p7p0dd4-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 05 Mar 2021 05:40:34 -0800 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; Fri, 5 Mar 2021 05:40:32 -0800 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; Fri, 5 Mar 2021 05:40:32 -0800 Received: from hyd1588t430.marvell.com (unknown [10.29.52.204]) by maili.marvell.com (Postfix) with ESMTP id 976B63F7040; Fri, 5 Mar 2021 05:40:29 -0800 (PST) From: Nithin Dabilpuram To: CC: , , , , , , Date: Fri, 5 Mar 2021 19:08:47 +0530 Message-ID: <20210305133918.8005-22-ndabilpuram@marvell.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20210305133918.8005-1-ndabilpuram@marvell.com> References: <20210305133918.8005-1-ndabilpuram@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369, 18.0.761 definitions=2021-03-05_08:2021-03-03, 2021-03-05 signatures=0 Subject: [dpdk-dev] [PATCH 21/52] common/cnxk: add nix MAC operations 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" From: Sunil Kumar Kori Add support to different MAC related operations such as MAC address set/get, link set/get, link status callback, etc. Signed-off-by: Sunil Kumar Kori --- drivers/common/cnxk/meson.build | 1 + drivers/common/cnxk/roc_nix.h | 41 ++++++ drivers/common/cnxk/roc_nix_mac.c | 298 ++++++++++++++++++++++++++++++++++++++ drivers/common/cnxk/version.map | 15 ++ 4 files changed, 355 insertions(+) create mode 100644 drivers/common/cnxk/roc_nix_mac.c diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build index ebd659d..21d9ad3 100644 --- a/drivers/common/cnxk/meson.build +++ b/drivers/common/cnxk/meson.build @@ -18,6 +18,7 @@ sources = files('roc_dev.c', 'roc_model.c', 'roc_nix.c', 'roc_nix_irq.c', + 'roc_nix_mac.c', 'roc_nix_queue.c', 'roc_npa.c', 'roc_npa_debug.c', diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h index a6221d2..a2910b8 100644 --- a/drivers/common/cnxk/roc_nix.h +++ b/drivers/common/cnxk/roc_nix.h @@ -100,6 +100,23 @@ struct roc_nix_sq { void *fc; }; +struct roc_nix_link_info { + uint64_t status : 1; + uint64_t full_duplex : 1; + uint64_t lmac_type_id : 4; + uint64_t speed : 20; + uint64_t autoneg : 1; + uint64_t fec : 2; + uint64_t port : 8; +}; + +/* Link status update callback */ +typedef void (*link_status_t)(struct roc_nix *roc_nix, + struct roc_nix_link_info *link); + +/* PTP info update callback */ +typedef int (*ptp_info_update_t)(struct roc_nix *roc_nix, bool enable); + struct roc_nix { /* Input parameters */ struct plt_pci_device *pci_dev; @@ -152,6 +169,30 @@ void __roc_api roc_nix_unregister_queue_irqs(struct roc_nix *roc_nix); int __roc_api roc_nix_register_cq_irqs(struct roc_nix *roc_nix); void __roc_api roc_nix_unregister_cq_irqs(struct roc_nix *roc_nix); +/* MAC */ +int __roc_api roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start); +int __roc_api roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix, + bool start); +int __roc_api roc_nix_mac_loopback_enable(struct roc_nix *roc_nix, bool enable); +int __roc_api roc_nix_mac_addr_set(struct roc_nix *roc_nix, + const uint8_t addr[]); +int __roc_api roc_nix_mac_max_entries_get(struct roc_nix *roc_nix); +int __roc_api roc_nix_mac_addr_add(struct roc_nix *roc_nix, uint8_t addr[]); +int __roc_api roc_nix_mac_addr_del(struct roc_nix *roc_nix, uint32_t index); +int __roc_api roc_nix_mac_promisc_mode_enable(struct roc_nix *roc_nix, + int enable); +int __roc_api roc_nix_mac_link_state_set(struct roc_nix *roc_nix, uint8_t up); +int __roc_api roc_nix_mac_link_info_set(struct roc_nix *roc_nix, + struct roc_nix_link_info *link_info); +int __roc_api roc_nix_mac_link_info_get(struct roc_nix *roc_nix, + struct roc_nix_link_info *link_info); +int __roc_api roc_nix_mac_mtu_set(struct roc_nix *roc_nix, uint16_t mtu); +int __roc_api roc_nix_mac_max_rx_len_set(struct roc_nix *roc_nix, + uint16_t maxlen); +int __roc_api roc_nix_mac_link_cb_register(struct roc_nix *roc_nix, + link_status_t link_update); +void __roc_api roc_nix_mac_link_cb_unregister(struct roc_nix *roc_nix); + /* Queue */ int __roc_api roc_nix_rq_init(struct roc_nix *roc_nix, struct roc_nix_rq *rq, bool ena); diff --git a/drivers/common/cnxk/roc_nix_mac.c b/drivers/common/cnxk/roc_nix_mac.c new file mode 100644 index 0000000..bedd95b --- /dev/null +++ b/drivers/common/cnxk/roc_nix_mac.c @@ -0,0 +1,298 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell. + */ + +#include "roc_api.h" +#include "roc_priv.h" + +static inline struct mbox * +nix_to_mbox(struct nix *nix) +{ + struct dev *dev = &nix->dev; + + return dev->mbox; +} + +int +roc_nix_mac_rxtx_start_stop(struct roc_nix *roc_nix, bool start) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + + if (roc_nix_is_vf_or_sdp(roc_nix)) + return NIX_ERR_OP_NOTSUP; + + if (start) + mbox_alloc_msg_cgx_start_rxtx(mbox); + else + mbox_alloc_msg_cgx_stop_rxtx(mbox); + + return mbox_process(mbox); +} + +int +roc_nix_mac_link_event_start_stop(struct roc_nix *roc_nix, bool start) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + + if (roc_nix_is_vf_or_sdp(roc_nix)) + return NIX_ERR_OP_NOTSUP; + + if (start) + mbox_alloc_msg_cgx_start_linkevents(mbox); + else + mbox_alloc_msg_cgx_stop_linkevents(mbox); + + return mbox_process(mbox); +} + +int +roc_nix_mac_loopback_enable(struct roc_nix *roc_nix, bool enable) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + + if (enable && roc_nix_is_vf_or_sdp(roc_nix)) + return NIX_ERR_OP_NOTSUP; + + if (enable) + mbox_alloc_msg_cgx_intlbk_enable(mbox); + else + mbox_alloc_msg_cgx_intlbk_disable(mbox); + + return mbox_process(mbox); +} + +int +roc_nix_mac_addr_set(struct roc_nix *roc_nix, const uint8_t addr[]) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + struct cgx_mac_addr_set_or_get *req; + + if (roc_nix_is_vf_or_sdp(roc_nix)) + return NIX_ERR_OP_NOTSUP; + + if (dev_active_vfs(&nix->dev)) + return NIX_ERR_OP_NOTSUP; + + req = mbox_alloc_msg_cgx_mac_addr_set(mbox); + mbox_memcpy(req->mac_addr, addr, PLT_ETHER_ADDR_LEN); + + return mbox_process(mbox); +} + +int +roc_nix_mac_max_entries_get(struct roc_nix *roc_nix) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct cgx_max_dmac_entries_get_rsp *rsp; + struct mbox *mbox = nix_to_mbox(nix); + int rc; + + if (roc_nix_is_vf_or_sdp(roc_nix)) + return NIX_ERR_OP_NOTSUP; + + mbox_alloc_msg_cgx_mac_max_entries_get(mbox); + rc = mbox_process_msg(mbox, (void *)&rsp); + if (rc) + return rc; + + return rsp->max_dmac_filters ? rsp->max_dmac_filters : 1; +} + +int +roc_nix_mac_addr_add(struct roc_nix *roc_nix, uint8_t addr[]) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + struct cgx_mac_addr_add_req *req; + struct cgx_mac_addr_add_rsp *rsp; + int rc; + + if (roc_nix_is_vf_or_sdp(roc_nix)) + return NIX_ERR_OP_NOTSUP; + + if (dev_active_vfs(&nix->dev)) + return NIX_ERR_OP_NOTSUP; + + req = mbox_alloc_msg_cgx_mac_addr_add(mbox); + mbox_memcpy(req->mac_addr, addr, PLT_ETHER_ADDR_LEN); + + rc = mbox_process_msg(mbox, (void *)&rsp); + if (rc < 0) + return rc; + + return rsp->index; +} + +int +roc_nix_mac_addr_del(struct roc_nix *roc_nix, uint32_t index) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + struct cgx_mac_addr_del_req *req; + int rc = -ENOSPC; + + if (roc_nix_is_vf_or_sdp(roc_nix)) + return NIX_ERR_OP_NOTSUP; + + req = mbox_alloc_msg_cgx_mac_addr_del(mbox); + if (req == NULL) + return rc; + req->index = index; + + return mbox_process(mbox); +} + +int +roc_nix_mac_promisc_mode_enable(struct roc_nix *roc_nix, int enable) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + + if (roc_nix_is_vf_or_sdp(roc_nix)) + return NIX_ERR_OP_NOTSUP; + + if (enable) + mbox_alloc_msg_cgx_promisc_enable(mbox); + else + mbox_alloc_msg_cgx_promisc_disable(mbox); + + return mbox_process(mbox); +} + +int +roc_nix_mac_link_info_get(struct roc_nix *roc_nix, + struct roc_nix_link_info *link_info) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + struct cgx_link_info_msg *rsp; + int rc; + + mbox_alloc_msg_cgx_get_linkinfo(mbox); + rc = mbox_process_msg(mbox, (void *)&rsp); + if (rc) + return rc; + + link_info->status = rsp->link_info.link_up; + link_info->full_duplex = rsp->link_info.full_duplex; + link_info->lmac_type_id = rsp->link_info.lmac_type_id; + link_info->speed = rsp->link_info.speed; + link_info->autoneg = rsp->link_info.an; + link_info->fec = rsp->link_info.fec; + link_info->port = rsp->link_info.port; + + return 0; +} + +int +roc_nix_mac_link_state_set(struct roc_nix *roc_nix, uint8_t up) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + struct cgx_set_link_state_msg *req; + int rc = -ENOSPC; + + req = mbox_alloc_msg_cgx_set_link_state(mbox); + if (req == NULL) + return rc; + req->enable = up; + return mbox_process(mbox); +} + +int +roc_nix_mac_link_info_set(struct roc_nix *roc_nix, + struct roc_nix_link_info *link_info) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + struct cgx_set_link_mode_req *req; + int rc; + + rc = roc_nix_mac_link_state_set(roc_nix, link_info->status); + if (rc) + return rc; + + req = mbox_alloc_msg_cgx_set_link_mode(mbox); + if (req == NULL) + return -ENOSPC; + req->args.speed = link_info->speed; + req->args.duplex = link_info->full_duplex; + req->args.an = link_info->autoneg; + + return mbox_process(mbox); +} + +int +roc_nix_mac_mtu_set(struct roc_nix *roc_nix, uint16_t mtu) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + struct nix_frs_cfg *req; + bool sdp_link = false; + int rc = -ENOSPC; + + if (roc_nix_is_sdp(roc_nix)) + sdp_link = true; + + req = mbox_alloc_msg_nix_set_hw_frs(mbox); + if (req == NULL) + return rc; + req->maxlen = mtu; + req->update_smq = true; + req->sdp_link = sdp_link; + + rc = mbox_process(mbox); + if (rc) + return rc; + + /* Save MTU for later use */ + nix->mtu = mtu; + return 0; +} + +int +roc_nix_mac_max_rx_len_set(struct roc_nix *roc_nix, uint16_t maxlen) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct mbox *mbox = nix_to_mbox(nix); + struct nix_frs_cfg *req; + bool sdp_link = false; + int rc = -ENOSPC; + + if (roc_nix_is_sdp(roc_nix)) + sdp_link = true; + + req = mbox_alloc_msg_nix_set_hw_frs(mbox); + if (req == NULL) + return rc; + req->sdp_link = sdp_link; + req->maxlen = maxlen; + + return mbox_process(mbox); +} + +int +roc_nix_mac_link_cb_register(struct roc_nix *roc_nix, link_status_t link_update) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct dev *dev = &nix->dev; + + if (link_update == NULL) + return NIX_ERR_PARAM; + + dev->ops->link_status_update = (link_info_t)link_update; + return 0; +} + +void +roc_nix_mac_link_cb_unregister(struct roc_nix *roc_nix) +{ + struct nix *nix = roc_nix_to_nix_priv(roc_nix); + struct dev *dev = &nix->dev; + + dev->ops->link_status_update = NULL; +} diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map index a25fe15..4d63514 100644 --- a/drivers/common/cnxk/version.map +++ b/drivers/common/cnxk/version.map @@ -30,6 +30,21 @@ INTERNAL { roc_nix_is_vf_or_sdp; roc_nix_lf_alloc; roc_nix_lf_free; + roc_nix_mac_addr_add; + roc_nix_mac_addr_del; + roc_nix_mac_addr_set; + roc_nix_mac_link_cb_register; + roc_nix_mac_link_cb_unregister; + roc_nix_mac_link_event_start_stop; + roc_nix_mac_link_info_get; + roc_nix_mac_link_info_set; + roc_nix_mac_link_state_set; + roc_nix_mac_loopback_enable; + roc_nix_mac_max_entries_get; + roc_nix_mac_max_rx_len_set; + roc_nix_mac_mtu_set; + roc_nix_mac_promisc_mode_enable; + roc_nix_mac_rxtx_start_stop; roc_nix_max_pkt_len; roc_nix_ras_intr_ena_dis; roc_nix_register_cq_irqs; -- 2.8.4