Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp184795pxb; Tue, 17 Aug 2021 23:11:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8rRr7mv7vccqorTwA3Xvt1nB+o0dlxppNf5b0fqvAiEIIzv9JD3yD1FK1lSvGbRFw2SkN X-Received: by 2002:a17:906:a894:: with SMTP id ha20mr8170681ejb.229.1629267092394; Tue, 17 Aug 2021 23:11:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629267092; cv=none; d=google.com; s=arc-20160816; b=zUZ4q5hOkKbUZsHp+YnlVyYZyE337sRjMQhMjjmMrxFp6B6UGSwx09sOKCVs2ZC52u u5loixkIUtxWSlHmdoVIdnlhngqZLVc9+AU9VjBab054K4cwcz3zcL4huDLg/R/NHhLQ D80SeQTrEY+NqZBb9n7lNLr1tbNJQ0n2tZT5+jmMnLwpVQXMtYTHL4J5t3faE75Rt+B2 HNU4SvNT3IGLC3sL8ZqpK9hO+UBNbGjzB3ue9K7ajPgO1jtZ7+2uEJsU2654jLW3HrnI SjFNdlTHT/eV3nRnZYtxKBq7gn56n4UYg6JLQuQpK8xIQzvLH8ajixNEuJQON0MMLYDp O+Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=BWOAEGreee3Kp14lu7g6QBCPdF0hAcE7XWUhj+Gr6QA=; b=c72mnk0LUNkA1veUNHclFft/gdzoVUqqQkFcwW2sdJyVIO+xOv1vSNpJxtp59b3zRm 1RLEWAUjIeuTDjNVExsYF1VfFnbSn5Y5w3Gm4Xbd1pOfVYrCV3QesMMOlDYhpTM6roMG tBXzHz0wVRwNiAFEAJORfaISATnF4lm5uERQ2RuoGOYLboyIjRSsDJuoEmG1XQvKKjos Y8tF7BpAw52q6syITdXENbccA8Jda9eD+lqhhcJaAkWcsDsGVZXedMCktpFPTenhpLpM NJZOJ4QU4F3vrYZOR4FXpIvnruLjYzP8lecDABKcfUvY+nijJnSOIn6vkUYQqCpYBoPs gueA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s4si4678001eji.269.2021.08.17.23.11.08; Tue, 17 Aug 2021 23:11:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239223AbhHRGKN (ORCPT + 99 others); Wed, 18 Aug 2021 02:10:13 -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: linux-kernel@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: -- 2.17.1