From patchwork Tue Apr 14 04:16:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 221222 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=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 68D53C2BB1D for ; Tue, 14 Apr 2020 04:17:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45BB42072D for ; Tue, 14 Apr 2020 04:17:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n1mQh4zZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405199AbgDNERT (ORCPT ); Tue, 14 Apr 2020 00:17:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2405149AbgDNEQq (ORCPT ); Tue, 14 Apr 2020 00:16:46 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD440C008748; Mon, 13 Apr 2020 21:16:45 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id a25so12727319wrd.0; Mon, 13 Apr 2020 21:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ra5+xF56vl//7UQmklkjgQ0mAqGgB+1LQ/hOVbR+zp8=; b=n1mQh4zZgBTivIGIq0ThPh99lt7S4FyW1UChIFlAwSdXkBJR2/4+kSNFOa/WCLQA03 nkg/u3g+SRR0REzWDyTaoYwsc+1kZ3R5zIpgqdDI8Fdx3pwMUxYuPDJc879NJzCbCqTS Yg+lwbtKbsMfPp/Plt5urXY7NUAcKKlowAUNj+WbOiRq4aXfG65C6i85IEnvygc0vlcP Me5OX7gtNUwonSK03HGwxucAg0ljDeNBsajyWyVCI37QWVq6EWcN+bzlBkFHjZXLf0w7 KSmtnhzTkBygOd3vULpq+Ss6TooUf4zBnJ8gx7i7VnmIdydkvu87illGZUh1urZS11gj Osfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ra5+xF56vl//7UQmklkjgQ0mAqGgB+1LQ/hOVbR+zp8=; b=AjJ0kUMgm857nmte4Ht4PFSP7w+Gb5TZ9MeiHEsgS34ZeJiB+U32SSMToJHHxDjtV8 VLFak+6Kf2nxM4LEEW1lMJoG7v+8PD+x69Zpw0NRWufuzwCG8YQCg8e/ejAUSqe6jed0 dJa9yf4HFsuOIWDl5XpU6WG7erkT6ts11JEieKZaBf5D5eH0WGgTB/Hd1eYg4ki9F0hw ksm7rj3N3Pdy/PsO0USE0gLEhMBXLOWG6oD4cwpTR+D0HqFiKyBbYDAN5fbPSY9+BUgG tWsie4b2/3M0UNkSrxYGcjqMkYbZ3DDFpdIetGrN+39P3FrRiTR1RThv2SXY8fJvJPGu ZlsQ== X-Gm-Message-State: AGi0PubDjWwcUpQc1DhQTXwrnBh4EyvafWQhQKNjY4P0NljjuHzhwot4 YGiX3RyyVzgtiBv/ei6ChasZXDLA X-Google-Smtp-Source: APiQypJ/i7+CQzsGFIbl7j9E8gK6ahy1bJ4l277DKHg/E1+y06RBB87cOEhcbxQubMbHmFFOlf1Cnw== X-Received: by 2002:a5d:5273:: with SMTP id l19mr21605238wrc.42.1586837804231; Mon, 13 Apr 2020 21:16:44 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id n4sm16704471wmi.20.2020.04.13.21.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2020 21:16:43 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , linux-kernel@vger.kernel.org (open list), davem@davemloft.net, kuba@kernel.org Subject: [PATCH net 3/4] net: dsa: b53: Fix ARL register definitions Date: Mon, 13 Apr 2020 21:16:29 -0700 Message-Id: <20200414041630.5740-4-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414041630.5740-1-f.fainelli@gmail.com> References: <20200414041630.5740-1-f.fainelli@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The ARL {MAC,VID} tuple and the forward entry were off by 0x10 bytes, which means that when we read/wrote from/to ARL bin index 0, we were actually accessing the ARLA_RWCTRL register. Fixes: 1da6df85c6fb ("net: dsa: b53: Implement ARL add/del/dump operations") Signed-off-by: Florian Fainelli --- drivers/net/dsa/b53/b53_regs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h index 2a9f421680aa..d914e756cdab 100644 --- a/drivers/net/dsa/b53/b53_regs.h +++ b/drivers/net/dsa/b53/b53_regs.h @@ -304,7 +304,7 @@ * * BCM5325 and BCM5365 share most definitions below */ -#define B53_ARLTBL_MAC_VID_ENTRY(n) (0x10 * (n)) +#define B53_ARLTBL_MAC_VID_ENTRY(n) ((0x10 * (n)) + 0x10) #define ARLTBL_MAC_MASK 0xffffffffffffULL #define ARLTBL_VID_S 48 #define ARLTBL_VID_MASK_25 0xff @@ -316,7 +316,7 @@ #define ARLTBL_VALID_25 BIT(63) /* ARL Table Data Entry N Registers (32 bit) */ -#define B53_ARLTBL_DATA_ENTRY(n) ((0x10 * (n)) + 0x08) +#define B53_ARLTBL_DATA_ENTRY(n) ((0x10 * (n)) + 0x18) #define ARLTBL_DATA_PORT_ID_MASK 0x1ff #define ARLTBL_TC(tc) ((3 & tc) << 11) #define ARLTBL_AGE BIT(14) From patchwork Tue Apr 14 04:16:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 221223 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=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 409E0C2BBFD for ; Tue, 14 Apr 2020 04:16:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 208B82072D for ; Tue, 14 Apr 2020 04:16:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pupj91GB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405180AbgDNEQv (ORCPT ); Tue, 14 Apr 2020 00:16:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2405167AbgDNEQs (ORCPT ); Tue, 14 Apr 2020 00:16:48 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6097C0A3BDC; Mon, 13 Apr 2020 21:16:47 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id a25so12727367wrd.0; Mon, 13 Apr 2020 21:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8+FrUca9gQRLeYSS11nklym7WjOSuUcaGzg4kk+01tQ=; b=pupj91GB0MguZ3qm6Rz3Fej2+i4TI2Ni4aQKc7mhm+6OQB8W7zvGLpXk6N1ldiM0PM UwiICYKKlj/9cNwuN10x8/jNZj2O858PeAU25ExxtTddQIgVuLh2vNKpwncE+fT9giPK ey4YhzBUMWC/GQS5lJn1mRhkotxQdz1lyMwXWfBso0mFPazLDAdBBuMlsRll9VdavIqx dlALdfQd0ZqqY9L/I05KQa5EFV32rK11UUoUkzwfDxgokvY5cq+S8ZrAzyMMY0mvk6cs c7v2Qp6J3X/vKHy5S+IonJebr2wmWDxea1bVjEuT/FU/H2G2U5brpcI42LZADiAHlLbZ 80GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8+FrUca9gQRLeYSS11nklym7WjOSuUcaGzg4kk+01tQ=; b=o4eESWmp/uvahvlTmUKatLGF5kvN/FZcer9kSHTd9lo5P41SNxdXwWsamH1tfTMC/K maRfM0J5LHT5aTaTBEWBjykFGTJDi9LnbiDmUwT/IloiNdIrDuHi2OdAh3jqaHva7FR8 oUgzpB8pLbCj9kSe39sktVmqNJUBIgzO9vrziiipwp1O5Tx9Rd74kwb4BoY2aVgRd3UB eYL3Yz5CtvfuaCu5M5juOjS23bU8AYIbixxQcyYl67fL7qW+YgDVjppOYGcGtFYbVVUC un5j/LIxzy2++XT4+JnOuHv2RGY11bREFIG9iY9X2tAgc7tHvvYRfWPie65tIXArEz9s 6rbg== X-Gm-Message-State: AGi0PuZk6JkQwot/zkUicJDbTHkNqCjPi+FrGuTrJO/nnxlHB8gx/+Yq uQM2aqDhHLcJnUImRNRqaiDrptsN X-Google-Smtp-Source: APiQypK7D1pS3X0E8mch1uooa9sSpvYvwAtKVfaDNpmQrYlmVj4QRIdfwkICUTrLBnc9/6sDI3KdAw== X-Received: by 2002:adf:ed07:: with SMTP id a7mr22431728wro.2.1586837806339; Mon, 13 Apr 2020 21:16:46 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id n4sm16704471wmi.20.2020.04.13.21.16.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2020 21:16:45 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , linux-kernel@vger.kernel.org (open list), davem@davemloft.net, kuba@kernel.org Subject: [PATCH net 4/4] net: dsa: b53: Rework ARL bin logic Date: Mon, 13 Apr 2020 21:16:30 -0700 Message-Id: <20200414041630.5740-5-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414041630.5740-1-f.fainelli@gmail.com> References: <20200414041630.5740-1-f.fainelli@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When asking the ARL to read a MAC address, we will get a number of bins returned in a single read. Out of those bins, there can essentially be 3 states: - all bins are full, we have no space left, and we can either replace an existing address or return that full condition - the MAC address was found, then we need to return its bin index and modify that one, and only that one - the MAC address was not found and we have a least one bin free, we use that bin index location then The code would unfortunately fail on all counts. Fixes: 1da6df85c6fb ("net: dsa: b53: Implement ARL add/del/dump operations") Signed-off-by: Florian Fainelli --- drivers/net/dsa/b53/b53_common.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index e937bf365490..b2b2c4a301bf 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -1483,6 +1483,7 @@ static int b53_arl_read(struct b53_device *dev, u64 mac, u16 vid, struct b53_arl_entry *ent, u8 *idx, bool is_valid) { + DECLARE_BITMAP(free_bins, dev->num_arl_entries); unsigned int i; int ret; @@ -1490,6 +1491,8 @@ static int b53_arl_read(struct b53_device *dev, u64 mac, if (ret) return ret; + bitmap_zero(free_bins, dev->num_arl_entries); + /* Read the bins */ for (i = 0; i < dev->num_arl_entries; i++) { u64 mac_vid; @@ -1501,16 +1504,24 @@ static int b53_arl_read(struct b53_device *dev, u64 mac, B53_ARLTBL_DATA_ENTRY(i), &fwd_entry); b53_arl_to_entry(ent, mac_vid, fwd_entry); - if (!(fwd_entry & ARLTBL_VALID)) + if (!(fwd_entry & ARLTBL_VALID)) { + set_bit(i, free_bins); continue; + } if ((mac_vid & ARLTBL_MAC_MASK) != mac) continue; if (dev->vlan_enabled && ((mac_vid >> ARLTBL_VID_S) & ARLTBL_VID_MASK) != vid) continue; *idx = i; + return 0; } + if (bitmap_weight(free_bins, dev->num_arl_entries) == 0) + return -ENOSPC; + + *idx = find_first_bit(free_bins, dev->num_arl_entries); + return -ENOENT; } @@ -1537,13 +1548,21 @@ static int b53_arl_op(struct b53_device *dev, int op, int port, ret = b53_arl_read(dev, mac, vid, &ent, &idx, is_valid); /* If this is a read, just finish now */ - if (op) + if (op && ret != -ENOENT) return ret; /* We could not find a matching MAC, so reset to a new entry */ - if (ret) { + switch (ret) { + case -ENOSPC: + dev_warn(dev->dev, "no space left in ARL\n"); + return ret; + case -ENOENT: + dev_dbg(dev->dev, "{%pM,%.4d} not found, using idx: %d\n", addr, vid, idx); fwd_entry = 0; - idx = 1; + break; + default: + dev_dbg(dev->dev, "{%pM,%.4d} found, using idx: %d\n", addr, vid, idx); + break; } /* For multicast address, the port is a bitmask and the validity