Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2673231rdb; Wed, 15 Nov 2023 07:31:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgP1REqsnWo7QYURLO/0uqhldGRUSEaBHN0YkeVHjjE593J6WCzUanCHwHE0NPLDoN21lB X-Received: by 2002:a05:6a00:c8d:b0:6c6:1f0a:89c6 with SMTP id a13-20020a056a000c8d00b006c61f0a89c6mr16361128pfv.34.1700062282573; Wed, 15 Nov 2023 07:31:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700062282; cv=none; d=google.com; s=arc-20160816; b=e3un5h5ay/tcJntPNLLwp88Wfmk3pBLTNMBCkCsmlBVQR9rghtPhUAfdqm9xPDH0Mn EzJhg327IeOUdIWvN7niZdxwTxuqgoolAJdyo4xiOGXuPCfA4joybv6UO0c8cXsHf5q1 VZYtB7+MEEtP3H3aCa+BXqHoGcc4DEQ/mf7Sa0dX6n/w2CR9CyBd2feBH7hdyBwOwU3K cSfMnTfxWcfPX2aiYM2OG5BRKa1hFiBQOpeGadPkDL6vKno4LnYpisV+B2r1ygAoIK3H 1h+s+kE4TFUuy4EGAD/lLc/qpc/ExO99WN/ndJqSuH4ZSO6WIFBg8tY5K6pCURBiut/F hXmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=yGGXh/tPnXL+P4n+7AuLV8zTk3Fq7KZAHBE5VIThsu4=; fh=OydBOjRH2VSVVSqnJy989a6Z8by/BoOGpLedHOC+Ecw=; b=W8g2u27DWaiy5ZDgUkgpCJtesVp3O+sA/NU8aYPVyBFQHhDNfJb9S3hQosnuJJOHJT yDjYVDjNYH1OqJ/Y3LYcvky9BsmRY1I3iPEe80WbTDXnB/fYgPrAEE222RLtaE9ZL8Qv 44+eF+j/HsDZc7cOZFn8K1TX+5PLSswMBc3t3FzUSqnkz8ExE8kRDd2bL8lcxcQjfnzP SfJ5a6frD47iY6TZenBkhCcjbIiU5r3wpfe89I4mV8Ln2NERQnAUGmybgJNjIpclEWyF 5GLslOQaQ5mY7sHj0q5kZ5hVUKKg/9P/8zQcbvqGBn24QdrSEWvFcs/XKb1dJFpY93o5 DLjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="iPaW/d66"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id k189-20020a633dc6000000b005be3c09abe7si10475021pga.262.2023.11.15.07.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 07:31:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="iPaW/d66"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id CD2538142D80; Wed, 15 Nov 2023 07:31:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229630AbjKOPa7 (ORCPT + 99 others); Wed, 15 Nov 2023 10:30:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229511AbjKOPa6 (ORCPT ); Wed, 15 Nov 2023 10:30:58 -0500 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E65A1A1; Wed, 15 Nov 2023 07:30:54 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id BF8501BF20A; Wed, 15 Nov 2023 15:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1700062253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yGGXh/tPnXL+P4n+7AuLV8zTk3Fq7KZAHBE5VIThsu4=; b=iPaW/d66IhN5NdRncx4yPDUzHnm6FBhB21+9vMHQSjywf2E1BZPiadZ6h+3dmxYLEhEdrQ lNQSFomaZnyg5YQfiRSskdqpQfsDzBjI0G1e23n26s0rANrPDWKF/b0yLRo7psbtaiXb8a 5rQmpiR6bMKlmnr0oAI4n11sI9ApabAVJjh9lqRE7b8Gh0NEFAPt4Tx3ofMPwJN33rsbYm bEoJ6LHX3WNotP0dpOGQHqgCez8ZAsYllAIjSveVRY1e2yhjWjqHV9ujHVp/YcLJYyH7QN ANSZnl6zlT7adNC2QhVry7sHf42+Jk4H//CV8pFhFYORkJcZhMgjgMWdQ6mCRg== Date: Wed, 15 Nov 2023 16:31:07 +0100 (CET) From: Romain Gantois To: Andrew Lunn cc: Romain Gantois , 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 In-Reply-To: Message-ID: <2d4c7054-1aa8-1531-ffa3-7be342ed9a07@bootlin.com> References: <20231114105600.1012056-1-romain.gantois@bootlin.com> <20231114105600.1012056-7-romain.gantois@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-GND-Sasl: romain.gantois@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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 07:31:08 -0800 (PST) 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. Best, -- Romain Gantois, Bootlin Embedded Linux and Kernel engineering https://bootlin.com