Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2720420pxb; Mon, 25 Apr 2022 00:26:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSV2U+bJIlQP7BNZFfGYyjiPsaFI3u8L+as+Nei2KFKgwonnYkLmCC9VBAxnYPjc5jQfZa X-Received: by 2002:a17:906:a219:b0:6e4:86a3:44ea with SMTP id r25-20020a170906a21900b006e486a344eamr15560627ejy.385.1650871569655; Mon, 25 Apr 2022 00:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650871569; cv=none; d=google.com; s=arc-20160816; b=CSHAeZK8cWuY5NwCbe68OHccYfBqLgyN8vmpmeC9rZfLlADhR0he9HVgPIe2SLWPqr nLmNUHrtABoSB13gqKMLB/egDp4PxpQqd4aS0EZXTvX/v9CEm5ebbW0l8NNwdQx2f/Az IUBNCzU7on9qCCOvx4hdUSk6mJUgAMTzzPiB67OWdAMri2q6b5BWmkknyRJqU2Llg6wU ynXP3nsEyB4SEKGSiqoPEta/TcR3p80WUsDgRq7BNBmYKIqoOfoTPPfD3bUNDBOfCUX4 YSRt0TNNpm0+GlG9RSzsCO4bA2MG7nZMVWEjLEgW94MznhtLvkxoLwmaISiKCqsgqF6p +dSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qmtIFptWMRA8qS+AOTNBa5g5ggHQNo6aqpELlxy2Zrk=; b=GU7tvM2xsMvIkyierZsWWuiSt2flfv280AvJ49u/zzWW6Az0ZaQZCNQpVNV3DP78yU +sA1hLn5Z1Pc+Bk4ns6Tk8JYt0TnWaeV2h1SDO5H+OoM92UwUJ+htwNzHu5cPgLxCfW/ rrR/5HtUrPNufagTDyEL9a+9Ky8QH38M2pZ8Z7gRJp2qZD2rw5dUSjVOKHOkXzA1tsZZ imjv1l0qiR51fQkYnh+m6KDG+q8RHrZta/uQ+zrWhM48FZfg8lvGcbyZp2pJiEHocpOX 7soGnh+dwYg6um7n7hqBQNJc1wB1YL31YRM29fRPTICCXTcuw2U8BtInsNETf0VtLYsA fNDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nathanrossi.com header.s=google header.b=ggVWQHuU; 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=NONE dis=NONE) header.from=nathanrossi.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a05640205cd00b00421aa8b312csi14486948edx.217.2022.04.25.00.25.45; Mon, 25 Apr 2022 00:26:09 -0700 (PDT) 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=@nathanrossi.com header.s=google header.b=ggVWQHuU; 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=NONE dis=NONE) header.from=nathanrossi.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230111AbiDXNAa (ORCPT + 99 others); Sun, 24 Apr 2022 09:00:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231205AbiDXNA2 (ORCPT ); Sun, 24 Apr 2022 09:00:28 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6160212A9DA for ; Sun, 24 Apr 2022 05:57:28 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id r189so22586408ybr.6 for ; Sun, 24 Apr 2022 05:57:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nathanrossi.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qmtIFptWMRA8qS+AOTNBa5g5ggHQNo6aqpELlxy2Zrk=; b=ggVWQHuUWBjHGTIKOf05ByEQgMsv7iDyLiC8l6mQJyn43YlKC94o/DF3w28TBzQIgt A284htmVI1eZbBAgXnwmPIK4TUqgYe1WG+zlOtg1BjXkEcXrxmYs31rIpbIq47Z3Scbo INa3EbTidTGr4aH4Q0k+Ch3/5W/VCIUHix3wNmp+uBSy3UjHPHJoTyJ+O7KYnLR0rumy j4fXiB0P1TtO2V2opE6Pd+pkO944HncEqegzrlBkS8ji46IhW2BaEFK4X/759vYB5EOd T7/axqTuFRULG1X7h5cKAPuJFGk1LGxwSozTmcsNmYEJ9UgEZ9cO4OOyoJWTFVfii4bN ra0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qmtIFptWMRA8qS+AOTNBa5g5ggHQNo6aqpELlxy2Zrk=; b=KY424rg/5HC8UkeSJiZvbn4tTc4H8Hy7QP4tTAaE8QeYqjHIeFN+YM2BJiEBshMzVA TLwl6V1wkJxLP/Bb6a6I+eW2AcgKufVLHqr3gEdWj6it0J88EJbD8Q1HpsNWEAgMcpfe iWCpPpOBRJoBrSIpZn5U9Bf/QvMgWiSs5OAdrNo8HDXw7XZUFS1/Ic43DSfZQmzgTT/5 S/m5eBfhvwCFfRkjmF/BSmFw8uDqDtMMvWJ3rT+jLEWyGCQlueAoe8poBjlnfiV/JrK0 PMHiMo+/jrZgrllWgGAQc/C8T+4iNfl1vVZMjAWfz4GFkK0UPHrYhTi4UHx8javARhHE Md8g== X-Gm-Message-State: AOAM533Sg2S8w04fwxNl6ffkcFQ8+sbgjVBP94QscoLAGZiNgiMV5U1y bMLw2uU/7vlFcFzfUeT5JkyAkwtlmodyDDGvxaSeTQ== X-Received: by 2002:a25:e056:0:b0:645:d68d:8474 with SMTP id x83-20020a25e056000000b00645d68d8474mr9396114ybg.294.1650805047571; Sun, 24 Apr 2022 05:57:27 -0700 (PDT) MIME-Version: 1.0 References: <20220423131427.237160-1-nathan@nathanrossi.com> <20220423131427.237160-2-nathan@nathanrossi.com> In-Reply-To: From: Nathan Rossi Date: Sun, 24 Apr 2022 22:57:16 +1000 Message-ID: Subject: Re: [PATCH 2/2] net: dsa: mv88e6xxx: Handle single-chip-address OF property To: Andrew Lunn Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Paolo Abeni Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 On Sun, 24 Apr 2022 at 01:41, Andrew Lunn wrote: > > On Sun, Apr 24, 2022 at 12:41:22AM +1000, Nathan Rossi wrote: > > On Sun, 24 Apr 2022 at 00:07, Andrew Lunn wrote: > > > > > > On Sat, Apr 23, 2022 at 01:14:27PM +0000, Nathan Rossi wrote: > > > > Handle the parsing and use of single chip addressing when the switch has > > > > the single-chip-address property defined. This allows for specifying the > > > > switch as using single chip addressing even when mdio address 0 is used > > > > by another device on the bus. This is a feature of some switches (e.g. > > > > the MV88E6341/MV88E6141) where the switch shares the bus only responding > > > > to the higher 16 addresses. > > > > > > Hi Nathan > > > > > > I think i'm missing something in this explanation: > > > > > > smi.c says: > > > > > > /* The switch ADDR[4:1] configuration pins define the chip SMI device address > > > * (ADDR[0] is always zero, thus only even SMI addresses can be strapped). > > > * > > > * When ADDR is all zero, the chip uses Single-chip Addressing Mode, assuming it > > > * is the only device connected to the SMI master. In this mode it responds to > > > * all 32 possible SMI addresses, and thus maps directly the internal devices. > > > * > > > * When ADDR is non-zero, the chip uses Multi-chip Addressing Mode, allowing > > > * multiple devices to share the SMI interface. In this mode it responds to only > > > * 2 registers, used to indirectly access the internal SMI devices. > > > * > > > * Some chips use a different scheme: Only the ADDR4 pin is used for > > > * configuration, and the device responds to 16 of the 32 SMI > > > * addresses, allowing two to coexist on the same SMI interface. > > > */ > > > > > > So if ADDR = 0, it takes up the whole bus. And in this case reg = 0. > > > If ADDR != 0, it is in multi chip mode, and DT reg = ADDR. > > > > > > int mv88e6xxx_smi_init(struct mv88e6xxx_chip *chip, > > > struct mii_bus *bus, int sw_addr) > > > { > > > if (chip->info->dual_chip) > > > chip->smi_ops = &mv88e6xxx_smi_dual_direct_ops; > > > else if (sw_addr == 0) > > > chip->smi_ops = &mv88e6xxx_smi_direct_ops; > > > else if (chip->info->multi_chip) > > > chip->smi_ops = &mv88e6xxx_smi_indirect_ops; > > > else > > > return -EINVAL; > > > > > > This seems to implement what is above. smi_direct_ops == whole bus, > > > smi_indirect_ops == multi-chip mode. > > > > > > In what situation do you see this not working? What device are you > > > using, what does you DT look like, and what at the ADDR value? > > > > The device I am using is the MV88E6141, it follows the second scheme > > such that it only responds to the upper 16 of the 32 SMI addresses in > > single chip addressing mode. I am able to define the switch at address > > 0, and everything works. However in the device I am using (Netgate > > SG-3100) the ethernet phys for the non switch ethernet interfaces are > > also on the same mdio bus as the switch. One of those phys is > > configured with address 0. Defining both the ethernet-phy and switch > > as address 0 does not work. > > > > The device tree I have looks like: > > > > &mdio { > > status = "okay"; > > pinctrl-0 = <&mdio_pins>; > > pinctrl-names = "default"; > > > > phy0: ethernet-phy@0 { > > status = "okay"; > > reg = <0>; > > }; > > > > phy1: ethernet-phy@1 { > > status = "okay"; > > reg = <1>; > > }; > > So normally, we would have > > > switch0: switch0@16 { > compatible = "marvell,mv88e6141", "marvell,mv88e6085"; > single-chip-address; > reg = <0>; > dsa,member = <0 0>; > status = "okay"; > > and then i guess you are seeing mdiobus_register_device() returning > -EBUSY because the PHY is also at address 0? Correct, that is the issue I am trying to solve here. > > This is what is missing from your explanation. It is always better to > have more than less in the commit message. > > So the chip is using addresses 0x10-0x1f, but in order to probe, you > need to put reg = 0, taking up slot 0, clashing with the PHY. Ideally > we want to take up one of the slots in the range 0x10-0x1f. reg=16 on > its own indicates multi-chip mode and the device is using address 16. > > O.K, a bit more digging into the datasheet: > > For multi-chip mode, for the 6341 family, > > The SMI address that is used is determined by the ADDR[3:0] > configuration pins. ADDR[4] must be zero to select the device. > > So it can only take the address range 0-f, since ADDR[4] == 0. So 16 > is not even a valid multi-chip address. But it is valid for some other > chips. > > So your DT property is says, ignore reg, i really am in single chip > mode. > > This appears to be a general problem for any device with > .port_base_addr = 0x10. I had initially thought of using the port_base_addr along with setting up an of_match for the 6141 to provide compat_info which smi init could use. > > I'm wondering if a better solution to this is special case > reg=16. First try mv88e6xxx_detect() in single chip mode. That will > read register 3. A read should be safe. If we get back a valid ID for > a switch, keep with single chip mode. Otherwise swap to multi-chip > mode. A multi-chip mv88e6xxx_detect() is more dangerous, because that > involves writes. I tested this idea and have sent out a patch for it (https://lore.kernel.org/netdev/20220424125451.295435-1-nathan@nathanrossi.com/). It works correctly for the single chip detection case and safely falls through on other multi-chip addresses. It would be great if you could test this on the armada 370 rd board with reg=16. However just a side note, I had to move the reset gpio setup to occur before the smi init. Interestingly I am not sure if there was a reason for the reset to be unconfigured before setting up smi, it seems that might cause issues with the multi-chip smi init ops? Thanks, Nathan > > Looking at the existing DTs, there are only two using multi-chip mode > with reg=16: > > arm/boot/dts/armada-370-rd.dts- reg = <0x10>; > arm/boot/dts/kirkwood-linksys-viper.dts- reg = <16>; > > And i happen to have an armada-370-rd :-) > > Andrew