Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2701327rdb; Wed, 15 Nov 2023 08:12:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXks/tB+XpV7vbiNrUPhyE5NiLisNacyOWRMU84MvrtcyHc5+xFtD40TG0DagpwG46e+fQ X-Received: by 2002:a17:90b:1e47:b0:280:65ed:df9 with SMTP id pi7-20020a17090b1e4700b0028065ed0df9mr14856523pjb.31.1700064749145; Wed, 15 Nov 2023 08:12:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700064749; cv=none; d=google.com; s=arc-20160816; b=GQ4mmrEghlhND6l+fiFOOY3vZ43RwcmGT5R2TWRJrlt9bRdrGuecdNA+qKVKuIbRqt oEXBZldpfIrgrWizzF6Q+hoPRHjfocMFdd8j6k/iekmpCwSu9SLSK+AGJNeKxwCvYhfG HM8jefkJr2+RvtIrlL8VyJ+stJLkNCqLJzLPQOx9Q8EjnvFXYCIwEmIjKKKcr/pCVFTL lHvG2iubK329CLFFsJIiJq1eFnUIdNqJYdKUZSX0+5qMObiBHXQ17k0dIDf1qXg/dLV1 ahQwhFm8myFwPoXBhS0IVEaCYSHHIpq8/mtgjtxxvaQpymRpEBDfX7/G1egD28UzHvhg 5Qmg== 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=3agsLpsSM2d58FHz7b5hDOIxhzFLmj2e63YxikopHhQ=; fh=ymRJBdjdKbXzsq6fafuM/dylsNQRQxKXrcXSK7z1BT0=; b=A3Qz/fJfxU1i95TaQp7jbn921jzOIOZRvjw6lVsTNNtnbfYYQhkSwdrKmc7yGy0Og6 xpAZh9ik9gBD+auahnzxedxfx+r9f84DCzOusr8AU+ailuW4Ijqj9KsfvnpcmUw9wmtX PwGHd9QO2gWRU9xxwR46UJGrewOQJuneh8N/uN8iKC2aSgCAJbADs2uSK9TQw0fe9ts8 Vaxmxe8U6Tpmvorudsm2TPqJBeNmvvX7G1mrW4IwyW2h7GBWRWbozgWiH4xq0XMQxi+d 4w+T0KBH1LREQMA0Vyg0P+aCKxyaqMbYtRKxDtbNee2ArTdSy2JOdVLFe5CxVeAupH/E duKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b="zH/neAjb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id nl6-20020a17090b384600b002774985e8b7si58641pjb.168.2023.11.15.08.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 08:12:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b="zH/neAjb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 192FA810679A; Wed, 15 Nov 2023 08:12:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231904AbjKOQMQ (ORCPT + 99 others); Wed, 15 Nov 2023 11:12:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230402AbjKOQMO (ORCPT ); Wed, 15 Nov 2023 11:12:14 -0500 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26347AD; Wed, 15 Nov 2023 08:12:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=3agsLpsSM2d58FHz7b5hDOIxhzFLmj2e63YxikopHhQ=; b=zH/neAjbIjs/dCVDLjp/tyn0Hm D46MRYuvFBN3YS+CfmEu+uK3mDflXyPxOyXoNQW3mjIacteJRwkCOCyLYic8chi3Qi9GLwmvjJiyi PsgLEgOeTJuTy17cCqCzDgZ77KbhmsCTO7yA3RbjXrN9HwBLTNcQIRNFDBpJSgceQu4U=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1r3IUl-000GHP-EA; Wed, 15 Nov 2023 17:12:03 +0100 Date: Wed, 15 Nov 2023 17:12:03 +0100 From: Andrew Lunn To: Romain Gantois Cc: davem@davemloft.net, Rob Herring , Krzysztof Kozlowski , Jakub Kicinski , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, thomas.petazzoni@bootlin.com, Florian Fainelli , Heiner Kallweit , Russell King , linux-arm-kernel@lists.infradead.org, Vladimir Oltean , Luka Perkov , Robert Marko , Andy Gross , Bjorn Andersson , Konrad Dybcio Subject: Re: [PATCH net-next v3 6/8] net: phy: add calibration callbacks to phy_driver Message-ID: <8bd7abff-9b6d-42ac-b98f-fbfe5f0d7c00@lunn.ch> References: <20231114105600.1012056-1-romain.gantois@bootlin.com> <20231114105600.1012056-7-romain.gantois@bootlin.com> <2d4c7054-1aa8-1531-ffa3-7be342ed9a07@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2d4c7054-1aa8-1531-ffa3-7be342ed9a07@bootlin.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 15 Nov 2023 08:12:24 -0800 (PST) On Wed, Nov 15, 2023 at 04:31:07PM +0100, Romain Gantois wrote: > On Tue, 14 Nov 2023, Andrew Lunn wrote: > > > > +static inline > > > +int phy_start_calibration(struct phy_device *phydev) > > > +{ > > > + if (!(phydev->drv && > > > + phydev->drv->calibration_start && > > > + phydev->drv->calibration_stop)) > > > + return -EOPNOTSUPP; > > > + > > > + return phydev->drv->calibration_start(phydev); > > > +} > > > + > > > +static inline > > > +int phy_stop_calibration(struct phy_device *phydev) > > > +{ > > > + if (!(phydev->drv && > > > + phydev->drv->calibration_stop)) > > > + return -EOPNOTSUPP; > > > + > > > + return phydev->drv->calibration_stop(phydev); > > > +} > > > + > > > > What is the locking model? > > > > Andrew > > > This driver currently uses an atomic flag to make sure that the calibration > doesn't run twice. It doesn't acquire any locks before calling > phy_start_calibration(), which is a mistake. > > I think a good locking model for this would be similar to the one used for > phy_cable_test. The phy_start_calibration() and phy_stop_calibration() wrappers > would acquire a lock on the PHY device and then test phydev->state, to check for > an ongoing calibration. A new enum member such as PHY_CALIB could be defined for > this purpose. The lock would be released by the phylib wrapper once the > phy_driver callback returns. > > The problem with this is that one calibration run can access multiple > phy_device instances at the same time, e.g. if a switch is linked to a multiport > PHY via a PSGMII link. > > So acquiring a lock on a single phy device isn't enough. Ideally, these > calls could somehow acquire one lock on all the hardware resources of a > multiport PHY simultaneously. From what I've seen, there is no standard kernel > interface that allows MAC drivers to know about link-sharing between phy > devices. I'll have to do more research on this but if you know of an existing > interface that I can use for this, please tell me. Lets get the switch parts merged first, then we can think about this calibration problem. I need a better understanding of the requirements before i can suggest something. Andrew