From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B6973A0559; Mon, 16 Mar 2020 10:35:24 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8D3DF1C0BE; Mon, 16 Mar 2020 10:34:58 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 335B01C06D for ; Mon, 16 Mar 2020 10:34:55 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02G9UN1I015039; Mon, 16 Mar 2020 02:34: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 : content-type : mime-version; s=pfpt0818; bh=V0HCLKT5hT9tTanNSE5re4VqfD7QNYu6ClOffaK5afE=; b=GPhCamNGFRihS+hKQhQwIYGff3P9z1OD8ivknLVgbN3h+xwB27S3H+yCEnok6EryX2vv gDaK8m6jdAVDovN/yQoxJmmp9TRIoJUN3iXFIML+nLAHQdBkHnOmLgfn4BBz9/KWhlyP WkOLIPNY3nHCM2HNGr5mZHUW8a1xvETFTlmIdvul7ecN9YgbaFqgJQNiLkh452DHc9kk 6tpJmfFQHTyPWsBl5mv34MlREDpB6o+hVNo6fWIEAVKs2psvkgyxkSsWXVLN4fXv+5+P wtyzMQ8Ntxat7egC94Ij/v+NG0yFdG3uwSfI4rSEFNWK90FZj0LxKGPl78RMIDMcKikY IQ== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 2yrxsme52d-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2020 02:34:54 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 16 Mar 2020 02:34:52 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.169) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Mon, 16 Mar 2020 02:34:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FN/Mq4HFrvWPTz5sPykkOaJXzHTZ4epWLMxizOOirBw0Z5nxME2GHKZHI8cc+cD7w4rHl1EG8bsLnFO7uNjK6RmuUdCnuKD4uR4BZDKvDUSlIH0X8UXrzoEuhz9+qQa44ofnDY4i3eE0Is3OlLMaUgGGizOlj8gytuk2GjvmXIa4n2w3xfgcVbQ4NLCVORDkD1viO1o1lUShFmg6N1SR8m+/y6l0RSdnW0Xms/a4D9yalsrG4wRxh1B4Uu9vXGvD738kgc0Vz8I2pdJe0BguRvOGpZN/84M2JlZNBcoXnzMsIoScriJ/N9+MHKN8GdRFNRUuU4Dum+fE69XpdBHJKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=V0HCLKT5hT9tTanNSE5re4VqfD7QNYu6ClOffaK5afE=; b=amBqf6ZdpoR3S07ah04yc4J4l8O2C8cGbPOnsIGpw78ChNqwc7UZ7qaMaL2qXoiUuzGdmxpuRq3Ss8aP3t8Hqsq3kfbMI+DNiJIWQV/g/ZeeS/uk1AE7w+BX5TPTPuLpDavgmlIHTs91Dcmu0e/x2waGdMSs3HhUaFb2NM/RACh8RTNo9ot/1OauQh2cmrGmTpspuLvxGX+qyVRBZViaogkSSWTBE010SHlRgl3wa8HX/APAAg9VHzuJ7ncPlxe0o8HTt7AyRIefuitEc53YiNTSjirGxDK4pgkX4482NWZ7zeckkd1V0la5oFhZo/FXrjIxmHiqkfc8dDdFTSrdQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=V0HCLKT5hT9tTanNSE5re4VqfD7QNYu6ClOffaK5afE=; b=O56DkY1Ny1/+An7oVdzG/eNzaAwhf8MMiVyvYn0yQhrd/efVg2czIF9wknsdV31u+c+820eujb37ISA0GbMy5a8UNhsMcfNawMiaDNOTXwWGDq3tI+dLlD4bXvnT56hc4TlGAHDqUveP6TjVslcJlP+rEfFo0SRUBRCRjpx7OCU= Received: from MN2PR18MB2848.namprd18.prod.outlook.com (2603:10b6:208:38::19) by MN2PR18MB3117.namprd18.prod.outlook.com (2603:10b6:208:162::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.14; Mon, 16 Mar 2020 09:34:50 +0000 Received: from MN2PR18MB2848.namprd18.prod.outlook.com ([fe80::f829:3e55:94f6:4efb]) by MN2PR18MB2848.namprd18.prod.outlook.com ([fe80::f829:3e55:94f6:4efb%5]) with mapi id 15.20.2814.021; Mon, 16 Mar 2020 09:34:50 +0000 From: Harman Kalra To: , , CC: , Date: Mon, 16 Mar 2020 15:03:41 +0530 Message-ID: <1584351224-23500-6-git-send-email-hkalra@marvell.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1584351224-23500-1-git-send-email-hkalra@marvell.com> References: <1584351224-23500-1-git-send-email-hkalra@marvell.com> Content-Type: text/plain X-ClientProxiedBy: BMXPR01CA0006.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:d::16) To MN2PR18MB2848.namprd18.prod.outlook.com (2603:10b6:208:38::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from hkarlara-OptiPlex-3046.marvell.com (115.113.156.2) by BMXPR01CA0006.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2814.13 via Frontend Transport; Mon, 16 Mar 2020 09:34:36 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [115.113.156.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d36c4178-6c07-48ec-b7ef-08d7c98d3ecc X-MS-TrafficTypeDiagnostic: MN2PR18MB3117: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:114; X-Forefront-PRVS: 03449D5DD1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(366004)(136003)(376002)(39860400002)(346002)(396003)(199004)(52116002)(7696005)(478600001)(4326008)(8676002)(8936002)(107886003)(26005)(66556008)(30864003)(2906002)(86362001)(5660300002)(36756003)(55236004)(16526019)(2616005)(956004)(66946007)(6486002)(66476007)(81156014)(81166006)(6666004)(186003)(316002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB3117; H:MN2PR18MB2848.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7d/2Nxz3/aY/86QRmxpaUFtHZt/wEI9YquP3VePLPmo0OytK2wtemyMGv10XG8lURWVNrwjaTVhSZjsNKdtKM8coiOm4Lo9Q5xtUlMffYVkek4YwpWX6zybKrf6JGhIrZ1NMsKELsdNXithLnC3CIsAOIB5WAbdcfWkzuOBKbBDaKrJBmrzHb8Z1f+n5o/BwFiIe/Wvm5EyeAprU5y0bW3Esq+8pHV3tj4kHU02jPkdU3voqQLed0/JQvlPIy93BaxxuYTNLse81u6E3OVj0eURKZZa20YnMmiobEOaV6MMd+/acTciuml+g9SJvb8AhzL2wesFoVcX8AAuj0Sc76rgQvUMFb10anzfvldDq67TnCjyb/wy/hlXjxsm8V6bzebxph/JmFHKNplj1A7nyFXbZvWfsv50qxdjXw1P+RUKb60r9/uSXmY2V1ONdhf1x X-MS-Exchange-AntiSpam-MessageData: HfyEBKwDanqjtzjvszyS+t8nnXJ4s7rcJNeWyS13mPqm8NxhCOgqV123Fc7pPrdz7tWJlxdCnya1qXI/PN1sQGNe3/pQ7PM3J7agpVlbYc2+Exa5dvyM3lUVatfWvsxkM/FNL7zi0cG+eOyrq9LJNA== X-MS-Exchange-CrossTenant-Network-Message-Id: d36c4178-6c07-48ec-b7ef-08d7c98d3ecc X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2020 09:34:37.9029 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UorcgcAaEfY5VVoqlBvofYepUOi4xPJYbxrPHlSUmBq1ftx7pOTFKt2Qv+y0fTCAkTV2kYSF88mtHQzNiFhnvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB3117 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-16_02:2020-03-12, 2020-03-16 signatures=0 Subject: [dpdk-dev] [PATCH 5/8] net/octeontx: add VLAN filter offload support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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: Vamsi Attunuru Patch adds support for vlan filter offload support. MBOX messages for vlan filter on/off and vlan filter entry add/rm are added to configure PCAM entries to filter out the vlan traffic on a given port. Patch also defines rx_offload_flag for vlan filtering. Signed-off-by: Vamsi Attunuru --- doc/guides/nics/features/octeontx.ini | 2 + doc/guides/nics/octeontx.rst | 1 + drivers/net/octeontx/Makefile | 1 + drivers/net/octeontx/base/octeontx_pkivf.c | 40 +++++ drivers/net/octeontx/base/octeontx_pkivf.h | 20 +++ drivers/net/octeontx/meson.build | 3 +- drivers/net/octeontx/octeontx_ethdev.c | 10 ++ drivers/net/octeontx/octeontx_ethdev.h | 24 ++- drivers/net/octeontx/octeontx_ethdev_ops.c | 184 +++++++++++++++++++++ drivers/net/octeontx/octeontx_rxtx.h | 1 + 10 files changed, 284 insertions(+), 2 deletions(-) create mode 100644 drivers/net/octeontx/octeontx_ethdev_ops.c diff --git a/doc/guides/nics/features/octeontx.ini b/doc/guides/nics/features/octeontx.ini index e3ee79f0f..53c541f4b 100644 --- a/doc/guides/nics/features/octeontx.ini +++ b/doc/guides/nics/features/octeontx.ini @@ -13,6 +13,8 @@ Jumbo frame = Y Scattered Rx = Y Promiscuous mode = Y Unicast MAC filter = Y +VLAN filter = Y +VLAN offload = P CRC offload = Y Packet type parsing = Y Basic stats = Y diff --git a/doc/guides/nics/octeontx.rst b/doc/guides/nics/octeontx.rst index ddb626bc3..c8655bf37 100644 --- a/doc/guides/nics/octeontx.rst +++ b/doc/guides/nics/octeontx.rst @@ -22,6 +22,7 @@ Features of the OCTEON TX Ethdev PMD are: - Jumbo frames - Scatter-Gather IO support - Link state information +- MAC/VLAN filtering - MTU update - SR-IOV VF - Multiple queues for TX diff --git a/drivers/net/octeontx/Makefile b/drivers/net/octeontx/Makefile index 8ddfc3089..694f403f1 100644 --- a/drivers/net/octeontx/Makefile +++ b/drivers/net/octeontx/Makefile @@ -28,6 +28,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_OCTEONTX_PMD) += octeontx_pkovf.c SRCS-$(CONFIG_RTE_LIBRTE_OCTEONTX_PMD) += octeontx_pkivf.c SRCS-$(CONFIG_RTE_LIBRTE_OCTEONTX_PMD) += octeontx_bgx.c SRCS-$(CONFIG_RTE_LIBRTE_OCTEONTX_PMD) += octeontx_ethdev.c +SRCS-$(CONFIG_RTE_LIBRTE_OCTEONTX_PMD) += octeontx_ethdev_ops.c ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y) CFLAGS_octeontx_rxtx.o += -fno-prefetch-loop-arrays diff --git a/drivers/net/octeontx/base/octeontx_pkivf.c b/drivers/net/octeontx/base/octeontx_pkivf.c index 8ce041955..0ddff5488 100644 --- a/drivers/net/octeontx/base/octeontx_pkivf.c +++ b/drivers/net/octeontx/base/octeontx_pkivf.c @@ -136,6 +136,46 @@ octeontx_pki_port_errchk_config(int port, pki_errchk_cfg_t *cfg) return res; } +int +octeontx_pki_port_vlan_fltr_config(int port, + pki_port_vlan_filter_config_t *fltr_cfg) +{ + struct octeontx_mbox_hdr hdr; + int res; + + pki_port_vlan_filter_config_t cfg = *fltr_cfg; + int len = sizeof(pki_port_vlan_filter_config_t); + + hdr.coproc = OCTEONTX_PKI_COPROC; + hdr.msg = MBOX_PKI_PORT_VLAN_FILTER_CONFIG; + hdr.vfid = port; + + res = octeontx_mbox_send(&hdr, &cfg, len, NULL, 0); + if (res < 0) + return -EACCES; + return res; +} + +int +octeontx_pki_port_vlan_fltr_entry_config(int port, + pki_port_vlan_filter_entry_config_t *e_cfg) +{ + struct octeontx_mbox_hdr hdr; + int res; + + pki_port_vlan_filter_entry_config_t cfg = *e_cfg; + int len = sizeof(pki_port_vlan_filter_entry_config_t); + + hdr.coproc = OCTEONTX_PKI_COPROC; + hdr.msg = MBOX_PKI_PORT_VLAN_FILTER_ENTRY_CONFIG; + hdr.vfid = port; + + res = octeontx_mbox_send(&hdr, &cfg, len, NULL, 0); + if (res < 0) + return -EACCES; + return res; +} + #define PCI_VENDOR_ID_CAVIUM 0x177D #define PCI_DEVICE_ID_OCTEONTX_PKI_VF 0xA0DD diff --git a/drivers/net/octeontx/base/octeontx_pkivf.h b/drivers/net/octeontx/base/octeontx_pkivf.h index d541dc3bd..d41eaa57e 100644 --- a/drivers/net/octeontx/base/octeontx_pkivf.h +++ b/drivers/net/octeontx/base/octeontx_pkivf.h @@ -36,6 +36,8 @@ #define MBOX_PKI_PORT_ALLOC_QPG 21 #define MBOX_PKI_PORT_FREE_QPG 22 #define MBOX_PKI_SET_PORT_CONFIG 23 +#define MBOX_PKI_PORT_VLAN_FILTER_CONFIG 24 +#define MBOX_PKI_PORT_VLAN_FILTER_ENTRY_CONFIG 25 #define MBOX_PKI_MAX_QOS_ENTRY 64 @@ -236,6 +238,20 @@ typedef struct pki_port_modify_qos_entry { struct pki_qos_entry qos_entry; } pki_mod_qos_t; +/* pki port VLAN filter config */ +typedef struct pki_port_vlan_filter_config { + uint8_t port_type; /* OCTTX_PORT_TYPE_[NET/INT/PCI] */ + uint8_t fltr_conf; /* '1' to enable & '0' to disable */ +} pki_port_vlan_filter_config_t; + +/* pki port VLAN filter entry config */ +typedef struct pki_port_vlan_filter_entry_config { + uint8_t port_type; /* OCTTX_PORT_TYPE_[NET/INT/PCI] */ + uint8_t entry_conf; /* '1' to add & '0' to remove */ + uint16_t vlan_tpid; /* in host byte-order */ + uint16_t vlan_id; /* in host byte-order */ +} pki_port_vlan_filter_entry_config_t; + static inline int octeontx_pki_port_modify_qos(int port, pki_mod_qos_t *qos_cfg) { @@ -348,5 +364,9 @@ int octeontx_pki_port_pktbuf_config(int port, pki_pktbuf_cfg_t *buf_cfg); int octeontx_pki_port_create_qos(int port, pki_qos_cfg_t *qos_cfg); int octeontx_pki_port_close(int port); int octeontx_pki_port_errchk_config(int port, pki_errchk_cfg_t *cfg); +int octeontx_pki_port_vlan_fltr_config(int port, + pki_port_vlan_filter_config_t *fltr_cfg); +int octeontx_pki_port_vlan_fltr_entry_config(int port, + pki_port_vlan_filter_entry_config_t *entry_cfg); #endif /* __OCTEONTX_PKI_H__ */ diff --git a/drivers/net/octeontx/meson.build b/drivers/net/octeontx/meson.build index 0e249eb98..f7ba6e68b 100644 --- a/drivers/net/octeontx/meson.build +++ b/drivers/net/octeontx/meson.build @@ -5,7 +5,8 @@ subdir('base') objs = [base_objs] sources = files('octeontx_rxtx.c', - 'octeontx_ethdev.c' + 'octeontx_ethdev.c', + 'octeontx_ethdev_ops.c' ) allow_experimental_apis = true diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c index 91b9ea645..5dd40bc04 100644 --- a/drivers/net/octeontx/octeontx_ethdev.c +++ b/drivers/net/octeontx/octeontx_ethdev.c @@ -360,6 +360,12 @@ octeontx_dev_configure(struct rte_eth_dev *dev) return -EFAULT; } + ret = octeontx_dev_vlan_offload_init(dev); + if (ret) { + octeontx_log_err("failed to initialize vlan offload"); + return -EFAULT; + } + nic->pki.classifier_enable = false; nic->pki.hash_enable = true; nic->pki.initialized = false; @@ -384,6 +390,8 @@ octeontx_dev_close(struct rte_eth_dev *dev) rte_event_dev_close(nic->evdev); + octeontx_dev_vlan_offload_fini(dev); + ret = octeontx_pko_channel_close(nic->base_ochan); if (ret < 0) { octeontx_log_err("failed to close channel %d VF%d %d %d", @@ -1185,6 +1193,8 @@ static const struct eth_dev_ops octeontx_dev_ops = { .mac_addr_remove = octeontx_dev_mac_addr_del, .mac_addr_add = octeontx_dev_mac_addr_add, .mac_addr_set = octeontx_dev_default_mac_addr_set, + .vlan_offload_set = octeontx_dev_vlan_offload_set, + .vlan_filter_set = octeontx_dev_vlan_filter_set, .tx_queue_start = octeontx_dev_tx_queue_start, .tx_queue_stop = octeontx_dev_tx_queue_stop, .tx_queue_setup = octeontx_dev_tx_queue_setup, diff --git a/drivers/net/octeontx/octeontx_ethdev.h b/drivers/net/octeontx/octeontx_ethdev.h index 27f6556dd..e7e0d40c7 100644 --- a/drivers/net/octeontx/octeontx_ethdev.h +++ b/drivers/net/octeontx/octeontx_ethdev.h @@ -55,7 +55,8 @@ #define OCTEONTX_RX_OFFLOADS (DEV_RX_OFFLOAD_CHECKSUM | \ DEV_RX_OFFLOAD_SCATTER | \ - DEV_RX_OFFLOAD_JUMBO_FRAME) + DEV_RX_OFFLOAD_JUMBO_FRAME | \ + DEV_RX_OFFLOAD_VLAN_FILTER) #define OCTEONTX_TX_OFFLOADS (DEV_TX_OFFLOAD_MT_LOCKFREE | \ DEV_TX_OFFLOAD_MBUF_FAST_FREE | \ @@ -70,6 +71,18 @@ octeontx_pmd_priv(struct rte_eth_dev *dev) extern uint16_t rte_octeontx_pchan_map[OCTEONTX_MAX_BGX_PORTS][OCTEONTX_MAX_LMAC_PER_BGX]; +struct vlan_entry { + TAILQ_ENTRY(vlan_entry) next; + uint16_t vlan_id; +}; + +TAILQ_HEAD(octeontx_vlan_filter_tbl, vlan_entry); + +struct octeontx_vlan_info { + struct octeontx_vlan_filter_tbl fltr_tbl; + uint8_t filter_on; +}; + /* Octeontx ethdev nic */ struct octeontx_nic { struct rte_eth_dev *dev; @@ -107,6 +120,7 @@ struct octeontx_nic { uint16_t rx_offload_flags; uint64_t tx_offloads; uint16_t tx_offload_flags; + struct octeontx_vlan_info vlan_info; } __rte_cache_aligned; struct octeontx_txq { @@ -127,4 +141,12 @@ struct octeontx_rxq { void octeontx_set_tx_function(struct rte_eth_dev *dev); + +/* VLAN */ +int octeontx_dev_vlan_offload_init(struct rte_eth_dev *dev); +int octeontx_dev_vlan_offload_fini(struct rte_eth_dev *eth_dev); +int octeontx_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask); +int octeontx_dev_vlan_filter_set(struct rte_eth_dev *dev, + uint16_t vlan_id, int on); + #endif /* __OCTEONTX_ETHDEV_H__ */ diff --git a/drivers/net/octeontx/octeontx_ethdev_ops.c b/drivers/net/octeontx/octeontx_ethdev_ops.c new file mode 100644 index 000000000..8c3065542 --- /dev/null +++ b/drivers/net/octeontx/octeontx_ethdev_ops.c @@ -0,0 +1,184 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#include + +#include "octeontx_ethdev.h" +#include "octeontx_logs.h" +#include "octeontx_rxtx.h" + +static int +octeontx_vlan_hw_filter(struct octeontx_nic *nic, uint8_t flag) +{ + struct octeontx_vlan_info *vlan = &nic->vlan_info; + pki_port_vlan_filter_config_t fltr_conf; + int rc = 0; + + if (vlan->filter_on == flag) + return rc; + + fltr_conf.port_type = OCTTX_PORT_TYPE_NET; + fltr_conf.fltr_conf = flag; + + rc = octeontx_pki_port_vlan_fltr_config(nic->port_id, &fltr_conf); + if (rc != 0) { + octeontx_log_err("Fail to configure vlan hw filter for port %d", + nic->port_id); + goto done; + } + + vlan->filter_on = flag; + +done: + return rc; +} + +int +octeontx_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask) +{ + struct octeontx_nic *nic = octeontx_pmd_priv(dev); + struct rte_eth_rxmode *rxmode; + int rc = 0; + + rxmode = &dev->data->dev_conf.rxmode; + + if (mask & ETH_VLAN_EXTEND_MASK) { + octeontx_log_err("Extend offload not supported"); + return -ENOTSUP; + } + + if (mask & ETH_VLAN_STRIP_MASK) { + octeontx_log_err("VLAN strip offload not supported"); + return -ENOTSUP; + } + + if (mask & ETH_VLAN_FILTER_MASK) { + if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER) { + rc = octeontx_vlan_hw_filter(nic, true); + if (rc) + goto done; + + nic->rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER; + nic->rx_offload_flags |= OCCTX_RX_VLAN_FLTR_F; + } else { + rc = octeontx_vlan_hw_filter(nic, false); + if (rc) + goto done; + + nic->rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER; + nic->rx_offload_flags &= ~OCCTX_RX_VLAN_FLTR_F; + } + } + +done: + return rc; +} + +int +octeontx_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on) +{ + struct octeontx_nic *nic = octeontx_pmd_priv(dev); + struct octeontx_vlan_info *vlan = &nic->vlan_info; + pki_port_vlan_filter_entry_config_t fltr_entry; + struct vlan_entry *entry = NULL; + int entry_count = 0; + int rc = -EINVAL; + + if (on) { + TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) + if (entry->vlan_id == vlan_id) { + octeontx_log_dbg("Vlan Id is already set"); + return 0; + } + } else { + TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) + entry_count++; + + if (!entry_count) + return 0; + } + + fltr_entry.port_type = OCTTX_PORT_TYPE_NET; + fltr_entry.vlan_tpid = RTE_ETHER_TYPE_VLAN; + fltr_entry.vlan_id = vlan_id; + fltr_entry.entry_conf = on; + + if (on) { + entry = rte_zmalloc("octeontx_nic_vlan_entry", + sizeof(struct vlan_entry), 0); + if (!entry) { + octeontx_log_err("Failed to allocate memory"); + return -ENOMEM; + } + } + + rc = octeontx_pki_port_vlan_fltr_entry_config(nic->port_id, + &fltr_entry); + if (rc != 0) { + octeontx_log_err("Fail to configure vlan filter entry " + "for port %d", nic->port_id); + if (entry) + rte_free(entry); + + goto done; + } + + if (on) { + entry->vlan_id = vlan_id; + TAILQ_INSERT_HEAD(&vlan->fltr_tbl, entry, next); + } else { + TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) { + if (entry->vlan_id == vlan_id) { + TAILQ_REMOVE(&vlan->fltr_tbl, entry, next); + rte_free(entry); + break; + } + } + } + +done: + return rc; +} + +int +octeontx_dev_vlan_offload_init(struct rte_eth_dev *dev) +{ + struct octeontx_nic *nic = octeontx_pmd_priv(dev); + int rc; + + TAILQ_INIT(&nic->vlan_info.fltr_tbl); + + rc = octeontx_dev_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK); + if (rc) + octeontx_log_err("Failed to set vlan offload rc=%d", rc); + + return rc; +} + +int +octeontx_dev_vlan_offload_fini(struct rte_eth_dev *dev) +{ + struct octeontx_nic *nic = octeontx_pmd_priv(dev); + struct octeontx_vlan_info *vlan = &nic->vlan_info; + pki_port_vlan_filter_entry_config_t fltr_entry; + struct vlan_entry *entry; + int rc = 0; + + TAILQ_FOREACH(entry, &vlan->fltr_tbl, next) { + fltr_entry.port_type = OCTTX_PORT_TYPE_NET; + fltr_entry.vlan_tpid = RTE_ETHER_TYPE_VLAN; + fltr_entry.vlan_id = entry->vlan_id; + fltr_entry.entry_conf = 0; + + rc = octeontx_pki_port_vlan_fltr_entry_config(nic->port_id, + &fltr_entry); + if (rc != 0) { + octeontx_log_err("Fail to configure vlan filter entry " + "for port %d", nic->port_id); + break; + } + } + + return rc; +} diff --git a/drivers/net/octeontx/octeontx_rxtx.h b/drivers/net/octeontx/octeontx_rxtx.h index 2383a8eb6..cc044dd79 100644 --- a/drivers/net/octeontx/octeontx_rxtx.h +++ b/drivers/net/octeontx/octeontx_rxtx.h @@ -19,6 +19,7 @@ #define OCCTX_RX_OFFLOAD_NONE (0) #define OCCTX_RX_OFFLOAD_RSS_F BIT(0) +#define OCCTX_RX_VLAN_FLTR_F BIT(1) #define OCCTX_RX_MULTI_SEG_F BIT(15) #define OCCTX_TX_OFFLOAD_NONE (0) -- 2.18.0