Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp331259pxb; Wed, 13 Jan 2021 04:59:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWTn7nzjWsZ7s9lWMns/2RDghNi/4J6NlQ8LOeuVIGmeBX8/+YNTPMK4ECmLiXMiKLPdKP X-Received: by 2002:a17:906:9613:: with SMTP id s19mr1494894ejx.351.1610542773932; Wed, 13 Jan 2021 04:59:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610542773; cv=none; d=google.com; s=arc-20160816; b=lvyX8lgvXRrYSWK1Sw9TVsnfb2mmMgDt+rC6kH68QQhsjCoi77XcPS4Ao3ZGNxl8SF 7O3vL3edlE6X3Njlb5BHW3pDUCS4vIf4NSJveJv0tiZFc9KUw2MiCB01BUKWEpUPajub zdbBr4iLD3DA9MRvszl2PqujPURqz/LyexYErA0ebTUZQz15E/RsX/gEFmgKJzH49LKX ErB9Ihl+L3urv2ByPnnzdENG6oXDRTsql1scpvdqCFPWtC9GLXqvnHEnRDdQowMCp6Ym SeBBxxK8NzYugMik53GavBY6G5w2Kvq95rIHZW+4H30AEVtYp0xQQOcQr5QgX+XNHkmO 66cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=tiqJ9Ky9U/ZsZE2qpnJ7R53ic0rmN9yif1XUxPBafD4=; b=n/1ItQeb3xcVFAF/ywx0txnT4fRQCSYkCiV3ZCtkcHsD/FL+ljsacLiuFFBxxC/xBq HaLH7QVefyb8JiS2XE+zFcFizzZlxDEjXZLOEKpxWponIwZa9yfVygJa4qMk6MnZ4Vih Kf261xXJqcW5nv9RkFFZxRc188crh9gCrH2M1j/c+keJeGRzwXdI51wy4CE5Uk4RK4Ml jnfvR9k8XNwqLa2tgWAzBTt9SbcWIa2U2Y1jHQrvRnpUi21btH5qQmFZrzTmyslhISzt GCS+AIGW25xi4qr3cF6ly/G7G9yznxx26bD3yP/S+/wXQrIDKpGffY4Rt2n3271ed+MD 1Eow== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l23si987088edr.325.2021.01.13.04.59.10; Wed, 13 Jan 2021 04:59:33 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727382AbhAMM4F (ORCPT + 99 others); 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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/microc= hip/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; } =20 static void ksz8795_get_strings(struct dsa_switch *ds, int port, @@ -796,6 +796,41 @@ static int ksz8795_port_vlan_filtering(struct dsa_sw= itch *ds, int port, return 0; } =20 +static void ksz8795_del_fid(u16 *ksz_fid_table, u16 vid) +{ + u8 i =3D 0; + + if (!ksz_fid_table) + return; + + for (i =3D 0; i < VLAN_TABLE_FID_SIZE; i++) { + if (ksz_fid_table[i] =3D=3D vid) { + ksz_fid_table[i] =3D 0; + break; + } + } +} + +static int ksz8795_get_next_fid(u16 *ksz_fid_table, u16 vid, u8 *fid) +{ + u8 i =3D 0; + int ret =3D -EOVERFLOW; + + if (!ksz_fid_table) + return ret; + + for (i =3D 0; i < VLAN_TABLE_FID_SIZE; i++) { + if (!ksz_fid_table[i]) { + ksz_fid_table[i] =3D vid; + *fid =3D i; + ret =3D 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 =3D ds->priv; u16 data, vid, new_pvid =3D 0; u8 fid, member, valid; + int ret; =20 ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged); =20 for (vid =3D vlan->vid_begin; vid <=3D vlan->vid_end; vid++) { + if (vid =3D=3D 0) + continue; + ksz8795_r_vlan_table(dev, vid, &data); ksz8795_from_vlan(data, &fid, &member, &valid); =20 /* First time to setup the VLAN entry. */ if (!valid) { - /* Need to find a way to map VID to FID. */ - fid =3D 1; + ret =3D 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 =3D 1; } member |=3D BIT(port); @@ -855,7 +897,7 @@ static int ksz8795_port_vlan_del(struct dsa_switch *d= s, int port, =20 /* Invalidate the entry if no more member. */ if (!member) { - fid =3D 0; + ksz8795_del_fid(dev->ksz_fid_table, vid); valid =3D 0; } =20 @@ -1087,6 +1129,9 @@ static int ksz8795_setup(struct dsa_switch *ds) for (i =3D 0; i < (dev->num_vlans / 4); i++) ksz8795_r_vlan_entries(dev, i); =20 + /* Assign first FID to VLAN 1 and always return FID=3D0 for this vlan *= / + dev->ksz_fid_table[0] =3D 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 =3D dev->port_cnt; =20 + dev->ksz_fid_table =3D devm_kzalloc(dev->dev, + VLAN_TABLE_FID_SIZE * sizeof(u16), + GFP_KERNEL); + if (!dev->ksz_fid_table) + return -ENOMEM; + return 0; } =20 diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/mi= crochip/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 @@ */ =20 #define VLAN_TABLE_FID 0x007F +#define VLAN_TABLE_FID_SIZE 128 #define VLAN_TABLE_MEMBERSHIP 0x0F80 #define VLAN_TABLE_VALID 0x1000 =20 diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/mic= rochip/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; =20 struct vlan_table *vlan_cache; + u16 *ksz_fid_table; =20 struct ksz_port *ports; struct delayed_work mib_read; --=20 2.25.1