Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2024680ybl; Thu, 29 Aug 2019 02:27:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyY97f0wOu482Hc5v8MEK+AilySeEzwd3gmGGvo1Gm2hru1qNaNc2s8pEks/GSoLJYou+Bm X-Received: by 2002:a17:90b:8ce:: with SMTP id ds14mr8656062pjb.105.1567070822226; Thu, 29 Aug 2019 02:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567070822; cv=none; d=google.com; s=arc-20160816; b=nO/jmAJNcUGLyN0re2vz/N5Tgvv3QxQk6YSLlcGuQVftPgapZTkgcwnpR5eXe8duLO NSZGDX59AU2eFQs0b43SpDM8ca3qfrmQHAWF33qINQ71QcAUKllsP64ppvcIYjdZAJ7w QuDKxRmmbIGgvb9HMJV4jaiQpjOJ7AmL71RtcSggMnIHXGSwv97/8o7zAxdcP6bmL0Qt 5uGfrzr+EsYBpzzZ0/0tehcqyWZkt7AMew84S76O2roT8a7rxNFAqgYVSLWPvb89rENl GrtrsaGo9Xm7MoAzGIn7IwmGC5OWsvt9sIpi/hc0Wg4do6+la5Ivbc1QuppHNWB73oxc qHFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr; bh=elqTRB7POfCdjcN6IsDIrGt2uwMtSjyVUb2FfV8dkUA=; b=d6X4cB4rh9IHCrziIwKXE8Wqug7jj+os619EKcaRszHz7NZkZt1wTGteQug13vHI5M +7z3SEXDiBHQE7l8ADb9TduwZJVUZpVCChHfo6as5t2//NIQh0k004f0rfkYig2YBXZe NmJMFm9ckfv3zH1YfZwriwHbHX6vTz4v3Wu2Y65Abji4NZ9Pl+ptfAGSCh/Wqot6J+AK H86M7ppuVt+mWnNaFmDkfUBTfIK7e8m4E9AdEkkgo+g+waozEE+HxHT0Rq0LH5gAiu/X U5KnGFEdI9nnFOQYNw92Mh5OQYJjeeAPMZ1Ms0PDV01jhZ5aE92VkRxaZ8DXPqDgUw++ xPLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=microchip.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si1511814pgp.250.2019.08.29.02.26.46; Thu, 29 Aug 2019 02:27:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727956AbfH2JYW (ORCPT + 99 others); Thu, 29 Aug 2019 05:24:22 -0400 Received: from esa6.microchip.iphmx.com ([216.71.154.253]:41005 "EHLO esa6.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726009AbfH2JYU (ORCPT ); Thu, 29 Aug 2019 05:24:20 -0400 Received-SPF: Pass (esa6.microchip.iphmx.com: domain of Horatiu.Vultur@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa6.microchip.iphmx.com; envelope-from="Horatiu.Vultur@microchip.com"; x-sender="Horatiu.Vultur@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa6.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa6.microchip.iphmx.com; envelope-from="Horatiu.Vultur@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa6.microchip.iphmx.com; dkim=none (message not signed) header.i=none; spf=Pass smtp.mailfrom=Horatiu.Vultur@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: dcw5HvdrWWW4kbMXgGxuMElWhsYPDEZ2r2ibGqZjytgKP860+4DfHv4CXfMD+ddtYGad9OBMgT 38QTqQVbl2yzZ+ozBONDV5w410Xbb6vA2BfRsO/us879/sNPHi9jBAt6k1gCLn1wweLlZ5pP7l NUY5jztFbtc1yKOaHBgYFju0MQRk+A3MIT/Ym64A7PEYgxPqLc1jx0+BMfbu14byb8OEAVjLHH O2iC7jC4Stuup5FZl7lCyFZx2Vkd45pwVLTGEoeLzSD/E9Jyac3BplEO9ava/k3m8vjOrXTab5 pq8= X-IronPort-AV: E=Sophos;i="5.64,442,1559545200"; d="scan'208";a="44136216" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 29 Aug 2019 02:24:20 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 29 Aug 2019 02:24:16 -0700 Received: from soft-dev3.microsemi.net (10.10.85.251) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Thu, 29 Aug 2019 02:24:17 -0700 From: Horatiu Vultur To: , , , , , , , , , CC: Horatiu Vultur Subject: [PATCH v3 2/2] net: mscc: Implement promisc mode. Date: Thu, 29 Aug 2019 11:22:29 +0200 Message-ID: <1567070549-29255-3-git-send-email-horatiu.vultur@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1567070549-29255-1-git-send-email-horatiu.vultur@microchip.com> References: <1567070549-29255-1-git-send-email-horatiu.vultur@microchip.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a port is added to the bridge, the port is added in promisc mode. But the HW is capable of switching the frames therefore is not needed for the port to be added in promisc mode. In case a user space application requires for the port to enter promisc mode then is it needed to enter the promisc mode. Therefore listen in when the promiscuity on a dev is change and when the port enters or leaves a bridge. Having this information it is possible to know when to set the port in promisc mode and when not: If the port is part of bridge and promiscuity > 1 or if the port is not part of bridge and promiscuity is > 0 then add then add the port in promisc mode otherwise don't. Signed-off-by: Horatiu Vultur --- drivers/net/ethernet/mscc/ocelot.c | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 4d1bce4..292fcc1 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -1294,6 +1294,37 @@ static void ocelot_port_attr_mc_set(struct ocelot_port *port, bool mc) ocelot_write_gix(ocelot, val, ANA_PORT_CPU_FWD_CFG, port->chip_port); } +static void ocelot_port_attr_promisc_set(struct ocelot_port *port, + unsigned int promisc, + bool is_bridge_port) +{ + struct ocelot *ocelot = port->ocelot; + u32 val; + + val = ocelot_read_gix(ocelot, ANA_PORT_CPU_FWD_CFG, port->chip_port); + + /* When a port is added to a bridge, the port is added in promisc mode, + * by calling the function 'ndo_set_rx_mode'. But the HW is capable + * of switching the frames therefore is not needed for the port to + * enter in promisc mode. + * But a port needs to be added in promisc mode if an application + * requires it(pcap library). Therefore listen when the + * dev->promiscuity is change and when the port is added or removed from + * the bridge. Using this information, calculate if the promisc mode + * is required in the following way: + */ + if (!is_bridge_port && promisc > 0) { + val |= ANA_PORT_CPU_FWD_CFG_CPU_SRC_COPY_ENA; + } else { + if (is_bridge_port && promisc > 1) + val |= ANA_PORT_CPU_FWD_CFG_CPU_SRC_COPY_ENA; + else + val &= ~(ANA_PORT_CPU_FWD_CFG_CPU_SRC_COPY_ENA); + } + + ocelot_write_gix(ocelot, val, ANA_PORT_CPU_FWD_CFG, port->chip_port); +} + static int ocelot_port_attr_set(struct net_device *dev, const struct switchdev_attr *attr, struct switchdev_trans *trans) @@ -1316,6 +1347,10 @@ static int ocelot_port_attr_set(struct net_device *dev, case SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED: ocelot_port_attr_mc_set(ocelot_port, !attr->u.mc_disabled); break; + case SWITCHDEV_ATTR_ID_PORT_PROMISCUITY: + ocelot_port_attr_promisc_set(ocelot_port, dev->promiscuity, + netif_is_bridge_port(dev)); + break; default: err = -EOPNOTSUPP; break; @@ -1688,6 +1723,18 @@ static int ocelot_netdevice_port_event(struct net_device *dev, ocelot_vlan_port_apply(ocelot_port->ocelot, ocelot_port); + + /* In case the port is added or removed from the bridge + * is it needed to recaulculate the promiscuity. The + * reason is that when a port leaves the bridge first + * it decrease the promiscuity and then the flag + * IFF_BRIDGE_PORT is removed from dev. Therefor the + * function ocelot_port_attr_promisc is called with + * the wrong arguments. + */ + ocelot_port_attr_promisc_set(ocelot_port, + dev->promiscuity, + info->linking); } if (netif_is_lag_master(info->upper_dev)) { if (info->linking) -- 2.7.4