From patchwork Wed Feb 8 10:32:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 54354 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3377509wrn; Wed, 8 Feb 2023 02:36:25 -0800 (PST) X-Google-Smtp-Source: AK7set8QTNNo62Lhaa2MJYBaVItx0aaYUX1a+DJB2drrRjcB4QRG4tPB7pHRr8S54Fis2V3uPAsP X-Received: by 2002:a05:6a20:7f94:b0:b8:b9e7:6d4 with SMTP id d20-20020a056a207f9400b000b8b9e706d4mr9476974pzj.0.1675852585199; Wed, 08 Feb 2023 02:36:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675852585; cv=none; d=google.com; s=arc-20160816; b=kXhXQ+3rk1y6Doj/PDG8/QmLeZvnOVNj05mU+G1Yd7bhcONWl+SoDNATR67MFomZka 7AmAlo0mSBfUaOB1pqfTzi/LT/qpV4EJnye+NupMqD8RJtfpDZJTifp21e5cAO2ABMPI ZF7mu0ML07Z8OdszsaDm/kn1inBmTTAiSSl7dpQ6FQ4di9+LDto3Sd9c9xDbauh0UX/c 6TST7ftuiDXKQLc03F5YeZ1CGGZHYbnw0EBtCDuf1pQqdgQ+7R4tL0lz6YlHoV5CXsCS crPO3+LKVFIrIT75kR04MjAONHGqbRlePWhW8tZYMy+hGQ4N7jWLsczQHlxCpZ9MRoDA QOoA== 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; bh=+ENpwFhtbepCLr8Wl8nhLK09ZrHsEgR3dSIN6dgucqI=; b=W6g7rv3DiOWOksvLyUQQP3YbJM9oNgI28JCRogmPnp4duBXBT12nslfwcPfOECcCRv PaafH67tjA31Ixv86ww0OPySZMxuF8vDVWTCmJ5/0fKSIQgUMDDUJdrUgut+K3oAS+Cp tDzjZMOcLGMtqLqKagt6cetZZ5/jAGmXLdDrZoQ7RfUWVjI/y4J/QDx57HMr31je7jva H2spjHvZQA6nK+3ECC8ljFz4+905pWC7ddeFrQaNnnWXWEq+v/97oq5TXOsobHTW3O6l LuGk/Cyksk3XwBKrEKOuz8500+RnfjvMxJ3Ged55OJyG6aLghB+U0f+Pk8bCpiOZQbgQ Nnqw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l187-20020a6391c4000000b004fb0b661a4fsi5745750pge.591.2023.02.08.02.36.11; Wed, 08 Feb 2023 02:36:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231367AbjBHKcm (ORCPT + 99 others); Wed, 8 Feb 2023 05:32:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbjBHKc0 (ORCPT ); Wed, 8 Feb 2023 05:32:26 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AC754672E for ; Wed, 8 Feb 2023 02:32:24 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pPhkN-00047W-Cl; Wed, 08 Feb 2023 11:32:15 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pPhkK-003UhY-SL; Wed, 08 Feb 2023 11:32:14 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pPhkK-00Aa3x-Pr; Wed, 08 Feb 2023 11:32:12 +0100 From: Oleksij Rempel To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Wei Fang , Heiner Kallweit Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Arun.Ramadoss@microchip.com Subject: [PATCH net-next v6 1/9] net: dsa: microchip: enable EEE support Date: Wed, 8 Feb 2023 11:32:03 +0100 Message-Id: <20230208103211.2521836-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230208103211.2521836-1-o.rempel@pengutronix.de> References: <20230208103211.2521836-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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?1757258800648046425?= X-GMAIL-MSGID: =?utf-8?q?1757258800648046425?= Some of KSZ9477 family switches provides EEE support. To enable it, we just need to register set_mac_eee/set_mac_eee handlers and validate supported chip version and port. Signed-off-by: Oleksij Rempel Reviewed-by: Andrew Lunn --- drivers/net/dsa/microchip/ksz_common.c | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 46becc0382d6..0a2d78253d17 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -2673,6 +2673,69 @@ static int ksz_max_mtu(struct dsa_switch *ds, int port) return -EOPNOTSUPP; } +static int ksz_validate_eee(struct dsa_switch *ds, int port) +{ + struct ksz_device *dev = ds->priv; + + if (!dev->info->internal_phy[port]) + return -EOPNOTSUPP; + + switch (dev->chip_id) { + case KSZ8563_CHIP_ID: + case KSZ9477_CHIP_ID: + case KSZ9563_CHIP_ID: + case KSZ9567_CHIP_ID: + case KSZ9893_CHIP_ID: + case KSZ9896_CHIP_ID: + case KSZ9897_CHIP_ID: + return 0; + } + + return -EOPNOTSUPP; +} + +static int ksz_get_mac_eee(struct dsa_switch *ds, int port, + struct ethtool_eee *e) +{ + int ret; + + ret = ksz_validate_eee(ds, port); + if (ret) + return ret; + + /* There is no documented control of Tx LPI configuration. */ + e->tx_lpi_enabled = true; + /* There is no documented control of Tx LPI timer. According to tests + * Tx LPI timer seems to be set by default to minimal value. + */ + e->tx_lpi_timer = 0; + + return 0; +} + +static int ksz_set_mac_eee(struct dsa_switch *ds, int port, + struct ethtool_eee *e) +{ + struct ksz_device *dev = ds->priv; + int ret; + + ret = ksz_validate_eee(ds, port); + if (ret) + return ret; + + if (!e->tx_lpi_enabled) { + dev_err(dev->dev, "Disabling EEE Tx LPI is not supported\n"); + return -EINVAL; + } + + if (e->tx_lpi_timer) { + dev_err(dev->dev, "Setting EEE Tx LPI timer is not supported\n"); + return -EINVAL; + } + + return 0; +} + static void ksz_set_xmii(struct ksz_device *dev, int port, phy_interface_t interface) { @@ -3130,6 +3193,8 @@ static const struct dsa_switch_ops ksz_switch_ops = { .port_txtstamp = ksz_port_txtstamp, .port_rxtstamp = ksz_port_rxtstamp, .port_setup_tc = ksz_setup_tc, + .get_mac_eee = ksz_get_mac_eee, + .set_mac_eee = ksz_set_mac_eee, }; struct ksz_device *ksz_switch_alloc(struct device *base, void *priv)