From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB679C433B4 for ; Fri, 23 Apr 2021 12:53:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 78854611CC for ; Fri, 23 Apr 2021 12:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230521AbhDWMxy (ORCPT ); Fri, 23 Apr 2021 08:53:54 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:37942 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbhDWMxy (ORCPT ); Fri, 23 Apr 2021 08:53:54 -0400 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1lZvJ3-000eY8-KB; Fri, 23 Apr 2021 14:53:13 +0200 Date: Fri, 23 Apr 2021 14:53:13 +0200 From: Andrew Lunn To: Ansuel Smith Cc: Florian Fainelli , Vivien Didelot , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Rob Herring , Heiner Kallweit , Russell King , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 13/14] drivers: net: dsa: qca8k: protect MASTER busy_wait with mdio mutex Message-ID: References: <20210423014741.11858-1-ansuelsmth@gmail.com> <20210423014741.11858-14-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210423014741.11858-14-ansuelsmth@gmail.com> Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org On Fri, Apr 23, 2021 at 03:47:39AM +0200, Ansuel Smith wrote: > MDIO_MASTER operation have a dedicated busy wait that is not protected > by the mdio mutex. This can cause situation where the MASTER operation > is done and a normal operation is executed between the MASTER read/write > and the MASTER busy_wait. Rework the qca8k_mdio_read/write function to > address this issue by binding the lock for the whole MASTER operation > and not only the mdio read/write common operation. > > Signed-off-by: Ansuel Smith > --- > drivers/net/dsa/qca8k.c | 59 ++++++++++++++++++++++++++++++++++------- > 1 file changed, 50 insertions(+), 9 deletions(-) > > diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c > index 88a0234f1a7b..d2f5e0b1c721 100644 > --- a/drivers/net/dsa/qca8k.c > +++ b/drivers/net/dsa/qca8k.c > @@ -609,9 +609,33 @@ qca8k_port_to_phy(int port) > return port - 1; > } > > +static int > +qca8k_mdio_busy_wait(struct qca8k_priv *priv, u32 reg, u32 mask) > +{ > + unsigned long timeout; > + u16 r1, r2, page; > + > + qca8k_split_addr(reg, &r1, &r2, &page); > + > + timeout = jiffies + msecs_to_jiffies(20); > + > + /* loop until the busy flag has cleared */ > + do { > + u32 val = qca8k_mii_read32(priv->bus, 0x10 | r2, r1); > + int busy = val & mask; > + > + if (!busy) > + break; > + cond_resched(); > + } while (!time_after_eq(jiffies, timeout)); > + > + return time_after_eq(jiffies, timeout); You should really be returning -ETIMEDOUT here on error. Andrew