Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp589568iog; Wed, 29 Jun 2022 06:29:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t1Dxq+l8Hcpy/iWFU9rD2KamsP1zYFP8HyzCNEwOHl8csnXotG8ONn2oT6BsEv43GZEFxb X-Received: by 2002:a50:c209:0:b0:435:6b37:46cb with SMTP id n9-20020a50c209000000b004356b3746cbmr4332148edf.341.1656509365851; Wed, 29 Jun 2022 06:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656509365; cv=none; d=google.com; s=arc-20160816; b=rc20tnfHoRAvr/Z1wVkqk/5wxuWPJXVslyeP3NId5Mb94ru6SVvZJ/xgyPVOgEAg53 uiwL+l/Dwo2XXLt/d3bFtrlItb1P3xvbkYuELU6sZn26HgtLkVjlRpjirJ1tK6TLXSvL NVCgG+IagNLQ87yKIglrU9bE7faHtqawDemkaoY08o9sIBN/oddJitQkBJY2UCU3G4p0 A/9ef/cz8cZbOwK8P8cmjRIZAW9DTilb2HseCajAbFpQa8B7Ms5w2D1e51fXavP+zDO5 0F+XahoBsAYHAiz3Bucgx7cielH/TdU6ccYX1jQ9VMnCNxxpqnLYKCJdlJUyvv2/sUmM 3XCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=a9zKFFOmvnQkMK5lOTxLNLdbs9S7/iN+PB986KeXEY4=; b=h6az409UOrLz1QSx9J/jbbXUy2h4e5KT4d+8MhFwamF7KTc0O6Ab39+G8xRN89fpyC NLf3CqkkQyIsNL3MwBvbzs/o4WwWO8xrtxj2y+00OppJJQx2vBu+Hm3FDxsetL1sPzLq 4EiqAG9g127VcvDZS64wgDWGIypYA7ndHorpSjGQZZAuA1DDMzcZ+evJh7nnLDp0N9+m sHC2HvMNi6w0cQCPMpttBxH97E6D5OoSHTeVJEXgbK4tCaKPdU1bQwWLJ2pTf2GFS8/f Bwhix/3CfnuYmb1qKpFzgZPtvwi5NAk5OTqLdH/oNfY314g8il6VOb5ljctKTm9MAueB u3hA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l11-20020a056402254b00b0042dd5f6dae8si2313709edb.563.2022.06.29.06.28.57; Wed, 29 Jun 2022 06:29:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233215AbiF2MuR (ORCPT + 99 others); Wed, 29 Jun 2022 08:50:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbiF2MuQ (ORCPT ); Wed, 29 Jun 2022 08:50:16 -0400 Received: from out28-73.mail.aliyun.com (out28-73.mail.aliyun.com [115.124.28.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7C7C30F72; Wed, 29 Jun 2022 05:50:06 -0700 (PDT) X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07440299|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.460961-0.000591807-0.538448;FP=0|0|0|0|0|-1|-1|-1;HT=ay29a033018047208;MF=frank.sae@motor-comm.com;NM=1;PH=DS;RN=14;RT=14;SR=0;TI=SMTPD_---.OFWkWUa_1656506959; Received: from sunhua.motor-comm.com(mailfrom:Frank.Sae@motor-comm.com fp:SMTPD_---.OFWkWUa_1656506959) by smtp.aliyun-inc.com; Wed, 29 Jun 2022 20:49:33 +0800 From: Frank To: Peter Geis , Andrew Lunn , Heiner Kallweit , Russell King , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: yinghong.zhang@motor-comm.com, fei.zhang@motor-comm.com, hua.sun@motor-comm.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Frank Subject: Re: Re: [PATCH v2] net: phy: Add driver for Motorcomm yt8521 gigabit Date: Wed, 29 Jun 2022 20:48:48 +0800 Message-Id: <20220629124848.142-1-Frank.Sae@motor-comm.com> X-Mailer: git-send-email 2.31.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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 Hi Andrew, Thanks for your comments. This driver is for an utp-fiber combo phy and sometimes, it has to switch register spaces between utp and fiber for same operation. That is why it looks that there are duplicated operations. > > + * yt8521_soft_reset() - called to issue a PHY software reset > > + * @phydev: a pointer to a &struct phy_device > > + * > > + * returns 0 or negative errno code > > + */ > > +int yt8521_soft_reset(struct phy_device *phydev) > > +{ > > + int old_page; > > + int ret = 0; > > + > > + old_page = phy_save_page(phydev); > > + if (old_page < 0) > > + goto err_restore_page; > > + > > + ret = yt8521_modify_UTP_FIBER_BMCR(phydev, 0, BMCR_RESET); > > + if (ret < 0) > > + goto err_restore_page; > > You should wait for the reset to completed. Can you actually use the > core helper? Is the BMCR in the usual place? So long as you hold the > lock, nothing is going to change the page, so you should be able to > use the helper. > yes, you said it. we will add codes to check if the reset is completed at all. > > > +int yt8521_config_aneg(struct phy_device *phydev) > > +{ > > + struct yt8521_priv *priv = phydev->priv; > > + u8 polling_mode = priv->polling_mode; > > + int old_page; > > + int ret; > > + > > + old_page = yt8521_read_page_with_lock(phydev); > > + if (old_page) > > + return old_page; > > + > > + if (polling_mode == YT8521_MODE_FIBER || > > + polling_mode == YT8521_MODE_POLL) { > > + ret = yt8521_write_page_with_lock(phydev, > > + YT8521_RSSR_FIBER_SPACE); > > + if (ret < 0) > > + goto err_restore_page; > > + > > + ret = genphy_config_aneg(phydev); > > + if (ret < 0) > > + goto err_restore_page; > > + } > > + > > + if (polling_mode == YT8521_MODE_UTP || > > + polling_mode == YT8521_MODE_POLL) { > > + ret = yt8521_write_page_with_lock(phydev, > > + YT8521_RSSR_UTP_SPACE); > > + if (ret < 0) > > + goto err_restore_page; > > + > > + ret = genphy_config_aneg(phydev); > > + if (ret < 0) > > + goto err_restore_page; > > + } > > Looks like this could be refactored to reduce duplication. > sure, as the reason said above, the same operation is required in both utp and fiber spaces. > > > +int yt8521_aneg_done(struct phy_device *phydev) > > +{ > > + struct yt8521_priv *priv = phydev->priv; > > + u8 polling_mode = priv->polling_mode; > > + int link_fiber = 0; > > + int link_utp = 0; > > + int old_page; > > + int ret = 0; > > + > > + old_page = phy_save_page(phydev); > > + if (old_page < 0) > > + goto err_restore_page; > > + > > + if (polling_mode == YT8521_MODE_FIBER || > > + polling_mode == YT8521_MODE_POLL) { > > + /* switch to FIBER reg space*/ > > + ret = yt8521_write_page(phydev, YT8521_RSSR_FIBER_SPACE); > > + if (ret < 0) > > + goto err_restore_page; > > + > > + ret = __phy_read(phydev, YTPHY_SPECIFIC_STATUS_REG); > > + if (ret < 0) > > + goto err_restore_page; > > + > > + link_fiber = !!(ret & YTPHY_SSR_LINK); > > + } > > + > > + if (polling_mode == YT8521_MODE_UTP || > > + polling_mode == YT8521_MODE_POLL) { > > + /* switch to UTP reg space */ > > + ret = yt8521_write_page(phydev, YT8521_RSSR_UTP_SPACE); > > + if (ret < 0) > > + goto err_restore_page; > > + > > + ret = __phy_read(phydev, YTPHY_SPECIFIC_STATUS_REG); > > + if (ret < 0) > > + goto err_restore_page; > > + > > + link_utp = !!(ret & YTPHY_SSR_LINK); > > + } > > + > > + ret = !!(link_fiber | link_utp); > > Does this mean it can do both copper and fibre at the same time. And > whichever gives up first wins? Sure, the phy supports utp, fiber, and both. In the case of both, this driver supposes that fiber is of priority. Thaks again and we will chnaged codes based on your comments. Cheers and BR, Frank -- 2.31.0.windows.1