From patchwork Wed Jan 13 12:45:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilles DOFFE X-Patchwork-Id: 362640 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 C40ADC4332B for ; Wed, 13 Jan 2021 12:56:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74414233F6 for ; Wed, 13 Jan 2021 12:56:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727335AbhAMM4F (ORCPT ); Wed, 13 Jan 2021 07:56:05 -0500 Received: from mail.savoirfairelinux.com ([208.88.110.44]:39124 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726674AbhAMMzu (ORCPT ); Wed, 13 Jan 2021 07:55:50 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 61EFD9C0DCE; Wed, 13 Jan 2021 07:45:36 -0500 (EST) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id W5ZObefErLHT; Wed, 13 Jan 2021 07:45:35 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id AC79E9C0DCC; Wed, 13 Jan 2021 07:45:35 -0500 (EST) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id FniZPELW2f2W; Wed, 13 Jan 2021 07:45:35 -0500 (EST) Received: from gdo-desktop.home (pop.92-184-98-96.mobile.abo.orange.fr [92.184.98.96]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id AE7929C0DA5; Wed, 13 Jan 2021 07:45:33 -0500 (EST) From: Gilles DOFFE To: netdev@vger.kernel.org Cc: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , linux-kernel@vger.kernel.org Subject: [PATCH net 1/6] net: dsa: ksz: fix FID management Date: Wed, 13 Jan 2021 13:45:17 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The FID (Filter ID) is a 7 bits field used to link the VLAN table to the static and dynamic mac address tables. Until now the KSZ8795 driver could only add one VLAN as the FID was always set to 1. This commit allows setting a FID for each new active VLAN. The FID list is stored in a static table dynamically allocated from ks8795_fid structure. Each newly activated VLAN is associated to the next available FID. Only the VLAN 0 is not added to the list as it is a special VLAN. As it has a special meaning, see IEEE 802.1q. When a VLAN is no more used, the associated FID table entry is reset to 0. Signed-off-by: Gilles DOFFE --- drivers/net/dsa/microchip/ksz8795.c | 59 +++++++++++++++++++++++-- drivers/net/dsa/microchip/ksz8795_reg.h | 1 + drivers/net/dsa/microchip/ksz_common.h | 1 + 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index c973db101b72..6962ba4ee125 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -648,7 +648,7 @@ static enum dsa_tag_protocol ksz8795_get_tag_protocol(struct dsa_switch *ds, int port, enum dsa_tag_protocol mp) { - return DSA_TAG_PROTO_KSZ8795; + return DSA_TAG_PROTO_NONE; } static void ksz8795_get_strings(struct dsa_switch *ds, int port, @@ -796,6 +796,41 @@ static int ksz8795_port_vlan_filtering(struct dsa_switch *ds, int port, return 0; } +static void ksz8795_del_fid(u16 *ksz_fid_table, u16 vid) +{ + u8 i = 0; + + if (!ksz_fid_table) + return; + + for (i = 0; i < VLAN_TABLE_FID_SIZE; i++) { + if (ksz_fid_table[i] == vid) { + ksz_fid_table[i] = 0; + break; + } + } +} + +static int ksz8795_get_next_fid(u16 *ksz_fid_table, u16 vid, u8 *fid) +{ + u8 i = 0; + int ret = -EOVERFLOW; + + if (!ksz_fid_table) + return ret; + + for (i = 0; i < VLAN_TABLE_FID_SIZE; i++) { + if (!ksz_fid_table[i]) { + ksz_fid_table[i] = vid; + *fid = i; + ret = 0; + break; + } + } + + return ret; +} + static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { @@ -803,17 +838,24 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port, struct ksz_device *dev = ds->priv; u16 data, vid, new_pvid = 0; u8 fid, member, valid; + int ret; ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged); for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { + if (vid == 0) + continue; + ksz8795_r_vlan_table(dev, vid, &data); ksz8795_from_vlan(data, &fid, &member, &valid); /* First time to setup the VLAN entry. */ if (!valid) { - /* Need to find a way to map VID to FID. */ - fid = 1; + ret = ksz8795_get_next_fid(dev->ksz_fid_table, vid, &fid); + if (ret) { + dev_err(ds->dev, "Switch FID table is full, cannot add"); + return; + } valid = 1; } member |= BIT(port); @@ -855,7 +897,7 @@ static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port, /* Invalidate the entry if no more member. */ if (!member) { - fid = 0; + ksz8795_del_fid(dev->ksz_fid_table, vid); valid = 0; } @@ -1087,6 +1129,9 @@ static int ksz8795_setup(struct dsa_switch *ds) for (i = 0; i < (dev->num_vlans / 4); i++) ksz8795_r_vlan_entries(dev, i); + /* Assign first FID to VLAN 1 and always return FID=0 for this vlan */ + dev->ksz_fid_table[0] = 1; + /* Setup STP address for STP operation. */ memset(&alu, 0, sizeof(alu)); ether_addr_copy(alu.mac, eth_stp_addr); @@ -1261,6 +1306,12 @@ static int ksz8795_switch_init(struct ksz_device *dev) /* set the real number of ports */ dev->ds->num_ports = dev->port_cnt; + dev->ksz_fid_table = devm_kzalloc(dev->dev, + VLAN_TABLE_FID_SIZE * sizeof(u16), + GFP_KERNEL); + if (!dev->ksz_fid_table) + return -ENOMEM; + return 0; } diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h index 40372047d40d..fe4c4f7fdd47 100644 --- a/drivers/net/dsa/microchip/ksz8795_reg.h +++ b/drivers/net/dsa/microchip/ksz8795_reg.h @@ -915,6 +915,7 @@ */ #define VLAN_TABLE_FID 0x007F +#define VLAN_TABLE_FID_SIZE 128 #define VLAN_TABLE_MEMBERSHIP 0x0F80 #define VLAN_TABLE_VALID 0x1000 diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 720f22275c84..44e97c55c2da 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -77,6 +77,7 @@ struct ksz_device { bool synclko_125; struct vlan_table *vlan_cache; + u16 *ksz_fid_table; struct ksz_port *ports; struct delayed_work mib_read; From patchwork Wed Jan 13 12:45:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilles DOFFE X-Patchwork-Id: 362639 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 96ABFC43332 for ; Wed, 13 Jan 2021 12:56:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55DB1222F9 for ; Wed, 13 Jan 2021 12:56:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727305AbhAMM4E (ORCPT ); Wed, 13 Jan 2021 07:56:04 -0500 Received: from mail.savoirfairelinux.com ([208.88.110.44]:39116 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727172AbhAMMzu (ORCPT ); Wed, 13 Jan 2021 07:55:50 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 2C1899C0DCF; Wed, 13 Jan 2021 07:45:38 -0500 (EST) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 7nsceJMoUmDn; Wed, 13 Jan 2021 07:45:37 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id C8E0E9C0DCB; Wed, 13 Jan 2021 07:45:37 -0500 (EST) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id accOWXalYQb3; Wed, 13 Jan 2021 07:45:37 -0500 (EST) Received: from gdo-desktop.home (pop.92-184-98-96.mobile.abo.orange.fr [92.184.98.96]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id D0B8B9C0DCD; Wed, 13 Jan 2021 07:45:35 -0500 (EST) From: Gilles DOFFE To: netdev@vger.kernel.org Cc: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , linux-kernel@vger.kernel.org Subject: [PATCH net 2/6] net: dsa: ksz: move tag/untag action Date: Wed, 13 Jan 2021 13:45:18 +0100 Message-Id: <8e1cd9b167bd39c0f82ca8970a355cdfbc0fe885.1610540603.git.gilles.doffe@savoirfairelinux.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Move tag/untag action at the end of the function to avoid tagging or untagging traffic if only vlan 0 is handled. Signed-off-by: Gilles DOFFE --- drivers/net/dsa/microchip/ksz8795.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 6962ba4ee125..4b060503b2e8 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -840,8 +840,6 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port, u8 fid, member, valid; int ret; - ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged); - for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { if (vid == 0) continue; @@ -874,6 +872,8 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port, vid |= new_pvid; ksz_pwrite16(dev, port, REG_PORT_CTRL_VID, vid); } + + ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged); } static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port, From patchwork Wed Jan 13 12:45:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilles DOFFE X-Patchwork-Id: 362641 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 148AFC433DB for ; Wed, 13 Jan 2021 12:56:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9D29233F6 for ; Wed, 13 Jan 2021 12:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727218AbhAMMzv (ORCPT ); Wed, 13 Jan 2021 07:55:51 -0500 Received: from mail.savoirfairelinux.com ([208.88.110.44]:39112 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727179AbhAMMzu (ORCPT ); Wed, 13 Jan 2021 07:55:50 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 52CB19C0DD1; Wed, 13 Jan 2021 07:45:40 -0500 (EST) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id NpDf8A8lalEm; Wed, 13 Jan 2021 07:45:40 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id EBFBC9C0DCD; Wed, 13 Jan 2021 07:45:39 -0500 (EST) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id AltUp2Rc3SPk; Wed, 13 Jan 2021 07:45:39 -0500 (EST) Received: from gdo-desktop.home (pop.92-184-98-96.mobile.abo.orange.fr [92.184.98.96]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id EFEAD9C0DCC; Wed, 13 Jan 2021 07:45:37 -0500 (EST) From: Gilles DOFFE To: netdev@vger.kernel.org Cc: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , linux-kernel@vger.kernel.org Subject: [PATCH net 3/6] net: dsa: ksz: insert tag on ks8795 ingress packets Date: Wed, 13 Jan 2021 13:45:19 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If 802.1q VLAN tag is removed from egress traffic, ingress traffic should by logic be tagged. Signed-off-by: Gilles DOFFE --- drivers/net/dsa/microchip/ksz8795.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 4b060503b2e8..193f03ef9160 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -874,6 +874,7 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port, } ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged); + ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_INSERT_TAG, !untagged); } static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port,