From patchwork Wed Jan 17 22:50:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13522232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 236B7C47258 for ; Wed, 17 Jan 2024 22:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=G3rVbuRSAsSYRg4TcJ8Z8ZNRhLh7ZEM6pIUaURJNKhk=; b=gsP6QX5aOok+2q wyL30BwlZd25y7H5p05AqPP4WD+ryscPp3uFwBUjtbOV4ibh5BHeDQiK8SlUAlE0nvvVj8yEsJhp+ 2VfIA2d5/Ra7MV4FTsuQ29qpq/GfMr5NXzbGB4CgeJ/GwkhbXFxExwVXBlKOymvs+CxlVrejOyQHg bhVEqhlq/wuFZ4pXf12qOsPRMeGFB18D6qXuyjptZLdy4J7rJ8GXXK/0qxcRMgE9nqVF70j5jUefa Jku3Pfcy0DFhvwUepG0xIYxwvUjc/Lx/CY+s8zCu0hHMfdu7ct1tsGW4eg6qLD0Vg8YIYrjnPeGCE PFng+ra+vbFVzp5IDmUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rQEk8-000zeR-0m; Wed, 17 Jan 2024 22:50:44 +0000 Received: from mail-dbaeur03on20600.outbound.protection.outlook.com ([2a01:111:f403:260d::600] helo=EUR03-DBA-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rQEk4-000zcr-2S for linux-i3c@lists.infradead.org; Wed, 17 Jan 2024 22:50:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TpQXnHykO7PcqPtkAsa+Vod+EOKVStsr7e6P1w8001NPk71jp3PI27q4CWdf4gsntk6QtmDMwySWi7AmRUzjS8snwZI/BiHvVPVBAl2Be/Q3I973d7bvOpvGDAFhouxqzk1XaL+nKpb9fXp/+ZiV2ben5lsVNPX+4g1OITXA4kVydVk/jI/NVLKBMyR62fJ4gQyLvkkVDa0rHqlcCVYB/ZHMj00O/mh394MZR5RR2vpDuEHzKd3pDPKSPbHWwd0S9vcu28Tl84czDFjcdc4y9Fol/AbNNWhFznLoYyhIEjgYtyLfxkGBURcC9J4+yS148WSIqQQYl46ek3nwA3h+dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nOtJ80JffkOgKKh0YsiAty6fMdEIu6BMNilzlP9Ml1Q=; b=gZgg5p+8juWVErVDL1yMs4UxLgtqm4pwhKruhdDCAXC7PcPrngRclHKnFlUZDyUW3LZEBAuRNB2rneRXM1ZzLtoX6YSzUV3ymcUbZ3q17XzmbZVMHhly7UtEDN8LVy4jDo5fuuAVZwvoWRDd3tY6itMUIWl+F8GMrkOAULh8A1vwRRPRkw2+miOUxXxKBvrAHD29JuOHfvDpEGNyyePZzaSpAsYj5TUN769ylkpVrXqCbGvowtgd0DvuRgKuMNVKXvh/GyNFjVjlvF7BcSj3jzKgN1mdGJ0vX8VkTlKOVtf3yWO7RycmpkBnVQTyyfrNJqKG83UioG4zOHUPFSAxlw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nOtJ80JffkOgKKh0YsiAty6fMdEIu6BMNilzlP9Ml1Q=; b=d3WE/Y9xc0Bm1ZX1zsl52tlMD+yd3o60pW/UPKxAqyYhvYQfk0QAv7EWVG2GglewgW/KbEBjHxNehEEzj6d2MAEhDpMFxuY+mDIk3zdKjHz0dL0pWsJ7ha3Z2EEE5MX1rVqwSO7N1dOMPoqS3OYJdCqOkbgpgJuzM/Quy+ws79c= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AM9PR04MB7714.eurprd04.prod.outlook.com (2603:10a6:20b:2dd::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.23; Wed, 17 Jan 2024 22:50:27 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::b8af:bfe5:dffd:59a9]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::b8af:bfe5:dffd:59a9%4]) with mapi id 15.20.7202.020; Wed, 17 Jan 2024 22:50:27 +0000 From: Frank Li To: imx@lists.linux.dev, Miquel Raynal , Conor Culhane , Alexandre Belloni , linux-i3c@lists.infradead.org (moderated list:SILVACO I3C DUAL-ROLE MASTER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/1] i3c: master: svc: add support for read len bigger than 255 Date: Wed, 17 Jan 2024 17:50:09 -0500 Message-Id: <20240117225009.2931699-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SJ2PR07CA0019.namprd07.prod.outlook.com (2603:10b6:a03:505::21) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AM9PR04MB7714:EE_ X-MS-Office365-Filtering-Correlation-Id: 56823d9f-eebb-49f4-0e37-08dc17aeb2e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Et8ZPyxUH+7YaOWaymfsCYF4SRUbvhKqlqoGu4+44XE6GBck5vGxNVC3YQSTP//av8gDH60immdoDKlj5nVoKfP4MwhaMx54ULny/bOnnNZmPRzEU4o3tX+3m1dzGombjvXnbQF5OwfdAxAYh+DKU9aB4fTFvyq2zOARDZRp2Skgk5YJMWN1Ndn0lwXpjBl4XkXrPePctuyuMhSCn+kh7vYte0XbW+1KmLuWtK2DacnZjIBlSXi8kivzjX3SkFXFRZ5sWxADdvBNBXjR1DwGxG690TyvgVW139C0Zfpz2TPyYt6jqxMKxHKwVNVsFGHAYFgIIQcWzQd6oGNPDBDGt8pcGSmVs/YeK9y5BJEGWATVlWrnQ0FGgknUDz1YJNjNBlmrb+NHQo3LFbdPWmpcYO5cHwMOM9thPsDeoq3SSCjKZXOv+GQfRdP/pqgISdaZLiYmzO2uuO0v15SLKigCi0wm1Uof4Xce/H9QzHEivF87Xt0zrVHKs41snadpmUZiNXjtsakMpaHE8Wk2tuUYR6t8XluOHnJqPA0GW8HCrfEtYMCbU9VQrFvv0OacCE5JSNAHwyOrxiRecx7g/YA5NqmJ+CES8IdCcgrOepsV1GZ2458QV8OuTBLDZtrmQAontOVqhKm3RqKKRTmRMek6n66j6YSBkwYgxYzTOlxHir8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(136003)(376002)(396003)(366004)(39860400002)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(8676002)(8936002)(36756003)(2906002)(41300700001)(86362001)(38100700002)(38350700005)(5660300002)(6486002)(52116002)(2616005)(6666004)(6506007)(26005)(1076003)(478600001)(83380400001)(6512007)(110136005)(66946007)(66556008)(66476007)(316002)(135533001)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ogEFc0VYek9bAOWDDC70M+X5Mzh0?= =?utf-8?q?/GtnFDI9bQ3PoIGO0qXkyTDz2t1MerRaELgtvoxEtQ1p4bXkhY2SikPIyd7Wh6HOG?= =?utf-8?q?rjsX5Fcas8j2eAkkqGbaoFfpE3RXKOiixAFz5qZ1AJ17/+vvgk5Rn1e4AaV5NRpeI?= =?utf-8?q?xXoYxm5aEfDo2X/UkxJmEV0eKDlq0SFYW5mrm8T+ysJUfrCwR1GTxjHmSUEd59LuH?= =?utf-8?q?uCFUft5RL6ZoV2nMIeVdmAHpQrLxUsGNIObuGaOpEPS0ceXrv6a4UX9LND1MqzfNR?= =?utf-8?q?MaB82jPHYhmdje9r/V19wdnv66R9qU5rWOTunHZyJ523TMC8yy0geTjl/xNQrry63?= =?utf-8?q?fOtlsdGtHpk3a03SuzJv87aLcOL9HnGqnh1Sg/lt6mzrI0pE2LeKvlCsUd1SGtblZ?= =?utf-8?q?KZ9rZ0CoVF+8DJnSrpIIxo/AOCAzihlwZygVcMnup7626wCc45SliLNOqCArBDM9J?= =?utf-8?q?bGf65EHYGO04TocI7CiuU6K/hMvIYrCeUedHYX9VrXNCC0u+/h73M894cx4BkW89z?= =?utf-8?q?LwA/sDwQTnhljDoOeboX9ecemxVBYF6qE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cN74SLDQAW5?= =?utf-8?q?J2IjEYVOkXeFR1/mhQ9ViUlhi/X7Bl1eODlYSaIQKplFluUpRRpwe/yJ2aJ1S8SNT?= =?utf-8?q?h18jwOn+8NyN?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56823d9f-eebb-49f4-0e37-08dc17aeb2e7 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2024 22:50:27.4826 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eXhD9QJDnHgEKJq4JopFiF3it0FGFSfFjmDS9j6SCupR4LOXs4+HxKHCaDcL6JAdQrSPUkYqoFxEczKYQq3qXQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB7714 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240117_145040_823914_BC625AE6 X-CRM114-Status: GOOD ( 14.85 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org RDTERM is 8bit. Only support max 255 read transfer for auto terminate. Use manual terminate when read len bigger than 255. When left data length is FIFO size + 1, issue terminate (RDTERM(1) | REQUEST_NONE). So hardware will stop fetch data after next data. │ ◄────────── buff length ────────►│ │ │ │ ┌─┬─────────────┤ │ │ │ FIFO SIZE │ │ └─┴─────────────┘ ▲ │ Wait FIFO Full and Issue read termniate here!! Signed-off-by: Frank Li --- drivers/i3c/master/svc-i3c-master.c | 76 ++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index 5ee4db68988e2..58047ad357791 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -977,7 +977,7 @@ static int svc_i3c_master_do_daa(struct i3c_master_controller *m) } static int svc_i3c_master_read(struct svc_i3c_master *master, - u8 *in, unsigned int len) + u8 *in, unsigned int len, bool auto_term) { int offset = 0, i; u32 mdctrl, mstatus; @@ -995,16 +995,60 @@ static int svc_i3c_master_read(struct svc_i3c_master *master, return -ETIMEDOUT; } - mdctrl = readl(master->regs + SVC_I3C_MDATACTRL); - count = SVC_I3C_MDATACTRL_RXCOUNT(mdctrl); - if (offset + count > len) { - dev_err(master->dev, "I3C receive length too long!\n"); - return -EINVAL; - } - for (i = 0; i < count; i++) - in[offset + i] = readl(master->regs + SVC_I3C_MRDATAB); + if (auto_term || completed) { + /* auto termate or early termate by target */ + mdctrl = readl(master->regs + SVC_I3C_MDATACTRL); + count = SVC_I3C_MDATACTRL_RXCOUNT(mdctrl); + if (offset + count > len) { + dev_err(master->dev, "I3C receive length too long!\n"); + return -EINVAL; + } + for (i = 0; i < count; i++) + in[offset + i] = readl(master->regs + SVC_I3C_MRDATAB); + + offset += count; - offset += count; + } else { + /* + * Controller will fill whole RX FIFO in manual mode. FIFO full can prevent + * controller continue fetch data from target. + * + * When left data length is FIFO size + 1, issue terminate + * (RDTERM(1) | REQUEST_NONE). So hardware will stop fetch data after next + * data. + * + * │ ◄────────── buff length ────────►│ + * │ │ + * │ ┌─┬─────────────┤ + * │ │ │ FIFO SIZE │ + * │ └─┴─────────────┘ + * ▲ + * │ + * Wait FIFO Full and Issue read termniate here!! + */ + mdctrl = readl_relaxed(master->regs + SVC_I3C_MDATACTRL); + count = SVC_I3C_MDATACTRL_RXCOUNT(mdctrl); + + if (offset + count + SVC_I3C_FIFO_SIZE < len) { + for (i = 0; i < count; i++) { + in[offset] = readl_relaxed(master->regs + SVC_I3C_MRDATAB); + offset++; + } + } else { + if (count != SVC_I3C_FIFO_SIZE) + continue; + + /* Issue manual read terminate at next data */ + if (offset + SVC_I3C_FIFO_SIZE == len - 1) + writel_relaxed(SVC_I3C_MCTRL_REQUEST_NONE | + SVC_I3C_MCTRL_DIR(1) | + SVC_I3C_MCTRL_RDTERM(1), + master->regs + SVC_I3C_MCTRL); + + in[offset] = readl_relaxed(master->regs + SVC_I3C_MRDATAB); + offset++; + } + } } return offset; @@ -1042,9 +1086,17 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master, u8 *in, const u8 *out, unsigned int xfer_len, unsigned int *actual_len, bool continued) { + int rdterm = 0; u32 reg; int ret; + if (rnw) + rdterm = xfer_len; + + /* If read length > max RDTERM in MCTRL, using manual terminate */ + if (xfer_len > 255) + rdterm = 0; + /* clean SVC_I3C_MINT_IBIWON w1c bits */ writel(SVC_I3C_MINT_IBIWON, master->regs + SVC_I3C_MSTATUS); @@ -1053,7 +1105,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master, SVC_I3C_MCTRL_IBIRESP_NACK | SVC_I3C_MCTRL_DIR(rnw) | SVC_I3C_MCTRL_ADDR(addr) | - SVC_I3C_MCTRL_RDTERM(*actual_len), + SVC_I3C_MCTRL_RDTERM(rdterm), master->regs + SVC_I3C_MCTRL); ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg, @@ -1086,7 +1138,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master, } if (rnw) - ret = svc_i3c_master_read(master, in, xfer_len); + ret = svc_i3c_master_read(master, in, xfer_len, !!rdterm); else ret = svc_i3c_master_write(master, out, xfer_len); if (ret < 0)