Received: by 10.213.65.68 with SMTP id h4csp1602425imn; Thu, 29 Mar 2018 07:42:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx497lH1s1XaKfrJAbLNRUUQWdShvcSyC2fQFnbUSDWQu/QZmKL8tYX+6mb9QpZwgObDPAxGh X-Received: by 2002:a17:902:8688:: with SMTP id g8-v6mr8761260plo.340.1522334537158; Thu, 29 Mar 2018 07:42:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522334537; cv=none; d=google.com; s=arc-20160816; b=FufWDgrmTGt2avRdOeWSCtvmIAfjiPeEtSW72TrsQ27pxMcgmBqVwXlJd96tUkCfFm U2TTvXGGPbT80Uf1J96GCbrWlGJ19K2HFxFEhH2sUXUJxxxQDTC7Hu01IpVJbo4SnHpX EaWJ0b6QlR5StCGfOkLwnefyeecSsjiDhrr8PQZKp25W1g/oAyyas5C1VUiqYSre0ykg jKJslD7Tm1lSnqsoaSDbkKr2j/WntFCaNHPYXSAfrnmj6RqxklRIqwRBHa56jcWd2gYj mKq93fj5ynTMrJb6xA4WfaD6uMOo+n5fFgOWnmzbcuFNAvBlg2hdy7fx01l4zxPrFtiz sR4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=LU4q0/VdYbImK89ahVzB6xkP9pQiEnOHeSvrFzMMkWo=; b=soLy47Zht0HLWB+mE2EKDqsjovSRzQWVs0/uqe/7c4PFtZwlNCHzWPPUTwbz5gAS8j ygNmgCmq8ZFn1u1DHAPj9hqMvRfUNRwEyEKbORAAcS0y1JxCba5TbibwazxmCJC3T2Rw PKIFwX41pIBWktvCEp7L7HAPzjx5WXnj1725+tk8K1PSdNZzSf8tcmGOnswn6qLsWLxY ZopYN7XSev6N0PgZ9qLzLoiy5Sj5fy7RJwDgnxuqdHR9Q5GcvRns8FSiUxxsSoWkMSUg PH435BMFtFHHiDGbJD7SoaCwPmqaWy8quRlIq6Nd02sbSLVBblJyKoel/b0r1vzi0ZX3 N+uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=MgHFM8ML; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13si4476177pfb.373.2018.03.29.07.42.02; Thu, 29 Mar 2018 07:42:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=MgHFM8ML; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751913AbeC2Okx (ORCPT + 99 others); Thu, 29 Mar 2018 10:40:53 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:46343 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750884AbeC2Okv (ORCPT ); Thu, 29 Mar 2018 10:40:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=LU4q0/VdYbImK89ahVzB6xkP9pQiEnOHeSvrFzMMkWo=; b=MgHFM8MLwE+c7ruGR5jUWrMOdHOt+iKuGQ+HQGON9P0d3TtFi+g36lhnlQZaTrJ+K1pmZWAi3wIbEayzaCahB8AvyqSRicYHJlqOgVdFDMnlfD03tvYy5JlI/GN8RngRXQyPQ6LyrY0RMRhMzvTp8LWzpSV+vWkgVgAFQvDfyGw=; Received: from andrew by vps0.lunn.ch with local (Exim 4.84_2) (envelope-from ) id 1f1YjJ-00029J-Qx; Thu, 29 Mar 2018 16:40:41 +0200 Date: Thu, 29 Mar 2018 16:40:41 +0200 From: Andrew Lunn To: Alexandre Belloni Cc: "David S . Miller" , Allan Nielsen , razvan.stefanescu@nxp.com, po.liu@nxp.com, Thomas Petazzoni , Florian Fainelli , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@linux-mips.org Subject: Re: [PATCH net-next 3/8] net: mscc: Add MDIO driver Message-ID: <20180329144041.GA25752@lunn.ch> References: <20180323201117.8416-1-alexandre.belloni@bootlin.com> <20180323201117.8416-4-alexandre.belloni@bootlin.com> <20180323204939.GS24361@lunn.ch> <20180329140544.GB12066@piout.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180329140544.GB12066@piout.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 29, 2018 at 04:05:44PM +0200, Alexandre Belloni wrote: > On 23/03/2018 at 21:49:39 +0100, Andrew Lunn wrote: > > On Fri, Mar 23, 2018 at 09:11:12PM +0100, Alexandre Belloni wrote: > > > Add a driver for the Microsemi MII Management controller (MIIM) found on > > > Microsemi SoCs. > > > On Ocelot, there are two controllers, one is connected to the internal > > > PHYs, the other one can communicate with external PHYs. > > > > Hi Alexandre > > > > This looks to be standalone. Such drivers we try to put in > > drivers/net/phy. > > > > > +static int mscc_miim_read(struct mii_bus *bus, int mii_id, int regnum) > > > +{ > > > + struct mscc_miim_dev *miim = bus->priv; > > > + u32 val; > > > + int ret; > > > + > > > + mutex_lock(&miim->lock); > > > > What are you locking against here? > > > > And you don't appear to initialize the mutex anywhere. > > > > > +static int mscc_miim_reset(struct mii_bus *bus) > > > +{ > > > + struct mscc_miim_dev *miim = bus->priv; > > > + int i; > > > + > > > + if (miim->phy_regs) { > > > + writel(0, miim->phy_regs + MSCC_PHY_REG_PHY_CFG); > > > + writel(0x1ff, miim->phy_regs + MSCC_PHY_REG_PHY_CFG); > > > + mdelay(500); > > > + } > > > + > > > + for (i = 0; i < PHY_MAX_ADDR; i++) { > > > + if (mscc_miim_read(bus, i, MII_PHYSID1) < 0) > > > + bus->phy_mask |= BIT(i); > > > + } > > > > Why do this? Especially so for the external bus, where the PHYs might > > have a GPIO reset line, and won't respond until the gpio is > > released. The core code does that just before it scans the bus, or > > just before it scans the particular address on the bus, depending on > > the scope of the GPIO. > > > > IIRC, this was needed when probing the bus without DT, in that case, the > mdiobus_scan loop of __mdiobus_register() will fail when doing the > get_phy_id for phys 0 to 31 because get_phy_id() transforms any error in > -EIO and so it is impossible to register the bus. Other drivers have a > similar code to handle that case. Hi Alexandre Do you mean mscc_miim_read() will return -EIO if there is no device on the bus at the address trying to be read? Most devices just return 0xffff because there is a pull up on the data line, nothing is driving it, so all 1's are read. It sounds like the correct fix is for get_phy_id() to look at the error code for mdiobus_read(bus, addr, MII_PHYSID1). If it is EIO and maybe ENODEV, set *phy_id to 0xffffffff and return. The scan code should then do the correct thing. Andrew