Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3099029rdb; Wed, 13 Sep 2023 01:47:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGzVg33dyCi9JkabvJWnr2g48PnlALGpIELc45k1cASAQZ8DEKs74Y2/v+nJKFrph9tO0l X-Received: by 2002:a17:902:a40a:b0:1c3:4565:22f with SMTP id p10-20020a170902a40a00b001c34565022fmr1656778plq.21.1694594826247; Wed, 13 Sep 2023 01:47:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694594826; cv=none; d=google.com; s=arc-20160816; b=C66DtaA4x0hoKzElmYF1V/Cn2HIg2ciDEyEZhZBGNcqek+CKuL9xAYWrUYR1Eu/va4 TkWWx27Y5gfL723xaew4MVGxy7qi6QxwxAmvSpxhsFj9tgXtGNr22vOYf2oao9EQaMgo CxtQlbIcySW7G9ytc41ikZYA/Mt1YF0JboFSg57bRajKSpHleNhl/wua9uARP7gKE9k6 HOY6tFtfkjmC6bF44jp+WOnYUTRBgWJlzqszYP0B1vtaAdREG5kKCFvr7Ic2w01Ltfby xdMCURLdhmLQ+7VN2lTKSKO49QOfoRWMqfrJvw8VmxnQBz+FpktS+tSq0vNg8h+3tRdO BpmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BXJm/TiqH4AAPAwfc/Qy2jYjA5r7iu+40UTmJpL7FD8=; fh=HP0u6UTDta/+GqBM4mahf5Lc0EVr0KtIYijFiIYMcHg=; b=QzwkDZe1DI5vOYpoaH+bs+zehX//RV9bKwi36BRYGQJThgq7liv+n4zYiPmSLiNTzG SdxE8aYEuoYCJX3AvFOx2vCH9ldMmnmEHfWHk9lCmxrw+dSzaSjX0l/FIdiYB85VPtzH JYIuSkjEvdpcZCS0a5uJNW+qr+WTZdvfY3n0VMY5XXjTYpiyK9hGO5LyRstn5Zm3vEOD CPo+BkKBwFJpI8WlyhjSWjWNCO5jkMHj0jX5xAFYw1rgNXCvUJtcqc4fZeOgqscXPLFs DoecofnF4QtBsfMcOY4SkGNqcpamzjhN5V92GvMc3ymy+nrneuzwFqYh4m4AylWNI8VP dprg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=YOctBJGu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id jb22-20020a170903259600b001b9d0ad0d40si9443737plb.128.2023.09.13.01.47.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 01:47:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=YOctBJGu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 97237824685C; Tue, 12 Sep 2023 19:40:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238036AbjIMCkQ (ORCPT + 99 others); Tue, 12 Sep 2023 22:40:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229557AbjIMCkP (ORCPT ); Tue, 12 Sep 2023 22:40:15 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E0371713; Tue, 12 Sep 2023 19:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=BXJm/TiqH4AAPAwfc/Qy2jYjA5r7iu+40UTmJpL7FD8=; b=YOctBJGu7AFO85kb3gkWsFXT5l 6Hb1ei68Q/4Sosm4kuzQ3VBJi9uFgKjj7ugOoHCxlS/dfY7Ay67gXOYwx/jEsuH66ct79qdvE5lz5 CLhHt5WyVcoeM9J3IOVQzgT9cb6p7+xoYbF92JlsBZSZb/YsnxuaIcuZbHDw1IO8Usss=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1qgFn3-006H2p-GA; Wed, 13 Sep 2023 04:39:41 +0200 Date: Wed, 13 Sep 2023 04:39:41 +0200 From: Andrew Lunn To: Parthiban Veerasooran Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, corbet@lwn.net, steen.hegelund@microchip.com, rdunlap@infradead.org, horms@kernel.org, casper.casan@gmail.com, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, horatiu.vultur@microchip.com, Woojung.Huh@microchip.com, Nicolas.Ferre@microchip.com, UNGLinuxDriver@microchip.com, Thorsten.Kummermehr@microchip.com Subject: Re: [RFC PATCH net-next 2/6] net: ethernet: add mac-phy interrupt support with reset complete handling Message-ID: <027d8f7b-6932-4d9d-b2f9-5369806a79a3@lunn.ch> References: <20230908142919.14849-1-Parthiban.Veerasooran@microchip.com> <20230908142919.14849-3-Parthiban.Veerasooran@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230908142919.14849-3-Parthiban.Veerasooran@microchip.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Sep 2023 19:40:37 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email > +static int oa_tc6_sw_reset(struct oa_tc6 *tc6) > +{ > + long timeleft; > + u32 regval; > + int ret; > + > + /* Perform software reset with both protected and unprotected control > + * commands because the driver doesn't know the current status of the > + * MAC-PHY. > + */ > + regval = SW_RESET; > + reinit_completion(&tc6->rst_complete); > + ret = oa_tc6_perform_ctrl(tc6, OA_TC6_RESET, ®val, 1, true, false); > + if (ret) { > + dev_err(&tc6->spi->dev, "RESET register write failed\n"); > + return ret; > + } > + > + ret = oa_tc6_perform_ctrl(tc6, OA_TC6_RESET, ®val, 1, true, true); > + if (ret) { > + dev_err(&tc6->spi->dev, "RESET register write failed\n"); > + return ret; > + } > + timeleft = wait_for_completion_interruptible_timeout(&tc6->rst_complete, > + msecs_to_jiffies(1)); > + if (timeleft <= 0) { > + dev_err(&tc6->spi->dev, "MAC-PHY reset failed\n"); > + return -ENODEV; > + } This seems a bit messy and complex. I assume reset is performed once during probe, and never again? So i wonder if it would be cleaner to actually just poll for the reset to complete? You can then remove all this completion code, and the interrupt handler gets simpler? > + /* Register MAC-PHY interrupt service routine */ > + ret = devm_request_irq(&spi->dev, spi->irq, macphy_irq, 0, "macphy int", > + tc6); > + if ((ret != -ENOTCONN) && ret < 0) { > + dev_err(&spi->dev, "Error attaching macphy irq %d\n", ret); > + goto err_macphy_irq; > + } Why is -ENOTCONN special? A comment would be good here. > -void oa_tc6_deinit(struct oa_tc6 *tc6) > +int oa_tc6_deinit(struct oa_tc6 *tc6) > { > - kfree(tc6); > + int ret; > + > + devm_free_irq(&tc6->spi->dev, tc6->spi->irq, tc6); > + ret = kthread_stop(tc6->tc6_task); > + if (!ret) > + kfree(tc6); > + return ret; > } What is the MAC driver supposed to do if this fails? But this problem probably goes away once you use a threaded interrupt handler. w> +/* Open Alliance TC6 Standard Control and Status Registers */ > +#define OA_TC6_RESET 0x0003 /* Reset Control and Status Register */ > +#define OA_TC6_STS0 0x0008 /* Status Register #0 */ Please use the same name as the standard. It use STATUS0, so OA_TC6_STATUS0. Please make sure all your defines follow the standard. > + > +/* RESET register field */ > +#define SW_RESET BIT(0) /* Software Reset */ It is pretty normal to put #defines for a register members after the #define for the register itself: #define OA_TC6_RESET 0x0003 /* Reset Control and Status Register */ #define OA_TC6_RESET_SWRESET BIT(0) #define OA_TC6_STATUS0 0x0008 /* Status Register #0 */ #define OA_TC6_STATUS0_RESETC BIT(6) /* Reset Complete */ The naming like this also helps avoid mixups. Andrew