From patchwork Thu Feb 2 12:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rakesh Sankaranarayanan X-Patchwork-Id: 51908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp221068wrn; Thu, 2 Feb 2023 04:59:57 -0800 (PST) X-Google-Smtp-Source: AK7set8oDl0OTa/a3vIeJdqg5DvIvhivollD+oEk4AXlrI+qExIyd6QoJtk5pxOoO2+0FC5pxTVV X-Received: by 2002:a17:907:9917:b0:88d:6de1:96bf with SMTP id ka23-20020a170907991700b0088d6de196bfmr6779905ejc.12.1675342797750; Thu, 02 Feb 2023 04:59:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675342797; cv=none; d=google.com; s=arc-20160816; b=x3Vs2UC+FY37DIurC8Ed+Jaa12IoD0BT5trNnsDnv7plqqw3W6dbAQhZTweftVBLfa VwjKviS1ZytmZmUDRwxexMiusGTeEmpcecULnVxAFFMNnKNG/D2cvp4zHVkatHUo/yDX 5yEZ/EOIgkYZkMQq2n1bhw2w2BJ0ju1TrYh+WNMz0alFwVDo0RmckJe/O7VfMnru/3PV 4njehy+coGSt+a/e+MBOGHgNjIc55j9nzsICijI2eV+Rz9lqMSAXm++6DMIEpKF8bGcH kbY29yF1HsSeJNi6bc48hUuF007Ha5kLQ3LdVSdJ6nsiZLTIDPFwl1X//krZ0N581ftv DqBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i6sBze9Q/F5bBQLRVveMBui/iR7yOUmv+Yg7bs2H96E=; b=cAhQQBzeiGhf3w1whPHtp+gvoZJeMhUG3dA3uhYFA+HRPnSxuIZPLg8qzzcAsXPgLC ID2UWXewF0aUCwWGcUvewPJItMqrNvVATYWVs+G0SOjCaD2rx7zRcnXts+ttbIfxdC44 dCLf4t6pMp/qkfxc0evSrEz+B5Yojnihf6Qs0VFzN1m9Rj6KsatyaivT8GfYZdcV5X4e jjogG6VwzNq4f0/zi+NwuXksdJAmAvR6yPRf0svh656LMBNWV4Xfu5ImI7wXe+Uz7uoG 6BYiOhxxDwf8DpDi4EF1E5V9YO3Rxu9z/xwk7tX7q2ojtrMBIUnOWZ4cs3DW2cycSJT5 9Q0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=EiVff7Qf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v26-20020a17090610da00b008787c8674b1si7067794ejv.751.2023.02.02.04.59.34; Thu, 02 Feb 2023 04:59:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=EiVff7Qf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232138AbjBBM6v (ORCPT + 99 others); Thu, 2 Feb 2023 07:58:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbjBBM6s (ORCPT ); Thu, 2 Feb 2023 07:58:48 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB254EF82; Thu, 2 Feb 2023 04:58:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1675342726; x=1706878726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bxVhL1m9KqOfZ9Y/N1jqZpYPk1To2xrlI3Xdh5PfAks=; b=EiVff7QfUvQrneIJCVgjDlXUuhtQ4/cOcZXp9T5WL/QQIJuTZKWTfG5g MroN2ACLf9AAfo/nN/u7nNDNhaY25W2pZ8gn9Ofnm5j0oJLkTkpWfAzUl ApsH+60Qu0ulWZTBeZcpb6QE9kFlGuIZgXmF0FYg7h4Ey5PtWZ+aVfpqz jak+nhkj8MVKmSVKk+YE4Vvh9pn5//OHXmfpsAkP0zeI8zvPDCrYl4CLY faR+UH3CTpExA5IChn0Wrjn6e/XKHgw5XbA2bo/D89nPGwJ6SAvJFnbIE 7DwjxKlPge88oSpUU2mqWFaWi2lrBdqQiBRBsKDO2rVGJhvj58WuyeVNh Q==; X-IronPort-AV: E=Sophos;i="5.97,267,1669100400"; d="scan'208";a="198620506" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 02 Feb 2023 05:58:44 -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.2507.16; Thu, 2 Feb 2023 05:58:44 -0700 Received: from che-lt-i67786lx.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Thu, 2 Feb 2023 05:58:39 -0700 From: Rakesh Sankaranarayanan To: , CC: , , , , , , , , , Subject: [RFC PATCH net-next 03/11] net: dsa: microchip: lan937x: enable cascade port Date: Thu, 2 Feb 2023 18:29:22 +0530 Message-ID: <20230202125930.271740-4-rakesh.sankaranarayanan@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202125930.271740-1-rakesh.sankaranarayanan@microchip.com> References: <20230202125930.271740-1-rakesh.sankaranarayanan@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756724249358301531?= X-GMAIL-MSGID: =?utf-8?q?1756724249358301531?= Get index of cascaded port (if any) from device tree and enable the feature. These ports referenced as dev->dsa_port and will be used for processing further based on cascaded connection. For the second switch in cascaded connection, no dev->cpu_port will be assigned, and same happens for dev->dsa_port variable for switches without cascading. For the single switch design, there is no way dev->cpu_port will be unassigned. But coming to cascaded connection, it can be unassigned, and they will be having value zero. Keeping the initial value as zero will create error in other features like port forwarding since DSA will misunderstood these as port index zero. So keep the default values as 0xFF which is of invalid value so that if nothing assigned, taking bitmap of the cpu_port or dsa_port will not cause any harm. Signed-off-by: Rakesh Sankaranarayanan --- drivers/net/dsa/microchip/ksz_common.c | 4 +++ drivers/net/dsa/microchip/ksz_common.h | 2 ++ drivers/net/dsa/microchip/lan937x.h | 1 + drivers/net/dsa/microchip/lan937x_main.c | 31 ++++++++++++++++++++++++ drivers/net/dsa/microchip/lan937x_reg.h | 3 +++ 5 files changed, 41 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index d2ec5acd7b17..ada673b6efc6 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -292,6 +292,7 @@ static const struct ksz_dev_ops lan937x_dev_ops = { .change_mtu = lan937x_change_mtu, .phylink_mac_link_up = ksz9477_phylink_mac_link_up, .config_cpu_port = lan937x_config_cpu_port, + .config_dsa_port = lan937x_config_dsa_port, .tc_cbs_set_cinc = lan937x_tc_cbs_set_cinc, .enable_stp_addr = ksz9477_enable_stp_addr, .reset = lan937x_reset_switch, @@ -2095,6 +2096,9 @@ static int ksz_setup(struct dsa_switch *ds) dev->dev_ops->config_cpu_port(ds); + if (dev->dev_ops->config_dsa_port) + dev->dev_ops->config_dsa_port(ds); + dev->dev_ops->enable_stp_addr(dev); ds->num_tx_queues = dev->info->num_tx_queues; diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index aab60f2587bf..c3c3eee178f4 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -147,6 +147,7 @@ struct ksz_device { u32 chip_id; u8 chip_rev; int cpu_port; /* port connected to CPU */ + int dsa_port; /* Port used as cascaded port */ u32 smi_index; int phy_port_cnt; phy_interface_t compat_interface; @@ -358,6 +359,7 @@ struct ksz_dev_ops { void (*setup_rgmii_delay)(struct ksz_device *dev, int port); int (*tc_cbs_set_cinc)(struct ksz_device *dev, int port, u32 val); void (*config_cpu_port)(struct dsa_switch *ds); + void (*config_dsa_port)(struct dsa_switch *ds); int (*enable_stp_addr)(struct ksz_device *dev); int (*reset)(struct ksz_device *dev); int (*init)(struct ksz_device *dev); diff --git a/drivers/net/dsa/microchip/lan937x.h b/drivers/net/dsa/microchip/lan937x.h index 3388d91dbc44..ef84abc31556 100644 --- a/drivers/net/dsa/microchip/lan937x.h +++ b/drivers/net/dsa/microchip/lan937x.h @@ -11,6 +11,7 @@ int lan937x_setup(struct dsa_switch *ds); void lan937x_teardown(struct dsa_switch *ds); void lan937x_port_setup(struct ksz_device *dev, int port, bool cpu_port); void lan937x_config_cpu_port(struct dsa_switch *ds); +void lan937x_config_dsa_port(struct dsa_switch *ds); int lan937x_switch_init(struct ksz_device *dev); void lan937x_switch_exit(struct ksz_device *dev); int lan937x_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data); diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c index 399a3905e6ca..5108a3f4bf76 100644 --- a/drivers/net/dsa/microchip/lan937x_main.c +++ b/drivers/net/dsa/microchip/lan937x_main.c @@ -205,11 +205,42 @@ void lan937x_port_setup(struct ksz_device *dev, int port, bool cpu_port) dev->dev_ops->cfg_port_member(dev, port, member); } +void lan937x_config_dsa_port(struct dsa_switch *ds) +{ + struct ksz_device *dev = ds->priv; + struct dsa_port *dp; + + dev->dsa_port = 0xFF; + + dsa_switch_for_each_port(dp, ds) { + if (dsa_is_dsa_port(ds, dp->index)) { + ksz_rmw32(dev, REG_SW_CASCADE_MODE_CTL, + CASCADE_PORT_SEL, dp->index); + dev->dsa_port = dp->index; + + /* Tail tag should be enabled for switch 0 + * in cascaded connection. + */ + if (dev->smi_index == 0) { + lan937x_port_cfg(dev, dp->index, REG_PORT_CTRL_0, + PORT_TAIL_TAG_ENABLE, true); + } + + /* Frame check length should be disabled for cascaded ports */ + lan937x_port_cfg(dev, dp->index, REG_PORT_MAC_CTRL_0, + PORT_CHECK_LENGTH, false); + } + } +} + void lan937x_config_cpu_port(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; struct dsa_port *dp; + /* Initializing cpu_port parameter into invalid value */ + dev->cpu_port = 0xFF; + dsa_switch_for_each_cpu_port(dp, ds) { if (dev->info->cpu_ports & (1 << dp->index)) { dev->cpu_port = dp->index; diff --git a/drivers/net/dsa/microchip/lan937x_reg.h b/drivers/net/dsa/microchip/lan937x_reg.h index 45b606b6429f..4f30bc12f7a9 100644 --- a/drivers/net/dsa/microchip/lan937x_reg.h +++ b/drivers/net/dsa/microchip/lan937x_reg.h @@ -32,6 +32,9 @@ #define REG_SW_PORT_INT_STATUS__4 0x0018 #define REG_SW_PORT_INT_MASK__4 0x001C +#define REG_SW_CASCADE_MODE_CTL 0x0030 +#define CASCADE_PORT_SEL 7 + /* 1 - Global */ #define REG_SW_GLOBAL_OUTPUT_CTRL__1 0x0103 #define SW_CLK125_ENB BIT(1)