From nobody Thu Sep 19 21:32:10 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 866D41B14FC; Mon, 9 Sep 2024 08:27:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725870471; cv=none; b=b+TQ53YSLd40KAWcsvluXr/eB+qAR28jAQnUQvRIl91eezaU21qJbvwpoxrk39H9jeH3euYTcBq9U/ghTQZAh4SNHi5m/5mPNYTB6vy51tLjNJkj/ufbakRRBe2r5vqUVJMxXO3mnvwdv4uADU23587SBiH9eolg9YB+x4JBHfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725870471; c=relaxed/simple; bh=+sI/jz+0k99u+/1sONE4Ydtk43cvotichTjvmCtOzAo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bVZgr3lwChONw02N7uOF3gLLjAldmJJY6nBfJhLXN49VIMM5R2/iNVjwh4J++BV80OjPlmkYfHFt72/N84soWXrMCli8FifXxsjH4vqbHhfHLsvUucookfWuI4wCwOtl2/iUR9jDx7w/nqEDSwDscTLuXkooha42Bx3I1+b8iZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=t+GuVrEh; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="t+GuVrEh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1725870469; x=1757406469; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+sI/jz+0k99u+/1sONE4Ydtk43cvotichTjvmCtOzAo=; b=t+GuVrEhQUIcB/2LHvMoTIT5EGhn1p9WA91eQ4ydIcn5QH3NH9bUUncm iKrjS1tAbyYXyJsRZWdxy4AqcTKffftPa0GALK5NHvy1btJSnC6LJgmN2 wDXk3FII5cz73uAi+QWvwJctJcudlupfzjEcWBCwGR+LLrL4cWllncF81 PDAfT7jZAgBFpO0CVLWRtiMXVj8vyM55hbn70bd6bNgA8jVHMtTHdOo5a C8vc8am2aXWVMUv6qCbSPKF8FK5jJlgNB11UGzeIwILeS5uphEx1IRwDP dIPYjyWYJEPxAWPKOks34DJsJxkWJSsZh1MfRJ4HD/K5UYGo0/FE4meDd g==; X-CSE-ConnectionGUID: j/68WEKfSwCMycVyn6gidg== X-CSE-MsgGUID: V6cS02hrRJqOwjkyBHyt5Q== X-IronPort-AV: E=Sophos;i="6.10,213,1719903600"; d="scan'208";a="34622101" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 09 Sep 2024 01:27:46 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 9 Sep 2024 01:27:27 -0700 Received: from che-ll-i17164.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Mon, 9 Sep 2024 01:27:17 -0700 From: Parthiban Veerasooran To: , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , Parthiban Veerasooran Subject: [PATCH net-next v8 11/14] net: ethernet: oa_tc6: implement mac-phy interrupt Date: Mon, 9 Sep 2024 13:55:11 +0530 Message-ID: <20240909082514.262942-12-Parthiban.Veerasooran@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240909082514.262942-1-Parthiban.Veerasooran@microchip.com> References: <20240909082514.262942-1-Parthiban.Veerasooran@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The MAC-PHY interrupt is asserted when the following conditions are met. Receive chunks available - This interrupt is asserted when the previous data footer had no receive data chunks available and once the receive data chunks become available for reading. On reception of the first data header this interrupt will be deasserted. Transmit chunk credits available - This interrupt is asserted when the previous data footer indicated no transmit credits available and once the transmit credits become available for transmitting transmit data chunks. On reception of the first data header this interrupt will be deasserted. Extended status event - This interrupt is asserted when the previous data footer indicated no extended status and once the extended event become available. In this case the host should read status #0 register to know the corresponding error/event. On reception of the first data header this interrupt will be deasserted. Reviewed-by: Andrew Lunn Signed-off-by: Parthiban Veerasooran --- drivers/net/ethernet/oa_tc6.c | 52 ++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/oa_tc6.c b/drivers/net/ethernet/oa_tc6.c index 72d95bad669f..d3510dc19273 100644 --- a/drivers/net/ethernet/oa_tc6.c +++ b/drivers/net/ethernet/oa_tc6.c @@ -126,6 +126,7 @@ struct oa_tc6 { u16 tx_credits; u8 rx_chunks_available; bool rx_buf_overflow; + bool int_flag; }; =20 enum oa_tc6_header_type { @@ -1064,6 +1065,14 @@ static int oa_tc6_try_spi_transfer(struct oa_tc6 *tc= 6) =20 spi_len =3D oa_tc6_prepare_spi_tx_buf_for_rx_chunks(tc6, spi_len); =20 + if (tc6->int_flag) { + tc6->int_flag =3D false; + if (spi_len =3D=3D 0) { + oa_tc6_add_empty_chunks_to_spi_buf(tc6, 1); + spi_len =3D OA_TC6_CHUNK_SIZE; + } + } + if (spi_len =3D=3D 0) break; =20 @@ -1098,8 +1107,11 @@ static int oa_tc6_spi_thread_handler(void *data) int ret; =20 while (likely(!kthread_should_stop())) { - /* This kthread will be waken up if there is a tx skb */ + /* This kthread will be waken up if there is a tx skb or mac-phy + * interrupt to perform spi transfer with tx chunks. + */ wait_event_interruptible(tc6->spi_wq, tc6->waiting_tx_skb || + tc6->int_flag || kthread_should_stop()); =20 if (kthread_should_stop()) @@ -1133,6 +1145,24 @@ static int oa_tc6_update_buffer_status_from_register= (struct oa_tc6 *tc6) return 0; } =20 +static irqreturn_t oa_tc6_macphy_isr(int irq, void *data) +{ + struct oa_tc6 *tc6 =3D data; + + /* MAC-PHY interrupt can occur for the following reasons. + * - availability of tx credits if it was 0 before and not reported in + * the previous rx footer. + * - availability of rx chunks if it was 0 before and not reported in + * the previous rx footer. + * - extended status event not reported in the previous rx footer. + */ + tc6->int_flag =3D true; + /* Wake spi kthread to perform spi transfer */ + wake_up_interruptible(&tc6->spi_wq); + + return IRQ_HANDLED; +} + /** * oa_tc6_start_xmit - function for sending the tx skb which consists ethe= rnet * frame. @@ -1260,8 +1290,28 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, s= truct net_device *netdev) =20 sched_set_fifo(tc6->spi_thread); =20 + ret =3D devm_request_irq(&tc6->spi->dev, tc6->spi->irq, oa_tc6_macphy_isr, + IRQF_TRIGGER_FALLING, dev_name(&tc6->spi->dev), + tc6); + if (ret) { + dev_err(&tc6->spi->dev, "Failed to request macphy isr %d\n", + ret); + goto kthread_stop; + } + + /* oa_tc6_sw_reset_macphy() function resets and clears the MAC-PHY reset + * complete status. IRQ is also asserted on reset completion and it is + * remain asserted until MAC-PHY receives a data chunk. So performing an + * empty data chunk transmission will deassert the IRQ. Refer section + * 7.7 and 9.2.8.8 in the OPEN Alliance specification for more details. + */ + tc6->int_flag =3D true; + wake_up_interruptible(&tc6->spi_wq); + return tc6; =20 +kthread_stop: + kthread_stop(tc6->spi_thread); phy_exit: oa_tc6_phy_exit(tc6); return NULL; --=20 2.34.1