Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2464173rdb; Fri, 8 Dec 2023 08:51:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFasY8Z873BjqE+H7wvEszZSmgcFoOyigaFwPwtFDa3Hp10wRDXEUjRGpElqp07EX/6zzB8 X-Received: by 2002:a17:90a:5986:b0:286:adca:497a with SMTP id l6-20020a17090a598600b00286adca497amr372138pji.2.1702054282523; Fri, 08 Dec 2023 08:51:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702054282; cv=none; d=google.com; s=arc-20160816; b=ky5wBZ1/HMeopQ6QrA4pK3dm/CsftvqMoTbT9OAOIzSZACvZEOg73HjK8unu9bgAtt EdXMvfqjdBuuGZHonnOLnhT0oYe8nFOEL0DEa4Oxit1pbDLZIsxzWxg0p1B0/IU3Q8jZ z84YhlVsjXxQVsIhtEqIy/ArwjSo3k/xjiHqqVJ7zhAC2ptqTr5D7J2HrVY9JIIwTExT V/+qv+xcHmnSm1cjEK0vXJVmvUm0CcbJE22g8cjODCxQ8jy0KJnv2nKGlSRU6PK45HPX WVXLns7/OdpbpZmXctLxnjoBAU4nSRhRQlMBhxdXib+K4uMnwZ+RmWGA4tf1aEYVzsYL /exA== 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=b9G4gtAHl2jdBgyqLp8sobufNphdW1bLmTw+/OLi/vA=; fh=s9xxWyJgYnGtTDImjKNbcvkIu/702tunpmaRHpiIVaE=; b=nkXYbUdGN0GN8QN7zQBPYAOXn0qQN4dfZDUHtmHV31ttxB9QhbOKF6OJUF3KuPLrEF HJw0FtFQJx+A6df3Rih9cn4uLvuZnLNglUX1KCeNloFuc6jObyR9daH3P1NfsnSagIZV n/hihi6shNUuTO0w6C5gi1iSr4r/X6TqHF+s7GTVdPobpasTQ9W+PMNZsg6Ob3O6aSO/ wW2E6ngQFEdqd3RV+ubzIxBYSY44uxnTIuPL30V3Sj/WiJ4ZXzcbuzxZl1QEBHpOaKoK WKdUwpQmIrnVkxk0CcEO0ujJiwqu5gnjum2EBwvuA6GYGJfHR06b1Cikm9+3U/EH8Z88 aO9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=daMT4hAT; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id b8-20020a170903228800b001d09c539cd5si1946811plh.133.2023.12.08.08.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 08:51: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=@redhat.com header.s=mimecast20190719 header.b=daMT4hAT; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 10C94817C3C2; Fri, 8 Dec 2023 08:51:19 -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 S235950AbjLHQuk (ORCPT + 99 others); Fri, 8 Dec 2023 11:50:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233657AbjLHQue (ORCPT ); Fri, 8 Dec 2023 11:50:34 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5BD01987 for ; Fri, 8 Dec 2023 08:50:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702054234; 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=b9G4gtAHl2jdBgyqLp8sobufNphdW1bLmTw+/OLi/vA=; b=daMT4hATPXYhk4artMrKm8Ufy6xW/Xwuf7KVsuk9kpTTrxz+jEgPb1/LB9XIwfex1/C35A Oy7raYIIamfSo1uCXIswLFCMFUETOBJl3No0JMeeP98mfIDeLsaLlLzd5eRVfO/aCm4hiW rpxvQ1A/U42ezUE98L3+B+fuTqCXF88= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-d_IIGuYMNA29YojQjXG8mg-1; Fri, 08 Dec 2023 11:50:33 -0500 X-MC-Unique: d_IIGuYMNA29YojQjXG8mg-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-423f436ed56so27633831cf.1 for ; Fri, 08 Dec 2023 08:50:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702054233; x=1702659033; 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=b9G4gtAHl2jdBgyqLp8sobufNphdW1bLmTw+/OLi/vA=; b=UsHQvcKm/uzmVSnfd+VZACz1qLAqdrpGnjqfifi25dAMOs9r2I6wKdze/lTNcS1RhV zjND4vLdU/tmKAGMvdZjSG0aoyoSf4G2D6df3yVBBaki3Nbi/OYrWyBxQpViUmumFpmh VrdIykFnbA3rZhNGzTstJTqWTxBTGhL6TOIIpcVii3uWNxuhnQSNAxR+DLrn05mNy/G0 ghbYEYC9Wjy4vjGAn5pLHYhvE2utV2MSt02OdvaATq3yq7RbLz0DVy8FOEEJ3s6MeaZx syvsyuKcLzLYNj4oOp57VBIpAZf60Vb7vWzjQs4v6R6gx5YJnwirb21RqJSnZ2e/E/sC UAyA== X-Gm-Message-State: AOJu0Yx3AI7uTkoviCT+vA9GPkShJ5mwz0U8J9LJUbgVTsQKSs5Dm2Ai SEgujKaRr5eDuBQP0JijCNXbq/RXiZeBQCbQXfmmRJoBEbiV1fidr4m0F5W332imJus0HtjNQeG mJMtFBTQdkhFmRj6eIY/qC47B X-Received: by 2002:a05:622a:1309:b0:425:9426:91aa with SMTP id v9-20020a05622a130900b00425942691aamr454866qtk.34.1702054232704; Fri, 08 Dec 2023 08:50:32 -0800 (PST) X-Received: by 2002:a05:622a:1309:b0:425:9426:91aa with SMTP id v9-20020a05622a130900b00425942691aamr454855qtk.34.1702054232378; Fri, 08 Dec 2023 08:50:32 -0800 (PST) Received: from fedora ([2600:1700:1ff0:d0e0::47]) by smtp.gmail.com with ESMTPSA id g23-20020ac842d7000000b00410a9dd3d88sm923673qtm.68.2023.12.08.08.50.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 08:50:31 -0800 (PST) Date: Fri, 8 Dec 2023 10:50:29 -0600 From: Andrew Halaney To: Serge Semin Cc: Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH net-next v3] net: stmmac: don't create a MDIO bus if unnecessary Message-ID: References: <20231207-stmmac-no-mdio-node-v3-1-34b870f2bafb@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,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]); Fri, 08 Dec 2023 08:51:19 -0800 (PST) On Fri, Dec 08, 2023 at 06:07:06PM +0300, Serge Semin wrote: > On Thu, Dec 07, 2023 at 05:07:24PM -0600, Andrew Halaney wrote: > > On Fri, Dec 08, 2023 at 01:16:12AM +0300, Serge Semin wrote: > > > On Thu, Dec 07, 2023 at 03:12:40PM -0600, Andrew Halaney wrote: > > > > The stmmac_dt_phy() function, which parses the devicetree node of the > > > > MAC and ultimately causes MDIO bus allocation, misinterprets what > > > > fixed-link means in relation to the MAC's MDIO bus. This results in > > > > a MDIO bus being created in situations it need not be. > > > > > > > > Currently a MDIO bus is created if the description is either: > > > > > > > > 1. Not fixed-link > > > > 2. fixed-link but contains a MDIO bus as well > > > > > > > > The "1" case above isn't always accurate. If there's a phy-handle, > > > > it could be referencing a phy on another MDIO controller's bus[1]. In > > > > this case currently the MAC will make a MDIO bus and scan it all > > > > anyways unnecessarily. > > > > > > > > There's also a lot of upstream devicetrees[2] that expect a MDIO bus to > > > > be created and scanned for a phy. This case can also be inferred from > > > > the platform description by not having a phy-handle && not being > > > > fixed-link. This hits case "1" in the current driver's logic. > > > > > > > > Let's improve the logic to create a MDIO bus if either: > > > > > > > > > > > - Devicetree contains a MDIO bus > > > > - !fixed-link && !phy-handle (legacy handling) > > > > > > If what you suggest here is a free from regressions semantics change > > > (really hope it is) I will be with both my hands for it. This will > > > solve the problem we have with one of our device which doesn't have > > > SMA interface (hardware designers decided to save ~4K gates of the > > > chip area) but has a PHY externally attached to the DW XGMAC<->XPCS > > > interface. PHY is accessible via a GPIO-based MDIO bus. BTW having no > > > SMA interface available on a DW *MAC device but creating the MDIO-bus > > > on top of the non-existent SMA CSRs anyway causes having _32_ dummy > > > PHYs created with zero IDs. > > > > > I hope it is regression free! I have tested both the [1] and [2] cases > > (I hacked up the devicetree for [1] to make it look like [2]) without > > any issue. > > > > I doubt you could have tested it on all the possible hardware the > STMMAC driver supports. The problem is that the DT-bindings thing is a > kind of contract which can't be changed that easily. It's like ABI but > for the hardware description so the kernel would bootup correctly on > the platforms with the old DT blobs. But if the change isn't that > critical, if the device-tree sources in the kernel fit to the updated > semantics, if the networking subsystem maintainers aren't against it > and I guess with the Rob, Krzysztof or Conor blessing (at least it > won't hurt to add them to the Cc-list together with the devicetree > mailing-list), then it will likely be accepted. To be clear, I don't think we're violating the dt-binding ABI contract here. My intention is that all the existing use cases continue to work, and this just improves one use case. I did a write up over on v2 about the use cases I see and the current logic vs what changes with this patch series: https://lore.kernel.org/netdev/plvbqgi2bwlv5quvpiwplq7cxx6m5rl3ghnfhuxfx4bpuhyihl@zmydwrtwdeg6/ Please comment if you think I have broken some backwards compatibility. If I _could_ break compatibility, I'd make everyone describe their busses entirely... but as you said that's against the spirit of dt-bindings and would upset a lot of people. That's why I've left the "!fixed-link && !phy-handle (legacy handling) logic :) > > > Sorry, I don't have any docs for stmmac hardware so this might be > > answered in there (or just common net knowledge that I can't find > > online)... what's SMA stand for? I assume it's the MDIO interface. > > Right. Synopsys names the MDIO-bus interface as Station Management > Agent MDIO module. > > > > > I agree though, if you have a phy-handle and no mdio node in your > > devicetree this patch series should bail out without registering a bus > > in stmmac_mdio_register(). > > On the other hand why would the MDIO-bus needed in such case? If the > phy-handle property is specified with no MDIO-bus DT-subnode, then it > will point out to a PHY residing an external bus. The only case I can > imagine though is that the DW XPCS device could be still auto-detected > on the internal SMA-MDIO-bus. But the only driver which currently has > XPCS auto-detection activated is the Intel glue layer (see > dwmac-intel.c and has_xpcs flag), but it doesn't use DT interface > since it handles a PCIe-based device. So this case is out of > brackets. Agreed, I think making the bus is not needed in the driver as is in that case. I'd like to think (but am not sure) that when a devicetree based DW XPCS description comes around it will allow you to describe it exactly instead of doing auto-detection (i.e. something like phy-handle), but I am not very familiar with PCS and friends in the stack so that may be a crude extension from my knowledge of MDIO. Thanks, Andrew > > > > > > > > > > > > > > Below upstream devicetree snippets can be found that explain some of > > > > the cases above more concretely. > > > > > > > > > > - if (mdio) { > > > > - plat->mdio_bus_data = > > > > - devm_kzalloc(dev, sizeof(struct stmmac_mdio_bus_data), > > > > - GFP_KERNEL); > > > > > > > + /* Legacy devicetrees allowed for no MDIO bus description and expect > > > > + * the bus to be scanned for devices. If there's no phy or fixed-link > > > > + * described assume this is the case since there must be something > > > > + * connected to the MAC. > > > > + */ > > > > + legacy_mdio = !of_phy_is_fixed_link(np) && !plat->phy_node; > > > > + if (legacy_mdio) > > > > + dev_info(dev, "Deprecated MDIO bus assumption used\n"); > > > > + > > > > + if (plat->mdio_node || legacy_mdio) { > > > > + plat->mdio_bus_data = devm_kzalloc(dev, > > > > > > Special thanks for adding the comment above this code. It will really > > > save time of figuring out why MDIO-bus needs to be created anyway. > > > > > > > + sizeof(struct stmmac_mdio_bus_data), > > > > > > Should v4 is required I would suggest to change this to > > > sizeof(*plat->mdio_bus_data). > > > > > > Anyway feel free to add: > > > Reviewed-by: Serge Semin > > > > > > -Serge(y) > > > > > Sure I will spin v4 to pick that up, thanks for catching it. I'll also > > improve the motivation in the commit message a hair more per Andrew > > Lunn's request over here on v2 (and will hold off a little bit just to > > make sure reviews come in before a respin): > > > > https://lore.kernel.org/netdev/e64b14c3-4b80-4120-8cc4-9baa40cdcb75@lunn.ch/ > > Ok. Thanks. > > -Serge(y) > > > > > Thanks, > > Andrew > > >