From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752738AbdFVBmo (ORCPT ); Wed, 21 Jun 2017 21:42:44 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:7917 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751884AbdFVBmS (ORCPT ); Wed, 21 Jun 2017 21:42:18 -0400 Subject: Re: [PATCH NET] net/hns:bugfix of ethtool -t phy self_test To: Andrew Lunn CC: Florian Fainelli , , , , , , , , , , , , , , , References: <1497605091-94725-1-git-send-email-linyunsheng@huawei.com> <7500513f-e263-838c-12a1-4343f7281f1a@gmail.com> <08ef77fc-29ab-8262-2126-c547960d5628@huawei.com> <20170620132705.GD13704@lunn.ch> <524e1181-f90d-0f05-200a-44cfa179dbf3@huawei.com> <20170621031320.GA1487@lunn.ch> <2a0e4db4-759d-4ce9-f42c-12303898b2c9@huawei.com> <20170621133449.GB27585@lunn.ch> From: l00371289 Message-ID: Date: Thu, 22 Jun 2017 09:41:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20170621133449.GB27585@lunn.ch> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.74.190.125] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0201.594B205D.00D1,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 79d1c646dd72e5c9909f6790615cfee2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Andrew On 2017/6/21 21:34, Andrew Lunn wrote: >> drivers/net/ph/marvell.c >> marvell_set_loopback(struct phy_device *dev, bool enable) >> { >> /* do some device specific setting */ >> ........ >> >> return genphy_loopback(dev, enable); >> } >> >> I don't know if this makes sense or not? > > Nope, you want something in phy.c like this. Not compiled, not > tested.... > > int phy_loopback(struct phy_device *dev, bool enable) > { > > int err; > > mutex_lock(dev->mutex); > > if (enable && dev->loopback_enabled) { > err = -EBUSY; > goto out; > } > > if (!enable && !dev->loopback_enabled) { > err = -EINVAL; > goto out; > } > > if (dev->drv->loopback) > err = dev->drv->loopback(dev, enable); > > if (!err) > dev->loopback_enabled = enable > > mutex_unlock(dev->mutex); > > out: > return err; > } > EXPORT_SYMBOL(phy_loopback); > > The interesting part is how to handle two attempts to enable loopback. > Should the MAC driver be responsible for preventing that? Or do it in > the PHY driver? And what will the MAC driver do if it gets EBUSY? > Return it to user space? I don't think returning to user space is an option, because it mean ethtool phy self test would fail because if availability of some software resoure, which is not some application would expect. here is what I can think of: driver/net/ethernet/hisilicon/hns/hns_ethtool.c int phy_loopback_selftest(struct phy_device *dev) { int err; mutex_lock(dev->mutex); if (dev->drv->loopback) err = dev->drv->loopback(dev, 1); if (err) goto out; /* mac driver do the test*/ ................. if (dev->drv->loopback) err = dev->drv->loopback(dev, 0); if (err) goto out; out: mutex_unlock(dev->mutex); return err; } One question I can think of is that, how do we ensure mac driver enable and disable phy loopback in pair, enable loopback after dev->mutex is taken, disable loopback before dev->mutex is released? I hope I am not missing something obvious, any suggestion and idea? Best Regards Yunsheng Lin