From patchwork Mon Aug 16 18:09:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 497926 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=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_1 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 7408EC4338F for ; Mon, 16 Aug 2021 18:09:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52D2160F22 for ; Mon, 16 Aug 2021 18:09:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230253AbhHPSJp (ORCPT ); Mon, 16 Aug 2021 14:09:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230009AbhHPSJp (ORCPT ); Mon, 16 Aug 2021 14:09:45 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40FC0C0613C1 for ; Mon, 16 Aug 2021 11:09:13 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id n12so27764688edx.8 for ; Mon, 16 Aug 2021 11:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mind.be; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=O3ErUZ22t3/2NnJvS4t3GxIKREc/lpK4t3GrCBcKr0s=; b=MqIR+wT3TQ7AperC/QwCBgWjfTLvLSef5OV3AlZZPKb99x1zp9VkDperrxeByexvZo 6btdJ3JlSZoWgdIJZtALiWD/7fEXImETrT+PY1kmGFHHGIUUBzmrWfJj7JbwjWQkwhy/ tw1ufFGwyjPpT3FZNhYPIP/bpOJTFHrV5HjvtrH9CII5KLn37RhUYIHH3hh5AmSBE6Tm F8yakd5pZDW8Q9UA7HGQtOWOG9bU8Db8/Pfmg4tUFoPhEghY+QeG92EOSzMPd6hCWA1M KmYRWIK3TH0S8Qb2Kv2dv+hHupAPnw/bCJrSGrbsCHOjV2xfd7iBRdJwU+BxWiytldxr m9BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=O3ErUZ22t3/2NnJvS4t3GxIKREc/lpK4t3GrCBcKr0s=; b=mSRMuz+9xhMhWCrWvbnrOosEdqzgMeQO8FRP2kjbzLdie3hMuA4i3st+PInoCX1Q3z HR9/x4PgChNJG+snqvQnwB/qfkCqbUrnpwJokvYrSQ/yu8hVMwWB97mufIOvnO+ABDLD UHT58AV+MPp7joa6HmvN6jrRxRzGv9ko8zSysSYbGWDR66wgnpb7Wec7LhLBx2IAwUIM ib41uJ94GG3ERf533jy36mg5tQDxFJQr/3du7tjspjriYAIK9OZsMbE9Mn0dGZWIfInA BY+p/JYonBgif0Y3e+qpwUcqL6WaXPg+tXjbkC9E6/kdb+1i1yjfnwXDqaAYS2UZT+z7 +BDA== X-Gm-Message-State: AOAM531SATz/Kjw+UATz7jgivtBT0Ve2sOwr41wsao1f92fjRp2/b1BO SEuc20ezozJgJyfD0iPw25nitg== X-Google-Smtp-Source: ABdhPJxr/NOJQwEcR8v0SouCivf0RaGELa2786Pp80kXXkfyso/2qhYytT5Bic1pg8IR4u20WhzRTQ== X-Received: by 2002:aa7:cad9:: with SMTP id l25mr22395060edt.351.1629137351869; Mon, 16 Aug 2021 11:09:11 -0700 (PDT) Received: from cephalopod (168.7-181-91.adsl-dyn.isp.belgacom.be. [91.181.7.168]) by smtp.gmail.com with ESMTPSA id fl2sm3916189ejc.114.2021.08.16.11.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 11:09:11 -0700 (PDT) Date: Mon, 16 Aug 2021 20:09:09 +0200 From: Ben Hutchings To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, "David S. Miller" , Sasha Levin , Woojung Huh , Microchip Linux Driver Support , Michael Grzeschik , Marek Vasut Subject: [PATCH 5.10 1/5] net: dsa: microchip: Fix probing KSZ87xx switch with DT node for host port Message-ID: <20210816180909.GE18930@cephalopod> References: <20210816174905.GD18930@cephalopod> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210816174905.GD18930@cephalopod> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The ksz8795 and ksz9477 drivers differ in the way they count ports. For ksz8795, ksz_device::port_cnt does not include the host port whereas for ksz9477 it does. This inconsistency was fixed in Linux 5.11 by a series of changes, but remains in 5.10-stable. When probing, the common code treats a port device node with an address >= dev->port_cnt as a fatal error. As a minimal fix, change it to compare again dev->mib_port_cnt. This is the length of the dev->ports array that the port number will be used to index, and always includes the host port. Cc: Woojung Huh Cc: Microchip Linux Driver Support Cc: Michael Grzeschik Cc: Marek Vasut Signed-off-by: Ben Hutchings --- drivers/net/dsa/microchip/ksz_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index d4a64dbde315..88fa0779e0bc 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -432,7 +432,7 @@ int ksz_switch_register(struct ksz_device *dev, if (of_property_read_u32(port, "reg", &port_num)) continue; - if (port_num >= dev->port_cnt) + if (port_num >= dev->mib_port_cnt) return -EINVAL; of_get_phy_mode(port, &dev->ports[port_num].interface); From patchwork Mon Aug 16 18:09:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 498702 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=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_1 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 605B2C4338F for ; Mon, 16 Aug 2021 18:09:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B81E60F41 for ; Mon, 16 Aug 2021 18:09:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232849AbhHPSKZ (ORCPT ); Mon, 16 Aug 2021 14:10:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230009AbhHPSKM (ORCPT ); Mon, 16 Aug 2021 14:10:12 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19078C0613CF for ; Mon, 16 Aug 2021 11:09:26 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id b15so33308111ejg.10 for ; Mon, 16 Aug 2021 11:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mind.be; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=XB1c9ILEXbIGeaE3RF5LyGrxlHfkgsii4y9hKMpsOPM=; b=VI1nmQkVG9NF54oMFgNJaqs5PhqOMtqHWzhdyKt7ZAMvAl0yGfSkwqBzm9DlrffV23 bFTG6mfUKjXFNG+jeKYDqnUpo5wpC8LQLgOZiMAclB91e9HEq90AmJe1Iw5wECEbi2fz KP6D7OnyxyBdVA0EvS/foCMdBVcWyQzV+W20KsHYVB9uBEtQ5G8rpabyib+7/n1z5Pwx cyyigDW1h/ctrNXOV9HxGMbF7NQXcMQZLyIoXzwh0q2DBo7QtfOhhq17HvRM5+x/UGUt sDJrW1kp7zyyq2WuMqggLoFNWJCguBYgMsRk6MTax4VzZOnIYxuieH07wCV3xRzljCkB SRlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=XB1c9ILEXbIGeaE3RF5LyGrxlHfkgsii4y9hKMpsOPM=; b=dnIJF3sL4S0B62Owcf6M+ag9waGVmrkVzLdktNRCxa9DoMwJw7agVw3WLF8twTQlBZ P6XENn5wlc6fsu27d8Y9ABdsOgRlUAWIGuSqVaK1fJppZqMIyaHAAVRixQtsj3edgbwm t+4wOGLUj0NgjrqtJRmo5cs1b2HZQiS15Fz0xUj44ZTOfK5M3BuJ2p9OQPJFBhx6rJdA rJ3MBARnF327DMv50bLJGZ+dFiydobxj2RYBD5Wb5+6uT33Y8lVsplY1JAdGVAvPvl1Q +4xOSMfKGBlK/I7vcAE3/fqsE3HMTNGOydgeD5iWJnh22Gel8uefDMG78Bs4oMvhHa1a CmAA== X-Gm-Message-State: AOAM531rBmN6nTFsrbFP1FYo9NSPnhGT5iQnR30L9dB8kuVTDerAX6D0 Eb8KBX7zV3RH07X1jB47UhsRSQ== X-Google-Smtp-Source: ABdhPJzCZ7DRGE8vLgBrbRafZo3Y06XGncpHZbIwrh/pRl8HaApv3MofBKSkpLDgVmnLRhLnOAKhgA== X-Received: by 2002:a17:906:26c1:: with SMTP id u1mr15242796ejc.491.1629137364653; Mon, 16 Aug 2021 11:09:24 -0700 (PDT) Received: from cephalopod (168.7-181-91.adsl-dyn.isp.belgacom.be. [91.181.7.168]) by smtp.gmail.com with ESMTPSA id fl2sm3916370ejc.114.2021.08.16.11.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 11:09:24 -0700 (PDT) Date: Mon, 16 Aug 2021 20:09:22 +0200 From: Ben Hutchings To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 2/5] net: dsa: microchip: ksz8795: Fix PVID tag insertion Message-ID: <20210816180921.GF18930@cephalopod> References: <20210816174905.GD18930@cephalopod> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210816174905.GD18930@cephalopod> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org commit ef3b02a1d79b691f9a354c4903cf1e6917e315f9 upstream. ksz8795 has never actually enabled PVID tag insertion, and it also programmed the PVID incorrectly. To fix this: * Allow tag insertion to be controlled per ingress port. On most chips, set bit 2 in Global Control 19. On KSZ88x3 this control flag doesn't exist. * When adding a PVID: - Set the appropriate register bits to enable tag insertion on egress at every other port if this was the packet's ingress port. - Mask *out* the VID from the default tag, before or-ing in the new PVID. * When removing a PVID: - Clear the same control bits to disable tag insertion. - Don't update the default tag. This wasn't doing anything useful. Fixes: e66f840c08a2 ("net: dsa: ksz: Add Microchip KSZ8795 DSA driver") Signed-off-by: Ben Hutchings Signed-off-by: David S. Miller [bwh: Backport to 5.10: - Drop the KSZ88x3 cases as those chips are not supported here - Handle VID ranges in ksz8795_port_vlan_del()] Signed-off-by: Ben Hutchings --- drivers/net/dsa/microchip/ksz8795.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 108a14db1f1a..3d36ffff1f4e 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -833,9 +833,11 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port, if (new_pvid) { ksz_pread16(dev, port, REG_PORT_CTRL_VID, &vid); - vid &= 0xfff; + vid &= ~VLAN_VID_MASK; vid |= new_pvid; ksz_pwrite16(dev, port, REG_PORT_CTRL_VID, vid); + + ksz_pwrite8(dev, port, REG_PORT_CTRL_12, 0x0f); } } @@ -844,8 +846,9 @@ static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port, { bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; struct ksz_device *dev = ds->priv; - u16 data, vid, pvid, new_pvid = 0; + u16 data, vid, pvid; u8 fid, member, valid; + bool del_pvid = false; ksz_pread16(dev, port, REG_PORT_CTRL_VID, &pvid); pvid = pvid & 0xFFF; @@ -865,14 +868,14 @@ static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port, } if (pvid == vid) - new_pvid = 1; + del_pvid = true; ksz8795_to_vlan(fid, member, valid, &data); ksz8795_w_vlan_table(dev, vid, data); } - if (new_pvid != pvid) - ksz_pwrite16(dev, port, REG_PORT_CTRL_VID, pvid); + if (del_pvid) + ksz_pwrite8(dev, port, REG_PORT_CTRL_12, 0x00); return 0; } @@ -1085,6 +1088,8 @@ static int ksz8795_setup(struct dsa_switch *ds) ksz_cfg(dev, S_MIRROR_CTRL, SW_MIRROR_RX_TX, false); + ksz_cfg(dev, REG_SW_CTRL_19, SW_INS_TAG_ENABLE, true); + /* set broadcast storm protection 10% rate */ regmap_update_bits(dev->regmap[1], S_REPLACE_VID_CTRL, BROADCAST_STORM_RATE, From patchwork Mon Aug 16 18:09:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 498701 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=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_1 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 A92A4C4320A for ; Mon, 16 Aug 2021 18:09:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 913DA60F22 for ; Mon, 16 Aug 2021 18:09:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233122AbhHPSK3 (ORCPT ); Mon, 16 Aug 2021 14:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233062AbhHPSKW (ORCPT ); Mon, 16 Aug 2021 14:10:22 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B769C0613A3 for ; Mon, 16 Aug 2021 11:09:34 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id i6so27809730edu.1 for ; Mon, 16 Aug 2021 11:09:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mind.be; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=JPEdTz55eeFZmTipGCcbNE0GKiAhFZ1eLySPvZceEsU=; b=USZrrePZsDm1l8YAZ/qA5fx/fzePtZlbfJmkcDUvidT8YYfBpHcnJ9Ru5an+FSzJZU 6Ksam4Ily92x5UxlqvSAhFzkuhQR7yP+a7bK5fItcVA9fziVe02VifdHAi5sVIcP+y3X mQRFG+iXGFPyxISaCewFUPws/p4y3rRhWCCOpZLTCVs73SBmIldOZ/VQeFV10HHemunT E0+8CZtfAo9HDcixqDp5Ny7WaQVm2NVMCMiN+GRi5ZG5XOl3P62mX0Cdir5HAI10hW6Y rT2fgRd6EBVEdDhsMSUv2njTokMe6+eGzae6wMs+iCd7HVjotR6yM4l5/3jrtzWzxO28 OQ0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=JPEdTz55eeFZmTipGCcbNE0GKiAhFZ1eLySPvZceEsU=; b=ktrSBzmYX1KE4u+uMgyPyuPccmllrJKo7cPAUjkbY8NFCLgjURzgqBmzaVhq6Nxd3d hDJ+HUnbh9xOJPCTpcWrrXTHrJt/YsCV6tCvoeplBBz9p7320A2oOJZB+bbs9Uf9UPkc Np8Ojx2r5NgV4vJebuXASxkm0AfTx0LSUpu7Ys9Dm/np4W4E7WNpvNI/GLcZ+mIALfuY 5h79wZF6P1tyox098LPjn1pvtUEpcNiBh3RCqsRefz/4iJAeYg8x72U2mkuqC5EHu84r gFCUdlnECpCfoxHbk8JXP2xj5CZJo+f/2otI8Norbj1oI8uWuZzeEzzMIoR+xmVgTsEp VFPA== X-Gm-Message-State: AOAM530lqulapiG/vZlppnCf29/lsaOwpEKqUfyqwUzchIq+sVjdwcbO yvPbK7aO7G96Bo34cwTMbWoBig== X-Google-Smtp-Source: ABdhPJxszyCJ08/thUnQI+lhz3dx9qB5WP9ylaGefLhrTFvXdKKvVKNZnl6sgZrrxL5mNFug+OqH7Q== X-Received: by 2002:a05:6402:27d2:: with SMTP id c18mr22129669ede.87.1629137373079; Mon, 16 Aug 2021 11:09:33 -0700 (PDT) Received: from cephalopod (168.7-181-91.adsl-dyn.isp.belgacom.be. [91.181.7.168]) by smtp.gmail.com with ESMTPSA id m6sm5201725edq.22.2021.08.16.11.09.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 11:09:32 -0700 (PDT) Date: Mon, 16 Aug 2021 20:09:31 +0200 From: Ben Hutchings To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 3/5] net: dsa: microchip: ksz8795: Reject unsupported VLAN configuration Message-ID: <20210816180930.GG18930@cephalopod> References: <20210816174905.GD18930@cephalopod> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210816174905.GD18930@cephalopod> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org commit 8f4f58f88fe0d9bd591f21f53de7dbd42baeb3fa upstream. The switches supported by ksz8795 only have a per-port flag for Tag Removal. This means it is not possible to support both tagged and untagged VLANs on the same port. Reject attempts to add a VLAN that requires the flag to be changed, unless there are no VLANs currently configured. VID 0 is excluded from this check since it is untagged regardless of the state of the flag. On the CPU port we could support tagged and untagged VLANs at the same time. This will be enabled by a later patch. Fixes: e66f840c08a2 ("net: dsa: ksz: Add Microchip KSZ8795 DSA driver") Signed-off-by: Ben Hutchings Signed-off-by: David S. Miller [bwh: Backport to 5.10: - This configuration has to be detected and rejected in the port_vlan_prepare operation - ksz8795_port_vlan_add() has to check again to decide whether to change the Tag Removal flag, so put the common condition in a separate function - Handle VID ranges] Signed-off-by: Ben Hutchings --- drivers/net/dsa/microchip/ksz8795.c | 55 +++++++++++++++++++++++++- drivers/net/dsa/microchip/ksz_common.h | 1 + 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 3d36ffff1f4e..b4b164d75520 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -801,15 +801,66 @@ static int ksz8795_port_vlan_filtering(struct dsa_switch *ds, int port, return 0; } +static bool ksz8795_port_vlan_changes_remove_tag( + struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan) +{ + bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; + struct ksz_device *dev = ds->priv; + struct ksz_port *p = &dev->ports[port]; + + /* If a VLAN is added with untagged flag different from the + * port's Remove Tag flag, we need to change the latter. + * Ignore VID 0, which is always untagged. + */ + return untagged != p->remove_tag && + !(vlan->vid_begin == 0 && vlan->vid_end == 0); +} + +int ksz8795_port_vlan_prepare(struct dsa_switch *ds, int port, + const struct switchdev_obj_port_vlan *vlan) +{ + struct ksz_device *dev = ds->priv; + + /* Reject attempts to add a VLAN that requires the Remove Tag + * flag to be changed, unless there are no other VLANs + * currently configured. + */ + if (ksz8795_port_vlan_changes_remove_tag(ds, port, vlan)) { + unsigned int vid; + + for (vid = 1; vid < dev->num_vlans; ++vid) { + u8 fid, member, valid; + + /* Skip the VIDs we are going to add or reconfigure */ + if (vid == vlan->vid_begin) { + vid = vlan->vid_end; + continue; + } + + ksz8795_from_vlan(dev->vlan_cache[vid].table[0], + &fid, &member, &valid); + if (valid && (member & BIT(port))) + return -EINVAL; + } + } + + return ksz_port_vlan_prepare(ds, port, vlan); +} + static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; struct ksz_device *dev = ds->priv; + struct ksz_port *p = &dev->ports[port]; u16 data, vid, new_pvid = 0; u8 fid, member, valid; - ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged); + if (ksz8795_port_vlan_changes_remove_tag(ds, port, vlan)) { + ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged); + p->remove_tag = untagged; + } for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { ksz8795_r_vlan_table(dev, vid, &data); @@ -1128,7 +1179,7 @@ static const struct dsa_switch_ops ksz8795_switch_ops = { .port_stp_state_set = ksz8795_port_stp_state_set, .port_fast_age = ksz_port_fast_age, .port_vlan_filtering = ksz8795_port_vlan_filtering, - .port_vlan_prepare = ksz_port_vlan_prepare, + .port_vlan_prepare = ksz8795_port_vlan_prepare, .port_vlan_add = ksz8795_port_vlan_add, .port_vlan_del = ksz8795_port_vlan_del, .port_fdb_dump = ksz_port_fdb_dump, diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index a51c716ec920..309ad4a72d78 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -27,6 +27,7 @@ struct ksz_port_mib { struct ksz_port { u16 member; u16 vid_member; + bool remove_tag; /* Remove Tag flag set, for ksz8795 only */ int stp_state; struct phy_device phydev; From patchwork Mon Aug 16 18:09:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 497924 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=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_1 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 5F035C432BE for ; Mon, 16 Aug 2021 18:09:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4780A60EFE for ; Mon, 16 Aug 2021 18:09:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233170AbhHPSK3 (ORCPT ); Mon, 16 Aug 2021 14:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233077AbhHPSKW (ORCPT ); Mon, 16 Aug 2021 14:10:22 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E924C0612E7 for ; Mon, 16 Aug 2021 11:09:42 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id lo4so33255392ejb.7 for ; Mon, 16 Aug 2021 11:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mind.be; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=NFp8ItiruJnih8e9B4NvO8TxjUv+6GZH4k3SEINJRWk=; b=E1InZ1hal7yp02RIrwVVQjsdGWFrPpLbbs2F7t3WAdWY1X9p3HMjfAXGSmw4peYrPc hn5ACP1mNRr6UqSHEav6ZuaV7j9Sp9qjLVZ0BPsX5CoUdTcsoKlUtl4tCGaA4lypA7J/ QfpbRzbsFrrHNEoUHXFQbbTmys9d10Cx2bNOdxTy8MhVZZV4iZuKnk1r1mN+8ZWVHUeI 5ali6tx0mWL0IZmq9Y7FkxWu7x5TnvhqOwT+FQ8YqHFlyaHAo9Yu+jSqxOhaKAmTIVVV j+sGFEZ8qZIqDtMa6gIvtoxoIerL6rDMO7rAugqRs6aTQ+G6HWKwd3VZ3Jd3kWPAk8Eg DiOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=NFp8ItiruJnih8e9B4NvO8TxjUv+6GZH4k3SEINJRWk=; b=UJwxjDd90c/LtAqTDxsJmEk8eX6F0/S7B3ldB68CVRgl1ldfgRFIbnJEY+SjqLDdMF snpvDXTmqUTEqylOj6foXWpnW8vkRHw+Nw9MTnU5/bPTxrucGF10Fv8sSbrYcmvbL6y2 O4Ge0XvEB+pWnrk8ql45PUypw9FSO+O7Gyc/XrDIXO4nexf+7cwXR0R+mRZwyXTxoYph 72NnEo05o3dbsVLFTq1JLBBuzQx/7rp8J0ndayyMmxYEVwLm3HB3+hpVUbCfYPSPqdJ/ HkyWHQ4wKGhxY+Jn2DlPhr9ZkU6hJCZuukmBpuXGS1hFd6iMW+7x+IXsYtMxQrt24Glw rdJw== X-Gm-Message-State: AOAM5336XkVe4CyHbJIy1monRgAsMt9K5vkQAoog+zhKVsHN4LvPlOtA 91lfs8ogOTm9rkpS/atviJGZLQ== X-Google-Smtp-Source: ABdhPJyd6Icy7JkcnIET+jJmCfJJVeWWnPGZJHWOUFGzYh0WiS8FCkv7jqnD53UJkM7z99h59bPGRw== X-Received: by 2002:a17:906:6847:: with SMTP id a7mr8949015ejs.288.1629137380678; Mon, 16 Aug 2021 11:09:40 -0700 (PDT) Received: from cephalopod (168.7-181-91.adsl-dyn.isp.belgacom.be. [91.181.7.168]) by smtp.gmail.com with ESMTPSA id t17sm5180003edw.13.2021.08.16.11.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 11:09:40 -0700 (PDT) Date: Mon, 16 Aug 2021 20:09:38 +0200 From: Ben Hutchings To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 4/5] net: dsa: microchip: ksz8795: Fix VLAN untagged flag change on deletion Message-ID: <20210816180938.GH18930@cephalopod> References: <20210816174905.GD18930@cephalopod> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210816174905.GD18930@cephalopod> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org commit af01754f9e3c553a2ee63b4693c79a3956e230ab upstream. When a VLAN is deleted from a port, the flags in struct switchdev_obj_port_vlan are always 0. ksz8_port_vlan_del() copies the BRIDGE_VLAN_INFO_UNTAGGED flag to the port's Tag Removal flag, and therefore always clears it. In case there are multiple VLANs configured as untagged on this port - which seems useless, but is allowed - deleting one of them changes the remaining VLANs to be tagged. It's only ever necessary to change this flag when a VLAN is added to the port, so leave it unchanged in ksz8_port_vlan_del(). Fixes: e66f840c08a2 ("net: dsa: ksz: Add Microchip KSZ8795 DSA driver") Signed-off-by: Ben Hutchings Signed-off-by: David S. Miller [bwh: Backport to 5.10: adjust context] Signed-off-by: Ben Hutchings --- drivers/net/dsa/microchip/ksz8795.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index b4b164d75520..8f2b54ae57f2 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -895,7 +895,6 @@ static void ksz8795_port_vlan_add(struct dsa_switch *ds, int port, static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port, const struct switchdev_obj_port_vlan *vlan) { - bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; struct ksz_device *dev = ds->priv; u16 data, vid, pvid; u8 fid, member, valid; @@ -904,8 +903,6 @@ static int ksz8795_port_vlan_del(struct dsa_switch *ds, int port, ksz_pread16(dev, port, REG_PORT_CTRL_VID, &pvid); pvid = pvid & 0xFFF; - ksz_port_cfg(dev, port, P_TAG_CTRL, PORT_REMOVE_TAG, untagged); - for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { ksz8795_r_vlan_table(dev, vid, &data); ksz8795_from_vlan(data, &fid, &member, &valid); From patchwork Mon Aug 16 18:09:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 497925 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=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_1 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 12E88C4320E for ; Mon, 16 Aug 2021 18:09:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDA5660EFF for ; Mon, 16 Aug 2021 18:09:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232426AbhHPSK1 (ORCPT ); Mon, 16 Aug 2021 14:10:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233109AbhHPSKZ (ORCPT ); Mon, 16 Aug 2021 14:10:25 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F165AC0612A6 for ; Mon, 16 Aug 2021 11:09:48 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id d6so27777072edt.7 for ; Mon, 16 Aug 2021 11:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mind.be; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Zj9DtZNu3Q5lzcO5ya/7HcU4ots3BHO7m+UZEwEjOK0=; b=P3od03FJR7TCIir+ZWZ9KFRvdy627Sj59JznVxQNEjZa6DAEwzLat+vf7fsL9PQ1VN g82QHQo0uSEd2nbyoaIaxq8SAMKn8nJp/9mDdE23HWEkokYeLfS1EAFeC4XsI+YBsGQm bdz+8X1RiY5vA2SuWJO820nQ6wVY+quykzw4wbtATB2lFSv3wOaYmCB64y32DnVxYTyj +Yw7iIY9HT7ib4OE0zs6dZuDKpzCK1WvFDB97AvvzSLKCvm3M3aT9+Y3NNGYx1GymQ6O KqW6EJkyU0eHqPSNpEQ9PpRj159vYQ9NzfqoszO0ccVvSD+3V6Dz5I3Z78tqRA7vfOsy yRlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Zj9DtZNu3Q5lzcO5ya/7HcU4ots3BHO7m+UZEwEjOK0=; b=cDY6R8qKiKeVS7AUXJXoQN1XX97pOwIZxYTU2ciZ0kmTyLanT6WkCrfmhfFKyFYu0s XreqZ5+47BjZBYj8JuWucQZEISZFD50W7fNW5rZCnkMuw2spKaA9bmPXwQLopVBHvd5Y AlcxNxrsbAb86D2EXQdlYLmPUBklax9PATBCO2HfU+yAUkbsIWjqdosLvmfJ2cuKJwlp T1Iyr6OsJNp8not+jp2Du7lABAIwSHfLeQ55XVQgkhPJ1XVIxNaGheqnWflo9M2tOaLS nJ1RWRdXr8/W+PmXRanxPBfPRHzbDK5Hoxw/tqYBJO7AJGSLa/EUMLafbN9vC2egjJEw c7lA== X-Gm-Message-State: AOAM531G9/pyxFOxlQ/EbRA3810lSjmzIU8a+uc+ryEi71VCPhuhGhcj INIqJGn2BDnuWpio8AN2sx90hw== X-Google-Smtp-Source: ABdhPJyu91YcIG5W9sZ9ALo4QBALyweoiLRGGYmbZVc/12XWHfdEMc8XMzaOyCZdbTrBKUIiFGiDqw== X-Received: by 2002:aa7:d681:: with SMTP id d1mr22359818edr.186.1629137387595; Mon, 16 Aug 2021 11:09:47 -0700 (PDT) Received: from cephalopod (168.7-181-91.adsl-dyn.isp.belgacom.be. [91.181.7.168]) by smtp.gmail.com with ESMTPSA id bm1sm3989649ejb.38.2021.08.16.11.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 11:09:47 -0700 (PDT) Date: Mon, 16 Aug 2021 20:09:45 +0200 From: Ben Hutchings To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 5/5] net: dsa: microchip: ksz8795: Use software untagging on CPU port Message-ID: <20210816180945.GI18930@cephalopod> References: <20210816174905.GD18930@cephalopod> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210816174905.GD18930@cephalopod> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org commit 9130c2d30c17846287b803a9803106318cbe5266 upstream. On the CPU port, we can support both tagged and untagged VLANs at the same time by doing any necessary untagging in software rather than hardware. To enable that, keep the CPU port's Remove Tag flag cleared and set the dsa_switch::untag_bridge_pvid flag. Fixes: e66f840c08a2 ("net: dsa: ksz: Add Microchip KSZ8795 DSA driver") Signed-off-by: Ben Hutchings Signed-off-by: David S. Miller [bwh: Backport to 5.10: adjust context] Signed-off-by: Ben Hutchings --- drivers/net/dsa/microchip/ksz8795.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 8f2b54ae57f2..ada0533b81fa 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -812,9 +812,11 @@ static bool ksz8795_port_vlan_changes_remove_tag( /* If a VLAN is added with untagged flag different from the * port's Remove Tag flag, we need to change the latter. * Ignore VID 0, which is always untagged. + * Ignore CPU port, which will always be tagged. */ return untagged != p->remove_tag && - !(vlan->vid_begin == 0 && vlan->vid_end == 0); + !(vlan->vid_begin == 0 && vlan->vid_end == 0) && + port != dev->cpu_port; } int ksz8795_port_vlan_prepare(struct dsa_switch *ds, int port, @@ -1325,6 +1327,11 @@ static int ksz8795_switch_init(struct ksz_device *dev) /* set the real number of ports */ dev->ds->num_ports = dev->port_cnt + 1; + /* We rely on software untagging on the CPU port, so that we + * can support both tagged and untagged VLANs + */ + dev->ds->untag_bridge_pvid = true; + /* VLAN filtering is partly controlled by the global VLAN * Enable flag */