Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7520705rwb; Tue, 6 Dec 2022 06:49:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf5dQp34ChuM69VXqmxebX92Rxp38U75jm7W7Oy1+TVTd9GMEn5UtmCCQp27z2i9fPWDo+c/ X-Received: by 2002:a63:140e:0:b0:477:b461:3a3b with SMTP id u14-20020a63140e000000b00477b4613a3bmr57022980pgl.623.1670338192667; Tue, 06 Dec 2022 06:49:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670338192; cv=none; d=google.com; s=arc-20160816; b=b2rOUGVyg70TxHinVEj4dLZjcfptqWB1beIupyvDH6zbPsurH7lboErCeUZYDvQiCc gCOQt1JOvzMY7FBmy5hCCEeFJZIvwNWrsJ0ML8HZ5CKoyIfuU+0FmBx8gZ/aCXESRMh3 7lFrsyFswCmPH1SYfEIFy55d7nsl65iZi/3jUSgDwNHcWB8ia6wi5E9tV/yUDSN8Fnsu FtH1HfaxjhfDbH+nrHzZ4wuoduSQik80nZc25bjucrbBHW57iTGO+Jp88GsB4ZR7B65w FHsMUK8WvOafTGr0PnABwnWEbvk9VF8kioGziQvGt14k+mcyPlW9TGfWQFOcvUPRZ0a2 Wl1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EzchpwuEta8aWE4H77gSMJ23xGLi6cuMRh/hqr7Hhzg=; b=v6giO2slCdE2MVDTE/ji+dInUnPvZP5chUY/TRl4Li6XMuMB/7wDebjrpfDF26M7C1 TS/KKXw/oBYv+VA9zveDaUhODLAHrfK5qUXjJgrnZDBlwS8QTnv3dbfbQfirv5+cJnFF 6Evl4Uplwe7hsiGFJvFes8rB0fs1509+o9+CXnxmcbq/+GGK3XzY/hDNYDkCmTKbh7X7 ukE2pfKzb5XlEiMwf7wOvVj+m6AyIAUs3eMG0gYgpMnadJF9sQauQP2pT5ArRoaTtiH0 dSy2jKZ9r4JBm6TeAzIiPkjcw/V1rzYa/vkcY5GLjcS2tDrS+PZ8j73qlqgDCduxc2jp kNPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PJlYuQu7; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p3-20020a170902e74300b00186f1c070fesi19789140plf.181.2022.12.06.06.49.41; Tue, 06 Dec 2022 06:49:52 -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=@gmail.com header.s=20210112 header.b=PJlYuQu7; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234632AbiLFOfH (ORCPT + 79 others); Tue, 6 Dec 2022 09:35:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231363AbiLFOfF (ORCPT ); Tue, 6 Dec 2022 09:35:05 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36AD821813; Tue, 6 Dec 2022 06:35:03 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id kw15so3215924ejc.10; Tue, 06 Dec 2022 06:35:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=EzchpwuEta8aWE4H77gSMJ23xGLi6cuMRh/hqr7Hhzg=; b=PJlYuQu7DT20Nqtsx+U+ypBjUKndXcSYcotmtLnM2rbpcnQF3hOCRETPKWv44aDNsO I34EdmBmvfCyNtp8f5Raec1qfcw/80sQWgGiSnDFlpKmkiMtI4IT97vesVZxY0Zl/cp1 JVuL4avU19GpqIVNJcn66YRPI/P4iwiWv33h7JtQNwS1gj0vJFUgOsWeKYk6iAI70bzb +DRU813exk/yoLvqLBd81Z5VGHPIoW7TjnIZFRuEiI6ZwftM/144e7/E4UmfL2qBANHS XqQhJaNkvQK/dLTKfCXuGvLqDhw7mlFYNpMlO3D7VH18KejQA+t+X9HiOFQBRLEPROMs YQKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=EzchpwuEta8aWE4H77gSMJ23xGLi6cuMRh/hqr7Hhzg=; b=nwK64y6wLlpsecLeh6vv7Kkr4Qd9AcENIEFoTF1xJqOhWyMJCZGHji9GPRBg8f5FaT q1ojc5+U6j6wNZPWWQhUit6ppFyWb/xird7mefKQlABaTpoMUhUIXN/sozQOXLYqN7Yv Z1FJw0FwzhO+BnH+/M21TGBC6wPcoz1lV5n4l2PbmbmMTkM9VeKG79NP1aaJZvijAFrx cZG6RHf/+lAsdHSP2U6UWjxenvkUGUxfWinnH+7DWu5HJ3DvDQZTVWj/hz/OJtqCEh01 ejELf56PT0KGnEUq4tN9ltsbPVFvsYtN+DccDQ/EkuqVdPa8dW6bT+GnGx+n7LYIVLI3 6BlA== X-Gm-Message-State: ANoB5pn7OT+duH3eJJr6VwJBSMl4K5T/W1AgmkZl/60AG1UWrwKuBLHc 5p4zk9rssRuyUJVAnxhqTInVioeUtnQN/41Q X-Received: by 2002:a17:906:99d3:b0:78d:c7fd:f755 with SMTP id s19-20020a17090699d300b0078dc7fdf755mr10882905ejn.702.1670337301415; Tue, 06 Dec 2022 06:35:01 -0800 (PST) Received: from gvm01 (net-2-45-26-236.cust.vodafonedsl.it. [2.45.26.236]) by smtp.gmail.com with ESMTPSA id g26-20020a056402181a00b004618a89d273sm1059447edy.36.2022.12.06.06.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 06:34:59 -0800 (PST) Date: Tue, 6 Dec 2022 15:35:10 +0100 From: Piergiorgio Beruto To: Andrew Lunn Cc: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Oleksij Rempel Subject: Re: [PATCH v4 net-next 5/5] drivers/net/phy: add driver for the onsemi NCN26000 10BASE-T1S PHY Message-ID: References: <1816cb14213fc2050b1a7e97a68be7186340d994.1670329232.git.piergiorgio.beruto@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 Hi Andrew, thank you for your review. Please, see my answers below. Thanks, Piergiorgio On Tue, Dec 06, 2022 at 02:47:49PM +0100, Andrew Lunn wrote: > > +// module parameter: if set, the link status is derived from the PLCA status > > +// default: false > > +static bool link_status_plca; > > +module_param(link_status_plca, bool, 0644); > > No module parameters, they are considered a bad user interface. OK, as you see I'm a bit "outdated" :-) What would be the alternative? There is a bunch of vendor-specific PHY features that I would like to expose at some point (e.g. regulation of TX voltage levels). Thanks! > > +static int ncn26000_get_features(struct phy_device *phydev) > > +{ > > + linkmode_zero(phydev->supported); > > + linkmode_set_bit(ETHTOOL_LINK_MODE_MII_BIT, phydev->supported); > > + > > + linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT, > > + phydev->supported); > > + > > + linkmode_copy(phydev->advertising, phydev->supported); > > That should not be needed. > > Also, look at PHY_BASIC_T1_FEATURES, and how it is used in > microchip_t1.c. In principle, I agree. But I have a problem with this specific chip, two actually... 1. The chip does -not- set the MDIO_PMA_EXTABLE while it should. This has been fixed in new versions of the chip, but for now, the bit is 0 so genphy_c45_baset1_able() reports 'false'. 2. This PHY is one of the PHYs that emulates AN (we discussed about this earlier), but it does not actually implement it. Therefore, I thought to just force the capabilities. In the future, I could read the chip ID/version and make a decision based on that (force or use the standard c45 functions). Doe it make sense to you? > > +static int ncn26000_read_status(struct phy_device *phydev) > > +{ > > + // The NCN26000 reports NCN26000_LINK_STATUS_BIT if the link status of > > + // the PHY is up. It further reports the logical AND of the link status > > + // and the PLCA status in the BMSR_LSTATUS bit. Thus, report the link > > + // status by testing the appropriate BMSR bit according to the module's > > + // parameter configuration. > > + const int lstatus_flag = link_status_plca ? > > + BMSR_LSTATUS : NCN26000_BMSR_LINK_STATUS_BIT; > > + > > + int ret; > > + > > + ret = phy_read(phydev, MII_BMSR); > > + if (unlikely(ret < 0)) > > + return ret; > > + > > + // update link status > > + phydev->link = (ret & lstatus_flag) ? 1 : 0; > > What about the latching behaviour of LSTATUS? See further down. > > https://elixir.bootlin.com/linux/latest/source/drivers/net/phy/phy_device.c#L2289 > > > + > > + // handle more IRQs here > > You are not in an IRQ handler... Right, this is just a left-over when I moved the code from the ISR to this functions. Fixed. > You should also be setting speed and duplex. I don't think they are > guaranteed to have any specific value if you don't set them. Ah, I got that before, but I removed it after comment from Russell asking me not to do this. Testing on my HW, this seems to work, although I'm not sure whether this is correct or it is working 'by chance' ? > > + > > + return 0; > > +} > > + > > +static irqreturn_t ncn26000_handle_interrupt(struct phy_device *phydev) > > +{ > > + const struct ncn26000_priv *const priv = phydev->priv; > > + int ret; > > + > > + // clear the latched bits in MII_BMSR > > + phy_read(phydev, MII_BMSR); > > Why? That was my ugly handling of the status double-read... See the pacth below! I copied part of the code you suggested. > > > + > > + // read and aknowledge the IRQ status register > > + ret = phy_read(phydev, NCN26000_REG_IRQ_STATUS); > > + > > + if (unlikely(ret < 0) || (ret & priv->enabled_irqs) == 0) > > How does NCN26000_REG_IRQ_STATUS work? Can it have bits set which are > not in NCN26000_REG_IRQ_CTL ? That does happen sometimes, but is > pretty unusual. If not, you don't need to track priv->enabled_irqs, > just ensure ret is not 0. It has a single bit that is not maskable. That would be the reset event bit, which is triggered if the chip goes through a spurious reset. Since I did not want to handle this in this first version of the driver, I just masked it this way. Thoughts? diff --git a/drivers/net/phy/ncn26000.c b/drivers/net/phy/ncn26000.c index 9e02c5c55244..198539b7ee66 100644 --- a/drivers/net/phy/ncn26000.c +++ b/drivers/net/phy/ncn26000.c @@ -92,15 +92,27 @@ static int ncn26000_read_status(struct phy_device *phydev) int ret; + /* The link state is latched low so that momentary link + * drops can be detected. Do not double-read the status + * in polling mode to detect such short link drops except + * the link was already down. + */ + if (!phy_polling_mode(phydev) || !phydev->link) { + ret = phy_read(phydev, MII_BMSR); + if (ret < 0) + return ret; + else if (ret & lstatus_flag) + goto upd_link; + } + ret = phy_read(phydev, MII_BMSR); if (unlikely(ret < 0)) return ret; +upd_link: // update link status phydev->link = (ret & lstatus_flag) ? 1 : 0; - // handle more IRQs here - return 0; } @@ -109,9 +121,6 @@ static irqreturn_t ncn26000_handle_interrupt(struct phy_device *phydev) const struct ncn26000_priv *const priv = phydev->priv; int ret; - // clear the latched bits in MII_BMSR - phy_read(phydev, MII_BMSR); - // read and aknowledge the IRQ status register ret = phy_read(phydev, NCN26000_REG_IRQ_STATUS);