Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1479015pxu; Fri, 16 Oct 2020 13:05:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiwR1L/UZ/5i9v0cke8seqBMMe/L/4dZRtrkhlttKXda7Ul2FOpwLTTbiyfETG1vJV3SAL X-Received: by 2002:a17:906:b1d6:: with SMTP id bv22mr5532232ejb.60.1602878700166; Fri, 16 Oct 2020 13:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602878700; cv=none; d=google.com; s=arc-20160816; b=TtM1+aBL820bYjGf2LrP3zDgvNvGvgT529gc8N8/BNaYF7tLISptZYi0XWmxwLH+lC YEBEXYkU1Og6dVU6+Yzm1TsJ58vFWpaGUYazeWoss6Kd3mduxH5xaMe6MWgllruyRAsh 6V7Xg6Sbnmx5F6ZJC77s8N1YkNx/evxgx5zAsBAD3hQjkcqUvD8s7dCa7nZl7n5AAnVF k6DRfZOtSfjgbeDCUVsqIdim6HxP9FXmXEEczbBgruUz6ai6fRFE1+9suCpnVBKZ1meo rYQiPnnkIgsI1/4O/8hzLhS0kESuSLnrvK2YDv0f5FJbdR8cR5io+mxtZbx7DyjwHIrz 9qjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:mime-version:user-agent :message-id:in-reply-to:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=79Ih4rNjifJnvzxSaVZe5NbN9xFlxjqnv7x4cIAYt6M=; b=ENZN4/uYVn0eD+BGHnZrBja7Y2rMDeeckqX6nYOnZDS3Sax/fZ9edV/EsrowGhXOf+ 0i0FJHtsna/kxYIbUWZLY31UHtxdw7ZMxzL6yHGV8GEnOISDwYuhOiIx1Bpdo7cdHnAX z316XgGFI38aQAjBgJhame1rzcmyxamOWjBe/+d3l7Urq69/5icVfkCiMG7Y3zXmXj5g EaidflVjbeEZSLqul1I6g/yn4wJJ/+70g+a54bgaElOWYcMW8u7ToefSQKCa9rjk0PUO oKl/8XNHfKzKKA5AoeP1doA0qR/o/5+NymoGFcOXGi+OzKGkVdiM/dVGcWP0Ngc647vX AmzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=YpGF5USu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l2si2396683ejb.423.2020.10.16.13.04.37; Fri, 16 Oct 2020 13:05:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=YpGF5USu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2410474AbgJPTTZ (ORCPT + 99 others); Fri, 16 Oct 2020 15:19:25 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:48271 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393083AbgJPTTY (ORCPT ); Fri, 16 Oct 2020 15:19:24 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20201016191912euoutp0255ae5b1dc6af9cc42961c6a5415eb66c~_jy_fovJt0912809128euoutp02Q; Fri, 16 Oct 2020 19:19:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20201016191912euoutp0255ae5b1dc6af9cc42961c6a5415eb66c~_jy_fovJt0912809128euoutp02Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1602875952; bh=79Ih4rNjifJnvzxSaVZe5NbN9xFlxjqnv7x4cIAYt6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YpGF5USubzsySPqgtY/SycVNhza9L5RK6dWA6KRdgbd1dkRlRS3XmgLsnJLjJpC06 z7d3eP9T3vHzmkQT59qyIj988rUnC+9fv+IBnfHooV7HuWZmkDeESVBgjD5G8eCGET +8K+3ZD+bq1rd8vwmXxs27xmYpJAYYM1y6lmCWSo= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20201016191906eucas1p18d3fbf7d9bd9b4e52522102784d4bf05~_jy5BL-ao1037210372eucas1p13; Fri, 16 Oct 2020 19:19:06 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 13.54.06456.A22F98F5; Fri, 16 Oct 2020 20:19:06 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20201016191905eucas1p235fb430a8f330a39e64f4fd6b81decb2~_jy4bzZVd3193331933eucas1p2t; Fri, 16 Oct 2020 19:19:05 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20201016191905eusmtrp17d44d024354b88fd8091fee606766fc1~_jy4a-_rq1439014390eusmtrp13; Fri, 16 Oct 2020 19:19:05 +0000 (GMT) X-AuditID: cbfec7f2-7efff70000001938-69-5f89f22ab066 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 96.9C.06017.922F98F5; Fri, 16 Oct 2020 20:19:05 +0100 (BST) Received: from localhost (unknown [106.120.51.46]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20201016191905eusmtip127e25dfb5fb7bda5cf6e854e3470ee53~_jy4QhrjU0978609786eusmtip1J; Fri, 16 Oct 2020 19:19:05 +0000 (GMT) From: Lukasz Stelmach To: Andrew Lunn Cc: "David S. Miller" , Jakub Kicinski , Krzysztof Kozlowski , Kukjin Kim , Rob Herring , Russell King , jim.cromie@gmail.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?Q?Bart=C5=82omiej_=C5=BBolnierkiewi?= =?utf-8?Q?cz?= , Marek Szyprowski Subject: Re: [PATCH v2 2/4] net: ax88796c: ASIX AX88796C SPI Ethernet Adapter Driver Date: Fri, 16 Oct 2020 21:18:54 +0200 In-Reply-To: <20201016180100.GF139700@lunn.ch> (Andrew Lunn's message of "Fri, 16 Oct 2020 20:01:00 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg="pgp-sha256"; protocol="application/pgp-signature" X-Brightmail-Tracker: H4sIAAAAAAAAA01Sa0hTYRjm2zlnOy5nx2X5siJkGKSlZY06kZlFxakfFUIRRemqg0Vuji0r ++OiLJ2bhmXpNDSblzSt5jK7WLFEM8nlFQ2li5GmmbQZbWHR1qfgv+d53ue9PB8fTUjdlIw+ rj7Ja9XKJLlQTNY3exwR4c7M+JVTJjHrGLQT7P38uxRb5LhAssVN7RTbOz5AsTlDYwTrcNwT sW/rsynWOtRLsV2Pi4RsvuOZgLXnNSK2pmlQxDaXLGDTG5tEsXO5rt4OgrPd7hdwj8yDIs5a lSnk6ixp3KMGl4DLtlUhzmVdvJveL44+yicdP8VrV8QkiI8ZuiyEJl1xRj+o0aM7YQbkRwOj gOwXZoEBiWkpU4mguClTiMkkgqmWjyQmLgRvOpyimZYJ09i0qwJBRuEXApNhBH/+Wr0VmhYy kVBTs8/XEM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5+YcVxGYWWM8isXoSJ4gtLBAisbDv FBOILSSgK/H12TNmEJtFQFXi05a1YHFOgVyJz51XwOK8AuYSV5bdArNFBSwltry4zw4RF5Q4 OfMJC8T8bImvq58zT2AUmIUkNQtJahbQdcwCmhLrd+lDhLUlli18zQxh20qsW/eeZQEj6ypG kdTS4tz03GIjveLE3OLSvHS95PzcTYzA+N127OeWHYxd74IPMQpwMCrx8G5Y1BkvxJpYVlyZ e4hRBWjMow2rLzBKseTl56UqifA6nT0dJ8SbklhZlVqUH19UmpNafIjRFOjPicxSosn5wJST VxJvaGpobmFpaG5sbmxmoSTO2yFwMEZIID2xJDU7NbUgtQimj4mDU6qB8ZgeO8u0K5q+L+dd WNboq8X/Xbfnlgbznid+PFlvk1VXLrn0kKv7UfFJTbbST8Hh8geVNpd937DvjseCKxyiE4Tq f7L4KRceF5HkNlP17Zpu/eVCzBcj7dup3JPU/jDFG0//n/5FYHtPz7p0qdBKU8erzfOnZwgt PbRMOeUhg9+JsKqGpkUHlViKMxINtZiLihMB7YU31AEDAAA= X-CMS-MailID: 20201016191905eucas1p235fb430a8f330a39e64f4fd6b81decb2 X-Msg-Generator: CA X-RootMTR: 20201016191905eucas1p235fb430a8f330a39e64f4fd6b81decb2 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20201016191905eucas1p235fb430a8f330a39e64f4fd6b81decb2 References: <20201016180100.GF139700@lunn.ch> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable It was <2020-10-16 pi=C4=85 20:01>, when Andrew Lunn wrote: >> >> +static void >> >> +ax88796c_get_regs(struct net_device *ndev, struct ethtool_regs *regs= , void *_p) >> >> +{ >> >> + struct ax88796c_device *ax_local =3D to_ax88796c_device(ndev); >> >> + u16 *p =3D _p; >> >> + int offset, i; >> >> + >> >> + memset(p, 0, AX88796C_REGDUMP_LEN); >> >> + >> >> + for (offset =3D 0; offset < AX88796C_REGDUMP_LEN; offset +=3D 2) { >> >> + if (!test_bit(offset / 2, ax88796c_no_regs_mask)) >> >> + *p =3D AX_READ(&ax_local->ax_spi, offset); >> >> + p++; >> >> + } >> >> + >> >> + for (i =3D 0; i < AX88796C_PHY_REGDUMP_LEN / 2; i++) { >> >> + *p =3D phy_read(ax_local->phydev, i); >> >> + p++; >> > >> > Depending on the PHY, that can be dangerous. >>=20 >> This is a built-in generic PHY. The chip has no lines to attach any >> other external one. >>=20 >> > phylib could be busy doing things with the PHY. It could be looking at >>=20 >> How does phylib prevent concurrent access to a PHY?=20 > > phydev->lock. All access to the PHY should go through the phylib, > which will take the lock before calling into the driver. > >> > a different page for example. >>=20 >> Different page?=20 > > I was talking about the general case. A number of PHYs have more than > 32 registers. So they implement pages to give access to more > registers. For that to work, you need to ensure you don't have > concurrent access. > It is not the case, this one has got only 7 and one only needs to make sure the transaction in ax88796c_mdio_read() is not messed up. >> > miitool(1) can give you the same functionally without the MAC driver >> > doing anything, other than forwarding the IOCTL call on. >>=20 >> No, I am afraid mii-tool is not able to dump registers. > > It should be able to. > > sudo mii-tool -vv eth0 > Using SIOCGMIIPHY=3D0x8947 > eth0: negotiated 1000baseT-FD flow-control, link ok > registers for MII PHY 0:=20 > 1040 79ed 001c c800 0de1 c5e1 006d 0000 > 0000 0200 0800 0000 0000 0000 0000 2000 > 0000 0000 ffff 0000 0000 0400 0f00 0f00 > 318b 0053 31ec 8012 bf1f 0000 0000 0000 > product info: vendor 00:07:32, model 0 rev 0 > basic mode: autonegotiation enabled > basic status: autonegotiation complete, link ok > capabilities: 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT= -HD > advertising: 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT= -HD flow-control > link partner: 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT= -HD flow-control Indeed. However, mii-tool(1) simply calls ioctl(SIOCGMIIREG) number of times. Is looping in the userspace any better than in kernel? Anyway, thanks for pointing out possible problems, I will make sure to avoid them. >> >> +ax88796c_mdio_write(struct mii_bus *mdiobus, int phy_id, int loc, u1= 6 val) >> >> +{ >> >> + struct ax88796c_device *ax_local =3D mdiobus->priv; >> >> + int ret; >> >> + >> >> + AX_WRITE(&ax_local->ax_spi, val, P2_MDIODR); >> >> + >> >> + AX_WRITE(&ax_local->ax_spi, >> >> + MDIOCR_RADDR(loc) | MDIOCR_FADDR(phy_id) >> >> + | MDIOCR_WRITE, P2_MDIOCR); >> >> + >> >> + ret =3D read_poll_timeout(AX_READ, ret, >> >> + ((ret & MDIOCR_VALID) !=3D 0), 0, >> >> + jiffies_to_usecs(HZ / 100), false, >> >> + &ax_local->ax_spi, P2_MDIOCR); >> >> + if (ret) >> >> + return -EIO; >> >> + >> >> + if (loc =3D=3D MII_ADVERTISE) { >> >> + AX_WRITE(&ax_local->ax_spi, (BMCR_FULLDPLX | BMCR_ANRESTART | >> >> + BMCR_ANENABLE | BMCR_SPEED100), P2_MDIODR); >> >> + AX_WRITE(&ax_local->ax_spi, (MDIOCR_RADDR(MII_BMCR) | >> >> + MDIOCR_FADDR(phy_id) | MDIOCR_WRITE), >> >> + P2_MDIOCR); >> >> >> > >> > What is this doing? >> > >>=20 >> Well=E2=80=A6 it turns autonegotiation when changing advertised link mod= es. But >> this is obvious. As to why this code is here, I will honestly say =E2=80= =94 I am >> not sure (Reminder: this is a vendor driver I am porting, I am more than >> happy to receive any comments, thank you). Apparently it is not required >> and I am willing to remove it. > > Please do remove it. > Done. >> >> + >> >> + ret =3D devm_register_netdev(&spi->dev, ndev); >> >> + if (ret) { >> >> + dev_err(&spi->dev, "failed to register a network device\n"); >> >> + destroy_workqueue(ax_local->ax_work_queue); >> >> + goto err; >> >> + } >> > >> > The device is not live. If this is being used for NFS root, the kernel >> > will start using it. So what sort of mess will it get into, if there >> > is no PHY yet? Nothing important should happen after register_netdev(). >> > >>=20 >> But, with an unregistered network device ndev_owner in >> phy_attach_direct() is NULL. Thus, phy_connect_direct() below fails. >>=20 >> --8<---------------cut here---------------start------------->8--- >> 1332 if (dev) >> 1333 ndev_owner =3D dev->dev.parent->driver->owner; >> 1334 if (ndev_owner !=3D bus->owner && !try_module_get(bus->= owner)) { >> 1335 phydev_err(phydev, "failed to get the bus modul= e\n"); >> 1336 return -EIO; >> 1337 } >> --8<---------------cut here---------------end--------------->8--- > > Which is probably why most drivers actually attach the PHY in open() > and detach it in close(). > > It can be done in probe, just look around for a driver which does and > copy it. > I will. Thanks for the info. >> No problem. Do you have any recommendation how to express this >>=20 >> #define PSR_RESET (0 << 15) >> >> I know it equals 0, but shows explicitly the bit number. > > Yes, that is useful for documentation. How about: > > #define PSR_NOT_RESET BIT(15) > > And then turn the logic around. OK. This is an idea. I'll look around some more. =2D-=20 =C5=81ukasz Stelmach Samsung R&D Institute Poland Samsung Electronics --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEXpuyqjq9kGEVr9UQsK4enJilgBAFAl+J8h4ACgkQsK4enJil gBD8qAf/eYt3jr44Y+Wjm/yUU1Myn0dZY7KbEcVSJo2oZEiYL3nKpTvcFeMPw9dH o49vEFwADVrjiHXyy1w05jJTyUBv8RiAMEpCovbFL26nW6eyxqNCyUUwRRDgi7fk uBnUyJWTcryPVGWH2bw84+ZtTvGh9UuHQpAWzhGf0X48kIym5GvgPK4+OaonqoPg C+9oQxLxJ4b0/+JHBSRcqHA2YVdHVZYCsCXchxkpX8cRxoNeLc6Y0pNXzfGKFYCM wLpJd+ZZ6bL4f4sEdIfpimB0nIcV19BxtmvbWFR6Bzur6+fTYxHY9sH8CrGS4rrJ +6ZXm5UZSxjT6/dYpUKiatNQZXTxFg== =JcIo -----END PGP SIGNATURE----- --=-=-=--