From patchwork Wed Aug 18 06:19:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoliang Yang X-Patchwork-Id: 499602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDA25C432BE for ; Wed, 18 Aug 2021 06:09:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9B9B6108F for ; Wed, 18 Aug 2021 06:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240195AbhHRGKC (ORCPT ); Wed, 18 Aug 2021 02:10:02 -0400 Received: from inva021.nxp.com ([92.121.34.21]:60110 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239189AbhHRGJJ (ORCPT ); Wed, 18 Aug 2021 02:09:09 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 85278204922; Wed, 18 Aug 2021 08:08:33 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 4CE9D204928; Wed, 18 Aug 2021 08:08:33 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 3295C183AD15; Wed, 18 Aug 2021 14:08:31 +0800 (+08) From: Xiaoliang Yang To: davem@davemloft.net, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: allan.nielsen@microchip.com, joergen.andreasen@microchip.com, UNGLinuxDriver@microchip.com, vinicius.gomes@intel.com, michael.chan@broadcom.com, vishal@chelsio.com, saeedm@mellanox.com, jiri@mellanox.com, idosch@mellanox.com, alexandre.belloni@bootlin.com, kuba@kernel.org, xiaoliang.yang_1@nxp.com, po.liu@nxp.com, vladimir.oltean@nxp.com, leoyang.li@nxp.com Subject: [RFC v2 net-next 1/8] net: mscc: ocelot: add MAC table write and lookup operations Date: Wed, 18 Aug 2021 14:19:15 +0800 Message-Id: <20210818061922.12625-2-xiaoliang.yang_1@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210818061922.12625-1-xiaoliang.yang_1@nxp.com> References: <20210818061922.12625-1-xiaoliang.yang_1@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean ocelot_mact_write() can be used for directly modifying an FDB entry situated at a given row and column, as opposed to the current ocelot_mact_learn() which calculates the row and column indices automatically (based on a 11-bit hash derived from the {DMAC, VID} key). ocelot_mact_lookup() can be used to retrieve the row and column at which an FDB entry with the given {DMAC, VID} key is found. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot.c | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index adfb9781799e..0241272e9ce9 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -102,6 +102,53 @@ int ocelot_mact_forget(struct ocelot *ocelot, } EXPORT_SYMBOL(ocelot_mact_forget); +int ocelot_mact_lookup(struct ocelot *ocelot, const unsigned char mac[ETH_ALEN], + unsigned int vid, int *row, int *col) +{ + int val; + + ocelot_mact_select(ocelot, mac, vid); + + /* Issue a read command with MACACCESS_VALID=1. */ + ocelot_write(ocelot, ANA_TABLES_MACACCESS_VALID | + ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_READ), + ANA_TABLES_MACACCESS); + + if (ocelot_mact_wait_for_completion(ocelot)) + return -ETIMEDOUT; + + /* Read back the entry flags */ + val = ocelot_read(ocelot, ANA_TABLES_MACACCESS); + if (!(val & ANA_TABLES_MACACCESS_VALID)) + return -ENOENT; + + ocelot_field_read(ocelot, ANA_TABLES_MACTINDX_M_INDEX, row); + ocelot_field_read(ocelot, ANA_TABLES_MACTINDX_BUCKET, col); + + return 0; +} +EXPORT_SYMBOL(ocelot_mact_lookup); + +/* Like ocelot_mact_learn, except at a specific row and col. */ +void ocelot_mact_write(struct ocelot *ocelot, int port, + const struct ocelot_mact_entry *entry, + int row, int col) +{ + ocelot_mact_select(ocelot, entry->mac, entry->vid); + + ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_M_INDEX, row); + ocelot_field_write(ocelot, ANA_TABLES_MACTINDX_BUCKET, col); + + ocelot_write(ocelot, ANA_TABLES_MACACCESS_VALID | + ANA_TABLES_MACACCESS_ENTRYTYPE(entry->type) | + ANA_TABLES_MACACCESS_DEST_IDX(port) | + ANA_TABLES_MACACCESS_MAC_TABLE_CMD(MACACCESS_CMD_WRITE), + ANA_TABLES_MACACCESS); + + ocelot_mact_wait_for_completion(ocelot); +} +EXPORT_SYMBOL(ocelot_mact_write); + static void ocelot_mact_init(struct ocelot *ocelot) { /* Configure the learning mode entries attributes: