Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2637455pxa; Mon, 17 Aug 2020 15:07:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6XeTDCoJiqYaM24doY6Oe3J3IXhFm5gYCLsov4wwZuCHfQOHYU28xQtC9OefvXVuN1LDa X-Received: by 2002:a17:906:4d4f:: with SMTP id b15mr16979532ejv.534.1597702050596; Mon, 17 Aug 2020 15:07:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597702050; cv=none; d=google.com; s=arc-20160816; b=PHqPeuLeulsLl8kS2A7o0+pXQPCBiTX/s+u4HuUAgd89aIj3ao4Yzs5484PPbgUeSP /PYbJygNgiAnetXUfmQNQMWnmuLIbz15i0tZb6sxkOGDeOmAsmhjsy5bP+hem4Q/mF7k 1lP/ouJeSOO+mEX3x8+CH/FFvUj85Hy2cgVzPc09AX8FyUXeQ+orH/UbNxrfN7XKbJDv 9qqDK5XHQ83U07t3xcoROk4XOEpHvitx9z7FayoKSAcLNX+YqrP9nxN5iueUu6H/x8JU 2SGph9bag52tkD4GsSCRJDTv+fJPjSX7PsI+7ONvDL7V8jNnNm5ivsUyICxU6KXsjDUU qTnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QY9IBJdbndl1yQw4Mx1AlvPhFNRE8nfdVXtmR/ixVPA=; b=djiRbYZ3I4WywFBd/PzPRlJZIV7trmGuO9pZE2kdiLHlzO2LRkDTa44KzXHlHFBu7E pZj0rjRwHRd3l8wy5gRxFYIW0MzmIbsTu4tCbi2HXPlXVfMVMDExnCvOTeTVXsSoUWAO eMeb2nwki4Mq5+VC730G+xCw41hc9KGKWvNlGvLmxIiUxIr80PwV0/CYZUlU1VUM4ZPS 65ETOe9vS2Xu1nY4mrB5g94hviVlmrKz2XUZApX1hER8AGB94IcD5D+mK8FujXVeh+eN VSHKFcimWkW2EMBYtuqO9XTpsGUk9PNuffBBflOU1ZPSwaB8db1OaljogIQjOhnDUI6s RFgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N5HKuMmw; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id aq7si11334741ejc.562.2020.08.17.15.07.06; Mon, 17 Aug 2020 15:07:30 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=N5HKuMmw; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388211AbgHQQCk (ORCPT + 99 others); Mon, 17 Aug 2020 12:02:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:53876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387616AbgHQPn1 (ORCPT ); Mon, 17 Aug 2020 11:43:27 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B610922D02; Mon, 17 Aug 2020 15:43:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679007; bh=xnrS1ql8mTJfZuXx7vS6OCxPj+h1Ygx9v8nHW/GzhqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N5HKuMmwNSkUhEm0doDrh1lW0twdOz2wANzoVMDmiMbP/rxYRyqSHmB516ZYaPocX 2MId48h7Nqa+2h4kwgwCwbN+WMZadUIixLmi1TRFkllARpqe4hz8pC5Y8ufDYKLuPD Dlmv0qZkxKBDvGjcmqYjdJuMUTU3ufndmNQ2DVW8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , "David S. Miller" , Sasha Levin Subject: [PATCH 5.7 065/393] net: mscc: ocelot: fix encoding destination ports into multicast IPv4 address Date: Mon, 17 Aug 2020 17:11:55 +0200 Message-Id: <20200817143822.783450813@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean [ Upstream commit 0897ecf7532577bda3dbcb043ce046a96948889d ] The ocelot hardware designers have made some hacks to support multicast IPv4 and IPv6 addresses. Normally, the MAC table matches on MAC addresses and the destination ports are selected through the DEST_IDX field of the respective MAC table entry. The DEST_IDX points to a Port Group ID (PGID) which contains the bit mask of ports that frames should be forwarded to. But there aren't a lot of PGIDs (only 80 or so) and there are clearly many more IP multicast addresses than that, so it doesn't scale to use this PGID mechanism, so something else was done. Since the first portion of the MAC address is known, the hack they did was to use a single PGID for _flooding_ unknown IPv4 multicast (PGID_MCIPV4 == 62), but for known IP multicast, embed the destination ports into the first 3 bytes of the MAC address recorded in the MAC table. The VSC7514 datasheet explains it like this: 3.9.1.5 IPv4 Multicast Entries MAC table entries with the ENTRY_TYPE = 2 settings are interpreted as IPv4 multicast entries. IPv4 multicasts entries match IPv4 frames, which are classified to the specified VID, and which have DMAC = 0x01005Exxxxxx, where xxxxxx is the lower 24 bits of the MAC address in the entry. Instead of a lookup in the destination mask table (PGID), the destination set is programmed as part of the entry MAC address. This is shown in the following table. Table 78: IPv4 Multicast Destination Mask Destination Ports Record Bit Field --------------------------------------------- Ports 10-0 MAC[34-24] Example: All IPv4 multicast frames in VLAN 12 with MAC 01005E112233 are to be forwarded to ports 3, 8, and 9. This is done by inserting the following entry in the MAC table entry: VALID = 1 VID = 12 MAC = 0x000308112233 ENTRY_TYPE = 2 DEST_IDX = 0 But this procedure is not at all what's going on in the driver. In fact, the code that embeds the ports into the MAC address looks like it hasn't actually been tested. This patch applies the procedure described in the datasheet. Since there are many other fixes to be made around multicast forwarding until it works properly, there is no real reason for this patch to be backported to stable trees, or considered a real fix of something that should have worked. Signed-off-by: Vladimir Oltean Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/mscc/ocelot.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 76dbf9ac8ad50..1eaefc0ff87e6 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -1599,14 +1599,14 @@ static int ocelot_port_obj_add_mdb(struct net_device *dev, addr[0] = 0; if (!new) { - addr[2] = mc->ports << 0; - addr[1] = mc->ports << 8; + addr[1] = mc->ports >> 8; + addr[2] = mc->ports & 0xff; ocelot_mact_forget(ocelot, addr, vid); } mc->ports |= BIT(port); - addr[2] = mc->ports << 0; - addr[1] = mc->ports << 8; + addr[1] = mc->ports >> 8; + addr[2] = mc->ports & 0xff; return ocelot_mact_learn(ocelot, 0, addr, vid, ENTRYTYPE_MACv4); } @@ -1630,9 +1630,9 @@ static int ocelot_port_obj_del_mdb(struct net_device *dev, return -ENOENT; memcpy(addr, mc->addr, ETH_ALEN); - addr[2] = mc->ports << 0; - addr[1] = mc->ports << 8; addr[0] = 0; + addr[1] = mc->ports >> 8; + addr[2] = mc->ports & 0xff; ocelot_mact_forget(ocelot, addr, vid); mc->ports &= ~BIT(port); @@ -1642,8 +1642,8 @@ static int ocelot_port_obj_del_mdb(struct net_device *dev, return 0; } - addr[2] = mc->ports << 0; - addr[1] = mc->ports << 8; + addr[1] = mc->ports >> 8; + addr[2] = mc->ports & 0xff; return ocelot_mact_learn(ocelot, 0, addr, vid, ENTRYTYPE_MACv4); } -- 2.25.1