From patchwork Thu Jun 20 00:28:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aryan Srivastava X-Patchwork-Id: 13704760 X-Patchwork-Delegate: kuba@kernel.org Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [202.36.163.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42F6C803 for ; Thu, 20 Jun 2024 00:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.36.163.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718843320; cv=none; b=QTkWLSBeyRQ0MLPjELwYYYvT6uvhq2+vL6zPy8tIwIDlXD1XW41YynDu7GxwyozRJiY+ATxDNcQcdpebEOX1TMBsaTmlbhkMD2ZPxcAX16sVsdeVbYTOHzpvk09bTNu8H+D2AUer0KwjXYVw8R9f7l+p5lSfNl7meSTyro6hdE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718843320; c=relaxed/simple; bh=orcpOtdaVS8Lt/7nnK/nb+mz8CnEu5zIl3alpK03zTY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KmqIbWi4OstAhPxmg4hCkMg/p3j0Vuevrl402TtVOG4V1eSbgQDJxMCWLyCMe/r1/rBFPCrQN6047Ryt7n4tXYrX7sw34x+W76Ak59VXQ3qnFTv1UDtZtktT5kDRV1qnvxXiSp1LH9jvVLXrdhvZ/vjBKYE558kBuEfb2uEy974= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz; spf=pass smtp.mailfrom=alliedtelesis.co.nz; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b=cp2tc/uL; arc=none smtp.client-ip=202.36.163.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="cp2tc/uL" Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id BD9F12C0240; Thu, 20 Jun 2024 12:28:35 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1718843315; bh=Lp0DNFqLPHML0eGPT5nW0MrIY2TAE9vKBYzLLBAqySw=; h=From:To:Cc:Subject:Date:From; b=cp2tc/uLVhYDT+l1Kd9iDU6pIc016zYPed3iQ22252Y0LWI6b0gOQtRus7wteeKQU KHtzfANv+av3xBY7/Uo2fmSchk3lSSga9nWDRSfZfK0Tn65zFgPE9zZCLcoOGZWwWA O4XtXCBNQsG/mnu3B6EKg2QVX+yuHskDvnBtVSQQs2PrWSGVpdgf98MQ7DjKNevCR3 Ei7GrpZMWyVSRmEQDsoc1iUB1Cn5BSST+vwVhkz44S1MkMHcBIp4tUOw2/11vcTjrL QkdyjJA65x5iMJ+R7xhp5MKzNC85nn7zk/Fckn2js7DOGuRRBxkIG7YXrMYAkIAZIW bxLkPc/Uh2VWA== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id ; Thu, 20 Jun 2024 12:28:35 +1200 Received: from aryans-dl.ws.atlnz.lc (aryans-dl.ws.atlnz.lc [10.33.22.38]) by pat.atlnz.lc (Postfix) with ESMTP id 7FB0613ED63; Thu, 20 Jun 2024 12:28:35 +1200 (NZST) Received: by aryans-dl.ws.atlnz.lc (Postfix, from userid 1844) id 7BBDD2A0FF5; Thu, 20 Jun 2024 12:28:35 +1200 (NZST) From: Aryan Srivastava To: Andrew Lunn , =?utf-8?q?Marek_Beh=C3=BAn?= Cc: Aryan Srivastava , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] net: dsa: mv88e6xxx: Add FID map cache Date: Thu, 20 Jun 2024 12:28:26 +1200 Message-ID: <20240620002826.213013-1-aryan.srivastava@alliedtelesis.co.nz> X-Mailer: git-send-email 2.43.2 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SEG-SpamProfiler-Analysis: v=2.4 cv=CvQccW4D c=1 sm=1 tr=0 ts=667377b3 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=T1WGqf2p2xoA:10 a=d04kM7kIrsN5wIaQCncA:9 a=3ZKOabzyN94A:10 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat X-Patchwork-Delegate: kuba@kernel.org Add a cached FID bitmap. This mitigates the need to walk all VTU entries to find the next free FID. Walk VTU once, then store read FID map into bitmap. Use and manipulate this bitmap from now on, instead of re-reading HW for the FID map. The repeatedly VTU walks are costly can result in taking ~40 mins if ~4000 vlans are added. Caching the FID map reduces this time to <2 mins. Signed-off-by: Aryan Srivastava --- drivers/net/dsa/mv88e6xxx/chip.c | 37 +++++++++++++++++++---------- drivers/net/dsa/mv88e6xxx/chip.h | 3 +++ drivers/net/dsa/mv88e6xxx/devlink.c | 9 +------ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index e5bac87941f6..38426434707c 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1726,14 +1726,6 @@ static void mv88e6xxx_port_fast_age(struct dsa_switch *ds, int port) port, err); } -static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip) -{ - if (!mv88e6xxx_max_vid(chip)) - return 0; - - return mv88e6xxx_g1_vtu_flush(chip); -} - static int mv88e6xxx_vtu_get(struct mv88e6xxx_chip *chip, u16 vid, struct mv88e6xxx_vtu_entry *entry) { @@ -1813,16 +1805,25 @@ int mv88e6xxx_fid_map(struct mv88e6xxx_chip *chip, unsigned long *fid_bitmap) return mv88e6xxx_vtu_walk(chip, mv88e6xxx_fid_map_vlan, fid_bitmap); } -static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid) +static int mv88e6xxx_vtu_setup(struct mv88e6xxx_chip *chip) { - DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID); int err; - err = mv88e6xxx_fid_map(chip, fid_bitmap); + if (!mv88e6xxx_max_vid(chip)) + return 0; + + err = mv88e6xxx_g1_vtu_flush(chip); if (err) return err; - *fid = find_first_zero_bit(fid_bitmap, MV88E6XXX_N_FID); + return mv88e6xxx_fid_map(chip, chip->fid_bitmap); +} + +static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid) +{ + int err; + + *fid = find_first_zero_bit(chip->fid_bitmap, MV88E6XXX_N_FID); if (unlikely(*fid >= mv88e6xxx_num_databases(chip))) return -ENOSPC; @@ -2529,6 +2530,9 @@ static int mv88e6xxx_port_vlan_join(struct mv88e6xxx_chip *chip, int port, port, vid); } + /* Record FID used in SW FID map */ + bitmap_set(chip->fid_bitmap, vlan.fid, 1); + return 0; } @@ -2636,7 +2640,14 @@ static int mv88e6xxx_port_vlan_leave(struct mv88e6xxx_chip *chip, return err; } - return mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false); + err = mv88e6xxx_g1_atu_remove(chip, vlan.fid, port, false); + if (err) + return err; + + /* Record FID freed in SW FID map */ + bitmap_clear(chip->fid_bitmap, vlan.fid, 1); + + return err; } static int mv88e6xxx_port_vlan_del(struct dsa_switch *ds, int port, diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index c54d305a1d83..37958a016a3f 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -421,6 +421,9 @@ struct mv88e6xxx_chip { /* Bridge MST to SID mappings */ struct list_head msts; + + /* FID map */ + DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID); }; struct mv88e6xxx_bus_ops { diff --git a/drivers/net/dsa/mv88e6xxx/devlink.c b/drivers/net/dsa/mv88e6xxx/devlink.c index a08dab75e0c0..ef3643bc43db 100644 --- a/drivers/net/dsa/mv88e6xxx/devlink.c +++ b/drivers/net/dsa/mv88e6xxx/devlink.c @@ -374,7 +374,6 @@ static int mv88e6xxx_region_atu_snapshot(struct devlink *dl, u8 **data) { struct dsa_switch *ds = dsa_devlink_to_ds(dl); - DECLARE_BITMAP(fid_bitmap, MV88E6XXX_N_FID); struct mv88e6xxx_devlink_atu_entry *table; struct mv88e6xxx_chip *chip = ds->priv; int fid = -1, count, err; @@ -392,14 +391,8 @@ static int mv88e6xxx_region_atu_snapshot(struct devlink *dl, mv88e6xxx_reg_lock(chip); - err = mv88e6xxx_fid_map(chip, fid_bitmap); - if (err) { - kfree(table); - goto out; - } - while (1) { - fid = find_next_bit(fid_bitmap, MV88E6XXX_N_FID, fid + 1); + fid = find_next_bit(chip->fid_bitmap, MV88E6XXX_N_FID, fid + 1); if (fid == MV88E6XXX_N_FID) break;